Index: trunk/include/VBox/apic.mac
===================================================================
--- trunk/include/VBox/apic.mac	(revision 45693)
+++ trunk/include/VBox/apic.mac	(revision 45701)
@@ -2,6 +2,6 @@
 %define ___VBox_apic_h
 %define APIC_REG_VERSION                        0x0030
-%define   APIC_REG_VERSION_GET_VER(u32)         (u32 & 0xff)
-%define   APIC_REG_VERSION_GET_MAX_LVT(u32)     ((u32 & 0xff0000) >> 16)
+%define APIC_REG_VERSION_GET_VER(u32)           (u32 & 0xff)
+%define APIC_REG_VERSION_GET_MAX_LVT(u32)       ((u32 & 0xff0000) >> 16)
 %define APIC_REG_LVT_LINT0                      0x0350
 %define APIC_REG_LVT_LINT1                      0x0360
@@ -9,11 +9,11 @@
 %define APIC_REG_LVT_PC                         0x0340
 %define APIC_REG_LVT_THMR                       0x0330
-%define   APIC_REG_LVT_MODE_MASK                (RT_BIT(8)|RT_BIT(9)|RT_BIT(10))
-%define   APIC_REG_LVT_MODE_FIXED               0
-%define   APIC_REG_LVT_MODE_NMI                 (RT_BIT(10))
-%define   APIC_REG_LVT_MODE_EXTINT              (RT_BIT(8)|RT_BIT(9)|RT_BIT(10))
-%define   APIC_REG_LVT_PIN_POLARIY              RT_BIT(13)
-%define   APIC_REG_LVT_REMOTE_IRR               RT_BIT(14)
-%define   APIC_REG_LVT_LEVEL_TRIGGER            RT_BIT(15)
-%define   APIC_REG_LVT_MASKED                   RT_BIT(16)
+%define APIC_REG_LVT_MODE_MASK                  (RT_BIT(8) | RT_BIT(9) | RT_BIT(10))
+%define APIC_REG_LVT_MODE_FIXED                 0
+%define APIC_REG_LVT_MODE_NMI                   RT_BIT(10)
+%define APIC_REG_LVT_MODE_EXTINT                (RT_BIT(8) | RT_BIT(9) | RT_BIT(10))
+%define APIC_REG_LVT_PIN_POLARIY                RT_BIT(13)
+%define APIC_REG_LVT_REMOTE_IRR                 RT_BIT(14)
+%define APIC_REG_LVT_LEVEL_TRIGGER              RT_BIT(15)
+%define APIC_REG_LVT_MASKED                     RT_BIT(16)
 %endif
Index: trunk/include/VBox/err.h
===================================================================
--- trunk/include/VBox/err.h	(revision 45693)
+++ trunk/include/VBox/err.h	(revision 45701)
@@ -975,4 +975,6 @@
 /** Internal processing error \#3 in TRPM. */
 #define VERR_TRPM_IPE_3                     (-2409)
+/** Got into a part of TRPM that is not used when HM (VT-x/AMD-V) is enabled. */
+#define VERR_TRPM_HM_IPE                    (-2410)
 /** @} */
 
@@ -1006,4 +1008,6 @@
  * selectors. */
 #define VERR_SELM_GDT_TOO_FULL              (-2508)
+/** Got into a part of SELM that is not used when HM (VT-x/AMD-V) is enabled. */
+#define VERR_SELM_HM_IPE                    (-2509)
 /** @} */
 
@@ -1126,4 +1130,6 @@
 /** Reason for leaving RZ: Unknown call to ring-3. */
 #define VINF_VMM_UNKNOWN_RING3_CALL         (2714)
+/** Attempted to use stub switcher. */
+#define VERR_VMM_SWITCHER_STUB              (-2715)
 /** @} */
 
Index: trunk/include/VBox/err.mac
===================================================================
--- trunk/include/VBox/err.mac	(revision 45693)
+++ trunk/include/VBox/err.mac	(revision 45701)
@@ -20,4 +20,5 @@
 %define VERR_TOO_MANY_CPUS    (-1019)
 %define VERR_SERVICE_DISABLED    (-1020)
+%define VERR_NOT_SUP_IN_RAW_MODE    (-1021)
 %define VINF_EM_FIRST    1100
 %define VINF_EM_TERMINATE    1100
