Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenkiinit.c
Go to the documentation of this file.
00001 /* 00002 * PROJECT: ReactOS Kernel 00003 * LICENSE: GPL - See COPYING in the top level directory 00004 * FILE: ntoskrnl/ke/powerpc/kiinit.c 00005 * PURPOSE: Kernel Initialization for x86 CPUs 00006 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org) 00007 * Art Yerkes (ayerkes@speakeasy.net) 00008 */ 00009 00010 /* INCLUDES *****************************************************************/ 00011 00012 #include <ntoskrnl.h> 00013 00014 //#define NDEBUG 00015 #include <debug.h> 00016 #include "ppcmmu/mmu.h" 00017 00018 /* GLOBALS *******************************************************************/ 00019 00020 /* Ku bit should be set, so that we get the best options for page protection */ 00021 #define PPC_SEG_Ku 0x40000000 00022 #define PPC_SEG_Ks 0x20000000 00023 00024 extern LOADER_MODULE KeLoaderModules[64]; 00025 extern ULONG KeLoaderModuleCount; 00026 extern ULONG_PTR MmFreeLdrLastKernelAddress; 00027 KPRCB PrcbData[MAXIMUM_PROCESSORS]; 00028 /* BIOS Memory Map. Not NTLDR-compliant yet */ 00029 extern ULONG KeMemoryMapRangeCount; 00030 extern ADDRESS_RANGE KeMemoryMap[64]; 00031 00032 /* FUNCTIONS *****************************************************************/ 00033 /* 00034 * Trap frame: 00035 * r0 .. r32 00036 * lr, ctr, srr0, srr1, dsisr 00037 */ 00038 00039 extern int syscall_start[], syscall_end, KiDecrementerTrapHandler[], 00040 KiDecrementerTrapHandlerEnd; 00041 00042 VOID 00043 NTAPI 00044 KiSetupSyscallHandler() 00045 { 00046 paddr_t handler_target; 00047 int *source; 00048 for(source = syscall_start, handler_target = 0xc00; 00049 source < &syscall_end; 00050 source++, handler_target += sizeof(int)) 00051 SetPhys(handler_target, *source); 00052 } 00053 00054 VOID 00055 NTAPI 00056 KiSetupDecrementerTrap() 00057 { 00058 paddr_t handler_target; 00059 int *source; 00060 00061 /* Turn off EE bit while redefining dec trap */ 00062 _disable(); 00063 00064 for(source = KiDecrementerTrapHandler, handler_target = 0x900; 00065 source != &KiDecrementerTrapHandlerEnd; 00066 source++, handler_target += sizeof(int)) 00067 SetPhys(handler_target, *source); 00068 00069 DPRINT("CurrentThread %08x IdleThread %08x\n", 00070 KeGetCurrentThread(), KeGetCurrentPrcb()->IdleThread); 00071 00072 /* Kick decmrenter! */ 00073 __asm__("mtdec %0" : : "r" (0)); 00074 00075 /* Enable interrupts! */ 00076 _enable(); 00077 } 00078 00079 VOID 00080 NTAPI 00081 KiInitializePcr(IN ULONG ProcessorNumber, 00082 IN PKIPCR Pcr, 00083 IN PKTHREAD IdleThread, 00084 IN PVOID DpcStack) 00085 { 00086 Pcr->MajorVersion = PCR_MAJOR_VERSION; 00087 Pcr->MinorVersion = PCR_MINOR_VERSION; 00088 Pcr->CurrentIrql = PASSIVE_LEVEL; 00089 Pcr->PrcbData = &PrcbData[ProcessorNumber]; 00090 Pcr->PrcbData->MajorVersion = PRCB_MAJOR_VERSION; 00091 Pcr->PrcbData->MinorVersion = 0; 00092 Pcr->PrcbData->Number = 0; /* UP for now */ 00093 Pcr->PrcbData->SetMember = 1; 00094 #if DBG 00095 Pcr->PrcbData->BuildType = PRCB_BUILD_DEBUG; 00096 #else 00097 Pcr->PrcbData->BuildType = 0; 00098 #endif 00099 Pcr->PrcbData->DpcStack = DpcStack; 00100 KeGetPcr()->Prcb = Pcr->PrcbData; 00101 KiProcessorBlock[ProcessorNumber] = Pcr->PrcbData; 00102 } 00103 00104 extern ULONG KiGetFeatureBits(); 00105 extern VOID KiSetProcessorType(); 00106 extern VOID KiGetCacheInformation(); 00107 00108 VOID 00109 NTAPI 00110 KiInitializeKernel(IN PKPROCESS InitProcess, 00111 IN PKTHREAD InitThread, 00112 IN PVOID IdleStack, 00113 IN PKPRCB Prcb, 00114 IN CCHAR Number, 00115 IN PLOADER_PARAMETER_BLOCK LoaderBlock) 00116 { 00117 ULONG FeatureBits; 00118 LARGE_INTEGER PageDirectory; 00119 PVOID DpcStack; 00120 00121 /* Detect and set the CPU Type */ 00122 KiSetProcessorType(); 00123 00124 /* Initialize the Power Management Support for this PRCB */ 00125 PoInitializePrcb(Prcb); 00126 00127 /* Get the processor features for the CPU */ 00128 FeatureBits = KiGetFeatureBits(); 00129 00130 /* Save feature bits */ 00131 Prcb->FeatureBits = FeatureBits; 00132 00133 /* Get cache line information for this CPU */ 00134 KiGetCacheInformation(); 00135 00136 /* Initialize spinlocks and DPC data */ 00137 KiInitSpinLocks(Prcb, Number); 00138 00139 /* Check if this is the Boot CPU */ 00140 if (!Number) 00141 { 00142 /* Set Node Data */ 00143 KeNodeBlock[0] = &KiNode0; 00144 Prcb->ParentNode = KeNodeBlock[0]; 00145 KeNodeBlock[0]->ProcessorMask = Prcb->SetMember; 00146 00147 /* Set boot-level flags */ 00148 KeProcessorArchitecture = 0; 00149 KeProcessorLevel = (USHORT)Prcb->CpuType; 00150 KeFeatureBits = FeatureBits; 00151 00152 /* Set the current MP Master KPRCB to the Boot PRCB */ 00153 Prcb->MultiThreadSetMaster = Prcb; 00154 00155 /* Lower to APC_LEVEL */ 00156 KeLowerIrql(APC_LEVEL); 00157 00158 /* Initialize portable parts of the OS */ 00159 KiInitSystem(); 00160 00161 /* Initialize the Idle Process and the Process Listhead */ 00162 InitializeListHead(&KiProcessListHead); 00163 PageDirectory.QuadPart = 0; 00164 KeInitializeProcess(InitProcess, 00165 0, 00166 0xFFFFFFFF, 00167 &PageDirectory, 00168 TRUE); 00169 InitProcess->QuantumReset = MAXCHAR; 00170 } 00171 else 00172 { 00173 /* FIXME */ 00174 DPRINT1("SMP Boot support not yet present\n"); 00175 } 00176 00177 /* Setup the Idle Thread */ 00178 KeInitializeThread(InitProcess, 00179 InitThread, 00180 NULL, 00181 NULL, 00182 NULL, 00183 NULL, 00184 NULL, 00185 IdleStack); 00186 InitThread->NextProcessor = Number; 00187 InitThread->Priority = HIGH_PRIORITY; 00188 InitThread->State = Running; 00189 InitThread->Affinity = 1 << Number; 00190 InitThread->WaitIrql = DISPATCH_LEVEL; 00191 InitProcess->ActiveProcessors = 1 << Number; 00192 00193 /* HACK for MmUpdatePageDir */ 00194 ((PETHREAD)InitThread)->ThreadsProcess = (PEPROCESS)InitProcess; 00195 00196 /* Set up the thread-related fields in the PRCB */ 00197 Prcb->CurrentThread = InitThread; 00198 Prcb->NextThread = NULL; 00199 Prcb->IdleThread = InitThread; 00200 00201 /* Initialize Kernel Memory Address Space */ 00202 MmInit1(MmFreeLdrFirstKrnlPhysAddr, 00203 MmFreeLdrLastKrnlPhysAddr, 00204 MmFreeLdrLastKernelAddress, 00205 KeMemoryMap, 00206 KeMemoryMapRangeCount, 00207 4096); 00208 00209 /* Initialize the Kernel Executive */ 00210 ExpInitializeExecutive(0, LoaderBlock); 00211 00212 /* Only do this on the boot CPU */ 00213 if (!Number) 00214 { 00215 /* Calculate the time reciprocal */ 00216 KiTimeIncrementReciprocal = 00217 KiComputeReciprocal(KeMaximumIncrement, 00218 &KiTimeIncrementShiftCount); 00219 00220 /* Update DPC Values in case they got updated by the executive */ 00221 Prcb->MaximumDpcQueueDepth = KiMaximumDpcQueueDepth; 00222 Prcb->MinimumDpcRate = KiMinimumDpcRate; 00223 Prcb->AdjustDpcThreshold = KiAdjustDpcThreshold; 00224 00225 /* Allocate the DPC Stack */ 00226 DpcStack = MmCreateKernelStack(FALSE, 0); 00227 if (!DpcStack) KeBugCheckEx(NO_PAGES_AVAILABLE, 1, 0, 0, 0); 00228 Prcb->DpcStack = DpcStack; 00229 } 00230 00231 /* Free Initial Memory */ 00232 // MiFreeInitMemory(); 00233 00234 KfRaiseIrql(DISPATCH_LEVEL); 00235 00236 KeSetPriorityThread(InitThread, 0); 00237 /* Setup decrementer exception */ 00238 KiSetupDecrementerTrap(); 00239 00240 KfLowerIrql(PASSIVE_LEVEL); 00241 00242 /* Should not return */ 00243 while(1) 00244 { 00245 NtYieldExecution(); 00246 } 00247 } 00248 00249 extern int KiPageFaultTrap(); 00250 KTRAP_FRAME KiInitialTrapFrame; 00251 00252 /* Use this for early boot additions to the page table */ 00253 VOID 00254 NTAPI 00255 KiSystemStartupReal(IN PLOADER_PARAMETER_BLOCK LoaderBlock) 00256 { 00257 ULONG Cpu; 00258 ppc_map_info_t info[4]; 00259 PKIPCR Pcr = (PKIPCR)KPCR_BASE; 00260 PKPRCB Prcb; 00261 00262 __asm__("mr 13,%0" : : "r" (KPCR_BASE)); 00263 00264 /* Set the page fault handler to the kernel */ 00265 MmuSetTrapHandler(3,KiPageFaultTrap); 00266 MmuSetTrapHandler(4,KiPageFaultTrap); 00267 00268 // Make 0xf... special 00269 MmuAllocVsid(2, 0x8000); 00270 MmuSetVsid(15,16,2); 00271 00272 /* Get the current CPU */ 00273 Cpu = KeNumberProcessors; 00274 if (!Cpu) 00275 { 00276 /* We'll allocate a page from the end of the kernel area for KPCR. This code will probably 00277 * change when we get SMP support. 00278 */ 00279 info[0].phys = 0; 00280 info[0].proc = 2; 00281 info[0].addr = (vaddr_t)Pcr; 00282 info[0].flags = MMU_KRW_UR; 00283 info[1].phys = 0; 00284 info[1].proc = 2; 00285 info[1].addr = ((vaddr_t)Pcr) + (1 << PAGE_SHIFT); 00286 info[1].flags = MMU_KRW_UR; 00287 info[2].phys = 0; 00288 info[2].proc = 2; 00289 info[2].addr = (vaddr_t)KI_USER_SHARED_DATA; 00290 info[2].flags = MMU_KRW_UR; 00291 info[3].phys = 0; 00292 info[3].proc = 2; 00293 info[3].addr = (vaddr_t)KIP0PCRADDRESS; 00294 info[3].flags = MMU_KRW_UR; 00295 MmuMapPage(info, 4); 00296 } 00297 00298 /* Skip initial setup if this isn't the Boot CPU */ 00299 if (Cpu) goto AppCpuInit; 00300 00301 /* Initialize the PCR */ 00302 RtlZeroMemory(Pcr, PAGE_SIZE); 00303 KiInitializePcr(Cpu, 00304 Pcr, 00305 &KiInitialThread.Tcb, 00306 KiDoubleFaultStack); 00307 00308 /* Set us as the current process */ 00309 KiInitialThread.Tcb.ApcState.Process = &KiInitialProcess.Pcb; 00310 KiInitialThread.Tcb.TrapFrame = &KiInitialTrapFrame; 00311 00312 /* Setup CPU-related fields */ 00313 AppCpuInit: 00314 Pcr->Number = Cpu; 00315 Pcr->SetMember = 1 << Cpu; 00316 Prcb = KeGetCurrentPrcb(); 00317 Prcb->SetMember = 1 << Cpu; 00318 00319 /* Initialize the Processor with HAL */ 00320 HalInitializeProcessor(Cpu, LoaderBlock); 00321 00322 /* Set active processors */ 00323 KeActiveProcessors |= Pcr->SetMember; 00324 KeNumberProcessors++; 00325 00326 /* Initialize the Debugger for the Boot CPU */ 00327 if (!Cpu) KdInitSystem (0, LoaderBlock); 00328 00329 /* Check for break-in */ 00330 if (KdPollBreakIn()) 00331 { 00332 DbgBreakPointWithStatus(DBG_STATUS_CONTROL_C); 00333 } 00334 00335 /* Raise to HIGH_LEVEL */ 00336 KfRaiseIrql(HIGH_LEVEL); 00337 00338 /* Call main kernel intialization */ 00339 KiInitializeKernel(&KiInitialProcess.Pcb, 00340 &KiInitialThread.Tcb, 00341 P0BootStack, 00342 Prcb, 00343 Cpu, 00344 (PVOID)LoaderBlock); 00345 } 00346 00347 VOID 00348 NTAPI 00349 KiInitMachineDependent(VOID) 00350 { 00351 } 00352 00353 void abort() 00354 { 00355 KeBugCheck(KMODE_EXCEPTION_NOT_HANDLED); 00356 while(1); 00357 } Generated on Sun May 27 2012 04:37:30 for ReactOS by
1.7.6.1
|