Index: /trunk/include/VBox/vm.h
===================================================================
--- /trunk/include/VBox/vm.h	(revision 22036)
+++ /trunk/include/VBox/vm.h	(revision 22037)
@@ -692,6 +692,9 @@
     uint32_t                    offVMCPU;
 
+    /** Maximum CPUID leaf, exposed to this VM. */
+    uint32_t                    cCpuidLeafs;
+
     /** Reserved; alignment. */
-    uint32_t                    u32Reserved[6];
+    uint32_t                    u32Reserved[5];
 
     /** @name Public VMM Switcher APIs
@@ -1001,3 +1004,2 @@
 
 #endif
-
Index: /trunk/include/VBox/vm.mac
===================================================================
--- /trunk/include/VBox/vm.mac	(revision 22036)
+++ /trunk/include/VBox/vm.mac	(revision 22037)
@@ -59,5 +59,6 @@
     .cbSelf                 resd 1
     .offVMCPU               resd 1
-    .u32Reserved            resd 6
+    .cCpuidLeafs            resd 1
+    .u32Reserved            resd 5
 
     .pfnVMMGCGuestToHostAsmGuestCtx RTRCPTR_RES 1
Index: /trunk/src/VBox/Main/ConsoleImpl2.cpp
===================================================================
--- /trunk/src/VBox/Main/ConsoleImpl2.cpp	(revision 22036)
+++ /trunk/src/VBox/Main/ConsoleImpl2.cpp	(revision 22037)
@@ -212,4 +212,18 @@
     hrc = pMachine->COMGETTER(CPUCount)(&cCpus);                                    H();
 
+    ULONG cCpuidLeafs = 5;
+    Bstr osTypeId;
+    hrc = pMachine->COMGETTER(OSTypeId)(osTypeId.asOutParam());                     H();
+    if (osTypeId == "WindowsNT4")
+    {
+        /*
+         * We must limit CPUID count for Windows NT 4 manually,
+         * as otherwise it stops with 0x3e error
+         * (MULTIPROCESSOR_CONFIGURATION_NOT_SUPPORTED).
+         */
+        LogRel(("Limiting CPUID leaf count for NT4 guests\n"));
+        cCpuidLeafs = 2;
+    }
+
     /*
      * Get root node first.
@@ -230,4 +244,5 @@
     rc = CFGMR3InsertInteger(pRoot, "RamHoleSize",          cbRamHole);             RC_CHECK();
     rc = CFGMR3InsertInteger(pRoot, "NumCPUs",              cCpus);                 RC_CHECK();
+    rc = CFGMR3InsertInteger(pRoot, "CpuidLeafs",           cCpuidLeafs);           RC_CHECK();
     rc = CFGMR3InsertInteger(pRoot, "TimerMillies",         10);                    RC_CHECK();
     rc = CFGMR3InsertInteger(pRoot, "RawR3Enabled",         1);     /* boolean */   RC_CHECK();
@@ -266,7 +281,4 @@
          */
 
-        Bstr osTypeId;
-        hrc = pMachine->COMGETTER(OSTypeId)(osTypeId.asOutParam());                 H();
-
         ComPtr<IGuestOSType> guestOSType;
         hrc = virtualBox->GetGuestOSType(osTypeId, guestOSType.asOutParam());       H();
