安装RISC-V工具链
参考https://blog.youkuaiyun.com/zhayujie5200/article/details/106374189/?ops_request_misc=&request_id=&biz_id=102&utm_term=xv6%E5%AE%9E%E9%AA%8CMac&utm_medium=distribute.pc_search_result.none-task-blog-2allsobaiduweb~default-1-106374189.142v47pc_rank_34_default_3,201v2control&spm=1018.2226.3001.4187
- 下载riscv-gnu-toolchain安装包(百度网盘https://pan.baidu.com/s/1104aCZiIUAEcHONKcI8GKw,ui4j)
- 解压
- 完成之后,输入如下
$ cd riscv-gnu-toolchain
$ sudo ./configure --prefix=/usr/local
$ sudo make
$ cd ..
#如果make错误,可能有依赖的软件包没安装,输入
$ sudo apt-get install libglib2.0-dev
$ sudo apt-get install libpixman-1-dev
- 验证安装
$ riscv64-unknown-elf-gcc --version
#有如下提示:
riscv64-unknown-elf-gcc (GCC) 9.2.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#安装成功
qemu模拟器安装
- 下载模拟器
$ wget https://download.qemu.org/qemu-5.0.0.tar.xz
$ tar xvJf qemu-5.0.0.tar.xz
- 编译
$ cd qemu-5.0.0
$ ./configure --target-list=riscv64-softmmu,riscv64-linux-user --prefix=/usr/local
$ make
$ sudo make install
- 验证安装
$ qemu-system-riscv64 --version
#有如下提示:
QEMU emulator version 5.0.0
Copyright (c) 2003-2020 Fabrice Bellard and the QEMU Project developers
#安装成功
编译xv6-riscv源码
- 获取
$ git clone https://github.com/mit-pdos/xv6-riscv.git
- 编译
$ cd xv6-riscv/
$ make clean
$ make
- 运行
$ make qemu
# 出现以下情况,代表运行成功
qemu-system-riscv64 -machine virt -bios none -kernel kernel/kernel -m 128M -smp 3 -nographic -global virtio-mmio.force-legacy=false -drive file=fs.img,if=none,format=raw,id=x0 -device virtio-blk-device,drive=x0,bus=virtio-mmio-bus.0
xv6 kernel is booting
hart 2 starting
hart 1 starting
init: starting sh
$
# 退出qemu:ctrl+a x