这里以i386平台为例,介绍OpenBSD的启动流程,NetBSD的启动流程类似。
这个是arch/i386/stand/biosboot/biosboot.S文件开头的注释,实际上它已经详细说
明了系统的启动流程:BIOS加载MBR到0x7C00, 然后把自己拷贝到0x7A00, 然后MBR加载
biosboot.S到0x7C00, biosboot.S加载/boot到 4000:0000, 然后/boot加载内核到相
应的内存,再把控制权传给内核。相应的一些文件都在stand目录下, mbr目录下是MBR
的,boot下是/boot下的,用于从磁盘启动,cdboot下是cdrom的启动代码,pxeboot下
是网络启动的代码,具体的细节就需要读者自己去读代码了。
*
* Memory layout:
*
* 0x00000 -> 0x079FF our stack (to 30k5)
* 0x07A00 -> 0x07BFF typical MBR loc (at 30k5)
* 0x07C00 -> 0x07DFF our code (at 31k)
* 0x07E00 -> ... /boot inode block (at 31k5)
* 0x07E00 -> ... (indirect block if nec)
* 0x40000 -> ... /boot (at 256k)
*
* The BIOS loads the MBR at physical address 0x07C00. It then relocates
* itself to (typically) 0x07A00.
*
* The MBR then loads us at physical address 0x07C00.
*
* We use a long jmp to normalise our address to seg:offset 07C0:0000.
* (In real mode on x86, segment registers contain a base address in
* paragraphs (16 bytes). 0000:00010 is the same as 0001:0000.)
*
* We set the stack to start at 0000:79FC (grows down on i386)
*
* We then read the inode for /boot into memory just above us at
* 07E0:0000, and run through the direct block table (and the first
* indirect block table, if necessary).
*
* We load /boot at seg:offset 4000:0000.
*
此时OpenBSD就进入了arch/i386/i386/locore.S的start:处,当然引导程序会传很
多参数给内核,然后是操作系统的初始化代码了,现在就可以跟着代码读下去了。
第一本要看的书是《The Design of the UNIX Operating System》。这本书是看所有
UNIX操作系统比看的书。
OpenBSD的内核还是比较传统的,如果不管网络,《the Design and Implementation
of the 4.4BSD Operating System》 和uvm作者的博士论文就差不多了。OpenBSD的
网络是一大块,现在我还没有了解过,所以不做说明,还请知道的朋友能否介绍一下。