Lab 0: Environment Set up
https://pdos.csail.mit.edu/6.S081/2023/labs/util.html
https://zhuanlan.zhihu.com/p/464386728
http://www.manongjc.com/detail/56-isregcmascbghji.html
Environment
MacBook Air M2
Sonoma 14.0
I choose use local environment. It will be more convenient to set on the ubuntu.
But when need use gdb I will use ubuntu 22.04 ARM64 on parallels.
Installing on macOS
First, install developer tools:
Next, install Homebrew, a package manager for macOS:
Next, install the RISC-V compiler toolchain:
(The course code not work for me. I download depends on RISC-V compiler toolchain)
Get this tap:
Build the toolchain:
I have to reinstall the riscv-gnu-toolchain
:
$ cd /usr/local/opt/
$ git clone --recursive https://github.com/riscv/riscv-gnu-toolchain
$ ./configure --prefix=/usr/local/opt/riscv-gnu-toolchain
$ make
And then you can test it whether successful:
Environment configuration
The brew formula may not link into /usr/local
. You will need to update your shell's rc file (e.g. ~/.bashrc) to add the appropriate directory to $PATH.
使用
export
: 这会设置一个环境变量,它不仅在当前 shell 会话中可用,而且在从当前会话启动的任何子进程中都可用。这意味着,当你使用export
修改PATH
变量时,从当前 shell 启动的任何程序或脚本都将看到新的PATH
值.
Finally, install QEMU:
Testing your Installation
To test your installation, you should be able to compile and run xv6. You can try this by following the instructions in the first lab.
You can also double check your installation is correct by running the following:
And at least one RISC-V version of GCC:
or
or
Boot xv6
Fetch the git repository for the xv6 source for the lab:
$ git clone git://g.csail.mit.edu/xv6-labs-2023
Cloning into 'xv6-labs-2023'...
...
$ cd xv6-labs-2023
The files you will need for this and subsequent lab assignments are distributed using the Git version control system. For each of the labs you will check out a version of xv6 tailored for that lab. To learn more about Git, take a look at the Git user's manual, or, you may find this CS-oriented overview of Git useful. Git allows you to keep track of the changes you make to the code. For example, if you are finished with one of the exercises, and want to checkpoint your progress, you can commit your changes by running:
$ git commit -am 'my solution for util lab exercise 1'
Created commit 60d2135: my solution for util lab exercise 1
1 files changed, 1 insertions(+), 0 deletions(-)
$
You can keep track of your changes by using the git diff command. Running git diff will display the changes to your code since your last commit, and git diff origin/util will display the changes relative to the initial util
code. Here, origin/util
is the name of the git branch for this lab.
Build and run xv6:
If you type ls
at the prompt, you should see output similar to the following:
$ 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
$ ls
These are the files that mkfs
includes in the initial file system; most are programs you can run. You just ran one of them: ls
.
xv6 has no ps
command, but, if you type Ctrl-p, the kernel will print information about each process. If you try it now, you'll see two lines: one for init
, and one for sh
.
To quit qemu type: Ctrl-a x (press Ctrl and a at the same time, followed by x).
On ubuntu
https://pdos.csail.mit.edu/6.828/2020/tools.html
$ sudo apt-get install git build-essential gdb-multiarch qemu-system-misc gcc-riscv64-linux-gnu binutils-riscv64-linux-gnu
# 单独移除掉qemu的新版本, 因为不知道为什么build时候会卡壳
$ sudo apt-get remove qemu-system-misc
# 额外安装一个旧版本的qemu
$ wget https://download.qemu.org/qemu-5.1.0.tar.xz
$ tar xf qemu-5.1.0.tar.xz
$ cd qemu-5.1.0
$ ./configure --disable-kvm --disable-werror --prefix=/usr/local --target-list="riscv64-softmmu"
# if ERROR: pkg-config binary 'pkg-config' not found, should
# sudo apt-get install pkg-config first
# if ERROR: glib-2.48 gthread-2.0 is required to compile QEMU
# sudo apt-get install libglib2.0-dev
# if ERROR: pixman >= 0.21.8 not present. Please install the pixman devel package.
# sudo apt-get install libpixman-1-dev
$ make
$ sudo make instal
$ cd ..
# 克隆xv6实验仓库
$ git clone git://g.csail.mit.edu/xv6-labs-2020
Cloning into '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 qemu
# 编译成功并进入xv6操作系统的shell
Also can use docker to set up, more details on https://www.bilibili.com/video/BV1Qi4y1o7tN/?spm_id_from=333.880.my_history.page.click&vd_source=73e7d2c4251a7c9000b22d21b70f5635