Changeset 609 for branches/GNU/src/binutils/bfd/mipsbsd.c
- Timestamp:
- Aug 16, 2003, 6:59:22 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GNU/src/binutils/bfd/mipsbsd.c
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.1.1.2
r608 r609 1 1 /* BFD backend for MIPS BSD (a.out) binaries. 2 Copyright 1993, 1994, 1995, 1997, 1998, 1999, 2000 2 Copyright 1993, 1994, 1995, 1997, 1998, 1999, 2000, 2001, 2002, 2003 3 3 Free Software Foundation, Inc. 4 4 Written by Ralph Campbell. … … 20 20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 21 21 22 #define BYTES_IN_WORD 423 22 /* #define ENTRY_CAN_BE_ZERO */ 24 23 #define N_HEADER_IN_TEXT(x) 1 … … 37 36 #define MY_symbol_leading_char '\0' 38 37 39 #define MY(OP) CAT(mipsbsd_,OP) 38 /* Do not "beautify" the CONCAT* macro args. Traditional C will not 39 remove whitespace added here, and thus will fail to concatenate 40 the tokens. */ 41 #define MY(OP) CONCAT2 (mipsbsd_,OP) 40 42 41 43 #include "bfd.h" … … 47 49 MY(set_arch_mach) (ABFD, N_MACHTYPE (EXEC)); \ 48 50 MY(choose_reloc_size) (ABFD); 49 static void MY(set_arch_mach) PARAMS ((bfd *abfd, intmachtype));51 static void MY(set_arch_mach) PARAMS ((bfd *abfd, unsigned long machtype)); 50 52 static void MY(choose_reloc_size) PARAMS ((bfd *abfd)); 51 53 52 54 #define MY_write_object_contents MY(write_object_contents) 53 static b oolean MY(write_object_contents) PARAMS ((bfd *abfd));54 55 /* We can't use MY(x) here because it leads to a recursive call to C AT55 static bfd_boolean MY(write_object_contents) PARAMS ((bfd *abfd)); 56 57 /* We can't use MY(x) here because it leads to a recursive call to CONCAT2 56 58 when expanded inside JUMP_TABLE. */ 57 59 #define MY_bfd_reloc_type_lookup mipsbsd_reloc_howto_type_lookup … … 68 70 #include "aout-target.h" 69 71 72 static bfd_reloc_status_type mips_fix_jmp_addr 73 PARAMS ((bfd *, arelent *, struct symbol_cache_entry *, PTR, asection *, 74 bfd *, char **)); 75 static reloc_howto_type *MY(reloc_howto_type_lookup) 76 PARAMS ((bfd *, bfd_reloc_code_real_type)); 77 78 long MY(canonicalize_reloc) PARAMS ((bfd *, sec_ptr, arelent **, asymbol **)); 79 70 80 static void 71 81 MY(set_arch_mach) (abfd, machtype) 72 82 bfd *abfd; 73 intmachtype;83 unsigned long machtype; 74 84 { 75 85 enum bfd_architecture arch; 76 longmachine;86 unsigned int machine; 77 87 78 88 /* Determine the architecture and machine type of the object file. */ 79 switch (machtype) { 80 81 case M_MIPS1: 82 arch = bfd_arch_mips; 83 machine = 3000; 84 break; 85 86 case M_MIPS2: 87 arch = bfd_arch_mips; 88 machine = 4000; 89 break; 90 91 default: 92 arch = bfd_arch_obscure; 93 machine = 0; 94 break; 95 } 96 bfd_set_arch_mach(abfd, arch, machine); 89 switch (machtype) 90 { 91 case M_MIPS1: 92 arch = bfd_arch_mips; 93 machine = bfd_mach_mips3000; 94 break; 95 96 case M_MIPS2: 97 arch = bfd_arch_mips; 98 machine = bfd_mach_mips4000; 99 break; 100 101 default: 102 arch = bfd_arch_obscure; 103 machine = 0; 104 break; 105 } 106 107 bfd_set_arch_mach (abfd, arch, machine); 97 108 } 98 109 99 110 /* Determine the size of a relocation entry, based on the architecture */ 100 111 static void 101 MY (choose_reloc_size) (abfd)112 MY (choose_reloc_size) (abfd) 102 113 bfd *abfd; 103 114 { 104 switch (bfd_get_arch(abfd)) { 105 case bfd_arch_sparc: 106 case bfd_arch_a29k: 107 case bfd_arch_mips: 108 obj_reloc_entry_size (abfd) = RELOC_EXT_SIZE; 109 break; 110 default: 111 obj_reloc_entry_size (abfd) = RELOC_STD_SIZE; 112 break; 113 } 115 switch (bfd_get_arch (abfd)) 116 { 117 case bfd_arch_sparc: 118 case bfd_arch_a29k: 119 case bfd_arch_mips: 120 obj_reloc_entry_size (abfd) = RELOC_EXT_SIZE; 121 break; 122 default: 123 obj_reloc_entry_size (abfd) = RELOC_STD_SIZE; 124 break; 125 } 114 126 } 115 127 … … 118 130 file header, symbols, and relocation. */ 119 131 120 static b oolean121 MY (write_object_contents) (abfd)132 static bfd_boolean 133 MY (write_object_contents) (abfd) 122 134 bfd *abfd; 123 135 { … … 126 138 127 139 /* Magic number, maestro, please! */ 128 switch (bfd_get_arch(abfd)) { 129 case bfd_arch_m68k: 130 switch (bfd_get_mach(abfd)) { 131 case bfd_mach_m68010: 132 N_SET_MACHTYPE(*execp, M_68010); 140 switch (bfd_get_arch (abfd)) 141 { 142 case bfd_arch_m68k: 143 switch (bfd_get_mach (abfd)) 144 { 145 case bfd_mach_m68010: 146 N_SET_MACHTYPE (*execp, M_68010); 147 break; 148 default: 149 case bfd_mach_m68020: 150 N_SET_MACHTYPE (*execp, M_68020); 151 break; 152 } 153 break; 154 case bfd_arch_sparc: 155 N_SET_MACHTYPE (*execp, M_SPARC); 156 break; 157 case bfd_arch_i386: 158 N_SET_MACHTYPE (*execp, M_386); 159 break; 160 case bfd_arch_a29k: 161 N_SET_MACHTYPE (*execp, M_29K); 162 break; 163 case bfd_arch_mips: 164 switch (bfd_get_mach (abfd)) 165 { 166 case bfd_mach_mips4000: 167 case bfd_mach_mips6000: 168 N_SET_MACHTYPE (*execp, M_MIPS2); 169 break; 170 default: 171 N_SET_MACHTYPE (*execp, M_MIPS1); 172 break; 173 } 133 174 break; 134 175 default: 135 case bfd_mach_m68020: 136 N_SET_MACHTYPE(*execp, M_68020); 137 break; 138 } 139 break; 140 case bfd_arch_sparc: 141 N_SET_MACHTYPE(*execp, M_SPARC); 142 break; 143 case bfd_arch_i386: 144 N_SET_MACHTYPE(*execp, M_386); 145 break; 146 case bfd_arch_a29k: 147 N_SET_MACHTYPE(*execp, M_29K); 148 break; 149 case bfd_arch_mips: 150 switch (bfd_get_mach(abfd)) { 151 case 4000: 152 case 6000: 153 N_SET_MACHTYPE(*execp, M_MIPS2); 154 break; 155 default: 156 N_SET_MACHTYPE(*execp, M_MIPS1); 157 break; 158 } 159 break; 160 default: 161 N_SET_MACHTYPE(*execp, M_UNKNOWN); 162 } 163 164 MY(choose_reloc_size) (abfd); 165 166 WRITE_HEADERS(abfd, execp); 167 168 return true; 169 } 170 171 /* 172 * MIPS relocation types. 173 */ 176 N_SET_MACHTYPE (*execp, M_UNKNOWN); 177 } 178 179 MY (choose_reloc_size) (abfd); 180 181 WRITE_HEADERS (abfd, execp); 182 183 return TRUE; 184 } 185 186 /* MIPS relocation types. */ 174 187 #define MIPS_RELOC_32 0 175 188 #define MIPS_RELOC_JMP 1 … … 179 192 #define MIPS_RELOC_LO16 5 180 193 181 /* 182 * This is only called when performing a BFD_RELOC_MIPS_JMP relocation. 183 * The jump destination address is formed from the upper 4 bits of the 184 * "current" program counter concatenated with the jump instruction's 185 * 26 bit field and two trailing zeros. 186 * If the destination address is not in the same segment as the "current" 187 * program counter, then we need to signal an error. 188 */ 194 /* This is only called when performing a BFD_RELOC_MIPS_JMP relocation. 195 The jump destination address is formed from the upper 4 bits of the 196 "current" program counter concatenated with the jump instruction's 197 26 bit field and two trailing zeros. 198 If the destination address is not in the same segment as the "current" 199 program counter, then we need to signal an error. */ 200 189 201 static bfd_reloc_status_type 190 mips_fix_jmp_addr (abfd,reloc_entry,symbol,data,input_section,output_bfd) 202 mips_fix_jmp_addr (abfd, reloc_entry, symbol, data, input_section, output_bfd, 203 error_message) 191 204 bfd *abfd ATTRIBUTE_UNUSED; 192 205 arelent *reloc_entry; … … 195 208 asection *input_section; 196 209 bfd *output_bfd; 210 char **error_message ATTRIBUTE_UNUSED; 197 211 { 198 212 bfd_vma relocation, pc; … … 207 221 return bfd_reloc_undefined; 208 222 209 /* 210 * Work out which section the relocation is targetted at and the 211 * initial relocation command value. 212 */ 223 /* Work out which section the relocation is targetted at and the 224 initial relocation command value. */ 213 225 if (bfd_is_com_section (symbol->section)) 214 226 relocation = 0; … … 229 241 } 230 242 231 /* 232 * This is only called when performing a BFD_RELOC_HI16_S relocation. 233 * We need to see if bit 15 is set in the result. If it is, we add 234 * 0x10000 and continue normally. This will compensate for the sign extension 235 * when the low bits are added at run time. 236 */ 243 /* This is only called when performing a BFD_RELOC_HI16_S relocation. 244 We need to see if bit 15 is set in the result. If it is, we add 245 0x10000 and continue normally. This will compensate for the sign extension 246 when the low bits are added at run time. */ 247 237 248 static bfd_reloc_status_type 238 249 mips_fix_hi16_s PARAMS ((bfd *, arelent *, asymbol *, PTR, … … 256 267 return bfd_reloc_continue; 257 268 258 /* If this is an undefined symbol, return error */269 /* If this is an undefined symbol, return error. */ 259 270 if (bfd_is_und_section (symbol->section) 260 271 && (symbol->flags & BSF_WEAK) == 0) 261 272 return bfd_reloc_undefined; 262 273 263 /* 264 * Work out which section the relocation is targetted at and the 265 * initial relocation command value. 266 */ 274 /* Work out which section the relocation is targetted at and the 275 initial relocation command value. */ 267 276 if (bfd_is_com_section (symbol->section)) 268 277 relocation = 0; … … 281 290 282 291 static reloc_howto_type mips_howto_table_ext[] = { 283 {MIPS_RELOC_32, 0, 2, 32, false, 0, complain_overflow_bitfield, 0,284 "32", false, 0, 0xffffffff, false},285 {MIPS_RELOC_JMP, 2, 2, 26, false, 0, complain_overflow_dont,292 {MIPS_RELOC_32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, 0, 293 "32", FALSE, 0, 0xffffffff, FALSE}, 294 {MIPS_RELOC_JMP, 2, 2, 26, FALSE, 0, complain_overflow_dont, 286 295 mips_fix_jmp_addr, 287 "MIPS_JMP", false, 0, 0x03ffffff, false},288 {MIPS_RELOC_WDISP16, 2, 2, 16, true, 0, complain_overflow_signed, 0,289 "WDISP16", false, 0, 0x0000ffff, false},290 {MIPS_RELOC_HI16, 16, 2, 16, false, 0, complain_overflow_bitfield, 0,291 "HI16", false, 0, 0x0000ffff, false},292 {MIPS_RELOC_HI16_S, 16, 2, 16, false, 0, complain_overflow_bitfield,296 "MIPS_JMP", FALSE, 0, 0x03ffffff, FALSE}, 297 {MIPS_RELOC_WDISP16, 2, 2, 16, TRUE, 0, complain_overflow_signed, 0, 298 "WDISP16", FALSE, 0, 0x0000ffff, FALSE}, 299 {MIPS_RELOC_HI16, 16, 2, 16, FALSE, 0, complain_overflow_bitfield, 0, 300 "HI16", FALSE, 0, 0x0000ffff, FALSE}, 301 {MIPS_RELOC_HI16_S, 16, 2, 16, FALSE, 0, complain_overflow_bitfield, 293 302 mips_fix_hi16_s, 294 "HI16_S", false, 0, 0x0000ffff, false},295 {MIPS_RELOC_LO16, 0, 2, 16, false, 0, complain_overflow_dont, 0,296 "LO16", false, 0, 0x0000ffff, false},303 "HI16_S", FALSE, 0, 0x0000ffff, FALSE}, 304 {MIPS_RELOC_LO16, 0, 2, 16, FALSE, 0, complain_overflow_dont, 0, 305 "LO16", FALSE, 0, 0x0000ffff, FALSE}, 297 306 }; 298 307 … … 326 335 } 327 336 328 /* 329 * This is just like the standard aoutx.h version but we need to do our 330 * own mapping of external reloc type values to howto entries. 331 */ 337 /* This is just like the standard aoutx.h version but we need to do our 338 own mapping of external reloc type values to howto entries. */ 332 339 long 333 340 MY(canonicalize_reloc) (abfd, section, relptr, symbols) … … 342 349 343 350 /* If we have already read in the relocation table, return the values. */ 344 if (section->flags & SEC_CONSTRUCTOR) { 345 arelent_chain *chain = section->constructor_chain; 346 347 for (count = 0; count < section->reloc_count; count++) { 348 *relptr++ = &chain->relent; 349 chain = chain->next; 350 } 351 *relptr = 0; 352 return section->reloc_count; 353 } 354 if (tblptr && section->reloc_count) { 355 for (count = 0; count++ < section->reloc_count;) 356 *relptr++ = tblptr++; 357 *relptr = 0; 358 return section->reloc_count; 359 } 351 if (section->flags & SEC_CONSTRUCTOR) 352 { 353 arelent_chain *chain = section->constructor_chain; 354 355 for (count = 0; count < section->reloc_count; count++) 356 { 357 *relptr++ = &chain->relent; 358 chain = chain->next; 359 } 360 *relptr = 0; 361 return section->reloc_count; 362 } 363 364 if (tblptr && section->reloc_count) 365 { 366 for (count = 0; count++ < section->reloc_count;) 367 *relptr++ = tblptr++; 368 *relptr = 0; 369 return section->reloc_count; 370 } 360 371 361 372 if (!NAME(aout,slurp_reloc_table) (abfd, section, symbols)) … … 363 374 tblptr = section->relocation; 364 375 365 /* fix up howto entries */376 /* fix up howto entries. */ 366 377 for (count = 0; count++ < section->reloc_count;) 367 378 { … … 375 386 } 376 387 377 static CONSTstruct aout_backend_data MY(backend_data) = {388 static const struct aout_backend_data MY(backend_data) = { 378 389 0, /* zmagic contiguous */ 379 390 1, /* text incl header */ … … 394 405 395 406 const bfd_target aout_mips_little_vec = 396 {397 "a.out-mips-little", /* name */398 bfd_target_aout_flavour,399 BFD_ENDIAN_LITTLE, /* target byte order (little) */400 BFD_ENDIAN_LITTLE, /* target headers byte order (little) */401 (HAS_RELOC | EXEC_P | /* object flags */402 HAS_LINENO | HAS_DEBUG |403 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),404 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_CODE | SEC_DATA),405 MY_symbol_leading_char,406 ' ', /* ar_pad_char */407 15, /* ar_max_namelen */408 bfd_getl64, bfd_getl_signed_64, bfd_putl64,409 410 411 bfd_getl64, bfd_getl_signed_64, bfd_putl64,412 413 407 { 408 "a.out-mips-little", /* name */ 409 bfd_target_aout_flavour, 410 BFD_ENDIAN_LITTLE, /* target byte order (little) */ 411 BFD_ENDIAN_LITTLE, /* target headers byte order (little) */ 412 (HAS_RELOC | EXEC_P | /* object flags */ 413 HAS_LINENO | HAS_DEBUG | 414 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED), 415 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_CODE | SEC_DATA), 416 MY_symbol_leading_char, 417 ' ', /* ar_pad_char */ 418 15, /* ar_max_namelen */ 419 bfd_getl64, bfd_getl_signed_64, bfd_putl64, 420 bfd_getl32, bfd_getl_signed_32, bfd_putl32, 421 bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */ 422 bfd_getl64, bfd_getl_signed_64, bfd_putl64, 423 bfd_getl32, bfd_getl_signed_32, bfd_putl32, 424 bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */ 414 425 {_bfd_dummy_target, MY_object_p, /* bfd_check_format */ 415 426 bfd_generic_archive_p, MY_core_file_p}, 416 427 {bfd_false, MY_mkobject, /* bfd_set_format */ 417 428 _bfd_generic_mkarchive, bfd_false}, 418 429 {bfd_false, MY_write_object_contents, /* bfd_write_contents */ 419 420 421 422 423 424 425 426 427 428 429 430 431 & aout_mips_big_vec,432 433 (PTR) MY_backend_data434 };430 _bfd_write_archive_contents, bfd_false}, 431 432 BFD_JUMP_TABLE_GENERIC (MY), 433 BFD_JUMP_TABLE_COPY (MY), 434 BFD_JUMP_TABLE_CORE (MY), 435 BFD_JUMP_TABLE_ARCHIVE (MY), 436 BFD_JUMP_TABLE_SYMBOLS (MY), 437 BFD_JUMP_TABLE_RELOCS (MY), 438 BFD_JUMP_TABLE_WRITE (MY), 439 BFD_JUMP_TABLE_LINK (MY), 440 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), 441 442 & aout_mips_big_vec, 443 444 (PTR) MY_backend_data 445 }; 435 446 436 447 const bfd_target aout_mips_big_vec = 437 {438 "a.out-mips-big", /* name */439 bfd_target_aout_flavour,440 BFD_ENDIAN_BIG, /* target byte order (big) */441 BFD_ENDIAN_BIG, /* target headers byte order (big) */442 (HAS_RELOC | EXEC_P | /* object flags */443 HAS_LINENO | HAS_DEBUG |444 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),445 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_CODE | SEC_DATA),446 MY_symbol_leading_char,447 ' ', /* ar_pad_char */448 15, /* ar_max_namelen */449 bfd_getb64, bfd_getb_signed_64, bfd_putb64,450 451 452 bfd_getb64, bfd_getb_signed_64, bfd_putb64,453 454 448 { 449 "a.out-mips-big", /* name */ 450 bfd_target_aout_flavour, 451 BFD_ENDIAN_BIG, /* target byte order (big) */ 452 BFD_ENDIAN_BIG, /* target headers byte order (big) */ 453 (HAS_RELOC | EXEC_P | /* object flags */ 454 HAS_LINENO | HAS_DEBUG | 455 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED), 456 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_CODE | SEC_DATA), 457 MY_symbol_leading_char, 458 ' ', /* ar_pad_char */ 459 15, /* ar_max_namelen */ 460 bfd_getb64, bfd_getb_signed_64, bfd_putb64, 461 bfd_getb32, bfd_getb_signed_32, bfd_putb32, 462 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */ 463 bfd_getb64, bfd_getb_signed_64, bfd_putb64, 464 bfd_getb32, bfd_getb_signed_32, bfd_putb32, 465 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */ 455 466 {_bfd_dummy_target, MY_object_p, /* bfd_check_format */ 456 467 bfd_generic_archive_p, MY_core_file_p}, 457 468 {bfd_false, MY_mkobject, /* bfd_set_format */ 458 469 _bfd_generic_mkarchive, bfd_false}, 459 470 {bfd_false, MY_write_object_contents, /* bfd_write_contents */ 460 461 462 463 464 465 466 467 468 469 470 471 472 & aout_mips_little_vec,473 474 (PTR) MY_backend_data475 };471 _bfd_write_archive_contents, bfd_false}, 472 473 BFD_JUMP_TABLE_GENERIC (MY), 474 BFD_JUMP_TABLE_COPY (MY), 475 BFD_JUMP_TABLE_CORE (MY), 476 BFD_JUMP_TABLE_ARCHIVE (MY), 477 BFD_JUMP_TABLE_SYMBOLS (MY), 478 BFD_JUMP_TABLE_RELOCS (MY), 479 BFD_JUMP_TABLE_WRITE (MY), 480 BFD_JUMP_TABLE_LINK (MY), 481 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), 482 483 & aout_mips_little_vec, 484 485 (PTR) MY_backend_data 486 }; -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.