elf32-m68hc12.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. /* Motorola 68HC12-specific support for 32-bit ELF
  2. Copyright (C) 1999-2022 Free Software Foundation, Inc.
  3. Contributed by Stephane Carrez (stcarrez@nerim.fr)
  4. (Heavily copied from the D10V port by Martin Hunt (hunt@cygnus.com))
  5. This file is part of BFD, the Binary File Descriptor library.
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 3 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  17. MA 02110-1301, USA. */
  18. #include "sysdep.h"
  19. #include "bfd.h"
  20. #include "bfdlink.h"
  21. #include "libbfd.h"
  22. #include "elf-bfd.h"
  23. #include "elf32-m68hc1x.h"
  24. #include "elf/m68hc11.h"
  25. #include "opcode/m68hc11.h"
  26. /* Relocation functions. */
  27. static reloc_howto_type *bfd_elf32_bfd_reloc_type_lookup
  28. (bfd *, bfd_reloc_code_real_type);
  29. static bool m68hc11_info_to_howto_rel
  30. (bfd *, arelent *, Elf_Internal_Rela *);
  31. /* Trampoline generation. */
  32. /* Use REL instead of RELA to save space */
  33. #define USE_REL 1
  34. /* The 68HC12 microcontroler has a memory bank switching system
  35. with a 16Kb window in the 64Kb address space. The extended memory
  36. is mapped in the 16Kb window (at 0x8000). The page register controls
  37. which 16Kb bank is mapped. The call/rtc instructions take care of
  38. bank switching in function calls/returns.
  39. For GNU Binutils to work, we consider there is a physical memory
  40. at 0..0x0ffff and a kind of virtual memory above that. Symbols
  41. in virtual memory have their addresses treated in a special way
  42. when disassembling and when linking.
  43. For the linker to work properly, we must always relocate the virtual
  44. memory as if it is mapped at 0x8000. When a 16-bit relocation is
  45. made in the virtual memory, we check that it does not cross the
  46. memory bank where it is used. This would involve a page change
  47. which would be wrong. The 24-bit relocation is for that and it
  48. treats the address as a physical address + page number.
  49. Banked
  50. Address Space
  51. | | Page n
  52. +---------------+ 0x1010000
  53. | |
  54. | jsr _foo |
  55. | .. | Page 3
  56. | _foo: |
  57. +---------------+ 0x100C000
  58. | |
  59. | call _bar |
  60. | .. | Page 2
  61. | _bar: |
  62. +---------------+ 0x1008000
  63. /------>| |
  64. | | call _foo | Page 1
  65. | | |
  66. | +---------------+ 0x1004000
  67. Physical | | |
  68. Address Space | | | Page 0
  69. | | |
  70. +-----------+ 0x00FFFF | +---------------+ 0x1000000
  71. | | |
  72. | call _foo | |
  73. | | |
  74. +-----------+ 0x00BFFF -+---/
  75. | | |
  76. | | |
  77. | | 16K |
  78. | | |
  79. +-----------+ 0x008000 -+
  80. | |
  81. | |
  82. = =
  83. | |
  84. | |
  85. +-----------+ 0000
  86. The 'call _foo' must be relocated with page 3 and 16-bit address
  87. mapped at 0x8000.
  88. The 3-bit and 16-bit PC rel relocation is only used by 68HC12. */
  89. static reloc_howto_type elf_m68hc11_howto_table[] = {
  90. /* This reloc does nothing. */
  91. HOWTO (R_M68HC11_NONE, /* type */
  92. 0, /* rightshift */
  93. 3, /* size (0 = byte, 1 = short, 2 = long) */
  94. 0, /* bitsize */
  95. false, /* pc_relative */
  96. 0, /* bitpos */
  97. complain_overflow_dont,/* complain_on_overflow */
  98. bfd_elf_generic_reloc, /* special_function */
  99. "R_M68HC12_NONE", /* name */
  100. false, /* partial_inplace */
  101. 0, /* src_mask */
  102. 0, /* dst_mask */
  103. false), /* pcrel_offset */
  104. /* A 8 bit absolute relocation */
  105. HOWTO (R_M68HC11_8, /* type */
  106. 0, /* rightshift */
  107. 0, /* size (0 = byte, 1 = short, 2 = long) */
  108. 8, /* bitsize */
  109. false, /* pc_relative */
  110. 0, /* bitpos */
  111. complain_overflow_bitfield, /* complain_on_overflow */
  112. bfd_elf_generic_reloc, /* special_function */
  113. "R_M68HC12_8", /* name */
  114. false, /* partial_inplace */
  115. 0x00ff, /* src_mask */
  116. 0x00ff, /* dst_mask */
  117. false), /* pcrel_offset */
  118. /* A 8 bit absolute relocation (upper address) */
  119. HOWTO (R_M68HC11_HI8, /* type */
  120. 8, /* rightshift */
  121. 0, /* size (0 = byte, 1 = short, 2 = long) */
  122. 8, /* bitsize */
  123. false, /* pc_relative */
  124. 0, /* bitpos */
  125. complain_overflow_bitfield, /* complain_on_overflow */
  126. bfd_elf_generic_reloc, /* special_function */
  127. "R_M68HC12_HI8", /* name */
  128. false, /* partial_inplace */
  129. 0x00ff, /* src_mask */
  130. 0x00ff, /* dst_mask */
  131. false), /* pcrel_offset */
  132. /* A 8 bit absolute relocation (upper address) */
  133. HOWTO (R_M68HC11_LO8, /* type */
  134. 0, /* rightshift */
  135. 0, /* size (0 = byte, 1 = short, 2 = long) */
  136. 8, /* bitsize */
  137. false, /* pc_relative */
  138. 0, /* bitpos */
  139. complain_overflow_dont, /* complain_on_overflow */
  140. bfd_elf_generic_reloc, /* special_function */
  141. "R_M68HC12_LO8", /* name */
  142. false, /* partial_inplace */
  143. 0x00ff, /* src_mask */
  144. 0x00ff, /* dst_mask */
  145. false), /* pcrel_offset */
  146. /* A 8 bit PC-rel relocation */
  147. HOWTO (R_M68HC11_PCREL_8, /* type */
  148. 0, /* rightshift */
  149. 0, /* size (0 = byte, 1 = short, 2 = long) */
  150. 8, /* bitsize */
  151. true, /* pc_relative */
  152. 0, /* bitpos */
  153. complain_overflow_bitfield, /* complain_on_overflow */
  154. bfd_elf_generic_reloc, /* special_function */
  155. "R_M68HC12_PCREL_8", /* name */
  156. false, /* partial_inplace */
  157. 0x00ff, /* src_mask */
  158. 0x00ff, /* dst_mask */
  159. true), /* pcrel_offset */
  160. /* A 16 bit absolute relocation */
  161. HOWTO (R_M68HC11_16, /* type */
  162. 0, /* rightshift */
  163. 1, /* size (0 = byte, 1 = short, 2 = long) */
  164. 16, /* bitsize */
  165. false, /* pc_relative */
  166. 0, /* bitpos */
  167. complain_overflow_dont /*bitfield */ , /* complain_on_overflow */
  168. bfd_elf_generic_reloc, /* special_function */
  169. "R_M68HC12_16", /* name */
  170. false, /* partial_inplace */
  171. 0xffff, /* src_mask */
  172. 0xffff, /* dst_mask */
  173. false), /* pcrel_offset */
  174. /* A 32 bit absolute relocation. This one is never used for the
  175. code relocation. It's used by gas for -gstabs generation. */
  176. HOWTO (R_M68HC11_32, /* type */
  177. 0, /* rightshift */
  178. 2, /* size (0 = byte, 1 = short, 2 = long) */
  179. 32, /* bitsize */
  180. false, /* pc_relative */
  181. 0, /* bitpos */
  182. complain_overflow_bitfield, /* complain_on_overflow */
  183. bfd_elf_generic_reloc, /* special_function */
  184. "R_M68HC12_32", /* name */
  185. false, /* partial_inplace */
  186. 0xffffffff, /* src_mask */
  187. 0xffffffff, /* dst_mask */
  188. false), /* pcrel_offset */
  189. /* A 3 bit absolute relocation */
  190. HOWTO (R_M68HC11_3B, /* type */
  191. 0, /* rightshift */
  192. 0, /* size (0 = byte, 1 = short, 2 = long) */
  193. 3, /* bitsize */
  194. false, /* pc_relative */
  195. 0, /* bitpos */
  196. complain_overflow_bitfield, /* complain_on_overflow */
  197. bfd_elf_generic_reloc, /* special_function */
  198. "R_M68HC12_4B", /* name */
  199. false, /* partial_inplace */
  200. 0x003, /* src_mask */
  201. 0x003, /* dst_mask */
  202. false), /* pcrel_offset */
  203. /* A 16 bit PC-rel relocation */
  204. HOWTO (R_M68HC11_PCREL_16, /* type */
  205. 0, /* rightshift */
  206. 1, /* size (0 = byte, 1 = short, 2 = long) */
  207. 16, /* bitsize */
  208. true, /* pc_relative */
  209. 0, /* bitpos */
  210. complain_overflow_dont, /* complain_on_overflow */
  211. bfd_elf_generic_reloc, /* special_function */
  212. "R_M68HC12_PCREL_16", /* name */
  213. false, /* partial_inplace */
  214. 0xffff, /* src_mask */
  215. 0xffff, /* dst_mask */
  216. true), /* pcrel_offset */
  217. /* GNU extension to record C++ vtable hierarchy */
  218. HOWTO (R_M68HC11_GNU_VTINHERIT, /* type */
  219. 0, /* rightshift */
  220. 1, /* size (0 = byte, 1 = short, 2 = long) */
  221. 0, /* bitsize */
  222. false, /* pc_relative */
  223. 0, /* bitpos */
  224. complain_overflow_dont, /* complain_on_overflow */
  225. NULL, /* special_function */
  226. "R_M68HC11_GNU_VTINHERIT", /* name */
  227. false, /* partial_inplace */
  228. 0, /* src_mask */
  229. 0, /* dst_mask */
  230. false), /* pcrel_offset */
  231. /* GNU extension to record C++ vtable member usage */
  232. HOWTO (R_M68HC11_GNU_VTENTRY, /* type */
  233. 0, /* rightshift */
  234. 1, /* size (0 = byte, 1 = short, 2 = long) */
  235. 0, /* bitsize */
  236. false, /* pc_relative */
  237. 0, /* bitpos */
  238. complain_overflow_dont, /* complain_on_overflow */
  239. _bfd_elf_rel_vtable_reloc_fn, /* special_function */
  240. "R_M68HC11_GNU_VTENTRY", /* name */
  241. false, /* partial_inplace */
  242. 0, /* src_mask */
  243. 0, /* dst_mask */
  244. false), /* pcrel_offset */
  245. /* A 24 bit relocation */
  246. HOWTO (R_M68HC11_24, /* type */
  247. 0, /* rightshift */
  248. 2, /* size (0 = byte, 1 = short, 2 = long) */
  249. 24, /* bitsize */
  250. false, /* pc_relative */
  251. 0, /* bitpos */
  252. complain_overflow_dont, /* complain_on_overflow */
  253. m68hc11_elf_special_reloc, /* special_function */
  254. "R_M68HC12_24", /* name */
  255. false, /* partial_inplace */
  256. 0xffffff, /* src_mask */
  257. 0xffffff, /* dst_mask */
  258. false), /* pcrel_offset */
  259. /* A 16-bit low relocation */
  260. HOWTO (R_M68HC11_LO16, /* type */
  261. 0, /* rightshift */
  262. 1, /* size (0 = byte, 1 = short, 2 = long) */
  263. 16, /* bitsize */
  264. false, /* pc_relative */
  265. 0, /* bitpos */
  266. complain_overflow_dont, /* complain_on_overflow */
  267. m68hc11_elf_special_reloc,/* special_function */
  268. "R_M68HC12_LO16", /* name */
  269. false, /* partial_inplace */
  270. 0xffff, /* src_mask */
  271. 0xffff, /* dst_mask */
  272. false), /* pcrel_offset */
  273. /* A page relocation */
  274. HOWTO (R_M68HC11_PAGE, /* type */
  275. 0, /* rightshift */
  276. 0, /* size (0 = byte, 1 = short, 2 = long) */
  277. 8, /* bitsize */
  278. false, /* pc_relative */
  279. 0, /* bitpos */
  280. complain_overflow_dont, /* complain_on_overflow */
  281. m68hc11_elf_special_reloc,/* special_function */
  282. "R_M68HC12_PAGE", /* name */
  283. false, /* partial_inplace */
  284. 0x00ff, /* src_mask */
  285. 0x00ff, /* dst_mask */
  286. false), /* pcrel_offset */
  287. EMPTY_HOWTO (14),
  288. /* A 16 bit absolute relocation. */
  289. HOWTO (R_M68HC12_16B, /* type */
  290. 0, /* rightshift */
  291. 1, /* size (0 = byte, 1 = short, 2 = long) */
  292. 16, /* bitsize */
  293. false, /* pc_relative */
  294. 0, /* bitpos */
  295. complain_overflow_bitfield, /* complain_on_overflow */
  296. bfd_elf_generic_reloc, /* special_function */
  297. "R_M68HC12_16B", /* name */
  298. false, /* partial_inplace */
  299. 0xffff, /* src_mask */
  300. 0xffff, /* dst_mask */
  301. false), /* pcrel_offset */
  302. /* A 9 bit PC-rel relocation. */
  303. HOWTO (R_M68HC12_PCREL_9, /* type */
  304. 1, /* rightshift */
  305. 1, /* size (0 = byte, 1 = short, 2 = long) */
  306. 10, /* bitsize (result is >>1) */
  307. true, /* pc_relative */
  308. 0, /* bitpos */
  309. complain_overflow_dont, /* complain_on_overflow */
  310. bfd_elf_generic_reloc, /* special_function */
  311. "R_M68HC12_PCREL_9", /* name */
  312. true, /* partial_inplace */
  313. 0xfe00, /* src_mask */
  314. 0x01ff, /* dst_mask */
  315. true), /* pcrel_offset */
  316. /* A 10 bit PC-rel relocation. */
  317. HOWTO (R_M68HC12_PCREL_10, /* type */
  318. 1, /* rightshift */
  319. 1, /* size (0 = byte, 1 = short, 2 = long) */
  320. 11, /* bitsize (result is >>1) */
  321. true, /* pc_relative */
  322. 0, /* bitpos */
  323. complain_overflow_dont, /* complain_on_overflow */
  324. bfd_elf_generic_reloc, /* special_function */
  325. "R_M68HC12_PCREL_10", /* name */
  326. true, /* partial_inplace */
  327. 0xfc00, /* src_mask */
  328. 0x03ff, /* dst_mask */
  329. true), /* pcrel_offset */
  330. /* A 8 bit absolute relocation (upper address). */
  331. HOWTO (R_M68HC12_HI8XG, /* type */
  332. 8, /* rightshift */
  333. 0, /* size (0 = byte, 1 = short, 2 = long) */
  334. 8, /* bitsize */
  335. false, /* pc_relative */
  336. 0, /* bitpos */
  337. complain_overflow_bitfield, /* complain_on_overflow */
  338. bfd_elf_generic_reloc, /* special_function */
  339. "R_M68HC12_HI8XG", /* name */
  340. false, /* partial_inplace */
  341. 0x00ff, /* src_mask */
  342. 0x00ff, /* dst_mask */
  343. false), /* pcrel_offset */
  344. /* A 8 bit absolute relocation (lower address). */
  345. HOWTO (R_M68HC12_LO8XG, /* type */
  346. 8, /* rightshift */
  347. 0, /* size (0 = byte, 1 = short, 2 = long) */
  348. 8, /* bitsize */
  349. false, /* pc_relative */
  350. 0, /* bitpos */
  351. complain_overflow_bitfield, /* complain_on_overflow */
  352. bfd_elf_generic_reloc, /* special_function */
  353. "R_M68HC12_LO8XG", /* name */
  354. false, /* partial_inplace */
  355. 0x00ff, /* src_mask */
  356. 0x00ff, /* dst_mask */
  357. false), /* pcrel_offset */
  358. /* Mark beginning of a jump instruction (any form). */
  359. HOWTO (R_M68HC11_RL_JUMP, /* type */
  360. 0, /* rightshift */
  361. 1, /* size (0 = byte, 1 = short, 2 = long) */
  362. 0, /* bitsize */
  363. false, /* pc_relative */
  364. 0, /* bitpos */
  365. complain_overflow_dont, /* complain_on_overflow */
  366. m68hc11_elf_ignore_reloc, /* special_function */
  367. "R_M68HC12_RL_JUMP", /* name */
  368. true, /* partial_inplace */
  369. 0, /* src_mask */
  370. 0, /* dst_mask */
  371. true), /* pcrel_offset */
  372. /* Mark beginning of Gcc relaxation group instruction. */
  373. HOWTO (R_M68HC11_RL_GROUP, /* type */
  374. 0, /* rightshift */
  375. 1, /* size (0 = byte, 1 = short, 2 = long) */
  376. 0, /* bitsize */
  377. false, /* pc_relative */
  378. 0, /* bitpos */
  379. complain_overflow_dont, /* complain_on_overflow */
  380. m68hc11_elf_ignore_reloc, /* special_function */
  381. "R_M68HC12_RL_GROUP", /* name */
  382. true, /* partial_inplace */
  383. 0, /* src_mask */
  384. 0, /* dst_mask */
  385. true), /* pcrel_offset */
  386. };
  387. /* Map BFD reloc types to M68HC11 ELF reloc types. */
  388. struct m68hc11_reloc_map
  389. {
  390. bfd_reloc_code_real_type bfd_reloc_val;
  391. unsigned char elf_reloc_val;
  392. };
  393. static const struct m68hc11_reloc_map m68hc11_reloc_map[] =
  394. {
  395. {BFD_RELOC_NONE, R_M68HC11_NONE,},
  396. {BFD_RELOC_8, R_M68HC11_8},
  397. {BFD_RELOC_M68HC11_HI8, R_M68HC11_HI8},
  398. {BFD_RELOC_M68HC11_LO8, R_M68HC11_LO8},
  399. {BFD_RELOC_8_PCREL, R_M68HC11_PCREL_8},
  400. {BFD_RELOC_16_PCREL, R_M68HC11_PCREL_16},
  401. {BFD_RELOC_16, R_M68HC11_16},
  402. {BFD_RELOC_32, R_M68HC11_32},
  403. {BFD_RELOC_M68HC11_3B, R_M68HC11_3B},
  404. {BFD_RELOC_VTABLE_INHERIT, R_M68HC11_GNU_VTINHERIT},
  405. {BFD_RELOC_VTABLE_ENTRY, R_M68HC11_GNU_VTENTRY},
  406. {BFD_RELOC_M68HC11_LO16, R_M68HC11_LO16},
  407. {BFD_RELOC_M68HC11_PAGE, R_M68HC11_PAGE},
  408. {BFD_RELOC_M68HC11_24, R_M68HC11_24},
  409. {BFD_RELOC_M68HC11_RL_JUMP, R_M68HC11_RL_JUMP},
  410. {BFD_RELOC_M68HC11_RL_GROUP, R_M68HC11_RL_GROUP},
  411. {BFD_RELOC_M68HC12_16B, R_M68HC12_16B},
  412. {BFD_RELOC_M68HC12_9_PCREL, R_M68HC12_PCREL_9},
  413. {BFD_RELOC_M68HC12_10_PCREL, R_M68HC12_PCREL_10},
  414. {BFD_RELOC_M68HC12_HI8XG, R_M68HC12_HI8XG},
  415. {BFD_RELOC_M68HC12_LO8XG, R_M68HC12_LO8XG},
  416. };
  417. static reloc_howto_type *
  418. bfd_elf32_bfd_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
  419. bfd_reloc_code_real_type code)
  420. {
  421. unsigned int i;
  422. for (i = 0;
  423. i < sizeof (m68hc11_reloc_map) / sizeof (struct m68hc11_reloc_map);
  424. i++)
  425. {
  426. if (m68hc11_reloc_map[i].bfd_reloc_val == code)
  427. return &elf_m68hc11_howto_table[m68hc11_reloc_map[i].elf_reloc_val];
  428. }
  429. return NULL;
  430. }
  431. static reloc_howto_type *
  432. bfd_elf32_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
  433. const char *r_name)
  434. {
  435. unsigned int i;
  436. for (i = 0;
  437. i < (sizeof (elf_m68hc11_howto_table)
  438. / sizeof (elf_m68hc11_howto_table[0]));
  439. i++)
  440. if (elf_m68hc11_howto_table[i].name != NULL
  441. && strcasecmp (elf_m68hc11_howto_table[i].name, r_name) == 0)
  442. return &elf_m68hc11_howto_table[i];
  443. return NULL;
  444. }
  445. /* Set the howto pointer for an M68HC11 ELF reloc. */
  446. static bool
  447. m68hc11_info_to_howto_rel (bfd *abfd,
  448. arelent *cache_ptr, Elf_Internal_Rela *dst)
  449. {
  450. unsigned int r_type;
  451. r_type = ELF32_R_TYPE (dst->r_info);
  452. if (r_type >= (unsigned int) R_M68HC11_max)
  453. {
  454. /* xgettext:c-format */
  455. _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
  456. abfd, r_type);
  457. bfd_set_error (bfd_error_bad_value);
  458. return false;
  459. }
  460. cache_ptr->howto = &elf_m68hc11_howto_table[r_type];
  461. return true;
  462. }
  463. /* Far trampoline generation. */
  464. /* Build a 68HC12 trampoline stub. */
  465. static bool
  466. m68hc12_elf_build_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
  467. {
  468. struct elf32_m68hc11_stub_hash_entry *stub_entry;
  469. struct bfd_link_info *info;
  470. struct m68hc11_elf_link_hash_table *htab;
  471. asection *stub_sec;
  472. bfd *stub_bfd;
  473. bfd_byte *loc;
  474. bfd_vma sym_value, phys_page, phys_addr;
  475. /* Massage our args to the form they really have. */
  476. stub_entry = (struct elf32_m68hc11_stub_hash_entry *) gen_entry;
  477. info = (struct bfd_link_info *) in_arg;
  478. /* Fail if the target section could not be assigned to an output
  479. section. The user should fix his linker script. */
  480. if (stub_entry->target_section->output_section == NULL
  481. && info->non_contiguous_regions)
  482. info->callbacks->einfo (_("%F%P: Could not assign '%pA' to an output section. "
  483. "Retry without --enable-non-contiguous-regions.\n"),
  484. stub_entry->target_section);
  485. htab = m68hc11_elf_hash_table (info);
  486. stub_sec = stub_entry->stub_sec;
  487. /* Make a note of the offset within the stubs for this entry. */
  488. stub_entry->stub_offset = stub_sec->size;
  489. stub_sec->size += 7;
  490. loc = stub_sec->contents + stub_entry->stub_offset;
  491. stub_bfd = stub_sec->owner;
  492. /* Create the trampoline call stub:
  493. ldy #%addr(symbol)
  494. call %page(symbol), __trampoline
  495. */
  496. sym_value = (stub_entry->target_value
  497. + stub_entry->target_section->output_offset
  498. + stub_entry->target_section->output_section->vma);
  499. phys_addr = m68hc11_phys_addr (&htab->pinfo, sym_value);
  500. phys_page = m68hc11_phys_page (&htab->pinfo, sym_value);
  501. /* ldy #%page(sym) */
  502. bfd_put_8 (stub_bfd, 0xCD, loc);
  503. bfd_put_16 (stub_bfd, phys_addr, loc + 1);
  504. loc += 3;
  505. /* call %page(sym), __trampoline */
  506. bfd_put_8 (stub_bfd, 0x4a, loc);
  507. bfd_put_16 (stub_bfd, htab->pinfo.trampoline_addr, loc + 1);
  508. bfd_put_8 (stub_bfd, phys_page, loc + 3);
  509. return true;
  510. }
  511. /* As above, but don't actually build the stub. Just bump offset so
  512. we know stub section sizes. */
  513. static bool
  514. m68hc12_elf_size_one_stub (struct bfd_hash_entry *gen_entry,
  515. void *in_arg ATTRIBUTE_UNUSED)
  516. {
  517. struct elf32_m68hc11_stub_hash_entry *stub_entry;
  518. /* Massage our args to the form they really have. */
  519. stub_entry = (struct elf32_m68hc11_stub_hash_entry *) gen_entry;
  520. stub_entry->stub_sec->size += 7;
  521. return true;
  522. }
  523. /* Create a 68HC12 ELF linker hash table. */
  524. static struct bfd_link_hash_table *
  525. m68hc12_elf_bfd_link_hash_table_create (bfd *abfd)
  526. {
  527. struct m68hc11_elf_link_hash_table *ret;
  528. ret = m68hc11_elf_hash_table_create (abfd);
  529. if (ret == (struct m68hc11_elf_link_hash_table *) NULL)
  530. return NULL;
  531. ret->size_one_stub = m68hc12_elf_size_one_stub;
  532. ret->build_one_stub = m68hc12_elf_build_one_stub;
  533. return &ret->root.root;
  534. }
  535. static bool
  536. m68hc12_elf_set_mach_from_flags (bfd *abfd)
  537. {
  538. flagword flags = elf_elfheader (abfd)->e_flags;
  539. switch (flags & EF_M68HC11_MACH_MASK)
  540. {
  541. case EF_M68HC12_MACH:
  542. bfd_default_set_arch_mach (abfd, bfd_arch_m68hc12, bfd_mach_m6812);
  543. break;
  544. case EF_M68HCS12_MACH:
  545. bfd_default_set_arch_mach (abfd, bfd_arch_m68hc12, bfd_mach_m6812s);
  546. break;
  547. case EF_M68HC11_GENERIC:
  548. bfd_default_set_arch_mach (abfd, bfd_arch_m68hc12,
  549. bfd_mach_m6812_default);
  550. break;
  551. default:
  552. return false;
  553. }
  554. return true;
  555. }
  556. /* Specific sections:
  557. - The .page0 is a data section that is mapped in [0x0000..0x00FF].
  558. Page0 accesses are faster on the M68HC12.
  559. - The .vectors is the section that represents the interrupt
  560. vectors. */
  561. static const struct bfd_elf_special_section elf32_m68hc12_special_sections[] =
  562. {
  563. { STRING_COMMA_LEN (".eeprom"), 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
  564. { STRING_COMMA_LEN (".page0"), 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
  565. { STRING_COMMA_LEN (".softregs"), 0, SHT_NOBITS, SHF_ALLOC + SHF_WRITE },
  566. { STRING_COMMA_LEN (".vectors"), 0, SHT_PROGBITS, SHF_ALLOC },
  567. { NULL, 0, 0, 0, 0 }
  568. };
  569. #define ELF_ARCH bfd_arch_m68hc12
  570. #define ELF_TARGET_ID M68HC11_ELF_DATA
  571. #define ELF_MACHINE_CODE EM_68HC12
  572. #define ELF_MAXPAGESIZE 0x1000
  573. #define TARGET_BIG_SYM m68hc12_elf32_vec
  574. #define TARGET_BIG_NAME "elf32-m68hc12"
  575. #define elf_info_to_howto NULL
  576. #define elf_info_to_howto_rel m68hc11_info_to_howto_rel
  577. #define elf_backend_check_relocs elf32_m68hc11_check_relocs
  578. #define elf_backend_relocate_section elf32_m68hc11_relocate_section
  579. #define elf_backend_object_p m68hc12_elf_set_mach_from_flags
  580. #define elf_backend_can_gc_sections 1
  581. #define elf_backend_special_sections elf32_m68hc12_special_sections
  582. #define elf_backend_init_file_header elf32_m68hc11_init_file_header
  583. #define elf_backend_add_symbol_hook elf32_m68hc11_add_symbol_hook
  584. #define elf_backend_merge_symbol_attribute elf32_m68hc11_merge_symbol_attribute
  585. #define bfd_elf32_bfd_link_hash_table_create \
  586. m68hc12_elf_bfd_link_hash_table_create
  587. #define bfd_elf32_bfd_merge_private_bfd_data \
  588. _bfd_m68hc11_elf_merge_private_bfd_data
  589. #define bfd_elf32_bfd_set_private_flags _bfd_m68hc11_elf_set_private_flags
  590. #define bfd_elf32_bfd_print_private_bfd_data \
  591. _bfd_m68hc11_elf_print_private_bfd_data
  592. #include "elf32-target.h"