2023-04-02 04:07:27 +03:00
|
|
|
cmake_minimum_required(VERSION 3.26)
|
|
|
|
|
2023-09-18 21:48:37 +03:00
|
|
|
project(kernel CXX C ASM)
|
2023-04-02 04:07:27 +03:00
|
|
|
|
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
|
2023-07-19 23:50:57 +03:00
|
|
|
kernel/Device/Device.cpp
|
2023-07-20 00:06:22 +03:00
|
|
|
kernel/Device/NullDevice.cpp
|
2023-09-09 22:46:15 +03:00
|
|
|
kernel/Device/ZeroDevice.cpp
|
2023-04-11 23:25:21 +03:00
|
|
|
kernel/Errors.cpp
|
2023-04-02 04:07:27 +03:00
|
|
|
kernel/Font.cpp
|
2023-07-10 23:17:14 +03:00
|
|
|
kernel/FS/DevFS/FileSystem.cpp
|
2023-09-01 15:10:23 +03:00
|
|
|
kernel/FS/Ext2/FileSystem.cpp
|
|
|
|
kernel/FS/Ext2/Inode.cpp
|
2023-06-11 19:52:13 +03:00
|
|
|
kernel/FS/Inode.cpp
|
2023-07-06 22:16:26 +03:00
|
|
|
kernel/FS/Pipe.cpp
|
2023-07-10 13:26:14 +03:00
|
|
|
kernel/FS/RamFS/FileSystem.cpp
|
|
|
|
kernel/FS/RamFS/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-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-09-13 19:09:12 +03:00
|
|
|
kernel/Networking/E1000.cpp
|
2023-07-07 23:11:37 +03:00
|
|
|
kernel/OpenFileDescriptorSet.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/Process.cpp
|
|
|
|
kernel/Scheduler.cpp
|
|
|
|
kernel/Semaphore.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-09-04 19:34:18 +03:00
|
|
|
kernel/Terminal/Serial.cpp
|
2023-04-05 00:56:09 +03:00
|
|
|
kernel/Terminal/TTY.cpp
|
|
|
|
kernel/Terminal/VesaTerminalDriver.cpp
|
2023-09-04 19:34:18 +03:00
|
|
|
kernel/Terminal/VirtualTTY.cpp
|
2023-08-04 10:22:20 +03:00
|
|
|
kernel/Thread.cpp
|
2023-08-04 15:15:45 +03:00
|
|
|
kernel/Timer/HPET.cpp
|
2023-08-04 10:22:20 +03:00
|
|
|
kernel/Timer/PIT.cpp
|
2023-08-04 11:12:16 +03:00
|
|
|
kernel/Timer/RTC.cpp
|
2023-08-04 10:22:20 +03:00
|
|
|
kernel/Timer/Timer.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-07-21 15:45:02 +03:00
|
|
|
arch/x86_64/Signal.S
|
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()
|
|
|
|
|
2023-09-18 21:48:37 +03:00
|
|
|
file(GLOB_RECURSE LAI_SOURCES
|
|
|
|
lai/*.c
|
|
|
|
)
|
|
|
|
set(LAI_SOURCES
|
|
|
|
${LAI_SOURCES}
|
|
|
|
kernel/lai_host.cpp
|
|
|
|
)
|
|
|
|
|
2023-04-02 04:07:27 +03:00
|
|
|
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
|
2023-09-29 02:00:10 +03:00
|
|
|
../LibELF/LibELF/LoadableELF.cpp
|
2023-04-12 22:20:18 +03:00
|
|
|
)
|
|
|
|
|
2023-04-02 04:07:27 +03:00
|
|
|
set(KERNEL_SOURCES
|
|
|
|
${KERNEL_SOURCES}
|
2023-09-18 21:48:37 +03:00
|
|
|
${LAI_SOURCES}
|
2023-04-02 04:07:27 +03:00
|
|
|
${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)
|
2023-09-18 21:48:37 +03:00
|
|
|
target_compile_options(kernel PUBLIC $<$<COMPILE_LANGUAGE:CXX>:-Wno-literal-suffix -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-09-18 21:48:37 +03:00
|
|
|
target_compile_options(kernel PUBLIC -fstack-protector -ffreestanding -Wall -Werror=return-type -Wstack-usage=1024 -fno-omit-frame-pointer -mgeneral-regs-only)
|
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
|
2023-08-23 10:35:16 +03:00
|
|
|
COMMAND ${CMAKE_CXX_COMPILER} -c ${CMAKE_CURRENT_SOURCE_DIR}/arch/${BANAN_ARCH}/crt0.S -o ${CMAKE_CURRENT_BINARY_DIR}/crt0.o
|
2023-04-07 02:27:15 +03:00
|
|
|
DEPENDS headers
|
|
|
|
)
|
|
|
|
|
2023-08-23 10:35:16 +03:00
|
|
|
add_custom_command(
|
|
|
|
TARGET crt0
|
|
|
|
POST_BUILD
|
|
|
|
COMMAND sudo cp ${CMAKE_CURRENT_BINARY_DIR}/crt0.o ${BANAN_LIB}/
|
|
|
|
)
|
|
|
|
|
2023-04-06 00:23:02 +03:00
|
|
|
add_custom_target(kernel-headers
|
2023-08-28 11:38:17 +03:00
|
|
|
COMMAND sudo rsync -a ${CMAKE_CURRENT_SOURCE_DIR}/include/ ${BANAN_INCLUDE}/
|
2023-09-18 21:48:37 +03:00
|
|
|
COMMAND sudo rsync -a ${CMAKE_CURRENT_SOURCE_DIR}/lai/include/ ${BANAN_INCLUDE}/
|
2023-04-02 04:07:27 +03:00
|
|
|
DEPENDS sysroot
|
2023-08-23 10:35:16 +03:00
|
|
|
USES_TERMINAL
|
2023-04-06 00:23:02 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
add_custom_target(kernel-install
|
2023-08-23 10:35:16 +03:00
|
|
|
COMMAND sudo cp ${CMAKE_CURRENT_BINARY_DIR}/kernel ${BANAN_BOOT}/banan-os.kernel
|
2023-04-02 04:07:27 +03:00
|
|
|
DEPENDS kernel
|
2023-08-23 10:35:16 +03:00
|
|
|
USES_TERMINAL
|
2023-04-02 04:07:27 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
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-07-21 15:47:31 +03:00
|
|
|
add_custom_command(
|
|
|
|
TARGET kernel POST_BUILD
|
|
|
|
COMMAND x86_64-banan_os-strip ${CMAKE_CURRENT_BINARY_DIR}/kernel
|
|
|
|
)
|
|
|
|
|
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 ")
|