void setupHeap() { Allocator *parent; PoolAllocator *pool; Address heapAddr; Size parentSize; // TODO: inefficient. needs another kernel call. Make forkexec() have zero kernel calls and/or IPC until main() for // maximum efficiency. // TODO: ProcessCtl(SELF, InfoPID, &info); // map = info.map.... Arch::MemoryMap map; PageAllocator alloc( map.range(MemoryMap::UserHeap).virt, map.range(MemoryMap::UserHeap).size ); // Pre-allocate 4 pages Size sz = PAGESIZE * 4; Address addr; alloc.allocate(&sz, &addr); // Allocate instance copy on vm pages itself heapAddr = alloc.base(); parent = new (heapAddr) PageAllocator(&alloc); parentSize = sizeof(PageAllocator); // Make a pool pool = new (heapAddr + parentSize) PoolAllocator(); pool->setParent(parent); // Set default allocator Allocator::setDefault(pool); }
Kernel::Kernel(CoreInfo *info) : Singleton<Kernel>(this), m_interrupts(256) { // Output log banners if (Log::instance) { Log::instance->append(BANNER); Log::instance->append(COPYRIGHT "\r\n"); } // TODO: compute lower & higher memory for this core. Memory::Range highMem; Arch::MemoryMap map; MemoryBlock::set(&highMem, 0, sizeof(highMem)); highMem.phys = info->memory.phys + map.range(MemoryMap::KernelData).size; // Initialize members m_alloc = new SplitAllocator(info->memory, highMem); m_procs = new ProcessManager(new Scheduler()); m_api = new API(); m_coreInfo = info; m_intControl = 0; // Mark kernel memory used (first 4MB in phys memory) for (Size i = 0; i < info->kernel.size; i += PAGESIZE) m_alloc->allocate(info->kernel.phys + i); // Mark BootImage memory used for (Size i = 0; i < m_coreInfo->bootImageSize; i += PAGESIZE) m_alloc->allocate(m_coreInfo->bootImageAddress + i); // Clear interrupts table m_interrupts.fill(ZERO); }