From 6ffe96d1e3f0289c2070e050cf8e1a30288e6d91 Mon Sep 17 00:00:00 2001 From: Alexey Gavrilov Date: Fri, 27 Mar 2026 14:03:55 +0700 Subject: Cmake build generator support: build stage Multi-target architecture implementation: each root source code directory presents the one *INTERFACE* target to it's subdirectory subtargets that link only as *STATIC* library. For instance, *arch* directory presents *Architecture* target then *Architecture* target has *CPUID*, *IO*, *PORT* and etc. dependencies Exact order of linking targets is: boot.o CRTIBUNDLE CRTNBUNDLE. Sequence destruction cause to UB. Please to pay attention to this. TODO - Debug information - Build type - Toolchain file - Image creation - Build by WinGW compiler on Windows platform (optional) Signed-off-by: Alexey Gavrilov --- kernel/CMakeLists.txt | 14 ++++++++++++++ kernel/boot.s | 16 ---------------- kernel/details/CMakeLists.txt | 8 ++++++++ kernel/kernel.c | 19 ------------------- kernel/kernel.cpp | 19 +++++++++++++++++++ 5 files changed, 41 insertions(+), 35 deletions(-) create mode 100644 kernel/CMakeLists.txt delete mode 100644 kernel/boot.s create mode 100644 kernel/details/CMakeLists.txt delete mode 100644 kernel/kernel.c create mode 100644 kernel/kernel.cpp (limited to 'kernel') diff --git a/kernel/CMakeLists.txt b/kernel/CMakeLists.txt new file mode 100644 index 0000000..cd249d0 --- /dev/null +++ b/kernel/CMakeLists.txt @@ -0,0 +1,14 @@ +target_link_options(CXX_LINKER_REQUIREMENTS INTERFACE + LINKER:-T${CMAKE_CURRENT_LIST_DIR}/linker.ld +) + +add_library(Kernel INTERFACE) + +add_library(Main STATIC) +target_sources(Main PRIVATE + ${CMAKE_CURRENT_LIST_DIR}/kernel.cpp +) +target_link_libraries(Main PUBLIC CXX_COMPILER_REQUIREMENTS Architecture Include) +target_link_libraries(Kernel INTERFACE Main) + +add_subdirectory(details) diff --git a/kernel/boot.s b/kernel/boot.s deleted file mode 100644 index 11175af..0000000 --- a/kernel/boot.s +++ /dev/null @@ -1,16 +0,0 @@ -section .text -extern main, _estack, _init -global _start:function -_start: - ; Stack setup - mov eax, _estack - ; Align stack to odd address - and eax, 0xFFFFFFFE - mov esp, eax - - call _init - call main - cli -.hang: hlt - jmp .hang -; .end: diff --git a/kernel/details/CMakeLists.txt b/kernel/details/CMakeLists.txt new file mode 100644 index 0000000..881d360 --- /dev/null +++ b/kernel/details/CMakeLists.txt @@ -0,0 +1,8 @@ +target_sources(CPUID + PUBLIC + FILE_SET HEADERS + BASE_DIRS + ${CMAKE_CURRENT_LIST_DIR} + FILES + ${CMAKE_CURRENT_LIST_DIR}/Platform.h +) diff --git a/kernel/kernel.c b/kernel/kernel.c deleted file mode 100644 index c280755..0000000 --- a/kernel/kernel.c +++ /dev/null @@ -1,19 +0,0 @@ - -#include "../arch/SecondaryInit.h" -#include "../arch/x86/ic/Pic.h" - - -void empty() {}; - -void main() -{ - SecondaryInitialization init; - - init.processorInitialize(); - init.devicesInitialize(); - - out::display << "Hello, World!\n"; - - asm("sti"); - while(true); -}; diff --git a/kernel/kernel.cpp b/kernel/kernel.cpp new file mode 100644 index 0000000..c280755 --- /dev/null +++ b/kernel/kernel.cpp @@ -0,0 +1,19 @@ + +#include "../arch/SecondaryInit.h" +#include "../arch/x86/ic/Pic.h" + + +void empty() {}; + +void main() +{ + SecondaryInitialization init; + + init.processorInitialize(); + init.devicesInitialize(); + + out::display << "Hello, World!\n"; + + asm("sti"); + while(true); +}; -- cgit v1.2.3