From c6629ba11c17601695b0542d7d1d1bf5dc036d84 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Thu, 24 Jul 2025 15:37:36 +0000 Subject: build: clean up configuration --- arch/x86_64/CMakeLists.txt | 192 +++----------------------------------------- arch/x86_64/kapi/io.cpp | 36 +++++++++ arch/x86_64/kapi/memory.cpp | 66 +++++++++++++++ arch/x86_64/kapi/system.cpp | 12 +++ arch/x86_64/src/io.cpp | 36 --------- arch/x86_64/src/memory.cpp | 66 --------------- arch/x86_64/src/system.cpp | 12 --- 7 files changed, 125 insertions(+), 295 deletions(-) create mode 100644 arch/x86_64/kapi/io.cpp create mode 100644 arch/x86_64/kapi/memory.cpp create mode 100644 arch/x86_64/kapi/system.cpp delete mode 100644 arch/x86_64/src/io.cpp delete mode 100644 arch/x86_64/src/memory.cpp delete mode 100644 arch/x86_64/src/system.cpp (limited to 'arch/x86_64') diff --git a/arch/x86_64/CMakeLists.txt b/arch/x86_64/CMakeLists.txt index 4cb20b6..1cb2f9a 100644 --- a/arch/x86_64/CMakeLists.txt +++ b/arch/x86_64/CMakeLists.txt @@ -10,196 +10,26 @@ target_link_libraries("arch-x86_64" PUBLIC "libs::multiboot2" ) -#[============================================================================[ -# arch::any Implementation -#]============================================================================] - target_sources("arch-x86_64" PRIVATE - "src/io.cpp" - "src/memory.cpp" - "src/system.cpp" -) - -#[============================================================================[ -# Bootstrap Code -#]============================================================================] + # api::kapi implementation + "kapi/io.cpp" + "kapi/memory.cpp" + "kapi/system.cpp" -target_sources("arch-x86_64" PRIVATE + # Low-level bootstrap "src/boot/boot32.S" "src/boot/entry64.s" "src/boot/initialize_runtime.cpp" "src/boot/multiboot.s" -) -#[============================================================================[ -# Memory Code -#]============================================================================] - -target_sources("arch-x86_64" PRIVATE + # Memory management "src/memory/region_allocator.cpp" -) - -#[============================================================================[ -# VGA Code -#]============================================================================] -target_sources("arch-x86_64" PRIVATE + # VGA text mode "src/vga/text.cpp" ) -# #[============================================================================[ -# # The Kernel Library -# #]============================================================================] - -# set(TEACHOS_KERNEL_LINKER_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/scripts/kernel.ld") -# mark_as_advanced(TEACHOS_KERNEL_LINKER_SCRIPT) - -# target_sources("_kernel" PRIVATE -# "src/kernel/main.cpp" -# "src/kernel/cpu/control_register.cpp" -# "src/kernel/cpu/gdtr.cpp" -# "src/kernel/cpu/idtr.cpp" -# "src/kernel/cpu/if.cpp" -# "src/kernel/cpu/call.cpp" -# "src/kernel/cpu/msr.cpp" -# "src/kernel/cpu/segment_register.cpp" -# "src/kernel/cpu/tlb.cpp" -# "src/kernel/cpu/tr.cpp" -# ) - -# target_link_options("_kernel" PRIVATE -# "-T${TEACHOS_KERNEL_LINKER_SCRIPT}" -# ) - -# set_target_properties("_kernel" PROPERTIES -# LINK_DEPENDS "${TEACHOS_KERNEL_LINKER_SCRIPT}" -# ) - -# #[============================================================================[ -# # The Bootstrap Library -# #]============================================================================] - -# target_sources("_boot" PRIVATE -# "src/boot/boot.s" -# "src/boot/crti.s" -# "src/boot/crtn.s" -# "src/boot/multiboot.s" -# ) - -# #[============================================================================[ -# # The Video Library -# #]============================================================================] - -# target_sources("_video" PRIVATE -# "src/video/vga/text.cpp" -# ) - -# #[============================================================================[ -# # The Memory Library -# #]============================================================================] - -# target_sources("_memory" PRIVATE -# "src/memory/main.cpp" -# "src/memory/multiboot/elf_symbols_section.cpp" -# "src/memory/multiboot/reader.cpp" -# "src/memory/allocator/area_frame_allocator.cpp" -# "src/memory/allocator/tiny_frame_allocator.cpp" -# "src/memory/allocator/physical_frame.cpp" -# "src/memory/paging/page_entry.cpp" -# "src/memory/paging/page_table.cpp" -# "src/memory/paging/temporary_page.cpp" -# "src/memory/paging/virtual_page.cpp" -# "src/memory/paging/active_page_table.cpp" -# "src/memory/paging/inactive_page_table.cpp" -# "src/memory/heap/bump_allocator.cpp" -# "src/memory/heap/user_heap_allocator.cpp" -# "src/memory/heap/memory_block.cpp" -# "src/memory/heap/linked_list_allocator.cpp" -# "src/memory/heap/global_heap_allocator.cpp" -# ) - -# target_link_libraries("_memory" PUBLIC -# "libs::kstd" -# "libs::multiboot2" -# ) - -# #[============================================================================[ -# # The Exception handling Library -# #]============================================================================] - -# target_sources("_exception" PRIVATE -# "src/exception_handling/assert.cpp" -# "src/exception_handling/abort.cpp" -# "src/exception_handling/panic.cpp" -# "src/exception_handling/pure_virtual.cpp" -# ) - -# #[============================================================================[ -# # The Context switching Library -# #]============================================================================] - -# target_sources("_context" PRIVATE -# "src/context_switching/segment_descriptor_table/access_byte.cpp" -# "src/context_switching/segment_descriptor_table/gdt_flags.cpp" -# "src/context_switching/segment_descriptor_table/global_descriptor_table_pointer.cpp" -# "src/context_switching/segment_descriptor_table/global_descriptor_table.cpp" -# "src/context_switching/segment_descriptor_table/segment_descriptor_base.cpp" -# "src/context_switching/segment_descriptor_table/segment_descriptor_extension.cpp" -# "src/context_switching/main.cpp" -# "src/context_switching/syscall/main.cpp" -# "src/context_switching/syscall/syscall_enable.cpp" -# "src/context_switching/syscall/syscall_handler.cpp" -# "src/context_switching/interrupt_descriptor_table/gate_descriptor.cpp" -# "src/context_switching/interrupt_descriptor_table/idt_flags.cpp" -# "src/context_switching/interrupt_descriptor_table/interrupt_descriptor_table_pointer.cpp" -# "src/context_switching/interrupt_descriptor_table/interrupt_descriptor_table.cpp" -# "src/context_switching/interrupt_descriptor_table/ist_offset.cpp" -# "src/context_switching/interrupt_descriptor_table/segment_selector.cpp" -# ) - -# target_link_libraries("_context" PUBLIC -# "libs::kstd" -# ) - -# #[============================================================================[ -# # The Interrupt Handlers -# #]============================================================================] - -# target_sources("_interrupt_handling" PRIVATE -# "src/interrupt_handling/generic_interrupt_handler.cpp" -# ) - -# #[============================================================================[ -# # The User code -# #]============================================================================] - -# target_sources("_context" PRIVATE -# "src/user/main.cpp" -# ) - -# #[============================================================================[ -# # The Bootable ISO Image -# #]============================================================================] - -# find_package("grub-mkrescue") - -# if(grub-mkrescue_FOUND) -# file(GENERATE -# OUTPUT "isofs/boot/grub/grub.cfg" -# INPUT "support/grub.cfg.in" -# ) - -# add_custom_target("bootable-iso" -# COMMAND "${GRUB_MKRESCUE_EXE}" -# "-o" -# "${PROJECT_BINARY_DIR}/teachos-$.iso" -# "${CMAKE_CURRENT_BINARY_DIR}/isofs" -# "$" -# "2>/dev/null" -# DEPENDS -# "$" -# "isofs/boot/grub/grub.cfg" -# BYPRODUCTS "${PROJECT_BINARY_DIR}/teachos-$.iso" -# COMMENT "Creating bootable ISO image" -# ) -# endif() +set(KERNEL_LINKER_SCRIPT + "${CMAKE_CURRENT_SOURCE_DIR}/scripts/kernel.ld" + PARENT_SCOPE +) \ No newline at end of file diff --git a/arch/x86_64/kapi/io.cpp b/arch/x86_64/kapi/io.cpp new file mode 100644 index 0000000..eab6473 --- /dev/null +++ b/arch/x86_64/kapi/io.cpp @@ -0,0 +1,36 @@ +#include "kapi/io.hpp" + +#include "x86_64/vga/text.hpp" + +namespace teachos::io +{ + + auto init() -> void + { + x86_64::vga::text::clear(); + x86_64::vga::text::cursor(false); + } + + auto print(std::string_view text) -> void + { + x86_64::vga::text::write(text, x86_64::vga::text::common_attributes::green_on_black); + } + + auto println(std::string_view text) -> void + { + x86_64::vga::text::write(text, x86_64::vga::text::common_attributes::green_on_black); + x86_64::vga::text::newline(); + } + + auto print_error(std::string_view text) -> void + { + x86_64::vga::text::write(text, x86_64::vga::text::common_attributes::red_on_black); + } + + auto println_error(std::string_view text) -> void + { + x86_64::vga::text::write(text, x86_64::vga::text::common_attributes::red_on_black); + x86_64::vga::text::newline(); + } + +} // namespace teachos::io diff --git a/arch/x86_64/kapi/memory.cpp b/arch/x86_64/kapi/memory.cpp new file mode 100644 index 0000000..d1c1f03 --- /dev/null +++ b/arch/x86_64/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/kapi/system.cpp b/arch/x86_64/kapi/system.cpp new file mode 100644 index 0000000..2d4c3fe --- /dev/null +++ b/arch/x86_64/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 diff --git a/arch/x86_64/src/io.cpp b/arch/x86_64/src/io.cpp deleted file mode 100644 index eab6473..0000000 --- a/arch/x86_64/src/io.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include "kapi/io.hpp" - -#include "x86_64/vga/text.hpp" - -namespace teachos::io -{ - - auto init() -> void - { - x86_64::vga::text::clear(); - x86_64::vga::text::cursor(false); - } - - auto print(std::string_view text) -> void - { - x86_64::vga::text::write(text, x86_64::vga::text::common_attributes::green_on_black); - } - - auto println(std::string_view text) -> void - { - x86_64::vga::text::write(text, x86_64::vga::text::common_attributes::green_on_black); - x86_64::vga::text::newline(); - } - - auto print_error(std::string_view text) -> void - { - x86_64::vga::text::write(text, x86_64::vga::text::common_attributes::red_on_black); - } - - auto println_error(std::string_view text) -> void - { - x86_64::vga::text::write(text, x86_64::vga::text::common_attributes::red_on_black); - x86_64::vga::text::newline(); - } - -} // namespace teachos::io diff --git a/arch/x86_64/src/memory.cpp b/arch/x86_64/src/memory.cpp deleted file mode 100644 index d1c1f03..0000000 --- a/arch/x86_64/src/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/src/system.cpp b/arch/x86_64/src/system.cpp deleted file mode 100644 index 2d4c3fe..0000000 --- a/arch/x86_64/src/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 -- cgit v1.2.3