Before starting, ensure you have:
- Git installed
- At least 10GB of free disk space
- Internet connection
Install homebrew
as the package manager.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Install dependencies required to build repositories:
brew install python3 gawk gnu-sed make gmp mpfr libmpc isl zlib expat texinfo flock libslirp glib gcc pkg-config pixman libmpc-devel libmpdclient capstone gnutls libpng libjpeg jpeg-turbo libusb libssh
mkdir -p ~/Developer/tools
Switch to working directory
cd ~/Developer/tools
We'll be building the Newlib cross compiler as instructed here
- Create a writeable directory
/opt/riscv
sudo mkdir /opt/riscv && sudo chmod -R 767 /opt/riscv
- Create bin folder that will be home to the risc-v binaries
mkdir /opt/riscv/bin
- Clone riscv-gnu-toolchain repository
git clone [email protected]:riscv-collab/riscv-gnu-toolchain.git
- Switch to riscv-gnu-toolchain repository directory
cd riscv-gnu-toolchain
- Add riscv-gnu-toolchain to your shell configuration
PATH
Open your .bashrc
or .zshrc
file
vim ~/.zshrc
Append this line
export PATH="/opt/riscv/bin:$PATH"
- Install Newlib
./configure --prefix=/opt/riscv --with-languages="c,c++"
make
- Check that all the riscv-gnu-toolchain binaries were created.
ls /opt/riscv/bin
Expected output:
riscv64-unknown-elf-addr2line riscv64-unknown-elf-gcc-nm riscv64-unknown-elf-nm
riscv64-unknown-elf-ar riscv64-unknown-elf-gcc-ranlib riscv64-unknown-elf-objcopy
riscv64-unknown-elf-as riscv64-unknown-elf-gcov riscv64-unknown-elf-objdump
riscv64-unknown-elf-c++ riscv64-unknown-elf-gcov-dump riscv64-unknown-elf-ranlib
riscv64-unknown-elf-c++filt riscv64-unknown-elf-gcov-tool riscv64-unknown-elf-readelf
riscv64-unknown-elf-cpp riscv64-unknown-elf-gdb riscv64-unknown-elf-run
riscv64-unknown-elf-elfedit riscv64-unknown-elf-gdb-add-index riscv64-unknown-elf-size
riscv64-unknown-elf-g++ riscv64-unknown-elf-gprof riscv64-unknown-elf-strings
riscv64-unknown-elf-gcc riscv64-unknown-elf-ld riscv64-unknown-elf-strip
riscv64-unknown-elf-gcc-14.2.0 riscv64-unknown-elf-ld.bfd
riscv64-unknown-elf-gcc-ar riscv64-unknown-elf-lto-dump
- Switch to the working directory created earlier
cd ~/Developer/tools
- Clone the qemu repo
git clone [email protected]:qemu/qemu.git
- Switch to qemu repository directory
cd qemu
- Build qemu
mkdir build
cd build
../configure --target-list=riscv64-softmmu
make
- Add the qemu-system-riscv64 binary to your local binaries
make install
Confirm it was added
which qemu-system-riscv64
Output: /usr/local/bin/qemu-system-riscv64
-
Clone the Repository
git clone git://g.csail.mit.edu/xv6-labs-2020 cd xv6-labs-2020
-
Switch to the Initial Lab Branch (util)
git checkout util
!Important: Add the file changes in this PR to the respective files on your util branch
-
Test the Installation
make qemu
This command will:
- Compile the xv6 operating system
- Start QEMU emulator
- Boot xv6
If successful, you should see the xv6 boot sequence and a prompt that looks like this:
xv6 kernel is booting hart 1 starting hart 2 starting init: starting sh $
-
Exit QEMU
- Press
Ctrl-a
thenx
to exit QEMU
- Press
console 3 21 0
$ QEMU: Terminated
(base) ➜ xv6-labs-2020 git:(util) ✗
-
Using GDB for Debugging
In one terminal:
make qemu-gdb
In another terminal:
riscv64-unknown-elf-gdb kernel/kernel
-
Useful Make Commands
make clean # Clean build files make # Build xv6 make qemu # Run xv6 in QEMU make grade # Test your implementation (when working on labs)
-
File Organization
kernel/
: Kernel source filesuser/
: User programsMakefile
: Build configuration
-
Each lab has its own branch. To switch to a different lab:
git fetch git checkout [lab-name]
-
Common lab branches:
- util
- syscall
- pgtbl
- traps
- lazy
- cow
- thread
- lock
- fs
- mmap
-
Before starting each lab, make sure to:
git checkout [lab-name] make clean
- Make your changes in the appropriate files
- Test your implementation:
make grade
- Commit your changes:
git add [modified-files] git commit -m "Descriptive message about changes"