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

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.
Post Reply
clementttttttttt
Member
Member
Posts: 70
Joined: Tue Jul 14, 2020 4:01 am
Libera.chat IRC: clementttttttttt

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

Post 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
Last edited by clementttttttttt on Thu Aug 06, 2020 10:01 am, edited 1 time in total.
User avatar
iansjack
Member
Member
Posts: 4703
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

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

Post by iansjack »

Your interrupt handler doesn't acknowledge the interrupt.
clementttttttttt
Member
Member
Posts: 70
Joined: Tue Jul 14, 2020 4:01 am
Libera.chat IRC: clementttttttttt

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

Post 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
User avatar
iansjack
Member
Member
Posts: 4703
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

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

Post by iansjack »

Could you publish the code of the interrupt handler that now acknowledges the interrupt?
nullplan
Member
Member
Posts: 1790
Joined: Wed Aug 30, 2017 8:24 am

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

Post 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.
Carpe diem!
clementttttttttt
Member
Member
Posts: 70
Joined: Tue Jul 14, 2020 4:01 am
Libera.chat IRC: clementttttttttt

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

Post 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.
User avatar
iansjack
Member
Member
Posts: 4703
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

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

Post by iansjack »

Just to clarify - you are now sending the EOI signal to the PIC?
Octocontrabass
Member
Member
Posts: 5572
Joined: Mon Mar 25, 2013 7:01 pm

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

Post by Octocontrabass »

How did you initialize the keyboard controller?
clementttttttttt
Member
Member
Posts: 70
Joined: Tue Jul 14, 2020 4:01 am
Libera.chat IRC: clementttttttttt

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

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