X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=gas%2Fconfig%2Ftc-sh.c;h=ee4058456e83dbaa59855081444a57976a4eb012;hb=bc805888417f16602aeb4bfd3f6e33d32ffcae24;hp=f2f27ade3d98ca882336d4914066dbbfa17a73a8;hpb=81d4177baa5f2bd91109912b42bd2d8b28ad5df8;p=deliverable%2Fbinutils-gdb.git diff --git a/gas/config/tc-sh.c b/gas/config/tc-sh.c index f2f27ade3d..ee4058456e 100644 --- a/gas/config/tc-sh.c +++ b/gas/config/tc-sh.c @@ -34,7 +34,6 @@ #endif #include "dwarf2dbg.h" -struct dwarf2_line_info debug_line; const char comment_chars[] = "!"; const char line_separator_chars[] = ";"; @@ -123,7 +122,6 @@ const char FLT_CHARS[] = "rRsSfFdDxXpP"; #define C(a,b) ENCODE_RELAX(a,b) -#define JREG 14 /* Register used as a temp when relaxing */ #define ENCODE_RELAX(what,length) (((what) << 4) + (length)) #define GET_WHAT(x) ((x>>4)) @@ -235,7 +233,7 @@ sh_elf_suffix (str_p, exp_p, new_exp_p) int len; struct map_bfd *ptr; -#define MAP(str,reloc) { str, sizeof(str)-1, reloc } +#define MAP(str,reloc) { str, sizeof (str)-1, reloc } static struct map_bfd mapping[] = { MAP ("got", BFD_RELOC_32_GOT_PCREL), @@ -390,7 +388,7 @@ sh_elf_cons (nbytes) input_line_pointer--; /* Put terminator back into stream. */ if (*input_line_pointer == '#' || *input_line_pointer == '!') { - while (! is_end_of_line[*input_line_pointer++]); + while (! is_end_of_line[(unsigned char) *input_line_pointer++]); } else demand_empty_rest_of_line (); @@ -464,13 +462,16 @@ parse_reg (src, mode, reg) int *mode; int *reg; { + char l0 = tolower (src[0]); + char l1 = l0 ? tolower (src[1]) : 0; + /* We use ! IDENT_CHAR for the next character after the register name, to make sure that we won't accidentally recognize a symbol name such as 'sram' or sr_ram as being a reference to the register 'sr'. */ - if (src[0] == 'r') + if (l0 == 'r') { - if (src[1] == '1') + if (l1 == '1') { if (src[2] >= '0' && src[2] <= '5' && ! IDENT_CHAR ((unsigned char) src[3])) @@ -480,36 +481,36 @@ parse_reg (src, mode, reg) return 3; } } - if (src[1] >= '0' && src[1] <= '9' + if (l1 >= '0' && l1 <= '9' && ! IDENT_CHAR ((unsigned char) src[2])) { *mode = A_REG_N; - *reg = (src[1] - '0'); + *reg = (l1 - '0'); return 2; } - if (src[1] >= '0' && src[1] <= '7' && strncmp (&src[2], "_bank", 5) == 0 + if (l1 >= '0' && l1 <= '7' && strncasecmp (&src[2], "_bank", 5) == 0 && ! IDENT_CHAR ((unsigned char) src[7])) { *mode = A_REG_B; - *reg = (src[1] - '0'); + *reg = (l1 - '0'); return 7; } - if (src[1] == 'e' && ! IDENT_CHAR ((unsigned char) src[2])) + if (l1 == 'e' && ! IDENT_CHAR ((unsigned char) src[2])) { *mode = A_RE; return 2; } - if (src[1] == 's' && ! IDENT_CHAR ((unsigned char) src[2])) + if (l1 == 's' && ! IDENT_CHAR ((unsigned char) src[2])) { *mode = A_RS; return 2; } } - if (src[0] == 'a') + if (l0 == 'a') { - if (src[1] == '0') + if (l1 == '0') { if (! IDENT_CHAR ((unsigned char) src[2])) { @@ -517,14 +518,14 @@ parse_reg (src, mode, reg) *reg = A_A0_NUM; return 2; } - if (src[2] == 'g' && ! IDENT_CHAR ((unsigned char) src[3])) + if (tolower (src[2]) == 'g' && ! IDENT_CHAR ((unsigned char) src[3])) { *mode = DSP_REG_N; *reg = A_A0G_NUM; return 3; } } - if (src[1] == '1') + if (l1 == '1') { if (! IDENT_CHAR ((unsigned char) src[2])) { @@ -532,7 +533,7 @@ parse_reg (src, mode, reg) *reg = A_A1_NUM; return 2; } - if (src[2] == 'g' && ! IDENT_CHAR ((unsigned char) src[3])) + if (tolower (src[2]) == 'g' && ! IDENT_CHAR ((unsigned char) src[3])) { *mode = DSP_REG_N; *reg = A_A1G_NUM; @@ -540,24 +541,24 @@ parse_reg (src, mode, reg) } } - if (src[1] == 'x' && src[2] >= '0' && src[2] <= '1' + if (l1 == 'x' && src[2] >= '0' && src[2] <= '1' && ! IDENT_CHAR ((unsigned char) src[3])) { *mode = A_REG_N; - *reg = 4 + (src[1] - '0'); + *reg = 4 + (l1 - '0'); return 3; } - if (src[1] == 'y' && src[2] >= '0' && src[2] <= '1' + if (l1 == 'y' && src[2] >= '0' && src[2] <= '1' && ! IDENT_CHAR ((unsigned char) src[3])) { *mode = A_REG_N; - *reg = 6 + (src[1] - '0'); + *reg = 6 + (l1 - '0'); return 3; } - if (src[1] == 's' && src[2] >= '0' && src[2] <= '3' + if (l1 == 's' && src[2] >= '0' && src[2] <= '3' && ! IDENT_CHAR ((unsigned char) src[3])) { - int n = src[1] - '0'; + int n = l1 - '0'; *mode = A_REG_N; *reg = n | ((~n & 2) << 1); @@ -565,21 +566,21 @@ parse_reg (src, mode, reg) } } - if (src[0] == 'i' && src[1] && ! IDENT_CHAR ((unsigned char) src[3])) + if (l0 == 'i' && l1 && ! IDENT_CHAR ((unsigned char) src[3])) { - if (src[1] == 's') + if (l1 == 's') { *mode = A_REG_N; *reg = 8; return 2; } - if (src[1] == 'x') + if (l1 == 'x') { *mode = A_REG_N; *reg = 8; return 2; } - if (src[1] == 'y') + if (l1 == 'y') { *mode = A_REG_N; *reg = 9; @@ -587,105 +588,105 @@ parse_reg (src, mode, reg) } } - if (src[0] == 'x' && src[1] >= '0' && src[1] <= '1' + if (l0 == 'x' && l1 >= '0' && l1 <= '1' && ! IDENT_CHAR ((unsigned char) src[2])) { *mode = DSP_REG_N; - *reg = A_X0_NUM + src[1] - '0'; + *reg = A_X0_NUM + l1 - '0'; return 2; } - if (src[0] == 'y' && src[1] >= '0' && src[1] <= '1' + if (l0 == 'y' && l1 >= '0' && l1 <= '1' && ! IDENT_CHAR ((unsigned char) src[2])) { *mode = DSP_REG_N; - *reg = A_Y0_NUM + src[1] - '0'; + *reg = A_Y0_NUM + l1 - '0'; return 2; } - if (src[0] == 'm' && src[1] >= '0' && src[1] <= '1' + if (l0 == 'm' && l1 >= '0' && l1 <= '1' && ! IDENT_CHAR ((unsigned char) src[2])) { *mode = DSP_REG_N; - *reg = src[1] == '0' ? A_M0_NUM : A_M1_NUM; + *reg = l1 == '0' ? A_M0_NUM : A_M1_NUM; return 2; } - if (src[0] == 's' - && src[1] == 's' - && src[2] == 'r' && ! IDENT_CHAR ((unsigned char) src[3])) + if (l0 == 's' + && l1 == 's' + && tolower (src[2]) == 'r' && ! IDENT_CHAR ((unsigned char) src[3])) { *mode = A_SSR; return 3; } - if (src[0] == 's' && src[1] == 'p' && src[2] == 'c' + if (l0 == 's' && l1 == 'p' && tolower (src[2]) == 'c' && ! IDENT_CHAR ((unsigned char) src[3])) { *mode = A_SPC; return 3; } - if (src[0] == 's' && src[1] == 'g' && src[2] == 'r' + if (l0 == 's' && l1 == 'g' && tolower (src[2]) == 'r' && ! IDENT_CHAR ((unsigned char) src[3])) { *mode = A_SGR; return 3; } - if (src[0] == 'd' && src[1] == 's' && src[2] == 'r' + if (l0 == 'd' && l1 == 's' && tolower (src[2]) == 'r' && ! IDENT_CHAR ((unsigned char) src[3])) { *mode = A_DSR; return 3; } - if (src[0] == 'd' && src[1] == 'b' && src[2] == 'r' + if (l0 == 'd' && l1 == 'b' && tolower (src[2]) == 'r' && ! IDENT_CHAR ((unsigned char) src[3])) { *mode = A_DBR; return 3; } - if (src[0] == 's' && src[1] == 'r' && ! IDENT_CHAR ((unsigned char) src[2])) + if (l0 == 's' && l1 == 'r' && ! IDENT_CHAR ((unsigned char) src[2])) { *mode = A_SR; return 2; } - if (src[0] == 's' && src[1] == 'p' && ! IDENT_CHAR ((unsigned char) src[2])) + if (l0 == 's' && l1 == 'p' && ! IDENT_CHAR ((unsigned char) src[2])) { *mode = A_REG_N; *reg = 15; return 2; } - if (src[0] == 'p' && src[1] == 'r' && ! IDENT_CHAR ((unsigned char) src[2])) + if (l0 == 'p' && l1 == 'r' && ! IDENT_CHAR ((unsigned char) src[2])) { *mode = A_PR; return 2; } - if (src[0] == 'p' && src[1] == 'c' && ! IDENT_CHAR ((unsigned char) src[2])) + if (l0 == 'p' && l1 == 'c' && ! IDENT_CHAR ((unsigned char) src[2])) { /* Don't use A_DISP_PC here - that would accept stuff like 'mova pc,r0' and use an uninitialized immediate. */ *mode = A_PC; return 2; } - if (src[0] == 'g' && src[1] == 'b' && src[2] == 'r' + if (l0 == 'g' && l1 == 'b' && tolower (src[2]) == 'r' && ! IDENT_CHAR ((unsigned char) src[3])) { *mode = A_GBR; return 3; } - if (src[0] == 'v' && src[1] == 'b' && src[2] == 'r' + if (l0 == 'v' && l1 == 'b' && tolower (src[2]) == 'r' && ! IDENT_CHAR ((unsigned char) src[3])) { *mode = A_VBR; return 3; } - if (src[0] == 'm' && src[1] == 'a' && src[2] == 'c' + if (l0 == 'm' && l1 == 'a' && tolower (src[2]) == 'c' && ! IDENT_CHAR ((unsigned char) src[4])) { if (src[3] == 'l') @@ -699,13 +700,13 @@ parse_reg (src, mode, reg) return 4; } } - if (src[0] == 'm' && src[1] == 'o' && src[2] == 'd' + if (l0 == 'm' && l1 == 'o' && tolower (src[2]) == 'd' && ! IDENT_CHAR ((unsigned char) src[4])) { *mode = A_MOD; return 3; } - if (src[0] == 'f' && src[1] == 'r') + if (l0 == 'f' && l1 == 'r') { if (src[2] == '1') { @@ -725,7 +726,7 @@ parse_reg (src, mode, reg) return 3; } } - if (src[0] == 'd' && src[1] == 'r') + if (l0 == 'd' && l1 == 'r') { if (src[2] == '1') { @@ -745,7 +746,7 @@ parse_reg (src, mode, reg) return 3; } } - if (src[0] == 'x' && src[1] == 'd') + if (l0 == 'x' && l1 == 'd') { if (src[2] == '1') { @@ -765,7 +766,7 @@ parse_reg (src, mode, reg) return 3; } } - if (src[0] == 'f' && src[1] == 'v') + if (l0 == 'f' && l1 == 'v') { if (src[2] == '1'&& src[3] == '2' && ! IDENT_CHAR ((unsigned char) src[4])) { @@ -781,22 +782,25 @@ parse_reg (src, mode, reg) return 3; } } - if (src[0] == 'f' && src[1] == 'p' && src[2] == 'u' && src[3] == 'l' + if (l0 == 'f' && l1 == 'p' && tolower (src[2]) == 'u' + && tolower (src[3]) == 'l' && ! IDENT_CHAR ((unsigned char) src[4])) { *mode = FPUL_N; return 4; } - if (src[0] == 'f' && src[1] == 'p' && src[2] == 's' && src[3] == 'c' - && src[4] == 'r' && ! IDENT_CHAR ((unsigned char) src[5])) + if (l0 == 'f' && l1 == 'p' && tolower (src[2]) == 's' + && tolower (src[3]) == 'c' + && tolower (src[4]) == 'r' && ! IDENT_CHAR ((unsigned char) src[5])) { *mode = FPSCR_N; return 5; } - if (src[0] == 'x' && src[1] == 'm' && src[2] == 't' && src[3] == 'r' - && src[4] == 'x' && ! IDENT_CHAR ((unsigned char) src[5])) + if (l0 == 'x' && l1 == 'm' && tolower (src[2]) == 't' + && tolower (src[3]) == 'r' + && tolower (src[4]) == 'x' && ! IDENT_CHAR ((unsigned char) src[5])) { *mode = XMTRX_M4; return 5; @@ -1863,7 +1867,7 @@ md_assemble (str) unsigned char *op_end; sh_operand_info operand[3]; sh_opcode_info *opcode; - unsigned int size; + unsigned int size = 0; opcode = find_cooked_opcode (&str); op_end = str; @@ -1931,20 +1935,7 @@ md_assemble (str) } } - if (debug_type == DEBUG_DWARF2) - { - bfd_vma addr; - - /* First update the notion of the current source line. */ - dwarf2_where (&debug_line); - - /* We want the offset of the start of this instruction within the - the current frag. may be used later */ - addr = frag_now->fr_address + frag_now_fix () - size; - - /* And record the information. */ - dwarf2_gen_line_info (addr, &debug_line); - } + dwarf2_emit_insn (size); } /* This routine is called each time a label definition is seen. It @@ -2406,58 +2397,19 @@ md_convert_frag (headers, seg, fragP) case C (UNCOND_JUMP, UNCOND32): case C (UNCOND_JUMP, UNDEF_WORD_DISP): if (fragP->fr_symbol == NULL) - as_bad (_("at 0x%lx, displacement overflows 12-bit field"), - (unsigned long) fragP->fr_address); + as_bad_where (fragP->fr_file, fragP->fr_line, + _("displacement overflows 12-bit field")); else if (S_IS_DEFINED (fragP->fr_symbol)) - as_bad (_("at 0x%lx, displacement to defined symbol %s overflows 12-bit field"), - (unsigned long) fragP->fr_address, - S_GET_NAME (fragP->fr_symbol)); + as_bad_where (fragP->fr_file, fragP->fr_line, + _("displacement to defined symbol %s overflows 12-bit field"), + S_GET_NAME (fragP->fr_symbol)); else - as_bad (_("at 0x%lx, displacement to undefined symbol %s overflows 12-bit field"), - (unsigned long) fragP->fr_address, - S_GET_NAME (fragP->fr_symbol)); - -#if 0 - /* This code works, but generates poor code and the compiler - should never produce a sequence that requires it to be used. */ - - /* A jump wont fit in 12 bits, make code which looks like - bra foo - mov.w @(0, PC), r14 - .long disp - foo: bra @r14 - */ - int t = buffer[0] & 0x10; - - buffer[highbyte ] = 0xa0; /* branch over move and disp */ - buffer[lowbyte ] = 3; - buffer[highbyte + 2] = 0xd0 | JREG; /* Build mov insn */ - buffer[lowbyte + 2] = 0x00; - - buffer[highbyte + 4] = 0; /* space for 32 bit jump disp */ - buffer[lowbyte + 4] = 0; - buffer[highbyte + 6] = 0; - buffer[lowbyte + 6] = 0; - - buffer[highbyte + 8] = 0x40 | JREG; /* Build jmp @JREG */ - buffer[lowbyte + 8] = t ? 0xb : 0x2b; - - buffer[highbyte + 10] = 0x20; /* build nop */ - buffer[lowbyte + 10] = 0x0b; - - /* Make reloc for the long disp. */ - fix_new (fragP, - fragP->fr_fix + 4, - 4, - fragP->fr_symbol, - fragP->fr_offset, - 0, - BFD_RELOC_32); - fragP->fr_fix += UNCOND32_LENGTH; + as_bad_where (fragP->fr_file, fragP->fr_line, + _("displacement to undefined symbol %s overflows 12-bit field"), + S_GET_NAME (fragP->fr_symbol)); + /* Stabilize this frag, so we don't trip an assert. */ + fragP->fr_fix += fragP->fr_var; fragP->fr_var = 0; - donerelax = 1; -#endif - break; case C (COND_JUMP, COND12): @@ -2530,59 +2482,19 @@ md_convert_frag (headers, seg, fragP) case C (COND_JUMP, UNDEF_WORD_DISP): case C (COND_JUMP_DELAY, UNDEF_WORD_DISP): if (fragP->fr_symbol == NULL) - as_bad (_("at 0x%lx, displacement overflows 8-bit field"), - (unsigned long) fragP->fr_address); + as_bad_where (fragP->fr_file, fragP->fr_line, + _("displacement overflows 8-bit field")); else if (S_IS_DEFINED (fragP->fr_symbol)) - as_bad (_("at 0x%lx, displacement to defined symbol %s overflows 8-bit field "), - (unsigned long) fragP->fr_address, - S_GET_NAME (fragP->fr_symbol)); + as_bad_where (fragP->fr_file, fragP->fr_line, + _("displacement to defined symbol %s overflows 8-bit field"), + S_GET_NAME (fragP->fr_symbol)); else - as_bad (_("at 0x%lx, displacement to undefined symbol %s overflows 8-bit field "), - (unsigned long) fragP->fr_address, - S_GET_NAME (fragP->fr_symbol)); - -#if 0 - /* This code works, but generates poor code, and the compiler - should never produce a sequence that requires it to be used. */ - - /* A bcond won't fit and it won't go into a 12 bit - displacement either, the code sequence looks like: - b!cond foop - mov.w @(n, PC), r14 - jmp @r14 - nop - .long where - foop: - */ - - buffer[0] ^= 0x2; /* Toggle T/F bit */ -#define JREG 14 - buffer[1] = 5; /* branch over mov, jump, nop and ptr */ - buffer[2] = 0xd0 | JREG; /* Build mov insn */ - buffer[3] = 0x2; - buffer[4] = 0x40 | JREG; /* Build jmp @JREG */ - buffer[5] = 0x0b; - buffer[6] = 0x20; /* build nop */ - buffer[7] = 0x0b; - buffer[8] = 0; /* space for 32 bit jump disp */ - buffer[9] = 0; - buffer[10] = 0; - buffer[11] = 0; - buffer[12] = 0; - buffer[13] = 0; - /* Make reloc for the long disp */ - fix_new (fragP, - fragP->fr_fix + 8, - 4, - fragP->fr_symbol, - fragP->fr_offset, - 0, - BFD_RELOC_32); - fragP->fr_fix += COND32_LENGTH; + as_bad_where (fragP->fr_file, fragP->fr_line, + _("displacement to undefined symbol %s overflows 8-bit field "), + S_GET_NAME (fragP->fr_symbol)); + /* Stabilize this frag, so we don't trip an assert. */ + fragP->fr_fix += fragP->fr_var; fragP->fr_var = 0; - donerelax = 1; -#endif - break; default: @@ -2599,7 +2511,7 @@ md_convert_frag (headers, seg, fragP) valueT md_section_align (seg, size) - segT seg; + segT seg ATTRIBUTE_UNUSED; valueT size; { #ifdef BFD_ASSEMBLER @@ -2865,8 +2777,17 @@ md_apply_fix (fixP, val) /* The function adjust_reloc_syms won't convert a reloc against a weak symbol into a reloc against a section, but bfd_install_relocation will screw up if the symbol is defined, so we have to adjust val here - to avoid the screw up later. */ - if (fixP->fx_addsy != NULL + to avoid the screw up later. + + For ordinary relocs, this does not happen for ELF, since for ELF, + bfd_install_relocation uses the "special function" field of the + howto, and does not execute the code that needs to be undone, as long + as the special function does not return bfd_reloc_continue. + It can happen for GOT- and PLT-type relocs the way they are + described in elf32-sh.c as they use bfd_elf_generic_reloc, but it + doesn't matter here since those relocs don't use VAL; see below. */ + if (OUTPUT_FLAVOR != bfd_target_elf_flavour + && fixP->fx_addsy != NULL && S_IS_WEAK (fixP->fx_addsy)) val -= S_GET_VALUE (fixP->fx_addsy); #endif @@ -2965,7 +2886,7 @@ md_apply_fix (fixP, val) case BFD_RELOC_SH_PCDISP12BY2: val /= 2; - if (val < -0x800 || val >= 0x7ff) + if (val < -0x800 || val > 0x7ff) as_bad_where (fixP->fx_file, fixP->fx_line, _("pcrel too far")); buf[lowbyte] = val & 0xff; buf[highbyte] |= (val >> 8) & 0xf; @@ -3413,10 +3334,3 @@ tc_gen_reloc (section, fixp) } #endif /* BFD_ASSEMBLER */ - -void -sh_finalize () -{ - if (debug_type == DEBUG_DWARF2) - dwarf2_finish (); -}