Skip to content

Commit 7089161

Browse files
committed
update xv lab
1 parent ddce6f2 commit 7089161

File tree

22 files changed

+4565
-0
lines changed

22 files changed

+4565
-0
lines changed

content/12-xv6-lab/01-cover.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
author: xnzone
3+
title: xv6(Unix Like OS) Lab
4+
date: 2021-09-10 10:23:32
5+
image: /covers/xv6.jpg
6+
cover: true
7+
weight: 12
8+
tags:
9+
- xv6
10+
- os
11+
---
12+
13+
>xv6课程网址[6.828-2018](https://pdos.csail.mit.edu/6.828/2018/)
14+
15+
## Introduction
16+
xv6 is a teaching operating system developed in the summer of 2006, which we ported xv6 to RISC-V for a new undergraduate class 6.1810.
17+
18+
## xv6 sources and text
19+
20+
The latest xv6 source and text are available via
21+
{{< highlight bash >}}
22+
git clone git://github.com/mit-pdos/xv6-riscv.git
23+
{{< /highlight >}}
24+
25+
and
26+
27+
{{< highlight bash >}}
28+
git clone git://github.com/mit-pdos/xv6-riscv-book.git
29+
{{< /highlight >}}
30+
31+
## Develop
32+
{{< highlight bash >}}
33+
git clone https://pdos.csail.mit.edu/6.828/2018/jos.git
34+
{{< /highlight >}}
35+
36+
{{< highlight bash >}}
37+
docker build -t xv6 .
38+
bash start.sh
39+
{{< /highlight >}}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
author: xnzone
3+
title: xv6环境
4+
date: 1906-01-01
5+
image: https://s2.loli.net/2025/09/24/B9kM2IQLyPN4DRw.jpg
6+
cover: false
7+
weight: 1201
8+
tags: ["xv6", "os"]
9+
---
10+
11+
12+
使用Docker
13+
----------------
14+
由于用macos编译太过于麻烦,所以就安装Docker来进行操作,参考[Docker](/01-xv6-lab/lab0-envs/02-docker)
15+
16+
17+
编译运行
18+
----------------
19+
- `make qemu-nox` 无图形界面编译运行
20+
- `make qemu-nox-gdb` 无图形界面调试运行
21+
- `make run-name` 运行用户程序,例如`make run-hello`运行`user/hello.c`
22+
- `make run-name-nox` `run-name-gdb``run-name-gdb-nox`等等
23+
- `make V=1` 打印正在执行的每一条指令
24+
25+
如果提示需要加载安全路径,gdb在运行的时候,需要带上参数,命令如下
26+
`gdb -iex 'add-auto-load-safe-path .'`
27+
28+
29+
GDB使用
30+
--------------
31+
- `Ctrl-c` 关闭GDB
32+
- `c`或者`continue` 断点执行
33+
- `si` 或者 `stepi` 分步执行
34+
- `b function`或者`b file:line` 给特定的行或者函数设置断点
35+
- `b *addr` 在EIP地址设置断点
36+
- `set print pretty` 对于数组和结构体启用格式化打印
37+
- `info registers` 打印通用寄存器,如eip,eflags和段选择器
38+
- `x/Nx addr` 显示16进制虚拟地址的前N个字,N默认是1,addr可以是任何表达式
39+
- `x/Ni addr` 显示N装配说明,使用$eip,将会显示当前指针介绍
40+
- `symbol-file file` 切换到标志文件
41+
- `thread n` 切换线程,n从0开始
42+
- `info threads` 列出所有线程信息,包括其中的状态和函数
43+
44+
QEMU使用
45+
-------------
46+
- `ctrl-a c`停止qemu
47+
- `xp/Nx paddr` 显示十六进制物理地址的前N位,N默认是1
48+
- `info registers` 显示所有内部寄存器状态,包括隐藏段信息的机器码,中断描述符表,和任务寄存器
49+
50+
比如下面的显示
51+
{{< highlight text >}}
52+
cs =0008 10000000 ffffffff 10cf9a00 DPL=0 CS32 [-R-]
53+
{{< /highlight >}}
54+
55+
1. **cs =0008** 代码选择器可见部分。我们使用段0x8.这也表明全局描述符表(0x8&4=0)和当前特权等级(CPL)为0x8&3=0
56+
2. **10000000** 段基地址。线性地址=逻辑地址+段基地址
57+
3. **ffffffff** 段限制。超过线性地址0xffffffff将会导致段无效错误
58+
4. **10cf9a00** 原生标志段,在接下来的几个字段,QEMU将帮助我们解码
59+
5. **DPL=0** 特权等级段。只有代码在特权等级0上运行的时候才能加载这个段
60+
6. **CS32** 32位代码段。其他值包括数据段`DS`(别和DS寄存器搞混)和局部描述符表(LDT)
61+
7. **[-R-]** 表示这个段只读的
62+
63+
- `info mem` 显示虚拟地址和权限
64+
- `info pg` 显示当前页表结构,输出和`info mem`类似,但是单独给出页入口和页表入口
65+
- `make QEMUEXTRA='-d int' ...`打印所有中断日志
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
author: xnzone
3+
title: Docker
4+
date: 1906-01-01
5+
image: https://s2.loli.net/2025/09/24/B9kM2IQLyPN4DRw.jpg
6+
cover: false
7+
weight: 1202
8+
tags: ["xv6", "os"]
9+
---
10+
11+
## Dockerfile
12+
13+
{{< highlight Dockerfile >}}
14+
FROM ubuntu:16.04
15+
16+
RUN apt-get -qq update
17+
18+
RUN apt-get install -y git build-essential gdb gcc-multilib tmux
19+
20+
RUN git clone http://web.mit.edu/ccutler/www/qemu.git -b 6.828-2.3.0
21+
22+
RUN apt-get install -y libsdl1.2-dev libtool-bin libglib2.0-dev libz-dev libpixman-1-dev
23+
24+
RUN cd qemu && ./configure --disable-kvm --target-list="i386-softmmu x86_64-softmmu" && make && make install && cd ..
25+
26+
ADD ./jos jos
27+
28+
WORKDIR jos
29+
30+
CMD ["/bin/bash"]
31+
{{< /highlight >}}
32+
33+
## startup
34+
35+
{{< highlight bash >}}
36+
joswd=$(pwd)
37+
echo ${joswd}
38+
docker run --rm -it -v ${joswd}/jos:/jos xv6
39+
{{< /highlight >}}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
bookCollapseSection: true
3+
weight: 1200
4+
title: Lab0-环境
5+
date: 2021-09-10
6+
image: https://s2.loli.net/2025/09/24/B9kM2IQLyPN4DRw.jpg
7+
---
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
bookCollapseSection: true
3+
weight: 1210
4+
title: Lab1-引导
5+
date: 2021-09-10
6+
image: https://s2.loli.net/2025/09/24/B9kM2IQLyPN4DRw.jpg
7+
---

0 commit comments

Comments
 (0)