From 096cecb95e4992f0dfa2526b2c134b14e114c26f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?kleines=20Filmr=C3=B6llchen?= Date: Thu, 17 Aug 2023 11:32:32 +0200 Subject: [PATCH] Everywhere: Add RISC-V 64 target to the build system This is a minimal set of changes to allow `serenity.sh build riscv64` to successfully generate the build environment and start building. This includes some, but not all, assembly stubs that will be needed later on; they are currently empty. --- Documentation/AdvancedBuildInstructions.md | 2 +- Kernel/CMakeLists.txt | 14 ++++++++++++-- Meta/ShellCompletions/zsh/_serenity | 1 + Meta/serenity.sh | 6 +++++- Toolchain/CMake/ClangToolchain.txt.in | 5 +++++ Toolchain/CMake/GNUToolchain.txt.in | 5 +++++ Userland/Libraries/LibC/CMakeLists.txt | 5 +++++ Userland/Libraries/LibC/arch/riscv64/crti.S | 1 + Userland/Libraries/LibC/arch/riscv64/crtn.S | 1 + Userland/Libraries/LibC/arch/riscv64/setjmp.S | 1 + Userland/Libraries/LibELF/Arch/riscv64/entry.S | 1 + .../Libraries/LibELF/Arch/riscv64/plt_trampoline.S | 1 + 12 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 Userland/Libraries/LibC/arch/riscv64/crti.S create mode 100644 Userland/Libraries/LibC/arch/riscv64/crtn.S create mode 100644 Userland/Libraries/LibC/arch/riscv64/setjmp.S create mode 100644 Userland/Libraries/LibELF/Arch/riscv64/entry.S create mode 100644 Userland/Libraries/LibELF/Arch/riscv64/plt_trampoline.S diff --git a/Documentation/AdvancedBuildInstructions.md b/Documentation/AdvancedBuildInstructions.md index 7b7aae98649..72eede8f87a 100644 --- a/Documentation/AdvancedBuildInstructions.md +++ b/Documentation/AdvancedBuildInstructions.md @@ -65,7 +65,7 @@ There are some optional features that can be enabled during compilation that are - `INCLUDE_WASM_SPEC_TESTS`: downloads and includes the WebAssembly spec testsuite tests. In order to use this option, you will need to install `prettier` and `wabt`. wabt version 1.0.23 or higher is required to pre-process the WebAssembly spec testsuite. - `INCLUDE_FLAC_SPEC_TESTS`: downloads and includes the xiph.org FLAC test suite. - `SERENITY_TOOLCHAIN`: Specifies whether to use the established GNU toolchain, or the experimental Clang-based toolchain for building SerenityOS. See the [Clang-based toolchain](#clang-based-toolchain) section below. -- `SERENITY_ARCH`: Specifies which architecture to build for. Currently supported options are `x86_64`. +- `SERENITY_ARCH`: Specifies which architecture to build for. Currently supported options are `x86_64`, `aarch64`, `riscv64`. - `BUILD_`: builds the specified component, e.g. `BUILD_HEARTS` (note: must be all caps). Check the components.ini file in your build directory for a list of available components. Make sure to run `ninja clean` and `rm -rf Build/x86_64/Root` after disabling components. These options can be easily configured by using the `ConfigureComponents` utility. See the [Component Configuration](#component-configuration) section below. - `BUILD_EVERYTHING`: builds all optional components, overrides other `BUILD_` flags when enabled - `SERENITY_CACHE_DIR`: sets the location of a shared cache of downloaded files. Should not need to be set unless managing a distribution package. diff --git a/Kernel/CMakeLists.txt b/Kernel/CMakeLists.txt index a72a9a8d002..e49e3ed1213 100644 --- a/Kernel/CMakeLists.txt +++ b/Kernel/CMakeLists.txt @@ -9,6 +9,8 @@ if ("${SERENITY_ARCH}" STREQUAL "aarch64") set(KERNEL_ARCH aarch64) elseif("${SERENITY_ARCH}" STREQUAL "x86_64") set(KERNEL_ARCH x86_64) +elseif("${SERENITY_ARCH}" STREQUAL "riscv64") + set(KERNEL_ARCH riscv64) endif() set(KERNEL_HEAP_SOURCES @@ -495,6 +497,14 @@ elseif("${SERENITY_ARCH}" STREQUAL "aarch64") # NOTE: These files cannot use a stack protector and sanitizers, as these will cause accesses to global variables to be inserted # by the compiler. The CPU cannot access global variables without the MMU as the kernel is linked for a virtual address in high memory. set_source_files_properties(${SOURCES_RUNNING_WITHOUT_MMU} PROPERTIES COMPILE_FLAGS "-fno-stack-protector -fno-sanitize=all") +elseif("${SERENITY_ARCH}" STREQUAL "riscv64") + set(KERNEL_SOURCES + ${KERNEL_SOURCES} + Arch/Processor.cpp + kprintf.cpp + ) + + add_compile_options(-fno-stack-protector -fno-sanitize=all) endif() set(AK_SOURCES @@ -767,7 +777,7 @@ endif() serenity_install_headers(Kernel) serenity_install_sources(Kernel) -# aarch64 does not need a Prekernel -if (NOT "${SERENITY_ARCH}" STREQUAL "aarch64") +# Only x86 needs a Prekernel +if ("${SERENITY_ARCH}" STREQUAL "x86_64") add_subdirectory(Prekernel) endif() diff --git a/Meta/ShellCompletions/zsh/_serenity b/Meta/ShellCompletions/zsh/_serenity index 32a6c591543..9462aabe1a3 100644 --- a/Meta/ShellCompletions/zsh/_serenity +++ b/Meta/ShellCompletions/zsh/_serenity @@ -46,6 +46,7 @@ _serenity() { targets=( 'x86_64:Target x86_64 or $SERENITY_ARCH (default)' 'aarch64:Target aarch64' + 'riscv64:Target riscv64' 'lagom:Target host machine' ) diff --git a/Meta/serenity.sh b/Meta/serenity.sh index 6c064c73458..5877d2772ac 100755 --- a/Meta/serenity.sh +++ b/Meta/serenity.sh @@ -7,7 +7,7 @@ print_help() { NAME=$(basename "$ARG0") cat <