在操作系统中刚进行加电启动电脑的时候是不存在对文件的处理的。所以对于系统模块载入内存期间,在屏幕上出现的“loading”并不是用printf这种文件操作实现的,而只是通过最原始的汇编进行的。
操作系统中必须存在一个根文件系统,其他文件系统挂载其上。linux0.11没有提供设备上建立文件系统的工具,故必须在一个正在运行的系统中利用工具例如(FDISK)做一个文件系统并加载在本机中。因此在操作系统启动的时候需要两个部分的数据分别是系统内核镜像和根文件系统。
在bootsect.s文件中根文件系统加载部分的汇编代码如下图所示:
! After that we check which root-device to use. If the device is
! defined (!= 0), nothing is done and the given device is used.
! Otherwise, either /dev/PS0 (2,28) or /dev/at0 (2,8), depending
! on the number of sectors that the BIOS reports currently.
seg cs
mov ax,root_dev
cmp ax,#0
jne root_defined !如果ax通过比较不等于0,则什么事情都不做,否则进行下面的操作
seg cs
mov bx,sectors !bx表示的是扇区数
mov ax,#0x0208 ! 挂载/dev/ps0 - 1.2Mb (/dev/at0 (2,8))
cmp bx,#15 !比较扇区数是否和15相等
je root_defined
mov ax,#0x021c ! 挂载/dev/PS0 - 1.44Mb (/dev/PS0 (2,28))
cmp bx,#18
je root_defined
undef_root:
jmp undef_root
root_defined:
seg cs
mov root_dev,ax
因为刚接触深入接触操作系统底层,如果有任何理解上的错误,欢迎评论指正,共同讨论学习。