1 /* tc-mips.c -- assemble code for a MIPS chip.
2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
4 Free Software Foundation, Inc.
5 Contributed by the OSF and Ralph Campbell.
6 Written by Keith Knowles and Ralph Campbell, working independently.
7 Modified for ECOFF and R4000 support by Ian Lance Taylor of Cygnus
10 This file is part of GAS.
12 GAS is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 3, or (at your option)
17 GAS is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with GAS; see the file COPYING. If not, write to the Free
24 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
30 #include "safe-ctype.h"
32 #include "opcode/mips.h"
34 #include "dwarf2dbg.h"
35 #include "dw2gencfi.h"
38 #define DBG(x) printf x
44 /* Clean up namespace so we can include obj-elf.h too. */
45 static int mips_output_flavor (void);
46 static int mips_output_flavor (void) { return OUTPUT_FLAVOR; }
47 #undef OBJ_PROCESS_STAB
54 #undef obj_frob_file_after_relocs
55 #undef obj_frob_symbol
57 #undef obj_sec_sym_ok_for_reloc
58 #undef OBJ_COPY_SYMBOL_ATTRIBUTES
61 /* Fix any of them that we actually care about. */
63 #define OUTPUT_FLAVOR mips_output_flavor()
70 #ifndef ECOFF_DEBUGGING
71 #define NO_ECOFF_DEBUGGING
72 #define ECOFF_DEBUGGING 0
75 int mips_flag_mdebug = -1;
77 /* Control generation of .pdr sections. Off by default on IRIX: the native
78 linker doesn't know about and discards them, but relocations against them
79 remain, leading to rld crashes. */
81 int mips_flag_pdr = FALSE;
83 int mips_flag_pdr = TRUE;
88 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
89 static char *mips_regmask_frag;
97 #define PIC_CALL_REG 25
105 #define ILLEGAL_REG (32)
107 #define AT mips_opts.at
109 /* Allow override of standard little-endian ECOFF format. */
111 #ifndef ECOFF_LITTLE_FORMAT
112 #define ECOFF_LITTLE_FORMAT "ecoff-littlemips"
115 extern int target_big_endian;
117 /* The name of the readonly data section. */
118 #define RDATA_SECTION_NAME (OUTPUT_FLAVOR == bfd_target_ecoff_flavour \
120 : OUTPUT_FLAVOR == bfd_target_coff_flavour \
122 : OUTPUT_FLAVOR == bfd_target_elf_flavour \
126 /* Ways in which an instruction can be "appended" to the output. */
128 /* Just add it normally. */
131 /* Add it normally and then add a nop. */
134 /* Turn an instruction with a delay slot into a "compact" version. */
137 /* Insert the instruction before the last one. */
141 /* Information about an instruction, including its format, operands
145 /* The opcode's entry in mips_opcodes or mips16_opcodes. */
146 const struct mips_opcode *insn_mo;
148 /* True if this is a mips16 instruction and if we want the extended
150 bfd_boolean use_extend;
152 /* The 16-bit extension instruction to use when USE_EXTEND is true. */
153 unsigned short extend;
155 /* The 16-bit or 32-bit bitstring of the instruction itself. This is
156 a copy of INSN_MO->match with the operands filled in. */
157 unsigned long insn_opcode;
159 /* The frag that contains the instruction. */
162 /* The offset into FRAG of the first instruction byte. */
165 /* The relocs associated with the instruction, if any. */
168 /* True if this entry cannot be moved from its current position. */
169 unsigned int fixed_p : 1;
171 /* True if this instruction occurred in a .set noreorder block. */
172 unsigned int noreorder_p : 1;
174 /* True for mips16 instructions that jump to an absolute address. */
175 unsigned int mips16_absolute_jump_p : 1;
177 /* True if this instruction is complete. */
178 unsigned int complete_p : 1;
181 /* The ABI to use. */
192 /* MIPS ABI we are using for this output file. */
193 static enum mips_abi_level mips_abi = NO_ABI;
195 /* Whether or not we have code that can call pic code. */
196 int mips_abicalls = FALSE;
198 /* Whether or not we have code which can be put into a shared
200 static bfd_boolean mips_in_shared = TRUE;
202 /* This is the set of options which may be modified by the .set
203 pseudo-op. We use a struct so that .set push and .set pop are more
206 struct mips_set_options
208 /* MIPS ISA (Instruction Set Architecture) level. This is set to -1
209 if it has not been initialized. Changed by `.set mipsN', and the
210 -mipsN command line option, and the default CPU. */
212 /* Enabled Application Specific Extensions (ASEs). These are set to -1
213 if they have not been initialized. Changed by `.set <asename>', by
214 command line options, and based on the default architecture. */
222 /* Whether we are assembling for the mips16 processor. 0 if we are
223 not, 1 if we are, and -1 if the value has not been initialized.
224 Changed by `.set mips16' and `.set nomips16', and the -mips16 and
225 -nomips16 command line options, and the default CPU. */
227 /* Whether we are assembling for the mipsMIPS ASE. 0 if we are not,
228 1 if we are, and -1 if the value has not been initialized. Changed
229 by `.set micromips' and `.set nomicromips', and the -mmicromips
230 and -mno-micromips command line options, and the default CPU. */
232 /* Non-zero if we should not reorder instructions. Changed by `.set
233 reorder' and `.set noreorder'. */
235 /* Non-zero if we should not permit the register designated "assembler
236 temporary" to be used in instructions. The value is the register
237 number, normally $at ($1). Changed by `.set at=REG', `.set noat'
238 (same as `.set at=$0') and `.set at' (same as `.set at=$1'). */
240 /* Non-zero if we should warn when a macro instruction expands into
241 more than one machine instruction. Changed by `.set nomacro' and
243 int warn_about_macros;
244 /* Non-zero if we should not move instructions. Changed by `.set
245 move', `.set volatile', `.set nomove', and `.set novolatile'. */
247 /* Non-zero if we should not optimize branches by moving the target
248 of the branch into the delay slot. Actually, we don't perform
249 this optimization anyhow. Changed by `.set bopt' and `.set
252 /* Non-zero if we should not autoextend mips16 instructions.
253 Changed by `.set autoextend' and `.set noautoextend'. */
255 /* Restrict general purpose registers and floating point registers
256 to 32 bit. This is initially determined when -mgp32 or -mfp32
257 is passed but can changed if the assembler code uses .set mipsN. */
260 /* MIPS architecture (CPU) type. Changed by .set arch=FOO, the -march
261 command line option, and the default CPU. */
263 /* True if ".set sym32" is in effect. */
265 /* True if floating-point operations are not allowed. Changed by .set
266 softfloat or .set hardfloat, by command line options -msoft-float or
267 -mhard-float. The default is false. */
268 bfd_boolean soft_float;
270 /* True if only single-precision floating-point operations are allowed.
271 Changed by .set singlefloat or .set doublefloat, command-line options
272 -msingle-float or -mdouble-float. The default is false. */
273 bfd_boolean single_float;
276 /* This is the struct we use to hold the current set of options. Note
277 that we must set the isa field to ISA_UNKNOWN and the ASE fields to
278 -1 to indicate that they have not been initialized. */
280 /* True if -mgp32 was passed. */
281 static int file_mips_gp32 = -1;
283 /* True if -mfp32 was passed. */
284 static int file_mips_fp32 = -1;
286 /* 1 if -msoft-float, 0 if -mhard-float. The default is 0. */
287 static int file_mips_soft_float = 0;
289 /* 1 if -msingle-float, 0 if -mdouble-float. The default is 0. */
290 static int file_mips_single_float = 0;
292 static struct mips_set_options mips_opts =
294 /* isa */ ISA_UNKNOWN, /* ase_mips3d */ -1, /* ase_mdmx */ -1,
295 /* ase_smartmips */ 0, /* ase_dsp */ -1, /* ase_dspr2 */ -1, /* ase_mt */ -1,
296 /* ase_mcu */ -1, /* mips16 */ -1, /* micromips */ -1, /* noreorder */ 0,
297 /* at */ ATREG, /* warn_about_macros */ 0, /* nomove */ 0, /* nobopt */ 0,
298 /* noautoextend */ 0, /* gp32 */ 0, /* fp32 */ 0, /* arch */ CPU_UNKNOWN,
299 /* sym32 */ FALSE, /* soft_float */ FALSE, /* single_float */ FALSE
302 /* These variables are filled in with the masks of registers used.
303 The object format code reads them and puts them in the appropriate
305 unsigned long mips_gprmask;
306 unsigned long mips_cprmask[4];
308 /* MIPS ISA we are using for this output file. */
309 static int file_mips_isa = ISA_UNKNOWN;
311 /* True if any MIPS16 code was produced. */
312 static int file_ase_mips16;
314 #define ISA_SUPPORTS_MIPS16E (mips_opts.isa == ISA_MIPS32 \
315 || mips_opts.isa == ISA_MIPS32R2 \
316 || mips_opts.isa == ISA_MIPS64 \
317 || mips_opts.isa == ISA_MIPS64R2)
319 /* True if any microMIPS code was produced. */
320 static int file_ase_micromips;
322 /* True if we want to create R_MIPS_JALR for jalr $25. */
324 #define MIPS_JALR_HINT_P(EXPR) HAVE_NEWABI
326 /* As a GNU extension, we use R_MIPS_JALR for o32 too. However,
327 because there's no place for any addend, the only acceptable
328 expression is a bare symbol. */
329 #define MIPS_JALR_HINT_P(EXPR) \
330 (!HAVE_IN_PLACE_ADDENDS \
331 || ((EXPR)->X_op == O_symbol && (EXPR)->X_add_number == 0))
334 /* True if -mips3d was passed or implied by arguments passed on the
335 command line (e.g., by -march). */
336 static int file_ase_mips3d;
338 /* True if -mdmx was passed or implied by arguments passed on the
339 command line (e.g., by -march). */
340 static int file_ase_mdmx;
342 /* True if -msmartmips was passed or implied by arguments passed on the
343 command line (e.g., by -march). */
344 static int file_ase_smartmips;
346 #define ISA_SUPPORTS_SMARTMIPS (mips_opts.isa == ISA_MIPS32 \
347 || mips_opts.isa == ISA_MIPS32R2)
349 /* True if -mdsp was passed or implied by arguments passed on the
350 command line (e.g., by -march). */
351 static int file_ase_dsp;
353 #define ISA_SUPPORTS_DSP_ASE (mips_opts.isa == ISA_MIPS32R2 \
354 || mips_opts.isa == ISA_MIPS64R2)
356 #define ISA_SUPPORTS_DSP64_ASE (mips_opts.isa == ISA_MIPS64R2)
358 /* True if -mdspr2 was passed or implied by arguments passed on the
359 command line (e.g., by -march). */
360 static int file_ase_dspr2;
362 #define ISA_SUPPORTS_DSPR2_ASE (mips_opts.isa == ISA_MIPS32R2 \
363 || mips_opts.isa == ISA_MIPS64R2)
365 /* True if -mmt was passed or implied by arguments passed on the
366 command line (e.g., by -march). */
367 static int file_ase_mt;
369 #define ISA_SUPPORTS_MT_ASE (mips_opts.isa == ISA_MIPS32R2 \
370 || mips_opts.isa == ISA_MIPS64R2)
372 #define ISA_SUPPORTS_MCU_ASE (mips_opts.isa == ISA_MIPS32R2 \
373 || mips_opts.isa == ISA_MIPS64R2 \
374 || mips_opts.micromips)
376 /* The argument of the -march= flag. The architecture we are assembling. */
377 static int file_mips_arch = CPU_UNKNOWN;
378 static const char *mips_arch_string;
380 /* The argument of the -mtune= flag. The architecture for which we
382 static int mips_tune = CPU_UNKNOWN;
383 static const char *mips_tune_string;
385 /* True when generating 32-bit code for a 64-bit processor. */
386 static int mips_32bitmode = 0;
388 /* True if the given ABI requires 32-bit registers. */
389 #define ABI_NEEDS_32BIT_REGS(ABI) ((ABI) == O32_ABI)
391 /* Likewise 64-bit registers. */
392 #define ABI_NEEDS_64BIT_REGS(ABI) \
394 || (ABI) == N64_ABI \
397 /* Return true if ISA supports 64 bit wide gp registers. */
398 #define ISA_HAS_64BIT_REGS(ISA) \
399 ((ISA) == ISA_MIPS3 \
400 || (ISA) == ISA_MIPS4 \
401 || (ISA) == ISA_MIPS5 \
402 || (ISA) == ISA_MIPS64 \
403 || (ISA) == ISA_MIPS64R2)
405 /* Return true if ISA supports 64 bit wide float registers. */
406 #define ISA_HAS_64BIT_FPRS(ISA) \
407 ((ISA) == ISA_MIPS3 \
408 || (ISA) == ISA_MIPS4 \
409 || (ISA) == ISA_MIPS5 \
410 || (ISA) == ISA_MIPS32R2 \
411 || (ISA) == ISA_MIPS64 \
412 || (ISA) == ISA_MIPS64R2)
414 /* Return true if ISA supports 64-bit right rotate (dror et al.)
416 #define ISA_HAS_DROR(ISA) \
417 ((ISA) == ISA_MIPS64R2 \
418 || (mips_opts.micromips \
419 && ISA_HAS_64BIT_REGS (ISA)) \
422 /* Return true if ISA supports 32-bit right rotate (ror et al.)
424 #define ISA_HAS_ROR(ISA) \
425 ((ISA) == ISA_MIPS32R2 \
426 || (ISA) == ISA_MIPS64R2 \
427 || mips_opts.ase_smartmips \
428 || mips_opts.micromips \
431 /* Return true if ISA supports single-precision floats in odd registers. */
432 #define ISA_HAS_ODD_SINGLE_FPR(ISA) \
433 ((ISA) == ISA_MIPS32 \
434 || (ISA) == ISA_MIPS32R2 \
435 || (ISA) == ISA_MIPS64 \
436 || (ISA) == ISA_MIPS64R2)
438 /* Return true if ISA supports move to/from high part of a 64-bit
439 floating-point register. */
440 #define ISA_HAS_MXHC1(ISA) \
441 ((ISA) == ISA_MIPS32R2 \
442 || (ISA) == ISA_MIPS64R2)
444 #define HAVE_32BIT_GPRS \
445 (mips_opts.gp32 || !ISA_HAS_64BIT_REGS (mips_opts.isa))
447 #define HAVE_32BIT_FPRS \
448 (mips_opts.fp32 || !ISA_HAS_64BIT_FPRS (mips_opts.isa))
450 #define HAVE_64BIT_GPRS (!HAVE_32BIT_GPRS)
451 #define HAVE_64BIT_FPRS (!HAVE_32BIT_FPRS)
453 #define HAVE_NEWABI (mips_abi == N32_ABI || mips_abi == N64_ABI)
455 #define HAVE_64BIT_OBJECTS (mips_abi == N64_ABI)
457 /* True if relocations are stored in-place. */
458 #define HAVE_IN_PLACE_ADDENDS (!HAVE_NEWABI)
460 /* The ABI-derived address size. */
461 #define HAVE_64BIT_ADDRESSES \
462 (HAVE_64BIT_GPRS && (mips_abi == EABI_ABI || mips_abi == N64_ABI))
463 #define HAVE_32BIT_ADDRESSES (!HAVE_64BIT_ADDRESSES)
465 /* The size of symbolic constants (i.e., expressions of the form
466 "SYMBOL" or "SYMBOL + OFFSET"). */
467 #define HAVE_32BIT_SYMBOLS \
468 (HAVE_32BIT_ADDRESSES || !HAVE_64BIT_OBJECTS || mips_opts.sym32)
469 #define HAVE_64BIT_SYMBOLS (!HAVE_32BIT_SYMBOLS)
471 /* Addresses are loaded in different ways, depending on the address size
472 in use. The n32 ABI Documentation also mandates the use of additions
473 with overflow checking, but existing implementations don't follow it. */
474 #define ADDRESS_ADD_INSN \
475 (HAVE_32BIT_ADDRESSES ? "addu" : "daddu")
477 #define ADDRESS_ADDI_INSN \
478 (HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu")
480 #define ADDRESS_LOAD_INSN \
481 (HAVE_32BIT_ADDRESSES ? "lw" : "ld")
483 #define ADDRESS_STORE_INSN \
484 (HAVE_32BIT_ADDRESSES ? "sw" : "sd")
486 /* Return true if the given CPU supports the MIPS16 ASE. */
487 #define CPU_HAS_MIPS16(cpu) \
488 (strncmp (TARGET_CPU, "mips16", sizeof ("mips16") - 1) == 0 \
489 || strncmp (TARGET_CANONICAL, "mips-lsi-elf", sizeof ("mips-lsi-elf") - 1) == 0)
491 /* Return true if the given CPU supports the microMIPS ASE. */
492 #define CPU_HAS_MICROMIPS(cpu) 0
494 /* True if CPU has a dror instruction. */
495 #define CPU_HAS_DROR(CPU) ((CPU) == CPU_VR5400 || (CPU) == CPU_VR5500)
497 /* True if CPU has a ror instruction. */
498 #define CPU_HAS_ROR(CPU) CPU_HAS_DROR (CPU)
500 /* True if CPU is in the Octeon family */
501 #define CPU_IS_OCTEON(CPU) ((CPU) == CPU_OCTEON || (CPU) == CPU_OCTEONP)
503 /* True if CPU has seq/sne and seqi/snei instructions. */
504 #define CPU_HAS_SEQ(CPU) (CPU_IS_OCTEON (CPU))
506 /* True if CPU does not implement the all the coprocessor insns. For these
507 CPUs only those COP insns are accepted that are explicitly marked to be
508 available on the CPU. ISA membership for COP insns is ignored. */
509 #define NO_ISA_COP(CPU) (CPU_IS_OCTEON (CPU))
511 /* True if mflo and mfhi can be immediately followed by instructions
512 which write to the HI and LO registers.
514 According to MIPS specifications, MIPS ISAs I, II, and III need
515 (at least) two instructions between the reads of HI/LO and
516 instructions which write them, and later ISAs do not. Contradicting
517 the MIPS specifications, some MIPS IV processor user manuals (e.g.
518 the UM for the NEC Vr5000) document needing the instructions between
519 HI/LO reads and writes, as well. Therefore, we declare only MIPS32,
520 MIPS64 and later ISAs to have the interlocks, plus any specific
521 earlier-ISA CPUs for which CPU documentation declares that the
522 instructions are really interlocked. */
523 #define hilo_interlocks \
524 (mips_opts.isa == ISA_MIPS32 \
525 || mips_opts.isa == ISA_MIPS32R2 \
526 || mips_opts.isa == ISA_MIPS64 \
527 || mips_opts.isa == ISA_MIPS64R2 \
528 || mips_opts.arch == CPU_R4010 \
529 || mips_opts.arch == CPU_R10000 \
530 || mips_opts.arch == CPU_R12000 \
531 || mips_opts.arch == CPU_R14000 \
532 || mips_opts.arch == CPU_R16000 \
533 || mips_opts.arch == CPU_RM7000 \
534 || mips_opts.arch == CPU_VR5500 \
535 || mips_opts.micromips \
538 /* Whether the processor uses hardware interlocks to protect reads
539 from the GPRs after they are loaded from memory, and thus does not
540 require nops to be inserted. This applies to instructions marked
541 INSN_LOAD_MEMORY_DELAY. These nops are only required at MIPS ISA
542 level I and microMIPS mode instructions are always interlocked. */
543 #define gpr_interlocks \
544 (mips_opts.isa != ISA_MIPS1 \
545 || mips_opts.arch == CPU_R3900 \
546 || mips_opts.micromips \
549 /* Whether the processor uses hardware interlocks to avoid delays
550 required by coprocessor instructions, and thus does not require
551 nops to be inserted. This applies to instructions marked
552 INSN_LOAD_COPROC_DELAY, INSN_COPROC_MOVE_DELAY, and to delays
553 between instructions marked INSN_WRITE_COND_CODE and ones marked
554 INSN_READ_COND_CODE. These nops are only required at MIPS ISA
555 levels I, II, and III and microMIPS mode instructions are always
557 /* Itbl support may require additional care here. */
558 #define cop_interlocks \
559 ((mips_opts.isa != ISA_MIPS1 \
560 && mips_opts.isa != ISA_MIPS2 \
561 && mips_opts.isa != ISA_MIPS3) \
562 || mips_opts.arch == CPU_R4300 \
563 || mips_opts.micromips \
566 /* Whether the processor uses hardware interlocks to protect reads
567 from coprocessor registers after they are loaded from memory, and
568 thus does not require nops to be inserted. This applies to
569 instructions marked INSN_COPROC_MEMORY_DELAY. These nops are only
570 requires at MIPS ISA level I and microMIPS mode instructions are
571 always interlocked. */
572 #define cop_mem_interlocks \
573 (mips_opts.isa != ISA_MIPS1 \
574 || mips_opts.micromips \
577 /* Is this a mfhi or mflo instruction? */
578 #define MF_HILO_INSN(PINFO) \
579 ((PINFO & INSN_READ_HI) || (PINFO & INSN_READ_LO))
581 /* Returns true for a (non floating-point) coprocessor instruction. Reading
582 or writing the condition code is only possible on the coprocessors and
583 these insns are not marked with INSN_COP. Thus for these insns use the
584 condition-code flags. */
585 #define COP_INSN(PINFO) \
586 (PINFO != INSN_MACRO \
587 && ((PINFO) & (FP_S | FP_D)) == 0 \
588 && ((PINFO) & (INSN_COP | INSN_READ_COND_CODE | INSN_WRITE_COND_CODE)))
590 /* Whether code compression (either of the MIPS16 or the microMIPS ASEs)
591 has been selected. This implies, in particular, that addresses of text
592 labels have their LSB set. */
593 #define HAVE_CODE_COMPRESSION \
594 ((mips_opts.mips16 | mips_opts.micromips) != 0)
596 /* MIPS PIC level. */
598 enum mips_pic_level mips_pic;
600 /* 1 if we should generate 32 bit offsets from the $gp register in
601 SVR4_PIC mode. Currently has no meaning in other modes. */
602 static int mips_big_got = 0;
604 /* 1 if trap instructions should used for overflow rather than break
606 static int mips_trap = 0;
608 /* 1 if double width floating point constants should not be constructed
609 by assembling two single width halves into two single width floating
610 point registers which just happen to alias the double width destination
611 register. On some architectures this aliasing can be disabled by a bit
612 in the status register, and the setting of this bit cannot be determined
613 automatically at assemble time. */
614 static int mips_disable_float_construction;
616 /* Non-zero if any .set noreorder directives were used. */
618 static int mips_any_noreorder;
620 /* Non-zero if nops should be inserted when the register referenced in
621 an mfhi/mflo instruction is read in the next two instructions. */
622 static int mips_7000_hilo_fix;
624 /* The size of objects in the small data section. */
625 static unsigned int g_switch_value = 8;
626 /* Whether the -G option was used. */
627 static int g_switch_seen = 0;
632 /* If we can determine in advance that GP optimization won't be
633 possible, we can skip the relaxation stuff that tries to produce
634 GP-relative references. This makes delay slot optimization work
637 This function can only provide a guess, but it seems to work for
638 gcc output. It needs to guess right for gcc, otherwise gcc
639 will put what it thinks is a GP-relative instruction in a branch
642 I don't know if a fix is needed for the SVR4_PIC mode. I've only
643 fixed it for the non-PIC mode. KR 95/04/07 */
644 static int nopic_need_relax (symbolS *, int);
646 /* handle of the OPCODE hash table */
647 static struct hash_control *op_hash = NULL;
649 /* The opcode hash table we use for the mips16. */
650 static struct hash_control *mips16_op_hash = NULL;
652 /* The opcode hash table we use for the microMIPS ASE. */
653 static struct hash_control *micromips_op_hash = NULL;
655 /* This array holds the chars that always start a comment. If the
656 pre-processor is disabled, these aren't very useful */
657 const char comment_chars[] = "#";
659 /* This array holds the chars that only start a comment at the beginning of
660 a line. If the line seems to have the form '# 123 filename'
661 .line and .file directives will appear in the pre-processed output */
662 /* Note that input_file.c hand checks for '#' at the beginning of the
663 first line of the input file. This is because the compiler outputs
664 #NO_APP at the beginning of its output. */
665 /* Also note that C style comments are always supported. */
666 const char line_comment_chars[] = "#";
668 /* This array holds machine specific line separator characters. */
669 const char line_separator_chars[] = ";";
671 /* Chars that can be used to separate mant from exp in floating point nums */
672 const char EXP_CHARS[] = "eE";
674 /* Chars that mean this number is a floating point constant */
677 const char FLT_CHARS[] = "rRsSfFdDxXpP";
679 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
680 changed in read.c . Ideally it shouldn't have to know about it at all,
681 but nothing is ideal around here.
684 static char *insn_error;
686 static int auto_align = 1;
688 /* When outputting SVR4 PIC code, the assembler needs to know the
689 offset in the stack frame from which to restore the $gp register.
690 This is set by the .cprestore pseudo-op, and saved in this
692 static offsetT mips_cprestore_offset = -1;
694 /* Similar for NewABI PIC code, where $gp is callee-saved. NewABI has some
695 more optimizations, it can use a register value instead of a memory-saved
696 offset and even an other register than $gp as global pointer. */
697 static offsetT mips_cpreturn_offset = -1;
698 static int mips_cpreturn_register = -1;
699 static int mips_gp_register = GP;
700 static int mips_gprel_offset = 0;
702 /* Whether mips_cprestore_offset has been set in the current function
703 (or whether it has already been warned about, if not). */
704 static int mips_cprestore_valid = 0;
706 /* This is the register which holds the stack frame, as set by the
707 .frame pseudo-op. This is needed to implement .cprestore. */
708 static int mips_frame_reg = SP;
710 /* Whether mips_frame_reg has been set in the current function
711 (or whether it has already been warned about, if not). */
712 static int mips_frame_reg_valid = 0;
714 /* To output NOP instructions correctly, we need to keep information
715 about the previous two instructions. */
717 /* Whether we are optimizing. The default value of 2 means to remove
718 unneeded NOPs and swap branch instructions when possible. A value
719 of 1 means to not swap branches. A value of 0 means to always
721 static int mips_optimize = 2;
723 /* Debugging level. -g sets this to 2. -gN sets this to N. -g0 is
724 equivalent to seeing no -g option at all. */
725 static int mips_debug = 0;
727 /* The maximum number of NOPs needed to avoid the VR4130 mflo/mfhi errata. */
728 #define MAX_VR4130_NOPS 4
730 /* The maximum number of NOPs needed to fill delay slots. */
731 #define MAX_DELAY_NOPS 2
733 /* The maximum number of NOPs needed for any purpose. */
736 /* A list of previous instructions, with index 0 being the most recent.
737 We need to look back MAX_NOPS instructions when filling delay slots
738 or working around processor errata. We need to look back one
739 instruction further if we're thinking about using history[0] to
740 fill a branch delay slot. */
741 static struct mips_cl_insn history[1 + MAX_NOPS];
743 /* Nop instructions used by emit_nop. */
744 static struct mips_cl_insn nop_insn;
745 static struct mips_cl_insn mips16_nop_insn;
746 static struct mips_cl_insn micromips_nop16_insn;
747 static struct mips_cl_insn micromips_nop32_insn;
749 /* The appropriate nop for the current mode. */
750 #define NOP_INSN (mips_opts.mips16 ? &mips16_nop_insn \
751 : (mips_opts.micromips ? µmips_nop16_insn : &nop_insn))
753 /* The size of NOP_INSN in bytes. */
754 #define NOP_INSN_SIZE (HAVE_CODE_COMPRESSION ? 2 : 4)
756 /* If this is set, it points to a frag holding nop instructions which
757 were inserted before the start of a noreorder section. If those
758 nops turn out to be unnecessary, the size of the frag can be
760 static fragS *prev_nop_frag;
762 /* The number of nop instructions we created in prev_nop_frag. */
763 static int prev_nop_frag_holds;
765 /* The number of nop instructions that we know we need in
767 static int prev_nop_frag_required;
769 /* The number of instructions we've seen since prev_nop_frag. */
770 static int prev_nop_frag_since;
772 /* For ECOFF and ELF, relocations against symbols are done in two
773 parts, with a HI relocation and a LO relocation. Each relocation
774 has only 16 bits of space to store an addend. This means that in
775 order for the linker to handle carries correctly, it must be able
776 to locate both the HI and the LO relocation. This means that the
777 relocations must appear in order in the relocation table.
779 In order to implement this, we keep track of each unmatched HI
780 relocation. We then sort them so that they immediately precede the
781 corresponding LO relocation. */
786 struct mips_hi_fixup *next;
789 /* The section this fixup is in. */
793 /* The list of unmatched HI relocs. */
795 static struct mips_hi_fixup *mips_hi_fixup_list;
797 /* The frag containing the last explicit relocation operator.
798 Null if explicit relocations have not been used. */
800 static fragS *prev_reloc_op_frag;
802 /* Map normal MIPS register numbers to mips16 register numbers. */
804 #define X ILLEGAL_REG
805 static const int mips32_to_16_reg_map[] =
807 X, X, 2, 3, 4, 5, 6, 7,
808 X, X, X, X, X, X, X, X,
809 0, 1, X, X, X, X, X, X,
810 X, X, X, X, X, X, X, X
814 /* Map mips16 register numbers to normal MIPS register numbers. */
816 static const unsigned int mips16_to_32_reg_map[] =
818 16, 17, 2, 3, 4, 5, 6, 7
821 /* Map normal MIPS register numbers to microMIPS register numbers. */
823 #define mips32_to_micromips_reg_b_map mips32_to_16_reg_map
824 #define mips32_to_micromips_reg_c_map mips32_to_16_reg_map
825 #define mips32_to_micromips_reg_d_map mips32_to_16_reg_map
826 #define mips32_to_micromips_reg_e_map mips32_to_16_reg_map
827 #define mips32_to_micromips_reg_f_map mips32_to_16_reg_map
828 #define mips32_to_micromips_reg_g_map mips32_to_16_reg_map
829 #define mips32_to_micromips_reg_l_map mips32_to_16_reg_map
831 #define X ILLEGAL_REG
832 /* reg type h: 4, 5, 6. */
833 static const int mips32_to_micromips_reg_h_map[] =
835 X, X, X, X, 4, 5, 6, X,
836 X, X, X, X, X, X, X, X,
837 X, X, X, X, X, X, X, X,
838 X, X, X, X, X, X, X, X
841 /* reg type m: 0, 17, 2, 3, 16, 18, 19, 20. */
842 static const int mips32_to_micromips_reg_m_map[] =
844 0, X, 2, 3, X, X, X, X,
845 X, X, X, X, X, X, X, X,
846 4, 1, 5, 6, 7, X, X, X,
847 X, X, X, X, X, X, X, X
850 /* reg type q: 0, 2-7. 17. */
851 static const int mips32_to_micromips_reg_q_map[] =
853 0, X, 2, 3, 4, 5, 6, 7,
854 X, X, X, X, X, X, X, X,
855 X, 1, X, X, X, X, X, X,
856 X, X, X, X, X, X, X, X
859 #define mips32_to_micromips_reg_n_map mips32_to_micromips_reg_m_map
862 /* Map microMIPS register numbers to normal MIPS register numbers. */
864 #define micromips_to_32_reg_b_map mips16_to_32_reg_map
865 #define micromips_to_32_reg_c_map mips16_to_32_reg_map
866 #define micromips_to_32_reg_d_map mips16_to_32_reg_map
867 #define micromips_to_32_reg_e_map mips16_to_32_reg_map
868 #define micromips_to_32_reg_f_map mips16_to_32_reg_map
869 #define micromips_to_32_reg_g_map mips16_to_32_reg_map
871 /* The microMIPS registers with type h. */
872 static const unsigned int micromips_to_32_reg_h_map[] =
874 5, 5, 6, 4, 4, 4, 4, 4
877 /* The microMIPS registers with type i. */
878 static const unsigned int micromips_to_32_reg_i_map[] =
880 6, 7, 7, 21, 22, 5, 6, 7
883 #define micromips_to_32_reg_l_map mips16_to_32_reg_map
885 /* The microMIPS registers with type m. */
886 static const unsigned int micromips_to_32_reg_m_map[] =
888 0, 17, 2, 3, 16, 18, 19, 20
891 #define micromips_to_32_reg_n_map micromips_to_32_reg_m_map
893 /* The microMIPS registers with type q. */
894 static const unsigned int micromips_to_32_reg_q_map[] =
896 0, 17, 2, 3, 4, 5, 6, 7
899 /* microMIPS imm type B. */
900 static const int micromips_imm_b_map[] =
902 1, 4, 8, 12, 16, 20, 24, -1
905 /* microMIPS imm type C. */
906 static const int micromips_imm_c_map[] =
908 128, 1, 2, 3, 4, 7, 8, 15, 16, 31, 32, 63, 64, 255, 32768, 65535
911 /* Classifies the kind of instructions we're interested in when
912 implementing -mfix-vr4120. */
913 enum fix_vr4120_class
921 NUM_FIX_VR4120_CLASSES
924 /* ...likewise -mfix-loongson2f-jump. */
925 static bfd_boolean mips_fix_loongson2f_jump;
927 /* ...likewise -mfix-loongson2f-nop. */
928 static bfd_boolean mips_fix_loongson2f_nop;
930 /* True if -mfix-loongson2f-nop or -mfix-loongson2f-jump passed. */
931 static bfd_boolean mips_fix_loongson2f;
933 /* Given two FIX_VR4120_* values X and Y, bit Y of element X is set if
934 there must be at least one other instruction between an instruction
935 of type X and an instruction of type Y. */
936 static unsigned int vr4120_conflicts[NUM_FIX_VR4120_CLASSES];
938 /* True if -mfix-vr4120 is in force. */
939 static int mips_fix_vr4120;
941 /* ...likewise -mfix-vr4130. */
942 static int mips_fix_vr4130;
944 /* ...likewise -mfix-24k. */
945 static int mips_fix_24k;
947 /* ...likewise -mfix-cn63xxp1 */
948 static bfd_boolean mips_fix_cn63xxp1;
950 /* We don't relax branches by default, since this causes us to expand
951 `la .l2 - .l1' if there's a branch between .l1 and .l2, because we
952 fail to compute the offset before expanding the macro to the most
953 efficient expansion. */
955 static int mips_relax_branch;
957 /* The expansion of many macros depends on the type of symbol that
958 they refer to. For example, when generating position-dependent code,
959 a macro that refers to a symbol may have two different expansions,
960 one which uses GP-relative addresses and one which uses absolute
961 addresses. When generating SVR4-style PIC, a macro may have
962 different expansions for local and global symbols.
964 We handle these situations by generating both sequences and putting
965 them in variant frags. In position-dependent code, the first sequence
966 will be the GP-relative one and the second sequence will be the
967 absolute one. In SVR4 PIC, the first sequence will be for global
968 symbols and the second will be for local symbols.
970 The frag's "subtype" is RELAX_ENCODE (FIRST, SECOND), where FIRST and
971 SECOND are the lengths of the two sequences in bytes. These fields
972 can be extracted using RELAX_FIRST() and RELAX_SECOND(). In addition,
973 the subtype has the following flags:
976 Set if it has been decided that we should use the second
977 sequence instead of the first.
980 Set in the first variant frag if the macro's second implementation
981 is longer than its first. This refers to the macro as a whole,
982 not an individual relaxation.
985 Set in the first variant frag if the macro appeared in a .set nomacro
986 block and if one alternative requires a warning but the other does not.
989 Like RELAX_NOMACRO, but indicates that the macro appears in a branch
992 RELAX_DELAY_SLOT_16BIT
993 Like RELAX_DELAY_SLOT, but indicates that the delay slot requires a
996 RELAX_DELAY_SLOT_SIZE_FIRST
997 Like RELAX_DELAY_SLOT, but indicates that the first implementation of
998 the macro is of the wrong size for the branch delay slot.
1000 RELAX_DELAY_SLOT_SIZE_SECOND
1001 Like RELAX_DELAY_SLOT, but indicates that the second implementation of
1002 the macro is of the wrong size for the branch delay slot.
1004 The frag's "opcode" points to the first fixup for relaxable code.
1006 Relaxable macros are generated using a sequence such as:
1008 relax_start (SYMBOL);
1009 ... generate first expansion ...
1011 ... generate second expansion ...
1014 The code and fixups for the unwanted alternative are discarded
1015 by md_convert_frag. */
1016 #define RELAX_ENCODE(FIRST, SECOND) (((FIRST) << 8) | (SECOND))
1018 #define RELAX_FIRST(X) (((X) >> 8) & 0xff)
1019 #define RELAX_SECOND(X) ((X) & 0xff)
1020 #define RELAX_USE_SECOND 0x10000
1021 #define RELAX_SECOND_LONGER 0x20000
1022 #define RELAX_NOMACRO 0x40000
1023 #define RELAX_DELAY_SLOT 0x80000
1024 #define RELAX_DELAY_SLOT_16BIT 0x100000
1025 #define RELAX_DELAY_SLOT_SIZE_FIRST 0x200000
1026 #define RELAX_DELAY_SLOT_SIZE_SECOND 0x400000
1028 /* Branch without likely bit. If label is out of range, we turn:
1030 beq reg1, reg2, label
1040 with the following opcode replacements:
1047 bltzal <-> bgezal (with jal label instead of j label)
1049 Even though keeping the delay slot instruction in the delay slot of
1050 the branch would be more efficient, it would be very tricky to do
1051 correctly, because we'd have to introduce a variable frag *after*
1052 the delay slot instruction, and expand that instead. Let's do it
1053 the easy way for now, even if the branch-not-taken case now costs
1054 one additional instruction. Out-of-range branches are not supposed
1055 to be common, anyway.
1057 Branch likely. If label is out of range, we turn:
1059 beql reg1, reg2, label
1060 delay slot (annulled if branch not taken)
1069 delay slot (executed only if branch taken)
1072 It would be possible to generate a shorter sequence by losing the
1073 likely bit, generating something like:
1078 delay slot (executed only if branch taken)
1090 bltzall -> bgezal (with jal label instead of j label)
1091 bgezall -> bltzal (ditto)
1094 but it's not clear that it would actually improve performance. */
1095 #define RELAX_BRANCH_ENCODE(at, uncond, likely, link, toofar) \
1096 ((relax_substateT) \
1099 | ((toofar) ? 0x20 : 0) \
1100 | ((link) ? 0x40 : 0) \
1101 | ((likely) ? 0x80 : 0) \
1102 | ((uncond) ? 0x100 : 0)))
1103 #define RELAX_BRANCH_P(i) (((i) & 0xf0000000) == 0xc0000000)
1104 #define RELAX_BRANCH_UNCOND(i) (((i) & 0x100) != 0)
1105 #define RELAX_BRANCH_LIKELY(i) (((i) & 0x80) != 0)
1106 #define RELAX_BRANCH_LINK(i) (((i) & 0x40) != 0)
1107 #define RELAX_BRANCH_TOOFAR(i) (((i) & 0x20) != 0)
1108 #define RELAX_BRANCH_AT(i) ((i) & 0x1f)
1110 /* For mips16 code, we use an entirely different form of relaxation.
1111 mips16 supports two versions of most instructions which take
1112 immediate values: a small one which takes some small value, and a
1113 larger one which takes a 16 bit value. Since branches also follow
1114 this pattern, relaxing these values is required.
1116 We can assemble both mips16 and normal MIPS code in a single
1117 object. Therefore, we need to support this type of relaxation at
1118 the same time that we support the relaxation described above. We
1119 use the high bit of the subtype field to distinguish these cases.
1121 The information we store for this type of relaxation is the
1122 argument code found in the opcode file for this relocation, whether
1123 the user explicitly requested a small or extended form, and whether
1124 the relocation is in a jump or jal delay slot. That tells us the
1125 size of the value, and how it should be stored. We also store
1126 whether the fragment is considered to be extended or not. We also
1127 store whether this is known to be a branch to a different section,
1128 whether we have tried to relax this frag yet, and whether we have
1129 ever extended a PC relative fragment because of a shift count. */
1130 #define RELAX_MIPS16_ENCODE(type, small, ext, dslot, jal_dslot) \
1133 | ((small) ? 0x100 : 0) \
1134 | ((ext) ? 0x200 : 0) \
1135 | ((dslot) ? 0x400 : 0) \
1136 | ((jal_dslot) ? 0x800 : 0))
1137 #define RELAX_MIPS16_P(i) (((i) & 0xc0000000) == 0x80000000)
1138 #define RELAX_MIPS16_TYPE(i) ((i) & 0xff)
1139 #define RELAX_MIPS16_USER_SMALL(i) (((i) & 0x100) != 0)
1140 #define RELAX_MIPS16_USER_EXT(i) (((i) & 0x200) != 0)
1141 #define RELAX_MIPS16_DSLOT(i) (((i) & 0x400) != 0)
1142 #define RELAX_MIPS16_JAL_DSLOT(i) (((i) & 0x800) != 0)
1143 #define RELAX_MIPS16_EXTENDED(i) (((i) & 0x1000) != 0)
1144 #define RELAX_MIPS16_MARK_EXTENDED(i) ((i) | 0x1000)
1145 #define RELAX_MIPS16_CLEAR_EXTENDED(i) ((i) &~ 0x1000)
1146 #define RELAX_MIPS16_LONG_BRANCH(i) (((i) & 0x2000) != 0)
1147 #define RELAX_MIPS16_MARK_LONG_BRANCH(i) ((i) | 0x2000)
1148 #define RELAX_MIPS16_CLEAR_LONG_BRANCH(i) ((i) &~ 0x2000)
1150 /* For microMIPS code, we use relaxation similar to one we use for
1151 MIPS16 code. Some instructions that take immediate values support
1152 two encodings: a small one which takes some small value, and a
1153 larger one which takes a 16 bit value. As some branches also follow
1154 this pattern, relaxing these values is required.
1156 We can assemble both microMIPS and normal MIPS code in a single
1157 object. Therefore, we need to support this type of relaxation at
1158 the same time that we support the relaxation described above. We
1159 use one of the high bits of the subtype field to distinguish these
1162 The information we store for this type of relaxation is the argument
1163 code found in the opcode file for this relocation, the register
1164 selected as the assembler temporary, whether the branch is
1165 unconditional, whether it is compact, whether it stores the link
1166 address implicitly in $ra, whether relaxation of out-of-range 32-bit
1167 branches to a sequence of instructions is enabled, and whether the
1168 displacement of a branch is too large to fit as an immediate argument
1169 of a 16-bit and a 32-bit branch, respectively. */
1170 #define RELAX_MICROMIPS_ENCODE(type, at, uncond, compact, link, \
1171 relax32, toofar16, toofar32) \
1174 | (((at) & 0x1f) << 8) \
1175 | ((uncond) ? 0x2000 : 0) \
1176 | ((compact) ? 0x4000 : 0) \
1177 | ((link) ? 0x8000 : 0) \
1178 | ((relax32) ? 0x10000 : 0) \
1179 | ((toofar16) ? 0x20000 : 0) \
1180 | ((toofar32) ? 0x40000 : 0))
1181 #define RELAX_MICROMIPS_P(i) (((i) & 0xc0000000) == 0x40000000)
1182 #define RELAX_MICROMIPS_TYPE(i) ((i) & 0xff)
1183 #define RELAX_MICROMIPS_AT(i) (((i) >> 8) & 0x1f)
1184 #define RELAX_MICROMIPS_UNCOND(i) (((i) & 0x2000) != 0)
1185 #define RELAX_MICROMIPS_COMPACT(i) (((i) & 0x4000) != 0)
1186 #define RELAX_MICROMIPS_LINK(i) (((i) & 0x8000) != 0)
1187 #define RELAX_MICROMIPS_RELAX32(i) (((i) & 0x10000) != 0)
1189 #define RELAX_MICROMIPS_TOOFAR16(i) (((i) & 0x20000) != 0)
1190 #define RELAX_MICROMIPS_MARK_TOOFAR16(i) ((i) | 0x20000)
1191 #define RELAX_MICROMIPS_CLEAR_TOOFAR16(i) ((i) & ~0x20000)
1192 #define RELAX_MICROMIPS_TOOFAR32(i) (((i) & 0x40000) != 0)
1193 #define RELAX_MICROMIPS_MARK_TOOFAR32(i) ((i) | 0x40000)
1194 #define RELAX_MICROMIPS_CLEAR_TOOFAR32(i) ((i) & ~0x40000)
1196 /* Is the given value a sign-extended 32-bit value? */
1197 #define IS_SEXT_32BIT_NUM(x) \
1198 (((x) &~ (offsetT) 0x7fffffff) == 0 \
1199 || (((x) &~ (offsetT) 0x7fffffff) == ~ (offsetT) 0x7fffffff))
1201 /* Is the given value a sign-extended 16-bit value? */
1202 #define IS_SEXT_16BIT_NUM(x) \
1203 (((x) &~ (offsetT) 0x7fff) == 0 \
1204 || (((x) &~ (offsetT) 0x7fff) == ~ (offsetT) 0x7fff))
1206 /* Is the given value a sign-extended 12-bit value? */
1207 #define IS_SEXT_12BIT_NUM(x) \
1208 (((((x) & 0xfff) ^ 0x800LL) - 0x800LL) == (x))
1210 /* Is the given value a zero-extended 32-bit value? Or a negated one? */
1211 #define IS_ZEXT_32BIT_NUM(x) \
1212 (((x) &~ (offsetT) 0xffffffff) == 0 \
1213 || (((x) &~ (offsetT) 0xffffffff) == ~ (offsetT) 0xffffffff))
1215 /* Replace bits MASK << SHIFT of STRUCT with the equivalent bits in
1216 VALUE << SHIFT. VALUE is evaluated exactly once. */
1217 #define INSERT_BITS(STRUCT, VALUE, MASK, SHIFT) \
1218 (STRUCT) = (((STRUCT) & ~((MASK) << (SHIFT))) \
1219 | (((VALUE) & (MASK)) << (SHIFT)))
1221 /* Extract bits MASK << SHIFT from STRUCT and shift them right
1223 #define EXTRACT_BITS(STRUCT, MASK, SHIFT) \
1224 (((STRUCT) >> (SHIFT)) & (MASK))
1226 /* Change INSN's opcode so that the operand given by FIELD has value VALUE.
1227 INSN is a mips_cl_insn structure and VALUE is evaluated exactly once.
1229 include/opcode/mips.h specifies operand fields using the macros
1230 OP_MASK_<FIELD> and OP_SH_<FIELD>. The MIPS16 equivalents start
1231 with "MIPS16OP" instead of "OP". */
1232 #define INSERT_OPERAND(MICROMIPS, FIELD, INSN, VALUE) \
1235 INSERT_BITS ((INSN).insn_opcode, VALUE, \
1236 OP_MASK_##FIELD, OP_SH_##FIELD); \
1238 INSERT_BITS ((INSN).insn_opcode, VALUE, \
1239 MICROMIPSOP_MASK_##FIELD, MICROMIPSOP_SH_##FIELD); \
1241 #define MIPS16_INSERT_OPERAND(FIELD, INSN, VALUE) \
1242 INSERT_BITS ((INSN).insn_opcode, VALUE, \
1243 MIPS16OP_MASK_##FIELD, MIPS16OP_SH_##FIELD)
1245 /* Extract the operand given by FIELD from mips_cl_insn INSN. */
1246 #define EXTRACT_OPERAND(MICROMIPS, FIELD, INSN) \
1248 ? EXTRACT_BITS ((INSN).insn_opcode, OP_MASK_##FIELD, OP_SH_##FIELD) \
1249 : EXTRACT_BITS ((INSN).insn_opcode, \
1250 MICROMIPSOP_MASK_##FIELD, MICROMIPSOP_SH_##FIELD))
1251 #define MIPS16_EXTRACT_OPERAND(FIELD, INSN) \
1252 EXTRACT_BITS ((INSN).insn_opcode, \
1253 MIPS16OP_MASK_##FIELD, \
1254 MIPS16OP_SH_##FIELD)
1256 /* Whether or not we are emitting a branch-likely macro. */
1257 static bfd_boolean emit_branch_likely_macro = FALSE;
1259 /* Global variables used when generating relaxable macros. See the
1260 comment above RELAX_ENCODE for more details about how relaxation
1263 /* 0 if we're not emitting a relaxable macro.
1264 1 if we're emitting the first of the two relaxation alternatives.
1265 2 if we're emitting the second alternative. */
1268 /* The first relaxable fixup in the current frag. (In other words,
1269 the first fixup that refers to relaxable code.) */
1272 /* sizes[0] says how many bytes of the first alternative are stored in
1273 the current frag. Likewise sizes[1] for the second alternative. */
1274 unsigned int sizes[2];
1276 /* The symbol on which the choice of sequence depends. */
1280 /* Global variables used to decide whether a macro needs a warning. */
1282 /* True if the macro is in a branch delay slot. */
1283 bfd_boolean delay_slot_p;
1285 /* Set to the length in bytes required if the macro is in a delay slot
1286 that requires a specific length of instruction, otherwise zero. */
1287 unsigned int delay_slot_length;
1289 /* For relaxable macros, sizes[0] is the length of the first alternative
1290 in bytes and sizes[1] is the length of the second alternative.
1291 For non-relaxable macros, both elements give the length of the
1293 unsigned int sizes[2];
1295 /* For relaxable macros, first_insn_sizes[0] is the length of the first
1296 instruction of the first alternative in bytes and first_insn_sizes[1]
1297 is the length of the first instruction of the second alternative.
1298 For non-relaxable macros, both elements give the length of the first
1299 instruction in bytes.
1301 Set to zero if we haven't yet seen the first instruction. */
1302 unsigned int first_insn_sizes[2];
1304 /* For relaxable macros, insns[0] is the number of instructions for the
1305 first alternative and insns[1] is the number of instructions for the
1308 For non-relaxable macros, both elements give the number of
1309 instructions for the macro. */
1310 unsigned int insns[2];
1312 /* The first variant frag for this macro. */
1314 } mips_macro_warning;
1316 /* Prototypes for static functions. */
1318 #define internalError() \
1319 as_fatal (_("internal Error, line %d, %s"), __LINE__, __FILE__)
1321 enum mips_regclass { MIPS_GR_REG, MIPS_FP_REG, MIPS16_REG };
1323 static void append_insn
1324 (struct mips_cl_insn *, expressionS *, bfd_reloc_code_real_type *,
1325 bfd_boolean expansionp);
1326 static void mips_no_prev_insn (void);
1327 static void macro_build (expressionS *, const char *, const char *, ...);
1328 static void mips16_macro_build
1329 (expressionS *, const char *, const char *, va_list *);
1330 static void load_register (int, expressionS *, int);
1331 static void macro_start (void);
1332 static void macro_end (void);
1333 static void macro (struct mips_cl_insn * ip);
1334 static void mips16_macro (struct mips_cl_insn * ip);
1335 static void mips_ip (char *str, struct mips_cl_insn * ip);
1336 static void mips16_ip (char *str, struct mips_cl_insn * ip);
1337 static void mips16_immed
1338 (char *, unsigned int, int, offsetT, bfd_boolean, bfd_boolean, bfd_boolean,
1339 unsigned long *, bfd_boolean *, unsigned short *);
1340 static size_t my_getSmallExpression
1341 (expressionS *, bfd_reloc_code_real_type *, char *);
1342 static void my_getExpression (expressionS *, char *);
1343 static void s_align (int);
1344 static void s_change_sec (int);
1345 static void s_change_section (int);
1346 static void s_cons (int);
1347 static void s_float_cons (int);
1348 static void s_mips_globl (int);
1349 static void s_option (int);
1350 static void s_mipsset (int);
1351 static void s_abicalls (int);
1352 static void s_cpload (int);
1353 static void s_cpsetup (int);
1354 static void s_cplocal (int);
1355 static void s_cprestore (int);
1356 static void s_cpreturn (int);
1357 static void s_dtprelword (int);
1358 static void s_dtpreldword (int);
1359 static void s_gpvalue (int);
1360 static void s_gpword (int);
1361 static void s_gpdword (int);
1362 static void s_cpadd (int);
1363 static void s_insn (int);
1364 static void md_obj_begin (void);
1365 static void md_obj_end (void);
1366 static void s_mips_ent (int);
1367 static void s_mips_end (int);
1368 static void s_mips_frame (int);
1369 static void s_mips_mask (int reg_type);
1370 static void s_mips_stab (int);
1371 static void s_mips_weakext (int);
1372 static void s_mips_file (int);
1373 static void s_mips_loc (int);
1374 static bfd_boolean pic_need_relax (symbolS *, asection *);
1375 static int relaxed_branch_length (fragS *, asection *, int);
1376 static int validate_mips_insn (const struct mips_opcode *);
1377 static int validate_micromips_insn (const struct mips_opcode *);
1378 static int relaxed_micromips_16bit_branch_length (fragS *, asection *, int);
1379 static int relaxed_micromips_32bit_branch_length (fragS *, asection *, int);
1381 /* Table and functions used to map between CPU/ISA names, and
1382 ISA levels, and CPU numbers. */
1384 struct mips_cpu_info
1386 const char *name; /* CPU or ISA name. */
1387 int flags; /* ASEs available, or ISA flag. */
1388 int isa; /* ISA level. */
1389 int cpu; /* CPU number (default CPU if ISA). */
1392 #define MIPS_CPU_IS_ISA 0x0001 /* Is this an ISA? (If 0, a CPU.) */
1393 #define MIPS_CPU_ASE_SMARTMIPS 0x0002 /* CPU implements SmartMIPS ASE */
1394 #define MIPS_CPU_ASE_DSP 0x0004 /* CPU implements DSP ASE */
1395 #define MIPS_CPU_ASE_MT 0x0008 /* CPU implements MT ASE */
1396 #define MIPS_CPU_ASE_MIPS3D 0x0010 /* CPU implements MIPS-3D ASE */
1397 #define MIPS_CPU_ASE_MDMX 0x0020 /* CPU implements MDMX ASE */
1398 #define MIPS_CPU_ASE_DSPR2 0x0040 /* CPU implements DSP R2 ASE */
1399 #define MIPS_CPU_ASE_MCU 0x0080 /* CPU implements MCU ASE */
1401 static const struct mips_cpu_info *mips_parse_cpu (const char *, const char *);
1402 static const struct mips_cpu_info *mips_cpu_info_from_isa (int);
1403 static const struct mips_cpu_info *mips_cpu_info_from_arch (int);
1407 The following pseudo-ops from the Kane and Heinrich MIPS book
1408 should be defined here, but are currently unsupported: .alias,
1409 .galive, .gjaldef, .gjrlive, .livereg, .noalias.
1411 The following pseudo-ops from the Kane and Heinrich MIPS book are
1412 specific to the type of debugging information being generated, and
1413 should be defined by the object format: .aent, .begin, .bend,
1414 .bgnb, .end, .endb, .ent, .fmask, .frame, .loc, .mask, .verstamp,
1417 The following pseudo-ops from the Kane and Heinrich MIPS book are
1418 not MIPS CPU specific, but are also not specific to the object file
1419 format. This file is probably the best place to define them, but
1420 they are not currently supported: .asm0, .endr, .lab, .struct. */
1422 static const pseudo_typeS mips_pseudo_table[] =
1424 /* MIPS specific pseudo-ops. */
1425 {"option", s_option, 0},
1426 {"set", s_mipsset, 0},
1427 {"rdata", s_change_sec, 'r'},
1428 {"sdata", s_change_sec, 's'},
1429 {"livereg", s_ignore, 0},
1430 {"abicalls", s_abicalls, 0},
1431 {"cpload", s_cpload, 0},
1432 {"cpsetup", s_cpsetup, 0},
1433 {"cplocal", s_cplocal, 0},
1434 {"cprestore", s_cprestore, 0},
1435 {"cpreturn", s_cpreturn, 0},
1436 {"dtprelword", s_dtprelword, 0},
1437 {"dtpreldword", s_dtpreldword, 0},
1438 {"gpvalue", s_gpvalue, 0},
1439 {"gpword", s_gpword, 0},
1440 {"gpdword", s_gpdword, 0},
1441 {"cpadd", s_cpadd, 0},
1442 {"insn", s_insn, 0},
1444 /* Relatively generic pseudo-ops that happen to be used on MIPS
1446 {"asciiz", stringer, 8 + 1},
1447 {"bss", s_change_sec, 'b'},
1449 {"half", s_cons, 1},
1450 {"dword", s_cons, 3},
1451 {"weakext", s_mips_weakext, 0},
1452 {"origin", s_org, 0},
1453 {"repeat", s_rept, 0},
1455 /* For MIPS this is non-standard, but we define it for consistency. */
1456 {"sbss", s_change_sec, 'B'},
1458 /* These pseudo-ops are defined in read.c, but must be overridden
1459 here for one reason or another. */
1460 {"align", s_align, 0},
1461 {"byte", s_cons, 0},
1462 {"data", s_change_sec, 'd'},
1463 {"double", s_float_cons, 'd'},
1464 {"float", s_float_cons, 'f'},
1465 {"globl", s_mips_globl, 0},
1466 {"global", s_mips_globl, 0},
1467 {"hword", s_cons, 1},
1469 {"long", s_cons, 2},
1470 {"octa", s_cons, 4},
1471 {"quad", s_cons, 3},
1472 {"section", s_change_section, 0},
1473 {"short", s_cons, 1},
1474 {"single", s_float_cons, 'f'},
1475 {"stabn", s_mips_stab, 'n'},
1476 {"text", s_change_sec, 't'},
1477 {"word", s_cons, 2},
1479 { "extern", ecoff_directive_extern, 0},
1484 static const pseudo_typeS mips_nonecoff_pseudo_table[] =
1486 /* These pseudo-ops should be defined by the object file format.
1487 However, a.out doesn't support them, so we have versions here. */
1488 {"aent", s_mips_ent, 1},
1489 {"bgnb", s_ignore, 0},
1490 {"end", s_mips_end, 0},
1491 {"endb", s_ignore, 0},
1492 {"ent", s_mips_ent, 0},
1493 {"file", s_mips_file, 0},
1494 {"fmask", s_mips_mask, 'F'},
1495 {"frame", s_mips_frame, 0},
1496 {"loc", s_mips_loc, 0},
1497 {"mask", s_mips_mask, 'R'},
1498 {"verstamp", s_ignore, 0},
1502 /* Export the ABI address size for use by TC_ADDRESS_BYTES for the
1503 purpose of the `.dc.a' internal pseudo-op. */
1506 mips_address_bytes (void)
1508 return HAVE_64BIT_ADDRESSES ? 8 : 4;
1511 extern void pop_insert (const pseudo_typeS *);
1514 mips_pop_insert (void)
1516 pop_insert (mips_pseudo_table);
1517 if (! ECOFF_DEBUGGING)
1518 pop_insert (mips_nonecoff_pseudo_table);
1521 /* Symbols labelling the current insn. */
1523 struct insn_label_list
1525 struct insn_label_list *next;
1529 static struct insn_label_list *free_insn_labels;
1530 #define label_list tc_segment_info_data.labels
1532 static void mips_clear_insn_labels (void);
1533 static void mips_mark_labels (void);
1534 static void mips_compressed_mark_labels (void);
1537 mips_clear_insn_labels (void)
1539 register struct insn_label_list **pl;
1540 segment_info_type *si;
1544 for (pl = &free_insn_labels; *pl != NULL; pl = &(*pl)->next)
1547 si = seg_info (now_seg);
1548 *pl = si->label_list;
1549 si->label_list = NULL;
1553 /* Mark instruction labels in MIPS16/microMIPS mode. */
1556 mips_mark_labels (void)
1558 if (HAVE_CODE_COMPRESSION)
1559 mips_compressed_mark_labels ();
1562 static char *expr_end;
1564 /* Expressions which appear in instructions. These are set by
1567 static expressionS imm_expr;
1568 static expressionS imm2_expr;
1569 static expressionS offset_expr;
1571 /* Relocs associated with imm_expr and offset_expr. */
1573 static bfd_reloc_code_real_type imm_reloc[3]
1574 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
1575 static bfd_reloc_code_real_type offset_reloc[3]
1576 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
1578 /* This is set to the resulting size of the instruction to be produced
1579 by mips16_ip if an explicit extension is used or by mips_ip if an
1580 explicit size is supplied. */
1582 static unsigned int forced_insn_length;
1585 /* The pdr segment for per procedure frame/regmask info. Not used for
1588 static segT pdr_seg;
1591 /* The default target format to use. */
1593 #if defined (TE_FreeBSD)
1594 #define ELF_TARGET(PREFIX, ENDIAN) PREFIX "trad" ENDIAN "mips-freebsd"
1595 #elif defined (TE_TMIPS)
1596 #define ELF_TARGET(PREFIX, ENDIAN) PREFIX "trad" ENDIAN "mips"
1598 #define ELF_TARGET(PREFIX, ENDIAN) PREFIX ENDIAN "mips"
1602 mips_target_format (void)
1604 switch (OUTPUT_FLAVOR)
1606 case bfd_target_ecoff_flavour:
1607 return target_big_endian ? "ecoff-bigmips" : ECOFF_LITTLE_FORMAT;
1608 case bfd_target_coff_flavour:
1610 case bfd_target_elf_flavour:
1612 if (!HAVE_64BIT_OBJECTS && !HAVE_NEWABI)
1613 return (target_big_endian
1614 ? "elf32-bigmips-vxworks"
1615 : "elf32-littlemips-vxworks");
1617 return (target_big_endian
1618 ? (HAVE_64BIT_OBJECTS
1619 ? ELF_TARGET ("elf64-", "big")
1621 ? ELF_TARGET ("elf32-n", "big")
1622 : ELF_TARGET ("elf32-", "big")))
1623 : (HAVE_64BIT_OBJECTS
1624 ? ELF_TARGET ("elf64-", "little")
1626 ? ELF_TARGET ("elf32-n", "little")
1627 : ELF_TARGET ("elf32-", "little"))));
1634 /* Return the length of a microMIPS instruction in bytes. If bits of
1635 the mask beyond the low 16 are 0, then it is a 16-bit instruction.
1636 Otherwise assume a 32-bit instruction; 48-bit instructions (0x1f
1637 major opcode) will require further modifications to the opcode
1640 static inline unsigned int
1641 micromips_insn_length (const struct mips_opcode *mo)
1643 return (mo->mask >> 16) == 0 ? 2 : 4;
1646 /* Return the length of instruction INSN. */
1648 static inline unsigned int
1649 insn_length (const struct mips_cl_insn *insn)
1651 if (mips_opts.micromips)
1652 return micromips_insn_length (insn->insn_mo);
1653 else if (mips_opts.mips16)
1654 return insn->mips16_absolute_jump_p || insn->use_extend ? 4 : 2;
1659 /* Initialise INSN from opcode entry MO. Leave its position unspecified. */
1662 create_insn (struct mips_cl_insn *insn, const struct mips_opcode *mo)
1667 insn->use_extend = FALSE;
1669 insn->insn_opcode = mo->match;
1672 for (i = 0; i < ARRAY_SIZE (insn->fixp); i++)
1673 insn->fixp[i] = NULL;
1674 insn->fixed_p = (mips_opts.noreorder > 0);
1675 insn->noreorder_p = (mips_opts.noreorder > 0);
1676 insn->mips16_absolute_jump_p = 0;
1677 insn->complete_p = 0;
1680 /* Record the current MIPS16/microMIPS mode in now_seg. */
1683 mips_record_compressed_mode (void)
1685 segment_info_type *si;
1687 si = seg_info (now_seg);
1688 if (si->tc_segment_info_data.mips16 != mips_opts.mips16)
1689 si->tc_segment_info_data.mips16 = mips_opts.mips16;
1690 if (si->tc_segment_info_data.micromips != mips_opts.micromips)
1691 si->tc_segment_info_data.micromips = mips_opts.micromips;
1694 /* Install INSN at the location specified by its "frag" and "where" fields. */
1697 install_insn (const struct mips_cl_insn *insn)
1699 char *f = insn->frag->fr_literal + insn->where;
1700 if (!HAVE_CODE_COMPRESSION)
1701 md_number_to_chars (f, insn->insn_opcode, 4);
1702 else if (mips_opts.micromips)
1704 unsigned int length = insn_length (insn);
1706 md_number_to_chars (f, insn->insn_opcode, 2);
1707 else if (length == 4)
1709 md_number_to_chars (f, insn->insn_opcode >> 16, 2);
1711 md_number_to_chars (f, insn->insn_opcode & 0xffff, 2);
1714 as_bad (_("48-bit microMIPS instructions are not supported"));
1716 else if (insn->mips16_absolute_jump_p)
1718 md_number_to_chars (f, insn->insn_opcode >> 16, 2);
1719 md_number_to_chars (f + 2, insn->insn_opcode & 0xffff, 2);
1723 if (insn->use_extend)
1725 md_number_to_chars (f, 0xf000 | insn->extend, 2);
1728 md_number_to_chars (f, insn->insn_opcode, 2);
1730 mips_record_compressed_mode ();
1733 /* Move INSN to offset WHERE in FRAG. Adjust the fixups accordingly
1734 and install the opcode in the new location. */
1737 move_insn (struct mips_cl_insn *insn, fragS *frag, long where)
1742 insn->where = where;
1743 for (i = 0; i < ARRAY_SIZE (insn->fixp); i++)
1744 if (insn->fixp[i] != NULL)
1746 insn->fixp[i]->fx_frag = frag;
1747 insn->fixp[i]->fx_where = where;
1749 install_insn (insn);
1752 /* Add INSN to the end of the output. */
1755 add_fixed_insn (struct mips_cl_insn *insn)
1757 char *f = frag_more (insn_length (insn));
1758 move_insn (insn, frag_now, f - frag_now->fr_literal);
1761 /* Start a variant frag and move INSN to the start of the variant part,
1762 marking it as fixed. The other arguments are as for frag_var. */
1765 add_relaxed_insn (struct mips_cl_insn *insn, int max_chars, int var,
1766 relax_substateT subtype, symbolS *symbol, offsetT offset)
1768 frag_grow (max_chars);
1769 move_insn (insn, frag_now, frag_more (0) - frag_now->fr_literal);
1771 frag_var (rs_machine_dependent, max_chars, var,
1772 subtype, symbol, offset, NULL);
1775 /* Insert N copies of INSN into the history buffer, starting at
1776 position FIRST. Neither FIRST nor N need to be clipped. */
1779 insert_into_history (unsigned int first, unsigned int n,
1780 const struct mips_cl_insn *insn)
1782 if (mips_relax.sequence != 2)
1786 for (i = ARRAY_SIZE (history); i-- > first;)
1788 history[i] = history[i - n];
1794 /* Initialize vr4120_conflicts. There is a bit of duplication here:
1795 the idea is to make it obvious at a glance that each errata is
1799 init_vr4120_conflicts (void)
1801 #define CONFLICT(FIRST, SECOND) \
1802 vr4120_conflicts[FIX_VR4120_##FIRST] |= 1 << FIX_VR4120_##SECOND
1804 /* Errata 21 - [D]DIV[U] after [D]MACC */
1805 CONFLICT (MACC, DIV);
1806 CONFLICT (DMACC, DIV);
1808 /* Errata 23 - Continuous DMULT[U]/DMACC instructions. */
1809 CONFLICT (DMULT, DMULT);
1810 CONFLICT (DMULT, DMACC);
1811 CONFLICT (DMACC, DMULT);
1812 CONFLICT (DMACC, DMACC);
1814 /* Errata 24 - MT{LO,HI} after [D]MACC */
1815 CONFLICT (MACC, MTHILO);
1816 CONFLICT (DMACC, MTHILO);
1818 /* VR4181A errata MD(1): "If a MULT, MULTU, DMULT or DMULTU
1819 instruction is executed immediately after a MACC or DMACC
1820 instruction, the result of [either instruction] is incorrect." */
1821 CONFLICT (MACC, MULT);
1822 CONFLICT (MACC, DMULT);
1823 CONFLICT (DMACC, MULT);
1824 CONFLICT (DMACC, DMULT);
1826 /* VR4181A errata MD(4): "If a MACC or DMACC instruction is
1827 executed immediately after a DMULT, DMULTU, DIV, DIVU,
1828 DDIV or DDIVU instruction, the result of the MACC or
1829 DMACC instruction is incorrect.". */
1830 CONFLICT (DMULT, MACC);
1831 CONFLICT (DMULT, DMACC);
1832 CONFLICT (DIV, MACC);
1833 CONFLICT (DIV, DMACC);
1843 #define RTYPE_MASK 0x1ff00
1844 #define RTYPE_NUM 0x00100
1845 #define RTYPE_FPU 0x00200
1846 #define RTYPE_FCC 0x00400
1847 #define RTYPE_VEC 0x00800
1848 #define RTYPE_GP 0x01000
1849 #define RTYPE_CP0 0x02000
1850 #define RTYPE_PC 0x04000
1851 #define RTYPE_ACC 0x08000
1852 #define RTYPE_CCC 0x10000
1853 #define RNUM_MASK 0x000ff
1854 #define RWARN 0x80000
1856 #define GENERIC_REGISTER_NUMBERS \
1857 {"$0", RTYPE_NUM | 0}, \
1858 {"$1", RTYPE_NUM | 1}, \
1859 {"$2", RTYPE_NUM | 2}, \
1860 {"$3", RTYPE_NUM | 3}, \
1861 {"$4", RTYPE_NUM | 4}, \
1862 {"$5", RTYPE_NUM | 5}, \
1863 {"$6", RTYPE_NUM | 6}, \
1864 {"$7", RTYPE_NUM | 7}, \
1865 {"$8", RTYPE_NUM | 8}, \
1866 {"$9", RTYPE_NUM | 9}, \
1867 {"$10", RTYPE_NUM | 10}, \
1868 {"$11", RTYPE_NUM | 11}, \
1869 {"$12", RTYPE_NUM | 12}, \
1870 {"$13", RTYPE_NUM | 13}, \
1871 {"$14", RTYPE_NUM | 14}, \
1872 {"$15", RTYPE_NUM | 15}, \
1873 {"$16", RTYPE_NUM | 16}, \
1874 {"$17", RTYPE_NUM | 17}, \
1875 {"$18", RTYPE_NUM | 18}, \
1876 {"$19", RTYPE_NUM | 19}, \
1877 {"$20", RTYPE_NUM | 20}, \
1878 {"$21", RTYPE_NUM | 21}, \
1879 {"$22", RTYPE_NUM | 22}, \
1880 {"$23", RTYPE_NUM | 23}, \
1881 {"$24", RTYPE_NUM | 24}, \
1882 {"$25", RTYPE_NUM | 25}, \
1883 {"$26", RTYPE_NUM | 26}, \
1884 {"$27", RTYPE_NUM | 27}, \
1885 {"$28", RTYPE_NUM | 28}, \
1886 {"$29", RTYPE_NUM | 29}, \
1887 {"$30", RTYPE_NUM | 30}, \
1888 {"$31", RTYPE_NUM | 31}
1890 #define FPU_REGISTER_NAMES \
1891 {"$f0", RTYPE_FPU | 0}, \
1892 {"$f1", RTYPE_FPU | 1}, \
1893 {"$f2", RTYPE_FPU | 2}, \
1894 {"$f3", RTYPE_FPU | 3}, \
1895 {"$f4", RTYPE_FPU | 4}, \
1896 {"$f5", RTYPE_FPU | 5}, \
1897 {"$f6", RTYPE_FPU | 6}, \
1898 {"$f7", RTYPE_FPU | 7}, \
1899 {"$f8", RTYPE_FPU | 8}, \
1900 {"$f9", RTYPE_FPU | 9}, \
1901 {"$f10", RTYPE_FPU | 10}, \
1902 {"$f11", RTYPE_FPU | 11}, \
1903 {"$f12", RTYPE_FPU | 12}, \
1904 {"$f13", RTYPE_FPU | 13}, \
1905 {"$f14", RTYPE_FPU | 14}, \
1906 {"$f15", RTYPE_FPU | 15}, \
1907 {"$f16", RTYPE_FPU | 16}, \
1908 {"$f17", RTYPE_FPU | 17}, \
1909 {"$f18", RTYPE_FPU | 18}, \
1910 {"$f19", RTYPE_FPU | 19}, \
1911 {"$f20", RTYPE_FPU | 20}, \
1912 {"$f21", RTYPE_FPU | 21}, \
1913 {"$f22", RTYPE_FPU | 22}, \
1914 {"$f23", RTYPE_FPU | 23}, \
1915 {"$f24", RTYPE_FPU | 24}, \
1916 {"$f25", RTYPE_FPU | 25}, \
1917 {"$f26", RTYPE_FPU | 26}, \
1918 {"$f27", RTYPE_FPU | 27}, \
1919 {"$f28", RTYPE_FPU | 28}, \
1920 {"$f29", RTYPE_FPU | 29}, \
1921 {"$f30", RTYPE_FPU | 30}, \
1922 {"$f31", RTYPE_FPU | 31}
1924 #define FPU_CONDITION_CODE_NAMES \
1925 {"$fcc0", RTYPE_FCC | 0}, \
1926 {"$fcc1", RTYPE_FCC | 1}, \
1927 {"$fcc2", RTYPE_FCC | 2}, \
1928 {"$fcc3", RTYPE_FCC | 3}, \
1929 {"$fcc4", RTYPE_FCC | 4}, \
1930 {"$fcc5", RTYPE_FCC | 5}, \
1931 {"$fcc6", RTYPE_FCC | 6}, \
1932 {"$fcc7", RTYPE_FCC | 7}
1934 #define COPROC_CONDITION_CODE_NAMES \
1935 {"$cc0", RTYPE_FCC | RTYPE_CCC | 0}, \
1936 {"$cc1", RTYPE_FCC | RTYPE_CCC | 1}, \
1937 {"$cc2", RTYPE_FCC | RTYPE_CCC | 2}, \
1938 {"$cc3", RTYPE_FCC | RTYPE_CCC | 3}, \
1939 {"$cc4", RTYPE_FCC | RTYPE_CCC | 4}, \
1940 {"$cc5", RTYPE_FCC | RTYPE_CCC | 5}, \
1941 {"$cc6", RTYPE_FCC | RTYPE_CCC | 6}, \
1942 {"$cc7", RTYPE_FCC | RTYPE_CCC | 7}
1944 #define N32N64_SYMBOLIC_REGISTER_NAMES \
1945 {"$a4", RTYPE_GP | 8}, \
1946 {"$a5", RTYPE_GP | 9}, \
1947 {"$a6", RTYPE_GP | 10}, \
1948 {"$a7", RTYPE_GP | 11}, \
1949 {"$ta0", RTYPE_GP | 8}, /* alias for $a4 */ \
1950 {"$ta1", RTYPE_GP | 9}, /* alias for $a5 */ \
1951 {"$ta2", RTYPE_GP | 10}, /* alias for $a6 */ \
1952 {"$ta3", RTYPE_GP | 11}, /* alias for $a7 */ \
1953 {"$t0", RTYPE_GP | 12}, \
1954 {"$t1", RTYPE_GP | 13}, \
1955 {"$t2", RTYPE_GP | 14}, \
1956 {"$t3", RTYPE_GP | 15}
1958 #define O32_SYMBOLIC_REGISTER_NAMES \
1959 {"$t0", RTYPE_GP | 8}, \
1960 {"$t1", RTYPE_GP | 9}, \
1961 {"$t2", RTYPE_GP | 10}, \
1962 {"$t3", RTYPE_GP | 11}, \
1963 {"$t4", RTYPE_GP | 12}, \
1964 {"$t5", RTYPE_GP | 13}, \
1965 {"$t6", RTYPE_GP | 14}, \
1966 {"$t7", RTYPE_GP | 15}, \
1967 {"$ta0", RTYPE_GP | 12}, /* alias for $t4 */ \
1968 {"$ta1", RTYPE_GP | 13}, /* alias for $t5 */ \
1969 {"$ta2", RTYPE_GP | 14}, /* alias for $t6 */ \
1970 {"$ta3", RTYPE_GP | 15} /* alias for $t7 */
1972 /* Remaining symbolic register names */
1973 #define SYMBOLIC_REGISTER_NAMES \
1974 {"$zero", RTYPE_GP | 0}, \
1975 {"$at", RTYPE_GP | 1}, \
1976 {"$AT", RTYPE_GP | 1}, \
1977 {"$v0", RTYPE_GP | 2}, \
1978 {"$v1", RTYPE_GP | 3}, \
1979 {"$a0", RTYPE_GP | 4}, \
1980 {"$a1", RTYPE_GP | 5}, \
1981 {"$a2", RTYPE_GP | 6}, \
1982 {"$a3", RTYPE_GP | 7}, \
1983 {"$s0", RTYPE_GP | 16}, \
1984 {"$s1", RTYPE_GP | 17}, \
1985 {"$s2", RTYPE_GP | 18}, \
1986 {"$s3", RTYPE_GP | 19}, \
1987 {"$s4", RTYPE_GP | 20}, \
1988 {"$s5", RTYPE_GP | 21}, \
1989 {"$s6", RTYPE_GP | 22}, \
1990 {"$s7", RTYPE_GP | 23}, \
1991 {"$t8", RTYPE_GP | 24}, \
1992 {"$t9", RTYPE_GP | 25}, \
1993 {"$k0", RTYPE_GP | 26}, \
1994 {"$kt0", RTYPE_GP | 26}, \
1995 {"$k1", RTYPE_GP | 27}, \
1996 {"$kt1", RTYPE_GP | 27}, \
1997 {"$gp", RTYPE_GP | 28}, \
1998 {"$sp", RTYPE_GP | 29}, \
1999 {"$s8", RTYPE_GP | 30}, \
2000 {"$fp", RTYPE_GP | 30}, \
2001 {"$ra", RTYPE_GP | 31}
2003 #define MIPS16_SPECIAL_REGISTER_NAMES \
2004 {"$pc", RTYPE_PC | 0}
2006 #define MDMX_VECTOR_REGISTER_NAMES \
2007 /* {"$v0", RTYPE_VEC | 0}, clash with REG 2 above */ \
2008 /* {"$v1", RTYPE_VEC | 1}, clash with REG 3 above */ \
2009 {"$v2", RTYPE_VEC | 2}, \
2010 {"$v3", RTYPE_VEC | 3}, \
2011 {"$v4", RTYPE_VEC | 4}, \
2012 {"$v5", RTYPE_VEC | 5}, \
2013 {"$v6", RTYPE_VEC | 6}, \
2014 {"$v7", RTYPE_VEC | 7}, \
2015 {"$v8", RTYPE_VEC | 8}, \
2016 {"$v9", RTYPE_VEC | 9}, \
2017 {"$v10", RTYPE_VEC | 10}, \
2018 {"$v11", RTYPE_VEC | 11}, \
2019 {"$v12", RTYPE_VEC | 12}, \
2020 {"$v13", RTYPE_VEC | 13}, \
2021 {"$v14", RTYPE_VEC | 14}, \
2022 {"$v15", RTYPE_VEC | 15}, \
2023 {"$v16", RTYPE_VEC | 16}, \
2024 {"$v17", RTYPE_VEC | 17}, \
2025 {"$v18", RTYPE_VEC | 18}, \
2026 {"$v19", RTYPE_VEC | 19}, \
2027 {"$v20", RTYPE_VEC | 20}, \
2028 {"$v21", RTYPE_VEC | 21}, \
2029 {"$v22", RTYPE_VEC | 22}, \
2030 {"$v23", RTYPE_VEC | 23}, \
2031 {"$v24", RTYPE_VEC | 24}, \
2032 {"$v25", RTYPE_VEC | 25}, \
2033 {"$v26", RTYPE_VEC | 26}, \
2034 {"$v27", RTYPE_VEC | 27}, \
2035 {"$v28", RTYPE_VEC | 28}, \
2036 {"$v29", RTYPE_VEC | 29}, \
2037 {"$v30", RTYPE_VEC | 30}, \
2038 {"$v31", RTYPE_VEC | 31}
2040 #define MIPS_DSP_ACCUMULATOR_NAMES \
2041 {"$ac0", RTYPE_ACC | 0}, \
2042 {"$ac1", RTYPE_ACC | 1}, \
2043 {"$ac2", RTYPE_ACC | 2}, \
2044 {"$ac3", RTYPE_ACC | 3}
2046 static const struct regname reg_names[] = {
2047 GENERIC_REGISTER_NUMBERS,
2049 FPU_CONDITION_CODE_NAMES,
2050 COPROC_CONDITION_CODE_NAMES,
2052 /* The $txx registers depends on the abi,
2053 these will be added later into the symbol table from
2054 one of the tables below once mips_abi is set after
2055 parsing of arguments from the command line. */
2056 SYMBOLIC_REGISTER_NAMES,
2058 MIPS16_SPECIAL_REGISTER_NAMES,
2059 MDMX_VECTOR_REGISTER_NAMES,
2060 MIPS_DSP_ACCUMULATOR_NAMES,
2064 static const struct regname reg_names_o32[] = {
2065 O32_SYMBOLIC_REGISTER_NAMES,
2069 static const struct regname reg_names_n32n64[] = {
2070 N32N64_SYMBOLIC_REGISTER_NAMES,
2074 /* Check if S points at a valid register specifier according to TYPES.
2075 If so, then return 1, advance S to consume the specifier and store
2076 the register's number in REGNOP, otherwise return 0. */
2079 reg_lookup (char **s, unsigned int types, unsigned int *regnop)
2086 /* Find end of name. */
2088 if (is_name_beginner (*e))
2090 while (is_part_of_name (*e))
2093 /* Terminate name. */
2097 /* Look for a register symbol. */
2098 if ((symbolP = symbol_find (*s)) && S_GET_SEGMENT (symbolP) == reg_section)
2100 int r = S_GET_VALUE (symbolP);
2102 reg = r & RNUM_MASK;
2103 else if ((types & RTYPE_VEC) && (r & ~1) == (RTYPE_GP | 2))
2104 /* Convert GP reg $v0/1 to MDMX reg $v0/1! */
2105 reg = (r & RNUM_MASK) - 2;
2107 /* Else see if this is a register defined in an itbl entry. */
2108 else if ((types & RTYPE_GP) && itbl_have_entries)
2115 if (itbl_get_reg_val (n, &r))
2116 reg = r & RNUM_MASK;
2119 /* Advance to next token if a register was recognised. */
2122 else if (types & RWARN)
2123 as_warn (_("Unrecognized register name `%s'"), *s);
2131 /* Check if S points at a valid register list according to TYPES.
2132 If so, then return 1, advance S to consume the list and store
2133 the registers present on the list as a bitmask of ones in REGLISTP,
2134 otherwise return 0. A valid list comprises a comma-separated
2135 enumeration of valid single registers and/or dash-separated
2136 contiguous register ranges as determined by their numbers.
2138 As a special exception if one of s0-s7 registers is specified as
2139 the range's lower delimiter and s8 (fp) is its upper one, then no
2140 registers whose numbers place them between s7 and s8 (i.e. $24-$29)
2141 are selected; they have to be listed separately if needed. */
2144 reglist_lookup (char **s, unsigned int types, unsigned int *reglistp)
2146 unsigned int reglist = 0;
2147 unsigned int lastregno;
2148 bfd_boolean ok = TRUE;
2149 unsigned int regmask;
2150 char *s_endlist = *s;
2154 while (reg_lookup (s, types, ®no))
2160 ok = reg_lookup (s, types, &lastregno);
2161 if (ok && lastregno < regno)
2167 if (lastregno == FP && regno >= S0 && regno <= S7)
2172 regmask = 1 << lastregno;
2173 regmask = (regmask << 1) - 1;
2174 regmask ^= (1 << regno) - 1;
2188 *reglistp = reglist;
2189 return ok && reglist != 0;
2192 /* Return TRUE if opcode MO is valid on the currently selected ISA and
2193 architecture. Use is_opcode_valid_16 for MIPS16 opcodes. */
2196 is_opcode_valid (const struct mips_opcode *mo)
2198 int isa = mips_opts.isa;
2201 if (mips_opts.ase_mdmx)
2203 if (mips_opts.ase_dsp)
2205 if (mips_opts.ase_dsp && ISA_SUPPORTS_DSP64_ASE)
2207 if (mips_opts.ase_dspr2)
2209 if (mips_opts.ase_mt)
2211 if (mips_opts.ase_mips3d)
2213 if (mips_opts.ase_smartmips)
2214 isa |= INSN_SMARTMIPS;
2215 if (mips_opts.ase_mcu)
2218 /* Don't accept instructions based on the ISA if the CPU does not implement
2219 all the coprocessor insns. */
2220 if (NO_ISA_COP (mips_opts.arch)
2221 && COP_INSN (mo->pinfo))
2224 if (!OPCODE_IS_MEMBER (mo, isa, mips_opts.arch))
2227 /* Check whether the instruction or macro requires single-precision or
2228 double-precision floating-point support. Note that this information is
2229 stored differently in the opcode table for insns and macros. */
2230 if (mo->pinfo == INSN_MACRO)
2232 fp_s = mo->pinfo2 & INSN2_M_FP_S;
2233 fp_d = mo->pinfo2 & INSN2_M_FP_D;
2237 fp_s = mo->pinfo & FP_S;
2238 fp_d = mo->pinfo & FP_D;
2241 if (fp_d && (mips_opts.soft_float || mips_opts.single_float))
2244 if (fp_s && mips_opts.soft_float)
2250 /* Return TRUE if the MIPS16 opcode MO is valid on the currently
2251 selected ISA and architecture. */
2254 is_opcode_valid_16 (const struct mips_opcode *mo)
2256 return OPCODE_IS_MEMBER (mo, mips_opts.isa, mips_opts.arch) ? TRUE : FALSE;
2259 /* Return TRUE if the size of the microMIPS opcode MO matches one
2260 explicitly requested. Always TRUE in the standard MIPS mode. */
2263 is_size_valid (const struct mips_opcode *mo)
2265 if (!mips_opts.micromips)
2268 if (!forced_insn_length)
2270 if (mo->pinfo == INSN_MACRO)
2272 return forced_insn_length == micromips_insn_length (mo);
2275 /* Return TRUE if the microMIPS opcode MO is valid for the delay slot
2276 of the preceding instruction. Always TRUE in the standard MIPS mode. */
2279 is_delay_slot_valid (const struct mips_opcode *mo)
2281 if (!mips_opts.micromips)
2284 if (mo->pinfo == INSN_MACRO)
2286 if ((history[0].insn_mo->pinfo2 & INSN2_BRANCH_DELAY_32BIT) != 0
2287 && micromips_insn_length (mo) != 4)
2289 if ((history[0].insn_mo->pinfo2 & INSN2_BRANCH_DELAY_16BIT) != 0
2290 && micromips_insn_length (mo) != 2)
2296 /* This function is called once, at assembler startup time. It should set up
2297 all the tables, etc. that the MD part of the assembler will need. */
2302 const char *retval = NULL;
2306 if (mips_pic != NO_PIC)
2308 if (g_switch_seen && g_switch_value != 0)
2309 as_bad (_("-G may not be used in position-independent code"));
2313 if (! bfd_set_arch_mach (stdoutput, bfd_arch_mips, file_mips_arch))
2314 as_warn (_("Could not set architecture and machine"));
2316 op_hash = hash_new ();
2318 for (i = 0; i < NUMOPCODES;)
2320 const char *name = mips_opcodes[i].name;
2322 retval = hash_insert (op_hash, name, (void *) &mips_opcodes[i]);
2325 fprintf (stderr, _("internal error: can't hash `%s': %s\n"),
2326 mips_opcodes[i].name, retval);
2327 /* Probably a memory allocation problem? Give up now. */
2328 as_fatal (_("Broken assembler. No assembly attempted."));
2332 if (mips_opcodes[i].pinfo != INSN_MACRO)
2334 if (!validate_mips_insn (&mips_opcodes[i]))
2336 if (nop_insn.insn_mo == NULL && strcmp (name, "nop") == 0)
2338 create_insn (&nop_insn, mips_opcodes + i);
2339 if (mips_fix_loongson2f_nop)
2340 nop_insn.insn_opcode = LOONGSON2F_NOP_INSN;
2341 nop_insn.fixed_p = 1;
2346 while ((i < NUMOPCODES) && !strcmp (mips_opcodes[i].name, name));
2349 mips16_op_hash = hash_new ();
2352 while (i < bfd_mips16_num_opcodes)
2354 const char *name = mips16_opcodes[i].name;
2356 retval = hash_insert (mips16_op_hash, name, (void *) &mips16_opcodes[i]);
2358 as_fatal (_("internal: can't hash `%s': %s"),
2359 mips16_opcodes[i].name, retval);
2362 if (mips16_opcodes[i].pinfo != INSN_MACRO
2363 && ((mips16_opcodes[i].match & mips16_opcodes[i].mask)
2364 != mips16_opcodes[i].match))
2366 fprintf (stderr, _("internal error: bad mips16 opcode: %s %s\n"),
2367 mips16_opcodes[i].name, mips16_opcodes[i].args);
2370 if (mips16_nop_insn.insn_mo == NULL && strcmp (name, "nop") == 0)
2372 create_insn (&mips16_nop_insn, mips16_opcodes + i);
2373 mips16_nop_insn.fixed_p = 1;
2377 while (i < bfd_mips16_num_opcodes
2378 && strcmp (mips16_opcodes[i].name, name) == 0);
2381 micromips_op_hash = hash_new ();
2384 while (i < bfd_micromips_num_opcodes)
2386 const char *name = micromips_opcodes[i].name;
2388 retval = hash_insert (micromips_op_hash, name,
2389 (void *) µmips_opcodes[i]);
2391 as_fatal (_("internal: can't hash `%s': %s"),
2392 micromips_opcodes[i].name, retval);
2394 if (micromips_opcodes[i].pinfo != INSN_MACRO)
2396 struct mips_cl_insn *micromips_nop_insn;
2398 if (!validate_micromips_insn (µmips_opcodes[i]))
2401 if (micromips_insn_length (micromips_opcodes + i) == 2)
2402 micromips_nop_insn = µmips_nop16_insn;
2403 else if (micromips_insn_length (micromips_opcodes + i) == 4)
2404 micromips_nop_insn = µmips_nop32_insn;
2408 if (micromips_nop_insn->insn_mo == NULL
2409 && strcmp (name, "nop") == 0)
2411 create_insn (micromips_nop_insn, micromips_opcodes + i);
2412 micromips_nop_insn->fixed_p = 1;
2415 while (++i < bfd_micromips_num_opcodes
2416 && strcmp (micromips_opcodes[i].name, name) == 0);
2420 as_fatal (_("Broken assembler. No assembly attempted."));
2422 /* We add all the general register names to the symbol table. This
2423 helps us detect invalid uses of them. */
2424 for (i = 0; reg_names[i].name; i++)
2425 symbol_table_insert (symbol_new (reg_names[i].name, reg_section,
2426 reg_names[i].num, /* & RNUM_MASK, */
2427 &zero_address_frag));
2429 for (i = 0; reg_names_n32n64[i].name; i++)
2430 symbol_table_insert (symbol_new (reg_names_n32n64[i].name, reg_section,
2431 reg_names_n32n64[i].num, /* & RNUM_MASK, */
2432 &zero_address_frag));
2434 for (i = 0; reg_names_o32[i].name; i++)
2435 symbol_table_insert (symbol_new (reg_names_o32[i].name, reg_section,
2436 reg_names_o32[i].num, /* & RNUM_MASK, */
2437 &zero_address_frag));
2439 mips_no_prev_insn ();
2442 mips_cprmask[0] = 0;
2443 mips_cprmask[1] = 0;
2444 mips_cprmask[2] = 0;
2445 mips_cprmask[3] = 0;
2447 /* set the default alignment for the text section (2**2) */
2448 record_alignment (text_section, 2);
2450 bfd_set_gp_size (stdoutput, g_switch_value);
2455 /* On a native system other than VxWorks, sections must be aligned
2456 to 16 byte boundaries. When configured for an embedded ELF
2457 target, we don't bother. */
2458 if (strncmp (TARGET_OS, "elf", 3) != 0
2459 && strncmp (TARGET_OS, "vxworks", 7) != 0)
2461 (void) bfd_set_section_alignment (stdoutput, text_section, 4);
2462 (void) bfd_set_section_alignment (stdoutput, data_section, 4);
2463 (void) bfd_set_section_alignment (stdoutput, bss_section, 4);
2466 /* Create a .reginfo section for register masks and a .mdebug
2467 section for debugging information. */
2475 subseg = now_subseg;
2477 /* The ABI says this section should be loaded so that the
2478 running program can access it. However, we don't load it
2479 if we are configured for an embedded target */
2480 flags = SEC_READONLY | SEC_DATA;
2481 if (strncmp (TARGET_OS, "elf", 3) != 0)
2482 flags |= SEC_ALLOC | SEC_LOAD;
2484 if (mips_abi != N64_ABI)
2486 sec = subseg_new (".reginfo", (subsegT) 0);
2488 bfd_set_section_flags (stdoutput, sec, flags);
2489 bfd_set_section_alignment (stdoutput, sec, HAVE_NEWABI ? 3 : 2);
2491 mips_regmask_frag = frag_more (sizeof (Elf32_External_RegInfo));
2495 /* The 64-bit ABI uses a .MIPS.options section rather than
2496 .reginfo section. */
2497 sec = subseg_new (".MIPS.options", (subsegT) 0);
2498 bfd_set_section_flags (stdoutput, sec, flags);
2499 bfd_set_section_alignment (stdoutput, sec, 3);
2501 /* Set up the option header. */
2503 Elf_Internal_Options opthdr;
2506 opthdr.kind = ODK_REGINFO;
2507 opthdr.size = (sizeof (Elf_External_Options)
2508 + sizeof (Elf64_External_RegInfo));
2511 f = frag_more (sizeof (Elf_External_Options));
2512 bfd_mips_elf_swap_options_out (stdoutput, &opthdr,
2513 (Elf_External_Options *) f);
2515 mips_regmask_frag = frag_more (sizeof (Elf64_External_RegInfo));
2519 if (ECOFF_DEBUGGING)
2521 sec = subseg_new (".mdebug", (subsegT) 0);
2522 (void) bfd_set_section_flags (stdoutput, sec,
2523 SEC_HAS_CONTENTS | SEC_READONLY);
2524 (void) bfd_set_section_alignment (stdoutput, sec, 2);
2526 else if (mips_flag_pdr)
2528 pdr_seg = subseg_new (".pdr", (subsegT) 0);
2529 (void) bfd_set_section_flags (stdoutput, pdr_seg,
2530 SEC_READONLY | SEC_RELOC
2532 (void) bfd_set_section_alignment (stdoutput, pdr_seg, 2);
2535 subseg_set (seg, subseg);
2538 #endif /* OBJ_ELF */
2540 if (! ECOFF_DEBUGGING)
2543 if (mips_fix_vr4120)
2544 init_vr4120_conflicts ();
2550 mips_emit_delays ();
2551 if (! ECOFF_DEBUGGING)
2556 md_assemble (char *str)
2558 struct mips_cl_insn insn;
2559 bfd_reloc_code_real_type unused_reloc[3]
2560 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
2562 imm_expr.X_op = O_absent;
2563 imm2_expr.X_op = O_absent;
2564 offset_expr.X_op = O_absent;
2565 imm_reloc[0] = BFD_RELOC_UNUSED;
2566 imm_reloc[1] = BFD_RELOC_UNUSED;
2567 imm_reloc[2] = BFD_RELOC_UNUSED;
2568 offset_reloc[0] = BFD_RELOC_UNUSED;
2569 offset_reloc[1] = BFD_RELOC_UNUSED;
2570 offset_reloc[2] = BFD_RELOC_UNUSED;
2572 if (mips_opts.mips16)
2573 mips16_ip (str, &insn);
2576 mips_ip (str, &insn);
2577 DBG ((_("returned from mips_ip(%s) insn_opcode = 0x%x\n"),
2578 str, insn.insn_opcode));
2583 as_bad ("%s `%s'", insn_error, str);
2587 if (insn.insn_mo->pinfo == INSN_MACRO)
2590 if (mips_opts.mips16)
2591 mips16_macro (&insn);
2598 if (imm_expr.X_op != O_absent)
2599 append_insn (&insn, &imm_expr, imm_reloc, FALSE);
2600 else if (offset_expr.X_op != O_absent)
2601 append_insn (&insn, &offset_expr, offset_reloc, FALSE);
2603 append_insn (&insn, NULL, unused_reloc, FALSE);
2607 /* Convenience functions for abstracting away the differences between
2608 MIPS16 and non-MIPS16 relocations. */
2610 static inline bfd_boolean
2611 mips16_reloc_p (bfd_reloc_code_real_type reloc)
2615 case BFD_RELOC_MIPS16_JMP:
2616 case BFD_RELOC_MIPS16_GPREL:
2617 case BFD_RELOC_MIPS16_GOT16:
2618 case BFD_RELOC_MIPS16_CALL16:
2619 case BFD_RELOC_MIPS16_HI16_S:
2620 case BFD_RELOC_MIPS16_HI16:
2621 case BFD_RELOC_MIPS16_LO16:
2629 static inline bfd_boolean
2630 micromips_reloc_p (bfd_reloc_code_real_type reloc)
2634 case BFD_RELOC_MICROMIPS_7_PCREL_S1:
2635 case BFD_RELOC_MICROMIPS_10_PCREL_S1:
2636 case BFD_RELOC_MICROMIPS_16_PCREL_S1:
2637 case BFD_RELOC_MICROMIPS_GPREL16:
2638 case BFD_RELOC_MICROMIPS_JMP:
2639 case BFD_RELOC_MICROMIPS_HI16:
2640 case BFD_RELOC_MICROMIPS_HI16_S:
2641 case BFD_RELOC_MICROMIPS_LO16:
2642 case BFD_RELOC_MICROMIPS_LITERAL:
2643 case BFD_RELOC_MICROMIPS_GOT16:
2644 case BFD_RELOC_MICROMIPS_CALL16:
2645 case BFD_RELOC_MICROMIPS_GOT_HI16:
2646 case BFD_RELOC_MICROMIPS_GOT_LO16:
2647 case BFD_RELOC_MICROMIPS_CALL_HI16:
2648 case BFD_RELOC_MICROMIPS_CALL_LO16:
2649 case BFD_RELOC_MICROMIPS_SUB:
2650 case BFD_RELOC_MICROMIPS_GOT_PAGE:
2651 case BFD_RELOC_MICROMIPS_GOT_OFST:
2652 case BFD_RELOC_MICROMIPS_GOT_DISP:
2653 case BFD_RELOC_MICROMIPS_HIGHEST:
2654 case BFD_RELOC_MICROMIPS_HIGHER:
2655 case BFD_RELOC_MICROMIPS_SCN_DISP:
2656 case BFD_RELOC_MICROMIPS_JALR:
2664 static inline bfd_boolean
2665 jmp_reloc_p (bfd_reloc_code_real_type reloc)
2667 return reloc == BFD_RELOC_MIPS_JMP || reloc == BFD_RELOC_MICROMIPS_JMP;
2670 static inline bfd_boolean
2671 got16_reloc_p (bfd_reloc_code_real_type reloc)
2673 return (reloc == BFD_RELOC_MIPS_GOT16 || reloc == BFD_RELOC_MIPS16_GOT16
2674 || reloc == BFD_RELOC_MICROMIPS_GOT16);
2677 static inline bfd_boolean
2678 hi16_reloc_p (bfd_reloc_code_real_type reloc)
2680 return (reloc == BFD_RELOC_HI16_S || reloc == BFD_RELOC_MIPS16_HI16_S
2681 || reloc == BFD_RELOC_MICROMIPS_HI16_S);
2684 static inline bfd_boolean
2685 lo16_reloc_p (bfd_reloc_code_real_type reloc)
2687 return (reloc == BFD_RELOC_LO16 || reloc == BFD_RELOC_MIPS16_LO16
2688 || reloc == BFD_RELOC_MICROMIPS_LO16);
2691 static inline bfd_boolean
2692 jalr_reloc_p (bfd_reloc_code_real_type reloc)
2694 return reloc == BFD_RELOC_MIPS_JALR || reloc == BFD_RELOC_MICROMIPS_JALR;
2697 /* Return true if the given relocation might need a matching %lo().
2698 This is only "might" because SVR4 R_MIPS_GOT16 relocations only
2699 need a matching %lo() when applied to local symbols. */
2701 static inline bfd_boolean
2702 reloc_needs_lo_p (bfd_reloc_code_real_type reloc)
2704 return (HAVE_IN_PLACE_ADDENDS
2705 && (hi16_reloc_p (reloc)
2706 /* VxWorks R_MIPS_GOT16 relocs never need a matching %lo();
2707 all GOT16 relocations evaluate to "G". */
2708 || (got16_reloc_p (reloc) && mips_pic != VXWORKS_PIC)));
2711 /* Return the type of %lo() reloc needed by RELOC, given that
2712 reloc_needs_lo_p. */
2714 static inline bfd_reloc_code_real_type
2715 matching_lo_reloc (bfd_reloc_code_real_type reloc)
2717 return (mips16_reloc_p (reloc) ? BFD_RELOC_MIPS16_LO16
2718 : (micromips_reloc_p (reloc) ? BFD_RELOC_MICROMIPS_LO16
2722 /* Return true if the given fixup is followed by a matching R_MIPS_LO16
2725 static inline bfd_boolean
2726 fixup_has_matching_lo_p (fixS *fixp)
2728 return (fixp->fx_next != NULL
2729 && fixp->fx_next->fx_r_type == matching_lo_reloc (fixp->fx_r_type)
2730 && fixp->fx_addsy == fixp->fx_next->fx_addsy
2731 && fixp->fx_offset == fixp->fx_next->fx_offset);
2734 /* This function returns true if modifying a register requires a
2738 reg_needs_delay (unsigned int reg)
2740 unsigned long prev_pinfo;
2742 prev_pinfo = history[0].insn_mo->pinfo;
2743 if (! mips_opts.noreorder
2744 && (((prev_pinfo & INSN_LOAD_MEMORY_DELAY)
2745 && ! gpr_interlocks)
2746 || ((prev_pinfo & INSN_LOAD_COPROC_DELAY)
2747 && ! cop_interlocks)))
2749 /* A load from a coprocessor or from memory. All load delays
2750 delay the use of general register rt for one instruction. */
2751 /* Itbl support may require additional care here. */
2752 know (prev_pinfo & INSN_WRITE_GPR_T);
2753 if (reg == EXTRACT_OPERAND (mips_opts.micromips, RT, history[0]))
2760 /* Move all labels in insn_labels to the current insertion point. */
2763 mips_move_labels (void)
2765 segment_info_type *si = seg_info (now_seg);
2766 struct insn_label_list *l;
2769 for (l = si->label_list; l != NULL; l = l->next)
2771 gas_assert (S_GET_SEGMENT (l->label) == now_seg);
2772 symbol_set_frag (l->label, frag_now);
2773 val = (valueT) frag_now_fix ();
2774 /* MIPS16/microMIPS text labels are stored as odd. */
2775 if (HAVE_CODE_COMPRESSION)
2777 S_SET_VALUE (l->label, val);
2782 s_is_linkonce (symbolS *sym, segT from_seg)
2784 bfd_boolean linkonce = FALSE;
2785 segT symseg = S_GET_SEGMENT (sym);
2787 if (symseg != from_seg && !S_IS_LOCAL (sym))
2789 if ((bfd_get_section_flags (stdoutput, symseg) & SEC_LINK_ONCE))
2792 /* The GNU toolchain uses an extension for ELF: a section
2793 beginning with the magic string .gnu.linkonce is a
2794 linkonce section. */
2795 if (strncmp (segment_name (symseg), ".gnu.linkonce",
2796 sizeof ".gnu.linkonce" - 1) == 0)
2803 /* Mark instruction labels in MIPS16/microMIPS mode. This permits the
2804 linker to handle them specially, such as generating jalx instructions
2805 when needed. We also make them odd for the duration of the assembly,
2806 in order to generate the right sort of code. We will make them even
2807 in the adjust_symtab routine, while leaving them marked. This is
2808 convenient for the debugger and the disassembler. The linker knows
2809 to make them odd again. */
2812 mips_compressed_mark_labels (void)
2814 segment_info_type *si = seg_info (now_seg);
2815 struct insn_label_list *l;
2817 gas_assert (HAVE_CODE_COMPRESSION);
2819 for (l = si->label_list; l != NULL; l = l->next)
2821 symbolS *label = l->label;
2823 #if defined(OBJ_ELF) || defined(OBJ_MAYBE_ELF)
2826 if (mips_opts.mips16)
2827 S_SET_OTHER (label, ELF_ST_SET_MIPS16 (S_GET_OTHER (label)));
2829 S_SET_OTHER (label, ELF_ST_SET_MICROMIPS (S_GET_OTHER (label)));
2832 if ((S_GET_VALUE (label) & 1) == 0
2833 /* Don't adjust the address if the label is global or weak, or
2834 in a link-once section, since we'll be emitting symbol reloc
2835 references to it which will be patched up by the linker, and
2836 the final value of the symbol may or may not be MIPS16/microMIPS. */
2837 && ! S_IS_WEAK (label)
2838 && ! S_IS_EXTERNAL (label)
2839 && ! s_is_linkonce (label, now_seg))
2840 S_SET_VALUE (label, S_GET_VALUE (label) | 1);
2844 /* End the current frag. Make it a variant frag and record the
2848 relax_close_frag (void)
2850 mips_macro_warning.first_frag = frag_now;
2851 frag_var (rs_machine_dependent, 0, 0,
2852 RELAX_ENCODE (mips_relax.sizes[0], mips_relax.sizes[1]),
2853 mips_relax.symbol, 0, (char *) mips_relax.first_fixup);
2855 memset (&mips_relax.sizes, 0, sizeof (mips_relax.sizes));
2856 mips_relax.first_fixup = 0;
2859 /* Start a new relaxation sequence whose expansion depends on SYMBOL.
2860 See the comment above RELAX_ENCODE for more details. */
2863 relax_start (symbolS *symbol)
2865 gas_assert (mips_relax.sequence == 0);
2866 mips_relax.sequence = 1;
2867 mips_relax.symbol = symbol;
2870 /* Start generating the second version of a relaxable sequence.
2871 See the comment above RELAX_ENCODE for more details. */
2876 gas_assert (mips_relax.sequence == 1);
2877 mips_relax.sequence = 2;
2880 /* End the current relaxable sequence. */
2885 gas_assert (mips_relax.sequence == 2);
2886 relax_close_frag ();
2887 mips_relax.sequence = 0;
2890 /* Return true if IP is a delayed branch or jump. */
2892 static inline bfd_boolean
2893 delayed_branch_p (const struct mips_cl_insn *ip)
2895 return (ip->insn_mo->pinfo & (INSN_UNCOND_BRANCH_DELAY
2896 | INSN_COND_BRANCH_DELAY
2897 | INSN_COND_BRANCH_LIKELY)) != 0;
2900 /* Return true if IP is a compact branch or jump. */
2902 static inline bfd_boolean
2903 compact_branch_p (const struct mips_cl_insn *ip)
2905 if (mips_opts.mips16)
2906 return (ip->insn_mo->pinfo & (MIPS16_INSN_UNCOND_BRANCH
2907 | MIPS16_INSN_COND_BRANCH)) != 0;
2909 return (ip->insn_mo->pinfo2 & (INSN2_UNCOND_BRANCH
2910 | INSN2_COND_BRANCH)) != 0;
2913 /* Return true if IP is an unconditional branch or jump. */
2915 static inline bfd_boolean
2916 uncond_branch_p (const struct mips_cl_insn *ip)
2918 return ((ip->insn_mo->pinfo & INSN_UNCOND_BRANCH_DELAY) != 0
2919 || (mips_opts.mips16
2920 ? (ip->insn_mo->pinfo & MIPS16_INSN_UNCOND_BRANCH) != 0
2921 : (ip->insn_mo->pinfo2 & INSN2_UNCOND_BRANCH) != 0));
2924 /* Return true if IP is a branch-likely instruction. */
2926 static inline bfd_boolean
2927 branch_likely_p (const struct mips_cl_insn *ip)
2929 return (ip->insn_mo->pinfo & INSN_COND_BRANCH_LIKELY) != 0;
2932 /* Return the type of nop that should be used to fill the delay slot
2933 of delayed branch IP. */
2935 static struct mips_cl_insn *
2936 get_delay_slot_nop (const struct mips_cl_insn *ip)
2938 if (mips_opts.micromips
2939 && (ip->insn_mo->pinfo2 & INSN2_BRANCH_DELAY_32BIT))
2940 return µmips_nop32_insn;
2944 /* Return the mask of core registers that IP reads or writes. */
2947 gpr_mod_mask (const struct mips_cl_insn *ip)
2949 unsigned long pinfo2;
2953 pinfo2 = ip->insn_mo->pinfo2;
2954 if (mips_opts.micromips)
2956 if (pinfo2 & INSN2_MOD_GPR_MD)
2957 mask |= 1 << micromips_to_32_reg_d_map[EXTRACT_OPERAND (1, MD, *ip)];
2958 if (pinfo2 & INSN2_MOD_GPR_MF)
2959 mask |= 1 << micromips_to_32_reg_f_map[EXTRACT_OPERAND (1, MF, *ip)];
2960 if (pinfo2 & INSN2_MOD_SP)
2966 /* Return the mask of core registers that IP reads. */
2969 gpr_read_mask (const struct mips_cl_insn *ip)
2971 unsigned long pinfo, pinfo2;
2974 mask = gpr_mod_mask (ip);
2975 pinfo = ip->insn_mo->pinfo;
2976 pinfo2 = ip->insn_mo->pinfo2;
2977 if (mips_opts.mips16)
2979 if (pinfo & MIPS16_INSN_READ_X)
2980 mask |= 1 << mips16_to_32_reg_map[MIPS16_EXTRACT_OPERAND (RX, *ip)];
2981 if (pinfo & MIPS16_INSN_READ_Y)
2982 mask |= 1 << mips16_to_32_reg_map[MIPS16_EXTRACT_OPERAND (RY, *ip)];
2983 if (pinfo & MIPS16_INSN_READ_T)
2985 if (pinfo & MIPS16_INSN_READ_SP)
2987 if (pinfo & MIPS16_INSN_READ_31)
2989 if (pinfo & MIPS16_INSN_READ_Z)
2990 mask |= 1 << (mips16_to_32_reg_map
2991 [MIPS16_EXTRACT_OPERAND (MOVE32Z, *ip)]);
2992 if (pinfo & MIPS16_INSN_READ_GPR_X)
2993 mask |= 1 << MIPS16_EXTRACT_OPERAND (REGR32, *ip);
2997 if (pinfo2 & INSN2_READ_GPR_D)
2998 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RD, *ip);
2999 if (pinfo & INSN_READ_GPR_T)
3000 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RT, *ip);
3001 if (pinfo & INSN_READ_GPR_S)
3002 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RS, *ip);
3003 if (pinfo2 & INSN2_READ_GP)
3005 if (pinfo2 & INSN2_READ_GPR_31)
3007 if (pinfo2 & INSN2_READ_GPR_Z)
3008 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RZ, *ip);
3010 if (mips_opts.micromips)
3012 if (pinfo2 & INSN2_READ_GPR_MC)
3013 mask |= 1 << micromips_to_32_reg_c_map[EXTRACT_OPERAND (1, MC, *ip)];
3014 if (pinfo2 & INSN2_READ_GPR_ME)
3015 mask |= 1 << micromips_to_32_reg_e_map[EXTRACT_OPERAND (1, ME, *ip)];
3016 if (pinfo2 & INSN2_READ_GPR_MG)
3017 mask |= 1 << micromips_to_32_reg_g_map[EXTRACT_OPERAND (1, MG, *ip)];
3018 if (pinfo2 & INSN2_READ_GPR_MJ)
3019 mask |= 1 << EXTRACT_OPERAND (1, MJ, *ip);
3020 if (pinfo2 & INSN2_READ_GPR_MMN)
3022 mask |= 1 << micromips_to_32_reg_m_map[EXTRACT_OPERAND (1, MM, *ip)];
3023 mask |= 1 << micromips_to_32_reg_n_map[EXTRACT_OPERAND (1, MN, *ip)];
3025 if (pinfo2 & INSN2_READ_GPR_MP)
3026 mask |= 1 << EXTRACT_OPERAND (1, MP, *ip);
3027 if (pinfo2 & INSN2_READ_GPR_MQ)
3028 mask |= 1 << micromips_to_32_reg_q_map[EXTRACT_OPERAND (1, MQ, *ip)];
3030 /* Don't include register 0. */
3034 /* Return the mask of core registers that IP writes. */
3037 gpr_write_mask (const struct mips_cl_insn *ip)
3039 unsigned long pinfo, pinfo2;
3042 mask = gpr_mod_mask (ip);
3043 pinfo = ip->insn_mo->pinfo;
3044 pinfo2 = ip->insn_mo->pinfo2;
3045 if (mips_opts.mips16)
3047 if (pinfo & MIPS16_INSN_WRITE_X)
3048 mask |= 1 << mips16_to_32_reg_map[MIPS16_EXTRACT_OPERAND (RX, *ip)];
3049 if (pinfo & MIPS16_INSN_WRITE_Y)
3050 mask |= 1 << mips16_to_32_reg_map[MIPS16_EXTRACT_OPERAND (RY, *ip)];
3051 if (pinfo & MIPS16_INSN_WRITE_Z)
3052 mask |= 1 << mips16_to_32_reg_map[MIPS16_EXTRACT_OPERAND (RZ, *ip)];
3053 if (pinfo & MIPS16_INSN_WRITE_T)
3055 if (pinfo & MIPS16_INSN_WRITE_SP)
3057 if (pinfo & MIPS16_INSN_WRITE_31)
3059 if (pinfo & MIPS16_INSN_WRITE_GPR_Y)
3060 mask |= 1 << MIPS16OP_EXTRACT_REG32R (ip->insn_opcode);
3064 if (pinfo & INSN_WRITE_GPR_D)
3065 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RD, *ip);
3066 if (pinfo & INSN_WRITE_GPR_T)
3067 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RT, *ip);
3068 if (pinfo & INSN_WRITE_GPR_S)
3069 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RS, *ip);
3070 if (pinfo & INSN_WRITE_GPR_31)
3072 if (pinfo2 & INSN2_WRITE_GPR_Z)
3073 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RZ, *ip);
3075 if (mips_opts.micromips)
3077 if (pinfo2 & INSN2_WRITE_GPR_MB)
3078 mask |= 1 << micromips_to_32_reg_b_map[EXTRACT_OPERAND (1, MB, *ip)];
3079 if (pinfo2 & INSN2_WRITE_GPR_MHI)
3081 mask |= 1 << micromips_to_32_reg_h_map[EXTRACT_OPERAND (1, MH, *ip)];
3082 mask |= 1 << micromips_to_32_reg_i_map[EXTRACT_OPERAND (1, MI, *ip)];
3084 if (pinfo2 & INSN2_WRITE_GPR_MJ)
3085 mask |= 1 << EXTRACT_OPERAND (1, MJ, *ip);
3086 if (pinfo2 & INSN2_WRITE_GPR_MP)
3087 mask |= 1 << EXTRACT_OPERAND (1, MP, *ip);
3089 /* Don't include register 0. */
3093 /* Return the mask of floating-point registers that IP reads. */
3096 fpr_read_mask (const struct mips_cl_insn *ip)
3098 unsigned long pinfo, pinfo2;
3102 pinfo = ip->insn_mo->pinfo;
3103 pinfo2 = ip->insn_mo->pinfo2;
3104 if (!mips_opts.mips16)
3106 if (pinfo2 & INSN2_READ_FPR_D)
3107 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FD, *ip);
3108 if (pinfo & INSN_READ_FPR_S)
3109 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FS, *ip);
3110 if (pinfo & INSN_READ_FPR_T)
3111 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FT, *ip);
3112 if (pinfo & INSN_READ_FPR_R)
3113 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FR, *ip);
3114 if (pinfo2 & INSN2_READ_FPR_Z)
3115 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FZ, *ip);
3117 /* Conservatively treat all operands to an FP_D instruction are doubles.
3118 (This is overly pessimistic for things like cvt.d.s.) */
3119 if (HAVE_32BIT_FPRS && (pinfo & FP_D))
3124 /* Return the mask of floating-point registers that IP writes. */
3127 fpr_write_mask (const struct mips_cl_insn *ip)
3129 unsigned long pinfo, pinfo2;
3133 pinfo = ip->insn_mo->pinfo;
3134 pinfo2 = ip->insn_mo->pinfo2;
3135 if (!mips_opts.mips16)
3137 if (pinfo & INSN_WRITE_FPR_D)
3138 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FD, *ip);
3139 if (pinfo & INSN_WRITE_FPR_S)
3140 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FS, *ip);
3141 if (pinfo & INSN_WRITE_FPR_T)
3142 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FT, *ip);
3143 if (pinfo2 & INSN2_WRITE_FPR_Z)
3144 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FZ, *ip);
3146 /* Conservatively treat all operands to an FP_D instruction are doubles.
3147 (This is overly pessimistic for things like cvt.s.d.) */
3148 if (HAVE_32BIT_FPRS && (pinfo & FP_D))
3153 /* Classify an instruction according to the FIX_VR4120_* enumeration.
3154 Return NUM_FIX_VR4120_CLASSES if the instruction isn't affected
3155 by VR4120 errata. */
3158 classify_vr4120_insn (const char *name)
3160 if (strncmp (name, "macc", 4) == 0)
3161 return FIX_VR4120_MACC;
3162 if (strncmp (name, "dmacc", 5) == 0)
3163 return FIX_VR4120_DMACC;
3164 if (strncmp (name, "mult", 4) == 0)
3165 return FIX_VR4120_MULT;
3166 if (strncmp (name, "dmult", 5) == 0)
3167 return FIX_VR4120_DMULT;
3168 if (strstr (name, "div"))
3169 return FIX_VR4120_DIV;
3170 if (strcmp (name, "mtlo") == 0 || strcmp (name, "mthi") == 0)
3171 return FIX_VR4120_MTHILO;
3172 return NUM_FIX_VR4120_CLASSES;
3175 #define INSN_ERET 0x42000018
3176 #define INSN_DERET 0x4200001f
3178 /* Return the number of instructions that must separate INSN1 and INSN2,
3179 where INSN1 is the earlier instruction. Return the worst-case value
3180 for any INSN2 if INSN2 is null. */
3183 insns_between (const struct mips_cl_insn *insn1,
3184 const struct mips_cl_insn *insn2)
3186 unsigned long pinfo1, pinfo2;
3189 /* This function needs to know which pinfo flags are set for INSN2
3190 and which registers INSN2 uses. The former is stored in PINFO2 and
3191 the latter is tested via INSN2_USES_GPR. If INSN2 is null, PINFO2
3192 will have every flag set and INSN2_USES_GPR will always return true. */
3193 pinfo1 = insn1->insn_mo->pinfo;
3194 pinfo2 = insn2 ? insn2->insn_mo->pinfo : ~0U;
3196 #define INSN2_USES_GPR(REG) \
3197 (insn2 == NULL || (gpr_read_mask (insn2) & (1U << (REG))) != 0)
3199 /* For most targets, write-after-read dependencies on the HI and LO
3200 registers must be separated by at least two instructions. */
3201 if (!hilo_interlocks)
3203 if ((pinfo1 & INSN_READ_LO) && (pinfo2 & INSN_WRITE_LO))
3205 if ((pinfo1 & INSN_READ_HI) && (pinfo2 & INSN_WRITE_HI))
3209 /* If we're working around r7000 errata, there must be two instructions
3210 between an mfhi or mflo and any instruction that uses the result. */
3211 if (mips_7000_hilo_fix
3212 && !mips_opts.micromips
3213 && MF_HILO_INSN (pinfo1)
3214 && INSN2_USES_GPR (EXTRACT_OPERAND (0, RD, *insn1)))
3217 /* If we're working around 24K errata, one instruction is required
3218 if an ERET or DERET is followed by a branch instruction. */
3219 if (mips_fix_24k && !mips_opts.micromips)
3221 if (insn1->insn_opcode == INSN_ERET
3222 || insn1->insn_opcode == INSN_DERET)
3225 || insn2->insn_opcode == INSN_ERET
3226 || insn2->insn_opcode == INSN_DERET
3227 || delayed_branch_p (insn2))
3232 /* If working around VR4120 errata, check for combinations that need
3233 a single intervening instruction. */
3234 if (mips_fix_vr4120 && !mips_opts.micromips)
3236 unsigned int class1, class2;
3238 class1 = classify_vr4120_insn (insn1->insn_mo->name);
3239 if (class1 != NUM_FIX_VR4120_CLASSES && vr4120_conflicts[class1] != 0)
3243 class2 = classify_vr4120_insn (insn2->insn_mo->name);
3244 if (vr4120_conflicts[class1] & (1 << class2))
3249 if (!HAVE_CODE_COMPRESSION)
3251 /* Check for GPR or coprocessor load delays. All such delays
3252 are on the RT register. */
3253 /* Itbl support may require additional care here. */
3254 if ((!gpr_interlocks && (pinfo1 & INSN_LOAD_MEMORY_DELAY))
3255 || (!cop_interlocks && (pinfo1 & INSN_LOAD_COPROC_DELAY)))
3257 know (pinfo1 & INSN_WRITE_GPR_T);
3258 if (INSN2_USES_GPR (EXTRACT_OPERAND (0, RT, *insn1)))
3262 /* Check for generic coprocessor hazards.
3264 This case is not handled very well. There is no special
3265 knowledge of CP0 handling, and the coprocessors other than
3266 the floating point unit are not distinguished at all. */
3267 /* Itbl support may require additional care here. FIXME!
3268 Need to modify this to include knowledge about
3269 user specified delays! */
3270 else if ((!cop_interlocks && (pinfo1 & INSN_COPROC_MOVE_DELAY))
3271 || (!cop_mem_interlocks && (pinfo1 & INSN_COPROC_MEMORY_DELAY)))
3273 /* Handle cases where INSN1 writes to a known general coprocessor
3274 register. There must be a one instruction delay before INSN2
3275 if INSN2 reads that register, otherwise no delay is needed. */
3276 mask = fpr_write_mask (insn1);
3279 if (!insn2 || (mask & fpr_read_mask (insn2)) != 0)
3284 /* Read-after-write dependencies on the control registers
3285 require a two-instruction gap. */
3286 if ((pinfo1 & INSN_WRITE_COND_CODE)
3287 && (pinfo2 & INSN_READ_COND_CODE))
3290 /* We don't know exactly what INSN1 does. If INSN2 is
3291 also a coprocessor instruction, assume there must be
3292 a one instruction gap. */
3293 if (pinfo2 & INSN_COP)
3298 /* Check for read-after-write dependencies on the coprocessor
3299 control registers in cases where INSN1 does not need a general
3300 coprocessor delay. This means that INSN1 is a floating point
3301 comparison instruction. */
3302 /* Itbl support may require additional care here. */
3303 else if (!cop_interlocks
3304 && (pinfo1 & INSN_WRITE_COND_CODE)
3305 && (pinfo2 & INSN_READ_COND_CODE))
3309 #undef INSN2_USES_GPR
3314 /* Return the number of nops that would be needed to work around the
3315 VR4130 mflo/mfhi errata if instruction INSN immediately followed
3316 the MAX_VR4130_NOPS instructions described by HIST. Ignore hazards
3317 that are contained within the first IGNORE instructions of HIST. */
3320 nops_for_vr4130 (int ignore, const struct mips_cl_insn *hist,
3321 const struct mips_cl_insn *insn)
3326 /* Check if the instruction writes to HI or LO. MTHI and MTLO
3327 are not affected by the errata. */
3329 && ((insn->insn_mo->pinfo & (INSN_WRITE_HI | INSN_WRITE_LO)) == 0
3330 || strcmp (insn->insn_mo->name, "mtlo") == 0
3331 || strcmp (insn->insn_mo->name, "mthi") == 0))
3334 /* Search for the first MFLO or MFHI. */
3335 for (i = 0; i < MAX_VR4130_NOPS; i++)
3336 if (MF_HILO_INSN (hist[i].insn_mo->pinfo))
3338 /* Extract the destination register. */
3339 mask = gpr_write_mask (&hist[i]);
3341 /* No nops are needed if INSN reads that register. */
3342 if (insn != NULL && (gpr_read_mask (insn) & mask) != 0)
3345 /* ...or if any of the intervening instructions do. */
3346 for (j = 0; j < i; j++)
3347 if (gpr_read_mask (&hist[j]) & mask)
3351 return MAX_VR4130_NOPS - i;
3356 #define BASE_REG_EQ(INSN1, INSN2) \
3357 ((((INSN1) >> OP_SH_RS) & OP_MASK_RS) \
3358 == (((INSN2) >> OP_SH_RS) & OP_MASK_RS))
3360 /* Return the minimum alignment for this store instruction. */
3363 fix_24k_align_to (const struct mips_opcode *mo)
3365 if (strcmp (mo->name, "sh") == 0)
3368 if (strcmp (mo->name, "swc1") == 0
3369 || strcmp (mo->name, "swc2") == 0
3370 || strcmp (mo->name, "sw") == 0
3371 || strcmp (mo->name, "sc") == 0
3372 || strcmp (mo->name, "s.s") == 0)
3375 if (strcmp (mo->name, "sdc1") == 0
3376 || strcmp (mo->name, "sdc2") == 0
3377 || strcmp (mo->name, "s.d") == 0)
3384 struct fix_24k_store_info
3386 /* Immediate offset, if any, for this store instruction. */
3388 /* Alignment required by this store instruction. */
3390 /* True for register offsets. */
3391 int register_offset;
3394 /* Comparison function used by qsort. */
3397 fix_24k_sort (const void *a, const void *b)
3399 const struct fix_24k_store_info *pos1 = a;
3400 const struct fix_24k_store_info *pos2 = b;
3402 return (pos1->off - pos2->off);
3405 /* INSN is a store instruction. Try to record the store information
3406 in STINFO. Return false if the information isn't known. */
3409 fix_24k_record_store_info (struct fix_24k_store_info *stinfo,
3410 const struct mips_cl_insn *insn)
3412 /* The instruction must have a known offset. */
3413 if (!insn->complete_p || !strstr (insn->insn_mo->args, "o("))
3416 stinfo->off = (insn->insn_opcode >> OP_SH_IMMEDIATE) & OP_MASK_IMMEDIATE;
3417 stinfo->align_to = fix_24k_align_to (insn->insn_mo);
3421 /* Return the number of nops that would be needed to work around the 24k
3422 "lost data on stores during refill" errata if instruction INSN
3423 immediately followed the 2 instructions described by HIST.
3424 Ignore hazards that are contained within the first IGNORE
3425 instructions of HIST.
3427 Problem: The FSB (fetch store buffer) acts as an intermediate buffer
3428 for the data cache refills and store data. The following describes
3429 the scenario where the store data could be lost.
3431 * A data cache miss, due to either a load or a store, causing fill
3432 data to be supplied by the memory subsystem
3433 * The first three doublewords of fill data are returned and written
3435 * A sequence of four stores occurs in consecutive cycles around the
3436 final doubleword of the fill:
3440 * Zero, One or more instructions
3443 The four stores A-D must be to different doublewords of the line that
3444 is being filled. The fourth instruction in the sequence above permits
3445 the fill of the final doubleword to be transferred from the FSB into
3446 the cache. In the sequence above, the stores may be either integer
3447 (sb, sh, sw, swr, swl, sc) or coprocessor (swc1/swc2, sdc1/sdc2,
3448 swxc1, sdxc1, suxc1) stores, as long as the four stores are to
3449 different doublewords on the line. If the floating point unit is
3450 running in 1:2 mode, it is not possible to create the sequence above
3451 using only floating point store instructions.
3453 In this case, the cache line being filled is incorrectly marked
3454 invalid, thereby losing the data from any store to the line that
3455 occurs between the original miss and the completion of the five
3456 cycle sequence shown above.
3458 The workarounds are:
3460 * Run the data cache in write-through mode.
3461 * Insert a non-store instruction between
3462 Store A and Store B or Store B and Store C. */
3465 nops_for_24k (int ignore, const struct mips_cl_insn *hist,
3466 const struct mips_cl_insn *insn)
3468 struct fix_24k_store_info pos[3];
3469 int align, i, base_offset;
3474 /* If the previous instruction wasn't a store, there's nothing to
3476 if ((hist[0].insn_mo->pinfo & INSN_STORE_MEMORY) == 0)
3479 /* If the instructions after the previous one are unknown, we have
3480 to assume the worst. */
3484 /* Check whether we are dealing with three consecutive stores. */
3485 if ((insn->insn_mo->pinfo & INSN_STORE_MEMORY) == 0
3486 || (hist[1].insn_mo->pinfo & INSN_STORE_MEMORY) == 0)
3489 /* If we don't know the relationship between the store addresses,
3490 assume the worst. */
3491 if (!BASE_REG_EQ (insn->insn_opcode, hist[0].insn_opcode)
3492 || !BASE_REG_EQ (insn->insn_opcode, hist[1].insn_opcode))
3495 if (!fix_24k_record_store_info (&pos[0], insn)
3496 || !fix_24k_record_store_info (&pos[1], &hist[0])
3497 || !fix_24k_record_store_info (&pos[2], &hist[1]))
3500 qsort (&pos, 3, sizeof (struct fix_24k_store_info), fix_24k_sort);
3502 /* Pick a value of ALIGN and X such that all offsets are adjusted by
3503 X bytes and such that the base register + X is known to be aligned
3506 if (((insn->insn_opcode >> OP_SH_RS) & OP_MASK_RS) == SP)
3510 align = pos[0].align_to;
3511 base_offset = pos[0].off;
3512 for (i = 1; i < 3; i++)
3513 if (align < pos[i].align_to)
3515 align = pos[i].align_to;
3516 base_offset = pos[i].off;
3518 for (i = 0; i < 3; i++)
3519 pos[i].off -= base_offset;
3522 pos[0].off &= ~align + 1;
3523 pos[1].off &= ~align + 1;
3524 pos[2].off &= ~align + 1;
3526 /* If any two stores write to the same chunk, they also write to the
3527 same doubleword. The offsets are still sorted at this point. */
3528 if (pos[0].off == pos[1].off || pos[1].off == pos[2].off)
3531 /* A range of at least 9 bytes is needed for the stores to be in
3532 non-overlapping doublewords. */
3533 if (pos[2].off - pos[0].off <= 8)
3536 if (pos[2].off - pos[1].off >= 24
3537 || pos[1].off - pos[0].off >= 24
3538 || pos[2].off - pos[0].off >= 32)
3544 /* Return the number of nops that would be needed if instruction INSN
3545 immediately followed the MAX_NOPS instructions given by HIST,
3546 where HIST[0] is the most recent instruction. Ignore hazards
3547 between INSN and the first IGNORE instructions in HIST.
3549 If INSN is null, return the worse-case number of nops for any
3553 nops_for_insn (int ignore, const struct mips_cl_insn *hist,
3554 const struct mips_cl_insn *insn)
3556 int i, nops, tmp_nops;
3559 for (i = ignore; i < MAX_DELAY_NOPS; i++)
3561 tmp_nops = insns_between (hist + i, insn) - i;
3562 if (tmp_nops > nops)
3566 if (mips_fix_vr4130 && !mips_opts.micromips)
3568 tmp_nops = nops_for_vr4130 (ignore, hist, insn);
3569 if (tmp_nops > nops)
3573 if (mips_fix_24k && !mips_opts.micromips)
3575 tmp_nops = nops_for_24k (ignore, hist, insn);
3576 if (tmp_nops > nops)
3583 /* The variable arguments provide NUM_INSNS extra instructions that
3584 might be added to HIST. Return the largest number of nops that
3585 would be needed after the extended sequence, ignoring hazards
3586 in the first IGNORE instructions. */
3589 nops_for_sequence (int num_insns, int ignore,
3590 const struct mips_cl_insn *hist, ...)
3593 struct mips_cl_insn buffer[MAX_NOPS];
3594 struct mips_cl_insn *cursor;
3597 va_start (args, hist);
3598 cursor = buffer + num_insns;
3599 memcpy (cursor, hist, (MAX_NOPS - num_insns) * sizeof (*cursor));
3600 while (cursor > buffer)
3601 *--cursor = *va_arg (args, const struct mips_cl_insn *);
3603 nops = nops_for_insn (ignore, buffer, NULL);
3608 /* Like nops_for_insn, but if INSN is a branch, take into account the
3609 worst-case delay for the branch target. */
3612 nops_for_insn_or_target (int ignore, const struct mips_cl_insn *hist,
3613 const struct mips_cl_insn *insn)
3617 nops = nops_for_insn (ignore, hist, insn);
3618 if (delayed_branch_p (insn))
3620 tmp_nops = nops_for_sequence (2, ignore ? ignore + 2 : 0,
3621 hist, insn, get_delay_slot_nop (insn));
3622 if (tmp_nops > nops)
3625 else if (compact_branch_p (insn))
3627 tmp_nops = nops_for_sequence (1, ignore ? ignore + 1 : 0, hist, insn);
3628 if (tmp_nops > nops)
3634 /* Fix NOP issue: Replace nops by "or at,at,zero". */
3637 fix_loongson2f_nop (struct mips_cl_insn * ip)
3639 gas_assert (!HAVE_CODE_COMPRESSION);
3640 if (strcmp (ip->insn_mo->name, "nop") == 0)
3641 ip->insn_opcode = LOONGSON2F_NOP_INSN;
3644 /* Fix Jump Issue: Eliminate instruction fetch from outside 256M region
3645 jr target pc &= 'hffff_ffff_cfff_ffff. */
3648 fix_loongson2f_jump (struct mips_cl_insn * ip)
3650 gas_assert (!HAVE_CODE_COMPRESSION);
3651 if (strcmp (ip->insn_mo->name, "j") == 0
3652 || strcmp (ip->insn_mo->name, "jr") == 0
3653 || strcmp (ip->insn_mo->name, "jalr") == 0)
3661 sreg = EXTRACT_OPERAND (0, RS, *ip);
3662 if (sreg == ZERO || sreg == KT0 || sreg == KT1 || sreg == ATREG)
3665 ep.X_op = O_constant;
3666 ep.X_add_number = 0xcfff0000;
3667 macro_build (&ep, "lui", "t,u", ATREG, BFD_RELOC_HI16);
3668 ep.X_add_number = 0xffff;
3669 macro_build (&ep, "ori", "t,r,i", ATREG, ATREG, BFD_RELOC_LO16);
3670 macro_build (NULL, "and", "d,v,t", sreg, sreg, ATREG);
3675 fix_loongson2f (struct mips_cl_insn * ip)
3677 if (mips_fix_loongson2f_nop)
3678 fix_loongson2f_nop (ip);
3680 if (mips_fix_loongson2f_jump)
3681 fix_loongson2f_jump (ip);
3684 /* IP is a branch that has a delay slot, and we need to fill it
3685 automatically. Return true if we can do that by swapping IP
3686 with the previous instruction. */
3689 can_swap_branch_p (struct mips_cl_insn *ip)
3691 unsigned long pinfo, pinfo2, prev_pinfo, prev_pinfo2;
3692 unsigned int gpr_read, gpr_write, prev_gpr_read, prev_gpr_write;
3694 /* -O2 and above is required for this optimization. */
3695 if (mips_optimize < 2)
3698 /* If we have seen .set volatile or .set nomove, don't optimize. */
3699 if (mips_opts.nomove)
3702 /* We can't swap if the previous instruction's position is fixed. */
3703 if (history[0].fixed_p)
3706 /* If the previous previous insn was in a .set noreorder, we can't
3707 swap. Actually, the MIPS assembler will swap in this situation.
3708 However, gcc configured -with-gnu-as will generate code like
3716 in which we can not swap the bne and INSN. If gcc is not configured
3717 -with-gnu-as, it does not output the .set pseudo-ops. */
3718 if (history[1].noreorder_p)
3721 /* If the previous instruction had a fixup in mips16 mode, we can not swap.
3722 This means that the previous instruction was a 4-byte one anyhow. */
3723 if (mips_opts.mips16 && history[0].fixp[0])
3726 /* If the branch is itself the target of a branch, we can not swap.
3727 We cheat on this; all we check for is whether there is a label on
3728 this instruction. If there are any branches to anything other than
3729 a label, users must use .set noreorder. */
3730 if (seg_info (now_seg)->label_list)
3733 /* If the previous instruction is in a variant frag other than this
3734 branch's one, we cannot do the swap. This does not apply to
3735 MIPS16 code, which uses variant frags for different purposes. */
3736 if (!mips_opts.mips16
3738 && history[0].frag->fr_type == rs_machine_dependent)
3741 /* We do not swap with instructions that cannot architecturally
3742 be placed in a branch delay slot, such as SYNC or ERET. We
3743 also refrain from swapping with a trap instruction, since it
3744 complicates trap handlers to have the trap instruction be in
3746 prev_pinfo = history[0].insn_mo->pinfo;
3747 if (prev_pinfo & INSN_NO_DELAY_SLOT)
3750 /* Check for conflicts between the branch and the instructions
3751 before the candidate delay slot. */
3752 if (nops_for_insn (0, history + 1, ip) > 0)
3755 /* Check for conflicts between the swapped sequence and the
3756 target of the branch. */
3757 if (nops_for_sequence (2, 0, history + 1, ip, history) > 0)
3760 /* If the branch reads a register that the previous
3761 instruction sets, we can not swap. */
3762 gpr_read = gpr_read_mask (ip);
3763 prev_gpr_write = gpr_write_mask (&history[0]);
3764 if (gpr_read & prev_gpr_write)
3767 /* If the branch writes a register that the previous
3768 instruction sets, we can not swap. */
3769 gpr_write = gpr_write_mask (ip);
3770 if (gpr_write & prev_gpr_write)
3773 /* If the branch writes a register that the previous
3774 instruction reads, we can not swap. */
3775 prev_gpr_read = gpr_read_mask (&history[0]);
3776 if (gpr_write & prev_gpr_read)
3779 /* If one instruction sets a condition code and the
3780 other one uses a condition code, we can not swap. */
3781 pinfo = ip->insn_mo->pinfo;
3782 if ((pinfo & INSN_READ_COND_CODE)
3783 && (prev_pinfo & INSN_WRITE_COND_CODE))
3785 if ((pinfo & INSN_WRITE_COND_CODE)
3786 && (prev_pinfo & INSN_READ_COND_CODE))
3789 /* If the previous instruction uses the PC, we can not swap. */
3790 prev_pinfo2 = history[0].insn_mo->pinfo2;
3791 if (mips_opts.mips16 && (prev_pinfo & MIPS16_INSN_READ_PC))
3793 if (mips_opts.micromips && (prev_pinfo2 & INSN2_READ_PC))
3796 /* If the previous instruction has an incorrect size for a fixed
3797 branch delay slot in microMIPS mode, we cannot swap. */
3798 pinfo2 = ip->insn_mo->pinfo2;
3799 if (mips_opts.micromips
3800 && (pinfo2 & INSN2_BRANCH_DELAY_16BIT)
3801 && insn_length (history) != 2)
3803 if (mips_opts.micromips
3804 && (pinfo2 & INSN2_BRANCH_DELAY_32BIT)
3805 && insn_length (history) != 4)
3811 /* Decide how we should add IP to the instruction stream. */
3813 static enum append_method
3814 get_append_method (struct mips_cl_insn *ip)
3816 unsigned long pinfo;
3818 /* The relaxed version of a macro sequence must be inherently
3820 if (mips_relax.sequence == 2)
3823 /* We must not dabble with instructions in a ".set norerorder" block. */
3824 if (mips_opts.noreorder)
3827 /* Otherwise, it's our responsibility to fill branch delay slots. */
3828 if (delayed_branch_p (ip))
3830 if (!branch_likely_p (ip) && can_swap_branch_p (ip))
3833 pinfo = ip->insn_mo->pinfo;
3834 if (mips_opts.mips16
3835 && ISA_SUPPORTS_MIPS16E
3836 && (pinfo & (MIPS16_INSN_READ_X | MIPS16_INSN_READ_31)))
3837 return APPEND_ADD_COMPACT;
3839 return APPEND_ADD_WITH_NOP;
3845 /* IP is a MIPS16 instruction whose opcode we have just changed.
3846 Point IP->insn_mo to the new opcode's definition. */
3849 find_altered_mips16_opcode (struct mips_cl_insn *ip)
3851 const struct mips_opcode *mo, *end;
3853 end = &mips16_opcodes[bfd_mips16_num_opcodes];
3854 for (mo = ip->insn_mo; mo < end; mo++)
3855 if ((ip->insn_opcode & mo->mask) == mo->match)
3863 /* For microMIPS macros, we need to generate a local number label
3864 as the target of branches. */
3865 #define MICROMIPS_LABEL_CHAR '\037'
3866 static unsigned long micromips_target_label;
3867 static char micromips_target_name[32];
3870 micromips_label_name (void)
3872 char *p = micromips_target_name;
3873 char symbol_name_temporary[24];
3881 l = micromips_target_label;
3882 #ifdef LOCAL_LABEL_PREFIX
3883 *p++ = LOCAL_LABEL_PREFIX;
3886 *p++ = MICROMIPS_LABEL_CHAR;
3889 symbol_name_temporary[i++] = l % 10 + '0';
3894 *p++ = symbol_name_temporary[--i];
3897 return micromips_target_name;
3901 micromips_label_expr (expressionS *label_expr)
3903 label_expr->X_op = O_symbol;
3904 label_expr->X_add_symbol = symbol_find_or_make (micromips_label_name ());
3905 label_expr->X_add_number = 0;
3909 micromips_label_inc (void)
3911 micromips_target_label++;
3912 *micromips_target_name = '\0';
3916 micromips_add_label (void)
3920 s = colon (micromips_label_name ());
3921 micromips_label_inc ();
3922 #if defined(OBJ_ELF) || defined(OBJ_MAYBE_ELF)
3924 S_SET_OTHER (s, ELF_ST_SET_MICROMIPS (S_GET_OTHER (s)));
3930 /* If assembling microMIPS code, then return the microMIPS reloc
3931 corresponding to the requested one if any. Otherwise return
3932 the reloc unchanged. */
3934 static bfd_reloc_code_real_type
3935 micromips_map_reloc (bfd_reloc_code_real_type reloc)
3937 static const bfd_reloc_code_real_type relocs[][2] =
3939 /* Keep sorted incrementally by the left-hand key. */
3940 { BFD_RELOC_16_PCREL_S2, BFD_RELOC_MICROMIPS_16_PCREL_S1 },
3941 { BFD_RELOC_GPREL16, BFD_RELOC_MICROMIPS_GPREL16 },
3942 { BFD_RELOC_MIPS_JMP, BFD_RELOC_MICROMIPS_JMP },
3943 { BFD_RELOC_HI16, BFD_RELOC_MICROMIPS_HI16 },
3944 { BFD_RELOC_HI16_S, BFD_RELOC_MICROMIPS_HI16_S },
3945 { BFD_RELOC_LO16, BFD_RELOC_MICROMIPS_LO16 },
3946 { BFD_RELOC_MIPS_LITERAL, BFD_RELOC_MICROMIPS_LITERAL },
3947 { BFD_RELOC_MIPS_GOT16, BFD_RELOC_MICROMIPS_GOT16 },
3948 { BFD_RELOC_MIPS_CALL16, BFD_RELOC_MICROMIPS_CALL16 },
3949 { BFD_RELOC_MIPS_GOT_HI16, BFD_RELOC_MICROMIPS_GOT_HI16 },
3950 { BFD_RELOC_MIPS_GOT_LO16, BFD_RELOC_MICROMIPS_GOT_LO16 },
3951 { BFD_RELOC_MIPS_CALL_HI16, BFD_RELOC_MICROMIPS_CALL_HI16 },
3952 { BFD_RELOC_MIPS_CALL_LO16, BFD_RELOC_MICROMIPS_CALL_LO16 },
3953 { BFD_RELOC_MIPS_SUB, BFD_RELOC_MICROMIPS_SUB },
3954 { BFD_RELOC_MIPS_GOT_PAGE, BFD_RELOC_MICROMIPS_GOT_PAGE },
3955 { BFD_RELOC_MIPS_GOT_OFST, BFD_RELOC_MICROMIPS_GOT_OFST },
3956 { BFD_RELOC_MIPS_GOT_DISP, BFD_RELOC_MICROMIPS_GOT_DISP },
3957 { BFD_RELOC_MIPS_HIGHEST, BFD_RELOC_MICROMIPS_HIGHEST },
3958 { BFD_RELOC_MIPS_HIGHER, BFD_RELOC_MICROMIPS_HIGHER },
3959 { BFD_RELOC_MIPS_SCN_DISP, BFD_RELOC_MICROMIPS_SCN_DISP },
3960 { BFD_RELOC_MIPS_TLS_GD, BFD_RELOC_MICROMIPS_TLS_GD },
3961 { BFD_RELOC_MIPS_TLS_LDM, BFD_RELOC_MICROMIPS_TLS_LDM },
3962 { BFD_RELOC_MIPS_TLS_DTPREL_HI16, BFD_RELOC_MICROMIPS_TLS_DTPREL_HI16 },
3963 { BFD_RELOC_MIPS_TLS_DTPREL_LO16, BFD_RELOC_MICROMIPS_TLS_DTPREL_LO16 },
3964 { BFD_RELOC_MIPS_TLS_GOTTPREL, BFD_RELOC_MICROMIPS_TLS_GOTTPREL },
3965 { BFD_RELOC_MIPS_TLS_TPREL_HI16, BFD_RELOC_MICROMIPS_TLS_TPREL_HI16 },
3966 { BFD_RELOC_MIPS_TLS_TPREL_LO16, BFD_RELOC_MICROMIPS_TLS_TPREL_LO16 }
3968 bfd_reloc_code_real_type r;
3971 if (!mips_opts.micromips)
3973 for (i = 0; i < ARRAY_SIZE (relocs); i++)
3979 return relocs[i][1];
3984 /* Output an instruction. IP is the instruction information.
3985 ADDRESS_EXPR is an operand of the instruction to be used with
3986 RELOC_TYPE. EXPANSIONP is true if the instruction is part of
3987 a macro expansion. */
3990 append_insn (struct mips_cl_insn *ip, expressionS *address_expr,
3991 bfd_reloc_code_real_type *reloc_type, bfd_boolean expansionp)
3993 unsigned long prev_pinfo2, pinfo;
3994 bfd_boolean relaxed_branch = FALSE;
3995 enum append_method method;
3996 bfd_boolean relax32;
3999 if (mips_fix_loongson2f && !HAVE_CODE_COMPRESSION)
4000 fix_loongson2f (ip);
4002 mips_mark_labels ();
4004 file_ase_mips16 |= mips_opts.mips16;
4005 file_ase_micromips |= mips_opts.micromips;
4007 prev_pinfo2 = history[0].insn_mo->pinfo2;
4008 pinfo = ip->insn_mo->pinfo;
4010 if (mips_opts.micromips
4012 && (((prev_pinfo2 & INSN2_BRANCH_DELAY_16BIT) != 0
4013 && micromips_insn_length (ip->insn_mo) != 2)
4014 || ((prev_pinfo2 & INSN2_BRANCH_DELAY_32BIT) != 0
4015 && micromips_insn_length (ip->insn_mo) != 4)))
4016 as_warn (_("Wrong size instruction in a %u-bit branch delay slot"),
4017 (prev_pinfo2 & INSN2_BRANCH_DELAY_16BIT) != 0 ? 16 : 32);
4019 if (address_expr == NULL)
4021 else if (*reloc_type <= BFD_RELOC_UNUSED
4022 && address_expr->X_op == O_constant)
4027 switch (*reloc_type)
4030 ip->insn_opcode |= address_expr->X_add_number;
4033 case BFD_RELOC_MIPS_HIGHEST:
4034 tmp = (address_expr->X_add_number + 0x800080008000ull) >> 48;
4035 ip->insn_opcode |= tmp & 0xffff;
4038 case BFD_RELOC_MIPS_HIGHER:
4039 tmp = (address_expr->X_add_number + 0x80008000ull) >> 32;
4040 ip->insn_opcode |= tmp & 0xffff;
4043 case BFD_RELOC_HI16_S:
4044 tmp = (address_expr->X_add_number + 0x8000) >> 16;
4045 ip->insn_opcode |= tmp & 0xffff;
4048 case BFD_RELOC_HI16:
4049 ip->insn_opcode |= (address_expr->X_add_number >> 16) & 0xffff;
4052 case BFD_RELOC_UNUSED:
4053 case BFD_RELOC_LO16:
4054 case BFD_RELOC_MIPS_GOT_DISP:
4055 ip->insn_opcode |= address_expr->X_add_number & 0xffff;
4058 case BFD_RELOC_MIPS_JMP:
4062 shift = mips_opts.micromips ? 1 : 2;
4063 if ((address_expr->X_add_number & ((1 << shift) - 1)) != 0)
4064 as_bad (_("jump to misaligned address (0x%lx)"),
4065 (unsigned long) address_expr->X_add_number);
4066 ip->insn_opcode |= ((address_expr->X_add_number >> shift)
4072 case BFD_RELOC_MIPS16_JMP:
4073 if ((address_expr->X_add_number & 3) != 0)
4074 as_bad (_("jump to misaligned address (0x%lx)"),
4075 (unsigned long) address_expr->X_add_number);
4077 (((address_expr->X_add_number & 0x7c0000) << 3)
4078 | ((address_expr->X_add_number & 0xf800000) >> 7)
4079 | ((address_expr->X_add_number & 0x3fffc) >> 2));
4083 case BFD_RELOC_16_PCREL_S2:
4087 shift = mips_opts.micromips ? 1 : 2;
4088 if ((address_expr->X_add_number & ((1 << shift) - 1)) != 0)
4089 as_bad (_("branch to misaligned address (0x%lx)"),
4090 (unsigned long) address_expr->X_add_number);
4091 if (!mips_relax_branch)
4093 if ((address_expr->X_add_number + (1 << (shift + 15)))
4094 & ~((1 << (shift + 16)) - 1))
4095 as_bad (_("branch address range overflow (0x%lx)"),
4096 (unsigned long) address_expr->X_add_number);
4097 ip->insn_opcode |= ((address_expr->X_add_number >> shift)
4109 if (mips_relax.sequence != 2 && !mips_opts.noreorder)
4111 /* There are a lot of optimizations we could do that we don't.
4112 In particular, we do not, in general, reorder instructions.
4113 If you use gcc with optimization, it will reorder
4114 instructions and generally do much more optimization then we
4115 do here; repeating all that work in the assembler would only
4116 benefit hand written assembly code, and does not seem worth
4118 int nops = (mips_optimize == 0
4119 ? nops_for_insn (0, history, NULL)
4120 : nops_for_insn_or_target (0, history, ip));
4124 unsigned long old_frag_offset;
4127 old_frag = frag_now;
4128 old_frag_offset = frag_now_fix ();
4130 for (i = 0; i < nops; i++)
4131 add_fixed_insn (NOP_INSN);
4132 insert_into_history (0, nops, NOP_INSN);
4136 listing_prev_line ();
4137 /* We may be at the start of a variant frag. In case we
4138 are, make sure there is enough space for the frag
4139 after the frags created by listing_prev_line. The
4140 argument to frag_grow here must be at least as large
4141 as the argument to all other calls to frag_grow in
4142 this file. We don't have to worry about being in the
4143 middle of a variant frag, because the variants insert
4144 all needed nop instructions themselves. */
4148 mips_move_labels ();
4150 #ifndef NO_ECOFF_DEBUGGING
4151 if (ECOFF_DEBUGGING)
4152 ecoff_fix_loc (old_frag, old_frag_offset);
4156 else if (mips_relax.sequence != 2 && prev_nop_frag != NULL)
4160 /* Work out how many nops in prev_nop_frag are needed by IP,
4161 ignoring hazards generated by the first prev_nop_frag_since
4163 nops = nops_for_insn_or_target (prev_nop_frag_since, history, ip);
4164 gas_assert (nops <= prev_nop_frag_holds);
4166 /* Enforce NOPS as a minimum. */
4167 if (nops > prev_nop_frag_required)
4168 prev_nop_frag_required = nops;
4170 if (prev_nop_frag_holds == prev_nop_frag_required)
4172 /* Settle for the current number of nops. Update the history
4173 accordingly (for the benefit of any future .set reorder code). */
4174 prev_nop_frag = NULL;
4175 insert_into_history (prev_nop_frag_since,
4176 prev_nop_frag_holds, NOP_INSN);
4180 /* Allow this instruction to replace one of the nops that was
4181 tentatively added to prev_nop_frag. */
4182 prev_nop_frag->fr_fix -= NOP_INSN_SIZE;
4183 prev_nop_frag_holds--;
4184 prev_nop_frag_since++;
4188 method = get_append_method (ip);
4189 branch_disp = method == APPEND_SWAP ? insn_length (history) : 0;
4192 /* The value passed to dwarf2_emit_insn is the distance between
4193 the beginning of the current instruction and the address that
4194 should be recorded in the debug tables. This is normally the
4197 For MIPS16/microMIPS debug info we want to use ISA-encoded
4198 addresses, so we use -1 for an address higher by one than the
4201 If the instruction produced is a branch that we will swap with
4202 the preceding instruction, then we add the displacement by which
4203 the branch will be moved backwards. This is more appropriate
4204 and for MIPS16/microMIPS code also prevents a debugger from
4205 placing a breakpoint in the middle of the branch (and corrupting
4206 code if software breakpoints are used). */
4207 dwarf2_emit_insn ((HAVE_CODE_COMPRESSION ? -1 : 0) + branch_disp);
4210 relax32 = (mips_relax_branch
4211 /* Don't try branch relaxation within .set nomacro, or within
4212 .set noat if we use $at for PIC computations. If it turns
4213 out that the branch was out-of-range, we'll get an error. */
4214 && !mips_opts.warn_about_macros
4215 && (mips_opts.at || mips_pic == NO_PIC)
4216 /* Don't relax BPOSGE32/64 as they have no complementing
4218 && !(ip->insn_mo->membership & (INSN_DSP64 | INSN_DSP)));
4220 if (!HAVE_CODE_COMPRESSION
4223 && *reloc_type == BFD_RELOC_16_PCREL_S2
4224 && delayed_branch_p (ip))
4226 relaxed_branch = TRUE;
4227 add_relaxed_insn (ip, (relaxed_branch_length
4229 uncond_branch_p (ip) ? -1
4230 : branch_likely_p (ip) ? 1
4234 uncond_branch_p (ip),
4235 branch_likely_p (ip),
4236 pinfo & INSN_WRITE_GPR_31,
4238 address_expr->X_add_symbol,
4239 address_expr->X_add_number);
4240 *reloc_type = BFD_RELOC_UNUSED;
4242 else if (mips_opts.micromips
4244 && ((relax32 && *reloc_type == BFD_RELOC_16_PCREL_S2)
4245 || *reloc_type > BFD_RELOC_UNUSED)
4246 && (delayed_branch_p (ip) || compact_branch_p (ip))
4247 /* Don't try branch relaxation when users specify
4248 16-bit/32-bit instructions. */
4249 && !forced_insn_length)
4251 bfd_boolean relax16 = *reloc_type > BFD_RELOC_UNUSED;
4252 int type = relax16 ? *reloc_type - BFD_RELOC_UNUSED : 0;
4253 int uncond = uncond_branch_p (ip) ? -1 : 0;
4254 int compact = compact_branch_p (ip);
4255 int al = pinfo & INSN_WRITE_GPR_31;
4258 gas_assert (address_expr != NULL);
4259 gas_assert (!mips_relax.sequence);
4261 relaxed_branch = TRUE;
4262 length32 = relaxed_micromips_32bit_branch_length (NULL, NULL, uncond);
4263 add_relaxed_insn (ip, relax32 ? length32 : 4, relax16 ? 2 : 4,
4264 RELAX_MICROMIPS_ENCODE (type, AT, uncond, compact, al,
4266 address_expr->X_add_symbol,
4267 address_expr->X_add_number);
4268 *reloc_type = BFD_RELOC_UNUSED;
4270 else if (mips_opts.mips16 && *reloc_type > BFD_RELOC_UNUSED)
4272 /* We need to set up a variant frag. */
4273 gas_assert (address_expr != NULL);
4274 add_relaxed_insn (ip, 4, 0,
4276 (*reloc_type - BFD_RELOC_UNUSED,
4277 forced_insn_length == 2, forced_insn_length == 4,
4278 delayed_branch_p (&history[0]),
4279 history[0].mips16_absolute_jump_p),
4280 make_expr_symbol (address_expr), 0);
4282 else if (mips_opts.mips16
4284 && *reloc_type != BFD_RELOC_MIPS16_JMP)
4286 if (!delayed_branch_p (ip))
4287 /* Make sure there is enough room to swap this instruction with
4288 a following jump instruction. */
4290 add_fixed_insn (ip);
4294 if (mips_opts.mips16
4295 && mips_opts.noreorder
4296 && delayed_branch_p (&history[0]))
4297 as_warn (_("extended instruction in delay slot"));
4299 if (mips_relax.sequence)
4301 /* If we've reached the end of this frag, turn it into a variant
4302 frag and record the information for the instructions we've
4304 if (frag_room () < 4)
4305 relax_close_frag ();
4306 mips_relax.sizes[mips_relax.sequence - 1] += insn_length (ip);
4309 if (mips_relax.sequence != 2)
4311 if (mips_macro_warning.first_insn_sizes[0] == 0)
4312 mips_macro_warning.first_insn_sizes[0] = insn_length (ip);
4313 mips_macro_warning.sizes[0] += insn_length (ip);
4314 mips_macro_warning.insns[0]++;
4316 if (mips_relax.sequence != 1)
4318 if (mips_macro_warning.first_insn_sizes[1] == 0)
4319 mips_macro_warning.first_insn_sizes[1] = insn_length (ip);
4320 mips_macro_warning.sizes[1] += insn_length (ip);
4321 mips_macro_warning.insns[1]++;
4324 if (mips_opts.mips16)
4327 ip->mips16_absolute_jump_p = (*reloc_type == BFD_RELOC_MIPS16_JMP);
4329 add_fixed_insn (ip);
4332 if (!ip->complete_p && *reloc_type < BFD_RELOC_UNUSED)
4334 bfd_reloc_code_real_type final_type[3];
4335 reloc_howto_type *howto0;
4336 reloc_howto_type *howto;
4339 /* Perform any necessary conversion to microMIPS relocations
4340 and find out how many relocations there actually are. */
4341 for (i = 0; i < 3 && reloc_type[i] != BFD_RELOC_UNUSED; i++)
4342 final_type[i] = micromips_map_reloc (reloc_type[i]);
4344 /* In a compound relocation, it is the final (outermost)
4345 operator that determines the relocated field. */
4346 howto = howto0 = bfd_reloc_type_lookup (stdoutput, final_type[i - 1]);
4350 /* To reproduce this failure try assembling gas/testsuites/
4351 gas/mips/mips16-intermix.s with a mips-ecoff targeted
4353 as_bad (_("Unsupported MIPS relocation number %d"),
4355 howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_16);
4359 howto0 = bfd_reloc_type_lookup (stdoutput, final_type[0]);
4360 ip->fixp[0] = fix_new_exp (ip->frag, ip->where,
4361 bfd_get_reloc_size (howto),
4363 howto0 && howto0->pc_relative,
4366 /* Tag symbols that have a R_MIPS16_26 relocation against them. */
4367 if (final_type[0] == BFD_RELOC_MIPS16_JMP && ip->fixp[0]->fx_addsy)
4368 *symbol_get_tc (ip->fixp[0]->fx_addsy) = 1;
4370 /* These relocations can have an addend that won't fit in
4371 4 octets for 64bit assembly. */
4373 && ! howto->partial_inplace
4374 && (reloc_type[0] == BFD_RELOC_16
4375 || reloc_type[0] == BFD_RELOC_32
4376 || reloc_type[0] == BFD_RELOC_MIPS_JMP
4377 || reloc_type[0] == BFD_RELOC_GPREL16
4378 || reloc_type[0] == BFD_RELOC_MIPS_LITERAL
4379 || reloc_type[0] == BFD_RELOC_GPREL32
4380 || reloc_type[0] == BFD_RELOC_64
4381 || reloc_type[0] == BFD_RELOC_CTOR
4382 || reloc_type[0] == BFD_RELOC_MIPS_SUB
4383 || reloc_type[0] == BFD_RELOC_MIPS_HIGHEST
4384 || reloc_type[0] == BFD_RELOC_MIPS_HIGHER
4385 || reloc_type[0] == BFD_RELOC_MIPS_SCN_DISP
4386 || reloc_type[0] == BFD_RELOC_MIPS_REL16
4387 || reloc_type[0] == BFD_RELOC_MIPS_RELGOT
4388 || reloc_type[0] == BFD_RELOC_MIPS16_GPREL
4389 || hi16_reloc_p (reloc_type[0])
4390 || lo16_reloc_p (reloc_type[0])))
4391 ip->fixp[0]->fx_no_overflow = 1;
4393 if (mips_relax.sequence)
4395 if (mips_relax.first_fixup == 0)
4396 mips_relax.first_fixup = ip->fixp[0];
4398 else if (reloc_needs_lo_p (*reloc_type))
4400 struct mips_hi_fixup *hi_fixup;
4402 /* Reuse the last entry if it already has a matching %lo. */
4403 hi_fixup = mips_hi_fixup_list;
4405 || !fixup_has_matching_lo_p (hi_fixup->fixp))
4407 hi_fixup = ((struct mips_hi_fixup *)
4408 xmalloc (sizeof (struct mips_hi_fixup)));
4409 hi_fixup->next = mips_hi_fixup_list;
4410 mips_hi_fixup_list = hi_fixup;
4412 hi_fixup->fixp = ip->fixp[0];
4413 hi_fixup->seg = now_seg;
4416 /* Add fixups for the second and third relocations, if given.
4417 Note that the ABI allows the second relocation to be
4418 against RSS_UNDEF, RSS_GP, RSS_GP0 or RSS_LOC. At the
4419 moment we only use RSS_UNDEF, but we could add support
4420 for the others if it ever becomes necessary. */
4421 for (i = 1; i < 3; i++)
4422 if (reloc_type[i] != BFD_RELOC_UNUSED)
4424 ip->fixp[i] = fix_new (ip->frag, ip->where,
4425 ip->fixp[0]->fx_size, NULL, 0,
4426 FALSE, final_type[i]);
4428 /* Use fx_tcbit to mark compound relocs. */
4429 ip->fixp[0]->fx_tcbit = 1;
4430 ip->fixp[i]->fx_tcbit = 1;
4435 /* Update the register mask information. */
4436 mips_gprmask |= gpr_read_mask (ip) | gpr_write_mask (ip);
4437 mips_cprmask[1] |= fpr_read_mask (ip) | fpr_write_mask (ip);
4442 insert_into_history (0, 1, ip);
4445 case APPEND_ADD_WITH_NOP:
4447 struct mips_cl_insn *nop;
4449 insert_into_history (0, 1, ip);
4450 nop = get_delay_slot_nop (ip);
4451 add_fixed_insn (nop);
4452 insert_into_history (0, 1, nop);
4453 if (mips_relax.sequence)
4454 mips_relax.sizes[mips_relax.sequence - 1] += insn_length (nop);
4458 case APPEND_ADD_COMPACT:
4459 /* Convert MIPS16 jr/jalr into a "compact" jump. */
4460 gas_assert (mips_opts.mips16);
4461 ip->insn_opcode |= 0x0080;
4462 find_altered_mips16_opcode (ip);
4464 insert_into_history (0, 1, ip);
4469 struct mips_cl_insn delay = history[0];
4470 if (mips_opts.mips16)
4472 know (delay.frag == ip->frag);
4473 move_insn (ip, delay.frag, delay.where);
4474 move_insn (&delay, ip->frag, ip->where + insn_length (ip));
4476 else if (relaxed_branch)
4478 /* Add the delay slot instruction to the end of the
4479 current frag and shrink the fixed part of the
4480 original frag. If the branch occupies the tail of
4481 the latter, move it backwards to cover the gap. */
4482 delay.frag->fr_fix -= branch_disp;
4483 if (delay.frag == ip->frag)
4484 move_insn (ip, ip->frag, ip->where - branch_disp);
4485 add_fixed_insn (&delay);
4489 move_insn (&delay, ip->frag,
4490 ip->where - branch_disp + insn_length (ip));
4491 move_insn (ip, history[0].frag, history[0].where);
4495 insert_into_history (0, 1, &delay);
4500 /* If we have just completed an unconditional branch, clear the history. */
4501 if ((delayed_branch_p (&history[1]) && uncond_branch_p (&history[1]))
4502 || (compact_branch_p (&history[0]) && uncond_branch_p (&history[0])))
4503 mips_no_prev_insn ();
4505 /* We need to emit a label at the end of branch-likely macros. */
4506 if (emit_branch_likely_macro)
4508 emit_branch_likely_macro = FALSE;
4509 micromips_add_label ();
4512 /* We just output an insn, so the next one doesn't have a label. */
4513 mips_clear_insn_labels ();
4516 /* Forget that there was any previous instruction or label. */
4519 mips_no_prev_insn (void)
4521 prev_nop_frag = NULL;
4522 insert_into_history (0, ARRAY_SIZE (history), NOP_INSN);
4523 mips_clear_insn_labels ();
4526 /* This function must be called before we emit something other than
4527 instructions. It is like mips_no_prev_insn except that it inserts
4528 any NOPS that might be needed by previous instructions. */
4531 mips_emit_delays (void)
4533 if (! mips_opts.noreorder)
4535 int nops = nops_for_insn (0, history, NULL);
4539 add_fixed_insn (NOP_INSN);
4540 mips_move_labels ();
4543 mips_no_prev_insn ();
4546 /* Start a (possibly nested) noreorder block. */
4549 start_noreorder (void)
4551 if (mips_opts.noreorder == 0)
4556 /* None of the instructions before the .set noreorder can be moved. */
4557 for (i = 0; i < ARRAY_SIZE (history); i++)
4558 history[i].fixed_p = 1;
4560 /* Insert any nops that might be needed between the .set noreorder
4561 block and the previous instructions. We will later remove any
4562 nops that turn out not to be needed. */
4563 nops = nops_for_insn (0, history, NULL);
4566 if (mips_optimize != 0)
4568 /* Record the frag which holds the nop instructions, so
4569 that we can remove them if we don't need them. */
4570 frag_grow (nops * NOP_INSN_SIZE);
4571 prev_nop_frag = frag_now;
4572 prev_nop_frag_holds = nops;
4573 prev_nop_frag_required = 0;
4574 prev_nop_frag_since = 0;
4577 for (; nops > 0; --nops)
4578 add_fixed_insn (NOP_INSN);
4580 /* Move on to a new frag, so that it is safe to simply
4581 decrease the size of prev_nop_frag. */
4582 frag_wane (frag_now);
4584 mips_move_labels ();
4586 mips_mark_labels ();
4587 mips_clear_insn_labels ();
4589 mips_opts.noreorder++;
4590 mips_any_noreorder = 1;
4593 /* End a nested noreorder block. */
4596 end_noreorder (void)
4598 mips_opts.noreorder--;
4599 if (mips_opts.noreorder == 0 && prev_nop_frag != NULL)
4601 /* Commit to inserting prev_nop_frag_required nops and go back to
4602 handling nop insertion the .set reorder way. */
4603 prev_nop_frag->fr_fix -= ((prev_nop_frag_holds - prev_nop_frag_required)
4605 insert_into_history (prev_nop_frag_since,
4606 prev_nop_frag_required, NOP_INSN);
4607 prev_nop_frag = NULL;
4611 /* Set up global variables for the start of a new macro. */
4616 memset (&mips_macro_warning.sizes, 0, sizeof (mips_macro_warning.sizes));
4617 memset (&mips_macro_warning.first_insn_sizes, 0,
4618 sizeof (mips_macro_warning.first_insn_sizes));
4619 memset (&mips_macro_warning.insns, 0, sizeof (mips_macro_warning.insns));
4620 mips_macro_warning.delay_slot_p = (mips_opts.noreorder
4621 && delayed_branch_p (&history[0]));
4622 switch (history[0].insn_mo->pinfo2
4623 & (INSN2_BRANCH_DELAY_32BIT | INSN2_BRANCH_DELAY_16BIT))
4625 case INSN2_BRANCH_DELAY_32BIT:
4626 mips_macro_warning.delay_slot_length = 4;
4628 case INSN2_BRANCH_DELAY_16BIT:
4629 mips_macro_warning.delay_slot_length = 2;
4632 mips_macro_warning.delay_slot_length = 0;
4635 mips_macro_warning.first_frag = NULL;
4638 /* Given that a macro is longer than one instruction or of the wrong size,
4639 return the appropriate warning for it. Return null if no warning is
4640 needed. SUBTYPE is a bitmask of RELAX_DELAY_SLOT, RELAX_DELAY_SLOT_16BIT,
4641 RELAX_DELAY_SLOT_SIZE_FIRST, RELAX_DELAY_SLOT_SIZE_SECOND,
4642 and RELAX_NOMACRO. */
4645 macro_warning (relax_substateT subtype)
4647 if (subtype & RELAX_DELAY_SLOT)
4648 return _("Macro instruction expanded into multiple instructions"
4649 " in a branch delay slot");
4650 else if (subtype & RELAX_NOMACRO)
4651 return _("Macro instruction expanded into multiple instructions");
4652 else if (subtype & (RELAX_DELAY_SLOT_SIZE_FIRST
4653 | RELAX_DELAY_SLOT_SIZE_SECOND))
4654 return ((subtype & RELAX_DELAY_SLOT_16BIT)
4655 ? _("Macro instruction expanded into a wrong size instruction"
4656 " in a 16-bit branch delay slot")
4657 : _("Macro instruction expanded into a wrong size instruction"
4658 " in a 32-bit branch delay slot"));
4663 /* Finish up a macro. Emit warnings as appropriate. */
4668 /* Relaxation warning flags. */
4669 relax_substateT subtype = 0;
4671 /* Check delay slot size requirements. */
4672 if (mips_macro_warning.delay_slot_length == 2)
4673 subtype |= RELAX_DELAY_SLOT_16BIT;
4674 if (mips_macro_warning.delay_slot_length != 0)
4676 if (mips_macro_warning.delay_slot_length
4677 != mips_macro_warning.first_insn_sizes[0])
4678 subtype |= RELAX_DELAY_SLOT_SIZE_FIRST;
4679 if (mips_macro_warning.delay_slot_length
4680 != mips_macro_warning.first_insn_sizes[1])
4681 subtype |= RELAX_DELAY_SLOT_SIZE_SECOND;
4684 /* Check instruction count requirements. */
4685 if (mips_macro_warning.insns[0] > 1 || mips_macro_warning.insns[1] > 1)
4687 if (mips_macro_warning.insns[1] > mips_macro_warning.insns[0])
4688 subtype |= RELAX_SECOND_LONGER;
4689 if (mips_opts.warn_about_macros)
4690 subtype |= RELAX_NOMACRO;
4691 if (mips_macro_warning.delay_slot_p)
4692 subtype |= RELAX_DELAY_SLOT;
4695 /* If both alternatives fail to fill a delay slot correctly,
4696 emit the warning now. */
4697 if ((subtype & RELAX_DELAY_SLOT_SIZE_FIRST) != 0
4698 && (subtype & RELAX_DELAY_SLOT_SIZE_SECOND) != 0)
4703 s = subtype & (RELAX_DELAY_SLOT_16BIT
4704 | RELAX_DELAY_SLOT_SIZE_FIRST
4705 | RELAX_DELAY_SLOT_SIZE_SECOND);
4706 msg = macro_warning (s);
4708 as_warn ("%s", msg);
4712 /* If both implementations are longer than 1 instruction, then emit the
4714 if (mips_macro_warning.insns[0] > 1 && mips_macro_warning.insns[1] > 1)
4719 s = subtype & (RELAX_SECOND_LONGER | RELAX_NOMACRO | RELAX_DELAY_SLOT);
4720 msg = macro_warning (s);
4722 as_warn ("%s", msg);
4726 /* If any flags still set, then one implementation might need a warning
4727 and the other either will need one of a different kind or none at all.
4728 Pass any remaining flags over to relaxation. */
4729 if (mips_macro_warning.first_frag != NULL)
4730 mips_macro_warning.first_frag->fr_subtype |= subtype;
4733 /* Instruction operand formats used in macros that vary between
4734 standard MIPS and microMIPS code. */
4736 static const char * const brk_fmt[2] = { "c", "mF" };
4737 static const char * const cop12_fmt[2] = { "E,o(b)", "E,~(b)" };
4738 static const char * const jalr_fmt[2] = { "d,s", "t,s" };
4739 static const char * const lui_fmt[2] = { "t,u", "s,u" };
4740 static const char * const mem12_fmt[2] = { "t,o(b)", "t,~(b)" };
4741 static const char * const mfhl_fmt[2] = { "d", "mj" };
4742 static const char * const shft_fmt[2] = { "d,w,<", "t,r,<" };
4743 static const char * const trap_fmt[2] = { "s,t,q", "s,t,|" };
4745 #define BRK_FMT (brk_fmt[mips_opts.micromips])
4746 #define COP12_FMT (cop12_fmt[mips_opts.micromips])
4747 #define JALR_FMT (jalr_fmt[mips_opts.micromips])
4748 #define LUI_FMT (lui_fmt[mips_opts.micromips])
4749 #define MEM12_FMT (mem12_fmt[mips_opts.micromips])
4750 #define MFHL_FMT (mfhl_fmt[mips_opts.micromips])
4751 #define SHFT_FMT (shft_fmt[mips_opts.micromips])
4752 #define TRAP_FMT (trap_fmt[mips_opts.micromips])
4754 /* Read a macro's relocation codes from *ARGS and store them in *R.
4755 The first argument in *ARGS will be either the code for a single
4756 relocation or -1 followed by the three codes that make up a
4757 composite relocation. */
4760 macro_read_relocs (va_list *args, bfd_reloc_code_real_type *r)
4764 next = va_arg (*args, int);
4766 r[0] = (bfd_reloc_code_real_type) next;
4768 for (i = 0; i < 3; i++)
4769 r[i] = (bfd_reloc_code_real_type) va_arg (*args, int);
4772 /* Build an instruction created by a macro expansion. This is passed
4773 a pointer to the count of instructions created so far, an
4774 expression, the name of the instruction to build, an operand format
4775 string, and corresponding arguments. */
4778 macro_build (expressionS *ep, const char *name, const char *fmt, ...)
4780 const struct mips_opcode *mo = NULL;
4781 bfd_reloc_code_real_type r[3];
4782 const struct mips_opcode *amo;
4783 struct hash_control *hash;
4784 struct mips_cl_insn insn;
4787 va_start (args, fmt);
4789 if (mips_opts.mips16)
4791 mips16_macro_build (ep, name, fmt, &args);
4796 r[0] = BFD_RELOC_UNUSED;
4797 r[1] = BFD_RELOC_UNUSED;
4798 r[2] = BFD_RELOC_UNUSED;
4799 hash = mips_opts.micromips ? micromips_op_hash : op_hash;
4800 amo = (struct mips_opcode *) hash_find (hash, name);
4802 gas_assert (strcmp (name, amo->name) == 0);
4806 /* Search until we get a match for NAME. It is assumed here that
4807 macros will never generate MDMX, MIPS-3D, or MT instructions.
4808 We try to match an instruction that fulfils the branch delay
4809 slot instruction length requirement (if any) of the previous
4810 instruction. While doing this we record the first instruction
4811 seen that matches all the other conditions and use it anyway
4812 if the requirement cannot be met; we will issue an appropriate
4813 warning later on. */
4814 if (strcmp (fmt, amo->args) == 0
4815 && amo->pinfo != INSN_MACRO
4816 && is_opcode_valid (amo)
4817 && is_size_valid (amo))
4819 if (is_delay_slot_valid (amo))
4829 gas_assert (amo->name);
4831 while (strcmp (name, amo->name) == 0);
4834 create_insn (&insn, mo);
4852 INSERT_OPERAND (mips_opts.micromips,
4853 EXTLSB, insn, va_arg (args, int));
4858 /* Note that in the macro case, these arguments are already
4859 in MSB form. (When handling the instruction in the
4860 non-macro case, these arguments are sizes from which
4861 MSB values must be calculated.) */
4862 INSERT_OPERAND (mips_opts.micromips,
4863 INSMSB, insn, va_arg (args, int));
4869 /* Note that in the macro case, these arguments are already
4870 in MSBD form. (When handling the instruction in the
4871 non-macro case, these arguments are sizes from which
4872 MSBD values must be calculated.) */
4873 INSERT_OPERAND (mips_opts.micromips,
4874 EXTMSBD, insn, va_arg (args, int));
4878 gas_assert (!mips_opts.micromips);
4879 INSERT_OPERAND (0, SEQI, insn, va_arg (args, int));
4888 gas_assert (!mips_opts.micromips);
4889 INSERT_OPERAND (0, BP, insn, va_arg (args, int));
4893 gas_assert (mips_opts.micromips);
4897 INSERT_OPERAND (mips_opts.micromips, RT, insn, va_arg (args, int));
4901 gas_assert (!mips_opts.micromips);
4902 INSERT_OPERAND (0, CODE, insn, va_arg (args, int));
4906 gas_assert (!mips_opts.micromips);
4908 INSERT_OPERAND (mips_opts.micromips, FT, insn, va_arg (args, int));
4912 if (mips_opts.micromips)
4913 INSERT_OPERAND (1, RS, insn, va_arg (args, int));
4915 INSERT_OPERAND (0, RD, insn, va_arg (args, int));
4919 gas_assert (!mips_opts.micromips);
4921 INSERT_OPERAND (mips_opts.micromips, RD, insn, va_arg (args, int));
4925 gas_assert (!mips_opts.micromips);
4927 int tmp = va_arg (args, int);
4929 INSERT_OPERAND (0, RT, insn, tmp);
4930 INSERT_OPERAND (0, RD, insn, tmp);
4936 gas_assert (!mips_opts.micromips);
4937 INSERT_OPERAND (0, FS, insn, va_arg (args, int));
4944 INSERT_OPERAND (mips_opts.micromips,
4945 SHAMT, insn, va_arg (args, int));
4949 gas_assert (!mips_opts.micromips);
4950 INSERT_OPERAND (0, FD, insn, va_arg (args, int));
4954 gas_assert (!mips_opts.micromips);
4955 INSERT_OPERAND (0, CODE20, insn, va_arg (args, int));
4959 gas_assert (!mips_opts.micromips);
4960 INSERT_OPERAND (0, CODE19, insn, va_arg (args, int));
4964 gas_assert (!mips_opts.micromips);
4965 INSERT_OPERAND (0, CODE2, insn, va_arg (args, int));
4972 INSERT_OPERAND (mips_opts.micromips, RS, insn, va_arg (args, int));
4977 macro_read_relocs (&args, r);
4978 gas_assert (*r == BFD_RELOC_GPREL16
4979 || *r == BFD_RELOC_MIPS_HIGHER
4980 || *r == BFD_RELOC_HI16_S
4981 || *r == BFD_RELOC_LO16
4982 || *r == BFD_RELOC_MIPS_GOT_OFST);
4986 macro_read_relocs (&args, r);
4990 macro_read_relocs (&args, r);
4991 gas_assert (ep != NULL
4992 && (ep->X_op == O_constant
4993 || (ep->X_op == O_symbol
4994 && (*r == BFD_RELOC_MIPS_HIGHEST
4995 || *r == BFD_RELOC_HI16_S
4996 || *r == BFD_RELOC_HI16
4997 || *r == BFD_RELOC_GPREL16
4998 || *r == BFD_RELOC_MIPS_GOT_HI16
4999 || *r == BFD_RELOC_MIPS_CALL_HI16))));
5003 gas_assert (ep != NULL);
5006 * This allows macro() to pass an immediate expression for
5007 * creating short branches without creating a symbol.
5009 * We don't allow branch relaxation for these branches, as
5010 * they should only appear in ".set nomacro" anyway.
5012 if (ep->X_op == O_constant)
5014 /* For microMIPS we always use relocations for branches.
5015 So we should not resolve immediate values. */
5016 gas_assert (!mips_opts.micromips);
5018 if ((ep->X_add_number & 3) != 0)
5019 as_bad (_("branch to misaligned address (0x%lx)"),
5020 (unsigned long) ep->X_add_number);
5021 if ((ep->X_add_number + 0x20000) & ~0x3ffff)
5022 as_bad (_("branch address range overflow (0x%lx)"),
5023 (unsigned long) ep->X_add_number);
5024 insn.insn_opcode |= (ep->X_add_number >> 2) & 0xffff;
5028 *r = BFD_RELOC_16_PCREL_S2;
5032 gas_assert (ep != NULL);
5033 *r = BFD_RELOC_MIPS_JMP;
5037 gas_assert (!mips_opts.micromips);
5038 INSERT_OPERAND (0, COPZ, insn, va_arg (args, unsigned long));
5042 INSERT_OPERAND (mips_opts.micromips,
5043 CACHE, insn, va_arg (args, unsigned long));
5047 gas_assert (mips_opts.micromips);
5048 INSERT_OPERAND (1, TRAP, insn, va_arg (args, int));
5052 gas_assert (mips_opts.micromips);
5053 INSERT_OPERAND (1, OFFSET10, insn, va_arg (args, int));
5057 INSERT_OPERAND (mips_opts.micromips,
5058 3BITPOS, insn, va_arg (args, unsigned int));
5062 INSERT_OPERAND (mips_opts.micromips,
5063 OFFSET12, insn, va_arg (args, unsigned long));
5067 gas_assert (mips_opts.micromips);
5068 INSERT_OPERAND (1, BCC, insn, va_arg (args, int));
5071 case 'm': /* Opcode extension character. */
5072 gas_assert (mips_opts.micromips);
5076 INSERT_OPERAND (1, MJ, insn, va_arg (args, int));
5080 INSERT_OPERAND (1, MP, insn, va_arg (args, int));
5084 INSERT_OPERAND (1, IMMF, insn, va_arg (args, int));
5098 gas_assert (*r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL);
5100 append_insn (&insn, ep, r, TRUE);
5104 mips16_macro_build (expressionS *ep, const char *name, const char *fmt,
5107 struct mips_opcode *mo;
5108 struct mips_cl_insn insn;
5109 bfd_reloc_code_real_type r[3]
5110 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
5112 mo = (struct mips_opcode *) hash_find (mips16_op_hash, name);
5114 gas_assert (strcmp (name, mo->name) == 0);
5116 while (strcmp (fmt, mo->args) != 0 || mo->pinfo == INSN_MACRO)
5119 gas_assert (mo->name);
5120 gas_assert (strcmp (name, mo->name) == 0);
5123 create_insn (&insn, mo);
5141 MIPS16_INSERT_OPERAND (RY, insn, va_arg (*args, int));
5146 MIPS16_INSERT_OPERAND (RX, insn, va_arg (*args, int));
5150 MIPS16_INSERT_OPERAND (RZ, insn, va_arg (*args, int));
5154 MIPS16_INSERT_OPERAND (MOVE32Z, insn, va_arg (*args, int));
5164 MIPS16_INSERT_OPERAND (REGR32, insn, va_arg (*args, int));
5171 regno = va_arg (*args, int);
5172 regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3);
5173 MIPS16_INSERT_OPERAND (REG32R, insn, regno);
5194 gas_assert (ep != NULL);
5196 if (ep->X_op != O_constant)
5197 *r = (int) BFD_RELOC_UNUSED + c;
5200 mips16_immed (NULL, 0, c, ep->X_add_number, FALSE, FALSE,
5201 FALSE, &insn.insn_opcode, &insn.use_extend,
5204 *r = BFD_RELOC_UNUSED;
5210 MIPS16_INSERT_OPERAND (IMM6, insn, va_arg (*args, int));
5217 gas_assert (*r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL);
5219 append_insn (&insn, ep, r, TRUE);
5223 * Sign-extend 32-bit mode constants that have bit 31 set and all
5224 * higher bits unset.
5227 normalize_constant_expr (expressionS *ex)
5229 if (ex->X_op == O_constant
5230 && IS_ZEXT_32BIT_NUM (ex->X_add_number))
5231 ex->X_add_number = (((ex->X_add_number & 0xffffffff) ^ 0x80000000)
5236 * Sign-extend 32-bit mode address offsets that have bit 31 set and
5237 * all higher bits unset.
5240 normalize_address_expr (expressionS *ex)
5242 if (((ex->X_op == O_constant && HAVE_32BIT_ADDRESSES)
5243 || (ex->X_op == O_symbol && HAVE_32BIT_SYMBOLS))
5244 && IS_ZEXT_32BIT_NUM (ex->X_add_number))
5245 ex->X_add_number = (((ex->X_add_number & 0xffffffff) ^ 0x80000000)
5250 * Generate a "jalr" instruction with a relocation hint to the called
5251 * function. This occurs in NewABI PIC code.
5254 macro_build_jalr (expressionS *ep, int cprestore)
5256 static const bfd_reloc_code_real_type jalr_relocs[2]
5257 = { BFD_RELOC_MIPS_JALR, BFD_RELOC_MICROMIPS_JALR };
5258 bfd_reloc_code_real_type jalr_reloc = jalr_relocs[mips_opts.micromips];
5262 if (MIPS_JALR_HINT_P (ep))
5267 if (mips_opts.micromips)
5269 jalr = mips_opts.noreorder && !cprestore ? "jalr" : "jalrs";
5270 if (MIPS_JALR_HINT_P (ep))
5271 macro_build (NULL, jalr, "t,s", RA, PIC_CALL_REG);
5273 macro_build (NULL, jalr, "mj", PIC_CALL_REG);
5276 macro_build (NULL, "jalr", "d,s", RA, PIC_CALL_REG);
5277 if (MIPS_JALR_HINT_P (ep))
5278 fix_new_exp (frag_now, f - frag_now->fr_literal, 4, ep, FALSE, jalr_reloc);
5282 * Generate a "lui" instruction.
5285 macro_build_lui (expressionS *ep, int regnum)
5287 gas_assert (! mips_opts.mips16);
5289 if (ep->X_op != O_constant)
5291 gas_assert (ep->X_op == O_symbol);
5292 /* _gp_disp is a special case, used from s_cpload.
5293 __gnu_local_gp is used if mips_no_shared. */
5294 gas_assert (mips_pic == NO_PIC
5296 && strcmp (S_GET_NAME (ep->X_add_symbol), "_gp_disp") == 0)
5297 || (! mips_in_shared
5298 && strcmp (S_GET_NAME (ep->X_add_symbol),
5299 "__gnu_local_gp") == 0));
5302 macro_build (ep, "lui", LUI_FMT, regnum, BFD_RELOC_HI16_S);
5305 /* Generate a sequence of instructions to do a load or store from a constant
5306 offset off of a base register (breg) into/from a target register (treg),
5307 using AT if necessary. */
5309 macro_build_ldst_constoffset (expressionS *ep, const char *op,
5310 int treg, int breg, int dbl)
5312 gas_assert (ep->X_op == O_constant);
5314 /* Sign-extending 32-bit constants makes their handling easier. */
5316 normalize_constant_expr (ep);
5318 /* Right now, this routine can only handle signed 32-bit constants. */
5319 if (! IS_SEXT_32BIT_NUM(ep->X_add_number + 0x8000))
5320 as_warn (_("operand overflow"));
5322 if (IS_SEXT_16BIT_NUM(ep->X_add_number))
5324 /* Signed 16-bit offset will fit in the op. Easy! */
5325 macro_build (ep, op, "t,o(b)", treg, BFD_RELOC_LO16, breg);
5329 /* 32-bit offset, need multiple instructions and AT, like:
5330 lui $tempreg,const_hi (BFD_RELOC_HI16_S)
5331 addu $tempreg,$tempreg,$breg
5332 <op> $treg,const_lo($tempreg) (BFD_RELOC_LO16)
5333 to handle the complete offset. */
5334 macro_build_lui (ep, AT);
5335 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, AT, breg);
5336 macro_build (ep, op, "t,o(b)", treg, BFD_RELOC_LO16, AT);
5339 as_bad (_("Macro used $at after \".set noat\""));
5344 * Generates code to set the $at register to true (one)
5345 * if reg is less than the immediate expression.
5348 set_at (int reg, int unsignedp)
5350 if (imm_expr.X_op == O_constant
5351 && imm_expr.X_add_number >= -0x8000
5352 && imm_expr.X_add_number < 0x8000)
5353 macro_build (&imm_expr, unsignedp ? "sltiu" : "slti", "t,r,j",
5354 AT, reg, BFD_RELOC_LO16);
5357 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
5358 macro_build (NULL, unsignedp ? "sltu" : "slt", "d,v,t", AT, reg, AT);
5362 /* Warn if an expression is not a constant. */
5365 check_absolute_expr (struct mips_cl_insn *ip, expressionS *ex)
5367 if (ex->X_op == O_big)
5368 as_bad (_("unsupported large constant"));
5369 else if (ex->X_op != O_constant)
5370 as_bad (_("Instruction %s requires absolute expression"),
5373 if (HAVE_32BIT_GPRS)
5374 normalize_constant_expr (ex);
5377 /* Count the leading zeroes by performing a binary chop. This is a
5378 bulky bit of source, but performance is a LOT better for the
5379 majority of values than a simple loop to count the bits:
5380 for (lcnt = 0; (lcnt < 32); lcnt++)
5381 if ((v) & (1 << (31 - lcnt)))
5383 However it is not code size friendly, and the gain will drop a bit
5384 on certain cached systems.
5386 #define COUNT_TOP_ZEROES(v) \
5387 (((v) & ~0xffff) == 0 \
5388 ? ((v) & ~0xff) == 0 \
5389 ? ((v) & ~0xf) == 0 \
5390 ? ((v) & ~0x3) == 0 \
5391 ? ((v) & ~0x1) == 0 \
5396 : ((v) & ~0x7) == 0 \
5399 : ((v) & ~0x3f) == 0 \
5400 ? ((v) & ~0x1f) == 0 \
5403 : ((v) & ~0x7f) == 0 \
5406 : ((v) & ~0xfff) == 0 \
5407 ? ((v) & ~0x3ff) == 0 \
5408 ? ((v) & ~0x1ff) == 0 \
5411 : ((v) & ~0x7ff) == 0 \
5414 : ((v) & ~0x3fff) == 0 \
5415 ? ((v) & ~0x1fff) == 0 \
5418 : ((v) & ~0x7fff) == 0 \
5421 : ((v) & ~0xffffff) == 0 \
5422 ? ((v) & ~0xfffff) == 0 \
5423 ? ((v) & ~0x3ffff) == 0 \
5424 ? ((v) & ~0x1ffff) == 0 \
5427 : ((v) & ~0x7ffff) == 0 \
5430 : ((v) & ~0x3fffff) == 0 \
5431 ? ((v) & ~0x1fffff) == 0 \
5434 : ((v) & ~0x7fffff) == 0 \
5437 : ((v) & ~0xfffffff) == 0 \
5438 ? ((v) & ~0x3ffffff) == 0 \
5439 ? ((v) & ~0x1ffffff) == 0 \
5442 : ((v) & ~0x7ffffff) == 0 \
5445 : ((v) & ~0x3fffffff) == 0 \
5446 ? ((v) & ~0x1fffffff) == 0 \
5449 : ((v) & ~0x7fffffff) == 0 \
5454 * This routine generates the least number of instructions necessary to load
5455 * an absolute expression value into a register.
5458 load_register (int reg, expressionS *ep, int dbl)
5461 expressionS hi32, lo32;
5463 if (ep->X_op != O_big)
5465 gas_assert (ep->X_op == O_constant);
5467 /* Sign-extending 32-bit constants makes their handling easier. */
5469 normalize_constant_expr (ep);
5471 if (IS_SEXT_16BIT_NUM (ep->X_add_number))
5473 /* We can handle 16 bit signed values with an addiu to
5474 $zero. No need to ever use daddiu here, since $zero and
5475 the result are always correct in 32 bit mode. */
5476 macro_build (ep, "addiu", "t,r,j", reg, 0, BFD_RELOC_LO16);
5479 else if (ep->X_add_number >= 0 && ep->X_add_number < 0x10000)
5481 /* We can handle 16 bit unsigned values with an ori to
5483 macro_build (ep, "ori", "t,r,i", reg, 0, BFD_RELOC_LO16);
5486 else if ((IS_SEXT_32BIT_NUM (ep->X_add_number)))
5488 /* 32 bit values require an lui. */
5489 macro_build (ep, "lui", LUI_FMT, reg, BFD_RELOC_HI16);
5490 if ((ep->X_add_number & 0xffff) != 0)
5491 macro_build (ep, "ori", "t,r,i", reg, reg, BFD_RELOC_LO16);
5496 /* The value is larger than 32 bits. */
5498 if (!dbl || HAVE_32BIT_GPRS)
5502 sprintf_vma (value, ep->X_add_number);
5503 as_bad (_("Number (0x%s) larger than 32 bits"), value);
5504 macro_build (ep, "addiu", "t,r,j", reg, 0, BFD_RELOC_LO16);
5508 if (ep->X_op != O_big)
5511 hi32.X_add_number = (valueT) hi32.X_add_number >> 16;
5512 hi32.X_add_number = (valueT) hi32.X_add_number >> 16;
5513 hi32.X_add_number &= 0xffffffff;
5515 lo32.X_add_number &= 0xffffffff;
5519 gas_assert (ep->X_add_number > 2);
5520 if (ep->X_add_number == 3)
5521 generic_bignum[3] = 0;
5522 else if (ep->X_add_number > 4)
5523 as_bad (_("Number larger than 64 bits"));
5524 lo32.X_op = O_constant;
5525 lo32.X_add_number = generic_bignum[0] + (generic_bignum[1] << 16);
5526 hi32.X_op = O_constant;
5527 hi32.X_add_number = generic_bignum[2] + (generic_bignum[3] << 16);
5530 if (hi32.X_add_number == 0)
5535 unsigned long hi, lo;
5537 if (hi32.X_add_number == (offsetT) 0xffffffff)
5539 if ((lo32.X_add_number & 0xffff8000) == 0xffff8000)
5541 macro_build (&lo32, "addiu", "t,r,j", reg, 0, BFD_RELOC_LO16);
5544 if (lo32.X_add_number & 0x80000000)
5546 macro_build (&lo32, "lui", LUI_FMT, reg, BFD_RELOC_HI16);
5547 if (lo32.X_add_number & 0xffff)
5548 macro_build (&lo32, "ori", "t,r,i", reg, reg, BFD_RELOC_LO16);
5553 /* Check for 16bit shifted constant. We know that hi32 is
5554 non-zero, so start the mask on the first bit of the hi32
5559 unsigned long himask, lomask;
5563 himask = 0xffff >> (32 - shift);
5564 lomask = (0xffff << shift) & 0xffffffff;
5568 himask = 0xffff << (shift - 32);
5571 if ((hi32.X_add_number & ~(offsetT) himask) == 0
5572 && (lo32.X_add_number & ~(offsetT) lomask) == 0)
5576 tmp.X_op = O_constant;
5578 tmp.X_add_number = ((hi32.X_add_number << (32 - shift))
5579 | (lo32.X_add_number >> shift));
5581 tmp.X_add_number = hi32.X_add_number >> (shift - 32);
5582 macro_build (&tmp, "ori", "t,r,i", reg, 0, BFD_RELOC_LO16);
5583 macro_build (NULL, (shift >= 32) ? "dsll32" : "dsll", SHFT_FMT,
5584 reg, reg, (shift >= 32) ? shift - 32 : shift);
5589 while (shift <= (64 - 16));
5591 /* Find the bit number of the lowest one bit, and store the
5592 shifted value in hi/lo. */
5593 hi = (unsigned long) (hi32.X_add_number & 0xffffffff);
5594 lo = (unsigned long) (lo32.X_add_number & 0xffffffff);
5598 while ((lo & 1) == 0)
5603 lo |= (hi & (((unsigned long) 1 << bit) - 1)) << (32 - bit);
5609 while ((hi & 1) == 0)
5618 /* Optimize if the shifted value is a (power of 2) - 1. */
5619 if ((hi == 0 && ((lo + 1) & lo) == 0)
5620 || (lo == 0xffffffff && ((hi + 1) & hi) == 0))
5622 shift = COUNT_TOP_ZEROES ((unsigned int) hi32.X_add_number);
5627 /* This instruction will set the register to be all
5629 tmp.X_op = O_constant;
5630 tmp.X_add_number = (offsetT) -1;
5631 macro_build (&tmp, "addiu", "t,r,j", reg, 0, BFD_RELOC_LO16);
5635 macro_build (NULL, (bit >= 32) ? "dsll32" : "dsll", SHFT_FMT,
5636 reg, reg, (bit >= 32) ? bit - 32 : bit);
5638 macro_build (NULL, (shift >= 32) ? "dsrl32" : "dsrl", SHFT_FMT,
5639 reg, reg, (shift >= 32) ? shift - 32 : shift);
5644 /* Sign extend hi32 before calling load_register, because we can
5645 generally get better code when we load a sign extended value. */
5646 if ((hi32.X_add_number & 0x80000000) != 0)
5647 hi32.X_add_number |= ~(offsetT) 0xffffffff;
5648 load_register (reg, &hi32, 0);
5651 if ((lo32.X_add_number & 0xffff0000) == 0)
5655 macro_build (NULL, "dsll32", SHFT_FMT, reg, freg, 0);
5663 if ((freg == 0) && (lo32.X_add_number == (offsetT) 0xffffffff))
5665 macro_build (&lo32, "lui", LUI_FMT, reg, BFD_RELOC_HI16);
5666 macro_build (NULL, "dsrl32", SHFT_FMT, reg, reg, 0);
5672 macro_build (NULL, "dsll", SHFT_FMT, reg, freg, 16);
5676 mid16.X_add_number >>= 16;
5677 macro_build (&mid16, "ori", "t,r,i", reg, freg, BFD_RELOC_LO16);
5678 macro_build (NULL, "dsll", SHFT_FMT, reg, reg, 16);
5681 if ((lo32.X_add_number & 0xffff) != 0)
5682 macro_build (&lo32, "ori", "t,r,i", reg, freg, BFD_RELOC_LO16);
5686 load_delay_nop (void)
5688 if (!gpr_interlocks)
5689 macro_build (NULL, "nop", "");
5692 /* Load an address into a register. */
5695 load_address (int reg, expressionS *ep, int *used_at)
5697 if (ep->X_op != O_constant
5698 && ep->X_op != O_symbol)
5700 as_bad (_("expression too complex"));
5701 ep->X_op = O_constant;
5704 if (ep->X_op == O_constant)
5706 load_register (reg, ep, HAVE_64BIT_ADDRESSES);
5710 if (mips_pic == NO_PIC)
5712 /* If this is a reference to a GP relative symbol, we want
5713 addiu $reg,$gp,<sym> (BFD_RELOC_GPREL16)
5715 lui $reg,<sym> (BFD_RELOC_HI16_S)
5716 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
5717 If we have an addend, we always use the latter form.
5719 With 64bit address space and a usable $at we want
5720 lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5721 lui $at,<sym> (BFD_RELOC_HI16_S)
5722 daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER)
5723 daddiu $at,<sym> (BFD_RELOC_LO16)
5727 If $at is already in use, we use a path which is suboptimal
5728 on superscalar processors.
5729 lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5730 daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER)
5732 daddiu $reg,<sym> (BFD_RELOC_HI16_S)
5734 daddiu $reg,<sym> (BFD_RELOC_LO16)
5736 For GP relative symbols in 64bit address space we can use
5737 the same sequence as in 32bit address space. */
5738 if (HAVE_64BIT_SYMBOLS)
5740 if ((valueT) ep->X_add_number <= MAX_GPREL_OFFSET
5741 && !nopic_need_relax (ep->X_add_symbol, 1))
5743 relax_start (ep->X_add_symbol);
5744 macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", reg,
5745 mips_gp_register, BFD_RELOC_GPREL16);
5749 if (*used_at == 0 && mips_opts.at)
5751 macro_build (ep, "lui", LUI_FMT, reg, BFD_RELOC_MIPS_HIGHEST);
5752 macro_build (ep, "lui", LUI_FMT, AT, BFD_RELOC_HI16_S);
5753 macro_build (ep, "daddiu", "t,r,j", reg, reg,
5754 BFD_RELOC_MIPS_HIGHER);
5755 macro_build (ep, "daddiu", "t,r,j", AT, AT, BFD_RELOC_LO16);
5756 macro_build (NULL, "dsll32", SHFT_FMT, reg, reg, 0);
5757 macro_build (NULL, "daddu", "d,v,t", reg, reg, AT);
5762 macro_build (ep, "lui", LUI_FMT, reg, BFD_RELOC_MIPS_HIGHEST);
5763 macro_build (ep, "daddiu", "t,r,j", reg, reg,
5764 BFD_RELOC_MIPS_HIGHER);
5765 macro_build (NULL, "dsll", SHFT_FMT, reg, reg, 16);
5766 macro_build (ep, "daddiu", "t,r,j", reg, reg, BFD_RELOC_HI16_S);
5767 macro_build (NULL, "dsll", SHFT_FMT, reg, reg, 16);
5768 macro_build (ep, "daddiu", "t,r,j", reg, reg, BFD_RELOC_LO16);
5771 if (mips_relax.sequence)
5776 if ((valueT) ep->X_add_number <= MAX_GPREL_OFFSET
5777 && !nopic_need_relax (ep->X_add_symbol, 1))
5779 relax_start (ep->X_add_symbol);
5780 macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", reg,
5781 mips_gp_register, BFD_RELOC_GPREL16);
5784 macro_build_lui (ep, reg);
5785 macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j",
5786 reg, reg, BFD_RELOC_LO16);
5787 if (mips_relax.sequence)
5791 else if (!mips_big_got)
5795 /* If this is a reference to an external symbol, we want
5796 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5798 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5800 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
5801 If there is a constant, it must be added in after.
5803 If we have NewABI, we want
5804 lw $reg,<sym+cst>($gp) (BFD_RELOC_MIPS_GOT_DISP)
5805 unless we're referencing a global symbol with a non-zero
5806 offset, in which case cst must be added separately. */
5809 if (ep->X_add_number)
5811 ex.X_add_number = ep->X_add_number;
5812 ep->X_add_number = 0;
5813 relax_start (ep->X_add_symbol);
5814 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
5815 BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
5816 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
5817 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
5818 ex.X_op = O_constant;
5819 macro_build (&ex, ADDRESS_ADDI_INSN, "t,r,j",
5820 reg, reg, BFD_RELOC_LO16);
5821 ep->X_add_number = ex.X_add_number;
5824 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
5825 BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
5826 if (mips_relax.sequence)
5831 ex.X_add_number = ep->X_add_number;
5832 ep->X_add_number = 0;
5833 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
5834 BFD_RELOC_MIPS_GOT16, mips_gp_register);
5836 relax_start (ep->X_add_symbol);
5838 macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", reg, reg,
5842 if (ex.X_add_number != 0)
5844 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
5845 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
5846 ex.X_op = O_constant;
5847 macro_build (&ex, ADDRESS_ADDI_INSN, "t,r,j",
5848 reg, reg, BFD_RELOC_LO16);
5852 else if (mips_big_got)
5856 /* This is the large GOT case. If this is a reference to an
5857 external symbol, we want
5858 lui $reg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5860 lw $reg,<sym>($reg) (BFD_RELOC_MIPS_GOT_LO16)
5862 Otherwise, for a reference to a local symbol in old ABI, we want
5863 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5865 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
5866 If there is a constant, it must be added in after.
5868 In the NewABI, for local symbols, with or without offsets, we want:
5869 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
5870 addiu $reg,$reg,<sym> (BFD_RELOC_MIPS_GOT_OFST)
5874 ex.X_add_number = ep->X_add_number;
5875 ep->X_add_number = 0;
5876 relax_start (ep->X_add_symbol);
5877 macro_build (ep, "lui", LUI_FMT, reg, BFD_RELOC_MIPS_GOT_HI16);
5878 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
5879 reg, reg, mips_gp_register);
5880 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)",
5881 reg, BFD_RELOC_MIPS_GOT_LO16, reg);
5882 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
5883 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
5884 else if (ex.X_add_number)
5886 ex.X_op = O_constant;
5887 macro_build (&ex, ADDRESS_ADDI_INSN, "t,r,j", reg, reg,
5891 ep->X_add_number = ex.X_add_number;
5893 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
5894 BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register);
5895 macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", reg, reg,
5896 BFD_RELOC_MIPS_GOT_OFST);
5901 ex.X_add_number = ep->X_add_number;
5902 ep->X_add_number = 0;
5903 relax_start (ep->X_add_symbol);
5904 macro_build (ep, "lui", LUI_FMT, reg, BFD_RELOC_MIPS_GOT_HI16);
5905 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
5906 reg, reg, mips_gp_register);
5907 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)",
5908 reg, BFD_RELOC_MIPS_GOT_LO16, reg);
5910 if (reg_needs_delay (mips_gp_register))
5912 /* We need a nop before loading from $gp. This special
5913 check is required because the lui which starts the main
5914 instruction stream does not refer to $gp, and so will not
5915 insert the nop which may be required. */
5916 macro_build (NULL, "nop", "");
5918 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
5919 BFD_RELOC_MIPS_GOT16, mips_gp_register);
5921 macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", reg, reg,
5925 if (ex.X_add_number != 0)
5927 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
5928 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
5929 ex.X_op = O_constant;
5930 macro_build (&ex, ADDRESS_ADDI_INSN, "t,r,j", reg, reg,
5938 if (!mips_opts.at && *used_at == 1)
5939 as_bad (_("Macro used $at after \".set noat\""));
5942 /* Move the contents of register SOURCE into register DEST. */
5945 move_register (int dest, int source)
5947 /* Prefer to use a 16-bit microMIPS instruction unless the previous
5948 instruction specifically requires a 32-bit one. */
5949 if (mips_opts.micromips
5950 && !(history[0].insn_mo->pinfo2 & INSN2_BRANCH_DELAY_32BIT))
5951 macro_build (NULL, "move", "mp,mj", dest, source);
5953 macro_build (NULL, HAVE_32BIT_GPRS ? "addu" : "daddu", "d,v,t",
5957 /* Emit an SVR4 PIC sequence to load address LOCAL into DEST, where
5958 LOCAL is the sum of a symbol and a 16-bit or 32-bit displacement.
5959 The two alternatives are:
5961 Global symbol Local sybmol
5962 ------------- ------------
5963 lw DEST,%got(SYMBOL) lw DEST,%got(SYMBOL + OFFSET)
5965 addiu DEST,DEST,OFFSET addiu DEST,DEST,%lo(SYMBOL + OFFSET)
5967 load_got_offset emits the first instruction and add_got_offset
5968 emits the second for a 16-bit offset or add_got_offset_hilo emits
5969 a sequence to add a 32-bit offset using a scratch register. */
5972 load_got_offset (int dest, expressionS *local)
5977 global.X_add_number = 0;
5979 relax_start (local->X_add_symbol);
5980 macro_build (&global, ADDRESS_LOAD_INSN, "t,o(b)", dest,
5981 BFD_RELOC_MIPS_GOT16, mips_gp_register);
5983 macro_build (local, ADDRESS_LOAD_INSN, "t,o(b)", dest,
5984 BFD_RELOC_MIPS_GOT16, mips_gp_register);
5989 add_got_offset (int dest, expressionS *local)
5993 global.X_op = O_constant;
5994 global.X_op_symbol = NULL;
5995 global.X_add_symbol = NULL;
5996 global.X_add_number = local->X_add_number;
5998 relax_start (local->X_add_symbol);
5999 macro_build (&global, ADDRESS_ADDI_INSN, "t,r,j",
6000 dest, dest, BFD_RELOC_LO16);
6002 macro_build (local, ADDRESS_ADDI_INSN, "t,r,j", dest, dest, BFD_RELOC_LO16);
6007 add_got_offset_hilo (int dest, expressionS *local, int tmp)
6010 int hold_mips_optimize;
6012 global.X_op = O_constant;
6013 global.X_op_symbol = NULL;
6014 global.X_add_symbol = NULL;
6015 global.X_add_number = local->X_add_number;
6017 relax_start (local->X_add_symbol);
6018 load_register (tmp, &global, HAVE_64BIT_ADDRESSES);
6020 /* Set mips_optimize around the lui instruction to avoid
6021 inserting an unnecessary nop after the lw. */
6022 hold_mips_optimize = mips_optimize;
6024 macro_build_lui (&global, tmp);
6025 mips_optimize = hold_mips_optimize;
6026 macro_build (local, ADDRESS_ADDI_INSN, "t,r,j", tmp, tmp, BFD_RELOC_LO16);
6029 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", dest, dest, tmp);
6032 /* Emit a sequence of instructions to emulate a branch likely operation.
6033 BR is an ordinary branch corresponding to one to be emulated. BRNEG
6034 is its complementing branch with the original condition negated.
6035 CALL is set if the original branch specified the link operation.
6036 EP, FMT, SREG and TREG specify the usual macro_build() parameters.
6038 Code like this is produced in the noreorder mode:
6043 delay slot (executed only if branch taken)
6051 delay slot (executed only if branch taken)
6054 In the reorder mode the delay slot would be filled with a nop anyway,
6055 so code produced is simply:
6060 This function is used when producing code for the microMIPS ASE that
6061 does not implement branch likely instructions in hardware. */
6064 macro_build_branch_likely (const char *br, const char *brneg,
6065 int call, expressionS *ep, const char *fmt,
6066 unsigned int sreg, unsigned int treg)
6068 int noreorder = mips_opts.noreorder;
6071 gas_assert (mips_opts.micromips);
6075 micromips_label_expr (&expr1);
6076 macro_build (&expr1, brneg, fmt, sreg, treg);
6077 macro_build (NULL, "nop", "");
6078 macro_build (ep, call ? "bal" : "b", "p");
6080 /* Set to true so that append_insn adds a label. */
6081 emit_branch_likely_macro = TRUE;
6085 macro_build (ep, br, fmt, sreg, treg);
6086 macro_build (NULL, "nop", "");
6091 /* Emit a coprocessor branch-likely macro specified by TYPE, using CC as
6092 the condition code tested. EP specifies the branch target. */
6095 macro_build_branch_ccl (int type, expressionS *ep, unsigned int cc)
6122 macro_build_branch_likely (br, brneg, call, ep, "N,p", cc, ZERO);
6125 /* Emit a two-argument branch macro specified by TYPE, using SREG as
6126 the register tested. EP specifies the branch target. */
6129 macro_build_branch_rs (int type, expressionS *ep, unsigned int sreg)
6131 const char *brneg = NULL;
6141 br = mips_opts.micromips ? "bgez" : "bgezl";
6145 gas_assert (mips_opts.micromips);
6154 br = mips_opts.micromips ? "bgtz" : "bgtzl";
6161 br = mips_opts.micromips ? "blez" : "blezl";
6168 br = mips_opts.micromips ? "bltz" : "bltzl";
6172 gas_assert (mips_opts.micromips);
6180 if (mips_opts.micromips && brneg)
6181 macro_build_branch_likely (br, brneg, call, ep, "s,p", sreg, ZERO);
6183 macro_build (ep, br, "s,p", sreg);
6186 /* Emit a three-argument branch macro specified by TYPE, using SREG and
6187 TREG as the registers tested. EP specifies the branch target. */
6190 macro_build_branch_rsrt (int type, expressionS *ep,
6191 unsigned int sreg, unsigned int treg)
6193 const char *brneg = NULL;
6205 br = mips_opts.micromips ? "beq" : "beql";
6214 br = mips_opts.micromips ? "bne" : "bnel";
6220 if (mips_opts.micromips && brneg)
6221 macro_build_branch_likely (br, brneg, call, ep, "s,t,p", sreg, treg);
6223 macro_build (ep, br, "s,t,p", sreg, treg);
6228 * This routine implements the seemingly endless macro or synthesized
6229 * instructions and addressing modes in the mips assembly language. Many
6230 * of these macros are simple and are similar to each other. These could
6231 * probably be handled by some kind of table or grammar approach instead of
6232 * this verbose method. Others are not simple macros but are more like
6233 * optimizing code generation.
6234 * One interesting optimization is when several store macros appear
6235 * consecutively that would load AT with the upper half of the same address.
6236 * The ensuing load upper instructions are ommited. This implies some kind
6237 * of global optimization. We currently only optimize within a single macro.
6238 * For many of the load and store macros if the address is specified as a
6239 * constant expression in the first 64k of memory (ie ld $2,0x4000c) we
6240 * first load register 'at' with zero and use it as the base register. The
6241 * mips assembler simply uses register $zero. Just one tiny optimization
6245 macro (struct mips_cl_insn *ip)
6247 unsigned int treg, sreg, dreg, breg;
6248 unsigned int tempreg;
6251 expressionS label_expr;
6270 bfd_reloc_code_real_type r;
6271 int hold_mips_optimize;
6273 gas_assert (! mips_opts.mips16);
6275 treg = EXTRACT_OPERAND (mips_opts.micromips, RT, *ip);
6276 dreg = EXTRACT_OPERAND (mips_opts.micromips, RD, *ip);
6277 sreg = breg = EXTRACT_OPERAND (mips_opts.micromips, RS, *ip);
6278 mask = ip->insn_mo->mask;
6280 label_expr.X_op = O_constant;
6281 label_expr.X_op_symbol = NULL;
6282 label_expr.X_add_symbol = NULL;
6283 label_expr.X_add_number = 0;
6285 expr1.X_op = O_constant;
6286 expr1.X_op_symbol = NULL;
6287 expr1.X_add_symbol = NULL;
6288 expr1.X_add_number = 1;
6303 if (mips_opts.micromips)
6304 micromips_label_expr (&label_expr);
6306 label_expr.X_add_number = 8;
6307 macro_build (&label_expr, "bgez", "s,p", sreg);
6309 macro_build (NULL, "nop", "");
6311 move_register (dreg, sreg);
6312 macro_build (NULL, dbl ? "dsub" : "sub", "d,v,t", dreg, 0, sreg);
6313 if (mips_opts.micromips)
6314 micromips_add_label ();
6331 if (!mips_opts.micromips)
6333 if (imm_expr.X_op == O_constant
6334 && imm_expr.X_add_number >= -0x200
6335 && imm_expr.X_add_number < 0x200)
6337 macro_build (NULL, s, "t,r,.", treg, sreg, imm_expr.X_add_number);
6346 if (imm_expr.X_op == O_constant
6347 && imm_expr.X_add_number >= -0x8000
6348 && imm_expr.X_add_number < 0x8000)
6350 macro_build (&imm_expr, s, "t,r,j", treg, sreg, BFD_RELOC_LO16);
6355 load_register (AT, &imm_expr, dbl);
6356 macro_build (NULL, s2, "d,v,t", treg, sreg, AT);
6375 if (imm_expr.X_op == O_constant
6376 && imm_expr.X_add_number >= 0
6377 && imm_expr.X_add_number < 0x10000)
6379 if (mask != M_NOR_I)
6380 macro_build (&imm_expr, s, "t,r,i", treg, sreg, BFD_RELOC_LO16);
6383 macro_build (&imm_expr, "ori", "t,r,i",
6384 treg, sreg, BFD_RELOC_LO16);
6385 macro_build (NULL, "nor", "d,v,t", treg, treg, 0);
6391 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
6392 macro_build (NULL, s2, "d,v,t", treg, sreg, AT);
6396 switch (imm_expr.X_add_number)
6399 macro_build (NULL, "nop", "");
6402 macro_build (NULL, "packrl.ph", "d,s,t", treg, treg, sreg);
6405 macro_build (NULL, "balign", "t,s,2", treg, sreg,
6406 (int) imm_expr.X_add_number);
6415 gas_assert (mips_opts.micromips);
6416 macro_build_branch_ccl (mask, &offset_expr,
6417 EXTRACT_OPERAND (1, BCC, *ip));
6424 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
6430 load_register (treg, &imm_expr, HAVE_64BIT_GPRS);
6435 macro_build_branch_rsrt (mask, &offset_expr, sreg, treg);
6442 macro_build_branch_rs (likely ? M_BGEZL : M_BGEZ, &offset_expr, sreg);
6444 macro_build_branch_rs (likely ? M_BLEZL : M_BLEZ, &offset_expr, treg);
6448 macro_build (NULL, "slt", "d,v,t", AT, sreg, treg);
6449 macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ,
6450 &offset_expr, AT, ZERO);
6460 macro_build_branch_rs (mask, &offset_expr, sreg);
6466 /* Check for > max integer. */
6467 maxnum = 0x7fffffff;
6468 if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4)
6475 if (imm_expr.X_op == O_constant
6476 && imm_expr.X_add_number >= maxnum
6477 && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4))
6480 /* Result is always false. */
6482 macro_build (NULL, "nop", "");
6484 macro_build_branch_rsrt (M_BNEL, &offset_expr, ZERO, ZERO);
6487 if (imm_expr.X_op != O_constant)
6488 as_bad (_("Unsupported large constant"));
6489 ++imm_expr.X_add_number;
6493 if (mask == M_BGEL_I)
6495 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
6497 macro_build_branch_rs (likely ? M_BGEZL : M_BGEZ,
6498 &offset_expr, sreg);
6501 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
6503 macro_build_branch_rs (likely ? M_BGTZL : M_BGTZ,
6504 &offset_expr, sreg);
6507 maxnum = 0x7fffffff;
6508 if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4)
6515 maxnum = - maxnum - 1;
6516 if (imm_expr.X_op == O_constant
6517 && imm_expr.X_add_number <= maxnum
6518 && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4))
6521 /* result is always true */
6522 as_warn (_("Branch %s is always true"), ip->insn_mo->name);
6523 macro_build (&offset_expr, "b", "p");
6528 macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ,
6529 &offset_expr, AT, ZERO);
6538 macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ,
6539 &offset_expr, ZERO, treg);
6543 macro_build (NULL, "sltu", "d,v,t", AT, sreg, treg);
6544 macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ,
6545 &offset_expr, AT, ZERO);
6554 && imm_expr.X_op == O_constant
6555 && imm_expr.X_add_number == -1))
6557 if (imm_expr.X_op != O_constant)
6558 as_bad (_("Unsupported large constant"));
6559 ++imm_expr.X_add_number;
6563 if (mask == M_BGEUL_I)
6565 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
6567 else if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
6568 macro_build_branch_rsrt (likely ? M_BNEL : M_BNE,
6569 &offset_expr, sreg, ZERO);
6574 macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ,
6575 &offset_expr, AT, ZERO);
6583 macro_build_branch_rs (likely ? M_BGTZL : M_BGTZ, &offset_expr, sreg);
6585 macro_build_branch_rs (likely ? M_BLTZL : M_BLTZ, &offset_expr, treg);
6589 macro_build (NULL, "slt", "d,v,t", AT, treg, sreg);
6590 macro_build_branch_rsrt (likely ? M_BNEL : M_BNE,
6591 &offset_expr, AT, ZERO);
6599 macro_build_branch_rsrt (likely ? M_BNEL : M_BNE,
6600 &offset_expr, sreg, ZERO);
6606 macro_build (NULL, "sltu", "d,v,t", AT, treg, sreg);
6607 macro_build_branch_rsrt (likely ? M_BNEL : M_BNE,
6608 &offset_expr, AT, ZERO);
6616 macro_build_branch_rs (likely ? M_BLEZL : M_BLEZ, &offset_expr, sreg);
6618 macro_build_branch_rs (likely ? M_BGEZL : M_BGEZ, &offset_expr, treg);
6622 macro_build (NULL, "slt", "d,v,t", AT, treg, sreg);
6623 macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ,
6624 &offset_expr, AT, ZERO);
6631 maxnum = 0x7fffffff;
6632 if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4)
6639 if (imm_expr.X_op == O_constant
6640 && imm_expr.X_add_number >= maxnum
6641 && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4))
6643 if (imm_expr.X_op != O_constant)
6644 as_bad (_("Unsupported large constant"));
6645 ++imm_expr.X_add_number;
6649 if (mask == M_BLTL_I)
6651 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
6652 macro_build_branch_rs (likely ? M_BLTZL : M_BLTZ, &offset_expr, sreg);
6653 else if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
6654 macro_build_branch_rs (likely ? M_BLEZL : M_BLEZ, &offset_expr, sreg);
6659 macro_build_branch_rsrt (likely ? M_BNEL : M_BNE,
6660 &offset_expr, AT, ZERO);
6668 macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ,
6669 &offset_expr, sreg, ZERO);
6675 macro_build (NULL, "sltu", "d,v,t", AT, treg, sreg);
6676 macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ,
6677 &offset_expr, AT, ZERO);
6686 && imm_expr.X_op == O_constant
6687 && imm_expr.X_add_number == -1))
6689 if (imm_expr.X_op != O_constant)
6690 as_bad (_("Unsupported large constant"));
6691 ++imm_expr.X_add_number;
6695 if (mask == M_BLTUL_I)
6697 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
6699 else if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
6700 macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ,
6701 &offset_expr, sreg, ZERO);
6706 macro_build_branch_rsrt (likely ? M_BNEL : M_BNE,
6707 &offset_expr, AT, ZERO);
6715 macro_build_branch_rs (likely ? M_BLTZL : M_BLTZ, &offset_expr, sreg);
6717 macro_build_branch_rs (likely ? M_BGTZL : M_BGTZ, &offset_expr, treg);
6721 macro_build (NULL, "slt", "d,v,t", AT, sreg, treg);
6722 macro_build_branch_rsrt (likely ? M_BNEL : M_BNE,
6723 &offset_expr, AT, ZERO);
6733 macro_build_branch_rsrt (likely ? M_BNEL : M_BNE,
6734 &offset_expr, ZERO, treg);
6738 macro_build (NULL, "sltu", "d,v,t", AT, sreg, treg);
6739 macro_build_branch_rsrt (likely ? M_BNEL : M_BNE,
6740 &offset_expr, AT, ZERO);
6746 /* Use unsigned arithmetic. */
6750 if (imm_expr.X_op != O_constant || imm2_expr.X_op != O_constant)
6752 as_bad (_("Unsupported large constant"));
6757 pos = imm_expr.X_add_number;
6758 size = imm2_expr.X_add_number;
6763 as_bad (_("Improper position (%lu)"), (unsigned long) pos);
6766 if (size == 0 || size > 64 || (pos + size - 1) > 63)
6768 as_bad (_("Improper extract size (%lu, position %lu)"),
6769 (unsigned long) size, (unsigned long) pos);
6773 if (size <= 32 && pos < 32)
6778 else if (size <= 32)
6788 macro_build ((expressionS *) NULL, s, fmt, treg, sreg, (int) pos,
6795 /* Use unsigned arithmetic. */
6799 if (imm_expr.X_op != O_constant || imm2_expr.X_op != O_constant)
6801 as_bad (_("Unsupported large constant"));
6806 pos = imm_expr.X_add_number;
6807 size = imm2_expr.X_add_number;
6812 as_bad (_("Improper position (%lu)"), (unsigned long) pos);
6815 if (size == 0 || size > 64 || (pos + size - 1) > 63)
6817 as_bad (_("Improper insert size (%lu, position %lu)"),
6818 (unsigned long) size, (unsigned long) pos);
6822 if (pos < 32 && (pos + size - 1) < 32)
6837 macro_build ((expressionS *) NULL, s, fmt, treg, sreg, (int) pos,
6838 (int) (pos + size - 1));
6854 as_warn (_("Divide by zero."));
6856 macro_build (NULL, "teq", TRAP_FMT, ZERO, ZERO, 7);
6858 macro_build (NULL, "break", BRK_FMT, 7);
6865 macro_build (NULL, "teq", TRAP_FMT, treg, ZERO, 7);
6866 macro_build (NULL, dbl ? "ddiv" : "div", "z,s,t", sreg, treg);
6870 if (mips_opts.micromips)
6871 micromips_label_expr (&label_expr);
6873 label_expr.X_add_number = 8;
6874 macro_build (&label_expr, "bne", "s,t,p", treg, ZERO);
6875 macro_build (NULL, dbl ? "ddiv" : "div", "z,s,t", sreg, treg);
6876 macro_build (NULL, "break", BRK_FMT, 7);
6877 if (mips_opts.micromips)
6878 micromips_add_label ();
6880 expr1.X_add_number = -1;
6882 load_register (AT, &expr1, dbl);
6883 if (mips_opts.micromips)
6884 micromips_label_expr (&label_expr);
6886 label_expr.X_add_number = mips_trap ? (dbl ? 12 : 8) : (dbl ? 20 : 16);
6887 macro_build (&label_expr, "bne", "s,t,p", treg, AT);
6890 expr1.X_add_number = 1;
6891 load_register (AT, &expr1, dbl);
6892 macro_build (NULL, "dsll32", SHFT_FMT, AT, AT, 31);
6896 expr1.X_add_number = 0x80000000;
6897 macro_build (&expr1, "lui", LUI_FMT, AT, BFD_RELOC_HI16);
6901 macro_build (NULL, "teq", TRAP_FMT, sreg, AT, 6);
6902 /* We want to close the noreorder block as soon as possible, so
6903 that later insns are available for delay slot filling. */
6908 if (mips_opts.micromips)
6909 micromips_label_expr (&label_expr);
6911 label_expr.X_add_number = 8;
6912 macro_build (&label_expr, "bne", "s,t,p", sreg, AT);
6913 macro_build (NULL, "nop", "");
6915 /* We want to close the noreorder block as soon as possible, so
6916 that later insns are available for delay slot filling. */
6919 macro_build (NULL, "break", BRK_FMT, 6);
6921 if (mips_opts.micromips)
6922 micromips_add_label ();
6923 macro_build (NULL, s, MFHL_FMT, dreg);
6962 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
6964 as_warn (_("Divide by zero."));
6966 macro_build (NULL, "teq", TRAP_FMT, ZERO, ZERO, 7);
6968 macro_build (NULL, "break", BRK_FMT, 7);
6971 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
6973 if (strcmp (s2, "mflo") == 0)
6974 move_register (dreg, sreg);
6976 move_register (dreg, ZERO);
6979 if (imm_expr.X_op == O_constant
6980 && imm_expr.X_add_number == -1
6981 && s[strlen (s) - 1] != 'u')
6983 if (strcmp (s2, "mflo") == 0)
6985 macro_build (NULL, dbl ? "dneg" : "neg", "d,w", dreg, sreg);
6988 move_register (dreg, ZERO);
6993 load_register (AT, &imm_expr, dbl);
6994 macro_build (NULL, s, "z,s,t", sreg, AT);
6995 macro_build (NULL, s2, MFHL_FMT, dreg);
7017 macro_build (NULL, "teq", TRAP_FMT, treg, ZERO, 7);
7018 macro_build (NULL, s, "z,s,t", sreg, treg);
7019 /* We want to close the noreorder block as soon as possible, so
7020 that later insns are available for delay slot filling. */
7025 if (mips_opts.micromips)
7026 micromips_label_expr (&label_expr);
7028 label_expr.X_add_number = 8;
7029 macro_build (&label_expr, "bne", "s,t,p", treg, ZERO);
7030 macro_build (NULL, s, "z,s,t", sreg, treg);
7032 /* We want to close the noreorder block as soon as possible, so
7033 that later insns are available for delay slot filling. */
7035 macro_build (NULL, "break", BRK_FMT, 7);
7036 if (mips_opts.micromips)
7037 micromips_add_label ();
7039 macro_build (NULL, s2, MFHL_FMT, dreg);
7051 /* Load the address of a symbol into a register. If breg is not
7052 zero, we then add a base register to it. */
7054 if (dbl && HAVE_32BIT_GPRS)
7055 as_warn (_("dla used to load 32-bit register"));
7057 if (!dbl && HAVE_64BIT_OBJECTS)
7058 as_warn (_("la used to load 64-bit address"));
7060 if (offset_expr.X_op == O_constant
7061 && offset_expr.X_add_number >= -0x8000
7062 && offset_expr.X_add_number < 0x8000)
7064 macro_build (&offset_expr, ADDRESS_ADDI_INSN,
7065 "t,r,j", treg, sreg, BFD_RELOC_LO16);
7069 if (mips_opts.at && (treg == breg))
7079 if (offset_expr.X_op != O_symbol
7080 && offset_expr.X_op != O_constant)
7082 as_bad (_("Expression too complex"));
7083 offset_expr.X_op = O_constant;
7086 if (offset_expr.X_op == O_constant)
7087 load_register (tempreg, &offset_expr, HAVE_64BIT_ADDRESSES);
7088 else if (mips_pic == NO_PIC)
7090 /* If this is a reference to a GP relative symbol, we want
7091 addiu $tempreg,$gp,<sym> (BFD_RELOC_GPREL16)
7093 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
7094 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
7095 If we have a constant, we need two instructions anyhow,
7096 so we may as well always use the latter form.
7098 With 64bit address space and a usable $at we want
7099 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
7100 lui $at,<sym> (BFD_RELOC_HI16_S)
7101 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
7102 daddiu $at,<sym> (BFD_RELOC_LO16)
7104 daddu $tempreg,$tempreg,$at
7106 If $at is already in use, we use a path which is suboptimal
7107 on superscalar processors.
7108 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
7109 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
7111 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
7113 daddiu $tempreg,<sym> (BFD_RELOC_LO16)
7115 For GP relative symbols in 64bit address space we can use
7116 the same sequence as in 32bit address space. */
7117 if (HAVE_64BIT_SYMBOLS)
7119 if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
7120 && !nopic_need_relax (offset_expr.X_add_symbol, 1))
7122 relax_start (offset_expr.X_add_symbol);
7123 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
7124 tempreg, mips_gp_register, BFD_RELOC_GPREL16);
7128 if (used_at == 0 && mips_opts.at)
7130 macro_build (&offset_expr, "lui", LUI_FMT,
7131 tempreg, BFD_RELOC_MIPS_HIGHEST);
7132 macro_build (&offset_expr, "lui", LUI_FMT,
7133 AT, BFD_RELOC_HI16_S);
7134 macro_build (&offset_expr, "daddiu", "t,r,j",
7135 tempreg, tempreg, BFD_RELOC_MIPS_HIGHER);
7136 macro_build (&offset_expr, "daddiu", "t,r,j",
7137 AT, AT, BFD_RELOC_LO16);
7138 macro_build (NULL, "dsll32", SHFT_FMT, tempreg, tempreg, 0);
7139 macro_build (NULL, "daddu", "d,v,t", tempreg, tempreg, AT);
7144 macro_build (&offset_expr, "lui", LUI_FMT,
7145 tempreg, BFD_RELOC_MIPS_HIGHEST);
7146 macro_build (&offset_expr, "daddiu", "t,r,j",
7147 tempreg, tempreg, BFD_RELOC_MIPS_HIGHER);
7148 macro_build (NULL, "dsll", SHFT_FMT, tempreg, tempreg, 16);
7149 macro_build (&offset_expr, "daddiu", "t,r,j",
7150 tempreg, tempreg, BFD_RELOC_HI16_S);
7151 macro_build (NULL, "dsll", SHFT_FMT, tempreg, tempreg, 16);
7152 macro_build (&offset_expr, "daddiu", "t,r,j",
7153 tempreg, tempreg, BFD_RELOC_LO16);
7156 if (mips_relax.sequence)
7161 if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
7162 && !nopic_need_relax (offset_expr.X_add_symbol, 1))
7164 relax_start (offset_expr.X_add_symbol);
7165 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
7166 tempreg, mips_gp_register, BFD_RELOC_GPREL16);
7169 if (!IS_SEXT_32BIT_NUM (offset_expr.X_add_number))
7170 as_bad (_("Offset too large"));
7171 macro_build_lui (&offset_expr, tempreg);
7172 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
7173 tempreg, tempreg, BFD_RELOC_LO16);
7174 if (mips_relax.sequence)
7178 else if (!mips_big_got && !HAVE_NEWABI)
7180 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT16;
7182 /* If this is a reference to an external symbol, and there
7183 is no constant, we want
7184 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
7185 or for lca or if tempreg is PIC_CALL_REG
7186 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
7187 For a local symbol, we want
7188 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
7190 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
7192 If we have a small constant, and this is a reference to
7193 an external symbol, we want
7194 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
7196 addiu $tempreg,$tempreg,<constant>
7197 For a local symbol, we want the same instruction
7198 sequence, but we output a BFD_RELOC_LO16 reloc on the
7201 If we have a large constant, and this is a reference to
7202 an external symbol, we want
7203 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
7204 lui $at,<hiconstant>
7205 addiu $at,$at,<loconstant>
7206 addu $tempreg,$tempreg,$at
7207 For a local symbol, we want the same instruction
7208 sequence, but we output a BFD_RELOC_LO16 reloc on the
7212 if (offset_expr.X_add_number == 0)
7214 if (mips_pic == SVR4_PIC
7216 && (call || tempreg == PIC_CALL_REG))
7217 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL16;
7219 relax_start (offset_expr.X_add_symbol);
7220 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
7221 lw_reloc_type, mips_gp_register);
7224 /* We're going to put in an addu instruction using
7225 tempreg, so we may as well insert the nop right
7230 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
7231 tempreg, BFD_RELOC_MIPS_GOT16, mips_gp_register);
7233 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
7234 tempreg, tempreg, BFD_RELOC_LO16);
7236 /* FIXME: If breg == 0, and the next instruction uses
7237 $tempreg, then if this variant case is used an extra
7238 nop will be generated. */
7240 else if (offset_expr.X_add_number >= -0x8000
7241 && offset_expr.X_add_number < 0x8000)
7243 load_got_offset (tempreg, &offset_expr);
7245 add_got_offset (tempreg, &offset_expr);
7249 expr1.X_add_number = offset_expr.X_add_number;
7250 offset_expr.X_add_number =
7251 ((offset_expr.X_add_number + 0x8000) & 0xffff) - 0x8000;
7252 load_got_offset (tempreg, &offset_expr);
7253 offset_expr.X_add_number = expr1.X_add_number;
7254 /* If we are going to add in a base register, and the
7255 target register and the base register are the same,
7256 then we are using AT as a temporary register. Since
7257 we want to load the constant into AT, we add our
7258 current AT (from the global offset table) and the
7259 register into the register now, and pretend we were
7260 not using a base register. */
7264 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
7269 add_got_offset_hilo (tempreg, &offset_expr, AT);
7273 else if (!mips_big_got && HAVE_NEWABI)
7275 int add_breg_early = 0;
7277 /* If this is a reference to an external, and there is no
7278 constant, or local symbol (*), with or without a
7280 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
7281 or for lca or if tempreg is PIC_CALL_REG
7282 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
7284 If we have a small constant, and this is a reference to
7285 an external symbol, we want
7286 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
7287 addiu $tempreg,$tempreg,<constant>
7289 If we have a large constant, and this is a reference to
7290 an external symbol, we want
7291 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
7292 lui $at,<hiconstant>
7293 addiu $at,$at,<loconstant>
7294 addu $tempreg,$tempreg,$at
7296 (*) Other assemblers seem to prefer GOT_PAGE/GOT_OFST for
7297 local symbols, even though it introduces an additional
7300 if (offset_expr.X_add_number)
7302 expr1.X_add_number = offset_expr.X_add_number;
7303 offset_expr.X_add_number = 0;
7305 relax_start (offset_expr.X_add_symbol);
7306 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
7307 BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
7309 if (expr1.X_add_number >= -0x8000
7310 && expr1.X_add_number < 0x8000)
7312 macro_build (&expr1, ADDRESS_ADDI_INSN, "t,r,j",
7313 tempreg, tempreg, BFD_RELOC_LO16);
7315 else if (IS_SEXT_32BIT_NUM (expr1.X_add_number + 0x8000))
7317 /* If we are going to add in a base register, and the
7318 target register and the base register are the same,
7319 then we are using AT as a temporary register. Since
7320 we want to load the constant into AT, we add our
7321 current AT (from the global offset table) and the
7322 register into the register now, and pretend we were
7323 not using a base register. */
7328 gas_assert (tempreg == AT);
7329 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
7335 load_register (AT, &expr1, HAVE_64BIT_ADDRESSES);
7336 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
7342 as_bad (_("PIC code offset overflow (max 32 signed bits)"));
7345 offset_expr.X_add_number = expr1.X_add_number;
7347 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
7348 BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
7351 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
7352 treg, tempreg, breg);
7358 else if (breg == 0 && (call || tempreg == PIC_CALL_REG))
7360 relax_start (offset_expr.X_add_symbol);
7361 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
7362 BFD_RELOC_MIPS_CALL16, mips_gp_register);
7364 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
7365 BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
7370 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
7371 BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
7374 else if (mips_big_got && !HAVE_NEWABI)
7377 int lui_reloc_type = (int) BFD_RELOC_MIPS_GOT_HI16;
7378 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT_LO16;
7379 int local_reloc_type = (int) BFD_RELOC_MIPS_GOT16;
7381 /* This is the large GOT case. If this is a reference to an
7382 external symbol, and there is no constant, we want
7383 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
7384 addu $tempreg,$tempreg,$gp
7385 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
7386 or for lca or if tempreg is PIC_CALL_REG
7387 lui $tempreg,<sym> (BFD_RELOC_MIPS_CALL_HI16)
7388 addu $tempreg,$tempreg,$gp
7389 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_CALL_LO16)
7390 For a local symbol, we want
7391 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
7393 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
7395 If we have a small constant, and this is a reference to
7396 an external symbol, we want
7397 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
7398 addu $tempreg,$tempreg,$gp
7399 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
7401 addiu $tempreg,$tempreg,<constant>
7402 For a local symbol, we want
7403 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
7405 addiu $tempreg,$tempreg,<constant> (BFD_RELOC_LO16)
7407 If we have a large constant, and this is a reference to
7408 an external symbol, we want
7409 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
7410 addu $tempreg,$tempreg,$gp
7411 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
7412 lui $at,<hiconstant>
7413 addiu $at,$at,<loconstant>
7414 addu $tempreg,$tempreg,$at
7415 For a local symbol, we want
7416 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
7417 lui $at,<hiconstant>
7418 addiu $at,$at,<loconstant> (BFD_RELOC_LO16)
7419 addu $tempreg,$tempreg,$at
7422 expr1.X_add_number = offset_expr.X_add_number;
7423 offset_expr.X_add_number = 0;
7424 relax_start (offset_expr.X_add_symbol);
7425 gpdelay = reg_needs_delay (mips_gp_register);
7426 if (expr1.X_add_number == 0 && breg == 0
7427 && (call || tempreg == PIC_CALL_REG))
7429 lui_reloc_type = (int) BFD_RELOC_MIPS_CALL_HI16;
7430 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL_LO16;
7432 macro_build (&offset_expr, "lui", LUI_FMT, tempreg, lui_reloc_type);
7433 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
7434 tempreg, tempreg, mips_gp_register);
7435 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
7436 tempreg, lw_reloc_type, tempreg);
7437 if (expr1.X_add_number == 0)
7441 /* We're going to put in an addu instruction using
7442 tempreg, so we may as well insert the nop right
7447 else if (expr1.X_add_number >= -0x8000
7448 && expr1.X_add_number < 0x8000)
7451 macro_build (&expr1, ADDRESS_ADDI_INSN, "t,r,j",
7452 tempreg, tempreg, BFD_RELOC_LO16);
7456 /* If we are going to add in a base register, and the
7457 target register and the base register are the same,
7458 then we are using AT as a temporary register. Since
7459 we want to load the constant into AT, we add our
7460 current AT (from the global offset table) and the
7461 register into the register now, and pretend we were
7462 not using a base register. */
7467 gas_assert (tempreg == AT);
7469 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
7474 load_register (AT, &expr1, HAVE_64BIT_ADDRESSES);
7475 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", dreg, dreg, AT);
7479 offset_expr.X_add_number =
7480 ((expr1.X_add_number + 0x8000) & 0xffff) - 0x8000;
7485 /* This is needed because this instruction uses $gp, but
7486 the first instruction on the main stream does not. */
7487 macro_build (NULL, "nop", "");
7490 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
7491 local_reloc_type, mips_gp_register);
7492 if (expr1.X_add_number >= -0x8000
7493 && expr1.X_add_number < 0x8000)
7496 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
7497 tempreg, tempreg, BFD_RELOC_LO16);
7498 /* FIXME: If add_number is 0, and there was no base
7499 register, the external symbol case ended with a load,
7500 so if the symbol turns out to not be external, and
7501 the next instruction uses tempreg, an unnecessary nop
7502 will be inserted. */
7508 /* We must add in the base register now, as in the
7509 external symbol case. */
7510 gas_assert (tempreg == AT);
7512 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
7515 /* We set breg to 0 because we have arranged to add
7516 it in in both cases. */
7520 macro_build_lui (&expr1, AT);
7521 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
7522 AT, AT, BFD_RELOC_LO16);
7523 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
7524 tempreg, tempreg, AT);
7529 else if (mips_big_got && HAVE_NEWABI)
7531 int lui_reloc_type = (int) BFD_RELOC_MIPS_GOT_HI16;
7532 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT_LO16;
7533 int add_breg_early = 0;
7535 /* This is the large GOT case. If this is a reference to an
7536 external symbol, and there is no constant, we want
7537 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
7538 add $tempreg,$tempreg,$gp
7539 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
7540 or for lca or if tempreg is PIC_CALL_REG
7541 lui $tempreg,<sym> (BFD_RELOC_MIPS_CALL_HI16)
7542 add $tempreg,$tempreg,$gp
7543 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_CALL_LO16)
7545 If we have a small constant, and this is a reference to
7546 an external symbol, we want
7547 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
7548 add $tempreg,$tempreg,$gp
7549 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
7550 addi $tempreg,$tempreg,<constant>
7552 If we have a large constant, and this is a reference to
7553 an external symbol, we want
7554 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
7555 addu $tempreg,$tempreg,$gp
7556 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
7557 lui $at,<hiconstant>
7558 addi $at,$at,<loconstant>
7559 add $tempreg,$tempreg,$at
7561 If we have NewABI, and we know it's a local symbol, we want
7562 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
7563 addiu $reg,$reg,<sym> (BFD_RELOC_MIPS_GOT_OFST)
7564 otherwise we have to resort to GOT_HI16/GOT_LO16. */
7566 relax_start (offset_expr.X_add_symbol);
7568 expr1.X_add_number = offset_expr.X_add_number;
7569 offset_expr.X_add_number = 0;
7571 if (expr1.X_add_number == 0 && breg == 0
7572 && (call || tempreg == PIC_CALL_REG))
7574 lui_reloc_type = (int) BFD_RELOC_MIPS_CALL_HI16;
7575 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL_LO16;
7577 macro_build (&offset_expr, "lui", LUI_FMT, tempreg, lui_reloc_type);
7578 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
7579 tempreg, tempreg, mips_gp_register);
7580 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
7581 tempreg, lw_reloc_type, tempreg);
7583 if (expr1.X_add_number == 0)
7585 else if (expr1.X_add_number >= -0x8000
7586 && expr1.X_add_number < 0x8000)
7588 macro_build (&expr1, ADDRESS_ADDI_INSN, "t,r,j",
7589 tempreg, tempreg, BFD_RELOC_LO16);
7591 else if (IS_SEXT_32BIT_NUM (expr1.X_add_number + 0x8000))
7593 /* If we are going to add in a base register, and the
7594 target register and the base register are the same,
7595 then we are using AT as a temporary register. Since
7596 we want to load the constant into AT, we add our
7597 current AT (from the global offset table) and the
7598 register into the register now, and pretend we were
7599 not using a base register. */
7604 gas_assert (tempreg == AT);
7605 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
7611 load_register (AT, &expr1, HAVE_64BIT_ADDRESSES);
7612 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", dreg, dreg, AT);
7617 as_bad (_("PIC code offset overflow (max 32 signed bits)"));
7620 offset_expr.X_add_number = expr1.X_add_number;
7621 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
7622 BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register);
7623 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j", tempreg,
7624 tempreg, BFD_RELOC_MIPS_GOT_OFST);
7627 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
7628 treg, tempreg, breg);
7638 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", treg, tempreg, breg);
7642 gas_assert (!mips_opts.micromips);
7644 unsigned long temp = (treg << 16) | (0x01);
7645 macro_build (NULL, "c2", "C", temp);
7650 gas_assert (!mips_opts.micromips);
7652 unsigned long temp = (0x02);
7653 macro_build (NULL, "c2", "C", temp);
7658 gas_assert (!mips_opts.micromips);
7660 unsigned long temp = (treg << 16) | (0x02);
7661 macro_build (NULL, "c2", "C", temp);
7666 gas_assert (!mips_opts.micromips);
7667 macro_build (NULL, "c2", "C", 3);
7671 gas_assert (!mips_opts.micromips);
7673 unsigned long temp = (treg << 16) | 0x03;
7674 macro_build (NULL, "c2", "C", temp);
7679 /* The j instruction may not be used in PIC code, since it
7680 requires an absolute address. We convert it to a b
7682 if (mips_pic == NO_PIC)
7683 macro_build (&offset_expr, "j", "a");
7685 macro_build (&offset_expr, "b", "p");
7688 /* The jal instructions must be handled as macros because when
7689 generating PIC code they expand to multi-instruction
7690 sequences. Normally they are simple instructions. */
7695 gas_assert (mips_opts.micromips);
7703 if (mips_pic == NO_PIC)
7705 s = jals ? "jalrs" : "jalr";
7706 if (mips_opts.micromips && dreg == RA)
7707 macro_build (NULL, s, "mj", sreg);
7709 macro_build (NULL, s, JALR_FMT, dreg, sreg);
7713 int cprestore = (mips_pic == SVR4_PIC && !HAVE_NEWABI
7714 && mips_cprestore_offset >= 0);
7716 if (sreg != PIC_CALL_REG)
7717 as_warn (_("MIPS PIC call to register other than $25"));
7719 s = (mips_opts.micromips && (!mips_opts.noreorder || cprestore)
7720 ? "jalrs" : "jalr");
7721 if (mips_opts.micromips && dreg == RA)
7722 macro_build (NULL, s, "mj", sreg);
7724 macro_build (NULL, s, JALR_FMT, dreg, sreg);
7725 if (mips_pic == SVR4_PIC && !HAVE_NEWABI)
7727 if (mips_cprestore_offset < 0)
7728 as_warn (_("No .cprestore pseudo-op used in PIC code"));
7731 if (!mips_frame_reg_valid)
7733 as_warn (_("No .frame pseudo-op used in PIC code"));
7734 /* Quiet this warning. */
7735 mips_frame_reg_valid = 1;
7737 if (!mips_cprestore_valid)
7739 as_warn (_("No .cprestore pseudo-op used in PIC code"));
7740 /* Quiet this warning. */
7741 mips_cprestore_valid = 1;
7743 if (mips_opts.noreorder)
7744 macro_build (NULL, "nop", "");
7745 expr1.X_add_number = mips_cprestore_offset;
7746 macro_build_ldst_constoffset (&expr1, ADDRESS_LOAD_INSN,
7749 HAVE_64BIT_ADDRESSES);
7757 gas_assert (mips_opts.micromips);
7761 if (mips_pic == NO_PIC)
7762 macro_build (&offset_expr, jals ? "jals" : "jal", "a");
7763 else if (mips_pic == SVR4_PIC)
7765 /* If this is a reference to an external symbol, and we are
7766 using a small GOT, we want
7767 lw $25,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
7771 lw $gp,cprestore($sp)
7772 The cprestore value is set using the .cprestore
7773 pseudo-op. If we are using a big GOT, we want
7774 lui $25,<sym> (BFD_RELOC_MIPS_CALL_HI16)
7776 lw $25,<sym>($25) (BFD_RELOC_MIPS_CALL_LO16)
7780 lw $gp,cprestore($sp)
7781 If the symbol is not external, we want
7782 lw $25,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
7784 addiu $25,$25,<sym> (BFD_RELOC_LO16)
7787 lw $gp,cprestore($sp)
7789 For NewABI, we use the same CALL16 or CALL_HI16/CALL_LO16
7790 sequences above, minus nops, unless the symbol is local,
7791 which enables us to use GOT_PAGE/GOT_OFST (big got) or
7797 relax_start (offset_expr.X_add_symbol);
7798 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
7799 PIC_CALL_REG, BFD_RELOC_MIPS_CALL16,
7802 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
7803 PIC_CALL_REG, BFD_RELOC_MIPS_GOT_DISP,
7809 relax_start (offset_expr.X_add_symbol);
7810 macro_build (&offset_expr, "lui", LUI_FMT, PIC_CALL_REG,
7811 BFD_RELOC_MIPS_CALL_HI16);
7812 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", PIC_CALL_REG,
7813 PIC_CALL_REG, mips_gp_register);
7814 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
7815 PIC_CALL_REG, BFD_RELOC_MIPS_CALL_LO16,
7818 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
7819 PIC_CALL_REG, BFD_RELOC_MIPS_GOT_PAGE,
7821 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
7822 PIC_CALL_REG, PIC_CALL_REG,
7823 BFD_RELOC_MIPS_GOT_OFST);
7827 macro_build_jalr (&offset_expr, 0);
7831 relax_start (offset_expr.X_add_symbol);
7834 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
7835 PIC_CALL_REG, BFD_RELOC_MIPS_CALL16,
7844 gpdelay = reg_needs_delay (mips_gp_register);
7845 macro_build (&offset_expr, "lui", LUI_FMT, PIC_CALL_REG,
7846 BFD_RELOC_MIPS_CALL_HI16);
7847 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", PIC_CALL_REG,
7848 PIC_CALL_REG, mips_gp_register);
7849 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
7850 PIC_CALL_REG, BFD_RELOC_MIPS_CALL_LO16,
7855 macro_build (NULL, "nop", "");
7857 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
7858 PIC_CALL_REG, BFD_RELOC_MIPS_GOT16,
7861 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
7862 PIC_CALL_REG, PIC_CALL_REG, BFD_RELOC_LO16);
7864 macro_build_jalr (&offset_expr, mips_cprestore_offset >= 0);
7866 if (mips_cprestore_offset < 0)
7867 as_warn (_("No .cprestore pseudo-op used in PIC code"));
7870 if (!mips_frame_reg_valid)
7872 as_warn (_("No .frame pseudo-op used in PIC code"));
7873 /* Quiet this warning. */
7874 mips_frame_reg_valid = 1;
7876 if (!mips_cprestore_valid)
7878 as_warn (_("No .cprestore pseudo-op used in PIC code"));
7879 /* Quiet this warning. */
7880 mips_cprestore_valid = 1;
7882 if (mips_opts.noreorder)
7883 macro_build (NULL, "nop", "");
7884 expr1.X_add_number = mips_cprestore_offset;
7885 macro_build_ldst_constoffset (&expr1, ADDRESS_LOAD_INSN,
7888 HAVE_64BIT_ADDRESSES);
7892 else if (mips_pic == VXWORKS_PIC)
7893 as_bad (_("Non-PIC jump used in PIC library"));
7903 treg = EXTRACT_OPERAND (mips_opts.micromips, 3BITPOS, *ip);
7911 treg = EXTRACT_OPERAND (mips_opts.micromips, 3BITPOS, *ip);
7942 gas_assert (!mips_opts.micromips);
7945 /* Itbl support may require additional care here. */
7952 /* Itbl support may require additional care here. */
7960 off12 = mips_opts.micromips;
7961 /* Itbl support may require additional care here. */
7966 gas_assert (!mips_opts.micromips);
7969 /* Itbl support may require additional care here. */
7977 off12 = mips_opts.micromips;
7984 off12 = mips_opts.micromips;
7990 /* Itbl support may require additional care here. */
7998 off12 = mips_opts.micromips;
7999 /* Itbl support may require additional care here. */
8006 /* Itbl support may require additional care here. */
8014 off12 = mips_opts.micromips;
8021 off12 = mips_opts.micromips;
8028 off12 = mips_opts.micromips;
8035 off12 = mips_opts.micromips;
8042 off12 = mips_opts.micromips;
8047 gas_assert (mips_opts.micromips);
8056 gas_assert (mips_opts.micromips);
8065 gas_assert (mips_opts.micromips);
8073 gas_assert (mips_opts.micromips);
8080 if (breg == treg + lp)
8083 tempreg = treg + lp;
8103 gas_assert (!mips_opts.micromips);
8106 /* Itbl support may require additional care here. */
8113 /* Itbl support may require additional care here. */
8121 off12 = mips_opts.micromips;
8122 /* Itbl support may require additional care here. */
8127 gas_assert (!mips_opts.micromips);
8130 /* Itbl support may require additional care here. */
8138 off12 = mips_opts.micromips;
8145 off12 = mips_opts.micromips;
8152 off12 = mips_opts.micromips;
8159 off12 = mips_opts.micromips;
8165 fmt = mips_opts.micromips ? "k,~(b)" : "k,o(b)";
8166 off12 = mips_opts.micromips;
8172 fmt = !mips_opts.micromips ? "k,o(b)" : "k,~(b)";
8173 off12 = mips_opts.micromips;
8180 /* Itbl support may require additional care here. */
8187 off12 = mips_opts.micromips;
8188 /* Itbl support may require additional care here. */
8193 gas_assert (!mips_opts.micromips);
8196 /* Itbl support may require additional care here. */
8204 off12 = mips_opts.micromips;
8211 off12 = mips_opts.micromips;
8216 gas_assert (mips_opts.micromips);
8224 gas_assert (mips_opts.micromips);
8232 gas_assert (mips_opts.micromips);
8240 gas_assert (mips_opts.micromips);
8250 && NO_ISA_COP (mips_opts.arch)
8251 && (ip->insn_mo->pinfo2 & (INSN2_M_FP_S | INSN2_M_FP_D)) == 0)
8253 as_bad (_("Opcode not supported on this processor: %s"),
8254 mips_cpu_info_from_arch (mips_opts.arch)->name);
8258 if (offset_expr.X_op != O_constant
8259 && offset_expr.X_op != O_symbol)
8261 as_bad (_("Expression too complex"));
8262 offset_expr.X_op = O_constant;
8265 if (HAVE_32BIT_ADDRESSES
8266 && !IS_SEXT_32BIT_NUM (offset_expr.X_add_number))
8270 sprintf_vma (value, offset_expr.X_add_number);
8271 as_bad (_("Number (0x%s) larger than 32 bits"), value);
8274 /* A constant expression in PIC code can be handled just as it
8275 is in non PIC code. */
8276 if (offset_expr.X_op == O_constant)
8280 expr1.X_add_number = offset_expr.X_add_number;
8281 normalize_address_expr (&expr1);
8282 if (!off12 && !IS_SEXT_16BIT_NUM (expr1.X_add_number))
8284 expr1.X_add_number = ((expr1.X_add_number + 0x8000)
8285 & ~(bfd_vma) 0xffff);
8288 else if (off12 && !IS_SEXT_12BIT_NUM (expr1.X_add_number))
8290 expr1.X_add_number = ((expr1.X_add_number + 0x800)
8291 & ~(bfd_vma) 0xfff);
8296 load_register (tempreg, &expr1, HAVE_64BIT_ADDRESSES);
8298 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
8299 tempreg, tempreg, breg);
8304 if (offset_expr.X_add_number == 0)
8307 macro_build (&offset_expr, ADDRESS_ADDI_INSN,
8308 "t,r,j", tempreg, breg, BFD_RELOC_LO16);
8309 macro_build (NULL, s, fmt, treg, tempreg);
8312 macro_build (&offset_expr, s, fmt, treg, BFD_RELOC_LO16, breg);
8314 macro_build (NULL, s, fmt,
8315 treg, (unsigned long) offset_expr.X_add_number, breg);
8317 else if (off12 || off0)
8319 /* A 12-bit or 0-bit offset field is too narrow to be used
8320 for a low-part relocation, so load the whole address into
8321 the auxillary register. In the case of "A(b)" addresses,
8322 we first load absolute address "A" into the register and
8323 then add base register "b". In the case of "o(b)" addresses,
8324 we simply need to add 16-bit offset "o" to base register "b", and
8325 offset_reloc already contains the relocations associated
8329 load_address (tempreg, &offset_expr, &used_at);
8331 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
8332 tempreg, tempreg, breg);
8335 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
8337 offset_reloc[0], offset_reloc[1], offset_reloc[2]);
8338 expr1.X_add_number = 0;
8340 macro_build (NULL, s, fmt, treg, tempreg);
8342 macro_build (NULL, s, fmt,
8343 treg, (unsigned long) expr1.X_add_number, tempreg);
8345 else if (mips_pic == NO_PIC)
8347 /* If this is a reference to a GP relative symbol, and there
8348 is no base register, we want
8349 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
8350 Otherwise, if there is no base register, we want
8351 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
8352 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
8353 If we have a constant, we need two instructions anyhow,
8354 so we always use the latter form.
8356 If we have a base register, and this is a reference to a
8357 GP relative symbol, we want
8358 addu $tempreg,$breg,$gp
8359 <op> $treg,<sym>($tempreg) (BFD_RELOC_GPREL16)
8361 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
8362 addu $tempreg,$tempreg,$breg
8363 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
8364 With a constant we always use the latter case.
8366 With 64bit address space and no base register and $at usable,
8368 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
8369 lui $at,<sym> (BFD_RELOC_HI16_S)
8370 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
8373 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
8374 If we have a base register, we want
8375 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
8376 lui $at,<sym> (BFD_RELOC_HI16_S)
8377 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
8381 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
8383 Without $at we can't generate the optimal path for superscalar
8384 processors here since this would require two temporary registers.
8385 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
8386 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
8388 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
8390 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
8391 If we have a base register, we want
8392 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
8393 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
8395 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
8397 daddu $tempreg,$tempreg,$breg
8398 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
8400 For GP relative symbols in 64bit address space we can use
8401 the same sequence as in 32bit address space. */
8402 if (HAVE_64BIT_SYMBOLS)
8404 if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
8405 && !nopic_need_relax (offset_expr.X_add_symbol, 1))
8407 relax_start (offset_expr.X_add_symbol);
8410 macro_build (&offset_expr, s, fmt, treg,
8411 BFD_RELOC_GPREL16, mips_gp_register);
8415 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
8416 tempreg, breg, mips_gp_register);
8417 macro_build (&offset_expr, s, fmt, treg,
8418 BFD_RELOC_GPREL16, tempreg);
8423 if (used_at == 0 && mips_opts.at)
8425 macro_build (&offset_expr, "lui", LUI_FMT, tempreg,
8426 BFD_RELOC_MIPS_HIGHEST);
8427 macro_build (&offset_expr, "lui", LUI_FMT, AT,
8429 macro_build (&offset_expr, "daddiu", "t,r,j", tempreg,
8430 tempreg, BFD_RELOC_MIPS_HIGHER);
8432 macro_build (NULL, "daddu", "d,v,t", AT, AT, breg);
8433 macro_build (NULL, "dsll32", SHFT_FMT, tempreg, tempreg, 0);
8434 macro_build (NULL, "daddu", "d,v,t", tempreg, tempreg, AT);
8435 macro_build (&offset_expr, s, fmt, treg, BFD_RELOC_LO16,
8441 macro_build (&offset_expr, "lui", LUI_FMT, tempreg,
8442 BFD_RELOC_MIPS_HIGHEST);
8443 macro_build (&offset_expr, "daddiu", "t,r,j", tempreg,
8444 tempreg, BFD_RELOC_MIPS_HIGHER);
8445 macro_build (NULL, "dsll", SHFT_FMT, tempreg, tempreg, 16);
8446 macro_build (&offset_expr, "daddiu", "t,r,j", tempreg,
8447 tempreg, BFD_RELOC_HI16_S);
8448 macro_build (NULL, "dsll", SHFT_FMT, tempreg, tempreg, 16);
8450 macro_build (NULL, "daddu", "d,v,t",
8451 tempreg, tempreg, breg);
8452 macro_build (&offset_expr, s, fmt, treg,
8453 BFD_RELOC_LO16, tempreg);
8456 if (mips_relax.sequence)
8463 if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
8464 && !nopic_need_relax (offset_expr.X_add_symbol, 1))
8466 relax_start (offset_expr.X_add_symbol);
8467 macro_build (&offset_expr, s, fmt, treg, BFD_RELOC_GPREL16,
8471 macro_build_lui (&offset_expr, tempreg);
8472 macro_build (&offset_expr, s, fmt, treg,
8473 BFD_RELOC_LO16, tempreg);
8474 if (mips_relax.sequence)
8479 if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
8480 && !nopic_need_relax (offset_expr.X_add_symbol, 1))
8482 relax_start (offset_expr.X_add_symbol);
8483 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
8484 tempreg, breg, mips_gp_register);
8485 macro_build (&offset_expr, s, fmt, treg,
8486 BFD_RELOC_GPREL16, tempreg);
8489 macro_build_lui (&offset_expr, tempreg);
8490 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
8491 tempreg, tempreg, breg);
8492 macro_build (&offset_expr, s, fmt, treg,
8493 BFD_RELOC_LO16, tempreg);
8494 if (mips_relax.sequence)
8498 else if (!mips_big_got)
8500 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT16;
8502 /* If this is a reference to an external symbol, we want
8503 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
8505 <op> $treg,0($tempreg)
8507 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
8509 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
8510 <op> $treg,0($tempreg)
8513 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
8514 <op> $treg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_OFST)
8516 If there is a base register, we add it to $tempreg before
8517 the <op>. If there is a constant, we stick it in the
8518 <op> instruction. We don't handle constants larger than
8519 16 bits, because we have no way to load the upper 16 bits
8520 (actually, we could handle them for the subset of cases
8521 in which we are not using $at). */
8522 gas_assert (offset_expr.X_op == O_symbol);
8525 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
8526 BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register);
8528 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
8529 tempreg, tempreg, breg);
8530 macro_build (&offset_expr, s, fmt, treg,
8531 BFD_RELOC_MIPS_GOT_OFST, tempreg);
8534 expr1.X_add_number = offset_expr.X_add_number;
8535 offset_expr.X_add_number = 0;
8536 if (expr1.X_add_number < -0x8000
8537 || expr1.X_add_number >= 0x8000)
8538 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
8539 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
8540 lw_reloc_type, mips_gp_register);
8542 relax_start (offset_expr.X_add_symbol);
8544 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j", tempreg,
8545 tempreg, BFD_RELOC_LO16);
8548 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
8549 tempreg, tempreg, breg);
8550 macro_build (&expr1, s, fmt, treg, BFD_RELOC_LO16, tempreg);
8552 else if (mips_big_got && !HAVE_NEWABI)
8556 /* If this is a reference to an external symbol, we want
8557 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
8558 addu $tempreg,$tempreg,$gp
8559 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
8560 <op> $treg,0($tempreg)
8562 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
8564 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
8565 <op> $treg,0($tempreg)
8566 If there is a base register, we add it to $tempreg before
8567 the <op>. If there is a constant, we stick it in the
8568 <op> instruction. We don't handle constants larger than
8569 16 bits, because we have no way to load the upper 16 bits
8570 (actually, we could handle them for the subset of cases
8571 in which we are not using $at). */
8572 gas_assert (offset_expr.X_op == O_symbol);
8573 expr1.X_add_number = offset_expr.X_add_number;
8574 offset_expr.X_add_number = 0;
8575 if (expr1.X_add_number < -0x8000
8576 || expr1.X_add_number >= 0x8000)
8577 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
8578 gpdelay = reg_needs_delay (mips_gp_register);
8579 relax_start (offset_expr.X_add_symbol);
8580 macro_build (&offset_expr, "lui", LUI_FMT, tempreg,
8581 BFD_RELOC_MIPS_GOT_HI16);
8582 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", tempreg, tempreg,
8584 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
8585 BFD_RELOC_MIPS_GOT_LO16, tempreg);
8588 macro_build (NULL, "nop", "");
8589 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
8590 BFD_RELOC_MIPS_GOT16, mips_gp_register);
8592 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j", tempreg,
8593 tempreg, BFD_RELOC_LO16);
8597 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
8598 tempreg, tempreg, breg);
8599 macro_build (&expr1, s, fmt, treg, BFD_RELOC_LO16, tempreg);
8601 else if (mips_big_got && HAVE_NEWABI)
8603 /* If this is a reference to an external symbol, we want
8604 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
8605 add $tempreg,$tempreg,$gp
8606 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
8607 <op> $treg,<ofst>($tempreg)
8608 Otherwise, for local symbols, we want:
8609 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
8610 <op> $treg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_OFST) */
8611 gas_assert (offset_expr.X_op == O_symbol);
8612 expr1.X_add_number = offset_expr.X_add_number;
8613 offset_expr.X_add_number = 0;
8614 if (expr1.X_add_number < -0x8000
8615 || expr1.X_add_number >= 0x8000)
8616 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
8617 relax_start (offset_expr.X_add_symbol);
8618 macro_build (&offset_expr, "lui", LUI_FMT, tempreg,
8619 BFD_RELOC_MIPS_GOT_HI16);
8620 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", tempreg, tempreg,
8622 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
8623 BFD_RELOC_MIPS_GOT_LO16, tempreg);
8625 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
8626 tempreg, tempreg, breg);
8627 macro_build (&expr1, s, fmt, treg, BFD_RELOC_LO16, tempreg);
8630 offset_expr.X_add_number = expr1.X_add_number;
8631 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
8632 BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register);
8634 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
8635 tempreg, tempreg, breg);
8636 macro_build (&offset_expr, s, fmt, treg,
8637 BFD_RELOC_MIPS_GOT_OFST, tempreg);
8647 load_register (treg, &imm_expr, 0);
8651 load_register (treg, &imm_expr, 1);
8655 if (imm_expr.X_op == O_constant)
8658 load_register (AT, &imm_expr, 0);
8659 macro_build (NULL, "mtc1", "t,G", AT, treg);
8664 gas_assert (offset_expr.X_op == O_symbol
8665 && strcmp (segment_name (S_GET_SEGMENT
8666 (offset_expr.X_add_symbol)),
8668 && offset_expr.X_add_number == 0);
8669 macro_build (&offset_expr, "lwc1", "T,o(b)", treg,
8670 BFD_RELOC_MIPS_LITERAL, mips_gp_register);
8675 /* Check if we have a constant in IMM_EXPR. If the GPRs are 64 bits
8676 wide, IMM_EXPR is the entire value. Otherwise IMM_EXPR is the high
8677 order 32 bits of the value and the low order 32 bits are either
8678 zero or in OFFSET_EXPR. */
8679 if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big)
8681 if (HAVE_64BIT_GPRS)
8682 load_register (treg, &imm_expr, 1);
8687 if (target_big_endian)
8699 load_register (hreg, &imm_expr, 0);
8702 if (offset_expr.X_op == O_absent)
8703 move_register (lreg, 0);
8706 gas_assert (offset_expr.X_op == O_constant);
8707 load_register (lreg, &offset_expr, 0);
8714 /* We know that sym is in the .rdata section. First we get the
8715 upper 16 bits of the address. */
8716 if (mips_pic == NO_PIC)
8718 macro_build_lui (&offset_expr, AT);
8723 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", AT,
8724 BFD_RELOC_MIPS_GOT16, mips_gp_register);
8728 /* Now we load the register(s). */
8729 if (HAVE_64BIT_GPRS)
8732 macro_build (&offset_expr, "ld", "t,o(b)", treg, BFD_RELOC_LO16, AT);
8737 macro_build (&offset_expr, "lw", "t,o(b)", treg, BFD_RELOC_LO16, AT);
8740 /* FIXME: How in the world do we deal with the possible
8742 offset_expr.X_add_number += 4;
8743 macro_build (&offset_expr, "lw", "t,o(b)",
8744 treg + 1, BFD_RELOC_LO16, AT);
8750 /* Check if we have a constant in IMM_EXPR. If the FPRs are 64 bits
8751 wide, IMM_EXPR is the entire value and the GPRs are known to be 64
8752 bits wide as well. Otherwise IMM_EXPR is the high order 32 bits of
8753 the value and the low order 32 bits are either zero or in
8755 if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big)
8758 load_register (AT, &imm_expr, HAVE_64BIT_FPRS);
8759 if (HAVE_64BIT_FPRS)
8761 gas_assert (HAVE_64BIT_GPRS);
8762 macro_build (NULL, "dmtc1", "t,S", AT, treg);
8766 macro_build (NULL, "mtc1", "t,G", AT, treg + 1);
8767 if (offset_expr.X_op == O_absent)
8768 macro_build (NULL, "mtc1", "t,G", 0, treg);
8771 gas_assert (offset_expr.X_op == O_constant);
8772 load_register (AT, &offset_expr, 0);
8773 macro_build (NULL, "mtc1", "t,G", AT, treg);
8779 gas_assert (offset_expr.X_op == O_symbol
8780 && offset_expr.X_add_number == 0);
8781 s = segment_name (S_GET_SEGMENT (offset_expr.X_add_symbol));
8782 if (strcmp (s, ".lit8") == 0)
8784 if (mips_opts.isa != ISA_MIPS1 || mips_opts.micromips)
8786 macro_build (&offset_expr, "ldc1", "T,o(b)", treg,
8787 BFD_RELOC_MIPS_LITERAL, mips_gp_register);
8790 breg = mips_gp_register;
8791 r = BFD_RELOC_MIPS_LITERAL;
8796 gas_assert (strcmp (s, RDATA_SECTION_NAME) == 0);
8798 if (mips_pic != NO_PIC)
8799 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", AT,
8800 BFD_RELOC_MIPS_GOT16, mips_gp_register);
8803 /* FIXME: This won't work for a 64 bit address. */
8804 macro_build_lui (&offset_expr, AT);
8807 if (mips_opts.isa != ISA_MIPS1 || mips_opts.micromips)
8809 macro_build (&offset_expr, "ldc1", "T,o(b)",
8810 treg, BFD_RELOC_LO16, AT);
8819 /* Even on a big endian machine $fn comes before $fn+1. We have
8820 to adjust when loading from memory. */
8823 gas_assert (!mips_opts.micromips);
8824 gas_assert (mips_opts.isa == ISA_MIPS1);
8825 macro_build (&offset_expr, "lwc1", "T,o(b)",
8826 target_big_endian ? treg + 1 : treg, r, breg);
8827 /* FIXME: A possible overflow which I don't know how to deal
8829 offset_expr.X_add_number += 4;
8830 macro_build (&offset_expr, "lwc1", "T,o(b)",
8831 target_big_endian ? treg : treg + 1, r, breg);
8835 gas_assert (!mips_opts.micromips);
8836 gas_assert (mips_opts.isa == ISA_MIPS1);
8837 /* Even on a big endian machine $fn comes before $fn+1. We have
8838 to adjust when storing to memory. */
8839 macro_build (&offset_expr, "swc1", "T,o(b)",
8840 target_big_endian ? treg + 1 : treg, BFD_RELOC_LO16, breg);
8841 offset_expr.X_add_number += 4;
8842 macro_build (&offset_expr, "swc1", "T,o(b)",
8843 target_big_endian ? treg : treg + 1, BFD_RELOC_LO16, breg);
8847 gas_assert (!mips_opts.micromips);
8849 * The MIPS assembler seems to check for X_add_number not
8850 * being double aligned and generating:
8853 * addiu at,at,%lo(foo+1)
8856 * But, the resulting address is the same after relocation so why
8857 * generate the extra instruction?
8859 /* Itbl support may require additional care here. */
8862 if (mips_opts.isa != ISA_MIPS1)
8871 gas_assert (!mips_opts.micromips);
8872 /* Itbl support may require additional care here. */
8875 if (mips_opts.isa != ISA_MIPS1)
8885 if (HAVE_64BIT_GPRS)
8895 if (HAVE_64BIT_GPRS)
8903 if (offset_expr.X_op != O_symbol
8904 && offset_expr.X_op != O_constant)
8906 as_bad (_("Expression too complex"));
8907 offset_expr.X_op = O_constant;
8910 if (HAVE_32BIT_ADDRESSES
8911 && !IS_SEXT_32BIT_NUM (offset_expr.X_add_number))
8915 sprintf_vma (value, offset_expr.X_add_number);
8916 as_bad (_("Number (0x%s) larger than 32 bits"), value);
8919 /* Even on a big endian machine $fn comes before $fn+1. We have
8920 to adjust when loading from memory. We set coproc if we must
8921 load $fn+1 first. */
8922 /* Itbl support may require additional care here. */
8923 if (!target_big_endian)
8926 if (mips_pic == NO_PIC || offset_expr.X_op == O_constant)
8928 /* If this is a reference to a GP relative symbol, we want
8929 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
8930 <op> $treg+1,<sym>+4($gp) (BFD_RELOC_GPREL16)
8931 If we have a base register, we use this
8933 <op> $treg,<sym>($at) (BFD_RELOC_GPREL16)
8934 <op> $treg+1,<sym>+4($at) (BFD_RELOC_GPREL16)
8935 If this is not a GP relative symbol, we want
8936 lui $at,<sym> (BFD_RELOC_HI16_S)
8937 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
8938 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
8939 If there is a base register, we add it to $at after the
8940 lui instruction. If there is a constant, we always use
8942 if (offset_expr.X_op == O_symbol
8943 && (valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
8944 && !nopic_need_relax (offset_expr.X_add_symbol, 1))
8946 relax_start (offset_expr.X_add_symbol);
8949 tempreg = mips_gp_register;
8953 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
8954 AT, breg, mips_gp_register);
8959 /* Itbl support may require additional care here. */
8960 macro_build (&offset_expr, s, fmt, coproc ? treg + 1 : treg,
8961 BFD_RELOC_GPREL16, tempreg);
8962 offset_expr.X_add_number += 4;
8964 /* Set mips_optimize to 2 to avoid inserting an
8966 hold_mips_optimize = mips_optimize;
8968 /* Itbl support may require additional care here. */
8969 macro_build (&offset_expr, s, fmt, coproc ? treg : treg + 1,
8970 BFD_RELOC_GPREL16, tempreg);
8971 mips_optimize = hold_mips_optimize;
8975 offset_expr.X_add_number -= 4;
8978 macro_build_lui (&offset_expr, AT);
8980 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, breg, AT);
8981 /* Itbl support may require additional care here. */
8982 macro_build (&offset_expr, s, fmt, coproc ? treg + 1 : treg,
8983 BFD_RELOC_LO16, AT);
8984 /* FIXME: How do we handle overflow here? */
8985 offset_expr.X_add_number += 4;
8986 /* Itbl support may require additional care here. */
8987 macro_build (&offset_expr, s, fmt, coproc ? treg : treg + 1,
8988 BFD_RELOC_LO16, AT);
8989 if (mips_relax.sequence)
8992 else if (!mips_big_got)
8994 /* If this is a reference to an external symbol, we want
8995 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
9000 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
9002 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
9003 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
9004 If there is a base register we add it to $at before the
9005 lwc1 instructions. If there is a constant we include it
9006 in the lwc1 instructions. */
9008 expr1.X_add_number = offset_expr.X_add_number;
9009 if (expr1.X_add_number < -0x8000
9010 || expr1.X_add_number >= 0x8000 - 4)
9011 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
9012 load_got_offset (AT, &offset_expr);
9015 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, breg, AT);
9017 /* Set mips_optimize to 2 to avoid inserting an undesired
9019 hold_mips_optimize = mips_optimize;
9022 /* Itbl support may require additional care here. */
9023 relax_start (offset_expr.X_add_symbol);
9024 macro_build (&expr1, s, fmt, coproc ? treg + 1 : treg,
9025 BFD_RELOC_LO16, AT);
9026 expr1.X_add_number += 4;
9027 macro_build (&expr1, s, fmt, coproc ? treg : treg + 1,
9028 BFD_RELOC_LO16, AT);
9030 macro_build (&offset_expr, s, fmt, coproc ? treg + 1 : treg,
9031 BFD_RELOC_LO16, AT);
9032 offset_expr.X_add_number += 4;
9033 macro_build (&offset_expr, s, fmt, coproc ? treg : treg + 1,
9034 BFD_RELOC_LO16, AT);
9037 mips_optimize = hold_mips_optimize;
9039 else if (mips_big_got)
9043 /* If this is a reference to an external symbol, we want
9044 lui $at,<sym> (BFD_RELOC_MIPS_GOT_HI16)
9046 lw $at,<sym>($at) (BFD_RELOC_MIPS_GOT_LO16)
9051 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
9053 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
9054 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
9055 If there is a base register we add it to $at before the
9056 lwc1 instructions. If there is a constant we include it
9057 in the lwc1 instructions. */
9059 expr1.X_add_number = offset_expr.X_add_number;
9060 offset_expr.X_add_number = 0;
9061 if (expr1.X_add_number < -0x8000
9062 || expr1.X_add_number >= 0x8000 - 4)
9063 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
9064 gpdelay = reg_needs_delay (mips_gp_register);
9065 relax_start (offset_expr.X_add_symbol);
9066 macro_build (&offset_expr, "lui", LUI_FMT,
9067 AT, BFD_RELOC_MIPS_GOT_HI16);
9068 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
9069 AT, AT, mips_gp_register);
9070 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
9071 AT, BFD_RELOC_MIPS_GOT_LO16, AT);
9074 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, breg, AT);
9075 /* Itbl support may require additional care here. */
9076 macro_build (&expr1, s, fmt, coproc ? treg + 1 : treg,
9077 BFD_RELOC_LO16, AT);
9078 expr1.X_add_number += 4;
9080 /* Set mips_optimize to 2 to avoid inserting an undesired
9082 hold_mips_optimize = mips_optimize;
9084 /* Itbl support may require additional care here. */
9085 macro_build (&expr1, s, fmt, coproc ? treg : treg + 1,
9086 BFD_RELOC_LO16, AT);
9087 mips_optimize = hold_mips_optimize;
9088 expr1.X_add_number -= 4;
9091 offset_expr.X_add_number = expr1.X_add_number;
9093 macro_build (NULL, "nop", "");
9094 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", AT,
9095 BFD_RELOC_MIPS_GOT16, mips_gp_register);
9098 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, breg, AT);
9099 /* Itbl support may require additional care here. */
9100 macro_build (&offset_expr, s, fmt, coproc ? treg + 1 : treg,
9101 BFD_RELOC_LO16, AT);
9102 offset_expr.X_add_number += 4;
9104 /* Set mips_optimize to 2 to avoid inserting an undesired
9106 hold_mips_optimize = mips_optimize;
9108 /* Itbl support may require additional care here. */
9109 macro_build (&offset_expr, s, fmt, coproc ? treg : treg + 1,
9110 BFD_RELOC_LO16, AT);
9111 mips_optimize = hold_mips_optimize;
9120 s = HAVE_64BIT_GPRS ? "ld" : "lw";
9123 s = HAVE_64BIT_GPRS ? "sd" : "sw";
9125 macro_build (&offset_expr, s, "t,o(b)", treg,
9126 -1, offset_reloc[0], offset_reloc[1], offset_reloc[2],
9128 if (!HAVE_64BIT_GPRS)
9130 offset_expr.X_add_number += 4;
9131 macro_build (&offset_expr, s, "t,o(b)", treg + 1,
9132 -1, offset_reloc[0], offset_reloc[1], offset_reloc[2],
9153 /* New code added to support COPZ instructions.
9154 This code builds table entries out of the macros in mip_opcodes.
9155 R4000 uses interlocks to handle coproc delays.
9156 Other chips (like the R3000) require nops to be inserted for delays.
9158 FIXME: Currently, we require that the user handle delays.
9159 In order to fill delay slots for non-interlocked chips,
9160 we must have a way to specify delays based on the coprocessor.
9161 Eg. 4 cycles if load coproc reg from memory, 1 if in cache, etc.
9162 What are the side-effects of the cop instruction?
9163 What cache support might we have and what are its effects?
9164 Both coprocessor & memory require delays. how long???
9165 What registers are read/set/modified?
9167 If an itbl is provided to interpret cop instructions,
9168 this knowledge can be encoded in the itbl spec. */
9182 gas_assert (!mips_opts.micromips);
9183 if (NO_ISA_COP (mips_opts.arch)
9184 && (ip->insn_mo->pinfo2 & INSN2_M_FP_S) == 0)
9186 as_bad (_("Opcode not supported on this processor: %s"),
9187 mips_cpu_info_from_arch (mips_opts.arch)->name);
9191 /* For now we just do C (same as Cz). The parameter will be
9192 stored in insn_opcode by mips_ip. */
9193 macro_build (NULL, s, "C", ip->insn_opcode);
9197 move_register (dreg, sreg);
9203 macro_build (NULL, dbl ? "dmultu" : "multu", "s,t", sreg, treg);
9204 macro_build (NULL, "mflo", MFHL_FMT, dreg);
9210 /* The MIPS assembler some times generates shifts and adds. I'm
9211 not trying to be that fancy. GCC should do this for us
9214 load_register (AT, &imm_expr, dbl);
9215 macro_build (NULL, dbl ? "dmult" : "mult", "s,t", sreg, AT);
9216 macro_build (NULL, "mflo", MFHL_FMT, dreg);
9232 load_register (AT, &imm_expr, dbl);
9233 macro_build (NULL, dbl ? "dmult" : "mult", "s,t", sreg, imm ? AT : treg);
9234 macro_build (NULL, "mflo", MFHL_FMT, dreg);
9235 macro_build (NULL, dbl ? "dsra32" : "sra", SHFT_FMT, dreg, dreg, RA);
9236 macro_build (NULL, "mfhi", MFHL_FMT, AT);
9238 macro_build (NULL, "tne", TRAP_FMT, dreg, AT, 6);
9241 if (mips_opts.micromips)
9242 micromips_label_expr (&label_expr);
9244 label_expr.X_add_number = 8;
9245 macro_build (&label_expr, "beq", "s,t,p", dreg, AT);
9246 macro_build (NULL, "nop", "");
9247 macro_build (NULL, "break", BRK_FMT, 6);
9248 if (mips_opts.micromips)
9249 micromips_add_label ();
9252 macro_build (NULL, "mflo", MFHL_FMT, dreg);
9268 load_register (AT, &imm_expr, dbl);
9269 macro_build (NULL, dbl ? "dmultu" : "multu", "s,t",
9270 sreg, imm ? AT : treg);
9271 macro_build (NULL, "mfhi", MFHL_FMT, AT);
9272 macro_build (NULL, "mflo", MFHL_FMT, dreg);
9274 macro_build (NULL, "tne", TRAP_FMT, AT, ZERO, 6);
9277 if (mips_opts.micromips)
9278 micromips_label_expr (&label_expr);
9280 label_expr.X_add_number = 8;
9281 macro_build (&label_expr, "beq", "s,t,p", AT, ZERO);
9282 macro_build (NULL, "nop", "");
9283 macro_build (NULL, "break", BRK_FMT, 6);
9284 if (mips_opts.micromips)
9285 micromips_add_label ();
9291 if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_opts.arch))
9302 macro_build (NULL, "dnegu", "d,w", tempreg, treg);
9303 macro_build (NULL, "drorv", "d,t,s", dreg, sreg, tempreg);
9307 macro_build (NULL, "dsubu", "d,v,t", AT, ZERO, treg);
9308 macro_build (NULL, "dsrlv", "d,t,s", AT, sreg, AT);
9309 macro_build (NULL, "dsllv", "d,t,s", dreg, sreg, treg);
9310 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
9314 if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_opts.arch))
9325 macro_build (NULL, "negu", "d,w", tempreg, treg);
9326 macro_build (NULL, "rorv", "d,t,s", dreg, sreg, tempreg);
9330 macro_build (NULL, "subu", "d,v,t", AT, ZERO, treg);
9331 macro_build (NULL, "srlv", "d,t,s", AT, sreg, AT);
9332 macro_build (NULL, "sllv", "d,t,s", dreg, sreg, treg);
9333 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
9342 if (imm_expr.X_op != O_constant)
9343 as_bad (_("Improper rotate count"));
9344 rot = imm_expr.X_add_number & 0x3f;
9345 if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_opts.arch))
9347 rot = (64 - rot) & 0x3f;
9349 macro_build (NULL, "dror32", SHFT_FMT, dreg, sreg, rot - 32);
9351 macro_build (NULL, "dror", SHFT_FMT, dreg, sreg, rot);
9356 macro_build (NULL, "dsrl", SHFT_FMT, dreg, sreg, 0);
9359 l = (rot < 0x20) ? "dsll" : "dsll32";
9360 rr = ((0x40 - rot) < 0x20) ? "dsrl" : "dsrl32";
9363 macro_build (NULL, l, SHFT_FMT, AT, sreg, rot);
9364 macro_build (NULL, rr, SHFT_FMT, dreg, sreg, (0x20 - rot) & 0x1f);
9365 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
9373 if (imm_expr.X_op != O_constant)
9374 as_bad (_("Improper rotate count"));
9375 rot = imm_expr.X_add_number & 0x1f;
9376 if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_opts.arch))
9378 macro_build (NULL, "ror", SHFT_FMT, dreg, sreg, (32 - rot) & 0x1f);
9383 macro_build (NULL, "srl", SHFT_FMT, dreg, sreg, 0);
9387 macro_build (NULL, "sll", SHFT_FMT, AT, sreg, rot);
9388 macro_build (NULL, "srl", SHFT_FMT, dreg, sreg, (0x20 - rot) & 0x1f);
9389 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
9394 if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_opts.arch))
9396 macro_build (NULL, "drorv", "d,t,s", dreg, sreg, treg);
9400 macro_build (NULL, "dsubu", "d,v,t", AT, ZERO, treg);
9401 macro_build (NULL, "dsllv", "d,t,s", AT, sreg, AT);
9402 macro_build (NULL, "dsrlv", "d,t,s", dreg, sreg, treg);
9403 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
9407 if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_opts.arch))
9409 macro_build (NULL, "rorv", "d,t,s", dreg, sreg, treg);
9413 macro_build (NULL, "subu", "d,v,t", AT, ZERO, treg);
9414 macro_build (NULL, "sllv", "d,t,s", AT, sreg, AT);
9415 macro_build (NULL, "srlv", "d,t,s", dreg, sreg, treg);
9416 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
9425 if (imm_expr.X_op != O_constant)
9426 as_bad (_("Improper rotate count"));
9427 rot = imm_expr.X_add_number & 0x3f;
9428 if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_opts.arch))
9431 macro_build (NULL, "dror32", SHFT_FMT, dreg, sreg, rot - 32);
9433 macro_build (NULL, "dror", SHFT_FMT, dreg, sreg, rot);
9438 macro_build (NULL, "dsrl", SHFT_FMT, dreg, sreg, 0);
9441 rr = (rot < 0x20) ? "dsrl" : "dsrl32";
9442 l = ((0x40 - rot) < 0x20) ? "dsll" : "dsll32";
9445 macro_build (NULL, rr, SHFT_FMT, AT, sreg, rot);
9446 macro_build (NULL, l, SHFT_FMT, dreg, sreg, (0x20 - rot) & 0x1f);
9447 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
9455 if (imm_expr.X_op != O_constant)
9456 as_bad (_("Improper rotate count"));
9457 rot = imm_expr.X_add_number & 0x1f;
9458 if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_opts.arch))
9460 macro_build (NULL, "ror", SHFT_FMT, dreg, sreg, rot);
9465 macro_build (NULL, "srl", SHFT_FMT, dreg, sreg, 0);
9469 macro_build (NULL, "srl", SHFT_FMT, AT, sreg, rot);
9470 macro_build (NULL, "sll", SHFT_FMT, dreg, sreg, (0x20 - rot) & 0x1f);
9471 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
9477 macro_build (&expr1, "sltiu", "t,r,j", dreg, treg, BFD_RELOC_LO16);
9479 macro_build (&expr1, "sltiu", "t,r,j", dreg, sreg, BFD_RELOC_LO16);
9482 macro_build (NULL, "xor", "d,v,t", dreg, sreg, treg);
9483 macro_build (&expr1, "sltiu", "t,r,j", dreg, dreg, BFD_RELOC_LO16);
9488 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
9490 macro_build (&expr1, "sltiu", "t,r,j", dreg, sreg, BFD_RELOC_LO16);
9495 as_warn (_("Instruction %s: result is always false"),
9497 move_register (dreg, 0);
9500 if (CPU_HAS_SEQ (mips_opts.arch)
9501 && -512 <= imm_expr.X_add_number
9502 && imm_expr.X_add_number < 512)
9504 macro_build (NULL, "seqi", "t,r,+Q", dreg, sreg,
9505 (int) imm_expr.X_add_number);
9508 if (imm_expr.X_op == O_constant
9509 && imm_expr.X_add_number >= 0
9510 && imm_expr.X_add_number < 0x10000)
9512 macro_build (&imm_expr, "xori", "t,r,i", dreg, sreg, BFD_RELOC_LO16);
9514 else if (imm_expr.X_op == O_constant
9515 && imm_expr.X_add_number > -0x8000
9516 && imm_expr.X_add_number < 0)
9518 imm_expr.X_add_number = -imm_expr.X_add_number;
9519 macro_build (&imm_expr, HAVE_32BIT_GPRS ? "addiu" : "daddiu",
9520 "t,r,j", dreg, sreg, BFD_RELOC_LO16);
9522 else if (CPU_HAS_SEQ (mips_opts.arch))
9525 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
9526 macro_build (NULL, "seq", "d,v,t", dreg, sreg, AT);
9531 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
9532 macro_build (NULL, "xor", "d,v,t", dreg, sreg, AT);
9535 macro_build (&expr1, "sltiu", "t,r,j", dreg, dreg, BFD_RELOC_LO16);
9538 case M_SGE: /* sreg >= treg <==> not (sreg < treg) */
9544 macro_build (NULL, s, "d,v,t", dreg, sreg, treg);
9545 macro_build (&expr1, "xori", "t,r,i", dreg, dreg, BFD_RELOC_LO16);
9548 case M_SGE_I: /* sreg >= I <==> not (sreg < I) */
9550 if (imm_expr.X_op == O_constant
9551 && imm_expr.X_add_number >= -0x8000
9552 && imm_expr.X_add_number < 0x8000)
9554 macro_build (&imm_expr, mask == M_SGE_I ? "slti" : "sltiu", "t,r,j",
9555 dreg, sreg, BFD_RELOC_LO16);
9559 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
9560 macro_build (NULL, mask == M_SGE_I ? "slt" : "sltu", "d,v,t",
9564 macro_build (&expr1, "xori", "t,r,i", dreg, dreg, BFD_RELOC_LO16);
9567 case M_SGT: /* sreg > treg <==> treg < sreg */
9573 macro_build (NULL, s, "d,v,t", dreg, treg, sreg);
9576 case M_SGT_I: /* sreg > I <==> I < sreg */
9583 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
9584 macro_build (NULL, s, "d,v,t", dreg, AT, sreg);
9587 case M_SLE: /* sreg <= treg <==> treg >= sreg <==> not (treg < sreg) */
9593 macro_build (NULL, s, "d,v,t", dreg, treg, sreg);
9594 macro_build (&expr1, "xori", "t,r,i", dreg, dreg, BFD_RELOC_LO16);
9597 case M_SLE_I: /* sreg <= I <==> I >= sreg <==> not (I < sreg) */
9604 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
9605 macro_build (NULL, s, "d,v,t", dreg, AT, sreg);
9606 macro_build (&expr1, "xori", "t,r,i", dreg, dreg, BFD_RELOC_LO16);
9610 if (imm_expr.X_op == O_constant
9611 && imm_expr.X_add_number >= -0x8000
9612 && imm_expr.X_add_number < 0x8000)
9614 macro_build (&imm_expr, "slti", "t,r,j", dreg, sreg, BFD_RELOC_LO16);
9618 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
9619 macro_build (NULL, "slt", "d,v,t", dreg, sreg, AT);
9623 if (imm_expr.X_op == O_constant
9624 && imm_expr.X_add_number >= -0x8000
9625 && imm_expr.X_add_number < 0x8000)
9627 macro_build (&imm_expr, "sltiu", "t,r,j", dreg, sreg,
9632 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
9633 macro_build (NULL, "sltu", "d,v,t", dreg, sreg, AT);
9638 macro_build (NULL, "sltu", "d,v,t", dreg, 0, treg);
9640 macro_build (NULL, "sltu", "d,v,t", dreg, 0, sreg);
9643 macro_build (NULL, "xor", "d,v,t", dreg, sreg, treg);
9644 macro_build (NULL, "sltu", "d,v,t", dreg, 0, dreg);
9649 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
9651 macro_build (NULL, "sltu", "d,v,t", dreg, 0, sreg);
9656 as_warn (_("Instruction %s: result is always true"),
9658 macro_build (&expr1, HAVE_32BIT_GPRS ? "addiu" : "daddiu", "t,r,j",
9659 dreg, 0, BFD_RELOC_LO16);
9662 if (CPU_HAS_SEQ (mips_opts.arch)
9663 && -512 <= imm_expr.X_add_number
9664 && imm_expr.X_add_number < 512)
9666 macro_build (NULL, "snei", "t,r,+Q", dreg, sreg,
9667 (int) imm_expr.X_add_number);
9670 if (imm_expr.X_op == O_constant
9671 && imm_expr.X_add_number >= 0
9672 && imm_expr.X_add_number < 0x10000)
9674 macro_build (&imm_expr, "xori", "t,r,i", dreg, sreg, BFD_RELOC_LO16);
9676 else if (imm_expr.X_op == O_constant
9677 && imm_expr.X_add_number > -0x8000
9678 && imm_expr.X_add_number < 0)
9680 imm_expr.X_add_number = -imm_expr.X_add_number;
9681 macro_build (&imm_expr, HAVE_32BIT_GPRS ? "addiu" : "daddiu",
9682 "t,r,j", dreg, sreg, BFD_RELOC_LO16);
9684 else if (CPU_HAS_SEQ (mips_opts.arch))
9687 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
9688 macro_build (NULL, "sne", "d,v,t", dreg, sreg, AT);
9693 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
9694 macro_build (NULL, "xor", "d,v,t", dreg, sreg, AT);
9697 macro_build (NULL, "sltu", "d,v,t", dreg, 0, dreg);
9712 if (!mips_opts.micromips)
9714 if (imm_expr.X_op == O_constant
9715 && imm_expr.X_add_number > -0x200
9716 && imm_expr.X_add_number <= 0x200)
9718 macro_build (NULL, s, "t,r,.", dreg, sreg, -imm_expr.X_add_number);
9727 if (imm_expr.X_op == O_constant
9728 && imm_expr.X_add_number > -0x8000
9729 && imm_expr.X_add_number <= 0x8000)
9731 imm_expr.X_add_number = -imm_expr.X_add_number;
9732 macro_build (&imm_expr, s, "t,r,j", dreg, sreg, BFD_RELOC_LO16);
9737 load_register (AT, &imm_expr, dbl);
9738 macro_build (NULL, s2, "d,v,t", dreg, sreg, AT);
9760 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
9761 macro_build (NULL, s, "s,t", sreg, AT);
9766 gas_assert (!mips_opts.micromips);
9767 gas_assert (mips_opts.isa == ISA_MIPS1);
9769 sreg = (ip->insn_opcode >> 11) & 0x1f; /* floating reg */
9770 dreg = (ip->insn_opcode >> 06) & 0x1f; /* floating reg */
9773 * Is the double cfc1 instruction a bug in the mips assembler;
9774 * or is there a reason for it?
9777 macro_build (NULL, "cfc1", "t,G", treg, RA);
9778 macro_build (NULL, "cfc1", "t,G", treg, RA);
9779 macro_build (NULL, "nop", "");
9780 expr1.X_add_number = 3;
9781 macro_build (&expr1, "ori", "t,r,i", AT, treg, BFD_RELOC_LO16);
9782 expr1.X_add_number = 2;
9783 macro_build (&expr1, "xori", "t,r,i", AT, AT, BFD_RELOC_LO16);
9784 macro_build (NULL, "ctc1", "t,G", AT, RA);
9785 macro_build (NULL, "nop", "");
9786 macro_build (NULL, mask == M_TRUNCWD ? "cvt.w.d" : "cvt.w.s", "D,S",
9788 macro_build (NULL, "ctc1", "t,G", treg, RA);
9789 macro_build (NULL, "nop", "");
9812 off12 = mips_opts.micromips;
9820 off12 = mips_opts.micromips;
9836 off12 = mips_opts.micromips;
9845 off12 = mips_opts.micromips;
9850 if (!ab && offset_expr.X_add_number >= 0x8000 - off)
9851 as_bad (_("Operand overflow"));
9854 expr1.X_add_number = 0;
9859 load_address (tempreg, ep, &used_at);
9861 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
9862 tempreg, tempreg, breg);
9868 && (offset_expr.X_op != O_constant
9869 || !IS_SEXT_12BIT_NUM (offset_expr.X_add_number)
9870 || !IS_SEXT_12BIT_NUM (offset_expr.X_add_number + off)))
9874 macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", tempreg, breg,
9875 -1, offset_reloc[0], offset_reloc[1], offset_reloc[2]);
9880 else if (!ust && treg == breg)
9891 if (!target_big_endian)
9892 ep->X_add_number += off;
9894 macro_build (ep, s, "t,o(b)", tempreg, BFD_RELOC_LO16, breg);
9896 macro_build (NULL, s, "t,~(b)",
9897 tempreg, (unsigned long) ep->X_add_number, breg);
9899 if (!target_big_endian)
9900 ep->X_add_number -= off;
9902 ep->X_add_number += off;
9904 macro_build (ep, s2, "t,o(b)", tempreg, BFD_RELOC_LO16, breg);
9906 macro_build (NULL, s2, "t,~(b)",
9907 tempreg, (unsigned long) ep->X_add_number, breg);
9909 /* If necessary, move the result in tempreg to the final destination. */
9910 if (!ust && treg != tempreg)
9912 /* Protect second load's delay slot. */
9914 move_register (treg, tempreg);
9920 if (target_big_endian == ust)
9921 ep->X_add_number += off;
9922 tempreg = ust || ab ? treg : AT;
9923 macro_build (ep, s, "t,o(b)", tempreg, BFD_RELOC_LO16, breg);
9925 /* For halfword transfers we need a temporary register to shuffle
9926 bytes. Unfortunately for M_USH_A we have none available before
9927 the next store as AT holds the base address. We deal with this
9928 case by clobbering TREG and then restoring it as with ULH. */
9929 tempreg = ust == ab ? treg : AT;
9931 macro_build (NULL, "srl", SHFT_FMT, tempreg, treg, 8);
9933 if (target_big_endian == ust)
9934 ep->X_add_number -= off;
9936 ep->X_add_number += off;
9937 macro_build (ep, s2, "t,o(b)", tempreg, BFD_RELOC_LO16, breg);
9939 /* For M_USH_A re-retrieve the LSB. */
9942 if (target_big_endian)
9943 ep->X_add_number += off;
9945 ep->X_add_number -= off;
9946 macro_build (&expr1, "lbu", "t,o(b)", AT, BFD_RELOC_LO16, AT);
9948 /* For ULH and M_USH_A OR the LSB in. */
9951 tempreg = !ab ? AT : treg;
9952 macro_build (NULL, "sll", SHFT_FMT, tempreg, tempreg, 8);
9953 macro_build (NULL, "or", "d,v,t", treg, treg, AT);
9958 /* FIXME: Check if this is one of the itbl macros, since they
9959 are added dynamically. */
9960 as_bad (_("Macro %s not implemented yet"), ip->insn_mo->name);
9963 if (!mips_opts.at && used_at)
9964 as_bad (_("Macro used $at after \".set noat\""));
9967 /* Implement macros in mips16 mode. */
9970 mips16_macro (struct mips_cl_insn *ip)
9973 int xreg, yreg, zreg, tmp;
9976 const char *s, *s2, *s3;
9978 mask = ip->insn_mo->mask;
9980 xreg = MIPS16_EXTRACT_OPERAND (RX, *ip);
9981 yreg = MIPS16_EXTRACT_OPERAND (RY, *ip);
9982 zreg = MIPS16_EXTRACT_OPERAND (RZ, *ip);
9984 expr1.X_op = O_constant;
9985 expr1.X_op_symbol = NULL;
9986 expr1.X_add_symbol = NULL;
9987 expr1.X_add_number = 1;
10006 start_noreorder ();
10007 macro_build (NULL, dbl ? "ddiv" : "div", "0,x,y", xreg, yreg);
10008 expr1.X_add_number = 2;
10009 macro_build (&expr1, "bnez", "x,p", yreg);
10010 macro_build (NULL, "break", "6", 7);
10012 /* FIXME: The normal code checks for of -1 / -0x80000000 here,
10013 since that causes an overflow. We should do that as well,
10014 but I don't see how to do the comparisons without a temporary
10017 macro_build (NULL, s, "x", zreg);
10036 start_noreorder ();
10037 macro_build (NULL, s, "0,x,y", xreg, yreg);
10038 expr1.X_add_number = 2;
10039 macro_build (&expr1, "bnez", "x,p", yreg);
10040 macro_build (NULL, "break", "6", 7);
10042 macro_build (NULL, s2, "x", zreg);
10048 macro_build (NULL, dbl ? "dmultu" : "multu", "x,y", xreg, yreg);
10049 macro_build (NULL, "mflo", "x", zreg);
10057 if (imm_expr.X_op != O_constant)
10058 as_bad (_("Unsupported large constant"));
10059 imm_expr.X_add_number = -imm_expr.X_add_number;
10060 macro_build (&imm_expr, dbl ? "daddiu" : "addiu", "y,x,4", yreg, xreg);
10064 if (imm_expr.X_op != O_constant)
10065 as_bad (_("Unsupported large constant"));
10066 imm_expr.X_add_number = -imm_expr.X_add_number;
10067 macro_build (&imm_expr, "addiu", "x,k", xreg);
10071 if (imm_expr.X_op != O_constant)
10072 as_bad (_("Unsupported large constant"));
10073 imm_expr.X_add_number = -imm_expr.X_add_number;
10074 macro_build (&imm_expr, "daddiu", "y,j", yreg);
10096 goto do_reverse_branch;
10100 goto do_reverse_branch;
10112 goto do_reverse_branch;
10123 macro_build (NULL, s, "x,y", xreg, yreg);
10124 macro_build (&offset_expr, s2, "p");
10151 goto do_addone_branch_i;
10156 goto do_addone_branch_i;
10171 goto do_addone_branch_i;
10177 do_addone_branch_i:
10178 if (imm_expr.X_op != O_constant)
10179 as_bad (_("Unsupported large constant"));
10180 ++imm_expr.X_add_number;
10183 macro_build (&imm_expr, s, s3, xreg);
10184 macro_build (&offset_expr, s2, "p");
10188 expr1.X_add_number = 0;
10189 macro_build (&expr1, "slti", "x,8", yreg);
10191 move_register (xreg, yreg);
10192 expr1.X_add_number = 2;
10193 macro_build (&expr1, "bteqz", "p");
10194 macro_build (NULL, "neg", "x,w", xreg, xreg);
10198 /* For consistency checking, verify that all bits are specified either
10199 by the match/mask part of the instruction definition, or by the
10202 validate_mips_insn (const struct mips_opcode *opc)
10204 const char *p = opc->args;
10206 unsigned long used_bits = opc->mask;
10208 if ((used_bits & opc->match) != opc->match)
10210 as_bad (_("internal: bad mips opcode (mask error): %s %s"),
10211 opc->name, opc->args);
10214 #define USE_BITS(mask,shift) (used_bits |= ((mask) << (shift)))
10224 case '1': USE_BITS (OP_MASK_UDI1, OP_SH_UDI1); break;
10225 case '2': USE_BITS (OP_MASK_UDI2, OP_SH_UDI2); break;
10226 case '3': USE_BITS (OP_MASK_UDI3, OP_SH_UDI3); break;
10227 case '4': USE_BITS (OP_MASK_UDI4, OP_SH_UDI4); break;
10228 case 'A': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
10229 case 'B': USE_BITS (OP_MASK_INSMSB, OP_SH_INSMSB); break;
10230 case 'C': USE_BITS (OP_MASK_EXTMSBD, OP_SH_EXTMSBD); break;
10231 case 'D': USE_BITS (OP_MASK_RD, OP_SH_RD);
10232 USE_BITS (OP_MASK_SEL, OP_SH_SEL); break;
10233 case 'E': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
10234 case 'F': USE_BITS (OP_MASK_INSMSB, OP_SH_INSMSB); break;
10235 case 'G': USE_BITS (OP_MASK_EXTMSBD, OP_SH_EXTMSBD); break;
10236 case 'H': USE_BITS (OP_MASK_EXTMSBD, OP_SH_EXTMSBD); break;
10238 case 't': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
10239 case 'T': USE_BITS (OP_MASK_RT, OP_SH_RT);
10240 USE_BITS (OP_MASK_SEL, OP_SH_SEL); break;
10241 case 'x': USE_BITS (OP_MASK_BBITIND, OP_SH_BBITIND); break;
10242 case 'X': USE_BITS (OP_MASK_BBITIND, OP_SH_BBITIND); break;
10243 case 'p': USE_BITS (OP_MASK_CINSPOS, OP_SH_CINSPOS); break;
10244 case 'P': USE_BITS (OP_MASK_CINSPOS, OP_SH_CINSPOS); break;
10245 case 'Q': USE_BITS (OP_MASK_SEQI, OP_SH_SEQI); break;
10246 case 's': USE_BITS (OP_MASK_CINSLM1, OP_SH_CINSLM1); break;
10247 case 'S': USE_BITS (OP_MASK_CINSLM1, OP_SH_CINSLM1); break;
10248 case 'z': USE_BITS (OP_MASK_RZ, OP_SH_RZ); break;
10249 case 'Z': USE_BITS (OP_MASK_FZ, OP_SH_FZ); break;
10250 case 'a': USE_BITS (OP_MASK_OFFSET_A, OP_SH_OFFSET_A); break;
10251 case 'b': USE_BITS (OP_MASK_OFFSET_B, OP_SH_OFFSET_B); break;
10252 case 'c': USE_BITS (OP_MASK_OFFSET_C, OP_SH_OFFSET_C); break;
10255 as_bad (_("internal: bad mips opcode (unknown extension operand type `+%c'): %s %s"),
10256 c, opc->name, opc->args);
10260 case '<': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
10261 case '>': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
10263 case 'B': USE_BITS (OP_MASK_CODE20, OP_SH_CODE20); break;
10264 case 'C': USE_BITS (OP_MASK_COPZ, OP_SH_COPZ); break;
10265 case 'D': USE_BITS (OP_MASK_FD, OP_SH_FD); break;
10266 case 'E': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
10268 case 'G': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
10269 case 'H': USE_BITS (OP_MASK_SEL, OP_SH_SEL); break;
10271 case 'J': USE_BITS (OP_MASK_CODE19, OP_SH_CODE19); break;
10272 case 'K': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
10274 case 'M': USE_BITS (OP_MASK_CCC, OP_SH_CCC); break;
10275 case 'N': USE_BITS (OP_MASK_BCC, OP_SH_BCC); break;
10276 case 'O': USE_BITS (OP_MASK_ALN, OP_SH_ALN); break;
10277 case 'Q': USE_BITS (OP_MASK_VSEL, OP_SH_VSEL);
10278 USE_BITS (OP_MASK_FT, OP_SH_FT); break;
10279 case 'R': USE_BITS (OP_MASK_FR, OP_SH_FR); break;
10280 case 'S': USE_BITS (OP_MASK_FS, OP_SH_FS); break;
10281 case 'T': USE_BITS (OP_MASK_FT, OP_SH_FT); break;
10282 case 'V': USE_BITS (OP_MASK_FS, OP_SH_FS); break;
10283 case 'W': USE_BITS (OP_MASK_FT, OP_SH_FT); break;
10284 case 'X': USE_BITS (OP_MASK_FD, OP_SH_FD); break;
10285 case 'Y': USE_BITS (OP_MASK_FS, OP_SH_FS); break;
10286 case 'Z': USE_BITS (OP_MASK_FT, OP_SH_FT); break;
10287 case 'a': USE_BITS (OP_MASK_TARGET, OP_SH_TARGET); break;
10288 case 'b': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
10289 case 'c': USE_BITS (OP_MASK_CODE, OP_SH_CODE); break;
10290 case 'd': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
10292 case 'h': USE_BITS (OP_MASK_PREFX, OP_SH_PREFX); break;
10293 case 'i': USE_BITS (OP_MASK_IMMEDIATE, OP_SH_IMMEDIATE); break;
10294 case 'j': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
10295 case 'k': USE_BITS (OP_MASK_CACHE, OP_SH_CACHE); break;
10297 case 'o': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
10298 case 'p': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
10299 case 'q': USE_BITS (OP_MASK_CODE2, OP_SH_CODE2); break;
10300 case 'r': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
10301 case 's': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
10302 case 't': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
10303 case 'u': USE_BITS (OP_MASK_IMMEDIATE, OP_SH_IMMEDIATE); break;
10304 case 'v': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
10305 case 'w': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
10308 case 'P': USE_BITS (OP_MASK_PERFREG, OP_SH_PERFREG); break;
10309 case 'U': USE_BITS (OP_MASK_RD, OP_SH_RD);
10310 USE_BITS (OP_MASK_RT, OP_SH_RT); break;
10311 case 'e': USE_BITS (OP_MASK_VECBYTE, OP_SH_VECBYTE); break;
10312 case '%': USE_BITS (OP_MASK_VECALIGN, OP_SH_VECALIGN); break;
10315 case '1': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
10316 case '2': USE_BITS (OP_MASK_BP, OP_SH_BP); break;
10317 case '3': USE_BITS (OP_MASK_SA3, OP_SH_SA3); break;
10318 case '4': USE_BITS (OP_MASK_SA4, OP_SH_SA4); break;
10319 case '5': USE_BITS (OP_MASK_IMM8, OP_SH_IMM8); break;
10320 case '6': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
10321 case '7': USE_BITS (OP_MASK_DSPACC, OP_SH_DSPACC); break;
10322 case '8': USE_BITS (OP_MASK_WRDSP, OP_SH_WRDSP); break;
10323 case '9': USE_BITS (OP_MASK_DSPACC_S, OP_SH_DSPACC_S);break;
10324 case '0': USE_BITS (OP_MASK_DSPSFT, OP_SH_DSPSFT); break;
10325 case '\'': USE_BITS (OP_MASK_RDDSP, OP_SH_RDDSP); break;
10326 case ':': USE_BITS (OP_MASK_DSPSFT_7, OP_SH_DSPSFT_7);break;
10327 case '@': USE_BITS (OP_MASK_IMM10, OP_SH_IMM10); break;
10328 case '!': USE_BITS (OP_MASK_MT_U, OP_SH_MT_U); break;
10329 case '$': USE_BITS (OP_MASK_MT_H, OP_SH_MT_H); break;
10330 case '*': USE_BITS (OP_MASK_MTACC_T, OP_SH_MTACC_T); break;
10331 case '&': USE_BITS (OP_MASK_MTACC_D, OP_SH_MTACC_D); break;
10332 case '\\': USE_BITS (OP_MASK_3BITPOS, OP_SH_3BITPOS); break;
10333 case '~': USE_BITS (OP_MASK_OFFSET12, OP_SH_OFFSET12); break;
10334 case 'g': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
10336 as_bad (_("internal: bad mips opcode (unknown operand type `%c'): %s %s"),
10337 c, opc->name, opc->args);
10341 if (used_bits != 0xffffffff)
10343 as_bad (_("internal: bad mips opcode (bits 0x%lx undefined): %s %s"),
10344 ~used_bits & 0xffffffff, opc->name, opc->args);
10350 /* For consistency checking, verify that the length implied matches the
10351 major opcode and that all bits are specified either by the match/mask
10352 part of the instruction definition, or by the operand list. */
10355 validate_micromips_insn (const struct mips_opcode *opc)
10357 unsigned long match = opc->match;
10358 unsigned long mask = opc->mask;
10359 const char *p = opc->args;
10360 unsigned long insn_bits;
10361 unsigned long used_bits;
10362 unsigned long major;
10363 unsigned int length;
10367 if ((mask & match) != match)
10369 as_bad (_("Internal error: bad microMIPS opcode (mask error): %s %s"),
10370 opc->name, opc->args);
10373 length = micromips_insn_length (opc);
10374 if (length != 2 && length != 4)
10376 as_bad (_("Internal error: bad microMIPS opcode (incorrect length: %u): "
10377 "%s %s"), length, opc->name, opc->args);
10380 major = match >> (10 + 8 * (length - 2));
10381 if ((length == 2 && (major & 7) != 1 && (major & 6) != 2)
10382 || (length == 4 && (major & 7) != 0 && (major & 4) != 4))
10384 as_bad (_("Internal error: bad microMIPS opcode "
10385 "(opcode/length mismatch): %s %s"), opc->name, opc->args);
10389 /* Shift piecewise to avoid an overflow where unsigned long is 32-bit. */
10390 insn_bits = 1 << 4 * length;
10391 insn_bits <<= 4 * length;
10394 #define USE_BITS(field) \
10395 (used_bits |= MICROMIPSOP_MASK_##field << MICROMIPSOP_SH_##field)
10406 case 'A': USE_BITS (EXTLSB); break;
10407 case 'B': USE_BITS (INSMSB); break;
10408 case 'C': USE_BITS (EXTMSBD); break;
10409 case 'D': USE_BITS (RS); USE_BITS (SEL); break;
10410 case 'E': USE_BITS (EXTLSB); break;
10411 case 'F': USE_BITS (INSMSB); break;
10412 case 'G': USE_BITS (EXTMSBD); break;
10413 case 'H': USE_BITS (EXTMSBD); break;
10415 as_bad (_("Internal error: bad mips opcode "
10416 "(unknown extension operand type `%c%c'): %s %s"),
10417 e, c, opc->name, opc->args);
10425 case 'A': USE_BITS (IMMA); break;
10426 case 'B': USE_BITS (IMMB); break;
10427 case 'C': USE_BITS (IMMC); break;
10428 case 'D': USE_BITS (IMMD); break;
10429 case 'E': USE_BITS (IMME); break;
10430 case 'F': USE_BITS (IMMF); break;
10431 case 'G': USE_BITS (IMMG); break;
10432 case 'H': USE_BITS (IMMH); break;
10433 case 'I': USE_BITS (IMMI); break;
10434 case 'J': USE_BITS (IMMJ); break;
10435 case 'L': USE_BITS (IMML); break;
10436 case 'M': USE_BITS (IMMM); break;
10437 case 'N': USE_BITS (IMMN); break;
10438 case 'O': USE_BITS (IMMO); break;
10439 case 'P': USE_BITS (IMMP); break;
10440 case 'Q': USE_BITS (IMMQ); break;
10441 case 'U': USE_BITS (IMMU); break;
10442 case 'W': USE_BITS (IMMW); break;
10443 case 'X': USE_BITS (IMMX); break;
10444 case 'Y': USE_BITS (IMMY); break;
10447 case 'b': USE_BITS (MB); break;
10448 case 'c': USE_BITS (MC); break;
10449 case 'd': USE_BITS (MD); break;
10450 case 'e': USE_BITS (ME); break;
10451 case 'f': USE_BITS (MF); break;
10452 case 'g': USE_BITS (MG); break;
10453 case 'h': USE_BITS (MH); break;
10454 case 'i': USE_BITS (MI); break;
10455 case 'j': USE_BITS (MJ); break;
10456 case 'l': USE_BITS (ML); break;
10457 case 'm': USE_BITS (MM); break;
10458 case 'n': USE_BITS (MN); break;
10459 case 'p': USE_BITS (MP); break;
10460 case 'q': USE_BITS (MQ); break;
10468 as_bad (_("Internal error: bad mips opcode "
10469 "(unknown extension operand type `%c%c'): %s %s"),
10470 e, c, opc->name, opc->args);
10474 case '.': USE_BITS (OFFSET10); break;
10475 case '1': USE_BITS (STYPE); break;
10476 case '<': USE_BITS (SHAMT); break;
10477 case '>': USE_BITS (SHAMT); break;
10478 case 'B': USE_BITS (CODE10); break;
10479 case 'C': USE_BITS (COPZ); break;
10480 case 'D': USE_BITS (FD); break;
10481 case 'E': USE_BITS (RT); break;
10482 case 'G': USE_BITS (RS); break;
10483 case 'H': USE_BITS (SEL); break;
10484 case 'K': USE_BITS (RS); break;
10485 case 'M': USE_BITS (CCC); break;
10486 case 'N': USE_BITS (BCC); break;
10487 case 'R': USE_BITS (FR); break;
10488 case 'S': USE_BITS (FS); break;
10489 case 'T': USE_BITS (FT); break;
10490 case 'V': USE_BITS (FS); break;
10491 case '\\': USE_BITS (3BITPOS); break;
10492 case 'a': USE_BITS (TARGET); break;
10493 case 'b': USE_BITS (RS); break;
10494 case 'c': USE_BITS (CODE); break;
10495 case 'd': USE_BITS (RD); break;
10496 case 'h': USE_BITS (PREFX); break;
10497 case 'i': USE_BITS (IMMEDIATE); break;
10498 case 'j': USE_BITS (DELTA); break;
10499 case 'k': USE_BITS (CACHE); break;
10500 case 'n': USE_BITS (RT); break;
10501 case 'o': USE_BITS (DELTA); break;
10502 case 'p': USE_BITS (DELTA); break;
10503 case 'q': USE_BITS (CODE2); break;
10504 case 'r': USE_BITS (RS); break;
10505 case 's': USE_BITS (RS); break;
10506 case 't': USE_BITS (RT); break;
10507 case 'u': USE_BITS (IMMEDIATE); break;
10508 case 'v': USE_BITS (RS); break;
10509 case 'w': USE_BITS (RT); break;
10510 case 'y': USE_BITS (RS3); break;
10512 case '|': USE_BITS (TRAP); break;
10513 case '~': USE_BITS (OFFSET12); break;
10515 as_bad (_("Internal error: bad microMIPS opcode "
10516 "(unknown operand type `%c'): %s %s"),
10517 c, opc->name, opc->args);
10521 if (used_bits != insn_bits)
10523 if (~used_bits & insn_bits)
10524 as_bad (_("Internal error: bad microMIPS opcode "
10525 "(bits 0x%lx undefined): %s %s"),
10526 ~used_bits & insn_bits, opc->name, opc->args);
10527 if (used_bits & ~insn_bits)
10528 as_bad (_("Internal error: bad microMIPS opcode "
10529 "(bits 0x%lx defined): %s %s"),
10530 used_bits & ~insn_bits, opc->name, opc->args);
10536 /* UDI immediates. */
10537 struct mips_immed {
10539 unsigned int shift;
10540 unsigned long mask;
10544 static const struct mips_immed mips_immed[] = {
10545 { '1', OP_SH_UDI1, OP_MASK_UDI1, 0},
10546 { '2', OP_SH_UDI2, OP_MASK_UDI2, 0},
10547 { '3', OP_SH_UDI3, OP_MASK_UDI3, 0},
10548 { '4', OP_SH_UDI4, OP_MASK_UDI4, 0},
10552 /* Check whether an odd floating-point register is allowed. */
10554 mips_oddfpreg_ok (const struct mips_opcode *insn, int argnum)
10556 const char *s = insn->name;
10558 if (insn->pinfo == INSN_MACRO)
10559 /* Let a macro pass, we'll catch it later when it is expanded. */
10562 if (ISA_HAS_ODD_SINGLE_FPR (mips_opts.isa))
10564 /* Allow odd registers for single-precision ops. */
10565 switch (insn->pinfo & (FP_S | FP_D))
10569 return 1; /* both single precision - ok */
10571 return 0; /* both double precision - fail */
10576 /* Cvt.w.x and cvt.x.w allow an odd register for a 'w' or 's' operand. */
10577 s = strchr (insn->name, '.');
10579 s = s != NULL ? strchr (s + 1, '.') : NULL;
10580 return (s != NULL && (s[1] == 'w' || s[1] == 's'));
10583 /* Single-precision coprocessor loads and moves are OK too. */
10584 if ((insn->pinfo & FP_S)
10585 && (insn->pinfo & (INSN_COPROC_MEMORY_DELAY | INSN_STORE_MEMORY
10586 | INSN_LOAD_COPROC_DELAY | INSN_COPROC_MOVE_DELAY)))
10592 /* Check if EXPR is a constant between MIN (inclusive) and MAX (exclusive)
10593 taking bits from BIT up. */
10595 expr_const_in_range (expressionS *ep, offsetT min, offsetT max, int bit)
10597 return (ep->X_op == O_constant
10598 && (ep->X_add_number & ((1 << bit) - 1)) == 0
10599 && ep->X_add_number >= min << bit
10600 && ep->X_add_number < max << bit);
10603 /* This routine assembles an instruction into its binary format. As a
10604 side effect, it sets one of the global variables imm_reloc or
10605 offset_reloc to the type of relocation to do if one of the operands
10606 is an address expression. */
10609 mips_ip (char *str, struct mips_cl_insn *ip)
10611 bfd_boolean wrong_delay_slot_insns = FALSE;
10612 bfd_boolean need_delay_slot_ok = TRUE;
10613 struct mips_opcode *firstinsn = NULL;
10614 const struct mips_opcode *past;
10615 struct hash_control *hash;
10619 struct mips_opcode *insn;
10621 unsigned int regno;
10622 unsigned int lastregno;
10623 unsigned int destregno = 0;
10624 unsigned int lastpos = 0;
10625 unsigned int limlo, limhi;
10627 offsetT min_range, max_range;
10631 unsigned int rtype;
10637 if (mips_opts.micromips)
10639 hash = micromips_op_hash;
10640 past = µmips_opcodes[bfd_micromips_num_opcodes];
10645 past = &mips_opcodes[NUMOPCODES];
10647 forced_insn_length = 0;
10650 /* We first try to match an instruction up to a space or to the end. */
10651 for (end = 0; str[end] != '\0' && !ISSPACE (str[end]); end++)
10654 /* Make a copy of the instruction so that we can fiddle with it. */
10655 name = alloca (end + 1);
10656 memcpy (name, str, end);
10661 insn = (struct mips_opcode *) hash_find (hash, name);
10663 if (insn != NULL || !mips_opts.micromips)
10665 if (forced_insn_length)
10668 /* See if there's an instruction size override suffix,
10669 either `16' or `32', at the end of the mnemonic proper,
10670 that defines the operation, i.e. before the first `.'
10671 character if any. Strip it and retry. */
10672 dot = strchr (name, '.');
10673 opend = dot != NULL ? dot - name : end;
10676 if (name[opend - 2] == '1' && name[opend - 1] == '6')
10677 forced_insn_length = 2;
10678 else if (name[opend - 2] == '3' && name[opend - 1] == '2')
10679 forced_insn_length = 4;
10682 memcpy (name + opend - 2, name + opend, end - opend + 1);
10686 insn_error = _("Unrecognized opcode");
10690 /* For microMIPS instructions placed in a fixed-length branch delay slot
10691 we make up to two passes over the relevant fragment of the opcode
10692 table. First we try instructions that meet the delay slot's length
10693 requirement. If none matched, then we retry with the remaining ones
10694 and if one matches, then we use it and then issue an appropriate
10695 warning later on. */
10696 argsStart = s = str + end;
10699 bfd_boolean delay_slot_ok;
10700 bfd_boolean size_ok;
10703 gas_assert (strcmp (insn->name, name) == 0);
10705 ok = is_opcode_valid (insn);
10706 size_ok = is_size_valid (insn);
10707 delay_slot_ok = is_delay_slot_valid (insn);
10708 if (!delay_slot_ok && !wrong_delay_slot_insns)
10711 wrong_delay_slot_insns = TRUE;
10713 if (!ok || !size_ok || delay_slot_ok != need_delay_slot_ok)
10715 static char buf[256];
10717 if (insn + 1 < past && strcmp (insn->name, insn[1].name) == 0)
10722 if (wrong_delay_slot_insns && need_delay_slot_ok)
10724 gas_assert (firstinsn);
10725 need_delay_slot_ok = FALSE;
10735 sprintf (buf, _("Opcode not supported on this processor: %s (%s)"),
10736 mips_cpu_info_from_arch (mips_opts.arch)->name,
10737 mips_cpu_info_from_isa (mips_opts.isa)->name);
10739 sprintf (buf, _("Unrecognized %u-bit version of microMIPS opcode"),
10740 8 * forced_insn_length);
10746 create_insn (ip, insn);
10749 lastregno = 0xffffffff;
10750 for (args = insn->args;; ++args)
10754 s += strspn (s, " \t");
10758 case '\0': /* end of args */
10763 case '2': /* DSP 2-bit unsigned immediate in bit 11. */
10764 gas_assert (!mips_opts.micromips);
10765 my_getExpression (&imm_expr, s);
10766 check_absolute_expr (ip, &imm_expr);
10767 if ((unsigned long) imm_expr.X_add_number != 1
10768 && (unsigned long) imm_expr.X_add_number != 3)
10770 as_bad (_("BALIGN immediate not 1 or 3 (%lu)"),
10771 (unsigned long) imm_expr.X_add_number);
10773 INSERT_OPERAND (0, BP, *ip, imm_expr.X_add_number);
10774 imm_expr.X_op = O_absent;
10778 case '3': /* DSP 3-bit unsigned immediate in bit 21. */
10779 gas_assert (!mips_opts.micromips);
10780 my_getExpression (&imm_expr, s);
10781 check_absolute_expr (ip, &imm_expr);
10782 if (imm_expr.X_add_number & ~OP_MASK_SA3)
10784 as_bad (_("DSP immediate not in range 0..%d (%lu)"),
10785 OP_MASK_SA3, (unsigned long) imm_expr.X_add_number);
10787 INSERT_OPERAND (0, SA3, *ip, imm_expr.X_add_number);
10788 imm_expr.X_op = O_absent;
10792 case '4': /* DSP 4-bit unsigned immediate in bit 21. */
10793 gas_assert (!mips_opts.micromips);
10794 my_getExpression (&imm_expr, s);
10795 check_absolute_expr (ip, &imm_expr);
10796 if (imm_expr.X_add_number & ~OP_MASK_SA4)
10798 as_bad (_("DSP immediate not in range 0..%d (%lu)"),
10799 OP_MASK_SA4, (unsigned long) imm_expr.X_add_number);
10801 INSERT_OPERAND (0, SA4, *ip, imm_expr.X_add_number);
10802 imm_expr.X_op = O_absent;
10806 case '5': /* DSP 8-bit unsigned immediate in bit 16. */
10807 gas_assert (!mips_opts.micromips);
10808 my_getExpression (&imm_expr, s);
10809 check_absolute_expr (ip, &imm_expr);
10810 if (imm_expr.X_add_number & ~OP_MASK_IMM8)
10812 as_bad (_("DSP immediate not in range 0..%d (%lu)"),
10813 OP_MASK_IMM8, (unsigned long) imm_expr.X_add_number);
10815 INSERT_OPERAND (0, IMM8, *ip, imm_expr.X_add_number);
10816 imm_expr.X_op = O_absent;
10820 case '6': /* DSP 5-bit unsigned immediate in bit 21. */
10821 gas_assert (!mips_opts.micromips);
10822 my_getExpression (&imm_expr, s);
10823 check_absolute_expr (ip, &imm_expr);
10824 if (imm_expr.X_add_number & ~OP_MASK_RS)
10826 as_bad (_("DSP immediate not in range 0..%d (%lu)"),
10827 OP_MASK_RS, (unsigned long) imm_expr.X_add_number);
10829 INSERT_OPERAND (0, RS, *ip, imm_expr.X_add_number);
10830 imm_expr.X_op = O_absent;
10834 case '7': /* Four DSP accumulators in bits 11,12. */
10835 gas_assert (!mips_opts.micromips);
10836 if (s[0] == '$' && s[1] == 'a' && s[2] == 'c' &&
10837 s[3] >= '0' && s[3] <= '3')
10839 regno = s[3] - '0';
10841 INSERT_OPERAND (0, DSPACC, *ip, regno);
10845 as_bad (_("Invalid dsp acc register"));
10848 case '8': /* DSP 6-bit unsigned immediate in bit 11. */
10849 gas_assert (!mips_opts.micromips);
10850 my_getExpression (&imm_expr, s);
10851 check_absolute_expr (ip, &imm_expr);
10852 if (imm_expr.X_add_number & ~OP_MASK_WRDSP)
10854 as_bad (_("DSP immediate not in range 0..%d (%lu)"),
10856 (unsigned long) imm_expr.X_add_number);
10858 INSERT_OPERAND (0, WRDSP, *ip, imm_expr.X_add_number);
10859 imm_expr.X_op = O_absent;
10863 case '9': /* Four DSP accumulators in bits 21,22. */
10864 gas_assert (!mips_opts.micromips);
10865 if (s[0] == '$' && s[1] == 'a' && s[2] == 'c' &&
10866 s[3] >= '0' && s[3] <= '3')
10868 regno = s[3] - '0';
10870 INSERT_OPERAND (0, DSPACC_S, *ip, regno);
10874 as_bad (_("Invalid dsp acc register"));
10877 case '0': /* DSP 6-bit signed immediate in bit 20. */
10878 gas_assert (!mips_opts.micromips);
10879 my_getExpression (&imm_expr, s);
10880 check_absolute_expr (ip, &imm_expr);
10881 min_range = -((OP_MASK_DSPSFT + 1) >> 1);
10882 max_range = ((OP_MASK_DSPSFT + 1) >> 1) - 1;
10883 if (imm_expr.X_add_number < min_range ||
10884 imm_expr.X_add_number > max_range)
10886 as_bad (_("DSP immediate not in range %ld..%ld (%ld)"),
10887 (long) min_range, (long) max_range,
10888 (long) imm_expr.X_add_number);
10890 INSERT_OPERAND (0, DSPSFT, *ip, imm_expr.X_add_number);
10891 imm_expr.X_op = O_absent;
10895 case '\'': /* DSP 6-bit unsigned immediate in bit 16. */
10896 gas_assert (!mips_opts.micromips);
10897 my_getExpression (&imm_expr, s);
10898 check_absolute_expr (ip, &imm_expr);
10899 if (imm_expr.X_add_number & ~OP_MASK_RDDSP)
10901 as_bad (_("DSP immediate not in range 0..%d (%lu)"),
10903 (unsigned long) imm_expr.X_add_number);
10905 INSERT_OPERAND (0, RDDSP, *ip, imm_expr.X_add_number);
10906 imm_expr.X_op = O_absent;
10910 case ':': /* DSP 7-bit signed immediate in bit 19. */
10911 gas_assert (!mips_opts.micromips);
10912 my_getExpression (&imm_expr, s);
10913 check_absolute_expr (ip, &imm_expr);
10914 min_range = -((OP_MASK_DSPSFT_7 + 1) >> 1);
10915 max_range = ((OP_MASK_DSPSFT_7 + 1) >> 1) - 1;
10916 if (imm_expr.X_add_number < min_range ||
10917 imm_expr.X_add_number > max_range)
10919 as_bad (_("DSP immediate not in range %ld..%ld (%ld)"),
10920 (long) min_range, (long) max_range,
10921 (long) imm_expr.X_add_number);
10923 INSERT_OPERAND (0, DSPSFT_7, *ip, imm_expr.X_add_number);
10924 imm_expr.X_op = O_absent;
10928 case '@': /* DSP 10-bit signed immediate in bit 16. */
10929 gas_assert (!mips_opts.micromips);
10930 my_getExpression (&imm_expr, s);
10931 check_absolute_expr (ip, &imm_expr);
10932 min_range = -((OP_MASK_IMM10 + 1) >> 1);
10933 max_range = ((OP_MASK_IMM10 + 1) >> 1) - 1;
10934 if (imm_expr.X_add_number < min_range ||
10935 imm_expr.X_add_number > max_range)
10937 as_bad (_("DSP immediate not in range %ld..%ld (%ld)"),
10938 (long) min_range, (long) max_range,
10939 (long) imm_expr.X_add_number);
10941 INSERT_OPERAND (0, IMM10, *ip, imm_expr.X_add_number);
10942 imm_expr.X_op = O_absent;
10946 case '!': /* MT usermode flag bit. */
10947 gas_assert (!mips_opts.micromips);
10948 my_getExpression (&imm_expr, s);
10949 check_absolute_expr (ip, &imm_expr);
10950 if (imm_expr.X_add_number & ~OP_MASK_MT_U)
10951 as_bad (_("MT usermode bit not 0 or 1 (%lu)"),
10952 (unsigned long) imm_expr.X_add_number);
10953 INSERT_OPERAND (0, MT_U, *ip, imm_expr.X_add_number);
10954 imm_expr.X_op = O_absent;
10958 case '$': /* MT load high flag bit. */
10959 gas_assert (!mips_opts.micromips);
10960 my_getExpression (&imm_expr, s);
10961 check_absolute_expr (ip, &imm_expr);
10962 if (imm_expr.X_add_number & ~OP_MASK_MT_H)
10963 as_bad (_("MT load high bit not 0 or 1 (%lu)"),
10964 (unsigned long) imm_expr.X_add_number);
10965 INSERT_OPERAND (0, MT_H, *ip, imm_expr.X_add_number);
10966 imm_expr.X_op = O_absent;
10970 case '*': /* Four DSP accumulators in bits 18,19. */
10971 gas_assert (!mips_opts.micromips);
10972 if (s[0] == '$' && s[1] == 'a' && s[2] == 'c' &&
10973 s[3] >= '0' && s[3] <= '3')
10975 regno = s[3] - '0';
10977 INSERT_OPERAND (0, MTACC_T, *ip, regno);
10981 as_bad (_("Invalid dsp/smartmips acc register"));
10984 case '&': /* Four DSP accumulators in bits 13,14. */
10985 gas_assert (!mips_opts.micromips);
10986 if (s[0] == '$' && s[1] == 'a' && s[2] == 'c' &&
10987 s[3] >= '0' && s[3] <= '3')
10989 regno = s[3] - '0';
10991 INSERT_OPERAND (0, MTACC_D, *ip, regno);
10995 as_bad (_("Invalid dsp/smartmips acc register"));
10998 case '\\': /* 3-bit bit position. */
11000 unsigned long mask = (mips_opts.micromips
11001 ? MICROMIPSOP_MASK_3BITPOS
11002 : OP_MASK_3BITPOS);
11004 my_getExpression (&imm_expr, s);
11005 check_absolute_expr (ip, &imm_expr);
11006 if ((unsigned long) imm_expr.X_add_number > mask)
11007 as_warn (_("Bit position for %s not in range 0..%lu (%lu)"),
11009 mask, (unsigned long) imm_expr.X_add_number);
11010 INSERT_OPERAND (mips_opts.micromips,
11011 3BITPOS, *ip, imm_expr.X_add_number);
11012 imm_expr.X_op = O_absent;
11026 INSERT_OPERAND (mips_opts.micromips, RS, *ip, lastregno);
11030 INSERT_OPERAND (mips_opts.micromips, RT, *ip, lastregno);
11034 gas_assert (!mips_opts.micromips);
11035 INSERT_OPERAND (0, FT, *ip, lastregno);
11039 INSERT_OPERAND (mips_opts.micromips, FS, *ip, lastregno);
11045 /* Handle optional base register.
11046 Either the base register is omitted or
11047 we must have a left paren. */
11048 /* This is dependent on the next operand specifier
11049 is a base register specification. */
11050 gas_assert (args[1] == 'b'
11051 || (mips_opts.micromips
11053 && (args[2] == 'l' || args[2] == 'n'
11054 || args[2] == 's' || args[2] == 'a')));
11055 if (*s == '\0' && args[1] == 'b')
11057 /* Fall through. */
11059 case ')': /* These must match exactly. */
11064 case '[': /* These must match exactly. */
11066 gas_assert (!mips_opts.micromips);
11071 case '+': /* Opcode extension character. */
11074 case '1': /* UDI immediates. */
11078 gas_assert (!mips_opts.micromips);
11080 const struct mips_immed *imm = mips_immed;
11082 while (imm->type && imm->type != *args)
11086 my_getExpression (&imm_expr, s);
11087 check_absolute_expr (ip, &imm_expr);
11088 if ((unsigned long) imm_expr.X_add_number & ~imm->mask)
11090 as_warn (_("Illegal %s number (%lu, 0x%lx)"),
11091 imm->desc ? imm->desc : ip->insn_mo->name,
11092 (unsigned long) imm_expr.X_add_number,
11093 (unsigned long) imm_expr.X_add_number);
11094 imm_expr.X_add_number &= imm->mask;
11096 ip->insn_opcode |= ((unsigned long) imm_expr.X_add_number
11098 imm_expr.X_op = O_absent;
11103 case 'A': /* ins/ext position, becomes LSB. */
11112 my_getExpression (&imm_expr, s);
11113 check_absolute_expr (ip, &imm_expr);
11114 if ((unsigned long) imm_expr.X_add_number < limlo
11115 || (unsigned long) imm_expr.X_add_number > limhi)
11117 as_bad (_("Improper position (%lu)"),
11118 (unsigned long) imm_expr.X_add_number);
11119 imm_expr.X_add_number = limlo;
11121 lastpos = imm_expr.X_add_number;
11122 INSERT_OPERAND (mips_opts.micromips,
11123 EXTLSB, *ip, imm_expr.X_add_number);
11124 imm_expr.X_op = O_absent;
11128 case 'B': /* ins size, becomes MSB. */
11137 my_getExpression (&imm_expr, s);
11138 check_absolute_expr (ip, &imm_expr);
11139 /* Check for negative input so that small negative numbers
11140 will not succeed incorrectly. The checks against
11141 (pos+size) transitively check "size" itself,
11142 assuming that "pos" is reasonable. */
11143 if ((long) imm_expr.X_add_number < 0
11144 || ((unsigned long) imm_expr.X_add_number
11146 || ((unsigned long) imm_expr.X_add_number
11147 + lastpos) > limhi)
11149 as_bad (_("Improper insert size (%lu, position %lu)"),
11150 (unsigned long) imm_expr.X_add_number,
11151 (unsigned long) lastpos);
11152 imm_expr.X_add_number = limlo - lastpos;
11154 INSERT_OPERAND (mips_opts.micromips, INSMSB, *ip,
11155 lastpos + imm_expr.X_add_number - 1);
11156 imm_expr.X_op = O_absent;
11160 case 'C': /* ext size, becomes MSBD. */
11173 my_getExpression (&imm_expr, s);
11174 check_absolute_expr (ip, &imm_expr);
11175 /* Check for negative input so that small negative numbers
11176 will not succeed incorrectly. The checks against
11177 (pos+size) transitively check "size" itself,
11178 assuming that "pos" is reasonable. */
11179 if ((long) imm_expr.X_add_number < 0
11180 || ((unsigned long) imm_expr.X_add_number
11182 || ((unsigned long) imm_expr.X_add_number
11183 + lastpos) > limhi)
11185 as_bad (_("Improper extract size (%lu, position %lu)"),
11186 (unsigned long) imm_expr.X_add_number,
11187 (unsigned long) lastpos);
11188 imm_expr.X_add_number = limlo - lastpos;
11190 INSERT_OPERAND (mips_opts.micromips,
11191 EXTMSBD, *ip, imm_expr.X_add_number - 1);
11192 imm_expr.X_op = O_absent;
11197 /* +D is for disassembly only; never match. */
11201 /* "+I" is like "I", except that imm2_expr is used. */
11202 my_getExpression (&imm2_expr, s);
11203 if (imm2_expr.X_op != O_big
11204 && imm2_expr.X_op != O_constant)
11205 insn_error = _("absolute expression required");
11206 if (HAVE_32BIT_GPRS)
11207 normalize_constant_expr (&imm2_expr);
11211 case 'T': /* Coprocessor register. */
11212 gas_assert (!mips_opts.micromips);
11213 /* +T is for disassembly only; never match. */
11216 case 't': /* Coprocessor register number. */
11217 gas_assert (!mips_opts.micromips);
11218 if (s[0] == '$' && ISDIGIT (s[1]))
11228 while (ISDIGIT (*s));
11230 as_bad (_("Invalid register number (%d)"), regno);
11233 INSERT_OPERAND (0, RT, *ip, regno);
11238 as_bad (_("Invalid coprocessor 0 register number"));
11242 /* bbit[01] and bbit[01]32 bit index. Give error if index
11243 is not in the valid range. */
11244 gas_assert (!mips_opts.micromips);
11245 my_getExpression (&imm_expr, s);
11246 check_absolute_expr (ip, &imm_expr);
11247 if ((unsigned) imm_expr.X_add_number > 31)
11249 as_bad (_("Improper bit index (%lu)"),
11250 (unsigned long) imm_expr.X_add_number);
11251 imm_expr.X_add_number = 0;
11253 INSERT_OPERAND (0, BBITIND, *ip, imm_expr.X_add_number);
11254 imm_expr.X_op = O_absent;
11259 /* bbit[01] bit index when bbit is used but we generate
11260 bbit[01]32 because the index is over 32. Move to the
11261 next candidate if index is not in the valid range. */
11262 gas_assert (!mips_opts.micromips);
11263 my_getExpression (&imm_expr, s);
11264 check_absolute_expr (ip, &imm_expr);
11265 if ((unsigned) imm_expr.X_add_number < 32
11266 || (unsigned) imm_expr.X_add_number > 63)
11268 INSERT_OPERAND (0, BBITIND, *ip, imm_expr.X_add_number - 32);
11269 imm_expr.X_op = O_absent;
11274 /* cins, cins32, exts and exts32 position field. Give error
11275 if it's not in the valid range. */
11276 gas_assert (!mips_opts.micromips);
11277 my_getExpression (&imm_expr, s);
11278 check_absolute_expr (ip, &imm_expr);
11279 if ((unsigned) imm_expr.X_add_number > 31)
11281 as_bad (_("Improper position (%lu)"),
11282 (unsigned long) imm_expr.X_add_number);
11283 imm_expr.X_add_number = 0;
11285 /* Make the pos explicit to simplify +S. */
11286 lastpos = imm_expr.X_add_number + 32;
11287 INSERT_OPERAND (0, CINSPOS, *ip, imm_expr.X_add_number);
11288 imm_expr.X_op = O_absent;
11293 /* cins, cins32, exts and exts32 position field. Move to
11294 the next candidate if it's not in the valid range. */
11295 gas_assert (!mips_opts.micromips);
11296 my_getExpression (&imm_expr, s);
11297 check_absolute_expr (ip, &imm_expr);
11298 if ((unsigned) imm_expr.X_add_number < 32
11299 || (unsigned) imm_expr.X_add_number > 63)
11301 lastpos = imm_expr.X_add_number;
11302 INSERT_OPERAND (0, CINSPOS, *ip, imm_expr.X_add_number - 32);
11303 imm_expr.X_op = O_absent;
11308 /* cins and exts length-minus-one field. */
11309 gas_assert (!mips_opts.micromips);
11310 my_getExpression (&imm_expr, s);
11311 check_absolute_expr (ip, &imm_expr);
11312 if ((unsigned long) imm_expr.X_add_number > 31)
11314 as_bad (_("Improper size (%lu)"),
11315 (unsigned long) imm_expr.X_add_number);
11316 imm_expr.X_add_number = 0;
11318 INSERT_OPERAND (0, CINSLM1, *ip, imm_expr.X_add_number);
11319 imm_expr.X_op = O_absent;
11324 /* cins32/exts32 and cins/exts aliasing cint32/exts32
11325 length-minus-one field. */
11326 gas_assert (!mips_opts.micromips);
11327 my_getExpression (&imm_expr, s);
11328 check_absolute_expr (ip, &imm_expr);
11329 if ((long) imm_expr.X_add_number < 0
11330 || (unsigned long) imm_expr.X_add_number + lastpos > 63)
11332 as_bad (_("Improper size (%lu)"),
11333 (unsigned long) imm_expr.X_add_number);
11334 imm_expr.X_add_number = 0;
11336 INSERT_OPERAND (0, CINSLM1, *ip, imm_expr.X_add_number);
11337 imm_expr.X_op = O_absent;
11342 /* seqi/snei immediate field. */
11343 gas_assert (!mips_opts.micromips);
11344 my_getExpression (&imm_expr, s);
11345 check_absolute_expr (ip, &imm_expr);
11346 if ((long) imm_expr.X_add_number < -512
11347 || (long) imm_expr.X_add_number >= 512)
11349 as_bad (_("Improper immediate (%ld)"),
11350 (long) imm_expr.X_add_number);
11351 imm_expr.X_add_number = 0;
11353 INSERT_OPERAND (0, SEQI, *ip, imm_expr.X_add_number);
11354 imm_expr.X_op = O_absent;
11358 case 'a': /* 8-bit signed offset in bit 6 */
11359 gas_assert (!mips_opts.micromips);
11360 my_getExpression (&imm_expr, s);
11361 check_absolute_expr (ip, &imm_expr);
11362 min_range = -((OP_MASK_OFFSET_A + 1) >> 1);
11363 max_range = ((OP_MASK_OFFSET_A + 1) >> 1) - 1;
11364 if (imm_expr.X_add_number < min_range
11365 || imm_expr.X_add_number > max_range)
11367 as_bad (_("Offset not in range %ld..%ld (%ld)"),
11368 (long) min_range, (long) max_range,
11369 (long) imm_expr.X_add_number);
11371 INSERT_OPERAND (0, OFFSET_A, *ip, imm_expr.X_add_number);
11372 imm_expr.X_op = O_absent;
11376 case 'b': /* 8-bit signed offset in bit 3 */
11377 gas_assert (!mips_opts.micromips);
11378 my_getExpression (&imm_expr, s);
11379 check_absolute_expr (ip, &imm_expr);
11380 min_range = -((OP_MASK_OFFSET_B + 1) >> 1);
11381 max_range = ((OP_MASK_OFFSET_B + 1) >> 1) - 1;
11382 if (imm_expr.X_add_number < min_range
11383 || imm_expr.X_add_number > max_range)
11385 as_bad (_("Offset not in range %ld..%ld (%ld)"),
11386 (long) min_range, (long) max_range,
11387 (long) imm_expr.X_add_number);
11389 INSERT_OPERAND (0, OFFSET_B, *ip, imm_expr.X_add_number);
11390 imm_expr.X_op = O_absent;
11394 case 'c': /* 9-bit signed offset in bit 6 */
11395 gas_assert (!mips_opts.micromips);
11396 my_getExpression (&imm_expr, s);
11397 check_absolute_expr (ip, &imm_expr);
11398 min_range = -((OP_MASK_OFFSET_C + 1) >> 1);
11399 max_range = ((OP_MASK_OFFSET_C + 1) >> 1) - 1;
11400 /* We check the offset range before adjusted. */
11403 if (imm_expr.X_add_number < min_range
11404 || imm_expr.X_add_number > max_range)
11406 as_bad (_("Offset not in range %ld..%ld (%ld)"),
11407 (long) min_range, (long) max_range,
11408 (long) imm_expr.X_add_number);
11410 if (imm_expr.X_add_number & 0xf)
11412 as_bad (_("Offset not 16 bytes alignment (%ld)"),
11413 (long) imm_expr.X_add_number);
11415 /* Right shift 4 bits to adjust the offset operand. */
11416 INSERT_OPERAND (0, OFFSET_C, *ip,
11417 imm_expr.X_add_number >> 4);
11418 imm_expr.X_op = O_absent;
11423 gas_assert (!mips_opts.micromips);
11424 if (!reg_lookup (&s, RTYPE_NUM | RTYPE_GP, ®no))
11426 if (regno == AT && mips_opts.at)
11428 if (mips_opts.at == ATREG)
11429 as_warn (_("used $at without \".set noat\""));
11431 as_warn (_("used $%u with \".set at=$%u\""),
11432 regno, mips_opts.at);
11434 INSERT_OPERAND (0, RZ, *ip, regno);
11438 gas_assert (!mips_opts.micromips);
11439 if (!reg_lookup (&s, RTYPE_FPU, ®no))
11441 INSERT_OPERAND (0, FZ, *ip, regno);
11445 as_bad (_("Internal error: bad %s opcode "
11446 "(unknown extension operand type `+%c'): %s %s"),
11447 mips_opts.micromips ? "microMIPS" : "MIPS",
11448 *args, insn->name, insn->args);
11449 /* Further processing is fruitless. */
11454 case '.': /* 10-bit offset. */
11455 gas_assert (mips_opts.micromips);
11456 case '~': /* 12-bit offset. */
11458 int shift = *args == '.' ? 9 : 11;
11461 /* Check whether there is only a single bracketed expression
11462 left. If so, it must be the base register and the
11463 constant must be zero. */
11464 if (*s == '(' && strchr (s + 1, '(') == 0)
11467 /* If this value won't fit into the offset, then go find
11468 a macro that will generate a 16- or 32-bit offset code
11470 i = my_getSmallExpression (&imm_expr, imm_reloc, s);
11471 if ((i == 0 && (imm_expr.X_op != O_constant
11472 || imm_expr.X_add_number >= 1 << shift
11473 || imm_expr.X_add_number < -1 << shift))
11476 imm_expr.X_op = O_absent;
11480 INSERT_OPERAND (1, OFFSET10, *ip, imm_expr.X_add_number);
11482 INSERT_OPERAND (mips_opts.micromips,
11483 OFFSET12, *ip, imm_expr.X_add_number);
11484 imm_expr.X_op = O_absent;
11489 case '<': /* must be at least one digit */
11491 * According to the manual, if the shift amount is greater
11492 * than 31 or less than 0, then the shift amount should be
11493 * mod 32. In reality the mips assembler issues an error.
11494 * We issue a warning and mask out all but the low 5 bits.
11496 my_getExpression (&imm_expr, s);
11497 check_absolute_expr (ip, &imm_expr);
11498 if ((unsigned long) imm_expr.X_add_number > 31)
11499 as_warn (_("Improper shift amount (%lu)"),
11500 (unsigned long) imm_expr.X_add_number);
11501 INSERT_OPERAND (mips_opts.micromips,
11502 SHAMT, *ip, imm_expr.X_add_number);
11503 imm_expr.X_op = O_absent;
11507 case '>': /* shift amount minus 32 */
11508 my_getExpression (&imm_expr, s);
11509 check_absolute_expr (ip, &imm_expr);
11510 if ((unsigned long) imm_expr.X_add_number < 32
11511 || (unsigned long) imm_expr.X_add_number > 63)
11513 INSERT_OPERAND (mips_opts.micromips,
11514 SHAMT, *ip, imm_expr.X_add_number - 32);
11515 imm_expr.X_op = O_absent;
11519 case 'k': /* CACHE code. */
11520 case 'h': /* PREFX code. */
11521 case '1': /* SYNC type. */
11522 my_getExpression (&imm_expr, s);
11523 check_absolute_expr (ip, &imm_expr);
11524 if ((unsigned long) imm_expr.X_add_number > 31)
11525 as_warn (_("Invalid value for `%s' (%lu)"),
11527 (unsigned long) imm_expr.X_add_number);
11531 if (mips_fix_cn63xxp1
11532 && !mips_opts.micromips
11533 && strcmp ("pref", insn->name) == 0)
11534 switch (imm_expr.X_add_number)
11543 case 31: /* These are ok. */
11546 default: /* The rest must be changed to 28. */
11547 imm_expr.X_add_number = 28;
11550 INSERT_OPERAND (mips_opts.micromips,
11551 CACHE, *ip, imm_expr.X_add_number);
11554 INSERT_OPERAND (mips_opts.micromips,
11555 PREFX, *ip, imm_expr.X_add_number);
11558 INSERT_OPERAND (mips_opts.micromips,
11559 STYPE, *ip, imm_expr.X_add_number);
11562 imm_expr.X_op = O_absent;
11566 case 'c': /* BREAK code. */
11568 unsigned long mask = (mips_opts.micromips
11569 ? MICROMIPSOP_MASK_CODE
11572 my_getExpression (&imm_expr, s);
11573 check_absolute_expr (ip, &imm_expr);
11574 if ((unsigned long) imm_expr.X_add_number > mask)
11575 as_warn (_("Code for %s not in range 0..%lu (%lu)"),
11577 mask, (unsigned long) imm_expr.X_add_number);
11578 INSERT_OPERAND (mips_opts.micromips,
11579 CODE, *ip, imm_expr.X_add_number);
11580 imm_expr.X_op = O_absent;
11585 case 'q': /* Lower BREAK code. */
11587 unsigned long mask = (mips_opts.micromips
11588 ? MICROMIPSOP_MASK_CODE2
11591 my_getExpression (&imm_expr, s);
11592 check_absolute_expr (ip, &imm_expr);
11593 if ((unsigned long) imm_expr.X_add_number > mask)
11594 as_warn (_("Lower code for %s not in range 0..%lu (%lu)"),
11596 mask, (unsigned long) imm_expr.X_add_number);
11597 INSERT_OPERAND (mips_opts.micromips,
11598 CODE2, *ip, imm_expr.X_add_number);
11599 imm_expr.X_op = O_absent;
11604 case 'B': /* 20- or 10-bit syscall/break/wait code. */
11606 unsigned long mask = (mips_opts.micromips
11607 ? MICROMIPSOP_MASK_CODE10
11610 my_getExpression (&imm_expr, s);
11611 check_absolute_expr (ip, &imm_expr);
11612 if ((unsigned long) imm_expr.X_add_number > mask)
11613 as_warn (_("Code for %s not in range 0..%lu (%lu)"),
11615 mask, (unsigned long) imm_expr.X_add_number);
11616 if (mips_opts.micromips)
11617 INSERT_OPERAND (1, CODE10, *ip, imm_expr.X_add_number);
11619 INSERT_OPERAND (0, CODE20, *ip, imm_expr.X_add_number);
11620 imm_expr.X_op = O_absent;
11625 case 'C': /* 25- or 23-bit coprocessor code. */
11627 unsigned long mask = (mips_opts.micromips
11628 ? MICROMIPSOP_MASK_COPZ
11631 my_getExpression (&imm_expr, s);
11632 check_absolute_expr (ip, &imm_expr);
11633 if ((unsigned long) imm_expr.X_add_number > mask)
11634 as_warn (_("Coproccesor code > %u bits (%lu)"),
11635 mips_opts.micromips ? 23U : 25U,
11636 (unsigned long) imm_expr.X_add_number);
11637 INSERT_OPERAND (mips_opts.micromips,
11638 COPZ, *ip, imm_expr.X_add_number);
11639 imm_expr.X_op = O_absent;
11644 case 'J': /* 19-bit WAIT code. */
11645 gas_assert (!mips_opts.micromips);
11646 my_getExpression (&imm_expr, s);
11647 check_absolute_expr (ip, &imm_expr);
11648 if ((unsigned long) imm_expr.X_add_number > OP_MASK_CODE19)
11650 as_warn (_("Illegal 19-bit code (%lu)"),
11651 (unsigned long) imm_expr.X_add_number);
11652 imm_expr.X_add_number &= OP_MASK_CODE19;
11654 INSERT_OPERAND (0, CODE19, *ip, imm_expr.X_add_number);
11655 imm_expr.X_op = O_absent;
11659 case 'P': /* Performance register. */
11660 gas_assert (!mips_opts.micromips);
11661 my_getExpression (&imm_expr, s);
11662 check_absolute_expr (ip, &imm_expr);
11663 if (imm_expr.X_add_number != 0 && imm_expr.X_add_number != 1)
11664 as_warn (_("Invalid performance register (%lu)"),
11665 (unsigned long) imm_expr.X_add_number);
11666 INSERT_OPERAND (0, PERFREG, *ip, imm_expr.X_add_number);
11667 imm_expr.X_op = O_absent;
11671 case 'G': /* Coprocessor destination register. */
11673 unsigned long opcode = ip->insn_opcode;
11674 unsigned long mask;
11675 unsigned int types;
11678 if (mips_opts.micromips)
11680 mask = ~((MICROMIPSOP_MASK_RT << MICROMIPSOP_SH_RT)
11681 | (MICROMIPSOP_MASK_RS << MICROMIPSOP_SH_RS)
11682 | (MICROMIPSOP_MASK_SEL << MICROMIPSOP_SH_SEL));
11686 case 0x000000fc: /* mfc0 */
11687 case 0x000002fc: /* mtc0 */
11688 case 0x580000fc: /* dmfc0 */
11689 case 0x580002fc: /* dmtc0 */
11699 opcode = (opcode >> OP_SH_OP) & OP_MASK_OP;
11700 cop0 = opcode == OP_OP_COP0;
11702 types = RTYPE_NUM | (cop0 ? RTYPE_CP0 : RTYPE_GP);
11703 ok = reg_lookup (&s, types, ®no);
11704 if (mips_opts.micromips)
11705 INSERT_OPERAND (1, RS, *ip, regno);
11707 INSERT_OPERAND (0, RD, *ip, regno);
11716 case 'y': /* ALNV.PS source register. */
11717 gas_assert (mips_opts.micromips);
11719 case 'x': /* Ignore register name. */
11720 case 'U': /* Destination register (CLO/CLZ). */
11721 case 'g': /* Coprocessor destination register. */
11722 gas_assert (!mips_opts.micromips);
11723 case 'b': /* Base register. */
11724 case 'd': /* Destination register. */
11725 case 's': /* Source register. */
11726 case 't': /* Target register. */
11727 case 'r': /* Both target and source. */
11728 case 'v': /* Both dest and source. */
11729 case 'w': /* Both dest and target. */
11730 case 'E': /* Coprocessor target register. */
11731 case 'K': /* RDHWR destination register. */
11732 case 'z': /* Must be zero register. */
11735 if (*args == 'E' || *args == 'K')
11736 ok = reg_lookup (&s, RTYPE_NUM, ®no);
11739 ok = reg_lookup (&s, RTYPE_NUM | RTYPE_GP, ®no);
11740 if (regno == AT && mips_opts.at)
11742 if (mips_opts.at == ATREG)
11743 as_warn (_("Used $at without \".set noat\""));
11745 as_warn (_("Used $%u with \".set at=$%u\""),
11746 regno, mips_opts.at);
11756 if (c == 'r' || c == 'v' || c == 'w')
11763 /* 'z' only matches $0. */
11764 if (c == 'z' && regno != 0)
11767 if (c == 's' && !strncmp (ip->insn_mo->name, "jalr", 4))
11769 if (regno == lastregno)
11772 = _("Source and destination must be different");
11775 if (regno == 31 && lastregno == 0xffffffff)
11778 = _("A destination register must be supplied");
11782 /* Now that we have assembled one operand, we use the args
11783 string to figure out where it goes in the instruction. */
11790 INSERT_OPERAND (mips_opts.micromips, RS, *ip, regno);
11794 if (mips_opts.micromips)
11795 INSERT_OPERAND (1, RS, *ip, regno);
11797 INSERT_OPERAND (0, RD, *ip, regno);
11802 INSERT_OPERAND (mips_opts.micromips, RD, *ip, regno);
11806 gas_assert (!mips_opts.micromips);
11807 INSERT_OPERAND (0, RD, *ip, regno);
11808 INSERT_OPERAND (0, RT, *ip, regno);
11814 INSERT_OPERAND (mips_opts.micromips, RT, *ip, regno);
11818 gas_assert (mips_opts.micromips);
11819 INSERT_OPERAND (1, RS3, *ip, regno);
11823 /* This case exists because on the r3000 trunc
11824 expands into a macro which requires a gp
11825 register. On the r6000 or r4000 it is
11826 assembled into a single instruction which
11827 ignores the register. Thus the insn version
11828 is MIPS_ISA2 and uses 'x', and the macro
11829 version is MIPS_ISA1 and uses 't'. */
11833 /* This case is for the div instruction, which
11834 acts differently if the destination argument
11835 is $0. This only matches $0, and is checked
11836 outside the switch. */
11846 INSERT_OPERAND (mips_opts.micromips, RS, *ip, lastregno);
11850 INSERT_OPERAND (mips_opts.micromips, RT, *ip, lastregno);
11855 case 'O': /* MDMX alignment immediate constant. */
11856 gas_assert (!mips_opts.micromips);
11857 my_getExpression (&imm_expr, s);
11858 check_absolute_expr (ip, &imm_expr);
11859 if ((unsigned long) imm_expr.X_add_number > OP_MASK_ALN)
11860 as_warn (_("Improper align amount (%ld), using low bits"),
11861 (long) imm_expr.X_add_number);
11862 INSERT_OPERAND (0, ALN, *ip, imm_expr.X_add_number);
11863 imm_expr.X_op = O_absent;
11867 case 'Q': /* MDMX vector, element sel, or const. */
11870 /* MDMX Immediate. */
11871 gas_assert (!mips_opts.micromips);
11872 my_getExpression (&imm_expr, s);
11873 check_absolute_expr (ip, &imm_expr);
11874 if ((unsigned long) imm_expr.X_add_number > OP_MASK_FT)
11875 as_warn (_("Invalid MDMX Immediate (%ld)"),
11876 (long) imm_expr.X_add_number);
11877 INSERT_OPERAND (0, FT, *ip, imm_expr.X_add_number);
11878 if (ip->insn_opcode & (OP_MASK_VSEL << OP_SH_VSEL))
11879 ip->insn_opcode |= MDMX_FMTSEL_IMM_QH << OP_SH_VSEL;
11881 ip->insn_opcode |= MDMX_FMTSEL_IMM_OB << OP_SH_VSEL;
11882 imm_expr.X_op = O_absent;
11886 /* Not MDMX Immediate. Fall through. */
11887 case 'X': /* MDMX destination register. */
11888 case 'Y': /* MDMX source register. */
11889 case 'Z': /* MDMX target register. */
11892 gas_assert (!mips_opts.micromips);
11893 case 'D': /* Floating point destination register. */
11894 case 'S': /* Floating point source register. */
11895 case 'T': /* Floating point target register. */
11896 case 'R': /* Floating point source register. */
11900 || (mips_opts.ase_mdmx
11901 && (ip->insn_mo->pinfo & FP_D)
11902 && (ip->insn_mo->pinfo & (INSN_COPROC_MOVE_DELAY
11903 | INSN_COPROC_MEMORY_DELAY
11904 | INSN_LOAD_COPROC_DELAY
11905 | INSN_LOAD_MEMORY_DELAY
11906 | INSN_STORE_MEMORY))))
11907 rtype |= RTYPE_VEC;
11909 if (reg_lookup (&s, rtype, ®no))
11911 if ((regno & 1) != 0
11913 && !mips_oddfpreg_ok (ip->insn_mo, argnum))
11914 as_warn (_("Float register should be even, was %d"),
11922 if (c == 'V' || c == 'W')
11933 INSERT_OPERAND (mips_opts.micromips, FD, *ip, regno);
11939 INSERT_OPERAND (mips_opts.micromips, FS, *ip, regno);
11943 /* This is like 'Z', but also needs to fix the MDMX
11944 vector/scalar select bits. Note that the
11945 scalar immediate case is handled above. */
11948 int is_qh = (ip->insn_opcode & (1 << OP_SH_VSEL));
11949 int max_el = (is_qh ? 3 : 7);
11951 my_getExpression(&imm_expr, s);
11952 check_absolute_expr (ip, &imm_expr);
11954 if (imm_expr.X_add_number > max_el)
11955 as_bad (_("Bad element selector %ld"),
11956 (long) imm_expr.X_add_number);
11957 imm_expr.X_add_number &= max_el;
11958 ip->insn_opcode |= (imm_expr.X_add_number
11961 imm_expr.X_op = O_absent;
11963 as_warn (_("Expecting ']' found '%s'"), s);
11969 if (ip->insn_opcode & (OP_MASK_VSEL << OP_SH_VSEL))
11970 ip->insn_opcode |= (MDMX_FMTSEL_VEC_QH
11973 ip->insn_opcode |= (MDMX_FMTSEL_VEC_OB <<
11976 /* Fall through. */
11980 INSERT_OPERAND (mips_opts.micromips, FT, *ip, regno);
11984 INSERT_OPERAND (mips_opts.micromips, FR, *ip, regno);
11994 INSERT_OPERAND (mips_opts.micromips, FS, *ip, lastregno);
11998 INSERT_OPERAND (mips_opts.micromips, FT, *ip, lastregno);
12004 my_getExpression (&imm_expr, s);
12005 if (imm_expr.X_op != O_big
12006 && imm_expr.X_op != O_constant)
12007 insn_error = _("absolute expression required");
12008 if (HAVE_32BIT_GPRS)
12009 normalize_constant_expr (&imm_expr);
12014 my_getExpression (&offset_expr, s);
12015 normalize_address_expr (&offset_expr);
12016 *imm_reloc = BFD_RELOC_32;
12029 unsigned char temp[8];
12031 unsigned int length;
12036 /* These only appear as the last operand in an
12037 instruction, and every instruction that accepts
12038 them in any variant accepts them in all variants.
12039 This means we don't have to worry about backing out
12040 any changes if the instruction does not match.
12042 The difference between them is the size of the
12043 floating point constant and where it goes. For 'F'
12044 and 'L' the constant is 64 bits; for 'f' and 'l' it
12045 is 32 bits. Where the constant is placed is based
12046 on how the MIPS assembler does things:
12049 f -- immediate value
12052 The .lit4 and .lit8 sections are only used if
12053 permitted by the -G argument.
12055 The code below needs to know whether the target register
12056 is 32 or 64 bits wide. It relies on the fact 'f' and
12057 'F' are used with GPR-based instructions and 'l' and
12058 'L' are used with FPR-based instructions. */
12060 f64 = *args == 'F' || *args == 'L';
12061 using_gprs = *args == 'F' || *args == 'f';
12063 save_in = input_line_pointer;
12064 input_line_pointer = s;
12065 err = md_atof (f64 ? 'd' : 'f', (char *) temp, &len);
12067 s = input_line_pointer;
12068 input_line_pointer = save_in;
12069 if (err != NULL && *err != '\0')
12071 as_bad (_("Bad floating point constant: %s"), err);
12072 memset (temp, '\0', sizeof temp);
12073 length = f64 ? 8 : 4;
12076 gas_assert (length == (unsigned) (f64 ? 8 : 4));
12080 && (g_switch_value < 4
12081 || (temp[0] == 0 && temp[1] == 0)
12082 || (temp[2] == 0 && temp[3] == 0))))
12084 imm_expr.X_op = O_constant;
12085 if (!target_big_endian)
12086 imm_expr.X_add_number = bfd_getl32 (temp);
12088 imm_expr.X_add_number = bfd_getb32 (temp);
12090 else if (length > 4
12091 && !mips_disable_float_construction
12092 /* Constants can only be constructed in GPRs and
12093 copied to FPRs if the GPRs are at least as wide
12094 as the FPRs. Force the constant into memory if
12095 we are using 64-bit FPRs but the GPRs are only
12098 || !(HAVE_64BIT_FPRS && HAVE_32BIT_GPRS))
12099 && ((temp[0] == 0 && temp[1] == 0)
12100 || (temp[2] == 0 && temp[3] == 0))
12101 && ((temp[4] == 0 && temp[5] == 0)
12102 || (temp[6] == 0 && temp[7] == 0)))
12104 /* The value is simple enough to load with a couple of
12105 instructions. If using 32-bit registers, set
12106 imm_expr to the high order 32 bits and offset_expr to
12107 the low order 32 bits. Otherwise, set imm_expr to
12108 the entire 64 bit constant. */
12109 if (using_gprs ? HAVE_32BIT_GPRS : HAVE_32BIT_FPRS)
12111 imm_expr.X_op = O_constant;
12112 offset_expr.X_op = O_constant;
12113 if (!target_big_endian)
12115 imm_expr.X_add_number = bfd_getl32 (temp + 4);
12116 offset_expr.X_add_number = bfd_getl32 (temp);
12120 imm_expr.X_add_number = bfd_getb32 (temp);
12121 offset_expr.X_add_number = bfd_getb32 (temp + 4);
12123 if (offset_expr.X_add_number == 0)
12124 offset_expr.X_op = O_absent;
12126 else if (sizeof (imm_expr.X_add_number) > 4)
12128 imm_expr.X_op = O_constant;
12129 if (!target_big_endian)
12130 imm_expr.X_add_number = bfd_getl64 (temp);
12132 imm_expr.X_add_number = bfd_getb64 (temp);
12136 imm_expr.X_op = O_big;
12137 imm_expr.X_add_number = 4;
12138 if (!target_big_endian)
12140 generic_bignum[0] = bfd_getl16 (temp);
12141 generic_bignum[1] = bfd_getl16 (temp + 2);
12142 generic_bignum[2] = bfd_getl16 (temp + 4);
12143 generic_bignum[3] = bfd_getl16 (temp + 6);
12147 generic_bignum[0] = bfd_getb16 (temp + 6);
12148 generic_bignum[1] = bfd_getb16 (temp + 4);
12149 generic_bignum[2] = bfd_getb16 (temp + 2);
12150 generic_bignum[3] = bfd_getb16 (temp);
12156 const char *newname;
12159 /* Switch to the right section. */
12161 subseg = now_subseg;
12164 default: /* unused default case avoids warnings. */
12166 newname = RDATA_SECTION_NAME;
12167 if (g_switch_value >= 8)
12171 newname = RDATA_SECTION_NAME;
12174 gas_assert (g_switch_value >= 4);
12178 new_seg = subseg_new (newname, (subsegT) 0);
12180 bfd_set_section_flags (stdoutput, new_seg,
12185 frag_align (*args == 'l' ? 2 : 3, 0, 0);
12186 if (IS_ELF && strncmp (TARGET_OS, "elf", 3) != 0)
12187 record_alignment (new_seg, 4);
12189 record_alignment (new_seg, *args == 'l' ? 2 : 3);
12190 if (seg == now_seg)
12191 as_bad (_("Can't use floating point insn in this section"));
12193 /* Set the argument to the current address in the
12195 offset_expr.X_op = O_symbol;
12196 offset_expr.X_add_symbol = symbol_temp_new_now ();
12197 offset_expr.X_add_number = 0;
12199 /* Put the floating point number into the section. */
12200 p = frag_more ((int) length);
12201 memcpy (p, temp, length);
12203 /* Switch back to the original section. */
12204 subseg_set (seg, subseg);
12209 case 'i': /* 16-bit unsigned immediate. */
12210 case 'j': /* 16-bit signed immediate. */
12211 *imm_reloc = BFD_RELOC_LO16;
12212 if (my_getSmallExpression (&imm_expr, imm_reloc, s) == 0)
12215 offsetT minval, maxval;
12217 more = (insn + 1 < past
12218 && strcmp (insn->name, insn[1].name) == 0);
12220 /* If the expression was written as an unsigned number,
12221 only treat it as signed if there are no more
12225 && sizeof (imm_expr.X_add_number) <= 4
12226 && imm_expr.X_op == O_constant
12227 && imm_expr.X_add_number < 0
12228 && imm_expr.X_unsigned
12229 && HAVE_64BIT_GPRS)
12232 /* For compatibility with older assemblers, we accept
12233 0x8000-0xffff as signed 16-bit numbers when only
12234 signed numbers are allowed. */
12236 minval = 0, maxval = 0xffff;
12238 minval = -0x8000, maxval = 0x7fff;
12240 minval = -0x8000, maxval = 0xffff;
12242 if (imm_expr.X_op != O_constant
12243 || imm_expr.X_add_number < minval
12244 || imm_expr.X_add_number > maxval)
12248 if (imm_expr.X_op == O_constant
12249 || imm_expr.X_op == O_big)
12250 as_bad (_("Expression out of range"));
12256 case 'o': /* 16-bit offset. */
12257 offset_reloc[0] = BFD_RELOC_LO16;
12258 offset_reloc[1] = BFD_RELOC_UNUSED;
12259 offset_reloc[2] = BFD_RELOC_UNUSED;
12261 /* Check whether there is only a single bracketed expression
12262 left. If so, it must be the base register and the
12263 constant must be zero. */
12264 if (*s == '(' && strchr (s + 1, '(') == 0)
12266 offset_expr.X_op = O_constant;
12267 offset_expr.X_add_number = 0;
12271 /* If this value won't fit into a 16 bit offset, then go
12272 find a macro that will generate the 32 bit offset
12274 if (my_getSmallExpression (&offset_expr, offset_reloc, s) == 0
12275 && (offset_expr.X_op != O_constant
12276 || offset_expr.X_add_number >= 0x8000
12277 || offset_expr.X_add_number < -0x8000))
12283 case 'p': /* PC-relative offset. */
12284 *offset_reloc = BFD_RELOC_16_PCREL_S2;
12285 my_getExpression (&offset_expr, s);
12289 case 'u': /* Upper 16 bits. */
12290 if (my_getSmallExpression (&imm_expr, imm_reloc, s) == 0
12291 && imm_expr.X_op == O_constant
12292 && (imm_expr.X_add_number < 0
12293 || imm_expr.X_add_number >= 0x10000))
12294 as_bad (_("lui expression (%lu) not in range 0..65535"),
12295 (unsigned long) imm_expr.X_add_number);
12299 case 'a': /* 26-bit address. */
12300 *offset_reloc = BFD_RELOC_MIPS_JMP;
12301 my_getExpression (&offset_expr, s);
12305 case 'N': /* 3-bit branch condition code. */
12306 case 'M': /* 3-bit compare condition code. */
12308 if (ip->insn_mo->pinfo & (FP_D | FP_S))
12309 rtype |= RTYPE_FCC;
12310 if (!reg_lookup (&s, rtype, ®no))
12312 if ((strcmp (str + strlen (str) - 3, ".ps") == 0
12313 || strcmp (str + strlen (str) - 5, "any2f") == 0
12314 || strcmp (str + strlen (str) - 5, "any2t") == 0)
12315 && (regno & 1) != 0)
12316 as_warn (_("Condition code register should be even for %s, "
12319 if ((strcmp (str + strlen (str) - 5, "any4f") == 0
12320 || strcmp (str + strlen (str) - 5, "any4t") == 0)
12321 && (regno & 3) != 0)
12322 as_warn (_("Condition code register should be 0 or 4 for %s, "
12326 INSERT_OPERAND (mips_opts.micromips, BCC, *ip, regno);
12328 INSERT_OPERAND (mips_opts.micromips, CCC, *ip, regno);
12332 if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X'))
12343 while (ISDIGIT (*s));
12346 c = 8; /* Invalid sel value. */
12349 as_bad (_("Invalid coprocessor sub-selection value (0-7)"));
12350 INSERT_OPERAND (mips_opts.micromips, SEL, *ip, c);
12354 gas_assert (!mips_opts.micromips);
12355 /* Must be at least one digit. */
12356 my_getExpression (&imm_expr, s);
12357 check_absolute_expr (ip, &imm_expr);
12359 if ((unsigned long) imm_expr.X_add_number
12360 > (unsigned long) OP_MASK_VECBYTE)
12362 as_bad (_("bad byte vector index (%ld)"),
12363 (long) imm_expr.X_add_number);
12364 imm_expr.X_add_number = 0;
12367 INSERT_OPERAND (0, VECBYTE, *ip, imm_expr.X_add_number);
12368 imm_expr.X_op = O_absent;
12373 gas_assert (!mips_opts.micromips);
12374 my_getExpression (&imm_expr, s);
12375 check_absolute_expr (ip, &imm_expr);
12377 if ((unsigned long) imm_expr.X_add_number
12378 > (unsigned long) OP_MASK_VECALIGN)
12380 as_bad (_("bad byte vector index (%ld)"),
12381 (long) imm_expr.X_add_number);
12382 imm_expr.X_add_number = 0;
12385 INSERT_OPERAND (0, VECALIGN, *ip, imm_expr.X_add_number);
12386 imm_expr.X_op = O_absent;
12390 case 'm': /* Opcode extension character. */
12391 gas_assert (mips_opts.micromips);
12396 if (strncmp (s, "$pc", 3) == 0)
12424 ok = reg_lookup (&s, RTYPE_NUM | RTYPE_GP, ®no);
12425 if (regno == AT && mips_opts.at)
12427 if (mips_opts.at == ATREG)
12428 as_warn (_("Used $at without \".set noat\""));
12430 as_warn (_("Used $%u with \".set at=$%u\""),
12431 regno, mips_opts.at);
12437 gas_assert (args[1] == ',');
12443 gas_assert (args[1] == ',');
12445 continue; /* Nothing to do. */
12451 if (c == 'j' && !strncmp (ip->insn_mo->name, "jalr", 4))
12453 if (regno == lastregno)
12456 = _("Source and destination must be different");
12459 if (regno == 31 && lastregno == 0xffffffff)
12462 = _("A destination register must be supplied");
12473 gas_assert (args[1] == ',');
12480 gas_assert (args[1] == ',');
12483 continue; /* Nothing to do. */
12487 /* Make sure regno is the same as lastregno. */
12488 if (c == 't' && regno != lastregno)
12491 /* Make sure regno is the same as destregno. */
12492 if (c == 'x' && regno != destregno)
12495 /* We need to save regno, before regno maps to the
12496 microMIPS register encoding. */
12506 regno = ILLEGAL_REG;
12510 regno = mips32_to_micromips_reg_b_map[regno];
12514 regno = mips32_to_micromips_reg_c_map[regno];
12518 regno = mips32_to_micromips_reg_d_map[regno];
12522 regno = mips32_to_micromips_reg_e_map[regno];
12526 regno = mips32_to_micromips_reg_f_map[regno];
12530 regno = mips32_to_micromips_reg_g_map[regno];
12534 regno = mips32_to_micromips_reg_h_map[regno];
12538 switch (EXTRACT_OPERAND (1, MI, *ip))
12543 else if (regno == 22)
12545 else if (regno == 5)
12547 else if (regno == 6)
12549 else if (regno == 7)
12552 regno = ILLEGAL_REG;
12558 else if (regno == 7)
12561 regno = ILLEGAL_REG;
12568 regno = ILLEGAL_REG;
12572 regno = ILLEGAL_REG;
12578 regno = mips32_to_micromips_reg_l_map[regno];
12582 regno = mips32_to_micromips_reg_m_map[regno];
12586 regno = mips32_to_micromips_reg_n_map[regno];
12590 regno = mips32_to_micromips_reg_q_map[regno];
12595 regno = ILLEGAL_REG;
12600 regno = ILLEGAL_REG;
12605 regno = ILLEGAL_REG;
12608 case 'j': /* Do nothing. */
12618 if (regno == ILLEGAL_REG)
12624 INSERT_OPERAND (1, MB, *ip, regno);
12628 INSERT_OPERAND (1, MC, *ip, regno);
12632 INSERT_OPERAND (1, MD, *ip, regno);
12636 INSERT_OPERAND (1, ME, *ip, regno);
12640 INSERT_OPERAND (1, MF, *ip, regno);
12644 INSERT_OPERAND (1, MG, *ip, regno);
12648 INSERT_OPERAND (1, MH, *ip, regno);
12652 INSERT_OPERAND (1, MI, *ip, regno);
12656 INSERT_OPERAND (1, MJ, *ip, regno);
12660 INSERT_OPERAND (1, ML, *ip, regno);
12664 INSERT_OPERAND (1, MM, *ip, regno);
12668 INSERT_OPERAND (1, MN, *ip, regno);
12672 INSERT_OPERAND (1, MP, *ip, regno);
12676 INSERT_OPERAND (1, MQ, *ip, regno);
12679 case 'a': /* Do nothing. */
12680 case 's': /* Do nothing. */
12681 case 't': /* Do nothing. */
12682 case 'x': /* Do nothing. */
12683 case 'y': /* Do nothing. */
12684 case 'z': /* Do nothing. */
12694 bfd_reloc_code_real_type r[3];
12698 /* Check whether there is only a single bracketed
12699 expression left. If so, it must be the base register
12700 and the constant must be zero. */
12701 if (*s == '(' && strchr (s + 1, '(') == 0)
12703 INSERT_OPERAND (1, IMMA, *ip, 0);
12707 if (my_getSmallExpression (&ep, r, s) > 0
12708 || !expr_const_in_range (&ep, -64, 64, 2))
12711 imm = ep.X_add_number >> 2;
12712 INSERT_OPERAND (1, IMMA, *ip, imm);
12719 bfd_reloc_code_real_type r[3];
12723 if (my_getSmallExpression (&ep, r, s) > 0
12724 || ep.X_op != O_constant)
12727 for (imm = 0; imm < 8; imm++)
12728 if (micromips_imm_b_map[imm] == ep.X_add_number)
12733 INSERT_OPERAND (1, IMMB, *ip, imm);
12740 bfd_reloc_code_real_type r[3];
12744 if (my_getSmallExpression (&ep, r, s) > 0
12745 || ep.X_op != O_constant)
12748 for (imm = 0; imm < 16; imm++)
12749 if (micromips_imm_c_map[imm] == ep.X_add_number)
12754 INSERT_OPERAND (1, IMMC, *ip, imm);
12759 case 'D': /* pc relative offset */
12760 case 'E': /* pc relative offset */
12761 my_getExpression (&offset_expr, s);
12762 if (offset_expr.X_op == O_register)
12765 if (!forced_insn_length)
12766 *offset_reloc = (int) BFD_RELOC_UNUSED + c;
12768 *offset_reloc = BFD_RELOC_MICROMIPS_10_PCREL_S1;
12770 *offset_reloc = BFD_RELOC_MICROMIPS_7_PCREL_S1;
12776 bfd_reloc_code_real_type r[3];
12780 if (my_getSmallExpression (&ep, r, s) > 0
12781 || !expr_const_in_range (&ep, 0, 16, 0))
12784 imm = ep.X_add_number;
12785 INSERT_OPERAND (1, IMMF, *ip, imm);
12792 bfd_reloc_code_real_type r[3];
12796 /* Check whether there is only a single bracketed
12797 expression left. If so, it must be the base register
12798 and the constant must be zero. */
12799 if (*s == '(' && strchr (s + 1, '(') == 0)
12801 INSERT_OPERAND (1, IMMG, *ip, 0);
12805 if (my_getSmallExpression (&ep, r, s) > 0
12806 || !expr_const_in_range (&ep, -1, 15, 0))
12809 imm = ep.X_add_number & 15;
12810 INSERT_OPERAND (1, IMMG, *ip, imm);
12817 bfd_reloc_code_real_type r[3];
12821 /* Check whether there is only a single bracketed
12822 expression left. If so, it must be the base register
12823 and the constant must be zero. */
12824 if (*s == '(' && strchr (s + 1, '(') == 0)
12826 INSERT_OPERAND (1, IMMH, *ip, 0);
12830 if (my_getSmallExpression (&ep, r, s) > 0
12831 || !expr_const_in_range (&ep, 0, 16, 1))
12834 imm = ep.X_add_number >> 1;
12835 INSERT_OPERAND (1, IMMH, *ip, imm);
12842 bfd_reloc_code_real_type r[3];
12846 if (my_getSmallExpression (&ep, r, s) > 0
12847 || !expr_const_in_range (&ep, -1, 127, 0))
12850 imm = ep.X_add_number & 127;
12851 INSERT_OPERAND (1, IMMI, *ip, imm);
12858 bfd_reloc_code_real_type r[3];
12862 /* Check whether there is only a single bracketed
12863 expression left. If so, it must be the base register
12864 and the constant must be zero. */
12865 if (*s == '(' && strchr (s + 1, '(') == 0)
12867 INSERT_OPERAND (1, IMMJ, *ip, 0);
12871 if (my_getSmallExpression (&ep, r, s) > 0
12872 || !expr_const_in_range (&ep, 0, 16, 2))
12875 imm = ep.X_add_number >> 2;
12876 INSERT_OPERAND (1, IMMJ, *ip, imm);
12883 bfd_reloc_code_real_type r[3];
12887 /* Check whether there is only a single bracketed
12888 expression left. If so, it must be the base register
12889 and the constant must be zero. */
12890 if (*s == '(' && strchr (s + 1, '(') == 0)
12892 INSERT_OPERAND (1, IMML, *ip, 0);
12896 if (my_getSmallExpression (&ep, r, s) > 0
12897 || !expr_const_in_range (&ep, 0, 16, 0))
12900 imm = ep.X_add_number;
12901 INSERT_OPERAND (1, IMML, *ip, imm);
12908 bfd_reloc_code_real_type r[3];
12912 if (my_getSmallExpression (&ep, r, s) > 0
12913 || !expr_const_in_range (&ep, 1, 9, 0))
12916 imm = ep.X_add_number & 7;
12917 INSERT_OPERAND (1, IMMM, *ip, imm);
12922 case 'N': /* Register list for lwm and swm. */
12924 /* A comma-separated list of registers and/or
12925 dash-separated contiguous ranges including
12926 both ra and a set of one or more registers
12927 starting at s0 up to s3 which have to be
12934 and any permutations of these. */
12935 unsigned int reglist;
12938 if (!reglist_lookup (&s, RTYPE_NUM | RTYPE_GP, ®list))
12941 if ((reglist & 0xfff1ffff) != 0x80010000)
12944 reglist = (reglist >> 17) & 7;
12946 if ((reglist & -reglist) != reglist)
12949 imm = ffs (reglist) - 1;
12950 INSERT_OPERAND (1, IMMN, *ip, imm);
12954 case 'O': /* sdbbp 4-bit code. */
12956 bfd_reloc_code_real_type r[3];
12960 if (my_getSmallExpression (&ep, r, s) > 0
12961 || !expr_const_in_range (&ep, 0, 16, 0))
12964 imm = ep.X_add_number;
12965 INSERT_OPERAND (1, IMMO, *ip, imm);
12972 bfd_reloc_code_real_type r[3];
12976 if (my_getSmallExpression (&ep, r, s) > 0
12977 || !expr_const_in_range (&ep, 0, 32, 2))
12980 imm = ep.X_add_number >> 2;
12981 INSERT_OPERAND (1, IMMP, *ip, imm);
12988 bfd_reloc_code_real_type r[3];
12992 if (my_getSmallExpression (&ep, r, s) > 0
12993 || !expr_const_in_range (&ep, -0x400000, 0x400000, 2))
12996 imm = ep.X_add_number >> 2;
12997 INSERT_OPERAND (1, IMMQ, *ip, imm);
13004 bfd_reloc_code_real_type r[3];
13008 /* Check whether there is only a single bracketed
13009 expression left. If so, it must be the base register
13010 and the constant must be zero. */
13011 if (*s == '(' && strchr (s + 1, '(') == 0)
13013 INSERT_OPERAND (1, IMMU, *ip, 0);
13017 if (my_getSmallExpression (&ep, r, s) > 0
13018 || !expr_const_in_range (&ep, 0, 32, 2))
13021 imm = ep.X_add_number >> 2;
13022 INSERT_OPERAND (1, IMMU, *ip, imm);
13029 bfd_reloc_code_real_type r[3];
13033 if (my_getSmallExpression (&ep, r, s) > 0
13034 || !expr_const_in_range (&ep, 0, 64, 2))
13037 imm = ep.X_add_number >> 2;
13038 INSERT_OPERAND (1, IMMW, *ip, imm);
13045 bfd_reloc_code_real_type r[3];
13049 if (my_getSmallExpression (&ep, r, s) > 0
13050 || !expr_const_in_range (&ep, -8, 8, 0))
13053 imm = ep.X_add_number;
13054 INSERT_OPERAND (1, IMMX, *ip, imm);
13061 bfd_reloc_code_real_type r[3];
13065 if (my_getSmallExpression (&ep, r, s) > 0
13066 || expr_const_in_range (&ep, -2, 2, 2)
13067 || !expr_const_in_range (&ep, -258, 258, 2))
13070 imm = ep.X_add_number >> 2;
13071 imm = ((imm >> 1) & ~0xff) | (imm & 0xff);
13072 INSERT_OPERAND (1, IMMY, *ip, imm);
13079 bfd_reloc_code_real_type r[3];
13082 if (my_getSmallExpression (&ep, r, s) > 0
13083 || !expr_const_in_range (&ep, 0, 1, 0))
13090 as_bad (_("Internal error: bad microMIPS opcode "
13091 "(unknown extension operand type `m%c'): %s %s"),
13092 *args, insn->name, insn->args);
13093 /* Further processing is fruitless. */
13098 case 'n': /* Register list for 32-bit lwm and swm. */
13099 gas_assert (mips_opts.micromips);
13101 /* A comma-separated list of registers and/or
13102 dash-separated contiguous ranges including
13103 at least one of ra and a set of one or more
13104 registers starting at s0 up to s7 and then
13105 s8 which have to be consecutive, e.g.:
13113 and any permutations of these. */
13114 unsigned int reglist;
13118 if (!reglist_lookup (&s, RTYPE_NUM | RTYPE_GP, ®list))
13121 if ((reglist & 0x3f00ffff) != 0)
13124 ra = (reglist >> 27) & 0x10;
13125 reglist = ((reglist >> 22) & 0x100) | ((reglist >> 16) & 0xff);
13127 if ((reglist & -reglist) != reglist)
13130 imm = (ffs (reglist) - 1) | ra;
13131 INSERT_OPERAND (1, RT, *ip, imm);
13132 imm_expr.X_op = O_absent;
13136 case '|': /* 4-bit trap code. */
13137 gas_assert (mips_opts.micromips);
13138 my_getExpression (&imm_expr, s);
13139 check_absolute_expr (ip, &imm_expr);
13140 if ((unsigned long) imm_expr.X_add_number
13141 > MICROMIPSOP_MASK_TRAP)
13142 as_bad (_("Trap code (%lu) for %s not in 0..15 range"),
13143 (unsigned long) imm_expr.X_add_number,
13144 ip->insn_mo->name);
13145 INSERT_OPERAND (1, TRAP, *ip, imm_expr.X_add_number);
13146 imm_expr.X_op = O_absent;
13151 as_bad (_("Bad char = '%c'\n"), *args);
13156 /* Args don't match. */
13158 insn_error = _("Illegal operands");
13159 if (insn + 1 < past && !strcmp (insn->name, insn[1].name))
13164 else if (wrong_delay_slot_insns && need_delay_slot_ok)
13166 gas_assert (firstinsn);
13167 need_delay_slot_ok = FALSE;
13176 #define SKIP_SPACE_TABS(S) { while (*(S) == ' ' || *(S) == '\t') ++(S); }
13178 /* This routine assembles an instruction into its binary format when
13179 assembling for the mips16. As a side effect, it sets one of the
13180 global variables imm_reloc or offset_reloc to the type of relocation
13181 to do if one of the operands is an address expression. It also sets
13182 forced_insn_length to the resulting instruction size in bytes if the
13183 user explicitly requested a small or extended instruction. */
13186 mips16_ip (char *str, struct mips_cl_insn *ip)
13190 struct mips_opcode *insn;
13192 unsigned int regno;
13193 unsigned int lastregno = 0;
13199 forced_insn_length = 0;
13201 for (s = str; ISLOWER (*s); ++s)
13213 if (s[1] == 't' && s[2] == ' ')
13216 forced_insn_length = 2;
13220 else if (s[1] == 'e' && s[2] == ' ')
13223 forced_insn_length = 4;
13227 /* Fall through. */
13229 insn_error = _("unknown opcode");
13233 if (mips_opts.noautoextend && !forced_insn_length)
13234 forced_insn_length = 2;
13236 if ((insn = (struct mips_opcode *) hash_find (mips16_op_hash, str)) == NULL)
13238 insn_error = _("unrecognized opcode");
13247 gas_assert (strcmp (insn->name, str) == 0);
13249 ok = is_opcode_valid_16 (insn);
13252 if (insn + 1 < &mips16_opcodes[bfd_mips16_num_opcodes]
13253 && strcmp (insn->name, insn[1].name) == 0)
13262 static char buf[100];
13264 _("Opcode not supported on this processor: %s (%s)"),
13265 mips_cpu_info_from_arch (mips_opts.arch)->name,
13266 mips_cpu_info_from_isa (mips_opts.isa)->name);
13273 create_insn (ip, insn);
13274 imm_expr.X_op = O_absent;
13275 imm_reloc[0] = BFD_RELOC_UNUSED;
13276 imm_reloc[1] = BFD_RELOC_UNUSED;
13277 imm_reloc[2] = BFD_RELOC_UNUSED;
13278 imm2_expr.X_op = O_absent;
13279 offset_expr.X_op = O_absent;
13280 offset_reloc[0] = BFD_RELOC_UNUSED;
13281 offset_reloc[1] = BFD_RELOC_UNUSED;
13282 offset_reloc[2] = BFD_RELOC_UNUSED;
13283 for (args = insn->args; 1; ++args)
13290 /* In this switch statement we call break if we did not find
13291 a match, continue if we did find a match, or return if we
13300 /* Stuff the immediate value in now, if we can. */
13301 if (imm_expr.X_op == O_constant
13302 && *imm_reloc > BFD_RELOC_UNUSED
13303 && *imm_reloc != BFD_RELOC_MIPS16_GOT16
13304 && *imm_reloc != BFD_RELOC_MIPS16_CALL16
13305 && insn->pinfo != INSN_MACRO)
13309 switch (*offset_reloc)
13311 case BFD_RELOC_MIPS16_HI16_S:
13312 tmp = (imm_expr.X_add_number + 0x8000) >> 16;
13315 case BFD_RELOC_MIPS16_HI16:
13316 tmp = imm_expr.X_add_number >> 16;
13319 case BFD_RELOC_MIPS16_LO16:
13320 tmp = ((imm_expr.X_add_number + 0x8000) & 0xffff)
13324 case BFD_RELOC_UNUSED:
13325 tmp = imm_expr.X_add_number;
13331 *offset_reloc = BFD_RELOC_UNUSED;
13333 mips16_immed (NULL, 0, *imm_reloc - BFD_RELOC_UNUSED,
13334 tmp, TRUE, forced_insn_length == 2,
13335 forced_insn_length == 4, &ip->insn_opcode,
13336 &ip->use_extend, &ip->extend);
13337 imm_expr.X_op = O_absent;
13338 *imm_reloc = BFD_RELOC_UNUSED;
13352 MIPS16_INSERT_OPERAND (RX, *ip, lastregno);
13355 MIPS16_INSERT_OPERAND (RY, *ip, lastregno);
13371 MIPS16_INSERT_OPERAND (RX, *ip, lastregno);
13373 MIPS16_INSERT_OPERAND (RY, *ip, lastregno);
13377 /* Fall through. */
13388 if (!reg_lookup (&s, RTYPE_NUM | RTYPE_GP, ®no))
13390 if (c == 'v' || c == 'w')
13393 MIPS16_INSERT_OPERAND (RX, *ip, lastregno);
13395 MIPS16_INSERT_OPERAND (RY, *ip, lastregno);
13406 if (c == 'v' || c == 'w')
13408 regno = mips16_to_32_reg_map[lastregno];
13422 regno = mips32_to_16_reg_map[regno];
13427 regno = ILLEGAL_REG;
13432 regno = ILLEGAL_REG;
13437 regno = ILLEGAL_REG;
13442 if (regno == AT && mips_opts.at)
13444 if (mips_opts.at == ATREG)
13445 as_warn (_("used $at without \".set noat\""));
13447 as_warn (_("used $%u with \".set at=$%u\""),
13448 regno, mips_opts.at);
13456 if (regno == ILLEGAL_REG)
13463 MIPS16_INSERT_OPERAND (RX, *ip, regno);
13467 MIPS16_INSERT_OPERAND (RY, *ip, regno);
13470 MIPS16_INSERT_OPERAND (RZ, *ip, regno);
13473 MIPS16_INSERT_OPERAND (MOVE32Z, *ip, regno);
13479 MIPS16_INSERT_OPERAND (REGR32, *ip, regno);
13482 regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3);
13483 MIPS16_INSERT_OPERAND (REG32R, *ip, regno);
13493 if (strncmp (s, "$pc", 3) == 0)
13510 i = my_getSmallExpression (&imm_expr, imm_reloc, s);
13513 if (imm_expr.X_op != O_constant)
13515 forced_insn_length = 4;
13516 ip->use_extend = TRUE;
13521 /* We need to relax this instruction. */
13522 *offset_reloc = *imm_reloc;
13523 *imm_reloc = (int) BFD_RELOC_UNUSED + c;
13528 *imm_reloc = BFD_RELOC_UNUSED;
13529 /* Fall through. */
13536 my_getExpression (&imm_expr, s);
13537 if (imm_expr.X_op == O_register)
13539 /* What we thought was an expression turned out to
13542 if (s[0] == '(' && args[1] == '(')
13544 /* It looks like the expression was omitted
13545 before a register indirection, which means
13546 that the expression is implicitly zero. We
13547 still set up imm_expr, so that we handle
13548 explicit extensions correctly. */
13549 imm_expr.X_op = O_constant;
13550 imm_expr.X_add_number = 0;
13551 *imm_reloc = (int) BFD_RELOC_UNUSED + c;
13558 /* We need to relax this instruction. */
13559 *imm_reloc = (int) BFD_RELOC_UNUSED + c;
13568 /* We use offset_reloc rather than imm_reloc for the PC
13569 relative operands. This lets macros with both
13570 immediate and address operands work correctly. */
13571 my_getExpression (&offset_expr, s);
13573 if (offset_expr.X_op == O_register)
13576 /* We need to relax this instruction. */
13577 *offset_reloc = (int) BFD_RELOC_UNUSED + c;
13581 case '6': /* break code */
13582 my_getExpression (&imm_expr, s);
13583 check_absolute_expr (ip, &imm_expr);
13584 if ((unsigned long) imm_expr.X_add_number > 63)
13585 as_warn (_("Invalid value for `%s' (%lu)"),
13587 (unsigned long) imm_expr.X_add_number);
13588 MIPS16_INSERT_OPERAND (IMM6, *ip, imm_expr.X_add_number);
13589 imm_expr.X_op = O_absent;
13593 case 'a': /* 26 bit address */
13594 my_getExpression (&offset_expr, s);
13596 *offset_reloc = BFD_RELOC_MIPS16_JMP;
13597 ip->insn_opcode <<= 16;
13600 case 'l': /* register list for entry macro */
13601 case 'L': /* register list for exit macro */
13611 unsigned int freg, reg1, reg2;
13613 while (*s == ' ' || *s == ',')
13615 if (reg_lookup (&s, RTYPE_GP | RTYPE_NUM, ®1))
13617 else if (reg_lookup (&s, RTYPE_FPU, ®1))
13621 as_bad (_("can't parse register list"));
13631 if (!reg_lookup (&s, freg ? RTYPE_FPU
13632 : (RTYPE_GP | RTYPE_NUM), ®2))
13634 as_bad (_("invalid register list"));
13638 if (freg && reg1 == 0 && reg2 == 0 && c == 'L')
13640 mask &= ~ (7 << 3);
13643 else if (freg && reg1 == 0 && reg2 == 1 && c == 'L')
13645 mask &= ~ (7 << 3);
13648 else if (reg1 == 4 && reg2 >= 4 && reg2 <= 7 && c != 'L')
13649 mask |= (reg2 - 3) << 3;
13650 else if (reg1 == 16 && reg2 >= 16 && reg2 <= 17)
13651 mask |= (reg2 - 15) << 1;
13652 else if (reg1 == RA && reg2 == RA)
13656 as_bad (_("invalid register list"));
13660 /* The mask is filled in in the opcode table for the
13661 benefit of the disassembler. We remove it before
13662 applying the actual mask. */
13663 ip->insn_opcode &= ~ ((7 << 3) << MIPS16OP_SH_IMM6);
13664 ip->insn_opcode |= mask << MIPS16OP_SH_IMM6;
13668 case 'm': /* Register list for save insn. */
13669 case 'M': /* Register list for restore insn. */
13672 int framesz = 0, seen_framesz = 0;
13673 int nargs = 0, statics = 0, sregs = 0;
13677 unsigned int reg1, reg2;
13679 SKIP_SPACE_TABS (s);
13682 SKIP_SPACE_TABS (s);
13684 my_getExpression (&imm_expr, s);
13685 if (imm_expr.X_op == O_constant)
13687 /* Handle the frame size. */
13690 as_bad (_("more than one frame size in list"));
13694 framesz = imm_expr.X_add_number;
13695 imm_expr.X_op = O_absent;
13700 if (! reg_lookup (&s, RTYPE_GP | RTYPE_NUM, ®1))
13702 as_bad (_("can't parse register list"));
13714 if (! reg_lookup (&s, RTYPE_GP | RTYPE_NUM, ®2)
13717 as_bad (_("can't parse register list"));
13722 while (reg1 <= reg2)
13724 if (reg1 >= 4 && reg1 <= 7)
13728 nargs |= 1 << (reg1 - 4);
13730 /* statics $a0-$a3 */
13731 statics |= 1 << (reg1 - 4);
13733 else if ((reg1 >= 16 && reg1 <= 23) || reg1 == 30)
13736 sregs |= 1 << ((reg1 == 30) ? 8 : (reg1 - 16));
13738 else if (reg1 == 31)
13740 /* Add $ra to insn. */
13745 as_bad (_("unexpected register in list"));
13753 /* Encode args/statics combination. */
13754 if (nargs & statics)
13755 as_bad (_("arg/static registers overlap"));
13756 else if (nargs == 0xf)
13757 /* All $a0-$a3 are args. */
13758 opcode |= MIPS16_ALL_ARGS << 16;
13759 else if (statics == 0xf)
13760 /* All $a0-$a3 are statics. */
13761 opcode |= MIPS16_ALL_STATICS << 16;
13764 int narg = 0, nstat = 0;
13766 /* Count arg registers. */
13767 while (nargs & 0x1)
13773 as_bad (_("invalid arg register list"));
13775 /* Count static registers. */
13776 while (statics & 0x8)
13778 statics = (statics << 1) & 0xf;
13782 as_bad (_("invalid static register list"));
13784 /* Encode args/statics. */
13785 opcode |= ((narg << 2) | nstat) << 16;
13788 /* Encode $s0/$s1. */
13789 if (sregs & (1 << 0)) /* $s0 */
13791 if (sregs & (1 << 1)) /* $s1 */
13797 /* Count regs $s2-$s8. */
13805 as_bad (_("invalid static register list"));
13806 /* Encode $s2-$s8. */
13807 opcode |= nsreg << 24;
13810 /* Encode frame size. */
13812 as_bad (_("missing frame size"));
13813 else if ((framesz & 7) != 0 || framesz < 0
13814 || framesz > 0xff * 8)
13815 as_bad (_("invalid frame size"));
13816 else if (framesz != 128 || (opcode >> 16) != 0)
13819 opcode |= (((framesz & 0xf0) << 16)
13820 | (framesz & 0x0f));
13823 /* Finally build the instruction. */
13824 if ((opcode >> 16) != 0 || framesz == 0)
13826 ip->use_extend = TRUE;
13827 ip->extend = opcode >> 16;
13829 ip->insn_opcode |= opcode & 0x7f;
13833 case 'e': /* extend code */
13834 my_getExpression (&imm_expr, s);
13835 check_absolute_expr (ip, &imm_expr);
13836 if ((unsigned long) imm_expr.X_add_number > 0x7ff)
13838 as_warn (_("Invalid value for `%s' (%lu)"),
13840 (unsigned long) imm_expr.X_add_number);
13841 imm_expr.X_add_number &= 0x7ff;
13843 ip->insn_opcode |= imm_expr.X_add_number;
13844 imm_expr.X_op = O_absent;
13854 /* Args don't match. */
13855 if (insn + 1 < &mips16_opcodes[bfd_mips16_num_opcodes] &&
13856 strcmp (insn->name, insn[1].name) == 0)
13863 insn_error = _("illegal operands");
13869 /* This structure holds information we know about a mips16 immediate
13872 struct mips16_immed_operand
13874 /* The type code used in the argument string in the opcode table. */
13876 /* The number of bits in the short form of the opcode. */
13878 /* The number of bits in the extended form of the opcode. */
13880 /* The amount by which the short form is shifted when it is used;
13881 for example, the sw instruction has a shift count of 2. */
13883 /* The amount by which the short form is shifted when it is stored
13884 into the instruction code. */
13886 /* Non-zero if the short form is unsigned. */
13888 /* Non-zero if the extended form is unsigned. */
13890 /* Non-zero if the value is PC relative. */
13894 /* The mips16 immediate operand types. */
13896 static const struct mips16_immed_operand mips16_immed_operands[] =
13898 { '<', 3, 5, 0, MIPS16OP_SH_RZ, 1, 1, 0 },
13899 { '>', 3, 5, 0, MIPS16OP_SH_RX, 1, 1, 0 },
13900 { '[', 3, 6, 0, MIPS16OP_SH_RZ, 1, 1, 0 },
13901 { ']', 3, 6, 0, MIPS16OP_SH_RX, 1, 1, 0 },
13902 { '4', 4, 15, 0, MIPS16OP_SH_IMM4, 0, 0, 0 },
13903 { '5', 5, 16, 0, MIPS16OP_SH_IMM5, 1, 0, 0 },
13904 { 'H', 5, 16, 1, MIPS16OP_SH_IMM5, 1, 0, 0 },
13905 { 'W', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 0 },
13906 { 'D', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 0 },
13907 { 'j', 5, 16, 0, MIPS16OP_SH_IMM5, 0, 0, 0 },
13908 { '8', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 0, 0 },
13909 { 'V', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 0 },
13910 { 'C', 8, 16, 3, MIPS16OP_SH_IMM8, 1, 0, 0 },
13911 { 'U', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 1, 0 },
13912 { 'k', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 0 },
13913 { 'K', 8, 16, 3, MIPS16OP_SH_IMM8, 0, 0, 0 },
13914 { 'p', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 },
13915 { 'q', 11, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 },
13916 { 'A', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 1 },
13917 { 'B', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 1 },
13918 { 'E', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 1 }
13921 #define MIPS16_NUM_IMMED \
13922 (sizeof mips16_immed_operands / sizeof mips16_immed_operands[0])
13924 /* Handle a mips16 instruction with an immediate value. This or's the
13925 small immediate value into *INSN. It sets *USE_EXTEND to indicate
13926 whether an extended value is needed; if one is needed, it sets
13927 *EXTEND to the value. The argument type is TYPE. The value is VAL.
13928 If SMALL is true, an unextended opcode was explicitly requested.
13929 If EXT is true, an extended opcode was explicitly requested. If
13930 WARN is true, warn if EXT does not match reality. */
13933 mips16_immed (char *file, unsigned int line, int type, offsetT val,
13934 bfd_boolean warn, bfd_boolean small, bfd_boolean ext,
13935 unsigned long *insn, bfd_boolean *use_extend,
13936 unsigned short *extend)
13938 const struct mips16_immed_operand *op;
13939 int mintiny, maxtiny;
13940 bfd_boolean needext;
13942 op = mips16_immed_operands;
13943 while (op->type != type)
13946 gas_assert (op < mips16_immed_operands + MIPS16_NUM_IMMED);
13951 if (type == '<' || type == '>' || type == '[' || type == ']')
13954 maxtiny = 1 << op->nbits;
13959 maxtiny = (1 << op->nbits) - 1;
13964 mintiny = - (1 << (op->nbits - 1));
13965 maxtiny = (1 << (op->nbits - 1)) - 1;
13968 /* Branch offsets have an implicit 0 in the lowest bit. */
13969 if (type == 'p' || type == 'q')
13972 if ((val & ((1 << op->shift) - 1)) != 0
13973 || val < (mintiny << op->shift)
13974 || val > (maxtiny << op->shift))
13979 if (warn && ext && ! needext)
13980 as_warn_where (file, line,
13981 _("extended operand requested but not required"));
13982 if (small && needext)
13983 as_bad_where (file, line, _("invalid unextended operand value"));
13985 if (small || (! ext && ! needext))
13989 *use_extend = FALSE;
13990 insnval = ((val >> op->shift) & ((1 << op->nbits) - 1));
13991 insnval <<= op->op_shift;
13996 long minext, maxext;
14002 maxext = (1 << op->extbits) - 1;
14006 minext = - (1 << (op->extbits - 1));
14007 maxext = (1 << (op->extbits - 1)) - 1;
14009 if (val < minext || val > maxext)
14010 as_bad_where (file, line,
14011 _("operand value out of range for instruction"));
14013 *use_extend = TRUE;
14014 if (op->extbits == 16)
14016 extval = ((val >> 11) & 0x1f) | (val & 0x7e0);
14019 else if (op->extbits == 15)
14021 extval = ((val >> 11) & 0xf) | (val & 0x7f0);
14026 extval = ((val & 0x1f) << 6) | (val & 0x20);
14030 *extend = (unsigned short) extval;
14035 struct percent_op_match
14038 bfd_reloc_code_real_type reloc;
14041 static const struct percent_op_match mips_percent_op[] =
14043 {"%lo", BFD_RELOC_LO16},
14045 {"%call_hi", BFD_RELOC_MIPS_CALL_HI16},
14046 {"%call_lo", BFD_RELOC_MIPS_CALL_LO16},
14047 {"%call16", BFD_RELOC_MIPS_CALL16},
14048 {"%got_disp", BFD_RELOC_MIPS_GOT_DISP},
14049 {"%got_page", BFD_RELOC_MIPS_GOT_PAGE},
14050 {"%got_ofst", BFD_RELOC_MIPS_GOT_OFST},
14051 {"%got_hi", BFD_RELOC_MIPS_GOT_HI16},
14052 {"%got_lo", BFD_RELOC_MIPS_GOT_LO16},
14053 {"%got", BFD_RELOC_MIPS_GOT16},
14054 {"%gp_rel", BFD_RELOC_GPREL16},
14055 {"%half", BFD_RELOC_16},
14056 {"%highest", BFD_RELOC_MIPS_HIGHEST},
14057 {"%higher", BFD_RELOC_MIPS_HIGHER},
14058 {"%neg", BFD_RELOC_MIPS_SUB},
14059 {"%tlsgd", BFD_RELOC_MIPS_TLS_GD},
14060 {"%tlsldm", BFD_RELOC_MIPS_TLS_LDM},
14061 {"%dtprel_hi", BFD_RELOC_MIPS_TLS_DTPREL_HI16},
14062 {"%dtprel_lo", BFD_RELOC_MIPS_TLS_DTPREL_LO16},
14063 {"%tprel_hi", BFD_RELOC_MIPS_TLS_TPREL_HI16},
14064 {"%tprel_lo", BFD_RELOC_MIPS_TLS_TPREL_LO16},
14065 {"%gottprel", BFD_RELOC_MIPS_TLS_GOTTPREL},
14067 {"%hi", BFD_RELOC_HI16_S}
14070 static const struct percent_op_match mips16_percent_op[] =
14072 {"%lo", BFD_RELOC_MIPS16_LO16},
14073 {"%gprel", BFD_RELOC_MIPS16_GPREL},
14074 {"%got", BFD_RELOC_MIPS16_GOT16},
14075 {"%call16", BFD_RELOC_MIPS16_CALL16},
14076 {"%hi", BFD_RELOC_MIPS16_HI16_S}
14080 /* Return true if *STR points to a relocation operator. When returning true,
14081 move *STR over the operator and store its relocation code in *RELOC.
14082 Leave both *STR and *RELOC alone when returning false. */
14085 parse_relocation (char **str, bfd_reloc_code_real_type *reloc)
14087 const struct percent_op_match *percent_op;
14090 if (mips_opts.mips16)
14092 percent_op = mips16_percent_op;
14093 limit = ARRAY_SIZE (mips16_percent_op);
14097 percent_op = mips_percent_op;
14098 limit = ARRAY_SIZE (mips_percent_op);
14101 for (i = 0; i < limit; i++)
14102 if (strncasecmp (*str, percent_op[i].str, strlen (percent_op[i].str)) == 0)
14104 int len = strlen (percent_op[i].str);
14106 if (!ISSPACE ((*str)[len]) && (*str)[len] != '(')
14109 *str += strlen (percent_op[i].str);
14110 *reloc = percent_op[i].reloc;
14112 /* Check whether the output BFD supports this relocation.
14113 If not, issue an error and fall back on something safe. */
14114 if (!bfd_reloc_type_lookup (stdoutput, percent_op[i].reloc))
14116 as_bad (_("relocation %s isn't supported by the current ABI"),
14117 percent_op[i].str);
14118 *reloc = BFD_RELOC_UNUSED;
14126 /* Parse string STR as a 16-bit relocatable operand. Store the
14127 expression in *EP and the relocations in the array starting
14128 at RELOC. Return the number of relocation operators used.
14130 On exit, EXPR_END points to the first character after the expression. */
14133 my_getSmallExpression (expressionS *ep, bfd_reloc_code_real_type *reloc,
14136 bfd_reloc_code_real_type reversed_reloc[3];
14137 size_t reloc_index, i;
14138 int crux_depth, str_depth;
14141 /* Search for the start of the main expression, recoding relocations
14142 in REVERSED_RELOC. End the loop with CRUX pointing to the start
14143 of the main expression and with CRUX_DEPTH containing the number
14144 of open brackets at that point. */
14151 crux_depth = str_depth;
14153 /* Skip over whitespace and brackets, keeping count of the number
14155 while (*str == ' ' || *str == '\t' || *str == '(')
14160 && reloc_index < (HAVE_NEWABI ? 3 : 1)
14161 && parse_relocation (&str, &reversed_reloc[reloc_index]));
14163 my_getExpression (ep, crux);
14166 /* Match every open bracket. */
14167 while (crux_depth > 0 && (*str == ')' || *str == ' ' || *str == '\t'))
14171 if (crux_depth > 0)
14172 as_bad (_("unclosed '('"));
14176 if (reloc_index != 0)
14178 prev_reloc_op_frag = frag_now;
14179 for (i = 0; i < reloc_index; i++)
14180 reloc[i] = reversed_reloc[reloc_index - 1 - i];
14183 return reloc_index;
14187 my_getExpression (expressionS *ep, char *str)
14191 save_in = input_line_pointer;
14192 input_line_pointer = str;
14194 expr_end = input_line_pointer;
14195 input_line_pointer = save_in;
14199 md_atof (int type, char *litP, int *sizeP)
14201 return ieee_md_atof (type, litP, sizeP, target_big_endian);
14205 md_number_to_chars (char *buf, valueT val, int n)
14207 if (target_big_endian)
14208 number_to_chars_bigendian (buf, val, n);
14210 number_to_chars_littleendian (buf, val, n);
14214 static int support_64bit_objects(void)
14216 const char **list, **l;
14219 list = bfd_target_list ();
14220 for (l = list; *l != NULL; l++)
14221 if (strcmp (*l, ELF_TARGET ("elf64-", "big")) == 0
14222 || strcmp (*l, ELF_TARGET ("elf64-", "little")) == 0)
14224 yes = (*l != NULL);
14228 #endif /* OBJ_ELF */
14230 const char *md_shortopts = "O::g::G:";
14234 OPTION_MARCH = OPTION_MD_BASE,
14256 OPTION_NO_SMARTMIPS,
14260 OPTION_NO_MICROMIPS,
14263 OPTION_COMPAT_ARCH_BASE,
14272 OPTION_M7000_HILO_FIX,
14273 OPTION_MNO_7000_HILO_FIX,
14276 OPTION_FIX_LOONGSON2F_JUMP,
14277 OPTION_NO_FIX_LOONGSON2F_JUMP,
14278 OPTION_FIX_LOONGSON2F_NOP,
14279 OPTION_NO_FIX_LOONGSON2F_NOP,
14281 OPTION_NO_FIX_VR4120,
14283 OPTION_NO_FIX_VR4130,
14284 OPTION_FIX_CN63XXP1,
14285 OPTION_NO_FIX_CN63XXP1,
14292 OPTION_CONSTRUCT_FLOATS,
14293 OPTION_NO_CONSTRUCT_FLOATS,
14296 OPTION_RELAX_BRANCH,
14297 OPTION_NO_RELAX_BRANCH,
14304 OPTION_SINGLE_FLOAT,
14305 OPTION_DOUBLE_FLOAT,
14308 OPTION_CALL_SHARED,
14309 OPTION_CALL_NONPIC,
14319 OPTION_MVXWORKS_PIC,
14320 #endif /* OBJ_ELF */
14324 struct option md_longopts[] =
14326 /* Options which specify architecture. */
14327 {"march", required_argument, NULL, OPTION_MARCH},
14328 {"mtune", required_argument, NULL, OPTION_MTUNE},
14329 {"mips0", no_argument, NULL, OPTION_MIPS1},
14330 {"mips1", no_argument, NULL, OPTION_MIPS1},
14331 {"mips2", no_argument, NULL, OPTION_MIPS2},
14332 {"mips3", no_argument, NULL, OPTION_MIPS3},
14333 {"mips4", no_argument, NULL, OPTION_MIPS4},
14334 {"mips5", no_argument, NULL, OPTION_MIPS5},
14335 {"mips32", no_argument, NULL, OPTION_MIPS32},
14336 {"mips64", no_argument, NULL, OPTION_MIPS64},
14337 {"mips32r2", no_argument, NULL, OPTION_MIPS32R2},
14338 {"mips64r2", no_argument, NULL, OPTION_MIPS64R2},
14340 /* Options which specify Application Specific Extensions (ASEs). */
14341 {"mips16", no_argument, NULL, OPTION_MIPS16},
14342 {"no-mips16", no_argument, NULL, OPTION_NO_MIPS16},
14343 {"mips3d", no_argument, NULL, OPTION_MIPS3D},
14344 {"no-mips3d", no_argument, NULL, OPTION_NO_MIPS3D},
14345 {"mdmx", no_argument, NULL, OPTION_MDMX},
14346 {"no-mdmx", no_argument, NULL, OPTION_NO_MDMX},
14347 {"mdsp", no_argument, NULL, OPTION_DSP},
14348 {"mno-dsp", no_argument, NULL, OPTION_NO_DSP},
14349 {"mmt", no_argument, NULL, OPTION_MT},
14350 {"mno-mt", no_argument, NULL, OPTION_NO_MT},
14351 {"msmartmips", no_argument, NULL, OPTION_SMARTMIPS},
14352 {"mno-smartmips", no_argument, NULL, OPTION_NO_SMARTMIPS},
14353 {"mdspr2", no_argument, NULL, OPTION_DSPR2},
14354 {"mno-dspr2", no_argument, NULL, OPTION_NO_DSPR2},
14355 {"mmicromips", no_argument, NULL, OPTION_MICROMIPS},
14356 {"mno-micromips", no_argument, NULL, OPTION_NO_MICROMIPS},
14357 {"mmcu", no_argument, NULL, OPTION_MCU},
14358 {"mno-mcu", no_argument, NULL, OPTION_NO_MCU},
14360 /* Old-style architecture options. Don't add more of these. */
14361 {"m4650", no_argument, NULL, OPTION_M4650},
14362 {"no-m4650", no_argument, NULL, OPTION_NO_M4650},
14363 {"m4010", no_argument, NULL, OPTION_M4010},
14364 {"no-m4010", no_argument, NULL, OPTION_NO_M4010},
14365 {"m4100", no_argument, NULL, OPTION_M4100},
14366 {"no-m4100", no_argument, NULL, OPTION_NO_M4100},
14367 {"m3900", no_argument, NULL, OPTION_M3900},
14368 {"no-m3900", no_argument, NULL, OPTION_NO_M3900},
14370 /* Options which enable bug fixes. */
14371 {"mfix7000", no_argument, NULL, OPTION_M7000_HILO_FIX},
14372 {"no-fix-7000", no_argument, NULL, OPTION_MNO_7000_HILO_FIX},
14373 {"mno-fix7000", no_argument, NULL, OPTION_MNO_7000_HILO_FIX},
14374 {"mfix-loongson2f-jump", no_argument, NULL, OPTION_FIX_LOONGSON2F_JUMP},
14375 {"mno-fix-loongson2f-jump", no_argument, NULL, OPTION_NO_FIX_LOONGSON2F_JUMP},
14376 {"mfix-loongson2f-nop", no_argument, NULL, OPTION_FIX_LOONGSON2F_NOP},
14377 {"mno-fix-loongson2f-nop", no_argument, NULL, OPTION_NO_FIX_LOONGSON2F_NOP},
14378 {"mfix-vr4120", no_argument, NULL, OPTION_FIX_VR4120},
14379 {"mno-fix-vr4120", no_argument, NULL, OPTION_NO_FIX_VR4120},
14380 {"mfix-vr4130", no_argument, NULL, OPTION_FIX_VR4130},
14381 {"mno-fix-vr4130", no_argument, NULL, OPTION_NO_FIX_VR4130},
14382 {"mfix-24k", no_argument, NULL, OPTION_FIX_24K},
14383 {"mno-fix-24k", no_argument, NULL, OPTION_NO_FIX_24K},
14384 {"mfix-cn63xxp1", no_argument, NULL, OPTION_FIX_CN63XXP1},
14385 {"mno-fix-cn63xxp1", no_argument, NULL, OPTION_NO_FIX_CN63XXP1},
14387 /* Miscellaneous options. */
14388 {"trap", no_argument, NULL, OPTION_TRAP},
14389 {"no-break", no_argument, NULL, OPTION_TRAP},
14390 {"break", no_argument, NULL, OPTION_BREAK},
14391 {"no-trap", no_argument, NULL, OPTION_BREAK},
14392 {"EB", no_argument, NULL, OPTION_EB},
14393 {"EL", no_argument, NULL, OPTION_EL},
14394 {"mfp32", no_argument, NULL, OPTION_FP32},
14395 {"mgp32", no_argument, NULL, OPTION_GP32},
14396 {"construct-floats", no_argument, NULL, OPTION_CONSTRUCT_FLOATS},
14397 {"no-construct-floats", no_argument, NULL, OPTION_NO_CONSTRUCT_FLOATS},
14398 {"mfp64", no_argument, NULL, OPTION_FP64},
14399 {"mgp64", no_argument, NULL, OPTION_GP64},
14400 {"relax-branch", no_argument, NULL, OPTION_RELAX_BRANCH},
14401 {"no-relax-branch", no_argument, NULL, OPTION_NO_RELAX_BRANCH},
14402 {"mshared", no_argument, NULL, OPTION_MSHARED},
14403 {"mno-shared", no_argument, NULL, OPTION_MNO_SHARED},
14404 {"msym32", no_argument, NULL, OPTION_MSYM32},
14405 {"mno-sym32", no_argument, NULL, OPTION_MNO_SYM32},
14406 {"msoft-float", no_argument, NULL, OPTION_SOFT_FLOAT},
14407 {"mhard-float", no_argument, NULL, OPTION_HARD_FLOAT},
14408 {"msingle-float", no_argument, NULL, OPTION_SINGLE_FLOAT},
14409 {"mdouble-float", no_argument, NULL, OPTION_DOUBLE_FLOAT},
14411 /* Strictly speaking this next option is ELF specific,
14412 but we allow it for other ports as well in order to
14413 make testing easier. */
14414 {"32", no_argument, NULL, OPTION_32},
14416 /* ELF-specific options. */
14418 {"KPIC", no_argument, NULL, OPTION_CALL_SHARED},
14419 {"call_shared", no_argument, NULL, OPTION_CALL_SHARED},
14420 {"call_nonpic", no_argument, NULL, OPTION_CALL_NONPIC},
14421 {"non_shared", no_argument, NULL, OPTION_NON_SHARED},
14422 {"xgot", no_argument, NULL, OPTION_XGOT},
14423 {"mabi", required_argument, NULL, OPTION_MABI},
14424 {"n32", no_argument, NULL, OPTION_N32},
14425 {"64", no_argument, NULL, OPTION_64},
14426 {"mdebug", no_argument, NULL, OPTION_MDEBUG},
14427 {"no-mdebug", no_argument, NULL, OPTION_NO_MDEBUG},
14428 {"mpdr", no_argument, NULL, OPTION_PDR},
14429 {"mno-pdr", no_argument, NULL, OPTION_NO_PDR},
14430 {"mvxworks-pic", no_argument, NULL, OPTION_MVXWORKS_PIC},
14431 #endif /* OBJ_ELF */
14433 {NULL, no_argument, NULL, 0}
14435 size_t md_longopts_size = sizeof (md_longopts);
14437 /* Set STRING_PTR (either &mips_arch_string or &mips_tune_string) to
14438 NEW_VALUE. Warn if another value was already specified. Note:
14439 we have to defer parsing the -march and -mtune arguments in order
14440 to handle 'from-abi' correctly, since the ABI might be specified
14441 in a later argument. */
14444 mips_set_option_string (const char **string_ptr, const char *new_value)
14446 if (*string_ptr != 0 && strcasecmp (*string_ptr, new_value) != 0)
14447 as_warn (_("A different %s was already specified, is now %s"),
14448 string_ptr == &mips_arch_string ? "-march" : "-mtune",
14451 *string_ptr = new_value;
14455 md_parse_option (int c, char *arg)
14459 case OPTION_CONSTRUCT_FLOATS:
14460 mips_disable_float_construction = 0;
14463 case OPTION_NO_CONSTRUCT_FLOATS:
14464 mips_disable_float_construction = 1;
14476 target_big_endian = 1;
14480 target_big_endian = 0;
14486 else if (arg[0] == '0')
14488 else if (arg[0] == '1')
14498 mips_debug = atoi (arg);
14502 file_mips_isa = ISA_MIPS1;
14506 file_mips_isa = ISA_MIPS2;
14510 file_mips_isa = ISA_MIPS3;
14514 file_mips_isa = ISA_MIPS4;
14518 file_mips_isa = ISA_MIPS5;
14521 case OPTION_MIPS32:
14522 file_mips_isa = ISA_MIPS32;
14525 case OPTION_MIPS32R2:
14526 file_mips_isa = ISA_MIPS32R2;
14529 case OPTION_MIPS64R2:
14530 file_mips_isa = ISA_MIPS64R2;
14533 case OPTION_MIPS64:
14534 file_mips_isa = ISA_MIPS64;
14538 mips_set_option_string (&mips_tune_string, arg);
14542 mips_set_option_string (&mips_arch_string, arg);
14546 mips_set_option_string (&mips_arch_string, "4650");
14547 mips_set_option_string (&mips_tune_string, "4650");
14550 case OPTION_NO_M4650:
14554 mips_set_option_string (&mips_arch_string, "4010");
14555 mips_set_option_string (&mips_tune_string, "4010");
14558 case OPTION_NO_M4010:
14562 mips_set_option_string (&mips_arch_string, "4100");
14563 mips_set_option_string (&mips_tune_string, "4100");
14566 case OPTION_NO_M4100:
14570 mips_set_option_string (&mips_arch_string, "3900");
14571 mips_set_option_string (&mips_tune_string, "3900");
14574 case OPTION_NO_M3900:
14578 mips_opts.ase_mdmx = 1;
14581 case OPTION_NO_MDMX:
14582 mips_opts.ase_mdmx = 0;
14586 mips_opts.ase_dsp = 1;
14587 mips_opts.ase_dspr2 = 0;
14590 case OPTION_NO_DSP:
14591 mips_opts.ase_dsp = 0;
14592 mips_opts.ase_dspr2 = 0;
14596 mips_opts.ase_dspr2 = 1;
14597 mips_opts.ase_dsp = 1;
14600 case OPTION_NO_DSPR2:
14601 mips_opts.ase_dspr2 = 0;
14602 mips_opts.ase_dsp = 0;
14606 mips_opts.ase_mt = 1;
14610 mips_opts.ase_mt = 0;
14614 mips_opts.ase_mcu = 1;
14617 case OPTION_NO_MCU:
14618 mips_opts.ase_mcu = 0;
14621 case OPTION_MICROMIPS:
14622 if (mips_opts.mips16 == 1)
14624 as_bad (_("-mmicromips cannot be used with -mips16"));
14627 mips_opts.micromips = 1;
14628 mips_no_prev_insn ();
14631 case OPTION_NO_MICROMIPS:
14632 mips_opts.micromips = 0;
14633 mips_no_prev_insn ();
14636 case OPTION_MIPS16:
14637 if (mips_opts.micromips == 1)
14639 as_bad (_("-mips16 cannot be used with -micromips"));
14642 mips_opts.mips16 = 1;
14643 mips_no_prev_insn ();
14646 case OPTION_NO_MIPS16:
14647 mips_opts.mips16 = 0;
14648 mips_no_prev_insn ();
14651 case OPTION_MIPS3D:
14652 mips_opts.ase_mips3d = 1;
14655 case OPTION_NO_MIPS3D:
14656 mips_opts.ase_mips3d = 0;
14659 case OPTION_SMARTMIPS:
14660 mips_opts.ase_smartmips = 1;
14663 case OPTION_NO_SMARTMIPS:
14664 mips_opts.ase_smartmips = 0;
14667 case OPTION_FIX_24K:
14671 case OPTION_NO_FIX_24K:
14675 case OPTION_FIX_LOONGSON2F_JUMP:
14676 mips_fix_loongson2f_jump = TRUE;
14679 case OPTION_NO_FIX_LOONGSON2F_JUMP:
14680 mips_fix_loongson2f_jump = FALSE;
14683 case OPTION_FIX_LOONGSON2F_NOP:
14684 mips_fix_loongson2f_nop = TRUE;
14687 case OPTION_NO_FIX_LOONGSON2F_NOP:
14688 mips_fix_loongson2f_nop = FALSE;
14691 case OPTION_FIX_VR4120:
14692 mips_fix_vr4120 = 1;
14695 case OPTION_NO_FIX_VR4120:
14696 mips_fix_vr4120 = 0;
14699 case OPTION_FIX_VR4130:
14700 mips_fix_vr4130 = 1;
14703 case OPTION_NO_FIX_VR4130:
14704 mips_fix_vr4130 = 0;
14707 case OPTION_FIX_CN63XXP1:
14708 mips_fix_cn63xxp1 = TRUE;
14711 case OPTION_NO_FIX_CN63XXP1:
14712 mips_fix_cn63xxp1 = FALSE;
14715 case OPTION_RELAX_BRANCH:
14716 mips_relax_branch = 1;
14719 case OPTION_NO_RELAX_BRANCH:
14720 mips_relax_branch = 0;
14723 case OPTION_MSHARED:
14724 mips_in_shared = TRUE;
14727 case OPTION_MNO_SHARED:
14728 mips_in_shared = FALSE;
14731 case OPTION_MSYM32:
14732 mips_opts.sym32 = TRUE;
14735 case OPTION_MNO_SYM32:
14736 mips_opts.sym32 = FALSE;
14740 /* When generating ELF code, we permit -KPIC and -call_shared to
14741 select SVR4_PIC, and -non_shared to select no PIC. This is
14742 intended to be compatible with Irix 5. */
14743 case OPTION_CALL_SHARED:
14746 as_bad (_("-call_shared is supported only for ELF format"));
14749 mips_pic = SVR4_PIC;
14750 mips_abicalls = TRUE;
14753 case OPTION_CALL_NONPIC:
14756 as_bad (_("-call_nonpic is supported only for ELF format"));
14760 mips_abicalls = TRUE;
14763 case OPTION_NON_SHARED:
14766 as_bad (_("-non_shared is supported only for ELF format"));
14770 mips_abicalls = FALSE;
14773 /* The -xgot option tells the assembler to use 32 bit offsets
14774 when accessing the got in SVR4_PIC mode. It is for Irix
14779 #endif /* OBJ_ELF */
14782 g_switch_value = atoi (arg);
14786 /* The -32, -n32 and -64 options are shortcuts for -mabi=32, -mabi=n32
14790 mips_abi = O32_ABI;
14791 /* We silently ignore -32 for non-ELF targets. This greatly
14792 simplifies the construction of the MIPS GAS test cases. */
14799 as_bad (_("-n32 is supported for ELF format only"));
14802 mips_abi = N32_ABI;
14808 as_bad (_("-64 is supported for ELF format only"));
14811 mips_abi = N64_ABI;
14812 if (!support_64bit_objects())
14813 as_fatal (_("No compiled in support for 64 bit object file format"));
14815 #endif /* OBJ_ELF */
14818 file_mips_gp32 = 1;
14822 file_mips_gp32 = 0;
14826 file_mips_fp32 = 1;
14830 file_mips_fp32 = 0;
14833 case OPTION_SINGLE_FLOAT:
14834 file_mips_single_float = 1;
14837 case OPTION_DOUBLE_FLOAT:
14838 file_mips_single_float = 0;
14841 case OPTION_SOFT_FLOAT:
14842 file_mips_soft_float = 1;
14845 case OPTION_HARD_FLOAT:
14846 file_mips_soft_float = 0;
14853 as_bad (_("-mabi is supported for ELF format only"));
14856 if (strcmp (arg, "32") == 0)
14857 mips_abi = O32_ABI;
14858 else if (strcmp (arg, "o64") == 0)
14859 mips_abi = O64_ABI;
14860 else if (strcmp (arg, "n32") == 0)
14861 mips_abi = N32_ABI;
14862 else if (strcmp (arg, "64") == 0)
14864 mips_abi = N64_ABI;
14865 if (! support_64bit_objects())
14866 as_fatal (_("No compiled in support for 64 bit object file "
14869 else if (strcmp (arg, "eabi") == 0)
14870 mips_abi = EABI_ABI;
14873 as_fatal (_("invalid abi -mabi=%s"), arg);
14877 #endif /* OBJ_ELF */
14879 case OPTION_M7000_HILO_FIX:
14880 mips_7000_hilo_fix = TRUE;
14883 case OPTION_MNO_7000_HILO_FIX:
14884 mips_7000_hilo_fix = FALSE;
14888 case OPTION_MDEBUG:
14889 mips_flag_mdebug = TRUE;
14892 case OPTION_NO_MDEBUG:
14893 mips_flag_mdebug = FALSE;
14897 mips_flag_pdr = TRUE;
14900 case OPTION_NO_PDR:
14901 mips_flag_pdr = FALSE;
14904 case OPTION_MVXWORKS_PIC:
14905 mips_pic = VXWORKS_PIC;
14907 #endif /* OBJ_ELF */
14913 mips_fix_loongson2f = mips_fix_loongson2f_nop || mips_fix_loongson2f_jump;
14918 /* Set up globals to generate code for the ISA or processor
14919 described by INFO. */
14922 mips_set_architecture (const struct mips_cpu_info *info)
14926 file_mips_arch = info->cpu;
14927 mips_opts.arch = info->cpu;
14928 mips_opts.isa = info->isa;
14933 /* Likewise for tuning. */
14936 mips_set_tune (const struct mips_cpu_info *info)
14939 mips_tune = info->cpu;
14944 mips_after_parse_args (void)
14946 const struct mips_cpu_info *arch_info = 0;
14947 const struct mips_cpu_info *tune_info = 0;
14949 /* GP relative stuff not working for PE */
14950 if (strncmp (TARGET_OS, "pe", 2) == 0)
14952 if (g_switch_seen && g_switch_value != 0)
14953 as_bad (_("-G not supported in this configuration."));
14954 g_switch_value = 0;
14957 if (mips_abi == NO_ABI)
14958 mips_abi = MIPS_DEFAULT_ABI;
14960 /* The following code determines the architecture and register size.
14961 Similar code was added to GCC 3.3 (see override_options() in
14962 config/mips/mips.c). The GAS and GCC code should be kept in sync
14963 as much as possible. */
14965 if (mips_arch_string != 0)
14966 arch_info = mips_parse_cpu ("-march", mips_arch_string);
14968 if (file_mips_isa != ISA_UNKNOWN)
14970 /* Handle -mipsN. At this point, file_mips_isa contains the
14971 ISA level specified by -mipsN, while arch_info->isa contains
14972 the -march selection (if any). */
14973 if (arch_info != 0)
14975 /* -march takes precedence over -mipsN, since it is more descriptive.
14976 There's no harm in specifying both as long as the ISA levels
14978 if (file_mips_isa != arch_info->isa)
14979 as_bad (_("-%s conflicts with the other architecture options, which imply -%s"),
14980 mips_cpu_info_from_isa (file_mips_isa)->name,
14981 mips_cpu_info_from_isa (arch_info->isa)->name);
14984 arch_info = mips_cpu_info_from_isa (file_mips_isa);
14987 if (arch_info == 0)
14988 arch_info = mips_parse_cpu ("default CPU", MIPS_CPU_STRING_DEFAULT);
14990 if (ABI_NEEDS_64BIT_REGS (mips_abi) && !ISA_HAS_64BIT_REGS (arch_info->isa))
14991 as_bad (_("-march=%s is not compatible with the selected ABI"),
14994 mips_set_architecture (arch_info);
14996 /* Optimize for file_mips_arch, unless -mtune selects a different processor. */
14997 if (mips_tune_string != 0)
14998 tune_info = mips_parse_cpu ("-mtune", mips_tune_string);
15000 if (tune_info == 0)
15001 mips_set_tune (arch_info);
15003 mips_set_tune (tune_info);
15005 if (file_mips_gp32 >= 0)
15007 /* The user specified the size of the integer registers. Make sure
15008 it agrees with the ABI and ISA. */
15009 if (file_mips_gp32 == 0 && !ISA_HAS_64BIT_REGS (mips_opts.isa))
15010 as_bad (_("-mgp64 used with a 32-bit processor"));
15011 else if (file_mips_gp32 == 1 && ABI_NEEDS_64BIT_REGS (mips_abi))
15012 as_bad (_("-mgp32 used with a 64-bit ABI"));
15013 else if (file_mips_gp32 == 0 && ABI_NEEDS_32BIT_REGS (mips_abi))
15014 as_bad (_("-mgp64 used with a 32-bit ABI"));
15018 /* Infer the integer register size from the ABI and processor.
15019 Restrict ourselves to 32-bit registers if that's all the
15020 processor has, or if the ABI cannot handle 64-bit registers. */
15021 file_mips_gp32 = (ABI_NEEDS_32BIT_REGS (mips_abi)
15022 || !ISA_HAS_64BIT_REGS (mips_opts.isa));
15025 switch (file_mips_fp32)
15029 /* No user specified float register size.
15030 ??? GAS treats single-float processors as though they had 64-bit
15031 float registers (although it complains when double-precision
15032 instructions are used). As things stand, saying they have 32-bit
15033 registers would lead to spurious "register must be even" messages.
15034 So here we assume float registers are never smaller than the
15036 if (file_mips_gp32 == 0)
15037 /* 64-bit integer registers implies 64-bit float registers. */
15038 file_mips_fp32 = 0;
15039 else if ((mips_opts.ase_mips3d > 0 || mips_opts.ase_mdmx > 0)
15040 && ISA_HAS_64BIT_FPRS (mips_opts.isa))
15041 /* -mips3d and -mdmx imply 64-bit float registers, if possible. */
15042 file_mips_fp32 = 0;
15044 /* 32-bit float registers. */
15045 file_mips_fp32 = 1;
15048 /* The user specified the size of the float registers. Check if it
15049 agrees with the ABI and ISA. */
15051 if (!ISA_HAS_64BIT_FPRS (mips_opts.isa))
15052 as_bad (_("-mfp64 used with a 32-bit fpu"));
15053 else if (ABI_NEEDS_32BIT_REGS (mips_abi)
15054 && !ISA_HAS_MXHC1 (mips_opts.isa))
15055 as_warn (_("-mfp64 used with a 32-bit ABI"));
15058 if (ABI_NEEDS_64BIT_REGS (mips_abi))
15059 as_warn (_("-mfp32 used with a 64-bit ABI"));
15063 /* End of GCC-shared inference code. */
15065 /* This flag is set when we have a 64-bit capable CPU but use only
15066 32-bit wide registers. Note that EABI does not use it. */
15067 if (ISA_HAS_64BIT_REGS (mips_opts.isa)
15068 && ((mips_abi == NO_ABI && file_mips_gp32 == 1)
15069 || mips_abi == O32_ABI))
15070 mips_32bitmode = 1;
15072 if (mips_opts.isa == ISA_MIPS1 && mips_trap)
15073 as_bad (_("trap exception not supported at ISA 1"));
15075 /* If the selected architecture includes support for ASEs, enable
15076 generation of code for them. */
15077 if (mips_opts.mips16 == -1)
15078 mips_opts.mips16 = (CPU_HAS_MIPS16 (file_mips_arch)) ? 1 : 0;
15079 if (mips_opts.micromips == -1)
15080 mips_opts.micromips = (CPU_HAS_MICROMIPS (file_mips_arch)) ? 1 : 0;
15081 if (mips_opts.ase_mips3d == -1)
15082 mips_opts.ase_mips3d = ((arch_info->flags & MIPS_CPU_ASE_MIPS3D)
15083 && file_mips_fp32 == 0) ? 1 : 0;
15084 if (mips_opts.ase_mips3d && file_mips_fp32 == 1)
15085 as_bad (_("-mfp32 used with -mips3d"));
15087 if (mips_opts.ase_mdmx == -1)
15088 mips_opts.ase_mdmx = ((arch_info->flags & MIPS_CPU_ASE_MDMX)
15089 && file_mips_fp32 == 0) ? 1 : 0;
15090 if (mips_opts.ase_mdmx && file_mips_fp32 == 1)
15091 as_bad (_("-mfp32 used with -mdmx"));
15093 if (mips_opts.ase_smartmips == -1)
15094 mips_opts.ase_smartmips = (arch_info->flags & MIPS_CPU_ASE_SMARTMIPS) ? 1 : 0;
15095 if (mips_opts.ase_smartmips && !ISA_SUPPORTS_SMARTMIPS)
15096 as_warn (_("%s ISA does not support SmartMIPS"),
15097 mips_cpu_info_from_isa (mips_opts.isa)->name);
15099 if (mips_opts.ase_dsp == -1)
15100 mips_opts.ase_dsp = (arch_info->flags & MIPS_CPU_ASE_DSP) ? 1 : 0;
15101 if (mips_opts.ase_dsp && !ISA_SUPPORTS_DSP_ASE)
15102 as_warn (_("%s ISA does not support DSP ASE"),
15103 mips_cpu_info_from_isa (mips_opts.isa)->name);
15105 if (mips_opts.ase_dspr2 == -1)
15107 mips_opts.ase_dspr2 = (arch_info->flags & MIPS_CPU_ASE_DSPR2) ? 1 : 0;
15108 mips_opts.ase_dsp = (arch_info->flags & MIPS_CPU_ASE_DSP) ? 1 : 0;
15110 if (mips_opts.ase_dspr2 && !ISA_SUPPORTS_DSPR2_ASE)
15111 as_warn (_("%s ISA does not support DSP R2 ASE"),
15112 mips_cpu_info_from_isa (mips_opts.isa)->name);
15114 if (mips_opts.ase_mt == -1)
15115 mips_opts.ase_mt = (arch_info->flags & MIPS_CPU_ASE_MT) ? 1 : 0;
15116 if (mips_opts.ase_mt && !ISA_SUPPORTS_MT_ASE)
15117 as_warn (_("%s ISA does not support MT ASE"),
15118 mips_cpu_info_from_isa (mips_opts.isa)->name);
15120 if (mips_opts.ase_mcu == -1)
15121 mips_opts.ase_mcu = (arch_info->flags & MIPS_CPU_ASE_MCU) ? 1 : 0;
15122 if (mips_opts.ase_mcu && !ISA_SUPPORTS_MCU_ASE)
15123 as_warn (_("%s ISA does not support MCU ASE"),
15124 mips_cpu_info_from_isa (mips_opts.isa)->name);
15126 file_mips_isa = mips_opts.isa;
15127 file_ase_mips3d = mips_opts.ase_mips3d;
15128 file_ase_mdmx = mips_opts.ase_mdmx;
15129 file_ase_smartmips = mips_opts.ase_smartmips;
15130 file_ase_dsp = mips_opts.ase_dsp;
15131 file_ase_dspr2 = mips_opts.ase_dspr2;
15132 file_ase_mt = mips_opts.ase_mt;
15133 mips_opts.gp32 = file_mips_gp32;
15134 mips_opts.fp32 = file_mips_fp32;
15135 mips_opts.soft_float = file_mips_soft_float;
15136 mips_opts.single_float = file_mips_single_float;
15138 if (mips_flag_mdebug < 0)
15140 #ifdef OBJ_MAYBE_ECOFF
15141 if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour)
15142 mips_flag_mdebug = 1;
15144 #endif /* OBJ_MAYBE_ECOFF */
15145 mips_flag_mdebug = 0;
15150 mips_init_after_args (void)
15152 /* initialize opcodes */
15153 bfd_mips_num_opcodes = bfd_mips_num_builtin_opcodes;
15154 mips_opcodes = (struct mips_opcode *) mips_builtin_opcodes;
15158 md_pcrel_from (fixS *fixP)
15160 valueT addr = fixP->fx_where + fixP->fx_frag->fr_address;
15161 switch (fixP->fx_r_type)
15163 case BFD_RELOC_MICROMIPS_7_PCREL_S1:
15164 case BFD_RELOC_MICROMIPS_10_PCREL_S1:
15165 /* Return the address of the delay slot. */
15168 case BFD_RELOC_MICROMIPS_16_PCREL_S1:
15169 case BFD_RELOC_MICROMIPS_JMP:
15170 case BFD_RELOC_16_PCREL_S2:
15171 case BFD_RELOC_MIPS_JMP:
15172 /* Return the address of the delay slot. */
15176 /* We have no relocation type for PC relative MIPS16 instructions. */
15177 if (fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != now_seg)
15178 as_bad_where (fixP->fx_file, fixP->fx_line,
15179 _("PC relative MIPS16 instruction references a different section"));
15184 /* This is called before the symbol table is processed. In order to
15185 work with gcc when using mips-tfile, we must keep all local labels.
15186 However, in other cases, we want to discard them. If we were
15187 called with -g, but we didn't see any debugging information, it may
15188 mean that gcc is smuggling debugging information through to
15189 mips-tfile, in which case we must generate all local labels. */
15192 mips_frob_file_before_adjust (void)
15194 #ifndef NO_ECOFF_DEBUGGING
15195 if (ECOFF_DEBUGGING
15197 && ! ecoff_debugging_seen)
15198 flag_keep_locals = 1;
15202 /* Sort any unmatched HI16 and GOT16 relocs so that they immediately precede
15203 the corresponding LO16 reloc. This is called before md_apply_fix and
15204 tc_gen_reloc. Unmatched relocs can only be generated by use of explicit
15205 relocation operators.
15207 For our purposes, a %lo() expression matches a %got() or %hi()
15210 (a) it refers to the same symbol; and
15211 (b) the offset applied in the %lo() expression is no lower than
15212 the offset applied in the %got() or %hi().
15214 (b) allows us to cope with code like:
15217 lh $4,%lo(foo+2)($4)
15219 ...which is legal on RELA targets, and has a well-defined behaviour
15220 if the user knows that adding 2 to "foo" will not induce a carry to
15223 When several %lo()s match a particular %got() or %hi(), we use the
15224 following rules to distinguish them:
15226 (1) %lo()s with smaller offsets are a better match than %lo()s with
15229 (2) %lo()s with no matching %got() or %hi() are better than those
15230 that already have a matching %got() or %hi().
15232 (3) later %lo()s are better than earlier %lo()s.
15234 These rules are applied in order.
15236 (1) means, among other things, that %lo()s with identical offsets are
15237 chosen if they exist.
15239 (2) means that we won't associate several high-part relocations with
15240 the same low-part relocation unless there's no alternative. Having
15241 several high parts for the same low part is a GNU extension; this rule
15242 allows careful users to avoid it.
15244 (3) is purely cosmetic. mips_hi_fixup_list is is in reverse order,
15245 with the last high-part relocation being at the front of the list.
15246 It therefore makes sense to choose the last matching low-part
15247 relocation, all other things being equal. It's also easier
15248 to code that way. */
15251 mips_frob_file (void)
15253 struct mips_hi_fixup *l;
15254 bfd_reloc_code_real_type looking_for_rtype = BFD_RELOC_UNUSED;
15256 for (l = mips_hi_fixup_list; l != NULL; l = l->next)
15258 segment_info_type *seginfo;
15259 bfd_boolean matched_lo_p;
15260 fixS **hi_pos, **lo_pos, **pos;
15262 gas_assert (reloc_needs_lo_p (l->fixp->fx_r_type));
15264 /* If a GOT16 relocation turns out to be against a global symbol,
15265 there isn't supposed to be a matching LO. */
15266 if (got16_reloc_p (l->fixp->fx_r_type)
15267 && !pic_need_relax (l->fixp->fx_addsy, l->seg))
15270 /* Check quickly whether the next fixup happens to be a matching %lo. */
15271 if (fixup_has_matching_lo_p (l->fixp))
15274 seginfo = seg_info (l->seg);
15276 /* Set HI_POS to the position of this relocation in the chain.
15277 Set LO_POS to the position of the chosen low-part relocation.
15278 MATCHED_LO_P is true on entry to the loop if *POS is a low-part
15279 relocation that matches an immediately-preceding high-part
15283 matched_lo_p = FALSE;
15284 looking_for_rtype = matching_lo_reloc (l->fixp->fx_r_type);
15286 for (pos = &seginfo->fix_root; *pos != NULL; pos = &(*pos)->fx_next)
15288 if (*pos == l->fixp)
15291 if ((*pos)->fx_r_type == looking_for_rtype
15292 && symbol_same_p ((*pos)->fx_addsy, l->fixp->fx_addsy)
15293 && (*pos)->fx_offset >= l->fixp->fx_offset
15295 || (*pos)->fx_offset < (*lo_pos)->fx_offset
15297 && (*pos)->fx_offset == (*lo_pos)->fx_offset)))
15300 matched_lo_p = (reloc_needs_lo_p ((*pos)->fx_r_type)
15301 && fixup_has_matching_lo_p (*pos));
15304 /* If we found a match, remove the high-part relocation from its
15305 current position and insert it before the low-part relocation.
15306 Make the offsets match so that fixup_has_matching_lo_p()
15309 We don't warn about unmatched high-part relocations since some
15310 versions of gcc have been known to emit dead "lui ...%hi(...)"
15312 if (lo_pos != NULL)
15314 l->fixp->fx_offset = (*lo_pos)->fx_offset;
15315 if (l->fixp->fx_next != *lo_pos)
15317 *hi_pos = l->fixp->fx_next;
15318 l->fixp->fx_next = *lo_pos;
15325 /* We may have combined relocations without symbols in the N32/N64 ABI.
15326 We have to prevent gas from dropping them. */
15329 mips_force_relocation (fixS *fixp)
15331 if (generic_force_reloc (fixp))
15334 /* We want to keep BFD_RELOC_MICROMIPS_*_PCREL_S1 relocation,
15335 so that the linker relaxation can update targets. */
15336 if (fixp->fx_r_type == BFD_RELOC_MICROMIPS_7_PCREL_S1
15337 || fixp->fx_r_type == BFD_RELOC_MICROMIPS_10_PCREL_S1
15338 || fixp->fx_r_type == BFD_RELOC_MICROMIPS_16_PCREL_S1)
15342 && S_GET_SEGMENT (fixp->fx_addsy) == bfd_abs_section_ptr
15343 && (fixp->fx_r_type == BFD_RELOC_MIPS_SUB
15344 || hi16_reloc_p (fixp->fx_r_type)
15345 || lo16_reloc_p (fixp->fx_r_type)))
15351 /* Apply a fixup to the object file. */
15354 md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
15358 reloc_howto_type *howto;
15360 /* We ignore generic BFD relocations we don't know about. */
15361 howto = bfd_reloc_type_lookup (stdoutput, fixP->fx_r_type);
15365 gas_assert (fixP->fx_size == 2
15366 || fixP->fx_size == 4
15367 || fixP->fx_r_type == BFD_RELOC_16
15368 || fixP->fx_r_type == BFD_RELOC_64
15369 || fixP->fx_r_type == BFD_RELOC_CTOR
15370 || fixP->fx_r_type == BFD_RELOC_MIPS_SUB
15371 || fixP->fx_r_type == BFD_RELOC_MICROMIPS_SUB
15372 || fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
15373 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY
15374 || fixP->fx_r_type == BFD_RELOC_MIPS_TLS_DTPREL64);
15376 buf = (bfd_byte *) (fixP->fx_frag->fr_literal + fixP->fx_where);
15378 gas_assert (!fixP->fx_pcrel || fixP->fx_r_type == BFD_RELOC_16_PCREL_S2
15379 || fixP->fx_r_type == BFD_RELOC_MICROMIPS_7_PCREL_S1
15380 || fixP->fx_r_type == BFD_RELOC_MICROMIPS_10_PCREL_S1
15381 || fixP->fx_r_type == BFD_RELOC_MICROMIPS_16_PCREL_S1);
15383 /* Don't treat parts of a composite relocation as done. There are two
15386 (1) The second and third parts will be against 0 (RSS_UNDEF) but
15387 should nevertheless be emitted if the first part is.
15389 (2) In normal usage, composite relocations are never assembly-time
15390 constants. The easiest way of dealing with the pathological
15391 exceptions is to generate a relocation against STN_UNDEF and
15392 leave everything up to the linker. */
15393 if (fixP->fx_addsy == NULL && !fixP->fx_pcrel && fixP->fx_tcbit == 0)
15396 switch (fixP->fx_r_type)
15398 case BFD_RELOC_MIPS_TLS_GD:
15399 case BFD_RELOC_MIPS_TLS_LDM:
15400 case BFD_RELOC_MIPS_TLS_DTPREL32:
15401 case BFD_RELOC_MIPS_TLS_DTPREL64:
15402 case BFD_RELOC_MIPS_TLS_DTPREL_HI16:
15403 case BFD_RELOC_MIPS_TLS_DTPREL_LO16:
15404 case BFD_RELOC_MIPS_TLS_GOTTPREL:
15405 case BFD_RELOC_MIPS_TLS_TPREL_HI16:
15406 case BFD_RELOC_MIPS_TLS_TPREL_LO16:
15407 case BFD_RELOC_MICROMIPS_TLS_GD:
15408 case BFD_RELOC_MICROMIPS_TLS_LDM:
15409 case BFD_RELOC_MICROMIPS_TLS_DTPREL_HI16:
15410 case BFD_RELOC_MICROMIPS_TLS_DTPREL_LO16:
15411 case BFD_RELOC_MICROMIPS_TLS_GOTTPREL:
15412 case BFD_RELOC_MICROMIPS_TLS_TPREL_HI16:
15413 case BFD_RELOC_MICROMIPS_TLS_TPREL_LO16:
15414 S_SET_THREAD_LOCAL (fixP->fx_addsy);
15417 case BFD_RELOC_MIPS_JMP:
15418 case BFD_RELOC_MIPS_SHIFT5:
15419 case BFD_RELOC_MIPS_SHIFT6:
15420 case BFD_RELOC_MIPS_GOT_DISP:
15421 case BFD_RELOC_MIPS_GOT_PAGE:
15422 case BFD_RELOC_MIPS_GOT_OFST:
15423 case BFD_RELOC_MIPS_SUB:
15424 case BFD_RELOC_MIPS_INSERT_A:
15425 case BFD_RELOC_MIPS_INSERT_B:
15426 case BFD_RELOC_MIPS_DELETE:
15427 case BFD_RELOC_MIPS_HIGHEST:
15428 case BFD_RELOC_MIPS_HIGHER:
15429 case BFD_RELOC_MIPS_SCN_DISP:
15430 case BFD_RELOC_MIPS_REL16:
15431 case BFD_RELOC_MIPS_RELGOT:
15432 case BFD_RELOC_MIPS_JALR:
15433 case BFD_RELOC_HI16:
15434 case BFD_RELOC_HI16_S:
15435 case BFD_RELOC_GPREL16:
15436 case BFD_RELOC_MIPS_LITERAL:
15437 case BFD_RELOC_MIPS_CALL16:
15438 case BFD_RELOC_MIPS_GOT16:
15439 case BFD_RELOC_GPREL32:
15440 case BFD_RELOC_MIPS_GOT_HI16:
15441 case BFD_RELOC_MIPS_GOT_LO16:
15442 case BFD_RELOC_MIPS_CALL_HI16:
15443 case BFD_RELOC_MIPS_CALL_LO16:
15444 case BFD_RELOC_MIPS16_GPREL:
15445 case BFD_RELOC_MIPS16_GOT16:
15446 case BFD_RELOC_MIPS16_CALL16:
15447 case BFD_RELOC_MIPS16_HI16:
15448 case BFD_RELOC_MIPS16_HI16_S:
15449 case BFD_RELOC_MIPS16_JMP:
15450 case BFD_RELOC_MICROMIPS_JMP:
15451 case BFD_RELOC_MICROMIPS_GOT_DISP:
15452 case BFD_RELOC_MICROMIPS_GOT_PAGE:
15453 case BFD_RELOC_MICROMIPS_GOT_OFST:
15454 case BFD_RELOC_MICROMIPS_SUB:
15455 case BFD_RELOC_MICROMIPS_HIGHEST:
15456 case BFD_RELOC_MICROMIPS_HIGHER:
15457 case BFD_RELOC_MICROMIPS_SCN_DISP:
15458 case BFD_RELOC_MICROMIPS_JALR:
15459 case BFD_RELOC_MICROMIPS_HI16:
15460 case BFD_RELOC_MICROMIPS_HI16_S:
15461 case BFD_RELOC_MICROMIPS_GPREL16:
15462 case BFD_RELOC_MICROMIPS_LITERAL:
15463 case BFD_RELOC_MICROMIPS_CALL16:
15464 case BFD_RELOC_MICROMIPS_GOT16:
15465 case BFD_RELOC_MICROMIPS_GOT_HI16:
15466 case BFD_RELOC_MICROMIPS_GOT_LO16:
15467 case BFD_RELOC_MICROMIPS_CALL_HI16:
15468 case BFD_RELOC_MICROMIPS_CALL_LO16:
15469 /* Nothing needed to do. The value comes from the reloc entry. */
15473 /* This is handled like BFD_RELOC_32, but we output a sign
15474 extended value if we are only 32 bits. */
15477 if (8 <= sizeof (valueT))
15478 md_number_to_chars ((char *) buf, *valP, 8);
15483 if ((*valP & 0x80000000) != 0)
15487 md_number_to_chars ((char *)(buf + (target_big_endian ? 4 : 0)),
15489 md_number_to_chars ((char *)(buf + (target_big_endian ? 0 : 4)),
15495 case BFD_RELOC_RVA:
15498 /* If we are deleting this reloc entry, we must fill in the
15499 value now. This can happen if we have a .word which is not
15500 resolved when it appears but is later defined. */
15502 md_number_to_chars ((char *) buf, *valP, fixP->fx_size);
15505 case BFD_RELOC_LO16:
15506 case BFD_RELOC_MIPS16_LO16:
15507 case BFD_RELOC_MICROMIPS_LO16:
15508 /* FIXME: Now that embedded-PIC is gone, some of this code/comment
15509 may be safe to remove, but if so it's not obvious. */
15510 /* When handling an embedded PIC switch statement, we can wind
15511 up deleting a LO16 reloc. See the 'o' case in mips_ip. */
15514 if (*valP + 0x8000 > 0xffff)
15515 as_bad_where (fixP->fx_file, fixP->fx_line,
15516 _("relocation overflow"));
15517 /* 32-bit microMIPS instructions are divided into two halfwords.
15518 Relocations always refer to the second halfword, regardless
15520 if (target_big_endian || fixP->fx_r_type == BFD_RELOC_MICROMIPS_LO16)
15522 md_number_to_chars ((char *) buf, *valP, 2);
15526 case BFD_RELOC_16_PCREL_S2:
15527 if ((*valP & 0x3) != 0)
15528 as_bad_where (fixP->fx_file, fixP->fx_line,
15529 _("Branch to misaligned address (%lx)"), (long) *valP);
15531 /* We need to save the bits in the instruction since fixup_segment()
15532 might be deleting the relocation entry (i.e., a branch within
15533 the current segment). */
15534 if (! fixP->fx_done)
15537 /* Update old instruction data. */
15538 if (target_big_endian)
15539 insn = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
15541 insn = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
15543 if (*valP + 0x20000 <= 0x3ffff)
15545 insn |= (*valP >> 2) & 0xffff;
15546 md_number_to_chars ((char *) buf, insn, 4);
15548 else if (mips_pic == NO_PIC
15550 && fixP->fx_frag->fr_address >= text_section->vma
15551 && (fixP->fx_frag->fr_address
15552 < text_section->vma + bfd_get_section_size (text_section))
15553 && ((insn & 0xffff0000) == 0x10000000 /* beq $0,$0 */
15554 || (insn & 0xffff0000) == 0x04010000 /* bgez $0 */
15555 || (insn & 0xffff0000) == 0x04110000)) /* bgezal $0 */
15557 /* The branch offset is too large. If this is an
15558 unconditional branch, and we are not generating PIC code,
15559 we can convert it to an absolute jump instruction. */
15560 if ((insn & 0xffff0000) == 0x04110000) /* bgezal $0 */
15561 insn = 0x0c000000; /* jal */
15563 insn = 0x08000000; /* j */
15564 fixP->fx_r_type = BFD_RELOC_MIPS_JMP;
15566 fixP->fx_addsy = section_symbol (text_section);
15567 *valP += md_pcrel_from (fixP);
15568 md_number_to_chars ((char *) buf, insn, 4);
15572 /* If we got here, we have branch-relaxation disabled,
15573 and there's nothing we can do to fix this instruction
15574 without turning it into a longer sequence. */
15575 as_bad_where (fixP->fx_file, fixP->fx_line,
15576 _("Branch out of range"));
15580 case BFD_RELOC_MICROMIPS_7_PCREL_S1:
15581 case BFD_RELOC_MICROMIPS_10_PCREL_S1:
15582 case BFD_RELOC_MICROMIPS_16_PCREL_S1:
15583 /* We adjust the offset back to even. */
15584 if ((*valP & 0x1) != 0)
15587 if (! fixP->fx_done)
15590 /* Should never visit here, because we keep the relocation. */
15594 case BFD_RELOC_VTABLE_INHERIT:
15597 && !S_IS_DEFINED (fixP->fx_addsy)
15598 && !S_IS_WEAK (fixP->fx_addsy))
15599 S_SET_WEAK (fixP->fx_addsy);
15602 case BFD_RELOC_VTABLE_ENTRY:
15610 /* Remember value for tc_gen_reloc. */
15611 fixP->fx_addnumber = *valP;
15621 name = input_line_pointer;
15622 c = get_symbol_end ();
15623 p = (symbolS *) symbol_find_or_make (name);
15624 *input_line_pointer = c;
15628 /* Align the current frag to a given power of two. If a particular
15629 fill byte should be used, FILL points to an integer that contains
15630 that byte, otherwise FILL is null.
15632 The MIPS assembler also automatically adjusts any preceding
15636 mips_align (int to, int *fill, symbolS *label)
15638 mips_emit_delays ();
15639 mips_record_compressed_mode ();
15640 if (fill == NULL && subseg_text_p (now_seg))
15641 frag_align_code (to, 0);
15643 frag_align (to, fill ? *fill : 0, 0);
15644 record_alignment (now_seg, to);
15647 gas_assert (S_GET_SEGMENT (label) == now_seg);
15648 symbol_set_frag (label, frag_now);
15649 S_SET_VALUE (label, (valueT) frag_now_fix ());
15653 /* Align to a given power of two. .align 0 turns off the automatic
15654 alignment used by the data creating pseudo-ops. */
15657 s_align (int x ATTRIBUTE_UNUSED)
15659 int temp, fill_value, *fill_ptr;
15660 long max_alignment = 28;
15662 /* o Note that the assembler pulls down any immediately preceding label
15663 to the aligned address.
15664 o It's not documented but auto alignment is reinstated by
15665 a .align pseudo instruction.
15666 o Note also that after auto alignment is turned off the mips assembler
15667 issues an error on attempt to assemble an improperly aligned data item.
15670 temp = get_absolute_expression ();
15671 if (temp > max_alignment)
15672 as_bad (_("Alignment too large: %d. assumed."), temp = max_alignment);
15675 as_warn (_("Alignment negative: 0 assumed."));
15678 if (*input_line_pointer == ',')
15680 ++input_line_pointer;
15681 fill_value = get_absolute_expression ();
15682 fill_ptr = &fill_value;
15688 segment_info_type *si = seg_info (now_seg);
15689 struct insn_label_list *l = si->label_list;
15690 /* Auto alignment should be switched on by next section change. */
15692 mips_align (temp, fill_ptr, l != NULL ? l->label : NULL);
15699 demand_empty_rest_of_line ();
15703 s_change_sec (int sec)
15708 /* The ELF backend needs to know that we are changing sections, so
15709 that .previous works correctly. We could do something like check
15710 for an obj_section_change_hook macro, but that might be confusing
15711 as it would not be appropriate to use it in the section changing
15712 functions in read.c, since obj-elf.c intercepts those. FIXME:
15713 This should be cleaner, somehow. */
15715 obj_elf_section_change_hook ();
15718 mips_emit_delays ();
15729 subseg_set (bss_section, (subsegT) get_absolute_expression ());
15730 demand_empty_rest_of_line ();
15734 seg = subseg_new (RDATA_SECTION_NAME,
15735 (subsegT) get_absolute_expression ());
15738 bfd_set_section_flags (stdoutput, seg, (SEC_ALLOC | SEC_LOAD
15739 | SEC_READONLY | SEC_RELOC
15741 if (strncmp (TARGET_OS, "elf", 3) != 0)
15742 record_alignment (seg, 4);
15744 demand_empty_rest_of_line ();
15748 seg = subseg_new (".sdata", (subsegT) get_absolute_expression ());
15751 bfd_set_section_flags (stdoutput, seg,
15752 SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_DATA);
15753 if (strncmp (TARGET_OS, "elf", 3) != 0)
15754 record_alignment (seg, 4);
15756 demand_empty_rest_of_line ();
15760 seg = subseg_new (".sbss", (subsegT) get_absolute_expression ());
15763 bfd_set_section_flags (stdoutput, seg, SEC_ALLOC);
15764 if (strncmp (TARGET_OS, "elf", 3) != 0)
15765 record_alignment (seg, 4);
15767 demand_empty_rest_of_line ();
15775 s_change_section (int ignore ATTRIBUTE_UNUSED)
15778 char *section_name;
15783 int section_entry_size;
15784 int section_alignment;
15789 section_name = input_line_pointer;
15790 c = get_symbol_end ();
15792 next_c = *(input_line_pointer + 1);
15794 /* Do we have .section Name<,"flags">? */
15795 if (c != ',' || (c == ',' && next_c == '"'))
15797 /* just after name is now '\0'. */
15798 *input_line_pointer = c;
15799 input_line_pointer = section_name;
15800 obj_elf_section (ignore);
15803 input_line_pointer++;
15805 /* Do we have .section Name<,type><,flag><,entry_size><,alignment> */
15807 section_type = get_absolute_expression ();
15810 if (*input_line_pointer++ == ',')
15811 section_flag = get_absolute_expression ();
15814 if (*input_line_pointer++ == ',')
15815 section_entry_size = get_absolute_expression ();
15817 section_entry_size = 0;
15818 if (*input_line_pointer++ == ',')
15819 section_alignment = get_absolute_expression ();
15821 section_alignment = 0;
15822 /* FIXME: really ignore? */
15823 (void) section_alignment;
15825 section_name = xstrdup (section_name);
15827 /* When using the generic form of .section (as implemented by obj-elf.c),
15828 there's no way to set the section type to SHT_MIPS_DWARF. Users have
15829 traditionally had to fall back on the more common @progbits instead.
15831 There's nothing really harmful in this, since bfd will correct
15832 SHT_PROGBITS to SHT_MIPS_DWARF before writing out the file. But it
15833 means that, for backwards compatibility, the special_section entries
15834 for dwarf sections must use SHT_PROGBITS rather than SHT_MIPS_DWARF.
15836 Even so, we shouldn't force users of the MIPS .section syntax to
15837 incorrectly label the sections as SHT_PROGBITS. The best compromise
15838 seems to be to map SHT_MIPS_DWARF to SHT_PROGBITS before calling the
15839 generic type-checking code. */
15840 if (section_type == SHT_MIPS_DWARF)
15841 section_type = SHT_PROGBITS;
15843 obj_elf_change_section (section_name, section_type, section_flag,
15844 section_entry_size, 0, 0, 0);
15846 if (now_seg->name != section_name)
15847 free (section_name);
15848 #endif /* OBJ_ELF */
15852 mips_enable_auto_align (void)
15858 s_cons (int log_size)
15860 segment_info_type *si = seg_info (now_seg);
15861 struct insn_label_list *l = si->label_list;
15864 label = l != NULL ? l->label : NULL;
15865 mips_emit_delays ();
15866 if (log_size > 0 && auto_align)
15867 mips_align (log_size, 0, label);
15868 cons (1 << log_size);
15869 mips_clear_insn_labels ();
15873 s_float_cons (int type)
15875 segment_info_type *si = seg_info (now_seg);
15876 struct insn_label_list *l = si->label_list;
15879 label = l != NULL ? l->label : NULL;
15881 mips_emit_delays ();
15886 mips_align (3, 0, label);
15888 mips_align (2, 0, label);
15892 mips_clear_insn_labels ();
15895 /* Handle .globl. We need to override it because on Irix 5 you are
15898 where foo is an undefined symbol, to mean that foo should be
15899 considered to be the address of a function. */
15902 s_mips_globl (int x ATTRIBUTE_UNUSED)
15911 name = input_line_pointer;
15912 c = get_symbol_end ();
15913 symbolP = symbol_find_or_make (name);
15914 S_SET_EXTERNAL (symbolP);
15916 *input_line_pointer = c;
15917 SKIP_WHITESPACE ();
15919 /* On Irix 5, every global symbol that is not explicitly labelled as
15920 being a function is apparently labelled as being an object. */
15923 if (!is_end_of_line[(unsigned char) *input_line_pointer]
15924 && (*input_line_pointer != ','))
15929 secname = input_line_pointer;
15930 c = get_symbol_end ();
15931 sec = bfd_get_section_by_name (stdoutput, secname);
15933 as_bad (_("%s: no such section"), secname);
15934 *input_line_pointer = c;
15936 if (sec != NULL && (sec->flags & SEC_CODE) != 0)
15937 flag = BSF_FUNCTION;
15940 symbol_get_bfdsym (symbolP)->flags |= flag;
15942 c = *input_line_pointer;
15945 input_line_pointer++;
15946 SKIP_WHITESPACE ();
15947 if (is_end_of_line[(unsigned char) *input_line_pointer])
15953 demand_empty_rest_of_line ();
15957 s_option (int x ATTRIBUTE_UNUSED)
15962 opt = input_line_pointer;
15963 c = get_symbol_end ();
15967 /* FIXME: What does this mean? */
15969 else if (strncmp (opt, "pic", 3) == 0)
15973 i = atoi (opt + 3);
15978 mips_pic = SVR4_PIC;
15979 mips_abicalls = TRUE;
15982 as_bad (_(".option pic%d not supported"), i);
15984 if (mips_pic == SVR4_PIC)
15986 if (g_switch_seen && g_switch_value != 0)
15987 as_warn (_("-G may not be used with SVR4 PIC code"));
15988 g_switch_value = 0;
15989 bfd_set_gp_size (stdoutput, 0);
15993 as_warn (_("Unrecognized option \"%s\""), opt);
15995 *input_line_pointer = c;
15996 demand_empty_rest_of_line ();
15999 /* This structure is used to hold a stack of .set values. */
16001 struct mips_option_stack
16003 struct mips_option_stack *next;
16004 struct mips_set_options options;
16007 static struct mips_option_stack *mips_opts_stack;
16009 /* Handle the .set pseudo-op. */
16012 s_mipsset (int x ATTRIBUTE_UNUSED)
16014 char *name = input_line_pointer, ch;
16016 while (!is_end_of_line[(unsigned char) *input_line_pointer])
16017 ++input_line_pointer;
16018 ch = *input_line_pointer;
16019 *input_line_pointer = '\0';
16021 if (strcmp (name, "reorder") == 0)
16023 if (mips_opts.noreorder)
16026 else if (strcmp (name, "noreorder") == 0)
16028 if (!mips_opts.noreorder)
16029 start_noreorder ();
16031 else if (strncmp (name, "at=", 3) == 0)
16033 char *s = name + 3;
16035 if (!reg_lookup (&s, RTYPE_NUM | RTYPE_GP, &mips_opts.at))
16036 as_bad (_("Unrecognized register name `%s'"), s);
16038 else if (strcmp (name, "at") == 0)
16040 mips_opts.at = ATREG;
16042 else if (strcmp (name, "noat") == 0)
16044 mips_opts.at = ZERO;
16046 else if (strcmp (name, "macro") == 0)
16048 mips_opts.warn_about_macros = 0;
16050 else if (strcmp (name, "nomacro") == 0)
16052 if (mips_opts.noreorder == 0)
16053 as_bad (_("`noreorder' must be set before `nomacro'"));
16054 mips_opts.warn_about_macros = 1;
16056 else if (strcmp (name, "move") == 0 || strcmp (name, "novolatile") == 0)
16058 mips_opts.nomove = 0;
16060 else if (strcmp (name, "nomove") == 0 || strcmp (name, "volatile") == 0)
16062 mips_opts.nomove = 1;
16064 else if (strcmp (name, "bopt") == 0)
16066 mips_opts.nobopt = 0;
16068 else if (strcmp (name, "nobopt") == 0)
16070 mips_opts.nobopt = 1;
16072 else if (strcmp (name, "gp=default") == 0)
16073 mips_opts.gp32 = file_mips_gp32;
16074 else if (strcmp (name, "gp=32") == 0)
16075 mips_opts.gp32 = 1;
16076 else if (strcmp (name, "gp=64") == 0)
16078 if (!ISA_HAS_64BIT_REGS (mips_opts.isa))
16079 as_warn (_("%s isa does not support 64-bit registers"),
16080 mips_cpu_info_from_isa (mips_opts.isa)->name);
16081 mips_opts.gp32 = 0;
16083 else if (strcmp (name, "fp=default") == 0)
16084 mips_opts.fp32 = file_mips_fp32;
16085 else if (strcmp (name, "fp=32") == 0)
16086 mips_opts.fp32 = 1;
16087 else if (strcmp (name, "fp=64") == 0)
16089 if (!ISA_HAS_64BIT_FPRS (mips_opts.isa))
16090 as_warn (_("%s isa does not support 64-bit floating point registers"),
16091 mips_cpu_info_from_isa (mips_opts.isa)->name);
16092 mips_opts.fp32 = 0;
16094 else if (strcmp (name, "softfloat") == 0)
16095 mips_opts.soft_float = 1;
16096 else if (strcmp (name, "hardfloat") == 0)
16097 mips_opts.soft_float = 0;
16098 else if (strcmp (name, "singlefloat") == 0)
16099 mips_opts.single_float = 1;
16100 else if (strcmp (name, "doublefloat") == 0)
16101 mips_opts.single_float = 0;
16102 else if (strcmp (name, "mips16") == 0
16103 || strcmp (name, "MIPS-16") == 0)
16105 if (mips_opts.micromips == 1)
16106 as_fatal (_("`mips16' cannot be used with `micromips'"));
16107 mips_opts.mips16 = 1;
16109 else if (strcmp (name, "nomips16") == 0
16110 || strcmp (name, "noMIPS-16") == 0)
16111 mips_opts.mips16 = 0;
16112 else if (strcmp (name, "micromips") == 0)
16114 if (mips_opts.mips16 == 1)
16115 as_fatal (_("`micromips' cannot be used with `mips16'"));
16116 mips_opts.micromips = 1;
16118 else if (strcmp (name, "nomicromips") == 0)
16119 mips_opts.micromips = 0;
16120 else if (strcmp (name, "smartmips") == 0)
16122 if (!ISA_SUPPORTS_SMARTMIPS)
16123 as_warn (_("%s ISA does not support SmartMIPS ASE"),
16124 mips_cpu_info_from_isa (mips_opts.isa)->name);
16125 mips_opts.ase_smartmips = 1;
16127 else if (strcmp (name, "nosmartmips") == 0)
16128 mips_opts.ase_smartmips = 0;
16129 else if (strcmp (name, "mips3d") == 0)
16130 mips_opts.ase_mips3d = 1;
16131 else if (strcmp (name, "nomips3d") == 0)
16132 mips_opts.ase_mips3d = 0;
16133 else if (strcmp (name, "mdmx") == 0)
16134 mips_opts.ase_mdmx = 1;
16135 else if (strcmp (name, "nomdmx") == 0)
16136 mips_opts.ase_mdmx = 0;
16137 else if (strcmp (name, "dsp") == 0)
16139 if (!ISA_SUPPORTS_DSP_ASE)
16140 as_warn (_("%s ISA does not support DSP ASE"),
16141 mips_cpu_info_from_isa (mips_opts.isa)->name);
16142 mips_opts.ase_dsp = 1;
16143 mips_opts.ase_dspr2 = 0;
16145 else if (strcmp (name, "nodsp") == 0)
16147 mips_opts.ase_dsp = 0;
16148 mips_opts.ase_dspr2 = 0;
16150 else if (strcmp (name, "dspr2") == 0)
16152 if (!ISA_SUPPORTS_DSPR2_ASE)
16153 as_warn (_("%s ISA does not support DSP R2 ASE"),
16154 mips_cpu_info_from_isa (mips_opts.isa)->name);
16155 mips_opts.ase_dspr2 = 1;
16156 mips_opts.ase_dsp = 1;
16158 else if (strcmp (name, "nodspr2") == 0)
16160 mips_opts.ase_dspr2 = 0;
16161 mips_opts.ase_dsp = 0;
16163 else if (strcmp (name, "mt") == 0)
16165 if (!ISA_SUPPORTS_MT_ASE)
16166 as_warn (_("%s ISA does not support MT ASE"),
16167 mips_cpu_info_from_isa (mips_opts.isa)->name);
16168 mips_opts.ase_mt = 1;
16170 else if (strcmp (name, "nomt") == 0)
16171 mips_opts.ase_mt = 0;
16172 else if (strcmp (name, "mcu") == 0)
16173 mips_opts.ase_mcu = 1;
16174 else if (strcmp (name, "nomcu") == 0)
16175 mips_opts.ase_mcu = 0;
16176 else if (strncmp (name, "mips", 4) == 0 || strncmp (name, "arch=", 5) == 0)
16180 /* Permit the user to change the ISA and architecture on the fly.
16181 Needless to say, misuse can cause serious problems. */
16182 if (strcmp (name, "mips0") == 0 || strcmp (name, "arch=default") == 0)
16185 mips_opts.isa = file_mips_isa;
16186 mips_opts.arch = file_mips_arch;
16188 else if (strncmp (name, "arch=", 5) == 0)
16190 const struct mips_cpu_info *p;
16192 p = mips_parse_cpu("internal use", name + 5);
16194 as_bad (_("unknown architecture %s"), name + 5);
16197 mips_opts.arch = p->cpu;
16198 mips_opts.isa = p->isa;
16201 else if (strncmp (name, "mips", 4) == 0)
16203 const struct mips_cpu_info *p;
16205 p = mips_parse_cpu("internal use", name);
16207 as_bad (_("unknown ISA level %s"), name + 4);
16210 mips_opts.arch = p->cpu;
16211 mips_opts.isa = p->isa;
16215 as_bad (_("unknown ISA or architecture %s"), name);
16217 switch (mips_opts.isa)
16225 mips_opts.gp32 = 1;
16226 mips_opts.fp32 = 1;
16233 mips_opts.gp32 = 0;
16234 mips_opts.fp32 = 0;
16237 as_bad (_("unknown ISA level %s"), name + 4);
16242 mips_opts.gp32 = file_mips_gp32;
16243 mips_opts.fp32 = file_mips_fp32;
16246 else if (strcmp (name, "autoextend") == 0)
16247 mips_opts.noautoextend = 0;
16248 else if (strcmp (name, "noautoextend") == 0)
16249 mips_opts.noautoextend = 1;
16250 else if (strcmp (name, "push") == 0)
16252 struct mips_option_stack *s;
16254 s = (struct mips_option_stack *) xmalloc (sizeof *s);
16255 s->next = mips_opts_stack;
16256 s->options = mips_opts;
16257 mips_opts_stack = s;
16259 else if (strcmp (name, "pop") == 0)
16261 struct mips_option_stack *s;
16263 s = mips_opts_stack;
16265 as_bad (_(".set pop with no .set push"));
16268 /* If we're changing the reorder mode we need to handle
16269 delay slots correctly. */
16270 if (s->options.noreorder && ! mips_opts.noreorder)
16271 start_noreorder ();
16272 else if (! s->options.noreorder && mips_opts.noreorder)
16275 mips_opts = s->options;
16276 mips_opts_stack = s->next;
16280 else if (strcmp (name, "sym32") == 0)
16281 mips_opts.sym32 = TRUE;
16282 else if (strcmp (name, "nosym32") == 0)
16283 mips_opts.sym32 = FALSE;
16284 else if (strchr (name, ','))
16286 /* Generic ".set" directive; use the generic handler. */
16287 *input_line_pointer = ch;
16288 input_line_pointer = name;
16294 as_warn (_("Tried to set unrecognized symbol: %s\n"), name);
16296 *input_line_pointer = ch;
16297 demand_empty_rest_of_line ();
16300 /* Handle the .abicalls pseudo-op. I believe this is equivalent to
16301 .option pic2. It means to generate SVR4 PIC calls. */
16304 s_abicalls (int ignore ATTRIBUTE_UNUSED)
16306 mips_pic = SVR4_PIC;
16307 mips_abicalls = TRUE;
16309 if (g_switch_seen && g_switch_value != 0)
16310 as_warn (_("-G may not be used with SVR4 PIC code"));
16311 g_switch_value = 0;
16313 bfd_set_gp_size (stdoutput, 0);
16314 demand_empty_rest_of_line ();
16317 /* Handle the .cpload pseudo-op. This is used when generating SVR4
16318 PIC code. It sets the $gp register for the function based on the
16319 function address, which is in the register named in the argument.
16320 This uses a relocation against _gp_disp, which is handled specially
16321 by the linker. The result is:
16322 lui $gp,%hi(_gp_disp)
16323 addiu $gp,$gp,%lo(_gp_disp)
16324 addu $gp,$gp,.cpload argument
16325 The .cpload argument is normally $25 == $t9.
16327 The -mno-shared option changes this to:
16328 lui $gp,%hi(__gnu_local_gp)
16329 addiu $gp,$gp,%lo(__gnu_local_gp)
16330 and the argument is ignored. This saves an instruction, but the
16331 resulting code is not position independent; it uses an absolute
16332 address for __gnu_local_gp. Thus code assembled with -mno-shared
16333 can go into an ordinary executable, but not into a shared library. */
16336 s_cpload (int ignore ATTRIBUTE_UNUSED)
16342 /* If we are not generating SVR4 PIC code, or if this is NewABI code,
16343 .cpload is ignored. */
16344 if (mips_pic != SVR4_PIC || HAVE_NEWABI)
16350 /* .cpload should be in a .set noreorder section. */
16351 if (mips_opts.noreorder == 0)
16352 as_warn (_(".cpload not in noreorder section"));
16354 reg = tc_get_register (0);
16356 /* If we need to produce a 64-bit address, we are better off using
16357 the default instruction sequence. */
16358 in_shared = mips_in_shared || HAVE_64BIT_SYMBOLS;
16360 ex.X_op = O_symbol;
16361 ex.X_add_symbol = symbol_find_or_make (in_shared ? "_gp_disp" :
16363 ex.X_op_symbol = NULL;
16364 ex.X_add_number = 0;
16366 /* In ELF, this symbol is implicitly an STT_OBJECT symbol. */
16367 symbol_get_bfdsym (ex.X_add_symbol)->flags |= BSF_OBJECT;
16370 macro_build_lui (&ex, mips_gp_register);
16371 macro_build (&ex, "addiu", "t,r,j", mips_gp_register,
16372 mips_gp_register, BFD_RELOC_LO16);
16374 macro_build (NULL, "addu", "d,v,t", mips_gp_register,
16375 mips_gp_register, reg);
16378 demand_empty_rest_of_line ();
16381 /* Handle the .cpsetup pseudo-op defined for NewABI PIC code. The syntax is:
16382 .cpsetup $reg1, offset|$reg2, label
16384 If offset is given, this results in:
16385 sd $gp, offset($sp)
16386 lui $gp, %hi(%neg(%gp_rel(label)))
16387 addiu $gp, $gp, %lo(%neg(%gp_rel(label)))
16388 daddu $gp, $gp, $reg1
16390 If $reg2 is given, this results in:
16391 daddu $reg2, $gp, $0
16392 lui $gp, %hi(%neg(%gp_rel(label)))
16393 addiu $gp, $gp, %lo(%neg(%gp_rel(label)))
16394 daddu $gp, $gp, $reg1
16395 $reg1 is normally $25 == $t9.
16397 The -mno-shared option replaces the last three instructions with
16399 addiu $gp,$gp,%lo(_gp) */
16402 s_cpsetup (int ignore ATTRIBUTE_UNUSED)
16404 expressionS ex_off;
16405 expressionS ex_sym;
16408 /* If we are not generating SVR4 PIC code, .cpsetup is ignored.
16409 We also need NewABI support. */
16410 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
16416 reg1 = tc_get_register (0);
16417 SKIP_WHITESPACE ();
16418 if (*input_line_pointer != ',')
16420 as_bad (_("missing argument separator ',' for .cpsetup"));
16424 ++input_line_pointer;
16425 SKIP_WHITESPACE ();
16426 if (*input_line_pointer == '$')
16428 mips_cpreturn_register = tc_get_register (0);
16429 mips_cpreturn_offset = -1;
16433 mips_cpreturn_offset = get_absolute_expression ();
16434 mips_cpreturn_register = -1;
16436 SKIP_WHITESPACE ();
16437 if (*input_line_pointer != ',')
16439 as_bad (_("missing argument separator ',' for .cpsetup"));
16443 ++input_line_pointer;
16444 SKIP_WHITESPACE ();
16445 expression (&ex_sym);
16448 if (mips_cpreturn_register == -1)
16450 ex_off.X_op = O_constant;
16451 ex_off.X_add_symbol = NULL;
16452 ex_off.X_op_symbol = NULL;
16453 ex_off.X_add_number = mips_cpreturn_offset;
16455 macro_build (&ex_off, "sd", "t,o(b)", mips_gp_register,
16456 BFD_RELOC_LO16, SP);
16459 macro_build (NULL, "daddu", "d,v,t", mips_cpreturn_register,
16460 mips_gp_register, 0);
16462 if (mips_in_shared || HAVE_64BIT_SYMBOLS)
16464 macro_build (&ex_sym, "lui", LUI_FMT, mips_gp_register,
16465 -1, BFD_RELOC_GPREL16, BFD_RELOC_MIPS_SUB,
16468 macro_build (&ex_sym, "addiu", "t,r,j", mips_gp_register,
16469 mips_gp_register, -1, BFD_RELOC_GPREL16,
16470 BFD_RELOC_MIPS_SUB, BFD_RELOC_LO16);
16472 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", mips_gp_register,
16473 mips_gp_register, reg1);
16479 ex.X_op = O_symbol;
16480 ex.X_add_symbol = symbol_find_or_make ("__gnu_local_gp");
16481 ex.X_op_symbol = NULL;
16482 ex.X_add_number = 0;
16484 /* In ELF, this symbol is implicitly an STT_OBJECT symbol. */
16485 symbol_get_bfdsym (ex.X_add_symbol)->flags |= BSF_OBJECT;
16487 macro_build_lui (&ex, mips_gp_register);
16488 macro_build (&ex, "addiu", "t,r,j", mips_gp_register,
16489 mips_gp_register, BFD_RELOC_LO16);
16494 demand_empty_rest_of_line ();
16498 s_cplocal (int ignore ATTRIBUTE_UNUSED)
16500 /* If we are not generating SVR4 PIC code, or if this is not NewABI code,
16501 .cplocal is ignored. */
16502 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
16508 mips_gp_register = tc_get_register (0);
16509 demand_empty_rest_of_line ();
16512 /* Handle the .cprestore pseudo-op. This stores $gp into a given
16513 offset from $sp. The offset is remembered, and after making a PIC
16514 call $gp is restored from that location. */
16517 s_cprestore (int ignore ATTRIBUTE_UNUSED)
16521 /* If we are not generating SVR4 PIC code, or if this is NewABI code,
16522 .cprestore is ignored. */
16523 if (mips_pic != SVR4_PIC || HAVE_NEWABI)
16529 mips_cprestore_offset = get_absolute_expression ();
16530 mips_cprestore_valid = 1;
16532 ex.X_op = O_constant;
16533 ex.X_add_symbol = NULL;
16534 ex.X_op_symbol = NULL;
16535 ex.X_add_number = mips_cprestore_offset;
16538 macro_build_ldst_constoffset (&ex, ADDRESS_STORE_INSN, mips_gp_register,
16539 SP, HAVE_64BIT_ADDRESSES);
16542 demand_empty_rest_of_line ();
16545 /* Handle the .cpreturn pseudo-op defined for NewABI PIC code. If an offset
16546 was given in the preceding .cpsetup, it results in:
16547 ld $gp, offset($sp)
16549 If a register $reg2 was given there, it results in:
16550 daddu $gp, $reg2, $0 */
16553 s_cpreturn (int ignore ATTRIBUTE_UNUSED)
16557 /* If we are not generating SVR4 PIC code, .cpreturn is ignored.
16558 We also need NewABI support. */
16559 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
16566 if (mips_cpreturn_register == -1)
16568 ex.X_op = O_constant;
16569 ex.X_add_symbol = NULL;
16570 ex.X_op_symbol = NULL;
16571 ex.X_add_number = mips_cpreturn_offset;
16573 macro_build (&ex, "ld", "t,o(b)", mips_gp_register, BFD_RELOC_LO16, SP);
16576 macro_build (NULL, "daddu", "d,v,t", mips_gp_register,
16577 mips_cpreturn_register, 0);
16580 demand_empty_rest_of_line ();
16583 /* Handle the .dtprelword and .dtpreldword pseudo-ops. They generate
16584 a 32-bit or 64-bit DTP-relative relocation (BYTES says which) for
16585 use in DWARF debug information. */
16588 s_dtprel_internal (size_t bytes)
16595 if (ex.X_op != O_symbol)
16597 as_bad (_("Unsupported use of %s"), (bytes == 8
16600 ignore_rest_of_line ();
16603 p = frag_more (bytes);
16604 md_number_to_chars (p, 0, bytes);
16605 fix_new_exp (frag_now, p - frag_now->fr_literal, bytes, &ex, FALSE,
16607 ? BFD_RELOC_MIPS_TLS_DTPREL64
16608 : BFD_RELOC_MIPS_TLS_DTPREL32));
16610 demand_empty_rest_of_line ();
16613 /* Handle .dtprelword. */
16616 s_dtprelword (int ignore ATTRIBUTE_UNUSED)
16618 s_dtprel_internal (4);
16621 /* Handle .dtpreldword. */
16624 s_dtpreldword (int ignore ATTRIBUTE_UNUSED)
16626 s_dtprel_internal (8);
16629 /* Handle the .gpvalue pseudo-op. This is used when generating NewABI PIC
16630 code. It sets the offset to use in gp_rel relocations. */
16633 s_gpvalue (int ignore ATTRIBUTE_UNUSED)
16635 /* If we are not generating SVR4 PIC code, .gpvalue is ignored.
16636 We also need NewABI support. */
16637 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
16643 mips_gprel_offset = get_absolute_expression ();
16645 demand_empty_rest_of_line ();
16648 /* Handle the .gpword pseudo-op. This is used when generating PIC
16649 code. It generates a 32 bit GP relative reloc. */
16652 s_gpword (int ignore ATTRIBUTE_UNUSED)
16654 segment_info_type *si;
16655 struct insn_label_list *l;
16660 /* When not generating PIC code, this is treated as .word. */
16661 if (mips_pic != SVR4_PIC)
16667 si = seg_info (now_seg);
16668 l = si->label_list;
16669 label = l != NULL ? l->label : NULL;
16670 mips_emit_delays ();
16672 mips_align (2, 0, label);
16675 mips_clear_insn_labels ();
16677 if (ex.X_op != O_symbol || ex.X_add_number != 0)
16679 as_bad (_("Unsupported use of .gpword"));
16680 ignore_rest_of_line ();
16684 md_number_to_chars (p, 0, 4);
16685 fix_new_exp (frag_now, p - frag_now->fr_literal, 4, &ex, FALSE,
16686 BFD_RELOC_GPREL32);
16688 demand_empty_rest_of_line ();
16692 s_gpdword (int ignore ATTRIBUTE_UNUSED)
16694 segment_info_type *si;
16695 struct insn_label_list *l;
16700 /* When not generating PIC code, this is treated as .dword. */
16701 if (mips_pic != SVR4_PIC)
16707 si = seg_info (now_seg);
16708 l = si->label_list;
16709 label = l != NULL ? l->label : NULL;
16710 mips_emit_delays ();
16712 mips_align (3, 0, label);
16715 mips_clear_insn_labels ();
16717 if (ex.X_op != O_symbol || ex.X_add_number != 0)
16719 as_bad (_("Unsupported use of .gpdword"));
16720 ignore_rest_of_line ();
16724 md_number_to_chars (p, 0, 8);
16725 fix_new_exp (frag_now, p - frag_now->fr_literal, 4, &ex, FALSE,
16726 BFD_RELOC_GPREL32)->fx_tcbit = 1;
16728 /* GPREL32 composed with 64 gives a 64-bit GP offset. */
16729 fix_new (frag_now, p - frag_now->fr_literal, 8, NULL, 0,
16730 FALSE, BFD_RELOC_64)->fx_tcbit = 1;
16732 demand_empty_rest_of_line ();
16735 /* Handle the .cpadd pseudo-op. This is used when dealing with switch
16736 tables in SVR4 PIC code. */
16739 s_cpadd (int ignore ATTRIBUTE_UNUSED)
16743 /* This is ignored when not generating SVR4 PIC code. */
16744 if (mips_pic != SVR4_PIC)
16750 /* Add $gp to the register named as an argument. */
16752 reg = tc_get_register (0);
16753 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", reg, reg, mips_gp_register);
16756 demand_empty_rest_of_line ();
16759 /* Handle the .insn pseudo-op. This marks instruction labels in
16760 mips16/micromips mode. This permits the linker to handle them specially,
16761 such as generating jalx instructions when needed. We also make
16762 them odd for the duration of the assembly, in order to generate the
16763 right sort of code. We will make them even in the adjust_symtab
16764 routine, while leaving them marked. This is convenient for the
16765 debugger and the disassembler. The linker knows to make them odd
16769 s_insn (int ignore ATTRIBUTE_UNUSED)
16771 mips_mark_labels ();
16773 demand_empty_rest_of_line ();
16776 /* Handle a .stabn directive. We need these in order to mark a label
16777 as being a mips16 text label correctly. Sometimes the compiler
16778 will emit a label, followed by a .stabn, and then switch sections.
16779 If the label and .stabn are in mips16 mode, then the label is
16780 really a mips16 text label. */
16783 s_mips_stab (int type)
16786 mips_mark_labels ();
16791 /* Handle the .weakext pseudo-op as defined in Kane and Heinrich. */
16794 s_mips_weakext (int ignore ATTRIBUTE_UNUSED)
16801 name = input_line_pointer;
16802 c = get_symbol_end ();
16803 symbolP = symbol_find_or_make (name);
16804 S_SET_WEAK (symbolP);
16805 *input_line_pointer = c;
16807 SKIP_WHITESPACE ();
16809 if (! is_end_of_line[(unsigned char) *input_line_pointer])
16811 if (S_IS_DEFINED (symbolP))
16813 as_bad (_("ignoring attempt to redefine symbol %s"),
16814 S_GET_NAME (symbolP));
16815 ignore_rest_of_line ();
16819 if (*input_line_pointer == ',')
16821 ++input_line_pointer;
16822 SKIP_WHITESPACE ();
16826 if (exp.X_op != O_symbol)
16828 as_bad (_("bad .weakext directive"));
16829 ignore_rest_of_line ();
16832 symbol_set_value_expression (symbolP, &exp);
16835 demand_empty_rest_of_line ();
16838 /* Parse a register string into a number. Called from the ECOFF code
16839 to parse .frame. The argument is non-zero if this is the frame
16840 register, so that we can record it in mips_frame_reg. */
16843 tc_get_register (int frame)
16847 SKIP_WHITESPACE ();
16848 if (! reg_lookup (&input_line_pointer, RWARN | RTYPE_NUM | RTYPE_GP, ®))
16852 mips_frame_reg = reg != 0 ? reg : SP;
16853 mips_frame_reg_valid = 1;
16854 mips_cprestore_valid = 0;
16860 md_section_align (asection *seg, valueT addr)
16862 int align = bfd_get_section_alignment (stdoutput, seg);
16866 /* We don't need to align ELF sections to the full alignment.
16867 However, Irix 5 may prefer that we align them at least to a 16
16868 byte boundary. We don't bother to align the sections if we
16869 are targeted for an embedded system. */
16870 if (strncmp (TARGET_OS, "elf", 3) == 0)
16876 return ((addr + (1 << align) - 1) & (-1 << align));
16879 /* Utility routine, called from above as well. If called while the
16880 input file is still being read, it's only an approximation. (For
16881 example, a symbol may later become defined which appeared to be
16882 undefined earlier.) */
16885 nopic_need_relax (symbolS *sym, int before_relaxing)
16890 if (g_switch_value > 0)
16892 const char *symname;
16895 /* Find out whether this symbol can be referenced off the $gp
16896 register. It can be if it is smaller than the -G size or if
16897 it is in the .sdata or .sbss section. Certain symbols can
16898 not be referenced off the $gp, although it appears as though
16900 symname = S_GET_NAME (sym);
16901 if (symname != (const char *) NULL
16902 && (strcmp (symname, "eprol") == 0
16903 || strcmp (symname, "etext") == 0
16904 || strcmp (symname, "_gp") == 0
16905 || strcmp (symname, "edata") == 0
16906 || strcmp (symname, "_fbss") == 0
16907 || strcmp (symname, "_fdata") == 0
16908 || strcmp (symname, "_ftext") == 0
16909 || strcmp (symname, "end") == 0
16910 || strcmp (symname, "_gp_disp") == 0))
16912 else if ((! S_IS_DEFINED (sym) || S_IS_COMMON (sym))
16914 #ifndef NO_ECOFF_DEBUGGING
16915 || (symbol_get_obj (sym)->ecoff_extern_size != 0
16916 && (symbol_get_obj (sym)->ecoff_extern_size
16917 <= g_switch_value))
16919 /* We must defer this decision until after the whole
16920 file has been read, since there might be a .extern
16921 after the first use of this symbol. */
16922 || (before_relaxing
16923 #ifndef NO_ECOFF_DEBUGGING
16924 && symbol_get_obj (sym)->ecoff_extern_size == 0
16926 && S_GET_VALUE (sym) == 0)
16927 || (S_GET_VALUE (sym) != 0
16928 && S_GET_VALUE (sym) <= g_switch_value)))
16932 const char *segname;
16934 segname = segment_name (S_GET_SEGMENT (sym));
16935 gas_assert (strcmp (segname, ".lit8") != 0
16936 && strcmp (segname, ".lit4") != 0);
16937 change = (strcmp (segname, ".sdata") != 0
16938 && strcmp (segname, ".sbss") != 0
16939 && strncmp (segname, ".sdata.", 7) != 0
16940 && strncmp (segname, ".sbss.", 6) != 0
16941 && strncmp (segname, ".gnu.linkonce.sb.", 17) != 0
16942 && strncmp (segname, ".gnu.linkonce.s.", 16) != 0);
16947 /* We are not optimizing for the $gp register. */
16952 /* Return true if the given symbol should be considered local for SVR4 PIC. */
16955 pic_need_relax (symbolS *sym, asection *segtype)
16959 /* Handle the case of a symbol equated to another symbol. */
16960 while (symbol_equated_reloc_p (sym))
16964 /* It's possible to get a loop here in a badly written program. */
16965 n = symbol_get_value_expression (sym)->X_add_symbol;
16971 if (symbol_section_p (sym))
16974 symsec = S_GET_SEGMENT (sym);
16976 /* This must duplicate the test in adjust_reloc_syms. */
16977 return (symsec != &bfd_und_section
16978 && symsec != &bfd_abs_section
16979 && !bfd_is_com_section (symsec)
16980 && !s_is_linkonce (sym, segtype)
16982 /* A global or weak symbol is treated as external. */
16983 && (!IS_ELF || (! S_IS_WEAK (sym) && ! S_IS_EXTERNAL (sym)))
16989 /* Given a mips16 variant frag FRAGP, return non-zero if it needs an
16990 extended opcode. SEC is the section the frag is in. */
16993 mips16_extended_frag (fragS *fragp, asection *sec, long stretch)
16996 const struct mips16_immed_operand *op;
16998 int mintiny, maxtiny;
17002 if (RELAX_MIPS16_USER_SMALL (fragp->fr_subtype))
17004 if (RELAX_MIPS16_USER_EXT (fragp->fr_subtype))
17007 type = RELAX_MIPS16_TYPE (fragp->fr_subtype);
17008 op = mips16_immed_operands;
17009 while (op->type != type)
17012 gas_assert (op < mips16_immed_operands + MIPS16_NUM_IMMED);
17017 if (type == '<' || type == '>' || type == '[' || type == ']')
17020 maxtiny = 1 << op->nbits;
17025 maxtiny = (1 << op->nbits) - 1;
17030 mintiny = - (1 << (op->nbits - 1));
17031 maxtiny = (1 << (op->nbits - 1)) - 1;
17034 sym_frag = symbol_get_frag (fragp->fr_symbol);
17035 val = S_GET_VALUE (fragp->fr_symbol);
17036 symsec = S_GET_SEGMENT (fragp->fr_symbol);
17042 /* We won't have the section when we are called from
17043 mips_relax_frag. However, we will always have been called
17044 from md_estimate_size_before_relax first. If this is a
17045 branch to a different section, we mark it as such. If SEC is
17046 NULL, and the frag is not marked, then it must be a branch to
17047 the same section. */
17050 if (RELAX_MIPS16_LONG_BRANCH (fragp->fr_subtype))
17055 /* Must have been called from md_estimate_size_before_relax. */
17058 fragp->fr_subtype =
17059 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
17061 /* FIXME: We should support this, and let the linker
17062 catch branches and loads that are out of range. */
17063 as_bad_where (fragp->fr_file, fragp->fr_line,
17064 _("unsupported PC relative reference to different section"));
17068 if (fragp != sym_frag && sym_frag->fr_address == 0)
17069 /* Assume non-extended on the first relaxation pass.
17070 The address we have calculated will be bogus if this is
17071 a forward branch to another frag, as the forward frag
17072 will have fr_address == 0. */
17076 /* In this case, we know for sure that the symbol fragment is in
17077 the same section. If the relax_marker of the symbol fragment
17078 differs from the relax_marker of this fragment, we have not
17079 yet adjusted the symbol fragment fr_address. We want to add
17080 in STRETCH in order to get a better estimate of the address.
17081 This particularly matters because of the shift bits. */
17083 && sym_frag->relax_marker != fragp->relax_marker)
17087 /* Adjust stretch for any alignment frag. Note that if have
17088 been expanding the earlier code, the symbol may be
17089 defined in what appears to be an earlier frag. FIXME:
17090 This doesn't handle the fr_subtype field, which specifies
17091 a maximum number of bytes to skip when doing an
17093 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
17095 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
17098 stretch = - ((- stretch)
17099 & ~ ((1 << (int) f->fr_offset) - 1));
17101 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
17110 addr = fragp->fr_address + fragp->fr_fix;
17112 /* The base address rules are complicated. The base address of
17113 a branch is the following instruction. The base address of a
17114 PC relative load or add is the instruction itself, but if it
17115 is in a delay slot (in which case it can not be extended) use
17116 the address of the instruction whose delay slot it is in. */
17117 if (type == 'p' || type == 'q')
17121 /* If we are currently assuming that this frag should be
17122 extended, then, the current address is two bytes
17124 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
17127 /* Ignore the low bit in the target, since it will be set
17128 for a text label. */
17129 if ((val & 1) != 0)
17132 else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype))
17134 else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype))
17137 val -= addr & ~ ((1 << op->shift) - 1);
17139 /* Branch offsets have an implicit 0 in the lowest bit. */
17140 if (type == 'p' || type == 'q')
17143 /* If any of the shifted bits are set, we must use an extended
17144 opcode. If the address depends on the size of this
17145 instruction, this can lead to a loop, so we arrange to always
17146 use an extended opcode. We only check this when we are in
17147 the main relaxation loop, when SEC is NULL. */
17148 if ((val & ((1 << op->shift) - 1)) != 0 && sec == NULL)
17150 fragp->fr_subtype =
17151 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
17155 /* If we are about to mark a frag as extended because the value
17156 is precisely maxtiny + 1, then there is a chance of an
17157 infinite loop as in the following code:
17162 In this case when the la is extended, foo is 0x3fc bytes
17163 away, so the la can be shrunk, but then foo is 0x400 away, so
17164 the la must be extended. To avoid this loop, we mark the
17165 frag as extended if it was small, and is about to become
17166 extended with a value of maxtiny + 1. */
17167 if (val == ((maxtiny + 1) << op->shift)
17168 && ! RELAX_MIPS16_EXTENDED (fragp->fr_subtype)
17171 fragp->fr_subtype =
17172 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
17176 else if (symsec != absolute_section && sec != NULL)
17177 as_bad_where (fragp->fr_file, fragp->fr_line, _("unsupported relocation"));
17179 if ((val & ((1 << op->shift) - 1)) != 0
17180 || val < (mintiny << op->shift)
17181 || val > (maxtiny << op->shift))
17187 /* Compute the length of a branch sequence, and adjust the
17188 RELAX_BRANCH_TOOFAR bit accordingly. If FRAGP is NULL, the
17189 worst-case length is computed, with UPDATE being used to indicate
17190 whether an unconditional (-1), branch-likely (+1) or regular (0)
17191 branch is to be computed. */
17193 relaxed_branch_length (fragS *fragp, asection *sec, int update)
17195 bfd_boolean toofar;
17199 && S_IS_DEFINED (fragp->fr_symbol)
17200 && sec == S_GET_SEGMENT (fragp->fr_symbol))
17205 val = S_GET_VALUE (fragp->fr_symbol) + fragp->fr_offset;
17207 addr = fragp->fr_address + fragp->fr_fix + 4;
17211 toofar = val < - (0x8000 << 2) || val >= (0x8000 << 2);
17214 /* If the symbol is not defined or it's in a different segment,
17215 assume the user knows what's going on and emit a short
17221 if (fragp && update && toofar != RELAX_BRANCH_TOOFAR (fragp->fr_subtype))
17223 = RELAX_BRANCH_ENCODE (RELAX_BRANCH_AT (fragp->fr_subtype),
17224 RELAX_BRANCH_UNCOND (fragp->fr_subtype),
17225 RELAX_BRANCH_LIKELY (fragp->fr_subtype),
17226 RELAX_BRANCH_LINK (fragp->fr_subtype),
17232 if (fragp ? RELAX_BRANCH_LIKELY (fragp->fr_subtype) : (update > 0))
17235 if (mips_pic != NO_PIC)
17237 /* Additional space for PIC loading of target address. */
17239 if (mips_opts.isa == ISA_MIPS1)
17240 /* Additional space for $at-stabilizing nop. */
17244 /* If branch is conditional. */
17245 if (fragp ? !RELAX_BRANCH_UNCOND (fragp->fr_subtype) : (update >= 0))
17252 /* Compute the length of a branch sequence, and adjust the
17253 RELAX_MICROMIPS_TOOFAR32 bit accordingly. If FRAGP is NULL, the
17254 worst-case length is computed, with UPDATE being used to indicate
17255 whether an unconditional (-1), or regular (0) branch is to be
17259 relaxed_micromips_32bit_branch_length (fragS *fragp, asection *sec, int update)
17261 bfd_boolean toofar;
17265 && S_IS_DEFINED (fragp->fr_symbol)
17266 && sec == S_GET_SEGMENT (fragp->fr_symbol))
17271 val = S_GET_VALUE (fragp->fr_symbol) + fragp->fr_offset;
17272 /* Ignore the low bit in the target, since it will be set
17273 for a text label. */
17274 if ((val & 1) != 0)
17277 addr = fragp->fr_address + fragp->fr_fix + 4;
17281 toofar = val < - (0x8000 << 1) || val >= (0x8000 << 1);
17284 /* If the symbol is not defined or it's in a different segment,
17285 assume the user knows what's going on and emit a short
17291 if (fragp && update
17292 && toofar != RELAX_MICROMIPS_TOOFAR32 (fragp->fr_subtype))
17293 fragp->fr_subtype = (toofar
17294 ? RELAX_MICROMIPS_MARK_TOOFAR32 (fragp->fr_subtype)
17295 : RELAX_MICROMIPS_CLEAR_TOOFAR32 (fragp->fr_subtype));
17300 bfd_boolean compact_known = fragp != NULL;
17301 bfd_boolean compact = FALSE;
17302 bfd_boolean uncond;
17305 compact = RELAX_MICROMIPS_COMPACT (fragp->fr_subtype);
17307 uncond = RELAX_MICROMIPS_UNCOND (fragp->fr_subtype);
17309 uncond = update < 0;
17311 /* If label is out of range, we turn branch <br>:
17313 <br> label # 4 bytes
17319 nop # 2 bytes if compact && !PIC
17322 if (mips_pic == NO_PIC && (!compact_known || compact))
17325 /* If assembling PIC code, we further turn:
17331 lw/ld at, %got(label)(gp) # 4 bytes
17332 d/addiu at, %lo(label) # 4 bytes
17335 if (mips_pic != NO_PIC)
17338 /* If branch <br> is conditional, we prepend negated branch <brneg>:
17340 <brneg> 0f # 4 bytes
17341 nop # 2 bytes if !compact
17344 length += (compact_known && compact) ? 4 : 6;
17350 /* Compute the length of a branch, and adjust the RELAX_MICROMIPS_TOOFAR16
17351 bit accordingly. */
17354 relaxed_micromips_16bit_branch_length (fragS *fragp, asection *sec, int update)
17356 bfd_boolean toofar;
17359 && S_IS_DEFINED (fragp->fr_symbol)
17360 && sec == S_GET_SEGMENT (fragp->fr_symbol))
17366 val = S_GET_VALUE (fragp->fr_symbol) + fragp->fr_offset;
17367 /* Ignore the low bit in the target, since it will be set
17368 for a text label. */
17369 if ((val & 1) != 0)
17372 /* Assume this is a 2-byte branch. */
17373 addr = fragp->fr_address + fragp->fr_fix + 2;
17375 /* We try to avoid the infinite loop by not adding 2 more bytes for
17380 type = RELAX_MICROMIPS_TYPE (fragp->fr_subtype);
17382 toofar = val < - (0x200 << 1) || val >= (0x200 << 1);
17383 else if (type == 'E')
17384 toofar = val < - (0x40 << 1) || val >= (0x40 << 1);
17389 /* If the symbol is not defined or it's in a different segment,
17390 we emit a normal 32-bit branch. */
17393 if (fragp && update
17394 && toofar != RELAX_MICROMIPS_TOOFAR16 (fragp->fr_subtype))
17396 = toofar ? RELAX_MICROMIPS_MARK_TOOFAR16 (fragp->fr_subtype)
17397 : RELAX_MICROMIPS_CLEAR_TOOFAR16 (fragp->fr_subtype);
17405 /* Estimate the size of a frag before relaxing. Unless this is the
17406 mips16, we are not really relaxing here, and the final size is
17407 encoded in the subtype information. For the mips16, we have to
17408 decide whether we are using an extended opcode or not. */
17411 md_estimate_size_before_relax (fragS *fragp, asection *segtype)
17415 if (RELAX_BRANCH_P (fragp->fr_subtype))
17418 fragp->fr_var = relaxed_branch_length (fragp, segtype, FALSE);
17420 return fragp->fr_var;
17423 if (RELAX_MIPS16_P (fragp->fr_subtype))
17424 /* We don't want to modify the EXTENDED bit here; it might get us
17425 into infinite loops. We change it only in mips_relax_frag(). */
17426 return (RELAX_MIPS16_EXTENDED (fragp->fr_subtype) ? 4 : 2);
17428 if (RELAX_MICROMIPS_P (fragp->fr_subtype))
17432 if (RELAX_MICROMIPS_TYPE (fragp->fr_subtype) != 0)
17433 length = relaxed_micromips_16bit_branch_length (fragp, segtype, FALSE);
17434 if (length == 4 && RELAX_MICROMIPS_RELAX32 (fragp->fr_subtype))
17435 length = relaxed_micromips_32bit_branch_length (fragp, segtype, FALSE);
17436 fragp->fr_var = length;
17441 if (mips_pic == NO_PIC)
17442 change = nopic_need_relax (fragp->fr_symbol, 0);
17443 else if (mips_pic == SVR4_PIC)
17444 change = pic_need_relax (fragp->fr_symbol, segtype);
17445 else if (mips_pic == VXWORKS_PIC)
17446 /* For vxworks, GOT16 relocations never have a corresponding LO16. */
17453 fragp->fr_subtype |= RELAX_USE_SECOND;
17454 return -RELAX_FIRST (fragp->fr_subtype);
17457 return -RELAX_SECOND (fragp->fr_subtype);
17460 /* This is called to see whether a reloc against a defined symbol
17461 should be converted into a reloc against a section. */
17464 mips_fix_adjustable (fixS *fixp)
17466 if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT
17467 || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
17470 if (fixp->fx_addsy == NULL)
17473 /* If symbol SYM is in a mergeable section, relocations of the form
17474 SYM + 0 can usually be made section-relative. The mergeable data
17475 is then identified by the section offset rather than by the symbol.
17477 However, if we're generating REL LO16 relocations, the offset is split
17478 between the LO16 and parterning high part relocation. The linker will
17479 need to recalculate the complete offset in order to correctly identify
17482 The linker has traditionally not looked for the parterning high part
17483 relocation, and has thus allowed orphaned R_MIPS_LO16 relocations to be
17484 placed anywhere. Rather than break backwards compatibility by changing
17485 this, it seems better not to force the issue, and instead keep the
17486 original symbol. This will work with either linker behavior. */
17487 if ((lo16_reloc_p (fixp->fx_r_type)
17488 || reloc_needs_lo_p (fixp->fx_r_type))
17489 && HAVE_IN_PLACE_ADDENDS
17490 && (S_GET_SEGMENT (fixp->fx_addsy)->flags & SEC_MERGE) != 0)
17493 /* There is no place to store an in-place offset for JALR relocations.
17494 Likewise an in-range offset of PC-relative relocations may overflow
17495 the in-place relocatable field if recalculated against the start
17496 address of the symbol's containing section. */
17497 if (HAVE_IN_PLACE_ADDENDS
17498 && (fixp->fx_pcrel || jalr_reloc_p (fixp->fx_r_type)))
17502 /* R_MIPS16_26 relocations against non-MIPS16 functions might resolve
17503 to a floating-point stub. The same is true for non-R_MIPS16_26
17504 relocations against MIPS16 functions; in this case, the stub becomes
17505 the function's canonical address.
17507 Floating-point stubs are stored in unique .mips16.call.* or
17508 .mips16.fn.* sections. If a stub T for function F is in section S,
17509 the first relocation in section S must be against F; this is how the
17510 linker determines the target function. All relocations that might
17511 resolve to T must also be against F. We therefore have the following
17512 restrictions, which are given in an intentionally-redundant way:
17514 1. We cannot reduce R_MIPS16_26 relocations against non-MIPS16
17517 2. We cannot reduce a stub's relocations against non-MIPS16 symbols
17518 if that stub might be used.
17520 3. We cannot reduce non-R_MIPS16_26 relocations against MIPS16
17523 4. We cannot reduce a stub's relocations against MIPS16 symbols if
17524 that stub might be used.
17526 There is a further restriction:
17528 5. We cannot reduce jump relocations (R_MIPS_26, R_MIPS16_26 or
17529 R_MICROMIPS_26_S1) against MIPS16 or microMIPS symbols on
17530 targets with in-place addends; the relocation field cannot
17531 encode the low bit.
17533 For simplicity, we deal with (3)-(4) by not reducing _any_ relocation
17534 against a MIPS16 symbol. We deal with (5) by by not reducing any
17535 such relocations on REL targets.
17537 We deal with (1)-(2) by saying that, if there's a R_MIPS16_26
17538 relocation against some symbol R, no relocation against R may be
17539 reduced. (Note that this deals with (2) as well as (1) because
17540 relocations against global symbols will never be reduced on ELF
17541 targets.) This approach is a little simpler than trying to detect
17542 stub sections, and gives the "all or nothing" per-symbol consistency
17543 that we have for MIPS16 symbols. */
17545 && fixp->fx_subsy == NULL
17546 && (ELF_ST_IS_MIPS16 (S_GET_OTHER (fixp->fx_addsy))
17547 || *symbol_get_tc (fixp->fx_addsy)
17548 || (HAVE_IN_PLACE_ADDENDS
17549 && ELF_ST_IS_MICROMIPS (S_GET_OTHER (fixp->fx_addsy))
17550 && jmp_reloc_p (fixp->fx_r_type))))
17557 /* Translate internal representation of relocation info to BFD target
17561 tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixp)
17563 static arelent *retval[4];
17565 bfd_reloc_code_real_type code;
17567 memset (retval, 0, sizeof(retval));
17568 reloc = retval[0] = (arelent *) xcalloc (1, sizeof (arelent));
17569 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
17570 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
17571 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
17573 if (fixp->fx_pcrel)
17575 gas_assert (fixp->fx_r_type == BFD_RELOC_16_PCREL_S2
17576 || fixp->fx_r_type == BFD_RELOC_MICROMIPS_7_PCREL_S1
17577 || fixp->fx_r_type == BFD_RELOC_MICROMIPS_10_PCREL_S1
17578 || fixp->fx_r_type == BFD_RELOC_MICROMIPS_16_PCREL_S1);
17580 /* At this point, fx_addnumber is "symbol offset - pcrel address".
17581 Relocations want only the symbol offset. */
17582 reloc->addend = fixp->fx_addnumber + reloc->address;
17585 /* A gruesome hack which is a result of the gruesome gas
17586 reloc handling. What's worse, for COFF (as opposed to
17587 ECOFF), we might need yet another copy of reloc->address.
17588 See bfd_install_relocation. */
17589 reloc->addend += reloc->address;
17593 reloc->addend = fixp->fx_addnumber;
17595 /* Since the old MIPS ELF ABI uses Rel instead of Rela, encode the vtable
17596 entry to be used in the relocation's section offset. */
17597 if (! HAVE_NEWABI && fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
17599 reloc->address = reloc->addend;
17603 code = fixp->fx_r_type;
17605 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
17606 if (reloc->howto == NULL)
17608 as_bad_where (fixp->fx_file, fixp->fx_line,
17609 _("Can not represent %s relocation in this object file format"),
17610 bfd_get_reloc_code_name (code));
17617 /* Relax a machine dependent frag. This returns the amount by which
17618 the current size of the frag should change. */
17621 mips_relax_frag (asection *sec, fragS *fragp, long stretch)
17623 if (RELAX_BRANCH_P (fragp->fr_subtype))
17625 offsetT old_var = fragp->fr_var;
17627 fragp->fr_var = relaxed_branch_length (fragp, sec, TRUE);
17629 return fragp->fr_var - old_var;
17632 if (RELAX_MICROMIPS_P (fragp->fr_subtype))
17634 offsetT old_var = fragp->fr_var;
17635 offsetT new_var = 4;
17637 if (RELAX_MICROMIPS_TYPE (fragp->fr_subtype) != 0)
17638 new_var = relaxed_micromips_16bit_branch_length (fragp, sec, TRUE);
17639 if (new_var == 4 && RELAX_MICROMIPS_RELAX32 (fragp->fr_subtype))
17640 new_var = relaxed_micromips_32bit_branch_length (fragp, sec, TRUE);
17641 fragp->fr_var = new_var;
17643 return new_var - old_var;
17646 if (! RELAX_MIPS16_P (fragp->fr_subtype))
17649 if (mips16_extended_frag (fragp, NULL, stretch))
17651 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
17653 fragp->fr_subtype = RELAX_MIPS16_MARK_EXTENDED (fragp->fr_subtype);
17658 if (! RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
17660 fragp->fr_subtype = RELAX_MIPS16_CLEAR_EXTENDED (fragp->fr_subtype);
17667 /* Convert a machine dependent frag. */
17670 md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, segT asec, fragS *fragp)
17672 if (RELAX_BRANCH_P (fragp->fr_subtype))
17675 unsigned long insn;
17679 buf = (bfd_byte *)fragp->fr_literal + fragp->fr_fix;
17681 if (target_big_endian)
17682 insn = bfd_getb32 (buf);
17684 insn = bfd_getl32 (buf);
17686 if (!RELAX_BRANCH_TOOFAR (fragp->fr_subtype))
17688 /* We generate a fixup instead of applying it right now
17689 because, if there are linker relaxations, we're going to
17690 need the relocations. */
17691 exp.X_op = O_symbol;
17692 exp.X_add_symbol = fragp->fr_symbol;
17693 exp.X_add_number = fragp->fr_offset;
17695 fixp = fix_new_exp (fragp, buf - (bfd_byte *)fragp->fr_literal,
17696 4, &exp, TRUE, BFD_RELOC_16_PCREL_S2);
17697 fixp->fx_file = fragp->fr_file;
17698 fixp->fx_line = fragp->fr_line;
17700 md_number_to_chars ((char *) buf, insn, 4);
17707 as_warn_where (fragp->fr_file, fragp->fr_line,
17708 _("Relaxed out-of-range branch into a jump"));
17710 if (RELAX_BRANCH_UNCOND (fragp->fr_subtype))
17713 if (!RELAX_BRANCH_LIKELY (fragp->fr_subtype))
17715 /* Reverse the branch. */
17716 switch ((insn >> 28) & 0xf)
17719 /* bc[0-3][tf]l? and bc1any[24][ft] instructions can
17720 have the condition reversed by tweaking a single
17721 bit, and their opcodes all have 0x4???????. */
17722 gas_assert ((insn & 0xf1000000) == 0x41000000);
17723 insn ^= 0x00010000;
17727 /* bltz 0x04000000 bgez 0x04010000
17728 bltzal 0x04100000 bgezal 0x04110000 */
17729 gas_assert ((insn & 0xfc0e0000) == 0x04000000);
17730 insn ^= 0x00010000;
17734 /* beq 0x10000000 bne 0x14000000
17735 blez 0x18000000 bgtz 0x1c000000 */
17736 insn ^= 0x04000000;
17744 if (RELAX_BRANCH_LINK (fragp->fr_subtype))
17746 /* Clear the and-link bit. */
17747 gas_assert ((insn & 0xfc1c0000) == 0x04100000);
17749 /* bltzal 0x04100000 bgezal 0x04110000
17750 bltzall 0x04120000 bgezall 0x04130000 */
17751 insn &= ~0x00100000;
17754 /* Branch over the branch (if the branch was likely) or the
17755 full jump (not likely case). Compute the offset from the
17756 current instruction to branch to. */
17757 if (RELAX_BRANCH_LIKELY (fragp->fr_subtype))
17761 /* How many bytes in instructions we've already emitted? */
17762 i = buf - (bfd_byte *)fragp->fr_literal - fragp->fr_fix;
17763 /* How many bytes in instructions from here to the end? */
17764 i = fragp->fr_var - i;
17766 /* Convert to instruction count. */
17768 /* Branch counts from the next instruction. */
17771 /* Branch over the jump. */
17772 md_number_to_chars ((char *) buf, insn, 4);
17776 md_number_to_chars ((char *) buf, 0, 4);
17779 if (RELAX_BRANCH_LIKELY (fragp->fr_subtype))
17781 /* beql $0, $0, 2f */
17783 /* Compute the PC offset from the current instruction to
17784 the end of the variable frag. */
17785 /* How many bytes in instructions we've already emitted? */
17786 i = buf - (bfd_byte *)fragp->fr_literal - fragp->fr_fix;
17787 /* How many bytes in instructions from here to the end? */
17788 i = fragp->fr_var - i;
17789 /* Convert to instruction count. */
17791 /* Don't decrement i, because we want to branch over the
17795 md_number_to_chars ((char *) buf, insn, 4);
17798 md_number_to_chars ((char *) buf, 0, 4);
17803 if (mips_pic == NO_PIC)
17806 insn = (RELAX_BRANCH_LINK (fragp->fr_subtype)
17807 ? 0x0c000000 : 0x08000000);
17808 exp.X_op = O_symbol;
17809 exp.X_add_symbol = fragp->fr_symbol;
17810 exp.X_add_number = fragp->fr_offset;
17812 fixp = fix_new_exp (fragp, buf - (bfd_byte *)fragp->fr_literal,
17813 4, &exp, FALSE, BFD_RELOC_MIPS_JMP);
17814 fixp->fx_file = fragp->fr_file;
17815 fixp->fx_line = fragp->fr_line;
17817 md_number_to_chars ((char *) buf, insn, 4);
17822 unsigned long at = RELAX_BRANCH_AT (fragp->fr_subtype);
17824 /* lw/ld $at, <sym>($gp) R_MIPS_GOT16 */
17825 insn = HAVE_64BIT_ADDRESSES ? 0xdf800000 : 0x8f800000;
17826 insn |= at << OP_SH_RT;
17827 exp.X_op = O_symbol;
17828 exp.X_add_symbol = fragp->fr_symbol;
17829 exp.X_add_number = fragp->fr_offset;
17831 if (fragp->fr_offset)
17833 exp.X_add_symbol = make_expr_symbol (&exp);
17834 exp.X_add_number = 0;
17837 fixp = fix_new_exp (fragp, buf - (bfd_byte *)fragp->fr_literal,
17838 4, &exp, FALSE, BFD_RELOC_MIPS_GOT16);
17839 fixp->fx_file = fragp->fr_file;
17840 fixp->fx_line = fragp->fr_line;
17842 md_number_to_chars ((char *) buf, insn, 4);
17845 if (mips_opts.isa == ISA_MIPS1)
17848 md_number_to_chars ((char *) buf, 0, 4);
17852 /* d/addiu $at, $at, <sym> R_MIPS_LO16 */
17853 insn = HAVE_64BIT_ADDRESSES ? 0x64000000 : 0x24000000;
17854 insn |= at << OP_SH_RS | at << OP_SH_RT;
17856 fixp = fix_new_exp (fragp, buf - (bfd_byte *)fragp->fr_literal,
17857 4, &exp, FALSE, BFD_RELOC_LO16);
17858 fixp->fx_file = fragp->fr_file;
17859 fixp->fx_line = fragp->fr_line;
17861 md_number_to_chars ((char *) buf, insn, 4);
17865 if (RELAX_BRANCH_LINK (fragp->fr_subtype))
17869 insn |= at << OP_SH_RS;
17871 md_number_to_chars ((char *) buf, insn, 4);
17876 gas_assert (buf == (bfd_byte *)fragp->fr_literal
17877 + fragp->fr_fix + fragp->fr_var);
17879 fragp->fr_fix += fragp->fr_var;
17884 /* Relax microMIPS branches. */
17885 if (RELAX_MICROMIPS_P (fragp->fr_subtype))
17887 bfd_byte *buf = (bfd_byte *) (fragp->fr_literal + fragp->fr_fix);
17888 bfd_boolean compact = RELAX_MICROMIPS_COMPACT (fragp->fr_subtype);
17889 bfd_boolean al = RELAX_MICROMIPS_LINK (fragp->fr_subtype);
17890 int type = RELAX_MICROMIPS_TYPE (fragp->fr_subtype);
17891 bfd_boolean short_ds;
17892 unsigned long insn;
17896 exp.X_op = O_symbol;
17897 exp.X_add_symbol = fragp->fr_symbol;
17898 exp.X_add_number = fragp->fr_offset;
17900 fragp->fr_fix += fragp->fr_var;
17902 /* Handle 16-bit branches that fit or are forced to fit. */
17903 if (type != 0 && !RELAX_MICROMIPS_TOOFAR16 (fragp->fr_subtype))
17905 /* We generate a fixup instead of applying it right now,
17906 because if there is linker relaxation, we're going to
17907 need the relocations. */
17909 fixp = fix_new_exp (fragp,
17910 buf - (bfd_byte *) fragp->fr_literal,
17912 BFD_RELOC_MICROMIPS_10_PCREL_S1);
17913 else if (type == 'E')
17914 fixp = fix_new_exp (fragp,
17915 buf - (bfd_byte *) fragp->fr_literal,
17917 BFD_RELOC_MICROMIPS_7_PCREL_S1);
17921 fixp->fx_file = fragp->fr_file;
17922 fixp->fx_line = fragp->fr_line;
17924 /* These relocations can have an addend that won't fit in
17926 fixp->fx_no_overflow = 1;
17931 /* Handle 32-bit branches that fit or are forced to fit. */
17932 if (!RELAX_MICROMIPS_RELAX32 (fragp->fr_subtype)
17933 || !RELAX_MICROMIPS_TOOFAR32 (fragp->fr_subtype))
17935 /* We generate a fixup instead of applying it right now,
17936 because if there is linker relaxation, we're going to
17937 need the relocations. */
17938 fixp = fix_new_exp (fragp, buf - (bfd_byte *) fragp->fr_literal,
17939 4, &exp, TRUE, BFD_RELOC_MICROMIPS_16_PCREL_S1);
17940 fixp->fx_file = fragp->fr_file;
17941 fixp->fx_line = fragp->fr_line;
17947 /* Relax 16-bit branches to 32-bit branches. */
17950 if (target_big_endian)
17951 insn = bfd_getb16 (buf);
17953 insn = bfd_getl16 (buf);
17955 if ((insn & 0xfc00) == 0xcc00) /* b16 */
17956 insn = 0x94000000; /* beq */
17957 else if ((insn & 0xdc00) == 0x8c00) /* beqz16/bnez16 */
17959 unsigned long regno;
17961 regno = (insn >> MICROMIPSOP_SH_MD) & MICROMIPSOP_MASK_MD;
17962 regno = micromips_to_32_reg_d_map [regno];
17963 insn = ((insn & 0x2000) << 16) | 0x94000000; /* beq/bne */
17964 insn |= regno << MICROMIPSOP_SH_RS;
17969 /* Nothing else to do, just write it out. */
17970 if (!RELAX_MICROMIPS_RELAX32 (fragp->fr_subtype)
17971 || !RELAX_MICROMIPS_TOOFAR32 (fragp->fr_subtype))
17973 md_number_to_chars ((char *) buf, insn >> 16, 2);
17975 md_number_to_chars ((char *) buf, insn & 0xffff, 2);
17978 gas_assert (buf == ((bfd_byte *) fragp->fr_literal
17985 unsigned long next;
17987 if (target_big_endian)
17989 insn = bfd_getb16 (buf);
17990 next = bfd_getb16 (buf + 2);
17994 insn = bfd_getl16 (buf);
17995 next = bfd_getl16 (buf + 2);
17997 insn = (insn << 16) | next;
18000 /* Relax 32-bit branches to a sequence of instructions. */
18001 as_warn_where (fragp->fr_file, fragp->fr_line,
18002 _("Relaxed out-of-range branch into a jump"));
18004 /* Set the short-delay-slot bit. */
18005 short_ds = al && (insn & 0x02000000) != 0;
18007 if (!RELAX_MICROMIPS_UNCOND (fragp->fr_subtype))
18011 /* Reverse the branch. */
18012 if ((insn & 0xfc000000) == 0x94000000 /* beq */
18013 || (insn & 0xfc000000) == 0xb4000000) /* bne */
18014 insn ^= 0x20000000;
18015 else if ((insn & 0xffe00000) == 0x40000000 /* bltz */
18016 || (insn & 0xffe00000) == 0x40400000 /* bgez */
18017 || (insn & 0xffe00000) == 0x40800000 /* blez */
18018 || (insn & 0xffe00000) == 0x40c00000 /* bgtz */
18019 || (insn & 0xffe00000) == 0x40a00000 /* bnezc */
18020 || (insn & 0xffe00000) == 0x40e00000 /* beqzc */
18021 || (insn & 0xffe00000) == 0x40200000 /* bltzal */
18022 || (insn & 0xffe00000) == 0x40600000 /* bgezal */
18023 || (insn & 0xffe00000) == 0x42200000 /* bltzals */
18024 || (insn & 0xffe00000) == 0x42600000) /* bgezals */
18025 insn ^= 0x00400000;
18026 else if ((insn & 0xffe30000) == 0x43800000 /* bc1f */
18027 || (insn & 0xffe30000) == 0x43a00000 /* bc1t */
18028 || (insn & 0xffe30000) == 0x42800000 /* bc2f */
18029 || (insn & 0xffe30000) == 0x42a00000) /* bc2t */
18030 insn ^= 0x00200000;
18036 /* Clear the and-link and short-delay-slot bits. */
18037 gas_assert ((insn & 0xfda00000) == 0x40200000);
18039 /* bltzal 0x40200000 bgezal 0x40600000 */
18040 /* bltzals 0x42200000 bgezals 0x42600000 */
18041 insn &= ~0x02200000;
18044 /* Make a label at the end for use with the branch. */
18045 l = symbol_new (micromips_label_name (), asec, fragp->fr_fix, fragp);
18046 micromips_label_inc ();
18047 #if defined(OBJ_ELF) || defined(OBJ_MAYBE_ELF)
18049 S_SET_OTHER (l, ELF_ST_SET_MICROMIPS (S_GET_OTHER (l)));
18053 fixp = fix_new (fragp, buf - (bfd_byte *) fragp->fr_literal,
18054 4, l, 0, TRUE, BFD_RELOC_MICROMIPS_16_PCREL_S1);
18055 fixp->fx_file = fragp->fr_file;
18056 fixp->fx_line = fragp->fr_line;
18058 /* Branch over the jump. */
18059 md_number_to_chars ((char *) buf, insn >> 16, 2);
18061 md_number_to_chars ((char *) buf, insn & 0xffff, 2);
18068 md_number_to_chars ((char *) buf, insn, 2);
18073 if (mips_pic == NO_PIC)
18075 unsigned long jal = short_ds ? 0x74000000 : 0xf4000000; /* jal/s */
18077 /* j/jal/jals <sym> R_MICROMIPS_26_S1 */
18078 insn = al ? jal : 0xd4000000;
18080 fixp = fix_new_exp (fragp, buf - (bfd_byte *) fragp->fr_literal,
18081 4, &exp, FALSE, BFD_RELOC_MICROMIPS_JMP);
18082 fixp->fx_file = fragp->fr_file;
18083 fixp->fx_line = fragp->fr_line;
18085 md_number_to_chars ((char *) buf, insn >> 16, 2);
18087 md_number_to_chars ((char *) buf, insn & 0xffff, 2);
18094 md_number_to_chars ((char *) buf, insn, 2);
18100 unsigned long at = RELAX_MICROMIPS_AT (fragp->fr_subtype);
18101 unsigned long jalr = short_ds ? 0x45e0 : 0x45c0; /* jalr/s */
18102 unsigned long jr = compact ? 0x45a0 : 0x4580; /* jr/c */
18104 /* lw/ld $at, <sym>($gp) R_MICROMIPS_GOT16 */
18105 insn = HAVE_64BIT_ADDRESSES ? 0xdc1c0000 : 0xfc1c0000;
18106 insn |= at << MICROMIPSOP_SH_RT;
18108 if (exp.X_add_number)
18110 exp.X_add_symbol = make_expr_symbol (&exp);
18111 exp.X_add_number = 0;
18114 fixp = fix_new_exp (fragp, buf - (bfd_byte *) fragp->fr_literal,
18115 4, &exp, FALSE, BFD_RELOC_MICROMIPS_GOT16);
18116 fixp->fx_file = fragp->fr_file;
18117 fixp->fx_line = fragp->fr_line;
18119 md_number_to_chars ((char *) buf, insn >> 16, 2);
18121 md_number_to_chars ((char *) buf, insn & 0xffff, 2);
18124 /* d/addiu $at, $at, <sym> R_MICROMIPS_LO16 */
18125 insn = HAVE_64BIT_ADDRESSES ? 0x5c000000 : 0x30000000;
18126 insn |= at << MICROMIPSOP_SH_RT | at << MICROMIPSOP_SH_RS;
18128 fixp = fix_new_exp (fragp, buf - (bfd_byte *) fragp->fr_literal,
18129 4, &exp, FALSE, BFD_RELOC_MICROMIPS_LO16);
18130 fixp->fx_file = fragp->fr_file;
18131 fixp->fx_line = fragp->fr_line;
18133 md_number_to_chars ((char *) buf, insn >> 16, 2);
18135 md_number_to_chars ((char *) buf, insn & 0xffff, 2);
18138 /* jr/jrc/jalr/jalrs $at */
18139 insn = al ? jalr : jr;
18140 insn |= at << MICROMIPSOP_SH_MJ;
18142 md_number_to_chars ((char *) buf, insn & 0xffff, 2);
18146 gas_assert (buf == (bfd_byte *) fragp->fr_literal + fragp->fr_fix);
18150 if (RELAX_MIPS16_P (fragp->fr_subtype))
18153 const struct mips16_immed_operand *op;
18154 bfd_boolean small, ext;
18157 unsigned long insn;
18158 bfd_boolean use_extend;
18159 unsigned short extend;
18161 type = RELAX_MIPS16_TYPE (fragp->fr_subtype);
18162 op = mips16_immed_operands;
18163 while (op->type != type)
18166 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
18177 val = resolve_symbol_value (fragp->fr_symbol);
18182 addr = fragp->fr_address + fragp->fr_fix;
18184 /* The rules for the base address of a PC relative reloc are
18185 complicated; see mips16_extended_frag. */
18186 if (type == 'p' || type == 'q')
18191 /* Ignore the low bit in the target, since it will be
18192 set for a text label. */
18193 if ((val & 1) != 0)
18196 else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype))
18198 else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype))
18201 addr &= ~ (addressT) ((1 << op->shift) - 1);
18204 /* Make sure the section winds up with the alignment we have
18207 record_alignment (asec, op->shift);
18211 && (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype)
18212 || RELAX_MIPS16_DSLOT (fragp->fr_subtype)))
18213 as_warn_where (fragp->fr_file, fragp->fr_line,
18214 _("extended instruction in delay slot"));
18216 buf = (bfd_byte *) (fragp->fr_literal + fragp->fr_fix);
18218 if (target_big_endian)
18219 insn = bfd_getb16 (buf);
18221 insn = bfd_getl16 (buf);
18223 mips16_immed (fragp->fr_file, fragp->fr_line, type, val,
18224 RELAX_MIPS16_USER_EXT (fragp->fr_subtype),
18225 small, ext, &insn, &use_extend, &extend);
18229 md_number_to_chars ((char *) buf, 0xf000 | extend, 2);
18230 fragp->fr_fix += 2;
18234 md_number_to_chars ((char *) buf, insn, 2);
18235 fragp->fr_fix += 2;
18240 relax_substateT subtype = fragp->fr_subtype;
18241 bfd_boolean second_longer = (subtype & RELAX_SECOND_LONGER) != 0;
18242 bfd_boolean use_second = (subtype & RELAX_USE_SECOND) != 0;
18246 first = RELAX_FIRST (subtype);
18247 second = RELAX_SECOND (subtype);
18248 fixp = (fixS *) fragp->fr_opcode;
18250 /* If the delay slot chosen does not match the size of the instruction,
18251 then emit a warning. */
18252 if ((!use_second && (subtype & RELAX_DELAY_SLOT_SIZE_FIRST) != 0)
18253 || (use_second && (subtype & RELAX_DELAY_SLOT_SIZE_SECOND) != 0))
18258 s = subtype & (RELAX_DELAY_SLOT_16BIT
18259 | RELAX_DELAY_SLOT_SIZE_FIRST
18260 | RELAX_DELAY_SLOT_SIZE_SECOND);
18261 msg = macro_warning (s);
18263 as_warn_where (fragp->fr_file, fragp->fr_line, "%s", msg);
18267 /* Possibly emit a warning if we've chosen the longer option. */
18268 if (use_second == second_longer)
18274 & (RELAX_SECOND_LONGER | RELAX_NOMACRO | RELAX_DELAY_SLOT));
18275 msg = macro_warning (s);
18277 as_warn_where (fragp->fr_file, fragp->fr_line, "%s", msg);
18281 /* Go through all the fixups for the first sequence. Disable them
18282 (by marking them as done) if we're going to use the second
18283 sequence instead. */
18285 && fixp->fx_frag == fragp
18286 && fixp->fx_where < fragp->fr_fix - second)
18288 if (subtype & RELAX_USE_SECOND)
18290 fixp = fixp->fx_next;
18293 /* Go through the fixups for the second sequence. Disable them if
18294 we're going to use the first sequence, otherwise adjust their
18295 addresses to account for the relaxation. */
18296 while (fixp && fixp->fx_frag == fragp)
18298 if (subtype & RELAX_USE_SECOND)
18299 fixp->fx_where -= first;
18302 fixp = fixp->fx_next;
18305 /* Now modify the frag contents. */
18306 if (subtype & RELAX_USE_SECOND)
18310 start = fragp->fr_literal + fragp->fr_fix - first - second;
18311 memmove (start, start + first, second);
18312 fragp->fr_fix -= first;
18315 fragp->fr_fix -= second;
18321 /* This function is called after the relocs have been generated.
18322 We've been storing mips16 text labels as odd. Here we convert them
18323 back to even for the convenience of the debugger. */
18326 mips_frob_file_after_relocs (void)
18329 unsigned int count, i;
18334 syms = bfd_get_outsymbols (stdoutput);
18335 count = bfd_get_symcount (stdoutput);
18336 for (i = 0; i < count; i++, syms++)
18337 if (ELF_ST_IS_COMPRESSED (elf_symbol (*syms)->internal_elf_sym.st_other)
18338 && ((*syms)->value & 1) != 0)
18340 (*syms)->value &= ~1;
18341 /* If the symbol has an odd size, it was probably computed
18342 incorrectly, so adjust that as well. */
18343 if ((elf_symbol (*syms)->internal_elf_sym.st_size & 1) != 0)
18344 ++elf_symbol (*syms)->internal_elf_sym.st_size;
18350 /* This function is called whenever a label is defined, including fake
18351 labels instantiated off the dot special symbol. It is used when
18352 handling branch delays; if a branch has a label, we assume we cannot
18353 move it. This also bumps the value of the symbol by 1 in compressed
18357 mips_record_label (symbolS *sym)
18359 segment_info_type *si = seg_info (now_seg);
18360 struct insn_label_list *l;
18362 if (free_insn_labels == NULL)
18363 l = (struct insn_label_list *) xmalloc (sizeof *l);
18366 l = free_insn_labels;
18367 free_insn_labels = l->next;
18371 l->next = si->label_list;
18372 si->label_list = l;
18375 /* This function is called as tc_frob_label() whenever a label is defined
18376 and adds a DWARF-2 record we only want for true labels. */
18379 mips_define_label (symbolS *sym)
18381 mips_record_label (sym);
18383 dwarf2_emit_label (sym);
18387 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
18389 /* Some special processing for a MIPS ELF file. */
18392 mips_elf_final_processing (void)
18394 /* Write out the register information. */
18395 if (mips_abi != N64_ABI)
18399 s.ri_gprmask = mips_gprmask;
18400 s.ri_cprmask[0] = mips_cprmask[0];
18401 s.ri_cprmask[1] = mips_cprmask[1];
18402 s.ri_cprmask[2] = mips_cprmask[2];
18403 s.ri_cprmask[3] = mips_cprmask[3];
18404 /* The gp_value field is set by the MIPS ELF backend. */
18406 bfd_mips_elf32_swap_reginfo_out (stdoutput, &s,
18407 ((Elf32_External_RegInfo *)
18408 mips_regmask_frag));
18412 Elf64_Internal_RegInfo s;
18414 s.ri_gprmask = mips_gprmask;
18416 s.ri_cprmask[0] = mips_cprmask[0];
18417 s.ri_cprmask[1] = mips_cprmask[1];
18418 s.ri_cprmask[2] = mips_cprmask[2];
18419 s.ri_cprmask[3] = mips_cprmask[3];
18420 /* The gp_value field is set by the MIPS ELF backend. */
18422 bfd_mips_elf64_swap_reginfo_out (stdoutput, &s,
18423 ((Elf64_External_RegInfo *)
18424 mips_regmask_frag));
18427 /* Set the MIPS ELF flag bits. FIXME: There should probably be some
18428 sort of BFD interface for this. */
18429 if (mips_any_noreorder)
18430 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_NOREORDER;
18431 if (mips_pic != NO_PIC)
18433 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_PIC;
18434 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_CPIC;
18437 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_CPIC;
18439 /* Set MIPS ELF flags for ASEs. */
18440 /* We may need to define a new flag for DSP ASE, and set this flag when
18441 file_ase_dsp is true. */
18442 /* Same for DSP R2. */
18443 /* We may need to define a new flag for MT ASE, and set this flag when
18444 file_ase_mt is true. */
18445 if (file_ase_mips16)
18446 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ARCH_ASE_M16;
18447 if (file_ase_micromips)
18448 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ARCH_ASE_MICROMIPS;
18449 #if 0 /* XXX FIXME */
18450 if (file_ase_mips3d)
18451 elf_elfheader (stdoutput)->e_flags |= ???;
18454 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ARCH_ASE_MDMX;
18456 /* Set the MIPS ELF ABI flags. */
18457 if (mips_abi == O32_ABI && USE_E_MIPS_ABI_O32)
18458 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O32;
18459 else if (mips_abi == O64_ABI)
18460 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O64;
18461 else if (mips_abi == EABI_ABI)
18463 if (!file_mips_gp32)
18464 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI64;
18466 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI32;
18468 else if (mips_abi == N32_ABI)
18469 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ABI2;
18471 /* Nothing to do for N64_ABI. */
18473 if (mips_32bitmode)
18474 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_32BITMODE;
18476 #if 0 /* XXX FIXME */
18477 /* 32 bit code with 64 bit FP registers. */
18478 if (!file_mips_fp32 && ABI_NEEDS_32BIT_REGS (mips_abi))
18479 elf_elfheader (stdoutput)->e_flags |= ???;
18483 #endif /* OBJ_ELF || OBJ_MAYBE_ELF */
18485 typedef struct proc {
18487 symbolS *func_end_sym;
18488 unsigned long reg_mask;
18489 unsigned long reg_offset;
18490 unsigned long fpreg_mask;
18491 unsigned long fpreg_offset;
18492 unsigned long frame_offset;
18493 unsigned long frame_reg;
18494 unsigned long pc_reg;
18497 static procS cur_proc;
18498 static procS *cur_proc_ptr;
18499 static int numprocs;
18501 /* Implement NOP_OPCODE. We encode a MIPS16 nop as "1", a microMIPS nop
18502 as "2", and a normal nop as "0". */
18504 #define NOP_OPCODE_MIPS 0
18505 #define NOP_OPCODE_MIPS16 1
18506 #define NOP_OPCODE_MICROMIPS 2
18509 mips_nop_opcode (void)
18511 if (seg_info (now_seg)->tc_segment_info_data.micromips)
18512 return NOP_OPCODE_MICROMIPS;
18513 else if (seg_info (now_seg)->tc_segment_info_data.mips16)
18514 return NOP_OPCODE_MIPS16;
18516 return NOP_OPCODE_MIPS;
18519 /* Fill in an rs_align_code fragment. Unlike elsewhere we want to use
18520 32-bit microMIPS NOPs here (if applicable). */
18523 mips_handle_align (fragS *fragp)
18527 int bytes, size, excess;
18530 if (fragp->fr_type != rs_align_code)
18533 p = fragp->fr_literal + fragp->fr_fix;
18535 switch (nop_opcode)
18537 case NOP_OPCODE_MICROMIPS:
18538 opcode = micromips_nop32_insn.insn_opcode;
18541 case NOP_OPCODE_MIPS16:
18542 opcode = mips16_nop_insn.insn_opcode;
18545 case NOP_OPCODE_MIPS:
18547 opcode = nop_insn.insn_opcode;
18552 bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
18553 excess = bytes % size;
18555 /* Handle the leading part if we're not inserting a whole number of
18556 instructions, and make it the end of the fixed part of the frag.
18557 Try to fit in a short microMIPS NOP if applicable and possible,
18558 and use zeroes otherwise. */
18559 gas_assert (excess < 4);
18560 fragp->fr_fix += excess;
18565 /* Fall through. */
18567 if (nop_opcode == NOP_OPCODE_MICROMIPS)
18569 md_number_to_chars (p, micromips_nop16_insn.insn_opcode, 2);
18574 /* Fall through. */
18577 /* Fall through. */
18582 md_number_to_chars (p, opcode, size);
18583 fragp->fr_var = size;
18587 md_obj_begin (void)
18594 /* Check for premature end, nesting errors, etc. */
18596 as_warn (_("missing .end at end of assembly"));
18605 if (*input_line_pointer == '-')
18607 ++input_line_pointer;
18610 if (!ISDIGIT (*input_line_pointer))
18611 as_bad (_("expected simple number"));
18612 if (input_line_pointer[0] == '0')
18614 if (input_line_pointer[1] == 'x')
18616 input_line_pointer += 2;
18617 while (ISXDIGIT (*input_line_pointer))
18620 val |= hex_value (*input_line_pointer++);
18622 return negative ? -val : val;
18626 ++input_line_pointer;
18627 while (ISDIGIT (*input_line_pointer))
18630 val |= *input_line_pointer++ - '0';
18632 return negative ? -val : val;
18635 if (!ISDIGIT (*input_line_pointer))
18637 printf (_(" *input_line_pointer == '%c' 0x%02x\n"),
18638 *input_line_pointer, *input_line_pointer);
18639 as_warn (_("invalid number"));
18642 while (ISDIGIT (*input_line_pointer))
18645 val += *input_line_pointer++ - '0';
18647 return negative ? -val : val;
18650 /* The .file directive; just like the usual .file directive, but there
18651 is an initial number which is the ECOFF file index. In the non-ECOFF
18652 case .file implies DWARF-2. */
18655 s_mips_file (int x ATTRIBUTE_UNUSED)
18657 static int first_file_directive = 0;
18659 if (ECOFF_DEBUGGING)
18668 filename = dwarf2_directive_file (0);
18670 /* Versions of GCC up to 3.1 start files with a ".file"
18671 directive even for stabs output. Make sure that this
18672 ".file" is handled. Note that you need a version of GCC
18673 after 3.1 in order to support DWARF-2 on MIPS. */
18674 if (filename != NULL && ! first_file_directive)
18676 (void) new_logical_line (filename, -1);
18677 s_app_file_string (filename, 0);
18679 first_file_directive = 1;
18683 /* The .loc directive, implying DWARF-2. */
18686 s_mips_loc (int x ATTRIBUTE_UNUSED)
18688 if (!ECOFF_DEBUGGING)
18689 dwarf2_directive_loc (0);
18692 /* The .end directive. */
18695 s_mips_end (int x ATTRIBUTE_UNUSED)
18699 /* Following functions need their own .frame and .cprestore directives. */
18700 mips_frame_reg_valid = 0;
18701 mips_cprestore_valid = 0;
18703 if (!is_end_of_line[(unsigned char) *input_line_pointer])
18706 demand_empty_rest_of_line ();
18711 if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) == 0)
18712 as_warn (_(".end not in text section"));
18716 as_warn (_(".end directive without a preceding .ent directive."));
18717 demand_empty_rest_of_line ();
18723 gas_assert (S_GET_NAME (p));
18724 if (strcmp (S_GET_NAME (p), S_GET_NAME (cur_proc_ptr->func_sym)))
18725 as_warn (_(".end symbol does not match .ent symbol."));
18727 if (debug_type == DEBUG_STABS)
18728 stabs_generate_asm_endfunc (S_GET_NAME (p),
18732 as_warn (_(".end directive missing or unknown symbol"));
18735 /* Create an expression to calculate the size of the function. */
18736 if (p && cur_proc_ptr)
18738 OBJ_SYMFIELD_TYPE *obj = symbol_get_obj (p);
18739 expressionS *exp = xmalloc (sizeof (expressionS));
18742 exp->X_op = O_subtract;
18743 exp->X_add_symbol = symbol_temp_new_now ();
18744 exp->X_op_symbol = p;
18745 exp->X_add_number = 0;
18747 cur_proc_ptr->func_end_sym = exp->X_add_symbol;
18750 /* Generate a .pdr section. */
18751 if (IS_ELF && !ECOFF_DEBUGGING && mips_flag_pdr)
18753 segT saved_seg = now_seg;
18754 subsegT saved_subseg = now_subseg;
18758 #ifdef md_flush_pending_output
18759 md_flush_pending_output ();
18762 gas_assert (pdr_seg);
18763 subseg_set (pdr_seg, 0);
18765 /* Write the symbol. */
18766 exp.X_op = O_symbol;
18767 exp.X_add_symbol = p;
18768 exp.X_add_number = 0;
18769 emit_expr (&exp, 4);
18771 fragp = frag_more (7 * 4);
18773 md_number_to_chars (fragp, cur_proc_ptr->reg_mask, 4);
18774 md_number_to_chars (fragp + 4, cur_proc_ptr->reg_offset, 4);
18775 md_number_to_chars (fragp + 8, cur_proc_ptr->fpreg_mask, 4);
18776 md_number_to_chars (fragp + 12, cur_proc_ptr->fpreg_offset, 4);
18777 md_number_to_chars (fragp + 16, cur_proc_ptr->frame_offset, 4);
18778 md_number_to_chars (fragp + 20, cur_proc_ptr->frame_reg, 4);
18779 md_number_to_chars (fragp + 24, cur_proc_ptr->pc_reg, 4);
18781 subseg_set (saved_seg, saved_subseg);
18783 #endif /* OBJ_ELF */
18785 cur_proc_ptr = NULL;
18788 /* The .aent and .ent directives. */
18791 s_mips_ent (int aent)
18795 symbolP = get_symbol ();
18796 if (*input_line_pointer == ',')
18797 ++input_line_pointer;
18798 SKIP_WHITESPACE ();
18799 if (ISDIGIT (*input_line_pointer)
18800 || *input_line_pointer == '-')
18803 if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) == 0)
18804 as_warn (_(".ent or .aent not in text section."));
18806 if (!aent && cur_proc_ptr)
18807 as_warn (_("missing .end"));
18811 /* This function needs its own .frame and .cprestore directives. */
18812 mips_frame_reg_valid = 0;
18813 mips_cprestore_valid = 0;
18815 cur_proc_ptr = &cur_proc;
18816 memset (cur_proc_ptr, '\0', sizeof (procS));
18818 cur_proc_ptr->func_sym = symbolP;
18822 if (debug_type == DEBUG_STABS)
18823 stabs_generate_asm_func (S_GET_NAME (symbolP),
18824 S_GET_NAME (symbolP));
18827 symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION;
18829 demand_empty_rest_of_line ();
18832 /* The .frame directive. If the mdebug section is present (IRIX 5 native)
18833 then ecoff.c (ecoff_directive_frame) is used. For embedded targets,
18834 s_mips_frame is used so that we can set the PDR information correctly.
18835 We can't use the ecoff routines because they make reference to the ecoff
18836 symbol table (in the mdebug section). */
18839 s_mips_frame (int ignore ATTRIBUTE_UNUSED)
18842 if (IS_ELF && !ECOFF_DEBUGGING)
18846 if (cur_proc_ptr == (procS *) NULL)
18848 as_warn (_(".frame outside of .ent"));
18849 demand_empty_rest_of_line ();
18853 cur_proc_ptr->frame_reg = tc_get_register (1);
18855 SKIP_WHITESPACE ();
18856 if (*input_line_pointer++ != ','
18857 || get_absolute_expression_and_terminator (&val) != ',')
18859 as_warn (_("Bad .frame directive"));
18860 --input_line_pointer;
18861 demand_empty_rest_of_line ();
18865 cur_proc_ptr->frame_offset = val;
18866 cur_proc_ptr->pc_reg = tc_get_register (0);
18868 demand_empty_rest_of_line ();
18871 #endif /* OBJ_ELF */
18875 /* The .fmask and .mask directives. If the mdebug section is present
18876 (IRIX 5 native) then ecoff.c (ecoff_directive_mask) is used. For
18877 embedded targets, s_mips_mask is used so that we can set the PDR
18878 information correctly. We can't use the ecoff routines because they
18879 make reference to the ecoff symbol table (in the mdebug section). */
18882 s_mips_mask (int reg_type)
18885 if (IS_ELF && !ECOFF_DEBUGGING)
18889 if (cur_proc_ptr == (procS *) NULL)
18891 as_warn (_(".mask/.fmask outside of .ent"));
18892 demand_empty_rest_of_line ();
18896 if (get_absolute_expression_and_terminator (&mask) != ',')
18898 as_warn (_("Bad .mask/.fmask directive"));
18899 --input_line_pointer;
18900 demand_empty_rest_of_line ();
18904 off = get_absolute_expression ();
18906 if (reg_type == 'F')
18908 cur_proc_ptr->fpreg_mask = mask;
18909 cur_proc_ptr->fpreg_offset = off;
18913 cur_proc_ptr->reg_mask = mask;
18914 cur_proc_ptr->reg_offset = off;
18917 demand_empty_rest_of_line ();
18920 #endif /* OBJ_ELF */
18921 s_ignore (reg_type);
18924 /* A table describing all the processors gas knows about. Names are
18925 matched in the order listed.
18927 To ease comparison, please keep this table in the same order as
18928 gcc's mips_cpu_info_table[]. */
18929 static const struct mips_cpu_info mips_cpu_info_table[] =
18931 /* Entries for generic ISAs */
18932 { "mips1", MIPS_CPU_IS_ISA, ISA_MIPS1, CPU_R3000 },
18933 { "mips2", MIPS_CPU_IS_ISA, ISA_MIPS2, CPU_R6000 },
18934 { "mips3", MIPS_CPU_IS_ISA, ISA_MIPS3, CPU_R4000 },
18935 { "mips4", MIPS_CPU_IS_ISA, ISA_MIPS4, CPU_R8000 },
18936 { "mips5", MIPS_CPU_IS_ISA, ISA_MIPS5, CPU_MIPS5 },
18937 { "mips32", MIPS_CPU_IS_ISA, ISA_MIPS32, CPU_MIPS32 },
18938 { "mips32r2", MIPS_CPU_IS_ISA, ISA_MIPS32R2, CPU_MIPS32R2 },
18939 { "mips64", MIPS_CPU_IS_ISA, ISA_MIPS64, CPU_MIPS64 },
18940 { "mips64r2", MIPS_CPU_IS_ISA, ISA_MIPS64R2, CPU_MIPS64R2 },
18943 { "r3000", 0, ISA_MIPS1, CPU_R3000 },
18944 { "r2000", 0, ISA_MIPS1, CPU_R3000 },
18945 { "r3900", 0, ISA_MIPS1, CPU_R3900 },
18948 { "r6000", 0, ISA_MIPS2, CPU_R6000 },
18951 { "r4000", 0, ISA_MIPS3, CPU_R4000 },
18952 { "r4010", 0, ISA_MIPS2, CPU_R4010 },
18953 { "vr4100", 0, ISA_MIPS3, CPU_VR4100 },
18954 { "vr4111", 0, ISA_MIPS3, CPU_R4111 },
18955 { "vr4120", 0, ISA_MIPS3, CPU_VR4120 },
18956 { "vr4130", 0, ISA_MIPS3, CPU_VR4120 },
18957 { "vr4181", 0, ISA_MIPS3, CPU_R4111 },
18958 { "vr4300", 0, ISA_MIPS3, CPU_R4300 },
18959 { "r4400", 0, ISA_MIPS3, CPU_R4400 },
18960 { "r4600", 0, ISA_MIPS3, CPU_R4600 },
18961 { "orion", 0, ISA_MIPS3, CPU_R4600 },
18962 { "r4650", 0, ISA_MIPS3, CPU_R4650 },
18963 /* ST Microelectronics Loongson 2E and 2F cores */
18964 { "loongson2e", 0, ISA_MIPS3, CPU_LOONGSON_2E },
18965 { "loongson2f", 0, ISA_MIPS3, CPU_LOONGSON_2F },
18968 { "r8000", 0, ISA_MIPS4, CPU_R8000 },
18969 { "r10000", 0, ISA_MIPS4, CPU_R10000 },
18970 { "r12000", 0, ISA_MIPS4, CPU_R12000 },
18971 { "r14000", 0, ISA_MIPS4, CPU_R14000 },
18972 { "r16000", 0, ISA_MIPS4, CPU_R16000 },
18973 { "vr5000", 0, ISA_MIPS4, CPU_R5000 },
18974 { "vr5400", 0, ISA_MIPS4, CPU_VR5400 },
18975 { "vr5500", 0, ISA_MIPS4, CPU_VR5500 },
18976 { "rm5200", 0, ISA_MIPS4, CPU_R5000 },
18977 { "rm5230", 0, ISA_MIPS4, CPU_R5000 },
18978 { "rm5231", 0, ISA_MIPS4, CPU_R5000 },
18979 { "rm5261", 0, ISA_MIPS4, CPU_R5000 },
18980 { "rm5721", 0, ISA_MIPS4, CPU_R5000 },
18981 { "rm7000", 0, ISA_MIPS4, CPU_RM7000 },
18982 { "rm9000", 0, ISA_MIPS4, CPU_RM9000 },
18985 { "4kc", 0, ISA_MIPS32, CPU_MIPS32 },
18986 { "4km", 0, ISA_MIPS32, CPU_MIPS32 },
18987 { "4kp", 0, ISA_MIPS32, CPU_MIPS32 },
18988 { "4ksc", MIPS_CPU_ASE_SMARTMIPS, ISA_MIPS32, CPU_MIPS32 },
18990 /* MIPS 32 Release 2 */
18991 { "4kec", 0, ISA_MIPS32R2, CPU_MIPS32R2 },
18992 { "4kem", 0, ISA_MIPS32R2, CPU_MIPS32R2 },
18993 { "4kep", 0, ISA_MIPS32R2, CPU_MIPS32R2 },
18994 { "4ksd", MIPS_CPU_ASE_SMARTMIPS, ISA_MIPS32R2, CPU_MIPS32R2 },
18995 { "m4k", 0, ISA_MIPS32R2, CPU_MIPS32R2 },
18996 { "m4kp", 0, ISA_MIPS32R2, CPU_MIPS32R2 },
18997 { "m14k", MIPS_CPU_ASE_MCU, ISA_MIPS32R2, CPU_MIPS32R2 },
18998 { "m14kc", MIPS_CPU_ASE_MCU, ISA_MIPS32R2, CPU_MIPS32R2 },
18999 { "m14ke", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_DSPR2 | MIPS_CPU_ASE_MCU,
19000 ISA_MIPS32R2, CPU_MIPS32R2 },
19001 { "m14kec", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_DSPR2 | MIPS_CPU_ASE_MCU,
19002 ISA_MIPS32R2, CPU_MIPS32R2 },
19003 { "24kc", 0, ISA_MIPS32R2, CPU_MIPS32R2 },
19004 { "24kf2_1", 0, ISA_MIPS32R2, CPU_MIPS32R2 },
19005 { "24kf", 0, ISA_MIPS32R2, CPU_MIPS32R2 },
19006 { "24kf1_1", 0, ISA_MIPS32R2, CPU_MIPS32R2 },
19007 /* Deprecated forms of the above. */
19008 { "24kfx", 0, ISA_MIPS32R2, CPU_MIPS32R2 },
19009 { "24kx", 0, ISA_MIPS32R2, CPU_MIPS32R2 },
19010 /* 24KE is a 24K with DSP ASE, other ASEs are optional. */
19011 { "24kec", MIPS_CPU_ASE_DSP, ISA_MIPS32R2, CPU_MIPS32R2 },
19012 { "24kef2_1", MIPS_CPU_ASE_DSP, ISA_MIPS32R2, CPU_MIPS32R2 },
19013 { "24kef", MIPS_CPU_ASE_DSP, ISA_MIPS32R2, CPU_MIPS32R2 },
19014 { "24kef1_1", MIPS_CPU_ASE_DSP, ISA_MIPS32R2, CPU_MIPS32R2 },
19015 /* Deprecated forms of the above. */
19016 { "24kefx", MIPS_CPU_ASE_DSP, ISA_MIPS32R2, CPU_MIPS32R2 },
19017 { "24kex", MIPS_CPU_ASE_DSP, ISA_MIPS32R2, CPU_MIPS32R2 },
19018 /* 34K is a 24K with DSP and MT ASE, other ASEs are optional. */
19019 { "34kc", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_MT,
19020 ISA_MIPS32R2, CPU_MIPS32R2 },
19021 { "34kf2_1", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_MT,
19022 ISA_MIPS32R2, CPU_MIPS32R2 },
19023 { "34kf", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_MT,
19024 ISA_MIPS32R2, CPU_MIPS32R2 },
19025 { "34kf1_1", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_MT,
19026 ISA_MIPS32R2, CPU_MIPS32R2 },
19027 /* Deprecated forms of the above. */
19028 { "34kfx", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_MT,
19029 ISA_MIPS32R2, CPU_MIPS32R2 },
19030 { "34kx", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_MT,
19031 ISA_MIPS32R2, CPU_MIPS32R2 },
19032 /* 74K with DSP and DSPR2 ASE, other ASEs are optional. */
19033 { "74kc", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_DSPR2,
19034 ISA_MIPS32R2, CPU_MIPS32R2 },
19035 { "74kf2_1", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_DSPR2,
19036 ISA_MIPS32R2, CPU_MIPS32R2 },
19037 { "74kf", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_DSPR2,
19038 ISA_MIPS32R2, CPU_MIPS32R2 },
19039 { "74kf1_1", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_DSPR2,
19040 ISA_MIPS32R2, CPU_MIPS32R2 },
19041 { "74kf3_2", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_DSPR2,
19042 ISA_MIPS32R2, CPU_MIPS32R2 },
19043 /* Deprecated forms of the above. */
19044 { "74kfx", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_DSPR2,
19045 ISA_MIPS32R2, CPU_MIPS32R2 },
19046 { "74kx", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_DSPR2,
19047 ISA_MIPS32R2, CPU_MIPS32R2 },
19048 /* 1004K cores are multiprocessor versions of the 34K. */
19049 { "1004kc", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_MT,
19050 ISA_MIPS32R2, CPU_MIPS32R2 },
19051 { "1004kf2_1", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_MT,
19052 ISA_MIPS32R2, CPU_MIPS32R2 },
19053 { "1004kf", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_MT,
19054 ISA_MIPS32R2, CPU_MIPS32R2 },
19055 { "1004kf1_1", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_MT,
19056 ISA_MIPS32R2, CPU_MIPS32R2 },
19059 { "5kc", 0, ISA_MIPS64, CPU_MIPS64 },
19060 { "5kf", 0, ISA_MIPS64, CPU_MIPS64 },
19061 { "20kc", MIPS_CPU_ASE_MIPS3D, ISA_MIPS64, CPU_MIPS64 },
19062 { "25kf", MIPS_CPU_ASE_MIPS3D, ISA_MIPS64, CPU_MIPS64 },
19064 /* Broadcom SB-1 CPU core */
19065 { "sb1", MIPS_CPU_ASE_MIPS3D | MIPS_CPU_ASE_MDMX,
19066 ISA_MIPS64, CPU_SB1 },
19067 /* Broadcom SB-1A CPU core */
19068 { "sb1a", MIPS_CPU_ASE_MIPS3D | MIPS_CPU_ASE_MDMX,
19069 ISA_MIPS64, CPU_SB1 },
19071 { "loongson3a", 0, ISA_MIPS64, CPU_LOONGSON_3A },
19073 /* MIPS 64 Release 2 */
19075 /* Cavium Networks Octeon CPU core */
19076 { "octeon", 0, ISA_MIPS64R2, CPU_OCTEON },
19077 { "octeon+", 0, ISA_MIPS64R2, CPU_OCTEONP },
19080 { "xlr", 0, ISA_MIPS64, CPU_XLR },
19087 /* Return true if GIVEN is the same as CANONICAL, or if it is CANONICAL
19088 with a final "000" replaced by "k". Ignore case.
19090 Note: this function is shared between GCC and GAS. */
19093 mips_strict_matching_cpu_name_p (const char *canonical, const char *given)
19095 while (*given != 0 && TOLOWER (*given) == TOLOWER (*canonical))
19096 given++, canonical++;
19098 return ((*given == 0 && *canonical == 0)
19099 || (strcmp (canonical, "000") == 0 && strcasecmp (given, "k") == 0));
19103 /* Return true if GIVEN matches CANONICAL, where GIVEN is a user-supplied
19104 CPU name. We've traditionally allowed a lot of variation here.
19106 Note: this function is shared between GCC and GAS. */
19109 mips_matching_cpu_name_p (const char *canonical, const char *given)
19111 /* First see if the name matches exactly, or with a final "000"
19112 turned into "k". */
19113 if (mips_strict_matching_cpu_name_p (canonical, given))
19116 /* If not, try comparing based on numerical designation alone.
19117 See if GIVEN is an unadorned number, or 'r' followed by a number. */
19118 if (TOLOWER (*given) == 'r')
19120 if (!ISDIGIT (*given))
19123 /* Skip over some well-known prefixes in the canonical name,
19124 hoping to find a number there too. */
19125 if (TOLOWER (canonical[0]) == 'v' && TOLOWER (canonical[1]) == 'r')
19127 else if (TOLOWER (canonical[0]) == 'r' && TOLOWER (canonical[1]) == 'm')
19129 else if (TOLOWER (canonical[0]) == 'r')
19132 return mips_strict_matching_cpu_name_p (canonical, given);
19136 /* Parse an option that takes the name of a processor as its argument.
19137 OPTION is the name of the option and CPU_STRING is the argument.
19138 Return the corresponding processor enumeration if the CPU_STRING is
19139 recognized, otherwise report an error and return null.
19141 A similar function exists in GCC. */
19143 static const struct mips_cpu_info *
19144 mips_parse_cpu (const char *option, const char *cpu_string)
19146 const struct mips_cpu_info *p;
19148 /* 'from-abi' selects the most compatible architecture for the given
19149 ABI: MIPS I for 32-bit ABIs and MIPS III for 64-bit ABIs. For the
19150 EABIs, we have to decide whether we're using the 32-bit or 64-bit
19151 version. Look first at the -mgp options, if given, otherwise base
19152 the choice on MIPS_DEFAULT_64BIT.
19154 Treat NO_ABI like the EABIs. One reason to do this is that the
19155 plain 'mips' and 'mips64' configs have 'from-abi' as their default
19156 architecture. This code picks MIPS I for 'mips' and MIPS III for
19157 'mips64', just as we did in the days before 'from-abi'. */
19158 if (strcasecmp (cpu_string, "from-abi") == 0)
19160 if (ABI_NEEDS_32BIT_REGS (mips_abi))
19161 return mips_cpu_info_from_isa (ISA_MIPS1);
19163 if (ABI_NEEDS_64BIT_REGS (mips_abi))
19164 return mips_cpu_info_from_isa (ISA_MIPS3);
19166 if (file_mips_gp32 >= 0)
19167 return mips_cpu_info_from_isa (file_mips_gp32 ? ISA_MIPS1 : ISA_MIPS3);
19169 return mips_cpu_info_from_isa (MIPS_DEFAULT_64BIT
19174 /* 'default' has traditionally been a no-op. Probably not very useful. */
19175 if (strcasecmp (cpu_string, "default") == 0)
19178 for (p = mips_cpu_info_table; p->name != 0; p++)
19179 if (mips_matching_cpu_name_p (p->name, cpu_string))
19182 as_bad (_("Bad value (%s) for %s"), cpu_string, option);
19186 /* Return the canonical processor information for ISA (a member of the
19187 ISA_MIPS* enumeration). */
19189 static const struct mips_cpu_info *
19190 mips_cpu_info_from_isa (int isa)
19194 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
19195 if ((mips_cpu_info_table[i].flags & MIPS_CPU_IS_ISA)
19196 && isa == mips_cpu_info_table[i].isa)
19197 return (&mips_cpu_info_table[i]);
19202 static const struct mips_cpu_info *
19203 mips_cpu_info_from_arch (int arch)
19207 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
19208 if (arch == mips_cpu_info_table[i].cpu)
19209 return (&mips_cpu_info_table[i]);
19215 show (FILE *stream, const char *string, int *col_p, int *first_p)
19219 fprintf (stream, "%24s", "");
19224 fprintf (stream, ", ");
19228 if (*col_p + strlen (string) > 72)
19230 fprintf (stream, "\n%24s", "");
19234 fprintf (stream, "%s", string);
19235 *col_p += strlen (string);
19241 md_show_usage (FILE *stream)
19246 fprintf (stream, _("\
19248 -EB generate big endian output\n\
19249 -EL generate little endian output\n\
19250 -g, -g2 do not remove unneeded NOPs or swap branches\n\
19251 -G NUM allow referencing objects up to NUM bytes\n\
19252 implicitly with the gp register [default 8]\n"));
19253 fprintf (stream, _("\
19254 -mips1 generate MIPS ISA I instructions\n\
19255 -mips2 generate MIPS ISA II instructions\n\
19256 -mips3 generate MIPS ISA III instructions\n\
19257 -mips4 generate MIPS ISA IV instructions\n\
19258 -mips5 generate MIPS ISA V instructions\n\
19259 -mips32 generate MIPS32 ISA instructions\n\
19260 -mips32r2 generate MIPS32 release 2 ISA instructions\n\
19261 -mips64 generate MIPS64 ISA instructions\n\
19262 -mips64r2 generate MIPS64 release 2 ISA instructions\n\
19263 -march=CPU/-mtune=CPU generate code/schedule for CPU, where CPU is one of:\n"));
19267 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
19268 show (stream, mips_cpu_info_table[i].name, &column, &first);
19269 show (stream, "from-abi", &column, &first);
19270 fputc ('\n', stream);
19272 fprintf (stream, _("\
19273 -mCPU equivalent to -march=CPU -mtune=CPU. Deprecated.\n\
19274 -no-mCPU don't generate code specific to CPU.\n\
19275 For -mCPU and -no-mCPU, CPU must be one of:\n"));
19279 show (stream, "3900", &column, &first);
19280 show (stream, "4010", &column, &first);
19281 show (stream, "4100", &column, &first);
19282 show (stream, "4650", &column, &first);
19283 fputc ('\n', stream);
19285 fprintf (stream, _("\
19286 -mips16 generate mips16 instructions\n\
19287 -no-mips16 do not generate mips16 instructions\n"));
19288 fprintf (stream, _("\
19289 -mmicromips generate microMIPS instructions\n\
19290 -mno-micromips do not generate microMIPS instructions\n"));
19291 fprintf (stream, _("\
19292 -msmartmips generate smartmips instructions\n\
19293 -mno-smartmips do not generate smartmips instructions\n"));
19294 fprintf (stream, _("\
19295 -mdsp generate DSP instructions\n\
19296 -mno-dsp do not generate DSP instructions\n"));
19297 fprintf (stream, _("\
19298 -mdspr2 generate DSP R2 instructions\n\
19299 -mno-dspr2 do not generate DSP R2 instructions\n"));
19300 fprintf (stream, _("\
19301 -mmt generate MT instructions\n\
19302 -mno-mt do not generate MT instructions\n"));
19303 fprintf (stream, _("\
19304 -mmcu generate MCU instructions\n\
19305 -mno-mcu do not generate MCU instructions\n"));
19306 fprintf (stream, _("\
19307 -mfix-loongson2f-jump work around Loongson2F JUMP instructions\n\
19308 -mfix-loongson2f-nop work around Loongson2F NOP errata\n\
19309 -mfix-vr4120 work around certain VR4120 errata\n\
19310 -mfix-vr4130 work around VR4130 mflo/mfhi errata\n\
19311 -mfix-24k insert a nop after ERET and DERET instructions\n\
19312 -mfix-cn63xxp1 work around CN63XXP1 PREF errata\n\
19313 -mgp32 use 32-bit GPRs, regardless of the chosen ISA\n\
19314 -mfp32 use 32-bit FPRs, regardless of the chosen ISA\n\
19315 -msym32 assume all symbols have 32-bit values\n\
19316 -O0 remove unneeded NOPs, do not swap branches\n\
19317 -O remove unneeded NOPs and swap branches\n\
19318 --trap, --no-break trap exception on div by 0 and mult overflow\n\
19319 --break, --no-trap break exception on div by 0 and mult overflow\n"));
19320 fprintf (stream, _("\
19321 -mhard-float allow floating-point instructions\n\
19322 -msoft-float do not allow floating-point instructions\n\
19323 -msingle-float only allow 32-bit floating-point operations\n\
19324 -mdouble-float allow 32-bit and 64-bit floating-point operations\n\
19325 --[no-]construct-floats [dis]allow floating point values to be constructed\n"
19328 fprintf (stream, _("\
19329 -KPIC, -call_shared generate SVR4 position independent code\n\
19330 -call_nonpic generate non-PIC code that can operate with DSOs\n\
19331 -mvxworks-pic generate VxWorks position independent code\n\
19332 -non_shared do not generate code that can operate with DSOs\n\
19333 -xgot assume a 32 bit GOT\n\
19334 -mpdr, -mno-pdr enable/disable creation of .pdr sections\n\
19335 -mshared, -mno-shared disable/enable .cpload optimization for\n\
19336 position dependent (non shared) code\n\
19337 -mabi=ABI create ABI conformant object file for:\n"));
19341 show (stream, "32", &column, &first);
19342 show (stream, "o64", &column, &first);
19343 show (stream, "n32", &column, &first);
19344 show (stream, "64", &column, &first);
19345 show (stream, "eabi", &column, &first);
19347 fputc ('\n', stream);
19349 fprintf (stream, _("\
19350 -32 create o32 ABI object file (default)\n\
19351 -n32 create n32 ABI object file\n\
19352 -64 create 64 ABI object file\n"));
19358 mips_dwarf2_format (asection *sec ATTRIBUTE_UNUSED)
19360 if (HAVE_64BIT_SYMBOLS)
19361 return dwarf2_format_64bit_irix;
19363 return dwarf2_format_32bit;
19368 mips_dwarf2_addr_size (void)
19370 if (HAVE_64BIT_OBJECTS)
19376 /* Standard calling conventions leave the CFA at SP on entry. */
19378 mips_cfi_frame_initial_instructions (void)
19380 cfi_add_CFA_def_cfa_register (SP);
19384 tc_mips_regname_to_dw2regnum (char *regname)
19386 unsigned int regnum = -1;
19389 if (reg_lookup (®name, RTYPE_GP | RTYPE_NUM, ®))