zoukankan      html  css  js  c++  java
  • u-boot ctr0.S详解 包含_main函数

    /**
    ******************************************************************************
    * @author    Maoxiao Hu
    * @version   V1.0.0
    * @date       Jan-2015
    ******************************************************************************
    * < COPYRIGHT 2015 ISE of SHANDONG UNIVERSITY >
    ******************************************************************************
    **/
    based on u-boot-2014.10。源代码红色标示,其它均为添加的注释。

    ------------脑补区---------------

    本文汇编涉及的指令:ldr , bic , mov , sub , cmp , strlo , addlo , blo , str , bl 。
    不是很清楚的请到我的另外一篇博客《arm汇编指令总结(不断更新)》中集中脑补。

    ----------------------------------

    分析一下 crt0.S 文件开头的一段。crt0.S 位于u-boot-2014.10/arch/arm/lib/crt0.S。
    正如 crt0.S 文件开头所注释的一样:
    1. Set up initial environment for calling board_init_f().This environment only provides a stack and a place to store the GD (‘global data’) structure, both located in some readily available RAM (SRAM, locked cache...). In this context, VARIABLE global data, initialized or not (BSS), are UNAVAILABLE; only CONSTANT initialized data are available.
    最开始先为调用 board_init_f() 设定初始化条件。这个初始化条件就是:设定栈首地址,将栈往下移 GD_SIZE 个大小,然后将刚才经过的这段 SRAM 从头清空(写0)。话不多说看代码:

    ENTRY(_main)

    /*
    * Set up initial C runtime environment and call board_init_f(0).
    */

    ldr sp, =(CONFIG_SYS_INIT_SP_ADDR)

    一路反查定义:

    #define CONFIG_SYS_INIT_SP_ADDR (CONFIG_SYS_LOAD_ADDR - GENERATED_GBL_DATA_SIZE)
    #define CONFIG_SYS_LOAD_ADDR (CONFIG_SYS_SDRAM_BASE + 0x4800000)
    #define GENERATED_GBL_DATA_SIZE 0xC0
    #define CONFIG_SYS_INIT_SP_ADDR (0x40000000 + 0x4800000 - 0xC0)
    #define CONFIG_SYS_INIT_SP_ADDR  0x447FFF40

    最终SP值为0x447FFF40。

    bic sp, sp, #7 /* 8-byte alignment for ABI compliance */

    sp低三位清0。

    mov r2, sp

    保存sp到r2中,现在r2中的值也是0x447FFF40。

    sub sp, sp, #GD_SIZE /* allocate one GD above SP */

     GD_SIZE为184(0xB8),将sp指针向下移184个字节,现在sp为0x447ffe88。

    bic sp, sp, #7 /* 8-byte alignment for ABI compliance */

    sp低三位再次清0。

    mov r9, sp /* GD is above SP */

    保存sp到r9中,现在r9中的值也是0x447ffe88。

    mov r1, sp

    再次保存sp到r1中,现在r1中的值也是0x447ffe88。

    mov r0, #0

    清r0。

    clr_gd:

        cmp r1, r2 /* while not at end of GD */

        现在 r1=0x447ffe88 < r2=0x447FFF40不相等是必然的。

        strlo r0, [r1] /* clear 32-bit GD word */


        addlo r1, r1, #4 /* move to next */


        blo clr_gd

        blo小于则跳转。


    #if defined(CONFIG_SYS_MALLOC_F_LEN) && !defined(CONFIG_SPL_BUILD)
    sub sp, sp, #CONFIG_SYS_MALLOC_F_LEN

    CONFIG_SYS_MALLOC_F_LEN=(1<<10)即0x400,现在sp为0x447ffa88。


    str sp, [r9, #GD_MALLOC_BASE] 

    GD_MALLOC_BASE = 136 (0x88),把sp的值存到r9+ 0x88 = 0x447fff10 地址处。

    NewImage

    #endif
    /* mov r0, #0 not needed due to above code */
    bl board_init_f

  • 相关阅读:
    多项式乘法
    容斥计算多重组合
    D. Tokitsukaze, CSL and Stone Game
    优惠买商品(dp、greedy)
    数星星(单点更新,求前缀和)
    信息推送(单点更新,求前缀和)
    互相送礼物
    Codeforces Round #611 (Div. 3)E. New Year Parties
    多源bfs
    mysql事务和锁
  • 原文地址:https://www.cnblogs.com/humaoxiao/p/4211598.html
Copyright © 2011-2022 走看看