#
# 这段代码被连接到system模块的最前面,这也是它为什么称之为head.s的原因。
# 从这里开始内核完全运行在保护模式下。head.s采用的是at&t格式的
# 汇编。注意的是代码中的赋值方向是从左到右。
#
# 这段程序实际上是出于内存的绝对地址0开始处。首先是加载各个数据段寄存器。
# 重新设置全局描述符表gdt --> 检测a20地址线是否真的开启,没有开启,loop
# 掉了 --> 检测pc是否含有数学协处理器 --> 设置管理内存分页的处理机制 -->
# 将页目录放置在内存地址0开始处。所以这段程序将被覆盖掉。 --> 最后利用ret
# 指令弹出预先压入的/init/main.c程序的入口地址,去运行main.c程序。
#
/*
* linux/boot/head.s
*
* (C) 1991 Linus Torvalds
*/
/*
* head.s contains the 32-bit startup code.
*
* NOTE!!! Startup happens at absolute address 0x00000000, which is also where
* the page directory will exist. The startup code will be overwritten by
* the page directory.
*/
.text
.globl _idt,_gdt,_pg_dir,_tmp_floppy_area
_pg_dir: #页目录将会存放在这里
startup_32:
#############################################
# 设置段寄存器
# 再次注意,现在程序已经运行在32模式,因此这里
# 的0x10并不是把地址0x10装入各个段寄存器,它现在
# 是全局段描述符表的偏移量。这里的0x10正好指向
# 在setup.s中设置的数据段的描述符。
#
# 下面代码的含义是,置ds,es,fs,gs中的选择符
# 为setup.s中构造的数据段,并将堆栈放置在数据段
# _stack_start数组内,然后使用新的中断描述符表
# 和全局描述符表,新的全局段描述符表中初始化内
# 容和setup.s中完全相同。
#
#
movl $0x10,%eax
mov %ax,%ds
mov %ax,%es
mov %ax,%fs
mov %ax,%gs
#############################################
# 加载堆栈指针寄指令
# long user_stack [ PAGE_SIZE>>2 ] ;
#
# struct {
# long * a;
# short b;
# } stack_start = { & user_stack [PAGE_SIZE>>2] , 0x10 };
#
lss _stack_start,%esp # 设置系统堆栈段
# _stack_start -> ss:esp
call setup_idt
call setup_gdt
############################################
# 因为修改了gdt,需要重新加载所有的段寄存器。
movl $0x10,%eax # reload all the segment registers
mov %ax,%ds # after changing gdt. CS was already
mov %ax,%es # reloaded in 'setup_gdt'
mov %ax,%fs
mov %ax,%gs
lss _stack_start,%esp
#############################################
# 下面检测是否开启a20地址线采用的方法是向0x000000
# 处写入一个数值,然后看内存地址0x100000处是否也是
# 这个数值。如果一直相同的话,loop死掉。
#
xorl %eax,%eax
1: incl %eax # check that A20 really IS enabled
movl %eax,0x000000 # loop forever if it isn't
cmpl %eax,0x100000
je 1b
/*
* NOTE! 486 should set bit 16, to check for write-protect in supervisor
* mode. Then it would be unnecessary with the "verify_area()"-cal