Compile and install RISC-V cross-compiler

Introduction of the RISC-V cross-compilation tools

A number of cross-compilation tools are provided in the $TOP/riscv-tools directory:

There are four ways to test a program:

Programs can be compiled and run in three different modes:

Compiling and simulating programs in different modes depends on different tool sets.

Building the RISC-V cross-compilation tools

A build script is provided to build most of the cross-compilation tools and Spike:

# set up the RISCV environment variables
cd $TOP/riscv-tools
./build.sh

After the compilation, the Spike and the newlib GCC binaries should be available:

which spike
# the newlib gcc
which riscv64-unknown-elf-gcc

The RISC-V GCC/Newlib Toolchain Installation Manual can be found here.

Building the Linux GCC

The build script above provides a GCC build using the Newlib libc but not the GNU libc, which is needed for compiling programs to run in user mode on Linux. To build a Linux GCC compiler:

# set up the RISCV environment variables
cd $TOP/riscv-tools/riscv-gnu-toolchain
# ignore if build already exist
mkdir build
cd build
../configure --prefix=$RISCV
make -j$(nproc) linux

After the compilation, the Linux GCC binaries should be available:

which riscv64-unknown-linux-gnu-gcc