Index: trunk/src/VBox/VMM/VMMR3/APIC.cpp
===================================================================
--- trunk/src/VBox/VMM/VMMR3/APIC.cpp	(revision 107112)
+++ trunk/src/VBox/VMM/VMMR3/APIC.cpp	(revision 107113)
@@ -33,5 +33,4 @@
 #include <VBox/log.h>
 #include "APICInternal.h"
-#include <VBox/vmm/apic.h>
 #include <VBox/vmm/cpum.h>
 #include <VBox/vmm/hm.h>
@@ -217,39 +216,16 @@
 
 /**
- * Receives an INIT IPI.
- *
- * @param   pVCpu   The cross context virtual CPU structure.
- */
-VMMR3_INT_DECL(void) APICR3InitIpi(PVMCPU pVCpu)
-{
-    VMCPU_ASSERT_EMT(pVCpu);
-    LogFlow(("APIC%u: APICR3InitIpi\n", pVCpu->idCpu));
-    apicInitIpi(pVCpu);
-}
-
-
-/**
- * Sets whether Hyper-V compatibility mode (MSR interface) is enabled or not.
- *
- * This mode is a hybrid of xAPIC and x2APIC modes, some caveats:
- * 1. MSRs are used even ones that are missing (illegal) in x2APIC like DFR.
- * 2. A single ICR is used by the guest to send IPIs rather than 2 ICR writes.
- * 3. It is unclear what the behaviour will be when invalid bits are set,
- *    currently we follow x2APIC behaviour of causing a \#GP.
- *
- * @param   pVM                 The cross context VM structure.
- * @param   fHyperVCompatMode   Whether the compatibility mode is enabled.
- */
-VMMR3_INT_DECL(void) APICR3HvSetCompatMode(PVM pVM, bool fHyperVCompatMode)
-{
-    Assert(pVM);
+ * @interface_method_impl{PDMAPICBACKEND,pfnHvSetCompatMode}
+ */
+DECLCALLBACK(int) apicR3HvSetCompatMode(PVM pVM, bool fHyperVCompatMode)
+{
     PAPIC pApic = VM_TO_APIC(pVM);
+    if (pApic->fHyperVCompatMode ^ fHyperVCompatMode)
+        LogRel(("APIC: %s Hyper-V x2APIC compatibility mode\n", fHyperVCompatMode ? "Enabling" : "Disabling"));
+
     pApic->fHyperVCompatMode = fHyperVCompatMode;
-
-    if (fHyperVCompatMode)
-        LogRel(("APIC: Enabling Hyper-V x2APIC compatibility mode\n"));
-
     int rc = CPUMR3MsrRangesInsert(pVM, &g_MsrRange_x2Apic);
     AssertLogRelRC(rc);
+    return rc;
 }
 
@@ -977,5 +953,5 @@
 
         /* Update interrupts from the pending-interrupts bitmaps to the IRR. */
-        APICUpdatePendingInterrupts(pVCpu);
+        PDMApicUpdatePendingInterrupts(pVCpu);
 
         /* Save the auxiliary data. */
@@ -1139,5 +1115,5 @@
         uint8_t uVector = XAPIC_LVT_GET_VECTOR(uLvtTimer);
         Log2(("APIC%u: apicR3TimerCallback: Raising timer interrupt. uVector=%#x\n", pVCpu->idCpu, uVector));
-        apicPostInterrupt(pVCpu, uVector, XAPICTRIGGERMODE_EDGE, 0 /* uSrcTag */);
+        apicPostInterrupt(pVCpu, uVector, XAPICTRIGGERMODE_EDGE, false /* fAutoEoi */, 0 /* uSrcTag */);
     }
 
@@ -1471,4 +1447,7 @@
      */
     rc = PDMDevHlpApicRegister(pDevIns);
+    AssertLogRelRCReturn(rc, rc);
+
+    rc = PDMApicRegisterBackend(pVM, PDMAPICBACKENDTYPE_VBOX, &g_ApicBackend);
     AssertLogRelRCReturn(rc, rc);
 
