From: Matthias Kruk Date: Tue, 17 Sep 2019 07:48:40 +0000 (+0900) Subject: Make _pg_dir_map_legacy() map large pages, where possible X-Git-Url: https://git.corax.cc/?a=commitdiff_plain;h=ec65b4d6a5294861b15dac1af017c9295941489e;p=corax Make _pg_dir_map_legacy() map large pages, where possible --- diff --git a/kernel/arch/paging.c b/kernel/arch/paging.c index 5277d10..7991817 100644 --- a/kernel/arch/paging.c +++ b/kernel/arch/paging.c @@ -355,17 +355,32 @@ static int _pg_dir_map_legacy(page_table_t *pd, u32_t paddr, u32_t vaddr, u32_t /* allocate a new page table if not present */ if(!(pd->pt_entries[pde] & PAGE_ATTR_PRESENT)) { - pd->pt_entries[pde] = (u32_t)pg_frame_alloc_end(); + /* + * Allocate a large page if we're at a large page boundary + * and we're supposed to allocate at least the size of a large page + */ + if(size >= PAGE_SIZE_LARGE && ALIGNED(vaddr, PAGE_SIZE_LARGE)) { + pd->pt_entries[pde] = vaddr | PAGE_ATTR_SIZE | PAGE_ATTR_PRESENT | flags; - if(!pd->pt_entries[pde]) { - ret_val = -ENOMEM; - break; + paddr += PAGE_SIZE_LARGE; + vaddr += PAGE_SIZE_LARGE; + size -= PAGE_SIZE_LARGE; + + /* skip the rest of the loop, which would attempt to populate the page table */ + continue; } else { - /* wipe the page table before using it */ - memset((void*)pd->pt_entries[pde], 0, PAGE_SIZE); - } + pd->pt_entries[pde] = (u32_t)pg_frame_alloc_end(); + + if(!pd->pt_entries[pde]) { + ret_val = -ENOMEM; + break; + } else { + /* wipe the page table before using it */ + memset((void*)pd->pt_entries[pde], 0, PAGE_SIZE); + } - pd->pt_entries[pde] |= PAGE_ATTR_PRESENT | flags; + pd->pt_entries[pde] |= PAGE_ATTR_PRESENT | flags; + } } pt = (page_table_t*)(pd->pt_entries[pde] & 0xfffff000);