From 3dcd14a0570fef3bcc68d7df42fe3ff4cd496f93 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Mon, 6 Apr 2026 14:47:37 +0200 Subject: kapi: hook ACPI initialization up to boot process --- kapi/include/kapi/acpi.hpp | 44 ++++++++++++++++++++++++++----------- kapi/include/kapi/memory/layout.hpp | 12 ++++++++++ 2 files changed, 43 insertions(+), 13 deletions(-) (limited to 'kapi') diff --git a/kapi/include/kapi/acpi.hpp b/kapi/include/kapi/acpi.hpp index 1068921..d5e3c87 100644 --- a/kapi/include/kapi/acpi.hpp +++ b/kapi/include/kapi/acpi.hpp @@ -2,16 +2,36 @@ #define TEACHOS_KAPI_ACPI_HPP #include "kapi/memory.hpp" + #include #include #include #include +#include #include namespace kapi::acpi { + //! @addtogroup kapi-acpi + //! @{ + + struct [[gnu::packed]] system_description_table_header + { + std::array signature; + std::uint32_t length; + std::uint8_t revision; + std::uint8_t checksum; + std::array oem_id; + std::array oem_table_id; + std::uint32_t oem_revision; + std::uint32_t creator_id; + std::uint32_t create_revision; + }; + + //! @} + //! @addtogroup kapi-acpi-kernel-defined //! @{ @@ -44,20 +64,18 @@ namespace kapi::acpi [[maybe_unused]] std::array m_reserved; }; - //! @} + //! Initialize the ACPI subsystem and discover the available tables. + //! + //! @return true iff. a valid system description tabled was found, false otherwise. + auto init(root_system_description_pointer const & sdp) -> bool; - struct [[gnu::packed]] system_description_table_header - { - std::array signature; - std::uint32_t length; - std::uint8_t revision; - std::uint8_t checksum; - std::array oem_id; - std::array oem_table_id; - std::uint32_t oem_revision; - std::uint32_t creator_id; - std::uint32_t create_revision; - }; + //! Validate and ACPI entity checksum. + //! + //! @param data The data to validate the checksum of. + //! @return true iff. the checksum is valid, false otherwise. + auto validate_checksum(std::span data) -> bool; + + //! @} } // namespace kapi::acpi diff --git a/kapi/include/kapi/memory/layout.hpp b/kapi/include/kapi/memory/layout.hpp index 157f41e..26b48d8 100644 --- a/kapi/include/kapi/memory/layout.hpp +++ b/kapi/include/kapi/memory/layout.hpp @@ -37,6 +37,18 @@ namespace kapi::memory //! The linear base address of the loaded kernel image. constexpr auto kernel_base = linear_address{0xffff'ffff'8000'0000uz}; + //! Convert a physical address to a linear address using the higher-half direct map. + constexpr auto hhdm_to_linear(physical_address address) -> linear_address + { + return linear_address{address.raw() + higher_half_direct_map_base.raw()}; + } + + //! Convert a linear address in the higher-half direct map to a physical address. + constexpr auto hhdm_to_physical(linear_address address) -> physical_address + { + return physical_address{address.raw() - higher_half_direct_map_base.raw()}; + } + } // namespace kapi::memory #endif \ No newline at end of file -- cgit v1.2.3