From ea01969067c6b8c12e10961e6afdbcd5ad4fdb55 Mon Sep 17 00:00:00 2001 From: Alex Ionescu Date: Sat, 2 Sep 2006 04:40:09 +0000 Subject: [PATCH] - More Initialization changes: - Initialize bugcheck lists, timer DPC, profile list/locks, timer lists, the swap lists and syscall table as part of KiInitSystem (portable). - Add more initialization for the initial/idle process+thread (some code disabled due to dispatcher problems). - Add code to support future Timer implementation (based on tick-hashes) - Separate post-boostrap initialization code in KiInitializeKernel. - Add some support for future SMP paths. - Create a DPC stack. - Changes based on WI4 and my automated parsing tool. svn path=/trunk/; revision=23880 --- reactos/ntoskrnl/ex/init.c | 11 +- reactos/ntoskrnl/include/internal/ke.h | 19 + reactos/ntoskrnl/ke/bug.c | 5 +- reactos/ntoskrnl/ke/clock.c | 3 - reactos/ntoskrnl/ke/dpc.c | 1 + reactos/ntoskrnl/ke/i386/kernel.c | 474 ++++++++++++++++++------- reactos/ntoskrnl/ke/process.c | 20 +- reactos/ntoskrnl/ke/timer.c | 3 + 8 files changed, 374 insertions(+), 162 deletions(-) diff --git a/reactos/ntoskrnl/ex/init.c b/reactos/ntoskrnl/ex/init.c index 0ae85dccde2..5b71f0a77ae 100644 --- a/reactos/ntoskrnl/ex/init.c +++ b/reactos/ntoskrnl/ex/init.c @@ -25,9 +25,6 @@ extern ULONG_PTR LastKrnlPhysAddr; extern ULONG_PTR LastKernelAddress; extern LOADER_MODULE KeLoaderModules[64]; extern PRTL_MESSAGE_RESOURCE_DATA KiBugCodeMessages; -extern LIST_ENTRY KiProfileListHead; -extern LIST_ENTRY KiProfileSourceListHead; -extern KSPIN_LOCK KiProfileLock; BOOLEAN SetupMode = TRUE; BOOLEAN NoGuiBoot = FALSE; @@ -503,6 +500,9 @@ ExpInitializeExecutive(VOID) /* Check if the structures match the ASM offset constants */ ExecuteRuntimeAsserts(); + /* Initialize HAL */ + HalInitSystem (0, (PLOADER_PARAMETER_BLOCK)&KeLoaderBlock); + /* Sets up the Text Sections of the Kernel and HAL for debugging */ LdrInit1(); @@ -532,11 +532,6 @@ ExpInitializeExecutive(VOID) /* Bring back the IRQL to Passive */ KeLowerIrql(PASSIVE_LEVEL); - /* Initialize Profiling */ - InitializeListHead(&KiProfileListHead); - InitializeListHead(&KiProfileSourceListHead); - KeInitializeSpinLock(&KiProfileLock); - /* Initialize resources */ ExpResourceInitialization(); diff --git a/reactos/ntoskrnl/include/internal/ke.h b/reactos/ntoskrnl/include/internal/ke.h index 21474de2f55..204568dcbab 100644 --- a/reactos/ntoskrnl/include/internal/ke.h +++ b/reactos/ntoskrnl/include/internal/ke.h @@ -49,6 +49,12 @@ typedef struct _DISPATCH_INFO PKINTERRUPT_ROUTINE *FlatDispatch; } DISPATCH_INFO, *PDISPATCH_INFO; +typedef struct _KTIMER_TABLE_ENTRY +{ + LIST_ENTRY Entry; + ULARGE_INTEGER Time; +} KTIMER_TABLE_ENTRY, *PKTIMER_TABLE_ENTRY; + typedef PCHAR (NTAPI *PKE_BUGCHECK_UNICODE_TO_ANSI)( IN PUNICODE_STRING Unicode, @@ -94,6 +100,19 @@ extern ULONG KiMaximumDpcQueueDepth; extern ULONG KiMinimumDpcRate; extern ULONG KiAdjustDpcThreshold; extern ULONG KiIdealDpcRate; +extern LARGE_INTEGER KiTimeIncrementReciprocal; +extern UCHAR KiTimeIncrementShiftCount; +extern LIST_ENTRY BugcheckCallbackListHead, BugcheckReasonCallbackListHead; +extern KSPIN_LOCK BugCheckCallbackLock; +extern KDPC KiExpireTimerDpc; +extern KTIMER_TABLE_ENTRY KiTimerTableListHead[TIMER_TABLE_SIZE]; +extern LIST_ENTRY KiTimerListHead; +extern KMUTEX KiGenericCallDpcMutex; +extern LIST_ENTRY KiProfileListHead, KiProfileSourceListHead; +extern KSPIN_LOCK KiProfileLock; +extern LIST_ENTRY KiProcessInSwapListHead, KiProcessOutSwapListHead; +extern LIST_ENTRY KiStackInSwapListHead; +extern KEVENT KiSwapEvent; /* MACROS *************************************************************************/ diff --git a/reactos/ntoskrnl/ke/bug.c b/reactos/ntoskrnl/ke/bug.c index 8727be08832..2bb504c62a2 100644 --- a/reactos/ntoskrnl/ke/bug.c +++ b/reactos/ntoskrnl/ke/bug.c @@ -28,6 +28,7 @@ HalReleaseDisplayOwnership( LIST_ENTRY BugcheckCallbackListHead; LIST_ENTRY BugcheckReasonCallbackListHead; +KSPIN_LOCK BugCheckCallbackLock; ULONG KeBugCheckActive, KeBugCheckOwner; LONG KeBugCheckOwnerRecursionCount; PRTL_MESSAGE_RESOURCE_DATA KiBugCodeMessages; @@ -126,10 +127,6 @@ KiInitializeBugCheck(VOID) PIMAGE_RESOURCE_DATA_ENTRY ResourceDataEntry; NTSTATUS Status; - /* Initialize Callbadk Listhead and State */ - InitializeListHead(&BugcheckCallbackListHead); - InitializeListHead(&BugcheckReasonCallbackListHead); - /* Cache the Bugcheck Message Strings. Prepare the Lookup Data */ ResourceInfo.Type = 11; ResourceInfo.Name = 1; diff --git a/reactos/ntoskrnl/ke/clock.c b/reactos/ntoskrnl/ke/clock.c index 0f25cd51791..1124cd192f9 100644 --- a/reactos/ntoskrnl/ke/clock.c +++ b/reactos/ntoskrnl/ke/clock.c @@ -78,9 +78,6 @@ KiInitializeSystemClock(VOID) { TIME_FIELDS TimeFields; - InitializeListHead(&KiTimerListHead); - KeInitializeDpc(&KiExpireTimerDpc, (PKDEFERRED_ROUTINE)KiExpireTimers, 0); - /* Calculate the starting time for the system clock */ HalQueryRealTimeClock(&TimeFields); RtlTimeFieldsToTime(&TimeFields, &SystemBootTime); diff --git a/reactos/ntoskrnl/ke/dpc.c b/reactos/ntoskrnl/ke/dpc.c index 93f281915b1..615ccfa07fb 100644 --- a/reactos/ntoskrnl/ke/dpc.c +++ b/reactos/ntoskrnl/ke/dpc.c @@ -29,6 +29,7 @@ ULONG KiMaximumDpcQueueDepth = 4; ULONG KiMinimumDpcRate = 3; ULONG KiAdjustDpcThreshold = 20; ULONG KiIdealDpcRate = 20; +KMUTEX KiGenericCallDpcMutex; /* TYPES *******************************************************************/ diff --git a/reactos/ntoskrnl/ke/i386/kernel.c b/reactos/ntoskrnl/ke/i386/kernel.c index 2d690605f75..2fef1cd30c0 100644 --- a/reactos/ntoskrnl/ke/i386/kernel.c +++ b/reactos/ntoskrnl/ke/i386/kernel.c @@ -13,6 +13,7 @@ #include #define NDEBUG #include +#include /* GLOBALS *******************************************************************/ @@ -23,6 +24,8 @@ UCHAR KeProcessNodeSeed; PKPRCB KiProcessorBlock[MAXIMUM_PROCESSORS]; ETHREAD KiInitialThread; EPROCESS KiInitialProcess; + +extern LIST_ENTRY KiProcessListHead; extern ULONG Ke386GlobalPagesEnabled; /* System-defined Spinlocks */ @@ -44,6 +47,9 @@ KSPIN_LOCK AfdWorkQueueSpinLock; KSPIN_LOCK KiTimerTableLock[16]; KSPIN_LOCK KiReverseStallIpiLock; +KSPIN_LOCK KiFreezeExecutionLock; +KSPIN_LOCK Ki486CompatibilityLock; + #if defined (ALLOC_PRAGMA) #pragma alloc_text(INIT, KeInit1) #pragma alloc_text(INIT, KeInit2) @@ -51,6 +57,123 @@ KSPIN_LOCK KiReverseStallIpiLock; /* FUNCTIONS *****************************************************************/ +VOID +NTAPI +KiInitSystem(VOID) +{ + ULONG i; + + /* Initialize Bugcheck Callback data */ + InitializeListHead(&BugcheckCallbackListHead); + InitializeListHead(&BugcheckReasonCallbackListHead); + KeInitializeSpinLock(&BugCheckCallbackLock); + + /* Initialize the Timer Expiration DPC */ + KeInitializeDpc(&KiExpireTimerDpc, KiExpireTimers, NULL); + KeSetTargetProcessorDpc(&KiExpireTimerDpc, 0); + + /* Initialize Profiling data */ + KeInitializeSpinLock(&KiProfileLock); + InitializeListHead(&KiProfileListHead); + InitializeListHead(&KiProfileSourceListHead); + + /* Loop the timer table */ + for (i = 0; i < TIMER_TABLE_SIZE; i++) + { + /* Initialize the list and entries */ + InitializeListHead(&KiTimerTableListHead[i].Entry); + KiTimerTableListHead[i].Time.HighPart = 0xFFFFFFFF; + KiTimerTableListHead[i].Time.LowPart = 0; + } + + /* Initialize old-style list */ + InitializeListHead(&KiTimerListHead); + + /* Initialize the Swap event and all swap lists */ + KeInitializeEvent(&KiSwapEvent, SynchronizationEvent, FALSE); + InitializeListHead(&KiProcessInSwapListHead); + InitializeListHead(&KiProcessOutSwapListHead); + InitializeListHead(&KiStackInSwapListHead); + + /* Initialize the mutex for generic DPC calls */ + KeInitializeMutex(&KiGenericCallDpcMutex, 0); + + /* Initialize the syscall table */ + KeServiceDescriptorTable[0].Base = MainSSDT; + KeServiceDescriptorTable[0].Count = NULL; + KeServiceDescriptorTable[0].Limit = NUMBER_OF_SYSCALLS; + KeServiceDescriptorTable[1].Limit = 0; + KeServiceDescriptorTable[0].Number = MainSSPT; + + /* Copy the the current table into the shadow table for win32k */ + RtlCopyMemory(KeServiceDescriptorTableShadow, + KeServiceDescriptorTable, + sizeof(KeServiceDescriptorTable)); +} + +LARGE_INTEGER +NTAPI +KiComputeReciprocal(IN LONG Divisor, + OUT PUCHAR Shift) +{ + LARGE_INTEGER Reciprocal = {{0}}; + LONG BitCount = 0, Remainder = 1; + + /* Start by calculating the remainder */ + while (Reciprocal.HighPart >= 0) + { + /* Increase the loop (bit) count */ + BitCount++; + + /* Calculate the current fraction */ + Reciprocal.HighPart = (Reciprocal.HighPart << 1) | + (Reciprocal.LowPart >> 31); + Reciprocal.LowPart <<= 1; + + /* Double the remainder and see if we went past the divisor */ + Remainder <<= 1; + if (Remainder >= Divisor) + { + /* Set the low-bit and calculate the new remainder */ + Remainder -= Divisor; + Reciprocal.LowPart |= 1; + } + } + + /* Check if we have a remainder */ + if (Remainder) + { + /* Check if the current fraction value is too large */ + if ((Reciprocal.LowPart == 0xFFFFFFFF) && + (Reciprocal.HighPart == 0xFFFFFFFF)) + { + /* Set the high bit and reduce the bit count */ + Reciprocal.LowPart = 0; + Reciprocal.HighPart = 0x80000000; + BitCount--; + } + else + { + /* Check if only the lowest bits got too large */ + if (Reciprocal.LowPart == 0xFFFFFFFF) + { + /* Reset them and increase the high bits instead */ + Reciprocal.LowPart = 0; + Reciprocal.HighPart++; + } + else + { + /* All is well, increase the low bits */ + Reciprocal.LowPart++; + } + } + } + + /* Now calculate the actual shift and return the reciprocal */ + *Shift = (UCHAR)BitCount - 64; + return Reciprocal; +} + VOID NTAPI KiInitSpinLocks(IN PKPRCB Prcb, @@ -78,7 +201,7 @@ KiInitSpinLocks(IN PKPRCB Prcb, Prcb->MinimumDpcRate = KiMinimumDpcRate; Prcb->AdjustDpcThreshold = KiAdjustDpcThreshold; KeInitializeDpc(&Prcb->CallDpc, NULL, NULL); - //KeSetTargetProcessorDpc(&Prcb->CallDpc, Number); + KeSetTargetProcessorDpc(&Prcb->CallDpc, Number); KeSetImportanceDpc(&Prcb->CallDpc, HighImportance); /* Initialize the Wait List Head */ @@ -200,6 +323,215 @@ KiInitializePcr(IN ULONG ProcessorNumber, Pcr->PrcbData.DpcStack = DpcStack; } +VOID +NTAPI +KiInitializeKernel(IN PKPROCESS InitProcess, + IN PKTHREAD InitThread, + IN PVOID IdleStack, + IN PKPRCB Prcb, + IN CCHAR Number, + IN PROS_LOADER_PARAMETER_BLOCK LoaderBlock) +{ + BOOLEAN NpxPresent; + ULONG FeatureBits; + LARGE_INTEGER PageDirectory; + PVOID DpcStack; + + /* Detect and set the CPU Type */ + KiSetProcessorType(); + + /* Set CR0 features based on detected CPU */ + KiSetCR0Bits(); + + /* Check if an FPU is present */ + NpxPresent = KiIsNpxPresent(); + + /* Initialize the Power Management Support for this PRCB */ + PoInitializePrcb(Prcb); + + /* Bugcheck if this is a 386 CPU */ + if (Prcb->CpuType == 3) KeBugCheckEx(0x5D, 0x386, 0, 0, 0); + + /* Get the processor features for the CPU */ + FeatureBits = KiGetFeatureBits(); + + /* Save feature bits */ + Prcb->FeatureBits = FeatureBits; + + /* Get cache line information for this CPU */ + KiGetCacheInformation(); + + /* Initialize spinlocks and DPC data */ + KiInitSpinLocks(Prcb, Number); + + /* Check if this is the Boot CPU */ + if (!Number) + { + /* Set Node Data */ + KeNodeBlock[0] = &KiNode0; + Prcb->ParentNode = KeNodeBlock[0]; + KeNodeBlock[0]->ProcessorMask = Prcb->SetMember; + + /* Set boot-level flags */ + KeI386NpxPresent = NpxPresent; + KeI386CpuType = Prcb->CpuType; + KeI386CpuStep = Prcb->CpuStep; + KeProcessorArchitecture = 0; + KeProcessorLevel = (USHORT)Prcb->CpuType; + if (Prcb->CpuID) KeProcessorRevision = Prcb->CpuStep; + KeFeatureBits = FeatureBits; + KeI386FxsrPresent = (KeFeatureBits & KF_FXSR) ? TRUE : FALSE; + KeI386XMMIPresent = (KeFeatureBits & KF_XMMI) ? TRUE : FALSE; + + /* Set the current MP Master KPRCB to the Boot PRCB */ + Prcb->MultiThreadSetMaster = Prcb; + + /* Initialize some spinlocks */ + KeInitializeSpinLock(&KiFreezeExecutionLock); + KeInitializeSpinLock(&Ki486CompatibilityLock); + + /* Initialize portable parts of the OS */ + KiInitSystem(); + + /* Initialize the Idle Process and the Process Listhead */ + InitializeListHead(&KiProcessListHead); + PageDirectory.QuadPart = 0; + KeInitializeProcess(InitProcess, + 0, + 0xFFFFFFFF, + PageDirectory); + InitProcess->QuantumReset = MAXCHAR; + } + else + { + /* 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 + /* Setup the Idle Thread */ + KeInitializeThread(InitProcess, + InitThread, + NULL, + NULL, + NULL, + NULL, + NULL, + IdleStack); +#endif + InitThread->NextProcessor = Number; + InitThread->Priority = HIGH_PRIORITY; + InitThread->State = Running; + InitThread->Affinity = 1 << Number; + InitThread->WaitIrql = DISPATCH_LEVEL; + InitProcess->ActiveProcessors = 1 << Number; + + /* Set up the thread-related fields in the PRCB */ + //Prcb->CurrentThread = InitThread; + Prcb->NextThread = NULL; + //Prcb->IdleThread = InitThread; + + /* Initialize the Debugger */ + KdInitSystem (0, &KeLoaderBlock); + + /* Initialize the Kernel Executive */ + ExpInitializeExecutive(); + + /* Only do this on the boot CPU */ + if (!Number) + { + /* Calculate the time reciprocal */ + KiTimeIncrementReciprocal = + KiComputeReciprocal(KeMaximumIncrement, + &KiTimeIncrementShiftCount); + + /* Update DPC Values in case they got updated by the executive */ + Prcb->MaximumDpcQueueDepth = KiMaximumDpcQueueDepth; + Prcb->MinimumDpcRate = KiMinimumDpcRate; + Prcb->AdjustDpcThreshold = KiAdjustDpcThreshold; + + /* Allocate the DPC Stack */ + DpcStack = MmCreateKernelStack(FALSE); + if (!DpcStack) KeBugCheckEx(NO_PAGES_AVAILABLE, 1, 0, 0, 0); + Prcb->DpcStack = DpcStack; + + /* Allocate the IOPM save area. */ + Ki386IopmSaveArea = ExAllocatePoolWithTag(PagedPool, + PAGE_SIZE * 2, + TAG('K', 'e', ' ', ' ')); + if (!Ki386IopmSaveArea) + { + /* Bugcheck. We need this for V86/VDM support. */ + KeBugCheckEx(NO_PAGES_AVAILABLE, 2, PAGE_SIZE * 2, 0, 0); + } + } + + /* Free Initial Memory */ + MiFreeInitMemory(); + + while (1) + { + LARGE_INTEGER Timeout; + Timeout.QuadPart = 0x7fffffffffffffffLL; + KeDelayExecutionThread(KernelMode, FALSE, &Timeout); + } + + /* Bug Check and loop forever if anything failed */ + KEBUGCHECK(0); + for(;;); +} + VOID NTAPI KiSystemStartup(IN PROS_LOADER_PARAMETER_BLOCK LoaderBlock, @@ -209,11 +541,9 @@ KiSystemStartup(IN PROS_LOADER_PARAMETER_BLOCK LoaderBlock, ULONG Cpu = 0; PKIPCR Pcr = (PKIPCR)KPCR_BASE; PKPRCB Prcb; - BOOLEAN NpxPresent; - ULONG FeatureBits; ULONG DriverSize; extern KGDTENTRY KiBootGdt[]; - extern PVOID trap_stack; + extern PVOID trap_stack, init_stack; extern KTSS KiBootTss; /* Initialize the PCR */ @@ -267,135 +597,13 @@ KiSystemStartup(IN PROS_LOADER_PARAMETER_BLOCK LoaderBlock, /* Raise to HIGH_LEVEL */ KfRaiseIrql(HIGH_LEVEL); - /* Detect and set the CPU Type */ - KiSetProcessorType(); - - /* Set CR0 features based on detected CPU */ - KiSetCR0Bits(); - - /* Check if an FPU is present */ - NpxPresent = KiIsNpxPresent(); - - /* Initialize the Power Management Support for this PRCB */ - PoInitializePrcb(Prcb); - - /* Bugcheck if this is a 386 CPU */ - if (Prcb->CpuType == 3) KeBugCheckEx(0x5D, 0x386, 0, 0, 0); - - /* Get the processor features for the CPU */ - FeatureBits = KiGetFeatureBits(); - - /* Save feature bits */ - Prcb->FeatureBits = FeatureBits; - - /* Get cache line information for this CPU */ - KiGetCacheInformation(); - - /* Initialize spinlocks and DPC data */ - KiInitSpinLocks(Prcb, 0); - - /* Set Node Data */ - KeNodeBlock[0] = &KiNode0; - Prcb->ParentNode = KeNodeBlock[0]; - KeNodeBlock[0]->ProcessorMask = Prcb->SetMember; - - /* Set boot-level flags */ - KeI386NpxPresent = NpxPresent; - KeI386CpuType = Prcb->CpuType; - KeI386CpuStep = Prcb->CpuStep; - KeProcessorArchitecture = 0; - KeProcessorLevel = (USHORT)Prcb->CpuType; - if (Prcb->CpuID) KeProcessorRevision = Prcb->CpuStep; - KeFeatureBits = FeatureBits; - KeI386FxsrPresent = (KeFeatureBits & KF_FXSR) ? TRUE : FALSE; - KeI386XMMIPresent = (KeFeatureBits & KF_XMMI) ? TRUE : FALSE; - - /* 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); - } - - /* Initialize the Debugger */ - KdInitSystem (0, &KeLoaderBlock); - - /* Initialize HAL */ - HalInitSystem (0, (PLOADER_PARAMETER_BLOCK)&KeLoaderBlock); - - /* Initialize the Kernel Executive */ - ExpInitializeExecutive(); - - /* Create the IOPM Save Area */ - Ki386IopmSaveArea = ExAllocatePoolWithTag(NonPagedPool, - PAGE_SIZE * 2, - TAG('K', 'e', ' ', ' ')); - - /* Free Initial Memory */ - MiFreeInitMemory(); - - /* Never returns */ -#if 0 - /* FIXME: - * The initial thread isn't a real ETHREAD object, we cannot call PspExitThread. - */ - PspExitThread(STATUS_SUCCESS); -#else - while (1) - { - LARGE_INTEGER Timeout; - Timeout.QuadPart = 0x7fffffffffffffffLL; - KeDelayExecutionThread(KernelMode, FALSE, &Timeout); - } -#endif - - /* Bug Check and loop forever if anything failed */ - KEBUGCHECK(0); - for(;;); + /* Call main kernel intialization */ + KiInitializeKernel(&KiInitialProcess.Pcb, + &KiInitialThread.Tcb, + init_stack, + Prcb, + Cpu, + LoaderBlock); } VOID diff --git a/reactos/ntoskrnl/ke/process.c b/reactos/ntoskrnl/ke/process.c index e619a104b5a..260ec804545 100644 --- a/reactos/ntoskrnl/ke/process.c +++ b/reactos/ntoskrnl/ke/process.c @@ -10,26 +10,18 @@ /* INCLUDES *****************************************************************/ #include -#include #define NDEBUG #include /* GLOBALS *****************************************************************/ -KSERVICE_TABLE_DESCRIPTOR -__declspec(dllexport) -KeServiceDescriptorTable[SSDT_MAX_ENTRIES] = -{ - { MainSSDT, NULL, NUMBER_OF_SYSCALLS, MainSSPT }, - { NULL, NULL, 0, NULL }, -}; +LIST_ENTRY KiProcessListHead; +LIST_ENTRY KiProcessInSwapListHead, KiProcessOutSwapListHead; +LIST_ENTRY KiStackInSwapListHead; +KEVENT KiSwapEvent; -KSERVICE_TABLE_DESCRIPTOR -KeServiceDescriptorTableShadow[SSDT_MAX_ENTRIES] = -{ - { MainSSDT, NULL, NUMBER_OF_SYSCALLS, MainSSPT }, - { NULL, NULL, 0, NULL }, -}; +KSERVICE_TABLE_DESCRIPTOR KeServiceDescriptorTable[SSDT_MAX_ENTRIES]; +KSERVICE_TABLE_DESCRIPTOR KeServiceDescriptorTableShadow[SSDT_MAX_ENTRIES]; /* FUNCTIONS *****************************************************************/ diff --git a/reactos/ntoskrnl/ke/timer.c b/reactos/ntoskrnl/ke/timer.c index be09db0cf47..b212ddba1a8 100644 --- a/reactos/ntoskrnl/ke/timer.c +++ b/reactos/ntoskrnl/ke/timer.c @@ -15,7 +15,10 @@ /* GLOBALS ****************************************************************/ +LARGE_INTEGER KiTimeIncrementReciprocal; +UCHAR KiTimeIncrementShiftCount; LIST_ENTRY KiTimerListHead; +KTIMER_TABLE_ENTRY KiTimerTableListHead[TIMER_TABLE_SIZE]; #define SYSTEM_TIME_UNITS_PER_MSEC (10000) /* PRIVATE FUNCTIONS ******************************************************/