@@ -37,5 +38,5 @@
 %define VERR_EM_NO_MEMORY    (-1114)
 %define VINF_EM_RESCHEDULE_REM    1115
-%define VINF_EM_RESCHEDULE_HWACC    1116
+%define VINF_EM_RESCHEDULE_HM    1116
 %define VINF_EM_RESCHEDULE_RAW    1117
 %define VINF_EM_RESCHEDULE    1118
@@ -68,6 +69,6 @@
 %define VINF_EM_RAW_EMULATE_DBG_STEP    1151
 %define VINF_EM_HM_PATCH_TPR_INSTR    1152
-%define VERR_EM_INTERNAL_DISAS_ERROR    (-1153)
 %define VERR_EM_UNEXPECTED_MAPPING_CONFLICT    (-1154)
+%define VINF_EM_TRIPLE_FAULT    1155
 %define VERR_DBGF_NOT_ATTACHED    (-1200)
 %define VERR_DBGF_ALREADY_ATTACHED    (-1201)
@@ -119,8 +120,10 @@
 %define VINF_PATM_SPINLOCK_FAILED    (1429)
 %define VINF_PATCH_CONTINUE    (1430)
+%define VERR_PATM_HM_IPE    (-1431)
 %define VWRN_CSAM_TRAP_NOT_HANDLED    1500
 %define VWRN_CSAM_INSTRUCTION_PATCHED    1501
 %define VWRN_CSAM_PAGE_NOT_FOUND    1502
 %define VINF_CSAM_PENDING_ACTION    1503
+%define VERR_CSAM_HM_IPE    (-1504)
 %define VERR_PGM_MAPPING_CONFLICT    (-1600)
 %define VERR_PGM_HANDLER_PHYSICAL_NO_RAM_RANGE    (-1601)
@@ -356,4 +359,5 @@
 %define VERR_TRPM_IPE_2    (-2408)
 %define VERR_TRPM_IPE_3    (-2409)
+%define VERR_TRPM_HM_IPE    (-2410)
 %define VERR_SELM_SHADOW_GDT_WRITE    (-2500)
 %define VERR_SELM_SHADOW_LDT_WRITE    (-2501)
@@ -365,4 +369,5 @@
 %define VERR_SELM_GDT_READ_ERROR    (-2507)
 %define VERR_SELM_GDT_TOO_FULL    (-2508)
+%define VERR_SELM_HM_IPE    (-2509)
 %define VERR_IOM_INVALID_IOPORT_RANGE    (-2600)
 %define VERR_IOM_NO_R3_IOPORT_RANGE    (-2601)
@@ -408,4 +413,6 @@
 %define VINF_VMM_CALL_TRACER    (2712)
 %define VERR_VMM_SWITCHER_IPE_1    (-2713)
+%define VINF_VMM_UNKNOWN_RING3_CALL    (2714)
+%define VERR_VMM_SWITCHER_STUB    (-2715)
 %define VERR_PDM_NO_SUCH_LUN    (-2800)
 %define VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES    (-2801)
@@ -442,7 +449,5 @@
 %define VERR_PDM_DRIVER_DETACH_NOT_POSSIBLE    (-2832)
 %define VERR_PDM_NO_PCI_BUS    (-2833)
-%define VINF_PDM_PCI_PHYS_READ_BM_DISABLED    (2833)
 %define VERR_PDM_NOT_PCI_DEVICE    (-2834)
-%define VINF_PDM_PCI_PHYS_WRITE_BM_DISABLED    (2834)
 %define VERR_PDM_UNKNOWN_DEVREG_VERSION    (-2835)
 %define VERR_PDM_INVALID_DEVICE_REGISTRATION    (-2836)
@@ -502,4 +507,5 @@
 %define VERR_PDM_MISCONFIGURED_DRV_TRANSFORMATION    (-2889)
 %define VERR_PDM_CANNOT_TRANSFORM_REMOVED_DRIVER    (-2890)
+%define VERR_PDM_NOT_PCI_BUS_MASTER    (-2891)
 %define VERR_HGCM_SERVICE_NOT_FOUND    (-2900)
 %define VINF_HGCM_CLIENT_REJECTED    2901
@@ -684,5 +690,4 @@
 %define VERR_VMX_UNSUPPORTED_MODE    (-4004)
 %define VERR_VMX_UNABLE_TO_START_VM    (-4005)
