ReactOS  0.4.15-dev-3017-g1d9542d
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

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)
 
DECLSPEC_NORETURN 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:1079
uint32_t ULONG_PTR
Definition: typedefs.h:65
_In_ WDFREQUEST _In_ PIO_STACK_LOCATION Stack
Definition: wdfrequest.h:636
#define HIGH_PRIORITY
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2652
#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
#define NULL
Definition: types.h:112
_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:563
#define ULONG_PTR
Definition: config.h:101

Referenced by KiInitializeKernel(), and KiSystemStartupBootStack().

◆ KiInitializeKernel()

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

Definition at line 141 of file krnlinit.c.

146 {
147  ULONG_PTR PageDirectory[2];
148  PVOID DpcStack;
149  ULONG i;
150 
151  /* Set Node Data */
152  KeNodeBlock[0] = &KiNode0;
153  Prcb->ParentNode = KeNodeBlock[0];
154  KeNodeBlock[0]->ProcessorMask = Prcb->SetMember;
155 
156  /* Set boot-level flags */
157  KeFeatureBits = Prcb->FeatureBits;
158 
159  /* Initialize 8/16 bit SList support */
161 
162  /* Set the current MP Master KPRCB to the Boot PRCB */
163  Prcb->MultiThreadSetMaster = Prcb;
164 
165  /* Initialize Bugcheck Callback data */
169 
170  /* Initialize the Timer Expiration DPC */
173 
174  /* Initialize Profiling data */
178 
179  /* Loop the timer table */
180  for (i = 0; i < TIMER_TABLE_SIZE; i++)
181  {
182  /* Initialize the list and entries */
184  KiTimerTableListHead[i].Time.HighPart = 0xFFFFFFFF;
186  }
187 
188  /* Initialize the Swap event and all swap lists */
193 
194  /* Initialize the mutex for generic DPC calls */
196 
197  /* Initialize the syscall table */
203 
204  /* Copy the the current table into the shadow table for win32k */
207  sizeof(KeServiceDescriptorTable));
208 
209  /* Initialize the Idle Process and the Process Listhead */
211  PageDirectory[0] = 0;
212  PageDirectory[1] = 0;
213  KeInitializeProcess(InitProcess,
214  0,
215  0xFFFFFFFF,
216  PageDirectory,
217  FALSE);
218  InitProcess->QuantumReset = MAXCHAR;
219 
220  /* Initialize the startup thread */
221  KiInitializeHandBuiltThread(InitThread, InitProcess, IdleStack);
222 
223  /* Initialize the Kernel Executive */
224  ExpInitializeExecutive(0, LoaderBlock);
225 
226  /* Calculate the time reciprocal */
230 
231  /* Update DPC Values in case they got updated by the executive */
232  Prcb->MaximumDpcQueueDepth = KiMaximumDpcQueueDepth;
233  Prcb->MinimumDpcRate = KiMinimumDpcRate;
234  Prcb->AdjustDpcThreshold = KiAdjustDpcThreshold;
235 
236  /* Allocate the DPC Stack */
237  DpcStack = MmCreateKernelStack(FALSE, 0);
238  if (!DpcStack) KeBugCheckEx(NO_PAGES_AVAILABLE, 1, 0, 0, 0);
239  Prcb->DpcStack = DpcStack;
240 }
VOID NTAPI KiInitializeHandBuiltThread(IN PKTHREAD Thread, IN PKPROCESS Process, IN PVOID Stack)
Definition: krnlinit.c:35
ULONG KeMaximumIncrement
Definition: clock.c:20
KSPIN_LOCK KiProfileLock
Definition: profobj.c:20
KNODE KiNode0
Definition: krnlinit.c:38
KDPC KiTimerExpireDpc
Definition: dpc.c:25
#define TRUE
Definition: types.h:120
PKNODE KeNodeBlock[1]
Definition: krnlinit.c:39
LARGE_INTEGER NTAPI KiComputeReciprocal(IN LONG Divisor, OUT PUCHAR Shift)
Definition: krnlinit.c:123
VOID NTAPI ExpInitializeExecutive(IN ULONG Cpu, IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: init.c:919
ULONG_PTR MainSSDT[]
Definition: napi.h:9
$ULONG LowPart
Definition: ntbasedef.h:569
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:65
FAST_MUTEX KiGenericCallDpcMutex
Definition: dpc.c:24
LIST_ENTRY KiProfileListHead
Definition: profobj.c:18
#define FALSE
Definition: types.h:117
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
LARGE_INTEGER KiTimeIncrementReciprocal
Definition: timerobj.c:18
UCHAR KiTimeIncrementShiftCount
Definition: timerobj.c:19
ULARGE_INTEGER Time
Definition: ketypes.h:709
#define TIMER_TABLE_SIZE
Definition: ketypes.h:836
$ULONG HighPart
Definition: ntbasedef.h:570
#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
LIST_ENTRY KeBugcheckCallbackListHead
Definition: bug.c:18
KTIMER_TABLE_ENTRY KiTimerTableListHead[TIMER_TABLE_SIZE]
Definition: timerobj.c:17
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
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
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
LIST_ENTRY KeBugcheckReasonCallbackListHead
Definition: bug.c:19
#define NULL
Definition: types.h:112
UCHAR MainSSPT[]
Definition: napi.h:15
VOID NTAPI KeSetTargetProcessorDpc(IN PKDPC Dpc, IN CCHAR Number)
Definition: dpc.c:971
KSERVICE_TABLE_DESCRIPTOR KeServiceDescriptorTable[SSDT_MAX_ENTRIES]
Definition: procobj.c:23
unsigned int ULONG
Definition: retypes.h:1
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
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:818
PVOID NTAPI MmCreateKernelStack(BOOLEAN GuiStack, UCHAR Node)
VOID NTAPI KeInitializeDpc(IN PKDPC Dpc, IN PKDEFERRED_ROUTINE DeferredRoutine, IN PVOID DeferredContext)
Definition: dpc.c:712
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:108
KSPIN_LOCK BugCheckCallbackLock
Definition: bug.c:20
LIST_ENTRY KiProcessListHead
Definition: procobj.c:18

Referenced by KiSystemStartupBootStack().

◆ KiSystemStartupBootStack()

DECLSPEC_NORETURN VOID NTAPI KiSystemStartupBootStack ( VOID  )

Definition at line 58 of file krnlinit.c.

59 {
60  PLOADER_PARAMETER_BLOCK LoaderBlock = KeLoaderBlock; // hack
61  PKPRCB Prcb = KeGetCurrentPrcb();
63  PKPROCESS Process = Thread->ApcState.Process;
64  PVOID KernelStack = (PVOID)KeLoaderBlock->KernelStack;
65 
66  /* Initialize the Power Management Support for this PRCB */
67  PoInitializePrcb(Prcb);
68 
69  /* Save CPU state */
71 
72  /* Get cache line information for this CPU */
74 
75  /* Initialize spinlocks and DPC data */
76  KiInitSpinLocks(Prcb, Prcb->Number);
77 
78  /* Set up the thread-related fields in the PRCB */
79  Prcb->CurrentThread = Thread;
80  Prcb->NextThread = NULL;
81  Prcb->IdleThread = Thread;
82 
83  /* Initialize PRCB pool lookaside pointers */
85 
86  /* Lower to APC_LEVEL */
88 
89  /* Check if this is the boot cpu */
90  if (Prcb->Number == 0)
91  {
92  /* Initialize the kernel */
93  KiInitializeKernel(Process, Thread, KernelStack, Prcb, LoaderBlock);
94  }
95  else
96  {
97  /* Initialize the startup thread */
99 
100  /* Initialize cpu with HAL */
101  if (!HalInitSystem(0, LoaderBlock))
102  {
103  /* Initialization failed */
104  KeBugCheck(HAL_INITIALIZATION_FAILED);
105  }
106  }
107 
108  /* Raise to Dispatch */
110 
111  /* Set the Idle Priority to 0. This will jump into Phase 1 */
113 
114  /* If there's no thread scheduled, put this CPU in the Idle summary */
115  KiAcquirePrcbLock(Prcb);
116  if (!Prcb->NextThread) KiIdleSummary |= (ULONG_PTR)1 << Prcb->Number;
117  KiReleasePrcbLock(Prcb);
118 
119  /* Raise back to HIGH_LEVEL and clear the PRCB for the loader block */
121  LoaderBlock->Prcb = 0;
122 
123  /* Set the priority of this thread to 0 */
125  Thread->Priority = 0;
126 
127  /* Force interrupts enabled and lower IRQL back to DISPATCH_LEVEL */
128  _enable();
130 
131  /* Set the right wait IRQL */
132  Thread->WaitIrql = DISPATCH_LEVEL;
133 
134  /* Jump into the idle loop */
135  KiIdleLoop();
136 }
DECLSPEC_NORETURN VOID KiIdleLoop(VOID)
Definition: stubs.c:175
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:230
void __cdecl _enable(void)
Definition: intrin_arm.h:373
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1079
ULONG_PTR Prcb
Definition: arc.h:497
struct _KTHREAD * NextThread
Definition: ketypes.h:571
ULONG_PTR Thread
Definition: arc.h:499
struct _KTHREAD * PKTHREAD
Definition: nt_native.h:28
DECLSPEC_NORETURN VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1427
struct _KTHREAD * CurrentThread
Definition: ketypes.h:570
FORCEINLINE VOID KiAcquirePrcbLock(IN PKPRCB Prcb)
Definition: ke_x.h:220
VOID NTAPI PoInitializePrcb(IN PKPRCB Prcb)
Definition: power.c:498
VOID NTAPI KiInitSpinLocks(IN PKPRCB Prcb, IN CCHAR Number)
Definition: krnlinit.c:187
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:2652
VOID KiGetCacheInformation(VOID)
Definition: cpu.c:204
KPROCESSOR_STATE ProcessorState
Definition: ketypes.h:583
VOID NTAPI KiSaveProcessorControlState(OUT PKPROCESSOR_STATE ProcessorState)
Definition: cpu.c:362
ULONG_PTR KiIdleSummary
Definition: thrdschd.c:25
struct _KTHREAD * IdleThread
Definition: ketypes.h:572
#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
VOID NTAPI ExInitPoolLookasidePointers(VOID)
Definition: lookas.c:59
#define NULL
Definition: types.h:112
_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:563
#define ULONG_PTR
Definition: config.h:101
#define KeGetCurrentThread
Definition: hal.h:55
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
VOID NTAPI KiInitializeKernel(IN PKPROCESS InitProcess, IN PKTHREAD InitThread, IN PVOID IdleStack, IN PKPRCB Prcb, IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: krnlinit.c:141

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().