Changeset 609 for branches/GNU/src/binutils/bfd/elf32-m68hc12.c
- Timestamp:
- Aug 16, 2003, 6:59:22 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GNU/src/binutils/bfd/elf32-m68hc12.c
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.1.1.2
r608 r609 1 1 /* Motorola 68HC12-specific support for 32-bit ELF 2 Copyright 1999, 2000 Free Software Foundation, Inc.3 Contributed by Stephane Carrez (stcarrez@ worldnet.fr)2 Copyright 1999, 2000, 2002, 2003 Free Software Foundation, Inc. 3 Contributed by Stephane Carrez (stcarrez@nerim.fr) 4 4 (Heavily copied from the D10V port by Martin Hunt (hunt@cygnus.com)) 5 5 … … 22 22 #include "bfd.h" 23 23 #include "sysdep.h" 24 #include "bfdlink.h" 24 25 #include "libbfd.h" 25 26 #include "elf-bfd.h" 27 #include "elf32-m68hc1x.h" 26 28 #include "elf/m68hc11.h" 27 29 #include "opcode/m68hc11.h" 30 31 /* Relocation functions. */ 28 32 static reloc_howto_type *bfd_elf32_bfd_reloc_type_lookup 29 PARAMS ((bfd * abfd, bfd_reloc_code_real_type code));33 PARAMS ((bfd *, bfd_reloc_code_real_type)); 30 34 static void m68hc11_info_to_howto_rel 31 PARAMS ((bfd *, arelent *, Elf32_Internal_Rel *)); 35 PARAMS ((bfd *, arelent *, Elf_Internal_Rela *)); 36 37 /* Trampoline generation. */ 38 static bfd_boolean m68hc12_elf_size_one_stub 39 PARAMS((struct bfd_hash_entry *gen_entry, PTR in_arg)); 40 static bfd_boolean m68hc12_elf_build_one_stub 41 PARAMS((struct bfd_hash_entry *gen_entry, PTR in_arg)); 42 static struct bfd_link_hash_table* m68hc12_elf_bfd_link_hash_table_create 43 PARAMS((bfd*)); 44 45 static bfd_boolean m68hc12_elf_set_mach_from_flags PARAMS ((bfd *)); 32 46 33 47 /* Use REL instead of RELA to save space */ 34 #define USE_REL 35 36 /* The Motorola 68HC11 microcontroler only addresses 64Kb. 37 We must handle 8 and 16-bit relocations. The 32-bit relocation 38 is defined but not used except by gas when -gstabs is used (which 39 is wrong). 48 #define USE_REL 1 49 50 /* The 68HC12 microcontroler has a memory bank switching system 51 with a 16Kb window in the 64Kb address space. The extended memory 52 is mapped in the 16Kb window (at 0x8000). The page register controls 53 which 16Kb bank is mapped. The call/rtc instructions take care of 54 bank switching in function calls/returns. 55 56 For GNU Binutils to work, we consider there is a physical memory 57 at 0..0x0ffff and a kind of virtual memory above that. Symbols 58 in virtual memory have their addresses treated in a special way 59 when disassembling and when linking. 60 61 For the linker to work properly, we must always relocate the virtual 62 memory as if it is mapped at 0x8000. When a 16-bit relocation is 63 made in the virtual memory, we check that it does not cross the 64 memory bank where it is used. This would involve a page change 65 which would be wrong. The 24-bit relocation is for that and it 66 treats the address as a physical address + page number. 67 68 69 Banked 70 Address Space 71 | | Page n 72 +---------------+ 0x1010000 73 | | 74 | jsr _foo | 75 | .. | Page 3 76 | _foo: | 77 +---------------+ 0x100C000 78 | | 79 | call _bar | 80 | .. | Page 2 81 | _bar: | 82 +---------------+ 0x1008000 83 /------>| | 84 | | call _foo | Page 1 85 | | | 86 | +---------------+ 0x1004000 87 Physical | | | 88 Address Space | | | Page 0 89 | | | 90 +-----------+ 0x00FFFF | +---------------+ 0x1000000 91 | | | 92 | call _foo | | 93 | | | 94 +-----------+ 0x00BFFF -+---/ 95 | | | 96 | | | 97 | | 16K | 98 | | | 99 +-----------+ 0x008000 -+ 100 | | 101 | | 102 = = 103 | | 104 | | 105 +-----------+ 0000 106 107 108 The 'call _foo' must be relocated with page 3 and 16-bit address 109 mapped at 0x8000. 110 40 111 The 3-bit and 16-bit PC rel relocation is only used by 68HC12. */ 41 112 static reloc_howto_type elf_m68hc11_howto_table[] = { … … 45 116 2, /* size (0 = byte, 1 = short, 2 = long) */ 46 117 32, /* bitsize */ 47 false, /* pc_relative */48 0, /* bitpos */ 49 complain_overflow_ bitfield,/* complain_on_overflow */50 bfd_elf_generic_reloc, /* special_function */ 51 "R_M68HC1 1_NONE", /* name */52 false, /* partial_inplace */118 FALSE, /* pc_relative */ 119 0, /* bitpos */ 120 complain_overflow_dont,/* complain_on_overflow */ 121 bfd_elf_generic_reloc, /* special_function */ 122 "R_M68HC12_NONE", /* name */ 123 FALSE, /* partial_inplace */ 53 124 0, /* src_mask */ 54 125 0, /* dst_mask */ 55 false), /* pcrel_offset */126 FALSE), /* pcrel_offset */ 56 127 57 128 /* A 8 bit absolute relocation */ … … 60 131 0, /* size (0 = byte, 1 = short, 2 = long) */ 61 132 8, /* bitsize */ 62 false, /* pc_relative */133 FALSE, /* pc_relative */ 63 134 0, /* bitpos */ 64 135 complain_overflow_bitfield, /* complain_on_overflow */ 65 136 bfd_elf_generic_reloc, /* special_function */ 66 "R_M68HC1 1_8", /* name */67 false, /* partial_inplace */137 "R_M68HC12_8", /* name */ 138 FALSE, /* partial_inplace */ 68 139 0x00ff, /* src_mask */ 69 140 0x00ff, /* dst_mask */ 70 false), /* pcrel_offset */141 FALSE), /* pcrel_offset */ 71 142 72 143 /* A 8 bit absolute relocation (upper address) */ … … 75 146 0, /* size (0 = byte, 1 = short, 2 = long) */ 76 147 8, /* bitsize */ 77 false, /* pc_relative */148 FALSE, /* pc_relative */ 78 149 0, /* bitpos */ 79 150 complain_overflow_bitfield, /* complain_on_overflow */ 80 151 bfd_elf_generic_reloc, /* special_function */ 81 "R_M68HC1 1_HI8", /* name */82 false, /* partial_inplace */152 "R_M68HC12_HI8", /* name */ 153 FALSE, /* partial_inplace */ 83 154 0x00ff, /* src_mask */ 84 155 0x00ff, /* dst_mask */ 85 false), /* pcrel_offset */156 FALSE), /* pcrel_offset */ 86 157 87 158 /* A 8 bit absolute relocation (upper address) */ … … 90 161 0, /* size (0 = byte, 1 = short, 2 = long) */ 91 162 8, /* bitsize */ 92 false, /* pc_relative */93 0, /* bitpos */ 94 complain_overflow_dont, /* complain_on_overflow */ 95 bfd_elf_generic_reloc, /* special_function */ 96 "R_M68HC1 1_LO8", /* name */97 false, /* partial_inplace */163 FALSE, /* pc_relative */ 164 0, /* bitpos */ 165 complain_overflow_dont, /* complain_on_overflow */ 166 bfd_elf_generic_reloc, /* special_function */ 167 "R_M68HC12_LO8", /* name */ 168 FALSE, /* partial_inplace */ 98 169 0x00ff, /* src_mask */ 99 170 0x00ff, /* dst_mask */ 100 false), /* pcrel_offset */171 FALSE), /* pcrel_offset */ 101 172 102 173 /* A 8 bit PC-rel relocation */ … … 105 176 0, /* size (0 = byte, 1 = short, 2 = long) */ 106 177 8, /* bitsize */ 107 true, /* pc_relative */178 TRUE, /* pc_relative */ 108 179 0, /* bitpos */ 109 180 complain_overflow_bitfield, /* complain_on_overflow */ 110 181 bfd_elf_generic_reloc, /* special_function */ 111 "R_M68HC1 1_PCREL_8", /* name */112 false, /* partial_inplace */113 0x0 ,/* src_mask */182 "R_M68HC12_PCREL_8", /* name */ 183 FALSE, /* partial_inplace */ 184 0x00ff, /* src_mask */ 114 185 0x00ff, /* dst_mask */ 115 false),/* pcrel_offset */186 TRUE), /* pcrel_offset */ 116 187 117 188 /* A 16 bit absolute relocation */ … … 120 191 1, /* size (0 = byte, 1 = short, 2 = long) */ 121 192 16, /* bitsize */ 122 false, /* pc_relative */193 FALSE, /* pc_relative */ 123 194 0, /* bitpos */ 124 195 complain_overflow_dont /*bitfield */ , /* complain_on_overflow */ 125 196 bfd_elf_generic_reloc, /* special_function */ 126 "R_M68HC1 1_16", /* name */127 false, /* partial_inplace */197 "R_M68HC12_16", /* name */ 198 FALSE, /* partial_inplace */ 128 199 0xffff, /* src_mask */ 129 200 0xffff, /* dst_mask */ 130 false), /* pcrel_offset */201 FALSE), /* pcrel_offset */ 131 202 132 203 /* A 32 bit absolute relocation. This one is never used for the … … 136 207 2, /* size (0 = byte, 1 = short, 2 = long) */ 137 208 32, /* bitsize */ 138 false, /* pc_relative */209 FALSE, /* pc_relative */ 139 210 0, /* bitpos */ 140 211 complain_overflow_bitfield, /* complain_on_overflow */ 141 212 bfd_elf_generic_reloc, /* special_function */ 142 "R_M68HC1 1_32", /* name */143 false, /* partial_inplace */213 "R_M68HC12_32", /* name */ 214 FALSE, /* partial_inplace */ 144 215 0xffffffff, /* src_mask */ 145 216 0xffffffff, /* dst_mask */ 146 false), /* pcrel_offset */217 FALSE), /* pcrel_offset */ 147 218 148 219 /* A 3 bit absolute relocation */ … … 151 222 0, /* size (0 = byte, 1 = short, 2 = long) */ 152 223 3, /* bitsize */ 153 false, /* pc_relative */224 FALSE, /* pc_relative */ 154 225 0, /* bitpos */ 155 226 complain_overflow_bitfield, /* complain_on_overflow */ 156 227 bfd_elf_generic_reloc, /* special_function */ 157 "R_M68HC1 1_4B", /* name */158 false, /* partial_inplace */228 "R_M68HC12_4B", /* name */ 229 FALSE, /* partial_inplace */ 159 230 0x003, /* src_mask */ 160 231 0x003, /* dst_mask */ 161 false), /* pcrel_offset */232 FALSE), /* pcrel_offset */ 162 233 163 234 /* A 16 bit PC-rel relocation */ … … 166 237 1, /* size (0 = byte, 1 = short, 2 = long) */ 167 238 16, /* bitsize */ 168 true, /* pc_relative */169 0, /* bitpos */ 170 complain_overflow_dont, /* complain_on_overflow */ 171 bfd_elf_generic_reloc, /* special_function */ 172 "R_M68HC1 1_PCREL_16", /* name */173 false, /* partial_inplace */174 0x 0,/* src_mask */239 TRUE, /* pc_relative */ 240 0, /* bitpos */ 241 complain_overflow_dont, /* complain_on_overflow */ 242 bfd_elf_generic_reloc, /* special_function */ 243 "R_M68HC12_PCREL_16", /* name */ 244 FALSE, /* partial_inplace */ 245 0xffff, /* src_mask */ 175 246 0xffff, /* dst_mask */ 176 false),/* pcrel_offset */247 TRUE), /* pcrel_offset */ 177 248 178 249 /* GNU extension to record C++ vtable hierarchy */ … … 181 252 1, /* size (0 = byte, 1 = short, 2 = long) */ 182 253 0, /* bitsize */ 183 false, /* pc_relative */254 FALSE, /* pc_relative */ 184 255 0, /* bitpos */ 185 256 complain_overflow_dont, /* complain_on_overflow */ 186 257 NULL, /* special_function */ 187 258 "R_M68HC11_GNU_VTINHERIT", /* name */ 188 false, /* partial_inplace */259 FALSE, /* partial_inplace */ 189 260 0, /* src_mask */ 190 261 0, /* dst_mask */ 191 false), /* pcrel_offset */262 FALSE), /* pcrel_offset */ 192 263 193 264 /* GNU extension to record C++ vtable member usage */ … … 196 267 1, /* size (0 = byte, 1 = short, 2 = long) */ 197 268 0, /* bitsize */ 198 false, /* pc_relative */269 FALSE, /* pc_relative */ 199 270 0, /* bitpos */ 200 271 complain_overflow_dont, /* complain_on_overflow */ 201 272 _bfd_elf_rel_vtable_reloc_fn, /* special_function */ 202 273 "R_M68HC11_GNU_VTENTRY", /* name */ 203 false, /* partial_inplace */274 FALSE, /* partial_inplace */ 204 275 0, /* src_mask */ 205 276 0, /* dst_mask */ 206 false), /* pcrel_offset */ 277 FALSE), /* pcrel_offset */ 278 279 /* A 24 bit relocation */ 280 HOWTO (R_M68HC11_24, /* type */ 281 0, /* rightshift */ 282 2, /* size (0 = byte, 1 = short, 2 = long) */ 283 24, /* bitsize */ 284 FALSE, /* pc_relative */ 285 0, /* bitpos */ 286 complain_overflow_dont, /* complain_on_overflow */ 287 m68hc11_elf_special_reloc, /* special_function */ 288 "R_M68HC12_24", /* name */ 289 FALSE, /* partial_inplace */ 290 0xffffff, /* src_mask */ 291 0xffffff, /* dst_mask */ 292 FALSE), /* pcrel_offset */ 293 294 /* A 16-bit low relocation */ 295 HOWTO (R_M68HC11_LO16, /* type */ 296 0, /* rightshift */ 297 1, /* size (0 = byte, 1 = short, 2 = long) */ 298 16, /* bitsize */ 299 FALSE, /* pc_relative */ 300 0, /* bitpos */ 301 complain_overflow_dont, /* complain_on_overflow */ 302 m68hc11_elf_special_reloc,/* special_function */ 303 "R_M68HC12_LO16", /* name */ 304 FALSE, /* partial_inplace */ 305 0xffff, /* src_mask */ 306 0xffff, /* dst_mask */ 307 FALSE), /* pcrel_offset */ 308 309 /* A page relocation */ 310 HOWTO (R_M68HC11_PAGE, /* type */ 311 0, /* rightshift */ 312 0, /* size (0 = byte, 1 = short, 2 = long) */ 313 8, /* bitsize */ 314 FALSE, /* pc_relative */ 315 0, /* bitpos */ 316 complain_overflow_dont, /* complain_on_overflow */ 317 m68hc11_elf_special_reloc,/* special_function */ 318 "R_M68HC12_PAGE", /* name */ 319 FALSE, /* partial_inplace */ 320 0x00ff, /* src_mask */ 321 0x00ff, /* dst_mask */ 322 FALSE), /* pcrel_offset */ 323 324 EMPTY_HOWTO (14), 325 EMPTY_HOWTO (15), 326 EMPTY_HOWTO (16), 327 EMPTY_HOWTO (17), 328 EMPTY_HOWTO (18), 329 EMPTY_HOWTO (19), 330 331 /* Mark beginning of a jump instruction (any form). */ 332 HOWTO (R_M68HC11_RL_JUMP, /* type */ 333 0, /* rightshift */ 334 1, /* size (0 = byte, 1 = short, 2 = long) */ 335 0, /* bitsize */ 336 FALSE, /* pc_relative */ 337 0, /* bitpos */ 338 complain_overflow_dont, /* complain_on_overflow */ 339 m68hc11_elf_ignore_reloc, /* special_function */ 340 "R_M68HC12_RL_JUMP", /* name */ 341 TRUE, /* partial_inplace */ 342 0, /* src_mask */ 343 0, /* dst_mask */ 344 TRUE), /* pcrel_offset */ 345 346 /* Mark beginning of Gcc relaxation group instruction. */ 347 HOWTO (R_M68HC11_RL_GROUP, /* type */ 348 0, /* rightshift */ 349 1, /* size (0 = byte, 1 = short, 2 = long) */ 350 0, /* bitsize */ 351 FALSE, /* pc_relative */ 352 0, /* bitpos */ 353 complain_overflow_dont, /* complain_on_overflow */ 354 m68hc11_elf_ignore_reloc, /* special_function */ 355 "R_M68HC12_RL_GROUP", /* name */ 356 TRUE, /* partial_inplace */ 357 0, /* src_mask */ 358 0, /* dst_mask */ 359 TRUE), /* pcrel_offset */ 207 360 }; 208 361 … … 226 379 {BFD_RELOC_M68HC11_3B, R_M68HC11_3B}, 227 380 228 /* The following relocs are defined but they probably don't work yet. */229 381 {BFD_RELOC_VTABLE_INHERIT, R_M68HC11_GNU_VTINHERIT}, 230 382 {BFD_RELOC_VTABLE_ENTRY, R_M68HC11_GNU_VTENTRY}, 383 384 {BFD_RELOC_M68HC11_LO16, R_M68HC11_LO16}, 385 {BFD_RELOC_M68HC11_PAGE, R_M68HC11_PAGE}, 386 {BFD_RELOC_M68HC11_24, R_M68HC11_24}, 387 388 {BFD_RELOC_M68HC11_RL_JUMP, R_M68HC11_RL_JUMP}, 389 {BFD_RELOC_M68HC11_RL_GROUP, R_M68HC11_RL_GROUP}, 231 390 }; 232 391 … … 255 414 bfd *abfd ATTRIBUTE_UNUSED; 256 415 arelent *cache_ptr; 257 Elf 32_Internal_Rel*dst;416 Elf_Internal_Rela *dst; 258 417 { 259 418 unsigned int r_type; … … 264 423 } 265 424 266 /* Below is the only difference between elf32-m68hc12.c and elf32-m68hc11.c. 267 The Motorola spec says to use a different Elf machine code. */ 425 426 427 /* Far trampoline generation. */ 428 429 /* Build a 68HC12 trampoline stub. */ 430 static bfd_boolean 431 m68hc12_elf_build_one_stub (gen_entry, in_arg) 432 struct bfd_hash_entry *gen_entry; 433 PTR in_arg; 434 { 435 struct elf32_m68hc11_stub_hash_entry *stub_entry; 436 struct bfd_link_info *info; 437 struct m68hc11_elf_link_hash_table *htab; 438 asection *stub_sec; 439 bfd *stub_bfd; 440 bfd_byte *loc; 441 bfd_vma sym_value, phys_page, phys_addr; 442 443 /* Massage our args to the form they really have. */ 444 stub_entry = (struct elf32_m68hc11_stub_hash_entry *) gen_entry; 445 info = (struct bfd_link_info *) in_arg; 446 447 htab = m68hc11_elf_hash_table (info); 448 449 stub_sec = stub_entry->stub_sec; 450 451 /* Make a note of the offset within the stubs for this entry. */ 452 stub_entry->stub_offset = stub_sec->_raw_size; 453 stub_sec->_raw_size += 7; 454 loc = stub_sec->contents + stub_entry->stub_offset; 455 456 stub_bfd = stub_sec->owner; 457 458 /* Create the trampoline call stub: 459 460 ldy #%addr(symbol) 461 call %page(symbol), __trampoline 462 463 */ 464 sym_value = (stub_entry->target_value 465 + stub_entry->target_section->output_offset 466 + stub_entry->target_section->output_section->vma); 467 phys_addr = m68hc11_phys_addr (&htab->pinfo, sym_value); 468 phys_page = m68hc11_phys_page (&htab->pinfo, sym_value); 469 470 /* ldy #%page(sym) */ 471 bfd_put_8 (stub_bfd, 0xCD, loc); 472 bfd_put_16 (stub_bfd, phys_addr, loc + 1); 473 loc += 3; 474 475 /* call %page(sym), __trampoline */ 476 bfd_put_8 (stub_bfd, 0x4a, loc); 477 bfd_put_16 (stub_bfd, htab->pinfo.trampoline_addr, loc + 1); 478 bfd_put_8 (stub_bfd, phys_page, loc + 3); 479 480 return TRUE; 481 } 482 483 /* As above, but don't actually build the stub. Just bump offset so 484 we know stub section sizes. */ 485 486 static bfd_boolean 487 m68hc12_elf_size_one_stub (gen_entry, in_arg) 488 struct bfd_hash_entry *gen_entry; 489 PTR in_arg ATTRIBUTE_UNUSED; 490 { 491 struct elf32_m68hc11_stub_hash_entry *stub_entry; 492 493 /* Massage our args to the form they really have. */ 494 stub_entry = (struct elf32_m68hc11_stub_hash_entry *) gen_entry; 495 496 stub_entry->stub_sec->_raw_size += 7; 497 return TRUE; 498 } 499 500 /* Create a 68HC12 ELF linker hash table. */ 501 502 static struct bfd_link_hash_table * 503 m68hc12_elf_bfd_link_hash_table_create (abfd) 504 bfd *abfd; 505 { 506 struct m68hc11_elf_link_hash_table *ret; 507 508 ret = m68hc11_elf_hash_table_create (abfd); 509 if (ret == (struct m68hc11_elf_link_hash_table *) NULL) 510 return NULL; 511 512 ret->size_one_stub = m68hc12_elf_size_one_stub; 513 ret->build_one_stub = m68hc12_elf_build_one_stub; 514 515 return &ret->root.root; 516 } 517 518 519 static bfd_boolean 520 m68hc12_elf_set_mach_from_flags (abfd) 521 bfd *abfd; 522 { 523 flagword flags = elf_elfheader (abfd)->e_flags; 524 525 switch (flags & EF_M68HC11_MACH_MASK) 526 { 527 case EF_M68HC12_MACH: 528 bfd_default_set_arch_mach (abfd, bfd_arch_m68hc12, bfd_mach_m6812); 529 break; 530 case EF_M68HCS12_MACH: 531 bfd_default_set_arch_mach (abfd, bfd_arch_m68hc12, bfd_mach_m6812s); 532 break; 533 case EF_M68HC11_GENERIC: 534 bfd_default_set_arch_mach (abfd, bfd_arch_m68hc12, 535 bfd_mach_m6812_default); 536 break; 537 default: 538 return FALSE; 539 } 540 return TRUE; 541 } 542 268 543 #define ELF_ARCH bfd_arch_m68hc12 269 544 #define ELF_MACHINE_CODE EM_68HC12 … … 275 550 #define elf_info_to_howto 0 276 551 #define elf_info_to_howto_rel m68hc11_info_to_howto_rel 277 #define elf_backend_object_p 0 552 #define elf_backend_gc_mark_hook elf32_m68hc11_gc_mark_hook 553 #define elf_backend_gc_sweep_hook elf32_m68hc11_gc_sweep_hook 554 #define elf_backend_check_relocs elf32_m68hc11_check_relocs 555 #define elf_backend_relocate_section elf32_m68hc11_relocate_section 556 #define elf_backend_object_p m68hc12_elf_set_mach_from_flags 278 557 #define elf_backend_final_write_processing 0 558 #define elf_backend_can_gc_sections 1 559 #define elf_backend_post_process_headers elf32_m68hc11_post_process_headers 560 #define elf_backend_add_symbol_hook elf32_m68hc11_add_symbol_hook 561 562 #define bfd_elf32_bfd_link_hash_table_create \ 563 m68hc12_elf_bfd_link_hash_table_create 564 #define bfd_elf32_bfd_link_hash_table_free \ 565 m68hc11_elf_bfd_link_hash_table_free 566 #define bfd_elf32_bfd_merge_private_bfd_data \ 567 _bfd_m68hc11_elf_merge_private_bfd_data 568 #define bfd_elf32_bfd_set_private_flags _bfd_m68hc11_elf_set_private_flags 569 #define bfd_elf32_bfd_print_private_bfd_data \ 570 _bfd_m68hc11_elf_print_private_bfd_data 279 571 280 572 #include "elf32-target.h" -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.