OS Boot Sequence

来源:互联网 发布:中文域名骗局中科瑞 编辑:程序博客网 时间:2024/06/07 17:25

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

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

NameDescriptionSize limitMaster Booter放置于Hard disk的第一个扇区(即MBR),用于装载boot block的程序。466 bytesBoot Sector放置与Floppy的第一个扇区,或者Hard disk的某一分区的第一个扇区的用于装载Secondary boot,或其它程序的可运行程序。512 bytesSecondary 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个字节以内。

OffsetContentSize0hMaster booting programmax 466 bytes01BEhDisk Partition Table64 bytes01FEhSignature (HEX 55 AA)2 bytes

Table 1.2.1- MBR Layout

OffsetContentSize01BEhPartition 1 data table16 bytes01CEhPartition 2 data table16 bytes01DEhPartition 3 data table16 bytes01FEhPartition 4 data table16 bytes

Table 1.2.2 - DPT Layout

OffsetContentData Type00hboot indicatorbyte01hbeginning sector head numberbyte02hbeginning sector (2 high bits of cylinder #)byte03hbeginning cylinder# (low order bits of cylinder #)byte04hsystem indicatorbyte05hending sector head numberbyte06hending sector (2 high bits of cylinder #)byte07hending cylinder# (low order bits of cylinder #)byte08hnumber of sectors preceding the partitiondword(4 bytes)0Bhnumber of sectors in the partitiondword

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.

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

 

原创粉丝点击