APIC timer under bochs

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
itportal
Posts: 18
Joined: Tue May 18, 2010 1:34 am

APIC timer under bochs

Post by itportal »

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?
User avatar
turdus
Member
Member
Posts: 496
Joined: Tue Feb 08, 2011 1:58 pm

Re: APIC timer under bochs

Post by turdus »

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:

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
Please note that APIC timer is not accurate in emulators, if you want to measure time I suggest to use RTC with 1024Hz instead.
Post Reply