-%define VERR_VMX_UNABLE_TO_RESUME_VM    (-4006)
 %define VERR_VMX_INVALID_HOST_STATE    (-4007)
 %define VERR_VMX_ILLEGAL_FEATURE_CONTROL_MSR    (-4008)
@@ -697,7 +702,7 @@
 %define VERR_VMX_UNEXPECTED_INTERRUPTION_EXIT_CODE    (-4017)
 %define VERR_VMX_NOT_IN_VMX_ROOT_MODE    (-4018)
-%define VERR_VMX_UNDEFINED_EXIT_CODE     (-4019)
-%define VINF_VMX_DOUBLE_FAULT              4020
-%define VERR_VMX_VMPTRLD_FAILED          (-4021)
+%define VERR_VMX_UNDEFINED_EXIT_CODE    (-4019)
+%define VINF_VMX_DOUBLE_FAULT    4020
+%define VERR_VMX_VMPTRLD_FAILED    (-4021)
 %define VERR_SVM_UNABLE_TO_START_VM    (-4050)
 %define VERR_SVM_ILLEGAL_EFER_MSR    (-4051)
@@ -705,4 +710,8 @@
 %define VERR_SVM_DISABLED    (-4053)
 %define VERR_SVM_IN_USE    (-4054)
+%define VERR_SVM_INVALID_PVMCB    (-4055)
+%define VERR_SVM_UNEXPECTED_EXIT    (-4056)
+%define VERR_SVM_UNEXPECTED_XCPT_EXIT    (-4057)
+%define VERR_SVM_UNEXPECTED_PATCH_TYPE    (-4058)
 %define VERR_HM_UNKNOWN_CPU    (-4100)
 %define VERR_HM_NO_CPUID    (-4101)
@@ -712,13 +721,13 @@
 %define VERR_HM_UNEXPECTED_LD_ST_MSR    (-4105)
 %define VERR_HM_NO_32_TO_64_SWITCHER    (-4106)
-%define VERR_HMSVM_INVALID_PVMCB    (-4107)
-%define VERR_HMSVM_UNEXPECTED_EXIT    (-4108)
-%define VERR_HMSVM_UNEXPECTED_XCPT_EXIT    (-4109)
-%define VERR_HMSVM_UNEXPECTED_PATCH_TYPE    (-4110)
-%define VERR_HM_WRONG_CPU_1    (-4111)
-%define VERR_HM_IPE_1    (-4112)
-%define VERR_HM_IPE_2    (-4113)
-%define VERR_HM_WRONG_SWITCHER    (-4114)
-%define VERR_HM_UNKNOWN_IO_INSTRUCTION    (-4115)
+%define VERR_HM_WRONG_CPU_1    (-4107)
+%define VERR_HM_IPE_1    (-4108)
+%define VERR_HM_IPE_2    (-4109)
+%define VERR_HM_WRONG_SWITCHER    (-4110)
+%define VERR_HM_UNKNOWN_IO_INSTRUCTION    (-4111)
+%define VERR_HM_UNSUPPORTED_CPU_FEATURE_COMBO    (-4112)
+%define VERR_HM_IPE_3    (-4113)
+%define VERR_HM_IPE_4    (-4114)
+%define VERR_HM_IPE_5    (-4115)
 %define VERR_DIS_INVALID_OPCODE    (-4200)
 %define VERR_DIS_GEN_FAILURE    (-4201)
@@ -726,5 +735,4 @@
 %define VERR_DIS_INVALID_MODRM    (-4203)
 %define VERR_DIS_INVALID_PARAMETER    (-4204)
-%define VERR_DIS_MEM_READ    (-4205)
 %define VERR_DIS_TOO_LONG_INSTR    (-4206)
 %define VERR_WEB_NOT_AUTHENTICATED    (-4300)
@@ -812,3 +820,5 @@
 %define VERR_EXTPACK_UNSUPPORTED_HOST_UNINSTALL    (-6000)
 %define VERR_EXTPACK_VBOX_VERSION_MISMATCH    (-6001)
+%define VERR_GSTCTL_GUEST_ERROR    (-6200)
+%define VWRN_GSTCTL_OBJECTSTATE_CHANGED    6220
 %include "iprt/err.mac"
