aboutsummaryrefslogtreecommitdiff
path: root/ld/scripttempl/elfm68hc12.sc
blob: 5c68ffffa58f0f08437a6dcfeb8db82857057f89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
# Copyright (C) 2014-2019 Free Software Foundation, Inc.
#
# Copying and distribution of this file, with or without modification,
# are permitted in any medium without royalty provided the copyright
# notice and this notice are preserved.
#
# Unusual variables checked by this code:
#	NOP - four byte opcode for no-op (defaults to 0)
#	DATA_ADDR - if end-of-text-plus-one-page isn't right for data start
#	OTHER_READWRITE_SECTIONS - other than .data .bss .ctors .sdata ...
#		(e.g., .PARISC.global)
#	OTHER_SECTIONS - at the end
#	EXECUTABLE_SYMBOLS - symbols that must be defined for an
#		executable (e.g., _DYNAMIC_LINK)
#	TEXT_START_SYMBOLS - symbols that appear at the start of the
#		.text section.
#	DATA_START_SYMBOLS - symbols that appear at the start of the
#		.data section.
#	OTHER_BSS_SYMBOLS - symbols that appear at the start of the
#		.bss section besides __bss_start.
#	EMBEDDED - whether this is for an embedded system.
#
# When adding sections, do note that the names of some sections are used
# when specifying the start address of the next.
#
test -z "$ENTRY" && ENTRY=_start
test -z "${BIG_OUTPUT_FORMAT}" && BIG_OUTPUT_FORMAT=${OUTPUT_FORMAT}
test -z "${LITTLE_OUTPUT_FORMAT}" && LITTLE_OUTPUT_FORMAT=${OUTPUT_FORMAT}
if [ -z "$MACHINE" ]; then OUTPUT_ARCH=${ARCH}; else OUTPUT_ARCH=${ARCH}:${MACHINE}; fi
test "$LD_FLAG" = "N" && DATA_ADDR=.

CTOR=".ctors ${CONSTRUCTING-0} :
  {
    ${CONSTRUCTING+ PROVIDE (__CTOR_LIST__ = .); }
    ${CONSTRUCTING+${CTOR_START}}
    KEEP (*(.ctors))

    ${CONSTRUCTING+${CTOR_END}}
    ${CONSTRUCTING+ PROVIDE(__CTOR_END__ = .); }
  } ${RELOCATING+ > ${TEXT_MEMORY}}"

DTOR="  .dtors	${CONSTRUCTING-0} :
  {
    ${CONSTRUCTING+ PROVIDE(__DTOR_LIST__ = .); }
    KEEP (*(.dtors))
    ${CONSTRUCTING+ PROVIDE(__DTOR_END__ = .); }
  } ${RELOCATING+ > ${TEXT_MEMORY}}"


VECTORS="
  /* If the 'vectors_addr' symbol is defined, it indicates the start address
     of interrupt vectors.  This depends on the 68HC11 operating mode:

			Addr
     Single chip	0xffc0
     Extended mode	0xffc0
     Bootstrap		0x00c0
     Test		0xbfc0

     In general, the vectors address is 0xffc0.  This can be overriden
     with the '-defsym vectors_addr=0xbfc0' ld option.

     Note: for the bootstrap mode, the interrupt vectors are at 0xbfc0 but
     they are redirected to 0x00c0 by the internal PROM.  Application's vectors
     must also consist of jump instructions (see Motorola's manual).  */

  PROVIDE (_vectors_addr = DEFINED (vectors_addr) ? vectors_addr : 0xffc0);
  .vectors DEFINED (vectors_addr) ? vectors_addr : 0xffc0 :
  {
    KEEP (*(.vectors))
  }"

#
# We provide two emulations: a fixed on that defines some memory banks
# and a configurable one that includes a user provided memory definition.
#
case $GENERIC_BOARD in
  yes|1|YES)
	MEMORY_DEF="
/* Get memory banks definition from some user configuration file.
   This file must be located in some linker directory (search path
   with -L<dir>). See fixed memory banks emulation script.  */