@@ -1586,5 +1565,5 @@
 
         APIC_PROF_COUNTER(&pApicCpu->StatUpdatePendingIntrs,
-                                                       "/PROF/CPU%u/APIC/UpdatePendingInterrupts", "Profiling of APICUpdatePendingInterrupts");
+                                                       "/PROF/CPU%u/APIC/UpdatePendingInterrupts", "Profiling of apicUpdatePendingInterrupts");
         APIC_PROF_COUNTER(&pApicCpu->StatPostIntr,     "/PROF/CPU%u/APIC/PostInterrupt",  "Profiling of APICPostInterrupt");
 #endif
Index: trunk/src/VBox/VMM/VMMR3/CPUM.cpp
===================================================================
--- trunk/src/VBox/VMM/VMMR3/CPUM.cpp	(revision 107112)
+++ trunk/src/VBox/VMM/VMMR3/CPUM.cpp	(revision 107113)
@@ -122,5 +122,5 @@
 #include <VBox/vmm/cpumctx-v1_6.h>
 #include <VBox/vmm/pgm.h>
-#include <VBox/vmm/apic.h>
+#include <VBox/vmm/pdmapic.h>
 #include <VBox/vmm/mm.h>
 #include <VBox/vmm/em.h>
Index: trunk/src/VBox/VMM/VMMR3/CPUMDbg-armv8.cpp
===================================================================
--- trunk/src/VBox/VMM/VMMR3/CPUMDbg-armv8.cpp	(revision 107112)
+++ trunk/src/VBox/VMM/VMMR3/CPUMDbg-armv8.cpp	(revision 107113)
@@ -33,5 +33,5 @@
 #include <VBox/vmm/cpum.h>
 #include <VBox/vmm/dbgf.h>
-#include <VBox/vmm/apic.h>
+#include <VBox/vmm/pdmapic.h>
 #include "CPUMInternal-armv8.h"
 #include <VBox/vmm/vm.h>
Index: trunk/src/VBox/VMM/VMMR3/CPUMDbg.cpp
===================================================================
--- trunk/src/VBox/VMM/VMMR3/CPUMDbg.cpp	(revision 107112)
+++ trunk/src/VBox/VMM/VMMR3/CPUMDbg.cpp	(revision 107113)
@@ -33,5 +33,5 @@
 #include <VBox/vmm/cpum.h>
 #include <VBox/vmm/dbgf.h>
-#include <VBox/vmm/apic.h>
+#include <VBox/vmm/pdmapic.h>
 #include "CPUMInternal.h"
 #include <VBox/vmm/vm.h>
@@ -501,5 +501,5 @@
         case 3: rc = CPUMSetGuestCR3(pVCpu, u64Value); break;
         case 4: rc = CPUMSetGuestCR4(pVCpu, u64Value); break;
-        case 8: rc = APICSetTpr(pVCpu, (uint8_t)(u64Value << 4)); break;
+        case 8: rc = PDMApicSetTpr(pVCpu, (uint8_t)(u64Value << 4)); break;
         default:
             AssertFailedReturn(VERR_IPE_NOT_REACHED_DEFAULT_CASE);
Index: trunk/src/VBox/VMM/VMMR3/DBGFCoreWrite.cpp
===================================================================
--- trunk/src/VBox/VMM/VMMR3/DBGFCoreWrite.cpp	(revision 107112)
+++ trunk/src/VBox/VMM/VMMR3/DBGFCoreWrite.cpp	(revision 107113)
@@ -69,5 +69,5 @@
 #include <VBox/vmm/cpum.h>
 #include <VBox/vmm/pgm.h>
-#include <VBox/vmm/apic.h>
+#include <VBox/vmm/pdmapic.h>
 #include <VBox/vmm/dbgf.h>
 #include <VBox/vmm/dbgfcorefmt.h>
@@ -390,5 +390,5 @@
     pDbgfCpu->msrSFMASK       = pCtx->msrSFMASK;
     pDbgfCpu->msrKernelGSBase = pCtx->msrKERNELGSBASE;
