2023-04-02 04:07:27 +03:00
|
|
|
cmake_minimum_required(VERSION 3.26)
|
|
|
|
|
|
|
|
project(kernel CXX ASM)
|
|
|
|
|
2023-04-02 04:48:56 +03:00
|
|
|
if("${BANAN_ARCH}" STREQUAL "x86_64")
|
|
|
|
set(ELF_FORMAT elf64-x86-64)
|
|
|
|
elseif("${BANAN_ARCH}" STREQUAL "i386")
|
|
|
|
set(ELF_FORMAT elf32-i386)
|
|
|
|
endif()
|
|
|
|
|
2023-04-02 04:07:27 +03:00
|
|
|
set(KERNEL_SOURCES
|
|
|
|
font/prefs.psf.o
|
|
|
|
kernel/ACPI.cpp
|
|
|
|
kernel/APIC.cpp
|
|
|
|
kernel/CPUID.cpp
|
|
|
|
kernel/Debug.cpp
|
|
|
|
kernel/Device.cpp
|
|
|
|
kernel/DeviceManager.cpp
|
2023-04-11 23:25:21 +03:00
|
|
|
kernel/Errors.cpp
|
2023-04-02 04:07:27 +03:00
|
|
|
kernel/Font.cpp
|
|
|
|
kernel/FS/Ext2.cpp
|
2023-06-11 19:52:13 +03:00
|
|
|
kernel/FS/Inode.cpp
|
2023-04-02 04:07:27 +03:00
|
|
|
kernel/FS/VirtualFileSystem.cpp
|
|
|
|
kernel/Input/PS2Controller.cpp
|
|
|
|
kernel/Input/PS2Keyboard.cpp
|
|
|
|
kernel/Input/PS2Keymap.cpp
|
|
|
|
kernel/InterruptController.cpp
|
|
|
|
kernel/kernel.cpp
|
2023-05-06 18:10:38 +03:00
|
|
|
kernel/Memory/FixedWidthAllocator.cpp
|
2023-05-08 22:10:49 +03:00
|
|
|
kernel/Memory/GeneralAllocator.cpp
|
2023-04-14 15:16:38 +03:00
|
|
|
kernel/Memory/Heap.cpp
|
2023-04-14 13:30:21 +03:00
|
|
|
kernel/Memory/kmalloc.cpp
|
2023-05-28 16:21:45 +03:00
|
|
|
kernel/Memory/PhysicalRange.cpp
|
|
|
|
kernel/Memory/VirtualRange.cpp
|
2023-04-16 00:04:49 +03:00
|
|
|
kernel/Panic.cpp
|
2023-04-02 04:07:27 +03:00
|
|
|
kernel/PCI.cpp
|
|
|
|
kernel/PIC.cpp
|
|
|
|
kernel/PIT.cpp
|
|
|
|
kernel/Process.cpp
|
|
|
|
kernel/RTC.cpp
|
|
|
|
kernel/Scheduler.cpp
|
|
|
|
kernel/Semaphore.cpp
|
|
|
|
kernel/Serial.cpp
|
|
|
|
kernel/Shell.cpp
|
|
|
|
kernel/SpinLock.cpp
|
|
|
|
kernel/SSP.cpp
|
2023-04-02 23:56:01 +03:00
|
|
|
kernel/Storage/ATABus.cpp
|
2023-04-02 04:07:27 +03:00
|
|
|
kernel/Storage/ATAController.cpp
|
2023-04-02 18:26:19 +03:00
|
|
|
kernel/Storage/ATADevice.cpp
|
2023-06-03 02:23:14 +03:00
|
|
|
kernel/Storage/DiskCache.cpp
|
2023-04-02 04:07:27 +03:00
|
|
|
kernel/Storage/StorageDevice.cpp
|
|
|
|
kernel/Syscall.cpp
|
2023-05-28 18:08:26 +03:00
|
|
|
kernel/Syscall.S
|
2023-04-02 04:07:27 +03:00
|
|
|
kernel/Thread.cpp
|
2023-04-05 00:56:09 +03:00
|
|
|
kernel/Terminal/TTY.cpp
|
|
|
|
kernel/Terminal/VesaTerminalDriver.cpp
|
2023-04-02 04:07:27 +03:00
|
|
|
icxxabi.cpp
|
|
|
|
)
|
|
|
|
|
2023-04-12 00:18:06 +03:00
|
|
|
#set(ENABLE_KERNEL_UBSAN True)
|
|
|
|
|
2023-04-02 04:07:27 +03:00
|
|
|
if(ENABLE_KERNEL_UBSAN)
|
|
|
|
set(KERNEL_SOURCES ${KERNEL_SOURCES} ubsan.cpp)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if("${BANAN_ARCH}" STREQUAL "x86_64")
|
|
|
|
set(KERNEL_SOURCES
|
|
|
|
${KERNEL_SOURCES}
|
|
|
|
arch/x86_64/boot.S
|
|
|
|
arch/x86_64/GDT.cpp
|
|
|
|
arch/x86_64/IDT.cpp
|
|
|
|
arch/x86_64/interrupts.S
|
2023-05-29 21:06:09 +03:00
|
|
|
arch/x86_64/PageTable.cpp
|
2023-04-02 04:07:27 +03:00
|
|
|
arch/x86_64/Thread.S
|
|
|
|
)
|
2023-04-02 04:48:56 +03:00
|
|
|
elseif("${BANAN_ARCH}" STREQUAL "i386")
|
2023-04-02 04:07:27 +03:00
|
|
|
set(KERNEL_SOURCES
|
|
|
|
${KERNEL_SOURCES}
|
|
|
|
arch/i386/boot.S
|
|
|
|
arch/i386/GDT.cpp
|
|
|
|
arch/i386/IDT.cpp
|
|
|
|
arch/i386/MMU.cpp
|
|
|
|
arch/i386/SpinLock.S
|
|
|
|
arch/i386/Thread.S
|
|
|
|
)
|
|
|
|
else()
|
2023-04-02 04:48:56 +03:00
|
|
|
message(FATAL_ERROR "unsupported architecure ${BANAN_ARCH}")
|
2023-04-02 04:07:27 +03:00
|
|
|
endif()
|
|
|
|
|
|
|
|
set(BAN_SOURCES
|
2023-04-10 21:03:41 +03:00
|
|
|
../BAN/BAN/New.cpp
|
2023-04-02 04:07:27 +03:00
|
|
|
../BAN/BAN/String.cpp
|
|
|
|
../BAN/BAN/StringView.cpp
|
|
|
|
../BAN/BAN/Time.cpp
|
|
|
|
)
|
|
|
|
|
|
|
|
set(LIBC_SOURCES
|
|
|
|
../libc/ctype.cpp
|
|
|
|
../libc/string.cpp
|
|
|
|
)
|
|
|
|
|
2023-04-12 22:20:18 +03:00
|
|
|
set(LIBELF_SOURCES
|
|
|
|
../LibELF/LibELF/ELF.cpp
|
|
|
|
)
|
|
|
|
|
2023-04-02 04:07:27 +03:00
|
|
|
set(KERNEL_SOURCES
|
|
|
|
${KERNEL_SOURCES}
|
|
|
|
${BAN_SOURCES}
|
|
|
|
${LIBC_SOURCES}
|
2023-04-12 22:20:18 +03:00
|
|
|
${LIBELF_SOURCES}
|
2023-04-02 04:07:27 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
add_executable(kernel ${KERNEL_SOURCES})
|
2023-04-10 20:27:20 +03:00
|
|
|
add_dependencies(kernel headers)
|
2023-04-02 04:07:27 +03:00
|
|
|
|
|
|
|
target_compile_definitions(kernel PUBLIC __is_kernel)
|
2023-04-02 04:48:56 +03:00
|
|
|
target_compile_definitions(kernel PUBLIC __arch=${BANAN_ARCH})
|
2023-04-02 04:07:27 +03:00
|
|
|
|
|
|
|
target_compile_options(kernel PUBLIC -O2 -g)
|
|
|
|
target_compile_options(kernel PUBLIC -Wno-literal-suffix)
|
|
|
|
target_compile_options(kernel PUBLIC -fno-rtti -fno-exceptions)
|
2023-04-28 14:43:19 +03:00
|
|
|
target_compile_options(kernel PUBLIC -fmacro-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}=.)
|
2023-04-12 00:18:06 +03:00
|
|
|
target_compile_options(kernel PUBLIC -fstack-protector -ffreestanding -Wall -Wextra -Werror=return-type -Wstack-usage=1024 -fno-omit-frame-pointer -mno-sse -mno-sse2)
|
2023-04-02 04:07:27 +03:00
|
|
|
|
|
|
|
if(ENABLE_KERNEL_UBSAN)
|
|
|
|
target_compile_options(kernel PUBLIC -fsanitize=undefined)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if("${BANAN_ARCH}" STREQUAL "x86_64")
|
2023-05-30 08:00:17 +03:00
|
|
|
target_compile_options(kernel PUBLIC -mcmodel=kernel -mno-red-zone -mno-mmx)
|
2023-04-02 04:07:27 +03:00
|
|
|
target_link_options(kernel PUBLIC LINKER:-z,max-page-size=4096)
|
|
|
|
target_link_options(kernel PUBLIC LINKER:-T,${CMAKE_CURRENT_SOURCE_DIR}/arch/x86_64/linker.ld)
|
|
|
|
elseif("${BANAN_ARCH}" STREQUAL "i386")
|
|
|
|
target_link_options(kernel PUBLIC LINKER:-T,${CMAKE_CURRENT_SOURCE_DIR}/arch/i386/linker.ld)
|
|
|
|
endif()
|
|
|
|
|
2023-05-06 18:14:45 +03:00
|
|
|
target_link_options(kernel PUBLIC -ffreestanding -nostdlib)
|
2023-04-02 04:07:27 +03:00
|
|
|
|
2023-04-07 02:27:15 +03:00
|
|
|
add_custom_target(crt0
|
|
|
|
COMMAND ${CMAKE_CXX_COMPILER} -c ${CMAKE_CURRENT_SOURCE_DIR}/arch/${BANAN_ARCH}/crt0.S -o ${BANAN_LIB}/crt0.o
|
|
|
|
DEPENDS headers
|
|
|
|
)
|
|
|
|
|
2023-04-06 00:23:02 +03:00
|
|
|
add_custom_target(kernel-headers
|
2023-04-10 20:27:20 +03:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy_directory_if_different ${CMAKE_CURRENT_SOURCE_DIR}/include ${BANAN_INCLUDE}
|
2023-04-02 04:07:27 +03:00
|
|
|
DEPENDS sysroot
|
2023-04-06 00:23:02 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
add_custom_target(kernel-install
|
|
|
|
COMMAND cp ${CMAKE_CURRENT_BINARY_DIR}/kernel ${BANAN_BOOT}/banan-os.kernel
|
2023-04-02 04:07:27 +03:00
|
|
|
DEPENDS kernel
|
|
|
|
)
|
|
|
|
|
|
|
|
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -print-file-name=crtbegin.o OUTPUT_VARIABLE CRTBEGIN OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
|
|
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -print-file-name=crtend.o OUTPUT_VARIABLE CRTEND OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
|
|
|
|
|
|
add_custom_command(
|
|
|
|
TARGET kernel PRE_LINK
|
|
|
|
COMMAND ${CMAKE_CXX_COMPILER} -MD -c ${CMAKE_CURRENT_SOURCE_DIR}/arch/${BANAN_ARCH}/crti.S ${COMPILE_OPTIONS}
|
|
|
|
COMMAND ${CMAKE_CXX_COMPILER} -MD -c ${CMAKE_CURRENT_SOURCE_DIR}/arch/${BANAN_ARCH}/crtn.S ${COMPILE_OPTIONS}
|
|
|
|
COMMAND cp ${CRTBEGIN} .
|
|
|
|
COMMAND cp ${CRTEND} .
|
|
|
|
)
|
|
|
|
|
2023-04-02 04:48:56 +03:00
|
|
|
add_custom_command(
|
|
|
|
OUTPUT font/prefs.psf.o
|
|
|
|
COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR} && objcopy -O ${ELF_FORMAT} -B i386 -I binary font/prefs.psf ${CMAKE_CURRENT_BINARY_DIR}/font/prefs.psf.o
|
|
|
|
)
|
|
|
|
|
|
|
|
set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_COMPILER} <CMAKE_CXX_LINK_FLAGS> <FLAGS> <LINK_FLAGS> -o <TARGET> ${CMAKE_CURRENT_BINARY_DIR}/crti.o ${CMAKE_CURRENT_BINARY_DIR}/crtbegin.o <OBJECTS> ${CMAKE_CURRENT_BINARY_DIR}/crtend.o ${CMAKE_CURRENT_BINARY_DIR}/crtn.o -lgcc ")
|