Run XV6 on Apple Silicon
Run XV6 on Apple Silicon
Setup of the experimental environment
This experiment uses a MacOS system based on the ARM architecture, so the first step is to build a RISC-V-based xv6 experimental environment, and use cross-compilation technology and simulator to simulate the RISC-V environment. Be prepared for subsequent modifications and compilation of XV6 code.
Install a toolchain capable of compiling RISC-V object code
On MacOS, I used the homebrew package manager to install it, and the command is as follows:
1 |
|
After installing the toolchain, you need to add it to the environment variables, which can be implemented with the following command:
1 |
|
Install the QEMU simulator
QEMU is a general-purpose and open-source machine emulation and virtualizer. It can emulate multiple hardware platforms, enabling users to run operating systems and programs of other architectures on one computer architecture. In this lab, we need to install a QEMU version that supports RISC-V. Install the QEMU emulator we need by entering the following instructions:
1 |
|
Compile the XV6 source code
In the xv6 source code directory, there is usually a Makefile file that defines how to build the system. A Makefile is a build automation tool that manages and automates the compilation process of a software project. In this step, we need to build xv6 using the make command and the RISC-V toolchain, which will automatically compile the xv6 source code and generate the object and executable files according to the rules and dependencies defined in the makefile. Go to the xv6 directory and run the following command to compile and open QEMU:
1 |
|
Configure the debugging environment in the integrated development environment (IDE) (CLION)
Since debugging from the command line was too cumbersome and required to configure an IDE to facilitate debugging of code, I chose CLION as the IDE.
CLion debug xv6 must be configured with riscv-elf-gdb instead of standard GDB, which is designed specifically for the RISC-V architecture and handles the RISC-V instruction set and register configuration correctly, while the standard GDB does not support the RISC-V architecture and therefore cannot properly parse and debug code on the RISC-V platform.
Use homebrew to download riscv-elf-gdb, then enter make-qemu gdb in the terminal to get the following output, and then configure it according to the displayed port number.
After the configuration is complete, enter the make qemu-gdb command in the terminal and click the debug button in CLION to start debugging.