From 4b00ba5d4df8f982817bb1cc2be61d864786284f Mon Sep 17 00:00:00 2001 From: Alex Ionescu Date: Sun, 8 Oct 2006 04:05:27 +0000 Subject: [PATCH] - Inline and make some slight correctiions to KiInitailizeSystemClock, since it's based on the Ex subsystem, not Ke. Add code for boot-time timezone bias, but currently disabled because I need to implement a function to read configuration registry data at startup. - Improve Init bugchecks to give the exact module that failed. Add Kd initilization in the same block as the other subsystems. - Rename and re-arrange some initlization calls. svn path=/trunk/; revision=24438 --- reactos/ntoskrnl/cc/cacheman.c | 2 +- reactos/ntoskrnl/cm/registry.c | 3 +- reactos/ntoskrnl/ex/init.c | 84 ++++++++++++++------ reactos/ntoskrnl/ex/sysinfo.c | 2 +- reactos/ntoskrnl/ex/time.c | 17 ++-- reactos/ntoskrnl/fs/filelock.c | 2 +- reactos/ntoskrnl/include/internal/cc.h | 2 +- reactos/ntoskrnl/include/internal/ex.h | 7 +- reactos/ntoskrnl/include/internal/fsrtl.h | 2 +- reactos/ntoskrnl/include/internal/ke.h | 2 +- reactos/ntoskrnl/include/internal/ntoskrnl.h | 4 +- reactos/ntoskrnl/kd/kdinit.c | 8 +- reactos/ntoskrnl/ke/clock.c | 34 +------- 13 files changed, 93 insertions(+), 76 deletions(-) diff --git a/reactos/ntoskrnl/cc/cacheman.c b/reactos/ntoskrnl/cc/cacheman.c index a0749134ffe..1be55694e4c 100644 --- a/reactos/ntoskrnl/cc/cacheman.c +++ b/reactos/ntoskrnl/cc/cacheman.c @@ -18,7 +18,7 @@ VOID NTAPI -CcInit(VOID) +CcInitializeCacheManager(VOID) { CcInitView(); } diff --git a/reactos/ntoskrnl/cm/registry.c b/reactos/ntoskrnl/cm/registry.c index 2546cdc4520..565be178e6c 100644 --- a/reactos/ntoskrnl/cm/registry.c +++ b/reactos/ntoskrnl/cm/registry.c @@ -188,7 +188,8 @@ CmInitHives(BOOLEAN SetupBoot) VOID INIT_FUNCTION -CmInitializeRegistry(VOID) +NTAPI +CmInitSystem1(VOID) { OBJECT_ATTRIBUTES ObjectAttributes; UNICODE_STRING KeyName; diff --git a/reactos/ntoskrnl/ex/init.c b/reactos/ntoskrnl/ex/init.c index 66ca9d6eea2..a767f3ca062 100644 --- a/reactos/ntoskrnl/ex/init.c +++ b/reactos/ntoskrnl/ex/init.c @@ -15,6 +15,9 @@ /* DATA **********************************************************************/ +/* HACK */ +extern BOOLEAN KiClockSetupComplete; + #define BUILD_OSCSDVERSION(major, minor) (((major & 0xFF) << 8) | (minor & 0xFF)) /* NT Version Info */ @@ -858,6 +861,8 @@ ExPhase2Init(PVOID Context) HANDLE ProcessHandle; HANDLE ThreadHandle; NTSTATUS Status; + TIME_FIELDS TimeFields; + LARGE_INTEGER SystemBootTime, UniversalBootTime; /* Set to phase 1 */ ExpInitializationPhase = 1; @@ -868,54 +873,88 @@ ExPhase2Init(PVOID Context) /* Do Phase 1 HAL Initialization */ HalInitSystem(1, KeLoaderBlock); - /* Setup system time */ - KiInitializeSystemClock(); + /* Check if GUI Boot is enabled */ + if (strstr(KeLoaderBlock->LoadOptions, "NOGUIBOOT")) NoGuiBoot = TRUE; + + /* Query the clock */ + if (HalQueryRealTimeClock(&TimeFields)) + { + /* Convert to time fields */ + RtlTimeFieldsToTime(&TimeFields, &SystemBootTime); + UniversalBootTime = SystemBootTime; + +#if 0 // FIXME: Won't work until we can read registry data here + /* FIXME: This assumes that the RTC is not already in GMT */ + ExpTimeZoneBias.QuadPart = Int32x32To64(ExpLastTimeZoneBias * 60, + 10000000); + + /* Set the boot time-zone bias */ + SharedUserData->TimeZoneBias.High2Time = ExpTimeZoneBias.HighPart; + SharedUserData->TimeZoneBias.LowPart = ExpTimeZoneBias.LowPart; + SharedUserData->TimeZoneBias.High1Time = ExpTimeZoneBias.HighPart; + + /* Convert the boot time to local time, and set it */ + UniversalBootTime.QuadPart = SystemBootTime.QuadPart + + ExpTimeZoneBias.QuadPart; +#endif + KiSetSystemTime(&UniversalBootTime); + + /* Remember this as the boot time */ + KeBootTime = UniversalBootTime; + } + + /* The clock is ready now (FIXME: HACK FOR OLD HAL) */ + KiClockSetupComplete = TRUE; /* Initialize all processors */ HalAllProcessorsStarted(); /* Call OB initialization again */ - if (!ObInit()) KEBUGCHECK(OBJECT1_INITIALIZATION_FAILED); + if (!ObInit()) KeBugCheck(OBJECT1_INITIALIZATION_FAILED); /* Initialize Basic System Objects and Worker Threads */ - if (!ExInitSystem()) KEBUGCHECK(PHASE1_INITIALIZATION_FAILED); + if (!ExInitSystem()) KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, 1, 0, 0, 0); /* Initialize the later stages of the kernel */ - if (!KeInitSystem()) KEBUGCHECK(PHASE1_INITIALIZATION_FAILED); + if (!KeInitSystem()) KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, 2, 0, 0, 0); + + /* Call KD Providers at Phase 1 */ + if (!KdInitSystem(ExpInitializationPhase, KeLoaderBlock)) + { + /* Failed, bugcheck */ + KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, 3, 0, 0, 0); + } /* Create NLS section */ ExpInitNls(KeLoaderBlock); - /* Call KD Providers at Phase 1 */ - KdInitSystem(1, KeLoaderBlock); - /* Initialize I/O Objects, Filesystems, Error Logging and Shutdown */ IoInit(); + /* Initialize Cache Views */ + CcInitializeCacheManager(); + + /* Initialize the Registry (Hives are NOT yet loaded!) */ + CmInitSystem1(); + + /* Update timezone information */ + ExRefreshTimeZoneInformation(&SystemBootTime); + /* TBD */ PoInit(AcpiTableDetected, KeLoaderBlock); - /* Initialize the Registry (Hives are NOT yet loaded!) */ - CmInitializeRegistry(); - /* Unmap Low memory, and initialize the MPW and Balancer Thread */ MmInit3(); - /* Initialize Cache Views */ - CcInit(); + /* Initialize the File System Runtime Library */ + FsRtlInitSystem(); - /* Initialize File Locking */ - FsRtlpInitFileLockingImplementation(); - - /* Report all resources used by hal */ + /* Report all resources used by HAL */ HalReportResourceUsage(); /* Clear the screen to blue */ HalInitSystem(2, KeLoaderBlock); - /* Check if GUI Boot is enabled */ - if (strstr(KeLoaderBlock->LoadOptions, "NOGUIBOOT")) NoGuiBoot = TRUE; - /* Display version number and copyright/warranty message */ if (NoGuiBoot) ExpDisplayNotice(); @@ -931,9 +970,6 @@ ExPhase2Init(PVOID Context) /* Initialize VDM support */ KeI386VdmInitialize(); - /* Initialize the time zone information from the registry */ - ExpInitTimeZoneInfo(); - /* Enter the kernel debugger before starting up the boot drivers */ if (KdDebuggerEnabled && KdpEarlyBreak) DbgBreakPoint(); @@ -953,7 +989,7 @@ ExPhase2Init(PVOID Context) /* Initialize shared user page. Set dos system path, dos device map, etc. */ InitSystemSharedUserPage(KeLoaderBlock); - /* Initailize the Process Manager at Phase 1 */ + /* Initialize the Process Manager at Phase 1 */ if (!PsInitSystem()) KeBugCheck(PROCESS1_INITIALIZATION_FAILED); /* Launch initial process */ diff --git a/reactos/ntoskrnl/ex/sysinfo.c b/reactos/ntoskrnl/ex/sysinfo.c index a9e1778af23..8e424b93a56 100644 --- a/reactos/ntoskrnl/ex/sysinfo.c +++ b/reactos/ntoskrnl/ex/sysinfo.c @@ -548,7 +548,7 @@ QSI_DEF(SystemTimeOfDayInformation) KeQuerySystemTime(&CurrentTime); - Sti->BootTime= SystemBootTime; + Sti->BootTime= KeBootTime; Sti->CurrentTime = CurrentTime; Sti->TimeZoneBias.QuadPart = ExpTimeZoneBias.QuadPart; Sti->TimeZoneId = ExpTimeZoneId; diff --git a/reactos/ntoskrnl/ex/time.c b/reactos/ntoskrnl/ex/time.c index bc618fd82a1..37d6964a303 100644 --- a/reactos/ntoskrnl/ex/time.c +++ b/reactos/ntoskrnl/ex/time.c @@ -23,21 +23,21 @@ /* Note: Bias[minutes] = UTC - local time */ TIME_ZONE_INFORMATION ExpTimeZoneInfo; +ULONG ExpLastTimeZoneBias = -1; LARGE_INTEGER ExpTimeZoneBias; ULONG ExpTimeZoneId; ULONG ExpTickCountMultiplier; /* FUNCTIONS ****************************************************************/ -VOID -INIT_FUNCTION +BOOLEAN NTAPI -ExpInitTimeZoneInfo(VOID) +ExRefreshTimeZoneInformation(IN PLARGE_INTEGER CurrentBootTime) { LARGE_INTEGER CurrentTime; NTSTATUS Status; - /* Read time zone information from the registry */ + /* Read time zone information from the registry */ Status = RtlQueryTimeZoneInformation(&ExpTimeZoneInfo); if (!NT_SUCCESS(Status)) { @@ -52,8 +52,8 @@ ExpInitTimeZoneInfo(VOID) /* Set bias and ID */ ExpTimeZoneBias.QuadPart = ((LONGLONG)(ExpTimeZoneInfo.Bias + - ExpTimeZoneInfo.StandardBias)) * - TICKSPERMINUTE; + ExpTimeZoneInfo.StandardBias)) * + TICKSPERMINUTE; ExpTimeZoneId = TIME_ZONE_ID_STANDARD; } @@ -64,7 +64,7 @@ ExpInitTimeZoneInfo(VOID) SharedUserData->TimeZoneId = ExpTimeZoneId; /* Convert boot time from local time to UTC */ - SystemBootTime.QuadPart += ExpTimeZoneBias.QuadPart; + KeBootTime.QuadPart += ExpTimeZoneBias.QuadPart; /* Convert system time from local time to UTC */ do @@ -78,6 +78,9 @@ ExpInitTimeZoneInfo(VOID) SharedUserData->SystemTime.LowPart = CurrentTime.u.LowPart; SharedUserData->SystemTime.High1Time = CurrentTime.u.HighPart; SharedUserData->SystemTime.High2Time = CurrentTime.u.HighPart; + + /* Return success */ + return TRUE; } NTSTATUS diff --git a/reactos/ntoskrnl/fs/filelock.c b/reactos/ntoskrnl/fs/filelock.c index 61c94cf04cd..029337788d3 100644 --- a/reactos/ntoskrnl/fs/filelock.c +++ b/reactos/ntoskrnl/fs/filelock.c @@ -77,7 +77,7 @@ IsSurroundingLock( */ VOID STDCALL INIT_FUNCTION -FsRtlpInitFileLockingImplementation(VOID) +FsRtlInitSystem(VOID) { ExInitializeNPagedLookasideList( &LockTocLookaside, NULL, diff --git a/reactos/ntoskrnl/include/internal/cc.h b/reactos/ntoskrnl/include/internal/cc.h index 16b425637d2..db19b69f7a9 100644 --- a/reactos/ntoskrnl/include/internal/cc.h +++ b/reactos/ntoskrnl/include/internal/cc.h @@ -112,7 +112,7 @@ WriteCacheSegment(PCACHE_SEGMENT CacheSeg); VOID NTAPI -CcInit(VOID); +CcInitializeCacheManager(VOID); NTSTATUS NTAPI diff --git a/reactos/ntoskrnl/include/internal/ex.h b/reactos/ntoskrnl/include/internal/ex.h index 3161cd4dabf..72ec44cc8ac 100644 --- a/reactos/ntoskrnl/include/internal/ex.h +++ b/reactos/ntoskrnl/include/internal/ex.h @@ -7,6 +7,7 @@ extern TIME_ZONE_INFORMATION ExpTimeZoneInfo; extern LARGE_INTEGER ExpTimeZoneBias; extern ULONG ExpTimeZoneId; extern ULONG ExpTickCountMultiplier; +extern ULONG ExpLastTimeZoneBias; extern POBJECT_TYPE ExEventPairObjectType; extern ULONG NtBuildNumber; extern ULONG NtMajorVersion; @@ -66,9 +67,11 @@ VOID NTAPI ExpInitializePushLocks(VOID); -VOID +BOOLEAN NTAPI -ExpInitTimeZoneInfo(VOID); +ExRefreshTimeZoneInformation( + IN PLARGE_INTEGER SystemBootTime +); VOID NTAPI diff --git a/reactos/ntoskrnl/include/internal/fsrtl.h b/reactos/ntoskrnl/include/internal/fsrtl.h index 7ff0f24c4d7..5387da975f7 100644 --- a/reactos/ntoskrnl/include/internal/fsrtl.h +++ b/reactos/ntoskrnl/include/internal/fsrtl.h @@ -22,7 +22,7 @@ FsRtlpInitNotifyImplementation(VOID); VOID NTAPI -FsRtlpInitFileLockingImplementation(VOID); +FsRtlInitSystem(VOID); VOID NTAPI diff --git a/reactos/ntoskrnl/include/internal/ke.h b/reactos/ntoskrnl/include/internal/ke.h index 94f9b141a4e..a86c0237c9d 100644 --- a/reactos/ntoskrnl/include/internal/ke.h +++ b/reactos/ntoskrnl/include/internal/ke.h @@ -66,7 +66,7 @@ extern PVOID KeUserApcDispatcher; extern PVOID KeUserCallbackDispatcher; extern PVOID KeUserExceptionDispatcher; extern PVOID KeRaiseUserExceptionDispatcher; -extern LARGE_INTEGER SystemBootTime; +extern LARGE_INTEGER KeBootTime; extern ULONG KeI386NpxPresent; extern ULONG KeI386XMMIPresent; extern ULONG KeI386FxsrPresent; diff --git a/reactos/ntoskrnl/include/internal/ntoskrnl.h b/reactos/ntoskrnl/include/internal/ntoskrnl.h index de6d82e0f84..66fc846292d 100644 --- a/reactos/ntoskrnl/include/internal/ntoskrnl.h +++ b/reactos/ntoskrnl/include/internal/ntoskrnl.h @@ -64,13 +64,13 @@ VOID IoInit(VOID); VOID IoInit2(BOOLEAN BootLog); VOID NTAPI IoInit3(VOID); BOOLEAN NTAPI ObInit(VOID); -VOID CmInitializeRegistry(VOID); +VOID NTAPI CmInitSystem1(VOID); VOID NTAPI CmInitHives(BOOLEAN SetupBoot); VOID CmInit2(PCHAR CommandLine); VOID CmShutdownRegistry(VOID); BOOLEAN CmImportSystemHive(PCHAR ChunkBase, ULONG ChunkSize); BOOLEAN CmImportHardwareHive(PCHAR ChunkBase, ULONG ChunkSize); -VOID KdInitSystem(ULONG Reserved, PLOADER_PARAMETER_BLOCK LoaderBlock); +BOOLEAN NTAPI KdInitSystem(ULONG Reserved, PLOADER_PARAMETER_BLOCK LoaderBlock); /* FIXME - RtlpCreateUnicodeString is obsolete and should be removed ASAP! */ BOOLEAN FASTCALL diff --git a/reactos/ntoskrnl/kd/kdinit.c b/reactos/ntoskrnl/kd/kdinit.c index 263faaa865a..1764cbe78b3 100644 --- a/reactos/ntoskrnl/kd/kdinit.c +++ b/reactos/ntoskrnl/kd/kdinit.c @@ -159,8 +159,9 @@ KdpCallInitRoutine(ULONG BootPhase) WrapperTable.KdpInitRoutine(&WrapperTable, BootPhase); } -VOID +BOOLEAN INIT_FUNCTION +NTAPI KdInitSystem(ULONG BootPhase, PLOADER_PARAMETER_BLOCK LoaderBlock) { @@ -253,11 +254,14 @@ KdInitSystem(ULONG BootPhase, /* Call Wrapper at Phase 0 */ if (WrapperInitRoutine) WrapperInitRoutine(&WrapperTable, 0); - return; + return TRUE; } /* Call the Initialization Routines of the Registered Providers */ KdpCallInitRoutine(BootPhase); + + /* Return success */ + return TRUE; } /* EOF */ diff --git a/reactos/ntoskrnl/ke/clock.c b/reactos/ntoskrnl/ke/clock.c index 63ee0c083da..ee739922e6e 100644 --- a/reactos/ntoskrnl/ke/clock.c +++ b/reactos/ntoskrnl/ke/clock.c @@ -26,15 +26,7 @@ /* GLOBALS ****************************************************************/ -/* - * Current time - */ -#if defined(__GNUC__) -LARGE_INTEGER SystemBootTime = (LARGE_INTEGER)0LL; -#else -LARGE_INTEGER SystemBootTime = { 0 }; -#endif - +LARGE_INTEGER KeBootTime, KeBootTimeBias; KDPC KiExpireTimerDpc; BOOLEAN KiClockSetupComplete = FALSE; ULONG KiTimeLimitIsrMicroseconds; @@ -66,28 +58,6 @@ ULONG KeTimeAdjustment = 100000; /* FUNCTIONS **************************************************************/ -/* - * FUNCTION: Initializes timer irq handling - * NOTE: This is only called once from main() - */ -VOID -INIT_FUNCTION -NTAPI -KiInitializeSystemClock(VOID) -{ - TIME_FIELDS TimeFields; - - /* Calculate the starting time for the system clock */ - HalQueryRealTimeClock(&TimeFields); - RtlTimeFieldsToTime(&TimeFields, &SystemBootTime); - - /* Set up the Used Shared Data */ - SharedUserData->SystemTime.High2Time = SystemBootTime.u.HighPart; - SharedUserData->SystemTime.LowPart = SystemBootTime.u.LowPart; - SharedUserData->SystemTime.High1Time = SystemBootTime.u.HighPart; - KiClockSetupComplete = TRUE; -} - VOID NTAPI KiSetSystemTime(PLARGE_INTEGER NewSystemTime) @@ -116,7 +86,7 @@ KiSetSystemTime(PLARGE_INTEGER NewSystemTime) DeltaTime.QuadPart = NewSystemTime->QuadPart - OldSystemTime.QuadPart; /* Update system boot time */ - SystemBootTime.QuadPart += DeltaTime.QuadPart; + KeBootTime.QuadPart += DeltaTime.QuadPart; /* Update absolute timers */ DPRINT1("FIXME: TIMER UPDATE NOT DONE!!!\n");