00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "bfd.h"
00028 #include "sysdep.h"
00029 #include "libbfd.h"
00030 #include "bfdlink.h"
00031 #include "coff/h8500.h"
00032 #include "coff/internal.h"
00033 #include "libcoff.h"
00034
00035 static int coff_h8500_select_reloc PARAMS ((reloc_howto_type *));
00036 static void rtype2howto PARAMS ((arelent *, struct internal_reloc *));
00037 static void reloc_processing PARAMS ((arelent *, struct internal_reloc *, asymbol **, bfd *, asection *));
00038 static void extra_case PARAMS ((bfd *, struct bfd_link_info *, struct bfd_link_order *, arelent *, bfd_byte *, unsigned int *, unsigned int *));
00039
00040 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (1)
00041
00042 static reloc_howto_type r_imm8 =
00043 HOWTO (R_H8500_IMM8, 0, 1, 8, FALSE, 0,
00044 complain_overflow_bitfield, 0, "r_imm8", TRUE, 0x000000ff, 0x000000ff, FALSE);
00045
00046 static reloc_howto_type r_imm16 =
00047 HOWTO (R_H8500_IMM16, 0, 1, 16, FALSE, 0,
00048 complain_overflow_bitfield, 0, "r_imm16", TRUE, 0x0000ffff, 0x0000ffff, FALSE);
00049
00050 static reloc_howto_type r_imm24 =
00051 HOWTO (R_H8500_IMM24, 0, 1, 24, FALSE, 0,
00052 complain_overflow_bitfield, 0, "r_imm24", TRUE, 0x00ffffff, 0x00ffffff, FALSE);
00053
00054 static reloc_howto_type r_imm32 =
00055 HOWTO (R_H8500_IMM32, 0, 1, 32, FALSE, 0,
00056 complain_overflow_bitfield, 0, "r_imm32", TRUE, 0xffffffff, 0xffffffff, FALSE);
00057
00058 static reloc_howto_type r_high8 =
00059 HOWTO (R_H8500_HIGH8, 0, 1, 8, FALSE, 0,
00060 complain_overflow_dont, 0, "r_high8", TRUE, 0x000000ff, 0x000000ff, FALSE);
00061
00062 static reloc_howto_type r_low16 =
00063 HOWTO (R_H8500_LOW16, 0, 1, 16, FALSE, 0,
00064 complain_overflow_dont, 0, "r_low16", TRUE, 0x0000ffff, 0x0000ffff, FALSE);
00065
00066 static reloc_howto_type r_pcrel8 =
00067 HOWTO (R_H8500_PCREL8, 0, 1, 8, TRUE, 0, complain_overflow_signed, 0, "r_pcrel8", TRUE, 0, 0, TRUE);
00068
00069 static reloc_howto_type r_pcrel16 =
00070 HOWTO (R_H8500_PCREL16, 0, 1, 16, TRUE, 0, complain_overflow_signed, 0, "r_pcrel16", TRUE, 0, 0, TRUE);
00071
00072 static reloc_howto_type r_high16 =
00073 HOWTO (R_H8500_HIGH16, 0, 1, 8, FALSE, 0,
00074 complain_overflow_dont, 0, "r_high16", TRUE, 0x000ffff, 0x0000ffff, FALSE);
00075
00076
00077
00078 static int
00079 coff_h8500_select_reloc (howto)
00080 reloc_howto_type *howto;
00081 {
00082 return howto->type;
00083 }
00084
00085 #define SELECT_RELOC(x,howto) x.r_type = coff_h8500_select_reloc(howto)
00086
00087 #define BADMAG(x) H8500BADMAG(x)
00088 #define H8500 1
00089
00090 #define __A_MAGIC_SET__
00091
00092
00093 #define SWAP_IN_RELOC_OFFSET H_GET_32
00094 #define SWAP_OUT_RELOC_OFFSET H_PUT_32
00095 #define SWAP_OUT_RELOC_EXTRA(abfd, src, dst) \
00096 dst->r_stuff[0] = 'S'; \
00097 dst->r_stuff[1] = 'C';
00098
00099
00100
00101 static void
00102 rtype2howto (internal, dst)
00103 arelent * internal;
00104 struct internal_reloc *dst;
00105 {
00106 switch (dst->r_type)
00107 {
00108 default:
00109 abort ();
00110 break;
00111 case R_H8500_IMM8:
00112 internal->howto = &r_imm8;
00113 break;
00114 case R_H8500_IMM16:
00115 internal->howto = &r_imm16;
00116 break;
00117 case R_H8500_IMM24:
00118 internal->howto = &r_imm24;
00119 break;
00120 case R_H8500_IMM32:
00121 internal->howto = &r_imm32;
00122 break;
00123 case R_H8500_PCREL8:
00124 internal->howto = &r_pcrel8;
00125 break;
00126 case R_H8500_PCREL16:
00127 internal->howto = &r_pcrel16;
00128 break;
00129 case R_H8500_HIGH8:
00130 internal->howto = &r_high8;
00131 break;
00132 case R_H8500_HIGH16:
00133 internal->howto = &r_high16;
00134 break;
00135 case R_H8500_LOW16:
00136 internal->howto = &r_low16;
00137 break;
00138 }
00139 }
00140
00141 #define RTYPE2HOWTO(internal, relocentry) rtype2howto(internal,relocentry)
00142
00143
00144
00145 #define CALC_ADDEND(abfd, symbol, ext_reloc, cache_ptr) \
00146 cache_ptr->addend = ext_reloc.r_offset;
00147
00148 #define RELOC_PROCESSING(relent,reloc,symbols,abfd,section) \
00149 reloc_processing(relent, reloc, symbols, abfd, section)
00150
00151 static void reloc_processing (relent, reloc, symbols, abfd, section)
00152 arelent * relent;
00153 struct internal_reloc *reloc;
00154 asymbol ** symbols;
00155 bfd * abfd;
00156 asection * section;
00157 {
00158 relent->address = reloc->r_vaddr;
00159 rtype2howto (relent, reloc);
00160
00161 if (reloc->r_symndx > 0)
00162 relent->sym_ptr_ptr = symbols + obj_convert (abfd)[reloc->r_symndx];
00163 else
00164 relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
00165
00166 relent->addend = reloc->r_offset;
00167 relent->address -= section->vma;
00168 }
00169
00170 static void
00171 extra_case (in_abfd, link_info, link_order, reloc, data, src_ptr, dst_ptr)
00172 bfd *in_abfd;
00173 struct bfd_link_info *link_info;
00174 struct bfd_link_order *link_order;
00175 arelent *reloc;
00176 bfd_byte *data;
00177 unsigned int *src_ptr;
00178 unsigned int *dst_ptr;
00179 {
00180 bfd_byte *d = data+*dst_ptr;
00181 asection *input_section = link_order->u.indirect.section;
00182
00183 switch (reloc->howto->type)
00184 {
00185 case R_H8500_IMM8:
00186 bfd_put_8 (in_abfd,
00187 bfd_coff_reloc16_get_value (reloc, link_info, input_section),
00188 d);
00189 (*dst_ptr) += 1;
00190 (*src_ptr) += 1;
00191 break;
00192
00193 case R_H8500_HIGH8:
00194 bfd_put_8 (in_abfd,
00195 (bfd_coff_reloc16_get_value (reloc, link_info, input_section)
00196 >> 16),
00197 d);
00198 (*dst_ptr) += 1;
00199 (*src_ptr) += 1;
00200 break;
00201
00202 case R_H8500_IMM16:
00203 bfd_put_16 (in_abfd,
00204 bfd_coff_reloc16_get_value (reloc, link_info, input_section),
00205 d);
00206 (*dst_ptr) += 2;
00207 (*src_ptr) += 2;
00208 break;
00209
00210 case R_H8500_LOW16:
00211 bfd_put_16 (in_abfd,
00212 bfd_coff_reloc16_get_value (reloc, link_info, input_section),
00213 d);
00214
00215 (*dst_ptr) += 2;
00216 (*src_ptr) += 2;
00217 break;
00218
00219 case R_H8500_HIGH16:
00220 bfd_put_16 (in_abfd,
00221 (bfd_coff_reloc16_get_value (reloc, link_info, input_section)
00222 >> 16),
00223 d);
00224
00225 (*dst_ptr) += 2;
00226 (*src_ptr) += 2;
00227 break;
00228
00229 case R_H8500_IMM24:
00230 {
00231 int v = bfd_coff_reloc16_get_value (reloc, link_info, input_section);
00232 int o = bfd_get_32 (in_abfd, data+ *dst_ptr -1);
00233 v = (v & 0x00ffffff) | (o & 0xff00000);
00234 bfd_put_32 (in_abfd, (bfd_vma) v, data + *dst_ptr -1);
00235 (*dst_ptr) += 3;
00236 (*src_ptr) += 3;;
00237 }
00238 break;
00239 case R_H8500_IMM32:
00240 {
00241 int v = bfd_coff_reloc16_get_value (reloc, link_info, input_section);
00242 bfd_put_32 (in_abfd, (bfd_vma) v, data + *dst_ptr);
00243 (*dst_ptr) += 4;
00244 (*src_ptr) += 4;;
00245 }
00246 break;
00247
00248 case R_H8500_PCREL8:
00249 {
00250 bfd_vma dst = bfd_coff_reloc16_get_value (reloc, link_info,
00251 input_section);
00252 bfd_vma dot = link_order->offset
00253 + *dst_ptr
00254 + link_order->u.indirect.section->output_section->vma;
00255 int gap = dst - dot - 1;
00256
00257
00258 if (gap > 128 || gap < -128)
00259 {
00260 if (! ((*link_info->callbacks->reloc_overflow)
00261 (link_info, NULL,
00262 bfd_asymbol_name (*reloc->sym_ptr_ptr),
00263 reloc->howto->name, reloc->addend, input_section->owner,
00264 input_section, reloc->address)))
00265 abort ();
00266 }
00267 bfd_put_8 (in_abfd, gap, data + *dst_ptr);
00268 (*dst_ptr)++;
00269 (*src_ptr)++;
00270 break;
00271 }
00272 case R_H8500_PCREL16:
00273 {
00274 bfd_vma dst = bfd_coff_reloc16_get_value (reloc, link_info,
00275 input_section);
00276 bfd_vma dot = link_order->offset
00277 + *dst_ptr
00278 + link_order->u.indirect.section->output_section->vma;
00279 int gap = dst - dot - 1;
00280
00281
00282 if (gap > 32767 || gap < -32768)
00283 {
00284 if (! ((*link_info->callbacks->reloc_overflow)
00285 (link_info, NULL,
00286 bfd_asymbol_name (*reloc->sym_ptr_ptr),
00287 reloc->howto->name, reloc->addend, input_section->owner,
00288 input_section, reloc->address)))
00289 abort ();
00290 }
00291 bfd_put_16 (in_abfd, (bfd_vma) gap, data + *dst_ptr);
00292 (*dst_ptr) += 2;
00293 (*src_ptr) += 2;
00294 break;
00295 }
00296
00297 default:
00298 abort ();
00299 }
00300 }
00301
00302 #define coff_reloc16_extra_cases extra_case
00303
00304 #include "coffcode.h"
00305
00306 #undef coff_bfd_get_relocated_section_contents
00307 #undef coff_bfd_relax_section
00308 #define coff_bfd_get_relocated_section_contents \
00309 bfd_coff_reloc16_get_relocated_section_contents
00310 #define coff_bfd_relax_section bfd_coff_reloc16_relax_section
00311
00312 CREATE_BIG_COFF_TARGET_VEC (h8500coff_vec, "coff-h8500", 0, 0, '_', NULL, COFF_SWAP_TABLE)