緣由 這兩天在梳理晶元的啟動流程, 研究到了鏈接腳本(樣本為stm32cube ide 中的 stm32f407 的 flash 鏈接腳本). 產生了一個疑問AT>是什麼? 答案 AT>就是用於指定這個section的載入記憶體地址(LMA)的 解釋 鏈接腳本生成sections要被載入到memory ...
緣由
這兩天在梳理晶元的啟動流程, 研究到了鏈接腳本(樣本為stm32cube ide 中的 stm32f407 的 flash 鏈接腳本).
產生了一個疑問AT>
是什麼?
答案
AT>
就是用於指定這個section的載入記憶體地址
(LMA)的
解釋
鏈接腳本生成sections要被載入到memory中,記憶體分兩種
- LMA 載入記憶體地址
- VMA 虛擬記憶體地址,也可以理解為運行記憶體地址
像下麵這種的就是LMA和VMA都是一樣的, 都是放在FLASH裡面的
/* Constant data into "FLASH" Rom type memory */
.rodata :
{
. = ALIGN(4);
*(.rodata) /* .rodata sections (constants, strings, etc.) */
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
. = ALIGN(4);
} >FLASH
像下麵這種就是LMA和VMA不一樣的, 鏈接的時候放在FLASH裡面, 運行的時候就從FLASH裡面搬運到RAM中
/* Used by the startup to initialize data */
_sidata = LOADADDR(.data);
/* Initialized data sections into "RAM" Ram type memory */
.data :
{
. = ALIGN(4);
_sdata = .; /* create a global symbol at data start */
*(.data) /* .data sections */
*(.data*) /* .data* sections */
*(.RamFunc) /* .RamFunc sections */
*(.RamFunc*) /* .RamFunc* sections */
. = ALIGN(4);
_edata = .; /* define a global symbol at data end */
} >RAM AT> FLASH
搬運data段的彙編代碼
/* Copy the data segment initializers from flash to SRAM */
ldr r0, =_sdata
ldr r1, =_edata
ldr r2, =_sidata
movs r3, #0
b LoopCopyDataInit
CopyDataInit:
ldr r4, [r2, r3]
str r4, [r0, r3]
adds r3, r3, #4
LoopCopyDataInit:
adds r4, r0, r3
cmp r4, r1
bcc CopyDataInit
/* Zero fill the bss segment. */
ldr r2, =_sbss
ldr r4, =_ebss
movs r3, #0
b LoopFillZerobss
目的
設置這個的目的就是為了將存儲的位置和運行的位置區分開來
參考
What does > region1 AT > region2 mean in an LD linker script?
3.6.8 Output Section Attributes
把3.6.8 Output Section Attributes
看完之後再去看What does > region1 AT > region2 mean in an LD linker script?
就一目瞭然了