Page 4 of 5
Re: Keyboard driver resets system when key is pressed.
Posted: Fri Sep 13, 2024 7:02 pm
by MichaelPetch
I would just add them this way by changing isr_stub_table to:
Code: Select all
isr_stub_table:
%assign i 0
%rep 48
dd isr_stub_%+i
%assign i i+1
%endrep
then add
Code: Select all
isr_no_err_stub 32
isr_no_err_stub 33
isr_no_err_stub 34
isr_no_err_stub 35
isr_no_err_stub 36
isr_no_err_stub 37
isr_no_err_stub 38
isr_no_err_stub 39
isr_no_err_stub 40
isr_no_err_stub 41
isr_no_err_stub 42
isr_no_err_stub 43
isr_no_err_stub 44
isr_no_err_stub 45
isr_no_err_stub 46
isr_no_err_stub 47
. That change alone won't resolve the issue. You create all those stubs but you have to set the IDT entries for them. So you'd need to change this in idt.c from:
Code: Select all
for (uint8_t vector = 0; vector < 32; vector++)
to
Code: Select all
for (uint8_t vector = 0; vector < 48; vector++)
. Of course your `exception_handler` will need to properly deal with the IRQs as well. I'd even recommend changing the name `exception_handler` to `isr_handler` if one were to handle exceptions and IRQs in the same function.
Re: Keyboard driver resets system when key is pressed.
Posted: Wed Sep 18, 2024 4:05 pm
by Tomrs123
So I'm doing some debugging, and hex-printed the error code from the General Proctection Fault, like this:
- 0004 error code.png (1.35 KiB) Viewed 3233 times
So I looked at the
General Protection Fault section in the
Exceptions page:
So I looked at that:
I didn't set up the LDT, so that might be the issue.
Re: Keyboard driver resets system when key is pressed.
Posted: Wed Sep 18, 2024 4:31 pm
by MichaelPetch
Part of the problem is that we don't know if you are printing the right value from the stack frame or whether there is a problem in your printing code. Can you update your Github repo with the latest version of the code so we can take a look?
You don't need LDTs. So if you didn't use them there shouldn't be one being referenced.
Re: Keyboard driver resets system when key is pressed.
Posted: Thu Sep 19, 2024 2:16 pm
by Tomrs123
Updated!
Re: Keyboard driver resets system when key is pressed.
Posted: Thu Sep 19, 2024 2:51 pm
by MichaelPetch
It doesn't build. I get errors `src/idt_asm.asm:(.text+0x4f): undefined reference to `interupt_handler'` and there is no function `interupt_handler` in any file. Interupt is spelled wrong. It should be interrupt.
Re: Keyboard driver resets system when key is pressed.
Posted: Thu Sep 19, 2024 2:54 pm
by Tomrs123
Updated, again... Gosh I hate having to "git add" every.. single.. time.
Re: Keyboard driver resets system when key is pressed.
Posted: Thu Sep 19, 2024 3:09 pm
by MichaelPetch
Your error code processing is all broken so it just prints garbage. If you want the error code you are going to have to pass a stack frame into the exception handler from the interrupts/exception stubs. Your stubs also don't handle exceptions with error codes properly. I ran your code with `qemu-system-i386 -cdrom build/os.iso -d int -no-shutdown -no-reboot` and got this
Code: Select all
0: v=20 e=0000 i=0 cpl=0 IP=0008:00100896 pc=00100896 SP=0010:0007ff00 env->regs[R_EAX]=00000000
EAX=00000000 EBX=0010bf60 ECX=000b8000 EDX=000003d5
ESI=00000000 EDI=00000000 EBP=00000000 ESP=0007ff00
EIP=00100896 EFL=00000206 [-----P-] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0010 00000000 ffffffff 00cf9300 DPL=0 DS [-WA]
CS =0008 00000000 ffffffff 00cf9a00 DPL=0 CS32 [-R-]
SS =0010 00000000 ffffffff 00cf9300 DPL=0 DS [-WA]
DS =0010 00000000 ffffffff 00cf9300 DPL=0 DS [-WA]
FS =0010 00000000 ffffffff 00cf9300 DPL=0 DS [-WA]
GS =0010 00000000 ffffffff 00cf9300 DPL=0 DS [-WA]
LDT=0000 00000000 0000ffff 00008200 DPL=0 LDT
TR =0000 00000000 0000ffff 00008b00 DPL=0 TSS32-busy
GDT= 00109b60 000007ff
IDT= 0010a780 000007ff
CR0=00000011 CR2=00000000 CR3=00000000 CR4=00000000
DR0=00000000 DR1=00000000 DR2=00000000 DR3=00000000
DR6=ffff0ff0 DR7=00000400
CCS=00000004 CCD=0007fe60 CCO=EFLAGS
EFER=0000000000000000
check_exception old: 0xffffffff new 0xd
1: v=0d e=0102 i=0 cpl=0 IP=0008:00100896 pc=00100896 SP=0010:0007ff00 env->regs[R_EAX]=00000000
EAX=00000000 EBX=0010bf60 ECX=000b8000 EDX=000003d5
ESI=00000000 EDI=00000000 EBP=00000000 ESP=0007ff00
EIP=00100896 EFL=00000206 [-----P-] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0010 00000000 ffffffff 00cf9300 DPL=0 DS [-WA]
CS =0008 00000000 ffffffff 00cf9a00 DPL=0 CS32 [-R-]
SS =0010 00000000 ffffffff 00cf9300 DPL=0 DS [-WA]
DS =0010 00000000 ffffffff 00cf9300 DPL=0 DS [-WA]
FS =0010 00000000 ffffffff 00cf9300 DPL=0 DS [-WA]
GS =0010 00000000 ffffffff 00cf9300 DPL=0 DS [-WA]
LDT=0000 00000000 0000ffff 00008200 DPL=0 LDT
TR =0000 00000000 0000ffff 00008b00 DPL=0 TSS32-busy
GDT= 00109b60 000007ff
IDT= 0010a780 000007ff
CR0=00000011 CR2=00000000 CR3=00000000 CR4=00000000
DR0=00000000 DR1=00000000 DR2=00000000 DR3=00000000
DR6=ffff0ff0 DR7=00000400
CCS=00000004 CCD=0007fe60 CCO=EFLAGS
EFER=0000000000000000
So you get a timer interrupt (v=20) and then a GPF with v=0d. Error code is e=0102. So this is a segment problem with entry 0x20 in the IDT. The reason for this is because you haven't actually initialized the IDT entries for the interrupts in idt.c . You have:
Code: Select all
for (uint8_t vector = 0; vector < 32; vector++) {
idt_set_descriptor(vector, interupt_stub_table[vector], 0x8E);
vectors[vector] = true;
}
should be:
Code: Select all
for (uint8_t vector = 0; vector < 48; vector++) {
idt_set_descriptor(vector, interupt_stub_table[vector], 0x8E);
vectors[vector] = true;
}
Re: Keyboard driver resets system when key is pressed.
Posted: Thu Sep 19, 2024 3:17 pm
by Tomrs123
No more GPF! Time to see if I get keyboard interrupts!
Re: Keyboard driver resets system when key is pressed.
Posted: Thu Sep 19, 2024 3:20 pm
by Tomrs123
Also forgot to send EOI, but simple fix.
Re: Keyboard driver resets system when key is pressed.
Posted: Thu Sep 19, 2024 3:39 pm
by Tomrs123
- YES.png (1.63 KiB) Viewed 3033 times
Re: Keyboard driver resets system when key is pressed.
Posted: Thu Sep 19, 2024 4:28 pm
by Tomrs123
After 55 posts, this topic is finally over.
Re: Keyboard driver resets system when key is pressed.
Posted: Mon Sep 23, 2024 5:06 pm
by Tomrs123
Tomrs123 wrote: ↑Thu Sep 19, 2024 4:28 pm
After 55 posts, this topic is
finally over.
Little did I know..
So anyway I'm working on the keyboard driver, but for some reason when I press a key, it resets the system- Just kidding. It just doesn't print anything.
I updated the Github repo.
Re: Keyboard driver resets system when key is pressed.
Posted: Mon Sep 23, 2024 7:57 pm
by MichaelPetch
I think the first place to start is looking to see if you have disabled PS/2 interrupts in your `keyboard_init` function. As an example comment out all the code except the `attach_interupt(0x21, keyboard_interupt);` and see if it works. If you do get keyboard interrupts then you have done something wrong in the initialization that has to be fixed.
Re: Keyboard driver resets system when key is pressed.
Posted: Tue Sep 24, 2024 9:18 am
by Tomrs123
Fixed it; messed up order of some bits
Re: Keyboard driver resets system when key is pressed.
Posted: Tue Sep 24, 2024 9:36 am
by Tomrs123
So I need to send command to the actual keyboard (not the controller), but I don't really know how to do that. I've read the controller AND keyboard wiki pages and still don't know how.