Index: trunk/include/VBox/vmm/hm.h
===================================================================
--- trunk/include/VBox/vmm/hm.h	(revision 45693)
+++ trunk/include/VBox/vmm/hm.h	(revision 45701)
@@ -40,8 +40,10 @@
 
 /**
- * Query HM state (enabled/disabled)
+ * Checks whether HM (VT-x/AMD-V) is being used by this VM.
  *
- * @returns 0 - disabled, 1 - enabled
- * @param   a_pVM       Pointer to the shared VM structure.
+ * @retval  @c true if used.
+ * @retval  @c false if software virtualization (raw-mode) is used.
+ *
+ * @param   a_pVM       The cross context VM structure.
  * @sa      HMIsEnabledNotMacro, HMR3IsEnabled
  * @internal
@@ -51,4 +53,20 @@
 #else
 # define HMIsEnabled(a_pVM)   ((a_pVM)->fHMEnabled)
+#endif
+
+/**
+ * Checks whether raw-mode context is required for any purpose.
+ *
+ * @retval  @c true if required either by raw-mode itself or by HM for doing
+ *          switching the cpu to 64-bit mode.
+ * @retval  @c false if not required.
+ *
+ * @param   a_pVM       The cross context VM structure.
+ * @internal
+ */
+#if HC_ARCH_BITS == 64
+# define HMIsRawModeCtxNeeded(a_pVM)   (!HMIsEnabled(a_pVM))
+#else
+# define HMIsRawModeCtxNeeded(a_pVM)   (!HMIsEnabled(a_pVM) || (a_pVM)->fHMNeedRawModeCtx)
 #endif
 
Index: trunk/include/VBox/vmm/selm.h
===================================================================
--- trunk/include/VBox/vmm/selm.h	(revision 45693)
+++ trunk/include/VBox/vmm/selm.h	(revision 45701)
@@ -42,5 +42,4 @@
 VMMDECL(void)           SELMSetTrap8EIP(PVM pVM, uint32_t u32EIP);
 VMMDECL(int)            SELMGetRing1Stack(PVM pVM, uint32_t *pSS, PRTGCPTR32 pEsp);
-VMMDECL(RTGCPTR)        SELMGetGuestTSS(PVM pVM);
 VMMDECL(RTSEL)          SELMGetHyperCS(PVM pVM);
 VMMDECL(RTSEL)          SELMGetHyperCS64(PVM pVM);
Index: trunk/include/VBox/vmm/vm.h
===================================================================
--- trunk/include/VBox/vmm/vm.h	(revision 45693)
+++ trunk/include/VBox/vmm/vm.h	(revision 45701)
@@ -882,4 +882,7 @@
     /** For asserting on fHMEnable usage. */
     bool                        fHMEnabledFixed;
+    /** Hardware VM support requires a minimal raw-mode context.
+     * This is never set on 64-bit hosts, only 32-bit hosts requires it. */
+    bool                        fHMNeedRawModeCtx;
     /** Set when this VM is the master FT node.
      * @todo This doesn't need to be here, FTM should store it in it's own
@@ -893,5 +896,5 @@
 
     /** Alignment padding.. */
-    uint8_t                     uPadding1[3];
+    uint8_t                     uPadding1[2];
 
     /** @name Debugging
Index: trunk/include/VBox/vmm/vm.mac
===================================================================
--- trunk/include/VBox/vmm/vm.mac	(revision 45693)
+++ trunk/include/VBox/vmm/vm.mac	(revision 45701)
@@ -64,8 +64,9 @@
     .fHMEnabled             resb 1
     .fHMEnabledFixed        resb 1
+    .fHMNeedRawModeCtx      resb 1
     .fFaultTolerantMaster   resb 1
     .fUseLargePages         resb 1
 
-    .uPadding1              resb 3
+    .uPadding1              resb 2
 
     .hTraceBufRC            RTRCPTR_RES 1
Index: trunk/include/VBox/vmm/vmm.h
===================================================================
--- trunk/include/VBox/vmm/vmm.h	(revision 45693)
+++ trunk/include/VBox/vmm/vmm.h	(revision 45701)
@@ -64,4 +64,8 @@
     /** Switcher for AMD64 host paging to AMD64 shadow paging. */
     VMMSWITCHER_AMD64_TO_AMD64,
+    /** Stub switcher for 32-bit and PAE. */
+    VMMSWITCHER_X86_STUB,
+    /** Stub switcher for AMD64. */
+    VMMSWITCHER_AMD64_STUB,
     /** Used to make a count for array declarations and suchlike. */
     VMMSWITCHER_MAX,