@@ -281,5 +293,5 @@
         {
             rc = CFGMR3InsertInteger(pHWVirtExt, "64bitEnabled", 1);                RC_CHECK();
-#if ARCH_BITS == 32 /* The recompiler must use load VBoxREM64 (32-bit host only). */
+#if ARCH_BITS == 32 /* The recompiler must use VBoxREM64 (32-bit host only). */
             PCFGMNODE pREM;
             rc = CFGMR3InsertNode(pRoot, "REM", &pREM);                             RC_CHECK();
Index: /trunk/src/VBox/VMM/CPUM.cpp
===================================================================
--- /trunk/src/VBox/VMM/CPUM.cpp	(revision 22036)
+++ /trunk/src/VBox/VMM/CPUM.cpp	(revision 22037)
@@ -534,17 +534,7 @@
      * info too in these leaves (like words about having a constant TSC).
      */
-#if 0
-    /** @todo NT4 installation regression - investigate */
-    /** Note from Intel manuals:
-     * CPUID leaves > 3 < 80000000 are visible only when
-     * IA32_MISC_ENABLES.BOOT_NT4[bit 22] = 0 (default).
-     *
-     */
-    if (pCPUM->aGuestCpuIdStd[0].eax > 5)
-        pCPUM->aGuestCpuIdStd[0].eax = 5;
-#else
-    if (pCPUM->aGuestCpuIdStd[0].eax > 2)
-        pCPUM->aGuestCpuIdStd[0].eax = 2;
-#endif
+    if (pCPUM->aGuestCpuIdStd[0].eax > pVM->cCpuidLeafs)
+        pCPUM->aGuestCpuIdStd[0].eax = pVM->cCpuidLeafs;
+
     for (i = pCPUM->aGuestCpuIdStd[0].eax + 1; i < RT_ELEMENTS(pCPUM->aGuestCpuIdStd); i++)
         pCPUM->aGuestCpuIdStd[i] = pCPUM->GuestCpuIdDef;
Index: /trunk/src/VBox/VMM/VM.cpp
===================================================================
--- /trunk/src/VBox/VMM/VM.cpp	(revision 22036)
+++ /trunk/src/VBox/VMM/VM.cpp	(revision 22037)
@@ -594,4 +594,14 @@
                     rc = VERR_INVALID_PARAMETER;
                 }
+            }
+            /*
+             * Set correct CPUID leafs limit, some guests types,
+             * notably Win NT 4.0 may wish to override this value.
+             */
+            if (RT_SUCCESS(rc))
+            {
+                 uint32_t cCpuidLeafs;
+                 rc = CFGMR3QueryU32Def(CFGMR3GetRoot(pVM), "CpuidLeafs", &cCpuidLeafs, 5);
+                 pVM->cCpuidLeafs = cCpuidLeafs;
             }
             if (RT_SUCCESS(rc))
@@ -3572,3 +3582,2 @@
     return pUVCpu->vm.s.ThreadEMT;
 }
-
Index: /trunk/src/VBox/VMM/VMMAll/CPUMAllRegs.cpp
===================================================================
--- /trunk/src/VBox/VMM/VMMAll/CPUMAllRegs.cpp	(revision 22036)
+++ /trunk/src/VBox/VMM/VMMAll/CPUMAllRegs.cpp	(revision 22037)
@@ -1065,4 +1065,6 @@
         pCpuId = &pVM->cpum.s.GuestCpuIdDef;
 
+    bool fHasMoreCaches = (*pEcx == 0);
+
     *pEax = pCpuId->eax;
     *pEbx = pCpuId->ebx;
@@ -1076,4 +1078,12 @@
         Assert(pVCpu->idCpu <= 255);
         *pEbx |= (pVCpu->idCpu << 24);
+   }
+
+    if ( iLeaf == 4 && fHasMoreCaches &&
+         pVM->cpum.s.enmCPUVendor == CPUMCPUVENDOR_INTEL)
+    {
+        /* Report unified L0 cache, Linux'es num_cpu_cores() requires
+         * that to be non-0 to detect core count correctly. */
+        *pEax |= (1 << 5) | 3;
     }
 
@@ -2048,3 +2058,2 @@
     return enmMode;
 }
-
Index: /trunk/src/VBox/VMM/VMMAll/EMAll.cpp
===================================================================
--- /trunk/src/VBox/VMM/VMMAll/EMAll.cpp	(revision 22036)
+++ /trunk/src/VBox/VMM/VMMAll/EMAll.cpp	(revision 22037)
@@ -1985,5 +1985,5 @@
     pRegFrame->rax = 0;
     pRegFrame->rbx = 0;
-    pRegFrame->rcx = 0;
+    pRegFrame->rcx &= UINT64_C(0x00000000ffffffff);
     pRegFrame->rdx = 0;
 
