From 7671b1f0e4790b43bb8f8747b63cd44b7a65e10f Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Mon, 27 Oct 2025 13:58:55 +0000 Subject: x86_64: move kapi implementation to src --- arch/x86_64/CMakeLists.txt | 10 +++---- arch/x86_64/kapi/cio.cpp | 16 ---------- arch/x86_64/kapi/memory.cpp | 66 ----------------------------------------- arch/x86_64/kapi/system.cpp | 12 -------- arch/x86_64/src/kapi/cio.cpp | 16 ++++++++++ arch/x86_64/src/kapi/memory.cpp | 66 +++++++++++++++++++++++++++++++++++++++++ arch/x86_64/src/kapi/system.cpp | 12 ++++++++ 7 files changed, 99 insertions(+), 99 deletions(-) delete mode 100644 arch/x86_64/kapi/cio.cpp delete mode 100644 arch/x86_64/kapi/memory.cpp delete mode 100644 arch/x86_64/kapi/system.cpp create mode 100644 arch/x86_64/src/kapi/cio.cpp create mode 100644 arch/x86_64/src/kapi/memory.cpp create mode 100644 arch/x86_64/src/kapi/system.cpp diff --git a/arch/x86_64/CMakeLists.txt b/arch/x86_64/CMakeLists.txt index e8b5162..9be7b04 100644 --- a/arch/x86_64/CMakeLists.txt +++ b/arch/x86_64/CMakeLists.txt @@ -11,11 +11,6 @@ target_link_libraries("x86_64" PUBLIC ) target_sources("x86_64" PRIVATE - # api::kapi implementation - "kapi/cio.cpp" - "kapi/memory.cpp" - "kapi/system.cpp" - # Low-level bootstrap "src/boot/boot32.S" "src/boot/entry64.s" @@ -25,6 +20,11 @@ target_sources("x86_64" PRIVATE # CPU intrinsics "src/cpu/registers.cpp" + # api::kapi implementation + "src/kapi/cio.cpp" + "src/kapi/memory.cpp" + "src/kapi/system.cpp" + # Memory management "src/memory/mmu.cpp" "src/memory/region_allocator.cpp" diff --git a/arch/x86_64/kapi/cio.cpp b/arch/x86_64/kapi/cio.cpp deleted file mode 100644 index ac3ae39..0000000 --- a/arch/x86_64/kapi/cio.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include "kapi/cio.hpp" - -#include "x86_64/vga/text.hpp" - -namespace teachos::cio -{ - - auto static constinit vga_device = std::optional{}; - - auto init() -> void - { - vga_device.emplace(); - set_output_device(*vga_device); - } - -} // namespace teachos::cio diff --git a/arch/x86_64/kapi/memory.cpp b/arch/x86_64/kapi/memory.cpp deleted file mode 100644 index d1c1f03..0000000 --- a/arch/x86_64/kapi/memory.cpp +++ /dev/null @@ -1,66 +0,0 @@ -#include "kapi/memory.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 - -#include - -namespace teachos::memory -{ - using namespace x86_64::memory; - using namespace x86_64::boot; - - namespace - { - auto constinit is_initialized = std::atomic_flag{}; - - auto create_memory_information() -> region_allocator::memory_information - { - auto const & mbi = multiboot_information_pointer.get(); - auto map = mbi->memory_map(); - - return {std::make_pair(physical_address{&_start_physical}, physical_address{&_end_physical}), - std::make_pair(physical_address{std::bit_cast(&mbi)}, - physical_address{std::bit_cast(&mbi) + mbi->size_bytes()}), - map}; - }; - } // namespace - - auto init() -> void - { - if (is_initialized.test_and_set()) - { - system::panic("[x86_64] Memory management has already been initialized."); - } - - auto memory_map = multiboot_information_pointer->maybe_memory_map(); - if (!memory_map) - { - system::panic("[x86_64] No memory map available."); - } - - auto mem_info = create_memory_information(); - auto allocator = region_allocator{mem_info}; - - static_cast(allocator); - - // kernel::cpu::set_cr0_bit(kernel::cpu::cr0_flags::WRITE_PROTECT); - // kernel::cpu::set_efer_bit(kernel::cpu::efer_flags::NXE); - - // paging::kernel_mapper kernel(allocator, memory_information); - // kernel.remap_kernel(); - // video::vga::text::write("Kernel remapping successful", video::vga::text::common_attributes::green_on_black); - // video::vga::text::newline(); - - // remap_heap(heap::KERNEL_HEAP_START, heap::KERNEL_HEAP_SIZE); - // video::vga::text::write("Heap remapping successful", video::vga::text::common_attributes::green_on_black); - // video::vga::text::newline(); - } - -} // namespace teachos::memory diff --git a/arch/x86_64/kapi/system.cpp b/arch/x86_64/kapi/system.cpp deleted file mode 100644 index 2d4c3fe..0000000 --- a/arch/x86_64/kapi/system.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "kapi/system.hpp" - -namespace teachos::system -{ - - auto halt() -> void - { - asm volatile("1: hlt\njmp 1b"); - __builtin_unreachable(); - } - -} // namespace teachos::system diff --git a/arch/x86_64/src/kapi/cio.cpp b/arch/x86_64/src/kapi/cio.cpp new file mode 100644 index 0000000..ac3ae39 --- /dev/null +++ b/arch/x86_64/src/kapi/cio.cpp @@ -0,0 +1,16 @@ +#include "kapi/cio.hpp" + +#include "x86_64/vga/text.hpp" + +namespace teachos::cio +{ + + auto static constinit vga_device = std::optional{}; + + auto init() -> void + { + vga_device.emplace(); + set_output_device(*vga_device); + } + +} // namespace teachos::cio diff --git a/arch/x86_64/src/kapi/memory.cpp b/arch/x86_64/src/kapi/memory.cpp new file mode 100644 index 0000000..d1c1f03 --- /dev/null +++ b/arch/x86_64/src/kapi/memory.cpp @@ -0,0 +1,66 @@ +#include "kapi/memory.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 + +#include + +namespace teachos::memory +{ + using namespace x86_64::memory; + using namespace x86_64::boot; + + namespace + { + auto constinit is_initialized = std::atomic_flag{}; + + auto create_memory_information() -> region_allocator::memory_information + { + auto const & mbi = multiboot_information_pointer.get(); + auto map = mbi->memory_map(); + + return {std::make_pair(physical_address{&_start_physical}, physical_address{&_end_physical}), + std::make_pair(physical_address{std::bit_cast(&mbi)}, + physical_address{std::bit_cast(&mbi) + mbi->size_bytes()}), + map}; + }; + } // namespace + + auto init() -> void + { + if (is_initialized.test_and_set()) + { + system::panic("[x86_64] Memory management has already been initialized."); + } + + auto memory_map = multiboot_information_pointer->maybe_memory_map(); + if (!memory_map) + { + system::panic("[x86_64] No memory map available."); + } + + auto mem_info = create_memory_information(); + auto allocator = region_allocator{mem_info}; + + static_cast(allocator); + + // kernel::cpu::set_cr0_bit(kernel::cpu::cr0_flags::WRITE_PROTECT); + // kernel::cpu::set_efer_bit(kernel::cpu::efer_flags::NXE); + + // paging::kernel_mapper kernel(allocator, memory_information); + // kernel.remap_kernel(); + // video::vga::text::write("Kernel remapping successful", video::vga::text::common_attributes::green_on_black); + // video::vga::text::newline(); + + // remap_heap(heap::KERNEL_HEAP_START, heap::KERNEL_HEAP_SIZE); + // video::vga::text::write("Heap remapping successful", video::vga::text::common_attributes::green_on_black); + // video::vga::text::newline(); + } + +} // namespace teachos::memory diff --git a/arch/x86_64/src/kapi/system.cpp b/arch/x86_64/src/kapi/system.cpp new file mode 100644 index 0000000..2d4c3fe --- /dev/null +++ b/arch/x86_64/src/kapi/system.cpp @@ -0,0 +1,12 @@ +#include "kapi/system.hpp" + +namespace teachos::system +{ + + auto halt() -> void + { + asm volatile("1: hlt\njmp 1b"); + __builtin_unreachable(); + } + +} // namespace teachos::system -- cgit v1.2.3