This repository provides lab material for the 2017 Computer Architecture and Engineering course (02155) at DTU. Although this lab is customized for the DTU course, it can also serve as introduction lab for computer architecture in general and the RISC-V instruction set specifically.
The lab is based on COD: Computer Organization and Design RISC-V Edition: The Hardware Software Interface, 1st Edition, by David A. Patterson (Author), John L. Hennessy (Author).
To use this material you can: (1) just browse it online on GitHub, (2) clone the repo to have all material offline (using it also for your solutions), or (3) fork the repo (and clone locally), to be able to contribute back with changes.
Contributions: We are happily accepting contributions in the form of pull requests. Even the fix of a small typo is appreciated.
The following list gives an overview of all lab sessions and assignments. For lab sessions where no link is given, we will provide the material in CampusNet.
- week 1: Number representation and performance
- week 2: Lab 2
- week 3: Lab 3
- week 4: Exercises from Chapter 3
- week 5: work on first assignment
- week 6: Lab 6
- week 7: Lab 7
For the first labs we will use the web based RISC-V simulator Venus. Venus executes in your browser and there is no need to install any tools on your laptop. You can also save that web page to have a local copy of the simulator to work when offline.
However, for later lab exercises and your final project we need the full RISC-V toolchain, including a port of gcc and the spike
simulator.
If you are using Ubuntu (or any other Linux version) or a Mac OS X laptop, you can install the tools natively on your machine. However, to simplify life we provide a virtual machine (VM) with Ubuntu and all needed tools installed. You need about 18 GB of free disk space for the VM and another temporary space of 7 GB for the .zip file
- An Ubuntu VM with RISC-V tools installed
- caelab.zip
- user: caelab pwd: caelab
- Use the free VMWare Workstation Player
Test the VM by opening a terminal and starting the compiler with:
riscv32-unknown-elf-gcc
You should get an error, similar to following
riscv32-unknown-elf-gcc: fatal error: no input files
compilation terminated.
which is good as you know the the compiler is installed. You are now prepared for all RISC-V based lab work and projects.
For the more curious, you can sneak ahead and compile and run
Hello World program on RISC-V spike
as follows:
echo -e '#include <stdio.h>\n int main(void) { printf("Hello world!\\n"); return 0; }' > hello.c
riscv32-unknown-elf-gcc -o hello hello.c
spike pk hello
- The RISC-V Instruction Set Manual
- Venus RV32I simulator
- RISC-V Green Card
- RISC-V Tools (GNU Toolchain, ISA Simulator, Tests)
- Rocket Chip Generator (including the RISC- tools)
- Wildcat RV32I simulator
- SPIM system calls
- Bare metal program on spike
- UC Berkeley: CS61C: Great Ideas in Computer Architecture (Machine Structures)
- MIT: 6.175: Constructive Computer Architecture
- Cornell: ECE 4750: Computer Architecture
- Eclipse plugin
- https://stackoverflow.com/questions/31390127/how-can-i-compile-c-code-to-get-a-bare-metal-skeleton-of-a-minimal-risc-v-assemb
- Assembler appendix from H&P
- MARS docu
- CS61C summer lab 3
This is a log how I prepared the Ubuntu VM for the CAE lab. It might be useful for your own installation of the RISC-V tools.
Please note that this is a log on how I prepared the Ubuntu VM for the CAE lab. This instructions might be out of date soon. Please refer to the original README documents of the RISC-V tools.
- Use VMware Workstation 15 Player
- Use Ubuntu 18.04 desktop
- Do not use VMware easy install
- Do not use LVM
- Settings: turn off screen locking
Install VM tools for clipboard support and restart VM
sudo apt install open-vm-tools
Install git
sudo apt install git
Follow the instructions for installing the RISC-V tools here, except do not execute
./build.sh
Instead, change all references in build-rv32ima.sh
from rv32ima
to rv32i
.
Set the RISCV variable and path by adding this into .profile
(including logout and login to update your environment variables):
# RISC-V tools
export RISCV=$HOME/riscv-tools
export PATH=$PATH:$RISCV/bin
Then run
./build-rv32ima.sh
Create a file linker.ld
in the $HOME directory containing the following:
SECTIONS {
.text :{*(*)}
}
Download the RISCV pipeline simulator Ripes from here. No installation is required, however, enable the file's execute bit to make it executable.
There is no free VMWaare Player available for macOS. You can buy their VMware Fusion.
An alternative is to use the free VM VirtualBox.
We provide:
- An Ubuntu VM for VirtualBox with RISC-V tools installed
- caelab-vb.zip
- user: caelab pwd: caelab
For diverse GNU tools you need a packet manager for those tools under macOS.
Homebrew is one of the popular ones. For the packets listed in the Ubuntu installation you need to find the related ones for brew/macOS. As my (Martin's) Mac has brew already installed, I cannot list all that are needed. But if anyone is doing this installation from scratch I would love to add this information here.
According to the RISC-V tools README, following Homebrew packages need to be installed with following command:
brew install libusb dtc gawk gnu-sed gmp mpfr libmpc isl wget automake md5sha1sum
Then follow the instructions above like the setup on Ubuntu.