OS Boot Sequence

当BIOS INT 19h被执行以后,系统进入OS Booting阶段。

下面定义几个程序段名称:

Name Description Size limit
Master Booter 放置于Hard disk的第一个扇区(即MBR),用于装载boot block的程序。 466 bytes
Boot Sector 放置与Floppy的第一个扇区,或者Hard disk的某一分区的第一个扇区的用于装载Secondary boot,或其它程序的可运行程序。 512 bytes
Secondary Boot 放置于非Floppy/Hard disk的第一个扇区,以及Hard disk的任意分区的第一个扇区之外的任意其它位置,用于装载OS,或其它程序的可运行程序。 no limit

当用硬盘启动OS的时候,以上调用顺序为 MB -> BS -> SB -> OS;

当用软盘启动OS的时候,以上调用顺序为 BS -> SB -> OS。

当机器被打开时,等电源稳定之后,电源会发送一个“加电成功信号”给芯片,以启动时钟生成器(8284);

1.2.4.2 软盘启动

相对于硬盘启动过程,软盘启动则要简单的多,只需要将boot sector程序放置于软盘的第一个扇区。当INT 19从软盘启动的时候,会自动将boot sector读入内存的7C00h的位置,然后跳转到7C00h开始执行。

1.2.4.1 硬盘启动

硬盘的第一个扇区(sector)被称作MBRMaster Boot Record)。由于硬盘可以有多个分区,所以MBR上,不仅放置着用于启动的可执行代码master boot,还放着磁盘分区表(DPT),占用66个字节,所以MBR中的可执行代码必须在512 - 66 = 446个字节以内。

Offset Content Size
0h Master booting program max 466 bytes
01BEh Disk Partition Table 64 bytes
01FEh Signature (HEX 55 AA) 2 bytes

Table 1.2.1- MBR Layout

Offset Content Size
01BEh Partition 1 data table 16 bytes
01CEh Partition 2 data table 16 bytes
01DEh Partition 3 data table 16 bytes
01FEh Partition 4 data table 16 bytes

Table 1.2.2 - DPT Layout

Offset Content Data Type
00h boot indicator byte
01h beginning sector head number byte
02h beginning sector (2 high bits of cylinder #) byte
03h beginning cylinder# (low order bits of cylinder #) byte
04h system indicator byte
05h ending sector head number byte
06h ending sector (2 high bits of cylinder #) byte
07h ending cylinder# (low order bits of cylinder #) byte
08h number of sectors preceding the partition dword(4 bytes)
0Bh number of sectors in the partition dword

Table 1.2.3 - Layout of Partition Data Table

Boot indicator (BYTE)

       00 - non-bootable partition

       80 - bootable partition (one partition only)

System Indicator (BYTE)

       00 - unknown operating system

       01 - DOS with 12 bit FAT, 16 bit sector number

       02 - XENIX

       04 - DOS with 16 bit FAT, 16 bit sector number

       05 - DOS Extended partition (DOS 3.3+)

       06 - DOS 4.0 (Compaq 3.31), 32 bit sector number

       51 - Ontrack extended partition

       64 - Novell

       75 - PCIX

       DB - CP/M

       FF – BBT

Signature

       Hex 55AA marks the end of valid boot sector.

       This is also required in each of the partition boot records.

OS Boot Sequence_第1张图片

What does master booter should do?

        INT 19会将MBR512 bytes load到内存0x7c00中,然后JUMP0x7c00处,开始执行MBR的可执行程序master booter,Master booter最起码需要做这些事情:

  • 检测MAGICSignature)是否为合法值(Hex 55AA);
  • 将自己移动到其它位置,将0x7C000x7c00+512K的空间让出来,以备其后将boot sector程序装入这个位置,这样才能和直接从软盘直接装入boot sector程序相一致;具体移动到什么位置,则根据设计而定,理论上,可以移动到任何非冲突位置(即没有被预留为其它程序所用的位置);但一般情况下,都是在0X0008000X0A0000之间寻找一端空间存放。

  • 查看分区表,将被设为活动的分区的第一个Sector装入0X7C00的位置,正常的情况下,此Sector放置的就是boot sector程序;

  • 最终,master booter跳转到0X7C00的位置,开始执行boot sector

OS Boot Sequence_第2张图片 

你可能感兴趣的:(OS,dos,table,byte,hex,disk)