ReactOS  0.4.14-dev-337-gf981a68
kiinit.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for kiinit.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define REQUIRED_FEATURE_BITS
 

Functions

UCHAR DECLSPEC_ALIGN (16)
 
void KiInitializeSegments ()
 
void KiSystemCallEntry64 ()
 
void KiSystemCallEntry32 ()
 
INIT_FUNCTION VOID NTAPI KiInitMachineDependent (VOID)
 
VOID NTAPI KiInitializePcr (IN PKIPCR Pcr, IN ULONG ProcessorNumber, IN PKTHREAD IdleThread, IN PVOID DpcStack)
 
VOID NTAPI KiInitializeCpu (PKIPCR Pcr)
 
VOID FASTCALL KiInitializeTss (IN PKTSS64 Tss, IN UINT64 Stack)
 
VOID NTAPI INIT_FUNCTION KiInitializeKernelMachineDependent (IN PKPRCB Prcb, IN PLOADER_PARAMETER_BLOCK LoaderBlock)
 
void KiInitModuleList (IN PLOADER_PARAMETER_BLOCK LoaderBlock)
 
INIT_FUNCTION VOID NTAPI KiSystemStartup (IN PLOADER_PARAMETER_BLOCK LoaderBlock)
 

Variables

ULONG(* FrLdrDbgPrint )(const char *Format,...)
 
KSPIN_LOCK KiFreezeExecutionLock
 
KIPCR KiInitialPcr
 
ULONG_PTR P0BootStack = (ULONG_PTR)&P0BootStackData[KERNEL_STACK_SIZE]
 
ULONG_PTR KiDoubleFaultStack = (ULONG_PTR)&KiDoubleFaultStackData[KERNEL_STACK_SIZE]
 
static LDR_DATA_TABLE_ENTRY LdrCoreEntries [3]
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file kiinit.c.

◆ REQUIRED_FEATURE_BITS

#define REQUIRED_FEATURE_BITS
Value:
#define KF_CMPXCHG8B
Definition: ketypes.h:150
#define KF_RDTSC
Definition: ketypes.h:144
#define KF_MMX
Definition: ketypes.h:151
#define KF_NX_BIT
Definition: ketypes.h:165
#define KF_PAT
Definition: ketypes.h:153
#define KF_XMMI
Definition: ketypes.h:156
#define KF_CR4
Definition: ketypes.h:145
#define KF_MTRR
Definition: ketypes.h:149
#define KF_FAST_SYSCALL
Definition: ketypes.h:155
#define KF_FXSR
Definition: ketypes.h:154
#define KF_XMMI64
Definition: ketypes.h:159
#define KF_GLOBAL_PAGE
Definition: ketypes.h:147

Definition at line 16 of file kiinit.c.

Function Documentation

◆ DECLSPEC_ALIGN()

UCHAR DECLSPEC_ALIGN ( 16  )

Definition at line 32 of file kiinit.c.

32 {0};

◆ KiInitializeCpu()

VOID NTAPI KiInitializeCpu ( PKIPCR  Pcr)

Definition at line 165 of file kiinit.c.

