/**
******************************************************************************
* @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。