INCLUDE memory.x;
"
	;;
  *)
MEMORY_DEF="
/* Fixed definition of the available memory banks.
   See generic emulation script for a user defined configuration.  */
MEMORY
{
  page0 (rwx) : ORIGIN = 0x0, LENGTH = 256
  text  (rx)  : ORIGIN = ${ROM_START_ADDR}, LENGTH = ${ROM_SIZE}
  data        : ORIGIN = ${RAM_START_ADDR}, LENGTH = ${RAM_SIZE}
  eeprom      : ORIGIN = ${EEPROM_START_ADDR}, LENGTH = ${EEPROM_SIZE}
}

/* Setup the stack on the top of the data memory bank.  */
PROVIDE (_stack = ${RAM_START_ADDR} + ${RAM_SIZE} - 1);
"
	;;
esac

STARTUP_CODE="
    /* Startup code.  */
    KEEP (*(.install0))	/* Section should setup the stack pointer.  */
    KEEP (*(.install1))	/* Place holder for applications.  */
    KEEP (*(.install2))	/* Optional installation of data sections in RAM.  */
    KEEP (*(.install3))	/* Place holder for applications.  */
    KEEP (*(.install4))	/* Section that calls the main.  */
"

FINISH_CODE="
    /* Finish code.  */
    KEEP (*(.fini0))	/* Beginning of finish code (_exit symbol).  */
    KEEP (*(.fini1))	/* Place holder for applications.  */
    KEEP (*(.fini2))	/* C++ destructors.  */
    KEEP (*(.fini3))	/* Place holder for applications.  */
    KEEP (*(.fini4))	/* Runtime exit.  */
"

PRE_COMPUTE_DATA_SIZE="
/* SCz: this does not work yet... This is supposed to force the loading
   of _map_data.o (from libgcc.a) when the .data section is not empty.
   By doing so, this should bring the code that copies the .data section
   from ROM to RAM at init time.

  ___pre_comp_data_size = SIZEOF(.data);
  __install_data_sections = ___pre_comp_data_size > 0 ?
		__map_data_sections : 0;
*/
"

INSTALL_RELOC="
  .install0 0 : { *(.install0) }
  .install1 0 : { *(.install1) }
  .install2 0 : { *(.install2) }
  .install3 0 : { *(.install3) }
  .install4 0 : { *(.install4) }
"

FINISH_RELOC="
  .fini0 0 : { *(.fini0) }
  .fini1 0 : { *(.fini1) }
  .fini2 0 : { *(.fini2) }
  .fini3 0 : { *(.fini3) }
  .fini4 0 : { *(.fini4) }
"

BSS_DATA_RELOC="
  .data1 0 : { *(.data1) }

  /* We want the small data sections together, so single-instruction offsets
     can access them all, and initialized data all before uninitialized, so
     we can shorten the on-disk segment size.  */
  .sdata   0 : { *(.sdata) }
  .sbss    0 : { *(.sbss) }
  .scommon 0 : { *(.scommon) }
"

SOFT_REGS_RELOC="
  .softregs 0 : { *(.softregs) }
"

cat <<EOF
/* Copyright (C) 2014-2019 Free Software Foundation, Inc.

   Copying and distribution of this script, with or without modification,
   are permitted in any medium without royalty provided the copyright
   notice and this notice are preserved.  */

${RELOCATING+/* Linker script for 68HC12 executable (PROM).  */}
${RELOCATING-/* Linker script for 68HC12 object file (ld -r).  */}

OUTPUT_FORMAT("${OUTPUT_FORMAT}", "${BIG_OUTPUT_FORMAT}",
	      "${LITTLE_OUTPUT_FORMAT}")
OUTPUT_ARCH(${OUTPUT_ARCH})
${RELOCATING+ENTRY(${ENTRY})}

${RELOCATING+${LIB_SEARCH_DIRS}}
${RELOCATING+${EXECUTABLE_SYMBOLS}}
${RELOCATING+${MEMORY_DEF}}