166 {
167  ULONG64 Pat;
168  ULONG FeatureBits;
169 
170  /* Initialize gs */
172 
173  /* Set GS base */
176 
177  /* Detect and set the CPU Type */
179 
180  /* Get the processor features for this CPU */
181  FeatureBits = KiGetFeatureBits();
182 
183  /* Check if we support all needed features */
184  if ((FeatureBits & REQUIRED_FEATURE_BITS) != REQUIRED_FEATURE_BITS)
185  {
186  /* If not, bugcheck system */
187  FrLdrDbgPrint("CPU doesn't have needed features! Has: 0x%x, required: 0x%x\n",
188  FeatureBits, REQUIRED_FEATURE_BITS);
189  KeBugCheck(0);
190  }
191 
192  /* Set DEP to always on */
193  SharedUserData->NXSupportPolicy = NX_SUPPORT_POLICY_ALWAYSON;
194  FeatureBits |= KF_NX_ENABLED;
195 
196  /* Save feature bits */
197  Pcr->Prcb.FeatureBits = FeatureBits;
198 
199  /* Enable fx save restore support */
201 
202  /* Enable XMMI exceptions */
204 
205  /* Enable Write-Protection */
207 
208  /* Disable fpu monitoring */
210 
211  /* Disable x87 fpu exceptions */
213 
214  /* LDT is unused */
215  __lldt(0);
216 
217  /* Set the systemcall entry points */
220 
222  ((ULONG64)(KGDT64_R3_CMCODE|RPL_MASK) << 48));
223 
224  /* Set the flags to be cleared when doing a syscall */
226 
227  /* Enable syscall instruction and no-execute support */
229 
230  /* Initialize the PAT */
231  Pat = (PAT_WB << 0) | (PAT_WC << 8) | (PAT_UCM << 16) | (PAT_UC << 24) |
232  (PAT_WB << 32) | (PAT_WC << 40) | (PAT_UCM << 48) | (PAT_UC << 56);
233  __writemsr(MSR_PAT, Pat);
234 }
__INTRIN_INLINE void __writecr4(unsigned int Data)
Definition: intrin_x86.h:1680
#define PAT_UCM
Definition: ketypes.h:206
#define REQUIRED_FEATURE_BITS
Definition: kiinit.c:16
#define CR0_NE
Definition: asm.h:250
ULONG FeatureBits
Definition: ketypes.h:799
#define CR4_FXSR
Definition: ketypes.h:92
void KiSystemCallEntry32()
#define MSR_SYSCALL_MASK
Definition: ketypes.h:186
void KiInitializeSegments()
#define MSR_PAT
Definition: ketypes.h:215
#define MSR_LSTAR
Definition: ketypes.h:184
#define NX_SUPPORT_POLICY_ALWAYSON
Definition: ketypes.h:1084
ULONG(* FrLdrDbgPrint)(const char *Format,...)
Definition: kiinit.c:23
#define RPL_MASK
Definition: ketypes.h:69
__INTRIN_INLINE void __writecr0(unsigned int Data)
Definition: intrin_x86.h:1670
PPC_QUAL unsigned long long __readmsr()
Definition: intrin_ppc.h:741
#define MSR_STAR
Definition: ketypes.h:183
VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1507
#define EFLAGS_IF_MASK
Definition: ketypes.h:139
#define CR4_XMMEXCPT
Definition: ketypes.h:93
void KiSystemCallEntry64()
#define KGDT64_R0_CODE
Definition: ketypes.h:72
unsigned __int64 ULONG64
Definition: imports.h:198
#define SharedUserData
#define MSR_SCE
Definition: ketypes.h:211
KPRCB Prcb
Definition: ketypes.h:889
__INTRIN_INLINE unsigned long __readcr0(void)
Definition: intrin_x86.h:1692
#define EFLAGS_TF
Definition: ketypes.h:125
__INTRIN_INLINE unsigned long __readcr4(void)
Definition: intrin_x86.h:1713
#define MSR_EFER
Definition: ketypes.h:182
PPC_QUAL void __writemsr(const unsigned long Value)
Definition: intrin_ppc.h:748
#define PAT_WC
Definition: ketypes.h:202
ULONG KiGetFeatureBits()
#define PAT_WB
Definition: ketypes.h:205
#define MSR_GS_BASE
Definition: ketypes.h:188
#define EFLAGS_DF
Definition: strlen.c:26
VOID KiSetProcessorType()
#define MSR_CSTAR
Definition: ketypes.h:185
#define PAT_UC
Definition: ketypes.h:201
#define CR0_WP
Definition: asm.h:251
unsigned int ULONG
Definition: retypes.h:1
#define KGDT64_R3_CMCODE
Definition: ketypes.h:74
#define MSR_GS_SWAP
Definition: ketypes.h:189
#define CR0_MP
Definition: asm.h:246
#define KF_NX_ENABLED
Definition: ketypes.h:167
#define MSR_NXE
Definition: ketypes.h:214

Referenced by KiSystemStartup().

◆ KiInitializeKernelMachineDependent()

VOID NTAPI INIT_FUNCTION KiInitializeKernelMachineDependent ( IN PKPRCB  Prcb,
IN PLOADER_PARAMETER_BLOCK  LoaderBlock 
)

Definition at line 274 of file kiinit.c.

