Skip to content

Commit

Permalink
ARM-based macOS support & riscv64 (#98)
Browse files Browse the repository at this point in the history
* Fix a few things to run on ARM-based macOS

* Install riscv64 GCC toolchain using apt in CI

* Find out where gcc is installed in CI

* Correct gcc toolchain path

* Build riscv gcc with newlib from source

* Switch back to xpack gcc

* Switch to a higher version of xpack gcc

* Look up binary names

* Correct binary names
  • Loading branch information
lsk567 authored Sep 16, 2024
1 parent 879dcaa commit 31032fb
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
19 changes: 11 additions & 8 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,22 @@ steps:
# We work around it by running the tests twice (!!!)
# flexpret.test.compileClasspath java.util.NoSuchElementException: key not found: https://oss.sonatype.org/content/repositories/releases/com/lihaoyi/utest_2.12/maven-metadata.xml
- script: |
## Install Verilator
# Ubuntu 20.04 only has Verilator 4.028 but we neeed a more modern version
# so we do not use 'sudo apt-get install -y -qq verilator' here.
wget -q https://github.com/sifive/verilator/releases/download/4.036-0sifive2/verilator_4.036-0sifive2_amd64.deb -O verilator.deb
sudo dpkg -i verilator.deb
wget -q https://github.com/xpack-dev-tools/riscv-none-embed-gcc-xpack/releases/download/v8.3.0-2.3/xpack-riscv-none-embed-gcc-8.3.0-2.3-linux-x64.tar.gz -O riscv.tgz
## Install RISC-V GCC
wget -q https://github.com/xpack-dev-tools/riscv-none-elf-gcc-xpack/releases/download/v14.2.0-2/xpack-riscv-none-elf-gcc-14.2.0-2-linux-x64.tar.gz -O riscv.tgz
tar zxf riscv.tgz
mv xpack-riscv-none-embed-gcc-8.3.0-2.3 ~/riscv-embed-gcc
ln -s ~/riscv-embed-gcc/bin/riscv-none-embed-as ~/riscv-embed-gcc/bin/riscv32-unknown-elf-as
ln -s ~/riscv-embed-gcc/bin/riscv-none-embed-ar ~/riscv-embed-gcc/bin/riscv32-unknown-elf-ar
ln -s ~/riscv-embed-gcc/bin/riscv-none-embed-gcc ~/riscv-embed-gcc/bin/riscv32-unknown-elf-gcc
ln -s ~/riscv-embed-gcc/bin/riscv-none-embed-ld ~/riscv-embed-gcc/bin/riscv32-unknown-elf-ld
ln -s ~/riscv-embed-gcc/bin/riscv-none-embed-objdump ~/riscv-embed-gcc/bin/riscv32-unknown-elf-objdump
ln -s ~/riscv-embed-gcc/bin/riscv-none-embed-objcopy ~/riscv-embed-gcc/bin/riscv32-unknown-elf-objcopy
ls xpack-riscv-none-elf-gcc-14.2.0-2/bin
mv xpack-riscv-none-elf-gcc-14.2.0-2 ~/riscv-embed-gcc
ln -s ~/riscv-embed-gcc/bin/riscv-none-elf-as ~/riscv-embed-gcc/bin/riscv64-unknown-elf-as
ln -s ~/riscv-embed-gcc/bin/riscv-none-elf-ar ~/riscv-embed-gcc/bin/riscv64-unknown-elf-ar
ln -s ~/riscv-embed-gcc/bin/riscv-none-elf-gcc ~/riscv-embed-gcc/bin/riscv64-unknown-elf-gcc
ln -s ~/riscv-embed-gcc/bin/riscv-none-elf-ld ~/riscv-embed-gcc/bin/riscv64-unknown-elf-ld
ln -s ~/riscv-embed-gcc/bin/riscv-none-elf-objdump ~/riscv-embed-gcc/bin/riscv64-unknown-elf-objdump
ln -s ~/riscv-embed-gcc/bin/riscv-none-elf-objcopy ~/riscv-embed-gcc/bin/riscv64-unknown-elf-objcopy
# Update submodules
git submodule update --init --recursive
Expand Down
2 changes: 1 addition & 1 deletion emulator/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ int main(int argc, char* argv[]) {
}

if (trace_enabled) {
trace->dump(10*timestamp);
trace->dump(static_cast<vluint64_t>(10*timestamp));
}

if (pin_client_enabled) {
Expand Down
2 changes: 1 addition & 1 deletion fpga/zedboard/fp-blinky/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ add_custom_target(${TARGET_NAME} DEPENDS
"${CMAKE_CURRENT_BINARY_DIR}/bitstream.bit"
)

set(ISPM_FILE $ENV{FP_PATH}/apps/build/blinky/blinky.mem)
set(ISPM_FILE $ENV{FP_PATH}/apps/blinky/build/blinky.mem)

# We want to include these commands because we do not want to type them out
# for each FPGA project
Expand Down
14 changes: 10 additions & 4 deletions sdk/cmake/riscv-toolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ cmake_minimum_required(VERSION 3.13)
# because they are appended to already existing flags
include_guard(GLOBAL)

set(CMAKE_SYSTEM_PROCESSOR riscv)
set(CMAKE_SYSTEM_NAME Generic) # Explicitly set for cross-compilation
set(CMAKE_SYSTEM_PROCESSOR riscv64)
set(RISCV_HOST_TAG linux)

set(RISCV_TOOL_PATH $ENV{RISCV_TOOL_PATH_PREFIX} CACHE PATH "RISC-V tool path" FORCE)

set(RISCV_TOOLCHAIN_ROOT "${RISCV_TOOL_PATH}/bin" CACHE PATH "RISC-V compiler path")
set(RISCV_TOOLCHAIN_PREFIX "riscv32-unknown-elf-" CACHE STRING "RISC-V toolchain prefix")
set(RISCV_TOOLCHAIN_PREFIX "riscv64-unknown-elf-" CACHE STRING "RISC-V toolchain prefix")
set(CMAKE_FIND_ROOT_PATH ${RISCV_TOOLCHAIN_ROOT})
list(APPEND CMAKE_PREFIX_PATH "${RISCV_TOOLCHAIN_ROOT}")

Expand All @@ -29,14 +30,19 @@ set(CMAKE_STRIP "${RISCV_TOOLCHAIN_ROOT}/${RISCV_TOOLCHAIN_PREFIX}strip")
set(CMAKE_OBJDUMP "${RISCV_TOOLCHAIN_ROOT}/${RISCV_TOOLCHAIN_PREFIX}objdump")
set(CMAKE_OBJCOPY "${RISCV_TOOLCHAIN_ROOT}/${RISCV_TOOLCHAIN_PREFIX}objcopy")

set(RISCV_COMPILER_FLAGS "-g -Os -static -march=rv32i -mabi=ilp32 -nostartfiles --specs=nosys.specs -ffunction-sections -fdata-sections -Wl,--gc-sections")
set(RISCV_COMPILER_FLAGS "-g -Os -static -march=rv32i_zicsr -mabi=ilp32 -nostartfiles --specs=nosys.specs -ffunction-sections -fdata-sections -Wl,--gc-sections")
set(RISCV_COMPILER_FLAGS_CXX)
set(RISCV_COMPILER_FLAGS_DEBUG)
set(RISCV_COMPILER_FLAGS_RELEASE)
set(RISCV_LINKER_FLAGS)
set(RISCV_LINKER_FLAGS_EXE "" CACHE STRING "Linker flags for RISCV executables")

set(CMAKE_SYSTEM_PROCESSOR riscv32)
# Check if the current OS is macOS
if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Darwin")
# Override macOS-specific settings
set(CMAKE_OSX_ARCHITECTURES "")
set(CMAKE_OSX_SYSROOT "")
endif()

set(CMAKE_C_FLAGS "${RISCV_COMPILER_FLAGS} ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${RISCV_COMPILER_FLAGS} ${RISCV_COMPILER_FLAGS_CXX} ${CMAKE_CXX_FLAGS}")
Expand Down

0 comments on commit 31032fb

Please sign in to comment.