2021-07-18 12:47:32 +00:00
|
|
|
set(SOURCES
|
2021-09-07 01:01:13 +00:00
|
|
|
UBSanitizer.cpp
|
2021-09-07 00:49:38 +00:00
|
|
|
../MiniStdLib.cpp
|
2021-07-18 12:47:32 +00:00
|
|
|
)
|
2021-08-28 17:41:14 +00:00
|
|
|
if ("${SERENITY_ARCH}" STREQUAL "aarch64")
|
|
|
|
set(SOURCES
|
2021-09-12 13:39:27 +00:00
|
|
|
# This has to be first, so that the entry point is at the start of the image.
|
|
|
|
# Needed because:
|
|
|
|
# - execution starts at the start of the image
|
|
|
|
# - the stack pointer currently starts before the start symbol, so if the start symbol isn't the first symbol, the stack will clobber arbitrary code
|
|
|
|
# FIXME: Use an aarch64-specific linker script instead.
|
|
|
|
Arch/aarch64/boot.S
|
|
|
|
|
2021-08-28 17:41:14 +00:00
|
|
|
${SOURCES}
|
2021-09-19 01:41:39 +00:00
|
|
|
Arch/aarch64/Mailbox.cpp
|
2021-09-12 13:42:27 +00:00
|
|
|
Arch/aarch64/MainIdRegister.cpp
|
2021-09-17 15:00:46 +00:00
|
|
|
Arch/aarch64/MMIO.cpp
|
2021-09-06 17:11:16 +00:00
|
|
|
Arch/aarch64/init.cpp
|
2021-08-28 17:41:14 +00:00
|
|
|
)
|
|
|
|
else()
|
|
|
|
set(SOURCES
|
|
|
|
${SOURCES}
|
|
|
|
Arch/x86/boot.S
|
|
|
|
Arch/x86/multiboot.S
|
|
|
|
# FIXME: Eventually, some of these should build on aarch64 too.
|
|
|
|
init.cpp
|
|
|
|
../../Userland/Libraries/LibELF/Relocation.cpp
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2021-07-18 12:47:32 +00:00
|
|
|
|
|
|
|
if ("${SERENITY_ARCH}" STREQUAL "i686")
|
|
|
|
set(PREKERNEL_TARGET Prekernel32)
|
2021-08-28 17:41:14 +00:00
|
|
|
elseif ("${SERENITY_ARCH}" STREQUAL "x86_64")
|
2021-07-18 12:47:32 +00:00
|
|
|
set(PREKERNEL_TARGET Prekernel64)
|
2021-08-28 17:41:14 +00:00
|
|
|
else()
|
|
|
|
set(PREKERNEL_TARGET Prekernel)
|
2021-07-18 12:47:32 +00:00
|
|
|
endif()
|
|
|
|
|
2021-07-26 13:10:51 +00:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static")
|
|
|
|
|
2021-07-18 12:47:32 +00:00
|
|
|
add_executable(${PREKERNEL_TARGET} ${SOURCES})
|
2021-09-12 13:09:36 +00:00
|
|
|
target_compile_options(${PREKERNEL_TARGET} PRIVATE -no-pie -fno-pic -fno-threadsafe-statics)
|
2021-07-18 12:47:32 +00:00
|
|
|
|
2021-07-13 14:43:45 +00:00
|
|
|
target_link_options(${PREKERNEL_TARGET} PRIVATE LINKER:-T ${CMAKE_CURRENT_SOURCE_DIR}/linker.ld -nostdlib LINKER:--no-pie)
|
2021-07-18 12:47:32 +00:00
|
|
|
set_target_properties(${PREKERNEL_TARGET} PROPERTIES LINK_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/linker.ld)
|
|
|
|
|
2021-09-07 08:21:36 +00:00
|
|
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
2021-09-17 14:01:46 +00:00
|
|
|
target_link_libraries(${PREKERNEL_TARGET} PRIVATE gcc)
|
2021-09-07 08:21:36 +00:00
|
|
|
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang$")
|
2021-09-17 14:01:46 +00:00
|
|
|
target_link_libraries(${PREKERNEL_TARGET} PRIVATE "clang_rt.builtins-${SERENITY_CLANG_ARCH}" c++abi)
|
2021-07-13 14:43:45 +00:00
|
|
|
endif()
|
2021-07-18 12:47:32 +00:00
|
|
|
|
2021-08-28 17:41:14 +00:00
|
|
|
if ("${SERENITY_ARCH}" STREQUAL "i686" OR "${SERENITY_ARCH}" STREQUAL "x86_64")
|
|
|
|
add_custom_command(
|
|
|
|
TARGET ${PREKERNEL_TARGET} POST_BUILD
|
|
|
|
COMMAND ${CMAKE_OBJCOPY} -O elf32-i386 ${CMAKE_CURRENT_BINARY_DIR}/${PREKERNEL_TARGET} ${CMAKE_CURRENT_BINARY_DIR}/Prekernel
|
|
|
|
BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/Prekernel
|
|
|
|
)
|
|
|
|
endif()
|
2021-07-18 12:47:32 +00:00
|
|
|
|
|
|
|
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/Prekernel" DESTINATION boot)
|
2021-08-25 03:28:51 +00:00
|
|
|
|
|
|
|
# Remove options which the Prekernel environment doesn't support.
|
|
|
|
get_target_property(PREKERNEL_TARGET_OPTIONS ${PREKERNEL_TARGET} COMPILE_OPTIONS)
|
|
|
|
list(REMOVE_ITEM PREKERNEL_TARGET_OPTIONS "-fsanitize-coverage=trace-pc")
|
|
|
|
list(REMOVE_ITEM PREKERNEL_TARGET_OPTIONS "-fsanitize=kernel-address")
|
|
|
|
set_target_properties(${PREKERNEL_TARGET} PROPERTIES COMPILE_OPTIONS "${PREKERNEL_TARGET_OPTIONS}")
|