blob: 9de487be9dcef49a5e05ec3855fd58ac27b08a57 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
#include <stdlib.h>
#pragma once
extern "C" void dump_address();
struct page_table {
uint32_t* addr;
};
class vmm {
public:
vmm(uint32_t* addr = nullptr);
constexpr static size_t table_id(uint32_t offset) {
offset &= 0xfff00000;
offset /= (4 * 1024 * 1024);
return static_cast<size_t>(offset);
}
constexpr static size_t page_id(uint32_t offset) { return static_cast<size_t>(offset / 4096); }
uint32_t map(uint32_t phys_addr, uint32_t offset);
private:
uint32_t* directory;
};
static_assert(vmm::table_id(0x00001234) == 0);
static_assert(vmm::table_id(0x00400000) == 1);
static_assert(vmm::table_id(0xc0000000) == 768);
static_assert(vmm::table_id(0xc03ff000) == 768);
|