Chinaunix首页 | 论坛 | 博客
  • 博客访问: 361780
  • 博文数量: 64
  • 博客积分: 2975
  • 博客等级: 少校
  • 技术积分: 831
  • 用 户 组: 普通用户
  • 注册时间: 2007-01-14 10:59
文章存档

2014年(2)

2012年(7)

2010年(40)

2009年(5)

2008年(8)

2007年(2)

分类: LINUX

2012-07-09 15:20:52

    .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"
阅读(1284) | 评论(0) | 转发(0) |
0

上一篇:系统启动(4)Grub

下一篇:系统启动(6)main.c

给主人留下些什么吧!~~