| 1 | /* Motorola 68HC12-specific support for 32-bit ELF
 | 
|---|
| 2 |    Copyright 1999, 2000, 2002, 2003 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 | 
 | 
|---|
| 6 | This file is part of BFD, the Binary File Descriptor library.
 | 
|---|
| 7 | 
 | 
|---|
| 8 | This program is free software; you can redistribute it and/or modify
 | 
|---|
| 9 | it under the terms of the GNU General Public License as published by
 | 
|---|
| 10 | the Free Software Foundation; either version 2 of the License, or
 | 
|---|
| 11 | (at your option) any later version.
 | 
|---|
| 12 | 
 | 
|---|
| 13 | This program is distributed in the hope that it will be useful,
 | 
|---|
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
|---|
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
|---|
| 16 | GNU General Public License for more details.
 | 
|---|
| 17 | 
 | 
|---|
| 18 | You should have received a copy of the GNU General Public License
 | 
|---|
| 19 | along with this program; if not, write to the Free Software
 | 
|---|
| 20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 | 
|---|
| 21 | 
 | 
|---|
| 22 | #include "bfd.h"
 | 
|---|
| 23 | #include "sysdep.h"
 | 
|---|
| 24 | #include "bfdlink.h"
 | 
|---|
| 25 | #include "libbfd.h"
 | 
|---|
| 26 | #include "elf-bfd.h"
 | 
|---|
| 27 | #include "elf32-m68hc1x.h"
 | 
|---|
| 28 | #include "elf/m68hc11.h"
 | 
|---|
| 29 | #include "opcode/m68hc11.h"
 | 
|---|
| 30 | 
 | 
|---|
| 31 | /* Relocation functions.  */
 | 
|---|
| 32 | static reloc_howto_type *bfd_elf32_bfd_reloc_type_lookup
 | 
|---|
| 33 |   PARAMS ((bfd *, bfd_reloc_code_real_type));
 | 
|---|
| 34 | static void m68hc11_info_to_howto_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 *));
 | 
|---|
| 46 | 
 | 
|---|
| 47 | /* Use REL instead of RELA to save space */
 | 
|---|
| 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 | 
 | 
|---|
| 111 |    The 3-bit and 16-bit PC rel relocation is only used by 68HC12.  */
 | 
