前言
又开新坑了。选这门课是因为吃了CS自学指南的安利以及被某人催着自学。课是好课,不过做实验看起来有些难度,所以做个留档。
个人环境
放一个实验环境(neofetch)在这里做参考。
text复制代码
1 'c. palemoons@MacBookPro 2 ,xNMM. -------------------- 3 .OMMMMo OS: macOS 12.1 21C52 arm64 4 OMMM0, Host: MacBookPro17,1 5 .;loddo:' loolloddol;. Kernel: 21.2.0 6 cKMMMMMMMMMMNWMMMMMMMMMM0: Uptime: 1 day, 7 hours, 36 mins 7 .KMMMMMMMMMMMMMMMMMMMMMMMWd. Packages: 193 (brew) 8 XMMMMMMMMMMMMMMMMMMMMMMMX. Shell: zsh 5.8 9;MMMMMMMMMMMMMMMMMMMMMMMM: Resolution: 1440x900 10:MMMMMMMMMMMMMMMMMMMMMMMM: DE: Aqua 11.MMMMMMMMMMMMMMMMMMMMMMMMX. WM: Quartz Compositor 12 kMMMMMMMMMMMMMMMMMMMMMMMMWd. WM Theme: Blue (Dark) 13 .XMMMMMMMMMMMMMMMMMMMMMMMMMMk Terminal: iTerm2 14 .XMMMMMMMMMMMMMMMMMMMMMMMMK. Terminal Font: Monaco 14 15 kMMMMMMMMMMMMMMMMMMMMMMd CPU: Apple M1 16 ;KMMMMMMMWXXWMMMMMMMk. GPU: Apple M1 17 .cooc,. .,coo:. Memory: 2139MiB / 16384MiB
环境配置
进行所有实验之前,我们先需要启动课程提供的操作系统xv6。
除了包管理器homebrew,还需要安装编译工具链riscv-tools
以及虚拟机qemu
。前者安装比较顺利,直接按照实验操作手册里面的步骤来就行。比较麻烦的是高版本的qemu无法正常启动xv6,这导致不能用homebrew直接安装qemu(它只提供最新版本),为此只能编译特定版本的源码。
根据测试,下载v5.1.0
版本的源码后,再打两个补丁即可正常安装qemu并启动xv6。
-
前往qemu官网下载页面选择5.1.0版本下载并解压。
-
为了加快编译速度以及避免编译全平台架构时挂掉,只选择编译
riscv64-softmmu
。配置如下:sh复制代码1./configure --disable-kvm --disable-werror --prefix=/usr/local --target-list="riscv64-softmmu"
设置
target-list
很重要,否则很容易在某些奇怪的地方报错导致全部木大。 -
make && make install
到这里qemu安装完成,按照实验手册来即可正常启动xv6。
text复制代码
1palemoons@MacBookPro ~/Documents/xv6-labs-2020 (util) $ make qemu 2qemu-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 3 4xv6 kernel is booting 5 6hart 1 starting 7hart 2 starting 8init: starting sh 9$
Gdb配置
Updated on 2022.3.10
Lecture3中提到了使用gdb调试程序,此处添加对于gdb的启动记录。
之前下载的riscv工具链里已经自带了gdb,且Mac M1也能正常使用,因此可以直接尝试启动。
sh复制代码1make CPUS=1 qumu-gdb #窗口1中”调试模式“启动
2riscv64-unknown-elf-gdb #窗口2中启动gdb
这里没有直接成功,出现了以下警告:
text复制代码
1GNU gdb (GDB) 10.1 2Copyright (C) 2020 Free Software Foundation, Inc. 3License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> 4This is free software: you are free to change and redistribute it. 5There is NO WARRANTY, to the extent permitted by law. 6Type "show copying" and "show warranty" for details. 7This GDB was configured as "--host=arm-apple-darwin21.2.0 --target=riscv64-unknown-elf". 8Type "show configuration" for configuration details. 9For bug reporting instructions, please see: 10<https://www.gnu.org/software/gdb/bugs/>. 11Find the GDB manual and other documentation resources online at: 12 <http://www.gnu.org/software/gdb/documentation/>. 13 14For help, type "help". 15Type "apropos word" to search for commands related to "word". 16warning: File "/Users/palemoons/Documents/xv6-labs-2020/.gdbinit" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load". 17To enable execution of this file add 18 add-auto-load-safe-path /Users/palemoons/Documents/xv6-labs-2020/.gdbinit 19line to your configuration file "/Users/palemoons/.gdbinit". 20To completely disable this security protection add 21 set auto-load safe-path / 22line to your configuration file "/Users/palemoons/.gdbinit". 23For more information about this security protection see the 24"Auto-loading safe path" section in the GDB manual. E.g., run from the shell: 25 info "(gdb)Auto-loading safe path" 26(gdb)
大意是初始化文件.gdbinit
的自动加载被禁用,这里程序建议添加全局配置文件把该工作区的初始化文件添加进自动加载列表。有兴趣可以试试,反正我没设置成功。也可以直接手动加载.gdbinit
文件,在gdb环境下source .gdbinit
。
text复制代码
1(gdb) source .gdbinit 2The target architecture is set to "riscv:rv64". 3warning: No executable has been specified and target does not support 4determining executable automatically. Try using the "file" command. 50x0000000000001000 in ?? () 6(gdb)
实验自带的.gdbinit
文件中,有对于监听端口的设置,需要把端口修改到实际对应的端口上。
References
参考了两个issue:
gdb配置参考了一篇博客: