ucore Lab0~1 一些杂记
前一阵子开始做 MIT 6.828,做了两三个实验才发现清华的 ucore 貌似更友好一些,再加上前几个实验也与6.828 有所重叠,于是决定迁移阵地。
文章计划分两类,一类是代码的分析,另一类是实验的解答和比较。
1. 计算机执行第一条指令之前,分段状态是怎样的?
执行make debug
, 然后考察 QEMU monitor 中 GDT 的值:
GDT= 00000000 0000ffff
参考 GDTR 寄存器:
[外链图片转存失败(img-sq24lnSm-1567514113749)(https://github.com/libinyl/CS-notes/blob/master/images/intel/v3/Figure%202-6.%20Memory%20Management%20Registers.png?raw=true)]
参考手册 2.4.1 节描述:
On power up or reset of the processor, the base address is set to the default value of 0 and the limit is set to 0FFFFH. A new base address must be loaded into the GDTR as part of the processor initialization process for protected-mode operation.
结论 计算机执行第一条指令前,也就是重置状态,全局描述符表区域被默认设置为,基址=0,limit=0FFFFH, 似乎是把整个内存空间都视作GDT,其本质上没有分段.
2. 怎样验证生成的磁盘文件是合法的 elf 文件?
期望: 磁盘的第 510 个(倒数第二个)字节是 0x55, 第 511 个(倒数第一个)字节是 0xAA.
验证:
cd ~/ucore_os_lab/labcodes_answer/lab1_result
make $(call totarget,ucore.img)
输出结果:
//省略。..
000001e0 05 42 86 03 83 04 00 00 00 00 01 00 00 02 00 00 |.B..............|
000001f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa <-得证 |..............U.|
//省略。..
原理 sign.c
用于将一个二进制文件构建为一个磁盘文件。
3. bootloader 被如何加载到内存中?
前置问题 bootloader 如何生成?
考察 Makefile
,参考实验报告中关于 make 的流程可知,ucore.img
由bootblock
和kernel
合并而成.bootloader ,有效的 elf 文件是 /obj/bootblock.o
; kernel 的有效 elf 文件是 bin/kernel
.
BIOS
把磁盘的第一个扇区作为 bootloader,即把磁盘的前 512 字节加载进来.
4. kernel 希望自己怎样加载到内存中,提供了哪些信息?
考察 kernel:
执行readelf -a kernel|less
:
其中由
Progr