Author: ion Date: Sat Sep 2 09:10:16 2006 New Revision: 23881
URL: http://svn.reactos.org/svn/reactos?rev=23881&view=rev Log: - 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.
Modified: trunk/reactos/ntoskrnl/ex/init.c trunk/reactos/ntoskrnl/include/internal/ke.h trunk/reactos/ntoskrnl/ke/clock.c trunk/reactos/ntoskrnl/ke/i386/kernel.c trunk/reactos/ntoskrnl/ke/main.c
Modified: trunk/reactos/ntoskrnl/ex/init.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ex/init.c?rev=2388... ============================================================================== --- trunk/reactos/ntoskrnl/ex/init.c (original) +++ trunk/reactos/ntoskrnl/ex/init.c Sat Sep 2 09:10:16 2006 @@ -506,6 +506,9 @@ /* 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 @@ /* 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 */
Modified: trunk/reactos/ntoskrnl/include/internal/ke.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/k... ============================================================================== --- trunk/reactos/ntoskrnl/include/internal/ke.h (original) +++ trunk/reactos/ntoskrnl/include/internal/ke.h Sat Sep 2 09:10:16 2006 @@ -631,8 +631,7 @@ VOID NTAPI KiSystemStartup( - IN PROS_LOADER_PARAMETER_BLOCK LoaderBlock, - IN ULONG DriverBase // FIXME: hackhack + IN PROS_LOADER_PARAMETER_BLOCK LoaderBlock );
VOID
Modified: trunk/reactos/ntoskrnl/ke/clock.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/clock.c?rev=238... ============================================================================== --- trunk/reactos/ntoskrnl/ke/clock.c (original) +++ trunk/reactos/ntoskrnl/ke/clock.c Sat Sep 2 09:10:16 2006 @@ -83,11 +83,6 @@ 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;
Modified: trunk/reactos/ntoskrnl/ke/i386/kernel.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/i386/kernel.c?r... ============================================================================== --- trunk/reactos/ntoskrnl/ke/i386/kernel.c (original) +++ trunk/reactos/ntoskrnl/ke/i386/kernel.c Sat Sep 2 09:10:16 2006 @@ -27,6 +27,9 @@
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 @@ KeInitializeSpinLock(&MmNonPagedPoolLock); KeInitializeSpinLock(&NtfsStructLock); KeInitializeSpinLock(&AfdWorkQueueSpinLock); + KeInitializeDispatcher(); // ROS OLD DISPATCHER } }
@@ -406,57 +410,6 @@ { /* FIXME */ 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 @@ -534,17 +487,12 @@
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 @@ 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 @@ { 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);
Modified: trunk/reactos/ntoskrnl/ke/main.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/main.c?rev=2388... ============================================================================== --- trunk/reactos/ntoskrnl/ke/main.c (original) +++ trunk/reactos/ntoskrnl/ke/main.c Sat Sep 2 09:10:16 2006 @@ -224,8 +224,18 @@ 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 */