diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2025-07-23 13:52:28 +0000 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2025-07-23 13:52:28 +0000 |
| commit | be5c7e992ef3f7827e7229d77af3f812484de260 (patch) | |
| tree | 25cb4767472b2a7e09b9906c6db62f4e8e65eaf7 | |
| parent | 29f0e6ad021997e4b6995de4f795781ac381f697 (diff) | |
| download | teachos-be5c7e992ef3f7827e7229d77af3f812484de260.tar.xz teachos-be5c7e992ef3f7827e7229d77af3f812484de260.zip | |
x86_64: extract linker script interface header
| -rw-r--r-- | arch/x86_64/include/x86_64/boot/ld.hpp | 22 | ||||
| -rw-r--r-- | arch/x86_64/src/memory.cpp | 25 |
2 files changed, 41 insertions, 6 deletions
diff --git a/arch/x86_64/include/x86_64/boot/ld.hpp b/arch/x86_64/include/x86_64/boot/ld.hpp new file mode 100644 index 0000000..e6b397b --- /dev/null +++ b/arch/x86_64/include/x86_64/boot/ld.hpp @@ -0,0 +1,22 @@ +#ifndef TEACHOS_X86_64_BOOT_LD_H +#define TEACHOS_X86_64_BOOT_LD_H + +#include <cstddef> + +extern "C" +{ + namespace teachos::x86_64::boot + { + /** + * @brief The first byte of the loaded kernel image. + */ + extern "C" std::byte _start_linear; + + /** + * @brief The first byte after the loaded kernel image. + */ + extern "C" std::byte _end_linear; + } // namespace teachos::x86_64::boot +} + +#endif diff --git a/arch/x86_64/src/memory.cpp b/arch/x86_64/src/memory.cpp index a31627b..105d69b 100644 --- a/arch/x86_64/src/memory.cpp +++ b/arch/x86_64/src/memory.cpp @@ -3,22 +3,33 @@ #include "kern/error.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> #include <atomic> -// extern "C" teachos::arch::asm_pointer<multiboot2::information_view> multiboot_information_pointer; - namespace teachos::arch::memory { + using namespace x86_64::memory; + using namespace x86_64::boot; + namespace { auto constinit is_initialized = std::atomic_flag{}; - // auto create_memory_information() -> x86_64::memory::region_allocator::memory_information { + 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_linear}, physical_address{&_end_linear}), + std::make_pair(physical_address{std::bit_cast<std::byte *>(&mbi)}, + physical_address{std::bit_cast<std::byte *>(&mbi) + mbi->size_bytes()}), + map}; + }; } // namespace auto init() -> void @@ -34,8 +45,10 @@ namespace teachos::arch::memory teachos::panic("[x86_64] No memory map available."); } - // auto mem_info = x86_64::memory::region_allocator::memory_information{}; - // auto allocator = x86_64::memory::region_allocator{mem_info}; + auto mem_info = create_memory_information(); + auto allocator = region_allocator{mem_info}; + + static_cast<void>(allocator); // kernel::cpu::set_cr0_bit(kernel::cpu::cr0_flags::WRITE_PROTECT); // kernel::cpu::set_efer_bit(kernel::cpu::efer_flags::NXE); |
