diff options
author | Benji Dial <benji@benjidial.net> | 2024-01-15 15:44:20 -0500 |
---|---|---|
committer | Benji Dial <benji@benjidial.net> | 2024-01-15 15:44:20 -0500 |
commit | c9a1266d219a83882735a3a8304f3824e0219cdb (patch) | |
tree | fea71a0b5b0de8f3a8962dc6ed417273f231e2a9 /kernel/paging.cpp | |
parent | 7c6a18d77a81f232ad2e1d3a311bb21ea8f1f5b4 (diff) | |
download | hilbert-os-c9a1266d219a83882735a3a8304f3824e0219cdb.tar.gz |
redo application paging and system calls, rename mercury to hilbert
Diffstat (limited to 'kernel/paging.cpp')
-rw-r--r-- | kernel/paging.cpp | 37 |
1 files changed, 10 insertions, 27 deletions
diff --git a/kernel/paging.cpp b/kernel/paging.cpp index 17b61f4..d8869fc 100644 --- a/kernel/paging.cpp +++ b/kernel/paging.cpp @@ -1,5 +1,5 @@ -#include <mercury/kernel/utility.hpp> -#include <mercury/kernel/paging.hpp> +#include <hilbert/kernel/utility.hpp> +#include <hilbert/kernel/paging.hpp> //see also ../documentation/memory.txt @@ -7,7 +7,7 @@ extern "C" { uint64_t __kernel_p4_paddr; } -namespace mercury::kernel::paging { +namespace hilbert::kernel::paging { static constexpr uint64_t kernel_vram_start = 0xffffffffc0000000; static constexpr uint64_t kernel_vram_end = 0xffffffffffe00000; @@ -38,11 +38,9 @@ namespace mercury::kernel::paging { uint64_t kernel_p4e; - uint64_t encode_pte( - uint64_t addr, bool user, bool write, bool execute, bool ps - ) { + uint64_t encode_pte(uint64_t addr, bool user, bool write, bool execute) { return (addr & 0x0000ffffffffffff) | (execute ? 0 : (1ULL << 63)) - | (ps << 7) | (user << 2) | (write << 1) | 1; + | (user << 2) | (write << 1) | 1; } void init_kernel_page_tables(uint64_t kernel_offset) { @@ -50,15 +48,15 @@ namespace mercury::kernel::paging { for (int i = 0; i < 511; ++i) kernel_p4[i] = 0; kernel_p4e = encode_pte( - (uint64_t)kernel_p3 - kernel_offset, false, true, true, false); + (uint64_t)kernel_p3 - kernel_offset, false, true, true); kernel_p4[511] = kernel_p4e; for (int i = 0; i < 511; ++i) kernel_p3[i] = 0; kernel_p3[511] = encode_pte( - (uint64_t)kernel_p2 - kernel_offset, false, true, true, false); + (uint64_t)kernel_p2 - kernel_offset, false, true, true); for (int i = 0; i < 512; ++i) kernel_p2[i] = encode_pte( - (uint64_t)kernel_p1s + 4096 * i - kernel_offset, false, true, true, false); + (uint64_t)kernel_p1s + 4096 * i - kernel_offset, false, true, true); for (int i = 0; i < 512 * 512; ++i) kernel_p1s[i] = 0; } @@ -66,7 +64,7 @@ namespace mercury::kernel::paging { void map_kernel_page( uint64_t paddr, uint64_t vaddr, bool write, bool execute) { uint64_t i = (vaddr - kernel_vram_start) / 4096; - kernel_p1s[i] = encode_pte(paddr, false, write, execute, false); + kernel_p1s[i] = encode_pte(paddr, false, write, execute); } void unmap_kernel_page(uint64_t vaddr) { @@ -77,7 +75,7 @@ namespace mercury::kernel::paging { ); } - static uint64_t take_pram_page() { + uint64_t take_pram_page() { for (uint64_t i = 0; i < pram_pages / 64; ++i) if (~pram_usage_bitmap[i] != 0) for (int j = 0; j < 64; ++j) @@ -89,21 +87,6 @@ namespace mercury::kernel::paging { return 0; } - uint64_t take_2mib_pram_page() { - for (uint64_t i = 0; i < pram_pages / 512; ++i) { - for (int j = 0; j < 8; ++j) - if (pram_usage_bitmap[i * 8 + j] != 0) - goto next_i; - for (int j = 0; j < 8; ++j) - pram_usage_bitmap[i * 8 + j] = ~0ULL; - return 0x200000 * i; - next_i: - ; - } - //TODO: handle error - return 0; - } - void map_kernel_stacks() { for (uint64_t vaddr = syscall_stack_bottom; vaddr < syscall_stack_top; vaddr += 4096) |