-
Notifications
You must be signed in to change notification settings - Fork 137
RISC V binutils
RISC-V binutils must be build manually, so first you'll need to get sources.
The source files are stored in GitHub repository in the RISC-V's riscv-gnu-toolchain project. Use git to get a local clone of the repository (--recursive option is required to get all submodules):
git clone --recursive https://github.com/riscv/riscv-gnu-toolchainIn case if submodules were not initialized automatically (their folders contain only .git file), set them manually from the project root:
cd riscv-gnu-toolchain
git submodule foreach 'git reset --hard'You can face problem with cloning "qemu" submodule. It is not required for the most of our usage cases, thus this can be ignored.
This cheat-sheet is based on GitHub README. See it if you have any problem or need more information.
# Install prerequisites
sudo apt-get install autoconf automake autotools-dev curl libmpc-dev libmpfr-dev libgmp-dev gawk build-essential \
bison flex texinfo gperf libtool patchutils bc zlib1g-dev libexpat-dev
# For convenience, you can proceed the build from project root
cd riscv-gnu-toolchain
# Create a directory where the binutils will be installed (can be any)
mkdir bin
# Create a directory for a build process (can be any), enter it
mkdir build && cd build
# Configure build (configures for RV64GC by default) using script from the project root.
# Set absolute path of destination binutils directory ("bin") for "prefix" flag
../configure --prefix=/riscv-gnu-toolchain/bin
# Make sources (can dump a lot of info). Paralleling can be archieved by specifying "-j NUMBER_OF_WORKERS" flag.
# Note: environment variables $CXX ($CC) should point to compiler supporting at least C++11 by default.
make
# Install (can dump a lot of info, usually requires sudo)
sudo make install
# Update $PATH variable to have binaries available
export PATH=$PATH:/riscv-gnu-toolchain/bin/bin
setenv PATH $PATH:/riscv-gnu-toolchain/bin/bin- Create a file with assembler code and save it as
<test name>.s
Note: Specify __start: before the first instruction of your program. This is required by mipt-mips to find a starting point of execution. |
|---|
- Generate an object file:
riscv64-unknown-elf-as <test name>.s -o <test name>.o- Convert the object file into the binary file:
riscv64-unknown-elf-ld <test name>.o -o <test name>.out- (optional) Look the content of .out using (pay attention only to .text section):
riscv64-unknown-elf-objdump -D <test name>.outNote that in addition to assembler this RISC-V GNU toolchain also includes C and C++ cross-compiler, so you can also build C/C++ code into a RISC-V binary on regular x86 machines.
MIPT-V / MIPT-MIPS — Cycle-accurate pre-silicon simulation.