PS/2 IRQ not firing + spurious IRQ (real hardware)
Re: PS/2 IRQ not firing + spurious IRQ (real hardware)
I was thinking of the APIC implementation, and then I thought: isn't the i8259 PIC on the CPU die on modern processors (just like the APIC) ?
If it's the case, how could there be a bug in the PIC ? Intel/ADM would reuse their old design for this part of the dies, and that's it (so old circuitry which is well tested, no bug in sight)...
If it's the case, how could there be a bug in the PIC ? Intel/ADM would reuse their old design for this part of the dies, and that's it (so old circuitry which is well tested, no bug in sight)...
-
Octocontrabass
- Member

- Posts: 6247
- Joined: Mon Mar 25, 2013 7:01 pm
Re: PS/2 IRQ not firing + spurious IRQ (real hardware)
It might be. You can try checking your CPU's datasheet.
Who would notice a bug in the PIC? Modern OSes don't use it, they have APIC.
Re: PS/2 IRQ not firing + spurious IRQ (real hardware)
I've tried numerous times, but every time I just end up with the poor Intel or AMD marketing pdf with stuff like number of cores, frequency and that's it. Do you know where to find it ? (say, for the r7 7840hs)Octocontrabass wrote: ↑Tue Mar 25, 2025 6:31 pm It might be. You can try checking your CPU's datasheet.
What I meant is, it has been well used and tested back in the days, and now since it's not used anymore (but for backward compatibility), they have no reasons to change the circuit and therefore introduce bugs: "if it works, don't touch it"Octocontrabass wrote: ↑Tue Mar 25, 2025 6:31 pm Who would notice a bug in the PIC? Modern OSes don't use it, they have APIC.
Re: PS/2 IRQ not firing + spurious IRQ (real hardware)
Possibly, but the system design might have introduced a regression somewhere, or maybe the thing is wired up wrong internally, and that wouldn't be noticed.
Carpe diem!
-
Octocontrabass
- Member

- Posts: 6247
- Joined: Mon Mar 25, 2013 7:01 pm
Re: PS/2 IRQ not firing + spurious IRQ (real hardware)
Sorry I missed you message, thank you ! How did you find this ?
Btw I'm working on the APIC, but I need to setup paging first to read some memory address, so it will take a while x)
Btw I'm working on the APIC, but I need to setup paging first to read some memory address, so it will take a while x)
-
Octocontrabass
- Member