|---|
| 112 | static reloc_howto_type elf_m68hc11_howto_table[] = {
 | 
|---|
| 113 |   /* This reloc does nothing.  */
 | 
|---|
| 114 |   HOWTO (R_M68HC11_NONE,        /* type */
 | 
|---|
| 115 |          0,                     /* rightshift */
 | 
|---|
| 116 |          2,                     /* size (0 = byte, 1 = short, 2 = long) */
 | 
|---|
| 117 |          32,                    /* bitsize */
 | 
|---|
| 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 */
 | 
|---|
| 124 |          0,                     /* src_mask */
 | 
|---|
| 125 |          0,                     /* dst_mask */
 | 
|---|
| 126 |          FALSE),                /* pcrel_offset */
 | 
|---|
| 127 | 
 | 
|---|
| 128 |   /* A 8 bit absolute relocation */
 | 
|---|
| 129 |   HOWTO (R_M68HC11_8,           /* type */
 | 
|---|
| 130 |          0,                     /* rightshift */
 | 
|---|
| 131 |          0,                     /* size (0 = byte, 1 = short, 2 = long) */
 | 
|---|
| 132 |          8,                     /* bitsize */
 | 
|---|
| 133 |          FALSE,                 /* pc_relative */
 | 
|---|
| 134 |          0,                     /* bitpos */
 | 
|---|
| 135 |          complain_overflow_bitfield,    /* complain_on_overflow */
 | 
|---|
| 136 |          bfd_elf_generic_reloc, /* special_function */
 | 
|---|
| 137 |          "R_M68HC12_8",         /* name */
 | 
|---|
| 138 |          FALSE,                 /* partial_inplace */
 | 
|---|
| 139 |          0x00ff,                /* src_mask */
 | 
|---|
| 140 |          0x00ff,                /* dst_mask */
 | 
|---|
| 141 |          FALSE),                /* pcrel_offset */
 | 
|---|
| 142 | 
 | 
|---|
| 143 |   /* A 8 bit absolute relocation (upper address) */
 | 
|---|
| 144 |   HOWTO (R_M68HC11_HI8,         /* type */
 | 
|---|
| 145 |          8,                     /* rightshift */
 | 
|---|
| 146 |          0,                     /* size (0 = byte, 1 = short, 2 = long) */
 | 
|---|
| 147 |          8,                     /* bitsize */
 | 
|---|
| 148 |          FALSE,                 /* pc_relative */
 | 
|---|
| 149 |          0,                     /* bitpos */
 | 
|---|
| 150 |          complain_overflow_bitfield,    /* complain_on_overflow */
 | 
|---|
| 151 |          bfd_elf_generic_reloc, /* special_function */
 | 
|---|
| 152 |          "R_M68HC12_HI8",       /* name */
 | 
|---|
| 153 |          FALSE,                 /* partial_inplace */
 | 
|---|
| 154 |          0x00ff,                /* src_mask */
 | 
|---|
| 155 |          0x00ff,                /* dst_mask */
 | 
|---|
| 156 |          FALSE),                /* pcrel_offset */
 | 
|---|
| 157 | 
 | 
|---|
| 158 |   /* A 8 bit absolute relocation (upper address) */
 | 
|---|
| 159 |   HOWTO (R_M68HC11_LO8,         /* type */
 | 
|---|
| 160 |          0,                     /* rightshift */
 | 
|---|
| 161 |          0,                     /* size (0 = byte, 1 = short, 2 = long) */
 | 
|---|
| 162 |          8,                     /* bitsize */
 | 
|---|
| 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 */
 | 
|---|
| 169 |          0x00ff,                /* src_mask */
 | 
|---|
| 170 |          0x00ff,                /* dst_mask */
 | 
|---|
| 171 |          FALSE),                /* pcrel_offset */
 | 
|---|
| 172 | 
 | 
|---|
| 173 |   /* A 8 bit PC-rel relocation */
 | 
|---|
| 174 |   HOWTO (R_M68HC11_PCREL_8,     /* type */
 | 
|---|
| 175 |          0,                     /* rightshift */
 | 
|---|
| 176 |          0,                     /* size (0 = byte, 1 = short, 2 = long) */
 | 
|---|
| 177 |          8,                     /* bitsize */
 | 
|---|
| 178 |          TRUE,                  /* pc_relative */
 | 
|---|
| 179 |          0,                     /* bitpos */
 | 
|---|
| 180 |          complain_overflow_bitfield,    /* complain_on_overflow */
 | 
|---|
| 181 |          bfd_elf_generic_reloc, /* special_function */
 | 
|---|
| 182 |          "R_M68HC12_PCREL_8",   /* name */
 | 
|---|
| 183 |          FALSE,                 /* partial_inplace */
 | 
|---|
| 184 |          0x00ff,                /* src_mask */
 | 
|---|
| 185 |          0x00ff,                /* dst_mask */
 | 
|---|
| 186 |          TRUE),                 /* pcrel_offset */
 | 
|---|
| 187 | 
 | 
|---|
| 188 |   /* A 16 bit absolute relocation */
 | 
|---|
| 189 |   HOWTO (R_M68HC11_16,          /* type */
 | 
|---|
| 190 |          0,                     /* rightshift */
 | 
|---|
| 191 |          1,                     /* size (0 = byte, 1 = short, 2 = long) */
 | 
|---|
| 192 |          16,                    /* bitsize */
 | 
|---|
| 193 |          FALSE,                 /* pc_relative */
 | 
|---|
| 194 |          0,                     /* bitpos */
 | 
|---|
| 195 |          complain_overflow_dont /*bitfield */ , /* complain_on_overflow */
 | 
|---|
| 196 |          bfd_elf_generic_reloc, /* special_function */
 | 
|---|
| 197 |          "R_M68HC12_16",        /* name */
 | 
|---|
| 198 |          FALSE,                 /* partial_inplace */
 | 
|---|
| 199 |          0xffff,                /* src_mask */
 | 
|---|
| 200 |          0xffff,                /* dst_mask */
 | 
|---|
| 201 |          FALSE),                /* pcrel_offset */
 | 
|---|
| 202 | 
 | 
|---|
| 203 |   /* A 32 bit absolute relocation.  This one is never used for the
 | 
|---|
| 204 |      code relocation.  It's used by gas for -gstabs generation.  */
 | 
|---|
| 205 |   HOWTO (R_M68HC11_32,          /* type */
 | 
|---|
| 206 |          0,                     /* rightshift */
 | 
|---|
| 207 |          2,                     /* size (0 = byte, 1 = short, 2 = long) */
 | 
|---|
| 208 |          32,                    /* bitsize */
 | 
|---|
| 209 |          FALSE,                 /* pc_relative */
 | 
|---|
| 210 |          0,                     /* bitpos */
 | 
|---|
| 211 |          complain_overflow_bitfield,    /* complain_on_overflow */
 | 
|---|
| 212 |          bfd_elf_generic_reloc, /* special_function */
 | 
|---|
| 213 |          "R_M68HC12_32",        /* name */
 | 
|---|
| 214 |          FALSE,                 /* partial_inplace */
 | 
|---|
| 215 |          0xffffffff,            /* src_mask */
 | 
|---|
| 216 |          0xffffffff,            /* dst_mask */
 | 
|---|
| 217 |          FALSE),                /* pcrel_offset */
 | 
|---|
| 218 | 
 | 
|---|
| 219 |   /* A 3 bit absolute relocation */
 | 
|---|
| 220 |   HOWTO (R_M68HC11_3B,          /* type */
 | 
|---|
| 221 |          0,                     /* rightshift */
 | 
|---|
| 222 |          0,                     /* size (0 = byte, 1 = short, 2 = long) */
 | 
|---|
| 223 |          3,                     /* bitsize */
 | 
|---|
| 224 |          FALSE,                 /* pc_relative */
 | 
|---|
| 225 |          0,                     /* bitpos */
 | 
|---|
| 226 |          complain_overflow_bitfield,    /* complain_on_overflow */
 | 
|---|
| 227 |          bfd_elf_generic_reloc, /* special_function */
 | 
|---|
| 228 |          "R_M68HC12_4B",        /* name */
 | 
|---|
| 229 |          FALSE,                 /* partial_inplace */
 | 
|---|
| 230 |          0x003,                 /* src_mask */
 | 
|---|
| 231 |          0x003,                 /* dst_mask */
 | 
|---|
| 232 |          FALSE),                /* pcrel_offset */
 | 
|---|
| 233 | 
 | 
|---|
| 234 |   /* A 16 bit PC-rel relocation */
 | 
|---|
| 235 |   HOWTO (R_M68HC11_PCREL_16,    /* type */
 | 
|---|
| 236 |          0,                     /* rightshift */
 | 
|---|
| 237 |          1,                     /* size (0 = byte, 1 = short, 2 = long) */
 | 
|---|
| 238 |          16,                    /* bitsize */
 | 
|---|
| 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 */
 | 
|---|
| 246 |          0xffff,                /* dst_mask */
 | 
|---|
| 247 |          TRUE),                 /* pcrel_offset */
 | 
|---|
| 248 | 
 | 
|---|
| 249 |   /* GNU extension to record C++ vtable hierarchy */
 | 
|---|
| 250 |   HOWTO (R_M68HC11_GNU_VTINHERIT,       /* type */
 | 
|---|
| 251 |          0,                     /* rightshift */
 | 
|---|
| 252 |          1,                     /* size (0 = byte, 1 = short, 2 = long) */
 | 
|---|
| 253 |          0,                     /* bitsize */
 | 
|---|
| 254 |          FALSE,                 /* pc_relative */
 | 
|---|
| 255 |          0,                     /* bitpos */
 | 
|---|
| 256 |          complain_overflow_dont,        /* complain_on_overflow */
 | 
|---|
| 257 |          NULL,                  /* special_function */
 | 
|---|
| 258 |          "R_M68HC11_GNU_VTINHERIT",     /* name */
 | 
|---|
| 259 |          FALSE,                 /* partial_inplace */
 | 
|---|
| 260 |          0,                     /* src_mask */
 | 
|---|
| 261 |          0,                     /* dst_mask */
 | 
|---|
| 262 |          FALSE),                /* pcrel_offset */
 | 
|---|
| 263 | 
 | 
|---|
| 264 |   /* GNU extension to record C++ vtable member usage */
 | 
|---|
| 265 |   HOWTO (R_M68HC11_GNU_VTENTRY, /* type */
 | 
|---|
| 266 |          0,                     /* rightshift */
 | 
|---|
| 267 |          1,                     /* size (0 = byte, 1 = short, 2 = long) */
 | 
|---|
| 268 |          0,                     /* bitsize */
 | 
|---|
| 269 |          FALSE,                 /* pc_relative */
 | 
|---|
| 270 |          0,                     /* bitpos */
 | 
|---|
| 271 |          complain_overflow_dont,        /* complain_on_overflow */
 | 
|---|
| 272 |          _bfd_elf_rel_vtable_reloc_fn,  /* special_function */
 | 
|---|
| 273 |          "R_M68HC11_GNU_VTENTRY",       /* name */
 | 
|---|
| 274 |          FALSE,                 /* partial_inplace */
 | 
|---|
| 275 |          0,                     /* src_mask */
 | 
|---|
| 276 |          0,                     /* dst_mask */
 | 
|---|
| 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 */
 | 
|---|
| 360 | };
 | 
|---|
| 361 | 
 | 
|---|
| 362 | /* Map BFD reloc types to M68HC11 ELF reloc types.  */
 | 
|---|
| 363 | 
 | 
|---|
| 364 | struct m68hc11_reloc_map
 | 
|---|
| 365 | {
 | 
|---|
| 366 |   bfd_reloc_code_real_type bfd_reloc_val;
 | 
|---|
| 367 |   unsigned char elf_reloc_val;
 | 
|---|
| 368 | };
 | 
|---|
| 369 | 
 | 
|---|
| 370 | static const struct m68hc11_reloc_map m68hc11_reloc_map[] = {
 | 
|---|
| 371 |   {BFD_RELOC_NONE, R_M68HC11_NONE,},
 | 
|---|
| 372 |   {BFD_RELOC_8, R_M68HC11_8},
 | 
|---|
| 373 |   {BFD_RELOC_M68HC11_HI8, R_M68HC11_HI8},
 | 
|---|
| 374 |   {BFD_RELOC_M68HC11_LO8, R_M68HC11_LO8},
 | 
|---|
| 375 |   {BFD_RELOC_8_PCREL, R_M68HC11_PCREL_8},
 | 
|---|
| 376 |   {BFD_RELOC_16_PCREL, R_M68HC11_PCREL_16},
 | 
|---|
| 377 |   {BFD_RELOC_16, R_M68HC11_16},
 | 
|---|
| 378 |   {BFD_RELOC_32, R_M68HC11_32},
 | 
|---|
| 379 |   {BFD_RELOC_M68HC11_3B, R_M68HC11_3B},
 | 
|---|
| 380 | 
 | 
|---|
| 381 |   {BFD_RELOC_VTABLE_INHERIT, R_M68HC11_GNU_VTINHERIT},
 | 
|---|
| 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},
 | 
|---|
| 390 | };
 | 
