[NTOSKRNL] Handle some more KeFeatureFlags in amd64/cpu.c and set RtlpUse16ByteSLists
authorTimo Kreuzer <timo.kreuzer@reactos.org>
Sat, 2 May 2015 22:20:59 +0000 (22:20 +0000)
committerTimo Kreuzer <timo.kreuzer@reactos.org>
Sat, 2 May 2015 22:20:59 +0000 (22:20 +0000)
[NTDLL] Set RtlpUse16ByteSLists
[RTL] Make use of RtlpUse16ByteSLists in x64 Interlocked SList functions

svn path=/trunk/; revision=67523

reactos/dll/ntdll/ldr/ldrinit.c
reactos/lib/rtl/amd64/slist.S
reactos/ntoskrnl/ke/amd64/cpu.c
reactos/ntoskrnl/ke/amd64/kiinit.c

index 6a74ef8..b6422b1 100644 (file)
@@ -87,6 +87,7 @@ ULONG RtlpShutdownProcessFlags; // TODO: Use it
 
 NTSTATUS LdrPerformRelocations(PIMAGE_NT_HEADERS NTHeaders, PVOID ImageBase);
 void actctx_init(void);
+extern BOOLEAN RtlpUse16ByteSLists;
 
 #ifdef _WIN64
 #define DEFAULT_SECURITY_COOKIE 0x00002B992DDFA232ll
@@ -2183,6 +2184,11 @@ LdrpInit(PCONTEXT Context,
         NtCurrentTeb()->RealClientId.UniqueProcess,
         NtCurrentTeb()->RealClientId.UniqueThread);
 
+#ifdef _WIN64
+    /* Set the SList header usage */
+    RtlpUse16ByteSLists = SharedUserData->ProcessorFeatures[PF_COMPARE_EXCHANGE128];
+#endif /* _WIN64 */
+
     /* Check if we have a deallocation stack */
     if (!Teb->DeallocationStack)
     {
index 38f257f..c677aa6 100644 (file)
@@ -9,6 +9,8 @@
 #include <asm.inc>
 #include <ksamd64.inc>
 
+EXTERN RtlpUse16ByteSLists:BYTE
+
 /*
 typedef union DECLSPEC_ALIGN(16) _SLIST_HEADER
 {
@@ -99,11 +101,11 @@ ExpInterlockedPopEntrySList:
     /* Load ListHead->Alignment into rax */
     mov rax, [rcx]
 
-    /* Check what kind of header this is */
-    test rdx, SLIST8B_HEADERTYPE_MASK
-    jnz RtlInterlockedPopEntrySList16
+    /* Check for 16 byte SList support */
+    cmp byte ptr [RtlpUse16ByteSLists], 0
+    jne RtlInterlockedPopEntrySList16
 
-    /* We have an 8 byte header */
+    /* Use the 8 byte header */
 
 ExpInterlockedPopEntrySListResume:
 
@@ -229,6 +231,13 @@ ExpInterlockedPushEntrySList:
     /* Not aligned, raise an assertion */
     int HEX(2C)
 ExpInterlockedPushEntrySListChecked:
+
+    /* Make sure RtlpUse16ByteSLists is initialized */
+    cmp byte ptr [RtlpUse16ByteSLists], HEX(FF)
+    jne ExpInterlockedPushEntrySListChecked2
+    /* Not initialized, raise an assertion */
+    int HEX(2C)
+ExpInterlockedPushEntrySListChecked2:
 #endif
 
     /* Load ListHead->Alignment into rax */
@@ -237,11 +246,11 @@ ExpInterlockedPushEntrySListChecked:
     /* Load ListHead->Region into r9 */
     mov r9, [rcx + 8]
 
-    /* Check what kind of header this is */
-    test r9, SLIST8B_HEADERTYPE_MASK
-    jnz RtlInterlockedPushEntrySList16
+    /* Check for 16 byte SList support */
+    cmp byte ptr [RtlpUse16ByteSLists], 0
+    jne RtlInterlockedPushEntrySList16
 
-    /* We have an 8 byte header */
+    /* Use the 8 byte header */
 
 RtlInterlockedPushEntrySListLoop:
 
@@ -358,11 +367,11 @@ ExpInterlockedFlushSList:
     /* Load ListHead->Alignment into rax */
     mov rax, [rcx]
 
-    /* Check what kind of header this is */
-    test rdx, SLIST8B_HEADERTYPE_MASK
-    jnz RtlInterlockedFlushSList16
+    /* Check for 16 byte SList support */
+    cmp byte ptr [RtlpUse16ByteSLists], 0
+    jne RtlInterlockedFlushSList16
 
-    /* We have an 8 byte header */
+    /* Use the 8 byte header */
 
 RtlInterlockedFlushSListLoop:
 
index 3ec6ee5..59d3a9f 100644 (file)
@@ -203,14 +203,13 @@ KiGetFeatureBits(VOID)
     if (CpuFeatures & 0x02000000) FeatureBits |= KF_XMMI;
     if (CpuFeatures & 0x04000000) FeatureBits |= KF_XMMI64;
 
-#if 0
-    if (Reg[2] & 0x00000001) FeatureBits |= KF_SSE3NEW;
-    if (Reg[2] & 0x00000008) FeatureBits |= KF_MONITOR;
-    if (Reg[2] & 0x00000200) FeatureBits |= KF_SSE3SUP;
+    if (Reg[2] & 0x00000001) FeatureBits |= KF_SSE3;
+    //if (Reg[2] & 0x00000008) FeatureBits |= KF_MONITOR;
+    //if (Reg[2] & 0x00000200) FeatureBits |= KF_SSE3SUP;
     if (Reg[2] & 0x00002000) FeatureBits |= KF_CMPXCHG16B;
-    if (Reg[2] & 0x00080000) FeatureBits |= KF_SSE41;
-    if (Reg[2] & 0x00800000) FeatureBits |= KF_POPCNT;
-#endif
+    //if (Reg[2] & 0x00080000) FeatureBits |= KF_SSE41;
+    //if (Reg[2] & 0x00800000) FeatureBits |= KF_POPCNT;
+    if (Reg[2] & 0x04000000) FeatureBits |= KF_XSTATE;
 
     /* Check if the CPU has hyper-threading */
     if (CpuFeatures & 0x10000000)
index e298635..1bd9568 100644 (file)
 
 #define REQUIRED_FEATURE_BITS (KF_RDTSC|KF_CR4|KF_CMPXCHG8B|KF_XMMI|KF_XMMI64| \
                                KF_LARGE_PAGE|KF_FAST_SYSCALL|KF_GLOBAL_PAGE| \
-                               KF_CMOV|KF_PAT|KF_MMX|KF_FXSR|KF_NX_BIT)
+                               KF_CMOV|KF_PAT|KF_MMX|KF_FXSR|KF_NX_BIT|KF_MTRR)
 
 /* GLOBALS *******************************************************************/
 
