keyboard interrupt needs strange workarounds on qemu (emu)?

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
xeyes
Member
Member
Posts: 212
Joined: Mon Dec 07, 2020 8:09 am

keyboard interrupt needs strange workarounds on qemu (emu)?

Post by xeyes »

I've switched to use APIC instead of the 8259 PIC and after that keyboard interrupts needed strange workarounds to work. So hope to get some insights on where to look.

Workarounds include:
1. MMIO read all redirection entries from the IOAPIC, either before or after setting up the keyboard interrupt redirection
2. read in a byte from port 0x61 and discard it, again either before or after setting up the keyboard interrupt redirection

"setting up the keyboard interrupt redirection" means writing the redirection entry to a different port, the entry is still masked and only unmasked much later.

Honestly these seem too tangential to be actual fixes, yet they work 100% of the time if I go back and forth between having those around the IOAPIC setup or not.

Keyboard also works fine with KVM (start qemu with -enable-kvm), only the software emulator mode of qemu (i.e. without -enable-kvm) needs one of the workarounds.

Questions:
1. Does IOAPIC need strict timings during its setup? The workarounds look more like timing changes, esp. since KVM is likely faster and might be hiding things.
2. Anything else that I need to do for the PIC to APIC transition other than masking all ports on PIC? Like do I need to somehow tell the keyboard to not send interrupt via PIC but via APIC?
3. Unrelated but GDB doesn't seem to work too reliably with KVM (missing breakpoints early in the boot process, temporarily jump to 'randomly places' before getting back on track if I si through certain 'transitions' like iret) but doesn't have these issues in the software emulator mode. Just curious is this expected or I might have some setup issue?
Post Reply