How to build xv6-riscv on mac

tingwei628

Tingwei

Posted on June 7, 2021

How to build xv6-riscv on mac

There're three parts:

  1. riscv-gnu-toolchain installation
  2. qemu installation
  3. build xv6-riscv

Part1: riscv-gnu-toolchain installation

Env: macOS Catalina 10.15.7

Step1:

git clone --recursive https://github.com/riscv/riscv-gnu-toolchain
Enter fullscreen mode Exit fullscreen mode

Although it doesn't need --recursive in README, this issue still happened on mac.

Step2:

brew install python3 gawk gnu-sed gmp mpfr libmpc isl zlib expat
Enter fullscreen mode Exit fullscreen mode

Step3:

cd riscv-gnu-toolchain
./configure --prefix=/opt/riscv --enable-multilib
Enter fullscreen mode Exit fullscreen mode

To build either cross-compiler with support for both 32-bit and 64-bit

Step4: find your .zshrc, append this line

export PATH="$PATH:/opt/riscv/bin"
Enter fullscreen mode Exit fullscreen mode

and then

source .zshrc
Enter fullscreen mode Exit fullscreen mode

Part2: qemu installation

After installing riscv-gnu-toolchain, I chose to building qemu for macOS first and installed qemu.

Step 1: install prerequisites

brew install libffi gettext glib pkg-config autoconf automake pixman ninja
Enter fullscreen mode Exit fullscreen mode

Explained

Step2: pull the source of qemu

curl -L https://download.qemu.org/qemu-5.2.0.tar.xz > qemu-5.2.0.tar.xz
Enter fullscreen mode Exit fullscreen mode

(why qemu 5.2.0)

Step3: unzip

tar xf qemu-5.2.0.tar.xz
Enter fullscreen mode Exit fullscreen mode

Step4: build and install qemu

cd qemu-5.2.0
Enter fullscreen mode Exit fullscreen mode

and

mkdir build && cd build
../confgiure`
make
make install
Enter fullscreen mode Exit fullscreen mode

Part3: build xv6-riscv

After installing qemu sucessfully, let's start to build xv6-riscv

Step1: Pull the source of xv6-riscv

git clone git://github.com/mit-pdos/xv6-riscv-fall19.git
Enter fullscreen mode Exit fullscreen mode

NOTE: The xv6-riscv-fall19 repository differs slightly from the book's xv6-riscv in order to make the labs easier.

Step2:

cd xv6-riscv-fall19
Enter fullscreen mode Exit fullscreen mode

and

make
make qemu
Enter fullscreen mode Exit fullscreen mode

That's it!
Thanks for your reading~

💖 💪 🙅 🚩
tingwei628
Tingwei

Posted on June 7, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

How to build xv6-riscv on mac