diff options
22 files changed, 148 insertions, 117 deletions
diff --git a/.vscode/launch.json b/.vscode/launch.json index 81bf456..b9d0a1e 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -5,7 +5,7 @@ "name": "(gdb) QEMU", "type": "cppdbg", "request": "launch", - "program": "${workspaceFolder}/build/Debug/bin/kernel", + "program": "${workspaceFolder}/build/Debug/bin/_kernel", "MIMode": "gdb", "miDebuggerServerAddress": "localhost:1234", "cwd": "${workspaceFolder}", @@ -18,7 +18,7 @@ }, { "description": "Load file", - "text": "-file-exec-and-symbols ${workspaceFolder}/build/Debug/bin/kernel" + "text": "-file-exec-and-symbols ${workspaceFolder}/build/Debug/bin/_kernel" }, { "description": "Set breakpoint on _start", diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 326fc8d..15b4016 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -7,8 +7,64 @@ project("kernel" LANGUAGES ASM C CXX ) +#[============================================================================[ +# Global Build System Configuration +#]============================================================================] + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin") set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib") +set(CMAKE_INTERPROCEDURAL_OPTIMIZATION YES) + +#[============================================================================[ +# Global Compiler Configuration +#]============================================================================] + +add_compile_options( + "$<$<CXX_COMPILER_ID:GNU>:-Wall>" + "$<$<CXX_COMPILER_ID:GNU>:-Wextra>" + "$<$<CXX_COMPILER_ID:GNU>:-Werror>" + "$<$<CXX_COMPILER_ID:GNU>:-pedantic-errors>" +) + +#[============================================================================[ +# Global Directories +#]============================================================================] + +include_directories( + "include" + "arch/${CMAKE_SYSTEM_PROCESSOR}/include" +) + +#[============================================================================[ +# The Bootstrap Library +#]============================================================================] + +add_library("_boot" OBJECT) +add_library("teachos::boot" ALIAS "_boot") + +#[============================================================================[ +# The Video Library +#]============================================================================] + +add_library("_video" OBJECT) +add_library("teachos::video" ALIAS "_video") + +#[============================================================================[ +# The Kernel +#]============================================================================] + +add_executable("_kernel" + "src/kernel/main.cpp" +) +add_executable("teachos::kernel" ALIAS "_kernel") + +target_link_libraries("_kernel" PRIVATE + "teachos::boot" + "teachos::video" +) + +#[============================================================================[ +# Platform Specific Components +#]============================================================================] -add_subdirectory("boot") -add_subdirectory("kernel") +add_subdirectory("arch/${CMAKE_SYSTEM_PROCESSOR}") diff --git a/source/kernel/arch/x86_64/CMakeLists.txt b/source/arch/x86_64/CMakeLists.txt index ffce50c..f917cd0 100644 --- a/source/kernel/arch/x86_64/CMakeLists.txt +++ b/source/arch/x86_64/CMakeLists.txt @@ -1,35 +1,43 @@ #[============================================================================[ -# x86_64 specific configuration for the kernel image. +# The Kernel Library #]============================================================================] -set(TEACHOS_KERNEL_LINKER_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/kern.ld") +set(TEACHOS_KERNEL_LINKER_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/scripts/kernel.ld") mark_as_advanced(TEACHOS_KERNEL_LINKER_SCRIPT) -target_sources("kernel" PRIVATE - "src/entry.cpp" - "src/vga.cpp" +target_sources("_kernel" PRIVATE + "src/kernel/main.cpp" ) -target_include_directories("kernel" PRIVATE - "include" +target_link_options("_kernel" PRIVATE + "-T${TEACHOS_KERNEL_LINKER_SCRIPT}" ) -target_link_options("kernel" PRIVATE - "-T${TEACHOS_KERNEL_LINKER_SCRIPT}" +set_target_properties("_kernel" PROPERTIES + LINK_DEPENDS "${TEACHOS_KERNEL_LINKER_SCRIPT}" ) -target_link_libraries("kernel" PRIVATE - "-Wl,--whole-archive" - "teachos::boot" - "-Wl,--no-whole-archive" +#[============================================================================[ +# The Bootstrap Library +#]============================================================================] + +target_sources("_boot" PRIVATE + "src/boot/boot.s" + "src/boot/crti.s" + "src/boot/crtn.s" + "src/boot/multiboot.s" ) -set_target_properties("kernel" PROPERTIES - LINK_DEPENDS "${TEACHOS_KERNEL_LINKER_SCRIPT}" +#[============================================================================[ +# The Video Library +#]============================================================================] + +target_sources("_video" PRIVATE + "src/video/vga/text.cpp" ) #[============================================================================[ -# Bootable ISO image generation +# The Bootable ISO Image #]============================================================================] find_package("grub-mkrescue") @@ -47,12 +55,12 @@ if(grub-mkrescue_FOUND) "-o" "${ISO_FILE}" "${CMAKE_CURRENT_BINARY_DIR}/isofs" - "$<TARGET_FILE:kernel>" + "$<TARGET_FILE:teachos::kernel>" "2>/dev/null" DEPENDS - "$<TARGET_FILE:kernel>" + "$<TARGET_FILE:teachos::kernel>" "isofs/boot/grub/grub.cfg" BYPRODUCTS "${ISO_FILE}" COMMENT "Creating bootable ISO image" ) -endif()
\ No newline at end of file +endif() diff --git a/source/boot/arch/x86_64/include/boot/pointers.hpp b/source/arch/x86_64/include/arch/boot/pointers.hpp index 4ef0258..052b115 100644 --- a/source/boot/arch/x86_64/include/boot/pointers.hpp +++ b/source/arch/x86_64/include/arch/boot/pointers.hpp @@ -3,10 +3,10 @@ #include <cstddef> -namespace teachos::boot::pointers +namespace teachos::arch::boot { extern "C" std::byte const multiboot_information_pointer; extern "C" std::byte * vga_buffer_pointer; -} // namespace teachos::boot +} // namespace teachos::arch::boot #endif
\ No newline at end of file diff --git a/source/arch/x86_64/include/arch/kernel/main.hpp b/source/arch/x86_64/include/arch/kernel/main.hpp new file mode 100644 index 0000000..6961594 --- /dev/null +++ b/source/arch/x86_64/include/arch/kernel/main.hpp @@ -0,0 +1,11 @@ +#ifndef TEACHOS_ARCH_X86_64_KERNEL_MAIN_HPP +#define TEACHOS_ARCH_X86_64_KERNEL_MAIN_HPP + +#include <cstddef> + +namespace teachos::arch::kernel +{ + auto main() -> void; +} + +#endif
\ No newline at end of file diff --git a/source/arch/x86_64/include/arch/video/vga/text.hpp b/source/arch/x86_64/include/arch/video/vga/text.hpp new file mode 100644 index 0000000..04b74d1 --- /dev/null +++ b/source/arch/x86_64/include/arch/video/vga/text.hpp @@ -0,0 +1,12 @@ +#ifndef TEACHOS_ARCH_X86_64_VIDEO_VGA_TEXT_HPP +#define TEACHOS_ARCH_X86_64_VIDEO_VGA_TEXT_HPP + +#include <cstddef> +#include <string_view> + +namespace teachos::arch::video::vga::text +{ + auto write(std::string_view text, std::byte color) -> void; +} + +#endif
\ No newline at end of file diff --git a/source/kernel/arch/x86_64/kern.ld b/source/arch/x86_64/scripts/kernel.ld index 78cc363..0817081 100644 --- a/source/kernel/arch/x86_64/kern.ld +++ b/source/arch/x86_64/scripts/kernel.ld @@ -74,9 +74,9 @@ SECTIONS * Make sure that the crt code is wrapped around the compiler generated * initialization code. */ - KEEP(*:crti.s.obj(.init)) + KEEP(*crti.s.obj(.init)) KEEP(*(EXCLUDE_FILE (*crti.s.obj crtn.s.obj) .init)) - KEEP(*:crtn.s.obj(.init)) + KEEP(*crtn.s.obj(.init)) } :text .fini ALIGN(4K) : AT(ADDR (.fini) - TEACHOS_HIGH) @@ -85,9 +85,9 @@ SECTIONS * Make sure that the crt code is wrapped around the compiler generated * finalizer code. */ - KEEP(*:crti.s.obj(.fini)) + KEEP(*crti.s.obj(.fini)) KEEP(*(EXCLUDE_FILE (*crti.s.obj crtn.s.obj).fini)) - KEEP(*:crtn.s.obj(.fini)) + KEEP(*crtn.s.obj(.fini)) } .text ALIGN(4K) : AT(ADDR (.text) - TEACHOS_HIGH) diff --git a/source/boot/arch/x86_64/src/boot.s b/source/arch/x86_64/src/boot/boot.s index 45f261e..45f261e 100644 --- a/source/boot/arch/x86_64/src/boot.s +++ b/source/arch/x86_64/src/boot/boot.s diff --git a/source/boot/arch/x86_64/src/crti.s b/source/arch/x86_64/src/boot/crti.s index 26878fe..26878fe 100644 --- a/source/boot/arch/x86_64/src/crti.s +++ b/source/arch/x86_64/src/boot/crti.s diff --git a/source/boot/arch/x86_64/src/crtn.s b/source/arch/x86_64/src/boot/crtn.s index 06fb7ce..06fb7ce 100644 --- a/source/boot/arch/x86_64/src/crtn.s +++ b/source/arch/x86_64/src/boot/crtn.s diff --git a/source/boot/arch/x86_64/src/multiboot.s b/source/arch/x86_64/src/boot/multiboot.s index 7ccca56..7ccca56 100644 --- a/source/boot/arch/x86_64/src/multiboot.s +++ b/source/arch/x86_64/src/boot/multiboot.s diff --git a/source/arch/x86_64/src/kernel/main.cpp b/source/arch/x86_64/src/kernel/main.cpp new file mode 100644 index 0000000..9ea756a --- /dev/null +++ b/source/arch/x86_64/src/kernel/main.cpp @@ -0,0 +1,15 @@ +#include "arch/kernel/main.hpp" + +#include "arch/video/vga/text.hpp" + +namespace teachos::arch::kernel +{ + auto main() -> void + { + video::vga::text::write("TeachOS is starting up...", static_cast<std::byte>(0x4f)); + while (true) + { + asm volatile("hlt"); + } + } +} // namespace teachos::arch::kernel diff --git a/source/kernel/arch/x86_64/src/vga.cpp b/source/arch/x86_64/src/video/vga/text.cpp index efa2848..11e3b1a 100644 --- a/source/kernel/arch/x86_64/src/vga.cpp +++ b/source/arch/x86_64/src/video/vga/text.cpp @@ -1,21 +1,21 @@ -#include "kernel/vga.hpp" +#include "arch/video/vga/text.hpp" -#include "boot/asm_pointer.hpp" -#include "boot/pointers.hpp" +#include "arch/boot/pointers.hpp" +#include "memory/asm_pointer.hpp" #include <algorithm> #include <string_view> -namespace teachos::kernel::vga +namespace teachos::arch::video::vga::text { namespace { - auto constinit text_buffer_pointer = boot::asm_pointer{boot::pointers::vga_buffer_pointer}; + auto constinit text_buffer = teachos::boot::asm_pointer{boot::vga_buffer_pointer}; auto write(char character, std::byte color) -> void { - auto & p = *text_buffer_pointer; + auto & p = *text_buffer; (*p++) = static_cast<std::byte>(character); (*p++) = color; }; @@ -26,4 +26,4 @@ namespace teachos::kernel::vga std::ranges::for_each(text, [&](auto character) { write(character, color); }); } -} // namespace teachos::kernel::vga
\ No newline at end of file +} // namespace teachos::arch::video::vga::text
\ No newline at end of file diff --git a/source/arch/x86_64/support/grub.cfg.in b/source/arch/x86_64/support/grub.cfg.in new file mode 100644 index 0000000..86674dd --- /dev/null +++ b/source/arch/x86_64/support/grub.cfg.in @@ -0,0 +1,7 @@ +timeout=2 +default=0 + +menuentry "TeachOS" { + multiboot2 /$<TARGET_FILE_NAME:teachos::kernel> + boot +}
\ No newline at end of file diff --git a/source/boot/CMakeLists.txt b/source/boot/CMakeLists.txt deleted file mode 100644 index 66f1d65..0000000 --- a/source/boot/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -#[============================================================================[ -# Configure the generic settings for the bootstrapping library. -# -# All the settings (e.g. include paths, linker flags, etc.) applied in this -# directly, are expected to be platform independent. -#]============================================================================] - -add_library("_boot" STATIC) -add_library("teachos::boot" ALIAS "_boot") - -target_include_directories("_boot" PUBLIC - "include" -) - -#[============================================================================[ -# Apply the platform dependent settings to the bootstrapping library. -#]============================================================================] - -add_subdirectory("arch/${CMAKE_SYSTEM_PROCESSOR}")
\ No newline at end of file diff --git a/source/boot/arch/x86_64/CMakeLists.txt b/source/boot/arch/x86_64/CMakeLists.txt deleted file mode 100644 index 14b0610..0000000 --- a/source/boot/arch/x86_64/CMakeLists.txt +++ /dev/null @@ -1,10 +0,0 @@ -target_sources("_boot" PRIVATE - "src/boot.s" - "src/crti.s" - "src/crtn.s" - "src/multiboot.s" -) - -target_include_directories("_boot" PUBLIC - "include" -)
\ No newline at end of file diff --git a/source/boot/include/boot/asm_pointer.hpp b/source/include/memory/asm_pointer.hpp index ec7141e..ec7141e 100644 --- a/source/boot/include/boot/asm_pointer.hpp +++ b/source/include/memory/asm_pointer.hpp diff --git a/source/kernel/CMakeLists.txt b/source/kernel/CMakeLists.txt deleted file mode 100644 index bc60f6c..0000000 --- a/source/kernel/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -#[============================================================================[ -# Configure the generic settings for the kernel image. -# -# All the settings (e.g. include paths, linker flags, etc.) applied in this -# directly, are expected to be platform independent. -#]============================================================================] - -add_executable("kernel") - -target_compile_options("kernel" PRIVATE - "$<$<CXX_COMPILER_ID:GNU>:-Wall>" - "$<$<CXX_COMPILER_ID:GNU>:-Wextra>" - "$<$<CXX_COMPILER_ID:GNU>:-Werror>" - "$<$<CXX_COMPILER_ID:GNU>:-pedantic-errors>" -) - -set_target_properties("kernel" PROPERTIES - INTERPROCEDURAL_OPTIMIZATION YES -) - -#[============================================================================[ -# Apply the platform dependent settings to the kernel image. -#]============================================================================] - -add_subdirectory("arch/${CMAKE_SYSTEM_PROCESSOR}")
\ No newline at end of file diff --git a/source/kernel/arch/x86_64/include/kernel/vga.hpp b/source/kernel/arch/x86_64/include/kernel/vga.hpp deleted file mode 100644 index ee5a808..0000000 --- a/source/kernel/arch/x86_64/include/kernel/vga.hpp +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef TEACHOS_KERNEL_VGA_HPP -#define TEACHOS_KERNEL_VGA_HPP - -#include <string_view> - -namespace teachos::kernel::vga -{ - auto write(std::string_view text, std::byte color) -> void; -} - -#endif
\ No newline at end of file diff --git a/source/kernel/arch/x86_64/src/entry.cpp b/source/kernel/arch/x86_64/src/entry.cpp deleted file mode 100644 index fd9d9d0..0000000 --- a/source/kernel/arch/x86_64/src/entry.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include "kernel/vga.hpp" - -namespace teachos::kernel -{ - extern "C" auto kernel_main() -> void - { - vga::write("TeachOS is starting up...", static_cast<std::byte>(0x4f)); - } -} // namespace teachos diff --git a/source/kernel/arch/x86_64/support/grub.cfg.in b/source/kernel/arch/x86_64/support/grub.cfg.in deleted file mode 100644 index 49f19ce..0000000 --- a/source/kernel/arch/x86_64/support/grub.cfg.in +++ /dev/null @@ -1,7 +0,0 @@ -timeout=2 -default=0 - -menuentry "TeachOS" { - multiboot2 /$<TARGET_FILE_NAME:kernel> - boot -}
\ No newline at end of file diff --git a/source/src/kernel/main.cpp b/source/src/kernel/main.cpp new file mode 100644 index 0000000..07a9955 --- /dev/null +++ b/source/src/kernel/main.cpp @@ -0,0 +1,3 @@ +#include "arch/kernel/main.hpp" + +extern "C" auto kernel_main() -> void { teachos::arch::kernel::main(); }
\ No newline at end of file |
