ReactOS  0.4.15-dev-341-g17c5fb8
krnlinit.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for krnlinit.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

INIT_FUNCTION VOID NTAPI KiInitializeKernel (IN PKPROCESS InitProcess, IN PKTHREAD InitThread, IN PVOID IdleStack, IN PKPRCB Prcb, IN PLOADER_PARAMETER_BLOCK LoaderBlock)
 
VOID NTAPI KiInitializeHandBuiltThread (IN PKTHREAD Thread, IN PKPROCESS Process, IN PVOID Stack)
 
INIT_FUNCTION VOID NTAPI KiSystemStartupBootStack (VOID)
 

Variables

ULONG_PTR MainSSDT []
 
UCHAR MainSSPT []
 
BOOLEAN RtlpUse16ByteSLists
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file krnlinit.c.

Function Documentation

◆ KiInitializeHandBuiltThread()

VOID NTAPI KiInitializeHandBuiltThread ( IN PKTHREAD  Thread,
IN PKPROCESS  Process,
IN PVOID  Stack 
)

Definition at line 35 of file krnlinit.c.

39 {
40  PKPRCB Prcb = KeGetCurrentPrcb();
41 
42  /* Setup the Thread */
44 
45  Thread->NextProcessor = Prcb->Number;
46  Thread->Priority = HIGH_PRIORITY;
47  Thread->State = Running;
48  Thread->Affinity = (ULONG_PTR)1 << Prcb->Number;
49  Thread->WaitIrql = DISPATCH_LEVEL;
50  Process->ActiveProcessors |= (ULONG_PTR)1 << Prcb->Number;
51 
52 }
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1063
uint32_t ULONG_PTR
Definition: typedefs.h:64
smooth NULL
Definition: ftsmooth.c:416
#define HIGH_PRIORITY
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
VOID NTAPI KeInitializeThread(IN PKPROCESS Process, IN OUT PKTHREAD Thread, IN PKSYSTEM_ROUTINE SystemRoutine, IN PKSTART_ROUTINE StartRoutine, IN PVOID StartContext, IN PCONTEXT Context, IN PVOID Teb, IN PVOID KernelStack)
Definition: thrdobj.c:900
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
USHORT Number
Definition: ketypes.h:559
#define ULONG_PTR
Definition: config.h:101

Referenced by KiInitializeKernel(), and KiSystemStartupBootStack().

◆ KiInitializeKernel()

INIT_FUNCTION VOID NTAPI KiInitializeKernel ( IN PKPROCESS  InitProcess,
IN PKTHREAD  InitThread,
IN PVOID  IdleStack,
IN PKPRCB  Prcb,
IN PLOADER_PARAMETER_BLOCK  LoaderBlock 
)

Definition at line 140 of file krnlinit.c.

