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)
|
2024-03-26 02:48:26 +02:00
|
|
|
elseif("${BANAN_ARCH}" STREQUAL "i686")
|
2023-04-02 04:48:56 +03:00
|
|
|
set(ELF_FORMAT elf32-i386)
|
|
|
|
endif()
|
|
|
|
|
2023-04-02 04:07:27 +03:00
|
|
|
set(KERNEL_SOURCES
|
|
|
|
font/prefs.psf.o
|
2024-04-04 14:14:28 +03:00
|
|
|
kernel/ACPI/ACPI.cpp
|
2023-04-02 04:07:27 +03:00
|
|
|
kernel/APIC.cpp
|
2023-11-17 18:54:59 +02:00
|
|
|
kernel/BootInfo.cpp
|
2023-04-02 04:07:27 +03:00
|
|
|
kernel/CPUID.cpp
|
2024-01-02 23:19:58 +02:00
|
|
|
kernel/Credentials.cpp
|
2023-04-02 04:07:27 +03:00
|
|
|
kernel/Debug.cpp
|
2024-02-05 01:24:09 +02:00
|
|
|
kernel/Device/DebugDevice.cpp
|
2023-07-19 23:50:57 +03:00
|
|
|
kernel/Device/Device.cpp
|
2023-11-22 20:34:00 +02:00
|
|
|
kernel/Device/FramebufferDevice.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-09-30 21:19:36 +03:00
|
|
|
kernel/FS/ProcFS/FileSystem.cpp
|
|
|
|
kernel/FS/ProcFS/Inode.cpp
|
2023-11-04 18:13:52 +02:00
|
|
|
kernel/FS/TmpFS/FileSystem.cpp
|
|
|
|
kernel/FS/TmpFS/Inode.cpp
|
2023-04-02 04:07:27 +03:00
|
|
|
kernel/FS/VirtualFileSystem.cpp
|
2024-03-26 13:59:09 +02:00
|
|
|
kernel/GDT.cpp
|
|
|
|
kernel/IDT.cpp
|
2024-01-10 14:43:19 +02:00
|
|
|
kernel/Input/KeyboardLayout.cpp
|
2024-01-10 01:29:37 +02:00
|
|
|
kernel/Input/KeyEvent.cpp
|
2024-01-04 11:00:10 +02:00
|
|
|
kernel/Input/PS2/Controller.cpp
|
|
|
|
kernel/Input/PS2/Device.cpp
|
|
|
|
kernel/Input/PS2/Keyboard.cpp
|
|
|
|
kernel/Input/PS2/Keymap.cpp
|
2024-01-04 12:09:49 +02:00
|
|
|
kernel/Input/PS2/Mouse.cpp
|
2024-03-06 00:46:20 +02:00
|
|
|
kernel/Interruptable.cpp
|
2023-04-02 04:07:27 +03:00
|
|
|
kernel/InterruptController.cpp
|
|
|
|
kernel/kernel.cpp
|
2023-10-08 02:56:01 +03:00
|
|
|
kernel/Memory/DMARegion.cpp
|
2023-09-29 17:23:42 +03:00
|
|
|
kernel/Memory/FileBackedRegion.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-09-29 16:18:23 +03:00
|
|
|
kernel/Memory/MemoryBackedRegion.cpp
|
|
|
|
kernel/Memory/MemoryRegion.cpp
|
2023-05-28 16:21:45 +03:00
|
|
|
kernel/Memory/PhysicalRange.cpp
|
|
|
|
kernel/Memory/VirtualRange.cpp
|
2024-02-03 01:26:06 +02:00
|
|
|
kernel/Networking/ARPTable.cpp
|
2024-02-01 22:08:59 +02:00
|
|
|
kernel/Networking/E1000/E1000.cpp
|
|
|
|
kernel/Networking/E1000/E1000E.cpp
|
2024-02-06 12:30:01 +02:00
|
|
|
kernel/Networking/IPv4Layer.cpp
|
2024-02-01 22:08:59 +02:00
|
|
|
kernel/Networking/NetworkInterface.cpp
|
2024-02-01 23:38:06 +02:00
|
|
|
kernel/Networking/NetworkManager.cpp
|
|
|
|
kernel/Networking/NetworkSocket.cpp
|
2024-02-12 04:27:50 +02:00
|
|
|
kernel/Networking/TCPSocket.cpp
|
2024-02-01 23:38:06 +02:00
|
|
|
kernel/Networking/UDPSocket.cpp
|
2024-02-08 02:28:19 +02:00
|
|
|
kernel/Networking/UNIX/Socket.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
|
2024-03-03 22:30:06 +02:00
|
|
|
kernel/Processor.cpp
|
2024-02-12 04:25:06 +02:00
|
|
|
kernel/Random.cpp
|
2023-04-02 04:07:27 +03:00
|
|
|
kernel/Scheduler.cpp
|
|
|
|
kernel/Semaphore.cpp
|
|
|
|
kernel/SSP.cpp
|
2023-10-12 21:53:48 +03:00
|
|
|
kernel/Storage/ATA/AHCI/Controller.cpp
|
|
|
|
kernel/Storage/ATA/AHCI/Device.cpp
|
2023-10-07 15:46:30 +03:00
|
|
|
kernel/Storage/ATA/ATABus.cpp
|
|
|
|
kernel/Storage/ATA/ATAController.cpp
|
|
|
|
kernel/Storage/ATA/ATADevice.cpp
|
2023-06-03 02:23:14 +03:00
|
|
|
kernel/Storage/DiskCache.cpp
|
2024-01-14 01:39:48 +02:00
|
|
|
kernel/Storage/NVMe/Controller.cpp
|
|
|
|
kernel/Storage/NVMe/Namespace.cpp
|
|
|
|
kernel/Storage/NVMe/Queue.cpp
|
2023-11-21 15:16:04 +02:00
|
|
|
kernel/Storage/Partition.cpp
|
2023-04-02 04:07:27 +03:00
|
|
|
kernel/Storage/StorageDevice.cpp
|
|
|
|
kernel/Syscall.cpp
|
2023-11-22 21:57:17 +02:00
|
|
|
kernel/Terminal/FramebufferTerminal.cpp
|
2023-09-04 19:34:18 +03:00
|
|
|
kernel/Terminal/Serial.cpp
|
2023-04-05 00:56:09 +03:00
|
|
|
kernel/Terminal/TTY.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/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
|
2024-03-22 12:48:54 +02:00
|
|
|
arch/x86_64/Syscall.S
|
2023-04-02 04:07:27 +03:00
|
|
|
arch/x86_64/Thread.S
|
|
|
|
)
|
2024-03-22 13:32:07 +02:00
|
|
|
file(GLOB_RECURSE LAI_SOURCES
|
|
|
|
lai/*.c
|
|
|
|
)
|
|
|
|
set(LAI_SOURCES
|
|
|
|
${LAI_SOURCES}
|
|
|
|
kernel/lai_host.cpp
|
|
|
|
)
|
2024-03-26 02:48:26 +02:00
|
|
|
elseif("${BANAN_ARCH}" STREQUAL "i686")
|
2023-04-02 04:07:27 +03:00
|
|
|
set(KERNEL_SOURCES
|
|
|
|
${KERNEL_SOURCES}
|
2024-03-26 02:48:26 +02:00
|
|
|
arch/i686/boot.S
|
2024-03-26 13:59:09 +02:00
|
|
|
arch/i686/interrupts.S
|
2024-03-26 02:48:26 +02:00
|
|
|
arch/i686/PageTable.cpp
|
|
|
|
arch/i686/Signal.S
|
|
|
|
arch/i686/Syscall.S
|
|
|
|
arch/i686/Thread.S
|
2023-04-02 04:07:27 +03:00
|
|
|
)
|
|
|
|
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
|
2024-03-04 11:41:54 +02:00
|
|
|
../BAN/BAN/Assert.cpp
|
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
|
|
|
|
)
|
|
|
|
|
2024-02-14 15:00:04 +02:00
|
|
|
set(KLIBC_SOURCES
|
|
|
|
klibc/ctype.cpp
|
|
|
|
klibc/string.cpp
|
2023-04-02 04:07:27 +03:00
|
|
|
)
|
|
|
|
|
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}
|
2024-02-14 15:00:04 +02:00
|
|
|
${KLIBC_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-11-30 13:41:14 +02:00
|
|
|
target_compile_options(kernel PUBLIC -fstack-protector -ffreestanding -Wall -Wextra -Werror -Wstack-usage=1024 -fno-omit-frame-pointer -mgeneral-regs-only)
|
2023-04-02 04:07:27 +03:00
|
|
|
|
2023-10-30 17:51:18 +02:00
|
|
|
# This might not work with other toolchains
|
|
|
|
target_compile_options(kernel PUBLIC $<$<COMPILE_LANGUAGE:CXX>:-Wno-invalid-offsetof>)
|
|
|
|
|
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")
|
2024-03-22 13:32:07 +02:00
|
|
|
target_compile_options(kernel PUBLIC -mcmodel=kernel -mno-red-zone)
|
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)
|
2024-03-26 02:48:26 +02:00
|
|
|
elseif("${BANAN_ARCH}" STREQUAL "i686")
|
|
|
|
target_link_options(kernel PUBLIC LINKER:-T,${CMAKE_CURRENT_SOURCE_DIR}/arch/i686/linker.ld)
|
2023-04-02 04:07:27 +03:00
|
|
|
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-11-30 13:39:33 +02:00
|
|
|
set_source_files_properties(${LAI_SOURCES} PROPERTIES COMPILE_FLAGS -Wno-stack-usage)
|
|
|
|
|
2023-04-06 00:23:02 +03:00
|
|
|
add_custom_target(kernel-headers
|
2023-11-04 17:50:43 +02:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy_directory_if_different ${CMAKE_CURRENT_SOURCE_DIR}/include/ ${BANAN_INCLUDE}/
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy_directory_if_different ${CMAKE_CURRENT_SOURCE_DIR}/lai/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
|
2023-11-04 17:50:43 +02:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy ${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}
|
2023-10-30 11:06:13 +02:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy ${CRTBEGIN} .
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy ${CRTEND} .
|
2023-04-02 04:07:27 +03:00
|
|
|
)
|
|
|
|
|
2023-10-05 18:52:44 +03:00
|
|
|
#add_custom_command(
|
|
|
|
# TARGET kernel POST_BUILD
|
|
|
|
# COMMAND x86_64-banan_os-strip ${CMAKE_CURRENT_BINARY_DIR}/kernel
|
|
|
|
#)
|
2023-07-21 15:47:31 +03:00
|
|
|
|
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 ")
|