|---|
| 391 | 
 | 
|---|
| 392 | static reloc_howto_type *
 | 
|---|
| 393 | bfd_elf32_bfd_reloc_type_lookup (abfd, code)
 | 
|---|
| 394 |      bfd *abfd ATTRIBUTE_UNUSED;
 | 
|---|
| 395 |      bfd_reloc_code_real_type code;
 | 
|---|
| 396 | {
 | 
|---|
| 397 |   unsigned int i;
 | 
|---|
| 398 | 
 | 
|---|
| 399 |   for (i = 0;
 | 
|---|
| 400 |        i < sizeof (m68hc11_reloc_map) / sizeof (struct m68hc11_reloc_map);
 | 
|---|
| 401 |        i++)
 | 
|---|
| 402 |     {
 | 
|---|
| 403 |       if (m68hc11_reloc_map[i].bfd_reloc_val == code)
 | 
|---|
| 404 |         return &elf_m68hc11_howto_table[m68hc11_reloc_map[i].elf_reloc_val];
 | 
|---|
| 405 |     }
 | 
|---|
| 406 | 
 | 
|---|
| 407 |   return NULL;
 | 
|---|
| 408 | }
 | 
|---|
| 409 | 
 | 
|---|
| 410 | /* Set the howto pointer for an M68HC11 ELF reloc.  */
 | 
