Page 1 of 1

IRQ7 when I program the PIT

Posted: Mon Nov 25, 2013 7:34 am
by kutkloon7
Hello,

I'm currently working on getting the PIC and PIT to work correctly. I believe I got the PIC working correctly, but the PIT causes problems for me. When I try to change the timer frequency, I get a IRQ7 for some frequencies. The behaviour of Bochs and VirtualBox is different, which complicates things even further... Another strange thing is that I cannot mask this IRQ for some reason.

What I do now is:
- Map the PIC to 0x20
- Mask all interrupts (just for now, as a test case)
- Enable interrupts

The code that I use for changing the PIT frequency:
(I hardcoded the 0x36, which sets the options of the command word. It initializes counter 0 as a squarewave and sets LSB and then MSB.

Code: Select all

void setPIT(uint32_t frequency)
{
    uint16_t tickPeriod = (uint16_t)(1193180 / frequency);
    ticks = 0;
    outb(0x43, 0x36);
    outb(0x40, tickPeriod & 0xff);
    outb(0x40, tickPeriod >> 8);
}
When I set the frequency to 100, everything seems to work fine, but for 1000, I get an IRQ7 on Bochs. For virtualbox, everything seems to run fine on 100Hz, but on 1000Hz I get a interrupt 0 (divide by zero) after a couple of seconds...

I found people with a similar issue here, but since I'm running on an emulator, this must be something else...

Re: IRQ7 when I program the PIT

Posted: Mon Nov 25, 2013 5:15 pm
by Combuster
kutkloon7 wrote:but since I'm running on an emulator, this must be something else...
Citation needed. Or actually, forget that:
google wrote:Bochs does emulate this spurious interrupt
Sanity check failed. Try again.

Re: IRQ7 when I program the PIT

Posted: Tue Nov 26, 2013 8:56 am
by kutkloon7
Thanks, you're awesome!

Pretty odd that I didn't find more information on this... I probably should have used the word "spurious" in my googling attemps... :P

Re: IRQ7 when I program the PIT

Posted: Tue Nov 26, 2013 9:20 am
by Combuster
Or read the relevant FAQ entry, where you can use IRQ7 as an index instead and then find out what it means. :wink:

Re: IRQ7 when I program the PIT

Posted: Wed Nov 27, 2013 5:09 pm
by kutkloon7
Yep, that should work too. Odd, those 'spurious' interrupts...

For the record: I had another issue too, which had to do with not restoring the registers in an interrupt handler. This caused errors occasionally, so this was kind of hard to track down. For some reason, this only caused troubles on VirtualBox (for example, a division by 0 where this should be impossible... I spent some hours figuring this out). The problems were gone after a adding 'pusha' before a call and 'popa' after :)