MCPcopy Create free account
hub / github.com/Simple-XX/SimpleKernel / MemoryInit

Function MemoryInit

src/memory/memory.cpp:102–135  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

100}
101
102auto 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
137auto MemoryInitSMP() -> void {
138 VirtualMemorySingleton::instance().InitCurrentCore();

Callers 2

mainFunction · 0.85
mainFunction · 0.85

Calls 7

PageAlignUpFunction · 0.85
InfoFunction · 0.85
WarnFunction · 0.85
GetElfSizeMethod · 0.80
MapMMIOMethod · 0.80
messageMethod · 0.80
InitCurrentCoreMethod · 0.45

Tested by

no test coverage detected