我使用的环境是VMware虚拟机,系统为Ubuntu20.04
工具链
安装软件包
1
| $ sudo apt-get install git build-essential gdb-multiarch qemu-system-misc gcc-riscv64-linux-gnu binutils-riscv64-linux-gnu
|
这里有个需要注意的点是之后执行 make qemu 且脚本在
1
| qemu-system-riscv64 -machine virt -bios none -kernel kernel/kernel -m 128M -smp 3 -nographic -drive file=fs.img,if=none,format=raw,id=x0 -device virtio-blk-device,drive=x0,bus=virtio-mmio-bus.0
|
之后出现挂起,则需要卸载该软件包并安装旧版本:
1 2
| $ sudo apt-get remove qemu-system-misc $ sudo apt-get install qemu-system-misc=1:4.2-3ubuntu6
|
这里我也遇到了此情况,但重装软件包后仍然挂起,后续检查发现是我的qemu版本太高,后面自己从官网下载了5.1.0版本后重新安装了qemu就能正常运行了
测试安装
若要测试安装,应能够检查以下内容:
1 2 3 4 5 6
| $ riscv64-unknown-elf-gcc --version riscv64-unknown-elf-gcc (GCC) 10.1.0 ...
$ qemu-system-riscv64 --version QEMU emulator version 5.1.0
|
下载源码
我做的是2020年的lab
1
| $ git clone git://g.csail.mit.edu/xv6-labs-2020
|
下载后进入文件夹切换一个分支后,make qemu 后能正常运行即代表环境配置成功
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| $ cd xv6-labs-2020 $ git checkout util $ make qemu riscv64-unknown-elf-gcc -c -o kernel/entry.o kernel/entry.S riscv64-unknown-elf-gcc -Wall -Werror -O -fno-omit-frame-pointer -ggdb -DSOL_UTIL -MD -mcmodel=medany -ffreestanding -fno-common -nostdlib -mno-relax -I. -fno-stack-protector -fno-pie -no-pie -c -o kernel/start.o kernel/start.c ... riscv64-unknown-elf-ld -z max-page-size=4096 -N -e main -Ttext 0 -o user/_zombie user/zombie.o user/ulib.o user/usys.o user/printf.o user/umalloc.o riscv64-unknown-elf-objdump -S user/_zombie > user/zombie.asm riscv64-unknown-elf-objdump -t user/_zombie | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$/d' > user/zombie.sym mkfs/mkfs fs.img README user/xargstest.sh user/_cat user/_echo user/_forktest user/_grep user/_init user/_kill user/_ln user/_ls user/_mkdir user/_rm user/_sh user/_stressfs user/_usertests user/_grind user/_wc user/_zombie nmeta 46 (boot, super, log blocks 30 inode blocks 13, bitmap blocks 1) blocks 954 total 1000 balloc: first 591 blocks have been allocated balloc: write bitmap block at sector 45 qemu-system-riscv64 -machine virt -bios none -kernel kernel/kernel -m 128M -smp 3 -nographic -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 $
|
ctrl + A 松开后按 X 键退出 qemu