linux内核学习(12)启动全过程概述之三

本文详细介绍了Linux内核启动过程,从arch/x86/compressed/head_32.S开始,讲解了解压缩、段寄存器加载、内存对齐、内核映像的临时定位、栈设置、BSS段清零、GOT调整、解压缩和最终跳转到解压缩后的内核等步骤。通过对关键代码的分析,揭示了内核启动的细节。
摘要由CSDN通过智能技术生成

进入了vmlinux内核映像部分,就进入了arch/x86/compressed/head_32.S。这个文件主要工作就是解压了,将真正的内核给释放出来,不过还得把这个文件分析完,内核才能出世。

来自arch/x86/compressed/head_32.S:

........省略了头文件......

__HEAD
ENTRY(startup_32)
    cld           /*di,si++*/
    /*
     * Test KEEP_SEGMENTS flag to see if the bootloader is asking
     * us to not reload segments
     */
    testb    $(1<<6), BP_loadflags(%esi)   /*esi = boot_params*/
    jnz    1f
# esi是之前就设置好了的,boot_params结构体的首地址,而loadflags的位6如果置位,则表示需要将段寄存器重新载入
    cli        /*close interrupt*/
    movl    $__BOOT_DS, %eax
    movl    %eax, %ds
    movl    %eax, %es
    movl    %eax, %fs
    movl    %eax, %gs
    movl    %eax, %ss
1:

/*
 * Calculate the delta between where we were compiled to run
 * at and where we were actually loaded at.  This can only be done
 * with a short local call on x86.  Nothing  else will tell us what
 * address we are running at.  The reserved chunk of the real-mode
 * data at 0x1e4 (defined as a scratch field) are used as the stack
 * for this calculation. Only 4 bytes are needed.
 */
    leal    (BP_scratch+4)(%esi), %esp  /*boot_params->scratch*/
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值