.section ".entrytext", "ax"
start_of_setup:
#ifdef SAFE_RESET_DISK_CONTROLLER
# Reset the disk controller.重置磁盘控制器
movw $0x0000, %ax # Reset disk controller
movb $0x80, %dl # All disks
int $0x13
#endif
# Force %es = %ds 使es和ds相等,grub已保证相等,且为0x9000
movw %ds, %ax
movw %ax, %es
cld
# Apparently some ancient versions of LILO invoked the kernel with %ss != %ds,
# which happened to work by accident for the old code. Recalculate the stack
# pointer if %ss is invalid. Otherwise leave it alone, LOADLIN sets up the
# stack behind its own code, so we can't blindly put it directly past the heap.
movw %ss, %dx
cmpw %ax, %dx # %ds == %ss?
movw %sp, %dx # %sp值为0x9000
je 2f # -> assume %sp is reasonably set
# Invalid %ss, make up a new stack
movw $_end, %dx
testb $CAN_USE_HEAP, loadflags
jz 1f
movw heap_end_ptr, %dx
1: addw $STACK_SIZE, %dx
jnc 2f
xorw %dx, %dx # Prevent wraparound
2: # Now %dx should point to the end of our stack space
andw $~3, %dx # dword align (might as well...)
jnz 3f #跳到3f
movw $0xfffc, %dx # Make sure we're not zero
3: movw %ax, %ss #0x9000
movzwl %dx, %esp # Clear upper half of %esp 0x9000
sti # Now we should have a working stack
# We will have entered with %cs = %ds+0x20, normalize %cs so
# it is on par with the other segments.
pushw %ds #grub中cs值为0x9020,规范化为0x9000
pushw $6f
lretw
6:
# Check signature at end of setup
cmpl $0x5a5aaa55, setup_sig
/*
在setup.ld中
.signature : {
setup_sig = .;
LONG(0x5a5aaa55)
}
*/
jne setup_bad
# Zero the bss清空 bss
movw $__bss_start, %di #setup.ld
movw $_end+3, %cx # +3,上对齐
xorl %eax, %eax
subw %di, %cx
shrw $2, %cx
rep; stosl
/*
在setup.ld中
. = ALIGN(16);
.bss :
{
__bss_start = .;
*(.bss)
__bss_end = .;
}
. = ALIGN(16);
_end = .;
*/
# Jump to C code (should not return)
calll main #调用main,在main.c中
# Setup corrupt somehow...
setup_bad:
movl $setup_corrupt, %eax
calll puts #在tty.c中
# Fall through...
.globl die
.type die, @function
die:
hlt
jmp die
.size die, .-die
.section ".initdata", "a"
setup_corrupt:
.byte 7
.string "No setup signature found...\n"