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

转载于:https://www.cnblogs.com/humaoxiao/p/4211598.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值