设为首页 加入收藏

TOP

链接脚本中 AT> 的作用
2023-07-23 13:31:14 】 浏览:74
Tags:AT>

缘由

这两天在梳理芯片的启动流程, 研究到了链接脚本(样本为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?就一目了然了

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇痞子衡嵌入式:探讨i.MXRT下FlexS.. 下一篇痞子衡嵌入式:我被邀请做科锐国..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目