+extern BOOLEAN RtlpUse16ByteSLists;
+
 /* Function pointer for early debug prints */
 ULONG (*FrLdrDbgPrint)(const char *Format, ...);
 
@@ -82,6 +84,8 @@ KiInitMachineDependent(VOID)
 //            KeBugCheckEx(NO_PAGES_AVAILABLE, 2, PAGE_SIZE * 2, 0, 0);
 //        }
 
+    /* Initialize 8/16 bit SList support */
+    RtlpUse16ByteSLists = (KeFeatureBits & KF_CMPXCHG16B) ? TRUE: FALSE;
 }
 
 VOID
@@ -279,19 +283,29 @@ KiInitializeKernelMachineDependent(
     KeI386CpuStep = Prcb->CpuStep;
     KeProcessorArchitecture = PROCESSOR_ARCHITECTURE_AMD64;
     KeProcessorLevel = (USHORT)Prcb->CpuType;
-    if (Prcb->CpuID) KeProcessorRevision = Prcb->CpuStep;
+    if (Prcb->CpuID)
+        KeProcessorRevision = Prcb->CpuStep;
 
     /* Set basic CPU Features that user mode can read */
+    SharedUserData->ProcessorFeatures[PF_COMPARE_EXCHANGE_DOUBLE] = TRUE;
+    SharedUserData->ProcessorFeatures[PF_RDTSC_INSTRUCTION_AVAILABLE] = TRUE;
+    SharedUserData->ProcessorFeatures[PF_PPC_MOVEMEM_64BIT_OK] = TRUE;
+    SharedUserData->ProcessorFeatures[PF_PAE_ENABLED] = TRUE; // ???
+    SharedUserData->ProcessorFeatures[PF_NX_ENABLED] = TRUE;
+    SharedUserData->ProcessorFeatures[PF_FASTFAIL_AVAILABLE] = TRUE;
+    SharedUserData->ProcessorFeatures[PF_XSAVE_ENABLED] = TRUE;
     SharedUserData->ProcessorFeatures[PF_MMX_INSTRUCTIONS_AVAILABLE] =
         (Prcb->FeatureBits & KF_MMX) ? TRUE: FALSE;
-    SharedUserData->ProcessorFeatures[PF_COMPARE_EXCHANGE_DOUBLE] = TRUE;
     SharedUserData->ProcessorFeatures[PF_XMMI_INSTRUCTIONS_AVAILABLE] =
         ((Prcb->FeatureBits & KF_FXSR) && (Prcb->FeatureBits & KF_XMMI)) ? TRUE: FALSE;
     SharedUserData->ProcessorFeatures[PF_XMMI64_INSTRUCTIONS_AVAILABLE] =
         ((Prcb->FeatureBits & KF_FXSR) && (Prcb->FeatureBits & KF_XMMI64)) ? TRUE: FALSE;
     SharedUserData->ProcessorFeatures[PF_3DNOW_INSTRUCTIONS_AVAILABLE] =
         (Prcb->FeatureBits & KF_3DNOW) ? TRUE: FALSE;
-    SharedUserData->ProcessorFeatures[PF_RDTSC_INSTRUCTION_AVAILABLE] = TRUE;
+    SharedUserData->ProcessorFeatures[PF_SSE3_INSTRUCTIONS_AVAILABLE] =
+        (Prcb->FeatureBits & KF_SSE3) ? TRUE: FALSE;
+    SharedUserData->ProcessorFeatures[PF_COMPARE_EXCHANGE128] =
+        (Prcb->FeatureBits & KF_CMPXCHG16B) ? TRUE: FALSE;
 
     /* Set the default NX policy (opt-in) */
     SharedUserData->NXSupportPolicy = NX_SUPPORT_POLICY_OPTIN;
@@ -322,7 +336,6 @@ KiInitializeKernelMachineDependent(
         SharedUserData->NXSupportPolicy = NX_SUPPORT_POLICY_ALWAYSOFF;
         Prcb->FeatureBits |= KF_NX_DISABLED;
     }
-
 }
 
 static LDR_DATA_TABLE_ENTRY LdrCoreEntries[3];