一、簡單的概括icf的文件,其主要包括以下幾個內(nèi)容,即:
(1)可編址的存儲空間(memory);
(2)不同的存儲地址區(qū)域(region);
(3)不同的地址塊(block);
(4)section的初始化與否;
(5)section在存儲空間的放置。
上面幾點內(nèi)容,如果你對照實際icf文件都會找得到,建議大家嘗試下,會讓你受益匪淺的。
?
二、icf常用命令:
-------------------------------------------------------------------
(1)
define [ exported ] symbol
name = expr;
作用:指定某個符號的值。
參數(shù):
exported
導(dǎo)出該symbol,使其對可執(zhí)行鏡像可用
name 符號名
expr 符號值
舉例:
define symbol RAM_START_ADDRESS = 0x40000000; ?/* ?定義 RAM起始地址 ?*/?
define symbol RAM_END_ADDRESS ?= 0x4000FFFF; ?/* ?定義 RAM結(jié)束地址 ?*/
?
-------------------------------------------------------------------
(2)
define memory name with size = expr [, unit-size];
作用:
定義一個可編址的存儲地址空間(memory)。
參數(shù):
name memory的名稱
expr 地址空間的大小
unit-size expr的單位,可以是位(unitbitsize),缺省是字節(jié)(unitbytesize)
舉例:
define memory MEM with size = 4G;
-----------------------------------------------------------------
(3)
define region name = region-expr;
作用:
定義一個存儲地址區(qū)域(region)。一個區(qū)域可由一個或多個范圍組成,每個范圍內(nèi)地址必須連續(xù),但幾個范圍之間不必是連續(xù)的。
參數(shù):
name region的名稱
region-expr memory:[from expr { to expr | size expr}],可以定義起止范圍,也可以定義起始地址和region的大小
舉例:
define region ROM = MEM:[from 0x0 size 0x10000];?
? ? /* 定義 ROM region,位于地址空間MEM 中,起始地址為0x0,大小為0x10000 字節(jié) ?*/?
define region ROM = MEM:[from 0x0 to 0xFFFF];?
? ? /* 定義 ROM region,位于地址空間MEM 中,起始地址為0x0,結(jié)束地址為0xFFFF */
?
-------------------------------------------------------------------
(4)
define blockname [ with param, param... ]?
{?
extended-selectors?
};?
作用: ? ? 定義一個地址塊(block);它可以是個只保留指定大小的地址空間的空塊,比如棧、堆;也可以包含一系列的sections,由extended-selectors 選擇。?
參數(shù):?
name ? ? block的名稱?
param ? 可以是: ? ? ? ?size = expr ? ? ? (塊的大小)?
? ? ? ? ? ? ? ? ? ?maximum size = expr(塊大小的上限)?
? ? ? ? ? ? ? ? ? ?alignment = expr ?(最小對齊字節(jié)數(shù))?
? ? ? ? ? ? ? ? ? ?fixed order ? ? ? ?(按照固定順序放置sections)?
extended-selector ?[ first | last ] { section-selector | block name | overlay name }?
first ? ? ? ? ?最先存放?
last ? ? ? ? ? ?最后存放?
section-selector [ section-attribute ][ section sectionname ][object filename ]?
section-attribute [ readonly [ code | data ] | readwrite [ code | data ] | zeroinit ]?
sectionname ? ? ?section的名稱?
filename ? ? ? ?目標文件的名稱?
name ? ? ? ? ? ?block或overlay的名稱?
注:這里可以按照section的屬性,名稱及其所在目標文件這三個過濾條件中,任意選取一個條件或多個條件進行組合,來圈定所要求的sections。?
舉例:?
define block HEAP with size = 0x1000, alignment = 4 { };?
? ? /* 定義 HEAP block,大小為0x1000,4 字節(jié)對齊,沒有內(nèi)容 ?*/?
define block MYBLOCK1 = { section mysection1, section mysection2, readwrite };?
? ? ?/* 定義 MYBLOCK1 block,含有mysection1,mysection2,以及所有readwrite 屬性的sections */?
define block MYBLOCK2 = { readwrite object myfile2.o };?
? ? /* 定義 MYBLOCK2 block,含有目標文件myfile2.o 中所有readwrite 屬性的sections */?
define block MYBLOCK3 = { readonly code object myfile3.o };?
? ? /* 定義 MYBLOCK3 block,含有目標文件myfile3.o 中所有readonly 屬性的code sections */?
?
-------------------------------------------------------------------
(5)
initialize { by copy | manually } [ with param, param... ]?
{?
section-selectors?
};?
作用: ? ? ? ? ? ? ?初始化sections?
參數(shù):?
by copy ? ? ? ? ?在程序啟動時自動執(zhí)行初始化?
manually ? ? ? ?在程序啟動時不自動執(zhí)行初始化?
param ? ? ? ? ? ?可以是: ? ? ? ? packing = { none | compress1 | compress2 | auto }?copy routine = functionname?
? ? ? ? ? ? ? ? ?packing表示是否壓縮數(shù)據(jù),缺省是auto?
? ? ? ? ? ? ? ? ?functionname表示是否使用自己的拷貝函數(shù)來取代缺省的拷貝函數(shù)?
section-selector同上?
舉例:?
initialize by copy { readwrite }; ?/* ?在啟動時初始化所有屬性為 readwrite的sections */?
?
--------------------------------------------------------------
(6)
do not initialize?
{?
section-selectors?
};?
作用: ? ? ? ? ? ? ?規(guī)定在程序啟動時不需要初始化的sections;一般用于__no_init 聲明的變量段(.noinit)?
參數(shù):?
section-selector ?同上?
舉例:?
do not initialize { .noinit }; ?/* ?在啟動時不要初始化.noinit section */?
?
-------------------------------------------------------------------
(7)
place at { address memory [:expr] | start of region_expr | end of region_expr }?
{?
extended-selectors?
};?
作用: ? ? ? ? ? ? ? ? ?把section 或 block 放置在某個具體的起始地址處,或者一個 region 的開始或結(jié)束處?
參數(shù):?
memory ? ? ? ? ? ? ? ?memory的名稱?
expr ? ? ? ? ? ? ? ? ?地址值,該地址必須在 memory所定義的范圍內(nèi)?
region_expr ? ? ? ? ? region的名稱?
extended-selector ? ? ?同上?
舉例:?
place at end of ROM { section .checksum }; ? ? ? ? ? ? ? ?/* ?把.checksum放在 ROM region 的最后 ?*/?
place at address MEM:0x0 { section .intvec }; ? ? ? ? ? ? /* ?把.intvec放在地址 0x0 */?
place at address MEM:0x1000 { section .text object myfile.o }; ?/* the .text section of myfile.o */?
place at address MEM:0x1000 { readonly object myfile.o }; ? ? ?/* all read-only sections of myfile.o */?
place at address MEM:0x1000 { readonly data object myfile.o }; /* all read-only data sections of myfile.o */?
?
-------------------------------------------------------------------
(8)
place in region-expr?
{?
extended-selectors?
};?
作用: ? ? ? ? ? ? ? ? ?把section 或 block ?(按任意順序)放置在某個region 中?
參數(shù):?
region-expr ? ? ? ? ? region的名稱?
extended-selector ? ? ?同上?
舉例:?
place in ROM { readonly }; ? ? ? ? ? ? ? /* all readonly sections */?
place in RAM { readwrite }; ? ? ? ? ? ? ?/* all readwrite sections */?
place in RAM { block HEAP, block CSTACK, block IRQ_STACK }; ?/* heap and stacks */?
place in ROM { section .text object myfile.o }; /* the .text section of myfile.o */?
place in ROM { readonly object myfile.o }; /* all read-only sections of myfile.o */?
place in ROM { readonly data object myfile.o }; /* all read-only data sections myfile.o */?