mirror of
https://github.com/johndoe6345789/MetalOS.git
synced 2026-04-24 13:45:02 +00:00
Merge branch 'main' into copilot/update-kernel-folder-files
This commit is contained in:
@@ -1,86 +1,79 @@
|
||||
# MetalOS Kernel CMakeLists
|
||||
# MetalOS Kernel CMakeLists.txt
|
||||
# Builds minimal kernel binary
|
||||
|
||||
# Include directories
|
||||
include_directories(include)
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(MetalOS_Kernel C ASM)
|
||||
|
||||
# Source files
|
||||
set(KERNEL_C_SOURCES
|
||||
set(KERNEL_SOURCES
|
||||
src/main.c
|
||||
src/gdt.c
|
||||
src/interrupts.c
|
||||
src/memory.c
|
||||
src/pci.c
|
||||
src/timer.c
|
||||
src/smp.c
|
||||
src/apic.c
|
||||
src/spinlock.c
|
||||
)
|
||||
|
||||
set(KERNEL_ASM_SOURCES
|
||||
src/gdt_flush.asm
|
||||
src/interrupts_asm.asm
|
||||
src/ap_trampoline.asm
|
||||
# Find all source files in subdirectories
|
||||
file(GLOB_RECURSE CORE_SOURCES "src/core/*.c")
|
||||
file(GLOB_RECURSE HAL_SOURCES "src/hal/*.c")
|
||||
file(GLOB_RECURSE DRIVER_SOURCES "src/drivers/*.c")
|
||||
file(GLOB_RECURSE SYSCALL_SOURCES "src/syscall/*.c")
|
||||
|
||||
list(APPEND KERNEL_SOURCES
|
||||
${CORE_SOURCES}
|
||||
${HAL_SOURCES}
|
||||
${DRIVER_SOURCES}
|
||||
${SYSCALL_SOURCES}
|
||||
)
|
||||
|
||||
# Kernel-specific C compiler flags
|
||||
# Compiler flags for kernel
|
||||
set(KERNEL_CFLAGS
|
||||
-Wall
|
||||
-Wextra
|
||||
-Werror
|
||||
-ffreestanding
|
||||
-fno-stack-protector
|
||||
-mno-red-zone
|
||||
-mcmodel=large
|
||||
-O2
|
||||
)
|
||||
|
||||
# Create kernel C object files
|
||||
add_library(kernel_c_objs OBJECT
|
||||
${KERNEL_C_SOURCES}
|
||||
# Create object library
|
||||
add_library(kernel_obj OBJECT ${KERNEL_SOURCES})
|
||||
target_include_directories(kernel_obj PRIVATE include)
|
||||
target_compile_options(kernel_obj PRIVATE ${KERNEL_CFLAGS})
|
||||
|
||||
# Create kernel binary
|
||||
add_executable(kernel_elf $<TARGET_OBJECTS:kernel_obj>)
|
||||
set_target_properties(kernel_elf PROPERTIES
|
||||
OUTPUT_NAME metalos.elf
|
||||
LINKER_LANGUAGE C
|
||||
)
|
||||
target_link_options(kernel_elf PRIVATE
|
||||
-nostdlib
|
||||
-T ${CMAKE_CURRENT_SOURCE_DIR}/linker.ld
|
||||
)
|
||||
|
||||
target_compile_options(kernel_c_objs PRIVATE ${KERNEL_CFLAGS})
|
||||
target_include_directories(kernel_c_objs PRIVATE include)
|
||||
|
||||
# Create kernel ASM object files separately
|
||||
# We need to avoid CMake adding C flags to NASM
|
||||
foreach(asm_file ${KERNEL_ASM_SOURCES})
|
||||
get_filename_component(asm_name ${asm_file} NAME_WE)
|
||||
set(asm_obj ${CMAKE_CURRENT_BINARY_DIR}/${asm_name}.o)
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT ${asm_obj}
|
||||
COMMAND ${CMAKE_ASM_NASM_COMPILER}
|
||||
-f elf64
|
||||
-I ${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
-o ${asm_obj}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/${asm_file}
|
||||
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${asm_file}
|
||||
COMMENT "Assembling ${asm_file}"
|
||||
VERBATIM
|
||||
)
|
||||
|
||||
list(APPEND KERNEL_ASM_OBJS ${asm_obj})
|
||||
endforeach()
|
||||
|
||||
# Custom target for ASM objects
|
||||
add_custom_target(kernel_asm_objs
|
||||
DEPENDS ${KERNEL_ASM_OBJS}
|
||||
)
|
||||
|
||||
# Link kernel binary
|
||||
# Custom command to create flat binary
|
||||
add_custom_command(
|
||||
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/metalos.bin
|
||||
COMMAND ${CMAKE_LINKER}
|
||||
-nostdlib
|
||||
-T ${CMAKE_CURRENT_SOURCE_DIR}/linker.ld
|
||||
$<TARGET_OBJECTS:kernel_c_objs>
|
||||
${KERNEL_ASM_OBJS}
|
||||
-o ${CMAKE_CURRENT_BINARY_DIR}/metalos.bin
|
||||
DEPENDS kernel_c_objs kernel_asm_objs ${CMAKE_CURRENT_SOURCE_DIR}/linker.ld
|
||||
COMMENT "Linking kernel binary"
|
||||
COMMAND_EXPAND_LISTS
|
||||
COMMAND ${CMAKE_OBJCOPY}
|
||||
-O binary
|
||||
$<TARGET_FILE:kernel_elf>
|
||||
${CMAKE_CURRENT_BINARY_DIR}/metalos.bin
|
||||
DEPENDS kernel_elf
|
||||
COMMENT "Creating kernel flat binary"
|
||||
VERBATIM
|
||||
)
|
||||
|
||||
add_custom_target(kernel ALL
|
||||
# Custom target for the binary
|
||||
add_custom_target(kernel_bin ALL
|
||||
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/metalos.bin
|
||||
)
|
||||
|
||||
# Install kernel binary
|
||||
# Install target
|
||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/metalos.bin
|
||||
DESTINATION bin
|
||||
DESTINATION boot
|
||||
)
|
||||
|
||||
# Print status
|
||||
message(STATUS "Kernel configuration:")
|
||||
message(STATUS " Sources: ${KERNEL_SOURCES}")
|
||||
message(STATUS " Output: metalos.bin")
|
||||
|
||||
Reference in New Issue
Block a user