-    pDbgfCpu->msrApicBase     = APICGetBaseMsrNoCheck(pVCpu);
+    pDbgfCpu->msrApicBase     = PDMApicGetBaseMsrNoCheck(pVCpu);
     pDbgfCpu->msrTscAux       = CPUMGetGuestTscAux(pVCpu);
     pDbgfCpu->aXcr[0]         = pCtx->aXcr[0];
Index: trunk/src/VBox/VMM/VMMR3/EM.cpp
===================================================================
--- trunk/src/VBox/VMM/VMMR3/EM.cpp	(revision 107112)
+++ trunk/src/VBox/VMM/VMMR3/EM.cpp	(revision 107113)
@@ -57,5 +57,5 @@
 #include <VBox/vmm/dbgf.h>
 #include <VBox/vmm/pgm.h>
-#include <VBox/vmm/apic.h>
+#include <VBox/vmm/pdmapic.h>
 #include <VBox/vmm/tm.h>
 #include <VBox/vmm/mm.h>
@@ -1659,5 +1659,5 @@
          */
         if (VMCPU_FF_TEST_AND_CLEAR(pVCpu, VMCPU_FF_UPDATE_APIC))
-            APICUpdatePendingInterrupts(pVCpu);
+            PDMApicUpdatePendingInterrupts(pVCpu);
 
         /*
@@ -2624,5 +2624,5 @@
                         {
                             if (VMCPU_FF_TEST_AND_CLEAR(pVCpu, VMCPU_FF_UPDATE_APIC))
-                                APICUpdatePendingInterrupts(pVCpu);
+                                PDMApicUpdatePendingInterrupts(pVCpu);
 
                             if (VMCPU_FF_IS_ANY_SET(pVCpu, VMCPU_FF_INTERRUPT_APIC | VMCPU_FF_INTERRUPT_PIC
Index: trunk/src/VBox/VMM/VMMR3/GIMHv.cpp
===================================================================
--- trunk/src/VBox/VMM/VMMR3/GIMHv.cpp	(revision 107112)
+++ trunk/src/VBox/VMM/VMMR3/GIMHv.cpp	(revision 107113)
@@ -31,5 +31,5 @@
 *********************************************************************************************************************************/
 #define LOG_GROUP LOG_GROUP_GIM
-#include <VBox/vmm/apic.h>
+#include <VBox/vmm/pdmapic.h>
 #include <VBox/vmm/gim.h>
 #include <VBox/vmm/cpum.h>
@@ -598,5 +598,5 @@
      */
     if (pHv->uHyperHints & GIM_HV_HINT_X2APIC_MSRS)
-        APICR3HvSetCompatMode(pVM, true);
+        PDMR3ApicHvSetCompatMode(pVM, true);
 
     return rc;
@@ -1121,5 +1121,5 @@
             uint8_t const uVector  = MSR_GIM_HV_SINT_GET_VECTOR(uSint);
             bool const    fAutoEoi = MSR_GIM_HV_SINT_IS_AUTOEOI(uSint);
-            APICHvSendInterrupt(pVCpu, uVector, fAutoEoi, XAPICTRIGGERMODE_EDGE);
+            PDMApicHvSendInterrupt(pVCpu, uVector, fAutoEoi, XAPICTRIGGERMODE_EDGE);
         }
     }
Index: trunk/src/VBox/VMM/VMMR3/GIMMinimal.cpp
===================================================================
--- trunk/src/VBox/VMM/VMMR3/GIMMinimal.cpp	(revision 107112)
+++ trunk/src/VBox/VMM/VMMR3/GIMMinimal.cpp	(revision 107113)
@@ -34,5 +34,5 @@
 #include <VBox/vmm/cpum.h>
 #include <VBox/vmm/tm.h>
-#include <VBox/vmm/apic.h>
+#include <VBox/vmm/pdmapic.h>
 #include "GIMInternal.h"
 #include <VBox/vmm/vm.h>
@@ -106,5 +106,5 @@
      *
      * This is done in the init. completed routine as we need PDM to be
