OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Mar 29, 2024 4:19 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Pressing 2 Keys on Keyboard results in Page Fault
PostPosted: Thu Oct 20, 2022 3:29 pm 
Offline

Joined: Thu Oct 20, 2022 2:46 pm
Posts: 2
Hello,

I am new to learning os development, and am working on a little hobby OS. Over the last couple days, I have finally been able to create a higher half kernel using limine as the bootloader. I am currently working on trying to get keyboard input and put it on the screen, however, I keep getting a weird page fault issue. I've spent all day on it, so I am hoping somebody else can see the issue I am unable to. I have a working GDT, IDT, and PIC, and the keystrokes will put a simple '.' on the screen. However, if I press 2 keys at the same time, the kernel halts in the page fault exception handler. I found a way around it by just reenabling interrupts in the handler, but something seems very bizzarre to me that it is even throwing the page fault exception.

This is what qemu debug displays:
Code:
check_exception old: 0xffffffff new 0xe
    13: v=0e e=0010 i=0 cpl=0 IP=0028:0000000000000028 pc=0000000000000028 SP=0030:ffff800007b20de8 CR2=0000000000000028
RAX=0000000000000020 RBX=0000000000000000 RCX=0000000000000009 RDX=0000000000000020
RSI=0000000000000020 RDI=0000000000000020 RBP=ffff800007b20ff0 RSP=ffff800007b20de8
R8 =0000000000000028 R9 =0000000000000000 R10=0000000000000000 R11=0000000000000000
R12=0000000000000000 R13=0000000000000000 R14=0000000000000000 R15=0000000000000000
RIP=0000000000000028 RFL=00000216 [----AP-] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0030 0000000000000000 00000fff 00a09300 DPL=0 DS   [-WA]
CS =0028 0000000000000000 20000fff 00a29a00 DPL=0 CS64 [-R-]
SS =0030 0000000000000000 00000fff 00a09300 DPL=0 DS   [-WA]
DS =0030 0000000000000000 00000fff 00a09300 DPL=0 DS   [-WA]
FS =0030 0000000000000000 00000fff 00a09300 DPL=0 DS   [-WA]
GS =0030 0000000000000000 00000fff 00a09300 DPL=0 DS   [-WA]
LDT=0000 0000000000000000 00000000 00008200 DPL=0 LDT
TR =0048 ffffffff80012560 00000068 00208900 DPL=0 TSS64-avl
GDT=     ffffffff800024a0 00000057
IDT=     ffffffff800125e0 00000fff
CR0=80010011 CR2=0000000000000028 CR3=0000000007b10000 CR4=00000020
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000
DR6=00000000ffff0ff0 DR7=0000000000000400
CCS=0000000000000018 CCD=0000000007b28000 CCO=ADDL
EFER=0000000000000d00


Any help is appreciated! I published the code to github.

(It is a mess right now while I am trying to debug this issue)
https://github.com/Programatic/PokerOS


Top
 Profile  
 
 Post subject: Re: Pressing 2 Keys on Keyboard results in Page Fault
PostPosted: Thu Oct 20, 2022 5:21 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5103
You can't put ordinary function pointers in your IDT. You need a stub written in assembly that adapts the interrupt context to meet the needs of the System V ABI.

There's a function attribute you could use instead of an assembly stub, but it's not suitable for a complete OS since it doesn't give you access to the interrupt context.


Top
 Profile  
 
 Post subject: Re: Pressing 2 Keys on Keyboard results in Page Fault
PostPosted: Fri Oct 21, 2022 7:41 am 
Offline

Joined: Thu Oct 20, 2022 2:46 pm
Posts: 2
@Octocontrabass This was the issue. Thank you so much! So is the best way to make the interrupt handlers to create an assembly file and have it redirect to my C functions?


Top
 Profile  
 
 Post subject: Re: Pressing 2 Keys on Keyboard results in Page Fault
PostPosted: Fri Oct 21, 2022 11:39 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5103
Yes.

Exactly how you do it is up to you, but it's pretty common to share most of the assembly code between interrupt vectors, including calling a single shared C function. That shared function then uses an array of function pointers to call the appropriate handler.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], songziming, thewrongchristian and 117 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group