|---|
| 411 | 
 | 
|---|
| 412 | static void
 | 
|---|
| 413 | m68hc11_info_to_howto_rel (abfd, cache_ptr, dst)
 | 
|---|
| 414 |      bfd *abfd ATTRIBUTE_UNUSED;
 | 
|---|
| 415 |      arelent *cache_ptr;
 | 
|---|
| 416 |      Elf_Internal_Rela *dst;
 | 
|---|
| 417 | {
 | 
|---|
| 418 |   unsigned int r_type;
 | 
|---|
| 419 | 
 | 
|---|
| 420 |   r_type = ELF32_R_TYPE (dst->r_info);
 | 
|---|
| 421 |   BFD_ASSERT (r_type < (unsigned int) R_M68HC11_max);
 | 
|---|
| 422 |   cache_ptr->howto = &elf_m68hc11_howto_table[r_type];
 | 
|---|
| 423 | }
 | 
|---|
| 424 | 
 | 
|---|
| 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 | 
 | 
|---|
| 543 | #define ELF_ARCH                bfd_arch_m68hc12
 | 
|---|
| 544 | #define ELF_MACHINE_CODE        EM_68HC12
 | 
|---|
| 545 | #define ELF_MAXPAGESIZE         0x1000
 | 
|---|
| 546 | 
 | 
|---|
| 547 | #define TARGET_BIG_SYM          bfd_elf32_m68hc12_vec
 | 
|---|
| 548 | #define TARGET_BIG_NAME         "elf32-m68hc12"
 | 
|---|
| 549 | 
 | 
|---|
| 550 | #define elf_info_to_howto       0
 | 
|---|
| 551 | #define elf_info_to_howto_rel   m68hc11_info_to_howto_rel
 | 
|---|
| 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
 | 
|---|
| 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
 | 
|---|
| 571 | 
 | 
|---|
| 572 | #include "elf32-target.h"
 | 
|---|