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

Method VirtualMemory

src/memory/virtual_memory.cpp:21–47  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19#include "sk_stdlib.h"
20
21VirtualMemory::VirtualMemory() {
22 // 分配根页表目录
23 kernel_page_dir_ = aligned_alloc(cpu_io::virtual_memory::kPageSize,
24 cpu_io::virtual_memory::kPageSize);
25 assert(kernel_page_dir_ != nullptr &&
26 "Failed to allocate kernel page directory");
27
28 // 清零页表目录
29 std::memset(kernel_page_dir_, 0, cpu_io::virtual_memory::kPageSize);
30
31 // 获取内核基本信息
32 const auto& basic_info = BasicInfoSingleton::instance();
33
34 // 映射全部物理内存
35 MapMMIO(basic_info.physical_memory_addr, basic_info.physical_memory_size)
36 .or_else([](auto&& err) -> Expected<void*> {
37 klog::Err("Failed to map kernel memory: {}", err.message());
38 while (true) {
39 cpu_io::Pause();
40 }
41 return {};
42 });
43
44 klog::Info("Kernel memory mapped from {:#X} to {:#X}",
45 basic_info.physical_memory_addr,
46 basic_info.physical_memory_addr + basic_info.physical_memory_size);
47}
48
49auto VirtualMemory::InitCurrentCore() const -> void {
50 cpu_io::virtual_memory::SetPageDirectory(

Callers

nothing calls this directly

Calls 6

memsetFunction · 0.85
ErrFunction · 0.85
PauseFunction · 0.85
InfoFunction · 0.85
messageMethod · 0.80
aligned_allocFunction · 0.70

Tested by

no test coverage detected