map_page: take the page size as an argument (enum)

Signed-off-by: Andy-Python-Programmer <andypythonappdeveloper@gmail.com>
This commit is contained in:
Andy-Python-Programmer 2022-01-27 10:54:26 +11:00 committed by mintsuki
parent ddf85ede0a
commit 7a1e3cb35c
3 changed files with 16 additions and 11 deletions

View File

@ -39,7 +39,7 @@ pagemap_t new_pagemap(int lv) {
return pagemap;
}
void map_page(pagemap_t pagemap, uint64_t virt_addr, uint64_t phys_addr, uint64_t flags, bool hugepages) {
void map_page(pagemap_t pagemap, uint64_t virt_addr, uint64_t phys_addr, uint64_t flags, enum page_size pg_size) {
// Calculate the indices in the various tables using the virtual address
size_t pml5_entry = (virt_addr & ((uint64_t)0x1ff << 48)) >> 48;
size_t pml4_entry = (virt_addr & ((uint64_t)0x1ff << 39)) >> 39;
@ -67,7 +67,7 @@ level4:
pml3 = get_next_level(pml4, pml4_entry);
pml2 = get_next_level(pml3, pml3_entry);
if (hugepages) {
if (pg_size == Size2MiB) {
pml2[pml2_entry] = (pt_entry_t)(phys_addr | flags | (1 << 7));
return;
}

View File

@ -13,8 +13,13 @@ typedef struct {
void *top_level;
} pagemap_t;
enum page_size {
Size4KiB,
Size2MiB
};
void vmm_assert_nx(void);
pagemap_t new_pagemap(int lv);
void map_page(pagemap_t pagemap, uint64_t virt_addr, uint64_t phys_addr, uint64_t flags, bool hugepages);
void map_page(pagemap_t pagemap, uint64_t virt_addr, uint64_t phys_addr, uint64_t flags, enum page_size page_size);
#endif

View File

@ -386,7 +386,7 @@ pagemap_t stivale_build_pagemap(bool level5pg, bool unmap_null, struct elf_range
if (ranges_count == 0) {
// Map 0 to 2GiB at 0xffffffff80000000
for (uint64_t i = 0; i < 0x80000000; i += 0x200000) {
map_page(pagemap, 0xffffffff80000000 + i, i, 0x03, true);
map_page(pagemap, 0xffffffff80000000 + i, i, 0x03, Size2MiB);
}
} else {
for (size_t i = 0; i < ranges_count; i++) {
@ -408,7 +408,7 @@ pagemap_t stivale_build_pagemap(bool level5pg, bool unmap_null, struct elf_range
(ranges[i].permissions & ELF_PF_W ? VMM_FLAG_WRITE : 0);
for (uint64_t j = 0; j < ranges[i].length; j += 0x1000) {
map_page(pagemap, virt + j, phys + j, pf, false);
map_page(pagemap, virt + j, phys + j, pf, Size4KiB);
}
}
}
@ -416,14 +416,14 @@ pagemap_t stivale_build_pagemap(bool level5pg, bool unmap_null, struct elf_range
// Sub 2MiB mappings
for (uint64_t i = 0; i < 0x200000; i += 0x1000) {
if (!(i == 0 && unmap_null))
map_page(pagemap, i, i, 0x03, false);
map_page(pagemap, direct_map_offset + i, i, 0x03, false);
map_page(pagemap, i, i, 0x03, Size4KiB);
map_page(pagemap, direct_map_offset + i, i, 0x03, Size4KiB);
}
// Map 2MiB to 4GiB at higher half base and 0
for (uint64_t i = 0x200000; i < 0x100000000; i += 0x200000) {
map_page(pagemap, i, i, 0x03, true);
map_page(pagemap, direct_map_offset + i, i, 0x03, true);
map_page(pagemap, i, i, 0x03, Size2MiB);
map_page(pagemap, direct_map_offset + i, i, 0x03, Size2MiB);
}
size_t _memmap_entries = memmap_entries;
@ -450,8 +450,8 @@ pagemap_t stivale_build_pagemap(bool level5pg, bool unmap_null, struct elf_range
for (uint64_t j = 0; j < aligned_length; j += 0x200000) {
uint64_t page = aligned_base + j;
map_page(pagemap, page, page, 0x03, true);
map_page(pagemap, direct_map_offset + page, page, 0x03, true);
map_page(pagemap, page, page, 0x03, Size2MiB);
map_page(pagemap, direct_map_offset + page, page, 0x03, Size2MiB);
}
}