elfm68hc12.sc 13 KB

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