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 #include "bfd.h"
00027 #include "sysdep.h"
00028 #include "libbfd.h"
00029 #include "bfdlink.h"
00030 #include "coff/w65.h"
00031 #include "coff/internal.h"
00032 #include "libcoff.h"
00033
00034 static int select_reloc PARAMS ((reloc_howto_type *));
00035 static void rtype2howto PARAMS ((arelent *, struct internal_reloc *));
00036 static void reloc_processing PARAMS ((arelent *, struct internal_reloc *, asymbol **, bfd *, asection *));
00037 static int w65_reloc16_estimate PARAMS ((bfd *, asection *, arelent *, unsigned int, struct bfd_link_info *));
00038 static void w65_reloc16_extra_cases 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 static reloc_howto_type howto_table[] =
00042 {
00043 HOWTO (R_W65_ABS8, 0, 0, 8, FALSE, 0, complain_overflow_bitfield, 0, "abs8", TRUE, 0x000000ff, 0x000000ff, FALSE),
00044 HOWTO (R_W65_ABS16, 1, 0, 16, FALSE, 0, complain_overflow_bitfield, 0, "abs16", TRUE, 0x0000ffff, 0x0000ffff, FALSE),
00045 HOWTO (R_W65_ABS24, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, 0, "abs24", TRUE, 0x00ffffff, 0x00ffffff, FALSE),
00046 HOWTO (R_W65_ABS8S8, 0, 0, 8, FALSE, 0, complain_overflow_bitfield, 0, ">abs8", TRUE, 0x000000ff, 0x000000ff, FALSE),
00047 HOWTO (R_W65_ABS8S16, 0, 0, 8, FALSE, 0, complain_overflow_bitfield, 0, "^abs8", TRUE, 0x000000ff, 0x000000ff, FALSE),
00048 HOWTO (R_W65_ABS16S8, 1, 0, 16, FALSE, 0, complain_overflow_bitfield, 0, ">abs16", TRUE, 0x0000ffff, 0x0000ffff, FALSE),
00049 HOWTO (R_W65_ABS16S16,1, 0, 16, FALSE, 0, complain_overflow_bitfield, 0, "^abs16", TRUE, 0x0000ffff, 0x0000ffff, FALSE),
00050 HOWTO (R_W65_PCR8, 0, 0, 8, FALSE, 0, complain_overflow_bitfield, 0, "pcrel8", TRUE, 0x000000ff, 0x000000ff, TRUE),
00051 HOWTO (R_W65_PCR16, 1, 0, 16, FALSE, 0, complain_overflow_bitfield, 0, "pcrel16", TRUE, 0x0000ffff, 0x0000ffff, TRUE),
00052 HOWTO (R_W65_DP, 0, 0, 8, FALSE, 0, complain_overflow_bitfield, 0, "dp", TRUE, 0x000000ff, 0x000000ff, FALSE),
00053 };
00054
00055
00056
00057 #define SELECT_RELOC(x,howto) \
00058 { x.r_type = select_reloc(howto); }
00059
00060 #define BADMAG(x) (W65BADMAG(x))
00061 #define W65 1
00062 #define __A_MAGIC_SET__
00063
00064
00065 #define SWAP_IN_RELOC_OFFSET H_GET_32
00066 #define SWAP_OUT_RELOC_OFFSET H_PUT_32
00067 #define SWAP_OUT_RELOC_EXTRA(abfd, src, dst) \
00068 dst->r_stuff[0] = 'S'; \
00069 dst->r_stuff[1] = 'C';
00070
00071 static int
00072 select_reloc (howto)
00073 reloc_howto_type *howto;
00074 {
00075 return howto->type ;
00076 }
00077
00078
00079
00080 static void
00081 rtype2howto (internal, dst)
00082 arelent *internal;
00083 struct internal_reloc *dst;
00084 {
00085 internal->howto = howto_table + dst->r_type - 1;
00086 }
00087
00088 #define RTYPE2HOWTO(internal, relocentry) rtype2howto(internal,relocentry)
00089
00090
00091
00092 #define CALC_ADDEND(abfd, symbol, ext_reloc, cache_ptr) \
00093 cache_ptr->addend = ext_reloc.r_offset;
00094
00095 #define RELOC_PROCESSING(relent,reloc,symbols,abfd,section) \
00096 reloc_processing(relent, reloc, symbols, abfd, section)
00097
00098 static void
00099 reloc_processing (relent, reloc, symbols, abfd, section)
00100 arelent * relent;
00101 struct internal_reloc *reloc;
00102 asymbol ** symbols;
00103 bfd * abfd;
00104 asection * section;
00105 {
00106 relent->address = reloc->r_vaddr;
00107 rtype2howto (relent, reloc);
00108
00109 if (((int) reloc->r_symndx) > 0)
00110 relent->sym_ptr_ptr = symbols + obj_convert (abfd)[reloc->r_symndx];
00111 else
00112 relent->sym_ptr_ptr = (asymbol **)&(bfd_abs_symbol);
00113
00114 relent->addend = reloc->r_offset;
00115
00116 relent->address -= section->vma;
00117
00118 }
00119
00120 static int
00121 w65_reloc16_estimate (abfd, input_section, reloc, shrink, link_info)
00122 bfd *abfd;
00123 asection *input_section;
00124 arelent *reloc;
00125 unsigned int shrink;
00126 struct bfd_link_info *link_info;
00127 {
00128 bfd_vma value;
00129 bfd_vma dot;
00130 bfd_vma gap;
00131
00132
00133
00134
00135
00136
00137
00138
00139 bfd_vma address = reloc->address - shrink;
00140
00141 switch (reloc->howto->type)
00142 {
00143 case R_MOV16B2:
00144 case R_JMP2:
00145 shrink+=2;
00146 break;
00147
00148
00149 case R_MOV16B1:
00150 value = bfd_coff_reloc16_get_value (reloc, link_info, input_section);
00151
00152 if (value >= 0xff00)
00153 {
00154
00155
00156 reloc->howto = reloc->howto + 1;
00157
00158
00159 shrink += 2;
00160 bfd_perform_slip (abfd, 2, input_section, address);
00161 }
00162
00163 break;
00164
00165
00166
00167
00168 case R_JMPL1:
00169 value = bfd_coff_reloc16_get_value (reloc, link_info, input_section);
00170
00171 dot = input_section->output_section->vma +
00172 input_section->output_offset + address;
00173
00174
00175
00176
00177 gap = value - dot;
00178
00179 if (-120 < (long) gap && (long) gap < 120)
00180 {
00181
00182
00183 reloc->howto = reloc->howto + 1;
00184
00185 shrink += 2;
00186 bfd_perform_slip (abfd, 2, input_section, address);
00187 }
00188 break;
00189
00190 case R_JMP1:
00191 value = bfd_coff_reloc16_get_value (reloc, link_info, input_section);
00192
00193 dot = input_section->output_section->vma +
00194 input_section->output_offset + address;
00195
00196
00197
00198
00199 gap = value - (dot - shrink);
00200
00201 if (-120 < (long) gap && (long) gap < 120)
00202 {
00203
00204
00205 reloc->howto = reloc->howto + 1;
00206
00207
00208
00209 shrink += 2;
00210 bfd_perform_slip (abfd, 2, input_section, address);
00211 }
00212 break;
00213 }
00214
00215 return shrink;
00216 }
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227 static void
00228 w65_reloc16_extra_cases (abfd, link_info, link_order, reloc, data, src_ptr,
00229 dst_ptr)
00230 bfd *abfd;
00231 struct bfd_link_info *link_info;
00232 struct bfd_link_order *link_order;
00233 arelent *reloc;
00234 bfd_byte *data;
00235 unsigned int *src_ptr;
00236 unsigned int *dst_ptr;
00237 {
00238 unsigned int src_address = *src_ptr;
00239 unsigned int dst_address = *dst_ptr;
00240 asection *input_section = link_order->u.indirect.section;
00241
00242 switch (reloc->howto->type)
00243 {
00244 case R_W65_ABS8:
00245 case R_W65_DP:
00246 {
00247 unsigned int gap = bfd_coff_reloc16_get_value (reloc, link_info,
00248 input_section);
00249 bfd_put_8 (abfd, gap, data + dst_address);
00250 dst_address += 1;
00251 src_address += 1;
00252 }
00253 break;
00254
00255 case R_W65_ABS8S8:
00256 {
00257 unsigned int gap = bfd_coff_reloc16_get_value (reloc, link_info,
00258 input_section);
00259 gap >>= 8;
00260 bfd_put_8 (abfd, gap, data + dst_address);
00261 dst_address += 1;
00262 src_address += 1;
00263 }
00264 break;
00265
00266 case R_W65_ABS8S16:
00267 {
00268 unsigned int gap = bfd_coff_reloc16_get_value (reloc, link_info,
00269 input_section);
00270 gap >>= 16;
00271 bfd_put_8 (abfd, gap, data + dst_address);
00272 dst_address += 1;
00273 src_address += 1;
00274 }
00275 break;
00276
00277 case R_W65_ABS16:
00278 {
00279 unsigned int gap = bfd_coff_reloc16_get_value (reloc, link_info,
00280 input_section);
00281
00282 bfd_put_16 (abfd, (bfd_vma) gap, data + dst_address);
00283 dst_address += 2;
00284 src_address += 2;
00285 }
00286 break;
00287 case R_W65_ABS16S8:
00288 {
00289 unsigned int gap = bfd_coff_reloc16_get_value (reloc, link_info,
00290 input_section);
00291 gap >>= 8;
00292 bfd_put_16 (abfd, (bfd_vma) gap, data + dst_address);
00293 dst_address += 2;
00294 src_address += 2;
00295 }
00296 break;
00297 case R_W65_ABS16S16:
00298 {
00299 unsigned int gap = bfd_coff_reloc16_get_value (reloc, link_info,
00300 input_section);
00301 gap >>= 16;
00302 bfd_put_16 (abfd, (bfd_vma) gap, data + dst_address);
00303 dst_address += 2;
00304 src_address += 2;
00305 }
00306 break;
00307
00308 case R_W65_ABS24:
00309 {
00310 unsigned int gap = bfd_coff_reloc16_get_value (reloc, link_info,
00311 input_section);
00312 bfd_put_16 (abfd, (bfd_vma) gap, data + dst_address);
00313 bfd_put_8 (abfd, gap >> 16, data+dst_address + 2);
00314 dst_address += 3;
00315 src_address += 3;
00316 }
00317 break;
00318
00319 case R_W65_PCR8:
00320 {
00321 int gap = bfd_coff_reloc16_get_value (reloc, link_info,
00322 input_section);
00323 bfd_vma dot = link_order->offset
00324 + dst_address
00325 + link_order->u.indirect.section->output_section->vma;
00326
00327 gap -= dot + 1;
00328 if (gap < -128 || gap > 127)
00329 {
00330 if (! ((*link_info->callbacks->reloc_overflow)
00331 (link_info, NULL,
00332 bfd_asymbol_name (*reloc->sym_ptr_ptr),
00333 reloc->howto->name, reloc->addend, input_section->owner,
00334 input_section, reloc->address)))
00335 abort ();
00336 }
00337 bfd_put_8 (abfd, gap, data + dst_address);
00338 dst_address += 1;
00339 src_address += 1;
00340 }
00341 break;
00342
00343 case R_W65_PCR16:
00344 {
00345 bfd_vma gap = bfd_coff_reloc16_get_value (reloc, link_info,
00346 input_section);
00347 bfd_vma dot = link_order->offset
00348 + dst_address
00349 + link_order->u.indirect.section->output_section->vma;
00350
00351
00352
00353 if ((gap & 0xf0000) != (dot & 0xf0000))
00354 {
00355 if (! ((*link_info->callbacks->reloc_overflow)
00356 (link_info, NULL,
00357 bfd_asymbol_name (*reloc->sym_ptr_ptr),
00358 reloc->howto->name, reloc->addend, input_section->owner,
00359 input_section, reloc->address)))
00360 abort ();
00361 }
00362
00363 gap -= dot + 2;
00364 bfd_put_16 (abfd, gap, data + dst_address);
00365 dst_address += 2;
00366 src_address += 2;
00367 }
00368 break;
00369 default:
00370 printf (_("ignoring reloc %s\n"), reloc->howto->name);
00371 break;
00372
00373 }
00374 *src_ptr = src_address;
00375 *dst_ptr = dst_address;
00376 }
00377
00378 #define coff_reloc16_extra_cases w65_reloc16_extra_cases
00379 #define coff_reloc16_estimate w65_reloc16_estimate
00380
00381 #include "coffcode.h"
00382
00383 #undef coff_bfd_get_relocated_section_contents
00384 #undef coff_bfd_relax_section
00385 #define coff_bfd_get_relocated_section_contents \
00386 bfd_coff_reloc16_get_relocated_section_contents
00387 #define coff_bfd_relax_section bfd_coff_reloc16_relax_section
00388
00389 CREATE_LITTLE_COFF_TARGET_VEC (w65_vec, "coff-w65", BFD_IS_RELAXABLE, 0, '_', NULL, COFF_SWAP_TABLE)