[SOLVED] PIT in combination with IO APIC

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
robbiedobbie
Member
Member
Posts: 36
Joined: Fri May 16, 2014 2:40 pm
Libera.chat IRC: robbiedobbie

[SOLVED] PIT in combination with IO APIC

Post by robbiedobbie »

I'm currently trying to get the PIT timer to work. My problem however is that I am not receiving any interrupts generated by the timer.
I'm using the I/O APIC to map the IRQs. I know that the I/O APIC code is working properly, because other irqs get mapped correctly. The RTC timer interrupts just fine and keyboard interrupts work too.

What I'm currently doing is the following:
-Map an interrupthandler to interrupt 34 (Which is not yet used)
-Map IRQ 0 to interrupt 34 with the I/O APIC
-Enable channel 0 of the pittimer with a divider value of 11931 to get roughly 100 hz.

The code I'm using to enable the PIT timer:

Code: Select all

uint16_t divisor = 11931;
outb(0x43, 0x36);
outb(0x40, divisor & 0xff);
outb(0x40, (divisor >> 8) & 0xff);
I have the feeling that I'm missing something trivial since the interrupt handling works, and initializing the PIT itself shouldn't be too hard.

Anyone any hints on what might be going wrong here?
Last edited by robbiedobbie on Thu Feb 02, 2017 6:53 am, edited 3 times in total.
robbiedobbie
Member
Member
Posts: 36
Joined: Fri May 16, 2014 2:40 pm
Libera.chat IRC: robbiedobbie

Re: PIT in combination with IO APIC

Post by robbiedobbie »

I actually solved it. Apparantly PIT timer interrupts are IRQ2 on the I/O APIC instead of IRQ0. I found this information in the wiki at the HPET topic, section "Legacy Replacement Mapping".

Maybe this should be added to the PIT timer page as well?
User avatar
BenLunt
Member
Member
Posts: 941
Joined: Sat Nov 22, 2014 6:33 pm
Location: USA
Contact:

Re: [Solved] PIT in combination with IO APIC

Post by BenLunt »

The IRQ override from IRQ0 to IRQ2 is in the ACPI's MADT block.

If you are going to use the IOAPIC, you need to parse the ACPI and the MADT to get these overrides as well as get the base address of the IOAPIC.

i.e.: You should not assume 0xFEC00000.
robbiedobbie
Member
Member
Posts: 36
Joined: Fri May 16, 2014 2:40 pm
Libera.chat IRC: robbiedobbie

Re: [Solved] PIT in combination with IO APIC

Post by robbiedobbie »

D'oh. I'm already getting the IOAPIC address from the MADT table. I completely forgot about the ISO entries in the table.

I was so naive to assume that since the HPET mentioned IRQ2 on IOAPIC, that this was always the case. Thank you for the help!
robbiedobbie
Member
Member
Posts: 36
Joined: Fri May 16, 2014 2:40 pm
Libera.chat IRC: robbiedobbie

Re: PIT in combination with IO APIC

Post by robbiedobbie »

Actually, I tried implement the interrupt source override, however qemu doesn't have such entries, eventhough irq0 is rerouted to irq2. Is this a known bug in qemu?
User avatar
BenLunt
Member
Member
Posts: 941
Joined: Sat Nov 22, 2014 6:33 pm
Location: USA
Contact:

Re: PIT in combination with IO APIC

Post by BenLunt »

QEMU does emulate the overrides, at least the version I am using.

https://qemu.weilnetz.de/

Ben
http://www.fysnet.net/the_universal_serial_bus.htm
robbiedobbie
Member
Member
Posts: 36
Joined: Fri May 16, 2014 2:40 pm
Libera.chat IRC: robbiedobbie

Re: PIT in combination with IO APIC

Post by robbiedobbie »

I'm stupid. Turns out that qemu indeed does have the entries. I forgot to remove a break in my loop going over all the table entries. As soon as it found the first IO APIC it stopped searching.

Thank you for all the help!
Post Reply