277 {
278  /* Set boot-level flags */
279  KeI386CpuType = Prcb->CpuType;
280  KeI386CpuStep = Prcb->CpuStep;
282  KeProcessorLevel = (USHORT)Prcb->CpuType;
283  if (Prcb->CpuID)
284  KeProcessorRevision = Prcb->CpuStep;
285 
286  /* Set basic CPU Features that user mode can read */
287  SharedUserData->ProcessorFeatures[PF_COMPARE_EXCHANGE_DOUBLE] = TRUE;
288  SharedUserData->ProcessorFeatures[PF_RDTSC_INSTRUCTION_AVAILABLE] = TRUE;
289  SharedUserData->ProcessorFeatures[PF_PPC_MOVEMEM_64BIT_OK] = TRUE;
290  SharedUserData->ProcessorFeatures[PF_PAE_ENABLED] = TRUE; // ???
291  SharedUserData->ProcessorFeatures[PF_NX_ENABLED] = TRUE;
292  SharedUserData->ProcessorFeatures[PF_FASTFAIL_AVAILABLE] = TRUE;
293  SharedUserData->ProcessorFeatures[PF_XSAVE_ENABLED] = TRUE;
294  SharedUserData->ProcessorFeatures[PF_MMX_INSTRUCTIONS_AVAILABLE] =
295  (Prcb->FeatureBits & KF_MMX) ? TRUE: FALSE;
296  SharedUserData->ProcessorFeatures[PF_XMMI_INSTRUCTIONS_AVAILABLE] =
297  ((Prcb->FeatureBits & KF_FXSR) && (Prcb->FeatureBits & KF_XMMI)) ? TRUE: FALSE;
299  ((Prcb->FeatureBits & KF_FXSR) && (Prcb->FeatureBits & KF_XMMI64)) ? TRUE: FALSE;
300  SharedUserData->ProcessorFeatures[PF_3DNOW_INSTRUCTIONS_AVAILABLE] =
301  (Prcb->FeatureBits & KF_3DNOW) ? TRUE: FALSE;
302  SharedUserData->ProcessorFeatures[PF_SSE3_INSTRUCTIONS_AVAILABLE] =
303  (Prcb->FeatureBits & KF_SSE3) ? TRUE: FALSE;
304  SharedUserData->ProcessorFeatures[PF_COMPARE_EXCHANGE128] =
305  (Prcb->FeatureBits & KF_CMPXCHG16B) ? TRUE: FALSE;
306 
307  /* Set the default NX policy (opt-in) */
308  SharedUserData->NXSupportPolicy = NX_SUPPORT_POLICY_OPTIN;
309 
310  /* Check if NPX is always on */
311  if (strstr(KeLoaderBlock->LoadOptions, "NOEXECUTE=ALWAYSON"))
312  {
313  /* Set it always on */
314  SharedUserData->NXSupportPolicy = NX_SUPPORT_POLICY_ALWAYSON;
315  Prcb->FeatureBits |= KF_NX_ENABLED;
316  }
317  else if (strstr(KeLoaderBlock->LoadOptions, "NOEXECUTE=OPTOUT"))
318  {
319  /* Set it in opt-out mode */
320  SharedUserData->NXSupportPolicy = NX_SUPPORT_POLICY_OPTOUT;
321  Prcb->FeatureBits |= KF_NX_ENABLED;
322  }
323  else if ((strstr(KeLoaderBlock->LoadOptions, "NOEXECUTE=OPTIN")) ||
324  (strstr(KeLoaderBlock->LoadOptions, "NOEXECUTE")))
325  {
326  /* Set the feature bits */
327  Prcb->FeatureBits |= KF_NX_ENABLED;
328  }
329  else if ((strstr(KeLoaderBlock->LoadOptions, "NOEXECUTE=ALWAYSOFF")) ||
330  (strstr(KeLoaderBlock->LoadOptions, "EXECUTE")))
331  {
332  /* Set disabled mode */
333  SharedUserData->NXSupportPolicy = NX_SUPPORT_POLICY_ALWAYSOFF;
334  Prcb->FeatureBits |= KF_NX_DISABLED;
335  }
336 }
#define PF_COMPARE_EXCHANGE128
#define TRUE
Definition: types.h:120
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
#define NX_SUPPORT_POLICY_OPTIN
Definition: ketypes.h:1085
#define PF_PPC_MOVEMEM_64BIT_OK
#define PF_COMPARE_EXCHANGE_DOUBLE
#define KF_MMX
Definition: ketypes.h:151
#define NX_SUPPORT_POLICY_ALWAYSON
Definition: ketypes.h:1084
#define NX_SUPPORT_POLICY_ALWAYSOFF
Definition: ketypes.h:1083
#define KF_XMMI
Definition: ketypes.h:156
#define NX_SUPPORT_POLICY_OPTOUT
Definition: ketypes.h:1086
#define PF_XMMI_INSTRUCTIONS_AVAILABLE
PLOADER_PARAMETER_BLOCK KeLoaderBlock
Definition: krnlinit.c:29
USHORT KeProcessorArchitecture
Definition: krnlinit.c:19
USHORT KeProcessorRevision
Definition: krnlinit.c:21
if(!(yy_init))
Definition: macro.lex.yy.c:714
#define PF_FASTFAIL_AVAILABLE
ULONG KeI386CpuType
Definition: cpu.c:28
#define PF_XSAVE_ENABLED
#define KF_FXSR
Definition: ketypes.h:154
#define KF_3DNOW
Definition: ketypes.h:157
#define PROCESSOR_ARCHITECTURE_AMD64
Definition: ketypes.h:114
#define SharedUserData
ULONG KeI386CpuStep
Definition: cpu.c:29
#define PF_SSE3_INSTRUCTIONS_AVAILABLE
#define KF_NX_DISABLED
Definition: ketypes.h:166
#define PF_RDTSC_INSTRUCTION_AVAILABLE
#define KF_XMMI64
Definition: ketypes.h:159
#define KF_CMPXCHG16B
Definition: ketypes.h:163
unsigned short USHORT
Definition: pedump.c:61
#define PF_PAE_ENABLED
#define PF_NX_ENABLED
#define KF_SSE3
Definition: ketypes.h:162
USHORT KeProcessorLevel
Definition: krnlinit.c:20
#define PF_XMMI64_INSTRUCTIONS_AVAILABLE
#define KF_NX_ENABLED
Definition: ketypes.h:167
#define PF_3DNOW_INSTRUCTIONS_AVAILABLE
#define PF_MMX_INSTRUCTIONS_AVAILABLE

