diff --git a/abstract-machine/CMakeLists.txt b/abstract-machine/CMakeLists.txt index 4de3a06..508bc68 100644 --- a/abstract-machine/CMakeLists.txt +++ b/abstract-machine/CMakeLists.txt @@ -76,9 +76,12 @@ add_link_options( ) # -- Include linker script here. Use this linker script at link time if INCLUDE_LINKER_SCRIPT is set to true -set(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/scripts/linker.ld) +set(LINKER_SCRIPT linker.ld) list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") +add_compile_options(-march=rv32if -mabi=ilp32) +add_link_options(-march=rv32if -mabi=ilp32) + add_subdirectory(klib) add_subdirectory(am) diff --git a/abstract-machine/am/src/CMakeLists.txt b/abstract-machine/am/src/CMakeLists.txt index 97e86b0..533dd3b 100644 --- a/abstract-machine/am/src/CMakeLists.txt +++ b/abstract-machine/am/src/CMakeLists.txt @@ -14,9 +14,11 @@ target_include_directories(am-${ARCH} target_link_libraries(am-${ARCH} PUBLIC klib_interface INTERFACE m) -if(INCLUDE_LINKER_SCRIPT) - target_link_options(am-${ARCH} INTERFACE -T${LINKER_SCRIPT}) -endif() + +# TODO: Check +target_link_options(am-${ARCH} INTERFACE + $ + $) # Interface compile flags target_link_options(am-${ARCH} INTERFACE @@ -45,3 +47,7 @@ configure_package_config_file(${CMAKE_SOURCE_DIR}/cmake/am-config.cmake.in install(FILES ${CMAKE_CURRENT_BINARY_DIR}/am-${ARCH}-config.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/am-${ARCH}) + +# TODO: check +install(FILES ${CMAKE_SOURCE_DIR}/scripts/${LINKER_SCRIPT} + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/am-${ARCH}) diff --git a/abstract-machine/am/src/riscv/nemu/CMakeLists.txt b/abstract-machine/am/src/riscv/nemu/CMakeLists.txt index ac024cc..a6992db 100644 --- a/abstract-machine/am/src/riscv/nemu/CMakeLists.txt +++ b/abstract-machine/am/src/riscv/nemu/CMakeLists.txt @@ -1,4 +1,5 @@ include(nemu-settings) +include(riscv-settings) add_library(am-${ISA}-nemu cte.c @@ -16,6 +17,12 @@ target_link_options(am-${ISA}-nemu PRIVATE ${RISCV_LINK_OPTIONS}) target_include_directories(am-${ISA}-nemu PRIVATE ${NEMU_INCLUDE_DIRECTORIES}) +target_link_options(am-${ISA}-nemu INTERFACE + LINKER:--defsym=_pmem_start=0x80000000 + LINKER:--defsym=_entry_offset=0x0 + LINKER:--gc-sections + LINKER:-e _start + -nostartfiles) target_compile_definitions(am-${ISA}-nemu PUBLIC ARCH_H="arch/riscv.h") diff --git a/abstract-machine/cmake/nemu-settings.cmake b/abstract-machine/cmake/nemu-settings.cmake index 555b4dd..910cdcf 100644 --- a/abstract-machine/cmake/nemu-settings.cmake +++ b/abstract-machine/cmake/nemu-settings.cmake @@ -8,4 +8,4 @@ set(NEMU_INCLUDE_DIRECTORIES ${CMAKE_SOURCE_DIR}/am/src/platform/nemu/include) file(GLOB_RECURSE NEMU_SOURCES ${CMAKE_SOURCE_DIR}/am/src/platform/nemu/*.[cS]) -set(INCLUDE_LINKER_SCRIPT true) +set(INCLUDE_LINKER_SCRIPT ON) diff --git a/abstract-machine/out/install/lib/libklib.a b/abstract-machine/out/install/lib/libklib.a index de0ce70..5023a30 100644 Binary files a/abstract-machine/out/install/lib/libklib.a and b/abstract-machine/out/install/lib/libklib.a differ diff --git a/flake.nix b/flake.nix index b86ae8a..6154319 100644 --- a/flake.nix +++ b/flake.nix @@ -12,7 +12,10 @@ localSystem = system; crossSystem = { config = "riscv32-none-elf"; - abi = "ilp32"; + gcc = { + abi = "ilp32"; + arch = "rv32if"; + }; }; }; in @@ -40,14 +43,21 @@ packages.am-kernels-cmake = crossPkgs.stdenv.mkDerivation rec { pname = "am-kernels-cmake"; - version = "2024.02.18"; + version = "2024.02.19"; - src = /home/xin/repo/am-kernels; + src = ./am-kernels; nativeBuildInputs = [ pkgs.cmake ]; + cmakeFlags = [ + (pkgs.lib.cmakeFeature "ISA" "riscv") + (pkgs.lib.cmakeFeature "PLATFORM" "nemu") + + (pkgs.lib.cmakeFeature "CMAKE_INSTALL_DATADIR" "share") + ]; + buildInputs = [ # SDL2 self.packages.${system}.abstract-machine diff --git a/result b/result index 62f4c55..c4a563f 120000 --- a/result +++ b/result @@ -1 +1 @@ -/nix/store/nzfl421lydgznc237s7z6nz93zml4i8p-am-kernels-rv32-riscv32-none-elf-2024.02.18 \ No newline at end of file +/nix/store/mpn11vhq7f7zqp9ql02n083x1wkp5jbx-am-kernels-cmake-riscv32-none-elf-2024.02.19 \ No newline at end of file