配置环境
- 1实现环境
- 2更换源
- 3.安装RISC-V交叉编译工具
- 4.安装QEMU
- 5.检测安装
- 6.下载源码
- 7.检查调试工具
- 8.安装vim
- 9.进行初步调试
1实现环境
- 虚拟机(我用的VMware Workstation Pro)
- Ubantu20.04
- 安装QEMU
注意必须使用ubuntu20.04版本,因为后面安装RISC-V交叉编译工具时,某个文件只有ubuntu20.04才有镜像源
2更换源
#2.1 首先备份源列表
sudo cp /etc/apt/sources.list /etc/apt/sources.list_backup
#2.2 打开sources.list文件
sudo gedit /etc/apt/sources.list
#2.3
#中科大源
deb https://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
#添加阿里源
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
#添加清华源
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse multiverse
#2.4刷新列表
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential
3.安装RISC-V交叉编译工具
sudo apt install git build-essential gdb-multiarch qemu-system-misc gcc-riscv64-linux-gnu binutils-riscv64-linux-gnu libglib2.0-dev libpixman-1-dev gcc-riscv64-unknown-elf
4.安装QEMU
在主目录下安装qemu
wget https://download.qemu.org/qemu-5.1.0.tar.xz
tar xvf qemu-5.1.0.tar.xz
cd qemu-5.1.0
./configure --disable-kvm --disable-werror --prefix=/usr/local --target-list="riscv64-softmmu"
make
sudo make install
5.检测安装
riscv64-unknown-elf-gcc --version
预期:riscv64-unknown-elf-gcc (GCC) 10.1.0
qemu-system-riscv64 --version
预期:QEMU emulator version 5.1.0
6.下载源码
git clone git://g.csail.mit.edu/xv6-labs-2020
cd xv6-labs-2020
git checkout util
预期:
Branch 'util' set up to track remote branch 'util' from 'origin'.
Switched to a new branch 'util'
#在项目目录下编译
make
make qemu
ls
#ctrl+a再按x退出qemu
7.检查调试工具
需要开启两个窗口,都是在xv6源码目录下
1.make qemu-gdb
make CPUS=1 qemu-gdb
sed "s/:1234/:26000/" < .gdbinit.tmpl-riscv > .gdbinit
如果第一次使用则需要在终端添加(具体的不记得了,在主目录和xv6目录下都添加下面代码则没错)
echo set auto-load safe-path / >> ~/.gdbinit
2.gdb-multiarch
gdb-multiarch -q kernel/kernel
8.安装vim
为了便于调试,则安装vim并配置vim
sudo apt install vim
#Vim配置
sudo vim /etc/vim/vimrc
##常用配置(其余配置可自行查找)
set ai 自动缩进,与上一行保持一致的自动空格
set ic 在查询模型与匹配模式下忽略大小写
set number 左侧显示行号
set showmatch 显示括号配对,并高亮显示相匹配的括号
set showmode 文本输入模型下,加亮显示模式指示器
set showcmd 在状态栏显示所执行的指令,未完成的指令片段
set warn 长行显示自动折行
set cindent 以C/C++模式缩进
set ruler 打开状态栏标尺
set scrolloff=6 设置光标离窗口上下6行时窗口自动滚动
set tabstop=4 设置Tab长度为4
set wrap 自动换行显示
syntax enable
syntax on 自动语法高亮
#常用命令
##打开文件
vim [文件路径]/[文件名]
##打开并有编辑权限
sudo vim [文件路径]/[文件名]
9.进行初步调试
在xv6目录下打开两个窗口后,用vim打开对应的文件,则可以进行调试。