- Used the already detected cache line size for RtlPrefetchMemoryNonTemporal.

- Initialized RtlPrefetchMemoryNonTemporal earlier.  
- Change the memory protection during the initialisation of RtlPrefetchMemoryNonTemporal.

svn path=/trunk/; revision=19764
This commit is contained in:
Hartmut Birr 2005-11-30 00:25:48 +00:00
parent 7f387da9c4
commit bcde224adb
2 changed files with 15 additions and 12 deletions

View file

@ -151,13 +151,12 @@ _RtlCompareMemory@12:
@RtlPrefetchMemoryNonTemporal@8:
ret /* Overwritten by ntoskrnl/ke/i386/kernel.c if SSE is supported (see Ki386SetProcessorFeatures() ) */
mov eax, [_Ke386CacheGranularity] // Get cache line size
mov eax, [_Ke386CacheAlignment] // Get cache line size
// This is fastcall, so ecx = address, edx = size
fetch_next_line:
fetch_next_line:
prefetchnta byte ptr [ecx] // prefechnta(address)
sub edx, eax // count = count - cache_line_size
add ecx, eax // address = address + cache_line_size
cmp edx, 0 // if(count) > 0
sub edx, eax // count = count - cache_line_size
ja fetch_next_line // goto fetch_next_line
ret

View 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) {