APIC troubles with VirtualBox

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
mghis
Posts: 17
Joined: Wed Jun 22, 2011 1:52 pm

APIC troubles with VirtualBox

Post by mghis »

Hi all.

I am trying to get the local APIC to signal timer interrupts. It seems to work fine in Bochs and QEMU. I have not tried it on real hardware. However in VirtualBox (Version 4.2.16) it does not work. What I do so far is:
1) ensure that APIC is enabled reading its MSR. In VirtualBox I got 0xfee00900. (much like QEMU and Bochs).
2) OR in 0x1ff to LAPIC spurious interrupt register. So I enable it and set vector to 255.
3) Set TPR to 0 to unmask interrupts.
4) Send EOI to flush any pending interrupt
5) Set up timer: vector 0x20, periodic mode, clock divisor to 128, initial count to 0xf00.

I tried to debug it in the standard VirtualBox debugger, even tough I am
not familiar with it:

Code: Select all

VBoxDbg> info apic
Local APIC at fee00900:
  LAPIC ID  : 00000000
    APIC ID = 00
  APIC VER   : 00050014
    version  = 14
    lvts     = 6
  TPR        : 00000000
    task pri = 0/0
  PPR        : 00000020
    cpu pri  = 2/0
  LDR       : 00000000
    log id  = 00
  DFR       : 0fffffff
  SVR       : 000001ff
    focus   = check on
    lapic   = ENABLED
    vector  = ff
  ISR       : 0000000000000001000000000000000000000000000000000000000000000000
    highest = 20
  IRR       : 0000000000000001000000000000000000000000000000000000000000000000
    highest = 20
VBoxDbg> info apic timer
Local APIC timer:
  Initial count : 0000f000
  Current count : 0000f000
  Divide config : 0000000a
    divider     = 128
VBoxDbg> info apic lvt
  LVT Timer : 00020020
    mode    = periodic
    mask    = 0
    status  = idle
    vector  = 20
  LVT LINT0 : 00000700
    mask    = 0
    trigger = edge
    rem irr = 0
    polarty = 0
    status  = idle
    delivry = ExtINT
    vector  = 00
  LVT LINT1 : 00000400
    mask    = 0
    trigger = edge
    rem irr = 0
    polarty = 0
    status  = idle
    delivry = NMI
    vector  = 00
VBoxDbg> 
As you can see ISR and IRR signal that vector 0x20 has a pending interrupt, but the handler is not called.

LAPIC is mapped in with caching disabled, as recommended. For now I configured VirtualBox and the other emulators to run with one CPU core only. I have not tried to enable other cores.

I cannot get interrupts from I/O APIC either (although they do work in Bochs and QEMU).

If deemed useful, I shall upload source tarball or compiled binary.

Thank you for any help.

P.S.:

After having found a working floppy disk drive, I managed to try my program out on my own real PC. It works fine as in QEMU and Bochs. Also ISA IRQs are working: I have got response after keyboard input. I have an Intel Core 2 Duo E8400 3.00GHz. Only one I/O APIC with 23 entries. After parsing MP table, my program recognized 7 PCI buses and a single ISA bus and got the pin assignment entry right.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: APIC troubles with VirtualBox

Post by Brendan »

Hi,

Unfortunately, I can't see anything wrong - it looks like the local APIC timer did generate an interrupt and that interrupt was sent to the CPU.

The first thing I'd check is whether the CPU has interrupts disabled in EFLAGS. Beyond that, I'd delete the "send EOI to flush any pending interrupt" part, as this shouldn't be needed and "EOI when no interrupt was sent" might be confusing VirtualBox.

If neither of those things help (which is likely) I'd start trying different versions of VirtualBox to determine if the problem exists in with some versions but not others (which could indicate that it was a bug in some versions of VirtualBox). Then I'd resort to "random changes that shouldn't make any difference, to see if anything makes a difference" (e.g. try different timer divisors, different timer counts, one-shot mode, setting DFR and LDR, etc).


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
mghis
Posts: 17
Joined: Wed Jun 22, 2011 1:52 pm

Re: APIC troubles with VirtualBox

Post by mghis »

Thank you for your help.

I tried not to send the first EOI and I checked I did a "sti" before waiting for interrupt. No result so far. I'll try it on a few other real computers. If it works, I'll assume that there is something wrong with my version of VirtualBox.
User avatar
SpyderTL
Member
Member
Posts: 1074
Joined: Sun Sep 19, 2010 10:05 pm

Re: APIC troubles with VirtualBox

Post by SpyderTL »

That version of VirtualBox is pretty old, and I did find a few references to APIC issues fixed after that version. But, on the other hand, I'd be truly surprised if there was actually one or more versions of VirtualBox with completely broken APIC interrupts, as it's doubtful Windows would even run properly in that situation.

Just as a diagnostic, have you tried disabling VT-x acceleration in VirtualBox to see if it made any difference?
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott
Post Reply