Changeset 609 for branches/GNU/src/binutils/bfd/coff-w65.c
- Timestamp:
- Aug 16, 2003, 6:59:22 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GNU/src/binutils/bfd/coff-w65.c
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.1.1.2
r608 r609 1 1 /* BFD back-end for WDC 65816 COFF binaries. 2 Copyright 1995, 1996, 1997, 1999, 2000 Free Software Foundation, Inc. 2 Copyright 1995, 1996, 1997, 1999, 2000, 2001, 2002 3 Free Software Foundation, Inc. 3 4 Written by Steve Chamberlain, <sac@cygnus.com>. 4 5 … … 27 28 #include "libcoff.h" 28 29 30 static int select_reloc PARAMS ((reloc_howto_type *)); 31 static void rtype2howto PARAMS ((arelent *, struct internal_reloc *)); 32 static void reloc_processing PARAMS ((arelent *, struct internal_reloc *, asymbol **, bfd *, asection *)); 33 static int w65_reloc16_estimate PARAMS ((bfd *, asection *, arelent *, unsigned int, struct bfd_link_info *)); 34 static void w65_reloc16_extra_cases PARAMS ((bfd *,struct bfd_link_info *, struct bfd_link_order *, arelent *, bfd_byte *, unsigned int *, unsigned int *)); 35 29 36 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (1) 30 37 static reloc_howto_type howto_table[] = 31 { 32 HOWTO (R_W65_ABS8, 0, 0, 8, false, 0, complain_overflow_bitfield, 0, "abs8", true, 0x000000ff, 0x000000ff, false), 33 HOWTO (R_W65_ABS16, 1, 0, 16, false, 0, complain_overflow_bitfield, 0, "abs16", true, 0x0000ffff, 0x0000ffff, false), 34 HOWTO (R_W65_ABS24, 0, 2, 32, false, 0, complain_overflow_bitfield, 0, "abs24", true, 0x00ffffff, 0x00ffffff, false), 35 HOWTO (R_W65_ABS8S8, 0, 0, 8, false, 0, complain_overflow_bitfield, 0, ">abs8", true, 0x000000ff, 0x000000ff, false), 36 HOWTO (R_W65_ABS8S16, 0, 0, 8, false, 0, complain_overflow_bitfield, 0, "^abs8", true, 0x000000ff, 0x000000ff, false), 37 HOWTO (R_W65_ABS16S8, 1, 0, 16, false, 0, complain_overflow_bitfield, 0, ">abs16", true, 0x0000ffff, 0x0000ffff, false), 38 HOWTO (R_W65_ABS16S16,1, 0, 16, false, 0, complain_overflow_bitfield, 0, "^abs16", true, 0x0000ffff, 0x0000ffff, false), 39 HOWTO (R_W65_PCR8, 0, 0, 8, false, 0, complain_overflow_bitfield, 0, "pcrel8", true, 0x000000ff, 0x000000ff, true), 40 HOWTO (R_W65_PCR16, 1, 0, 16, false, 0, complain_overflow_bitfield, 0, "pcrel16", true, 0x0000ffff, 0x0000ffff, true), 41 HOWTO (R_W65_DP, 0, 0, 8, false, 0, complain_overflow_bitfield, 0, "dp", true, 0x000000ff, 0x000000ff, false), 42 43 }; 44 45 /* Turn a howto into a reloc number */ 38 { 39 HOWTO (R_W65_ABS8, 0, 0, 8, FALSE, 0, complain_overflow_bitfield, 0, "abs8", TRUE, 0x000000ff, 0x000000ff, FALSE), 40 HOWTO (R_W65_ABS16, 1, 0, 16, FALSE, 0, complain_overflow_bitfield, 0, "abs16", TRUE, 0x0000ffff, 0x0000ffff, FALSE), 41 HOWTO (R_W65_ABS24, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, 0, "abs24", TRUE, 0x00ffffff, 0x00ffffff, FALSE), 42 HOWTO (R_W65_ABS8S8, 0, 0, 8, FALSE, 0, complain_overflow_bitfield, 0, ">abs8", TRUE, 0x000000ff, 0x000000ff, FALSE), 43 HOWTO (R_W65_ABS8S16, 0, 0, 8, FALSE, 0, complain_overflow_bitfield, 0, "^abs8", TRUE, 0x000000ff, 0x000000ff, FALSE), 44 HOWTO (R_W65_ABS16S8, 1, 0, 16, FALSE, 0, complain_overflow_bitfield, 0, ">abs16", TRUE, 0x0000ffff, 0x0000ffff, FALSE), 45 HOWTO (R_W65_ABS16S16,1, 0, 16, FALSE, 0, complain_overflow_bitfield, 0, "^abs16", TRUE, 0x0000ffff, 0x0000ffff, FALSE), 46 HOWTO (R_W65_PCR8, 0, 0, 8, FALSE, 0, complain_overflow_bitfield, 0, "pcrel8", TRUE, 0x000000ff, 0x000000ff, TRUE), 47 HOWTO (R_W65_PCR16, 1, 0, 16, FALSE, 0, complain_overflow_bitfield, 0, "pcrel16", TRUE, 0x0000ffff, 0x0000ffff, TRUE), 48 HOWTO (R_W65_DP, 0, 0, 8, FALSE, 0, complain_overflow_bitfield, 0, "dp", TRUE, 0x000000ff, 0x000000ff, FALSE), 49 }; 50 51 /* Turn a howto into a reloc number. */ 46 52 47 53 #define SELECT_RELOC(x,howto) \ … … 53 59 54 60 /* Code to swap in the reloc */ 55 #define SWAP_IN_RELOC_OFFSET bfd_h_get_3256 #define SWAP_OUT_RELOC_OFFSET bfd_h_put_3261 #define SWAP_IN_RELOC_OFFSET H_GET_32 62 #define SWAP_OUT_RELOC_OFFSET H_PUT_32 57 63 #define SWAP_OUT_RELOC_EXTRA(abfd, src, dst) \ 58 64 dst->r_stuff[0] = 'S'; \ … … 66 72 } 67 73 68 /* Code to turn a r_type into a howto ptr, uses the above howto table 69 */ 74 /* Code to turn a r_type into a howto ptr, uses the above howto table. */ 70 75 71 76 static void … … 74 79 struct internal_reloc *dst; 75 80 { 76 81 internal->howto = howto_table + dst->r_type - 1; 77 82 } 78 83 79 84 #define RTYPE2HOWTO(internal, relocentry) rtype2howto(internal,relocentry) 80 85 81 /* Perform any necessary magic to the addend in a reloc entry */86 /* Perform any necessary magic to the addend in a reloc entry. */ 82 87 83 88 #define CALC_ADDEND(abfd, symbol, ext_reloc, cache_ptr) \ … … 99 104 100 105 if (((int) reloc->r_symndx) > 0) 101 { 102 relent->sym_ptr_ptr = symbols + obj_convert (abfd)[reloc->r_symndx]; 103 } 106 relent->sym_ptr_ptr = symbols + obj_convert (abfd)[reloc->r_symndx]; 104 107 else 105 { 106 relent->sym_ptr_ptr = (asymbol **)&(bfd_abs_symbol); 107 } 108 relent->sym_ptr_ptr = (asymbol **)&(bfd_abs_symbol); 108 109 109 110 relent->addend = reloc->r_offset; … … 114 115 115 116 static int 116 h8300_reloc16_estimate(abfd, input_section, reloc, shrink, link_info)117 w65_reloc16_estimate (abfd, input_section, reloc, shrink, link_info) 117 118 bfd *abfd; 118 119 asection *input_section; … … 128 129 the size of the shrink - but we don't change reloc->address here, 129 130 since we need it to know where the relocation lives in the source 130 uncooked section */131 uncooked section. */ 131 132 132 133 /* reloc->address -= shrink; conceptual */ … … 141 142 break; 142 143 143 /* Thing is a move one byte */144 /* Thing is a move one byte. */ 144 145 case R_MOV16B1: 145 value = bfd_coff_reloc16_get_value (reloc, link_info, input_section);146 value = bfd_coff_reloc16_get_value (reloc, link_info, input_section); 146 147 147 148 if (value >= 0xff00) 148 149 { 149 150 150 /* Change the reloc type from 16bit, possible 8 to 8bit 151 possible 16 */151 possible 16. */ 152 152 reloc->howto = reloc->howto + 1; 153 /* The place to relc moves back by one */154 /* This will be two bytes smaller in the long run */155 shrink += 2;156 bfd_perform_slip (abfd, 2, input_section, address);153 /* The place to relc moves back by one. */ 154 /* This will be two bytes smaller in the long run. */ 155 shrink += 2; 156 bfd_perform_slip (abfd, 2, input_section, address); 157 157 } 158 158 159 159 break; 160 160 /* This is the 24 bit branch which could become an 8 bitter, 161 162 actual data*/161 the relocation points to the first byte of the insn, not the 162 actual data. */ 163 163 164 164 case R_JMPL1: 165 value = bfd_coff_reloc16_get_value (reloc, link_info, input_section);165 value = bfd_coff_reloc16_get_value (reloc, link_info, input_section); 166 166 167 167 dot = input_section->output_section->vma + … … 170 170 /* See if the address we're looking at within 127 bytes of where 171 171 we are, if so then we can use a small branch rather than the 172 jump we were going to */ 173 174 gap = value - dot ; 175 176 if (-120 < (long)gap && (long)gap < 120 ) 172 jump we were going to. */ 173 gap = value - dot; 174 175 if (-120 < (long) gap && (long) gap < 120) 177 176 { 178 179 177 /* Change the reloc type from 24bit, possible 8 to 8bit 180 possible 32 */178 possible 32. */ 181 179 reloc->howto = reloc->howto + 1; 182 /* This will be two bytes smaller in the long run */183 shrink += 2;184 bfd_perform_slip (abfd, 2, input_section, address);180 /* This will be two bytes smaller in the long run. */ 181 shrink += 2; 182 bfd_perform_slip (abfd, 2, input_section, address); 185 183 } 186 184 break; 187 185 188 186 case R_JMP1: 189 190 value = bfd_coff_reloc16_get_value(reloc, link_info, input_section); 187 value = bfd_coff_reloc16_get_value (reloc, link_info, input_section); 191 188 192 189 dot = input_section->output_section->vma + … … 195 192 /* See if the address we're looking at within 127 bytes of where 196 193 we are, if so then we can use a small branch rather than the 197 jump we were going to */ 198 194 jump we were going to. */ 199 195 gap = value - (dot - shrink); 200 196 201 if (-120 < (long) gap && (long)gap < 120)197 if (-120 < (long) gap && (long) gap < 120) 202 198 { 203 204 199 /* Change the reloc type from 16bit, possible 8 to 8bit 205 possible 16 */200 possible 16. */ 206 201 reloc->howto = reloc->howto + 1; 207 /* The place to relc moves back by one */208 209 /* This will be two bytes smaller in the long run */210 shrink += 2;211 bfd_perform_slip (abfd, 2, input_section, address);202 /* The place to relc moves back by one. */ 203 204 /* This will be two bytes smaller in the long run. */ 205 shrink += 2; 206 bfd_perform_slip (abfd, 2, input_section, address); 212 207 } 213 208 break; … … 217 212 } 218 213 219 /* First phase of a relaxing link */214 /* First phase of a relaxing link. */ 220 215 221 216 /* Reloc types … … 224 219 R_JMP1 R_JMP2 jmp or pcrel branch 225 220 R_JMPL1 R_JMPL_B8 24jmp or pcrel branch 226 R_MOV24B1 R_MOV24B2 24 or 8 bit reloc for mov.b 227 228 */ 221 R_MOV24B1 R_MOV24B2 24 or 8 bit reloc for mov.b */ 229 222 230 223 static void 231 h8300_reloc16_extra_cases (abfd, link_info, link_order, reloc, data, src_ptr,224 w65_reloc16_extra_cases (abfd, link_info, link_order, reloc, data, src_ptr, 232 225 dst_ptr) 233 226 bfd *abfd; … … 271 264 unsigned int gap = bfd_coff_reloc16_get_value (reloc, link_info, 272 265 input_section); 273 gap >>= 16;266 gap >>= 16; 274 267 bfd_put_8 (abfd, gap, data + dst_address); 275 268 dst_address += 1; … … 283 276 input_section); 284 277 285 bfd_put_16 (abfd, gap, data + dst_address);278 bfd_put_16 (abfd, (bfd_vma) gap, data + dst_address); 286 279 dst_address += 2; 287 280 src_address += 2; … … 293 286 input_section); 294 287 gap >>= 8; 295 bfd_put_16 (abfd, gap, data + dst_address);288 bfd_put_16 (abfd, (bfd_vma) gap, data + dst_address); 296 289 dst_address += 2; 297 290 src_address += 2; … … 303 296 input_section); 304 297 gap >>= 16; 305 bfd_put_16 (abfd, gap, data + dst_address);298 bfd_put_16 (abfd, (bfd_vma) gap, data + dst_address); 306 299 dst_address += 2; 307 300 src_address += 2; … … 313 306 unsigned int gap = bfd_coff_reloc16_get_value (reloc, link_info, 314 307 input_section); 315 bfd_put_16 (abfd, gap, data + dst_address);316 bfd_put_8 (abfd, gap >>16, data+dst_address+2);308 bfd_put_16 (abfd, (bfd_vma) gap, data + dst_address); 309 bfd_put_8 (abfd, gap >> 16, data+dst_address + 2); 317 310 dst_address += 3; 318 311 src_address += 3; … … 329 322 330 323 gap -= dot + 1; 331 if (gap < -128 || gap > 127) { 332 if (! ((*link_info->callbacks->reloc_overflow) 333 (link_info, bfd_asymbol_name (*reloc->sym_ptr_ptr), 334 reloc->howto->name, reloc->addend, input_section->owner, 335 input_section, reloc->address))) 336 abort (); 337 } 324 if (gap < -128 || gap > 127) 325 { 326 if (! ((*link_info->callbacks->reloc_overflow) 327 (link_info, bfd_asymbol_name (*reloc->sym_ptr_ptr), 328 reloc->howto->name, reloc->addend, input_section->owner, 329 input_section, reloc->address))) 330 abort (); 331 } 338 332 bfd_put_8 (abfd, gap, data + dst_address); 339 333 dst_address += 1; … … 351 345 352 346 /* This wraps within the page, so ignore the relativeness, look at the 353 high part */ 354 if ((gap & 0xf0000) != (dot & 0xf0000)) { 355 if (! ((*link_info->callbacks->reloc_overflow) 356 (link_info, bfd_asymbol_name (*reloc->sym_ptr_ptr), 357 reloc->howto->name, reloc->addend, input_section->owner, 358 input_section, reloc->address))) 359 abort (); 360 } 347 high part. */ 348 if ((gap & 0xf0000) != (dot & 0xf0000)) 349 { 350 if (! ((*link_info->callbacks->reloc_overflow) 351 (link_info, bfd_asymbol_name (*reloc->sym_ptr_ptr), 352 reloc->howto->name, reloc->addend, input_section->owner, 353 input_section, reloc->address))) 354 abort (); 355 } 361 356 362 357 gap -= dot + 2; … … 373 368 *src_ptr = src_address; 374 369 *dst_ptr = dst_address; 375 376 } 377 378 #define coff_reloc16_extra_cases h8300_reloc16_extra_cases 379 #define coff_reloc16_estimate h8300_reloc16_estimate 370 } 371 372 #define coff_reloc16_extra_cases w65_reloc16_extra_cases 373 #define coff_reloc16_estimate w65_reloc16_estimate 380 374 381 375 #include "coffcode.h" -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.