aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt8
-rw-r--r--arch/CMakeLists.txt10
-rw-r--r--arch/x86_64/CMakeLists.txt314
-rw-r--r--arch/x86_64/src/boot/boot.s2
-rw-r--r--arch/x86_64/src/io.cpp22
-rw-r--r--arch/x86_64/src/memory.cpp62
-rw-r--r--arch/x86_64/src/system.cpp12
-rw-r--r--kern/CMakeLists.txt2
-rw-r--r--libs/kstd/CMakeLists.txt7
-rw-r--r--libs/multiboot2/CMakeLists.txt7
10 files changed, 285 insertions, 161 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e10da55..c08753b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -25,16 +25,16 @@ set(CMAKE_CXX_EXTENSIONS NO)
# Global Build System Configuration
#]============================================================================]
+add_executable("kernel")
+
add_subdirectory("libs")
add_subdirectory("kern")
add_subdirectory("arch")
-add_executable("kernel")
-
target_link_libraries("kernel" PRIVATE
"kern"
- "arch::all"
- # "arch-${CMAKE_SYSTEM_PROCESSOR}"
+ "arch::any"
+ "arch::${CMAKE_SYSTEM_PROCESSOR}"
)
# #[============================================================================[
diff --git a/arch/CMakeLists.txt b/arch/CMakeLists.txt
index 3bdc3c2..c7b2c15 100644
--- a/arch/CMakeLists.txt
+++ b/arch/CMakeLists.txt
@@ -1,7 +1,7 @@
-add_library("arch-all" INTERFACE)
-add_library("arch::all" ALIAS "arch-all")
+add_library("arch-any" INTERFACE)
+add_library("arch::any" ALIAS "arch-any")
-target_sources("arch-all" INTERFACE
+target_sources("arch-any" INTERFACE
FILE_SET HEADERS
BASE_DIRS "include"
FILES
@@ -10,8 +10,8 @@ target_sources("arch-all" INTERFACE
"include/arch/system.hpp"
)
-target_include_directories("arch-all" INTERFACE
+target_include_directories("arch-any" INTERFACE
"include"
)
-# add_subdirectory("${CMAKE_SYSTEM_PROCESSOR}")
+add_subdirectory("${CMAKE_SYSTEM_PROCESSOR}")
diff --git a/arch/x86_64/CMakeLists.txt b/arch/x86_64/CMakeLists.txt
index c8ff216..19bc78c 100644
--- a/arch/x86_64/CMakeLists.txt
+++ b/arch/x86_64/CMakeLists.txt
@@ -1,156 +1,198 @@
-#[============================================================================[
-# 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}"
-)
+add_library("arch-x86_64" OBJECT)
+add_library("arch::x86_64" ALIAS "arch-x86_64")
-#[============================================================================[
-# The Bootstrap Library
-#]============================================================================]
-
-target_sources("_boot" PRIVATE
- "src/boot/boot.s"
- "src/boot/crti.s"
- "src/boot/crtn.s"
- "src/boot/multiboot.s"
+target_include_directories("arch-x86_64" PUBLIC
+ "include"
)
-#[============================================================================[
-# The Video Library
-#]============================================================================]
+target_link_libraries("arch-x86_64" PUBLIC
+ "kern"
-target_sources("_video" PRIVATE
- "src/video/vga/text.cpp"
+ "libs::multiboot2"
)
-#[============================================================================[
-# 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_options("arch-x86_64" PUBLIC
+ "-T${CMAKE_CURRENT_SOURCE_DIR}/scripts/kernel.ld"
)
-target_link_libraries("_memory" PUBLIC
- "libs::kstd"
- "libs::multiboot2"
+set_target_properties("arch-x86_64" PROPERTIES
+ LINK_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/scripts/kernel.ld"
)
#[============================================================================[
-# The Exception handling Library
+# arch::any Implementation
#]============================================================================]
-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"
+target_sources("arch-x86_64" PRIVATE
+ "src/io.cpp"
+ "src/memory.cpp"
+ "src/system.cpp"
)
#[============================================================================[
-# The Context switching Library
+# Bootstrap Code
#]============================================================================]
-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_sources("arch-x86_64" PRIVATE
+ "src/boot/boot.s"
+ "src/boot/crti.s"
+ "src/boot/crtn.s"
+ "src/boot/multiboot.s"
)
-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-$<CONFIGURATION>.iso"
- "${CMAKE_CURRENT_BINARY_DIR}/isofs"
- "$<TARGET_FILE:teachos::kernel>"
- "2>/dev/null"
- DEPENDS
- "$<TARGET_FILE:teachos::kernel>"
- "isofs/boot/grub/grub.cfg"
- BYPRODUCTS "${PROJECT_BINARY_DIR}/teachos-$<CONFIGURATION>.iso"
- COMMENT "Creating bootable ISO image"
- )
-endif()
+# #[============================================================================[
+# # 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-$<CONFIGURATION>.iso"
+# "${CMAKE_CURRENT_BINARY_DIR}/isofs"
+# "$<TARGET_FILE:teachos::kernel>"
+# "2>/dev/null"
+# DEPENDS
+# "$<TARGET_FILE:teachos::kernel>"
+# "isofs/boot/grub/grub.cfg"
+# BYPRODUCTS "${PROJECT_BINARY_DIR}/teachos-$<CONFIGURATION>.iso"
+# COMMENT "Creating bootable ISO image"
+# )
+# endif()
diff --git a/arch/x86_64/src/boot/boot.s b/arch/x86_64/src/boot/boot.s
index 7932045..5488073 100644
--- a/arch/x86_64/src/boot/boot.s
+++ b/arch/x86_64/src/boot/boot.s
@@ -364,5 +364,5 @@ _transition_to_long_mode:
call _init
- call kernel_main
+ call main
call halt
diff --git a/arch/x86_64/src/io.cpp b/arch/x86_64/src/io.cpp
new file mode 100644
index 0000000..8808dbb
--- /dev/null
+++ b/arch/x86_64/src/io.cpp
@@ -0,0 +1,22 @@
+namespace teachos::arch::io
+{
+
+ // using x86_64::vga::text_mode::attributes;
+ // using x86_64::vga::text_mode::color;
+
+ // namespace
+ // {
+ // auto constexpr error_attributes =
+ // attributes{.foreground = color::light_gray, .bright = true, .background = color::red, .blink = true};
+ // } // namespace
+
+ auto init() -> void
+ {
+ // kernel::set_print_handler([](auto text) { return x86_64::vga::text_mode::print(text); });
+ // kernel::set_println_handler([](auto text) { return x86_64::vga::text_mode::println(text); });
+ // kernel::set_print_error_handler([](auto text) { return x86_64::vga::text_mode::print(text, error_attributes); });
+ // kernel::set_println_error_handler(
+ // [](auto text) { return x86_64::vga::text_mode::println(text, error_attributes); });
+ }
+
+} // namespace teachos::arch::io
diff --git a/arch/x86_64/src/memory.cpp b/arch/x86_64/src/memory.cpp
new file mode 100644
index 0000000..245d7bd
--- /dev/null
+++ b/arch/x86_64/src/memory.cpp
@@ -0,0 +1,62 @@
+#include "arch/memory.hpp"
+
+// #include "noarch/error.hpp"
+// #include "noarch/print.hpp"
+// #include "x86_64/bootstrap/mutiboot.hpp"
+// #include "x86_64/memory/frame_allocator.hpp"
+// #include "x86_64/memory/mbi_frame_allocator.hpp"
+
+// #include <elf/constants.hpp>
+// #include <elf/section_header.hpp>
+// #include <elf/section_header_table.hpp>
+// #include <multiboot2/information.hpp>
+
+namespace teachos::arch::memory
+{
+
+ // namespace
+ // {
+ // /**
+ // * @brief Remap the kernel according to the ELF information.
+ // *
+ // * After initial bootup, a basic identity mapping of the lower 1GiB is set up. This mapping allows execution
+ // from,
+ // * as well as read and write access to, the mapped memory. In order to protect the kernel, remap it according to
+ // the
+ // * information supplied by the ELF file. This means remapping code sections as read-only and data sections as
+ // * no-execute (and read only for .rodata).
+ // *
+ // * @param sections Information about the sections in the loaded kernel binary.
+ // * @param allocator The frame allocator used to create new page mappings.
+ // */
+ // auto remap_kernel(elf::section_header_table const & sections, x86_64::memory::frame_allocator & allocator) ->
+ // void
+ // {
+ // static_cast<void>(sections);
+ // static_cast<void>(allocator);
+ // }
+ // } // namespace
+
+ auto init() -> void
+ {
+ // kernel::println("Initializing memory");
+
+ // if (!x86_64::bootstrap::multiboot_information_pointer->has<multiboot2::memory_map>())
+ // {
+ // kernel::panic("Received no memory map from the boot loader!");
+ // }
+
+ // if (!x86_64::bootstrap::multiboot_information_pointer->has<multiboot2::elf_symbols>())
+ // {
+ // kernel::panic("Received no ELF symbol information from the boot loader!");
+ // }
+
+ // auto memory_map = x86_64::bootstrap::multiboot_information_pointer->memory_map();
+ // auto elf_symbols = x86_64::bootstrap::multiboot_information_pointer->elf_symbols();
+ // auto section_header_table = elf::section_header_table{elf_symbols.data(), elf::file_class::bits_64};
+ // auto allocator = x86_64::memory::mbi_frame_allocator{memory_map, section_header_table};
+
+ // remap_kernel(section_header_table, allocator);
+ }
+
+} // namespace teachos::arch::memory
diff --git a/arch/x86_64/src/system.cpp b/arch/x86_64/src/system.cpp
new file mode 100644
index 0000000..60ebf0e
--- /dev/null
+++ b/arch/x86_64/src/system.cpp
@@ -0,0 +1,12 @@
+#include "arch/system.hpp"
+
+namespace teachos::arch::system
+{
+
+ auto halt() -> void
+ {
+ asm volatile("1: hlt\njmp 1b");
+ __builtin_unreachable();
+ }
+
+} // namespace teachos::arch::system
diff --git a/kern/CMakeLists.txt b/kern/CMakeLists.txt
index b2c7e2f..9bfe9e8 100644
--- a/kern/CMakeLists.txt
+++ b/kern/CMakeLists.txt
@@ -10,7 +10,7 @@ target_include_directories("kern" PUBLIC
)
target_link_libraries("kern" PUBLIC
- "arch::all"
+ "arch::any"
"gcc"
)
diff --git a/libs/kstd/CMakeLists.txt b/libs/kstd/CMakeLists.txt
index 06083f3..a29fac8 100644
--- a/libs/kstd/CMakeLists.txt
+++ b/libs/kstd/CMakeLists.txt
@@ -1,10 +1,3 @@
-cmake_minimum_required(VERSION "3.27")
-
-project("kstd"
- LANGUAGES CXX
- VERSION "1.0.0"
-)
-
add_library("kstd" STATIC)
add_library("libs::kstd" ALIAS "kstd")
diff --git a/libs/multiboot2/CMakeLists.txt b/libs/multiboot2/CMakeLists.txt
index 386a127..7b9e58a 100644
--- a/libs/multiboot2/CMakeLists.txt
+++ b/libs/multiboot2/CMakeLists.txt
@@ -1,10 +1,3 @@
-cmake_minimum_required(VERSION "3.27")
-
-project("multiboot2"
- LANGUAGES CXX
- VERSION "1.0.0"
-)
-
add_library("multiboot2" INTERFACE)
add_library("libs::multiboot2" ALIAS "multiboot2")