-     * initialized (otherwise APICGetTimerFreq() would fail).
+     * initialized (otherwise PDMApicGetTimerFreq() would fail).
      */
     CPUMCPUIDLEAF HyperLeaf;
@@ -123,5 +123,5 @@
          */
         uint64_t uApicFreq;
-        rc = APICGetTimerFreq(pVM, &uApicFreq);
+        rc = PDMApicGetTimerFreq(pVM, &uApicFreq);
         AssertLogRelRCReturn(rc, rc);
 
Index: trunk/src/VBox/VMM/VMMR3/NEMR3Native-darwin.cpp
===================================================================
--- trunk/src/VBox/VMM/VMMR3/NEMR3Native-darwin.cpp	(revision 107112)
+++ trunk/src/VBox/VMM/VMMR3/NEMR3Native-darwin.cpp	(revision 107113)
@@ -40,5 +40,5 @@
 #include <VBox/vmm/iem.h>
 #include <VBox/vmm/em.h>
-#include <VBox/vmm/apic.h>
+#include <VBox/vmm/pdmapic.h>
 #include <VBox/vmm/pdm.h>
 #include <VBox/vmm/hm.h>
@@ -1859,5 +1859,5 @@
         vmxHCExportGuestApicTpr(pVCpu, pVmxTransient);
 
-        rc = APICGetTpr(pVCpu, &pVmxTransient->u8GuestTpr, NULL /*pfPending*/, NULL /*pu8PendingIntr*/);
+        rc = PDMApicGetTpr(pVCpu, &pVmxTransient->u8GuestTpr, NULL /*pfPending*/, NULL /*pu8PendingIntr*/);
         AssertRC(rc);
 
Index: trunk/src/VBox/VMM/VMMR3/NEMR3Native-linux.cpp
===================================================================
--- trunk/src/VBox/VMM/VMMR3/NEMR3Native-linux.cpp	(revision 107112)
+++ trunk/src/VBox/VMM/VMMR3/NEMR3Native-linux.cpp	(revision 107113)
@@ -35,5 +35,5 @@
 #include <VBox/vmm/iem.h>
 #include <VBox/vmm/em.h>
-#include <VBox/vmm/apic.h>
+#include <VBox/vmm/pdmapic.h>
 #include <VBox/vmm/pdm.h>
 #include <VBox/vmm/trpm.h>
@@ -704,5 +704,5 @@
      * VBox always has the right base register value, so it's one directional.
      */
