Keyboard driver resets system when key is pressed.

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
MichaelPetch
Member
Member
Posts: 787
Joined: Fri Aug 26, 2016 1:41 pm
Libera.chat IRC: mpetch

Re: Keyboard driver resets system when key is pressed.

Post 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.
Tomrs123
Member
Member
Posts: 40
Joined: Mon Aug 19, 2024 11:12 am
GitHub: https://github.com/ilikecoding-197

Re: Keyboard driver resets system when key is pressed.

Post 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
0004 error code.png (1.35 KiB) Viewed 2595 times
So I looked at the General Protection Fault section in the Exceptions page:
generalprotectionfaultpage.png
So I looked at that:
selectorerrorcode.png
I didn't set up the LDT, so that might be the issue.
MichaelPetch
Member
Member
Posts: 787
Joined: Fri Aug 26, 2016 1:41 pm
Libera.chat IRC: mpetch

Re: Keyboard driver resets system when key is pressed.

Post 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.
MichaelPetch
Member
Member
Posts: 787
Joined: Fri Aug 26, 2016 1:41 pm
Libera.chat IRC: mpetch

Re: Keyboard driver resets system when key is pressed.

Post 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.
Tomrs123
Member
Member
Posts: 40
Joined: Mon Aug 19, 2024 11:12 am
GitHub: https://github.com/ilikecoding-197

Re: Keyboard driver resets system when key is pressed.

Post by Tomrs123 »

Updated, again... Gosh I hate having to "git add" every.. single.. time.
MichaelPetch
Member
Member
Posts: 787
Joined: Fri Aug 26, 2016 1:41 pm
Libera.chat IRC: mpetch

Re: Keyboard driver resets system when key is pressed.

Post 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;
    }
Tomrs123
Member
Member
Posts: 40
Joined: Mon Aug 19, 2024 11:12 am
GitHub: https://github.com/ilikecoding-197

Re: Keyboard driver resets system when key is pressed.

Post by Tomrs123 »

No more GPF! Time to see if I get keyboard interrupts!
Tomrs123
Member
Member
Posts: 40
Joined: Mon Aug 19, 2024 11:12 am
GitHub: https://github.com/ilikecoding-197

Re: Keyboard driver resets system when key is pressed.

Post by Tomrs123 »

Also forgot to send EOI, but simple fix.
Tomrs123
Member
Member
Posts: 40
Joined: Mon Aug 19, 2024 11:12 am
GitHub: https://github.com/ilikecoding-197

Re: Keyboard driver resets system when key is pressed.

Post by Tomrs123 »

YES.png
YES.png (1.63 KiB) Viewed 2395 times
Tomrs123
Member
Member
Posts: 40
Joined: Mon Aug 19, 2024 11:12 am
GitHub: https://github.com/ilikecoding-197

Re: Keyboard driver resets system when key is pressed.

Post by Tomrs123 »

After 55 posts, this topic is finally over.
Tomrs123
Member
Member
Posts: 40
Joined: Mon Aug 19, 2024 11:12 am
GitHub: https://github.com/ilikecoding-197

Re: Keyboard driver resets system when key is pressed.

Post 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.
MichaelPetch
Member
Member
Posts: 787
Joined: Fri Aug 26, 2016 1:41 pm
Libera.chat IRC: mpetch

Re: Keyboard driver resets system when key is pressed.

Post 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.
Tomrs123
Member
Member
Posts: 40
Joined: Mon Aug 19, 2024 11:12 am
GitHub: https://github.com/ilikecoding-197

Re: Keyboard driver resets system when key is pressed.

Post by Tomrs123 »

Fixed it; messed up order of some bits :lol:
Tomrs123
Member
Member
Posts: 40
Joined: Mon Aug 19, 2024 11:12 am
GitHub: https://github.com/ilikecoding-197

Re: Keyboard driver resets system when key is pressed.

Post 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. :(
Post Reply