Page 1 of 1

APIC troubles with VirtualBox

Posted: Thu Sep 01, 2016 2:20 pm
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.

Re: APIC troubles with VirtualBox

Posted: Thu Sep 01, 2016 9:53 pm
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

Re: APIC troubles with VirtualBox

Posted: Fri Sep 02, 2016 7:05 am
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.

Re: APIC troubles with VirtualBox

Posted: Fri Sep 02, 2016 8:05 am
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?