Index: trunk/src/VBox/Devices/EFI/FirmwareNew/OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.c
===================================================================
--- trunk/src/VBox/Devices/EFI/FirmwareNew/OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.c	(revision 77728)
+++ trunk/src/VBox/Devices/EFI/FirmwareNew/OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.c	(revision 77729)
@@ -49,4 +49,8 @@
   switch (HostBridgeDevId) {
     case INTEL_82441_DEVICE_ID:
+#ifdef VBOX
+    // HACK ALERT! There is no host bridge device in the PCIe chipset, and the same PIIX4 PM device is used.
+    case 0xffff:
+#endif
       Pmba       = POWER_MGMT_REGISTER_PIIX4 (PIIX4_PMBA);
       PmbaAndVal = ~(UINT32)PIIX4_PMBA_MASK;
Index: trunk/src/VBox/Devices/EFI/FirmwareNew/OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.c
===================================================================
--- trunk/src/VBox/Devices/EFI/FirmwareNew/OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.c	(revision 77728)
+++ trunk/src/VBox/Devices/EFI/FirmwareNew/OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.c	(revision 77729)
@@ -47,4 +47,8 @@
   switch (HostBridgeDevId) {
     case INTEL_82441_DEVICE_ID:
+#ifdef VBOX
+    // HACK ALERT! There is no host bridge device in the PCIe chipset, and the same PIIX4 PM device is used.
+    case 0xffff:
+#endif
       Pmba       = POWER_MGMT_REGISTER_PIIX4 (PIIX4_PMBA);
       PmbaAndVal = ~(UINT32)PIIX4_PMBA_MASK;
Index: trunk/src/VBox/Devices/EFI/FirmwareNew/OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c
===================================================================
--- trunk/src/VBox/Devices/EFI/FirmwareNew/OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c	(revision 77728)
+++ trunk/src/VBox/Devices/EFI/FirmwareNew/OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c	(revision 77729)
@@ -51,10 +51,16 @@
   HostBridgeDevId = PcdGet16 (PcdOvmfHostBridgePciDevId);
   switch (HostBridgeDevId) {
+#ifdef VBOX
+    // HACK ALERT! In the PCIe chipset, the same PIIX4 PM device is used.
+    case INTEL_Q35_MCH_DEVICE_ID:
+#endif
     case INTEL_82441_DEVICE_ID:
       Pmba = POWER_MGMT_REGISTER_PIIX4 (PIIX4_PMBA);
       break;
+#ifndef VBOX
     case INTEL_Q35_MCH_DEVICE_ID:
       Pmba = POWER_MGMT_REGISTER_Q35 (ICH9_PMBASE);
       break;
+#endif
     default:
       DEBUG ((EFI_D_ERROR, "%a: Unknown Host Bridge Device ID: 0x%04x\n",
Index: trunk/src/VBox/Devices/EFI/FirmwareNew/OvmfPkg/OvmfPkgIa32.dsc
===================================================================
--- trunk/src/VBox/Devices/EFI/FirmwareNew/OvmfPkg/OvmfPkgIa32.dsc	(revision 77728)
+++ trunk/src/VBox/Devices/EFI/FirmwareNew/OvmfPkg/OvmfPkgIa32.dsc	(revision 77729)
@@ -526,4 +526,5 @@
 !endif
 
+!ifndef $(VBOX)
   # This PCD is used to set the base address of the PCI express hierarchy. It
   # is only consulted when OVMF runs on Q35. In that case it is programmed into
@@ -533,4 +534,5 @@
   # never lets the RAM below 4 GB exceed 2 GB.
   gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress|0x80000000
+!endif
 
 !ifdef $(SOURCE_DEBUG_ENABLE)
@@ -613,4 +615,16 @@
 
   gEfiSecurityPkgTokenSpaceGuid.PcdOptionRomImageVerificationPolicy|0x00
+
+!ifdef $(VBOX)
+  # This PCD is used to set the base address of the PCI express hierarchy. It
+  # is only consulted when OVMF runs on Q35. In that case it is programmed into
+  # the PCIEXBAR register.
+  #
+  # On Q35 machine types that QEMU intends to support in the long term, QEMU
+  # never lets the RAM below 4 GB exceed 2 GB.
+  #
+  # On VirtualBox it is dynamic.
+  gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress|0x80000000
+!endif
 
 ################################################################################
Index: trunk/src/VBox/Devices/EFI/FirmwareNew/OvmfPkg/OvmfPkgX64.dsc
===================================================================
--- trunk/src/VBox/Devices/EFI/FirmwareNew/OvmfPkg/OvmfPkgX64.dsc	(revision 77728)
+++ trunk/src/VBox/Devices/EFI/FirmwareNew/OvmfPkg/OvmfPkgX64.dsc	(revision 77729)
@@ -44,4 +44,6 @@
   DEFINE SMM_REQUIRE             = FALSE
   DEFINE TLS_ENABLE              = FALSE
+
+  DEFINE SOURCE_DEBUG_ENABLE     = TRUE
 
   #
@@ -104,4 +106,10 @@
    MSFT:*_*_*_CC_FLAGS = -DVBOX -DIPRT_NO_CRT -DRT_OS_UEFI -DARCH_BITS=64 -DHC_ARCH_BITS=64 -DVBOX_REV=$(VBOX_REV)
   INTEL:*_*_*_CC_FLAGS = -DVBOX -DIPRT_NO_CRT -DRT_OS_UEFI -DARCH_BITS=64 -DHC_ARCH_BITS=64 -DVBOX_REV=$(VBOX_REV)
+
+!ifdef $(SOURCE_DEBUG_ENABLE)
+   # Get much better source-level debugging
+   MSFT:DEBUG_*_*_CC_FLAGS = /Od
+!endif
+
 !endif
 
@@ -134,5 +142,9 @@
   PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
 !else
+!ifdef $(SOURCE_DEBUG_ENABLE)
+  PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
+!else
   PeCoffLib|VBoxPkg/Library/VBoxPeCoffLib/VBoxPeCoffLib.inf
+!endif
 !endif
   CacheMaintenanceLib|MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheMaintenanceLib.inf
@@ -182,11 +194,11 @@
   FrameBufferBltLib|MdeModulePkg/Library/FrameBufferBltLib/FrameBufferBltLib.inf
 
+!ifdef $(SOURCE_DEBUG_ENABLE)
+  PeCoffExtraActionLib|SourceLevelDebugPkg/Library/PeCoffExtraActionLibDebug/PeCoffExtraActionLibDebug.inf
+  DebugCommunicationLib|SourceLevelDebugPkg/Library/DebugCommunicationLibSerialPort/DebugCommunicationLibSerialPort.inf
+!else
 !ifdef $(VBOX)
   PeCoffExtraActionLib|VBoxPkg/Library/VBoxPeCoffExtraActionLib/VBoxPeCoffExtraActionLib.inf
   DebugAgentLib|VBoxPkg/Library/VBoxDebugAgentLib/VBoxDebugAgentLib.inf
-!else
-!ifdef $(SOURCE_DEBUG_ENABLE)
-  PeCoffExtraActionLib|SourceLevelDebugPkg/Library/PeCoffExtraActionLibDebug/PeCoffExtraActionLibDebug.inf
-  DebugCommunicationLib|SourceLevelDebugPkg/Library/DebugCommunicationLibSerialPort/DebugCommunicationLibSerialPort.inf
 !else
   PeCoffExtraActionLib|MdePkg/Library/BasePeCoffExtraActionLibNull/BasePeCoffExtraActionLibNull.inf
@@ -247,12 +259,14 @@
 !endif
 !else
+!ifdef $(SOURCE_DEBUG_ENABLE)
+  DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf
+!else
   DebugLib|VBoxPkg/Library/VBoxDebugLib/VBoxDebugLib.inf
+!endif
 !endif
   ReportStatusCodeLib|MdeModulePkg/Library/PeiReportStatusCodeLib/PeiReportStatusCodeLib.inf
   ExtractGuidedSectionLib|MdePkg/Library/BaseExtractGuidedSectionLib/BaseExtractGuidedSectionLib.inf
-!ifdef $(VBOX)
 !ifdef $(SOURCE_DEBUG_ENABLE)
   DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgentLib.inf
-!endif
 !endif
   HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf
@@ -279,6 +293,11 @@
   PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
 !else
+!ifdef $(SOURCE_DEBUG_ENABLE)
+  DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf
+  PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
+!else
   DebugLib|VBoxPkg/Library/VBoxDebugLib/VBoxDebugLib.inf
   PeCoffLib|VBoxPkg/Library/VBoxPeCoffLib/VBoxPeCoffLib.inf
+!endif
 !endif
 
@@ -297,8 +316,14 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
-!endif  PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
+!endif
+  PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
+!else
+!ifdef $(SOURCE_DEBUG_ENABLE)
+  DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf
+  PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
 !else
   DebugLib|VBoxPkg/Library/VBoxDebugLib/VBoxDebugLib.inf
   PeCoffLib|VBoxPkg/Library/VBoxPeCoffLib/VBoxPeCoffLib.inf
+!endif
 !endif
   PeiResourcePublicationLib|MdePkg/Library/PeiResourcePublicationLib/PeiResourcePublicationLib.inf
@@ -325,5 +350,9 @@
 !endif
 !else
+!ifdef $(SOURCE_DEBUG_ENABLE)
+  DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf
+!else
   DebugLib|VBoxPkg/Library/VBoxDebugLib/VBoxDebugLib.inf
+!endif
 !endif
   ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.inf
@@ -348,5 +377,9 @@
 !endif
 !else
+!ifdef $(SOURCE_DEBUG_ENABLE)
+  DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf
+!else
   DebugLib|VBoxPkg/Library/VBoxDebugLib/VBoxDebugLib.inf
+!endif
 !endif
   UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf
@@ -369,5 +402,9 @@
 !endif
 !else
+!ifdef $(SOURCE_DEBUG_ENABLE)
+  DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf
+!else
   DebugLib|VBoxPkg/Library/VBoxDebugLib/VBoxDebugLib.inf
+!endif
 !endif
   UefiScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf
@@ -388,5 +425,9 @@
 !endif
 !else
+!ifdef $(SOURCE_DEBUG_ENABLE)
+  DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf
+!else
   DebugLib|VBoxPkg/Library/VBoxDebugLib/VBoxDebugLib.inf
+!endif
 !endif
   NetLib|MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf
@@ -422,5 +463,9 @@
 !endif
 !else
+!ifdef $(SOURCE_DEBUG_ENABLE)
+  DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf
+!else
   DebugLib|VBoxPkg/Library/VBoxDebugLib/VBoxDebugLib.inf
+!endif
 !endif
   PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
@@ -530,4 +575,5 @@
 !endif
 
+!ifndef $(VBOX)
   # This PCD is used to set the base address of the PCI express hierarchy. It
   # is only consulted when OVMF runs on Q35. In that case it is programmed into
@@ -537,4 +583,5 @@
   # never lets the RAM below 4 GB exceed 2 GB.
   gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress|0x80000000
+!endif
 
 !ifdef $(SOURCE_DEBUG_ENABLE)
@@ -619,4 +666,13 @@
 
   gEfiSecurityPkgTokenSpaceGuid.PcdOptionRomImageVerificationPolicy|0x00
+
+!ifdef $(VBOX)
+  # This PCD is used to set the base address of the PCI express hierarchy. It
+  # is only consulted when OVMF runs on Q35. In that case it is programmed into
+  # the PCIEXBAR register.
+  #
+  # On VirtualBox it is dynamic.
+  gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress|0x80000000
+!endif
 
 ################################################################################
Index: trunk/src/VBox/Devices/EFI/FirmwareNew/OvmfPkg/PlatformPei/Platform.c
===================================================================
--- trunk/src/VBox/Devices/EFI/FirmwareNew/OvmfPkg/PlatformPei/Platform.c	(revision 77728)
+++ trunk/src/VBox/Devices/EFI/FirmwareNew/OvmfPkg/PlatformPei/Platform.c	(revision 77729)
@@ -271,5 +271,5 @@
       // the base of the 32-bit PCI host aperture.
       //
-      PciExBarBase = FixedPcdGet64 (PcdPciExpressBaseAddress);
+      PciExBarBase = PcdGet64 (PcdPciExpressBaseAddress);
       ASSERT (TopOfLowRam <= PciExBarBase);
       ASSERT (PciExBarBase <= MAX_UINT32 - SIZE_256MB);
@@ -309,4 +309,5 @@
       AddIoMemoryRangeHob (TopOfLowRam, McfgBase);
     AddIoMemoryRangeHob (McfgBase + McfgSize, 0xFC000000);
+    PcdSet64S (PcdPciExpressBaseAddress, McfgBase);
 #else
     AddIoMemoryRangeHob (TopOfLowRam < BASE_2GB ?
@@ -470,5 +471,5 @@
   // for DXE's page tables to cover the MMCONFIG area.
   //
-  PciExBarBase.Uint64 = FixedPcdGet64 (PcdPciExpressBaseAddress);
+  PciExBarBase.Uint64 = PcdGet64 (PcdPciExpressBaseAddress);
   ASSERT ((PciExBarBase.Uint32[1] & MCH_PCIEXBAR_HIGHMASK) == 0);
   ASSERT ((PciExBarBase.Uint32[0] & MCH_PCIEXBAR_LOWMASK) == 0);
@@ -755,4 +756,9 @@
   //
   mHostBridgeDevId = PciRead16 (OVMF_HOSTBRIDGE_DID);
+#ifdef VBOX
+  // HACK ALERT! There is no host bridge device in the PCIe chipset, but we pretend it's a 3 Series chip.
+  if (mHostBridgeDevId == 0xffff)
+        mHostBridgeDevId = INTEL_Q35_MCH_DEVICE_ID;
+#endif
 
   if (FeaturePcdGet (PcdSmmSmramRequire)) {
Index: trunk/src/VBox/Devices/EFI/FirmwareNew/OvmfPkg/PlatformPei/PlatformPei.inf
===================================================================
--- trunk/src/VBox/Devices/EFI/FirmwareNew/OvmfPkg/PlatformPei/PlatformPei.inf	(revision 77728)
+++ trunk/src/VBox/Devices/EFI/FirmwareNew/OvmfPkg/PlatformPei/PlatformPei.inf	(revision 77729)
@@ -89,4 +89,5 @@
   gUefiOvmfPkgTokenSpaceGuid.PcdQ35TsegMbytes
   gEfiMdePkgTokenSpaceGuid.PcdGuidedExtractHandlerTableAddress
+  gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress
   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize
   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize
@@ -105,6 +106,6 @@
   gUefiCpuPkgTokenSpaceGuid.PcdCpuApStackSize
 
-[FixedPcd]
-  gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress
+#[FixedPcd]
+#  gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress
 
 [FeaturePcd]
