涉及的硬件与程序如下:
硬件:cpu、内存、硬盘
程序:BIOS、mbr、内核
开机
cpu通电后第一时间读取BIOS。
BIOS提供默认或指定的启动硬盘的编号
BIOS读取硬盘开头的512字节内容(MBR),写入内存0x7c00处。
BIOS结束生命周期,将控制权转交给0x7c00处的程序(MBR)。
mbr依照自己携带的分区表,读取硬盘其他区域的内容,写入指定位置,结束生命周期。
cpu的指针被指向上面被指定的内存位置,从此进入内核初始化周期。
硬盘如何工作?
Mechanically, hard disk drives contain one or more stacked platters that spin under a
read/write head, much like an old record player, only potentially, to increase capacity,
with several records stacked one above the other, where a head moves in and out to get
coverage of the whole of a particular spinning platter's surface; and since a particular
platter may be readible and writable on both of its surfaces, one read/write head may
float above and another below it. Figure 1 shows the inside of a typical hard disk
drive, with the stack of platters and heads exposed. Note that the same idea applies to
oppy disk drives, which, instead of several stacked hard platters, usually have a single,
two-sided oppy disk medium.
The metalic coating of the platters give them the property that specic areas of their
surface can be magnetised or demagnetised by the head, electively allowing any state
to be recorded permanently on them . It is therefore important to be able to describe
the exact place on the disk's surface where some state is to be read or written, and
so Cylinder-Head-Sector (CHS) addressing is used, which electively is a 3D coordinate
system (see Figure 3.9):
Cylinder: the cylinder describes the head's discrete distance from the outer edge
of the platter and is so named since, when several platters are stacked up, you
can visualise that all of the heads select a cylinder through all of the platters
Head: the head describes which track (i.e. which specic platter surface within
the cylinder) we are interested in.
Sector: the circular track is divided into sectors, usually of capacity 512 bytes,
which can be referenced with a sector index.
;
; A simple boot sector program that demonstrates segment offsetting
;
mov ah , 0 x0e ; int 10/ ah = 0eh -> scrolling teletype BIOS routine
mov al , [ the_secret ]
int 0x10 ; Does this print an X?
mov bx , 0 x7c0 ; Can 't set ds directly , so set bx
mov ds , bx ; then copy bx to ds.
mov al , [ the_secret ]
int 0x10 ; Does this print an X?
mov al , [es: the_secret ] ; Tell the CPU to use the es ( not ds) segment.
int 0x10 ; Does this print an X?
mov bx , 0 x7c0
mov es , bx
mov al , [es: the_secret ]
int 0x10 ; Does this print an X?
jmp $ ; Jump forever.
the_secret :
db "X"
; Padding and magic BIOS number.
times 510 -($-$$) db 0
dw 0 xaa55