啓動代碼中關於變量的初始化

對於一個標準C程序所用到的全局和靜態變量都是定位在固定的內存空間,在程序啓動時必須賦予確定的數值,對於程序中沒有賦初值的變量,編譯器默認賦值爲0。對於__no_init限定的變量則不會被初始化。

對於一個標準的C程序中用到的變量類別如下 Categories of declared data 所示,




L(1) 初始化過程

需要初始化爲0sectionILINK中放置在RAM中。需要被初始化的section需要放置在initialize指令列表中,不包括初始化爲0section

通常在鏈接中,需要被初始化的塊分爲兩個section一個section變量的名字,一個section保存變量的初始值。例子,一個.data section被分割爲.data .data_init

 

包含常量的section不用初始化,放置在ROM/FLASH

 

__no_init指令定義的變量不需初始化,因此將.noinit放在 do not initialize指令列表下,這些變量放置在RAM

 

L(2) icf中,關於數據的鏈接內容例下


do not initialize { section .noinit };

/* Initialize RW sections,exclude zero-initialized sections */ 

initialize by copy { readwrite }; 


/* Place startup code at a fixed address */

place at start of ROM { readonly section .cstartup };


/* Place code and data */

/* Place constants and initializers in ROM: .rodata and .data_init */


place in ROM { readonly }; 

/* Place .data, .bss, and .noinit  and STACK */

place in RAM { readwrite, block STACK };



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章