-    uint64_t const uApicBase = APICGetBaseMsrNoCheck(pVCpu);
+    uint64_t const uApicBase = PDMApicGetBaseMsrNoCheck(pVCpu);
     if (   (fExtrn & (  CPUMCTX_EXTRN_SREG_MASK | CPUMCTX_EXTRN_TABLE_MASK | CPUMCTX_EXTRN_CR_MASK
                       | CPUMCTX_EXTRN_EFER      | CPUMCTX_EXTRN_APIC_TPR))
@@ -1082,5 +1082,5 @@
     if (VMCPU_FF_TEST_AND_CLEAR(pVCpu, VMCPU_FF_UPDATE_APIC))
     {
-        APICUpdatePendingInterrupts(pVCpu);
+        PDMApicUpdatePendingInterrupts(pVCpu);
         if (!VMCPU_FF_IS_ANY_SET(pVCpu, VMCPU_FF_INTERRUPT_APIC | VMCPU_FF_INTERRUPT_PIC
                                       | VMCPU_FF_INTERRUPT_NMI  | VMCPU_FF_INTERRUPT_SMI))
@@ -1157,5 +1157,5 @@
                  */
                 if (pVCpu->cpum.GstCtx.fExtrn & CPUMCTX_EXTRN_APIC_TPR)
-                    APICSetTpr(pVCpu, (uint8_t)pRun->cr8 << 4);
+                    PDMApicSetTpr(pVCpu, (uint8_t)pRun->cr8 << 4);
 
                 uint8_t bInterrupt;
Index: trunk/src/VBox/VMM/VMMR3/NEMR3Native-win-armv8.cpp
===================================================================
--- trunk/src/VBox/VMM/VMMR3/NEMR3Native-win-armv8.cpp	(revision 107112)
+++ trunk/src/VBox/VMM/VMMR3/NEMR3Native-win-armv8.cpp	(revision 107113)
@@ -58,5 +58,5 @@
 #include <VBox/vmm/iem.h>
 #include <VBox/vmm/em.h>
-#include <VBox/vmm/apic.h>
+#include <VBox/vmm/pdmapic.h>
 #include <VBox/vmm/pdm.h>
 #include <VBox/vmm/dbgftrace.h>
Index: trunk/src/VBox/VMM/VMMR3/NEMR3Native-win.cpp
===================================================================
--- trunk/src/VBox/VMM/VMMR3/NEMR3Native-win.cpp	(revision 107112)
+++ trunk/src/VBox/VMM/VMMR3/NEMR3Native-win.cpp	(revision 107113)
@@ -58,5 +58,5 @@
 #include <VBox/vmm/iem.h>
 #include <VBox/vmm/em.h>
-#include <VBox/vmm/apic.h>
+#include <VBox/vmm/pdmapic.h>
 #include <VBox/vmm/pdm.h>
 #include <VBox/vmm/dbgftrace.h>
Index: trunk/src/VBox/VMM/VMMR3/PDM.cpp
===================================================================
--- trunk/src/VBox/VMM/VMMR3/PDM.cpp	(revision 107112)
+++ trunk/src/VBox/VMM/VMMR3/PDM.cpp	(revision 107113)
@@ -605,6 +605,6 @@
      * The registered APIC.
      */
-    if (pVM->pdm.s.Apic.pDevInsRC)
-        pVM->pdm.s.Apic.pDevInsRC           += offDelta;
+    if (pVM->pdm.s.Ic.pDevInsRC)
+        pVM->pdm.s.Ic.pDevInsRC             += offDelta;
 
     /*
Index: trunk/src/VBox/VMM/VMMR3/PDMDevHlp.cpp
===================================================================
--- trunk/src/VBox/VMM/VMMR3/PDMDevHlp.cpp	(revision 107112)
+++ trunk/src/VBox/VMM/VMMR3/PDMDevHlp.cpp	(revision 107113)
@@ -4193,5 +4193,5 @@
      * as they need to communicate and share state easily.
      */
-    AssertMsgReturnStmt(pVM->pdm.s.Apic.pDevInsR3 == NULL,
+    AssertMsgReturnStmt(pVM->pdm.s.Ic.pDevInsR3 == NULL,
                         ("%s/%u: Only one APIC device is supported!\n", pDevIns->pReg->szName, pDevIns->iInstance),
                         RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw),
@@ -4201,8 +4201,8 @@
      * Set the ring-3 and raw-mode bits, leave the ring-0 to ring-0 setup.
      */
-    pVM->pdm.s.Apic.pDevInsR3 = pDevIns;
+    pVM->pdm.s.Ic.pDevInsR3 = pDevIns;
 #ifdef VBOX_WITH_RAW_MODE_KEEP
-    pVM->pdm.s.Apic.pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);
-    Assert(pVM->pdm.s.Apic.pDevInsRC || !VM_IS_RAW_MODE_ENABLED(pVM));
+    pVM->pdm.s.Ic.pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);
+    Assert(pVM->pdm.s.Ic.pDevInsRC || !VM_IS_RAW_MODE_ENABLED(pVM));
 #endif
 
@@ -4245,5 +4245,5 @@
      * If the I/O APIC does GC stuff so must the APIC.
      */
-    AssertMsgReturnStmt(pVM->pdm.s.Apic.pDevInsR3 != NULL,
+    AssertMsgReturnStmt(pVM->pdm.s.Ic.pDevInsR3 != NULL,
                         ("Configuration error / Init order error! No APIC!\n"),
                         RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw),
Index: trunk/src/VBox/VMM/VMMR3/PDMDevMiscHlp.cpp
===================================================================
--- trunk/src/VBox/VMM/VMMR3/PDMDevMiscHlp.cpp	(revision 107112)
+++ trunk/src/VBox/VMM/VMMR3/PDMDevMiscHlp.cpp	(revision 107113)
@@ -36,5 +36,5 @@
 #include <VBox/vmm/hm.h>
 #ifndef VBOX_VMM_TARGET_ARMV8
-# include <VBox/vmm/apic.h>
+# include <VBox/vmm/pdmapic.h>
 #endif
 #include <VBox/vmm/vm.h>
@@ -72,5 +72,5 @@
 #else
     PVMCPU pVCpu = pVM->apCpusR3[0];  /* for PIC we always deliver to CPU 0, SMP uses APIC */
-    APICLocalInterrupt(pVCpu, 0 /* u8Pin */, 1 /* u8Level */, VINF_SUCCESS /* rcRZ */);
+    PDMApicSetLocalInterrupt(pVCpu, 0 /* u8Pin */, 1 /* u8Level */, VINF_SUCCESS /* rcRZ */);
 #endif
 }
@@ -91,5 +91,5 @@
 #else
     PVMCPU pVCpu = pVM->apCpusR3[0];  /* for PIC we always deliver to CPU 0, SMP uses APIC */
-    APICLocalInterrupt(pVCpu, 0 /* u8Pin */,  0 /* u8Level */, VINF_SUCCESS /* rcRZ */);
+    PDMApicSetLocalInterrupt(pVCpu, 0 /* u8Pin */,  0 /* u8Level */, VINF_SUCCESS /* rcRZ */);
 #endif
 }
