2008-02-12 16:22:01 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS Kernel
|
2008-06-29 02:58:05 +00:00
|
|
|
* LICENSE: BSD - See COPYING.ARM in the top level directory
|
2008-02-12 16:22:01 +00:00
|
|
|
* FILE: ntoskrnl/ke/arm/kiinit.c
|
|
|
|
* PURPOSE: Implements the kernel entry point for ARM machines
|
|
|
|
* PROGRAMMERS: ReactOS Portable Systems Group
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES *******************************************************************/
|
|
|
|
|
|
|
|
#include <ntoskrnl.h>
|
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
2015-05-14 22:31:58 +00:00
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
KdPortPutByteEx(
|
|
|
|
PCPPORT PortInformation,
|
|
|
|
UCHAR ByteToSend
|
|
|
|
);
|
|
|
|
|
2008-02-12 16:22:01 +00:00
|
|
|
/* GLOBALS ********************************************************************/
|
|
|
|
|
2008-02-12 22:50:54 +00:00
|
|
|
KINTERRUPT KxUnexpectedInterrupt;
|
2008-02-12 16:22:01 +00:00
|
|
|
BOOLEAN KeIsArmV6;
|
|
|
|
ULONG KeNumberProcessIds;
|
|
|
|
ULONG KeNumberTbEntries;
|
2010-02-01 03:51:45 +00:00
|
|
|
ULONG ProcessCount; // PERF
|
2008-03-11 02:45:13 +00:00
|
|
|
extern PVOID KiArmVectorTable;
|
2008-02-12 16:22:01 +00:00
|
|
|
#define __ARMV6__ KeIsArmV6
|
|
|
|
|
|
|
|
/* FUNCTIONS ******************************************************************/
|
|
|
|
|
2008-06-15 05:40:27 +00:00
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
KiInitMachineDependent(VOID)
|
|
|
|
{
|
2010-02-09 02:11:18 +00:00
|
|
|
/* There is nothing to do on ARM */
|
2008-06-15 05:40:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-02-12 16:22:01 +00:00
|
|
|
VOID
|
2008-02-12 22:50:54 +00:00
|
|
|
NTAPI
|
|
|
|
KiInitializeKernel(IN PKPROCESS InitProcess,
|
|
|
|
IN PKTHREAD InitThread,
|
|
|
|
IN PVOID IdleStack,
|
|
|
|
IN PKPRCB Prcb,
|
|
|
|
IN CCHAR Number,
|
|
|
|
IN PLOADER_PARAMETER_BLOCK LoaderBlock)
|
2008-02-12 16:22:01 +00:00
|
|
|
{
|
2010-02-09 02:11:18 +00:00
|
|
|
PKIPCR Pcr = (PKIPCR)KeGetPcr();
|
2009-07-12 10:47:45 +00:00
|
|
|
ULONG PageDirectory[2];
|
2008-02-12 22:50:54 +00:00
|
|
|
ULONG i;
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2010-02-09 02:11:18 +00:00
|
|
|
/* Set the default NX policy (opt-in) */
|
|
|
|
SharedUserData->NXSupportPolicy = NX_SUPPORT_POLICY_OPTIN;
|
2008-02-12 22:50:54 +00:00
|
|
|
|
2010-02-09 02:11:18 +00:00
|
|
|
/* Initialize spinlocks and DPC data */
|
2008-02-12 22:50:54 +00:00
|
|
|
KiInitSpinLocks(Prcb, Number);
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2010-02-09 02:11:18 +00:00
|
|
|
/* Set stack pointers */
|
2015-05-14 22:31:58 +00:00
|
|
|
//Pcr->InitialStack = IdleStack;
|
|
|
|
Pcr->Prcb.SpBase = IdleStack; // ???
|
2008-02-12 22:50:54 +00:00
|
|
|
|
2010-02-09 02:11:18 +00:00
|
|
|
/* Check if this is the Boot CPU */
|
2008-02-12 22:50:54 +00:00
|
|
|
if (!Number)
|
2008-02-12 19:01:48 +00:00
|
|
|
{
|
2010-02-09 02:11:18 +00:00
|
|
|
/* Setup the unexpected interrupt */
|
2008-02-12 22:50:54 +00:00
|
|
|
KxUnexpectedInterrupt.DispatchAddress = KiUnexpectedInterrupt;
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
{
|
2010-02-09 02:11:18 +00:00
|
|
|
/* Copy the template code */
|
2010-02-01 03:51:45 +00:00
|
|
|
KxUnexpectedInterrupt.DispatchCode[i] = ((PULONG)KiInterruptTemplate)[i];
|
2008-02-12 22:50:54 +00:00
|
|
|
}
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2010-02-09 02:11:18 +00:00
|
|
|
/* Set DMA coherency */
|
2008-02-12 22:50:54 +00:00
|
|
|
KiDmaIoCoherency = 0;
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2010-02-09 02:11:18 +00:00
|
|
|
/* Sweep D-Cache */
|
2008-02-12 22:50:54 +00:00
|
|
|
HalSweepDcache();
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2010-02-09 02:11:18 +00:00
|
|
|
/* Set boot-level flags */
|
|
|
|
KeProcessorArchitecture = PROCESSOR_ARCHITECTURE_ARM;
|
|
|
|
KeFeatureBits = 0;
|
2015-05-14 22:31:58 +00:00
|
|
|
/// FIXME: just a wild guess
|
|
|
|
KeProcessorLevel = (USHORT)(Pcr->Prcb.ProcessorState.ArchState.Cp15_Cr0_CpuId >> 8);
|
|
|
|
KeProcessorRevision = (USHORT)(Pcr->Prcb.ProcessorState.ArchState.Cp15_Cr0_CpuId & 0xFF);
|
|
|
|
#if 0
|
2010-02-09 02:11:18 +00:00
|
|
|
/* Set the current MP Master KPRCB to the Boot PRCB */
|
|
|
|
Prcb->MultiThreadSetMaster = Prcb;
|
2015-05-14 22:31:58 +00:00
|
|
|
#endif
|
2010-02-09 02:11:18 +00:00
|
|
|
/* Lower to APC_LEVEL */
|
|
|
|
KeLowerIrql(APC_LEVEL);
|
2008-02-12 22:50:54 +00:00
|
|
|
|
2010-02-09 02:11:18 +00:00
|
|
|
/* Initialize portable parts of the OS */
|
2008-02-12 20:32:23 +00:00
|
|
|
KiInitSystem();
|
2008-02-12 22:50:54 +00:00
|
|
|
|
2010-02-09 02:11:18 +00:00
|
|
|
/* Initialize the Idle Process and the Process Listhead */
|
2008-02-12 20:32:23 +00:00
|
|
|
InitializeListHead(&KiProcessListHead);
|
2010-02-09 02:11:18 +00:00
|
|
|
PageDirectory[0] = 0;
|
|
|
|
PageDirectory[1] = 0;
|
2008-02-12 20:32:23 +00:00
|
|
|
KeInitializeProcess(InitProcess,
|
|
|
|
0,
|
|
|
|
0xFFFFFFFF,
|
2009-07-12 10:47:45 +00:00
|
|
|
PageDirectory,
|
2008-02-12 20:32:23 +00:00
|
|
|
FALSE);
|
|
|
|
InitProcess->QuantumReset = MAXCHAR;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-02-09 02:11:18 +00:00
|
|
|
/* FIXME-V6: See if we want to support MP */
|
2008-02-12 22:50:54 +00:00
|
|
|
DPRINT1("ARM MPCore not supported\n");
|
2008-02-12 20:32:23 +00:00
|
|
|
}
|
2010-02-09 02:11:18 +00:00
|
|
|
|
|
|
|
/* Setup the Idle Thread */
|
2008-02-12 20:32:23 +00:00
|
|
|
KeInitializeThread(InitProcess,
|
|
|
|
InitThread,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
IdleStack);
|
|
|
|
InitThread->NextProcessor = Number;
|
|
|
|
InitThread->Priority = HIGH_PRIORITY;
|
|
|
|
InitThread->State = Running;
|
|
|
|
InitThread->Affinity = 1 << Number;
|
|
|
|
InitThread->WaitIrql = DISPATCH_LEVEL;
|
|
|
|
InitProcess->ActiveProcessors = 1 << Number;
|
2008-02-12 22:50:54 +00:00
|
|
|
|
2010-02-09 02:11:18 +00:00
|
|
|
/* HACK for MmUpdatePageDir */
|
2008-02-12 20:32:23 +00:00
|
|
|
((PETHREAD)InitThread)->ThreadsProcess = (PEPROCESS)InitProcess;
|
2008-02-12 22:50:54 +00:00
|
|
|
|
2010-02-09 02:11:18 +00:00
|
|
|
/* Set up the thread-related fields in the PRCB */
|
|
|
|
Prcb->CurrentThread = InitThread;
|
|
|
|
Prcb->NextThread = NULL;
|
|
|
|
Prcb->IdleThread = InitThread;
|
|
|
|
|
|
|
|
/* Initialize the Kernel Executive */
|
2008-02-12 20:32:23 +00:00
|
|
|
ExpInitializeExecutive(Number, LoaderBlock);
|
2010-02-09 02:11:18 +00:00
|
|
|
|
|
|
|
/* Only do this on the boot CPU */
|
2008-02-12 20:32:23 +00:00
|
|
|
if (!Number)
|
|
|
|
{
|
2010-02-09 02:11:18 +00:00
|
|
|
/* Calculate the time reciprocal */
|
2008-02-12 20:32:23 +00:00
|
|
|
KiTimeIncrementReciprocal =
|
2010-02-09 02:11:18 +00:00
|
|
|
KiComputeReciprocal(KeMaximumIncrement,
|
|
|
|
&KiTimeIncrementShiftCount);
|
|
|
|
|
|
|
|
/* Update DPC Values in case they got updated by the executive */
|
2008-02-12 20:32:23 +00:00
|
|
|
Prcb->MaximumDpcQueueDepth = KiMaximumDpcQueueDepth;
|
|
|
|
Prcb->MinimumDpcRate = KiMinimumDpcRate;
|
|
|
|
Prcb->AdjustDpcThreshold = KiAdjustDpcThreshold;
|
|
|
|
}
|
2010-02-09 02:11:18 +00:00
|
|
|
|
|
|
|
/* Raise to Dispatch */
|
2008-06-14 22:02:50 +00:00
|
|
|
KfRaiseIrql(DISPATCH_LEVEL);
|
2010-02-09 02:11:18 +00:00
|
|
|
|
|
|
|
/* Set the Idle Priority to 0. This will jump into Phase 1 */
|
2008-02-12 20:32:23 +00:00
|
|
|
KeSetPriorityThread(InitThread, 0);
|
2010-02-09 02:11:18 +00:00
|
|
|
|
|
|
|
/* If there's no thread scheduled, put this CPU in the Idle summary */
|
2008-02-12 20:32:23 +00:00
|
|
|
KiAcquirePrcbLock(Prcb);
|
|
|
|
if (!Prcb->NextThread) KiIdleSummary |= 1 << Number;
|
|
|
|
KiReleasePrcbLock(Prcb);
|
2010-02-09 02:11:18 +00:00
|
|
|
|
|
|
|
/* Raise back to HIGH_LEVEL and clear the PRCB for the loader block */
|
2008-06-14 22:02:50 +00:00
|
|
|
KfRaiseIrql(HIGH_LEVEL);
|
2010-02-09 02:11:18 +00:00
|
|
|
LoaderBlock->Prcb = 0;
|
2008-02-12 20:32:23 +00:00
|
|
|
}
|
|
|
|
|
2015-05-14 22:31:58 +00:00
|
|
|
//C_ASSERT((PKIPCR)KeGetPcr() == (PKIPCR)0xFFDFF000);
|
|
|
|
//C_ASSERT((FIELD_OFFSET(KIPCR, FirstLevelDcacheSize) & 4) == 0);
|
|
|
|
//C_ASSERT(sizeof(KIPCR) <= PAGE_SIZE);
|
2010-02-09 02:11:18 +00:00
|
|
|
|
2008-02-12 16:22:01 +00:00
|
|
|
VOID
|
2010-02-09 02:11:18 +00:00
|
|
|
NTAPI
|
|
|
|
KiInitializePcr(IN ULONG ProcessorNumber,
|
|
|
|
IN PKIPCR Pcr,
|
|
|
|
IN PKTHREAD IdleThread,
|
|
|
|
IN PVOID PanicStack,
|
|
|
|
IN PVOID InterruptStack)
|
2008-02-12 16:22:01 +00:00
|
|
|
{
|
2010-02-09 02:11:18 +00:00
|
|
|
ULONG i;
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2010-02-09 02:11:18 +00:00
|
|
|
/* Set the Current Thread */
|
2015-05-14 22:31:58 +00:00
|
|
|
Pcr->Prcb.CurrentThread = IdleThread;
|
2010-02-09 02:11:18 +00:00
|
|
|
|
|
|
|
/* Set pointers to ourselves */
|
|
|
|
Pcr->Self = (PKPCR)Pcr;
|
2015-05-14 22:31:58 +00:00
|
|
|
Pcr->CurrentPrcb = &Pcr->Prcb;
|
2010-02-09 02:11:18 +00:00
|
|
|
|
|
|
|
/* Set the PCR Version */
|
|
|
|
Pcr->MajorVersion = PCR_MAJOR_VERSION;
|
|
|
|
Pcr->MinorVersion = PCR_MINOR_VERSION;
|
|
|
|
|
|
|
|
/* Set the PCRB Version */
|
2015-05-14 22:31:58 +00:00
|
|
|
Pcr->Prcb.MajorVersion = 1;
|
|
|
|
Pcr->Prcb.MinorVersion = 1;
|
2010-02-09 02:11:18 +00:00
|
|
|
|
|
|
|
/* Set the Build Type */
|
2015-05-14 22:31:58 +00:00
|
|
|
Pcr->Prcb.BuildType = 0;
|
2010-02-09 02:11:18 +00:00
|
|
|
#ifndef CONFIG_SMP
|
2015-05-14 22:31:58 +00:00
|
|
|
Pcr->Prcb.BuildType |= PRCB_BUILD_UNIPROCESSOR;
|
2010-02-09 02:11:18 +00:00
|
|
|
#endif
|
|
|
|
#if DBG
|
2015-05-14 22:31:58 +00:00
|
|
|
Pcr->Prcb.BuildType |= PRCB_BUILD_DEBUG;
|
2010-02-09 02:11:18 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Set the Processor Number and current Processor Mask */
|
2015-05-14 22:31:58 +00:00
|
|
|
Pcr->Prcb.Number = (UCHAR)ProcessorNumber;
|
|
|
|
Pcr->Prcb.SetMember = 1 << ProcessorNumber;
|
2010-02-09 02:11:18 +00:00
|
|
|
|
|
|
|
/* Set the PRCB for this Processor */
|
2015-05-14 22:31:58 +00:00
|
|
|
KiProcessorBlock[ProcessorNumber] = Pcr->CurrentPrcb;
|
2010-02-09 02:11:18 +00:00
|
|
|
|
|
|
|
/* Start us out at PASSIVE_LEVEL */
|
2015-05-14 22:31:58 +00:00
|
|
|
Pcr->CurrentIrql = PASSIVE_LEVEL;
|
2010-02-09 02:11:18 +00:00
|
|
|
|
|
|
|
/* Set the stacks */
|
2015-05-14 22:31:58 +00:00
|
|
|
Pcr->Prcb.PanicStackBase = (ULONG)PanicStack;
|
|
|
|
Pcr->Prcb.IsrStack = InterruptStack;
|
|
|
|
#if 0
|
2010-02-09 02:11:18 +00:00
|
|
|
/* Setup the processor set */
|
2015-05-14 22:31:58 +00:00
|
|
|
Pcr->Prcb.MultiThreadProcessorSet = Pcr->Prcb.SetMember;
|
|
|
|
#endif
|
|
|
|
|
2010-02-09 02:11:18 +00:00
|
|
|
/* Copy cache information from the loader block */
|
2015-05-14 22:31:58 +00:00
|
|
|
Pcr->Prcb.Cache[FirstLevelDcache].Type = CacheData;
|
|
|
|
Pcr->Prcb.Cache[FirstLevelDcache].Level = 1;
|
|
|
|
Pcr->Prcb.Cache[FirstLevelDcache].Associativity = 0; // FIXME
|
|
|
|
Pcr->Prcb.Cache[FirstLevelDcache].LineSize = KeLoaderBlock->u.Arm.FirstLevelDcacheFillSize;
|
|
|
|
Pcr->Prcb.Cache[FirstLevelDcache].Size = KeLoaderBlock->u.Arm.FirstLevelDcacheSize;
|
|
|
|
|
|
|
|
Pcr->Prcb.Cache[SecondLevelDcache].Type = CacheData;
|
|
|
|
Pcr->Prcb.Cache[SecondLevelDcache].Level = 2;
|
|
|
|
Pcr->Prcb.Cache[SecondLevelDcache].Associativity = 0; // FIXME
|
|
|
|
Pcr->Prcb.Cache[SecondLevelDcache].LineSize = KeLoaderBlock->u.Arm.SecondLevelDcacheFillSize;
|
|
|
|
Pcr->Prcb.Cache[SecondLevelDcache].Size = KeLoaderBlock->u.Arm.SecondLevelDcacheSize;
|
|
|
|
|
|
|
|
Pcr->Prcb.Cache[FirstLevelIcache].Type = CacheInstruction;
|
|
|
|
Pcr->Prcb.Cache[FirstLevelIcache].Level = 1;
|
|
|
|
Pcr->Prcb.Cache[FirstLevelIcache].Associativity = 0; // FIXME
|
|
|
|
Pcr->Prcb.Cache[FirstLevelIcache].LineSize = KeLoaderBlock->u.Arm.FirstLevelIcacheFillSize;
|
|
|
|
Pcr->Prcb.Cache[FirstLevelIcache].Size = KeLoaderBlock->u.Arm.FirstLevelIcacheSize;
|
|
|
|
|
|
|
|
Pcr->Prcb.Cache[SecondLevelIcache].Type = CacheInstruction;
|
|
|
|
Pcr->Prcb.Cache[SecondLevelIcache].Level = 2;
|
|
|
|
Pcr->Prcb.Cache[SecondLevelIcache].Associativity = 0; // FIXME
|
|
|
|
Pcr->Prcb.Cache[SecondLevelIcache].LineSize = KeLoaderBlock->u.Arm.SecondLevelIcacheFillSize;
|
|
|
|
Pcr->Prcb.Cache[SecondLevelIcache].Size = KeLoaderBlock->u.Arm.SecondLevelIcacheSize;
|
2010-02-09 02:11:18 +00:00
|
|
|
|
|
|
|
/* Set global d-cache fill and alignment values */
|
2015-05-14 22:31:58 +00:00
|
|
|
if (Pcr->Prcb.Cache[SecondLevelDcache].Size == 0)
|
2008-02-12 19:01:48 +00:00
|
|
|
{
|
2010-02-09 02:11:18 +00:00
|
|
|
/* Use the first level */
|
2015-05-14 22:31:58 +00:00
|
|
|
Pcr->Prcb.Cache[GlobalDcache] = Pcr->Prcb.Cache[FirstLevelDcache];
|
2008-02-12 19:01:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-02-09 02:11:18 +00:00
|
|
|
/* Use the second level */
|
2015-05-14 22:31:58 +00:00
|
|
|
Pcr->Prcb.Cache[GlobalDcache] = Pcr->Prcb.Cache[SecondLevelDcache];
|
2008-02-12 19:01:48 +00:00
|
|
|
}
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2010-02-09 02:11:18 +00:00
|
|
|
/* Set the alignment */
|
2015-05-14 22:31:58 +00:00
|
|
|
//Pcr->DcacheAlignment = Pcr->DcacheFillSize - 1;
|
|
|
|
|
2010-02-09 02:11:18 +00:00
|
|
|
/* Set global i-cache fill and alignment values */
|
2015-05-14 22:31:58 +00:00
|
|
|
if (Pcr->Prcb.Cache[SecondLevelIcache].Size == 0)
|
2008-02-12 19:01:48 +00:00
|
|
|
{
|
2010-02-09 02:11:18 +00:00
|
|
|
/* Use the first level */
|
2015-05-14 22:31:58 +00:00
|
|
|
Pcr->Prcb.Cache[GlobalIcache] = Pcr->Prcb.Cache[FirstLevelIcache];
|
2008-02-12 19:01:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-02-09 02:11:18 +00:00
|
|
|
/* Use the second level */
|
2015-05-14 22:31:58 +00:00
|
|
|
Pcr->Prcb.Cache[GlobalIcache] = Pcr->Prcb.Cache[SecondLevelIcache];
|
2008-02-12 19:01:48 +00:00
|
|
|
}
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2010-02-09 02:11:18 +00:00
|
|
|
/* Set the alignment */
|
2015-05-14 22:31:58 +00:00
|
|
|
//Pcr->IcacheAlignment = Pcr->IcacheFillSize - 1;
|
|
|
|
|
2010-02-09 02:11:18 +00:00
|
|
|
/* Set processor information */
|
2015-05-14 22:31:58 +00:00
|
|
|
//Pcr->ProcessorId = KeArmIdCodeRegisterGet().AsUlong;
|
|
|
|
|
2010-02-09 02:11:18 +00:00
|
|
|
/* Set all interrupt routines to unexpected interrupts as well */
|
|
|
|
for (i = 0; i < MAXIMUM_VECTOR; i++)
|
|
|
|
{
|
|
|
|
/* Point to the same template */
|
2015-05-14 22:31:58 +00:00
|
|
|
Pcr->Idt[i] = (PVOID)&KxUnexpectedInterrupt.DispatchCode;
|
2010-02-09 02:11:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set default stall factor */
|
|
|
|
Pcr->StallScaleFactor = 50;
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2010-02-09 02:11:18 +00:00
|
|
|
/* Setup software interrupts */
|
2015-05-14 22:31:58 +00:00
|
|
|
Pcr->Idt[PASSIVE_LEVEL] = KiPassiveRelease;
|
|
|
|
Pcr->Idt[APC_LEVEL] = KiApcInterrupt;
|
|
|
|
Pcr->Idt[DISPATCH_LEVEL] = KiDispatchInterrupt;
|
|
|
|
#if 0
|
2010-02-09 02:11:18 +00:00
|
|
|
Pcr->ReservedVectors = (1 << PASSIVE_LEVEL) |
|
|
|
|
(1 << APC_LEVEL) |
|
|
|
|
(1 << DISPATCH_LEVEL) |
|
|
|
|
(1 << IPI_LEVEL);
|
2015-05-14 22:31:58 +00:00
|
|
|
#endif
|
2010-02-09 02:11:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
KiInitializeMachineType(VOID)
|
|
|
|
{
|
|
|
|
/* Detect ARM version */
|
|
|
|
KeIsArmV6 = KeArmIdCodeRegisterGet().Architecture >= 7;
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2010-02-09 02:11:18 +00:00
|
|
|
/* Set the number of TLB entries and ASIDs */
|
|
|
|
KeNumberTbEntries = 64;
|
|
|
|
if (__ARMV6__)
|
|
|
|
{
|
|
|
|
/* 256 ASIDs on v6/v7 */
|
|
|
|
KeNumberProcessIds = 256;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* The TLB is VIVT on v4/v5 */
|
|
|
|
KeNumberProcessIds = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
KiInitializeSystem(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
|
|
|
|
{
|
|
|
|
ULONG Cpu;
|
|
|
|
PKTHREAD InitialThread;
|
|
|
|
PKPROCESS InitialProcess;
|
|
|
|
ARM_CONTROL_REGISTER ControlRegister;
|
|
|
|
PKIPCR Pcr = (PKIPCR)KeGetPcr();
|
|
|
|
PKTHREAD Thread;
|
|
|
|
|
|
|
|
/* Flush the TLB */
|
|
|
|
KeFlushTb();
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2010-02-09 02:11:18 +00:00
|
|
|
/* Save the loader block and get the current CPU */
|
|
|
|
KeLoaderBlock = LoaderBlock;
|
|
|
|
Cpu = KeNumberProcessors;
|
|
|
|
|
|
|
|
/* Save the initial thread and process */
|
|
|
|
InitialThread = (PKTHREAD)LoaderBlock->Thread;
|
|
|
|
InitialProcess = (PKPROCESS)LoaderBlock->Process;
|
|
|
|
|
|
|
|
/* Clean the APC List Head */
|
|
|
|
InitializeListHead(&InitialThread->ApcState.ApcListHead[KernelMode]);
|
|
|
|
|
|
|
|
/* Initialize the machine type */
|
|
|
|
KiInitializeMachineType();
|
|
|
|
|
|
|
|
/* Skip initial setup if this isn't the Boot CPU */
|
|
|
|
if (Cpu) goto AppCpuInit;
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2010-02-09 02:11:18 +00:00
|
|
|
/* Initialize the PCR */
|
|
|
|
RtlZeroMemory(Pcr, PAGE_SIZE);
|
|
|
|
KiInitializePcr(Cpu,
|
|
|
|
Pcr,
|
|
|
|
InitialThread,
|
|
|
|
(PVOID)LoaderBlock->u.Arm.PanicStack,
|
|
|
|
(PVOID)LoaderBlock->u.Arm.InterruptStack);
|
|
|
|
|
|
|
|
/* Now sweep caches */
|
|
|
|
HalSweepIcache();
|
|
|
|
HalSweepDcache();
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2010-02-09 02:11:18 +00:00
|
|
|
/* Set us as the current process */
|
|
|
|
InitialThread->ApcState.Process = InitialProcess;
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2010-02-09 02:11:18 +00:00
|
|
|
AppCpuInit:
|
|
|
|
/* Setup CPU-related fields */
|
2015-05-14 22:31:58 +00:00
|
|
|
Pcr->Prcb.Number = Cpu;
|
|
|
|
Pcr->Prcb.SetMember = 1 << Cpu;
|
|
|
|
|
2010-02-09 02:11:18 +00:00
|
|
|
/* Initialize the Processor with HAL */
|
|
|
|
HalInitializeProcessor(Cpu, KeLoaderBlock);
|
|
|
|
|
|
|
|
/* Set active processors */
|
2015-05-14 22:31:58 +00:00
|
|
|
KeActiveProcessors |= Pcr->Prcb.SetMember;
|
2010-02-09 02:11:18 +00:00
|
|
|
KeNumberProcessors++;
|
|
|
|
|
|
|
|
/* Check if this is the boot CPU */
|
|
|
|
if (!Cpu)
|
|
|
|
{
|
|
|
|
/* Initialize debugging system */
|
|
|
|
KdInitSystem(0, KeLoaderBlock);
|
|
|
|
|
|
|
|
/* Check for break-in */
|
|
|
|
if (KdPollBreakIn()) DbgBreakPointWithStatus(DBG_STATUS_CONTROL_C);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Raise to HIGH_LEVEL */
|
|
|
|
KfRaiseIrql(HIGH_LEVEL);
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2010-02-09 02:11:18 +00:00
|
|
|
/* Set the exception address to high */
|
2008-03-11 02:45:13 +00:00
|
|
|
ControlRegister = KeArmControlRegisterGet();
|
|
|
|
ControlRegister.HighVectors = TRUE;
|
|
|
|
KeArmControlRegisterSet(ControlRegister);
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2010-02-09 02:11:18 +00:00
|
|
|
/* Setup the exception vector table */
|
2008-03-11 02:45:13 +00:00
|
|
|
RtlCopyMemory((PVOID)0xFFFF0000, &KiArmVectorTable, 14 * sizeof(PVOID));
|
|
|
|
|
2010-02-09 02:11:18 +00:00
|
|
|
/* Initialize the rest of the kernel now */
|
2008-02-12 20:32:23 +00:00
|
|
|
KiInitializeKernel((PKPROCESS)LoaderBlock->Process,
|
|
|
|
(PKTHREAD)LoaderBlock->Thread,
|
|
|
|
(PVOID)LoaderBlock->KernelStack,
|
2015-05-14 22:31:58 +00:00
|
|
|
&Pcr->Prcb,
|
|
|
|
Pcr->Prcb.Number,
|
2010-02-09 02:11:18 +00:00
|
|
|
KeLoaderBlock);
|
|
|
|
|
|
|
|
/* Set the priority of this thread to 0 */
|
|
|
|
Thread = KeGetCurrentThread();
|
|
|
|
Thread->Priority = 0;
|
|
|
|
|
|
|
|
/* Force interrupts enabled and lower IRQL back to DISPATCH_LEVEL */
|
|
|
|
_enable();
|
|
|
|
KfLowerIrql(DISPATCH_LEVEL);
|
|
|
|
|
|
|
|
/* Set the right wait IRQL */
|
|
|
|
Thread->WaitIrql = DISPATCH_LEVEL;
|
|
|
|
|
|
|
|
/* Jump into the idle loop */
|
|
|
|
KiIdleLoop();
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG
|
|
|
|
DbgPrintEarly(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
unsigned int i;
|
|
|
|
char Buffer[1024];
|
|
|
|
PCHAR String = Buffer;
|
|
|
|
|
|
|
|
va_start(args, fmt);
|
|
|
|
i = vsprintf(Buffer, fmt, args);
|
|
|
|
va_end(args);
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2010-02-09 02:11:18 +00:00
|
|
|
/* Output the message */
|
|
|
|
while (*String != 0)
|
|
|
|
{
|
|
|
|
if (*String == '\n')
|
|
|
|
{
|
|
|
|
KdPortPutByteEx(NULL, '\r');
|
|
|
|
}
|
|
|
|
KdPortPutByteEx(NULL, *String);
|
|
|
|
String++;
|
|
|
|
}
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2010-02-09 02:11:18 +00:00
|
|
|
return STATUS_SUCCESS;
|
2008-02-12 16:22:01 +00:00
|
|
|
}
|