Referenced by KiSystemStartup().

◆ KiInitializePcr()

VOID NTAPI KiInitializePcr ( IN PKIPCR  Pcr,
IN ULONG  ProcessorNumber,
IN PKTHREAD  IdleThread,
IN PVOID  DpcStack 
)

Definition at line 90 of file kiinit.c.

94 {
95  KDESCRIPTOR GdtDescriptor = {{0},0,0}, IdtDescriptor = {{0},0,0};
96  PKGDTENTRY64 TssEntry;
97  USHORT Tr = 0;
98 
99  /* Zero out the PCR */
100  RtlZeroMemory(Pcr, sizeof(KIPCR));
101 
102  /* Set pointers to ourselves */
103  Pcr->Self = (PKPCR)Pcr;
104  Pcr->CurrentPrcb = &Pcr->Prcb;
105 
106  /* Set the PCR Version */
107  Pcr->MajorVersion = PCR_MAJOR_VERSION;
108  Pcr->MinorVersion = PCR_MINOR_VERSION;
109 
110  /* Set the PRCB Version */
111  Pcr->Prcb.MajorVersion = 1;
112  Pcr->Prcb.MinorVersion = 1;
113 
114  /* Set the Build Type */
115  Pcr->Prcb.BuildType = 0;
116 #ifndef CONFIG_SMP
117  Pcr->Prcb.BuildType |= PRCB_BUILD_UNIPROCESSOR;
118 #endif
119 #if DBG
120  Pcr->Prcb.BuildType |= PRCB_BUILD_DEBUG;
121 #endif
122 
123  /* Set the Processor Number and current Processor Mask */
124  Pcr->Prcb.Number = (UCHAR)ProcessorNumber;
125  Pcr->Prcb.SetMember = 1ULL << ProcessorNumber;
126 
127  /* Get GDT and IDT descriptors */
128  __sgdt(&GdtDescriptor.Limit);
129  __sidt(&IdtDescriptor.Limit);
130  Pcr->GdtBase = (PVOID)GdtDescriptor.Base;
131  Pcr->IdtBase = (PKIDTENTRY)IdtDescriptor.Base;
132 
133  /* Get TSS Selector */
134  __str(&Tr);
135  ASSERT(Tr == KGDT64_SYS_TSS);
136 
137  /* Get TSS Entry */
138  TssEntry = KiGetGdtEntry(Pcr->GdtBase, Tr);
139 
140  /* Get the KTSS itself */
141  Pcr->TssBase = KiGetGdtDescriptorBase(TssEntry);
142 
143  Pcr->Prcb.RspBase = Pcr->TssBase->Rsp0; // FIXME
144 
145  /* Set DPC Stack */
146  Pcr->Prcb.DpcStack = DpcStack;
147 
148  /* Setup the processor set */
149  Pcr->Prcb.MultiThreadProcessorSet = Pcr->Prcb.SetMember;
150 
151  /* Clear DR6/7 to cleanup bootloader debugging */
152  Pcr->Prcb.ProcessorState.SpecialRegisters.KernelDr6 = 0;
153  Pcr->Prcb.ProcessorState.SpecialRegisters.KernelDr7 = 0;
154 
155  /* Set the Current Thread */
156  Pcr->Prcb.CurrentThread = IdleThread;
157 
158  /* Start us out at PASSIVE_LEVEL */
159  Pcr->Irql = PASSIVE_LEVEL;
161 }
VOID KeSetCurrentIrql(KIRQL NewIrql)
Definition: mpsirql.c:51
#define PRCB_BUILD_DEBUG
Definition: ketypes.h:242
PVOID Base
Definition: ketypes.h:486
USHORT Limit
Definition: ketypes.h:485
__INTRIN_INLINE void __sidt(void *Destination)
Definition: intrin_x86.h:1920
PVOID FORCEINLINE KiGetGdtDescriptorBase(PKGDTENTRY Entry)
Definition: intrin_i.h:20
void * PVOID
Definition: retypes.h:9
#define ULL(a, b)
Definition: format_msg.c:27
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
unsigned char UCHAR
Definition: xmlstorage.h:181
#define KGDT64_SYS_TSS
Definition: ketypes.h:77
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
#define PCR_MINOR_VERSION
Definition: ke.h:277
unsigned short USHORT
Definition: pedump.c:61
#define PRCB_BUILD_UNIPROCESSOR
Definition: ketypes.h:243
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
struct _KPCR * PKPCR
#define PCR_MAJOR_VERSION
Definition: ke.h:278
FORCEINLINE PKGDTENTRY KiGetGdtEntry(IN PVOID pGdt, IN USHORT Selector)
Definition: winldr.c:69

