MIT 6.828 学习笔记3 Lab1实验报告

这篇博客详细记录了MIT 6.828操作系统课程Lab1的实验过程,包括从16-到32位模式的切换、boot loader如何决定读取内核扇区数、指针问题、链接地址影响、内存映射、printf与console接口、x86的字节序、栈初始化和递归调用的栈结构分析等。博主深入探讨了每个练习的解决步骤和原理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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, 标志 0x00000112EXEC_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<

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值