feat: add page table
This commit is contained in:
parent
61dfda6a70
commit
ada1859910
8 changed files with 435 additions and 13 deletions
36
kernel/include/memory/pagetable.h
Normal file
36
kernel/include/memory/pagetable.h
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
#pragma once
|
||||
|
||||
#include "memory/pointer.h"
|
||||
#include "util/optional.h"
|
||||
|
||||
struct PageTable {
|
||||
struct flags_t {
|
||||
enum class granularity_t : uint8_t {
|
||||
page_4KiB,
|
||||
page_2MiB,
|
||||
page_1GiB,
|
||||
};
|
||||
|
||||
bool writeable : 1; // allow writes
|
||||
bool user_accessible : 1; // allow ring-3 access
|
||||
bool write_through : 1; // write-through instead of write-back
|
||||
bool cache_disabled : 1; // uncached (MMIO)
|
||||
bool execute_disabled : 1; // forbid instruction fetch
|
||||
bool global : 1; // keep in TLB across CR3 switches
|
||||
granularity_t granularity : 2; // mapping size
|
||||
};
|
||||
struct info_t {
|
||||
flags_t flags;
|
||||
paddr_t address;
|
||||
};
|
||||
|
||||
static PageTable fromCurrent();
|
||||
|
||||
void activate();
|
||||
bool map(void* vaddress, paddr_t paddress, flags_t flags);
|
||||
void unmap(void* vaddress);
|
||||
optional<info_t> get(void* vaddress);
|
||||
|
||||
private:
|
||||
paddr_t l4;
|
||||
};
|
||||
|
|
@ -3,6 +3,7 @@
|
|||
#include "util/number.h"
|
||||
|
||||
constexpr uint64_t high_base = 0xFFFF800000000000;
|
||||
constexpr uint64_t uncached_base = high_base + (uint64_t{1} << 38);
|
||||
|
||||
#define read_symbol(symbol) \
|
||||
[]() { \
|
||||
|
|
@ -18,6 +19,11 @@ struct paddr_t {
|
|||
T* access() {
|
||||
return reinterpret_cast<T*>(address + high_base);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T* access_uc() {
|
||||
return reinterpret_cast<T*>(address + uncached_base);
|
||||
}
|
||||
};
|
||||
|
||||
inline void* operator new(size_t, void* p) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue