Index: gas/config/tc-mips.c =================================================================== --- gas/config/tc-mips.c 2011-07-24 15:07:48.000000000 +0100 +++ gas/config/tc-mips.c 2011-07-24 15:07:51.000000000 +0100 @@ -203,9 +203,6 @@ static bfd_boolean mips_in_shared = TRUE pseudo-op. We use a struct so that .set push and .set pop are more reliable. */ -/* Whether or not we emit branch likely macros. */ -static bfd_boolean emit_branch_likely_macro = FALSE; - struct mips_set_options { /* MIPS ISA (Instruction Set Architecture) level. This is set to -1 @@ -644,7 +641,7 @@ static struct hash_control *op_hash = NU /* The opcode hash table we use for the mips16. */ static struct hash_control *mips16_op_hash = NULL; -/* The opcode hash table we use for the micromips. */ +/* The opcode hash table we use for the microMIPS ASE. */ static struct hash_control *micromips_op_hash = NULL; /* This array holds the chars that always start a comment. If the @@ -745,7 +742,7 @@ #define MAX_NOPS 4 #define NOP_INSN (mips_opts.mips16 ? &mips16_nop_insn \ : (mips_opts.micromips ? µmips_nop16_insn : &nop_insn)) -/* The number of bytes NOP takes for the current mode. */ +/* The size of NOP_INSN in bytes. */ #define NOP_INSN_SIZE (HAVE_CODE_COMPRESSION ? 2 : 4) /* If this is set, it points to a frag holding nop instructions which @@ -1251,6 +1248,9 @@ #define MIPS16_EXTRACT_OPERAND(FIELD, IN MIPS16OP_MASK_##FIELD, \ MIPS16OP_SH_##FIELD) +/* Whether or not we are emitting a branch-likely macro. */ +static bfd_boolean emit_branch_likely_macro = FALSE; + /* Global variables used when generating relaxable macros. See the comment above RELAX_ENCODE for more details about how relaxation is used. */ @@ -1292,12 +1292,14 @@ #define MIPS16_EXTRACT_OPERAND(FIELD, IN is the length of the first instruction of the second alternative. For non-relaxable macros, both elements give the length of the first instruction in bytes. + Set to zero if we haven't yet seen the first instruction. */ unsigned int first_insn_sizes[2]; /* For relaxable macros, insns[0] is the number of instructions for the first alternative and insns[1] is the number of instructions for the second alternative. + For non-relaxable macros, both elements give the number of instructions for the macro. */ unsigned int insns[2]; @@ -1542,10 +1544,11 @@ mips_clear_insn_labels (void) } } +/* Mark instruction labels in MIPS16/microMIPS mode. */ + static inline void mips_mark_labels (void) { - /* Mark instruction labels in MIPS16/microMIPS mode. */ if (HAVE_CODE_COMPRESSION) mips_compressed_mark_labels (); } @@ -2071,7 +2074,6 @@ static const struct regname reg_names_n3 {0, 0} }; - /* Check if S points at a valid register specifier according to TYPES. If so, then return 1, advance S to consume the specifier and store the register's number in REGNOP, otherwise return 0. */ @@ -3973,7 +3975,8 @@ micromips_map_reloc (bfd_reloc_code_real /* Output an instruction. IP is the instruction information. ADDRESS_EXPR is an operand of the instruction to be used with - RELOC_TYPE. */ + RELOC_TYPE. EXPANSIONP is true if the instruction is part of + a macro expansion. */ static void append_insn (struct mips_cl_insn *ip, expressionS *address_expr, @@ -4209,12 +4212,12 @@ append_insn (struct mips_cl_insn *ip, ex 16-bit/32-bit instructions. */ && !forced_insn_length); - if (address_expr + if (!HAVE_CODE_COMPRESSION + && address_expr && relax32 && *reloc_type == BFD_RELOC_16_PCREL_S2 && (pinfo & INSN_UNCOND_BRANCH_DELAY || pinfo & INSN_COND_BRANCH_DELAY - || pinfo & INSN_COND_BRANCH_LIKELY) - && !HAVE_CODE_COMPRESSION) + || pinfo & INSN_COND_BRANCH_LIKELY)) { relaxed_branch = TRUE; add_relaxed_insn (ip, (relaxed_branch_length @@ -4232,14 +4235,14 @@ append_insn (struct mips_cl_insn *ip, ex address_expr->X_add_number); *reloc_type = BFD_RELOC_UNUSED; } - else if (address_expr + else if (mips_opts.micromips + && address_expr && ((relax32 && *reloc_type == BFD_RELOC_16_PCREL_S2) || *reloc_type > BFD_RELOC_UNUSED) && (pinfo & INSN_UNCOND_BRANCH_DELAY || pinfo & INSN_COND_BRANCH_DELAY || (pinfo2 & ~INSN2_ALIAS) == INSN2_UNCOND_BRANCH - || pinfo2 & INSN2_COND_BRANCH) - && mips_opts.micromips) + || pinfo2 & INSN2_COND_BRANCH)) { bfd_boolean relax16 = *reloc_type > BFD_RELOC_UNUSED; int type = relax16 ? *reloc_type - BFD_RELOC_UNUSED : 0; @@ -4348,6 +4351,7 @@ append_insn (struct mips_cl_insn *ip, ex howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_16); } + howto = bfd_reloc_type_lookup (stdoutput, final_type[0]); ip->fixp[0] = fix_new_exp (ip->frag, ip->where, bfd_get_reloc_size (howto), address_expr, @@ -4503,12 +4507,10 @@ append_insn (struct mips_cl_insn *ip, ex && (history[0].insn_mo->pinfo & MIPS16_INSN_UNCOND_BRANCH))) mips_no_prev_insn (); - /* For branch likely macro, we need to emit a label at the end. */ + /* We need to emit a label at the end of branch-likely macros. */ if (emit_branch_likely_macro) { emit_branch_likely_macro = FALSE; - - /* We need to generate a label. */ micromips_add_label (); } @@ -4723,8 +4725,7 @@ macro_end (void) relax_substateT s; const char *msg; - s = (subtype - & (RELAX_SECOND_LONGER | RELAX_NOMACRO | RELAX_DELAY_SLOT)); + s = subtype & (RELAX_SECOND_LONGER | RELAX_NOMACRO | RELAX_DELAY_SLOT); msg = macro_warning (s); if (msg != NULL) as_warn ("%s", msg); @@ -5259,7 +5260,7 @@ macro_build_jalr (expressionS *ep, int c static const bfd_reloc_code_real_type jalr_relocs[2] = { BFD_RELOC_MIPS_JALR, BFD_RELOC_MICROMIPS_JALR }; bfd_reloc_code_real_type jalr_reloc = jalr_relocs[mips_opts.micromips]; - const char *jalr = mips_opts.noreorder && !cprestore ? "jalr" : "jalrs"; + const char *jalr; char *f = NULL; if (MIPS_JALR_HINT_P (ep)) @@ -5269,10 +5270,14 @@ macro_build_jalr (expressionS *ep, int c } if (!mips_opts.micromips) macro_build (NULL, "jalr", "d,s", RA, PIC_CALL_REG); - else if (MIPS_JALR_HINT_P (ep)) - macro_build (NULL, jalr, "t,s", RA, PIC_CALL_REG); else - macro_build (NULL, jalr, "mj", PIC_CALL_REG); + { + jalr = mips_opts.noreorder && !cprestore ? "jalr" : "jalrs"; + if (MIPS_JALR_HINT_P (ep)) + macro_build (NULL, jalr, "t,s", RA, PIC_CALL_REG); + else + macro_build (NULL, jalr, "mj", PIC_CALL_REG); + } if (MIPS_JALR_HINT_P (ep)) fix_new_exp (frag_now, f - frag_now->fr_literal, 4, ep, FALSE, jalr_reloc); } @@ -6031,23 +6036,28 @@ add_got_offset_hilo (int dest, expressio /* Emit a sequence of instructions to emulate a branch likely operation. BR is an ordinary branch corresponding to one to be emulated. BRNEG is its complementing branch with the original condition negated. - CALL is set if the original branch specified the link operation. EP, - FMT, SREG and TREG specify the usual macro_build() parameters. + CALL is set if the original branch specified the link operation. + EP, FMT, SREG and TREG specify the usual macro_build() parameters. Code like this is produced in the noreorder mode: + BRNEG , 1f nop b delay slot (executed only if branch taken) 1: - or: + + or, if CALL is set: + BRNEG , 1f nop bal delay slot (executed only if branch taken) 1: - if CALL is set. In the reorder mode the delay slot would be filled - with a nop anyway, so code produced is simply: + + In the reorder mode the delay slot would be filled with a nop anyway, + so code produced is simply: + BR , nop Index: gas/testsuite/gas/mips/dli.s =================================================================== --- gas/testsuite/gas/mips/dli.s 2011-07-24 15:01:44.000000000 +0100 +++ gas/testsuite/gas/mips/dli.s 2011-07-24 15:07:51.000000000 +0100 @@ -62,6 +62,4 @@ foo: dli $4,0x003ffc03ffffc000 # Round to a 16 byte boundary, for ease in testing multiple targets. - nop - nop - nop + .p2align 4 Index: gas/testsuite/gas/mips/micromips-trap.d =================================================================== --- gas/testsuite/gas/mips/micromips-trap.d 2011-07-24 15:05:46.000000000 +0100 +++ gas/testsuite/gas/mips/micromips-trap.d 2011-07-24 15:07:52.000000000 +0100 @@ -1,6 +1,6 @@ #objdump: -dr --show-raw-insn #name: microMIPS for MIPS32r2 (w/traps) -#as: -mips32r2 -32 -trap -mfp64 +#as: -mips32r2 -32 -trap -mfp64 -EB #stderr: micromips.l #source: micromips.s Index: gas/testsuite/gas/mips/micromips.d =================================================================== --- gas/testsuite/gas/mips/micromips.d 2011-07-24 15:05:46.000000000 +0100 +++ gas/testsuite/gas/mips/micromips.d 2011-07-24 15:07:52.000000000 +0100 @@ -1,6 +1,6 @@ #objdump: -dr --show-raw-insn #name: microMIPS for MIPS32r2 -#as: -mips32r2 -32 -mfp64 +#as: -mips32r2 -32 -mfp64 -EB #stderr: micromips.l #source: micromips.s Index: gas/testsuite/gas/mips/micromips@dli.d =================================================================== --- gas/testsuite/gas/mips/micromips@dli.d 2011-07-24 15:05:46.000000000 +0100 +++ gas/testsuite/gas/mips/micromips@dli.d 2011-07-24 15:07:51.000000000 +0100 @@ -113,7 +113,4 @@ Disassembly of section \.text: [0-9a-f]+ <[^>]*> 5084 ffff ori a0,a0,0xffff [0-9a-f]+ <[^>]*> 5884 8000 dsll a0,a0,0x10 [0-9a-f]+ <[^>]*> 5084 c000 ori a0,a0,0xc000 -[0-9a-f]+ <[^>]*> 0c00 nop -[0-9a-f]+ <[^>]*> 0c00 nop -[0-9a-f]+ <[^>]*> 0c00 nop -[0-9a-f]+ <[^>]*> 0c00 nop + \.\.\. Index: gas/testsuite/gas/mips/micromips@elfel-rel2.d =================================================================== --- /dev/null 2011-07-24 10:34:17.994719526 +0100 +++ gas/testsuite/gas/mips/micromips@elfel-rel2.d 2011-07-24 15:07:52.000000000 +0100 @@ -0,0 +1,28 @@ +#objdump: -sr -j .text +#name: MIPS ELF reloc 2 +#source: elf-rel2.s +#as: -mabi=o64 + +# Test the GPREL and LITERAL generation (microMIPS). +# FIXME: really this should check that the contents of .sdata, .lit4, +# and .lit8 are correct too. + +.*: +file format .*mips.* + +RELOCATION RECORDS FOR \[\.text\]: +OFFSET [ ]+ TYPE VALUE +0+0000000 R_MICROMIPS_LITERAL \.lit8 +0+0000004 R_MICROMIPS_LITERAL \.lit8 +0+0000008 R_MICROMIPS_LITERAL \.lit8 +0+000000c R_MICROMIPS_LITERAL \.lit4 +0+0000010 R_MICROMIPS_LITERAL \.lit4 +0+0000014 R_MICROMIPS_LITERAL \.lit4 +0+0000018 R_MICROMIPS_GPREL16 \.sdata +0+000001c R_MICROMIPS_GPREL16 \.sdata +0+0000020 R_MICROMIPS_GPREL16 \.sdata + + +Contents of section \.text: + 0000 5cbc0000 5cbc0800 5cbc1000 5c9c0000 .* + 0010 5c9c0400 5c9c0800 5cfc0000 5cfc0400 .* + 0020 5cfc0800 .* Index: gas/testsuite/gas/mips/micromips@mips4-branch-likely.d =================================================================== --- gas/testsuite/gas/mips/micromips@mips4-branch-likely.d 2011-07-24 15:05:46.000000000 +0100 +++ gas/testsuite/gas/mips/micromips@mips4-branch-likely.d 2011-07-24 15:07:51.000000000 +0100 @@ -1,6 +1,7 @@ #objdump: -dr --prefix-addresses --show-raw-insn #name: MIPS mips4 branch-likely instructions #source: mips4-branch-likely.s +#as: -32 # Test mips4 branch-likely instructions (microMIPS). Index: gas/testsuite/gas/mips/micromips@mips4-fp.d =================================================================== --- gas/testsuite/gas/mips/micromips@mips4-fp.d 2011-07-24 15:05:46.000000000 +0100 +++ gas/testsuite/gas/mips/micromips@mips4-fp.d 2011-07-24 15:07:51.000000000 +0100 @@ -1,6 +1,7 @@ #objdump: -dr --prefix-addresses --show-raw-insn #name: MIPS mips4 fp #source: mips4-fp.s +#as: -32 # Test mips4 fp instructions (microMIPS). Index: gas/testsuite/gas/mips/mips.exp =================================================================== --- gas/testsuite/gas/mips/mips.exp 2011-07-24 15:06:40.000000000 +0100 +++ gas/testsuite/gas/mips/mips.exp 2011-07-24 15:07:51.000000000 +0100 @@ -489,21 +489,31 @@ if { [istarget mips*-*-vxworks*] } { run_dump_test "eret-1" run_dump_test "eret-2" run_dump_test "eret-3" - run_dump_test_arches "24k-branch-delay-1" [mips_arch_list_matching mips1] + run_dump_test_arches "24k-branch-delay-1" \ + [mips_arch_list_matching mips1 !micromips] run_dump_test_arches "24k-triple-stores-1" \ - [mips_arch_list_matching mips32r2 !octeon] - run_dump_test_arches "24k-triple-stores-2" [mips_arch_list_matching mips2] - run_dump_test_arches "24k-triple-stores-3" [mips_arch_list_matching mips3] - run_dump_test_arches "24k-triple-stores-4" [mips_arch_list_matching mips2] - run_dump_test_arches "24k-triple-stores-5" [mips_arch_list_matching mips1] - run_dump_test_arches "24k-triple-stores-6" [mips_arch_list_matching mips2] - run_dump_test_arches "24k-triple-stores-7" [mips_arch_list_matching mips2] - run_dump_test_arches "24k-triple-stores-8" [mips_arch_list_matching mips1] - run_dump_test_arches "24k-triple-stores-9" [mips_arch_list_matching mips1] - run_dump_test_arches "24k-triple-stores-10" [mips_arch_list_matching mips1] + [mips_arch_list_matching mips32r2 !octeon !micromips] + run_dump_test_arches "24k-triple-stores-2" \ + [mips_arch_list_matching mips2 !micromips] + run_dump_test_arches "24k-triple-stores-3" \ + [mips_arch_list_matching mips3 !micromips] + run_dump_test_arches "24k-triple-stores-4" \ + [mips_arch_list_matching mips2 !micromips] + run_dump_test_arches "24k-triple-stores-5" \ + [mips_arch_list_matching mips1 !micromips] + run_dump_test_arches "24k-triple-stores-6" \ + [mips_arch_list_matching mips2 !micromips] + run_dump_test_arches "24k-triple-stores-7" \ + [mips_arch_list_matching mips2 !micromips] + run_dump_test_arches "24k-triple-stores-8" \ + [mips_arch_list_matching mips1 !micromips] + run_dump_test_arches "24k-triple-stores-9" \ + [mips_arch_list_matching mips1 !micromips] + run_dump_test_arches "24k-triple-stores-10" \ + [mips_arch_list_matching mips1 !micromips] if $elf { run_dump_test_arches "24k-triple-stores-11" \ - [mips_arch_list_matching mips1] + [mips_arch_list_matching mips1 !micromips] } if $elf { Index: gas/testsuite/gas/mips/mipsel16-e.d =================================================================== --- gas/testsuite/gas/mips/mipsel16-e.d 2011-07-24 15:01:44.000000000 +0100 +++ gas/testsuite/gas/mips/mipsel16-e.d 2011-07-24 15:07:52.000000000 +0100 @@ -1,4 +1,4 @@ -#objdump: -rst -mips16 +#objdump: -rst --special-syms -mips16 #name: MIPS16 reloc #as: -32 -mips16 #source: mips16-e.s Index: gas/testsuite/gas/mips/tmipsel16-e.d =================================================================== --- gas/testsuite/gas/mips/tmipsel16-e.d 2011-07-24 15:01:44.000000000 +0100 +++ gas/testsuite/gas/mips/tmipsel16-e.d 2011-07-24 15:07:52.000000000 +0100 @@ -1,4 +1,4 @@ -#objdump: -rst -mips16 +#objdump: -rst --special-syms -mips16 #name: MIPS16 reloc #as: -32 -mips16 #source: mips16-e.s Index: ld/testsuite/ld-mips-elf/mips-elf.exp =================================================================== --- ld/testsuite/ld-mips-elf/mips-elf.exp 2011-07-24 15:05:46.000000000 +0100 +++ ld/testsuite/ld-mips-elf/mips-elf.exp 2011-07-24 15:07:51.000000000 +0100 @@ -129,19 +129,19 @@ run_dump_test "jalx-1" if { $linux_gnu } { run_ld_link_tests [list \ [list "Dummy shared library for JALX test 2" \ - "-shared -nostdlib" \ + "-shared -nostdlib -melf32btsmip" \ "-G0 -EB -mmicromips -no-mdebug -mabi=32 -march=mips32r2 -KPIC" \ { jalx-2-printf.s } \ {} \ "libjalx-2.so"] \ [list "Dummy external function for JALX test 2" \ - "-r" \ + "-r -melf32btsmip" \ "-G0 -EB -no-mdebug -mabi=32 -march=mips32r2 -mno-shared -call_nonpic" \ { jalx-2-ex.s } \ {} \ "jalx-2-ex.o.r"] \ [list "MIPS JALX test 2" \ - "-nostdlib -T jalx-2.ld tmpdir/libjalx-2.so tmpdir/jalx-2-ex.o.r" \ + "-nostdlib -T jalx-2.ld tmpdir/libjalx-2.so tmpdir/jalx-2-ex.o.r -melf32btsmip" \ "-G0 -EB -mmicromips -no-mdebug -mabi=32 -march=mips32r2 -mno-shared -call_nonpic" \ { jalx-2-main.s } \ { { objdump -d jalx-2.dd } } \