From: Amelia Coutard Date: Tue, 5 Dec 2023 16:35:07 +0000 (+0100) Subject: Simplified some getters and setters, with the new template definitions X-Git-Url: https://git.ameliathe1st.gay/?a=commitdiff_plain;h=ef1edc3fb580d1b3c4b6b2876e63ca9d801a74c6;p=voyage-au-centre-des-fichiers.git Simplified some getters and setters, with the new template definitions --- diff --git a/kernel/src/paging.hpp b/kernel/src/paging.hpp index d4ed443..6955a7b 100644 --- a/kernel/src/paging.hpp +++ b/kernel/src/paging.hpp @@ -170,59 +170,27 @@ static_assert(alignof(paging_entry<0>) == 8); static_assert(sizeof(paging_entry<0>) == 8); -inline bool is_page(const PML4E __attribute__((unused))& PML4E) { return false; } -inline bool is_page(const PDPE& PDPE) { return PDPE.page.one == 1; } -inline bool is_page(const PDE& PDE) { return PDE.page.one == 1; } -inline bool is_page(const PE __attribute__((unused))& PE) { return true; } - -inline phys_ptr get_base_address(const PML4E& PML4E) { - os::assert(!is_page(PML4E), "Tried to get non-page out of a page paging."); - return phys_ptr{PML4E.non_page.base_address * 0x1000ull}; -} -inline phys_ptr get_base_address(const PDPE& PDPE) { - os::assert(!is_page(PDPE), "Tried to get non-page out of a page paging."); - return phys_ptr{PDPE.non_page.base_address * 0x1000ull}; -} -inline phys_ptr get_base_address(const PDE& PDE) { - os::assert(!is_page(PDE), "Tried to get non-page out of a page paging."); - return phys_ptr{PDE.non_page.base_address * 0x1000ull}; -} -inline phys_ptr> get_page_base_address(const PDPE& PDPE) { - os::assert(is_page(PDPE), "Tried to get page out of a non-page paging."); - return phys_ptr>{PDPE.page.base_address * sizeof(page<2>)}; -} -inline phys_ptr> get_page_base_address(const PDE& PDE) { - os::assert(is_page(PDE), "Tried to get page out of a non-page paging."); - return phys_ptr>{PDE.page.base_address * sizeof(page<1>)}; +inline bool is_page(PML4E) { return false; } +inline bool is_page(PDPE PDPE) { return PDPE.page.one == 1; } +inline bool is_page(PDE PDE) { return PDE.page.one == 1; } +inline bool is_page(PE) { return true; } + +template phys_ptr> get_base_address(paging_entry entry) { + os::assert(!is_page(entry), "Tried to get non-page out of a page paging."); + return phys_ptr>{entry.non_page.base_address * 0x1000ull}; } -inline phys_ptr> get_page_base_address(const PE& PE) { - os::assert(is_page(PE), "Tried to get page out of a non-page paging."); - return phys_ptr>{PE.page.base_address * sizeof(page<0>)}; +template phys_ptr> get_page_base_address(paging_entry entry) { + os::assert(is_page(entry), "Tried to get page out of a non-page paging."); + return phys_ptr>{entry.page.base_address * sizeof(page)}; } -inline void set_base_address(PML4E& PML4E, phys_ptr ptr) { - os::assert(!is_page(PML4E), "Tried to get non-page out of a page paging."); - PML4E.non_page.base_address = ptr.get_phys_addr() / 0x1000ull; -} -inline void set_base_address(PDPE& PDPE, phys_ptr ptr) { - os::assert(!is_page(PDPE), "Tried to get non-page out of a page paging."); - PDPE.non_page.base_address = ptr.get_phys_addr() / 0x1000ull; -} -inline void set_base_address(PDE& PDE, phys_ptr ptr) { - os::assert(!is_page(PDE), "Tried to get non-page out of a page paging."); - PDE.non_page.base_address = ptr.get_phys_addr() / 0x1000ull; -} -inline void set_page_base_address(PDPE& PDPE, phys_ptr> ptr) { - os::assert(is_page(PDPE), "Tried to get page out of a non-page paging."); - PDPE.page.base_address = ptr.get_phys_addr() / sizeof(*ptr); -} -inline void set_page_base_address(PDE& PDE, phys_ptr> ptr) { - os::assert(is_page(PDE), "Tried to get page out of a non-page paging."); - PDE.page.base_address = ptr.get_phys_addr() / sizeof(*ptr); +template void set_base_address(paging_entry& entry, phys_ptr> ptr) { + os::assert(!is_page(entry), "Tried to get non-page out of a page paging."); + entry.non_page.base_address = ptr.get_phys_addr() / 0x1000ull; } -inline void set_page_base_address(PE& PE, phys_ptr> ptr) { - os::assert(is_page(PE), "Tried to get page out of a non-page paging."); - PE.page.base_address = ptr.get_phys_addr() / sizeof(*ptr); +template void set_page_base_address(paging_entry& entry, phys_ptr> ptr) { + os::assert(is_page(entry), "Tried to get page out of a non-page paging."); + entry.page.base_address = ptr.get_phys_addr() / sizeof(page); } struct page_table_indices {