IRQ7 when I program the PIT

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
kutkloon7
Member
Member
Posts: 98
Joined: Fri Jan 04, 2013 6:56 pm

IRQ7 when I program the PIT

Post 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...
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: IRQ7 when I program the PIT

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
kutkloon7
Member
Member
Posts: 98
Joined: Fri Jan 04, 2013 6:56 pm

Re: IRQ7 when I program the PIT

Post 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
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: IRQ7 when I program the PIT

Post 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:
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
kutkloon7
Member
Member
Posts: 98
Joined: Fri Jan 04, 2013 6:56 pm

Re: IRQ7 when I program the PIT

Post 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 :)
Post Reply