Referenced by KiInitializeSystem(), KiSystemStartup(), and KiSystemStartupReal().

◆ KiInitializeSegments()

void KiInitializeSegments ( )

Referenced by KiInitializeCpu().

◆ KiInitializeTss()

VOID FASTCALL KiInitializeTss ( IN PKTSS64  Tss,
IN UINT64  Stack 
)

Definition at line 238 of file kiinit.c.

240 {
241  PKGDTENTRY64 TssEntry;
242 
243  /* Get pointer to the GDT entry */
244  TssEntry = KiGetGdtEntry(KeGetPcr()->GdtBase, KGDT64_SYS_TSS);
245 
246  /* Initialize the GDT entry */
247  KiInitGdtEntry(TssEntry, (ULONG64)Tss, sizeof(KTSS64), AMD64_TSS, 0);
248 
249  /* Zero out the TSS */
250  RtlZeroMemory(Tss, sizeof(KTSS64));
251 
252  /* FIXME: I/O Map? */
253  Tss->IoMapBase = 0x68;
254 
255  /* Setup ring 0 stack pointer */
256  Tss->Rsp0 = Stack;
257 
258  /* Setup a stack for Double Fault Traps */
259  Tss->Ist[1] = (ULONG64)KiDoubleFaultStack;
260 
261  /* Setup a stack for CheckAbort Traps */
262  Tss->Ist[2] = (ULONG64)KiDoubleFaultStack;
263 
264  /* Setup a stack for NMI Traps */
265  Tss->Ist[3] = (ULONG64)KiDoubleFaultStack;
266 
267  /* Load the task register */
268  __ltr(KGDT64_SYS_TSS);
269 }
VOID FORCEINLINE KiInitGdtEntry(PKGDTENTRY64 Entry, ULONG64 Base, ULONG Size, UCHAR Type, UCHAR Dpl)
Definition: intrin_i.h:48
#define KeGetPcr()
Definition: ke.h:25
ULONG_PTR KiDoubleFaultStack
Definition: kiinit.c:35
unsigned __int64 ULONG64
Definition: imports.h:198
#define AMD64_TSS
Definition: ke.h:81
#define KGDT64_SYS_TSS
Definition: ketypes.h:77
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
FORCEINLINE PKGDTENTRY KiGetGdtEntry(IN PVOID pGdt, IN USHORT Selector)
Definition: winldr.c:69

