1# Copyright (C) 2014-2020 Free Software Foundation, Inc. 2# 3# Copying and distribution of this file, with or without modification, 4# are permitted in any medium without royalty provided the copyright 5# notice and this notice are preserved. 6# 7# Unusual variables checked by this code: 8# NOP - four byte opcode for no-op (defaults to 0) 9# DATA_ADDR - if end-of-text-plus-one-page isn't right for data start 10# OTHER_READWRITE_SECTIONS - other than .data .bss .ctors .sdata ... 11# (e.g., .PARISC.global) 12# OTHER_SECTIONS - at the end 13# EXECUTABLE_SYMBOLS - symbols that must be defined for an 14# executable (e.g., _DYNAMIC_LINK) 15# TEXT_START_SYMBOLS - symbols that appear at the start of the 16# .text section. 17# DATA_START_SYMBOLS - symbols that appear at the start of the 18# .data section. 19# OTHER_BSS_SYMBOLS - symbols that appear at the start of the 20# .bss section besides __bss_start. 21# EMBEDDED - whether this is for an embedded system. 22# 23# When adding sections, do note that the names of some sections are used 24# when specifying the start address of the next. 25# 26test -z "$ENTRY" && ENTRY=_start 27test -z "${BIG_OUTPUT_FORMAT}" && BIG_OUTPUT_FORMAT=${OUTPUT_FORMAT} 28test -z "${LITTLE_OUTPUT_FORMAT}" && LITTLE_OUTPUT_FORMAT=${OUTPUT_FORMAT} 29if [ -z "$MACHINE" ]; then OUTPUT_ARCH=${ARCH}; else OUTPUT_ARCH=${ARCH}:${MACHINE}; fi 30test "$LD_FLAG" = "N" && DATA_ADDR=. 31 32CTOR=".ctors ${CONSTRUCTING-0} : 33 { 34 ${CONSTRUCTING+ PROVIDE (__CTOR_LIST__ = .); } 35 ${CONSTRUCTING+${CTOR_START}} 36 KEEP (*(.ctors)) 37 38 ${CONSTRUCTING+${CTOR_END}} 39 ${CONSTRUCTING+ PROVIDE(__CTOR_END__ = .); } 40 } ${RELOCATING+ > ${TEXT_MEMORY}}" 41 42DTOR=" .dtors ${CONSTRUCTING-0} : 43 { 44 ${CONSTRUCTING+ PROVIDE(__DTOR_LIST__ = .); } 45 KEEP (*(.dtors)) 46 ${CONSTRUCTING+ PROVIDE(__DTOR_END__ = .); } 47 } ${RELOCATING+ > ${TEXT_MEMORY}}" 48 49 50VECTORS=" 51 /* If the 'vectors_addr' symbol is defined, it indicates the start address 52 of interrupt vectors. 53 54 In general, the vectors address is 0xfffe00. This can be overriden 55 with the '-defsym vectors_addr=0xbfc000' ld option. If you do this, 56 then your startup code should also set the IVBR register accordingly. 57 */ 58 59 PROVIDE (_vectors_addr = DEFINED (vectors_addr) ? vectors_addr : 0xfffe00); 60 .vectors DEFINED (vectors_addr) ? vectors_addr : 0xfffe00 : 61 { 62 KEEP (*(.vectors)) 63 }" 64 65# 66# We provide two emulations: a fixed on that defines some memory banks 67# and a configurable one that includes a user provided memory definition. 68# 69case $GENERIC_BOARD in 70 yes|1|YES) 71 MEMORY_DEF=" 72/* Get memory banks definition from some user configuration file. 73 This file must be located in some linker directory (search path 74 with -L<dir>). See fixed memory banks emulation script. */ 75INCLUDE memory.x; 76" 77 ;; 78 *) 79MEMORY_DEF=" 80/* Fixed definition of the available memory banks. 81 See generic emulation script for a user defined configuration. */ 82MEMORY 83{ 84 text (rx) : ORIGIN = $[$ROM_TOP - $ROM_SIZE + 1], LENGTH = ${ROM_SIZE} - 4 85 data : ORIGIN = ${RAM_START_ADDR}, LENGTH = ${RAM_SIZE} 86 eeprom : ORIGIN = ${EEPROM_START_ADDR}, LENGTH = ${EEPROM_SIZE} 87 rvec : ORIGIN = 0xFFFFFC, LENGTH = 4 88} 89 90/* Setup the stack on the top of the data memory bank. */ 91PROVIDE (_stack = ${RAM_START_ADDR} + ${RAM_SIZE} - 1); 92" 93 ;; 94esac 95 96STARTUP_CODE=" 97 /* Startup code. */ 98 KEEP (*(.install0)) /* Section should setup the stack pointer. */ 99 KEEP (*(.install1)) /* Place holder for applications. */ 100 KEEP (*(.install2)) /* Optional installation of data sections in RAM. */ 101 KEEP (*(.install3)) /* Place holder for applications. */ 102 KEEP (*(.install4)) /* Section that calls the main. */ 103" 104 105FINISH_CODE=" 106 /* Finish code. */ 107 KEEP (*(.fini0)) /* Beginning of finish code (_exit symbol). */ 108 KEEP (*(.fini1)) /* Place holder for applications. */ 109 KEEP (*(.fini2)) /* C++ destructors. */ 110 KEEP (*(.fini3)) /* Place holder for applications. */ 111 KEEP (*(.fini4)) /* Runtime exit. */ 112" 113 114PRE_COMPUTE_DATA_SIZE=" 115/* SCz: this does not work yet... This is supposed to force the loading 116 of _map_data.o (from libgcc.a) when the .data section is not empty. 117 By doing so, this should bring the code that copies the .data section 118 from ROM to RAM at init time. 119 120 ___pre_comp_data_size = SIZEOF(.data); 121 __install_data_sections = ___pre_comp_data_size > 0 ? 122 __map_data_sections : 0; 123*/ 124" 125 126INSTALL_RELOC=" 127 .install0 0 : { *(.install0) } 128 .install1 0 : { *(.install1) } 129 .install2 0 : { *(.install2) } 130 .install3 0 : { *(.install3) } 131 .install4 0 : { *(.install4) } 132" 133 134FINISH_RELOC=" 135 .fini0 0 : { *(.fini0) } 136 .fini1 0 : { *(.fini1) } 137 .fini2 0 : { *(.fini2) } 138 .fini3 0 : { *(.fini3) } 139 .fini4 0 : { *(.fini4) } 140" 141 142BSS_DATA_RELOC=" 143 .data1 0 : { *(.data1) } 144 145 /* We want the small data sections together, so single-instruction offsets 146 can access them all, and initialized data all before uninitialized, so 147 we can shorten the on-disk segment size. */ 148 .sdata 0 : { *(.sdata) } 149 .sbss 0 : { *(.sbss) } 150 .scommon 0 : { *(.scommon) } 151" 152 153SOFT_REGS_RELOC=" 154 .softregs 0 : { *(.softregs) } 155" 156 157cat <<EOF 158/* Copyright (C) 2014-2020 Free Software Foundation, Inc. 159 160 Copying and distribution of this script, with or without modification, 161 are permitted in any medium without royalty provided the copyright 162 notice and this notice are preserved. */ 163 164${RELOCATING+/* Linker script for HCS12Z executable (PROM). */} 165${RELOCATING-/* Linker script for HCS12Z object file (ld -r). */} 166 167OUTPUT_FORMAT("${OUTPUT_FORMAT}", "${BIG_OUTPUT_FORMAT}", 168 "${LITTLE_OUTPUT_FORMAT}") 169OUTPUT_ARCH(${OUTPUT_ARCH}) 170${RELOCATING+ENTRY(${ENTRY})} 171 172${RELOCATING+${LIB_SEARCH_DIRS}} 173${RELOCATING+${EXECUTABLE_SYMBOLS}} 174${RELOCATING+${MEMORY_DEF}} 175 176${RELOCATING+PROVIDE (_start = $[$ROM_TOP - $ROM_SIZE + 1]);} 177SECTIONS 178{ 179 .hash ${RELOCATING-0} : { *(.hash) } 180 .dynsym ${RELOCATING-0} : { *(.dynsym) } 181 .dynstr ${RELOCATING-0} : { *(.dynstr) } 182 .gnu.version ${RELOCATING-0} : { *(.gnu.version) } 183 .gnu.version_d ${RELOCATING-0} : { *(.gnu.version_d) } 184 .gnu.version_r ${RELOCATING-0} : { *(.gnu.version_r) } 185 186 .rel.text ${RELOCATING-0} : 187 { 188 *(.rel.text) 189 ${RELOCATING+*(.rel.text.*)} 190 ${RELOCATING+*(.rel.gnu.linkonce.t.*)} 191 } 192 .rela.text ${RELOCATING-0} : 193 { 194 *(.rela.text) 195 ${RELOCATING+*(.rela.text.*)} 196 ${RELOCATING+*(.rela.gnu.linkonce.t.*)} 197 } 198 .rel.data ${RELOCATING-0} : 199 { 200 *(.rel.data) 201 ${RELOCATING+*(.rel.data.*)} 202 ${RELOCATING+*(.rel.gnu.linkonce.d.*)} 203 } 204 .rela.data ${RELOCATING-0} : 205 { 206 *(.rela.data) 207 ${RELOCATING+*(.rela.data.*)} 208 ${RELOCATING+*(.rela.gnu.linkonce.d.*)} 209 } 210 .rel.rodata ${RELOCATING-0} : 211 { 212 *(.rel.rodata) 213 ${RELOCATING+*(.rel.rodata.*)} 214 ${RELOCATING+*(.rel.gnu.linkonce.r.*)} 215 } 216 .rela.rodata ${RELOCATING-0} : 217 { 218 *(.rela.rodata) 219 ${RELOCATING+*(.rela.rodata.*)} 220 ${RELOCATING+*(.rela.gnu.linkonce.r.*)} 221 } 222 .rel.sdata ${RELOCATING-0} : 223 { 224 *(.rel.sdata) 225 ${RELOCATING+*(.rel.sdata.*)} 226 ${RELOCATING+*(.rel.gnu.linkonce.s.*)} 227 } 228 .rela.sdata ${RELOCATING-0} : 229 { 230 *(.rela.sdata) 231 ${RELOCATING+*(.rela.sdata.*)} 232 ${RELOCATING+*(.rela.gnu.linkonce.s.*)} 233 } 234 .rel.sbss ${RELOCATING-0} : 235 { 236 *(.rel.sbss) 237 ${RELOCATING+*(.rel.sbss.*)} 238 ${RELOCATING+*(.rel.gnu.linkonce.sb.*)} 239 } 240 .rela.sbss ${RELOCATING-0} : 241 { 242 *(.rela.sbss) 243 ${RELOCATING+*(.rela.sbss.*)} 244 ${RELOCATING+*(.rel.gnu.linkonce.sb.*)} 245 } 246 .rel.bss ${RELOCATING-0} : 247 { 248 *(.rel.bss) 249 ${RELOCATING+*(.rel.bss.*)} 250 ${RELOCATING+*(.rel.gnu.linkonce.b.*)} 251 } 252 .rela.bss ${RELOCATING-0} : 253 { 254 *(.rela.bss) 255 ${RELOCATING+*(.rela.bss.*)} 256 ${RELOCATING+*(.rela.gnu.linkonce.b.*)} 257 } 258 .rel.stext ${RELOCATING-0} : { *(.rel.stest) } 259 .rela.stext ${RELOCATING-0} : { *(.rela.stest) } 260 .rel.etext ${RELOCATING-0} : { *(.rel.etest) } 261 .rela.etext ${RELOCATING-0} : { *(.rela.etest) } 262 .rel.sdata ${RELOCATING-0} : { *(.rel.sdata) } 263 .rela.sdata ${RELOCATING-0} : { *(.rela.sdata) } 264 .rel.edata ${RELOCATING-0} : { *(.rel.edata) } 265 .rela.edata ${RELOCATING-0} : { *(.rela.edata) } 266 .rel.eit_v ${RELOCATING-0} : { *(.rel.eit_v) } 267 .rela.eit_v ${RELOCATING-0} : { *(.rela.eit_v) } 268 .rel.ebss ${RELOCATING-0} : { *(.rel.ebss) } 269 .rela.ebss ${RELOCATING-0} : { *(.rela.ebss) } 270 .rel.srodata ${RELOCATING-0} : { *(.rel.srodata) } 271 .rela.srodata ${RELOCATING-0} : { *(.rela.srodata) } 272 .rel.erodata ${RELOCATING-0} : { *(.rel.erodata) } 273 .rela.erodata ${RELOCATING-0} : { *(.rela.erodata) } 274 .rel.got ${RELOCATING-0} : { *(.rel.got) } 275 .rela.got ${RELOCATING-0} : { *(.rela.got) } 276 .rel.ctors ${RELOCATING-0} : { *(.rel.ctors) } 277 .rela.ctors ${RELOCATING-0} : { *(.rela.ctors) } 278 .rel.dtors ${RELOCATING-0} : { *(.rel.dtors) } 279 .rela.dtors ${RELOCATING-0} : { *(.rela.dtors) } 280 .rel.init ${RELOCATING-0} : { *(.rel.init) } 281 .rela.init ${RELOCATING-0} : { *(.rela.init) } 282 .rel.fini ${RELOCATING-0} : { *(.rel.fini) } 283 .rela.fini ${RELOCATING-0} : { *(.rela.fini) } 284 .rel.plt ${RELOCATING-0} : { *(.rel.plt) } 285 .rela.plt ${RELOCATING-0} : { *(.rela.plt) } 286 287 /* Start of text section. */ 288 .stext ${RELOCATING-0} : 289 { 290 *(.stext) 291 } ${RELOCATING+ > ${TEXT_MEMORY}} 292 293 .init ${RELOCATING-0} : 294 { 295 KEEP (*(SORT_NONE(.init))) 296 } ${RELOCATING+=${NOP-0}} 297 298 ${RELOCATING-${INSTALL_RELOC}} 299 ${RELOCATING-${FINISH_RELOC}} 300 301 .text ${RELOCATING-0}: 302 { 303 /* Put startup code at beginning so that _start keeps same address. */ 304 ${RELOCATING+${STARTUP_CODE}} 305 306 *(.text) 307 ${RELOCATING+*(.text.*)} 308 /* .gnu.warning sections are handled specially by elf.em. */ 309 *(.gnu.warning) 310 ${RELOCATING+*(.gnu.linkonce.t.*)} 311 ${RELOCATING+*(.tramp)} 312 ${RELOCATING+*(.tramp.*)} 313 314 ${RELOCATING+KEEP (*(SORT_NONE(.fini)))} 315 ${RELOCATING+${FINISH_CODE}} 316 317 ${RELOCATING+_etext = .;} 318 ${RELOCATING+PROVIDE (etext = .);} 319 ${RELOCATING+. = ALIGN(2);} 320 } ${RELOCATING+ > ${TEXT_MEMORY} =${NOP}} 321 .rvec ${RELOCATING-0} : 322 { 323 ${RELOCATING+LONG(_start);} 324 } ${RELOCATING+ > rvec} 325 .eh_frame ${RELOCATING-0} : 326 { 327 KEEP (*(.eh_frame)) 328 } ${RELOCATING+ > ${TEXT_MEMORY}} 329 330 .gcc_except_table ${RELOCATING-0} : 331 { 332 *(.gcc_except_table) 333 } ${RELOCATING+ > ${TEXT_MEMORY}} 334 335 .rodata ${RELOCATING-0} : 336 { 337 *(.rodata) 338 ${RELOCATING+*(.rodata.*)} 339 ${RELOCATING+*(.gnu.linkonce.r*)} 340 ${RELOCATING+. = ALIGN(2);} 341 } ${RELOCATING+ > ${TEXT_MEMORY} =0xffffffff} 342 343 .rodata1 ${RELOCATING-0} : 344 { 345 *(.rodata1) 346 ${RELOCATING+. = ALIGN(2);} 347 } ${RELOCATING+ > ${TEXT_MEMORY} =0xffffffff} 348 349 /* Constructor and destructor tables are in ROM. */ 350 ${RELOCATING+${CTOR}} 351 ${RELOCATING+${DTOR}} 352 353 .jcr ${RELOCATING-0} : 354 { 355 KEEP (*(.jcr)) 356 } ${RELOCATING+ > ${TEXT_MEMORY}} 357 358 /* Start of the data section image in ROM. */ 359 ${RELOCATING+__data_image = .;} 360 ${RELOCATING+PROVIDE (__data_image = .);} 361 362 /* All read-only sections that normally go in PROM must be above. 363 We construct the DATA image section in PROM at end of all these 364 read-only sections. The data image must be copied at init time. 365 Refer to GNU ld, Section 3.6.8.2 Output Section LMA. */ 366 .data ${RELOCATING-0} : ${RELOCATING+AT (__data_image)} 367 { 368 ${RELOCATING+__data_section_start = .;} 369 ${RELOCATING+PROVIDE (__data_section_start = .);} 370 371 ${RELOCATING+${DATA_START_SYMBOLS}} 372 ${RELOCATING+*(.sdata)} 373 *(.data) 374 ${RELOCATING+*(.data.*)} 375 ${RELOCATING+*(.data1)} 376 ${RELOCATING+*(.gnu.linkonce.d.*)} 377 ${CONSTRUCTING+CONSTRUCTORS} 378 379 ${RELOCATING+_edata = .;} 380 ${RELOCATING+PROVIDE (edata = .);} 381 ${RELOCATING+. = ALIGN(2);} 382 } ${RELOCATING+ > ${DATA_MEMORY} =0xffffffff} 383 384 ${RELOCATING+__data_section_size = SIZEOF(.data);} 385 ${RELOCATING+PROVIDE (__data_section_size = SIZEOF(.data));} 386 ${RELOCATING+__data_image_end = __data_image + __data_section_size;} 387 388 ${RELOCATING+${PRE_COMPUTE_DATA_SIZE}} 389 390 .install ${RELOCATING-0}: 391 { 392 ${RELOCATING+. = __data_section_size;} 393 } ${RELOCATING+ > ${TEXT_MEMORY}} 394 395 /* Relocation for some bss and data sections. */ 396 ${RELOCATING-${BSS_DATA_RELOC}} 397 ${RELOCATING-${SOFT_REGS_RELOC}} 398 399 .bss ${RELOCATING-0} : 400 { 401 ${RELOCATING+__bss_start = .;} 402 ${RELOCATING+*(.softregs)} 403 ${RELOCATING+*(.sbss)} 404 ${RELOCATING+*(.common)} 405 ${RELOCATING+*(.scommon)} 406 ${RELOCATING+*(.dynbss)} 407 *(.bss) 408 ${RELOCATING+*(.bss.*)} 409 ${RELOCATING+*(.gnu.linkonce.b.*)} 410 ${RELOCATING+*(COMMON)} 411 ${RELOCATING+PROVIDE (_end = .);} 412 } ${RELOCATING+ > ${DATA_MEMORY}} 413 ${RELOCATING+__bss_size = SIZEOF(.bss);} 414 ${RELOCATING+PROVIDE (__bss_size = SIZEOF(.bss));} 415 416 .eeprom ${RELOCATING-0} : 417 { 418 *(.eeprom) 419 ${RELOCATING+*(.eeprom.*)} 420 } ${RELOCATING+ > ${EEPROM_MEMORY}} 421 422 ${RELOCATING+${VECTORS}} 423 424 /* Stabs debugging sections. */ 425 .stab 0 : { *(.stab) } 426 .stabstr 0 : { *(.stabstr) } 427 .stab.excl 0 : { *(.stab.excl) } 428 .stab.exclstr 0 : { *(.stab.exclstr) } 429 .stab.index 0 : { *(.stab.index) } 430 .stab.indexstr 0 : { *(.stab.indexstr) } 431 432 .comment 0 : { *(.comment) } 433 434 /* Treatment of DWARF debug section must be at end of the linker 435 script to avoid problems when there are undefined symbols. It's necessary 436 to avoid that the DWARF section is relocated before such undefined 437 symbols are found. */ 438EOF 439 440. $srcdir/scripttempl/DWARF.sc 441 442cat <<EOF 443} 444EOF 445