From aa69c69afb196230279e76bf59321285da83ffbc Mon Sep 17 00:00:00 2001 From: Alex Ionescu Date: Sat, 2 Sep 2006 05:10:16 +0000 Subject: [PATCH] - Move machine-specific initializations to KeInit2. - Initialize bugcheck messages much earlier, separate clock initialization from KeInit2. - Completely move out and isolate ROS/FREELDR PE loading hacks to KiRosPrepareForSystemStartup so that KiSystemStartup is clean of them. svn path=/trunk/; revision=23881 --- reactos/ntoskrnl/ex/init.c | 8 +- reactos/ntoskrnl/include/internal/ke.h | 3 +- reactos/ntoskrnl/ke/clock.c | 5 - reactos/ntoskrnl/ke/i386/kernel.c | 121 +++++++++++-------------- reactos/ntoskrnl/ke/main.c | 12 ++- 5 files changed, 72 insertions(+), 77 deletions(-) diff --git a/reactos/ntoskrnl/ex/init.c b/reactos/ntoskrnl/ex/init.c index 5b71f0a77ae..cab32e4329f 100644 --- a/reactos/ntoskrnl/ex/init.c +++ b/reactos/ntoskrnl/ex/init.c @@ -506,6 +506,9 @@ ExpInitializeExecutive(VOID) /* Sets up the Text Sections of the Kernel and HAL for debugging */ LdrInit1(); + /* Setup bugcheck messages */ + KiInitializeBugCheck(); + /* Lower the IRQL to Dispatch Level */ KeLowerIrql(DISPATCH_LEVEL); @@ -526,7 +529,10 @@ ExpInitializeExecutive(VOID) /* Parse the Loaded Modules (by FreeLoader) and cache the ones we'll need */ ParseAndCacheLoadedModules(); - /* Initialize the Dispatcher, Clock and Bug Check Mechanisms. */ + /* Setup system time */ + KiInitializeSystemClock(); + + /* Initialize the second stage of the kernel */ KeInit2(); /* Bring back the IRQL to Passive */ diff --git a/reactos/ntoskrnl/include/internal/ke.h b/reactos/ntoskrnl/include/internal/ke.h index 204568dcbab..b92589660ee 100644 --- a/reactos/ntoskrnl/include/internal/ke.h +++ b/reactos/ntoskrnl/include/internal/ke.h @@ -631,8 +631,7 @@ Phase1Initialization(PVOID Context); VOID NTAPI KiSystemStartup( - IN PROS_LOADER_PARAMETER_BLOCK LoaderBlock, - IN ULONG DriverBase // FIXME: hackhack + IN PROS_LOADER_PARAMETER_BLOCK LoaderBlock ); VOID diff --git a/reactos/ntoskrnl/ke/clock.c b/reactos/ntoskrnl/ke/clock.c index 1124cd192f9..0204c70a23f 100644 --- a/reactos/ntoskrnl/ke/clock.c +++ b/reactos/ntoskrnl/ke/clock.c @@ -83,11 +83,6 @@ KiInitializeSystemClock(VOID) RtlTimeFieldsToTime(&TimeFields, &SystemBootTime); /* Set up the Used Shared Data */ - SharedUserData->TickCountLowDeprecated = 0; - SharedUserData->TickCountMultiplier = 167783691; // 2^24 * 1193182 / 119310 - SharedUserData->InterruptTime.High2Time = 0; - SharedUserData->InterruptTime.LowPart = 0; - SharedUserData->InterruptTime.High1Time = 0; SharedUserData->SystemTime.High2Time = SystemBootTime.u.HighPart; SharedUserData->SystemTime.LowPart = SystemBootTime.u.LowPart; SharedUserData->SystemTime.High1Time = SystemBootTime.u.HighPart; diff --git a/reactos/ntoskrnl/ke/i386/kernel.c b/reactos/ntoskrnl/ke/i386/kernel.c index 2fef1cd30c0..42e7f8c8784 100644 --- a/reactos/ntoskrnl/ke/i386/kernel.c +++ b/reactos/ntoskrnl/ke/i386/kernel.c @@ -27,6 +27,9 @@ EPROCESS KiInitialProcess; extern LIST_ENTRY KiProcessListHead; extern ULONG Ke386GlobalPagesEnabled; +extern KGDTENTRY KiBootGdt[]; +extern PVOID trap_stack, init_stack; +extern KTSS KiBootTss; /* System-defined Spinlocks */ KSPIN_LOCK KiDispatcherLock; @@ -269,6 +272,7 @@ KiInitSpinLocks(IN PKPRCB Prcb, KeInitializeSpinLock(&MmNonPagedPoolLock); KeInitializeSpinLock(&NtfsStructLock); KeInitializeSpinLock(&AfdWorkQueueSpinLock); + KeInitializeDispatcher(); // ROS OLD DISPATCHER } } @@ -408,57 +412,6 @@ KiInitializeKernel(IN PKPROCESS InitProcess, DPRINT1("SMP Boot support not yet present\n"); } - /* Check if Fxsr was found */ - if (KeI386FxsrPresent) - { - /* Enable it. FIXME: Send an IPI */ - Ke386SetCr4(Ke386GetCr4() | X86_CR4_OSFXSR); - - /* Check if XMM was found too */ - if (KeI386XMMIPresent) - { - /* Enable it: FIXME: Send an IPI. */ - Ke386SetCr4(Ke386GetCr4() | X86_CR4_OSXMMEXCPT); - - /* FIXME: Implement and enable XMM Page Zeroing for Mm */ - } - } - - if (KeFeatureBits & KF_GLOBAL_PAGE) - { - ULONG Flags; - /* Enable global pages */ - Ke386GlobalPagesEnabled = TRUE; - Ke386SaveFlags(Flags); - Ke386DisableInterrupts(); - Ke386SetCr4(Ke386GetCr4() | X86_CR4_PGE); - Ke386RestoreFlags(Flags); - } - - if (KeFeatureBits & KF_FAST_SYSCALL) - { - extern void KiFastCallEntry(void); - - /* CS Selector of the target segment. */ - Ke386Wrmsr(0x174, KGDT_R0_CODE, 0); - /* Target ESP. */ - Ke386Wrmsr(0x175, 0, 0); - /* Target EIP. */ - Ke386Wrmsr(0x176, (ULONG_PTR)KiFastCallEntry, 0); - } - - /* Does the CPU Support 'prefetchnta' (SSE) */ - if(KeFeatureBits & KF_XMMI) - { - 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); - } - #if 0 /* Setup the Idle Thread */ KeInitializeThread(InitProcess, @@ -534,17 +487,12 @@ KiInitializeKernel(IN PKPROCESS InitProcess, VOID NTAPI -KiSystemStartup(IN PROS_LOADER_PARAMETER_BLOCK LoaderBlock, - IN ULONG DriverBase) // FIXME: hackhack +KiSystemStartup(IN PROS_LOADER_PARAMETER_BLOCK LoaderBlock) { /* Currently hacked for CPU 0 only */ ULONG Cpu = 0; PKIPCR Pcr = (PKIPCR)KPCR_BASE; PKPRCB Prcb; - ULONG DriverSize; - extern KGDTENTRY KiBootGdt[]; - extern PVOID trap_stack, init_stack; - extern KTSS KiBootTss; /* Initialize the PCR */ RtlZeroMemory(Pcr, PAGE_SIZE); @@ -572,14 +520,6 @@ KiSystemStartup(IN PROS_LOADER_PARAMETER_BLOCK LoaderBlock, KiInitializeGdt(NULL); Ki386BootInitializeTSS(); Ki386InitializeLdt(); - KeInitExceptions(); - KeInitInterrupts(); - - /* Load the Kernel with the PE Loader */ - LdrSafePEProcessModule((PVOID)KERNEL_BASE, - (PVOID)KERNEL_BASE, - (PVOID)DriverBase, - &DriverSize); /* Setup CPU-related fields */ Pcr->Number = Cpu; @@ -613,9 +553,54 @@ KeInit2(VOID) { ULONG Protect; - KiInitializeBugCheck(); - KeInitializeDispatcher(); - KiInitializeSystemClock(); + /* Check if Fxsr was found */ + if (KeI386FxsrPresent) + { + /* Enable it. FIXME: Send an IPI */ + Ke386SetCr4(Ke386GetCr4() | X86_CR4_OSFXSR); + + /* Check if XMM was found too */ + if (KeI386XMMIPresent) + { + /* Enable it: FIXME: Send an IPI. */ + Ke386SetCr4(Ke386GetCr4() | X86_CR4_OSXMMEXCPT); + + /* FIXME: Implement and enable XMM Page Zeroing for Mm */ + } + } + + if (KeFeatureBits & KF_GLOBAL_PAGE) + { + ULONG Flags; + /* Enable global pages */ + Ke386GlobalPagesEnabled = TRUE; + Ke386SaveFlags(Flags); + Ke386DisableInterrupts(); + Ke386SetCr4(Ke386GetCr4() | X86_CR4_PGE); + Ke386RestoreFlags(Flags); + } + + if (KeFeatureBits & KF_FAST_SYSCALL) + { + extern void KiFastCallEntry(void); + + /* CS Selector of the target segment. */ + Ke386Wrmsr(0x174, KGDT_R0_CODE, 0); + /* Target ESP. */ + Ke386Wrmsr(0x175, 0, 0); + /* Target EIP. */ + Ke386Wrmsr(0x176, (ULONG_PTR)KiFastCallEntry, 0); + } + + /* Does the CPU Support 'prefetchnta' (SSE) */ + if(KeFeatureBits & KF_XMMI) + { + 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); + } /* Set IDT to writable */ Protect = MmGetPageProtect(NULL, (PVOID)KiIdt); diff --git a/reactos/ntoskrnl/ke/main.c b/reactos/ntoskrnl/ke/main.c index 67859fb1d60..acd30662f7e 100644 --- a/reactos/ntoskrnl/ke/main.c +++ b/reactos/ntoskrnl/ke/main.c @@ -224,8 +224,18 @@ KiRosPrepareForSystemStartup(IN PROS_LOADER_PARAMETER_BLOCK LoaderBlock) FirstKrnlPhysAddr = KeLoaderModules[0].ModStart - KERNEL_BASE + 0x200000; LastKrnlPhysAddr = LastKernelAddress - KERNEL_BASE + 0x200000; + /* Setup the IDT */ + KeInitExceptions(); // ONCE HACK BELOW IS GONE, MOVE TO KISYSTEMSTARTUP! + KeInitInterrupts(); // ROS HACK DEPRECATED SOON BY NEW HAL + + /* Load the Kernel with the PE Loader */ + LdrSafePEProcessModule((PVOID)KERNEL_BASE, + (PVOID)KERNEL_BASE, + (PVOID)DriverBase, + &DriverSize); + /* Do general System Startup */ - KiSystemStartup(LoaderBlock, DriverBase); + KiSystemStartup(LoaderBlock); } /* EOF */