Referenced by KiSystemStartup().

◆ KiInitMachineDependent()

INIT_FUNCTION VOID NTAPI KiInitMachineDependent ( VOID  )

Definition at line 46 of file kiinit.c.

47 {
48  /* Check for large page support */
50  {
51  /* FIXME: Support this */
52  DPRINT("Large Page support detected but not yet taken advantage of!\n");
53  }
54 
55  /* Check for global page support */
57  {
58  /* FIXME: Support this */
59  DPRINT("Global Page support detected but not yet taken advantage of!\n");
60  }
61 
62  /* Check if we have MTRR */
63  if (KeFeatureBits & KF_MTRR)
64  {
65  /* FIXME: Support this */
66  DPRINT("MTRR support detected but not yet taken advantage of!\n");
67  }
68 
69  /* Check for PAT and/or MTRR support */
70  if (KeFeatureBits & KF_PAT)
71  {
72  /* FIXME: Support this */
73  DPRINT("PAT support detected but not yet taken advantage of!\n");
74  }
75 
76  /* Allocate the IOPM save area. */
77 // Ki386IopmSaveArea = ExAllocatePoolWithTag(PagedPool,
78 // PAGE_SIZE * 2,
79 // TAG('K', 'e', ' ', ' '));
80 // if (!Ki386IopmSaveArea)
81 // {
82 // /* Bugcheck. We need this for V86/VDM support. */
83 // KeBugCheckEx(NO_PAGES_AVAILABLE, 2, PAGE_SIZE * 2, 0, 0);
84 // }
85 
86 }
ULONG KeFeatureBits
Definition: krnlinit.c:22
#define KF_LARGE_PAGE
Definition: ketypes.h:148
#define KF_PAT
Definition: ketypes.h:153
void DPRINT(...)
Definition: polytest.cpp:61
#define KF_MTRR
Definition: ketypes.h:149
#define KF_GLOBAL_PAGE
Definition: ketypes.h:147

◆ KiInitModuleList()

void KiInitModuleList ( IN PLOADER_PARAMETER_BLOCK  LoaderBlock)

Definition at line 341 of file kiinit.c.

342 {
343  PLDR_DATA_TABLE_ENTRY LdrEntry;
345  ULONG i;
346 
347  /* Initialize the list head */
349 
350  /* Loop the first 3 entries */
351  for (Entry = LoaderBlock->LoadOrderListHead.Flink, i = 0;
352  Entry != &LoaderBlock->LoadOrderListHead && i < 3;
353  Entry = Entry->Flink, i++)
354  {
355  /* Get the data table entry */
356  LdrEntry = CONTAINING_RECORD(Entry,
358  InLoadOrderLinks);
359 
360  /* Copy the entry */
361  LdrCoreEntries[i] = *LdrEntry;
362 
363  /* Insert the copy into the list */
364  InsertTailList(&PsLoadedModuleList, &LdrCoreEntries[i].InLoadOrderLinks);
365  }
366 }
struct _Entry Entry
Definition: kefuncs.h:640
#define InsertTailList(ListHead, Entry)
static LDR_DATA_TABLE_ENTRY LdrCoreEntries[3]
Definition: kiinit.c:338
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
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
LIST_ENTRY PsLoadedModuleList
Definition: sysldr.c:34
Definition: btrfs_drv.h:1853
Definition: typedefs.h:117
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
unsigned int ULONG
Definition: retypes.h:1
base of all file and directory entries
Definition: entries.h:82

Referenced by KiSystemStartup().

◆ KiSystemCallEntry32()

void KiSystemCallEntry32 ( )

Referenced by KiInitializeCpu().

◆ KiSystemCallEntry64()

void KiSystemCallEntry64 ( )

Referenced by KiInitializeCpu().

◆ KiSystemStartup()

INIT_FUNCTION VOID NTAPI KiSystemStartup ( IN PLOADER_PARAMETER_BLOCK  LoaderBlock)

