Lab1实验报告
Exercise 3
- At what point does the processor start executing 32-bit code? What exactly causes the switch from 16- to 32-bit mode?
在0x7c2d
处的指令
ljmp $PROT_MODE_CSEG, $protcseg
跳转到了32
位代码处,即从0x7c32
处开始执行32
位代码
在0x7c2a
处开启cr0
寄存器的PE
位,从16
位实模式转换到32
位保护模式
- What is the last instruction of the boot loader executed, and what is the first instruction of the kernel it just loaded?
在0x7d6b
处的指令
call *0x10018
调用内核程序入口,所以这条指令是boot loader
的最后一条指令,通过si
命令可以得出内核的第一条指令,结果如下
(gdb) b *0x7d6b
Breakpoint 1 at 0x7d6b
(gdb) c
Continuing.
The target architecture is assumed to be i386
=> 0x7d6b: call *0x10018
Breakpoint 1, 0x00007d6b in ?? ()
(gdb) si
=> 0x10000c: movw $0x1234,0x472
0x0010000c in ?? ()
- Where is the first instruction of the kernel?
地址为0x10000c
,利用objdump
命令查看内核,结果如下
hiroshi@Hiroshi-PC:~/6.828/lab/obj/kern$ objdump -f kernel
kernel: 文件格式 elf32-i386
体系结构:i386, 标志 0x00000112:
EXEC_P, HAS_SYMS, D_PAGED
起始地址 0x0010000c
- How does the boot loader decide how many sectors it must read in order to fetch the entire kernel from disk? Where does it find this information?
通过Program Header Table
中的信息来决定读取的扇区,利用objdump
命令可以查看内核程序的段信息,结果如下
hiroshi@Hiroshi-PC:~/6.828/lab/obj/kern$ objdump -p kernel
kernel: 文件格式 elf32-i386
程序头:
LOAD off 0x00001000 vaddr 0xf0100000 paddr 0x00100000 align 2**12
filesz 0x0000712f memsz 0x0000712f flags r-x
LOAD off 0x00009000 vaddr 0xf0108000 paddr 0x00108000 align 2**12
filesz 0x0000a300 memsz 0x0000a944 flags rw-
STACK off 0x00000000 vaddr 0x00000000 paddr 0x00000000 align 2**4
filesz 0x00000000 memsz 0x00000000 flags rwx
Exercise 4
- Download the code for pointers.c, run it, and make sure you understand where all of the printed values come from.
这个好理解,主要是int
指针和char
指针增加时,由于字节大小不一致,偏移的位置不一样,导致读取的数据位置不对
Exercise 5
- Change the link address in boot/Makefrag to something wrong, run make clean, recompile the lab with make, and trace into the boot loader again to see what happens.
将地址改为0x7c04
,由于BIOS<