Changeset 618 for trunk/src/binutils/gas
- Timestamp:
- Aug 16, 2003, 11:33:53 PM (22 years ago)
- Location:
- trunk/src/binutils/gas
- Files:
-
- 16 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/binutils/gas/as.c
-
Property cvs2svn:cvs-rev
changed from
1.2
to1.3
r617 r618 1 1 /* as.c - GAS main program. 2 2 Copyright 1987, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 3 1999, 2000, 2001 3 1999, 2000, 2001, 2002 4 4 Free Software Foundation, Inc. 5 5 … … 44 44 #include "dwarf2dbg.h" 45 45 46 #ifdef BFD_ASSEMBLER 47 #include "bfdver.h" 48 #endif 49 46 50 #ifdef HAVE_ITBL_CPU 47 51 #include "itbl-ops.h" … … 62 66 static void perform_an_assembly_pass PARAMS ((int argc, char **argv)); 63 67 static int macro_expr PARAMS ((const char *, int, sb *, int *)); 68 #ifdef USING_CGEN 69 /* Perform any cgen specific initialisation for gas. */ 70 extern void gas_cgen_begin PARAMS ((void)); 71 #endif 64 72 65 73 /* True if a listing is wanted. */ … … 217 225 #ifdef BFD_ASSEMBLER 218 226 fprintf (stderr, _("GNU assembler version %s (%s) using BFD version %s"), 219 VERSION, TARGET_ALIAS, BFD_VERSION );227 VERSION, TARGET_ALIAS, BFD_VERSION_STRING); 220 228 #else 221 229 fprintf (stderr, _("GNU assembler version %s (%s)"), VERSION, TARGET_ALIAS); … … 359 367 360 368 char *shortopts; 361 extern CONSTchar *md_shortopts;369 extern const char *md_shortopts; 362 370 static const char std_shortopts[] = { 363 371 '-', 'J', … … 383 391 #define OPTION_HELP (OPTION_STD_BASE) 384 392 {"help", no_argument, NULL, OPTION_HELP}, 393 /* getopt allows abbreviations, so we do this to stop it from 394 treating -k as an abbreviation for --keep-locals. Some 395 ports use -k to enable PIC assembly. */ 396 {"keep-locals", no_argument, NULL, 'L'}, 385 397 {"keep-locals", no_argument, NULL, 'L'}, 386 398 {"mri", no_argument, NULL, 'M'}, … … 509 521 510 522 case OPTION_TARGET_HELP: 511 512 523 md_show_usage (stdout); 524 exit (EXIT_SUCCESS); 513 525 514 526 case OPTION_HELP: … … 533 545 case OPTION_VERSION: 534 546 /* This output is intended to follow the GNU standards document. */ 547 #ifdef BFD_ASSEMBLER 548 printf (_("GNU assembler %s\n"), BFD_VERSION_STRING); 549 #else 535 550 printf (_("GNU assembler %s\n"), VERSION); 536 printf (_("Copyright 2001 Free Software Foundation, Inc.\n")); 551 #endif 552 printf (_("Copyright 2002 Free Software Foundation, Inc.\n")); 537 553 printf (_("\ 538 554 This program is free software; you may redistribute it under the terms of\n\ … … 596 612 if (optarg == NULL) 597 613 { 598 as_warn (_(" No file name following -t option\n"));614 as_warn (_("no file name following -t option")); 599 615 break; 600 616 } … … 611 627 itbl_files->name = xstrdup (optarg); 612 628 if (itbl_parse (itbl_files->name) != 0) 613 { 614 fprintf (stderr, _("Failed to read instruction table %s\n"), 615 itbl_files->name); 616 exit (EXIT_SUCCESS); 617 } 629 as_fatal (_("failed to read instruction table %s\n"), 630 itbl_files->name); 618 631 } 619 632 break; … … 774 787 *pargc = new_argc; 775 788 *pargv = new_argv; 789 790 #ifdef md_after_parse_args 791 md_after_parse_args (); 792 #endif 776 793 } 777 794 778 795 static long start_time; 796 797 int main PARAMS ((int, char **)); 779 798 780 799 int … … 799 818 setlocale (LC_MESSAGES, ""); 800 819 #endif 820 #if defined (HAVE_SETLOCALE) 821 setlocale (LC_CTYPE, ""); 822 #endif 801 823 bindtextdomain (PACKAGE, LOCALEDIR); 802 824 textdomain (PACKAGE); 803 825 804 826 if (debug_memory) 805 { 806 #ifdef BFD_ASSEMBLER 807 extern long _bfd_chunksize; 808 _bfd_chunksize = 64; 809 #endif 810 chunksize = 64; 811 } 827 chunksize = 64; 812 828 813 829 #ifdef HOST_SPECIAL_INIT … … 1119 1135 md_begin (); 1120 1136 1137 #ifdef USING_CGEN 1138 gas_cgen_begin (); 1139 #endif 1121 1140 #ifdef obj_begin 1122 1141 obj_begin (); -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/binutils/gas/config/tc-i386.c
-
Property cvs2svn:cvs-rev
changed from
1.2
to1.3
r617 r618 1 1 /* i386.c -- Assemble code for the Intel 80386 2 2 Copyright 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 3 2000, 2001 3 2000, 2001, 2002, 2003 4 4 Free Software Foundation, Inc. 5 5 … … 27 27 Please help us make it better. */ 28 28 29 #include <ctype.h>30 31 29 #include "as.h" 30 #include "safe-ctype.h" 32 31 #include "subsegs.h" 33 32 #include "dwarf2dbg.h" … … 50 49 #endif 51 50 52 #define true 1 53 #define false 0 54 55 static unsigned int mode_from_disp_size PARAMS ((unsigned int)); 56 static int fits_in_signed_byte PARAMS ((offsetT)); 57 static int fits_in_unsigned_byte PARAMS ((offsetT)); 58 static int fits_in_unsigned_word PARAMS ((offsetT)); 59 static int fits_in_signed_word PARAMS ((offsetT)); 60 static int fits_in_unsigned_long PARAMS ((offsetT)); 61 static int fits_in_signed_long PARAMS ((offsetT)); 51 #ifdef BFD_ASSEMBLER 52 #define RELOC_ENUM enum bfd_reloc_code_real 53 #else 54 #define RELOC_ENUM int 55 #endif 56 57 #ifndef DEFAULT_ARCH 58 #define DEFAULT_ARCH "i386" 59 #endif 60 61 #ifndef INLINE 62 #if __GNUC__ >= 2 63 #define INLINE __inline__ 64 #else 65 #define INLINE 66 #endif 67 #endif 68 69 static INLINE unsigned int mode_from_disp_size PARAMS ((unsigned int)); 70 static INLINE int fits_in_signed_byte PARAMS ((offsetT)); 71 static INLINE int fits_in_unsigned_byte PARAMS ((offsetT)); 72 static INLINE int fits_in_unsigned_word PARAMS ((offsetT)); 73 static INLINE int fits_in_signed_word PARAMS ((offsetT)); 74 static INLINE int fits_in_unsigned_long PARAMS ((offsetT)); 75 static INLINE int fits_in_signed_long PARAMS ((offsetT)); 62 76 static int smallest_imm_type PARAMS ((offsetT)); 63 77 static offsetT offset_in_range PARAMS ((offsetT, int)); … … 67 81 static void set_intel_syntax PARAMS ((int)); 68 82 static void set_cpu_arch PARAMS ((int)); 69 70 #ifdef BFD_ASSEMBLER 71 static bfd_reloc_code_real_type reloc 72 PARAMS ((int, int, int, bfd_reloc_code_real_type)); 73 #define RELOC_ENUM enum bfd_reloc_code_real 74 #else 75 #define RELOC_ENUM int 76 #endif 77 78 #ifndef DEFAULT_ARCH 79 #define DEFAULT_ARCH "i386" 80 #endif 81 static char *default_arch = DEFAULT_ARCH; 83 static char *output_invalid PARAMS ((int c)); 84 static int i386_operand PARAMS ((char *operand_string)); 85 static int i386_intel_operand PARAMS ((char *operand_string, int got_a_float)); 86 static const reg_entry *parse_register PARAMS ((char *reg_string, 87 char **end_op)); 88 static char *parse_insn PARAMS ((char *, char *)); 89 static char *parse_operands PARAMS ((char *, const char *)); 90 static void swap_operands PARAMS ((void)); 91 static void optimize_imm PARAMS ((void)); 92 static void optimize_disp PARAMS ((void)); 93 static int match_template PARAMS ((void)); 94 static int check_string PARAMS ((void)); 95 static int process_suffix PARAMS ((void)); 96 static int check_byte_reg PARAMS ((void)); 97 static int check_long_reg PARAMS ((void)); 98 static int check_qword_reg PARAMS ((void)); 99 static int check_word_reg PARAMS ((void)); 100 static int finalize_imm PARAMS ((void)); 101 static int process_operands PARAMS ((void)); 102 static const seg_entry *build_modrm_byte PARAMS ((void)); 103 static void output_insn PARAMS ((void)); 104 static void output_branch PARAMS ((void)); 105 static void output_jump PARAMS ((void)); 106 static void output_interseg_jump PARAMS ((void)); 107 static void output_imm PARAMS ((fragS *insn_start_frag, 108 offsetT insn_start_off)); 109 static void output_disp PARAMS ((fragS *insn_start_frag, 110 offsetT insn_start_off)); 111 #ifndef I386COFF 112 static void s_bss PARAMS ((int)); 113 #endif 114 115 static const char *default_arch = DEFAULT_ARCH; 82 116 83 117 /* 'md_assemble ()' gathers together information and puts it into a … … 151 185 operand. Used to prevent the scrubber eating vital white-space. */ 152 186 #ifdef LEX_AT 153 const char extra_symbol_chars[] = "*%-(@ ";187 const char extra_symbol_chars[] = "*%-(@["; 154 188 #else 155 const char extra_symbol_chars[] = "*%-("; 156 #endif 157 189 const char extra_symbol_chars[] = "*%-(["; 190 #endif 191 192 #if (defined (TE_I386AIX) \ 193 || ((defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)) \ 194 && !defined (TE_LINUX) \ 195 && !defined (TE_FreeBSD) \ 196 && !defined (TE_NetBSD))) 158 197 /* This array holds the chars that always start a comment. If the 159 198 pre-processor is disabled, these aren't very useful. */ 160 #if defined (TE_I386AIX) || ((defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)) && ! defined (TE_LINUX) && !defined(TE_FreeBSD))161 /* Putting '/' here makes it impossible to use the divide operator.162 However, we need it for compatibility with SVR4 systems. */163 199 const char comment_chars[] = "#/"; 164 200 #define PREFIX_SEPARATOR '\\' 165 #else166 const char comment_chars[] = "#";167 #define PREFIX_SEPARATOR '/'168 #endif169 201 170 202 /* This array holds the chars that only start a comment at the beginning of … … 176 208 Also note that comments started like this one will always work if 177 209 '/' isn't otherwise defined. */ 178 #if defined (TE_I386AIX) || ((defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)) && ! defined (TE_LINUX) && !defined(TE_FreeBSD)) 179 const char line_comment_chars[] = ""; 210 const char line_comment_chars[] = "#"; 211 180 212 #else 181 const char line_comment_chars[] = "/"; 213 /* Putting '/' here makes it impossible to use the divide operator. 214 However, we need it for compatibility with SVR4 systems. */ 215 const char comment_chars[] = "#"; 216 #define PREFIX_SEPARATOR '/' 217 218 const char line_comment_chars[] = "/#"; 182 219 #endif 183 220 … … 273 310 274 311 /* CPU feature flags. */ 275 static unsigned int cpu_arch_flags = CpuUnknownFlags |CpuNo64;312 static unsigned int cpu_arch_flags = CpuUnknownFlags | CpuNo64; 276 313 277 314 /* If set, conditional jumps are not automatically promoted to handle 278 315 larger than a byte offset. */ 279 316 static unsigned int no_cond_jump_promotion = 0; 317 318 /* Pre-defined "_GLOBAL_OFFSET_TABLE_". */ 319 symbolS *GOT_symbol; 280 320 281 321 /* Interface to relax_segment. … … 292 332 #define CODE16 1 293 333 #define SMALL 0 294 #define SMALL16 (SMALL |CODE16)334 #define SMALL16 (SMALL | CODE16) 295 335 #define BIG 2 296 #define BIG16 (BIG |CODE16)336 #define BIG16 (BIG | CODE16) 297 337 298 338 #ifndef INLINE … … 374 414 {NULL, 0 } 375 415 }; 416 417 const pseudo_typeS md_pseudo_table[] = 418 { 419 #if !defined(OBJ_AOUT) && !defined(USE_ALIGN_PTWO) 420 {"align", s_align_bytes, 0}, 421 #else 422 {"align", s_align_ptwo, 0}, 423 #endif 424 {"arch", set_cpu_arch, 0}, 425 #ifndef I386COFF 426 {"bss", s_bss, 0}, 427 #endif 428 {"ffloat", float_cons, 'f'}, 429 {"dfloat", float_cons, 'd'}, 430 {"tfloat", float_cons, 'x'}, 431 {"value", cons, 2}, 432 {"noopt", s_ignore, 0}, 433 {"optim", s_ignore, 0}, 434 {"code16gcc", set_16bit_gcc_code_flag, CODE_16BIT}, 435 {"code16", set_code_flag, CODE_16BIT}, 436 {"code32", set_code_flag, CODE_32BIT}, 437 {"code64", set_code_flag, CODE_64BIT}, 438 {"intel_syntax", set_intel_syntax, 1}, 439 {"att_syntax", set_intel_syntax, 0}, 440 {"file", (void (*) PARAMS ((int))) dwarf2_directive_file, 0}, 441 {"loc", dwarf2_directive_loc, 0}, 442 {0, 0, 0} 443 }; 444 445 /* For interface with expression (). */ 446 extern char *input_line_pointer; 447 448 /* Hash table for instruction mnemonic lookup. */ 449 static struct hash_control *op_hash; 450 451 /* Hash table for register lookup. */ 452 static struct hash_control *reg_hash; 453 376 454 377 455 void … … 447 525 }; 448 526 449 /* ??? We can't use these fillers for x86_64, since they often kills the 450 upper halves. Solve later. */ 527 if (count <= 0 || count > 15) 528 return; 529 530 /* The recommended way to pad 64bit code is to use NOPs preceded by 531 maximally four 0x66 prefixes. Balance the size of nops. */ 451 532 if (flag_code == CODE_64BIT) 452 count = 1; 453 454 if (count > 0 && count <= 15) 455 { 456 if (flag_code == CODE_16BIT) 457 { 458 memcpy (fragP->fr_literal + fragP->fr_fix, 459 f16_patt[count - 1], count); 460 if (count > 8) 461 /* Adjust jump offset. */ 462 fragP->fr_literal[fragP->fr_fix + 1] = count - 2; 463 } 464 else 533 { 534 int i; 535 int nnops = (count + 3) / 4; 536 int len = count / nnops; 537 int remains = count - nnops * len; 538 int pos = 0; 539 540 for (i = 0; i < remains; i++) 541 { 542 memset (fragP->fr_literal + fragP->fr_fix + pos, 0x66, len); 543 fragP->fr_literal[fragP->fr_fix + pos + len] = 0x90; 544 pos += len + 1; 545 } 546 for (; i < nnops; i++) 547 { 548 memset (fragP->fr_literal + fragP->fr_fix + pos, 0x66, len - 1); 549 fragP->fr_literal[fragP->fr_fix + pos + len - 1] = 0x90; 550 pos += len; 551 } 552 } 553 else 554 if (flag_code == CODE_16BIT) 555 { 465 556 memcpy (fragP->fr_literal + fragP->fr_fix, 466 f32_patt[count - 1], count); 467 fragP->fr_var = count; 468 } 469 } 470 471 static char *output_invalid PARAMS ((int c)); 472 static int i386_operand PARAMS ((char *operand_string)); 473 static int i386_intel_operand PARAMS ((char *operand_string, int got_a_float)); 474 static const reg_entry *parse_register PARAMS ((char *reg_string, 475 char **end_op)); 476 477 #ifndef I386COFF 478 static void s_bss PARAMS ((int)); 479 #endif 480 481 symbolS *GOT_symbol; /* Pre-defined "_GLOBAL_OFFSET_TABLE_". */ 557 f16_patt[count - 1], count); 558 if (count > 8) 559 /* Adjust jump offset. */ 560 fragP->fr_literal[fragP->fr_fix + 1] = count - 2; 561 } 562 else 563 memcpy (fragP->fr_literal + fragP->fr_fix, 564 f32_patt[count - 1], count); 565 fragP->fr_var = count; 566 } 482 567 483 568 static INLINE unsigned int … … 541 626 offsetT num; 542 627 { 543 if (cpu_arch_flags != (Cpu086 | Cpu186 | Cpu286 | Cpu386 | Cpu486 | CpuNo64) 544 && !(cpu_arch_flags & (CpuUnknown))) 628 if (cpu_arch_flags != (Cpu086 | Cpu186 | Cpu286 | Cpu386 | Cpu486 | CpuNo64)) 545 629 { 546 630 /* This code is disabled on the 486 because all the Imm1 forms … … 609 693 int q; 610 694 611 if (prefix >= 0x40 && prefix < 0x50 && flag_code == CODE_64BIT) 695 if (prefix >= REX_OPCODE && prefix < REX_OPCODE + 16 696 && flag_code == CODE_64BIT) 612 697 q = REX_PREFIX; 613 698 else … … 647 732 } 648 733 649 if (i.prefix[q] )734 if (i.prefix[q] != 0) 650 735 { 651 736 as_bad (_("same type of prefix used twice")); … … 694 779 695 780 SKIP_WHITESPACE (); 696 if (! 781 if (!is_end_of_line[(unsigned char) *input_line_pointer]) 697 782 { 698 783 char *string = input_line_pointer; … … 731 816 SKIP_WHITESPACE (); 732 817 733 if (! 818 if (!is_end_of_line[(unsigned char) *input_line_pointer]) 734 819 { 735 820 char *string = input_line_pointer; … … 757 842 no_cond_jump_promotion = 0; 758 843 if (*input_line_pointer == ',' 759 && ! 844 && !is_end_of_line[(unsigned char) input_line_pointer[1]]) 760 845 { 761 846 char *string = ++input_line_pointer; … … 775 860 } 776 861 777 const pseudo_typeS md_pseudo_table[] =778 {779 #if !defined(OBJ_AOUT) && !defined(USE_ALIGN_PTWO)780 {"align", s_align_bytes, 0},781 #else782 {"align", s_align_ptwo, 0},783 #endif784 {"arch", set_cpu_arch, 0},785 #ifndef I386COFF786 {"bss", s_bss, 0},787 #endif788 {"ffloat", float_cons, 'f'},789 {"dfloat", float_cons, 'd'},790 {"tfloat", float_cons, 'x'},791 {"value", cons, 2},792 {"noopt", s_ignore, 0},793 {"optim", s_ignore, 0},794 {"code16gcc", set_16bit_gcc_code_flag, CODE_16BIT},795 {"code16", set_code_flag, CODE_16BIT},796 {"code32", set_code_flag, CODE_32BIT},797 {"code64", set_code_flag, CODE_64BIT},798 {"intel_syntax", set_intel_syntax, 1},799 {"att_syntax", set_intel_syntax, 0},800 {"file", dwarf2_directive_file, 0},801 {"loc", dwarf2_directive_loc, 0},802 {0, 0, 0}803 };804 805 /* For interface with expression (). */806 extern char *input_line_pointer;807 808 /* Hash table for instruction mnemonic lookup. */809 static struct hash_control *op_hash;810 811 /* Hash table for register lookup. */812 static struct hash_control *reg_hash;813 814 815 862 #ifdef BFD_ASSEMBLER 816 863 unsigned long … … 836 883 837 884 { 838 registerconst template *optab;839 registertemplates *core_optab;885 const template *optab; 886 templates *core_optab; 840 887 841 888 /* Setup for loop. */ … … 873 920 reg_hash = hash_new (); 874 921 { 875 registerconst reg_entry *regtab;922 const reg_entry *regtab; 876 923 877 924 for (regtab = i386_regtab; … … 889 936 /* Fill in lexical tables: mnemonic_chars, operand_chars. */ 890 937 { 891 registerint c;892 registerchar *p;938 int c; 939 char *p; 893 940 894 941 for (c = 0; c < 256; c++) 895 942 { 896 if ( isdigit(c))943 if (ISDIGIT (c)) 897 944 { 898 945 digit_chars[c] = c; … … 901 948 operand_chars[c] = c; 902 949 } 903 else if ( islower(c))950 else if (ISLOWER (c)) 904 951 { 905 952 mnemonic_chars[c] = c; … … 907 954 operand_chars[c] = c; 908 955 } 909 else if ( isupper(c))956 else if (ISUPPER (c)) 910 957 { 911 mnemonic_chars[c] = tolower(c);958 mnemonic_chars[c] = TOLOWER (c); 912 959 register_chars[c] = mnemonic_chars[c]; 913 960 operand_chars[c] = c; 914 961 } 915 962 916 if ( isalpha (c) || isdigit(c))963 if (ISALPHA (c) || ISDIGIT (c)) 917 964 identifier_chars[c] = c; 918 965 else if (c >= 128) … … 980 1027 x->sib.base, x->sib.index, x->sib.scale); 981 1028 fprintf (stdout, " rex: 64bit %x extX %x extY %x extZ %x\n", 982 x->rex.mode64, x->rex.extX, x->rex.extY, x->rex.extZ); 1029 (x->rex & REX_MODE64) != 0, 1030 (x->rex & REX_EXTX) != 0, 1031 (x->rex & REX_EXTY) != 0, 1032 (x->rex & REX_EXTZ) != 0); 983 1033 for (i = 0; i < x->operands; i++) 984 1034 { … … 1055 1105 } 1056 1106 1057 type_names[] =1107 static const type_names[] = 1058 1108 { 1059 1109 { Reg8, "r8" }, … … 1095 1145 unsigned int t; 1096 1146 { 1097 registerstruct type_name *ty;1147 const struct type_name *ty; 1098 1148 1099 1149 for (ty = type_names; ty->mask; ty++) … … 1106 1156 1107 1157 1108 int1109 tc_i386_force_relocation (fixp)1110 struct fix *fixp;1111 {1112 1158 #ifdef BFD_ASSEMBLER 1113 if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT 1114 || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY) 1115 return 1; 1116 return 0; 1117 #else 1118 /* For COFF. */ 1119 return fixp->fx_r_type == 7; 1120 #endif 1121 } 1122 1123 #ifdef BFD_ASSEMBLER 1159 static bfd_reloc_code_real_type reloc 1160 PARAMS ((int, int, int, bfd_reloc_code_real_type)); 1124 1161 1125 1162 static bfd_reloc_code_real_type … … 1175 1212 int 1176 1213 tc_i386_fix_adjustable (fixP) 1177 fixS *fixP ;1214 fixS *fixP ATTRIBUTE_UNUSED; 1178 1215 { 1179 1216 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) 1180 /* Prevent all adjustments to global symbols, or else dynamic 1181 linking will not work correctly. */ 1182 if (S_IS_EXTERNAL (fixP->fx_addsy) 1183 || S_IS_WEAK (fixP->fx_addsy)) 1217 if (OUTPUT_FLAVOR != bfd_target_elf_flavour) 1218 return 1; 1219 1220 /* Don't adjust pc-relative references to merge sections in 64-bit 1221 mode. */ 1222 if (use_rela_relocations 1223 && (S_GET_SEGMENT (fixP->fx_addsy)->flags & SEC_MERGE) != 0 1224 && fixP->fx_pcrel) 1184 1225 return 0; 1185 #endif 1226 1186 1227 /* adjust_reloc_syms doesn't know about the GOT. */ 1187 1228 if (fixP->fx_r_type == BFD_RELOC_386_GOTOFF 1188 1229 || fixP->fx_r_type == BFD_RELOC_386_PLT32 1189 1230 || fixP->fx_r_type == BFD_RELOC_386_GOT32 1231 || fixP->fx_r_type == BFD_RELOC_386_TLS_GD 1232 || fixP->fx_r_type == BFD_RELOC_386_TLS_LDM 1233 || fixP->fx_r_type == BFD_RELOC_386_TLS_LDO_32 1234 || fixP->fx_r_type == BFD_RELOC_386_TLS_IE_32 1235 || fixP->fx_r_type == BFD_RELOC_386_TLS_IE 1236 || fixP->fx_r_type == BFD_RELOC_386_TLS_GOTIE 1237 || fixP->fx_r_type == BFD_RELOC_386_TLS_LE_32 1238 || fixP->fx_r_type == BFD_RELOC_386_TLS_LE 1190 1239 || fixP->fx_r_type == BFD_RELOC_X86_64_PLT32 1191 1240 || fixP->fx_r_type == BFD_RELOC_X86_64_GOT32 1192 1241 || fixP->fx_r_type == BFD_RELOC_X86_64_GOTPCREL 1242 || fixP->fx_r_type == BFD_RELOC_X86_64_TLSGD 1243 || fixP->fx_r_type == BFD_RELOC_X86_64_TLSLD 1244 || fixP->fx_r_type == BFD_RELOC_X86_64_DTPOFF32 1245 || fixP->fx_r_type == BFD_RELOC_X86_64_GOTTPOFF 1246 || fixP->fx_r_type == BFD_RELOC_X86_64_TPOFF32 1193 1247 || fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT 1194 1248 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY) 1195 1249 return 0; 1250 #endif 1196 1251 return 1; 1197 1252 } 1198 1253 #else 1199 1254 #define reloc(SIZE,PCREL,SIGN,OTHER) 0 1255 #define BFD_RELOC_8 0 1200 1256 #define BFD_RELOC_16 0 1201 1257 #define BFD_RELOC_32 0 1258 #define BFD_RELOC_8_PCREL 0 1202 1259 #define BFD_RELOC_16_PCREL 0 1203 1260 #define BFD_RELOC_32_PCREL 0 … … 1205 1262 #define BFD_RELOC_386_GOT32 0 1206 1263 #define BFD_RELOC_386_GOTOFF 0 1264 #define BFD_RELOC_386_TLS_GD 0 1265 #define BFD_RELOC_386_TLS_LDM 0 1266 #define BFD_RELOC_386_TLS_LDO_32 0 1267 #define BFD_RELOC_386_TLS_IE_32 0 1268 #define BFD_RELOC_386_TLS_IE 0 1269 #define BFD_RELOC_386_TLS_GOTIE 0 1270 #define BFD_RELOC_386_TLS_LE_32 0 1271 #define BFD_RELOC_386_TLS_LE 0 1207 1272 #define BFD_RELOC_X86_64_PLT32 0 1208 1273 #define BFD_RELOC_X86_64_GOT32 0 1209 1274 #define BFD_RELOC_X86_64_GOTPCREL 0 1210 #endif 1211 1212 static int intel_float_operand PARAMS ((char *mnemonic)); 1275 #define BFD_RELOC_X86_64_TLSGD 0 1276 #define BFD_RELOC_X86_64_TLSLD 0 1277 #define BFD_RELOC_X86_64_DTPOFF32 0 1278 #define BFD_RELOC_X86_64_GOTTPOFF 0 1279 #define BFD_RELOC_X86_64_TPOFF32 0 1280 #endif 1281 1282 static int intel_float_operand PARAMS ((const char *mnemonic)); 1213 1283 1214 1284 static int 1215 1285 intel_float_operand (mnemonic) 1216 c har *mnemonic;1286 const char *mnemonic; 1217 1287 { 1218 1288 if (mnemonic[0] == 'f' && mnemonic[1] == 'i') … … 1233 1303 char *line; 1234 1304 { 1235 /* Points to template once we've found it. */1236 const template *t;1237 1238 1305 int j; 1239 1240 1306 char mnemonic[MAX_MNEM_SIZE]; 1241 1307 … … 1251 1317 We assume that the scrubber has arranged it so that line[0] is the valid 1252 1318 start of a (possibly prefixed) mnemonic. */ 1253 { 1254 char *l = line; 1255 char *token_start = l; 1256 char *mnem_p; 1257 1258 /* Non-zero if we found a prefix only acceptable with string insns. */ 1259 const char *expecting_string_instruction = NULL; 1260 1261 while (1) 1262 { 1263 mnem_p = mnemonic; 1264 while ((*mnem_p = mnemonic_chars[(unsigned char) *l]) != 0) 1265 { 1266 mnem_p++; 1267 if (mnem_p >= mnemonic + sizeof (mnemonic)) 1268 { 1269 as_bad (_("no such instruction: `%s'"), token_start); 1270 return; 1271 } 1272 l++; 1273 } 1274 if (!is_space_char (*l) 1275 && *l != END_OF_INSN 1276 && *l != PREFIX_SEPARATOR) 1277 { 1278 as_bad (_("invalid character %s in mnemonic"), 1279 output_invalid (*l)); 1280 return; 1281 } 1282 if (token_start == l) 1283 { 1284 if (*l == PREFIX_SEPARATOR) 1285 as_bad (_("expecting prefix; got nothing")); 1286 else 1287 as_bad (_("expecting mnemonic; got nothing")); 1288 return; 1289 } 1290 1291 /* Look up instruction (or prefix) via hash table. */ 1292 current_templates = hash_find (op_hash, mnemonic); 1293 1294 if (*l != END_OF_INSN 1295 && (! is_space_char (*l) || l[1] != END_OF_INSN) 1296 && current_templates 1297 && (current_templates->start->opcode_modifier & IsPrefix)) 1298 { 1299 /* If we are in 16-bit mode, do not allow addr16 or data16. 1300 Similarly, in 32-bit mode, do not allow addr32 or data32. */ 1301 if ((current_templates->start->opcode_modifier & (Size16 | Size32)) 1302 && (((current_templates->start->opcode_modifier & Size32) != 0) 1303 ^ (flag_code == CODE_16BIT))) 1304 { 1305 as_bad (_("redundant %s prefix"), 1306 current_templates->start->name); 1307 return; 1308 } 1309 /* Add prefix, checking for repeated prefixes. */ 1310 switch (add_prefix (current_templates->start->base_opcode)) 1311 { 1312 case 0: 1313 return; 1314 case 2: 1315 expecting_string_instruction = current_templates->start->name; 1316 break; 1317 } 1318 /* Skip past PREFIX_SEPARATOR and reset token_start. */ 1319 token_start = ++l; 1320 } 1321 else 1322 break; 1323 } 1324 1325 if (!current_templates) 1326 { 1327 /* See if we can get a match by trimming off a suffix. */ 1328 switch (mnem_p[-1]) 1329 { 1330 case WORD_MNEM_SUFFIX: 1331 case BYTE_MNEM_SUFFIX: 1332 case QWORD_MNEM_SUFFIX: 1333 i.suffix = mnem_p[-1]; 1334 mnem_p[-1] = '\0'; 1335 current_templates = hash_find (op_hash, mnemonic); 1336 break; 1337 case SHORT_MNEM_SUFFIX: 1338 case LONG_MNEM_SUFFIX: 1339 if (!intel_syntax) 1340 { 1341 i.suffix = mnem_p[-1]; 1342 mnem_p[-1] = '\0'; 1343 current_templates = hash_find (op_hash, mnemonic); 1344 } 1345 break; 1346 1347 /* Intel Syntax. */ 1348 case 'd': 1349 if (intel_syntax) 1350 { 1351 if (intel_float_operand (mnemonic)) 1352 i.suffix = SHORT_MNEM_SUFFIX; 1353 else 1354 i.suffix = LONG_MNEM_SUFFIX; 1355 mnem_p[-1] = '\0'; 1356 current_templates = hash_find (op_hash, mnemonic); 1357 } 1358 break; 1359 } 1360 if (!current_templates) 1361 { 1362 as_bad (_("no such instruction: `%s'"), token_start); 1363 return; 1364 } 1365 } 1366 1367 /* Check if instruction is supported on specified architecture. */ 1368 if (cpu_arch_flags != 0) 1369 { 1370 if ((current_templates->start->cpu_flags & ~(Cpu64 | CpuNo64)) 1371 & ~(cpu_arch_flags & ~(Cpu64 | CpuNo64))) 1372 { 1373 as_warn (_("`%s' is not supported on `%s'"), 1374 current_templates->start->name, cpu_arch_name); 1375 } 1376 else if ((Cpu386 & ~cpu_arch_flags) && (flag_code != CODE_16BIT)) 1377 { 1378 as_warn (_("use .code16 to ensure correct addressing mode")); 1379 } 1380 } 1381 1382 /* Check for rep/repne without a string instruction. */ 1383 if (expecting_string_instruction 1384 && !(current_templates->start->opcode_modifier & IsString)) 1385 { 1386 as_bad (_("expecting string instruction after `%s'"), 1387 expecting_string_instruction); 1388 return; 1389 } 1390 1391 /* There may be operands to parse. */ 1392 if (*l != END_OF_INSN) 1393 { 1394 /* 1 if operand is pending after ','. */ 1395 unsigned int expecting_operand = 0; 1396 1397 /* Non-zero if operand parens not balanced. */ 1398 unsigned int paren_not_balanced; 1399 1400 do 1401 { 1402 /* Skip optional white space before operand. */ 1403 if (is_space_char (*l)) 1404 ++l; 1405 if (!is_operand_char (*l) && *l != END_OF_INSN) 1406 { 1407 as_bad (_("invalid character %s before operand %d"), 1408 output_invalid (*l), 1409 i.operands + 1); 1410 return; 1411 } 1412 token_start = l; /* after white space */ 1413 paren_not_balanced = 0; 1414 while (paren_not_balanced || *l != ',') 1415 { 1416 if (*l == END_OF_INSN) 1417 { 1418 if (paren_not_balanced) 1419 { 1420 if (!intel_syntax) 1421 as_bad (_("unbalanced parenthesis in operand %d."), 1422 i.operands + 1); 1423 else 1424 as_bad (_("unbalanced brackets in operand %d."), 1425 i.operands + 1); 1426 return; 1427 } 1428 else 1429 break; /* we are done */ 1430 } 1431 else if (!is_operand_char (*l) && !is_space_char (*l)) 1432 { 1433 as_bad (_("invalid character %s in operand %d"), 1434 output_invalid (*l), 1435 i.operands + 1); 1436 return; 1437 } 1438 if (!intel_syntax) 1439 { 1440 if (*l == '(') 1441 ++paren_not_balanced; 1442 if (*l == ')') 1443 --paren_not_balanced; 1444 } 1445 else 1446 { 1447 if (*l == '[') 1448 ++paren_not_balanced; 1449 if (*l == ']') 1450 --paren_not_balanced; 1451 } 1452 l++; 1453 } 1454 if (l != token_start) 1455 { /* Yes, we've read in another operand. */ 1456 unsigned int operand_ok; 1457 this_operand = i.operands++; 1458 if (i.operands > MAX_OPERANDS) 1459 { 1460 as_bad (_("spurious operands; (%d operands/instruction max)"), 1461 MAX_OPERANDS); 1462 return; 1463 } 1464 /* Now parse operand adding info to 'i' as we go along. */ 1465 END_STRING_AND_SAVE (l); 1466 1467 if (intel_syntax) 1468 operand_ok = 1469 i386_intel_operand (token_start, 1470 intel_float_operand (mnemonic)); 1471 else 1472 operand_ok = i386_operand (token_start); 1473 1474 RESTORE_END_STRING (l); 1475 if (!operand_ok) 1476 return; 1477 } 1478 else 1479 { 1480 if (expecting_operand) 1481 { 1482 expecting_operand_after_comma: 1483 as_bad (_("expecting operand after ','; got nothing")); 1484 return; 1485 } 1486 if (*l == ',') 1487 { 1488 as_bad (_("expecting operand before ','; got nothing")); 1489 return; 1490 } 1491 } 1492 1493 /* Now *l must be either ',' or END_OF_INSN. */ 1494 if (*l == ',') 1495 { 1496 if (*++l == END_OF_INSN) 1497 { 1498 /* Just skip it, if it's \n complain. */ 1499 goto expecting_operand_after_comma; 1500 } 1501 expecting_operand = 1; 1502 } 1503 } 1504 while (*l != END_OF_INSN); 1505 } 1506 } 1319 1320 line = parse_insn (line, mnemonic); 1321 if (line == NULL) 1322 return; 1323 1324 line = parse_operands (line, mnemonic); 1325 if (line == NULL) 1326 return; 1507 1327 1508 1328 /* Now we've parsed the mnemonic into a set of templates, and have the 1509 operands at hand. 1510 1511 Next, we find a template that matches the given insn, 1329 operands at hand. */ 1330 1331 /* All intel opcodes have reversed operands except for "bound" and 1332 "enter". We also don't reverse intersegment "jmp" and "call" 1333 instructions with 2 immediate operands so that the immediate segment 1334 precedes the offset, as it does when in AT&T mode. "enter" and the 1335 intersegment "jmp" and "call" instructions are the only ones that 1336 have two immediate operands. */ 1337 if (intel_syntax && i.operands > 1 1338 && (strcmp (mnemonic, "bound") != 0) 1339 && !((i.types[0] & Imm) && (i.types[1] & Imm))) 1340 swap_operands (); 1341 1342 if (i.imm_operands) 1343 optimize_imm (); 1344 1345 if (i.disp_operands) 1346 optimize_disp (); 1347 1348 /* Next, we find a template that matches the given insn, 1512 1349 making sure the overlap of the given operands types is consistent 1513 1350 with the template operand types. */ 1514 1351 1515 #define MATCH(overlap, given, template) \ 1516 ((overlap & ~JumpAbsolute) \ 1517 && ((given) & (BaseIndex|JumpAbsolute)) == ((overlap) & (BaseIndex|JumpAbsolute))) 1518 1519 /* If given types r0 and r1 are registers they must be of the same type 1520 unless the expected operand type register overlap is null. 1521 Note that Acc in a template matches every size of reg. */ 1522 #define CONSISTENT_REGISTER_MATCH(m0, g0, t0, m1, g1, t1) \ 1523 ( ((g0) & Reg) == 0 || ((g1) & Reg) == 0 || \ 1524 ((g0) & Reg) == ((g1) & Reg) || \ 1525 ((((m0) & Acc) ? Reg : (t0)) & (((m1) & Acc) ? Reg : (t1)) & Reg) == 0 ) 1526 1527 { 1528 register unsigned int overlap0, overlap1; 1529 unsigned int overlap2; 1530 unsigned int found_reverse_match; 1531 int suffix_check; 1532 1533 /* All intel opcodes have reversed operands except for "bound" and 1534 "enter". We also don't reverse intersegment "jmp" and "call" 1535 instructions with 2 immediate operands so that the immediate segment 1536 precedes the offset, as it does when in AT&T mode. "enter" and the 1537 intersegment "jmp" and "call" instructions are the only ones that 1538 have two immediate operands. */ 1539 if (intel_syntax && i.operands > 1 1540 && (strcmp (mnemonic, "bound") != 0) 1541 && !((i.types[0] & Imm) && (i.types[1] & Imm))) 1542 { 1543 union i386_op temp_op; 1544 unsigned int temp_type; 1545 RELOC_ENUM temp_reloc; 1546 int xchg1 = 0; 1547 int xchg2 = 0; 1548 1549 if (i.operands == 2) 1550 { 1551 xchg1 = 0; 1552 xchg2 = 1; 1553 } 1554 else if (i.operands == 3) 1555 { 1556 xchg1 = 0; 1557 xchg2 = 2; 1558 } 1559 temp_type = i.types[xchg2]; 1560 i.types[xchg2] = i.types[xchg1]; 1561 i.types[xchg1] = temp_type; 1562 temp_op = i.op[xchg2]; 1563 i.op[xchg2] = i.op[xchg1]; 1564 i.op[xchg1] = temp_op; 1565 temp_reloc = i.reloc[xchg2]; 1566 i.reloc[xchg2] = i.reloc[xchg1]; 1567 i.reloc[xchg1] = temp_reloc; 1568 1569 if (i.mem_operands == 2) 1570 { 1571 const seg_entry *temp_seg; 1572 temp_seg = i.seg[0]; 1573 i.seg[0] = i.seg[1]; 1574 i.seg[1] = temp_seg; 1575 } 1576 } 1577 1578 if (i.imm_operands) 1579 { 1580 /* Try to ensure constant immediates are represented in the smallest 1581 opcode possible. */ 1582 char guess_suffix = 0; 1583 int op; 1584 1585 if (i.suffix) 1586 guess_suffix = i.suffix; 1587 else if (i.reg_operands) 1588 { 1589 /* Figure out a suffix from the last register operand specified. 1590 We can't do this properly yet, ie. excluding InOutPortReg, 1591 but the following works for instructions with immediates. 1592 In any case, we can't set i.suffix yet. */ 1593 for (op = i.operands; --op >= 0;) 1594 if (i.types[op] & Reg) 1595 { 1596 if (i.types[op] & Reg8) 1597 guess_suffix = BYTE_MNEM_SUFFIX; 1598 else if (i.types[op] & Reg16) 1599 guess_suffix = WORD_MNEM_SUFFIX; 1600 else if (i.types[op] & Reg32) 1601 guess_suffix = LONG_MNEM_SUFFIX; 1602 else if (i.types[op] & Reg64) 1603 guess_suffix = QWORD_MNEM_SUFFIX; 1604 break; 1605 } 1606 } 1607 else if ((flag_code == CODE_16BIT) ^ (i.prefix[DATA_PREFIX] != 0)) 1608 guess_suffix = WORD_MNEM_SUFFIX; 1609 1610 for (op = i.operands; --op >= 0;) 1611 if (i.types[op] & Imm) 1612 { 1613 switch (i.op[op].imms->X_op) 1614 { 1615 case O_constant: 1616 /* If a suffix is given, this operand may be shortened. */ 1617 switch (guess_suffix) 1618 { 1619 case LONG_MNEM_SUFFIX: 1620 i.types[op] |= Imm32 | Imm64; 1621 break; 1622 case WORD_MNEM_SUFFIX: 1623 i.types[op] |= Imm16 | Imm32S | Imm32 | Imm64; 1624 break; 1625 case BYTE_MNEM_SUFFIX: 1626 i.types[op] |= Imm16 | Imm8 | Imm8S | Imm32S | Imm32 | Imm64; 1627 break; 1628 } 1629 1630 /* If this operand is at most 16 bits, convert it 1631 to a signed 16 bit number before trying to see 1632 whether it will fit in an even smaller size. 1633 This allows a 16-bit operand such as $0xffe0 to 1634 be recognised as within Imm8S range. */ 1635 if ((i.types[op] & Imm16) 1636 && (i.op[op].imms->X_add_number & ~(offsetT) 0xffff) == 0) 1637 { 1638 i.op[op].imms->X_add_number = 1639 (((i.op[op].imms->X_add_number & 0xffff) ^ 0x8000) - 0x8000); 1640 } 1641 if ((i.types[op] & Imm32) 1642 && (i.op[op].imms->X_add_number & ~(((offsetT) 2 << 31) - 1)) == 0) 1643 { 1644 i.op[op].imms->X_add_number = 1645 (i.op[op].imms->X_add_number ^ ((offsetT) 1 << 31)) - ((addressT) 1 << 31); 1646 } 1647 i.types[op] |= smallest_imm_type (i.op[op].imms->X_add_number); 1648 /* We must avoid matching of Imm32 templates when 64bit only immediate is available. */ 1649 if (guess_suffix == QWORD_MNEM_SUFFIX) 1650 i.types[op] &= ~Imm32; 1651 break; 1652 case O_absent: 1653 case O_register: 1654 abort (); 1655 /* Symbols and expressions. */ 1656 default: 1657 /* Convert symbolic operand to proper sizes for matching. */ 1658 switch (guess_suffix) 1659 { 1660 case QWORD_MNEM_SUFFIX: 1661 i.types[op] = Imm64 | Imm32S; 1662 break; 1663 case LONG_MNEM_SUFFIX: 1664 i.types[op] = Imm32 | Imm64; 1665 break; 1666 case WORD_MNEM_SUFFIX: 1667 i.types[op] = Imm16 | Imm32 | Imm64; 1668 break; 1669 break; 1670 case BYTE_MNEM_SUFFIX: 1671 i.types[op] = Imm8 | Imm8S | Imm16 | Imm32S | Imm32; 1672 break; 1673 break; 1674 } 1675 break; 1676 } 1677 } 1678 } 1679 1680 if (i.disp_operands) 1681 { 1682 /* Try to use the smallest displacement type too. */ 1683 int op; 1684 1685 for (op = i.operands; --op >= 0;) 1686 if ((i.types[op] & Disp) 1687 && i.op[op].disps->X_op == O_constant) 1688 { 1689 offsetT disp = i.op[op].disps->X_add_number; 1690 1691 if (i.types[op] & Disp16) 1692 { 1693 /* We know this operand is at most 16 bits, so 1694 convert to a signed 16 bit number before trying 1695 to see whether it will fit in an even smaller 1696 size. */ 1697 1698 disp = (((disp & 0xffff) ^ 0x8000) - 0x8000); 1699 } 1700 else if (i.types[op] & Disp32) 1701 { 1702 /* We know this operand is at most 32 bits, so convert to a 1703 signed 32 bit number before trying to see whether it will 1704 fit in an even smaller size. */ 1705 disp &= (((offsetT) 2 << 31) - 1); 1706 disp = (disp ^ ((offsetT) 1 << 31)) - ((addressT) 1 << 31); 1707 } 1708 if (flag_code == CODE_64BIT) 1709 { 1710 if (fits_in_signed_long (disp)) 1711 i.types[op] |= Disp32S; 1712 if (fits_in_unsigned_long (disp)) 1713 i.types[op] |= Disp32; 1714 } 1715 if ((i.types[op] & (Disp32 | Disp32S | Disp16)) 1716 && fits_in_signed_byte (disp)) 1717 i.types[op] |= Disp8; 1718 } 1719 } 1720 1721 overlap0 = 0; 1722 overlap1 = 0; 1723 overlap2 = 0; 1724 found_reverse_match = 0; 1725 suffix_check = (i.suffix == BYTE_MNEM_SUFFIX 1726 ? No_bSuf 1727 : (i.suffix == WORD_MNEM_SUFFIX 1728 ? No_wSuf 1729 : (i.suffix == SHORT_MNEM_SUFFIX 1730 ? No_sSuf 1731 : (i.suffix == LONG_MNEM_SUFFIX 1732 ? No_lSuf 1733 : (i.suffix == QWORD_MNEM_SUFFIX 1734 ? No_qSuf 1735 : (i.suffix == LONG_DOUBLE_MNEM_SUFFIX ? No_xSuf : 0)))))); 1736 1737 for (t = current_templates->start; 1738 t < current_templates->end; 1739 t++) 1740 { 1741 /* Must have right number of operands. */ 1742 if (i.operands != t->operands) 1743 continue; 1744 1745 /* Check the suffix, except for some instructions in intel mode. */ 1746 if ((t->opcode_modifier & suffix_check) 1747 && !(intel_syntax 1748 && (t->opcode_modifier & IgnoreSize)) 1749 && !(intel_syntax 1750 && t->base_opcode == 0xd9 1751 && (t->extension_opcode == 5 /* 0xd9,5 "fldcw" */ 1752 || t->extension_opcode == 7))) /* 0xd9,7 "f{n}stcw" */ 1753 continue; 1754 1755 /* Do not verify operands when there are none. */ 1756 else if (!t->operands) 1757 { 1758 if (t->cpu_flags & ~cpu_arch_flags) 1759 continue; 1760 /* We've found a match; break out of loop. */ 1761 break; 1762 } 1763 1764 overlap0 = i.types[0] & t->operand_types[0]; 1765 switch (t->operands) 1766 { 1767 case 1: 1768 if (!MATCH (overlap0, i.types[0], t->operand_types[0])) 1769 continue; 1770 break; 1771 case 2: 1772 case 3: 1773 overlap1 = i.types[1] & t->operand_types[1]; 1774 if (!MATCH (overlap0, i.types[0], t->operand_types[0]) 1775 || !MATCH (overlap1, i.types[1], t->operand_types[1]) 1776 || !CONSISTENT_REGISTER_MATCH (overlap0, i.types[0], 1777 t->operand_types[0], 1778 overlap1, i.types[1], 1779 t->operand_types[1])) 1780 { 1781 /* Check if other direction is valid ... */ 1782 if ((t->opcode_modifier & (D|FloatD)) == 0) 1783 continue; 1784 1785 /* Try reversing direction of operands. */ 1786 overlap0 = i.types[0] & t->operand_types[1]; 1787 overlap1 = i.types[1] & t->operand_types[0]; 1788 if (!MATCH (overlap0, i.types[0], t->operand_types[1]) 1789 || !MATCH (overlap1, i.types[1], t->operand_types[0]) 1790 || !CONSISTENT_REGISTER_MATCH (overlap0, i.types[0], 1791 t->operand_types[1], 1792 overlap1, i.types[1], 1793 t->operand_types[0])) 1794 { 1795 /* Does not match either direction. */ 1796 continue; 1797 } 1798 /* found_reverse_match holds which of D or FloatDR 1799 we've found. */ 1800 found_reverse_match = t->opcode_modifier & (D|FloatDR); 1801 } 1802 /* Found a forward 2 operand match here. */ 1803 else if (t->operands == 3) 1804 { 1805 /* Here we make use of the fact that there are no 1806 reverse match 3 operand instructions, and all 3 1807 operand instructions only need to be checked for 1808 register consistency between operands 2 and 3. */ 1809 overlap2 = i.types[2] & t->operand_types[2]; 1810 if (!MATCH (overlap2, i.types[2], t->operand_types[2]) 1811 || !CONSISTENT_REGISTER_MATCH (overlap1, i.types[1], 1812 t->operand_types[1], 1813 overlap2, i.types[2], 1814 t->operand_types[2])) 1815 1816 continue; 1817 } 1818 /* Found either forward/reverse 2 or 3 operand match here: 1819 slip through to break. */ 1820 } 1821 if (t->cpu_flags & ~cpu_arch_flags) 1822 { 1823 found_reverse_match = 0; 1824 continue; 1825 } 1826 /* We've found a match; break out of loop. */ 1827 break; 1828 } 1829 if (t == current_templates->end) 1830 { 1831 /* We found no match. */ 1832 as_bad (_("suffix or operands invalid for `%s'"), 1833 current_templates->start->name); 1352 if (!match_template ()) 1353 return; 1354 1355 if (intel_syntax) 1356 { 1357 /* Undo SYSV386_COMPAT brokenness when in Intel mode. See i386.h */ 1358 if (SYSV386_COMPAT 1359 && (i.tm.base_opcode & 0xfffffde0) == 0xdce0) 1360 i.tm.base_opcode ^= FloatR; 1361 1362 /* Zap movzx and movsx suffix. The suffix may have been set from 1363 "word ptr" or "byte ptr" on the source operand, but we'll use 1364 the suffix later to choose the destination register. */ 1365 if ((i.tm.base_opcode & ~9) == 0x0fb6) 1366 i.suffix = 0; 1367 } 1368 1369 if (i.tm.opcode_modifier & FWait) 1370 if (!add_prefix (FWAIT_OPCODE)) 1371 return; 1372 1373 /* Check string instruction segment overrides. */ 1374 if ((i.tm.opcode_modifier & IsString) != 0 && i.mem_operands != 0) 1375 { 1376 if (!check_string ()) 1834 1377 return; 1835 1836 1837 if (!quiet_warnings)1838 {1839 if (!intel_syntax 1840 && ((i.types[0] & JumpAbsolute) 1841 != (t->operand_types[0] & JumpAbsolute))) 1842 { 1843 as_warn (_("indirect %s without `*'"), t->name);1844 } 1845 1846 if ((t->opcode_modifier & (IsPrefix|IgnoreSize)) 1847 == (IsPrefix|IgnoreSize))1848 { 1849 /* Warn them that a data or address size prefix doesn't 1850 affect assembly of the next line of code. */ 1851 as_warn (_("stand-alone `%s' prefix"), t->name); 1852 } 1853 } 1854 1855 /* Copy the template we found. */1856 i.tm = *t;1857 if (found_reverse_match) 1858 { 1859 /* If we found a reverse match we must alter the opcode1860 direction bit. found_reverse_match holds bits to change 1861 (different for int & float insns). */ 1862 1863 i.tm.base_opcode ^= found_reverse_match;1864 1865 i.tm.operand_types[0] = t->operand_types[1];1866 i.tm.operand_types[1] = t->operand_types[0];1867 }1868 1869 /* Undo SYSV386_COMPAT brokenness when in Intel mode. See i386.h */1870 if (SYSV386_COMPAT1871 && intel_syntax 1872 && (i.tm.base_opcode & 0xfffffde0) == 0xdce0) 1873 i.tm.base_opcode ^= FloatR;1874 1875 if (i.tm.opcode_modifier & FWait)1876 if (! add_prefix (FWAIT_OPCODE))1378 } 1379 1380 if (!process_suffix ()) 1381 return; 1382 1383 /* Make still unresolved immediate matches conform to size of immediate 1384 given in i.suffix. */ 1385 if (!finalize_imm ()) 1386 return; 1387 1388 if (i.types[0] & Imm1) 1389 i.imm_operands = 0; /* kludge for shift insns. */ 1390 if (i.types[0] & ImplicitRegister) 1391 i.reg_operands--; 1392 if (i.types[1] & ImplicitRegister) 1393 i.reg_operands--; 1394 if (i.types[2] & ImplicitRegister) 1395 i.reg_operands--; 1396 1397 if (i.tm.opcode_modifier & ImmExt) 1398 { 1399 /* These AMD 3DNow! and Intel Katmai New Instructions have an 1400 opcode suffix which is coded in the same place as an 8-bit 1401 immediate field would be. Here we fake an 8-bit immediate 1402 operand from the opcode suffix stored in tm.extension_opcode. */ 1403 1404 expressionS *exp; 1405 1406 assert (i.imm_operands == 0 && i.operands <= 2 && 2 < MAX_OPERANDS); 1407 1408 exp = &im_expressions[i.imm_operands++]; 1409 i.op[i.operands].imms = exp; 1410 i.types[i.operands++] = Imm8; 1411 exp->X_op = O_constant; 1412 exp->X_add_number = i.tm.extension_opcode; 1413 i.tm.extension_opcode = None; 1414 } 1415 1416 /* For insns with operands there are more diddles to do to the opcode. */ 1417 if (i.operands) 1418 { 1419 if (!process_operands ()) 1877 1420 return; 1878 1879 /* Check string instruction segment overrides. */ 1880 if ((i.tm.opcode_modifier & IsString) != 0 && i.mem_operands != 0) 1881 { 1882 int mem_op = (i.types[0] & AnyMem) ? 0 : 1; 1883 if ((i.tm.operand_types[mem_op] & EsSeg) != 0) 1884 { 1885 if (i.seg[0] != NULL && i.seg[0] != &es) 1886 { 1887 as_bad (_("`%s' operand %d must use `%%es' segment"), 1888 i.tm.name, 1889 mem_op + 1); 1890 return; 1891 } 1892 /* There's only ever one segment override allowed per instruction. 1893 This instruction possibly has a legal segment override on the 1894 second operand, so copy the segment to where non-string 1895 instructions store it, allowing common code. */ 1896 i.seg[0] = i.seg[1]; 1897 } 1898 else if ((i.tm.operand_types[mem_op + 1] & EsSeg) != 0) 1899 { 1900 if (i.seg[1] != NULL && i.seg[1] != &es) 1901 { 1902 as_bad (_("`%s' operand %d must use `%%es' segment"), 1903 i.tm.name, 1904 mem_op + 2); 1905 return; 1906 } 1907 } 1908 } 1909 1910 if (i.reg_operands && flag_code < CODE_64BIT) 1911 { 1912 int op; 1913 for (op = i.operands; --op >= 0;) 1914 if ((i.types[op] & Reg) 1915 && (i.op[op].regs->reg_flags & (RegRex64|RegRex))) 1916 { 1917 as_bad (_("Extended register `%%%s' available only in 64bit mode."), 1918 i.op[op].regs->reg_name); 1919 return; 1920 } 1921 } 1922 1923 /* If matched instruction specifies an explicit instruction mnemonic 1924 suffix, use it. */ 1925 if (i.tm.opcode_modifier & (Size16 | Size32 | Size64)) 1926 { 1927 if (i.tm.opcode_modifier & Size16) 1928 i.suffix = WORD_MNEM_SUFFIX; 1929 else if (i.tm.opcode_modifier & Size64) 1930 i.suffix = QWORD_MNEM_SUFFIX; 1931 else 1932 i.suffix = LONG_MNEM_SUFFIX; 1933 } 1934 else if (i.reg_operands) 1935 { 1936 /* If there's no instruction mnemonic suffix we try to invent one 1937 based on register operands. */ 1938 if (!i.suffix) 1939 { 1940 /* We take i.suffix from the last register operand specified, 1941 Destination register type is more significant than source 1942 register type. */ 1943 int op; 1944 for (op = i.operands; --op >= 0;) 1945 if ((i.types[op] & Reg) 1946 && !(i.tm.operand_types[op] & InOutPortReg)) 1947 { 1948 i.suffix = ((i.types[op] & Reg8) ? BYTE_MNEM_SUFFIX : 1949 (i.types[op] & Reg16) ? WORD_MNEM_SUFFIX : 1950 (i.types[op] & Reg64) ? QWORD_MNEM_SUFFIX : 1951 LONG_MNEM_SUFFIX); 1952 break; 1953 } 1954 } 1955 else if (i.suffix == BYTE_MNEM_SUFFIX) 1956 { 1957 int op; 1958 for (op = i.operands; --op >= 0;) 1959 { 1960 /* If this is an eight bit register, it's OK. If it's 1961 the 16 or 32 bit version of an eight bit register, 1962 we will just use the low portion, and that's OK too. */ 1963 if (i.types[op] & Reg8) 1964 continue; 1965 1966 /* movzx and movsx should not generate this warning. */ 1967 if (intel_syntax 1968 && (i.tm.base_opcode == 0xfb7 1969 || i.tm.base_opcode == 0xfb6 1970 || i.tm.base_opcode == 0x63 1971 || i.tm.base_opcode == 0xfbe 1972 || i.tm.base_opcode == 0xfbf)) 1973 continue; 1974 1975 if ((i.types[op] & WordReg) && i.op[op].regs->reg_num < 4 1976 #if 0 1977 /* Check that the template allows eight bit regs 1978 This kills insns such as `orb $1,%edx', which 1979 maybe should be allowed. */ 1980 && (i.tm.operand_types[op] & (Reg8|InOutPortReg)) 1981 #endif 1982 ) 1983 { 1984 /* Prohibit these changes in the 64bit mode, since 1985 the lowering is more complicated. */ 1986 if (flag_code == CODE_64BIT 1987 && (i.tm.operand_types[op] & InOutPortReg) == 0) 1988 as_bad (_("Incorrect register `%%%s' used with`%c' suffix"), 1989 i.op[op].regs->reg_name, 1990 i.suffix); 1991 #if REGISTER_WARNINGS 1992 if (!quiet_warnings 1993 && (i.tm.operand_types[op] & InOutPortReg) == 0) 1994 as_warn (_("using `%%%s' instead of `%%%s' due to `%c' suffix"), 1995 (i.op[op].regs 1996 + (i.types[op] & Reg16 1997 ? REGNAM_AL - REGNAM_AX 1998 : REGNAM_AL - REGNAM_EAX))->reg_name, 1999 i.op[op].regs->reg_name, 2000 i.suffix); 2001 #endif 2002 continue; 2003 } 2004 /* Any other register is bad. */ 2005 if (i.types[op] & (Reg | RegMMX | RegXMM 2006 | SReg2 | SReg3 2007 | Control | Debug | Test 2008 | FloatReg | FloatAcc)) 2009 { 2010 as_bad (_("`%%%s' not allowed with `%s%c'"), 2011 i.op[op].regs->reg_name, 2012 i.tm.name, 2013 i.suffix); 2014 return; 2015 } 2016 } 2017 } 2018 else if (i.suffix == LONG_MNEM_SUFFIX) 2019 { 2020 int op; 2021 2022 for (op = i.operands; --op >= 0;) 2023 /* Reject eight bit registers, except where the template 2024 requires them. (eg. movzb) */ 2025 if ((i.types[op] & Reg8) != 0 2026 && (i.tm.operand_types[op] & (Reg16 | Reg32 | Acc)) != 0) 2027 { 2028 as_bad (_("`%%%s' not allowed with `%s%c'"), 2029 i.op[op].regs->reg_name, 2030 i.tm.name, 2031 i.suffix); 2032 return; 2033 } 2034 /* Warn if the e prefix on a general reg is missing. */ 2035 else if ((!quiet_warnings || flag_code == CODE_64BIT) 2036 && (i.types[op] & Reg16) != 0 2037 && (i.tm.operand_types[op] & (Reg32|Acc)) != 0) 2038 { 2039 /* Prohibit these changes in the 64bit mode, since 2040 the lowering is more complicated. */ 2041 if (flag_code == CODE_64BIT) 2042 as_bad (_("Incorrect register `%%%s' used with`%c' suffix"), 2043 i.op[op].regs->reg_name, 2044 i.suffix); 2045 #if REGISTER_WARNINGS 2046 else 2047 as_warn (_("using `%%%s' instead of `%%%s' due to `%c' suffix"), 2048 (i.op[op].regs + REGNAM_EAX - REGNAM_AX)->reg_name, 2049 i.op[op].regs->reg_name, 2050 i.suffix); 2051 #endif 2052 } 2053 /* Warn if the r prefix on a general reg is missing. */ 2054 else if ((i.types[op] & Reg64) != 0 2055 && (i.tm.operand_types[op] & (Reg32|Acc)) != 0) 2056 { 2057 as_bad (_("Incorrect register `%%%s' used with`%c' suffix"), 2058 i.op[op].regs->reg_name, 2059 i.suffix); 2060 } 2061 } 2062 else if (i.suffix == QWORD_MNEM_SUFFIX) 2063 { 2064 int op; 2065 2066 for (op = i.operands; --op >= 0; ) 2067 /* Reject eight bit registers, except where the template 2068 requires them. (eg. movzb) */ 2069 if ((i.types[op] & Reg8) != 0 2070 && (i.tm.operand_types[op] & (Reg16|Reg32|Acc)) != 0) 2071 { 2072 as_bad (_("`%%%s' not allowed with `%s%c'"), 2073 i.op[op].regs->reg_name, 2074 i.tm.name, 2075 i.suffix); 2076 return; 2077 } 2078 /* Warn if the e prefix on a general reg is missing. */ 2079 else if (((i.types[op] & Reg16) != 0 2080 || (i.types[op] & Reg32) != 0) 2081 && (i.tm.operand_types[op] & (Reg32|Acc)) != 0) 2082 { 2083 /* Prohibit these changes in the 64bit mode, since 2084 the lowering is more complicated. */ 2085 as_bad (_("Incorrect register `%%%s' used with`%c' suffix"), 2086 i.op[op].regs->reg_name, 2087 i.suffix); 2088 } 2089 } 2090 else if (i.suffix == WORD_MNEM_SUFFIX) 2091 { 2092 int op; 2093 for (op = i.operands; --op >= 0;) 2094 /* Reject eight bit registers, except where the template 2095 requires them. (eg. movzb) */ 2096 if ((i.types[op] & Reg8) != 0 2097 && (i.tm.operand_types[op] & (Reg16|Reg32|Acc)) != 0) 2098 { 2099 as_bad (_("`%%%s' not allowed with `%s%c'"), 2100 i.op[op].regs->reg_name, 2101 i.tm.name, 2102 i.suffix); 2103 return; 2104 } 2105 /* Warn if the e prefix on a general reg is present. */ 2106 else if ((!quiet_warnings || flag_code == CODE_64BIT) 2107 && (i.types[op] & Reg32) != 0 2108 && (i.tm.operand_types[op] & (Reg16|Acc)) != 0) 2109 { 2110 /* Prohibit these changes in the 64bit mode, since 2111 the lowering is more complicated. */ 2112 if (flag_code == CODE_64BIT) 2113 as_bad (_("Incorrect register `%%%s' used with`%c' suffix"), 2114 i.op[op].regs->reg_name, 2115 i.suffix); 2116 else 2117 #if REGISTER_WARNINGS 2118 as_warn (_("using `%%%s' instead of `%%%s' due to `%c' suffix"), 2119 (i.op[op].regs + REGNAM_AX - REGNAM_EAX)->reg_name, 2120 i.op[op].regs->reg_name, 2121 i.suffix); 2122 #endif 2123 } 2124 } 2125 else if (intel_syntax && (i.tm.opcode_modifier & IgnoreSize)) 2126 /* Do nothing if the instruction is going to ignore the prefix. */ 2127 ; 2128 else 2129 abort (); 2130 } 2131 else if ((i.tm.opcode_modifier & DefaultSize) && !i.suffix) 2132 { 2133 i.suffix = stackop_size; 2134 } 2135 /* Make still unresolved immediate matches conform to size of immediate 2136 given in i.suffix. Note: overlap2 cannot be an immediate! */ 2137 if ((overlap0 & (Imm8 | Imm8S | Imm16 | Imm32 | Imm32S)) 2138 && overlap0 != Imm8 && overlap0 != Imm8S 2139 && overlap0 != Imm16 && overlap0 != Imm32S 2140 && overlap0 != Imm32 && overlap0 != Imm64) 2141 { 2142 if (i.suffix) 2143 { 2144 overlap0 &= (i.suffix == BYTE_MNEM_SUFFIX ? (Imm8 | Imm8S) : 2145 (i.suffix == WORD_MNEM_SUFFIX ? Imm16 : 2146 (i.suffix == QWORD_MNEM_SUFFIX ? Imm64 | Imm32S : Imm32))); 2147 } 2148 else if (overlap0 == (Imm16 | Imm32S | Imm32) 2149 || overlap0 == (Imm16 | Imm32) 2150 || overlap0 == (Imm16 | Imm32S)) 2151 { 2152 overlap0 = 2153 ((flag_code == CODE_16BIT) ^ (i.prefix[DATA_PREFIX] != 0)) ? Imm16 : Imm32S; 2154 } 2155 if (overlap0 != Imm8 && overlap0 != Imm8S 2156 && overlap0 != Imm16 && overlap0 != Imm32S 2157 && overlap0 != Imm32 && overlap0 != Imm64) 2158 { 2159 as_bad (_("no instruction mnemonic suffix given; can't determine immediate size")); 2160 return; 2161 } 2162 } 2163 if ((overlap1 & (Imm8 | Imm8S | Imm16 | Imm32S | Imm32)) 2164 && overlap1 != Imm8 && overlap1 != Imm8S 2165 && overlap1 != Imm16 && overlap1 != Imm32S 2166 && overlap1 != Imm32 && overlap1 != Imm64) 2167 { 2168 if (i.suffix) 2169 { 2170 overlap1 &= (i.suffix == BYTE_MNEM_SUFFIX ? (Imm8 | Imm8S) : 2171 (i.suffix == WORD_MNEM_SUFFIX ? Imm16 : 2172 (i.suffix == QWORD_MNEM_SUFFIX ? Imm64 | Imm32S : Imm32))); 2173 } 2174 else if (overlap1 == (Imm16 | Imm32 | Imm32S) 2175 || overlap1 == (Imm16 | Imm32) 2176 || overlap1 == (Imm16 | Imm32S)) 2177 { 2178 overlap1 = 2179 ((flag_code == CODE_16BIT) ^ (i.prefix[DATA_PREFIX] != 0)) ? Imm16 : Imm32S; 2180 } 2181 if (overlap1 != Imm8 && overlap1 != Imm8S 2182 && overlap1 != Imm16 && overlap1 != Imm32S 2183 && overlap1 != Imm32 && overlap1 != Imm64) 2184 { 2185 as_bad (_("no instruction mnemonic suffix given; can't determine immediate size %x %c"),overlap1, i.suffix); 2186 return; 2187 } 2188 } 2189 assert ((overlap2 & Imm) == 0); 2190 2191 i.types[0] = overlap0; 2192 if (overlap0 & ImplicitRegister) 2193 i.reg_operands--; 2194 if (overlap0 & Imm1) 2195 i.imm_operands = 0; /* kludge for shift insns. */ 2196 2197 i.types[1] = overlap1; 2198 if (overlap1 & ImplicitRegister) 2199 i.reg_operands--; 2200 2201 i.types[2] = overlap2; 2202 if (overlap2 & ImplicitRegister) 2203 i.reg_operands--; 2204 2205 /* Finalize opcode. First, we change the opcode based on the operand 2206 size given by i.suffix: We need not change things for byte insns. */ 2207 2208 if (!i.suffix && (i.tm.opcode_modifier & W)) 2209 { 2210 as_bad (_("no instruction mnemonic suffix given and no register operands; can't size instruction")); 2211 return; 2212 } 2213 2214 /* For movzx and movsx, need to check the register type. */ 2215 if (intel_syntax 2216 && (i.tm.base_opcode == 0xfb6 || i.tm.base_opcode == 0xfbe)) 2217 if (i.suffix && i.suffix == BYTE_MNEM_SUFFIX) 2218 { 2219 unsigned int prefix = DATA_PREFIX_OPCODE; 2220 2221 if ((i.op[1].regs->reg_type & Reg16) != 0) 2222 if (!add_prefix (prefix)) 2223 return; 2224 } 2225 2226 if (i.suffix && i.suffix != BYTE_MNEM_SUFFIX) 2227 { 2228 /* It's not a byte, select word/dword operation. */ 2229 if (i.tm.opcode_modifier & W) 2230 { 2231 if (i.tm.opcode_modifier & ShortForm) 2232 i.tm.base_opcode |= 8; 2233 else 2234 i.tm.base_opcode |= 1; 2235 } 2236 /* Now select between word & dword operations via the operand 2237 size prefix, except for instructions that will ignore this 2238 prefix anyway. */ 2239 if (i.suffix != QWORD_MNEM_SUFFIX 2240 && (i.suffix == LONG_MNEM_SUFFIX) == (flag_code == CODE_16BIT) 2241 && !(i.tm.opcode_modifier & IgnoreSize)) 2242 { 2243 unsigned int prefix = DATA_PREFIX_OPCODE; 2244 if (i.tm.opcode_modifier & JumpByte) /* jcxz, loop */ 2245 prefix = ADDR_PREFIX_OPCODE; 2246 2247 if (! add_prefix (prefix)) 2248 return; 2249 } 2250 2251 /* Set mode64 for an operand. */ 2252 if (i.suffix == QWORD_MNEM_SUFFIX 2253 && !(i.tm.opcode_modifier & NoRex64)) 2254 { 2255 i.rex.mode64 = 1; 2256 if (flag_code < CODE_64BIT) 2257 { 2258 as_bad (_("64bit operations available only in 64bit modes.")); 2259 return; 2260 } 2261 } 2262 2263 /* Size floating point instruction. */ 2264 if (i.suffix == LONG_MNEM_SUFFIX) 2265 { 2266 if (i.tm.opcode_modifier & FloatMF) 2267 i.tm.base_opcode ^= 4; 2268 } 2269 } 2270 2271 if (i.tm.opcode_modifier & ImmExt) 2272 { 2273 /* These AMD 3DNow! and Intel Katmai New Instructions have an 2274 opcode suffix which is coded in the same place as an 8-bit 2275 immediate field would be. Here we fake an 8-bit immediate 2276 operand from the opcode suffix stored in tm.extension_opcode. */ 2277 2278 expressionS *exp; 2279 2280 assert (i.imm_operands == 0 && i.operands <= 2 && 2 < MAX_OPERANDS); 2281 2282 exp = &im_expressions[i.imm_operands++]; 2283 i.op[i.operands].imms = exp; 2284 i.types[i.operands++] = Imm8; 2285 exp->X_op = O_constant; 2286 exp->X_add_number = i.tm.extension_opcode; 2287 i.tm.extension_opcode = None; 2288 } 2289 2290 /* For insns with operands there are more diddles to do to the opcode. */ 2291 if (i.operands) 2292 { 2293 /* Default segment register this instruction will use 2294 for memory accesses. 0 means unknown. 2295 This is only for optimizing out unnecessary segment overrides. */ 2296 const seg_entry *default_seg = 0; 2297 2298 /* The imul $imm, %reg instruction is converted into 2299 imul $imm, %reg, %reg, and the clr %reg instruction 2300 is converted into xor %reg, %reg. */ 2301 if (i.tm.opcode_modifier & regKludge) 2302 { 2303 unsigned int first_reg_op = (i.types[0] & Reg) ? 0 : 1; 2304 /* Pretend we saw the extra register operand. */ 2305 assert (i.op[first_reg_op + 1].regs == 0); 2306 i.op[first_reg_op + 1].regs = i.op[first_reg_op].regs; 2307 i.types[first_reg_op + 1] = i.types[first_reg_op]; 2308 i.reg_operands = 2; 2309 } 2310 2311 if (i.tm.opcode_modifier & ShortForm) 2312 { 2313 /* The register or float register operand is in operand 0 or 1. */ 2314 unsigned int op = (i.types[0] & (Reg | FloatReg)) ? 0 : 1; 2315 /* Register goes in low 3 bits of opcode. */ 2316 i.tm.base_opcode |= i.op[op].regs->reg_num; 2317 if (i.op[op].regs->reg_flags & RegRex) 2318 i.rex.extZ = 1; 2319 if (!quiet_warnings && (i.tm.opcode_modifier & Ugh) != 0) 2320 { 2321 /* Warn about some common errors, but press on regardless. 2322 The first case can be generated by gcc (<= 2.8.1). */ 2323 if (i.operands == 2) 2324 { 2325 /* Reversed arguments on faddp, fsubp, etc. */ 2326 as_warn (_("translating to `%s %%%s,%%%s'"), i.tm.name, 2327 i.op[1].regs->reg_name, 2328 i.op[0].regs->reg_name); 2329 } 2330 else 2331 { 2332 /* Extraneous `l' suffix on fp insn. */ 2333 as_warn (_("translating to `%s %%%s'"), i.tm.name, 2334 i.op[0].regs->reg_name); 2335 } 2336 } 2337 } 2338 else if (i.tm.opcode_modifier & Modrm) 2339 { 2340 /* The opcode is completed (modulo i.tm.extension_opcode which 2341 must be put into the modrm byte). 2342 Now, we make the modrm & index base bytes based on all the 2343 info we've collected. */ 2344 2345 /* i.reg_operands MUST be the number of real register operands; 2346 implicit registers do not count. */ 2347 if (i.reg_operands == 2) 2348 { 2349 unsigned int source, dest; 2350 source = ((i.types[0] 2351 & (Reg | RegMMX | RegXMM 2352 | SReg2 | SReg3 2353 | Control | Debug | Test)) 2354 ? 0 : 1); 2355 dest = source + 1; 2356 2357 i.rm.mode = 3; 2358 /* One of the register operands will be encoded in the 2359 i.tm.reg field, the other in the combined i.tm.mode 2360 and i.tm.regmem fields. If no form of this 2361 instruction supports a memory destination operand, 2362 then we assume the source operand may sometimes be 2363 a memory operand and so we need to store the 2364 destination in the i.rm.reg field. */ 2365 if ((i.tm.operand_types[dest] & AnyMem) == 0) 2366 { 2367 i.rm.reg = i.op[dest].regs->reg_num; 2368 i.rm.regmem = i.op[source].regs->reg_num; 2369 if (i.op[dest].regs->reg_flags & RegRex) 2370 i.rex.extX = 1; 2371 if (i.op[source].regs->reg_flags & RegRex) 2372 i.rex.extZ = 1; 2373 } 2374 else 2375 { 2376 i.rm.reg = i.op[source].regs->reg_num; 2377 i.rm.regmem = i.op[dest].regs->reg_num; 2378 if (i.op[dest].regs->reg_flags & RegRex) 2379 i.rex.extZ = 1; 2380 if (i.op[source].regs->reg_flags & RegRex) 2381 i.rex.extX = 1; 2382 } 2383 } 2384 else 2385 { /* If it's not 2 reg operands... */ 2386 if (i.mem_operands) 2387 { 2388 unsigned int fake_zero_displacement = 0; 2389 unsigned int op = ((i.types[0] & AnyMem) 2390 ? 0 2391 : (i.types[1] & AnyMem) ? 1 : 2); 2392 2393 default_seg = &ds; 2394 2395 if (! i.base_reg) 2396 { 2397 i.rm.mode = 0; 2398 if (! i.disp_operands) 2399 fake_zero_displacement = 1; 2400 if (! i.index_reg) 2401 { 2402 /* Operand is just <disp> */ 2403 if ((flag_code == CODE_16BIT) ^ (i.prefix[ADDR_PREFIX] != 0)) 2404 { 2405 i.rm.regmem = NO_BASE_REGISTER_16; 2406 i.types[op] &= ~Disp; 2407 i.types[op] |= Disp16; 2408 } 2409 else if (flag_code != CODE_64BIT) 2410 { 2411 i.rm.regmem = NO_BASE_REGISTER; 2412 i.types[op] &= ~Disp; 2413 i.types[op] |= Disp32; 2414 } 2415 else 2416 { 2417 /* 64bit mode overwrites the 32bit 2418 absolute addressing by RIP relative 2419 addressing and absolute addressing 2420 is encoded by one of the redundant 2421 SIB forms. */ 2422 2423 i.rm.regmem = ESCAPE_TO_TWO_BYTE_ADDRESSING; 2424 i.sib.base = NO_BASE_REGISTER; 2425 i.sib.index = NO_INDEX_REGISTER; 2426 i.types[op] &= ~Disp; 2427 i.types[op] |= Disp32S; 2428 } 2429 } 2430 else /* ! i.base_reg && i.index_reg */ 2431 { 2432 i.sib.index = i.index_reg->reg_num; 2433 i.sib.base = NO_BASE_REGISTER; 2434 i.sib.scale = i.log2_scale_factor; 2435 i.rm.regmem = ESCAPE_TO_TWO_BYTE_ADDRESSING; 2436 i.types[op] &= ~Disp; 2437 if (flag_code != CODE_64BIT) 2438 i.types[op] |= Disp32; /* Must be 32 bit */ 2439 else 2440 i.types[op] |= Disp32S; 2441 if (i.index_reg->reg_flags & RegRex) 2442 i.rex.extY = 1; 2443 } 2444 } 2445 /* RIP addressing for 64bit mode. */ 2446 else if (i.base_reg->reg_type == BaseIndex) 2447 { 2448 i.rm.regmem = NO_BASE_REGISTER; 2449 i.types[op] &= ~Disp; 2450 i.types[op] |= Disp32S; 2451 i.flags[op] = Operand_PCrel; 2452 } 2453 else if (i.base_reg->reg_type & Reg16) 2454 { 2455 switch (i.base_reg->reg_num) 2456 { 2457 case 3: /* (%bx) */ 2458 if (! i.index_reg) 2459 i.rm.regmem = 7; 2460 else /* (%bx,%si) -> 0, or (%bx,%di) -> 1 */ 2461 i.rm.regmem = i.index_reg->reg_num - 6; 2462 break; 2463 case 5: /* (%bp) */ 2464 default_seg = &ss; 2465 if (! i.index_reg) 2466 { 2467 i.rm.regmem = 6; 2468 if ((i.types[op] & Disp) == 0) 2469 { 2470 /* fake (%bp) into 0(%bp) */ 2471 i.types[op] |= Disp8; 2472 fake_zero_displacement = 1; 2473 } 2474 } 2475 else /* (%bp,%si) -> 2, or (%bp,%di) -> 3 */ 2476 i.rm.regmem = i.index_reg->reg_num - 6 + 2; 2477 break; 2478 default: /* (%si) -> 4 or (%di) -> 5 */ 2479 i.rm.regmem = i.base_reg->reg_num - 6 + 4; 2480 } 2481 i.rm.mode = mode_from_disp_size (i.types[op]); 2482 } 2483 else /* i.base_reg and 32/64 bit mode */ 2484 { 2485 if (flag_code == CODE_64BIT 2486 && (i.types[op] & Disp)) 2487 { 2488 if (i.types[op] & Disp8) 2489 i.types[op] = Disp8 | Disp32S; 2490 else 2491 i.types[op] = Disp32S; 2492 } 2493 i.rm.regmem = i.base_reg->reg_num; 2494 if (i.base_reg->reg_flags & RegRex) 2495 i.rex.extZ = 1; 2496 i.sib.base = i.base_reg->reg_num; 2497 /* x86-64 ignores REX prefix bit here to avoid 2498 decoder complications. */ 2499 if ((i.base_reg->reg_num & 7) == EBP_REG_NUM) 2500 { 2501 default_seg = &ss; 2502 if (i.disp_operands == 0) 2503 { 2504 fake_zero_displacement = 1; 2505 i.types[op] |= Disp8; 2506 } 2507 } 2508 else if (i.base_reg->reg_num == ESP_REG_NUM) 2509 { 2510 default_seg = &ss; 2511 } 2512 i.sib.scale = i.log2_scale_factor; 2513 if (! i.index_reg) 2514 { 2515 /* <disp>(%esp) becomes two byte modrm 2516 with no index register. We've already 2517 stored the code for esp in i.rm.regmem 2518 ie. ESCAPE_TO_TWO_BYTE_ADDRESSING. Any 2519 base register besides %esp will not use 2520 the extra modrm byte. */ 2521 i.sib.index = NO_INDEX_REGISTER; 2522 #if ! SCALE1_WHEN_NO_INDEX 2523 /* Another case where we force the second 2524 modrm byte. */ 2525 if (i.log2_scale_factor) 2526 i.rm.regmem = ESCAPE_TO_TWO_BYTE_ADDRESSING; 2527 #endif 2528 } 2529 else 2530 { 2531 i.sib.index = i.index_reg->reg_num; 2532 i.rm.regmem = ESCAPE_TO_TWO_BYTE_ADDRESSING; 2533 if (i.index_reg->reg_flags & RegRex) 2534 i.rex.extY = 1; 2535 } 2536 i.rm.mode = mode_from_disp_size (i.types[op]); 2537 } 2538 2539 if (fake_zero_displacement) 2540 { 2541 /* Fakes a zero displacement assuming that i.types[op] 2542 holds the correct displacement size. */ 2543 expressionS *exp; 2544 2545 assert (i.op[op].disps == 0); 2546 exp = &disp_expressions[i.disp_operands++]; 2547 i.op[op].disps = exp; 2548 exp->X_op = O_constant; 2549 exp->X_add_number = 0; 2550 exp->X_add_symbol = (symbolS *) 0; 2551 exp->X_op_symbol = (symbolS *) 0; 2552 } 2553 } 2554 2555 /* Fill in i.rm.reg or i.rm.regmem field with register 2556 operand (if any) based on i.tm.extension_opcode. 2557 Again, we must be careful to make sure that 2558 segment/control/debug/test/MMX registers are coded 2559 into the i.rm.reg field. */ 2560 if (i.reg_operands) 2561 { 2562 unsigned int op = 2563 ((i.types[0] 2564 & (Reg | RegMMX | RegXMM 2565 | SReg2 | SReg3 2566 | Control | Debug | Test)) 2567 ? 0 2568 : ((i.types[1] 2569 & (Reg | RegMMX | RegXMM 2570 | SReg2 | SReg3 2571 | Control | Debug | Test)) 2572 ? 1 2573 : 2)); 2574 /* If there is an extension opcode to put here, the 2575 register number must be put into the regmem field. */ 2576 if (i.tm.extension_opcode != None) 2577 { 2578 i.rm.regmem = i.op[op].regs->reg_num; 2579 if (i.op[op].regs->reg_flags & RegRex) 2580 i.rex.extZ = 1; 2581 } 2582 else 2583 { 2584 i.rm.reg = i.op[op].regs->reg_num; 2585 if (i.op[op].regs->reg_flags & RegRex) 2586 i.rex.extX = 1; 2587 } 2588 2589 /* Now, if no memory operand has set i.rm.mode = 0, 1, 2 2590 we must set it to 3 to indicate this is a register 2591 operand in the regmem field. */ 2592 if (!i.mem_operands) 2593 i.rm.mode = 3; 2594 } 2595 2596 /* Fill in i.rm.reg field with extension opcode (if any). */ 2597 if (i.tm.extension_opcode != None) 2598 i.rm.reg = i.tm.extension_opcode; 2599 } 2600 } 2601 else if (i.tm.opcode_modifier & (Seg2ShortForm | Seg3ShortForm)) 2602 { 2603 if (i.tm.base_opcode == POP_SEG_SHORT 2604 && i.op[0].regs->reg_num == 1) 2605 { 2606 as_bad (_("you can't `pop %%cs'")); 2607 return; 2608 } 2609 i.tm.base_opcode |= (i.op[0].regs->reg_num << 3); 2610 if (i.op[0].regs->reg_flags & RegRex) 2611 i.rex.extZ = 1; 2612 } 2613 else if ((i.tm.base_opcode & ~(D|W)) == MOV_AX_DISP32) 2614 { 2615 default_seg = &ds; 2616 } 2617 else if ((i.tm.opcode_modifier & IsString) != 0) 2618 { 2619 /* For the string instructions that allow a segment override 2620 on one of their operands, the default segment is ds. */ 2621 default_seg = &ds; 2622 } 2623 2624 /* If a segment was explicitly specified, 2625 and the specified segment is not the default, 2626 use an opcode prefix to select it. 2627 If we never figured out what the default segment is, 2628 then default_seg will be zero at this point, 2629 and the specified segment prefix will always be used. */ 2630 if ((i.seg[0]) && (i.seg[0] != default_seg)) 2631 { 2632 if (! add_prefix (i.seg[0]->seg_prefix)) 2633 return; 2634 } 2635 } 2636 else if (!quiet_warnings && (i.tm.opcode_modifier & Ugh) != 0) 2637 { 2638 /* UnixWare fsub no args is alias for fsubp, fadd -> faddp, etc. */ 2639 as_warn (_("translating to `%sp'"), i.tm.name); 2640 } 2641 } 1421 } 1422 else if (!quiet_warnings && (i.tm.opcode_modifier & Ugh) != 0) 1423 { 1424 /* UnixWare fsub no args is alias for fsubp, fadd -> faddp, etc. */ 1425 as_warn (_("translating to `%sp'"), i.tm.name); 1426 } 2642 1427 2643 1428 /* Handle conversion of 'int $3' --> special int3 insn. */ … … 2658 1443 } 2659 1444 2660 if (i.tm.opcode_modifier & Rex64) 2661 i.rex.mode64 = 1; 2662 2663 /* For 8bit registers we would need an empty rex prefix. 2664 Also in the case instruction is already having prefix, 2665 we need to convert old registers to new ones. */ 2666 2667 if (((i.types[0] & Reg8) && (i.op[0].regs->reg_flags & RegRex64)) 2668 || ((i.types[1] & Reg8) && (i.op[1].regs->reg_flags & RegRex64)) 2669 || ((i.rex.mode64 || i.rex.extX || i.rex.extY || i.rex.extZ || i.rex.empty) 2670 && ((i.types[0] & Reg8) || (i.types[1] & Reg8)))) 1445 if ((i.tm.opcode_modifier & Rex64) != 0) 1446 i.rex |= REX_MODE64; 1447 1448 /* For 8 bit registers we need an empty rex prefix. Also if the 1449 instruction already has a prefix, we need to convert old 1450 registers to new ones. */ 1451 1452 if (((i.types[0] & Reg8) != 0 1453 && (i.op[0].regs->reg_flags & RegRex64) != 0) 1454 || ((i.types[1] & Reg8) != 0 1455 && (i.op[1].regs->reg_flags & RegRex64) != 0) 1456 || (((i.types[0] & Reg8) != 0 || (i.types[1] & Reg8) != 0) 1457 && i.rex != 0)) 2671 1458 { 2672 1459 int x; 2673 i.rex.empty = 1; 1460 1461 i.rex |= REX_OPCODE; 2674 1462 for (x = 0; x < 2; x++) 2675 1463 { 2676 /* Look for 8 bit operand that does useold registers. */2677 if ( i.types[x] & Reg82678 && !(i.op[x].regs->reg_flags & RegRex64))1464 /* Look for 8 bit operand that uses old registers. */ 1465 if ((i.types[x] & Reg8) != 0 1466 && (i.op[x].regs->reg_flags & RegRex64) == 0) 2679 1467 { 2680 1468 /* In case it is "hi" register, give up. */ 2681 1469 if (i.op[x].regs->reg_num > 3) 2682 as_bad (_(" Can't encode registers '%%%s' in theinstruction requiring REX prefix.\n"),1470 as_bad (_("can't encode register '%%%s' in an instruction requiring REX prefix.\n"), 2683 1471 i.op[x].regs->reg_name); 2684 1472 2685 1473 /* Otherwise it is equivalent to the extended register. 2686 Since the encoding don't change this is merely cosmetical2687 1474 Since the encoding doesn't change this is merely 1475 cosmetic cleanup for debug output. */ 2688 1476 2689 1477 i.op[x].regs = i.op[x].regs + 8; … … 2692 1480 } 2693 1481 2694 if (i.rex.mode64 || i.rex.extX || i.rex.extY || i.rex.extZ || i.rex.empty) 2695 add_prefix (0x40 2696 | (i.rex.mode64 ? 8 : 0) 2697 | (i.rex.extX ? 4 : 0) 2698 | (i.rex.extY ? 2 : 0) 2699 | (i.rex.extZ ? 1 : 0)); 1482 if (i.rex != 0) 1483 add_prefix (REX_OPCODE | i.rex); 2700 1484 2701 1485 /* We are ready to output the insn. */ 2702 { 2703 register char *p; 2704 2705 /* Tie dwarf2 debug info to the address at the start of the insn. 2706 We can't do this after the insn has been output as the current 2707 frag may have been closed off. eg. by frag_var. */ 2708 dwarf2_emit_insn (0); 2709 2710 /* Output jumps. */ 2711 if (i.tm.opcode_modifier & Jump) 1486 output_insn (); 1487 } 1488 1489 static char * 1490 parse_insn (line, mnemonic) 1491 char *line; 1492 char *mnemonic; 1493 { 1494 char *l = line; 1495 char *token_start = l; 1496 char *mnem_p; 1497 1498 /* Non-zero if we found a prefix only acceptable with string insns. */ 1499 const char *expecting_string_instruction = NULL; 1500 1501 while (1) 1502 { 1503 mnem_p = mnemonic; 1504 while ((*mnem_p = mnemonic_chars[(unsigned char) *l]) != 0) 1505 { 1506 mnem_p++; 1507 if (mnem_p >= mnemonic + MAX_MNEM_SIZE) 1508 { 1509 as_bad (_("no such instruction: `%s'"), token_start); 1510 return NULL; 1511 } 1512 l++; 1513 } 1514 if (!is_space_char (*l) 1515 && *l != END_OF_INSN 1516 && *l != PREFIX_SEPARATOR 1517 && *l != ',') 1518 { 1519 as_bad (_("invalid character %s in mnemonic"), 1520 output_invalid (*l)); 1521 return NULL; 1522 } 1523 if (token_start == l) 1524 { 1525 if (*l == PREFIX_SEPARATOR) 1526 as_bad (_("expecting prefix; got nothing")); 1527 else 1528 as_bad (_("expecting mnemonic; got nothing")); 1529 return NULL; 1530 } 1531 1532 /* Look up instruction (or prefix) via hash table. */ 1533 current_templates = hash_find (op_hash, mnemonic); 1534 1535 if (*l != END_OF_INSN 1536 && (!is_space_char (*l) || l[1] != END_OF_INSN) 1537 && current_templates 1538 && (current_templates->start->opcode_modifier & IsPrefix)) 1539 { 1540 /* If we are in 16-bit mode, do not allow addr16 or data16. 1541 Similarly, in 32-bit mode, do not allow addr32 or data32. */ 1542 if ((current_templates->start->opcode_modifier & (Size16 | Size32)) 1543 && flag_code != CODE_64BIT 1544 && (((current_templates->start->opcode_modifier & Size32) != 0) 1545 ^ (flag_code == CODE_16BIT))) 1546 { 1547 as_bad (_("redundant %s prefix"), 1548 current_templates->start->name); 1549 return NULL; 1550 } 1551 /* Add prefix, checking for repeated prefixes. */ 1552 switch (add_prefix (current_templates->start->base_opcode)) 1553 { 1554 case 0: 1555 return NULL; 1556 case 2: 1557 expecting_string_instruction = current_templates->start->name; 1558 break; 1559 } 1560 /* Skip past PREFIX_SEPARATOR and reset token_start. */ 1561 token_start = ++l; 1562 } 1563 else 1564 break; 1565 } 1566 1567 if (!current_templates) 1568 { 1569 /* See if we can get a match by trimming off a suffix. */ 1570 switch (mnem_p[-1]) 1571 { 1572 case WORD_MNEM_SUFFIX: 1573 case BYTE_MNEM_SUFFIX: 1574 case QWORD_MNEM_SUFFIX: 1575 i.suffix = mnem_p[-1]; 1576 mnem_p[-1] = '\0'; 1577 current_templates = hash_find (op_hash, mnemonic); 1578 break; 1579 case SHORT_MNEM_SUFFIX: 1580 case LONG_MNEM_SUFFIX: 1581 if (!intel_syntax) 1582 { 1583 i.suffix = mnem_p[-1]; 1584 mnem_p[-1] = '\0'; 1585 current_templates = hash_find (op_hash, mnemonic); 1586 } 1587 break; 1588 1589 /* Intel Syntax. */ 1590 case 'd': 1591 if (intel_syntax) 1592 { 1593 if (intel_float_operand (mnemonic)) 1594 i.suffix = SHORT_MNEM_SUFFIX; 1595 else 1596 i.suffix = LONG_MNEM_SUFFIX; 1597 mnem_p[-1] = '\0'; 1598 current_templates = hash_find (op_hash, mnemonic); 1599 } 1600 break; 1601 } 1602 if (!current_templates) 1603 { 1604 as_bad (_("no such instruction: `%s'"), token_start); 1605 return NULL; 1606 } 1607 } 1608 1609 if (current_templates->start->opcode_modifier & (Jump | JumpByte)) 1610 { 1611 /* Check for a branch hint. We allow ",pt" and ",pn" for 1612 predict taken and predict not taken respectively. 1613 I'm not sure that branch hints actually do anything on loop 1614 and jcxz insns (JumpByte) for current Pentium4 chips. They 1615 may work in the future and it doesn't hurt to accept them 1616 now. */ 1617 if (l[0] == ',' && l[1] == 'p') 1618 { 1619 if (l[2] == 't') 1620 { 1621 if (!add_prefix (DS_PREFIX_OPCODE)) 1622 return NULL; 1623 l += 3; 1624 } 1625 else if (l[2] == 'n') 1626 { 1627 if (!add_prefix (CS_PREFIX_OPCODE)) 1628 return NULL; 1629 l += 3; 1630 } 1631 } 1632 } 1633 /* Any other comma loses. */ 1634 if (*l == ',') 1635 { 1636 as_bad (_("invalid character %s in mnemonic"), 1637 output_invalid (*l)); 1638 return NULL; 1639 } 1640 1641 /* Check if instruction is supported on specified architecture. */ 1642 if ((current_templates->start->cpu_flags & ~(Cpu64 | CpuNo64)) 1643 & ~(cpu_arch_flags & ~(Cpu64 | CpuNo64))) 1644 { 1645 as_warn (_("`%s' is not supported on `%s'"), 1646 current_templates->start->name, cpu_arch_name); 1647 } 1648 else if ((Cpu386 & ~cpu_arch_flags) && (flag_code != CODE_16BIT)) 1649 { 1650 as_warn (_("use .code16 to ensure correct addressing mode")); 1651 } 1652 1653 /* Check for rep/repne without a string instruction. */ 1654 if (expecting_string_instruction 1655 && !(current_templates->start->opcode_modifier & IsString)) 1656 { 1657 as_bad (_("expecting string instruction after `%s'"), 1658 expecting_string_instruction); 1659 return NULL; 1660 } 1661 1662 return l; 1663 } 1664 1665 static char * 1666 parse_operands (l, mnemonic) 1667 char *l; 1668 const char *mnemonic; 1669 { 1670 char *token_start; 1671 1672 /* 1 if operand is pending after ','. */ 1673 unsigned int expecting_operand = 0; 1674 1675 /* Non-zero if operand parens not balanced. */ 1676 unsigned int paren_not_balanced; 1677 1678 while (*l != END_OF_INSN) 1679 { 1680 /* Skip optional white space before operand. */ 1681 if (is_space_char (*l)) 1682 ++l; 1683 if (!is_operand_char (*l) && *l != END_OF_INSN) 1684 { 1685 as_bad (_("invalid character %s before operand %d"), 1686 output_invalid (*l), 1687 i.operands + 1); 1688 return NULL; 1689 } 1690 token_start = l; /* after white space */ 1691 paren_not_balanced = 0; 1692 while (paren_not_balanced || *l != ',') 1693 { 1694 if (*l == END_OF_INSN) 1695 { 1696 if (paren_not_balanced) 1697 { 1698 if (!intel_syntax) 1699 as_bad (_("unbalanced parenthesis in operand %d."), 1700 i.operands + 1); 1701 else 1702 as_bad (_("unbalanced brackets in operand %d."), 1703 i.operands + 1); 1704 return NULL; 1705 } 1706 else 1707 break; /* we are done */ 1708 } 1709 else if (!is_operand_char (*l) && !is_space_char (*l)) 1710 { 1711 as_bad (_("invalid character %s in operand %d"), 1712 output_invalid (*l), 1713 i.operands + 1); 1714 return NULL; 1715 } 1716 if (!intel_syntax) 1717 { 1718 if (*l == '(') 1719 ++paren_not_balanced; 1720 if (*l == ')') 1721 --paren_not_balanced; 1722 } 1723 else 1724 { 1725 if (*l == '[') 1726 ++paren_not_balanced; 1727 if (*l == ']') 1728 --paren_not_balanced; 1729 } 1730 l++; 1731 } 1732 if (l != token_start) 1733 { /* Yes, we've read in another operand. */ 1734 unsigned int operand_ok; 1735 this_operand = i.operands++; 1736 if (i.operands > MAX_OPERANDS) 1737 { 1738 as_bad (_("spurious operands; (%d operands/instruction max)"), 1739 MAX_OPERANDS); 1740 return NULL; 1741 } 1742 /* Now parse operand adding info to 'i' as we go along. */ 1743 END_STRING_AND_SAVE (l); 1744 1745 if (intel_syntax) 1746 operand_ok = 1747 i386_intel_operand (token_start, 1748 intel_float_operand (mnemonic)); 1749 else 1750 operand_ok = i386_operand (token_start); 1751 1752 RESTORE_END_STRING (l); 1753 if (!operand_ok) 1754 return NULL; 1755 } 1756 else 1757 { 1758 if (expecting_operand) 1759 { 1760 expecting_operand_after_comma: 1761 as_bad (_("expecting operand after ','; got nothing")); 1762 return NULL; 1763 } 1764 if (*l == ',') 1765 { 1766 as_bad (_("expecting operand before ','; got nothing")); 1767 return NULL; 1768 } 1769 } 1770 1771 /* Now *l must be either ',' or END_OF_INSN. */ 1772 if (*l == ',') 1773 { 1774 if (*++l == END_OF_INSN) 1775 { 1776 /* Just skip it, if it's \n complain. */ 1777 goto expecting_operand_after_comma; 1778 } 1779 expecting_operand = 1; 1780 } 1781 } 1782 return l; 1783 } 1784 1785 static void 1786 swap_operands () 1787 { 1788 union i386_op temp_op; 1789 unsigned int temp_type; 1790 RELOC_ENUM temp_reloc; 1791 int xchg1 = 0; 1792 int xchg2 = 0; 1793 1794 if (i.operands == 2) 1795 { 1796 xchg1 = 0; 1797 xchg2 = 1; 1798 } 1799 else if (i.operands == 3) 1800 { 1801 xchg1 = 0; 1802 xchg2 = 2; 1803 } 1804 temp_type = i.types[xchg2]; 1805 i.types[xchg2] = i.types[xchg1]; 1806 i.types[xchg1] = temp_type; 1807 temp_op = i.op[xchg2]; 1808 i.op[xchg2] = i.op[xchg1]; 1809 i.op[xchg1] = temp_op; 1810 temp_reloc = i.reloc[xchg2]; 1811 i.reloc[xchg2] = i.reloc[xchg1]; 1812 i.reloc[xchg1] = temp_reloc; 1813 1814 if (i.mem_operands == 2) 1815 { 1816 const seg_entry *temp_seg; 1817 temp_seg = i.seg[0]; 1818 i.seg[0] = i.seg[1]; 1819 i.seg[1] = temp_seg; 1820 } 1821 } 1822 1823 /* Try to ensure constant immediates are represented in the smallest 1824 opcode possible. */ 1825 static void 1826 optimize_imm () 1827 { 1828 char guess_suffix = 0; 1829 int op; 1830 1831 if (i.suffix) 1832 guess_suffix = i.suffix; 1833 else if (i.reg_operands) 1834 { 1835 /* Figure out a suffix from the last register operand specified. 1836 We can't do this properly yet, ie. excluding InOutPortReg, 1837 but the following works for instructions with immediates. 1838 In any case, we can't set i.suffix yet. */ 1839 for (op = i.operands; --op >= 0;) 1840 if (i.types[op] & Reg) 1841 { 1842 if (i.types[op] & Reg8) 1843 guess_suffix = BYTE_MNEM_SUFFIX; 1844 else if (i.types[op] & Reg16) 1845 guess_suffix = WORD_MNEM_SUFFIX; 1846 else if (i.types[op] & Reg32) 1847 guess_suffix = LONG_MNEM_SUFFIX; 1848 else if (i.types[op] & Reg64) 1849 guess_suffix = QWORD_MNEM_SUFFIX; 1850 break; 1851 } 1852 } 1853 else if ((flag_code == CODE_16BIT) ^ (i.prefix[DATA_PREFIX] != 0)) 1854 guess_suffix = WORD_MNEM_SUFFIX; 1855 1856 for (op = i.operands; --op >= 0;) 1857 if (i.types[op] & Imm) 2712 1858 { 2713 int code16; 2714 int prefix; 2715 2716 code16 = 0; 2717 if (flag_code == CODE_16BIT) 2718 code16 = CODE16; 2719 2720 prefix = 0; 2721 if (i.prefix[DATA_PREFIX]) 1859 switch (i.op[op].imms->X_op) 2722 1860 { 2723 prefix = 1; 2724 i.prefixes -= 1; 2725 code16 ^= CODE16; 1861 case O_constant: 1862 /* If a suffix is given, this operand may be shortened. */ 1863 switch (guess_suffix) 1864 { 1865 case LONG_MNEM_SUFFIX: 1866 i.types[op] |= Imm32 | Imm64; 1867 break; 1868 case WORD_MNEM_SUFFIX: 1869 i.types[op] |= Imm16 | Imm32S | Imm32 | Imm64; 1870 break; 1871 case BYTE_MNEM_SUFFIX: 1872 i.types[op] |= Imm16 | Imm8 | Imm8S | Imm32S | Imm32 | Imm64; 1873 break; 1874 } 1875 1876 /* If this operand is at most 16 bits, convert it 1877 to a signed 16 bit number before trying to see 1878 whether it will fit in an even smaller size. 1879 This allows a 16-bit operand such as $0xffe0 to 1880 be recognised as within Imm8S range. */ 1881 if ((i.types[op] & Imm16) 1882 && (i.op[op].imms->X_add_number & ~(offsetT) 0xffff) == 0) 1883 { 1884 i.op[op].imms->X_add_number = 1885 (((i.op[op].imms->X_add_number & 0xffff) ^ 0x8000) - 0x8000); 1886 } 1887 if ((i.types[op] & Imm32) 1888 && ((i.op[op].imms->X_add_number & ~(((offsetT) 2 << 31) - 1)) 1889 == 0)) 1890 { 1891 i.op[op].imms->X_add_number = ((i.op[op].imms->X_add_number 1892 ^ ((offsetT) 1 << 31)) 1893 - ((offsetT) 1 << 31)); 1894 } 1895 i.types[op] |= smallest_imm_type (i.op[op].imms->X_add_number); 1896 1897 /* We must avoid matching of Imm32 templates when 64bit 1898 only immediate is available. */ 1899 if (guess_suffix == QWORD_MNEM_SUFFIX) 1900 i.types[op] &= ~Imm32; 1901 break; 1902 1903 case O_absent: 1904 case O_register: 1905 abort (); 1906 1907 /* Symbols and expressions. */ 1908 default: 1909 /* Convert symbolic operand to proper sizes for matching. */ 1910 switch (guess_suffix) 1911 { 1912 case QWORD_MNEM_SUFFIX: 1913 i.types[op] = Imm64 | Imm32S; 1914 break; 1915 case LONG_MNEM_SUFFIX: 1916 i.types[op] = Imm32 | Imm64; 1917 break; 1918 case WORD_MNEM_SUFFIX: 1919 i.types[op] = Imm16 | Imm32 | Imm64; 1920 break; 1921 break; 1922 case BYTE_MNEM_SUFFIX: 1923 i.types[op] = Imm8 | Imm8S | Imm16 | Imm32S | Imm32; 1924 break; 1925 break; 1926 } 1927 break; 2726 1928 } 2727 /* Pentium4 branch hints. */ 2728 if (i.prefix[SEG_PREFIX] == CS_PREFIX_OPCODE /* not taken */ 2729 || i.prefix[SEG_PREFIX] == DS_PREFIX_OPCODE /* taken */) 1929 } 1930 } 1931 1932 /* Try to use the smallest displacement type too. */ 1933 static void 1934 optimize_disp () 1935 { 1936 int op; 1937 1938 for (op = i.operands; --op >= 0;) 1939 if ((i.types[op] & Disp) && i.op[op].disps->X_op == O_constant) 1940 { 1941 offsetT disp = i.op[op].disps->X_add_number; 1942 1943 if (i.types[op] & Disp16) 2730 1944 { 2731 prefix++; 2732 i.prefixes--; 1945 /* We know this operand is at most 16 bits, so 1946 convert to a signed 16 bit number before trying 1947 to see whether it will fit in an even smaller 1948 size. */ 1949 1950 disp = (((disp & 0xffff) ^ 0x8000) - 0x8000); 2733 1951 } 2734 if (i.prefix[REX_PREFIX])1952 else if (i.types[op] & Disp32) 2735 1953 { 2736 prefix++; 2737 i.prefixes--; 1954 /* We know this operand is at most 32 bits, so convert to a 1955 signed 32 bit number before trying to see whether it will 1956 fit in an even smaller size. */ 1957 disp &= (((offsetT) 2 << 31) - 1); 1958 disp = (disp ^ ((offsetT) 1 << 31)) - ((addressT) 1 << 31); 2738 1959 } 2739 2740 if (i.prefixes != 0 && !intel_syntax) 2741 as_warn (_("skipping prefixes on this instruction")); 2742 2743 /* It's always a symbol; End frag & setup for relax. 2744 Make sure there is enough room in this frag for the largest 2745 instruction we may generate in md_convert_frag. This is 2 2746 bytes for the opcode and room for the prefix and largest 2747 displacement. */ 2748 frag_grow (prefix + 2 + 4); 2749 /* Prefix and 1 opcode byte go in fr_fix. */ 2750 p = frag_more (prefix + 1); 2751 if (i.prefix[DATA_PREFIX]) 2752 *p++ = DATA_PREFIX_OPCODE; 2753 if (i.prefix[SEG_PREFIX] == CS_PREFIX_OPCODE 2754 || i.prefix[SEG_PREFIX] == DS_PREFIX_OPCODE) 2755 *p++ = i.prefix[SEG_PREFIX]; 2756 if (i.prefix[REX_PREFIX]) 2757 *p++ = i.prefix[REX_PREFIX]; 2758 *p = i.tm.base_opcode; 2759 /* 1 possible extra opcode + displacement go in var part. 2760 Pass reloc in fr_var. */ 2761 frag_var (rs_machine_dependent, 2762 1 + 4, 2763 i.reloc[0], 2764 ((unsigned char) *p == JUMP_PC_RELATIVE 2765 ? ENCODE_RELAX_STATE (UNCOND_JUMP, SMALL) | code16 2766 : ((cpu_arch_flags & Cpu386) != 0 2767 ? ENCODE_RELAX_STATE (COND_JUMP, SMALL) | code16 2768 : ENCODE_RELAX_STATE (COND_JUMP86, SMALL) | code16)), 2769 i.op[0].disps->X_add_symbol, 2770 i.op[0].disps->X_add_number, 2771 p); 1960 if (flag_code == CODE_64BIT) 1961 { 1962 if (fits_in_signed_long (disp)) 1963 i.types[op] |= Disp32S; 1964 if (fits_in_unsigned_long (disp)) 1965 i.types[op] |= Disp32; 1966 } 1967 if ((i.types[op] & (Disp32 | Disp32S | Disp16)) 1968 && fits_in_signed_byte (disp)) 1969 i.types[op] |= Disp8; 2772 1970 } 2773 else if (i.tm.opcode_modifier & (JumpByte | JumpDword)) 1971 } 1972 1973 static int 1974 match_template () 1975 { 1976 /* Points to template once we've found it. */ 1977 const template *t; 1978 unsigned int overlap0, overlap1, overlap2; 1979 unsigned int found_reverse_match; 1980 int suffix_check; 1981 1982 #define MATCH(overlap, given, template) \ 1983 ((overlap & ~JumpAbsolute) \ 1984 && (((given) & (BaseIndex | JumpAbsolute)) \ 1985 == ((overlap) & (BaseIndex | JumpAbsolute)))) 1986 1987 /* If given types r0 and r1 are registers they must be of the same type 1988 unless the expected operand type register overlap is null. 1989 Note that Acc in a template matches every size of reg. */ 1990 #define CONSISTENT_REGISTER_MATCH(m0, g0, t0, m1, g1, t1) \ 1991 (((g0) & Reg) == 0 || ((g1) & Reg) == 0 \ 1992 || ((g0) & Reg) == ((g1) & Reg) \ 1993 || ((((m0) & Acc) ? Reg : (t0)) & (((m1) & Acc) ? Reg : (t1)) & Reg) == 0 ) 1994 1995 overlap0 = 0; 1996 overlap1 = 0; 1997 overlap2 = 0; 1998 found_reverse_match = 0; 1999 suffix_check = (i.suffix == BYTE_MNEM_SUFFIX 2000 ? No_bSuf 2001 : (i.suffix == WORD_MNEM_SUFFIX 2002 ? No_wSuf 2003 : (i.suffix == SHORT_MNEM_SUFFIX 2004 ? No_sSuf 2005 : (i.suffix == LONG_MNEM_SUFFIX 2006 ? No_lSuf 2007 : (i.suffix == QWORD_MNEM_SUFFIX 2008 ? No_qSuf 2009 : (i.suffix == LONG_DOUBLE_MNEM_SUFFIX 2010 ? No_xSuf : 0)))))); 2011 2012 for (t = current_templates->start; 2013 t < current_templates->end; 2014 t++) 2015 { 2016 /* Must have right number of operands. */ 2017 if (i.operands != t->operands) 2018 continue; 2019 2020 /* Check the suffix, except for some instructions in intel mode. */ 2021 if ((t->opcode_modifier & suffix_check) 2022 && !(intel_syntax 2023 && (t->opcode_modifier & IgnoreSize)) 2024 && !(intel_syntax 2025 && t->base_opcode == 0xd9 2026 && (t->extension_opcode == 5 /* 0xd9,5 "fldcw" */ 2027 || t->extension_opcode == 7))) /* 0xd9,7 "f{n}stcw" */ 2028 continue; 2029 2030 /* Do not verify operands when there are none. */ 2031 else if (!t->operands) 2032 { 2033 if (t->cpu_flags & ~cpu_arch_flags) 2034 continue; 2035 /* We've found a match; break out of loop. */ 2036 break; 2037 } 2038 2039 overlap0 = i.types[0] & t->operand_types[0]; 2040 switch (t->operands) 2041 { 2042 case 1: 2043 if (!MATCH (overlap0, i.types[0], t->operand_types[0])) 2044 continue; 2045 break; 2046 case 2: 2047 case 3: 2048 overlap1 = i.types[1] & t->operand_types[1]; 2049 if (!MATCH (overlap0, i.types[0], t->operand_types[0]) 2050 || !MATCH (overlap1, i.types[1], t->operand_types[1]) 2051 || !CONSISTENT_REGISTER_MATCH (overlap0, i.types[0], 2052 t->operand_types[0], 2053 overlap1, i.types[1], 2054 t->operand_types[1])) 2055 { 2056 /* Check if other direction is valid ... */ 2057 if ((t->opcode_modifier & (D | FloatD)) == 0) 2058 continue; 2059 2060 /* Try reversing direction of operands. */ 2061 overlap0 = i.types[0] & t->operand_types[1]; 2062 overlap1 = i.types[1] & t->operand_types[0]; 2063 if (!MATCH (overlap0, i.types[0], t->operand_types[1]) 2064 || !MATCH (overlap1, i.types[1], t->operand_types[0]) 2065 || !CONSISTENT_REGISTER_MATCH (overlap0, i.types[0], 2066 t->operand_types[1], 2067 overlap1, i.types[1], 2068 t->operand_types[0])) 2069 { 2070 /* Does not match either direction. */ 2071 continue; 2072 } 2073 /* found_reverse_match holds which of D or FloatDR 2074 we've found. */ 2075 found_reverse_match = t->opcode_modifier & (D | FloatDR); 2076 } 2077 /* Found a forward 2 operand match here. */ 2078 else if (t->operands == 3) 2079 { 2080 /* Here we make use of the fact that there are no 2081 reverse match 3 operand instructions, and all 3 2082 operand instructions only need to be checked for 2083 register consistency between operands 2 and 3. */ 2084 overlap2 = i.types[2] & t->operand_types[2]; 2085 if (!MATCH (overlap2, i.types[2], t->operand_types[2]) 2086 || !CONSISTENT_REGISTER_MATCH (overlap1, i.types[1], 2087 t->operand_types[1], 2088 overlap2, i.types[2], 2089 t->operand_types[2])) 2090 2091 continue; 2092 } 2093 /* Found either forward/reverse 2 or 3 operand match here: 2094 slip through to break. */ 2095 } 2096 if (t->cpu_flags & ~cpu_arch_flags) 2097 { 2098 found_reverse_match = 0; 2099 continue; 2100 } 2101 /* We've found a match; break out of loop. */ 2102 break; 2103 } 2104 2105 if (t == current_templates->end) 2106 { 2107 /* We found no match. */ 2108 as_bad (_("suffix or operands invalid for `%s'"), 2109 current_templates->start->name); 2110 return 0; 2111 } 2112 2113 if (!quiet_warnings) 2114 { 2115 if (!intel_syntax 2116 && ((i.types[0] & JumpAbsolute) 2117 != (t->operand_types[0] & JumpAbsolute))) 2118 { 2119 as_warn (_("indirect %s without `*'"), t->name); 2120 } 2121 2122 if ((t->opcode_modifier & (IsPrefix | IgnoreSize)) 2123 == (IsPrefix | IgnoreSize)) 2124 { 2125 /* Warn them that a data or address size prefix doesn't 2126 affect assembly of the next line of code. */ 2127 as_warn (_("stand-alone `%s' prefix"), t->name); 2128 } 2129 } 2130 2131 /* Copy the template we found. */ 2132 i.tm = *t; 2133 if (found_reverse_match) 2134 { 2135 /* If we found a reverse match we must alter the opcode 2136 direction bit. found_reverse_match holds bits to change 2137 (different for int & float insns). */ 2138 2139 i.tm.base_opcode ^= found_reverse_match; 2140 2141 i.tm.operand_types[0] = t->operand_types[1]; 2142 i.tm.operand_types[1] = t->operand_types[0]; 2143 } 2144 2145 return 1; 2146 } 2147 2148 static int 2149 check_string () 2150 { 2151 int mem_op = (i.types[0] & AnyMem) ? 0 : 1; 2152 if ((i.tm.operand_types[mem_op] & EsSeg) != 0) 2153 { 2154 if (i.seg[0] != NULL && i.seg[0] != &es) 2155 { 2156 as_bad (_("`%s' operand %d must use `%%es' segment"), 2157 i.tm.name, 2158 mem_op + 1); 2159 return 0; 2160 } 2161 /* There's only ever one segment override allowed per instruction. 2162 This instruction possibly has a legal segment override on the 2163 second operand, so copy the segment to where non-string 2164 instructions store it, allowing common code. */ 2165 i.seg[0] = i.seg[1]; 2166 } 2167 else if ((i.tm.operand_types[mem_op + 1] & EsSeg) != 0) 2168 { 2169 if (i.seg[1] != NULL && i.seg[1] != &es) 2170 { 2171 as_bad (_("`%s' operand %d must use `%%es' segment"), 2172 i.tm.name, 2173 mem_op + 2); 2174 return 0; 2175 } 2176 } 2177 return 1; 2178 } 2179 2180 static int 2181 process_suffix () 2182 { 2183 /* If matched instruction specifies an explicit instruction mnemonic 2184 suffix, use it. */ 2185 if (i.tm.opcode_modifier & (Size16 | Size32 | Size64)) 2186 { 2187 if (i.tm.opcode_modifier & Size16) 2188 i.suffix = WORD_MNEM_SUFFIX; 2189 else if (i.tm.opcode_modifier & Size64) 2190 i.suffix = QWORD_MNEM_SUFFIX; 2191 else 2192 i.suffix = LONG_MNEM_SUFFIX; 2193 } 2194 else if (i.reg_operands) 2195 { 2196 /* If there's no instruction mnemonic suffix we try to invent one 2197 based on register operands. */ 2198 if (!i.suffix) 2199 { 2200 /* We take i.suffix from the last register operand specified, 2201 Destination register type is more significant than source 2202 register type. */ 2203 int op; 2204 for (op = i.operands; --op >= 0;) 2205 if ((i.types[op] & Reg) 2206 && !(i.tm.operand_types[op] & InOutPortReg)) 2207 { 2208 i.suffix = ((i.types[op] & Reg8) ? BYTE_MNEM_SUFFIX : 2209 (i.types[op] & Reg16) ? WORD_MNEM_SUFFIX : 2210 (i.types[op] & Reg64) ? QWORD_MNEM_SUFFIX : 2211 LONG_MNEM_SUFFIX); 2212 break; 2213 } 2214 } 2215 else if (i.suffix == BYTE_MNEM_SUFFIX) 2216 { 2217 if (!check_byte_reg ()) 2218 return 0; 2219 } 2220 else if (i.suffix == LONG_MNEM_SUFFIX) 2221 { 2222 if (!check_long_reg ()) 2223 return 0; 2224 } 2225 else if (i.suffix == QWORD_MNEM_SUFFIX) 2226 { 2227 if (!check_qword_reg ()) 2228 return 0; 2229 } 2230 else if (i.suffix == WORD_MNEM_SUFFIX) 2231 { 2232 if (!check_word_reg ()) 2233 return 0; 2234 } 2235 else if (intel_syntax && (i.tm.opcode_modifier & IgnoreSize)) 2236 /* Do nothing if the instruction is going to ignore the prefix. */ 2237 ; 2238 else 2239 abort (); 2240 } 2241 else if ((i.tm.opcode_modifier & DefaultSize) && !i.suffix) 2242 { 2243 i.suffix = stackop_size; 2244 } 2245 2246 /* Change the opcode based on the operand size given by i.suffix; 2247 We need not change things for byte insns. */ 2248 2249 if (!i.suffix && (i.tm.opcode_modifier & W)) 2250 { 2251 as_bad (_("no instruction mnemonic suffix given and no register operands; can't size instruction")); 2252 return 0; 2253 } 2254 2255 if (i.suffix && i.suffix != BYTE_MNEM_SUFFIX) 2256 { 2257 /* It's not a byte, select word/dword operation. */ 2258 if (i.tm.opcode_modifier & W) 2259 { 2260 if (i.tm.opcode_modifier & ShortForm) 2261 i.tm.base_opcode |= 8; 2262 else 2263 i.tm.base_opcode |= 1; 2264 } 2265 2266 /* Now select between word & dword operations via the operand 2267 size prefix, except for instructions that will ignore this 2268 prefix anyway. */ 2269 if (i.suffix != QWORD_MNEM_SUFFIX 2270 && !(i.tm.opcode_modifier & IgnoreSize) 2271 && ((i.suffix == LONG_MNEM_SUFFIX) == (flag_code == CODE_16BIT) 2272 || (flag_code == CODE_64BIT 2273 && (i.tm.opcode_modifier & JumpByte)))) 2274 { 2275 unsigned int prefix = DATA_PREFIX_OPCODE; 2276 if (i.tm.opcode_modifier & JumpByte) /* jcxz, loop */ 2277 prefix = ADDR_PREFIX_OPCODE; 2278 2279 if (!add_prefix (prefix)) 2280 return 0; 2281 } 2282 2283 /* Set mode64 for an operand. */ 2284 if (i.suffix == QWORD_MNEM_SUFFIX 2285 && flag_code == CODE_64BIT 2286 && (i.tm.opcode_modifier & NoRex64) == 0) 2287 i.rex |= REX_MODE64; 2288 2289 /* Size floating point instruction. */ 2290 if (i.suffix == LONG_MNEM_SUFFIX) 2291 { 2292 if (i.tm.opcode_modifier & FloatMF) 2293 i.tm.base_opcode ^= 4; 2294 } 2295 } 2296 2297 return 1; 2298 } 2299 2300 static int 2301 check_byte_reg () 2302 { 2303 int op; 2304 for (op = i.operands; --op >= 0;) 2305 { 2306 /* If this is an eight bit register, it's OK. If it's the 16 or 2307 32 bit version of an eight bit register, we will just use the 2308 low portion, and that's OK too. */ 2309 if (i.types[op] & Reg8) 2310 continue; 2311 2312 /* movzx and movsx should not generate this warning. */ 2313 if (intel_syntax 2314 && (i.tm.base_opcode == 0xfb7 2315 || i.tm.base_opcode == 0xfb6 2316 || i.tm.base_opcode == 0x63 2317 || i.tm.base_opcode == 0xfbe 2318 || i.tm.base_opcode == 0xfbf)) 2319 continue; 2320 2321 if ((i.types[op] & WordReg) && i.op[op].regs->reg_num < 4 2322 #if 0 2323 /* Check that the template allows eight bit regs. This 2324 kills insns such as `orb $1,%edx', which maybe should be 2325 allowed. */ 2326 && (i.tm.operand_types[op] & (Reg8 | InOutPortReg)) 2327 #endif 2328 ) 2329 { 2330 /* Prohibit these changes in the 64bit mode, since the 2331 lowering is more complicated. */ 2332 if (flag_code == CODE_64BIT 2333 && (i.tm.operand_types[op] & InOutPortReg) == 0) 2334 { 2335 as_bad (_("Incorrect register `%%%s' used with `%c' suffix"), 2336 i.op[op].regs->reg_name, 2337 i.suffix); 2338 return 0; 2339 } 2340 #if REGISTER_WARNINGS 2341 if (!quiet_warnings 2342 && (i.tm.operand_types[op] & InOutPortReg) == 0) 2343 as_warn (_("using `%%%s' instead of `%%%s' due to `%c' suffix"), 2344 (i.op[op].regs + (i.types[op] & Reg16 2345 ? REGNAM_AL - REGNAM_AX 2346 : REGNAM_AL - REGNAM_EAX))->reg_name, 2347 i.op[op].regs->reg_name, 2348 i.suffix); 2349 #endif 2350 continue; 2351 } 2352 /* Any other register is bad. */ 2353 if (i.types[op] & (Reg | RegMMX | RegXMM 2354 | SReg2 | SReg3 2355 | Control | Debug | Test 2356 | FloatReg | FloatAcc)) 2357 { 2358 as_bad (_("`%%%s' not allowed with `%s%c'"), 2359 i.op[op].regs->reg_name, 2360 i.tm.name, 2361 i.suffix); 2362 return 0; 2363 } 2364 } 2365 return 1; 2366 } 2367 2368 static int 2369 check_long_reg () 2370 { 2371 int op; 2372 2373 for (op = i.operands; --op >= 0;) 2374 /* Reject eight bit registers, except where the template requires 2375 them. (eg. movzb) */ 2376 if ((i.types[op] & Reg8) != 0 2377 && (i.tm.operand_types[op] & (Reg16 | Reg32 | Acc)) != 0) 2774 2378 { 2775 int size; 2776 2777 if (i.tm.opcode_modifier & JumpByte) 2379 as_bad (_("`%%%s' not allowed with `%s%c'"), 2380 i.op[op].regs->reg_name, 2381 i.tm.name, 2382 i.suffix); 2383 return 0; 2384 } 2385 /* Warn if the e prefix on a general reg is missing. */ 2386 else if ((!quiet_warnings || flag_code == CODE_64BIT) 2387 && (i.types[op] & Reg16) != 0 2388 && (i.tm.operand_types[op] & (Reg32 | Acc)) != 0) 2389 { 2390 /* Prohibit these changes in the 64bit mode, since the 2391 lowering is more complicated. */ 2392 if (flag_code == CODE_64BIT) 2778 2393 { 2779 /* This is a loop or jecxz type instruction. */ 2780 size = 1; 2781 if (i.prefix[ADDR_PREFIX]) 2782 { 2783 FRAG_APPEND_1_CHAR (ADDR_PREFIX_OPCODE); 2784 i.prefixes -= 1; 2785 } 2786 /* Pentium4 branch hints. */ 2787 if (i.prefix[SEG_PREFIX] == CS_PREFIX_OPCODE /* not taken */ 2788 || i.prefix[SEG_PREFIX] == DS_PREFIX_OPCODE /* taken */) 2789 { 2790 FRAG_APPEND_1_CHAR (i.prefix[SEG_PREFIX]); 2791 i.prefixes--; 2792 } 2394 as_bad (_("Incorrect register `%%%s' used with `%c' suffix"), 2395 i.op[op].regs->reg_name, 2396 i.suffix); 2397 return 0; 2398 } 2399 #if REGISTER_WARNINGS 2400 else 2401 as_warn (_("using `%%%s' instead of `%%%s' due to `%c' suffix"), 2402 (i.op[op].regs + REGNAM_EAX - REGNAM_AX)->reg_name, 2403 i.op[op].regs->reg_name, 2404 i.suffix); 2405 #endif 2406 } 2407 /* Warn if the r prefix on a general reg is missing. */ 2408 else if ((i.types[op] & Reg64) != 0 2409 && (i.tm.operand_types[op] & (Reg32 | Acc)) != 0) 2410 { 2411 as_bad (_("Incorrect register `%%%s' used with `%c' suffix"), 2412 i.op[op].regs->reg_name, 2413 i.suffix); 2414 return 0; 2415 } 2416 return 1; 2417 } 2418 2419 static int 2420 check_qword_reg () 2421 { 2422 int op; 2423 2424 for (op = i.operands; --op >= 0; ) 2425 /* Reject eight bit registers, except where the template requires 2426 them. (eg. movzb) */ 2427 if ((i.types[op] & Reg8) != 0 2428 && (i.tm.operand_types[op] & (Reg16 | Reg32 | Acc)) != 0) 2429 { 2430 as_bad (_("`%%%s' not allowed with `%s%c'"), 2431 i.op[op].regs->reg_name, 2432 i.tm.name, 2433 i.suffix); 2434 return 0; 2435 } 2436 /* Warn if the e prefix on a general reg is missing. */ 2437 else if (((i.types[op] & Reg16) != 0 2438 || (i.types[op] & Reg32) != 0) 2439 && (i.tm.operand_types[op] & (Reg32 | Acc)) != 0) 2440 { 2441 /* Prohibit these changes in the 64bit mode, since the 2442 lowering is more complicated. */ 2443 as_bad (_("Incorrect register `%%%s' used with `%c' suffix"), 2444 i.op[op].regs->reg_name, 2445 i.suffix); 2446 return 0; 2447 } 2448 return 1; 2449 } 2450 2451 static int 2452 check_word_reg () 2453 { 2454 int op; 2455 for (op = i.operands; --op >= 0;) 2456 /* Reject eight bit registers, except where the template requires 2457 them. (eg. movzb) */ 2458 if ((i.types[op] & Reg8) != 0 2459 && (i.tm.operand_types[op] & (Reg16 | Reg32 | Acc)) != 0) 2460 { 2461 as_bad (_("`%%%s' not allowed with `%s%c'"), 2462 i.op[op].regs->reg_name, 2463 i.tm.name, 2464 i.suffix); 2465 return 0; 2466 } 2467 /* Warn if the e prefix on a general reg is present. */ 2468 else if ((!quiet_warnings || flag_code == CODE_64BIT) 2469 && (i.types[op] & Reg32) != 0 2470 && (i.tm.operand_types[op] & (Reg16 | Acc)) != 0) 2471 { 2472 /* Prohibit these changes in the 64bit mode, since the 2473 lowering is more complicated. */ 2474 if (flag_code == CODE_64BIT) 2475 { 2476 as_bad (_("Incorrect register `%%%s' used with `%c' suffix"), 2477 i.op[op].regs->reg_name, 2478 i.suffix); 2479 return 0; 2793 2480 } 2794 2481 else 2795 { 2796 int code16; 2797 2798 code16 = 0; 2799 if (flag_code == CODE_16BIT) 2800 code16 = CODE16; 2801 2802 if (i.prefix[DATA_PREFIX]) 2803 { 2804 FRAG_APPEND_1_CHAR (DATA_PREFIX_OPCODE); 2805 i.prefixes -= 1; 2806 code16 ^= CODE16; 2807 } 2808 2809 size = 4; 2810 if (code16) 2811 size = 2; 2812 } 2813 2814 if (i.prefix[REX_PREFIX]) 2815 { 2816 FRAG_APPEND_1_CHAR (i.prefix[REX_PREFIX]); 2817 i.prefixes -= 1; 2818 } 2819 2820 if (i.prefixes != 0 && !intel_syntax) 2821 as_warn (_("skipping prefixes on this instruction")); 2822 2823 p = frag_more (1 + size); 2824 *p++ = i.tm.base_opcode; 2825 2826 fix_new_exp (frag_now, p - frag_now->fr_literal, size, 2827 i.op[0].disps, 1, reloc (size, 1, 1, i.reloc[0])); 2482 #if REGISTER_WARNINGS 2483 as_warn (_("using `%%%s' instead of `%%%s' due to `%c' suffix"), 2484 (i.op[op].regs + REGNAM_AX - REGNAM_EAX)->reg_name, 2485 i.op[op].regs->reg_name, 2486 i.suffix); 2487 #endif 2828 2488 } 2829 else if (i.tm.opcode_modifier & JumpInterSegment) 2830 { 2831 int size; 2832 int prefix; 2833 int code16; 2834 2835 code16 = 0; 2836 if (flag_code == CODE_16BIT) 2837 code16 = CODE16; 2838 2839 prefix = 0; 2840 if (i.prefix[DATA_PREFIX]) 2841 { 2842 prefix = 1; 2843 i.prefixes -= 1; 2844 code16 ^= CODE16; 2845 } 2846 if (i.prefix[REX_PREFIX]) 2847 { 2848 prefix++; 2849 i.prefixes -= 1; 2850 } 2851 2852 size = 4; 2853 if (code16) 2854 size = 2; 2855 2856 if (i.prefixes != 0 && !intel_syntax) 2857 as_warn (_("skipping prefixes on this instruction")); 2858 2859 /* 1 opcode; 2 segment; offset */ 2860 p = frag_more (prefix + 1 + 2 + size); 2861 2862 if (i.prefix[DATA_PREFIX]) 2863 *p++ = DATA_PREFIX_OPCODE; 2864 2865 if (i.prefix[REX_PREFIX]) 2866 *p++ = i.prefix[REX_PREFIX]; 2867 2868 *p++ = i.tm.base_opcode; 2869 if (i.op[1].imms->X_op == O_constant) 2870 { 2871 offsetT n = i.op[1].imms->X_add_number; 2872 2873 if (size == 2 2874 && !fits_in_unsigned_word (n) 2875 && !fits_in_signed_word (n)) 2876 { 2877 as_bad (_("16-bit jump out of range")); 2878 return; 2879 } 2880 md_number_to_chars (p, n, size); 2881 } 2882 else 2883 fix_new_exp (frag_now, p - frag_now->fr_literal, size, 2884 i.op[1].imms, 0, reloc (size, 0, 0, i.reloc[1])); 2885 if (i.op[0].imms->X_op != O_constant) 2886 as_bad (_("can't handle non absolute segment in `%s'"), 2887 i.tm.name); 2888 md_number_to_chars (p + size, (valueT) i.op[0].imms->X_add_number, 2); 2889 } 2890 else 2891 { 2892 /* Output normal instructions here. */ 2893 unsigned char *q; 2894 2895 /* All opcodes on i386 have eighter 1 or 2 bytes. We may use third 2896 byte for the SSE instructions to specify prefix they require. */ 2897 if (i.tm.base_opcode & 0xff0000) 2898 add_prefix ((i.tm.base_opcode >> 16) & 0xff); 2899 2900 /* The prefix bytes. */ 2901 for (q = i.prefix; 2902 q < i.prefix + sizeof (i.prefix) / sizeof (i.prefix[0]); 2903 q++) 2904 { 2905 if (*q) 2906 { 2907 p = frag_more (1); 2908 md_number_to_chars (p, (valueT) *q, 1); 2909 } 2910 } 2911 2912 /* Now the opcode; be careful about word order here! */ 2913 if (fits_in_unsigned_byte (i.tm.base_opcode)) 2914 { 2915 FRAG_APPEND_1_CHAR (i.tm.base_opcode); 2916 } 2917 else 2918 { 2919 p = frag_more (2); 2920 /* Put out high byte first: can't use md_number_to_chars! */ 2921 *p++ = (i.tm.base_opcode >> 8) & 0xff; 2922 *p = i.tm.base_opcode & 0xff; 2923 } 2924 2925 /* Now the modrm byte and sib byte (if present). */ 2926 if (i.tm.opcode_modifier & Modrm) 2927 { 2928 p = frag_more (1); 2929 md_number_to_chars (p, 2930 (valueT) (i.rm.regmem << 0 2931 | i.rm.reg << 3 2932 | i.rm.mode << 6), 2933 1); 2934 /* If i.rm.regmem == ESP (4) 2935 && i.rm.mode != (Register mode) 2936 && not 16 bit 2937 ==> need second modrm byte. */ 2938 if (i.rm.regmem == ESCAPE_TO_TWO_BYTE_ADDRESSING 2939 && i.rm.mode != 3 2940 && !(i.base_reg && (i.base_reg->reg_type & Reg16) != 0)) 2941 { 2942 p = frag_more (1); 2943 md_number_to_chars (p, 2944 (valueT) (i.sib.base << 0 2945 | i.sib.index << 3 2946 | i.sib.scale << 6), 2947 1); 2948 } 2949 } 2950 2951 if (i.disp_operands) 2952 { 2953 register unsigned int n; 2954 2955 for (n = 0; n < i.operands; n++) 2956 { 2957 if (i.types[n] & Disp) 2958 { 2959 if (i.op[n].disps->X_op == O_constant) 2489 return 1; 2490 } 2491 2492 static int 2493 finalize_imm () 2494 { 2495 unsigned int overlap0, overlap1, overlap2; 2496 2497 overlap0 = i.types[0] & i.tm.operand_types[0]; 2498 if ((overlap0 & (Imm8 | Imm8S | Imm16 | Imm32 | Imm32S)) 2499 && overlap0 != Imm8 && overlap0 != Imm8S 2500 && overlap0 != Imm16 && overlap0 != Imm32S 2501 && overlap0 != Imm32 && overlap0 != Imm64) 2502 { 2503 if (i.suffix) 2504 { 2505 overlap0 &= (i.suffix == BYTE_MNEM_SUFFIX 2506 ? Imm8 | Imm8S 2507 : (i.suffix == WORD_MNEM_SUFFIX 2508 ? Imm16 2509 : (i.suffix == QWORD_MNEM_SUFFIX 2510 ? Imm64 | Imm32S 2511 : Imm32))); 2512 } 2513 else if (overlap0 == (Imm16 | Imm32S | Imm32) 2514 || overlap0 == (Imm16 | Imm32) 2515 || overlap0 == (Imm16 | Imm32S)) 2516 { 2517 overlap0 = ((flag_code == CODE_16BIT) ^ (i.prefix[DATA_PREFIX] != 0) 2518 ? Imm16 : Imm32S); 2519 } 2520 if (overlap0 != Imm8 && overlap0 != Imm8S 2521 && overlap0 != Imm16 && overlap0 != Imm32S 2522 && overlap0 != Imm32 && overlap0 != Imm64) 2523 { 2524 as_bad (_("no instruction mnemonic suffix given; can't determine immediate size")); 2525 return 0; 2526 } 2527 } 2528 i.types[0] = overlap0; 2529 2530 overlap1 = i.types[1] & i.tm.operand_types[1]; 2531 if ((overlap1 & (Imm8 | Imm8S | Imm16 | Imm32S | Imm32)) 2532 && overlap1 != Imm8 && overlap1 != Imm8S 2533 && overlap1 != Imm16 && overlap1 != Imm32S 2534 && overlap1 != Imm32 && overlap1 != Imm64) 2535 { 2536 if (i.suffix) 2537 { 2538 overlap1 &= (i.suffix == BYTE_MNEM_SUFFIX 2539 ? Imm8 | Imm8S 2540 : (i.suffix == WORD_MNEM_SUFFIX 2541 ? Imm16 2542 : (i.suffix == QWORD_MNEM_SUFFIX 2543 ? Imm64 | Imm32S 2544 : Imm32))); 2545 } 2546 else if (overlap1 == (Imm16 | Imm32 | Imm32S) 2547 || overlap1 == (Imm16 | Imm32) 2548 || overlap1 == (Imm16 | Imm32S)) 2549 { 2550 overlap1 = ((flag_code == CODE_16BIT) ^ (i.prefix[DATA_PREFIX] != 0) 2551 ? Imm16 : Imm32S); 2552 } 2553 if (overlap1 != Imm8 && overlap1 != Imm8S 2554 && overlap1 != Imm16 && overlap1 != Imm32S 2555 && overlap1 != Imm32 && overlap1 != Imm64) 2556 { 2557 as_bad (_("no instruction mnemonic suffix given; can't determine immediate size %x %c"),overlap1, i.suffix); 2558 return 0; 2559 } 2560 } 2561 i.types[1] = overlap1; 2562 2563 overlap2 = i.types[2] & i.tm.operand_types[2]; 2564 assert ((overlap2 & Imm) == 0); 2565 i.types[2] = overlap2; 2566 2567 return 1; 2568 } 2569 2570 static int 2571 process_operands () 2572 { 2573 /* Default segment register this instruction will use for memory 2574 accesses. 0 means unknown. This is only for optimizing out 2575 unnecessary segment overrides. */ 2576 const seg_entry *default_seg = 0; 2577 2578 /* The imul $imm, %reg instruction is converted into 2579 imul $imm, %reg, %reg, and the clr %reg instruction 2580 is converted into xor %reg, %reg. */ 2581 if (i.tm.opcode_modifier & regKludge) 2582 { 2583 unsigned int first_reg_op = (i.types[0] & Reg) ? 0 : 1; 2584 /* Pretend we saw the extra register operand. */ 2585 assert (i.op[first_reg_op + 1].regs == 0); 2586 i.op[first_reg_op + 1].regs = i.op[first_reg_op].regs; 2587 i.types[first_reg_op + 1] = i.types[first_reg_op]; 2588 i.reg_operands = 2; 2589 } 2590 2591 if (i.tm.opcode_modifier & ShortForm) 2592 { 2593 /* The register or float register operand is in operand 0 or 1. */ 2594 unsigned int op = (i.types[0] & (Reg | FloatReg)) ? 0 : 1; 2595 /* Register goes in low 3 bits of opcode. */ 2596 i.tm.base_opcode |= i.op[op].regs->reg_num; 2597 if ((i.op[op].regs->reg_flags & RegRex) != 0) 2598 i.rex |= REX_EXTZ; 2599 if (!quiet_warnings && (i.tm.opcode_modifier & Ugh) != 0) 2600 { 2601 /* Warn about some common errors, but press on regardless. 2602 The first case can be generated by gcc (<= 2.8.1). */ 2603 if (i.operands == 2) 2604 { 2605 /* Reversed arguments on faddp, fsubp, etc. */ 2606 as_warn (_("translating to `%s %%%s,%%%s'"), i.tm.name, 2607 i.op[1].regs->reg_name, 2608 i.op[0].regs->reg_name); 2609 } 2610 else 2611 { 2612 /* Extraneous `l' suffix on fp insn. */ 2613 as_warn (_("translating to `%s %%%s'"), i.tm.name, 2614 i.op[0].regs->reg_name); 2615 } 2616 } 2617 } 2618 else if (i.tm.opcode_modifier & Modrm) 2619 { 2620 /* The opcode is completed (modulo i.tm.extension_opcode which 2621 must be put into the modrm byte). Now, we make the modrm and 2622 index base bytes based on all the info we've collected. */ 2623 2624 default_seg = build_modrm_byte (); 2625 } 2626 else if (i.tm.opcode_modifier & (Seg2ShortForm | Seg3ShortForm)) 2627 { 2628 if (i.tm.base_opcode == POP_SEG_SHORT 2629 && i.op[0].regs->reg_num == 1) 2630 { 2631 as_bad (_("you can't `pop %%cs'")); 2632 return 0; 2633 } 2634 i.tm.base_opcode |= (i.op[0].regs->reg_num << 3); 2635 if ((i.op[0].regs->reg_flags & RegRex) != 0) 2636 i.rex |= REX_EXTZ; 2637 } 2638 else if ((i.tm.base_opcode & ~(D | W)) == MOV_AX_DISP32) 2639 { 2640 default_seg = &ds; 2641 } 2642 else if ((i.tm.opcode_modifier & IsString) != 0) 2643 { 2644 /* For the string instructions that allow a segment override 2645 on one of their operands, the default segment is ds. */ 2646 default_seg = &ds; 2647 } 2648 2649 if (i.tm.base_opcode == 0x8d /* lea */ && i.seg[0] && !quiet_warnings) 2650 as_warn (_("segment override on `lea' is ineffectual")); 2651 2652 /* If a segment was explicitly specified, and the specified segment 2653 is not the default, use an opcode prefix to select it. If we 2654 never figured out what the default segment is, then default_seg 2655 will be zero at this point, and the specified segment prefix will 2656 always be used. */ 2657 if ((i.seg[0]) && (i.seg[0] != default_seg)) 2658 { 2659 if (!add_prefix (i.seg[0]->seg_prefix)) 2660 return 0; 2661 } 2662 return 1; 2663 } 2664 2665 static const seg_entry * 2666 build_modrm_byte () 2667 { 2668 const seg_entry *default_seg = 0; 2669 2670 /* i.reg_operands MUST be the number of real register operands; 2671 implicit registers do not count. */ 2672 if (i.reg_operands == 2) 2673 { 2674 unsigned int source, dest; 2675 source = ((i.types[0] 2676 & (Reg | RegMMX | RegXMM 2677 | SReg2 | SReg3 2678 | Control | Debug | Test)) 2679 ? 0 : 1); 2680 dest = source + 1; 2681 2682 i.rm.mode = 3; 2683 /* One of the register operands will be encoded in the i.tm.reg 2684 field, the other in the combined i.tm.mode and i.tm.regmem 2685 fields. If no form of this instruction supports a memory 2686 destination operand, then we assume the source operand may 2687 sometimes be a memory operand and so we need to store the 2688 destination in the i.rm.reg field. */ 2689 if ((i.tm.operand_types[dest] & AnyMem) == 0) 2690 { 2691 i.rm.reg = i.op[dest].regs->reg_num; 2692 i.rm.regmem = i.op[source].regs->reg_num; 2693 if ((i.op[dest].regs->reg_flags & RegRex) != 0) 2694 i.rex |= REX_EXTX; 2695 if ((i.op[source].regs->reg_flags & RegRex) != 0) 2696 i.rex |= REX_EXTZ; 2697 } 2698 else 2699 { 2700 i.rm.reg = i.op[source].regs->reg_num; 2701 i.rm.regmem = i.op[dest].regs->reg_num; 2702 if ((i.op[dest].regs->reg_flags & RegRex) != 0) 2703 i.rex |= REX_EXTZ; 2704 if ((i.op[source].regs->reg_flags & RegRex) != 0) 2705 i.rex |= REX_EXTX; 2706 } 2707 } 2708 else 2709 { /* If it's not 2 reg operands... */ 2710 if (i.mem_operands) 2711 { 2712 unsigned int fake_zero_displacement = 0; 2713 unsigned int op = ((i.types[0] & AnyMem) 2714 ? 0 2715 : (i.types[1] & AnyMem) ? 1 : 2); 2716 2717 default_seg = &ds; 2718 2719 if (i.base_reg == 0) 2720 { 2721 i.rm.mode = 0; 2722 if (!i.disp_operands) 2723 fake_zero_displacement = 1; 2724 if (i.index_reg == 0) 2725 { 2726 /* Operand is just <disp> */ 2727 if ((flag_code == CODE_16BIT) ^ (i.prefix[ADDR_PREFIX] != 0) 2728 && (flag_code != CODE_64BIT)) 2729 { 2730 i.rm.regmem = NO_BASE_REGISTER_16; 2731 i.types[op] &= ~Disp; 2732 i.types[op] |= Disp16; 2733 } 2734 else if (flag_code != CODE_64BIT 2735 || (i.prefix[ADDR_PREFIX] != 0)) 2736 { 2737 i.rm.regmem = NO_BASE_REGISTER; 2738 i.types[op] &= ~Disp; 2739 i.types[op] |= Disp32; 2740 } 2741 else 2742 { 2743 /* 64bit mode overwrites the 32bit absolute 2744 addressing by RIP relative addressing and 2745 absolute addressing is encoded by one of the 2746 redundant SIB forms. */ 2747 i.rm.regmem = ESCAPE_TO_TWO_BYTE_ADDRESSING; 2748 i.sib.base = NO_BASE_REGISTER; 2749 i.sib.index = NO_INDEX_REGISTER; 2750 i.types[op] &= ~Disp; 2751 i.types[op] |= Disp32S; 2752 } 2753 } 2754 else /* !i.base_reg && i.index_reg */ 2755 { 2756 i.sib.index = i.index_reg->reg_num; 2757 i.sib.base = NO_BASE_REGISTER; 2758 i.sib.scale = i.log2_scale_factor; 2759 i.rm.regmem = ESCAPE_TO_TWO_BYTE_ADDRESSING; 2760 i.types[op] &= ~Disp; 2761 if (flag_code != CODE_64BIT) 2762 i.types[op] |= Disp32; /* Must be 32 bit */ 2763 else 2764 i.types[op] |= Disp32S; 2765 if ((i.index_reg->reg_flags & RegRex) != 0) 2766 i.rex |= REX_EXTY; 2767 } 2768 } 2769 /* RIP addressing for 64bit mode. */ 2770 else if (i.base_reg->reg_type == BaseIndex) 2771 { 2772 i.rm.regmem = NO_BASE_REGISTER; 2773 i.types[op] &= ~Disp; 2774 i.types[op] |= Disp32S; 2775 i.flags[op] = Operand_PCrel; 2776 } 2777 else if (i.base_reg->reg_type & Reg16) 2778 { 2779 switch (i.base_reg->reg_num) 2780 { 2781 case 3: /* (%bx) */ 2782 if (i.index_reg == 0) 2783 i.rm.regmem = 7; 2784 else /* (%bx,%si) -> 0, or (%bx,%di) -> 1 */ 2785 i.rm.regmem = i.index_reg->reg_num - 6; 2786 break; 2787 case 5: /* (%bp) */ 2788 default_seg = &ss; 2789 if (i.index_reg == 0) 2790 { 2791 i.rm.regmem = 6; 2792 if ((i.types[op] & Disp) == 0) 2793 { 2794 /* fake (%bp) into 0(%bp) */ 2795 i.types[op] |= Disp8; 2796 fake_zero_displacement = 1; 2797 } 2798 } 2799 else /* (%bp,%si) -> 2, or (%bp,%di) -> 3 */ 2800 i.rm.regmem = i.index_reg->reg_num - 6 + 2; 2801 break; 2802 default: /* (%si) -> 4 or (%di) -> 5 */ 2803 i.rm.regmem = i.base_reg->reg_num - 6 + 4; 2804 } 2805 i.rm.mode = mode_from_disp_size (i.types[op]); 2806 } 2807 else /* i.base_reg and 32/64 bit mode */ 2808 { 2809 if (flag_code == CODE_64BIT 2810 && (i.types[op] & Disp)) 2811 { 2812 if (i.types[op] & Disp8) 2813 i.types[op] = Disp8 | Disp32S; 2814 else 2815 i.types[op] = Disp32S; 2816 } 2817 i.rm.regmem = i.base_reg->reg_num; 2818 if ((i.base_reg->reg_flags & RegRex) != 0) 2819 i.rex |= REX_EXTZ; 2820 i.sib.base = i.base_reg->reg_num; 2821 /* x86-64 ignores REX prefix bit here to avoid decoder 2822 complications. */ 2823 if ((i.base_reg->reg_num & 7) == EBP_REG_NUM) 2824 { 2825 default_seg = &ss; 2826 if (i.disp_operands == 0) 2827 { 2828 fake_zero_displacement = 1; 2829 i.types[op] |= Disp8; 2830 } 2831 } 2832 else if (i.base_reg->reg_num == ESP_REG_NUM) 2833 { 2834 default_seg = &ss; 2835 } 2836 i.sib.scale = i.log2_scale_factor; 2837 if (i.index_reg == 0) 2838 { 2839 /* <disp>(%esp) becomes two byte modrm with no index 2840 register. We've already stored the code for esp 2841 in i.rm.regmem ie. ESCAPE_TO_TWO_BYTE_ADDRESSING. 2842 Any base register besides %esp will not use the 2843 extra modrm byte. */ 2844 i.sib.index = NO_INDEX_REGISTER; 2845 #if !SCALE1_WHEN_NO_INDEX 2846 /* Another case where we force the second modrm byte. */ 2847 if (i.log2_scale_factor) 2848 i.rm.regmem = ESCAPE_TO_TWO_BYTE_ADDRESSING; 2849 #endif 2850 } 2851 else 2852 { 2853 i.sib.index = i.index_reg->reg_num; 2854 i.rm.regmem = ESCAPE_TO_TWO_BYTE_ADDRESSING; 2855 if ((i.index_reg->reg_flags & RegRex) != 0) 2856 i.rex |= REX_EXTY; 2857 } 2858 i.rm.mode = mode_from_disp_size (i.types[op]); 2859 } 2860 2861 if (fake_zero_displacement) 2862 { 2863 /* Fakes a zero displacement assuming that i.types[op] 2864 holds the correct displacement size. */ 2865 expressionS *exp; 2866 2867 assert (i.op[op].disps == 0); 2868 exp = &disp_expressions[i.disp_operands++]; 2869 i.op[op].disps = exp; 2870 exp->X_op = O_constant; 2871 exp->X_add_number = 0; 2872 exp->X_add_symbol = (symbolS *) 0; 2873 exp->X_op_symbol = (symbolS *) 0; 2874 } 2875 } 2876 2877 /* Fill in i.rm.reg or i.rm.regmem field with register operand 2878 (if any) based on i.tm.extension_opcode. Again, we must be 2879 careful to make sure that segment/control/debug/test/MMX 2880 registers are coded into the i.rm.reg field. */ 2881 if (i.reg_operands) 2882 { 2883 unsigned int op = 2884 ((i.types[0] 2885 & (Reg | RegMMX | RegXMM 2886 | SReg2 | SReg3 2887 | Control | Debug | Test)) 2888 ? 0 2889 : ((i.types[1] 2890 & (Reg | RegMMX | RegXMM 2891 | SReg2 | SReg3 2892 | Control | Debug | Test)) 2893 ? 1 2894 : 2)); 2895 /* If there is an extension opcode to put here, the register 2896 number must be put into the regmem field. */ 2897 if (i.tm.extension_opcode != None) 2898 { 2899 i.rm.regmem = i.op[op].regs->reg_num; 2900 if ((i.op[op].regs->reg_flags & RegRex) != 0) 2901 i.rex |= REX_EXTZ; 2902 } 2903 else 2904 { 2905 i.rm.reg = i.op[op].regs->reg_num; 2906 if ((i.op[op].regs->reg_flags & RegRex) != 0) 2907 i.rex |= REX_EXTX; 2908 } 2909 2910 /* Now, if no memory operand has set i.rm.mode = 0, 1, 2 we 2911 must set it to 3 to indicate this is a register operand 2912 in the regmem field. */ 2913 if (!i.mem_operands) 2914 i.rm.mode = 3; 2915 } 2916 2917 /* Fill in i.rm.reg field with extension opcode (if any). */ 2918 if (i.tm.extension_opcode != None) 2919 i.rm.reg = i.tm.extension_opcode; 2920 } 2921 return default_seg; 2922 } 2923 2924 static void 2925 output_branch () 2926 { 2927 char *p; 2928 int code16; 2929 int prefix; 2930 relax_substateT subtype; 2931 symbolS *sym; 2932 offsetT off; 2933 2934 code16 = 0; 2935 if (flag_code == CODE_16BIT) 2936 code16 = CODE16; 2937 2938 prefix = 0; 2939 if (i.prefix[DATA_PREFIX] != 0) 2940 { 2941 prefix = 1; 2942 i.prefixes -= 1; 2943 code16 ^= CODE16; 2944 } 2945 /* Pentium4 branch hints. */ 2946 if (i.prefix[SEG_PREFIX] == CS_PREFIX_OPCODE /* not taken */ 2947 || i.prefix[SEG_PREFIX] == DS_PREFIX_OPCODE /* taken */) 2948 { 2949 prefix++; 2950 i.prefixes--; 2951 } 2952 if (i.prefix[REX_PREFIX] != 0) 2953 { 2954 prefix++; 2955 i.prefixes--; 2956 } 2957 2958 if (i.prefixes != 0 && !intel_syntax) 2959 as_warn (_("skipping prefixes on this instruction")); 2960 2961 /* It's always a symbol; End frag & setup for relax. 2962 Make sure there is enough room in this frag for the largest 2963 instruction we may generate in md_convert_frag. This is 2 2964 bytes for the opcode and room for the prefix and largest 2965 displacement. */ 2966 frag_grow (prefix + 2 + 4); 2967 /* Prefix and 1 opcode byte go in fr_fix. */ 2968 p = frag_more (prefix + 1); 2969 if (i.prefix[DATA_PREFIX] != 0) 2970 *p++ = DATA_PREFIX_OPCODE; 2971 if (i.prefix[SEG_PREFIX] == CS_PREFIX_OPCODE 2972 || i.prefix[SEG_PREFIX] == DS_PREFIX_OPCODE) 2973 *p++ = i.prefix[SEG_PREFIX]; 2974 if (i.prefix[REX_PREFIX] != 0) 2975 *p++ = i.prefix[REX_PREFIX]; 2976 *p = i.tm.base_opcode; 2977 2978 if ((unsigned char) *p == JUMP_PC_RELATIVE) 2979 subtype = ENCODE_RELAX_STATE (UNCOND_JUMP, SMALL); 2980 else if ((cpu_arch_flags & Cpu386) != 0) 2981 subtype = ENCODE_RELAX_STATE (COND_JUMP, SMALL); 2982 else 2983 subtype = ENCODE_RELAX_STATE (COND_JUMP86, SMALL); 2984 subtype |= code16; 2985 2986 sym = i.op[0].disps->X_add_symbol; 2987 off = i.op[0].disps->X_add_number; 2988 2989 if (i.op[0].disps->X_op != O_constant 2990 && i.op[0].disps->X_op != O_symbol) 2991 { 2992 /* Handle complex expressions. */ 2993 sym = make_expr_symbol (i.op[0].disps); 2994 off = 0; 2995 } 2996 2997 /* 1 possible extra opcode + 4 byte displacement go in var part. 2998 Pass reloc in fr_var. */ 2999 frag_var (rs_machine_dependent, 5, i.reloc[0], subtype, sym, off, p); 3000 } 3001 3002 static void 3003 output_jump () 3004 { 3005 char *p; 3006 int size; 3007 fixS *fixP; 3008 3009 if (i.tm.opcode_modifier & JumpByte) 3010 { 3011 /* This is a loop or jecxz type instruction. */ 3012 size = 1; 3013 if (i.prefix[ADDR_PREFIX] != 0) 3014 { 3015 FRAG_APPEND_1_CHAR (ADDR_PREFIX_OPCODE); 3016 i.prefixes -= 1; 3017 } 3018 /* Pentium4 branch hints. */ 3019 if (i.prefix[SEG_PREFIX] == CS_PREFIX_OPCODE /* not taken */ 3020 || i.prefix[SEG_PREFIX] == DS_PREFIX_OPCODE /* taken */) 3021 { 3022 FRAG_APPEND_1_CHAR (i.prefix[SEG_PREFIX]); 3023 i.prefixes--; 3024 } 3025 } 3026 else 3027 { 3028 int code16; 3029 3030 code16 = 0; 3031 if (flag_code == CODE_16BIT) 3032 code16 = CODE16; 3033 3034 if (i.prefix[DATA_PREFIX] != 0) 3035 { 3036 FRAG_APPEND_1_CHAR (DATA_PREFIX_OPCODE); 3037 i.prefixes -= 1; 3038 code16 ^= CODE16; 3039 } 3040 3041 size = 4; 3042 if (code16) 3043 size = 2; 3044 } 3045 3046 if (i.prefix[REX_PREFIX] != 0) 3047 { 3048 FRAG_APPEND_1_CHAR (i.prefix[REX_PREFIX]); 3049 i.prefixes -= 1; 3050 } 3051 3052 if (i.prefixes != 0 && !intel_syntax) 3053 as_warn (_("skipping prefixes on this instruction")); 3054 3055 p = frag_more (1 + size); 3056 *p++ = i.tm.base_opcode; 3057 3058 fixP = fix_new_exp (frag_now, p - frag_now->fr_literal, size, 3059 i.op[0].disps, 1, reloc (size, 1, 1, i.reloc[0])); 3060 3061 /* All jumps handled here are signed, but don't use a signed limit 3062 check for 32 and 16 bit jumps as we want to allow wrap around at 3063 4G and 64k respectively. */ 3064 if (size == 1) 3065 fixP->fx_signed = 1; 3066 } 3067 3068 static void 3069 output_interseg_jump () 3070 { 3071 char *p; 3072 int size; 3073 int prefix; 3074 int code16; 3075 3076 code16 = 0; 3077 if (flag_code == CODE_16BIT) 3078 code16 = CODE16; 3079 3080 prefix = 0; 3081 if (i.prefix[DATA_PREFIX] != 0) 3082 { 3083 prefix = 1; 3084 i.prefixes -= 1; 3085 code16 ^= CODE16; 3086 } 3087 if (i.prefix[REX_PREFIX] != 0) 3088 { 3089 prefix++; 3090 i.prefixes -= 1; 3091 } 3092 3093 size = 4; 3094 if (code16) 3095 size = 2; 3096 3097 if (i.prefixes != 0 && !intel_syntax) 3098 as_warn (_("skipping prefixes on this instruction")); 3099 3100 /* 1 opcode; 2 segment; offset */ 3101 p = frag_more (prefix + 1 + 2 + size); 3102 3103 if (i.prefix[DATA_PREFIX] != 0) 3104 *p++ = DATA_PREFIX_OPCODE; 3105 3106 if (i.prefix[REX_PREFIX] != 0) 3107 *p++ = i.prefix[REX_PREFIX]; 3108 3109 *p++ = i.tm.base_opcode; 3110 if (i.op[1].imms->X_op == O_constant) 3111 { 3112 offsetT n = i.op[1].imms->X_add_number; 3113 3114 if (size == 2 3115 && !fits_in_unsigned_word (n) 3116 && !fits_in_signed_word (n)) 3117 { 3118 as_bad (_("16-bit jump out of range")); 3119 return; 3120 } 3121 md_number_to_chars (p, n, size); 3122 } 3123 else 3124 fix_new_exp (frag_now, p - frag_now->fr_literal, size, 3125 i.op[1].imms, 0, reloc (size, 0, 0, i.reloc[1])); 3126 if (i.op[0].imms->X_op != O_constant) 3127 as_bad (_("can't handle non absolute segment in `%s'"), 3128 i.tm.name); 3129 md_number_to_chars (p + size, (valueT) i.op[0].imms->X_add_number, 2); 3130 } 3131 3132 3133 static void 3134 output_insn () 3135 { 3136 fragS *insn_start_frag; 3137 offsetT insn_start_off; 3138 3139 /* Tie dwarf2 debug info to the address at the start of the insn. 3140 We can't do this after the insn has been output as the current 3141 frag may have been closed off. eg. by frag_var. */ 3142 dwarf2_emit_insn (0); 3143 3144 insn_start_frag = frag_now; 3145 insn_start_off = frag_now_fix (); 3146 3147 /* Output jumps. */ 3148 if (i.tm.opcode_modifier & Jump) 3149 output_branch (); 3150 else if (i.tm.opcode_modifier & (JumpByte | JumpDword)) 3151 output_jump (); 3152 else if (i.tm.opcode_modifier & JumpInterSegment) 3153 output_interseg_jump (); 3154 else 3155 { 3156 /* Output normal instructions here. */ 3157 char *p; 3158 unsigned char *q; 3159 3160 /* All opcodes on i386 have either 1 or 2 bytes. We may use third 3161 byte for the SSE instructions to specify a prefix they require. */ 3162 if (i.tm.base_opcode & 0xff0000) 3163 add_prefix ((i.tm.base_opcode >> 16) & 0xff); 3164 3165 /* The prefix bytes. */ 3166 for (q = i.prefix; 3167 q < i.prefix + sizeof (i.prefix) / sizeof (i.prefix[0]); 3168 q++) 3169 { 3170 if (*q) 3171 { 3172 p = frag_more (1); 3173 md_number_to_chars (p, (valueT) *q, 1); 3174 } 3175 } 3176 3177 /* Now the opcode; be careful about word order here! */ 3178 if (fits_in_unsigned_byte (i.tm.base_opcode)) 3179 { 3180 FRAG_APPEND_1_CHAR (i.tm.base_opcode); 3181 } 3182 else 3183 { 3184 p = frag_more (2); 3185 /* Put out high byte first: can't use md_number_to_chars! */ 3186 *p++ = (i.tm.base_opcode >> 8) & 0xff; 3187 *p = i.tm.base_opcode & 0xff; 3188 } 3189 3190 /* Now the modrm byte and sib byte (if present). */ 3191 if (i.tm.opcode_modifier & Modrm) 3192 { 3193 p = frag_more (1); 3194 md_number_to_chars (p, 3195 (valueT) (i.rm.regmem << 0 3196 | i.rm.reg << 3 3197 | i.rm.mode << 6), 3198 1); 3199 /* If i.rm.regmem == ESP (4) 3200 && i.rm.mode != (Register mode) 3201 && not 16 bit 3202 ==> need second modrm byte. */ 3203 if (i.rm.regmem == ESCAPE_TO_TWO_BYTE_ADDRESSING 3204 && i.rm.mode != 3 3205 && !(i.base_reg && (i.base_reg->reg_type & Reg16) != 0)) 3206 { 3207 p = frag_more (1); 3208 md_number_to_chars (p, 3209 (valueT) (i.sib.base << 0 3210 | i.sib.index << 3 3211 | i.sib.scale << 6), 3212 1); 3213 } 3214 } 3215 3216 if (i.disp_operands) 3217 output_disp (insn_start_frag, insn_start_off); 3218 3219 if (i.imm_operands) 3220 output_imm (insn_start_frag, insn_start_off); 3221 } 3222 3223 #ifdef DEBUG386 3224 if (flag_debug) 3225 { 3226 pi (line, &i); 3227 } 3228 #endif /* DEBUG386 */ 3229 } 3230 3231 static void 3232 output_disp (insn_start_frag, insn_start_off) 3233 fragS *insn_start_frag; 3234 offsetT insn_start_off; 3235 { 3236 char *p; 3237 unsigned int n; 3238 3239 for (n = 0; n < i.operands; n++) 3240 { 3241 if (i.types[n] & Disp) 3242 { 3243 if (i.op[n].disps->X_op == O_constant) 3244 { 3245 int size; 3246 offsetT val; 3247 3248 size = 4; 3249 if (i.types[n] & (Disp8 | Disp16 | Disp64)) 3250 { 3251 size = 2; 3252 if (i.types[n] & Disp8) 3253 size = 1; 3254 if (i.types[n] & Disp64) 3255 size = 8; 3256 } 3257 val = offset_in_range (i.op[n].disps->X_add_number, 3258 size); 3259 p = frag_more (size); 3260 md_number_to_chars (p, val, size); 3261 } 3262 else 3263 { 3264 RELOC_ENUM reloc_type; 3265 int size = 4; 3266 int sign = 0; 3267 int pcrel = (i.flags[n] & Operand_PCrel) != 0; 3268 3269 /* The PC relative address is computed relative 3270 to the instruction boundary, so in case immediate 3271 fields follows, we need to adjust the value. */ 3272 if (pcrel && i.imm_operands) 3273 { 3274 int imm_size = 4; 3275 unsigned int n1; 3276 3277 for (n1 = 0; n1 < i.operands; n1++) 3278 if (i.types[n1] & Imm) 2960 3279 { 2961 int size; 2962 offsetT val; 2963 2964 size = 4; 2965 if (i.types[n] & (Disp8 | Disp16 | Disp64)) 3280 if (i.types[n1] & (Imm8 | Imm8S | Imm16 | Imm64)) 2966 3281 { 2967 size = 2;2968 if (i.types[n ] & Disp8)2969 size = 1;2970 if (i.types[n ] & Disp64)2971 size = 8;3282 imm_size = 2; 3283 if (i.types[n1] & (Imm8 | Imm8S)) 3284 imm_size = 1; 3285 if (i.types[n1] & Imm64) 3286 imm_size = 8; 2972 3287 } 2973 val = offset_in_range (i.op[n].disps->X_add_number, 2974 size); 2975 p = frag_more (size); 2976 md_number_to_chars (p, val, size); 3288 break; 2977 3289 } 2978 else 2979 { 2980 int size = 4; 2981 int sign = 0; 2982 int pcrel = (i.flags[n] & Operand_PCrel) != 0; 2983 2984 /* The PC relative address is computed relative 2985 to the instruction boundary, so in case immediate 2986 fields follows, we need to adjust the value. */ 2987 if (pcrel && i.imm_operands) 2988 { 2989 int imm_size = 4; 2990 register unsigned int n1; 2991 2992 for (n1 = 0; n1 < i.operands; n1++) 2993 if (i.types[n1] & Imm) 2994 { 2995 if (i.types[n1] & (Imm8 | Imm8S | Imm16 | Imm64)) 2996 { 2997 imm_size = 2; 2998 if (i.types[n1] & (Imm8 | Imm8S)) 2999 imm_size = 1; 3000 if (i.types[n1] & Imm64) 3001 imm_size = 8; 3002 } 3003 break; 3004 } 3005 /* We should find the immediate. */ 3006 if (n1 == i.operands) 3007 abort (); 3008 i.op[n].disps->X_add_number -= imm_size; 3009 } 3010 3011 if (i.types[n] & Disp32S) 3012 sign = 1; 3013 3014 if (i.types[n] & (Disp16 | Disp64)) 3015 { 3016 size = 2; 3017 if (i.types[n] & Disp64) 3018 size = 8; 3019 } 3020 3021 p = frag_more (size); 3022 fix_new_exp (frag_now, p - frag_now->fr_literal, size, 3023 i.op[n].disps, pcrel, 3024 reloc (size, pcrel, sign, i.reloc[n])); 3025 } 3026 } 3027 } 3028 } 3029 3030 /* Output immediate. */ 3031 if (i.imm_operands) 3032 { 3033 register unsigned int n; 3034 3035 for (n = 0; n < i.operands; n++) 3036 { 3037 if (i.types[n] & Imm) 3038 { 3039 if (i.op[n].imms->X_op == O_constant) 3040 { 3041 int size; 3042 offsetT val; 3043 3044 size = 4; 3045 if (i.types[n] & (Imm8 | Imm8S | Imm16 | Imm64)) 3046 { 3047 size = 2; 3048 if (i.types[n] & (Imm8 | Imm8S)) 3049 size = 1; 3050 else if (i.types[n] & Imm64) 3051 size = 8; 3052 } 3053 val = offset_in_range (i.op[n].imms->X_add_number, 3054 size); 3055 p = frag_more (size); 3056 md_number_to_chars (p, val, size); 3057 } 3058 else 3059 { 3060 /* Not absolute_section. 3061 Need a 32-bit fixup (don't support 8bit 3062 non-absolute imms). Try to support other 3063 sizes ... */ 3064 RELOC_ENUM reloc_type; 3065 int size = 4; 3066 int sign = 0; 3067 3068 if ((i.types[n] & (Imm32S)) 3069 && i.suffix == QWORD_MNEM_SUFFIX) 3070 sign = 1; 3071 if (i.types[n] & (Imm8 | Imm8S | Imm16 | Imm64)) 3072 { 3073 size = 2; 3074 if (i.types[n] & (Imm8 | Imm8S)) 3075 size = 1; 3076 if (i.types[n] & Imm64) 3077 size = 8; 3078 } 3079 3080 p = frag_more (size); 3081 reloc_type = reloc (size, 0, sign, i.reloc[n]); 3290 /* We should find the immediate. */ 3291 if (n1 == i.operands) 3292 abort (); 3293 i.op[n].disps->X_add_number -= imm_size; 3294 } 3295 3296 if (i.types[n] & Disp32S) 3297 sign = 1; 3298 3299 if (i.types[n] & (Disp16 | Disp64)) 3300 { 3301 size = 2; 3302 if (i.types[n] & Disp64) 3303 size = 8; 3304 } 3305 3306 p = frag_more (size); 3307 reloc_type = reloc (size, pcrel, sign, i.reloc[n]); 3082 3308 #ifdef BFD_ASSEMBLER 3083 if (reloc_type == BFD_RELOC_32 3084 && GOT_symbol 3085 && GOT_symbol == i.op[n].imms->X_add_symbol 3086 && (i.op[n].imms->X_op == O_symbol 3087 || (i.op[n].imms->X_op == O_add 3088 && ((symbol_get_value_expression 3089 (i.op[n].imms->X_op_symbol)->X_op) 3090 == O_subtract)))) 3091 { 3092 /* We don't support dynamic linking on x86-64 yet. */ 3093 if (flag_code == CODE_64BIT) 3094 abort (); 3095 reloc_type = BFD_RELOC_386_GOTPC; 3096 i.op[n].imms->X_add_number += 3; 3097 } 3098 #endif 3099 fix_new_exp (frag_now, p - frag_now->fr_literal, size, 3100 i.op[n].imms, 0, reloc_type); 3101 } 3102 } 3103 } 3104 } 3105 } 3106 3107 #ifdef DEBUG386 3108 if (flag_debug) 3109 { 3110 pi (line, &i); 3111 } 3112 #endif /* DEBUG386 */ 3113 } 3309 if (reloc_type == BFD_RELOC_32 3310 && GOT_symbol 3311 && GOT_symbol == i.op[n].disps->X_add_symbol 3312 && (i.op[n].disps->X_op == O_symbol 3313 || (i.op[n].disps->X_op == O_add 3314 && ((symbol_get_value_expression 3315 (i.op[n].disps->X_op_symbol)->X_op) 3316 == O_subtract)))) 3317 { 3318 offsetT add; 3319 3320 if (insn_start_frag == frag_now) 3321 add = (p - frag_now->fr_literal) - insn_start_off; 3322 else 3323 { 3324 fragS *fr; 3325 3326 add = insn_start_frag->fr_fix - insn_start_off; 3327 for (fr = insn_start_frag->fr_next; 3328 fr && fr != frag_now; fr = fr->fr_next) 3329 add += fr->fr_fix; 3330 add += p - frag_now->fr_literal; 3331 } 3332 3333 /* We don't support dynamic linking on x86-64 yet. */ 3334 if (flag_code == CODE_64BIT) 3335 abort (); 3336 reloc_type = BFD_RELOC_386_GOTPC; 3337 i.op[n].disps->X_add_number += add; 3338 } 3339 #endif 3340 fix_new_exp (frag_now, p - frag_now->fr_literal, size, 3341 i.op[n].disps, pcrel, reloc_type); 3342 } 3343 } 3344 } 3345 } 3346 3347 static void 3348 output_imm (insn_start_frag, insn_start_off) 3349 fragS *insn_start_frag; 3350 offsetT insn_start_off; 3351 { 3352 char *p; 3353 unsigned int n; 3354 3355 for (n = 0; n < i.operands; n++) 3356 { 3357 if (i.types[n] & Imm) 3358 { 3359 if (i.op[n].imms->X_op == O_constant) 3360 { 3361 int size; 3362 offsetT val; 3363 3364 size = 4; 3365 if (i.types[n] & (Imm8 | Imm8S | Imm16 | Imm64)) 3366 { 3367 size = 2; 3368 if (i.types[n] & (Imm8 | Imm8S)) 3369 size = 1; 3370 else if (i.types[n] & Imm64) 3371 size = 8; 3372 } 3373 val = offset_in_range (i.op[n].imms->X_add_number, 3374 size); 3375 p = frag_more (size); 3376 md_number_to_chars (p, val, size); 3377 } 3378 else 3379 { 3380 /* Not absolute_section. 3381 Need a 32-bit fixup (don't support 8bit 3382 non-absolute imms). Try to support other 3383 sizes ... */ 3384 RELOC_ENUM reloc_type; 3385 int size = 4; 3386 int sign = 0; 3387 3388 if ((i.types[n] & (Imm32S)) 3389 && i.suffix == QWORD_MNEM_SUFFIX) 3390 sign = 1; 3391 if (i.types[n] & (Imm8 | Imm8S | Imm16 | Imm64)) 3392 { 3393 size = 2; 3394 if (i.types[n] & (Imm8 | Imm8S)) 3395 size = 1; 3396 if (i.types[n] & Imm64) 3397 size = 8; 3398 } 3399 3400 p = frag_more (size); 3401 reloc_type = reloc (size, 0, sign, i.reloc[n]); 3402 #ifdef BFD_ASSEMBLER 3403 /* This is tough to explain. We end up with this one if we 3404 * have operands that look like 3405 * "_GLOBAL_OFFSET_TABLE_+[.-.L284]". The goal here is to 3406 * obtain the absolute address of the GOT, and it is strongly 3407 * preferable from a performance point of view to avoid using 3408 * a runtime relocation for this. The actual sequence of 3409 * instructions often look something like: 3410 * 3411 * call .L66 3412 * .L66: 3413 * popl %ebx 3414 * addl $_GLOBAL_OFFSET_TABLE_+[.-.L66],%ebx 3415 * 3416 * The call and pop essentially return the absolute address 3417 * of the label .L66 and store it in %ebx. The linker itself 3418 * will ultimately change the first operand of the addl so 3419 * that %ebx points to the GOT, but to keep things simple, the 3420 * .o file must have this operand set so that it generates not 3421 * the absolute address of .L66, but the absolute address of 3422 * itself. This allows the linker itself simply treat a GOTPC 3423 * relocation as asking for a pcrel offset to the GOT to be 3424 * added in, and the addend of the relocation is stored in the 3425 * operand field for the instruction itself. 3426 * 3427 * Our job here is to fix the operand so that it would add 3428 * the correct offset so that %ebx would point to itself. The 3429 * thing that is tricky is that .-.L66 will point to the 3430 * beginning of the instruction, so we need to further modify 3431 * the operand so that it will point to itself. There are 3432 * other cases where you have something like: 3433 * 3434 * .long $_GLOBAL_OFFSET_TABLE_+[.-.L66] 3435 * 3436 * and here no correction would be required. Internally in 3437 * the assembler we treat operands of this form as not being 3438 * pcrel since the '.' is explicitly mentioned, and I wonder 3439 * whether it would simplify matters to do it this way. Who 3440 * knows. In earlier versions of the PIC patches, the 3441 * pcrel_adjust field was used to store the correction, but 3442 * since the expression is not pcrel, I felt it would be 3443 * confusing to do it this way. */ 3444 3445 if (reloc_type == BFD_RELOC_32 3446 && GOT_symbol 3447 && GOT_symbol == i.op[n].imms->X_add_symbol 3448 && (i.op[n].imms->X_op == O_symbol 3449 || (i.op[n].imms->X_op == O_add 3450 && ((symbol_get_value_expression 3451 (i.op[n].imms->X_op_symbol)->X_op) 3452 == O_subtract)))) 3453 { 3454 offsetT add; 3455 3456 if (insn_start_frag == frag_now) 3457 add = (p - frag_now->fr_literal) - insn_start_off; 3458 else 3459 { 3460 fragS *fr; 3461 3462 add = insn_start_frag->fr_fix - insn_start_off; 3463 for (fr = insn_start_frag->fr_next; 3464 fr && fr != frag_now; fr = fr->fr_next) 3465 add += fr->fr_fix; 3466 add += p - frag_now->fr_literal; 3467 } 3468 3469 /* We don't support dynamic linking on x86-64 yet. */ 3470 if (flag_code == CODE_64BIT) 3471 abort (); 3472 reloc_type = BFD_RELOC_386_GOTPC; 3473 i.op[n].imms->X_add_number += add; 3474 } 3475 #endif 3476 fix_new_exp (frag_now, p - frag_now->fr_literal, size, 3477 i.op[n].imms, 0, reloc_type); 3478 } 3479 } 3480 } 3114 3481 } 3115 3482 … … 3137 3504 const RELOC_ENUM rel[NUM_FLAG_CODE]; 3138 3505 } gotrel[] = { 3139 { "PLT", { BFD_RELOC_386_PLT32, 0, BFD_RELOC_X86_64_PLT32 } }, 3140 { "GOTOFF", { BFD_RELOC_386_GOTOFF, 0, 0 } }, 3141 { "GOTPCREL", { 0, 0, BFD_RELOC_X86_64_GOTPCREL } }, 3142 { "GOT", { BFD_RELOC_386_GOT32, 0, BFD_RELOC_X86_64_GOT32 } } 3506 { "PLT", { BFD_RELOC_386_PLT32, 0, BFD_RELOC_X86_64_PLT32 } }, 3507 { "GOTOFF", { BFD_RELOC_386_GOTOFF, 0, 0 } }, 3508 { "GOTPCREL", { 0, 0, BFD_RELOC_X86_64_GOTPCREL } }, 3509 { "TLSGD", { BFD_RELOC_386_TLS_GD, 0, BFD_RELOC_X86_64_TLSGD } }, 3510 { "TLSLDM", { BFD_RELOC_386_TLS_LDM, 0, 0 } }, 3511 { "TLSLD", { 0, 0, BFD_RELOC_X86_64_TLSLD } }, 3512 { "GOTTPOFF", { BFD_RELOC_386_TLS_IE_32, 0, BFD_RELOC_X86_64_GOTTPOFF } }, 3513 { "TPOFF", { BFD_RELOC_386_TLS_LE_32, 0, BFD_RELOC_X86_64_TPOFF32 } }, 3514 { "NTPOFF", { BFD_RELOC_386_TLS_LE, 0, 0 } }, 3515 { "DTPOFF", { BFD_RELOC_386_TLS_LDO_32, 0, BFD_RELOC_X86_64_DTPOFF32 } }, 3516 { "GOTNTPOFF",{ BFD_RELOC_386_TLS_GOTIE, 0, 0 } }, 3517 { "INDNTPOFF",{ BFD_RELOC_386_TLS_IE, 0, 0 } }, 3518 { "GOT", { BFD_RELOC_386_GOT32, 0, BFD_RELOC_X86_64_GOT32 } } 3143 3519 }; 3144 3520 char *cp; … … 3154 3530 3155 3531 len = strlen (gotrel[j].str); 3156 if (strnc mp (cp + 1, gotrel[j].str, len) == 0)3532 if (strncasecmp (cp + 1, gotrel[j].str, len) == 0) 3157 3533 { 3158 3534 if (gotrel[j].rel[(unsigned int) flag_code] != 0) 3159 3535 { 3160 int first ;3161 char *tmpbuf ;3536 int first, second; 3537 char *tmpbuf, *past_reloc; 3162 3538 3163 3539 *reloc = gotrel[j].rel[(unsigned int) flag_code]; 3540 if (adjust) 3541 *adjust = len; 3164 3542 3165 3543 if (GOT_symbol == NULL) … … 3168 3546 /* Replace the relocation token with ' ', so that 3169 3547 errors like foo@GOTOFF1 will be detected. */ 3548 3549 /* The length of the first part of our input line. */ 3170 3550 first = cp - input_line_pointer; 3171 tmpbuf = xmalloc (strlen (input_line_pointer)); 3551 3552 /* The second part goes from after the reloc token until 3553 (and including) an end_of_line char. Don't use strlen 3554 here as the end_of_line char may not be a NUL. */ 3555 past_reloc = cp + 1 + len; 3556 for (cp = past_reloc; !is_end_of_line[(unsigned char) *cp++]; ) 3557 ; 3558 second = cp - past_reloc; 3559 3560 /* Allocate and copy string. The trailing NUL shouldn't 3561 be necessary, but be safe. */ 3562 tmpbuf = xmalloc (first + second + 2); 3172 3563 memcpy (tmpbuf, input_line_pointer, first); 3173 3564 tmpbuf[first] = ' '; 3174 strcpy (tmpbuf + first + 1, cp + 1 + len); 3175 if (adjust) 3176 *adjust = len; 3565 memcpy (tmpbuf + first + 1, past_reloc, second); 3566 tmpbuf[first + second + 1] = '\0'; 3177 3567 return tmpbuf; 3178 3568 } … … 3309 3699 && OUTPUT_FLAVOR == bfd_target_aout_flavour 3310 3700 #endif 3701 && exp_seg != absolute_section 3311 3702 && exp_seg != text_section 3312 3703 && exp_seg != data_section … … 3370 3761 return NULL; 3371 3762 } 3372 if (i.log2_scale_factor != 0 && ! i.index_reg)3763 if (i.log2_scale_factor != 0 && i.index_reg == 0) 3373 3764 { 3374 3765 as_warn (_("scale factor of %d without an index register"), … … 3390 3781 char *disp_end; 3391 3782 { 3392 registerexpressionS *exp;3783 expressionS *exp; 3393 3784 segT exp_seg = 0; 3394 3785 char *save_input_line_pointer; … … 3398 3789 int bigdisp = Disp32; 3399 3790 3400 if ((flag_code == CODE_16BIT) ^ (i.prefix[ADDR_PREFIX] != 0)) 3791 if (flag_code == CODE_64BIT) 3792 { 3793 if (i.prefix[ADDR_PREFIX] == 0) 3794 bigdisp = Disp64; 3795 } 3796 else if ((flag_code == CODE_16BIT) ^ (i.prefix[ADDR_PREFIX] != 0)) 3401 3797 bigdisp = Disp16; 3402 if (flag_code == CODE_64BIT)3403 bigdisp = Disp64;3404 3798 i.types[this_operand] |= bigdisp; 3405 3799 … … 3498 3892 exp->X_op_symbol = GOT_symbol; 3499 3893 if (i.reloc[this_operand] == BFD_RELOC_X86_64_GOTPCREL) 3500 3894 i.reloc[this_operand] = BFD_RELOC_32_PCREL; 3501 3895 else 3502 3896 i.reloc[this_operand] = BFD_RELOC_32; 3503 3897 } 3504 3898 #endif … … 3520 3914 && OUTPUT_FLAVOR == bfd_target_aout_flavour 3521 3915 #endif 3916 && exp_seg != absolute_section 3522 3917 && exp_seg != text_section 3523 3918 && exp_seg != data_section 3524 3919 && exp_seg != bss_section 3525 && exp_seg != undefined_section) 3920 && exp_seg != undefined_section 3921 #ifdef BFD_ASSEMBLER 3922 && !bfd_is_com_section (exp_seg) 3923 #endif 3924 ) 3526 3925 { 3527 3926 #ifdef BFD_ASSEMBLER … … 3556 3955 if (flag_code == CODE_64BIT) 3557 3956 { 3558 /* 64bit checks. */ 3559 if ((i.base_reg 3560 && ((i.base_reg->reg_type & Reg64) == 0) 3561 && (i.base_reg->reg_type != BaseIndex 3562 || i.index_reg)) 3563 || (i.index_reg 3564 && ((i.index_reg->reg_type & (Reg64|BaseIndex)) 3565 != (Reg64|BaseIndex)))) 3566 ok = 0; 3567 } 3568 else 3569 { 3570 if ((flag_code == CODE_16BIT) ^ (i.prefix[ADDR_PREFIX] != 0)) 3571 { 3572 /* 16bit checks. */ 3957 if (i.prefix[ADDR_PREFIX] == 0) 3958 { 3959 /* 64bit checks. */ 3573 3960 if ((i.base_reg 3574 && ((i.base_reg->reg_type & (Reg16|BaseIndex|RegRex)) 3575 != (Reg16|BaseIndex))) 3961 && ((i.base_reg->reg_type & Reg64) == 0) 3962 && (i.base_reg->reg_type != BaseIndex 3963 || i.index_reg)) 3576 3964 || (i.index_reg 3577 && (((i.index_reg->reg_type & (Reg16|BaseIndex)) 3578 != (Reg16|BaseIndex)) 3579 || ! (i.base_reg 3580 && i.base_reg->reg_num < 6 3581 && i.index_reg->reg_num >= 6 3582 && i.log2_scale_factor == 0)))) 3965 && ((i.index_reg->reg_type & (Reg64 | BaseIndex)) 3966 != (Reg64 | BaseIndex)))) 3583 3967 ok = 0; 3584 3968 } … … 3589 3973 && (i.base_reg->reg_type & (Reg32 | RegRex)) != Reg32) 3590 3974 || (i.index_reg 3591 && ((i.index_reg->reg_type & (Reg32|BaseIndex|RegRex)) 3592 != (Reg32|BaseIndex)))) 3975 && ((i.index_reg->reg_type & (Reg32 | BaseIndex | RegRex)) 3976 != (Reg32 | BaseIndex)))) 3977 ok = 0; 3978 } 3979 } 3980 else 3981 { 3982 if ((flag_code == CODE_16BIT) ^ (i.prefix[ADDR_PREFIX] != 0)) 3983 { 3984 /* 16bit checks. */ 3985 if ((i.base_reg 3986 && ((i.base_reg->reg_type & (Reg16 | BaseIndex | RegRex)) 3987 != (Reg16 | BaseIndex))) 3988 || (i.index_reg 3989 && (((i.index_reg->reg_type & (Reg16 | BaseIndex)) 3990 != (Reg16 | BaseIndex)) 3991 || !(i.base_reg 3992 && i.base_reg->reg_num < 6 3993 && i.index_reg->reg_num >= 6 3994 && i.log2_scale_factor == 0)))) 3995 ok = 0; 3996 } 3997 else 3998 { 3999 /* 32bit checks. */ 4000 if ((i.base_reg 4001 && (i.base_reg->reg_type & (Reg32 | RegRex)) != Reg32) 4002 || (i.index_reg 4003 && ((i.index_reg->reg_type & (Reg32 | BaseIndex | RegRex)) 4004 != (Reg32 | BaseIndex)))) 3593 4005 ok = 0; 3594 4006 } … … 3607 4019 Disp16 and Disp32 flags. The same goes for Imm16 and Imm32. 3608 4020 Removing them would probably clean up the code quite a lot. */ 3609 if (i.types[this_operand] & (Disp16 |Disp32))3610 i.types[this_operand] ^= (Disp16 |Disp32);4021 if (i.types[this_operand] & (Disp16 | Disp32)) 4022 i.types[this_operand] ^= (Disp16 | Disp32); 3611 4023 fudged = 1; 3612 4024 goto tryprefix; … … 3928 4340 int 3929 4341 md_estimate_size_before_relax (fragP, segment) 3930 registerfragS *fragP;3931 registersegT segment;4342 fragS *fragP; 4343 segT segment; 3932 4344 { 3933 4345 /* We've already got fragP->fr_subtype right; all we have to do is … … 3937 4349 if (S_GET_SEGMENT (fragP->fr_symbol) != segment 3938 4350 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) 3939 || S_IS_EXTERNAL (fragP->fr_symbol) 3940 || S_IS_WEAK (fragP->fr_symbol) 4351 || (OUTPUT_FLAVOR == bfd_target_elf_flavour 4352 && (S_IS_EXTERNAL (fragP->fr_symbol) 4353 || S_IS_WEAK (fragP->fr_symbol))) 3941 4354 #endif 3942 4355 ) … … 3972 4385 3973 4386 case COND_JUMP86: 3974 if (no_cond_jump_promotion) 3975 goto relax_guess; 3976 3977 if (size == 2) 4387 if (size == 2 4388 && (!no_cond_jump_promotion || fragP->fr_var != NO_RELOC)) 3978 4389 { 3979 4390 /* Negate the condition, and branch past an … … 3995 4406 3996 4407 case COND_JUMP: 3997 if (no_cond_jump_promotion) 3998 goto relax_guess; 4408 if (no_cond_jump_promotion && fragP->fr_var == NO_RELOC) 4409 { 4410 fixS *fixP; 4411 4412 fragP->fr_fix += 1; 4413 fixP = fix_new (fragP, old_fr_fix, 1, 4414 fragP->fr_symbol, 4415 fragP->fr_offset, 1, 4416 BFD_RELOC_8_PCREL); 4417 fixP->fx_signed = 1; 4418 break; 4419 } 3999 4420 4000 4421 /* This changes the byte-displacement jump 0x7N … … 4018 4439 } 4019 4440 4020 relax_guess:4021 4441 /* Guess size depending on current relax state. Initially the relax 4022 4442 state will correspond to a short jump and we return 1, because … … 4042 4462 object_headers *headers ATTRIBUTE_UNUSED; 4043 4463 segT sec ATTRIBUTE_UNUSED; 4044 registerfragS *fragP;4464 fragS *fragP; 4045 4465 #else 4046 4466 void … … 4048 4468 bfd *abfd ATTRIBUTE_UNUSED; 4049 4469 segT sec ATTRIBUTE_UNUSED; 4050 registerfragS *fragP;4051 #endif 4052 { 4053 registerunsigned char *opcode;4470 fragS *fragP; 4471 #endif 4472 { 4473 unsigned char *opcode; 4054 4474 unsigned char *where_to_put_displacement = NULL; 4055 4475 offsetT target_address; … … 4062 4482 /* Address we want to reach in file space. */ 4063 4483 target_address = S_GET_VALUE (fragP->fr_symbol) + fragP->fr_offset; 4064 #ifdef BFD_ASSEMBLER4065 /* Not needed otherwise? */4066 {4067 /* Local symbols which have already been resolved have a NULL frag. */4068 fragS *sym_frag = symbol_get_frag (fragP->fr_symbol);4069 if (sym_frag)4070 target_address += sym_frag->fr_address;4071 }4072 #endif4073 4484 4074 4485 /* Address opcode resides at in file space. */ … … 4187 4598 we are handling. */ 4188 4599 4189 int 4190 md_apply_fix3 (fixP, val p, seg)4600 void 4601 md_apply_fix3 (fixP, valP, seg) 4191 4602 /* The fix we're to put in. */ 4192 4603 fixS *fixP; 4193 4194 4604 /* Pointer to the value of the bits. */ 4195 valueT *valp; 4196 4605 valueT *valP; 4197 4606 /* Segment fix is from. */ 4198 4607 segT seg ATTRIBUTE_UNUSED; 4199 4608 { 4200 registerchar *p = fixP->fx_where + fixP->fx_frag->fr_literal;4201 valueT value = *val p;4609 char *p = fixP->fx_where + fixP->fx_frag->fr_literal; 4610 valueT value = *valP; 4202 4611 4203 4612 #if defined (BFD_ASSEMBLER) && !defined (TE_Mach) … … 4221 4630 } 4222 4631 4223 /* This is a hack. There should be a better way to handle this. 4224 This covers for the fact that bfd_install_relocation will 4225 subtract the current location (for partial_inplace, PC relative 4226 relocations); see more below. */ 4227 if ((fixP->fx_r_type == BFD_RELOC_32_PCREL 4228 || fixP->fx_r_type == BFD_RELOC_16_PCREL 4229 || fixP->fx_r_type == BFD_RELOC_8_PCREL) 4230 && fixP->fx_addsy && !use_rela_relocations) 4231 { 4632 if (fixP->fx_addsy != NULL 4633 && (fixP->fx_r_type == BFD_RELOC_32_PCREL 4634 || fixP->fx_r_type == BFD_RELOC_16_PCREL 4635 || fixP->fx_r_type == BFD_RELOC_8_PCREL) 4636 && !use_rela_relocations) 4637 { 4638 /* This is a hack. There should be a better way to handle this. 4639 This covers for the fact that bfd_install_relocation will 4640 subtract the current location (for partial_inplace, PC relative 4641 relocations); see more below. */ 4232 4642 #ifndef OBJ_AOUT 4233 4643 if (OUTPUT_FLAVOR == bfd_target_elf_flavour … … 4241 4651 if (OUTPUT_FLAVOR == bfd_target_elf_flavour) 4242 4652 { 4243 segT fseg = S_GET_SEGMENT (fixP->fx_addsy);4244 4245 if (( fseg == seg4653 segT sym_seg = S_GET_SEGMENT (fixP->fx_addsy); 4654 4655 if ((sym_seg == seg 4246 4656 || (symbol_section_p (fixP->fx_addsy) 4247 && fseg != absolute_section)) 4248 && ! S_IS_EXTERNAL (fixP->fx_addsy) 4249 && ! S_IS_WEAK (fixP->fx_addsy) 4250 && S_IS_DEFINED (fixP->fx_addsy) 4251 && ! S_IS_COMMON (fixP->fx_addsy)) 4657 && sym_seg != absolute_section)) 4658 && !generic_force_reloc (fixP)) 4252 4659 { 4253 4660 /* Yes, we add the values in twice. This is because 4254 bfd_ perform_relocation subtracts them out again. I think4255 bfd_ perform_relocation is broken, but I don't dare change4661 bfd_install_relocation subtracts them out again. I think 4662 bfd_install_relocation is broken, but I don't dare change 4256 4663 it. FIXME. */ 4257 4664 value += fixP->fx_where + fixP->fx_frag->fr_address; … … 4280 4687 value = -4; 4281 4688 break; 4282 case BFD_RELOC_386_GOTPC: 4283 4284 /* This is tough to explain. We end up with this one if we have 4285 * operands that look like "_GLOBAL_OFFSET_TABLE_+[.-.L284]". The goal 4286 * here is to obtain the absolute address of the GOT, and it is strongly 4287 * preferable from a performance point of view to avoid using a runtime 4288 * relocation for this. The actual sequence of instructions often look 4289 * something like: 4290 * 4291 * call .L66 4292 * .L66: 4293 * popl %ebx 4294 * addl $_GLOBAL_OFFSET_TABLE_+[.-.L66],%ebx 4295 * 4296 * The call and pop essentially return the absolute address of 4297 * the label .L66 and store it in %ebx. The linker itself will 4298 * ultimately change the first operand of the addl so that %ebx points to 4299 * the GOT, but to keep things simple, the .o file must have this operand 4300 * set so that it generates not the absolute address of .L66, but the 4301 * absolute address of itself. This allows the linker itself simply 4302 * treat a GOTPC relocation as asking for a pcrel offset to the GOT to be 4303 * added in, and the addend of the relocation is stored in the operand 4304 * field for the instruction itself. 4305 * 4306 * Our job here is to fix the operand so that it would add the correct 4307 * offset so that %ebx would point to itself. The thing that is tricky is 4308 * that .-.L66 will point to the beginning of the instruction, so we need 4309 * to further modify the operand so that it will point to itself. 4310 * There are other cases where you have something like: 4311 * 4312 * .long $_GLOBAL_OFFSET_TABLE_+[.-.L66] 4313 * 4314 * and here no correction would be required. Internally in the assembler 4315 * we treat operands of this form as not being pcrel since the '.' is 4316 * explicitly mentioned, and I wonder whether it would simplify matters 4317 * to do it this way. Who knows. In earlier versions of the PIC patches, 4318 * the pcrel_adjust field was used to store the correction, but since the 4319 * expression is not pcrel, I felt it would be confusing to do it this 4320 * way. */ 4321 4322 value -= 1; 4689 4690 case BFD_RELOC_386_TLS_GD: 4691 case BFD_RELOC_386_TLS_LDM: 4692 case BFD_RELOC_386_TLS_IE_32: 4693 case BFD_RELOC_386_TLS_IE: 4694 case BFD_RELOC_386_TLS_GOTIE: 4695 case BFD_RELOC_X86_64_TLSGD: 4696 case BFD_RELOC_X86_64_TLSLD: 4697 case BFD_RELOC_X86_64_GOTTPOFF: 4698 value = 0; /* Fully resolved at runtime. No addend. */ 4699 /* Fallthrough */ 4700 case BFD_RELOC_386_TLS_LE: 4701 case BFD_RELOC_386_TLS_LDO_32: 4702 case BFD_RELOC_386_TLS_LE_32: 4703 case BFD_RELOC_X86_64_DTPOFF32: 4704 case BFD_RELOC_X86_64_TPOFF32: 4705 S_SET_THREAD_LOCAL (fixP->fx_addsy); 4323 4706 break; 4707 4324 4708 case BFD_RELOC_386_GOT32: 4325 4709 case BFD_RELOC_X86_64_GOT32: 4326 4710 value = 0; /* Fully resolved at runtime. No addend. */ 4327 4711 break; 4328 case BFD_RELOC_386_GOTOFF:4329 case BFD_RELOC_X86_64_GOTPCREL:4330 break;4331 4712 4332 4713 case BFD_RELOC_VTABLE_INHERIT: 4333 4714 case BFD_RELOC_VTABLE_ENTRY: 4334 4715 fixP->fx_done = 0; 4335 return 1;4716 return; 4336 4717 4337 4718 default: … … 4339 4720 } 4340 4721 #endif /* defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) */ 4341 *val p= value;4722 *valP = value; 4342 4723 #endif /* defined (BFD_ASSEMBLER) && !defined (TE_Mach) */ 4343 4724 4344 #ifndef BFD_ASSEMBLER 4725 /* Are we finished with this relocation now? */ 4726 if (fixP->fx_addsy == NULL) 4727 fixP->fx_done = 1; 4728 #ifdef BFD_ASSEMBLER 4729 else if (use_rela_relocations) 4730 { 4731 fixP->fx_no_overflow = 1; 4732 /* Remember value for tc_gen_reloc. */ 4733 fixP->fx_addnumber = value; 4734 value = 0; 4735 } 4736 #endif 4345 4737 md_number_to_chars (p, value, fixP->fx_size); 4346 #else4347 /* Are we finished with this relocation now? */4348 if (fixP->fx_addsy == 0 && fixP->fx_pcrel == 0)4349 fixP->fx_done = 1;4350 else if (use_rela_relocations)4351 {4352 fixP->fx_no_overflow = 1;4353 value = 0;4354 }4355 md_number_to_chars (p, value, fixP->fx_size);4356 #endif4357 4358 return 1;4359 4738 } 4360 4739 … … 4421 4800 int c; 4422 4801 { 4423 if ( isprint(c))4802 if (ISPRINT (c)) 4424 4803 sprintf (output_invalid_buf, "'%c'", c); 4425 4804 else … … 4492 4871 } 4493 4872 4873 if (r != NULL 4874 && (r->reg_flags & (RegRex64 | RegRex)) != 0 4875 && flag_code != CODE_64BIT) 4876 { 4877 return (const reg_entry *) NULL; 4878 } 4879 4494 4880 return r; 4495 4881 } … … 4552 4938 case 's': 4553 4939 /* -s: On i386 Solaris, this tells the native assembler to use 4554 4940 .stab instead of .stab.excl. We always use .stab anyhow. */ 4555 4941 break; 4556 4942 … … 4640 5026 if (flag_code == CODE_64BIT) 4641 5027 use_rela_relocations = 1; 4642 return flag_code == CODE_64BIT ? "elf64-x86-64" : "elf32-i386";5028 return flag_code == CODE_64BIT ? "elf64-x86-64" : ELF_TARGET_FORMAT; 4643 5029 } 4644 5030 #endif … … 4650 5036 4651 5037 #endif /* OBJ_MAYBE_ more than one */ 5038 5039 #if (defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)) 5040 void i386_elf_emit_arch_note () 5041 { 5042 if (OUTPUT_FLAVOR == bfd_target_elf_flavour 5043 && cpu_arch_name != NULL) 5044 { 5045 char *p; 5046 asection *seg = now_seg; 5047 subsegT subseg = now_subseg; 5048 Elf_Internal_Note i_note; 5049 Elf_External_Note e_note; 5050 asection *note_secp; 5051 int len; 5052 5053 /* Create the .note section. */ 5054 note_secp = subseg_new (".note", 0); 5055 bfd_set_section_flags (stdoutput, 5056 note_secp, 5057 SEC_HAS_CONTENTS | SEC_READONLY); 5058 5059 /* Process the arch string. */ 5060 len = strlen (cpu_arch_name); 5061 5062 i_note.namesz = len + 1; 5063 i_note.descsz = 0; 5064 i_note.type = NT_ARCH; 5065 p = frag_more (sizeof (e_note.namesz)); 5066 md_number_to_chars (p, (valueT) i_note.namesz, sizeof (e_note.namesz)); 5067 p = frag_more (sizeof (e_note.descsz)); 5068 md_number_to_chars (p, (valueT) i_note.descsz, sizeof (e_note.descsz)); 5069 p = frag_more (sizeof (e_note.type)); 5070 md_number_to_chars (p, (valueT) i_note.type, sizeof (e_note.type)); 5071 p = frag_more (len + 1); 5072 strcpy (p, cpu_arch_name); 5073 5074 frag_align (2, 0, 0); 5075 5076 subseg_set (seg, subseg); 5077 } 5078 } 5079 #endif 4652 5080 #endif /* BFD_ASSEMBLER */ 4653 5081 … … 4718 5146 int ignore ATTRIBUTE_UNUSED; 4719 5147 { 4720 registerint temp;5148 int temp; 4721 5149 4722 5150 temp = get_absolute_expression (); … … 4769 5197 case BFD_RELOC_386_GOTOFF: 4770 5198 case BFD_RELOC_386_GOTPC: 5199 case BFD_RELOC_386_TLS_GD: 5200 case BFD_RELOC_386_TLS_LDM: 5201 case BFD_RELOC_386_TLS_LDO_32: 5202 case BFD_RELOC_386_TLS_IE_32: 5203 case BFD_RELOC_386_TLS_IE: 5204 case BFD_RELOC_386_TLS_GOTIE: 5205 case BFD_RELOC_386_TLS_LE_32: 5206 case BFD_RELOC_386_TLS_LE: 4771 5207 case BFD_RELOC_X86_64_32S: 5208 case BFD_RELOC_X86_64_TLSGD: 5209 case BFD_RELOC_X86_64_TLSLD: 5210 case BFD_RELOC_X86_64_DTPOFF32: 5211 case BFD_RELOC_X86_64_GOTTPOFF: 5212 case BFD_RELOC_X86_64_TPOFF32: 4772 5213 case BFD_RELOC_RVA: 4773 5214 case BFD_RELOC_VTABLE_ENTRY: … … 4781 5222 { 4782 5223 default: 4783 as_bad (_("can not do %d byte pc-relative relocation"), 4784 fixp->fx_size); 5224 as_bad_where (fixp->fx_file, fixp->fx_line, 5225 _("can not do %d byte pc-relative relocation"), 5226 fixp->fx_size); 4785 5227 code = BFD_RELOC_32_PCREL; 4786 5228 break; … … 4795 5237 { 4796 5238 default: 4797 as_bad (_("can not do %d byte relocation"), fixp->fx_size); 5239 as_bad_where (fixp->fx_file, fixp->fx_line, 5240 _("can not do %d byte relocation"), 5241 fixp->fx_size); 4798 5242 code = BFD_RELOC_32; 4799 5243 break; … … 4801 5245 case 2: code = BFD_RELOC_16; break; 4802 5246 case 4: code = BFD_RELOC_32; break; 5247 #ifdef BFD64 4803 5248 case 8: code = BFD_RELOC_64; break; 5249 #endif 4804 5250 } 4805 5251 } … … 4829 5275 rel->address = fixp->fx_offset; 4830 5276 4831 if (fixp->fx_pcrel) 4832 rel->addend = fixp->fx_addnumber; 4833 else 4834 rel->addend = 0; 5277 rel->addend = 0; 4835 5278 } 4836 5279 /* Use the rela in 64bit mode. */ 4837 5280 else 4838 5281 { 4839 rel->addend = fixp->fx_offset; 4840 if (fixp->fx_pcrel) 4841 rel->addend -= fixp->fx_size; 5282 if (!fixp->fx_pcrel) 5283 rel->addend = fixp->fx_offset; 5284 else 5285 switch (code) 5286 { 5287 case BFD_RELOC_X86_64_PLT32: 5288 case BFD_RELOC_X86_64_GOT32: 5289 case BFD_RELOC_X86_64_GOTPCREL: 5290 case BFD_RELOC_X86_64_TLSGD: 5291 case BFD_RELOC_X86_64_TLSLD: 5292 case BFD_RELOC_X86_64_GOTTPOFF: 5293 rel->addend = fixp->fx_offset - fixp->fx_size; 5294 break; 5295 default: 5296 rel->addend = (section->vma 5297 - fixp->fx_size 5298 + fixp->fx_addnumber 5299 + md_pcrel_from (fixp)); 5300 break; 5301 } 4842 5302 } 4843 5303 … … 4856 5316 } 4857 5317 4858 #else /* ! 5318 #else /* !BFD_ASSEMBLER */ 4859 5319 4860 5320 #if (defined(OBJ_AOUT) | defined(OBJ_BOUT)) … … 4922 5382 #endif /* I386COFF */ 4923 5383 4924 #endif /* ! 5384 #endif /* !BFD_ASSEMBLER */ 4925 5385 4926 5386 -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/binutils/gas/config/tc-i386.h
-
Property cvs2svn:cvs-rev
changed from
1.2
to1.3
r617 r618 1 1 /* tc-i386.h -- Header file for tc-i386.c 2 2 Copyright 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 3 2001 3 2001, 2002, 2003 4 4 Free Software Foundation, Inc. 5 5 … … 35 35 36 36 #ifdef BFD_ASSEMBLER 37 /* This is used to determine relocation types in tc-i386.c. The first38 parameter is the current relocation type, the second one is the desired39 type. The idea is that if the original type is already some kind of PIC40 relocation, we leave it alone, otherwise we give it the desired type */41 42 #define tc_fix_adjustable(X) tc_i386_fix_adjustable(X)43 extern int tc_i386_fix_adjustable PARAMS ((struct fix *));44 45 #if (defined (OBJ_MAYBE_ELF) || defined (OBJ_ELF) || defined (OBJ_MAYBE_COFF) || defined (OBJ_COFF)) && !defined (TE_PE)46 /* This arranges for gas/write.c to not apply a relocation if47 tc_fix_adjustable() says it is not adjustable.48 The "! symbol_used_in_reloc_p" test is there specifically to cover49 the case of non-global symbols in linkonce sections. It's the50 generally correct thing to do though; If a reloc is going to be51 emitted against a symbol then we don't want to adjust the fixup by52 applying the reloc during assembly. The reloc will be applied by53 the linker during final link. */54 #define TC_FIX_ADJUSTABLE(fixP) \55 (! symbol_used_in_reloc_p ((fixP)->fx_addsy) && tc_fix_adjustable (fixP))56 #endif57 58 /* This expression evaluates to false if the relocation is for a local object59 for which we still want to do the relocation at runtime. True if we60 are willing to perform this relocation while building the .o file.61 This is only used for pcrel relocations, so GOTOFF does not need to be62 checked here. I am not sure if some of the others are ever used with63 pcrel, but it is easier to be safe than sorry. */64 65 #define TC_RELOC_RTSYM_LOC_FIXUP(FIX) \66 ((FIX)->fx_r_type != BFD_RELOC_386_PLT32 \67 && (FIX)->fx_r_type != BFD_RELOC_386_GOT32 \68 && (FIX)->fx_r_type != BFD_RELOC_386_GOTPC \69 && ((FIX)->fx_addsy == NULL \70 || (! S_IS_EXTERNAL ((FIX)->fx_addsy) \71 && ! S_IS_WEAK ((FIX)->fx_addsy) \72 && S_IS_DEFINED ((FIX)->fx_addsy) \73 && ! S_IS_COMMON ((FIX)->fx_addsy))))74 75 37 #define TARGET_ARCH bfd_arch_i386 76 38 #define TARGET_MACH (i386_mach ()) … … 100 62 #ifndef AOUT_TARGET_FORMAT 101 63 #define AOUT_TARGET_FORMAT "a.out-i386" 64 #endif 65 66 #ifdef TE_FreeBSD 67 #define ELF_TARGET_FORMAT "elf32-i386-freebsd" 68 #endif 69 #ifndef ELF_TARGET_FORMAT 70 #define ELF_TARGET_FORMAT "elf32-i386" 102 71 #endif 103 72 … … 108 77 #else 109 78 #ifdef OBJ_ELF 110 #define TARGET_FORMAT "elf32-i386"79 #define TARGET_FORMAT ELF_TARGET_FORMAT 111 80 #endif 112 81 #ifdef OBJ_AOUT … … 114 83 #endif 115 84 #endif 85 86 #if (defined (OBJ_MAYBE_ELF) || defined (OBJ_ELF)) 87 #define md_end i386_elf_emit_arch_note 88 extern void i386_elf_emit_arch_note PARAMS ((void)); 89 #endif 90 91 #define SUB_SEGMENT_ALIGN(SEG, FRCHAIN) 0 116 92 117 93 #else /* ! BFD_ASSEMBLER */ … … 123 99 #define COFF_FLAGS F_AR32WR 124 100 #define TC_COUNT_RELOC(x) ((x)->fx_addsy || (x)->fx_r_type==7) 125 #define TC_COFF_FIX2RTYPE( fixP) tc_coff_fix2rtype(fixP)101 #define TC_COFF_FIX2RTYPE(FIX) tc_coff_fix2rtype(FIX) 126 102 extern short tc_coff_fix2rtype PARAMS ((struct fix *)); 127 #define TC_COFF_SIZEMACHDEP(frag) tc_coff_sizemachdep (frag)103 #define TC_COFF_SIZEMACHDEP(frag) tc_coff_sizemachdep (frag) 128 104 extern int tc_coff_sizemachdep PARAMS ((fragS *frag)); 129 105 130 106 #ifdef TE_GO32 131 107 /* DJGPP now expects some sections to be 2**4 aligned. */ 132 #define SUB_SEGMENT_ALIGN(SEG )\108 #define SUB_SEGMENT_ALIGN(SEG, FRCHAIN) \ 133 109 ((strcmp (obj_segment_name (SEG), ".text") == 0 \ 134 110 || strcmp (obj_segment_name (SEG), ".data") == 0 \ … … 140 116 : 2) 141 117 #else 142 #define SUB_SEGMENT_ALIGN(SEG) 2 143 #endif 144 145 #define TC_RVA_RELOC 7 146 /* Need this for PIC relocations */ 147 #define NEED_FX_R_TYPE 118 #define SUB_SEGMENT_ALIGN(SEG, FRCHAIN) 2 119 #endif 148 120 149 121 #ifdef TE_386BSD … … 155 127 #endif 156 128 157 #undef REVERSE_SORT_RELOCS158 159 #endif /* ! BFD_ASSEMBLER */160 161 #ifndef LEX_AT162 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) x86_cons (EXP, NBYTES)163 extern void x86_cons PARAMS ((expressionS *, int));164 165 #define TC_CONS_FIX_NEW(FRAG,OFF,LEN,EXP) x86_cons_fix_new(FRAG, OFF, LEN, EXP)166 extern void x86_cons_fix_new167 PARAMS ((fragS *, unsigned int, unsigned int, expressionS *));168 #endif169 170 #define TC_FORCE_RELOCATION(fixp) tc_i386_force_relocation(fixp)171 extern int tc_i386_force_relocation PARAMS ((struct fix *));172 173 #ifdef BFD_ASSEMBLER174 #define NO_RELOC BFD_RELOC_NONE175 #else176 #define NO_RELOC 0177 #endif178 #define tc_coff_symbol_emit_hook(a) ; /* not used */179 180 #ifndef BFD_ASSEMBLER181 129 #ifndef OBJ_AOUT 182 130 #ifndef TE_PE … … 188 136 #endif 189 137 #endif 190 #endif191 192 #define LOCAL_LABELS_FB 1193 138 194 139 #define tc_aout_pre_write_hook(x) {;} /* not used */ 195 140 #define tc_crawl_symbol_chain(a) {;} /* not used */ 196 141 #define tc_headers_hook(a) {;} /* not used */ 142 #define tc_coff_symbol_emit_hook(a) {;} /* not used */ 143 144 #endif /* ! BFD_ASSEMBLER */ 145 146 #define LOCAL_LABELS_FB 1 197 147 198 148 extern const char extra_symbol_chars[]; … … 297 247 #define CpuSSE2 0x2000 /* Streaming SIMD extensions 2 required */ 298 248 #define Cpu3dnow 0x4000 /* 3dnow! support required */ 299 #define CpuUnknown 0x8000 /* The CPU is unknown, be on the safe side. */300 249 301 250 /* These flags are set by gas depending on the flag_code. */ … … 467 416 468 417 /* x86-64 extension prefix. */ 469 typedef struct 470 { 471 unsigned int mode64; 472 unsigned int extX; /* Used to extend modrm reg field. */ 473 unsigned int extY; /* Used to extend SIB index field. */ 474 unsigned int extZ; /* Used to extend modrm reg/mem, SIB base, modrm base fields. */ 475 unsigned int empty; /* Used to old-style byte registers to new style. */ 476 } 477 rex_byte; 418 typedef int rex_byte; 419 #define REX_OPCODE 0x40 420 421 /* Indicates 64 bit operand size. */ 422 #define REX_MODE64 8 423 /* High extension to reg field of modrm byte. */ 424 #define REX_EXTX 4 425 /* High extension to SIB index field. */ 426 #define REX_EXTY 2 427 /* High extension to base field of modrm or SIB, or reg field of opcode. */ 428 #define REX_EXTZ 1 478 429 479 430 /* 386 opcode byte to code indirect addressing. */ … … 500 451 #endif 501 452 453 #ifndef LEX_AT 454 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) x86_cons (EXP, NBYTES) 455 extern void x86_cons PARAMS ((expressionS *, int)); 456 457 #define TC_CONS_FIX_NEW(FRAG,OFF,LEN,EXP) x86_cons_fix_new(FRAG, OFF, LEN, EXP) 458 extern void x86_cons_fix_new 459 PARAMS ((fragS *, unsigned int, unsigned int, expressionS *)); 460 #endif 461 462 #define DIFF_EXPR_OK /* foo-. gets turned into PC relative relocs */ 463 502 464 #ifdef BFD_ASSEMBLER 465 #define NO_RELOC BFD_RELOC_NONE 466 503 467 void i386_validate_fix PARAMS ((struct fix *)); 504 #define TC_VALIDATE_FIX(FIXP,SEGTYPE,SKIP) i386_validate_fix(FIXP) 505 #endif 506 507 #endif /* TC_I386 */ 468 #define TC_VALIDATE_FIX(FIX,SEGTYPE,SKIP) i386_validate_fix(FIX) 469 470 #define tc_fix_adjustable(X) tc_i386_fix_adjustable(X) 471 extern int tc_i386_fix_adjustable PARAMS ((struct fix *)); 472 473 /* Values passed to md_apply_fix3 don't include the symbol value. */ 474 #define MD_APPLY_SYM_VALUE(FIX) 0 475 476 /* ELF wants external syms kept, as does PE COFF. */ 477 #if defined (TE_PE) && defined (STRICT_PE_FORMAT) 478 #define EXTERN_FORCE_RELOC \ 479 (OUTPUT_FLAVOR == bfd_target_elf_flavour \ 480 || OUTPUT_FLAVOR == bfd_target_coff_flavour) 481 #else 482 #define EXTERN_FORCE_RELOC \ 483 (OUTPUT_FLAVOR == bfd_target_elf_flavour) 484 #endif 485 486 /* This expression evaluates to true if the relocation is for a local 487 object for which we still want to do the relocation at runtime. 488 False if we are willing to perform this relocation while building 489 the .o file. GOTOFF does not need to be checked here because it is 490 not pcrel. I am not sure if some of the others are ever used with 491 pcrel, but it is easier to be safe than sorry. */ 492 493 #define TC_FORCE_RELOCATION_LOCAL(FIX) \ 494 (!(FIX)->fx_pcrel \ 495 || (FIX)->fx_plt \ 496 || (FIX)->fx_r_type == BFD_RELOC_386_PLT32 \ 497 || (FIX)->fx_r_type == BFD_RELOC_386_GOT32 \ 498 || (FIX)->fx_r_type == BFD_RELOC_386_GOTPC \ 499 || TC_FORCE_RELOCATION (FIX)) 500 501 #else /* ! BFD_ASSEMBLER */ 502 503 #define NO_RELOC 0 504 505 #define TC_RVA_RELOC 7 506 507 /* Need this for PIC relocations */ 508 #define NEED_FX_R_TYPE 509 510 #undef REVERSE_SORT_RELOCS 511 512 /* For COFF. */ 513 #define TC_FORCE_RELOCATION(FIX) \ 514 ((FIX)->fx_r_type == 7 || generic_force_reloc (FIX)) 515 #endif /* ! BFD_ASSEMBLER */ 508 516 509 517 #define md_operand(x) … … 531 539 - fragP->fr_fix)); 532 540 533 /* call md_apply_fix3 with segment instead of md_apply_fix */534 #define MD_APPLY_FIX3535 536 541 void i386_print_statistics PARAMS ((FILE *)); 537 542 #define tc_print_statistics i386_print_statistics … … 544 549 #endif 545 550 546 # define DIFF_EXPR_OK /* foo-. gets turned into PC relative relocs*/551 #endif /* TC_I386 */ -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/binutils/gas/configure.in
-
Property cvs2svn:cvs-rev
changed from
1.2
to1.3
r617 r618 45 45 using_cgen=no 46 46 47 build_warnings="-W -Wall "47 build_warnings="-W -Wall -Wstrict-prototypes -Wmissing-prototypes" 48 48 AC_ARG_ENABLE(build-warnings, 49 49 [ --enable-build-warnings Enable build-time compiler warnings if gcc is used], … … 73 73 GDBINIT=".gdbinit" 74 74 case "${host}" in 75 *-*-msdos* | *-*-go32* | *-*-mingw32* | *-*- cygwin* | *-*-windows*)75 *-*-msdos* | *-*-go32* | *-*-mingw32* | *-*-windows*) 76 76 GDBINIT="gdb.ini" 77 77 ;; … … 116 116 case ${cpu} in 117 117 alpha*) cpu_type=alpha ;; 118 armeb) cpu_type=arm endian=big ;; 119 arm*) cpu_type=arm endian=little ;; 120 armb*) cpu_type=arm endian=little ;; 121 armv*l) cpu_type=arm endian=little ;; 122 armv*b) cpu_type=arm endian=big ;; 123 xscale*) cpu_type=arm endian=little ;; 124 strongarm*) cpu_type=arm endian=little ;; 125 thumb*) cpu_type=arm endian=little ;; 118 arm*b|xscale*b|strongarm*b) cpu_type=arm endian=big ;; 119 arm*|xscale*|strongarm*) cpu_type=arm endian=little ;; 126 120 hppa*) cpu_type=hppa ;; 127 121 changequote(,)dnl … … 129 123 x86_64) cpu_type=i386 arch=x86_64;; 130 124 ia64) cpu_type=ia64 ;; 125 ip2k) cpu_type=ip2k endian=big ;; 126 iq2000) cpu_type=iq2000 endian=big ;; 131 127 m6811|m6812|m68hc12) cpu_type=m68hc11 ;; 132 128 m680[012346]0) cpu_type=m68k ;; … … 138 134 mips*el) cpu_type=mips endian=little ;; 139 135 mips*) cpu_type=mips endian=big ;; 136 or32*) cpu_type=or32 endian=big ;; 140 137 pjl*) cpu_type=pj endian=little ;; 141 138 pj*) cpu_type=pj endian=big ;; 142 powerpc le*) cpu_type=ppc endian=little ;;139 powerpc*le*) cpu_type=ppc endian=little ;; 143 140 powerpc*) cpu_type=ppc endian=big ;; 144 141 rs6000*) cpu_type=ppc ;; 142 s390x*) cpu_type=s390 arch=s390x ;; 143 s390*) cpu_type=s390 arch=s390 ;; 144 sh5*) cpu_type=sh64 endian=big ;; 145 sh5le*) cpu_type=sh64 endian=little ;; 146 sh64*) cpu_type=sh64 endian=big ;; 147 sh64le*) cpu_type=sh64 endian=little ;; 148 sh*le) cpu_type=sh endian=little ;; 149 sh*) cpu_type=sh endian=big ;; 145 150 sparclite*) cpu_type=sparc arch=sparclite ;; 146 151 sparclet*) cpu_type=sparc arch=sparclet ;; … … 149 154 sparc*) cpu_type=sparc arch=sparclite ;; # ??? See tc-sparc.c. 150 155 v850*) cpu_type=v850 ;; 156 xtensa*) cpu_type=xtensa arch=xtensa ;; 151 157 *) cpu_type=${cpu} ;; 152 158 esac … … 165 171 # assign object format 166 172 case ${generic_target} in 167 a29k-*-coff) fmt=coff ;; 168 a29k-amd-udi) fmt=coff ;; 169 a29k-amd-ebmon) fmt=coff ;; 170 a29k-nyu-sym1) fmt=coff ;; 171 a29k-*-rtems*) fmt=coff ;; 172 a29k-*-vxworks*) fmt=coff ;; 173 174 alpha*-*-*vms*) fmt=evax ;; 175 alpha*-*-netware*) fmt=ecoff ;; 176 alpha*-*-openbsd*) fmt=ecoff ;; 177 alpha*-*-osf*) fmt=ecoff ;; 178 alpha*-*-linuxecoff*) fmt=ecoff ;; 179 alpha*-*-linux-gnu*) fmt=elf em=linux ;; 180 alpha*-*-netbsd*) fmt=elf em=nbsd ;; 181 182 arc-*-elf*) fmt=elf bfd_gas=yes ;; 183 184 arm-*-aout) fmt=aout ;; 185 arm-*-coff | thumb-*-coff) fmt=coff ;; 186 arm-*-rtems | thumb-*-rtems) fmt=elf ;; 187 arm-*-elf | thumb-*-elf) fmt=elf ;; 173 a29k-*-coff) fmt=coff ;; 174 a29k-amd-udi) fmt=coff ;; 175 a29k-amd-ebmon) fmt=coff ;; 176 a29k-nyu-sym1) fmt=coff ;; 177 a29k-*-rtems*) fmt=coff ;; 178 a29k-*-vxworks*) fmt=coff ;; 179 180 alpha*-*-*vms*) fmt=evax ;; 181 alpha*-*-netware*) fmt=ecoff ;; 182 alpha*-*-osf*) fmt=ecoff ;; 183 alpha*-*-linuxecoff*) fmt=ecoff ;; 184 alpha*-*-linux-gnu*) fmt=elf em=linux ;; 185 alpha*-*-netbsd*) fmt=elf em=nbsd ;; 186 alpha*-*-openbsd*) fmt=elf em=obsd ;; 187 188 arc-*-elf*) fmt=elf ;; 189 190 arm-*-aout) fmt=aout ;; 191 arm-*-coff | thumb-*-coff) fmt=coff ;; 192 arm-*-rtems | thumb-*-rtems) fmt=elf ;; 193 arm-*-elf | thumb-*-elf) fmt=elf ;; 194 arm-*-kaos*) fmt=elf ;; 188 195 arm*-*-conix*) fmt=elf ;; 189 arm-*-linux*aout*) fmt=aout em=linux ;; 190 arm*-*-linux-gnu* | arm*-*-uclinux*) 191 fmt=elf em=linux ;; 192 arm-*-netbsd*) fmt=aout em=nbsd ;; 193 arm-*-oabi | thumb-*-oabi) fmt=elf ;; 194 arm-epoc-pe | thumb-epoc-pe) fmt=coff em=epoc-pe ;; 196 arm-*-linux*aout*) fmt=aout em=linux ;; 197 arm*-*-linux-gnu*) fmt=elf em=linux ;; 198 arm*-*-uclinux*) fmt=elf em=linux ;; 199 arm-*-netbsdelf*) fmt=elf em=nbsd ;; 200 arm-*-*n*bsd*) fmt=aout em=nbsd ;; 201 arm-**-nto*) fmt=elf ;; 202 arm-*-oabi | thumb-*-oabi) fmt=elf ;; 203 arm-epoc-pe | thumb-epoc-pe) fmt=coff em=epoc-pe ;; 195 204 arm-*-wince) fmt=coff em=wince-pe ;; 196 arm-*-pe | thumb-*-pe) fmt=coff em=pe ;; 197 arm-*-riscix*) fmt=aout em=riscix ;; 198 arm-*-vxworks) fmt=coff ;; 199 200 avr-*-*) fmt=elf bfd_gas=yes ;; 201 202 cris-*-*) fmt=multi bfd_gas=yes ;; 203 204 d10v-*-*) fmt=elf bfd_gas=yes ;; 205 d30v-*-*) fmt=elf bfd_gas=yes ;; 206 207 208 fr30-*-*) fmt=elf bfd_gas=yes ;; 209 210 hppa-*-linux-gnu*) case ${cpu} in 211 hppa*64*) 212 fmt=elf em=hppalinux64;; 213 hppa*) 214 fmt=elf em=linux;; 215 esac ;; 216 hppa-*-*elf*) fmt=elf em=hppa ;; 217 hppa-*-lites*) fmt=elf em=hppa ;; 218 hppa-*-osf*) fmt=som em=hppa ;; 219 hppa-*-rtems*) fmt=elf em=hppa ;; 220 hppa-*-hpux11*) case ${cpu} in 221 hppa*64*) 222 fmt=elf em=hppa64 ;; 223 hppa*) 224 fmt=som em=hppa ;; 225 esac ;; 226 hppa-*-hpux*) fmt=som em=hppa ;; 227 hppa-*-mpeix*) fmt=som em=hppa ;; 228 hppa-*-bsd*) fmt=som em=hppa ;; 229 hppa-*-hiux*) fmt=som em=hppa ;; 230 231 h8300-*-rtems*) fmt=coff ;; 232 h8300-*-coff) fmt=coff ;; 233 h8500-*-rtems*) fmt=coff ;; 234 h8500-*-coff) fmt=coff ;; 235 236 i370-*-elf* | i370-*-linux*) fmt=elf ;; 237 i386-ibm-aix*) fmt=coff em=i386aix ;; 238 i386-sequent-bsd*) fmt=aout em=dynix bfd_gas=yes ;; 239 i386-*-beospe*) fmt=coff em=pe bfd_gas=yes ;; 240 i386-*-beoself* | i386-*-beos*) fmt=elf bfd_gas=yes ;; 241 i386-*-bsd*) fmt=aout em=386bsd ;; 242 i386-*-netbsd0.8) fmt=aout em=386bsd ;; 243 i386-*-netbsd*) fmt=aout em=nbsd bfd_gas=yes;; 244 i386-*-openbsd*) fmt=aout em=nbsd bfd_gas=yes;; 245 i386-*-linux*aout* | i386-*-linux*oldld) fmt=aout em=linux ;; 246 i386-*-linux*coff*) fmt=coff em=linux ;; 247 i386-*-linux-gnu*) fmt=elf em=linux bfd_gas=yes ;; 248 x86_64-*-linux-gnu*) fmt=elf em=linux bfd_gas=yes ;; 249 i386-*-lynxos*) fmt=coff em=lynx ;; 205 arm-*-pe | thumb-*-pe) fmt=coff em=pe ;; 206 arm-*-riscix*) fmt=aout em=riscix ;; 207 arm-*-vxworks) fmt=coff ;; 208 209 avr-*-*) fmt=elf ;; 210 211 cris-*-*) fmt=multi bfd_gas=yes ;; 212 213 d10v-*-*) fmt=elf ;; 214 d30v-*-*) fmt=elf ;; 215 dlx-*-*) fmt=elf ;; 216 217 fr30-*-*) fmt=elf ;; 218 frv-*-*) fmt=elf ;; 219 220 hppa-*-linux*) case ${cpu} in 221 hppa*64*) fmt=elf em=hppalinux64;; 222 hppa*) fmt=elf em=linux;; 223 esac ;; 224 hppa-*-*elf*) fmt=elf em=hppa ;; 225 hppa-*-lites*) fmt=elf em=hppa ;; 226 hppa-*-netbsd*) fmt=elf em=nbsd ;; 227 hppa-*-openbsd*) fmt=elf em=hppa ;; 228 hppa-*-osf*) fmt=som em=hppa ;; 229 hppa-*-rtems*) fmt=elf em=hppa ;; 230 hppa-*-hpux11*) case ${cpu} in 231 hppa*64*) fmt=elf em=hppa64 ;; 232 hppa*) fmt=som em=hppa ;; 233 esac ;; 234 hppa-*-hpux*) fmt=som em=hppa ;; 235 hppa-*-mpeix*) fmt=som em=hppa ;; 236 hppa-*-bsd*) fmt=som em=hppa ;; 237 hppa-*-hiux*) fmt=som em=hppa ;; 238 239 h8300-*-rtems*) fmt=coff ;; 240 h8300-*-coff) fmt=coff ;; 241 h8300-*-elf) fmt=elf ;; 242 h8500-*-rtems*) fmt=coff ;; 243 h8500-*-coff) fmt=coff ;; 244 245 i370-*-elf* | i370-*-linux*) fmt=elf ;; 246 i386-ibm-aix*) fmt=coff em=i386aix ;; 247 i386-sequent-bsd*) fmt=aout em=dynix ;; 248 i386-*-beospe*) fmt=coff em=pe ;; 249 i386-*-beos*) fmt=elf ;; 250 i386-*-coff) fmt=coff ;; 251 i386-*-elf) fmt=elf ;; 252 i386-*-kaos*) fmt=elf ;; 253 i386-*-bsd*) fmt=aout em=386bsd ;; 254 i386-*-netbsd0.8) fmt=aout em=386bsd ;; 255 i386-*-netbsdpe*) fmt=coff em=pe ;; 256 i386-*-netbsdelf*) fmt=elf em=nbsd ;; 257 i386-*-*n*bsd*) case ${cpu} in 258 x86_64) fmt=elf em=nbsd ;; 259 *) fmt=aout em=nbsd ;; 260 esac ;; 261 i386-*-linux*aout*) fmt=aout em=linux ;; 262 i386-*-linux*oldld) fmt=aout em=linux ;; 263 i386-*-linux*coff*) fmt=coff em=linux ;; 264 i386-*-linux-gnu*) fmt=elf em=linux ;; 265 x86_64-*-linux-gnu*) fmt=elf em=linux ;; 266 i386-*-lynxos*) fmt=coff em=lynx ;; 250 267 changequote(,)dnl 251 i386-*-sysv[45]* | i386-*-solaris* | i386-*-elf) 252 fmt=elf bfd_gas=yes ;; 253 i386-*-freebsdaout* | i386-*-freebsd[12].* | i386-*-freebsd[12]) 254 fmt=aout em=386bsd ;; 268 i386-*-sysv[45]*) fmt=elf ;; 269 i386-*-solaris*) fmt=elf ;; 270 i386-*-freebsdaout*) fmt=aout em=386bsd ;; 271 i386-*-freebsd[12].*) fmt=aout em=386bsd ;; 272 i386-*-freebsd[12]) fmt=aout em=386bsd ;; 255 273 changequote([,])dnl 256 i386-*- coff | i386-*-sysv* | i386-*-sco3.2v5*coff | i386-*-isc*)257 258 i386-*- sco3.2v5*) fmt=elf259 if test ${this_target} = $target; then 260 AC_DEFINE(SCO_ELF, 1,261 262 fi263 264 i386-*- sco3.2*) fmt=coff;;265 i386-*- vsta) fmt=aout ;;266 i386-*-msdosdjgpp* | i386-*-go32* | i386-go32-rtems*)267 fmt=coff em=go32 bfd_gas=yes 268 AC_DEFINE(STRICTCOFF, 1, [Using strict COFF?])269 270 i386-*-rtems elf*) fmt=elf ;;271 i386-*-rtems*) fmt=coff ;;272 i386-*-gnu*) 273 i386-*-mach*) 274 fmt=aout em=mach bfd_gas=yes;;275 i386-*-m sdos*) fmt=aout;;276 i386-*- moss*) fmt=elf;;277 i386-*- pe) fmt=coff em=pe bfd_gas=yes;;278 i386-*- cygwin*) fmt=coff em=pe bfd_gas=yes;;279 i386-*- interix*) fmt=coff em=interix bfd_gas=yes;;280 i386-*- mingw32*) fmt=coff em=pe bfd_gas=yes;;281 i386-*-*nt*) fmt=coff em=pe bfd_gas=yes;;274 i386-*-sysv*) fmt=coff ;; 275 i386-*-sco3.2v5*coff) fmt=coff ;; 276 i386-*-isc*) fmt=coff ;; 277 i386-*-sco3.2v5*) fmt=elf 278 if test ${this_target} = $target; then 279 AC_DEFINE(SCO_ELF, 1, [Define if defaulting to ELF on SCO 5.]) 280 fi ;; 281 i386-*-sco3.2*) fmt=coff ;; 282 i386-*-vsta) fmt=aout ;; 283 i386-*-msdosdjgpp* \ 284 | i386-*-go32* \ 285 | i386-go32-rtems*) fmt=coff em=go32 286 AC_DEFINE(STRICTCOFF, 1, [Using strict COFF?]) ;; 287 i386-*-rtemself*) fmt=elf ;; 288 i386-*-rtemscoff*) fmt=coff ;; 289 i386-*-rtems*) fmt=elf ;; 290 i386-*-gnu*) fmt=elf ;; 291 i386-*-mach*) fmt=aout em=mach ;; 292 i386-*-msdos*) fmt=aout ;; 293 i386-*-moss*) fmt=elf ;; 294 i386-*-pe) fmt=coff em=pe ;; 295 i386-*-cygwin*) fmt=coff em=pe ;; 296 i386-*-interix*) fmt=coff em=interix ;; 297 i386-*-mingw32*) fmt=coff em=pe ;; 298 i386-*-nto-qnx*) fmt=elf ;; 299 i386-*-*nt*) fmt=coff em=pe ;; 282 300 i386-*-os2*) fmt=aout em=emx bfd_gas=yes ;; 283 i386-*-vxworks*) fmt=aout ;; 284 i386-*-chaos) fmt=elf ;; 285 i860-stardent-sysv4* | i860-stardent-elf*) 286 fmt=elf bfd_gas=yes endian=little 287 AC_MSG_WARN(GAS support for ${generic_target} is preliminary and a work in progress) ;; 288 i960-*-bout) fmt=bout ;; 289 i960-*-coff) fmt=coff em=ic960 ;; 290 i960-*-rtems*) fmt=coff em=ic960 ;; 291 i960-*-nindy*) fmt=bout ;; 292 i960-*-vxworks4*) fmt=bout ;; 293 i960-*-vxworks5.0) fmt=bout ;; 294 i960-*-vxworks5.*) fmt=coff em=ic960 ;; 295 i960-*-vxworks*) fmt=bout ;; 296 i960-*-elf*) fmt=elf ;; 297 298 ia64-*-elf*) fmt=elf ;; 299 ia64-*-linux-gnu*) fmt=elf em=linux ;; 300 ia64-*-hpux*) fmt=elf em=hpux ;; 301 302 m32r-*-*) fmt=elf bfd_gas=yes ;; 303 304 m68hc11-*-*|m6811-*-*|m68hc12-*-*|m6812-*-*)fmt=elf bfd_gas=yes ;; 305 306 m68k-*-vxworks* | m68k-ericsson-ose | m68k-*-sunos*) 307 fmt=aout em=sun3 ;; 308 m68k-motorola-sysv*) fmt=coff em=delta ;; 309 m68k-bull-sysv3*) fmt=coff em=dpx2 ;; 310 m68k-apollo-*) fmt=coff em=apollo ;; 311 m68k-*-sysv4*) # must be before -sysv* 312 fmt=elf em=svr4 ;; 313 m68k-*-elf*) fmt=elf ;; 314 m68k-*-coff | m68k-*-sysv* | m68k-*-rtems*) 315 fmt=coff ;; 316 m68k-*-hpux*) fmt=hp300 em=hp300 ;; 317 m68k-*-linux*aout*) fmt=aout em=linux ;; 318 m68k-*-linux-gnu*) fmt=elf em=linux ;; 319 m68k-*-gnu*) fmt=elf ;; 320 m68k-*-lynxos*) fmt=coff em=lynx ;; 321 m68k-*-netbsd*) fmt=aout em=nbsd bfd_gas=yes ;; 322 m68k-*-openbsd*) fmt=aout em=nbsd bfd_gas=yes ;; 323 m68k-apple-aux*) fmt=coff em=aux ;; 324 m68k-*-psos*) fmt=elf em=psos;; 325 326 m88k-motorola-sysv3*) fmt=coff em=delt88 ;; 327 m88k-*-coff*) fmt=coff ;; 328 329 mcore-*-elf) fmt=elf bfd_gas=yes ;; 330 mcore-*-pe) fmt=coff em=pe bfd_gas=yes ;; 301 i386-*-vxworks*) fmt=aout ;; 302 i386-*-chaos) fmt=elf ;; 303 304 i860-*-*) fmt=elf endian=little 305 AC_MSG_WARN(GAS support for ${generic_target} is preliminary and a work in progress) ;; 306 i960-*-bout) fmt=bout ;; 307 i960-*-coff) fmt=coff em=ic960 ;; 308 i960-*-rtems*) fmt=coff em=ic960 ;; 309 i960-*-nindy*) fmt=bout ;; 310 i960-*-vxworks5.0) fmt=bout ;; 311 i960-*-vxworks5.*) fmt=coff em=ic960 ;; 312 i960-*-vxworks*) fmt=bout ;; 313 i960-*-elf*) fmt=elf ;; 314 315 ia64-*-elf*) fmt=elf ;; 316 ia64-*-aix*) fmt=elf em=ia64aix ;; 317 ia64-*-linux-gnu*) fmt=elf em=linux ;; 318 ia64-*-hpux*) fmt=elf em=hpux ;; 319 ia64-*-netbsd*) fmt=elf em=nbsd ;; 320 321 ip2k-*-*) fmt=elf ;; 322 323 iq2000-*-elf) fmt=elf bfd_gas=yes ;; 324 325 m32r-*-*) fmt=elf ;; 326 327 m68hc11-*-* | m6811-*-*) fmt=elf ;; 328 m68hc12-*-* | m6812-*-*) fmt=elf ;; 329 330 m68k-*-vxworks*) fmt=aout em=sun3 ;; 331 m68k-ericsson-ose) fmt=aout em=sun3 ;; 332 m68k-*-sunos*) fmt=aout em=sun3 ;; 333 m68k-motorola-sysv*) fmt=coff em=delta ;; 334 m68k-bull-sysv3*) fmt=coff em=dpx2 ;; 335 m68k-apollo-*) fmt=coff em=apollo ;; 336 m68k-*-elf*) fmt=elf ;; 337 m68k-*-sysv4*) fmt=elf em=svr4 ;; 338 m68k-*-sysv*) fmt=coff ;; 339 m68k-*-coff | m68k-*-rtemscoff*) fmt=coff ;; 340 m68k-*-rtems*) fmt=elf ;; 341 m68k-*-hpux*) fmt=hp300 em=hp300 ;; 342 m68k-*-linux*aout*) fmt=aout em=linux ;; 343 m68k-*-linux-gnu*) fmt=elf em=linux ;; 344 m68k-*-gnu*) fmt=elf ;; 345 m68k-*-lynxos*) fmt=coff em=lynx ;; 346 m68k-*-netbsdelf*) fmt=elf em=nbsd ;; 347 m68k-*-netbsd*) fmt=aout em=nbsd bfd_gas=yes ;; 348 m68k-*-openbsd*) fmt=aout em=nbsd bfd_gas=yes ;; 349 m68k-apple-aux*) fmt=coff em=aux ;; 350 m68k-*-psos*) fmt=elf em=psos;; 351 352 m88k-motorola-sysv3*) fmt=coff em=delt88 ;; 353 m88k-*-coff*) fmt=coff ;; 354 355 mcore-*-elf) fmt=elf ;; 356 mcore-*-pe) fmt=coff em=pe bfd_gas=yes ;; 331 357 332 358 # don't change em like *-*-bsd does 333 mips-dec-netbsd*) fmt=elf endian=little ;; 334 mips-dec-openbsd*) fmt=elf endian=little ;; 335 mips-dec-bsd*) fmt=aout endian=little ;; 336 mips-sony-bsd*) fmt=ecoff ;; 337 mips-*-bsd*) AC_MSG_ERROR(Unknown vendor for mips-bsd configuration.) ;; 338 mips-*-ultrix*) fmt=ecoff endian=little ;; 339 mips-*-osf*) fmt=ecoff endian=little ;; 340 mips-*-ecoff*) fmt=ecoff ;; 341 mips-*-pe*) fmt=coff endian=little em=pe ;; 342 mips-*-irix6*) fmt=elf ;; 343 mips-*-irix5*) fmt=elf ;; 344 mips-*-irix*) fmt=ecoff ;; 345 mips-*-lnews*) fmt=ecoff em=lnews ;; 346 mips-*-riscos*) fmt=ecoff ;; 347 mips-*-linux-gnu*) 348 fmt=elf em=tmips 349 AC_DEFINE(MIPS_STABS_ELF, 1, 350 [Use ELF stabs for MIPS, not ECOFF stabs]) 351 ;; 352 mips-*-sysv4*MP* | mips-*-gnu*) 353 fmt=elf em=tmips ;; 354 mips-*-sysv*) fmt=ecoff ;; 355 mips-*-elf* | mips-*-rtems* | mips-*-openbsd*) 356 fmt=elf ;; 357 mips-*-vxworks*) fmt=elf 358 AC_DEFINE(MIPS_STABS_ELF, 1, 359 [Use ELF stabs for MIPS, not ECOFF stabs]) 360 ;; 361 mn10200-*-*) fmt=elf bfd_gas=yes ;; 362 mn10300-*-*) fmt=elf bfd_gas=yes ;; 363 pj*) fmt=elf ;; 364 ppc-*-pe | ppc-*-cygwin* | ppc-*-winnt*) 365 fmt=coff em=pe ;; 366 ppc-*-aix*) fmt=coff ;; 367 ppc-*-beos*) fmt=coff ;; 368 ppc-*-*bsd* | ppc-*-elf* | ppc-*-eabi* | ppc-*-sysv4*) 369 fmt=elf ;; 370 ppc-*-linux-gnu*) fmt=elf 371 case "$endian" in 372 big) ;; 373 *) AC_MSG_ERROR(GNU/Linux must be configured big endian) ;; 374 esac 375 ;; 376 ppc-*-solaris*) fmt=elf 377 if test ${this_target} = $target; then 378 AC_DEFINE(TARGET_SOLARIS_COMMENT, 1, 379 [Define if default target is PowerPC Solaris.]) 380 fi 381 if test x${endian} = xbig; then 382 AC_MSG_ERROR(Solaris must be configured little endian) 383 fi 384 ;; 385 ppc-*-rtems*) fmt=elf ;; 386 ppc-*-macos* | ppc-*-mpw*) 387 fmt=coff em=macos ;; 388 ppc-*-netware*) fmt=elf em=ppcnw ;; 389 ppc-*-vxworks*) fmt=elf ;; 390 391 sh-*-linux*) fmt=elf em=linux ;; 392 sh-*-elf*) fmt=elf ;; 393 sh-*-coff*) fmt=coff ;; 394 sh-*-pe*) fmt=coff em=pe bfd_gas=yes;; 395 sh-*-rtemself*) fmt=elf ;; 396 sh-*-rtems*) fmt=coff ;; 397 398 ns32k-pc532-mach* | ns32k-pc532-ux*) fmt=aout em=pc532mach ;; 399 ns32k-pc532-netbsd* | ns32k-pc532-lites*) fmt=aout em=nbsd532 ;; 400 ns32k-pc532-openbsd*) fmt=aout em=nbsd532 ;; 401 402 sparc-*-rtemsaout*) fmt=aout ;; 403 sparc-*-rtemself*) fmt=elf ;; 404 sparc-*-rtems*) fmt=elf ;; 405 sparc-*-sunos4*) fmt=aout em=sun3 ;; 406 sparc-*-aout | sparc*-*-vxworks*) 407 fmt=aout em=sparcaout ;; 408 sparc-*-coff) fmt=coff ;; 409 sparc-*-linux*aout*) fmt=aout em=linux ;; 410 sparc-*-linux-gnu*) fmt=elf em=linux ;; 411 sparc-*-lynxos*) fmt=coff em=lynx ;; 412 sparc-fujitsu-none) fmt=aout ;; 413 sparc-*-elf | sparc-*-sysv4* | sparc-*-solaris*) 414 fmt=elf ;; 415 sparc-*-netbsd*) em=nbsd bfd_gas=yes 416 case ${cpu} in 417 sparc) case ${os} in 418 *elf*) fmt=elf ;; 419 *) fmt=aout ;; 420 esac ;; 421 sparc64) fmt=elf ;; 422 esac 423 ;; 424 sparc-*-openbsd*) fmt=aout em=nbsd ;; 425 426 strongarm-*-coff) fmt=coff ;; 427 strongarm-*-elf) fmt=elf ;; 428 xscale-*-coff) fmt=coff ;; 429 xscale-*-elf) fmt=elf ;; 430 431 tic30-*-*aout*) fmt=aout bfd_gas=yes ;; 432 tic30-*-*coff*) fmt=coff bfd_gas=yes ;; 433 tic54x-*-* | c54x*-*-*) 434 fmt=coff bfd_gas=yes need_libm=yes;; 435 tic80-*-*) fmt=coff ;; 436 437 v850-*-*) fmt=elf bfd_gas=yes ;; 438 v850e-*-*) fmt=elf bfd_gas=yes ;; 439 v850ea-*-*) fmt=elf bfd_gas=yes ;; 440 441 vax-*-bsd* | vax-*-ultrix*) 442 fmt=aout ;; 443 vax-*-vms) fmt=vms ;; 444 445 446 z8k-*-coff | z8k-*-sim) 447 fmt=coff ;; 448 449 w65-*-*) fmt=coff ;; 450 451 *-*-aout | *-*-scout) 452 fmt=aout ;; 453 *-*-freebsd*) fmt=elf em=freebsd bfd_gas=yes ;; 454 *-*-nindy*) 455 fmt=bout ;; 456 *-*-bsd*) 457 fmt=aout em=sun3 ;; 458 *-*-generic) fmt=generic ;; 459 *-*-xray | *-*-hms) fmt=coff ;; 460 *-*-sim) fmt=coff ;; 461 *-*-elf | *-*-sysv4* | *-*-solaris*) 462 AC_MSG_WARN(GAS support for ${generic_target} is incomplete.) 463 fmt=elf dev=yes ;; 464 *-*-vxworks) fmt=aout ;; 465 *-*-netware) fmt=elf ;; 359 mips-dec-openbsd*) fmt=elf endian=little ;; 360 mips-dec-bsd*) fmt=aout endian=little ;; 361 mips-sony-bsd*) fmt=ecoff ;; 362 mips-*-bsd*) 363 AC_MSG_ERROR(Unknown vendor for mips-bsd configuration.) ;; 364 mips-*-ultrix*) fmt=ecoff endian=little ;; 365 mips-*-osf*) fmt=ecoff endian=little ;; 366 mips-*-ecoff*) fmt=ecoff ;; 367 mips-*-pe*) fmt=coff endian=little em=pe ;; 368 mips-*-irix6*) fmt=elf em=irix ;; 369 mips-*-irix5*) fmt=elf em=irix ;; 370 mips-*-irix*) fmt=ecoff em=irix ;; 371 mips-*-lnews*) fmt=ecoff em=lnews ;; 372 mips-*-riscos*) fmt=ecoff ;; 373 mips*-*-linux*) fmt=elf em=tmips ;; 374 mips-*-sysv4*MP* | mips-*-gnu*) fmt=elf em=tmips ;; 375 mips-*-sysv*) fmt=ecoff ;; 376 mips-*-elf* | mips-*-rtems*) fmt=elf ;; 377 mips-*-netbsd*) fmt=elf ;; 378 mips-*-openbsd*) fmt=elf ;; 379 mips-*-vxworks*) fmt=elf ;; 380 381 mmix-*-*) fmt=elf ;; 382 mn10200-*-*) fmt=elf ;; 383 mn10300-*-*) fmt=elf ;; 384 msp430-*-*) fmt=elf ;; 385 openrisc-*-*) fmt=elf ;; 386 or32-*-rtems*) fmt=coff ;; 387 or32-*-coff) fmt=coff ;; 388 or32-*-elf) fmt=elf ;; 389 pj*) fmt=elf ;; 390 391 ppc-*-pe | ppc-*-cygwin*) fmt=coff em=pe ;; 392 ppc-*-winnt*) fmt=coff em=pe ;; 393 ppc-*-aix5*) fmt=coff em=aix5 ;; 394 ppc-*-aix*) fmt=coff ;; 395 ppc-*-beos*) fmt=coff ;; 396 ppc-*-*n*bsd* | ppc-*-elf*) fmt=elf ;; 397 ppc-*-eabi* | ppc-*-sysv4*) fmt=elf ;; 398 ppc-*-linux-gnu*) fmt=elf 399 case "$endian" in 400 big) ;; 401 *) AC_MSG_ERROR(GNU/Linux must be configured big endian) ;; 402 esac ;; 403 ppc-*-solaris*) fmt=elf 404 if test ${this_target} = $target; then 405 AC_DEFINE(TARGET_SOLARIS_COMMENT, 1, 406 [Define if default target is PowerPC Solaris.]) 407 fi 408 if test x${endian} = xbig; then 409 AC_MSG_ERROR(Solaris must be configured little endian) 410 fi ;; 411 ppc-*-rtems*) fmt=elf ;; 412 ppc-*-macos* | ppc-*-mpw*) fmt=coff em=macos ;; 413 ppc-*-netware*) fmt=elf em=ppcnw ;; 414 ppc-**-nto*) fmt=elf ;; 415 ppc-*-vxworks*) fmt=elf ;; 416 ppc-*-windiss*) fmt=elf ;; 417 ppc-*-kaos*) fmt=elf ;; 418 419 s390x-*-linux-gnu*) fmt=elf em=linux ;; 420 s390-*-linux-gnu*) fmt=elf em=linux ;; 421 422 sh*-*-linux*) fmt=elf em=linux 423 case ${cpu} in 424 sh*eb) endian=big ;; 425 *) endian=little ;; 426 esac ;; 427 sh5*-*-netbsd*) fmt=elf em=nbsd ;; 428 sh64*-*-netbsd*) fmt=elf em=nbsd ;; 429 sh*-*-netbsdelf*) fmt=elf em=nbsd ;; 430 sh-*-elf*) fmt=elf ;; 431 sh-*-coff*) fmt=coff ;; 432 sh-*-nto*) fmt=elf ;; 433 sh-*-pe*) fmt=coff em=pe bfd_gas=yes endian=little ;; 434 sh-*-rtemself*) fmt=elf ;; 435 sh-*-rtems*) fmt=coff ;; 436 sh-*-kaos*) fmt=elf ;; 437 shle*-*-kaos*) fmt=elf ;; 438 sh64-*-elf*) fmt=elf ;; 439 440 ns32k-pc532-mach*) fmt=aout em=pc532mach ;; 441 ns32k-pc532-ux*) fmt=aout em=pc532mach ;; 442 ns32k-pc532-lites*) fmt=aout em=nbsd532 ;; 443 ns32k-*-*n*bsd*) fmt=aout em=nbsd532 ;; 444 445 sparc-*-rtemsaout*) fmt=aout ;; 446 sparc-*-rtemself*) fmt=elf ;; 447 sparc-*-rtems*) fmt=elf ;; 448 sparc-*-sunos4*) fmt=aout em=sun3 ;; 449 sparc-*-aout | sparc*-*-vxworks*) fmt=aout em=sparcaout ;; 450 sparc-*-coff) fmt=coff ;; 451 sparc-*-linux*aout*) fmt=aout em=linux ;; 452 sparc-*-linux-gnu*) fmt=elf em=linux ;; 453 sparc-*-lynxos*) fmt=coff em=lynx ;; 454 sparc-fujitsu-none) fmt=aout ;; 455 sparc-*-elf) fmt=elf ;; 456 sparc-*-sysv4*) fmt=elf ;; 457 sparc-*-solaris*) fmt=elf ;; 458 sparc-*-netbsdelf*) fmt=elf em=nbsd ;; 459 sparc-*-*n*bsd*) case ${cpu} in 460 sparc64) fmt=elf em=nbsd ;; 461 *) fmt=aout em=nbsd ;; 462 esac ;; 463 strongarm-*-coff) fmt=coff ;; 464 strongarm-*-elf) fmt=elf ;; 465 strongarm-*-kaos*) fmt=elf ;; 466 xscale-*-coff) fmt=coff ;; 467 xscale-*-elf) fmt=elf ;; 468 469 tic30-*-*aout*) fmt=aout bfd_gas=yes ;; 470 tic30-*-*coff*) fmt=coff bfd_gas=yes ;; 471 tic4x-*-* | c4x-*-*) fmt=coff bfd_gas=yes ;; 472 tic54x-*-* | c54x*-*-*) fmt=coff bfd_gas=yes need_libm=yes;; 473 tic80-*-*) fmt=coff ;; 474 475 v850-*-*) fmt=elf ;; 476 v850e-*-*) fmt=elf ;; 477 v850ea-*-*) fmt=elf ;; 478 479 vax-*-netbsdelf*) fmt=elf em=nbsd ;; 480 vax-*-netbsd*) fmt=aout em=nbsd ;; 481 vax-*-bsd* | vax-*-ultrix*) fmt=aout ;; 482 vax-*-vms) fmt=vms ;; 483 484 w65-*-*) fmt=coff ;; 485 486 xstormy16-*-*) fmt=elf ;; 487 488 xtensa-*-*) fmt=elf ;; 489 490 z8k-*-coff | z8k-*-sim) fmt=coff ;; 491 492 *-*-aout | *-*-scout) fmt=aout ;; 493 *-*-freebsd*) fmt=elf em=freebsd ;; 494 *-*-nindy*) fmt=bout ;; 495 *-*-bsd*) fmt=aout em=sun3 ;; 496 *-*-generic) fmt=generic ;; 497 *-*-xray | *-*-hms) fmt=coff ;; 498 *-*-sim) fmt=coff ;; 499 *-*-elf | *-*-sysv4* | *-*-solaris*) fmt=elf dev=yes ;; 500 *-*-aros*) fmt=elf em=linux bfd_gas=yes ;; 501 *-*-vxworks) fmt=aout ;; 502 *-*-netware) fmt=elf ;; 466 503 esac 467 504 … … 480 517 481 518 case ${cpu_type}-${fmt} in 482 alpha*-*) bfd_gas=yes ;; 483 arm-*) bfd_gas=yes ;; 484 # not yet 485 # i386-aout) bfd_gas=preferred ;; 486 ia64*-*) bfd_gas=yes ;; 487 mips-*) bfd_gas=yes ;; 488 ns32k-*) bfd_gas=yes ;; 489 ppc-*) bfd_gas=yes ;; 490 sparc-*) bfd_gas=yes ;; 491 strongarm-*) bfd_gas=yes ;; 492 xscale-*) bfd_gas=yes ;; 493 *-elf) bfd_gas=yes ;; 494 *-ecoff) bfd_gas=yes ;; 495 *-som) bfd_gas=yes ;; 496 #enable bfd for coff and aout to allow testing if a bfd target is 497 #the primary target, but not for coff or aout as the primary target 498 i386-coff) if test x${primary_bfd_gas} = xyes; then bfd_gas=yes; fi ;; 499 i386-aout) if test x${primary_bfd_gas} = xyes; then bfd_gas=yes; fi ;; 500 *) ;; 519 alpha*-* | arm-* | i386-* | ia64*-* | mips-* | ns32k-* \ 520 | pdp11-* | ppc-* | sparc-* | strongarm-* | xscale-* \ 521 | *-elf | *-ecoff | *-som) 522 bfd_gas=yes ;; 501 523 esac 502 524 503 525 # Other random stuff. 526 527 case ${cpu_type} in 528 mips) 529 # Set mips_cpu to the name of the default CPU. 530 case ${target_cpu} in 531 mips | mipsbe | mipseb | mipsle | mipsel | mips64 | mips64el) 532 mips_cpu=from-abi 533 ;; 534 mipsisa32 | mipsisa32el) 535 mips_cpu=mips32 536 ;; 537 mipsisa32r2 | mipsisa32r2el) 538 mips_cpu=mips32r2 539 ;; 540 mipsisa64 | mipsisa64el) 541 mips_cpu=mips64 542 ;; 543 mipstx39 | mipstx39el) 544 mips_cpu=r3900 545 ;; 546 mips64vr | mips64vrel) 547 mips_cpu=vr4100 548 ;; 549 mipsisa32r2*) 550 changequote(,)dnl 551 mips_cpu=`echo $target_cpu | sed -e 's/[a-z]*..r2//' -e 's/el$//'` 552 changequote([,])dnl 553 ;; 554 mips64* | mipsisa64* | mipsisa32*) 555 changequote(,)dnl 556 mips_cpu=`echo $target_cpu | sed -e 's/[a-z]*..//' -e 's/el$//'` 557 changequote([,])dnl 558 ;; 559 *) 560 AC_ERROR($target_cpu isn't a supported MIPS CPU name) 561 ;; 562 esac 563 # See whether it's appropriate to set E_MIPS_ABI_O32 for o32 564 # binaries. It's a GNU extension that some OSes don't understand. 565 # The value only matters on ELF targets. 566 case ${target} in 567 *-*-irix*) 568 use_e_mips_abi_o32=0 569 ;; 570 *) 571 use_e_mips_abi_o32=1 572 ;; 573 esac 574 # Decide whether to generate 32-bit or 64-bit code by default. 575 # Used to resolve -march=from-abi when an embedded ABI is selected. 576 case ${target} in 577 mips64*-*-* | mipsisa64*-*-*) 578 mips_default_64bit=1 579 ;; 580 *) 581 mips_default_64bit=0 582 ;; 583 esac 584 # Decide which ABI to target by default. 585 case ${target} in 586 mips64*-linux* | mips-sgi-irix6*) 587 mips_default_abi=N32_ABI 588 ;; 589 mips*-linux*) 590 mips_default_abi=O32_ABI 591 ;; 592 *) 593 mips_default_abi=NO_ABI 594 ;; 595 esac 596 AC_DEFINE_UNQUOTED(MIPS_CPU_STRING_DEFAULT, "$mips_cpu", 597 [Default CPU for MIPS targets. ]) 598 AC_DEFINE_UNQUOTED(USE_E_MIPS_ABI_O32, $use_e_mips_abi_o32, 599 [Allow use of E_MIPS_ABI_O32 on MIPS targets. ]) 600 AC_DEFINE_UNQUOTED(MIPS_DEFAULT_64BIT, $mips_default_64bit, 601 [Generate 64-bit code by default on MIPS targets. ]) 602 AC_DEFINE_UNQUOTED(MIPS_DEFAULT_ABI, $mips_default_abi, 603 [Choose a default ABI for MIPS targets. ]) 604 ;; 605 esac 504 606 505 607 # Do we need the opcodes library? … … 525 627 # Any other special object files needed ? 526 628 case ${cpu_type} in 527 fr30 | m32r)629 fr30 | ip2k | iq2000 | m32r | openrisc) 528 630 using_cgen=yes 529 631 ;; 530 632 633 frv) 634 using_cgen=yes 635 ;; 531 636 m68k) 532 637 case ${extra_objects} in … … 537 642 538 643 mips) 539 echo ${extra_objects} | grep -s "itbl-parse.o" 644 echo ${extra_objects} | grep -s "itbl-parse.o" 540 645 if test $? -ne 0 ; then 541 646 extra_objects="$extra_objects itbl-parse.o" 542 647 fi 543 648 544 echo ${extra_objects} | grep -s "itbl-lex.o" 649 echo ${extra_objects} | grep -s "itbl-lex.o" 545 650 if test $? -ne 0 ; then 546 651 extra_objects="$extra_objects itbl-lex.o" 547 652 fi 548 653 549 echo ${extra_objects} | grep -s "itbl-ops.o" 654 echo ${extra_objects} | grep -s "itbl-ops.o" 550 655 if test $? -ne 0 ; then 551 656 extra_objects="$extra_objects itbl-ops.o" … … 553 658 ;; 554 659 555 i386 )660 i386 | s390 | sparc) 556 661 if test $this_target = $target ; then 557 662 AC_DEFINE_UNQUOTED(DEFAULT_ARCH, "${arch}", [Default architecture.]) 558 663 fi 559 664 ;; 560 sparc) 561 if test $this_target = $target ; then 562 AC_DEFINE_UNQUOTED(DEFAULT_ARCH, "${arch}", [Default architecture.]) 665 666 xstormy16) 667 using_cgen=yes 668 ;; 669 670 xtensa) 671 echo ${extra_objects} | grep -s "xtensa-relax.o" 672 if test $? -ne 0 ; then 673 extra_objects="$extra_objects xtensa-relax.o" 563 674 fi 564 675 ;; 676 565 677 *) 566 678 ;; … … 594 706 case ${generic_target}-${fmt} in 595 707 mips-*-irix5*-*) emulation="mipsbelf mipslelf mipself mipsbecoff mipslecoff mipsecoff" ;; 596 mips -*-linux-gnu*-*) case "$endian" in597 big) emulation="mipsbelf mipslelf mipself mipsbecoff mipslecoff mipsecoff" ;;598 *) emulation="mipslelf mipsbelf mipself mipslecoff mipsbecoff mipsecoff" ;;708 mips*-*-linux*-*) case "$endian" in 709 big) emulation="mipsbelf mipslelf mipself" ;; 710 *) emulation="mipslelf mipsbelf mipself" ;; 599 711 esac ;; 600 712 mips-*-lnews*-ecoff) ;; … … 651 763 case ${target_cpu} in 652 764 vax | tahoe ) atof=${target_cpu} ;; 765 pdp11) atof=vax ;; 653 766 *) atof=ieee ;; 654 767 esac … … 818 931 yes) 819 932 BFDLIB=../bfd/libbfd.la 820 ALL_OBJ_DEPS="$ALL_OBJ_DEPS ../bfd/bfd.h" 933 BFDVER_H=../bfd/bfdver.h 934 ALL_OBJ_DEPS="$ALL_OBJ_DEPS"' ../bfd/bfd.h $(INCDIR)/symcat.h' 821 935 ;; 822 936 esac … … 825 939 AC_SUBST(OPCODES_LIB) 826 940 941 AC_SUBST(BFDVER_H) 827 942 AC_SUBST(ALL_OBJ_DEPS) 828 943 … … 838 953 AM_PROG_LEX 839 954 840 ALL_LINGUAS= 955 ALL_LINGUAS="fr tr es" 841 956 CY_GNU_GETTEXT 842 957 … … 870 985 # do we need the math library? 871 986 case "${need_libm}" in 872 yes) 987 yes) 873 988 AC_CHECK_LIBM 874 989 AC_SUBST(LIBM) -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/binutils/gas/write.c
-
Property cvs2svn:cvs-rev
changed from
1.2
to1.3
r617 r618 1 1 /* write.c - emit .o file 2 2 Copyright 1986, 1987, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 3 1998, 1999, 2000, 2001 3 1998, 1999, 2000, 2001, 2002, 2003 4 4 Free Software Foundation, Inc. 5 5 … … 29 29 #include "dwarf2dbg.h" 30 30 31 /* This looks like a good idea. Let's try turning it on always, for now. */32 #undef BFD_FAST_SECTION_FILL33 #define BFD_FAST_SECTION_FILL34 35 31 #ifndef TC_ADJUST_RELOC_COUNT 36 #define TC_ADJUST_RELOC_COUNT(FIX P,COUNT)32 #define TC_ADJUST_RELOC_COUNT(FIX, COUNT) 37 33 #endif 38 34 39 35 #ifndef TC_FORCE_RELOCATION 40 #define TC_FORCE_RELOCATION(FIXP) 0 41 #endif 42 43 #ifndef TC_FORCE_RELOCATION_SECTION 44 #define TC_FORCE_RELOCATION_SECTION(FIXP,SEG) TC_FORCE_RELOCATION(FIXP) 36 #define TC_FORCE_RELOCATION(FIX) \ 37 (generic_force_reloc (FIX)) 38 #endif 39 40 #ifndef TC_FORCE_RELOCATION_ABS 41 #define TC_FORCE_RELOCATION_ABS(FIX) \ 42 (TC_FORCE_RELOCATION (FIX)) 43 #endif 44 45 #ifndef TC_FORCE_RELOCATION_LOCAL 46 #define TC_FORCE_RELOCATION_LOCAL(FIX) \ 47 (!(FIX)->fx_pcrel \ 48 || (FIX)->fx_plt \ 49 || TC_FORCE_RELOCATION (FIX)) 50 #endif 51 52 #ifndef TC_FORCE_RELOCATION_SUB_SAME 53 #define TC_FORCE_RELOCATION_SUB_SAME(FIX, SEG) \ 54 (! SEG_NORMAL (SEG)) 55 #endif 56 57 #ifndef TC_FORCE_RELOCATION_SUB_ABS 58 #define TC_FORCE_RELOCATION_SUB_ABS(FIX) 0 59 #endif 60 61 #ifndef TC_FORCE_RELOCATION_SUB_LOCAL 62 #ifdef DIFF_EXPR_OK 63 #define TC_FORCE_RELOCATION_SUB_LOCAL(FIX) 0 64 #else 65 #define TC_FORCE_RELOCATION_SUB_LOCAL(FIX) 1 66 #endif 67 #endif 68 69 #ifndef TC_VALIDATE_FIX_SUB 70 #ifdef UNDEFINED_DIFFERENCE_OK 71 /* The PA needs this for PIC code generation. */ 72 #define TC_VALIDATE_FIX_SUB(FIX) 1 73 #else 74 #ifdef BFD_ASSEMBLER 75 #define TC_VALIDATE_FIX_SUB(FIX) \ 76 ((FIX)->fx_r_type == BFD_RELOC_GPREL32 \ 77 || (FIX)->fx_r_type == BFD_RELOC_GPREL16) 78 #else 79 #define TC_VALIDATE_FIX_SUB(FIX) 0 80 #endif 81 #endif 45 82 #endif 46 83 … … 49 86 #endif 50 87 51 #ifndef TC_FIX_ADJUSTABLE 52 #define TC_FIX_ADJUSTABLE(fix) 1 88 #ifndef MD_APPLY_SYM_VALUE 89 #define MD_APPLY_SYM_VALUE(FIX) 1 90 #endif 91 92 #ifndef TC_FINALIZE_SYMS_BEFORE_SIZE_SEG 93 #define TC_FINALIZE_SYMS_BEFORE_SIZE_SEG 1 53 94 #endif 54 95 55 96 #ifndef MD_PCREL_FROM_SECTION 56 #define MD_PCREL_FROM_SECTION(FIX P, SEC) md_pcrel_from(FIXP)97 #define MD_PCREL_FROM_SECTION(FIX, SEC) md_pcrel_from (FIX) 57 98 #endif 58 99 59 100 #ifndef WORKING_DOT_WORD 60 extern CONST int md_short_jump_size; 61 extern CONST int md_long_jump_size; 62 #endif 101 extern const int md_short_jump_size; 102 extern const int md_long_jump_size; 103 #endif 104 105 /* Used to control final evaluation of expressions. */ 106 int finalize_syms = 0; 63 107 64 108 int symbol_table_frozen; 109 110 symbolS *abs_section_sym; 111 112 /* Remember the value of dot when parsing expressions. */ 113 addressT dot_value; 114 65 115 void print_fixup PARAMS ((fixS *)); 66 116 … … 103 153 104 154 #ifdef BFD_ASSEMBLER 155 #define RELOC_ENUM enum bfd_reloc_code_real 156 #else 157 #define RELOC_ENUM int 158 #endif 159 105 160 static fixS *fix_new_internal PARAMS ((fragS *, int where, int size, 106 161 symbolS *add, symbolS *sub, 107 162 offsetT offset, int pcrel, 108 bfd_reloc_code_real_type r_type)); 109 #else 110 static fixS *fix_new_internal PARAMS ((fragS *, int where, int size, 111 symbolS *add, symbolS *sub, 112 offsetT offset, int pcrel, 113 int r_type)); 114 #endif 163 RELOC_ENUM r_type)); 115 164 #if defined (BFD_ASSEMBLER) || (!defined (BFD) && !defined (OBJ_VMS)) 116 static long fixup_segment PARAMS ((fixS * fixP, segT this_segment_type));165 static long fixup_segment PARAMS ((fixS *, segT)); 117 166 #endif 118 167 static relax_addressT relax_align PARAMS ((relax_addressT addr, int align)); … … 123 172 static void chain_frchains_together PARAMS ((bfd *, segT, PTR)); 124 173 static void cvt_frag_to_fill PARAMS ((segT, fragS *)); 125 static void relax_seg PARAMS ((bfd *, asection *, PTR));126 static void size_seg PARAMS ((bfd *, asection *, PTR));127 174 static void adjust_reloc_syms PARAMS ((bfd *, asection *, PTR)); 175 static void fix_segment PARAMS ((bfd *, asection *, PTR)); 128 176 static void write_relocs PARAMS ((bfd *, asection *, PTR)); 129 177 static void write_contents PARAMS ((bfd *, asection *, PTR)); … … 137 185 static void remove_subsegs PARAMS ((frchainS *, int, fragS **, fragS **)); 138 186 static void relax_and_size_all_segments PARAMS ((void)); 139 #endif140 #if defined (BFD_ASSEMBLER) && defined (OBJ_COFF) && defined (TE_GO32)141 static void set_segment_vma PARAMS ((bfd *, asection *, PTR));142 187 #endif 143 188 … … 154 199 offsetT offset; /* X_add_number. */ 155 200 int pcrel; /* TRUE if PC-relative relocation. */ 156 #ifdef BFD_ASSEMBLER 157 bfd_reloc_code_real_type r_type; /* Relocation type. */ 158 #else 159 int r_type; /* Relocation type. */ 160 #endif 201 RELOC_ENUM r_type ATTRIBUTE_UNUSED; /* Relocation type. */ 161 202 { 162 203 fixS *fixP; … … 178 219 fixP->fx_subsy = sub_symbol; 179 220 fixP->fx_offset = offset; 221 fixP->fx_dot_value = dot_value; 180 222 fixP->fx_pcrel = pcrel; 181 223 fixP->fx_plt = 0; … … 249 291 offsetT offset; /* X_add_number. */ 250 292 int pcrel; /* TRUE if PC-relative relocation. */ 251 #ifdef BFD_ASSEMBLER 252 bfd_reloc_code_real_type r_type; /* Relocation type. */ 253 #else 254 int r_type; /* Relocation type. */ 255 #endif 293 RELOC_ENUM r_type; /* Relocation type. */ 256 294 { 257 295 return fix_new_internal (frag, where, size, add_symbol, … … 270 308 expressionS *exp; /* Expression. */ 271 309 int pcrel; /* TRUE if PC-relative relocation. */ 272 #ifdef BFD_ASSEMBLER 273 bfd_reloc_code_real_type r_type; /* Relocation type. */ 274 #else 275 int r_type; /* Relocation type. */ 276 #endif 310 RELOC_ENUM r_type; /* Relocation type. */ 277 311 { 278 312 symbolS *add = NULL; … … 339 373 340 374 return fix_new_internal (frag, where, size, add, sub, off, pcrel, r_type); 375 } 376 377 /* Generic function to determine whether a fixup requires a relocation. */ 378 int 379 generic_force_reloc (fix) 380 fixS *fix; 381 { 382 #ifdef BFD_ASSEMBLER 383 if (fix->fx_r_type == BFD_RELOC_VTABLE_INHERIT 384 || fix->fx_r_type == BFD_RELOC_VTABLE_ENTRY) 385 return 1; 386 #endif 387 return S_FORCE_RELOC (fix->fx_addsy, fix->fx_subsy == NULL); 341 388 } 342 389 … … 523 570 _("attempt to .org/.space backwards? (%ld)"), 524 571 (long) fragP->fr_offset); 572 fragP->fr_offset = 0; 525 573 } 526 574 fragP->fr_type = rs_fill; … … 599 647 600 648 #ifdef BFD_ASSEMBLER 649 static void relax_seg PARAMS ((bfd *, asection *, PTR)); 601 650 static void 602 relax_seg (abfd, sec, do_code)603 bfd *abfd ;651 relax_seg (abfd, sec, xxx) 652 bfd *abfd ATTRIBUTE_UNUSED; 604 653 asection *sec; 605 PTR do_code; 606 { 607 flagword flags = bfd_get_section_flags (abfd, sec); 654 PTR xxx; 655 { 608 656 segment_info_type *seginfo = seg_info (sec); 609 657 610 if (!(flags & SEC_CODE) == !do_code 611 && seginfo && seginfo->frchainP) 612 relax_segment (seginfo->frchainP->frch_root, sec); 613 } 614 658 if (seginfo && seginfo->frchainP 659 && relax_segment (seginfo->frchainP->frch_root, sec)) 660 { 661 int *result = (int *) xxx; 662 *result = 1; 663 } 664 } 665 666 static void size_seg PARAMS ((bfd *, asection *, PTR)); 615 667 static void 616 668 size_seg (abfd, sec, xxx) … … 653 705 flags &= ~SEC_RELOC; 654 706 x = bfd_set_section_flags (abfd, sec, flags); 655 assert (x == true);707 assert (x); 656 708 657 709 newsize = md_section_align (sec, size); 658 710 x = bfd_set_section_size (abfd, sec, newsize); 659 assert (x == true);711 assert (x); 660 712 661 713 /* If the size had to be rounded up, add some padding in the last … … 669 721 fragp = fragp->fr_next; 670 722 last->fr_address = size; 671 fragp->fr_offset += newsize - size; 723 if ((newsize - size) % fragp->fr_var == 0) 724 fragp->fr_offset += (newsize - size) / fragp->fr_var; 725 else 726 /* If we hit this abort, it's likely due to subsegs_finish not 727 providing sufficient alignment on the last frag, and the 728 machine dependent code using alignment frags with fr_var 729 greater than 1. */ 730 abort (); 672 731 } 673 732 … … 719 778 #endif 720 779 780 /* This pass over fixups decides whether symbols can be replaced with 781 section symbols. */ 782 721 783 static void 722 784 adjust_reloc_syms (abfd, sec, xxx) … … 753 815 symbols, though, since they are not in the regular symbol 754 816 table. */ 755 if (sym != NULL) 756 resolve_symbol_value (sym, 1); 817 resolve_symbol_value (sym); 757 818 758 819 if (fixp->fx_subsy != NULL) 759 resolve_symbol_value (fixp->fx_subsy , 1);820 resolve_symbol_value (fixp->fx_subsy); 760 821 761 822 /* If this symbol is equated to an undefined symbol, convert 762 823 the fixup to being against that symbol. */ 763 if (sym != NULL && symbol_equated_p (sym) 764 && (! S_IS_DEFINED (sym) || S_IS_COMMON (sym))) 824 if (symbol_equated_reloc_p (sym)) 765 825 { 766 826 fixp->fx_offset += symbol_get_value_expression (sym)->X_add_number; … … 769 829 } 770 830 771 if (sym != NULL && symbol_mri_common_p (sym))831 if (symbol_mri_common_p (sym)) 772 832 { 773 833 /* These symbols are handled specially in fixup_segment. */ 774 goto done;834 continue; 775 835 } 776 836 837 /* If the symbol is undefined, common, weak, or global (ELF 838 shared libs), we can't replace it with the section symbol. */ 839 if (S_FORCE_RELOC (fixp->fx_addsy, 1)) 840 continue; 841 842 /* Is there some other (target cpu dependent) reason we can't adjust 843 this one? (E.g. relocations involving function addresses on 844 the PA. */ 845 #ifdef tc_fix_adjustable 846 if (! tc_fix_adjustable (fixp)) 847 continue; 848 #endif 849 850 /* Since we're reducing to section symbols, don't attempt to reduce 851 anything that's already using one. */ 852 if (symbol_section_p (sym)) 853 continue; 854 777 855 symsec = S_GET_SEGMENT (sym); 778 779 856 if (symsec == NULL) 780 857 abort (); … … 782 859 if (bfd_is_abs_section (symsec)) 783 860 { 784 /* The fixup_segment routine will not use this symbol in a 785 relocation unless TC_FORCE_RELOCATION returns 1. */ 786 if (TC_FORCE_RELOCATION (fixp)) 787 { 788 symbol_mark_used_in_reloc (fixp->fx_addsy); 789 #ifdef UNDEFINED_DIFFERENCE_OK 790 if (fixp->fx_subsy != NULL) 791 symbol_mark_used_in_reloc (fixp->fx_subsy); 792 #endif 793 } 794 goto done; 795 } 796 797 /* If it's one of these sections, assume the symbol is 798 definitely going to be output. The code in 799 md_estimate_size_before_relax in tc-mips.c uses this test 800 as well, so if you change this code you should look at that 801 code. */ 802 if (bfd_is_und_section (symsec) 803 || bfd_is_com_section (symsec)) 804 { 805 symbol_mark_used_in_reloc (fixp->fx_addsy); 806 #ifdef UNDEFINED_DIFFERENCE_OK 807 /* We have the difference of an undefined symbol and some 808 other symbol. Make sure to mark the other symbol as used 809 in a relocation so that it will always be output. */ 810 if (fixp->fx_subsy) 811 symbol_mark_used_in_reloc (fixp->fx_subsy); 812 #endif 813 goto done; 861 /* The fixup_segment routine normally will not use this 862 symbol in a relocation. */ 863 continue; 814 864 } 815 865 … … 820 870 if (symsec != sec && ! S_IS_LOCAL (sym)) 821 871 { 822 boolean linkonce; 823 824 linkonce = false; 825 #ifdef BFD_ASSEMBLER 826 if ((bfd_get_section_flags (stdoutput, symsec) & SEC_LINK_ONCE) 827 != 0) 828 linkonce = true; 829 #endif 830 #ifdef OBJ_ELF 831 /* The GNU toolchain uses an extension for ELF: a section 832 beginning with the magic string .gnu.linkonce is a 833 linkonce section. */ 834 if (strncmp (segment_name (symsec), ".gnu.linkonce", 835 sizeof ".gnu.linkonce" - 1) == 0) 836 linkonce = true; 837 #endif 838 839 if (linkonce) 840 { 841 symbol_mark_used_in_reloc (fixp->fx_addsy); 842 #ifdef UNDEFINED_DIFFERENCE_OK 843 if (fixp->fx_subsy != NULL) 844 symbol_mark_used_in_reloc (fixp->fx_subsy); 845 #endif 846 goto done; 847 } 872 if ((symsec->flags & SEC_LINK_ONCE) != 0 873 || (IS_ELF 874 /* The GNU toolchain uses an extension for ELF: a 875 section beginning with the magic string 876 .gnu.linkonce is a linkonce section. */ 877 && strncmp (segment_name (symsec), ".gnu.linkonce", 878 sizeof ".gnu.linkonce" - 1) == 0)) 879 continue; 848 880 } 849 881 850 /* Since we're reducing to section symbols, don't attempt to reduce 851 anything that's already using one. */ 852 if (symbol_section_p (sym)) 853 { 854 symbol_mark_used_in_reloc (fixp->fx_addsy); 855 goto done; 856 } 857 858 #ifdef BFD_ASSEMBLER 859 #ifndef __EMX__ 860 /* UGLY HACK: FOR SOME REASON IT DOESN'T WORK WITH EMX, 861 BUT IT LOOKS LIKE IT IS LIBBFD FAULT! LET'S WAIT TILL IT GETS FIXED. */ 862 /* We can never adjust a reloc against a weak symbol. If we 863 did, and the weak symbol was overridden by a real symbol 864 somewhere else, then our relocation would be pointing at 865 the wrong area of memory. */ 866 if (S_IS_WEAK (sym)) 867 { 868 symbol_mark_used_in_reloc (fixp->fx_addsy); 869 goto done; 870 } 871 #endif 872 #endif 873 874 /* Is there some other reason we can't adjust this one? (E.g., 875 call/bal links in i960-bout symbols.) */ 876 #ifdef obj_fix_adjustable 877 if (! obj_fix_adjustable (fixp)) 878 { 879 symbol_mark_used_in_reloc (fixp->fx_addsy); 880 goto done; 881 } 882 #endif 883 884 /* Is there some other (target cpu dependent) reason we can't adjust 885 this one? (E.g. relocations involving function addresses on 886 the PA. */ 887 #ifdef tc_fix_adjustable 888 if (! tc_fix_adjustable (fixp)) 889 { 890 symbol_mark_used_in_reloc (fixp->fx_addsy); 891 goto done; 892 } 893 #endif 894 895 /* If the section symbol isn't going to be output, the relocs 896 at least should still work. If not, figure out what to do 897 when we run into that case. 898 899 We refetch the segment when calling section_symbol, rather 882 /* Never adjust a reloc against local symbol in a merge section 883 with non-zero addend. */ 884 if ((symsec->flags & SEC_MERGE) != 0 885 && (fixp->fx_offset != 0 || fixp->fx_subsy != NULL)) 886 continue; 887 888 /* Never adjust a reloc against TLS local symbol. */ 889 if ((symsec->flags & SEC_THREAD_LOCAL) != 0) 890 continue; 891 892 /* We refetch the segment when calling section_symbol, rather 900 893 than using symsec, because S_GET_VALUE may wind up changing 901 894 the section when it calls resolve_symbol_value. */ 902 895 fixp->fx_offset += S_GET_VALUE (sym); 903 896 fixp->fx_addsy = section_symbol (S_GET_SEGMENT (sym)); 904 symbol_mark_used_in_reloc (fixp->fx_addsy);905 897 #ifdef DEBUG5 906 898 fprintf (stderr, "\nadjusted fixup:\n"); 907 899 print_fixup (fixp); 908 900 #endif 909 910 done:911 ;912 901 } 913 #if 1 /* def RELOC_REQUIRES_SYMBOL */914 else915 {916 /* There was no symbol required by this relocation. However,917 BFD doesn't really handle relocations without symbols well.918 (At least, the COFF support doesn't.) So for now we fake up919 a local symbol in the absolute section. */920 921 fixp->fx_addsy = section_symbol (absolute_section);922 #if 0923 fixp->fx_addsy->sy_used_in_reloc = 1;924 #endif925 }926 #endif927 902 928 903 dump_section_relocs (abfd, sec, stderr); 904 } 905 906 static void 907 fix_segment (abfd, sec, xxx) 908 bfd *abfd ATTRIBUTE_UNUSED; 909 asection *sec; 910 PTR xxx ATTRIBUTE_UNUSED; 911 { 912 segment_info_type *seginfo = seg_info (sec); 913 914 fixup_segment (seginfo->fix_root, sec); 929 915 } 930 916 … … 947 933 return; 948 934 949 fixup_segment (seginfo->fix_root, sec);950 951 935 n = 0; 952 936 for (fixp = seginfo->fix_root; fixp; fixp = fixp->fx_next) … … 972 956 973 957 /* If this is an undefined symbol which was equated to another 974 symbol, then usegenerate the reloc against the latter symbol958 symbol, then generate the reloc against the latter symbol 975 959 rather than the former. */ 976 960 sym = fixp->fx_addsy; 977 while (symbol_equated_p (sym) 978 && (! S_IS_DEFINED (sym) || S_IS_COMMON (sym))) 961 while (symbol_equated_reloc_p (sym)) 979 962 { 980 963 symbolS *n; … … 1013 996 break; 1014 997 case bfd_reloc_overflow: 1015 as_bad_where (fixp->fx_file, fixp->fx_line, _("relocation overflow")); 998 as_bad_where (fixp->fx_file, fixp->fx_line, 999 _("relocation overflow")); 1016 1000 break; 1017 1001 case bfd_reloc_outofrange: 1018 as_bad_where (fixp->fx_file, fixp->fx_line, _("relocation out of range")); 1002 as_bad_where (fixp->fx_file, fixp->fx_line, 1003 _("relocation out of range")); 1019 1004 break; 1020 1005 default: … … 1033 1018 { 1034 1019 arelent **reloc; 1035 char *data;1036 1020 bfd_reloc_status_type s; 1037 1021 symbolS *sym; … … 1048 1032 rather than the former. */ 1049 1033 sym = fixp->fx_addsy; 1050 while (symbol_equated_p (sym) 1051 && (! S_IS_DEFINED (sym) || S_IS_COMMON (sym))) 1052 sym = symbol_get_value_expression (sym)->X_add_symbol; 1034 while (symbol_equated_reloc_p (sym)) 1035 { 1036 symbolS *n; 1037 1038 /* We must avoid looping, as that can occur with a badly 1039 written program. */ 1040 n = symbol_get_value_expression (sym)->X_add_symbol; 1041 if (n == sym) 1042 break; 1043 fixp->fx_offset += symbol_get_value_expression (sym)->X_add_number; 1044 sym = n; 1045 } 1053 1046 fixp->fx_addsy = sym; 1054 1047 … … 1060 1053 assert (i <= n); 1061 1054 } 1062 data = fixp->fx_frag->fr_literal + fixp->fx_where;1063 1055 if (fixp->fx_where + fixp->fx_size 1064 1056 > fixp->fx_frag->fr_fix + fixp->fx_frag->fr_offset) … … 1079 1071 _("relocation overflow")); 1080 1072 break; 1073 case bfd_reloc_outofrange: 1074 as_bad_where (fixp->fx_file, fixp->fx_line, 1075 _("relocation out of range")); 1076 break; 1081 1077 default: 1082 as_fatal (_("%s:%u: bad return from bfd_install_relocation "),1083 fixp->fx_file, fixp->fx_line );1078 as_fatal (_("%s:%u: bad return from bfd_install_relocation: %x"), 1079 fixp->fx_file, fixp->fx_line, s); 1084 1080 } 1085 1081 } … … 1164 1160 f->fr_literal, (file_ptr) offset, 1165 1161 (bfd_size_type) f->fr_fix); 1166 if ( x == false)1162 if (!x) 1167 1163 { 1168 1164 bfd_perror (stdoutput->filename); … … 1188 1184 (file_ptr) offset, 1189 1185 (bfd_size_type) fill_size); 1190 if ( x == false)1186 if (!x) 1191 1187 { 1192 1188 bfd_perror (stdoutput->filename); … … 1222 1218 (stdoutput, sec, buf, (file_ptr) offset, 1223 1219 (bfd_size_type) n_per_buf * fill_size); 1224 if ( x != true)1225 as_fatal (_(" Cannot write to output file."));1220 if (!x) 1221 as_fatal (_("cannot write to output file")); 1226 1222 offset += n_per_buf * fill_size; 1227 1223 } … … 1356 1352 asymbol **asympp; 1357 1353 symbolS *symp; 1358 b oolean result;1359 extern PTR bfd_alloc PARAMS ((bfd *, size_t));1354 bfd_boolean result; 1355 extern PTR bfd_alloc PARAMS ((bfd *, bfd_size_type)); 1360 1356 1361 1357 /* Count symbols. We can't rely on a count made by the loop in … … 1369 1365 { 1370 1366 int i; 1371 1372 asympp = (asymbol **) bfd_alloc (stdoutput, 1373 nsyms * sizeof (asymbol *));1367 bfd_size_type amt = (bfd_size_type) nsyms * sizeof (asymbol *); 1368 1369 asympp = (asymbol **) bfd_alloc (stdoutput, amt); 1374 1370 symp = symbol_rootP; 1375 1371 for (i = 0; i < nsyms; i++, symp = symbol_next (symp)) … … 1382 1378 asympp = 0; 1383 1379 result = bfd_set_symtab (stdoutput, asympp, nsyms); 1384 assert (result == true);1380 assert (result); 1385 1381 symbol_table_frozen = 1; 1386 1382 } 1387 1383 #endif 1388 1389 #if defined (BFD_ASSEMBLER) && defined (OBJ_COFF) && defined (TE_GO32)1390 static void1391 set_segment_vma (abfd, sec, xxx)1392 bfd *abfd;1393 asection *sec;1394 PTR xxx ATTRIBUTE_UNUSED;1395 {1396 static bfd_vma addr = 0;1397 1398 bfd_set_section_vma (abfd, sec, addr);1399 addr += bfd_section_size (abfd, sec);1400 }1401 #endif /* BFD_ASSEMBLER && OBJ_COFF && !TE_PE */1402 1384 1403 1385 /* Finish the subsegments. After every sub-segment, we fake an … … 1408 1390 1409 1391 #ifndef SUB_SEGMENT_ALIGN 1392 #ifdef HANDLE_ALIGN 1393 /* The last subsegment gets an aligment corresponding to the alignment 1394 of the section. This allows proper nop-filling at the end of 1395 code-bearing sections. */ 1396 #define SUB_SEGMENT_ALIGN(SEG, FRCHAIN) \ 1397 (!(FRCHAIN)->frch_next || (FRCHAIN)->frch_next->frch_seg != (SEG) \ 1398 ? get_recorded_alignment (SEG) : 0) 1399 #else 1410 1400 #ifdef BFD_ASSEMBLER 1411 #define SUB_SEGMENT_ALIGN(SEG ) (0)1401 #define SUB_SEGMENT_ALIGN(SEG, FRCHAIN) 0 1412 1402 #else 1413 #define SUB_SEGMENT_ALIGN(SEG) (2) 1403 #define SUB_SEGMENT_ALIGN(SEG, FRCHAIN) 2 1404 #endif 1414 1405 #endif 1415 1406 #endif … … 1422 1413 for (frchainP = frchain_root; frchainP; frchainP = frchainP->frch_next) 1423 1414 { 1424 int alignment ;1415 int alignment = 0; 1425 1416 1426 1417 subseg_set (frchainP->frch_seg, frchainP->frch_subseg); … … 1429 1420 any alignment is meaningless, and, moreover, will look weird 1430 1421 if we are generating a listing. */ 1431 alignment = had_errors () ? 0 : SUB_SEGMENT_ALIGN (now_seg); 1432 1433 /* The last subsegment gets an aligment corresponding to the 1434 alignment of the section. This allows proper nop-filling 1435 at the end of code-bearing sections. */ 1436 if (!frchainP->frch_next || frchainP->frch_next->frch_seg != now_seg) 1437 alignment = get_recorded_alignment (now_seg); 1422 if (!had_errors ()) 1423 { 1424 alignment = SUB_SEGMENT_ALIGN (now_seg, frchainP); 1425 #ifdef BFD_ASSEMBLER 1426 if ((bfd_get_section_flags (now_seg->owner, now_seg) & SEC_MERGE) 1427 && now_seg->entsize) 1428 { 1429 unsigned int entsize = now_seg->entsize; 1430 int entalign = 0; 1431 1432 while ((entsize & 1) == 0) 1433 { 1434 ++entalign; 1435 entsize >>= 1; 1436 } 1437 if (entalign > alignment) 1438 alignment = entalign; 1439 } 1440 #endif 1441 } 1438 1442 1439 1443 if (subseg_text_p (now_seg)) … … 1472 1476 { 1473 1477 if (n_warns || n_errs) 1474 as_warn (_("%d error%s, %d warning%s, generating bad object file .\n"),1478 as_warn (_("%d error%s, %d warning%s, generating bad object file"), 1475 1479 n_errs, n_errs == 1 ? "" : "s", 1476 1480 n_warns, n_warns == 1 ? "" : "s"); … … 1479 1483 { 1480 1484 if (n_errs) 1481 as_fatal (_("%d error%s, %d warning%s, no object file generated .\n"),1485 as_fatal (_("%d error%s, %d warning%s, no object file generated"), 1482 1486 n_errs, n_errs == 1 ? "" : "s", 1483 1487 n_warns, n_warns == 1 ? "" : "s"); … … 1498 1502 /* Remove the sections created by gas for its own purposes. */ 1499 1503 { 1500 asection **seclist , *sec;1504 asection **seclist; 1501 1505 int i; 1502 1506 1503 1507 seclist = &stdoutput->sections; 1504 while ( seclist &&*seclist)1508 while (*seclist) 1505 1509 { 1506 sec = *seclist; 1507 while (sec == reg_section || sec == expr_section) 1510 if (*seclist == reg_section || *seclist == expr_section) 1508 1511 { 1509 sec = sec->next; 1510 *seclist = sec; 1512 bfd_section_list_remove (stdoutput, seclist); 1511 1513 stdoutput->section_count--; 1512 if (!sec)1513 break;1514 1514 } 1515 if (*seclist)1515 else 1516 1516 seclist = &(*seclist)->next; 1517 1517 } … … 1538 1538 1539 1539 #ifdef BFD_ASSEMBLER 1540 bfd_map_over_sections (stdoutput, relax_seg, (char *) 1); 1541 bfd_map_over_sections (stdoutput, relax_seg, (char *) 0); 1540 while (1) 1541 { 1542 int changed; 1543 1544 #ifndef WORKING_DOT_WORD 1545 /* We need to reset the markers in the broken word list and 1546 associated frags between calls to relax_segment (via 1547 relax_seg). Since the broken word list is global, we do it 1548 once per round, rather than locally in relax_segment for each 1549 segment. */ 1550 struct broken_word *brokp; 1551 1552 for (brokp = broken_words; 1553 brokp != (struct broken_word *) NULL; 1554 brokp = brokp->next_broken_word) 1555 { 1556 brokp->added = 0; 1557 1558 if (brokp->dispfrag != (fragS *) NULL 1559 && brokp->dispfrag->fr_type == rs_broken_word) 1560 brokp->dispfrag->fr_subtype = 0; 1561 } 1562 #endif 1563 1564 changed = 0; 1565 bfd_map_over_sections (stdoutput, relax_seg, &changed); 1566 if (!changed) 1567 break; 1568 } 1569 1570 /* Note - Most ports will use the default value of 1571 TC_FINALIZE_SYMS_BEFORE_SIZE_SEG, which 1. This will force 1572 local symbols to be resolved, removing their frag information. 1573 Some ports however, will not have finished relaxing all of 1574 their frags and will still need the local symbol frag 1575 information. These ports can set 1576 TC_FINALIZE_SYMS_BEFORE_SIZE_SEG to 0. */ 1577 finalize_syms = TC_FINALIZE_SYMS_BEFORE_SIZE_SEG; 1578 1542 1579 bfd_map_over_sections (stdoutput, size_seg, (char *) 0); 1543 1580 #else … … 1545 1582 #endif /* BFD_ASSEMBLER */ 1546 1583 1547 #if defined (BFD_ASSEMBLER) && defined (OBJ_COFF) && defined (TE_GO32) 1548 /* Now that the segments have their final sizes, run through the 1549 sections and set their vma and lma. !BFD gas sets them, and BFD gas 1550 should too. Currently, only DJGPP uses this code, but other 1551 COFF targets may need to execute this too. */ 1552 bfd_map_over_sections (stdoutput, set_segment_vma, (char *) 0); 1584 /* Relaxation has completed. Freeze all syms. */ 1585 finalize_syms = 1; 1586 1587 #ifdef md_post_relax_hook 1588 md_post_relax_hook; 1553 1589 #endif 1554 1590 … … 1604 1640 || fragP->fr_next == data_frag_root 1605 1641 #endif 1606 || (( fragP->fr_next->fr_address - fragP->fr_address)1642 || ((offsetT) (fragP->fr_next->fr_address - fragP->fr_address) 1607 1643 == (fragP->fr_fix + fragP->fr_offset * fragP->fr_var)))) 1608 1644 abort (); … … 1699 1735 /* This is the offset from ??? to table_ptr+0. */ 1700 1736 to_addr = table_addr - S_GET_VALUE (lie->sub); 1701 #ifdef BFD_ASSEMBLER1702 to_addr -= symbol_get_frag (lie->sub)->fr_address;1703 #endif1704 1737 #ifdef TC_CHECK_ADJUSTED_BROKEN_DOT_WORD 1705 1738 TC_CHECK_ADJUSTED_BROKEN_DOT_WORD (to_addr, lie); … … 1718 1751 from_addr = table_addr; 1719 1752 to_addr = S_GET_VALUE (lie->add) + lie->addnum; 1720 #ifdef BFD_ASSEMBLER1721 to_addr += symbol_get_frag (lie->add)->fr_address;1722 #endif1723 1753 md_create_long_jump (table_ptr, from_addr, to_addr, lie->dispfrag, 1724 1754 lie->add); … … 1838 1868 1839 1869 #ifdef BFD_HEADERS 1840 bfd_seek (stdoutput, 0, 0);1841 bfd_ write (the_object_file, 1,object_file_size, stdoutput);1870 bfd_seek (stdoutput, (file_ptr) 0, 0); 1871 bfd_bwrite (the_object_file, (bfd_size_type) object_file_size, stdoutput); 1842 1872 #else 1843 1873 … … 1863 1893 1864 1894 for (symp = symbol_rootP; symp; symp = symbol_next (symp)) 1865 resolve_symbol_value (symp , 1);1895 resolve_symbol_value (symp); 1866 1896 } 1867 1897 resolve_local_symbol_values (); … … 1877 1907 1878 1908 bfd_map_over_sections (stdoutput, adjust_reloc_syms, (char *) 0); 1909 1910 #ifdef tc_frob_file_before_fix 1911 tc_frob_file_before_fix (); 1912 #endif 1913 #ifdef obj_frob_file_before_fix 1914 obj_frob_file_before_fix (); 1915 #endif 1916 1917 bfd_map_over_sections (stdoutput, fix_segment, (char *) 0); 1879 1918 1880 1919 /* Set up symbol table, and write it out. */ … … 1905 1944 label name. */ 1906 1945 if (name2 != name && ! S_IS_DEFINED (symp)) 1907 as_bad (_("local label %sis not defined"), name2);1946 as_bad (_("local label `%s' is not defined"), name2); 1908 1947 } 1909 1948 … … 1911 1950 more symbols. They'll probably only be section symbols, 1912 1951 but they'll still need to have the values computed. */ 1913 resolve_symbol_value (symp , 1);1952 resolve_symbol_value (symp); 1914 1953 1915 1954 /* Skip symbols which were equated to undefined or common 1916 1955 symbols. */ 1917 if (symbol_equated_p (symp) 1918 && (! S_IS_DEFINED (symp) || S_IS_COMMON (symp))) 1956 if (symbol_equated_reloc_p (symp)) 1919 1957 { 1920 1958 symbol_remove (symp, &symbol_rootP, &symbol_lastP); … … 1948 1986 and symbols that the frob_symbol macros told us to punt, 1949 1987 but we keep such symbols if they are used in relocs. */ 1950 if ((! EMIT_SECTION_SYMBOLS 1951 && symbol_section_p (symp)) 1988 if (symp == abs_section_sym 1989 || (! EMIT_SECTION_SYMBOLS 1990 && symbol_section_p (symp)) 1952 1991 /* Note that S_IS_EXTERN and S_IS_LOCAL are not always 1953 1992 opposites. Sometimes the former checks flags and the 1954 1993 latter examines the name... */ 1955 1994 || (!S_IS_EXTERN (symp) 1956 && ( S_IS_LOCAL (symp) || punt)1995 && (punt || S_IS_LOCAL (symp)) 1957 1996 && ! symbol_used_in_reloc_p (symp))) 1958 1997 { … … 1968 2007 if (! symbol_resolved_p (symp)) 1969 2008 { 1970 as_bad (_("can't resolve value for symbol \"%s\""),2009 as_bad (_("can't resolve value for symbol `%s'"), 1971 2010 S_GET_NAME (symp)); 1972 2011 symbol_mark_resolved (symp); … … 2062 2101 know (sym_frag != NULL); 2063 2102 #endif 2064 know ( !(S_GET_SEGMENT (symbolP) == absolute_section)2103 know (S_GET_SEGMENT (symbolP) != absolute_section 2065 2104 || sym_frag == &zero_address_frag); 2066 target += S_GET_VALUE (symbolP) + sym_frag->fr_address;2105 target += S_GET_VALUE (symbolP); 2067 2106 2068 2107 /* If frag has yet to be reached on this pass, … … 2162 2201 addresses. */ 2163 2202 2164 void 2203 int 2165 2204 relax_segment (segment_frag_root, segment) 2166 2205 struct frag *segment_frag_root; … … 2169 2208 register struct frag *fragP; 2170 2209 register relax_addressT address; 2210 int ret; 2211 2171 2212 #if !defined (MANY_SEGMENTS) && !defined (BFD_ASSEMBLER) 2172 2213 know (segment == SEG_DATA || segment == SEG_TEXT || segment == SEG_BSS); … … 2201 2242 if (offset % fragP->fr_var != 0) 2202 2243 { 2203 as_bad (_("alignment padding (%lu bytes) not a multiple of %ld"), 2204 (unsigned long) offset, (long) fragP->fr_var); 2244 as_bad_where (fragP->fr_file, fragP->fr_line, 2245 _("alignment padding (%lu bytes) not a multiple of %ld"), 2246 (unsigned long) offset, (long) fragP->fr_var); 2205 2247 offset -= (offset % fragP->fr_var); 2206 2248 } … … 2216 2258 2217 2259 case rs_machine_dependent: 2260 /* If fr_symbol is an expression, this call to 2261 resolve_symbol_value sets up the correct segment, which will 2262 likely be needed in md_estimate_size_before_relax. */ 2263 if (fragP->fr_symbol) 2264 resolve_symbol_value (fragP->fr_symbol); 2265 2218 2266 address += md_estimate_size_before_relax (fragP, segment); 2219 2267 break; … … 2302 2350 continue; 2303 2351 2304 offset = (symbol_get_frag (lie->add)->fr_address 2305 + S_GET_VALUE (lie->add) 2352 offset = (S_GET_VALUE (lie->add) 2306 2353 + lie->addnum 2307 - (symbol_get_frag (lie->sub)->fr_address 2308 + S_GET_VALUE (lie->sub))); 2354 - S_GET_VALUE (lie->sub)); 2309 2355 if (offset <= -32768 || offset >= 32767) 2310 2356 { … … 2313 2359 char buf[50]; 2314 2360 sprint_value (buf, (addressT) lie->addnum); 2315 as_warn (_(".word %s-%s+%s didn't fit"), 2316 S_GET_NAME (lie->add), 2317 S_GET_NAME (lie->sub), 2318 buf); 2361 as_warn_where (fragP->fr_file, fragP->fr_line, 2362 _(".word %s-%s+%s didn't fit"), 2363 S_GET_NAME (lie->add), 2364 S_GET_NAME (lie->sub), 2365 buf); 2319 2366 } 2320 2367 lie->added = 1; … … 2381 2428 || (symbolP->sy_frag == &zero_address_frag)); 2382 2429 #endif 2383 target += (S_GET_VALUE (symbolP) 2384 + symbol_get_frag (symbolP)->fr_address); 2385 } /* if we have a symbol */ 2430 /* Convert from an actual address to an octet offset 2431 into the section. Here it is assumed that the 2432 section's VMA is zero, and can omit subtracting it 2433 from the symbol's value to get the address offset. */ 2434 know (S_GET_SECTION (symbolP)->vma == 0); 2435 target += S_GET_VALUE (symbolP) * OCTETS_PER_BYTE; 2436 } 2386 2437 2387 2438 know (fragP->fr_next); … … 2394 2445 .org backwards. */ 2395 2446 as_bad_where (fragP->fr_file, fragP->fr_line, 2396 _("attempt to .org backwards ignored"));2447 _("attempt to .org backwards")); 2397 2448 2398 2449 /* We've issued an error message. Change the … … 2411 2462 2412 2463 case rs_space: 2464 growth = 0; 2413 2465 if (symbolP) 2414 2466 { 2415 growth = S_GET_VALUE (symbolP); 2416 if (symbol_get_frag (symbolP) != &zero_address_frag 2467 offsetT amount; 2468 2469 amount = S_GET_VALUE (symbolP); 2470 if (S_GET_SEGMENT (symbolP) != absolute_section 2417 2471 || S_IS_COMMON (symbolP) 2418 2472 || ! S_IS_DEFINED (symbolP)) 2419 as_bad_where (fragP->fr_file, fragP->fr_line,2420 _(".space specifies non-absolute value"));2421 fragP->fr_symbol = 0;2422 if (growth < 0)2423 2473 { 2424 as_warn (_(".space or .fill with negative value, ignored")); 2425 growth = 0; 2474 as_bad_where (fragP->fr_file, fragP->fr_line, 2475 _(".space specifies non-absolute value")); 2476 /* Prevent repeat of this error message. */ 2477 fragP->fr_symbol = 0; 2426 2478 } 2479 else if (amount < 0) 2480 { 2481 as_warn_where (fragP->fr_file, fragP->fr_line, 2482 _(".space or .fill with negative value, ignored")); 2483 fragP->fr_symbol = 0; 2484 } 2485 else 2486 growth = (was_address + fragP->fr_fix + amount 2487 - fragP->fr_next->fr_address); 2427 2488 } 2428 else2429 growth = 0;2430 2489 break; 2431 2490 … … 2447 2506 int size; 2448 2507 2449 value = resolve_symbol_value (fragP->fr_symbol , 0);2508 value = resolve_symbol_value (fragP->fr_symbol); 2450 2509 size = sizeof_leb128 (value, fragP->fr_subtype); 2451 2510 growth = size - fragP->fr_offset; … … 2476 2535 } /* do_relax */ 2477 2536 2478 /* We now have valid fr_address'es for each frag. */ 2479 2480 /* All fr_address's are correct, relative to their own segment. 2481 We have made all the fixS we will ever make. */ 2537 ret = 0; 2538 for (fragP = segment_frag_root; fragP; fragP = fragP->fr_next) 2539 if (fragP->last_fr_address != fragP->fr_address) 2540 { 2541 fragP->last_fr_address = fragP->fr_address; 2542 ret = 1; 2543 } 2544 return ret; 2482 2545 } 2483 2546 2484 2547 #if defined (BFD_ASSEMBLER) || (!defined (BFD) && !defined (OBJ_VMS)) 2485 2486 #ifndef TC_RELOC_RTSYM_LOC_FIXUP2487 #define TC_RELOC_RTSYM_LOC_FIXUP(X) (1)2488 #endif2489 2548 2490 2549 /* fixup_segment() … … 2493 2552 handled now. (These consist of fixS where we have since discovered 2494 2553 the value of a symbol, or the address of the frag involved.) 2495 For each one, call md_apply_fix to put the fix into the frag data.2554 For each one, call md_apply_fix3 to put the fix into the frag data. 2496 2555 2497 2556 Result is a count of how many relocation structs will be needed to … … 2500 2559 2501 2560 static long 2502 fixup_segment (fixP, this_segment _type)2503 registerfixS *fixP;2504 segT this_segment _type; /* N_TYPE bits for segment. */2561 fixup_segment (fixP, this_segment) 2562 fixS *fixP; 2563 segT this_segment; 2505 2564 { 2506 2565 long seg_reloc_count = 0; 2507 symbolS *add_symbolP;2508 symbolS *sub_symbolP;2509 2566 valueT add_number; 2510 int size;2511 char *place;2512 long where;2513 int pcrel, plt;2514 2567 fragS *fragP; 2515 2568 segT add_symbol_segment = absolute_section; 2516 2569 2570 if (fixP != NULL && abs_section_sym == NULL) 2571 { 2572 #ifndef BFD_ASSEMBLER 2573 abs_section_sym = &abs_symbol; 2574 #else 2575 abs_section_sym = section_symbol (absolute_section); 2576 #endif 2577 } 2578 2517 2579 /* If the linker is doing the relaxing, we must not do any fixups. 2518 2580 2519 Well, strictly speaking that's not true -- we could do any that are 2520 PC-relative and don't cross regions that could change size. And for the 2521 i960 (the only machine for which we've got a relaxing linker right now), 2522 we might be able to turn callx/callj into bal anyways in cases where we 2523 know the maximum displacement. */ 2524 if (linkrelax && TC_LINKRELAX_FIXUP (this_segment_type)) 2581 Well, strictly speaking that's not true -- we could do any that 2582 are PC-relative and don't cross regions that could change size. 2583 And for the i960 we might be able to turn callx/callj into bal 2584 anyways in cases where we know the maximum displacement. */ 2585 if (linkrelax && TC_LINKRELAX_FIXUP (this_segment)) 2525 2586 { 2526 2587 for (; fixP; fixP = fixP->fx_next) 2527 seg_reloc_count++; 2588 if (!fixP->fx_done) 2589 { 2590 if (fixP->fx_addsy == NULL) 2591 { 2592 /* There was no symbol required by this relocation. 2593 However, BFD doesn't really handle relocations 2594 without symbols well. So fake up a local symbol in 2595 the absolute section. */ 2596 fixP->fx_addsy = abs_section_sym; 2597 } 2598 symbol_mark_used_in_reloc (fixP->fx_addsy); 2599 if (fixP->fx_subsy != NULL) 2600 symbol_mark_used_in_reloc (fixP->fx_subsy); 2601 seg_reloc_count++; 2602 } 2528 2603 TC_ADJUST_RELOC_COUNT (fixP, seg_reloc_count); 2529 2604 return seg_reloc_count; … … 2539 2614 fragP = fixP->fx_frag; 2540 2615 know (fragP); 2541 where = fixP->fx_where;2542 place = fragP->fr_literal + where;2543 size = fixP->fx_size;2544 add_symbolP = fixP->fx_addsy;2545 2616 #ifdef TC_VALIDATE_FIX 2546 TC_VALIDATE_FIX (fixP, this_segment_type, skip); 2547 #endif 2548 sub_symbolP = fixP->fx_subsy; 2617 TC_VALIDATE_FIX (fixP, this_segment, skip); 2618 #endif 2549 2619 add_number = fixP->fx_offset; 2550 pcrel = fixP->fx_pcrel; 2551 plt = fixP->fx_plt; 2552 2553 if (add_symbolP != NULL 2554 && symbol_mri_common_p (add_symbolP)) 2620 2621 if (fixP->fx_addsy != NULL 2622 && symbol_mri_common_p (fixP->fx_addsy)) 2555 2623 { 2556 know ( add_symbolP->sy_value.X_op == O_symbol);2557 add_number += S_GET_VALUE ( add_symbolP);2624 know (fixP->fx_addsy->sy_value.X_op == O_symbol); 2625 add_number += S_GET_VALUE (fixP->fx_addsy); 2558 2626 fixP->fx_offset = add_number; 2559 add_symbolP = fixP->fx_addsy =2560 symbol_get_value_expression (add_symbolP)->X_add_symbol;2627 fixP->fx_addsy 2628 = symbol_get_value_expression (fixP->fx_addsy)->X_add_symbol; 2561 2629 } 2562 2630 2563 if ( add_symbolP)2564 add_symbol_segment = S_GET_SEGMENT ( add_symbolP);2565 2566 if ( sub_symbolP)2631 if (fixP->fx_addsy != NULL) 2632 add_symbol_segment = S_GET_SEGMENT (fixP->fx_addsy); 2633 2634 if (fixP->fx_subsy != NULL) 2567 2635 { 2568 resolve_symbol_value (sub_symbolP, 1); 2569 if (add_symbolP == NULL || add_symbol_segment == absolute_section) 2636 segT sub_symbol_segment; 2637 resolve_symbol_value (fixP->fx_subsy); 2638 sub_symbol_segment = S_GET_SEGMENT (fixP->fx_subsy); 2639 if (fixP->fx_addsy != NULL 2640 && sub_symbol_segment == add_symbol_segment 2641 && !TC_FORCE_RELOCATION_SUB_SAME (fixP, add_symbol_segment)) 2570 2642 { 2571 if (add_symbolP != NULL) 2572 { 2573 add_number += S_GET_VALUE (add_symbolP); 2574 add_symbolP = NULL; 2575 fixP->fx_addsy = NULL; 2576 } 2577 2578 /* It's just -sym. */ 2579 if (S_GET_SEGMENT (sub_symbolP) == absolute_section) 2580 { 2581 add_number -= S_GET_VALUE (sub_symbolP); 2582 fixP->fx_subsy = NULL; 2583 } 2584 else if (pcrel 2585 && S_GET_SEGMENT (sub_symbolP) == this_segment_type) 2586 { 2587 /* Should try converting to a constant. */ 2588 goto bad_sub_reloc; 2589 } 2590 else 2591 bad_sub_reloc: 2592 as_bad_where (fixP->fx_file, fixP->fx_line, 2593 _("Negative of non-absolute symbol %s"), 2594 S_GET_NAME (sub_symbolP)); 2643 add_number += S_GET_VALUE (fixP->fx_addsy); 2644 add_number -= S_GET_VALUE (fixP->fx_subsy); 2645 fixP->fx_offset = add_number; 2646 /* If the back-end code has selected a pc-relative 2647 reloc, adjust the value to be pc-relative. */ 2648 if (1 2649 #ifdef TC_M68K 2650 /* See the comment below about 68k weirdness. */ 2651 && 0 2652 #endif 2653 && fixP->fx_pcrel) 2654 add_number -= MD_PCREL_FROM_SECTION (fixP, this_segment); 2655 fixP->fx_addsy = NULL; 2656 fixP->fx_subsy = NULL; 2657 fixP->fx_pcrel = 0; 2595 2658 } 2596 else if ( S_GET_SEGMENT (sub_symbolP) == add_symbol_segment2597 && SEG_NORMAL (add_symbol_segment))2659 else if (sub_symbol_segment == absolute_section 2660 && !TC_FORCE_RELOCATION_SUB_ABS (fixP)) 2598 2661 { 2599 /* Difference of 2 symbols from same segment. 2600 Can't make difference of 2 undefineds: 'value' means 2601 something different for N_UNDF. */ 2602 #ifdef TC_I960 2603 /* Makes no sense to use the difference of 2 arbitrary symbols 2604 as the target of a call instruction. */ 2605 if (fixP->fx_tcbit) 2606 as_bad_where (fixP->fx_file, fixP->fx_line, 2607 _("callj to difference of 2 symbols")); 2608 #endif /* TC_I960 */ 2609 add_number += S_GET_VALUE (add_symbolP) - 2610 S_GET_VALUE (sub_symbolP); 2611 2612 add_symbolP = NULL; 2613 pcrel = 0; /* No further pcrel processing. */ 2614 2615 /* Let the target machine make the final determination 2616 as to whether or not a relocation will be needed to 2617 handle this fixup. */ 2618 if (!TC_FORCE_RELOCATION_SECTION (fixP, this_segment_type)) 2619 { 2620 fixP->fx_pcrel = 0; 2621 fixP->fx_addsy = NULL; 2622 fixP->fx_subsy = NULL; 2623 } 2662 add_number -= S_GET_VALUE (fixP->fx_subsy); 2663 fixP->fx_offset = add_number; 2664 fixP->fx_subsy = NULL; 2624 2665 } 2625 else 2666 else if (sub_symbol_segment == this_segment 2667 && !TC_FORCE_RELOCATION_SUB_LOCAL (fixP)) 2626 2668 { 2627 /* Different segments in subtraction. */ 2628 know (!(S_IS_EXTERNAL (sub_symbolP) 2629 && (S_GET_SEGMENT (sub_symbolP) == absolute_section))); 2630 2631 if ((S_GET_SEGMENT (sub_symbolP) == absolute_section)) 2632 add_number -= S_GET_VALUE (sub_symbolP); 2633 2634 #ifdef DIFF_EXPR_OK 2635 else if (S_GET_SEGMENT (sub_symbolP) == this_segment_type 2636 #if 0 2637 /* Do this even if it's already described as 2638 pc-relative. For example, on the m68k, an 2639 operand of "pc@(foo-.-2)" should address 2640 "foo" in a pc-relative mode. */ 2641 && pcrel 2642 #endif 2643 ) 2644 { 2645 /* Make it pc-relative. */ 2646 add_number += (MD_PCREL_FROM_SECTION (fixP, this_segment_type) 2647 - S_GET_VALUE (sub_symbolP)); 2648 pcrel = 1; 2649 fixP->fx_pcrel = 1; 2650 sub_symbolP = 0; 2651 fixP->fx_subsy = 0; 2652 } 2653 #endif 2654 #ifdef UNDEFINED_DIFFERENCE_OK 2655 /* The PA needs this for PIC code generation. We basically 2656 don't want to do anything if we have the difference of two 2657 symbols at this point. */ 2658 else if (1) 2659 { 2660 /* Leave it alone. */ 2661 } 2662 #endif 2663 #ifdef BFD_ASSEMBLER 2664 else if (fixP->fx_r_type == BFD_RELOC_GPREL32 2665 || fixP->fx_r_type == BFD_RELOC_GPREL16) 2666 { 2667 /* Leave it alone. */ 2668 } 2669 #endif 2670 else 2671 { 2672 char buf[50]; 2673 sprint_value (buf, fragP->fr_address + where); 2674 as_bad_where (fixP->fx_file, fixP->fx_line, 2675 _("Subtraction of two symbols in different sections \"%s\" {%s section} - \"%s\" {%s section} at file address %s."), 2676 S_GET_NAME (add_symbolP), 2677 segment_name (S_GET_SEGMENT (add_symbolP)), 2678 S_GET_NAME (sub_symbolP), 2679 segment_name (S_GET_SEGMENT (sub_symbolP)), 2680 buf); 2681 } 2669 add_number -= S_GET_VALUE (fixP->fx_subsy); 2670 fixP->fx_offset = (add_number + fixP->fx_dot_value 2671 + fixP->fx_frag->fr_address); 2672 2673 /* Make it pc-relative. If the back-end code has not 2674 selected a pc-relative reloc, cancel the adjustment 2675 we do later on all pc-relative relocs. */ 2676 if (0 2677 #ifdef TC_M68K 2678 /* Do this for m68k even if it's already described 2679 as pc-relative. On the m68k, an operand of 2680 "pc@(foo-.-2)" should address "foo" in a 2681 pc-relative mode. */ 2682 || 1 2683 #endif 2684 || !fixP->fx_pcrel) 2685 add_number += MD_PCREL_FROM_SECTION (fixP, this_segment); 2686 fixP->fx_subsy = NULL; 2687 fixP->fx_pcrel = 1; 2688 } 2689 else if (!TC_VALIDATE_FIX_SUB (fixP)) 2690 { 2691 as_bad_where (fixP->fx_file, fixP->fx_line, 2692 _("can't resolve `%s' {%s section} - `%s' {%s section}"), 2693 fixP->fx_addsy ? S_GET_NAME (fixP->fx_addsy) : "0", 2694 segment_name (add_symbol_segment), 2695 S_GET_NAME (fixP->fx_subsy), 2696 segment_name (sub_symbol_segment)); 2682 2697 } 2683 2698 } 2684 2699 2685 if ( add_symbolP)2700 if (fixP->fx_addsy) 2686 2701 { 2687 if (add_symbol_segment == this_segment _type && pcrel && !plt2688 && TC_RELOC_RTSYM_LOC_FIXUP(fixP))2702 if (add_symbol_segment == this_segment 2703 && !TC_FORCE_RELOCATION_LOCAL (fixP)) 2689 2704 { 2690 2705 /* This fixup was made when the symbol's segment was 2691 2706 SEG_UNKNOWN, but it is now in the local segment. 2692 2707 So we know how to do the address without relocation. */ 2693 #ifdef TC_I960 2694 /* reloc_callj() may replace a 'call' with a 'calls' or a 2695 'bal', in which cases it modifies *fixP as appropriate. 2696 In the case of a 'calls', no further work is required, 2697 and *fixP has been set up to make the rest of the code 2698 below a no-op. */ 2699 reloc_callj (fixP); 2700 #endif /* TC_I960 */ 2701 2702 add_number += S_GET_VALUE (add_symbolP); 2703 add_number -= MD_PCREL_FROM_SECTION (fixP, this_segment_type); 2704 /* Lie. Don't want further pcrel processing. */ 2705 pcrel = 0; 2706 2707 /* Let the target machine make the final determination 2708 as to whether or not a relocation will be needed to 2709 handle this fixup. */ 2710 if (!TC_FORCE_RELOCATION (fixP)) 2711 { 2712 fixP->fx_pcrel = 0; 2713 fixP->fx_addsy = NULL; 2714 } 2708 add_number += S_GET_VALUE (fixP->fx_addsy); 2709 fixP->fx_offset = add_number; 2710 if (fixP->fx_pcrel) 2711 add_number -= MD_PCREL_FROM_SECTION (fixP, this_segment); 2712 fixP->fx_addsy = NULL; 2713 fixP->fx_pcrel = 0; 2715 2714 } 2716 else 2715 else if (add_symbol_segment == absolute_section 2716 && !TC_FORCE_RELOCATION_ABS (fixP)) 2717 2717 { 2718 if (add_symbol_segment == absolute_section 2719 && ! pcrel) 2720 { 2721 #ifdef TC_I960 2722 /* See comment about reloc_callj() above. */ 2723 reloc_callj (fixP); 2724 #endif /* TC_I960 */ 2725 add_number += S_GET_VALUE (add_symbolP); 2726 2727 /* Let the target machine make the final determination 2728 as to whether or not a relocation will be needed to 2729 handle this fixup. */ 2730 2731 if (!TC_FORCE_RELOCATION (fixP)) 2732 { 2733 fixP->fx_addsy = NULL; 2734 add_symbolP = NULL; 2735 } 2736 } 2737 else if (add_symbol_segment == undefined_section 2718 add_number += S_GET_VALUE (fixP->fx_addsy); 2719 fixP->fx_offset = add_number; 2720 fixP->fx_addsy = NULL; 2721 } 2722 else if (add_symbol_segment != undefined_section 2738 2723 #ifdef BFD_ASSEMBLER 2739 || bfd_is_com_section (add_symbol_segment) 2740 #endif 2741 ) 2742 { 2743 #ifdef TC_I960 2744 if ((int) fixP->fx_bit_fixP == 13) 2745 { 2746 /* This is a COBR instruction. They have only a 2747 13-bit displacement and are only to be used 2748 for local branches: flag as error, don't generate 2749 relocation. */ 2750 as_bad_where (fixP->fx_file, fixP->fx_line, 2751 _("can't use COBR format with external label")); 2752 fixP->fx_addsy = NULL; 2753 fixP->fx_done = 1; 2754 continue; 2755 } /* COBR. */ 2756 #endif /* TC_I960 */ 2757 2758 #ifdef OBJ_COFF 2759 #ifdef TE_I386AIX 2760 if (S_IS_COMMON (add_symbolP)) 2761 add_number += S_GET_VALUE (add_symbolP); 2762 #endif /* TE_I386AIX */ 2763 #endif /* OBJ_COFF */ 2764 ++seg_reloc_count; 2765 } 2766 else 2767 { 2768 seg_reloc_count++; 2769 if (TC_FIX_ADJUSTABLE (fixP)) 2770 add_number += S_GET_VALUE (add_symbolP); 2771 } 2724 && ! bfd_is_com_section (add_symbol_segment) 2725 #endif 2726 && MD_APPLY_SYM_VALUE (fixP)) 2727 add_number += S_GET_VALUE (fixP->fx_addsy); 2728 } 2729 2730 if (fixP->fx_pcrel) 2731 { 2732 add_number -= MD_PCREL_FROM_SECTION (fixP, this_segment); 2733 if (!fixP->fx_done && fixP->fx_addsy == NULL) 2734 { 2735 /* There was no symbol required by this relocation. 2736 However, BFD doesn't really handle relocations 2737 without symbols well. So fake up a local symbol in 2738 the absolute section. */ 2739 fixP->fx_addsy = abs_section_sym; 2772 2740 } 2773 2741 } 2774 2742 2775 if (pcrel) 2776 { 2777 add_number -= MD_PCREL_FROM_SECTION (fixP, this_segment_type); 2778 if (add_symbolP == 0) 2779 { 2780 #ifndef BFD_ASSEMBLER 2781 fixP->fx_addsy = &abs_symbol; 2782 #else 2783 fixP->fx_addsy = section_symbol (absolute_section); 2784 #endif 2785 symbol_mark_used_in_reloc (fixP->fx_addsy); 2786 ++seg_reloc_count; 2787 } 2788 } 2743 if (!fixP->fx_done) 2744 md_apply_fix3 (fixP, &add_number, this_segment); 2789 2745 2790 2746 if (!fixP->fx_done) 2791 2747 { 2792 #ifdef MD_APPLY_FIX3 2793 md_apply_fix3 (fixP, &add_number, this_segment_type); 2794 #else 2795 #ifdef BFD_ASSEMBLER 2796 md_apply_fix (fixP, &add_number); 2797 #else 2798 md_apply_fix (fixP, add_number); 2799 #endif 2800 #endif 2801 2802 #ifndef TC_HANDLES_FX_DONE 2803 /* If the tc-* files haven't been converted, assume it's handling 2804 it the old way, where a null fx_addsy means that the fix has 2805 been applied completely, and no further work is needed. */ 2806 if (fixP->fx_addsy == 0 && fixP->fx_pcrel == 0) 2807 fixP->fx_done = 1; 2808 #endif 2748 ++seg_reloc_count; 2749 if (fixP->fx_addsy == NULL) 2750 fixP->fx_addsy = abs_section_sym; 2751 symbol_mark_used_in_reloc (fixP->fx_addsy); 2752 if (fixP->fx_subsy != NULL) 2753 symbol_mark_used_in_reloc (fixP->fx_subsy); 2809 2754 } 2810 2755 2811 if (!fixP->fx_bit_fixP && !fixP->fx_no_overflow && size >0)2756 if (!fixP->fx_bit_fixP && !fixP->fx_no_overflow && fixP->fx_size != 0) 2812 2757 { 2813 if ( (size_t)size < sizeof (valueT))2758 if (fixP->fx_size < sizeof (valueT)) 2814 2759 { 2815 2760 valueT mask; … … 2817 2762 mask = 0; 2818 2763 mask--; /* Set all bits to one. */ 2819 mask <<= size * 8 - (fixP->fx_signed ? 1 : 0);2764 mask <<= fixP->fx_size * 8 - (fixP->fx_signed ? 1 : 0); 2820 2765 if ((add_number & mask) != 0 && (add_number & mask) != mask) 2821 2766 { 2822 2767 char buf[50], buf2[50]; 2823 sprint_value (buf, fragP->fr_address + where);2768 sprint_value (buf, fragP->fr_address + fixP->fx_where); 2824 2769 if (add_number > 1000) 2825 2770 sprint_value (buf2, add_number); … … 2827 2772 sprintf (buf2, "%ld", (long) add_number); 2828 2773 as_bad_where (fixP->fx_file, fixP->fx_line, 2829 _(" Value of %s too large for field of %d bytes at %s"),2830 buf2, size, buf);2774 _("value of %s too large for field of %d bytes at %s"), 2775 buf2, fixP->fx_size, buf); 2831 2776 } /* Generic error checking. */ 2832 2777 } … … 2836 2781 catch over-large switches generated by gcc on the 68k. */ 2837 2782 if (!flag_signed_overflow_ok 2838 && size == 22783 && fixP->fx_size == 2 2839 2784 && add_number > 0x7fff) 2840 2785 as_bad_where (fixP->fx_file, fixP->fx_line, 2841 _(" Signed .word overflow; switch may be too large; %ld at 0x%lx"),2786 _("signed .word overflow; switch may be too large; %ld at 0x%lx"), 2842 2787 (long) add_number, 2843 ( unsigned long) (fragP->fr_address +where));2788 (long) (fragP->fr_address + fixP->fx_where)); 2844 2789 #endif 2845 2790 } /* Not a bit fix. */ … … 2867 2812 int n; 2868 2813 { 2869 if ( (size_t) n > sizeof (val) ||n <= 0)2814 if (n <= 0) 2870 2815 abort (); 2871 2816 while (n--) … … 2882 2827 int n; 2883 2828 { 2884 if ( (size_t) n > sizeof (val) ||n <= 0)2829 if (n <= 0) 2885 2830 abort (); 2886 2831 while (n--) -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.