Replace page_size (function) with ARCH_PAGE_SIZE (constant)
This commit is contained in:
parent
30ac95bcf8
commit
2c9329928c
@ -43,10 +43,10 @@ namespace MemoryManager
|
||||
{
|
||||
Result<void> protect_kernel_sections()
|
||||
{
|
||||
u64 rodata_pages = get_blocks_from_size((u64)(end_of_kernel_rodata - start_of_kernel_rodata), MMU::page_size());
|
||||
u64 rodata_pages = get_blocks_from_size((u64)(end_of_kernel_rodata - start_of_kernel_rodata), ARCH_PAGE_SIZE);
|
||||
TRY(remap((u64)start_of_kernel_rodata, rodata_pages, MMU::NoExecute));
|
||||
|
||||
u64 data_pages = get_blocks_from_size((u64)(end_of_kernel_data - start_of_kernel_data), MMU::page_size());
|
||||
u64 data_pages = get_blocks_from_size((u64)(end_of_kernel_data - start_of_kernel_data), ARCH_PAGE_SIZE);
|
||||
TRY(remap((u64)start_of_kernel_data, data_pages, MMU::NoExecute | MMU::ReadWrite));
|
||||
|
||||
return {};
|
||||
@ -81,25 +81,25 @@ namespace MemoryManager
|
||||
|
||||
page_bitmap_addr = (char*)biggest_memory_block;
|
||||
page_virtual_bitmap_addr = page_bitmap_addr; // we'll map this to virtual memory as soon as the MMU is ready
|
||||
if ((total_mem / MMU::page_size() / 8) >= biggest_memory_block_size)
|
||||
if ((total_mem / ARCH_PAGE_SIZE / 8) >= biggest_memory_block_size)
|
||||
{
|
||||
Serial::println("ERROR: No single memory block is enough to hold the page bitmap");
|
||||
for (;;)
|
||||
;
|
||||
}
|
||||
|
||||
page_bitmap_size = total_mem / MMU::page_size() / 8 + 1;
|
||||
page_bitmap_size = total_mem / ARCH_PAGE_SIZE / 8 + 1;
|
||||
memset(page_bitmap_addr, 0xFF, page_bitmap_size);
|
||||
|
||||
ptr = &bootboot.mmap;
|
||||
for (uint64_t i = 0; i < mmap_entries; i++)
|
||||
{
|
||||
uint64_t index = MMapEnt_Ptr(ptr) / MMU::page_size();
|
||||
uint64_t index = MMapEnt_Ptr(ptr) / ARCH_PAGE_SIZE;
|
||||
if (!MMapEnt_IsFree(ptr)) { reserved_mem += MMapEnt_Size(ptr); }
|
||||
else
|
||||
{
|
||||
free_mem += MMapEnt_Size(ptr);
|
||||
for (uint64_t j = 0; j < (MMapEnt_Size(ptr) / MMU::page_size()); j++)
|
||||
for (uint64_t j = 0; j < (MMapEnt_Size(ptr) / ARCH_PAGE_SIZE); j++)
|
||||
{
|
||||
page_bitmap_set(index + j, false);
|
||||
}
|
||||
@ -107,7 +107,7 @@ namespace MemoryManager
|
||||
ptr++;
|
||||
}
|
||||
|
||||
lock_pages((u64)page_bitmap_addr, page_bitmap_size / MMU::page_size() + 1);
|
||||
lock_pages((u64)page_bitmap_addr, page_bitmap_size / ARCH_PAGE_SIZE + 1);
|
||||
}
|
||||
|
||||
void init()
|
||||
@ -118,16 +118,16 @@ namespace MemoryManager
|
||||
|
||||
void lock_page(u64 page)
|
||||
{
|
||||
uint64_t index = ((uint64_t)page) / MMU::page_size();
|
||||
uint64_t index = ((uint64_t)page) / ARCH_PAGE_SIZE;
|
||||
if (page_bitmap_read(index)) return;
|
||||
page_bitmap_set(index, true);
|
||||
used_mem += MMU::page_size();
|
||||
free_mem -= MMU::page_size();
|
||||
used_mem += ARCH_PAGE_SIZE;
|
||||
free_mem -= ARCH_PAGE_SIZE;
|
||||
}
|
||||
|
||||
void lock_pages(u64 pages, u64 count)
|
||||
{
|
||||
for (u64 index = 0; index < count; index++) { lock_page(pages + (index * MMU::page_size())); }
|
||||
for (u64 index = 0; index < count; index++) { lock_page(pages + (index * ARCH_PAGE_SIZE)); }
|
||||
}
|
||||
|
||||
Result<u64> alloc_physical_page()
|
||||
@ -137,9 +137,9 @@ namespace MemoryManager
|
||||
if (page_bitmap_read(index)) continue;
|
||||
page_bitmap_set(index, true);
|
||||
start_index = index + 1;
|
||||
free_mem -= MMU::page_size();
|
||||
used_mem += MMU::page_size();
|
||||
return index * MMU::page_size();
|
||||
free_mem -= ARCH_PAGE_SIZE;
|
||||
used_mem += ARCH_PAGE_SIZE;
|
||||
return index * ARCH_PAGE_SIZE;
|
||||
}
|
||||
|
||||
return err; // FIXME: ENOMEM.
|
||||
@ -147,24 +147,24 @@ namespace MemoryManager
|
||||
|
||||
Result<void> free_physical_page(u64 page)
|
||||
{
|
||||
u64 index = page / MMU::page_size();
|
||||
u64 index = page / ARCH_PAGE_SIZE;
|
||||
if (index > (page_bitmap_size * 8)) return err;
|
||||
if (!page_bitmap_read(index)) return err;
|
||||
page_bitmap_set(index, false);
|
||||
used_mem -= MMU::page_size();
|
||||
free_mem += MMU::page_size();
|
||||
used_mem -= ARCH_PAGE_SIZE;
|
||||
free_mem += ARCH_PAGE_SIZE;
|
||||
if (start_index > index) start_index = index;
|
||||
return {};
|
||||
}
|
||||
|
||||
Result<void> remap(u64 address, usize count, int flags)
|
||||
{
|
||||
check(is_aligned(address, MMU::page_size()));
|
||||
check(is_aligned(address, ARCH_PAGE_SIZE));
|
||||
|
||||
while (count--)
|
||||
{
|
||||
TRY(MMU::remap(address, flags));
|
||||
address += MMU::page_size();
|
||||
address += ARCH_PAGE_SIZE;
|
||||
}
|
||||
|
||||
return {};
|
||||
@ -172,13 +172,13 @@ namespace MemoryManager
|
||||
|
||||
Result<void> remap_unaligned(u64 address, usize count, int flags)
|
||||
{
|
||||
if (!is_aligned(address, MMU::page_size())) count++;
|
||||
address = align_down(address, MMU::page_size());
|
||||
if (!is_aligned(address, ARCH_PAGE_SIZE)) count++;
|
||||
address = align_down(address, ARCH_PAGE_SIZE);
|
||||
|
||||
while (count--)
|
||||
{
|
||||
TRY(MMU::remap(address, flags));
|
||||
address += MMU::page_size();
|
||||
address += ARCH_PAGE_SIZE;
|
||||
}
|
||||
|
||||
return {};
|
||||
|
@ -3,6 +3,8 @@
|
||||
|
||||
struct PageDirectory;
|
||||
|
||||
extern const usize ARCH_PAGE_SIZE;
|
||||
|
||||
namespace MMU
|
||||
{
|
||||
enum Flags
|
||||
@ -28,6 +30,4 @@ namespace MMU
|
||||
|
||||
Result<PageDirectory*> create_page_directory_for_userspace();
|
||||
void setup_initial_page_directory();
|
||||
|
||||
usize page_size();
|
||||
}
|
@ -4,6 +4,8 @@
|
||||
|
||||
#define PAGE_SIZE 4096
|
||||
|
||||
const usize ARCH_PAGE_SIZE = PAGE_SIZE;
|
||||
|
||||
const u64 rindex = 0776; // recursive index
|
||||
const u64 sign = 0177777UL << 48; // sign extension
|
||||
|
||||
@ -52,10 +54,6 @@ static_assert(sizeof(PageDirectory) == PAGE_SIZE);
|
||||
|
||||
namespace MMU
|
||||
{
|
||||
usize page_size()
|
||||
{
|
||||
return PAGE_SIZE;
|
||||
}
|
||||
|
||||
PageDirectory* l4_table()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user