SECTIONS
{
  .hash        ${RELOCATING-0} : { *(.hash)		}
  .dynsym      ${RELOCATING-0} : { *(.dynsym)		}
  .dynstr      ${RELOCATING-0} : { *(.dynstr)		}
  .gnu.version		${RELOCATING-0} : { *(.gnu.version) }
  .gnu.version_d	${RELOCATING-0} : { *(.gnu.version_d) }
  .gnu.version_r	${RELOCATING-0} : { *(.gnu.version_r) }

  .rel.text    ${RELOCATING-0} :
    {
      *(.rel.text)
      ${RELOCATING+*(.rel.text.*)}
      ${RELOCATING+*(.rel.gnu.linkonce.t.*)}
    }
  .rela.text   ${RELOCATING-0} :
    {
      *(.rela.text)
      ${RELOCATING+*(.rela.text.*)}
      ${RELOCATING+*(.rela.gnu.linkonce.t.*)}
    }
  .rel.data    ${RELOCATING-0} :
    {
      *(.rel.data)
      ${RELOCATING+*(.rel.data.*)}
      ${RELOCATING+*(.rel.gnu.linkonce.d.*)}
    }
  .rela.data   ${RELOCATING-0} :
    {
      *(.rela.data)
      ${RELOCATING+*(.rela.data.*)}
      ${RELOCATING+*(.rela.gnu.linkonce.d.*)}
    }
  .rel.rodata  ${RELOCATING-0} :
    {
      *(.rel.rodata)
      ${RELOCATING+*(.rel.rodata.*)}
      ${RELOCATING+*(.rel.gnu.linkonce.r.*)}
    }
  .rela.rodata ${RELOCATING-0} :
    {
      *(.rela.rodata)
      ${RELOCATING+*(.rela.rodata.*)}
      ${RELOCATING+*(.rela.gnu.linkonce.r.*)}
    }
  .rel.sdata   ${RELOCATING-0} :
    {
      *(.rel.sdata)
      ${RELOCATING+*(.rel.sdata.*)}
      ${RELOCATING+*(.rel.gnu.linkonce.s.*)}
    }
  .rela.sdata   ${RELOCATING-0} :
    {
      *(.rela.sdata)
      ${RELOCATING+*(.rela.sdata.*)}
      ${RELOCATING+*(.rela.gnu.linkonce.s.*)}
    }
  .rel.sbss    ${RELOCATING-0} :
    {
      *(.rel.sbss)
      ${RELOCATING+*(.rel.sbss.*)}
      ${RELOCATING+*(.rel.gnu.linkonce.sb.*)}
    }
  .rela.sbss   ${RELOCATING-0} :
    {
      *(.rela.sbss)
      ${RELOCATING+*(.rela.sbss.*)}
      ${RELOCATING+*(.rel.gnu.linkonce.sb.*)}
    }
  .rel.bss     ${RELOCATING-0} :
    {
      *(.rel.bss)
      ${RELOCATING+*(.rel.bss.*)}
      ${RELOCATING+*(.rel.gnu.linkonce.b.*)}
    }
  .rela.bss    ${RELOCATING-0} :
    {
      *(.rela.bss)
      ${RELOCATING+*(.rela.bss.*)}
      ${RELOCATING+*(.rela.gnu.linkonce.b.*)}
    }
  .rel.stext		${RELOCATING-0} : { *(.rel.stest) }
  .rela.stext		${RELOCATING-0} : { *(.rela.stest) }
  .rel.etext		${RELOCATING-0} : { *(.rel.etest) }
  .rela.etext		${RELOCATING-0} : { *(.rela.etest) }
  .rel.sdata		${RELOCATING-0} : { *(.rel.sdata) }
  .rela.sdata		${RELOCATING-0} : { *(.rela.sdata) }
  .rel.edata		${RELOCATING-0} : { *(.rel.edata) }
  .rela.edata		${RELOCATING-0} : { *(.rela.edata) }
  .rel.eit_v		${RELOCATING-0} : { *(.rel.eit_v) }
  .rela.eit_v		${RELOCATING-0} : { *(.rela.eit_v) }
  .rel.ebss		${RELOCATING-0} : { *(.rel.ebss) }
  .rela.ebss		${RELOCATING-0} : { *(.rela.ebss) }
  .rel.srodata		${RELOCATING-0} : { *(.rel.srodata) }
  .rela.srodata		${RELOCATING-0} : { *(.rela.srodata) }
  .rel.erodata		${RELOCATING-0} : { *(.rel.erodata) }
  .rela.erodata		${RELOCATING-0} : { *(.rela.erodata) }
  .rel.got		${RELOCATING-0} : { *(.rel.got) }
  .rela.got		${RELOCATING-0} : { *(.rela.got) }
  .rel.ctors		${RELOCATING-0} : { *(.rel.ctors) }
  .rela.ctors		${RELOCATING-0} : { *(.rela.ctors) }
  .rel.dtors		${RELOCATING-0} : { *(.rel.dtors) }
  .rela.dtors		${RELOCATING-0} : { *(.rela.dtors) }
  .rel.init		${RELOCATING-0} : { *(.rel.init) }
  .rela.init		${RELOCATING-0} : { *(.rela.init) }
  .rel.fini		${RELOCATING-0} : { *(.rel.fini) }
  .rela.fini		${RELOCATING-0} : { *(.rela.fini) }
  .rel.plt		${RELOCATING-0} : { *(.rel.plt) }
  .rela.plt		${RELOCATING-0} : { *(.rela.plt) }

  /* Concatenate .page0 sections.  Put them in the page0 memory bank
     unless we are creating a relocatable file.  */
  .page0 :
  {
    *(.page0)
  } ${RELOCATING+ > page0}

  /* Start of text section.  */
  .stext ${RELOCATING-0} :
  {
    *(.stext)
  } ${RELOCATING+ > ${TEXT_MEMORY}}

  .init	${RELOCATING-0} :
  {
    *(.init)
  } ${RELOCATING+=${NOP-0}}

  ${RELOCATING-${INSTALL_RELOC}}
  ${RELOCATING-${FINISH_RELOC}}

  .text ${RELOCATING-0}:
  {
    /* Put startup code at beginning so that _start keeps same address.  */
    ${RELOCATING+${STARTUP_CODE}}

    ${RELOCATING+*(.init)}
    *(.text)
    ${RELOCATING+*(.text.*)}
    /* .gnu.warning sections are handled specially by elf32.em.  */
    *(.gnu.warning)
    ${RELOCATING+*(.gnu.linkonce.t.*)}
    ${RELOCATING+*(.tramp)}
    ${RELOCATING+*(.tramp.*)}

    ${RELOCATING+${FINISH_CODE}}

    ${RELOCATING+_etext = .;}
    ${RELOCATING+PROVIDE (etext = .);}
    ${RELOCATING+. = ALIGN(2);}
  } ${RELOCATING+ > ${TEXT_MEMORY} =0xa7a7a7a7}

  .eh_frame ${RELOCATING-0} :
  {
    KEEP (*(.eh_frame))
  } ${RELOCATING+ > ${TEXT_MEMORY}}

  .gcc_except_table ${RELOCATING-0} :
  {
    *(.gcc_except_table)
  } ${RELOCATING+ > ${TEXT_MEMORY}}

  .rodata  ${RELOCATING-0} :
  {
    *(.rodata)
    ${RELOCATING+*(.rodata.*)}
    ${RELOCATING+*(.gnu.linkonce.r*)}
    ${RELOCATING+. = ALIGN(2);}
  } ${RELOCATING+ > ${TEXT_MEMORY} =0xffffffff}

  .rodata1 ${RELOCATING-0} :
  {
    *(.rodata1)
    ${RELOCATING+. = ALIGN(2);}
  } ${RELOCATING+ > ${TEXT_MEMORY} =0xffffffff}

  /* Constructor and destructor tables are in ROM.  */
  ${RELOCATING+${CTOR}}
  ${RELOCATING+${DTOR}}

  .jcr ${RELOCATING-0} :
  {
    KEEP (*(.jcr))
  } ${RELOCATING+ > ${TEXT_MEMORY}}

  /* Start of the data section image in ROM.  */
  ${RELOCATING+__data_image = .;}
  ${RELOCATING+PROVIDE (__data_image = .);}

  /* All read-only sections that normally go in PROM must be above.
     We construct the DATA image section in PROM at end of all these
     read-only sections.  The data image must be copied at init time.
     Refer to GNU ld, Section 3.6.8.2 Output Section LMA.  */
  .data  ${RELOCATING-0} : ${RELOCATING+AT (__data_image)}
  {
    ${RELOCATING+__data_section_start = .;}
    ${RELOCATING+PROVIDE (__data_section_start = .);}

    ${RELOCATING+${DATA_START_SYMBOLS}}
    ${RELOCATING+*(.sdata)}
    *(.data)
    ${RELOCATING+*(.data.*)}
    ${RELOCATING+*(.data1)}
    ${RELOCATING+*(.gnu.linkonce.d.*)}
    ${CONSTRUCTING+CONSTRUCTORS}

    ${RELOCATING+_edata  =  .;}
    ${RELOCATING+PROVIDE (edata = .);}
    ${RELOCATING+. = ALIGN(2);}
  } ${RELOCATING+ > ${DATA_MEMORY} =0xffffffff}

  ${RELOCATING+__data_section_size = SIZEOF(.data);}
  ${RELOCATING+PROVIDE (__data_section_size = SIZEOF(.data));}
  ${RELOCATING+__data_image_end = __data_image + __data_section_size;}

  ${RELOCATING+${PRE_COMPUTE_DATA_SIZE}}

  /* .install ${RELOCATING-0}:
  {
    . = _data_image_end;
  } ${RELOCATING+ > ${TEXT_MEMORY}} */

  /* Relocation for some bss and data sections.  */
  ${RELOCATING-${BSS_DATA_RELOC}}
  ${RELOCATING-${SOFT_REGS_RELOC}}

  .bss ${RELOCATING-0} :
  {
    ${RELOCATING+__bss_start = .;}
    ${RELOCATING+*(.softregs)}
    ${RELOCATING+*(.sbss)}
    ${RELOCATING+*(.scommon)}
    ${RELOCATING+*(.dynbss)}
    *(.bss)
    ${RELOCATING+*(.bss.*)}
    ${RELOCATING+*(.gnu.linkonce.b.*)}
    ${RELOCATING+*(COMMON)}
    ${RELOCATING+PROVIDE (_end = .);}
  } ${RELOCATING+ > ${DATA_MEMORY}}
  ${RELOCATING+__bss_size = SIZEOF(.bss);}
  ${RELOCATING+PROVIDE (__bss_size = SIZEOF(.bss));}

  .eeprom ${RELOCATING-0} :
  {
    *(.eeprom)
    ${RELOCATING+*(.eeprom.*)}
  } ${RELOCATING+ > ${EEPROM_MEMORY}}

  ${RELOCATING+${VECTORS}}

  /* Stabs debugging sections.  */
  .stab		 0 : { *(.stab) }
  .stabstr	 0 : { *(.stabstr) }
  .stab.excl	 0 : { *(.stab.excl) }
  .stab.exclstr	 0 : { *(.stab.exclstr) }
  .stab.index	 0 : { *(.stab.index) }
  .stab.indexstr 0 : { *(.stab.indexstr) }

  .comment	 0 : { *(.comment) }

  /* Treatment of DWARF debug section must be at end of the linker
     script to avoid problems when there are undefined symbols. It's necessary
     to avoid that the DWARF section is relocated before such undefined
     symbols are found.  */
EOF

. $srcdir/scripttempl/DWARF.sc

cat <<EOF
}
EOF