| 100 | } |
| 101 | |
| 102 | auto MemoryInit() -> void { |
| 103 | auto allocator_addr = |
| 104 | reinterpret_cast<void*>(cpu_io::virtual_memory::PageAlignUp( |
| 105 | BasicInfoSingleton::instance().elf_addr + |
| 106 | KernelElfSingleton::instance().GetElfSize())); |
| 107 | auto allocator_size = BasicInfoSingleton::instance().physical_memory_addr + |
| 108 | BasicInfoSingleton::instance().physical_memory_size - |
| 109 | reinterpret_cast<uint64_t>(allocator_addr); |
| 110 | |
| 111 | klog::Info("bmalloc address: {:#x}, size: {:#X}", |
| 112 | static_cast<uint64_t>(reinterpret_cast<uintptr_t>(allocator_addr)), |
| 113 | static_cast<uint64_t>(allocator_size)); |
| 114 | |
| 115 | static bmalloc::Bmalloc<BmallocLogger, BmallocLock> bmallocator( |
| 116 | allocator_addr, allocator_size); |
| 117 | allocator = &bmallocator; |
| 118 | |
| 119 | // 初始化当前核心的虚拟内存 |
| 120 | VirtualMemorySingleton::create(); |
| 121 | VirtualMemorySingleton::instance().InitCurrentCore(); |
| 122 | |
| 123 | // 重新映射早期控制台地址(如果有的话) |
| 124 | if (SIMPLEKERNEL_EARLY_CONSOLE_BASE != 0) { |
| 125 | VirtualMemorySingleton::instance() |
| 126 | .MapMMIO(SIMPLEKERNEL_EARLY_CONSOLE_BASE, |
| 127 | cpu_io::virtual_memory::kPageSize) |
| 128 | .or_else([](Error err) -> Expected<void*> { |
| 129 | klog::Warn("Failed to remap early console MMIO: {}", err.message()); |
| 130 | return std::unexpected(err); |
| 131 | }); |
| 132 | } |
| 133 | |
| 134 | klog::Info("Memory initialization completed"); |
| 135 | } |
| 136 | |
| 137 | auto MemoryInitSMP() -> void { |
| 138 | VirtualMemorySingleton::instance().InitCurrentCore(); |
no test coverage detected