Hightec免费工具链_链接脚本学习#

免费工具链网址申请链接(1年)#

https://free-entry-toolchain.hightec-rt.com/

简介#

tricore-gcc 的链接脚本是以 lsl 为后缀的文件。

安装完工具链后,安装目录下会包含 ld.pdfusersguide.pdf 文件。

上述两个文件包含了链接脚本的介绍。

link文件参考

一个简单的例子#

参考文章 链接脚本(Linker Scripts)语法和规则解析(自官方手册)

代码应在地址 0x10000 处加载,数据应从地址 0x8000000 开始。

SECTIONS
{
. = 0x10000;
.text : { *(.text) }
. = 0x8000000;
.data : { *(.data) }
.bss : { *(.bss) }
}

程序起始点定义#

ENTRY(symbol)

iLLD 工程中定义如下:

ENTRY(_START)

程序起始地址为:

void _START(void)
{
    Ifx_Ssw_jumpToFunction(__StartUpSoftware);
}

text bss data rodata#

  • .text :程序代码

  • .rodata :只读数据

  • .data :可读写且需要初始化数据

  • .bss :可读写的置零初始化数据

REGION_ALIAS 内存段重命名#

REGION_ALIAS( default_ram , dsram0)
REGION_ALIAS( default_rom , pfls0)

注释的方式#

/*Un comment one of the below statement groups to enable CpuX DMI RAM to hold global variables*/

中断向量表#

inttab_tcx_y

x 代表核心 , y 代表优先级

每个核心都有一组中断向量表,每个优先级占用 32 字节的内存地址。

__clear_table 和 __copy_table#

有初始值和没有初始值的全局变量分别需要在程序运行之前被重新赋值和清空。也就是所谓的 data 段和 bss 段的区别。

iLLD demo 工程中是放在 Ifx_Ssw_C_Init 函数中进行的。

获取链接文件中定义值的方式#

参考如下:

link文件中

PROVIDE(__copy_table = .);

代码中

extern unsigned int __copy_table[];   /**< copy table entry */
pTable = (unsigned int *)&__copy_table;

设置段的绝对地址#

参考中断向量表

LCF_INTVEC0_START = 0x802FE000;
__INTTAB_CPU0 = LCF_INTVEC0_START;
.inttab_tc0_000 (__INTTAB_CPU0 + 0x0000) : { . = ALIGN(8) ;  KEEP (*(.intvec_tc0_0  )); }

内存块定义时 attr属性#

<name> [(<attr>)] : ORIGIN = <origin>, LENGTH = <len>
dsram3_local (w!xp): org = 0xd0000000, len = 96K
  • R Read-only section.

  • W Read/write section.

  • X Executable section.

  • A Allocatable section.

  • I Initialized section.

  • L Same as I.

  • P Section contains PCP code or data.

  • ! Invert the sense of any of the preceding attributes.

FLAGS#

[FLAGS(section_flags)]
  • a section is allocatable

  • w section is writable

  • v section contains vle code

  • x section is executable

  • l section is loadable

方式1#

例子如下:

CORE_SEC(.text) : FLAGS(axl)
CORE_SEC(.bss) (NOLOAD): FLAGS(aw)
CORE_SEC(.data) : FLAGS(awl)
CORE_SEC(.rodata) : FLAGS(arl)

比如说你定义的内存段希望有初始值,那么就需要加上 al 标志,并在 __copy_table__ 中将其 VMA 和 LMA 加进去。

方式2#

#pragma section "<name>" [<flags>] [<alignment>]
<objects>
#pragma section

#pragma section ".bmhd_0_orig" a
#pragma section

方式3#

__attribute__ ((asection("<name>", "a=<align>", "f=<flags>")))