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

Method MapMMIO

src/memory/virtual_memory.cpp:56–72  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

54}
55
56auto VirtualMemory::MapMMIO(uint64_t phys_addr, size_t size, uint32_t flags)
57 -> Expected<void*> {
58 // 计算对齐后的起始和结束页
59 auto start_page = cpu_io::virtual_memory::PageAlign(phys_addr);
60 auto end_page = cpu_io::virtual_memory::PageAlignUp(phys_addr + size);
61
62 // 遍历并映射
63 for (uint64_t addr = start_page; addr < end_page;
64 addr += cpu_io::virtual_memory::kPageSize) {
65 auto result = MapPage(kernel_page_dir_, reinterpret_cast<void*>(addr),
66 reinterpret_cast<void*>(addr), flags);
67 if (!result.has_value()) {
68 return std::unexpected(result.error());
69 }
70 }
71 return reinterpret_cast<void*>(phys_addr);
72}
73
74auto VirtualMemory::MapPage(void* page_dir, void* virtual_addr,
75 void* physical_addr, uint32_t flags)

Callers 5

InterruptInitFunction · 0.80
InterruptMethod · 0.80
MemoryInitFunction · 0.80
PrepareFunction · 0.80
QemuExitFunction · 0.80

Calls 2

PageAlignFunction · 0.85
PageAlignUpFunction · 0.85

Tested by 1

QemuExitFunction · 0.64