@@ -146,5 +146,5 @@
 #else
     PVM pVM = pDevIns->Internal.s.pVMR3;
-    return APICBusDeliver(pVM, u8Dest, u8DestMode, u8DeliveryMode, uVector, u8Polarity, u8TriggerMode, uTagSrc);
+    return PDMApicBusDeliver(pVM, u8Dest, u8DestMode, u8DeliveryMode, uVector, u8Polarity, u8TriggerMode, uTagSrc);
 #endif
 }
Index: trunk/src/VBox/VMM/VMMR3/PDMDevice.cpp
===================================================================
--- trunk/src/VBox/VMM/VMMR3/PDMDevice.cpp	(revision 107112)
+++ trunk/src/VBox/VMM/VMMR3/PDMDevice.cpp	(revision 107113)
@@ -38,5 +38,5 @@
 # include <VBox/vmm/pmu.h>
 #else
-# include <VBox/vmm/apic.h>
+# include <VBox/vmm/pdmapic.h>
 #endif
 #include <VBox/vmm/cfgm.h>
Index: trunk/src/VBox/VMM/VMMR3/VM.cpp
===================================================================
--- trunk/src/VBox/VMM/VMMR3/VM.cpp	(revision 107112)
+++ trunk/src/VBox/VMM/VMMR3/VM.cpp	(revision 107113)
@@ -69,5 +69,5 @@
 #include <VBox/vmm/iem.h>
 #include <VBox/vmm/nem.h>
-#include <VBox/vmm/apic.h>
+#include <VBox/vmm/pdmapic.h>
 #include <VBox/vmm/tm.h>
 #include <VBox/vmm/stam.h>
Index: trunk/src/VBox/VMM/VMMR3/VMM.cpp
===================================================================
--- trunk/src/VBox/VMM/VMMR3/VMM.cpp	(revision 107112)
+++ trunk/src/VBox/VMM/VMMR3/VMM.cpp	(revision 107113)
@@ -133,5 +133,5 @@
 # include <VBox/vmm/gic.h>
 #else
-# include <VBox/vmm/apic.h>
+# include <VBox/vmm/pdmapic.h>
 #endif
 #include <VBox/vmm/ssm.h>
@@ -1435,5 +1435,5 @@
     PDMR3ResetCpu(pVCpu);   /* Only clears pending interrupts force flags */
 # if !defined(VBOX_VMM_TARGET_ARMV8)
-    APICR3InitIpi(pVCpu);
+    PDMR3ApicInitIpi(pVCpu);
 # endif
     TRPMR3ResetCpu(pVCpu);