- Posts: 6247
- Joined: Mon Mar 25, 2013 7:01 pm
Re: PS/2 IRQ not firing + spurious IRQ (real hardware)
I searched the AMD documentation hub for your CPU's family and model.
Re: PS/2 IRQ not firing + spurious IRQ (real hardware)
Hi. It's been a long time ! I implemented a lot of stuff, including APIC & IOAPIC drivers.
Sadly, it didn't solve my problem, everything is just like before.
I'll make a summary of my setup here:
- Mask ISA IRQ 1 and 12 in the APIC (keyboard & mouse)
- Initialize the 8042 PS/2 controller by using polling (using simple counter timeout):
• disable both ports
• flush output buffer
• setup controller configuration byte
• test presence of port 2 by enabling it, and disabling it again
• perform ports self test
• re-enable ports
• enable devices IRQ in the config byte
- Setup irq handler for PS/2 mouse & keyboard IRQs
- Unmask said IRQs
- Flush any data (there's none)
- Test PS/2 keyboard
• Send 'disable scanning' command
• No IRQ fires, timeout reached, initialization fails
I tried some stuff as debugging. (Note that this is NOT supposed to be the actual final code, just debug checks !) Here's what I learned:
- Added a check for PS/2 controller status register's "output buffer full" bit set in my timer IRQ ; this highlighted that the keyboard responds to the scanning command during my timeout loop ! but the keyboard IRQ doesn't fire
- If I read the output buffer when it's full (polling), THEN NOW the IRQ fires, after the buffer is emptied (???)
- If I use the byte I got by polling, it 'works', until there are several bytes of response, things get out of order and fail (as it should). This highlights that the "irq firing after the data has been read" goes on and on
- I went back to using polling (I know @Octocontrabass said I should use IRQs), and initialization fails, one byte seems to disappear in the void somehow ; plus, IRQs still don't fire afterwards
What could be wrong in my setup ?
Sadly, it didn't solve my problem, everything is just like before.
I'll make a summary of my setup here:
- Mask ISA IRQ 1 and 12 in the APIC (keyboard & mouse)
- Initialize the 8042 PS/2 controller by using polling (using simple counter timeout):
• disable both ports
• flush output buffer
• setup controller configuration byte
• test presence of port 2 by enabling it, and disabling it again
• perform ports self test
• re-enable ports
• enable devices IRQ in the config byte
- Setup irq handler for PS/2 mouse & keyboard IRQs
- Unmask said IRQs
- Flush any data (there's none)
- Test PS/2 keyboard
• Send 'disable scanning' command
• No IRQ fires, timeout reached, initialization fails
I tried some stuff as debugging. (Note that this is NOT supposed to be the actual final code, just debug checks !) Here's what I learned:
- Added a check for PS/2 controller status register's "output buffer full" bit set in my timer IRQ ; this highlighted that the keyboard responds to the scanning command during my timeout loop ! but the keyboard IRQ doesn't fire
- If I read the output buffer when it's full (polling), THEN NOW the IRQ fires, after the buffer is emptied (???)
- If I use the byte I got by polling, it 'works', until there are several bytes of response, things get out of order and fail (as it should). This highlights that the "irq firing after the data has been read" goes on and on
- I went back to using polling (I know @Octocontrabass said I should use IRQs), and initialization fails, one byte seems to disappear in the void somehow ; plus, IRQs still don't fire afterwards
What could be wrong in my setup ?
-
Octocontrabass
- Member

- Posts: 6247
- Joined: Mon Mar 25, 2013 7:01 pm
Re: PS/2 IRQ not firing + spurious IRQ (real hardware)
Did you program the IOAPIC with the correct polarity and trigger mode?
Did you initialize the USB HCIs? USB legacy support can interfere with PS/2. It might also be misbehaving because you're not supposed to poll, or maybe just a bug in your code, though I'm not sure why you would lose only one byte in those cases.
Re: PS/2 IRQ not firing + spurious IRQ (real hardware)
Yes, afaik. I'm getting exactly the same behaviour whatever IRQ chip I'm using (PIC or APIC)Octocontrabass wrote: ↑Mon Aug 04, 2025 3:05 pm Did you program the IOAPIC with the correct polarity and trigger mode?
I did not touch USB. If I'm being honest, I don't plan to, I'd rather not bother implementing this hell. I'm getting my buggy behaviour exactly the same way on two machines, one Intel cpu, one AMD ; I reckon it means that my bug is not a problem with USB (?)Octocontrabass wrote: ↑Mon Aug 04, 2025 3:05 pm Did you initialize the USB HCIs? USB legacy support can interfere with PS/2. It might also be misbehaving because you're not supposed to poll, or maybe just a bug in your code, though I'm not sure why you would lose only one byte in those cases.
As I said, if I don't poll at all (which is what I do on the commit code, cause that's what you told me to do), and only use IRQs, just nothing happens (the first irq never fires, timeout, and that's it)
I'm guessing it's 'just' a bug in my code, but I've been searching it for literal weeks now. Maybe I'm getting the "polling" thing wrong: what is considered polling ? Only reading from the data port, or is reading the status register already considered polling ?
-
Octocontrabass
- Member

- Posts: 6247
- Joined: Mon Mar 25, 2013 7:01 pm
Re: PS/2 IRQ not firing + spurious IRQ (real hardware)
Which polarity and trigger mode? Is there an interrupt source override in the MADT?
I'm not sure you can properly initialize PS/2 without touching USB. Does the keyboard work properly if you don't initialize the PS/2 controller at all? Just flush the output buffer, enable IRQ1, and move on to whatever keyboard initialization you like.
It could still be a problem with USB if both machines have the same buggy USB legacy support module from the same BIOS vendor.
Polling is when you have a loop that reads the status register waiting for it to change. Like this.
Re: PS/2 IRQ not firing + spurious IRQ (real hardware)
Octocontrabass, I'm curious, is the OS you've linked to your own?
Re: PS/2 IRQ not firing + spurious IRQ (real hardware)
No it's mine
Yes there are 2 overrides iirc. Default polarity is high (0) and default trigger mode is edge (0). For the overrides I use the MADT-provided configurationOctocontrabass wrote: ↑Tue Aug 05, 2025 4:20 pm Which polarity and trigger mode? Is there an interrupt source override in the MADT?
I think I tried this already, but I don't remember. I'll test again when I have a little timeOctocontrabass wrote: ↑Tue Aug 05, 2025 4:20 pm I'm not sure you can properly initialize PS/2 without touching USB. Does the keyboard work properly if you don't initialize the PS/2 controller at all? Just flush the output buffer, enable IRQ1, and move on to whatever keyboard initialization you like.
Yeah, I changed this without committing (removed the waitUntilBitValueOrTimeout call). That's what I mean when I say I don't use polling.Octocontrabass wrote: ↑Tue Aug 05, 2025 4:20 pm Polling is when you have a loop that reads the status register waiting for it to change. Like this.
However, I think it's wrong not to wait for input buffer empty before sending command, is it ? Is it considered polling, and what's the best way of sending commands (for initializing PS/2 devices), with or without the wait loop ?
Re: PS/2 IRQ not firing + spurious IRQ (real hardware)
Well, I can not pinpoint what I liked, but I can say that to me the code seems overall well written. Something to learn from. I did try v0.2-tetris, too.
Anyway, I'll try not to hijack the thread and shut up now. : )
Re: PS/2 IRQ not firing + spurious IRQ (real hardware)
Thank you sandras, that's genuinely heartwarming and motivating to read ! 

What could I try ? Try to write a USB stub to deactivate the controller.s that might get in the way ? (I really don't want to end up like i did with the APIC, write tons of stuff for in the end figuring out that the problem is still here and taunting me)
I can confirm, it get the same behaviour as previouslyMagyar57 wrote: ↑Wed Aug 06, 2025 3:36 pmI think I tried this already, but I don't remember. I'll test again when I have a little timeOctocontrabass wrote: ↑Tue Aug 05, 2025 4:20 pm I'm not sure you can properly initialize PS/2 without touching USB. Does the keyboard work properly if you don't initialize the PS/2 controller at all? Just flush the output buffer, enable IRQ1, and move on to whatever keyboard initialization you like.
I'll reiterate that question
What could I try ? Try to write a USB stub to deactivate the controller.s that might get in the way ? (I really don't want to end up like i did with the APIC, write tons of stuff for in the end figuring out that the problem is still here and taunting me)
