本文为系统启动的相关笔记。

16 位 CPU 寻址 1MB 内存

参考 Real-Mode Memory Management,在 Intel 处理器的 real-mode(中文翻译可能叫「实模式」)中,实际的物理地址是通过 segment + offset 的形式来确认的。

其中 segment register 有以下:

Segment Register Designated Role
CS
Code Segment Register
This register points to the currently active code segment. Used in conjunction with the IP register to point to the next instruction to be fetched and executed by the processor.
DS
Data Segment Register
This register usually points to the default data segment which contains the global and static variables of the active application.
ES
Extra Segment Register
General purpose segment register used mostly for data transfers between different segments.
SS
Stack Segment Register
This register points to the segment containing the active stack. The top of stack is located at address SS:SP.
FS
GS
General Purpose Segment Registers
First introduced on the 80386, these segment registers can be used for any purpose in your application code.

计算方式如下:

image

比如,如果想访问地址 0x12345,可以使用以下汇编实现 [0x1234:0x5] ( segment 0x1234 + offset 0x5):

Mov BX, 1234h
Mov ES, BX
Mov BX, 5h
Mov AL, [ES:BX]

因为 segment 和 offset 是有部分重叠的,所以 0x12345 也能通过 [0x1233:0x15]( segment 0x1233 + offset 0x15) 来访问。

启动区(以 img 文件为例)

参考全网最硬核讲解计算机的启动过程,BIOS 会加载分区的前 512 个字节,并以第 511 和 512 个字节为依据,来判断是否可被引导。

windows101.img 为例,查看第 511 0x1fe 和 512 0x1ff 个字节。

$ xxd -s 0x1f0 -l 32 images/windows101.img
000001f0: 0000 0000 0000 0000 0000 0000 0000 55aa  ..............U.
00000200: f0ff ff03 4000 0560 0007 8000 09a0 000b  ....@..`........

可以看到分别对应的值为 0x55 0xaa, 所以,是个启动盘。

0x55aa

0x55aa 是一个 MBR (Master Boot Record)

image

References