- Used the already detected cache line size for RtlPrefetchMemoryNonTemporal.
authorHartmut Birr <osexpert@googlemail.com>
Wed, 30 Nov 2005 00:25:48 +0000 (00:25 +0000)
committerHartmut Birr <osexpert@googlemail.com>
Wed, 30 Nov 2005 00:25:48 +0000 (00:25 +0000)
- Initialized RtlPrefetchMemoryNonTemporal earlier.
- Change the memory protection during the initialisation of RtlPrefetchMemoryNonTemporal.

svn path=/trunk/; revision=19764

reactos/lib/rtl/i386/mem_asm.S
reactos/ntoskrnl/ke/i386/kernel.c

index d1552c5..adbef80 100644 (file)
@@ -151,13 +151,12 @@ _RtlCompareMemory@12:
 @RtlPrefetchMemoryNonTemporal@8:\r
        ret         /* Overwritten by ntoskrnl/ke/i386/kernel.c if SSE is supported (see Ki386SetProcessorFeatures() ) */\r
 \r
-       mov eax, [_Ke386CacheGranularity]    // Get cache line size\r
+       mov eax, [_Ke386CacheAlignment]    // Get cache line size\r
 \r
        // This is fastcall, so ecx = address, edx = size\r
-       fetch_next_line:\r
+fetch_next_line:\r
        prefetchnta byte ptr [ecx]  // prefechnta(address)\r
-       sub edx, eax                // count = count - cache_line_size\r
        add ecx, eax                // address = address + cache_line_size\r
-       cmp edx, 0                  // if(count) > 0\r
+       sub edx, eax                // count = count - cache_line_size\r
        ja fetch_next_line          //     goto fetch_next_line\r
        ret\r
index aace793..2e4f0cd 100644 (file)
@@ -22,7 +22,6 @@ static ULONG Ke386CpuidFlags2, Ke386CpuidExFlags, Ke386CpuidExMisc;
 ULONG Ke386CacheAlignment;
 CHAR Ke386CpuidModel[49] = {0,};
 ULONG Ke386L1CacheSize;
-ULONG Ke386CacheGranularity = 0x40;      /* FIXME: Default to 64 bytes for RtlPrefetchMemoryNonTemporal(), need real size */
 BOOLEAN Ke386NoExecute = FALSE;
 BOOLEAN Ke386Pae = FALSE;
 BOOLEAN Ke386GlobalPagesEnabled = FALSE;
@@ -418,6 +417,18 @@ KeInit1(PCHAR CommandLine, PULONG LastKernelAddress)
       /* Target EIP. */
       Ke386Wrmsr(0x176, (ULONG_PTR)KiFastCallEntry, 0);
    }
+
+   /* Does the CPU Support 'prefetchnta' (SSE)  */
+   if(KPCR->PrcbData.FeatureBits & X86_FEATURE_SSE)
+   {
+       ULONG Protect;
+
+       Protect = MmGetPageProtect(NULL, (PVOID)RtlPrefetchMemoryNonTemporal);
+       MmSetPageProtect(NULL, (PVOID)RtlPrefetchMemoryNonTemporal, Protect | PAGE_IS_WRITABLE);
+       /* Replace the ret by a nop */
+       *(PCHAR)RtlPrefetchMemoryNonTemporal = 0x90;
+       MmSetPageProtect(NULL, (PVOID)RtlPrefetchMemoryNonTemporal, Protect);
+   }
 }
 
 VOID
@@ -523,13 +534,6 @@ Ki386SetProcessorFeatures(VOID)
    SharedUserData->ProcessorFeatures[PF_XMMI64_INSTRUCTIONS_AVAILABLE] =
       (Pcr->PrcbData.FeatureBits & X86_FEATURE_SSE2);
 
-   /* Does the CPU Support 'prefetchnta' (SSE)  */
-   if(Pcr->PrcbData.FeatureBits & X86_FEATURE_SSE)
-   {
-       /* Replace the ret by a nop */
-       /* FIXME - *(PCHAR)RtlPrefetchMemoryNonTemporal = 0x90; */
-   }
-
    /* Does the CPU Support Fast System Call? */   
    if (Pcr->PrcbData.FeatureBits & X86_FEATURE_SYSCALL) {