Void Planet::CreateMoon( MoonID iMoonID ) { Assert( iMoonID < m_iMoonCount ); if ( m_arrMoons[iMoonID] != NULL ) return; BlockWorldFn->SelectMemory( TEXT("Scratch") ); m_arrMoons[iMoonID] = New RegionMap(); BlockWorldFn->UnSelectMemory(); m_arrMoons[iMoonID]->UseMemoryContext( BlockWorldFn->GetMemoryContext(), TEXT("Scratch") ); m_arrMoons[iMoonID]->SetComparator( _Compare_RegionCoords ); m_arrMoons[iMoonID]->Create(); }
/* * The Main function for the KL sub-module. * uint32_t *BITPointer -> the pointer to the BIT. */ void Main(BIT_t *BITPointer) { // Save BITPointer into a global variable. BIT = BITPointer; FileAPIFunc = (FileAPIFunc_t)BIT->FileAPI; VideoAPIFunc = (VideoAPIFunc_t)BIT->Video.VideoAPI; AllocFrameFunc = (AllocFrameFunc_t)BIT->DBALPMM.AllocFrame; FreeFrameFunc = (FreeFrameFunc_t)BIT->DBALPMM.FreeFrame; AllocContigFramesFunc = (AllocContigFramesFunc_t)BIT->DBALPMM.AllocContigFrames; FreeContigFramesFunc = (FreeContigFramesFunc_t)BIT->DBALPMM.FreeContigFrames; AbortBootFunc = (AbortBootFunc_t)BIT->Video.AbortBoot; uint32_t FeatureFlags = CPUFeatureFlags(); FILE_t Kernel, KernelMPMM, KernelMVMM; // Long mode is present - load the related files. if(FeatureFlags & LONG_MODE_PRESENT) { // Load the AMD64 kernel. FileAPIFunc(FILE_KERNEL, ARCH_AMD64, &Kernel); // Load the PMM and VMM AMD64 kernel module. FileAPIFunc(FILE_KERNEL_M, PMMAMD64, &KernelMPMM); FileAPIFunc(FILE_KERNEL_M, VMMAMD64, &KernelMVMM); AMD64PagingInit(); // Point the paging map function to AMD64 one. GenericPagingMap = &AMD64PagingMap; // Set the architecture. BIT->Arch = ARCH_AMD64; } // Else, load the x86 files. else { // Load the x86 kernel. FileAPIFunc(FILE_KERNEL, ARCH_X86, &Kernel); // If PAE is present, then load those modules. // ALSO, NOTE: Memory *should* be present over 4GiB to take advantage of PAE, so we // ensure there is. Else, we use x86. if((FeatureFlags & PAE_PRESENT) && (BIT->HighestAddress > 0xFFFFFFFFLLU)) { FileAPIFunc(FILE_KERNEL_M, PMMX86PAE, &KernelMPMM); FileAPIFunc(FILE_KERNEL_M, VMMX86PAE, &KernelMVMM); PAEPagingInit(); // Point the paging map function to PAE one. GenericPagingMap = &PAEPagingMap; // Set the architecture. BIT->Arch = ARCH_PAE; } // Else, load the x86 modules. else { FileAPIFunc(FILE_KERNEL_M, PMMX86, &KernelMPMM); FileAPIFunc(FILE_KERNEL_M, VMMX86, &KernelMVMM); x86PagingInit(); // Point the paging map function to x86 one. GenericPagingMap = &x86PagingMap; // Set the architecture. BIT->Arch = ARCH_X86; } } // Initialize the API. APIInit(); // Map the kernel (& modules). ModuleMap(Kernel); ModuleMap(KernelMPMM); ModuleMap(KernelMVMM); uint32_t BITFrame = AllocFrameFunc(POOL_BITMAP); if(!BITFrame) { // Switch to text mode. VideoAPIFunc(VIDEO_VGA_SWITCH_MODE, MODE_80_25_TEXT); AbortBootFunc("ERROR: Unable to allocate pages for the BIT."); } // Copy the BIT to the frame. memcpy((void*)BITFrame, BIT, sizeof(BIT_t)); switch(BIT->Arch) { case ARCH_X86: // Map the BIT frame. GenericPagingMap(X86_BIT, BITFrame); // Map the stack for x86. RegionMap(X86_STACK - STACK_SIZE, X86_STACK); // Enable paging completely. x86PagingEnable(); break; case ARCH_PAE: // Map the BIT frame. GenericPagingMap(PAE_BIT, BITFrame); // Map the stack for PAE. RegionMap(PAE_STACK - STACK_SIZE, PAE_STACK); // Enable paging completely. PAEPagingEnable(); break; case ARCH_AMD64: // Map the BIT frame. GenericPagingMap(AMD64_BIT, BITFrame); // Map the stack for AMD64. RegionMap(AMD64_STACK - STACK_SIZE, AMD64_STACK); // Enable paging completely. AMD64PagingEnable(); break; } // We shouldn't reach here. for(;;) { __asm__ __volatile__("hlt"); } }