I have been following the example C code in the wiki (http://wiki.osdev.org/APIC_timer) about implementing the APIC timer.
It seems to work correctly under QEMU, but under Bochs the difference between the initial APIC count and the current APIC count after the PIC is done seems too low (around 0x84). Under QEMU this is around 0x9951F. The periodic timer interrupt on bochs then fires too quickly and this does not equal the given quantum value. Is this somehow normal because bochs is emulator or I am missing something here?
APIC timer under bochs
Re: APIC timer under bochs
I use it under bochs without a problem (2.5.1 although I compiled it with flags for my taste). I'll try to reproduce the error, I think it's not APIC timer, but PIT one-shot mode fires too early, so you'll have small value in APIC counter. In the meantime, can you please provide the value of cpubusfreq under qemu and bochs? Also the version you're using? Bochs output would be nice too.
You may also try to use RTC and wait 1 second by polling cmos, and see whether it's still wrong:
Please note that APIC timer is not accurate in emulators, if you want to measure time I suggest to use RTC with 1024Hz instead.
You may also try to use RTC and wait 1 second by polling cmos, and see whether it's still wrong:
Code: Select all
char getsecfromcmos() {
outb(0x70,0);
return inb(0x71);
}
tmp=getsecfromcmos();
while(tmp==getsecfromcmos()); //wait for change
(uint32*)(apic+APIC_TMRINITCNT)=0xFFFFFFFF; //start APIC timer
tmp=getsecfromcmos();
while(tmp==getsecfromcmos()); //wait for change
(uint32*)(apic+APIC_LVT_TMR)=APIC_DISABLE; //stop APIC timer