Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenkrnlinit.c
Go to the documentation of this file.
00001 /* 00002 * PROJECT: ReactOS Kernel 00003 * LICENSE: GPL - See COPYING in the top level directory 00004 * FILE: ntoskrnl/ke/krnlinit.c 00005 * PURPOSE: Portable part of kernel initialization 00006 * PROGRAMMERS: Timo Kreuzer (timo.kreuzer@reactos.org) 00007 * Alex Ionescu (alex.ionescu@reactos.org) 00008 */ 00009 00010 /* INCLUDES ******************************************************************/ 00011 00012 #include <ntoskrnl.h> 00013 #define NDEBUG 00014 #include <debug.h> 00015 00016 extern ULONG_PTR MainSSDT[]; 00017 extern UCHAR MainSSPT[]; 00018 00019 /* FUNCTIONS *****************************************************************/ 00020 00021 VOID 00022 NTAPI 00023 INIT_FUNCTION 00024 KiInitializeKernel(IN PKPROCESS InitProcess, 00025 IN PKTHREAD InitThread, 00026 IN PVOID IdleStack, 00027 IN PKPRCB Prcb, 00028 IN PLOADER_PARAMETER_BLOCK LoaderBlock); 00029 00030 00031 VOID 00032 NTAPI 00033 KiInitalizeHandBuiltThread( 00034 IN PKTHREAD Thread, 00035 IN PKPROCESS Process, 00036 IN PVOID Stack) 00037 { 00038 PKPRCB Prcb = KeGetCurrentPrcb(); 00039 00040 /* Setup the Thread */ 00041 KeInitializeThread(Process, Thread, NULL, NULL, NULL, NULL, NULL, Stack); 00042 00043 Thread->NextProcessor = Prcb->Number; 00044 Thread->Priority = HIGH_PRIORITY; 00045 Thread->State = Running; 00046 Thread->Affinity = (ULONG_PTR)1 << Prcb->Number; 00047 Thread->WaitIrql = DISPATCH_LEVEL; 00048 Process->ActiveProcessors |= (ULONG_PTR)1 << Prcb->Number; 00049 00050 } 00051 00052 VOID 00053 NTAPI 00054 INIT_FUNCTION 00055 KiSystemStartupBootStack(VOID) 00056 { 00057 PLOADER_PARAMETER_BLOCK LoaderBlock = KeLoaderBlock; // hack 00058 PKPRCB Prcb = KeGetCurrentPrcb(); 00059 PKTHREAD Thread = (PKTHREAD)KeLoaderBlock->Thread; 00060 PKPROCESS Process = Thread->ApcState.Process; 00061 PVOID KernelStack = (PVOID)KeLoaderBlock->KernelStack; 00062 00063 /* Initialize the Power Management Support for this PRCB */ 00064 PoInitializePrcb(Prcb); 00065 00066 /* Save CPU state */ 00067 KiSaveProcessorControlState(&Prcb->ProcessorState); 00068 00069 /* Get cache line information for this CPU */ 00070 KiGetCacheInformation(); 00071 00072 /* Initialize spinlocks and DPC data */ 00073 KiInitSpinLocks(Prcb, Prcb->Number); 00074 00075 /* Set up the thread-related fields in the PRCB */ 00076 Prcb->CurrentThread = Thread; 00077 Prcb->NextThread = NULL; 00078 Prcb->IdleThread = Thread; 00079 00080 /* Initialize PRCB pool lookaside pointers */ 00081 ExInitPoolLookasidePointers(); 00082 00083 /* Lower to APC_LEVEL */ 00084 KeLowerIrql(APC_LEVEL); 00085 00086 /* Check if this is the boot cpu */ 00087 if (Prcb->Number == 0) 00088 { 00089 /* Initialize the kernel */ 00090 KiInitializeKernel(Process, Thread, KernelStack, Prcb, LoaderBlock); 00091 } 00092 else 00093 { 00094 /* Initialize the startup thread */ 00095 KiInitalizeHandBuiltThread(Thread, Process, KernelStack); 00096 00097 /* Initialize cpu with HAL */ 00098 if (!HalInitSystem(0, LoaderBlock)) 00099 { 00100 /* Initialization failed */ 00101 KeBugCheck(HAL_INITIALIZATION_FAILED); 00102 } 00103 } 00104 00105 /* Raise to Dispatch */ 00106 KfRaiseIrql(DISPATCH_LEVEL); 00107 00108 /* Set the Idle Priority to 0. This will jump into Phase 1 */ 00109 KeSetPriorityThread(Thread, 0); 00110 00111 /* If there's no thread scheduled, put this CPU in the Idle summary */ 00112 KiAcquirePrcbLock(Prcb); 00113 if (!Prcb->NextThread) KiIdleSummary |= (ULONG_PTR)1 << Prcb->Number; 00114 KiReleasePrcbLock(Prcb); 00115 00116 /* Raise back to HIGH_LEVEL and clear the PRCB for the loader block */ 00117 KfRaiseIrql(HIGH_LEVEL); 00118 LoaderBlock->Prcb = 0; 00119 00120 /* Set the priority of this thread to 0 */ 00121 Thread = KeGetCurrentThread(); 00122 Thread->Priority = 0; 00123 00124 /* Force interrupts enabled and lower IRQL back to DISPATCH_LEVEL */ 00125 _enable(); 00126 KeLowerIrql(DISPATCH_LEVEL); 00127 00128 /* Set the right wait IRQL */ 00129 Thread->WaitIrql = DISPATCH_LEVEL; 00130 00131 /* Jump into the idle loop */ 00132 KiIdleLoop(); 00133 } 00134 00135 VOID 00136 NTAPI 00137 INIT_FUNCTION 00138 KiInitializeKernel(IN PKPROCESS InitProcess, 00139 IN PKTHREAD InitThread, 00140 IN PVOID IdleStack, 00141 IN PKPRCB Prcb, 00142 IN PLOADER_PARAMETER_BLOCK LoaderBlock) 00143 { 00144 ULONG_PTR PageDirectory[2]; 00145 PVOID DpcStack; 00146 ULONG i; 00147 00148 /* Set Node Data */ 00149 KeNodeBlock[0] = &KiNode0; 00150 Prcb->ParentNode = KeNodeBlock[0]; 00151 KeNodeBlock[0]->ProcessorMask = Prcb->SetMember; 00152 00153 /* Set boot-level flags */ 00154 KeFeatureBits = Prcb->FeatureBits; 00155 00156 /* Set the current MP Master KPRCB to the Boot PRCB */ 00157 Prcb->MultiThreadSetMaster = Prcb; 00158 00159 /* Initialize Bugcheck Callback data */ 00160 InitializeListHead(&KeBugcheckCallbackListHead); 00161 InitializeListHead(&KeBugcheckReasonCallbackListHead); 00162 KeInitializeSpinLock(&BugCheckCallbackLock); 00163 00164 /* Initialize the Timer Expiration DPC */ 00165 KeInitializeDpc(&KiTimerExpireDpc, KiTimerExpiration, NULL); 00166 KeSetTargetProcessorDpc(&KiTimerExpireDpc, 0); 00167 00168 /* Initialize Profiling data */ 00169 KeInitializeSpinLock(&KiProfileLock); 00170 InitializeListHead(&KiProfileListHead); 00171 InitializeListHead(&KiProfileSourceListHead); 00172 00173 /* Loop the timer table */ 00174 for (i = 0; i < TIMER_TABLE_SIZE; i++) 00175 { 00176 /* Initialize the list and entries */ 00177 InitializeListHead(&KiTimerTableListHead[i].Entry); 00178 KiTimerTableListHead[i].Time.HighPart = 0xFFFFFFFF; 00179 KiTimerTableListHead[i].Time.LowPart = 0; 00180 } 00181 00182 /* Initialize the Swap event and all swap lists */ 00183 KeInitializeEvent(&KiSwapEvent, SynchronizationEvent, FALSE); 00184 InitializeListHead(&KiProcessInSwapListHead); 00185 InitializeListHead(&KiProcessOutSwapListHead); 00186 InitializeListHead(&KiStackInSwapListHead); 00187 00188 /* Initialize the mutex for generic DPC calls */ 00189 ExInitializeFastMutex(&KiGenericCallDpcMutex); 00190 00191 /* Initialize the syscall table */ 00192 KeServiceDescriptorTable[0].Base = MainSSDT; 00193 KeServiceDescriptorTable[0].Count = NULL; 00194 KeServiceDescriptorTable[0].Limit = KiServiceLimit; 00195 KeServiceDescriptorTable[1].Limit = 0; 00196 KeServiceDescriptorTable[0].Number = MainSSPT; 00197 00198 /* Copy the the current table into the shadow table for win32k */ 00199 RtlCopyMemory(KeServiceDescriptorTableShadow, 00200 KeServiceDescriptorTable, 00201 sizeof(KeServiceDescriptorTable)); 00202 00203 /* Initialize the Idle Process and the Process Listhead */ 00204 InitializeListHead(&KiProcessListHead); 00205 PageDirectory[0] = 0; 00206 PageDirectory[1] = 0; 00207 KeInitializeProcess(InitProcess, 00208 0, 00209 0xFFFFFFFF, 00210 PageDirectory, 00211 FALSE); 00212 InitProcess->QuantumReset = MAXCHAR; 00213 00214 /* Initialize the startup thread */ 00215 KiInitalizeHandBuiltThread(InitThread, InitProcess, IdleStack); 00216 00217 /* Initialize the Kernel Executive */ 00218 ExpInitializeExecutive(0, LoaderBlock); 00219 00220 /* Calculate the time reciprocal */ 00221 KiTimeIncrementReciprocal = 00222 KiComputeReciprocal(KeMaximumIncrement, 00223 &KiTimeIncrementShiftCount); 00224 00225 /* Update DPC Values in case they got updated by the executive */ 00226 Prcb->MaximumDpcQueueDepth = KiMaximumDpcQueueDepth; 00227 Prcb->MinimumDpcRate = KiMinimumDpcRate; 00228 Prcb->AdjustDpcThreshold = KiAdjustDpcThreshold; 00229 00230 /* Allocate the DPC Stack */ 00231 DpcStack = MmCreateKernelStack(FALSE, 0); 00232 if (!DpcStack) KeBugCheckEx(NO_PAGES_AVAILABLE, 1, 0, 0, 0); 00233 Prcb->DpcStack = DpcStack; 00234 } 00235 Generated on Sat May 26 2012 04:36:18 for ReactOS by
1.7.6.1
|