Appendix A
Installing a RISC-V Toolchain

All of the software presented in this text was assembled/compiled using the GNU toolchain and executed using the rvddt simulator on a Linux (Ubuntu 20.04 LTS) operating system.

The installation instructions provided here were last tested on on March 5, 2021.

It is expected that these tools will evolve over time. See the respective documentation web sites for the latest news and options for installing them.

A.1 The GNU Toolchain

In order to install custom code in a location that will not cause interference with other applications (and allow for easy hacking and cleanup), these will install the toolchain under a private directory: ~/projects/riscv/install. At any time you can remove everything and start over by executing the following command:

1rm -rf ~/projects/riscv/install
 
2

Be very careful how you type the above rm command. If typed incorrectly, it could irreversibly remove many of your files!

Before building the toolchain, a number of utilities must be present on your system. The following will install those that are needed:

1sudo apt install autoconf automake autotools-dev curl python3 python-dev libmpc-dev \ 
2    libmpfr-dev libgmp-dev gawk build-essential bison flex texinfo gperf \ 
3    libtool patchutils bc zlib1g-dev libexpat-dev
 
4

Note that the above apt command is the only operation that should be performed as root. All other commands should be executed as a regular user. This will eliminate the possibility of clobbering system files that should not be touched when tinkering with the toolchain applications.

To download, compile and install the toolchain:

1mkdir -p ~/projects/riscv 
2cd ~/projects/riscv 
3git clone https://github.com/riscv/riscv-gnu-toolchain 
4cd riscv-gnu-toolchain 
5INS_DIR=~/projects/riscv/install/rv32i 
6./configure --prefix=$INS_DIR \ 
7    --with-multilib-generator="rv32i-ilp32--;rv32imafd-ilp32--;rv32ima-ilp32--" 
8make
 
9

After building the toolchain, make it available by putting it into your PATH by adding the following to the end of your .bashrc file:

1export PATH=$PATH:$INS_DIR
 
2

For this PATH change to take place, start a new terminal or paste the same export command into your existing terminal.

A.2 rvddt

Download and install the rvddt simulator by executing the following commands. Building the rvddt example programs will verify that the GNU toolchain has been built and installed properly.

1cd ~/projects/riscv 
2git clone https://github.com/johnwinans/rvddt.git 
3cd rvddt/src 
4make world 
5cd ../examples 
6make world
 
7

After building rvddt, make it available by putting it into your PATH by adding the following to the end of your .bashrc file:

1export PATH=$PATH:~/projects/riscv/rvddt/src
 
2

For this PATH change to take place, start a new terminal or paste the same export command into your existing terminal.

Test the rvddt build by executing one of the examples:

1winans@ux410:~/projects/riscv/rvddt/examples$ rvddt -f counter/counter.bin 
2sp initialized to top of memory: 0x0000fff0 
3Loading ’counter/counter.bin’ to 0x0 
4This is rvddt.  Enter ? for help. 
5ddt> ti 0 1000 
600000000: 00300293  addi    x5, x0, 3     # x5 = 0x00000003 = 0x00000000 + 0x00000003 
700000004: 00000313  addi    x6, x0, 0     # x6 = 0x00000000 = 0x00000000 + 0x00000000 
800000008: 00130313  addi    x6, x6, 1     # x6 = 0x00000001 = 0x00000000 + 0x00000001 
90000000c: fe534ee3  blt     x6, x5, -4    # pc = (0x1 < 0x3) ? 0x8 : 0x10 
1000000008: 00130313  addi    x6, x6, 1     # x6 = 0x00000002 = 0x00000001 + 0x00000001 
110000000c: fe534ee3  blt     x6, x5, -4    # pc = (0x2 < 0x3) ? 0x8 : 0x10 
1200000008: 00130313  addi    x6, x6, 1     # x6 = 0x00000003 = 0x00000002 + 0x00000001 
130000000c: fe534ee3  blt     x6, x5, -4    # pc = (0x3 < 0x3) ? 0x8 : 0x10 
1400000010: ebreak 
15ddt> x 
16winans@ux410:~/projects/riscv/rvddt/examples$
 
17

A.3 qemu

You can download and install the RV32 qemu simulator by executing the following commands.

At the time of this writing (2021-06) I use release v5.0.0. Release v5.2.0 has issues that confuse GDB when printing the registers and v6.0.0 has different CPU types that I have had trouble with when executing privileged instructions.

1INS_DIR=~/projects/riscv/install/rv32i 
2cd ~/projects/riscv 
3git clone git@github.com:qemu/qemu.git 
4cd qemu 
5git checkout v5.0.0 
6./configure --target-list=riscv32-softmmu --prefix=${INS_DIR} 
7make -j4 
8make install
 
9