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