1# Copyright (C) 2014-2016 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. This depends on the 68HC11 operating mode: 53 54 Addr 55 Single chip 0xffc0 56 Extended mode 0xffc0 57 Bootstrap 0x00c0 58 Test 0xbfc0 59 60 In general, the vectors address is 0xffc0. This can be overriden 61 with the '-defsym vectors_addr=0xbfc0' ld option. 62 63 Note: for the bootstrap mode, the interrupt vectors are at 0xbfc0 but 64 they are redirected to 0x00c0 by the internal PROM. Application's vectors 65 must also consist of jump instructions (see Motorola's manual). */ 66 67 PROVIDE (_vectors_addr = DEFINED (vectors_addr) ? vectors_addr : 0xffc0); 68 .vectors DEFINED (vectors_addr) ? vectors_addr : 0xffc0 : 69 { 70 KEEP (*(.vectors)) 71 }" 72 73# 74# We provide two emulations: a fixed on that defines some memory banks 75# and a configurable one that includes a user provided memory definition. 76# 77case $GENERIC_BOARD in 78 yes|1|YES) 79 MEMORY_DEF=" 80/* Get memory banks definition from some user configuration file. 81 This file must be located in some linker directory (search path 82 with -L<dir>). See fixed memory banks emulation script. */ 83INCLUDE memory.x; 84" 85 ;; 86 *) 87MEMORY_DEF=" 88/* Fixed definition of the available memory banks. 89 See generic emulation script for a user defined configuration. */ 90MEMORY 91{ 92 page0 (rwx) : ORIGIN = 0x0, LENGTH = 256 93 text (rx) : ORIGIN = ${ROM_START_ADDR}, LENGTH = ${ROM_SIZE} 94 data : ORIGIN = ${RAM_START_ADDR}, LENGTH = ${RAM_SIZE} 95 eeprom : ORIGIN = ${EEPROM_START_ADDR}, LENGTH = ${EEPROM_SIZE} 96} 97 98/* Setup the stack on the top of the data memory bank. */ 99PROVIDE (_stack = ${RAM_START_ADDR} + ${RAM_SIZE} - 1); 100" 101 ;; 102esac 103 104STARTUP_CODE=" 105 /* Startup code. */ 106 KEEP (*(.install0)) /* Section should setup the stack pointer. */ 107 KEEP (*(.install1)) /* Place holder for applications. */ 108 KEEP (*(.install2)) /* Optional installation of data sections in RAM. */ 109 KEEP (*(.install3)) /* Place holder for applications. */ 110 KEEP (*(.install4)) /* Section that calls the main. */ 111" 112 113FINISH_CODE=" 114 /* Finish code. */ 115 KEEP (*(.fini0)) /* Beginning of finish code (_exit symbol). */ 116 KEEP (*(.fini1)) /* Place holder for applications. */ 117 KEEP (*(.fini2)) /* C++ destructors. */ 118 KEEP (*(.fini3)) /* Place holder for applications. */ 119 KEEP (*(.fini4)) /* Runtime exit. */ 120" 121 122PRE_COMPUTE_DATA_SIZE=" 123/* SCz: this does not work yet... This is supposed to force the loading 124 of _map_data.o (from libgcc.a) when the .data section is not empty. 125 By doing so, this should bring the code that copies the .data section 126 from ROM to RAM at init time. 127 128 ___pre_comp_data_size = SIZEOF(.data); 129 __install_data_sections = ___pre_comp_data_size > 0 ? 130 __map_data_sections : 0; 131*/ 132" 133 134INSTALL_RELOC=" 135 .install0 0 : { *(.install0) } 136 .install1 0 : { *(.install1) } 137 .install2 0 : { *(.install2) } 138 .install3 0 : { *(.install3) } 139 .install4 0 : { *(.install4) } 140" 141 142FINISH_RELOC=" 143 .fini0 0 : { *(.fini0) } 144 .fini1 0 : { *(.fini1) } 145 .fini2 0 : { *(.fini2) } 146 .fini3 0 : { *(.fini3) } 147 .fini4 0 : { *(.fini4) } 148" 149 150BSS_DATA_RELOC=" 151 .data1 0 : { *(.data1) } 152 153 /* We want the small data sections together, so single-instruction offsets 154 can access them all, and initialized data all before uninitialized, so 155 we can shorten the on-disk segment size. */ 156 .sdata 0 : { *(.sdata) } 157 .sbss 0 : { *(.sbss) } 158 .scommon 0 : { *(.scommon) } 159" 160 161SOFT_REGS_RELOC=" 162 .softregs 0 : { *(.softregs) } 163" 164 165cat <<EOF 166/* Copyright (C) 2014-2016 Free Software Foundation, Inc. 167 168 Copying and distribution of this script, with or without modification, 169 are permitted in any medium without royalty provided the copyright 170 notice and this notice are preserved. */ 171 172${RELOCATING+/* Linker script for 68HC11 executable (PROM). */} 173${RELOCATING-/* Linker script for 68HC11 object file (ld -r). */} 174 175OUTPUT_FORMAT("${OUTPUT_FORMAT}", "${BIG_OUTPUT_FORMAT}", 176 "${LITTLE_OUTPUT_FORMAT}") 177OUTPUT_ARCH(${OUTPUT_ARCH}) 178${RELOCATING+ENTRY(${ENTRY})} 179 180${RELOCATING+${LIB_SEARCH_DIRS}} 181${RELOCATING+${EXECUTABLE_SYMBOLS}} 182${RELOCATING+${MEMORY_DEF}} 183 184SECTIONS 185{ 186 .hash ${RELOCATING-0} : { *(.hash) } 187 .dynsym ${RELOCATING-0} : { *(.dynsym) } 188 .dynstr ${RELOCATING-0} : { *(.dynstr) } 189 .gnu.version ${RELOCATING-0} : { *(.gnu.version) } 190 .gnu.version_d ${RELOCATING-0} : { *(.gnu.version_d) } 191 .gnu.version_r ${RELOCATING-0} : { *(.gnu.version_r) } 192 193 .rel.text ${RELOCATING-0} : 194 { 195 *(.rel.text) 196 ${RELOCATING+*(.rel.text.*)} 197 ${RELOCATING+*(.rel.gnu.linkonce.t.*)} 198 } 199 .rela.text ${RELOCATING-0} : 200 { 201 *(.rela.text) 202 ${RELOCATING+*(.rela.text.*)} 203 ${RELOCATING+*(.rela.gnu.linkonce.t.*)} 204 } 205 .rel.data ${RELOCATING-0} : 206 { 207 *(.rel.data) 208 ${RELOCATING+*(.rel.data.*)} 209 ${RELOCATING+*(.rel.gnu.linkonce.d.*)} 210 } 211 .rela.data ${RELOCATING-0} : 212 { 213 *(.rela.data) 214 ${RELOCATING+*(.rela.data.*)} 215 ${RELOCATING+*(.rela.gnu.linkonce.d.*)} 216 } 217 .rel.rodata ${RELOCATING-0} : 218 { 219 *(.rel.rodata) 220 ${RELOCATING+*(.rel.rodata.*)} 221 ${RELOCATING+*(.rel.gnu.linkonce.r.*)} 222 } 223 .rela.rodata ${RELOCATING-0} : 224 { 225 *(.rela.rodata) 226 ${RELOCATING+*(.rela.rodata.*)} 227 ${RELOCATING+*(.rela.gnu.linkonce.r.*)} 228 } 229 .rel.sdata ${RELOCATING-0} : 230 { 231 *(.rel.sdata) 232 ${RELOCATING+*(.rel.sdata.*)} 233 ${RELOCATING+*(.rel.gnu.linkonce.s.*)} 234 } 235 .rela.sdata ${RELOCATING-0} : 236 { 237 *(.rela.sdata) 238 ${RELOCATING+*(.rela.sdata.*)} 239 ${RELOCATING+*(.rela.gnu.linkonce.s.*)} 240 } 241 .rel.sbss ${RELOCATING-0} : 242 { 243 *(.rel.sbss) 244 ${RELOCATING+*(.rel.sbss.*)} 245 ${RELOCATING+*(.rel.gnu.linkonce.sb.*)} 246 } 247 .rela.sbss ${RELOCATING-0} : 248 { 249 *(.rela.sbss) 250 ${RELOCATING+*(.rela.sbss.*)} 251 ${RELOCATING+*(.rel.gnu.linkonce.sb.*)} 252 } 253 .rel.bss ${RELOCATING-0} : 254 { 255 *(.rel.bss) 256 ${RELOCATING+*(.rel.bss.*)} 257 ${RELOCATING+*(.rel.gnu.linkonce.b.*)} 258 } 259 .rela.bss ${RELOCATING-0} : 260 { 261 *(.rela.bss) 262 ${RELOCATING+*(.rela.bss.*)} 263 ${RELOCATING+*(.rela.gnu.linkonce.b.*)} 264 } 265 .rel.stext ${RELOCATING-0} : { *(.rel.stest) } 266 .rela.stext ${RELOCATING-0} : { *(.rela.stest) } 267 .rel.etext ${RELOCATING-0} : { *(.rel.etest) } 268 .rela.etext ${RELOCATING-0} : { *(.rela.etest) } 269 .rel.sdata ${RELOCATING-0} : { *(.rel.sdata) } 270 .rela.sdata ${RELOCATING-0} : { *(.rela.sdata) } 271 .rel.edata ${RELOCATING-0} : { *(.rel.edata) } 272 .rela.edata ${RELOCATING-0} : { *(.rela.edata) } 273 .rel.eit_v ${RELOCATING-0} : { *(.rel.eit_v) } 274 .rela.eit_v ${RELOCATING-0} : { *(.rela.eit_v) } 275 .rel.ebss ${RELOCATING-0} : { *(.rel.ebss) } 276 .rela.ebss ${RELOCATING-0} : { *(.rela.ebss) } 277 .rel.srodata ${RELOCATING-0} : { *(.rel.srodata) } 278 .rela.srodata ${RELOCATING-0} : { *(.rela.srodata) } 279 .rel.erodata ${RELOCATING-0} : { *(.rel.erodata) } 280 .rela.erodata ${RELOCATING-0} : { *(.rela.erodata) } 281 .rel.got ${RELOCATING-0} : { *(.rel.got) } 282 .rela.got ${RELOCATING-0} : { *(.rela.got) } 283 .rel.ctors ${RELOCATING-0} : { *(.rel.ctors) } 284 .rela.ctors ${RELOCATING-0} : { *(.rela.ctors) } 285 .rel.dtors ${RELOCATING-0} : { *(.rel.dtors) } 286 .rela.dtors ${RELOCATING-0} : { *(.rela.dtors) } 287 .rel.init ${RELOCATING-0} : { *(.rel.init) } 288 .rela.init ${RELOCATING-0} : { *(.rela.init) } 289 .rel.fini ${RELOCATING-0} : { *(.rel.fini) } 290 .rela.fini ${RELOCATING-0} : { *(.rela.fini) } 291 .rel.plt ${RELOCATING-0} : { *(.rel.plt) } 292 .rela.plt ${RELOCATING-0} : { *(.rela.plt) } 293 294 /* Concatenate .page0 sections. Put them in the page0 memory bank 295 unless we are creating a relocatable file. */ 296 .page0 : 297 { 298 *(.page0) 299 ${RELOCATING+*(.softregs)} 300 } ${RELOCATING+ > page0} 301 302 /* Start of text section. */ 303 .stext ${RELOCATING-0} : 304 { 305 *(.stext) 306 } ${RELOCATING+ > ${TEXT_MEMORY}} 307 308 .init ${RELOCATING-0} : 309 { 310 *(.init) 311 } ${RELOCATING+=${NOP-0}} 312 313 ${RELOCATING-${INSTALL_RELOC}} 314 ${RELOCATING-${FINISH_RELOC}} 315 316 .text ${RELOCATING-0}: 317 { 318 /* Put startup code at beginning so that _start keeps same address. */ 319 ${RELOCATING+${STARTUP_CODE}} 320 321 ${RELOCATING+*(.init)} 322 *(.text) 323 ${RELOCATING+*(.text.*)} 324 /* .gnu.warning sections are handled specially by elf32.em. */ 325 *(.gnu.warning) 326 ${RELOCATING+*(.gnu.linkonce.t.*)} 327 ${RELOCATING+*(.tramp)} 328 ${RELOCATING+*(.tramp.*)} 329 330 ${RELOCATING+${FINISH_CODE}} 331 332 ${RELOCATING+_etext = .;} 333 ${RELOCATING+PROVIDE (etext = .);} 334 335 } ${RELOCATING+ > ${TEXT_MEMORY}} 336 337 .eh_frame ${RELOCATING-0} : 338 { 339 KEEP (*(.eh_frame)) 340 } ${RELOCATING+ > ${TEXT_MEMORY}} 341 342 .gcc_except_table ${RELOCATING-0} : 343 { 344 *(.gcc_except_table) 345 } ${RELOCATING+ > ${TEXT_MEMORY}} 346 347 .rodata ${RELOCATING-0} : 348 { 349 *(.rodata) 350 ${RELOCATING+*(.rodata.*)} 351 ${RELOCATING+*(.gnu.linkonce.r*)} 352 } ${RELOCATING+ > ${TEXT_MEMORY}} 353 354 .rodata1 ${RELOCATING-0} : 355 { 356 *(.rodata1) 357 } ${RELOCATING+ > ${TEXT_MEMORY}} 358 359 /* Constructor and destructor tables are in ROM. */ 360 ${RELOCATING+${CTOR}} 361 ${RELOCATING+${DTOR}} 362 363 .jcr ${RELOCATING-0} : 364 { 365 KEEP (*(.jcr)) 366 } ${RELOCATING+ > ${TEXT_MEMORY}} 367 368 /* Start of the data section image in ROM. */ 369 ${RELOCATING+__data_image = .;} 370 ${RELOCATING+PROVIDE (__data_image = .);} 371 372 /* All read-only sections that normally go in PROM must be above. 373 We construct the DATA image section in PROM at end of all these 374 read-only sections. The data image must be copied at init time. 375 Refer to GNU ld, Section 3.6.8.2 Output Section LMA. */ 376 .data ${RELOCATING-0} : ${RELOCATING+AT (__data_image)} 377 { 378 ${RELOCATING+__data_section_start = .;} 379 ${RELOCATING+PROVIDE (__data_section_start = .);} 380 381 ${RELOCATING+${DATA_START_SYMBOLS}} 382 ${RELOCATING+*(.sdata)} 383 *(.data) 384 ${RELOCATING+*(.data.*)} 385 ${RELOCATING+*(.data1)} 386 ${RELOCATING+*(.gnu.linkonce.d.*)} 387 ${CONSTRUCTING+CONSTRUCTORS} 388 389 ${RELOCATING+_edata = .;} 390 ${RELOCATING+PROVIDE (edata = .);} 391 } ${RELOCATING+ > ${DATA_MEMORY}} 392 393 ${RELOCATING+__data_section_size = SIZEOF(.data);} 394 ${RELOCATING+PROVIDE (__data_section_size = SIZEOF(.data));} 395 ${RELOCATING+__data_image_end = __data_image + __data_section_size;} 396 397 ${RELOCATING+${PRE_COMPUTE_DATA_SIZE}} 398 399 /* .install ${RELOCATING-0}: 400 { 401 . = _data_image_end; 402 } ${RELOCATING+ > ${TEXT_MEMORY}} */ 403 404 /* Relocation for some bss and data sections. */ 405 ${RELOCATING-${BSS_DATA_RELOC}} 406 ${RELOCATING-${SOFT_REGS_RELOC}} 407 408 .bss ${RELOCATING-0} : 409 { 410 ${RELOCATING+__bss_start = .;} 411 ${RELOCATING+*(.sbss)} 412 ${RELOCATING+*(.scommon)} 413 414 *(.dynbss) 415 *(.bss) 416 ${RELOCATING+*(.bss.*)} 417 ${RELOCATING+*(.gnu.linkonce.b.*)} 418 *(COMMON) 419 ${RELOCATING+PROVIDE (_end = .);} 420 } ${RELOCATING+ > ${DATA_MEMORY}} 421 ${RELOCATING+__bss_size = SIZEOF(.bss);} 422 ${RELOCATING+PROVIDE (__bss_size = SIZEOF(.bss));} 423 424 .eeprom ${RELOCATING-0} : 425 { 426 *(.eeprom) 427 *(.eeprom.*) 428 } ${RELOCATING+ > ${EEPROM_MEMORY}} 429 430 ${RELOCATING+${VECTORS}} 431 432 /* Stabs debugging sections. */ 433 .stab 0 : { *(.stab) } 434 .stabstr 0 : { *(.stabstr) } 435 .stab.excl 0 : { *(.stab.excl) } 436 .stab.exclstr 0 : { *(.stab.exclstr) } 437 .stab.index 0 : { *(.stab.index) } 438 .stab.indexstr 0 : { *(.stab.indexstr) } 439 440 .comment 0 : { *(.comment) } 441 442EOF 443 444. $srcdir/scripttempl/DWARF.sc 445 446cat <<EOF 447} 448EOF 449