MIT 6.828 Lab 1: Booting a PC

Preface

Our environment: 1. Host: Mac Air 2. Virtualbox: Ubuntu 14.04

Install The QEMU

MIT6.828 uses QEMU as simulator. To install QEMU, we use the command like:

1
sudo apt-get install qemu

Part 1: PC Bootstrap

1
2
3
git clone https://pdos.csail.mit.edu/6.828/2018/jos.git lab
cd lab
make

Well, error like "undefined reference to '__udivdi3'" happen. The reason is that we don't have 32-bit gcc multilib. Install it by the following command:

1
sudo apt-get install gcc-4.8-multilib

Then just run

1
make qemu
You will see the following outputs:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
qemu-system-i386 -drive file=obj/kern/kernel.img,index=0,media=disk,format=raw -serial mon:stdio -gdb tcp::26000 -D qemu.log 
6828 decimal is XXX octal!
entering test_backtrace 5
entering test_backtrace 4
entering test_backtrace 3
entering test_backtrace 2
entering test_backtrace 1
entering test_backtrace 0
leaving test_backtrace 0
leaving test_backtrace 1
leaving test_backtrace 2
leaving test_backtrace 3
leaving test_backtrace 4
leaving test_backtrace 5
Welcome to the JOS kernel monitor!
Type 'help' for a list of commands.
K>

Exercise 3

先看一下要求: *Exercise 3. Take a look at the lab tools guide, especially the section on GDB commands. Even if you're familiar with GDB, this includes some esoteric GDB commands that are useful for OS work.

Set a breakpoint at address 0x7c00, which is where the boot sector will be loaded. Continue execution until that breakpoint. Trace through the code in boot/boot.S, using the source code and the disassembly file obj/boot/boot.asm to keep track of where you are. Also use the x/i command in GDB to disassemble sequences of instructions in the boot loader, and compare the original boot loader source code with both the disassembly in obj/boot/boot.asm and GDB.

Trace into bootmain() in boot/main.c, and then into readsect(). Identify the exact assembly instructions that correspond to each of the statements in readsect(). Trace through the rest of readsect() and back out into bootmain(), and identify the begin and end of the for loop that reads the remaining sectors of the kernel from the disk. Find out what code will run when the loop is finished, set a breakpoint there, and continue to that breakpoint. Then step through the remainder of the boot loader.*

为什么说 0x7c00 这个地址很特殊 我的执行建议 1. 先过一遍 lab tools guide 的 GDB 部分,方便GDB 调试, 附上lab tools guide 链接: https://pdos.csail.mit.edu/6.828/2018/labguide.html 2. 我们会用到的 GDB 指令 + b function or b file:line: 打断点 + b *addr : 在EIP addr 处打断点。 + c*: 继续执行直到断点

看一下具体的要求: 1. 跟踪 /boot/boot.S 的执行过程, 可以采用 obj/boot/boot.asm 来进行跟踪(trace through) 2.