00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
#include "ki.h"
00032
00033
00034
00035
00036
00037 extern KSPIN_LOCK
CcMasterSpinLock;
00038 extern KSPIN_LOCK
CcVacbSpinLock;
00039 extern KSPIN_LOCK
MmPfnLock;
00040 extern KSPIN_LOCK
MmSystemSpaceLock;
00041
00042
00043
00044
00045
00046 ULONG
00047
KiGetFeatureBits (
00048 VOID
00049 );
00050
00051 __inline
00052 ULONG
00053 amask(
00054 IN ULONG Feature
00055 )
00056
00057 {
00058
return(__asm(
"amask %0, v0",Feature));
00059 }
00060
#ifdef ALLOC_PRAGMA
00061
#pragma alloc_text(INIT, KiInitializeKernel)
00062
#endif
00063
00064
VOID
00065 KiInitializeKernel (
00066 IN
PKPROCESS Process,
00067 IN
PKTHREAD Thread,
00068 IN PVOID IdleStack,
00069 IN PKPRCB Prcb,
00070 IN CCHAR Number,
00071 IN
PLOADER_PARAMETER_BLOCK LoaderBlock
00072 )
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111 {
00112
00113 UCHAR DataByte;
00114 ULONG DataLong;
00115 LONG
Index;
00116 KIRQL OldIrql;
00117 PKPCR Pcr = PCR;
00118
struct _RESTART_BLOCK *RestartBlock;
00119
00120
00121
00122
00123
00124
KeLoaderBlock = LoaderBlock;
00125
00126
00127
00128
00129
00130
SetMember(Number,
KeActiveProcessors);
00131
00132
00133
00134
00135
00136
00137
if ((Number + 1) >
KeNumberProcessors) {
00138
KeNumberProcessors = Number + 1;
00139 }
00140
00141
00142
00143
00144
00145
00146
if (Number == 0) {
00147 KiMaximumAsn = LoaderBlock->u.Alpha.MaximumAddressSpaceNumber;
00148
00149 }
else if (KiMaximumAsn > LoaderBlock->u.Alpha.MaximumAddressSpaceNumber) {
00150 KiMaximumAsn = LoaderBlock->u.Alpha.MaximumAddressSpaceNumber;
00151 }
00152
00153
00154
00155
00156
00157 Pcr->InterruptRoutine[0] =
KiPassiveRelease;
00158 Pcr->InterruptRoutine[
APC_LEVEL] =
KiApcInterrupt;
00159 Pcr->InterruptRoutine[
DISPATCH_LEVEL] =
KiDispatchInterrupt;
00160 Pcr->ReservedVectors =
00161 (1 <<
PASSIVE_LEVEL) | (1 <<
APC_LEVEL) | (1 <<
DISPATCH_LEVEL);
00162
00163
00164
00165
00166
00167 Pcr->Number = Number;
00168 Pcr->SetMember = 1 << Number;
00169 Pcr->NotMember = ~Pcr->SetMember;
00170
00171
00172
00173
00174
00175 Prcb->MinorVersion =
PRCB_MINOR_VERSION;
00176 Prcb->MajorVersion =
PRCB_MAJOR_VERSION;
00177 Prcb->BuildType = 0;
00178
00179
#if DBG
00180
00181 Prcb->BuildType |= PRCB_BUILD_DEBUG;
00182
00183
#endif
00184
00185
#ifdef NT_UP
00186
00187 Prcb->BuildType |= PRCB_BUILD_UNIPROCESSOR;
00188
00189
#endif
00190
00191 Prcb->CurrentThread = Thread;
00192 Prcb->NextThread = (
PKTHREAD)
NULL;
00193 Prcb->IdleThread = Thread;
00194 Prcb->Number = Number;
00195 Prcb->SetMember = 1 << Number;
00196
00197
KeInitializeDpc(&Prcb->QuantumEndDpc,
00198 (
PKDEFERRED_ROUTINE)
KiQuantumEnd,
00199
NIL);
00200
00201
00202
00203
00204
00205
#if !defined(NT_UP)
00206
00207 Prcb->LockQueue[
LockQueueDispatcherLock].Next =
NULL;
00208 Prcb->LockQueue[
LockQueueDispatcherLock].Lock = &
KiDispatcherLock;
00209 Prcb->LockQueue[
LockQueueContextSwapLock].Next =
NULL;
00210 Prcb->LockQueue[
LockQueueContextSwapLock].Lock = &
KiContextSwapLock;
00211 Prcb->LockQueue[
LockQueuePfnLock].Next =
NULL;
00212 Prcb->LockQueue[
LockQueuePfnLock].Lock = &
MmPfnLock;
00213 Prcb->LockQueue[
LockQueueSystemSpaceLock].Next =
NULL;
00214 Prcb->LockQueue[
LockQueueSystemSpaceLock].Lock = &
MmSystemSpaceLock;
00215 Prcb->LockQueue[
LockQueueMasterLock].Next =
NULL;
00216 Prcb->LockQueue[
LockQueueMasterLock].Lock = &
CcMasterSpinLock;
00217 Prcb->LockQueue[
LockQueueVacbLock].Next =
NULL;
00218 Prcb->LockQueue[
LockQueueVacbLock].Lock = &
CcVacbSpinLock;
00219
00220
#endif
00221
00222
00223
00224
00225
00226 Prcb->Pcr = Pcr;
00227
00228
00229
00230
00231
00232
#if !defined(NT_UP)
00233
00234 Prcb->TargetSet = 0;
00235 Prcb->WorkerRoutine =
NULL;
00236 Prcb->RequestSummary = 0;
00237 Prcb->IpiFrozen = 0;
00238
00239
#if NT_INST
00240
00241 Prcb->IpiCounts = &KiIpiCounts[Number];
00242
00243
#endif //NT_INST
00244
00245
#endif //NT_UP
00246
00247 Prcb->MaximumDpcQueueDepth =
KiMaximumDpcQueueDepth;
00248 Prcb->MinimumDpcRate =
KiMinimumDpcRate;
00249 Prcb->AdjustDpcThreshold =
KiAdjustDpcThreshold;
00250
00251
00252
00253
00254
00255 InitializeListHead(&Prcb->DpcListHead);
00256
KeInitializeSpinLock(&Prcb->DpcLock);
00257
00258
00259
00260
00261
00262
KiProcessorBlock[Number] = Prcb;
00263
00264
00265
00266
00267
00268 Thread->ApcState.Process = Process;
00269
00270
00271
00272
00273
00274
SetMember( Number,
KeActiveProcessors );
00275
00276
00277
00278
00279
00280
00281
if( (Number+1) >
KeNumberProcessors ){
00282
KeNumberProcessors = Number + 1;
00283 }
00284
00285
00286
00287
00288
00289
PoInitializePrcb (Prcb);
00290
00291
00292
00293
00294
00295
00296
#ifdef _AXP64_
00297
KeProcessorArchitecture = PROCESSOR_ARCHITECTURE_ALPHA64;
00298
#else
00299
KeProcessorArchitecture = PROCESSOR_ARCHITECTURE_ALPHA;
00300
#endif
00301
00302
if ((
KeProcessorLevel == 0) ||
00303 (
KeProcessorLevel > (
USHORT)Pcr->ProcessorType)) {
00304
KeProcessorLevel = (
USHORT)Pcr->ProcessorType;
00305 }
00306
00307
if ((
KeProcessorRevision == 0) ||
00308 (
KeProcessorRevision > (
USHORT)Pcr->ProcessorRevision)) {
00309
KeProcessorRevision = (
USHORT)Pcr->ProcessorRevision;
00310 }
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
if (Number == 0) {
00323
00324
KeFeatureBits =
KiGetFeatureBits();
00325
00326
00327
00328
00329
00330 KxUnexpectedInterrupt.DispatchAddress =
KiUnexpectedInterrupt;
00331
00332
00333
00334
00335
00336
KeInitializeSpinLock(&
KiContextSwapLock);
00337
00338
00339
00340
00341
00342
00343
00344
for (
Index = 0;
Index < DISPATCH_LENGTH;
Index += 1) {
00345 KxUnexpectedInterrupt.DispatchCode[
Index] = KiInterruptTemplate[
Index];
00346 }
00347
00348
00349
00350
00351
00352 KiImb();
00353
00354 }
else {
00355
00356
00357
00358
00359
00360
KeFeatureBits &=
KiGetFeatureBits();
00361 }
00362
00363
00364
00365
00366
00367 SharedUserData->ProcessorFeatures[PF_ALPHA_BYTE_INSTRUCTIONS] =
00368 (
KeFeatureBits & KF_BYTE) ?
TRUE :
FALSE;
00369
00370
for (
Index =
DISPATCH_LEVEL+1;
Index < MAXIMUM_VECTOR;
Index += 1) {
00371 Pcr->InterruptRoutine[
Index] = (PKINTERRUPT_ROUTINE)(&KxUnexpectedInterrupt.DispatchCode);
00372 }
00373
00374
00375
00376
00377
00378
KeRaiseIrql(
APC_LEVEL, &OldIrql);
00379
00380
00381
00382
00383
00384
00385
if (Number == 0) {
00386
00387
00388
00389
00390
00391 Prcb->RestartBlock = SYSTEM_BLOCK->RestartBlock;
00392
00393
00394
00395
00396
00397
if (
KdInitSystem(LoaderBlock,
FALSE) ==
FALSE) {
00398
KeBugCheck(PHASE0_INITIALIZATION_FAILED);
00399 }
00400
00401
#if DBG
00402
00403
00404
00405
00406
00407
if (
KdPollBreakIn() !=
FALSE){
00408 DbgBreakPointWithStatus(
DBG_STATUS_CONTROL_C);
00409 }
00410
00411
#endif //DBG
00412
00413
00414
00415
00416
00417
for (
Index = 1;
Index <
MAXIMUM_PROCESSORS;
Index += 1) {
00418
KiProcessorBlock[
Index] = (PKPRCB)
NULL;
00419 }
00420
00421
00422
00423
00424
00425
KiDmaIoCoherency =
DMA_READ_DCACHE_INVALIDATE |
DMA_WRITE_DCACHE_SNOOP;
00426
00427
00428
00429
00430
00431
KiInitSystem();
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
KeInitializeProcess(Process,
00442 (KPRIORITY)0,
00443 (KAFFINITY)(0xffffffff),
00444 (PULONG_PTR)PDE_SELFMAP,
00445
FALSE);
00446
00447 Process->ThreadQuantum = MAXCHAR;
00448 }
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
KeInitializeThread(Thread,
00463 (PVOID)((ULONG_PTR)IdleStack -
PAGE_SIZE),
00464 (
PKSYSTEM_ROUTINE)
NULL,
00465 (
PKSTART_ROUTINE)
NULL,
00466 (PVOID)
NULL,
00467 (PCONTEXT)
NULL,
00468 (PVOID)
NULL,
00469 Process);
00470
00471 Thread->InitialStack = IdleStack;
00472 Thread->StackBase = IdleStack;
00473 Thread->StackLimit = (PVOID)((ULONG_PTR)IdleStack - KERNEL_STACK_SIZE);
00474 Thread->NextProcessor = Number;
00475 Thread->Priority = HIGH_PRIORITY;
00476 Thread->State =
Running;
00477 Thread->Affinity = (KAFFINITY)(1 << Number);
00478 Thread->WaitIrql =
DISPATCH_LEVEL;
00479
00480
00481
00482
00483
00484
00485
if (Number == 0) {
00486
SetMember(Number, Process->ActiveProcessors);
00487 }
00488
00489
00490
00491
00492
00493
try {
00494
ExpInitializeExecutive(Number, LoaderBlock);
00495
00496 } except(
KeBugCheckEx(PHASE0_EXCEPTION,
00497 (ULONG)GetExceptionCode(),
00498 (ULONG_PTR)GetExceptionInformation(),
00499 0,0),
EXCEPTION_EXECUTE_HANDLER) {
00500 ;
00501 }
00502
00503
00504
00505
00506
00507
00508
00509
00510
if (Number == 0) {
00511
KiTimeIncrementReciprocal =
KiComputeReciprocal((LONG)
KeMaximumIncrement,
00512 &
KiTimeIncrementShiftCount);
00513
00514 Prcb->MaximumDpcQueueDepth =
KiMaximumDpcQueueDepth;
00515 Prcb->MinimumDpcRate =
KiMinimumDpcRate;
00516 Prcb->AdjustDpcThreshold =
KiAdjustDpcThreshold;
00517 }
00518
00519
00520
00521
00522
00523
00524
00525
KiDisableAlignmentExceptions();
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
KeRaiseIrql(
DISPATCH_LEVEL, &OldIrql);
00536
KeSetPriorityThread(Thread, (KPRIORITY)0);
00537 Thread->Priority = LOW_REALTIME_PRIORITY;
00538
00539
00540
00541
00542
00543
KeRaiseIrql(
HIGH_LEVEL, &OldIrql);
00544
00545
00546
00547
00548
00549
00550
#if !defined(NT_UP)
00551
00552 RestartBlock = Prcb->RestartBlock;
00553
if (RestartBlock !=
NULL) {
00554 RestartBlock->BootStatus.BootFinished = 1;
00555 }
00556
00557
00558
00559
00560
00561
00562
00563
if ((Number != 0) && (Prcb->NextThread ==
NULL)) {
00564
SetMember(Number,
KiIdleSummary);
00565 }
00566
00567
#endif //NT_UP
00568
00569
return;
00570 }
00571
00572 ULONG
00573 KiGetFeatureBits(
00574 VOID
00575 )
00576
00577
00578
00579
00580
00581
00582
00583 {
00584
00585 ULONG Features = 0;
00586
00587
00588
00589
00590
00591
if (
amask(1) == 0) {
00592 Features |= KF_BYTE;
00593 }
00594
00595
return Features;
00596 }
00597
00598
#if defined(_AXP64_)
00599
00600
00601
VOID
00602 KiStartHalThread (
00603 IN
PKTHREAD Thread,
00604 IN PVOID Stack,
00605 IN PKSTART_ROUTINE StartRoutine,
00606 IN ULONG_PTR Process
00607 )
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631 {
00632
00633
00634
00635
00636
00637
KeInitializeThread(Thread,
00638 Stack,
00639 (PKSYSTEM_ROUTINE)StartRoutine,
00640 NULL,
00641 NULL,
00642 NULL,
00643 NULL,
00644 (
PKPROCESS)Process);
00645
00646
00647
00648
00649
00650 Thread->Priority = (KPRIORITY) NORMAL_BASE_PRIORITY - 1;
00651
KeReadyThread(Thread);
00652
return;
00653 }
00654
00655
#endif