@@ -254,5 +258,4 @@
 VMMR3DECL(const char *) VMMR3GetRZAssertMsg2(PVM pVM);
 VMMR3_INT_DECL(int)     VMMR3SelectSwitcher(PVM pVM, VMMSWITCHER enmSwitcher);
-VMMR3_INT_DECL(int)     VMMR3DisableSwitcher(PVM pVM);
 VMMR3_INT_DECL(RTR0PTR) VMMR3GetHostToGuestSwitcher(PVM pVM, VMMSWITCHER enmSwitcher);
 VMMR3_INT_DECL(int)     VMMR3HmRunGC(PVM pVM, PVMCPU pVCpu);
Index: trunk/include/iprt/err.mac
===================================================================
--- trunk/include/iprt/err.mac	(revision 45693)
+++ trunk/include/iprt/err.mac	(revision 45701)
@@ -16,4 +16,5 @@
 %define VERR_VERSION_MISMATCH    (-11)
 %define VERR_NOT_IMPLEMENTED    (-12)
+%define VERR_INVALID_FLAGS    (-13)
 %define VERR_NOT_EQUAL    (-18)
 %define VERR_NOT_SYMLINK    (-19)
@@ -122,4 +123,5 @@
 %define VERR_UNEVEN_INPUT    (-22402)
 %define VERR_NOT_AVAILABLE    (-22403)
+%define VERR_PROC_DETACH_NOT_SUPPORTED    (-22404)
 %define VERR_FILE_IO_ERROR    (-100)
 %define VERR_OPEN_FAILED    (-101)
@@ -169,4 +171,5 @@
 %define VERR_PATH_IS_RELATIVE    (-143)
 %define VERR_PATH_IS_NOT_RELATIVE    (-144)
+%define VERR_PATH_ZERO_LENGTH    (-145)
 %define VERR_DISK_IO_ERROR    (-150)
 %define VERR_INVALID_DRIVE    (-151)
@@ -275,4 +278,5 @@
 %define VERR_NET_HOST_UNREACHABLE    (-465)
 %define VERR_NET_PROTOCOL_ERROR    (-466)
+%define VERR_NET_INCOMPLETE_TX_PACKET    (-467)
 %define VERR_TCP_SERVER_STOP    (-500)
 %define VINF_TCP_SERVER_STOP    500
@@ -395,4 +399,13 @@
 %define VERR_S3_BUCKET_NOT_EMPTY    (-878)
 %define VERR_S3_CANCELED    (-879)
+%define VERR_HTTP_INIT_FAILED    (-885)
+%define VERR_HTTP_NOT_FOUND    (-886)
+%define VERR_HTTP_ACCESS_DENIED    (-887)
+%define VERR_HTTP_BAD_REQUEST    (-888)
+%define VERR_HTTP_COULDNT_CONNECT    (-889)
+%define VERR_HTTP_SSL_CONNECT_ERROR    (-890)
+%define VERR_HTTP_CACERT_WRONG_FORMAT    (-891)
+%define VERR_HTTP_CACERT_CANNOT_AUTHENTICATE    (-892)
+%define VERR_HTTP_ABORTED    (-893)
 %define VERR_MANIFEST_UNSUPPORTED_DIGEST_TYPE    (-900)
 %define VERR_MANIFEST_WRONG_FILE_FORMAT    (-901)
Index: trunk/include/iprt/x86.mac
===================================================================
--- trunk/include/iprt/x86.mac	(revision 45693)
+++ trunk/include/iprt/x86.mac	(revision 45701)
@@ -334,5 +334,5 @@
 %define MSR_IA32_VMX_VMCS_ENUM              0x48A
 %define MSR_IA32_VMX_PROCBASED_CTLS2        0x48B
-%define MSR_IA32_VMX_EPT_CAPS               0x48C
+%define MSR_IA32_VMX_EPT_VPID_CAP           0x48C
 %define MSR_IA32_DS_AREA                    0x600
 %define MSR_IA32_X2APIC_START               0x800
@@ -647,4 +647,5 @@
 %define X86_SEL_RPL             0x0003
 %define X86_SEL_RPL_LDT         0x0007
+%define X86_XCPT_MAX                (X86_XCPT_XF)
 %define X86_TRAP_ERR_EXTERNAL       1
 %define X86_TRAP_ERR_IDT            2
