From acbd91c9898808a928af0b1bdd9d5058e8a91f62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Sun, 27 Oct 2024 14:55:52 +0000 Subject: Add typedef for virtual / physical addresses --- .../include/arch/memory/allocator/physical_frame.hpp | 6 ++++-- .../include/arch/memory/paging/page_mapper.hpp | 20 ++++++++++---------- .../include/arch/memory/paging/virtual_page.hpp | 6 ++++-- 3 files changed, 18 insertions(+), 14 deletions(-) (limited to 'arch/x86_64/include') diff --git a/arch/x86_64/include/arch/memory/allocator/physical_frame.hpp b/arch/x86_64/include/arch/memory/allocator/physical_frame.hpp index e33c77a..87c14ac 100644 --- a/arch/x86_64/include/arch/memory/allocator/physical_frame.hpp +++ b/arch/x86_64/include/arch/memory/allocator/physical_frame.hpp @@ -6,6 +6,8 @@ namespace teachos::arch::memory::allocator { + typedef std::size_t physical_address; + constexpr std::size_t PAGE_FRAME_SIZE = 4096U; ///< Default page size of x86_84 is always 4KiB. /** @@ -24,10 +26,10 @@ namespace teachos::arch::memory::allocator /** * @brief Returns the physical frame the given address is contained in. * - * @param physical_address Physical address we want to get the corresponding physical frame for. + * @param address Physical address we want to get the corresponding physical frame for. * @return Frame the given address is contained in. */ - auto static containing_address(std::size_t physical_address) -> physical_frame; + auto static containing_address(physical_address address) -> physical_frame; /** * @brief Evaluates the start address of the physical frame. diff --git a/arch/x86_64/include/arch/memory/paging/page_mapper.hpp b/arch/x86_64/include/arch/memory/paging/page_mapper.hpp index 7a8e2c9..5b74bd2 100644 --- a/arch/x86_64/include/arch/memory/paging/page_mapper.hpp +++ b/arch/x86_64/include/arch/memory/paging/page_mapper.hpp @@ -30,8 +30,16 @@ namespace teachos::arch::memory::paging auto create_or_get() -> page_table_handle; /** - * @brief Translates page into physical frame, will first attempt to parse normally using default page size and if it - * failed attempt to parse using huge pages. + * @brief Translates virtual address into corresponding physical address. Calls translate_page under the hood. + * + * @param address Virtual address we want to translate into physical one. + * @return Physical address corresponding to the provided virtual address. + */ + auto translate_address(virtual_address address) -> std::optional; + + /** + * @brief Translates page into physical frame, will first attempt to parse normally using default page size and if + * it failed attempt to parse using huge pages. * * @param page Page to translate into physical frame. * @return Physical frame corresponding to the provided virtual page. @@ -46,14 +54,6 @@ namespace teachos::arch::memory::paging */ auto translate_huge_page(virtual_page page) -> std::optional; - /** - * @brief Translate virtual into phyical address. - * - * @param virtual_address Address to translate into physical. - * @return Physical address. - */ - auto translate_address(std::size_t virtual_address) -> std::optional; - /** * @brief Maps a virtual page to a physical frame in the page table with the specified flags. * diff --git a/arch/x86_64/include/arch/memory/paging/virtual_page.hpp b/arch/x86_64/include/arch/memory/paging/virtual_page.hpp index f01073d..b9e2195 100644 --- a/arch/x86_64/include/arch/memory/paging/virtual_page.hpp +++ b/arch/x86_64/include/arch/memory/paging/virtual_page.hpp @@ -10,6 +10,8 @@ namespace teachos::arch::memory::paging { + typedef std::size_t virtual_address; + /** * @brief Virtual page entry contained in P1 page tables */ @@ -25,10 +27,10 @@ namespace teachos::arch::memory::paging /** * @brief Returns the virtual page the given address is contained in. * - * @param virtual_address Virtual address we want to get the corresponding virtual page for. + * @param address Virtual address we want to get the corresponding virtual page for. * @return Frame the given address is contained in. */ - auto static containing_address(std::size_t virtual_address) -> virtual_page; + auto static containing_address(virtual_address address) -> virtual_page; /** * @brief Evaluates the start address of the virtual page. -- cgit v1.2.3