Definition at line 371 of file kiinit.c.

372 {
373  CCHAR Cpu;
374  PKTHREAD InitialThread;
375  ULONG64 InitialStack;
376  PKIPCR Pcr;
377 
378  /* HACK */
379  FrLdrDbgPrint = LoaderBlock->u.I386.CommonDataArea;
380  //FrLdrDbgPrint("Hello from KiSystemStartup!!!\n");
381 
382  /* Save the loader block */
383  KeLoaderBlock = LoaderBlock;
384 
385  /* Get the current CPU number */
386  Cpu = KeNumberProcessors++; // FIXME
387 
388  /* LoaderBlock initialization for Cpu 0 */
389  if (Cpu == 0)
390  {
391  /* Set the initial stack, idle thread and process */
392  LoaderBlock->KernelStack = (ULONG_PTR)P0BootStack;
393  LoaderBlock->Thread = (ULONG_PTR)&KiInitialThread;
394  LoaderBlock->Process = (ULONG_PTR)&KiInitialProcess.Pcb;
395  LoaderBlock->Prcb = (ULONG_PTR)&KiInitialPcr.Prcb;
396  }
397 
398  /* Get Pcr from loader block */
399  Pcr = CONTAINING_RECORD(LoaderBlock->Prcb, KIPCR, Prcb);
400 
401  /* Set the PRCB for this Processor */
402  KiProcessorBlock[Cpu] = &Pcr->Prcb;
403 
404  /* Align stack to 16 bytes */
405  LoaderBlock->KernelStack &= ~(16 - 1);
406 
407  /* Save the initial thread and stack */
408  InitialStack = LoaderBlock->KernelStack; // Checkme
409  InitialThread = (PKTHREAD)LoaderBlock->Thread;
410 
411  /* Set us as the current process */
412  InitialThread->ApcState.Process = (PVOID)LoaderBlock->Process;
413 
414  /* Initialize the PCR */
415  KiInitializePcr(Pcr, Cpu, InitialThread, (PVOID)KiDoubleFaultStack);
416 
417  /* Initialize the CPU features */
418  KiInitializeCpu(Pcr);
419 
420  /* Initial setup for the boot CPU */
421  if (Cpu == 0)
422  {
423  /* Initialize the module list (ntos, hal, kdcom) */
424  KiInitModuleList(LoaderBlock);
425 
426  /* Setup the TSS descriptors and entries */
427  KiInitializeTss(Pcr->TssBase, InitialStack);
428 
429  /* Setup the IDT */
431 
432  /* Initialize debugging system */
434 
435  /* Check for break-in */
437  }
438 
439  DPRINT1("Pcr = %p, Gdt = %p, Idt = %p, Tss = %p\n",
440  Pcr, Pcr->GdtBase, Pcr->IdtBase, Pcr->TssBase);
441 
442  /* Acquire lock */
443  while (InterlockedBitTestAndSet64((PLONG64)&KiFreezeExecutionLock, 0))
444  {
445  /* Loop until lock is free */
446  while ((*(volatile KSPIN_LOCK*)&KiFreezeExecutionLock) & 1);
447  }
448 
449  /* Initialize the Processor with HAL */
451 
452  /* Set processor as active */
453  KeActiveProcessors |= 1ULL << Cpu;
454 
455  /* Release lock */
457 
458  /* Raise to HIGH_LEVEL */
460 
461  /* Machine specific kernel initialization */
462  if (Cpu == 0) KiInitializeKernelMachineDependent(&Pcr->Prcb, LoaderBlock);
463 
464  /* Switch to new kernel stack and start kernel bootstrapping */
465  KiSwitchToBootStack(InitialStack & ~3);
466 }
VOID FASTCALL KiInitializeTss(IN PKTSS64 Tss, IN UINT64 Stack)
Definition: kiinit.c:238
#define InterlockedAnd64
Definition: interlocked.h:87
union _KGDTENTRY64 * GdtBase
Definition: ketypes.h:860
VOID NTAPI KiInitializePcr(IN PKIPCR Pcr, IN ULONG ProcessorNumber, IN PKTHREAD IdleThread, IN PVOID DpcStack)
Definition: kiinit.c:90
struct _KTSS64 * TssBase
Definition: ketypes.h:861
uint32_t ULONG_PTR
Definition: typedefs.h:63
ULONG(* FrLdrDbgPrint)(const char *Format,...)
Definition: kiinit.c:23
ULONG_PTR P0BootStack
Definition: kiinit.c:34
struct _KTHREAD * PKTHREAD
Definition: nt_native.h:28
VOID NTAPI HalInitializeProcessor(IN ULONG ProcessorNumber, IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: processor.c:48
KAPC_STATE ApcState
Definition: ketypes.h:1668
BOOLEAN NTAPI KdPollBreakIn(VOID)
Definition: kdmain.c:352
void KiInitModuleList(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: kiinit.c:341
PLOADER_PARAMETER_BLOCK KeLoaderBlock
Definition: krnlinit.c:29
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define ULL(a, b)
Definition: format_msg.c:27
ULONG_PTR KiDoubleFaultStack
Definition: kiinit.c:35
KIRQL FASTCALL KfRaiseIrql(IN KIRQL NewIrql)
Definition: pic.c:187
char CCHAR
Definition: typedefs.h:50
VOID NTAPI KiInitializeCpu(PKIPCR Pcr)
Definition: kiinit.c:165
unsigned __int64 ULONG64
Definition: imports.h:198
KPRCB Prcb
Definition: ketypes.h:889
VOID KiSwitchToBootStack(IN ULONG_PTR InitialStack)
Definition: ke.h:815
KPROCESS Pcb
Definition: pstypes.h:1193
KIPCR KiInitialPcr
Definition: kiinit.c:29
KAFFINITY KeActiveProcessors
Definition: krnlinit.c:23
CCHAR KeNumberProcessors
Definition: krnlinit.c:35
EPROCESS KiInitialProcess
Definition: krnlinit.c:45
union _KIDTENTRY64 * IdtBase
Definition: ketypes.h:869
#define HIGH_LEVEL
Definition: env_spec_w32.h:703
INIT_FUNCTION VOID NTAPI KeInitExceptions(VOID)
Definition: except.c:59
BOOLEAN NTAPI KdInitSystem(ULONG Reserved, PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: kdinit.c:169
PKPRCB KiProcessorBlock[]
Definition: krnlinit.c:32
ETHREAD KiInitialThread
Definition: krnlinit.c:44
ULONG KSPIN_LOCK
Definition: env_spec_w32.h:72
VOID NTAPI INIT_FUNCTION KiInitializeKernelMachineDependent(IN PKPRCB Prcb, IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: kiinit.c:274
#define DPRINT1
Definition: precomp.h:8
#define DBG_STATUS_CONTROL_C
Definition: kdtypes.h:39
KSPIN_LOCK KiFreezeExecutionLock
Definition: kiinit.c:26
#define ULONG_PTR
Definition: config.h:101
__analysis_noreturn NTSYSAPI VOID NTAPI DbgBreakPointWithStatus(_In_ ULONG Status)
__int64 * PLONG64
Definition: basetsd.h:185

Variable Documentation

◆ FrLdrDbgPrint

ULONG(* FrLdrDbgPrint) (const char *Format,...)

Definition at line 23 of file kiinit.c.

Referenced by KiInitializeCpu(), and KiSystemStartup().

◆ KiDoubleFaultStack

ULONG_PTR KiDoubleFaultStack = (ULONG_PTR)&KiDoubleFaultStackData[KERNEL_STACK_SIZE]

Definition at line 35 of file kiinit.c.

Referenced by KiInitializeTss(), KiSystemStartup(), and KiSystemStartupReal().

◆ KiFreezeExecutionLock

KSPIN_LOCK KiFreezeExecutionLock

Definition at line 26 of file kiinit.c.

Referenced by KiInitializeKernel(), and KiSystemStartup().

◆ KiInitialPcr

KIPCR KiInitialPcr

Definition at line 29 of file kiinit.c.

Referenced by KiSystemStartup().

◆ LdrCoreEntries

LDR_DATA_TABLE_ENTRY LdrCoreEntries[3]
static

Definition at line 338 of file kiinit.c.

Referenced by KiInitModuleList().

◆ P0BootStack

ULONG_PTR P0BootStack = (ULONG_PTR)&P0BootStackData[KERNEL_STACK_SIZE]

Definition at line 34 of file kiinit.c.

Referenced by KiSystemStartup(), and KiSystemStartupReal().