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, 2012, 2013
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"
37 /* Check assumptions made in this file. */
38 typedef char static_assert1[sizeof (offsetT) < 8 ? -1 : 1];
39 typedef char static_assert2[sizeof (valueT) < 8 ? -1 : 1];
42 #define DBG(x) printf x
47 #define SKIP_SPACE_TABS(S) \
48 do { while (*(S) == ' ' || *(S) == '\t') ++(S); } while (0)
50 /* Clean up namespace so we can include obj-elf.h too. */
51 static int mips_output_flavor (void);
52 static int mips_output_flavor (void) { return OUTPUT_FLAVOR; }
53 #undef OBJ_PROCESS_STAB
60 #undef obj_frob_file_after_relocs
61 #undef obj_frob_symbol
63 #undef obj_sec_sym_ok_for_reloc
64 #undef OBJ_COPY_SYMBOL_ATTRIBUTES
67 /* Fix any of them that we actually care about. */
69 #define OUTPUT_FLAVOR mips_output_flavor()
73 #ifndef ECOFF_DEBUGGING
74 #define NO_ECOFF_DEBUGGING
75 #define ECOFF_DEBUGGING 0
78 int mips_flag_mdebug = -1;
80 /* Control generation of .pdr sections. Off by default on IRIX: the native
81 linker doesn't know about and discards them, but relocations against them
82 remain, leading to rld crashes. */
84 int mips_flag_pdr = FALSE;
86 int mips_flag_pdr = TRUE;
91 static char *mips_regmask_frag;
98 #define PIC_CALL_REG 25
106 #define ILLEGAL_REG (32)
108 #define AT mips_opts.at
110 extern int target_big_endian;
112 /* The name of the readonly data section. */
113 #define RDATA_SECTION_NAME ".rodata"
115 /* Ways in which an instruction can be "appended" to the output. */
117 /* Just add it normally. */
120 /* Add it normally and then add a nop. */
123 /* Turn an instruction with a delay slot into a "compact" version. */
126 /* Insert the instruction before the last one. */
130 /* Information about an instruction, including its format, operands
134 /* The opcode's entry in mips_opcodes or mips16_opcodes. */
135 const struct mips_opcode *insn_mo;
137 /* The 16-bit or 32-bit bitstring of the instruction itself. This is
138 a copy of INSN_MO->match with the operands filled in. If we have
139 decided to use an extended MIPS16 instruction, this includes the
141 unsigned long insn_opcode;
143 /* The frag that contains the instruction. */
146 /* The offset into FRAG of the first instruction byte. */
149 /* The relocs associated with the instruction, if any. */
152 /* True if this entry cannot be moved from its current position. */
153 unsigned int fixed_p : 1;
155 /* True if this instruction occurred in a .set noreorder block. */
156 unsigned int noreorder_p : 1;
158 /* True for mips16 instructions that jump to an absolute address. */
159 unsigned int mips16_absolute_jump_p : 1;
161 /* True if this instruction is complete. */
162 unsigned int complete_p : 1;
164 /* True if this instruction is cleared from history by unconditional
166 unsigned int cleared_p : 1;
169 /* The ABI to use. */
180 /* MIPS ABI we are using for this output file. */
181 static enum mips_abi_level mips_abi = NO_ABI;
183 /* Whether or not we have code that can call pic code. */
184 int mips_abicalls = FALSE;
186 /* Whether or not we have code which can be put into a shared
188 static bfd_boolean mips_in_shared = TRUE;
190 /* This is the set of options which may be modified by the .set
191 pseudo-op. We use a struct so that .set push and .set pop are more
194 struct mips_set_options
196 /* MIPS ISA (Instruction Set Architecture) level. This is set to -1
197 if it has not been initialized. Changed by `.set mipsN', and the
198 -mipsN command line option, and the default CPU. */
200 /* Enabled Application Specific Extensions (ASEs). Changed by `.set
201 <asename>', by command line options, and based on the default
204 /* Whether we are assembling for the mips16 processor. 0 if we are
205 not, 1 if we are, and -1 if the value has not been initialized.
206 Changed by `.set mips16' and `.set nomips16', and the -mips16 and
207 -nomips16 command line options, and the default CPU. */
209 /* Whether we are assembling for the mipsMIPS ASE. 0 if we are not,
210 1 if we are, and -1 if the value has not been initialized. Changed
211 by `.set micromips' and `.set nomicromips', and the -mmicromips
212 and -mno-micromips command line options, and the default CPU. */
214 /* Non-zero if we should not reorder instructions. Changed by `.set
215 reorder' and `.set noreorder'. */
217 /* Non-zero if we should not permit the register designated "assembler
218 temporary" to be used in instructions. The value is the register
219 number, normally $at ($1). Changed by `.set at=REG', `.set noat'
220 (same as `.set at=$0') and `.set at' (same as `.set at=$1'). */
222 /* Non-zero if we should warn when a macro instruction expands into
223 more than one machine instruction. Changed by `.set nomacro' and
225 int warn_about_macros;
226 /* Non-zero if we should not move instructions. Changed by `.set
227 move', `.set volatile', `.set nomove', and `.set novolatile'. */
229 /* Non-zero if we should not optimize branches by moving the target
230 of the branch into the delay slot. Actually, we don't perform
231 this optimization anyhow. Changed by `.set bopt' and `.set
234 /* Non-zero if we should not autoextend mips16 instructions.
235 Changed by `.set autoextend' and `.set noautoextend'. */
237 /* True if we should only emit 32-bit microMIPS instructions.
238 Changed by `.set insn32' and `.set noinsn32', and the -minsn32
239 and -mno-insn32 command line options. */
241 /* Restrict general purpose registers and floating point registers
242 to 32 bit. This is initially determined when -mgp32 or -mfp32
243 is passed but can changed if the assembler code uses .set mipsN. */
246 /* MIPS architecture (CPU) type. Changed by .set arch=FOO, the -march
247 command line option, and the default CPU. */
249 /* True if ".set sym32" is in effect. */
251 /* True if floating-point operations are not allowed. Changed by .set
252 softfloat or .set hardfloat, by command line options -msoft-float or
253 -mhard-float. The default is false. */
254 bfd_boolean soft_float;
256 /* True if only single-precision floating-point operations are allowed.
257 Changed by .set singlefloat or .set doublefloat, command-line options
258 -msingle-float or -mdouble-float. The default is false. */
259 bfd_boolean single_float;
262 /* This is the struct we use to hold the current set of options. Note
263 that we must set the isa field to ISA_UNKNOWN and the ASE fields to
264 -1 to indicate that they have not been initialized. */
266 /* True if -mgp32 was passed. */
267 static int file_mips_gp32 = -1;
269 /* True if -mfp32 was passed. */
270 static int file_mips_fp32 = -1;
272 /* 1 if -msoft-float, 0 if -mhard-float. The default is 0. */
273 static int file_mips_soft_float = 0;
275 /* 1 if -msingle-float, 0 if -mdouble-float. The default is 0. */
276 static int file_mips_single_float = 0;
278 /* True if -mnan=2008, false if -mnan=legacy. */
279 static bfd_boolean mips_flag_nan2008 = FALSE;
281 static struct mips_set_options mips_opts =
283 /* isa */ ISA_UNKNOWN, /* ase */ 0, /* mips16 */ -1, /* micromips */ -1,
284 /* noreorder */ 0, /* at */ ATREG, /* warn_about_macros */ 0,
285 /* nomove */ 0, /* nobopt */ 0, /* noautoextend */ 0, /* insn32 */ FALSE,
286 /* gp32 */ 0, /* fp32 */ 0, /* arch */ CPU_UNKNOWN, /* sym32 */ FALSE,
287 /* soft_float */ FALSE, /* single_float */ FALSE
290 /* The set of ASEs that were selected on the command line, either
291 explicitly via ASE options or implicitly through things like -march. */
292 static unsigned int file_ase;
294 /* Which bits of file_ase were explicitly set or cleared by ASE options. */
295 static unsigned int file_ase_explicit;
297 /* These variables are filled in with the masks of registers used.
298 The object format code reads them and puts them in the appropriate
300 unsigned long mips_gprmask;
301 unsigned long mips_cprmask[4];
303 /* MIPS ISA we are using for this output file. */
304 static int file_mips_isa = ISA_UNKNOWN;
306 /* True if any MIPS16 code was produced. */
307 static int file_ase_mips16;
309 #define ISA_SUPPORTS_MIPS16E (mips_opts.isa == ISA_MIPS32 \
310 || mips_opts.isa == ISA_MIPS32R2 \
311 || mips_opts.isa == ISA_MIPS64 \
312 || mips_opts.isa == ISA_MIPS64R2)
314 /* True if any microMIPS code was produced. */
315 static int file_ase_micromips;
317 /* True if we want to create R_MIPS_JALR for jalr $25. */
319 #define MIPS_JALR_HINT_P(EXPR) HAVE_NEWABI
321 /* As a GNU extension, we use R_MIPS_JALR for o32 too. However,
322 because there's no place for any addend, the only acceptable
323 expression is a bare symbol. */
324 #define MIPS_JALR_HINT_P(EXPR) \
325 (!HAVE_IN_PLACE_ADDENDS \
326 || ((EXPR)->X_op == O_symbol && (EXPR)->X_add_number == 0))
329 /* The argument of the -march= flag. The architecture we are assembling. */
330 static int file_mips_arch = CPU_UNKNOWN;
331 static const char *mips_arch_string;
333 /* The argument of the -mtune= flag. The architecture for which we
335 static int mips_tune = CPU_UNKNOWN;
336 static const char *mips_tune_string;
338 /* True when generating 32-bit code for a 64-bit processor. */
339 static int mips_32bitmode = 0;
341 /* True if the given ABI requires 32-bit registers. */
342 #define ABI_NEEDS_32BIT_REGS(ABI) ((ABI) == O32_ABI)
344 /* Likewise 64-bit registers. */
345 #define ABI_NEEDS_64BIT_REGS(ABI) \
347 || (ABI) == N64_ABI \
350 /* Return true if ISA supports 64 bit wide gp registers. */
351 #define ISA_HAS_64BIT_REGS(ISA) \
352 ((ISA) == ISA_MIPS3 \
353 || (ISA) == ISA_MIPS4 \
354 || (ISA) == ISA_MIPS5 \
355 || (ISA) == ISA_MIPS64 \
356 || (ISA) == ISA_MIPS64R2)
358 /* Return true if ISA supports 64 bit wide float registers. */
359 #define ISA_HAS_64BIT_FPRS(ISA) \
360 ((ISA) == ISA_MIPS3 \
361 || (ISA) == ISA_MIPS4 \
362 || (ISA) == ISA_MIPS5 \
363 || (ISA) == ISA_MIPS32R2 \
364 || (ISA) == ISA_MIPS64 \
365 || (ISA) == ISA_MIPS64R2)
367 /* Return true if ISA supports 64-bit right rotate (dror et al.)
369 #define ISA_HAS_DROR(ISA) \
370 ((ISA) == ISA_MIPS64R2 \
371 || (mips_opts.micromips \
372 && ISA_HAS_64BIT_REGS (ISA)) \
375 /* Return true if ISA supports 32-bit right rotate (ror et al.)
377 #define ISA_HAS_ROR(ISA) \
378 ((ISA) == ISA_MIPS32R2 \
379 || (ISA) == ISA_MIPS64R2 \
380 || (mips_opts.ase & ASE_SMARTMIPS) \
381 || mips_opts.micromips \
384 /* Return true if ISA supports single-precision floats in odd registers. */
385 #define ISA_HAS_ODD_SINGLE_FPR(ISA) \
386 ((ISA) == ISA_MIPS32 \
387 || (ISA) == ISA_MIPS32R2 \
388 || (ISA) == ISA_MIPS64 \
389 || (ISA) == ISA_MIPS64R2)
391 /* Return true if ISA supports move to/from high part of a 64-bit
392 floating-point register. */
393 #define ISA_HAS_MXHC1(ISA) \
394 ((ISA) == ISA_MIPS32R2 \
395 || (ISA) == ISA_MIPS64R2)
397 #define HAVE_32BIT_GPRS \
398 (mips_opts.gp32 || !ISA_HAS_64BIT_REGS (mips_opts.isa))
400 #define HAVE_32BIT_FPRS \
401 (mips_opts.fp32 || !ISA_HAS_64BIT_FPRS (mips_opts.isa))
403 #define HAVE_64BIT_GPRS (!HAVE_32BIT_GPRS)
404 #define HAVE_64BIT_FPRS (!HAVE_32BIT_FPRS)
406 #define HAVE_NEWABI (mips_abi == N32_ABI || mips_abi == N64_ABI)
408 #define HAVE_64BIT_OBJECTS (mips_abi == N64_ABI)
410 /* True if relocations are stored in-place. */
411 #define HAVE_IN_PLACE_ADDENDS (!HAVE_NEWABI)
413 /* The ABI-derived address size. */
414 #define HAVE_64BIT_ADDRESSES \
415 (HAVE_64BIT_GPRS && (mips_abi == EABI_ABI || mips_abi == N64_ABI))
416 #define HAVE_32BIT_ADDRESSES (!HAVE_64BIT_ADDRESSES)
418 /* The size of symbolic constants (i.e., expressions of the form
419 "SYMBOL" or "SYMBOL + OFFSET"). */
420 #define HAVE_32BIT_SYMBOLS \
421 (HAVE_32BIT_ADDRESSES || !HAVE_64BIT_OBJECTS || mips_opts.sym32)
422 #define HAVE_64BIT_SYMBOLS (!HAVE_32BIT_SYMBOLS)
424 /* Addresses are loaded in different ways, depending on the address size
425 in use. The n32 ABI Documentation also mandates the use of additions
426 with overflow checking, but existing implementations don't follow it. */
427 #define ADDRESS_ADD_INSN \
428 (HAVE_32BIT_ADDRESSES ? "addu" : "daddu")
430 #define ADDRESS_ADDI_INSN \
431 (HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu")
433 #define ADDRESS_LOAD_INSN \
434 (HAVE_32BIT_ADDRESSES ? "lw" : "ld")
436 #define ADDRESS_STORE_INSN \
437 (HAVE_32BIT_ADDRESSES ? "sw" : "sd")
439 /* Return true if the given CPU supports the MIPS16 ASE. */
440 #define CPU_HAS_MIPS16(cpu) \
441 (strncmp (TARGET_CPU, "mips16", sizeof ("mips16") - 1) == 0 \
442 || strncmp (TARGET_CANONICAL, "mips-lsi-elf", sizeof ("mips-lsi-elf") - 1) == 0)
444 /* Return true if the given CPU supports the microMIPS ASE. */
445 #define CPU_HAS_MICROMIPS(cpu) 0
447 /* True if CPU has a dror instruction. */
448 #define CPU_HAS_DROR(CPU) ((CPU) == CPU_VR5400 || (CPU) == CPU_VR5500)
450 /* True if CPU has a ror instruction. */
451 #define CPU_HAS_ROR(CPU) CPU_HAS_DROR (CPU)
453 /* True if CPU is in the Octeon family */
454 #define CPU_IS_OCTEON(CPU) ((CPU) == CPU_OCTEON || (CPU) == CPU_OCTEONP || (CPU) == CPU_OCTEON2)
456 /* True if CPU has seq/sne and seqi/snei instructions. */
457 #define CPU_HAS_SEQ(CPU) (CPU_IS_OCTEON (CPU))
459 /* True, if CPU has support for ldc1 and sdc1. */
460 #define CPU_HAS_LDC1_SDC1(CPU) \
461 ((mips_opts.isa != ISA_MIPS1) && ((CPU) != CPU_R5900))
463 /* True if mflo and mfhi can be immediately followed by instructions
464 which write to the HI and LO registers.
466 According to MIPS specifications, MIPS ISAs I, II, and III need
467 (at least) two instructions between the reads of HI/LO and
468 instructions which write them, and later ISAs do not. Contradicting
469 the MIPS specifications, some MIPS IV processor user manuals (e.g.
470 the UM for the NEC Vr5000) document needing the instructions between
471 HI/LO reads and writes, as well. Therefore, we declare only MIPS32,
472 MIPS64 and later ISAs to have the interlocks, plus any specific
473 earlier-ISA CPUs for which CPU documentation declares that the
474 instructions are really interlocked. */
475 #define hilo_interlocks \
476 (mips_opts.isa == ISA_MIPS32 \
477 || mips_opts.isa == ISA_MIPS32R2 \
478 || mips_opts.isa == ISA_MIPS64 \
479 || mips_opts.isa == ISA_MIPS64R2 \
480 || mips_opts.arch == CPU_R4010 \
481 || mips_opts.arch == CPU_R5900 \
482 || mips_opts.arch == CPU_R10000 \
483 || mips_opts.arch == CPU_R12000 \
484 || mips_opts.arch == CPU_R14000 \
485 || mips_opts.arch == CPU_R16000 \
486 || mips_opts.arch == CPU_RM7000 \
487 || mips_opts.arch == CPU_VR5500 \
488 || mips_opts.micromips \
491 /* Whether the processor uses hardware interlocks to protect reads
492 from the GPRs after they are loaded from memory, and thus does not
493 require nops to be inserted. This applies to instructions marked
494 INSN_LOAD_MEMORY_DELAY. These nops are only required at MIPS ISA
495 level I and microMIPS mode instructions are always interlocked. */
496 #define gpr_interlocks \
497 (mips_opts.isa != ISA_MIPS1 \
498 || mips_opts.arch == CPU_R3900 \
499 || mips_opts.arch == CPU_R5900 \
500 || mips_opts.micromips \
503 /* Whether the processor uses hardware interlocks to avoid delays
504 required by coprocessor instructions, and thus does not require
505 nops to be inserted. This applies to instructions marked
506 INSN_LOAD_COPROC_DELAY, INSN_COPROC_MOVE_DELAY, and to delays
507 between instructions marked INSN_WRITE_COND_CODE and ones marked
508 INSN_READ_COND_CODE. These nops are only required at MIPS ISA
509 levels I, II, and III and microMIPS mode instructions are always
511 /* Itbl support may require additional care here. */
512 #define cop_interlocks \
513 ((mips_opts.isa != ISA_MIPS1 \
514 && mips_opts.isa != ISA_MIPS2 \
515 && mips_opts.isa != ISA_MIPS3) \
516 || mips_opts.arch == CPU_R4300 \
517 || mips_opts.micromips \
520 /* Whether the processor uses hardware interlocks to protect reads
521 from coprocessor registers after they are loaded from memory, and
522 thus does not require nops to be inserted. This applies to
523 instructions marked INSN_COPROC_MEMORY_DELAY. These nops are only
524 requires at MIPS ISA level I and microMIPS mode instructions are
525 always interlocked. */
526 #define cop_mem_interlocks \
527 (mips_opts.isa != ISA_MIPS1 \
528 || mips_opts.micromips \
531 /* Is this a mfhi or mflo instruction? */
532 #define MF_HILO_INSN(PINFO) \
533 ((PINFO & INSN_READ_HI) || (PINFO & INSN_READ_LO))
535 /* Whether code compression (either of the MIPS16 or the microMIPS ASEs)
536 has been selected. This implies, in particular, that addresses of text
537 labels have their LSB set. */
538 #define HAVE_CODE_COMPRESSION \
539 ((mips_opts.mips16 | mips_opts.micromips) != 0)
541 /* The minimum and maximum signed values that can be stored in a GPR. */
542 #define GPR_SMAX ((offsetT) (((valueT) 1 << (HAVE_64BIT_GPRS ? 63 : 31)) - 1))
543 #define GPR_SMIN (-GPR_SMAX - 1)
545 /* MIPS PIC level. */
547 enum mips_pic_level mips_pic;
549 /* 1 if we should generate 32 bit offsets from the $gp register in
550 SVR4_PIC mode. Currently has no meaning in other modes. */
551 static int mips_big_got = 0;
553 /* 1 if trap instructions should used for overflow rather than break
555 static int mips_trap = 0;
557 /* 1 if double width floating point constants should not be constructed
558 by assembling two single width halves into two single width floating
559 point registers which just happen to alias the double width destination
560 register. On some architectures this aliasing can be disabled by a bit
561 in the status register, and the setting of this bit cannot be determined
562 automatically at assemble time. */
563 static int mips_disable_float_construction;
565 /* Non-zero if any .set noreorder directives were used. */
567 static int mips_any_noreorder;
569 /* Non-zero if nops should be inserted when the register referenced in
570 an mfhi/mflo instruction is read in the next two instructions. */
571 static int mips_7000_hilo_fix;
573 /* The size of objects in the small data section. */
574 static unsigned int g_switch_value = 8;
575 /* Whether the -G option was used. */
576 static int g_switch_seen = 0;
581 /* If we can determine in advance that GP optimization won't be
582 possible, we can skip the relaxation stuff that tries to produce
583 GP-relative references. This makes delay slot optimization work
586 This function can only provide a guess, but it seems to work for
587 gcc output. It needs to guess right for gcc, otherwise gcc
588 will put what it thinks is a GP-relative instruction in a branch
591 I don't know if a fix is needed for the SVR4_PIC mode. I've only
592 fixed it for the non-PIC mode. KR 95/04/07 */
593 static int nopic_need_relax (symbolS *, int);
595 /* handle of the OPCODE hash table */
596 static struct hash_control *op_hash = NULL;
598 /* The opcode hash table we use for the mips16. */
599 static struct hash_control *mips16_op_hash = NULL;
601 /* The opcode hash table we use for the microMIPS ASE. */
602 static struct hash_control *micromips_op_hash = NULL;
604 /* This array holds the chars that always start a comment. If the
605 pre-processor is disabled, these aren't very useful */
606 const char comment_chars[] = "#";
608 /* This array holds the chars that only start a comment at the beginning of
609 a line. If the line seems to have the form '# 123 filename'
610 .line and .file directives will appear in the pre-processed output */
611 /* Note that input_file.c hand checks for '#' at the beginning of the
612 first line of the input file. This is because the compiler outputs
613 #NO_APP at the beginning of its output. */
614 /* Also note that C style comments are always supported. */
615 const char line_comment_chars[] = "#";
617 /* This array holds machine specific line separator characters. */
618 const char line_separator_chars[] = ";";
620 /* Chars that can be used to separate mant from exp in floating point nums */
621 const char EXP_CHARS[] = "eE";
623 /* Chars that mean this number is a floating point constant */
626 const char FLT_CHARS[] = "rRsSfFdDxXpP";
628 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
629 changed in read.c . Ideally it shouldn't have to know about it at all,
630 but nothing is ideal around here.
633 static char *insn_error;
635 static int auto_align = 1;
637 /* When outputting SVR4 PIC code, the assembler needs to know the
638 offset in the stack frame from which to restore the $gp register.
639 This is set by the .cprestore pseudo-op, and saved in this
641 static offsetT mips_cprestore_offset = -1;
643 /* Similar for NewABI PIC code, where $gp is callee-saved. NewABI has some
644 more optimizations, it can use a register value instead of a memory-saved
645 offset and even an other register than $gp as global pointer. */
646 static offsetT mips_cpreturn_offset = -1;
647 static int mips_cpreturn_register = -1;
648 static int mips_gp_register = GP;
649 static int mips_gprel_offset = 0;
651 /* Whether mips_cprestore_offset has been set in the current function
652 (or whether it has already been warned about, if not). */
653 static int mips_cprestore_valid = 0;
655 /* This is the register which holds the stack frame, as set by the
656 .frame pseudo-op. This is needed to implement .cprestore. */
657 static int mips_frame_reg = SP;
659 /* Whether mips_frame_reg has been set in the current function
660 (or whether it has already been warned about, if not). */
661 static int mips_frame_reg_valid = 0;
663 /* To output NOP instructions correctly, we need to keep information
664 about the previous two instructions. */
666 /* Whether we are optimizing. The default value of 2 means to remove
667 unneeded NOPs and swap branch instructions when possible. A value
668 of 1 means to not swap branches. A value of 0 means to always
670 static int mips_optimize = 2;
672 /* Debugging level. -g sets this to 2. -gN sets this to N. -g0 is
673 equivalent to seeing no -g option at all. */
674 static int mips_debug = 0;
676 /* The maximum number of NOPs needed to avoid the VR4130 mflo/mfhi errata. */
677 #define MAX_VR4130_NOPS 4
679 /* The maximum number of NOPs needed to fill delay slots. */
680 #define MAX_DELAY_NOPS 2
682 /* The maximum number of NOPs needed for any purpose. */
685 /* A list of previous instructions, with index 0 being the most recent.
686 We need to look back MAX_NOPS instructions when filling delay slots
687 or working around processor errata. We need to look back one
688 instruction further if we're thinking about using history[0] to
689 fill a branch delay slot. */
690 static struct mips_cl_insn history[1 + MAX_NOPS];
692 /* Nop instructions used by emit_nop. */
693 static struct mips_cl_insn nop_insn;
694 static struct mips_cl_insn mips16_nop_insn;
695 static struct mips_cl_insn micromips_nop16_insn;
696 static struct mips_cl_insn micromips_nop32_insn;
698 /* The appropriate nop for the current mode. */
699 #define NOP_INSN (mips_opts.mips16 \
701 : (mips_opts.micromips \
702 ? (mips_opts.insn32 \
703 ? µmips_nop32_insn \
704 : µmips_nop16_insn) \
707 /* The size of NOP_INSN in bytes. */
708 #define NOP_INSN_SIZE ((mips_opts.mips16 \
709 || (mips_opts.micromips && !mips_opts.insn32)) \
712 /* If this is set, it points to a frag holding nop instructions which
713 were inserted before the start of a noreorder section. If those
714 nops turn out to be unnecessary, the size of the frag can be
716 static fragS *prev_nop_frag;
718 /* The number of nop instructions we created in prev_nop_frag. */
719 static int prev_nop_frag_holds;
721 /* The number of nop instructions that we know we need in
723 static int prev_nop_frag_required;
725 /* The number of instructions we've seen since prev_nop_frag. */
726 static int prev_nop_frag_since;
728 /* Relocations against symbols are sometimes done in two parts, with a HI
729 relocation and a LO relocation. Each relocation has only 16 bits of
730 space to store an addend. This means that in order for the linker to
731 handle carries correctly, it must be able to locate both the HI and
732 the LO relocation. This means that the relocations must appear in
733 order in the relocation table.
735 In order to implement this, we keep track of each unmatched HI
736 relocation. We then sort them so that they immediately precede the
737 corresponding LO relocation. */
742 struct mips_hi_fixup *next;
745 /* The section this fixup is in. */
749 /* The list of unmatched HI relocs. */
751 static struct mips_hi_fixup *mips_hi_fixup_list;
753 /* The frag containing the last explicit relocation operator.
754 Null if explicit relocations have not been used. */
756 static fragS *prev_reloc_op_frag;
758 /* Map mips16 register numbers to normal MIPS register numbers. */
760 static const unsigned int mips16_to_32_reg_map[] =
762 16, 17, 2, 3, 4, 5, 6, 7
765 /* Map microMIPS register numbers to normal MIPS register numbers. */
767 #define micromips_to_32_reg_b_map mips16_to_32_reg_map
768 #define micromips_to_32_reg_c_map mips16_to_32_reg_map
769 #define micromips_to_32_reg_d_map mips16_to_32_reg_map
770 #define micromips_to_32_reg_e_map mips16_to_32_reg_map
771 #define micromips_to_32_reg_f_map mips16_to_32_reg_map
772 #define micromips_to_32_reg_g_map mips16_to_32_reg_map
774 /* The microMIPS registers with type h. */
775 static const unsigned int micromips_to_32_reg_h_map1[] =
777 5, 5, 6, 4, 4, 4, 4, 4
779 static const unsigned int micromips_to_32_reg_h_map2[] =
781 6, 7, 7, 21, 22, 5, 6, 7
784 #define micromips_to_32_reg_l_map mips16_to_32_reg_map
786 /* The microMIPS registers with type m. */
787 static const unsigned int micromips_to_32_reg_m_map[] =
789 0, 17, 2, 3, 16, 18, 19, 20
792 #define micromips_to_32_reg_n_map micromips_to_32_reg_m_map
794 /* The microMIPS registers with type q. */
795 static const unsigned int micromips_to_32_reg_q_map[] =
797 0, 17, 2, 3, 4, 5, 6, 7
800 /* Classifies the kind of instructions we're interested in when
801 implementing -mfix-vr4120. */
802 enum fix_vr4120_class
810 NUM_FIX_VR4120_CLASSES
813 /* ...likewise -mfix-loongson2f-jump. */
814 static bfd_boolean mips_fix_loongson2f_jump;
816 /* ...likewise -mfix-loongson2f-nop. */
817 static bfd_boolean mips_fix_loongson2f_nop;
819 /* True if -mfix-loongson2f-nop or -mfix-loongson2f-jump passed. */
820 static bfd_boolean mips_fix_loongson2f;
822 /* Given two FIX_VR4120_* values X and Y, bit Y of element X is set if
823 there must be at least one other instruction between an instruction
824 of type X and an instruction of type Y. */
825 static unsigned int vr4120_conflicts[NUM_FIX_VR4120_CLASSES];
827 /* True if -mfix-vr4120 is in force. */
828 static int mips_fix_vr4120;
830 /* ...likewise -mfix-vr4130. */
831 static int mips_fix_vr4130;
833 /* ...likewise -mfix-24k. */
834 static int mips_fix_24k;
836 /* ...likewise -mfix-cn63xxp1 */
837 static bfd_boolean mips_fix_cn63xxp1;
839 /* We don't relax branches by default, since this causes us to expand
840 `la .l2 - .l1' if there's a branch between .l1 and .l2, because we
841 fail to compute the offset before expanding the macro to the most
842 efficient expansion. */
844 static int mips_relax_branch;
846 /* The expansion of many macros depends on the type of symbol that
847 they refer to. For example, when generating position-dependent code,
848 a macro that refers to a symbol may have two different expansions,
849 one which uses GP-relative addresses and one which uses absolute
850 addresses. When generating SVR4-style PIC, a macro may have
851 different expansions for local and global symbols.
853 We handle these situations by generating both sequences and putting
854 them in variant frags. In position-dependent code, the first sequence
855 will be the GP-relative one and the second sequence will be the
856 absolute one. In SVR4 PIC, the first sequence will be for global
857 symbols and the second will be for local symbols.
859 The frag's "subtype" is RELAX_ENCODE (FIRST, SECOND), where FIRST and
860 SECOND are the lengths of the two sequences in bytes. These fields
861 can be extracted using RELAX_FIRST() and RELAX_SECOND(). In addition,
862 the subtype has the following flags:
865 Set if it has been decided that we should use the second
866 sequence instead of the first.
869 Set in the first variant frag if the macro's second implementation
870 is longer than its first. This refers to the macro as a whole,
871 not an individual relaxation.
874 Set in the first variant frag if the macro appeared in a .set nomacro
875 block and if one alternative requires a warning but the other does not.
878 Like RELAX_NOMACRO, but indicates that the macro appears in a branch
881 RELAX_DELAY_SLOT_16BIT
882 Like RELAX_DELAY_SLOT, but indicates that the delay slot requires a
885 RELAX_DELAY_SLOT_SIZE_FIRST
886 Like RELAX_DELAY_SLOT, but indicates that the first implementation of
887 the macro is of the wrong size for the branch delay slot.
889 RELAX_DELAY_SLOT_SIZE_SECOND
890 Like RELAX_DELAY_SLOT, but indicates that the second implementation of
891 the macro is of the wrong size for the branch delay slot.
893 The frag's "opcode" points to the first fixup for relaxable code.
895 Relaxable macros are generated using a sequence such as:
897 relax_start (SYMBOL);
898 ... generate first expansion ...
900 ... generate second expansion ...
903 The code and fixups for the unwanted alternative are discarded
904 by md_convert_frag. */
905 #define RELAX_ENCODE(FIRST, SECOND) (((FIRST) << 8) | (SECOND))
907 #define RELAX_FIRST(X) (((X) >> 8) & 0xff)
908 #define RELAX_SECOND(X) ((X) & 0xff)
909 #define RELAX_USE_SECOND 0x10000
910 #define RELAX_SECOND_LONGER 0x20000
911 #define RELAX_NOMACRO 0x40000
912 #define RELAX_DELAY_SLOT 0x80000
913 #define RELAX_DELAY_SLOT_16BIT 0x100000
914 #define RELAX_DELAY_SLOT_SIZE_FIRST 0x200000
915 #define RELAX_DELAY_SLOT_SIZE_SECOND 0x400000
917 /* Branch without likely bit. If label is out of range, we turn:
919 beq reg1, reg2, label
929 with the following opcode replacements:
936 bltzal <-> bgezal (with jal label instead of j label)
938 Even though keeping the delay slot instruction in the delay slot of
939 the branch would be more efficient, it would be very tricky to do
940 correctly, because we'd have to introduce a variable frag *after*
941 the delay slot instruction, and expand that instead. Let's do it
942 the easy way for now, even if the branch-not-taken case now costs
943 one additional instruction. Out-of-range branches are not supposed
944 to be common, anyway.
946 Branch likely. If label is out of range, we turn:
948 beql reg1, reg2, label
949 delay slot (annulled if branch not taken)
958 delay slot (executed only if branch taken)
961 It would be possible to generate a shorter sequence by losing the
962 likely bit, generating something like:
967 delay slot (executed only if branch taken)
979 bltzall -> bgezal (with jal label instead of j label)
980 bgezall -> bltzal (ditto)
983 but it's not clear that it would actually improve performance. */
984 #define RELAX_BRANCH_ENCODE(at, uncond, likely, link, toofar) \
988 | ((toofar) ? 0x20 : 0) \
989 | ((link) ? 0x40 : 0) \
990 | ((likely) ? 0x80 : 0) \
991 | ((uncond) ? 0x100 : 0)))
992 #define RELAX_BRANCH_P(i) (((i) & 0xf0000000) == 0xc0000000)
993 #define RELAX_BRANCH_UNCOND(i) (((i) & 0x100) != 0)
994 #define RELAX_BRANCH_LIKELY(i) (((i) & 0x80) != 0)
995 #define RELAX_BRANCH_LINK(i) (((i) & 0x40) != 0)
996 #define RELAX_BRANCH_TOOFAR(i) (((i) & 0x20) != 0)
997 #define RELAX_BRANCH_AT(i) ((i) & 0x1f)
999 /* For mips16 code, we use an entirely different form of relaxation.
1000 mips16 supports two versions of most instructions which take
1001 immediate values: a small one which takes some small value, and a
1002 larger one which takes a 16 bit value. Since branches also follow
1003 this pattern, relaxing these values is required.
1005 We can assemble both mips16 and normal MIPS code in a single
1006 object. Therefore, we need to support this type of relaxation at
1007 the same time that we support the relaxation described above. We
1008 use the high bit of the subtype field to distinguish these cases.
1010 The information we store for this type of relaxation is the
1011 argument code found in the opcode file for this relocation, whether
1012 the user explicitly requested a small or extended form, and whether
1013 the relocation is in a jump or jal delay slot. That tells us the
1014 size of the value, and how it should be stored. We also store
1015 whether the fragment is considered to be extended or not. We also
1016 store whether this is known to be a branch to a different section,
1017 whether we have tried to relax this frag yet, and whether we have
1018 ever extended a PC relative fragment because of a shift count. */
1019 #define RELAX_MIPS16_ENCODE(type, small, ext, dslot, jal_dslot) \
1022 | ((small) ? 0x100 : 0) \
1023 | ((ext) ? 0x200 : 0) \
1024 | ((dslot) ? 0x400 : 0) \
1025 | ((jal_dslot) ? 0x800 : 0))
1026 #define RELAX_MIPS16_P(i) (((i) & 0xc0000000) == 0x80000000)
1027 #define RELAX_MIPS16_TYPE(i) ((i) & 0xff)
1028 #define RELAX_MIPS16_USER_SMALL(i) (((i) & 0x100) != 0)
1029 #define RELAX_MIPS16_USER_EXT(i) (((i) & 0x200) != 0)
1030 #define RELAX_MIPS16_DSLOT(i) (((i) & 0x400) != 0)
1031 #define RELAX_MIPS16_JAL_DSLOT(i) (((i) & 0x800) != 0)
1032 #define RELAX_MIPS16_EXTENDED(i) (((i) & 0x1000) != 0)
1033 #define RELAX_MIPS16_MARK_EXTENDED(i) ((i) | 0x1000)
1034 #define RELAX_MIPS16_CLEAR_EXTENDED(i) ((i) &~ 0x1000)
1035 #define RELAX_MIPS16_LONG_BRANCH(i) (((i) & 0x2000) != 0)
1036 #define RELAX_MIPS16_MARK_LONG_BRANCH(i) ((i) | 0x2000)
1037 #define RELAX_MIPS16_CLEAR_LONG_BRANCH(i) ((i) &~ 0x2000)
1039 /* For microMIPS code, we use relaxation similar to one we use for
1040 MIPS16 code. Some instructions that take immediate values support
1041 two encodings: a small one which takes some small value, and a
1042 larger one which takes a 16 bit value. As some branches also follow
1043 this pattern, relaxing these values is required.
1045 We can assemble both microMIPS and normal MIPS code in a single
1046 object. Therefore, we need to support this type of relaxation at
1047 the same time that we support the relaxation described above. We
1048 use one of the high bits of the subtype field to distinguish these
1051 The information we store for this type of relaxation is the argument
1052 code found in the opcode file for this relocation, the register
1053 selected as the assembler temporary, whether the branch is
1054 unconditional, whether it is compact, whether it stores the link
1055 address implicitly in $ra, whether relaxation of out-of-range 32-bit
1056 branches to a sequence of instructions is enabled, and whether the
1057 displacement of a branch is too large to fit as an immediate argument
1058 of a 16-bit and a 32-bit branch, respectively. */
1059 #define RELAX_MICROMIPS_ENCODE(type, at, uncond, compact, link, \
1060 relax32, toofar16, toofar32) \
1063 | (((at) & 0x1f) << 8) \
1064 | ((uncond) ? 0x2000 : 0) \
1065 | ((compact) ? 0x4000 : 0) \
1066 | ((link) ? 0x8000 : 0) \
1067 | ((relax32) ? 0x10000 : 0) \
1068 | ((toofar16) ? 0x20000 : 0) \
1069 | ((toofar32) ? 0x40000 : 0))
1070 #define RELAX_MICROMIPS_P(i) (((i) & 0xc0000000) == 0x40000000)
1071 #define RELAX_MICROMIPS_TYPE(i) ((i) & 0xff)
1072 #define RELAX_MICROMIPS_AT(i) (((i) >> 8) & 0x1f)
1073 #define RELAX_MICROMIPS_UNCOND(i) (((i) & 0x2000) != 0)
1074 #define RELAX_MICROMIPS_COMPACT(i) (((i) & 0x4000) != 0)
1075 #define RELAX_MICROMIPS_LINK(i) (((i) & 0x8000) != 0)
1076 #define RELAX_MICROMIPS_RELAX32(i) (((i) & 0x10000) != 0)
1078 #define RELAX_MICROMIPS_TOOFAR16(i) (((i) & 0x20000) != 0)
1079 #define RELAX_MICROMIPS_MARK_TOOFAR16(i) ((i) | 0x20000)
1080 #define RELAX_MICROMIPS_CLEAR_TOOFAR16(i) ((i) & ~0x20000)
1081 #define RELAX_MICROMIPS_TOOFAR32(i) (((i) & 0x40000) != 0)
1082 #define RELAX_MICROMIPS_MARK_TOOFAR32(i) ((i) | 0x40000)
1083 #define RELAX_MICROMIPS_CLEAR_TOOFAR32(i) ((i) & ~0x40000)
1085 /* Sign-extend 16-bit value X. */
1086 #define SEXT_16BIT(X) ((((X) + 0x8000) & 0xffff) - 0x8000)
1088 /* Is the given value a sign-extended 32-bit value? */
1089 #define IS_SEXT_32BIT_NUM(x) \
1090 (((x) &~ (offsetT) 0x7fffffff) == 0 \
1091 || (((x) &~ (offsetT) 0x7fffffff) == ~ (offsetT) 0x7fffffff))
1093 /* Is the given value a sign-extended 16-bit value? */
1094 #define IS_SEXT_16BIT_NUM(x) \
1095 (((x) &~ (offsetT) 0x7fff) == 0 \
1096 || (((x) &~ (offsetT) 0x7fff) == ~ (offsetT) 0x7fff))
1098 /* Is the given value a sign-extended 12-bit value? */
1099 #define IS_SEXT_12BIT_NUM(x) \
1100 (((((x) & 0xfff) ^ 0x800LL) - 0x800LL) == (x))
1102 /* Is the given value a sign-extended 9-bit value? */
1103 #define IS_SEXT_9BIT_NUM(x) \
1104 (((((x) & 0x1ff) ^ 0x100LL) - 0x100LL) == (x))
1106 /* Is the given value a zero-extended 32-bit value? Or a negated one? */
1107 #define IS_ZEXT_32BIT_NUM(x) \
1108 (((x) &~ (offsetT) 0xffffffff) == 0 \
1109 || (((x) &~ (offsetT) 0xffffffff) == ~ (offsetT) 0xffffffff))
1111 /* Extract bits MASK << SHIFT from STRUCT and shift them right
1113 #define EXTRACT_BITS(STRUCT, MASK, SHIFT) \
1114 (((STRUCT) >> (SHIFT)) & (MASK))
1116 /* Extract the operand given by FIELD from mips_cl_insn INSN. */
1117 #define EXTRACT_OPERAND(MICROMIPS, FIELD, INSN) \
1119 ? EXTRACT_BITS ((INSN).insn_opcode, OP_MASK_##FIELD, OP_SH_##FIELD) \
1120 : EXTRACT_BITS ((INSN).insn_opcode, \
1121 MICROMIPSOP_MASK_##FIELD, MICROMIPSOP_SH_##FIELD))
1122 #define MIPS16_EXTRACT_OPERAND(FIELD, INSN) \
1123 EXTRACT_BITS ((INSN).insn_opcode, \
1124 MIPS16OP_MASK_##FIELD, \
1125 MIPS16OP_SH_##FIELD)
1127 /* The MIPS16 EXTEND opcode, shifted left 16 places. */
1128 #define MIPS16_EXTEND (0xf000U << 16)
1130 /* Whether or not we are emitting a branch-likely macro. */
1131 static bfd_boolean emit_branch_likely_macro = FALSE;
1133 /* Global variables used when generating relaxable macros. See the
1134 comment above RELAX_ENCODE for more details about how relaxation
1137 /* 0 if we're not emitting a relaxable macro.
1138 1 if we're emitting the first of the two relaxation alternatives.
1139 2 if we're emitting the second alternative. */
1142 /* The first relaxable fixup in the current frag. (In other words,
1143 the first fixup that refers to relaxable code.) */
1146 /* sizes[0] says how many bytes of the first alternative are stored in
1147 the current frag. Likewise sizes[1] for the second alternative. */
1148 unsigned int sizes[2];
1150 /* The symbol on which the choice of sequence depends. */
1154 /* Global variables used to decide whether a macro needs a warning. */
1156 /* True if the macro is in a branch delay slot. */
1157 bfd_boolean delay_slot_p;
1159 /* Set to the length in bytes required if the macro is in a delay slot
1160 that requires a specific length of instruction, otherwise zero. */
1161 unsigned int delay_slot_length;
1163 /* For relaxable macros, sizes[0] is the length of the first alternative
1164 in bytes and sizes[1] is the length of the second alternative.
1165 For non-relaxable macros, both elements give the length of the
1167 unsigned int sizes[2];
1169 /* For relaxable macros, first_insn_sizes[0] is the length of the first
1170 instruction of the first alternative in bytes and first_insn_sizes[1]
1171 is the length of the first instruction of the second alternative.
1172 For non-relaxable macros, both elements give the length of the first
1173 instruction in bytes.
1175 Set to zero if we haven't yet seen the first instruction. */
1176 unsigned int first_insn_sizes[2];
1178 /* For relaxable macros, insns[0] is the number of instructions for the
1179 first alternative and insns[1] is the number of instructions for the
1182 For non-relaxable macros, both elements give the number of
1183 instructions for the macro. */
1184 unsigned int insns[2];
1186 /* The first variant frag for this macro. */
1188 } mips_macro_warning;
1190 /* Prototypes for static functions. */
1192 enum mips_regclass { MIPS_GR_REG, MIPS_FP_REG, MIPS16_REG };
1194 static void append_insn
1195 (struct mips_cl_insn *, expressionS *, bfd_reloc_code_real_type *,
1196 bfd_boolean expansionp);
1197 static void mips_no_prev_insn (void);
1198 static void macro_build (expressionS *, const char *, const char *, ...);
1199 static void mips16_macro_build
1200 (expressionS *, const char *, const char *, va_list *);
1201 static void load_register (int, expressionS *, int);
1202 static void macro_start (void);
1203 static void macro_end (void);
1204 static void macro (struct mips_cl_insn *ip, char *str);
1205 static void mips16_macro (struct mips_cl_insn * ip);
1206 static void mips_ip (char *str, struct mips_cl_insn * ip);
1207 static void mips16_ip (char *str, struct mips_cl_insn * ip);
1208 static void mips16_immed
1209 (char *, unsigned int, int, bfd_reloc_code_real_type, offsetT,
1210 unsigned int, unsigned long *);
1211 static size_t my_getSmallExpression
1212 (expressionS *, bfd_reloc_code_real_type *, char *);
1213 static void my_getExpression (expressionS *, char *);
1214 static void s_align (int);
1215 static void s_change_sec (int);
1216 static void s_change_section (int);
1217 static void s_cons (int);
1218 static void s_float_cons (int);
1219 static void s_mips_globl (int);
1220 static void s_option (int);
1221 static void s_mipsset (int);
1222 static void s_abicalls (int);
1223 static void s_cpload (int);
1224 static void s_cpsetup (int);
1225 static void s_cplocal (int);
1226 static void s_cprestore (int);
1227 static void s_cpreturn (int);
1228 static void s_dtprelword (int);
1229 static void s_dtpreldword (int);
1230 static void s_tprelword (int);
1231 static void s_tpreldword (int);
1232 static void s_gpvalue (int);
1233 static void s_gpword (int);
1234 static void s_gpdword (int);
1235 static void s_ehword (int);
1236 static void s_cpadd (int);
1237 static void s_insn (int);
1238 static void s_nan (int);
1239 static void md_obj_begin (void);
1240 static void md_obj_end (void);
1241 static void s_mips_ent (int);
1242 static void s_mips_end (int);
1243 static void s_mips_frame (int);
1244 static void s_mips_mask (int reg_type);
1245 static void s_mips_stab (int);
1246 static void s_mips_weakext (int);
1247 static void s_mips_file (int);
1248 static void s_mips_loc (int);
1249 static bfd_boolean pic_need_relax (symbolS *, asection *);
1250 static int relaxed_branch_length (fragS *, asection *, int);
1251 static int relaxed_micromips_16bit_branch_length (fragS *, asection *, int);
1252 static int relaxed_micromips_32bit_branch_length (fragS *, asection *, int);
1254 /* Table and functions used to map between CPU/ISA names, and
1255 ISA levels, and CPU numbers. */
1257 struct mips_cpu_info
1259 const char *name; /* CPU or ISA name. */
1260 int flags; /* MIPS_CPU_* flags. */
1261 int ase; /* Set of ASEs implemented by the CPU. */
1262 int isa; /* ISA level. */
1263 int cpu; /* CPU number (default CPU if ISA). */
1266 #define MIPS_CPU_IS_ISA 0x0001 /* Is this an ISA? (If 0, a CPU.) */
1268 static const struct mips_cpu_info *mips_parse_cpu (const char *, const char *);
1269 static const struct mips_cpu_info *mips_cpu_info_from_isa (int);
1270 static const struct mips_cpu_info *mips_cpu_info_from_arch (int);
1272 /* Command-line options. */
1273 const char *md_shortopts = "O::g::G:";
1277 OPTION_MARCH = OPTION_MD_BASE,
1301 OPTION_NO_SMARTMIPS,
1307 OPTION_NO_MICROMIPS,
1310 OPTION_COMPAT_ARCH_BASE,
1319 OPTION_M7000_HILO_FIX,
1320 OPTION_MNO_7000_HILO_FIX,
1323 OPTION_FIX_LOONGSON2F_JUMP,
1324 OPTION_NO_FIX_LOONGSON2F_JUMP,
1325 OPTION_FIX_LOONGSON2F_NOP,
1326 OPTION_NO_FIX_LOONGSON2F_NOP,
1328 OPTION_NO_FIX_VR4120,
1330 OPTION_NO_FIX_VR4130,
1331 OPTION_FIX_CN63XXP1,
1332 OPTION_NO_FIX_CN63XXP1,
1339 OPTION_CONSTRUCT_FLOATS,
1340 OPTION_NO_CONSTRUCT_FLOATS,
1343 OPTION_RELAX_BRANCH,
1344 OPTION_NO_RELAX_BRANCH,
1353 OPTION_SINGLE_FLOAT,
1354 OPTION_DOUBLE_FLOAT,
1367 OPTION_MVXWORKS_PIC,
1372 struct option md_longopts[] =
1374 /* Options which specify architecture. */
1375 {"march", required_argument, NULL, OPTION_MARCH},
1376 {"mtune", required_argument, NULL, OPTION_MTUNE},
1377 {"mips0", no_argument, NULL, OPTION_MIPS1},
1378 {"mips1", no_argument, NULL, OPTION_MIPS1},
1379 {"mips2", no_argument, NULL, OPTION_MIPS2},
1380 {"mips3", no_argument, NULL, OPTION_MIPS3},
1381 {"mips4", no_argument, NULL, OPTION_MIPS4},
1382 {"mips5", no_argument, NULL, OPTION_MIPS5},
1383 {"mips32", no_argument, NULL, OPTION_MIPS32},
1384 {"mips64", no_argument, NULL, OPTION_MIPS64},
1385 {"mips32r2", no_argument, NULL, OPTION_MIPS32R2},
1386 {"mips64r2", no_argument, NULL, OPTION_MIPS64R2},
1388 /* Options which specify Application Specific Extensions (ASEs). */
1389 {"mips16", no_argument, NULL, OPTION_MIPS16},
1390 {"no-mips16", no_argument, NULL, OPTION_NO_MIPS16},
1391 {"mips3d", no_argument, NULL, OPTION_MIPS3D},
1392 {"no-mips3d", no_argument, NULL, OPTION_NO_MIPS3D},
1393 {"mdmx", no_argument, NULL, OPTION_MDMX},
1394 {"no-mdmx", no_argument, NULL, OPTION_NO_MDMX},
1395 {"mdsp", no_argument, NULL, OPTION_DSP},
1396 {"mno-dsp", no_argument, NULL, OPTION_NO_DSP},
1397 {"mmt", no_argument, NULL, OPTION_MT},
1398 {"mno-mt", no_argument, NULL, OPTION_NO_MT},
1399 {"msmartmips", no_argument, NULL, OPTION_SMARTMIPS},
1400 {"mno-smartmips", no_argument, NULL, OPTION_NO_SMARTMIPS},
1401 {"mdspr2", no_argument, NULL, OPTION_DSPR2},
1402 {"mno-dspr2", no_argument, NULL, OPTION_NO_DSPR2},
1403 {"meva", no_argument, NULL, OPTION_EVA},
1404 {"mno-eva", no_argument, NULL, OPTION_NO_EVA},
1405 {"mmicromips", no_argument, NULL, OPTION_MICROMIPS},
1406 {"mno-micromips", no_argument, NULL, OPTION_NO_MICROMIPS},
1407 {"mmcu", no_argument, NULL, OPTION_MCU},
1408 {"mno-mcu", no_argument, NULL, OPTION_NO_MCU},
1409 {"mvirt", no_argument, NULL, OPTION_VIRT},
1410 {"mno-virt", no_argument, NULL, OPTION_NO_VIRT},
1412 /* Old-style architecture options. Don't add more of these. */
1413 {"m4650", no_argument, NULL, OPTION_M4650},
1414 {"no-m4650", no_argument, NULL, OPTION_NO_M4650},
1415 {"m4010", no_argument, NULL, OPTION_M4010},
1416 {"no-m4010", no_argument, NULL, OPTION_NO_M4010},
1417 {"m4100", no_argument, NULL, OPTION_M4100},
1418 {"no-m4100", no_argument, NULL, OPTION_NO_M4100},
1419 {"m3900", no_argument, NULL, OPTION_M3900},
1420 {"no-m3900", no_argument, NULL, OPTION_NO_M3900},
1422 /* Options which enable bug fixes. */
1423 {"mfix7000", no_argument, NULL, OPTION_M7000_HILO_FIX},
1424 {"no-fix-7000", no_argument, NULL, OPTION_MNO_7000_HILO_FIX},
1425 {"mno-fix7000", no_argument, NULL, OPTION_MNO_7000_HILO_FIX},
1426 {"mfix-loongson2f-jump", no_argument, NULL, OPTION_FIX_LOONGSON2F_JUMP},
1427 {"mno-fix-loongson2f-jump", no_argument, NULL, OPTION_NO_FIX_LOONGSON2F_JUMP},
1428 {"mfix-loongson2f-nop", no_argument, NULL, OPTION_FIX_LOONGSON2F_NOP},
1429 {"mno-fix-loongson2f-nop", no_argument, NULL, OPTION_NO_FIX_LOONGSON2F_NOP},
1430 {"mfix-vr4120", no_argument, NULL, OPTION_FIX_VR4120},
1431 {"mno-fix-vr4120", no_argument, NULL, OPTION_NO_FIX_VR4120},
1432 {"mfix-vr4130", no_argument, NULL, OPTION_FIX_VR4130},
1433 {"mno-fix-vr4130", no_argument, NULL, OPTION_NO_FIX_VR4130},
1434 {"mfix-24k", no_argument, NULL, OPTION_FIX_24K},
1435 {"mno-fix-24k", no_argument, NULL, OPTION_NO_FIX_24K},
1436 {"mfix-cn63xxp1", no_argument, NULL, OPTION_FIX_CN63XXP1},
1437 {"mno-fix-cn63xxp1", no_argument, NULL, OPTION_NO_FIX_CN63XXP1},
1439 /* Miscellaneous options. */
1440 {"trap", no_argument, NULL, OPTION_TRAP},
1441 {"no-break", no_argument, NULL, OPTION_TRAP},
1442 {"break", no_argument, NULL, OPTION_BREAK},
1443 {"no-trap", no_argument, NULL, OPTION_BREAK},
1444 {"EB", no_argument, NULL, OPTION_EB},
1445 {"EL", no_argument, NULL, OPTION_EL},
1446 {"mfp32", no_argument, NULL, OPTION_FP32},
1447 {"mgp32", no_argument, NULL, OPTION_GP32},
1448 {"construct-floats", no_argument, NULL, OPTION_CONSTRUCT_FLOATS},
1449 {"no-construct-floats", no_argument, NULL, OPTION_NO_CONSTRUCT_FLOATS},
1450 {"mfp64", no_argument, NULL, OPTION_FP64},
1451 {"mgp64", no_argument, NULL, OPTION_GP64},
1452 {"relax-branch", no_argument, NULL, OPTION_RELAX_BRANCH},
1453 {"no-relax-branch", no_argument, NULL, OPTION_NO_RELAX_BRANCH},
1454 {"minsn32", no_argument, NULL, OPTION_INSN32},
1455 {"mno-insn32", no_argument, NULL, OPTION_NO_INSN32},
1456 {"mshared", no_argument, NULL, OPTION_MSHARED},
1457 {"mno-shared", no_argument, NULL, OPTION_MNO_SHARED},
1458 {"msym32", no_argument, NULL, OPTION_MSYM32},
1459 {"mno-sym32", no_argument, NULL, OPTION_MNO_SYM32},
1460 {"msoft-float", no_argument, NULL, OPTION_SOFT_FLOAT},
1461 {"mhard-float", no_argument, NULL, OPTION_HARD_FLOAT},
1462 {"msingle-float", no_argument, NULL, OPTION_SINGLE_FLOAT},
1463 {"mdouble-float", no_argument, NULL, OPTION_DOUBLE_FLOAT},
1465 /* Strictly speaking this next option is ELF specific,
1466 but we allow it for other ports as well in order to
1467 make testing easier. */
1468 {"32", no_argument, NULL, OPTION_32},
1470 /* ELF-specific options. */
1471 {"KPIC", no_argument, NULL, OPTION_CALL_SHARED},
1472 {"call_shared", no_argument, NULL, OPTION_CALL_SHARED},
1473 {"call_nonpic", no_argument, NULL, OPTION_CALL_NONPIC},
1474 {"non_shared", no_argument, NULL, OPTION_NON_SHARED},
1475 {"xgot", no_argument, NULL, OPTION_XGOT},
1476 {"mabi", required_argument, NULL, OPTION_MABI},
1477 {"n32", no_argument, NULL, OPTION_N32},
1478 {"64", no_argument, NULL, OPTION_64},
1479 {"mdebug", no_argument, NULL, OPTION_MDEBUG},
1480 {"no-mdebug", no_argument, NULL, OPTION_NO_MDEBUG},
1481 {"mpdr", no_argument, NULL, OPTION_PDR},
1482 {"mno-pdr", no_argument, NULL, OPTION_NO_PDR},
1483 {"mvxworks-pic", no_argument, NULL, OPTION_MVXWORKS_PIC},
1484 {"mnan", required_argument, NULL, OPTION_NAN},
1486 {NULL, no_argument, NULL, 0}
1488 size_t md_longopts_size = sizeof (md_longopts);
1490 /* Information about either an Application Specific Extension or an
1491 optional architecture feature that, for simplicity, we treat in the
1492 same way as an ASE. */
1495 /* The name of the ASE, used in both the command-line and .set options. */
1498 /* The associated ASE_* flags. If the ASE is available on both 32-bit
1499 and 64-bit architectures, the flags here refer to the subset that
1500 is available on both. */
1503 /* The ASE_* flag used for instructions that are available on 64-bit
1504 architectures but that are not included in FLAGS. */
1505 unsigned int flags64;
1507 /* The command-line options that turn the ASE on and off. */
1511 /* The minimum required architecture revisions for MIPS32, MIPS64,
1512 microMIPS32 and microMIPS64, or -1 if the extension isn't supported. */
1515 int micromips32_rev;
1516 int micromips64_rev;
1519 /* A table of all supported ASEs. */
1520 static const struct mips_ase mips_ases[] = {
1521 { "dsp", ASE_DSP, ASE_DSP64,
1522 OPTION_DSP, OPTION_NO_DSP,
1525 { "dspr2", ASE_DSP | ASE_DSPR2, 0,
1526 OPTION_DSPR2, OPTION_NO_DSPR2,
1529 { "eva", ASE_EVA, 0,
1530 OPTION_EVA, OPTION_NO_EVA,
1533 { "mcu", ASE_MCU, 0,
1534 OPTION_MCU, OPTION_NO_MCU,
1537 /* Deprecated in MIPS64r5, but we don't implement that yet. */
1538 { "mdmx", ASE_MDMX, 0,
1539 OPTION_MDMX, OPTION_NO_MDMX,
1542 /* Requires 64-bit FPRs, so the minimum MIPS32 revision is 2. */
1543 { "mips3d", ASE_MIPS3D, 0,
1544 OPTION_MIPS3D, OPTION_NO_MIPS3D,
1548 OPTION_MT, OPTION_NO_MT,
1551 { "smartmips", ASE_SMARTMIPS, 0,
1552 OPTION_SMARTMIPS, OPTION_NO_SMARTMIPS,
1555 { "virt", ASE_VIRT, ASE_VIRT64,
1556 OPTION_VIRT, OPTION_NO_VIRT,
1560 /* The set of ASEs that require -mfp64. */
1561 #define FP64_ASES (ASE_MIPS3D | ASE_MDMX)
1563 /* Groups of ASE_* flags that represent different revisions of an ASE. */
1564 static const unsigned int mips_ase_groups[] = {
1570 The following pseudo-ops from the Kane and Heinrich MIPS book
1571 should be defined here, but are currently unsupported: .alias,
1572 .galive, .gjaldef, .gjrlive, .livereg, .noalias.
1574 The following pseudo-ops from the Kane and Heinrich MIPS book are
1575 specific to the type of debugging information being generated, and
1576 should be defined by the object format: .aent, .begin, .bend,
1577 .bgnb, .end, .endb, .ent, .fmask, .frame, .loc, .mask, .verstamp,
1580 The following pseudo-ops from the Kane and Heinrich MIPS book are
1581 not MIPS CPU specific, but are also not specific to the object file
1582 format. This file is probably the best place to define them, but
1583 they are not currently supported: .asm0, .endr, .lab, .struct. */
1585 static const pseudo_typeS mips_pseudo_table[] =
1587 /* MIPS specific pseudo-ops. */
1588 {"option", s_option, 0},
1589 {"set", s_mipsset, 0},
1590 {"rdata", s_change_sec, 'r'},
1591 {"sdata", s_change_sec, 's'},
1592 {"livereg", s_ignore, 0},
1593 {"abicalls", s_abicalls, 0},
1594 {"cpload", s_cpload, 0},
1595 {"cpsetup", s_cpsetup, 0},
1596 {"cplocal", s_cplocal, 0},
1597 {"cprestore", s_cprestore, 0},
1598 {"cpreturn", s_cpreturn, 0},
1599 {"dtprelword", s_dtprelword, 0},
1600 {"dtpreldword", s_dtpreldword, 0},
1601 {"tprelword", s_tprelword, 0},
1602 {"tpreldword", s_tpreldword, 0},
1603 {"gpvalue", s_gpvalue, 0},
1604 {"gpword", s_gpword, 0},
1605 {"gpdword", s_gpdword, 0},
1606 {"ehword", s_ehword, 0},
1607 {"cpadd", s_cpadd, 0},
1608 {"insn", s_insn, 0},
1611 /* Relatively generic pseudo-ops that happen to be used on MIPS
1613 {"asciiz", stringer, 8 + 1},
1614 {"bss", s_change_sec, 'b'},
1616 {"half", s_cons, 1},
1617 {"dword", s_cons, 3},
1618 {"weakext", s_mips_weakext, 0},
1619 {"origin", s_org, 0},
1620 {"repeat", s_rept, 0},
1622 /* For MIPS this is non-standard, but we define it for consistency. */
1623 {"sbss", s_change_sec, 'B'},
1625 /* These pseudo-ops are defined in read.c, but must be overridden
1626 here for one reason or another. */
1627 {"align", s_align, 0},
1628 {"byte", s_cons, 0},
1629 {"data", s_change_sec, 'd'},
1630 {"double", s_float_cons, 'd'},
1631 {"float", s_float_cons, 'f'},
1632 {"globl", s_mips_globl, 0},
1633 {"global", s_mips_globl, 0},
1634 {"hword", s_cons, 1},
1636 {"long", s_cons, 2},
1637 {"octa", s_cons, 4},
1638 {"quad", s_cons, 3},
1639 {"section", s_change_section, 0},
1640 {"short", s_cons, 1},
1641 {"single", s_float_cons, 'f'},
1642 {"stabd", s_mips_stab, 'd'},
1643 {"stabn", s_mips_stab, 'n'},
1644 {"stabs", s_mips_stab, 's'},
1645 {"text", s_change_sec, 't'},
1646 {"word", s_cons, 2},
1648 { "extern", ecoff_directive_extern, 0},
1653 static const pseudo_typeS mips_nonecoff_pseudo_table[] =
1655 /* These pseudo-ops should be defined by the object file format.
1656 However, a.out doesn't support them, so we have versions here. */
1657 {"aent", s_mips_ent, 1},
1658 {"bgnb", s_ignore, 0},
1659 {"end", s_mips_end, 0},
1660 {"endb", s_ignore, 0},
1661 {"ent", s_mips_ent, 0},
1662 {"file", s_mips_file, 0},
1663 {"fmask", s_mips_mask, 'F'},
1664 {"frame", s_mips_frame, 0},
1665 {"loc", s_mips_loc, 0},
1666 {"mask", s_mips_mask, 'R'},
1667 {"verstamp", s_ignore, 0},
1671 /* Export the ABI address size for use by TC_ADDRESS_BYTES for the
1672 purpose of the `.dc.a' internal pseudo-op. */
1675 mips_address_bytes (void)
1677 return HAVE_64BIT_ADDRESSES ? 8 : 4;
1680 extern void pop_insert (const pseudo_typeS *);
1683 mips_pop_insert (void)
1685 pop_insert (mips_pseudo_table);
1686 if (! ECOFF_DEBUGGING)
1687 pop_insert (mips_nonecoff_pseudo_table);
1690 /* Symbols labelling the current insn. */
1692 struct insn_label_list
1694 struct insn_label_list *next;
1698 static struct insn_label_list *free_insn_labels;
1699 #define label_list tc_segment_info_data.labels
1701 static void mips_clear_insn_labels (void);
1702 static void mips_mark_labels (void);
1703 static void mips_compressed_mark_labels (void);
1706 mips_clear_insn_labels (void)
1708 register struct insn_label_list **pl;
1709 segment_info_type *si;
1713 for (pl = &free_insn_labels; *pl != NULL; pl = &(*pl)->next)
1716 si = seg_info (now_seg);
1717 *pl = si->label_list;
1718 si->label_list = NULL;
1722 /* Mark instruction labels in MIPS16/microMIPS mode. */
1725 mips_mark_labels (void)
1727 if (HAVE_CODE_COMPRESSION)
1728 mips_compressed_mark_labels ();
1731 static char *expr_end;
1733 /* Expressions which appear in macro instructions. These are set by
1734 mips_ip and read by macro. */
1736 static expressionS imm_expr;
1737 static expressionS imm2_expr;
1739 /* The relocatable field in an instruction and the relocs associated
1740 with it. These variables are used for instructions like LUI and
1741 JAL as well as true offsets. They are also used for address
1742 operands in macros. */
1744 static expressionS offset_expr;
1745 static bfd_reloc_code_real_type offset_reloc[3]
1746 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
1748 /* This is set to the resulting size of the instruction to be produced
1749 by mips16_ip if an explicit extension is used or by mips_ip if an
1750 explicit size is supplied. */
1752 static unsigned int forced_insn_length;
1754 /* True if we are assembling an instruction. All dot symbols defined during
1755 this time should be treated as code labels. */
1757 static bfd_boolean mips_assembling_insn;
1759 /* The pdr segment for per procedure frame/regmask info. Not used for
1762 static segT pdr_seg;
1764 /* The default target format to use. */
1766 #if defined (TE_FreeBSD)
1767 #define ELF_TARGET(PREFIX, ENDIAN) PREFIX "trad" ENDIAN "mips-freebsd"
1768 #elif defined (TE_TMIPS)
1769 #define ELF_TARGET(PREFIX, ENDIAN) PREFIX "trad" ENDIAN "mips"
1771 #define ELF_TARGET(PREFIX, ENDIAN) PREFIX ENDIAN "mips"
1775 mips_target_format (void)
1777 switch (OUTPUT_FLAVOR)
1779 case bfd_target_elf_flavour:
1781 if (!HAVE_64BIT_OBJECTS && !HAVE_NEWABI)
1782 return (target_big_endian
1783 ? "elf32-bigmips-vxworks"
1784 : "elf32-littlemips-vxworks");
1786 return (target_big_endian
1787 ? (HAVE_64BIT_OBJECTS
1788 ? ELF_TARGET ("elf64-", "big")
1790 ? ELF_TARGET ("elf32-n", "big")
1791 : ELF_TARGET ("elf32-", "big")))
1792 : (HAVE_64BIT_OBJECTS
1793 ? ELF_TARGET ("elf64-", "little")
1795 ? ELF_TARGET ("elf32-n", "little")
1796 : ELF_TARGET ("elf32-", "little"))));
1803 /* Return the ISA revision that is currently in use, or 0 if we are
1804 generating code for MIPS V or below. */
1809 if (mips_opts.isa == ISA_MIPS32R2 || mips_opts.isa == ISA_MIPS64R2)
1812 /* microMIPS implies revision 2 or above. */
1813 if (mips_opts.micromips)
1816 if (mips_opts.isa == ISA_MIPS32 || mips_opts.isa == ISA_MIPS64)
1822 /* Return the mask of all ASEs that are revisions of those in FLAGS. */
1825 mips_ase_mask (unsigned int flags)
1829 for (i = 0; i < ARRAY_SIZE (mips_ase_groups); i++)
1830 if (flags & mips_ase_groups[i])
1831 flags |= mips_ase_groups[i];
1835 /* Check whether the current ISA supports ASE. Issue a warning if
1839 mips_check_isa_supports_ase (const struct mips_ase *ase)
1843 static unsigned int warned_isa;
1844 static unsigned int warned_fp32;
1846 if (ISA_HAS_64BIT_REGS (mips_opts.isa))
1847 min_rev = mips_opts.micromips ? ase->micromips64_rev : ase->mips64_rev;
1849 min_rev = mips_opts.micromips ? ase->micromips32_rev : ase->mips32_rev;
1850 if ((min_rev < 0 || mips_isa_rev () < min_rev)
1851 && (warned_isa & ase->flags) != ase->flags)
1853 warned_isa |= ase->flags;
1854 base = mips_opts.micromips ? "microMIPS" : "MIPS";
1855 size = ISA_HAS_64BIT_REGS (mips_opts.isa) ? 64 : 32;
1857 as_warn (_("The %d-bit %s architecture does not support the"
1858 " `%s' extension"), size, base, ase->name);
1860 as_warn (_("The `%s' extension requires %s%d revision %d or greater"),
1861 ase->name, base, size, min_rev);
1863 if ((ase->flags & FP64_ASES)
1865 && (warned_fp32 & ase->flags) != ase->flags)
1867 warned_fp32 |= ase->flags;
1868 as_warn (_("The `%s' extension requires 64-bit FPRs"), ase->name);
1872 /* Check all enabled ASEs to see whether they are supported by the
1873 chosen architecture. */
1876 mips_check_isa_supports_ases (void)
1878 unsigned int i, mask;
1880 for (i = 0; i < ARRAY_SIZE (mips_ases); i++)
1882 mask = mips_ase_mask (mips_ases[i].flags);
1883 if ((mips_opts.ase & mask) == mips_ases[i].flags)
1884 mips_check_isa_supports_ase (&mips_ases[i]);
1888 /* Set the state of ASE to ENABLED_P. Return the mask of ASE_* flags
1889 that were affected. */
1892 mips_set_ase (const struct mips_ase *ase, bfd_boolean enabled_p)
1896 mask = mips_ase_mask (ase->flags);
1897 mips_opts.ase &= ~mask;
1899 mips_opts.ase |= ase->flags;
1903 /* Return the ASE called NAME, or null if none. */
1905 static const struct mips_ase *
1906 mips_lookup_ase (const char *name)
1910 for (i = 0; i < ARRAY_SIZE (mips_ases); i++)
1911 if (strcmp (name, mips_ases[i].name) == 0)
1912 return &mips_ases[i];
1916 /* Return the length of a microMIPS instruction in bytes. If bits of
1917 the mask beyond the low 16 are 0, then it is a 16-bit instruction.
1918 Otherwise assume a 32-bit instruction; 48-bit instructions (0x1f
1919 major opcode) will require further modifications to the opcode
1922 static inline unsigned int
1923 micromips_insn_length (const struct mips_opcode *mo)
1925 return (mo->mask >> 16) == 0 ? 2 : 4;
1928 /* Return the length of MIPS16 instruction OPCODE. */
1930 static inline unsigned int
1931 mips16_opcode_length (unsigned long opcode)
1933 return (opcode >> 16) == 0 ? 2 : 4;
1936 /* Return the length of instruction INSN. */
1938 static inline unsigned int
1939 insn_length (const struct mips_cl_insn *insn)
1941 if (mips_opts.micromips)
1942 return micromips_insn_length (insn->insn_mo);
1943 else if (mips_opts.mips16)
1944 return mips16_opcode_length (insn->insn_opcode);
1949 /* Initialise INSN from opcode entry MO. Leave its position unspecified. */
1952 create_insn (struct mips_cl_insn *insn, const struct mips_opcode *mo)
1957 insn->insn_opcode = mo->match;
1960 for (i = 0; i < ARRAY_SIZE (insn->fixp); i++)
1961 insn->fixp[i] = NULL;
1962 insn->fixed_p = (mips_opts.noreorder > 0);
1963 insn->noreorder_p = (mips_opts.noreorder > 0);
1964 insn->mips16_absolute_jump_p = 0;
1965 insn->complete_p = 0;
1966 insn->cleared_p = 0;
1969 /* Install UVAL as the value of OPERAND in INSN. */
1972 insn_insert_operand (struct mips_cl_insn *insn,
1973 const struct mips_operand *operand, unsigned int uval)
1975 insn->insn_opcode = mips_insert_operand (operand, insn->insn_opcode, uval);
1978 /* Record the current MIPS16/microMIPS mode in now_seg. */
1981 mips_record_compressed_mode (void)
1983 segment_info_type *si;
1985 si = seg_info (now_seg);
1986 if (si->tc_segment_info_data.mips16 != mips_opts.mips16)
1987 si->tc_segment_info_data.mips16 = mips_opts.mips16;
1988 if (si->tc_segment_info_data.micromips != mips_opts.micromips)
1989 si->tc_segment_info_data.micromips = mips_opts.micromips;
1992 /* Read a standard MIPS instruction from BUF. */
1994 static unsigned long
1995 read_insn (char *buf)
1997 if (target_big_endian)
1998 return bfd_getb32 ((bfd_byte *) buf);
2000 return bfd_getl32 ((bfd_byte *) buf);
2003 /* Write standard MIPS instruction INSN to BUF. Return a pointer to
2007 write_insn (char *buf, unsigned int insn)
2009 md_number_to_chars (buf, insn, 4);
2013 /* Read a microMIPS or MIPS16 opcode from BUF, given that it
2014 has length LENGTH. */
2016 static unsigned long
2017 read_compressed_insn (char *buf, unsigned int length)
2023 for (i = 0; i < length; i += 2)
2026 if (target_big_endian)
2027 insn |= bfd_getb16 ((char *) buf);
2029 insn |= bfd_getl16 ((char *) buf);
2035 /* Write microMIPS or MIPS16 instruction INSN to BUF, given that the
2036 instruction is LENGTH bytes long. Return a pointer to the next byte. */
2039 write_compressed_insn (char *buf, unsigned int insn, unsigned int length)
2043 for (i = 0; i < length; i += 2)
2044 md_number_to_chars (buf + i, insn >> ((length - i - 2) * 8), 2);
2045 return buf + length;
2048 /* Install INSN at the location specified by its "frag" and "where" fields. */
2051 install_insn (const struct mips_cl_insn *insn)
2053 char *f = insn->frag->fr_literal + insn->where;
2054 if (HAVE_CODE_COMPRESSION)
2055 write_compressed_insn (f, insn->insn_opcode, insn_length (insn));
2057 write_insn (f, insn->insn_opcode);
2058 mips_record_compressed_mode ();
2061 /* Move INSN to offset WHERE in FRAG. Adjust the fixups accordingly
2062 and install the opcode in the new location. */
2065 move_insn (struct mips_cl_insn *insn, fragS *frag, long where)
2070 insn->where = where;
2071 for (i = 0; i < ARRAY_SIZE (insn->fixp); i++)
2072 if (insn->fixp[i] != NULL)
2074 insn->fixp[i]->fx_frag = frag;
2075 insn->fixp[i]->fx_where = where;
2077 install_insn (insn);
2080 /* Add INSN to the end of the output. */
2083 add_fixed_insn (struct mips_cl_insn *insn)
2085 char *f = frag_more (insn_length (insn));
2086 move_insn (insn, frag_now, f - frag_now->fr_literal);
2089 /* Start a variant frag and move INSN to the start of the variant part,
2090 marking it as fixed. The other arguments are as for frag_var. */
2093 add_relaxed_insn (struct mips_cl_insn *insn, int max_chars, int var,
2094 relax_substateT subtype, symbolS *symbol, offsetT offset)
2096 frag_grow (max_chars);
2097 move_insn (insn, frag_now, frag_more (0) - frag_now->fr_literal);
2099 frag_var (rs_machine_dependent, max_chars, var,
2100 subtype, symbol, offset, NULL);
2103 /* Insert N copies of INSN into the history buffer, starting at
2104 position FIRST. Neither FIRST nor N need to be clipped. */
2107 insert_into_history (unsigned int first, unsigned int n,
2108 const struct mips_cl_insn *insn)
2110 if (mips_relax.sequence != 2)
2114 for (i = ARRAY_SIZE (history); i-- > first;)
2116 history[i] = history[i - n];
2122 /* Initialize vr4120_conflicts. There is a bit of duplication here:
2123 the idea is to make it obvious at a glance that each errata is
2127 init_vr4120_conflicts (void)
2129 #define CONFLICT(FIRST, SECOND) \
2130 vr4120_conflicts[FIX_VR4120_##FIRST] |= 1 << FIX_VR4120_##SECOND
2132 /* Errata 21 - [D]DIV[U] after [D]MACC */
2133 CONFLICT (MACC, DIV);
2134 CONFLICT (DMACC, DIV);
2136 /* Errata 23 - Continuous DMULT[U]/DMACC instructions. */
2137 CONFLICT (DMULT, DMULT);
2138 CONFLICT (DMULT, DMACC);
2139 CONFLICT (DMACC, DMULT);
2140 CONFLICT (DMACC, DMACC);
2142 /* Errata 24 - MT{LO,HI} after [D]MACC */
2143 CONFLICT (MACC, MTHILO);
2144 CONFLICT (DMACC, MTHILO);
2146 /* VR4181A errata MD(1): "If a MULT, MULTU, DMULT or DMULTU
2147 instruction is executed immediately after a MACC or DMACC
2148 instruction, the result of [either instruction] is incorrect." */
2149 CONFLICT (MACC, MULT);
2150 CONFLICT (MACC, DMULT);
2151 CONFLICT (DMACC, MULT);
2152 CONFLICT (DMACC, DMULT);
2154 /* VR4181A errata MD(4): "If a MACC or DMACC instruction is
2155 executed immediately after a DMULT, DMULTU, DIV, DIVU,
2156 DDIV or DDIVU instruction, the result of the MACC or
2157 DMACC instruction is incorrect.". */
2158 CONFLICT (DMULT, MACC);
2159 CONFLICT (DMULT, DMACC);
2160 CONFLICT (DIV, MACC);
2161 CONFLICT (DIV, DMACC);
2171 #define RTYPE_MASK 0x1ff00
2172 #define RTYPE_NUM 0x00100
2173 #define RTYPE_FPU 0x00200
2174 #define RTYPE_FCC 0x00400
2175 #define RTYPE_VEC 0x00800
2176 #define RTYPE_GP 0x01000
2177 #define RTYPE_CP0 0x02000
2178 #define RTYPE_PC 0x04000
2179 #define RTYPE_ACC 0x08000
2180 #define RTYPE_CCC 0x10000
2181 #define RNUM_MASK 0x000ff
2182 #define RWARN 0x80000
2184 #define GENERIC_REGISTER_NUMBERS \
2185 {"$0", RTYPE_NUM | 0}, \
2186 {"$1", RTYPE_NUM | 1}, \
2187 {"$2", RTYPE_NUM | 2}, \
2188 {"$3", RTYPE_NUM | 3}, \
2189 {"$4", RTYPE_NUM | 4}, \
2190 {"$5", RTYPE_NUM | 5}, \
2191 {"$6", RTYPE_NUM | 6}, \
2192 {"$7", RTYPE_NUM | 7}, \
2193 {"$8", RTYPE_NUM | 8}, \
2194 {"$9", RTYPE_NUM | 9}, \
2195 {"$10", RTYPE_NUM | 10}, \
2196 {"$11", RTYPE_NUM | 11}, \
2197 {"$12", RTYPE_NUM | 12}, \
2198 {"$13", RTYPE_NUM | 13}, \
2199 {"$14", RTYPE_NUM | 14}, \
2200 {"$15", RTYPE_NUM | 15}, \
2201 {"$16", RTYPE_NUM | 16}, \
2202 {"$17", RTYPE_NUM | 17}, \
2203 {"$18", RTYPE_NUM | 18}, \
2204 {"$19", RTYPE_NUM | 19}, \
2205 {"$20", RTYPE_NUM | 20}, \
2206 {"$21", RTYPE_NUM | 21}, \
2207 {"$22", RTYPE_NUM | 22}, \
2208 {"$23", RTYPE_NUM | 23}, \
2209 {"$24", RTYPE_NUM | 24}, \
2210 {"$25", RTYPE_NUM | 25}, \
2211 {"$26", RTYPE_NUM | 26}, \
2212 {"$27", RTYPE_NUM | 27}, \
2213 {"$28", RTYPE_NUM | 28}, \
2214 {"$29", RTYPE_NUM | 29}, \
2215 {"$30", RTYPE_NUM | 30}, \
2216 {"$31", RTYPE_NUM | 31}
2218 #define FPU_REGISTER_NAMES \
2219 {"$f0", RTYPE_FPU | 0}, \
2220 {"$f1", RTYPE_FPU | 1}, \
2221 {"$f2", RTYPE_FPU | 2}, \
2222 {"$f3", RTYPE_FPU | 3}, \
2223 {"$f4", RTYPE_FPU | 4}, \
2224 {"$f5", RTYPE_FPU | 5}, \
2225 {"$f6", RTYPE_FPU | 6}, \
2226 {"$f7", RTYPE_FPU | 7}, \
2227 {"$f8", RTYPE_FPU | 8}, \
2228 {"$f9", RTYPE_FPU | 9}, \
2229 {"$f10", RTYPE_FPU | 10}, \
2230 {"$f11", RTYPE_FPU | 11}, \
2231 {"$f12", RTYPE_FPU | 12}, \
2232 {"$f13", RTYPE_FPU | 13}, \
2233 {"$f14", RTYPE_FPU | 14}, \
2234 {"$f15", RTYPE_FPU | 15}, \
2235 {"$f16", RTYPE_FPU | 16}, \
2236 {"$f17", RTYPE_FPU | 17}, \
2237 {"$f18", RTYPE_FPU | 18}, \
2238 {"$f19", RTYPE_FPU | 19}, \
2239 {"$f20", RTYPE_FPU | 20}, \
2240 {"$f21", RTYPE_FPU | 21}, \
2241 {"$f22", RTYPE_FPU | 22}, \
2242 {"$f23", RTYPE_FPU | 23}, \
2243 {"$f24", RTYPE_FPU | 24}, \
2244 {"$f25", RTYPE_FPU | 25}, \
2245 {"$f26", RTYPE_FPU | 26}, \
2246 {"$f27", RTYPE_FPU | 27}, \
2247 {"$f28", RTYPE_FPU | 28}, \
2248 {"$f29", RTYPE_FPU | 29}, \
2249 {"$f30", RTYPE_FPU | 30}, \
2250 {"$f31", RTYPE_FPU | 31}
2252 #define FPU_CONDITION_CODE_NAMES \
2253 {"$fcc0", RTYPE_FCC | 0}, \
2254 {"$fcc1", RTYPE_FCC | 1}, \
2255 {"$fcc2", RTYPE_FCC | 2}, \
2256 {"$fcc3", RTYPE_FCC | 3}, \
2257 {"$fcc4", RTYPE_FCC | 4}, \
2258 {"$fcc5", RTYPE_FCC | 5}, \
2259 {"$fcc6", RTYPE_FCC | 6}, \
2260 {"$fcc7", RTYPE_FCC | 7}
2262 #define COPROC_CONDITION_CODE_NAMES \
2263 {"$cc0", RTYPE_FCC | RTYPE_CCC | 0}, \
2264 {"$cc1", RTYPE_FCC | RTYPE_CCC | 1}, \
2265 {"$cc2", RTYPE_FCC | RTYPE_CCC | 2}, \
2266 {"$cc3", RTYPE_FCC | RTYPE_CCC | 3}, \
2267 {"$cc4", RTYPE_FCC | RTYPE_CCC | 4}, \
2268 {"$cc5", RTYPE_FCC | RTYPE_CCC | 5}, \
2269 {"$cc6", RTYPE_FCC | RTYPE_CCC | 6}, \
2270 {"$cc7", RTYPE_FCC | RTYPE_CCC | 7}
2272 #define N32N64_SYMBOLIC_REGISTER_NAMES \
2273 {"$a4", RTYPE_GP | 8}, \
2274 {"$a5", RTYPE_GP | 9}, \
2275 {"$a6", RTYPE_GP | 10}, \
2276 {"$a7", RTYPE_GP | 11}, \
2277 {"$ta0", RTYPE_GP | 8}, /* alias for $a4 */ \
2278 {"$ta1", RTYPE_GP | 9}, /* alias for $a5 */ \
2279 {"$ta2", RTYPE_GP | 10}, /* alias for $a6 */ \
2280 {"$ta3", RTYPE_GP | 11}, /* alias for $a7 */ \
2281 {"$t0", RTYPE_GP | 12}, \
2282 {"$t1", RTYPE_GP | 13}, \
2283 {"$t2", RTYPE_GP | 14}, \
2284 {"$t3", RTYPE_GP | 15}
2286 #define O32_SYMBOLIC_REGISTER_NAMES \
2287 {"$t0", RTYPE_GP | 8}, \
2288 {"$t1", RTYPE_GP | 9}, \
2289 {"$t2", RTYPE_GP | 10}, \
2290 {"$t3", RTYPE_GP | 11}, \
2291 {"$t4", RTYPE_GP | 12}, \
2292 {"$t5", RTYPE_GP | 13}, \
2293 {"$t6", RTYPE_GP | 14}, \
2294 {"$t7", RTYPE_GP | 15}, \
2295 {"$ta0", RTYPE_GP | 12}, /* alias for $t4 */ \
2296 {"$ta1", RTYPE_GP | 13}, /* alias for $t5 */ \
2297 {"$ta2", RTYPE_GP | 14}, /* alias for $t6 */ \
2298 {"$ta3", RTYPE_GP | 15} /* alias for $t7 */
2300 /* Remaining symbolic register names */
2301 #define SYMBOLIC_REGISTER_NAMES \
2302 {"$zero", RTYPE_GP | 0}, \
2303 {"$at", RTYPE_GP | 1}, \
2304 {"$AT", RTYPE_GP | 1}, \
2305 {"$v0", RTYPE_GP | 2}, \
2306 {"$v1", RTYPE_GP | 3}, \
2307 {"$a0", RTYPE_GP | 4}, \
2308 {"$a1", RTYPE_GP | 5}, \
2309 {"$a2", RTYPE_GP | 6}, \
2310 {"$a3", RTYPE_GP | 7}, \
2311 {"$s0", RTYPE_GP | 16}, \
2312 {"$s1", RTYPE_GP | 17}, \
2313 {"$s2", RTYPE_GP | 18}, \
2314 {"$s3", RTYPE_GP | 19}, \
2315 {"$s4", RTYPE_GP | 20}, \
2316 {"$s5", RTYPE_GP | 21}, \
2317 {"$s6", RTYPE_GP | 22}, \
2318 {"$s7", RTYPE_GP | 23}, \
2319 {"$t8", RTYPE_GP | 24}, \
2320 {"$t9", RTYPE_GP | 25}, \
2321 {"$k0", RTYPE_GP | 26}, \
2322 {"$kt0", RTYPE_GP | 26}, \
2323 {"$k1", RTYPE_GP | 27}, \
2324 {"$kt1", RTYPE_GP | 27}, \
2325 {"$gp", RTYPE_GP | 28}, \
2326 {"$sp", RTYPE_GP | 29}, \
2327 {"$s8", RTYPE_GP | 30}, \
2328 {"$fp", RTYPE_GP | 30}, \
2329 {"$ra", RTYPE_GP | 31}
2331 #define MIPS16_SPECIAL_REGISTER_NAMES \
2332 {"$pc", RTYPE_PC | 0}
2334 #define MDMX_VECTOR_REGISTER_NAMES \
2335 /* {"$v0", RTYPE_VEC | 0}, clash with REG 2 above */ \
2336 /* {"$v1", RTYPE_VEC | 1}, clash with REG 3 above */ \
2337 {"$v2", RTYPE_VEC | 2}, \
2338 {"$v3", RTYPE_VEC | 3}, \
2339 {"$v4", RTYPE_VEC | 4}, \
2340 {"$v5", RTYPE_VEC | 5}, \
2341 {"$v6", RTYPE_VEC | 6}, \
2342 {"$v7", RTYPE_VEC | 7}, \
2343 {"$v8", RTYPE_VEC | 8}, \
2344 {"$v9", RTYPE_VEC | 9}, \
2345 {"$v10", RTYPE_VEC | 10}, \
2346 {"$v11", RTYPE_VEC | 11}, \
2347 {"$v12", RTYPE_VEC | 12}, \
2348 {"$v13", RTYPE_VEC | 13}, \
2349 {"$v14", RTYPE_VEC | 14}, \
2350 {"$v15", RTYPE_VEC | 15}, \
2351 {"$v16", RTYPE_VEC | 16}, \
2352 {"$v17", RTYPE_VEC | 17}, \
2353 {"$v18", RTYPE_VEC | 18}, \
2354 {"$v19", RTYPE_VEC | 19}, \
2355 {"$v20", RTYPE_VEC | 20}, \
2356 {"$v21", RTYPE_VEC | 21}, \
2357 {"$v22", RTYPE_VEC | 22}, \
2358 {"$v23", RTYPE_VEC | 23}, \
2359 {"$v24", RTYPE_VEC | 24}, \
2360 {"$v25", RTYPE_VEC | 25}, \
2361 {"$v26", RTYPE_VEC | 26}, \
2362 {"$v27", RTYPE_VEC | 27}, \
2363 {"$v28", RTYPE_VEC | 28}, \
2364 {"$v29", RTYPE_VEC | 29}, \
2365 {"$v30", RTYPE_VEC | 30}, \
2366 {"$v31", RTYPE_VEC | 31}
2368 #define MIPS_DSP_ACCUMULATOR_NAMES \
2369 {"$ac0", RTYPE_ACC | 0}, \
2370 {"$ac1", RTYPE_ACC | 1}, \
2371 {"$ac2", RTYPE_ACC | 2}, \
2372 {"$ac3", RTYPE_ACC | 3}
2374 static const struct regname reg_names[] = {
2375 GENERIC_REGISTER_NUMBERS,
2377 FPU_CONDITION_CODE_NAMES,
2378 COPROC_CONDITION_CODE_NAMES,
2380 /* The $txx registers depends on the abi,
2381 these will be added later into the symbol table from
2382 one of the tables below once mips_abi is set after
2383 parsing of arguments from the command line. */
2384 SYMBOLIC_REGISTER_NAMES,
2386 MIPS16_SPECIAL_REGISTER_NAMES,
2387 MDMX_VECTOR_REGISTER_NAMES,
2388 MIPS_DSP_ACCUMULATOR_NAMES,
2392 static const struct regname reg_names_o32[] = {
2393 O32_SYMBOLIC_REGISTER_NAMES,
2397 static const struct regname reg_names_n32n64[] = {
2398 N32N64_SYMBOLIC_REGISTER_NAMES,
2402 /* Register symbols $v0 and $v1 map to GPRs 2 and 3, but they can also be
2403 interpreted as vector registers 0 and 1. If SYMVAL is the value of one
2404 of these register symbols, return the associated vector register,
2405 otherwise return SYMVAL itself. */
2408 mips_prefer_vec_regno (unsigned int symval)
2410 if ((symval & -2) == (RTYPE_GP | 2))
2411 return RTYPE_VEC | (symval & 1);
2415 /* Return true if the string at *SPTR is a valid register name. If so,
2416 move *SPTR past the register and store the register's symbol value
2417 in *SYMVAL. This symbol value includes the register number
2418 (RNUM_MASK) and register type (RTYPE_MASK). */
2421 mips_parse_register (char **sptr, unsigned int *symval)
2427 /* Find end of name. */
2429 if (is_name_beginner (*e))
2431 while (is_part_of_name (*e))
2434 /* Terminate name. */
2438 /* Look up the name. */
2439 symbol = symbol_find (s);
2442 if (!symbol || S_GET_SEGMENT (symbol) != reg_section)
2446 *symval = S_GET_VALUE (symbol);
2450 /* Check if SPTR points at a valid register specifier according to TYPES.
2451 If so, then return 1, advance S to consume the specifier and store
2452 the register's number in REGNOP, otherwise return 0. */
2455 reg_lookup (char **s, unsigned int types, unsigned int *regnop)
2459 if (mips_parse_register (s, ®no))
2461 if (types & RTYPE_VEC)
2462 regno = mips_prefer_vec_regno (regno);
2471 as_warn (_("Unrecognized register name `%s'"), *s);
2476 return regno <= RNUM_MASK;
2479 /* Token types for parsed operand lists. */
2480 enum mips_operand_token_type {
2481 /* A plain register, e.g. $f2. */
2484 /* An element of a vector, e.g. $v0[1]. */
2487 /* A continuous range of registers, e.g. $s0-$s4. */
2490 /* A (possibly relocated) expression. */
2493 /* A floating-point value. */
2496 /* A single character. This can be '(', ')' or ',', but '(' only appears
2500 /* The end of the operand list. */
2504 /* A parsed operand token. */
2505 struct mips_operand_token
2507 /* The type of token. */
2508 enum mips_operand_token_type type;
2511 /* The register symbol value for an OT_REG. */
2514 /* The register symbol value and index for an OT_REG_ELEMENT. */
2520 /* The two register symbol values involved in an OT_REG_RANGE. */
2522 unsigned int regno1;
2523 unsigned int regno2;
2526 /* The value of an OT_INTEGER. The value is represented as an
2527 expression and the relocation operators that were applied to
2528 that expression. The reloc entries are BFD_RELOC_UNUSED if no
2529 relocation operators were used. */
2532 bfd_reloc_code_real_type relocs[3];
2535 /* The binary data for an OT_FLOAT constant, and the number of bytes
2538 unsigned char data[8];
2542 /* The character represented by an OT_CHAR. */
2547 /* An obstack used to construct lists of mips_operand_tokens. */
2548 static struct obstack mips_operand_tokens;
2550 /* Give TOKEN type TYPE and add it to mips_operand_tokens. */
2553 mips_add_token (struct mips_operand_token *token,
2554 enum mips_operand_token_type type)
2557 obstack_grow (&mips_operand_tokens, token, sizeof (*token));
2560 /* Check whether S is '(' followed by a register name. Add OT_CHAR
2561 and OT_REG tokens for them if so, and return a pointer to the first
2562 unconsumed character. Return null otherwise. */
2565 mips_parse_base_start (char *s)
2567 struct mips_operand_token token;
2574 SKIP_SPACE_TABS (s);
2575 if (!mips_parse_register (&s, ®no))
2579 mips_add_token (&token, OT_CHAR);
2581 token.u.regno = regno;
2582 mips_add_token (&token, OT_REG);
2587 /* Parse one or more tokens from S. Return a pointer to the first
2588 unconsumed character on success. Return null if an error was found
2589 and store the error text in insn_error. FLOAT_FORMAT is as for
2590 mips_parse_arguments. */
2593 mips_parse_argument_token (char *s, char float_format)
2595 char *end, *save_in, *err;
2596 unsigned int regno1, regno2;
2597 struct mips_operand_token token;
2599 /* First look for "($reg", since we want to treat that as an
2600 OT_CHAR and OT_REG rather than an expression. */
2601 end = mips_parse_base_start (s);
2605 /* Handle other characters that end up as OT_CHARs. */
2606 if (*s == ')' || *s == ',')
2609 mips_add_token (&token, OT_CHAR);
2614 /* Handle tokens that start with a register. */
2615 if (mips_parse_register (&s, ®no1))
2617 SKIP_SPACE_TABS (s);
2620 /* A register range. */
2622 SKIP_SPACE_TABS (s);
2623 if (!mips_parse_register (&s, ®no2))
2625 insn_error = _("Invalid register range");
2629 token.u.reg_range.regno1 = regno1;
2630 token.u.reg_range.regno2 = regno2;
2631 mips_add_token (&token, OT_REG_RANGE);
2636 /* A vector element. */
2637 expressionS element;
2640 SKIP_SPACE_TABS (s);
2641 my_getExpression (&element, s);
2642 if (element.X_op != O_constant)
2644 insn_error = _("Vector element must be constant");
2648 SKIP_SPACE_TABS (s);
2651 insn_error = _("Missing `]'");
2656 token.u.reg_element.regno = regno1;
2657 token.u.reg_element.index = element.X_add_number;
2658 mips_add_token (&token, OT_REG_ELEMENT);
2662 /* Looks like just a plain register. */
2663 token.u.regno = regno1;
2664 mips_add_token (&token, OT_REG);
2670 /* First try to treat expressions as floats. */
2671 save_in = input_line_pointer;
2672 input_line_pointer = s;
2673 err = md_atof (float_format, (char *) token.u.flt.data,
2674 &token.u.flt.length);
2675 end = input_line_pointer;
2676 input_line_pointer = save_in;
2684 mips_add_token (&token, OT_FLOAT);
2689 /* Treat everything else as an integer expression. */
2690 token.u.integer.relocs[0] = BFD_RELOC_UNUSED;
2691 token.u.integer.relocs[1] = BFD_RELOC_UNUSED;
2692 token.u.integer.relocs[2] = BFD_RELOC_UNUSED;
2693 my_getSmallExpression (&token.u.integer.value, token.u.integer.relocs, s);
2695 mips_add_token (&token, OT_INTEGER);
2699 /* S points to the operand list for an instruction. FLOAT_FORMAT is 'f'
2700 if expressions should be treated as 32-bit floating-point constants,
2701 'd' if they should be treated as 64-bit floating-point constants,
2702 or 0 if they should be treated as integer expressions (the usual case).
2704 Return a list of tokens on success, otherwise return 0. The caller
2705 must obstack_free the list after use. */
2707 static struct mips_operand_token *
2708 mips_parse_arguments (char *s, char float_format)
2710 struct mips_operand_token token;
2712 SKIP_SPACE_TABS (s);
2715 s = mips_parse_argument_token (s, float_format);
2718 obstack_free (&mips_operand_tokens,
2719 obstack_finish (&mips_operand_tokens));
2722 SKIP_SPACE_TABS (s);
2724 mips_add_token (&token, OT_END);
2725 return (struct mips_operand_token *) obstack_finish (&mips_operand_tokens);
2728 /* Return TRUE if opcode MO is valid on the currently selected ISA, ASE
2729 and architecture. Use is_opcode_valid_16 for MIPS16 opcodes. */
2732 is_opcode_valid (const struct mips_opcode *mo)
2734 int isa = mips_opts.isa;
2735 int ase = mips_opts.ase;
2739 if (ISA_HAS_64BIT_REGS (mips_opts.isa))
2740 for (i = 0; i < ARRAY_SIZE (mips_ases); i++)
2741 if ((ase & mips_ases[i].flags) == mips_ases[i].flags)
2742 ase |= mips_ases[i].flags64;
2744 if (!opcode_is_member (mo, isa, ase, mips_opts.arch))
2747 /* Check whether the instruction or macro requires single-precision or
2748 double-precision floating-point support. Note that this information is
2749 stored differently in the opcode table for insns and macros. */
2750 if (mo->pinfo == INSN_MACRO)
2752 fp_s = mo->pinfo2 & INSN2_M_FP_S;
2753 fp_d = mo->pinfo2 & INSN2_M_FP_D;
2757 fp_s = mo->pinfo & FP_S;
2758 fp_d = mo->pinfo & FP_D;
2761 if (fp_d && (mips_opts.soft_float || mips_opts.single_float))
2764 if (fp_s && mips_opts.soft_float)
2770 /* Return TRUE if the MIPS16 opcode MO is valid on the currently
2771 selected ISA and architecture. */
2774 is_opcode_valid_16 (const struct mips_opcode *mo)
2776 return opcode_is_member (mo, mips_opts.isa, 0, mips_opts.arch);
2779 /* Return TRUE if the size of the microMIPS opcode MO matches one
2780 explicitly requested. Always TRUE in the standard MIPS mode. */
2783 is_size_valid (const struct mips_opcode *mo)
2785 if (!mips_opts.micromips)
2788 if (mips_opts.insn32)
2790 if (mo->pinfo != INSN_MACRO && micromips_insn_length (mo) != 4)
2792 if ((mo->pinfo2 & INSN2_BRANCH_DELAY_16BIT) != 0)
2795 if (!forced_insn_length)
2797 if (mo->pinfo == INSN_MACRO)
2799 return forced_insn_length == micromips_insn_length (mo);
2802 /* Return TRUE if the microMIPS opcode MO is valid for the delay slot
2803 of the preceding instruction. Always TRUE in the standard MIPS mode.
2805 We don't accept macros in 16-bit delay slots to avoid a case where
2806 a macro expansion fails because it relies on a preceding 32-bit real
2807 instruction to have matched and does not handle the operands correctly.
2808 The only macros that may expand to 16-bit instructions are JAL that
2809 cannot be placed in a delay slot anyway, and corner cases of BALIGN
2810 and BGT (that likewise cannot be placed in a delay slot) that decay to
2811 a NOP. In all these cases the macros precede any corresponding real
2812 instruction definitions in the opcode table, so they will match in the
2813 second pass where the size of the delay slot is ignored and therefore
2814 produce correct code. */
2817 is_delay_slot_valid (const struct mips_opcode *mo)
2819 if (!mips_opts.micromips)
2822 if (mo->pinfo == INSN_MACRO)
2823 return (history[0].insn_mo->pinfo2 & INSN2_BRANCH_DELAY_16BIT) == 0;
2824 if ((history[0].insn_mo->pinfo2 & INSN2_BRANCH_DELAY_32BIT) != 0
2825 && micromips_insn_length (mo) != 4)
2827 if ((history[0].insn_mo->pinfo2 & INSN2_BRANCH_DELAY_16BIT) != 0
2828 && micromips_insn_length (mo) != 2)
2834 /* For consistency checking, verify that all bits of OPCODE are
2835 specified either by the match/mask part of the instruction
2836 definition, or by the operand list. INSN_BITS says which
2837 bits of the instruction are significant and DECODE_OPERAND
2838 provides the mips_operand description of each operand. */
2841 validate_mips_insn (const struct mips_opcode *opcode,
2842 unsigned long insn_bits,
2843 const struct mips_operand *(*decode_operand) (const char *))
2846 unsigned long used_bits, doubled, undefined;
2847 const struct mips_operand *operand;
2849 if ((opcode->mask & opcode->match) != opcode->match)
2851 as_bad (_("internal: bad mips opcode (mask error): %s %s"),
2852 opcode->name, opcode->args);
2856 for (s = opcode->args; *s; ++s)
2865 operand = decode_operand (s);
2868 as_bad (_("internal: unknown operand type: %s %s"),
2869 opcode->name, opcode->args);
2872 used_bits |= ((1 << operand->size) - 1) << operand->lsb;
2873 if (operand->type == OP_MDMX_IMM_REG)
2874 /* Bit 5 is the format selector (OB vs QH). The opcode table
2875 has separate entries for each format. */
2876 used_bits &= ~(1 << (operand->lsb + 5));
2877 /* Skip prefix characters. */
2878 if (*s == '+' || *s == 'm')
2882 doubled = used_bits & opcode->mask & insn_bits;
2885 as_bad (_("internal: bad mips opcode (bits 0x%08lx doubly defined):"
2886 " %s %s"), doubled, opcode->name, opcode->args);
2889 used_bits |= opcode->mask;
2890 undefined = ~used_bits & insn_bits;
2893 as_bad (_("internal: bad mips opcode (bits 0x%08lx undefined): %s %s"),
2894 undefined, opcode->name, opcode->args);
2897 used_bits &= ~insn_bits;
2900 as_bad (_("internal: bad mips opcode (bits 0x%08lx defined): %s %s"),
2901 used_bits, opcode->name, opcode->args);
2907 /* The microMIPS version of validate_mips_insn. */
2910 validate_micromips_insn (const struct mips_opcode *opc)
2912 unsigned long insn_bits;
2913 unsigned long major;
2914 unsigned int length;
2916 length = micromips_insn_length (opc);
2917 if (length != 2 && length != 4)
2919 as_bad (_("Internal error: bad microMIPS opcode (incorrect length: %u): "
2920 "%s %s"), length, opc->name, opc->args);
2923 major = opc->match >> (10 + 8 * (length - 2));
2924 if ((length == 2 && (major & 7) != 1 && (major & 6) != 2)
2925 || (length == 4 && (major & 7) != 0 && (major & 4) != 4))
2927 as_bad (_("Internal error: bad microMIPS opcode "
2928 "(opcode/length mismatch): %s %s"), opc->name, opc->args);
2932 /* Shift piecewise to avoid an overflow where unsigned long is 32-bit. */
2933 insn_bits = 1 << 4 * length;
2934 insn_bits <<= 4 * length;
2936 return validate_mips_insn (opc, insn_bits, decode_micromips_operand);
2939 /* This function is called once, at assembler startup time. It should set up
2940 all the tables, etc. that the MD part of the assembler will need. */
2945 const char *retval = NULL;
2949 if (mips_pic != NO_PIC)
2951 if (g_switch_seen && g_switch_value != 0)
2952 as_bad (_("-G may not be used in position-independent code"));
2956 if (! bfd_set_arch_mach (stdoutput, bfd_arch_mips, file_mips_arch))
2957 as_warn (_("Could not set architecture and machine"));
2959 op_hash = hash_new ();
2961 for (i = 0; i < NUMOPCODES;)
2963 const char *name = mips_opcodes[i].name;
2965 retval = hash_insert (op_hash, name, (void *) &mips_opcodes[i]);
2968 fprintf (stderr, _("internal error: can't hash `%s': %s\n"),
2969 mips_opcodes[i].name, retval);
2970 /* Probably a memory allocation problem? Give up now. */
2971 as_fatal (_("Broken assembler. No assembly attempted."));
2975 if (mips_opcodes[i].pinfo != INSN_MACRO)
2977 if (!validate_mips_insn (&mips_opcodes[i], 0xffffffff,
2978 decode_mips_operand))
2980 if (nop_insn.insn_mo == NULL && strcmp (name, "nop") == 0)
2982 create_insn (&nop_insn, mips_opcodes + i);
2983 if (mips_fix_loongson2f_nop)
2984 nop_insn.insn_opcode = LOONGSON2F_NOP_INSN;
2985 nop_insn.fixed_p = 1;
2990 while ((i < NUMOPCODES) && !strcmp (mips_opcodes[i].name, name));
2993 mips16_op_hash = hash_new ();
2996 while (i < bfd_mips16_num_opcodes)
2998 const char *name = mips16_opcodes[i].name;
3000 retval = hash_insert (mips16_op_hash, name, (void *) &mips16_opcodes[i]);
3002 as_fatal (_("internal: can't hash `%s': %s"),
3003 mips16_opcodes[i].name, retval);
3006 if (mips16_opcodes[i].pinfo != INSN_MACRO
3007 && ((mips16_opcodes[i].match & mips16_opcodes[i].mask)
3008 != mips16_opcodes[i].match))
3010 fprintf (stderr, _("internal error: bad mips16 opcode: %s %s\n"),
3011 mips16_opcodes[i].name, mips16_opcodes[i].args);
3014 if (mips16_nop_insn.insn_mo == NULL && strcmp (name, "nop") == 0)
3016 create_insn (&mips16_nop_insn, mips16_opcodes + i);
3017 mips16_nop_insn.fixed_p = 1;
3021 while (i < bfd_mips16_num_opcodes
3022 && strcmp (mips16_opcodes[i].name, name) == 0);
3025 micromips_op_hash = hash_new ();
3028 while (i < bfd_micromips_num_opcodes)
3030 const char *name = micromips_opcodes[i].name;
3032 retval = hash_insert (micromips_op_hash, name,
3033 (void *) µmips_opcodes[i]);
3035 as_fatal (_("internal: can't hash `%s': %s"),
3036 micromips_opcodes[i].name, retval);
3038 if (micromips_opcodes[i].pinfo != INSN_MACRO)
3040 struct mips_cl_insn *micromips_nop_insn;
3042 if (!validate_micromips_insn (µmips_opcodes[i]))
3045 if (micromips_insn_length (micromips_opcodes + i) == 2)
3046 micromips_nop_insn = µmips_nop16_insn;
3047 else if (micromips_insn_length (micromips_opcodes + i) == 4)
3048 micromips_nop_insn = µmips_nop32_insn;
3052 if (micromips_nop_insn->insn_mo == NULL
3053 && strcmp (name, "nop") == 0)
3055 create_insn (micromips_nop_insn, micromips_opcodes + i);
3056 micromips_nop_insn->fixed_p = 1;
3059 while (++i < bfd_micromips_num_opcodes
3060 && strcmp (micromips_opcodes[i].name, name) == 0);
3064 as_fatal (_("Broken assembler. No assembly attempted."));
3066 /* We add all the general register names to the symbol table. This
3067 helps us detect invalid uses of them. */
3068 for (i = 0; reg_names[i].name; i++)
3069 symbol_table_insert (symbol_new (reg_names[i].name, reg_section,
3070 reg_names[i].num, /* & RNUM_MASK, */
3071 &zero_address_frag));
3073 for (i = 0; reg_names_n32n64[i].name; i++)
3074 symbol_table_insert (symbol_new (reg_names_n32n64[i].name, reg_section,
3075 reg_names_n32n64[i].num, /* & RNUM_MASK, */
3076 &zero_address_frag));
3078 for (i = 0; reg_names_o32[i].name; i++)
3079 symbol_table_insert (symbol_new (reg_names_o32[i].name, reg_section,
3080 reg_names_o32[i].num, /* & RNUM_MASK, */
3081 &zero_address_frag));
3083 obstack_init (&mips_operand_tokens);
3085 mips_no_prev_insn ();
3088 mips_cprmask[0] = 0;
3089 mips_cprmask[1] = 0;
3090 mips_cprmask[2] = 0;
3091 mips_cprmask[3] = 0;
3093 /* set the default alignment for the text section (2**2) */
3094 record_alignment (text_section, 2);
3096 bfd_set_gp_size (stdoutput, g_switch_value);
3098 /* On a native system other than VxWorks, sections must be aligned
3099 to 16 byte boundaries. When configured for an embedded ELF
3100 target, we don't bother. */
3101 if (strncmp (TARGET_OS, "elf", 3) != 0
3102 && strncmp (TARGET_OS, "vxworks", 7) != 0)
3104 (void) bfd_set_section_alignment (stdoutput, text_section, 4);
3105 (void) bfd_set_section_alignment (stdoutput, data_section, 4);
3106 (void) bfd_set_section_alignment (stdoutput, bss_section, 4);
3109 /* Create a .reginfo section for register masks and a .mdebug
3110 section for debugging information. */
3118 subseg = now_subseg;
3120 /* The ABI says this section should be loaded so that the
3121 running program can access it. However, we don't load it
3122 if we are configured for an embedded target */
3123 flags = SEC_READONLY | SEC_DATA;
3124 if (strncmp (TARGET_OS, "elf", 3) != 0)
3125 flags |= SEC_ALLOC | SEC_LOAD;
3127 if (mips_abi != N64_ABI)
3129 sec = subseg_new (".reginfo", (subsegT) 0);
3131 bfd_set_section_flags (stdoutput, sec, flags);
3132 bfd_set_section_alignment (stdoutput, sec, HAVE_NEWABI ? 3 : 2);
3134 mips_regmask_frag = frag_more (sizeof (Elf32_External_RegInfo));
3138 /* The 64-bit ABI uses a .MIPS.options section rather than
3139 .reginfo section. */
3140 sec = subseg_new (".MIPS.options", (subsegT) 0);
3141 bfd_set_section_flags (stdoutput, sec, flags);
3142 bfd_set_section_alignment (stdoutput, sec, 3);
3144 /* Set up the option header. */
3146 Elf_Internal_Options opthdr;
3149 opthdr.kind = ODK_REGINFO;
3150 opthdr.size = (sizeof (Elf_External_Options)
3151 + sizeof (Elf64_External_RegInfo));
3154 f = frag_more (sizeof (Elf_External_Options));
3155 bfd_mips_elf_swap_options_out (stdoutput, &opthdr,
3156 (Elf_External_Options *) f);
3158 mips_regmask_frag = frag_more (sizeof (Elf64_External_RegInfo));
3162 if (ECOFF_DEBUGGING)
3164 sec = subseg_new (".mdebug", (subsegT) 0);
3165 (void) bfd_set_section_flags (stdoutput, sec,
3166 SEC_HAS_CONTENTS | SEC_READONLY);
3167 (void) bfd_set_section_alignment (stdoutput, sec, 2);
3169 else if (mips_flag_pdr)
3171 pdr_seg = subseg_new (".pdr", (subsegT) 0);
3172 (void) bfd_set_section_flags (stdoutput, pdr_seg,
3173 SEC_READONLY | SEC_RELOC
3175 (void) bfd_set_section_alignment (stdoutput, pdr_seg, 2);
3178 subseg_set (seg, subseg);
3181 if (! ECOFF_DEBUGGING)
3184 if (mips_fix_vr4120)
3185 init_vr4120_conflicts ();
3191 mips_emit_delays ();
3192 if (! ECOFF_DEBUGGING)
3197 md_assemble (char *str)
3199 struct mips_cl_insn insn;
3200 bfd_reloc_code_real_type unused_reloc[3]
3201 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
3203 imm_expr.X_op = O_absent;
3204 imm2_expr.X_op = O_absent;
3205 offset_expr.X_op = O_absent;
3206 offset_reloc[0] = BFD_RELOC_UNUSED;
3207 offset_reloc[1] = BFD_RELOC_UNUSED;
3208 offset_reloc[2] = BFD_RELOC_UNUSED;
3210 mips_mark_labels ();
3211 mips_assembling_insn = TRUE;
3213 if (mips_opts.mips16)
3214 mips16_ip (str, &insn);
3217 mips_ip (str, &insn);
3218 DBG ((_("returned from mips_ip(%s) insn_opcode = 0x%x\n"),
3219 str, insn.insn_opcode));
3223 as_bad ("%s `%s'", insn_error, str);
3224 else if (insn.insn_mo->pinfo == INSN_MACRO)
3227 if (mips_opts.mips16)
3228 mips16_macro (&insn);
3235 if (offset_expr.X_op != O_absent)
3236 append_insn (&insn, &offset_expr, offset_reloc, FALSE);
3238 append_insn (&insn, NULL, unused_reloc, FALSE);
3241 mips_assembling_insn = FALSE;
3244 /* Convenience functions for abstracting away the differences between
3245 MIPS16 and non-MIPS16 relocations. */
3247 static inline bfd_boolean
3248 mips16_reloc_p (bfd_reloc_code_real_type reloc)
3252 case BFD_RELOC_MIPS16_JMP:
3253 case BFD_RELOC_MIPS16_GPREL:
3254 case BFD_RELOC_MIPS16_GOT16:
3255 case BFD_RELOC_MIPS16_CALL16:
3256 case BFD_RELOC_MIPS16_HI16_S:
3257 case BFD_RELOC_MIPS16_HI16:
3258 case BFD_RELOC_MIPS16_LO16:
3266 static inline bfd_boolean
3267 micromips_reloc_p (bfd_reloc_code_real_type reloc)
3271 case BFD_RELOC_MICROMIPS_7_PCREL_S1:
3272 case BFD_RELOC_MICROMIPS_10_PCREL_S1:
3273 case BFD_RELOC_MICROMIPS_16_PCREL_S1:
3274 case BFD_RELOC_MICROMIPS_GPREL16:
3275 case BFD_RELOC_MICROMIPS_JMP:
3276 case BFD_RELOC_MICROMIPS_HI16:
3277 case BFD_RELOC_MICROMIPS_HI16_S:
3278 case BFD_RELOC_MICROMIPS_LO16:
3279 case BFD_RELOC_MICROMIPS_LITERAL:
3280 case BFD_RELOC_MICROMIPS_GOT16:
3281 case BFD_RELOC_MICROMIPS_CALL16:
3282 case BFD_RELOC_MICROMIPS_GOT_HI16:
3283 case BFD_RELOC_MICROMIPS_GOT_LO16:
3284 case BFD_RELOC_MICROMIPS_CALL_HI16:
3285 case BFD_RELOC_MICROMIPS_CALL_LO16:
3286 case BFD_RELOC_MICROMIPS_SUB:
3287 case BFD_RELOC_MICROMIPS_GOT_PAGE:
3288 case BFD_RELOC_MICROMIPS_GOT_OFST:
3289 case BFD_RELOC_MICROMIPS_GOT_DISP:
3290 case BFD_RELOC_MICROMIPS_HIGHEST:
3291 case BFD_RELOC_MICROMIPS_HIGHER:
3292 case BFD_RELOC_MICROMIPS_SCN_DISP:
3293 case BFD_RELOC_MICROMIPS_JALR:
3301 static inline bfd_boolean
3302 jmp_reloc_p (bfd_reloc_code_real_type reloc)
3304 return reloc == BFD_RELOC_MIPS_JMP || reloc == BFD_RELOC_MICROMIPS_JMP;
3307 static inline bfd_boolean
3308 got16_reloc_p (bfd_reloc_code_real_type reloc)
3310 return (reloc == BFD_RELOC_MIPS_GOT16 || reloc == BFD_RELOC_MIPS16_GOT16
3311 || reloc == BFD_RELOC_MICROMIPS_GOT16);
3314 static inline bfd_boolean
3315 hi16_reloc_p (bfd_reloc_code_real_type reloc)
3317 return (reloc == BFD_RELOC_HI16_S || reloc == BFD_RELOC_MIPS16_HI16_S
3318 || reloc == BFD_RELOC_MICROMIPS_HI16_S);
3321 static inline bfd_boolean
3322 lo16_reloc_p (bfd_reloc_code_real_type reloc)
3324 return (reloc == BFD_RELOC_LO16 || reloc == BFD_RELOC_MIPS16_LO16
3325 || reloc == BFD_RELOC_MICROMIPS_LO16);
3328 static inline bfd_boolean
3329 jalr_reloc_p (bfd_reloc_code_real_type reloc)
3331 return reloc == BFD_RELOC_MIPS_JALR || reloc == BFD_RELOC_MICROMIPS_JALR;
3334 static inline bfd_boolean
3335 gprel16_reloc_p (bfd_reloc_code_real_type reloc)
3337 return (reloc == BFD_RELOC_GPREL16 || reloc == BFD_RELOC_MIPS16_GPREL
3338 || reloc == BFD_RELOC_MICROMIPS_GPREL16);
3341 /* Return true if RELOC is a PC-relative relocation that does not have
3342 full address range. */
3344 static inline bfd_boolean
3345 limited_pcrel_reloc_p (bfd_reloc_code_real_type reloc)
3349 case BFD_RELOC_16_PCREL_S2:
3350 case BFD_RELOC_MICROMIPS_7_PCREL_S1:
3351 case BFD_RELOC_MICROMIPS_10_PCREL_S1:
3352 case BFD_RELOC_MICROMIPS_16_PCREL_S1:
3355 case BFD_RELOC_32_PCREL:
3356 return HAVE_64BIT_ADDRESSES;
3363 /* Return true if the given relocation might need a matching %lo().
3364 This is only "might" because SVR4 R_MIPS_GOT16 relocations only
3365 need a matching %lo() when applied to local symbols. */
3367 static inline bfd_boolean
3368 reloc_needs_lo_p (bfd_reloc_code_real_type reloc)
3370 return (HAVE_IN_PLACE_ADDENDS
3371 && (hi16_reloc_p (reloc)
3372 /* VxWorks R_MIPS_GOT16 relocs never need a matching %lo();
3373 all GOT16 relocations evaluate to "G". */
3374 || (got16_reloc_p (reloc) && mips_pic != VXWORKS_PIC)));
3377 /* Return the type of %lo() reloc needed by RELOC, given that
3378 reloc_needs_lo_p. */
3380 static inline bfd_reloc_code_real_type
3381 matching_lo_reloc (bfd_reloc_code_real_type reloc)
3383 return (mips16_reloc_p (reloc) ? BFD_RELOC_MIPS16_LO16
3384 : (micromips_reloc_p (reloc) ? BFD_RELOC_MICROMIPS_LO16
3388 /* Return true if the given fixup is followed by a matching R_MIPS_LO16
3391 static inline bfd_boolean
3392 fixup_has_matching_lo_p (fixS *fixp)
3394 return (fixp->fx_next != NULL
3395 && fixp->fx_next->fx_r_type == matching_lo_reloc (fixp->fx_r_type)
3396 && fixp->fx_addsy == fixp->fx_next->fx_addsy
3397 && fixp->fx_offset == fixp->fx_next->fx_offset);
3400 /* This function returns true if modifying a register requires a
3404 reg_needs_delay (unsigned int reg)
3406 unsigned long prev_pinfo;
3408 prev_pinfo = history[0].insn_mo->pinfo;
3409 if (! mips_opts.noreorder
3410 && (((prev_pinfo & INSN_LOAD_MEMORY_DELAY)
3411 && ! gpr_interlocks)
3412 || ((prev_pinfo & INSN_LOAD_COPROC_DELAY)
3413 && ! cop_interlocks)))
3415 /* A load from a coprocessor or from memory. All load delays
3416 delay the use of general register rt for one instruction. */
3417 /* Itbl support may require additional care here. */
3418 know (prev_pinfo & INSN_WRITE_GPR_T);
3419 if (reg == EXTRACT_OPERAND (mips_opts.micromips, RT, history[0]))
3426 /* Move all labels in LABELS to the current insertion point. TEXT_P
3427 says whether the labels refer to text or data. */
3430 mips_move_labels (struct insn_label_list *labels, bfd_boolean text_p)
3432 struct insn_label_list *l;
3435 for (l = labels; l != NULL; l = l->next)
3437 gas_assert (S_GET_SEGMENT (l->label) == now_seg);
3438 symbol_set_frag (l->label, frag_now);
3439 val = (valueT) frag_now_fix ();
3440 /* MIPS16/microMIPS text labels are stored as odd. */
3441 if (text_p && HAVE_CODE_COMPRESSION)
3443 S_SET_VALUE (l->label, val);
3447 /* Move all labels in insn_labels to the current insertion point
3448 and treat them as text labels. */
3451 mips_move_text_labels (void)
3453 mips_move_labels (seg_info (now_seg)->label_list, TRUE);
3457 s_is_linkonce (symbolS *sym, segT from_seg)
3459 bfd_boolean linkonce = FALSE;
3460 segT symseg = S_GET_SEGMENT (sym);
3462 if (symseg != from_seg && !S_IS_LOCAL (sym))
3464 if ((bfd_get_section_flags (stdoutput, symseg) & SEC_LINK_ONCE))
3466 /* The GNU toolchain uses an extension for ELF: a section
3467 beginning with the magic string .gnu.linkonce is a
3468 linkonce section. */
3469 if (strncmp (segment_name (symseg), ".gnu.linkonce",
3470 sizeof ".gnu.linkonce" - 1) == 0)
3476 /* Mark MIPS16 or microMIPS instruction label LABEL. This permits the
3477 linker to handle them specially, such as generating jalx instructions
3478 when needed. We also make them odd for the duration of the assembly,
3479 in order to generate the right sort of code. We will make them even
3480 in the adjust_symtab routine, while leaving them marked. This is
3481 convenient for the debugger and the disassembler. The linker knows
3482 to make them odd again. */
3485 mips_compressed_mark_label (symbolS *label)
3487 gas_assert (HAVE_CODE_COMPRESSION);
3489 if (mips_opts.mips16)
3490 S_SET_OTHER (label, ELF_ST_SET_MIPS16 (S_GET_OTHER (label)));
3492 S_SET_OTHER (label, ELF_ST_SET_MICROMIPS (S_GET_OTHER (label)));
3493 if ((S_GET_VALUE (label) & 1) == 0
3494 /* Don't adjust the address if the label is global or weak, or
3495 in a link-once section, since we'll be emitting symbol reloc
3496 references to it which will be patched up by the linker, and
3497 the final value of the symbol may or may not be MIPS16/microMIPS. */
3498 && !S_IS_WEAK (label)
3499 && !S_IS_EXTERNAL (label)
3500 && !s_is_linkonce (label, now_seg))
3501 S_SET_VALUE (label, S_GET_VALUE (label) | 1);
3504 /* Mark preceding MIPS16 or microMIPS instruction labels. */
3507 mips_compressed_mark_labels (void)
3509 struct insn_label_list *l;
3511 for (l = seg_info (now_seg)->label_list; l != NULL; l = l->next)
3512 mips_compressed_mark_label (l->label);
3515 /* End the current frag. Make it a variant frag and record the
3519 relax_close_frag (void)
3521 mips_macro_warning.first_frag = frag_now;
3522 frag_var (rs_machine_dependent, 0, 0,
3523 RELAX_ENCODE (mips_relax.sizes[0], mips_relax.sizes[1]),
3524 mips_relax.symbol, 0, (char *) mips_relax.first_fixup);
3526 memset (&mips_relax.sizes, 0, sizeof (mips_relax.sizes));
3527 mips_relax.first_fixup = 0;
3530 /* Start a new relaxation sequence whose expansion depends on SYMBOL.
3531 See the comment above RELAX_ENCODE for more details. */
3534 relax_start (symbolS *symbol)
3536 gas_assert (mips_relax.sequence == 0);
3537 mips_relax.sequence = 1;
3538 mips_relax.symbol = symbol;
3541 /* Start generating the second version of a relaxable sequence.
3542 See the comment above RELAX_ENCODE for more details. */
3547 gas_assert (mips_relax.sequence == 1);
3548 mips_relax.sequence = 2;
3551 /* End the current relaxable sequence. */
3556 gas_assert (mips_relax.sequence == 2);
3557 relax_close_frag ();
3558 mips_relax.sequence = 0;
3561 /* Return true if IP is a delayed branch or jump. */
3563 static inline bfd_boolean
3564 delayed_branch_p (const struct mips_cl_insn *ip)
3566 return (ip->insn_mo->pinfo & (INSN_UNCOND_BRANCH_DELAY
3567 | INSN_COND_BRANCH_DELAY
3568 | INSN_COND_BRANCH_LIKELY)) != 0;
3571 /* Return true if IP is a compact branch or jump. */
3573 static inline bfd_boolean
3574 compact_branch_p (const struct mips_cl_insn *ip)
3576 if (mips_opts.mips16)
3577 return (ip->insn_mo->pinfo & (MIPS16_INSN_UNCOND_BRANCH
3578 | MIPS16_INSN_COND_BRANCH)) != 0;
3580 return (ip->insn_mo->pinfo2 & (INSN2_UNCOND_BRANCH
3581 | INSN2_COND_BRANCH)) != 0;
3584 /* Return true if IP is an unconditional branch or jump. */
3586 static inline bfd_boolean
3587 uncond_branch_p (const struct mips_cl_insn *ip)
3589 return ((ip->insn_mo->pinfo & INSN_UNCOND_BRANCH_DELAY) != 0
3590 || (mips_opts.mips16
3591 ? (ip->insn_mo->pinfo & MIPS16_INSN_UNCOND_BRANCH) != 0
3592 : (ip->insn_mo->pinfo2 & INSN2_UNCOND_BRANCH) != 0));
3595 /* Return true if IP is a branch-likely instruction. */
3597 static inline bfd_boolean
3598 branch_likely_p (const struct mips_cl_insn *ip)
3600 return (ip->insn_mo->pinfo & INSN_COND_BRANCH_LIKELY) != 0;
3603 /* Return the type of nop that should be used to fill the delay slot
3604 of delayed branch IP. */
3606 static struct mips_cl_insn *
3607 get_delay_slot_nop (const struct mips_cl_insn *ip)
3609 if (mips_opts.micromips
3610 && (ip->insn_mo->pinfo2 & INSN2_BRANCH_DELAY_32BIT))
3611 return µmips_nop32_insn;
3615 /* Return the mask of core registers that IP reads or writes. */
3618 gpr_mod_mask (const struct mips_cl_insn *ip)
3620 unsigned long pinfo2;
3624 pinfo2 = ip->insn_mo->pinfo2;
3625 if (mips_opts.micromips)
3627 if (pinfo2 & INSN2_MOD_GPR_MD)
3628 mask |= 1 << micromips_to_32_reg_d_map[EXTRACT_OPERAND (1, MD, *ip)];
3629 if (pinfo2 & INSN2_MOD_GPR_MF)
3630 mask |= 1 << micromips_to_32_reg_f_map[EXTRACT_OPERAND (1, MF, *ip)];
3631 if (pinfo2 & INSN2_MOD_SP)
3637 /* Return the mask of core registers that IP reads. */
3640 gpr_read_mask (const struct mips_cl_insn *ip)
3642 unsigned long pinfo, pinfo2;
3645 mask = gpr_mod_mask (ip);
3646 pinfo = ip->insn_mo->pinfo;
3647 pinfo2 = ip->insn_mo->pinfo2;
3648 if (mips_opts.mips16)
3650 if (pinfo & MIPS16_INSN_READ_X)
3651 mask |= 1 << mips16_to_32_reg_map[MIPS16_EXTRACT_OPERAND (RX, *ip)];
3652 if (pinfo & MIPS16_INSN_READ_Y)
3653 mask |= 1 << mips16_to_32_reg_map[MIPS16_EXTRACT_OPERAND (RY, *ip)];
3654 if (pinfo & MIPS16_INSN_READ_T)
3656 if (pinfo & MIPS16_INSN_READ_SP)
3658 if (pinfo & MIPS16_INSN_READ_31)
3660 if (pinfo & MIPS16_INSN_READ_Z)
3661 mask |= 1 << (mips16_to_32_reg_map
3662 [MIPS16_EXTRACT_OPERAND (MOVE32Z, *ip)]);
3663 if (pinfo & MIPS16_INSN_READ_GPR_X)
3664 mask |= 1 << MIPS16_EXTRACT_OPERAND (REGR32, *ip);
3668 if (pinfo2 & INSN2_READ_GPR_D)
3669 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RD, *ip);
3670 if (pinfo & INSN_READ_GPR_T)
3671 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RT, *ip);
3672 if (pinfo & INSN_READ_GPR_S)
3673 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RS, *ip);
3674 if (pinfo2 & INSN2_READ_GP)
3676 if (pinfo2 & INSN2_READ_GPR_31)
3678 if (pinfo2 & INSN2_READ_GPR_Z)
3679 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RZ, *ip);
3681 if (mips_opts.micromips)
3683 if (pinfo2 & INSN2_READ_GPR_MC)
3684 mask |= 1 << micromips_to_32_reg_c_map[EXTRACT_OPERAND (1, MC, *ip)];
3685 if (pinfo2 & INSN2_READ_GPR_ME)
3686 mask |= 1 << micromips_to_32_reg_e_map[EXTRACT_OPERAND (1, ME, *ip)];
3687 if (pinfo2 & INSN2_READ_GPR_MG)
3688 mask |= 1 << micromips_to_32_reg_g_map[EXTRACT_OPERAND (1, MG, *ip)];
3689 if (pinfo2 & INSN2_READ_GPR_MJ)
3690 mask |= 1 << EXTRACT_OPERAND (1, MJ, *ip);
3691 if (pinfo2 & INSN2_READ_GPR_MMN)
3693 mask |= 1 << micromips_to_32_reg_m_map[EXTRACT_OPERAND (1, MM, *ip)];
3694 mask |= 1 << micromips_to_32_reg_n_map[EXTRACT_OPERAND (1, MN, *ip)];
3696 if (pinfo2 & INSN2_READ_GPR_MP)
3697 mask |= 1 << EXTRACT_OPERAND (1, MP, *ip);
3698 if (pinfo2 & INSN2_READ_GPR_MQ)
3699 mask |= 1 << micromips_to_32_reg_q_map[EXTRACT_OPERAND (1, MQ, *ip)];
3701 /* Don't include register 0. */
3705 /* Return the mask of core registers that IP writes. */
3708 gpr_write_mask (const struct mips_cl_insn *ip)
3710 unsigned long pinfo, pinfo2;
3713 mask = gpr_mod_mask (ip);
3714 pinfo = ip->insn_mo->pinfo;
3715 pinfo2 = ip->insn_mo->pinfo2;
3716 if (mips_opts.mips16)
3718 if (pinfo & MIPS16_INSN_WRITE_X)
3719 mask |= 1 << mips16_to_32_reg_map[MIPS16_EXTRACT_OPERAND (RX, *ip)];
3720 if (pinfo & MIPS16_INSN_WRITE_Y)
3721 mask |= 1 << mips16_to_32_reg_map[MIPS16_EXTRACT_OPERAND (RY, *ip)];
3722 if (pinfo & MIPS16_INSN_WRITE_Z)
3723 mask |= 1 << mips16_to_32_reg_map[MIPS16_EXTRACT_OPERAND (RZ, *ip)];
3724 if (pinfo & MIPS16_INSN_WRITE_T)
3726 if (pinfo & MIPS16_INSN_WRITE_SP)
3728 if (pinfo & MIPS16_INSN_WRITE_31)
3730 if (pinfo & MIPS16_INSN_WRITE_GPR_Y)
3731 mask |= 1 << MIPS16OP_EXTRACT_REG32R (ip->insn_opcode);
3735 if (pinfo & INSN_WRITE_GPR_D)
3736 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RD, *ip);
3737 if (pinfo & INSN_WRITE_GPR_T)
3738 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RT, *ip);
3739 if (pinfo & INSN_WRITE_GPR_S)
3740 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RS, *ip);
3741 if (pinfo & INSN_WRITE_GPR_31)
3743 if (pinfo2 & INSN2_WRITE_GPR_Z)
3744 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RZ, *ip);
3746 if (mips_opts.micromips)
3748 if (pinfo2 & INSN2_WRITE_GPR_MB)
3749 mask |= 1 << micromips_to_32_reg_b_map[EXTRACT_OPERAND (1, MB, *ip)];
3750 if (pinfo2 & INSN2_WRITE_GPR_MH)
3752 mask |= 1 << micromips_to_32_reg_h_map1[EXTRACT_OPERAND (1, MH, *ip)];
3753 mask |= 1 << micromips_to_32_reg_h_map2[EXTRACT_OPERAND (1, MH, *ip)];
3755 if (pinfo2 & INSN2_WRITE_GPR_MJ)
3756 mask |= 1 << EXTRACT_OPERAND (1, MJ, *ip);
3757 if (pinfo2 & INSN2_WRITE_GPR_MP)
3758 mask |= 1 << EXTRACT_OPERAND (1, MP, *ip);
3760 /* Don't include register 0. */
3764 /* Return the mask of floating-point registers that IP reads. */
3767 fpr_read_mask (const struct mips_cl_insn *ip)
3769 unsigned long pinfo, pinfo2;
3773 pinfo = ip->insn_mo->pinfo;
3774 pinfo2 = ip->insn_mo->pinfo2;
3775 if (!mips_opts.mips16)
3777 if (pinfo2 & INSN2_READ_FPR_D)
3778 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FD, *ip);
3779 if (pinfo & INSN_READ_FPR_S)
3780 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FS, *ip);
3781 if (pinfo & INSN_READ_FPR_T)
3782 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FT, *ip);
3783 if (pinfo & INSN_READ_FPR_R)
3784 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FR, *ip);
3785 if (pinfo2 & INSN2_READ_FPR_Z)
3786 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FZ, *ip);
3788 /* Conservatively treat all operands to an FP_D instruction are doubles.
3789 (This is overly pessimistic for things like cvt.d.s.) */
3790 if (HAVE_32BIT_FPRS && (pinfo & FP_D))
3795 /* Return the mask of floating-point registers that IP writes. */
3798 fpr_write_mask (const struct mips_cl_insn *ip)
3800 unsigned long pinfo, pinfo2;
3804 pinfo = ip->insn_mo->pinfo;
3805 pinfo2 = ip->insn_mo->pinfo2;
3806 if (!mips_opts.mips16)
3808 if (pinfo & INSN_WRITE_FPR_D)
3809 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FD, *ip);
3810 if (pinfo & INSN_WRITE_FPR_S)
3811 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FS, *ip);
3812 if (pinfo & INSN_WRITE_FPR_T)
3813 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FT, *ip);
3814 if (pinfo2 & INSN2_WRITE_FPR_Z)
3815 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FZ, *ip);
3817 /* Conservatively treat all operands to an FP_D instruction are doubles.
3818 (This is overly pessimistic for things like cvt.s.d.) */
3819 if (HAVE_32BIT_FPRS && (pinfo & FP_D))
3824 /* Operand OPNUM of INSN is an odd-numbered floating-point register.
3825 Check whether that is allowed. */
3828 mips_oddfpreg_ok (const struct mips_opcode *insn, int opnum)
3830 const char *s = insn->name;
3832 if (insn->pinfo == INSN_MACRO)
3833 /* Let a macro pass, we'll catch it later when it is expanded. */
3836 if (ISA_HAS_ODD_SINGLE_FPR (mips_opts.isa) || mips_opts.arch == CPU_R5900)
3838 /* Allow odd registers for single-precision ops. */
3839 switch (insn->pinfo & (FP_S | FP_D))
3850 /* Cvt.w.x and cvt.x.w allow an odd register for a 'w' or 's' operand. */
3851 s = strchr (insn->name, '.');
3852 if (s != NULL && opnum == 2)
3853 s = strchr (s + 1, '.');
3854 return (s != NULL && (s[1] == 'w' || s[1] == 's'));
3857 /* Single-precision coprocessor loads and moves are OK too. */
3858 if ((insn->pinfo & FP_S)
3859 && (insn->pinfo & (INSN_COPROC_MEMORY_DELAY | INSN_STORE_MEMORY
3860 | INSN_LOAD_COPROC_DELAY | INSN_COPROC_MOVE_DELAY)))
3866 /* Report that user-supplied argument ARGNUM for INSN was VAL, but should
3867 have been in the range [MIN_VAL, MAX_VAL]. PRINT_HEX says whether
3868 this operand is normally printed in hex or decimal. */
3871 report_bad_range (struct mips_cl_insn *insn, int argnum,
3872 offsetT val, int min_val, int max_val,
3873 bfd_boolean print_hex)
3875 if (print_hex && val >= 0)
3876 as_bad (_("Operand %d of `%s' must be in the range [0x%x, 0x%x],"
3878 argnum, insn->insn_mo->name, min_val, max_val, (unsigned long) val);
3880 as_bad (_("Operand %d of `%s' must be in the range [0x%x, 0x%x],"
3882 argnum, insn->insn_mo->name, min_val, max_val, (unsigned long) val);
3884 as_bad (_("Operand %d of `%s' must be in the range [%d, %d],"
3886 argnum, insn->insn_mo->name, min_val, max_val, (unsigned long) val);
3889 /* Report an invalid combination of position and size operands for a bitfield
3890 operation. POS and SIZE are the values that were given. */
3893 report_bad_field (offsetT pos, offsetT size)
3895 as_bad (_("Invalid field specification (position %ld, size %ld)"),
3896 (unsigned long) pos, (unsigned long) size);
3899 /* Information about an instruction argument that we're trying to match. */
3900 struct mips_arg_info
3902 /* The instruction so far. */
3903 struct mips_cl_insn *insn;
3905 /* The first unconsumed operand token. */
3906 struct mips_operand_token *token;
3908 /* The 1-based operand number, in terms of insn->insn_mo->args. */
3911 /* The 1-based argument number, for error reporting. This does not
3912 count elided optional registers, etc.. */
3915 /* The last OP_REG operand seen, or ILLEGAL_REG if none. */
3916 unsigned int last_regno;
3918 /* If the first operand was an OP_REG, this is the register that it
3919 specified, otherwise it is ILLEGAL_REG. */
3920 unsigned int dest_regno;
3922 /* The value of the last OP_INT operand. Only used for OP_MSB,
3923 where it gives the lsb position. */
3924 unsigned int last_op_int;
3926 /* If true, match routines should silently reject invalid arguments.
3927 If false, match routines can accept invalid arguments as long as
3928 they report an appropriate error. They still have the option of
3929 silently rejecting arguments, in which case a generic "Invalid operands"
3930 style of error will be used instead. */
3931 bfd_boolean soft_match;
3933 /* If true, the OP_INT match routine should treat plain symbolic operands
3934 as if a relocation operator like %lo(...) had been used. This is only
3935 ever true if the operand can be relocated. */
3936 bfd_boolean allow_nonconst;
3938 /* When true, the OP_INT match routine should allow unsigned N-bit
3939 arguments to be used where a signed N-bit operand is expected. */
3940 bfd_boolean lax_max;
3942 /* True if a reference to the current AT register was seen. */
3943 bfd_boolean seen_at;
3946 /* Try to match an OT_CHAR token for character CH. Consume the token
3947 and return true on success, otherwise return false. */
3950 match_char (struct mips_arg_info *arg, char ch)
3952 if (arg->token->type == OT_CHAR && arg->token->u.ch == ch)
3962 /* Try to get an expression from the next tokens in ARG. Consume the
3963 tokens and return true on success, storing the expression value in
3964 VALUE and relocation types in R. */
3967 match_expression (struct mips_arg_info *arg, expressionS *value,
3968 bfd_reloc_code_real_type *r)
3970 if (arg->token->type == OT_INTEGER)
3972 *value = arg->token->u.integer.value;
3973 memcpy (r, arg->token->u.integer.relocs, 3 * sizeof (*r));
3978 /* Error-reporting is more consistent if we treat registers as O_register
3979 rather than rejecting them outright. "$1", "($1)" and "(($1))" are
3980 then handled in the same way. */
3981 if (arg->token->type == OT_REG)
3983 value->X_add_number = arg->token->u.regno;
3986 else if (arg->token[0].type == OT_CHAR
3987 && arg->token[0].u.ch == '('
3988 && arg->token[1].type == OT_REG
3989 && arg->token[2].type == OT_CHAR
3990 && arg->token[2].u.ch == ')')
3992 value->X_add_number = arg->token[1].u.regno;
3998 value->X_op = O_register;
3999 r[0] = r[1] = r[2] = BFD_RELOC_UNUSED;
4003 /* Try to get a constant expression from the next tokens in ARG. Consume
4004 the tokens and return return true on success, storing the constant value
4005 in *VALUE. Use FALLBACK as the value if the match succeeded with an
4009 match_const_int (struct mips_arg_info *arg, offsetT *value, offsetT fallback)
4012 bfd_reloc_code_real_type r[3];
4014 if (!match_expression (arg, &ex, r))
4017 if (r[0] == BFD_RELOC_UNUSED && ex.X_op == O_constant)
4018 *value = ex.X_add_number;
4021 if (arg->soft_match)
4023 as_bad (_("Operand %d of `%s' must be constant"),
4024 arg->argnum, arg->insn->insn_mo->name);
4030 /* Return the RTYPE_* flags for a register operand of type TYPE that
4031 appears in instruction OPCODE. */
4034 convert_reg_type (const struct mips_opcode *opcode,
4035 enum mips_reg_operand_type type)
4040 return RTYPE_NUM | RTYPE_GP;
4043 /* Allow vector register names for MDMX if the instruction is a 64-bit
4044 FPR load, store or move (including moves to and from GPRs). */
4045 if ((mips_opts.ase & ASE_MDMX)
4046 && (opcode->pinfo & FP_D)
4047 && (opcode->pinfo & (INSN_COPROC_MOVE_DELAY
4048 | INSN_COPROC_MEMORY_DELAY
4049 | INSN_LOAD_COPROC_DELAY
4050 | INSN_LOAD_MEMORY_DELAY
4051 | INSN_STORE_MEMORY)))
4052 return RTYPE_FPU | RTYPE_VEC;
4056 if (opcode->pinfo & (FP_D | FP_S))
4057 return RTYPE_CCC | RTYPE_FCC;
4061 if (opcode->membership & INSN_5400)
4063 return RTYPE_FPU | RTYPE_VEC;
4069 if (opcode->name[strlen (opcode->name) - 1] == '0')
4070 return RTYPE_NUM | RTYPE_CP0;
4079 /* ARG is register REGNO, of type TYPE. Warn about any dubious registers. */
4082 check_regno (struct mips_arg_info *arg,
4083 enum mips_reg_operand_type type, unsigned int regno)
4085 if (AT && type == OP_REG_GP && regno == AT)
4086 arg->seen_at = TRUE;
4088 if (type == OP_REG_FP
4091 && !mips_oddfpreg_ok (arg->insn->insn_mo, arg->opnum))
4092 as_warn (_("Float register should be even, was %d"), regno);
4094 if (type == OP_REG_CCC)
4099 name = arg->insn->insn_mo->name;
4100 length = strlen (name);
4101 if ((regno & 1) != 0
4102 && ((length >= 3 && strcmp (name + length - 3, ".ps") == 0)
4103 || (length >= 5 && strncmp (name + length - 5, "any2", 4) == 0)))
4104 as_warn (_("Condition code register should be even for %s, was %d"),
4107 if ((regno & 3) != 0
4108 && (length >= 5 && strncmp (name + length - 5, "any4", 4) == 0))
4109 as_warn (_("Condition code register should be 0 or 4 for %s, was %d"),
4114 /* ARG is a register with symbol value SYMVAL. Try to interpret it as
4115 a register of type TYPE. Return true on success, storing the register
4116 number in *REGNO and warning about any dubious uses. */
4119 match_regno (struct mips_arg_info *arg, enum mips_reg_operand_type type,
4120 unsigned int symval, unsigned int *regno)
4122 if (type == OP_REG_VEC)
4123 symval = mips_prefer_vec_regno (symval);
4124 if (!(symval & convert_reg_type (arg->insn->insn_mo, type)))
4127 *regno = symval & RNUM_MASK;
4128 check_regno (arg, type, *regno);
4132 /* Try to interpret the next token in ARG as a register of type TYPE.
4133 Consume the token and return true on success, storing the register
4134 number in *REGNO. Return false on failure. */
4137 match_reg (struct mips_arg_info *arg, enum mips_reg_operand_type type,
4138 unsigned int *regno)
4140 if (arg->token->type == OT_REG
4141 && match_regno (arg, type, arg->token->u.regno, regno))
4149 /* Try to interpret the next token in ARG as a range of registers of type TYPE.
4150 Consume the token and return true on success, storing the register numbers
4151 in *REGNO1 and *REGNO2. Return false on failure. */
4154 match_reg_range (struct mips_arg_info *arg, enum mips_reg_operand_type type,
4155 unsigned int *regno1, unsigned int *regno2)
4157 if (match_reg (arg, type, regno1))
4162 if (arg->token->type == OT_REG_RANGE
4163 && match_regno (arg, type, arg->token->u.reg_range.regno1, regno1)
4164 && match_regno (arg, type, arg->token->u.reg_range.regno2, regno2)
4165 && *regno1 <= *regno2)
4173 /* OP_INT matcher. */
4176 match_int_operand (struct mips_arg_info *arg,
4177 const struct mips_operand *operand_base)
4179 const struct mips_int_operand *operand;
4180 unsigned int uval, mask;
4181 int min_val, max_val, factor;
4183 bfd_boolean print_hex;
4185 operand = (const struct mips_int_operand *) operand_base;
4186 factor = 1 << operand->shift;
4187 mask = (1 << operand_base->size) - 1;
4188 max_val = (operand->max_val + operand->bias) << operand->shift;
4189 min_val = max_val - (mask << operand->shift);
4191 max_val = mask << operand->shift;
4193 if (arg->token->type == OT_CHAR && arg->token->u.ch == '(')
4194 /* Assume we have an elided offset. The later match will fail
4195 if this turns out to be wrong. */
4197 else if (operand_base->lsb == 0
4198 && operand_base->size == 16
4199 && operand->shift == 0
4200 && operand->bias == 0
4201 && (operand->max_val == 32767 || operand->max_val == 65535))
4203 /* The operand can be relocated. */
4204 if (!match_expression (arg, &offset_expr, offset_reloc))
4207 if (offset_reloc[0] != BFD_RELOC_UNUSED)
4208 /* Relocation operators were used. Accept the arguent and
4209 leave the relocation value in offset_expr and offset_relocs
4210 for the caller to process. */
4213 if (offset_expr.X_op != O_constant)
4215 /* If non-constant operands are allowed then leave them for
4216 the caller to process, otherwise fail the match. */
4217 if (!arg->allow_nonconst)
4219 offset_reloc[0] = BFD_RELOC_LO16;
4223 /* Clear the global state; we're going to install the operand
4225 sval = offset_expr.X_add_number;
4226 offset_expr.X_op = O_absent;
4230 if (!match_const_int (arg, &sval, min_val))
4234 arg->last_op_int = sval;
4236 /* Check the range. If there's a problem, record the lowest acceptable
4237 value in arg->last_op_int in order to prevent an unhelpful error
4240 Bit counts have traditionally been printed in hex by the disassembler
4241 but printed as decimal in error messages. Only resort to hex if
4242 the operand is bigger than 6 bits. */
4243 print_hex = operand->print_hex && operand_base->size > 6;
4244 if (sval < min_val || sval > max_val)
4246 if (arg->soft_match)
4248 report_bad_range (arg->insn, arg->argnum, sval, min_val, max_val,
4250 arg->last_op_int = min_val;
4252 else if (sval % factor)
4254 if (arg->soft_match)
4256 as_bad (print_hex && sval >= 0
4257 ? _("Operand %d of `%s' must be a factor of %d, was 0x%lx.")
4258 : _("Operand %d of `%s' must be a factor of %d, was %ld."),
4259 arg->argnum, arg->insn->insn_mo->name, factor,
4260 (unsigned long) sval);
4261 arg->last_op_int = min_val;
4264 uval = (unsigned int) sval >> operand->shift;
4265 uval -= operand->bias;
4267 /* Handle -mfix-cn63xxp1. */
4269 && mips_fix_cn63xxp1
4270 && !mips_opts.micromips
4271 && strcmp ("pref", arg->insn->insn_mo->name) == 0)
4286 /* The rest must be changed to 28. */
4291 insn_insert_operand (arg->insn, operand_base, uval);
4295 /* OP_MAPPED_INT matcher. */
4298 match_mapped_int_operand (struct mips_arg_info *arg,
4299 const struct mips_operand *operand_base)
4301 const struct mips_mapped_int_operand *operand;
4302 unsigned int uval, num_vals;
4305 operand = (const struct mips_mapped_int_operand *) operand_base;
4306 if (!match_const_int (arg, &sval, operand->int_map[0]))
4309 num_vals = 1 << operand_base->size;
4310 for (uval = 0; uval < num_vals; uval++)
4311 if (operand->int_map[uval] == sval)
4313 if (uval == num_vals)
4316 insn_insert_operand (arg->insn, operand_base, uval);
4320 /* OP_MSB matcher. */
4323 match_msb_operand (struct mips_arg_info *arg,
4324 const struct mips_operand *operand_base)
4326 const struct mips_msb_operand *operand;
4327 int min_val, max_val, max_high;
4328 offsetT size, sval, high;
4330 operand = (const struct mips_msb_operand *) operand_base;
4331 min_val = operand->bias;
4332 max_val = min_val + (1 << operand_base->size) - 1;
4333 max_high = operand->opsize;
4335 if (!match_const_int (arg, &size, 1))
4338 high = size + arg->last_op_int;
4339 sval = operand->add_lsb ? high : size;
4341 if (size < 0 || high > max_high || sval < min_val || sval > max_val)
4343 if (arg->soft_match)
4345 report_bad_field (arg->last_op_int, size);
4348 insn_insert_operand (arg->insn, operand_base, sval - min_val);
4352 /* OP_REG matcher. */
4355 match_reg_operand (struct mips_arg_info *arg,
4356 const struct mips_operand *operand_base)
4358 const struct mips_reg_operand *operand;
4359 unsigned int regno, uval, num_vals;
4361 operand = (const struct mips_reg_operand *) operand_base;
4362 if (!match_reg (arg, operand->reg_type, ®no))
4365 if (operand->reg_map)
4367 num_vals = 1 << operand->root.size;
4368 for (uval = 0; uval < num_vals; uval++)
4369 if (operand->reg_map[uval] == regno)
4371 if (num_vals == uval)
4377 arg->last_regno = regno;
4378 if (arg->opnum == 1)
4379 arg->dest_regno = regno;
4380 insn_insert_operand (arg->insn, operand_base, uval);
4384 /* OP_REG_PAIR matcher. */
4387 match_reg_pair_operand (struct mips_arg_info *arg,
4388 const struct mips_operand *operand_base)
4390 const struct mips_reg_pair_operand *operand;
4391 unsigned int regno1, regno2, uval, num_vals;
4393 operand = (const struct mips_reg_pair_operand *) operand_base;
4394 if (!match_reg (arg, operand->reg_type, ®no1)
4395 || !match_char (arg, ',')
4396 || !match_reg (arg, operand->reg_type, ®no2))
4399 num_vals = 1 << operand_base->size;
4400 for (uval = 0; uval < num_vals; uval++)
4401 if (operand->reg1_map[uval] == regno1 && operand->reg2_map[uval] == regno2)
4403 if (uval == num_vals)
4406 insn_insert_operand (arg->insn, operand_base, uval);
4410 /* OP_PCREL matcher. The caller chooses the relocation type. */
4413 match_pcrel_operand (struct mips_arg_info *arg)
4415 bfd_reloc_code_real_type r[3];
4417 return match_expression (arg, &offset_expr, r) && r[0] == BFD_RELOC_UNUSED;
4420 /* OP_PERF_REG matcher. */
4423 match_perf_reg_operand (struct mips_arg_info *arg,
4424 const struct mips_operand *operand)
4428 if (!match_const_int (arg, &sval, 0))
4433 || (mips_opts.arch == CPU_R5900
4434 && (strcmp (arg->insn->insn_mo->name, "mfps") == 0
4435 || strcmp (arg->insn->insn_mo->name, "mtps") == 0))))
4437 if (arg->soft_match)
4439 as_bad (_("Invalid performance register (%ld)"), (unsigned long) sval);
4442 insn_insert_operand (arg->insn, operand, sval);
4446 /* OP_ADDIUSP matcher. */
4449 match_addiusp_operand (struct mips_arg_info *arg,
4450 const struct mips_operand *operand)
4455 if (!match_const_int (arg, &sval, -256))
4462 if (!(sval >= -258 && sval <= 257) || (sval >= -2 && sval <= 1))
4465 uval = (unsigned int) sval;
4466 uval = ((uval >> 1) & ~0xff) | (uval & 0xff);
4467 insn_insert_operand (arg->insn, operand, uval);
4471 /* OP_CLO_CLZ_DEST matcher. */
4474 match_clo_clz_dest_operand (struct mips_arg_info *arg,
4475 const struct mips_operand *operand)
4479 if (!match_reg (arg, OP_REG_GP, ®no))
4482 insn_insert_operand (arg->insn, operand, regno | (regno << 5));
4486 /* OP_LWM_SWM_LIST matcher. */
4489 match_lwm_swm_list_operand (struct mips_arg_info *arg,
4490 const struct mips_operand *operand)
4492 unsigned int reglist, sregs, ra, regno1, regno2;
4493 struct mips_arg_info reset;
4496 if (!match_reg_range (arg, OP_REG_GP, ®no1, ®no2))
4500 if (regno2 == FP && regno1 >= S0 && regno1 <= S7)
4505 reglist |= ((1U << regno2 << 1) - 1) & -(1U << regno1);
4508 while (match_char (arg, ',')
4509 && match_reg_range (arg, OP_REG_GP, ®no1, ®no2));
4512 if (operand->size == 2)
4514 /* The list must include both ra and s0-sN, for 0 <= N <= 3. E.g.:
4520 and any permutations of these. */
4521 if ((reglist & 0xfff1ffff) != 0x80010000)
4524 sregs = (reglist >> 17) & 7;
4529 /* The list must include at least one of ra and s0-sN,
4530 for 0 <= N <= 8. (Note that there is a gap between s7 and s8,
4531 which are $23 and $30 respectively.) E.g.:
4539 and any permutations of these. */
4540 if ((reglist & 0x3f00ffff) != 0)
4543 ra = (reglist >> 27) & 0x10;
4544 sregs = ((reglist >> 22) & 0x100) | ((reglist >> 16) & 0xff);
4547 if ((sregs & -sregs) != sregs)
4550 insn_insert_operand (arg->insn, operand, (ffs (sregs) - 1) | ra);
4554 /* OP_ENTRY_EXIT_LIST matcher. */
4557 match_entry_exit_operand (struct mips_arg_info *arg,
4558 const struct mips_operand *operand)
4561 bfd_boolean is_exit;
4563 /* The format is the same for both ENTRY and EXIT, but the constraints
4565 is_exit = strcmp (arg->insn->insn_mo->name, "exit") == 0;
4566 mask = (is_exit ? 7 << 3 : 0);
4569 unsigned int regno1, regno2;
4570 bfd_boolean is_freg;
4572 if (match_reg_range (arg, OP_REG_GP, ®no1, ®no2))
4574 else if (match_reg_range (arg, OP_REG_FP, ®no1, ®no2))
4579 if (is_exit && is_freg && regno1 == 0 && regno2 < 2)
4582 mask |= (5 + regno2) << 3;
4584 else if (!is_exit && regno1 == 4 && regno2 >= 4 && regno2 <= 7)
4585 mask |= (regno2 - 3) << 3;
4586 else if (regno1 == 16 && regno2 >= 16 && regno2 <= 17)
4587 mask |= (regno2 - 15) << 1;
4588 else if (regno1 == RA && regno2 == RA)
4593 while (match_char (arg, ','));
4595 insn_insert_operand (arg->insn, operand, mask);
4599 /* OP_SAVE_RESTORE_LIST matcher. */
4602 match_save_restore_list_operand (struct mips_arg_info *arg)
4604 unsigned int opcode, args, statics, sregs;
4605 unsigned int num_frame_sizes, num_args, num_statics, num_sregs;
4610 opcode = arg->insn->insn_opcode;
4612 num_frame_sizes = 0;
4618 unsigned int regno1, regno2;
4620 if (arg->token->type == OT_INTEGER)
4622 /* Handle the frame size. */
4623 if (!match_const_int (arg, &frame_size, 0))
4625 num_frame_sizes += 1;
4629 if (!match_reg_range (arg, OP_REG_GP, ®no1, ®no2))
4632 while (regno1 <= regno2)
4634 if (regno1 >= 4 && regno1 <= 7)
4636 if (num_frame_sizes == 0)
4638 args |= 1 << (regno1 - 4);
4640 /* statics $a0-$a3 */
4641 statics |= 1 << (regno1 - 4);
4643 else if (regno1 >= 16 && regno1 <= 23)
4645 sregs |= 1 << (regno1 - 16);
4646 else if (regno1 == 30)
4649 else if (regno1 == 31)
4650 /* Add $ra to insn. */
4660 while (match_char (arg, ','));
4662 /* Encode args/statics combination. */
4665 else if (args == 0xf)
4666 /* All $a0-$a3 are args. */
4667 opcode |= MIPS16_ALL_ARGS << 16;
4668 else if (statics == 0xf)
4669 /* All $a0-$a3 are statics. */
4670 opcode |= MIPS16_ALL_STATICS << 16;
4673 /* Count arg registers. */
4683 /* Count static registers. */
4685 while (statics & 0x8)
4687 statics = (statics << 1) & 0xf;
4693 /* Encode args/statics. */
4694 opcode |= ((num_args << 2) | num_statics) << 16;
4697 /* Encode $s0/$s1. */
4698 if (sregs & (1 << 0)) /* $s0 */
4700 if (sregs & (1 << 1)) /* $s1 */
4704 /* Encode $s2-$s8. */
4713 opcode |= num_sregs << 24;
4715 /* Encode frame size. */
4716 if (num_frame_sizes == 0)
4717 error = _("Missing frame size");
4718 else if (num_frame_sizes > 1)
4719 error = _("Frame size specified twice");
4720 else if ((frame_size & 7) != 0 || frame_size < 0 || frame_size > 0xff * 8)
4721 error = _("Invalid frame size");
4722 else if (frame_size != 128 || (opcode >> 16) != 0)
4725 opcode |= (((frame_size & 0xf0) << 16)
4726 | (frame_size & 0x0f));
4731 if (arg->soft_match)
4736 /* Finally build the instruction. */
4737 if ((opcode >> 16) != 0 || frame_size == 0)
4738 opcode |= MIPS16_EXTEND;
4739 arg->insn->insn_opcode = opcode;
4743 /* OP_MDMX_IMM_REG matcher. */
4746 match_mdmx_imm_reg_operand (struct mips_arg_info *arg,
4747 const struct mips_operand *operand)
4749 unsigned int regno, uval;
4751 const struct mips_opcode *opcode;
4753 /* The mips_opcode records whether this is an octobyte or quadhalf
4754 instruction. Start out with that bit in place. */
4755 opcode = arg->insn->insn_mo;
4756 uval = mips_extract_operand (operand, opcode->match);
4757 is_qh = (uval != 0);
4759 if (arg->token->type == OT_REG || arg->token->type == OT_REG_ELEMENT)
4761 if ((opcode->membership & INSN_5400)
4762 && strcmp (opcode->name, "rzu.ob") == 0)
4764 if (arg->soft_match)
4766 as_bad (_("Operand %d of `%s' must be an immediate"),
4767 arg->argnum, opcode->name);
4770 /* Check whether this is a vector register or a broadcast of
4771 a single element. */
4772 if (arg->token->type == OT_REG_ELEMENT)
4774 if (!match_regno (arg, OP_REG_VEC, arg->token->u.reg_element.regno,
4777 if (arg->token->u.reg_element.index > (is_qh ? 3 : 7))
4779 if (arg->soft_match)
4781 as_bad (_("Invalid element selector"));
4784 uval |= arg->token->u.reg_element.index << (is_qh ? 2 : 1) << 5;
4788 /* A full vector. */
4789 if ((opcode->membership & INSN_5400)
4790 && (strcmp (opcode->name, "sll.ob") == 0
4791 || strcmp (opcode->name, "srl.ob") == 0))
4793 if (arg->soft_match)
4795 as_bad (_("Operand %d of `%s' must be scalar"),
4796 arg->argnum, opcode->name);
4799 if (!match_regno (arg, OP_REG_VEC, arg->token->u.regno, ®no))
4802 uval |= MDMX_FMTSEL_VEC_QH << 5;
4804 uval |= MDMX_FMTSEL_VEC_OB << 5;
4813 if (!match_const_int (arg, &sval, 0))
4815 if (sval < 0 || sval > 31)
4817 if (arg->soft_match)
4819 report_bad_range (arg->insn, arg->argnum, sval, 0, 31, FALSE);
4821 uval |= (sval & 31);
4823 uval |= MDMX_FMTSEL_IMM_QH << 5;
4825 uval |= MDMX_FMTSEL_IMM_OB << 5;
4827 insn_insert_operand (arg->insn, operand, uval);
4831 /* OP_PC matcher. */
4834 match_pc_operand (struct mips_arg_info *arg)
4836 if (arg->token->type == OT_REG && (arg->token->u.regno & RTYPE_PC))
4844 /* OP_REPEAT_DEST_REG and OP_REPEAT_PREV_REG matcher. OTHER_REGNO is the
4845 register that we need to match. */
4848 match_tied_reg_operand (struct mips_arg_info *arg, unsigned int other_regno)
4852 return match_reg (arg, OP_REG_GP, ®no) && regno == other_regno;
4855 /* Read a floating-point constant from S for LI.S or LI.D. LENGTH is
4856 the length of the value in bytes (4 for float, 8 for double) and
4857 USING_GPRS says whether the destination is a GPR rather than an FPR.
4859 Return the constant in IMM and OFFSET as follows:
4861 - If the constant should be loaded via memory, set IMM to O_absent and
4862 OFFSET to the memory address.
4864 - Otherwise, if the constant should be loaded into two 32-bit registers,
4865 set IMM to the O_constant to load into the high register and OFFSET
4866 to the corresponding value for the low register.
4868 - Otherwise, set IMM to the full O_constant and set OFFSET to O_absent.
4870 These constants only appear as the last operand in an instruction,
4871 and every instruction that accepts them in any variant accepts them
4872 in all variants. This means we don't have to worry about backing out
4873 any changes if the instruction does not match. We just match
4874 unconditionally and report an error if the constant is invalid. */
4877 match_float_constant (struct mips_arg_info *arg, expressionS *imm,
4878 expressionS *offset, int length, bfd_boolean using_gprs)
4883 const char *newname;
4884 unsigned char *data;
4886 /* Where the constant is placed is based on how the MIPS assembler
4889 length == 4 && using_gprs -- immediate value only
4890 length == 8 && using_gprs -- .rdata or immediate value
4891 length == 4 && !using_gprs -- .lit4 or immediate value
4892 length == 8 && !using_gprs -- .lit8 or immediate value
4894 The .lit4 and .lit8 sections are only used if permitted by the
4896 if (arg->token->type != OT_FLOAT)
4899 gas_assert (arg->token->u.flt.length == length);
4900 data = arg->token->u.flt.data;
4903 /* Handle 32-bit constants for which an immediate value is best. */
4906 || g_switch_value < 4
4907 || (data[0] == 0 && data[1] == 0)
4908 || (data[2] == 0 && data[3] == 0)))
4910 imm->X_op = O_constant;
4911 if (!target_big_endian)
4912 imm->X_add_number = bfd_getl32 (data);
4914 imm->X_add_number = bfd_getb32 (data);
4915 offset->X_op = O_absent;
4919 /* Handle 64-bit constants for which an immediate value is best. */
4921 && !mips_disable_float_construction
4922 /* Constants can only be constructed in GPRs and copied
4923 to FPRs if the GPRs are at least as wide as the FPRs.
4924 Force the constant into memory if we are using 64-bit FPRs
4925 but the GPRs are only 32 bits wide. */
4926 /* ??? No longer true with the addition of MTHC1, but this
4927 is legacy code... */
4928 && (using_gprs || !(HAVE_64BIT_FPRS && HAVE_32BIT_GPRS))
4929 && ((data[0] == 0 && data[1] == 0)
4930 || (data[2] == 0 && data[3] == 0))
4931 && ((data[4] == 0 && data[5] == 0)
4932 || (data[6] == 0 && data[7] == 0)))
4934 /* The value is simple enough to load with a couple of instructions.
4935 If using 32-bit registers, set IMM to the high order 32 bits and
4936 OFFSET to the low order 32 bits. Otherwise, set IMM to the entire
4938 if (using_gprs ? HAVE_32BIT_GPRS : HAVE_32BIT_FPRS)
4940 imm->X_op = O_constant;
4941 offset->X_op = O_constant;
4942 if (!target_big_endian)
4944 imm->X_add_number = bfd_getl32 (data + 4);
4945 offset->X_add_number = bfd_getl32 (data);
4949 imm->X_add_number = bfd_getb32 (data);
4950 offset->X_add_number = bfd_getb32 (data + 4);
4952 if (offset->X_add_number == 0)
4953 offset->X_op = O_absent;
4957 imm->X_op = O_constant;
4958 if (!target_big_endian)
4959 imm->X_add_number = bfd_getl64 (data);
4961 imm->X_add_number = bfd_getb64 (data);
4962 offset->X_op = O_absent;
4967 /* Switch to the right section. */
4969 subseg = now_subseg;
4972 gas_assert (!using_gprs && g_switch_value >= 4);
4977 if (using_gprs || g_switch_value < 8)
4978 newname = RDATA_SECTION_NAME;
4983 new_seg = subseg_new (newname, (subsegT) 0);
4984 bfd_set_section_flags (stdoutput, new_seg,
4985 SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA);
4986 frag_align (length == 4 ? 2 : 3, 0, 0);
4987 if (strncmp (TARGET_OS, "elf", 3) != 0)
4988 record_alignment (new_seg, 4);
4990 record_alignment (new_seg, length == 4 ? 2 : 3);
4992 as_bad (_("Can't use floating point insn in this section"));
4994 /* Set the argument to the current address in the section. */
4995 imm->X_op = O_absent;
4996 offset->X_op = O_symbol;
4997 offset->X_add_symbol = symbol_temp_new_now ();
4998 offset->X_add_number = 0;
5000 /* Put the floating point number into the section. */
5001 p = frag_more (length);
5002 memcpy (p, data, length);
5004 /* Switch back to the original section. */
5005 subseg_set (seg, subseg);
5009 /* S is the text seen for ARG. Match it against OPERAND. Return the end
5010 of the argument text if the match is successful, otherwise return null. */
5013 match_operand (struct mips_arg_info *arg,
5014 const struct mips_operand *operand)
5016 switch (operand->type)
5019 return match_int_operand (arg, operand);
5022 return match_mapped_int_operand (arg, operand);
5025 return match_msb_operand (arg, operand);
5028 return match_reg_operand (arg, operand);
5031 return match_reg_pair_operand (arg, operand);
5034 return match_pcrel_operand (arg);
5037 return match_perf_reg_operand (arg, operand);
5039 case OP_ADDIUSP_INT:
5040 return match_addiusp_operand (arg, operand);
5042 case OP_CLO_CLZ_DEST:
5043 return match_clo_clz_dest_operand (arg, operand);
5045 case OP_LWM_SWM_LIST:
5046 return match_lwm_swm_list_operand (arg, operand);
5048 case OP_ENTRY_EXIT_LIST:
5049 return match_entry_exit_operand (arg, operand);
5051 case OP_SAVE_RESTORE_LIST:
5052 return match_save_restore_list_operand (arg);
5054 case OP_MDMX_IMM_REG:
5055 return match_mdmx_imm_reg_operand (arg, operand);
5057 case OP_REPEAT_DEST_REG:
5058 return match_tied_reg_operand (arg, arg->dest_regno);
5060 case OP_REPEAT_PREV_REG:
5061 return match_tied_reg_operand (arg, arg->last_regno);
5064 return match_pc_operand (arg);
5069 /* ARG is the state after successfully matching an instruction.
5070 Issue any queued-up warnings. */
5073 check_completed_insn (struct mips_arg_info *arg)
5078 as_warn (_("Used $at without \".set noat\""));
5080 as_warn (_("Used $%u with \".set at=$%u\""), AT, AT);
5084 /* Classify an instruction according to the FIX_VR4120_* enumeration.
5085 Return NUM_FIX_VR4120_CLASSES if the instruction isn't affected
5086 by VR4120 errata. */
5089 classify_vr4120_insn (const char *name)
5091 if (strncmp (name, "macc", 4) == 0)
5092 return FIX_VR4120_MACC;
5093 if (strncmp (name, "dmacc", 5) == 0)
5094 return FIX_VR4120_DMACC;
5095 if (strncmp (name, "mult", 4) == 0)
5096 return FIX_VR4120_MULT;
5097 if (strncmp (name, "dmult", 5) == 0)
5098 return FIX_VR4120_DMULT;
5099 if (strstr (name, "div"))
5100 return FIX_VR4120_DIV;
5101 if (strcmp (name, "mtlo") == 0 || strcmp (name, "mthi") == 0)
5102 return FIX_VR4120_MTHILO;
5103 return NUM_FIX_VR4120_CLASSES;
5106 #define INSN_ERET 0x42000018
5107 #define INSN_DERET 0x4200001f
5109 /* Return the number of instructions that must separate INSN1 and INSN2,
5110 where INSN1 is the earlier instruction. Return the worst-case value
5111 for any INSN2 if INSN2 is null. */
5114 insns_between (const struct mips_cl_insn *insn1,
5115 const struct mips_cl_insn *insn2)
5117 unsigned long pinfo1, pinfo2;
5120 /* This function needs to know which pinfo flags are set for INSN2
5121 and which registers INSN2 uses. The former is stored in PINFO2 and
5122 the latter is tested via INSN2_USES_GPR. If INSN2 is null, PINFO2
5123 will have every flag set and INSN2_USES_GPR will always return true. */
5124 pinfo1 = insn1->insn_mo->pinfo;
5125 pinfo2 = insn2 ? insn2->insn_mo->pinfo : ~0U;
5127 #define INSN2_USES_GPR(REG) \
5128 (insn2 == NULL || (gpr_read_mask (insn2) & (1U << (REG))) != 0)
5130 /* For most targets, write-after-read dependencies on the HI and LO
5131 registers must be separated by at least two instructions. */
5132 if (!hilo_interlocks)
5134 if ((pinfo1 & INSN_READ_LO) && (pinfo2 & INSN_WRITE_LO))
5136 if ((pinfo1 & INSN_READ_HI) && (pinfo2 & INSN_WRITE_HI))
5140 /* If we're working around r7000 errata, there must be two instructions
5141 between an mfhi or mflo and any instruction that uses the result. */
5142 if (mips_7000_hilo_fix
5143 && !mips_opts.micromips
5144 && MF_HILO_INSN (pinfo1)
5145 && INSN2_USES_GPR (EXTRACT_OPERAND (0, RD, *insn1)))
5148 /* If we're working around 24K errata, one instruction is required
5149 if an ERET or DERET is followed by a branch instruction. */
5150 if (mips_fix_24k && !mips_opts.micromips)
5152 if (insn1->insn_opcode == INSN_ERET
5153 || insn1->insn_opcode == INSN_DERET)
5156 || insn2->insn_opcode == INSN_ERET
5157 || insn2->insn_opcode == INSN_DERET
5158 || delayed_branch_p (insn2))
5163 /* If working around VR4120 errata, check for combinations that need
5164 a single intervening instruction. */
5165 if (mips_fix_vr4120 && !mips_opts.micromips)
5167 unsigned int class1, class2;
5169 class1 = classify_vr4120_insn (insn1->insn_mo->name);
5170 if (class1 != NUM_FIX_VR4120_CLASSES && vr4120_conflicts[class1] != 0)
5174 class2 = classify_vr4120_insn (insn2->insn_mo->name);
5175 if (vr4120_conflicts[class1] & (1 << class2))
5180 if (!HAVE_CODE_COMPRESSION)
5182 /* Check for GPR or coprocessor load delays. All such delays
5183 are on the RT register. */
5184 /* Itbl support may require additional care here. */
5185 if ((!gpr_interlocks && (pinfo1 & INSN_LOAD_MEMORY_DELAY))
5186 || (!cop_interlocks && (pinfo1 & INSN_LOAD_COPROC_DELAY)))
5188 know (pinfo1 & INSN_WRITE_GPR_T);
5189 if (INSN2_USES_GPR (EXTRACT_OPERAND (0, RT, *insn1)))
5193 /* Check for generic coprocessor hazards.
5195 This case is not handled very well. There is no special
5196 knowledge of CP0 handling, and the coprocessors other than
5197 the floating point unit are not distinguished at all. */
5198 /* Itbl support may require additional care here. FIXME!
5199 Need to modify this to include knowledge about
5200 user specified delays! */
5201 else if ((!cop_interlocks && (pinfo1 & INSN_COPROC_MOVE_DELAY))
5202 || (!cop_mem_interlocks && (pinfo1 & INSN_COPROC_MEMORY_DELAY)))
5204 /* Handle cases where INSN1 writes to a known general coprocessor
5205 register. There must be a one instruction delay before INSN2
5206 if INSN2 reads that register, otherwise no delay is needed. */
5207 mask = fpr_write_mask (insn1);
5210 if (!insn2 || (mask & fpr_read_mask (insn2)) != 0)
5215 /* Read-after-write dependencies on the control registers
5216 require a two-instruction gap. */
5217 if ((pinfo1 & INSN_WRITE_COND_CODE)
5218 && (pinfo2 & INSN_READ_COND_CODE))
5221 /* We don't know exactly what INSN1 does. If INSN2 is
5222 also a coprocessor instruction, assume there must be
5223 a one instruction gap. */
5224 if (pinfo2 & INSN_COP)
5229 /* Check for read-after-write dependencies on the coprocessor
5230 control registers in cases where INSN1 does not need a general
5231 coprocessor delay. This means that INSN1 is a floating point
5232 comparison instruction. */
5233 /* Itbl support may require additional care here. */
5234 else if (!cop_interlocks
5235 && (pinfo1 & INSN_WRITE_COND_CODE)
5236 && (pinfo2 & INSN_READ_COND_CODE))
5240 #undef INSN2_USES_GPR
5245 /* Return the number of nops that would be needed to work around the
5246 VR4130 mflo/mfhi errata if instruction INSN immediately followed
5247 the MAX_VR4130_NOPS instructions described by HIST. Ignore hazards
5248 that are contained within the first IGNORE instructions of HIST. */
5251 nops_for_vr4130 (int ignore, const struct mips_cl_insn *hist,
5252 const struct mips_cl_insn *insn)
5257 /* Check if the instruction writes to HI or LO. MTHI and MTLO
5258 are not affected by the errata. */
5260 && ((insn->insn_mo->pinfo & (INSN_WRITE_HI | INSN_WRITE_LO)) == 0
5261 || strcmp (insn->insn_mo->name, "mtlo") == 0
5262 || strcmp (insn->insn_mo->name, "mthi") == 0))
5265 /* Search for the first MFLO or MFHI. */
5266 for (i = 0; i < MAX_VR4130_NOPS; i++)
5267 if (MF_HILO_INSN (hist[i].insn_mo->pinfo))
5269 /* Extract the destination register. */
5270 mask = gpr_write_mask (&hist[i]);
5272 /* No nops are needed if INSN reads that register. */
5273 if (insn != NULL && (gpr_read_mask (insn) & mask) != 0)
5276 /* ...or if any of the intervening instructions do. */
5277 for (j = 0; j < i; j++)
5278 if (gpr_read_mask (&hist[j]) & mask)
5282 return MAX_VR4130_NOPS - i;
5287 #define BASE_REG_EQ(INSN1, INSN2) \
5288 ((((INSN1) >> OP_SH_RS) & OP_MASK_RS) \
5289 == (((INSN2) >> OP_SH_RS) & OP_MASK_RS))
5291 /* Return the minimum alignment for this store instruction. */
5294 fix_24k_align_to (const struct mips_opcode *mo)
5296 if (strcmp (mo->name, "sh") == 0)
5299 if (strcmp (mo->name, "swc1") == 0
5300 || strcmp (mo->name, "swc2") == 0
5301 || strcmp (mo->name, "sw") == 0
5302 || strcmp (mo->name, "sc") == 0
5303 || strcmp (mo->name, "s.s") == 0)
5306 if (strcmp (mo->name, "sdc1") == 0
5307 || strcmp (mo->name, "sdc2") == 0
5308 || strcmp (mo->name, "s.d") == 0)
5315 struct fix_24k_store_info
5317 /* Immediate offset, if any, for this store instruction. */
5319 /* Alignment required by this store instruction. */
5321 /* True for register offsets. */
5322 int register_offset;
5325 /* Comparison function used by qsort. */
5328 fix_24k_sort (const void *a, const void *b)
5330 const struct fix_24k_store_info *pos1 = a;
5331 const struct fix_24k_store_info *pos2 = b;
5333 return (pos1->off - pos2->off);
5336 /* INSN is a store instruction. Try to record the store information
5337 in STINFO. Return false if the information isn't known. */
5340 fix_24k_record_store_info (struct fix_24k_store_info *stinfo,
5341 const struct mips_cl_insn *insn)
5343 /* The instruction must have a known offset. */
5344 if (!insn->complete_p || !strstr (insn->insn_mo->args, "o("))
5347 stinfo->off = (insn->insn_opcode >> OP_SH_IMMEDIATE) & OP_MASK_IMMEDIATE;
5348 stinfo->align_to = fix_24k_align_to (insn->insn_mo);
5352 /* Return the number of nops that would be needed to work around the 24k
5353 "lost data on stores during refill" errata if instruction INSN
5354 immediately followed the 2 instructions described by HIST.
5355 Ignore hazards that are contained within the first IGNORE
5356 instructions of HIST.
5358 Problem: The FSB (fetch store buffer) acts as an intermediate buffer
5359 for the data cache refills and store data. The following describes
5360 the scenario where the store data could be lost.
5362 * A data cache miss, due to either a load or a store, causing fill
5363 data to be supplied by the memory subsystem
5364 * The first three doublewords of fill data are returned and written
5366 * A sequence of four stores occurs in consecutive cycles around the
5367 final doubleword of the fill:
5371 * Zero, One or more instructions
5374 The four stores A-D must be to different doublewords of the line that
5375 is being filled. The fourth instruction in the sequence above permits
5376 the fill of the final doubleword to be transferred from the FSB into
5377 the cache. In the sequence above, the stores may be either integer
5378 (sb, sh, sw, swr, swl, sc) or coprocessor (swc1/swc2, sdc1/sdc2,
5379 swxc1, sdxc1, suxc1) stores, as long as the four stores are to
5380 different doublewords on the line. If the floating point unit is
5381 running in 1:2 mode, it is not possible to create the sequence above
5382 using only floating point store instructions.
5384 In this case, the cache line being filled is incorrectly marked
5385 invalid, thereby losing the data from any store to the line that
5386 occurs between the original miss and the completion of the five
5387 cycle sequence shown above.
5389 The workarounds are:
5391 * Run the data cache in write-through mode.
5392 * Insert a non-store instruction between
5393 Store A and Store B or Store B and Store C. */
5396 nops_for_24k (int ignore, const struct mips_cl_insn *hist,
5397 const struct mips_cl_insn *insn)
5399 struct fix_24k_store_info pos[3];
5400 int align, i, base_offset;
5405 /* If the previous instruction wasn't a store, there's nothing to
5407 if ((hist[0].insn_mo->pinfo & INSN_STORE_MEMORY) == 0)
5410 /* If the instructions after the previous one are unknown, we have
5411 to assume the worst. */
5415 /* Check whether we are dealing with three consecutive stores. */
5416 if ((insn->insn_mo->pinfo & INSN_STORE_MEMORY) == 0
5417 || (hist[1].insn_mo->pinfo & INSN_STORE_MEMORY) == 0)
5420 /* If we don't know the relationship between the store addresses,
5421 assume the worst. */
5422 if (!BASE_REG_EQ (insn->insn_opcode, hist[0].insn_opcode)
5423 || !BASE_REG_EQ (insn->insn_opcode, hist[1].insn_opcode))
5426 if (!fix_24k_record_store_info (&pos[0], insn)
5427 || !fix_24k_record_store_info (&pos[1], &hist[0])
5428 || !fix_24k_record_store_info (&pos[2], &hist[1]))
5431 qsort (&pos, 3, sizeof (struct fix_24k_store_info), fix_24k_sort);
5433 /* Pick a value of ALIGN and X such that all offsets are adjusted by
5434 X bytes and such that the base register + X is known to be aligned
5437 if (((insn->insn_opcode >> OP_SH_RS) & OP_MASK_RS) == SP)
5441 align = pos[0].align_to;
5442 base_offset = pos[0].off;
5443 for (i = 1; i < 3; i++)
5444 if (align < pos[i].align_to)
5446 align = pos[i].align_to;
5447 base_offset = pos[i].off;
5449 for (i = 0; i < 3; i++)
5450 pos[i].off -= base_offset;
5453 pos[0].off &= ~align + 1;
5454 pos[1].off &= ~align + 1;
5455 pos[2].off &= ~align + 1;
5457 /* If any two stores write to the same chunk, they also write to the
5458 same doubleword. The offsets are still sorted at this point. */
5459 if (pos[0].off == pos[1].off || pos[1].off == pos[2].off)
5462 /* A range of at least 9 bytes is needed for the stores to be in
5463 non-overlapping doublewords. */
5464 if (pos[2].off - pos[0].off <= 8)
5467 if (pos[2].off - pos[1].off >= 24
5468 || pos[1].off - pos[0].off >= 24
5469 || pos[2].off - pos[0].off >= 32)
5475 /* Return the number of nops that would be needed if instruction INSN
5476 immediately followed the MAX_NOPS instructions given by HIST,
5477 where HIST[0] is the most recent instruction. Ignore hazards
5478 between INSN and the first IGNORE instructions in HIST.
5480 If INSN is null, return the worse-case number of nops for any
5484 nops_for_insn (int ignore, const struct mips_cl_insn *hist,
5485 const struct mips_cl_insn *insn)
5487 int i, nops, tmp_nops;
5490 for (i = ignore; i < MAX_DELAY_NOPS; i++)
5492 tmp_nops = insns_between (hist + i, insn) - i;
5493 if (tmp_nops > nops)
5497 if (mips_fix_vr4130 && !mips_opts.micromips)
5499 tmp_nops = nops_for_vr4130 (ignore, hist, insn);
5500 if (tmp_nops > nops)
5504 if (mips_fix_24k && !mips_opts.micromips)
5506 tmp_nops = nops_for_24k (ignore, hist, insn);
5507 if (tmp_nops > nops)
5514 /* The variable arguments provide NUM_INSNS extra instructions that
5515 might be added to HIST. Return the largest number of nops that
5516 would be needed after the extended sequence, ignoring hazards
5517 in the first IGNORE instructions. */
5520 nops_for_sequence (int num_insns, int ignore,
5521 const struct mips_cl_insn *hist, ...)
5524 struct mips_cl_insn buffer[MAX_NOPS];
5525 struct mips_cl_insn *cursor;
5528 va_start (args, hist);
5529 cursor = buffer + num_insns;
5530 memcpy (cursor, hist, (MAX_NOPS - num_insns) * sizeof (*cursor));
5531 while (cursor > buffer)
5532 *--cursor = *va_arg (args, const struct mips_cl_insn *);
5534 nops = nops_for_insn (ignore, buffer, NULL);
5539 /* Like nops_for_insn, but if INSN is a branch, take into account the
5540 worst-case delay for the branch target. */
5543 nops_for_insn_or_target (int ignore, const struct mips_cl_insn *hist,
5544 const struct mips_cl_insn *insn)
5548 nops = nops_for_insn (ignore, hist, insn);
5549 if (delayed_branch_p (insn))
5551 tmp_nops = nops_for_sequence (2, ignore ? ignore + 2 : 0,
5552 hist, insn, get_delay_slot_nop (insn));
5553 if (tmp_nops > nops)
5556 else if (compact_branch_p (insn))
5558 tmp_nops = nops_for_sequence (1, ignore ? ignore + 1 : 0, hist, insn);
5559 if (tmp_nops > nops)
5565 /* Fix NOP issue: Replace nops by "or at,at,zero". */
5568 fix_loongson2f_nop (struct mips_cl_insn * ip)
5570 gas_assert (!HAVE_CODE_COMPRESSION);
5571 if (strcmp (ip->insn_mo->name, "nop") == 0)
5572 ip->insn_opcode = LOONGSON2F_NOP_INSN;
5575 /* Fix Jump Issue: Eliminate instruction fetch from outside 256M region
5576 jr target pc &= 'hffff_ffff_cfff_ffff. */
5579 fix_loongson2f_jump (struct mips_cl_insn * ip)
5581 gas_assert (!HAVE_CODE_COMPRESSION);
5582 if (strcmp (ip->insn_mo->name, "j") == 0
5583 || strcmp (ip->insn_mo->name, "jr") == 0
5584 || strcmp (ip->insn_mo->name, "jalr") == 0)
5592 sreg = EXTRACT_OPERAND (0, RS, *ip);
5593 if (sreg == ZERO || sreg == KT0 || sreg == KT1 || sreg == ATREG)
5596 ep.X_op = O_constant;
5597 ep.X_add_number = 0xcfff0000;
5598 macro_build (&ep, "lui", "t,u", ATREG, BFD_RELOC_HI16);
5599 ep.X_add_number = 0xffff;
5600 macro_build (&ep, "ori", "t,r,i", ATREG, ATREG, BFD_RELOC_LO16);
5601 macro_build (NULL, "and", "d,v,t", sreg, sreg, ATREG);
5606 fix_loongson2f (struct mips_cl_insn * ip)
5608 if (mips_fix_loongson2f_nop)
5609 fix_loongson2f_nop (ip);
5611 if (mips_fix_loongson2f_jump)
5612 fix_loongson2f_jump (ip);
5615 /* IP is a branch that has a delay slot, and we need to fill it
5616 automatically. Return true if we can do that by swapping IP
5617 with the previous instruction.
5618 ADDRESS_EXPR is an operand of the instruction to be used with
5622 can_swap_branch_p (struct mips_cl_insn *ip, expressionS *address_expr,
5623 bfd_reloc_code_real_type *reloc_type)
5625 unsigned long pinfo, pinfo2, prev_pinfo, prev_pinfo2;
5626 unsigned int gpr_read, gpr_write, prev_gpr_read, prev_gpr_write;
5628 /* -O2 and above is required for this optimization. */
5629 if (mips_optimize < 2)
5632 /* If we have seen .set volatile or .set nomove, don't optimize. */
5633 if (mips_opts.nomove)
5636 /* We can't swap if the previous instruction's position is fixed. */
5637 if (history[0].fixed_p)
5640 /* If the previous previous insn was in a .set noreorder, we can't
5641 swap. Actually, the MIPS assembler will swap in this situation.
5642 However, gcc configured -with-gnu-as will generate code like
5650 in which we can not swap the bne and INSN. If gcc is not configured
5651 -with-gnu-as, it does not output the .set pseudo-ops. */
5652 if (history[1].noreorder_p)
5655 /* If the previous instruction had a fixup in mips16 mode, we can not swap.
5656 This means that the previous instruction was a 4-byte one anyhow. */
5657 if (mips_opts.mips16 && history[0].fixp[0])
5660 /* If the branch is itself the target of a branch, we can not swap.
5661 We cheat on this; all we check for is whether there is a label on
5662 this instruction. If there are any branches to anything other than
5663 a label, users must use .set noreorder. */
5664 if (seg_info (now_seg)->label_list)
5667 /* If the previous instruction is in a variant frag other than this
5668 branch's one, we cannot do the swap. This does not apply to
5669 MIPS16 code, which uses variant frags for different purposes. */
5670 if (!mips_opts.mips16
5672 && history[0].frag->fr_type == rs_machine_dependent)
5675 /* We do not swap with instructions that cannot architecturally
5676 be placed in a branch delay slot, such as SYNC or ERET. We
5677 also refrain from swapping with a trap instruction, since it
5678 complicates trap handlers to have the trap instruction be in
5680 prev_pinfo = history[0].insn_mo->pinfo;
5681 if (prev_pinfo & INSN_NO_DELAY_SLOT)
5684 /* Check for conflicts between the branch and the instructions
5685 before the candidate delay slot. */
5686 if (nops_for_insn (0, history + 1, ip) > 0)
5689 /* Check for conflicts between the swapped sequence and the
5690 target of the branch. */
5691 if (nops_for_sequence (2, 0, history + 1, ip, history) > 0)
5694 /* If the branch reads a register that the previous
5695 instruction sets, we can not swap. */
5696 gpr_read = gpr_read_mask (ip);
5697 prev_gpr_write = gpr_write_mask (&history[0]);
5698 if (gpr_read & prev_gpr_write)
5701 /* If the branch writes a register that the previous
5702 instruction sets, we can not swap. */
5703 gpr_write = gpr_write_mask (ip);
5704 if (gpr_write & prev_gpr_write)
5707 /* If the branch writes a register that the previous
5708 instruction reads, we can not swap. */
5709 prev_gpr_read = gpr_read_mask (&history[0]);
5710 if (gpr_write & prev_gpr_read)
5713 /* If one instruction sets a condition code and the
5714 other one uses a condition code, we can not swap. */
5715 pinfo = ip->insn_mo->pinfo;
5716 if ((pinfo & INSN_READ_COND_CODE)
5717 && (prev_pinfo & INSN_WRITE_COND_CODE))
5719 if ((pinfo & INSN_WRITE_COND_CODE)
5720 && (prev_pinfo & INSN_READ_COND_CODE))
5723 /* If the previous instruction uses the PC, we can not swap. */
5724 prev_pinfo2 = history[0].insn_mo->pinfo2;
5725 if (mips_opts.mips16 && (prev_pinfo & MIPS16_INSN_READ_PC))
5727 if (mips_opts.micromips && (prev_pinfo2 & INSN2_READ_PC))
5730 /* If the previous instruction has an incorrect size for a fixed
5731 branch delay slot in microMIPS mode, we cannot swap. */
5732 pinfo2 = ip->insn_mo->pinfo2;
5733 if (mips_opts.micromips
5734 && (pinfo2 & INSN2_BRANCH_DELAY_16BIT)
5735 && insn_length (history) != 2)
5737 if (mips_opts.micromips
5738 && (pinfo2 & INSN2_BRANCH_DELAY_32BIT)
5739 && insn_length (history) != 4)
5742 /* On R5900 short loops need to be fixed by inserting a nop in
5743 the branch delay slots.
5744 A short loop can be terminated too early. */
5745 if (mips_opts.arch == CPU_R5900
5746 /* Check if instruction has a parameter, ignore "j $31". */
5747 && (address_expr != NULL)
5748 /* Parameter must be 16 bit. */
5749 && (*reloc_type == BFD_RELOC_16_PCREL_S2)
5750 /* Branch to same segment. */
5751 && (S_GET_SEGMENT(address_expr->X_add_symbol) == now_seg)
5752 /* Branch to same code fragment. */
5753 && (symbol_get_frag(address_expr->X_add_symbol) == frag_now)
5754 /* Can only calculate branch offset if value is known. */
5755 && symbol_constant_p(address_expr->X_add_symbol)
5756 /* Check if branch is really conditional. */
5757 && !((ip->insn_opcode & 0xffff0000) == 0x10000000 /* beq $0,$0 */
5758 || (ip->insn_opcode & 0xffff0000) == 0x04010000 /* bgez $0 */
5759 || (ip->insn_opcode & 0xffff0000) == 0x04110000)) /* bgezal $0 */
5762 /* Check if loop is shorter than 6 instructions including
5763 branch and delay slot. */
5764 distance = frag_now_fix() - S_GET_VALUE(address_expr->X_add_symbol);
5771 /* When the loop includes branches or jumps,
5772 it is not a short loop. */
5773 for (i = 0; i < (distance / 4); i++)
5775 if ((history[i].cleared_p)
5776 || delayed_branch_p(&history[i]))
5784 /* Insert nop after branch to fix short loop. */
5793 /* Decide how we should add IP to the instruction stream.
5794 ADDRESS_EXPR is an operand of the instruction to be used with
5797 static enum append_method
5798 get_append_method (struct mips_cl_insn *ip, expressionS *address_expr,
5799 bfd_reloc_code_real_type *reloc_type)
5801 unsigned long pinfo;
5803 /* The relaxed version of a macro sequence must be inherently
5805 if (mips_relax.sequence == 2)
5808 /* We must not dabble with instructions in a ".set norerorder" block. */
5809 if (mips_opts.noreorder)
5812 /* Otherwise, it's our responsibility to fill branch delay slots. */
5813 if (delayed_branch_p (ip))
5815 if (!branch_likely_p (ip)
5816 && can_swap_branch_p (ip, address_expr, reloc_type))
5819 pinfo = ip->insn_mo->pinfo;
5820 if (mips_opts.mips16
5821 && ISA_SUPPORTS_MIPS16E
5822 && (pinfo & (MIPS16_INSN_READ_X | MIPS16_INSN_READ_31)))
5823 return APPEND_ADD_COMPACT;
5825 return APPEND_ADD_WITH_NOP;
5831 /* IP is a MIPS16 instruction whose opcode we have just changed.
5832 Point IP->insn_mo to the new opcode's definition. */
5835 find_altered_mips16_opcode (struct mips_cl_insn *ip)
5837 const struct mips_opcode *mo, *end;
5839 end = &mips16_opcodes[bfd_mips16_num_opcodes];
5840 for (mo = ip->insn_mo; mo < end; mo++)
5841 if ((ip->insn_opcode & mo->mask) == mo->match)
5849 /* For microMIPS macros, we need to generate a local number label
5850 as the target of branches. */
5851 #define MICROMIPS_LABEL_CHAR '\037'
5852 static unsigned long micromips_target_label;
5853 static char micromips_target_name[32];
5856 micromips_label_name (void)
5858 char *p = micromips_target_name;
5859 char symbol_name_temporary[24];
5867 l = micromips_target_label;
5868 #ifdef LOCAL_LABEL_PREFIX
5869 *p++ = LOCAL_LABEL_PREFIX;
5872 *p++ = MICROMIPS_LABEL_CHAR;
5875 symbol_name_temporary[i++] = l % 10 + '0';
5880 *p++ = symbol_name_temporary[--i];
5883 return micromips_target_name;
5887 micromips_label_expr (expressionS *label_expr)
5889 label_expr->X_op = O_symbol;
5890 label_expr->X_add_symbol = symbol_find_or_make (micromips_label_name ());
5891 label_expr->X_add_number = 0;
5895 micromips_label_inc (void)
5897 micromips_target_label++;
5898 *micromips_target_name = '\0';
5902 micromips_add_label (void)
5906 s = colon (micromips_label_name ());
5907 micromips_label_inc ();
5908 S_SET_OTHER (s, ELF_ST_SET_MICROMIPS (S_GET_OTHER (s)));
5911 /* If assembling microMIPS code, then return the microMIPS reloc
5912 corresponding to the requested one if any. Otherwise return
5913 the reloc unchanged. */
5915 static bfd_reloc_code_real_type
5916 micromips_map_reloc (bfd_reloc_code_real_type reloc)
5918 static const bfd_reloc_code_real_type relocs[][2] =
5920 /* Keep sorted incrementally by the left-hand key. */
5921 { BFD_RELOC_16_PCREL_S2, BFD_RELOC_MICROMIPS_16_PCREL_S1 },
5922 { BFD_RELOC_GPREL16, BFD_RELOC_MICROMIPS_GPREL16 },
5923 { BFD_RELOC_MIPS_JMP, BFD_RELOC_MICROMIPS_JMP },
5924 { BFD_RELOC_HI16, BFD_RELOC_MICROMIPS_HI16 },
5925 { BFD_RELOC_HI16_S, BFD_RELOC_MICROMIPS_HI16_S },
5926 { BFD_RELOC_LO16, BFD_RELOC_MICROMIPS_LO16 },
5927 { BFD_RELOC_MIPS_LITERAL, BFD_RELOC_MICROMIPS_LITERAL },
5928 { BFD_RELOC_MIPS_GOT16, BFD_RELOC_MICROMIPS_GOT16 },
5929 { BFD_RELOC_MIPS_CALL16, BFD_RELOC_MICROMIPS_CALL16 },
5930 { BFD_RELOC_MIPS_GOT_HI16, BFD_RELOC_MICROMIPS_GOT_HI16 },
5931 { BFD_RELOC_MIPS_GOT_LO16, BFD_RELOC_MICROMIPS_GOT_LO16 },
5932 { BFD_RELOC_MIPS_CALL_HI16, BFD_RELOC_MICROMIPS_CALL_HI16 },
5933 { BFD_RELOC_MIPS_CALL_LO16, BFD_RELOC_MICROMIPS_CALL_LO16 },
5934 { BFD_RELOC_MIPS_SUB, BFD_RELOC_MICROMIPS_SUB },
5935 { BFD_RELOC_MIPS_GOT_PAGE, BFD_RELOC_MICROMIPS_GOT_PAGE },
5936 { BFD_RELOC_MIPS_GOT_OFST, BFD_RELOC_MICROMIPS_GOT_OFST },
5937 { BFD_RELOC_MIPS_GOT_DISP, BFD_RELOC_MICROMIPS_GOT_DISP },
5938 { BFD_RELOC_MIPS_HIGHEST, BFD_RELOC_MICROMIPS_HIGHEST },
5939 { BFD_RELOC_MIPS_HIGHER, BFD_RELOC_MICROMIPS_HIGHER },
5940 { BFD_RELOC_MIPS_SCN_DISP, BFD_RELOC_MICROMIPS_SCN_DISP },
5941 { BFD_RELOC_MIPS_TLS_GD, BFD_RELOC_MICROMIPS_TLS_GD },
5942 { BFD_RELOC_MIPS_TLS_LDM, BFD_RELOC_MICROMIPS_TLS_LDM },
5943 { BFD_RELOC_MIPS_TLS_DTPREL_HI16, BFD_RELOC_MICROMIPS_TLS_DTPREL_HI16 },
5944 { BFD_RELOC_MIPS_TLS_DTPREL_LO16, BFD_RELOC_MICROMIPS_TLS_DTPREL_LO16 },
5945 { BFD_RELOC_MIPS_TLS_GOTTPREL, BFD_RELOC_MICROMIPS_TLS_GOTTPREL },
5946 { BFD_RELOC_MIPS_TLS_TPREL_HI16, BFD_RELOC_MICROMIPS_TLS_TPREL_HI16 },
5947 { BFD_RELOC_MIPS_TLS_TPREL_LO16, BFD_RELOC_MICROMIPS_TLS_TPREL_LO16 }
5949 bfd_reloc_code_real_type r;
5952 if (!mips_opts.micromips)
5954 for (i = 0; i < ARRAY_SIZE (relocs); i++)
5960 return relocs[i][1];
5965 /* Try to resolve relocation RELOC against constant OPERAND at assembly time.
5966 Return true on success, storing the resolved value in RESULT. */
5969 calculate_reloc (bfd_reloc_code_real_type reloc, offsetT operand,
5974 case BFD_RELOC_MIPS_HIGHEST:
5975 case BFD_RELOC_MICROMIPS_HIGHEST:
5976 *result = ((operand + 0x800080008000ull) >> 48) & 0xffff;
5979 case BFD_RELOC_MIPS_HIGHER:
5980 case BFD_RELOC_MICROMIPS_HIGHER:
5981 *result = ((operand + 0x80008000ull) >> 32) & 0xffff;
5984 case BFD_RELOC_HI16_S:
5985 case BFD_RELOC_MICROMIPS_HI16_S:
5986 case BFD_RELOC_MIPS16_HI16_S:
5987 *result = ((operand + 0x8000) >> 16) & 0xffff;
5990 case BFD_RELOC_HI16:
5991 case BFD_RELOC_MICROMIPS_HI16:
5992 case BFD_RELOC_MIPS16_HI16:
5993 *result = (operand >> 16) & 0xffff;
5996 case BFD_RELOC_LO16:
5997 case BFD_RELOC_MICROMIPS_LO16:
5998 case BFD_RELOC_MIPS16_LO16:
5999 *result = operand & 0xffff;
6002 case BFD_RELOC_UNUSED:
6011 /* Output an instruction. IP is the instruction information.
6012 ADDRESS_EXPR is an operand of the instruction to be used with
6013 RELOC_TYPE. EXPANSIONP is true if the instruction is part of
6014 a macro expansion. */
6017 append_insn (struct mips_cl_insn *ip, expressionS *address_expr,
6018 bfd_reloc_code_real_type *reloc_type, bfd_boolean expansionp)
6020 unsigned long prev_pinfo2, pinfo;
6021 bfd_boolean relaxed_branch = FALSE;
6022 enum append_method method;
6023 bfd_boolean relax32;
6026 if (mips_fix_loongson2f && !HAVE_CODE_COMPRESSION)
6027 fix_loongson2f (ip);
6029 file_ase_mips16 |= mips_opts.mips16;
6030 file_ase_micromips |= mips_opts.micromips;
6032 prev_pinfo2 = history[0].insn_mo->pinfo2;
6033 pinfo = ip->insn_mo->pinfo;
6035 if (mips_opts.micromips
6037 && (((prev_pinfo2 & INSN2_BRANCH_DELAY_16BIT) != 0
6038 && micromips_insn_length (ip->insn_mo) != 2)
6039 || ((prev_pinfo2 & INSN2_BRANCH_DELAY_32BIT) != 0
6040 && micromips_insn_length (ip->insn_mo) != 4)))
6041 as_warn (_("Wrong size instruction in a %u-bit branch delay slot"),
6042 (prev_pinfo2 & INSN2_BRANCH_DELAY_16BIT) != 0 ? 16 : 32);
6044 if (address_expr == NULL)
6046 else if (reloc_type[0] <= BFD_RELOC_UNUSED
6047 && reloc_type[1] == BFD_RELOC_UNUSED
6048 && reloc_type[2] == BFD_RELOC_UNUSED
6049 && address_expr->X_op == O_constant)
6051 switch (*reloc_type)
6053 case BFD_RELOC_MIPS_JMP:
6057 shift = mips_opts.micromips ? 1 : 2;
6058 if ((address_expr->X_add_number & ((1 << shift) - 1)) != 0)
6059 as_bad (_("jump to misaligned address (0x%lx)"),
6060 (unsigned long) address_expr->X_add_number);
6061 ip->insn_opcode |= ((address_expr->X_add_number >> shift)
6067 case BFD_RELOC_MIPS16_JMP:
6068 if ((address_expr->X_add_number & 3) != 0)
6069 as_bad (_("jump to misaligned address (0x%lx)"),
6070 (unsigned long) address_expr->X_add_number);
6072 (((address_expr->X_add_number & 0x7c0000) << 3)
6073 | ((address_expr->X_add_number & 0xf800000) >> 7)
6074 | ((address_expr->X_add_number & 0x3fffc) >> 2));
6078 case BFD_RELOC_16_PCREL_S2:
6082 shift = mips_opts.micromips ? 1 : 2;
6083 if ((address_expr->X_add_number & ((1 << shift) - 1)) != 0)
6084 as_bad (_("branch to misaligned address (0x%lx)"),
6085 (unsigned long) address_expr->X_add_number);
6086 if (!mips_relax_branch)
6088 if ((address_expr->X_add_number + (1 << (shift + 15)))
6089 & ~((1 << (shift + 16)) - 1))
6090 as_bad (_("branch address range overflow (0x%lx)"),
6091 (unsigned long) address_expr->X_add_number);
6092 ip->insn_opcode |= ((address_expr->X_add_number >> shift)
6102 if (calculate_reloc (*reloc_type, address_expr->X_add_number,
6105 ip->insn_opcode |= value & 0xffff;
6113 if (mips_relax.sequence != 2 && !mips_opts.noreorder)
6115 /* There are a lot of optimizations we could do that we don't.
6116 In particular, we do not, in general, reorder instructions.
6117 If you use gcc with optimization, it will reorder
6118 instructions and generally do much more optimization then we
6119 do here; repeating all that work in the assembler would only
6120 benefit hand written assembly code, and does not seem worth
6122 int nops = (mips_optimize == 0
6123 ? nops_for_insn (0, history, NULL)
6124 : nops_for_insn_or_target (0, history, ip));
6128 unsigned long old_frag_offset;
6131 old_frag = frag_now;
6132 old_frag_offset = frag_now_fix ();
6134 for (i = 0; i < nops; i++)
6135 add_fixed_insn (NOP_INSN);
6136 insert_into_history (0, nops, NOP_INSN);
6140 listing_prev_line ();
6141 /* We may be at the start of a variant frag. In case we
6142 are, make sure there is enough space for the frag
6143 after the frags created by listing_prev_line. The
6144 argument to frag_grow here must be at least as large
6145 as the argument to all other calls to frag_grow in
6146 this file. We don't have to worry about being in the
6147 middle of a variant frag, because the variants insert
6148 all needed nop instructions themselves. */
6152 mips_move_text_labels ();
6154 #ifndef NO_ECOFF_DEBUGGING
6155 if (ECOFF_DEBUGGING)
6156 ecoff_fix_loc (old_frag, old_frag_offset);
6160 else if (mips_relax.sequence != 2 && prev_nop_frag != NULL)
6164 /* Work out how many nops in prev_nop_frag are needed by IP,
6165 ignoring hazards generated by the first prev_nop_frag_since
6167 nops = nops_for_insn_or_target (prev_nop_frag_since, history, ip);
6168 gas_assert (nops <= prev_nop_frag_holds);
6170 /* Enforce NOPS as a minimum. */
6171 if (nops > prev_nop_frag_required)
6172 prev_nop_frag_required = nops;
6174 if (prev_nop_frag_holds == prev_nop_frag_required)
6176 /* Settle for the current number of nops. Update the history
6177 accordingly (for the benefit of any future .set reorder code). */
6178 prev_nop_frag = NULL;
6179 insert_into_history (prev_nop_frag_since,
6180 prev_nop_frag_holds, NOP_INSN);
6184 /* Allow this instruction to replace one of the nops that was
6185 tentatively added to prev_nop_frag. */
6186 prev_nop_frag->fr_fix -= NOP_INSN_SIZE;
6187 prev_nop_frag_holds--;
6188 prev_nop_frag_since++;
6192 method = get_append_method (ip, address_expr, reloc_type);
6193 branch_disp = method == APPEND_SWAP ? insn_length (history) : 0;
6195 dwarf2_emit_insn (0);
6196 /* We want MIPS16 and microMIPS debug info to use ISA-encoded addresses,
6197 so "move" the instruction address accordingly.
6199 Also, it doesn't seem appropriate for the assembler to reorder .loc
6200 entries. If this instruction is a branch that we are going to swap
6201 with the previous instruction, the two instructions should be
6202 treated as a unit, and the debug information for both instructions
6203 should refer to the start of the branch sequence. Using the
6204 current position is certainly wrong when swapping a 32-bit branch
6205 and a 16-bit delay slot, since the current position would then be
6206 in the middle of a branch. */
6207 dwarf2_move_insn ((HAVE_CODE_COMPRESSION ? 1 : 0) - branch_disp);
6209 relax32 = (mips_relax_branch
6210 /* Don't try branch relaxation within .set nomacro, or within
6211 .set noat if we use $at for PIC computations. If it turns
6212 out that the branch was out-of-range, we'll get an error. */
6213 && !mips_opts.warn_about_macros
6214 && (mips_opts.at || mips_pic == NO_PIC)
6215 /* Don't relax BPOSGE32/64 or BC1ANY2T/F and BC1ANY4T/F
6216 as they have no complementing branches. */
6217 && !(ip->insn_mo->ase & (ASE_MIPS3D | ASE_DSP64 | ASE_DSP)));
6219 if (!HAVE_CODE_COMPRESSION
6222 && *reloc_type == BFD_RELOC_16_PCREL_S2
6223 && delayed_branch_p (ip))
6225 relaxed_branch = TRUE;
6226 add_relaxed_insn (ip, (relaxed_branch_length
6228 uncond_branch_p (ip) ? -1
6229 : branch_likely_p (ip) ? 1
6233 uncond_branch_p (ip),
6234 branch_likely_p (ip),
6235 pinfo & INSN_WRITE_GPR_31,
6237 address_expr->X_add_symbol,
6238 address_expr->X_add_number);
6239 *reloc_type = BFD_RELOC_UNUSED;
6241 else if (mips_opts.micromips
6243 && ((relax32 && *reloc_type == BFD_RELOC_16_PCREL_S2)
6244 || *reloc_type > BFD_RELOC_UNUSED)
6245 && (delayed_branch_p (ip) || compact_branch_p (ip))
6246 /* Don't try branch relaxation when users specify
6247 16-bit/32-bit instructions. */
6248 && !forced_insn_length)
6250 bfd_boolean relax16 = *reloc_type > BFD_RELOC_UNUSED;
6251 int type = relax16 ? *reloc_type - BFD_RELOC_UNUSED : 0;
6252 int uncond = uncond_branch_p (ip) ? -1 : 0;
6253 int compact = compact_branch_p (ip);
6254 int al = pinfo & INSN_WRITE_GPR_31;
6257 gas_assert (address_expr != NULL);
6258 gas_assert (!mips_relax.sequence);
6260 relaxed_branch = TRUE;
6261 length32 = relaxed_micromips_32bit_branch_length (NULL, NULL, uncond);
6262 add_relaxed_insn (ip, relax32 ? length32 : 4, relax16 ? 2 : 4,
6263 RELAX_MICROMIPS_ENCODE (type, AT, uncond, compact, al,
6265 address_expr->X_add_symbol,
6266 address_expr->X_add_number);
6267 *reloc_type = BFD_RELOC_UNUSED;
6269 else if (mips_opts.mips16 && *reloc_type > BFD_RELOC_UNUSED)
6271 /* We need to set up a variant frag. */
6272 gas_assert (address_expr != NULL);
6273 add_relaxed_insn (ip, 4, 0,
6275 (*reloc_type - BFD_RELOC_UNUSED,
6276 forced_insn_length == 2, forced_insn_length == 4,
6277 delayed_branch_p (&history[0]),
6278 history[0].mips16_absolute_jump_p),
6279 make_expr_symbol (address_expr), 0);
6281 else if (mips_opts.mips16 && insn_length (ip) == 2)
6283 if (!delayed_branch_p (ip))
6284 /* Make sure there is enough room to swap this instruction with
6285 a following jump instruction. */
6287 add_fixed_insn (ip);
6291 if (mips_opts.mips16
6292 && mips_opts.noreorder
6293 && delayed_branch_p (&history[0]))
6294 as_warn (_("extended instruction in delay slot"));
6296 if (mips_relax.sequence)
6298 /* If we've reached the end of this frag, turn it into a variant
6299 frag and record the information for the instructions we've
6301 if (frag_room () < 4)
6302 relax_close_frag ();
6303 mips_relax.sizes[mips_relax.sequence - 1] += insn_length (ip);
6306 if (mips_relax.sequence != 2)
6308 if (mips_macro_warning.first_insn_sizes[0] == 0)
6309 mips_macro_warning.first_insn_sizes[0] = insn_length (ip);
6310 mips_macro_warning.sizes[0] += insn_length (ip);
6311 mips_macro_warning.insns[0]++;
6313 if (mips_relax.sequence != 1)
6315 if (mips_macro_warning.first_insn_sizes[1] == 0)
6316 mips_macro_warning.first_insn_sizes[1] = insn_length (ip);
6317 mips_macro_warning.sizes[1] += insn_length (ip);
6318 mips_macro_warning.insns[1]++;
6321 if (mips_opts.mips16)
6324 ip->mips16_absolute_jump_p = (*reloc_type == BFD_RELOC_MIPS16_JMP);
6326 add_fixed_insn (ip);
6329 if (!ip->complete_p && *reloc_type < BFD_RELOC_UNUSED)
6331 bfd_reloc_code_real_type final_type[3];
6332 reloc_howto_type *howto0;
6333 reloc_howto_type *howto;
6336 /* Perform any necessary conversion to microMIPS relocations
6337 and find out how many relocations there actually are. */
6338 for (i = 0; i < 3 && reloc_type[i] != BFD_RELOC_UNUSED; i++)
6339 final_type[i] = micromips_map_reloc (reloc_type[i]);
6341 /* In a compound relocation, it is the final (outermost)
6342 operator that determines the relocated field. */
6343 howto = howto0 = bfd_reloc_type_lookup (stdoutput, final_type[i - 1]);
6348 howto0 = bfd_reloc_type_lookup (stdoutput, final_type[0]);
6349 ip->fixp[0] = fix_new_exp (ip->frag, ip->where,
6350 bfd_get_reloc_size (howto),
6352 howto0 && howto0->pc_relative,
6355 /* Tag symbols that have a R_MIPS16_26 relocation against them. */
6356 if (final_type[0] == BFD_RELOC_MIPS16_JMP && ip->fixp[0]->fx_addsy)
6357 *symbol_get_tc (ip->fixp[0]->fx_addsy) = 1;
6359 /* These relocations can have an addend that won't fit in
6360 4 octets for 64bit assembly. */
6362 && ! howto->partial_inplace
6363 && (reloc_type[0] == BFD_RELOC_16
6364 || reloc_type[0] == BFD_RELOC_32
6365 || reloc_type[0] == BFD_RELOC_MIPS_JMP
6366 || reloc_type[0] == BFD_RELOC_GPREL16
6367 || reloc_type[0] == BFD_RELOC_MIPS_LITERAL
6368 || reloc_type[0] == BFD_RELOC_GPREL32
6369 || reloc_type[0] == BFD_RELOC_64
6370 || reloc_type[0] == BFD_RELOC_CTOR
6371 || reloc_type[0] == BFD_RELOC_MIPS_SUB
6372 || reloc_type[0] == BFD_RELOC_MIPS_HIGHEST
6373 || reloc_type[0] == BFD_RELOC_MIPS_HIGHER
6374 || reloc_type[0] == BFD_RELOC_MIPS_SCN_DISP
6375 || reloc_type[0] == BFD_RELOC_MIPS_REL16
6376 || reloc_type[0] == BFD_RELOC_MIPS_RELGOT
6377 || reloc_type[0] == BFD_RELOC_MIPS16_GPREL
6378 || hi16_reloc_p (reloc_type[0])
6379 || lo16_reloc_p (reloc_type[0])))
6380 ip->fixp[0]->fx_no_overflow = 1;
6382 /* These relocations can have an addend that won't fit in 2 octets. */
6383 if (reloc_type[0] == BFD_RELOC_MICROMIPS_7_PCREL_S1
6384 || reloc_type[0] == BFD_RELOC_MICROMIPS_10_PCREL_S1)
6385 ip->fixp[0]->fx_no_overflow = 1;
6387 if (mips_relax.sequence)
6389 if (mips_relax.first_fixup == 0)
6390 mips_relax.first_fixup = ip->fixp[0];
6392 else if (reloc_needs_lo_p (*reloc_type))
6394 struct mips_hi_fixup *hi_fixup;
6396 /* Reuse the last entry if it already has a matching %lo. */
6397 hi_fixup = mips_hi_fixup_list;
6399 || !fixup_has_matching_lo_p (hi_fixup->fixp))
6401 hi_fixup = ((struct mips_hi_fixup *)
6402 xmalloc (sizeof (struct mips_hi_fixup)));
6403 hi_fixup->next = mips_hi_fixup_list;
6404 mips_hi_fixup_list = hi_fixup;
6406 hi_fixup->fixp = ip->fixp[0];
6407 hi_fixup->seg = now_seg;
6410 /* Add fixups for the second and third relocations, if given.
6411 Note that the ABI allows the second relocation to be
6412 against RSS_UNDEF, RSS_GP, RSS_GP0 or RSS_LOC. At the
6413 moment we only use RSS_UNDEF, but we could add support
6414 for the others if it ever becomes necessary. */
6415 for (i = 1; i < 3; i++)
6416 if (reloc_type[i] != BFD_RELOC_UNUSED)
6418 ip->fixp[i] = fix_new (ip->frag, ip->where,
6419 ip->fixp[0]->fx_size, NULL, 0,
6420 FALSE, final_type[i]);
6422 /* Use fx_tcbit to mark compound relocs. */
6423 ip->fixp[0]->fx_tcbit = 1;
6424 ip->fixp[i]->fx_tcbit = 1;
6429 /* Update the register mask information. */
6430 mips_gprmask |= gpr_read_mask (ip) | gpr_write_mask (ip);
6431 mips_cprmask[1] |= fpr_read_mask (ip) | fpr_write_mask (ip);
6436 insert_into_history (0, 1, ip);
6439 case APPEND_ADD_WITH_NOP:
6441 struct mips_cl_insn *nop;
6443 insert_into_history (0, 1, ip);
6444 nop = get_delay_slot_nop (ip);
6445 add_fixed_insn (nop);
6446 insert_into_history (0, 1, nop);
6447 if (mips_relax.sequence)
6448 mips_relax.sizes[mips_relax.sequence - 1] += insn_length (nop);
6452 case APPEND_ADD_COMPACT:
6453 /* Convert MIPS16 jr/jalr into a "compact" jump. */
6454 gas_assert (mips_opts.mips16);
6455 ip->insn_opcode |= 0x0080;
6456 find_altered_mips16_opcode (ip);
6458 insert_into_history (0, 1, ip);
6463 struct mips_cl_insn delay = history[0];
6464 if (mips_opts.mips16)
6466 know (delay.frag == ip->frag);
6467 move_insn (ip, delay.frag, delay.where);
6468 move_insn (&delay, ip->frag, ip->where + insn_length (ip));
6470 else if (relaxed_branch || delay.frag != ip->frag)
6472 /* Add the delay slot instruction to the end of the
6473 current frag and shrink the fixed part of the
6474 original frag. If the branch occupies the tail of
6475 the latter, move it backwards to cover the gap. */
6476 delay.frag->fr_fix -= branch_disp;
6477 if (delay.frag == ip->frag)
6478 move_insn (ip, ip->frag, ip->where - branch_disp);
6479 add_fixed_insn (&delay);
6483 move_insn (&delay, ip->frag,
6484 ip->where - branch_disp + insn_length (ip));
6485 move_insn (ip, history[0].frag, history[0].where);
6489 insert_into_history (0, 1, &delay);
6494 /* If we have just completed an unconditional branch, clear the history. */
6495 if ((delayed_branch_p (&history[1]) && uncond_branch_p (&history[1]))
6496 || (compact_branch_p (&history[0]) && uncond_branch_p (&history[0])))
6500 mips_no_prev_insn ();
6502 for (i = 0; i < ARRAY_SIZE (history); i++)
6503 history[i].cleared_p = 1;
6506 /* We need to emit a label at the end of branch-likely macros. */
6507 if (emit_branch_likely_macro)
6509 emit_branch_likely_macro = FALSE;
6510 micromips_add_label ();
6513 /* We just output an insn, so the next one doesn't have a label. */
6514 mips_clear_insn_labels ();
6517 /* Forget that there was any previous instruction or label.
6518 When BRANCH is true, the branch history is also flushed. */
6521 mips_no_prev_insn (void)
6523 prev_nop_frag = NULL;
6524 insert_into_history (0, ARRAY_SIZE (history), NOP_INSN);
6525 mips_clear_insn_labels ();
6528 /* This function must be called before we emit something other than
6529 instructions. It is like mips_no_prev_insn except that it inserts
6530 any NOPS that might be needed by previous instructions. */
6533 mips_emit_delays (void)
6535 if (! mips_opts.noreorder)
6537 int nops = nops_for_insn (0, history, NULL);
6541 add_fixed_insn (NOP_INSN);
6542 mips_move_text_labels ();
6545 mips_no_prev_insn ();
6548 /* Start a (possibly nested) noreorder block. */
6551 start_noreorder (void)
6553 if (mips_opts.noreorder == 0)
6558 /* None of the instructions before the .set noreorder can be moved. */
6559 for (i = 0; i < ARRAY_SIZE (history); i++)
6560 history[i].fixed_p = 1;
6562 /* Insert any nops that might be needed between the .set noreorder
6563 block and the previous instructions. We will later remove any
6564 nops that turn out not to be needed. */
6565 nops = nops_for_insn (0, history, NULL);
6568 if (mips_optimize != 0)
6570 /* Record the frag which holds the nop instructions, so
6571 that we can remove them if we don't need them. */
6572 frag_grow (nops * NOP_INSN_SIZE);
6573 prev_nop_frag = frag_now;
6574 prev_nop_frag_holds = nops;
6575 prev_nop_frag_required = 0;
6576 prev_nop_frag_since = 0;
6579 for (; nops > 0; --nops)
6580 add_fixed_insn (NOP_INSN);
6582 /* Move on to a new frag, so that it is safe to simply
6583 decrease the size of prev_nop_frag. */
6584 frag_wane (frag_now);
6586 mips_move_text_labels ();
6588 mips_mark_labels ();
6589 mips_clear_insn_labels ();
6591 mips_opts.noreorder++;
6592 mips_any_noreorder = 1;
6595 /* End a nested noreorder block. */
6598 end_noreorder (void)
6600 mips_opts.noreorder--;
6601 if (mips_opts.noreorder == 0 && prev_nop_frag != NULL)
6603 /* Commit to inserting prev_nop_frag_required nops and go back to
6604 handling nop insertion the .set reorder way. */
6605 prev_nop_frag->fr_fix -= ((prev_nop_frag_holds - prev_nop_frag_required)
6607 insert_into_history (prev_nop_frag_since,
6608 prev_nop_frag_required, NOP_INSN);
6609 prev_nop_frag = NULL;
6613 /* Set up global variables for the start of a new macro. */
6618 memset (&mips_macro_warning.sizes, 0, sizeof (mips_macro_warning.sizes));
6619 memset (&mips_macro_warning.first_insn_sizes, 0,
6620 sizeof (mips_macro_warning.first_insn_sizes));
6621 memset (&mips_macro_warning.insns, 0, sizeof (mips_macro_warning.insns));
6622 mips_macro_warning.delay_slot_p = (mips_opts.noreorder
6623 && delayed_branch_p (&history[0]));
6624 switch (history[0].insn_mo->pinfo2
6625 & (INSN2_BRANCH_DELAY_32BIT | INSN2_BRANCH_DELAY_16BIT))
6627 case INSN2_BRANCH_DELAY_32BIT:
6628 mips_macro_warning.delay_slot_length = 4;
6630 case INSN2_BRANCH_DELAY_16BIT:
6631 mips_macro_warning.delay_slot_length = 2;
6634 mips_macro_warning.delay_slot_length = 0;
6637 mips_macro_warning.first_frag = NULL;
6640 /* Given that a macro is longer than one instruction or of the wrong size,
6641 return the appropriate warning for it. Return null if no warning is
6642 needed. SUBTYPE is a bitmask of RELAX_DELAY_SLOT, RELAX_DELAY_SLOT_16BIT,
6643 RELAX_DELAY_SLOT_SIZE_FIRST, RELAX_DELAY_SLOT_SIZE_SECOND,
6644 and RELAX_NOMACRO. */
6647 macro_warning (relax_substateT subtype)
6649 if (subtype & RELAX_DELAY_SLOT)
6650 return _("Macro instruction expanded into multiple instructions"
6651 " in a branch delay slot");
6652 else if (subtype & RELAX_NOMACRO)
6653 return _("Macro instruction expanded into multiple instructions");
6654 else if (subtype & (RELAX_DELAY_SLOT_SIZE_FIRST
6655 | RELAX_DELAY_SLOT_SIZE_SECOND))
6656 return ((subtype & RELAX_DELAY_SLOT_16BIT)
6657 ? _("Macro instruction expanded into a wrong size instruction"
6658 " in a 16-bit branch delay slot")
6659 : _("Macro instruction expanded into a wrong size instruction"
6660 " in a 32-bit branch delay slot"));
6665 /* Finish up a macro. Emit warnings as appropriate. */
6670 /* Relaxation warning flags. */
6671 relax_substateT subtype = 0;
6673 /* Check delay slot size requirements. */
6674 if (mips_macro_warning.delay_slot_length == 2)
6675 subtype |= RELAX_DELAY_SLOT_16BIT;
6676 if (mips_macro_warning.delay_slot_length != 0)
6678 if (mips_macro_warning.delay_slot_length
6679 != mips_macro_warning.first_insn_sizes[0])
6680 subtype |= RELAX_DELAY_SLOT_SIZE_FIRST;
6681 if (mips_macro_warning.delay_slot_length
6682 != mips_macro_warning.first_insn_sizes[1])
6683 subtype |= RELAX_DELAY_SLOT_SIZE_SECOND;
6686 /* Check instruction count requirements. */
6687 if (mips_macro_warning.insns[0] > 1 || mips_macro_warning.insns[1] > 1)
6689 if (mips_macro_warning.insns[1] > mips_macro_warning.insns[0])
6690 subtype |= RELAX_SECOND_LONGER;
6691 if (mips_opts.warn_about_macros)
6692 subtype |= RELAX_NOMACRO;
6693 if (mips_macro_warning.delay_slot_p)
6694 subtype |= RELAX_DELAY_SLOT;
6697 /* If both alternatives fail to fill a delay slot correctly,
6698 emit the warning now. */
6699 if ((subtype & RELAX_DELAY_SLOT_SIZE_FIRST) != 0
6700 && (subtype & RELAX_DELAY_SLOT_SIZE_SECOND) != 0)
6705 s = subtype & (RELAX_DELAY_SLOT_16BIT
6706 | RELAX_DELAY_SLOT_SIZE_FIRST
6707 | RELAX_DELAY_SLOT_SIZE_SECOND);
6708 msg = macro_warning (s);
6710 as_warn ("%s", msg);
6714 /* If both implementations are longer than 1 instruction, then emit the
6716 if (mips_macro_warning.insns[0] > 1 && mips_macro_warning.insns[1] > 1)
6721 s = subtype & (RELAX_SECOND_LONGER | RELAX_NOMACRO | RELAX_DELAY_SLOT);
6722 msg = macro_warning (s);
6724 as_warn ("%s", msg);
6728 /* If any flags still set, then one implementation might need a warning
6729 and the other either will need one of a different kind or none at all.
6730 Pass any remaining flags over to relaxation. */
6731 if (mips_macro_warning.first_frag != NULL)
6732 mips_macro_warning.first_frag->fr_subtype |= subtype;
6735 /* Instruction operand formats used in macros that vary between
6736 standard MIPS and microMIPS code. */
6738 static const char * const brk_fmt[2][2] = { { "c", "c" }, { "mF", "c" } };
6739 static const char * const cop12_fmt[2] = { "E,o(b)", "E,~(b)" };
6740 static const char * const jalr_fmt[2] = { "d,s", "t,s" };
6741 static const char * const lui_fmt[2] = { "t,u", "s,u" };
6742 static const char * const mem12_fmt[2] = { "t,o(b)", "t,~(b)" };
6743 static const char * const mfhl_fmt[2][2] = { { "d", "d" }, { "mj", "s" } };
6744 static const char * const shft_fmt[2] = { "d,w,<", "t,r,<" };
6745 static const char * const trap_fmt[2] = { "s,t,q", "s,t,|" };
6747 #define BRK_FMT (brk_fmt[mips_opts.micromips][mips_opts.insn32])
6748 #define COP12_FMT (cop12_fmt[mips_opts.micromips])
6749 #define JALR_FMT (jalr_fmt[mips_opts.micromips])
6750 #define LUI_FMT (lui_fmt[mips_opts.micromips])
6751 #define MEM12_FMT (mem12_fmt[mips_opts.micromips])
6752 #define MFHL_FMT (mfhl_fmt[mips_opts.micromips][mips_opts.insn32])
6753 #define SHFT_FMT (shft_fmt[mips_opts.micromips])
6754 #define TRAP_FMT (trap_fmt[mips_opts.micromips])
6756 /* Read a macro's relocation codes from *ARGS and store them in *R.
6757 The first argument in *ARGS will be either the code for a single
6758 relocation or -1 followed by the three codes that make up a
6759 composite relocation. */
6762 macro_read_relocs (va_list *args, bfd_reloc_code_real_type *r)
6766 next = va_arg (*args, int);
6768 r[0] = (bfd_reloc_code_real_type) next;
6771 for (i = 0; i < 3; i++)
6772 r[i] = (bfd_reloc_code_real_type) va_arg (*args, int);
6773 /* This function is only used for 16-bit relocation fields.
6774 To make the macro code simpler, treat an unrelocated value
6775 in the same way as BFD_RELOC_LO16. */
6776 if (r[0] == BFD_RELOC_UNUSED)
6777 r[0] = BFD_RELOC_LO16;
6781 /* Build an instruction created by a macro expansion. This is passed
6782 a pointer to the count of instructions created so far, an
6783 expression, the name of the instruction to build, an operand format
6784 string, and corresponding arguments. */
6787 macro_build (expressionS *ep, const char *name, const char *fmt, ...)
6789 const struct mips_opcode *mo = NULL;
6790 bfd_reloc_code_real_type r[3];
6791 const struct mips_opcode *amo;
6792 const struct mips_operand *operand;
6793 struct hash_control *hash;
6794 struct mips_cl_insn insn;
6798 va_start (args, fmt);
6800 if (mips_opts.mips16)
6802 mips16_macro_build (ep, name, fmt, &args);
6807 r[0] = BFD_RELOC_UNUSED;
6808 r[1] = BFD_RELOC_UNUSED;
6809 r[2] = BFD_RELOC_UNUSED;
6810 hash = mips_opts.micromips ? micromips_op_hash : op_hash;
6811 amo = (struct mips_opcode *) hash_find (hash, name);
6813 gas_assert (strcmp (name, amo->name) == 0);
6817 /* Search until we get a match for NAME. It is assumed here that
6818 macros will never generate MDMX, MIPS-3D, or MT instructions.
6819 We try to match an instruction that fulfils the branch delay
6820 slot instruction length requirement (if any) of the previous
6821 instruction. While doing this we record the first instruction
6822 seen that matches all the other conditions and use it anyway
6823 if the requirement cannot be met; we will issue an appropriate
6824 warning later on. */
6825 if (strcmp (fmt, amo->args) == 0
6826 && amo->pinfo != INSN_MACRO
6827 && is_opcode_valid (amo)
6828 && is_size_valid (amo))
6830 if (is_delay_slot_valid (amo))
6840 gas_assert (amo->name);
6842 while (strcmp (name, amo->name) == 0);
6845 create_insn (&insn, mo);
6858 macro_read_relocs (&args, r);
6859 gas_assert (*r == BFD_RELOC_GPREL16
6860 || *r == BFD_RELOC_MIPS_HIGHER
6861 || *r == BFD_RELOC_HI16_S
6862 || *r == BFD_RELOC_LO16
6863 || *r == BFD_RELOC_MIPS_GOT_OFST);
6867 macro_read_relocs (&args, r);
6871 macro_read_relocs (&args, r);
6872 gas_assert (ep != NULL
6873 && (ep->X_op == O_constant
6874 || (ep->X_op == O_symbol
6875 && (*r == BFD_RELOC_MIPS_HIGHEST
6876 || *r == BFD_RELOC_HI16_S
6877 || *r == BFD_RELOC_HI16
6878 || *r == BFD_RELOC_GPREL16
6879 || *r == BFD_RELOC_MIPS_GOT_HI16
6880 || *r == BFD_RELOC_MIPS_CALL_HI16))));
6884 gas_assert (ep != NULL);
6887 * This allows macro() to pass an immediate expression for
6888 * creating short branches without creating a symbol.
6890 * We don't allow branch relaxation for these branches, as
6891 * they should only appear in ".set nomacro" anyway.
6893 if (ep->X_op == O_constant)
6895 /* For microMIPS we always use relocations for branches.
6896 So we should not resolve immediate values. */
6897 gas_assert (!mips_opts.micromips);
6899 if ((ep->X_add_number & 3) != 0)
6900 as_bad (_("branch to misaligned address (0x%lx)"),
6901 (unsigned long) ep->X_add_number);
6902 if ((ep->X_add_number + 0x20000) & ~0x3ffff)
6903 as_bad (_("branch address range overflow (0x%lx)"),
6904 (unsigned long) ep->X_add_number);
6905 insn.insn_opcode |= (ep->X_add_number >> 2) & 0xffff;
6909 *r = BFD_RELOC_16_PCREL_S2;
6913 gas_assert (ep != NULL);
6914 *r = BFD_RELOC_MIPS_JMP;
6918 operand = (mips_opts.micromips
6919 ? decode_micromips_operand (fmt)
6920 : decode_mips_operand (fmt));
6924 uval = va_arg (args, int);
6925 if (operand->type == OP_CLO_CLZ_DEST)
6926 uval |= (uval << 5);
6927 insn_insert_operand (&insn, operand, uval);
6929 if (*fmt == '+' || *fmt == 'm')
6935 gas_assert (*r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL);
6937 append_insn (&insn, ep, r, TRUE);
6941 mips16_macro_build (expressionS *ep, const char *name, const char *fmt,
6944 struct mips_opcode *mo;
6945 struct mips_cl_insn insn;
6946 const struct mips_operand *operand;
6947 bfd_reloc_code_real_type r[3]
6948 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
6950 mo = (struct mips_opcode *) hash_find (mips16_op_hash, name);
6952 gas_assert (strcmp (name, mo->name) == 0);
6954 while (strcmp (fmt, mo->args) != 0 || mo->pinfo == INSN_MACRO)
6957 gas_assert (mo->name);
6958 gas_assert (strcmp (name, mo->name) == 0);
6961 create_insn (&insn, mo);
6999 gas_assert (ep != NULL);
7001 if (ep->X_op != O_constant)
7002 *r = (int) BFD_RELOC_UNUSED + c;
7003 else if (calculate_reloc (*r, ep->X_add_number, &value))
7005 mips16_immed (NULL, 0, c, *r, value, 0, &insn.insn_opcode);
7007 *r = BFD_RELOC_UNUSED;
7013 operand = decode_mips16_operand (c, FALSE);
7017 insn_insert_operand (&insn, operand, va_arg (args, int));
7022 gas_assert (*r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL);
7024 append_insn (&insn, ep, r, TRUE);
7028 * Sign-extend 32-bit mode constants that have bit 31 set and all
7029 * higher bits unset.
7032 normalize_constant_expr (expressionS *ex)
7034 if (ex->X_op == O_constant
7035 && IS_ZEXT_32BIT_NUM (ex->X_add_number))
7036 ex->X_add_number = (((ex->X_add_number & 0xffffffff) ^ 0x80000000)
7041 * Sign-extend 32-bit mode address offsets that have bit 31 set and
7042 * all higher bits unset.
7045 normalize_address_expr (expressionS *ex)
7047 if (((ex->X_op == O_constant && HAVE_32BIT_ADDRESSES)
7048 || (ex->X_op == O_symbol && HAVE_32BIT_SYMBOLS))
7049 && IS_ZEXT_32BIT_NUM (ex->X_add_number))
7050 ex->X_add_number = (((ex->X_add_number & 0xffffffff) ^ 0x80000000)
7055 * Generate a "jalr" instruction with a relocation hint to the called
7056 * function. This occurs in NewABI PIC code.
7059 macro_build_jalr (expressionS *ep, int cprestore)
7061 static const bfd_reloc_code_real_type jalr_relocs[2]
7062 = { BFD_RELOC_MIPS_JALR, BFD_RELOC_MICROMIPS_JALR };
7063 bfd_reloc_code_real_type jalr_reloc = jalr_relocs[mips_opts.micromips];
7067 if (MIPS_JALR_HINT_P (ep))
7072 if (mips_opts.micromips)
7074 jalr = ((mips_opts.noreorder && !cprestore) || mips_opts.insn32
7075 ? "jalr" : "jalrs");
7076 if (MIPS_JALR_HINT_P (ep)
7078 || (history[0].insn_mo->pinfo2 & INSN2_BRANCH_DELAY_32BIT))
7079 macro_build (NULL, jalr, "t,s", RA, PIC_CALL_REG);
7081 macro_build (NULL, jalr, "mj", PIC_CALL_REG);
7084 macro_build (NULL, "jalr", "d,s", RA, PIC_CALL_REG);
7085 if (MIPS_JALR_HINT_P (ep))
7086 fix_new_exp (frag_now, f - frag_now->fr_literal, 4, ep, FALSE, jalr_reloc);
7090 * Generate a "lui" instruction.
7093 macro_build_lui (expressionS *ep, int regnum)
7095 gas_assert (! mips_opts.mips16);
7097 if (ep->X_op != O_constant)
7099 gas_assert (ep->X_op == O_symbol);
7100 /* _gp_disp is a special case, used from s_cpload.
7101 __gnu_local_gp is used if mips_no_shared. */
7102 gas_assert (mips_pic == NO_PIC
7104 && strcmp (S_GET_NAME (ep->X_add_symbol), "_gp_disp") == 0)
7105 || (! mips_in_shared
7106 && strcmp (S_GET_NAME (ep->X_add_symbol),
7107 "__gnu_local_gp") == 0));
7110 macro_build (ep, "lui", LUI_FMT, regnum, BFD_RELOC_HI16_S);
7113 /* Generate a sequence of instructions to do a load or store from a constant
7114 offset off of a base register (breg) into/from a target register (treg),
7115 using AT if necessary. */
7117 macro_build_ldst_constoffset (expressionS *ep, const char *op,
7118 int treg, int breg, int dbl)
7120 gas_assert (ep->X_op == O_constant);
7122 /* Sign-extending 32-bit constants makes their handling easier. */
7124 normalize_constant_expr (ep);
7126 /* Right now, this routine can only handle signed 32-bit constants. */
7127 if (! IS_SEXT_32BIT_NUM(ep->X_add_number + 0x8000))
7128 as_warn (_("operand overflow"));
7130 if (IS_SEXT_16BIT_NUM(ep->X_add_number))
7132 /* Signed 16-bit offset will fit in the op. Easy! */
7133 macro_build (ep, op, "t,o(b)", treg, BFD_RELOC_LO16, breg);
7137 /* 32-bit offset, need multiple instructions and AT, like:
7138 lui $tempreg,const_hi (BFD_RELOC_HI16_S)
7139 addu $tempreg,$tempreg,$breg
7140 <op> $treg,const_lo($tempreg) (BFD_RELOC_LO16)
7141 to handle the complete offset. */
7142 macro_build_lui (ep, AT);
7143 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, AT, breg);
7144 macro_build (ep, op, "t,o(b)", treg, BFD_RELOC_LO16, AT);
7147 as_bad (_("Macro used $at after \".set noat\""));
7152 * Generates code to set the $at register to true (one)
7153 * if reg is less than the immediate expression.
7156 set_at (int reg, int unsignedp)
7158 if (imm_expr.X_op == O_constant
7159 && imm_expr.X_add_number >= -0x8000
7160 && imm_expr.X_add_number < 0x8000)
7161 macro_build (&imm_expr, unsignedp ? "sltiu" : "slti", "t,r,j",
7162 AT, reg, BFD_RELOC_LO16);
7165 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
7166 macro_build (NULL, unsignedp ? "sltu" : "slt", "d,v,t", AT, reg, AT);
7170 /* Count the leading zeroes by performing a binary chop. This is a
7171 bulky bit of source, but performance is a LOT better for the
7172 majority of values than a simple loop to count the bits:
7173 for (lcnt = 0; (lcnt < 32); lcnt++)
7174 if ((v) & (1 << (31 - lcnt)))
7176 However it is not code size friendly, and the gain will drop a bit
7177 on certain cached systems.
7179 #define COUNT_TOP_ZEROES(v) \
7180 (((v) & ~0xffff) == 0 \
7181 ? ((v) & ~0xff) == 0 \
7182 ? ((v) & ~0xf) == 0 \
7183 ? ((v) & ~0x3) == 0 \
7184 ? ((v) & ~0x1) == 0 \
7189 : ((v) & ~0x7) == 0 \
7192 : ((v) & ~0x3f) == 0 \
7193 ? ((v) & ~0x1f) == 0 \
7196 : ((v) & ~0x7f) == 0 \
7199 : ((v) & ~0xfff) == 0 \
7200 ? ((v) & ~0x3ff) == 0 \
7201 ? ((v) & ~0x1ff) == 0 \
7204 : ((v) & ~0x7ff) == 0 \
7207 : ((v) & ~0x3fff) == 0 \
7208 ? ((v) & ~0x1fff) == 0 \
7211 : ((v) & ~0x7fff) == 0 \
7214 : ((v) & ~0xffffff) == 0 \
7215 ? ((v) & ~0xfffff) == 0 \
7216 ? ((v) & ~0x3ffff) == 0 \
7217 ? ((v) & ~0x1ffff) == 0 \
7220 : ((v) & ~0x7ffff) == 0 \
7223 : ((v) & ~0x3fffff) == 0 \
7224 ? ((v) & ~0x1fffff) == 0 \
7227 : ((v) & ~0x7fffff) == 0 \
7230 : ((v) & ~0xfffffff) == 0 \
7231 ? ((v) & ~0x3ffffff) == 0 \
7232 ? ((v) & ~0x1ffffff) == 0 \
7235 : ((v) & ~0x7ffffff) == 0 \
7238 : ((v) & ~0x3fffffff) == 0 \
7239 ? ((v) & ~0x1fffffff) == 0 \
7242 : ((v) & ~0x7fffffff) == 0 \
7247 * This routine generates the least number of instructions necessary to load
7248 * an absolute expression value into a register.
7251 load_register (int reg, expressionS *ep, int dbl)
7254 expressionS hi32, lo32;
7256 if (ep->X_op != O_big)
7258 gas_assert (ep->X_op == O_constant);
7260 /* Sign-extending 32-bit constants makes their handling easier. */
7262 normalize_constant_expr (ep);
7264 if (IS_SEXT_16BIT_NUM (ep->X_add_number))
7266 /* We can handle 16 bit signed values with an addiu to
7267 $zero. No need to ever use daddiu here, since $zero and
7268 the result are always correct in 32 bit mode. */
7269 macro_build (ep, "addiu", "t,r,j", reg, 0, BFD_RELOC_LO16);
7272 else if (ep->X_add_number >= 0 && ep->X_add_number < 0x10000)
7274 /* We can handle 16 bit unsigned values with an ori to
7276 macro_build (ep, "ori", "t,r,i", reg, 0, BFD_RELOC_LO16);
7279 else if ((IS_SEXT_32BIT_NUM (ep->X_add_number)))
7281 /* 32 bit values require an lui. */
7282 macro_build (ep, "lui", LUI_FMT, reg, BFD_RELOC_HI16);
7283 if ((ep->X_add_number & 0xffff) != 0)
7284 macro_build (ep, "ori", "t,r,i", reg, reg, BFD_RELOC_LO16);
7289 /* The value is larger than 32 bits. */
7291 if (!dbl || HAVE_32BIT_GPRS)
7295 sprintf_vma (value, ep->X_add_number);
7296 as_bad (_("Number (0x%s) larger than 32 bits"), value);
7297 macro_build (ep, "addiu", "t,r,j", reg, 0, BFD_RELOC_LO16);
7301 if (ep->X_op != O_big)
7304 hi32.X_add_number = (valueT) hi32.X_add_number >> 16;
7305 hi32.X_add_number = (valueT) hi32.X_add_number >> 16;
7306 hi32.X_add_number &= 0xffffffff;
7308 lo32.X_add_number &= 0xffffffff;
7312 gas_assert (ep->X_add_number > 2);
7313 if (ep->X_add_number == 3)
7314 generic_bignum[3] = 0;
7315 else if (ep->X_add_number > 4)
7316 as_bad (_("Number larger than 64 bits"));
7317 lo32.X_op = O_constant;
7318 lo32.X_add_number = generic_bignum[0] + (generic_bignum[1] << 16);
7319 hi32.X_op = O_constant;
7320 hi32.X_add_number = generic_bignum[2] + (generic_bignum[3] << 16);
7323 if (hi32.X_add_number == 0)
7328 unsigned long hi, lo;
7330 if (hi32.X_add_number == (offsetT) 0xffffffff)
7332 if ((lo32.X_add_number & 0xffff8000) == 0xffff8000)
7334 macro_build (&lo32, "addiu", "t,r,j", reg, 0, BFD_RELOC_LO16);
7337 if (lo32.X_add_number & 0x80000000)
7339 macro_build (&lo32, "lui", LUI_FMT, reg, BFD_RELOC_HI16);
7340 if (lo32.X_add_number & 0xffff)
7341 macro_build (&lo32, "ori", "t,r,i", reg, reg, BFD_RELOC_LO16);
7346 /* Check for 16bit shifted constant. We know that hi32 is
7347 non-zero, so start the mask on the first bit of the hi32
7352 unsigned long himask, lomask;
7356 himask = 0xffff >> (32 - shift);
7357 lomask = (0xffff << shift) & 0xffffffff;
7361 himask = 0xffff << (shift - 32);
7364 if ((hi32.X_add_number & ~(offsetT) himask) == 0
7365 && (lo32.X_add_number & ~(offsetT) lomask) == 0)
7369 tmp.X_op = O_constant;
7371 tmp.X_add_number = ((hi32.X_add_number << (32 - shift))
7372 | (lo32.X_add_number >> shift));
7374 tmp.X_add_number = hi32.X_add_number >> (shift - 32);
7375 macro_build (&tmp, "ori", "t,r,i", reg, 0, BFD_RELOC_LO16);
7376 macro_build (NULL, (shift >= 32) ? "dsll32" : "dsll", SHFT_FMT,
7377 reg, reg, (shift >= 32) ? shift - 32 : shift);
7382 while (shift <= (64 - 16));
7384 /* Find the bit number of the lowest one bit, and store the
7385 shifted value in hi/lo. */
7386 hi = (unsigned long) (hi32.X_add_number & 0xffffffff);
7387 lo = (unsigned long) (lo32.X_add_number & 0xffffffff);
7391 while ((lo & 1) == 0)
7396 lo |= (hi & (((unsigned long) 1 << bit) - 1)) << (32 - bit);
7402 while ((hi & 1) == 0)
7411 /* Optimize if the shifted value is a (power of 2) - 1. */
7412 if ((hi == 0 && ((lo + 1) & lo) == 0)
7413 || (lo == 0xffffffff && ((hi + 1) & hi) == 0))
7415 shift = COUNT_TOP_ZEROES ((unsigned int) hi32.X_add_number);
7420 /* This instruction will set the register to be all
7422 tmp.X_op = O_constant;
7423 tmp.X_add_number = (offsetT) -1;
7424 macro_build (&tmp, "addiu", "t,r,j", reg, 0, BFD_RELOC_LO16);
7428 macro_build (NULL, (bit >= 32) ? "dsll32" : "dsll", SHFT_FMT,
7429 reg, reg, (bit >= 32) ? bit - 32 : bit);
7431 macro_build (NULL, (shift >= 32) ? "dsrl32" : "dsrl", SHFT_FMT,
7432 reg, reg, (shift >= 32) ? shift - 32 : shift);
7437 /* Sign extend hi32 before calling load_register, because we can
7438 generally get better code when we load a sign extended value. */
7439 if ((hi32.X_add_number & 0x80000000) != 0)
7440 hi32.X_add_number |= ~(offsetT) 0xffffffff;
7441 load_register (reg, &hi32, 0);
7444 if ((lo32.X_add_number & 0xffff0000) == 0)
7448 macro_build (NULL, "dsll32", SHFT_FMT, reg, freg, 0);
7456 if ((freg == 0) && (lo32.X_add_number == (offsetT) 0xffffffff))
7458 macro_build (&lo32, "lui", LUI_FMT, reg, BFD_RELOC_HI16);
7459 macro_build (NULL, "dsrl32", SHFT_FMT, reg, reg, 0);
7465 macro_build (NULL, "dsll", SHFT_FMT, reg, freg, 16);
7469 mid16.X_add_number >>= 16;
7470 macro_build (&mid16, "ori", "t,r,i", reg, freg, BFD_RELOC_LO16);
7471 macro_build (NULL, "dsll", SHFT_FMT, reg, reg, 16);
7474 if ((lo32.X_add_number & 0xffff) != 0)
7475 macro_build (&lo32, "ori", "t,r,i", reg, freg, BFD_RELOC_LO16);
7479 load_delay_nop (void)
7481 if (!gpr_interlocks)
7482 macro_build (NULL, "nop", "");
7485 /* Load an address into a register. */
7488 load_address (int reg, expressionS *ep, int *used_at)
7490 if (ep->X_op != O_constant
7491 && ep->X_op != O_symbol)
7493 as_bad (_("expression too complex"));
7494 ep->X_op = O_constant;
7497 if (ep->X_op == O_constant)
7499 load_register (reg, ep, HAVE_64BIT_ADDRESSES);
7503 if (mips_pic == NO_PIC)
7505 /* If this is a reference to a GP relative symbol, we want
7506 addiu $reg,$gp,<sym> (BFD_RELOC_GPREL16)
7508 lui $reg,<sym> (BFD_RELOC_HI16_S)
7509 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
7510 If we have an addend, we always use the latter form.
7512 With 64bit address space and a usable $at we want
7513 lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST)
7514 lui $at,<sym> (BFD_RELOC_HI16_S)
7515 daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER)
7516 daddiu $at,<sym> (BFD_RELOC_LO16)
7520 If $at is already in use, we use a path which is suboptimal
7521 on superscalar processors.
7522 lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST)
7523 daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER)
7525 daddiu $reg,<sym> (BFD_RELOC_HI16_S)
7527 daddiu $reg,<sym> (BFD_RELOC_LO16)
7529 For GP relative symbols in 64bit address space we can use
7530 the same sequence as in 32bit address space. */
7531 if (HAVE_64BIT_SYMBOLS)
7533 if ((valueT) ep->X_add_number <= MAX_GPREL_OFFSET
7534 && !nopic_need_relax (ep->X_add_symbol, 1))
7536 relax_start (ep->X_add_symbol);
7537 macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", reg,
7538 mips_gp_register, BFD_RELOC_GPREL16);
7542 if (*used_at == 0 && mips_opts.at)
7544 macro_build (ep, "lui", LUI_FMT, reg, BFD_RELOC_MIPS_HIGHEST);
7545 macro_build (ep, "lui", LUI_FMT, AT, BFD_RELOC_HI16_S);
7546 macro_build (ep, "daddiu", "t,r,j", reg, reg,
7547 BFD_RELOC_MIPS_HIGHER);
7548 macro_build (ep, "daddiu", "t,r,j", AT, AT, BFD_RELOC_LO16);
7549 macro_build (NULL, "dsll32", SHFT_FMT, reg, reg, 0);
7550 macro_build (NULL, "daddu", "d,v,t", reg, reg, AT);
7555 macro_build (ep, "lui", LUI_FMT, reg, BFD_RELOC_MIPS_HIGHEST);
7556 macro_build (ep, "daddiu", "t,r,j", reg, reg,
7557 BFD_RELOC_MIPS_HIGHER);
7558 macro_build (NULL, "dsll", SHFT_FMT, reg, reg, 16);
7559 macro_build (ep, "daddiu", "t,r,j", reg, reg, BFD_RELOC_HI16_S);
7560 macro_build (NULL, "dsll", SHFT_FMT, reg, reg, 16);
7561 macro_build (ep, "daddiu", "t,r,j", reg, reg, BFD_RELOC_LO16);
7564 if (mips_relax.sequence)
7569 if ((valueT) ep->X_add_number <= MAX_GPREL_OFFSET
7570 && !nopic_need_relax (ep->X_add_symbol, 1))
7572 relax_start (ep->X_add_symbol);
7573 macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", reg,
7574 mips_gp_register, BFD_RELOC_GPREL16);
7577 macro_build_lui (ep, reg);
7578 macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j",
7579 reg, reg, BFD_RELOC_LO16);
7580 if (mips_relax.sequence)
7584 else if (!mips_big_got)
7588 /* If this is a reference to an external symbol, we want
7589 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
7591 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
7593 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
7594 If there is a constant, it must be added in after.
7596 If we have NewABI, we want
7597 lw $reg,<sym+cst>($gp) (BFD_RELOC_MIPS_GOT_DISP)
7598 unless we're referencing a global symbol with a non-zero
7599 offset, in which case cst must be added separately. */
7602 if (ep->X_add_number)
7604 ex.X_add_number = ep->X_add_number;
7605 ep->X_add_number = 0;
7606 relax_start (ep->X_add_symbol);
7607 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
7608 BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
7609 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
7610 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
7611 ex.X_op = O_constant;
7612 macro_build (&ex, ADDRESS_ADDI_INSN, "t,r,j",
7613 reg, reg, BFD_RELOC_LO16);
7614 ep->X_add_number = ex.X_add_number;
7617 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
7618 BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
7619 if (mips_relax.sequence)
7624 ex.X_add_number = ep->X_add_number;
7625 ep->X_add_number = 0;
7626 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
7627 BFD_RELOC_MIPS_GOT16, mips_gp_register);
7629 relax_start (ep->X_add_symbol);
7631 macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", reg, reg,
7635 if (ex.X_add_number != 0)
7637 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
7638 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
7639 ex.X_op = O_constant;
7640 macro_build (&ex, ADDRESS_ADDI_INSN, "t,r,j",
7641 reg, reg, BFD_RELOC_LO16);
7645 else if (mips_big_got)
7649 /* This is the large GOT case. If this is a reference to an
7650 external symbol, we want
7651 lui $reg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
7653 lw $reg,<sym>($reg) (BFD_RELOC_MIPS_GOT_LO16)
7655 Otherwise, for a reference to a local symbol in old ABI, we want
7656 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
7658 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
7659 If there is a constant, it must be added in after.
7661 In the NewABI, for local symbols, with or without offsets, we want:
7662 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
7663 addiu $reg,$reg,<sym> (BFD_RELOC_MIPS_GOT_OFST)
7667 ex.X_add_number = ep->X_add_number;
7668 ep->X_add_number = 0;
7669 relax_start (ep->X_add_symbol);
7670 macro_build (ep, "lui", LUI_FMT, reg, BFD_RELOC_MIPS_GOT_HI16);
7671 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
7672 reg, reg, mips_gp_register);
7673 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)",
7674 reg, BFD_RELOC_MIPS_GOT_LO16, reg);
7675 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
7676 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
7677 else if (ex.X_add_number)
7679 ex.X_op = O_constant;
7680 macro_build (&ex, ADDRESS_ADDI_INSN, "t,r,j", reg, reg,
7684 ep->X_add_number = ex.X_add_number;
7686 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
7687 BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register);
7688 macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", reg, reg,
7689 BFD_RELOC_MIPS_GOT_OFST);
7694 ex.X_add_number = ep->X_add_number;
7695 ep->X_add_number = 0;
7696 relax_start (ep->X_add_symbol);
7697 macro_build (ep, "lui", LUI_FMT, reg, BFD_RELOC_MIPS_GOT_HI16);
7698 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
7699 reg, reg, mips_gp_register);
7700 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)",
7701 reg, BFD_RELOC_MIPS_GOT_LO16, reg);
7703 if (reg_needs_delay (mips_gp_register))
7705 /* We need a nop before loading from $gp. This special
7706 check is required because the lui which starts the main
7707 instruction stream does not refer to $gp, and so will not
7708 insert the nop which may be required. */
7709 macro_build (NULL, "nop", "");
7711 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
7712 BFD_RELOC_MIPS_GOT16, mips_gp_register);
7714 macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", reg, reg,
7718 if (ex.X_add_number != 0)
7720 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
7721 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
7722 ex.X_op = O_constant;
7723 macro_build (&ex, ADDRESS_ADDI_INSN, "t,r,j", reg, reg,
7731 if (!mips_opts.at && *used_at == 1)
7732 as_bad (_("Macro used $at after \".set noat\""));
7735 /* Move the contents of register SOURCE into register DEST. */
7738 move_register (int dest, int source)
7740 /* Prefer to use a 16-bit microMIPS instruction unless the previous
7741 instruction specifically requires a 32-bit one. */
7742 if (mips_opts.micromips
7743 && !mips_opts.insn32
7744 && !(history[0].insn_mo->pinfo2 & INSN2_BRANCH_DELAY_32BIT))
7745 macro_build (NULL, "move", "mp,mj", dest, source);
7747 macro_build (NULL, HAVE_32BIT_GPRS ? "addu" : "daddu", "d,v,t",
7751 /* Emit an SVR4 PIC sequence to load address LOCAL into DEST, where
7752 LOCAL is the sum of a symbol and a 16-bit or 32-bit displacement.
7753 The two alternatives are:
7755 Global symbol Local sybmol
7756 ------------- ------------
7757 lw DEST,%got(SYMBOL) lw DEST,%got(SYMBOL + OFFSET)
7759 addiu DEST,DEST,OFFSET addiu DEST,DEST,%lo(SYMBOL + OFFSET)
7761 load_got_offset emits the first instruction and add_got_offset
7762 emits the second for a 16-bit offset or add_got_offset_hilo emits
7763 a sequence to add a 32-bit offset using a scratch register. */
7766 load_got_offset (int dest, expressionS *local)
7771 global.X_add_number = 0;
7773 relax_start (local->X_add_symbol);
7774 macro_build (&global, ADDRESS_LOAD_INSN, "t,o(b)", dest,
7775 BFD_RELOC_MIPS_GOT16, mips_gp_register);
7777 macro_build (local, ADDRESS_LOAD_INSN, "t,o(b)", dest,
7778 BFD_RELOC_MIPS_GOT16, mips_gp_register);
7783 add_got_offset (int dest, expressionS *local)
7787 global.X_op = O_constant;
7788 global.X_op_symbol = NULL;
7789 global.X_add_symbol = NULL;
7790 global.X_add_number = local->X_add_number;
7792 relax_start (local->X_add_symbol);
7793 macro_build (&global, ADDRESS_ADDI_INSN, "t,r,j",
7794 dest, dest, BFD_RELOC_LO16);
7796 macro_build (local, ADDRESS_ADDI_INSN, "t,r,j", dest, dest, BFD_RELOC_LO16);
7801 add_got_offset_hilo (int dest, expressionS *local, int tmp)
7804 int hold_mips_optimize;
7806 global.X_op = O_constant;
7807 global.X_op_symbol = NULL;
7808 global.X_add_symbol = NULL;
7809 global.X_add_number = local->X_add_number;
7811 relax_start (local->X_add_symbol);
7812 load_register (tmp, &global, HAVE_64BIT_ADDRESSES);
7814 /* Set mips_optimize around the lui instruction to avoid
7815 inserting an unnecessary nop after the lw. */
7816 hold_mips_optimize = mips_optimize;
7818 macro_build_lui (&global, tmp);
7819 mips_optimize = hold_mips_optimize;
7820 macro_build (local, ADDRESS_ADDI_INSN, "t,r,j", tmp, tmp, BFD_RELOC_LO16);
7823 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", dest, dest, tmp);
7826 /* Emit a sequence of instructions to emulate a branch likely operation.
7827 BR is an ordinary branch corresponding to one to be emulated. BRNEG
7828 is its complementing branch with the original condition negated.
7829 CALL is set if the original branch specified the link operation.
7830 EP, FMT, SREG and TREG specify the usual macro_build() parameters.
7832 Code like this is produced in the noreorder mode:
7837 delay slot (executed only if branch taken)
7845 delay slot (executed only if branch taken)
7848 In the reorder mode the delay slot would be filled with a nop anyway,
7849 so code produced is simply:
7854 This function is used when producing code for the microMIPS ASE that
7855 does not implement branch likely instructions in hardware. */
7858 macro_build_branch_likely (const char *br, const char *brneg,
7859 int call, expressionS *ep, const char *fmt,
7860 unsigned int sreg, unsigned int treg)
7862 int noreorder = mips_opts.noreorder;
7865 gas_assert (mips_opts.micromips);
7869 micromips_label_expr (&expr1);
7870 macro_build (&expr1, brneg, fmt, sreg, treg);
7871 macro_build (NULL, "nop", "");
7872 macro_build (ep, call ? "bal" : "b", "p");
7874 /* Set to true so that append_insn adds a label. */
7875 emit_branch_likely_macro = TRUE;
7879 macro_build (ep, br, fmt, sreg, treg);
7880 macro_build (NULL, "nop", "");
7885 /* Emit a coprocessor branch-likely macro specified by TYPE, using CC as
7886 the condition code tested. EP specifies the branch target. */
7889 macro_build_branch_ccl (int type, expressionS *ep, unsigned int cc)
7916 macro_build_branch_likely (br, brneg, call, ep, "N,p", cc, ZERO);
7919 /* Emit a two-argument branch macro specified by TYPE, using SREG as
7920 the register tested. EP specifies the branch target. */
7923 macro_build_branch_rs (int type, expressionS *ep, unsigned int sreg)
7925 const char *brneg = NULL;
7935 br = mips_opts.micromips ? "bgez" : "bgezl";
7939 gas_assert (mips_opts.micromips);
7940 br = mips_opts.insn32 ? "bgezal" : "bgezals";
7948 br = mips_opts.micromips ? "bgtz" : "bgtzl";
7955 br = mips_opts.micromips ? "blez" : "blezl";
7962 br = mips_opts.micromips ? "bltz" : "bltzl";
7966 gas_assert (mips_opts.micromips);
7967 br = mips_opts.insn32 ? "bltzal" : "bltzals";
7974 if (mips_opts.micromips && brneg)
7975 macro_build_branch_likely (br, brneg, call, ep, "s,p", sreg, ZERO);
7977 macro_build (ep, br, "s,p", sreg);
7980 /* Emit a three-argument branch macro specified by TYPE, using SREG and
7981 TREG as the registers tested. EP specifies the branch target. */
7984 macro_build_branch_rsrt (int type, expressionS *ep,
7985 unsigned int sreg, unsigned int treg)
7987 const char *brneg = NULL;
7999 br = mips_opts.micromips ? "beq" : "beql";
8008 br = mips_opts.micromips ? "bne" : "bnel";
8014 if (mips_opts.micromips && brneg)
8015 macro_build_branch_likely (br, brneg, call, ep, "s,t,p", sreg, treg);
8017 macro_build (ep, br, "s,t,p", sreg, treg);
8020 /* Return the high part that should be loaded in order to make the low
8021 part of VALUE accessible using an offset of OFFBITS bits. */
8024 offset_high_part (offsetT value, unsigned int offbits)
8031 bias = 1 << (offbits - 1);
8032 low_mask = bias * 2 - 1;
8033 return (value + bias) & ~low_mask;
8036 /* Return true if the value stored in offset_expr and offset_reloc
8037 fits into a signed offset of OFFBITS bits. RANGE is the maximum
8038 amount that the caller wants to add without inducing overflow
8039 and ALIGN is the known alignment of the value in bytes. */
8042 small_offset_p (unsigned int range, unsigned int align, unsigned int offbits)
8046 /* Accept any relocation operator if overflow isn't a concern. */
8047 if (range < align && *offset_reloc != BFD_RELOC_UNUSED)
8050 /* These relocations are guaranteed not to overflow in correct links. */
8051 if (*offset_reloc == BFD_RELOC_MIPS_LITERAL
8052 || gprel16_reloc_p (*offset_reloc))
8055 if (offset_expr.X_op == O_constant
8056 && offset_high_part (offset_expr.X_add_number, offbits) == 0
8057 && offset_high_part (offset_expr.X_add_number + range, offbits) == 0)
8064 * This routine implements the seemingly endless macro or synthesized
8065 * instructions and addressing modes in the mips assembly language. Many
8066 * of these macros are simple and are similar to each other. These could
8067 * probably be handled by some kind of table or grammar approach instead of
8068 * this verbose method. Others are not simple macros but are more like
8069 * optimizing code generation.
8070 * One interesting optimization is when several store macros appear
8071 * consecutively that would load AT with the upper half of the same address.
8072 * The ensuing load upper instructions are ommited. This implies some kind
8073 * of global optimization. We currently only optimize within a single macro.
8074 * For many of the load and store macros if the address is specified as a
8075 * constant expression in the first 64k of memory (ie ld $2,0x4000c) we
8076 * first load register 'at' with zero and use it as the base register. The
8077 * mips assembler simply uses register $zero. Just one tiny optimization
8081 macro (struct mips_cl_insn *ip, char *str)
8083 unsigned int treg, sreg, dreg, breg;
8084 unsigned int tempreg;
8087 expressionS label_expr;
8102 bfd_boolean large_offset;
8104 int hold_mips_optimize;
8107 gas_assert (! mips_opts.mips16);
8109 treg = EXTRACT_OPERAND (mips_opts.micromips, RT, *ip);
8110 dreg = EXTRACT_OPERAND (mips_opts.micromips, RD, *ip);
8111 sreg = breg = EXTRACT_OPERAND (mips_opts.micromips, RS, *ip);
8112 mask = ip->insn_mo->mask;
8114 label_expr.X_op = O_constant;
8115 label_expr.X_op_symbol = NULL;
8116 label_expr.X_add_symbol = NULL;
8117 label_expr.X_add_number = 0;
8119 expr1.X_op = O_constant;
8120 expr1.X_op_symbol = NULL;
8121 expr1.X_add_symbol = NULL;
8122 expr1.X_add_number = 1;
8138 if (mips_opts.micromips)
8139 micromips_label_expr (&label_expr);
8141 label_expr.X_add_number = 8;
8142 macro_build (&label_expr, "bgez", "s,p", sreg);
8144 macro_build (NULL, "nop", "");
8146 move_register (dreg, sreg);
8147 macro_build (NULL, dbl ? "dsub" : "sub", "d,v,t", dreg, 0, sreg);
8148 if (mips_opts.micromips)
8149 micromips_add_label ();
8166 if (!mips_opts.micromips)
8168 if (imm_expr.X_op == O_constant
8169 && imm_expr.X_add_number >= -0x200
8170 && imm_expr.X_add_number < 0x200)
8172 macro_build (NULL, s, "t,r,.", treg, sreg, imm_expr.X_add_number);
8181 if (imm_expr.X_op == O_constant
8182 && imm_expr.X_add_number >= -0x8000
8183 && imm_expr.X_add_number < 0x8000)
8185 macro_build (&imm_expr, s, "t,r,j", treg, sreg, BFD_RELOC_LO16);
8190 load_register (AT, &imm_expr, dbl);
8191 macro_build (NULL, s2, "d,v,t", treg, sreg, AT);
8210 if (imm_expr.X_op == O_constant
8211 && imm_expr.X_add_number >= 0
8212 && imm_expr.X_add_number < 0x10000)
8214 if (mask != M_NOR_I)
8215 macro_build (&imm_expr, s, "t,r,i", treg, sreg, BFD_RELOC_LO16);
8218 macro_build (&imm_expr, "ori", "t,r,i",
8219 treg, sreg, BFD_RELOC_LO16);
8220 macro_build (NULL, "nor", "d,v,t", treg, treg, 0);
8226 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
8227 macro_build (NULL, s2, "d,v,t", treg, sreg, AT);
8231 switch (imm_expr.X_add_number)
8234 macro_build (NULL, "nop", "");
8237 macro_build (NULL, "packrl.ph", "d,s,t", treg, treg, sreg);
8241 macro_build (NULL, "balign", "t,s,2", treg, sreg,
8242 (int) imm_expr.X_add_number);
8245 as_bad (_("BALIGN immediate not 0, 1, 2 or 3 (%lu)"),
8246 (unsigned long) imm_expr.X_add_number);
8255 gas_assert (mips_opts.micromips);
8256 macro_build_branch_ccl (mask, &offset_expr,
8257 EXTRACT_OPERAND (1, BCC, *ip));
8264 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
8270 load_register (treg, &imm_expr, HAVE_64BIT_GPRS);
8275 macro_build_branch_rsrt (mask, &offset_expr, sreg, treg);
8282 macro_build_branch_rs (likely ? M_BGEZL : M_BGEZ, &offset_expr, sreg);
8284 macro_build_branch_rs (likely ? M_BLEZL : M_BLEZ, &offset_expr, treg);
8288 macro_build (NULL, "slt", "d,v,t", AT, sreg, treg);
8289 macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ,
8290 &offset_expr, AT, ZERO);
8300 macro_build_branch_rs (mask, &offset_expr, sreg);
8306 /* Check for > max integer. */
8307 if (imm_expr.X_op == O_constant && imm_expr.X_add_number >= GPR_SMAX)
8310 /* Result is always false. */
8312 macro_build (NULL, "nop", "");
8314 macro_build_branch_rsrt (M_BNEL, &offset_expr, ZERO, ZERO);
8317 if (imm_expr.X_op != O_constant)
8318 as_bad (_("Unsupported large constant"));
8319 ++imm_expr.X_add_number;
8323 if (mask == M_BGEL_I)
8325 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
8327 macro_build_branch_rs (likely ? M_BGEZL : M_BGEZ,
8328 &offset_expr, sreg);
8331 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
8333 macro_build_branch_rs (likely ? M_BGTZL : M_BGTZ,
8334 &offset_expr, sreg);
8337 if (imm_expr.X_op == O_constant && imm_expr.X_add_number <= GPR_SMIN)
8340 /* result is always true */
8341 as_warn (_("Branch %s is always true"), ip->insn_mo->name);
8342 macro_build (&offset_expr, "b", "p");
8347 macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ,
8348 &offset_expr, AT, ZERO);
8357 macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ,
8358 &offset_expr, ZERO, treg);
8362 macro_build (NULL, "sltu", "d,v,t", AT, sreg, treg);
8363 macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ,
8364 &offset_expr, AT, ZERO);
8373 && imm_expr.X_op == O_constant
8374 && imm_expr.X_add_number == -1))
8376 if (imm_expr.X_op != O_constant)
8377 as_bad (_("Unsupported large constant"));
8378 ++imm_expr.X_add_number;
8382 if (mask == M_BGEUL_I)
8384 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
8386 else if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
8387 macro_build_branch_rsrt (likely ? M_BNEL : M_BNE,
8388 &offset_expr, sreg, ZERO);
8393 macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ,
8394 &offset_expr, AT, ZERO);
8402 macro_build_branch_rs (likely ? M_BGTZL : M_BGTZ, &offset_expr, sreg);
8404 macro_build_branch_rs (likely ? M_BLTZL : M_BLTZ, &offset_expr, treg);
8408 macro_build (NULL, "slt", "d,v,t", AT, treg, sreg);
8409 macro_build_branch_rsrt (likely ? M_BNEL : M_BNE,
8410 &offset_expr, AT, ZERO);
8418 macro_build_branch_rsrt (likely ? M_BNEL : M_BNE,
8419 &offset_expr, sreg, ZERO);
8425 macro_build (NULL, "sltu", "d,v,t", AT, treg, sreg);
8426 macro_build_branch_rsrt (likely ? M_BNEL : M_BNE,
8427 &offset_expr, AT, ZERO);
8435 macro_build_branch_rs (likely ? M_BLEZL : M_BLEZ, &offset_expr, sreg);
8437 macro_build_branch_rs (likely ? M_BGEZL : M_BGEZ, &offset_expr, treg);
8441 macro_build (NULL, "slt", "d,v,t", AT, treg, sreg);
8442 macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ,
8443 &offset_expr, AT, ZERO);
8450 if (imm_expr.X_op == O_constant && imm_expr.X_add_number >= GPR_SMAX)
8452 if (imm_expr.X_op != O_constant)
8453 as_bad (_("Unsupported large constant"));
8454 ++imm_expr.X_add_number;
8458 if (mask == M_BLTL_I)
8460 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
8461 macro_build_branch_rs (likely ? M_BLTZL : M_BLTZ, &offset_expr, sreg);
8462 else if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
8463 macro_build_branch_rs (likely ? M_BLEZL : M_BLEZ, &offset_expr, sreg);
8468 macro_build_branch_rsrt (likely ? M_BNEL : M_BNE,
8469 &offset_expr, AT, ZERO);
8477 macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ,
8478 &offset_expr, sreg, ZERO);
8484 macro_build (NULL, "sltu", "d,v,t", AT, treg, sreg);
8485 macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ,
8486 &offset_expr, AT, ZERO);
8495 && imm_expr.X_op == O_constant
8496 && imm_expr.X_add_number == -1))
8498 if (imm_expr.X_op != O_constant)
8499 as_bad (_("Unsupported large constant"));
8500 ++imm_expr.X_add_number;
8504 if (mask == M_BLTUL_I)
8506 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
8508 else if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
8509 macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ,
8510 &offset_expr, sreg, ZERO);
8515 macro_build_branch_rsrt (likely ? M_BNEL : M_BNE,
8516 &offset_expr, AT, ZERO);
8524 macro_build_branch_rs (likely ? M_BLTZL : M_BLTZ, &offset_expr, sreg);
8526 macro_build_branch_rs (likely ? M_BGTZL : M_BGTZ, &offset_expr, treg);
8530 macro_build (NULL, "slt", "d,v,t", AT, sreg, treg);
8531 macro_build_branch_rsrt (likely ? M_BNEL : M_BNE,
8532 &offset_expr, AT, ZERO);
8542 macro_build_branch_rsrt (likely ? M_BNEL : M_BNE,
8543 &offset_expr, ZERO, treg);
8547 macro_build (NULL, "sltu", "d,v,t", AT, sreg, treg);
8548 macro_build_branch_rsrt (likely ? M_BNEL : M_BNE,
8549 &offset_expr, AT, ZERO);
8555 /* Use unsigned arithmetic. */
8559 if (imm_expr.X_op != O_constant || imm2_expr.X_op != O_constant)
8561 as_bad (_("Unsupported large constant"));
8566 pos = imm_expr.X_add_number;
8567 size = imm2_expr.X_add_number;
8572 report_bad_range (ip, 3, pos, 0, 63, FALSE);
8575 if (size == 0 || size > 64 || (pos + size - 1) > 63)
8577 report_bad_field (pos, size);
8581 if (size <= 32 && pos < 32)
8586 else if (size <= 32)
8596 macro_build ((expressionS *) NULL, s, fmt, treg, sreg, (int) pos,
8603 /* Use unsigned arithmetic. */
8607 if (imm_expr.X_op != O_constant || imm2_expr.X_op != O_constant)
8609 as_bad (_("Unsupported large constant"));
8614 pos = imm_expr.X_add_number;
8615 size = imm2_expr.X_add_number;
8620 report_bad_range (ip, 3, pos, 0, 63, FALSE);
8623 if (size == 0 || size > 64 || (pos + size - 1) > 63)
8625 report_bad_field (pos, size);
8629 if (pos < 32 && (pos + size - 1) < 32)
8644 macro_build ((expressionS *) NULL, s, fmt, treg, sreg, (int) pos,
8645 (int) (pos + size - 1));
8661 as_warn (_("Divide by zero."));
8663 macro_build (NULL, "teq", TRAP_FMT, ZERO, ZERO, 7);
8665 macro_build (NULL, "break", BRK_FMT, 7);
8672 macro_build (NULL, "teq", TRAP_FMT, treg, ZERO, 7);
8673 macro_build (NULL, dbl ? "ddiv" : "div", "z,s,t", sreg, treg);
8677 if (mips_opts.micromips)
8678 micromips_label_expr (&label_expr);
8680 label_expr.X_add_number = 8;
8681 macro_build (&label_expr, "bne", "s,t,p", treg, ZERO);
8682 macro_build (NULL, dbl ? "ddiv" : "div", "z,s,t", sreg, treg);
8683 macro_build (NULL, "break", BRK_FMT, 7);
8684 if (mips_opts.micromips)
8685 micromips_add_label ();
8687 expr1.X_add_number = -1;
8689 load_register (AT, &expr1, dbl);
8690 if (mips_opts.micromips)
8691 micromips_label_expr (&label_expr);
8693 label_expr.X_add_number = mips_trap ? (dbl ? 12 : 8) : (dbl ? 20 : 16);
8694 macro_build (&label_expr, "bne", "s,t,p", treg, AT);
8697 expr1.X_add_number = 1;
8698 load_register (AT, &expr1, dbl);
8699 macro_build (NULL, "dsll32", SHFT_FMT, AT, AT, 31);
8703 expr1.X_add_number = 0x80000000;
8704 macro_build (&expr1, "lui", LUI_FMT, AT, BFD_RELOC_HI16);
8708 macro_build (NULL, "teq", TRAP_FMT, sreg, AT, 6);
8709 /* We want to close the noreorder block as soon as possible, so
8710 that later insns are available for delay slot filling. */
8715 if (mips_opts.micromips)
8716 micromips_label_expr (&label_expr);
8718 label_expr.X_add_number = 8;
8719 macro_build (&label_expr, "bne", "s,t,p", sreg, AT);
8720 macro_build (NULL, "nop", "");
8722 /* We want to close the noreorder block as soon as possible, so
8723 that later insns are available for delay slot filling. */
8726 macro_build (NULL, "break", BRK_FMT, 6);
8728 if (mips_opts.micromips)
8729 micromips_add_label ();
8730 macro_build (NULL, s, MFHL_FMT, dreg);
8769 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
8771 as_warn (_("Divide by zero."));
8773 macro_build (NULL, "teq", TRAP_FMT, ZERO, ZERO, 7);
8775 macro_build (NULL, "break", BRK_FMT, 7);
8778 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
8780 if (strcmp (s2, "mflo") == 0)
8781 move_register (dreg, sreg);
8783 move_register (dreg, ZERO);
8786 if (imm_expr.X_op == O_constant
8787 && imm_expr.X_add_number == -1
8788 && s[strlen (s) - 1] != 'u')
8790 if (strcmp (s2, "mflo") == 0)
8792 macro_build (NULL, dbl ? "dneg" : "neg", "d,w", dreg, sreg);
8795 move_register (dreg, ZERO);
8800 load_register (AT, &imm_expr, dbl);
8801 macro_build (NULL, s, "z,s,t", sreg, AT);
8802 macro_build (NULL, s2, MFHL_FMT, dreg);
8824 macro_build (NULL, "teq", TRAP_FMT, treg, ZERO, 7);
8825 macro_build (NULL, s, "z,s,t", sreg, treg);
8826 /* We want to close the noreorder block as soon as possible, so
8827 that later insns are available for delay slot filling. */
8832 if (mips_opts.micromips)
8833 micromips_label_expr (&label_expr);
8835 label_expr.X_add_number = 8;
8836 macro_build (&label_expr, "bne", "s,t,p", treg, ZERO);
8837 macro_build (NULL, s, "z,s,t", sreg, treg);
8839 /* We want to close the noreorder block as soon as possible, so
8840 that later insns are available for delay slot filling. */
8842 macro_build (NULL, "break", BRK_FMT, 7);
8843 if (mips_opts.micromips)
8844 micromips_add_label ();
8846 macro_build (NULL, s2, MFHL_FMT, dreg);
8858 /* Load the address of a symbol into a register. If breg is not
8859 zero, we then add a base register to it. */
8861 if (dbl && HAVE_32BIT_GPRS)
8862 as_warn (_("dla used to load 32-bit register"));
8864 if (!dbl && HAVE_64BIT_OBJECTS)
8865 as_warn (_("la used to load 64-bit address"));
8867 if (small_offset_p (0, align, 16))
8869 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j", treg, breg,
8870 -1, offset_reloc[0], offset_reloc[1], offset_reloc[2]);
8874 if (mips_opts.at && (treg == breg))
8884 if (offset_expr.X_op != O_symbol
8885 && offset_expr.X_op != O_constant)
8887 as_bad (_("Expression too complex"));
8888 offset_expr.X_op = O_constant;
8891 if (offset_expr.X_op == O_constant)
8892 load_register (tempreg, &offset_expr, HAVE_64BIT_ADDRESSES);
8893 else if (mips_pic == NO_PIC)
8895 /* If this is a reference to a GP relative symbol, we want
8896 addiu $tempreg,$gp,<sym> (BFD_RELOC_GPREL16)
8898 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
8899 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
8900 If we have a constant, we need two instructions anyhow,
8901 so we may as well always use the latter form.
8903 With 64bit address space and a usable $at we want
8904 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
8905 lui $at,<sym> (BFD_RELOC_HI16_S)
8906 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
8907 daddiu $at,<sym> (BFD_RELOC_LO16)
8909 daddu $tempreg,$tempreg,$at
8911 If $at is already in use, we use a path which is suboptimal
8912 on superscalar processors.
8913 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
8914 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
8916 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
8918 daddiu $tempreg,<sym> (BFD_RELOC_LO16)
8920 For GP relative symbols in 64bit address space we can use
8921 the same sequence as in 32bit address space. */
8922 if (HAVE_64BIT_SYMBOLS)
8924 if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
8925 && !nopic_need_relax (offset_expr.X_add_symbol, 1))
8927 relax_start (offset_expr.X_add_symbol);
8928 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
8929 tempreg, mips_gp_register, BFD_RELOC_GPREL16);
8933 if (used_at == 0 && mips_opts.at)
8935 macro_build (&offset_expr, "lui", LUI_FMT,
8936 tempreg, BFD_RELOC_MIPS_HIGHEST);
8937 macro_build (&offset_expr, "lui", LUI_FMT,
8938 AT, BFD_RELOC_HI16_S);
8939 macro_build (&offset_expr, "daddiu", "t,r,j",
8940 tempreg, tempreg, BFD_RELOC_MIPS_HIGHER);
8941 macro_build (&offset_expr, "daddiu", "t,r,j",
8942 AT, AT, BFD_RELOC_LO16);
8943 macro_build (NULL, "dsll32", SHFT_FMT, tempreg, tempreg, 0);
8944 macro_build (NULL, "daddu", "d,v,t", tempreg, tempreg, AT);
8949 macro_build (&offset_expr, "lui", LUI_FMT,
8950 tempreg, BFD_RELOC_MIPS_HIGHEST);
8951 macro_build (&offset_expr, "daddiu", "t,r,j",
8952 tempreg, tempreg, BFD_RELOC_MIPS_HIGHER);
8953 macro_build (NULL, "dsll", SHFT_FMT, tempreg, tempreg, 16);
8954 macro_build (&offset_expr, "daddiu", "t,r,j",
8955 tempreg, tempreg, BFD_RELOC_HI16_S);
8956 macro_build (NULL, "dsll", SHFT_FMT, tempreg, tempreg, 16);
8957 macro_build (&offset_expr, "daddiu", "t,r,j",
8958 tempreg, tempreg, BFD_RELOC_LO16);
8961 if (mips_relax.sequence)
8966 if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
8967 && !nopic_need_relax (offset_expr.X_add_symbol, 1))
8969 relax_start (offset_expr.X_add_symbol);
8970 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
8971 tempreg, mips_gp_register, BFD_RELOC_GPREL16);
8974 if (!IS_SEXT_32BIT_NUM (offset_expr.X_add_number))
8975 as_bad (_("Offset too large"));
8976 macro_build_lui (&offset_expr, tempreg);
8977 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
8978 tempreg, tempreg, BFD_RELOC_LO16);
8979 if (mips_relax.sequence)
8983 else if (!mips_big_got && !HAVE_NEWABI)
8985 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT16;
8987 /* If this is a reference to an external symbol, and there
8988 is no constant, we want
8989 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
8990 or for lca or if tempreg is PIC_CALL_REG
8991 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
8992 For a local symbol, we want
8993 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
8995 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
8997 If we have a small constant, and this is a reference to
8998 an external symbol, we want
8999 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
9001 addiu $tempreg,$tempreg,<constant>
9002 For a local symbol, we want the same instruction
9003 sequence, but we output a BFD_RELOC_LO16 reloc on the
9006 If we have a large constant, and this is a reference to
9007 an external symbol, we want
9008 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
9009 lui $at,<hiconstant>
9010 addiu $at,$at,<loconstant>
9011 addu $tempreg,$tempreg,$at
9012 For a local symbol, we want the same instruction
9013 sequence, but we output a BFD_RELOC_LO16 reloc on the
9017 if (offset_expr.X_add_number == 0)
9019 if (mips_pic == SVR4_PIC
9021 && (call || tempreg == PIC_CALL_REG))
9022 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL16;
9024 relax_start (offset_expr.X_add_symbol);
9025 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
9026 lw_reloc_type, mips_gp_register);
9029 /* We're going to put in an addu instruction using
9030 tempreg, so we may as well insert the nop right
9035 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
9036 tempreg, BFD_RELOC_MIPS_GOT16, mips_gp_register);
9038 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
9039 tempreg, tempreg, BFD_RELOC_LO16);
9041 /* FIXME: If breg == 0, and the next instruction uses
9042 $tempreg, then if this variant case is used an extra
9043 nop will be generated. */
9045 else if (offset_expr.X_add_number >= -0x8000
9046 && offset_expr.X_add_number < 0x8000)
9048 load_got_offset (tempreg, &offset_expr);
9050 add_got_offset (tempreg, &offset_expr);
9054 expr1.X_add_number = offset_expr.X_add_number;
9055 offset_expr.X_add_number =
9056 SEXT_16BIT (offset_expr.X_add_number);
9057 load_got_offset (tempreg, &offset_expr);
9058 offset_expr.X_add_number = expr1.X_add_number;
9059 /* If we are going to add in a base register, and the
9060 target register and the base register are the same,
9061 then we are using AT as a temporary register. Since
9062 we want to load the constant into AT, we add our
9063 current AT (from the global offset table) and the
9064 register into the register now, and pretend we were
9065 not using a base register. */
9069 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
9074 add_got_offset_hilo (tempreg, &offset_expr, AT);
9078 else if (!mips_big_got && HAVE_NEWABI)
9080 int add_breg_early = 0;
9082 /* If this is a reference to an external, and there is no
9083 constant, or local symbol (*), with or without a
9085 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
9086 or for lca or if tempreg is PIC_CALL_REG
9087 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
9089 If we have a small constant, and this is a reference to
9090 an external symbol, we want
9091 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
9092 addiu $tempreg,$tempreg,<constant>
9094 If we have a large constant, and this is a reference to
9095 an external symbol, we want
9096 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
9097 lui $at,<hiconstant>
9098 addiu $at,$at,<loconstant>
9099 addu $tempreg,$tempreg,$at
9101 (*) Other assemblers seem to prefer GOT_PAGE/GOT_OFST for
9102 local symbols, even though it introduces an additional
9105 if (offset_expr.X_add_number)
9107 expr1.X_add_number = offset_expr.X_add_number;
9108 offset_expr.X_add_number = 0;
9110 relax_start (offset_expr.X_add_symbol);
9111 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
9112 BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
9114 if (expr1.X_add_number >= -0x8000
9115 && expr1.X_add_number < 0x8000)
9117 macro_build (&expr1, ADDRESS_ADDI_INSN, "t,r,j",
9118 tempreg, tempreg, BFD_RELOC_LO16);
9120 else if (IS_SEXT_32BIT_NUM (expr1.X_add_number + 0x8000))
9122 /* If we are going to add in a base register, and the
9123 target register and the base register are the same,
9124 then we are using AT as a temporary register. Since
9125 we want to load the constant into AT, we add our
9126 current AT (from the global offset table) and the
9127 register into the register now, and pretend we were
9128 not using a base register. */
9133 gas_assert (tempreg == AT);
9134 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
9140 load_register (AT, &expr1, HAVE_64BIT_ADDRESSES);
9141 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
9147 as_bad (_("PIC code offset overflow (max 32 signed bits)"));
9150 offset_expr.X_add_number = expr1.X_add_number;
9152 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
9153 BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
9156 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
9157 treg, tempreg, breg);
9163 else if (breg == 0 && (call || tempreg == PIC_CALL_REG))
9165 relax_start (offset_expr.X_add_symbol);
9166 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
9167 BFD_RELOC_MIPS_CALL16, mips_gp_register);
9169 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
9170 BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
9175 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
9176 BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
9179 else if (mips_big_got && !HAVE_NEWABI)
9182 int lui_reloc_type = (int) BFD_RELOC_MIPS_GOT_HI16;
9183 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT_LO16;
9184 int local_reloc_type = (int) BFD_RELOC_MIPS_GOT16;
9186 /* This is the large GOT case. If this is a reference to an
9187 external symbol, and there is no constant, we want
9188 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
9189 addu $tempreg,$tempreg,$gp
9190 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
9191 or for lca or if tempreg is PIC_CALL_REG
9192 lui $tempreg,<sym> (BFD_RELOC_MIPS_CALL_HI16)
9193 addu $tempreg,$tempreg,$gp
9194 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_CALL_LO16)
9195 For a local symbol, we want
9196 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
9198 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
9200 If we have a small constant, and this is a reference to
9201 an external symbol, we want
9202 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
9203 addu $tempreg,$tempreg,$gp
9204 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
9206 addiu $tempreg,$tempreg,<constant>
9207 For a local symbol, we want
9208 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
9210 addiu $tempreg,$tempreg,<constant> (BFD_RELOC_LO16)
9212 If we have a large constant, and this is a reference to
9213 an external symbol, we want
9214 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
9215 addu $tempreg,$tempreg,$gp
9216 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
9217 lui $at,<hiconstant>
9218 addiu $at,$at,<loconstant>
9219 addu $tempreg,$tempreg,$at
9220 For a local symbol, we want
9221 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
9222 lui $at,<hiconstant>
9223 addiu $at,$at,<loconstant> (BFD_RELOC_LO16)
9224 addu $tempreg,$tempreg,$at
9227 expr1.X_add_number = offset_expr.X_add_number;
9228 offset_expr.X_add_number = 0;
9229 relax_start (offset_expr.X_add_symbol);
9230 gpdelay = reg_needs_delay (mips_gp_register);
9231 if (expr1.X_add_number == 0 && breg == 0
9232 && (call || tempreg == PIC_CALL_REG))
9234 lui_reloc_type = (int) BFD_RELOC_MIPS_CALL_HI16;
9235 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL_LO16;
9237 macro_build (&offset_expr, "lui", LUI_FMT, tempreg, lui_reloc_type);
9238 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
9239 tempreg, tempreg, mips_gp_register);
9240 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
9241 tempreg, lw_reloc_type, tempreg);
9242 if (expr1.X_add_number == 0)
9246 /* We're going to put in an addu instruction using
9247 tempreg, so we may as well insert the nop right
9252 else if (expr1.X_add_number >= -0x8000
9253 && expr1.X_add_number < 0x8000)
9256 macro_build (&expr1, ADDRESS_ADDI_INSN, "t,r,j",
9257 tempreg, tempreg, BFD_RELOC_LO16);
9261 /* If we are going to add in a base register, and the
9262 target register and the base register are the same,
9263 then we are using AT as a temporary register. Since
9264 we want to load the constant into AT, we add our
9265 current AT (from the global offset table) and the
9266 register into the register now, and pretend we were
9267 not using a base register. */
9272 gas_assert (tempreg == AT);
9274 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
9279 load_register (AT, &expr1, HAVE_64BIT_ADDRESSES);
9280 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", dreg, dreg, AT);
9284 offset_expr.X_add_number = SEXT_16BIT (expr1.X_add_number);
9289 /* This is needed because this instruction uses $gp, but
9290 the first instruction on the main stream does not. */
9291 macro_build (NULL, "nop", "");
9294 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
9295 local_reloc_type, mips_gp_register);
9296 if (expr1.X_add_number >= -0x8000
9297 && expr1.X_add_number < 0x8000)
9300 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
9301 tempreg, tempreg, BFD_RELOC_LO16);
9302 /* FIXME: If add_number is 0, and there was no base
9303 register, the external symbol case ended with a load,
9304 so if the symbol turns out to not be external, and
9305 the next instruction uses tempreg, an unnecessary nop
9306 will be inserted. */
9312 /* We must add in the base register now, as in the
9313 external symbol case. */
9314 gas_assert (tempreg == AT);
9316 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
9319 /* We set breg to 0 because we have arranged to add
9320 it in in both cases. */
9324 macro_build_lui (&expr1, AT);
9325 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
9326 AT, AT, BFD_RELOC_LO16);
9327 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
9328 tempreg, tempreg, AT);
9333 else if (mips_big_got && HAVE_NEWABI)
9335 int lui_reloc_type = (int) BFD_RELOC_MIPS_GOT_HI16;
9336 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT_LO16;
9337 int add_breg_early = 0;
9339 /* This is the large GOT case. If this is a reference to an
9340 external symbol, and there is no constant, we want
9341 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
9342 add $tempreg,$tempreg,$gp
9343 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
9344 or for lca or if tempreg is PIC_CALL_REG
9345 lui $tempreg,<sym> (BFD_RELOC_MIPS_CALL_HI16)
9346 add $tempreg,$tempreg,$gp
9347 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_CALL_LO16)
9349 If we have a small constant, and this is a reference to
9350 an external symbol, we want
9351 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
9352 add $tempreg,$tempreg,$gp
9353 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
9354 addi $tempreg,$tempreg,<constant>
9356 If we have a large constant, and this is a reference to
9357 an external symbol, we want
9358 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
9359 addu $tempreg,$tempreg,$gp
9360 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
9361 lui $at,<hiconstant>
9362 addi $at,$at,<loconstant>
9363 add $tempreg,$tempreg,$at
9365 If we have NewABI, and we know it's a local symbol, we want
9366 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
9367 addiu $reg,$reg,<sym> (BFD_RELOC_MIPS_GOT_OFST)
9368 otherwise we have to resort to GOT_HI16/GOT_LO16. */
9370 relax_start (offset_expr.X_add_symbol);
9372 expr1.X_add_number = offset_expr.X_add_number;
9373 offset_expr.X_add_number = 0;
9375 if (expr1.X_add_number == 0 && breg == 0
9376 && (call || tempreg == PIC_CALL_REG))
9378 lui_reloc_type = (int) BFD_RELOC_MIPS_CALL_HI16;
9379 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL_LO16;
9381 macro_build (&offset_expr, "lui", LUI_FMT, tempreg, lui_reloc_type);
9382 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
9383 tempreg, tempreg, mips_gp_register);
9384 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
9385 tempreg, lw_reloc_type, tempreg);
9387 if (expr1.X_add_number == 0)
9389 else if (expr1.X_add_number >= -0x8000
9390 && expr1.X_add_number < 0x8000)
9392 macro_build (&expr1, ADDRESS_ADDI_INSN, "t,r,j",
9393 tempreg, tempreg, BFD_RELOC_LO16);
9395 else if (IS_SEXT_32BIT_NUM (expr1.X_add_number + 0x8000))
9397 /* If we are going to add in a base register, and the
9398 target register and the base register are the same,
9399 then we are using AT as a temporary register. Since
9400 we want to load the constant into AT, we add our
9401 current AT (from the global offset table) and the
9402 register into the register now, and pretend we were
9403 not using a base register. */
9408 gas_assert (tempreg == AT);
9409 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
9415 load_register (AT, &expr1, HAVE_64BIT_ADDRESSES);
9416 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", dreg, dreg, AT);
9421 as_bad (_("PIC code offset overflow (max 32 signed bits)"));
9424 offset_expr.X_add_number = expr1.X_add_number;
9425 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
9426 BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register);
9427 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j", tempreg,
9428 tempreg, BFD_RELOC_MIPS_GOT_OFST);
9431 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
9432 treg, tempreg, breg);
9442 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", treg, tempreg, breg);
9446 gas_assert (!mips_opts.micromips);
9447 macro_build (NULL, "c2", "C", (treg << 16) | 0x01);
9451 gas_assert (!mips_opts.micromips);
9452 macro_build (NULL, "c2", "C", 0x02);
9456 gas_assert (!mips_opts.micromips);
9457 macro_build (NULL, "c2", "C", (treg << 16) | 0x02);
9461 gas_assert (!mips_opts.micromips);
9462 macro_build (NULL, "c2", "C", 3);
9466 gas_assert (!mips_opts.micromips);
9467 macro_build (NULL, "c2", "C", (treg << 16) | 0x03);
9471 /* The j instruction may not be used in PIC code, since it
9472 requires an absolute address. We convert it to a b
9474 if (mips_pic == NO_PIC)
9475 macro_build (&offset_expr, "j", "a");
9477 macro_build (&offset_expr, "b", "p");
9480 /* The jal instructions must be handled as macros because when
9481 generating PIC code they expand to multi-instruction
9482 sequences. Normally they are simple instructions. */
9487 gas_assert (mips_opts.micromips);
9488 if (mips_opts.insn32)
9490 as_bad (_("Opcode not supported in the `insn32' mode `%s'"), str);
9500 if (mips_pic == NO_PIC)
9502 s = jals ? "jalrs" : "jalr";
9503 if (mips_opts.micromips
9504 && !mips_opts.insn32
9506 && !(history[0].insn_mo->pinfo2 & INSN2_BRANCH_DELAY_32BIT))
9507 macro_build (NULL, s, "mj", sreg);
9509 macro_build (NULL, s, JALR_FMT, dreg, sreg);
9513 int cprestore = (mips_pic == SVR4_PIC && !HAVE_NEWABI
9514 && mips_cprestore_offset >= 0);
9516 if (sreg != PIC_CALL_REG)
9517 as_warn (_("MIPS PIC call to register other than $25"));
9519 s = ((mips_opts.micromips
9520 && !mips_opts.insn32
9521 && (!mips_opts.noreorder || cprestore))
9522 ? "jalrs" : "jalr");
9523 if (mips_opts.micromips
9524 && !mips_opts.insn32
9526 && !(history[0].insn_mo->pinfo2 & INSN2_BRANCH_DELAY_32BIT))
9527 macro_build (NULL, s, "mj", sreg);
9529 macro_build (NULL, s, JALR_FMT, dreg, sreg);
9530 if (mips_pic == SVR4_PIC && !HAVE_NEWABI)
9532 if (mips_cprestore_offset < 0)
9533 as_warn (_("No .cprestore pseudo-op used in PIC code"));
9536 if (!mips_frame_reg_valid)
9538 as_warn (_("No .frame pseudo-op used in PIC code"));
9539 /* Quiet this warning. */
9540 mips_frame_reg_valid = 1;
9542 if (!mips_cprestore_valid)
9544 as_warn (_("No .cprestore pseudo-op used in PIC code"));
9545 /* Quiet this warning. */
9546 mips_cprestore_valid = 1;
9548 if (mips_opts.noreorder)
9549 macro_build (NULL, "nop", "");
9550 expr1.X_add_number = mips_cprestore_offset;
9551 macro_build_ldst_constoffset (&expr1, ADDRESS_LOAD_INSN,
9554 HAVE_64BIT_ADDRESSES);
9562 gas_assert (mips_opts.micromips);
9563 if (mips_opts.insn32)
9565 as_bad (_("Opcode not supported in the `insn32' mode `%s'"), str);
9571 if (mips_pic == NO_PIC)
9572 macro_build (&offset_expr, jals ? "jals" : "jal", "a");
9573 else if (mips_pic == SVR4_PIC)
9575 /* If this is a reference to an external symbol, and we are
9576 using a small GOT, we want
9577 lw $25,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
9581 lw $gp,cprestore($sp)
9582 The cprestore value is set using the .cprestore
9583 pseudo-op. If we are using a big GOT, we want
9584 lui $25,<sym> (BFD_RELOC_MIPS_CALL_HI16)
9586 lw $25,<sym>($25) (BFD_RELOC_MIPS_CALL_LO16)
9590 lw $gp,cprestore($sp)
9591 If the symbol is not external, we want
9592 lw $25,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
9594 addiu $25,$25,<sym> (BFD_RELOC_LO16)
9597 lw $gp,cprestore($sp)
9599 For NewABI, we use the same CALL16 or CALL_HI16/CALL_LO16
9600 sequences above, minus nops, unless the symbol is local,
9601 which enables us to use GOT_PAGE/GOT_OFST (big got) or
9607 relax_start (offset_expr.X_add_symbol);
9608 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
9609 PIC_CALL_REG, BFD_RELOC_MIPS_CALL16,
9612 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
9613 PIC_CALL_REG, BFD_RELOC_MIPS_GOT_DISP,
9619 relax_start (offset_expr.X_add_symbol);
9620 macro_build (&offset_expr, "lui", LUI_FMT, PIC_CALL_REG,
9621 BFD_RELOC_MIPS_CALL_HI16);
9622 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", PIC_CALL_REG,
9623 PIC_CALL_REG, mips_gp_register);
9624 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
9625 PIC_CALL_REG, BFD_RELOC_MIPS_CALL_LO16,
9628 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
9629 PIC_CALL_REG, BFD_RELOC_MIPS_GOT_PAGE,
9631 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
9632 PIC_CALL_REG, PIC_CALL_REG,
9633 BFD_RELOC_MIPS_GOT_OFST);
9637 macro_build_jalr (&offset_expr, 0);
9641 relax_start (offset_expr.X_add_symbol);
9644 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
9645 PIC_CALL_REG, BFD_RELOC_MIPS_CALL16,
9654 gpdelay = reg_needs_delay (mips_gp_register);
9655 macro_build (&offset_expr, "lui", LUI_FMT, PIC_CALL_REG,
9656 BFD_RELOC_MIPS_CALL_HI16);
9657 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", PIC_CALL_REG,
9658 PIC_CALL_REG, mips_gp_register);
9659 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
9660 PIC_CALL_REG, BFD_RELOC_MIPS_CALL_LO16,
9665 macro_build (NULL, "nop", "");
9667 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
9668 PIC_CALL_REG, BFD_RELOC_MIPS_GOT16,
9671 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
9672 PIC_CALL_REG, PIC_CALL_REG, BFD_RELOC_LO16);
9674 macro_build_jalr (&offset_expr, mips_cprestore_offset >= 0);
9676 if (mips_cprestore_offset < 0)
9677 as_warn (_("No .cprestore pseudo-op used in PIC code"));
9680 if (!mips_frame_reg_valid)
9682 as_warn (_("No .frame pseudo-op used in PIC code"));
9683 /* Quiet this warning. */
9684 mips_frame_reg_valid = 1;
9686 if (!mips_cprestore_valid)
9688 as_warn (_("No .cprestore pseudo-op used in PIC code"));
9689 /* Quiet this warning. */
9690 mips_cprestore_valid = 1;
9692 if (mips_opts.noreorder)
9693 macro_build (NULL, "nop", "");
9694 expr1.X_add_number = mips_cprestore_offset;
9695 macro_build_ldst_constoffset (&expr1, ADDRESS_LOAD_INSN,
9698 HAVE_64BIT_ADDRESSES);
9702 else if (mips_pic == VXWORKS_PIC)
9703 as_bad (_("Non-PIC jump used in PIC library"));
9781 treg = EXTRACT_OPERAND (mips_opts.micromips, 3BITPOS, *ip);
9787 treg = EXTRACT_OPERAND (mips_opts.micromips, 3BITPOS, *ip);
9812 gas_assert (!mips_opts.micromips);
9815 /* Itbl support may require additional care here. */
9821 /* Itbl support may require additional care here. */
9827 offbits = (mips_opts.micromips ? 12 : 16);
9828 /* Itbl support may require additional care here. */
9832 gas_assert (!mips_opts.micromips);
9835 /* Itbl support may require additional care here. */
9841 offbits = (mips_opts.micromips ? 12 : 16);
9846 offbits = (mips_opts.micromips ? 12 : 16);
9851 /* Itbl support may require additional care here. */
9857 offbits = (mips_opts.micromips ? 12 : 16);
9858 /* Itbl support may require additional care here. */
9864 /* Itbl support may require additional care here. */
9870 /* Itbl support may require additional care here. */
9876 offbits = (mips_opts.micromips ? 12 : 16);
9881 offbits = (mips_opts.micromips ? 12 : 16);
9886 offbits = (mips_opts.micromips ? 12 : 16);
9891 offbits = (mips_opts.micromips ? 12 : 16);
9896 offbits = (mips_opts.micromips ? 12 : 16);
9899 gas_assert (mips_opts.micromips);
9906 gas_assert (mips_opts.micromips);
9913 gas_assert (mips_opts.micromips);
9919 gas_assert (mips_opts.micromips);
9926 /* We don't want to use $0 as tempreg. */
9927 if (breg == treg + lp || treg + lp == ZERO)
9930 tempreg = treg + lp;
9946 gas_assert (!mips_opts.micromips);
9949 /* Itbl support may require additional care here. */
9955 /* Itbl support may require additional care here. */
9961 offbits = (mips_opts.micromips ? 12 : 16);
9962 /* Itbl support may require additional care here. */
9966 gas_assert (!mips_opts.micromips);
9969 /* Itbl support may require additional care here. */
9975 offbits = (mips_opts.micromips ? 12 : 16);
9980 offbits = (mips_opts.micromips ? 12 : 16);
9985 offbits = (mips_opts.micromips ? 12 : 16);
9990 offbits = (mips_opts.micromips ? 12 : 16);
9994 fmt = mips_opts.micromips ? "k,~(b)" : "k,o(b)";
9995 offbits = (mips_opts.micromips ? 12 : 16);
10004 fmt = !mips_opts.micromips ? "k,o(b)" : "k,~(b)";
10005 offbits = (mips_opts.micromips ? 12 : 16);
10016 /* Itbl support may require additional care here. */
10021 offbits = (mips_opts.micromips ? 12 : 16);
10022 /* Itbl support may require additional care here. */
10028 /* Itbl support may require additional care here. */
10032 gas_assert (!mips_opts.micromips);
10035 /* Itbl support may require additional care here. */
10041 offbits = (mips_opts.micromips ? 12 : 16);
10046 offbits = (mips_opts.micromips ? 12 : 16);
10049 gas_assert (mips_opts.micromips);
10055 gas_assert (mips_opts.micromips);
10061 gas_assert (mips_opts.micromips);
10067 gas_assert (mips_opts.micromips);
10075 if (small_offset_p (0, align, 16))
10077 /* The first case exists for M_LD_AB and M_SD_AB, which are
10078 macros for o32 but which should act like normal instructions
10081 macro_build (&offset_expr, s, fmt, treg, -1, offset_reloc[0],
10082 offset_reloc[1], offset_reloc[2], breg);
10083 else if (small_offset_p (0, align, offbits))
10086 macro_build (NULL, s, fmt, treg, breg);
10088 macro_build (NULL, s, fmt, treg,
10089 (int) offset_expr.X_add_number, breg);
10095 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
10096 tempreg, breg, -1, offset_reloc[0],
10097 offset_reloc[1], offset_reloc[2]);
10099 macro_build (NULL, s, fmt, treg, tempreg);
10101 macro_build (NULL, s, fmt, treg, 0, tempreg);
10109 if (offset_expr.X_op != O_constant
10110 && offset_expr.X_op != O_symbol)
10112 as_bad (_("Expression too complex"));
10113 offset_expr.X_op = O_constant;
10116 if (HAVE_32BIT_ADDRESSES
10117 && !IS_SEXT_32BIT_NUM (offset_expr.X_add_number))
10121 sprintf_vma (value, offset_expr.X_add_number);
10122 as_bad (_("Number (0x%s) larger than 32 bits"), value);
10125 /* A constant expression in PIC code can be handled just as it
10126 is in non PIC code. */
10127 if (offset_expr.X_op == O_constant)
10129 expr1.X_add_number = offset_high_part (offset_expr.X_add_number,
10130 offbits == 0 ? 16 : offbits);
10131 offset_expr.X_add_number -= expr1.X_add_number;
10133 load_register (tempreg, &expr1, HAVE_64BIT_ADDRESSES);
10135 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
10136 tempreg, tempreg, breg);
10139 if (offset_expr.X_add_number != 0)
10140 macro_build (&offset_expr, ADDRESS_ADDI_INSN,
10141 "t,r,j", tempreg, tempreg, BFD_RELOC_LO16);
10142 macro_build (NULL, s, fmt, treg, tempreg);
10144 else if (offbits == 16)
10145 macro_build (&offset_expr, s, fmt, treg, BFD_RELOC_LO16, tempreg);
10147 macro_build (NULL, s, fmt, treg,
10148 (int) offset_expr.X_add_number, tempreg);
10150 else if (offbits != 16)
10152 /* The offset field is too narrow to be used for a low-part
10153 relocation, so load the whole address into the auxillary
10155 load_address (tempreg, &offset_expr, &used_at);
10157 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
10158 tempreg, tempreg, breg);
10160 macro_build (NULL, s, fmt, treg, tempreg);
10162 macro_build (NULL, s, fmt, treg, 0, tempreg);
10164 else if (mips_pic == NO_PIC)
10166 /* If this is a reference to a GP relative symbol, and there
10167 is no base register, we want
10168 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
10169 Otherwise, if there is no base register, we want
10170 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
10171 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
10172 If we have a constant, we need two instructions anyhow,
10173 so we always use the latter form.
10175 If we have a base register, and this is a reference to a
10176 GP relative symbol, we want
10177 addu $tempreg,$breg,$gp
10178 <op> $treg,<sym>($tempreg) (BFD_RELOC_GPREL16)
10180 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
10181 addu $tempreg,$tempreg,$breg
10182 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
10183 With a constant we always use the latter case.
10185 With 64bit address space and no base register and $at usable,
10187 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
10188 lui $at,<sym> (BFD_RELOC_HI16_S)
10189 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
10192 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
10193 If we have a base register, we want
10194 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
10195 lui $at,<sym> (BFD_RELOC_HI16_S)
10196 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
10200 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
10202 Without $at we can't generate the optimal path for superscalar
10203 processors here since this would require two temporary registers.
10204 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
10205 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
10207 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
10209 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
10210 If we have a base register, we want
10211 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
10212 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
10214 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
10216 daddu $tempreg,$tempreg,$breg
10217 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
10219 For GP relative symbols in 64bit address space we can use
10220 the same sequence as in 32bit address space. */
10221 if (HAVE_64BIT_SYMBOLS)
10223 if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
10224 && !nopic_need_relax (offset_expr.X_add_symbol, 1))
10226 relax_start (offset_expr.X_add_symbol);
10229 macro_build (&offset_expr, s, fmt, treg,
10230 BFD_RELOC_GPREL16, mips_gp_register);
10234 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
10235 tempreg, breg, mips_gp_register);
10236 macro_build (&offset_expr, s, fmt, treg,
10237 BFD_RELOC_GPREL16, tempreg);
10242 if (used_at == 0 && mips_opts.at)
10244 macro_build (&offset_expr, "lui", LUI_FMT, tempreg,
10245 BFD_RELOC_MIPS_HIGHEST);
10246 macro_build (&offset_expr, "lui", LUI_FMT, AT,
10248 macro_build (&offset_expr, "daddiu", "t,r,j", tempreg,
10249 tempreg, BFD_RELOC_MIPS_HIGHER);
10251 macro_build (NULL, "daddu", "d,v,t", AT, AT, breg);
10252 macro_build (NULL, "dsll32", SHFT_FMT, tempreg, tempreg, 0);
10253 macro_build (NULL, "daddu", "d,v,t", tempreg, tempreg, AT);
10254 macro_build (&offset_expr, s, fmt, treg, BFD_RELOC_LO16,
10260 macro_build (&offset_expr, "lui", LUI_FMT, tempreg,
10261 BFD_RELOC_MIPS_HIGHEST);
10262 macro_build (&offset_expr, "daddiu", "t,r,j", tempreg,
10263 tempreg, BFD_RELOC_MIPS_HIGHER);
10264 macro_build (NULL, "dsll", SHFT_FMT, tempreg, tempreg, 16);
10265 macro_build (&offset_expr, "daddiu", "t,r,j", tempreg,
10266 tempreg, BFD_RELOC_HI16_S);
10267 macro_build (NULL, "dsll", SHFT_FMT, tempreg, tempreg, 16);
10269 macro_build (NULL, "daddu", "d,v,t",
10270 tempreg, tempreg, breg);
10271 macro_build (&offset_expr, s, fmt, treg,
10272 BFD_RELOC_LO16, tempreg);
10275 if (mips_relax.sequence)
10282 if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
10283 && !nopic_need_relax (offset_expr.X_add_symbol, 1))
10285 relax_start (offset_expr.X_add_symbol);
10286 macro_build (&offset_expr, s, fmt, treg, BFD_RELOC_GPREL16,
10290 macro_build_lui (&offset_expr, tempreg);
10291 macro_build (&offset_expr, s, fmt, treg,
10292 BFD_RELOC_LO16, tempreg);
10293 if (mips_relax.sequence)
10298 if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
10299 && !nopic_need_relax (offset_expr.X_add_symbol, 1))
10301 relax_start (offset_expr.X_add_symbol);
10302 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
10303 tempreg, breg, mips_gp_register);
10304 macro_build (&offset_expr, s, fmt, treg,
10305 BFD_RELOC_GPREL16, tempreg);
10308 macro_build_lui (&offset_expr, tempreg);
10309 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
10310 tempreg, tempreg, breg);
10311 macro_build (&offset_expr, s, fmt, treg,
10312 BFD_RELOC_LO16, tempreg);
10313 if (mips_relax.sequence)
10317 else if (!mips_big_got)
10319 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT16;
10321 /* If this is a reference to an external symbol, we want
10322 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
10324 <op> $treg,0($tempreg)
10326 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
10328 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
10329 <op> $treg,0($tempreg)
10331 For NewABI, we want
10332 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
10333 <op> $treg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_OFST)
10335 If there is a base register, we add it to $tempreg before
10336 the <op>. If there is a constant, we stick it in the
10337 <op> instruction. We don't handle constants larger than
10338 16 bits, because we have no way to load the upper 16 bits
10339 (actually, we could handle them for the subset of cases
10340 in which we are not using $at). */
10341 gas_assert (offset_expr.X_op == O_symbol);
10344 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
10345 BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register);
10347 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
10348 tempreg, tempreg, breg);
10349 macro_build (&offset_expr, s, fmt, treg,
10350 BFD_RELOC_MIPS_GOT_OFST, tempreg);
10353 expr1.X_add_number = offset_expr.X_add_number;
10354 offset_expr.X_add_number = 0;
10355 if (expr1.X_add_number < -0x8000
10356 || expr1.X_add_number >= 0x8000)
10357 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
10358 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
10359 lw_reloc_type, mips_gp_register);
10361 relax_start (offset_expr.X_add_symbol);
10363 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j", tempreg,
10364 tempreg, BFD_RELOC_LO16);
10367 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
10368 tempreg, tempreg, breg);
10369 macro_build (&expr1, s, fmt, treg, BFD_RELOC_LO16, tempreg);
10371 else if (mips_big_got && !HAVE_NEWABI)
10375 /* If this is a reference to an external symbol, we want
10376 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
10377 addu $tempreg,$tempreg,$gp
10378 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
10379 <op> $treg,0($tempreg)
10381 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
10383 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
10384 <op> $treg,0($tempreg)
10385 If there is a base register, we add it to $tempreg before
10386 the <op>. If there is a constant, we stick it in the
10387 <op> instruction. We don't handle constants larger than
10388 16 bits, because we have no way to load the upper 16 bits
10389 (actually, we could handle them for the subset of cases
10390 in which we are not using $at). */
10391 gas_assert (offset_expr.X_op == O_symbol);
10392 expr1.X_add_number = offset_expr.X_add_number;
10393 offset_expr.X_add_number = 0;
10394 if (expr1.X_add_number < -0x8000
10395 || expr1.X_add_number >= 0x8000)
10396 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
10397 gpdelay = reg_needs_delay (mips_gp_register);
10398 relax_start (offset_expr.X_add_symbol);
10399 macro_build (&offset_expr, "lui", LUI_FMT, tempreg,
10400 BFD_RELOC_MIPS_GOT_HI16);
10401 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", tempreg, tempreg,
10403 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
10404 BFD_RELOC_MIPS_GOT_LO16, tempreg);
10407 macro_build (NULL, "nop", "");
10408 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
10409 BFD_RELOC_MIPS_GOT16, mips_gp_register);
10411 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j", tempreg,
10412 tempreg, BFD_RELOC_LO16);
10416 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
10417 tempreg, tempreg, breg);
10418 macro_build (&expr1, s, fmt, treg, BFD_RELOC_LO16, tempreg);
10420 else if (mips_big_got && HAVE_NEWABI)
10422 /* If this is a reference to an external symbol, we want
10423 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
10424 add $tempreg,$tempreg,$gp
10425 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
10426 <op> $treg,<ofst>($tempreg)
10427 Otherwise, for local symbols, we want:
10428 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
10429 <op> $treg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_OFST) */
10430 gas_assert (offset_expr.X_op == O_symbol);
10431 expr1.X_add_number = offset_expr.X_add_number;
10432 offset_expr.X_add_number = 0;
10433 if (expr1.X_add_number < -0x8000
10434 || expr1.X_add_number >= 0x8000)
10435 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
10436 relax_start (offset_expr.X_add_symbol);
10437 macro_build (&offset_expr, "lui", LUI_FMT, tempreg,
10438 BFD_RELOC_MIPS_GOT_HI16);
10439 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", tempreg, tempreg,
10441 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
10442 BFD_RELOC_MIPS_GOT_LO16, tempreg);
10444 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
10445 tempreg, tempreg, breg);
10446 macro_build (&expr1, s, fmt, treg, BFD_RELOC_LO16, tempreg);
10449 offset_expr.X_add_number = expr1.X_add_number;
10450 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
10451 BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register);
10453 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
10454 tempreg, tempreg, breg);
10455 macro_build (&offset_expr, s, fmt, treg,
10456 BFD_RELOC_MIPS_GOT_OFST, tempreg);
10465 gas_assert (mips_opts.micromips);
10466 gas_assert (mips_opts.insn32);
10467 start_noreorder ();
10468 macro_build (NULL, "jr", "s", RA);
10469 expr1.X_add_number = EXTRACT_OPERAND (1, IMMP, *ip) << 2;
10470 macro_build (&expr1, "addiu", "t,r,j", SP, SP, BFD_RELOC_LO16);
10475 gas_assert (mips_opts.micromips);
10476 gas_assert (mips_opts.insn32);
10477 macro_build (NULL, "jr", "s", sreg);
10478 if (mips_opts.noreorder)
10479 macro_build (NULL, "nop", "");
10484 load_register (treg, &imm_expr, 0);
10488 load_register (treg, &imm_expr, 1);
10492 if (imm_expr.X_op == O_constant)
10495 load_register (AT, &imm_expr, 0);
10496 macro_build (NULL, "mtc1", "t,G", AT, treg);
10501 gas_assert (offset_expr.X_op == O_symbol
10502 && strcmp (segment_name (S_GET_SEGMENT
10503 (offset_expr.X_add_symbol)),
10505 && offset_expr.X_add_number == 0);
10506 macro_build (&offset_expr, "lwc1", "T,o(b)", treg,
10507 BFD_RELOC_MIPS_LITERAL, mips_gp_register);
10512 /* Check if we have a constant in IMM_EXPR. If the GPRs are 64 bits
10513 wide, IMM_EXPR is the entire value. Otherwise IMM_EXPR is the high
10514 order 32 bits of the value and the low order 32 bits are either
10515 zero or in OFFSET_EXPR. */
10516 if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big)
10518 if (HAVE_64BIT_GPRS)
10519 load_register (treg, &imm_expr, 1);
10524 if (target_big_endian)
10536 load_register (hreg, &imm_expr, 0);
10539 if (offset_expr.X_op == O_absent)
10540 move_register (lreg, 0);
10543 gas_assert (offset_expr.X_op == O_constant);
10544 load_register (lreg, &offset_expr, 0);
10551 /* We know that sym is in the .rdata section. First we get the
10552 upper 16 bits of the address. */
10553 if (mips_pic == NO_PIC)
10555 macro_build_lui (&offset_expr, AT);
10560 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", AT,
10561 BFD_RELOC_MIPS_GOT16, mips_gp_register);
10565 /* Now we load the register(s). */
10566 if (HAVE_64BIT_GPRS)
10569 macro_build (&offset_expr, "ld", "t,o(b)", treg, BFD_RELOC_LO16, AT);
10574 macro_build (&offset_expr, "lw", "t,o(b)", treg, BFD_RELOC_LO16, AT);
10577 /* FIXME: How in the world do we deal with the possible
10579 offset_expr.X_add_number += 4;
10580 macro_build (&offset_expr, "lw", "t,o(b)",
10581 treg + 1, BFD_RELOC_LO16, AT);
10587 /* Check if we have a constant in IMM_EXPR. If the FPRs are 64 bits
10588 wide, IMM_EXPR is the entire value and the GPRs are known to be 64
10589 bits wide as well. Otherwise IMM_EXPR is the high order 32 bits of
10590 the value and the low order 32 bits are either zero or in
10592 if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big)
10595 load_register (AT, &imm_expr, HAVE_64BIT_FPRS);
10596 if (HAVE_64BIT_FPRS)
10598 gas_assert (HAVE_64BIT_GPRS);
10599 macro_build (NULL, "dmtc1", "t,S", AT, treg);
10603 macro_build (NULL, "mtc1", "t,G", AT, treg + 1);
10604 if (offset_expr.X_op == O_absent)
10605 macro_build (NULL, "mtc1", "t,G", 0, treg);
10608 gas_assert (offset_expr.X_op == O_constant);
10609 load_register (AT, &offset_expr, 0);
10610 macro_build (NULL, "mtc1", "t,G", AT, treg);
10616 gas_assert (offset_expr.X_op == O_symbol
10617 && offset_expr.X_add_number == 0);
10618 s = segment_name (S_GET_SEGMENT (offset_expr.X_add_symbol));
10619 if (strcmp (s, ".lit8") == 0)
10621 breg = mips_gp_register;
10622 offset_reloc[0] = BFD_RELOC_MIPS_LITERAL;
10623 offset_reloc[1] = BFD_RELOC_UNUSED;
10624 offset_reloc[2] = BFD_RELOC_UNUSED;
10628 gas_assert (strcmp (s, RDATA_SECTION_NAME) == 0);
10630 if (mips_pic != NO_PIC)
10631 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", AT,
10632 BFD_RELOC_MIPS_GOT16, mips_gp_register);
10635 /* FIXME: This won't work for a 64 bit address. */
10636 macro_build_lui (&offset_expr, AT);
10640 offset_reloc[0] = BFD_RELOC_LO16;
10641 offset_reloc[1] = BFD_RELOC_UNUSED;
10642 offset_reloc[2] = BFD_RELOC_UNUSED;
10649 * The MIPS assembler seems to check for X_add_number not
10650 * being double aligned and generating:
10651 * lui at,%hi(foo+1)
10653 * addiu at,at,%lo(foo+1)
10656 * But, the resulting address is the same after relocation so why
10657 * generate the extra instruction?
10659 /* Itbl support may require additional care here. */
10662 if (CPU_HAS_LDC1_SDC1 (mips_opts.arch))
10671 gas_assert (!mips_opts.micromips);
10672 /* Itbl support may require additional care here. */
10675 if (CPU_HAS_LDC1_SDC1 (mips_opts.arch))
10695 if (HAVE_64BIT_GPRS)
10705 if (HAVE_64BIT_GPRS)
10713 /* Even on a big endian machine $fn comes before $fn+1. We have
10714 to adjust when loading from memory. We set coproc if we must
10715 load $fn+1 first. */
10716 /* Itbl support may require additional care here. */
10717 if (!target_big_endian)
10720 if (small_offset_p (0, align, 16))
10723 if (!small_offset_p (4, align, 16))
10725 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j", AT, breg,
10726 -1, offset_reloc[0], offset_reloc[1],
10728 expr1.X_add_number = 0;
10732 offset_reloc[0] = BFD_RELOC_LO16;
10733 offset_reloc[1] = BFD_RELOC_UNUSED;
10734 offset_reloc[2] = BFD_RELOC_UNUSED;
10736 if (strcmp (s, "lw") == 0 && treg == breg)
10738 ep->X_add_number += 4;
10739 macro_build (ep, s, fmt, treg + 1, -1, offset_reloc[0],
10740 offset_reloc[1], offset_reloc[2], breg);
10741 ep->X_add_number -= 4;
10742 macro_build (ep, s, fmt, treg, -1, offset_reloc[0],
10743 offset_reloc[1], offset_reloc[2], breg);
10747 macro_build (ep, s, fmt, coproc ? treg + 1 : treg, -1,
10748 offset_reloc[0], offset_reloc[1], offset_reloc[2],
10750 ep->X_add_number += 4;
10751 macro_build (ep, s, fmt, coproc ? treg : treg + 1, -1,
10752 offset_reloc[0], offset_reloc[1], offset_reloc[2],
10758 if (offset_expr.X_op != O_symbol
10759 && offset_expr.X_op != O_constant)
10761 as_bad (_("Expression too complex"));
10762 offset_expr.X_op = O_constant;
10765 if (HAVE_32BIT_ADDRESSES
10766 && !IS_SEXT_32BIT_NUM (offset_expr.X_add_number))
10770 sprintf_vma (value, offset_expr.X_add_number);
10771 as_bad (_("Number (0x%s) larger than 32 bits"), value);
10774 if (mips_pic == NO_PIC || offset_expr.X_op == O_constant)
10776 /* If this is a reference to a GP relative symbol, we want
10777 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
10778 <op> $treg+1,<sym>+4($gp) (BFD_RELOC_GPREL16)
10779 If we have a base register, we use this
10781 <op> $treg,<sym>($at) (BFD_RELOC_GPREL16)
10782 <op> $treg+1,<sym>+4($at) (BFD_RELOC_GPREL16)
10783 If this is not a GP relative symbol, we want
10784 lui $at,<sym> (BFD_RELOC_HI16_S)
10785 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
10786 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
10787 If there is a base register, we add it to $at after the
10788 lui instruction. If there is a constant, we always use
10790 if (offset_expr.X_op == O_symbol
10791 && (valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
10792 && !nopic_need_relax (offset_expr.X_add_symbol, 1))
10794 relax_start (offset_expr.X_add_symbol);
10797 tempreg = mips_gp_register;
10801 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
10802 AT, breg, mips_gp_register);
10807 /* Itbl support may require additional care here. */
10808 macro_build (&offset_expr, s, fmt, coproc ? treg + 1 : treg,
10809 BFD_RELOC_GPREL16, tempreg);
10810 offset_expr.X_add_number += 4;
10812 /* Set mips_optimize to 2 to avoid inserting an
10814 hold_mips_optimize = mips_optimize;
10816 /* Itbl support may require additional care here. */
10817 macro_build (&offset_expr, s, fmt, coproc ? treg : treg + 1,
10818 BFD_RELOC_GPREL16, tempreg);
10819 mips_optimize = hold_mips_optimize;
10823 offset_expr.X_add_number -= 4;
10826 if (offset_high_part (offset_expr.X_add_number, 16)
10827 != offset_high_part (offset_expr.X_add_number + 4, 16))
10829 load_address (AT, &offset_expr, &used_at);
10830 offset_expr.X_op = O_constant;
10831 offset_expr.X_add_number = 0;
10834 macro_build_lui (&offset_expr, AT);
10836 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, breg, AT);
10837 /* Itbl support may require additional care here. */
10838 macro_build (&offset_expr, s, fmt, coproc ? treg + 1 : treg,
10839 BFD_RELOC_LO16, AT);
10840 /* FIXME: How do we handle overflow here? */
10841 offset_expr.X_add_number += 4;
10842 /* Itbl support may require additional care here. */
10843 macro_build (&offset_expr, s, fmt, coproc ? treg : treg + 1,
10844 BFD_RELOC_LO16, AT);
10845 if (mips_relax.sequence)
10848 else if (!mips_big_got)
10850 /* If this is a reference to an external symbol, we want
10851 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
10854 <op> $treg+1,4($at)
10856 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
10858 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
10859 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
10860 If there is a base register we add it to $at before the
10861 lwc1 instructions. If there is a constant we include it
10862 in the lwc1 instructions. */
10864 expr1.X_add_number = offset_expr.X_add_number;
10865 if (expr1.X_add_number < -0x8000
10866 || expr1.X_add_number >= 0x8000 - 4)
10867 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
10868 load_got_offset (AT, &offset_expr);
10871 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, breg, AT);
10873 /* Set mips_optimize to 2 to avoid inserting an undesired
10875 hold_mips_optimize = mips_optimize;
10878 /* Itbl support may require additional care here. */
10879 relax_start (offset_expr.X_add_symbol);
10880 macro_build (&expr1, s, fmt, coproc ? treg + 1 : treg,
10881 BFD_RELOC_LO16, AT);
10882 expr1.X_add_number += 4;
10883 macro_build (&expr1, s, fmt, coproc ? treg : treg + 1,
10884 BFD_RELOC_LO16, AT);
10886 macro_build (&offset_expr, s, fmt, coproc ? treg + 1 : treg,
10887 BFD_RELOC_LO16, AT);
10888 offset_expr.X_add_number += 4;
10889 macro_build (&offset_expr, s, fmt, coproc ? treg : treg + 1,
10890 BFD_RELOC_LO16, AT);
10893 mips_optimize = hold_mips_optimize;
10895 else if (mips_big_got)
10899 /* If this is a reference to an external symbol, we want
10900 lui $at,<sym> (BFD_RELOC_MIPS_GOT_HI16)
10902 lw $at,<sym>($at) (BFD_RELOC_MIPS_GOT_LO16)
10905 <op> $treg+1,4($at)
10907 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
10909 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
10910 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
10911 If there is a base register we add it to $at before the
10912 lwc1 instructions. If there is a constant we include it
10913 in the lwc1 instructions. */
10915 expr1.X_add_number = offset_expr.X_add_number;
10916 offset_expr.X_add_number = 0;
10917 if (expr1.X_add_number < -0x8000
10918 || expr1.X_add_number >= 0x8000 - 4)
10919 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
10920 gpdelay = reg_needs_delay (mips_gp_register);
10921 relax_start (offset_expr.X_add_symbol);
10922 macro_build (&offset_expr, "lui", LUI_FMT,
10923 AT, BFD_RELOC_MIPS_GOT_HI16);
10924 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
10925 AT, AT, mips_gp_register);
10926 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
10927 AT, BFD_RELOC_MIPS_GOT_LO16, AT);
10930 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, breg, AT);
10931 /* Itbl support may require additional care here. */
10932 macro_build (&expr1, s, fmt, coproc ? treg + 1 : treg,
10933 BFD_RELOC_LO16, AT);
10934 expr1.X_add_number += 4;
10936 /* Set mips_optimize to 2 to avoid inserting an undesired
10938 hold_mips_optimize = mips_optimize;
10940 /* Itbl support may require additional care here. */
10941 macro_build (&expr1, s, fmt, coproc ? treg : treg + 1,
10942 BFD_RELOC_LO16, AT);
10943 mips_optimize = hold_mips_optimize;
10944 expr1.X_add_number -= 4;
10947 offset_expr.X_add_number = expr1.X_add_number;
10949 macro_build (NULL, "nop", "");
10950 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", AT,
10951 BFD_RELOC_MIPS_GOT16, mips_gp_register);
10954 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, breg, AT);
10955 /* Itbl support may require additional care here. */
10956 macro_build (&offset_expr, s, fmt, coproc ? treg + 1 : treg,
10957 BFD_RELOC_LO16, AT);
10958 offset_expr.X_add_number += 4;
10960 /* Set mips_optimize to 2 to avoid inserting an undesired
10962 hold_mips_optimize = mips_optimize;
10964 /* Itbl support may require additional care here. */
10965 macro_build (&offset_expr, s, fmt, coproc ? treg : treg + 1,
10966 BFD_RELOC_LO16, AT);
10967 mips_optimize = hold_mips_optimize;
10986 /* New code added to support COPZ instructions.
10987 This code builds table entries out of the macros in mip_opcodes.
10988 R4000 uses interlocks to handle coproc delays.
10989 Other chips (like the R3000) require nops to be inserted for delays.
10991 FIXME: Currently, we require that the user handle delays.
10992 In order to fill delay slots for non-interlocked chips,
10993 we must have a way to specify delays based on the coprocessor.
10994 Eg. 4 cycles if load coproc reg from memory, 1 if in cache, etc.
10995 What are the side-effects of the cop instruction?
10996 What cache support might we have and what are its effects?
10997 Both coprocessor & memory require delays. how long???
10998 What registers are read/set/modified?
11000 If an itbl is provided to interpret cop instructions,
11001 this knowledge can be encoded in the itbl spec. */
11015 gas_assert (!mips_opts.micromips);
11016 /* For now we just do C (same as Cz). The parameter will be
11017 stored in insn_opcode by mips_ip. */
11018 macro_build (NULL, s, "C", (int) ip->insn_opcode);
11022 move_register (dreg, sreg);
11026 gas_assert (mips_opts.micromips);
11027 gas_assert (mips_opts.insn32);
11028 dreg = micromips_to_32_reg_h_map1[EXTRACT_OPERAND (1, MH, *ip)];
11029 breg = micromips_to_32_reg_h_map2[EXTRACT_OPERAND (1, MH, *ip)];
11030 sreg = micromips_to_32_reg_m_map[EXTRACT_OPERAND (1, MM, *ip)];
11031 treg = micromips_to_32_reg_n_map[EXTRACT_OPERAND (1, MN, *ip)];
11032 move_register (dreg, sreg);
11033 move_register (breg, treg);
11039 if (mips_opts.arch == CPU_R5900)
11041 macro_build (NULL, dbl ? "dmultu" : "multu", "d,s,t", dreg, sreg, treg);
11045 macro_build (NULL, dbl ? "dmultu" : "multu", "s,t", sreg, treg);
11046 macro_build (NULL, "mflo", MFHL_FMT, dreg);
11053 /* The MIPS assembler some times generates shifts and adds. I'm
11054 not trying to be that fancy. GCC should do this for us
11057 load_register (AT, &imm_expr, dbl);
11058 macro_build (NULL, dbl ? "dmult" : "mult", "s,t", sreg, AT);
11059 macro_build (NULL, "mflo", MFHL_FMT, dreg);
11072 start_noreorder ();
11075 load_register (AT, &imm_expr, dbl);
11076 macro_build (NULL, dbl ? "dmult" : "mult", "s,t", sreg, imm ? AT : treg);
11077 macro_build (NULL, "mflo", MFHL_FMT, dreg);
11078 macro_build (NULL, dbl ? "dsra32" : "sra", SHFT_FMT, dreg, dreg, RA);
11079 macro_build (NULL, "mfhi", MFHL_FMT, AT);
11081 macro_build (NULL, "tne", TRAP_FMT, dreg, AT, 6);
11084 if (mips_opts.micromips)
11085 micromips_label_expr (&label_expr);
11087 label_expr.X_add_number = 8;
11088 macro_build (&label_expr, "beq", "s,t,p", dreg, AT);
11089 macro_build (NULL, "nop", "");
11090 macro_build (NULL, "break", BRK_FMT, 6);
11091 if (mips_opts.micromips)
11092 micromips_add_label ();
11095 macro_build (NULL, "mflo", MFHL_FMT, dreg);
11108 start_noreorder ();
11111 load_register (AT, &imm_expr, dbl);
11112 macro_build (NULL, dbl ? "dmultu" : "multu", "s,t",
11113 sreg, imm ? AT : treg);
11114 macro_build (NULL, "mfhi", MFHL_FMT, AT);
11115 macro_build (NULL, "mflo", MFHL_FMT, dreg);
11117 macro_build (NULL, "tne", TRAP_FMT, AT, ZERO, 6);
11120 if (mips_opts.micromips)
11121 micromips_label_expr (&label_expr);
11123 label_expr.X_add_number = 8;
11124 macro_build (&label_expr, "beq", "s,t,p", AT, ZERO);
11125 macro_build (NULL, "nop", "");
11126 macro_build (NULL, "break", BRK_FMT, 6);
11127 if (mips_opts.micromips)
11128 micromips_add_label ();
11134 if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_opts.arch))
11145 macro_build (NULL, "dnegu", "d,w", tempreg, treg);
11146 macro_build (NULL, "drorv", "d,t,s", dreg, sreg, tempreg);
11150 macro_build (NULL, "dsubu", "d,v,t", AT, ZERO, treg);
11151 macro_build (NULL, "dsrlv", "d,t,s", AT, sreg, AT);
11152 macro_build (NULL, "dsllv", "d,t,s", dreg, sreg, treg);
11153 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
11157 if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_opts.arch))
11168 macro_build (NULL, "negu", "d,w", tempreg, treg);
11169 macro_build (NULL, "rorv", "d,t,s", dreg, sreg, tempreg);
11173 macro_build (NULL, "subu", "d,v,t", AT, ZERO, treg);
11174 macro_build (NULL, "srlv", "d,t,s", AT, sreg, AT);
11175 macro_build (NULL, "sllv", "d,t,s", dreg, sreg, treg);
11176 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
11185 if (imm_expr.X_op != O_constant)
11186 as_bad (_("Improper rotate count"));
11187 rot = imm_expr.X_add_number & 0x3f;
11188 if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_opts.arch))
11190 rot = (64 - rot) & 0x3f;
11192 macro_build (NULL, "dror32", SHFT_FMT, dreg, sreg, rot - 32);
11194 macro_build (NULL, "dror", SHFT_FMT, dreg, sreg, rot);
11199 macro_build (NULL, "dsrl", SHFT_FMT, dreg, sreg, 0);
11202 l = (rot < 0x20) ? "dsll" : "dsll32";
11203 rr = ((0x40 - rot) < 0x20) ? "dsrl" : "dsrl32";
11206 macro_build (NULL, l, SHFT_FMT, AT, sreg, rot);
11207 macro_build (NULL, rr, SHFT_FMT, dreg, sreg, (0x20 - rot) & 0x1f);
11208 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
11216 if (imm_expr.X_op != O_constant)
11217 as_bad (_("Improper rotate count"));
11218 rot = imm_expr.X_add_number & 0x1f;
11219 if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_opts.arch))
11221 macro_build (NULL, "ror", SHFT_FMT, dreg, sreg, (32 - rot) & 0x1f);
11226 macro_build (NULL, "srl", SHFT_FMT, dreg, sreg, 0);
11230 macro_build (NULL, "sll", SHFT_FMT, AT, sreg, rot);
11231 macro_build (NULL, "srl", SHFT_FMT, dreg, sreg, (0x20 - rot) & 0x1f);
11232 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
11237 if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_opts.arch))
11239 macro_build (NULL, "drorv", "d,t,s", dreg, sreg, treg);
11243 macro_build (NULL, "dsubu", "d,v,t", AT, ZERO, treg);
11244 macro_build (NULL, "dsllv", "d,t,s", AT, sreg, AT);
11245 macro_build (NULL, "dsrlv", "d,t,s", dreg, sreg, treg);
11246 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
11250 if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_opts.arch))
11252 macro_build (NULL, "rorv", "d,t,s", dreg, sreg, treg);
11256 macro_build (NULL, "subu", "d,v,t", AT, ZERO, treg);
11257 macro_build (NULL, "sllv", "d,t,s", AT, sreg, AT);
11258 macro_build (NULL, "srlv", "d,t,s", dreg, sreg, treg);
11259 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
11268 if (imm_expr.X_op != O_constant)
11269 as_bad (_("Improper rotate count"));
11270 rot = imm_expr.X_add_number & 0x3f;
11271 if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_opts.arch))
11274 macro_build (NULL, "dror32", SHFT_FMT, dreg, sreg, rot - 32);
11276 macro_build (NULL, "dror", SHFT_FMT, dreg, sreg, rot);
11281 macro_build (NULL, "dsrl", SHFT_FMT, dreg, sreg, 0);
11284 rr = (rot < 0x20) ? "dsrl" : "dsrl32";
11285 l = ((0x40 - rot) < 0x20) ? "dsll" : "dsll32";
11288 macro_build (NULL, rr, SHFT_FMT, AT, sreg, rot);
11289 macro_build (NULL, l, SHFT_FMT, dreg, sreg, (0x20 - rot) & 0x1f);
11290 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
11298 if (imm_expr.X_op != O_constant)
11299 as_bad (_("Improper rotate count"));
11300 rot = imm_expr.X_add_number & 0x1f;
11301 if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_opts.arch))
11303 macro_build (NULL, "ror", SHFT_FMT, dreg, sreg, rot);
11308 macro_build (NULL, "srl", SHFT_FMT, dreg, sreg, 0);
11312 macro_build (NULL, "srl", SHFT_FMT, AT, sreg, rot);
11313 macro_build (NULL, "sll", SHFT_FMT, dreg, sreg, (0x20 - rot) & 0x1f);
11314 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
11320 macro_build (&expr1, "sltiu", "t,r,j", dreg, treg, BFD_RELOC_LO16);
11321 else if (treg == 0)
11322 macro_build (&expr1, "sltiu", "t,r,j", dreg, sreg, BFD_RELOC_LO16);
11325 macro_build (NULL, "xor", "d,v,t", dreg, sreg, treg);
11326 macro_build (&expr1, "sltiu", "t,r,j", dreg, dreg, BFD_RELOC_LO16);
11331 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
11333 macro_build (&expr1, "sltiu", "t,r,j", dreg, sreg, BFD_RELOC_LO16);
11338 as_warn (_("Instruction %s: result is always false"),
11339 ip->insn_mo->name);
11340 move_register (dreg, 0);
11343 if (CPU_HAS_SEQ (mips_opts.arch)
11344 && -512 <= imm_expr.X_add_number
11345 && imm_expr.X_add_number < 512)
11347 macro_build (NULL, "seqi", "t,r,+Q", dreg, sreg,
11348 (int) imm_expr.X_add_number);
11351 if (imm_expr.X_op == O_constant
11352 && imm_expr.X_add_number >= 0
11353 && imm_expr.X_add_number < 0x10000)
11355 macro_build (&imm_expr, "xori", "t,r,i", dreg, sreg, BFD_RELOC_LO16);
11357 else if (imm_expr.X_op == O_constant
11358 && imm_expr.X_add_number > -0x8000
11359 && imm_expr.X_add_number < 0)
11361 imm_expr.X_add_number = -imm_expr.X_add_number;
11362 macro_build (&imm_expr, HAVE_32BIT_GPRS ? "addiu" : "daddiu",
11363 "t,r,j", dreg, sreg, BFD_RELOC_LO16);
11365 else if (CPU_HAS_SEQ (mips_opts.arch))
11368 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
11369 macro_build (NULL, "seq", "d,v,t", dreg, sreg, AT);
11374 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
11375 macro_build (NULL, "xor", "d,v,t", dreg, sreg, AT);
11378 macro_build (&expr1, "sltiu", "t,r,j", dreg, dreg, BFD_RELOC_LO16);
11381 case M_SGE: /* sreg >= treg <==> not (sreg < treg) */
11387 macro_build (NULL, s, "d,v,t", dreg, sreg, treg);
11388 macro_build (&expr1, "xori", "t,r,i", dreg, dreg, BFD_RELOC_LO16);
11391 case M_SGE_I: /* sreg >= I <==> not (sreg < I) */
11393 if (imm_expr.X_op == O_constant
11394 && imm_expr.X_add_number >= -0x8000
11395 && imm_expr.X_add_number < 0x8000)
11397 macro_build (&imm_expr, mask == M_SGE_I ? "slti" : "sltiu", "t,r,j",
11398 dreg, sreg, BFD_RELOC_LO16);
11402 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
11403 macro_build (NULL, mask == M_SGE_I ? "slt" : "sltu", "d,v,t",
11407 macro_build (&expr1, "xori", "t,r,i", dreg, dreg, BFD_RELOC_LO16);
11410 case M_SGT: /* sreg > treg <==> treg < sreg */
11416 macro_build (NULL, s, "d,v,t", dreg, treg, sreg);
11419 case M_SGT_I: /* sreg > I <==> I < sreg */
11426 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
11427 macro_build (NULL, s, "d,v,t", dreg, AT, sreg);
11430 case M_SLE: /* sreg <= treg <==> treg >= sreg <==> not (treg < sreg) */
11436 macro_build (NULL, s, "d,v,t", dreg, treg, sreg);
11437 macro_build (&expr1, "xori", "t,r,i", dreg, dreg, BFD_RELOC_LO16);
11440 case M_SLE_I: /* sreg <= I <==> I >= sreg <==> not (I < sreg) */
11447 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
11448 macro_build (NULL, s, "d,v,t", dreg, AT, sreg);
11449 macro_build (&expr1, "xori", "t,r,i", dreg, dreg, BFD_RELOC_LO16);
11453 if (imm_expr.X_op == O_constant
11454 && imm_expr.X_add_number >= -0x8000
11455 && imm_expr.X_add_number < 0x8000)
11457 macro_build (&imm_expr, "slti", "t,r,j", dreg, sreg, BFD_RELOC_LO16);
11461 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
11462 macro_build (NULL, "slt", "d,v,t", dreg, sreg, AT);
11466 if (imm_expr.X_op == O_constant
11467 && imm_expr.X_add_number >= -0x8000
11468 && imm_expr.X_add_number < 0x8000)
11470 macro_build (&imm_expr, "sltiu", "t,r,j", dreg, sreg,
11475 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
11476 macro_build (NULL, "sltu", "d,v,t", dreg, sreg, AT);
11481 macro_build (NULL, "sltu", "d,v,t", dreg, 0, treg);
11482 else if (treg == 0)
11483 macro_build (NULL, "sltu", "d,v,t", dreg, 0, sreg);
11486 macro_build (NULL, "xor", "d,v,t", dreg, sreg, treg);
11487 macro_build (NULL, "sltu", "d,v,t", dreg, 0, dreg);
11492 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
11494 macro_build (NULL, "sltu", "d,v,t", dreg, 0, sreg);
11499 as_warn (_("Instruction %s: result is always true"),
11500 ip->insn_mo->name);
11501 macro_build (&expr1, HAVE_32BIT_GPRS ? "addiu" : "daddiu", "t,r,j",
11502 dreg, 0, BFD_RELOC_LO16);
11505 if (CPU_HAS_SEQ (mips_opts.arch)
11506 && -512 <= imm_expr.X_add_number
11507 && imm_expr.X_add_number < 512)
11509 macro_build (NULL, "snei", "t,r,+Q", dreg, sreg,
11510 (int) imm_expr.X_add_number);
11513 if (imm_expr.X_op == O_constant
11514 && imm_expr.X_add_number >= 0
11515 && imm_expr.X_add_number < 0x10000)
11517 macro_build (&imm_expr, "xori", "t,r,i", dreg, sreg, BFD_RELOC_LO16);
11519 else if (imm_expr.X_op == O_constant
11520 && imm_expr.X_add_number > -0x8000
11521 && imm_expr.X_add_number < 0)
11523 imm_expr.X_add_number = -imm_expr.X_add_number;
11524 macro_build (&imm_expr, HAVE_32BIT_GPRS ? "addiu" : "daddiu",
11525 "t,r,j", dreg, sreg, BFD_RELOC_LO16);
11527 else if (CPU_HAS_SEQ (mips_opts.arch))
11530 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
11531 macro_build (NULL, "sne", "d,v,t", dreg, sreg, AT);
11536 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
11537 macro_build (NULL, "xor", "d,v,t", dreg, sreg, AT);
11540 macro_build (NULL, "sltu", "d,v,t", dreg, 0, dreg);
11555 if (!mips_opts.micromips)
11557 if (imm_expr.X_op == O_constant
11558 && imm_expr.X_add_number > -0x200
11559 && imm_expr.X_add_number <= 0x200)
11561 macro_build (NULL, s, "t,r,.", dreg, sreg, -imm_expr.X_add_number);
11570 if (imm_expr.X_op == O_constant
11571 && imm_expr.X_add_number > -0x8000
11572 && imm_expr.X_add_number <= 0x8000)
11574 imm_expr.X_add_number = -imm_expr.X_add_number;
11575 macro_build (&imm_expr, s, "t,r,j", dreg, sreg, BFD_RELOC_LO16);
11580 load_register (AT, &imm_expr, dbl);
11581 macro_build (NULL, s2, "d,v,t", dreg, sreg, AT);
11603 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
11604 macro_build (NULL, s, "s,t", sreg, AT);
11609 gas_assert (!mips_opts.micromips);
11610 gas_assert (mips_opts.isa == ISA_MIPS1);
11612 sreg = (ip->insn_opcode >> 11) & 0x1f; /* floating reg */
11613 dreg = (ip->insn_opcode >> 06) & 0x1f; /* floating reg */
11616 * Is the double cfc1 instruction a bug in the mips assembler;
11617 * or is there a reason for it?
11619 start_noreorder ();
11620 macro_build (NULL, "cfc1", "t,G", treg, RA);
11621 macro_build (NULL, "cfc1", "t,G", treg, RA);
11622 macro_build (NULL, "nop", "");
11623 expr1.X_add_number = 3;
11624 macro_build (&expr1, "ori", "t,r,i", AT, treg, BFD_RELOC_LO16);
11625 expr1.X_add_number = 2;
11626 macro_build (&expr1, "xori", "t,r,i", AT, AT, BFD_RELOC_LO16);
11627 macro_build (NULL, "ctc1", "t,G", AT, RA);
11628 macro_build (NULL, "nop", "");
11629 macro_build (NULL, mask == M_TRUNCWD ? "cvt.w.d" : "cvt.w.s", "D,S",
11631 macro_build (NULL, "ctc1", "t,G", treg, RA);
11632 macro_build (NULL, "nop", "");
11649 offbits = (mips_opts.micromips ? 12 : 16);
11655 offbits = (mips_opts.micromips ? 12 : 16);
11667 offbits = (mips_opts.micromips ? 12 : 16);
11674 offbits = (mips_opts.micromips ? 12 : 16);
11679 large_offset = !small_offset_p (off, align, offbits);
11681 expr1.X_add_number = 0;
11686 if (small_offset_p (0, align, 16))
11687 macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", tempreg, breg, -1,
11688 offset_reloc[0], offset_reloc[1], offset_reloc[2]);
11691 load_address (tempreg, ep, &used_at);
11693 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
11694 tempreg, tempreg, breg);
11696 offset_reloc[0] = BFD_RELOC_LO16;
11697 offset_reloc[1] = BFD_RELOC_UNUSED;
11698 offset_reloc[2] = BFD_RELOC_UNUSED;
11703 else if (!ust && treg == breg)
11714 if (!target_big_endian)
11715 ep->X_add_number += off;
11717 macro_build (NULL, s, "t,~(b)", tempreg, (int) ep->X_add_number, breg);
11719 macro_build (ep, s, "t,o(b)", tempreg, -1,
11720 offset_reloc[0], offset_reloc[1], offset_reloc[2], breg);
11722 if (!target_big_endian)
11723 ep->X_add_number -= off;
11725 ep->X_add_number += off;
11727 macro_build (NULL, s2, "t,~(b)",
11728 tempreg, (int) ep->X_add_number, breg);
11730 macro_build (ep, s2, "t,o(b)", tempreg, -1,
11731 offset_reloc[0], offset_reloc[1], offset_reloc[2], breg);
11733 /* If necessary, move the result in tempreg to the final destination. */
11734 if (!ust && treg != tempreg)
11736 /* Protect second load's delay slot. */
11738 move_register (treg, tempreg);
11744 if (target_big_endian == ust)
11745 ep->X_add_number += off;
11746 tempreg = ust || large_offset ? treg : AT;
11747 macro_build (ep, s, "t,o(b)", tempreg, -1,
11748 offset_reloc[0], offset_reloc[1], offset_reloc[2], breg);
11750 /* For halfword transfers we need a temporary register to shuffle
11751 bytes. Unfortunately for M_USH_A we have none available before
11752 the next store as AT holds the base address. We deal with this
11753 case by clobbering TREG and then restoring it as with ULH. */
11754 tempreg = ust == large_offset ? treg : AT;
11756 macro_build (NULL, "srl", SHFT_FMT, tempreg, treg, 8);
11758 if (target_big_endian == ust)
11759 ep->X_add_number -= off;
11761 ep->X_add_number += off;
11762 macro_build (ep, s2, "t,o(b)", tempreg, -1,
11763 offset_reloc[0], offset_reloc[1], offset_reloc[2], breg);
11765 /* For M_USH_A re-retrieve the LSB. */
11766 if (ust && large_offset)
11768 if (target_big_endian)
11769 ep->X_add_number += off;
11771 ep->X_add_number -= off;
11772 macro_build (&expr1, "lbu", "t,o(b)", AT, -1,
11773 offset_reloc[0], offset_reloc[1], offset_reloc[2], AT);
11775 /* For ULH and M_USH_A OR the LSB in. */
11776 if (!ust || large_offset)
11778 tempreg = !large_offset ? AT : treg;
11779 macro_build (NULL, "sll", SHFT_FMT, tempreg, tempreg, 8);
11780 macro_build (NULL, "or", "d,v,t", treg, treg, AT);
11785 /* FIXME: Check if this is one of the itbl macros, since they
11786 are added dynamically. */
11787 as_bad (_("Macro %s not implemented yet"), ip->insn_mo->name);
11790 if (!mips_opts.at && used_at)
11791 as_bad (_("Macro used $at after \".set noat\""));
11794 /* Implement macros in mips16 mode. */
11797 mips16_macro (struct mips_cl_insn *ip)
11800 int xreg, yreg, zreg, tmp;
11803 const char *s, *s2, *s3;
11805 mask = ip->insn_mo->mask;
11807 xreg = MIPS16_EXTRACT_OPERAND (RX, *ip);
11808 yreg = MIPS16_EXTRACT_OPERAND (RY, *ip);
11809 zreg = MIPS16_EXTRACT_OPERAND (RZ, *ip);
11811 expr1.X_op = O_constant;
11812 expr1.X_op_symbol = NULL;
11813 expr1.X_add_symbol = NULL;
11814 expr1.X_add_number = 1;
11833 start_noreorder ();
11834 macro_build (NULL, dbl ? "ddiv" : "div", "0,x,y", xreg, yreg);
11835 expr1.X_add_number = 2;
11836 macro_build (&expr1, "bnez", "x,p", yreg);
11837 macro_build (NULL, "break", "6", 7);
11839 /* FIXME: The normal code checks for of -1 / -0x80000000 here,
11840 since that causes an overflow. We should do that as well,
11841 but I don't see how to do the comparisons without a temporary
11844 macro_build (NULL, s, "x", zreg);
11863 start_noreorder ();
11864 macro_build (NULL, s, "0,x,y", xreg, yreg);
11865 expr1.X_add_number = 2;
11866 macro_build (&expr1, "bnez", "x,p", yreg);
11867 macro_build (NULL, "break", "6", 7);
11869 macro_build (NULL, s2, "x", zreg);
11875 macro_build (NULL, dbl ? "dmultu" : "multu", "x,y", xreg, yreg);
11876 macro_build (NULL, "mflo", "x", zreg);
11884 if (imm_expr.X_op != O_constant)
11885 as_bad (_("Unsupported large constant"));
11886 imm_expr.X_add_number = -imm_expr.X_add_number;
11887 macro_build (&imm_expr, dbl ? "daddiu" : "addiu", "y,x,4", yreg, xreg);
11891 if (imm_expr.X_op != O_constant)
11892 as_bad (_("Unsupported large constant"));
11893 imm_expr.X_add_number = -imm_expr.X_add_number;
11894 macro_build (&imm_expr, "addiu", "x,k", xreg);
11898 if (imm_expr.X_op != O_constant)
11899 as_bad (_("Unsupported large constant"));
11900 imm_expr.X_add_number = -imm_expr.X_add_number;
11901 macro_build (&imm_expr, "daddiu", "y,j", yreg);
11923 goto do_reverse_branch;
11927 goto do_reverse_branch;
11939 goto do_reverse_branch;
11950 macro_build (NULL, s, "x,y", xreg, yreg);
11951 macro_build (&offset_expr, s2, "p");
11978 goto do_addone_branch_i;
11983 goto do_addone_branch_i;
11998 goto do_addone_branch_i;
12004 do_addone_branch_i:
12005 if (imm_expr.X_op != O_constant)
12006 as_bad (_("Unsupported large constant"));
12007 ++imm_expr.X_add_number;
12010 macro_build (&imm_expr, s, s3, xreg);
12011 macro_build (&offset_expr, s2, "p");
12015 expr1.X_add_number = 0;
12016 macro_build (&expr1, "slti", "x,8", yreg);
12018 move_register (xreg, yreg);
12019 expr1.X_add_number = 2;
12020 macro_build (&expr1, "bteqz", "p");
12021 macro_build (NULL, "neg", "x,w", xreg, xreg);
12025 /* Assemble an instruction into its binary format. If the instruction
12026 is a macro, set imm_expr, imm2_expr and offset_expr to the values
12027 associated with "I", "+I" and "A" operands respectively. Otherwise
12028 store the value of the relocatable field (if any) in offset_expr.
12029 In both cases set offset_reloc to the relocation operators applied
12033 mips_ip (char *str, struct mips_cl_insn *ip)
12035 bfd_boolean wrong_delay_slot_insns = FALSE;
12036 bfd_boolean need_delay_slot_ok = TRUE;
12037 struct mips_opcode *firstinsn = NULL;
12038 const struct mips_opcode *past;
12039 struct hash_control *hash;
12042 struct mips_opcode *insn;
12048 const struct mips_operand *operand;
12049 struct mips_arg_info arg;
12050 struct mips_operand_token *tokens;
12051 bfd_boolean optional_reg;
12055 if (mips_opts.micromips)
12057 hash = micromips_op_hash;
12058 past = µmips_opcodes[bfd_micromips_num_opcodes];
12063 past = &mips_opcodes[NUMOPCODES];
12065 forced_insn_length = 0;
12068 /* We first try to match an instruction up to a space or to the end. */
12069 for (end = 0; str[end] != '\0' && !ISSPACE (str[end]); end++)
12072 /* Make a copy of the instruction so that we can fiddle with it. */
12073 name = alloca (end + 1);
12074 memcpy (name, str, end);
12079 insn = (struct mips_opcode *) hash_find (hash, name);
12081 if (insn != NULL || !mips_opts.micromips)
12083 if (forced_insn_length)
12086 /* See if there's an instruction size override suffix,
12087 either `16' or `32', at the end of the mnemonic proper,
12088 that defines the operation, i.e. before the first `.'
12089 character if any. Strip it and retry. */
12090 dot = strchr (name, '.');
12091 opend = dot != NULL ? dot - name : end;
12094 if (name[opend - 2] == '1' && name[opend - 1] == '6')
12095 forced_insn_length = 2;
12096 else if (name[opend - 2] == '3' && name[opend - 1] == '2')
12097 forced_insn_length = 4;
12100 memcpy (name + opend - 2, name + opend, end - opend + 1);
12104 insn_error = _("Unrecognized opcode");
12108 if (strcmp (name, "li.s") == 0)
12110 else if (strcmp (name, "li.d") == 0)
12114 tokens = mips_parse_arguments (str + end, format);
12118 /* For microMIPS instructions placed in a fixed-length branch delay slot
12119 we make up to two passes over the relevant fragment of the opcode
12120 table. First we try instructions that meet the delay slot's length
12121 requirement. If none matched, then we retry with the remaining ones
12122 and if one matches, then we use it and then issue an appropriate
12123 warning later on. */
12126 bfd_boolean delay_slot_ok;
12127 bfd_boolean size_ok;
12129 bfd_boolean more_alts;
12131 gas_assert (strcmp (insn->name, name) == 0);
12133 ok = is_opcode_valid (insn);
12134 size_ok = is_size_valid (insn);
12135 delay_slot_ok = is_delay_slot_valid (insn);
12136 if (!delay_slot_ok && !wrong_delay_slot_insns)
12139 wrong_delay_slot_insns = TRUE;
12141 more_alts = (insn + 1 < past
12142 && strcmp (insn[0].name, insn[1].name) == 0);
12143 if (!ok || !size_ok || delay_slot_ok != need_delay_slot_ok)
12145 static char buf[256];
12152 if (wrong_delay_slot_insns && need_delay_slot_ok)
12154 gas_assert (firstinsn);
12155 need_delay_slot_ok = FALSE;
12161 obstack_free (&mips_operand_tokens, tokens);
12166 sprintf (buf, _("Opcode not supported on this processor: %s (%s)"),
12167 mips_cpu_info_from_arch (mips_opts.arch)->name,
12168 mips_cpu_info_from_isa (mips_opts.isa)->name);
12169 else if (mips_opts.insn32)
12170 sprintf (buf, _("Opcode not supported in the `insn32' mode"));
12172 sprintf (buf, _("Unrecognized %u-bit version of microMIPS opcode"),
12173 8 * forced_insn_length);
12179 imm_expr.X_op = O_absent;
12180 imm2_expr.X_op = O_absent;
12181 offset_expr.X_op = O_absent;
12182 offset_reloc[0] = BFD_RELOC_UNUSED;
12183 offset_reloc[1] = BFD_RELOC_UNUSED;
12184 offset_reloc[2] = BFD_RELOC_UNUSED;
12186 create_insn (ip, insn);
12188 memset (&arg, 0, sizeof (arg));
12190 arg.token = tokens;
12192 arg.last_regno = ILLEGAL_REG;
12193 arg.dest_regno = ILLEGAL_REG;
12194 arg.soft_match = (more_alts
12195 || (wrong_delay_slot_insns && need_delay_slot_ok));
12196 for (args = insn->args;; ++args)
12198 if (arg.token->type == OT_END)
12200 /* Handle unary instructions in which only one operand is given.
12201 The source is then the same as the destination. */
12202 if (arg.opnum == 1 && *args == ',')
12210 arg.token = tokens;
12215 /* Treat elided base registers as $0. */
12216 if (strcmp (args, "(b)") == 0)
12219 /* Fail the match if there were too few operands. */
12223 /* Successful match. */
12224 if (arg.dest_regno == arg.last_regno
12225 && strncmp (ip->insn_mo->name, "jalr", 4) == 0)
12227 if (arg.opnum == 2)
12228 as_bad (_("Source and destination must be different"));
12229 else if (arg.last_regno == 31)
12230 as_bad (_("A destination register must be supplied"));
12232 check_completed_insn (&arg);
12233 obstack_free (&mips_operand_tokens, tokens);
12237 /* Fail the match if the line has too many operands. */
12241 /* Handle characters that need to match exactly. */
12242 if (*args == '(' || *args == ')' || *args == ',')
12244 if (match_char (&arg, *args))
12249 /* Handle special macro operands. Work out the properties of
12252 arg.lax_max = FALSE;
12253 optional_reg = FALSE;
12272 /* If these integer forms come last, there is no other
12273 form of the instruction that could match. Prefer to
12274 give detailed error messages where possible. */
12276 arg.soft_match = FALSE;
12280 /* "+I" is like "I", except that imm2_expr is used. */
12281 if (match_const_int (&arg, &imm2_expr.X_add_number, 0))
12282 imm2_expr.X_op = O_constant;
12284 insn_error = _("absolute expression required");
12285 if (HAVE_32BIT_GPRS)
12286 normalize_constant_expr (&imm2_expr);
12291 *offset_reloc = BFD_RELOC_MIPS_JMP;
12321 /* If these integer forms come last, there is no other
12322 form of the instruction that could match. Prefer to
12323 give detailed error messages where possible. */
12325 arg.soft_match = FALSE;
12333 /* We have already matched a comma by this point, so the register
12334 is only optional if there is another operand to come. */
12335 gas_assert (arg.opnum == 2);
12336 optional_reg = (args[1] == ',');
12340 if (match_const_int (&arg, &imm_expr.X_add_number, 0))
12341 imm_expr.X_op = O_constant;
12343 insn_error = _("absolute expression required");
12344 if (HAVE_32BIT_GPRS)
12345 normalize_constant_expr (&imm_expr);
12349 if (arg.token->type == OT_CHAR && arg.token->u.ch == '(')
12351 /* Assume that the offset has been elided and that what
12352 we saw was a base register. The match will fail later
12353 if that assumption turns out to be wrong. */
12354 offset_expr.X_op = O_constant;
12355 offset_expr.X_add_number = 0;
12357 else if (match_expression (&arg, &offset_expr, offset_reloc))
12358 normalize_address_expr (&offset_expr);
12360 insn_error = _("absolute expression required");
12364 if (!match_float_constant (&arg, &imm_expr, &offset_expr,
12366 insn_error = _("floating-point expression required");
12370 if (!match_float_constant (&arg, &imm_expr, &offset_expr,
12372 insn_error = _("floating-point expression required");
12376 if (!match_float_constant (&arg, &imm_expr, &offset_expr,
12378 insn_error = _("floating-point expression required");
12382 if (!match_float_constant (&arg, &imm_expr, &offset_expr,
12384 insn_error = _("floating-point expression required");
12387 /* ??? This is the traditional behavior, but is flaky if
12388 there are alternative versions of the same instruction
12389 for different subarchitectures. The next alternative
12390 might not be suitable. */
12392 /* For compatibility with older assemblers, we accept
12393 0x8000-0xffff as signed 16-bit numbers when only
12394 signed numbers are allowed. */
12395 arg.lax_max = !more_alts;
12397 /* Only accept non-constant operands if this is the
12398 final alternative. Later alternatives might include
12399 a macro implementation. */
12400 arg.allow_nonconst = !more_alts;
12404 /* There are no macro implementations for out-of-range values. */
12405 arg.allow_nonconst = TRUE;
12409 /* There should always be a macro implementation. */
12410 arg.allow_nonconst = FALSE;
12414 *offset_reloc = BFD_RELOC_16_PCREL_S2;
12418 *offset_reloc = BFD_RELOC_MIPS_JMP;
12422 gas_assert (mips_opts.micromips);
12429 /* We have already matched a comma by this point,
12430 so the register is only optional if there is another
12431 operand to come. */
12432 gas_assert (arg.opnum == 2);
12433 optional_reg = (args[2] == ',');
12438 if (!forced_insn_length)
12439 *offset_reloc = (int) BFD_RELOC_UNUSED + c;
12441 *offset_reloc = BFD_RELOC_MICROMIPS_10_PCREL_S1;
12443 *offset_reloc = BFD_RELOC_MICROMIPS_7_PCREL_S1;
12449 operand = (mips_opts.micromips
12450 ? decode_micromips_operand (args)
12451 : decode_mips_operand (args));
12456 && (arg.token[0].type != OT_REG
12457 || arg.token[1].type == OT_END))
12459 /* Assume that the register has been elided and is the
12460 same as the first operand. */
12461 arg.token = tokens;
12465 if (!match_operand (&arg, operand))
12468 /* Skip prefixes. */
12469 if (*args == '+' || *args == 'm')
12474 /* Args don't match. */
12475 insn_error = _("Illegal operands");
12481 if (wrong_delay_slot_insns && need_delay_slot_ok)
12483 gas_assert (firstinsn);
12484 need_delay_slot_ok = FALSE;
12489 obstack_free (&mips_operand_tokens, tokens);
12494 /* As for mips_ip, but used when assembling MIPS16 code.
12495 Also set forced_insn_length to the resulting instruction size in
12496 bytes if the user explicitly requested a small or extended instruction. */
12499 mips16_ip (char *str, struct mips_cl_insn *ip)
12503 struct mips_opcode *insn;
12504 const struct mips_operand *operand;
12505 const struct mips_operand *ext_operand;
12506 struct mips_arg_info arg;
12507 struct mips_operand_token *tokens;
12508 bfd_boolean optional_reg;
12512 forced_insn_length = 0;
12514 for (s = str; ISLOWER (*s); ++s)
12526 if (s[1] == 't' && s[2] == ' ')
12529 forced_insn_length = 2;
12533 else if (s[1] == 'e' && s[2] == ' ')
12536 forced_insn_length = 4;
12540 /* Fall through. */
12542 insn_error = _("unknown opcode");
12546 if (mips_opts.noautoextend && !forced_insn_length)
12547 forced_insn_length = 2;
12549 if ((insn = (struct mips_opcode *) hash_find (mips16_op_hash, str)) == NULL)
12551 insn_error = _("unrecognized opcode");
12555 tokens = mips_parse_arguments (s, 0);
12562 bfd_boolean more_alts;
12565 gas_assert (strcmp (insn->name, str) == 0);
12567 ok = is_opcode_valid_16 (insn);
12568 more_alts = (insn + 1 < &mips16_opcodes[bfd_mips16_num_opcodes]
12569 && strcmp (insn[0].name, insn[1].name) == 0);
12581 static char buf[100];
12583 _("Opcode not supported on this processor: %s (%s)"),
12584 mips_cpu_info_from_arch (mips_opts.arch)->name,
12585 mips_cpu_info_from_isa (mips_opts.isa)->name);
12588 obstack_free (&mips_operand_tokens, tokens);
12593 create_insn (ip, insn);
12594 imm_expr.X_op = O_absent;
12595 imm2_expr.X_op = O_absent;
12596 offset_expr.X_op = O_absent;
12597 offset_reloc[0] = BFD_RELOC_UNUSED;
12598 offset_reloc[1] = BFD_RELOC_UNUSED;
12599 offset_reloc[2] = BFD_RELOC_UNUSED;
12602 memset (&arg, 0, sizeof (arg));
12604 arg.token = tokens;
12606 arg.last_regno = ILLEGAL_REG;
12607 arg.dest_regno = ILLEGAL_REG;
12608 arg.soft_match = more_alts;
12610 for (args = insn->args; 1; ++args)
12614 if (arg.token->type == OT_END)
12618 /* Handle unary instructions in which only one operand is given.
12619 The source is then the same as the destination. */
12620 if (arg.opnum == 1 && *args == ',')
12625 arg.token = tokens;
12630 /* Fail the match if there were too few operands. */
12634 /* Successful match. Stuff the immediate value in now, if
12636 if (insn->pinfo == INSN_MACRO)
12638 gas_assert (relax_char == 0);
12639 gas_assert (*offset_reloc == BFD_RELOC_UNUSED);
12641 else if (relax_char
12642 && offset_expr.X_op == O_constant
12643 && calculate_reloc (*offset_reloc,
12644 offset_expr.X_add_number,
12647 mips16_immed (NULL, 0, relax_char, *offset_reloc, value,
12648 forced_insn_length, &ip->insn_opcode);
12649 offset_expr.X_op = O_absent;
12650 *offset_reloc = BFD_RELOC_UNUSED;
12652 else if (relax_char && *offset_reloc != BFD_RELOC_UNUSED)
12654 if (forced_insn_length == 2)
12655 as_bad (_("invalid unextended operand value"));
12656 forced_insn_length = 4;
12657 ip->insn_opcode |= MIPS16_EXTEND;
12659 else if (relax_char)
12660 *offset_reloc = (int) BFD_RELOC_UNUSED + relax_char;
12662 check_completed_insn (&arg);
12663 obstack_free (&mips_operand_tokens, tokens);
12667 /* Fail the match if the line has too many operands. */
12671 /* Handle characters that need to match exactly. */
12672 if (*args == '(' || *args == ')' || *args == ',')
12674 if (match_char (&arg, *args))
12680 optional_reg = FALSE;
12686 optional_reg = (args[1] == ',');
12698 if (match_const_int (&arg, &imm_expr.X_add_number, 0))
12699 imm_expr.X_op = O_constant;
12701 insn_error = _("absolute expression required");
12702 if (HAVE_32BIT_GPRS)
12703 normalize_constant_expr (&imm_expr);
12708 *offset_reloc = BFD_RELOC_MIPS16_JMP;
12709 ip->insn_opcode <<= 16;
12713 operand = decode_mips16_operand (c, FALSE);
12717 /* '6' is a special case. It is used for BREAK and SDBBP,
12718 whose operands are only meaningful to the software that decodes
12719 them. This means that there is no architectural reason why
12720 they cannot be prefixed by EXTEND, but in practice,
12721 exception handlers will only look at the instruction
12722 itself. We therefore allow '6' to be extended when
12723 disassembling but not when assembling. */
12724 if (operand->type != OP_PCREL && c != '6')
12726 ext_operand = decode_mips16_operand (c, TRUE);
12727 if (operand != ext_operand)
12729 if (arg.token->type == OT_CHAR && arg.token->u.ch == '(')
12731 offset_expr.X_op = O_constant;
12732 offset_expr.X_add_number = 0;
12737 /* We need the OT_INTEGER check because some MIPS16
12738 immediate variants are listed before the register ones. */
12739 if (arg.token->type != OT_INTEGER
12740 || !match_expression (&arg, &offset_expr, offset_reloc))
12743 /* '8' is used for SLTI(U) and has traditionally not
12744 been allowed to take relocation operators. */
12745 if (offset_reloc[0] != BFD_RELOC_UNUSED
12746 && (ext_operand->size != 16 || c == '8'))
12755 && (arg.token[0].type != OT_REG
12756 || arg.token[1].type == OT_END))
12758 /* Assume that the register has been elided and is the
12759 same as the first operand. */
12760 arg.token = tokens;
12764 if (!match_operand (&arg, operand))
12769 /* Args don't match. */
12776 insn_error = _("illegal operands");
12778 obstack_free (&mips_operand_tokens, tokens);
12783 /* This structure holds information we know about a mips16 immediate
12786 struct mips16_immed_operand
12788 /* The type code used in the argument string in the opcode table. */
12790 /* The number of bits in the short form of the opcode. */
12792 /* The number of bits in the extended form of the opcode. */
12794 /* The amount by which the short form is shifted when it is used;
12795 for example, the sw instruction has a shift count of 2. */
12797 /* The amount by which the short form is shifted when it is stored
12798 into the instruction code. */
12800 /* Non-zero if the short form is unsigned. */
12802 /* Non-zero if the extended form is unsigned. */
12804 /* Non-zero if the value is PC relative. */
12808 /* The mips16 immediate operand types. */
12810 static const struct mips16_immed_operand mips16_immed_operands[] =
12812 { '<', 3, 5, 0, MIPS16OP_SH_RZ, 1, 1, 0 },
12813 { '>', 3, 5, 0, MIPS16OP_SH_RX, 1, 1, 0 },
12814 { '[', 3, 6, 0, MIPS16OP_SH_RZ, 1, 1, 0 },
12815 { ']', 3, 6, 0, MIPS16OP_SH_RX, 1, 1, 0 },
12816 { '4', 4, 15, 0, MIPS16OP_SH_IMM4, 0, 0, 0 },
12817 { '5', 5, 16, 0, MIPS16OP_SH_IMM5, 1, 0, 0 },
12818 { 'H', 5, 16, 1, MIPS16OP_SH_IMM5, 1, 0, 0 },
12819 { 'W', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 0 },
12820 { 'D', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 0 },
12821 { 'j', 5, 16, 0, MIPS16OP_SH_IMM5, 0, 0, 0 },
12822 { '8', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 0, 0 },
12823 { 'V', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 0 },
12824 { 'C', 8, 16, 3, MIPS16OP_SH_IMM8, 1, 0, 0 },
12825 { 'U', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 1, 0 },
12826 { 'k', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 0 },
12827 { 'K', 8, 16, 3, MIPS16OP_SH_IMM8, 0, 0, 0 },
12828 { 'p', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 },
12829 { 'q', 11, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 },
12830 { 'A', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 1 },
12831 { 'B', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 1 },
12832 { 'E', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 1 }
12835 #define MIPS16_NUM_IMMED \
12836 (sizeof mips16_immed_operands / sizeof mips16_immed_operands[0])
12838 /* Marshal immediate value VAL for an extended MIPS16 instruction.
12839 NBITS is the number of significant bits in VAL. */
12841 static unsigned long
12842 mips16_immed_extend (offsetT val, unsigned int nbits)
12847 extval = ((val >> 11) & 0x1f) | (val & 0x7e0);
12850 else if (nbits == 15)
12852 extval = ((val >> 11) & 0xf) | (val & 0x7f0);
12857 extval = ((val & 0x1f) << 6) | (val & 0x20);
12860 return (extval << 16) | val;
12863 /* Install immediate value VAL into MIPS16 instruction *INSN,
12864 extending it if necessary. The instruction in *INSN may
12865 already be extended.
12867 RELOC is the relocation that produced VAL, or BFD_RELOC_UNUSED
12868 if none. In the former case, VAL is a 16-bit number with no
12869 defined signedness.
12871 TYPE is the type of the immediate field. USER_INSN_LENGTH
12872 is the length that the user requested, or 0 if none. */
12875 mips16_immed (char *file, unsigned int line, int type,
12876 bfd_reloc_code_real_type reloc, offsetT val,
12877 unsigned int user_insn_length, unsigned long *insn)
12879 const struct mips16_immed_operand *op;
12880 int mintiny, maxtiny;
12882 op = mips16_immed_operands;
12883 while (op->type != type)
12886 gas_assert (op < mips16_immed_operands + MIPS16_NUM_IMMED);
12891 if (type == '<' || type == '>' || type == '[' || type == ']')
12894 maxtiny = 1 << op->nbits;
12899 maxtiny = (1 << op->nbits) - 1;
12901 if (reloc != BFD_RELOC_UNUSED)
12906 mintiny = - (1 << (op->nbits - 1));
12907 maxtiny = (1 << (op->nbits - 1)) - 1;
12908 if (reloc != BFD_RELOC_UNUSED)
12909 val = SEXT_16BIT (val);
12912 /* Branch offsets have an implicit 0 in the lowest bit. */
12913 if (type == 'p' || type == 'q')
12916 if ((val & ((1 << op->shift) - 1)) != 0
12917 || val < (mintiny << op->shift)
12918 || val > (maxtiny << op->shift))
12920 /* We need an extended instruction. */
12921 if (user_insn_length == 2)
12922 as_bad_where (file, line, _("invalid unextended operand value"));
12924 *insn |= MIPS16_EXTEND;
12926 else if (user_insn_length == 4)
12928 /* The operand doesn't force an unextended instruction to be extended.
12929 Warn if the user wanted an extended instruction anyway. */
12930 *insn |= MIPS16_EXTEND;
12931 as_warn_where (file, line,
12932 _("extended operand requested but not required"));
12935 if (mips16_opcode_length (*insn) == 2)
12939 insnval = ((val >> op->shift) & ((1 << op->nbits) - 1));
12940 insnval <<= op->op_shift;
12945 long minext, maxext;
12947 if (reloc == BFD_RELOC_UNUSED)
12952 maxext = (1 << op->extbits) - 1;
12956 minext = - (1 << (op->extbits - 1));
12957 maxext = (1 << (op->extbits - 1)) - 1;
12959 if (val < minext || val > maxext)
12960 as_bad_where (file, line,
12961 _("operand value out of range for instruction"));
12964 *insn |= mips16_immed_extend (val, op->extbits);
12968 struct percent_op_match
12971 bfd_reloc_code_real_type reloc;
12974 static const struct percent_op_match mips_percent_op[] =
12976 {"%lo", BFD_RELOC_LO16},
12977 {"%call_hi", BFD_RELOC_MIPS_CALL_HI16},
12978 {"%call_lo", BFD_RELOC_MIPS_CALL_LO16},
12979 {"%call16", BFD_RELOC_MIPS_CALL16},
12980 {"%got_disp", BFD_RELOC_MIPS_GOT_DISP},
12981 {"%got_page", BFD_RELOC_MIPS_GOT_PAGE},
12982 {"%got_ofst", BFD_RELOC_MIPS_GOT_OFST},
12983 {"%got_hi", BFD_RELOC_MIPS_GOT_HI16},
12984 {"%got_lo", BFD_RELOC_MIPS_GOT_LO16},
12985 {"%got", BFD_RELOC_MIPS_GOT16},
12986 {"%gp_rel", BFD_RELOC_GPREL16},
12987 {"%half", BFD_RELOC_16},
12988 {"%highest", BFD_RELOC_MIPS_HIGHEST},
12989 {"%higher", BFD_RELOC_MIPS_HIGHER},
12990 {"%neg", BFD_RELOC_MIPS_SUB},
12991 {"%tlsgd", BFD_RELOC_MIPS_TLS_GD},
12992 {"%tlsldm", BFD_RELOC_MIPS_TLS_LDM},
12993 {"%dtprel_hi", BFD_RELOC_MIPS_TLS_DTPREL_HI16},
12994 {"%dtprel_lo", BFD_RELOC_MIPS_TLS_DTPREL_LO16},
12995 {"%tprel_hi", BFD_RELOC_MIPS_TLS_TPREL_HI16},
12996 {"%tprel_lo", BFD_RELOC_MIPS_TLS_TPREL_LO16},
12997 {"%gottprel", BFD_RELOC_MIPS_TLS_GOTTPREL},
12998 {"%hi", BFD_RELOC_HI16_S}
13001 static const struct percent_op_match mips16_percent_op[] =
13003 {"%lo", BFD_RELOC_MIPS16_LO16},
13004 {"%gprel", BFD_RELOC_MIPS16_GPREL},
13005 {"%got", BFD_RELOC_MIPS16_GOT16},
13006 {"%call16", BFD_RELOC_MIPS16_CALL16},
13007 {"%hi", BFD_RELOC_MIPS16_HI16_S},
13008 {"%tlsgd", BFD_RELOC_MIPS16_TLS_GD},
13009 {"%tlsldm", BFD_RELOC_MIPS16_TLS_LDM},
13010 {"%dtprel_hi", BFD_RELOC_MIPS16_TLS_DTPREL_HI16},
13011 {"%dtprel_lo", BFD_RELOC_MIPS16_TLS_DTPREL_LO16},
13012 {"%tprel_hi", BFD_RELOC_MIPS16_TLS_TPREL_HI16},
13013 {"%tprel_lo", BFD_RELOC_MIPS16_TLS_TPREL_LO16},
13014 {"%gottprel", BFD_RELOC_MIPS16_TLS_GOTTPREL}
13018 /* Return true if *STR points to a relocation operator. When returning true,
13019 move *STR over the operator and store its relocation code in *RELOC.
13020 Leave both *STR and *RELOC alone when returning false. */
13023 parse_relocation (char **str, bfd_reloc_code_real_type *reloc)
13025 const struct percent_op_match *percent_op;
13028 if (mips_opts.mips16)
13030 percent_op = mips16_percent_op;
13031 limit = ARRAY_SIZE (mips16_percent_op);
13035 percent_op = mips_percent_op;
13036 limit = ARRAY_SIZE (mips_percent_op);
13039 for (i = 0; i < limit; i++)
13040 if (strncasecmp (*str, percent_op[i].str, strlen (percent_op[i].str)) == 0)
13042 int len = strlen (percent_op[i].str);
13044 if (!ISSPACE ((*str)[len]) && (*str)[len] != '(')
13047 *str += strlen (percent_op[i].str);
13048 *reloc = percent_op[i].reloc;
13050 /* Check whether the output BFD supports this relocation.
13051 If not, issue an error and fall back on something safe. */
13052 if (!bfd_reloc_type_lookup (stdoutput, percent_op[i].reloc))
13054 as_bad (_("relocation %s isn't supported by the current ABI"),
13055 percent_op[i].str);
13056 *reloc = BFD_RELOC_UNUSED;
13064 /* Parse string STR as a 16-bit relocatable operand. Store the
13065 expression in *EP and the relocations in the array starting
13066 at RELOC. Return the number of relocation operators used.
13068 On exit, EXPR_END points to the first character after the expression. */
13071 my_getSmallExpression (expressionS *ep, bfd_reloc_code_real_type *reloc,
13074 bfd_reloc_code_real_type reversed_reloc[3];
13075 size_t reloc_index, i;
13076 int crux_depth, str_depth;
13079 /* Search for the start of the main expression, recoding relocations
13080 in REVERSED_RELOC. End the loop with CRUX pointing to the start
13081 of the main expression and with CRUX_DEPTH containing the number
13082 of open brackets at that point. */
13089 crux_depth = str_depth;
13091 /* Skip over whitespace and brackets, keeping count of the number
13093 while (*str == ' ' || *str == '\t' || *str == '(')
13098 && reloc_index < (HAVE_NEWABI ? 3 : 1)
13099 && parse_relocation (&str, &reversed_reloc[reloc_index]));
13101 my_getExpression (ep, crux);
13104 /* Match every open bracket. */
13105 while (crux_depth > 0 && (*str == ')' || *str == ' ' || *str == '\t'))
13109 if (crux_depth > 0)
13110 as_bad (_("unclosed '('"));
13114 if (reloc_index != 0)
13116 prev_reloc_op_frag = frag_now;
13117 for (i = 0; i < reloc_index; i++)
13118 reloc[i] = reversed_reloc[reloc_index - 1 - i];
13121 return reloc_index;
13125 my_getExpression (expressionS *ep, char *str)
13129 save_in = input_line_pointer;
13130 input_line_pointer = str;
13132 expr_end = input_line_pointer;
13133 input_line_pointer = save_in;
13137 md_atof (int type, char *litP, int *sizeP)
13139 return ieee_md_atof (type, litP, sizeP, target_big_endian);
13143 md_number_to_chars (char *buf, valueT val, int n)
13145 if (target_big_endian)
13146 number_to_chars_bigendian (buf, val, n);
13148 number_to_chars_littleendian (buf, val, n);
13151 static int support_64bit_objects(void)
13153 const char **list, **l;
13156 list = bfd_target_list ();
13157 for (l = list; *l != NULL; l++)
13158 if (strcmp (*l, ELF_TARGET ("elf64-", "big")) == 0
13159 || strcmp (*l, ELF_TARGET ("elf64-", "little")) == 0)
13161 yes = (*l != NULL);
13166 /* Set STRING_PTR (either &mips_arch_string or &mips_tune_string) to
13167 NEW_VALUE. Warn if another value was already specified. Note:
13168 we have to defer parsing the -march and -mtune arguments in order
13169 to handle 'from-abi' correctly, since the ABI might be specified
13170 in a later argument. */
13173 mips_set_option_string (const char **string_ptr, const char *new_value)
13175 if (*string_ptr != 0 && strcasecmp (*string_ptr, new_value) != 0)
13176 as_warn (_("A different %s was already specified, is now %s"),
13177 string_ptr == &mips_arch_string ? "-march" : "-mtune",
13180 *string_ptr = new_value;
13184 md_parse_option (int c, char *arg)
13188 for (i = 0; i < ARRAY_SIZE (mips_ases); i++)
13189 if (c == mips_ases[i].option_on || c == mips_ases[i].option_off)
13191 file_ase_explicit |= mips_set_ase (&mips_ases[i],
13192 c == mips_ases[i].option_on);
13198 case OPTION_CONSTRUCT_FLOATS:
13199 mips_disable_float_construction = 0;
13202 case OPTION_NO_CONSTRUCT_FLOATS:
13203 mips_disable_float_construction = 1;
13215 target_big_endian = 1;
13219 target_big_endian = 0;
13225 else if (arg[0] == '0')
13227 else if (arg[0] == '1')
13237 mips_debug = atoi (arg);
13241 file_mips_isa = ISA_MIPS1;
13245 file_mips_isa = ISA_MIPS2;
13249 file_mips_isa = ISA_MIPS3;
13253 file_mips_isa = ISA_MIPS4;
13257 file_mips_isa = ISA_MIPS5;
13260 case OPTION_MIPS32:
13261 file_mips_isa = ISA_MIPS32;
13264 case OPTION_MIPS32R2:
13265 file_mips_isa = ISA_MIPS32R2;
13268 case OPTION_MIPS64R2:
13269 file_mips_isa = ISA_MIPS64R2;
13272 case OPTION_MIPS64:
13273 file_mips_isa = ISA_MIPS64;
13277 mips_set_option_string (&mips_tune_string, arg);
13281 mips_set_option_string (&mips_arch_string, arg);
13285 mips_set_option_string (&mips_arch_string, "4650");
13286 mips_set_option_string (&mips_tune_string, "4650");
13289 case OPTION_NO_M4650:
13293 mips_set_option_string (&mips_arch_string, "4010");
13294 mips_set_option_string (&mips_tune_string, "4010");
13297 case OPTION_NO_M4010:
13301 mips_set_option_string (&mips_arch_string, "4100");
13302 mips_set_option_string (&mips_tune_string, "4100");
13305 case OPTION_NO_M4100:
13309 mips_set_option_string (&mips_arch_string, "3900");
13310 mips_set_option_string (&mips_tune_string, "3900");
13313 case OPTION_NO_M3900:
13316 case OPTION_MICROMIPS:
13317 if (mips_opts.mips16 == 1)
13319 as_bad (_("-mmicromips cannot be used with -mips16"));
13322 mips_opts.micromips = 1;
13323 mips_no_prev_insn ();
13326 case OPTION_NO_MICROMIPS:
13327 mips_opts.micromips = 0;
13328 mips_no_prev_insn ();
13331 case OPTION_MIPS16:
13332 if (mips_opts.micromips == 1)
13334 as_bad (_("-mips16 cannot be used with -micromips"));
13337 mips_opts.mips16 = 1;
13338 mips_no_prev_insn ();
13341 case OPTION_NO_MIPS16:
13342 mips_opts.mips16 = 0;
13343 mips_no_prev_insn ();
13346 case OPTION_FIX_24K:
13350 case OPTION_NO_FIX_24K:
13354 case OPTION_FIX_LOONGSON2F_JUMP:
13355 mips_fix_loongson2f_jump = TRUE;
13358 case OPTION_NO_FIX_LOONGSON2F_JUMP:
13359 mips_fix_loongson2f_jump = FALSE;
13362 case OPTION_FIX_LOONGSON2F_NOP:
13363 mips_fix_loongson2f_nop = TRUE;
13366 case OPTION_NO_FIX_LOONGSON2F_NOP:
13367 mips_fix_loongson2f_nop = FALSE;
13370 case OPTION_FIX_VR4120:
13371 mips_fix_vr4120 = 1;
13374 case OPTION_NO_FIX_VR4120:
13375 mips_fix_vr4120 = 0;
13378 case OPTION_FIX_VR4130:
13379 mips_fix_vr4130 = 1;
13382 case OPTION_NO_FIX_VR4130:
13383 mips_fix_vr4130 = 0;
13386 case OPTION_FIX_CN63XXP1:
13387 mips_fix_cn63xxp1 = TRUE;
13390 case OPTION_NO_FIX_CN63XXP1:
13391 mips_fix_cn63xxp1 = FALSE;
13394 case OPTION_RELAX_BRANCH:
13395 mips_relax_branch = 1;
13398 case OPTION_NO_RELAX_BRANCH:
13399 mips_relax_branch = 0;
13402 case OPTION_INSN32:
13403 mips_opts.insn32 = TRUE;
13406 case OPTION_NO_INSN32:
13407 mips_opts.insn32 = FALSE;
13410 case OPTION_MSHARED:
13411 mips_in_shared = TRUE;
13414 case OPTION_MNO_SHARED:
13415 mips_in_shared = FALSE;
13418 case OPTION_MSYM32:
13419 mips_opts.sym32 = TRUE;
13422 case OPTION_MNO_SYM32:
13423 mips_opts.sym32 = FALSE;
13426 /* When generating ELF code, we permit -KPIC and -call_shared to
13427 select SVR4_PIC, and -non_shared to select no PIC. This is
13428 intended to be compatible with Irix 5. */
13429 case OPTION_CALL_SHARED:
13430 mips_pic = SVR4_PIC;
13431 mips_abicalls = TRUE;
13434 case OPTION_CALL_NONPIC:
13436 mips_abicalls = TRUE;
13439 case OPTION_NON_SHARED:
13441 mips_abicalls = FALSE;
13444 /* The -xgot option tells the assembler to use 32 bit offsets
13445 when accessing the got in SVR4_PIC mode. It is for Irix
13452 g_switch_value = atoi (arg);
13456 /* The -32, -n32 and -64 options are shortcuts for -mabi=32, -mabi=n32
13459 mips_abi = O32_ABI;
13463 mips_abi = N32_ABI;
13467 mips_abi = N64_ABI;
13468 if (!support_64bit_objects())
13469 as_fatal (_("No compiled in support for 64 bit object file format"));
13473 file_mips_gp32 = 1;
13477 file_mips_gp32 = 0;
13481 file_mips_fp32 = 1;
13485 file_mips_fp32 = 0;
13488 case OPTION_SINGLE_FLOAT:
13489 file_mips_single_float = 1;
13492 case OPTION_DOUBLE_FLOAT:
13493 file_mips_single_float = 0;
13496 case OPTION_SOFT_FLOAT:
13497 file_mips_soft_float = 1;
13500 case OPTION_HARD_FLOAT:
13501 file_mips_soft_float = 0;
13505 if (strcmp (arg, "32") == 0)
13506 mips_abi = O32_ABI;
13507 else if (strcmp (arg, "o64") == 0)
13508 mips_abi = O64_ABI;
13509 else if (strcmp (arg, "n32") == 0)
13510 mips_abi = N32_ABI;
13511 else if (strcmp (arg, "64") == 0)
13513 mips_abi = N64_ABI;
13514 if (! support_64bit_objects())
13515 as_fatal (_("No compiled in support for 64 bit object file "
13518 else if (strcmp (arg, "eabi") == 0)
13519 mips_abi = EABI_ABI;
13522 as_fatal (_("invalid abi -mabi=%s"), arg);
13527 case OPTION_M7000_HILO_FIX:
13528 mips_7000_hilo_fix = TRUE;
13531 case OPTION_MNO_7000_HILO_FIX:
13532 mips_7000_hilo_fix = FALSE;
13535 case OPTION_MDEBUG:
13536 mips_flag_mdebug = TRUE;
13539 case OPTION_NO_MDEBUG:
13540 mips_flag_mdebug = FALSE;
13544 mips_flag_pdr = TRUE;
13547 case OPTION_NO_PDR:
13548 mips_flag_pdr = FALSE;
13551 case OPTION_MVXWORKS_PIC:
13552 mips_pic = VXWORKS_PIC;
13556 if (strcmp (arg, "2008") == 0)
13557 mips_flag_nan2008 = TRUE;
13558 else if (strcmp (arg, "legacy") == 0)
13559 mips_flag_nan2008 = FALSE;
13562 as_fatal (_("Invalid NaN setting -mnan=%s"), arg);
13571 mips_fix_loongson2f = mips_fix_loongson2f_nop || mips_fix_loongson2f_jump;
13576 /* Set up globals to generate code for the ISA or processor
13577 described by INFO. */
13580 mips_set_architecture (const struct mips_cpu_info *info)
13584 file_mips_arch = info->cpu;
13585 mips_opts.arch = info->cpu;
13586 mips_opts.isa = info->isa;
13591 /* Likewise for tuning. */
13594 mips_set_tune (const struct mips_cpu_info *info)
13597 mips_tune = info->cpu;
13602 mips_after_parse_args (void)
13604 const struct mips_cpu_info *arch_info = 0;
13605 const struct mips_cpu_info *tune_info = 0;
13607 /* GP relative stuff not working for PE */
13608 if (strncmp (TARGET_OS, "pe", 2) == 0)
13610 if (g_switch_seen && g_switch_value != 0)
13611 as_bad (_("-G not supported in this configuration."));
13612 g_switch_value = 0;
13615 if (mips_abi == NO_ABI)
13616 mips_abi = MIPS_DEFAULT_ABI;
13618 /* The following code determines the architecture and register size.
13619 Similar code was added to GCC 3.3 (see override_options() in
13620 config/mips/mips.c). The GAS and GCC code should be kept in sync
13621 as much as possible. */
13623 if (mips_arch_string != 0)
13624 arch_info = mips_parse_cpu ("-march", mips_arch_string);
13626 if (file_mips_isa != ISA_UNKNOWN)
13628 /* Handle -mipsN. At this point, file_mips_isa contains the
13629 ISA level specified by -mipsN, while arch_info->isa contains
13630 the -march selection (if any). */
13631 if (arch_info != 0)
13633 /* -march takes precedence over -mipsN, since it is more descriptive.
13634 There's no harm in specifying both as long as the ISA levels
13636 if (file_mips_isa != arch_info->isa)
13637 as_bad (_("-%s conflicts with the other architecture options, which imply -%s"),
13638 mips_cpu_info_from_isa (file_mips_isa)->name,
13639 mips_cpu_info_from_isa (arch_info->isa)->name);
13642 arch_info = mips_cpu_info_from_isa (file_mips_isa);
13645 if (arch_info == 0)
13647 arch_info = mips_parse_cpu ("default CPU", MIPS_CPU_STRING_DEFAULT);
13648 gas_assert (arch_info);
13651 if (ABI_NEEDS_64BIT_REGS (mips_abi) && !ISA_HAS_64BIT_REGS (arch_info->isa))
13652 as_bad (_("-march=%s is not compatible with the selected ABI"),
13655 mips_set_architecture (arch_info);
13657 /* Optimize for file_mips_arch, unless -mtune selects a different processor. */
13658 if (mips_tune_string != 0)
13659 tune_info = mips_parse_cpu ("-mtune", mips_tune_string);
13661 if (tune_info == 0)
13662 mips_set_tune (arch_info);
13664 mips_set_tune (tune_info);
13666 if (file_mips_gp32 >= 0)
13668 /* The user specified the size of the integer registers. Make sure
13669 it agrees with the ABI and ISA. */
13670 if (file_mips_gp32 == 0 && !ISA_HAS_64BIT_REGS (mips_opts.isa))
13671 as_bad (_("-mgp64 used with a 32-bit processor"));
13672 else if (file_mips_gp32 == 1 && ABI_NEEDS_64BIT_REGS (mips_abi))
13673 as_bad (_("-mgp32 used with a 64-bit ABI"));
13674 else if (file_mips_gp32 == 0 && ABI_NEEDS_32BIT_REGS (mips_abi))
13675 as_bad (_("-mgp64 used with a 32-bit ABI"));
13679 /* Infer the integer register size from the ABI and processor.
13680 Restrict ourselves to 32-bit registers if that's all the
13681 processor has, or if the ABI cannot handle 64-bit registers. */
13682 file_mips_gp32 = (ABI_NEEDS_32BIT_REGS (mips_abi)
13683 || !ISA_HAS_64BIT_REGS (mips_opts.isa));
13686 switch (file_mips_fp32)
13690 /* No user specified float register size.
13691 ??? GAS treats single-float processors as though they had 64-bit
13692 float registers (although it complains when double-precision
13693 instructions are used). As things stand, saying they have 32-bit
13694 registers would lead to spurious "register must be even" messages.
13695 So here we assume float registers are never smaller than the
13697 if (file_mips_gp32 == 0)
13698 /* 64-bit integer registers implies 64-bit float registers. */
13699 file_mips_fp32 = 0;
13700 else if ((mips_opts.ase & FP64_ASES)
13701 && ISA_HAS_64BIT_FPRS (mips_opts.isa))
13702 /* -mips3d and -mdmx imply 64-bit float registers, if possible. */
13703 file_mips_fp32 = 0;
13705 /* 32-bit float registers. */
13706 file_mips_fp32 = 1;
13709 /* The user specified the size of the float registers. Check if it
13710 agrees with the ABI and ISA. */
13712 if (!ISA_HAS_64BIT_FPRS (mips_opts.isa))
13713 as_bad (_("-mfp64 used with a 32-bit fpu"));
13714 else if (ABI_NEEDS_32BIT_REGS (mips_abi)
13715 && !ISA_HAS_MXHC1 (mips_opts.isa))
13716 as_warn (_("-mfp64 used with a 32-bit ABI"));
13719 if (ABI_NEEDS_64BIT_REGS (mips_abi))
13720 as_warn (_("-mfp32 used with a 64-bit ABI"));
13724 /* End of GCC-shared inference code. */
13726 /* This flag is set when we have a 64-bit capable CPU but use only
13727 32-bit wide registers. Note that EABI does not use it. */
13728 if (ISA_HAS_64BIT_REGS (mips_opts.isa)
13729 && ((mips_abi == NO_ABI && file_mips_gp32 == 1)
13730 || mips_abi == O32_ABI))
13731 mips_32bitmode = 1;
13733 if (mips_opts.isa == ISA_MIPS1 && mips_trap)
13734 as_bad (_("trap exception not supported at ISA 1"));
13736 /* If the selected architecture includes support for ASEs, enable
13737 generation of code for them. */
13738 if (mips_opts.mips16 == -1)
13739 mips_opts.mips16 = (CPU_HAS_MIPS16 (file_mips_arch)) ? 1 : 0;
13740 if (mips_opts.micromips == -1)
13741 mips_opts.micromips = (CPU_HAS_MICROMIPS (file_mips_arch)) ? 1 : 0;
13743 /* MIPS3D and MDMX require 64-bit FPRs, so -mfp32 should stop those
13744 ASEs from being selected implicitly. */
13745 if (file_mips_fp32 == 1)
13746 file_ase_explicit |= ASE_MIPS3D | ASE_MDMX;
13748 /* If the user didn't explicitly select or deselect a particular ASE,
13749 use the default setting for the CPU. */
13750 mips_opts.ase |= (arch_info->ase & ~file_ase_explicit);
13752 file_mips_isa = mips_opts.isa;
13753 file_ase = mips_opts.ase;
13754 mips_opts.gp32 = file_mips_gp32;
13755 mips_opts.fp32 = file_mips_fp32;
13756 mips_opts.soft_float = file_mips_soft_float;
13757 mips_opts.single_float = file_mips_single_float;
13759 mips_check_isa_supports_ases ();
13761 if (mips_flag_mdebug < 0)
13762 mips_flag_mdebug = 0;
13766 mips_init_after_args (void)
13768 /* initialize opcodes */
13769 bfd_mips_num_opcodes = bfd_mips_num_builtin_opcodes;
13770 mips_opcodes = (struct mips_opcode *) mips_builtin_opcodes;
13774 md_pcrel_from (fixS *fixP)
13776 valueT addr = fixP->fx_where + fixP->fx_frag->fr_address;
13777 switch (fixP->fx_r_type)
13779 case BFD_RELOC_MICROMIPS_7_PCREL_S1:
13780 case BFD_RELOC_MICROMIPS_10_PCREL_S1:
13781 /* Return the address of the delay slot. */
13784 case BFD_RELOC_MICROMIPS_16_PCREL_S1:
13785 case BFD_RELOC_MICROMIPS_JMP:
13786 case BFD_RELOC_16_PCREL_S2:
13787 case BFD_RELOC_MIPS_JMP:
13788 /* Return the address of the delay slot. */
13791 case BFD_RELOC_32_PCREL:
13795 /* We have no relocation type for PC relative MIPS16 instructions. */
13796 if (fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != now_seg)
13797 as_bad_where (fixP->fx_file, fixP->fx_line,
13798 _("PC relative MIPS16 instruction references a different section"));
13803 /* This is called before the symbol table is processed. In order to
13804 work with gcc when using mips-tfile, we must keep all local labels.
13805 However, in other cases, we want to discard them. If we were
13806 called with -g, but we didn't see any debugging information, it may
13807 mean that gcc is smuggling debugging information through to
13808 mips-tfile, in which case we must generate all local labels. */
13811 mips_frob_file_before_adjust (void)
13813 #ifndef NO_ECOFF_DEBUGGING
13814 if (ECOFF_DEBUGGING
13816 && ! ecoff_debugging_seen)
13817 flag_keep_locals = 1;
13821 /* Sort any unmatched HI16 and GOT16 relocs so that they immediately precede
13822 the corresponding LO16 reloc. This is called before md_apply_fix and
13823 tc_gen_reloc. Unmatched relocs can only be generated by use of explicit
13824 relocation operators.
13826 For our purposes, a %lo() expression matches a %got() or %hi()
13829 (a) it refers to the same symbol; and
13830 (b) the offset applied in the %lo() expression is no lower than
13831 the offset applied in the %got() or %hi().
13833 (b) allows us to cope with code like:
13836 lh $4,%lo(foo+2)($4)
13838 ...which is legal on RELA targets, and has a well-defined behaviour
13839 if the user knows that adding 2 to "foo" will not induce a carry to
13842 When several %lo()s match a particular %got() or %hi(), we use the
13843 following rules to distinguish them:
13845 (1) %lo()s with smaller offsets are a better match than %lo()s with
13848 (2) %lo()s with no matching %got() or %hi() are better than those
13849 that already have a matching %got() or %hi().
13851 (3) later %lo()s are better than earlier %lo()s.
13853 These rules are applied in order.
13855 (1) means, among other things, that %lo()s with identical offsets are
13856 chosen if they exist.
13858 (2) means that we won't associate several high-part relocations with
13859 the same low-part relocation unless there's no alternative. Having
13860 several high parts for the same low part is a GNU extension; this rule
13861 allows careful users to avoid it.
13863 (3) is purely cosmetic. mips_hi_fixup_list is is in reverse order,
13864 with the last high-part relocation being at the front of the list.
13865 It therefore makes sense to choose the last matching low-part
13866 relocation, all other things being equal. It's also easier
13867 to code that way. */
13870 mips_frob_file (void)
13872 struct mips_hi_fixup *l;
13873 bfd_reloc_code_real_type looking_for_rtype = BFD_RELOC_UNUSED;
13875 for (l = mips_hi_fixup_list; l != NULL; l = l->next)
13877 segment_info_type *seginfo;
13878 bfd_boolean matched_lo_p;
13879 fixS **hi_pos, **lo_pos, **pos;
13881 gas_assert (reloc_needs_lo_p (l->fixp->fx_r_type));
13883 /* If a GOT16 relocation turns out to be against a global symbol,
13884 there isn't supposed to be a matching LO. Ignore %gots against
13885 constants; we'll report an error for those later. */
13886 if (got16_reloc_p (l->fixp->fx_r_type)
13887 && !(l->fixp->fx_addsy
13888 && pic_need_relax (l->fixp->fx_addsy, l->seg)))
13891 /* Check quickly whether the next fixup happens to be a matching %lo. */
13892 if (fixup_has_matching_lo_p (l->fixp))
13895 seginfo = seg_info (l->seg);
13897 /* Set HI_POS to the position of this relocation in the chain.
13898 Set LO_POS to the position of the chosen low-part relocation.
13899 MATCHED_LO_P is true on entry to the loop if *POS is a low-part
13900 relocation that matches an immediately-preceding high-part
13904 matched_lo_p = FALSE;
13905 looking_for_rtype = matching_lo_reloc (l->fixp->fx_r_type);
13907 for (pos = &seginfo->fix_root; *pos != NULL; pos = &(*pos)->fx_next)
13909 if (*pos == l->fixp)
13912 if ((*pos)->fx_r_type == looking_for_rtype
13913 && symbol_same_p ((*pos)->fx_addsy, l->fixp->fx_addsy)
13914 && (*pos)->fx_offset >= l->fixp->fx_offset
13916 || (*pos)->fx_offset < (*lo_pos)->fx_offset
13918 && (*pos)->fx_offset == (*lo_pos)->fx_offset)))
13921 matched_lo_p = (reloc_needs_lo_p ((*pos)->fx_r_type)
13922 && fixup_has_matching_lo_p (*pos));
13925 /* If we found a match, remove the high-part relocation from its
13926 current position and insert it before the low-part relocation.
13927 Make the offsets match so that fixup_has_matching_lo_p()
13930 We don't warn about unmatched high-part relocations since some
13931 versions of gcc have been known to emit dead "lui ...%hi(...)"
13933 if (lo_pos != NULL)
13935 l->fixp->fx_offset = (*lo_pos)->fx_offset;
13936 if (l->fixp->fx_next != *lo_pos)
13938 *hi_pos = l->fixp->fx_next;
13939 l->fixp->fx_next = *lo_pos;
13947 mips_force_relocation (fixS *fixp)
13949 if (generic_force_reloc (fixp))
13952 /* We want to keep BFD_RELOC_MICROMIPS_*_PCREL_S1 relocation,
13953 so that the linker relaxation can update targets. */
13954 if (fixp->fx_r_type == BFD_RELOC_MICROMIPS_7_PCREL_S1
13955 || fixp->fx_r_type == BFD_RELOC_MICROMIPS_10_PCREL_S1
13956 || fixp->fx_r_type == BFD_RELOC_MICROMIPS_16_PCREL_S1)
13962 /* Read the instruction associated with RELOC from BUF. */
13964 static unsigned int
13965 read_reloc_insn (char *buf, bfd_reloc_code_real_type reloc)
13967 if (mips16_reloc_p (reloc) || micromips_reloc_p (reloc))
13968 return read_compressed_insn (buf, 4);
13970 return read_insn (buf);
13973 /* Write instruction INSN to BUF, given that it has been relocated
13977 write_reloc_insn (char *buf, bfd_reloc_code_real_type reloc,
13978 unsigned long insn)
13980 if (mips16_reloc_p (reloc) || micromips_reloc_p (reloc))
13981 write_compressed_insn (buf, insn, 4);
13983 write_insn (buf, insn);
13986 /* Apply a fixup to the object file. */
13989 md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
13992 unsigned long insn;
13993 reloc_howto_type *howto;
13995 /* We ignore generic BFD relocations we don't know about. */
13996 howto = bfd_reloc_type_lookup (stdoutput, fixP->fx_r_type);
14000 gas_assert (fixP->fx_size == 2
14001 || fixP->fx_size == 4
14002 || fixP->fx_r_type == BFD_RELOC_16
14003 || fixP->fx_r_type == BFD_RELOC_64
14004 || fixP->fx_r_type == BFD_RELOC_CTOR
14005 || fixP->fx_r_type == BFD_RELOC_MIPS_SUB
14006 || fixP->fx_r_type == BFD_RELOC_MICROMIPS_SUB
14007 || fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
14008 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY
14009 || fixP->fx_r_type == BFD_RELOC_MIPS_TLS_DTPREL64);
14011 buf = fixP->fx_frag->fr_literal + fixP->fx_where;
14013 gas_assert (!fixP->fx_pcrel || fixP->fx_r_type == BFD_RELOC_16_PCREL_S2
14014 || fixP->fx_r_type == BFD_RELOC_MICROMIPS_7_PCREL_S1
14015 || fixP->fx_r_type == BFD_RELOC_MICROMIPS_10_PCREL_S1
14016 || fixP->fx_r_type == BFD_RELOC_MICROMIPS_16_PCREL_S1
14017 || fixP->fx_r_type == BFD_RELOC_32_PCREL);
14019 /* Don't treat parts of a composite relocation as done. There are two
14022 (1) The second and third parts will be against 0 (RSS_UNDEF) but
14023 should nevertheless be emitted if the first part is.
14025 (2) In normal usage, composite relocations are never assembly-time
14026 constants. The easiest way of dealing with the pathological
14027 exceptions is to generate a relocation against STN_UNDEF and
14028 leave everything up to the linker. */
14029 if (fixP->fx_addsy == NULL && !fixP->fx_pcrel && fixP->fx_tcbit == 0)
14032 switch (fixP->fx_r_type)
14034 case BFD_RELOC_MIPS_TLS_GD:
14035 case BFD_RELOC_MIPS_TLS_LDM:
14036 case BFD_RELOC_MIPS_TLS_DTPREL32:
14037 case BFD_RELOC_MIPS_TLS_DTPREL64:
14038 case BFD_RELOC_MIPS_TLS_DTPREL_HI16:
14039 case BFD_RELOC_MIPS_TLS_DTPREL_LO16:
14040 case BFD_RELOC_MIPS_TLS_GOTTPREL:
14041 case BFD_RELOC_MIPS_TLS_TPREL32:
14042 case BFD_RELOC_MIPS_TLS_TPREL64:
14043 case BFD_RELOC_MIPS_TLS_TPREL_HI16:
14044 case BFD_RELOC_MIPS_TLS_TPREL_LO16:
14045 case BFD_RELOC_MICROMIPS_TLS_GD:
14046 case BFD_RELOC_MICROMIPS_TLS_LDM:
14047 case BFD_RELOC_MICROMIPS_TLS_DTPREL_HI16:
14048 case BFD_RELOC_MICROMIPS_TLS_DTPREL_LO16:
14049 case BFD_RELOC_MICROMIPS_TLS_GOTTPREL:
14050 case BFD_RELOC_MICROMIPS_TLS_TPREL_HI16:
14051 case BFD_RELOC_MICROMIPS_TLS_TPREL_LO16:
14052 case BFD_RELOC_MIPS16_TLS_GD:
14053 case BFD_RELOC_MIPS16_TLS_LDM:
14054 case BFD_RELOC_MIPS16_TLS_DTPREL_HI16:
14055 case BFD_RELOC_MIPS16_TLS_DTPREL_LO16:
14056 case BFD_RELOC_MIPS16_TLS_GOTTPREL:
14057 case BFD_RELOC_MIPS16_TLS_TPREL_HI16:
14058 case BFD_RELOC_MIPS16_TLS_TPREL_LO16:
14059 if (!fixP->fx_addsy)
14061 as_bad_where (fixP->fx_file, fixP->fx_line,
14062 _("TLS relocation against a constant"));
14065 S_SET_THREAD_LOCAL (fixP->fx_addsy);
14068 case BFD_RELOC_MIPS_JMP:
14069 case BFD_RELOC_MIPS_SHIFT5:
14070 case BFD_RELOC_MIPS_SHIFT6:
14071 case BFD_RELOC_MIPS_GOT_DISP:
14072 case BFD_RELOC_MIPS_GOT_PAGE:
14073 case BFD_RELOC_MIPS_GOT_OFST:
14074 case BFD_RELOC_MIPS_SUB:
14075 case BFD_RELOC_MIPS_INSERT_A:
14076 case BFD_RELOC_MIPS_INSERT_B:
14077 case BFD_RELOC_MIPS_DELETE:
14078 case BFD_RELOC_MIPS_HIGHEST:
14079 case BFD_RELOC_MIPS_HIGHER:
14080 case BFD_RELOC_MIPS_SCN_DISP:
14081 case BFD_RELOC_MIPS_REL16:
14082 case BFD_RELOC_MIPS_RELGOT:
14083 case BFD_RELOC_MIPS_JALR:
14084 case BFD_RELOC_HI16:
14085 case BFD_RELOC_HI16_S:
14086 case BFD_RELOC_LO16:
14087 case BFD_RELOC_GPREL16:
14088 case BFD_RELOC_MIPS_LITERAL:
14089 case BFD_RELOC_MIPS_CALL16:
14090 case BFD_RELOC_MIPS_GOT16:
14091 case BFD_RELOC_GPREL32:
14092 case BFD_RELOC_MIPS_GOT_HI16:
14093 case BFD_RELOC_MIPS_GOT_LO16:
14094 case BFD_RELOC_MIPS_CALL_HI16:
14095 case BFD_RELOC_MIPS_CALL_LO16:
14096 case BFD_RELOC_MIPS16_GPREL:
14097 case BFD_RELOC_MIPS16_GOT16:
14098 case BFD_RELOC_MIPS16_CALL16:
14099 case BFD_RELOC_MIPS16_HI16:
14100 case BFD_RELOC_MIPS16_HI16_S:
14101 case BFD_RELOC_MIPS16_LO16:
14102 case BFD_RELOC_MIPS16_JMP:
14103 case BFD_RELOC_MICROMIPS_JMP:
14104 case BFD_RELOC_MICROMIPS_GOT_DISP:
14105 case BFD_RELOC_MICROMIPS_GOT_PAGE:
14106 case BFD_RELOC_MICROMIPS_GOT_OFST:
14107 case BFD_RELOC_MICROMIPS_SUB:
14108 case BFD_RELOC_MICROMIPS_HIGHEST:
14109 case BFD_RELOC_MICROMIPS_HIGHER:
14110 case BFD_RELOC_MICROMIPS_SCN_DISP:
14111 case BFD_RELOC_MICROMIPS_JALR:
14112 case BFD_RELOC_MICROMIPS_HI16:
14113 case BFD_RELOC_MICROMIPS_HI16_S:
14114 case BFD_RELOC_MICROMIPS_LO16:
14115 case BFD_RELOC_MICROMIPS_GPREL16:
14116 case BFD_RELOC_MICROMIPS_LITERAL:
14117 case BFD_RELOC_MICROMIPS_CALL16:
14118 case BFD_RELOC_MICROMIPS_GOT16:
14119 case BFD_RELOC_MICROMIPS_GOT_HI16:
14120 case BFD_RELOC_MICROMIPS_GOT_LO16:
14121 case BFD_RELOC_MICROMIPS_CALL_HI16:
14122 case BFD_RELOC_MICROMIPS_CALL_LO16:
14123 case BFD_RELOC_MIPS_EH:
14128 if (calculate_reloc (fixP->fx_r_type, *valP, &value))
14130 insn = read_reloc_insn (buf, fixP->fx_r_type);
14131 if (mips16_reloc_p (fixP->fx_r_type))
14132 insn |= mips16_immed_extend (value, 16);
14134 insn |= (value & 0xffff);
14135 write_reloc_insn (buf, fixP->fx_r_type, insn);
14138 as_bad_where (fixP->fx_file, fixP->fx_line,
14139 _("Unsupported constant in relocation"));
14144 /* This is handled like BFD_RELOC_32, but we output a sign
14145 extended value if we are only 32 bits. */
14148 if (8 <= sizeof (valueT))
14149 md_number_to_chars (buf, *valP, 8);
14154 if ((*valP & 0x80000000) != 0)
14158 md_number_to_chars (buf + (target_big_endian ? 4 : 0), *valP, 4);
14159 md_number_to_chars (buf + (target_big_endian ? 0 : 4), hiv, 4);
14164 case BFD_RELOC_RVA:
14166 case BFD_RELOC_32_PCREL:
14168 /* If we are deleting this reloc entry, we must fill in the
14169 value now. This can happen if we have a .word which is not
14170 resolved when it appears but is later defined. */
14172 md_number_to_chars (buf, *valP, fixP->fx_size);
14175 case BFD_RELOC_16_PCREL_S2:
14176 if ((*valP & 0x3) != 0)
14177 as_bad_where (fixP->fx_file, fixP->fx_line,
14178 _("Branch to misaligned address (%lx)"), (long) *valP);
14180 /* We need to save the bits in the instruction since fixup_segment()
14181 might be deleting the relocation entry (i.e., a branch within
14182 the current segment). */
14183 if (! fixP->fx_done)
14186 /* Update old instruction data. */
14187 insn = read_insn (buf);
14189 if (*valP + 0x20000 <= 0x3ffff)
14191 insn |= (*valP >> 2) & 0xffff;
14192 write_insn (buf, insn);
14194 else if (mips_pic == NO_PIC
14196 && fixP->fx_frag->fr_address >= text_section->vma
14197 && (fixP->fx_frag->fr_address
14198 < text_section->vma + bfd_get_section_size (text_section))
14199 && ((insn & 0xffff0000) == 0x10000000 /* beq $0,$0 */
14200 || (insn & 0xffff0000) == 0x04010000 /* bgez $0 */
14201 || (insn & 0xffff0000) == 0x04110000)) /* bgezal $0 */
14203 /* The branch offset is too large. If this is an
14204 unconditional branch, and we are not generating PIC code,
14205 we can convert it to an absolute jump instruction. */
14206 if ((insn & 0xffff0000) == 0x04110000) /* bgezal $0 */
14207 insn = 0x0c000000; /* jal */
14209 insn = 0x08000000; /* j */
14210 fixP->fx_r_type = BFD_RELOC_MIPS_JMP;
14212 fixP->fx_addsy = section_symbol (text_section);
14213 *valP += md_pcrel_from (fixP);
14214 write_insn (buf, insn);
14218 /* If we got here, we have branch-relaxation disabled,
14219 and there's nothing we can do to fix this instruction
14220 without turning it into a longer sequence. */
14221 as_bad_where (fixP->fx_file, fixP->fx_line,
14222 _("Branch out of range"));
14226 case BFD_RELOC_MICROMIPS_7_PCREL_S1:
14227 case BFD_RELOC_MICROMIPS_10_PCREL_S1:
14228 case BFD_RELOC_MICROMIPS_16_PCREL_S1:
14229 /* We adjust the offset back to even. */
14230 if ((*valP & 0x1) != 0)
14233 if (! fixP->fx_done)
14236 /* Should never visit here, because we keep the relocation. */
14240 case BFD_RELOC_VTABLE_INHERIT:
14243 && !S_IS_DEFINED (fixP->fx_addsy)
14244 && !S_IS_WEAK (fixP->fx_addsy))
14245 S_SET_WEAK (fixP->fx_addsy);
14248 case BFD_RELOC_VTABLE_ENTRY:
14256 /* Remember value for tc_gen_reloc. */
14257 fixP->fx_addnumber = *valP;
14267 name = input_line_pointer;
14268 c = get_symbol_end ();
14269 p = (symbolS *) symbol_find_or_make (name);
14270 *input_line_pointer = c;
14274 /* Align the current frag to a given power of two. If a particular
14275 fill byte should be used, FILL points to an integer that contains
14276 that byte, otherwise FILL is null.
14278 This function used to have the comment:
14280 The MIPS assembler also automatically adjusts any preceding label.
14282 The implementation therefore applied the adjustment to a maximum of
14283 one label. However, other label adjustments are applied to batches
14284 of labels, and adjusting just one caused problems when new labels
14285 were added for the sake of debugging or unwind information.
14286 We therefore adjust all preceding labels (given as LABELS) instead. */
14289 mips_align (int to, int *fill, struct insn_label_list *labels)
14291 mips_emit_delays ();
14292 mips_record_compressed_mode ();
14293 if (fill == NULL && subseg_text_p (now_seg))
14294 frag_align_code (to, 0);
14296 frag_align (to, fill ? *fill : 0, 0);
14297 record_alignment (now_seg, to);
14298 mips_move_labels (labels, FALSE);
14301 /* Align to a given power of two. .align 0 turns off the automatic
14302 alignment used by the data creating pseudo-ops. */
14305 s_align (int x ATTRIBUTE_UNUSED)
14307 int temp, fill_value, *fill_ptr;
14308 long max_alignment = 28;
14310 /* o Note that the assembler pulls down any immediately preceding label
14311 to the aligned address.
14312 o It's not documented but auto alignment is reinstated by
14313 a .align pseudo instruction.
14314 o Note also that after auto alignment is turned off the mips assembler
14315 issues an error on attempt to assemble an improperly aligned data item.
14318 temp = get_absolute_expression ();
14319 if (temp > max_alignment)
14320 as_bad (_("Alignment too large: %d. assumed."), temp = max_alignment);
14323 as_warn (_("Alignment negative: 0 assumed."));
14326 if (*input_line_pointer == ',')
14328 ++input_line_pointer;
14329 fill_value = get_absolute_expression ();
14330 fill_ptr = &fill_value;
14336 segment_info_type *si = seg_info (now_seg);
14337 struct insn_label_list *l = si->label_list;
14338 /* Auto alignment should be switched on by next section change. */
14340 mips_align (temp, fill_ptr, l);
14347 demand_empty_rest_of_line ();
14351 s_change_sec (int sec)
14355 /* The ELF backend needs to know that we are changing sections, so
14356 that .previous works correctly. We could do something like check
14357 for an obj_section_change_hook macro, but that might be confusing
14358 as it would not be appropriate to use it in the section changing
14359 functions in read.c, since obj-elf.c intercepts those. FIXME:
14360 This should be cleaner, somehow. */
14361 obj_elf_section_change_hook ();
14363 mips_emit_delays ();
14374 subseg_set (bss_section, (subsegT) get_absolute_expression ());
14375 demand_empty_rest_of_line ();
14379 seg = subseg_new (RDATA_SECTION_NAME,
14380 (subsegT) get_absolute_expression ());
14381 bfd_set_section_flags (stdoutput, seg, (SEC_ALLOC | SEC_LOAD
14382 | SEC_READONLY | SEC_RELOC
14384 if (strncmp (TARGET_OS, "elf", 3) != 0)
14385 record_alignment (seg, 4);
14386 demand_empty_rest_of_line ();
14390 seg = subseg_new (".sdata", (subsegT) get_absolute_expression ());
14391 bfd_set_section_flags (stdoutput, seg,
14392 SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_DATA);
14393 if (strncmp (TARGET_OS, "elf", 3) != 0)
14394 record_alignment (seg, 4);
14395 demand_empty_rest_of_line ();
14399 seg = subseg_new (".sbss", (subsegT) get_absolute_expression ());
14400 bfd_set_section_flags (stdoutput, seg, SEC_ALLOC);
14401 if (strncmp (TARGET_OS, "elf", 3) != 0)
14402 record_alignment (seg, 4);
14403 demand_empty_rest_of_line ();
14411 s_change_section (int ignore ATTRIBUTE_UNUSED)
14413 char *section_name;
14418 int section_entry_size;
14419 int section_alignment;
14421 section_name = input_line_pointer;
14422 c = get_symbol_end ();
14424 next_c = *(input_line_pointer + 1);
14426 /* Do we have .section Name<,"flags">? */
14427 if (c != ',' || (c == ',' && next_c == '"'))
14429 /* just after name is now '\0'. */
14430 *input_line_pointer = c;
14431 input_line_pointer = section_name;
14432 obj_elf_section (ignore);
14435 input_line_pointer++;
14437 /* Do we have .section Name<,type><,flag><,entry_size><,alignment> */
14439 section_type = get_absolute_expression ();
14442 if (*input_line_pointer++ == ',')
14443 section_flag = get_absolute_expression ();
14446 if (*input_line_pointer++ == ',')
14447 section_entry_size = get_absolute_expression ();
14449 section_entry_size = 0;
14450 if (*input_line_pointer++ == ',')
14451 section_alignment = get_absolute_expression ();
14453 section_alignment = 0;
14454 /* FIXME: really ignore? */
14455 (void) section_alignment;
14457 section_name = xstrdup (section_name);
14459 /* When using the generic form of .section (as implemented by obj-elf.c),
14460 there's no way to set the section type to SHT_MIPS_DWARF. Users have
14461 traditionally had to fall back on the more common @progbits instead.
14463 There's nothing really harmful in this, since bfd will correct
14464 SHT_PROGBITS to SHT_MIPS_DWARF before writing out the file. But it
14465 means that, for backwards compatibility, the special_section entries
14466 for dwarf sections must use SHT_PROGBITS rather than SHT_MIPS_DWARF.
14468 Even so, we shouldn't force users of the MIPS .section syntax to
14469 incorrectly label the sections as SHT_PROGBITS. The best compromise
14470 seems to be to map SHT_MIPS_DWARF to SHT_PROGBITS before calling the
14471 generic type-checking code. */
14472 if (section_type == SHT_MIPS_DWARF)
14473 section_type = SHT_PROGBITS;
14475 obj_elf_change_section (section_name, section_type, section_flag,
14476 section_entry_size, 0, 0, 0);
14478 if (now_seg->name != section_name)
14479 free (section_name);
14483 mips_enable_auto_align (void)
14489 s_cons (int log_size)
14491 segment_info_type *si = seg_info (now_seg);
14492 struct insn_label_list *l = si->label_list;
14494 mips_emit_delays ();
14495 if (log_size > 0 && auto_align)
14496 mips_align (log_size, 0, l);
14497 cons (1 << log_size);
14498 mips_clear_insn_labels ();
14502 s_float_cons (int type)
14504 segment_info_type *si = seg_info (now_seg);
14505 struct insn_label_list *l = si->label_list;
14507 mips_emit_delays ();
14512 mips_align (3, 0, l);
14514 mips_align (2, 0, l);
14518 mips_clear_insn_labels ();
14521 /* Handle .globl. We need to override it because on Irix 5 you are
14524 where foo is an undefined symbol, to mean that foo should be
14525 considered to be the address of a function. */
14528 s_mips_globl (int x ATTRIBUTE_UNUSED)
14537 name = input_line_pointer;
14538 c = get_symbol_end ();
14539 symbolP = symbol_find_or_make (name);
14540 S_SET_EXTERNAL (symbolP);
14542 *input_line_pointer = c;
14543 SKIP_WHITESPACE ();
14545 /* On Irix 5, every global symbol that is not explicitly labelled as
14546 being a function is apparently labelled as being an object. */
14549 if (!is_end_of_line[(unsigned char) *input_line_pointer]
14550 && (*input_line_pointer != ','))
14555 secname = input_line_pointer;
14556 c = get_symbol_end ();
14557 sec = bfd_get_section_by_name (stdoutput, secname);
14559 as_bad (_("%s: no such section"), secname);
14560 *input_line_pointer = c;
14562 if (sec != NULL && (sec->flags & SEC_CODE) != 0)
14563 flag = BSF_FUNCTION;
14566 symbol_get_bfdsym (symbolP)->flags |= flag;
14568 c = *input_line_pointer;
14571 input_line_pointer++;
14572 SKIP_WHITESPACE ();
14573 if (is_end_of_line[(unsigned char) *input_line_pointer])
14579 demand_empty_rest_of_line ();
14583 s_option (int x ATTRIBUTE_UNUSED)
14588 opt = input_line_pointer;
14589 c = get_symbol_end ();
14593 /* FIXME: What does this mean? */
14595 else if (strncmp (opt, "pic", 3) == 0)
14599 i = atoi (opt + 3);
14604 mips_pic = SVR4_PIC;
14605 mips_abicalls = TRUE;
14608 as_bad (_(".option pic%d not supported"), i);
14610 if (mips_pic == SVR4_PIC)
14612 if (g_switch_seen && g_switch_value != 0)
14613 as_warn (_("-G may not be used with SVR4 PIC code"));
14614 g_switch_value = 0;
14615 bfd_set_gp_size (stdoutput, 0);
14619 as_warn (_("Unrecognized option \"%s\""), opt);
14621 *input_line_pointer = c;
14622 demand_empty_rest_of_line ();
14625 /* This structure is used to hold a stack of .set values. */
14627 struct mips_option_stack
14629 struct mips_option_stack *next;
14630 struct mips_set_options options;
14633 static struct mips_option_stack *mips_opts_stack;
14635 /* Handle the .set pseudo-op. */
14638 s_mipsset (int x ATTRIBUTE_UNUSED)
14640 char *name = input_line_pointer, ch;
14641 const struct mips_ase *ase;
14643 while (!is_end_of_line[(unsigned char) *input_line_pointer])
14644 ++input_line_pointer;
14645 ch = *input_line_pointer;
14646 *input_line_pointer = '\0';
14648 if (strcmp (name, "reorder") == 0)
14650 if (mips_opts.noreorder)
14653 else if (strcmp (name, "noreorder") == 0)
14655 if (!mips_opts.noreorder)
14656 start_noreorder ();
14658 else if (strncmp (name, "at=", 3) == 0)
14660 char *s = name + 3;
14662 if (!reg_lookup (&s, RTYPE_NUM | RTYPE_GP, &mips_opts.at))
14663 as_bad (_("Unrecognized register name `%s'"), s);
14665 else if (strcmp (name, "at") == 0)
14667 mips_opts.at = ATREG;
14669 else if (strcmp (name, "noat") == 0)
14671 mips_opts.at = ZERO;
14673 else if (strcmp (name, "macro") == 0)
14675 mips_opts.warn_about_macros = 0;
14677 else if (strcmp (name, "nomacro") == 0)
14679 if (mips_opts.noreorder == 0)
14680 as_bad (_("`noreorder' must be set before `nomacro'"));
14681 mips_opts.warn_about_macros = 1;
14683 else if (strcmp (name, "move") == 0 || strcmp (name, "novolatile") == 0)
14685 mips_opts.nomove = 0;
14687 else if (strcmp (name, "nomove") == 0 || strcmp (name, "volatile") == 0)
14689 mips_opts.nomove = 1;
14691 else if (strcmp (name, "bopt") == 0)
14693 mips_opts.nobopt = 0;
14695 else if (strcmp (name, "nobopt") == 0)
14697 mips_opts.nobopt = 1;
14699 else if (strcmp (name, "gp=default") == 0)
14700 mips_opts.gp32 = file_mips_gp32;
14701 else if (strcmp (name, "gp=32") == 0)
14702 mips_opts.gp32 = 1;
14703 else if (strcmp (name, "gp=64") == 0)
14705 if (!ISA_HAS_64BIT_REGS (mips_opts.isa))
14706 as_warn (_("%s isa does not support 64-bit registers"),
14707 mips_cpu_info_from_isa (mips_opts.isa)->name);
14708 mips_opts.gp32 = 0;
14710 else if (strcmp (name, "fp=default") == 0)
14711 mips_opts.fp32 = file_mips_fp32;
14712 else if (strcmp (name, "fp=32") == 0)
14713 mips_opts.fp32 = 1;
14714 else if (strcmp (name, "fp=64") == 0)
14716 if (!ISA_HAS_64BIT_FPRS (mips_opts.isa))
14717 as_warn (_("%s isa does not support 64-bit floating point registers"),
14718 mips_cpu_info_from_isa (mips_opts.isa)->name);
14719 mips_opts.fp32 = 0;
14721 else if (strcmp (name, "softfloat") == 0)
14722 mips_opts.soft_float = 1;
14723 else if (strcmp (name, "hardfloat") == 0)
14724 mips_opts.soft_float = 0;
14725 else if (strcmp (name, "singlefloat") == 0)
14726 mips_opts.single_float = 1;
14727 else if (strcmp (name, "doublefloat") == 0)
14728 mips_opts.single_float = 0;
14729 else if (strcmp (name, "mips16") == 0
14730 || strcmp (name, "MIPS-16") == 0)
14732 if (mips_opts.micromips == 1)
14733 as_fatal (_("`mips16' cannot be used with `micromips'"));
14734 mips_opts.mips16 = 1;
14736 else if (strcmp (name, "nomips16") == 0
14737 || strcmp (name, "noMIPS-16") == 0)
14738 mips_opts.mips16 = 0;
14739 else if (strcmp (name, "micromips") == 0)
14741 if (mips_opts.mips16 == 1)
14742 as_fatal (_("`micromips' cannot be used with `mips16'"));
14743 mips_opts.micromips = 1;
14745 else if (strcmp (name, "nomicromips") == 0)
14746 mips_opts.micromips = 0;
14747 else if (name[0] == 'n'
14749 && (ase = mips_lookup_ase (name + 2)))
14750 mips_set_ase (ase, FALSE);
14751 else if ((ase = mips_lookup_ase (name)))
14752 mips_set_ase (ase, TRUE);
14753 else if (strncmp (name, "mips", 4) == 0 || strncmp (name, "arch=", 5) == 0)
14757 /* Permit the user to change the ISA and architecture on the fly.
14758 Needless to say, misuse can cause serious problems. */
14759 if (strcmp (name, "mips0") == 0 || strcmp (name, "arch=default") == 0)
14762 mips_opts.isa = file_mips_isa;
14763 mips_opts.arch = file_mips_arch;
14765 else if (strncmp (name, "arch=", 5) == 0)
14767 const struct mips_cpu_info *p;
14769 p = mips_parse_cpu("internal use", name + 5);
14771 as_bad (_("unknown architecture %s"), name + 5);
14774 mips_opts.arch = p->cpu;
14775 mips_opts.isa = p->isa;
14778 else if (strncmp (name, "mips", 4) == 0)
14780 const struct mips_cpu_info *p;
14782 p = mips_parse_cpu("internal use", name);
14784 as_bad (_("unknown ISA level %s"), name + 4);
14787 mips_opts.arch = p->cpu;
14788 mips_opts.isa = p->isa;
14792 as_bad (_("unknown ISA or architecture %s"), name);
14794 switch (mips_opts.isa)
14802 mips_opts.gp32 = 1;
14803 mips_opts.fp32 = 1;
14810 mips_opts.gp32 = 0;
14811 if (mips_opts.arch == CPU_R5900)
14813 mips_opts.fp32 = 1;
14817 mips_opts.fp32 = 0;
14821 as_bad (_("unknown ISA level %s"), name + 4);
14826 mips_opts.gp32 = file_mips_gp32;
14827 mips_opts.fp32 = file_mips_fp32;
14830 else if (strcmp (name, "autoextend") == 0)
14831 mips_opts.noautoextend = 0;
14832 else if (strcmp (name, "noautoextend") == 0)
14833 mips_opts.noautoextend = 1;
14834 else if (strcmp (name, "insn32") == 0)
14835 mips_opts.insn32 = TRUE;
14836 else if (strcmp (name, "noinsn32") == 0)
14837 mips_opts.insn32 = FALSE;
14838 else if (strcmp (name, "push") == 0)
14840 struct mips_option_stack *s;
14842 s = (struct mips_option_stack *) xmalloc (sizeof *s);
14843 s->next = mips_opts_stack;
14844 s->options = mips_opts;
14845 mips_opts_stack = s;
14847 else if (strcmp (name, "pop") == 0)
14849 struct mips_option_stack *s;
14851 s = mips_opts_stack;
14853 as_bad (_(".set pop with no .set push"));
14856 /* If we're changing the reorder mode we need to handle
14857 delay slots correctly. */
14858 if (s->options.noreorder && ! mips_opts.noreorder)
14859 start_noreorder ();
14860 else if (! s->options.noreorder && mips_opts.noreorder)
14863 mips_opts = s->options;
14864 mips_opts_stack = s->next;
14868 else if (strcmp (name, "sym32") == 0)
14869 mips_opts.sym32 = TRUE;
14870 else if (strcmp (name, "nosym32") == 0)
14871 mips_opts.sym32 = FALSE;
14872 else if (strchr (name, ','))
14874 /* Generic ".set" directive; use the generic handler. */
14875 *input_line_pointer = ch;
14876 input_line_pointer = name;
14882 as_warn (_("Tried to set unrecognized symbol: %s\n"), name);
14884 mips_check_isa_supports_ases ();
14885 *input_line_pointer = ch;
14886 demand_empty_rest_of_line ();
14889 /* Handle the .abicalls pseudo-op. I believe this is equivalent to
14890 .option pic2. It means to generate SVR4 PIC calls. */
14893 s_abicalls (int ignore ATTRIBUTE_UNUSED)
14895 mips_pic = SVR4_PIC;
14896 mips_abicalls = TRUE;
14898 if (g_switch_seen && g_switch_value != 0)
14899 as_warn (_("-G may not be used with SVR4 PIC code"));
14900 g_switch_value = 0;
14902 bfd_set_gp_size (stdoutput, 0);
14903 demand_empty_rest_of_line ();
14906 /* Handle the .cpload pseudo-op. This is used when generating SVR4
14907 PIC code. It sets the $gp register for the function based on the
14908 function address, which is in the register named in the argument.
14909 This uses a relocation against _gp_disp, which is handled specially
14910 by the linker. The result is:
14911 lui $gp,%hi(_gp_disp)
14912 addiu $gp,$gp,%lo(_gp_disp)
14913 addu $gp,$gp,.cpload argument
14914 The .cpload argument is normally $25 == $t9.
14916 The -mno-shared option changes this to:
14917 lui $gp,%hi(__gnu_local_gp)
14918 addiu $gp,$gp,%lo(__gnu_local_gp)
14919 and the argument is ignored. This saves an instruction, but the
14920 resulting code is not position independent; it uses an absolute
14921 address for __gnu_local_gp. Thus code assembled with -mno-shared
14922 can go into an ordinary executable, but not into a shared library. */
14925 s_cpload (int ignore ATTRIBUTE_UNUSED)
14931 /* If we are not generating SVR4 PIC code, or if this is NewABI code,
14932 .cpload is ignored. */
14933 if (mips_pic != SVR4_PIC || HAVE_NEWABI)
14939 if (mips_opts.mips16)
14941 as_bad (_("%s not supported in MIPS16 mode"), ".cpload");
14942 ignore_rest_of_line ();
14946 /* .cpload should be in a .set noreorder section. */
14947 if (mips_opts.noreorder == 0)
14948 as_warn (_(".cpload not in noreorder section"));
14950 reg = tc_get_register (0);
14952 /* If we need to produce a 64-bit address, we are better off using
14953 the default instruction sequence. */
14954 in_shared = mips_in_shared || HAVE_64BIT_SYMBOLS;
14956 ex.X_op = O_symbol;
14957 ex.X_add_symbol = symbol_find_or_make (in_shared ? "_gp_disp" :
14959 ex.X_op_symbol = NULL;
14960 ex.X_add_number = 0;
14962 /* In ELF, this symbol is implicitly an STT_OBJECT symbol. */
14963 symbol_get_bfdsym (ex.X_add_symbol)->flags |= BSF_OBJECT;
14965 mips_mark_labels ();
14966 mips_assembling_insn = TRUE;
14969 macro_build_lui (&ex, mips_gp_register);
14970 macro_build (&ex, "addiu", "t,r,j", mips_gp_register,
14971 mips_gp_register, BFD_RELOC_LO16);
14973 macro_build (NULL, "addu", "d,v,t", mips_gp_register,
14974 mips_gp_register, reg);
14977 mips_assembling_insn = FALSE;
14978 demand_empty_rest_of_line ();
14981 /* Handle the .cpsetup pseudo-op defined for NewABI PIC code. The syntax is:
14982 .cpsetup $reg1, offset|$reg2, label
14984 If offset is given, this results in:
14985 sd $gp, offset($sp)
14986 lui $gp, %hi(%neg(%gp_rel(label)))
14987 addiu $gp, $gp, %lo(%neg(%gp_rel(label)))
14988 daddu $gp, $gp, $reg1
14990 If $reg2 is given, this results in:
14991 daddu $reg2, $gp, $0
14992 lui $gp, %hi(%neg(%gp_rel(label)))
14993 addiu $gp, $gp, %lo(%neg(%gp_rel(label)))
14994 daddu $gp, $gp, $reg1
14995 $reg1 is normally $25 == $t9.
14997 The -mno-shared option replaces the last three instructions with
14999 addiu $gp,$gp,%lo(_gp) */
15002 s_cpsetup (int ignore ATTRIBUTE_UNUSED)
15004 expressionS ex_off;
15005 expressionS ex_sym;
15008 /* If we are not generating SVR4 PIC code, .cpsetup is ignored.
15009 We also need NewABI support. */
15010 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
15016 if (mips_opts.mips16)
15018 as_bad (_("%s not supported in MIPS16 mode"), ".cpsetup");
15019 ignore_rest_of_line ();
15023 reg1 = tc_get_register (0);
15024 SKIP_WHITESPACE ();
15025 if (*input_line_pointer != ',')
15027 as_bad (_("missing argument separator ',' for .cpsetup"));
15031 ++input_line_pointer;
15032 SKIP_WHITESPACE ();
15033 if (*input_line_pointer == '$')
15035 mips_cpreturn_register = tc_get_register (0);
15036 mips_cpreturn_offset = -1;
15040 mips_cpreturn_offset = get_absolute_expression ();
15041 mips_cpreturn_register = -1;
15043 SKIP_WHITESPACE ();
15044 if (*input_line_pointer != ',')
15046 as_bad (_("missing argument separator ',' for .cpsetup"));
15050 ++input_line_pointer;
15051 SKIP_WHITESPACE ();
15052 expression (&ex_sym);
15054 mips_mark_labels ();
15055 mips_assembling_insn = TRUE;
15058 if (mips_cpreturn_register == -1)
15060 ex_off.X_op = O_constant;
15061 ex_off.X_add_symbol = NULL;
15062 ex_off.X_op_symbol = NULL;
15063 ex_off.X_add_number = mips_cpreturn_offset;
15065 macro_build (&ex_off, "sd", "t,o(b)", mips_gp_register,
15066 BFD_RELOC_LO16, SP);
15069 macro_build (NULL, "daddu", "d,v,t", mips_cpreturn_register,
15070 mips_gp_register, 0);
15072 if (mips_in_shared || HAVE_64BIT_SYMBOLS)
15074 macro_build (&ex_sym, "lui", LUI_FMT, mips_gp_register,
15075 -1, BFD_RELOC_GPREL16, BFD_RELOC_MIPS_SUB,
15078 macro_build (&ex_sym, "addiu", "t,r,j", mips_gp_register,
15079 mips_gp_register, -1, BFD_RELOC_GPREL16,
15080 BFD_RELOC_MIPS_SUB, BFD_RELOC_LO16);
15082 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", mips_gp_register,
15083 mips_gp_register, reg1);
15089 ex.X_op = O_symbol;
15090 ex.X_add_symbol = symbol_find_or_make ("__gnu_local_gp");
15091 ex.X_op_symbol = NULL;
15092 ex.X_add_number = 0;
15094 /* In ELF, this symbol is implicitly an STT_OBJECT symbol. */
15095 symbol_get_bfdsym (ex.X_add_symbol)->flags |= BSF_OBJECT;
15097 macro_build_lui (&ex, mips_gp_register);
15098 macro_build (&ex, "addiu", "t,r,j", mips_gp_register,
15099 mips_gp_register, BFD_RELOC_LO16);
15104 mips_assembling_insn = FALSE;
15105 demand_empty_rest_of_line ();
15109 s_cplocal (int ignore ATTRIBUTE_UNUSED)
15111 /* If we are not generating SVR4 PIC code, or if this is not NewABI code,
15112 .cplocal is ignored. */
15113 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
15119 if (mips_opts.mips16)
15121 as_bad (_("%s not supported in MIPS16 mode"), ".cplocal");
15122 ignore_rest_of_line ();
15126 mips_gp_register = tc_get_register (0);
15127 demand_empty_rest_of_line ();
15130 /* Handle the .cprestore pseudo-op. This stores $gp into a given
15131 offset from $sp. The offset is remembered, and after making a PIC
15132 call $gp is restored from that location. */
15135 s_cprestore (int ignore ATTRIBUTE_UNUSED)
15139 /* If we are not generating SVR4 PIC code, or if this is NewABI code,
15140 .cprestore is ignored. */
15141 if (mips_pic != SVR4_PIC || HAVE_NEWABI)
15147 if (mips_opts.mips16)
15149 as_bad (_("%s not supported in MIPS16 mode"), ".cprestore");
15150 ignore_rest_of_line ();
15154 mips_cprestore_offset = get_absolute_expression ();
15155 mips_cprestore_valid = 1;
15157 ex.X_op = O_constant;
15158 ex.X_add_symbol = NULL;
15159 ex.X_op_symbol = NULL;
15160 ex.X_add_number = mips_cprestore_offset;
15162 mips_mark_labels ();
15163 mips_assembling_insn = TRUE;
15166 macro_build_ldst_constoffset (&ex, ADDRESS_STORE_INSN, mips_gp_register,
15167 SP, HAVE_64BIT_ADDRESSES);
15170 mips_assembling_insn = FALSE;
15171 demand_empty_rest_of_line ();
15174 /* Handle the .cpreturn pseudo-op defined for NewABI PIC code. If an offset
15175 was given in the preceding .cpsetup, it results in:
15176 ld $gp, offset($sp)
15178 If a register $reg2 was given there, it results in:
15179 daddu $gp, $reg2, $0 */
15182 s_cpreturn (int ignore ATTRIBUTE_UNUSED)
15186 /* If we are not generating SVR4 PIC code, .cpreturn is ignored.
15187 We also need NewABI support. */
15188 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
15194 if (mips_opts.mips16)
15196 as_bad (_("%s not supported in MIPS16 mode"), ".cpreturn");
15197 ignore_rest_of_line ();
15201 mips_mark_labels ();
15202 mips_assembling_insn = TRUE;
15205 if (mips_cpreturn_register == -1)
15207 ex.X_op = O_constant;
15208 ex.X_add_symbol = NULL;
15209 ex.X_op_symbol = NULL;
15210 ex.X_add_number = mips_cpreturn_offset;
15212 macro_build (&ex, "ld", "t,o(b)", mips_gp_register, BFD_RELOC_LO16, SP);
15215 macro_build (NULL, "daddu", "d,v,t", mips_gp_register,
15216 mips_cpreturn_register, 0);
15219 mips_assembling_insn = FALSE;
15220 demand_empty_rest_of_line ();
15223 /* Handle a .dtprelword, .dtpreldword, .tprelword, or .tpreldword
15224 pseudo-op; DIRSTR says which. The pseudo-op generates a BYTES-size
15225 DTP- or TP-relative relocation of type RTYPE, for use in either DWARF
15226 debug information or MIPS16 TLS. */
15229 s_tls_rel_directive (const size_t bytes, const char *dirstr,
15230 bfd_reloc_code_real_type rtype)
15237 if (ex.X_op != O_symbol)
15239 as_bad (_("Unsupported use of %s"), dirstr);
15240 ignore_rest_of_line ();
15243 p = frag_more (bytes);
15244 md_number_to_chars (p, 0, bytes);
15245 fix_new_exp (frag_now, p - frag_now->fr_literal, bytes, &ex, FALSE, rtype);
15246 demand_empty_rest_of_line ();
15247 mips_clear_insn_labels ();
15250 /* Handle .dtprelword. */
15253 s_dtprelword (int ignore ATTRIBUTE_UNUSED)
15255 s_tls_rel_directive (4, ".dtprelword", BFD_RELOC_MIPS_TLS_DTPREL32);
15258 /* Handle .dtpreldword. */
15261 s_dtpreldword (int ignore ATTRIBUTE_UNUSED)
15263 s_tls_rel_directive (8, ".dtpreldword", BFD_RELOC_MIPS_TLS_DTPREL64);
15266 /* Handle .tprelword. */
15269 s_tprelword (int ignore ATTRIBUTE_UNUSED)
15271 s_tls_rel_directive (4, ".tprelword", BFD_RELOC_MIPS_TLS_TPREL32);
15274 /* Handle .tpreldword. */
15277 s_tpreldword (int ignore ATTRIBUTE_UNUSED)
15279 s_tls_rel_directive (8, ".tpreldword", BFD_RELOC_MIPS_TLS_TPREL64);
15282 /* Handle the .gpvalue pseudo-op. This is used when generating NewABI PIC
15283 code. It sets the offset to use in gp_rel relocations. */
15286 s_gpvalue (int ignore ATTRIBUTE_UNUSED)
15288 /* If we are not generating SVR4 PIC code, .gpvalue is ignored.
15289 We also need NewABI support. */
15290 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
15296 mips_gprel_offset = get_absolute_expression ();
15298 demand_empty_rest_of_line ();
15301 /* Handle the .gpword pseudo-op. This is used when generating PIC
15302 code. It generates a 32 bit GP relative reloc. */
15305 s_gpword (int ignore ATTRIBUTE_UNUSED)
15307 segment_info_type *si;
15308 struct insn_label_list *l;
15312 /* When not generating PIC code, this is treated as .word. */
15313 if (mips_pic != SVR4_PIC)
15319 si = seg_info (now_seg);
15320 l = si->label_list;
15321 mips_emit_delays ();
15323 mips_align (2, 0, l);
15326 mips_clear_insn_labels ();
15328 if (ex.X_op != O_symbol || ex.X_add_number != 0)
15330 as_bad (_("Unsupported use of .gpword"));
15331 ignore_rest_of_line ();
15335 md_number_to_chars (p, 0, 4);
15336 fix_new_exp (frag_now, p - frag_now->fr_literal, 4, &ex, FALSE,
15337 BFD_RELOC_GPREL32);
15339 demand_empty_rest_of_line ();
15343 s_gpdword (int ignore ATTRIBUTE_UNUSED)
15345 segment_info_type *si;
15346 struct insn_label_list *l;
15350 /* When not generating PIC code, this is treated as .dword. */
15351 if (mips_pic != SVR4_PIC)
15357 si = seg_info (now_seg);
15358 l = si->label_list;
15359 mips_emit_delays ();
15361 mips_align (3, 0, l);
15364 mips_clear_insn_labels ();
15366 if (ex.X_op != O_symbol || ex.X_add_number != 0)
15368 as_bad (_("Unsupported use of .gpdword"));
15369 ignore_rest_of_line ();
15373 md_number_to_chars (p, 0, 8);
15374 fix_new_exp (frag_now, p - frag_now->fr_literal, 4, &ex, FALSE,
15375 BFD_RELOC_GPREL32)->fx_tcbit = 1;
15377 /* GPREL32 composed with 64 gives a 64-bit GP offset. */
15378 fix_new (frag_now, p - frag_now->fr_literal, 8, NULL, 0,
15379 FALSE, BFD_RELOC_64)->fx_tcbit = 1;
15381 demand_empty_rest_of_line ();
15384 /* Handle the .ehword pseudo-op. This is used when generating unwinding
15385 tables. It generates a R_MIPS_EH reloc. */
15388 s_ehword (int ignore ATTRIBUTE_UNUSED)
15393 mips_emit_delays ();
15396 mips_clear_insn_labels ();
15398 if (ex.X_op != O_symbol || ex.X_add_number != 0)
15400 as_bad (_("Unsupported use of .ehword"));
15401 ignore_rest_of_line ();
15405 md_number_to_chars (p, 0, 4);
15406 fix_new_exp (frag_now, p - frag_now->fr_literal, 4, &ex, FALSE,
15407 BFD_RELOC_MIPS_EH);
15409 demand_empty_rest_of_line ();
15412 /* Handle the .cpadd pseudo-op. This is used when dealing with switch
15413 tables in SVR4 PIC code. */
15416 s_cpadd (int ignore ATTRIBUTE_UNUSED)
15420 /* This is ignored when not generating SVR4 PIC code. */
15421 if (mips_pic != SVR4_PIC)
15427 mips_mark_labels ();
15428 mips_assembling_insn = TRUE;
15430 /* Add $gp to the register named as an argument. */
15432 reg = tc_get_register (0);
15433 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", reg, reg, mips_gp_register);
15436 mips_assembling_insn = FALSE;
15437 demand_empty_rest_of_line ();
15440 /* Handle the .insn pseudo-op. This marks instruction labels in
15441 mips16/micromips mode. This permits the linker to handle them specially,
15442 such as generating jalx instructions when needed. We also make
15443 them odd for the duration of the assembly, in order to generate the
15444 right sort of code. We will make them even in the adjust_symtab
15445 routine, while leaving them marked. This is convenient for the
15446 debugger and the disassembler. The linker knows to make them odd
15450 s_insn (int ignore ATTRIBUTE_UNUSED)
15452 mips_mark_labels ();
15454 demand_empty_rest_of_line ();
15457 /* Handle the .nan pseudo-op. */
15460 s_nan (int ignore ATTRIBUTE_UNUSED)
15462 static const char str_legacy[] = "legacy";
15463 static const char str_2008[] = "2008";
15466 for (i = 0; !is_end_of_line[(unsigned char) input_line_pointer[i]]; i++);
15468 if (i == sizeof (str_2008) - 1
15469 && memcmp (input_line_pointer, str_2008, i) == 0)
15470 mips_flag_nan2008 = TRUE;
15471 else if (i == sizeof (str_legacy) - 1
15472 && memcmp (input_line_pointer, str_legacy, i) == 0)
15473 mips_flag_nan2008 = FALSE;
15475 as_bad (_("Bad .nan directive"));
15477 input_line_pointer += i;
15478 demand_empty_rest_of_line ();
15481 /* Handle a .stab[snd] directive. Ideally these directives would be
15482 implemented in a transparent way, so that removing them would not
15483 have any effect on the generated instructions. However, s_stab
15484 internally changes the section, so in practice we need to decide
15485 now whether the preceding label marks compressed code. We do not
15486 support changing the compression mode of a label after a .stab*
15487 directive, such as in:
15493 so the current mode wins. */
15496 s_mips_stab (int type)
15498 mips_mark_labels ();
15502 /* Handle the .weakext pseudo-op as defined in Kane and Heinrich. */
15505 s_mips_weakext (int ignore ATTRIBUTE_UNUSED)
15512 name = input_line_pointer;
15513 c = get_symbol_end ();
15514 symbolP = symbol_find_or_make (name);
15515 S_SET_WEAK (symbolP);
15516 *input_line_pointer = c;
15518 SKIP_WHITESPACE ();
15520 if (! is_end_of_line[(unsigned char) *input_line_pointer])
15522 if (S_IS_DEFINED (symbolP))
15524 as_bad (_("ignoring attempt to redefine symbol %s"),
15525 S_GET_NAME (symbolP));
15526 ignore_rest_of_line ();
15530 if (*input_line_pointer == ',')
15532 ++input_line_pointer;
15533 SKIP_WHITESPACE ();
15537 if (exp.X_op != O_symbol)
15539 as_bad (_("bad .weakext directive"));
15540 ignore_rest_of_line ();
15543 symbol_set_value_expression (symbolP, &exp);
15546 demand_empty_rest_of_line ();
15549 /* Parse a register string into a number. Called from the ECOFF code
15550 to parse .frame. The argument is non-zero if this is the frame
15551 register, so that we can record it in mips_frame_reg. */
15554 tc_get_register (int frame)
15558 SKIP_WHITESPACE ();
15559 if (! reg_lookup (&input_line_pointer, RWARN | RTYPE_NUM | RTYPE_GP, ®))
15563 mips_frame_reg = reg != 0 ? reg : SP;
15564 mips_frame_reg_valid = 1;
15565 mips_cprestore_valid = 0;
15571 md_section_align (asection *seg, valueT addr)
15573 int align = bfd_get_section_alignment (stdoutput, seg);
15575 /* We don't need to align ELF sections to the full alignment.
15576 However, Irix 5 may prefer that we align them at least to a 16
15577 byte boundary. We don't bother to align the sections if we
15578 are targeted for an embedded system. */
15579 if (strncmp (TARGET_OS, "elf", 3) == 0)
15584 return ((addr + (1 << align) - 1) & (-1 << align));
15587 /* Utility routine, called from above as well. If called while the
15588 input file is still being read, it's only an approximation. (For
15589 example, a symbol may later become defined which appeared to be
15590 undefined earlier.) */
15593 nopic_need_relax (symbolS *sym, int before_relaxing)
15598 if (g_switch_value > 0)
15600 const char *symname;
15603 /* Find out whether this symbol can be referenced off the $gp
15604 register. It can be if it is smaller than the -G size or if
15605 it is in the .sdata or .sbss section. Certain symbols can
15606 not be referenced off the $gp, although it appears as though
15608 symname = S_GET_NAME (sym);
15609 if (symname != (const char *) NULL
15610 && (strcmp (symname, "eprol") == 0
15611 || strcmp (symname, "etext") == 0
15612 || strcmp (symname, "_gp") == 0
15613 || strcmp (symname, "edata") == 0
15614 || strcmp (symname, "_fbss") == 0
15615 || strcmp (symname, "_fdata") == 0
15616 || strcmp (symname, "_ftext") == 0
15617 || strcmp (symname, "end") == 0
15618 || strcmp (symname, "_gp_disp") == 0))
15620 else if ((! S_IS_DEFINED (sym) || S_IS_COMMON (sym))
15622 #ifndef NO_ECOFF_DEBUGGING
15623 || (symbol_get_obj (sym)->ecoff_extern_size != 0
15624 && (symbol_get_obj (sym)->ecoff_extern_size
15625 <= g_switch_value))
15627 /* We must defer this decision until after the whole
15628 file has been read, since there might be a .extern
15629 after the first use of this symbol. */
15630 || (before_relaxing
15631 #ifndef NO_ECOFF_DEBUGGING
15632 && symbol_get_obj (sym)->ecoff_extern_size == 0
15634 && S_GET_VALUE (sym) == 0)
15635 || (S_GET_VALUE (sym) != 0
15636 && S_GET_VALUE (sym) <= g_switch_value)))
15640 const char *segname;
15642 segname = segment_name (S_GET_SEGMENT (sym));
15643 gas_assert (strcmp (segname, ".lit8") != 0
15644 && strcmp (segname, ".lit4") != 0);
15645 change = (strcmp (segname, ".sdata") != 0
15646 && strcmp (segname, ".sbss") != 0
15647 && strncmp (segname, ".sdata.", 7) != 0
15648 && strncmp (segname, ".sbss.", 6) != 0
15649 && strncmp (segname, ".gnu.linkonce.sb.", 17) != 0
15650 && strncmp (segname, ".gnu.linkonce.s.", 16) != 0);
15655 /* We are not optimizing for the $gp register. */
15660 /* Return true if the given symbol should be considered local for SVR4 PIC. */
15663 pic_need_relax (symbolS *sym, asection *segtype)
15667 /* Handle the case of a symbol equated to another symbol. */
15668 while (symbol_equated_reloc_p (sym))
15672 /* It's possible to get a loop here in a badly written program. */
15673 n = symbol_get_value_expression (sym)->X_add_symbol;
15679 if (symbol_section_p (sym))
15682 symsec = S_GET_SEGMENT (sym);
15684 /* This must duplicate the test in adjust_reloc_syms. */
15685 return (!bfd_is_und_section (symsec)
15686 && !bfd_is_abs_section (symsec)
15687 && !bfd_is_com_section (symsec)
15688 && !s_is_linkonce (sym, segtype)
15689 /* A global or weak symbol is treated as external. */
15690 && (!S_IS_WEAK (sym) && !S_IS_EXTERNAL (sym)));
15694 /* Given a mips16 variant frag FRAGP, return non-zero if it needs an
15695 extended opcode. SEC is the section the frag is in. */
15698 mips16_extended_frag (fragS *fragp, asection *sec, long stretch)
15701 const struct mips16_immed_operand *op;
15703 int mintiny, maxtiny;
15707 if (RELAX_MIPS16_USER_SMALL (fragp->fr_subtype))
15709 if (RELAX_MIPS16_USER_EXT (fragp->fr_subtype))
15712 type = RELAX_MIPS16_TYPE (fragp->fr_subtype);
15713 op = mips16_immed_operands;
15714 while (op->type != type)
15717 gas_assert (op < mips16_immed_operands + MIPS16_NUM_IMMED);
15722 if (type == '<' || type == '>' || type == '[' || type == ']')
15725 maxtiny = 1 << op->nbits;
15730 maxtiny = (1 << op->nbits) - 1;
15735 mintiny = - (1 << (op->nbits - 1));
15736 maxtiny = (1 << (op->nbits - 1)) - 1;
15739 sym_frag = symbol_get_frag (fragp->fr_symbol);
15740 val = S_GET_VALUE (fragp->fr_symbol);
15741 symsec = S_GET_SEGMENT (fragp->fr_symbol);
15747 /* We won't have the section when we are called from
15748 mips_relax_frag. However, we will always have been called
15749 from md_estimate_size_before_relax first. If this is a
15750 branch to a different section, we mark it as such. If SEC is
15751 NULL, and the frag is not marked, then it must be a branch to
15752 the same section. */
15755 if (RELAX_MIPS16_LONG_BRANCH (fragp->fr_subtype))
15760 /* Must have been called from md_estimate_size_before_relax. */
15763 fragp->fr_subtype =
15764 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
15766 /* FIXME: We should support this, and let the linker
15767 catch branches and loads that are out of range. */
15768 as_bad_where (fragp->fr_file, fragp->fr_line,
15769 _("unsupported PC relative reference to different section"));
15773 if (fragp != sym_frag && sym_frag->fr_address == 0)
15774 /* Assume non-extended on the first relaxation pass.
15775 The address we have calculated will be bogus if this is
15776 a forward branch to another frag, as the forward frag
15777 will have fr_address == 0. */
15781 /* In this case, we know for sure that the symbol fragment is in
15782 the same section. If the relax_marker of the symbol fragment
15783 differs from the relax_marker of this fragment, we have not
15784 yet adjusted the symbol fragment fr_address. We want to add
15785 in STRETCH in order to get a better estimate of the address.
15786 This particularly matters because of the shift bits. */
15788 && sym_frag->relax_marker != fragp->relax_marker)
15792 /* Adjust stretch for any alignment frag. Note that if have
15793 been expanding the earlier code, the symbol may be
15794 defined in what appears to be an earlier frag. FIXME:
15795 This doesn't handle the fr_subtype field, which specifies
15796 a maximum number of bytes to skip when doing an
15798 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
15800 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
15803 stretch = - ((- stretch)
15804 & ~ ((1 << (int) f->fr_offset) - 1));
15806 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
15815 addr = fragp->fr_address + fragp->fr_fix;
15817 /* The base address rules are complicated. The base address of
15818 a branch is the following instruction. The base address of a
15819 PC relative load or add is the instruction itself, but if it
15820 is in a delay slot (in which case it can not be extended) use
15821 the address of the instruction whose delay slot it is in. */
15822 if (type == 'p' || type == 'q')
15826 /* If we are currently assuming that this frag should be
15827 extended, then, the current address is two bytes
15829 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
15832 /* Ignore the low bit in the target, since it will be set
15833 for a text label. */
15834 if ((val & 1) != 0)
15837 else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype))
15839 else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype))
15842 val -= addr & ~ ((1 << op->shift) - 1);
15844 /* Branch offsets have an implicit 0 in the lowest bit. */
15845 if (type == 'p' || type == 'q')
15848 /* If any of the shifted bits are set, we must use an extended
15849 opcode. If the address depends on the size of this
15850 instruction, this can lead to a loop, so we arrange to always
15851 use an extended opcode. We only check this when we are in
15852 the main relaxation loop, when SEC is NULL. */
15853 if ((val & ((1 << op->shift) - 1)) != 0 && sec == NULL)
15855 fragp->fr_subtype =
15856 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
15860 /* If we are about to mark a frag as extended because the value
15861 is precisely maxtiny + 1, then there is a chance of an
15862 infinite loop as in the following code:
15867 In this case when the la is extended, foo is 0x3fc bytes
15868 away, so the la can be shrunk, but then foo is 0x400 away, so
15869 the la must be extended. To avoid this loop, we mark the
15870 frag as extended if it was small, and is about to become
15871 extended with a value of maxtiny + 1. */
15872 if (val == ((maxtiny + 1) << op->shift)
15873 && ! RELAX_MIPS16_EXTENDED (fragp->fr_subtype)
15876 fragp->fr_subtype =
15877 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
15881 else if (symsec != absolute_section && sec != NULL)
15882 as_bad_where (fragp->fr_file, fragp->fr_line, _("unsupported relocation"));
15884 if ((val & ((1 << op->shift) - 1)) != 0
15885 || val < (mintiny << op->shift)
15886 || val > (maxtiny << op->shift))
15892 /* Compute the length of a branch sequence, and adjust the
15893 RELAX_BRANCH_TOOFAR bit accordingly. If FRAGP is NULL, the
15894 worst-case length is computed, with UPDATE being used to indicate
15895 whether an unconditional (-1), branch-likely (+1) or regular (0)
15896 branch is to be computed. */
15898 relaxed_branch_length (fragS *fragp, asection *sec, int update)
15900 bfd_boolean toofar;
15904 && S_IS_DEFINED (fragp->fr_symbol)
15905 && sec == S_GET_SEGMENT (fragp->fr_symbol))
15910 val = S_GET_VALUE (fragp->fr_symbol) + fragp->fr_offset;
15912 addr = fragp->fr_address + fragp->fr_fix + 4;
15916 toofar = val < - (0x8000 << 2) || val >= (0x8000 << 2);
15919 /* If the symbol is not defined or it's in a different segment,
15920 assume the user knows what's going on and emit a short
15926 if (fragp && update && toofar != RELAX_BRANCH_TOOFAR (fragp->fr_subtype))
15928 = RELAX_BRANCH_ENCODE (RELAX_BRANCH_AT (fragp->fr_subtype),
15929 RELAX_BRANCH_UNCOND (fragp->fr_subtype),
15930 RELAX_BRANCH_LIKELY (fragp->fr_subtype),
15931 RELAX_BRANCH_LINK (fragp->fr_subtype),
15937 if (fragp ? RELAX_BRANCH_LIKELY (fragp->fr_subtype) : (update > 0))
15940 if (mips_pic != NO_PIC)
15942 /* Additional space for PIC loading of target address. */
15944 if (mips_opts.isa == ISA_MIPS1)
15945 /* Additional space for $at-stabilizing nop. */
15949 /* If branch is conditional. */
15950 if (fragp ? !RELAX_BRANCH_UNCOND (fragp->fr_subtype) : (update >= 0))
15957 /* Compute the length of a branch sequence, and adjust the
15958 RELAX_MICROMIPS_TOOFAR32 bit accordingly. If FRAGP is NULL, the
15959 worst-case length is computed, with UPDATE being used to indicate
15960 whether an unconditional (-1), or regular (0) branch is to be
15964 relaxed_micromips_32bit_branch_length (fragS *fragp, asection *sec, int update)
15966 bfd_boolean toofar;
15970 && S_IS_DEFINED (fragp->fr_symbol)
15971 && sec == S_GET_SEGMENT (fragp->fr_symbol))
15976 val = S_GET_VALUE (fragp->fr_symbol) + fragp->fr_offset;
15977 /* Ignore the low bit in the target, since it will be set
15978 for a text label. */
15979 if ((val & 1) != 0)
15982 addr = fragp->fr_address + fragp->fr_fix + 4;
15986 toofar = val < - (0x8000 << 1) || val >= (0x8000 << 1);
15989 /* If the symbol is not defined or it's in a different segment,
15990 assume the user knows what's going on and emit a short
15996 if (fragp && update
15997 && toofar != RELAX_MICROMIPS_TOOFAR32 (fragp->fr_subtype))
15998 fragp->fr_subtype = (toofar
15999 ? RELAX_MICROMIPS_MARK_TOOFAR32 (fragp->fr_subtype)
16000 : RELAX_MICROMIPS_CLEAR_TOOFAR32 (fragp->fr_subtype));
16005 bfd_boolean compact_known = fragp != NULL;
16006 bfd_boolean compact = FALSE;
16007 bfd_boolean uncond;
16010 compact = RELAX_MICROMIPS_COMPACT (fragp->fr_subtype);
16012 uncond = RELAX_MICROMIPS_UNCOND (fragp->fr_subtype);
16014 uncond = update < 0;
16016 /* If label is out of range, we turn branch <br>:
16018 <br> label # 4 bytes
16024 nop # 2 bytes if compact && !PIC
16027 if (mips_pic == NO_PIC && (!compact_known || compact))
16030 /* If assembling PIC code, we further turn:
16036 lw/ld at, %got(label)(gp) # 4 bytes
16037 d/addiu at, %lo(label) # 4 bytes
16040 if (mips_pic != NO_PIC)
16043 /* If branch <br> is conditional, we prepend negated branch <brneg>:
16045 <brneg> 0f # 4 bytes
16046 nop # 2 bytes if !compact
16049 length += (compact_known && compact) ? 4 : 6;
16055 /* Compute the length of a branch, and adjust the RELAX_MICROMIPS_TOOFAR16
16056 bit accordingly. */
16059 relaxed_micromips_16bit_branch_length (fragS *fragp, asection *sec, int update)
16061 bfd_boolean toofar;
16064 && S_IS_DEFINED (fragp->fr_symbol)
16065 && sec == S_GET_SEGMENT (fragp->fr_symbol))
16071 val = S_GET_VALUE (fragp->fr_symbol) + fragp->fr_offset;
16072 /* Ignore the low bit in the target, since it will be set
16073 for a text label. */
16074 if ((val & 1) != 0)
16077 /* Assume this is a 2-byte branch. */
16078 addr = fragp->fr_address + fragp->fr_fix + 2;
16080 /* We try to avoid the infinite loop by not adding 2 more bytes for
16085 type = RELAX_MICROMIPS_TYPE (fragp->fr_subtype);
16087 toofar = val < - (0x200 << 1) || val >= (0x200 << 1);
16088 else if (type == 'E')
16089 toofar = val < - (0x40 << 1) || val >= (0x40 << 1);
16094 /* If the symbol is not defined or it's in a different segment,
16095 we emit a normal 32-bit branch. */
16098 if (fragp && update
16099 && toofar != RELAX_MICROMIPS_TOOFAR16 (fragp->fr_subtype))
16101 = toofar ? RELAX_MICROMIPS_MARK_TOOFAR16 (fragp->fr_subtype)
16102 : RELAX_MICROMIPS_CLEAR_TOOFAR16 (fragp->fr_subtype);
16110 /* Estimate the size of a frag before relaxing. Unless this is the
16111 mips16, we are not really relaxing here, and the final size is
16112 encoded in the subtype information. For the mips16, we have to
16113 decide whether we are using an extended opcode or not. */
16116 md_estimate_size_before_relax (fragS *fragp, asection *segtype)
16120 if (RELAX_BRANCH_P (fragp->fr_subtype))
16123 fragp->fr_var = relaxed_branch_length (fragp, segtype, FALSE);
16125 return fragp->fr_var;
16128 if (RELAX_MIPS16_P (fragp->fr_subtype))
16129 /* We don't want to modify the EXTENDED bit here; it might get us
16130 into infinite loops. We change it only in mips_relax_frag(). */
16131 return (RELAX_MIPS16_EXTENDED (fragp->fr_subtype) ? 4 : 2);
16133 if (RELAX_MICROMIPS_P (fragp->fr_subtype))
16137 if (RELAX_MICROMIPS_TYPE (fragp->fr_subtype) != 0)
16138 length = relaxed_micromips_16bit_branch_length (fragp, segtype, FALSE);
16139 if (length == 4 && RELAX_MICROMIPS_RELAX32 (fragp->fr_subtype))
16140 length = relaxed_micromips_32bit_branch_length (fragp, segtype, FALSE);
16141 fragp->fr_var = length;
16146 if (mips_pic == NO_PIC)
16147 change = nopic_need_relax (fragp->fr_symbol, 0);
16148 else if (mips_pic == SVR4_PIC)
16149 change = pic_need_relax (fragp->fr_symbol, segtype);
16150 else if (mips_pic == VXWORKS_PIC)
16151 /* For vxworks, GOT16 relocations never have a corresponding LO16. */
16158 fragp->fr_subtype |= RELAX_USE_SECOND;
16159 return -RELAX_FIRST (fragp->fr_subtype);
16162 return -RELAX_SECOND (fragp->fr_subtype);
16165 /* This is called to see whether a reloc against a defined symbol
16166 should be converted into a reloc against a section. */
16169 mips_fix_adjustable (fixS *fixp)
16171 if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT
16172 || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
16175 if (fixp->fx_addsy == NULL)
16178 /* If symbol SYM is in a mergeable section, relocations of the form
16179 SYM + 0 can usually be made section-relative. The mergeable data
16180 is then identified by the section offset rather than by the symbol.
16182 However, if we're generating REL LO16 relocations, the offset is split
16183 between the LO16 and parterning high part relocation. The linker will
16184 need to recalculate the complete offset in order to correctly identify
16187 The linker has traditionally not looked for the parterning high part
16188 relocation, and has thus allowed orphaned R_MIPS_LO16 relocations to be
16189 placed anywhere. Rather than break backwards compatibility by changing
16190 this, it seems better not to force the issue, and instead keep the
16191 original symbol. This will work with either linker behavior. */
16192 if ((lo16_reloc_p (fixp->fx_r_type)
16193 || reloc_needs_lo_p (fixp->fx_r_type))
16194 && HAVE_IN_PLACE_ADDENDS
16195 && (S_GET_SEGMENT (fixp->fx_addsy)->flags & SEC_MERGE) != 0)
16198 /* There is no place to store an in-place offset for JALR relocations.
16199 Likewise an in-range offset of limited PC-relative relocations may
16200 overflow the in-place relocatable field if recalculated against the
16201 start address of the symbol's containing section. */
16202 if (HAVE_IN_PLACE_ADDENDS
16203 && (limited_pcrel_reloc_p (fixp->fx_r_type)
16204 || jalr_reloc_p (fixp->fx_r_type)))
16207 /* R_MIPS16_26 relocations against non-MIPS16 functions might resolve
16208 to a floating-point stub. The same is true for non-R_MIPS16_26
16209 relocations against MIPS16 functions; in this case, the stub becomes
16210 the function's canonical address.
16212 Floating-point stubs are stored in unique .mips16.call.* or
16213 .mips16.fn.* sections. If a stub T for function F is in section S,
16214 the first relocation in section S must be against F; this is how the
16215 linker determines the target function. All relocations that might
16216 resolve to T must also be against F. We therefore have the following
16217 restrictions, which are given in an intentionally-redundant way:
16219 1. We cannot reduce R_MIPS16_26 relocations against non-MIPS16
16222 2. We cannot reduce a stub's relocations against non-MIPS16 symbols
16223 if that stub might be used.
16225 3. We cannot reduce non-R_MIPS16_26 relocations against MIPS16
16228 4. We cannot reduce a stub's relocations against MIPS16 symbols if
16229 that stub might be used.
16231 There is a further restriction:
16233 5. We cannot reduce jump relocations (R_MIPS_26, R_MIPS16_26 or
16234 R_MICROMIPS_26_S1) against MIPS16 or microMIPS symbols on
16235 targets with in-place addends; the relocation field cannot
16236 encode the low bit.
16238 For simplicity, we deal with (3)-(4) by not reducing _any_ relocation
16239 against a MIPS16 symbol. We deal with (5) by by not reducing any
16240 such relocations on REL targets.
16242 We deal with (1)-(2) by saying that, if there's a R_MIPS16_26
16243 relocation against some symbol R, no relocation against R may be
16244 reduced. (Note that this deals with (2) as well as (1) because
16245 relocations against global symbols will never be reduced on ELF
16246 targets.) This approach is a little simpler than trying to detect
16247 stub sections, and gives the "all or nothing" per-symbol consistency
16248 that we have for MIPS16 symbols. */
16249 if (fixp->fx_subsy == NULL
16250 && (ELF_ST_IS_MIPS16 (S_GET_OTHER (fixp->fx_addsy))
16251 || *symbol_get_tc (fixp->fx_addsy)
16252 || (HAVE_IN_PLACE_ADDENDS
16253 && ELF_ST_IS_MICROMIPS (S_GET_OTHER (fixp->fx_addsy))
16254 && jmp_reloc_p (fixp->fx_r_type))))
16260 /* Translate internal representation of relocation info to BFD target
16264 tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixp)
16266 static arelent *retval[4];
16268 bfd_reloc_code_real_type code;
16270 memset (retval, 0, sizeof(retval));
16271 reloc = retval[0] = (arelent *) xcalloc (1, sizeof (arelent));
16272 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
16273 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
16274 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
16276 if (fixp->fx_pcrel)
16278 gas_assert (fixp->fx_r_type == BFD_RELOC_16_PCREL_S2
16279 || fixp->fx_r_type == BFD_RELOC_MICROMIPS_7_PCREL_S1
16280 || fixp->fx_r_type == BFD_RELOC_MICROMIPS_10_PCREL_S1
16281 || fixp->fx_r_type == BFD_RELOC_MICROMIPS_16_PCREL_S1
16282 || fixp->fx_r_type == BFD_RELOC_32_PCREL);
16284 /* At this point, fx_addnumber is "symbol offset - pcrel address".
16285 Relocations want only the symbol offset. */
16286 reloc->addend = fixp->fx_addnumber + reloc->address;
16289 reloc->addend = fixp->fx_addnumber;
16291 /* Since the old MIPS ELF ABI uses Rel instead of Rela, encode the vtable
16292 entry to be used in the relocation's section offset. */
16293 if (! HAVE_NEWABI && fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
16295 reloc->address = reloc->addend;
16299 code = fixp->fx_r_type;
16301 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
16302 if (reloc->howto == NULL)
16304 as_bad_where (fixp->fx_file, fixp->fx_line,
16305 _("Can not represent %s relocation in this object file format"),
16306 bfd_get_reloc_code_name (code));
16313 /* Relax a machine dependent frag. This returns the amount by which
16314 the current size of the frag should change. */
16317 mips_relax_frag (asection *sec, fragS *fragp, long stretch)
16319 if (RELAX_BRANCH_P (fragp->fr_subtype))
16321 offsetT old_var = fragp->fr_var;
16323 fragp->fr_var = relaxed_branch_length (fragp, sec, TRUE);
16325 return fragp->fr_var - old_var;
16328 if (RELAX_MICROMIPS_P (fragp->fr_subtype))
16330 offsetT old_var = fragp->fr_var;
16331 offsetT new_var = 4;
16333 if (RELAX_MICROMIPS_TYPE (fragp->fr_subtype) != 0)
16334 new_var = relaxed_micromips_16bit_branch_length (fragp, sec, TRUE);
16335 if (new_var == 4 && RELAX_MICROMIPS_RELAX32 (fragp->fr_subtype))
16336 new_var = relaxed_micromips_32bit_branch_length (fragp, sec, TRUE);
16337 fragp->fr_var = new_var;
16339 return new_var - old_var;
16342 if (! RELAX_MIPS16_P (fragp->fr_subtype))
16345 if (mips16_extended_frag (fragp, NULL, stretch))
16347 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
16349 fragp->fr_subtype = RELAX_MIPS16_MARK_EXTENDED (fragp->fr_subtype);
16354 if (! RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
16356 fragp->fr_subtype = RELAX_MIPS16_CLEAR_EXTENDED (fragp->fr_subtype);
16363 /* Convert a machine dependent frag. */
16366 md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, segT asec, fragS *fragp)
16368 if (RELAX_BRANCH_P (fragp->fr_subtype))
16371 unsigned long insn;
16375 buf = fragp->fr_literal + fragp->fr_fix;
16376 insn = read_insn (buf);
16378 if (!RELAX_BRANCH_TOOFAR (fragp->fr_subtype))
16380 /* We generate a fixup instead of applying it right now
16381 because, if there are linker relaxations, we're going to
16382 need the relocations. */
16383 exp.X_op = O_symbol;
16384 exp.X_add_symbol = fragp->fr_symbol;
16385 exp.X_add_number = fragp->fr_offset;
16387 fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 4, &exp, TRUE,
16388 BFD_RELOC_16_PCREL_S2);
16389 fixp->fx_file = fragp->fr_file;
16390 fixp->fx_line = fragp->fr_line;
16392 buf = write_insn (buf, insn);
16398 as_warn_where (fragp->fr_file, fragp->fr_line,
16399 _("Relaxed out-of-range branch into a jump"));
16401 if (RELAX_BRANCH_UNCOND (fragp->fr_subtype))
16404 if (!RELAX_BRANCH_LIKELY (fragp->fr_subtype))
16406 /* Reverse the branch. */
16407 switch ((insn >> 28) & 0xf)
16410 /* bc[0-3][tf]l? instructions can have the condition
16411 reversed by tweaking a single TF bit, and their
16412 opcodes all have 0x4???????. */
16413 gas_assert ((insn & 0xf3e00000) == 0x41000000);
16414 insn ^= 0x00010000;
16418 /* bltz 0x04000000 bgez 0x04010000
16419 bltzal 0x04100000 bgezal 0x04110000 */
16420 gas_assert ((insn & 0xfc0e0000) == 0x04000000);
16421 insn ^= 0x00010000;
16425 /* beq 0x10000000 bne 0x14000000
16426 blez 0x18000000 bgtz 0x1c000000 */
16427 insn ^= 0x04000000;
16435 if (RELAX_BRANCH_LINK (fragp->fr_subtype))
16437 /* Clear the and-link bit. */
16438 gas_assert ((insn & 0xfc1c0000) == 0x04100000);
16440 /* bltzal 0x04100000 bgezal 0x04110000
16441 bltzall 0x04120000 bgezall 0x04130000 */
16442 insn &= ~0x00100000;
16445 /* Branch over the branch (if the branch was likely) or the
16446 full jump (not likely case). Compute the offset from the
16447 current instruction to branch to. */
16448 if (RELAX_BRANCH_LIKELY (fragp->fr_subtype))
16452 /* How many bytes in instructions we've already emitted? */
16453 i = buf - fragp->fr_literal - fragp->fr_fix;
16454 /* How many bytes in instructions from here to the end? */
16455 i = fragp->fr_var - i;
16457 /* Convert to instruction count. */
16459 /* Branch counts from the next instruction. */
16462 /* Branch over the jump. */
16463 buf = write_insn (buf, insn);
16466 buf = write_insn (buf, 0);
16468 if (RELAX_BRANCH_LIKELY (fragp->fr_subtype))
16470 /* beql $0, $0, 2f */
16472 /* Compute the PC offset from the current instruction to
16473 the end of the variable frag. */
16474 /* How many bytes in instructions we've already emitted? */
16475 i = buf - fragp->fr_literal - fragp->fr_fix;
16476 /* How many bytes in instructions from here to the end? */
16477 i = fragp->fr_var - i;
16478 /* Convert to instruction count. */
16480 /* Don't decrement i, because we want to branch over the
16484 buf = write_insn (buf, insn);
16485 buf = write_insn (buf, 0);
16489 if (mips_pic == NO_PIC)
16492 insn = (RELAX_BRANCH_LINK (fragp->fr_subtype)
16493 ? 0x0c000000 : 0x08000000);
16494 exp.X_op = O_symbol;
16495 exp.X_add_symbol = fragp->fr_symbol;
16496 exp.X_add_number = fragp->fr_offset;
16498 fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 4, &exp,
16499 FALSE, BFD_RELOC_MIPS_JMP);
16500 fixp->fx_file = fragp->fr_file;
16501 fixp->fx_line = fragp->fr_line;
16503 buf = write_insn (buf, insn);
16507 unsigned long at = RELAX_BRANCH_AT (fragp->fr_subtype);
16509 /* lw/ld $at, <sym>($gp) R_MIPS_GOT16 */
16510 insn = HAVE_64BIT_ADDRESSES ? 0xdf800000 : 0x8f800000;
16511 insn |= at << OP_SH_RT;
16512 exp.X_op = O_symbol;
16513 exp.X_add_symbol = fragp->fr_symbol;
16514 exp.X_add_number = fragp->fr_offset;
16516 if (fragp->fr_offset)
16518 exp.X_add_symbol = make_expr_symbol (&exp);
16519 exp.X_add_number = 0;
16522 fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 4, &exp,
16523 FALSE, BFD_RELOC_MIPS_GOT16);
16524 fixp->fx_file = fragp->fr_file;
16525 fixp->fx_line = fragp->fr_line;
16527 buf = write_insn (buf, insn);
16529 if (mips_opts.isa == ISA_MIPS1)
16531 buf = write_insn (buf, 0);
16533 /* d/addiu $at, $at, <sym> R_MIPS_LO16 */
16534 insn = HAVE_64BIT_ADDRESSES ? 0x64000000 : 0x24000000;
16535 insn |= at << OP_SH_RS | at << OP_SH_RT;
16537 fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 4, &exp,
16538 FALSE, BFD_RELOC_LO16);
16539 fixp->fx_file = fragp->fr_file;
16540 fixp->fx_line = fragp->fr_line;
16542 buf = write_insn (buf, insn);
16545 if (RELAX_BRANCH_LINK (fragp->fr_subtype))
16549 insn |= at << OP_SH_RS;
16551 buf = write_insn (buf, insn);
16555 fragp->fr_fix += fragp->fr_var;
16556 gas_assert (buf == fragp->fr_literal + fragp->fr_fix);
16560 /* Relax microMIPS branches. */
16561 if (RELAX_MICROMIPS_P (fragp->fr_subtype))
16563 char *buf = fragp->fr_literal + fragp->fr_fix;
16564 bfd_boolean compact = RELAX_MICROMIPS_COMPACT (fragp->fr_subtype);
16565 bfd_boolean al = RELAX_MICROMIPS_LINK (fragp->fr_subtype);
16566 int type = RELAX_MICROMIPS_TYPE (fragp->fr_subtype);
16567 bfd_boolean short_ds;
16568 unsigned long insn;
16572 exp.X_op = O_symbol;
16573 exp.X_add_symbol = fragp->fr_symbol;
16574 exp.X_add_number = fragp->fr_offset;
16576 fragp->fr_fix += fragp->fr_var;
16578 /* Handle 16-bit branches that fit or are forced to fit. */
16579 if (type != 0 && !RELAX_MICROMIPS_TOOFAR16 (fragp->fr_subtype))
16581 /* We generate a fixup instead of applying it right now,
16582 because if there is linker relaxation, we're going to
16583 need the relocations. */
16585 fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 2, &exp, TRUE,
16586 BFD_RELOC_MICROMIPS_10_PCREL_S1);
16587 else if (type == 'E')
16588 fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 2, &exp, TRUE,
16589 BFD_RELOC_MICROMIPS_7_PCREL_S1);
16593 fixp->fx_file = fragp->fr_file;
16594 fixp->fx_line = fragp->fr_line;
16596 /* These relocations can have an addend that won't fit in
16598 fixp->fx_no_overflow = 1;
16603 /* Handle 32-bit branches that fit or are forced to fit. */
16604 if (!RELAX_MICROMIPS_RELAX32 (fragp->fr_subtype)
16605 || !RELAX_MICROMIPS_TOOFAR32 (fragp->fr_subtype))
16607 /* We generate a fixup instead of applying it right now,
16608 because if there is linker relaxation, we're going to
16609 need the relocations. */
16610 fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 4, &exp, TRUE,
16611 BFD_RELOC_MICROMIPS_16_PCREL_S1);
16612 fixp->fx_file = fragp->fr_file;
16613 fixp->fx_line = fragp->fr_line;
16619 /* Relax 16-bit branches to 32-bit branches. */
16622 insn = read_compressed_insn (buf, 2);
16624 if ((insn & 0xfc00) == 0xcc00) /* b16 */
16625 insn = 0x94000000; /* beq */
16626 else if ((insn & 0xdc00) == 0x8c00) /* beqz16/bnez16 */
16628 unsigned long regno;
16630 regno = (insn >> MICROMIPSOP_SH_MD) & MICROMIPSOP_MASK_MD;
16631 regno = micromips_to_32_reg_d_map [regno];
16632 insn = ((insn & 0x2000) << 16) | 0x94000000; /* beq/bne */
16633 insn |= regno << MICROMIPSOP_SH_RS;
16638 /* Nothing else to do, just write it out. */
16639 if (!RELAX_MICROMIPS_RELAX32 (fragp->fr_subtype)
16640 || !RELAX_MICROMIPS_TOOFAR32 (fragp->fr_subtype))
16642 buf = write_compressed_insn (buf, insn, 4);
16643 gas_assert (buf == fragp->fr_literal + fragp->fr_fix);
16648 insn = read_compressed_insn (buf, 4);
16650 /* Relax 32-bit branches to a sequence of instructions. */
16651 as_warn_where (fragp->fr_file, fragp->fr_line,
16652 _("Relaxed out-of-range branch into a jump"));
16654 /* Set the short-delay-slot bit. */
16655 short_ds = al && (insn & 0x02000000) != 0;
16657 if (!RELAX_MICROMIPS_UNCOND (fragp->fr_subtype))
16661 /* Reverse the branch. */
16662 if ((insn & 0xfc000000) == 0x94000000 /* beq */
16663 || (insn & 0xfc000000) == 0xb4000000) /* bne */
16664 insn ^= 0x20000000;
16665 else if ((insn & 0xffe00000) == 0x40000000 /* bltz */
16666 || (insn & 0xffe00000) == 0x40400000 /* bgez */
16667 || (insn & 0xffe00000) == 0x40800000 /* blez */
16668 || (insn & 0xffe00000) == 0x40c00000 /* bgtz */
16669 || (insn & 0xffe00000) == 0x40a00000 /* bnezc */
16670 || (insn & 0xffe00000) == 0x40e00000 /* beqzc */
16671 || (insn & 0xffe00000) == 0x40200000 /* bltzal */
16672 || (insn & 0xffe00000) == 0x40600000 /* bgezal */
16673 || (insn & 0xffe00000) == 0x42200000 /* bltzals */
16674 || (insn & 0xffe00000) == 0x42600000) /* bgezals */
16675 insn ^= 0x00400000;
16676 else if ((insn & 0xffe30000) == 0x43800000 /* bc1f */
16677 || (insn & 0xffe30000) == 0x43a00000 /* bc1t */
16678 || (insn & 0xffe30000) == 0x42800000 /* bc2f */
16679 || (insn & 0xffe30000) == 0x42a00000) /* bc2t */
16680 insn ^= 0x00200000;
16686 /* Clear the and-link and short-delay-slot bits. */
16687 gas_assert ((insn & 0xfda00000) == 0x40200000);
16689 /* bltzal 0x40200000 bgezal 0x40600000 */
16690 /* bltzals 0x42200000 bgezals 0x42600000 */
16691 insn &= ~0x02200000;
16694 /* Make a label at the end for use with the branch. */
16695 l = symbol_new (micromips_label_name (), asec, fragp->fr_fix, fragp);
16696 micromips_label_inc ();
16697 S_SET_OTHER (l, ELF_ST_SET_MICROMIPS (S_GET_OTHER (l)));
16700 fixp = fix_new (fragp, buf - fragp->fr_literal, 4, l, 0, TRUE,
16701 BFD_RELOC_MICROMIPS_16_PCREL_S1);
16702 fixp->fx_file = fragp->fr_file;
16703 fixp->fx_line = fragp->fr_line;
16705 /* Branch over the jump. */
16706 buf = write_compressed_insn (buf, insn, 4);
16709 buf = write_compressed_insn (buf, 0x0c00, 2);
16712 if (mips_pic == NO_PIC)
16714 unsigned long jal = short_ds ? 0x74000000 : 0xf4000000; /* jal/s */
16716 /* j/jal/jals <sym> R_MICROMIPS_26_S1 */
16717 insn = al ? jal : 0xd4000000;
16719 fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 4, &exp, FALSE,
16720 BFD_RELOC_MICROMIPS_JMP);
16721 fixp->fx_file = fragp->fr_file;
16722 fixp->fx_line = fragp->fr_line;
16724 buf = write_compressed_insn (buf, insn, 4);
16727 buf = write_compressed_insn (buf, 0x0c00, 2);
16731 unsigned long at = RELAX_MICROMIPS_AT (fragp->fr_subtype);
16732 unsigned long jalr = short_ds ? 0x45e0 : 0x45c0; /* jalr/s */
16733 unsigned long jr = compact ? 0x45a0 : 0x4580; /* jr/c */
16735 /* lw/ld $at, <sym>($gp) R_MICROMIPS_GOT16 */
16736 insn = HAVE_64BIT_ADDRESSES ? 0xdc1c0000 : 0xfc1c0000;
16737 insn |= at << MICROMIPSOP_SH_RT;
16739 if (exp.X_add_number)
16741 exp.X_add_symbol = make_expr_symbol (&exp);
16742 exp.X_add_number = 0;
16745 fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 4, &exp, FALSE,
16746 BFD_RELOC_MICROMIPS_GOT16);
16747 fixp->fx_file = fragp->fr_file;
16748 fixp->fx_line = fragp->fr_line;
16750 buf = write_compressed_insn (buf, insn, 4);
16752 /* d/addiu $at, $at, <sym> R_MICROMIPS_LO16 */
16753 insn = HAVE_64BIT_ADDRESSES ? 0x5c000000 : 0x30000000;
16754 insn |= at << MICROMIPSOP_SH_RT | at << MICROMIPSOP_SH_RS;
16756 fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 4, &exp, FALSE,
16757 BFD_RELOC_MICROMIPS_LO16);
16758 fixp->fx_file = fragp->fr_file;
16759 fixp->fx_line = fragp->fr_line;
16761 buf = write_compressed_insn (buf, insn, 4);
16763 /* jr/jrc/jalr/jalrs $at */
16764 insn = al ? jalr : jr;
16765 insn |= at << MICROMIPSOP_SH_MJ;
16767 buf = write_compressed_insn (buf, insn, 2);
16770 gas_assert (buf == fragp->fr_literal + fragp->fr_fix);
16774 if (RELAX_MIPS16_P (fragp->fr_subtype))
16777 const struct mips16_immed_operand *op;
16780 unsigned int user_length, length;
16781 unsigned long insn;
16784 type = RELAX_MIPS16_TYPE (fragp->fr_subtype);
16785 op = mips16_immed_operands;
16786 while (op->type != type)
16789 ext = RELAX_MIPS16_EXTENDED (fragp->fr_subtype);
16790 val = resolve_symbol_value (fragp->fr_symbol);
16795 addr = fragp->fr_address + fragp->fr_fix;
16797 /* The rules for the base address of a PC relative reloc are
16798 complicated; see mips16_extended_frag. */
16799 if (type == 'p' || type == 'q')
16804 /* Ignore the low bit in the target, since it will be
16805 set for a text label. */
16806 if ((val & 1) != 0)
16809 else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype))
16811 else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype))
16814 addr &= ~ (addressT) ((1 << op->shift) - 1);
16817 /* Make sure the section winds up with the alignment we have
16820 record_alignment (asec, op->shift);
16824 && (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype)
16825 || RELAX_MIPS16_DSLOT (fragp->fr_subtype)))
16826 as_warn_where (fragp->fr_file, fragp->fr_line,
16827 _("extended instruction in delay slot"));
16829 buf = fragp->fr_literal + fragp->fr_fix;
16831 insn = read_compressed_insn (buf, 2);
16833 insn |= MIPS16_EXTEND;
16835 if (RELAX_MIPS16_USER_EXT (fragp->fr_subtype))
16837 else if (RELAX_MIPS16_USER_SMALL (fragp->fr_subtype))
16842 mips16_immed (fragp->fr_file, fragp->fr_line, type,
16843 BFD_RELOC_UNUSED, val, user_length, &insn);
16845 length = (ext ? 4 : 2);
16846 gas_assert (mips16_opcode_length (insn) == length);
16847 write_compressed_insn (buf, insn, length);
16848 fragp->fr_fix += length;
16852 relax_substateT subtype = fragp->fr_subtype;
16853 bfd_boolean second_longer = (subtype & RELAX_SECOND_LONGER) != 0;
16854 bfd_boolean use_second = (subtype & RELAX_USE_SECOND) != 0;
16858 first = RELAX_FIRST (subtype);
16859 second = RELAX_SECOND (subtype);
16860 fixp = (fixS *) fragp->fr_opcode;
16862 /* If the delay slot chosen does not match the size of the instruction,
16863 then emit a warning. */
16864 if ((!use_second && (subtype & RELAX_DELAY_SLOT_SIZE_FIRST) != 0)
16865 || (use_second && (subtype & RELAX_DELAY_SLOT_SIZE_SECOND) != 0))
16870 s = subtype & (RELAX_DELAY_SLOT_16BIT
16871 | RELAX_DELAY_SLOT_SIZE_FIRST
16872 | RELAX_DELAY_SLOT_SIZE_SECOND);
16873 msg = macro_warning (s);
16875 as_warn_where (fragp->fr_file, fragp->fr_line, "%s", msg);
16879 /* Possibly emit a warning if we've chosen the longer option. */
16880 if (use_second == second_longer)
16886 & (RELAX_SECOND_LONGER | RELAX_NOMACRO | RELAX_DELAY_SLOT));
16887 msg = macro_warning (s);
16889 as_warn_where (fragp->fr_file, fragp->fr_line, "%s", msg);
16893 /* Go through all the fixups for the first sequence. Disable them
16894 (by marking them as done) if we're going to use the second
16895 sequence instead. */
16897 && fixp->fx_frag == fragp
16898 && fixp->fx_where < fragp->fr_fix - second)
16900 if (subtype & RELAX_USE_SECOND)
16902 fixp = fixp->fx_next;
16905 /* Go through the fixups for the second sequence. Disable them if
16906 we're going to use the first sequence, otherwise adjust their
16907 addresses to account for the relaxation. */
16908 while (fixp && fixp->fx_frag == fragp)
16910 if (subtype & RELAX_USE_SECOND)
16911 fixp->fx_where -= first;
16914 fixp = fixp->fx_next;
16917 /* Now modify the frag contents. */
16918 if (subtype & RELAX_USE_SECOND)
16922 start = fragp->fr_literal + fragp->fr_fix - first - second;
16923 memmove (start, start + first, second);
16924 fragp->fr_fix -= first;
16927 fragp->fr_fix -= second;
16931 /* This function is called after the relocs have been generated.
16932 We've been storing mips16 text labels as odd. Here we convert them
16933 back to even for the convenience of the debugger. */
16936 mips_frob_file_after_relocs (void)
16939 unsigned int count, i;
16941 syms = bfd_get_outsymbols (stdoutput);
16942 count = bfd_get_symcount (stdoutput);
16943 for (i = 0; i < count; i++, syms++)
16944 if (ELF_ST_IS_COMPRESSED (elf_symbol (*syms)->internal_elf_sym.st_other)
16945 && ((*syms)->value & 1) != 0)
16947 (*syms)->value &= ~1;
16948 /* If the symbol has an odd size, it was probably computed
16949 incorrectly, so adjust that as well. */
16950 if ((elf_symbol (*syms)->internal_elf_sym.st_size & 1) != 0)
16951 ++elf_symbol (*syms)->internal_elf_sym.st_size;
16955 /* This function is called whenever a label is defined, including fake
16956 labels instantiated off the dot special symbol. It is used when
16957 handling branch delays; if a branch has a label, we assume we cannot
16958 move it. This also bumps the value of the symbol by 1 in compressed
16962 mips_record_label (symbolS *sym)
16964 segment_info_type *si = seg_info (now_seg);
16965 struct insn_label_list *l;
16967 if (free_insn_labels == NULL)
16968 l = (struct insn_label_list *) xmalloc (sizeof *l);
16971 l = free_insn_labels;
16972 free_insn_labels = l->next;
16976 l->next = si->label_list;
16977 si->label_list = l;
16980 /* This function is called as tc_frob_label() whenever a label is defined
16981 and adds a DWARF-2 record we only want for true labels. */
16984 mips_define_label (symbolS *sym)
16986 mips_record_label (sym);
16987 dwarf2_emit_label (sym);
16990 /* This function is called by tc_new_dot_label whenever a new dot symbol
16994 mips_add_dot_label (symbolS *sym)
16996 mips_record_label (sym);
16997 if (mips_assembling_insn && HAVE_CODE_COMPRESSION)
16998 mips_compressed_mark_label (sym);
17001 /* Some special processing for a MIPS ELF file. */
17004 mips_elf_final_processing (void)
17006 /* Write out the register information. */
17007 if (mips_abi != N64_ABI)
17011 s.ri_gprmask = mips_gprmask;
17012 s.ri_cprmask[0] = mips_cprmask[0];
17013 s.ri_cprmask[1] = mips_cprmask[1];
17014 s.ri_cprmask[2] = mips_cprmask[2];
17015 s.ri_cprmask[3] = mips_cprmask[3];
17016 /* The gp_value field is set by the MIPS ELF backend. */
17018 bfd_mips_elf32_swap_reginfo_out (stdoutput, &s,
17019 ((Elf32_External_RegInfo *)
17020 mips_regmask_frag));
17024 Elf64_Internal_RegInfo s;
17026 s.ri_gprmask = mips_gprmask;
17028 s.ri_cprmask[0] = mips_cprmask[0];
17029 s.ri_cprmask[1] = mips_cprmask[1];
17030 s.ri_cprmask[2] = mips_cprmask[2];
17031 s.ri_cprmask[3] = mips_cprmask[3];
17032 /* The gp_value field is set by the MIPS ELF backend. */
17034 bfd_mips_elf64_swap_reginfo_out (stdoutput, &s,
17035 ((Elf64_External_RegInfo *)
17036 mips_regmask_frag));
17039 /* Set the MIPS ELF flag bits. FIXME: There should probably be some
17040 sort of BFD interface for this. */
17041 if (mips_any_noreorder)
17042 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_NOREORDER;
17043 if (mips_pic != NO_PIC)
17045 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_PIC;
17046 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_CPIC;
17049 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_CPIC;
17051 /* Set MIPS ELF flags for ASEs. Note that not all ASEs have flags
17052 defined at present; this might need to change in future. */
17053 if (file_ase_mips16)
17054 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ARCH_ASE_M16;
17055 if (file_ase_micromips)
17056 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ARCH_ASE_MICROMIPS;
17057 if (file_ase & ASE_MDMX)
17058 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ARCH_ASE_MDMX;
17060 /* Set the MIPS ELF ABI flags. */
17061 if (mips_abi == O32_ABI && USE_E_MIPS_ABI_O32)
17062 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O32;
17063 else if (mips_abi == O64_ABI)
17064 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O64;
17065 else if (mips_abi == EABI_ABI)
17067 if (!file_mips_gp32)
17068 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI64;
17070 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI32;
17072 else if (mips_abi == N32_ABI)
17073 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ABI2;
17075 /* Nothing to do for N64_ABI. */
17077 if (mips_32bitmode)
17078 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_32BITMODE;
17080 if (mips_flag_nan2008)
17081 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_NAN2008;
17083 #if 0 /* XXX FIXME */
17084 /* 32 bit code with 64 bit FP registers. */
17085 if (!file_mips_fp32 && ABI_NEEDS_32BIT_REGS (mips_abi))
17086 elf_elfheader (stdoutput)->e_flags |= ???;
17090 typedef struct proc {
17092 symbolS *func_end_sym;
17093 unsigned long reg_mask;
17094 unsigned long reg_offset;
17095 unsigned long fpreg_mask;
17096 unsigned long fpreg_offset;
17097 unsigned long frame_offset;
17098 unsigned long frame_reg;
17099 unsigned long pc_reg;
17102 static procS cur_proc;
17103 static procS *cur_proc_ptr;
17104 static int numprocs;
17106 /* Implement NOP_OPCODE. We encode a MIPS16 nop as "1", a microMIPS nop
17107 as "2", and a normal nop as "0". */
17109 #define NOP_OPCODE_MIPS 0
17110 #define NOP_OPCODE_MIPS16 1
17111 #define NOP_OPCODE_MICROMIPS 2
17114 mips_nop_opcode (void)
17116 if (seg_info (now_seg)->tc_segment_info_data.micromips)
17117 return NOP_OPCODE_MICROMIPS;
17118 else if (seg_info (now_seg)->tc_segment_info_data.mips16)
17119 return NOP_OPCODE_MIPS16;
17121 return NOP_OPCODE_MIPS;
17124 /* Fill in an rs_align_code fragment. Unlike elsewhere we want to use
17125 32-bit microMIPS NOPs here (if applicable). */
17128 mips_handle_align (fragS *fragp)
17132 int bytes, size, excess;
17135 if (fragp->fr_type != rs_align_code)
17138 p = fragp->fr_literal + fragp->fr_fix;
17140 switch (nop_opcode)
17142 case NOP_OPCODE_MICROMIPS:
17143 opcode = micromips_nop32_insn.insn_opcode;
17146 case NOP_OPCODE_MIPS16:
17147 opcode = mips16_nop_insn.insn_opcode;
17150 case NOP_OPCODE_MIPS:
17152 opcode = nop_insn.insn_opcode;
17157 bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
17158 excess = bytes % size;
17160 /* Handle the leading part if we're not inserting a whole number of
17161 instructions, and make it the end of the fixed part of the frag.
17162 Try to fit in a short microMIPS NOP if applicable and possible,
17163 and use zeroes otherwise. */
17164 gas_assert (excess < 4);
17165 fragp->fr_fix += excess;
17170 /* Fall through. */
17172 if (nop_opcode == NOP_OPCODE_MICROMIPS && !mips_opts.insn32)
17174 p = write_compressed_insn (p, micromips_nop16_insn.insn_opcode, 2);
17178 /* Fall through. */
17181 /* Fall through. */
17186 md_number_to_chars (p, opcode, size);
17187 fragp->fr_var = size;
17191 md_obj_begin (void)
17198 /* Check for premature end, nesting errors, etc. */
17200 as_warn (_("missing .end at end of assembly"));
17209 if (*input_line_pointer == '-')
17211 ++input_line_pointer;
17214 if (!ISDIGIT (*input_line_pointer))
17215 as_bad (_("expected simple number"));
17216 if (input_line_pointer[0] == '0')
17218 if (input_line_pointer[1] == 'x')
17220 input_line_pointer += 2;
17221 while (ISXDIGIT (*input_line_pointer))
17224 val |= hex_value (*input_line_pointer++);
17226 return negative ? -val : val;
17230 ++input_line_pointer;
17231 while (ISDIGIT (*input_line_pointer))
17234 val |= *input_line_pointer++ - '0';
17236 return negative ? -val : val;
17239 if (!ISDIGIT (*input_line_pointer))
17241 printf (_(" *input_line_pointer == '%c' 0x%02x\n"),
17242 *input_line_pointer, *input_line_pointer);
17243 as_warn (_("invalid number"));
17246 while (ISDIGIT (*input_line_pointer))
17249 val += *input_line_pointer++ - '0';
17251 return negative ? -val : val;
17254 /* The .file directive; just like the usual .file directive, but there
17255 is an initial number which is the ECOFF file index. In the non-ECOFF
17256 case .file implies DWARF-2. */
17259 s_mips_file (int x ATTRIBUTE_UNUSED)
17261 static int first_file_directive = 0;
17263 if (ECOFF_DEBUGGING)
17272 filename = dwarf2_directive_file (0);
17274 /* Versions of GCC up to 3.1 start files with a ".file"
17275 directive even for stabs output. Make sure that this
17276 ".file" is handled. Note that you need a version of GCC
17277 after 3.1 in order to support DWARF-2 on MIPS. */
17278 if (filename != NULL && ! first_file_directive)
17280 (void) new_logical_line (filename, -1);
17281 s_app_file_string (filename, 0);
17283 first_file_directive = 1;
17287 /* The .loc directive, implying DWARF-2. */
17290 s_mips_loc (int x ATTRIBUTE_UNUSED)
17292 if (!ECOFF_DEBUGGING)
17293 dwarf2_directive_loc (0);
17296 /* The .end directive. */
17299 s_mips_end (int x ATTRIBUTE_UNUSED)
17303 /* Following functions need their own .frame and .cprestore directives. */
17304 mips_frame_reg_valid = 0;
17305 mips_cprestore_valid = 0;
17307 if (!is_end_of_line[(unsigned char) *input_line_pointer])
17310 demand_empty_rest_of_line ();
17315 if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) == 0)
17316 as_warn (_(".end not in text section"));
17320 as_warn (_(".end directive without a preceding .ent directive."));
17321 demand_empty_rest_of_line ();
17327 gas_assert (S_GET_NAME (p));
17328 if (strcmp (S_GET_NAME (p), S_GET_NAME (cur_proc_ptr->func_sym)))
17329 as_warn (_(".end symbol does not match .ent symbol."));
17331 if (debug_type == DEBUG_STABS)
17332 stabs_generate_asm_endfunc (S_GET_NAME (p),
17336 as_warn (_(".end directive missing or unknown symbol"));
17338 /* Create an expression to calculate the size of the function. */
17339 if (p && cur_proc_ptr)
17341 OBJ_SYMFIELD_TYPE *obj = symbol_get_obj (p);
17342 expressionS *exp = xmalloc (sizeof (expressionS));
17345 exp->X_op = O_subtract;
17346 exp->X_add_symbol = symbol_temp_new_now ();
17347 exp->X_op_symbol = p;
17348 exp->X_add_number = 0;
17350 cur_proc_ptr->func_end_sym = exp->X_add_symbol;
17353 /* Generate a .pdr section. */
17354 if (!ECOFF_DEBUGGING && mips_flag_pdr)
17356 segT saved_seg = now_seg;
17357 subsegT saved_subseg = now_subseg;
17361 #ifdef md_flush_pending_output
17362 md_flush_pending_output ();
17365 gas_assert (pdr_seg);
17366 subseg_set (pdr_seg, 0);
17368 /* Write the symbol. */
17369 exp.X_op = O_symbol;
17370 exp.X_add_symbol = p;
17371 exp.X_add_number = 0;
17372 emit_expr (&exp, 4);
17374 fragp = frag_more (7 * 4);
17376 md_number_to_chars (fragp, cur_proc_ptr->reg_mask, 4);
17377 md_number_to_chars (fragp + 4, cur_proc_ptr->reg_offset, 4);
17378 md_number_to_chars (fragp + 8, cur_proc_ptr->fpreg_mask, 4);
17379 md_number_to_chars (fragp + 12, cur_proc_ptr->fpreg_offset, 4);
17380 md_number_to_chars (fragp + 16, cur_proc_ptr->frame_offset, 4);
17381 md_number_to_chars (fragp + 20, cur_proc_ptr->frame_reg, 4);
17382 md_number_to_chars (fragp + 24, cur_proc_ptr->pc_reg, 4);
17384 subseg_set (saved_seg, saved_subseg);
17387 cur_proc_ptr = NULL;
17390 /* The .aent and .ent directives. */
17393 s_mips_ent (int aent)
17397 symbolP = get_symbol ();
17398 if (*input_line_pointer == ',')
17399 ++input_line_pointer;
17400 SKIP_WHITESPACE ();
17401 if (ISDIGIT (*input_line_pointer)
17402 || *input_line_pointer == '-')
17405 if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) == 0)
17406 as_warn (_(".ent or .aent not in text section."));
17408 if (!aent && cur_proc_ptr)
17409 as_warn (_("missing .end"));
17413 /* This function needs its own .frame and .cprestore directives. */
17414 mips_frame_reg_valid = 0;
17415 mips_cprestore_valid = 0;
17417 cur_proc_ptr = &cur_proc;
17418 memset (cur_proc_ptr, '\0', sizeof (procS));
17420 cur_proc_ptr->func_sym = symbolP;
17424 if (debug_type == DEBUG_STABS)
17425 stabs_generate_asm_func (S_GET_NAME (symbolP),
17426 S_GET_NAME (symbolP));
17429 symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION;
17431 demand_empty_rest_of_line ();
17434 /* The .frame directive. If the mdebug section is present (IRIX 5 native)
17435 then ecoff.c (ecoff_directive_frame) is used. For embedded targets,
17436 s_mips_frame is used so that we can set the PDR information correctly.
17437 We can't use the ecoff routines because they make reference to the ecoff
17438 symbol table (in the mdebug section). */
17441 s_mips_frame (int ignore ATTRIBUTE_UNUSED)
17443 if (ECOFF_DEBUGGING)
17449 if (cur_proc_ptr == (procS *) NULL)
17451 as_warn (_(".frame outside of .ent"));
17452 demand_empty_rest_of_line ();
17456 cur_proc_ptr->frame_reg = tc_get_register (1);
17458 SKIP_WHITESPACE ();
17459 if (*input_line_pointer++ != ','
17460 || get_absolute_expression_and_terminator (&val) != ',')
17462 as_warn (_("Bad .frame directive"));
17463 --input_line_pointer;
17464 demand_empty_rest_of_line ();
17468 cur_proc_ptr->frame_offset = val;
17469 cur_proc_ptr->pc_reg = tc_get_register (0);
17471 demand_empty_rest_of_line ();
17475 /* The .fmask and .mask directives. If the mdebug section is present
17476 (IRIX 5 native) then ecoff.c (ecoff_directive_mask) is used. For
17477 embedded targets, s_mips_mask is used so that we can set the PDR
17478 information correctly. We can't use the ecoff routines because they
17479 make reference to the ecoff symbol table (in the mdebug section). */
17482 s_mips_mask (int reg_type)
17484 if (ECOFF_DEBUGGING)
17485 s_ignore (reg_type);
17490 if (cur_proc_ptr == (procS *) NULL)
17492 as_warn (_(".mask/.fmask outside of .ent"));
17493 demand_empty_rest_of_line ();
17497 if (get_absolute_expression_and_terminator (&mask) != ',')
17499 as_warn (_("Bad .mask/.fmask directive"));
17500 --input_line_pointer;
17501 demand_empty_rest_of_line ();
17505 off = get_absolute_expression ();
17507 if (reg_type == 'F')
17509 cur_proc_ptr->fpreg_mask = mask;
17510 cur_proc_ptr->fpreg_offset = off;
17514 cur_proc_ptr->reg_mask = mask;
17515 cur_proc_ptr->reg_offset = off;
17518 demand_empty_rest_of_line ();
17522 /* A table describing all the processors gas knows about. Names are
17523 matched in the order listed.
17525 To ease comparison, please keep this table in the same order as
17526 gcc's mips_cpu_info_table[]. */
17527 static const struct mips_cpu_info mips_cpu_info_table[] =
17529 /* Entries for generic ISAs */
17530 { "mips1", MIPS_CPU_IS_ISA, 0, ISA_MIPS1, CPU_R3000 },
17531 { "mips2", MIPS_CPU_IS_ISA, 0, ISA_MIPS2, CPU_R6000 },
17532 { "mips3", MIPS_CPU_IS_ISA, 0, ISA_MIPS3, CPU_R4000 },
17533 { "mips4", MIPS_CPU_IS_ISA, 0, ISA_MIPS4, CPU_R8000 },
17534 { "mips5", MIPS_CPU_IS_ISA, 0, ISA_MIPS5, CPU_MIPS5 },
17535 { "mips32", MIPS_CPU_IS_ISA, 0, ISA_MIPS32, CPU_MIPS32 },
17536 { "mips32r2", MIPS_CPU_IS_ISA, 0, ISA_MIPS32R2, CPU_MIPS32R2 },
17537 { "mips64", MIPS_CPU_IS_ISA, 0, ISA_MIPS64, CPU_MIPS64 },
17538 { "mips64r2", MIPS_CPU_IS_ISA, 0, ISA_MIPS64R2, CPU_MIPS64R2 },
17541 { "r3000", 0, 0, ISA_MIPS1, CPU_R3000 },
17542 { "r2000", 0, 0, ISA_MIPS1, CPU_R3000 },
17543 { "r3900", 0, 0, ISA_MIPS1, CPU_R3900 },
17546 { "r6000", 0, 0, ISA_MIPS2, CPU_R6000 },
17549 { "r4000", 0, 0, ISA_MIPS3, CPU_R4000 },
17550 { "r4010", 0, 0, ISA_MIPS2, CPU_R4010 },
17551 { "vr4100", 0, 0, ISA_MIPS3, CPU_VR4100 },
17552 { "vr4111", 0, 0, ISA_MIPS3, CPU_R4111 },
17553 { "vr4120", 0, 0, ISA_MIPS3, CPU_VR4120 },
17554 { "vr4130", 0, 0, ISA_MIPS3, CPU_VR4120 },
17555 { "vr4181", 0, 0, ISA_MIPS3, CPU_R4111 },
17556 { "vr4300", 0, 0, ISA_MIPS3, CPU_R4300 },
17557 { "r4400", 0, 0, ISA_MIPS3, CPU_R4400 },
17558 { "r4600", 0, 0, ISA_MIPS3, CPU_R4600 },
17559 { "orion", 0, 0, ISA_MIPS3, CPU_R4600 },
17560 { "r4650", 0, 0, ISA_MIPS3, CPU_R4650 },
17561 { "r5900", 0, 0, ISA_MIPS3, CPU_R5900 },
17562 /* ST Microelectronics Loongson 2E and 2F cores */
17563 { "loongson2e", 0, 0, ISA_MIPS3, CPU_LOONGSON_2E },
17564 { "loongson2f", 0, 0, ISA_MIPS3, CPU_LOONGSON_2F },
17567 { "r8000", 0, 0, ISA_MIPS4, CPU_R8000 },
17568 { "r10000", 0, 0, ISA_MIPS4, CPU_R10000 },
17569 { "r12000", 0, 0, ISA_MIPS4, CPU_R12000 },
17570 { "r14000", 0, 0, ISA_MIPS4, CPU_R14000 },
17571 { "r16000", 0, 0, ISA_MIPS4, CPU_R16000 },
17572 { "vr5000", 0, 0, ISA_MIPS4, CPU_R5000 },
17573 { "vr5400", 0, 0, ISA_MIPS4, CPU_VR5400 },
17574 { "vr5500", 0, 0, ISA_MIPS4, CPU_VR5500 },
17575 { "rm5200", 0, 0, ISA_MIPS4, CPU_R5000 },
17576 { "rm5230", 0, 0, ISA_MIPS4, CPU_R5000 },
17577 { "rm5231", 0, 0, ISA_MIPS4, CPU_R5000 },
17578 { "rm5261", 0, 0, ISA_MIPS4, CPU_R5000 },
17579 { "rm5721", 0, 0, ISA_MIPS4, CPU_R5000 },
17580 { "rm7000", 0, 0, ISA_MIPS4, CPU_RM7000 },
17581 { "rm9000", 0, 0, ISA_MIPS4, CPU_RM9000 },
17584 { "4kc", 0, 0, ISA_MIPS32, CPU_MIPS32 },
17585 { "4km", 0, 0, ISA_MIPS32, CPU_MIPS32 },
17586 { "4kp", 0, 0, ISA_MIPS32, CPU_MIPS32 },
17587 { "4ksc", 0, ASE_SMARTMIPS, ISA_MIPS32, CPU_MIPS32 },
17589 /* MIPS 32 Release 2 */
17590 { "4kec", 0, 0, ISA_MIPS32R2, CPU_MIPS32R2 },
17591 { "4kem", 0, 0, ISA_MIPS32R2, CPU_MIPS32R2 },
17592 { "4kep", 0, 0, ISA_MIPS32R2, CPU_MIPS32R2 },
17593 { "4ksd", 0, ASE_SMARTMIPS, ISA_MIPS32R2, CPU_MIPS32R2 },
17594 { "m4k", 0, 0, ISA_MIPS32R2, CPU_MIPS32R2 },
17595 { "m4kp", 0, 0, ISA_MIPS32R2, CPU_MIPS32R2 },
17596 { "m14k", 0, ASE_MCU, ISA_MIPS32R2, CPU_MIPS32R2 },
17597 { "m14kc", 0, ASE_MCU, ISA_MIPS32R2, CPU_MIPS32R2 },
17598 { "m14ke", 0, ASE_DSP | ASE_DSPR2 | ASE_MCU,
17599 ISA_MIPS32R2, CPU_MIPS32R2 },
17600 { "m14kec", 0, ASE_DSP | ASE_DSPR2 | ASE_MCU,
17601 ISA_MIPS32R2, CPU_MIPS32R2 },
17602 { "24kc", 0, 0, ISA_MIPS32R2, CPU_MIPS32R2 },
17603 { "24kf2_1", 0, 0, ISA_MIPS32R2, CPU_MIPS32R2 },
17604 { "24kf", 0, 0, ISA_MIPS32R2, CPU_MIPS32R2 },
17605 { "24kf1_1", 0, 0, ISA_MIPS32R2, CPU_MIPS32R2 },
17606 /* Deprecated forms of the above. */
17607 { "24kfx", 0, 0, ISA_MIPS32R2, CPU_MIPS32R2 },
17608 { "24kx", 0, 0, ISA_MIPS32R2, CPU_MIPS32R2 },
17609 /* 24KE is a 24K with DSP ASE, other ASEs are optional. */
17610 { "24kec", 0, ASE_DSP, ISA_MIPS32R2, CPU_MIPS32R2 },
17611 { "24kef2_1", 0, ASE_DSP, ISA_MIPS32R2, CPU_MIPS32R2 },
17612 { "24kef", 0, ASE_DSP, ISA_MIPS32R2, CPU_MIPS32R2 },
17613 { "24kef1_1", 0, ASE_DSP, ISA_MIPS32R2, CPU_MIPS32R2 },
17614 /* Deprecated forms of the above. */
17615 { "24kefx", 0, ASE_DSP, ISA_MIPS32R2, CPU_MIPS32R2 },
17616 { "24kex", 0, ASE_DSP, ISA_MIPS32R2, CPU_MIPS32R2 },
17617 /* 34K is a 24K with DSP and MT ASE, other ASEs are optional. */
17618 { "34kc", 0, ASE_DSP | ASE_MT, ISA_MIPS32R2, CPU_MIPS32R2 },
17619 { "34kf2_1", 0, ASE_DSP | ASE_MT, ISA_MIPS32R2, CPU_MIPS32R2 },
17620 { "34kf", 0, ASE_DSP | ASE_MT, ISA_MIPS32R2, CPU_MIPS32R2 },
17621 { "34kf1_1", 0, ASE_DSP | ASE_MT, ISA_MIPS32R2, CPU_MIPS32R2 },
17622 /* Deprecated forms of the above. */
17623 { "34kfx", 0, ASE_DSP | ASE_MT, ISA_MIPS32R2, CPU_MIPS32R2 },
17624 { "34kx", 0, ASE_DSP | ASE_MT, ISA_MIPS32R2, CPU_MIPS32R2 },
17625 /* 34Kn is a 34kc without DSP. */
17626 { "34kn", 0, ASE_MT, ISA_MIPS32R2, CPU_MIPS32R2 },
17627 /* 74K with DSP and DSPR2 ASE, other ASEs are optional. */
17628 { "74kc", 0, ASE_DSP | ASE_DSPR2, ISA_MIPS32R2, CPU_MIPS32R2 },
17629 { "74kf2_1", 0, ASE_DSP | ASE_DSPR2, ISA_MIPS32R2, CPU_MIPS32R2 },
17630 { "74kf", 0, ASE_DSP | ASE_DSPR2, ISA_MIPS32R2, CPU_MIPS32R2 },
17631 { "74kf1_1", 0, ASE_DSP | ASE_DSPR2, ISA_MIPS32R2, CPU_MIPS32R2 },
17632 { "74kf3_2", 0, ASE_DSP | ASE_DSPR2, ISA_MIPS32R2, CPU_MIPS32R2 },
17633 /* Deprecated forms of the above. */
17634 { "74kfx", 0, ASE_DSP | ASE_DSPR2, ISA_MIPS32R2, CPU_MIPS32R2 },
17635 { "74kx", 0, ASE_DSP | ASE_DSPR2, ISA_MIPS32R2, CPU_MIPS32R2 },
17636 /* 1004K cores are multiprocessor versions of the 34K. */
17637 { "1004kc", 0, ASE_DSP | ASE_MT, ISA_MIPS32R2, CPU_MIPS32R2 },
17638 { "1004kf2_1", 0, ASE_DSP | ASE_MT, ISA_MIPS32R2, CPU_MIPS32R2 },
17639 { "1004kf", 0, ASE_DSP | ASE_MT, ISA_MIPS32R2, CPU_MIPS32R2 },
17640 { "1004kf1_1", 0, ASE_DSP | ASE_MT, ISA_MIPS32R2, CPU_MIPS32R2 },
17643 { "5kc", 0, 0, ISA_MIPS64, CPU_MIPS64 },
17644 { "5kf", 0, 0, ISA_MIPS64, CPU_MIPS64 },
17645 { "20kc", 0, ASE_MIPS3D, ISA_MIPS64, CPU_MIPS64 },
17646 { "25kf", 0, ASE_MIPS3D, ISA_MIPS64, CPU_MIPS64 },
17648 /* Broadcom SB-1 CPU core */
17649 { "sb1", 0, ASE_MIPS3D | ASE_MDMX, ISA_MIPS64, CPU_SB1 },
17650 /* Broadcom SB-1A CPU core */
17651 { "sb1a", 0, ASE_MIPS3D | ASE_MDMX, ISA_MIPS64, CPU_SB1 },
17653 { "loongson3a", 0, 0, ISA_MIPS64, CPU_LOONGSON_3A },
17655 /* MIPS 64 Release 2 */
17657 /* Cavium Networks Octeon CPU core */
17658 { "octeon", 0, 0, ISA_MIPS64R2, CPU_OCTEON },
17659 { "octeon+", 0, 0, ISA_MIPS64R2, CPU_OCTEONP },
17660 { "octeon2", 0, 0, ISA_MIPS64R2, CPU_OCTEON2 },
17663 { "xlr", 0, 0, ISA_MIPS64, CPU_XLR },
17666 XLP is mostly like XLR, with the prominent exception that it is
17667 MIPS64R2 rather than MIPS64. */
17668 { "xlp", 0, 0, ISA_MIPS64R2, CPU_XLR },
17671 { NULL, 0, 0, 0, 0 }
17675 /* Return true if GIVEN is the same as CANONICAL, or if it is CANONICAL
17676 with a final "000" replaced by "k". Ignore case.
17678 Note: this function is shared between GCC and GAS. */
17681 mips_strict_matching_cpu_name_p (const char *canonical, const char *given)
17683 while (*given != 0 && TOLOWER (*given) == TOLOWER (*canonical))
17684 given++, canonical++;
17686 return ((*given == 0 && *canonical == 0)
17687 || (strcmp (canonical, "000") == 0 && strcasecmp (given, "k") == 0));
17691 /* Return true if GIVEN matches CANONICAL, where GIVEN is a user-supplied
17692 CPU name. We've traditionally allowed a lot of variation here.
17694 Note: this function is shared between GCC and GAS. */
17697 mips_matching_cpu_name_p (const char *canonical, const char *given)
17699 /* First see if the name matches exactly, or with a final "000"
17700 turned into "k". */
17701 if (mips_strict_matching_cpu_name_p (canonical, given))
17704 /* If not, try comparing based on numerical designation alone.
17705 See if GIVEN is an unadorned number, or 'r' followed by a number. */
17706 if (TOLOWER (*given) == 'r')
17708 if (!ISDIGIT (*given))
17711 /* Skip over some well-known prefixes in the canonical name,
17712 hoping to find a number there too. */
17713 if (TOLOWER (canonical[0]) == 'v' && TOLOWER (canonical[1]) == 'r')
17715 else if (TOLOWER (canonical[0]) == 'r' && TOLOWER (canonical[1]) == 'm')
17717 else if (TOLOWER (canonical[0]) == 'r')
17720 return mips_strict_matching_cpu_name_p (canonical, given);
17724 /* Parse an option that takes the name of a processor as its argument.
17725 OPTION is the name of the option and CPU_STRING is the argument.
17726 Return the corresponding processor enumeration if the CPU_STRING is
17727 recognized, otherwise report an error and return null.
17729 A similar function exists in GCC. */
17731 static const struct mips_cpu_info *
17732 mips_parse_cpu (const char *option, const char *cpu_string)
17734 const struct mips_cpu_info *p;
17736 /* 'from-abi' selects the most compatible architecture for the given
17737 ABI: MIPS I for 32-bit ABIs and MIPS III for 64-bit ABIs. For the
17738 EABIs, we have to decide whether we're using the 32-bit or 64-bit
17739 version. Look first at the -mgp options, if given, otherwise base
17740 the choice on MIPS_DEFAULT_64BIT.
17742 Treat NO_ABI like the EABIs. One reason to do this is that the
17743 plain 'mips' and 'mips64' configs have 'from-abi' as their default
17744 architecture. This code picks MIPS I for 'mips' and MIPS III for
17745 'mips64', just as we did in the days before 'from-abi'. */
17746 if (strcasecmp (cpu_string, "from-abi") == 0)
17748 if (ABI_NEEDS_32BIT_REGS (mips_abi))
17749 return mips_cpu_info_from_isa (ISA_MIPS1);
17751 if (ABI_NEEDS_64BIT_REGS (mips_abi))
17752 return mips_cpu_info_from_isa (ISA_MIPS3);
17754 if (file_mips_gp32 >= 0)
17755 return mips_cpu_info_from_isa (file_mips_gp32 ? ISA_MIPS1 : ISA_MIPS3);
17757 return mips_cpu_info_from_isa (MIPS_DEFAULT_64BIT
17762 /* 'default' has traditionally been a no-op. Probably not very useful. */
17763 if (strcasecmp (cpu_string, "default") == 0)
17766 for (p = mips_cpu_info_table; p->name != 0; p++)
17767 if (mips_matching_cpu_name_p (p->name, cpu_string))
17770 as_bad (_("Bad value (%s) for %s"), cpu_string, option);
17774 /* Return the canonical processor information for ISA (a member of the
17775 ISA_MIPS* enumeration). */
17777 static const struct mips_cpu_info *
17778 mips_cpu_info_from_isa (int isa)
17782 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
17783 if ((mips_cpu_info_table[i].flags & MIPS_CPU_IS_ISA)
17784 && isa == mips_cpu_info_table[i].isa)
17785 return (&mips_cpu_info_table[i]);
17790 static const struct mips_cpu_info *
17791 mips_cpu_info_from_arch (int arch)
17795 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
17796 if (arch == mips_cpu_info_table[i].cpu)
17797 return (&mips_cpu_info_table[i]);
17803 show (FILE *stream, const char *string, int *col_p, int *first_p)
17807 fprintf (stream, "%24s", "");
17812 fprintf (stream, ", ");
17816 if (*col_p + strlen (string) > 72)
17818 fprintf (stream, "\n%24s", "");
17822 fprintf (stream, "%s", string);
17823 *col_p += strlen (string);
17829 md_show_usage (FILE *stream)
17834 fprintf (stream, _("\
17836 -EB generate big endian output\n\
17837 -EL generate little endian output\n\
17838 -g, -g2 do not remove unneeded NOPs or swap branches\n\
17839 -G NUM allow referencing objects up to NUM bytes\n\
17840 implicitly with the gp register [default 8]\n"));
17841 fprintf (stream, _("\
17842 -mips1 generate MIPS ISA I instructions\n\
17843 -mips2 generate MIPS ISA II instructions\n\
17844 -mips3 generate MIPS ISA III instructions\n\
17845 -mips4 generate MIPS ISA IV instructions\n\
17846 -mips5 generate MIPS ISA V instructions\n\
17847 -mips32 generate MIPS32 ISA instructions\n\
17848 -mips32r2 generate MIPS32 release 2 ISA instructions\n\
17849 -mips64 generate MIPS64 ISA instructions\n\
17850 -mips64r2 generate MIPS64 release 2 ISA instructions\n\
17851 -march=CPU/-mtune=CPU generate code/schedule for CPU, where CPU is one of:\n"));
17855 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
17856 show (stream, mips_cpu_info_table[i].name, &column, &first);
17857 show (stream, "from-abi", &column, &first);
17858 fputc ('\n', stream);
17860 fprintf (stream, _("\
17861 -mCPU equivalent to -march=CPU -mtune=CPU. Deprecated.\n\
17862 -no-mCPU don't generate code specific to CPU.\n\
17863 For -mCPU and -no-mCPU, CPU must be one of:\n"));
17867 show (stream, "3900", &column, &first);
17868 show (stream, "4010", &column, &first);
17869 show (stream, "4100", &column, &first);
17870 show (stream, "4650", &column, &first);
17871 fputc ('\n', stream);
17873 fprintf (stream, _("\
17874 -mips16 generate mips16 instructions\n\
17875 -no-mips16 do not generate mips16 instructions\n"));
17876 fprintf (stream, _("\
17877 -mmicromips generate microMIPS instructions\n\
17878 -mno-micromips do not generate microMIPS instructions\n"));
17879 fprintf (stream, _("\
17880 -msmartmips generate smartmips instructions\n\
17881 -mno-smartmips do not generate smartmips instructions\n"));
17882 fprintf (stream, _("\
17883 -mdsp generate DSP instructions\n\
17884 -mno-dsp do not generate DSP instructions\n"));
17885 fprintf (stream, _("\
17886 -mdspr2 generate DSP R2 instructions\n\
17887 -mno-dspr2 do not generate DSP R2 instructions\n"));
17888 fprintf (stream, _("\
17889 -mmt generate MT instructions\n\
17890 -mno-mt do not generate MT instructions\n"));
17891 fprintf (stream, _("\
17892 -mmcu generate MCU instructions\n\
17893 -mno-mcu do not generate MCU instructions\n"));
17894 fprintf (stream, _("\
17895 -mvirt generate Virtualization instructions\n\
17896 -mno-virt do not generate Virtualization instructions\n"));
17897 fprintf (stream, _("\
17898 -minsn32 only generate 32-bit microMIPS instructions\n\
17899 -mno-insn32 generate all microMIPS instructions\n"));
17900 fprintf (stream, _("\
17901 -mfix-loongson2f-jump work around Loongson2F JUMP instructions\n\
17902 -mfix-loongson2f-nop work around Loongson2F NOP errata\n\
17903 -mfix-vr4120 work around certain VR4120 errata\n\
17904 -mfix-vr4130 work around VR4130 mflo/mfhi errata\n\
17905 -mfix-24k insert a nop after ERET and DERET instructions\n\
17906 -mfix-cn63xxp1 work around CN63XXP1 PREF errata\n\
17907 -mgp32 use 32-bit GPRs, regardless of the chosen ISA\n\
17908 -mfp32 use 32-bit FPRs, regardless of the chosen ISA\n\
17909 -msym32 assume all symbols have 32-bit values\n\
17910 -O0 remove unneeded NOPs, do not swap branches\n\
17911 -O remove unneeded NOPs and swap branches\n\
17912 --trap, --no-break trap exception on div by 0 and mult overflow\n\
17913 --break, --no-trap break exception on div by 0 and mult overflow\n"));
17914 fprintf (stream, _("\
17915 -mhard-float allow floating-point instructions\n\
17916 -msoft-float do not allow floating-point instructions\n\
17917 -msingle-float only allow 32-bit floating-point operations\n\
17918 -mdouble-float allow 32-bit and 64-bit floating-point operations\n\
17919 --[no-]construct-floats [dis]allow floating point values to be constructed\n\
17920 --[no-]relax-branch [dis]allow out-of-range branches to be relaxed\n\
17921 -mnan=ENCODING select an IEEE 754 NaN encoding convention, either of:\n"));
17925 show (stream, "legacy", &column, &first);
17926 show (stream, "2008", &column, &first);
17928 fputc ('\n', stream);
17930 fprintf (stream, _("\
17931 -KPIC, -call_shared generate SVR4 position independent code\n\
17932 -call_nonpic generate non-PIC code that can operate with DSOs\n\
17933 -mvxworks-pic generate VxWorks position independent code\n\
17934 -non_shared do not generate code that can operate with DSOs\n\
17935 -xgot assume a 32 bit GOT\n\
17936 -mpdr, -mno-pdr enable/disable creation of .pdr sections\n\
17937 -mshared, -mno-shared disable/enable .cpload optimization for\n\
17938 position dependent (non shared) code\n\
17939 -mabi=ABI create ABI conformant object file for:\n"));
17943 show (stream, "32", &column, &first);
17944 show (stream, "o64", &column, &first);
17945 show (stream, "n32", &column, &first);
17946 show (stream, "64", &column, &first);
17947 show (stream, "eabi", &column, &first);
17949 fputc ('\n', stream);
17951 fprintf (stream, _("\
17952 -32 create o32 ABI object file (default)\n\
17953 -n32 create n32 ABI object file\n\
17954 -64 create 64 ABI object file\n"));
17959 mips_dwarf2_format (asection *sec ATTRIBUTE_UNUSED)
17961 if (HAVE_64BIT_SYMBOLS)
17962 return dwarf2_format_64bit_irix;
17964 return dwarf2_format_32bit;
17969 mips_dwarf2_addr_size (void)
17971 if (HAVE_64BIT_OBJECTS)
17977 /* Standard calling conventions leave the CFA at SP on entry. */
17979 mips_cfi_frame_initial_instructions (void)
17981 cfi_add_CFA_def_cfa_register (SP);
17985 tc_mips_regname_to_dw2regnum (char *regname)
17987 unsigned int regnum = -1;
17990 if (reg_lookup (®name, RTYPE_GP | RTYPE_NUM, ®))