Debugging the PIT in Bochs
Posted: Tue Feb 20, 2007 4:21 am
Hi All,
I have re-written large portions of my OS code to take in to account a more flexible approach to drivers. One of the things I have just done is re-written my PIT initialisation code, which is pretty simple, as follows:
Doesn't look like it could get much simpler! It's pretty much lifted from Bran's kernel development tutorial. The reason for 3 functions is that kt_install() ('kernel time') will eventually encompass the RTC clock too. The irq enable function simply un-masks IRQ0.
The only problem is that in Bochs, I constantly get the message '[PIT81] Undefined behaviour when loading a half loaded count'. The IRQ also only fires once, despite writing an EOI to the PIC.
What really simple thing have I missed here - I had a working PIT in my old version, but fail to see the difference between my old and new code. It's almost embarrasing!
Oh - BTW, the interrupt handler for the PIT currently just does the EOI and an iret - I'm not even bothering to increment a tick counter until I get the simple code right!
Thanks in advance,
Adam
I have re-written large portions of my OS code to take in to account a more flexible approach to drivers. One of the things I have just done is re-written my PIT initialisation code, which is pretty simple, as follows:
Code: Select all
void kt_install()
{
kt_pit_frequency(1000);
ki_irq_enable(0);
}
void kt_pit_frequency(uint32 hz)
{
int div = 1193180 / hz;
outportb(0x43, 0x36);
outportb(0x40, div&0xFF);
outportb(0x40, (div>>8)&0xFF);
}
The only problem is that in Bochs, I constantly get the message '[PIT81] Undefined behaviour when loading a half loaded count'. The IRQ also only fires once, despite writing an EOI to the PIC.
What really simple thing have I missed here - I had a working PIT in my old version, but fail to see the difference between my old and new code. It's almost embarrasing!
![Embarassed :oops:](./images/smilies/icon_redface.gif)
Oh - BTW, the interrupt handler for the PIT currently just does the EOI and an iret - I'm not even bothering to increment a tick counter until I get the simple code right!
Thanks in advance,
Adam