Part2 基本語法 2.1 BNF 符號與語法 " :由引號賴標示的符號保持其字面原意,如A” ”B標示A B。 A ::= B :定義A爲B。 [A] :標示可選部分,如A[B]C用來標示ABC或AC。 A :用來標示A可以重複任意次,如A 可標示A,AA,AAA, … A* :同A 。 A | B :用來標示選擇其一,不能全選。如A|B用來標示A或者B。 (A B) :標示一個整體,當和|符號或複雜符號的多次重複一起使用時尤其強大,如(AB) (C|D)標示ABC,ABD,ABABC,ABABD, … 2.2 分散加載文件各部分描述 (2.1) 如圖2.1所示爲一個完整的分散加載腳本描述結構圖。下面我們對圖示中各個部分進行講述。 2.2.1 加載區描述 每個加載區有: ó名稱:供連接器確定不同下載區域 ó基地址:相對或絕對地址 ó屬性:可選 ó最大字節數:可選 ó執行區域列:確定執行時各執行區域的類型與位置 load_region_name (base_address | (" " offset)) [attribute_list] [ max_size ] "{" execution_region_description "}"
load_region_name:下載區域名稱,最大有效字符數31。(並不像執行區域段名用於Load$$region_name,而是僅僅用於標示下載區域)。 base_address:本區域內部目標被連接到的地址(按字對齊)。 offset:相對前一個下載區域的偏移量(4的整數倍,如果爲第一個區域)。
2.2.2 執行區描述 每個執行區有: ó名稱:供連接器確定不同下載區域 ó基地址:相對或絕對地址 ó屬性:確定執行區域的屬性 ó最大字節數:可選 ó輸入段:確定放在該執行區域的模塊 exec_region_name (base_address | " " offset) [attribute_list] [max_size] "{" input_section_description "}" exec_region_name:執行區域名稱,最大有效字符數31。 base_address:本執行區域目標要被聯接到的位置,按字對齊。 offset:相對於前一個執行區域結束地址的偏移量,4的整數倍;如果沒有前繼之能夠行區域(本執行區域爲該下載區域的第一個執行區域),則該偏移量是相對於該下載區域的基址偏移量。 attribute_list:PI,OVERLAY,ABSOLUTE,FIXED,UNINIT。 PI: 位置獨立。 OVERLAY: 覆蓋。 ABSOLUTE: 絕對地址。 FIXED: 固定地址,下載地址與執行地址具有該地址指示確定。 UNINIT: 未初始化數據。 RELOC:無法明確指定執行區域具有該屬性,而只能通過繼承前一個執行區或父區域獲得。 對於PI,OVERLAY,ABSOLUTE,FIXED,我們只能選擇一個,缺省屬性爲ABSOLUTE。一個執行區域要麼直接繼承其前面的執行區域的屬性或者具有屬性爲ABSOLUTE。 具有PI,OVERLAY,RELOC屬性的執行區域允許其地址空間重疊,對於BSOLUTE,FIXED 屬性執行區域地址空間重疊Armlink會報錯。 max_size:可選,他用於指使Armlink在實際分配空間大於指定值時報錯。 input_section_description:指示輸入段的內容。
2.2.3 輸入段描述 輸入段: ó模塊名:目標文件名,庫成員名,庫文件名。名稱可以使用通配符。 ó輸入段名,或輸入段屬性(READ-ONLY,CODE)。 module_select_pattern ["(" (" " input_section_attr | input_section_pattern) ([","] " " input_section_attr | "," input_section_pattern))* ")"] 2.2.3.1 module_select_pattern:選擇的模塊名稱(目標文件,庫文件成員,庫文件),模塊名可以使用通配符(*匹配任意多個字符,?匹配任意一個字符),名稱不區分字母大小寫,它是供選擇的樣本。 例1:*libtx.a ( RO) libtx.a爲threadX庫文件。 例2:tx_ill.o (INIT) tx_ill.o爲threadX中斷向量目標文件。 2.2.3.2 input_section_attr:輸入段屬性選擇子,每個選擇子以” ”開頭,選擇子不區分大小寫字符。 選擇子可選RO-CODE,RO-DATA,RO( selects both RO-CODE and RO-DATA),RW-DATA,RW-CODE,RW( selects both RW-CODE and RW-DATA),ZI,ENTRY( that is a section containing an ENTRY point)。 以下同義詞可以選擇:CODE (for RO-CODE),CONST( for RO-DATA),TEXT (for RO),DATA (for RW),BSS (for ZI)。 還有兩個僞屬性:FIRST,LAST。如果各段的先後順序比較重要時,可以使用FIRST,LAST標示一個執行區域的第一個和最後一個段。 例1:os_main_init.o (INIT , FIRST) FIRST表示放於本執行區域的開始處。 例2:*libtx.a ( RO) RO 表示*libtx.a的只讀部分。 2.2.3.3 input_section_pattern:輸入段名。 例1:os_main_init.o (INIT , FIRST) INIT 爲os_main_init.o的一個段。 例2:os_stackheap.o (heap) heap 爲os_stackheap.o的一個段。 例3:os_stackheap.o (stack) stack爲os_stackheap.o的一個段。
//-------------------------------------------------------------------------------------------------------------------------- 分散加載文件事例
ADS下的分散加載文件應用實例 load_region_name start_address | " "offset [attributes] [max_size] { execution_region_name start_address | " "offset [attributes][max_size] { module_select_pattern ["(" (" " input_section_attr | input_section_pattern) ([","] " " input_section_attr | "," input_section_pattern)) * ")"] } } load_region: 加載區,用來保存永久性數據(程序和只讀變量)的區域; execution_region: 執行區,程序執行時,從加載區域將數據複製到相應執行區後才能被正確執行; load_region_name: 加載區域名,用於“Linker”區別不同的加載區域,最多31個字符; start_address: 起始地址,指示區域的首地址; offset: 前一個加載區域尾地址+offset 做爲當前的起始地址,且“offset”應爲“0”或“4”的倍數; attributes: 區域屬性,可設置如下屬性: PI 與地址無關方式存放; RELOC 重新部署,保留定位信息,以便重新定位該段到新的執行區; OVERLAY 覆蓋,允許多個可執行區域在同一個地址,ADS不支持; ABSOLUTE 絕對地址(默認); max_size: 該區域的大小; execution_region_name:執行區域名; start_address: 該執行區的首地址,必須字對齊; offset: 同上; attributes: 同上; PI 與地址無關,該區域的代碼可任意移動後執行; OVERLAY 覆蓋; ABSOLUTE 絕對地址(默認); FIXED 固定地址; UNINIT 不用初始化該區域的ZI段; module_select_pattern: 目標文件濾波器,支持通配符“*”和“?”; *.o匹配所有目標,* (或“.ANY”)匹配所有目標文件和庫。 input_section_attr: 每個input_section_attr必須跟隨在“+”後;且大小寫不敏感; RO-CODE 或 CODE RO-DATA 或 CONST RO或TEXT, selects both RO-CODE and RO-DATA RW-DATA RW-CODE RW 或 DATA, selects both RW-CODE and RW-DATA ZI 或 BSS ENTRY, that is a section containing an ENTRY point. FIRST,用於指定存放在一個執行區域的第一個或最後一個區域; LAST,同上; input_section_pattern: 段名; 彙編中指定段: AREA vectors, CODE, READONLY C中指定段: #pragma arm section [sort_type[[=]"name"]] [,sort_type="name"]* sort_type: code、rwdata、rodata、zidata 如果“sort_type”指定了但沒有指定“name”,那麼之前的修改的段名將被恢復成默認值。 #pragma arm section // 恢復所有段名爲默認設置。 應用: #pragma arm section rwdata = "SRAM",zidata = "SRAM" static OS_STK SecondTaskStk[256]; // “rwdata”“zidata”將定位在“sram”段中。 #pragma arm section // 恢復默認設置 分散加載文件中定義如下: Exec_Sram 0x80000000 0x40000 { * (sram) } “PI” 屬性使用示例: LR_1 0x010000 PI ; The first load region is at 0x010000. { ER_RO 0 ; The PI attribute is inherited from parent. ; The default execution address is 0x010000, but the code can be moved. { *( RO) ; All the RO sections go here. } ER_RW 0 ABSOLUTE ; PI attribute is overridden by ABSOLUTE. { *( RW) ; The RW sections are placed next. They cannot be moved. } ER_ZI 0 ; ER_ZI region placed after ER_RW region. { *( ZI) ; All the ZI sections are placed consecutively here. } } LR_1 0x010000 ; The first load region is at 0x010000. { ER_RO 0 ; Default ABSOLUTE attribute is inherited from parent. The execution address ; is 0x010000. The code and ro data cannot be moved. { *( RO) ; All the RO sections go here. } ER_RW 0x018000 PI ; PI attribute overrides ABSOLUTE { *( RW) ; The RW sections are placed at 0x018000 and they can be moved. } ER_ZI 0 ; ER_ZI region placed after ER_RW region. { *( ZI) ; All the ZI sections are placed consecutively here. } } 程序中對某區域地址等的引用方法: Load$$region_name$$Base Load address of the region. Image$$region_name$$Base Execution address of the region. Image$$region_name$$Length Execution region length in bytes (multiple of 4). Image$$region_name$$Limit Address of the byte beyond the end of the execution region. Image$$region_name$$ZI$$Base Execution address of the ZI output section in this region. Image$$region_name$$ZI$$Length Length of the ZI output section in bytes (multiple of 4). Image$$region_name$$ZI$$Limit Address of the byte beyond the end of the ZI output sectionin the execution region. SectionName$$Base Input Address of the start of the consolidated section called SectionName. SectionName$$Limit Input Address of the byte beyond the end of the consolidated section called SectionName. Load: 加載區,即存放地址; Image: 執行區,即運行地址; Base: 區首地址; Limit: 區尾地址; Length: 區長度; region_name: RO、RW、ZI、load_region_name、execution_region_name; 例如: “RAM1”區域的首地址: Image$$RAM1$$Base 上例中“sram”段首地址: sram$$Base 彙編引用示例: IMPORT |Load$$Exec_RAM1$$Base| // Exec_RAM1 爲“RW”段 IMPORT |Image$$Exec_RAM1$$Base| IMPORT |Image$$Exec_RAM1$$Length| IMPORT |Image$$Exec_RAM1$$Limit| LDR R0, =|Load$$Exec_RAM1$$Base| LDR R1, =|Image$$Exec_RAM1$$Base| LDR R2, =|Image$$Exec_RAM1$$Limit| 0 CMP R1, R2 LDRCC R3, [R0], #4 STRCC R3, [R1], #4 BCC %b0 C 引用: extern unsigned char Load$$Exec_RAM1$$Base; extern unsigned char Image$$Exec_RAM1$$Base; extern unsigned char Image$$Exec_RAM1$$Length; void MoveRO(void) { unsigned char * psrc, *pdst; unsigned int count; count = (unsigned int) &Image$$Exec_RAM1$$Length; psrc = (unsigned char *)&Load$$Exec_RAM1$$Base; pdst = (unsigned char *)&Image$$Exec_RAM1$$Base; while (count--) { *pdst = *psrc ; } } 加載文件示例一: 起始地址 大小 ROM: 0x00000000 256K ;0x1fc 保留爲加密字,程序在ROM中運行; RAM 0x40000000 16K ;用於全局變量及任務堆棧; SRAM 0x80000000 512K ;SRAM速度慢,主要用於存放大的數據表; LOAD_ROM1 0x00000000 0x1f8 ; 指定該加載區域首地址、大小 { EXEC_ROM1 0 0x1f8 ; 沒有前一加載區域,所以該執行區域首地址爲加載去首地址 ; 並指定該區域長度 { Startup.o (vectors, FIRST) ; 目標文件的“vectors”段放在該執行區域的第一段 irq.o ( RO) ; 目標文件的所有“RO”段放在該執行區域 } } LOAD_ROM2 0x00000200 ; 第二個加載區域 { EXEC_ROM2 0 0x3e600 { * ( RO) ; 所有目標文件和庫文件中的“RO”段存放在該區域 } RAM1 0x40000000 0x4000 { * ( RW, ZI) ; 所有目標文件和庫文件的“RW”和“ZI”段存放在該區域 } SRAM2 0x80000000 0x80000 { * (sram) ; 所有目標文件中的“sram”段存放在該區域 } } |
ARM 2
ARM RO RW ZI 說明 2轉帖
2009/08/29 22:47
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.