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"
38 #define DBG(x) printf x
44 /* Clean up namespace so we can include obj-elf.h too. */
45 static int mips_output_flavor (void);
46 static int mips_output_flavor (void) { return OUTPUT_FLAVOR; }
47 #undef OBJ_PROCESS_STAB
54 #undef obj_frob_file_after_relocs
55 #undef obj_frob_symbol
57 #undef obj_sec_sym_ok_for_reloc
58 #undef OBJ_COPY_SYMBOL_ATTRIBUTES
61 /* Fix any of them that we actually care about. */
63 #define OUTPUT_FLAVOR mips_output_flavor()
70 #ifndef ECOFF_DEBUGGING
71 #define NO_ECOFF_DEBUGGING
72 #define ECOFF_DEBUGGING 0
75 int mips_flag_mdebug = -1;
77 /* Control generation of .pdr sections. Off by default on IRIX: the native
78 linker doesn't know about and discards them, but relocations against them
79 remain, leading to rld crashes. */
81 int mips_flag_pdr = FALSE;
83 int mips_flag_pdr = TRUE;
88 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
89 static char *mips_regmask_frag;
97 #define PIC_CALL_REG 25
105 #define ILLEGAL_REG (32)
107 #define AT mips_opts.at
109 /* Allow override of standard little-endian ECOFF format. */
111 #ifndef ECOFF_LITTLE_FORMAT
112 #define ECOFF_LITTLE_FORMAT "ecoff-littlemips"
115 extern int target_big_endian;
117 /* The name of the readonly data section. */
118 #define RDATA_SECTION_NAME (OUTPUT_FLAVOR == bfd_target_ecoff_flavour \
120 : OUTPUT_FLAVOR == bfd_target_coff_flavour \
122 : OUTPUT_FLAVOR == bfd_target_elf_flavour \
126 /* Ways in which an instruction can be "appended" to the output. */
128 /* Just add it normally. */
131 /* Add it normally and then add a nop. */
134 /* Turn an instruction with a delay slot into a "compact" version. */
137 /* Insert the instruction before the last one. */
141 /* Information about an instruction, including its format, operands
145 /* The opcode's entry in mips_opcodes or mips16_opcodes. */
146 const struct mips_opcode *insn_mo;
148 /* The 16-bit or 32-bit bitstring of the instruction itself. This is
149 a copy of INSN_MO->match with the operands filled in. If we have
150 decided to use an extended MIPS16 instruction, this includes the
152 unsigned long insn_opcode;
154 /* The frag that contains the instruction. */
157 /* The offset into FRAG of the first instruction byte. */
160 /* The relocs associated with the instruction, if any. */
163 /* True if this entry cannot be moved from its current position. */
164 unsigned int fixed_p : 1;
166 /* True if this instruction occurred in a .set noreorder block. */
167 unsigned int noreorder_p : 1;
169 /* True for mips16 instructions that jump to an absolute address. */
170 unsigned int mips16_absolute_jump_p : 1;
172 /* True if this instruction is complete. */
173 unsigned int complete_p : 1;
175 /* True if this instruction is cleared from history by unconditional
177 unsigned int cleared_p : 1;
180 /* The ABI to use. */
191 /* MIPS ABI we are using for this output file. */
192 static enum mips_abi_level mips_abi = NO_ABI;
194 /* Whether or not we have code that can call pic code. */
195 int mips_abicalls = FALSE;
197 /* Whether or not we have code which can be put into a shared
199 static bfd_boolean mips_in_shared = TRUE;
201 /* This is the set of options which may be modified by the .set
202 pseudo-op. We use a struct so that .set push and .set pop are more
205 struct mips_set_options
207 /* MIPS ISA (Instruction Set Architecture) level. This is set to -1
208 if it has not been initialized. Changed by `.set mipsN', and the
209 -mipsN command line option, and the default CPU. */
211 /* Enabled Application Specific Extensions (ASEs). Changed by `.set
212 <asename>', by command line options, and based on the default
215 /* Whether we are assembling for the mips16 processor. 0 if we are
216 not, 1 if we are, and -1 if the value has not been initialized.
217 Changed by `.set mips16' and `.set nomips16', and the -mips16 and
218 -nomips16 command line options, and the default CPU. */
220 /* Whether we are assembling for the mipsMIPS ASE. 0 if we are not,
221 1 if we are, and -1 if the value has not been initialized. Changed
222 by `.set micromips' and `.set nomicromips', and the -mmicromips
223 and -mno-micromips command line options, and the default CPU. */
225 /* Non-zero if we should not reorder instructions. Changed by `.set
226 reorder' and `.set noreorder'. */
228 /* Non-zero if we should not permit the register designated "assembler
229 temporary" to be used in instructions. The value is the register
230 number, normally $at ($1). Changed by `.set at=REG', `.set noat'
231 (same as `.set at=$0') and `.set at' (same as `.set at=$1'). */
233 /* Non-zero if we should warn when a macro instruction expands into
234 more than one machine instruction. Changed by `.set nomacro' and
236 int warn_about_macros;
237 /* Non-zero if we should not move instructions. Changed by `.set
238 move', `.set volatile', `.set nomove', and `.set novolatile'. */
240 /* Non-zero if we should not optimize branches by moving the target
241 of the branch into the delay slot. Actually, we don't perform
242 this optimization anyhow. Changed by `.set bopt' and `.set
245 /* Non-zero if we should not autoextend mips16 instructions.
246 Changed by `.set autoextend' and `.set noautoextend'. */
248 /* Restrict general purpose registers and floating point registers
249 to 32 bit. This is initially determined when -mgp32 or -mfp32
250 is passed but can changed if the assembler code uses .set mipsN. */
253 /* MIPS architecture (CPU) type. Changed by .set arch=FOO, the -march
254 command line option, and the default CPU. */
256 /* True if ".set sym32" is in effect. */
258 /* True if floating-point operations are not allowed. Changed by .set
259 softfloat or .set hardfloat, by command line options -msoft-float or
260 -mhard-float. The default is false. */
261 bfd_boolean soft_float;
263 /* True if only single-precision floating-point operations are allowed.
264 Changed by .set singlefloat or .set doublefloat, command-line options
265 -msingle-float or -mdouble-float. The default is false. */
266 bfd_boolean single_float;
269 /* This is the struct we use to hold the current set of options. Note
270 that we must set the isa field to ISA_UNKNOWN and the ASE fields to
271 -1 to indicate that they have not been initialized. */
273 /* True if -mgp32 was passed. */
274 static int file_mips_gp32 = -1;
276 /* True if -mfp32 was passed. */
277 static int file_mips_fp32 = -1;
279 /* 1 if -msoft-float, 0 if -mhard-float. The default is 0. */
280 static int file_mips_soft_float = 0;
282 /* 1 if -msingle-float, 0 if -mdouble-float. The default is 0. */
283 static int file_mips_single_float = 0;
285 static struct mips_set_options mips_opts =
287 /* isa */ ISA_UNKNOWN, /* ase */ 0, /* mips16 */ -1, /* micromips */ -1,
288 /* noreorder */ 0, /* at */ ATREG, /* warn_about_macros */ 0,
289 /* nomove */ 0, /* nobopt */ 0, /* noautoextend */ 0, /* gp32 */ 0,
290 /* fp32 */ 0, /* arch */ CPU_UNKNOWN, /* sym32 */ FALSE,
291 /* soft_float */ FALSE, /* single_float */ FALSE
294 /* The set of ASEs that were selected on the command line, either
295 explicitly via ASE options or implicitly through things like -march. */
296 static unsigned int file_ase;
298 /* Which bits of file_ase were explicitly set or cleared by ASE options. */
299 static unsigned int file_ase_explicit;
301 /* These variables are filled in with the masks of registers used.
302 The object format code reads them and puts them in the appropriate
304 unsigned long mips_gprmask;
305 unsigned long mips_cprmask[4];
307 /* MIPS ISA we are using for this output file. */
308 static int file_mips_isa = ISA_UNKNOWN;
310 /* True if any MIPS16 code was produced. */
311 static int file_ase_mips16;
313 #define ISA_SUPPORTS_MIPS16E (mips_opts.isa == ISA_MIPS32 \
314 || mips_opts.isa == ISA_MIPS32R2 \
315 || mips_opts.isa == ISA_MIPS64 \
316 || mips_opts.isa == ISA_MIPS64R2)
318 /* True if any microMIPS code was produced. */
319 static int file_ase_micromips;
321 /* True if we want to create R_MIPS_JALR for jalr $25. */
323 #define MIPS_JALR_HINT_P(EXPR) HAVE_NEWABI
325 /* As a GNU extension, we use R_MIPS_JALR for o32 too. However,
326 because there's no place for any addend, the only acceptable
327 expression is a bare symbol. */
328 #define MIPS_JALR_HINT_P(EXPR) \
329 (!HAVE_IN_PLACE_ADDENDS \
330 || ((EXPR)->X_op == O_symbol && (EXPR)->X_add_number == 0))
333 /* The argument of the -march= flag. The architecture we are assembling. */
334 static int file_mips_arch = CPU_UNKNOWN;
335 static const char *mips_arch_string;
337 /* The argument of the -mtune= flag. The architecture for which we
339 static int mips_tune = CPU_UNKNOWN;
340 static const char *mips_tune_string;
342 /* True when generating 32-bit code for a 64-bit processor. */
343 static int mips_32bitmode = 0;
345 /* True if the given ABI requires 32-bit registers. */
346 #define ABI_NEEDS_32BIT_REGS(ABI) ((ABI) == O32_ABI)
348 /* Likewise 64-bit registers. */
349 #define ABI_NEEDS_64BIT_REGS(ABI) \
351 || (ABI) == N64_ABI \
354 /* Return true if ISA supports 64 bit wide gp registers. */
355 #define ISA_HAS_64BIT_REGS(ISA) \
356 ((ISA) == ISA_MIPS3 \
357 || (ISA) == ISA_MIPS4 \
358 || (ISA) == ISA_MIPS5 \
359 || (ISA) == ISA_MIPS64 \
360 || (ISA) == ISA_MIPS64R2)
362 /* Return true if ISA supports 64 bit wide float registers. */
363 #define ISA_HAS_64BIT_FPRS(ISA) \
364 ((ISA) == ISA_MIPS3 \
365 || (ISA) == ISA_MIPS4 \
366 || (ISA) == ISA_MIPS5 \
367 || (ISA) == ISA_MIPS32R2 \
368 || (ISA) == ISA_MIPS64 \
369 || (ISA) == ISA_MIPS64R2)
371 /* Return true if ISA supports 64-bit right rotate (dror et al.)
373 #define ISA_HAS_DROR(ISA) \
374 ((ISA) == ISA_MIPS64R2 \
375 || (mips_opts.micromips \
376 && ISA_HAS_64BIT_REGS (ISA)) \
379 /* Return true if ISA supports 32-bit right rotate (ror et al.)
381 #define ISA_HAS_ROR(ISA) \
382 ((ISA) == ISA_MIPS32R2 \
383 || (ISA) == ISA_MIPS64R2 \
384 || (mips_opts.ase & ASE_SMARTMIPS) \
385 || mips_opts.micromips \
388 /* Return true if ISA supports single-precision floats in odd registers. */
389 #define ISA_HAS_ODD_SINGLE_FPR(ISA) \
390 ((ISA) == ISA_MIPS32 \
391 || (ISA) == ISA_MIPS32R2 \
392 || (ISA) == ISA_MIPS64 \
393 || (ISA) == ISA_MIPS64R2)
395 /* Return true if ISA supports move to/from high part of a 64-bit
396 floating-point register. */
397 #define ISA_HAS_MXHC1(ISA) \
398 ((ISA) == ISA_MIPS32R2 \
399 || (ISA) == ISA_MIPS64R2)
401 #define HAVE_32BIT_GPRS \
402 (mips_opts.gp32 || !ISA_HAS_64BIT_REGS (mips_opts.isa))
404 #define HAVE_32BIT_FPRS \
405 (mips_opts.fp32 || !ISA_HAS_64BIT_FPRS (mips_opts.isa))
407 #define HAVE_64BIT_GPRS (!HAVE_32BIT_GPRS)
408 #define HAVE_64BIT_FPRS (!HAVE_32BIT_FPRS)
410 #define HAVE_NEWABI (mips_abi == N32_ABI || mips_abi == N64_ABI)
412 #define HAVE_64BIT_OBJECTS (mips_abi == N64_ABI)
414 /* True if relocations are stored in-place. */
415 #define HAVE_IN_PLACE_ADDENDS (!HAVE_NEWABI)
417 /* The ABI-derived address size. */
418 #define HAVE_64BIT_ADDRESSES \
419 (HAVE_64BIT_GPRS && (mips_abi == EABI_ABI || mips_abi == N64_ABI))
420 #define HAVE_32BIT_ADDRESSES (!HAVE_64BIT_ADDRESSES)
422 /* The size of symbolic constants (i.e., expressions of the form
423 "SYMBOL" or "SYMBOL + OFFSET"). */
424 #define HAVE_32BIT_SYMBOLS \
425 (HAVE_32BIT_ADDRESSES || !HAVE_64BIT_OBJECTS || mips_opts.sym32)
426 #define HAVE_64BIT_SYMBOLS (!HAVE_32BIT_SYMBOLS)
428 /* Addresses are loaded in different ways, depending on the address size
429 in use. The n32 ABI Documentation also mandates the use of additions
430 with overflow checking, but existing implementations don't follow it. */
431 #define ADDRESS_ADD_INSN \
432 (HAVE_32BIT_ADDRESSES ? "addu" : "daddu")
434 #define ADDRESS_ADDI_INSN \
435 (HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu")
437 #define ADDRESS_LOAD_INSN \
438 (HAVE_32BIT_ADDRESSES ? "lw" : "ld")
440 #define ADDRESS_STORE_INSN \
441 (HAVE_32BIT_ADDRESSES ? "sw" : "sd")
443 /* Return true if the given CPU supports the MIPS16 ASE. */
444 #define CPU_HAS_MIPS16(cpu) \
445 (strncmp (TARGET_CPU, "mips16", sizeof ("mips16") - 1) == 0 \
446 || strncmp (TARGET_CANONICAL, "mips-lsi-elf", sizeof ("mips-lsi-elf") - 1) == 0)
448 /* Return true if the given CPU supports the microMIPS ASE. */
449 #define CPU_HAS_MICROMIPS(cpu) 0
451 /* True if CPU has a dror instruction. */
452 #define CPU_HAS_DROR(CPU) ((CPU) == CPU_VR5400 || (CPU) == CPU_VR5500)
454 /* True if CPU has a ror instruction. */
455 #define CPU_HAS_ROR(CPU) CPU_HAS_DROR (CPU)
457 /* True if CPU is in the Octeon family */
458 #define CPU_IS_OCTEON(CPU) ((CPU) == CPU_OCTEON || (CPU) == CPU_OCTEONP || (CPU) == CPU_OCTEON2)
460 /* True if CPU has seq/sne and seqi/snei instructions. */
461 #define CPU_HAS_SEQ(CPU) (CPU_IS_OCTEON (CPU))
463 /* True, if CPU has support for ldc1 and sdc1. */
464 #define CPU_HAS_LDC1_SDC1(CPU) \
465 ((mips_opts.isa != ISA_MIPS1) && ((CPU) != CPU_R5900))
467 /* True if mflo and mfhi can be immediately followed by instructions
468 which write to the HI and LO registers.
470 According to MIPS specifications, MIPS ISAs I, II, and III need
471 (at least) two instructions between the reads of HI/LO and
472 instructions which write them, and later ISAs do not. Contradicting
473 the MIPS specifications, some MIPS IV processor user manuals (e.g.
474 the UM for the NEC Vr5000) document needing the instructions between
475 HI/LO reads and writes, as well. Therefore, we declare only MIPS32,
476 MIPS64 and later ISAs to have the interlocks, plus any specific
477 earlier-ISA CPUs for which CPU documentation declares that the
478 instructions are really interlocked. */
479 #define hilo_interlocks \
480 (mips_opts.isa == ISA_MIPS32 \
481 || mips_opts.isa == ISA_MIPS32R2 \
482 || mips_opts.isa == ISA_MIPS64 \
483 || mips_opts.isa == ISA_MIPS64R2 \
484 || mips_opts.arch == CPU_R4010 \
485 || mips_opts.arch == CPU_R5900 \
486 || mips_opts.arch == CPU_R10000 \
487 || mips_opts.arch == CPU_R12000 \
488 || mips_opts.arch == CPU_R14000 \
489 || mips_opts.arch == CPU_R16000 \
490 || mips_opts.arch == CPU_RM7000 \
491 || mips_opts.arch == CPU_VR5500 \
492 || mips_opts.micromips \
495 /* Whether the processor uses hardware interlocks to protect reads
496 from the GPRs after they are loaded from memory, and thus does not
497 require nops to be inserted. This applies to instructions marked
498 INSN_LOAD_MEMORY_DELAY. These nops are only required at MIPS ISA
499 level I and microMIPS mode instructions are always interlocked. */
500 #define gpr_interlocks \
501 (mips_opts.isa != ISA_MIPS1 \
502 || mips_opts.arch == CPU_R3900 \
503 || mips_opts.arch == CPU_R5900 \
504 || mips_opts.micromips \
507 /* Whether the processor uses hardware interlocks to avoid delays
508 required by coprocessor instructions, and thus does not require
509 nops to be inserted. This applies to instructions marked
510 INSN_LOAD_COPROC_DELAY, INSN_COPROC_MOVE_DELAY, and to delays
511 between instructions marked INSN_WRITE_COND_CODE and ones marked
512 INSN_READ_COND_CODE. These nops are only required at MIPS ISA
513 levels I, II, and III and microMIPS mode instructions are always
515 /* Itbl support may require additional care here. */
516 #define cop_interlocks \
517 ((mips_opts.isa != ISA_MIPS1 \
518 && mips_opts.isa != ISA_MIPS2 \
519 && mips_opts.isa != ISA_MIPS3) \
520 || mips_opts.arch == CPU_R4300 \
521 || mips_opts.micromips \
524 /* Whether the processor uses hardware interlocks to protect reads
525 from coprocessor registers after they are loaded from memory, and
526 thus does not require nops to be inserted. This applies to
527 instructions marked INSN_COPROC_MEMORY_DELAY. These nops are only
528 requires at MIPS ISA level I and microMIPS mode instructions are
529 always interlocked. */
530 #define cop_mem_interlocks \
531 (mips_opts.isa != ISA_MIPS1 \
532 || mips_opts.micromips \
535 /* Is this a mfhi or mflo instruction? */
536 #define MF_HILO_INSN(PINFO) \
537 ((PINFO & INSN_READ_HI) || (PINFO & INSN_READ_LO))
539 /* Whether code compression (either of the MIPS16 or the microMIPS ASEs)
540 has been selected. This implies, in particular, that addresses of text
541 labels have their LSB set. */
542 #define HAVE_CODE_COMPRESSION \
543 ((mips_opts.mips16 | mips_opts.micromips) != 0)
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 ? &mips16_nop_insn \
700 : (mips_opts.micromips ? µmips_nop16_insn : &nop_insn))
702 /* The size of NOP_INSN in bytes. */
703 #define NOP_INSN_SIZE (HAVE_CODE_COMPRESSION ? 2 : 4)
705 /* If this is set, it points to a frag holding nop instructions which
706 were inserted before the start of a noreorder section. If those
707 nops turn out to be unnecessary, the size of the frag can be
709 static fragS *prev_nop_frag;
711 /* The number of nop instructions we created in prev_nop_frag. */
712 static int prev_nop_frag_holds;
714 /* The number of nop instructions that we know we need in
716 static int prev_nop_frag_required;
718 /* The number of instructions we've seen since prev_nop_frag. */
719 static int prev_nop_frag_since;
721 /* For ECOFF and ELF, relocations against symbols are done in two
722 parts, with a HI relocation and a LO relocation. Each relocation
723 has only 16 bits of space to store an addend. This means that in
724 order for the linker to handle carries correctly, it must be able
725 to locate both the HI and the LO relocation. This means that the
726 relocations must appear in order in the relocation table.
728 In order to implement this, we keep track of each unmatched HI
729 relocation. We then sort them so that they immediately precede the
730 corresponding LO relocation. */
735 struct mips_hi_fixup *next;
738 /* The section this fixup is in. */
742 /* The list of unmatched HI relocs. */
744 static struct mips_hi_fixup *mips_hi_fixup_list;
746 /* The frag containing the last explicit relocation operator.
747 Null if explicit relocations have not been used. */
749 static fragS *prev_reloc_op_frag;
751 /* Map normal MIPS register numbers to mips16 register numbers. */
753 #define X ILLEGAL_REG
754 static const int mips32_to_16_reg_map[] =
756 X, X, 2, 3, 4, 5, 6, 7,
757 X, X, X, X, X, X, X, X,
758 0, 1, X, X, X, X, X, X,
759 X, X, X, X, X, X, X, X
763 /* Map mips16 register numbers to normal MIPS register numbers. */
765 static const unsigned int mips16_to_32_reg_map[] =
767 16, 17, 2, 3, 4, 5, 6, 7
770 /* Map normal MIPS register numbers to microMIPS register numbers. */
772 #define mips32_to_micromips_reg_b_map mips32_to_16_reg_map
773 #define mips32_to_micromips_reg_c_map mips32_to_16_reg_map
774 #define mips32_to_micromips_reg_d_map mips32_to_16_reg_map
775 #define mips32_to_micromips_reg_e_map mips32_to_16_reg_map
776 #define mips32_to_micromips_reg_f_map mips32_to_16_reg_map
777 #define mips32_to_micromips_reg_g_map mips32_to_16_reg_map
778 #define mips32_to_micromips_reg_l_map mips32_to_16_reg_map
780 #define X ILLEGAL_REG
781 /* reg type h: 4, 5, 6. */
782 static const int mips32_to_micromips_reg_h_map[] =
784 X, X, X, X, 4, 5, 6, X,
785 X, X, X, X, X, X, X, X,
786 X, X, X, X, X, X, X, X,
787 X, X, X, X, X, X, X, X
790 /* reg type m: 0, 17, 2, 3, 16, 18, 19, 20. */
791 static const int mips32_to_micromips_reg_m_map[] =
793 0, X, 2, 3, X, X, X, X,
794 X, X, X, X, X, X, X, X,
795 4, 1, 5, 6, 7, X, X, X,
796 X, X, X, X, X, X, X, X
799 /* reg type q: 0, 2-7. 17. */
800 static const int mips32_to_micromips_reg_q_map[] =
802 0, X, 2, 3, 4, 5, 6, 7,
803 X, X, X, X, X, X, X, X,
804 X, 1, X, X, X, X, X, X,
805 X, X, X, X, X, X, X, X
808 #define mips32_to_micromips_reg_n_map mips32_to_micromips_reg_m_map
811 /* Map microMIPS register numbers to normal MIPS register numbers. */
813 #define micromips_to_32_reg_b_map mips16_to_32_reg_map
814 #define micromips_to_32_reg_c_map mips16_to_32_reg_map
815 #define micromips_to_32_reg_d_map mips16_to_32_reg_map
816 #define micromips_to_32_reg_e_map mips16_to_32_reg_map
817 #define micromips_to_32_reg_f_map mips16_to_32_reg_map
818 #define micromips_to_32_reg_g_map mips16_to_32_reg_map
820 /* The microMIPS registers with type h. */
821 static const unsigned int micromips_to_32_reg_h_map[] =
823 5, 5, 6, 4, 4, 4, 4, 4
826 /* The microMIPS registers with type i. */
827 static const unsigned int micromips_to_32_reg_i_map[] =
829 6, 7, 7, 21, 22, 5, 6, 7
832 #define micromips_to_32_reg_l_map mips16_to_32_reg_map
834 /* The microMIPS registers with type m. */
835 static const unsigned int micromips_to_32_reg_m_map[] =
837 0, 17, 2, 3, 16, 18, 19, 20
840 #define micromips_to_32_reg_n_map micromips_to_32_reg_m_map
842 /* The microMIPS registers with type q. */
843 static const unsigned int micromips_to_32_reg_q_map[] =
845 0, 17, 2, 3, 4, 5, 6, 7
848 /* microMIPS imm type B. */
849 static const int micromips_imm_b_map[] =
851 1, 4, 8, 12, 16, 20, 24, -1
854 /* microMIPS imm type C. */
855 static const int micromips_imm_c_map[] =
857 128, 1, 2, 3, 4, 7, 8, 15, 16, 31, 32, 63, 64, 255, 32768, 65535
860 /* Classifies the kind of instructions we're interested in when
861 implementing -mfix-vr4120. */
862 enum fix_vr4120_class
870 NUM_FIX_VR4120_CLASSES
873 /* ...likewise -mfix-loongson2f-jump. */
874 static bfd_boolean mips_fix_loongson2f_jump;
876 /* ...likewise -mfix-loongson2f-nop. */
877 static bfd_boolean mips_fix_loongson2f_nop;
879 /* True if -mfix-loongson2f-nop or -mfix-loongson2f-jump passed. */
880 static bfd_boolean mips_fix_loongson2f;
882 /* Given two FIX_VR4120_* values X and Y, bit Y of element X is set if
883 there must be at least one other instruction between an instruction
884 of type X and an instruction of type Y. */
885 static unsigned int vr4120_conflicts[NUM_FIX_VR4120_CLASSES];
887 /* True if -mfix-vr4120 is in force. */
888 static int mips_fix_vr4120;
890 /* ...likewise -mfix-vr4130. */
891 static int mips_fix_vr4130;
893 /* ...likewise -mfix-24k. */
894 static int mips_fix_24k;
896 /* ...likewise -mfix-cn63xxp1 */
897 static bfd_boolean mips_fix_cn63xxp1;
899 /* We don't relax branches by default, since this causes us to expand
900 `la .l2 - .l1' if there's a branch between .l1 and .l2, because we
901 fail to compute the offset before expanding the macro to the most
902 efficient expansion. */
904 static int mips_relax_branch;
906 /* The expansion of many macros depends on the type of symbol that
907 they refer to. For example, when generating position-dependent code,
908 a macro that refers to a symbol may have two different expansions,
909 one which uses GP-relative addresses and one which uses absolute
910 addresses. When generating SVR4-style PIC, a macro may have
911 different expansions for local and global symbols.
913 We handle these situations by generating both sequences and putting
914 them in variant frags. In position-dependent code, the first sequence
915 will be the GP-relative one and the second sequence will be the
916 absolute one. In SVR4 PIC, the first sequence will be for global
917 symbols and the second will be for local symbols.
919 The frag's "subtype" is RELAX_ENCODE (FIRST, SECOND), where FIRST and
920 SECOND are the lengths of the two sequences in bytes. These fields
921 can be extracted using RELAX_FIRST() and RELAX_SECOND(). In addition,
922 the subtype has the following flags:
925 Set if it has been decided that we should use the second
926 sequence instead of the first.
929 Set in the first variant frag if the macro's second implementation
930 is longer than its first. This refers to the macro as a whole,
931 not an individual relaxation.
934 Set in the first variant frag if the macro appeared in a .set nomacro
935 block and if one alternative requires a warning but the other does not.
938 Like RELAX_NOMACRO, but indicates that the macro appears in a branch
941 RELAX_DELAY_SLOT_16BIT
942 Like RELAX_DELAY_SLOT, but indicates that the delay slot requires a
945 RELAX_DELAY_SLOT_SIZE_FIRST
946 Like RELAX_DELAY_SLOT, but indicates that the first implementation of
947 the macro is of the wrong size for the branch delay slot.
949 RELAX_DELAY_SLOT_SIZE_SECOND
950 Like RELAX_DELAY_SLOT, but indicates that the second implementation of
951 the macro is of the wrong size for the branch delay slot.
953 The frag's "opcode" points to the first fixup for relaxable code.
955 Relaxable macros are generated using a sequence such as:
957 relax_start (SYMBOL);
958 ... generate first expansion ...
960 ... generate second expansion ...
963 The code and fixups for the unwanted alternative are discarded
964 by md_convert_frag. */
965 #define RELAX_ENCODE(FIRST, SECOND) (((FIRST) << 8) | (SECOND))
967 #define RELAX_FIRST(X) (((X) >> 8) & 0xff)
968 #define RELAX_SECOND(X) ((X) & 0xff)
969 #define RELAX_USE_SECOND 0x10000
970 #define RELAX_SECOND_LONGER 0x20000
971 #define RELAX_NOMACRO 0x40000
972 #define RELAX_DELAY_SLOT 0x80000
973 #define RELAX_DELAY_SLOT_16BIT 0x100000
974 #define RELAX_DELAY_SLOT_SIZE_FIRST 0x200000
975 #define RELAX_DELAY_SLOT_SIZE_SECOND 0x400000
977 /* Branch without likely bit. If label is out of range, we turn:
979 beq reg1, reg2, label
989 with the following opcode replacements:
996 bltzal <-> bgezal (with jal label instead of j label)
998 Even though keeping the delay slot instruction in the delay slot of
999 the branch would be more efficient, it would be very tricky to do
1000 correctly, because we'd have to introduce a variable frag *after*
1001 the delay slot instruction, and expand that instead. Let's do it
1002 the easy way for now, even if the branch-not-taken case now costs
1003 one additional instruction. Out-of-range branches are not supposed
1004 to be common, anyway.
1006 Branch likely. If label is out of range, we turn:
1008 beql reg1, reg2, label
1009 delay slot (annulled if branch not taken)
1018 delay slot (executed only if branch taken)
1021 It would be possible to generate a shorter sequence by losing the
1022 likely bit, generating something like:
1027 delay slot (executed only if branch taken)
1039 bltzall -> bgezal (with jal label instead of j label)
1040 bgezall -> bltzal (ditto)
1043 but it's not clear that it would actually improve performance. */
1044 #define RELAX_BRANCH_ENCODE(at, uncond, likely, link, toofar) \
1045 ((relax_substateT) \
1048 | ((toofar) ? 0x20 : 0) \
1049 | ((link) ? 0x40 : 0) \
1050 | ((likely) ? 0x80 : 0) \
1051 | ((uncond) ? 0x100 : 0)))
1052 #define RELAX_BRANCH_P(i) (((i) & 0xf0000000) == 0xc0000000)
1053 #define RELAX_BRANCH_UNCOND(i) (((i) & 0x100) != 0)
1054 #define RELAX_BRANCH_LIKELY(i) (((i) & 0x80) != 0)
1055 #define RELAX_BRANCH_LINK(i) (((i) & 0x40) != 0)
1056 #define RELAX_BRANCH_TOOFAR(i) (((i) & 0x20) != 0)
1057 #define RELAX_BRANCH_AT(i) ((i) & 0x1f)
1059 /* For mips16 code, we use an entirely different form of relaxation.
1060 mips16 supports two versions of most instructions which take
1061 immediate values: a small one which takes some small value, and a
1062 larger one which takes a 16 bit value. Since branches also follow
1063 this pattern, relaxing these values is required.
1065 We can assemble both mips16 and normal MIPS code in a single
1066 object. Therefore, we need to support this type of relaxation at
1067 the same time that we support the relaxation described above. We
1068 use the high bit of the subtype field to distinguish these cases.
1070 The information we store for this type of relaxation is the
1071 argument code found in the opcode file for this relocation, whether
1072 the user explicitly requested a small or extended form, and whether
1073 the relocation is in a jump or jal delay slot. That tells us the
1074 size of the value, and how it should be stored. We also store
1075 whether the fragment is considered to be extended or not. We also
1076 store whether this is known to be a branch to a different section,
1077 whether we have tried to relax this frag yet, and whether we have
1078 ever extended a PC relative fragment because of a shift count. */
1079 #define RELAX_MIPS16_ENCODE(type, small, ext, dslot, jal_dslot) \
1082 | ((small) ? 0x100 : 0) \
1083 | ((ext) ? 0x200 : 0) \
1084 | ((dslot) ? 0x400 : 0) \
1085 | ((jal_dslot) ? 0x800 : 0))
1086 #define RELAX_MIPS16_P(i) (((i) & 0xc0000000) == 0x80000000)
1087 #define RELAX_MIPS16_TYPE(i) ((i) & 0xff)
1088 #define RELAX_MIPS16_USER_SMALL(i) (((i) & 0x100) != 0)
1089 #define RELAX_MIPS16_USER_EXT(i) (((i) & 0x200) != 0)
1090 #define RELAX_MIPS16_DSLOT(i) (((i) & 0x400) != 0)
1091 #define RELAX_MIPS16_JAL_DSLOT(i) (((i) & 0x800) != 0)
1092 #define RELAX_MIPS16_EXTENDED(i) (((i) & 0x1000) != 0)
1093 #define RELAX_MIPS16_MARK_EXTENDED(i) ((i) | 0x1000)
1094 #define RELAX_MIPS16_CLEAR_EXTENDED(i) ((i) &~ 0x1000)
1095 #define RELAX_MIPS16_LONG_BRANCH(i) (((i) & 0x2000) != 0)
1096 #define RELAX_MIPS16_MARK_LONG_BRANCH(i) ((i) | 0x2000)
1097 #define RELAX_MIPS16_CLEAR_LONG_BRANCH(i) ((i) &~ 0x2000)
1099 /* For microMIPS code, we use relaxation similar to one we use for
1100 MIPS16 code. Some instructions that take immediate values support
1101 two encodings: a small one which takes some small value, and a
1102 larger one which takes a 16 bit value. As some branches also follow
1103 this pattern, relaxing these values is required.
1105 We can assemble both microMIPS and normal MIPS code in a single
1106 object. Therefore, we need to support this type of relaxation at
1107 the same time that we support the relaxation described above. We
1108 use one of the high bits of the subtype field to distinguish these
1111 The information we store for this type of relaxation is the argument
1112 code found in the opcode file for this relocation, the register
1113 selected as the assembler temporary, whether the branch is
1114 unconditional, whether it is compact, whether it stores the link
1115 address implicitly in $ra, whether relaxation of out-of-range 32-bit
1116 branches to a sequence of instructions is enabled, and whether the
1117 displacement of a branch is too large to fit as an immediate argument
1118 of a 16-bit and a 32-bit branch, respectively. */
1119 #define RELAX_MICROMIPS_ENCODE(type, at, uncond, compact, link, \
1120 relax32, toofar16, toofar32) \
1123 | (((at) & 0x1f) << 8) \
1124 | ((uncond) ? 0x2000 : 0) \
1125 | ((compact) ? 0x4000 : 0) \
1126 | ((link) ? 0x8000 : 0) \
1127 | ((relax32) ? 0x10000 : 0) \
1128 | ((toofar16) ? 0x20000 : 0) \
1129 | ((toofar32) ? 0x40000 : 0))
1130 #define RELAX_MICROMIPS_P(i) (((i) & 0xc0000000) == 0x40000000)
1131 #define RELAX_MICROMIPS_TYPE(i) ((i) & 0xff)
1132 #define RELAX_MICROMIPS_AT(i) (((i) >> 8) & 0x1f)
1133 #define RELAX_MICROMIPS_UNCOND(i) (((i) & 0x2000) != 0)
1134 #define RELAX_MICROMIPS_COMPACT(i) (((i) & 0x4000) != 0)
1135 #define RELAX_MICROMIPS_LINK(i) (((i) & 0x8000) != 0)
1136 #define RELAX_MICROMIPS_RELAX32(i) (((i) & 0x10000) != 0)
1138 #define RELAX_MICROMIPS_TOOFAR16(i) (((i) & 0x20000) != 0)
1139 #define RELAX_MICROMIPS_MARK_TOOFAR16(i) ((i) | 0x20000)
1140 #define RELAX_MICROMIPS_CLEAR_TOOFAR16(i) ((i) & ~0x20000)
1141 #define RELAX_MICROMIPS_TOOFAR32(i) (((i) & 0x40000) != 0)
1142 #define RELAX_MICROMIPS_MARK_TOOFAR32(i) ((i) | 0x40000)
1143 #define RELAX_MICROMIPS_CLEAR_TOOFAR32(i) ((i) & ~0x40000)
1145 /* Sign-extend 16-bit value X. */
1146 #define SEXT_16BIT(X) ((((X) + 0x8000) & 0xffff) - 0x8000)
1148 /* Is the given value a sign-extended 32-bit value? */
1149 #define IS_SEXT_32BIT_NUM(x) \
1150 (((x) &~ (offsetT) 0x7fffffff) == 0 \
1151 || (((x) &~ (offsetT) 0x7fffffff) == ~ (offsetT) 0x7fffffff))
1153 /* Is the given value a sign-extended 16-bit value? */
1154 #define IS_SEXT_16BIT_NUM(x) \
1155 (((x) &~ (offsetT) 0x7fff) == 0 \
1156 || (((x) &~ (offsetT) 0x7fff) == ~ (offsetT) 0x7fff))
1158 /* Is the given value a sign-extended 12-bit value? */
1159 #define IS_SEXT_12BIT_NUM(x) \
1160 (((((x) & 0xfff) ^ 0x800LL) - 0x800LL) == (x))
1162 /* Is the given value a sign-extended 9-bit value? */
1163 #define IS_SEXT_9BIT_NUM(x) \
1164 (((((x) & 0x1ff) ^ 0x100LL) - 0x100LL) == (x))
1166 /* Is the given value a zero-extended 32-bit value? Or a negated one? */
1167 #define IS_ZEXT_32BIT_NUM(x) \
1168 (((x) &~ (offsetT) 0xffffffff) == 0 \
1169 || (((x) &~ (offsetT) 0xffffffff) == ~ (offsetT) 0xffffffff))
1171 /* Replace bits MASK << SHIFT of STRUCT with the equivalent bits in
1172 VALUE << SHIFT. VALUE is evaluated exactly once. */
1173 #define INSERT_BITS(STRUCT, VALUE, MASK, SHIFT) \
1174 (STRUCT) = (((STRUCT) & ~((MASK) << (SHIFT))) \
1175 | (((VALUE) & (MASK)) << (SHIFT)))
1177 /* Extract bits MASK << SHIFT from STRUCT and shift them right
1179 #define EXTRACT_BITS(STRUCT, MASK, SHIFT) \
1180 (((STRUCT) >> (SHIFT)) & (MASK))
1182 /* Change INSN's opcode so that the operand given by FIELD has value VALUE.
1183 INSN is a mips_cl_insn structure and VALUE is evaluated exactly once.
1185 include/opcode/mips.h specifies operand fields using the macros
1186 OP_MASK_<FIELD> and OP_SH_<FIELD>. The MIPS16 equivalents start
1187 with "MIPS16OP" instead of "OP". */
1188 #define INSERT_OPERAND(MICROMIPS, FIELD, INSN, VALUE) \
1191 INSERT_BITS ((INSN).insn_opcode, VALUE, \
1192 OP_MASK_##FIELD, OP_SH_##FIELD); \
1194 INSERT_BITS ((INSN).insn_opcode, VALUE, \
1195 MICROMIPSOP_MASK_##FIELD, MICROMIPSOP_SH_##FIELD); \
1197 #define MIPS16_INSERT_OPERAND(FIELD, INSN, VALUE) \
1198 INSERT_BITS ((INSN).insn_opcode, VALUE, \
1199 MIPS16OP_MASK_##FIELD, MIPS16OP_SH_##FIELD)
1201 /* Extract the operand given by FIELD from mips_cl_insn INSN. */
1202 #define EXTRACT_OPERAND(MICROMIPS, FIELD, INSN) \
1204 ? EXTRACT_BITS ((INSN).insn_opcode, OP_MASK_##FIELD, OP_SH_##FIELD) \
1205 : EXTRACT_BITS ((INSN).insn_opcode, \
1206 MICROMIPSOP_MASK_##FIELD, MICROMIPSOP_SH_##FIELD))
1207 #define MIPS16_EXTRACT_OPERAND(FIELD, INSN) \
1208 EXTRACT_BITS ((INSN).insn_opcode, \
1209 MIPS16OP_MASK_##FIELD, \
1210 MIPS16OP_SH_##FIELD)
1212 /* The MIPS16 EXTEND opcode, shifted left 16 places. */
1213 #define MIPS16_EXTEND (0xf000U << 16)
1215 /* Whether or not we are emitting a branch-likely macro. */
1216 static bfd_boolean emit_branch_likely_macro = FALSE;
1218 /* Global variables used when generating relaxable macros. See the
1219 comment above RELAX_ENCODE for more details about how relaxation
1222 /* 0 if we're not emitting a relaxable macro.
1223 1 if we're emitting the first of the two relaxation alternatives.
1224 2 if we're emitting the second alternative. */
1227 /* The first relaxable fixup in the current frag. (In other words,
1228 the first fixup that refers to relaxable code.) */
1231 /* sizes[0] says how many bytes of the first alternative are stored in
1232 the current frag. Likewise sizes[1] for the second alternative. */
1233 unsigned int sizes[2];
1235 /* The symbol on which the choice of sequence depends. */
1239 /* Global variables used to decide whether a macro needs a warning. */
1241 /* True if the macro is in a branch delay slot. */
1242 bfd_boolean delay_slot_p;
1244 /* Set to the length in bytes required if the macro is in a delay slot
1245 that requires a specific length of instruction, otherwise zero. */
1246 unsigned int delay_slot_length;
1248 /* For relaxable macros, sizes[0] is the length of the first alternative
1249 in bytes and sizes[1] is the length of the second alternative.
1250 For non-relaxable macros, both elements give the length of the
1252 unsigned int sizes[2];
1254 /* For relaxable macros, first_insn_sizes[0] is the length of the first
1255 instruction of the first alternative in bytes and first_insn_sizes[1]
1256 is the length of the first instruction of the second alternative.
1257 For non-relaxable macros, both elements give the length of the first
1258 instruction in bytes.
1260 Set to zero if we haven't yet seen the first instruction. */
1261 unsigned int first_insn_sizes[2];
1263 /* For relaxable macros, insns[0] is the number of instructions for the
1264 first alternative and insns[1] is the number of instructions for the
1267 For non-relaxable macros, both elements give the number of
1268 instructions for the macro. */
1269 unsigned int insns[2];
1271 /* The first variant frag for this macro. */
1273 } mips_macro_warning;
1275 /* Prototypes for static functions. */
1277 enum mips_regclass { MIPS_GR_REG, MIPS_FP_REG, MIPS16_REG };
1279 static void append_insn
1280 (struct mips_cl_insn *, expressionS *, bfd_reloc_code_real_type *,
1281 bfd_boolean expansionp);
1282 static void mips_no_prev_insn (void);
1283 static void macro_build (expressionS *, const char *, const char *, ...);
1284 static void mips16_macro_build
1285 (expressionS *, const char *, const char *, va_list *);
1286 static void load_register (int, expressionS *, int);
1287 static void macro_start (void);
1288 static void macro_end (void);
1289 static void macro (struct mips_cl_insn * ip);
1290 static void mips16_macro (struct mips_cl_insn * ip);
1291 static void mips_ip (char *str, struct mips_cl_insn * ip);
1292 static void mips16_ip (char *str, struct mips_cl_insn * ip);
1293 static void mips16_immed
1294 (char *, unsigned int, int, bfd_reloc_code_real_type, offsetT,
1295 unsigned int, unsigned long *);
1296 static size_t my_getSmallExpression
1297 (expressionS *, bfd_reloc_code_real_type *, char *);
1298 static void my_getExpression (expressionS *, char *);
1299 static void s_align (int);
1300 static void s_change_sec (int);
1301 static void s_change_section (int);
1302 static void s_cons (int);
1303 static void s_float_cons (int);
1304 static void s_mips_globl (int);
1305 static void s_option (int);
1306 static void s_mipsset (int);
1307 static void s_abicalls (int);
1308 static void s_cpload (int);
1309 static void s_cpsetup (int);
1310 static void s_cplocal (int);
1311 static void s_cprestore (int);
1312 static void s_cpreturn (int);
1313 static void s_dtprelword (int);
1314 static void s_dtpreldword (int);
1315 static void s_tprelword (int);
1316 static void s_tpreldword (int);
1317 static void s_gpvalue (int);
1318 static void s_gpword (int);
1319 static void s_gpdword (int);
1320 static void s_ehword (int);
1321 static void s_cpadd (int);
1322 static void s_insn (int);
1323 static void md_obj_begin (void);
1324 static void md_obj_end (void);
1325 static void s_mips_ent (int);
1326 static void s_mips_end (int);
1327 static void s_mips_frame (int);
1328 static void s_mips_mask (int reg_type);
1329 static void s_mips_stab (int);
1330 static void s_mips_weakext (int);
1331 static void s_mips_file (int);
1332 static void s_mips_loc (int);
1333 static bfd_boolean pic_need_relax (symbolS *, asection *);
1334 static int relaxed_branch_length (fragS *, asection *, int);
1335 static int validate_mips_insn (const struct mips_opcode *);
1336 static int validate_micromips_insn (const struct mips_opcode *);
1337 static int relaxed_micromips_16bit_branch_length (fragS *, asection *, int);
1338 static int relaxed_micromips_32bit_branch_length (fragS *, asection *, int);
1340 /* Table and functions used to map between CPU/ISA names, and
1341 ISA levels, and CPU numbers. */
1343 struct mips_cpu_info
1345 const char *name; /* CPU or ISA name. */
1346 int flags; /* MIPS_CPU_* flags. */
1347 int ase; /* Set of ASEs implemented by the CPU. */
1348 int isa; /* ISA level. */
1349 int cpu; /* CPU number (default CPU if ISA). */
1352 #define MIPS_CPU_IS_ISA 0x0001 /* Is this an ISA? (If 0, a CPU.) */
1354 static const struct mips_cpu_info *mips_parse_cpu (const char *, const char *);
1355 static const struct mips_cpu_info *mips_cpu_info_from_isa (int);
1356 static const struct mips_cpu_info *mips_cpu_info_from_arch (int);
1358 /* Command-line options. */
1359 const char *md_shortopts = "O::g::G:";
1363 OPTION_MARCH = OPTION_MD_BASE,
1387 OPTION_NO_SMARTMIPS,
1393 OPTION_NO_MICROMIPS,
1396 OPTION_COMPAT_ARCH_BASE,
1405 OPTION_M7000_HILO_FIX,
1406 OPTION_MNO_7000_HILO_FIX,
1409 OPTION_FIX_LOONGSON2F_JUMP,
1410 OPTION_NO_FIX_LOONGSON2F_JUMP,
1411 OPTION_FIX_LOONGSON2F_NOP,
1412 OPTION_NO_FIX_LOONGSON2F_NOP,
1414 OPTION_NO_FIX_VR4120,
1416 OPTION_NO_FIX_VR4130,
1417 OPTION_FIX_CN63XXP1,
1418 OPTION_NO_FIX_CN63XXP1,
1425 OPTION_CONSTRUCT_FLOATS,
1426 OPTION_NO_CONSTRUCT_FLOATS,
1429 OPTION_RELAX_BRANCH,
1430 OPTION_NO_RELAX_BRANCH,
1437 OPTION_SINGLE_FLOAT,
1438 OPTION_DOUBLE_FLOAT,
1452 OPTION_MVXWORKS_PIC,
1453 #endif /* OBJ_ELF */
1457 struct option md_longopts[] =
1459 /* Options which specify architecture. */
1460 {"march", required_argument, NULL, OPTION_MARCH},
1461 {"mtune", required_argument, NULL, OPTION_MTUNE},
1462 {"mips0", no_argument, NULL, OPTION_MIPS1},
1463 {"mips1", no_argument, NULL, OPTION_MIPS1},
1464 {"mips2", no_argument, NULL, OPTION_MIPS2},
1465 {"mips3", no_argument, NULL, OPTION_MIPS3},
1466 {"mips4", no_argument, NULL, OPTION_MIPS4},
1467 {"mips5", no_argument, NULL, OPTION_MIPS5},
1468 {"mips32", no_argument, NULL, OPTION_MIPS32},
1469 {"mips64", no_argument, NULL, OPTION_MIPS64},
1470 {"mips32r2", no_argument, NULL, OPTION_MIPS32R2},
1471 {"mips64r2", no_argument, NULL, OPTION_MIPS64R2},
1473 /* Options which specify Application Specific Extensions (ASEs). */
1474 {"mips16", no_argument, NULL, OPTION_MIPS16},
1475 {"no-mips16", no_argument, NULL, OPTION_NO_MIPS16},
1476 {"mips3d", no_argument, NULL, OPTION_MIPS3D},
1477 {"no-mips3d", no_argument, NULL, OPTION_NO_MIPS3D},
1478 {"mdmx", no_argument, NULL, OPTION_MDMX},
1479 {"no-mdmx", no_argument, NULL, OPTION_NO_MDMX},
1480 {"mdsp", no_argument, NULL, OPTION_DSP},
1481 {"mno-dsp", no_argument, NULL, OPTION_NO_DSP},
1482 {"mmt", no_argument, NULL, OPTION_MT},
1483 {"mno-mt", no_argument, NULL, OPTION_NO_MT},
1484 {"msmartmips", no_argument, NULL, OPTION_SMARTMIPS},
1485 {"mno-smartmips", no_argument, NULL, OPTION_NO_SMARTMIPS},
1486 {"mdspr2", no_argument, NULL, OPTION_DSPR2},
1487 {"mno-dspr2", no_argument, NULL, OPTION_NO_DSPR2},
1488 {"meva", no_argument, NULL, OPTION_EVA},
1489 {"mno-eva", no_argument, NULL, OPTION_NO_EVA},
1490 {"mmicromips", no_argument, NULL, OPTION_MICROMIPS},
1491 {"mno-micromips", no_argument, NULL, OPTION_NO_MICROMIPS},
1492 {"mmcu", no_argument, NULL, OPTION_MCU},
1493 {"mno-mcu", no_argument, NULL, OPTION_NO_MCU},
1494 {"mvirt", no_argument, NULL, OPTION_VIRT},
1495 {"mno-virt", no_argument, NULL, OPTION_NO_VIRT},
1497 /* Old-style architecture options. Don't add more of these. */
1498 {"m4650", no_argument, NULL, OPTION_M4650},
1499 {"no-m4650", no_argument, NULL, OPTION_NO_M4650},
1500 {"m4010", no_argument, NULL, OPTION_M4010},
1501 {"no-m4010", no_argument, NULL, OPTION_NO_M4010},
1502 {"m4100", no_argument, NULL, OPTION_M4100},
1503 {"no-m4100", no_argument, NULL, OPTION_NO_M4100},
1504 {"m3900", no_argument, NULL, OPTION_M3900},
1505 {"no-m3900", no_argument, NULL, OPTION_NO_M3900},
1507 /* Options which enable bug fixes. */
1508 {"mfix7000", no_argument, NULL, OPTION_M7000_HILO_FIX},
1509 {"no-fix-7000", no_argument, NULL, OPTION_MNO_7000_HILO_FIX},
1510 {"mno-fix7000", no_argument, NULL, OPTION_MNO_7000_HILO_FIX},
1511 {"mfix-loongson2f-jump", no_argument, NULL, OPTION_FIX_LOONGSON2F_JUMP},
1512 {"mno-fix-loongson2f-jump", no_argument, NULL, OPTION_NO_FIX_LOONGSON2F_JUMP},
1513 {"mfix-loongson2f-nop", no_argument, NULL, OPTION_FIX_LOONGSON2F_NOP},
1514 {"mno-fix-loongson2f-nop", no_argument, NULL, OPTION_NO_FIX_LOONGSON2F_NOP},
1515 {"mfix-vr4120", no_argument, NULL, OPTION_FIX_VR4120},
1516 {"mno-fix-vr4120", no_argument, NULL, OPTION_NO_FIX_VR4120},
1517 {"mfix-vr4130", no_argument, NULL, OPTION_FIX_VR4130},
1518 {"mno-fix-vr4130", no_argument, NULL, OPTION_NO_FIX_VR4130},
1519 {"mfix-24k", no_argument, NULL, OPTION_FIX_24K},
1520 {"mno-fix-24k", no_argument, NULL, OPTION_NO_FIX_24K},
1521 {"mfix-cn63xxp1", no_argument, NULL, OPTION_FIX_CN63XXP1},
1522 {"mno-fix-cn63xxp1", no_argument, NULL, OPTION_NO_FIX_CN63XXP1},
1524 /* Miscellaneous options. */
1525 {"trap", no_argument, NULL, OPTION_TRAP},
1526 {"no-break", no_argument, NULL, OPTION_TRAP},
1527 {"break", no_argument, NULL, OPTION_BREAK},
1528 {"no-trap", no_argument, NULL, OPTION_BREAK},
1529 {"EB", no_argument, NULL, OPTION_EB},
1530 {"EL", no_argument, NULL, OPTION_EL},
1531 {"mfp32", no_argument, NULL, OPTION_FP32},
1532 {"mgp32", no_argument, NULL, OPTION_GP32},
1533 {"construct-floats", no_argument, NULL, OPTION_CONSTRUCT_FLOATS},
1534 {"no-construct-floats", no_argument, NULL, OPTION_NO_CONSTRUCT_FLOATS},
1535 {"mfp64", no_argument, NULL, OPTION_FP64},
1536 {"mgp64", no_argument, NULL, OPTION_GP64},
1537 {"relax-branch", no_argument, NULL, OPTION_RELAX_BRANCH},
1538 {"no-relax-branch", no_argument, NULL, OPTION_NO_RELAX_BRANCH},
1539 {"mshared", no_argument, NULL, OPTION_MSHARED},
1540 {"mno-shared", no_argument, NULL, OPTION_MNO_SHARED},
1541 {"msym32", no_argument, NULL, OPTION_MSYM32},
1542 {"mno-sym32", no_argument, NULL, OPTION_MNO_SYM32},
1543 {"msoft-float", no_argument, NULL, OPTION_SOFT_FLOAT},
1544 {"mhard-float", no_argument, NULL, OPTION_HARD_FLOAT},
1545 {"msingle-float", no_argument, NULL, OPTION_SINGLE_FLOAT},
1546 {"mdouble-float", no_argument, NULL, OPTION_DOUBLE_FLOAT},
1548 /* Strictly speaking this next option is ELF specific,
1549 but we allow it for other ports as well in order to
1550 make testing easier. */
1551 {"32", no_argument, NULL, OPTION_32},
1553 /* ELF-specific options. */
1555 {"KPIC", no_argument, NULL, OPTION_CALL_SHARED},
1556 {"call_shared", no_argument, NULL, OPTION_CALL_SHARED},
1557 {"call_nonpic", no_argument, NULL, OPTION_CALL_NONPIC},
1558 {"non_shared", no_argument, NULL, OPTION_NON_SHARED},
1559 {"xgot", no_argument, NULL, OPTION_XGOT},
1560 {"mabi", required_argument, NULL, OPTION_MABI},
1561 {"n32", no_argument, NULL, OPTION_N32},
1562 {"64", no_argument, NULL, OPTION_64},
1563 {"mdebug", no_argument, NULL, OPTION_MDEBUG},
1564 {"no-mdebug", no_argument, NULL, OPTION_NO_MDEBUG},
1565 {"mpdr", no_argument, NULL, OPTION_PDR},
1566 {"mno-pdr", no_argument, NULL, OPTION_NO_PDR},
1567 {"mvxworks-pic", no_argument, NULL, OPTION_MVXWORKS_PIC},
1568 #endif /* OBJ_ELF */
1570 {NULL, no_argument, NULL, 0}
1572 size_t md_longopts_size = sizeof (md_longopts);
1574 /* Information about either an Application Specific Extension or an
1575 optional architecture feature that, for simplicity, we treat in the
1576 same way as an ASE. */
1579 /* The name of the ASE, used in both the command-line and .set options. */
1582 /* The associated ASE_* flags. If the ASE is available on both 32-bit
1583 and 64-bit architectures, the flags here refer to the subset that
1584 is available on both. */
1587 /* The ASE_* flag used for instructions that are available on 64-bit
1588 architectures but that are not included in FLAGS. */
1589 unsigned int flags64;
1591 /* The command-line options that turn the ASE on and off. */
1595 /* The minimum required architecture revisions for MIPS32, MIPS64,
1596 microMIPS32 and microMIPS64, or -1 if the extension isn't supported. */
1599 int micromips32_rev;
1600 int micromips64_rev;
1603 /* A table of all supported ASEs. */
1604 static const struct mips_ase mips_ases[] = {
1605 { "dsp", ASE_DSP, ASE_DSP64,
1606 OPTION_DSP, OPTION_NO_DSP,
1609 { "dspr2", ASE_DSP | ASE_DSPR2, 0,
1610 OPTION_DSPR2, OPTION_NO_DSPR2,
1613 { "eva", ASE_EVA, 0,
1614 OPTION_EVA, OPTION_NO_EVA,
1617 { "mcu", ASE_MCU, 0,
1618 OPTION_MCU, OPTION_NO_MCU,
1621 /* Deprecated in MIPS64r5, but we don't implement that yet. */
1622 { "mdmx", ASE_MDMX, 0,
1623 OPTION_MDMX, OPTION_NO_MDMX,
1626 /* Requires 64-bit FPRs, so the minimum MIPS32 revision is 2. */
1627 { "mips3d", ASE_MIPS3D, 0,
1628 OPTION_MIPS3D, OPTION_NO_MIPS3D,
1632 OPTION_MT, OPTION_NO_MT,
1635 { "smartmips", ASE_SMARTMIPS, 0,
1636 OPTION_SMARTMIPS, OPTION_NO_SMARTMIPS,
1639 { "virt", ASE_VIRT, ASE_VIRT64,
1640 OPTION_VIRT, OPTION_NO_VIRT,
1644 /* The set of ASEs that require -mfp64. */
1645 #define FP64_ASES (ASE_MIPS3D | ASE_MDMX)
1647 /* Groups of ASE_* flags that represent different revisions of an ASE. */
1648 static const unsigned int mips_ase_groups[] = {
1654 The following pseudo-ops from the Kane and Heinrich MIPS book
1655 should be defined here, but are currently unsupported: .alias,
1656 .galive, .gjaldef, .gjrlive, .livereg, .noalias.
1658 The following pseudo-ops from the Kane and Heinrich MIPS book are
1659 specific to the type of debugging information being generated, and
1660 should be defined by the object format: .aent, .begin, .bend,
1661 .bgnb, .end, .endb, .ent, .fmask, .frame, .loc, .mask, .verstamp,
1664 The following pseudo-ops from the Kane and Heinrich MIPS book are
1665 not MIPS CPU specific, but are also not specific to the object file
1666 format. This file is probably the best place to define them, but
1667 they are not currently supported: .asm0, .endr, .lab, .struct. */
1669 static const pseudo_typeS mips_pseudo_table[] =
1671 /* MIPS specific pseudo-ops. */
1672 {"option", s_option, 0},
1673 {"set", s_mipsset, 0},
1674 {"rdata", s_change_sec, 'r'},
1675 {"sdata", s_change_sec, 's'},
1676 {"livereg", s_ignore, 0},
1677 {"abicalls", s_abicalls, 0},
1678 {"cpload", s_cpload, 0},
1679 {"cpsetup", s_cpsetup, 0},
1680 {"cplocal", s_cplocal, 0},
1681 {"cprestore", s_cprestore, 0},
1682 {"cpreturn", s_cpreturn, 0},
1683 {"dtprelword", s_dtprelword, 0},
1684 {"dtpreldword", s_dtpreldword, 0},
1685 {"tprelword", s_tprelword, 0},
1686 {"tpreldword", s_tpreldword, 0},
1687 {"gpvalue", s_gpvalue, 0},
1688 {"gpword", s_gpword, 0},
1689 {"gpdword", s_gpdword, 0},
1690 {"ehword", s_ehword, 0},
1691 {"cpadd", s_cpadd, 0},
1692 {"insn", s_insn, 0},
1694 /* Relatively generic pseudo-ops that happen to be used on MIPS
1696 {"asciiz", stringer, 8 + 1},
1697 {"bss", s_change_sec, 'b'},
1699 {"half", s_cons, 1},
1700 {"dword", s_cons, 3},
1701 {"weakext", s_mips_weakext, 0},
1702 {"origin", s_org, 0},
1703 {"repeat", s_rept, 0},
1705 /* For MIPS this is non-standard, but we define it for consistency. */
1706 {"sbss", s_change_sec, 'B'},
1708 /* These pseudo-ops are defined in read.c, but must be overridden
1709 here for one reason or another. */
1710 {"align", s_align, 0},
1711 {"byte", s_cons, 0},
1712 {"data", s_change_sec, 'd'},
1713 {"double", s_float_cons, 'd'},
1714 {"float", s_float_cons, 'f'},
1715 {"globl", s_mips_globl, 0},
1716 {"global", s_mips_globl, 0},
1717 {"hword", s_cons, 1},
1719 {"long", s_cons, 2},
1720 {"octa", s_cons, 4},
1721 {"quad", s_cons, 3},
1722 {"section", s_change_section, 0},
1723 {"short", s_cons, 1},
1724 {"single", s_float_cons, 'f'},
1725 {"stabd", s_mips_stab, 'd'},
1726 {"stabn", s_mips_stab, 'n'},
1727 {"stabs", s_mips_stab, 's'},
1728 {"text", s_change_sec, 't'},
1729 {"word", s_cons, 2},
1731 { "extern", ecoff_directive_extern, 0},
1736 static const pseudo_typeS mips_nonecoff_pseudo_table[] =
1738 /* These pseudo-ops should be defined by the object file format.
1739 However, a.out doesn't support them, so we have versions here. */
1740 {"aent", s_mips_ent, 1},
1741 {"bgnb", s_ignore, 0},
1742 {"end", s_mips_end, 0},
1743 {"endb", s_ignore, 0},
1744 {"ent", s_mips_ent, 0},
1745 {"file", s_mips_file, 0},
1746 {"fmask", s_mips_mask, 'F'},
1747 {"frame", s_mips_frame, 0},
1748 {"loc", s_mips_loc, 0},
1749 {"mask", s_mips_mask, 'R'},
1750 {"verstamp", s_ignore, 0},
1754 /* Export the ABI address size for use by TC_ADDRESS_BYTES for the
1755 purpose of the `.dc.a' internal pseudo-op. */
1758 mips_address_bytes (void)
1760 return HAVE_64BIT_ADDRESSES ? 8 : 4;
1763 extern void pop_insert (const pseudo_typeS *);
1766 mips_pop_insert (void)
1768 pop_insert (mips_pseudo_table);
1769 if (! ECOFF_DEBUGGING)
1770 pop_insert (mips_nonecoff_pseudo_table);
1773 /* Symbols labelling the current insn. */
1775 struct insn_label_list
1777 struct insn_label_list *next;
1781 static struct insn_label_list *free_insn_labels;
1782 #define label_list tc_segment_info_data.labels
1784 static void mips_clear_insn_labels (void);
1785 static void mips_mark_labels (void);
1786 static void mips_compressed_mark_labels (void);
1789 mips_clear_insn_labels (void)
1791 register struct insn_label_list **pl;
1792 segment_info_type *si;
1796 for (pl = &free_insn_labels; *pl != NULL; pl = &(*pl)->next)
1799 si = seg_info (now_seg);
1800 *pl = si->label_list;
1801 si->label_list = NULL;
1805 /* Mark instruction labels in MIPS16/microMIPS mode. */
1808 mips_mark_labels (void)
1810 if (HAVE_CODE_COMPRESSION)
1811 mips_compressed_mark_labels ();
1814 static char *expr_end;
1816 /* Expressions which appear in instructions. These are set by
1819 static expressionS imm_expr;
1820 static expressionS imm2_expr;
1821 static expressionS offset_expr;
1823 /* Relocs associated with imm_expr and offset_expr. */
1825 static bfd_reloc_code_real_type imm_reloc[3]
1826 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
1827 static bfd_reloc_code_real_type offset_reloc[3]
1828 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
1830 /* This is set to the resulting size of the instruction to be produced
1831 by mips16_ip if an explicit extension is used or by mips_ip if an
1832 explicit size is supplied. */
1834 static unsigned int forced_insn_length;
1836 /* True if we are assembling an instruction. All dot symbols defined during
1837 this time should be treated as code labels. */
1839 static bfd_boolean mips_assembling_insn;
1842 /* The pdr segment for per procedure frame/regmask info. Not used for
1845 static segT pdr_seg;
1848 /* The default target format to use. */
1850 #if defined (TE_FreeBSD)
1851 #define ELF_TARGET(PREFIX, ENDIAN) PREFIX "trad" ENDIAN "mips-freebsd"
1852 #elif defined (TE_TMIPS)
1853 #define ELF_TARGET(PREFIX, ENDIAN) PREFIX "trad" ENDIAN "mips"
1855 #define ELF_TARGET(PREFIX, ENDIAN) PREFIX ENDIAN "mips"
1859 mips_target_format (void)
1861 switch (OUTPUT_FLAVOR)
1863 case bfd_target_ecoff_flavour:
1864 return target_big_endian ? "ecoff-bigmips" : ECOFF_LITTLE_FORMAT;
1865 case bfd_target_coff_flavour:
1867 case bfd_target_elf_flavour:
1869 if (!HAVE_64BIT_OBJECTS && !HAVE_NEWABI)
1870 return (target_big_endian
1871 ? "elf32-bigmips-vxworks"
1872 : "elf32-littlemips-vxworks");
1874 return (target_big_endian
1875 ? (HAVE_64BIT_OBJECTS
1876 ? ELF_TARGET ("elf64-", "big")
1878 ? ELF_TARGET ("elf32-n", "big")
1879 : ELF_TARGET ("elf32-", "big")))
1880 : (HAVE_64BIT_OBJECTS
1881 ? ELF_TARGET ("elf64-", "little")
1883 ? ELF_TARGET ("elf32-n", "little")
1884 : ELF_TARGET ("elf32-", "little"))));
1891 /* Return the ISA revision that is currently in use, or 0 if we are
1892 generating code for MIPS V or below. */
1897 if (mips_opts.isa == ISA_MIPS32R2 || mips_opts.isa == ISA_MIPS64R2)
1900 /* microMIPS implies revision 2 or above. */
1901 if (mips_opts.micromips)
1904 if (mips_opts.isa == ISA_MIPS32 || mips_opts.isa == ISA_MIPS64)
1910 /* Return the mask of all ASEs that are revisions of those in FLAGS. */
1913 mips_ase_mask (unsigned int flags)
1917 for (i = 0; i < ARRAY_SIZE (mips_ase_groups); i++)
1918 if (flags & mips_ase_groups[i])
1919 flags |= mips_ase_groups[i];
1923 /* Check whether the current ISA supports ASE. Issue a warning if
1927 mips_check_isa_supports_ase (const struct mips_ase *ase)
1931 static unsigned int warned_isa;
1932 static unsigned int warned_fp32;
1934 if (ISA_HAS_64BIT_REGS (mips_opts.isa))
1935 min_rev = mips_opts.micromips ? ase->micromips64_rev : ase->mips64_rev;
1937 min_rev = mips_opts.micromips ? ase->micromips32_rev : ase->mips32_rev;
1938 if ((min_rev < 0 || mips_isa_rev () < min_rev)
1939 && (warned_isa & ase->flags) != ase->flags)
1941 warned_isa |= ase->flags;
1942 base = mips_opts.micromips ? "microMIPS" : "MIPS";
1943 size = ISA_HAS_64BIT_REGS (mips_opts.isa) ? 64 : 32;
1945 as_warn (_("The %d-bit %s architecture does not support the"
1946 " `%s' extension"), size, base, ase->name);
1948 as_warn (_("The `%s' extension requires %s%d revision %d or greater"),
1949 ase->name, base, size, min_rev);
1951 if ((ase->flags & FP64_ASES)
1953 && (warned_fp32 & ase->flags) != ase->flags)
1955 warned_fp32 |= ase->flags;
1956 as_warn (_("The `%s' extension requires 64-bit FPRs"), ase->name);
1960 /* Check all enabled ASEs to see whether they are supported by the
1961 chosen architecture. */
1964 mips_check_isa_supports_ases (void)
1966 unsigned int i, mask;
1968 for (i = 0; i < ARRAY_SIZE (mips_ases); i++)
1970 mask = mips_ase_mask (mips_ases[i].flags);
1971 if ((mips_opts.ase & mask) == mips_ases[i].flags)
1972 mips_check_isa_supports_ase (&mips_ases[i]);
1976 /* Set the state of ASE to ENABLED_P. Return the mask of ASE_* flags
1977 that were affected. */
1980 mips_set_ase (const struct mips_ase *ase, bfd_boolean enabled_p)
1984 mask = mips_ase_mask (ase->flags);
1985 mips_opts.ase &= ~mask;
1987 mips_opts.ase |= ase->flags;
1991 /* Return the ASE called NAME, or null if none. */
1993 static const struct mips_ase *
1994 mips_lookup_ase (const char *name)
1998 for (i = 0; i < ARRAY_SIZE (mips_ases); i++)
1999 if (strcmp (name, mips_ases[i].name) == 0)
2000 return &mips_ases[i];
2004 /* Return the length of a microMIPS instruction in bytes. If bits of
2005 the mask beyond the low 16 are 0, then it is a 16-bit instruction.
2006 Otherwise assume a 32-bit instruction; 48-bit instructions (0x1f
2007 major opcode) will require further modifications to the opcode
2010 static inline unsigned int
2011 micromips_insn_length (const struct mips_opcode *mo)
2013 return (mo->mask >> 16) == 0 ? 2 : 4;
2016 /* Return the length of MIPS16 instruction OPCODE. */
2018 static inline unsigned int
2019 mips16_opcode_length (unsigned long opcode)
2021 return (opcode >> 16) == 0 ? 2 : 4;
2024 /* Return the length of instruction INSN. */
2026 static inline unsigned int
2027 insn_length (const struct mips_cl_insn *insn)
2029 if (mips_opts.micromips)
2030 return micromips_insn_length (insn->insn_mo);
2031 else if (mips_opts.mips16)
2032 return mips16_opcode_length (insn->insn_opcode);
2037 /* Initialise INSN from opcode entry MO. Leave its position unspecified. */
2040 create_insn (struct mips_cl_insn *insn, const struct mips_opcode *mo)
2045 insn->insn_opcode = mo->match;
2048 for (i = 0; i < ARRAY_SIZE (insn->fixp); i++)
2049 insn->fixp[i] = NULL;
2050 insn->fixed_p = (mips_opts.noreorder > 0);
2051 insn->noreorder_p = (mips_opts.noreorder > 0);
2052 insn->mips16_absolute_jump_p = 0;
2053 insn->complete_p = 0;
2054 insn->cleared_p = 0;
2057 /* Record the current MIPS16/microMIPS mode in now_seg. */
2060 mips_record_compressed_mode (void)
2062 segment_info_type *si;
2064 si = seg_info (now_seg);
2065 if (si->tc_segment_info_data.mips16 != mips_opts.mips16)
2066 si->tc_segment_info_data.mips16 = mips_opts.mips16;
2067 if (si->tc_segment_info_data.micromips != mips_opts.micromips)
2068 si->tc_segment_info_data.micromips = mips_opts.micromips;
2071 /* Read a standard MIPS instruction from BUF. */
2073 static unsigned long
2074 read_insn (char *buf)
2076 if (target_big_endian)
2077 return bfd_getb32 ((bfd_byte *) buf);
2079 return bfd_getl32 ((bfd_byte *) buf);
2082 /* Write standard MIPS instruction INSN to BUF. Return a pointer to
2086 write_insn (char *buf, unsigned int insn)
2088 md_number_to_chars (buf, insn, 4);
2092 /* Read a microMIPS or MIPS16 opcode from BUF, given that it
2093 has length LENGTH. */
2095 static unsigned long
2096 read_compressed_insn (char *buf, unsigned int length)
2102 for (i = 0; i < length; i += 2)
2105 if (target_big_endian)
2106 insn |= bfd_getb16 ((char *) buf);
2108 insn |= bfd_getl16 ((char *) buf);
2114 /* Write microMIPS or MIPS16 instruction INSN to BUF, given that the
2115 instruction is LENGTH bytes long. Return a pointer to the next byte. */
2118 write_compressed_insn (char *buf, unsigned int insn, unsigned int length)
2122 for (i = 0; i < length; i += 2)
2123 md_number_to_chars (buf + i, insn >> ((length - i - 2) * 8), 2);
2124 return buf + length;
2127 /* Install INSN at the location specified by its "frag" and "where" fields. */
2130 install_insn (const struct mips_cl_insn *insn)
2132 char *f = insn->frag->fr_literal + insn->where;
2133 if (HAVE_CODE_COMPRESSION)
2134 write_compressed_insn (f, insn->insn_opcode, insn_length (insn));
2136 write_insn (f, insn->insn_opcode);
2137 mips_record_compressed_mode ();
2140 /* Move INSN to offset WHERE in FRAG. Adjust the fixups accordingly
2141 and install the opcode in the new location. */
2144 move_insn (struct mips_cl_insn *insn, fragS *frag, long where)
2149 insn->where = where;
2150 for (i = 0; i < ARRAY_SIZE (insn->fixp); i++)
2151 if (insn->fixp[i] != NULL)
2153 insn->fixp[i]->fx_frag = frag;
2154 insn->fixp[i]->fx_where = where;
2156 install_insn (insn);
2159 /* Add INSN to the end of the output. */
2162 add_fixed_insn (struct mips_cl_insn *insn)
2164 char *f = frag_more (insn_length (insn));
2165 move_insn (insn, frag_now, f - frag_now->fr_literal);
2168 /* Start a variant frag and move INSN to the start of the variant part,
2169 marking it as fixed. The other arguments are as for frag_var. */
2172 add_relaxed_insn (struct mips_cl_insn *insn, int max_chars, int var,
2173 relax_substateT subtype, symbolS *symbol, offsetT offset)
2175 frag_grow (max_chars);
2176 move_insn (insn, frag_now, frag_more (0) - frag_now->fr_literal);
2178 frag_var (rs_machine_dependent, max_chars, var,
2179 subtype, symbol, offset, NULL);
2182 /* Insert N copies of INSN into the history buffer, starting at
2183 position FIRST. Neither FIRST nor N need to be clipped. */
2186 insert_into_history (unsigned int first, unsigned int n,
2187 const struct mips_cl_insn *insn)
2189 if (mips_relax.sequence != 2)
2193 for (i = ARRAY_SIZE (history); i-- > first;)
2195 history[i] = history[i - n];
2201 /* Initialize vr4120_conflicts. There is a bit of duplication here:
2202 the idea is to make it obvious at a glance that each errata is
2206 init_vr4120_conflicts (void)
2208 #define CONFLICT(FIRST, SECOND) \
2209 vr4120_conflicts[FIX_VR4120_##FIRST] |= 1 << FIX_VR4120_##SECOND
2211 /* Errata 21 - [D]DIV[U] after [D]MACC */
2212 CONFLICT (MACC, DIV);
2213 CONFLICT (DMACC, DIV);
2215 /* Errata 23 - Continuous DMULT[U]/DMACC instructions. */
2216 CONFLICT (DMULT, DMULT);
2217 CONFLICT (DMULT, DMACC);
2218 CONFLICT (DMACC, DMULT);
2219 CONFLICT (DMACC, DMACC);
2221 /* Errata 24 - MT{LO,HI} after [D]MACC */
2222 CONFLICT (MACC, MTHILO);
2223 CONFLICT (DMACC, MTHILO);
2225 /* VR4181A errata MD(1): "If a MULT, MULTU, DMULT or DMULTU
2226 instruction is executed immediately after a MACC or DMACC
2227 instruction, the result of [either instruction] is incorrect." */
2228 CONFLICT (MACC, MULT);
2229 CONFLICT (MACC, DMULT);
2230 CONFLICT (DMACC, MULT);
2231 CONFLICT (DMACC, DMULT);
2233 /* VR4181A errata MD(4): "If a MACC or DMACC instruction is
2234 executed immediately after a DMULT, DMULTU, DIV, DIVU,
2235 DDIV or DDIVU instruction, the result of the MACC or
2236 DMACC instruction is incorrect.". */
2237 CONFLICT (DMULT, MACC);
2238 CONFLICT (DMULT, DMACC);
2239 CONFLICT (DIV, MACC);
2240 CONFLICT (DIV, DMACC);
2250 #define RTYPE_MASK 0x1ff00
2251 #define RTYPE_NUM 0x00100
2252 #define RTYPE_FPU 0x00200
2253 #define RTYPE_FCC 0x00400
2254 #define RTYPE_VEC 0x00800
2255 #define RTYPE_GP 0x01000
2256 #define RTYPE_CP0 0x02000
2257 #define RTYPE_PC 0x04000
2258 #define RTYPE_ACC 0x08000
2259 #define RTYPE_CCC 0x10000
2260 #define RNUM_MASK 0x000ff
2261 #define RWARN 0x80000
2263 #define GENERIC_REGISTER_NUMBERS \
2264 {"$0", RTYPE_NUM | 0}, \
2265 {"$1", RTYPE_NUM | 1}, \
2266 {"$2", RTYPE_NUM | 2}, \
2267 {"$3", RTYPE_NUM | 3}, \
2268 {"$4", RTYPE_NUM | 4}, \
2269 {"$5", RTYPE_NUM | 5}, \
2270 {"$6", RTYPE_NUM | 6}, \
2271 {"$7", RTYPE_NUM | 7}, \
2272 {"$8", RTYPE_NUM | 8}, \
2273 {"$9", RTYPE_NUM | 9}, \
2274 {"$10", RTYPE_NUM | 10}, \
2275 {"$11", RTYPE_NUM | 11}, \
2276 {"$12", RTYPE_NUM | 12}, \
2277 {"$13", RTYPE_NUM | 13}, \
2278 {"$14", RTYPE_NUM | 14}, \
2279 {"$15", RTYPE_NUM | 15}, \
2280 {"$16", RTYPE_NUM | 16}, \
2281 {"$17", RTYPE_NUM | 17}, \
2282 {"$18", RTYPE_NUM | 18}, \
2283 {"$19", RTYPE_NUM | 19}, \
2284 {"$20", RTYPE_NUM | 20}, \
2285 {"$21", RTYPE_NUM | 21}, \
2286 {"$22", RTYPE_NUM | 22}, \
2287 {"$23", RTYPE_NUM | 23}, \
2288 {"$24", RTYPE_NUM | 24}, \
2289 {"$25", RTYPE_NUM | 25}, \
2290 {"$26", RTYPE_NUM | 26}, \
2291 {"$27", RTYPE_NUM | 27}, \
2292 {"$28", RTYPE_NUM | 28}, \
2293 {"$29", RTYPE_NUM | 29}, \
2294 {"$30", RTYPE_NUM | 30}, \
2295 {"$31", RTYPE_NUM | 31}
2297 #define FPU_REGISTER_NAMES \
2298 {"$f0", RTYPE_FPU | 0}, \
2299 {"$f1", RTYPE_FPU | 1}, \
2300 {"$f2", RTYPE_FPU | 2}, \
2301 {"$f3", RTYPE_FPU | 3}, \
2302 {"$f4", RTYPE_FPU | 4}, \
2303 {"$f5", RTYPE_FPU | 5}, \
2304 {"$f6", RTYPE_FPU | 6}, \
2305 {"$f7", RTYPE_FPU | 7}, \
2306 {"$f8", RTYPE_FPU | 8}, \
2307 {"$f9", RTYPE_FPU | 9}, \
2308 {"$f10", RTYPE_FPU | 10}, \
2309 {"$f11", RTYPE_FPU | 11}, \
2310 {"$f12", RTYPE_FPU | 12}, \
2311 {"$f13", RTYPE_FPU | 13}, \
2312 {"$f14", RTYPE_FPU | 14}, \
2313 {"$f15", RTYPE_FPU | 15}, \
2314 {"$f16", RTYPE_FPU | 16}, \
2315 {"$f17", RTYPE_FPU | 17}, \
2316 {"$f18", RTYPE_FPU | 18}, \
2317 {"$f19", RTYPE_FPU | 19}, \
2318 {"$f20", RTYPE_FPU | 20}, \
2319 {"$f21", RTYPE_FPU | 21}, \
2320 {"$f22", RTYPE_FPU | 22}, \
2321 {"$f23", RTYPE_FPU | 23}, \
2322 {"$f24", RTYPE_FPU | 24}, \
2323 {"$f25", RTYPE_FPU | 25}, \
2324 {"$f26", RTYPE_FPU | 26}, \
2325 {"$f27", RTYPE_FPU | 27}, \
2326 {"$f28", RTYPE_FPU | 28}, \
2327 {"$f29", RTYPE_FPU | 29}, \
2328 {"$f30", RTYPE_FPU | 30}, \
2329 {"$f31", RTYPE_FPU | 31}
2331 #define FPU_CONDITION_CODE_NAMES \
2332 {"$fcc0", RTYPE_FCC | 0}, \
2333 {"$fcc1", RTYPE_FCC | 1}, \
2334 {"$fcc2", RTYPE_FCC | 2}, \
2335 {"$fcc3", RTYPE_FCC | 3}, \
2336 {"$fcc4", RTYPE_FCC | 4}, \
2337 {"$fcc5", RTYPE_FCC | 5}, \
2338 {"$fcc6", RTYPE_FCC | 6}, \
2339 {"$fcc7", RTYPE_FCC | 7}
2341 #define COPROC_CONDITION_CODE_NAMES \
2342 {"$cc0", RTYPE_FCC | RTYPE_CCC | 0}, \
2343 {"$cc1", RTYPE_FCC | RTYPE_CCC | 1}, \
2344 {"$cc2", RTYPE_FCC | RTYPE_CCC | 2}, \
2345 {"$cc3", RTYPE_FCC | RTYPE_CCC | 3}, \
2346 {"$cc4", RTYPE_FCC | RTYPE_CCC | 4}, \
2347 {"$cc5", RTYPE_FCC | RTYPE_CCC | 5}, \
2348 {"$cc6", RTYPE_FCC | RTYPE_CCC | 6}, \
2349 {"$cc7", RTYPE_FCC | RTYPE_CCC | 7}
2351 #define N32N64_SYMBOLIC_REGISTER_NAMES \
2352 {"$a4", RTYPE_GP | 8}, \
2353 {"$a5", RTYPE_GP | 9}, \
2354 {"$a6", RTYPE_GP | 10}, \
2355 {"$a7", RTYPE_GP | 11}, \
2356 {"$ta0", RTYPE_GP | 8}, /* alias for $a4 */ \
2357 {"$ta1", RTYPE_GP | 9}, /* alias for $a5 */ \
2358 {"$ta2", RTYPE_GP | 10}, /* alias for $a6 */ \
2359 {"$ta3", RTYPE_GP | 11}, /* alias for $a7 */ \
2360 {"$t0", RTYPE_GP | 12}, \
2361 {"$t1", RTYPE_GP | 13}, \
2362 {"$t2", RTYPE_GP | 14}, \
2363 {"$t3", RTYPE_GP | 15}
2365 #define O32_SYMBOLIC_REGISTER_NAMES \
2366 {"$t0", RTYPE_GP | 8}, \
2367 {"$t1", RTYPE_GP | 9}, \
2368 {"$t2", RTYPE_GP | 10}, \
2369 {"$t3", RTYPE_GP | 11}, \
2370 {"$t4", RTYPE_GP | 12}, \
2371 {"$t5", RTYPE_GP | 13}, \
2372 {"$t6", RTYPE_GP | 14}, \
2373 {"$t7", RTYPE_GP | 15}, \
2374 {"$ta0", RTYPE_GP | 12}, /* alias for $t4 */ \
2375 {"$ta1", RTYPE_GP | 13}, /* alias for $t5 */ \
2376 {"$ta2", RTYPE_GP | 14}, /* alias for $t6 */ \
2377 {"$ta3", RTYPE_GP | 15} /* alias for $t7 */
2379 /* Remaining symbolic register names */
2380 #define SYMBOLIC_REGISTER_NAMES \
2381 {"$zero", RTYPE_GP | 0}, \
2382 {"$at", RTYPE_GP | 1}, \
2383 {"$AT", RTYPE_GP | 1}, \
2384 {"$v0", RTYPE_GP | 2}, \
2385 {"$v1", RTYPE_GP | 3}, \
2386 {"$a0", RTYPE_GP | 4}, \
2387 {"$a1", RTYPE_GP | 5}, \
2388 {"$a2", RTYPE_GP | 6}, \
2389 {"$a3", RTYPE_GP | 7}, \
2390 {"$s0", RTYPE_GP | 16}, \
2391 {"$s1", RTYPE_GP | 17}, \
2392 {"$s2", RTYPE_GP | 18}, \
2393 {"$s3", RTYPE_GP | 19}, \
2394 {"$s4", RTYPE_GP | 20}, \
2395 {"$s5", RTYPE_GP | 21}, \
2396 {"$s6", RTYPE_GP | 22}, \
2397 {"$s7", RTYPE_GP | 23}, \
2398 {"$t8", RTYPE_GP | 24}, \
2399 {"$t9", RTYPE_GP | 25}, \
2400 {"$k0", RTYPE_GP | 26}, \
2401 {"$kt0", RTYPE_GP | 26}, \
2402 {"$k1", RTYPE_GP | 27}, \
2403 {"$kt1", RTYPE_GP | 27}, \
2404 {"$gp", RTYPE_GP | 28}, \
2405 {"$sp", RTYPE_GP | 29}, \
2406 {"$s8", RTYPE_GP | 30}, \
2407 {"$fp", RTYPE_GP | 30}, \
2408 {"$ra", RTYPE_GP | 31}
2410 #define MIPS16_SPECIAL_REGISTER_NAMES \
2411 {"$pc", RTYPE_PC | 0}
2413 #define MDMX_VECTOR_REGISTER_NAMES \
2414 /* {"$v0", RTYPE_VEC | 0}, clash with REG 2 above */ \
2415 /* {"$v1", RTYPE_VEC | 1}, clash with REG 3 above */ \
2416 {"$v2", RTYPE_VEC | 2}, \
2417 {"$v3", RTYPE_VEC | 3}, \
2418 {"$v4", RTYPE_VEC | 4}, \
2419 {"$v5", RTYPE_VEC | 5}, \
2420 {"$v6", RTYPE_VEC | 6}, \
2421 {"$v7", RTYPE_VEC | 7}, \
2422 {"$v8", RTYPE_VEC | 8}, \
2423 {"$v9", RTYPE_VEC | 9}, \
2424 {"$v10", RTYPE_VEC | 10}, \
2425 {"$v11", RTYPE_VEC | 11}, \
2426 {"$v12", RTYPE_VEC | 12}, \
2427 {"$v13", RTYPE_VEC | 13}, \
2428 {"$v14", RTYPE_VEC | 14}, \
2429 {"$v15", RTYPE_VEC | 15}, \
2430 {"$v16", RTYPE_VEC | 16}, \
2431 {"$v17", RTYPE_VEC | 17}, \
2432 {"$v18", RTYPE_VEC | 18}, \
2433 {"$v19", RTYPE_VEC | 19}, \
2434 {"$v20", RTYPE_VEC | 20}, \
2435 {"$v21", RTYPE_VEC | 21}, \
2436 {"$v22", RTYPE_VEC | 22}, \
2437 {"$v23", RTYPE_VEC | 23}, \
2438 {"$v24", RTYPE_VEC | 24}, \
2439 {"$v25", RTYPE_VEC | 25}, \
2440 {"$v26", RTYPE_VEC | 26}, \
2441 {"$v27", RTYPE_VEC | 27}, \
2442 {"$v28", RTYPE_VEC | 28}, \
2443 {"$v29", RTYPE_VEC | 29}, \
2444 {"$v30", RTYPE_VEC | 30}, \
2445 {"$v31", RTYPE_VEC | 31}
2447 #define MIPS_DSP_ACCUMULATOR_NAMES \
2448 {"$ac0", RTYPE_ACC | 0}, \
2449 {"$ac1", RTYPE_ACC | 1}, \
2450 {"$ac2", RTYPE_ACC | 2}, \
2451 {"$ac3", RTYPE_ACC | 3}
2453 static const struct regname reg_names[] = {
2454 GENERIC_REGISTER_NUMBERS,
2456 FPU_CONDITION_CODE_NAMES,
2457 COPROC_CONDITION_CODE_NAMES,
2459 /* The $txx registers depends on the abi,
2460 these will be added later into the symbol table from
2461 one of the tables below once mips_abi is set after
2462 parsing of arguments from the command line. */
2463 SYMBOLIC_REGISTER_NAMES,
2465 MIPS16_SPECIAL_REGISTER_NAMES,
2466 MDMX_VECTOR_REGISTER_NAMES,
2467 MIPS_DSP_ACCUMULATOR_NAMES,
2471 static const struct regname reg_names_o32[] = {
2472 O32_SYMBOLIC_REGISTER_NAMES,
2476 static const struct regname reg_names_n32n64[] = {
2477 N32N64_SYMBOLIC_REGISTER_NAMES,
2481 /* Check if S points at a valid register specifier according to TYPES.
2482 If so, then return 1, advance S to consume the specifier and store
2483 the register's number in REGNOP, otherwise return 0. */
2486 reg_lookup (char **s, unsigned int types, unsigned int *regnop)
2493 /* Find end of name. */
2495 if (is_name_beginner (*e))
2497 while (is_part_of_name (*e))
2500 /* Terminate name. */
2504 /* Look for a register symbol. */
2505 if ((symbolP = symbol_find (*s)) && S_GET_SEGMENT (symbolP) == reg_section)
2507 int r = S_GET_VALUE (symbolP);
2509 reg = r & RNUM_MASK;
2510 else if ((types & RTYPE_VEC) && (r & ~1) == (RTYPE_GP | 2))
2511 /* Convert GP reg $v0/1 to MDMX reg $v0/1! */
2512 reg = (r & RNUM_MASK) - 2;
2514 /* Else see if this is a register defined in an itbl entry. */
2515 else if ((types & RTYPE_GP) && itbl_have_entries)
2522 if (itbl_get_reg_val (n, &r))
2523 reg = r & RNUM_MASK;
2526 /* Advance to next token if a register was recognised. */
2529 else if (types & RWARN)
2530 as_warn (_("Unrecognized register name `%s'"), *s);
2538 /* Check if S points at a valid register list according to TYPES.
2539 If so, then return 1, advance S to consume the list and store
2540 the registers present on the list as a bitmask of ones in REGLISTP,
2541 otherwise return 0. A valid list comprises a comma-separated
2542 enumeration of valid single registers and/or dash-separated
2543 contiguous register ranges as determined by their numbers.
2545 As a special exception if one of s0-s7 registers is specified as
2546 the range's lower delimiter and s8 (fp) is its upper one, then no
2547 registers whose numbers place them between s7 and s8 (i.e. $24-$29)
2548 are selected; they have to be listed separately if needed. */
2551 reglist_lookup (char **s, unsigned int types, unsigned int *reglistp)
2553 unsigned int reglist = 0;
2554 unsigned int lastregno;
2555 bfd_boolean ok = TRUE;
2556 unsigned int regmask;
2557 char *s_endlist = *s;
2561 while (reg_lookup (s, types, ®no))
2567 ok = reg_lookup (s, types, &lastregno);
2568 if (ok && lastregno < regno)
2574 if (lastregno == FP && regno >= S0 && regno <= S7)
2579 regmask = 1 << lastregno;
2580 regmask = (regmask << 1) - 1;
2581 regmask ^= (1 << regno) - 1;
2595 *reglistp = reglist;
2596 return ok && reglist != 0;
2599 /* Return TRUE if opcode MO is valid on the currently selected ISA, ASE
2600 and architecture. Use is_opcode_valid_16 for MIPS16 opcodes. */
2603 is_opcode_valid (const struct mips_opcode *mo)
2605 int isa = mips_opts.isa;
2606 int ase = mips_opts.ase;
2610 if (ISA_HAS_64BIT_REGS (mips_opts.isa))
2611 for (i = 0; i < ARRAY_SIZE (mips_ases); i++)
2612 if ((ase & mips_ases[i].flags) == mips_ases[i].flags)
2613 ase |= mips_ases[i].flags64;
2615 if (!opcode_is_member (mo, isa, ase, mips_opts.arch))
2618 /* Check whether the instruction or macro requires single-precision or
2619 double-precision floating-point support. Note that this information is
2620 stored differently in the opcode table for insns and macros. */
2621 if (mo->pinfo == INSN_MACRO)
2623 fp_s = mo->pinfo2 & INSN2_M_FP_S;
2624 fp_d = mo->pinfo2 & INSN2_M_FP_D;
2628 fp_s = mo->pinfo & FP_S;
2629 fp_d = mo->pinfo & FP_D;
2632 if (fp_d && (mips_opts.soft_float || mips_opts.single_float))
2635 if (fp_s && mips_opts.soft_float)
2641 /* Return TRUE if the MIPS16 opcode MO is valid on the currently
2642 selected ISA and architecture. */
2645 is_opcode_valid_16 (const struct mips_opcode *mo)
2647 return opcode_is_member (mo, mips_opts.isa, 0, mips_opts.arch);
2650 /* Return TRUE if the size of the microMIPS opcode MO matches one
2651 explicitly requested. Always TRUE in the standard MIPS mode. */
2654 is_size_valid (const struct mips_opcode *mo)
2656 if (!mips_opts.micromips)
2659 if (!forced_insn_length)
2661 if (mo->pinfo == INSN_MACRO)
2663 return forced_insn_length == micromips_insn_length (mo);
2666 /* Return TRUE if the microMIPS opcode MO is valid for the delay slot
2667 of the preceding instruction. Always TRUE in the standard MIPS mode.
2669 We don't accept macros in 16-bit delay slots to avoid a case where
2670 a macro expansion fails because it relies on a preceding 32-bit real
2671 instruction to have matched and does not handle the operands correctly.
2672 The only macros that may expand to 16-bit instructions are JAL that
2673 cannot be placed in a delay slot anyway, and corner cases of BALIGN
2674 and BGT (that likewise cannot be placed in a delay slot) that decay to
2675 a NOP. In all these cases the macros precede any corresponding real
2676 instruction definitions in the opcode table, so they will match in the
2677 second pass where the size of the delay slot is ignored and therefore
2678 produce correct code. */
2681 is_delay_slot_valid (const struct mips_opcode *mo)
2683 if (!mips_opts.micromips)
2686 if (mo->pinfo == INSN_MACRO)
2687 return (history[0].insn_mo->pinfo2 & INSN2_BRANCH_DELAY_16BIT) == 0;
2688 if ((history[0].insn_mo->pinfo2 & INSN2_BRANCH_DELAY_32BIT) != 0
2689 && micromips_insn_length (mo) != 4)
2691 if ((history[0].insn_mo->pinfo2 & INSN2_BRANCH_DELAY_16BIT) != 0
2692 && micromips_insn_length (mo) != 2)
2698 /* This function is called once, at assembler startup time. It should set up
2699 all the tables, etc. that the MD part of the assembler will need. */
2704 const char *retval = NULL;
2708 if (mips_pic != NO_PIC)
2710 if (g_switch_seen && g_switch_value != 0)
2711 as_bad (_("-G may not be used in position-independent code"));
2715 if (! bfd_set_arch_mach (stdoutput, bfd_arch_mips, file_mips_arch))
2716 as_warn (_("Could not set architecture and machine"));
2718 op_hash = hash_new ();
2720 for (i = 0; i < NUMOPCODES;)
2722 const char *name = mips_opcodes[i].name;
2724 retval = hash_insert (op_hash, name, (void *) &mips_opcodes[i]);
2727 fprintf (stderr, _("internal error: can't hash `%s': %s\n"),
2728 mips_opcodes[i].name, retval);
2729 /* Probably a memory allocation problem? Give up now. */
2730 as_fatal (_("Broken assembler. No assembly attempted."));
2734 if (mips_opcodes[i].pinfo != INSN_MACRO)
2736 if (!validate_mips_insn (&mips_opcodes[i]))
2738 if (nop_insn.insn_mo == NULL && strcmp (name, "nop") == 0)
2740 create_insn (&nop_insn, mips_opcodes + i);
2741 if (mips_fix_loongson2f_nop)
2742 nop_insn.insn_opcode = LOONGSON2F_NOP_INSN;
2743 nop_insn.fixed_p = 1;
2748 while ((i < NUMOPCODES) && !strcmp (mips_opcodes[i].name, name));
2751 mips16_op_hash = hash_new ();
2754 while (i < bfd_mips16_num_opcodes)
2756 const char *name = mips16_opcodes[i].name;
2758 retval = hash_insert (mips16_op_hash, name, (void *) &mips16_opcodes[i]);
2760 as_fatal (_("internal: can't hash `%s': %s"),
2761 mips16_opcodes[i].name, retval);
2764 if (mips16_opcodes[i].pinfo != INSN_MACRO
2765 && ((mips16_opcodes[i].match & mips16_opcodes[i].mask)
2766 != mips16_opcodes[i].match))
2768 fprintf (stderr, _("internal error: bad mips16 opcode: %s %s\n"),
2769 mips16_opcodes[i].name, mips16_opcodes[i].args);
2772 if (mips16_nop_insn.insn_mo == NULL && strcmp (name, "nop") == 0)
2774 create_insn (&mips16_nop_insn, mips16_opcodes + i);
2775 mips16_nop_insn.fixed_p = 1;
2779 while (i < bfd_mips16_num_opcodes
2780 && strcmp (mips16_opcodes[i].name, name) == 0);
2783 micromips_op_hash = hash_new ();
2786 while (i < bfd_micromips_num_opcodes)
2788 const char *name = micromips_opcodes[i].name;
2790 retval = hash_insert (micromips_op_hash, name,
2791 (void *) µmips_opcodes[i]);
2793 as_fatal (_("internal: can't hash `%s': %s"),
2794 micromips_opcodes[i].name, retval);
2796 if (micromips_opcodes[i].pinfo != INSN_MACRO)
2798 struct mips_cl_insn *micromips_nop_insn;
2800 if (!validate_micromips_insn (µmips_opcodes[i]))
2803 if (micromips_insn_length (micromips_opcodes + i) == 2)
2804 micromips_nop_insn = µmips_nop16_insn;
2805 else if (micromips_insn_length (micromips_opcodes + i) == 4)
2806 micromips_nop_insn = µmips_nop32_insn;
2810 if (micromips_nop_insn->insn_mo == NULL
2811 && strcmp (name, "nop") == 0)
2813 create_insn (micromips_nop_insn, micromips_opcodes + i);
2814 micromips_nop_insn->fixed_p = 1;
2817 while (++i < bfd_micromips_num_opcodes
2818 && strcmp (micromips_opcodes[i].name, name) == 0);
2822 as_fatal (_("Broken assembler. No assembly attempted."));
2824 /* We add all the general register names to the symbol table. This
2825 helps us detect invalid uses of them. */
2826 for (i = 0; reg_names[i].name; i++)
2827 symbol_table_insert (symbol_new (reg_names[i].name, reg_section,
2828 reg_names[i].num, /* & RNUM_MASK, */
2829 &zero_address_frag));
2831 for (i = 0; reg_names_n32n64[i].name; i++)
2832 symbol_table_insert (symbol_new (reg_names_n32n64[i].name, reg_section,
2833 reg_names_n32n64[i].num, /* & RNUM_MASK, */
2834 &zero_address_frag));
2836 for (i = 0; reg_names_o32[i].name; i++)
2837 symbol_table_insert (symbol_new (reg_names_o32[i].name, reg_section,
2838 reg_names_o32[i].num, /* & RNUM_MASK, */
2839 &zero_address_frag));
2841 mips_no_prev_insn ();
2844 mips_cprmask[0] = 0;
2845 mips_cprmask[1] = 0;
2846 mips_cprmask[2] = 0;
2847 mips_cprmask[3] = 0;
2849 /* set the default alignment for the text section (2**2) */
2850 record_alignment (text_section, 2);
2852 bfd_set_gp_size (stdoutput, g_switch_value);
2857 /* On a native system other than VxWorks, sections must be aligned
2858 to 16 byte boundaries. When configured for an embedded ELF
2859 target, we don't bother. */
2860 if (strncmp (TARGET_OS, "elf", 3) != 0
2861 && strncmp (TARGET_OS, "vxworks", 7) != 0)
2863 (void) bfd_set_section_alignment (stdoutput, text_section, 4);
2864 (void) bfd_set_section_alignment (stdoutput, data_section, 4);
2865 (void) bfd_set_section_alignment (stdoutput, bss_section, 4);
2868 /* Create a .reginfo section for register masks and a .mdebug
2869 section for debugging information. */
2877 subseg = now_subseg;
2879 /* The ABI says this section should be loaded so that the
2880 running program can access it. However, we don't load it
2881 if we are configured for an embedded target */
2882 flags = SEC_READONLY | SEC_DATA;
2883 if (strncmp (TARGET_OS, "elf", 3) != 0)
2884 flags |= SEC_ALLOC | SEC_LOAD;
2886 if (mips_abi != N64_ABI)
2888 sec = subseg_new (".reginfo", (subsegT) 0);
2890 bfd_set_section_flags (stdoutput, sec, flags);
2891 bfd_set_section_alignment (stdoutput, sec, HAVE_NEWABI ? 3 : 2);
2893 mips_regmask_frag = frag_more (sizeof (Elf32_External_RegInfo));
2897 /* The 64-bit ABI uses a .MIPS.options section rather than
2898 .reginfo section. */
2899 sec = subseg_new (".MIPS.options", (subsegT) 0);
2900 bfd_set_section_flags (stdoutput, sec, flags);
2901 bfd_set_section_alignment (stdoutput, sec, 3);
2903 /* Set up the option header. */
2905 Elf_Internal_Options opthdr;
2908 opthdr.kind = ODK_REGINFO;
2909 opthdr.size = (sizeof (Elf_External_Options)
2910 + sizeof (Elf64_External_RegInfo));
2913 f = frag_more (sizeof (Elf_External_Options));
2914 bfd_mips_elf_swap_options_out (stdoutput, &opthdr,
2915 (Elf_External_Options *) f);
2917 mips_regmask_frag = frag_more (sizeof (Elf64_External_RegInfo));
2921 if (ECOFF_DEBUGGING)
2923 sec = subseg_new (".mdebug", (subsegT) 0);
2924 (void) bfd_set_section_flags (stdoutput, sec,
2925 SEC_HAS_CONTENTS | SEC_READONLY);
2926 (void) bfd_set_section_alignment (stdoutput, sec, 2);
2928 else if (mips_flag_pdr)
2930 pdr_seg = subseg_new (".pdr", (subsegT) 0);
2931 (void) bfd_set_section_flags (stdoutput, pdr_seg,
2932 SEC_READONLY | SEC_RELOC
2934 (void) bfd_set_section_alignment (stdoutput, pdr_seg, 2);
2937 subseg_set (seg, subseg);
2940 #endif /* OBJ_ELF */
2942 if (! ECOFF_DEBUGGING)
2945 if (mips_fix_vr4120)
2946 init_vr4120_conflicts ();
2952 mips_emit_delays ();
2953 if (! ECOFF_DEBUGGING)
2958 md_assemble (char *str)
2960 struct mips_cl_insn insn;
2961 bfd_reloc_code_real_type unused_reloc[3]
2962 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
2964 imm_expr.X_op = O_absent;
2965 imm2_expr.X_op = O_absent;
2966 offset_expr.X_op = O_absent;
2967 imm_reloc[0] = BFD_RELOC_UNUSED;
2968 imm_reloc[1] = BFD_RELOC_UNUSED;
2969 imm_reloc[2] = BFD_RELOC_UNUSED;
2970 offset_reloc[0] = BFD_RELOC_UNUSED;
2971 offset_reloc[1] = BFD_RELOC_UNUSED;
2972 offset_reloc[2] = BFD_RELOC_UNUSED;
2974 mips_mark_labels ();
2975 mips_assembling_insn = TRUE;
2977 if (mips_opts.mips16)
2978 mips16_ip (str, &insn);
2981 mips_ip (str, &insn);
2982 DBG ((_("returned from mips_ip(%s) insn_opcode = 0x%x\n"),
2983 str, insn.insn_opcode));
2987 as_bad ("%s `%s'", insn_error, str);
2988 else if (insn.insn_mo->pinfo == INSN_MACRO)
2991 if (mips_opts.mips16)
2992 mips16_macro (&insn);
2999 if (imm_expr.X_op != O_absent)
3000 append_insn (&insn, &imm_expr, imm_reloc, FALSE);
3001 else if (offset_expr.X_op != O_absent)
3002 append_insn (&insn, &offset_expr, offset_reloc, FALSE);
3004 append_insn (&insn, NULL, unused_reloc, FALSE);
3007 mips_assembling_insn = FALSE;
3010 /* Convenience functions for abstracting away the differences between
3011 MIPS16 and non-MIPS16 relocations. */
3013 static inline bfd_boolean
3014 mips16_reloc_p (bfd_reloc_code_real_type reloc)
3018 case BFD_RELOC_MIPS16_JMP:
3019 case BFD_RELOC_MIPS16_GPREL:
3020 case BFD_RELOC_MIPS16_GOT16:
3021 case BFD_RELOC_MIPS16_CALL16:
3022 case BFD_RELOC_MIPS16_HI16_S:
3023 case BFD_RELOC_MIPS16_HI16:
3024 case BFD_RELOC_MIPS16_LO16:
3032 static inline bfd_boolean
3033 micromips_reloc_p (bfd_reloc_code_real_type reloc)
3037 case BFD_RELOC_MICROMIPS_7_PCREL_S1:
3038 case BFD_RELOC_MICROMIPS_10_PCREL_S1:
3039 case BFD_RELOC_MICROMIPS_16_PCREL_S1:
3040 case BFD_RELOC_MICROMIPS_GPREL16:
3041 case BFD_RELOC_MICROMIPS_JMP:
3042 case BFD_RELOC_MICROMIPS_HI16:
3043 case BFD_RELOC_MICROMIPS_HI16_S:
3044 case BFD_RELOC_MICROMIPS_LO16:
3045 case BFD_RELOC_MICROMIPS_LITERAL:
3046 case BFD_RELOC_MICROMIPS_GOT16:
3047 case BFD_RELOC_MICROMIPS_CALL16:
3048 case BFD_RELOC_MICROMIPS_GOT_HI16:
3049 case BFD_RELOC_MICROMIPS_GOT_LO16:
3050 case BFD_RELOC_MICROMIPS_CALL_HI16:
3051 case BFD_RELOC_MICROMIPS_CALL_LO16:
3052 case BFD_RELOC_MICROMIPS_SUB:
3053 case BFD_RELOC_MICROMIPS_GOT_PAGE:
3054 case BFD_RELOC_MICROMIPS_GOT_OFST:
3055 case BFD_RELOC_MICROMIPS_GOT_DISP:
3056 case BFD_RELOC_MICROMIPS_HIGHEST:
3057 case BFD_RELOC_MICROMIPS_HIGHER:
3058 case BFD_RELOC_MICROMIPS_SCN_DISP:
3059 case BFD_RELOC_MICROMIPS_JALR:
3067 static inline bfd_boolean
3068 jmp_reloc_p (bfd_reloc_code_real_type reloc)
3070 return reloc == BFD_RELOC_MIPS_JMP || reloc == BFD_RELOC_MICROMIPS_JMP;
3073 static inline bfd_boolean
3074 got16_reloc_p (bfd_reloc_code_real_type reloc)
3076 return (reloc == BFD_RELOC_MIPS_GOT16 || reloc == BFD_RELOC_MIPS16_GOT16
3077 || reloc == BFD_RELOC_MICROMIPS_GOT16);
3080 static inline bfd_boolean
3081 hi16_reloc_p (bfd_reloc_code_real_type reloc)
3083 return (reloc == BFD_RELOC_HI16_S || reloc == BFD_RELOC_MIPS16_HI16_S
3084 || reloc == BFD_RELOC_MICROMIPS_HI16_S);
3087 static inline bfd_boolean
3088 lo16_reloc_p (bfd_reloc_code_real_type reloc)
3090 return (reloc == BFD_RELOC_LO16 || reloc == BFD_RELOC_MIPS16_LO16
3091 || reloc == BFD_RELOC_MICROMIPS_LO16);
3094 static inline bfd_boolean
3095 jalr_reloc_p (bfd_reloc_code_real_type reloc)
3097 return reloc == BFD_RELOC_MIPS_JALR || reloc == BFD_RELOC_MICROMIPS_JALR;
3100 /* Return true if RELOC is a PC-relative relocation that does not have
3101 full address range. */
3103 static inline bfd_boolean
3104 limited_pcrel_reloc_p (bfd_reloc_code_real_type reloc)
3108 case BFD_RELOC_16_PCREL_S2:
3109 case BFD_RELOC_MICROMIPS_7_PCREL_S1:
3110 case BFD_RELOC_MICROMIPS_10_PCREL_S1:
3111 case BFD_RELOC_MICROMIPS_16_PCREL_S1:
3114 case BFD_RELOC_32_PCREL:
3115 return HAVE_64BIT_ADDRESSES;
3122 /* Return true if the given relocation might need a matching %lo().
3123 This is only "might" because SVR4 R_MIPS_GOT16 relocations only
3124 need a matching %lo() when applied to local symbols. */
3126 static inline bfd_boolean
3127 reloc_needs_lo_p (bfd_reloc_code_real_type reloc)
3129 return (HAVE_IN_PLACE_ADDENDS
3130 && (hi16_reloc_p (reloc)
3131 /* VxWorks R_MIPS_GOT16 relocs never need a matching %lo();
3132 all GOT16 relocations evaluate to "G". */
3133 || (got16_reloc_p (reloc) && mips_pic != VXWORKS_PIC)));
3136 /* Return the type of %lo() reloc needed by RELOC, given that
3137 reloc_needs_lo_p. */
3139 static inline bfd_reloc_code_real_type
3140 matching_lo_reloc (bfd_reloc_code_real_type reloc)
3142 return (mips16_reloc_p (reloc) ? BFD_RELOC_MIPS16_LO16
3143 : (micromips_reloc_p (reloc) ? BFD_RELOC_MICROMIPS_LO16
3147 /* Return true if the given fixup is followed by a matching R_MIPS_LO16
3150 static inline bfd_boolean
3151 fixup_has_matching_lo_p (fixS *fixp)
3153 return (fixp->fx_next != NULL
3154 && fixp->fx_next->fx_r_type == matching_lo_reloc (fixp->fx_r_type)
3155 && fixp->fx_addsy == fixp->fx_next->fx_addsy
3156 && fixp->fx_offset == fixp->fx_next->fx_offset);
3159 /* This function returns true if modifying a register requires a
3163 reg_needs_delay (unsigned int reg)
3165 unsigned long prev_pinfo;
3167 prev_pinfo = history[0].insn_mo->pinfo;
3168 if (! mips_opts.noreorder
3169 && (((prev_pinfo & INSN_LOAD_MEMORY_DELAY)
3170 && ! gpr_interlocks)
3171 || ((prev_pinfo & INSN_LOAD_COPROC_DELAY)
3172 && ! cop_interlocks)))
3174 /* A load from a coprocessor or from memory. All load delays
3175 delay the use of general register rt for one instruction. */
3176 /* Itbl support may require additional care here. */
3177 know (prev_pinfo & INSN_WRITE_GPR_T);
3178 if (reg == EXTRACT_OPERAND (mips_opts.micromips, RT, history[0]))
3185 /* Move all labels in LABELS to the current insertion point. TEXT_P
3186 says whether the labels refer to text or data. */
3189 mips_move_labels (struct insn_label_list *labels, bfd_boolean text_p)
3191 struct insn_label_list *l;
3194 for (l = labels; l != NULL; l = l->next)
3196 gas_assert (S_GET_SEGMENT (l->label) == now_seg);
3197 symbol_set_frag (l->label, frag_now);
3198 val = (valueT) frag_now_fix ();
3199 /* MIPS16/microMIPS text labels are stored as odd. */
3200 if (text_p && HAVE_CODE_COMPRESSION)
3202 S_SET_VALUE (l->label, val);
3206 /* Move all labels in insn_labels to the current insertion point
3207 and treat them as text labels. */
3210 mips_move_text_labels (void)
3212 mips_move_labels (seg_info (now_seg)->label_list, TRUE);
3216 s_is_linkonce (symbolS *sym, segT from_seg)
3218 bfd_boolean linkonce = FALSE;
3219 segT symseg = S_GET_SEGMENT (sym);
3221 if (symseg != from_seg && !S_IS_LOCAL (sym))
3223 if ((bfd_get_section_flags (stdoutput, symseg) & SEC_LINK_ONCE))
3226 /* The GNU toolchain uses an extension for ELF: a section
3227 beginning with the magic string .gnu.linkonce is a
3228 linkonce section. */
3229 if (strncmp (segment_name (symseg), ".gnu.linkonce",
3230 sizeof ".gnu.linkonce" - 1) == 0)
3237 /* Mark MIPS16 or microMIPS instruction label LABEL. This permits the
3238 linker to handle them specially, such as generating jalx instructions
3239 when needed. We also make them odd for the duration of the assembly,
3240 in order to generate the right sort of code. We will make them even
3241 in the adjust_symtab routine, while leaving them marked. This is
3242 convenient for the debugger and the disassembler. The linker knows
3243 to make them odd again. */
3246 mips_compressed_mark_label (symbolS *label)
3248 gas_assert (HAVE_CODE_COMPRESSION);
3250 #if defined(OBJ_ELF) || defined(OBJ_MAYBE_ELF)
3253 if (mips_opts.mips16)
3254 S_SET_OTHER (label, ELF_ST_SET_MIPS16 (S_GET_OTHER (label)));
3256 S_SET_OTHER (label, ELF_ST_SET_MICROMIPS (S_GET_OTHER (label)));
3259 if ((S_GET_VALUE (label) & 1) == 0
3260 /* Don't adjust the address if the label is global or weak, or
3261 in a link-once section, since we'll be emitting symbol reloc
3262 references to it which will be patched up by the linker, and
3263 the final value of the symbol may or may not be MIPS16/microMIPS. */
3264 && !S_IS_WEAK (label)
3265 && !S_IS_EXTERNAL (label)
3266 && !s_is_linkonce (label, now_seg))
3267 S_SET_VALUE (label, S_GET_VALUE (label) | 1);
3270 /* Mark preceding MIPS16 or microMIPS instruction labels. */
3273 mips_compressed_mark_labels (void)
3275 struct insn_label_list *l;
3277 for (l = seg_info (now_seg)->label_list; l != NULL; l = l->next)
3278 mips_compressed_mark_label (l->label);
3281 /* End the current frag. Make it a variant frag and record the
3285 relax_close_frag (void)
3287 mips_macro_warning.first_frag = frag_now;
3288 frag_var (rs_machine_dependent, 0, 0,
3289 RELAX_ENCODE (mips_relax.sizes[0], mips_relax.sizes[1]),
3290 mips_relax.symbol, 0, (char *) mips_relax.first_fixup);
3292 memset (&mips_relax.sizes, 0, sizeof (mips_relax.sizes));
3293 mips_relax.first_fixup = 0;
3296 /* Start a new relaxation sequence whose expansion depends on SYMBOL.
3297 See the comment above RELAX_ENCODE for more details. */
3300 relax_start (symbolS *symbol)
3302 gas_assert (mips_relax.sequence == 0);
3303 mips_relax.sequence = 1;
3304 mips_relax.symbol = symbol;
3307 /* Start generating the second version of a relaxable sequence.
3308 See the comment above RELAX_ENCODE for more details. */
3313 gas_assert (mips_relax.sequence == 1);
3314 mips_relax.sequence = 2;
3317 /* End the current relaxable sequence. */
3322 gas_assert (mips_relax.sequence == 2);
3323 relax_close_frag ();
3324 mips_relax.sequence = 0;
3327 /* Return true if IP is a delayed branch or jump. */
3329 static inline bfd_boolean
3330 delayed_branch_p (const struct mips_cl_insn *ip)
3332 return (ip->insn_mo->pinfo & (INSN_UNCOND_BRANCH_DELAY
3333 | INSN_COND_BRANCH_DELAY
3334 | INSN_COND_BRANCH_LIKELY)) != 0;
3337 /* Return true if IP is a compact branch or jump. */
3339 static inline bfd_boolean
3340 compact_branch_p (const struct mips_cl_insn *ip)
3342 if (mips_opts.mips16)
3343 return (ip->insn_mo->pinfo & (MIPS16_INSN_UNCOND_BRANCH
3344 | MIPS16_INSN_COND_BRANCH)) != 0;
3346 return (ip->insn_mo->pinfo2 & (INSN2_UNCOND_BRANCH
3347 | INSN2_COND_BRANCH)) != 0;
3350 /* Return true if IP is an unconditional branch or jump. */
3352 static inline bfd_boolean
3353 uncond_branch_p (const struct mips_cl_insn *ip)
3355 return ((ip->insn_mo->pinfo & INSN_UNCOND_BRANCH_DELAY) != 0
3356 || (mips_opts.mips16
3357 ? (ip->insn_mo->pinfo & MIPS16_INSN_UNCOND_BRANCH) != 0
3358 : (ip->insn_mo->pinfo2 & INSN2_UNCOND_BRANCH) != 0));
3361 /* Return true if IP is a branch-likely instruction. */
3363 static inline bfd_boolean
3364 branch_likely_p (const struct mips_cl_insn *ip)
3366 return (ip->insn_mo->pinfo & INSN_COND_BRANCH_LIKELY) != 0;
3369 /* Return the type of nop that should be used to fill the delay slot
3370 of delayed branch IP. */
3372 static struct mips_cl_insn *
3373 get_delay_slot_nop (const struct mips_cl_insn *ip)
3375 if (mips_opts.micromips
3376 && (ip->insn_mo->pinfo2 & INSN2_BRANCH_DELAY_32BIT))
3377 return µmips_nop32_insn;
3381 /* Return the mask of core registers that IP reads or writes. */
3384 gpr_mod_mask (const struct mips_cl_insn *ip)
3386 unsigned long pinfo2;
3390 pinfo2 = ip->insn_mo->pinfo2;
3391 if (mips_opts.micromips)
3393 if (pinfo2 & INSN2_MOD_GPR_MD)
3394 mask |= 1 << micromips_to_32_reg_d_map[EXTRACT_OPERAND (1, MD, *ip)];
3395 if (pinfo2 & INSN2_MOD_GPR_MF)
3396 mask |= 1 << micromips_to_32_reg_f_map[EXTRACT_OPERAND (1, MF, *ip)];
3397 if (pinfo2 & INSN2_MOD_SP)
3403 /* Return the mask of core registers that IP reads. */
3406 gpr_read_mask (const struct mips_cl_insn *ip)
3408 unsigned long pinfo, pinfo2;
3411 mask = gpr_mod_mask (ip);
3412 pinfo = ip->insn_mo->pinfo;
3413 pinfo2 = ip->insn_mo->pinfo2;
3414 if (mips_opts.mips16)
3416 if (pinfo & MIPS16_INSN_READ_X)
3417 mask |= 1 << mips16_to_32_reg_map[MIPS16_EXTRACT_OPERAND (RX, *ip)];
3418 if (pinfo & MIPS16_INSN_READ_Y)
3419 mask |= 1 << mips16_to_32_reg_map[MIPS16_EXTRACT_OPERAND (RY, *ip)];
3420 if (pinfo & MIPS16_INSN_READ_T)
3422 if (pinfo & MIPS16_INSN_READ_SP)
3424 if (pinfo & MIPS16_INSN_READ_31)
3426 if (pinfo & MIPS16_INSN_READ_Z)
3427 mask |= 1 << (mips16_to_32_reg_map
3428 [MIPS16_EXTRACT_OPERAND (MOVE32Z, *ip)]);
3429 if (pinfo & MIPS16_INSN_READ_GPR_X)
3430 mask |= 1 << MIPS16_EXTRACT_OPERAND (REGR32, *ip);
3434 if (pinfo2 & INSN2_READ_GPR_D)
3435 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RD, *ip);
3436 if (pinfo & INSN_READ_GPR_T)
3437 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RT, *ip);
3438 if (pinfo & INSN_READ_GPR_S)
3439 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RS, *ip);
3440 if (pinfo2 & INSN2_READ_GP)
3442 if (pinfo2 & INSN2_READ_GPR_31)
3444 if (pinfo2 & INSN2_READ_GPR_Z)
3445 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RZ, *ip);
3447 if (mips_opts.micromips)
3449 if (pinfo2 & INSN2_READ_GPR_MC)
3450 mask |= 1 << micromips_to_32_reg_c_map[EXTRACT_OPERAND (1, MC, *ip)];
3451 if (pinfo2 & INSN2_READ_GPR_ME)
3452 mask |= 1 << micromips_to_32_reg_e_map[EXTRACT_OPERAND (1, ME, *ip)];
3453 if (pinfo2 & INSN2_READ_GPR_MG)
3454 mask |= 1 << micromips_to_32_reg_g_map[EXTRACT_OPERAND (1, MG, *ip)];
3455 if (pinfo2 & INSN2_READ_GPR_MJ)
3456 mask |= 1 << EXTRACT_OPERAND (1, MJ, *ip);
3457 if (pinfo2 & INSN2_READ_GPR_MMN)
3459 mask |= 1 << micromips_to_32_reg_m_map[EXTRACT_OPERAND (1, MM, *ip)];
3460 mask |= 1 << micromips_to_32_reg_n_map[EXTRACT_OPERAND (1, MN, *ip)];
3462 if (pinfo2 & INSN2_READ_GPR_MP)
3463 mask |= 1 << EXTRACT_OPERAND (1, MP, *ip);
3464 if (pinfo2 & INSN2_READ_GPR_MQ)
3465 mask |= 1 << micromips_to_32_reg_q_map[EXTRACT_OPERAND (1, MQ, *ip)];
3467 /* Don't include register 0. */
3471 /* Return the mask of core registers that IP writes. */
3474 gpr_write_mask (const struct mips_cl_insn *ip)
3476 unsigned long pinfo, pinfo2;
3479 mask = gpr_mod_mask (ip);
3480 pinfo = ip->insn_mo->pinfo;
3481 pinfo2 = ip->insn_mo->pinfo2;
3482 if (mips_opts.mips16)
3484 if (pinfo & MIPS16_INSN_WRITE_X)
3485 mask |= 1 << mips16_to_32_reg_map[MIPS16_EXTRACT_OPERAND (RX, *ip)];
3486 if (pinfo & MIPS16_INSN_WRITE_Y)
3487 mask |= 1 << mips16_to_32_reg_map[MIPS16_EXTRACT_OPERAND (RY, *ip)];
3488 if (pinfo & MIPS16_INSN_WRITE_Z)
3489 mask |= 1 << mips16_to_32_reg_map[MIPS16_EXTRACT_OPERAND (RZ, *ip)];
3490 if (pinfo & MIPS16_INSN_WRITE_T)
3492 if (pinfo & MIPS16_INSN_WRITE_SP)
3494 if (pinfo & MIPS16_INSN_WRITE_31)
3496 if (pinfo & MIPS16_INSN_WRITE_GPR_Y)
3497 mask |= 1 << MIPS16OP_EXTRACT_REG32R (ip->insn_opcode);
3501 if (pinfo & INSN_WRITE_GPR_D)
3502 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RD, *ip);
3503 if (pinfo & INSN_WRITE_GPR_T)
3504 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RT, *ip);
3505 if (pinfo & INSN_WRITE_GPR_S)
3506 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RS, *ip);
3507 if (pinfo & INSN_WRITE_GPR_31)
3509 if (pinfo2 & INSN2_WRITE_GPR_Z)
3510 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RZ, *ip);
3512 if (mips_opts.micromips)
3514 if (pinfo2 & INSN2_WRITE_GPR_MB)
3515 mask |= 1 << micromips_to_32_reg_b_map[EXTRACT_OPERAND (1, MB, *ip)];
3516 if (pinfo2 & INSN2_WRITE_GPR_MHI)
3518 mask |= 1 << micromips_to_32_reg_h_map[EXTRACT_OPERAND (1, MH, *ip)];
3519 mask |= 1 << micromips_to_32_reg_i_map[EXTRACT_OPERAND (1, MI, *ip)];
3521 if (pinfo2 & INSN2_WRITE_GPR_MJ)
3522 mask |= 1 << EXTRACT_OPERAND (1, MJ, *ip);
3523 if (pinfo2 & INSN2_WRITE_GPR_MP)
3524 mask |= 1 << EXTRACT_OPERAND (1, MP, *ip);
3526 /* Don't include register 0. */
3530 /* Return the mask of floating-point registers that IP reads. */
3533 fpr_read_mask (const struct mips_cl_insn *ip)
3535 unsigned long pinfo, pinfo2;
3539 pinfo = ip->insn_mo->pinfo;
3540 pinfo2 = ip->insn_mo->pinfo2;
3541 if (!mips_opts.mips16)
3543 if (pinfo2 & INSN2_READ_FPR_D)
3544 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FD, *ip);
3545 if (pinfo & INSN_READ_FPR_S)
3546 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FS, *ip);
3547 if (pinfo & INSN_READ_FPR_T)
3548 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FT, *ip);
3549 if (pinfo & INSN_READ_FPR_R)
3550 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FR, *ip);
3551 if (pinfo2 & INSN2_READ_FPR_Z)
3552 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FZ, *ip);
3554 /* Conservatively treat all operands to an FP_D instruction are doubles.
3555 (This is overly pessimistic for things like cvt.d.s.) */
3556 if (HAVE_32BIT_FPRS && (pinfo & FP_D))
3561 /* Return the mask of floating-point registers that IP writes. */
3564 fpr_write_mask (const struct mips_cl_insn *ip)
3566 unsigned long pinfo, pinfo2;
3570 pinfo = ip->insn_mo->pinfo;
3571 pinfo2 = ip->insn_mo->pinfo2;
3572 if (!mips_opts.mips16)
3574 if (pinfo & INSN_WRITE_FPR_D)
3575 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FD, *ip);
3576 if (pinfo & INSN_WRITE_FPR_S)
3577 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FS, *ip);
3578 if (pinfo & INSN_WRITE_FPR_T)
3579 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FT, *ip);
3580 if (pinfo2 & INSN2_WRITE_FPR_Z)
3581 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FZ, *ip);
3583 /* Conservatively treat all operands to an FP_D instruction are doubles.
3584 (This is overly pessimistic for things like cvt.s.d.) */
3585 if (HAVE_32BIT_FPRS && (pinfo & FP_D))
3590 /* Classify an instruction according to the FIX_VR4120_* enumeration.
3591 Return NUM_FIX_VR4120_CLASSES if the instruction isn't affected
3592 by VR4120 errata. */
3595 classify_vr4120_insn (const char *name)
3597 if (strncmp (name, "macc", 4) == 0)
3598 return FIX_VR4120_MACC;
3599 if (strncmp (name, "dmacc", 5) == 0)
3600 return FIX_VR4120_DMACC;
3601 if (strncmp (name, "mult", 4) == 0)
3602 return FIX_VR4120_MULT;
3603 if (strncmp (name, "dmult", 5) == 0)
3604 return FIX_VR4120_DMULT;
3605 if (strstr (name, "div"))
3606 return FIX_VR4120_DIV;
3607 if (strcmp (name, "mtlo") == 0 || strcmp (name, "mthi") == 0)
3608 return FIX_VR4120_MTHILO;
3609 return NUM_FIX_VR4120_CLASSES;
3612 #define INSN_ERET 0x42000018
3613 #define INSN_DERET 0x4200001f
3615 /* Return the number of instructions that must separate INSN1 and INSN2,
3616 where INSN1 is the earlier instruction. Return the worst-case value
3617 for any INSN2 if INSN2 is null. */
3620 insns_between (const struct mips_cl_insn *insn1,
3621 const struct mips_cl_insn *insn2)
3623 unsigned long pinfo1, pinfo2;
3626 /* This function needs to know which pinfo flags are set for INSN2
3627 and which registers INSN2 uses. The former is stored in PINFO2 and
3628 the latter is tested via INSN2_USES_GPR. If INSN2 is null, PINFO2
3629 will have every flag set and INSN2_USES_GPR will always return true. */
3630 pinfo1 = insn1->insn_mo->pinfo;
3631 pinfo2 = insn2 ? insn2->insn_mo->pinfo : ~0U;
3633 #define INSN2_USES_GPR(REG) \
3634 (insn2 == NULL || (gpr_read_mask (insn2) & (1U << (REG))) != 0)
3636 /* For most targets, write-after-read dependencies on the HI and LO
3637 registers must be separated by at least two instructions. */
3638 if (!hilo_interlocks)
3640 if ((pinfo1 & INSN_READ_LO) && (pinfo2 & INSN_WRITE_LO))
3642 if ((pinfo1 & INSN_READ_HI) && (pinfo2 & INSN_WRITE_HI))
3646 /* If we're working around r7000 errata, there must be two instructions
3647 between an mfhi or mflo and any instruction that uses the result. */
3648 if (mips_7000_hilo_fix
3649 && !mips_opts.micromips
3650 && MF_HILO_INSN (pinfo1)
3651 && INSN2_USES_GPR (EXTRACT_OPERAND (0, RD, *insn1)))
3654 /* If we're working around 24K errata, one instruction is required
3655 if an ERET or DERET is followed by a branch instruction. */
3656 if (mips_fix_24k && !mips_opts.micromips)
3658 if (insn1->insn_opcode == INSN_ERET
3659 || insn1->insn_opcode == INSN_DERET)
3662 || insn2->insn_opcode == INSN_ERET
3663 || insn2->insn_opcode == INSN_DERET
3664 || delayed_branch_p (insn2))
3669 /* If working around VR4120 errata, check for combinations that need
3670 a single intervening instruction. */
3671 if (mips_fix_vr4120 && !mips_opts.micromips)
3673 unsigned int class1, class2;
3675 class1 = classify_vr4120_insn (insn1->insn_mo->name);
3676 if (class1 != NUM_FIX_VR4120_CLASSES && vr4120_conflicts[class1] != 0)
3680 class2 = classify_vr4120_insn (insn2->insn_mo->name);
3681 if (vr4120_conflicts[class1] & (1 << class2))
3686 if (!HAVE_CODE_COMPRESSION)
3688 /* Check for GPR or coprocessor load delays. All such delays
3689 are on the RT register. */
3690 /* Itbl support may require additional care here. */
3691 if ((!gpr_interlocks && (pinfo1 & INSN_LOAD_MEMORY_DELAY))
3692 || (!cop_interlocks && (pinfo1 & INSN_LOAD_COPROC_DELAY)))
3694 know (pinfo1 & INSN_WRITE_GPR_T);
3695 if (INSN2_USES_GPR (EXTRACT_OPERAND (0, RT, *insn1)))
3699 /* Check for generic coprocessor hazards.
3701 This case is not handled very well. There is no special
3702 knowledge of CP0 handling, and the coprocessors other than
3703 the floating point unit are not distinguished at all. */
3704 /* Itbl support may require additional care here. FIXME!
3705 Need to modify this to include knowledge about
3706 user specified delays! */
3707 else if ((!cop_interlocks && (pinfo1 & INSN_COPROC_MOVE_DELAY))
3708 || (!cop_mem_interlocks && (pinfo1 & INSN_COPROC_MEMORY_DELAY)))
3710 /* Handle cases where INSN1 writes to a known general coprocessor
3711 register. There must be a one instruction delay before INSN2
3712 if INSN2 reads that register, otherwise no delay is needed. */
3713 mask = fpr_write_mask (insn1);
3716 if (!insn2 || (mask & fpr_read_mask (insn2)) != 0)
3721 /* Read-after-write dependencies on the control registers
3722 require a two-instruction gap. */
3723 if ((pinfo1 & INSN_WRITE_COND_CODE)
3724 && (pinfo2 & INSN_READ_COND_CODE))
3727 /* We don't know exactly what INSN1 does. If INSN2 is
3728 also a coprocessor instruction, assume there must be
3729 a one instruction gap. */
3730 if (pinfo2 & INSN_COP)
3735 /* Check for read-after-write dependencies on the coprocessor
3736 control registers in cases where INSN1 does not need a general
3737 coprocessor delay. This means that INSN1 is a floating point
3738 comparison instruction. */
3739 /* Itbl support may require additional care here. */
3740 else if (!cop_interlocks
3741 && (pinfo1 & INSN_WRITE_COND_CODE)
3742 && (pinfo2 & INSN_READ_COND_CODE))
3746 #undef INSN2_USES_GPR
3751 /* Return the number of nops that would be needed to work around the
3752 VR4130 mflo/mfhi errata if instruction INSN immediately followed
3753 the MAX_VR4130_NOPS instructions described by HIST. Ignore hazards
3754 that are contained within the first IGNORE instructions of HIST. */
3757 nops_for_vr4130 (int ignore, const struct mips_cl_insn *hist,
3758 const struct mips_cl_insn *insn)
3763 /* Check if the instruction writes to HI or LO. MTHI and MTLO
3764 are not affected by the errata. */
3766 && ((insn->insn_mo->pinfo & (INSN_WRITE_HI | INSN_WRITE_LO)) == 0
3767 || strcmp (insn->insn_mo->name, "mtlo") == 0
3768 || strcmp (insn->insn_mo->name, "mthi") == 0))
3771 /* Search for the first MFLO or MFHI. */
3772 for (i = 0; i < MAX_VR4130_NOPS; i++)
3773 if (MF_HILO_INSN (hist[i].insn_mo->pinfo))
3775 /* Extract the destination register. */
3776 mask = gpr_write_mask (&hist[i]);
3778 /* No nops are needed if INSN reads that register. */
3779 if (insn != NULL && (gpr_read_mask (insn) & mask) != 0)
3782 /* ...or if any of the intervening instructions do. */
3783 for (j = 0; j < i; j++)
3784 if (gpr_read_mask (&hist[j]) & mask)
3788 return MAX_VR4130_NOPS - i;
3793 #define BASE_REG_EQ(INSN1, INSN2) \
3794 ((((INSN1) >> OP_SH_RS) & OP_MASK_RS) \
3795 == (((INSN2) >> OP_SH_RS) & OP_MASK_RS))
3797 /* Return the minimum alignment for this store instruction. */
3800 fix_24k_align_to (const struct mips_opcode *mo)
3802 if (strcmp (mo->name, "sh") == 0)
3805 if (strcmp (mo->name, "swc1") == 0
3806 || strcmp (mo->name, "swc2") == 0
3807 || strcmp (mo->name, "sw") == 0
3808 || strcmp (mo->name, "sc") == 0
3809 || strcmp (mo->name, "s.s") == 0)
3812 if (strcmp (mo->name, "sdc1") == 0
3813 || strcmp (mo->name, "sdc2") == 0
3814 || strcmp (mo->name, "s.d") == 0)
3821 struct fix_24k_store_info
3823 /* Immediate offset, if any, for this store instruction. */
3825 /* Alignment required by this store instruction. */
3827 /* True for register offsets. */
3828 int register_offset;
3831 /* Comparison function used by qsort. */
3834 fix_24k_sort (const void *a, const void *b)
3836 const struct fix_24k_store_info *pos1 = a;
3837 const struct fix_24k_store_info *pos2 = b;
3839 return (pos1->off - pos2->off);
3842 /* INSN is a store instruction. Try to record the store information
3843 in STINFO. Return false if the information isn't known. */
3846 fix_24k_record_store_info (struct fix_24k_store_info *stinfo,
3847 const struct mips_cl_insn *insn)
3849 /* The instruction must have a known offset. */
3850 if (!insn->complete_p || !strstr (insn->insn_mo->args, "o("))
3853 stinfo->off = (insn->insn_opcode >> OP_SH_IMMEDIATE) & OP_MASK_IMMEDIATE;
3854 stinfo->align_to = fix_24k_align_to (insn->insn_mo);
3858 /* Return the number of nops that would be needed to work around the 24k
3859 "lost data on stores during refill" errata if instruction INSN
3860 immediately followed the 2 instructions described by HIST.
3861 Ignore hazards that are contained within the first IGNORE
3862 instructions of HIST.
3864 Problem: The FSB (fetch store buffer) acts as an intermediate buffer
3865 for the data cache refills and store data. The following describes
3866 the scenario where the store data could be lost.
3868 * A data cache miss, due to either a load or a store, causing fill
3869 data to be supplied by the memory subsystem
3870 * The first three doublewords of fill data are returned and written
3872 * A sequence of four stores occurs in consecutive cycles around the
3873 final doubleword of the fill:
3877 * Zero, One or more instructions
3880 The four stores A-D must be to different doublewords of the line that
3881 is being filled. The fourth instruction in the sequence above permits
3882 the fill of the final doubleword to be transferred from the FSB into
3883 the cache. In the sequence above, the stores may be either integer
3884 (sb, sh, sw, swr, swl, sc) or coprocessor (swc1/swc2, sdc1/sdc2,
3885 swxc1, sdxc1, suxc1) stores, as long as the four stores are to
3886 different doublewords on the line. If the floating point unit is
3887 running in 1:2 mode, it is not possible to create the sequence above
3888 using only floating point store instructions.
3890 In this case, the cache line being filled is incorrectly marked
3891 invalid, thereby losing the data from any store to the line that
3892 occurs between the original miss and the completion of the five
3893 cycle sequence shown above.
3895 The workarounds are:
3897 * Run the data cache in write-through mode.
3898 * Insert a non-store instruction between
3899 Store A and Store B or Store B and Store C. */
3902 nops_for_24k (int ignore, const struct mips_cl_insn *hist,
3903 const struct mips_cl_insn *insn)
3905 struct fix_24k_store_info pos[3];
3906 int align, i, base_offset;
3911 /* If the previous instruction wasn't a store, there's nothing to
3913 if ((hist[0].insn_mo->pinfo & INSN_STORE_MEMORY) == 0)
3916 /* If the instructions after the previous one are unknown, we have
3917 to assume the worst. */
3921 /* Check whether we are dealing with three consecutive stores. */
3922 if ((insn->insn_mo->pinfo & INSN_STORE_MEMORY) == 0
3923 || (hist[1].insn_mo->pinfo & INSN_STORE_MEMORY) == 0)
3926 /* If we don't know the relationship between the store addresses,
3927 assume the worst. */
3928 if (!BASE_REG_EQ (insn->insn_opcode, hist[0].insn_opcode)
3929 || !BASE_REG_EQ (insn->insn_opcode, hist[1].insn_opcode))
3932 if (!fix_24k_record_store_info (&pos[0], insn)
3933 || !fix_24k_record_store_info (&pos[1], &hist[0])
3934 || !fix_24k_record_store_info (&pos[2], &hist[1]))
3937 qsort (&pos, 3, sizeof (struct fix_24k_store_info), fix_24k_sort);
3939 /* Pick a value of ALIGN and X such that all offsets are adjusted by
3940 X bytes and such that the base register + X is known to be aligned
3943 if (((insn->insn_opcode >> OP_SH_RS) & OP_MASK_RS) == SP)
3947 align = pos[0].align_to;
3948 base_offset = pos[0].off;
3949 for (i = 1; i < 3; i++)
3950 if (align < pos[i].align_to)
3952 align = pos[i].align_to;
3953 base_offset = pos[i].off;
3955 for (i = 0; i < 3; i++)
3956 pos[i].off -= base_offset;
3959 pos[0].off &= ~align + 1;
3960 pos[1].off &= ~align + 1;
3961 pos[2].off &= ~align + 1;
3963 /* If any two stores write to the same chunk, they also write to the
3964 same doubleword. The offsets are still sorted at this point. */
3965 if (pos[0].off == pos[1].off || pos[1].off == pos[2].off)
3968 /* A range of at least 9 bytes is needed for the stores to be in
3969 non-overlapping doublewords. */
3970 if (pos[2].off - pos[0].off <= 8)
3973 if (pos[2].off - pos[1].off >= 24
3974 || pos[1].off - pos[0].off >= 24
3975 || pos[2].off - pos[0].off >= 32)
3981 /* Return the number of nops that would be needed if instruction INSN
3982 immediately followed the MAX_NOPS instructions given by HIST,
3983 where HIST[0] is the most recent instruction. Ignore hazards
3984 between INSN and the first IGNORE instructions in HIST.
3986 If INSN is null, return the worse-case number of nops for any
3990 nops_for_insn (int ignore, const struct mips_cl_insn *hist,
3991 const struct mips_cl_insn *insn)
3993 int i, nops, tmp_nops;
3996 for (i = ignore; i < MAX_DELAY_NOPS; i++)
3998 tmp_nops = insns_between (hist + i, insn) - i;
3999 if (tmp_nops > nops)
4003 if (mips_fix_vr4130 && !mips_opts.micromips)
4005 tmp_nops = nops_for_vr4130 (ignore, hist, insn);
4006 if (tmp_nops > nops)
4010 if (mips_fix_24k && !mips_opts.micromips)
4012 tmp_nops = nops_for_24k (ignore, hist, insn);
4013 if (tmp_nops > nops)
4020 /* The variable arguments provide NUM_INSNS extra instructions that
4021 might be added to HIST. Return the largest number of nops that
4022 would be needed after the extended sequence, ignoring hazards
4023 in the first IGNORE instructions. */
4026 nops_for_sequence (int num_insns, int ignore,
4027 const struct mips_cl_insn *hist, ...)
4030 struct mips_cl_insn buffer[MAX_NOPS];
4031 struct mips_cl_insn *cursor;
4034 va_start (args, hist);
4035 cursor = buffer + num_insns;
4036 memcpy (cursor, hist, (MAX_NOPS - num_insns) * sizeof (*cursor));
4037 while (cursor > buffer)
4038 *--cursor = *va_arg (args, const struct mips_cl_insn *);
4040 nops = nops_for_insn (ignore, buffer, NULL);
4045 /* Like nops_for_insn, but if INSN is a branch, take into account the
4046 worst-case delay for the branch target. */
4049 nops_for_insn_or_target (int ignore, const struct mips_cl_insn *hist,
4050 const struct mips_cl_insn *insn)
4054 nops = nops_for_insn (ignore, hist, insn);
4055 if (delayed_branch_p (insn))
4057 tmp_nops = nops_for_sequence (2, ignore ? ignore + 2 : 0,
4058 hist, insn, get_delay_slot_nop (insn));
4059 if (tmp_nops > nops)
4062 else if (compact_branch_p (insn))
4064 tmp_nops = nops_for_sequence (1, ignore ? ignore + 1 : 0, hist, insn);
4065 if (tmp_nops > nops)
4071 /* Fix NOP issue: Replace nops by "or at,at,zero". */
4074 fix_loongson2f_nop (struct mips_cl_insn * ip)
4076 gas_assert (!HAVE_CODE_COMPRESSION);
4077 if (strcmp (ip->insn_mo->name, "nop") == 0)
4078 ip->insn_opcode = LOONGSON2F_NOP_INSN;
4081 /* Fix Jump Issue: Eliminate instruction fetch from outside 256M region
4082 jr target pc &= 'hffff_ffff_cfff_ffff. */
4085 fix_loongson2f_jump (struct mips_cl_insn * ip)
4087 gas_assert (!HAVE_CODE_COMPRESSION);
4088 if (strcmp (ip->insn_mo->name, "j") == 0
4089 || strcmp (ip->insn_mo->name, "jr") == 0
4090 || strcmp (ip->insn_mo->name, "jalr") == 0)
4098 sreg = EXTRACT_OPERAND (0, RS, *ip);
4099 if (sreg == ZERO || sreg == KT0 || sreg == KT1 || sreg == ATREG)
4102 ep.X_op = O_constant;
4103 ep.X_add_number = 0xcfff0000;
4104 macro_build (&ep, "lui", "t,u", ATREG, BFD_RELOC_HI16);
4105 ep.X_add_number = 0xffff;
4106 macro_build (&ep, "ori", "t,r,i", ATREG, ATREG, BFD_RELOC_LO16);
4107 macro_build (NULL, "and", "d,v,t", sreg, sreg, ATREG);
4112 fix_loongson2f (struct mips_cl_insn * ip)
4114 if (mips_fix_loongson2f_nop)
4115 fix_loongson2f_nop (ip);
4117 if (mips_fix_loongson2f_jump)
4118 fix_loongson2f_jump (ip);
4121 /* IP is a branch that has a delay slot, and we need to fill it
4122 automatically. Return true if we can do that by swapping IP
4123 with the previous instruction.
4124 ADDRESS_EXPR is an operand of the instruction to be used with
4128 can_swap_branch_p (struct mips_cl_insn *ip, expressionS *address_expr,
4129 bfd_reloc_code_real_type *reloc_type)
4131 unsigned long pinfo, pinfo2, prev_pinfo, prev_pinfo2;
4132 unsigned int gpr_read, gpr_write, prev_gpr_read, prev_gpr_write;
4134 /* -O2 and above is required for this optimization. */
4135 if (mips_optimize < 2)
4138 /* If we have seen .set volatile or .set nomove, don't optimize. */
4139 if (mips_opts.nomove)
4142 /* We can't swap if the previous instruction's position is fixed. */
4143 if (history[0].fixed_p)
4146 /* If the previous previous insn was in a .set noreorder, we can't
4147 swap. Actually, the MIPS assembler will swap in this situation.
4148 However, gcc configured -with-gnu-as will generate code like
4156 in which we can not swap the bne and INSN. If gcc is not configured
4157 -with-gnu-as, it does not output the .set pseudo-ops. */
4158 if (history[1].noreorder_p)
4161 /* If the previous instruction had a fixup in mips16 mode, we can not swap.
4162 This means that the previous instruction was a 4-byte one anyhow. */
4163 if (mips_opts.mips16 && history[0].fixp[0])
4166 /* If the branch is itself the target of a branch, we can not swap.
4167 We cheat on this; all we check for is whether there is a label on
4168 this instruction. If there are any branches to anything other than
4169 a label, users must use .set noreorder. */
4170 if (seg_info (now_seg)->label_list)
4173 /* If the previous instruction is in a variant frag other than this
4174 branch's one, we cannot do the swap. This does not apply to
4175 MIPS16 code, which uses variant frags for different purposes. */
4176 if (!mips_opts.mips16
4178 && history[0].frag->fr_type == rs_machine_dependent)
4181 /* We do not swap with instructions that cannot architecturally
4182 be placed in a branch delay slot, such as SYNC or ERET. We
4183 also refrain from swapping with a trap instruction, since it
4184 complicates trap handlers to have the trap instruction be in
4186 prev_pinfo = history[0].insn_mo->pinfo;
4187 if (prev_pinfo & INSN_NO_DELAY_SLOT)
4190 /* Check for conflicts between the branch and the instructions
4191 before the candidate delay slot. */
4192 if (nops_for_insn (0, history + 1, ip) > 0)
4195 /* Check for conflicts between the swapped sequence and the
4196 target of the branch. */
4197 if (nops_for_sequence (2, 0, history + 1, ip, history) > 0)
4200 /* If the branch reads a register that the previous
4201 instruction sets, we can not swap. */
4202 gpr_read = gpr_read_mask (ip);
4203 prev_gpr_write = gpr_write_mask (&history[0]);
4204 if (gpr_read & prev_gpr_write)
4207 /* If the branch writes a register that the previous
4208 instruction sets, we can not swap. */
4209 gpr_write = gpr_write_mask (ip);
4210 if (gpr_write & prev_gpr_write)
4213 /* If the branch writes a register that the previous
4214 instruction reads, we can not swap. */
4215 prev_gpr_read = gpr_read_mask (&history[0]);
4216 if (gpr_write & prev_gpr_read)
4219 /* If one instruction sets a condition code and the
4220 other one uses a condition code, we can not swap. */
4221 pinfo = ip->insn_mo->pinfo;
4222 if ((pinfo & INSN_READ_COND_CODE)
4223 && (prev_pinfo & INSN_WRITE_COND_CODE))
4225 if ((pinfo & INSN_WRITE_COND_CODE)
4226 && (prev_pinfo & INSN_READ_COND_CODE))
4229 /* If the previous instruction uses the PC, we can not swap. */
4230 prev_pinfo2 = history[0].insn_mo->pinfo2;
4231 if (mips_opts.mips16 && (prev_pinfo & MIPS16_INSN_READ_PC))
4233 if (mips_opts.micromips && (prev_pinfo2 & INSN2_READ_PC))
4236 /* If the previous instruction has an incorrect size for a fixed
4237 branch delay slot in microMIPS mode, we cannot swap. */
4238 pinfo2 = ip->insn_mo->pinfo2;
4239 if (mips_opts.micromips
4240 && (pinfo2 & INSN2_BRANCH_DELAY_16BIT)
4241 && insn_length (history) != 2)
4243 if (mips_opts.micromips
4244 && (pinfo2 & INSN2_BRANCH_DELAY_32BIT)
4245 && insn_length (history) != 4)
4248 /* On R5900 short loops need to be fixed by inserting a nop in
4249 the branch delay slots.
4250 A short loop can be terminated too early. */
4251 if (mips_opts.arch == CPU_R5900
4252 /* Check if instruction has a parameter, ignore "j $31". */
4253 && (address_expr != NULL)
4254 /* Parameter must be 16 bit. */
4255 && (*reloc_type == BFD_RELOC_16_PCREL_S2)
4256 /* Branch to same segment. */
4257 && (S_GET_SEGMENT(address_expr->X_add_symbol) == now_seg)
4258 /* Branch to same code fragment. */
4259 && (symbol_get_frag(address_expr->X_add_symbol) == frag_now)
4260 /* Can only calculate branch offset if value is known. */
4261 && symbol_constant_p(address_expr->X_add_symbol)
4262 /* Check if branch is really conditional. */
4263 && !((ip->insn_opcode & 0xffff0000) == 0x10000000 /* beq $0,$0 */
4264 || (ip->insn_opcode & 0xffff0000) == 0x04010000 /* bgez $0 */
4265 || (ip->insn_opcode & 0xffff0000) == 0x04110000)) /* bgezal $0 */
4268 /* Check if loop is shorter than 6 instructions including
4269 branch and delay slot. */
4270 distance = frag_now_fix() - S_GET_VALUE(address_expr->X_add_symbol);
4277 /* When the loop includes branches or jumps,
4278 it is not a short loop. */
4279 for (i = 0; i < (distance / 4); i++)
4281 if ((history[i].cleared_p)
4282 || delayed_branch_p(&history[i]))
4290 /* Insert nop after branch to fix short loop. */
4299 /* Decide how we should add IP to the instruction stream.
4300 ADDRESS_EXPR is an operand of the instruction to be used with
4303 static enum append_method
4304 get_append_method (struct mips_cl_insn *ip, expressionS *address_expr,
4305 bfd_reloc_code_real_type *reloc_type)
4307 unsigned long pinfo;
4309 /* The relaxed version of a macro sequence must be inherently
4311 if (mips_relax.sequence == 2)
4314 /* We must not dabble with instructions in a ".set norerorder" block. */
4315 if (mips_opts.noreorder)
4318 /* Otherwise, it's our responsibility to fill branch delay slots. */
4319 if (delayed_branch_p (ip))
4321 if (!branch_likely_p (ip)
4322 && can_swap_branch_p (ip, address_expr, reloc_type))
4325 pinfo = ip->insn_mo->pinfo;
4326 if (mips_opts.mips16
4327 && ISA_SUPPORTS_MIPS16E
4328 && (pinfo & (MIPS16_INSN_READ_X | MIPS16_INSN_READ_31)))
4329 return APPEND_ADD_COMPACT;
4331 return APPEND_ADD_WITH_NOP;
4337 /* IP is a MIPS16 instruction whose opcode we have just changed.
4338 Point IP->insn_mo to the new opcode's definition. */
4341 find_altered_mips16_opcode (struct mips_cl_insn *ip)
4343 const struct mips_opcode *mo, *end;
4345 end = &mips16_opcodes[bfd_mips16_num_opcodes];
4346 for (mo = ip->insn_mo; mo < end; mo++)
4347 if ((ip->insn_opcode & mo->mask) == mo->match)
4355 /* For microMIPS macros, we need to generate a local number label
4356 as the target of branches. */
4357 #define MICROMIPS_LABEL_CHAR '\037'
4358 static unsigned long micromips_target_label;
4359 static char micromips_target_name[32];
4362 micromips_label_name (void)
4364 char *p = micromips_target_name;
4365 char symbol_name_temporary[24];
4373 l = micromips_target_label;
4374 #ifdef LOCAL_LABEL_PREFIX
4375 *p++ = LOCAL_LABEL_PREFIX;
4378 *p++ = MICROMIPS_LABEL_CHAR;
4381 symbol_name_temporary[i++] = l % 10 + '0';
4386 *p++ = symbol_name_temporary[--i];
4389 return micromips_target_name;
4393 micromips_label_expr (expressionS *label_expr)
4395 label_expr->X_op = O_symbol;
4396 label_expr->X_add_symbol = symbol_find_or_make (micromips_label_name ());
4397 label_expr->X_add_number = 0;
4401 micromips_label_inc (void)
4403 micromips_target_label++;
4404 *micromips_target_name = '\0';
4408 micromips_add_label (void)
4412 s = colon (micromips_label_name ());
4413 micromips_label_inc ();
4414 #if defined(OBJ_ELF) || defined(OBJ_MAYBE_ELF)
4416 S_SET_OTHER (s, ELF_ST_SET_MICROMIPS (S_GET_OTHER (s)));
4422 /* If assembling microMIPS code, then return the microMIPS reloc
4423 corresponding to the requested one if any. Otherwise return
4424 the reloc unchanged. */
4426 static bfd_reloc_code_real_type
4427 micromips_map_reloc (bfd_reloc_code_real_type reloc)
4429 static const bfd_reloc_code_real_type relocs[][2] =
4431 /* Keep sorted incrementally by the left-hand key. */
4432 { BFD_RELOC_16_PCREL_S2, BFD_RELOC_MICROMIPS_16_PCREL_S1 },
4433 { BFD_RELOC_GPREL16, BFD_RELOC_MICROMIPS_GPREL16 },
4434 { BFD_RELOC_MIPS_JMP, BFD_RELOC_MICROMIPS_JMP },
4435 { BFD_RELOC_HI16, BFD_RELOC_MICROMIPS_HI16 },
4436 { BFD_RELOC_HI16_S, BFD_RELOC_MICROMIPS_HI16_S },
4437 { BFD_RELOC_LO16, BFD_RELOC_MICROMIPS_LO16 },
4438 { BFD_RELOC_MIPS_LITERAL, BFD_RELOC_MICROMIPS_LITERAL },
4439 { BFD_RELOC_MIPS_GOT16, BFD_RELOC_MICROMIPS_GOT16 },
4440 { BFD_RELOC_MIPS_CALL16, BFD_RELOC_MICROMIPS_CALL16 },
4441 { BFD_RELOC_MIPS_GOT_HI16, BFD_RELOC_MICROMIPS_GOT_HI16 },
4442 { BFD_RELOC_MIPS_GOT_LO16, BFD_RELOC_MICROMIPS_GOT_LO16 },
4443 { BFD_RELOC_MIPS_CALL_HI16, BFD_RELOC_MICROMIPS_CALL_HI16 },
4444 { BFD_RELOC_MIPS_CALL_LO16, BFD_RELOC_MICROMIPS_CALL_LO16 },
4445 { BFD_RELOC_MIPS_SUB, BFD_RELOC_MICROMIPS_SUB },
4446 { BFD_RELOC_MIPS_GOT_PAGE, BFD_RELOC_MICROMIPS_GOT_PAGE },
4447 { BFD_RELOC_MIPS_GOT_OFST, BFD_RELOC_MICROMIPS_GOT_OFST },
4448 { BFD_RELOC_MIPS_GOT_DISP, BFD_RELOC_MICROMIPS_GOT_DISP },
4449 { BFD_RELOC_MIPS_HIGHEST, BFD_RELOC_MICROMIPS_HIGHEST },
4450 { BFD_RELOC_MIPS_HIGHER, BFD_RELOC_MICROMIPS_HIGHER },
4451 { BFD_RELOC_MIPS_SCN_DISP, BFD_RELOC_MICROMIPS_SCN_DISP },
4452 { BFD_RELOC_MIPS_TLS_GD, BFD_RELOC_MICROMIPS_TLS_GD },
4453 { BFD_RELOC_MIPS_TLS_LDM, BFD_RELOC_MICROMIPS_TLS_LDM },
4454 { BFD_RELOC_MIPS_TLS_DTPREL_HI16, BFD_RELOC_MICROMIPS_TLS_DTPREL_HI16 },
4455 { BFD_RELOC_MIPS_TLS_DTPREL_LO16, BFD_RELOC_MICROMIPS_TLS_DTPREL_LO16 },
4456 { BFD_RELOC_MIPS_TLS_GOTTPREL, BFD_RELOC_MICROMIPS_TLS_GOTTPREL },
4457 { BFD_RELOC_MIPS_TLS_TPREL_HI16, BFD_RELOC_MICROMIPS_TLS_TPREL_HI16 },
4458 { BFD_RELOC_MIPS_TLS_TPREL_LO16, BFD_RELOC_MICROMIPS_TLS_TPREL_LO16 }
4460 bfd_reloc_code_real_type r;
4463 if (!mips_opts.micromips)
4465 for (i = 0; i < ARRAY_SIZE (relocs); i++)
4471 return relocs[i][1];
4476 /* Try to resolve relocation RELOC against constant OPERAND at assembly time.
4477 Return true on success, storing the resolved value in RESULT. */
4480 calculate_reloc (bfd_reloc_code_real_type reloc, offsetT operand,
4485 case BFD_RELOC_MIPS_HIGHEST:
4486 case BFD_RELOC_MICROMIPS_HIGHEST:
4487 *result = ((operand + 0x800080008000ull) >> 48) & 0xffff;
4490 case BFD_RELOC_MIPS_HIGHER:
4491 case BFD_RELOC_MICROMIPS_HIGHER:
4492 *result = ((operand + 0x80008000ull) >> 32) & 0xffff;
4495 case BFD_RELOC_HI16_S:
4496 case BFD_RELOC_MICROMIPS_HI16_S:
4497 case BFD_RELOC_MIPS16_HI16_S:
4498 *result = ((operand + 0x8000) >> 16) & 0xffff;
4501 case BFD_RELOC_HI16:
4502 case BFD_RELOC_MICROMIPS_HI16:
4503 case BFD_RELOC_MIPS16_HI16:
4504 *result = (operand >> 16) & 0xffff;
4507 case BFD_RELOC_LO16:
4508 case BFD_RELOC_MICROMIPS_LO16:
4509 case BFD_RELOC_MIPS16_LO16:
4510 *result = operand & 0xffff;
4513 case BFD_RELOC_UNUSED:
4522 /* Output an instruction. IP is the instruction information.
4523 ADDRESS_EXPR is an operand of the instruction to be used with
4524 RELOC_TYPE. EXPANSIONP is true if the instruction is part of
4525 a macro expansion. */
4528 append_insn (struct mips_cl_insn *ip, expressionS *address_expr,
4529 bfd_reloc_code_real_type *reloc_type, bfd_boolean expansionp)
4531 unsigned long prev_pinfo2, pinfo;
4532 bfd_boolean relaxed_branch = FALSE;
4533 enum append_method method;
4534 bfd_boolean relax32;
4537 if (mips_fix_loongson2f && !HAVE_CODE_COMPRESSION)
4538 fix_loongson2f (ip);
4540 file_ase_mips16 |= mips_opts.mips16;
4541 file_ase_micromips |= mips_opts.micromips;
4543 prev_pinfo2 = history[0].insn_mo->pinfo2;
4544 pinfo = ip->insn_mo->pinfo;
4546 if (mips_opts.micromips
4548 && (((prev_pinfo2 & INSN2_BRANCH_DELAY_16BIT) != 0
4549 && micromips_insn_length (ip->insn_mo) != 2)
4550 || ((prev_pinfo2 & INSN2_BRANCH_DELAY_32BIT) != 0
4551 && micromips_insn_length (ip->insn_mo) != 4)))
4552 as_warn (_("Wrong size instruction in a %u-bit branch delay slot"),
4553 (prev_pinfo2 & INSN2_BRANCH_DELAY_16BIT) != 0 ? 16 : 32);
4555 if (address_expr == NULL)
4557 else if (reloc_type[0] <= BFD_RELOC_UNUSED
4558 && reloc_type[1] == BFD_RELOC_UNUSED
4559 && reloc_type[2] == BFD_RELOC_UNUSED
4560 && address_expr->X_op == O_constant)
4562 switch (*reloc_type)
4564 case BFD_RELOC_MIPS_JMP:
4568 shift = mips_opts.micromips ? 1 : 2;
4569 if ((address_expr->X_add_number & ((1 << shift) - 1)) != 0)
4570 as_bad (_("jump to misaligned address (0x%lx)"),
4571 (unsigned long) address_expr->X_add_number);
4572 ip->insn_opcode |= ((address_expr->X_add_number >> shift)
4578 case BFD_RELOC_MIPS16_JMP:
4579 if ((address_expr->X_add_number & 3) != 0)
4580 as_bad (_("jump to misaligned address (0x%lx)"),
4581 (unsigned long) address_expr->X_add_number);
4583 (((address_expr->X_add_number & 0x7c0000) << 3)
4584 | ((address_expr->X_add_number & 0xf800000) >> 7)
4585 | ((address_expr->X_add_number & 0x3fffc) >> 2));
4589 case BFD_RELOC_16_PCREL_S2:
4593 shift = mips_opts.micromips ? 1 : 2;
4594 if ((address_expr->X_add_number & ((1 << shift) - 1)) != 0)
4595 as_bad (_("branch to misaligned address (0x%lx)"),
4596 (unsigned long) address_expr->X_add_number);
4597 if (!mips_relax_branch)
4599 if ((address_expr->X_add_number + (1 << (shift + 15)))
4600 & ~((1 << (shift + 16)) - 1))
4601 as_bad (_("branch address range overflow (0x%lx)"),
4602 (unsigned long) address_expr->X_add_number);
4603 ip->insn_opcode |= ((address_expr->X_add_number >> shift)
4613 if (calculate_reloc (*reloc_type, address_expr->X_add_number,
4616 ip->insn_opcode |= value & 0xffff;
4624 if (mips_relax.sequence != 2 && !mips_opts.noreorder)
4626 /* There are a lot of optimizations we could do that we don't.
4627 In particular, we do not, in general, reorder instructions.
4628 If you use gcc with optimization, it will reorder
4629 instructions and generally do much more optimization then we
4630 do here; repeating all that work in the assembler would only
4631 benefit hand written assembly code, and does not seem worth
4633 int nops = (mips_optimize == 0
4634 ? nops_for_insn (0, history, NULL)
4635 : nops_for_insn_or_target (0, history, ip));
4639 unsigned long old_frag_offset;
4642 old_frag = frag_now;
4643 old_frag_offset = frag_now_fix ();
4645 for (i = 0; i < nops; i++)
4646 add_fixed_insn (NOP_INSN);
4647 insert_into_history (0, nops, NOP_INSN);
4651 listing_prev_line ();
4652 /* We may be at the start of a variant frag. In case we
4653 are, make sure there is enough space for the frag
4654 after the frags created by listing_prev_line. The
4655 argument to frag_grow here must be at least as large
4656 as the argument to all other calls to frag_grow in
4657 this file. We don't have to worry about being in the
4658 middle of a variant frag, because the variants insert
4659 all needed nop instructions themselves. */
4663 mips_move_text_labels ();
4665 #ifndef NO_ECOFF_DEBUGGING
4666 if (ECOFF_DEBUGGING)
4667 ecoff_fix_loc (old_frag, old_frag_offset);
4671 else if (mips_relax.sequence != 2 && prev_nop_frag != NULL)
4675 /* Work out how many nops in prev_nop_frag are needed by IP,
4676 ignoring hazards generated by the first prev_nop_frag_since
4678 nops = nops_for_insn_or_target (prev_nop_frag_since, history, ip);
4679 gas_assert (nops <= prev_nop_frag_holds);
4681 /* Enforce NOPS as a minimum. */
4682 if (nops > prev_nop_frag_required)
4683 prev_nop_frag_required = nops;
4685 if (prev_nop_frag_holds == prev_nop_frag_required)
4687 /* Settle for the current number of nops. Update the history
4688 accordingly (for the benefit of any future .set reorder code). */
4689 prev_nop_frag = NULL;
4690 insert_into_history (prev_nop_frag_since,
4691 prev_nop_frag_holds, NOP_INSN);
4695 /* Allow this instruction to replace one of the nops that was
4696 tentatively added to prev_nop_frag. */
4697 prev_nop_frag->fr_fix -= NOP_INSN_SIZE;
4698 prev_nop_frag_holds--;
4699 prev_nop_frag_since++;
4703 method = get_append_method (ip, address_expr, reloc_type);
4704 branch_disp = method == APPEND_SWAP ? insn_length (history) : 0;
4707 dwarf2_emit_insn (0);
4708 /* We want MIPS16 and microMIPS debug info to use ISA-encoded addresses,
4709 so "move" the instruction address accordingly.
4711 Also, it doesn't seem appropriate for the assembler to reorder .loc
4712 entries. If this instruction is a branch that we are going to swap
4713 with the previous instruction, the two instructions should be
4714 treated as a unit, and the debug information for both instructions
4715 should refer to the start of the branch sequence. Using the
4716 current position is certainly wrong when swapping a 32-bit branch
4717 and a 16-bit delay slot, since the current position would then be
4718 in the middle of a branch. */
4719 dwarf2_move_insn ((HAVE_CODE_COMPRESSION ? 1 : 0) - branch_disp);
4722 relax32 = (mips_relax_branch
4723 /* Don't try branch relaxation within .set nomacro, or within
4724 .set noat if we use $at for PIC computations. If it turns
4725 out that the branch was out-of-range, we'll get an error. */
4726 && !mips_opts.warn_about_macros
4727 && (mips_opts.at || mips_pic == NO_PIC)
4728 /* Don't relax BPOSGE32/64 or BC1ANY2T/F and BC1ANY4T/F
4729 as they have no complementing branches. */
4730 && !(ip->insn_mo->ase & (ASE_MIPS3D | ASE_DSP64 | ASE_DSP)));
4732 if (!HAVE_CODE_COMPRESSION
4735 && *reloc_type == BFD_RELOC_16_PCREL_S2
4736 && delayed_branch_p (ip))
4738 relaxed_branch = TRUE;
4739 add_relaxed_insn (ip, (relaxed_branch_length
4741 uncond_branch_p (ip) ? -1
4742 : branch_likely_p (ip) ? 1
4746 uncond_branch_p (ip),
4747 branch_likely_p (ip),
4748 pinfo & INSN_WRITE_GPR_31,
4750 address_expr->X_add_symbol,
4751 address_expr->X_add_number);
4752 *reloc_type = BFD_RELOC_UNUSED;
4754 else if (mips_opts.micromips
4756 && ((relax32 && *reloc_type == BFD_RELOC_16_PCREL_S2)
4757 || *reloc_type > BFD_RELOC_UNUSED)
4758 && (delayed_branch_p (ip) || compact_branch_p (ip))
4759 /* Don't try branch relaxation when users specify
4760 16-bit/32-bit instructions. */
4761 && !forced_insn_length)
4763 bfd_boolean relax16 = *reloc_type > BFD_RELOC_UNUSED;
4764 int type = relax16 ? *reloc_type - BFD_RELOC_UNUSED : 0;
4765 int uncond = uncond_branch_p (ip) ? -1 : 0;
4766 int compact = compact_branch_p (ip);
4767 int al = pinfo & INSN_WRITE_GPR_31;
4770 gas_assert (address_expr != NULL);
4771 gas_assert (!mips_relax.sequence);
4773 relaxed_branch = TRUE;
4774 length32 = relaxed_micromips_32bit_branch_length (NULL, NULL, uncond);
4775 add_relaxed_insn (ip, relax32 ? length32 : 4, relax16 ? 2 : 4,
4776 RELAX_MICROMIPS_ENCODE (type, AT, uncond, compact, al,
4778 address_expr->X_add_symbol,
4779 address_expr->X_add_number);
4780 *reloc_type = BFD_RELOC_UNUSED;
4782 else if (mips_opts.mips16 && *reloc_type > BFD_RELOC_UNUSED)
4784 /* We need to set up a variant frag. */
4785 gas_assert (address_expr != NULL);
4786 add_relaxed_insn (ip, 4, 0,
4788 (*reloc_type - BFD_RELOC_UNUSED,
4789 forced_insn_length == 2, forced_insn_length == 4,
4790 delayed_branch_p (&history[0]),
4791 history[0].mips16_absolute_jump_p),
4792 make_expr_symbol (address_expr), 0);
4794 else if (mips_opts.mips16 && insn_length (ip) == 2)
4796 if (!delayed_branch_p (ip))
4797 /* Make sure there is enough room to swap this instruction with
4798 a following jump instruction. */
4800 add_fixed_insn (ip);
4804 if (mips_opts.mips16
4805 && mips_opts.noreorder
4806 && delayed_branch_p (&history[0]))
4807 as_warn (_("extended instruction in delay slot"));
4809 if (mips_relax.sequence)
4811 /* If we've reached the end of this frag, turn it into a variant
4812 frag and record the information for the instructions we've
4814 if (frag_room () < 4)
4815 relax_close_frag ();
4816 mips_relax.sizes[mips_relax.sequence - 1] += insn_length (ip);
4819 if (mips_relax.sequence != 2)
4821 if (mips_macro_warning.first_insn_sizes[0] == 0)
4822 mips_macro_warning.first_insn_sizes[0] = insn_length (ip);
4823 mips_macro_warning.sizes[0] += insn_length (ip);
4824 mips_macro_warning.insns[0]++;
4826 if (mips_relax.sequence != 1)
4828 if (mips_macro_warning.first_insn_sizes[1] == 0)
4829 mips_macro_warning.first_insn_sizes[1] = insn_length (ip);
4830 mips_macro_warning.sizes[1] += insn_length (ip);
4831 mips_macro_warning.insns[1]++;
4834 if (mips_opts.mips16)
4837 ip->mips16_absolute_jump_p = (*reloc_type == BFD_RELOC_MIPS16_JMP);
4839 add_fixed_insn (ip);
4842 if (!ip->complete_p && *reloc_type < BFD_RELOC_UNUSED)
4844 bfd_reloc_code_real_type final_type[3];
4845 reloc_howto_type *howto0;
4846 reloc_howto_type *howto;
4849 /* Perform any necessary conversion to microMIPS relocations
4850 and find out how many relocations there actually are. */
4851 for (i = 0; i < 3 && reloc_type[i] != BFD_RELOC_UNUSED; i++)
4852 final_type[i] = micromips_map_reloc (reloc_type[i]);
4854 /* In a compound relocation, it is the final (outermost)
4855 operator that determines the relocated field. */
4856 howto = howto0 = bfd_reloc_type_lookup (stdoutput, final_type[i - 1]);
4860 /* To reproduce this failure try assembling gas/testsuites/
4861 gas/mips/mips16-intermix.s with a mips-ecoff targeted
4863 as_bad (_("Unsupported MIPS relocation number %d"),
4865 howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_16);
4869 howto0 = bfd_reloc_type_lookup (stdoutput, final_type[0]);
4870 ip->fixp[0] = fix_new_exp (ip->frag, ip->where,
4871 bfd_get_reloc_size (howto),
4873 howto0 && howto0->pc_relative,
4876 /* Tag symbols that have a R_MIPS16_26 relocation against them. */
4877 if (final_type[0] == BFD_RELOC_MIPS16_JMP && ip->fixp[0]->fx_addsy)
4878 *symbol_get_tc (ip->fixp[0]->fx_addsy) = 1;
4880 /* These relocations can have an addend that won't fit in
4881 4 octets for 64bit assembly. */
4883 && ! howto->partial_inplace
4884 && (reloc_type[0] == BFD_RELOC_16
4885 || reloc_type[0] == BFD_RELOC_32
4886 || reloc_type[0] == BFD_RELOC_MIPS_JMP
4887 || reloc_type[0] == BFD_RELOC_GPREL16
4888 || reloc_type[0] == BFD_RELOC_MIPS_LITERAL
4889 || reloc_type[0] == BFD_RELOC_GPREL32
4890 || reloc_type[0] == BFD_RELOC_64
4891 || reloc_type[0] == BFD_RELOC_CTOR
4892 || reloc_type[0] == BFD_RELOC_MIPS_SUB
4893 || reloc_type[0] == BFD_RELOC_MIPS_HIGHEST
4894 || reloc_type[0] == BFD_RELOC_MIPS_HIGHER
4895 || reloc_type[0] == BFD_RELOC_MIPS_SCN_DISP
4896 || reloc_type[0] == BFD_RELOC_MIPS_REL16
4897 || reloc_type[0] == BFD_RELOC_MIPS_RELGOT
4898 || reloc_type[0] == BFD_RELOC_MIPS16_GPREL
4899 || hi16_reloc_p (reloc_type[0])
4900 || lo16_reloc_p (reloc_type[0])))
4901 ip->fixp[0]->fx_no_overflow = 1;
4903 /* These relocations can have an addend that won't fit in 2 octets. */
4904 if (reloc_type[0] == BFD_RELOC_MICROMIPS_7_PCREL_S1
4905 || reloc_type[0] == BFD_RELOC_MICROMIPS_10_PCREL_S1)
4906 ip->fixp[0]->fx_no_overflow = 1;
4908 if (mips_relax.sequence)
4910 if (mips_relax.first_fixup == 0)
4911 mips_relax.first_fixup = ip->fixp[0];
4913 else if (reloc_needs_lo_p (*reloc_type))
4915 struct mips_hi_fixup *hi_fixup;
4917 /* Reuse the last entry if it already has a matching %lo. */
4918 hi_fixup = mips_hi_fixup_list;
4920 || !fixup_has_matching_lo_p (hi_fixup->fixp))
4922 hi_fixup = ((struct mips_hi_fixup *)
4923 xmalloc (sizeof (struct mips_hi_fixup)));
4924 hi_fixup->next = mips_hi_fixup_list;
4925 mips_hi_fixup_list = hi_fixup;
4927 hi_fixup->fixp = ip->fixp[0];
4928 hi_fixup->seg = now_seg;
4931 /* Add fixups for the second and third relocations, if given.
4932 Note that the ABI allows the second relocation to be
4933 against RSS_UNDEF, RSS_GP, RSS_GP0 or RSS_LOC. At the
4934 moment we only use RSS_UNDEF, but we could add support
4935 for the others if it ever becomes necessary. */
4936 for (i = 1; i < 3; i++)
4937 if (reloc_type[i] != BFD_RELOC_UNUSED)
4939 ip->fixp[i] = fix_new (ip->frag, ip->where,
4940 ip->fixp[0]->fx_size, NULL, 0,
4941 FALSE, final_type[i]);
4943 /* Use fx_tcbit to mark compound relocs. */
4944 ip->fixp[0]->fx_tcbit = 1;
4945 ip->fixp[i]->fx_tcbit = 1;
4950 /* Update the register mask information. */
4951 mips_gprmask |= gpr_read_mask (ip) | gpr_write_mask (ip);
4952 mips_cprmask[1] |= fpr_read_mask (ip) | fpr_write_mask (ip);
4957 insert_into_history (0, 1, ip);
4960 case APPEND_ADD_WITH_NOP:
4962 struct mips_cl_insn *nop;
4964 insert_into_history (0, 1, ip);
4965 nop = get_delay_slot_nop (ip);
4966 add_fixed_insn (nop);
4967 insert_into_history (0, 1, nop);
4968 if (mips_relax.sequence)
4969 mips_relax.sizes[mips_relax.sequence - 1] += insn_length (nop);
4973 case APPEND_ADD_COMPACT:
4974 /* Convert MIPS16 jr/jalr into a "compact" jump. */
4975 gas_assert (mips_opts.mips16);
4976 ip->insn_opcode |= 0x0080;
4977 find_altered_mips16_opcode (ip);
4979 insert_into_history (0, 1, ip);
4984 struct mips_cl_insn delay = history[0];
4985 if (mips_opts.mips16)
4987 know (delay.frag == ip->frag);
4988 move_insn (ip, delay.frag, delay.where);
4989 move_insn (&delay, ip->frag, ip->where + insn_length (ip));
4991 else if (relaxed_branch || delay.frag != ip->frag)
4993 /* Add the delay slot instruction to the end of the
4994 current frag and shrink the fixed part of the
4995 original frag. If the branch occupies the tail of
4996 the latter, move it backwards to cover the gap. */
4997 delay.frag->fr_fix -= branch_disp;
4998 if (delay.frag == ip->frag)
4999 move_insn (ip, ip->frag, ip->where - branch_disp);
5000 add_fixed_insn (&delay);
5004 move_insn (&delay, ip->frag,
5005 ip->where - branch_disp + insn_length (ip));
5006 move_insn (ip, history[0].frag, history[0].where);
5010 insert_into_history (0, 1, &delay);
5015 /* If we have just completed an unconditional branch, clear the history. */
5016 if ((delayed_branch_p (&history[1]) && uncond_branch_p (&history[1]))
5017 || (compact_branch_p (&history[0]) && uncond_branch_p (&history[0])))
5021 mips_no_prev_insn ();
5023 for (i = 0; i < ARRAY_SIZE (history); i++)
5024 history[i].cleared_p = 1;
5027 /* We need to emit a label at the end of branch-likely macros. */
5028 if (emit_branch_likely_macro)
5030 emit_branch_likely_macro = FALSE;
5031 micromips_add_label ();
5034 /* We just output an insn, so the next one doesn't have a label. */
5035 mips_clear_insn_labels ();
5038 /* Forget that there was any previous instruction or label.
5039 When BRANCH is true, the branch history is also flushed. */
5042 mips_no_prev_insn (void)
5044 prev_nop_frag = NULL;
5045 insert_into_history (0, ARRAY_SIZE (history), NOP_INSN);
5046 mips_clear_insn_labels ();
5049 /* This function must be called before we emit something other than
5050 instructions. It is like mips_no_prev_insn except that it inserts
5051 any NOPS that might be needed by previous instructions. */
5054 mips_emit_delays (void)
5056 if (! mips_opts.noreorder)
5058 int nops = nops_for_insn (0, history, NULL);
5062 add_fixed_insn (NOP_INSN);
5063 mips_move_text_labels ();
5066 mips_no_prev_insn ();
5069 /* Start a (possibly nested) noreorder block. */
5072 start_noreorder (void)
5074 if (mips_opts.noreorder == 0)
5079 /* None of the instructions before the .set noreorder can be moved. */
5080 for (i = 0; i < ARRAY_SIZE (history); i++)
5081 history[i].fixed_p = 1;
5083 /* Insert any nops that might be needed between the .set noreorder
5084 block and the previous instructions. We will later remove any
5085 nops that turn out not to be needed. */
5086 nops = nops_for_insn (0, history, NULL);
5089 if (mips_optimize != 0)
5091 /* Record the frag which holds the nop instructions, so
5092 that we can remove them if we don't need them. */
5093 frag_grow (nops * NOP_INSN_SIZE);
5094 prev_nop_frag = frag_now;
5095 prev_nop_frag_holds = nops;
5096 prev_nop_frag_required = 0;
5097 prev_nop_frag_since = 0;
5100 for (; nops > 0; --nops)
5101 add_fixed_insn (NOP_INSN);
5103 /* Move on to a new frag, so that it is safe to simply
5104 decrease the size of prev_nop_frag. */
5105 frag_wane (frag_now);
5107 mips_move_text_labels ();
5109 mips_mark_labels ();
5110 mips_clear_insn_labels ();
5112 mips_opts.noreorder++;
5113 mips_any_noreorder = 1;
5116 /* End a nested noreorder block. */
5119 end_noreorder (void)
5121 mips_opts.noreorder--;
5122 if (mips_opts.noreorder == 0 && prev_nop_frag != NULL)
5124 /* Commit to inserting prev_nop_frag_required nops and go back to
5125 handling nop insertion the .set reorder way. */
5126 prev_nop_frag->fr_fix -= ((prev_nop_frag_holds - prev_nop_frag_required)
5128 insert_into_history (prev_nop_frag_since,
5129 prev_nop_frag_required, NOP_INSN);
5130 prev_nop_frag = NULL;
5134 /* Set up global variables for the start of a new macro. */
5139 memset (&mips_macro_warning.sizes, 0, sizeof (mips_macro_warning.sizes));
5140 memset (&mips_macro_warning.first_insn_sizes, 0,
5141 sizeof (mips_macro_warning.first_insn_sizes));
5142 memset (&mips_macro_warning.insns, 0, sizeof (mips_macro_warning.insns));
5143 mips_macro_warning.delay_slot_p = (mips_opts.noreorder
5144 && delayed_branch_p (&history[0]));
5145 switch (history[0].insn_mo->pinfo2
5146 & (INSN2_BRANCH_DELAY_32BIT | INSN2_BRANCH_DELAY_16BIT))
5148 case INSN2_BRANCH_DELAY_32BIT:
5149 mips_macro_warning.delay_slot_length = 4;
5151 case INSN2_BRANCH_DELAY_16BIT:
5152 mips_macro_warning.delay_slot_length = 2;
5155 mips_macro_warning.delay_slot_length = 0;
5158 mips_macro_warning.first_frag = NULL;
5161 /* Given that a macro is longer than one instruction or of the wrong size,
5162 return the appropriate warning for it. Return null if no warning is
5163 needed. SUBTYPE is a bitmask of RELAX_DELAY_SLOT, RELAX_DELAY_SLOT_16BIT,
5164 RELAX_DELAY_SLOT_SIZE_FIRST, RELAX_DELAY_SLOT_SIZE_SECOND,
5165 and RELAX_NOMACRO. */
5168 macro_warning (relax_substateT subtype)
5170 if (subtype & RELAX_DELAY_SLOT)
5171 return _("Macro instruction expanded into multiple instructions"
5172 " in a branch delay slot");
5173 else if (subtype & RELAX_NOMACRO)
5174 return _("Macro instruction expanded into multiple instructions");
5175 else if (subtype & (RELAX_DELAY_SLOT_SIZE_FIRST
5176 | RELAX_DELAY_SLOT_SIZE_SECOND))
5177 return ((subtype & RELAX_DELAY_SLOT_16BIT)
5178 ? _("Macro instruction expanded into a wrong size instruction"
5179 " in a 16-bit branch delay slot")
5180 : _("Macro instruction expanded into a wrong size instruction"
5181 " in a 32-bit branch delay slot"));
5186 /* Finish up a macro. Emit warnings as appropriate. */
5191 /* Relaxation warning flags. */
5192 relax_substateT subtype = 0;
5194 /* Check delay slot size requirements. */
5195 if (mips_macro_warning.delay_slot_length == 2)
5196 subtype |= RELAX_DELAY_SLOT_16BIT;
5197 if (mips_macro_warning.delay_slot_length != 0)
5199 if (mips_macro_warning.delay_slot_length
5200 != mips_macro_warning.first_insn_sizes[0])
5201 subtype |= RELAX_DELAY_SLOT_SIZE_FIRST;
5202 if (mips_macro_warning.delay_slot_length
5203 != mips_macro_warning.first_insn_sizes[1])
5204 subtype |= RELAX_DELAY_SLOT_SIZE_SECOND;
5207 /* Check instruction count requirements. */
5208 if (mips_macro_warning.insns[0] > 1 || mips_macro_warning.insns[1] > 1)
5210 if (mips_macro_warning.insns[1] > mips_macro_warning.insns[0])
5211 subtype |= RELAX_SECOND_LONGER;
5212 if (mips_opts.warn_about_macros)
5213 subtype |= RELAX_NOMACRO;
5214 if (mips_macro_warning.delay_slot_p)
5215 subtype |= RELAX_DELAY_SLOT;
5218 /* If both alternatives fail to fill a delay slot correctly,
5219 emit the warning now. */
5220 if ((subtype & RELAX_DELAY_SLOT_SIZE_FIRST) != 0
5221 && (subtype & RELAX_DELAY_SLOT_SIZE_SECOND) != 0)
5226 s = subtype & (RELAX_DELAY_SLOT_16BIT
5227 | RELAX_DELAY_SLOT_SIZE_FIRST
5228 | RELAX_DELAY_SLOT_SIZE_SECOND);
5229 msg = macro_warning (s);
5231 as_warn ("%s", msg);
5235 /* If both implementations are longer than 1 instruction, then emit the
5237 if (mips_macro_warning.insns[0] > 1 && mips_macro_warning.insns[1] > 1)
5242 s = subtype & (RELAX_SECOND_LONGER | RELAX_NOMACRO | RELAX_DELAY_SLOT);
5243 msg = macro_warning (s);
5245 as_warn ("%s", msg);
5249 /* If any flags still set, then one implementation might need a warning
5250 and the other either will need one of a different kind or none at all.
5251 Pass any remaining flags over to relaxation. */
5252 if (mips_macro_warning.first_frag != NULL)
5253 mips_macro_warning.first_frag->fr_subtype |= subtype;
5256 /* Instruction operand formats used in macros that vary between
5257 standard MIPS and microMIPS code. */
5259 static const char * const brk_fmt[2] = { "c", "mF" };
5260 static const char * const cop12_fmt[2] = { "E,o(b)", "E,~(b)" };
5261 static const char * const jalr_fmt[2] = { "d,s", "t,s" };
5262 static const char * const lui_fmt[2] = { "t,u", "s,u" };
5263 static const char * const mem12_fmt[2] = { "t,o(b)", "t,~(b)" };
5264 static const char * const mfhl_fmt[2] = { "d", "mj" };
5265 static const char * const shft_fmt[2] = { "d,w,<", "t,r,<" };
5266 static const char * const trap_fmt[2] = { "s,t,q", "s,t,|" };
5268 #define BRK_FMT (brk_fmt[mips_opts.micromips])
5269 #define COP12_FMT (cop12_fmt[mips_opts.micromips])
5270 #define JALR_FMT (jalr_fmt[mips_opts.micromips])
5271 #define LUI_FMT (lui_fmt[mips_opts.micromips])
5272 #define MEM12_FMT (mem12_fmt[mips_opts.micromips])
5273 #define MFHL_FMT (mfhl_fmt[mips_opts.micromips])
5274 #define SHFT_FMT (shft_fmt[mips_opts.micromips])
5275 #define TRAP_FMT (trap_fmt[mips_opts.micromips])
5277 /* Read a macro's relocation codes from *ARGS and store them in *R.
5278 The first argument in *ARGS will be either the code for a single
5279 relocation or -1 followed by the three codes that make up a
5280 composite relocation. */
5283 macro_read_relocs (va_list *args, bfd_reloc_code_real_type *r)
5287 next = va_arg (*args, int);
5289 r[0] = (bfd_reloc_code_real_type) next;
5291 for (i = 0; i < 3; i++)
5292 r[i] = (bfd_reloc_code_real_type) va_arg (*args, int);
5295 /* Build an instruction created by a macro expansion. This is passed
5296 a pointer to the count of instructions created so far, an
5297 expression, the name of the instruction to build, an operand format
5298 string, and corresponding arguments. */
5301 macro_build (expressionS *ep, const char *name, const char *fmt, ...)
5303 const struct mips_opcode *mo = NULL;
5304 bfd_reloc_code_real_type r[3];
5305 const struct mips_opcode *amo;
5306 struct hash_control *hash;
5307 struct mips_cl_insn insn;
5310 va_start (args, fmt);
5312 if (mips_opts.mips16)
5314 mips16_macro_build (ep, name, fmt, &args);
5319 r[0] = BFD_RELOC_UNUSED;
5320 r[1] = BFD_RELOC_UNUSED;
5321 r[2] = BFD_RELOC_UNUSED;
5322 hash = mips_opts.micromips ? micromips_op_hash : op_hash;
5323 amo = (struct mips_opcode *) hash_find (hash, name);
5325 gas_assert (strcmp (name, amo->name) == 0);
5329 /* Search until we get a match for NAME. It is assumed here that
5330 macros will never generate MDMX, MIPS-3D, or MT instructions.
5331 We try to match an instruction that fulfils the branch delay
5332 slot instruction length requirement (if any) of the previous
5333 instruction. While doing this we record the first instruction
5334 seen that matches all the other conditions and use it anyway
5335 if the requirement cannot be met; we will issue an appropriate
5336 warning later on. */
5337 if (strcmp (fmt, amo->args) == 0
5338 && amo->pinfo != INSN_MACRO
5339 && is_opcode_valid (amo)
5340 && is_size_valid (amo))
5342 if (is_delay_slot_valid (amo))
5352 gas_assert (amo->name);
5354 while (strcmp (name, amo->name) == 0);
5357 create_insn (&insn, mo);
5375 INSERT_OPERAND (mips_opts.micromips,
5376 EXTLSB, insn, va_arg (args, int));
5381 /* Note that in the macro case, these arguments are already
5382 in MSB form. (When handling the instruction in the
5383 non-macro case, these arguments are sizes from which
5384 MSB values must be calculated.) */
5385 INSERT_OPERAND (mips_opts.micromips,
5386 INSMSB, insn, va_arg (args, int));
5390 gas_assert (!mips_opts.micromips);
5391 INSERT_OPERAND (0, CODE10, insn, va_arg (args, int));
5397 /* Note that in the macro case, these arguments are already
5398 in MSBD form. (When handling the instruction in the
5399 non-macro case, these arguments are sizes from which
5400 MSBD values must be calculated.) */
5401 INSERT_OPERAND (mips_opts.micromips,
5402 EXTMSBD, insn, va_arg (args, int));
5406 gas_assert (!mips_opts.micromips);
5407 INSERT_OPERAND (0, SEQI, insn, va_arg (args, int));
5411 INSERT_OPERAND (mips_opts.micromips, EVAOFFSET, insn, va_arg (args, int));
5420 INSERT_OPERAND (mips_opts.micromips, BP, insn, va_arg (args, int));
5424 gas_assert (mips_opts.micromips);
5428 INSERT_OPERAND (mips_opts.micromips, RT, insn, va_arg (args, int));
5432 gas_assert (!mips_opts.micromips);
5433 INSERT_OPERAND (0, CODE, insn, va_arg (args, int));
5437 gas_assert (!mips_opts.micromips);
5439 INSERT_OPERAND (mips_opts.micromips, FT, insn, va_arg (args, int));
5443 if (mips_opts.micromips)
5444 INSERT_OPERAND (1, RS, insn, va_arg (args, int));
5446 INSERT_OPERAND (0, RD, insn, va_arg (args, int));
5450 gas_assert (!mips_opts.micromips);
5452 INSERT_OPERAND (mips_opts.micromips, RD, insn, va_arg (args, int));
5456 gas_assert (!mips_opts.micromips);
5458 int tmp = va_arg (args, int);
5460 INSERT_OPERAND (0, RT, insn, tmp);
5461 INSERT_OPERAND (0, RD, insn, tmp);
5467 gas_assert (!mips_opts.micromips);
5468 INSERT_OPERAND (0, FS, insn, va_arg (args, int));
5475 INSERT_OPERAND (mips_opts.micromips,
5476 SHAMT, insn, va_arg (args, int));
5480 gas_assert (!mips_opts.micromips);
5481 INSERT_OPERAND (0, FD, insn, va_arg (args, int));
5485 gas_assert (!mips_opts.micromips);
5486 INSERT_OPERAND (0, CODE20, insn, va_arg (args, int));
5490 gas_assert (!mips_opts.micromips);
5491 INSERT_OPERAND (0, CODE19, insn, va_arg (args, int));
5495 gas_assert (!mips_opts.micromips);
5496 INSERT_OPERAND (0, CODE2, insn, va_arg (args, int));
5503 INSERT_OPERAND (mips_opts.micromips, RS, insn, va_arg (args, int));
5508 macro_read_relocs (&args, r);
5509 gas_assert (*r == BFD_RELOC_GPREL16
5510 || *r == BFD_RELOC_MIPS_HIGHER
5511 || *r == BFD_RELOC_HI16_S
5512 || *r == BFD_RELOC_LO16
5513 || *r == BFD_RELOC_MIPS_GOT_OFST);
5517 macro_read_relocs (&args, r);
5521 macro_read_relocs (&args, r);
5522 gas_assert (ep != NULL
5523 && (ep->X_op == O_constant
5524 || (ep->X_op == O_symbol
5525 && (*r == BFD_RELOC_MIPS_HIGHEST
5526 || *r == BFD_RELOC_HI16_S
5527 || *r == BFD_RELOC_HI16
5528 || *r == BFD_RELOC_GPREL16
5529 || *r == BFD_RELOC_MIPS_GOT_HI16
5530 || *r == BFD_RELOC_MIPS_CALL_HI16))));
5534 gas_assert (ep != NULL);
5537 * This allows macro() to pass an immediate expression for
5538 * creating short branches without creating a symbol.
5540 * We don't allow branch relaxation for these branches, as
5541 * they should only appear in ".set nomacro" anyway.
5543 if (ep->X_op == O_constant)
5545 /* For microMIPS we always use relocations for branches.
5546 So we should not resolve immediate values. */
5547 gas_assert (!mips_opts.micromips);
5549 if ((ep->X_add_number & 3) != 0)
5550 as_bad (_("branch to misaligned address (0x%lx)"),
5551 (unsigned long) ep->X_add_number);
5552 if ((ep->X_add_number + 0x20000) & ~0x3ffff)
5553 as_bad (_("branch address range overflow (0x%lx)"),
5554 (unsigned long) ep->X_add_number);
5555 insn.insn_opcode |= (ep->X_add_number >> 2) & 0xffff;
5559 *r = BFD_RELOC_16_PCREL_S2;
5563 gas_assert (ep != NULL);
5564 *r = BFD_RELOC_MIPS_JMP;
5568 gas_assert (!mips_opts.micromips);
5569 INSERT_OPERAND (0, COPZ, insn, va_arg (args, unsigned long));
5573 INSERT_OPERAND (mips_opts.micromips,
5574 CACHE, insn, va_arg (args, unsigned long));
5578 gas_assert (mips_opts.micromips);
5579 INSERT_OPERAND (1, TRAP, insn, va_arg (args, int));
5583 gas_assert (mips_opts.micromips);
5584 INSERT_OPERAND (1, OFFSET10, insn, va_arg (args, int));
5588 INSERT_OPERAND (mips_opts.micromips,
5589 3BITPOS, insn, va_arg (args, unsigned int));
5593 INSERT_OPERAND (mips_opts.micromips,
5594 OFFSET12, insn, va_arg (args, unsigned long));
5598 gas_assert (mips_opts.micromips);
5599 INSERT_OPERAND (1, BCC, insn, va_arg (args, int));
5602 case 'm': /* Opcode extension character. */
5603 gas_assert (mips_opts.micromips);
5607 INSERT_OPERAND (1, MJ, insn, va_arg (args, int));
5611 INSERT_OPERAND (1, MP, insn, va_arg (args, int));
5615 INSERT_OPERAND (1, IMMF, insn, va_arg (args, int));
5629 gas_assert (*r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL);
5631 append_insn (&insn, ep, r, TRUE);
5635 mips16_macro_build (expressionS *ep, const char *name, const char *fmt,
5638 struct mips_opcode *mo;
5639 struct mips_cl_insn insn;
5640 bfd_reloc_code_real_type r[3]
5641 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
5643 mo = (struct mips_opcode *) hash_find (mips16_op_hash, name);
5645 gas_assert (strcmp (name, mo->name) == 0);
5647 while (strcmp (fmt, mo->args) != 0 || mo->pinfo == INSN_MACRO)
5650 gas_assert (mo->name);
5651 gas_assert (strcmp (name, mo->name) == 0);
5654 create_insn (&insn, mo);
5672 MIPS16_INSERT_OPERAND (RY, insn, va_arg (*args, int));
5677 MIPS16_INSERT_OPERAND (RX, insn, va_arg (*args, int));
5681 MIPS16_INSERT_OPERAND (RZ, insn, va_arg (*args, int));
5685 MIPS16_INSERT_OPERAND (MOVE32Z, insn, va_arg (*args, int));
5695 MIPS16_INSERT_OPERAND (REGR32, insn, va_arg (*args, int));
5702 regno = va_arg (*args, int);
5703 regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3);
5704 MIPS16_INSERT_OPERAND (REG32R, insn, regno);
5727 gas_assert (ep != NULL);
5729 if (ep->X_op != O_constant)
5730 *r = (int) BFD_RELOC_UNUSED + c;
5731 else if (calculate_reloc (*r, ep->X_add_number, &value))
5733 mips16_immed (NULL, 0, c, *r, value, 0, &insn.insn_opcode);
5735 *r = BFD_RELOC_UNUSED;
5741 MIPS16_INSERT_OPERAND (IMM6, insn, va_arg (*args, int));
5748 gas_assert (*r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL);
5750 append_insn (&insn, ep, r, TRUE);
5754 * Sign-extend 32-bit mode constants that have bit 31 set and all
5755 * higher bits unset.
5758 normalize_constant_expr (expressionS *ex)
5760 if (ex->X_op == O_constant
5761 && IS_ZEXT_32BIT_NUM (ex->X_add_number))
5762 ex->X_add_number = (((ex->X_add_number & 0xffffffff) ^ 0x80000000)
5767 * Sign-extend 32-bit mode address offsets that have bit 31 set and
5768 * all higher bits unset.
5771 normalize_address_expr (expressionS *ex)
5773 if (((ex->X_op == O_constant && HAVE_32BIT_ADDRESSES)
5774 || (ex->X_op == O_symbol && HAVE_32BIT_SYMBOLS))
5775 && IS_ZEXT_32BIT_NUM (ex->X_add_number))
5776 ex->X_add_number = (((ex->X_add_number & 0xffffffff) ^ 0x80000000)
5781 * Generate a "jalr" instruction with a relocation hint to the called
5782 * function. This occurs in NewABI PIC code.
5785 macro_build_jalr (expressionS *ep, int cprestore)
5787 static const bfd_reloc_code_real_type jalr_relocs[2]
5788 = { BFD_RELOC_MIPS_JALR, BFD_RELOC_MICROMIPS_JALR };
5789 bfd_reloc_code_real_type jalr_reloc = jalr_relocs[mips_opts.micromips];
5793 if (MIPS_JALR_HINT_P (ep))
5798 if (mips_opts.micromips)
5800 jalr = mips_opts.noreorder && !cprestore ? "jalr" : "jalrs";
5801 if (MIPS_JALR_HINT_P (ep)
5802 || (history[0].insn_mo->pinfo2 & INSN2_BRANCH_DELAY_32BIT))
5803 macro_build (NULL, jalr, "t,s", RA, PIC_CALL_REG);
5805 macro_build (NULL, jalr, "mj", PIC_CALL_REG);
5808 macro_build (NULL, "jalr", "d,s", RA, PIC_CALL_REG);
5809 if (MIPS_JALR_HINT_P (ep))
5810 fix_new_exp (frag_now, f - frag_now->fr_literal, 4, ep, FALSE, jalr_reloc);
5814 * Generate a "lui" instruction.
5817 macro_build_lui (expressionS *ep, int regnum)
5819 gas_assert (! mips_opts.mips16);
5821 if (ep->X_op != O_constant)
5823 gas_assert (ep->X_op == O_symbol);
5824 /* _gp_disp is a special case, used from s_cpload.
5825 __gnu_local_gp is used if mips_no_shared. */
5826 gas_assert (mips_pic == NO_PIC
5828 && strcmp (S_GET_NAME (ep->X_add_symbol), "_gp_disp") == 0)
5829 || (! mips_in_shared
5830 && strcmp (S_GET_NAME (ep->X_add_symbol),
5831 "__gnu_local_gp") == 0));
5834 macro_build (ep, "lui", LUI_FMT, regnum, BFD_RELOC_HI16_S);
5837 /* Generate a sequence of instructions to do a load or store from a constant
5838 offset off of a base register (breg) into/from a target register (treg),
5839 using AT if necessary. */
5841 macro_build_ldst_constoffset (expressionS *ep, const char *op,
5842 int treg, int breg, int dbl)
5844 gas_assert (ep->X_op == O_constant);
5846 /* Sign-extending 32-bit constants makes their handling easier. */
5848 normalize_constant_expr (ep);
5850 /* Right now, this routine can only handle signed 32-bit constants. */
5851 if (! IS_SEXT_32BIT_NUM(ep->X_add_number + 0x8000))
5852 as_warn (_("operand overflow"));
5854 if (IS_SEXT_16BIT_NUM(ep->X_add_number))
5856 /* Signed 16-bit offset will fit in the op. Easy! */
5857 macro_build (ep, op, "t,o(b)", treg, BFD_RELOC_LO16, breg);
5861 /* 32-bit offset, need multiple instructions and AT, like:
5862 lui $tempreg,const_hi (BFD_RELOC_HI16_S)
5863 addu $tempreg,$tempreg,$breg
5864 <op> $treg,const_lo($tempreg) (BFD_RELOC_LO16)
5865 to handle the complete offset. */
5866 macro_build_lui (ep, AT);
5867 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, AT, breg);
5868 macro_build (ep, op, "t,o(b)", treg, BFD_RELOC_LO16, AT);
5871 as_bad (_("Macro used $at after \".set noat\""));
5876 * Generates code to set the $at register to true (one)
5877 * if reg is less than the immediate expression.
5880 set_at (int reg, int unsignedp)
5882 if (imm_expr.X_op == O_constant
5883 && imm_expr.X_add_number >= -0x8000
5884 && imm_expr.X_add_number < 0x8000)
5885 macro_build (&imm_expr, unsignedp ? "sltiu" : "slti", "t,r,j",
5886 AT, reg, BFD_RELOC_LO16);
5889 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
5890 macro_build (NULL, unsignedp ? "sltu" : "slt", "d,v,t", AT, reg, AT);
5894 /* Warn if an expression is not a constant. */
5897 check_absolute_expr (struct mips_cl_insn *ip, expressionS *ex)
5899 if (ex->X_op == O_big)
5900 as_bad (_("unsupported large constant"));
5901 else if (ex->X_op != O_constant)
5902 as_bad (_("Instruction %s requires absolute expression"),
5905 if (HAVE_32BIT_GPRS)
5906 normalize_constant_expr (ex);
5909 /* Count the leading zeroes by performing a binary chop. This is a
5910 bulky bit of source, but performance is a LOT better for the
5911 majority of values than a simple loop to count the bits:
5912 for (lcnt = 0; (lcnt < 32); lcnt++)
5913 if ((v) & (1 << (31 - lcnt)))
5915 However it is not code size friendly, and the gain will drop a bit
5916 on certain cached systems.
5918 #define COUNT_TOP_ZEROES(v) \
5919 (((v) & ~0xffff) == 0 \
5920 ? ((v) & ~0xff) == 0 \
5921 ? ((v) & ~0xf) == 0 \
5922 ? ((v) & ~0x3) == 0 \
5923 ? ((v) & ~0x1) == 0 \
5928 : ((v) & ~0x7) == 0 \
5931 : ((v) & ~0x3f) == 0 \
5932 ? ((v) & ~0x1f) == 0 \
5935 : ((v) & ~0x7f) == 0 \
5938 : ((v) & ~0xfff) == 0 \
5939 ? ((v) & ~0x3ff) == 0 \
5940 ? ((v) & ~0x1ff) == 0 \
5943 : ((v) & ~0x7ff) == 0 \
5946 : ((v) & ~0x3fff) == 0 \
5947 ? ((v) & ~0x1fff) == 0 \
5950 : ((v) & ~0x7fff) == 0 \
5953 : ((v) & ~0xffffff) == 0 \
5954 ? ((v) & ~0xfffff) == 0 \
5955 ? ((v) & ~0x3ffff) == 0 \
5956 ? ((v) & ~0x1ffff) == 0 \
5959 : ((v) & ~0x7ffff) == 0 \
5962 : ((v) & ~0x3fffff) == 0 \
5963 ? ((v) & ~0x1fffff) == 0 \
5966 : ((v) & ~0x7fffff) == 0 \
5969 : ((v) & ~0xfffffff) == 0 \
5970 ? ((v) & ~0x3ffffff) == 0 \
5971 ? ((v) & ~0x1ffffff) == 0 \
5974 : ((v) & ~0x7ffffff) == 0 \
5977 : ((v) & ~0x3fffffff) == 0 \
5978 ? ((v) & ~0x1fffffff) == 0 \
5981 : ((v) & ~0x7fffffff) == 0 \
5986 * This routine generates the least number of instructions necessary to load
5987 * an absolute expression value into a register.
5990 load_register (int reg, expressionS *ep, int dbl)
5993 expressionS hi32, lo32;
5995 if (ep->X_op != O_big)
5997 gas_assert (ep->X_op == O_constant);
5999 /* Sign-extending 32-bit constants makes their handling easier. */
6001 normalize_constant_expr (ep);
6003 if (IS_SEXT_16BIT_NUM (ep->X_add_number))
6005 /* We can handle 16 bit signed values with an addiu to
6006 $zero. No need to ever use daddiu here, since $zero and
6007 the result are always correct in 32 bit mode. */
6008 macro_build (ep, "addiu", "t,r,j", reg, 0, BFD_RELOC_LO16);
6011 else if (ep->X_add_number >= 0 && ep->X_add_number < 0x10000)
6013 /* We can handle 16 bit unsigned values with an ori to
6015 macro_build (ep, "ori", "t,r,i", reg, 0, BFD_RELOC_LO16);
6018 else if ((IS_SEXT_32BIT_NUM (ep->X_add_number)))
6020 /* 32 bit values require an lui. */
6021 macro_build (ep, "lui", LUI_FMT, reg, BFD_RELOC_HI16);
6022 if ((ep->X_add_number & 0xffff) != 0)
6023 macro_build (ep, "ori", "t,r,i", reg, reg, BFD_RELOC_LO16);
6028 /* The value is larger than 32 bits. */
6030 if (!dbl || HAVE_32BIT_GPRS)
6034 sprintf_vma (value, ep->X_add_number);
6035 as_bad (_("Number (0x%s) larger than 32 bits"), value);
6036 macro_build (ep, "addiu", "t,r,j", reg, 0, BFD_RELOC_LO16);
6040 if (ep->X_op != O_big)
6043 hi32.X_add_number = (valueT) hi32.X_add_number >> 16;
6044 hi32.X_add_number = (valueT) hi32.X_add_number >> 16;
6045 hi32.X_add_number &= 0xffffffff;
6047 lo32.X_add_number &= 0xffffffff;
6051 gas_assert (ep->X_add_number > 2);
6052 if (ep->X_add_number == 3)
6053 generic_bignum[3] = 0;
6054 else if (ep->X_add_number > 4)
6055 as_bad (_("Number larger than 64 bits"));
6056 lo32.X_op = O_constant;
6057 lo32.X_add_number = generic_bignum[0] + (generic_bignum[1] << 16);
6058 hi32.X_op = O_constant;
6059 hi32.X_add_number = generic_bignum[2] + (generic_bignum[3] << 16);
6062 if (hi32.X_add_number == 0)
6067 unsigned long hi, lo;
6069 if (hi32.X_add_number == (offsetT) 0xffffffff)
6071 if ((lo32.X_add_number & 0xffff8000) == 0xffff8000)
6073 macro_build (&lo32, "addiu", "t,r,j", reg, 0, BFD_RELOC_LO16);
6076 if (lo32.X_add_number & 0x80000000)
6078 macro_build (&lo32, "lui", LUI_FMT, reg, BFD_RELOC_HI16);
6079 if (lo32.X_add_number & 0xffff)
6080 macro_build (&lo32, "ori", "t,r,i", reg, reg, BFD_RELOC_LO16);
6085 /* Check for 16bit shifted constant. We know that hi32 is
6086 non-zero, so start the mask on the first bit of the hi32
6091 unsigned long himask, lomask;
6095 himask = 0xffff >> (32 - shift);
6096 lomask = (0xffff << shift) & 0xffffffff;
6100 himask = 0xffff << (shift - 32);
6103 if ((hi32.X_add_number & ~(offsetT) himask) == 0
6104 && (lo32.X_add_number & ~(offsetT) lomask) == 0)
6108 tmp.X_op = O_constant;
6110 tmp.X_add_number = ((hi32.X_add_number << (32 - shift))
6111 | (lo32.X_add_number >> shift));
6113 tmp.X_add_number = hi32.X_add_number >> (shift - 32);
6114 macro_build (&tmp, "ori", "t,r,i", reg, 0, BFD_RELOC_LO16);
6115 macro_build (NULL, (shift >= 32) ? "dsll32" : "dsll", SHFT_FMT,
6116 reg, reg, (shift >= 32) ? shift - 32 : shift);
6121 while (shift <= (64 - 16));
6123 /* Find the bit number of the lowest one bit, and store the
6124 shifted value in hi/lo. */
6125 hi = (unsigned long) (hi32.X_add_number & 0xffffffff);
6126 lo = (unsigned long) (lo32.X_add_number & 0xffffffff);
6130 while ((lo & 1) == 0)
6135 lo |= (hi & (((unsigned long) 1 << bit) - 1)) << (32 - bit);
6141 while ((hi & 1) == 0)
6150 /* Optimize if the shifted value is a (power of 2) - 1. */
6151 if ((hi == 0 && ((lo + 1) & lo) == 0)
6152 || (lo == 0xffffffff && ((hi + 1) & hi) == 0))
6154 shift = COUNT_TOP_ZEROES ((unsigned int) hi32.X_add_number);
6159 /* This instruction will set the register to be all
6161 tmp.X_op = O_constant;
6162 tmp.X_add_number = (offsetT) -1;
6163 macro_build (&tmp, "addiu", "t,r,j", reg, 0, BFD_RELOC_LO16);
6167 macro_build (NULL, (bit >= 32) ? "dsll32" : "dsll", SHFT_FMT,
6168 reg, reg, (bit >= 32) ? bit - 32 : bit);
6170 macro_build (NULL, (shift >= 32) ? "dsrl32" : "dsrl", SHFT_FMT,
6171 reg, reg, (shift >= 32) ? shift - 32 : shift);
6176 /* Sign extend hi32 before calling load_register, because we can
6177 generally get better code when we load a sign extended value. */
6178 if ((hi32.X_add_number & 0x80000000) != 0)
6179 hi32.X_add_number |= ~(offsetT) 0xffffffff;
6180 load_register (reg, &hi32, 0);
6183 if ((lo32.X_add_number & 0xffff0000) == 0)
6187 macro_build (NULL, "dsll32", SHFT_FMT, reg, freg, 0);
6195 if ((freg == 0) && (lo32.X_add_number == (offsetT) 0xffffffff))
6197 macro_build (&lo32, "lui", LUI_FMT, reg, BFD_RELOC_HI16);
6198 macro_build (NULL, "dsrl32", SHFT_FMT, reg, reg, 0);
6204 macro_build (NULL, "dsll", SHFT_FMT, reg, freg, 16);
6208 mid16.X_add_number >>= 16;
6209 macro_build (&mid16, "ori", "t,r,i", reg, freg, BFD_RELOC_LO16);
6210 macro_build (NULL, "dsll", SHFT_FMT, reg, reg, 16);
6213 if ((lo32.X_add_number & 0xffff) != 0)
6214 macro_build (&lo32, "ori", "t,r,i", reg, freg, BFD_RELOC_LO16);
6218 load_delay_nop (void)
6220 if (!gpr_interlocks)
6221 macro_build (NULL, "nop", "");
6224 /* Load an address into a register. */
6227 load_address (int reg, expressionS *ep, int *used_at)
6229 if (ep->X_op != O_constant
6230 && ep->X_op != O_symbol)
6232 as_bad (_("expression too complex"));
6233 ep->X_op = O_constant;
6236 if (ep->X_op == O_constant)
6238 load_register (reg, ep, HAVE_64BIT_ADDRESSES);
6242 if (mips_pic == NO_PIC)
6244 /* If this is a reference to a GP relative symbol, we want
6245 addiu $reg,$gp,<sym> (BFD_RELOC_GPREL16)
6247 lui $reg,<sym> (BFD_RELOC_HI16_S)
6248 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
6249 If we have an addend, we always use the latter form.
6251 With 64bit address space and a usable $at we want
6252 lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST)
6253 lui $at,<sym> (BFD_RELOC_HI16_S)
6254 daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER)
6255 daddiu $at,<sym> (BFD_RELOC_LO16)
6259 If $at is already in use, we use a path which is suboptimal
6260 on superscalar processors.
6261 lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST)
6262 daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER)
6264 daddiu $reg,<sym> (BFD_RELOC_HI16_S)
6266 daddiu $reg,<sym> (BFD_RELOC_LO16)
6268 For GP relative symbols in 64bit address space we can use
6269 the same sequence as in 32bit address space. */
6270 if (HAVE_64BIT_SYMBOLS)
6272 if ((valueT) ep->X_add_number <= MAX_GPREL_OFFSET
6273 && !nopic_need_relax (ep->X_add_symbol, 1))
6275 relax_start (ep->X_add_symbol);
6276 macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", reg,
6277 mips_gp_register, BFD_RELOC_GPREL16);
6281 if (*used_at == 0 && mips_opts.at)
6283 macro_build (ep, "lui", LUI_FMT, reg, BFD_RELOC_MIPS_HIGHEST);
6284 macro_build (ep, "lui", LUI_FMT, AT, BFD_RELOC_HI16_S);
6285 macro_build (ep, "daddiu", "t,r,j", reg, reg,
6286 BFD_RELOC_MIPS_HIGHER);
6287 macro_build (ep, "daddiu", "t,r,j", AT, AT, BFD_RELOC_LO16);
6288 macro_build (NULL, "dsll32", SHFT_FMT, reg, reg, 0);
6289 macro_build (NULL, "daddu", "d,v,t", reg, reg, AT);
6294 macro_build (ep, "lui", LUI_FMT, reg, BFD_RELOC_MIPS_HIGHEST);
6295 macro_build (ep, "daddiu", "t,r,j", reg, reg,
6296 BFD_RELOC_MIPS_HIGHER);
6297 macro_build (NULL, "dsll", SHFT_FMT, reg, reg, 16);
6298 macro_build (ep, "daddiu", "t,r,j", reg, reg, BFD_RELOC_HI16_S);
6299 macro_build (NULL, "dsll", SHFT_FMT, reg, reg, 16);
6300 macro_build (ep, "daddiu", "t,r,j", reg, reg, BFD_RELOC_LO16);
6303 if (mips_relax.sequence)
6308 if ((valueT) ep->X_add_number <= MAX_GPREL_OFFSET
6309 && !nopic_need_relax (ep->X_add_symbol, 1))
6311 relax_start (ep->X_add_symbol);
6312 macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", reg,
6313 mips_gp_register, BFD_RELOC_GPREL16);
6316 macro_build_lui (ep, reg);
6317 macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j",
6318 reg, reg, BFD_RELOC_LO16);
6319 if (mips_relax.sequence)
6323 else if (!mips_big_got)
6327 /* If this is a reference to an external symbol, we want
6328 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6330 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6332 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
6333 If there is a constant, it must be added in after.
6335 If we have NewABI, we want
6336 lw $reg,<sym+cst>($gp) (BFD_RELOC_MIPS_GOT_DISP)
6337 unless we're referencing a global symbol with a non-zero
6338 offset, in which case cst must be added separately. */
6341 if (ep->X_add_number)
6343 ex.X_add_number = ep->X_add_number;
6344 ep->X_add_number = 0;
6345 relax_start (ep->X_add_symbol);
6346 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
6347 BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
6348 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
6349 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6350 ex.X_op = O_constant;
6351 macro_build (&ex, ADDRESS_ADDI_INSN, "t,r,j",
6352 reg, reg, BFD_RELOC_LO16);
6353 ep->X_add_number = ex.X_add_number;
6356 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
6357 BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
6358 if (mips_relax.sequence)
6363 ex.X_add_number = ep->X_add_number;
6364 ep->X_add_number = 0;
6365 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
6366 BFD_RELOC_MIPS_GOT16, mips_gp_register);
6368 relax_start (ep->X_add_symbol);
6370 macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", reg, reg,
6374 if (ex.X_add_number != 0)
6376 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
6377 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6378 ex.X_op = O_constant;
6379 macro_build (&ex, ADDRESS_ADDI_INSN, "t,r,j",
6380 reg, reg, BFD_RELOC_LO16);
6384 else if (mips_big_got)
6388 /* This is the large GOT case. If this is a reference to an
6389 external symbol, we want
6390 lui $reg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
6392 lw $reg,<sym>($reg) (BFD_RELOC_MIPS_GOT_LO16)
6394 Otherwise, for a reference to a local symbol in old ABI, we want
6395 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6397 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
6398 If there is a constant, it must be added in after.
6400 In the NewABI, for local symbols, with or without offsets, we want:
6401 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
6402 addiu $reg,$reg,<sym> (BFD_RELOC_MIPS_GOT_OFST)
6406 ex.X_add_number = ep->X_add_number;
6407 ep->X_add_number = 0;
6408 relax_start (ep->X_add_symbol);
6409 macro_build (ep, "lui", LUI_FMT, reg, BFD_RELOC_MIPS_GOT_HI16);
6410 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
6411 reg, reg, mips_gp_register);
6412 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)",
6413 reg, BFD_RELOC_MIPS_GOT_LO16, reg);
6414 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
6415 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6416 else if (ex.X_add_number)
6418 ex.X_op = O_constant;
6419 macro_build (&ex, ADDRESS_ADDI_INSN, "t,r,j", reg, reg,
6423 ep->X_add_number = ex.X_add_number;
6425 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
6426 BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register);
6427 macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", reg, reg,
6428 BFD_RELOC_MIPS_GOT_OFST);
6433 ex.X_add_number = ep->X_add_number;
6434 ep->X_add_number = 0;
6435 relax_start (ep->X_add_symbol);
6436 macro_build (ep, "lui", LUI_FMT, reg, BFD_RELOC_MIPS_GOT_HI16);
6437 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
6438 reg, reg, mips_gp_register);
6439 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)",
6440 reg, BFD_RELOC_MIPS_GOT_LO16, reg);
6442 if (reg_needs_delay (mips_gp_register))
6444 /* We need a nop before loading from $gp. This special
6445 check is required because the lui which starts the main
6446 instruction stream does not refer to $gp, and so will not
6447 insert the nop which may be required. */
6448 macro_build (NULL, "nop", "");
6450 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
6451 BFD_RELOC_MIPS_GOT16, mips_gp_register);
6453 macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", reg, reg,
6457 if (ex.X_add_number != 0)
6459 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
6460 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6461 ex.X_op = O_constant;
6462 macro_build (&ex, ADDRESS_ADDI_INSN, "t,r,j", reg, reg,
6470 if (!mips_opts.at && *used_at == 1)
6471 as_bad (_("Macro used $at after \".set noat\""));
6474 /* Move the contents of register SOURCE into register DEST. */
6477 move_register (int dest, int source)
6479 /* Prefer to use a 16-bit microMIPS instruction unless the previous
6480 instruction specifically requires a 32-bit one. */
6481 if (mips_opts.micromips
6482 && !(history[0].insn_mo->pinfo2 & INSN2_BRANCH_DELAY_32BIT))
6483 macro_build (NULL, "move", "mp,mj", dest, source);
6485 macro_build (NULL, HAVE_32BIT_GPRS ? "addu" : "daddu", "d,v,t",
6489 /* Emit an SVR4 PIC sequence to load address LOCAL into DEST, where
6490 LOCAL is the sum of a symbol and a 16-bit or 32-bit displacement.
6491 The two alternatives are:
6493 Global symbol Local sybmol
6494 ------------- ------------
6495 lw DEST,%got(SYMBOL) lw DEST,%got(SYMBOL + OFFSET)
6497 addiu DEST,DEST,OFFSET addiu DEST,DEST,%lo(SYMBOL + OFFSET)
6499 load_got_offset emits the first instruction and add_got_offset
6500 emits the second for a 16-bit offset or add_got_offset_hilo emits
6501 a sequence to add a 32-bit offset using a scratch register. */
6504 load_got_offset (int dest, expressionS *local)
6509 global.X_add_number = 0;
6511 relax_start (local->X_add_symbol);
6512 macro_build (&global, ADDRESS_LOAD_INSN, "t,o(b)", dest,
6513 BFD_RELOC_MIPS_GOT16, mips_gp_register);
6515 macro_build (local, ADDRESS_LOAD_INSN, "t,o(b)", dest,
6516 BFD_RELOC_MIPS_GOT16, mips_gp_register);
6521 add_got_offset (int dest, expressionS *local)
6525 global.X_op = O_constant;
6526 global.X_op_symbol = NULL;
6527 global.X_add_symbol = NULL;
6528 global.X_add_number = local->X_add_number;
6530 relax_start (local->X_add_symbol);
6531 macro_build (&global, ADDRESS_ADDI_INSN, "t,r,j",
6532 dest, dest, BFD_RELOC_LO16);
6534 macro_build (local, ADDRESS_ADDI_INSN, "t,r,j", dest, dest, BFD_RELOC_LO16);
6539 add_got_offset_hilo (int dest, expressionS *local, int tmp)
6542 int hold_mips_optimize;
6544 global.X_op = O_constant;
6545 global.X_op_symbol = NULL;
6546 global.X_add_symbol = NULL;
6547 global.X_add_number = local->X_add_number;
6549 relax_start (local->X_add_symbol);
6550 load_register (tmp, &global, HAVE_64BIT_ADDRESSES);
6552 /* Set mips_optimize around the lui instruction to avoid
6553 inserting an unnecessary nop after the lw. */
6554 hold_mips_optimize = mips_optimize;
6556 macro_build_lui (&global, tmp);
6557 mips_optimize = hold_mips_optimize;
6558 macro_build (local, ADDRESS_ADDI_INSN, "t,r,j", tmp, tmp, BFD_RELOC_LO16);
6561 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", dest, dest, tmp);
6564 /* Emit a sequence of instructions to emulate a branch likely operation.
6565 BR is an ordinary branch corresponding to one to be emulated. BRNEG
6566 is its complementing branch with the original condition negated.
6567 CALL is set if the original branch specified the link operation.
6568 EP, FMT, SREG and TREG specify the usual macro_build() parameters.
6570 Code like this is produced in the noreorder mode:
6575 delay slot (executed only if branch taken)
6583 delay slot (executed only if branch taken)
6586 In the reorder mode the delay slot would be filled with a nop anyway,
6587 so code produced is simply:
6592 This function is used when producing code for the microMIPS ASE that
6593 does not implement branch likely instructions in hardware. */
6596 macro_build_branch_likely (const char *br, const char *brneg,
6597 int call, expressionS *ep, const char *fmt,
6598 unsigned int sreg, unsigned int treg)
6600 int noreorder = mips_opts.noreorder;
6603 gas_assert (mips_opts.micromips);
6607 micromips_label_expr (&expr1);
6608 macro_build (&expr1, brneg, fmt, sreg, treg);
6609 macro_build (NULL, "nop", "");
6610 macro_build (ep, call ? "bal" : "b", "p");
6612 /* Set to true so that append_insn adds a label. */
6613 emit_branch_likely_macro = TRUE;
6617 macro_build (ep, br, fmt, sreg, treg);
6618 macro_build (NULL, "nop", "");
6623 /* Emit a coprocessor branch-likely macro specified by TYPE, using CC as
6624 the condition code tested. EP specifies the branch target. */
6627 macro_build_branch_ccl (int type, expressionS *ep, unsigned int cc)
6654 macro_build_branch_likely (br, brneg, call, ep, "N,p", cc, ZERO);
6657 /* Emit a two-argument branch macro specified by TYPE, using SREG as
6658 the register tested. EP specifies the branch target. */
6661 macro_build_branch_rs (int type, expressionS *ep, unsigned int sreg)
6663 const char *brneg = NULL;
6673 br = mips_opts.micromips ? "bgez" : "bgezl";
6677 gas_assert (mips_opts.micromips);
6686 br = mips_opts.micromips ? "bgtz" : "bgtzl";
6693 br = mips_opts.micromips ? "blez" : "blezl";
6700 br = mips_opts.micromips ? "bltz" : "bltzl";
6704 gas_assert (mips_opts.micromips);
6712 if (mips_opts.micromips && brneg)
6713 macro_build_branch_likely (br, brneg, call, ep, "s,p", sreg, ZERO);
6715 macro_build (ep, br, "s,p", sreg);
6718 /* Emit a three-argument branch macro specified by TYPE, using SREG and
6719 TREG as the registers tested. EP specifies the branch target. */
6722 macro_build_branch_rsrt (int type, expressionS *ep,
6723 unsigned int sreg, unsigned int treg)
6725 const char *brneg = NULL;
6737 br = mips_opts.micromips ? "beq" : "beql";
6746 br = mips_opts.micromips ? "bne" : "bnel";
6752 if (mips_opts.micromips && brneg)
6753 macro_build_branch_likely (br, brneg, call, ep, "s,t,p", sreg, treg);
6755 macro_build (ep, br, "s,t,p", sreg, treg);
6760 * This routine implements the seemingly endless macro or synthesized
6761 * instructions and addressing modes in the mips assembly language. Many
6762 * of these macros are simple and are similar to each other. These could
6763 * probably be handled by some kind of table or grammar approach instead of
6764 * this verbose method. Others are not simple macros but are more like
6765 * optimizing code generation.
6766 * One interesting optimization is when several store macros appear
6767 * consecutively that would load AT with the upper half of the same address.
6768 * The ensuing load upper instructions are ommited. This implies some kind
6769 * of global optimization. We currently only optimize within a single macro.
6770 * For many of the load and store macros if the address is specified as a
6771 * constant expression in the first 64k of memory (ie ld $2,0x4000c) we
6772 * first load register 'at' with zero and use it as the base register. The
6773 * mips assembler simply uses register $zero. Just one tiny optimization
6777 macro (struct mips_cl_insn *ip)
6779 unsigned int treg, sreg, dreg, breg;
6780 unsigned int tempreg;
6783 expressionS label_expr;
6801 bfd_reloc_code_real_type r;
6802 int hold_mips_optimize;
6804 gas_assert (! mips_opts.mips16);
6806 treg = EXTRACT_OPERAND (mips_opts.micromips, RT, *ip);
6807 dreg = EXTRACT_OPERAND (mips_opts.micromips, RD, *ip);
6808 sreg = breg = EXTRACT_OPERAND (mips_opts.micromips, RS, *ip);
6809 mask = ip->insn_mo->mask;
6811 label_expr.X_op = O_constant;
6812 label_expr.X_op_symbol = NULL;
6813 label_expr.X_add_symbol = NULL;
6814 label_expr.X_add_number = 0;
6816 expr1.X_op = O_constant;
6817 expr1.X_op_symbol = NULL;
6818 expr1.X_add_symbol = NULL;
6819 expr1.X_add_number = 1;
6834 if (mips_opts.micromips)
6835 micromips_label_expr (&label_expr);
6837 label_expr.X_add_number = 8;
6838 macro_build (&label_expr, "bgez", "s,p", sreg);
6840 macro_build (NULL, "nop", "");
6842 move_register (dreg, sreg);
6843 macro_build (NULL, dbl ? "dsub" : "sub", "d,v,t", dreg, 0, sreg);
6844 if (mips_opts.micromips)
6845 micromips_add_label ();
6862 if (!mips_opts.micromips)
6864 if (imm_expr.X_op == O_constant
6865 && imm_expr.X_add_number >= -0x200
6866 && imm_expr.X_add_number < 0x200)
6868 macro_build (NULL, s, "t,r,.", treg, sreg, imm_expr.X_add_number);
6877 if (imm_expr.X_op == O_constant
6878 && imm_expr.X_add_number >= -0x8000
6879 && imm_expr.X_add_number < 0x8000)
6881 macro_build (&imm_expr, s, "t,r,j", treg, sreg, BFD_RELOC_LO16);
6886 load_register (AT, &imm_expr, dbl);
6887 macro_build (NULL, s2, "d,v,t", treg, sreg, AT);
6906 if (imm_expr.X_op == O_constant
6907 && imm_expr.X_add_number >= 0
6908 && imm_expr.X_add_number < 0x10000)
6910 if (mask != M_NOR_I)
6911 macro_build (&imm_expr, s, "t,r,i", treg, sreg, BFD_RELOC_LO16);
6914 macro_build (&imm_expr, "ori", "t,r,i",
6915 treg, sreg, BFD_RELOC_LO16);
6916 macro_build (NULL, "nor", "d,v,t", treg, treg, 0);
6922 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
6923 macro_build (NULL, s2, "d,v,t", treg, sreg, AT);
6927 switch (imm_expr.X_add_number)
6930 macro_build (NULL, "nop", "");
6933 macro_build (NULL, "packrl.ph", "d,s,t", treg, treg, sreg);
6937 macro_build (NULL, "balign", "t,s,2", treg, sreg,
6938 (int) imm_expr.X_add_number);
6941 as_bad (_("BALIGN immediate not 0, 1, 2 or 3 (%lu)"),
6942 (unsigned long) imm_expr.X_add_number);
6951 gas_assert (mips_opts.micromips);
6952 macro_build_branch_ccl (mask, &offset_expr,
6953 EXTRACT_OPERAND (1, BCC, *ip));
6960 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
6966 load_register (treg, &imm_expr, HAVE_64BIT_GPRS);
6971 macro_build_branch_rsrt (mask, &offset_expr, sreg, treg);
6978 macro_build_branch_rs (likely ? M_BGEZL : M_BGEZ, &offset_expr, sreg);
6980 macro_build_branch_rs (likely ? M_BLEZL : M_BLEZ, &offset_expr, treg);
6984 macro_build (NULL, "slt", "d,v,t", AT, sreg, treg);
6985 macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ,
6986 &offset_expr, AT, ZERO);
6996 macro_build_branch_rs (mask, &offset_expr, sreg);
7002 /* Check for > max integer. */
7003 maxnum = 0x7fffffff;
7004 if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4)
7011 if (imm_expr.X_op == O_constant
7012 && imm_expr.X_add_number >= maxnum
7013 && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4))
7016 /* Result is always false. */
7018 macro_build (NULL, "nop", "");
7020 macro_build_branch_rsrt (M_BNEL, &offset_expr, ZERO, ZERO);
7023 if (imm_expr.X_op != O_constant)
7024 as_bad (_("Unsupported large constant"));
7025 ++imm_expr.X_add_number;
7029 if (mask == M_BGEL_I)
7031 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
7033 macro_build_branch_rs (likely ? M_BGEZL : M_BGEZ,
7034 &offset_expr, sreg);
7037 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
7039 macro_build_branch_rs (likely ? M_BGTZL : M_BGTZ,
7040 &offset_expr, sreg);
7043 maxnum = 0x7fffffff;
7044 if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4)
7051 maxnum = - maxnum - 1;
7052 if (imm_expr.X_op == O_constant
7053 && imm_expr.X_add_number <= maxnum
7054 && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4))
7057 /* result is always true */
7058 as_warn (_("Branch %s is always true"), ip->insn_mo->name);
7059 macro_build (&offset_expr, "b", "p");
7064 macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ,
7065 &offset_expr, AT, ZERO);
7074 macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ,
7075 &offset_expr, ZERO, treg);
7079 macro_build (NULL, "sltu", "d,v,t", AT, sreg, treg);
7080 macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ,
7081 &offset_expr, AT, ZERO);
7090 && imm_expr.X_op == O_constant
7091 && imm_expr.X_add_number == -1))
7093 if (imm_expr.X_op != O_constant)
7094 as_bad (_("Unsupported large constant"));
7095 ++imm_expr.X_add_number;
7099 if (mask == M_BGEUL_I)
7101 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
7103 else if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
7104 macro_build_branch_rsrt (likely ? M_BNEL : M_BNE,
7105 &offset_expr, sreg, ZERO);
7110 macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ,
7111 &offset_expr, AT, ZERO);
7119 macro_build_branch_rs (likely ? M_BGTZL : M_BGTZ, &offset_expr, sreg);
7121 macro_build_branch_rs (likely ? M_BLTZL : M_BLTZ, &offset_expr, treg);
7125 macro_build (NULL, "slt", "d,v,t", AT, treg, sreg);
7126 macro_build_branch_rsrt (likely ? M_BNEL : M_BNE,
7127 &offset_expr, AT, ZERO);
7135 macro_build_branch_rsrt (likely ? M_BNEL : M_BNE,
7136 &offset_expr, sreg, ZERO);
7142 macro_build (NULL, "sltu", "d,v,t", AT, treg, sreg);
7143 macro_build_branch_rsrt (likely ? M_BNEL : M_BNE,
7144 &offset_expr, AT, ZERO);
7152 macro_build_branch_rs (likely ? M_BLEZL : M_BLEZ, &offset_expr, sreg);
7154 macro_build_branch_rs (likely ? M_BGEZL : M_BGEZ, &offset_expr, treg);
7158 macro_build (NULL, "slt", "d,v,t", AT, treg, sreg);
7159 macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ,
7160 &offset_expr, AT, ZERO);
7167 maxnum = 0x7fffffff;
7168 if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4)
7175 if (imm_expr.X_op == O_constant
7176 && imm_expr.X_add_number >= maxnum
7177 && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4))
7179 if (imm_expr.X_op != O_constant)
7180 as_bad (_("Unsupported large constant"));
7181 ++imm_expr.X_add_number;
7185 if (mask == M_BLTL_I)
7187 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
7188 macro_build_branch_rs (likely ? M_BLTZL : M_BLTZ, &offset_expr, sreg);
7189 else if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
7190 macro_build_branch_rs (likely ? M_BLEZL : M_BLEZ, &offset_expr, sreg);
7195 macro_build_branch_rsrt (likely ? M_BNEL : M_BNE,
7196 &offset_expr, AT, ZERO);
7204 macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ,
7205 &offset_expr, sreg, ZERO);
7211 macro_build (NULL, "sltu", "d,v,t", AT, treg, sreg);
7212 macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ,
7213 &offset_expr, AT, ZERO);
7222 && imm_expr.X_op == O_constant
7223 && imm_expr.X_add_number == -1))
7225 if (imm_expr.X_op != O_constant)
7226 as_bad (_("Unsupported large constant"));
7227 ++imm_expr.X_add_number;
7231 if (mask == M_BLTUL_I)
7233 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
7235 else if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
7236 macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ,
7237 &offset_expr, sreg, ZERO);
7242 macro_build_branch_rsrt (likely ? M_BNEL : M_BNE,
7243 &offset_expr, AT, ZERO);
7251 macro_build_branch_rs (likely ? M_BLTZL : M_BLTZ, &offset_expr, sreg);
7253 macro_build_branch_rs (likely ? M_BGTZL : M_BGTZ, &offset_expr, treg);
7257 macro_build (NULL, "slt", "d,v,t", AT, sreg, treg);
7258 macro_build_branch_rsrt (likely ? M_BNEL : M_BNE,
7259 &offset_expr, AT, ZERO);
7269 macro_build_branch_rsrt (likely ? M_BNEL : M_BNE,
7270 &offset_expr, ZERO, treg);
7274 macro_build (NULL, "sltu", "d,v,t", AT, sreg, treg);
7275 macro_build_branch_rsrt (likely ? M_BNEL : M_BNE,
7276 &offset_expr, AT, ZERO);
7282 /* Use unsigned arithmetic. */
7286 if (imm_expr.X_op != O_constant || imm2_expr.X_op != O_constant)
7288 as_bad (_("Unsupported large constant"));
7293 pos = imm_expr.X_add_number;
7294 size = imm2_expr.X_add_number;
7299 as_bad (_("Improper position (%lu)"), (unsigned long) pos);
7302 if (size == 0 || size > 64 || (pos + size - 1) > 63)
7304 as_bad (_("Improper extract size (%lu, position %lu)"),
7305 (unsigned long) size, (unsigned long) pos);
7309 if (size <= 32 && pos < 32)
7314 else if (size <= 32)
7324 macro_build ((expressionS *) NULL, s, fmt, treg, sreg, (int) pos,
7331 /* Use unsigned arithmetic. */
7335 if (imm_expr.X_op != O_constant || imm2_expr.X_op != O_constant)
7337 as_bad (_("Unsupported large constant"));
7342 pos = imm_expr.X_add_number;
7343 size = imm2_expr.X_add_number;
7348 as_bad (_("Improper position (%lu)"), (unsigned long) pos);
7351 if (size == 0 || size > 64 || (pos + size - 1) > 63)
7353 as_bad (_("Improper insert size (%lu, position %lu)"),
7354 (unsigned long) size, (unsigned long) pos);
7358 if (pos < 32 && (pos + size - 1) < 32)
7373 macro_build ((expressionS *) NULL, s, fmt, treg, sreg, (int) pos,
7374 (int) (pos + size - 1));
7390 as_warn (_("Divide by zero."));
7392 macro_build (NULL, "teq", TRAP_FMT, ZERO, ZERO, 7);
7394 macro_build (NULL, "break", BRK_FMT, 7);
7401 macro_build (NULL, "teq", TRAP_FMT, treg, ZERO, 7);
7402 macro_build (NULL, dbl ? "ddiv" : "div", "z,s,t", sreg, treg);
7406 if (mips_opts.micromips)
7407 micromips_label_expr (&label_expr);
7409 label_expr.X_add_number = 8;
7410 macro_build (&label_expr, "bne", "s,t,p", treg, ZERO);
7411 macro_build (NULL, dbl ? "ddiv" : "div", "z,s,t", sreg, treg);
7412 macro_build (NULL, "break", BRK_FMT, 7);
7413 if (mips_opts.micromips)
7414 micromips_add_label ();
7416 expr1.X_add_number = -1;
7418 load_register (AT, &expr1, dbl);
7419 if (mips_opts.micromips)
7420 micromips_label_expr (&label_expr);
7422 label_expr.X_add_number = mips_trap ? (dbl ? 12 : 8) : (dbl ? 20 : 16);
7423 macro_build (&label_expr, "bne", "s,t,p", treg, AT);
7426 expr1.X_add_number = 1;
7427 load_register (AT, &expr1, dbl);
7428 macro_build (NULL, "dsll32", SHFT_FMT, AT, AT, 31);
7432 expr1.X_add_number = 0x80000000;
7433 macro_build (&expr1, "lui", LUI_FMT, AT, BFD_RELOC_HI16);
7437 macro_build (NULL, "teq", TRAP_FMT, sreg, AT, 6);
7438 /* We want to close the noreorder block as soon as possible, so
7439 that later insns are available for delay slot filling. */
7444 if (mips_opts.micromips)
7445 micromips_label_expr (&label_expr);
7447 label_expr.X_add_number = 8;
7448 macro_build (&label_expr, "bne", "s,t,p", sreg, AT);
7449 macro_build (NULL, "nop", "");
7451 /* We want to close the noreorder block as soon as possible, so
7452 that later insns are available for delay slot filling. */
7455 macro_build (NULL, "break", BRK_FMT, 6);
7457 if (mips_opts.micromips)
7458 micromips_add_label ();
7459 macro_build (NULL, s, MFHL_FMT, dreg);
7498 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
7500 as_warn (_("Divide by zero."));
7502 macro_build (NULL, "teq", TRAP_FMT, ZERO, ZERO, 7);
7504 macro_build (NULL, "break", BRK_FMT, 7);
7507 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
7509 if (strcmp (s2, "mflo") == 0)
7510 move_register (dreg, sreg);
7512 move_register (dreg, ZERO);
7515 if (imm_expr.X_op == O_constant
7516 && imm_expr.X_add_number == -1
7517 && s[strlen (s) - 1] != 'u')
7519 if (strcmp (s2, "mflo") == 0)
7521 macro_build (NULL, dbl ? "dneg" : "neg", "d,w", dreg, sreg);
7524 move_register (dreg, ZERO);
7529 load_register (AT, &imm_expr, dbl);
7530 macro_build (NULL, s, "z,s,t", sreg, AT);
7531 macro_build (NULL, s2, MFHL_FMT, dreg);
7553 macro_build (NULL, "teq", TRAP_FMT, treg, ZERO, 7);
7554 macro_build (NULL, s, "z,s,t", sreg, treg);
7555 /* We want to close the noreorder block as soon as possible, so
7556 that later insns are available for delay slot filling. */
7561 if (mips_opts.micromips)
7562 micromips_label_expr (&label_expr);
7564 label_expr.X_add_number = 8;
7565 macro_build (&label_expr, "bne", "s,t,p", treg, ZERO);
7566 macro_build (NULL, s, "z,s,t", sreg, treg);
7568 /* We want to close the noreorder block as soon as possible, so
7569 that later insns are available for delay slot filling. */
7571 macro_build (NULL, "break", BRK_FMT, 7);
7572 if (mips_opts.micromips)
7573 micromips_add_label ();
7575 macro_build (NULL, s2, MFHL_FMT, dreg);
7587 /* Load the address of a symbol into a register. If breg is not
7588 zero, we then add a base register to it. */
7590 if (dbl && HAVE_32BIT_GPRS)
7591 as_warn (_("dla used to load 32-bit register"));
7593 if (!dbl && HAVE_64BIT_OBJECTS)
7594 as_warn (_("la used to load 64-bit address"));
7596 if (offset_expr.X_op == O_constant
7597 && offset_expr.X_add_number >= -0x8000
7598 && offset_expr.X_add_number < 0x8000)
7600 macro_build (&offset_expr, ADDRESS_ADDI_INSN,
7601 "t,r,j", treg, sreg, BFD_RELOC_LO16);
7605 if (mips_opts.at && (treg == breg))
7615 if (offset_expr.X_op != O_symbol
7616 && offset_expr.X_op != O_constant)
7618 as_bad (_("Expression too complex"));
7619 offset_expr.X_op = O_constant;
7622 if (offset_expr.X_op == O_constant)
7623 load_register (tempreg, &offset_expr, HAVE_64BIT_ADDRESSES);
7624 else if (mips_pic == NO_PIC)
7626 /* If this is a reference to a GP relative symbol, we want
7627 addiu $tempreg,$gp,<sym> (BFD_RELOC_GPREL16)
7629 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
7630 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
7631 If we have a constant, we need two instructions anyhow,
7632 so we may as well always use the latter form.
7634 With 64bit address space and a usable $at we want
7635 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
7636 lui $at,<sym> (BFD_RELOC_HI16_S)
7637 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
7638 daddiu $at,<sym> (BFD_RELOC_LO16)
7640 daddu $tempreg,$tempreg,$at
7642 If $at is already in use, we use a path which is suboptimal
7643 on superscalar processors.
7644 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
7645 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
7647 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
7649 daddiu $tempreg,<sym> (BFD_RELOC_LO16)
7651 For GP relative symbols in 64bit address space we can use
7652 the same sequence as in 32bit address space. */
7653 if (HAVE_64BIT_SYMBOLS)
7655 if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
7656 && !nopic_need_relax (offset_expr.X_add_symbol, 1))
7658 relax_start (offset_expr.X_add_symbol);
7659 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
7660 tempreg, mips_gp_register, BFD_RELOC_GPREL16);
7664 if (used_at == 0 && mips_opts.at)
7666 macro_build (&offset_expr, "lui", LUI_FMT,
7667 tempreg, BFD_RELOC_MIPS_HIGHEST);
7668 macro_build (&offset_expr, "lui", LUI_FMT,
7669 AT, BFD_RELOC_HI16_S);
7670 macro_build (&offset_expr, "daddiu", "t,r,j",
7671 tempreg, tempreg, BFD_RELOC_MIPS_HIGHER);
7672 macro_build (&offset_expr, "daddiu", "t,r,j",
7673 AT, AT, BFD_RELOC_LO16);
7674 macro_build (NULL, "dsll32", SHFT_FMT, tempreg, tempreg, 0);
7675 macro_build (NULL, "daddu", "d,v,t", tempreg, tempreg, AT);
7680 macro_build (&offset_expr, "lui", LUI_FMT,
7681 tempreg, BFD_RELOC_MIPS_HIGHEST);
7682 macro_build (&offset_expr, "daddiu", "t,r,j",
7683 tempreg, tempreg, BFD_RELOC_MIPS_HIGHER);
7684 macro_build (NULL, "dsll", SHFT_FMT, tempreg, tempreg, 16);
7685 macro_build (&offset_expr, "daddiu", "t,r,j",
7686 tempreg, tempreg, BFD_RELOC_HI16_S);
7687 macro_build (NULL, "dsll", SHFT_FMT, tempreg, tempreg, 16);
7688 macro_build (&offset_expr, "daddiu", "t,r,j",
7689 tempreg, tempreg, BFD_RELOC_LO16);
7692 if (mips_relax.sequence)
7697 if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
7698 && !nopic_need_relax (offset_expr.X_add_symbol, 1))
7700 relax_start (offset_expr.X_add_symbol);
7701 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
7702 tempreg, mips_gp_register, BFD_RELOC_GPREL16);
7705 if (!IS_SEXT_32BIT_NUM (offset_expr.X_add_number))
7706 as_bad (_("Offset too large"));
7707 macro_build_lui (&offset_expr, tempreg);
7708 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
7709 tempreg, tempreg, BFD_RELOC_LO16);
7710 if (mips_relax.sequence)
7714 else if (!mips_big_got && !HAVE_NEWABI)
7716 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT16;
7718 /* If this is a reference to an external symbol, and there
7719 is no constant, we want
7720 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
7721 or for lca or if tempreg is PIC_CALL_REG
7722 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
7723 For a local symbol, we want
7724 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
7726 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
7728 If we have a small constant, and this is a reference to
7729 an external symbol, we want
7730 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
7732 addiu $tempreg,$tempreg,<constant>
7733 For a local symbol, we want the same instruction
7734 sequence, but we output a BFD_RELOC_LO16 reloc on the
7737 If we have a large constant, and this is a reference to
7738 an external symbol, we want
7739 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
7740 lui $at,<hiconstant>
7741 addiu $at,$at,<loconstant>
7742 addu $tempreg,$tempreg,$at
7743 For a local symbol, we want the same instruction
7744 sequence, but we output a BFD_RELOC_LO16 reloc on the
7748 if (offset_expr.X_add_number == 0)
7750 if (mips_pic == SVR4_PIC
7752 && (call || tempreg == PIC_CALL_REG))
7753 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL16;
7755 relax_start (offset_expr.X_add_symbol);
7756 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
7757 lw_reloc_type, mips_gp_register);
7760 /* We're going to put in an addu instruction using
7761 tempreg, so we may as well insert the nop right
7766 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
7767 tempreg, BFD_RELOC_MIPS_GOT16, mips_gp_register);
7769 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
7770 tempreg, tempreg, BFD_RELOC_LO16);
7772 /* FIXME: If breg == 0, and the next instruction uses
7773 $tempreg, then if this variant case is used an extra
7774 nop will be generated. */
7776 else if (offset_expr.X_add_number >= -0x8000
7777 && offset_expr.X_add_number < 0x8000)
7779 load_got_offset (tempreg, &offset_expr);
7781 add_got_offset (tempreg, &offset_expr);
7785 expr1.X_add_number = offset_expr.X_add_number;
7786 offset_expr.X_add_number =
7787 SEXT_16BIT (offset_expr.X_add_number);
7788 load_got_offset (tempreg, &offset_expr);
7789 offset_expr.X_add_number = expr1.X_add_number;
7790 /* If we are going to add in a base register, and the
7791 target register and the base register are the same,
7792 then we are using AT as a temporary register. Since
7793 we want to load the constant into AT, we add our
7794 current AT (from the global offset table) and the
7795 register into the register now, and pretend we were
7796 not using a base register. */
7800 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
7805 add_got_offset_hilo (tempreg, &offset_expr, AT);
7809 else if (!mips_big_got && HAVE_NEWABI)
7811 int add_breg_early = 0;
7813 /* If this is a reference to an external, and there is no
7814 constant, or local symbol (*), with or without a
7816 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
7817 or for lca or if tempreg is PIC_CALL_REG
7818 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
7820 If we have a small constant, and this is a reference to
7821 an external symbol, we want
7822 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
7823 addiu $tempreg,$tempreg,<constant>
7825 If we have a large constant, and this is a reference to
7826 an external symbol, we want
7827 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
7828 lui $at,<hiconstant>
7829 addiu $at,$at,<loconstant>
7830 addu $tempreg,$tempreg,$at
7832 (*) Other assemblers seem to prefer GOT_PAGE/GOT_OFST for
7833 local symbols, even though it introduces an additional
7836 if (offset_expr.X_add_number)
7838 expr1.X_add_number = offset_expr.X_add_number;
7839 offset_expr.X_add_number = 0;
7841 relax_start (offset_expr.X_add_symbol);
7842 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
7843 BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
7845 if (expr1.X_add_number >= -0x8000
7846 && expr1.X_add_number < 0x8000)
7848 macro_build (&expr1, ADDRESS_ADDI_INSN, "t,r,j",
7849 tempreg, tempreg, BFD_RELOC_LO16);
7851 else if (IS_SEXT_32BIT_NUM (expr1.X_add_number + 0x8000))
7853 /* If we are going to add in a base register, and the
7854 target register and the base register are the same,
7855 then we are using AT as a temporary register. Since
7856 we want to load the constant into AT, we add our
7857 current AT (from the global offset table) and the
7858 register into the register now, and pretend we were
7859 not using a base register. */
7864 gas_assert (tempreg == AT);
7865 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
7871 load_register (AT, &expr1, HAVE_64BIT_ADDRESSES);
7872 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
7878 as_bad (_("PIC code offset overflow (max 32 signed bits)"));
7881 offset_expr.X_add_number = expr1.X_add_number;
7883 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
7884 BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
7887 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
7888 treg, tempreg, breg);
7894 else if (breg == 0 && (call || tempreg == PIC_CALL_REG))
7896 relax_start (offset_expr.X_add_symbol);
7897 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
7898 BFD_RELOC_MIPS_CALL16, mips_gp_register);
7900 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
7901 BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
7906 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
7907 BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
7910 else if (mips_big_got && !HAVE_NEWABI)
7913 int lui_reloc_type = (int) BFD_RELOC_MIPS_GOT_HI16;
7914 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT_LO16;
7915 int local_reloc_type = (int) BFD_RELOC_MIPS_GOT16;
7917 /* This is the large GOT case. If this is a reference to an
7918 external symbol, and there is no constant, we want
7919 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
7920 addu $tempreg,$tempreg,$gp
7921 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
7922 or for lca or if tempreg is PIC_CALL_REG
7923 lui $tempreg,<sym> (BFD_RELOC_MIPS_CALL_HI16)
7924 addu $tempreg,$tempreg,$gp
7925 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_CALL_LO16)
7926 For a local symbol, we want
7927 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
7929 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
7931 If we have a small constant, and this is a reference to
7932 an external symbol, we want
7933 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
7934 addu $tempreg,$tempreg,$gp
7935 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
7937 addiu $tempreg,$tempreg,<constant>
7938 For a local symbol, we want
7939 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
7941 addiu $tempreg,$tempreg,<constant> (BFD_RELOC_LO16)
7943 If we have a large constant, and this is a reference to
7944 an external symbol, we want
7945 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
7946 addu $tempreg,$tempreg,$gp
7947 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
7948 lui $at,<hiconstant>
7949 addiu $at,$at,<loconstant>
7950 addu $tempreg,$tempreg,$at
7951 For a local symbol, we want
7952 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
7953 lui $at,<hiconstant>
7954 addiu $at,$at,<loconstant> (BFD_RELOC_LO16)
7955 addu $tempreg,$tempreg,$at
7958 expr1.X_add_number = offset_expr.X_add_number;
7959 offset_expr.X_add_number = 0;
7960 relax_start (offset_expr.X_add_symbol);
7961 gpdelay = reg_needs_delay (mips_gp_register);
7962 if (expr1.X_add_number == 0 && breg == 0
7963 && (call || tempreg == PIC_CALL_REG))
7965 lui_reloc_type = (int) BFD_RELOC_MIPS_CALL_HI16;
7966 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL_LO16;
7968 macro_build (&offset_expr, "lui", LUI_FMT, tempreg, lui_reloc_type);
7969 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
7970 tempreg, tempreg, mips_gp_register);
7971 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
7972 tempreg, lw_reloc_type, tempreg);
7973 if (expr1.X_add_number == 0)
7977 /* We're going to put in an addu instruction using
7978 tempreg, so we may as well insert the nop right
7983 else if (expr1.X_add_number >= -0x8000
7984 && expr1.X_add_number < 0x8000)
7987 macro_build (&expr1, ADDRESS_ADDI_INSN, "t,r,j",
7988 tempreg, tempreg, BFD_RELOC_LO16);
7992 /* If we are going to add in a base register, and the
7993 target register and the base register are the same,
7994 then we are using AT as a temporary register. Since
7995 we want to load the constant into AT, we add our
7996 current AT (from the global offset table) and the
7997 register into the register now, and pretend we were
7998 not using a base register. */
8003 gas_assert (tempreg == AT);
8005 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
8010 load_register (AT, &expr1, HAVE_64BIT_ADDRESSES);
8011 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", dreg, dreg, AT);
8015 offset_expr.X_add_number = SEXT_16BIT (expr1.X_add_number);
8020 /* This is needed because this instruction uses $gp, but
8021 the first instruction on the main stream does not. */
8022 macro_build (NULL, "nop", "");
8025 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
8026 local_reloc_type, mips_gp_register);
8027 if (expr1.X_add_number >= -0x8000
8028 && expr1.X_add_number < 0x8000)
8031 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
8032 tempreg, tempreg, BFD_RELOC_LO16);
8033 /* FIXME: If add_number is 0, and there was no base
8034 register, the external symbol case ended with a load,
8035 so if the symbol turns out to not be external, and
8036 the next instruction uses tempreg, an unnecessary nop
8037 will be inserted. */
8043 /* We must add in the base register now, as in the
8044 external symbol case. */
8045 gas_assert (tempreg == AT);
8047 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
8050 /* We set breg to 0 because we have arranged to add
8051 it in in both cases. */
8055 macro_build_lui (&expr1, AT);
8056 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
8057 AT, AT, BFD_RELOC_LO16);
8058 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
8059 tempreg, tempreg, AT);
8064 else if (mips_big_got && HAVE_NEWABI)
8066 int lui_reloc_type = (int) BFD_RELOC_MIPS_GOT_HI16;
8067 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT_LO16;
8068 int add_breg_early = 0;
8070 /* This is the large GOT case. If this is a reference to an
8071 external symbol, and there is no constant, we want
8072 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
8073 add $tempreg,$tempreg,$gp
8074 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
8075 or for lca or if tempreg is PIC_CALL_REG
8076 lui $tempreg,<sym> (BFD_RELOC_MIPS_CALL_HI16)
8077 add $tempreg,$tempreg,$gp
8078 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_CALL_LO16)
8080 If we have a small constant, and this is a reference to
8081 an external symbol, we want
8082 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
8083 add $tempreg,$tempreg,$gp
8084 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
8085 addi $tempreg,$tempreg,<constant>
8087 If we have a large constant, and this is a reference to
8088 an external symbol, we want
8089 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
8090 addu $tempreg,$tempreg,$gp
8091 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
8092 lui $at,<hiconstant>
8093 addi $at,$at,<loconstant>
8094 add $tempreg,$tempreg,$at
8096 If we have NewABI, and we know it's a local symbol, we want
8097 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
8098 addiu $reg,$reg,<sym> (BFD_RELOC_MIPS_GOT_OFST)
8099 otherwise we have to resort to GOT_HI16/GOT_LO16. */
8101 relax_start (offset_expr.X_add_symbol);
8103 expr1.X_add_number = offset_expr.X_add_number;
8104 offset_expr.X_add_number = 0;
8106 if (expr1.X_add_number == 0 && breg == 0
8107 && (call || tempreg == PIC_CALL_REG))
8109 lui_reloc_type = (int) BFD_RELOC_MIPS_CALL_HI16;
8110 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL_LO16;
8112 macro_build (&offset_expr, "lui", LUI_FMT, tempreg, lui_reloc_type);
8113 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
8114 tempreg, tempreg, mips_gp_register);
8115 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
8116 tempreg, lw_reloc_type, tempreg);
8118 if (expr1.X_add_number == 0)
8120 else if (expr1.X_add_number >= -0x8000
8121 && expr1.X_add_number < 0x8000)
8123 macro_build (&expr1, ADDRESS_ADDI_INSN, "t,r,j",
8124 tempreg, tempreg, BFD_RELOC_LO16);
8126 else if (IS_SEXT_32BIT_NUM (expr1.X_add_number + 0x8000))
8128 /* If we are going to add in a base register, and the
8129 target register and the base register are the same,
8130 then we are using AT as a temporary register. Since
8131 we want to load the constant into AT, we add our
8132 current AT (from the global offset table) and the
8133 register into the register now, and pretend we were
8134 not using a base register. */
8139 gas_assert (tempreg == AT);
8140 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
8146 load_register (AT, &expr1, HAVE_64BIT_ADDRESSES);
8147 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", dreg, dreg, AT);
8152 as_bad (_("PIC code offset overflow (max 32 signed bits)"));
8155 offset_expr.X_add_number = expr1.X_add_number;
8156 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
8157 BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register);
8158 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j", tempreg,
8159 tempreg, BFD_RELOC_MIPS_GOT_OFST);
8162 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
8163 treg, tempreg, breg);
8173 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", treg, tempreg, breg);
8177 gas_assert (!mips_opts.micromips);
8179 unsigned long temp = (treg << 16) | (0x01);
8180 macro_build (NULL, "c2", "C", temp);
8185 gas_assert (!mips_opts.micromips);
8187 unsigned long temp = (0x02);
8188 macro_build (NULL, "c2", "C", temp);
8193 gas_assert (!mips_opts.micromips);
8195 unsigned long temp = (treg << 16) | (0x02);
8196 macro_build (NULL, "c2", "C", temp);
8201 gas_assert (!mips_opts.micromips);
8202 macro_build (NULL, "c2", "C", 3);
8206 gas_assert (!mips_opts.micromips);
8208 unsigned long temp = (treg << 16) | 0x03;
8209 macro_build (NULL, "c2", "C", temp);
8214 /* The j instruction may not be used in PIC code, since it
8215 requires an absolute address. We convert it to a b
8217 if (mips_pic == NO_PIC)
8218 macro_build (&offset_expr, "j", "a");
8220 macro_build (&offset_expr, "b", "p");
8223 /* The jal instructions must be handled as macros because when
8224 generating PIC code they expand to multi-instruction
8225 sequences. Normally they are simple instructions. */
8230 gas_assert (mips_opts.micromips);
8238 if (mips_pic == NO_PIC)
8240 s = jals ? "jalrs" : "jalr";
8241 if (mips_opts.micromips
8243 && !(history[0].insn_mo->pinfo2 & INSN2_BRANCH_DELAY_32BIT))
8244 macro_build (NULL, s, "mj", sreg);
8246 macro_build (NULL, s, JALR_FMT, dreg, sreg);
8250 int cprestore = (mips_pic == SVR4_PIC && !HAVE_NEWABI
8251 && mips_cprestore_offset >= 0);
8253 if (sreg != PIC_CALL_REG)
8254 as_warn (_("MIPS PIC call to register other than $25"));
8256 s = (mips_opts.micromips && (!mips_opts.noreorder || cprestore)
8257 ? "jalrs" : "jalr");
8258 if (mips_opts.micromips
8260 && !(history[0].insn_mo->pinfo2 & INSN2_BRANCH_DELAY_32BIT))
8261 macro_build (NULL, s, "mj", sreg);
8263 macro_build (NULL, s, JALR_FMT, dreg, sreg);
8264 if (mips_pic == SVR4_PIC && !HAVE_NEWABI)
8266 if (mips_cprestore_offset < 0)
8267 as_warn (_("No .cprestore pseudo-op used in PIC code"));
8270 if (!mips_frame_reg_valid)
8272 as_warn (_("No .frame pseudo-op used in PIC code"));
8273 /* Quiet this warning. */
8274 mips_frame_reg_valid = 1;
8276 if (!mips_cprestore_valid)
8278 as_warn (_("No .cprestore pseudo-op used in PIC code"));
8279 /* Quiet this warning. */
8280 mips_cprestore_valid = 1;
8282 if (mips_opts.noreorder)
8283 macro_build (NULL, "nop", "");
8284 expr1.X_add_number = mips_cprestore_offset;
8285 macro_build_ldst_constoffset (&expr1, ADDRESS_LOAD_INSN,
8288 HAVE_64BIT_ADDRESSES);
8296 gas_assert (mips_opts.micromips);
8300 if (mips_pic == NO_PIC)
8301 macro_build (&offset_expr, jals ? "jals" : "jal", "a");
8302 else if (mips_pic == SVR4_PIC)
8304 /* If this is a reference to an external symbol, and we are
8305 using a small GOT, we want
8306 lw $25,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
8310 lw $gp,cprestore($sp)
8311 The cprestore value is set using the .cprestore
8312 pseudo-op. If we are using a big GOT, we want
8313 lui $25,<sym> (BFD_RELOC_MIPS_CALL_HI16)
8315 lw $25,<sym>($25) (BFD_RELOC_MIPS_CALL_LO16)
8319 lw $gp,cprestore($sp)
8320 If the symbol is not external, we want
8321 lw $25,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
8323 addiu $25,$25,<sym> (BFD_RELOC_LO16)
8326 lw $gp,cprestore($sp)
8328 For NewABI, we use the same CALL16 or CALL_HI16/CALL_LO16
8329 sequences above, minus nops, unless the symbol is local,
8330 which enables us to use GOT_PAGE/GOT_OFST (big got) or
8336 relax_start (offset_expr.X_add_symbol);
8337 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
8338 PIC_CALL_REG, BFD_RELOC_MIPS_CALL16,
8341 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
8342 PIC_CALL_REG, BFD_RELOC_MIPS_GOT_DISP,
8348 relax_start (offset_expr.X_add_symbol);
8349 macro_build (&offset_expr, "lui", LUI_FMT, PIC_CALL_REG,
8350 BFD_RELOC_MIPS_CALL_HI16);
8351 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", PIC_CALL_REG,
8352 PIC_CALL_REG, mips_gp_register);
8353 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
8354 PIC_CALL_REG, BFD_RELOC_MIPS_CALL_LO16,
8357 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
8358 PIC_CALL_REG, BFD_RELOC_MIPS_GOT_PAGE,
8360 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
8361 PIC_CALL_REG, PIC_CALL_REG,
8362 BFD_RELOC_MIPS_GOT_OFST);
8366 macro_build_jalr (&offset_expr, 0);
8370 relax_start (offset_expr.X_add_symbol);
8373 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
8374 PIC_CALL_REG, BFD_RELOC_MIPS_CALL16,
8383 gpdelay = reg_needs_delay (mips_gp_register);
8384 macro_build (&offset_expr, "lui", LUI_FMT, PIC_CALL_REG,
8385 BFD_RELOC_MIPS_CALL_HI16);
8386 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", PIC_CALL_REG,
8387 PIC_CALL_REG, mips_gp_register);
8388 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
8389 PIC_CALL_REG, BFD_RELOC_MIPS_CALL_LO16,
8394 macro_build (NULL, "nop", "");
8396 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
8397 PIC_CALL_REG, BFD_RELOC_MIPS_GOT16,
8400 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
8401 PIC_CALL_REG, PIC_CALL_REG, BFD_RELOC_LO16);
8403 macro_build_jalr (&offset_expr, mips_cprestore_offset >= 0);
8405 if (mips_cprestore_offset < 0)
8406 as_warn (_("No .cprestore pseudo-op used in PIC code"));
8409 if (!mips_frame_reg_valid)
8411 as_warn (_("No .frame pseudo-op used in PIC code"));
8412 /* Quiet this warning. */
8413 mips_frame_reg_valid = 1;
8415 if (!mips_cprestore_valid)
8417 as_warn (_("No .cprestore pseudo-op used in PIC code"));
8418 /* Quiet this warning. */
8419 mips_cprestore_valid = 1;
8421 if (mips_opts.noreorder)
8422 macro_build (NULL, "nop", "");
8423 expr1.X_add_number = mips_cprestore_offset;
8424 macro_build_ldst_constoffset (&expr1, ADDRESS_LOAD_INSN,
8427 HAVE_64BIT_ADDRESSES);
8431 else if (mips_pic == VXWORKS_PIC)
8432 as_bad (_("Non-PIC jump used in PIC library"));
8540 treg = EXTRACT_OPERAND (mips_opts.micromips, 3BITPOS, *ip);
8548 treg = EXTRACT_OPERAND (mips_opts.micromips, 3BITPOS, *ip);
8579 gas_assert (!mips_opts.micromips);
8582 /* Itbl support may require additional care here. */
8589 /* Itbl support may require additional care here. */
8597 offbits = (mips_opts.micromips ? 12 : 16);
8598 /* Itbl support may require additional care here. */
8603 gas_assert (!mips_opts.micromips);
8606 /* Itbl support may require additional care here. */
8614 offbits = (mips_opts.micromips ? 12 : 16);
8621 offbits = (mips_opts.micromips ? 12 : 16);
8627 /* Itbl support may require additional care here. */
8635 offbits = (mips_opts.micromips ? 12 : 16);
8636 /* Itbl support may require additional care here. */
8643 /* Itbl support may require additional care here. */
8650 /* Itbl support may require additional care here. */
8658 offbits = (mips_opts.micromips ? 12 : 16);
8665 offbits = (mips_opts.micromips ? 12 : 16);
8672 offbits = (mips_opts.micromips ? 12 : 16);
8679 offbits = (mips_opts.micromips ? 12 : 16);
8686 offbits = (mips_opts.micromips ? 12 : 16);
8691 gas_assert (mips_opts.micromips);
8700 gas_assert (mips_opts.micromips);
8709 gas_assert (mips_opts.micromips);
8717 gas_assert (mips_opts.micromips);
8724 /* We don't want to use $0 as tempreg. */
8725 if (breg == treg + lp || treg + lp == ZERO)
8728 tempreg = treg + lp;
8748 gas_assert (!mips_opts.micromips);
8751 /* Itbl support may require additional care here. */
8758 /* Itbl support may require additional care here. */
8766 offbits = (mips_opts.micromips ? 12 : 16);
8767 /* Itbl support may require additional care here. */
8772 gas_assert (!mips_opts.micromips);
8775 /* Itbl support may require additional care here. */
8783 offbits = (mips_opts.micromips ? 12 : 16);
8790 offbits = (mips_opts.micromips ? 12 : 16);
8797 offbits = (mips_opts.micromips ? 12 : 16);
8804 offbits = (mips_opts.micromips ? 12 : 16);
8810 fmt = mips_opts.micromips ? "k,~(b)" : "k,o(b)";
8811 offbits = (mips_opts.micromips ? 12 : 16);
8824 fmt = !mips_opts.micromips ? "k,o(b)" : "k,~(b)";
8825 offbits = (mips_opts.micromips ? 12 : 16);
8839 /* Itbl support may require additional care here. */
8846 offbits = (mips_opts.micromips ? 12 : 16);
8847 /* Itbl support may require additional care here. */
8854 /* Itbl support may require additional care here. */
8859 gas_assert (!mips_opts.micromips);
8862 /* Itbl support may require additional care here. */
8870 offbits = (mips_opts.micromips ? 12 : 16);
8877 offbits = (mips_opts.micromips ? 12 : 16);
8882 gas_assert (mips_opts.micromips);
8890 gas_assert (mips_opts.micromips);
8898 gas_assert (mips_opts.micromips);
8906 gas_assert (mips_opts.micromips);
8915 if (offset_expr.X_op != O_constant
8916 && offset_expr.X_op != O_symbol)
8918 as_bad (_("Expression too complex"));
8919 offset_expr.X_op = O_constant;
8922 if (HAVE_32BIT_ADDRESSES
8923 && !IS_SEXT_32BIT_NUM (offset_expr.X_add_number))
8927 sprintf_vma (value, offset_expr.X_add_number);
8928 as_bad (_("Number (0x%s) larger than 32 bits"), value);
8931 /* A constant expression in PIC code can be handled just as it
8932 is in non PIC code. */
8933 if (offset_expr.X_op == O_constant)
8937 expr1.X_add_number = offset_expr.X_add_number;
8938 normalize_address_expr (&expr1);
8939 if ((offbits == 0 || offbits == 16)
8940 && !IS_SEXT_16BIT_NUM (expr1.X_add_number))
8942 expr1.X_add_number = ((expr1.X_add_number + 0x8000)
8943 & ~(bfd_vma) 0xffff);
8946 else if (offbits == 12 && !IS_SEXT_12BIT_NUM (expr1.X_add_number))
8948 expr1.X_add_number = ((expr1.X_add_number + 0x800)
8949 & ~(bfd_vma) 0xfff);
8952 else if (offbits == 9 && !IS_SEXT_9BIT_NUM (expr1.X_add_number))
8954 expr1.X_add_number = ((expr1.X_add_number + 0x100)
8955 & ~(bfd_vma) 0x1ff);
8960 load_register (tempreg, &expr1, HAVE_64BIT_ADDRESSES);
8962 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
8963 tempreg, tempreg, breg);
8968 if (offset_expr.X_add_number == 0)
8971 macro_build (&offset_expr, ADDRESS_ADDI_INSN,
8972 "t,r,j", tempreg, breg, BFD_RELOC_LO16);
8973 macro_build (NULL, s, fmt, treg, tempreg);
8975 else if (offbits == 16)
8976 macro_build (&offset_expr, s, fmt, treg, BFD_RELOC_LO16, breg);
8978 macro_build (NULL, s, fmt,
8979 treg, (unsigned long) offset_expr.X_add_number, breg);
8981 else if (offbits != 16)
8983 /* The offset field is too narrow to be used for a low-part
8984 relocation, so load the whole address into the auxillary
8985 register. In the case of "A(b)" addresses, we first load
8986 absolute address "A" into the register and then add base
8987 register "b". In the case of "o(b)" addresses, we simply
8988 need to add 16-bit offset "o" to base register "b", and
8989 offset_reloc already contains the relocations associated
8993 load_address (tempreg, &offset_expr, &used_at);
8995 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
8996 tempreg, tempreg, breg);
8999 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
9001 offset_reloc[0], offset_reloc[1], offset_reloc[2]);
9002 expr1.X_add_number = 0;
9004 macro_build (NULL, s, fmt, treg, tempreg);
9006 macro_build (NULL, s, fmt,
9007 treg, (unsigned long) expr1.X_add_number, tempreg);
9009 else if (mips_pic == NO_PIC)
9011 /* If this is a reference to a GP relative symbol, and there
9012 is no base register, we want
9013 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
9014 Otherwise, if there is no base register, we want
9015 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
9016 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
9017 If we have a constant, we need two instructions anyhow,
9018 so we always use the latter form.
9020 If we have a base register, and this is a reference to a
9021 GP relative symbol, we want
9022 addu $tempreg,$breg,$gp
9023 <op> $treg,<sym>($tempreg) (BFD_RELOC_GPREL16)
9025 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
9026 addu $tempreg,$tempreg,$breg
9027 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
9028 With a constant we always use the latter case.
9030 With 64bit address space and no base register and $at usable,
9032 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
9033 lui $at,<sym> (BFD_RELOC_HI16_S)
9034 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
9037 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
9038 If we have a base register, we want
9039 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
9040 lui $at,<sym> (BFD_RELOC_HI16_S)
9041 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
9045 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
9047 Without $at we can't generate the optimal path for superscalar
9048 processors here since this would require two temporary registers.
9049 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
9050 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
9052 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
9054 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
9055 If we have a base register, we want
9056 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
9057 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
9059 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
9061 daddu $tempreg,$tempreg,$breg
9062 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
9064 For GP relative symbols in 64bit address space we can use
9065 the same sequence as in 32bit address space. */
9066 if (HAVE_64BIT_SYMBOLS)
9068 if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
9069 && !nopic_need_relax (offset_expr.X_add_symbol, 1))
9071 relax_start (offset_expr.X_add_symbol);
9074 macro_build (&offset_expr, s, fmt, treg,
9075 BFD_RELOC_GPREL16, mips_gp_register);
9079 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
9080 tempreg, breg, mips_gp_register);
9081 macro_build (&offset_expr, s, fmt, treg,
9082 BFD_RELOC_GPREL16, tempreg);
9087 if (used_at == 0 && mips_opts.at)
9089 macro_build (&offset_expr, "lui", LUI_FMT, tempreg,
9090 BFD_RELOC_MIPS_HIGHEST);
9091 macro_build (&offset_expr, "lui", LUI_FMT, AT,
9093 macro_build (&offset_expr, "daddiu", "t,r,j", tempreg,
9094 tempreg, BFD_RELOC_MIPS_HIGHER);
9096 macro_build (NULL, "daddu", "d,v,t", AT, AT, breg);
9097 macro_build (NULL, "dsll32", SHFT_FMT, tempreg, tempreg, 0);
9098 macro_build (NULL, "daddu", "d,v,t", tempreg, tempreg, AT);
9099 macro_build (&offset_expr, s, fmt, treg, BFD_RELOC_LO16,
9105 macro_build (&offset_expr, "lui", LUI_FMT, tempreg,
9106 BFD_RELOC_MIPS_HIGHEST);
9107 macro_build (&offset_expr, "daddiu", "t,r,j", tempreg,
9108 tempreg, BFD_RELOC_MIPS_HIGHER);
9109 macro_build (NULL, "dsll", SHFT_FMT, tempreg, tempreg, 16);
9110 macro_build (&offset_expr, "daddiu", "t,r,j", tempreg,
9111 tempreg, BFD_RELOC_HI16_S);
9112 macro_build (NULL, "dsll", SHFT_FMT, tempreg, tempreg, 16);
9114 macro_build (NULL, "daddu", "d,v,t",
9115 tempreg, tempreg, breg);
9116 macro_build (&offset_expr, s, fmt, treg,
9117 BFD_RELOC_LO16, tempreg);
9120 if (mips_relax.sequence)
9127 if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
9128 && !nopic_need_relax (offset_expr.X_add_symbol, 1))
9130 relax_start (offset_expr.X_add_symbol);
9131 macro_build (&offset_expr, s, fmt, treg, BFD_RELOC_GPREL16,
9135 macro_build_lui (&offset_expr, tempreg);
9136 macro_build (&offset_expr, s, fmt, treg,
9137 BFD_RELOC_LO16, tempreg);
9138 if (mips_relax.sequence)
9143 if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
9144 && !nopic_need_relax (offset_expr.X_add_symbol, 1))
9146 relax_start (offset_expr.X_add_symbol);
9147 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
9148 tempreg, breg, mips_gp_register);
9149 macro_build (&offset_expr, s, fmt, treg,
9150 BFD_RELOC_GPREL16, tempreg);
9153 macro_build_lui (&offset_expr, tempreg);
9154 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
9155 tempreg, tempreg, breg);
9156 macro_build (&offset_expr, s, fmt, treg,
9157 BFD_RELOC_LO16, tempreg);
9158 if (mips_relax.sequence)
9162 else if (!mips_big_got)
9164 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT16;
9166 /* If this is a reference to an external symbol, we want
9167 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
9169 <op> $treg,0($tempreg)
9171 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
9173 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
9174 <op> $treg,0($tempreg)
9177 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
9178 <op> $treg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_OFST)
9180 If there is a base register, we add it to $tempreg before
9181 the <op>. If there is a constant, we stick it in the
9182 <op> instruction. We don't handle constants larger than
9183 16 bits, because we have no way to load the upper 16 bits
9184 (actually, we could handle them for the subset of cases
9185 in which we are not using $at). */
9186 gas_assert (offset_expr.X_op == O_symbol);
9189 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
9190 BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register);
9192 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
9193 tempreg, tempreg, breg);
9194 macro_build (&offset_expr, s, fmt, treg,
9195 BFD_RELOC_MIPS_GOT_OFST, tempreg);
9198 expr1.X_add_number = offset_expr.X_add_number;
9199 offset_expr.X_add_number = 0;
9200 if (expr1.X_add_number < -0x8000
9201 || expr1.X_add_number >= 0x8000)
9202 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
9203 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
9204 lw_reloc_type, mips_gp_register);
9206 relax_start (offset_expr.X_add_symbol);
9208 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j", tempreg,
9209 tempreg, BFD_RELOC_LO16);
9212 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
9213 tempreg, tempreg, breg);
9214 macro_build (&expr1, s, fmt, treg, BFD_RELOC_LO16, tempreg);
9216 else if (mips_big_got && !HAVE_NEWABI)
9220 /* If this is a reference to an external symbol, we want
9221 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
9222 addu $tempreg,$tempreg,$gp
9223 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
9224 <op> $treg,0($tempreg)
9226 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
9228 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
9229 <op> $treg,0($tempreg)
9230 If there is a base register, we add it to $tempreg before
9231 the <op>. If there is a constant, we stick it in the
9232 <op> instruction. We don't handle constants larger than
9233 16 bits, because we have no way to load the upper 16 bits
9234 (actually, we could handle them for the subset of cases
9235 in which we are not using $at). */
9236 gas_assert (offset_expr.X_op == O_symbol);
9237 expr1.X_add_number = offset_expr.X_add_number;
9238 offset_expr.X_add_number = 0;
9239 if (expr1.X_add_number < -0x8000
9240 || expr1.X_add_number >= 0x8000)
9241 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
9242 gpdelay = reg_needs_delay (mips_gp_register);
9243 relax_start (offset_expr.X_add_symbol);
9244 macro_build (&offset_expr, "lui", LUI_FMT, tempreg,
9245 BFD_RELOC_MIPS_GOT_HI16);
9246 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", tempreg, tempreg,
9248 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
9249 BFD_RELOC_MIPS_GOT_LO16, tempreg);
9252 macro_build (NULL, "nop", "");
9253 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
9254 BFD_RELOC_MIPS_GOT16, mips_gp_register);
9256 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j", tempreg,
9257 tempreg, BFD_RELOC_LO16);
9261 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
9262 tempreg, tempreg, breg);
9263 macro_build (&expr1, s, fmt, treg, BFD_RELOC_LO16, tempreg);
9265 else if (mips_big_got && HAVE_NEWABI)
9267 /* If this is a reference to an external symbol, we want
9268 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
9269 add $tempreg,$tempreg,$gp
9270 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
9271 <op> $treg,<ofst>($tempreg)
9272 Otherwise, for local symbols, we want:
9273 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
9274 <op> $treg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_OFST) */
9275 gas_assert (offset_expr.X_op == O_symbol);
9276 expr1.X_add_number = offset_expr.X_add_number;
9277 offset_expr.X_add_number = 0;
9278 if (expr1.X_add_number < -0x8000
9279 || expr1.X_add_number >= 0x8000)
9280 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
9281 relax_start (offset_expr.X_add_symbol);
9282 macro_build (&offset_expr, "lui", LUI_FMT, tempreg,
9283 BFD_RELOC_MIPS_GOT_HI16);
9284 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", tempreg, tempreg,
9286 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
9287 BFD_RELOC_MIPS_GOT_LO16, tempreg);
9289 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
9290 tempreg, tempreg, breg);
9291 macro_build (&expr1, s, fmt, treg, BFD_RELOC_LO16, tempreg);
9294 offset_expr.X_add_number = expr1.X_add_number;
9295 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
9296 BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register);
9298 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
9299 tempreg, tempreg, breg);
9300 macro_build (&offset_expr, s, fmt, treg,
9301 BFD_RELOC_MIPS_GOT_OFST, tempreg);
9311 load_register (treg, &imm_expr, 0);
9315 load_register (treg, &imm_expr, 1);
9319 if (imm_expr.X_op == O_constant)
9322 load_register (AT, &imm_expr, 0);
9323 macro_build (NULL, "mtc1", "t,G", AT, treg);
9328 gas_assert (offset_expr.X_op == O_symbol
9329 && strcmp (segment_name (S_GET_SEGMENT
9330 (offset_expr.X_add_symbol)),
9332 && offset_expr.X_add_number == 0);
9333 macro_build (&offset_expr, "lwc1", "T,o(b)", treg,
9334 BFD_RELOC_MIPS_LITERAL, mips_gp_register);
9339 /* Check if we have a constant in IMM_EXPR. If the GPRs are 64 bits
9340 wide, IMM_EXPR is the entire value. Otherwise IMM_EXPR is the high
9341 order 32 bits of the value and the low order 32 bits are either
9342 zero or in OFFSET_EXPR. */
9343 if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big)
9345 if (HAVE_64BIT_GPRS)
9346 load_register (treg, &imm_expr, 1);
9351 if (target_big_endian)
9363 load_register (hreg, &imm_expr, 0);
9366 if (offset_expr.X_op == O_absent)
9367 move_register (lreg, 0);
9370 gas_assert (offset_expr.X_op == O_constant);
9371 load_register (lreg, &offset_expr, 0);
9378 /* We know that sym is in the .rdata section. First we get the
9379 upper 16 bits of the address. */
9380 if (mips_pic == NO_PIC)
9382 macro_build_lui (&offset_expr, AT);
9387 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", AT,
9388 BFD_RELOC_MIPS_GOT16, mips_gp_register);
9392 /* Now we load the register(s). */
9393 if (HAVE_64BIT_GPRS)
9396 macro_build (&offset_expr, "ld", "t,o(b)", treg, BFD_RELOC_LO16, AT);
9401 macro_build (&offset_expr, "lw", "t,o(b)", treg, BFD_RELOC_LO16, AT);
9404 /* FIXME: How in the world do we deal with the possible
9406 offset_expr.X_add_number += 4;
9407 macro_build (&offset_expr, "lw", "t,o(b)",
9408 treg + 1, BFD_RELOC_LO16, AT);
9414 /* Check if we have a constant in IMM_EXPR. If the FPRs are 64 bits
9415 wide, IMM_EXPR is the entire value and the GPRs are known to be 64
9416 bits wide as well. Otherwise IMM_EXPR is the high order 32 bits of
9417 the value and the low order 32 bits are either zero or in
9419 if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big)
9422 load_register (AT, &imm_expr, HAVE_64BIT_FPRS);
9423 if (HAVE_64BIT_FPRS)
9425 gas_assert (HAVE_64BIT_GPRS);
9426 macro_build (NULL, "dmtc1", "t,S", AT, treg);
9430 macro_build (NULL, "mtc1", "t,G", AT, treg + 1);
9431 if (offset_expr.X_op == O_absent)
9432 macro_build (NULL, "mtc1", "t,G", 0, treg);
9435 gas_assert (offset_expr.X_op == O_constant);
9436 load_register (AT, &offset_expr, 0);
9437 macro_build (NULL, "mtc1", "t,G", AT, treg);
9443 gas_assert (offset_expr.X_op == O_symbol
9444 && offset_expr.X_add_number == 0);
9445 s = segment_name (S_GET_SEGMENT (offset_expr.X_add_symbol));
9446 if (strcmp (s, ".lit8") == 0)
9448 if (CPU_HAS_LDC1_SDC1 (mips_opts.arch) || mips_opts.micromips)
9450 macro_build (&offset_expr, "ldc1", "T,o(b)", treg,
9451 BFD_RELOC_MIPS_LITERAL, mips_gp_register);
9454 breg = mips_gp_register;
9455 r = BFD_RELOC_MIPS_LITERAL;
9460 gas_assert (strcmp (s, RDATA_SECTION_NAME) == 0);
9462 if (mips_pic != NO_PIC)
9463 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", AT,
9464 BFD_RELOC_MIPS_GOT16, mips_gp_register);
9467 /* FIXME: This won't work for a 64 bit address. */
9468 macro_build_lui (&offset_expr, AT);
9471 if (CPU_HAS_LDC1_SDC1 (mips_opts.arch) || mips_opts.micromips)
9473 macro_build (&offset_expr, "ldc1", "T,o(b)",
9474 treg, BFD_RELOC_LO16, AT);
9483 /* Even on a big endian machine $fn comes before $fn+1. We have
9484 to adjust when loading from memory. */
9487 gas_assert (!mips_opts.micromips);
9488 gas_assert (!CPU_HAS_LDC1_SDC1 (mips_opts.arch));
9489 macro_build (&offset_expr, "lwc1", "T,o(b)",
9490 target_big_endian ? treg + 1 : treg, r, breg);
9491 /* FIXME: A possible overflow which I don't know how to deal
9493 offset_expr.X_add_number += 4;
9494 macro_build (&offset_expr, "lwc1", "T,o(b)",
9495 target_big_endian ? treg : treg + 1, r, breg);
9499 gas_assert (!mips_opts.micromips);
9500 gas_assert (!CPU_HAS_LDC1_SDC1 (mips_opts.arch));
9501 /* Even on a big endian machine $fn comes before $fn+1. We have
9502 to adjust when storing to memory. */
9503 macro_build (&offset_expr, "swc1", "T,o(b)",
9504 target_big_endian ? treg + 1 : treg, BFD_RELOC_LO16, breg);
9505 offset_expr.X_add_number += 4;
9506 macro_build (&offset_expr, "swc1", "T,o(b)",
9507 target_big_endian ? treg : treg + 1, BFD_RELOC_LO16, breg);
9511 gas_assert (!mips_opts.micromips);
9513 * The MIPS assembler seems to check for X_add_number not
9514 * being double aligned and generating:
9517 * addiu at,at,%lo(foo+1)
9520 * But, the resulting address is the same after relocation so why
9521 * generate the extra instruction?
9523 /* Itbl support may require additional care here. */
9526 if (CPU_HAS_LDC1_SDC1 (mips_opts.arch))
9535 gas_assert (!mips_opts.micromips);
9536 /* Itbl support may require additional care here. */
9539 if (CPU_HAS_LDC1_SDC1 (mips_opts.arch))
9559 if (HAVE_64BIT_GPRS)
9569 if (HAVE_64BIT_GPRS)
9577 if (offset_expr.X_op != O_symbol
9578 && offset_expr.X_op != O_constant)
9580 as_bad (_("Expression too complex"));
9581 offset_expr.X_op = O_constant;
9584 if (HAVE_32BIT_ADDRESSES
9585 && !IS_SEXT_32BIT_NUM (offset_expr.X_add_number))
9589 sprintf_vma (value, offset_expr.X_add_number);
9590 as_bad (_("Number (0x%s) larger than 32 bits"), value);
9593 /* Even on a big endian machine $fn comes before $fn+1. We have
9594 to adjust when loading from memory. We set coproc if we must
9595 load $fn+1 first. */
9596 /* Itbl support may require additional care here. */
9597 if (!target_big_endian)
9600 if (mips_pic == NO_PIC || offset_expr.X_op == O_constant)
9602 /* If this is a reference to a GP relative symbol, we want
9603 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
9604 <op> $treg+1,<sym>+4($gp) (BFD_RELOC_GPREL16)
9605 If we have a base register, we use this
9607 <op> $treg,<sym>($at) (BFD_RELOC_GPREL16)
9608 <op> $treg+1,<sym>+4($at) (BFD_RELOC_GPREL16)
9609 If this is not a GP relative symbol, we want
9610 lui $at,<sym> (BFD_RELOC_HI16_S)
9611 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
9612 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
9613 If there is a base register, we add it to $at after the
9614 lui instruction. If there is a constant, we always use
9616 if (offset_expr.X_op == O_symbol
9617 && (valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
9618 && !nopic_need_relax (offset_expr.X_add_symbol, 1))
9620 relax_start (offset_expr.X_add_symbol);
9623 tempreg = mips_gp_register;
9627 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
9628 AT, breg, mips_gp_register);
9633 /* Itbl support may require additional care here. */
9634 macro_build (&offset_expr, s, fmt, coproc ? treg + 1 : treg,
9635 BFD_RELOC_GPREL16, tempreg);
9636 offset_expr.X_add_number += 4;
9638 /* Set mips_optimize to 2 to avoid inserting an
9640 hold_mips_optimize = mips_optimize;
9642 /* Itbl support may require additional care here. */
9643 macro_build (&offset_expr, s, fmt, coproc ? treg : treg + 1,
9644 BFD_RELOC_GPREL16, tempreg);
9645 mips_optimize = hold_mips_optimize;
9649 offset_expr.X_add_number -= 4;
9652 macro_build_lui (&offset_expr, AT);
9654 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, breg, AT);
9655 /* Itbl support may require additional care here. */
9656 macro_build (&offset_expr, s, fmt, coproc ? treg + 1 : treg,
9657 BFD_RELOC_LO16, AT);
9658 /* FIXME: How do we handle overflow here? */
9659 offset_expr.X_add_number += 4;
9660 /* Itbl support may require additional care here. */
9661 macro_build (&offset_expr, s, fmt, coproc ? treg : treg + 1,
9662 BFD_RELOC_LO16, AT);
9663 if (mips_relax.sequence)
9666 else if (!mips_big_got)
9668 /* If this is a reference to an external symbol, we want
9669 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
9674 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
9676 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
9677 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
9678 If there is a base register we add it to $at before the
9679 lwc1 instructions. If there is a constant we include it
9680 in the lwc1 instructions. */
9682 expr1.X_add_number = offset_expr.X_add_number;
9683 if (expr1.X_add_number < -0x8000
9684 || expr1.X_add_number >= 0x8000 - 4)
9685 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
9686 load_got_offset (AT, &offset_expr);
9689 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, breg, AT);
9691 /* Set mips_optimize to 2 to avoid inserting an undesired
9693 hold_mips_optimize = mips_optimize;
9696 /* Itbl support may require additional care here. */
9697 relax_start (offset_expr.X_add_symbol);
9698 macro_build (&expr1, s, fmt, coproc ? treg + 1 : treg,
9699 BFD_RELOC_LO16, AT);
9700 expr1.X_add_number += 4;
9701 macro_build (&expr1, s, fmt, coproc ? treg : treg + 1,
9702 BFD_RELOC_LO16, AT);
9704 macro_build (&offset_expr, s, fmt, coproc ? treg + 1 : treg,
9705 BFD_RELOC_LO16, AT);
9706 offset_expr.X_add_number += 4;
9707 macro_build (&offset_expr, s, fmt, coproc ? treg : treg + 1,
9708 BFD_RELOC_LO16, AT);
9711 mips_optimize = hold_mips_optimize;
9713 else if (mips_big_got)
9717 /* If this is a reference to an external symbol, we want
9718 lui $at,<sym> (BFD_RELOC_MIPS_GOT_HI16)
9720 lw $at,<sym>($at) (BFD_RELOC_MIPS_GOT_LO16)
9725 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
9727 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
9728 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
9729 If there is a base register we add it to $at before the
9730 lwc1 instructions. If there is a constant we include it
9731 in the lwc1 instructions. */
9733 expr1.X_add_number = offset_expr.X_add_number;
9734 offset_expr.X_add_number = 0;
9735 if (expr1.X_add_number < -0x8000
9736 || expr1.X_add_number >= 0x8000 - 4)
9737 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
9738 gpdelay = reg_needs_delay (mips_gp_register);
9739 relax_start (offset_expr.X_add_symbol);
9740 macro_build (&offset_expr, "lui", LUI_FMT,
9741 AT, BFD_RELOC_MIPS_GOT_HI16);
9742 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
9743 AT, AT, mips_gp_register);
9744 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
9745 AT, BFD_RELOC_MIPS_GOT_LO16, AT);
9748 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, breg, AT);
9749 /* Itbl support may require additional care here. */
9750 macro_build (&expr1, s, fmt, coproc ? treg + 1 : treg,
9751 BFD_RELOC_LO16, AT);
9752 expr1.X_add_number += 4;
9754 /* Set mips_optimize to 2 to avoid inserting an undesired
9756 hold_mips_optimize = mips_optimize;
9758 /* Itbl support may require additional care here. */
9759 macro_build (&expr1, s, fmt, coproc ? treg : treg + 1,
9760 BFD_RELOC_LO16, AT);
9761 mips_optimize = hold_mips_optimize;
9762 expr1.X_add_number -= 4;
9765 offset_expr.X_add_number = expr1.X_add_number;
9767 macro_build (NULL, "nop", "");
9768 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", AT,
9769 BFD_RELOC_MIPS_GOT16, mips_gp_register);
9772 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, breg, AT);
9773 /* Itbl support may require additional care here. */
9774 macro_build (&offset_expr, s, fmt, coproc ? treg + 1 : treg,
9775 BFD_RELOC_LO16, AT);
9776 offset_expr.X_add_number += 4;
9778 /* Set mips_optimize to 2 to avoid inserting an undesired
9780 hold_mips_optimize = mips_optimize;
9782 /* Itbl support may require additional care here. */
9783 macro_build (&offset_expr, s, fmt, coproc ? treg : treg + 1,
9784 BFD_RELOC_LO16, AT);
9785 mips_optimize = hold_mips_optimize;
9794 s = HAVE_64BIT_GPRS ? "ld" : "lw";
9797 s = HAVE_64BIT_GPRS ? "sd" : "sw";
9799 macro_build (&offset_expr, s, "t,o(b)", treg,
9800 -1, offset_reloc[0], offset_reloc[1], offset_reloc[2],
9802 if (!HAVE_64BIT_GPRS)
9804 offset_expr.X_add_number += 4;
9805 macro_build (&offset_expr, s, "t,o(b)", treg + 1,
9806 -1, offset_reloc[0], offset_reloc[1], offset_reloc[2],
9827 /* New code added to support COPZ instructions.
9828 This code builds table entries out of the macros in mip_opcodes.
9829 R4000 uses interlocks to handle coproc delays.
9830 Other chips (like the R3000) require nops to be inserted for delays.
9832 FIXME: Currently, we require that the user handle delays.
9833 In order to fill delay slots for non-interlocked chips,
9834 we must have a way to specify delays based on the coprocessor.
9835 Eg. 4 cycles if load coproc reg from memory, 1 if in cache, etc.
9836 What are the side-effects of the cop instruction?
9837 What cache support might we have and what are its effects?
9838 Both coprocessor & memory require delays. how long???
9839 What registers are read/set/modified?
9841 If an itbl is provided to interpret cop instructions,
9842 this knowledge can be encoded in the itbl spec. */
9856 gas_assert (!mips_opts.micromips);
9857 /* For now we just do C (same as Cz). The parameter will be
9858 stored in insn_opcode by mips_ip. */
9859 macro_build (NULL, s, "C", ip->insn_opcode);
9863 move_register (dreg, sreg);
9869 if (mips_opts.arch == CPU_R5900)
9871 macro_build (NULL, dbl ? "dmultu" : "multu", "d,s,t", dreg, sreg, treg);
9875 macro_build (NULL, dbl ? "dmultu" : "multu", "s,t", sreg, treg);
9876 macro_build (NULL, "mflo", MFHL_FMT, dreg);
9883 /* The MIPS assembler some times generates shifts and adds. I'm
9884 not trying to be that fancy. GCC should do this for us
9887 load_register (AT, &imm_expr, dbl);
9888 macro_build (NULL, dbl ? "dmult" : "mult", "s,t", sreg, AT);
9889 macro_build (NULL, "mflo", MFHL_FMT, dreg);
9905 load_register (AT, &imm_expr, dbl);
9906 macro_build (NULL, dbl ? "dmult" : "mult", "s,t", sreg, imm ? AT : treg);
9907 macro_build (NULL, "mflo", MFHL_FMT, dreg);
9908 macro_build (NULL, dbl ? "dsra32" : "sra", SHFT_FMT, dreg, dreg, RA);
9909 macro_build (NULL, "mfhi", MFHL_FMT, AT);
9911 macro_build (NULL, "tne", TRAP_FMT, dreg, AT, 6);
9914 if (mips_opts.micromips)
9915 micromips_label_expr (&label_expr);
9917 label_expr.X_add_number = 8;
9918 macro_build (&label_expr, "beq", "s,t,p", dreg, AT);
9919 macro_build (NULL, "nop", "");
9920 macro_build (NULL, "break", BRK_FMT, 6);
9921 if (mips_opts.micromips)
9922 micromips_add_label ();
9925 macro_build (NULL, "mflo", MFHL_FMT, dreg);
9941 load_register (AT, &imm_expr, dbl);
9942 macro_build (NULL, dbl ? "dmultu" : "multu", "s,t",
9943 sreg, imm ? AT : treg);
9944 macro_build (NULL, "mfhi", MFHL_FMT, AT);
9945 macro_build (NULL, "mflo", MFHL_FMT, dreg);
9947 macro_build (NULL, "tne", TRAP_FMT, AT, ZERO, 6);
9950 if (mips_opts.micromips)
9951 micromips_label_expr (&label_expr);
9953 label_expr.X_add_number = 8;
9954 macro_build (&label_expr, "beq", "s,t,p", AT, ZERO);
9955 macro_build (NULL, "nop", "");
9956 macro_build (NULL, "break", BRK_FMT, 6);
9957 if (mips_opts.micromips)
9958 micromips_add_label ();
9964 if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_opts.arch))
9975 macro_build (NULL, "dnegu", "d,w", tempreg, treg);
9976 macro_build (NULL, "drorv", "d,t,s", dreg, sreg, tempreg);
9980 macro_build (NULL, "dsubu", "d,v,t", AT, ZERO, treg);
9981 macro_build (NULL, "dsrlv", "d,t,s", AT, sreg, AT);
9982 macro_build (NULL, "dsllv", "d,t,s", dreg, sreg, treg);
9983 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
9987 if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_opts.arch))
9998 macro_build (NULL, "negu", "d,w", tempreg, treg);
9999 macro_build (NULL, "rorv", "d,t,s", dreg, sreg, tempreg);
10003 macro_build (NULL, "subu", "d,v,t", AT, ZERO, treg);
10004 macro_build (NULL, "srlv", "d,t,s", AT, sreg, AT);
10005 macro_build (NULL, "sllv", "d,t,s", dreg, sreg, treg);
10006 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
10015 if (imm_expr.X_op != O_constant)
10016 as_bad (_("Improper rotate count"));
10017 rot = imm_expr.X_add_number & 0x3f;
10018 if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_opts.arch))
10020 rot = (64 - rot) & 0x3f;
10022 macro_build (NULL, "dror32", SHFT_FMT, dreg, sreg, rot - 32);
10024 macro_build (NULL, "dror", SHFT_FMT, dreg, sreg, rot);
10029 macro_build (NULL, "dsrl", SHFT_FMT, dreg, sreg, 0);
10032 l = (rot < 0x20) ? "dsll" : "dsll32";
10033 rr = ((0x40 - rot) < 0x20) ? "dsrl" : "dsrl32";
10036 macro_build (NULL, l, SHFT_FMT, AT, sreg, rot);
10037 macro_build (NULL, rr, SHFT_FMT, dreg, sreg, (0x20 - rot) & 0x1f);
10038 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
10046 if (imm_expr.X_op != O_constant)
10047 as_bad (_("Improper rotate count"));
10048 rot = imm_expr.X_add_number & 0x1f;
10049 if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_opts.arch))
10051 macro_build (NULL, "ror", SHFT_FMT, dreg, sreg, (32 - rot) & 0x1f);
10056 macro_build (NULL, "srl", SHFT_FMT, dreg, sreg, 0);
10060 macro_build (NULL, "sll", SHFT_FMT, AT, sreg, rot);
10061 macro_build (NULL, "srl", SHFT_FMT, dreg, sreg, (0x20 - rot) & 0x1f);
10062 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
10067 if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_opts.arch))
10069 macro_build (NULL, "drorv", "d,t,s", dreg, sreg, treg);
10073 macro_build (NULL, "dsubu", "d,v,t", AT, ZERO, treg);
10074 macro_build (NULL, "dsllv", "d,t,s", AT, sreg, AT);
10075 macro_build (NULL, "dsrlv", "d,t,s", dreg, sreg, treg);
10076 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
10080 if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_opts.arch))
10082 macro_build (NULL, "rorv", "d,t,s", dreg, sreg, treg);
10086 macro_build (NULL, "subu", "d,v,t", AT, ZERO, treg);
10087 macro_build (NULL, "sllv", "d,t,s", AT, sreg, AT);
10088 macro_build (NULL, "srlv", "d,t,s", dreg, sreg, treg);
10089 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
10098 if (imm_expr.X_op != O_constant)
10099 as_bad (_("Improper rotate count"));
10100 rot = imm_expr.X_add_number & 0x3f;
10101 if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_opts.arch))
10104 macro_build (NULL, "dror32", SHFT_FMT, dreg, sreg, rot - 32);
10106 macro_build (NULL, "dror", SHFT_FMT, dreg, sreg, rot);
10111 macro_build (NULL, "dsrl", SHFT_FMT, dreg, sreg, 0);
10114 rr = (rot < 0x20) ? "dsrl" : "dsrl32";
10115 l = ((0x40 - rot) < 0x20) ? "dsll" : "dsll32";
10118 macro_build (NULL, rr, SHFT_FMT, AT, sreg, rot);
10119 macro_build (NULL, l, SHFT_FMT, dreg, sreg, (0x20 - rot) & 0x1f);
10120 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
10128 if (imm_expr.X_op != O_constant)
10129 as_bad (_("Improper rotate count"));
10130 rot = imm_expr.X_add_number & 0x1f;
10131 if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_opts.arch))
10133 macro_build (NULL, "ror", SHFT_FMT, dreg, sreg, rot);
10138 macro_build (NULL, "srl", SHFT_FMT, dreg, sreg, 0);
10142 macro_build (NULL, "srl", SHFT_FMT, AT, sreg, rot);
10143 macro_build (NULL, "sll", SHFT_FMT, dreg, sreg, (0x20 - rot) & 0x1f);
10144 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
10150 macro_build (&expr1, "sltiu", "t,r,j", dreg, treg, BFD_RELOC_LO16);
10151 else if (treg == 0)
10152 macro_build (&expr1, "sltiu", "t,r,j", dreg, sreg, BFD_RELOC_LO16);
10155 macro_build (NULL, "xor", "d,v,t", dreg, sreg, treg);
10156 macro_build (&expr1, "sltiu", "t,r,j", dreg, dreg, BFD_RELOC_LO16);
10161 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
10163 macro_build (&expr1, "sltiu", "t,r,j", dreg, sreg, BFD_RELOC_LO16);
10168 as_warn (_("Instruction %s: result is always false"),
10169 ip->insn_mo->name);
10170 move_register (dreg, 0);
10173 if (CPU_HAS_SEQ (mips_opts.arch)
10174 && -512 <= imm_expr.X_add_number
10175 && imm_expr.X_add_number < 512)
10177 macro_build (NULL, "seqi", "t,r,+Q", dreg, sreg,
10178 (int) imm_expr.X_add_number);
10181 if (imm_expr.X_op == O_constant
10182 && imm_expr.X_add_number >= 0
10183 && imm_expr.X_add_number < 0x10000)
10185 macro_build (&imm_expr, "xori", "t,r,i", dreg, sreg, BFD_RELOC_LO16);
10187 else if (imm_expr.X_op == O_constant
10188 && imm_expr.X_add_number > -0x8000
10189 && imm_expr.X_add_number < 0)
10191 imm_expr.X_add_number = -imm_expr.X_add_number;
10192 macro_build (&imm_expr, HAVE_32BIT_GPRS ? "addiu" : "daddiu",
10193 "t,r,j", dreg, sreg, BFD_RELOC_LO16);
10195 else if (CPU_HAS_SEQ (mips_opts.arch))
10198 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
10199 macro_build (NULL, "seq", "d,v,t", dreg, sreg, AT);
10204 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
10205 macro_build (NULL, "xor", "d,v,t", dreg, sreg, AT);
10208 macro_build (&expr1, "sltiu", "t,r,j", dreg, dreg, BFD_RELOC_LO16);
10211 case M_SGE: /* sreg >= treg <==> not (sreg < treg) */
10217 macro_build (NULL, s, "d,v,t", dreg, sreg, treg);
10218 macro_build (&expr1, "xori", "t,r,i", dreg, dreg, BFD_RELOC_LO16);
10221 case M_SGE_I: /* sreg >= I <==> not (sreg < I) */
10223 if (imm_expr.X_op == O_constant
10224 && imm_expr.X_add_number >= -0x8000
10225 && imm_expr.X_add_number < 0x8000)
10227 macro_build (&imm_expr, mask == M_SGE_I ? "slti" : "sltiu", "t,r,j",
10228 dreg, sreg, BFD_RELOC_LO16);
10232 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
10233 macro_build (NULL, mask == M_SGE_I ? "slt" : "sltu", "d,v,t",
10237 macro_build (&expr1, "xori", "t,r,i", dreg, dreg, BFD_RELOC_LO16);
10240 case M_SGT: /* sreg > treg <==> treg < sreg */
10246 macro_build (NULL, s, "d,v,t", dreg, treg, sreg);
10249 case M_SGT_I: /* sreg > I <==> I < sreg */
10256 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
10257 macro_build (NULL, s, "d,v,t", dreg, AT, sreg);
10260 case M_SLE: /* sreg <= treg <==> treg >= sreg <==> not (treg < sreg) */
10266 macro_build (NULL, s, "d,v,t", dreg, treg, sreg);
10267 macro_build (&expr1, "xori", "t,r,i", dreg, dreg, BFD_RELOC_LO16);
10270 case M_SLE_I: /* sreg <= I <==> I >= sreg <==> not (I < sreg) */
10277 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
10278 macro_build (NULL, s, "d,v,t", dreg, AT, sreg);
10279 macro_build (&expr1, "xori", "t,r,i", dreg, dreg, BFD_RELOC_LO16);
10283 if (imm_expr.X_op == O_constant
10284 && imm_expr.X_add_number >= -0x8000
10285 && imm_expr.X_add_number < 0x8000)
10287 macro_build (&imm_expr, "slti", "t,r,j", dreg, sreg, BFD_RELOC_LO16);
10291 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
10292 macro_build (NULL, "slt", "d,v,t", dreg, sreg, AT);
10296 if (imm_expr.X_op == O_constant
10297 && imm_expr.X_add_number >= -0x8000
10298 && imm_expr.X_add_number < 0x8000)
10300 macro_build (&imm_expr, "sltiu", "t,r,j", dreg, sreg,
10305 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
10306 macro_build (NULL, "sltu", "d,v,t", dreg, sreg, AT);
10311 macro_build (NULL, "sltu", "d,v,t", dreg, 0, treg);
10312 else if (treg == 0)
10313 macro_build (NULL, "sltu", "d,v,t", dreg, 0, sreg);
10316 macro_build (NULL, "xor", "d,v,t", dreg, sreg, treg);
10317 macro_build (NULL, "sltu", "d,v,t", dreg, 0, dreg);
10322 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
10324 macro_build (NULL, "sltu", "d,v,t", dreg, 0, sreg);
10329 as_warn (_("Instruction %s: result is always true"),
10330 ip->insn_mo->name);
10331 macro_build (&expr1, HAVE_32BIT_GPRS ? "addiu" : "daddiu", "t,r,j",
10332 dreg, 0, BFD_RELOC_LO16);
10335 if (CPU_HAS_SEQ (mips_opts.arch)
10336 && -512 <= imm_expr.X_add_number
10337 && imm_expr.X_add_number < 512)
10339 macro_build (NULL, "snei", "t,r,+Q", dreg, sreg,
10340 (int) imm_expr.X_add_number);
10343 if (imm_expr.X_op == O_constant
10344 && imm_expr.X_add_number >= 0
10345 && imm_expr.X_add_number < 0x10000)
10347 macro_build (&imm_expr, "xori", "t,r,i", dreg, sreg, BFD_RELOC_LO16);
10349 else if (imm_expr.X_op == O_constant
10350 && imm_expr.X_add_number > -0x8000
10351 && imm_expr.X_add_number < 0)
10353 imm_expr.X_add_number = -imm_expr.X_add_number;
10354 macro_build (&imm_expr, HAVE_32BIT_GPRS ? "addiu" : "daddiu",
10355 "t,r,j", dreg, sreg, BFD_RELOC_LO16);
10357 else if (CPU_HAS_SEQ (mips_opts.arch))
10360 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
10361 macro_build (NULL, "sne", "d,v,t", dreg, sreg, AT);
10366 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
10367 macro_build (NULL, "xor", "d,v,t", dreg, sreg, AT);
10370 macro_build (NULL, "sltu", "d,v,t", dreg, 0, dreg);
10385 if (!mips_opts.micromips)
10387 if (imm_expr.X_op == O_constant
10388 && imm_expr.X_add_number > -0x200
10389 && imm_expr.X_add_number <= 0x200)
10391 macro_build (NULL, s, "t,r,.", dreg, sreg, -imm_expr.X_add_number);
10400 if (imm_expr.X_op == O_constant
10401 && imm_expr.X_add_number > -0x8000
10402 && imm_expr.X_add_number <= 0x8000)
10404 imm_expr.X_add_number = -imm_expr.X_add_number;
10405 macro_build (&imm_expr, s, "t,r,j", dreg, sreg, BFD_RELOC_LO16);
10410 load_register (AT, &imm_expr, dbl);
10411 macro_build (NULL, s2, "d,v,t", dreg, sreg, AT);
10433 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
10434 macro_build (NULL, s, "s,t", sreg, AT);
10439 gas_assert (!mips_opts.micromips);
10440 gas_assert (mips_opts.isa == ISA_MIPS1);
10442 sreg = (ip->insn_opcode >> 11) & 0x1f; /* floating reg */
10443 dreg = (ip->insn_opcode >> 06) & 0x1f; /* floating reg */
10446 * Is the double cfc1 instruction a bug in the mips assembler;
10447 * or is there a reason for it?
10449 start_noreorder ();
10450 macro_build (NULL, "cfc1", "t,G", treg, RA);
10451 macro_build (NULL, "cfc1", "t,G", treg, RA);
10452 macro_build (NULL, "nop", "");
10453 expr1.X_add_number = 3;
10454 macro_build (&expr1, "ori", "t,r,i", AT, treg, BFD_RELOC_LO16);
10455 expr1.X_add_number = 2;
10456 macro_build (&expr1, "xori", "t,r,i", AT, AT, BFD_RELOC_LO16);
10457 macro_build (NULL, "ctc1", "t,G", AT, RA);
10458 macro_build (NULL, "nop", "");
10459 macro_build (NULL, mask == M_TRUNCWD ? "cvt.w.d" : "cvt.w.s", "D,S",
10461 macro_build (NULL, "ctc1", "t,G", treg, RA);
10462 macro_build (NULL, "nop", "");
10485 offbits = (mips_opts.micromips ? 12 : 16);
10493 offbits = (mips_opts.micromips ? 12 : 16);
10509 offbits = (mips_opts.micromips ? 12 : 16);
10518 offbits = (mips_opts.micromips ? 12 : 16);
10523 if (!ab && offset_expr.X_add_number >= 0x8000 - off)
10524 as_bad (_("Operand overflow"));
10527 expr1.X_add_number = 0;
10532 load_address (tempreg, ep, &used_at);
10534 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
10535 tempreg, tempreg, breg);
10540 else if (offbits == 12
10541 && (offset_expr.X_op != O_constant
10542 || !IS_SEXT_12BIT_NUM (offset_expr.X_add_number)
10543 || !IS_SEXT_12BIT_NUM (offset_expr.X_add_number + off)))
10547 macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", tempreg, breg,
10548 -1, offset_reloc[0], offset_reloc[1], offset_reloc[2]);
10553 else if (!ust && treg == breg)
10564 if (!target_big_endian)
10565 ep->X_add_number += off;
10567 macro_build (ep, s, "t,o(b)", tempreg, BFD_RELOC_LO16, breg);
10569 macro_build (NULL, s, "t,~(b)",
10570 tempreg, (unsigned long) ep->X_add_number, breg);
10572 if (!target_big_endian)
10573 ep->X_add_number -= off;
10575 ep->X_add_number += off;
10577 macro_build (ep, s2, "t,o(b)", tempreg, BFD_RELOC_LO16, breg);
10579 macro_build (NULL, s2, "t,~(b)",
10580 tempreg, (unsigned long) ep->X_add_number, breg);
10582 /* If necessary, move the result in tempreg to the final destination. */
10583 if (!ust && treg != tempreg)
10585 /* Protect second load's delay slot. */
10587 move_register (treg, tempreg);
10593 if (target_big_endian == ust)
10594 ep->X_add_number += off;
10595 tempreg = ust || ab ? treg : AT;
10596 macro_build (ep, s, "t,o(b)", tempreg, BFD_RELOC_LO16, breg);
10598 /* For halfword transfers we need a temporary register to shuffle
10599 bytes. Unfortunately for M_USH_A we have none available before
10600 the next store as AT holds the base address. We deal with this
10601 case by clobbering TREG and then restoring it as with ULH. */
10602 tempreg = ust == ab ? treg : AT;
10604 macro_build (NULL, "srl", SHFT_FMT, tempreg, treg, 8);
10606 if (target_big_endian == ust)
10607 ep->X_add_number -= off;
10609 ep->X_add_number += off;
10610 macro_build (ep, s2, "t,o(b)", tempreg, BFD_RELOC_LO16, breg);
10612 /* For M_USH_A re-retrieve the LSB. */
10615 if (target_big_endian)
10616 ep->X_add_number += off;
10618 ep->X_add_number -= off;
10619 macro_build (&expr1, "lbu", "t,o(b)", AT, BFD_RELOC_LO16, AT);
10621 /* For ULH and M_USH_A OR the LSB in. */
10624 tempreg = !ab ? AT : treg;
10625 macro_build (NULL, "sll", SHFT_FMT, tempreg, tempreg, 8);
10626 macro_build (NULL, "or", "d,v,t", treg, treg, AT);
10631 /* FIXME: Check if this is one of the itbl macros, since they
10632 are added dynamically. */
10633 as_bad (_("Macro %s not implemented yet"), ip->insn_mo->name);
10636 if (!mips_opts.at && used_at)
10637 as_bad (_("Macro used $at after \".set noat\""));
10640 /* Implement macros in mips16 mode. */
10643 mips16_macro (struct mips_cl_insn *ip)
10646 int xreg, yreg, zreg, tmp;
10649 const char *s, *s2, *s3;
10651 mask = ip->insn_mo->mask;
10653 xreg = MIPS16_EXTRACT_OPERAND (RX, *ip);
10654 yreg = MIPS16_EXTRACT_OPERAND (RY, *ip);
10655 zreg = MIPS16_EXTRACT_OPERAND (RZ, *ip);
10657 expr1.X_op = O_constant;
10658 expr1.X_op_symbol = NULL;
10659 expr1.X_add_symbol = NULL;
10660 expr1.X_add_number = 1;
10679 start_noreorder ();
10680 macro_build (NULL, dbl ? "ddiv" : "div", "0,x,y", xreg, yreg);
10681 expr1.X_add_number = 2;
10682 macro_build (&expr1, "bnez", "x,p", yreg);
10683 macro_build (NULL, "break", "6", 7);
10685 /* FIXME: The normal code checks for of -1 / -0x80000000 here,
10686 since that causes an overflow. We should do that as well,
10687 but I don't see how to do the comparisons without a temporary
10690 macro_build (NULL, s, "x", zreg);
10709 start_noreorder ();
10710 macro_build (NULL, s, "0,x,y", xreg, yreg);
10711 expr1.X_add_number = 2;
10712 macro_build (&expr1, "bnez", "x,p", yreg);
10713 macro_build (NULL, "break", "6", 7);
10715 macro_build (NULL, s2, "x", zreg);
10721 macro_build (NULL, dbl ? "dmultu" : "multu", "x,y", xreg, yreg);
10722 macro_build (NULL, "mflo", "x", zreg);
10730 if (imm_expr.X_op != O_constant)
10731 as_bad (_("Unsupported large constant"));
10732 imm_expr.X_add_number = -imm_expr.X_add_number;
10733 macro_build (&imm_expr, dbl ? "daddiu" : "addiu", "y,x,4", yreg, xreg);
10737 if (imm_expr.X_op != O_constant)
10738 as_bad (_("Unsupported large constant"));
10739 imm_expr.X_add_number = -imm_expr.X_add_number;
10740 macro_build (&imm_expr, "addiu", "x,k", xreg);
10744 if (imm_expr.X_op != O_constant)
10745 as_bad (_("Unsupported large constant"));
10746 imm_expr.X_add_number = -imm_expr.X_add_number;
10747 macro_build (&imm_expr, "daddiu", "y,j", yreg);
10769 goto do_reverse_branch;
10773 goto do_reverse_branch;
10785 goto do_reverse_branch;
10796 macro_build (NULL, s, "x,y", xreg, yreg);
10797 macro_build (&offset_expr, s2, "p");
10824 goto do_addone_branch_i;
10829 goto do_addone_branch_i;
10844 goto do_addone_branch_i;
10850 do_addone_branch_i:
10851 if (imm_expr.X_op != O_constant)
10852 as_bad (_("Unsupported large constant"));
10853 ++imm_expr.X_add_number;
10856 macro_build (&imm_expr, s, s3, xreg);
10857 macro_build (&offset_expr, s2, "p");
10861 expr1.X_add_number = 0;
10862 macro_build (&expr1, "slti", "x,8", yreg);
10864 move_register (xreg, yreg);
10865 expr1.X_add_number = 2;
10866 macro_build (&expr1, "bteqz", "p");
10867 macro_build (NULL, "neg", "x,w", xreg, xreg);
10871 /* For consistency checking, verify that all bits are specified either
10872 by the match/mask part of the instruction definition, or by the
10875 validate_mips_insn (const struct mips_opcode *opc)
10877 const char *p = opc->args;
10879 unsigned long used_bits = opc->mask;
10881 if ((used_bits & opc->match) != opc->match)
10883 as_bad (_("internal: bad mips opcode (mask error): %s %s"),
10884 opc->name, opc->args);
10887 #define USE_BITS(mask,shift) (used_bits |= ((mask) << (shift)))
10897 case '1': USE_BITS (OP_MASK_UDI1, OP_SH_UDI1); break;
10898 case '2': USE_BITS (OP_MASK_UDI2, OP_SH_UDI2); break;
10899 case '3': USE_BITS (OP_MASK_UDI3, OP_SH_UDI3); break;
10900 case '4': USE_BITS (OP_MASK_UDI4, OP_SH_UDI4); break;
10901 case 'A': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
10902 case 'B': USE_BITS (OP_MASK_INSMSB, OP_SH_INSMSB); break;
10903 case 'C': USE_BITS (OP_MASK_EXTMSBD, OP_SH_EXTMSBD); break;
10904 case 'D': USE_BITS (OP_MASK_RD, OP_SH_RD);
10905 USE_BITS (OP_MASK_SEL, OP_SH_SEL); break;
10906 case 'E': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
10907 case 'F': USE_BITS (OP_MASK_INSMSB, OP_SH_INSMSB); break;
10908 case 'G': USE_BITS (OP_MASK_EXTMSBD, OP_SH_EXTMSBD); break;
10909 case 'H': USE_BITS (OP_MASK_EXTMSBD, OP_SH_EXTMSBD); break;
10911 case 'J': USE_BITS (OP_MASK_CODE10, OP_SH_CODE10); break;
10912 case 't': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
10913 case 'T': USE_BITS (OP_MASK_RT, OP_SH_RT);
10914 USE_BITS (OP_MASK_SEL, OP_SH_SEL); break;
10915 case 'x': USE_BITS (OP_MASK_BBITIND, OP_SH_BBITIND); break;
10916 case 'X': USE_BITS (OP_MASK_BBITIND, OP_SH_BBITIND); break;
10917 case 'p': USE_BITS (OP_MASK_CINSPOS, OP_SH_CINSPOS); break;
10918 case 'P': USE_BITS (OP_MASK_CINSPOS, OP_SH_CINSPOS); break;
10919 case 'Q': USE_BITS (OP_MASK_SEQI, OP_SH_SEQI); break;
10920 case 's': USE_BITS (OP_MASK_CINSLM1, OP_SH_CINSLM1); break;
10921 case 'S': USE_BITS (OP_MASK_CINSLM1, OP_SH_CINSLM1); break;
10922 case 'z': USE_BITS (OP_MASK_RZ, OP_SH_RZ); break;
10923 case 'Z': USE_BITS (OP_MASK_FZ, OP_SH_FZ); break;
10924 case 'a': USE_BITS (OP_MASK_OFFSET_A, OP_SH_OFFSET_A); break;
10925 case 'b': USE_BITS (OP_MASK_OFFSET_B, OP_SH_OFFSET_B); break;
10926 case 'c': USE_BITS (OP_MASK_OFFSET_C, OP_SH_OFFSET_C); break;
10927 case 'j': USE_BITS (OP_MASK_EVAOFFSET, OP_SH_EVAOFFSET); break;
10930 as_bad (_("internal: bad mips opcode (unknown extension operand type `+%c'): %s %s"),
10931 c, opc->name, opc->args);
10935 case '<': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
10936 case '>': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
10938 case 'B': USE_BITS (OP_MASK_CODE20, OP_SH_CODE20); break;
10939 case 'C': USE_BITS (OP_MASK_COPZ, OP_SH_COPZ); break;
10940 case 'D': USE_BITS (OP_MASK_FD, OP_SH_FD); break;
10941 case 'E': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
10943 case 'G': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
10944 case 'H': USE_BITS (OP_MASK_SEL, OP_SH_SEL); break;
10946 case 'J': USE_BITS (OP_MASK_CODE19, OP_SH_CODE19); break;
10947 case 'K': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
10949 case 'M': USE_BITS (OP_MASK_CCC, OP_SH_CCC); break;
10950 case 'N': USE_BITS (OP_MASK_BCC, OP_SH_BCC); break;
10951 case 'O': USE_BITS (OP_MASK_ALN, OP_SH_ALN); break;
10952 case 'Q': USE_BITS (OP_MASK_VSEL, OP_SH_VSEL);
10953 USE_BITS (OP_MASK_FT, OP_SH_FT); break;
10954 case 'R': USE_BITS (OP_MASK_FR, OP_SH_FR); break;
10955 case 'S': USE_BITS (OP_MASK_FS, OP_SH_FS); break;
10956 case 'T': USE_BITS (OP_MASK_FT, OP_SH_FT); break;
10957 case 'V': USE_BITS (OP_MASK_FS, OP_SH_FS); break;
10958 case 'W': USE_BITS (OP_MASK_FT, OP_SH_FT); break;
10959 case 'X': USE_BITS (OP_MASK_FD, OP_SH_FD); break;
10960 case 'Y': USE_BITS (OP_MASK_FS, OP_SH_FS); break;
10961 case 'Z': USE_BITS (OP_MASK_FT, OP_SH_FT); break;
10962 case 'a': USE_BITS (OP_MASK_TARGET, OP_SH_TARGET); break;
10963 case 'b': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
10964 case 'c': USE_BITS (OP_MASK_CODE, OP_SH_CODE); break;
10965 case 'd': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
10967 case 'h': USE_BITS (OP_MASK_PREFX, OP_SH_PREFX); break;
10968 case 'i': USE_BITS (OP_MASK_IMMEDIATE, OP_SH_IMMEDIATE); break;
10969 case 'j': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
10970 case 'k': USE_BITS (OP_MASK_CACHE, OP_SH_CACHE); break;
10972 case 'o': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
10973 case 'p': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
10974 case 'q': USE_BITS (OP_MASK_CODE2, OP_SH_CODE2); break;
10975 case 'r': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
10976 case 's': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
10977 case 't': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
10978 case 'u': USE_BITS (OP_MASK_IMMEDIATE, OP_SH_IMMEDIATE); break;
10979 case 'v': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
10980 case 'w': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
10983 case 'P': USE_BITS (OP_MASK_PERFREG, OP_SH_PERFREG); break;
10984 case 'U': USE_BITS (OP_MASK_RD, OP_SH_RD);
10985 USE_BITS (OP_MASK_RT, OP_SH_RT); break;
10986 case 'e': USE_BITS (OP_MASK_VECBYTE, OP_SH_VECBYTE); break;
10987 case '%': USE_BITS (OP_MASK_VECALIGN, OP_SH_VECALIGN); break;
10990 case '1': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
10991 case '2': USE_BITS (OP_MASK_BP, OP_SH_BP); break;
10992 case '3': USE_BITS (OP_MASK_SA3, OP_SH_SA3); break;
10993 case '4': USE_BITS (OP_MASK_SA4, OP_SH_SA4); break;
10994 case '5': USE_BITS (OP_MASK_IMM8, OP_SH_IMM8); break;
10995 case '6': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
10996 case '7': USE_BITS (OP_MASK_DSPACC, OP_SH_DSPACC); break;
10997 case '8': USE_BITS (OP_MASK_WRDSP, OP_SH_WRDSP); break;
10998 case '9': USE_BITS (OP_MASK_DSPACC_S, OP_SH_DSPACC_S);break;
10999 case '0': USE_BITS (OP_MASK_DSPSFT, OP_SH_DSPSFT); break;
11000 case '\'': USE_BITS (OP_MASK_RDDSP, OP_SH_RDDSP); break;
11001 case ':': USE_BITS (OP_MASK_DSPSFT_7, OP_SH_DSPSFT_7);break;
11002 case '@': USE_BITS (OP_MASK_IMM10, OP_SH_IMM10); break;
11003 case '!': USE_BITS (OP_MASK_MT_U, OP_SH_MT_U); break;
11004 case '$': USE_BITS (OP_MASK_MT_H, OP_SH_MT_H); break;
11005 case '*': USE_BITS (OP_MASK_MTACC_T, OP_SH_MTACC_T); break;
11006 case '&': USE_BITS (OP_MASK_MTACC_D, OP_SH_MTACC_D); break;
11007 case '\\': USE_BITS (OP_MASK_3BITPOS, OP_SH_3BITPOS); break;
11008 case '~': USE_BITS (OP_MASK_OFFSET12, OP_SH_OFFSET12); break;
11009 case 'g': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
11011 as_bad (_("internal: bad mips opcode (unknown operand type `%c'): %s %s"),
11012 c, opc->name, opc->args);
11016 if (used_bits != 0xffffffff)
11018 as_bad (_("internal: bad mips opcode (bits 0x%lx undefined): %s %s"),
11019 ~used_bits & 0xffffffff, opc->name, opc->args);
11025 /* For consistency checking, verify that the length implied matches the
11026 major opcode and that all bits are specified either by the match/mask
11027 part of the instruction definition, or by the operand list. */
11030 validate_micromips_insn (const struct mips_opcode *opc)
11032 unsigned long match = opc->match;
11033 unsigned long mask = opc->mask;
11034 const char *p = opc->args;
11035 unsigned long insn_bits;
11036 unsigned long used_bits;
11037 unsigned long major;
11038 unsigned int length;
11042 if ((mask & match) != match)
11044 as_bad (_("Internal error: bad microMIPS opcode (mask error): %s %s"),
11045 opc->name, opc->args);
11048 length = micromips_insn_length (opc);
11049 if (length != 2 && length != 4)
11051 as_bad (_("Internal error: bad microMIPS opcode (incorrect length: %u): "
11052 "%s %s"), length, opc->name, opc->args);
11055 major = match >> (10 + 8 * (length - 2));
11056 if ((length == 2 && (major & 7) != 1 && (major & 6) != 2)
11057 || (length == 4 && (major & 7) != 0 && (major & 4) != 4))
11059 as_bad (_("Internal error: bad microMIPS opcode "
11060 "(opcode/length mismatch): %s %s"), opc->name, opc->args);
11064 /* Shift piecewise to avoid an overflow where unsigned long is 32-bit. */
11065 insn_bits = 1 << 4 * length;
11066 insn_bits <<= 4 * length;
11069 #define USE_BITS(field) \
11070 (used_bits |= MICROMIPSOP_MASK_##field << MICROMIPSOP_SH_##field)
11081 case 'A': USE_BITS (EXTLSB); break;
11082 case 'B': USE_BITS (INSMSB); break;
11083 case 'C': USE_BITS (EXTMSBD); break;
11084 case 'D': USE_BITS (RS); USE_BITS (SEL); break;
11085 case 'E': USE_BITS (EXTLSB); break;
11086 case 'F': USE_BITS (INSMSB); break;
11087 case 'G': USE_BITS (EXTMSBD); break;
11088 case 'H': USE_BITS (EXTMSBD); break;
11089 case 'j': USE_BITS (EVAOFFSET); break;
11091 as_bad (_("Internal error: bad mips opcode "
11092 "(unknown extension operand type `%c%c'): %s %s"),
11093 e, c, opc->name, opc->args);
11101 case 'A': USE_BITS (IMMA); break;
11102 case 'B': USE_BITS (IMMB); break;
11103 case 'C': USE_BITS (IMMC); break;
11104 case 'D': USE_BITS (IMMD); break;
11105 case 'E': USE_BITS (IMME); break;
11106 case 'F': USE_BITS (IMMF); break;
11107 case 'G': USE_BITS (IMMG); break;
11108 case 'H': USE_BITS (IMMH); break;
11109 case 'I': USE_BITS (IMMI); break;
11110 case 'J': USE_BITS (IMMJ); break;
11111 case 'L': USE_BITS (IMML); break;
11112 case 'M': USE_BITS (IMMM); break;
11113 case 'N': USE_BITS (IMMN); break;
11114 case 'O': USE_BITS (IMMO); break;
11115 case 'P': USE_BITS (IMMP); break;
11116 case 'Q': USE_BITS (IMMQ); break;
11117 case 'U': USE_BITS (IMMU); break;
11118 case 'W': USE_BITS (IMMW); break;
11119 case 'X': USE_BITS (IMMX); break;
11120 case 'Y': USE_BITS (IMMY); break;
11123 case 'b': USE_BITS (MB); break;
11124 case 'c': USE_BITS (MC); break;
11125 case 'd': USE_BITS (MD); break;
11126 case 'e': USE_BITS (ME); break;
11127 case 'f': USE_BITS (MF); break;
11128 case 'g': USE_BITS (MG); break;
11129 case 'h': USE_BITS (MH); break;
11130 case 'i': USE_BITS (MI); break;
11131 case 'j': USE_BITS (MJ); break;
11132 case 'l': USE_BITS (ML); break;
11133 case 'm': USE_BITS (MM); break;
11134 case 'n': USE_BITS (MN); break;
11135 case 'p': USE_BITS (MP); break;
11136 case 'q': USE_BITS (MQ); break;
11144 as_bad (_("Internal error: bad mips opcode "
11145 "(unknown extension operand type `%c%c'): %s %s"),
11146 e, c, opc->name, opc->args);
11150 case '.': USE_BITS (OFFSET10); break;
11151 case '1': USE_BITS (STYPE); break;
11152 case '2': USE_BITS (BP); break;
11153 case '3': USE_BITS (SA3); break;
11154 case '4': USE_BITS (SA4); break;
11155 case '5': USE_BITS (IMM8); break;
11156 case '6': USE_BITS (RS); break;
11157 case '7': USE_BITS (DSPACC); break;
11158 case '8': USE_BITS (WRDSP); break;
11159 case '0': USE_BITS (DSPSFT); break;
11160 case '<': USE_BITS (SHAMT); break;
11161 case '>': USE_BITS (SHAMT); break;
11162 case '@': USE_BITS (IMM10); break;
11163 case 'B': USE_BITS (CODE10); break;
11164 case 'C': USE_BITS (COPZ); break;
11165 case 'D': USE_BITS (FD); break;
11166 case 'E': USE_BITS (RT); break;
11167 case 'G': USE_BITS (RS); break;
11168 case 'H': USE_BITS (SEL); break;
11169 case 'K': USE_BITS (RS); break;
11170 case 'M': USE_BITS (CCC); break;
11171 case 'N': USE_BITS (BCC); break;
11172 case 'R': USE_BITS (FR); break;
11173 case 'S': USE_BITS (FS); break;
11174 case 'T': USE_BITS (FT); break;
11175 case 'V': USE_BITS (FS); break;
11176 case '\\': USE_BITS (3BITPOS); break;
11177 case '^': USE_BITS (RD); break;
11178 case 'a': USE_BITS (TARGET); break;
11179 case 'b': USE_BITS (RS); break;
11180 case 'c': USE_BITS (CODE); break;
11181 case 'd': USE_BITS (RD); break;
11182 case 'h': USE_BITS (PREFX); break;
11183 case 'i': USE_BITS (IMMEDIATE); break;
11184 case 'j': USE_BITS (DELTA); break;
11185 case 'k': USE_BITS (CACHE); break;
11186 case 'n': USE_BITS (RT); break;
11187 case 'o': USE_BITS (DELTA); break;
11188 case 'p': USE_BITS (DELTA); break;
11189 case 'q': USE_BITS (CODE2); break;
11190 case 'r': USE_BITS (RS); break;
11191 case 's': USE_BITS (RS); break;
11192 case 't': USE_BITS (RT); break;
11193 case 'u': USE_BITS (IMMEDIATE); break;
11194 case 'v': USE_BITS (RS); break;
11195 case 'w': USE_BITS (RT); break;
11196 case 'y': USE_BITS (RS3); break;
11198 case '|': USE_BITS (TRAP); break;
11199 case '~': USE_BITS (OFFSET12); break;
11201 as_bad (_("Internal error: bad microMIPS opcode "
11202 "(unknown operand type `%c'): %s %s"),
11203 c, opc->name, opc->args);
11207 if (used_bits != insn_bits)
11209 if (~used_bits & insn_bits)
11210 as_bad (_("Internal error: bad microMIPS opcode "
11211 "(bits 0x%lx undefined): %s %s"),
11212 ~used_bits & insn_bits, opc->name, opc->args);
11213 if (used_bits & ~insn_bits)
11214 as_bad (_("Internal error: bad microMIPS opcode "
11215 "(bits 0x%lx defined): %s %s"),
11216 used_bits & ~insn_bits, opc->name, opc->args);
11222 /* UDI immediates. */
11223 struct mips_immed {
11225 unsigned int shift;
11226 unsigned long mask;
11230 static const struct mips_immed mips_immed[] = {
11231 { '1', OP_SH_UDI1, OP_MASK_UDI1, 0},
11232 { '2', OP_SH_UDI2, OP_MASK_UDI2, 0},
11233 { '3', OP_SH_UDI3, OP_MASK_UDI3, 0},
11234 { '4', OP_SH_UDI4, OP_MASK_UDI4, 0},
11238 /* Check whether an odd floating-point register is allowed. */
11240 mips_oddfpreg_ok (const struct mips_opcode *insn, int argnum)
11242 const char *s = insn->name;
11244 if (insn->pinfo == INSN_MACRO)
11245 /* Let a macro pass, we'll catch it later when it is expanded. */
11248 if (ISA_HAS_ODD_SINGLE_FPR (mips_opts.isa) || (mips_opts.arch == CPU_R5900))
11250 /* Allow odd registers for single-precision ops. */
11251 switch (insn->pinfo & (FP_S | FP_D))
11255 return 1; /* both single precision - ok */
11257 return 0; /* both double precision - fail */
11262 /* Cvt.w.x and cvt.x.w allow an odd register for a 'w' or 's' operand. */
11263 s = strchr (insn->name, '.');
11265 s = s != NULL ? strchr (s + 1, '.') : NULL;
11266 return (s != NULL && (s[1] == 'w' || s[1] == 's'));
11269 /* Single-precision coprocessor loads and moves are OK too. */
11270 if ((insn->pinfo & FP_S)
11271 && (insn->pinfo & (INSN_COPROC_MEMORY_DELAY | INSN_STORE_MEMORY
11272 | INSN_LOAD_COPROC_DELAY | INSN_COPROC_MOVE_DELAY)))
11278 /* Check if EXPR is a constant between MIN (inclusive) and MAX (exclusive)
11279 taking bits from BIT up. */
11281 expr_const_in_range (expressionS *ep, offsetT min, offsetT max, int bit)
11283 return (ep->X_op == O_constant
11284 && (ep->X_add_number & ((1 << bit) - 1)) == 0
11285 && ep->X_add_number >= min << bit
11286 && ep->X_add_number < max << bit);
11289 /* This routine assembles an instruction into its binary format. As a
11290 side effect, it sets one of the global variables imm_reloc or
11291 offset_reloc to the type of relocation to do if one of the operands
11292 is an address expression. */
11295 mips_ip (char *str, struct mips_cl_insn *ip)
11297 bfd_boolean wrong_delay_slot_insns = FALSE;
11298 bfd_boolean need_delay_slot_ok = TRUE;
11299 struct mips_opcode *firstinsn = NULL;
11300 const struct mips_opcode *past;
11301 struct hash_control *hash;
11305 struct mips_opcode *insn;
11307 unsigned int regno;
11308 unsigned int lastregno;
11309 unsigned int destregno = 0;
11310 unsigned int lastpos = 0;
11311 unsigned int limlo, limhi;
11314 offsetT min_range, max_range;
11318 unsigned int rtype;
11324 if (mips_opts.micromips)
11326 hash = micromips_op_hash;
11327 past = µmips_opcodes[bfd_micromips_num_opcodes];
11332 past = &mips_opcodes[NUMOPCODES];
11334 forced_insn_length = 0;
11337 /* We first try to match an instruction up to a space or to the end. */
11338 for (end = 0; str[end] != '\0' && !ISSPACE (str[end]); end++)
11341 /* Make a copy of the instruction so that we can fiddle with it. */
11342 name = alloca (end + 1);
11343 memcpy (name, str, end);
11348 insn = (struct mips_opcode *) hash_find (hash, name);
11350 if (insn != NULL || !mips_opts.micromips)
11352 if (forced_insn_length)
11355 /* See if there's an instruction size override suffix,
11356 either `16' or `32', at the end of the mnemonic proper,
11357 that defines the operation, i.e. before the first `.'
11358 character if any. Strip it and retry. */
11359 dot = strchr (name, '.');
11360 opend = dot != NULL ? dot - name : end;
11363 if (name[opend - 2] == '1' && name[opend - 1] == '6')
11364 forced_insn_length = 2;
11365 else if (name[opend - 2] == '3' && name[opend - 1] == '2')
11366 forced_insn_length = 4;
11369 memcpy (name + opend - 2, name + opend, end - opend + 1);
11373 insn_error = _("Unrecognized opcode");
11377 /* For microMIPS instructions placed in a fixed-length branch delay slot
11378 we make up to two passes over the relevant fragment of the opcode
11379 table. First we try instructions that meet the delay slot's length
11380 requirement. If none matched, then we retry with the remaining ones
11381 and if one matches, then we use it and then issue an appropriate
11382 warning later on. */
11383 argsStart = s = str + end;
11386 bfd_boolean delay_slot_ok;
11387 bfd_boolean size_ok;
11390 gas_assert (strcmp (insn->name, name) == 0);
11392 ok = is_opcode_valid (insn);
11393 size_ok = is_size_valid (insn);
11394 delay_slot_ok = is_delay_slot_valid (insn);
11395 if (!delay_slot_ok && !wrong_delay_slot_insns)
11398 wrong_delay_slot_insns = TRUE;
11400 if (!ok || !size_ok || delay_slot_ok != need_delay_slot_ok)
11402 static char buf[256];
11404 if (insn + 1 < past && strcmp (insn->name, insn[1].name) == 0)
11409 if (wrong_delay_slot_insns && need_delay_slot_ok)
11411 gas_assert (firstinsn);
11412 need_delay_slot_ok = FALSE;
11422 sprintf (buf, _("Opcode not supported on this processor: %s (%s)"),
11423 mips_cpu_info_from_arch (mips_opts.arch)->name,
11424 mips_cpu_info_from_isa (mips_opts.isa)->name);
11426 sprintf (buf, _("Unrecognized %u-bit version of microMIPS opcode"),
11427 8 * forced_insn_length);
11433 create_insn (ip, insn);
11436 lastregno = 0xffffffff;
11437 for (args = insn->args;; ++args)
11441 s += strspn (s, " \t");
11445 case '\0': /* end of args */
11451 /* DSP 2-bit unsigned immediate in bit 11 (for standard MIPS
11452 code) or 14 (for microMIPS code). */
11453 my_getExpression (&imm_expr, s);
11454 check_absolute_expr (ip, &imm_expr);
11455 if ((unsigned long) imm_expr.X_add_number != 1
11456 && (unsigned long) imm_expr.X_add_number != 3)
11458 as_bad (_("BALIGN immediate not 1 or 3 (%lu)"),
11459 (unsigned long) imm_expr.X_add_number);
11461 INSERT_OPERAND (mips_opts.micromips,
11462 BP, *ip, imm_expr.X_add_number);
11463 imm_expr.X_op = O_absent;
11468 /* DSP 3-bit unsigned immediate in bit 13 (for standard MIPS
11469 code) or 21 (for microMIPS code). */
11471 unsigned long mask = (mips_opts.micromips
11472 ? MICROMIPSOP_MASK_SA3 : OP_MASK_SA3);
11474 my_getExpression (&imm_expr, s);
11475 check_absolute_expr (ip, &imm_expr);
11476 if ((unsigned long) imm_expr.X_add_number > mask)
11477 as_bad (_("DSP immediate not in range 0..%lu (%lu)"),
11478 mask, (unsigned long) imm_expr.X_add_number);
11479 INSERT_OPERAND (mips_opts.micromips,
11480 SA3, *ip, imm_expr.X_add_number);
11481 imm_expr.X_op = O_absent;
11487 /* DSP 4-bit unsigned immediate in bit 12 (for standard MIPS
11488 code) or 21 (for microMIPS code). */
11490 unsigned long mask = (mips_opts.micromips
11491 ? MICROMIPSOP_MASK_SA4 : OP_MASK_SA4);
11493 my_getExpression (&imm_expr, s);
11494 check_absolute_expr (ip, &imm_expr);
11495 if ((unsigned long) imm_expr.X_add_number > mask)
11496 as_bad (_("DSP immediate not in range 0..%lu (%lu)"),
11497 mask, (unsigned long) imm_expr.X_add_number);
11498 INSERT_OPERAND (mips_opts.micromips,
11499 SA4, *ip, imm_expr.X_add_number);
11500 imm_expr.X_op = O_absent;
11506 /* DSP 8-bit unsigned immediate in bit 13 (for standard MIPS
11507 code) or 16 (for microMIPS code). */
11509 unsigned long mask = (mips_opts.micromips
11510 ? MICROMIPSOP_MASK_IMM8 : OP_MASK_IMM8);
11512 my_getExpression (&imm_expr, s);
11513 check_absolute_expr (ip, &imm_expr);
11514 if ((unsigned long) imm_expr.X_add_number > mask)
11515 as_bad (_("DSP immediate not in range 0..%lu (%lu)"),
11516 mask, (unsigned long) imm_expr.X_add_number);
11517 INSERT_OPERAND (mips_opts.micromips,
11518 IMM8, *ip, imm_expr.X_add_number);
11519 imm_expr.X_op = O_absent;
11525 /* DSP 5-bit unsigned immediate in bit 16 (for standard MIPS
11526 code) or 21 (for microMIPS code). */
11528 unsigned long mask = (mips_opts.micromips
11529 ? MICROMIPSOP_MASK_RS : OP_MASK_RS);
11531 my_getExpression (&imm_expr, s);
11532 check_absolute_expr (ip, &imm_expr);
11533 if ((unsigned long) imm_expr.X_add_number > mask)
11534 as_bad (_("DSP immediate not in range 0..%lu (%lu)"),
11535 mask, (unsigned long) imm_expr.X_add_number);
11536 INSERT_OPERAND (mips_opts.micromips,
11537 RS, *ip, imm_expr.X_add_number);
11538 imm_expr.X_op = O_absent;
11543 case '7': /* Four DSP accumulators in bits 11,12. */
11544 if (s[0] == '$' && s[1] == 'a' && s[2] == 'c'
11545 && s[3] >= '0' && s[3] <= '3')
11547 regno = s[3] - '0';
11549 INSERT_OPERAND (mips_opts.micromips, DSPACC, *ip, regno);
11553 as_bad (_("Invalid dsp acc register"));
11557 /* DSP 6-bit unsigned immediate in bit 11 (for standard MIPS
11558 code) or 14 (for microMIPS code). */
11560 unsigned long mask = (mips_opts.micromips
11561 ? MICROMIPSOP_MASK_WRDSP
11564 my_getExpression (&imm_expr, s);
11565 check_absolute_expr (ip, &imm_expr);
11566 if ((unsigned long) imm_expr.X_add_number > mask)
11567 as_bad (_("DSP immediate not in range 0..%lu (%lu)"),
11568 mask, (unsigned long) imm_expr.X_add_number);
11569 INSERT_OPERAND (mips_opts.micromips,
11570 WRDSP, *ip, imm_expr.X_add_number);
11571 imm_expr.X_op = O_absent;
11576 case '9': /* Four DSP accumulators in bits 21,22. */
11577 gas_assert (!mips_opts.micromips);
11578 if (s[0] == '$' && s[1] == 'a' && s[2] == 'c'
11579 && s[3] >= '0' && s[3] <= '3')
11581 regno = s[3] - '0';
11583 INSERT_OPERAND (0, DSPACC_S, *ip, regno);
11587 as_bad (_("Invalid dsp acc register"));
11591 /* DSP 6-bit signed immediate in bit 16 (for standard MIPS
11592 code) or 20 (for microMIPS code). */
11594 long mask = (mips_opts.micromips
11595 ? MICROMIPSOP_MASK_DSPSFT : OP_MASK_DSPSFT);
11597 my_getExpression (&imm_expr, s);
11598 check_absolute_expr (ip, &imm_expr);
11599 min_range = -((mask + 1) >> 1);
11600 max_range = ((mask + 1) >> 1) - 1;
11601 if (imm_expr.X_add_number < min_range
11602 || imm_expr.X_add_number > max_range)
11603 as_bad (_("DSP immediate not in range %ld..%ld (%ld)"),
11604 (long) min_range, (long) max_range,
11605 (long) imm_expr.X_add_number);
11606 INSERT_OPERAND (mips_opts.micromips,
11607 DSPSFT, *ip, imm_expr.X_add_number);
11608 imm_expr.X_op = O_absent;
11613 case '\'': /* DSP 6-bit unsigned immediate in bit 16. */
11614 gas_assert (!mips_opts.micromips);
11615 my_getExpression (&imm_expr, s);
11616 check_absolute_expr (ip, &imm_expr);
11617 if (imm_expr.X_add_number & ~OP_MASK_RDDSP)
11619 as_bad (_("DSP immediate not in range 0..%d (%lu)"),
11621 (unsigned long) imm_expr.X_add_number);
11623 INSERT_OPERAND (0, RDDSP, *ip, imm_expr.X_add_number);
11624 imm_expr.X_op = O_absent;
11628 case ':': /* DSP 7-bit signed immediate in bit 19. */
11629 gas_assert (!mips_opts.micromips);
11630 my_getExpression (&imm_expr, s);
11631 check_absolute_expr (ip, &imm_expr);
11632 min_range = -((OP_MASK_DSPSFT_7 + 1) >> 1);
11633 max_range = ((OP_MASK_DSPSFT_7 + 1) >> 1) - 1;
11634 if (imm_expr.X_add_number < min_range ||
11635 imm_expr.X_add_number > max_range)
11637 as_bad (_("DSP immediate not in range %ld..%ld (%ld)"),
11638 (long) min_range, (long) max_range,
11639 (long) imm_expr.X_add_number);
11641 INSERT_OPERAND (0, DSPSFT_7, *ip, imm_expr.X_add_number);
11642 imm_expr.X_op = O_absent;
11646 case '@': /* DSP 10-bit signed immediate in bit 16. */
11648 long mask = (mips_opts.micromips
11649 ? MICROMIPSOP_MASK_IMM10 : OP_MASK_IMM10);
11651 my_getExpression (&imm_expr, s);
11652 check_absolute_expr (ip, &imm_expr);
11653 min_range = -((mask + 1) >> 1);
11654 max_range = ((mask + 1) >> 1) - 1;
11655 if (imm_expr.X_add_number < min_range
11656 || imm_expr.X_add_number > max_range)
11657 as_bad (_("DSP immediate not in range %ld..%ld (%ld)"),
11658 (long) min_range, (long) max_range,
11659 (long) imm_expr.X_add_number);
11660 INSERT_OPERAND (mips_opts.micromips,
11661 IMM10, *ip, imm_expr.X_add_number);
11662 imm_expr.X_op = O_absent;
11667 case '^': /* DSP 5-bit unsigned immediate in bit 11. */
11668 gas_assert (mips_opts.micromips);
11669 my_getExpression (&imm_expr, s);
11670 check_absolute_expr (ip, &imm_expr);
11671 if (imm_expr.X_add_number & ~MICROMIPSOP_MASK_RD)
11672 as_bad (_("DSP immediate not in range 0..%d (%lu)"),
11673 MICROMIPSOP_MASK_RD,
11674 (unsigned long) imm_expr.X_add_number);
11675 INSERT_OPERAND (1, RD, *ip, imm_expr.X_add_number);
11676 imm_expr.X_op = O_absent;
11680 case '!': /* MT usermode flag bit. */
11681 gas_assert (!mips_opts.micromips);
11682 my_getExpression (&imm_expr, s);
11683 check_absolute_expr (ip, &imm_expr);
11684 if (imm_expr.X_add_number & ~OP_MASK_MT_U)
11685 as_bad (_("MT usermode bit not 0 or 1 (%lu)"),
11686 (unsigned long) imm_expr.X_add_number);
11687 INSERT_OPERAND (0, MT_U, *ip, imm_expr.X_add_number);
11688 imm_expr.X_op = O_absent;
11692 case '$': /* MT load high flag bit. */
11693 gas_assert (!mips_opts.micromips);
11694 my_getExpression (&imm_expr, s);
11695 check_absolute_expr (ip, &imm_expr);
11696 if (imm_expr.X_add_number & ~OP_MASK_MT_H)
11697 as_bad (_("MT load high bit not 0 or 1 (%lu)"),
11698 (unsigned long) imm_expr.X_add_number);
11699 INSERT_OPERAND (0, MT_H, *ip, imm_expr.X_add_number);
11700 imm_expr.X_op = O_absent;
11704 case '*': /* Four DSP accumulators in bits 18,19. */
11705 gas_assert (!mips_opts.micromips);
11706 if (s[0] == '$' && s[1] == 'a' && s[2] == 'c' &&
11707 s[3] >= '0' && s[3] <= '3')
11709 regno = s[3] - '0';
11711 INSERT_OPERAND (0, MTACC_T, *ip, regno);
11715 as_bad (_("Invalid dsp/smartmips acc register"));
11718 case '&': /* Four DSP accumulators in bits 13,14. */
11719 gas_assert (!mips_opts.micromips);
11720 if (s[0] == '$' && s[1] == 'a' && s[2] == 'c' &&
11721 s[3] >= '0' && s[3] <= '3')
11723 regno = s[3] - '0';
11725 INSERT_OPERAND (0, MTACC_D, *ip, regno);
11729 as_bad (_("Invalid dsp/smartmips acc register"));
11732 case '\\': /* 3-bit bit position. */
11734 unsigned long mask = (mips_opts.micromips
11735 ? MICROMIPSOP_MASK_3BITPOS
11736 : OP_MASK_3BITPOS);
11738 my_getExpression (&imm_expr, s);
11739 check_absolute_expr (ip, &imm_expr);
11740 if ((unsigned long) imm_expr.X_add_number > mask)
11741 as_warn (_("Bit position for %s not in range 0..%lu (%lu)"),
11743 mask, (unsigned long) imm_expr.X_add_number);
11744 INSERT_OPERAND (mips_opts.micromips,
11745 3BITPOS, *ip, imm_expr.X_add_number);
11746 imm_expr.X_op = O_absent;
11760 INSERT_OPERAND (mips_opts.micromips, RS, *ip, lastregno);
11764 INSERT_OPERAND (mips_opts.micromips, RT, *ip, lastregno);
11768 gas_assert (!mips_opts.micromips);
11769 INSERT_OPERAND (0, FT, *ip, lastregno);
11773 INSERT_OPERAND (mips_opts.micromips, FS, *ip, lastregno);
11779 /* Handle optional base register.
11780 Either the base register is omitted or
11781 we must have a left paren. */
11782 /* This is dependent on the next operand specifier
11783 is a base register specification. */
11784 gas_assert (args[1] == 'b'
11785 || (mips_opts.micromips
11787 && (args[2] == 'l' || args[2] == 'n'
11788 || args[2] == 's' || args[2] == 'a')));
11789 if (*s == '\0' && args[1] == 'b')
11791 /* Fall through. */
11793 case ')': /* These must match exactly. */
11798 case '[': /* These must match exactly. */
11800 gas_assert (!mips_opts.micromips);
11805 case '+': /* Opcode extension character. */
11808 case '1': /* UDI immediates. */
11812 gas_assert (!mips_opts.micromips);
11814 const struct mips_immed *imm = mips_immed;
11816 while (imm->type && imm->type != *args)
11820 my_getExpression (&imm_expr, s);
11821 check_absolute_expr (ip, &imm_expr);
11822 if ((unsigned long) imm_expr.X_add_number & ~imm->mask)
11824 as_warn (_("Illegal %s number (%lu, 0x%lx)"),
11825 imm->desc ? imm->desc : ip->insn_mo->name,
11826 (unsigned long) imm_expr.X_add_number,
11827 (unsigned long) imm_expr.X_add_number);
11828 imm_expr.X_add_number &= imm->mask;
11830 ip->insn_opcode |= ((unsigned long) imm_expr.X_add_number
11832 imm_expr.X_op = O_absent;
11837 case 'J': /* 10-bit hypcall code. */
11838 gas_assert (!mips_opts.micromips);
11840 unsigned long mask = OP_MASK_CODE10;
11842 my_getExpression (&imm_expr, s);
11843 check_absolute_expr (ip, &imm_expr);
11844 if ((unsigned long) imm_expr.X_add_number > mask)
11845 as_warn (_("Code for %s not in range 0..%lu (%lu)"),
11847 mask, (unsigned long) imm_expr.X_add_number);
11848 INSERT_OPERAND (0, CODE10, *ip, imm_expr.X_add_number);
11849 imm_expr.X_op = O_absent;
11854 case 'A': /* ins/ext position, becomes LSB. */
11863 my_getExpression (&imm_expr, s);
11864 check_absolute_expr (ip, &imm_expr);
11865 if ((unsigned long) imm_expr.X_add_number < limlo
11866 || (unsigned long) imm_expr.X_add_number > limhi)
11868 as_bad (_("Improper position (%lu)"),
11869 (unsigned long) imm_expr.X_add_number);
11870 imm_expr.X_add_number = limlo;
11872 lastpos = imm_expr.X_add_number;
11873 INSERT_OPERAND (mips_opts.micromips,
11874 EXTLSB, *ip, imm_expr.X_add_number);
11875 imm_expr.X_op = O_absent;
11879 case 'B': /* ins size, becomes MSB. */
11888 my_getExpression (&imm_expr, s);
11889 check_absolute_expr (ip, &imm_expr);
11890 /* Check for negative input so that small negative numbers
11891 will not succeed incorrectly. The checks against
11892 (pos+size) transitively check "size" itself,
11893 assuming that "pos" is reasonable. */
11894 if ((long) imm_expr.X_add_number < 0
11895 || ((unsigned long) imm_expr.X_add_number
11897 || ((unsigned long) imm_expr.X_add_number
11898 + lastpos) > limhi)
11900 as_bad (_("Improper insert size (%lu, position %lu)"),
11901 (unsigned long) imm_expr.X_add_number,
11902 (unsigned long) lastpos);
11903 imm_expr.X_add_number = limlo - lastpos;
11905 INSERT_OPERAND (mips_opts.micromips, INSMSB, *ip,
11906 lastpos + imm_expr.X_add_number - 1);
11907 imm_expr.X_op = O_absent;
11911 case 'C': /* ext size, becomes MSBD. */
11927 my_getExpression (&imm_expr, s);
11928 check_absolute_expr (ip, &imm_expr);
11929 /* The checks against (pos+size) don't transitively check
11930 "size" itself, assuming that "pos" is reasonable.
11931 We also need to check the lower bound of "size". */
11932 if ((long) imm_expr.X_add_number < sizelo
11933 || ((unsigned long) imm_expr.X_add_number
11935 || ((unsigned long) imm_expr.X_add_number
11936 + lastpos) > limhi)
11938 as_bad (_("Improper extract size (%lu, position %lu)"),
11939 (unsigned long) imm_expr.X_add_number,
11940 (unsigned long) lastpos);
11941 imm_expr.X_add_number = limlo - lastpos;
11943 INSERT_OPERAND (mips_opts.micromips,
11944 EXTMSBD, *ip, imm_expr.X_add_number - 1);
11945 imm_expr.X_op = O_absent;
11950 /* +D is for disassembly only; never match. */
11954 /* "+I" is like "I", except that imm2_expr is used. */
11955 my_getExpression (&imm2_expr, s);
11956 if (imm2_expr.X_op != O_big
11957 && imm2_expr.X_op != O_constant)
11958 insn_error = _("absolute expression required");
11959 if (HAVE_32BIT_GPRS)
11960 normalize_constant_expr (&imm2_expr);
11964 case 'T': /* Coprocessor register. */
11965 gas_assert (!mips_opts.micromips);
11966 /* +T is for disassembly only; never match. */
11969 case 't': /* Coprocessor register number. */
11970 gas_assert (!mips_opts.micromips);
11971 if (s[0] == '$' && ISDIGIT (s[1]))
11981 while (ISDIGIT (*s));
11983 as_bad (_("Invalid register number (%d)"), regno);
11986 INSERT_OPERAND (0, RT, *ip, regno);
11991 as_bad (_("Invalid coprocessor 0 register number"));
11995 /* bbit[01] and bbit[01]32 bit index. Give error if index
11996 is not in the valid range. */
11997 gas_assert (!mips_opts.micromips);
11998 my_getExpression (&imm_expr, s);
11999 check_absolute_expr (ip, &imm_expr);
12000 if ((unsigned) imm_expr.X_add_number > 31)
12002 as_bad (_("Improper bit index (%lu)"),
12003 (unsigned long) imm_expr.X_add_number);
12004 imm_expr.X_add_number = 0;
12006 INSERT_OPERAND (0, BBITIND, *ip, imm_expr.X_add_number);
12007 imm_expr.X_op = O_absent;
12012 /* bbit[01] bit index when bbit is used but we generate
12013 bbit[01]32 because the index is over 32. Move to the
12014 next candidate if index is not in the valid range. */
12015 gas_assert (!mips_opts.micromips);
12016 my_getExpression (&imm_expr, s);
12017 check_absolute_expr (ip, &imm_expr);
12018 if ((unsigned) imm_expr.X_add_number < 32
12019 || (unsigned) imm_expr.X_add_number > 63)
12021 INSERT_OPERAND (0, BBITIND, *ip, imm_expr.X_add_number - 32);
12022 imm_expr.X_op = O_absent;
12027 /* cins, cins32, exts and exts32 position field. Give error
12028 if it's not in the valid range. */
12029 gas_assert (!mips_opts.micromips);
12030 my_getExpression (&imm_expr, s);
12031 check_absolute_expr (ip, &imm_expr);
12032 if ((unsigned) imm_expr.X_add_number > 31)
12034 as_bad (_("Improper position (%lu)"),
12035 (unsigned long) imm_expr.X_add_number);
12036 imm_expr.X_add_number = 0;
12038 /* Make the pos explicit to simplify +S. */
12039 lastpos = imm_expr.X_add_number + 32;
12040 INSERT_OPERAND (0, CINSPOS, *ip, imm_expr.X_add_number);
12041 imm_expr.X_op = O_absent;
12046 /* cins, cins32, exts and exts32 position field. Move to
12047 the next candidate if it's not in the valid range. */
12048 gas_assert (!mips_opts.micromips);
12049 my_getExpression (&imm_expr, s);
12050 check_absolute_expr (ip, &imm_expr);
12051 if ((unsigned) imm_expr.X_add_number < 32
12052 || (unsigned) imm_expr.X_add_number > 63)
12054 lastpos = imm_expr.X_add_number;
12055 INSERT_OPERAND (0, CINSPOS, *ip, imm_expr.X_add_number - 32);
12056 imm_expr.X_op = O_absent;
12061 /* cins and exts length-minus-one field. */
12062 gas_assert (!mips_opts.micromips);
12063 my_getExpression (&imm_expr, s);
12064 check_absolute_expr (ip, &imm_expr);
12065 if ((unsigned long) imm_expr.X_add_number > 31)
12067 as_bad (_("Improper size (%lu)"),
12068 (unsigned long) imm_expr.X_add_number);
12069 imm_expr.X_add_number = 0;
12071 INSERT_OPERAND (0, CINSLM1, *ip, imm_expr.X_add_number);
12072 imm_expr.X_op = O_absent;
12077 /* cins32/exts32 and cins/exts aliasing cint32/exts32
12078 length-minus-one field. */
12079 gas_assert (!mips_opts.micromips);
12080 my_getExpression (&imm_expr, s);
12081 check_absolute_expr (ip, &imm_expr);
12082 if ((long) imm_expr.X_add_number < 0
12083 || (unsigned long) imm_expr.X_add_number + lastpos > 63)
12085 as_bad (_("Improper size (%lu)"),
12086 (unsigned long) imm_expr.X_add_number);
12087 imm_expr.X_add_number = 0;
12089 INSERT_OPERAND (0, CINSLM1, *ip, imm_expr.X_add_number);
12090 imm_expr.X_op = O_absent;
12095 /* seqi/snei immediate field. */
12096 gas_assert (!mips_opts.micromips);
12097 my_getExpression (&imm_expr, s);
12098 check_absolute_expr (ip, &imm_expr);
12099 if ((long) imm_expr.X_add_number < -512
12100 || (long) imm_expr.X_add_number >= 512)
12102 as_bad (_("Improper immediate (%ld)"),
12103 (long) imm_expr.X_add_number);
12104 imm_expr.X_add_number = 0;
12106 INSERT_OPERAND (0, SEQI, *ip, imm_expr.X_add_number);
12107 imm_expr.X_op = O_absent;
12111 case 'a': /* 8-bit signed offset in bit 6 */
12112 gas_assert (!mips_opts.micromips);
12113 my_getExpression (&imm_expr, s);
12114 check_absolute_expr (ip, &imm_expr);
12115 min_range = -((OP_MASK_OFFSET_A + 1) >> 1);
12116 max_range = ((OP_MASK_OFFSET_A + 1) >> 1) - 1;
12117 if (imm_expr.X_add_number < min_range
12118 || imm_expr.X_add_number > max_range)
12120 as_bad (_("Offset not in range %ld..%ld (%ld)"),
12121 (long) min_range, (long) max_range,
12122 (long) imm_expr.X_add_number);
12124 INSERT_OPERAND (0, OFFSET_A, *ip, imm_expr.X_add_number);
12125 imm_expr.X_op = O_absent;
12129 case 'b': /* 8-bit signed offset in bit 3 */
12130 gas_assert (!mips_opts.micromips);
12131 my_getExpression (&imm_expr, s);
12132 check_absolute_expr (ip, &imm_expr);
12133 min_range = -((OP_MASK_OFFSET_B + 1) >> 1);
12134 max_range = ((OP_MASK_OFFSET_B + 1) >> 1) - 1;
12135 if (imm_expr.X_add_number < min_range
12136 || imm_expr.X_add_number > max_range)
12138 as_bad (_("Offset not in range %ld..%ld (%ld)"),
12139 (long) min_range, (long) max_range,
12140 (long) imm_expr.X_add_number);
12142 INSERT_OPERAND (0, OFFSET_B, *ip, imm_expr.X_add_number);
12143 imm_expr.X_op = O_absent;
12147 case 'c': /* 9-bit signed offset in bit 6 */
12148 gas_assert (!mips_opts.micromips);
12149 my_getExpression (&imm_expr, s);
12150 check_absolute_expr (ip, &imm_expr);
12151 min_range = -((OP_MASK_OFFSET_C + 1) >> 1);
12152 max_range = ((OP_MASK_OFFSET_C + 1) >> 1) - 1;
12153 /* We check the offset range before adjusted. */
12156 if (imm_expr.X_add_number < min_range
12157 || imm_expr.X_add_number > max_range)
12159 as_bad (_("Offset not in range %ld..%ld (%ld)"),
12160 (long) min_range, (long) max_range,
12161 (long) imm_expr.X_add_number);
12163 if (imm_expr.X_add_number & 0xf)
12165 as_bad (_("Offset not 16 bytes alignment (%ld)"),
12166 (long) imm_expr.X_add_number);
12168 /* Right shift 4 bits to adjust the offset operand. */
12169 INSERT_OPERAND (0, OFFSET_C, *ip,
12170 imm_expr.X_add_number >> 4);
12171 imm_expr.X_op = O_absent;
12176 gas_assert (!mips_opts.micromips);
12177 if (!reg_lookup (&s, RTYPE_NUM | RTYPE_GP, ®no))
12179 if (regno == AT && mips_opts.at)
12181 if (mips_opts.at == ATREG)
12182 as_warn (_("used $at without \".set noat\""));
12184 as_warn (_("used $%u with \".set at=$%u\""),
12185 regno, mips_opts.at);
12187 INSERT_OPERAND (0, RZ, *ip, regno);
12191 gas_assert (!mips_opts.micromips);
12192 if (!reg_lookup (&s, RTYPE_FPU, ®no))
12194 INSERT_OPERAND (0, FZ, *ip, regno);
12201 /* Check whether there is only a single bracketed expression
12202 left. If so, it must be the base register and the
12203 constant must be zero. */
12204 if (*s == '(' && strchr (s + 1, '(') == 0)
12207 /* If this value won't fit into the offset, then go find
12208 a macro that will generate a 16- or 32-bit offset code
12210 i = my_getSmallExpression (&imm_expr, imm_reloc, s);
12211 if ((i == 0 && (imm_expr.X_op != O_constant
12212 || imm_expr.X_add_number >= 1 << shift
12213 || imm_expr.X_add_number < -1 << shift))
12216 imm_expr.X_op = O_absent;
12219 INSERT_OPERAND (mips_opts.micromips, EVAOFFSET, *ip,
12220 imm_expr.X_add_number);
12221 imm_expr.X_op = O_absent;
12227 as_bad (_("Internal error: bad %s opcode "
12228 "(unknown extension operand type `+%c'): %s %s"),
12229 mips_opts.micromips ? "microMIPS" : "MIPS",
12230 *args, insn->name, insn->args);
12231 /* Further processing is fruitless. */
12236 case '.': /* 10-bit offset. */
12237 gas_assert (mips_opts.micromips);
12238 case '~': /* 12-bit offset. */
12240 int shift = *args == '.' ? 9 : 11;
12243 /* Check whether there is only a single bracketed expression
12244 left. If so, it must be the base register and the
12245 constant must be zero. */
12246 if (*s == '(' && strchr (s + 1, '(') == 0)
12249 /* If this value won't fit into the offset, then go find
12250 a macro that will generate a 16- or 32-bit offset code
12252 i = my_getSmallExpression (&imm_expr, imm_reloc, s);
12253 if ((i == 0 && (imm_expr.X_op != O_constant
12254 || imm_expr.X_add_number >= 1 << shift
12255 || imm_expr.X_add_number < -1 << shift))
12258 imm_expr.X_op = O_absent;
12262 INSERT_OPERAND (1, OFFSET10, *ip, imm_expr.X_add_number);
12264 INSERT_OPERAND (mips_opts.micromips,
12265 OFFSET12, *ip, imm_expr.X_add_number);
12266 imm_expr.X_op = O_absent;
12271 case '<': /* must be at least one digit */
12273 * According to the manual, if the shift amount is greater
12274 * than 31 or less than 0, then the shift amount should be
12275 * mod 32. In reality the mips assembler issues an error.
12276 * We issue a warning and mask out all but the low 5 bits.
12278 my_getExpression (&imm_expr, s);
12279 check_absolute_expr (ip, &imm_expr);
12280 if ((unsigned long) imm_expr.X_add_number > 31)
12281 as_warn (_("Improper shift amount (%lu)"),
12282 (unsigned long) imm_expr.X_add_number);
12283 INSERT_OPERAND (mips_opts.micromips,
12284 SHAMT, *ip, imm_expr.X_add_number);
12285 imm_expr.X_op = O_absent;
12289 case '>': /* shift amount minus 32 */
12290 my_getExpression (&imm_expr, s);
12291 check_absolute_expr (ip, &imm_expr);
12292 if ((unsigned long) imm_expr.X_add_number < 32
12293 || (unsigned long) imm_expr.X_add_number > 63)
12295 INSERT_OPERAND (mips_opts.micromips,
12296 SHAMT, *ip, imm_expr.X_add_number - 32);
12297 imm_expr.X_op = O_absent;
12301 case 'k': /* CACHE code. */
12302 case 'h': /* PREFX code. */
12303 case '1': /* SYNC type. */
12304 my_getExpression (&imm_expr, s);
12305 check_absolute_expr (ip, &imm_expr);
12306 if ((unsigned long) imm_expr.X_add_number > 31)
12307 as_warn (_("Invalid value for `%s' (%lu)"),
12309 (unsigned long) imm_expr.X_add_number);
12313 if (mips_fix_cn63xxp1
12314 && !mips_opts.micromips
12315 && strcmp ("pref", insn->name) == 0)
12316 switch (imm_expr.X_add_number)
12325 case 31: /* These are ok. */
12328 default: /* The rest must be changed to 28. */
12329 imm_expr.X_add_number = 28;
12332 INSERT_OPERAND (mips_opts.micromips,
12333 CACHE, *ip, imm_expr.X_add_number);
12336 INSERT_OPERAND (mips_opts.micromips,
12337 PREFX, *ip, imm_expr.X_add_number);
12340 INSERT_OPERAND (mips_opts.micromips,
12341 STYPE, *ip, imm_expr.X_add_number);
12344 imm_expr.X_op = O_absent;
12348 case 'c': /* BREAK code. */
12350 unsigned long mask = (mips_opts.micromips
12351 ? MICROMIPSOP_MASK_CODE
12354 my_getExpression (&imm_expr, s);
12355 check_absolute_expr (ip, &imm_expr);
12356 if ((unsigned long) imm_expr.X_add_number > mask)
12357 as_warn (_("Code for %s not in range 0..%lu (%lu)"),
12359 mask, (unsigned long) imm_expr.X_add_number);
12360 INSERT_OPERAND (mips_opts.micromips,
12361 CODE, *ip, imm_expr.X_add_number);
12362 imm_expr.X_op = O_absent;
12367 case 'q': /* Lower BREAK code. */
12369 unsigned long mask = (mips_opts.micromips
12370 ? MICROMIPSOP_MASK_CODE2
12373 my_getExpression (&imm_expr, s);
12374 check_absolute_expr (ip, &imm_expr);
12375 if ((unsigned long) imm_expr.X_add_number > mask)
12376 as_warn (_("Lower code for %s not in range 0..%lu (%lu)"),
12378 mask, (unsigned long) imm_expr.X_add_number);
12379 INSERT_OPERAND (mips_opts.micromips,
12380 CODE2, *ip, imm_expr.X_add_number);
12381 imm_expr.X_op = O_absent;
12386 case 'B': /* 20- or 10-bit syscall/break/wait code. */
12388 unsigned long mask = (mips_opts.micromips
12389 ? MICROMIPSOP_MASK_CODE10
12392 my_getExpression (&imm_expr, s);
12393 check_absolute_expr (ip, &imm_expr);
12394 if ((unsigned long) imm_expr.X_add_number > mask)
12395 as_warn (_("Code for %s not in range 0..%lu (%lu)"),
12397 mask, (unsigned long) imm_expr.X_add_number);
12398 if (mips_opts.micromips)
12399 INSERT_OPERAND (1, CODE10, *ip, imm_expr.X_add_number);
12401 INSERT_OPERAND (0, CODE20, *ip, imm_expr.X_add_number);
12402 imm_expr.X_op = O_absent;
12407 case 'C': /* 25- or 23-bit coprocessor code. */
12409 unsigned long mask = (mips_opts.micromips
12410 ? MICROMIPSOP_MASK_COPZ
12413 my_getExpression (&imm_expr, s);
12414 check_absolute_expr (ip, &imm_expr);
12415 if ((unsigned long) imm_expr.X_add_number > mask)
12416 as_warn (_("Coproccesor code > %u bits (%lu)"),
12417 mips_opts.micromips ? 23U : 25U,
12418 (unsigned long) imm_expr.X_add_number);
12419 INSERT_OPERAND (mips_opts.micromips,
12420 COPZ, *ip, imm_expr.X_add_number);
12421 imm_expr.X_op = O_absent;
12426 case 'J': /* 19-bit WAIT code. */
12427 gas_assert (!mips_opts.micromips);
12428 my_getExpression (&imm_expr, s);
12429 check_absolute_expr (ip, &imm_expr);
12430 if ((unsigned long) imm_expr.X_add_number > OP_MASK_CODE19)
12432 as_warn (_("Illegal 19-bit code (%lu)"),
12433 (unsigned long) imm_expr.X_add_number);
12434 imm_expr.X_add_number &= OP_MASK_CODE19;
12436 INSERT_OPERAND (0, CODE19, *ip, imm_expr.X_add_number);
12437 imm_expr.X_op = O_absent;
12441 case 'P': /* Performance register. */
12442 gas_assert (!mips_opts.micromips);
12443 my_getExpression (&imm_expr, s);
12444 check_absolute_expr (ip, &imm_expr);
12445 if (imm_expr.X_add_number != 0 && imm_expr.X_add_number != 1)
12446 as_warn (_("Invalid performance register (%lu)"),
12447 (unsigned long) imm_expr.X_add_number);
12448 if (imm_expr.X_add_number != 0 && mips_opts.arch == CPU_R5900
12449 && (!strcmp(insn->name,"mfps") || !strcmp(insn->name,"mtps")))
12450 as_warn (_("Invalid performance register (%lu)"),
12451 (unsigned long) imm_expr.X_add_number);
12452 INSERT_OPERAND (0, PERFREG, *ip, imm_expr.X_add_number);
12453 imm_expr.X_op = O_absent;
12457 case 'G': /* Coprocessor destination register. */
12459 unsigned long opcode = ip->insn_opcode;
12460 unsigned long mask;
12461 unsigned int types;
12464 if (mips_opts.micromips)
12466 mask = ~((MICROMIPSOP_MASK_RT << MICROMIPSOP_SH_RT)
12467 | (MICROMIPSOP_MASK_RS << MICROMIPSOP_SH_RS)
12468 | (MICROMIPSOP_MASK_SEL << MICROMIPSOP_SH_SEL));
12472 case 0x000000fc: /* mfc0 */
12473 case 0x000002fc: /* mtc0 */
12474 case 0x580000fc: /* dmfc0 */
12475 case 0x580002fc: /* dmtc0 */
12485 opcode = (opcode >> OP_SH_OP) & OP_MASK_OP;
12486 cop0 = opcode == OP_OP_COP0;
12488 types = RTYPE_NUM | (cop0 ? RTYPE_CP0 : RTYPE_GP);
12489 ok = reg_lookup (&s, types, ®no);
12490 if (mips_opts.micromips)
12491 INSERT_OPERAND (1, RS, *ip, regno);
12493 INSERT_OPERAND (0, RD, *ip, regno);
12502 case 'y': /* ALNV.PS source register. */
12503 gas_assert (mips_opts.micromips);
12505 case 'x': /* Ignore register name. */
12506 case 'U': /* Destination register (CLO/CLZ). */
12507 case 'g': /* Coprocessor destination register. */
12508 gas_assert (!mips_opts.micromips);
12509 case 'b': /* Base register. */
12510 case 'd': /* Destination register. */
12511 case 's': /* Source register. */
12512 case 't': /* Target register. */
12513 case 'r': /* Both target and source. */
12514 case 'v': /* Both dest and source. */
12515 case 'w': /* Both dest and target. */
12516 case 'E': /* Coprocessor target register. */
12517 case 'K': /* RDHWR destination register. */
12518 case 'z': /* Must be zero register. */
12521 if (*args == 'E' || *args == 'K')
12522 ok = reg_lookup (&s, RTYPE_NUM, ®no);
12525 ok = reg_lookup (&s, RTYPE_NUM | RTYPE_GP, ®no);
12526 if (regno == AT && mips_opts.at)
12528 if (mips_opts.at == ATREG)
12529 as_warn (_("Used $at without \".set noat\""));
12531 as_warn (_("Used $%u with \".set at=$%u\""),
12532 regno, mips_opts.at);
12542 if (c == 'r' || c == 'v' || c == 'w')
12549 /* 'z' only matches $0. */
12550 if (c == 'z' && regno != 0)
12553 if (c == 's' && !strncmp (ip->insn_mo->name, "jalr", 4))
12555 if (regno == lastregno)
12558 = _("Source and destination must be different");
12561 if (regno == 31 && lastregno == 0xffffffff)
12564 = _("A destination register must be supplied");
12568 /* Now that we have assembled one operand, we use the args
12569 string to figure out where it goes in the instruction. */
12576 INSERT_OPERAND (mips_opts.micromips, RS, *ip, regno);
12580 if (mips_opts.micromips)
12581 INSERT_OPERAND (1, RS, *ip, regno);
12583 INSERT_OPERAND (0, RD, *ip, regno);
12588 INSERT_OPERAND (mips_opts.micromips, RD, *ip, regno);
12592 gas_assert (!mips_opts.micromips);
12593 INSERT_OPERAND (0, RD, *ip, regno);
12594 INSERT_OPERAND (0, RT, *ip, regno);
12600 INSERT_OPERAND (mips_opts.micromips, RT, *ip, regno);
12604 gas_assert (mips_opts.micromips);
12605 INSERT_OPERAND (1, RS3, *ip, regno);
12609 /* This case exists because on the r3000 trunc
12610 expands into a macro which requires a gp
12611 register. On the r6000 or r4000 it is
12612 assembled into a single instruction which
12613 ignores the register. Thus the insn version
12614 is MIPS_ISA2 and uses 'x', and the macro
12615 version is MIPS_ISA1 and uses 't'. */
12619 /* This case is for the div instruction, which
12620 acts differently if the destination argument
12621 is $0. This only matches $0, and is checked
12622 outside the switch. */
12632 INSERT_OPERAND (mips_opts.micromips, RS, *ip, lastregno);
12636 INSERT_OPERAND (mips_opts.micromips, RT, *ip, lastregno);
12641 case 'O': /* MDMX alignment immediate constant. */
12642 gas_assert (!mips_opts.micromips);
12643 my_getExpression (&imm_expr, s);
12644 check_absolute_expr (ip, &imm_expr);
12645 if ((unsigned long) imm_expr.X_add_number > OP_MASK_ALN)
12646 as_warn (_("Improper align amount (%ld), using low bits"),
12647 (long) imm_expr.X_add_number);
12648 INSERT_OPERAND (0, ALN, *ip, imm_expr.X_add_number);
12649 imm_expr.X_op = O_absent;
12653 case 'Q': /* MDMX vector, element sel, or const. */
12656 /* MDMX Immediate. */
12657 gas_assert (!mips_opts.micromips);
12658 my_getExpression (&imm_expr, s);
12659 check_absolute_expr (ip, &imm_expr);
12660 if ((unsigned long) imm_expr.X_add_number > OP_MASK_FT)
12661 as_warn (_("Invalid MDMX Immediate (%ld)"),
12662 (long) imm_expr.X_add_number);
12663 INSERT_OPERAND (0, FT, *ip, imm_expr.X_add_number);
12664 if (ip->insn_opcode & (OP_MASK_VSEL << OP_SH_VSEL))
12665 ip->insn_opcode |= MDMX_FMTSEL_IMM_QH << OP_SH_VSEL;
12667 ip->insn_opcode |= MDMX_FMTSEL_IMM_OB << OP_SH_VSEL;
12668 imm_expr.X_op = O_absent;
12672 /* Not MDMX Immediate. Fall through. */
12673 case 'X': /* MDMX destination register. */
12674 case 'Y': /* MDMX source register. */
12675 case 'Z': /* MDMX target register. */
12678 gas_assert (!mips_opts.micromips);
12679 case 'D': /* Floating point destination register. */
12680 case 'S': /* Floating point source register. */
12681 case 'T': /* Floating point target register. */
12682 case 'R': /* Floating point source register. */
12686 || ((mips_opts.ase & ASE_MDMX)
12687 && (ip->insn_mo->pinfo & FP_D)
12688 && (ip->insn_mo->pinfo & (INSN_COPROC_MOVE_DELAY
12689 | INSN_COPROC_MEMORY_DELAY
12690 | INSN_LOAD_COPROC_DELAY
12691 | INSN_LOAD_MEMORY_DELAY
12692 | INSN_STORE_MEMORY))))
12693 rtype |= RTYPE_VEC;
12695 if (reg_lookup (&s, rtype, ®no))
12697 if ((regno & 1) != 0
12699 && !mips_oddfpreg_ok (ip->insn_mo, argnum))
12700 as_warn (_("Float register should be even, was %d"),
12708 if (c == 'V' || c == 'W')
12719 INSERT_OPERAND (mips_opts.micromips, FD, *ip, regno);
12725 INSERT_OPERAND (mips_opts.micromips, FS, *ip, regno);
12729 /* This is like 'Z', but also needs to fix the MDMX
12730 vector/scalar select bits. Note that the
12731 scalar immediate case is handled above. */
12734 int is_qh = (ip->insn_opcode & (1 << OP_SH_VSEL));
12735 int max_el = (is_qh ? 3 : 7);
12737 my_getExpression(&imm_expr, s);
12738 check_absolute_expr (ip, &imm_expr);
12740 if (imm_expr.X_add_number > max_el)
12741 as_bad (_("Bad element selector %ld"),
12742 (long) imm_expr.X_add_number);
12743 imm_expr.X_add_number &= max_el;
12744 ip->insn_opcode |= (imm_expr.X_add_number
12747 imm_expr.X_op = O_absent;
12749 as_warn (_("Expecting ']' found '%s'"), s);
12755 if (ip->insn_opcode & (OP_MASK_VSEL << OP_SH_VSEL))
12756 ip->insn_opcode |= (MDMX_FMTSEL_VEC_QH
12759 ip->insn_opcode |= (MDMX_FMTSEL_VEC_OB <<
12762 /* Fall through. */
12766 INSERT_OPERAND (mips_opts.micromips, FT, *ip, regno);
12770 INSERT_OPERAND (mips_opts.micromips, FR, *ip, regno);
12780 INSERT_OPERAND (mips_opts.micromips, FS, *ip, lastregno);
12784 INSERT_OPERAND (mips_opts.micromips, FT, *ip, lastregno);
12790 my_getExpression (&imm_expr, s);
12791 if (imm_expr.X_op != O_big
12792 && imm_expr.X_op != O_constant)
12793 insn_error = _("absolute expression required");
12794 if (HAVE_32BIT_GPRS)
12795 normalize_constant_expr (&imm_expr);
12800 my_getExpression (&offset_expr, s);
12801 normalize_address_expr (&offset_expr);
12802 *imm_reloc = BFD_RELOC_32;
12815 unsigned char temp[8];
12817 unsigned int length;
12822 /* These only appear as the last operand in an
12823 instruction, and every instruction that accepts
12824 them in any variant accepts them in all variants.
12825 This means we don't have to worry about backing out
12826 any changes if the instruction does not match.
12828 The difference between them is the size of the
12829 floating point constant and where it goes. For 'F'
12830 and 'L' the constant is 64 bits; for 'f' and 'l' it
12831 is 32 bits. Where the constant is placed is based
12832 on how the MIPS assembler does things:
12835 f -- immediate value
12838 The .lit4 and .lit8 sections are only used if
12839 permitted by the -G argument.
12841 The code below needs to know whether the target register
12842 is 32 or 64 bits wide. It relies on the fact 'f' and
12843 'F' are used with GPR-based instructions and 'l' and
12844 'L' are used with FPR-based instructions. */
12846 f64 = *args == 'F' || *args == 'L';
12847 using_gprs = *args == 'F' || *args == 'f';
12849 save_in = input_line_pointer;
12850 input_line_pointer = s;
12851 err = md_atof (f64 ? 'd' : 'f', (char *) temp, &len);
12853 s = input_line_pointer;
12854 input_line_pointer = save_in;
12855 if (err != NULL && *err != '\0')
12857 as_bad (_("Bad floating point constant: %s"), err);
12858 memset (temp, '\0', sizeof temp);
12859 length = f64 ? 8 : 4;
12862 gas_assert (length == (unsigned) (f64 ? 8 : 4));
12866 && (g_switch_value < 4
12867 || (temp[0] == 0 && temp[1] == 0)
12868 || (temp[2] == 0 && temp[3] == 0))))
12870 imm_expr.X_op = O_constant;
12871 if (!target_big_endian)
12872 imm_expr.X_add_number = bfd_getl32 (temp);
12874 imm_expr.X_add_number = bfd_getb32 (temp);
12876 else if (length > 4
12877 && !mips_disable_float_construction
12878 /* Constants can only be constructed in GPRs and
12879 copied to FPRs if the GPRs are at least as wide
12880 as the FPRs. Force the constant into memory if
12881 we are using 64-bit FPRs but the GPRs are only
12884 || !(HAVE_64BIT_FPRS && HAVE_32BIT_GPRS))
12885 && ((temp[0] == 0 && temp[1] == 0)
12886 || (temp[2] == 0 && temp[3] == 0))
12887 && ((temp[4] == 0 && temp[5] == 0)
12888 || (temp[6] == 0 && temp[7] == 0)))
12890 /* The value is simple enough to load with a couple of
12891 instructions. If using 32-bit registers, set
12892 imm_expr to the high order 32 bits and offset_expr to
12893 the low order 32 bits. Otherwise, set imm_expr to
12894 the entire 64 bit constant. */
12895 if (using_gprs ? HAVE_32BIT_GPRS : HAVE_32BIT_FPRS)
12897 imm_expr.X_op = O_constant;
12898 offset_expr.X_op = O_constant;
12899 if (!target_big_endian)
12901 imm_expr.X_add_number = bfd_getl32 (temp + 4);
12902 offset_expr.X_add_number = bfd_getl32 (temp);
12906 imm_expr.X_add_number = bfd_getb32 (temp);
12907 offset_expr.X_add_number = bfd_getb32 (temp + 4);
12909 if (offset_expr.X_add_number == 0)
12910 offset_expr.X_op = O_absent;
12912 else if (sizeof (imm_expr.X_add_number) > 4)
12914 imm_expr.X_op = O_constant;
12915 if (!target_big_endian)
12916 imm_expr.X_add_number = bfd_getl64 (temp);
12918 imm_expr.X_add_number = bfd_getb64 (temp);
12922 imm_expr.X_op = O_big;
12923 imm_expr.X_add_number = 4;
12924 if (!target_big_endian)
12926 generic_bignum[0] = bfd_getl16 (temp);
12927 generic_bignum[1] = bfd_getl16 (temp + 2);
12928 generic_bignum[2] = bfd_getl16 (temp + 4);
12929 generic_bignum[3] = bfd_getl16 (temp + 6);
12933 generic_bignum[0] = bfd_getb16 (temp + 6);
12934 generic_bignum[1] = bfd_getb16 (temp + 4);
12935 generic_bignum[2] = bfd_getb16 (temp + 2);
12936 generic_bignum[3] = bfd_getb16 (temp);
12942 const char *newname;
12945 /* Switch to the right section. */
12947 subseg = now_subseg;
12950 default: /* unused default case avoids warnings. */
12952 newname = RDATA_SECTION_NAME;
12953 if (g_switch_value >= 8)
12957 newname = RDATA_SECTION_NAME;
12960 gas_assert (g_switch_value >= 4);
12964 new_seg = subseg_new (newname, (subsegT) 0);
12966 bfd_set_section_flags (stdoutput, new_seg,
12971 frag_align (*args == 'l' ? 2 : 3, 0, 0);
12972 if (IS_ELF && strncmp (TARGET_OS, "elf", 3) != 0)
12973 record_alignment (new_seg, 4);
12975 record_alignment (new_seg, *args == 'l' ? 2 : 3);
12976 if (seg == now_seg)
12977 as_bad (_("Can't use floating point insn in this section"));
12979 /* Set the argument to the current address in the
12981 offset_expr.X_op = O_symbol;
12982 offset_expr.X_add_symbol = symbol_temp_new_now ();
12983 offset_expr.X_add_number = 0;
12985 /* Put the floating point number into the section. */
12986 p = frag_more ((int) length);
12987 memcpy (p, temp, length);
12989 /* Switch back to the original section. */
12990 subseg_set (seg, subseg);
12995 case 'i': /* 16-bit unsigned immediate. */
12996 case 'j': /* 16-bit signed immediate. */
12997 *imm_reloc = BFD_RELOC_LO16;
12998 if (my_getSmallExpression (&imm_expr, imm_reloc, s) == 0)
13001 offsetT minval, maxval;
13003 more = (insn + 1 < past
13004 && strcmp (insn->name, insn[1].name) == 0);
13006 /* If the expression was written as an unsigned number,
13007 only treat it as signed if there are no more
13011 && sizeof (imm_expr.X_add_number) <= 4
13012 && imm_expr.X_op == O_constant
13013 && imm_expr.X_add_number < 0
13014 && imm_expr.X_unsigned
13015 && HAVE_64BIT_GPRS)
13018 /* For compatibility with older assemblers, we accept
13019 0x8000-0xffff as signed 16-bit numbers when only
13020 signed numbers are allowed. */
13022 minval = 0, maxval = 0xffff;
13024 minval = -0x8000, maxval = 0x7fff;
13026 minval = -0x8000, maxval = 0xffff;
13028 if (imm_expr.X_op != O_constant
13029 || imm_expr.X_add_number < minval
13030 || imm_expr.X_add_number > maxval)
13034 if (imm_expr.X_op == O_constant
13035 || imm_expr.X_op == O_big)
13036 as_bad (_("Expression out of range"));
13042 case 'o': /* 16-bit offset. */
13043 offset_reloc[0] = BFD_RELOC_LO16;
13044 offset_reloc[1] = BFD_RELOC_UNUSED;
13045 offset_reloc[2] = BFD_RELOC_UNUSED;
13047 /* Check whether there is only a single bracketed expression
13048 left. If so, it must be the base register and the
13049 constant must be zero. */
13050 if (*s == '(' && strchr (s + 1, '(') == 0)
13052 offset_expr.X_op = O_constant;
13053 offset_expr.X_add_number = 0;
13057 /* If this value won't fit into a 16 bit offset, then go
13058 find a macro that will generate the 32 bit offset
13060 if (my_getSmallExpression (&offset_expr, offset_reloc, s) == 0
13061 && (offset_expr.X_op != O_constant
13062 || offset_expr.X_add_number >= 0x8000
13063 || offset_expr.X_add_number < -0x8000))
13069 case 'p': /* PC-relative offset. */
13070 *offset_reloc = BFD_RELOC_16_PCREL_S2;
13071 my_getExpression (&offset_expr, s);
13075 case 'u': /* Upper 16 bits. */
13076 *imm_reloc = BFD_RELOC_LO16;
13077 if (my_getSmallExpression (&imm_expr, imm_reloc, s) == 0
13078 && imm_expr.X_op == O_constant
13079 && (imm_expr.X_add_number < 0
13080 || imm_expr.X_add_number >= 0x10000))
13081 as_bad (_("lui expression (%lu) not in range 0..65535"),
13082 (unsigned long) imm_expr.X_add_number);
13086 case 'a': /* 26-bit address. */
13087 *offset_reloc = BFD_RELOC_MIPS_JMP;
13088 my_getExpression (&offset_expr, s);
13092 case 'N': /* 3-bit branch condition code. */
13093 case 'M': /* 3-bit compare condition code. */
13095 if (ip->insn_mo->pinfo & (FP_D | FP_S))
13096 rtype |= RTYPE_FCC;
13097 if (!reg_lookup (&s, rtype, ®no))
13099 if ((strcmp (str + strlen (str) - 3, ".ps") == 0
13100 || strcmp (str + strlen (str) - 5, "any2f") == 0
13101 || strcmp (str + strlen (str) - 5, "any2t") == 0)
13102 && (regno & 1) != 0)
13103 as_warn (_("Condition code register should be even for %s, "
13106 if ((strcmp (str + strlen (str) - 5, "any4f") == 0
13107 || strcmp (str + strlen (str) - 5, "any4t") == 0)
13108 && (regno & 3) != 0)
13109 as_warn (_("Condition code register should be 0 or 4 for %s, "
13113 INSERT_OPERAND (mips_opts.micromips, BCC, *ip, regno);
13115 INSERT_OPERAND (mips_opts.micromips, CCC, *ip, regno);
13119 if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X'))
13130 while (ISDIGIT (*s));
13133 c = 8; /* Invalid sel value. */
13136 as_bad (_("Invalid coprocessor sub-selection value (0-7)"));
13137 INSERT_OPERAND (mips_opts.micromips, SEL, *ip, c);
13141 gas_assert (!mips_opts.micromips);
13142 /* Must be at least one digit. */
13143 my_getExpression (&imm_expr, s);
13144 check_absolute_expr (ip, &imm_expr);
13146 if ((unsigned long) imm_expr.X_add_number
13147 > (unsigned long) OP_MASK_VECBYTE)
13149 as_bad (_("bad byte vector index (%ld)"),
13150 (long) imm_expr.X_add_number);
13151 imm_expr.X_add_number = 0;
13154 INSERT_OPERAND (0, VECBYTE, *ip, imm_expr.X_add_number);
13155 imm_expr.X_op = O_absent;
13160 gas_assert (!mips_opts.micromips);
13161 my_getExpression (&imm_expr, s);
13162 check_absolute_expr (ip, &imm_expr);
13164 if ((unsigned long) imm_expr.X_add_number
13165 > (unsigned long) OP_MASK_VECALIGN)
13167 as_bad (_("bad byte vector index (%ld)"),
13168 (long) imm_expr.X_add_number);
13169 imm_expr.X_add_number = 0;
13172 INSERT_OPERAND (0, VECALIGN, *ip, imm_expr.X_add_number);
13173 imm_expr.X_op = O_absent;
13177 case 'm': /* Opcode extension character. */
13178 gas_assert (mips_opts.micromips);
13183 if (strncmp (s, "$pc", 3) == 0)
13211 ok = reg_lookup (&s, RTYPE_NUM | RTYPE_GP, ®no);
13212 if (regno == AT && mips_opts.at)
13214 if (mips_opts.at == ATREG)
13215 as_warn (_("Used $at without \".set noat\""));
13217 as_warn (_("Used $%u with \".set at=$%u\""),
13218 regno, mips_opts.at);
13224 gas_assert (args[1] == ',');
13230 gas_assert (args[1] == ',');
13232 continue; /* Nothing to do. */
13238 if (c == 'j' && !strncmp (ip->insn_mo->name, "jalr", 4))
13240 if (regno == lastregno)
13243 = _("Source and destination must be different");
13246 if (regno == 31 && lastregno == 0xffffffff)
13249 = _("A destination register must be supplied");
13260 gas_assert (args[1] == ',');
13267 gas_assert (args[1] == ',');
13270 continue; /* Nothing to do. */
13274 /* Make sure regno is the same as lastregno. */
13275 if (c == 't' && regno != lastregno)
13278 /* Make sure regno is the same as destregno. */
13279 if (c == 'x' && regno != destregno)
13282 /* We need to save regno, before regno maps to the
13283 microMIPS register encoding. */
13293 regno = ILLEGAL_REG;
13297 regno = mips32_to_micromips_reg_b_map[regno];
13301 regno = mips32_to_micromips_reg_c_map[regno];
13305 regno = mips32_to_micromips_reg_d_map[regno];
13309 regno = mips32_to_micromips_reg_e_map[regno];
13313 regno = mips32_to_micromips_reg_f_map[regno];
13317 regno = mips32_to_micromips_reg_g_map[regno];
13321 regno = mips32_to_micromips_reg_h_map[regno];
13325 switch (EXTRACT_OPERAND (1, MI, *ip))
13330 else if (regno == 22)
13332 else if (regno == 5)
13334 else if (regno == 6)
13336 else if (regno == 7)
13339 regno = ILLEGAL_REG;
13345 else if (regno == 7)
13348 regno = ILLEGAL_REG;
13355 regno = ILLEGAL_REG;
13359 regno = ILLEGAL_REG;
13365 regno = mips32_to_micromips_reg_l_map[regno];
13369 regno = mips32_to_micromips_reg_m_map[regno];
13373 regno = mips32_to_micromips_reg_n_map[regno];
13377 regno = mips32_to_micromips_reg_q_map[regno];
13382 regno = ILLEGAL_REG;
13387 regno = ILLEGAL_REG;
13392 regno = ILLEGAL_REG;
13395 case 'j': /* Do nothing. */
13405 if (regno == ILLEGAL_REG)
13411 INSERT_OPERAND (1, MB, *ip, regno);
13415 INSERT_OPERAND (1, MC, *ip, regno);
13419 INSERT_OPERAND (1, MD, *ip, regno);
13423 INSERT_OPERAND (1, ME, *ip, regno);
13427 INSERT_OPERAND (1, MF, *ip, regno);
13431 INSERT_OPERAND (1, MG, *ip, regno);
13435 INSERT_OPERAND (1, MH, *ip, regno);
13439 INSERT_OPERAND (1, MI, *ip, regno);
13443 INSERT_OPERAND (1, MJ, *ip, regno);
13447 INSERT_OPERAND (1, ML, *ip, regno);
13451 INSERT_OPERAND (1, MM, *ip, regno);
13455 INSERT_OPERAND (1, MN, *ip, regno);
13459 INSERT_OPERAND (1, MP, *ip, regno);
13463 INSERT_OPERAND (1, MQ, *ip, regno);
13466 case 'a': /* Do nothing. */
13467 case 's': /* Do nothing. */
13468 case 't': /* Do nothing. */
13469 case 'x': /* Do nothing. */
13470 case 'y': /* Do nothing. */
13471 case 'z': /* Do nothing. */
13481 bfd_reloc_code_real_type r[3];
13485 /* Check whether there is only a single bracketed
13486 expression left. If so, it must be the base register
13487 and the constant must be zero. */
13488 if (*s == '(' && strchr (s + 1, '(') == 0)
13490 INSERT_OPERAND (1, IMMA, *ip, 0);
13494 if (my_getSmallExpression (&ep, r, s) > 0
13495 || !expr_const_in_range (&ep, -64, 64, 2))
13498 imm = ep.X_add_number >> 2;
13499 INSERT_OPERAND (1, IMMA, *ip, imm);
13506 bfd_reloc_code_real_type r[3];
13510 if (my_getSmallExpression (&ep, r, s) > 0
13511 || ep.X_op != O_constant)
13514 for (imm = 0; imm < 8; imm++)
13515 if (micromips_imm_b_map[imm] == ep.X_add_number)
13520 INSERT_OPERAND (1, IMMB, *ip, imm);
13527 bfd_reloc_code_real_type r[3];
13531 if (my_getSmallExpression (&ep, r, s) > 0
13532 || ep.X_op != O_constant)
13535 for (imm = 0; imm < 16; imm++)
13536 if (micromips_imm_c_map[imm] == ep.X_add_number)
13541 INSERT_OPERAND (1, IMMC, *ip, imm);
13546 case 'D': /* pc relative offset */
13547 case 'E': /* pc relative offset */
13548 my_getExpression (&offset_expr, s);
13549 if (offset_expr.X_op == O_register)
13552 if (!forced_insn_length)
13553 *offset_reloc = (int) BFD_RELOC_UNUSED + c;
13555 *offset_reloc = BFD_RELOC_MICROMIPS_10_PCREL_S1;
13557 *offset_reloc = BFD_RELOC_MICROMIPS_7_PCREL_S1;
13563 bfd_reloc_code_real_type r[3];
13567 if (my_getSmallExpression (&ep, r, s) > 0
13568 || !expr_const_in_range (&ep, 0, 16, 0))
13571 imm = ep.X_add_number;
13572 INSERT_OPERAND (1, IMMF, *ip, imm);
13579 bfd_reloc_code_real_type r[3];
13583 /* Check whether there is only a single bracketed
13584 expression left. If so, it must be the base register
13585 and the constant must be zero. */
13586 if (*s == '(' && strchr (s + 1, '(') == 0)
13588 INSERT_OPERAND (1, IMMG, *ip, 0);
13592 if (my_getSmallExpression (&ep, r, s) > 0
13593 || !expr_const_in_range (&ep, -1, 15, 0))
13596 imm = ep.X_add_number & 15;
13597 INSERT_OPERAND (1, IMMG, *ip, imm);
13604 bfd_reloc_code_real_type r[3];
13608 /* Check whether there is only a single bracketed
13609 expression left. If so, it must be the base register
13610 and the constant must be zero. */
13611 if (*s == '(' && strchr (s + 1, '(') == 0)
13613 INSERT_OPERAND (1, IMMH, *ip, 0);
13617 if (my_getSmallExpression (&ep, r, s) > 0
13618 || !expr_const_in_range (&ep, 0, 16, 1))
13621 imm = ep.X_add_number >> 1;
13622 INSERT_OPERAND (1, IMMH, *ip, imm);
13629 bfd_reloc_code_real_type r[3];
13633 if (my_getSmallExpression (&ep, r, s) > 0
13634 || !expr_const_in_range (&ep, -1, 127, 0))
13637 imm = ep.X_add_number & 127;
13638 INSERT_OPERAND (1, IMMI, *ip, imm);
13645 bfd_reloc_code_real_type r[3];
13649 /* Check whether there is only a single bracketed
13650 expression left. If so, it must be the base register
13651 and the constant must be zero. */
13652 if (*s == '(' && strchr (s + 1, '(') == 0)
13654 INSERT_OPERAND (1, IMMJ, *ip, 0);
13658 if (my_getSmallExpression (&ep, r, s) > 0
13659 || !expr_const_in_range (&ep, 0, 16, 2))
13662 imm = ep.X_add_number >> 2;
13663 INSERT_OPERAND (1, IMMJ, *ip, imm);
13670 bfd_reloc_code_real_type r[3];
13674 /* Check whether there is only a single bracketed
13675 expression left. If so, it must be the base register
13676 and the constant must be zero. */
13677 if (*s == '(' && strchr (s + 1, '(') == 0)
13679 INSERT_OPERAND (1, IMML, *ip, 0);
13683 if (my_getSmallExpression (&ep, r, s) > 0
13684 || !expr_const_in_range (&ep, 0, 16, 0))
13687 imm = ep.X_add_number;
13688 INSERT_OPERAND (1, IMML, *ip, imm);
13695 bfd_reloc_code_real_type r[3];
13699 if (my_getSmallExpression (&ep, r, s) > 0
13700 || !expr_const_in_range (&ep, 1, 9, 0))
13703 imm = ep.X_add_number & 7;
13704 INSERT_OPERAND (1, IMMM, *ip, imm);
13709 case 'N': /* Register list for lwm and swm. */
13711 /* A comma-separated list of registers and/or
13712 dash-separated contiguous ranges including
13713 both ra and a set of one or more registers
13714 starting at s0 up to s3 which have to be
13721 and any permutations of these. */
13722 unsigned int reglist;
13725 if (!reglist_lookup (&s, RTYPE_NUM | RTYPE_GP, ®list))
13728 if ((reglist & 0xfff1ffff) != 0x80010000)
13731 reglist = (reglist >> 17) & 7;
13733 if ((reglist & -reglist) != reglist)
13736 imm = ffs (reglist) - 1;
13737 INSERT_OPERAND (1, IMMN, *ip, imm);
13741 case 'O': /* sdbbp 4-bit code. */
13743 bfd_reloc_code_real_type r[3];
13747 if (my_getSmallExpression (&ep, r, s) > 0
13748 || !expr_const_in_range (&ep, 0, 16, 0))
13751 imm = ep.X_add_number;
13752 INSERT_OPERAND (1, IMMO, *ip, imm);
13759 bfd_reloc_code_real_type r[3];
13763 if (my_getSmallExpression (&ep, r, s) > 0
13764 || !expr_const_in_range (&ep, 0, 32, 2))
13767 imm = ep.X_add_number >> 2;
13768 INSERT_OPERAND (1, IMMP, *ip, imm);
13775 bfd_reloc_code_real_type r[3];
13779 if (my_getSmallExpression (&ep, r, s) > 0
13780 || !expr_const_in_range (&ep, -0x400000, 0x400000, 2))
13783 imm = ep.X_add_number >> 2;
13784 INSERT_OPERAND (1, IMMQ, *ip, imm);
13791 bfd_reloc_code_real_type r[3];
13795 /* Check whether there is only a single bracketed
13796 expression left. If so, it must be the base register
13797 and the constant must be zero. */
13798 if (*s == '(' && strchr (s + 1, '(') == 0)
13800 INSERT_OPERAND (1, IMMU, *ip, 0);
13804 if (my_getSmallExpression (&ep, r, s) > 0
13805 || !expr_const_in_range (&ep, 0, 32, 2))
13808 imm = ep.X_add_number >> 2;
13809 INSERT_OPERAND (1, IMMU, *ip, imm);
13816 bfd_reloc_code_real_type r[3];
13820 if (my_getSmallExpression (&ep, r, s) > 0
13821 || !expr_const_in_range (&ep, 0, 64, 2))
13824 imm = ep.X_add_number >> 2;
13825 INSERT_OPERAND (1, IMMW, *ip, imm);
13832 bfd_reloc_code_real_type r[3];
13836 if (my_getSmallExpression (&ep, r, s) > 0
13837 || !expr_const_in_range (&ep, -8, 8, 0))
13840 imm = ep.X_add_number;
13841 INSERT_OPERAND (1, IMMX, *ip, imm);
13848 bfd_reloc_code_real_type r[3];
13852 if (my_getSmallExpression (&ep, r, s) > 0
13853 || expr_const_in_range (&ep, -2, 2, 2)
13854 || !expr_const_in_range (&ep, -258, 258, 2))
13857 imm = ep.X_add_number >> 2;
13858 imm = ((imm >> 1) & ~0xff) | (imm & 0xff);
13859 INSERT_OPERAND (1, IMMY, *ip, imm);
13866 bfd_reloc_code_real_type r[3];
13869 if (my_getSmallExpression (&ep, r, s) > 0
13870 || !expr_const_in_range (&ep, 0, 1, 0))
13877 as_bad (_("Internal error: bad microMIPS opcode "
13878 "(unknown extension operand type `m%c'): %s %s"),
13879 *args, insn->name, insn->args);
13880 /* Further processing is fruitless. */
13885 case 'n': /* Register list for 32-bit lwm and swm. */
13886 gas_assert (mips_opts.micromips);
13888 /* A comma-separated list of registers and/or
13889 dash-separated contiguous ranges including
13890 at least one of ra and a set of one or more
13891 registers starting at s0 up to s7 and then
13892 s8 which have to be consecutive, e.g.:
13900 and any permutations of these. */
13901 unsigned int reglist;
13905 if (!reglist_lookup (&s, RTYPE_NUM | RTYPE_GP, ®list))
13908 if ((reglist & 0x3f00ffff) != 0)
13911 ra = (reglist >> 27) & 0x10;
13912 reglist = ((reglist >> 22) & 0x100) | ((reglist >> 16) & 0xff);
13914 if ((reglist & -reglist) != reglist)
13917 imm = (ffs (reglist) - 1) | ra;
13918 INSERT_OPERAND (1, RT, *ip, imm);
13919 imm_expr.X_op = O_absent;
13923 case '|': /* 4-bit trap code. */
13924 gas_assert (mips_opts.micromips);
13925 my_getExpression (&imm_expr, s);
13926 check_absolute_expr (ip, &imm_expr);
13927 if ((unsigned long) imm_expr.X_add_number
13928 > MICROMIPSOP_MASK_TRAP)
13929 as_bad (_("Trap code (%lu) for %s not in 0..15 range"),
13930 (unsigned long) imm_expr.X_add_number,
13931 ip->insn_mo->name);
13932 INSERT_OPERAND (1, TRAP, *ip, imm_expr.X_add_number);
13933 imm_expr.X_op = O_absent;
13938 as_bad (_("Bad char = '%c'\n"), *args);
13943 /* Args don't match. */
13945 insn_error = _("Illegal operands");
13946 if (insn + 1 < past && !strcmp (insn->name, insn[1].name))
13951 else if (wrong_delay_slot_insns && need_delay_slot_ok)
13953 gas_assert (firstinsn);
13954 need_delay_slot_ok = FALSE;
13963 #define SKIP_SPACE_TABS(S) { while (*(S) == ' ' || *(S) == '\t') ++(S); }
13965 /* This routine assembles an instruction into its binary format when
13966 assembling for the mips16. As a side effect, it sets one of the
13967 global variables imm_reloc or offset_reloc to the type of relocation
13968 to do if one of the operands is an address expression. It also sets
13969 forced_insn_length to the resulting instruction size in bytes if the
13970 user explicitly requested a small or extended instruction. */
13973 mips16_ip (char *str, struct mips_cl_insn *ip)
13977 struct mips_opcode *insn;
13979 unsigned int regno;
13980 unsigned int lastregno = 0;
13986 forced_insn_length = 0;
13988 for (s = str; ISLOWER (*s); ++s)
14000 if (s[1] == 't' && s[2] == ' ')
14003 forced_insn_length = 2;
14007 else if (s[1] == 'e' && s[2] == ' ')
14010 forced_insn_length = 4;
14014 /* Fall through. */
14016 insn_error = _("unknown opcode");
14020 if (mips_opts.noautoextend && !forced_insn_length)
14021 forced_insn_length = 2;
14023 if ((insn = (struct mips_opcode *) hash_find (mips16_op_hash, str)) == NULL)
14025 insn_error = _("unrecognized opcode");
14034 gas_assert (strcmp (insn->name, str) == 0);
14036 ok = is_opcode_valid_16 (insn);
14039 if (insn + 1 < &mips16_opcodes[bfd_mips16_num_opcodes]
14040 && strcmp (insn->name, insn[1].name) == 0)
14049 static char buf[100];
14051 _("Opcode not supported on this processor: %s (%s)"),
14052 mips_cpu_info_from_arch (mips_opts.arch)->name,
14053 mips_cpu_info_from_isa (mips_opts.isa)->name);
14060 create_insn (ip, insn);
14061 imm_expr.X_op = O_absent;
14062 imm_reloc[0] = BFD_RELOC_UNUSED;
14063 imm_reloc[1] = BFD_RELOC_UNUSED;
14064 imm_reloc[2] = BFD_RELOC_UNUSED;
14065 imm2_expr.X_op = O_absent;
14066 offset_expr.X_op = O_absent;
14067 offset_reloc[0] = BFD_RELOC_UNUSED;
14068 offset_reloc[1] = BFD_RELOC_UNUSED;
14069 offset_reloc[2] = BFD_RELOC_UNUSED;
14070 for (args = insn->args; 1; ++args)
14077 /* In this switch statement we call break if we did not find
14078 a match, continue if we did find a match, or return if we
14089 /* Stuff the immediate value in now, if we can. */
14090 if (imm_expr.X_op == O_constant
14091 && *imm_reloc > BFD_RELOC_UNUSED
14092 && insn->pinfo != INSN_MACRO
14093 && calculate_reloc (*offset_reloc,
14094 imm_expr.X_add_number, &value))
14096 mips16_immed (NULL, 0, *imm_reloc - BFD_RELOC_UNUSED,
14097 *offset_reloc, value, forced_insn_length,
14099 imm_expr.X_op = O_absent;
14100 *imm_reloc = BFD_RELOC_UNUSED;
14101 *offset_reloc = BFD_RELOC_UNUSED;
14115 MIPS16_INSERT_OPERAND (RX, *ip, lastregno);
14118 MIPS16_INSERT_OPERAND (RY, *ip, lastregno);
14134 MIPS16_INSERT_OPERAND (RX, *ip, lastregno);
14136 MIPS16_INSERT_OPERAND (RY, *ip, lastregno);
14140 /* Fall through. */
14151 if (!reg_lookup (&s, RTYPE_NUM | RTYPE_GP, ®no))
14153 if (c == 'v' || c == 'w')
14156 MIPS16_INSERT_OPERAND (RX, *ip, lastregno);
14158 MIPS16_INSERT_OPERAND (RY, *ip, lastregno);
14169 if (c == 'v' || c == 'w')
14171 regno = mips16_to_32_reg_map[lastregno];
14185 regno = mips32_to_16_reg_map[regno];
14190 regno = ILLEGAL_REG;
14195 regno = ILLEGAL_REG;
14200 regno = ILLEGAL_REG;
14205 if (regno == AT && mips_opts.at)
14207 if (mips_opts.at == ATREG)
14208 as_warn (_("used $at without \".set noat\""));
14210 as_warn (_("used $%u with \".set at=$%u\""),
14211 regno, mips_opts.at);
14219 if (regno == ILLEGAL_REG)
14226 MIPS16_INSERT_OPERAND (RX, *ip, regno);
14230 MIPS16_INSERT_OPERAND (RY, *ip, regno);
14233 MIPS16_INSERT_OPERAND (RZ, *ip, regno);
14236 MIPS16_INSERT_OPERAND (MOVE32Z, *ip, regno);
14242 MIPS16_INSERT_OPERAND (REGR32, *ip, regno);
14245 regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3);
14246 MIPS16_INSERT_OPERAND (REG32R, *ip, regno);
14256 if (strncmp (s, "$pc", 3) == 0)
14273 i = my_getSmallExpression (&imm_expr, imm_reloc, s);
14276 if (imm_expr.X_op != O_constant)
14278 forced_insn_length = 4;
14279 ip->insn_opcode |= MIPS16_EXTEND;
14283 /* We need to relax this instruction. */
14284 *offset_reloc = *imm_reloc;
14285 *imm_reloc = (int) BFD_RELOC_UNUSED + c;
14290 *imm_reloc = BFD_RELOC_UNUSED;
14291 /* Fall through. */
14298 my_getExpression (&imm_expr, s);
14299 if (imm_expr.X_op == O_register)
14301 /* What we thought was an expression turned out to
14304 if (s[0] == '(' && args[1] == '(')
14306 /* It looks like the expression was omitted
14307 before a register indirection, which means
14308 that the expression is implicitly zero. We
14309 still set up imm_expr, so that we handle
14310 explicit extensions correctly. */
14311 imm_expr.X_op = O_constant;
14312 imm_expr.X_add_number = 0;
14313 *imm_reloc = (int) BFD_RELOC_UNUSED + c;
14320 /* We need to relax this instruction. */
14321 *imm_reloc = (int) BFD_RELOC_UNUSED + c;
14330 /* We use offset_reloc rather than imm_reloc for the PC
14331 relative operands. This lets macros with both
14332 immediate and address operands work correctly. */
14333 my_getExpression (&offset_expr, s);
14335 if (offset_expr.X_op == O_register)
14338 /* We need to relax this instruction. */
14339 *offset_reloc = (int) BFD_RELOC_UNUSED + c;
14343 case '6': /* break code */
14344 my_getExpression (&imm_expr, s);
14345 check_absolute_expr (ip, &imm_expr);
14346 if ((unsigned long) imm_expr.X_add_number > 63)
14347 as_warn (_("Invalid value for `%s' (%lu)"),
14349 (unsigned long) imm_expr.X_add_number);
14350 MIPS16_INSERT_OPERAND (IMM6, *ip, imm_expr.X_add_number);
14351 imm_expr.X_op = O_absent;
14355 case 'a': /* 26 bit address */
14356 my_getExpression (&offset_expr, s);
14358 *offset_reloc = BFD_RELOC_MIPS16_JMP;
14359 ip->insn_opcode <<= 16;
14362 case 'l': /* register list for entry macro */
14363 case 'L': /* register list for exit macro */
14373 unsigned int freg, reg1, reg2;
14375 while (*s == ' ' || *s == ',')
14377 if (reg_lookup (&s, RTYPE_GP | RTYPE_NUM, ®1))
14379 else if (reg_lookup (&s, RTYPE_FPU, ®1))
14383 as_bad (_("can't parse register list"));
14393 if (!reg_lookup (&s, freg ? RTYPE_FPU
14394 : (RTYPE_GP | RTYPE_NUM), ®2))
14396 as_bad (_("invalid register list"));
14400 if (freg && reg1 == 0 && reg2 == 0 && c == 'L')
14402 mask &= ~ (7 << 3);
14405 else if (freg && reg1 == 0 && reg2 == 1 && c == 'L')
14407 mask &= ~ (7 << 3);
14410 else if (reg1 == 4 && reg2 >= 4 && reg2 <= 7 && c != 'L')
14411 mask |= (reg2 - 3) << 3;
14412 else if (reg1 == 16 && reg2 >= 16 && reg2 <= 17)
14413 mask |= (reg2 - 15) << 1;
14414 else if (reg1 == RA && reg2 == RA)
14418 as_bad (_("invalid register list"));
14422 /* The mask is filled in in the opcode table for the
14423 benefit of the disassembler. We remove it before
14424 applying the actual mask. */
14425 ip->insn_opcode &= ~ ((7 << 3) << MIPS16OP_SH_IMM6);
14426 ip->insn_opcode |= mask << MIPS16OP_SH_IMM6;
14430 case 'm': /* Register list for save insn. */
14431 case 'M': /* Register list for restore insn. */
14433 int opcode = ip->insn_opcode;
14434 int framesz = 0, seen_framesz = 0;
14435 int nargs = 0, statics = 0, sregs = 0;
14439 unsigned int reg1, reg2;
14441 SKIP_SPACE_TABS (s);
14444 SKIP_SPACE_TABS (s);
14446 my_getExpression (&imm_expr, s);
14447 if (imm_expr.X_op == O_constant)
14449 /* Handle the frame size. */
14452 as_bad (_("more than one frame size in list"));
14456 framesz = imm_expr.X_add_number;
14457 imm_expr.X_op = O_absent;
14462 if (! reg_lookup (&s, RTYPE_GP | RTYPE_NUM, ®1))
14464 as_bad (_("can't parse register list"));
14476 if (! reg_lookup (&s, RTYPE_GP | RTYPE_NUM, ®2)
14479 as_bad (_("can't parse register list"));
14484 while (reg1 <= reg2)
14486 if (reg1 >= 4 && reg1 <= 7)
14490 nargs |= 1 << (reg1 - 4);
14492 /* statics $a0-$a3 */
14493 statics |= 1 << (reg1 - 4);
14495 else if ((reg1 >= 16 && reg1 <= 23) || reg1 == 30)
14498 sregs |= 1 << ((reg1 == 30) ? 8 : (reg1 - 16));
14500 else if (reg1 == 31)
14502 /* Add $ra to insn. */
14507 as_bad (_("unexpected register in list"));
14515 /* Encode args/statics combination. */
14516 if (nargs & statics)
14517 as_bad (_("arg/static registers overlap"));
14518 else if (nargs == 0xf)
14519 /* All $a0-$a3 are args. */
14520 opcode |= MIPS16_ALL_ARGS << 16;
14521 else if (statics == 0xf)
14522 /* All $a0-$a3 are statics. */
14523 opcode |= MIPS16_ALL_STATICS << 16;
14526 int narg = 0, nstat = 0;
14528 /* Count arg registers. */
14529 while (nargs & 0x1)
14535 as_bad (_("invalid arg register list"));
14537 /* Count static registers. */
14538 while (statics & 0x8)
14540 statics = (statics << 1) & 0xf;
14544 as_bad (_("invalid static register list"));
14546 /* Encode args/statics. */
14547 opcode |= ((narg << 2) | nstat) << 16;
14550 /* Encode $s0/$s1. */
14551 if (sregs & (1 << 0)) /* $s0 */
14553 if (sregs & (1 << 1)) /* $s1 */
14559 /* Count regs $s2-$s8. */
14567 as_bad (_("invalid static register list"));
14568 /* Encode $s2-$s8. */
14569 opcode |= nsreg << 24;
14572 /* Encode frame size. */
14574 as_bad (_("missing frame size"));
14575 else if ((framesz & 7) != 0 || framesz < 0
14576 || framesz > 0xff * 8)
14577 as_bad (_("invalid frame size"));
14578 else if (framesz != 128 || (opcode >> 16) != 0)
14581 opcode |= (((framesz & 0xf0) << 16)
14582 | (framesz & 0x0f));
14585 /* Finally build the instruction. */
14586 if ((opcode >> 16) != 0 || framesz == 0)
14587 opcode |= MIPS16_EXTEND;
14588 ip->insn_opcode = opcode;
14592 case 'e': /* extend code */
14593 my_getExpression (&imm_expr, s);
14594 check_absolute_expr (ip, &imm_expr);
14595 if ((unsigned long) imm_expr.X_add_number > 0x7ff)
14597 as_warn (_("Invalid value for `%s' (%lu)"),
14599 (unsigned long) imm_expr.X_add_number);
14600 imm_expr.X_add_number &= 0x7ff;
14602 ip->insn_opcode |= imm_expr.X_add_number;
14603 imm_expr.X_op = O_absent;
14613 /* Args don't match. */
14614 if (insn + 1 < &mips16_opcodes[bfd_mips16_num_opcodes] &&
14615 strcmp (insn->name, insn[1].name) == 0)
14622 insn_error = _("illegal operands");
14628 /* This structure holds information we know about a mips16 immediate
14631 struct mips16_immed_operand
14633 /* The type code used in the argument string in the opcode table. */
14635 /* The number of bits in the short form of the opcode. */
14637 /* The number of bits in the extended form of the opcode. */
14639 /* The amount by which the short form is shifted when it is used;
14640 for example, the sw instruction has a shift count of 2. */
14642 /* The amount by which the short form is shifted when it is stored
14643 into the instruction code. */
14645 /* Non-zero if the short form is unsigned. */
14647 /* Non-zero if the extended form is unsigned. */
14649 /* Non-zero if the value is PC relative. */
14653 /* The mips16 immediate operand types. */
14655 static const struct mips16_immed_operand mips16_immed_operands[] =
14657 { '<', 3, 5, 0, MIPS16OP_SH_RZ, 1, 1, 0 },
14658 { '>', 3, 5, 0, MIPS16OP_SH_RX, 1, 1, 0 },
14659 { '[', 3, 6, 0, MIPS16OP_SH_RZ, 1, 1, 0 },
14660 { ']', 3, 6, 0, MIPS16OP_SH_RX, 1, 1, 0 },
14661 { '4', 4, 15, 0, MIPS16OP_SH_IMM4, 0, 0, 0 },
14662 { '5', 5, 16, 0, MIPS16OP_SH_IMM5, 1, 0, 0 },
14663 { 'H', 5, 16, 1, MIPS16OP_SH_IMM5, 1, 0, 0 },
14664 { 'W', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 0 },
14665 { 'D', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 0 },
14666 { 'j', 5, 16, 0, MIPS16OP_SH_IMM5, 0, 0, 0 },
14667 { '8', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 0, 0 },
14668 { 'V', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 0 },
14669 { 'C', 8, 16, 3, MIPS16OP_SH_IMM8, 1, 0, 0 },
14670 { 'U', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 1, 0 },
14671 { 'k', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 0 },
14672 { 'K', 8, 16, 3, MIPS16OP_SH_IMM8, 0, 0, 0 },
14673 { 'p', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 },
14674 { 'q', 11, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 },
14675 { 'A', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 1 },
14676 { 'B', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 1 },
14677 { 'E', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 1 }
14680 #define MIPS16_NUM_IMMED \
14681 (sizeof mips16_immed_operands / sizeof mips16_immed_operands[0])
14683 /* Marshal immediate value VAL for an extended MIPS16 instruction.
14684 NBITS is the number of significant bits in VAL. */
14686 static unsigned long
14687 mips16_immed_extend (offsetT val, unsigned int nbits)
14692 extval = ((val >> 11) & 0x1f) | (val & 0x7e0);
14695 else if (nbits == 15)
14697 extval = ((val >> 11) & 0xf) | (val & 0x7f0);
14702 extval = ((val & 0x1f) << 6) | (val & 0x20);
14705 return (extval << 16) | val;
14708 /* Install immediate value VAL into MIPS16 instruction *INSN,
14709 extending it if necessary. The instruction in *INSN may
14710 already be extended.
14712 RELOC is the relocation that produced VAL, or BFD_RELOC_UNUSED
14713 if none. In the former case, VAL is a 16-bit number with no
14714 defined signedness.
14716 TYPE is the type of the immediate field. USER_INSN_LENGTH
14717 is the length that the user requested, or 0 if none. */
14720 mips16_immed (char *file, unsigned int line, int type,
14721 bfd_reloc_code_real_type reloc, offsetT val,
14722 unsigned int user_insn_length, unsigned long *insn)
14724 const struct mips16_immed_operand *op;
14725 int mintiny, maxtiny;
14727 op = mips16_immed_operands;
14728 while (op->type != type)
14731 gas_assert (op < mips16_immed_operands + MIPS16_NUM_IMMED);
14736 if (type == '<' || type == '>' || type == '[' || type == ']')
14739 maxtiny = 1 << op->nbits;
14744 maxtiny = (1 << op->nbits) - 1;
14746 if (reloc != BFD_RELOC_UNUSED)
14751 mintiny = - (1 << (op->nbits - 1));
14752 maxtiny = (1 << (op->nbits - 1)) - 1;
14753 if (reloc != BFD_RELOC_UNUSED)
14754 val = SEXT_16BIT (val);
14757 /* Branch offsets have an implicit 0 in the lowest bit. */
14758 if (type == 'p' || type == 'q')
14761 if ((val & ((1 << op->shift) - 1)) != 0
14762 || val < (mintiny << op->shift)
14763 || val > (maxtiny << op->shift))
14765 /* We need an extended instruction. */
14766 if (user_insn_length == 2)
14767 as_bad_where (file, line, _("invalid unextended operand value"));
14769 *insn |= MIPS16_EXTEND;
14771 else if (user_insn_length == 4)
14773 /* The operand doesn't force an unextended instruction to be extended.
14774 Warn if the user wanted an extended instruction anyway. */
14775 *insn |= MIPS16_EXTEND;
14776 as_warn_where (file, line,
14777 _("extended operand requested but not required"));
14780 if (mips16_opcode_length (*insn) == 2)
14784 insnval = ((val >> op->shift) & ((1 << op->nbits) - 1));
14785 insnval <<= op->op_shift;
14790 long minext, maxext;
14792 if (reloc == BFD_RELOC_UNUSED)
14797 maxext = (1 << op->extbits) - 1;
14801 minext = - (1 << (op->extbits - 1));
14802 maxext = (1 << (op->extbits - 1)) - 1;
14804 if (val < minext || val > maxext)
14805 as_bad_where (file, line,
14806 _("operand value out of range for instruction"));
14809 *insn |= mips16_immed_extend (val, op->extbits);
14813 struct percent_op_match
14816 bfd_reloc_code_real_type reloc;
14819 static const struct percent_op_match mips_percent_op[] =
14821 {"%lo", BFD_RELOC_LO16},
14823 {"%call_hi", BFD_RELOC_MIPS_CALL_HI16},
14824 {"%call_lo", BFD_RELOC_MIPS_CALL_LO16},
14825 {"%call16", BFD_RELOC_MIPS_CALL16},
14826 {"%got_disp", BFD_RELOC_MIPS_GOT_DISP},
14827 {"%got_page", BFD_RELOC_MIPS_GOT_PAGE},
14828 {"%got_ofst", BFD_RELOC_MIPS_GOT_OFST},
14829 {"%got_hi", BFD_RELOC_MIPS_GOT_HI16},
14830 {"%got_lo", BFD_RELOC_MIPS_GOT_LO16},
14831 {"%got", BFD_RELOC_MIPS_GOT16},
14832 {"%gp_rel", BFD_RELOC_GPREL16},
14833 {"%half", BFD_RELOC_16},
14834 {"%highest", BFD_RELOC_MIPS_HIGHEST},
14835 {"%higher", BFD_RELOC_MIPS_HIGHER},
14836 {"%neg", BFD_RELOC_MIPS_SUB},
14837 {"%tlsgd", BFD_RELOC_MIPS_TLS_GD},
14838 {"%tlsldm", BFD_RELOC_MIPS_TLS_LDM},
14839 {"%dtprel_hi", BFD_RELOC_MIPS_TLS_DTPREL_HI16},
14840 {"%dtprel_lo", BFD_RELOC_MIPS_TLS_DTPREL_LO16},
14841 {"%tprel_hi", BFD_RELOC_MIPS_TLS_TPREL_HI16},
14842 {"%tprel_lo", BFD_RELOC_MIPS_TLS_TPREL_LO16},
14843 {"%gottprel", BFD_RELOC_MIPS_TLS_GOTTPREL},
14845 {"%hi", BFD_RELOC_HI16_S}
14848 static const struct percent_op_match mips16_percent_op[] =
14850 {"%lo", BFD_RELOC_MIPS16_LO16},
14851 {"%gprel", BFD_RELOC_MIPS16_GPREL},
14852 {"%got", BFD_RELOC_MIPS16_GOT16},
14853 {"%call16", BFD_RELOC_MIPS16_CALL16},
14854 {"%hi", BFD_RELOC_MIPS16_HI16_S},
14855 {"%tlsgd", BFD_RELOC_MIPS16_TLS_GD},
14856 {"%tlsldm", BFD_RELOC_MIPS16_TLS_LDM},
14857 {"%dtprel_hi", BFD_RELOC_MIPS16_TLS_DTPREL_HI16},
14858 {"%dtprel_lo", BFD_RELOC_MIPS16_TLS_DTPREL_LO16},
14859 {"%tprel_hi", BFD_RELOC_MIPS16_TLS_TPREL_HI16},
14860 {"%tprel_lo", BFD_RELOC_MIPS16_TLS_TPREL_LO16},
14861 {"%gottprel", BFD_RELOC_MIPS16_TLS_GOTTPREL}
14865 /* Return true if *STR points to a relocation operator. When returning true,
14866 move *STR over the operator and store its relocation code in *RELOC.
14867 Leave both *STR and *RELOC alone when returning false. */
14870 parse_relocation (char **str, bfd_reloc_code_real_type *reloc)
14872 const struct percent_op_match *percent_op;
14875 if (mips_opts.mips16)
14877 percent_op = mips16_percent_op;
14878 limit = ARRAY_SIZE (mips16_percent_op);
14882 percent_op = mips_percent_op;
14883 limit = ARRAY_SIZE (mips_percent_op);
14886 for (i = 0; i < limit; i++)
14887 if (strncasecmp (*str, percent_op[i].str, strlen (percent_op[i].str)) == 0)
14889 int len = strlen (percent_op[i].str);
14891 if (!ISSPACE ((*str)[len]) && (*str)[len] != '(')
14894 *str += strlen (percent_op[i].str);
14895 *reloc = percent_op[i].reloc;
14897 /* Check whether the output BFD supports this relocation.
14898 If not, issue an error and fall back on something safe. */
14899 if (!bfd_reloc_type_lookup (stdoutput, percent_op[i].reloc))
14901 as_bad (_("relocation %s isn't supported by the current ABI"),
14902 percent_op[i].str);
14903 *reloc = BFD_RELOC_UNUSED;
14911 /* Parse string STR as a 16-bit relocatable operand. Store the
14912 expression in *EP and the relocations in the array starting
14913 at RELOC. Return the number of relocation operators used.
14915 On exit, EXPR_END points to the first character after the expression. */
14918 my_getSmallExpression (expressionS *ep, bfd_reloc_code_real_type *reloc,
14921 bfd_reloc_code_real_type reversed_reloc[3];
14922 size_t reloc_index, i;
14923 int crux_depth, str_depth;
14926 /* Search for the start of the main expression, recoding relocations
14927 in REVERSED_RELOC. End the loop with CRUX pointing to the start
14928 of the main expression and with CRUX_DEPTH containing the number
14929 of open brackets at that point. */
14936 crux_depth = str_depth;
14938 /* Skip over whitespace and brackets, keeping count of the number
14940 while (*str == ' ' || *str == '\t' || *str == '(')
14945 && reloc_index < (HAVE_NEWABI ? 3 : 1)
14946 && parse_relocation (&str, &reversed_reloc[reloc_index]));
14948 my_getExpression (ep, crux);
14951 /* Match every open bracket. */
14952 while (crux_depth > 0 && (*str == ')' || *str == ' ' || *str == '\t'))
14956 if (crux_depth > 0)
14957 as_bad (_("unclosed '('"));
14961 if (reloc_index != 0)
14963 prev_reloc_op_frag = frag_now;
14964 for (i = 0; i < reloc_index; i++)
14965 reloc[i] = reversed_reloc[reloc_index - 1 - i];
14968 return reloc_index;
14972 my_getExpression (expressionS *ep, char *str)
14976 save_in = input_line_pointer;
14977 input_line_pointer = str;
14979 expr_end = input_line_pointer;
14980 input_line_pointer = save_in;
14984 md_atof (int type, char *litP, int *sizeP)
14986 return ieee_md_atof (type, litP, sizeP, target_big_endian);
14990 md_number_to_chars (char *buf, valueT val, int n)
14992 if (target_big_endian)
14993 number_to_chars_bigendian (buf, val, n);
14995 number_to_chars_littleendian (buf, val, n);
14999 static int support_64bit_objects(void)
15001 const char **list, **l;
15004 list = bfd_target_list ();
15005 for (l = list; *l != NULL; l++)
15006 if (strcmp (*l, ELF_TARGET ("elf64-", "big")) == 0
15007 || strcmp (*l, ELF_TARGET ("elf64-", "little")) == 0)
15009 yes = (*l != NULL);
15013 #endif /* OBJ_ELF */
15015 /* Set STRING_PTR (either &mips_arch_string or &mips_tune_string) to
15016 NEW_VALUE. Warn if another value was already specified. Note:
15017 we have to defer parsing the -march and -mtune arguments in order
15018 to handle 'from-abi' correctly, since the ABI might be specified
15019 in a later argument. */
15022 mips_set_option_string (const char **string_ptr, const char *new_value)
15024 if (*string_ptr != 0 && strcasecmp (*string_ptr, new_value) != 0)
15025 as_warn (_("A different %s was already specified, is now %s"),
15026 string_ptr == &mips_arch_string ? "-march" : "-mtune",
15029 *string_ptr = new_value;
15033 md_parse_option (int c, char *arg)
15037 for (i = 0; i < ARRAY_SIZE (mips_ases); i++)
15038 if (c == mips_ases[i].option_on || c == mips_ases[i].option_off)
15040 file_ase_explicit |= mips_set_ase (&mips_ases[i],
15041 c == mips_ases[i].option_on);
15047 case OPTION_CONSTRUCT_FLOATS:
15048 mips_disable_float_construction = 0;
15051 case OPTION_NO_CONSTRUCT_FLOATS:
15052 mips_disable_float_construction = 1;
15064 target_big_endian = 1;
15068 target_big_endian = 0;
15074 else if (arg[0] == '0')
15076 else if (arg[0] == '1')
15086 mips_debug = atoi (arg);
15090 file_mips_isa = ISA_MIPS1;
15094 file_mips_isa = ISA_MIPS2;
15098 file_mips_isa = ISA_MIPS3;
15102 file_mips_isa = ISA_MIPS4;
15106 file_mips_isa = ISA_MIPS5;
15109 case OPTION_MIPS32:
15110 file_mips_isa = ISA_MIPS32;
15113 case OPTION_MIPS32R2:
15114 file_mips_isa = ISA_MIPS32R2;
15117 case OPTION_MIPS64R2:
15118 file_mips_isa = ISA_MIPS64R2;
15121 case OPTION_MIPS64:
15122 file_mips_isa = ISA_MIPS64;
15126 mips_set_option_string (&mips_tune_string, arg);
15130 mips_set_option_string (&mips_arch_string, arg);
15134 mips_set_option_string (&mips_arch_string, "4650");
15135 mips_set_option_string (&mips_tune_string, "4650");
15138 case OPTION_NO_M4650:
15142 mips_set_option_string (&mips_arch_string, "4010");
15143 mips_set_option_string (&mips_tune_string, "4010");
15146 case OPTION_NO_M4010:
15150 mips_set_option_string (&mips_arch_string, "4100");
15151 mips_set_option_string (&mips_tune_string, "4100");
15154 case OPTION_NO_M4100:
15158 mips_set_option_string (&mips_arch_string, "3900");
15159 mips_set_option_string (&mips_tune_string, "3900");
15162 case OPTION_NO_M3900:
15165 case OPTION_MICROMIPS:
15166 if (mips_opts.mips16 == 1)
15168 as_bad (_("-mmicromips cannot be used with -mips16"));
15171 mips_opts.micromips = 1;
15172 mips_no_prev_insn ();
15175 case OPTION_NO_MICROMIPS:
15176 mips_opts.micromips = 0;
15177 mips_no_prev_insn ();
15180 case OPTION_MIPS16:
15181 if (mips_opts.micromips == 1)
15183 as_bad (_("-mips16 cannot be used with -micromips"));
15186 mips_opts.mips16 = 1;
15187 mips_no_prev_insn ();
15190 case OPTION_NO_MIPS16:
15191 mips_opts.mips16 = 0;
15192 mips_no_prev_insn ();
15195 case OPTION_FIX_24K:
15199 case OPTION_NO_FIX_24K:
15203 case OPTION_FIX_LOONGSON2F_JUMP:
15204 mips_fix_loongson2f_jump = TRUE;
15207 case OPTION_NO_FIX_LOONGSON2F_JUMP:
15208 mips_fix_loongson2f_jump = FALSE;
15211 case OPTION_FIX_LOONGSON2F_NOP:
15212 mips_fix_loongson2f_nop = TRUE;
15215 case OPTION_NO_FIX_LOONGSON2F_NOP:
15216 mips_fix_loongson2f_nop = FALSE;
15219 case OPTION_FIX_VR4120:
15220 mips_fix_vr4120 = 1;
15223 case OPTION_NO_FIX_VR4120:
15224 mips_fix_vr4120 = 0;
15227 case OPTION_FIX_VR4130:
15228 mips_fix_vr4130 = 1;
15231 case OPTION_NO_FIX_VR4130:
15232 mips_fix_vr4130 = 0;
15235 case OPTION_FIX_CN63XXP1:
15236 mips_fix_cn63xxp1 = TRUE;
15239 case OPTION_NO_FIX_CN63XXP1:
15240 mips_fix_cn63xxp1 = FALSE;
15243 case OPTION_RELAX_BRANCH:
15244 mips_relax_branch = 1;
15247 case OPTION_NO_RELAX_BRANCH:
15248 mips_relax_branch = 0;
15251 case OPTION_MSHARED:
15252 mips_in_shared = TRUE;
15255 case OPTION_MNO_SHARED:
15256 mips_in_shared = FALSE;
15259 case OPTION_MSYM32:
15260 mips_opts.sym32 = TRUE;
15263 case OPTION_MNO_SYM32:
15264 mips_opts.sym32 = FALSE;
15268 /* When generating ELF code, we permit -KPIC and -call_shared to
15269 select SVR4_PIC, and -non_shared to select no PIC. This is
15270 intended to be compatible with Irix 5. */
15271 case OPTION_CALL_SHARED:
15274 as_bad (_("-call_shared is supported only for ELF format"));
15277 mips_pic = SVR4_PIC;
15278 mips_abicalls = TRUE;
15281 case OPTION_CALL_NONPIC:
15284 as_bad (_("-call_nonpic is supported only for ELF format"));
15288 mips_abicalls = TRUE;
15291 case OPTION_NON_SHARED:
15294 as_bad (_("-non_shared is supported only for ELF format"));
15298 mips_abicalls = FALSE;
15301 /* The -xgot option tells the assembler to use 32 bit offsets
15302 when accessing the got in SVR4_PIC mode. It is for Irix
15307 #endif /* OBJ_ELF */
15310 g_switch_value = atoi (arg);
15314 /* The -32, -n32 and -64 options are shortcuts for -mabi=32, -mabi=n32
15318 mips_abi = O32_ABI;
15319 /* We silently ignore -32 for non-ELF targets. This greatly
15320 simplifies the construction of the MIPS GAS test cases. */
15327 as_bad (_("-n32 is supported for ELF format only"));
15330 mips_abi = N32_ABI;
15336 as_bad (_("-64 is supported for ELF format only"));
15339 mips_abi = N64_ABI;
15340 if (!support_64bit_objects())
15341 as_fatal (_("No compiled in support for 64 bit object file format"));
15343 #endif /* OBJ_ELF */
15346 file_mips_gp32 = 1;
15350 file_mips_gp32 = 0;
15354 file_mips_fp32 = 1;
15358 file_mips_fp32 = 0;
15361 case OPTION_SINGLE_FLOAT:
15362 file_mips_single_float = 1;
15365 case OPTION_DOUBLE_FLOAT:
15366 file_mips_single_float = 0;
15369 case OPTION_SOFT_FLOAT:
15370 file_mips_soft_float = 1;
15373 case OPTION_HARD_FLOAT:
15374 file_mips_soft_float = 0;
15381 as_bad (_("-mabi is supported for ELF format only"));
15384 if (strcmp (arg, "32") == 0)
15385 mips_abi = O32_ABI;
15386 else if (strcmp (arg, "o64") == 0)
15387 mips_abi = O64_ABI;
15388 else if (strcmp (arg, "n32") == 0)
15389 mips_abi = N32_ABI;
15390 else if (strcmp (arg, "64") == 0)
15392 mips_abi = N64_ABI;
15393 if (! support_64bit_objects())
15394 as_fatal (_("No compiled in support for 64 bit object file "
15397 else if (strcmp (arg, "eabi") == 0)
15398 mips_abi = EABI_ABI;
15401 as_fatal (_("invalid abi -mabi=%s"), arg);
15405 #endif /* OBJ_ELF */
15407 case OPTION_M7000_HILO_FIX:
15408 mips_7000_hilo_fix = TRUE;
15411 case OPTION_MNO_7000_HILO_FIX:
15412 mips_7000_hilo_fix = FALSE;
15416 case OPTION_MDEBUG:
15417 mips_flag_mdebug = TRUE;
15420 case OPTION_NO_MDEBUG:
15421 mips_flag_mdebug = FALSE;
15425 mips_flag_pdr = TRUE;
15428 case OPTION_NO_PDR:
15429 mips_flag_pdr = FALSE;
15432 case OPTION_MVXWORKS_PIC:
15433 mips_pic = VXWORKS_PIC;
15435 #endif /* OBJ_ELF */
15441 mips_fix_loongson2f = mips_fix_loongson2f_nop || mips_fix_loongson2f_jump;
15446 /* Set up globals to generate code for the ISA or processor
15447 described by INFO. */
15450 mips_set_architecture (const struct mips_cpu_info *info)
15454 file_mips_arch = info->cpu;
15455 mips_opts.arch = info->cpu;
15456 mips_opts.isa = info->isa;
15461 /* Likewise for tuning. */
15464 mips_set_tune (const struct mips_cpu_info *info)
15467 mips_tune = info->cpu;
15472 mips_after_parse_args (void)
15474 const struct mips_cpu_info *arch_info = 0;
15475 const struct mips_cpu_info *tune_info = 0;
15477 /* GP relative stuff not working for PE */
15478 if (strncmp (TARGET_OS, "pe", 2) == 0)
15480 if (g_switch_seen && g_switch_value != 0)
15481 as_bad (_("-G not supported in this configuration."));
15482 g_switch_value = 0;
15485 if (mips_abi == NO_ABI)
15486 mips_abi = MIPS_DEFAULT_ABI;
15488 /* The following code determines the architecture and register size.
15489 Similar code was added to GCC 3.3 (see override_options() in
15490 config/mips/mips.c). The GAS and GCC code should be kept in sync
15491 as much as possible. */
15493 if (mips_arch_string != 0)
15494 arch_info = mips_parse_cpu ("-march", mips_arch_string);
15496 if (file_mips_isa != ISA_UNKNOWN)
15498 /* Handle -mipsN. At this point, file_mips_isa contains the
15499 ISA level specified by -mipsN, while arch_info->isa contains
15500 the -march selection (if any). */
15501 if (arch_info != 0)
15503 /* -march takes precedence over -mipsN, since it is more descriptive.
15504 There's no harm in specifying both as long as the ISA levels
15506 if (file_mips_isa != arch_info->isa)
15507 as_bad (_("-%s conflicts with the other architecture options, which imply -%s"),
15508 mips_cpu_info_from_isa (file_mips_isa)->name,
15509 mips_cpu_info_from_isa (arch_info->isa)->name);
15512 arch_info = mips_cpu_info_from_isa (file_mips_isa);
15515 if (arch_info == 0)
15517 arch_info = mips_parse_cpu ("default CPU", MIPS_CPU_STRING_DEFAULT);
15518 gas_assert (arch_info);
15521 if (ABI_NEEDS_64BIT_REGS (mips_abi) && !ISA_HAS_64BIT_REGS (arch_info->isa))
15522 as_bad (_("-march=%s is not compatible with the selected ABI"),
15525 mips_set_architecture (arch_info);
15527 /* Optimize for file_mips_arch, unless -mtune selects a different processor. */
15528 if (mips_tune_string != 0)
15529 tune_info = mips_parse_cpu ("-mtune", mips_tune_string);
15531 if (tune_info == 0)
15532 mips_set_tune (arch_info);
15534 mips_set_tune (tune_info);
15536 if (file_mips_gp32 >= 0)
15538 /* The user specified the size of the integer registers. Make sure
15539 it agrees with the ABI and ISA. */
15540 if (file_mips_gp32 == 0 && !ISA_HAS_64BIT_REGS (mips_opts.isa))
15541 as_bad (_("-mgp64 used with a 32-bit processor"));
15542 else if (file_mips_gp32 == 1 && ABI_NEEDS_64BIT_REGS (mips_abi))
15543 as_bad (_("-mgp32 used with a 64-bit ABI"));
15544 else if (file_mips_gp32 == 0 && ABI_NEEDS_32BIT_REGS (mips_abi))
15545 as_bad (_("-mgp64 used with a 32-bit ABI"));
15549 /* Infer the integer register size from the ABI and processor.
15550 Restrict ourselves to 32-bit registers if that's all the
15551 processor has, or if the ABI cannot handle 64-bit registers. */
15552 file_mips_gp32 = (ABI_NEEDS_32BIT_REGS (mips_abi)
15553 || !ISA_HAS_64BIT_REGS (mips_opts.isa));
15556 switch (file_mips_fp32)
15560 /* No user specified float register size.
15561 ??? GAS treats single-float processors as though they had 64-bit
15562 float registers (although it complains when double-precision
15563 instructions are used). As things stand, saying they have 32-bit
15564 registers would lead to spurious "register must be even" messages.
15565 So here we assume float registers are never smaller than the
15567 if (file_mips_gp32 == 0)
15568 /* 64-bit integer registers implies 64-bit float registers. */
15569 file_mips_fp32 = 0;
15570 else if ((mips_opts.ase & FP64_ASES)
15571 && ISA_HAS_64BIT_FPRS (mips_opts.isa))
15572 /* -mips3d and -mdmx imply 64-bit float registers, if possible. */
15573 file_mips_fp32 = 0;
15575 /* 32-bit float registers. */
15576 file_mips_fp32 = 1;
15579 /* The user specified the size of the float registers. Check if it
15580 agrees with the ABI and ISA. */
15582 if (!ISA_HAS_64BIT_FPRS (mips_opts.isa))
15583 as_bad (_("-mfp64 used with a 32-bit fpu"));
15584 else if (ABI_NEEDS_32BIT_REGS (mips_abi)
15585 && !ISA_HAS_MXHC1 (mips_opts.isa))
15586 as_warn (_("-mfp64 used with a 32-bit ABI"));
15589 if (ABI_NEEDS_64BIT_REGS (mips_abi))
15590 as_warn (_("-mfp32 used with a 64-bit ABI"));
15594 /* End of GCC-shared inference code. */
15596 /* This flag is set when we have a 64-bit capable CPU but use only
15597 32-bit wide registers. Note that EABI does not use it. */
15598 if (ISA_HAS_64BIT_REGS (mips_opts.isa)
15599 && ((mips_abi == NO_ABI && file_mips_gp32 == 1)
15600 || mips_abi == O32_ABI))
15601 mips_32bitmode = 1;
15603 if (mips_opts.isa == ISA_MIPS1 && mips_trap)
15604 as_bad (_("trap exception not supported at ISA 1"));
15606 /* If the selected architecture includes support for ASEs, enable
15607 generation of code for them. */
15608 if (mips_opts.mips16 == -1)
15609 mips_opts.mips16 = (CPU_HAS_MIPS16 (file_mips_arch)) ? 1 : 0;
15610 if (mips_opts.micromips == -1)
15611 mips_opts.micromips = (CPU_HAS_MICROMIPS (file_mips_arch)) ? 1 : 0;
15613 /* MIPS3D and MDMX require 64-bit FPRs, so -mfp32 should stop those
15614 ASEs from being selected implicitly. */
15615 if (file_mips_fp32 == 1)
15616 file_ase_explicit |= ASE_MIPS3D | ASE_MDMX;
15618 /* If the user didn't explicitly select or deselect a particular ASE,
15619 use the default setting for the CPU. */
15620 mips_opts.ase |= (arch_info->ase & ~file_ase_explicit);
15622 file_mips_isa = mips_opts.isa;
15623 file_ase = mips_opts.ase;
15624 mips_opts.gp32 = file_mips_gp32;
15625 mips_opts.fp32 = file_mips_fp32;
15626 mips_opts.soft_float = file_mips_soft_float;
15627 mips_opts.single_float = file_mips_single_float;
15629 mips_check_isa_supports_ases ();
15631 if (mips_flag_mdebug < 0)
15633 #ifdef OBJ_MAYBE_ECOFF
15634 if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour)
15635 mips_flag_mdebug = 1;
15637 #endif /* OBJ_MAYBE_ECOFF */
15638 mips_flag_mdebug = 0;
15643 mips_init_after_args (void)
15645 /* initialize opcodes */
15646 bfd_mips_num_opcodes = bfd_mips_num_builtin_opcodes;
15647 mips_opcodes = (struct mips_opcode *) mips_builtin_opcodes;
15651 md_pcrel_from (fixS *fixP)
15653 valueT addr = fixP->fx_where + fixP->fx_frag->fr_address;
15654 switch (fixP->fx_r_type)
15656 case BFD_RELOC_MICROMIPS_7_PCREL_S1:
15657 case BFD_RELOC_MICROMIPS_10_PCREL_S1:
15658 /* Return the address of the delay slot. */
15661 case BFD_RELOC_MICROMIPS_16_PCREL_S1:
15662 case BFD_RELOC_MICROMIPS_JMP:
15663 case BFD_RELOC_16_PCREL_S2:
15664 case BFD_RELOC_MIPS_JMP:
15665 /* Return the address of the delay slot. */
15668 case BFD_RELOC_32_PCREL:
15672 /* We have no relocation type for PC relative MIPS16 instructions. */
15673 if (fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != now_seg)
15674 as_bad_where (fixP->fx_file, fixP->fx_line,
15675 _("PC relative MIPS16 instruction references a different section"));
15680 /* This is called before the symbol table is processed. In order to
15681 work with gcc when using mips-tfile, we must keep all local labels.
15682 However, in other cases, we want to discard them. If we were
15683 called with -g, but we didn't see any debugging information, it may
15684 mean that gcc is smuggling debugging information through to
15685 mips-tfile, in which case we must generate all local labels. */
15688 mips_frob_file_before_adjust (void)
15690 #ifndef NO_ECOFF_DEBUGGING
15691 if (ECOFF_DEBUGGING
15693 && ! ecoff_debugging_seen)
15694 flag_keep_locals = 1;
15698 /* Sort any unmatched HI16 and GOT16 relocs so that they immediately precede
15699 the corresponding LO16 reloc. This is called before md_apply_fix and
15700 tc_gen_reloc. Unmatched relocs can only be generated by use of explicit
15701 relocation operators.
15703 For our purposes, a %lo() expression matches a %got() or %hi()
15706 (a) it refers to the same symbol; and
15707 (b) the offset applied in the %lo() expression is no lower than
15708 the offset applied in the %got() or %hi().
15710 (b) allows us to cope with code like:
15713 lh $4,%lo(foo+2)($4)
15715 ...which is legal on RELA targets, and has a well-defined behaviour
15716 if the user knows that adding 2 to "foo" will not induce a carry to
15719 When several %lo()s match a particular %got() or %hi(), we use the
15720 following rules to distinguish them:
15722 (1) %lo()s with smaller offsets are a better match than %lo()s with
15725 (2) %lo()s with no matching %got() or %hi() are better than those
15726 that already have a matching %got() or %hi().
15728 (3) later %lo()s are better than earlier %lo()s.
15730 These rules are applied in order.
15732 (1) means, among other things, that %lo()s with identical offsets are
15733 chosen if they exist.
15735 (2) means that we won't associate several high-part relocations with
15736 the same low-part relocation unless there's no alternative. Having
15737 several high parts for the same low part is a GNU extension; this rule
15738 allows careful users to avoid it.
15740 (3) is purely cosmetic. mips_hi_fixup_list is is in reverse order,
15741 with the last high-part relocation being at the front of the list.
15742 It therefore makes sense to choose the last matching low-part
15743 relocation, all other things being equal. It's also easier
15744 to code that way. */
15747 mips_frob_file (void)
15749 struct mips_hi_fixup *l;
15750 bfd_reloc_code_real_type looking_for_rtype = BFD_RELOC_UNUSED;
15752 for (l = mips_hi_fixup_list; l != NULL; l = l->next)
15754 segment_info_type *seginfo;
15755 bfd_boolean matched_lo_p;
15756 fixS **hi_pos, **lo_pos, **pos;
15758 gas_assert (reloc_needs_lo_p (l->fixp->fx_r_type));
15760 /* If a GOT16 relocation turns out to be against a global symbol,
15761 there isn't supposed to be a matching LO. Ignore %gots against
15762 constants; we'll report an error for those later. */
15763 if (got16_reloc_p (l->fixp->fx_r_type)
15764 && !(l->fixp->fx_addsy
15765 && pic_need_relax (l->fixp->fx_addsy, l->seg)))
15768 /* Check quickly whether the next fixup happens to be a matching %lo. */
15769 if (fixup_has_matching_lo_p (l->fixp))
15772 seginfo = seg_info (l->seg);
15774 /* Set HI_POS to the position of this relocation in the chain.
15775 Set LO_POS to the position of the chosen low-part relocation.
15776 MATCHED_LO_P is true on entry to the loop if *POS is a low-part
15777 relocation that matches an immediately-preceding high-part
15781 matched_lo_p = FALSE;
15782 looking_for_rtype = matching_lo_reloc (l->fixp->fx_r_type);
15784 for (pos = &seginfo->fix_root; *pos != NULL; pos = &(*pos)->fx_next)
15786 if (*pos == l->fixp)
15789 if ((*pos)->fx_r_type == looking_for_rtype
15790 && symbol_same_p ((*pos)->fx_addsy, l->fixp->fx_addsy)
15791 && (*pos)->fx_offset >= l->fixp->fx_offset
15793 || (*pos)->fx_offset < (*lo_pos)->fx_offset
15795 && (*pos)->fx_offset == (*lo_pos)->fx_offset)))
15798 matched_lo_p = (reloc_needs_lo_p ((*pos)->fx_r_type)
15799 && fixup_has_matching_lo_p (*pos));
15802 /* If we found a match, remove the high-part relocation from its
15803 current position and insert it before the low-part relocation.
15804 Make the offsets match so that fixup_has_matching_lo_p()
15807 We don't warn about unmatched high-part relocations since some
15808 versions of gcc have been known to emit dead "lui ...%hi(...)"
15810 if (lo_pos != NULL)
15812 l->fixp->fx_offset = (*lo_pos)->fx_offset;
15813 if (l->fixp->fx_next != *lo_pos)
15815 *hi_pos = l->fixp->fx_next;
15816 l->fixp->fx_next = *lo_pos;
15824 mips_force_relocation (fixS *fixp)
15826 if (generic_force_reloc (fixp))
15829 /* We want to keep BFD_RELOC_MICROMIPS_*_PCREL_S1 relocation,
15830 so that the linker relaxation can update targets. */
15831 if (fixp->fx_r_type == BFD_RELOC_MICROMIPS_7_PCREL_S1
15832 || fixp->fx_r_type == BFD_RELOC_MICROMIPS_10_PCREL_S1
15833 || fixp->fx_r_type == BFD_RELOC_MICROMIPS_16_PCREL_S1)
15839 /* Read the instruction associated with RELOC from BUF. */
15841 static unsigned int
15842 read_reloc_insn (char *buf, bfd_reloc_code_real_type reloc)
15844 if (mips16_reloc_p (reloc) || micromips_reloc_p (reloc))
15845 return read_compressed_insn (buf, 4);
15847 return read_insn (buf);
15850 /* Write instruction INSN to BUF, given that it has been relocated
15854 write_reloc_insn (char *buf, bfd_reloc_code_real_type reloc,
15855 unsigned long insn)
15857 if (mips16_reloc_p (reloc) || micromips_reloc_p (reloc))
15858 write_compressed_insn (buf, insn, 4);
15860 write_insn (buf, insn);
15863 /* Apply a fixup to the object file. */
15866 md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
15869 unsigned long insn;
15870 reloc_howto_type *howto;
15872 /* We ignore generic BFD relocations we don't know about. */
15873 howto = bfd_reloc_type_lookup (stdoutput, fixP->fx_r_type);
15877 gas_assert (fixP->fx_size == 2
15878 || fixP->fx_size == 4
15879 || fixP->fx_r_type == BFD_RELOC_16
15880 || fixP->fx_r_type == BFD_RELOC_64
15881 || fixP->fx_r_type == BFD_RELOC_CTOR
15882 || fixP->fx_r_type == BFD_RELOC_MIPS_SUB
15883 || fixP->fx_r_type == BFD_RELOC_MICROMIPS_SUB
15884 || fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
15885 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY
15886 || fixP->fx_r_type == BFD_RELOC_MIPS_TLS_DTPREL64);
15888 buf = fixP->fx_frag->fr_literal + fixP->fx_where;
15890 gas_assert (!fixP->fx_pcrel || fixP->fx_r_type == BFD_RELOC_16_PCREL_S2
15891 || fixP->fx_r_type == BFD_RELOC_MICROMIPS_7_PCREL_S1
15892 || fixP->fx_r_type == BFD_RELOC_MICROMIPS_10_PCREL_S1
15893 || fixP->fx_r_type == BFD_RELOC_MICROMIPS_16_PCREL_S1
15894 || fixP->fx_r_type == BFD_RELOC_32_PCREL);
15896 /* Don't treat parts of a composite relocation as done. There are two
15899 (1) The second and third parts will be against 0 (RSS_UNDEF) but
15900 should nevertheless be emitted if the first part is.
15902 (2) In normal usage, composite relocations are never assembly-time
15903 constants. The easiest way of dealing with the pathological
15904 exceptions is to generate a relocation against STN_UNDEF and
15905 leave everything up to the linker. */
15906 if (fixP->fx_addsy == NULL && !fixP->fx_pcrel && fixP->fx_tcbit == 0)
15909 switch (fixP->fx_r_type)
15911 case BFD_RELOC_MIPS_TLS_GD:
15912 case BFD_RELOC_MIPS_TLS_LDM:
15913 case BFD_RELOC_MIPS_TLS_DTPREL32:
15914 case BFD_RELOC_MIPS_TLS_DTPREL64:
15915 case BFD_RELOC_MIPS_TLS_DTPREL_HI16:
15916 case BFD_RELOC_MIPS_TLS_DTPREL_LO16:
15917 case BFD_RELOC_MIPS_TLS_GOTTPREL:
15918 case BFD_RELOC_MIPS_TLS_TPREL32:
15919 case BFD_RELOC_MIPS_TLS_TPREL64:
15920 case BFD_RELOC_MIPS_TLS_TPREL_HI16:
15921 case BFD_RELOC_MIPS_TLS_TPREL_LO16:
15922 case BFD_RELOC_MICROMIPS_TLS_GD:
15923 case BFD_RELOC_MICROMIPS_TLS_LDM:
15924 case BFD_RELOC_MICROMIPS_TLS_DTPREL_HI16:
15925 case BFD_RELOC_MICROMIPS_TLS_DTPREL_LO16:
15926 case BFD_RELOC_MICROMIPS_TLS_GOTTPREL:
15927 case BFD_RELOC_MICROMIPS_TLS_TPREL_HI16:
15928 case BFD_RELOC_MICROMIPS_TLS_TPREL_LO16:
15929 case BFD_RELOC_MIPS16_TLS_GD:
15930 case BFD_RELOC_MIPS16_TLS_LDM:
15931 case BFD_RELOC_MIPS16_TLS_DTPREL_HI16:
15932 case BFD_RELOC_MIPS16_TLS_DTPREL_LO16:
15933 case BFD_RELOC_MIPS16_TLS_GOTTPREL:
15934 case BFD_RELOC_MIPS16_TLS_TPREL_HI16:
15935 case BFD_RELOC_MIPS16_TLS_TPREL_LO16:
15936 if (!fixP->fx_addsy)
15938 as_bad_where (fixP->fx_file, fixP->fx_line,
15939 _("TLS relocation against a constant"));
15942 S_SET_THREAD_LOCAL (fixP->fx_addsy);
15945 case BFD_RELOC_MIPS_JMP:
15946 case BFD_RELOC_MIPS_SHIFT5:
15947 case BFD_RELOC_MIPS_SHIFT6:
15948 case BFD_RELOC_MIPS_GOT_DISP:
15949 case BFD_RELOC_MIPS_GOT_PAGE:
15950 case BFD_RELOC_MIPS_GOT_OFST:
15951 case BFD_RELOC_MIPS_SUB:
15952 case BFD_RELOC_MIPS_INSERT_A:
15953 case BFD_RELOC_MIPS_INSERT_B:
15954 case BFD_RELOC_MIPS_DELETE:
15955 case BFD_RELOC_MIPS_HIGHEST:
15956 case BFD_RELOC_MIPS_HIGHER:
15957 case BFD_RELOC_MIPS_SCN_DISP:
15958 case BFD_RELOC_MIPS_REL16:
15959 case BFD_RELOC_MIPS_RELGOT:
15960 case BFD_RELOC_MIPS_JALR:
15961 case BFD_RELOC_HI16:
15962 case BFD_RELOC_HI16_S:
15963 case BFD_RELOC_LO16:
15964 case BFD_RELOC_GPREL16:
15965 case BFD_RELOC_MIPS_LITERAL:
15966 case BFD_RELOC_MIPS_CALL16:
15967 case BFD_RELOC_MIPS_GOT16:
15968 case BFD_RELOC_GPREL32:
15969 case BFD_RELOC_MIPS_GOT_HI16:
15970 case BFD_RELOC_MIPS_GOT_LO16:
15971 case BFD_RELOC_MIPS_CALL_HI16:
15972 case BFD_RELOC_MIPS_CALL_LO16:
15973 case BFD_RELOC_MIPS16_GPREL:
15974 case BFD_RELOC_MIPS16_GOT16:
15975 case BFD_RELOC_MIPS16_CALL16:
15976 case BFD_RELOC_MIPS16_HI16:
15977 case BFD_RELOC_MIPS16_HI16_S:
15978 case BFD_RELOC_MIPS16_LO16:
15979 case BFD_RELOC_MIPS16_JMP:
15980 case BFD_RELOC_MICROMIPS_JMP:
15981 case BFD_RELOC_MICROMIPS_GOT_DISP:
15982 case BFD_RELOC_MICROMIPS_GOT_PAGE:
15983 case BFD_RELOC_MICROMIPS_GOT_OFST:
15984 case BFD_RELOC_MICROMIPS_SUB:
15985 case BFD_RELOC_MICROMIPS_HIGHEST:
15986 case BFD_RELOC_MICROMIPS_HIGHER:
15987 case BFD_RELOC_MICROMIPS_SCN_DISP:
15988 case BFD_RELOC_MICROMIPS_JALR:
15989 case BFD_RELOC_MICROMIPS_HI16:
15990 case BFD_RELOC_MICROMIPS_HI16_S:
15991 case BFD_RELOC_MICROMIPS_LO16:
15992 case BFD_RELOC_MICROMIPS_GPREL16:
15993 case BFD_RELOC_MICROMIPS_LITERAL:
15994 case BFD_RELOC_MICROMIPS_CALL16:
15995 case BFD_RELOC_MICROMIPS_GOT16:
15996 case BFD_RELOC_MICROMIPS_GOT_HI16:
15997 case BFD_RELOC_MICROMIPS_GOT_LO16:
15998 case BFD_RELOC_MICROMIPS_CALL_HI16:
15999 case BFD_RELOC_MICROMIPS_CALL_LO16:
16000 case BFD_RELOC_MIPS_EH:
16005 if (calculate_reloc (fixP->fx_r_type, *valP, &value))
16007 insn = read_reloc_insn (buf, fixP->fx_r_type);
16008 if (mips16_reloc_p (fixP->fx_r_type))
16009 insn |= mips16_immed_extend (value, 16);
16011 insn |= (value & 0xffff);
16012 write_reloc_insn (buf, fixP->fx_r_type, insn);
16015 as_bad_where (fixP->fx_file, fixP->fx_line,
16016 _("Unsupported constant in relocation"));
16021 /* This is handled like BFD_RELOC_32, but we output a sign
16022 extended value if we are only 32 bits. */
16025 if (8 <= sizeof (valueT))
16026 md_number_to_chars (buf, *valP, 8);
16031 if ((*valP & 0x80000000) != 0)
16035 md_number_to_chars (buf + (target_big_endian ? 4 : 0), *valP, 4);
16036 md_number_to_chars (buf + (target_big_endian ? 0 : 4), hiv, 4);
16041 case BFD_RELOC_RVA:
16043 case BFD_RELOC_32_PCREL:
16045 /* If we are deleting this reloc entry, we must fill in the
16046 value now. This can happen if we have a .word which is not
16047 resolved when it appears but is later defined. */
16049 md_number_to_chars (buf, *valP, fixP->fx_size);
16052 case BFD_RELOC_16_PCREL_S2:
16053 if ((*valP & 0x3) != 0)
16054 as_bad_where (fixP->fx_file, fixP->fx_line,
16055 _("Branch to misaligned address (%lx)"), (long) *valP);
16057 /* We need to save the bits in the instruction since fixup_segment()
16058 might be deleting the relocation entry (i.e., a branch within
16059 the current segment). */
16060 if (! fixP->fx_done)
16063 /* Update old instruction data. */
16064 insn = read_insn (buf);
16066 if (*valP + 0x20000 <= 0x3ffff)
16068 insn |= (*valP >> 2) & 0xffff;
16069 write_insn (buf, insn);
16071 else if (mips_pic == NO_PIC
16073 && fixP->fx_frag->fr_address >= text_section->vma
16074 && (fixP->fx_frag->fr_address
16075 < text_section->vma + bfd_get_section_size (text_section))
16076 && ((insn & 0xffff0000) == 0x10000000 /* beq $0,$0 */
16077 || (insn & 0xffff0000) == 0x04010000 /* bgez $0 */
16078 || (insn & 0xffff0000) == 0x04110000)) /* bgezal $0 */
16080 /* The branch offset is too large. If this is an
16081 unconditional branch, and we are not generating PIC code,
16082 we can convert it to an absolute jump instruction. */
16083 if ((insn & 0xffff0000) == 0x04110000) /* bgezal $0 */
16084 insn = 0x0c000000; /* jal */
16086 insn = 0x08000000; /* j */
16087 fixP->fx_r_type = BFD_RELOC_MIPS_JMP;
16089 fixP->fx_addsy = section_symbol (text_section);
16090 *valP += md_pcrel_from (fixP);
16091 write_insn (buf, insn);
16095 /* If we got here, we have branch-relaxation disabled,
16096 and there's nothing we can do to fix this instruction
16097 without turning it into a longer sequence. */
16098 as_bad_where (fixP->fx_file, fixP->fx_line,
16099 _("Branch out of range"));
16103 case BFD_RELOC_MICROMIPS_7_PCREL_S1:
16104 case BFD_RELOC_MICROMIPS_10_PCREL_S1:
16105 case BFD_RELOC_MICROMIPS_16_PCREL_S1:
16106 /* We adjust the offset back to even. */
16107 if ((*valP & 0x1) != 0)
16110 if (! fixP->fx_done)
16113 /* Should never visit here, because we keep the relocation. */
16117 case BFD_RELOC_VTABLE_INHERIT:
16120 && !S_IS_DEFINED (fixP->fx_addsy)
16121 && !S_IS_WEAK (fixP->fx_addsy))
16122 S_SET_WEAK (fixP->fx_addsy);
16125 case BFD_RELOC_VTABLE_ENTRY:
16133 /* Remember value for tc_gen_reloc. */
16134 fixP->fx_addnumber = *valP;
16144 name = input_line_pointer;
16145 c = get_symbol_end ();
16146 p = (symbolS *) symbol_find_or_make (name);
16147 *input_line_pointer = c;
16151 /* Align the current frag to a given power of two. If a particular
16152 fill byte should be used, FILL points to an integer that contains
16153 that byte, otherwise FILL is null.
16155 This function used to have the comment:
16157 The MIPS assembler also automatically adjusts any preceding label.
16159 The implementation therefore applied the adjustment to a maximum of
16160 one label. However, other label adjustments are applied to batches
16161 of labels, and adjusting just one caused problems when new labels
16162 were added for the sake of debugging or unwind information.
16163 We therefore adjust all preceding labels (given as LABELS) instead. */
16166 mips_align (int to, int *fill, struct insn_label_list *labels)
16168 mips_emit_delays ();
16169 mips_record_compressed_mode ();
16170 if (fill == NULL && subseg_text_p (now_seg))
16171 frag_align_code (to, 0);
16173 frag_align (to, fill ? *fill : 0, 0);
16174 record_alignment (now_seg, to);
16175 mips_move_labels (labels, FALSE);
16178 /* Align to a given power of two. .align 0 turns off the automatic
16179 alignment used by the data creating pseudo-ops. */
16182 s_align (int x ATTRIBUTE_UNUSED)
16184 int temp, fill_value, *fill_ptr;
16185 long max_alignment = 28;
16187 /* o Note that the assembler pulls down any immediately preceding label
16188 to the aligned address.
16189 o It's not documented but auto alignment is reinstated by
16190 a .align pseudo instruction.
16191 o Note also that after auto alignment is turned off the mips assembler
16192 issues an error on attempt to assemble an improperly aligned data item.
16195 temp = get_absolute_expression ();
16196 if (temp > max_alignment)
16197 as_bad (_("Alignment too large: %d. assumed."), temp = max_alignment);
16200 as_warn (_("Alignment negative: 0 assumed."));
16203 if (*input_line_pointer == ',')
16205 ++input_line_pointer;
16206 fill_value = get_absolute_expression ();
16207 fill_ptr = &fill_value;
16213 segment_info_type *si = seg_info (now_seg);
16214 struct insn_label_list *l = si->label_list;
16215 /* Auto alignment should be switched on by next section change. */
16217 mips_align (temp, fill_ptr, l);
16224 demand_empty_rest_of_line ();
16228 s_change_sec (int sec)
16233 /* The ELF backend needs to know that we are changing sections, so
16234 that .previous works correctly. We could do something like check
16235 for an obj_section_change_hook macro, but that might be confusing
16236 as it would not be appropriate to use it in the section changing
16237 functions in read.c, since obj-elf.c intercepts those. FIXME:
16238 This should be cleaner, somehow. */
16240 obj_elf_section_change_hook ();
16243 mips_emit_delays ();
16254 subseg_set (bss_section, (subsegT) get_absolute_expression ());
16255 demand_empty_rest_of_line ();
16259 seg = subseg_new (RDATA_SECTION_NAME,
16260 (subsegT) get_absolute_expression ());
16263 bfd_set_section_flags (stdoutput, seg, (SEC_ALLOC | SEC_LOAD
16264 | SEC_READONLY | SEC_RELOC
16266 if (strncmp (TARGET_OS, "elf", 3) != 0)
16267 record_alignment (seg, 4);
16269 demand_empty_rest_of_line ();
16273 seg = subseg_new (".sdata", (subsegT) get_absolute_expression ());
16276 bfd_set_section_flags (stdoutput, seg,
16277 SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_DATA);
16278 if (strncmp (TARGET_OS, "elf", 3) != 0)
16279 record_alignment (seg, 4);
16281 demand_empty_rest_of_line ();
16285 seg = subseg_new (".sbss", (subsegT) get_absolute_expression ());
16288 bfd_set_section_flags (stdoutput, seg, SEC_ALLOC);
16289 if (strncmp (TARGET_OS, "elf", 3) != 0)
16290 record_alignment (seg, 4);
16292 demand_empty_rest_of_line ();
16300 s_change_section (int ignore ATTRIBUTE_UNUSED)
16303 char *section_name;
16308 int section_entry_size;
16309 int section_alignment;
16314 section_name = input_line_pointer;
16315 c = get_symbol_end ();
16317 next_c = *(input_line_pointer + 1);
16319 /* Do we have .section Name<,"flags">? */
16320 if (c != ',' || (c == ',' && next_c == '"'))
16322 /* just after name is now '\0'. */
16323 *input_line_pointer = c;
16324 input_line_pointer = section_name;
16325 obj_elf_section (ignore);
16328 input_line_pointer++;
16330 /* Do we have .section Name<,type><,flag><,entry_size><,alignment> */
16332 section_type = get_absolute_expression ();
16335 if (*input_line_pointer++ == ',')
16336 section_flag = get_absolute_expression ();
16339 if (*input_line_pointer++ == ',')
16340 section_entry_size = get_absolute_expression ();
16342 section_entry_size = 0;
16343 if (*input_line_pointer++ == ',')
16344 section_alignment = get_absolute_expression ();
16346 section_alignment = 0;
16347 /* FIXME: really ignore? */
16348 (void) section_alignment;
16350 section_name = xstrdup (section_name);
16352 /* When using the generic form of .section (as implemented by obj-elf.c),
16353 there's no way to set the section type to SHT_MIPS_DWARF. Users have
16354 traditionally had to fall back on the more common @progbits instead.
16356 There's nothing really harmful in this, since bfd will correct
16357 SHT_PROGBITS to SHT_MIPS_DWARF before writing out the file. But it
16358 means that, for backwards compatibility, the special_section entries
16359 for dwarf sections must use SHT_PROGBITS rather than SHT_MIPS_DWARF.
16361 Even so, we shouldn't force users of the MIPS .section syntax to
16362 incorrectly label the sections as SHT_PROGBITS. The best compromise
16363 seems to be to map SHT_MIPS_DWARF to SHT_PROGBITS before calling the
16364 generic type-checking code. */
16365 if (section_type == SHT_MIPS_DWARF)
16366 section_type = SHT_PROGBITS;
16368 obj_elf_change_section (section_name, section_type, section_flag,
16369 section_entry_size, 0, 0, 0);
16371 if (now_seg->name != section_name)
16372 free (section_name);
16373 #endif /* OBJ_ELF */
16377 mips_enable_auto_align (void)
16383 s_cons (int log_size)
16385 segment_info_type *si = seg_info (now_seg);
16386 struct insn_label_list *l = si->label_list;
16388 mips_emit_delays ();
16389 if (log_size > 0 && auto_align)
16390 mips_align (log_size, 0, l);
16391 cons (1 << log_size);
16392 mips_clear_insn_labels ();
16396 s_float_cons (int type)
16398 segment_info_type *si = seg_info (now_seg);
16399 struct insn_label_list *l = si->label_list;
16401 mips_emit_delays ();
16406 mips_align (3, 0, l);
16408 mips_align (2, 0, l);
16412 mips_clear_insn_labels ();
16415 /* Handle .globl. We need to override it because on Irix 5 you are
16418 where foo is an undefined symbol, to mean that foo should be
16419 considered to be the address of a function. */
16422 s_mips_globl (int x ATTRIBUTE_UNUSED)
16431 name = input_line_pointer;
16432 c = get_symbol_end ();
16433 symbolP = symbol_find_or_make (name);
16434 S_SET_EXTERNAL (symbolP);
16436 *input_line_pointer = c;
16437 SKIP_WHITESPACE ();
16439 /* On Irix 5, every global symbol that is not explicitly labelled as
16440 being a function is apparently labelled as being an object. */
16443 if (!is_end_of_line[(unsigned char) *input_line_pointer]
16444 && (*input_line_pointer != ','))
16449 secname = input_line_pointer;
16450 c = get_symbol_end ();
16451 sec = bfd_get_section_by_name (stdoutput, secname);
16453 as_bad (_("%s: no such section"), secname);
16454 *input_line_pointer = c;
16456 if (sec != NULL && (sec->flags & SEC_CODE) != 0)
16457 flag = BSF_FUNCTION;
16460 symbol_get_bfdsym (symbolP)->flags |= flag;
16462 c = *input_line_pointer;
16465 input_line_pointer++;
16466 SKIP_WHITESPACE ();
16467 if (is_end_of_line[(unsigned char) *input_line_pointer])
16473 demand_empty_rest_of_line ();
16477 s_option (int x ATTRIBUTE_UNUSED)
16482 opt = input_line_pointer;
16483 c = get_symbol_end ();
16487 /* FIXME: What does this mean? */
16489 else if (strncmp (opt, "pic", 3) == 0)
16493 i = atoi (opt + 3);
16498 mips_pic = SVR4_PIC;
16499 mips_abicalls = TRUE;
16502 as_bad (_(".option pic%d not supported"), i);
16504 if (mips_pic == SVR4_PIC)
16506 if (g_switch_seen && g_switch_value != 0)
16507 as_warn (_("-G may not be used with SVR4 PIC code"));
16508 g_switch_value = 0;
16509 bfd_set_gp_size (stdoutput, 0);
16513 as_warn (_("Unrecognized option \"%s\""), opt);
16515 *input_line_pointer = c;
16516 demand_empty_rest_of_line ();
16519 /* This structure is used to hold a stack of .set values. */
16521 struct mips_option_stack
16523 struct mips_option_stack *next;
16524 struct mips_set_options options;
16527 static struct mips_option_stack *mips_opts_stack;
16529 /* Handle the .set pseudo-op. */
16532 s_mipsset (int x ATTRIBUTE_UNUSED)
16534 char *name = input_line_pointer, ch;
16535 const struct mips_ase *ase;
16537 while (!is_end_of_line[(unsigned char) *input_line_pointer])
16538 ++input_line_pointer;
16539 ch = *input_line_pointer;
16540 *input_line_pointer = '\0';
16542 if (strcmp (name, "reorder") == 0)
16544 if (mips_opts.noreorder)
16547 else if (strcmp (name, "noreorder") == 0)
16549 if (!mips_opts.noreorder)
16550 start_noreorder ();
16552 else if (strncmp (name, "at=", 3) == 0)
16554 char *s = name + 3;
16556 if (!reg_lookup (&s, RTYPE_NUM | RTYPE_GP, &mips_opts.at))
16557 as_bad (_("Unrecognized register name `%s'"), s);
16559 else if (strcmp (name, "at") == 0)
16561 mips_opts.at = ATREG;
16563 else if (strcmp (name, "noat") == 0)
16565 mips_opts.at = ZERO;
16567 else if (strcmp (name, "macro") == 0)
16569 mips_opts.warn_about_macros = 0;
16571 else if (strcmp (name, "nomacro") == 0)
16573 if (mips_opts.noreorder == 0)
16574 as_bad (_("`noreorder' must be set before `nomacro'"));
16575 mips_opts.warn_about_macros = 1;
16577 else if (strcmp (name, "move") == 0 || strcmp (name, "novolatile") == 0)
16579 mips_opts.nomove = 0;
16581 else if (strcmp (name, "nomove") == 0 || strcmp (name, "volatile") == 0)
16583 mips_opts.nomove = 1;
16585 else if (strcmp (name, "bopt") == 0)
16587 mips_opts.nobopt = 0;
16589 else if (strcmp (name, "nobopt") == 0)
16591 mips_opts.nobopt = 1;
16593 else if (strcmp (name, "gp=default") == 0)
16594 mips_opts.gp32 = file_mips_gp32;
16595 else if (strcmp (name, "gp=32") == 0)
16596 mips_opts.gp32 = 1;
16597 else if (strcmp (name, "gp=64") == 0)
16599 if (!ISA_HAS_64BIT_REGS (mips_opts.isa))
16600 as_warn (_("%s isa does not support 64-bit registers"),
16601 mips_cpu_info_from_isa (mips_opts.isa)->name);
16602 mips_opts.gp32 = 0;
16604 else if (strcmp (name, "fp=default") == 0)
16605 mips_opts.fp32 = file_mips_fp32;
16606 else if (strcmp (name, "fp=32") == 0)
16607 mips_opts.fp32 = 1;
16608 else if (strcmp (name, "fp=64") == 0)
16610 if (!ISA_HAS_64BIT_FPRS (mips_opts.isa))
16611 as_warn (_("%s isa does not support 64-bit floating point registers"),
16612 mips_cpu_info_from_isa (mips_opts.isa)->name);
16613 mips_opts.fp32 = 0;
16615 else if (strcmp (name, "softfloat") == 0)
16616 mips_opts.soft_float = 1;
16617 else if (strcmp (name, "hardfloat") == 0)
16618 mips_opts.soft_float = 0;
16619 else if (strcmp (name, "singlefloat") == 0)
16620 mips_opts.single_float = 1;
16621 else if (strcmp (name, "doublefloat") == 0)
16622 mips_opts.single_float = 0;
16623 else if (strcmp (name, "mips16") == 0
16624 || strcmp (name, "MIPS-16") == 0)
16626 if (mips_opts.micromips == 1)
16627 as_fatal (_("`mips16' cannot be used with `micromips'"));
16628 mips_opts.mips16 = 1;
16630 else if (strcmp (name, "nomips16") == 0
16631 || strcmp (name, "noMIPS-16") == 0)
16632 mips_opts.mips16 = 0;
16633 else if (strcmp (name, "micromips") == 0)
16635 if (mips_opts.mips16 == 1)
16636 as_fatal (_("`micromips' cannot be used with `mips16'"));
16637 mips_opts.micromips = 1;
16639 else if (strcmp (name, "nomicromips") == 0)
16640 mips_opts.micromips = 0;
16641 else if (name[0] == 'n'
16643 && (ase = mips_lookup_ase (name + 2)))
16644 mips_set_ase (ase, FALSE);
16645 else if ((ase = mips_lookup_ase (name)))
16646 mips_set_ase (ase, TRUE);
16647 else if (strncmp (name, "mips", 4) == 0 || strncmp (name, "arch=", 5) == 0)
16651 /* Permit the user to change the ISA and architecture on the fly.
16652 Needless to say, misuse can cause serious problems. */
16653 if (strcmp (name, "mips0") == 0 || strcmp (name, "arch=default") == 0)
16656 mips_opts.isa = file_mips_isa;
16657 mips_opts.arch = file_mips_arch;
16659 else if (strncmp (name, "arch=", 5) == 0)
16661 const struct mips_cpu_info *p;
16663 p = mips_parse_cpu("internal use", name + 5);
16665 as_bad (_("unknown architecture %s"), name + 5);
16668 mips_opts.arch = p->cpu;
16669 mips_opts.isa = p->isa;
16672 else if (strncmp (name, "mips", 4) == 0)
16674 const struct mips_cpu_info *p;
16676 p = mips_parse_cpu("internal use", name);
16678 as_bad (_("unknown ISA level %s"), name + 4);
16681 mips_opts.arch = p->cpu;
16682 mips_opts.isa = p->isa;
16686 as_bad (_("unknown ISA or architecture %s"), name);
16688 switch (mips_opts.isa)
16696 mips_opts.gp32 = 1;
16697 mips_opts.fp32 = 1;
16704 mips_opts.gp32 = 0;
16705 if (mips_opts.arch == CPU_R5900)
16707 mips_opts.fp32 = 1;
16711 mips_opts.fp32 = 0;
16715 as_bad (_("unknown ISA level %s"), name + 4);
16720 mips_opts.gp32 = file_mips_gp32;
16721 mips_opts.fp32 = file_mips_fp32;
16724 else if (strcmp (name, "autoextend") == 0)
16725 mips_opts.noautoextend = 0;
16726 else if (strcmp (name, "noautoextend") == 0)
16727 mips_opts.noautoextend = 1;
16728 else if (strcmp (name, "push") == 0)
16730 struct mips_option_stack *s;
16732 s = (struct mips_option_stack *) xmalloc (sizeof *s);
16733 s->next = mips_opts_stack;
16734 s->options = mips_opts;
16735 mips_opts_stack = s;
16737 else if (strcmp (name, "pop") == 0)
16739 struct mips_option_stack *s;
16741 s = mips_opts_stack;
16743 as_bad (_(".set pop with no .set push"));
16746 /* If we're changing the reorder mode we need to handle
16747 delay slots correctly. */
16748 if (s->options.noreorder && ! mips_opts.noreorder)
16749 start_noreorder ();
16750 else if (! s->options.noreorder && mips_opts.noreorder)
16753 mips_opts = s->options;
16754 mips_opts_stack = s->next;
16758 else if (strcmp (name, "sym32") == 0)
16759 mips_opts.sym32 = TRUE;
16760 else if (strcmp (name, "nosym32") == 0)
16761 mips_opts.sym32 = FALSE;
16762 else if (strchr (name, ','))
16764 /* Generic ".set" directive; use the generic handler. */
16765 *input_line_pointer = ch;
16766 input_line_pointer = name;
16772 as_warn (_("Tried to set unrecognized symbol: %s\n"), name);
16774 mips_check_isa_supports_ases ();
16775 *input_line_pointer = ch;
16776 demand_empty_rest_of_line ();
16779 /* Handle the .abicalls pseudo-op. I believe this is equivalent to
16780 .option pic2. It means to generate SVR4 PIC calls. */
16783 s_abicalls (int ignore ATTRIBUTE_UNUSED)
16785 mips_pic = SVR4_PIC;
16786 mips_abicalls = TRUE;
16788 if (g_switch_seen && g_switch_value != 0)
16789 as_warn (_("-G may not be used with SVR4 PIC code"));
16790 g_switch_value = 0;
16792 bfd_set_gp_size (stdoutput, 0);
16793 demand_empty_rest_of_line ();
16796 /* Handle the .cpload pseudo-op. This is used when generating SVR4
16797 PIC code. It sets the $gp register for the function based on the
16798 function address, which is in the register named in the argument.
16799 This uses a relocation against _gp_disp, which is handled specially
16800 by the linker. The result is:
16801 lui $gp,%hi(_gp_disp)
16802 addiu $gp,$gp,%lo(_gp_disp)
16803 addu $gp,$gp,.cpload argument
16804 The .cpload argument is normally $25 == $t9.
16806 The -mno-shared option changes this to:
16807 lui $gp,%hi(__gnu_local_gp)
16808 addiu $gp,$gp,%lo(__gnu_local_gp)
16809 and the argument is ignored. This saves an instruction, but the
16810 resulting code is not position independent; it uses an absolute
16811 address for __gnu_local_gp. Thus code assembled with -mno-shared
16812 can go into an ordinary executable, but not into a shared library. */
16815 s_cpload (int ignore ATTRIBUTE_UNUSED)
16821 /* If we are not generating SVR4 PIC code, or if this is NewABI code,
16822 .cpload is ignored. */
16823 if (mips_pic != SVR4_PIC || HAVE_NEWABI)
16829 if (mips_opts.mips16)
16831 as_bad (_("%s not supported in MIPS16 mode"), ".cpload");
16832 ignore_rest_of_line ();
16836 /* .cpload should be in a .set noreorder section. */
16837 if (mips_opts.noreorder == 0)
16838 as_warn (_(".cpload not in noreorder section"));
16840 reg = tc_get_register (0);
16842 /* If we need to produce a 64-bit address, we are better off using
16843 the default instruction sequence. */
16844 in_shared = mips_in_shared || HAVE_64BIT_SYMBOLS;
16846 ex.X_op = O_symbol;
16847 ex.X_add_symbol = symbol_find_or_make (in_shared ? "_gp_disp" :
16849 ex.X_op_symbol = NULL;
16850 ex.X_add_number = 0;
16852 /* In ELF, this symbol is implicitly an STT_OBJECT symbol. */
16853 symbol_get_bfdsym (ex.X_add_symbol)->flags |= BSF_OBJECT;
16855 mips_mark_labels ();
16856 mips_assembling_insn = TRUE;
16859 macro_build_lui (&ex, mips_gp_register);
16860 macro_build (&ex, "addiu", "t,r,j", mips_gp_register,
16861 mips_gp_register, BFD_RELOC_LO16);
16863 macro_build (NULL, "addu", "d,v,t", mips_gp_register,
16864 mips_gp_register, reg);
16867 mips_assembling_insn = FALSE;
16868 demand_empty_rest_of_line ();
16871 /* Handle the .cpsetup pseudo-op defined for NewABI PIC code. The syntax is:
16872 .cpsetup $reg1, offset|$reg2, label
16874 If offset is given, this results in:
16875 sd $gp, offset($sp)
16876 lui $gp, %hi(%neg(%gp_rel(label)))
16877 addiu $gp, $gp, %lo(%neg(%gp_rel(label)))
16878 daddu $gp, $gp, $reg1
16880 If $reg2 is given, this results in:
16881 daddu $reg2, $gp, $0
16882 lui $gp, %hi(%neg(%gp_rel(label)))
16883 addiu $gp, $gp, %lo(%neg(%gp_rel(label)))
16884 daddu $gp, $gp, $reg1
16885 $reg1 is normally $25 == $t9.
16887 The -mno-shared option replaces the last three instructions with
16889 addiu $gp,$gp,%lo(_gp) */
16892 s_cpsetup (int ignore ATTRIBUTE_UNUSED)
16894 expressionS ex_off;
16895 expressionS ex_sym;
16898 /* If we are not generating SVR4 PIC code, .cpsetup is ignored.
16899 We also need NewABI support. */
16900 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
16906 if (mips_opts.mips16)
16908 as_bad (_("%s not supported in MIPS16 mode"), ".cpsetup");
16909 ignore_rest_of_line ();
16913 reg1 = tc_get_register (0);
16914 SKIP_WHITESPACE ();
16915 if (*input_line_pointer != ',')
16917 as_bad (_("missing argument separator ',' for .cpsetup"));
16921 ++input_line_pointer;
16922 SKIP_WHITESPACE ();
16923 if (*input_line_pointer == '$')
16925 mips_cpreturn_register = tc_get_register (0);
16926 mips_cpreturn_offset = -1;
16930 mips_cpreturn_offset = get_absolute_expression ();
16931 mips_cpreturn_register = -1;
16933 SKIP_WHITESPACE ();
16934 if (*input_line_pointer != ',')
16936 as_bad (_("missing argument separator ',' for .cpsetup"));
16940 ++input_line_pointer;
16941 SKIP_WHITESPACE ();
16942 expression (&ex_sym);
16944 mips_mark_labels ();
16945 mips_assembling_insn = TRUE;
16948 if (mips_cpreturn_register == -1)
16950 ex_off.X_op = O_constant;
16951 ex_off.X_add_symbol = NULL;
16952 ex_off.X_op_symbol = NULL;
16953 ex_off.X_add_number = mips_cpreturn_offset;
16955 macro_build (&ex_off, "sd", "t,o(b)", mips_gp_register,
16956 BFD_RELOC_LO16, SP);
16959 macro_build (NULL, "daddu", "d,v,t", mips_cpreturn_register,
16960 mips_gp_register, 0);
16962 if (mips_in_shared || HAVE_64BIT_SYMBOLS)
16964 macro_build (&ex_sym, "lui", LUI_FMT, mips_gp_register,
16965 -1, BFD_RELOC_GPREL16, BFD_RELOC_MIPS_SUB,
16968 macro_build (&ex_sym, "addiu", "t,r,j", mips_gp_register,
16969 mips_gp_register, -1, BFD_RELOC_GPREL16,
16970 BFD_RELOC_MIPS_SUB, BFD_RELOC_LO16);
16972 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", mips_gp_register,
16973 mips_gp_register, reg1);
16979 ex.X_op = O_symbol;
16980 ex.X_add_symbol = symbol_find_or_make ("__gnu_local_gp");
16981 ex.X_op_symbol = NULL;
16982 ex.X_add_number = 0;
16984 /* In ELF, this symbol is implicitly an STT_OBJECT symbol. */
16985 symbol_get_bfdsym (ex.X_add_symbol)->flags |= BSF_OBJECT;
16987 macro_build_lui (&ex, mips_gp_register);
16988 macro_build (&ex, "addiu", "t,r,j", mips_gp_register,
16989 mips_gp_register, BFD_RELOC_LO16);
16994 mips_assembling_insn = FALSE;
16995 demand_empty_rest_of_line ();
16999 s_cplocal (int ignore ATTRIBUTE_UNUSED)
17001 /* If we are not generating SVR4 PIC code, or if this is not NewABI code,
17002 .cplocal is ignored. */
17003 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
17009 if (mips_opts.mips16)
17011 as_bad (_("%s not supported in MIPS16 mode"), ".cplocal");
17012 ignore_rest_of_line ();
17016 mips_gp_register = tc_get_register (0);
17017 demand_empty_rest_of_line ();
17020 /* Handle the .cprestore pseudo-op. This stores $gp into a given
17021 offset from $sp. The offset is remembered, and after making a PIC
17022 call $gp is restored from that location. */
17025 s_cprestore (int ignore ATTRIBUTE_UNUSED)
17029 /* If we are not generating SVR4 PIC code, or if this is NewABI code,
17030 .cprestore is ignored. */
17031 if (mips_pic != SVR4_PIC || HAVE_NEWABI)
17037 if (mips_opts.mips16)
17039 as_bad (_("%s not supported in MIPS16 mode"), ".cprestore");
17040 ignore_rest_of_line ();
17044 mips_cprestore_offset = get_absolute_expression ();
17045 mips_cprestore_valid = 1;
17047 ex.X_op = O_constant;
17048 ex.X_add_symbol = NULL;
17049 ex.X_op_symbol = NULL;
17050 ex.X_add_number = mips_cprestore_offset;
17052 mips_mark_labels ();
17053 mips_assembling_insn = TRUE;
17056 macro_build_ldst_constoffset (&ex, ADDRESS_STORE_INSN, mips_gp_register,
17057 SP, HAVE_64BIT_ADDRESSES);
17060 mips_assembling_insn = FALSE;
17061 demand_empty_rest_of_line ();
17064 /* Handle the .cpreturn pseudo-op defined for NewABI PIC code. If an offset
17065 was given in the preceding .cpsetup, it results in:
17066 ld $gp, offset($sp)
17068 If a register $reg2 was given there, it results in:
17069 daddu $gp, $reg2, $0 */
17072 s_cpreturn (int ignore ATTRIBUTE_UNUSED)
17076 /* If we are not generating SVR4 PIC code, .cpreturn is ignored.
17077 We also need NewABI support. */
17078 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
17084 if (mips_opts.mips16)
17086 as_bad (_("%s not supported in MIPS16 mode"), ".cpreturn");
17087 ignore_rest_of_line ();
17091 mips_mark_labels ();
17092 mips_assembling_insn = TRUE;
17095 if (mips_cpreturn_register == -1)
17097 ex.X_op = O_constant;
17098 ex.X_add_symbol = NULL;
17099 ex.X_op_symbol = NULL;
17100 ex.X_add_number = mips_cpreturn_offset;
17102 macro_build (&ex, "ld", "t,o(b)", mips_gp_register, BFD_RELOC_LO16, SP);
17105 macro_build (NULL, "daddu", "d,v,t", mips_gp_register,
17106 mips_cpreturn_register, 0);
17109 mips_assembling_insn = FALSE;
17110 demand_empty_rest_of_line ();
17113 /* Handle a .dtprelword, .dtpreldword, .tprelword, or .tpreldword
17114 pseudo-op; DIRSTR says which. The pseudo-op generates a BYTES-size
17115 DTP- or TP-relative relocation of type RTYPE, for use in either DWARF
17116 debug information or MIPS16 TLS. */
17119 s_tls_rel_directive (const size_t bytes, const char *dirstr,
17120 bfd_reloc_code_real_type rtype)
17127 if (ex.X_op != O_symbol)
17129 as_bad (_("Unsupported use of %s"), dirstr);
17130 ignore_rest_of_line ();
17133 p = frag_more (bytes);
17134 md_number_to_chars (p, 0, bytes);
17135 fix_new_exp (frag_now, p - frag_now->fr_literal, bytes, &ex, FALSE, rtype);
17136 demand_empty_rest_of_line ();
17137 mips_clear_insn_labels ();
17140 /* Handle .dtprelword. */
17143 s_dtprelword (int ignore ATTRIBUTE_UNUSED)
17145 s_tls_rel_directive (4, ".dtprelword", BFD_RELOC_MIPS_TLS_DTPREL32);
17148 /* Handle .dtpreldword. */
17151 s_dtpreldword (int ignore ATTRIBUTE_UNUSED)
17153 s_tls_rel_directive (8, ".dtpreldword", BFD_RELOC_MIPS_TLS_DTPREL64);
17156 /* Handle .tprelword. */
17159 s_tprelword (int ignore ATTRIBUTE_UNUSED)
17161 s_tls_rel_directive (4, ".tprelword", BFD_RELOC_MIPS_TLS_TPREL32);
17164 /* Handle .tpreldword. */
17167 s_tpreldword (int ignore ATTRIBUTE_UNUSED)
17169 s_tls_rel_directive (8, ".tpreldword", BFD_RELOC_MIPS_TLS_TPREL64);
17172 /* Handle the .gpvalue pseudo-op. This is used when generating NewABI PIC
17173 code. It sets the offset to use in gp_rel relocations. */
17176 s_gpvalue (int ignore ATTRIBUTE_UNUSED)
17178 /* If we are not generating SVR4 PIC code, .gpvalue is ignored.
17179 We also need NewABI support. */
17180 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
17186 mips_gprel_offset = get_absolute_expression ();
17188 demand_empty_rest_of_line ();
17191 /* Handle the .gpword pseudo-op. This is used when generating PIC
17192 code. It generates a 32 bit GP relative reloc. */
17195 s_gpword (int ignore ATTRIBUTE_UNUSED)
17197 segment_info_type *si;
17198 struct insn_label_list *l;
17202 /* When not generating PIC code, this is treated as .word. */
17203 if (mips_pic != SVR4_PIC)
17209 si = seg_info (now_seg);
17210 l = si->label_list;
17211 mips_emit_delays ();
17213 mips_align (2, 0, l);
17216 mips_clear_insn_labels ();
17218 if (ex.X_op != O_symbol || ex.X_add_number != 0)
17220 as_bad (_("Unsupported use of .gpword"));
17221 ignore_rest_of_line ();
17225 md_number_to_chars (p, 0, 4);
17226 fix_new_exp (frag_now, p - frag_now->fr_literal, 4, &ex, FALSE,
17227 BFD_RELOC_GPREL32);
17229 demand_empty_rest_of_line ();
17233 s_gpdword (int ignore ATTRIBUTE_UNUSED)
17235 segment_info_type *si;
17236 struct insn_label_list *l;
17240 /* When not generating PIC code, this is treated as .dword. */
17241 if (mips_pic != SVR4_PIC)
17247 si = seg_info (now_seg);
17248 l = si->label_list;
17249 mips_emit_delays ();
17251 mips_align (3, 0, l);
17254 mips_clear_insn_labels ();
17256 if (ex.X_op != O_symbol || ex.X_add_number != 0)
17258 as_bad (_("Unsupported use of .gpdword"));
17259 ignore_rest_of_line ();
17263 md_number_to_chars (p, 0, 8);
17264 fix_new_exp (frag_now, p - frag_now->fr_literal, 4, &ex, FALSE,
17265 BFD_RELOC_GPREL32)->fx_tcbit = 1;
17267 /* GPREL32 composed with 64 gives a 64-bit GP offset. */
17268 fix_new (frag_now, p - frag_now->fr_literal, 8, NULL, 0,
17269 FALSE, BFD_RELOC_64)->fx_tcbit = 1;
17271 demand_empty_rest_of_line ();
17274 /* Handle the .ehword pseudo-op. This is used when generating unwinding
17275 tables. It generates a R_MIPS_EH reloc. */
17278 s_ehword (int ignore ATTRIBUTE_UNUSED)
17283 mips_emit_delays ();
17286 mips_clear_insn_labels ();
17288 if (ex.X_op != O_symbol || ex.X_add_number != 0)
17290 as_bad (_("Unsupported use of .ehword"));
17291 ignore_rest_of_line ();
17295 md_number_to_chars (p, 0, 4);
17296 fix_new_exp (frag_now, p - frag_now->fr_literal, 4, &ex, FALSE,
17297 BFD_RELOC_MIPS_EH);
17299 demand_empty_rest_of_line ();
17302 /* Handle the .cpadd pseudo-op. This is used when dealing with switch
17303 tables in SVR4 PIC code. */
17306 s_cpadd (int ignore ATTRIBUTE_UNUSED)
17310 /* This is ignored when not generating SVR4 PIC code. */
17311 if (mips_pic != SVR4_PIC)
17317 mips_mark_labels ();
17318 mips_assembling_insn = TRUE;
17320 /* Add $gp to the register named as an argument. */
17322 reg = tc_get_register (0);
17323 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", reg, reg, mips_gp_register);
17326 mips_assembling_insn = FALSE;
17327 demand_empty_rest_of_line ();
17330 /* Handle the .insn pseudo-op. This marks instruction labels in
17331 mips16/micromips mode. This permits the linker to handle them specially,
17332 such as generating jalx instructions when needed. We also make
17333 them odd for the duration of the assembly, in order to generate the
17334 right sort of code. We will make them even in the adjust_symtab
17335 routine, while leaving them marked. This is convenient for the
17336 debugger and the disassembler. The linker knows to make them odd
17340 s_insn (int ignore ATTRIBUTE_UNUSED)
17342 mips_mark_labels ();
17344 demand_empty_rest_of_line ();
17347 /* Handle a .stab[snd] directive. Ideally these directives would be
17348 implemented in a transparent way, so that removing them would not
17349 have any effect on the generated instructions. However, s_stab
17350 internally changes the section, so in practice we need to decide
17351 now whether the preceding label marks compressed code. We do not
17352 support changing the compression mode of a label after a .stab*
17353 directive, such as in:
17359 so the current mode wins. */
17362 s_mips_stab (int type)
17364 mips_mark_labels ();
17368 /* Handle the .weakext pseudo-op as defined in Kane and Heinrich. */
17371 s_mips_weakext (int ignore ATTRIBUTE_UNUSED)
17378 name = input_line_pointer;
17379 c = get_symbol_end ();
17380 symbolP = symbol_find_or_make (name);
17381 S_SET_WEAK (symbolP);
17382 *input_line_pointer = c;
17384 SKIP_WHITESPACE ();
17386 if (! is_end_of_line[(unsigned char) *input_line_pointer])
17388 if (S_IS_DEFINED (symbolP))
17390 as_bad (_("ignoring attempt to redefine symbol %s"),
17391 S_GET_NAME (symbolP));
17392 ignore_rest_of_line ();
17396 if (*input_line_pointer == ',')
17398 ++input_line_pointer;
17399 SKIP_WHITESPACE ();
17403 if (exp.X_op != O_symbol)
17405 as_bad (_("bad .weakext directive"));
17406 ignore_rest_of_line ();
17409 symbol_set_value_expression (symbolP, &exp);
17412 demand_empty_rest_of_line ();
17415 /* Parse a register string into a number. Called from the ECOFF code
17416 to parse .frame. The argument is non-zero if this is the frame
17417 register, so that we can record it in mips_frame_reg. */
17420 tc_get_register (int frame)
17424 SKIP_WHITESPACE ();
17425 if (! reg_lookup (&input_line_pointer, RWARN | RTYPE_NUM | RTYPE_GP, ®))
17429 mips_frame_reg = reg != 0 ? reg : SP;
17430 mips_frame_reg_valid = 1;
17431 mips_cprestore_valid = 0;
17437 md_section_align (asection *seg, valueT addr)
17439 int align = bfd_get_section_alignment (stdoutput, seg);
17443 /* We don't need to align ELF sections to the full alignment.
17444 However, Irix 5 may prefer that we align them at least to a 16
17445 byte boundary. We don't bother to align the sections if we
17446 are targeted for an embedded system. */
17447 if (strncmp (TARGET_OS, "elf", 3) == 0)
17453 return ((addr + (1 << align) - 1) & (-1 << align));
17456 /* Utility routine, called from above as well. If called while the
17457 input file is still being read, it's only an approximation. (For
17458 example, a symbol may later become defined which appeared to be
17459 undefined earlier.) */
17462 nopic_need_relax (symbolS *sym, int before_relaxing)
17467 if (g_switch_value > 0)
17469 const char *symname;
17472 /* Find out whether this symbol can be referenced off the $gp
17473 register. It can be if it is smaller than the -G size or if
17474 it is in the .sdata or .sbss section. Certain symbols can
17475 not be referenced off the $gp, although it appears as though
17477 symname = S_GET_NAME (sym);
17478 if (symname != (const char *) NULL
17479 && (strcmp (symname, "eprol") == 0
17480 || strcmp (symname, "etext") == 0
17481 || strcmp (symname, "_gp") == 0
17482 || strcmp (symname, "edata") == 0
17483 || strcmp (symname, "_fbss") == 0
17484 || strcmp (symname, "_fdata") == 0
17485 || strcmp (symname, "_ftext") == 0
17486 || strcmp (symname, "end") == 0
17487 || strcmp (symname, "_gp_disp") == 0))
17489 else if ((! S_IS_DEFINED (sym) || S_IS_COMMON (sym))
17491 #ifndef NO_ECOFF_DEBUGGING
17492 || (symbol_get_obj (sym)->ecoff_extern_size != 0
17493 && (symbol_get_obj (sym)->ecoff_extern_size
17494 <= g_switch_value))
17496 /* We must defer this decision until after the whole
17497 file has been read, since there might be a .extern
17498 after the first use of this symbol. */
17499 || (before_relaxing
17500 #ifndef NO_ECOFF_DEBUGGING
17501 && symbol_get_obj (sym)->ecoff_extern_size == 0
17503 && S_GET_VALUE (sym) == 0)
17504 || (S_GET_VALUE (sym) != 0
17505 && S_GET_VALUE (sym) <= g_switch_value)))
17509 const char *segname;
17511 segname = segment_name (S_GET_SEGMENT (sym));
17512 gas_assert (strcmp (segname, ".lit8") != 0
17513 && strcmp (segname, ".lit4") != 0);
17514 change = (strcmp (segname, ".sdata") != 0
17515 && strcmp (segname, ".sbss") != 0
17516 && strncmp (segname, ".sdata.", 7) != 0
17517 && strncmp (segname, ".sbss.", 6) != 0
17518 && strncmp (segname, ".gnu.linkonce.sb.", 17) != 0
17519 && strncmp (segname, ".gnu.linkonce.s.", 16) != 0);
17524 /* We are not optimizing for the $gp register. */
17529 /* Return true if the given symbol should be considered local for SVR4 PIC. */
17532 pic_need_relax (symbolS *sym, asection *segtype)
17536 /* Handle the case of a symbol equated to another symbol. */
17537 while (symbol_equated_reloc_p (sym))
17541 /* It's possible to get a loop here in a badly written program. */
17542 n = symbol_get_value_expression (sym)->X_add_symbol;
17548 if (symbol_section_p (sym))
17551 symsec = S_GET_SEGMENT (sym);
17553 /* This must duplicate the test in adjust_reloc_syms. */
17554 return (!bfd_is_und_section (symsec)
17555 && !bfd_is_abs_section (symsec)
17556 && !bfd_is_com_section (symsec)
17557 && !s_is_linkonce (sym, segtype)
17559 /* A global or weak symbol is treated as external. */
17560 && (!IS_ELF || (! S_IS_WEAK (sym) && ! S_IS_EXTERNAL (sym)))
17566 /* Given a mips16 variant frag FRAGP, return non-zero if it needs an
17567 extended opcode. SEC is the section the frag is in. */
17570 mips16_extended_frag (fragS *fragp, asection *sec, long stretch)
17573 const struct mips16_immed_operand *op;
17575 int mintiny, maxtiny;
17579 if (RELAX_MIPS16_USER_SMALL (fragp->fr_subtype))
17581 if (RELAX_MIPS16_USER_EXT (fragp->fr_subtype))
17584 type = RELAX_MIPS16_TYPE (fragp->fr_subtype);
17585 op = mips16_immed_operands;
17586 while (op->type != type)
17589 gas_assert (op < mips16_immed_operands + MIPS16_NUM_IMMED);
17594 if (type == '<' || type == '>' || type == '[' || type == ']')
17597 maxtiny = 1 << op->nbits;
17602 maxtiny = (1 << op->nbits) - 1;
17607 mintiny = - (1 << (op->nbits - 1));
17608 maxtiny = (1 << (op->nbits - 1)) - 1;
17611 sym_frag = symbol_get_frag (fragp->fr_symbol);
17612 val = S_GET_VALUE (fragp->fr_symbol);
17613 symsec = S_GET_SEGMENT (fragp->fr_symbol);
17619 /* We won't have the section when we are called from
17620 mips_relax_frag. However, we will always have been called
17621 from md_estimate_size_before_relax first. If this is a
17622 branch to a different section, we mark it as such. If SEC is
17623 NULL, and the frag is not marked, then it must be a branch to
17624 the same section. */
17627 if (RELAX_MIPS16_LONG_BRANCH (fragp->fr_subtype))
17632 /* Must have been called from md_estimate_size_before_relax. */
17635 fragp->fr_subtype =
17636 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
17638 /* FIXME: We should support this, and let the linker
17639 catch branches and loads that are out of range. */
17640 as_bad_where (fragp->fr_file, fragp->fr_line,
17641 _("unsupported PC relative reference to different section"));
17645 if (fragp != sym_frag && sym_frag->fr_address == 0)
17646 /* Assume non-extended on the first relaxation pass.
17647 The address we have calculated will be bogus if this is
17648 a forward branch to another frag, as the forward frag
17649 will have fr_address == 0. */
17653 /* In this case, we know for sure that the symbol fragment is in
17654 the same section. If the relax_marker of the symbol fragment
17655 differs from the relax_marker of this fragment, we have not
17656 yet adjusted the symbol fragment fr_address. We want to add
17657 in STRETCH in order to get a better estimate of the address.
17658 This particularly matters because of the shift bits. */
17660 && sym_frag->relax_marker != fragp->relax_marker)
17664 /* Adjust stretch for any alignment frag. Note that if have
17665 been expanding the earlier code, the symbol may be
17666 defined in what appears to be an earlier frag. FIXME:
17667 This doesn't handle the fr_subtype field, which specifies
17668 a maximum number of bytes to skip when doing an
17670 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
17672 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
17675 stretch = - ((- stretch)
17676 & ~ ((1 << (int) f->fr_offset) - 1));
17678 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
17687 addr = fragp->fr_address + fragp->fr_fix;
17689 /* The base address rules are complicated. The base address of
17690 a branch is the following instruction. The base address of a
17691 PC relative load or add is the instruction itself, but if it
17692 is in a delay slot (in which case it can not be extended) use
17693 the address of the instruction whose delay slot it is in. */
17694 if (type == 'p' || type == 'q')
17698 /* If we are currently assuming that this frag should be
17699 extended, then, the current address is two bytes
17701 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
17704 /* Ignore the low bit in the target, since it will be set
17705 for a text label. */
17706 if ((val & 1) != 0)
17709 else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype))
17711 else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype))
17714 val -= addr & ~ ((1 << op->shift) - 1);
17716 /* Branch offsets have an implicit 0 in the lowest bit. */
17717 if (type == 'p' || type == 'q')
17720 /* If any of the shifted bits are set, we must use an extended
17721 opcode. If the address depends on the size of this
17722 instruction, this can lead to a loop, so we arrange to always
17723 use an extended opcode. We only check this when we are in
17724 the main relaxation loop, when SEC is NULL. */
17725 if ((val & ((1 << op->shift) - 1)) != 0 && sec == NULL)
17727 fragp->fr_subtype =
17728 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
17732 /* If we are about to mark a frag as extended because the value
17733 is precisely maxtiny + 1, then there is a chance of an
17734 infinite loop as in the following code:
17739 In this case when the la is extended, foo is 0x3fc bytes
17740 away, so the la can be shrunk, but then foo is 0x400 away, so
17741 the la must be extended. To avoid this loop, we mark the
17742 frag as extended if it was small, and is about to become
17743 extended with a value of maxtiny + 1. */
17744 if (val == ((maxtiny + 1) << op->shift)
17745 && ! RELAX_MIPS16_EXTENDED (fragp->fr_subtype)
17748 fragp->fr_subtype =
17749 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
17753 else if (symsec != absolute_section && sec != NULL)
17754 as_bad_where (fragp->fr_file, fragp->fr_line, _("unsupported relocation"));
17756 if ((val & ((1 << op->shift) - 1)) != 0
17757 || val < (mintiny << op->shift)
17758 || val > (maxtiny << op->shift))
17764 /* Compute the length of a branch sequence, and adjust the
17765 RELAX_BRANCH_TOOFAR bit accordingly. If FRAGP is NULL, the
17766 worst-case length is computed, with UPDATE being used to indicate
17767 whether an unconditional (-1), branch-likely (+1) or regular (0)
17768 branch is to be computed. */
17770 relaxed_branch_length (fragS *fragp, asection *sec, int update)
17772 bfd_boolean toofar;
17776 && S_IS_DEFINED (fragp->fr_symbol)
17777 && sec == S_GET_SEGMENT (fragp->fr_symbol))
17782 val = S_GET_VALUE (fragp->fr_symbol) + fragp->fr_offset;
17784 addr = fragp->fr_address + fragp->fr_fix + 4;
17788 toofar = val < - (0x8000 << 2) || val >= (0x8000 << 2);
17791 /* If the symbol is not defined or it's in a different segment,
17792 assume the user knows what's going on and emit a short
17798 if (fragp && update && toofar != RELAX_BRANCH_TOOFAR (fragp->fr_subtype))
17800 = RELAX_BRANCH_ENCODE (RELAX_BRANCH_AT (fragp->fr_subtype),
17801 RELAX_BRANCH_UNCOND (fragp->fr_subtype),
17802 RELAX_BRANCH_LIKELY (fragp->fr_subtype),
17803 RELAX_BRANCH_LINK (fragp->fr_subtype),
17809 if (fragp ? RELAX_BRANCH_LIKELY (fragp->fr_subtype) : (update > 0))
17812 if (mips_pic != NO_PIC)
17814 /* Additional space for PIC loading of target address. */
17816 if (mips_opts.isa == ISA_MIPS1)
17817 /* Additional space for $at-stabilizing nop. */
17821 /* If branch is conditional. */
17822 if (fragp ? !RELAX_BRANCH_UNCOND (fragp->fr_subtype) : (update >= 0))
17829 /* Compute the length of a branch sequence, and adjust the
17830 RELAX_MICROMIPS_TOOFAR32 bit accordingly. If FRAGP is NULL, the
17831 worst-case length is computed, with UPDATE being used to indicate
17832 whether an unconditional (-1), or regular (0) branch is to be
17836 relaxed_micromips_32bit_branch_length (fragS *fragp, asection *sec, int update)
17838 bfd_boolean toofar;
17842 && S_IS_DEFINED (fragp->fr_symbol)
17843 && sec == S_GET_SEGMENT (fragp->fr_symbol))
17848 val = S_GET_VALUE (fragp->fr_symbol) + fragp->fr_offset;
17849 /* Ignore the low bit in the target, since it will be set
17850 for a text label. */
17851 if ((val & 1) != 0)
17854 addr = fragp->fr_address + fragp->fr_fix + 4;
17858 toofar = val < - (0x8000 << 1) || val >= (0x8000 << 1);
17861 /* If the symbol is not defined or it's in a different segment,
17862 assume the user knows what's going on and emit a short
17868 if (fragp && update
17869 && toofar != RELAX_MICROMIPS_TOOFAR32 (fragp->fr_subtype))
17870 fragp->fr_subtype = (toofar
17871 ? RELAX_MICROMIPS_MARK_TOOFAR32 (fragp->fr_subtype)
17872 : RELAX_MICROMIPS_CLEAR_TOOFAR32 (fragp->fr_subtype));
17877 bfd_boolean compact_known = fragp != NULL;
17878 bfd_boolean compact = FALSE;
17879 bfd_boolean uncond;
17882 compact = RELAX_MICROMIPS_COMPACT (fragp->fr_subtype);
17884 uncond = RELAX_MICROMIPS_UNCOND (fragp->fr_subtype);
17886 uncond = update < 0;
17888 /* If label is out of range, we turn branch <br>:
17890 <br> label # 4 bytes
17896 nop # 2 bytes if compact && !PIC
17899 if (mips_pic == NO_PIC && (!compact_known || compact))
17902 /* If assembling PIC code, we further turn:
17908 lw/ld at, %got(label)(gp) # 4 bytes
17909 d/addiu at, %lo(label) # 4 bytes
17912 if (mips_pic != NO_PIC)
17915 /* If branch <br> is conditional, we prepend negated branch <brneg>:
17917 <brneg> 0f # 4 bytes
17918 nop # 2 bytes if !compact
17921 length += (compact_known && compact) ? 4 : 6;
17927 /* Compute the length of a branch, and adjust the RELAX_MICROMIPS_TOOFAR16
17928 bit accordingly. */
17931 relaxed_micromips_16bit_branch_length (fragS *fragp, asection *sec, int update)
17933 bfd_boolean toofar;
17936 && S_IS_DEFINED (fragp->fr_symbol)
17937 && sec == S_GET_SEGMENT (fragp->fr_symbol))
17943 val = S_GET_VALUE (fragp->fr_symbol) + fragp->fr_offset;
17944 /* Ignore the low bit in the target, since it will be set
17945 for a text label. */
17946 if ((val & 1) != 0)
17949 /* Assume this is a 2-byte branch. */
17950 addr = fragp->fr_address + fragp->fr_fix + 2;
17952 /* We try to avoid the infinite loop by not adding 2 more bytes for
17957 type = RELAX_MICROMIPS_TYPE (fragp->fr_subtype);
17959 toofar = val < - (0x200 << 1) || val >= (0x200 << 1);
17960 else if (type == 'E')
17961 toofar = val < - (0x40 << 1) || val >= (0x40 << 1);
17966 /* If the symbol is not defined or it's in a different segment,
17967 we emit a normal 32-bit branch. */
17970 if (fragp && update
17971 && toofar != RELAX_MICROMIPS_TOOFAR16 (fragp->fr_subtype))
17973 = toofar ? RELAX_MICROMIPS_MARK_TOOFAR16 (fragp->fr_subtype)
17974 : RELAX_MICROMIPS_CLEAR_TOOFAR16 (fragp->fr_subtype);
17982 /* Estimate the size of a frag before relaxing. Unless this is the
17983 mips16, we are not really relaxing here, and the final size is
17984 encoded in the subtype information. For the mips16, we have to
17985 decide whether we are using an extended opcode or not. */
17988 md_estimate_size_before_relax (fragS *fragp, asection *segtype)
17992 if (RELAX_BRANCH_P (fragp->fr_subtype))
17995 fragp->fr_var = relaxed_branch_length (fragp, segtype, FALSE);
17997 return fragp->fr_var;
18000 if (RELAX_MIPS16_P (fragp->fr_subtype))
18001 /* We don't want to modify the EXTENDED bit here; it might get us
18002 into infinite loops. We change it only in mips_relax_frag(). */
18003 return (RELAX_MIPS16_EXTENDED (fragp->fr_subtype) ? 4 : 2);
18005 if (RELAX_MICROMIPS_P (fragp->fr_subtype))
18009 if (RELAX_MICROMIPS_TYPE (fragp->fr_subtype) != 0)
18010 length = relaxed_micromips_16bit_branch_length (fragp, segtype, FALSE);
18011 if (length == 4 && RELAX_MICROMIPS_RELAX32 (fragp->fr_subtype))
18012 length = relaxed_micromips_32bit_branch_length (fragp, segtype, FALSE);
18013 fragp->fr_var = length;
18018 if (mips_pic == NO_PIC)
18019 change = nopic_need_relax (fragp->fr_symbol, 0);
18020 else if (mips_pic == SVR4_PIC)
18021 change = pic_need_relax (fragp->fr_symbol, segtype);
18022 else if (mips_pic == VXWORKS_PIC)
18023 /* For vxworks, GOT16 relocations never have a corresponding LO16. */
18030 fragp->fr_subtype |= RELAX_USE_SECOND;
18031 return -RELAX_FIRST (fragp->fr_subtype);
18034 return -RELAX_SECOND (fragp->fr_subtype);
18037 /* This is called to see whether a reloc against a defined symbol
18038 should be converted into a reloc against a section. */
18041 mips_fix_adjustable (fixS *fixp)
18043 if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT
18044 || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
18047 if (fixp->fx_addsy == NULL)
18050 /* If symbol SYM is in a mergeable section, relocations of the form
18051 SYM + 0 can usually be made section-relative. The mergeable data
18052 is then identified by the section offset rather than by the symbol.
18054 However, if we're generating REL LO16 relocations, the offset is split
18055 between the LO16 and parterning high part relocation. The linker will
18056 need to recalculate the complete offset in order to correctly identify
18059 The linker has traditionally not looked for the parterning high part
18060 relocation, and has thus allowed orphaned R_MIPS_LO16 relocations to be
18061 placed anywhere. Rather than break backwards compatibility by changing
18062 this, it seems better not to force the issue, and instead keep the
18063 original symbol. This will work with either linker behavior. */
18064 if ((lo16_reloc_p (fixp->fx_r_type)
18065 || reloc_needs_lo_p (fixp->fx_r_type))
18066 && HAVE_IN_PLACE_ADDENDS
18067 && (S_GET_SEGMENT (fixp->fx_addsy)->flags & SEC_MERGE) != 0)
18070 /* There is no place to store an in-place offset for JALR relocations.
18071 Likewise an in-range offset of limited PC-relative relocations may
18072 overflow the in-place relocatable field if recalculated against the
18073 start address of the symbol's containing section. */
18074 if (HAVE_IN_PLACE_ADDENDS
18075 && (limited_pcrel_reloc_p (fixp->fx_r_type)
18076 || jalr_reloc_p (fixp->fx_r_type)))
18080 /* R_MIPS16_26 relocations against non-MIPS16 functions might resolve
18081 to a floating-point stub. The same is true for non-R_MIPS16_26
18082 relocations against MIPS16 functions; in this case, the stub becomes
18083 the function's canonical address.
18085 Floating-point stubs are stored in unique .mips16.call.* or
18086 .mips16.fn.* sections. If a stub T for function F is in section S,
18087 the first relocation in section S must be against F; this is how the
18088 linker determines the target function. All relocations that might
18089 resolve to T must also be against F. We therefore have the following
18090 restrictions, which are given in an intentionally-redundant way:
18092 1. We cannot reduce R_MIPS16_26 relocations against non-MIPS16
18095 2. We cannot reduce a stub's relocations against non-MIPS16 symbols
18096 if that stub might be used.
18098 3. We cannot reduce non-R_MIPS16_26 relocations against MIPS16
18101 4. We cannot reduce a stub's relocations against MIPS16 symbols if
18102 that stub might be used.
18104 There is a further restriction:
18106 5. We cannot reduce jump relocations (R_MIPS_26, R_MIPS16_26 or
18107 R_MICROMIPS_26_S1) against MIPS16 or microMIPS symbols on
18108 targets with in-place addends; the relocation field cannot
18109 encode the low bit.
18111 For simplicity, we deal with (3)-(4) by not reducing _any_ relocation
18112 against a MIPS16 symbol. We deal with (5) by by not reducing any
18113 such relocations on REL targets.
18115 We deal with (1)-(2) by saying that, if there's a R_MIPS16_26
18116 relocation against some symbol R, no relocation against R may be
18117 reduced. (Note that this deals with (2) as well as (1) because
18118 relocations against global symbols will never be reduced on ELF
18119 targets.) This approach is a little simpler than trying to detect
18120 stub sections, and gives the "all or nothing" per-symbol consistency
18121 that we have for MIPS16 symbols. */
18123 && fixp->fx_subsy == NULL
18124 && (ELF_ST_IS_MIPS16 (S_GET_OTHER (fixp->fx_addsy))
18125 || *symbol_get_tc (fixp->fx_addsy)
18126 || (HAVE_IN_PLACE_ADDENDS
18127 && ELF_ST_IS_MICROMIPS (S_GET_OTHER (fixp->fx_addsy))
18128 && jmp_reloc_p (fixp->fx_r_type))))
18135 /* Translate internal representation of relocation info to BFD target
18139 tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixp)
18141 static arelent *retval[4];
18143 bfd_reloc_code_real_type code;
18145 memset (retval, 0, sizeof(retval));
18146 reloc = retval[0] = (arelent *) xcalloc (1, sizeof (arelent));
18147 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
18148 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
18149 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
18151 if (fixp->fx_pcrel)
18153 gas_assert (fixp->fx_r_type == BFD_RELOC_16_PCREL_S2
18154 || fixp->fx_r_type == BFD_RELOC_MICROMIPS_7_PCREL_S1
18155 || fixp->fx_r_type == BFD_RELOC_MICROMIPS_10_PCREL_S1
18156 || fixp->fx_r_type == BFD_RELOC_MICROMIPS_16_PCREL_S1
18157 || fixp->fx_r_type == BFD_RELOC_32_PCREL);
18159 /* At this point, fx_addnumber is "symbol offset - pcrel address".
18160 Relocations want only the symbol offset. */
18161 reloc->addend = fixp->fx_addnumber + reloc->address;
18164 /* A gruesome hack which is a result of the gruesome gas
18165 reloc handling. What's worse, for COFF (as opposed to
18166 ECOFF), we might need yet another copy of reloc->address.
18167 See bfd_install_relocation. */
18168 reloc->addend += reloc->address;
18172 reloc->addend = fixp->fx_addnumber;
18174 /* Since the old MIPS ELF ABI uses Rel instead of Rela, encode the vtable
18175 entry to be used in the relocation's section offset. */
18176 if (! HAVE_NEWABI && fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
18178 reloc->address = reloc->addend;
18182 code = fixp->fx_r_type;
18184 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
18185 if (reloc->howto == NULL)
18187 as_bad_where (fixp->fx_file, fixp->fx_line,
18188 _("Can not represent %s relocation in this object file format"),
18189 bfd_get_reloc_code_name (code));
18196 /* Relax a machine dependent frag. This returns the amount by which
18197 the current size of the frag should change. */
18200 mips_relax_frag (asection *sec, fragS *fragp, long stretch)
18202 if (RELAX_BRANCH_P (fragp->fr_subtype))
18204 offsetT old_var = fragp->fr_var;
18206 fragp->fr_var = relaxed_branch_length (fragp, sec, TRUE);
18208 return fragp->fr_var - old_var;
18211 if (RELAX_MICROMIPS_P (fragp->fr_subtype))
18213 offsetT old_var = fragp->fr_var;
18214 offsetT new_var = 4;
18216 if (RELAX_MICROMIPS_TYPE (fragp->fr_subtype) != 0)
18217 new_var = relaxed_micromips_16bit_branch_length (fragp, sec, TRUE);
18218 if (new_var == 4 && RELAX_MICROMIPS_RELAX32 (fragp->fr_subtype))
18219 new_var = relaxed_micromips_32bit_branch_length (fragp, sec, TRUE);
18220 fragp->fr_var = new_var;
18222 return new_var - old_var;
18225 if (! RELAX_MIPS16_P (fragp->fr_subtype))
18228 if (mips16_extended_frag (fragp, NULL, stretch))
18230 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
18232 fragp->fr_subtype = RELAX_MIPS16_MARK_EXTENDED (fragp->fr_subtype);
18237 if (! RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
18239 fragp->fr_subtype = RELAX_MIPS16_CLEAR_EXTENDED (fragp->fr_subtype);
18246 /* Convert a machine dependent frag. */
18249 md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, segT asec, fragS *fragp)
18251 if (RELAX_BRANCH_P (fragp->fr_subtype))
18254 unsigned long insn;
18258 buf = fragp->fr_literal + fragp->fr_fix;
18259 insn = read_insn (buf);
18261 if (!RELAX_BRANCH_TOOFAR (fragp->fr_subtype))
18263 /* We generate a fixup instead of applying it right now
18264 because, if there are linker relaxations, we're going to
18265 need the relocations. */
18266 exp.X_op = O_symbol;
18267 exp.X_add_symbol = fragp->fr_symbol;
18268 exp.X_add_number = fragp->fr_offset;
18270 fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 4, &exp, TRUE,
18271 BFD_RELOC_16_PCREL_S2);
18272 fixp->fx_file = fragp->fr_file;
18273 fixp->fx_line = fragp->fr_line;
18275 buf = write_insn (buf, insn);
18281 as_warn_where (fragp->fr_file, fragp->fr_line,
18282 _("Relaxed out-of-range branch into a jump"));
18284 if (RELAX_BRANCH_UNCOND (fragp->fr_subtype))
18287 if (!RELAX_BRANCH_LIKELY (fragp->fr_subtype))
18289 /* Reverse the branch. */
18290 switch ((insn >> 28) & 0xf)
18293 /* bc[0-3][tf]l? instructions can have the condition
18294 reversed by tweaking a single TF bit, and their
18295 opcodes all have 0x4???????. */
18296 gas_assert ((insn & 0xf3e00000) == 0x41000000);
18297 insn ^= 0x00010000;
18301 /* bltz 0x04000000 bgez 0x04010000
18302 bltzal 0x04100000 bgezal 0x04110000 */
18303 gas_assert ((insn & 0xfc0e0000) == 0x04000000);
18304 insn ^= 0x00010000;
18308 /* beq 0x10000000 bne 0x14000000
18309 blez 0x18000000 bgtz 0x1c000000 */
18310 insn ^= 0x04000000;
18318 if (RELAX_BRANCH_LINK (fragp->fr_subtype))
18320 /* Clear the and-link bit. */
18321 gas_assert ((insn & 0xfc1c0000) == 0x04100000);
18323 /* bltzal 0x04100000 bgezal 0x04110000
18324 bltzall 0x04120000 bgezall 0x04130000 */
18325 insn &= ~0x00100000;
18328 /* Branch over the branch (if the branch was likely) or the
18329 full jump (not likely case). Compute the offset from the
18330 current instruction to branch to. */
18331 if (RELAX_BRANCH_LIKELY (fragp->fr_subtype))
18335 /* How many bytes in instructions we've already emitted? */
18336 i = buf - fragp->fr_literal - fragp->fr_fix;
18337 /* How many bytes in instructions from here to the end? */
18338 i = fragp->fr_var - i;
18340 /* Convert to instruction count. */
18342 /* Branch counts from the next instruction. */
18345 /* Branch over the jump. */
18346 buf = write_insn (buf, insn);
18349 buf = write_insn (buf, 0);
18351 if (RELAX_BRANCH_LIKELY (fragp->fr_subtype))
18353 /* beql $0, $0, 2f */
18355 /* Compute the PC offset from the current instruction to
18356 the end of the variable frag. */
18357 /* How many bytes in instructions we've already emitted? */
18358 i = buf - fragp->fr_literal - fragp->fr_fix;
18359 /* How many bytes in instructions from here to the end? */
18360 i = fragp->fr_var - i;
18361 /* Convert to instruction count. */
18363 /* Don't decrement i, because we want to branch over the
18367 buf = write_insn (buf, insn);
18368 buf = write_insn (buf, 0);
18372 if (mips_pic == NO_PIC)
18375 insn = (RELAX_BRANCH_LINK (fragp->fr_subtype)
18376 ? 0x0c000000 : 0x08000000);
18377 exp.X_op = O_symbol;
18378 exp.X_add_symbol = fragp->fr_symbol;
18379 exp.X_add_number = fragp->fr_offset;
18381 fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 4, &exp,
18382 FALSE, BFD_RELOC_MIPS_JMP);
18383 fixp->fx_file = fragp->fr_file;
18384 fixp->fx_line = fragp->fr_line;
18386 buf = write_insn (buf, insn);
18390 unsigned long at = RELAX_BRANCH_AT (fragp->fr_subtype);
18392 /* lw/ld $at, <sym>($gp) R_MIPS_GOT16 */
18393 insn = HAVE_64BIT_ADDRESSES ? 0xdf800000 : 0x8f800000;
18394 insn |= at << OP_SH_RT;
18395 exp.X_op = O_symbol;
18396 exp.X_add_symbol = fragp->fr_symbol;
18397 exp.X_add_number = fragp->fr_offset;
18399 if (fragp->fr_offset)
18401 exp.X_add_symbol = make_expr_symbol (&exp);
18402 exp.X_add_number = 0;
18405 fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 4, &exp,
18406 FALSE, BFD_RELOC_MIPS_GOT16);
18407 fixp->fx_file = fragp->fr_file;
18408 fixp->fx_line = fragp->fr_line;
18410 buf = write_insn (buf, insn);
18412 if (mips_opts.isa == ISA_MIPS1)
18414 buf = write_insn (buf, 0);
18416 /* d/addiu $at, $at, <sym> R_MIPS_LO16 */
18417 insn = HAVE_64BIT_ADDRESSES ? 0x64000000 : 0x24000000;
18418 insn |= at << OP_SH_RS | at << OP_SH_RT;
18420 fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 4, &exp,
18421 FALSE, BFD_RELOC_LO16);
18422 fixp->fx_file = fragp->fr_file;
18423 fixp->fx_line = fragp->fr_line;
18425 buf = write_insn (buf, insn);
18428 if (RELAX_BRANCH_LINK (fragp->fr_subtype))
18432 insn |= at << OP_SH_RS;
18434 buf = write_insn (buf, insn);
18438 fragp->fr_fix += fragp->fr_var;
18439 gas_assert (buf == fragp->fr_literal + fragp->fr_fix);
18443 /* Relax microMIPS branches. */
18444 if (RELAX_MICROMIPS_P (fragp->fr_subtype))
18446 char *buf = fragp->fr_literal + fragp->fr_fix;
18447 bfd_boolean compact = RELAX_MICROMIPS_COMPACT (fragp->fr_subtype);
18448 bfd_boolean al = RELAX_MICROMIPS_LINK (fragp->fr_subtype);
18449 int type = RELAX_MICROMIPS_TYPE (fragp->fr_subtype);
18450 bfd_boolean short_ds;
18451 unsigned long insn;
18455 exp.X_op = O_symbol;
18456 exp.X_add_symbol = fragp->fr_symbol;
18457 exp.X_add_number = fragp->fr_offset;
18459 fragp->fr_fix += fragp->fr_var;
18461 /* Handle 16-bit branches that fit or are forced to fit. */
18462 if (type != 0 && !RELAX_MICROMIPS_TOOFAR16 (fragp->fr_subtype))
18464 /* We generate a fixup instead of applying it right now,
18465 because if there is linker relaxation, we're going to
18466 need the relocations. */
18468 fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 2, &exp, TRUE,
18469 BFD_RELOC_MICROMIPS_10_PCREL_S1);
18470 else if (type == 'E')
18471 fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 2, &exp, TRUE,
18472 BFD_RELOC_MICROMIPS_7_PCREL_S1);
18476 fixp->fx_file = fragp->fr_file;
18477 fixp->fx_line = fragp->fr_line;
18479 /* These relocations can have an addend that won't fit in
18481 fixp->fx_no_overflow = 1;
18486 /* Handle 32-bit branches that fit or are forced to fit. */
18487 if (!RELAX_MICROMIPS_RELAX32 (fragp->fr_subtype)
18488 || !RELAX_MICROMIPS_TOOFAR32 (fragp->fr_subtype))
18490 /* We generate a fixup instead of applying it right now,
18491 because if there is linker relaxation, we're going to
18492 need the relocations. */
18493 fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 4, &exp, TRUE,
18494 BFD_RELOC_MICROMIPS_16_PCREL_S1);
18495 fixp->fx_file = fragp->fr_file;
18496 fixp->fx_line = fragp->fr_line;
18502 /* Relax 16-bit branches to 32-bit branches. */
18505 insn = read_compressed_insn (buf, 2);
18507 if ((insn & 0xfc00) == 0xcc00) /* b16 */
18508 insn = 0x94000000; /* beq */
18509 else if ((insn & 0xdc00) == 0x8c00) /* beqz16/bnez16 */
18511 unsigned long regno;
18513 regno = (insn >> MICROMIPSOP_SH_MD) & MICROMIPSOP_MASK_MD;
18514 regno = micromips_to_32_reg_d_map [regno];
18515 insn = ((insn & 0x2000) << 16) | 0x94000000; /* beq/bne */
18516 insn |= regno << MICROMIPSOP_SH_RS;
18521 /* Nothing else to do, just write it out. */
18522 if (!RELAX_MICROMIPS_RELAX32 (fragp->fr_subtype)
18523 || !RELAX_MICROMIPS_TOOFAR32 (fragp->fr_subtype))
18525 buf = write_compressed_insn (buf, insn, 4);
18526 gas_assert (buf == fragp->fr_literal + fragp->fr_fix);
18531 insn = read_compressed_insn (buf, 4);
18533 /* Relax 32-bit branches to a sequence of instructions. */
18534 as_warn_where (fragp->fr_file, fragp->fr_line,
18535 _("Relaxed out-of-range branch into a jump"));
18537 /* Set the short-delay-slot bit. */
18538 short_ds = al && (insn & 0x02000000) != 0;
18540 if (!RELAX_MICROMIPS_UNCOND (fragp->fr_subtype))
18544 /* Reverse the branch. */
18545 if ((insn & 0xfc000000) == 0x94000000 /* beq */
18546 || (insn & 0xfc000000) == 0xb4000000) /* bne */
18547 insn ^= 0x20000000;
18548 else if ((insn & 0xffe00000) == 0x40000000 /* bltz */
18549 || (insn & 0xffe00000) == 0x40400000 /* bgez */
18550 || (insn & 0xffe00000) == 0x40800000 /* blez */
18551 || (insn & 0xffe00000) == 0x40c00000 /* bgtz */
18552 || (insn & 0xffe00000) == 0x40a00000 /* bnezc */
18553 || (insn & 0xffe00000) == 0x40e00000 /* beqzc */
18554 || (insn & 0xffe00000) == 0x40200000 /* bltzal */
18555 || (insn & 0xffe00000) == 0x40600000 /* bgezal */
18556 || (insn & 0xffe00000) == 0x42200000 /* bltzals */
18557 || (insn & 0xffe00000) == 0x42600000) /* bgezals */
18558 insn ^= 0x00400000;
18559 else if ((insn & 0xffe30000) == 0x43800000 /* bc1f */
18560 || (insn & 0xffe30000) == 0x43a00000 /* bc1t */
18561 || (insn & 0xffe30000) == 0x42800000 /* bc2f */
18562 || (insn & 0xffe30000) == 0x42a00000) /* bc2t */
18563 insn ^= 0x00200000;
18569 /* Clear the and-link and short-delay-slot bits. */
18570 gas_assert ((insn & 0xfda00000) == 0x40200000);
18572 /* bltzal 0x40200000 bgezal 0x40600000 */
18573 /* bltzals 0x42200000 bgezals 0x42600000 */
18574 insn &= ~0x02200000;
18577 /* Make a label at the end for use with the branch. */
18578 l = symbol_new (micromips_label_name (), asec, fragp->fr_fix, fragp);
18579 micromips_label_inc ();
18580 #if defined(OBJ_ELF) || defined(OBJ_MAYBE_ELF)
18582 S_SET_OTHER (l, ELF_ST_SET_MICROMIPS (S_GET_OTHER (l)));
18586 fixp = fix_new (fragp, buf - fragp->fr_literal, 4, l, 0, TRUE,
18587 BFD_RELOC_MICROMIPS_16_PCREL_S1);
18588 fixp->fx_file = fragp->fr_file;
18589 fixp->fx_line = fragp->fr_line;
18591 /* Branch over the jump. */
18592 buf = write_compressed_insn (buf, insn, 4);
18595 buf = write_compressed_insn (buf, 0x0c00, 2);
18598 if (mips_pic == NO_PIC)
18600 unsigned long jal = short_ds ? 0x74000000 : 0xf4000000; /* jal/s */
18602 /* j/jal/jals <sym> R_MICROMIPS_26_S1 */
18603 insn = al ? jal : 0xd4000000;
18605 fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 4, &exp, FALSE,
18606 BFD_RELOC_MICROMIPS_JMP);
18607 fixp->fx_file = fragp->fr_file;
18608 fixp->fx_line = fragp->fr_line;
18610 buf = write_compressed_insn (buf, insn, 4);
18613 buf = write_compressed_insn (buf, 0x0c00, 2);
18617 unsigned long at = RELAX_MICROMIPS_AT (fragp->fr_subtype);
18618 unsigned long jalr = short_ds ? 0x45e0 : 0x45c0; /* jalr/s */
18619 unsigned long jr = compact ? 0x45a0 : 0x4580; /* jr/c */
18621 /* lw/ld $at, <sym>($gp) R_MICROMIPS_GOT16 */
18622 insn = HAVE_64BIT_ADDRESSES ? 0xdc1c0000 : 0xfc1c0000;
18623 insn |= at << MICROMIPSOP_SH_RT;
18625 if (exp.X_add_number)
18627 exp.X_add_symbol = make_expr_symbol (&exp);
18628 exp.X_add_number = 0;
18631 fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 4, &exp, FALSE,
18632 BFD_RELOC_MICROMIPS_GOT16);
18633 fixp->fx_file = fragp->fr_file;
18634 fixp->fx_line = fragp->fr_line;
18636 buf = write_compressed_insn (buf, insn, 4);
18638 /* d/addiu $at, $at, <sym> R_MICROMIPS_LO16 */
18639 insn = HAVE_64BIT_ADDRESSES ? 0x5c000000 : 0x30000000;
18640 insn |= at << MICROMIPSOP_SH_RT | at << MICROMIPSOP_SH_RS;
18642 fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 4, &exp, FALSE,
18643 BFD_RELOC_MICROMIPS_LO16);
18644 fixp->fx_file = fragp->fr_file;
18645 fixp->fx_line = fragp->fr_line;
18647 buf = write_compressed_insn (buf, insn, 4);
18649 /* jr/jrc/jalr/jalrs $at */
18650 insn = al ? jalr : jr;
18651 insn |= at << MICROMIPSOP_SH_MJ;
18653 buf = write_compressed_insn (buf, insn, 2);
18656 gas_assert (buf == fragp->fr_literal + fragp->fr_fix);
18660 if (RELAX_MIPS16_P (fragp->fr_subtype))
18663 const struct mips16_immed_operand *op;
18666 unsigned int user_length, length;
18667 unsigned long insn;
18670 type = RELAX_MIPS16_TYPE (fragp->fr_subtype);
18671 op = mips16_immed_operands;
18672 while (op->type != type)
18675 ext = RELAX_MIPS16_EXTENDED (fragp->fr_subtype);
18676 val = resolve_symbol_value (fragp->fr_symbol);
18681 addr = fragp->fr_address + fragp->fr_fix;
18683 /* The rules for the base address of a PC relative reloc are
18684 complicated; see mips16_extended_frag. */
18685 if (type == 'p' || type == 'q')
18690 /* Ignore the low bit in the target, since it will be
18691 set for a text label. */
18692 if ((val & 1) != 0)
18695 else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype))
18697 else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype))
18700 addr &= ~ (addressT) ((1 << op->shift) - 1);
18703 /* Make sure the section winds up with the alignment we have
18706 record_alignment (asec, op->shift);
18710 && (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype)
18711 || RELAX_MIPS16_DSLOT (fragp->fr_subtype)))
18712 as_warn_where (fragp->fr_file, fragp->fr_line,
18713 _("extended instruction in delay slot"));
18715 buf = fragp->fr_literal + fragp->fr_fix;
18717 insn = read_compressed_insn (buf, 2);
18719 insn |= MIPS16_EXTEND;
18721 if (RELAX_MIPS16_USER_EXT (fragp->fr_subtype))
18723 else if (RELAX_MIPS16_USER_SMALL (fragp->fr_subtype))
18728 mips16_immed (fragp->fr_file, fragp->fr_line, type,
18729 BFD_RELOC_UNUSED, val, user_length, &insn);
18731 length = (ext ? 4 : 2);
18732 gas_assert (mips16_opcode_length (insn) == length);
18733 write_compressed_insn (buf, insn, length);
18734 fragp->fr_fix += length;
18738 relax_substateT subtype = fragp->fr_subtype;
18739 bfd_boolean second_longer = (subtype & RELAX_SECOND_LONGER) != 0;
18740 bfd_boolean use_second = (subtype & RELAX_USE_SECOND) != 0;
18744 first = RELAX_FIRST (subtype);
18745 second = RELAX_SECOND (subtype);
18746 fixp = (fixS *) fragp->fr_opcode;
18748 /* If the delay slot chosen does not match the size of the instruction,
18749 then emit a warning. */
18750 if ((!use_second && (subtype & RELAX_DELAY_SLOT_SIZE_FIRST) != 0)
18751 || (use_second && (subtype & RELAX_DELAY_SLOT_SIZE_SECOND) != 0))
18756 s = subtype & (RELAX_DELAY_SLOT_16BIT
18757 | RELAX_DELAY_SLOT_SIZE_FIRST
18758 | RELAX_DELAY_SLOT_SIZE_SECOND);
18759 msg = macro_warning (s);
18761 as_warn_where (fragp->fr_file, fragp->fr_line, "%s", msg);
18765 /* Possibly emit a warning if we've chosen the longer option. */
18766 if (use_second == second_longer)
18772 & (RELAX_SECOND_LONGER | RELAX_NOMACRO | RELAX_DELAY_SLOT));
18773 msg = macro_warning (s);
18775 as_warn_where (fragp->fr_file, fragp->fr_line, "%s", msg);
18779 /* Go through all the fixups for the first sequence. Disable them
18780 (by marking them as done) if we're going to use the second
18781 sequence instead. */
18783 && fixp->fx_frag == fragp
18784 && fixp->fx_where < fragp->fr_fix - second)
18786 if (subtype & RELAX_USE_SECOND)
18788 fixp = fixp->fx_next;
18791 /* Go through the fixups for the second sequence. Disable them if
18792 we're going to use the first sequence, otherwise adjust their
18793 addresses to account for the relaxation. */
18794 while (fixp && fixp->fx_frag == fragp)
18796 if (subtype & RELAX_USE_SECOND)
18797 fixp->fx_where -= first;
18800 fixp = fixp->fx_next;
18803 /* Now modify the frag contents. */
18804 if (subtype & RELAX_USE_SECOND)
18808 start = fragp->fr_literal + fragp->fr_fix - first - second;
18809 memmove (start, start + first, second);
18810 fragp->fr_fix -= first;
18813 fragp->fr_fix -= second;
18819 /* This function is called after the relocs have been generated.
18820 We've been storing mips16 text labels as odd. Here we convert them
18821 back to even for the convenience of the debugger. */
18824 mips_frob_file_after_relocs (void)
18827 unsigned int count, i;
18832 syms = bfd_get_outsymbols (stdoutput);
18833 count = bfd_get_symcount (stdoutput);
18834 for (i = 0; i < count; i++, syms++)
18835 if (ELF_ST_IS_COMPRESSED (elf_symbol (*syms)->internal_elf_sym.st_other)
18836 && ((*syms)->value & 1) != 0)
18838 (*syms)->value &= ~1;
18839 /* If the symbol has an odd size, it was probably computed
18840 incorrectly, so adjust that as well. */
18841 if ((elf_symbol (*syms)->internal_elf_sym.st_size & 1) != 0)
18842 ++elf_symbol (*syms)->internal_elf_sym.st_size;
18848 /* This function is called whenever a label is defined, including fake
18849 labels instantiated off the dot special symbol. It is used when
18850 handling branch delays; if a branch has a label, we assume we cannot
18851 move it. This also bumps the value of the symbol by 1 in compressed
18855 mips_record_label (symbolS *sym)
18857 segment_info_type *si = seg_info (now_seg);
18858 struct insn_label_list *l;
18860 if (free_insn_labels == NULL)
18861 l = (struct insn_label_list *) xmalloc (sizeof *l);
18864 l = free_insn_labels;
18865 free_insn_labels = l->next;
18869 l->next = si->label_list;
18870 si->label_list = l;
18873 /* This function is called as tc_frob_label() whenever a label is defined
18874 and adds a DWARF-2 record we only want for true labels. */
18877 mips_define_label (symbolS *sym)
18879 mips_record_label (sym);
18881 dwarf2_emit_label (sym);
18885 /* This function is called by tc_new_dot_label whenever a new dot symbol
18889 mips_add_dot_label (symbolS *sym)
18891 mips_record_label (sym);
18892 if (mips_assembling_insn && HAVE_CODE_COMPRESSION)
18893 mips_compressed_mark_label (sym);
18896 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
18898 /* Some special processing for a MIPS ELF file. */
18901 mips_elf_final_processing (void)
18903 /* Write out the register information. */
18904 if (mips_abi != N64_ABI)
18908 s.ri_gprmask = mips_gprmask;
18909 s.ri_cprmask[0] = mips_cprmask[0];
18910 s.ri_cprmask[1] = mips_cprmask[1];
18911 s.ri_cprmask[2] = mips_cprmask[2];
18912 s.ri_cprmask[3] = mips_cprmask[3];
18913 /* The gp_value field is set by the MIPS ELF backend. */
18915 bfd_mips_elf32_swap_reginfo_out (stdoutput, &s,
18916 ((Elf32_External_RegInfo *)
18917 mips_regmask_frag));
18921 Elf64_Internal_RegInfo s;
18923 s.ri_gprmask = mips_gprmask;
18925 s.ri_cprmask[0] = mips_cprmask[0];
18926 s.ri_cprmask[1] = mips_cprmask[1];
18927 s.ri_cprmask[2] = mips_cprmask[2];
18928 s.ri_cprmask[3] = mips_cprmask[3];
18929 /* The gp_value field is set by the MIPS ELF backend. */
18931 bfd_mips_elf64_swap_reginfo_out (stdoutput, &s,
18932 ((Elf64_External_RegInfo *)
18933 mips_regmask_frag));
18936 /* Set the MIPS ELF flag bits. FIXME: There should probably be some
18937 sort of BFD interface for this. */
18938 if (mips_any_noreorder)
18939 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_NOREORDER;
18940 if (mips_pic != NO_PIC)
18942 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_PIC;
18943 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_CPIC;
18946 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_CPIC;
18948 /* Set MIPS ELF flags for ASEs. Note that not all ASEs have flags
18949 defined at present; this might need to change in future. */
18950 if (file_ase_mips16)
18951 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ARCH_ASE_M16;
18952 if (file_ase_micromips)
18953 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ARCH_ASE_MICROMIPS;
18954 if (file_ase & ASE_MDMX)
18955 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ARCH_ASE_MDMX;
18957 /* Set the MIPS ELF ABI flags. */
18958 if (mips_abi == O32_ABI && USE_E_MIPS_ABI_O32)
18959 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O32;
18960 else if (mips_abi == O64_ABI)
18961 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O64;
18962 else if (mips_abi == EABI_ABI)
18964 if (!file_mips_gp32)
18965 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI64;
18967 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI32;
18969 else if (mips_abi == N32_ABI)
18970 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ABI2;
18972 /* Nothing to do for N64_ABI. */
18974 if (mips_32bitmode)
18975 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_32BITMODE;
18977 #if 0 /* XXX FIXME */
18978 /* 32 bit code with 64 bit FP registers. */
18979 if (!file_mips_fp32 && ABI_NEEDS_32BIT_REGS (mips_abi))
18980 elf_elfheader (stdoutput)->e_flags |= ???;
18984 #endif /* OBJ_ELF || OBJ_MAYBE_ELF */
18986 typedef struct proc {
18988 symbolS *func_end_sym;
18989 unsigned long reg_mask;
18990 unsigned long reg_offset;
18991 unsigned long fpreg_mask;
18992 unsigned long fpreg_offset;
18993 unsigned long frame_offset;
18994 unsigned long frame_reg;
18995 unsigned long pc_reg;
18998 static procS cur_proc;
18999 static procS *cur_proc_ptr;
19000 static int numprocs;
19002 /* Implement NOP_OPCODE. We encode a MIPS16 nop as "1", a microMIPS nop
19003 as "2", and a normal nop as "0". */
19005 #define NOP_OPCODE_MIPS 0
19006 #define NOP_OPCODE_MIPS16 1
19007 #define NOP_OPCODE_MICROMIPS 2
19010 mips_nop_opcode (void)
19012 if (seg_info (now_seg)->tc_segment_info_data.micromips)
19013 return NOP_OPCODE_MICROMIPS;
19014 else if (seg_info (now_seg)->tc_segment_info_data.mips16)
19015 return NOP_OPCODE_MIPS16;
19017 return NOP_OPCODE_MIPS;
19020 /* Fill in an rs_align_code fragment. Unlike elsewhere we want to use
19021 32-bit microMIPS NOPs here (if applicable). */
19024 mips_handle_align (fragS *fragp)
19028 int bytes, size, excess;
19031 if (fragp->fr_type != rs_align_code)
19034 p = fragp->fr_literal + fragp->fr_fix;
19036 switch (nop_opcode)
19038 case NOP_OPCODE_MICROMIPS:
19039 opcode = micromips_nop32_insn.insn_opcode;
19042 case NOP_OPCODE_MIPS16:
19043 opcode = mips16_nop_insn.insn_opcode;
19046 case NOP_OPCODE_MIPS:
19048 opcode = nop_insn.insn_opcode;
19053 bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
19054 excess = bytes % size;
19056 /* Handle the leading part if we're not inserting a whole number of
19057 instructions, and make it the end of the fixed part of the frag.
19058 Try to fit in a short microMIPS NOP if applicable and possible,
19059 and use zeroes otherwise. */
19060 gas_assert (excess < 4);
19061 fragp->fr_fix += excess;
19066 /* Fall through. */
19068 if (nop_opcode == NOP_OPCODE_MICROMIPS)
19070 p = write_compressed_insn (p, micromips_nop16_insn.insn_opcode, 2);
19074 /* Fall through. */
19077 /* Fall through. */
19082 md_number_to_chars (p, opcode, size);
19083 fragp->fr_var = size;
19087 md_obj_begin (void)
19094 /* Check for premature end, nesting errors, etc. */
19096 as_warn (_("missing .end at end of assembly"));
19105 if (*input_line_pointer == '-')
19107 ++input_line_pointer;
19110 if (!ISDIGIT (*input_line_pointer))
19111 as_bad (_("expected simple number"));
19112 if (input_line_pointer[0] == '0')
19114 if (input_line_pointer[1] == 'x')
19116 input_line_pointer += 2;
19117 while (ISXDIGIT (*input_line_pointer))
19120 val |= hex_value (*input_line_pointer++);
19122 return negative ? -val : val;
19126 ++input_line_pointer;
19127 while (ISDIGIT (*input_line_pointer))
19130 val |= *input_line_pointer++ - '0';
19132 return negative ? -val : val;
19135 if (!ISDIGIT (*input_line_pointer))
19137 printf (_(" *input_line_pointer == '%c' 0x%02x\n"),
19138 *input_line_pointer, *input_line_pointer);
19139 as_warn (_("invalid number"));
19142 while (ISDIGIT (*input_line_pointer))
19145 val += *input_line_pointer++ - '0';
19147 return negative ? -val : val;
19150 /* The .file directive; just like the usual .file directive, but there
19151 is an initial number which is the ECOFF file index. In the non-ECOFF
19152 case .file implies DWARF-2. */
19155 s_mips_file (int x ATTRIBUTE_UNUSED)
19157 static int first_file_directive = 0;
19159 if (ECOFF_DEBUGGING)
19168 filename = dwarf2_directive_file (0);
19170 /* Versions of GCC up to 3.1 start files with a ".file"
19171 directive even for stabs output. Make sure that this
19172 ".file" is handled. Note that you need a version of GCC
19173 after 3.1 in order to support DWARF-2 on MIPS. */
19174 if (filename != NULL && ! first_file_directive)
19176 (void) new_logical_line (filename, -1);
19177 s_app_file_string (filename, 0);
19179 first_file_directive = 1;
19183 /* The .loc directive, implying DWARF-2. */
19186 s_mips_loc (int x ATTRIBUTE_UNUSED)
19188 if (!ECOFF_DEBUGGING)
19189 dwarf2_directive_loc (0);
19192 /* The .end directive. */
19195 s_mips_end (int x ATTRIBUTE_UNUSED)
19199 /* Following functions need their own .frame and .cprestore directives. */
19200 mips_frame_reg_valid = 0;
19201 mips_cprestore_valid = 0;
19203 if (!is_end_of_line[(unsigned char) *input_line_pointer])
19206 demand_empty_rest_of_line ();
19211 if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) == 0)
19212 as_warn (_(".end not in text section"));
19216 as_warn (_(".end directive without a preceding .ent directive."));
19217 demand_empty_rest_of_line ();
19223 gas_assert (S_GET_NAME (p));
19224 if (strcmp (S_GET_NAME (p), S_GET_NAME (cur_proc_ptr->func_sym)))
19225 as_warn (_(".end symbol does not match .ent symbol."));
19227 if (debug_type == DEBUG_STABS)
19228 stabs_generate_asm_endfunc (S_GET_NAME (p),
19232 as_warn (_(".end directive missing or unknown symbol"));
19235 /* Create an expression to calculate the size of the function. */
19236 if (p && cur_proc_ptr)
19238 OBJ_SYMFIELD_TYPE *obj = symbol_get_obj (p);
19239 expressionS *exp = xmalloc (sizeof (expressionS));
19242 exp->X_op = O_subtract;
19243 exp->X_add_symbol = symbol_temp_new_now ();
19244 exp->X_op_symbol = p;
19245 exp->X_add_number = 0;
19247 cur_proc_ptr->func_end_sym = exp->X_add_symbol;
19250 /* Generate a .pdr section. */
19251 if (IS_ELF && !ECOFF_DEBUGGING && mips_flag_pdr)
19253 segT saved_seg = now_seg;
19254 subsegT saved_subseg = now_subseg;
19258 #ifdef md_flush_pending_output
19259 md_flush_pending_output ();
19262 gas_assert (pdr_seg);
19263 subseg_set (pdr_seg, 0);
19265 /* Write the symbol. */
19266 exp.X_op = O_symbol;
19267 exp.X_add_symbol = p;
19268 exp.X_add_number = 0;
19269 emit_expr (&exp, 4);
19271 fragp = frag_more (7 * 4);
19273 md_number_to_chars (fragp, cur_proc_ptr->reg_mask, 4);
19274 md_number_to_chars (fragp + 4, cur_proc_ptr->reg_offset, 4);
19275 md_number_to_chars (fragp + 8, cur_proc_ptr->fpreg_mask, 4);
19276 md_number_to_chars (fragp + 12, cur_proc_ptr->fpreg_offset, 4);
19277 md_number_to_chars (fragp + 16, cur_proc_ptr->frame_offset, 4);
19278 md_number_to_chars (fragp + 20, cur_proc_ptr->frame_reg, 4);
19279 md_number_to_chars (fragp + 24, cur_proc_ptr->pc_reg, 4);
19281 subseg_set (saved_seg, saved_subseg);
19283 #endif /* OBJ_ELF */
19285 cur_proc_ptr = NULL;
19288 /* The .aent and .ent directives. */
19291 s_mips_ent (int aent)
19295 symbolP = get_symbol ();
19296 if (*input_line_pointer == ',')
19297 ++input_line_pointer;
19298 SKIP_WHITESPACE ();
19299 if (ISDIGIT (*input_line_pointer)
19300 || *input_line_pointer == '-')
19303 if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) == 0)
19304 as_warn (_(".ent or .aent not in text section."));
19306 if (!aent && cur_proc_ptr)
19307 as_warn (_("missing .end"));
19311 /* This function needs its own .frame and .cprestore directives. */
19312 mips_frame_reg_valid = 0;
19313 mips_cprestore_valid = 0;
19315 cur_proc_ptr = &cur_proc;
19316 memset (cur_proc_ptr, '\0', sizeof (procS));
19318 cur_proc_ptr->func_sym = symbolP;
19322 if (debug_type == DEBUG_STABS)
19323 stabs_generate_asm_func (S_GET_NAME (symbolP),
19324 S_GET_NAME (symbolP));
19327 symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION;
19329 demand_empty_rest_of_line ();
19332 /* The .frame directive. If the mdebug section is present (IRIX 5 native)
19333 then ecoff.c (ecoff_directive_frame) is used. For embedded targets,
19334 s_mips_frame is used so that we can set the PDR information correctly.
19335 We can't use the ecoff routines because they make reference to the ecoff
19336 symbol table (in the mdebug section). */
19339 s_mips_frame (int ignore ATTRIBUTE_UNUSED)
19342 if (IS_ELF && !ECOFF_DEBUGGING)
19346 if (cur_proc_ptr == (procS *) NULL)
19348 as_warn (_(".frame outside of .ent"));
19349 demand_empty_rest_of_line ();
19353 cur_proc_ptr->frame_reg = tc_get_register (1);
19355 SKIP_WHITESPACE ();
19356 if (*input_line_pointer++ != ','
19357 || get_absolute_expression_and_terminator (&val) != ',')
19359 as_warn (_("Bad .frame directive"));
19360 --input_line_pointer;
19361 demand_empty_rest_of_line ();
19365 cur_proc_ptr->frame_offset = val;
19366 cur_proc_ptr->pc_reg = tc_get_register (0);
19368 demand_empty_rest_of_line ();
19371 #endif /* OBJ_ELF */
19375 /* The .fmask and .mask directives. If the mdebug section is present
19376 (IRIX 5 native) then ecoff.c (ecoff_directive_mask) is used. For
19377 embedded targets, s_mips_mask is used so that we can set the PDR
19378 information correctly. We can't use the ecoff routines because they
19379 make reference to the ecoff symbol table (in the mdebug section). */
19382 s_mips_mask (int reg_type)
19385 if (IS_ELF && !ECOFF_DEBUGGING)
19389 if (cur_proc_ptr == (procS *) NULL)
19391 as_warn (_(".mask/.fmask outside of .ent"));
19392 demand_empty_rest_of_line ();
19396 if (get_absolute_expression_and_terminator (&mask) != ',')
19398 as_warn (_("Bad .mask/.fmask directive"));
19399 --input_line_pointer;
19400 demand_empty_rest_of_line ();
19404 off = get_absolute_expression ();
19406 if (reg_type == 'F')
19408 cur_proc_ptr->fpreg_mask = mask;
19409 cur_proc_ptr->fpreg_offset = off;
19413 cur_proc_ptr->reg_mask = mask;
19414 cur_proc_ptr->reg_offset = off;
19417 demand_empty_rest_of_line ();
19420 #endif /* OBJ_ELF */
19421 s_ignore (reg_type);
19424 /* A table describing all the processors gas knows about. Names are
19425 matched in the order listed.
19427 To ease comparison, please keep this table in the same order as
19428 gcc's mips_cpu_info_table[]. */
19429 static const struct mips_cpu_info mips_cpu_info_table[] =
19431 /* Entries for generic ISAs */
19432 { "mips1", MIPS_CPU_IS_ISA, 0, ISA_MIPS1, CPU_R3000 },
19433 { "mips2", MIPS_CPU_IS_ISA, 0, ISA_MIPS2, CPU_R6000 },
19434 { "mips3", MIPS_CPU_IS_ISA, 0, ISA_MIPS3, CPU_R4000 },
19435 { "mips4", MIPS_CPU_IS_ISA, 0, ISA_MIPS4, CPU_R8000 },
19436 { "mips5", MIPS_CPU_IS_ISA, 0, ISA_MIPS5, CPU_MIPS5 },
19437 { "mips32", MIPS_CPU_IS_ISA, 0, ISA_MIPS32, CPU_MIPS32 },
19438 { "mips32r2", MIPS_CPU_IS_ISA, 0, ISA_MIPS32R2, CPU_MIPS32R2 },
19439 { "mips64", MIPS_CPU_IS_ISA, 0, ISA_MIPS64, CPU_MIPS64 },
19440 { "mips64r2", MIPS_CPU_IS_ISA, 0, ISA_MIPS64R2, CPU_MIPS64R2 },
19443 { "r3000", 0, 0, ISA_MIPS1, CPU_R3000 },
19444 { "r2000", 0, 0, ISA_MIPS1, CPU_R3000 },
19445 { "r3900", 0, 0, ISA_MIPS1, CPU_R3900 },
19448 { "r6000", 0, 0, ISA_MIPS2, CPU_R6000 },
19451 { "r4000", 0, 0, ISA_MIPS3, CPU_R4000 },
19452 { "r4010", 0, 0, ISA_MIPS2, CPU_R4010 },
19453 { "vr4100", 0, 0, ISA_MIPS3, CPU_VR4100 },
19454 { "vr4111", 0, 0, ISA_MIPS3, CPU_R4111 },
19455 { "vr4120", 0, 0, ISA_MIPS3, CPU_VR4120 },
19456 { "vr4130", 0, 0, ISA_MIPS3, CPU_VR4120 },
19457 { "vr4181", 0, 0, ISA_MIPS3, CPU_R4111 },
19458 { "vr4300", 0, 0, ISA_MIPS3, CPU_R4300 },
19459 { "r4400", 0, 0, ISA_MIPS3, CPU_R4400 },
19460 { "r4600", 0, 0, ISA_MIPS3, CPU_R4600 },
19461 { "orion", 0, 0, ISA_MIPS3, CPU_R4600 },
19462 { "r4650", 0, 0, ISA_MIPS3, CPU_R4650 },
19463 { "r5900", 0, 0, ISA_MIPS3, CPU_R5900 },
19464 /* ST Microelectronics Loongson 2E and 2F cores */
19465 { "loongson2e", 0, 0, ISA_MIPS3, CPU_LOONGSON_2E },
19466 { "loongson2f", 0, 0, ISA_MIPS3, CPU_LOONGSON_2F },
19469 { "r8000", 0, 0, ISA_MIPS4, CPU_R8000 },
19470 { "r10000", 0, 0, ISA_MIPS4, CPU_R10000 },
19471 { "r12000", 0, 0, ISA_MIPS4, CPU_R12000 },
19472 { "r14000", 0, 0, ISA_MIPS4, CPU_R14000 },
19473 { "r16000", 0, 0, ISA_MIPS4, CPU_R16000 },
19474 { "vr5000", 0, 0, ISA_MIPS4, CPU_R5000 },
19475 { "vr5400", 0, 0, ISA_MIPS4, CPU_VR5400 },
19476 { "vr5500", 0, 0, ISA_MIPS4, CPU_VR5500 },
19477 { "rm5200", 0, 0, ISA_MIPS4, CPU_R5000 },
19478 { "rm5230", 0, 0, ISA_MIPS4, CPU_R5000 },
19479 { "rm5231", 0, 0, ISA_MIPS4, CPU_R5000 },
19480 { "rm5261", 0, 0, ISA_MIPS4, CPU_R5000 },
19481 { "rm5721", 0, 0, ISA_MIPS4, CPU_R5000 },
19482 { "rm7000", 0, 0, ISA_MIPS4, CPU_RM7000 },
19483 { "rm9000", 0, 0, ISA_MIPS4, CPU_RM9000 },
19486 { "4kc", 0, 0, ISA_MIPS32, CPU_MIPS32 },
19487 { "4km", 0, 0, ISA_MIPS32, CPU_MIPS32 },
19488 { "4kp", 0, 0, ISA_MIPS32, CPU_MIPS32 },
19489 { "4ksc", 0, ASE_SMARTMIPS, ISA_MIPS32, CPU_MIPS32 },
19491 /* MIPS 32 Release 2 */
19492 { "4kec", 0, 0, ISA_MIPS32R2, CPU_MIPS32R2 },
19493 { "4kem", 0, 0, ISA_MIPS32R2, CPU_MIPS32R2 },
19494 { "4kep", 0, 0, ISA_MIPS32R2, CPU_MIPS32R2 },
19495 { "4ksd", 0, ASE_SMARTMIPS, ISA_MIPS32R2, CPU_MIPS32R2 },
19496 { "m4k", 0, 0, ISA_MIPS32R2, CPU_MIPS32R2 },
19497 { "m4kp", 0, 0, ISA_MIPS32R2, CPU_MIPS32R2 },
19498 { "m14k", 0, ASE_MCU, ISA_MIPS32R2, CPU_MIPS32R2 },
19499 { "m14kc", 0, ASE_MCU, ISA_MIPS32R2, CPU_MIPS32R2 },
19500 { "m14ke", 0, ASE_DSP | ASE_DSPR2 | ASE_MCU,
19501 ISA_MIPS32R2, CPU_MIPS32R2 },
19502 { "m14kec", 0, ASE_DSP | ASE_DSPR2 | ASE_MCU,
19503 ISA_MIPS32R2, CPU_MIPS32R2 },
19504 { "24kc", 0, 0, ISA_MIPS32R2, CPU_MIPS32R2 },
19505 { "24kf2_1", 0, 0, ISA_MIPS32R2, CPU_MIPS32R2 },
19506 { "24kf", 0, 0, ISA_MIPS32R2, CPU_MIPS32R2 },
19507 { "24kf1_1", 0, 0, ISA_MIPS32R2, CPU_MIPS32R2 },
19508 /* Deprecated forms of the above. */
19509 { "24kfx", 0, 0, ISA_MIPS32R2, CPU_MIPS32R2 },
19510 { "24kx", 0, 0, ISA_MIPS32R2, CPU_MIPS32R2 },
19511 /* 24KE is a 24K with DSP ASE, other ASEs are optional. */
19512 { "24kec", 0, ASE_DSP, ISA_MIPS32R2, CPU_MIPS32R2 },
19513 { "24kef2_1", 0, ASE_DSP, ISA_MIPS32R2, CPU_MIPS32R2 },
19514 { "24kef", 0, ASE_DSP, ISA_MIPS32R2, CPU_MIPS32R2 },
19515 { "24kef1_1", 0, ASE_DSP, ISA_MIPS32R2, CPU_MIPS32R2 },
19516 /* Deprecated forms of the above. */
19517 { "24kefx", 0, ASE_DSP, ISA_MIPS32R2, CPU_MIPS32R2 },
19518 { "24kex", 0, ASE_DSP, ISA_MIPS32R2, CPU_MIPS32R2 },
19519 /* 34K is a 24K with DSP and MT ASE, other ASEs are optional. */
19520 { "34kc", 0, ASE_DSP | ASE_MT, ISA_MIPS32R2, CPU_MIPS32R2 },
19521 { "34kf2_1", 0, ASE_DSP | ASE_MT, ISA_MIPS32R2, CPU_MIPS32R2 },
19522 { "34kf", 0, ASE_DSP | ASE_MT, ISA_MIPS32R2, CPU_MIPS32R2 },
19523 { "34kf1_1", 0, ASE_DSP | ASE_MT, ISA_MIPS32R2, CPU_MIPS32R2 },
19524 /* Deprecated forms of the above. */
19525 { "34kfx", 0, ASE_DSP | ASE_MT, ISA_MIPS32R2, CPU_MIPS32R2 },
19526 { "34kx", 0, ASE_DSP | ASE_MT, ISA_MIPS32R2, CPU_MIPS32R2 },
19527 /* 34Kn is a 34kc without DSP. */
19528 { "34kn", 0, ASE_MT, ISA_MIPS32R2, CPU_MIPS32R2 },
19529 /* 74K with DSP and DSPR2 ASE, other ASEs are optional. */
19530 { "74kc", 0, ASE_DSP | ASE_DSPR2, ISA_MIPS32R2, CPU_MIPS32R2 },
19531 { "74kf2_1", 0, ASE_DSP | ASE_DSPR2, ISA_MIPS32R2, CPU_MIPS32R2 },
19532 { "74kf", 0, ASE_DSP | ASE_DSPR2, ISA_MIPS32R2, CPU_MIPS32R2 },
19533 { "74kf1_1", 0, ASE_DSP | ASE_DSPR2, ISA_MIPS32R2, CPU_MIPS32R2 },
19534 { "74kf3_2", 0, ASE_DSP | ASE_DSPR2, ISA_MIPS32R2, CPU_MIPS32R2 },
19535 /* Deprecated forms of the above. */
19536 { "74kfx", 0, ASE_DSP | ASE_DSPR2, ISA_MIPS32R2, CPU_MIPS32R2 },
19537 { "74kx", 0, ASE_DSP | ASE_DSPR2, ISA_MIPS32R2, CPU_MIPS32R2 },
19538 /* 1004K cores are multiprocessor versions of the 34K. */
19539 { "1004kc", 0, ASE_DSP | ASE_MT, ISA_MIPS32R2, CPU_MIPS32R2 },
19540 { "1004kf2_1", 0, ASE_DSP | ASE_MT, ISA_MIPS32R2, CPU_MIPS32R2 },
19541 { "1004kf", 0, ASE_DSP | ASE_MT, ISA_MIPS32R2, CPU_MIPS32R2 },
19542 { "1004kf1_1", 0, ASE_DSP | ASE_MT, ISA_MIPS32R2, CPU_MIPS32R2 },
19545 { "5kc", 0, 0, ISA_MIPS64, CPU_MIPS64 },
19546 { "5kf", 0, 0, ISA_MIPS64, CPU_MIPS64 },
19547 { "20kc", 0, ASE_MIPS3D, ISA_MIPS64, CPU_MIPS64 },
19548 { "25kf", 0, ASE_MIPS3D, ISA_MIPS64, CPU_MIPS64 },
19550 /* Broadcom SB-1 CPU core */
19551 { "sb1", 0, ASE_MIPS3D | ASE_MDMX, ISA_MIPS64, CPU_SB1 },
19552 /* Broadcom SB-1A CPU core */
19553 { "sb1a", 0, ASE_MIPS3D | ASE_MDMX, ISA_MIPS64, CPU_SB1 },
19555 { "loongson3a", 0, 0, ISA_MIPS64, CPU_LOONGSON_3A },
19557 /* MIPS 64 Release 2 */
19559 /* Cavium Networks Octeon CPU core */
19560 { "octeon", 0, 0, ISA_MIPS64R2, CPU_OCTEON },
19561 { "octeon+", 0, 0, ISA_MIPS64R2, CPU_OCTEONP },
19562 { "octeon2", 0, 0, ISA_MIPS64R2, CPU_OCTEON2 },
19565 { "xlr", 0, 0, ISA_MIPS64, CPU_XLR },
19568 XLP is mostly like XLR, with the prominent exception that it is
19569 MIPS64R2 rather than MIPS64. */
19570 { "xlp", 0, 0, ISA_MIPS64R2, CPU_XLR },
19573 { NULL, 0, 0, 0, 0 }
19577 /* Return true if GIVEN is the same as CANONICAL, or if it is CANONICAL
19578 with a final "000" replaced by "k". Ignore case.
19580 Note: this function is shared between GCC and GAS. */
19583 mips_strict_matching_cpu_name_p (const char *canonical, const char *given)
19585 while (*given != 0 && TOLOWER (*given) == TOLOWER (*canonical))
19586 given++, canonical++;
19588 return ((*given == 0 && *canonical == 0)
19589 || (strcmp (canonical, "000") == 0 && strcasecmp (given, "k") == 0));
19593 /* Return true if GIVEN matches CANONICAL, where GIVEN is a user-supplied
19594 CPU name. We've traditionally allowed a lot of variation here.
19596 Note: this function is shared between GCC and GAS. */
19599 mips_matching_cpu_name_p (const char *canonical, const char *given)
19601 /* First see if the name matches exactly, or with a final "000"
19602 turned into "k". */
19603 if (mips_strict_matching_cpu_name_p (canonical, given))
19606 /* If not, try comparing based on numerical designation alone.
19607 See if GIVEN is an unadorned number, or 'r' followed by a number. */
19608 if (TOLOWER (*given) == 'r')
19610 if (!ISDIGIT (*given))
19613 /* Skip over some well-known prefixes in the canonical name,
19614 hoping to find a number there too. */
19615 if (TOLOWER (canonical[0]) == 'v' && TOLOWER (canonical[1]) == 'r')
19617 else if (TOLOWER (canonical[0]) == 'r' && TOLOWER (canonical[1]) == 'm')
19619 else if (TOLOWER (canonical[0]) == 'r')
19622 return mips_strict_matching_cpu_name_p (canonical, given);
19626 /* Parse an option that takes the name of a processor as its argument.
19627 OPTION is the name of the option and CPU_STRING is the argument.
19628 Return the corresponding processor enumeration if the CPU_STRING is
19629 recognized, otherwise report an error and return null.
19631 A similar function exists in GCC. */
19633 static const struct mips_cpu_info *
19634 mips_parse_cpu (const char *option, const char *cpu_string)
19636 const struct mips_cpu_info *p;
19638 /* 'from-abi' selects the most compatible architecture for the given
19639 ABI: MIPS I for 32-bit ABIs and MIPS III for 64-bit ABIs. For the
19640 EABIs, we have to decide whether we're using the 32-bit or 64-bit
19641 version. Look first at the -mgp options, if given, otherwise base
19642 the choice on MIPS_DEFAULT_64BIT.
19644 Treat NO_ABI like the EABIs. One reason to do this is that the
19645 plain 'mips' and 'mips64' configs have 'from-abi' as their default
19646 architecture. This code picks MIPS I for 'mips' and MIPS III for
19647 'mips64', just as we did in the days before 'from-abi'. */
19648 if (strcasecmp (cpu_string, "from-abi") == 0)
19650 if (ABI_NEEDS_32BIT_REGS (mips_abi))
19651 return mips_cpu_info_from_isa (ISA_MIPS1);
19653 if (ABI_NEEDS_64BIT_REGS (mips_abi))
19654 return mips_cpu_info_from_isa (ISA_MIPS3);
19656 if (file_mips_gp32 >= 0)
19657 return mips_cpu_info_from_isa (file_mips_gp32 ? ISA_MIPS1 : ISA_MIPS3);
19659 return mips_cpu_info_from_isa (MIPS_DEFAULT_64BIT
19664 /* 'default' has traditionally been a no-op. Probably not very useful. */
19665 if (strcasecmp (cpu_string, "default") == 0)
19668 for (p = mips_cpu_info_table; p->name != 0; p++)
19669 if (mips_matching_cpu_name_p (p->name, cpu_string))
19672 as_bad (_("Bad value (%s) for %s"), cpu_string, option);
19676 /* Return the canonical processor information for ISA (a member of the
19677 ISA_MIPS* enumeration). */
19679 static const struct mips_cpu_info *
19680 mips_cpu_info_from_isa (int isa)
19684 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
19685 if ((mips_cpu_info_table[i].flags & MIPS_CPU_IS_ISA)
19686 && isa == mips_cpu_info_table[i].isa)
19687 return (&mips_cpu_info_table[i]);
19692 static const struct mips_cpu_info *
19693 mips_cpu_info_from_arch (int arch)
19697 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
19698 if (arch == mips_cpu_info_table[i].cpu)
19699 return (&mips_cpu_info_table[i]);
19705 show (FILE *stream, const char *string, int *col_p, int *first_p)
19709 fprintf (stream, "%24s", "");
19714 fprintf (stream, ", ");
19718 if (*col_p + strlen (string) > 72)
19720 fprintf (stream, "\n%24s", "");
19724 fprintf (stream, "%s", string);
19725 *col_p += strlen (string);
19731 md_show_usage (FILE *stream)
19736 fprintf (stream, _("\
19738 -EB generate big endian output\n\
19739 -EL generate little endian output\n\
19740 -g, -g2 do not remove unneeded NOPs or swap branches\n\
19741 -G NUM allow referencing objects up to NUM bytes\n\
19742 implicitly with the gp register [default 8]\n"));
19743 fprintf (stream, _("\
19744 -mips1 generate MIPS ISA I instructions\n\
19745 -mips2 generate MIPS ISA II instructions\n\
19746 -mips3 generate MIPS ISA III instructions\n\
19747 -mips4 generate MIPS ISA IV instructions\n\
19748 -mips5 generate MIPS ISA V instructions\n\
19749 -mips32 generate MIPS32 ISA instructions\n\
19750 -mips32r2 generate MIPS32 release 2 ISA instructions\n\
19751 -mips64 generate MIPS64 ISA instructions\n\
19752 -mips64r2 generate MIPS64 release 2 ISA instructions\n\
19753 -march=CPU/-mtune=CPU generate code/schedule for CPU, where CPU is one of:\n"));
19757 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
19758 show (stream, mips_cpu_info_table[i].name, &column, &first);
19759 show (stream, "from-abi", &column, &first);
19760 fputc ('\n', stream);
19762 fprintf (stream, _("\
19763 -mCPU equivalent to -march=CPU -mtune=CPU. Deprecated.\n\
19764 -no-mCPU don't generate code specific to CPU.\n\
19765 For -mCPU and -no-mCPU, CPU must be one of:\n"));
19769 show (stream, "3900", &column, &first);
19770 show (stream, "4010", &column, &first);
19771 show (stream, "4100", &column, &first);
19772 show (stream, "4650", &column, &first);
19773 fputc ('\n', stream);
19775 fprintf (stream, _("\
19776 -mips16 generate mips16 instructions\n\
19777 -no-mips16 do not generate mips16 instructions\n"));
19778 fprintf (stream, _("\
19779 -mmicromips generate microMIPS instructions\n\
19780 -mno-micromips do not generate microMIPS instructions\n"));
19781 fprintf (stream, _("\
19782 -msmartmips generate smartmips instructions\n\
19783 -mno-smartmips do not generate smartmips instructions\n"));
19784 fprintf (stream, _("\
19785 -mdsp generate DSP instructions\n\
19786 -mno-dsp do not generate DSP instructions\n"));
19787 fprintf (stream, _("\
19788 -mdspr2 generate DSP R2 instructions\n\
19789 -mno-dspr2 do not generate DSP R2 instructions\n"));
19790 fprintf (stream, _("\
19791 -mmt generate MT instructions\n\
19792 -mno-mt do not generate MT instructions\n"));
19793 fprintf (stream, _("\
19794 -mmcu generate MCU instructions\n\
19795 -mno-mcu do not generate MCU instructions\n"));
19796 fprintf (stream, _("\
19797 -mvirt generate Virtualization instructions\n\
19798 -mno-virt do not generate Virtualization instructions\n"));
19799 fprintf (stream, _("\
19800 -mfix-loongson2f-jump work around Loongson2F JUMP instructions\n\
19801 -mfix-loongson2f-nop work around Loongson2F NOP errata\n\
19802 -mfix-vr4120 work around certain VR4120 errata\n\
19803 -mfix-vr4130 work around VR4130 mflo/mfhi errata\n\
19804 -mfix-24k insert a nop after ERET and DERET instructions\n\
19805 -mfix-cn63xxp1 work around CN63XXP1 PREF errata\n\
19806 -mgp32 use 32-bit GPRs, regardless of the chosen ISA\n\
19807 -mfp32 use 32-bit FPRs, regardless of the chosen ISA\n\
19808 -msym32 assume all symbols have 32-bit values\n\
19809 -O0 remove unneeded NOPs, do not swap branches\n\
19810 -O remove unneeded NOPs and swap branches\n\
19811 --trap, --no-break trap exception on div by 0 and mult overflow\n\
19812 --break, --no-trap break exception on div by 0 and mult overflow\n"));
19813 fprintf (stream, _("\
19814 -mhard-float allow floating-point instructions\n\
19815 -msoft-float do not allow floating-point instructions\n\
19816 -msingle-float only allow 32-bit floating-point operations\n\
19817 -mdouble-float allow 32-bit and 64-bit floating-point operations\n\
19818 --[no-]construct-floats [dis]allow floating point values to be constructed\n\
19819 --[no-]relax-branch [dis]allow out-of-range branches to be relaxed\n"
19822 fprintf (stream, _("\
19823 -KPIC, -call_shared generate SVR4 position independent code\n\
19824 -call_nonpic generate non-PIC code that can operate with DSOs\n\
19825 -mvxworks-pic generate VxWorks position independent code\n\
19826 -non_shared do not generate code that can operate with DSOs\n\
19827 -xgot assume a 32 bit GOT\n\
19828 -mpdr, -mno-pdr enable/disable creation of .pdr sections\n\
19829 -mshared, -mno-shared disable/enable .cpload optimization for\n\
19830 position dependent (non shared) code\n\
19831 -mabi=ABI create ABI conformant object file for:\n"));
19835 show (stream, "32", &column, &first);
19836 show (stream, "o64", &column, &first);
19837 show (stream, "n32", &column, &first);
19838 show (stream, "64", &column, &first);
19839 show (stream, "eabi", &column, &first);
19841 fputc ('\n', stream);
19843 fprintf (stream, _("\
19844 -32 create o32 ABI object file (default)\n\
19845 -n32 create n32 ABI object file\n\
19846 -64 create 64 ABI object file\n"));
19852 mips_dwarf2_format (asection *sec ATTRIBUTE_UNUSED)
19854 if (HAVE_64BIT_SYMBOLS)
19855 return dwarf2_format_64bit_irix;
19857 return dwarf2_format_32bit;
19862 mips_dwarf2_addr_size (void)
19864 if (HAVE_64BIT_OBJECTS)
19870 /* Standard calling conventions leave the CFA at SP on entry. */
19872 mips_cfi_frame_initial_instructions (void)
19874 cfi_add_CFA_def_cfa_register (SP);
19878 tc_mips_regname_to_dw2regnum (char *regname)
19880 unsigned int regnum = -1;
19883 if (reg_lookup (®name, RTYPE_GP | RTYPE_NUM, ®))