145 {
146  ULONG_PTR PageDirectory[2];
147  PVOID DpcStack;
148  ULONG i;
149 
150  /* Set Node Data */
151  KeNodeBlock[0] = &KiNode0;
152  Prcb->ParentNode = KeNodeBlock[0];
153  KeNodeBlock[0]->ProcessorMask = Prcb->SetMember;
154 
155  /* Set boot-level flags */
156  KeFeatureBits = Prcb->FeatureBits;
157 
158  /* Initialize 8/16 bit SList support */
160 
161  /* Set the current MP Master KPRCB to the Boot PRCB */
162  Prcb->MultiThreadSetMaster = Prcb;
163 
164  /* Initialize Bugcheck Callback data */
168 
169  /* Initialize the Timer Expiration DPC */
172 
173  /* Initialize Profiling data */
177 
178  /* Loop the timer table */
179  for (i = 0; i < TIMER_TABLE_SIZE; i++)
180  {
181  /* Initialize the list and entries */
183  KiTimerTableListHead[i].Time.HighPart = 0xFFFFFFFF;
185  }
186 
187  /* Initialize the Swap event and all swap lists */
192 
193  /* Initialize the mutex for generic DPC calls */
195 
196  /* Initialize the syscall table */
202 
203  /* Copy the the current table into the shadow table for win32k */
206  sizeof(KeServiceDescriptorTable));
207 
208  /* Initialize the Idle Process and the Process Listhead */
210  PageDirectory[0] = 0;
211  PageDirectory[1] = 0;
212  KeInitializeProcess(InitProcess,
213  0,
214  0xFFFFFFFF,
215  PageDirectory,
216  FALSE);
217  InitProcess->QuantumReset = MAXCHAR;
218 
219  /* Initialize the startup thread */
220  KiInitializeHandBuiltThread(InitThread, InitProcess, IdleStack);
221 
222  /* Initialize the Kernel Executive */
223  ExpInitializeExecutive(0, LoaderBlock);
224 
225  /* Calculate the time reciprocal */
229 
230  /* Update DPC Values in case they got updated by the executive */
231  Prcb->MaximumDpcQueueDepth = KiMaximumDpcQueueDepth;
232  Prcb->MinimumDpcRate = KiMinimumDpcRate;
233  Prcb->AdjustDpcThreshold = KiAdjustDpcThreshold;
234 
235  /* Allocate the DPC Stack */
236  DpcStack = MmCreateKernelStack(FALSE, 0);
237  if (!DpcStack) KeBugCheckEx(NO_PAGES_AVAILABLE, 1, 0, 0, 0);
238  Prcb->DpcStack = DpcStack;
239 }
VOID NTAPI KiInitializeHandBuiltThread(IN PKTHREAD Thread, IN PKPROCESS Process, IN PVOID Stack)
Definition: krnlinit.c:35
ULONG KeMaximumIncrement
Definition: clock.c:20
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
KSPIN_LOCK KiProfileLock
Definition: profobj.c:20
KNODE KiNode0
Definition: krnlinit.c:38
KDPC KiTimerExpireDpc
Definition: dpc.c:25
PKNODE KeNodeBlock[1]
Definition: krnlinit.c:39
ULONG_PTR MainSSDT[]
Definition: napi.h:9
$ULONG LowPart
Definition: ntbasedef.h:576
ULONG KiAdjustDpcThreshold
Definition: dpc.c:21
VOID NTAPI KeInitializeProcess(struct _KPROCESS *Process, KPRIORITY Priority, KAFFINITY Affinity, PULONG_PTR DirectoryTableBase, IN BOOLEAN Enable)
uint32_t ULONG_PTR
Definition: typedefs.h:64
FAST_MUTEX KiGenericCallDpcMutex
Definition: dpc.c:24
LIST_ENTRY KiProfileListHead
Definition: profobj.c:18
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
VOID NTAPI KiTimerExpiration(IN PKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: dpc.c:79
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:238
KSERVICE_TABLE_DESCRIPTOR KeServiceDescriptorTableShadow[SSDT_MAX_ENTRIES]
Definition: procobj.c:24
ULONG KeFeatureBits
Definition: krnlinit.c:22
smooth NULL
Definition: ftsmooth.c:416
LARGE_INTEGER KiTimeIncrementReciprocal
Definition: timerobj.c:18
UCHAR KiTimeIncrementShiftCount
Definition: timerobj.c:19
ULARGE_INTEGER Time
Definition: ketypes.h:667
#define TIMER_TABLE_SIZE
Definition: ketypes.h:836
$ULONG HighPart
Definition: ntbasedef.h:577
#define MAXCHAR
Definition: umtypes.h:112
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274
ULONG KiServiceLimit
Definition: krnlinit.c:26
BOOLEAN RtlpUse16ByteSLists
ULONG KiMinimumDpcRate
Definition: dpc.c:20
INIT_FUNCTION VOID NTAPI ExpInitializeExecutive(IN ULONG Cpu, IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: init.c:919
LIST_ENTRY KeBugcheckCallbackListHead
Definition: bug.c:22
KTIMER_TABLE_ENTRY KiTimerTableListHead[TIMER_TABLE_SIZE]
Definition: timerobj.c:17
INIT_FUNCTION LARGE_INTEGER NTAPI KiComputeReciprocal(IN LONG Divisor, OUT PUCHAR Shift)
Definition: krnlinit.c:123
KEVENT KiSwapEvent
Definition: procobj.c:21
LIST_ENTRY KiProfileSourceListHead
Definition: profobj.c:19
ULONG KiMaximumDpcQueueDepth
Definition: dpc.c:19
#define KF_CMPXCHG16B
Definition: ketypes.h:163
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
LIST_ENTRY KeBugcheckReasonCallbackListHead
Definition: bug.c:23
UCHAR MainSSPT[]
Definition: napi.h:15
VOID NTAPI KeSetTargetProcessorDpc(IN PKDPC Dpc, IN CCHAR Number)
Definition: dpc.c:970
KSERVICE_TABLE_DESCRIPTOR KeServiceDescriptorTable[SSDT_MAX_ENTRIES]
Definition: procobj.c:23
unsigned int ULONG
Definition: retypes.h:1
LIST_ENTRY KiStackInSwapListHead
Definition: procobj.c:20
LIST_ENTRY KiProcessInSwapListHead
Definition: procobj.c:19
LIST_ENTRY KiProcessOutSwapListHead
Definition: procobj.c:19
KAFFINITY ProcessorMask
Definition: ketypes.h:776
PVOID NTAPI MmCreateKernelStack(BOOLEAN GuiStack, UCHAR Node)
VOID NTAPI KeInitializeDpc(IN PKDPC Dpc, IN PKDEFERRED_ROUTINE DeferredRoutine, IN PVOID DeferredContext)
Definition: dpc.c:711
base of all file and directory entries
Definition: entries.h:82
VOID NTAPI KeBugCheckEx(_In_ ULONG BugCheckCode, _In_ ULONG_PTR BugCheckParameter1, _In_ ULONG_PTR BugCheckParameter2, _In_ ULONG_PTR BugCheckParameter3, _In_ ULONG_PTR BugCheckParameter4)
Definition: rtlcompat.c:107
KSPIN_LOCK BugCheckCallbackLock
Definition: bug.c:24
LIST_ENTRY KiProcessListHead
Definition: procobj.c:18

Referenced by KiSystemStartupBootStack().

◆ KiSystemStartupBootStack()

INIT_FUNCTION VOID NTAPI KiSystemStartupBootStack ( VOID  )

Definition at line 57 of file krnlinit.c.

58 {
59  PLOADER_PARAMETER_BLOCK LoaderBlock = KeLoaderBlock; // hack
60  PKPRCB Prcb = KeGetCurrentPrcb();
62  PKPROCESS Process = Thread->ApcState.Process;
63  PVOID KernelStack = (PVOID)KeLoaderBlock->KernelStack;
64 
65  /* Initialize the Power Management Support for this PRCB */
66  PoInitializePrcb(Prcb);
67 
68  /* Save CPU state */
70 
71  /* Get cache line information for this CPU */
73 
74  /* Initialize spinlocks and DPC data */
75  KiInitSpinLocks(Prcb, Prcb->Number);
76 
77  /* Set up the thread-related fields in the PRCB */
78  Prcb->CurrentThread = Thread;
79  Prcb->NextThread = NULL;
80  Prcb->IdleThread = Thread;
81 
82  /* Initialize PRCB pool lookaside pointers */
84 
85  /* Lower to APC_LEVEL */
87 
88  /* Check if this is the boot cpu */
89  if (Prcb->Number == 0)
90  {
91  /* Initialize the kernel */
92  KiInitializeKernel(Process, Thread, KernelStack, Prcb, LoaderBlock);
93  }
94  else
95  {
96  /* Initialize the startup thread */
98 
99  /* Initialize cpu with HAL */
100  if (!HalInitSystem(0, LoaderBlock))
101  {
102  /* Initialization failed */
103  KeBugCheck(HAL_INITIALIZATION_FAILED);
104  }
105  }
106 
107  /* Raise to Dispatch */
109 
110  /* Set the Idle Priority to 0. This will jump into Phase 1 */
112 
113  /* If there's no thread scheduled, put this CPU in the Idle summary */
114  KiAcquirePrcbLock(Prcb);
115  if (!Prcb->NextThread) KiIdleSummary |= (ULONG_PTR)1 << Prcb->Number;
116  KiReleasePrcbLock(Prcb);
117 
118  /* Raise back to HIGH_LEVEL and clear the PRCB for the loader block */
120  LoaderBlock->Prcb = 0;
121 
122  /* Set the priority of this thread to 0 */
124  Thread->Priority = 0;
125 
126  /* Force interrupts enabled and lower IRQL back to DISPATCH_LEVEL */
127  _enable();
129 
130  /* Set the right wait IRQL */
131  Thread->WaitIrql = DISPATCH_LEVEL;
132 
133  /* Jump into the idle loop */
134  KiIdleLoop();
135 }
VOID NTAPI KiInitializeHandBuiltThread(IN PKTHREAD Thread, IN PKPROCESS Process, IN PVOID Stack)
Definition: krnlinit.c:35
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
FORCEINLINE VOID KiReleasePrcbLock(IN PKPRCB Prcb)
Definition: ke_x.h:225
void __cdecl _enable(void)
Definition: intrin_arm.h:373
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1063
INIT_FUNCTION VOID NTAPI PoInitializePrcb(IN PKPRCB Prcb)
Definition: power.c:490
ULONG_PTR Prcb
Definition: arc.h:497
struct _KTHREAD * NextThread
Definition: ketypes.h:567
ULONG_PTR Thread
Definition: arc.h:499
struct _KTHREAD * PKTHREAD
Definition: nt_native.h:28
struct _KTHREAD * CurrentThread
Definition: ketypes.h:566
FORCEINLINE VOID KiAcquirePrcbLock(IN PKPRCB Prcb)
Definition: ke_x.h:215
smooth NULL
Definition: ftsmooth.c:416
VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1428
PLOADER_PARAMETER_BLOCK KeLoaderBlock
Definition: krnlinit.c:29
KIRQL FASTCALL KfRaiseIrql(IN KIRQL NewIrql)
Definition: pic.c:187
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
VOID KiGetCacheInformation(VOID)
Definition: cpu.c:214
INIT_FUNCTION VOID NTAPI KiInitSpinLocks(IN PKPRCB Prcb, IN CCHAR Number)
Definition: krnlinit.c:187
KPROCESSOR_STATE ProcessorState
Definition: ketypes.h:579
INIT_FUNCTION VOID NTAPI ExInitPoolLookasidePointers(VOID)
Definition: lookas.c:63
VOID NTAPI KiSaveProcessorControlState(OUT PKPROCESSOR_STATE ProcessorState)
Definition: cpu.c:372
ULONG_PTR KiIdleSummary
Definition: thrdschd.c:25
VOID FASTCALL KiIdleLoop(VOID)
Definition: stubs.c:113
INIT_FUNCTION VOID NTAPI KiInitializeKernel(IN PKPROCESS InitProcess, IN PKTHREAD InitThread, IN PVOID IdleStack, IN PKPRCB Prcb, IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: krnlinit.c:140
struct _KTHREAD * IdleThread
Definition: ketypes.h:568
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
#define HIGH_LEVEL
Definition: env_spec_w32.h:703
KPRIORITY NTAPI KeSetPriorityThread(IN PKTHREAD Thread, IN KPRIORITY Priority)
Definition: thrdobj.c:1327
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
USHORT Number
Definition: ketypes.h:559
#define ULONG_PTR
Definition: config.h:101
#define KeGetCurrentThread
Definition: hal.h:44
BOOLEAN NTAPI HalInitSystem(IN ULONG BootPhase, IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: halinit.c:43
#define APC_LEVEL
Definition: env_spec_w32.h:695
ULONG_PTR KernelStack
Definition: arc.h:496

Referenced by KiSwitchToBootStack().

Variable Documentation

◆ MainSSDT

ULONG_PTR MainSSDT[]

Definition at line 9 of file napi.h.

Referenced by KiInitializeKernel(), and KiInitSystem().

◆ MainSSPT

UCHAR MainSSPT[]

Definition at line 15 of file napi.h.

Referenced by KiInitializeKernel(), and KiInitSystem().

◆ RtlpUse16ByteSLists

BOOLEAN RtlpUse16ByteSLists

Referenced by KiInitializeKernel().