From: Amelia Coutard Date: Sat, 30 Dec 2023 02:10:31 +0000 (+0100) Subject: Déduplication du code pour mettre les plus grandes pages physiques possibles dans... X-Git-Url: https://git.ameliathe1st.gay/?a=commitdiff_plain;h=9c6a551be066ee8d75252eaad9498f1aa46b26ed;p=voyage-au-centre-des-fichiers.git Déduplication du code pour mettre les plus grandes pages physiques possibles dans la mémoire virtuelle --- diff --git a/kernel/src/kernel.cpp b/kernel/src/kernel.cpp index 76dcd4a..10547cd 100644 --- a/kernel/src/kernel.cpp +++ b/kernel/src/kernel.cpp @@ -32,6 +32,19 @@ char _kernel_phys_end; os::paging::page<0> bootstrap_pages_for_memory[256]; // 256 pages = 1MiB +void map_biggest_physical_page(os::paging::PML4T& paging_table, void const* vaddr, amy::ptr& phys_addr, amy::ptr phys_addr_end, os::paging::page_info page_info) { + if (phys_addr % (1024 * 1024 * 1024) == 0 && phys_addr + 1024 * 1024 * 1024 < phys_addr_end) { + os::paging::map_page<2, 3>(paging_table, (os::paging::page<2>*)vaddr, os::phys_ptr>(phys_addr), page_info); + phys_addr += 1024 * 1024 * 1024; + } else if (phys_addr % (1024 * 1024 * 2) == 0 && phys_addr + 1024 * 1024 * 2 < phys_addr_end) { + os::paging::map_page<1, 3>(paging_table, (os::paging::page<1>*)vaddr, os::phys_ptr>(phys_addr), page_info); + phys_addr += 1024 * 1024 * 2; + } else { + os::paging::map_page<0, 3>(paging_table, (os::paging::page<0>*)vaddr, os::phys_ptr>(phys_addr), page_info); + phys_addr += 1024 * 4; + } +} + extern "C" void kmain(unsigned long magic, os::phys_ptr info) { if (!os::init_serial_port()) { while (true) { @@ -51,34 +64,12 @@ extern "C" void kmain(unsigned long magic, os::phys_ptr(os::paging::global_PML4T, (os::paging::page<2>*)(0xFFFF'FFFF'8000'0000 + i), os::phys_ptr>(i), - { .RW = false, .US = false, .PWT = false, .PCD = false, .A = false, .D = false, .PAT = false, .G = true, .AVL = 0, .NX = false }); - i += 1024 * 1024 * 1024; - } else if (i % (1024 * 1024 * 2) == 0 && i + 1024 * 1024 * 2 < amy::ptr(&_kernel_phys_rw_start)) { - os::paging::map_page<1, 3>(os::paging::global_PML4T, (os::paging::page<1>*)(0xFFFF'FFFF'8000'0000 + i), os::phys_ptr>(i), - { .RW = false, .US = false, .PWT = false, .PCD = false, .A = false, .D = false, .PAT = false, .G = true, .AVL = 0, .NX = false }); - i += 1024 * 1024 * 2; - } else { - os::paging::map_page<0, 3>(os::paging::global_PML4T, (os::paging::page<0>*)(0xFFFF'FFFF'8000'0000 + i), os::phys_ptr>(i), - { .RW = false, .US = false, .PWT = false, .PCD = false, .A = false, .D = false, .PAT = false, .G = true, .AVL = 0, .NX = false }); - i += 1024 * 4; - } + map_biggest_physical_page(os::paging::global_PML4T, (void*)(0xFFFF'FFFF'8000'0000 + i), i, amy::ptr(&_kernel_phys_rw_start), + { .RW = false, .US = false, .PWT = false, .PCD = false, .A = false, .D = false, .PAT = false, .G = true, .AVL = 0, .NX = false }); } for (amy::size i = amy::ptr(&_kernel_phys_rw_start); i < amy::ptr(&_kernel_phys_end); ) { - if (i % (1024 * 1024 * 1024) == 0 && i + 1024 * 1024 * 1024 < amy::ptr(&_kernel_phys_rw_start)) { - os::paging::map_page<2, 3>(os::paging::global_PML4T, (os::paging::page<2>*)(0xFFFF'FFFF'8000'0000 + i), os::phys_ptr>(i), - { .RW = true, .US = false, .PWT = false, .PCD = false, .A = false, .D = false, .PAT = false, .G = true, .AVL = 0, .NX = true }); - i += 1024 * 1024 * 1024; - } else if (i % (1024 * 1024 * 2) == 0 && i + 1024 * 1024 * 2 < amy::ptr(&_kernel_phys_rw_start)) { - os::paging::map_page<1, 3>(os::paging::global_PML4T, (os::paging::page<1>*)(0xFFFF'FFFF'8000'0000 + i), os::phys_ptr>(i), - { .RW = true, .US = false, .PWT = false, .PCD = false, .A = false, .D = false, .PAT = false, .G = true, .AVL = 0, .NX = true }); - i += 1024 * 1024 * 2; - } else { - os::paging::map_page<0, 3>(os::paging::global_PML4T, (os::paging::page<0>*)(0xFFFF'FFFF'8000'0000 + i), os::phys_ptr>(i), - { .RW = true, .US = false, .PWT = false, .PCD = false, .A = false, .D = false, .PAT = false, .G = true, .AVL = 0, .NX = true }); - i += 1024 * 4; - } + map_biggest_physical_page(os::paging::global_PML4T, (void*)(0xFFFF'FFFF'8000'0000 + i), i, amy::ptr(&_kernel_phys_end), + { .RW = true, .US = false, .PWT = false, .PCD = false, .A = false, .D = false, .PAT = false, .G = true, .AVL = 0, .NX = true }); } // Initialise physical memory map. for (auto it = multiboot2::next(info); it->type != multiboot2::info::type_t::end; it = multiboot2::next(it)) { @@ -98,29 +89,10 @@ extern "C" void kmain(unsigned long magic, os::phys_ptr( - os::paging::global_PML4T, - (os::paging::page<2>*)(0xFFFF'8000'0000'0000 + j), - os::phys_ptr>(j), - { .RW = true, .US = false, .PWT = false, .PCD = false, .A = false, .D = false, - .PAT = false, .G = true, .AVL = 0, .NX = true }); - j += 1024 * 1024 * 1024; - } else if (j % (1024 * 1024 * 2) == 0 && j + 1024 * 1024 * 2 < e) { - os::paging::map_page<1, 3>(os::paging::global_PML4T, - (os::paging::page<1>*)(0xFFFF'8000'0000'0000 + j), - os::phys_ptr>(j), - { .RW = true, .US = false, .PWT = false, .PCD = false, .A = false, .D = false, - .PAT = false, .G = true, .AVL = 0, .NX = true }); - j += 1024 * 1024 * 2; - } else { - os::paging::map_page<0, 3>(os::paging::global_PML4T, - (os::paging::page<0>*)(0xFFFF'8000'0000'0000 + j), - os::phys_ptr>(j), - { .RW = true, .US = false, .PWT = false, .PCD = false, .A = false, .D = false, - .PAT = false, .G = true, .AVL = 0, .NX = true }); - j += 1024 * 4; - } + map_biggest_physical_page(os::paging::global_PML4T, + (void*)(0xFFFF'8000'0000'0000 + j), j, e, + { .RW = true, .US = false, .PWT = false, .PCD = false, .A = false, .D = false, + .PAT = false, .G = true, .AVL = 0, .NX = true }); } } os::print("RAM END\n");