Page 1 of 1

IRQ won't fire, checked the wiki page, can't find any errors

Posted: Thu Aug 06, 2020 7:30 am
by clementttttttttt
I'm developing my own legacy bios implementation for bochs, and got stuck at INT 16h. The keyboard IRQ just won't fire(bochs reported keyboard buffer full,ignoring scancode). The PIC initialization code looks really fine, the handlers looks fine, but it just wont fire. I checked everything, and I just can't find the reason why(interrupt flag is present, proper segment, ivt does have int 0x9 according to bochs's info ivt 0x9 command).Here's the pic initialization code, which set an irq offset of 0x8 for master and 0x70 for slave:

Code: Select all

initpic:
    mov al,0x11
    out 0x20,al
    out 0xa0,al
    mov al,0x8
    out 0x21,al
    mov al,0x70
    out 0xa1,al
    mov al,4
    out 0x21,al
    mov al,0x2
    out 0xa1,al
    mov al,1
    out 0x21,al
    out 0xa1,al
    mov al,0xfd
    out 0x21,al
    mov al,0xff
    out 0xa1,al
Here's the handler code, which is a dummy code for now:

Code: Select all

irq1:
   pusha
   mov al,0x20 ;the acknowledge interrupt code
   out 0x20,al
   in al,60h
   popa
   iret
And here's the code for setting the ivt:

Code: Select all

setivt:
   xor dx,dx
   mov gs,dx
   mov [gs:0x9*4+2],cs
   mov [gs:0x9*4],irq1
and the code looked perfectly fine to me.
EDIT: Added the acknowledge interrupt code

Re: IRQ won't fire, checked the wiki page, can't find any er

Posted: Thu Aug 06, 2020 8:45 am
by iansjack
Your interrupt handler doesn't acknowledge the interrupt.

Re: IRQ won't fire, checked the wiki page, can't find any er

Posted: Thu Aug 06, 2020 9:20 am
by clementttttttttt
The problem is, even with acknowledge interrupt, I still can't receive any IRQs.

EDIT:
I inserted the initialization code in the startup code of NetDOS(my os), and it works fine, so the initialization code was definitely not the problem

Re: IRQ won't fire, checked the wiki page, can't find any er

Posted: Thu Aug 06, 2020 9:57 am
by iansjack
Could you publish the code of the interrupt handler that now acknowledges the interrupt?

Re: IRQ won't fire, checked the wiki page, can't find any er

Posted: Thu Aug 06, 2020 10:28 am
by nullplan
clementttttttttt wrote:(bochs reported keyboard buffer full,ignoring scancode)
Something is already in the keyboard buffer. Your keyboard initialization routine fails to empty the buffer. Therefore no new scan code can be put into the buffer. The initialization routine must read port 0x64 and test if bit 0 is set. If so, it must read port 0x60 until that bit is clear. Since at that point you cannot know where you are in a multi-byte scan code, just discard the data.

The interrupt handler also must read port 0x60 to clear the buffer. Else the PS/2 controller will not send another code byte, even if the PIC has been satisfied.

Re: IRQ won't fire, checked the wiki page, can't find any er

Posted: Thu Aug 06, 2020 12:07 pm
by clementttttttttt
I knew that, and its intended only for placeholder purposes and only intended for single byte scancodes.I tried to replace my os's keyboard handler with that one, smashed the keyboard, and that buffer full message never appeared, so i think its not the problem of the handler too.

Re: IRQ won't fire, checked the wiki page, can't find any er

Posted: Thu Aug 06, 2020 12:57 pm
by iansjack
Just to clarify - you are now sending the EOI signal to the PIC?

Re: IRQ won't fire, checked the wiki page, can't find any er

Posted: Thu Aug 06, 2020 6:27 pm
by Octocontrabass
How did you initialize the keyboard controller?

Re: IRQ won't fire, checked the wiki page, can't find any er

Posted: Thu Aug 06, 2020 8:40 pm
by clementttttttttt
How clumsy am I... It appears that I forgot to initialize the keyboard controller.

UPDATE: After setting the configure byte of the keyboard controller, NO, it still didn't work. Here's the code for setting the configure byte:

Code: Select all

initps2:
    mov al,0x60
    out 0x64,al
    mov al,0b01000111 ;enable clocks on all ps2 ports and enable all interrupts
    out 0x60,al
    mov al,0xae
    out 0x64,al

UPDATE 2: The code suddenly works, but only when it wanted to. It might be because of I initialized the PIC way too quickly.

UPDATE 3: FINALLY, I FOUND THE REASON WHY IT DOESN'T WORK. Somehow, the damn keyboard buffer have something in it, and it caused the keyboard to not sent interrupts. FINALLY SETTLED THIS FRUSTRATING PROBLEM.