diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2025-10-29 11:09:42 +0100 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2025-10-29 11:09:42 +0100 |
| commit | 6434de8ff75a9143847ef529bc209790ac4909b3 (patch) | |
| tree | a66902303f99f10897cb04e294c55fabf814c49f /arch | |
| parent | acabbacdee68ad80e829bda56ae5363d04646d2d (diff) | |
| download | teachos-6434de8ff75a9143847ef529bc209790ac4909b3.tar.xz teachos-6434de8ff75a9143847ef529bc209790ac4909b3.zip | |
kapi: move frame and address to KAPI
Diffstat (limited to 'arch')
| -rw-r--r-- | arch/x86_64/include/x86_64/boot/boot.hpp | 26 | ||||
| -rw-r--r-- | arch/x86_64/include/x86_64/boot/ld.hpp | 4 | ||||
| -rw-r--r-- | arch/x86_64/include/x86_64/cpu/registers.hpp | 4 | ||||
| -rw-r--r-- | arch/x86_64/include/x86_64/device_io/port_io.hpp | 4 | ||||
| -rw-r--r-- | arch/x86_64/include/x86_64/memory/address.hpp | 47 | ||||
| -rw-r--r-- | arch/x86_64/include/x86_64/memory/frame.hpp | 95 | ||||
| -rw-r--r-- | arch/x86_64/include/x86_64/memory/mmu.hpp | 6 | ||||
| -rw-r--r-- | arch/x86_64/include/x86_64/memory/region_allocator.hpp | 8 | ||||
| -rw-r--r-- | arch/x86_64/include/x86_64/vga/crtc.hpp | 8 | ||||
| -rw-r--r-- | arch/x86_64/include/x86_64/vga/text.hpp | 4 | ||||
| -rw-r--r-- | arch/x86_64/src/cpu/registers.cpp | 4 | ||||
| -rw-r--r-- | arch/x86_64/src/kapi/cio.cpp | 2 | ||||
| -rw-r--r-- | arch/x86_64/src/kapi/memory.cpp | 8 | ||||
| -rw-r--r-- | arch/x86_64/src/memory/mmu.cpp | 6 | ||||
| -rw-r--r-- | arch/x86_64/src/memory/region_allocator.cpp | 16 | ||||
| -rw-r--r-- | arch/x86_64/src/vga/text.cpp | 6 |
16 files changed, 54 insertions, 194 deletions
diff --git a/arch/x86_64/include/x86_64/boot/boot.hpp b/arch/x86_64/include/x86_64/boot/boot.hpp index 1887e73..86f8ce3 100644 --- a/arch/x86_64/include/x86_64/boot/boot.hpp +++ b/arch/x86_64/include/x86_64/boot/boot.hpp @@ -48,18 +48,22 @@ #include <kstd/asm_ptr> -extern "C" +namespace teachos::boot::x86_64 { - /** - * @brief A pointer to the multiboot 2 information structure provided by the boot loader. - */ - extern kstd::asm_ptr<multiboot2::information_view> multiboot_information_pointer; - - /** - * @brief A pointer to the VGA text mode buffer. - */ - extern kstd::asm_ptr<std::pair<char, std::byte>> vga_buffer_pointer; -} + + extern "C" + { + /** + * @brief A pointer to the multiboot 2 information structure provided by the boot loader. + */ + extern kstd::asm_ptr<multiboot2::information_view> multiboot_information_pointer; + + /** + * @brief A pointer to the VGA text mode buffer. + */ + extern kstd::asm_ptr<std::pair<char, std::byte>> vga_buffer_pointer; + } +} // namespace teachos::boot::x86_64 #endif diff --git a/arch/x86_64/include/x86_64/boot/ld.hpp b/arch/x86_64/include/x86_64/boot/ld.hpp index 51eb23b..cf59c66 100644 --- a/arch/x86_64/include/x86_64/boot/ld.hpp +++ b/arch/x86_64/include/x86_64/boot/ld.hpp @@ -17,7 +17,7 @@ #include <cstddef> -namespace teachos::x86_64::boot +namespace teachos::boot::x86_64 { /** * @var _start_physical @@ -42,6 +42,6 @@ namespace teachos::x86_64::boot * @see _start_physical */ extern "C" std::byte _end_physical; -} // namespace teachos::x86_64::boot +} // namespace teachos::boot::x86_64 #endif diff --git a/arch/x86_64/include/x86_64/cpu/registers.hpp b/arch/x86_64/include/x86_64/cpu/registers.hpp index 607d559..d19acfc 100644 --- a/arch/x86_64/include/x86_64/cpu/registers.hpp +++ b/arch/x86_64/include/x86_64/cpu/registers.hpp @@ -3,7 +3,7 @@ #include <cstdint> -namespace teachos::x86_64::cpu +namespace teachos::cpu::x86_64 { /** @@ -67,6 +67,6 @@ namespace teachos::x86_64::cpu */ auto set_cr0_bit(cr0_flags flag) -> void; -} // namespace teachos::x86_64::cpu +} // namespace teachos::cpu::x86_64 #endif
\ No newline at end of file diff --git a/arch/x86_64/include/x86_64/device_io/port_io.hpp b/arch/x86_64/include/x86_64/device_io/port_io.hpp index 4cf0b65..352a4d0 100644 --- a/arch/x86_64/include/x86_64/device_io/port_io.hpp +++ b/arch/x86_64/include/x86_64/device_io/port_io.hpp @@ -5,7 +5,7 @@ #include <cstdint> #include <type_traits> -namespace teachos::x86_64::io +namespace teachos::io::x86_64 { /** * @brief An I/O port of a given size at a given address. @@ -127,6 +127,6 @@ namespace teachos::x86_64::io } }; -} // namespace teachos::x86_64::io +} // namespace teachos::io::x86_64 #endif
\ No newline at end of file diff --git a/arch/x86_64/include/x86_64/memory/address.hpp b/arch/x86_64/include/x86_64/memory/address.hpp deleted file mode 100644 index 20e9655..0000000 --- a/arch/x86_64/include/x86_64/memory/address.hpp +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef TEACHOS_X86_64_MEMORY_ADDRESS_HPP -#define TEACHOS_X86_64_MEMORY_ADDRESS_HPP - -#include <bit> -#include <compare> -#include <cstddef> -#include <cstdint> - -namespace teachos::x86_64::memory -{ - - enum struct address_type : bool - { - linear, - physical, - }; - - template<address_type Type> - struct address - { - constexpr explicit address(std::uintptr_t value) noexcept - : m_value{value} - { - } - - explicit address(std::byte * pointer) noexcept - : m_value{std::bit_cast<std::uintptr_t>(pointer)} - { - } - - explicit operator std::byte *() const noexcept { return std::bit_cast<std::byte *>(m_value); } - - auto constexpr operator<=>(address const &) const noexcept -> std::strong_ordering = default; - auto constexpr operator==(address const &) const noexcept -> bool = default; - - auto constexpr raw() const noexcept -> std::uintptr_t { return m_value; } - - private: - std::uintptr_t m_value{}; - }; - - using linear_address = address<address_type::linear>; - using physical_address = address<address_type::physical>; - -} // namespace teachos::x86_64::memory - -#endif
\ No newline at end of file diff --git a/arch/x86_64/include/x86_64/memory/frame.hpp b/arch/x86_64/include/x86_64/memory/frame.hpp deleted file mode 100644 index 21565fd..0000000 --- a/arch/x86_64/include/x86_64/memory/frame.hpp +++ /dev/null @@ -1,95 +0,0 @@ -#ifndef TEACHOS_X86_64_MEMORY_FRAME_HPP -#define TEACHOS_X86_64_MEMORY_FRAME_HPP - -#include "x86_64/memory/address.hpp" - -#include <compare> -#include <cstddef> - -namespace teachos::x86_64::memory -{ - /** - * @brief Specific physical frame containing helper functions to determine if a specific address is in that - * physical frame or not. - */ - struct frame - { - auto static inline constexpr DEFAULT_SIZE = std::size_t{4096}; ///< Default page size of x86_84 is always 4KiB. - - /** - * @brief Defaulted constructor. - */ - constexpr frame() = default; - - /** - * @brief Constructor. - * - * @param frame_number Index number that should be assigned to this physical frame. - */ - explicit constexpr frame(std::size_t number) - : m_number(number) - { - } - - /** - * @brief Returns the physical frame the given address is contained in. - * - * @param address Physical address we want to get the corresponding physical frame for. - * @return Frame the given address is contained in. - */ - auto constexpr static containing(physical_address address) noexcept -> frame - { - return frame{address.raw() / DEFAULT_SIZE}; - } - - /** - * @brief Get the start address of this physical frame. - * - * @return Start address of the physical frame. - */ - auto constexpr start_address() const noexcept -> physical_address - { - return physical_address{m_number * DEFAULT_SIZE}; - } - - auto constexpr operator+(std::size_t offset) const noexcept -> frame { return frame{m_number + offset}; } - - /** - * @brief Post increment operator. Returns a copy of the value. - * - * @return Copy of the incremented underlying frame number. - */ - auto constexpr operator++(int) noexcept -> frame - { - auto copy = *this; - return ++copy; - } - - /** - * @brief Pre increment operator. Returns a reference to the changed value. - * - * @return Reference to the incremented underlying frame number. - */ - auto constexpr operator++() noexcept -> frame & - { - ++m_number; - return *this; - } - - /** - * @brief Defaulted equals operator. - */ - auto constexpr operator==(frame const & other) const noexcept -> bool = default; - - /** - * @brief Defaulted three-way comparison operator. - */ - auto constexpr operator<=>(frame const & other) const noexcept -> std::strong_ordering = default; - - private: - std::size_t m_number{}; ///< Index number of the current physical frame, used to distinguish it from other frames. - }; - -} // namespace teachos::x86_64::memory - -#endif // TEACHOS_ARCH_X86_64_MEMORY_ALLOCATOR_frame_HPP diff --git a/arch/x86_64/include/x86_64/memory/mmu.hpp b/arch/x86_64/include/x86_64/memory/mmu.hpp index b03ffa2..323d18a 100644 --- a/arch/x86_64/include/x86_64/memory/mmu.hpp +++ b/arch/x86_64/include/x86_64/memory/mmu.hpp @@ -1,9 +1,9 @@ #ifndef TEACHOS_X86_64_MEMORY_MMU_HPP #define TEACHOS_X86_64_MEMORY_MMU_HPP -#include "x86_64/memory/address.hpp" +#include "kapi/memory/address.hpp" -namespace teachos::x86_64::memory +namespace teachos::memory::x86_64 { /** * @brief Invalidates any translation lookaside buffer (TLB) entry for the page table the given address is cotained @@ -22,6 +22,6 @@ namespace teachos::x86_64::memory */ auto tlb_flush_all() -> void; -} // namespace teachos::x86_64::memory +} // namespace teachos::memory::x86_64 #endif
\ No newline at end of file diff --git a/arch/x86_64/include/x86_64/memory/region_allocator.hpp b/arch/x86_64/include/x86_64/memory/region_allocator.hpp index 23bea10..a918195 100644 --- a/arch/x86_64/include/x86_64/memory/region_allocator.hpp +++ b/arch/x86_64/include/x86_64/memory/region_allocator.hpp @@ -1,15 +1,15 @@ #ifndef TEACHOS_X86_64_MEMORY_REGION_ALLOCATOR_HPP #define TEACHOS_X86_64_MEMORY_REGION_ALLOCATOR_HPP -#include "x86_64/memory/address.hpp" -#include "x86_64/memory/frame.hpp" +#include "kapi/memory/address.hpp" +#include "kapi/memory/frame.hpp" #include <multiboot2/information.hpp> #include <optional> #include <utility> -namespace teachos::x86_64::memory +namespace teachos::memory::x86_64 { /** * @brief Allocates memory linearly using memory areas read from the multiboot2 information pointer and leaks any @@ -71,6 +71,6 @@ namespace teachos::x86_64::memory frame const m_multiboot_end; ///< The end address of the multiboot code in memory. }; -} // namespace teachos::x86_64::memory +} // namespace teachos::memory::x86_64 #endif // TEACHOS_ARCH_X86_64_MEMORY_ALLOCATOR_AREA_FRAME_ALLOCATOR_HPP diff --git a/arch/x86_64/include/x86_64/vga/crtc.hpp b/arch/x86_64/include/x86_64/vga/crtc.hpp index 4b4eac5..e5ab9f1 100644 --- a/arch/x86_64/include/x86_64/vga/crtc.hpp +++ b/arch/x86_64/include/x86_64/vga/crtc.hpp @@ -5,17 +5,17 @@ #include <cstddef> -namespace teachos::x86_64::vga::crtc +namespace teachos::vga::x86_64::crtc { /** * @brief The address port of the CRT Controller. */ - using address = x86_64::io::port<0x3d4, 1>; + using address = io::x86_64::port<0x3d4, 1>; /** * @brief The data port of the CRT Controller. */ - using data = x86_64::io::port<0x3d5, 1>; + using data = io::x86_64::port<0x3d5, 1>; namespace registers { @@ -30,6 +30,6 @@ namespace teachos::x86_64::vga::crtc [[maybe_unused]] auto constexpr cursor_end = std::byte{0x0b}; } // namespace registers -} // namespace teachos::x86_64::vga::crtc +} // namespace teachos::vga::x86_64::crtc #endif
\ No newline at end of file diff --git a/arch/x86_64/include/x86_64/vga/text.hpp b/arch/x86_64/include/x86_64/vga/text.hpp index f8e6f1b..c193576 100644 --- a/arch/x86_64/include/x86_64/vga/text.hpp +++ b/arch/x86_64/include/x86_64/vga/text.hpp @@ -6,7 +6,7 @@ #include <cstdint> #include <string_view> -namespace teachos::x86_64::vga::text +namespace teachos::vga::x86_64::text { /** * @brief The colors available in the standard VGA text mode. @@ -142,6 +142,6 @@ namespace teachos::x86_64::vga::text auto writeln(std::string_view code_points, attribute attribute) -> void; }; -} // namespace teachos::x86_64::vga::text +} // namespace teachos::vga::x86_64::text #endif // TEACHOS_ARCH_X86_64_VIDEO_VGA_TEXT_HPP
\ No newline at end of file diff --git a/arch/x86_64/src/cpu/registers.cpp b/arch/x86_64/src/cpu/registers.cpp index 7ade98d..8646829 100644 --- a/arch/x86_64/src/cpu/registers.cpp +++ b/arch/x86_64/src/cpu/registers.cpp @@ -2,7 +2,7 @@ #include <type_traits> -namespace teachos::x86_64::cpu +namespace teachos::cpu::x86_64 { auto read_control_register(control_register cr) -> uint64_t { @@ -61,4 +61,4 @@ namespace teachos::x86_64::cpu auto const cr0 = read_control_register(control_register::cr0); write_control_register(control_register::cr0, static_cast<std::underlying_type<cr0_flags>::type>(flag) | cr0); } -} // namespace teachos::x86_64::cpu +} // namespace teachos::cpu::x86_64 diff --git a/arch/x86_64/src/kapi/cio.cpp b/arch/x86_64/src/kapi/cio.cpp index ac3ae39..eb0142a 100644 --- a/arch/x86_64/src/kapi/cio.cpp +++ b/arch/x86_64/src/kapi/cio.cpp @@ -5,7 +5,7 @@ namespace teachos::cio { - auto static constinit vga_device = std::optional<x86_64::vga::text::device>{}; + auto static constinit vga_device = std::optional<vga::x86_64::text::device>{}; auto init() -> void { diff --git a/arch/x86_64/src/kapi/memory.cpp b/arch/x86_64/src/kapi/memory.cpp index d1c1f03..55e6ba9 100644 --- a/arch/x86_64/src/kapi/memory.cpp +++ b/arch/x86_64/src/kapi/memory.cpp @@ -1,10 +1,10 @@ #include "kapi/memory.hpp" +#include "kapi/memory/frame.hpp" #include "kapi/system.hpp" #include "x86_64/boot/boot.hpp" #include "x86_64/boot/ld.hpp" -#include "x86_64/memory/address.hpp" #include "x86_64/memory/region_allocator.hpp" #include <multiboot2/information.hpp> @@ -13,8 +13,10 @@ namespace teachos::memory { - using namespace x86_64::memory; - using namespace x86_64::boot; + using namespace boot::x86_64; + using namespace memory::x86_64; + + std::size_t const PLATFORM_FRAME_SIZE{4096}; namespace { diff --git a/arch/x86_64/src/memory/mmu.cpp b/arch/x86_64/src/memory/mmu.cpp index 31783fe..e573b4e 100644 --- a/arch/x86_64/src/memory/mmu.cpp +++ b/arch/x86_64/src/memory/mmu.cpp @@ -2,8 +2,10 @@ #include "x86_64/cpu/registers.hpp" -namespace teachos::x86_64::memory +namespace teachos::memory::x86_64 { + namespace cpu = cpu::x86_64; + auto tlb_flush(linear_address address) -> void { asm volatile("invlpg (%[input])" : /* no output from call */ : [input] "r"(address) : "memory"); @@ -14,4 +16,4 @@ namespace teachos::x86_64::memory auto current_value = cpu::read_control_register(cpu::control_register::cr3); cpu::write_control_register(cpu::control_register::cr3, current_value); } -} // namespace teachos::x86_64::memory +} // namespace teachos::memory::x86_64 diff --git a/arch/x86_64/src/memory/region_allocator.cpp b/arch/x86_64/src/memory/region_allocator.cpp index c9a98b4..91a5d49 100644 --- a/arch/x86_64/src/memory/region_allocator.cpp +++ b/arch/x86_64/src/memory/region_allocator.cpp @@ -1,22 +1,14 @@ -// #include "arch/memory/allocator/region_allocator.hpp" - -// #include "arch/exception_handling/assert.hpp" - -// #include <algorithm> -// #include <array> -// #include <ranges> - #include "x86_64/memory/region_allocator.hpp" -#include "x86_64/memory/address.hpp" -#include "x86_64/memory/frame.hpp" +#include "kapi/memory/address.hpp" +#include "kapi/memory/frame.hpp" #include <multiboot2/information.hpp> #include <algorithm> #include <ranges> -namespace teachos::x86_64::memory +namespace teachos::memory::x86_64 { namespace { @@ -92,4 +84,4 @@ namespace teachos::x86_64::memory } auto region_allocator::deallocate_frame(frame const &) -> void {} -} // namespace teachos::x86_64::memory +} // namespace teachos::memory::x86_64 diff --git a/arch/x86_64/src/vga/text.cpp b/arch/x86_64/src/vga/text.cpp index af089fd..8f78ea9 100644 --- a/arch/x86_64/src/vga/text.cpp +++ b/arch/x86_64/src/vga/text.cpp @@ -9,8 +9,10 @@ #include <string_view> #include <utility> -namespace teachos::x86_64::vga::text +namespace teachos::vga::x86_64::text { + using boot::x86_64::vga_buffer_pointer; + namespace { auto constinit buffer_offset = std::ptrdiff_t{}; @@ -67,4 +69,4 @@ namespace teachos::x86_64::vga::text newline(); } -} // namespace teachos::x86_64::vga::text +} // namespace teachos::vga::x86_64::text |
