diff options
author | Gunnar Beutner <gbeutner@serenityos.org> | 2021-06-24 13:08:19 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-06-25 15:19:09 +0200 |
commit | c9747a32366f9d0f6d37970579a2661233ea40bf (patch) | |
tree | 3202311d0abd795a9b10ce2c9a7893ca3098a4ba | |
parent | 04ba5cfcad6771de04fc8c7fa7bc0be810c72beb (diff) | |
download | serenity-c9747a32366f9d0f6d37970579a2661233ea40bf.zip |
Kernel: Build the x86_64 kernel as an ELF32 executable
Multiboot only supports ELF32 executables. This changes the build
process to build an ELF32 executable which has a 32-bit entry point,
but consists of mostly 64-bit code.
-rw-r--r-- | Kernel/CMakeLists.txt | 29 | ||||
-rw-r--r-- | Kernel/mkmap.sh | 7 | ||||
-rwxr-xr-x | Meta/debug-kernel.sh | 12 |
3 files changed, 37 insertions, 11 deletions
diff --git a/Kernel/CMakeLists.txt b/Kernel/CMakeLists.txt index 4b75fd1094..e8fdefd60d 100644 --- a/Kernel/CMakeLists.txt +++ b/Kernel/CMakeLists.txt @@ -387,22 +387,35 @@ else() link_directories(${TOOLCHAIN_ROOT}/Kernel/lib/gcc/${SERENITY_ARCH}-pc-serenity/${GCC_VERSION}/) endif() -add_executable(Kernel ${SOURCES}) -add_dependencies(Kernel generate_EscapeSequenceStateMachine.h) +if ("${SERENITY_ARCH}" STREQUAL "i686") + set(KERNEL_TARGET Kernel32) +else() + set(KERNEL_TARGET Kernel64) +endif() + +add_executable(${KERNEL_TARGET} ${SOURCES}) +add_dependencies(${KERNEL_TARGET} generate_EscapeSequenceStateMachine.h) -set_target_properties(Kernel PROPERTIES LINK_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/linker.ld) +set_target_properties(${KERNEL_TARGET} PROPERTIES LINK_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/linker.ld) if (ENABLE_KERNEL_LTO) include(CheckIPOSupported) check_ipo_supported() - set_property(TARGET Kernel PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) + set_property(TARGET ${KERNEL_TARGET} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) endif() -target_link_libraries(Kernel kernel_heap gcc supc++) -add_dependencies(Kernel kernel_heap) -install(TARGETS Kernel RUNTIME DESTINATION boot) +target_link_libraries(${KERNEL_TARGET} kernel_heap gcc supc++) +add_dependencies(${KERNEL_TARGET} kernel_heap) + +add_custom_command( + TARGET ${KERNEL_TARGET} POST_BUILD + COMMAND ${TOOLCHAIN_PREFIX}objcopy -O elf32-i386 ${CMAKE_CURRENT_BINARY_DIR}/${KERNEL_TARGET} ${CMAKE_CURRENT_BINARY_DIR}/Kernel + BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/Kernel +) + +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/Kernel" DESTINATION boot) add_custom_command( - TARGET Kernel + TARGET ${KERNEL_TARGET} POST_BUILD COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/mkmap.sh ) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/kernel.map DESTINATION res) diff --git a/Kernel/mkmap.sh b/Kernel/mkmap.sh index 15231e8fcd..35c112805d 100644 --- a/Kernel/mkmap.sh +++ b/Kernel/mkmap.sh @@ -1,6 +1,11 @@ #!/bin/sh tmp=$(mktemp) -nm -n Kernel | awk '{ if ($2 != "a") print; }' | uniq > "$tmp" +if [ -f Kernel32 ]; then + kernel_binary=Kernel32 +else + kernel_binary=Kernel64 +fi +nm -n $kernel_binary | awk '{ if ($2 != "a") print; }' | uniq > "$tmp" printf "%08x\n" "$(wc -l "$tmp" | cut -f1 -d' ')" > kernel.map cat "$tmp" >> kernel.map rm -f "$tmp" diff --git a/Meta/debug-kernel.sh b/Meta/debug-kernel.sh index 0f78ee6ceb..70130d11cb 100755 --- a/Meta/debug-kernel.sh +++ b/Meta/debug-kernel.sh @@ -8,9 +8,17 @@ # remote on localhost:1234. So point our debugger there, and inform # the debugger which binary to load symbols, etc from. # +if [ "$SERENITY_ARCH" = "x86_64" ]; then + gdb_arch=i386:x86-64 + kernel_binary=Kernel64 +else + gdb_arch=i386:intel + kernel_binary=Kernel +fi + exec $SERENITY_KERNEL_DEBUGGER \ - -ex "file $(dirname "$0")/../Build/${SERENITY_ARCH:-i686}/Kernel/Kernel" \ - -ex 'set arch i386:intel' \ + -ex "file $(dirname "$0")/../Build/${SERENITY_ARCH:-i686}/Kernel/$kernel_binary" \ + -ex "set arch $gdb_arch" \ -ex 'target remote localhost:1234' \ -ex "source $(dirname "$0")/serenity_gdb.py" \ "$@" |