1 /* tc-mips.c -- assemble code for a MIPS chip.
2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
4 Free Software Foundation, Inc.
5 Contributed by the OSF and Ralph Campbell.
6 Written by Keith Knowles and Ralph Campbell, working independently.
7 Modified for ECOFF and R4000 support by Ian Lance Taylor of Cygnus
10 This file is part of GAS.
12 GAS is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 3, or (at your option)
17 GAS is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with GAS; see the file COPYING. If not, write to the Free
24 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
30 #include "safe-ctype.h"
32 #include "opcode/mips.h"
34 #include "dwarf2dbg.h"
35 #include "dw2gencfi.h"
38 #define DBG(x) printf x
44 /* Clean up namespace so we can include obj-elf.h too. */
45 static int mips_output_flavor (void);
46 static int mips_output_flavor (void) { return OUTPUT_FLAVOR; }
47 #undef OBJ_PROCESS_STAB
54 #undef obj_frob_file_after_relocs
55 #undef obj_frob_symbol
57 #undef obj_sec_sym_ok_for_reloc
58 #undef OBJ_COPY_SYMBOL_ATTRIBUTES
61 /* Fix any of them that we actually care about. */
63 #define OUTPUT_FLAVOR mips_output_flavor()
70 #ifndef ECOFF_DEBUGGING
71 #define NO_ECOFF_DEBUGGING
72 #define ECOFF_DEBUGGING 0
75 int mips_flag_mdebug = -1;
77 /* Control generation of .pdr sections. Off by default on IRIX: the native
78 linker doesn't know about and discards them, but relocations against them
79 remain, leading to rld crashes. */
81 int mips_flag_pdr = FALSE;
83 int mips_flag_pdr = TRUE;
88 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
89 static char *mips_regmask_frag;
97 #define PIC_CALL_REG 25
105 #define ILLEGAL_REG (32)
107 #define AT mips_opts.at
109 /* Allow override of standard little-endian ECOFF format. */
111 #ifndef ECOFF_LITTLE_FORMAT
112 #define ECOFF_LITTLE_FORMAT "ecoff-littlemips"
115 extern int target_big_endian;
117 /* The name of the readonly data section. */
118 #define RDATA_SECTION_NAME (OUTPUT_FLAVOR == bfd_target_ecoff_flavour \
120 : OUTPUT_FLAVOR == bfd_target_coff_flavour \
122 : OUTPUT_FLAVOR == bfd_target_elf_flavour \
126 /* Ways in which an instruction can be "appended" to the output. */
128 /* Just add it normally. */
131 /* Add it normally and then add a nop. */
134 /* Turn an instruction with a delay slot into a "compact" version. */
137 /* Insert the instruction before the last one. */
141 /* Information about an instruction, including its format, operands
145 /* The opcode's entry in mips_opcodes or mips16_opcodes. */
146 const struct mips_opcode *insn_mo;
148 /* True if this is a mips16 instruction and if we want the extended
150 bfd_boolean use_extend;
152 /* The 16-bit extension instruction to use when USE_EXTEND is true. */
153 unsigned short extend;
155 /* The 16-bit or 32-bit bitstring of the instruction itself. This is
156 a copy of INSN_MO->match with the operands filled in. */
157 unsigned long insn_opcode;
159 /* The frag that contains the instruction. */
162 /* The offset into FRAG of the first instruction byte. */
165 /* The relocs associated with the instruction, if any. */
168 /* True if this entry cannot be moved from its current position. */
169 unsigned int fixed_p : 1;
171 /* True if this instruction occurred in a .set noreorder block. */
172 unsigned int noreorder_p : 1;
174 /* True for mips16 instructions that jump to an absolute address. */
175 unsigned int mips16_absolute_jump_p : 1;
177 /* True if this instruction is complete. */
178 unsigned int complete_p : 1;
181 /* The ABI to use. */
192 /* MIPS ABI we are using for this output file. */
193 static enum mips_abi_level mips_abi = NO_ABI;
195 /* Whether or not we have code that can call pic code. */
196 int mips_abicalls = FALSE;
198 /* Whether or not we have code which can be put into a shared
200 static bfd_boolean mips_in_shared = TRUE;
202 /* This is the set of options which may be modified by the .set
203 pseudo-op. We use a struct so that .set push and .set pop are more
206 struct mips_set_options
208 /* MIPS ISA (Instruction Set Architecture) level. This is set to -1
209 if it has not been initialized. Changed by `.set mipsN', and the
210 -mipsN command line option, and the default CPU. */
212 /* Enabled Application Specific Extensions (ASEs). These are set to -1
213 if they have not been initialized. Changed by `.set <asename>', by
214 command line options, and based on the default architecture. */
222 /* Whether we are assembling for the mips16 processor. 0 if we are
223 not, 1 if we are, and -1 if the value has not been initialized.
224 Changed by `.set mips16' and `.set nomips16', and the -mips16 and
225 -nomips16 command line options, and the default CPU. */
227 /* Whether we are assembling for the mipsMIPS ASE. 0 if we are not,
228 1 if we are, and -1 if the value has not been initialized. Changed
229 by `.set micromips' and `.set nomicromips', and the -mmicromips
230 and -mno-micromips command line options, and the default CPU. */
232 /* Non-zero if we should not reorder instructions. Changed by `.set
233 reorder' and `.set noreorder'. */
235 /* Non-zero if we should not permit the register designated "assembler
236 temporary" to be used in instructions. The value is the register
237 number, normally $at ($1). Changed by `.set at=REG', `.set noat'
238 (same as `.set at=$0') and `.set at' (same as `.set at=$1'). */
240 /* Non-zero if we should warn when a macro instruction expands into
241 more than one machine instruction. Changed by `.set nomacro' and
243 int warn_about_macros;
244 /* Non-zero if we should not move instructions. Changed by `.set
245 move', `.set volatile', `.set nomove', and `.set novolatile'. */
247 /* Non-zero if we should not optimize branches by moving the target
248 of the branch into the delay slot. Actually, we don't perform
249 this optimization anyhow. Changed by `.set bopt' and `.set
252 /* Non-zero if we should not autoextend mips16 instructions.
253 Changed by `.set autoextend' and `.set noautoextend'. */
255 /* Restrict general purpose registers and floating point registers
256 to 32 bit. This is initially determined when -mgp32 or -mfp32
257 is passed but can changed if the assembler code uses .set mipsN. */
260 /* MIPS architecture (CPU) type. Changed by .set arch=FOO, the -march
261 command line option, and the default CPU. */
263 /* True if ".set sym32" is in effect. */
265 /* True if floating-point operations are not allowed. Changed by .set
266 softfloat or .set hardfloat, by command line options -msoft-float or
267 -mhard-float. The default is false. */
268 bfd_boolean soft_float;
270 /* True if only single-precision floating-point operations are allowed.
271 Changed by .set singlefloat or .set doublefloat, command-line options
272 -msingle-float or -mdouble-float. The default is false. */
273 bfd_boolean single_float;
276 /* This is the struct we use to hold the current set of options. Note
277 that we must set the isa field to ISA_UNKNOWN and the ASE fields to
278 -1 to indicate that they have not been initialized. */
280 /* True if -mgp32 was passed. */
281 static int file_mips_gp32 = -1;
283 /* True if -mfp32 was passed. */
284 static int file_mips_fp32 = -1;
286 /* 1 if -msoft-float, 0 if -mhard-float. The default is 0. */
287 static int file_mips_soft_float = 0;
289 /* 1 if -msingle-float, 0 if -mdouble-float. The default is 0. */
290 static int file_mips_single_float = 0;
292 static struct mips_set_options mips_opts =
294 /* isa */ ISA_UNKNOWN, /* ase_mips3d */ -1, /* ase_mdmx */ -1,
295 /* ase_smartmips */ 0, /* ase_dsp */ -1, /* ase_dspr2 */ -1, /* ase_mt */ -1,
296 /* ase_mcu */ -1, /* mips16 */ -1, /* micromips */ -1, /* noreorder */ 0,
297 /* at */ ATREG, /* warn_about_macros */ 0, /* nomove */ 0, /* nobopt */ 0,
298 /* noautoextend */ 0, /* gp32 */ 0, /* fp32 */ 0, /* arch */ CPU_UNKNOWN,
299 /* sym32 */ FALSE, /* soft_float */ FALSE, /* single_float */ FALSE
302 /* These variables are filled in with the masks of registers used.
303 The object format code reads them and puts them in the appropriate
305 unsigned long mips_gprmask;
306 unsigned long mips_cprmask[4];
308 /* MIPS ISA we are using for this output file. */
309 static int file_mips_isa = ISA_UNKNOWN;
311 /* True if any MIPS16 code was produced. */
312 static int file_ase_mips16;
314 #define ISA_SUPPORTS_MIPS16E (mips_opts.isa == ISA_MIPS32 \
315 || mips_opts.isa == ISA_MIPS32R2 \
316 || mips_opts.isa == ISA_MIPS64 \
317 || mips_opts.isa == ISA_MIPS64R2)
319 /* True if any microMIPS code was produced. */
320 static int file_ase_micromips;
322 /* True if we want to create R_MIPS_JALR for jalr $25. */
324 #define MIPS_JALR_HINT_P(EXPR) HAVE_NEWABI
326 /* As a GNU extension, we use R_MIPS_JALR for o32 too. However,
327 because there's no place for any addend, the only acceptable
328 expression is a bare symbol. */
329 #define MIPS_JALR_HINT_P(EXPR) \
330 (!HAVE_IN_PLACE_ADDENDS \
331 || ((EXPR)->X_op == O_symbol && (EXPR)->X_add_number == 0))
334 /* True if -mips3d was passed or implied by arguments passed on the
335 command line (e.g., by -march). */
336 static int file_ase_mips3d;
338 /* True if -mdmx was passed or implied by arguments passed on the
339 command line (e.g., by -march). */
340 static int file_ase_mdmx;
342 /* True if -msmartmips was passed or implied by arguments passed on the
343 command line (e.g., by -march). */
344 static int file_ase_smartmips;
346 #define ISA_SUPPORTS_SMARTMIPS (mips_opts.isa == ISA_MIPS32 \
347 || mips_opts.isa == ISA_MIPS32R2)
349 /* True if -mdsp was passed or implied by arguments passed on the
350 command line (e.g., by -march). */
351 static int file_ase_dsp;
353 #define ISA_SUPPORTS_DSP_ASE (mips_opts.isa == ISA_MIPS32R2 \
354 || mips_opts.isa == ISA_MIPS64R2)
356 #define ISA_SUPPORTS_DSP64_ASE (mips_opts.isa == ISA_MIPS64R2)
358 /* True if -mdspr2 was passed or implied by arguments passed on the
359 command line (e.g., by -march). */
360 static int file_ase_dspr2;
362 #define ISA_SUPPORTS_DSPR2_ASE (mips_opts.isa == ISA_MIPS32R2 \
363 || mips_opts.isa == ISA_MIPS64R2)
365 /* True if -mmt was passed or implied by arguments passed on the
366 command line (e.g., by -march). */
367 static int file_ase_mt;
369 #define ISA_SUPPORTS_MT_ASE (mips_opts.isa == ISA_MIPS32R2 \
370 || mips_opts.isa == ISA_MIPS64R2)
372 #define ISA_SUPPORTS_MCU_ASE (mips_opts.isa == ISA_MIPS32R2 \
373 || mips_opts.isa == ISA_MIPS64R2 \
374 || mips_opts.micromips)
376 /* The argument of the -march= flag. The architecture we are assembling. */
377 static int file_mips_arch = CPU_UNKNOWN;
378 static const char *mips_arch_string;
380 /* The argument of the -mtune= flag. The architecture for which we
382 static int mips_tune = CPU_UNKNOWN;
383 static const char *mips_tune_string;
385 /* True when generating 32-bit code for a 64-bit processor. */
386 static int mips_32bitmode = 0;
388 /* True if the given ABI requires 32-bit registers. */
389 #define ABI_NEEDS_32BIT_REGS(ABI) ((ABI) == O32_ABI)
391 /* Likewise 64-bit registers. */
392 #define ABI_NEEDS_64BIT_REGS(ABI) \
394 || (ABI) == N64_ABI \
397 /* Return true if ISA supports 64 bit wide gp registers. */
398 #define ISA_HAS_64BIT_REGS(ISA) \
399 ((ISA) == ISA_MIPS3 \
400 || (ISA) == ISA_MIPS4 \
401 || (ISA) == ISA_MIPS5 \
402 || (ISA) == ISA_MIPS64 \
403 || (ISA) == ISA_MIPS64R2)
405 /* Return true if ISA supports 64 bit wide float registers. */
406 #define ISA_HAS_64BIT_FPRS(ISA) \
407 ((ISA) == ISA_MIPS3 \
408 || (ISA) == ISA_MIPS4 \
409 || (ISA) == ISA_MIPS5 \
410 || (ISA) == ISA_MIPS32R2 \
411 || (ISA) == ISA_MIPS64 \
412 || (ISA) == ISA_MIPS64R2)
414 /* Return true if ISA supports 64-bit right rotate (dror et al.)
416 #define ISA_HAS_DROR(ISA) \
417 ((ISA) == ISA_MIPS64R2 \
418 || (mips_opts.micromips \
419 && ISA_HAS_64BIT_REGS (ISA)) \
422 /* Return true if ISA supports 32-bit right rotate (ror et al.)
424 #define ISA_HAS_ROR(ISA) \
425 ((ISA) == ISA_MIPS32R2 \
426 || (ISA) == ISA_MIPS64R2 \
427 || mips_opts.ase_smartmips \
428 || mips_opts.micromips \
431 /* Return true if ISA supports single-precision floats in odd registers. */
432 #define ISA_HAS_ODD_SINGLE_FPR(ISA) \
433 ((ISA) == ISA_MIPS32 \
434 || (ISA) == ISA_MIPS32R2 \
435 || (ISA) == ISA_MIPS64 \
436 || (ISA) == ISA_MIPS64R2)
438 /* Return true if ISA supports move to/from high part of a 64-bit
439 floating-point register. */
440 #define ISA_HAS_MXHC1(ISA) \
441 ((ISA) == ISA_MIPS32R2 \
442 || (ISA) == ISA_MIPS64R2)
444 #define HAVE_32BIT_GPRS \
445 (mips_opts.gp32 || !ISA_HAS_64BIT_REGS (mips_opts.isa))
447 #define HAVE_32BIT_FPRS \
448 (mips_opts.fp32 || !ISA_HAS_64BIT_FPRS (mips_opts.isa))
450 #define HAVE_64BIT_GPRS (!HAVE_32BIT_GPRS)
451 #define HAVE_64BIT_FPRS (!HAVE_32BIT_FPRS)
453 #define HAVE_NEWABI (mips_abi == N32_ABI || mips_abi == N64_ABI)
455 #define HAVE_64BIT_OBJECTS (mips_abi == N64_ABI)
457 /* True if relocations are stored in-place. */
458 #define HAVE_IN_PLACE_ADDENDS (!HAVE_NEWABI)
460 /* The ABI-derived address size. */
461 #define HAVE_64BIT_ADDRESSES \
462 (HAVE_64BIT_GPRS && (mips_abi == EABI_ABI || mips_abi == N64_ABI))
463 #define HAVE_32BIT_ADDRESSES (!HAVE_64BIT_ADDRESSES)
465 /* The size of symbolic constants (i.e., expressions of the form
466 "SYMBOL" or "SYMBOL + OFFSET"). */
467 #define HAVE_32BIT_SYMBOLS \
468 (HAVE_32BIT_ADDRESSES || !HAVE_64BIT_OBJECTS || mips_opts.sym32)
469 #define HAVE_64BIT_SYMBOLS (!HAVE_32BIT_SYMBOLS)
471 /* Addresses are loaded in different ways, depending on the address size
472 in use. The n32 ABI Documentation also mandates the use of additions
473 with overflow checking, but existing implementations don't follow it. */
474 #define ADDRESS_ADD_INSN \
475 (HAVE_32BIT_ADDRESSES ? "addu" : "daddu")
477 #define ADDRESS_ADDI_INSN \
478 (HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu")
480 #define ADDRESS_LOAD_INSN \
481 (HAVE_32BIT_ADDRESSES ? "lw" : "ld")
483 #define ADDRESS_STORE_INSN \
484 (HAVE_32BIT_ADDRESSES ? "sw" : "sd")
486 /* Return true if the given CPU supports the MIPS16 ASE. */
487 #define CPU_HAS_MIPS16(cpu) \
488 (strncmp (TARGET_CPU, "mips16", sizeof ("mips16") - 1) == 0 \
489 || strncmp (TARGET_CANONICAL, "mips-lsi-elf", sizeof ("mips-lsi-elf") - 1) == 0)
491 /* Return true if the given CPU supports the microMIPS ASE. */
492 #define CPU_HAS_MICROMIPS(cpu) 0
494 /* True if CPU has a dror instruction. */
495 #define CPU_HAS_DROR(CPU) ((CPU) == CPU_VR5400 || (CPU) == CPU_VR5500)
497 /* True if CPU has a ror instruction. */
498 #define CPU_HAS_ROR(CPU) CPU_HAS_DROR (CPU)
500 /* True if CPU has seq/sne and seqi/snei instructions. */
501 #define CPU_HAS_SEQ(CPU) ((CPU) == CPU_OCTEON)
503 /* True if CPU does not implement the all the coprocessor insns. For these
504 CPUs only those COP insns are accepted that are explicitly marked to be
505 available on the CPU. ISA membership for COP insns is ignored. */
506 #define NO_ISA_COP(CPU) ((CPU) == CPU_OCTEON)
508 /* True if mflo and mfhi can be immediately followed by instructions
509 which write to the HI and LO registers.
511 According to MIPS specifications, MIPS ISAs I, II, and III need
512 (at least) two instructions between the reads of HI/LO and
513 instructions which write them, and later ISAs do not. Contradicting
514 the MIPS specifications, some MIPS IV processor user manuals (e.g.
515 the UM for the NEC Vr5000) document needing the instructions between
516 HI/LO reads and writes, as well. Therefore, we declare only MIPS32,
517 MIPS64 and later ISAs to have the interlocks, plus any specific
518 earlier-ISA CPUs for which CPU documentation declares that the
519 instructions are really interlocked. */
520 #define hilo_interlocks \
521 (mips_opts.isa == ISA_MIPS32 \
522 || mips_opts.isa == ISA_MIPS32R2 \
523 || mips_opts.isa == ISA_MIPS64 \
524 || mips_opts.isa == ISA_MIPS64R2 \
525 || mips_opts.arch == CPU_R4010 \
526 || mips_opts.arch == CPU_R10000 \
527 || mips_opts.arch == CPU_R12000 \
528 || mips_opts.arch == CPU_R14000 \
529 || mips_opts.arch == CPU_R16000 \
530 || mips_opts.arch == CPU_RM7000 \
531 || mips_opts.arch == CPU_VR5500 \
532 || mips_opts.micromips \
535 /* Whether the processor uses hardware interlocks to protect reads
536 from the GPRs after they are loaded from memory, and thus does not
537 require nops to be inserted. This applies to instructions marked
538 INSN_LOAD_MEMORY_DELAY. These nops are only required at MIPS ISA
539 level I and microMIPS mode instructions are always interlocked. */
540 #define gpr_interlocks \
541 (mips_opts.isa != ISA_MIPS1 \
542 || mips_opts.arch == CPU_R3900 \
543 || mips_opts.micromips \
546 /* Whether the processor uses hardware interlocks to avoid delays
547 required by coprocessor instructions, and thus does not require
548 nops to be inserted. This applies to instructions marked
549 INSN_LOAD_COPROC_DELAY, INSN_COPROC_MOVE_DELAY, and to delays
550 between instructions marked INSN_WRITE_COND_CODE and ones marked
551 INSN_READ_COND_CODE. These nops are only required at MIPS ISA
552 levels I, II, and III and microMIPS mode instructions are always
554 /* Itbl support may require additional care here. */
555 #define cop_interlocks \
556 ((mips_opts.isa != ISA_MIPS1 \
557 && mips_opts.isa != ISA_MIPS2 \
558 && mips_opts.isa != ISA_MIPS3) \
559 || mips_opts.arch == CPU_R4300 \
560 || mips_opts.micromips \
563 /* Whether the processor uses hardware interlocks to protect reads
564 from coprocessor registers after they are loaded from memory, and
565 thus does not require nops to be inserted. This applies to
566 instructions marked INSN_COPROC_MEMORY_DELAY. These nops are only
567 requires at MIPS ISA level I and microMIPS mode instructions are
568 always interlocked. */
569 #define cop_mem_interlocks \
570 (mips_opts.isa != ISA_MIPS1 \
571 || mips_opts.micromips \
574 /* Is this a mfhi or mflo instruction? */
575 #define MF_HILO_INSN(PINFO) \
576 ((PINFO & INSN_READ_HI) || (PINFO & INSN_READ_LO))
578 /* Returns true for a (non floating-point) coprocessor instruction. Reading
579 or writing the condition code is only possible on the coprocessors and
580 these insns are not marked with INSN_COP. Thus for these insns use the
581 condition-code flags. */
582 #define COP_INSN(PINFO) \
583 (PINFO != INSN_MACRO \
584 && ((PINFO) & (FP_S | FP_D)) == 0 \
585 && ((PINFO) & (INSN_COP | INSN_READ_COND_CODE | INSN_WRITE_COND_CODE)))
587 /* Whether code compression (either of the MIPS16 or the microMIPS ASEs)
588 has been selected. This implies, in particular, that addresses of text
589 labels have their LSB set. */
590 #define HAVE_CODE_COMPRESSION \
591 ((mips_opts.mips16 | mips_opts.micromips) != 0)
593 /* MIPS PIC level. */
595 enum mips_pic_level mips_pic;
597 /* 1 if we should generate 32 bit offsets from the $gp register in
598 SVR4_PIC mode. Currently has no meaning in other modes. */
599 static int mips_big_got = 0;
601 /* 1 if trap instructions should used for overflow rather than break
603 static int mips_trap = 0;
605 /* 1 if double width floating point constants should not be constructed
606 by assembling two single width halves into two single width floating
607 point registers which just happen to alias the double width destination
608 register. On some architectures this aliasing can be disabled by a bit
609 in the status register, and the setting of this bit cannot be determined
610 automatically at assemble time. */
611 static int mips_disable_float_construction;
613 /* Non-zero if any .set noreorder directives were used. */
615 static int mips_any_noreorder;
617 /* Non-zero if nops should be inserted when the register referenced in
618 an mfhi/mflo instruction is read in the next two instructions. */
619 static int mips_7000_hilo_fix;
621 /* The size of objects in the small data section. */
622 static unsigned int g_switch_value = 8;
623 /* Whether the -G option was used. */
624 static int g_switch_seen = 0;
629 /* If we can determine in advance that GP optimization won't be
630 possible, we can skip the relaxation stuff that tries to produce
631 GP-relative references. This makes delay slot optimization work
634 This function can only provide a guess, but it seems to work for
635 gcc output. It needs to guess right for gcc, otherwise gcc
636 will put what it thinks is a GP-relative instruction in a branch
639 I don't know if a fix is needed for the SVR4_PIC mode. I've only
640 fixed it for the non-PIC mode. KR 95/04/07 */
641 static int nopic_need_relax (symbolS *, int);
643 /* handle of the OPCODE hash table */
644 static struct hash_control *op_hash = NULL;
646 /* The opcode hash table we use for the mips16. */
647 static struct hash_control *mips16_op_hash = NULL;
649 /* The opcode hash table we use for the microMIPS ASE. */
650 static struct hash_control *micromips_op_hash = NULL;
652 /* This array holds the chars that always start a comment. If the
653 pre-processor is disabled, these aren't very useful */
654 const char comment_chars[] = "#";
656 /* This array holds the chars that only start a comment at the beginning of
657 a line. If the line seems to have the form '# 123 filename'
658 .line and .file directives will appear in the pre-processed output */
659 /* Note that input_file.c hand checks for '#' at the beginning of the
660 first line of the input file. This is because the compiler outputs
661 #NO_APP at the beginning of its output. */
662 /* Also note that C style comments are always supported. */
663 const char line_comment_chars[] = "#";
665 /* This array holds machine specific line separator characters. */
666 const char line_separator_chars[] = ";";
668 /* Chars that can be used to separate mant from exp in floating point nums */
669 const char EXP_CHARS[] = "eE";
671 /* Chars that mean this number is a floating point constant */
674 const char FLT_CHARS[] = "rRsSfFdDxXpP";
676 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
677 changed in read.c . Ideally it shouldn't have to know about it at all,
678 but nothing is ideal around here.
681 static char *insn_error;
683 static int auto_align = 1;
685 /* When outputting SVR4 PIC code, the assembler needs to know the
686 offset in the stack frame from which to restore the $gp register.
687 This is set by the .cprestore pseudo-op, and saved in this
689 static offsetT mips_cprestore_offset = -1;
691 /* Similar for NewABI PIC code, where $gp is callee-saved. NewABI has some
692 more optimizations, it can use a register value instead of a memory-saved
693 offset and even an other register than $gp as global pointer. */
694 static offsetT mips_cpreturn_offset = -1;
695 static int mips_cpreturn_register = -1;
696 static int mips_gp_register = GP;
697 static int mips_gprel_offset = 0;
699 /* Whether mips_cprestore_offset has been set in the current function
700 (or whether it has already been warned about, if not). */
701 static int mips_cprestore_valid = 0;
703 /* This is the register which holds the stack frame, as set by the
704 .frame pseudo-op. This is needed to implement .cprestore. */
705 static int mips_frame_reg = SP;
707 /* Whether mips_frame_reg has been set in the current function
708 (or whether it has already been warned about, if not). */
709 static int mips_frame_reg_valid = 0;
711 /* To output NOP instructions correctly, we need to keep information
712 about the previous two instructions. */
714 /* Whether we are optimizing. The default value of 2 means to remove
715 unneeded NOPs and swap branch instructions when possible. A value
716 of 1 means to not swap branches. A value of 0 means to always
718 static int mips_optimize = 2;
720 /* Debugging level. -g sets this to 2. -gN sets this to N. -g0 is
721 equivalent to seeing no -g option at all. */
722 static int mips_debug = 0;
724 /* The maximum number of NOPs needed to avoid the VR4130 mflo/mfhi errata. */
725 #define MAX_VR4130_NOPS 4
727 /* The maximum number of NOPs needed to fill delay slots. */
728 #define MAX_DELAY_NOPS 2
730 /* The maximum number of NOPs needed for any purpose. */
733 /* A list of previous instructions, with index 0 being the most recent.
734 We need to look back MAX_NOPS instructions when filling delay slots
735 or working around processor errata. We need to look back one
736 instruction further if we're thinking about using history[0] to
737 fill a branch delay slot. */
738 static struct mips_cl_insn history[1 + MAX_NOPS];
740 /* Nop instructions used by emit_nop. */
741 static struct mips_cl_insn nop_insn;
742 static struct mips_cl_insn mips16_nop_insn;
743 static struct mips_cl_insn micromips_nop16_insn;
744 static struct mips_cl_insn micromips_nop32_insn;
746 /* The appropriate nop for the current mode. */
747 #define NOP_INSN (mips_opts.mips16 ? &mips16_nop_insn \
748 : (mips_opts.micromips ? µmips_nop16_insn : &nop_insn))
750 /* The size of NOP_INSN in bytes. */
751 #define NOP_INSN_SIZE (HAVE_CODE_COMPRESSION ? 2 : 4)
753 /* If this is set, it points to a frag holding nop instructions which
754 were inserted before the start of a noreorder section. If those
755 nops turn out to be unnecessary, the size of the frag can be
757 static fragS *prev_nop_frag;
759 /* The number of nop instructions we created in prev_nop_frag. */
760 static int prev_nop_frag_holds;
762 /* The number of nop instructions that we know we need in
764 static int prev_nop_frag_required;
766 /* The number of instructions we've seen since prev_nop_frag. */
767 static int prev_nop_frag_since;
769 /* For ECOFF and ELF, relocations against symbols are done in two
770 parts, with a HI relocation and a LO relocation. Each relocation
771 has only 16 bits of space to store an addend. This means that in
772 order for the linker to handle carries correctly, it must be able
773 to locate both the HI and the LO relocation. This means that the
774 relocations must appear in order in the relocation table.
776 In order to implement this, we keep track of each unmatched HI
777 relocation. We then sort them so that they immediately precede the
778 corresponding LO relocation. */
783 struct mips_hi_fixup *next;
786 /* The section this fixup is in. */
790 /* The list of unmatched HI relocs. */
792 static struct mips_hi_fixup *mips_hi_fixup_list;
794 /* The frag containing the last explicit relocation operator.
795 Null if explicit relocations have not been used. */
797 static fragS *prev_reloc_op_frag;
799 /* Map normal MIPS register numbers to mips16 register numbers. */
801 #define X ILLEGAL_REG
802 static const int mips32_to_16_reg_map[] =
804 X, X, 2, 3, 4, 5, 6, 7,
805 X, X, X, X, X, X, X, X,
806 0, 1, X, X, X, X, X, X,
807 X, X, X, X, X, X, X, X
811 /* Map mips16 register numbers to normal MIPS register numbers. */
813 static const unsigned int mips16_to_32_reg_map[] =
815 16, 17, 2, 3, 4, 5, 6, 7
818 /* Map normal MIPS register numbers to microMIPS register numbers. */
820 #define mips32_to_micromips_reg_b_map mips32_to_16_reg_map
821 #define mips32_to_micromips_reg_c_map mips32_to_16_reg_map
822 #define mips32_to_micromips_reg_d_map mips32_to_16_reg_map
823 #define mips32_to_micromips_reg_e_map mips32_to_16_reg_map
824 #define mips32_to_micromips_reg_f_map mips32_to_16_reg_map
825 #define mips32_to_micromips_reg_g_map mips32_to_16_reg_map
826 #define mips32_to_micromips_reg_l_map mips32_to_16_reg_map
828 #define X ILLEGAL_REG
829 /* reg type h: 4, 5, 6. */
830 static const int mips32_to_micromips_reg_h_map[] =
832 X, X, X, X, 4, 5, 6, X,
833 X, X, X, X, X, X, X, X,
834 X, X, X, X, X, X, X, X,
835 X, X, X, X, X, X, X, X
838 /* reg type m: 0, 17, 2, 3, 16, 18, 19, 20. */
839 static const int mips32_to_micromips_reg_m_map[] =
841 0, X, 2, 3, X, X, X, X,
842 X, X, X, X, X, X, X, X,
843 4, 1, 5, 6, 7, X, X, X,
844 X, X, X, X, X, X, X, X
847 /* reg type q: 0, 2-7. 17. */
848 static const int mips32_to_micromips_reg_q_map[] =
850 0, X, 2, 3, 4, 5, 6, 7,
851 X, X, X, X, X, X, X, X,
852 X, 1, X, X, X, X, X, X,
853 X, X, X, X, X, X, X, X
856 #define mips32_to_micromips_reg_n_map mips32_to_micromips_reg_m_map
859 /* Map microMIPS register numbers to normal MIPS register numbers. */
861 #define micromips_to_32_reg_b_map mips16_to_32_reg_map
862 #define micromips_to_32_reg_c_map mips16_to_32_reg_map
863 #define micromips_to_32_reg_d_map mips16_to_32_reg_map
864 #define micromips_to_32_reg_e_map mips16_to_32_reg_map
865 #define micromips_to_32_reg_f_map mips16_to_32_reg_map
866 #define micromips_to_32_reg_g_map mips16_to_32_reg_map
868 /* The microMIPS registers with type h. */
869 static const unsigned int micromips_to_32_reg_h_map[] =
871 5, 5, 6, 4, 4, 4, 4, 4
874 /* The microMIPS registers with type i. */
875 static const unsigned int micromips_to_32_reg_i_map[] =
877 6, 7, 7, 21, 22, 5, 6, 7
880 #define micromips_to_32_reg_l_map mips16_to_32_reg_map
882 /* The microMIPS registers with type m. */
883 static const unsigned int micromips_to_32_reg_m_map[] =
885 0, 17, 2, 3, 16, 18, 19, 20
888 #define micromips_to_32_reg_n_map micromips_to_32_reg_m_map
890 /* The microMIPS registers with type q. */
891 static const unsigned int micromips_to_32_reg_q_map[] =
893 0, 17, 2, 3, 4, 5, 6, 7
896 /* microMIPS imm type B. */
897 static const int micromips_imm_b_map[] =
899 1, 4, 8, 12, 16, 20, 24, -1
902 /* microMIPS imm type C. */
903 static const int micromips_imm_c_map[] =
905 128, 1, 2, 3, 4, 7, 8, 15, 16, 31, 32, 63, 64, 255, 32768, 65535
908 /* Classifies the kind of instructions we're interested in when
909 implementing -mfix-vr4120. */
910 enum fix_vr4120_class
918 NUM_FIX_VR4120_CLASSES
921 /* ...likewise -mfix-loongson2f-jump. */
922 static bfd_boolean mips_fix_loongson2f_jump;
924 /* ...likewise -mfix-loongson2f-nop. */
925 static bfd_boolean mips_fix_loongson2f_nop;
927 /* True if -mfix-loongson2f-nop or -mfix-loongson2f-jump passed. */
928 static bfd_boolean mips_fix_loongson2f;
930 /* Given two FIX_VR4120_* values X and Y, bit Y of element X is set if
931 there must be at least one other instruction between an instruction
932 of type X and an instruction of type Y. */
933 static unsigned int vr4120_conflicts[NUM_FIX_VR4120_CLASSES];
935 /* True if -mfix-vr4120 is in force. */
936 static int mips_fix_vr4120;
938 /* ...likewise -mfix-vr4130. */
939 static int mips_fix_vr4130;
941 /* ...likewise -mfix-24k. */
942 static int mips_fix_24k;
944 /* ...likewise -mfix-cn63xxp1 */
945 static bfd_boolean mips_fix_cn63xxp1;
947 /* We don't relax branches by default, since this causes us to expand
948 `la .l2 - .l1' if there's a branch between .l1 and .l2, because we
949 fail to compute the offset before expanding the macro to the most
950 efficient expansion. */
952 static int mips_relax_branch;
954 /* The expansion of many macros depends on the type of symbol that
955 they refer to. For example, when generating position-dependent code,
956 a macro that refers to a symbol may have two different expansions,
957 one which uses GP-relative addresses and one which uses absolute
958 addresses. When generating SVR4-style PIC, a macro may have
959 different expansions for local and global symbols.
961 We handle these situations by generating both sequences and putting
962 them in variant frags. In position-dependent code, the first sequence
963 will be the GP-relative one and the second sequence will be the
964 absolute one. In SVR4 PIC, the first sequence will be for global
965 symbols and the second will be for local symbols.
967 The frag's "subtype" is RELAX_ENCODE (FIRST, SECOND), where FIRST and
968 SECOND are the lengths of the two sequences in bytes. These fields
969 can be extracted using RELAX_FIRST() and RELAX_SECOND(). In addition,
970 the subtype has the following flags:
973 Set if it has been decided that we should use the second
974 sequence instead of the first.
977 Set in the first variant frag if the macro's second implementation
978 is longer than its first. This refers to the macro as a whole,
979 not an individual relaxation.
982 Set in the first variant frag if the macro appeared in a .set nomacro
983 block and if one alternative requires a warning but the other does not.
986 Like RELAX_NOMACRO, but indicates that the macro appears in a branch
989 RELAX_DELAY_SLOT_16BIT
990 Like RELAX_DELAY_SLOT, but indicates that the delay slot requires a
993 RELAX_DELAY_SLOT_SIZE_FIRST
994 Like RELAX_DELAY_SLOT, but indicates that the first implementation of
995 the macro is of the wrong size for the branch delay slot.
997 RELAX_DELAY_SLOT_SIZE_SECOND
998 Like RELAX_DELAY_SLOT, but indicates that the second implementation of
999 the macro is of the wrong size for the branch delay slot.
1001 The frag's "opcode" points to the first fixup for relaxable code.
1003 Relaxable macros are generated using a sequence such as:
1005 relax_start (SYMBOL);
1006 ... generate first expansion ...
1008 ... generate second expansion ...
1011 The code and fixups for the unwanted alternative are discarded
1012 by md_convert_frag. */
1013 #define RELAX_ENCODE(FIRST, SECOND) (((FIRST) << 8) | (SECOND))
1015 #define RELAX_FIRST(X) (((X) >> 8) & 0xff)
1016 #define RELAX_SECOND(X) ((X) & 0xff)
1017 #define RELAX_USE_SECOND 0x10000
1018 #define RELAX_SECOND_LONGER 0x20000
1019 #define RELAX_NOMACRO 0x40000
1020 #define RELAX_DELAY_SLOT 0x80000
1021 #define RELAX_DELAY_SLOT_16BIT 0x100000
1022 #define RELAX_DELAY_SLOT_SIZE_FIRST 0x200000
1023 #define RELAX_DELAY_SLOT_SIZE_SECOND 0x400000
1025 /* Branch without likely bit. If label is out of range, we turn:
1027 beq reg1, reg2, label
1037 with the following opcode replacements:
1044 bltzal <-> bgezal (with jal label instead of j label)
1046 Even though keeping the delay slot instruction in the delay slot of
1047 the branch would be more efficient, it would be very tricky to do
1048 correctly, because we'd have to introduce a variable frag *after*
1049 the delay slot instruction, and expand that instead. Let's do it
1050 the easy way for now, even if the branch-not-taken case now costs
1051 one additional instruction. Out-of-range branches are not supposed
1052 to be common, anyway.
1054 Branch likely. If label is out of range, we turn:
1056 beql reg1, reg2, label
1057 delay slot (annulled if branch not taken)
1066 delay slot (executed only if branch taken)
1069 It would be possible to generate a shorter sequence by losing the
1070 likely bit, generating something like:
1075 delay slot (executed only if branch taken)
1087 bltzall -> bgezal (with jal label instead of j label)
1088 bgezall -> bltzal (ditto)
1091 but it's not clear that it would actually improve performance. */
1092 #define RELAX_BRANCH_ENCODE(at, uncond, likely, link, toofar) \
1093 ((relax_substateT) \
1096 | ((toofar) ? 0x20 : 0) \
1097 | ((link) ? 0x40 : 0) \
1098 | ((likely) ? 0x80 : 0) \
1099 | ((uncond) ? 0x100 : 0)))
1100 #define RELAX_BRANCH_P(i) (((i) & 0xf0000000) == 0xc0000000)
1101 #define RELAX_BRANCH_UNCOND(i) (((i) & 0x100) != 0)
1102 #define RELAX_BRANCH_LIKELY(i) (((i) & 0x80) != 0)
1103 #define RELAX_BRANCH_LINK(i) (((i) & 0x40) != 0)
1104 #define RELAX_BRANCH_TOOFAR(i) (((i) & 0x20) != 0)
1105 #define RELAX_BRANCH_AT(i) ((i) & 0x1f)
1107 /* For mips16 code, we use an entirely different form of relaxation.
1108 mips16 supports two versions of most instructions which take
1109 immediate values: a small one which takes some small value, and a
1110 larger one which takes a 16 bit value. Since branches also follow
1111 this pattern, relaxing these values is required.
1113 We can assemble both mips16 and normal MIPS code in a single
1114 object. Therefore, we need to support this type of relaxation at
1115 the same time that we support the relaxation described above. We
1116 use the high bit of the subtype field to distinguish these cases.
1118 The information we store for this type of relaxation is the
1119 argument code found in the opcode file for this relocation, whether
1120 the user explicitly requested a small or extended form, and whether
1121 the relocation is in a jump or jal delay slot. That tells us the
1122 size of the value, and how it should be stored. We also store
1123 whether the fragment is considered to be extended or not. We also
1124 store whether this is known to be a branch to a different section,
1125 whether we have tried to relax this frag yet, and whether we have
1126 ever extended a PC relative fragment because of a shift count. */
1127 #define RELAX_MIPS16_ENCODE(type, small, ext, dslot, jal_dslot) \
1130 | ((small) ? 0x100 : 0) \
1131 | ((ext) ? 0x200 : 0) \
1132 | ((dslot) ? 0x400 : 0) \
1133 | ((jal_dslot) ? 0x800 : 0))
1134 #define RELAX_MIPS16_P(i) (((i) & 0xc0000000) == 0x80000000)
1135 #define RELAX_MIPS16_TYPE(i) ((i) & 0xff)
1136 #define RELAX_MIPS16_USER_SMALL(i) (((i) & 0x100) != 0)
1137 #define RELAX_MIPS16_USER_EXT(i) (((i) & 0x200) != 0)
1138 #define RELAX_MIPS16_DSLOT(i) (((i) & 0x400) != 0)
1139 #define RELAX_MIPS16_JAL_DSLOT(i) (((i) & 0x800) != 0)
1140 #define RELAX_MIPS16_EXTENDED(i) (((i) & 0x1000) != 0)
1141 #define RELAX_MIPS16_MARK_EXTENDED(i) ((i) | 0x1000)
1142 #define RELAX_MIPS16_CLEAR_EXTENDED(i) ((i) &~ 0x1000)
1143 #define RELAX_MIPS16_LONG_BRANCH(i) (((i) & 0x2000) != 0)
1144 #define RELAX_MIPS16_MARK_LONG_BRANCH(i) ((i) | 0x2000)
1145 #define RELAX_MIPS16_CLEAR_LONG_BRANCH(i) ((i) &~ 0x2000)
1147 /* For microMIPS code, we use relaxation similar to one we use for
1148 MIPS16 code. Some instructions that take immediate values support
1149 two encodings: a small one which takes some small value, and a
1150 larger one which takes a 16 bit value. As some branches also follow
1151 this pattern, relaxing these values is required.
1153 We can assemble both microMIPS and normal MIPS code in a single
1154 object. Therefore, we need to support this type of relaxation at
1155 the same time that we support the relaxation described above. We
1156 use one of the high bits of the subtype field to distinguish these
1159 The information we store for this type of relaxation is the argument
1160 code found in the opcode file for this relocation, the register
1161 selected as the assembler temporary, whether the branch is
1162 unconditional, whether it is compact, whether it stores the link
1163 address implicitly in $ra, whether relaxation of out-of-range 32-bit
1164 branches to a sequence of instructions is enabled, and whether the
1165 displacement of a branch is too large to fit as an immediate argument
1166 of a 16-bit and a 32-bit branch, respectively. */
1167 #define RELAX_MICROMIPS_ENCODE(type, at, uncond, compact, link, \
1168 relax32, toofar16, toofar32) \
1171 | (((at) & 0x1f) << 8) \
1172 | ((uncond) ? 0x2000 : 0) \
1173 | ((compact) ? 0x4000 : 0) \
1174 | ((link) ? 0x8000 : 0) \
1175 | ((relax32) ? 0x10000 : 0) \
1176 | ((toofar16) ? 0x20000 : 0) \
1177 | ((toofar32) ? 0x40000 : 0))
1178 #define RELAX_MICROMIPS_P(i) (((i) & 0xc0000000) == 0x40000000)
1179 #define RELAX_MICROMIPS_TYPE(i) ((i) & 0xff)
1180 #define RELAX_MICROMIPS_AT(i) (((i) >> 8) & 0x1f)
1181 #define RELAX_MICROMIPS_UNCOND(i) (((i) & 0x2000) != 0)
1182 #define RELAX_MICROMIPS_COMPACT(i) (((i) & 0x4000) != 0)
1183 #define RELAX_MICROMIPS_LINK(i) (((i) & 0x8000) != 0)
1184 #define RELAX_MICROMIPS_RELAX32(i) (((i) & 0x10000) != 0)
1186 #define RELAX_MICROMIPS_TOOFAR16(i) (((i) & 0x20000) != 0)
1187 #define RELAX_MICROMIPS_MARK_TOOFAR16(i) ((i) | 0x20000)
1188 #define RELAX_MICROMIPS_CLEAR_TOOFAR16(i) ((i) & ~0x20000)
1189 #define RELAX_MICROMIPS_TOOFAR32(i) (((i) & 0x40000) != 0)
1190 #define RELAX_MICROMIPS_MARK_TOOFAR32(i) ((i) | 0x40000)
1191 #define RELAX_MICROMIPS_CLEAR_TOOFAR32(i) ((i) & ~0x40000)
1193 /* Is the given value a sign-extended 32-bit value? */
1194 #define IS_SEXT_32BIT_NUM(x) \
1195 (((x) &~ (offsetT) 0x7fffffff) == 0 \
1196 || (((x) &~ (offsetT) 0x7fffffff) == ~ (offsetT) 0x7fffffff))
1198 /* Is the given value a sign-extended 16-bit value? */
1199 #define IS_SEXT_16BIT_NUM(x) \
1200 (((x) &~ (offsetT) 0x7fff) == 0 \
1201 || (((x) &~ (offsetT) 0x7fff) == ~ (offsetT) 0x7fff))
1203 /* Is the given value a sign-extended 12-bit value? */
1204 #define IS_SEXT_12BIT_NUM(x) \
1205 (((((x) & 0xfff) ^ 0x800LL) - 0x800LL) == (x))
1207 /* Is the given value a zero-extended 32-bit value? Or a negated one? */
1208 #define IS_ZEXT_32BIT_NUM(x) \
1209 (((x) &~ (offsetT) 0xffffffff) == 0 \
1210 || (((x) &~ (offsetT) 0xffffffff) == ~ (offsetT) 0xffffffff))
1212 /* Replace bits MASK << SHIFT of STRUCT with the equivalent bits in
1213 VALUE << SHIFT. VALUE is evaluated exactly once. */
1214 #define INSERT_BITS(STRUCT, VALUE, MASK, SHIFT) \
1215 (STRUCT) = (((STRUCT) & ~((MASK) << (SHIFT))) \
1216 | (((VALUE) & (MASK)) << (SHIFT)))
1218 /* Extract bits MASK << SHIFT from STRUCT and shift them right
1220 #define EXTRACT_BITS(STRUCT, MASK, SHIFT) \
1221 (((STRUCT) >> (SHIFT)) & (MASK))
1223 /* Change INSN's opcode so that the operand given by FIELD has value VALUE.
1224 INSN is a mips_cl_insn structure and VALUE is evaluated exactly once.
1226 include/opcode/mips.h specifies operand fields using the macros
1227 OP_MASK_<FIELD> and OP_SH_<FIELD>. The MIPS16 equivalents start
1228 with "MIPS16OP" instead of "OP". */
1229 #define INSERT_OPERAND(MICROMIPS, FIELD, INSN, VALUE) \
1232 INSERT_BITS ((INSN).insn_opcode, VALUE, \
1233 OP_MASK_##FIELD, OP_SH_##FIELD); \
1235 INSERT_BITS ((INSN).insn_opcode, VALUE, \
1236 MICROMIPSOP_MASK_##FIELD, MICROMIPSOP_SH_##FIELD); \
1238 #define MIPS16_INSERT_OPERAND(FIELD, INSN, VALUE) \
1239 INSERT_BITS ((INSN).insn_opcode, VALUE, \
1240 MIPS16OP_MASK_##FIELD, MIPS16OP_SH_##FIELD)
1242 /* Extract the operand given by FIELD from mips_cl_insn INSN. */
1243 #define EXTRACT_OPERAND(MICROMIPS, FIELD, INSN) \
1245 ? EXTRACT_BITS ((INSN).insn_opcode, OP_MASK_##FIELD, OP_SH_##FIELD) \
1246 : EXTRACT_BITS ((INSN).insn_opcode, \
1247 MICROMIPSOP_MASK_##FIELD, MICROMIPSOP_SH_##FIELD))
1248 #define MIPS16_EXTRACT_OPERAND(FIELD, INSN) \
1249 EXTRACT_BITS ((INSN).insn_opcode, \
1250 MIPS16OP_MASK_##FIELD, \
1251 MIPS16OP_SH_##FIELD)
1253 /* Whether or not we are emitting a branch-likely macro. */
1254 static bfd_boolean emit_branch_likely_macro = FALSE;
1256 /* Global variables used when generating relaxable macros. See the
1257 comment above RELAX_ENCODE for more details about how relaxation
1260 /* 0 if we're not emitting a relaxable macro.
1261 1 if we're emitting the first of the two relaxation alternatives.
1262 2 if we're emitting the second alternative. */
1265 /* The first relaxable fixup in the current frag. (In other words,
1266 the first fixup that refers to relaxable code.) */
1269 /* sizes[0] says how many bytes of the first alternative are stored in
1270 the current frag. Likewise sizes[1] for the second alternative. */
1271 unsigned int sizes[2];
1273 /* The symbol on which the choice of sequence depends. */
1277 /* Global variables used to decide whether a macro needs a warning. */
1279 /* True if the macro is in a branch delay slot. */
1280 bfd_boolean delay_slot_p;
1282 /* Set to the length in bytes required if the macro is in a delay slot
1283 that requires a specific length of instruction, otherwise zero. */
1284 unsigned int delay_slot_length;
1286 /* For relaxable macros, sizes[0] is the length of the first alternative
1287 in bytes and sizes[1] is the length of the second alternative.
1288 For non-relaxable macros, both elements give the length of the
1290 unsigned int sizes[2];
1292 /* For relaxable macros, first_insn_sizes[0] is the length of the first
1293 instruction of the first alternative in bytes and first_insn_sizes[1]
1294 is the length of the first instruction of the second alternative.
1295 For non-relaxable macros, both elements give the length of the first
1296 instruction in bytes.
1298 Set to zero if we haven't yet seen the first instruction. */
1299 unsigned int first_insn_sizes[2];
1301 /* For relaxable macros, insns[0] is the number of instructions for the
1302 first alternative and insns[1] is the number of instructions for the
1305 For non-relaxable macros, both elements give the number of
1306 instructions for the macro. */
1307 unsigned int insns[2];
1309 /* The first variant frag for this macro. */
1311 } mips_macro_warning;
1313 /* Prototypes for static functions. */
1315 #define internalError() \
1316 as_fatal (_("internal Error, line %d, %s"), __LINE__, __FILE__)
1318 enum mips_regclass { MIPS_GR_REG, MIPS_FP_REG, MIPS16_REG };
1320 static void append_insn
1321 (struct mips_cl_insn *, expressionS *, bfd_reloc_code_real_type *,
1322 bfd_boolean expansionp);
1323 static void mips_no_prev_insn (void);
1324 static void macro_build (expressionS *, const char *, const char *, ...);
1325 static void mips16_macro_build
1326 (expressionS *, const char *, const char *, va_list *);
1327 static void load_register (int, expressionS *, int);
1328 static void macro_start (void);
1329 static void macro_end (void);
1330 static void macro (struct mips_cl_insn * ip);
1331 static void mips16_macro (struct mips_cl_insn * ip);
1332 static void mips_ip (char *str, struct mips_cl_insn * ip);
1333 static void mips16_ip (char *str, struct mips_cl_insn * ip);
1334 static void mips16_immed
1335 (char *, unsigned int, int, offsetT, bfd_boolean, bfd_boolean, bfd_boolean,
1336 unsigned long *, bfd_boolean *, unsigned short *);
1337 static size_t my_getSmallExpression
1338 (expressionS *, bfd_reloc_code_real_type *, char *);
1339 static void my_getExpression (expressionS *, char *);
1340 static void s_align (int);
1341 static void s_change_sec (int);
1342 static void s_change_section (int);
1343 static void s_cons (int);
1344 static void s_float_cons (int);
1345 static void s_mips_globl (int);
1346 static void s_option (int);
1347 static void s_mipsset (int);
1348 static void s_abicalls (int);
1349 static void s_cpload (int);
1350 static void s_cpsetup (int);
1351 static void s_cplocal (int);
1352 static void s_cprestore (int);
1353 static void s_cpreturn (int);
1354 static void s_dtprelword (int);
1355 static void s_dtpreldword (int);
1356 static void s_gpvalue (int);
1357 static void s_gpword (int);
1358 static void s_gpdword (int);
1359 static void s_cpadd (int);
1360 static void s_insn (int);
1361 static void md_obj_begin (void);
1362 static void md_obj_end (void);
1363 static void s_mips_ent (int);
1364 static void s_mips_end (int);
1365 static void s_mips_frame (int);
1366 static void s_mips_mask (int reg_type);
1367 static void s_mips_stab (int);
1368 static void s_mips_weakext (int);
1369 static void s_mips_file (int);
1370 static void s_mips_loc (int);
1371 static bfd_boolean pic_need_relax (symbolS *, asection *);
1372 static int relaxed_branch_length (fragS *, asection *, int);
1373 static int validate_mips_insn (const struct mips_opcode *);
1374 static int validate_micromips_insn (const struct mips_opcode *);
1375 static int relaxed_micromips_16bit_branch_length (fragS *, asection *, int);
1376 static int relaxed_micromips_32bit_branch_length (fragS *, asection *, int);
1378 /* Table and functions used to map between CPU/ISA names, and
1379 ISA levels, and CPU numbers. */
1381 struct mips_cpu_info
1383 const char *name; /* CPU or ISA name. */
1384 int flags; /* ASEs available, or ISA flag. */
1385 int isa; /* ISA level. */
1386 int cpu; /* CPU number (default CPU if ISA). */
1389 #define MIPS_CPU_IS_ISA 0x0001 /* Is this an ISA? (If 0, a CPU.) */
1390 #define MIPS_CPU_ASE_SMARTMIPS 0x0002 /* CPU implements SmartMIPS ASE */
1391 #define MIPS_CPU_ASE_DSP 0x0004 /* CPU implements DSP ASE */
1392 #define MIPS_CPU_ASE_MT 0x0008 /* CPU implements MT ASE */
1393 #define MIPS_CPU_ASE_MIPS3D 0x0010 /* CPU implements MIPS-3D ASE */
1394 #define MIPS_CPU_ASE_MDMX 0x0020 /* CPU implements MDMX ASE */
1395 #define MIPS_CPU_ASE_DSPR2 0x0040 /* CPU implements DSP R2 ASE */
1396 #define MIPS_CPU_ASE_MCU 0x0080 /* CPU implements MCU ASE */
1398 static const struct mips_cpu_info *mips_parse_cpu (const char *, const char *);
1399 static const struct mips_cpu_info *mips_cpu_info_from_isa (int);
1400 static const struct mips_cpu_info *mips_cpu_info_from_arch (int);
1404 The following pseudo-ops from the Kane and Heinrich MIPS book
1405 should be defined here, but are currently unsupported: .alias,
1406 .galive, .gjaldef, .gjrlive, .livereg, .noalias.
1408 The following pseudo-ops from the Kane and Heinrich MIPS book are
1409 specific to the type of debugging information being generated, and
1410 should be defined by the object format: .aent, .begin, .bend,
1411 .bgnb, .end, .endb, .ent, .fmask, .frame, .loc, .mask, .verstamp,
1414 The following pseudo-ops from the Kane and Heinrich MIPS book are
1415 not MIPS CPU specific, but are also not specific to the object file
1416 format. This file is probably the best place to define them, but
1417 they are not currently supported: .asm0, .endr, .lab, .struct. */
1419 static const pseudo_typeS mips_pseudo_table[] =
1421 /* MIPS specific pseudo-ops. */
1422 {"option", s_option, 0},
1423 {"set", s_mipsset, 0},
1424 {"rdata", s_change_sec, 'r'},
1425 {"sdata", s_change_sec, 's'},
1426 {"livereg", s_ignore, 0},
1427 {"abicalls", s_abicalls, 0},
1428 {"cpload", s_cpload, 0},
1429 {"cpsetup", s_cpsetup, 0},
1430 {"cplocal", s_cplocal, 0},
1431 {"cprestore", s_cprestore, 0},
1432 {"cpreturn", s_cpreturn, 0},
1433 {"dtprelword", s_dtprelword, 0},
1434 {"dtpreldword", s_dtpreldword, 0},
1435 {"gpvalue", s_gpvalue, 0},
1436 {"gpword", s_gpword, 0},
1437 {"gpdword", s_gpdword, 0},
1438 {"cpadd", s_cpadd, 0},
1439 {"insn", s_insn, 0},
1441 /* Relatively generic pseudo-ops that happen to be used on MIPS
1443 {"asciiz", stringer, 8 + 1},
1444 {"bss", s_change_sec, 'b'},
1446 {"half", s_cons, 1},
1447 {"dword", s_cons, 3},
1448 {"weakext", s_mips_weakext, 0},
1449 {"origin", s_org, 0},
1450 {"repeat", s_rept, 0},
1452 /* For MIPS this is non-standard, but we define it for consistency. */
1453 {"sbss", s_change_sec, 'B'},
1455 /* These pseudo-ops are defined in read.c, but must be overridden
1456 here for one reason or another. */
1457 {"align", s_align, 0},
1458 {"byte", s_cons, 0},
1459 {"data", s_change_sec, 'd'},
1460 {"double", s_float_cons, 'd'},
1461 {"float", s_float_cons, 'f'},
1462 {"globl", s_mips_globl, 0},
1463 {"global", s_mips_globl, 0},
1464 {"hword", s_cons, 1},
1466 {"long", s_cons, 2},
1467 {"octa", s_cons, 4},
1468 {"quad", s_cons, 3},
1469 {"section", s_change_section, 0},
1470 {"short", s_cons, 1},
1471 {"single", s_float_cons, 'f'},
1472 {"stabn", s_mips_stab, 'n'},
1473 {"text", s_change_sec, 't'},
1474 {"word", s_cons, 2},
1476 { "extern", ecoff_directive_extern, 0},
1481 static const pseudo_typeS mips_nonecoff_pseudo_table[] =
1483 /* These pseudo-ops should be defined by the object file format.
1484 However, a.out doesn't support them, so we have versions here. */
1485 {"aent", s_mips_ent, 1},
1486 {"bgnb", s_ignore, 0},
1487 {"end", s_mips_end, 0},
1488 {"endb", s_ignore, 0},
1489 {"ent", s_mips_ent, 0},
1490 {"file", s_mips_file, 0},
1491 {"fmask", s_mips_mask, 'F'},
1492 {"frame", s_mips_frame, 0},
1493 {"loc", s_mips_loc, 0},
1494 {"mask", s_mips_mask, 'R'},
1495 {"verstamp", s_ignore, 0},
1499 /* Export the ABI address size for use by TC_ADDRESS_BYTES for the
1500 purpose of the `.dc.a' internal pseudo-op. */
1503 mips_address_bytes (void)
1505 return HAVE_64BIT_ADDRESSES ? 8 : 4;
1508 extern void pop_insert (const pseudo_typeS *);
1511 mips_pop_insert (void)
1513 pop_insert (mips_pseudo_table);
1514 if (! ECOFF_DEBUGGING)
1515 pop_insert (mips_nonecoff_pseudo_table);
1518 /* Symbols labelling the current insn. */
1520 struct insn_label_list
1522 struct insn_label_list *next;
1526 static struct insn_label_list *free_insn_labels;
1527 #define label_list tc_segment_info_data.labels
1529 static void mips_clear_insn_labels (void);
1530 static void mips_mark_labels (void);
1531 static void mips_compressed_mark_labels (void);
1534 mips_clear_insn_labels (void)
1536 register struct insn_label_list **pl;
1537 segment_info_type *si;
1541 for (pl = &free_insn_labels; *pl != NULL; pl = &(*pl)->next)
1544 si = seg_info (now_seg);
1545 *pl = si->label_list;
1546 si->label_list = NULL;
1550 /* Mark instruction labels in MIPS16/microMIPS mode. */
1553 mips_mark_labels (void)
1555 if (HAVE_CODE_COMPRESSION)
1556 mips_compressed_mark_labels ();
1559 static char *expr_end;
1561 /* Expressions which appear in instructions. These are set by
1564 static expressionS imm_expr;
1565 static expressionS imm2_expr;
1566 static expressionS offset_expr;
1568 /* Relocs associated with imm_expr and offset_expr. */
1570 static bfd_reloc_code_real_type imm_reloc[3]
1571 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
1572 static bfd_reloc_code_real_type offset_reloc[3]
1573 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
1575 /* This is set to the resulting size of the instruction to be produced
1576 by mips16_ip if an explicit extension is used or by mips_ip if an
1577 explicit size is supplied. */
1579 static unsigned int forced_insn_length;
1582 /* The pdr segment for per procedure frame/regmask info. Not used for
1585 static segT pdr_seg;
1588 /* The default target format to use. */
1590 #if defined (TE_FreeBSD)
1591 #define ELF_TARGET(PREFIX, ENDIAN) PREFIX "trad" ENDIAN "mips-freebsd"
1592 #elif defined (TE_TMIPS)
1593 #define ELF_TARGET(PREFIX, ENDIAN) PREFIX "trad" ENDIAN "mips"
1595 #define ELF_TARGET(PREFIX, ENDIAN) PREFIX ENDIAN "mips"
1599 mips_target_format (void)
1601 switch (OUTPUT_FLAVOR)
1603 case bfd_target_ecoff_flavour:
1604 return target_big_endian ? "ecoff-bigmips" : ECOFF_LITTLE_FORMAT;
1605 case bfd_target_coff_flavour:
1607 case bfd_target_elf_flavour:
1609 if (!HAVE_64BIT_OBJECTS && !HAVE_NEWABI)
1610 return (target_big_endian
1611 ? "elf32-bigmips-vxworks"
1612 : "elf32-littlemips-vxworks");
1614 return (target_big_endian
1615 ? (HAVE_64BIT_OBJECTS
1616 ? ELF_TARGET ("elf64-", "big")
1618 ? ELF_TARGET ("elf32-n", "big")
1619 : ELF_TARGET ("elf32-", "big")))
1620 : (HAVE_64BIT_OBJECTS
1621 ? ELF_TARGET ("elf64-", "little")
1623 ? ELF_TARGET ("elf32-n", "little")
1624 : ELF_TARGET ("elf32-", "little"))));
1631 /* Return the length of a microMIPS instruction in bytes. If bits of
1632 the mask beyond the low 16 are 0, then it is a 16-bit instruction.
1633 Otherwise assume a 32-bit instruction; 48-bit instructions (0x1f
1634 major opcode) will require further modifications to the opcode
1637 static inline unsigned int
1638 micromips_insn_length (const struct mips_opcode *mo)
1640 return (mo->mask >> 16) == 0 ? 2 : 4;
1643 /* Return the length of instruction INSN. */
1645 static inline unsigned int
1646 insn_length (const struct mips_cl_insn *insn)
1648 if (mips_opts.micromips)
1649 return micromips_insn_length (insn->insn_mo);
1650 else if (mips_opts.mips16)
1651 return insn->mips16_absolute_jump_p || insn->use_extend ? 4 : 2;
1656 /* Initialise INSN from opcode entry MO. Leave its position unspecified. */
1659 create_insn (struct mips_cl_insn *insn, const struct mips_opcode *mo)
1664 insn->use_extend = FALSE;
1666 insn->insn_opcode = mo->match;
1669 for (i = 0; i < ARRAY_SIZE (insn->fixp); i++)
1670 insn->fixp[i] = NULL;
1671 insn->fixed_p = (mips_opts.noreorder > 0);
1672 insn->noreorder_p = (mips_opts.noreorder > 0);
1673 insn->mips16_absolute_jump_p = 0;
1674 insn->complete_p = 0;
1677 /* Record the current MIPS16/microMIPS mode in now_seg. */
1680 mips_record_compressed_mode (void)
1682 segment_info_type *si;
1684 si = seg_info (now_seg);
1685 if (si->tc_segment_info_data.mips16 != mips_opts.mips16)
1686 si->tc_segment_info_data.mips16 = mips_opts.mips16;
1687 if (si->tc_segment_info_data.micromips != mips_opts.micromips)
1688 si->tc_segment_info_data.micromips = mips_opts.micromips;
1691 /* Install INSN at the location specified by its "frag" and "where" fields. */
1694 install_insn (const struct mips_cl_insn *insn)
1696 char *f = insn->frag->fr_literal + insn->where;
1697 if (!HAVE_CODE_COMPRESSION)
1698 md_number_to_chars (f, insn->insn_opcode, 4);
1699 else if (mips_opts.micromips)
1701 unsigned int length = insn_length (insn);
1703 md_number_to_chars (f, insn->insn_opcode, 2);
1704 else if (length == 4)
1706 md_number_to_chars (f, insn->insn_opcode >> 16, 2);
1708 md_number_to_chars (f, insn->insn_opcode & 0xffff, 2);
1711 as_bad (_("48-bit microMIPS instructions are not supported"));
1713 else if (insn->mips16_absolute_jump_p)
1715 md_number_to_chars (f, insn->insn_opcode >> 16, 2);
1716 md_number_to_chars (f + 2, insn->insn_opcode & 0xffff, 2);
1720 if (insn->use_extend)
1722 md_number_to_chars (f, 0xf000 | insn->extend, 2);
1725 md_number_to_chars (f, insn->insn_opcode, 2);
1727 mips_record_compressed_mode ();
1730 /* Move INSN to offset WHERE in FRAG. Adjust the fixups accordingly
1731 and install the opcode in the new location. */
1734 move_insn (struct mips_cl_insn *insn, fragS *frag, long where)
1739 insn->where = where;
1740 for (i = 0; i < ARRAY_SIZE (insn->fixp); i++)
1741 if (insn->fixp[i] != NULL)
1743 insn->fixp[i]->fx_frag = frag;
1744 insn->fixp[i]->fx_where = where;
1746 install_insn (insn);
1749 /* Add INSN to the end of the output. */
1752 add_fixed_insn (struct mips_cl_insn *insn)
1754 char *f = frag_more (insn_length (insn));
1755 move_insn (insn, frag_now, f - frag_now->fr_literal);
1758 /* Start a variant frag and move INSN to the start of the variant part,
1759 marking it as fixed. The other arguments are as for frag_var. */
1762 add_relaxed_insn (struct mips_cl_insn *insn, int max_chars, int var,
1763 relax_substateT subtype, symbolS *symbol, offsetT offset)
1765 frag_grow (max_chars);
1766 move_insn (insn, frag_now, frag_more (0) - frag_now->fr_literal);
1768 frag_var (rs_machine_dependent, max_chars, var,
1769 subtype, symbol, offset, NULL);
1772 /* Insert N copies of INSN into the history buffer, starting at
1773 position FIRST. Neither FIRST nor N need to be clipped. */
1776 insert_into_history (unsigned int first, unsigned int n,
1777 const struct mips_cl_insn *insn)
1779 if (mips_relax.sequence != 2)
1783 for (i = ARRAY_SIZE (history); i-- > first;)
1785 history[i] = history[i - n];
1791 /* Initialize vr4120_conflicts. There is a bit of duplication here:
1792 the idea is to make it obvious at a glance that each errata is
1796 init_vr4120_conflicts (void)
1798 #define CONFLICT(FIRST, SECOND) \
1799 vr4120_conflicts[FIX_VR4120_##FIRST] |= 1 << FIX_VR4120_##SECOND
1801 /* Errata 21 - [D]DIV[U] after [D]MACC */
1802 CONFLICT (MACC, DIV);
1803 CONFLICT (DMACC, DIV);
1805 /* Errata 23 - Continuous DMULT[U]/DMACC instructions. */
1806 CONFLICT (DMULT, DMULT);
1807 CONFLICT (DMULT, DMACC);
1808 CONFLICT (DMACC, DMULT);
1809 CONFLICT (DMACC, DMACC);
1811 /* Errata 24 - MT{LO,HI} after [D]MACC */
1812 CONFLICT (MACC, MTHILO);
1813 CONFLICT (DMACC, MTHILO);
1815 /* VR4181A errata MD(1): "If a MULT, MULTU, DMULT or DMULTU
1816 instruction is executed immediately after a MACC or DMACC
1817 instruction, the result of [either instruction] is incorrect." */
1818 CONFLICT (MACC, MULT);
1819 CONFLICT (MACC, DMULT);
1820 CONFLICT (DMACC, MULT);
1821 CONFLICT (DMACC, DMULT);
1823 /* VR4181A errata MD(4): "If a MACC or DMACC instruction is
1824 executed immediately after a DMULT, DMULTU, DIV, DIVU,
1825 DDIV or DDIVU instruction, the result of the MACC or
1826 DMACC instruction is incorrect.". */
1827 CONFLICT (DMULT, MACC);
1828 CONFLICT (DMULT, DMACC);
1829 CONFLICT (DIV, MACC);
1830 CONFLICT (DIV, DMACC);
1840 #define RTYPE_MASK 0x1ff00
1841 #define RTYPE_NUM 0x00100
1842 #define RTYPE_FPU 0x00200
1843 #define RTYPE_FCC 0x00400
1844 #define RTYPE_VEC 0x00800
1845 #define RTYPE_GP 0x01000
1846 #define RTYPE_CP0 0x02000
1847 #define RTYPE_PC 0x04000
1848 #define RTYPE_ACC 0x08000
1849 #define RTYPE_CCC 0x10000
1850 #define RNUM_MASK 0x000ff
1851 #define RWARN 0x80000
1853 #define GENERIC_REGISTER_NUMBERS \
1854 {"$0", RTYPE_NUM | 0}, \
1855 {"$1", RTYPE_NUM | 1}, \
1856 {"$2", RTYPE_NUM | 2}, \
1857 {"$3", RTYPE_NUM | 3}, \
1858 {"$4", RTYPE_NUM | 4}, \
1859 {"$5", RTYPE_NUM | 5}, \
1860 {"$6", RTYPE_NUM | 6}, \
1861 {"$7", RTYPE_NUM | 7}, \
1862 {"$8", RTYPE_NUM | 8}, \
1863 {"$9", RTYPE_NUM | 9}, \
1864 {"$10", RTYPE_NUM | 10}, \
1865 {"$11", RTYPE_NUM | 11}, \
1866 {"$12", RTYPE_NUM | 12}, \
1867 {"$13", RTYPE_NUM | 13}, \
1868 {"$14", RTYPE_NUM | 14}, \
1869 {"$15", RTYPE_NUM | 15}, \
1870 {"$16", RTYPE_NUM | 16}, \
1871 {"$17", RTYPE_NUM | 17}, \
1872 {"$18", RTYPE_NUM | 18}, \
1873 {"$19", RTYPE_NUM | 19}, \
1874 {"$20", RTYPE_NUM | 20}, \
1875 {"$21", RTYPE_NUM | 21}, \
1876 {"$22", RTYPE_NUM | 22}, \
1877 {"$23", RTYPE_NUM | 23}, \
1878 {"$24", RTYPE_NUM | 24}, \
1879 {"$25", RTYPE_NUM | 25}, \
1880 {"$26", RTYPE_NUM | 26}, \
1881 {"$27", RTYPE_NUM | 27}, \
1882 {"$28", RTYPE_NUM | 28}, \
1883 {"$29", RTYPE_NUM | 29}, \
1884 {"$30", RTYPE_NUM | 30}, \
1885 {"$31", RTYPE_NUM | 31}
1887 #define FPU_REGISTER_NAMES \
1888 {"$f0", RTYPE_FPU | 0}, \
1889 {"$f1", RTYPE_FPU | 1}, \
1890 {"$f2", RTYPE_FPU | 2}, \
1891 {"$f3", RTYPE_FPU | 3}, \
1892 {"$f4", RTYPE_FPU | 4}, \
1893 {"$f5", RTYPE_FPU | 5}, \
1894 {"$f6", RTYPE_FPU | 6}, \
1895 {"$f7", RTYPE_FPU | 7}, \
1896 {"$f8", RTYPE_FPU | 8}, \
1897 {"$f9", RTYPE_FPU | 9}, \
1898 {"$f10", RTYPE_FPU | 10}, \
1899 {"$f11", RTYPE_FPU | 11}, \
1900 {"$f12", RTYPE_FPU | 12}, \
1901 {"$f13", RTYPE_FPU | 13}, \
1902 {"$f14", RTYPE_FPU | 14}, \
1903 {"$f15", RTYPE_FPU | 15}, \
1904 {"$f16", RTYPE_FPU | 16}, \
1905 {"$f17", RTYPE_FPU | 17}, \
1906 {"$f18", RTYPE_FPU | 18}, \
1907 {"$f19", RTYPE_FPU | 19}, \
1908 {"$f20", RTYPE_FPU | 20}, \
1909 {"$f21", RTYPE_FPU | 21}, \
1910 {"$f22", RTYPE_FPU | 22}, \
1911 {"$f23", RTYPE_FPU | 23}, \
1912 {"$f24", RTYPE_FPU | 24}, \
1913 {"$f25", RTYPE_FPU | 25}, \
1914 {"$f26", RTYPE_FPU | 26}, \
1915 {"$f27", RTYPE_FPU | 27}, \
1916 {"$f28", RTYPE_FPU | 28}, \
1917 {"$f29", RTYPE_FPU | 29}, \
1918 {"$f30", RTYPE_FPU | 30}, \
1919 {"$f31", RTYPE_FPU | 31}
1921 #define FPU_CONDITION_CODE_NAMES \
1922 {"$fcc0", RTYPE_FCC | 0}, \
1923 {"$fcc1", RTYPE_FCC | 1}, \
1924 {"$fcc2", RTYPE_FCC | 2}, \
1925 {"$fcc3", RTYPE_FCC | 3}, \
1926 {"$fcc4", RTYPE_FCC | 4}, \
1927 {"$fcc5", RTYPE_FCC | 5}, \
1928 {"$fcc6", RTYPE_FCC | 6}, \
1929 {"$fcc7", RTYPE_FCC | 7}
1931 #define COPROC_CONDITION_CODE_NAMES \
1932 {"$cc0", RTYPE_FCC | RTYPE_CCC | 0}, \
1933 {"$cc1", RTYPE_FCC | RTYPE_CCC | 1}, \
1934 {"$cc2", RTYPE_FCC | RTYPE_CCC | 2}, \
1935 {"$cc3", RTYPE_FCC | RTYPE_CCC | 3}, \
1936 {"$cc4", RTYPE_FCC | RTYPE_CCC | 4}, \
1937 {"$cc5", RTYPE_FCC | RTYPE_CCC | 5}, \
1938 {"$cc6", RTYPE_FCC | RTYPE_CCC | 6}, \
1939 {"$cc7", RTYPE_FCC | RTYPE_CCC | 7}
1941 #define N32N64_SYMBOLIC_REGISTER_NAMES \
1942 {"$a4", RTYPE_GP | 8}, \
1943 {"$a5", RTYPE_GP | 9}, \
1944 {"$a6", RTYPE_GP | 10}, \
1945 {"$a7", RTYPE_GP | 11}, \
1946 {"$ta0", RTYPE_GP | 8}, /* alias for $a4 */ \
1947 {"$ta1", RTYPE_GP | 9}, /* alias for $a5 */ \
1948 {"$ta2", RTYPE_GP | 10}, /* alias for $a6 */ \
1949 {"$ta3", RTYPE_GP | 11}, /* alias for $a7 */ \
1950 {"$t0", RTYPE_GP | 12}, \
1951 {"$t1", RTYPE_GP | 13}, \
1952 {"$t2", RTYPE_GP | 14}, \
1953 {"$t3", RTYPE_GP | 15}
1955 #define O32_SYMBOLIC_REGISTER_NAMES \
1956 {"$t0", RTYPE_GP | 8}, \
1957 {"$t1", RTYPE_GP | 9}, \
1958 {"$t2", RTYPE_GP | 10}, \
1959 {"$t3", RTYPE_GP | 11}, \
1960 {"$t4", RTYPE_GP | 12}, \
1961 {"$t5", RTYPE_GP | 13}, \
1962 {"$t6", RTYPE_GP | 14}, \
1963 {"$t7", RTYPE_GP | 15}, \
1964 {"$ta0", RTYPE_GP | 12}, /* alias for $t4 */ \
1965 {"$ta1", RTYPE_GP | 13}, /* alias for $t5 */ \
1966 {"$ta2", RTYPE_GP | 14}, /* alias for $t6 */ \
1967 {"$ta3", RTYPE_GP | 15} /* alias for $t7 */
1969 /* Remaining symbolic register names */
1970 #define SYMBOLIC_REGISTER_NAMES \
1971 {"$zero", RTYPE_GP | 0}, \
1972 {"$at", RTYPE_GP | 1}, \
1973 {"$AT", RTYPE_GP | 1}, \
1974 {"$v0", RTYPE_GP | 2}, \
1975 {"$v1", RTYPE_GP | 3}, \
1976 {"$a0", RTYPE_GP | 4}, \
1977 {"$a1", RTYPE_GP | 5}, \
1978 {"$a2", RTYPE_GP | 6}, \
1979 {"$a3", RTYPE_GP | 7}, \
1980 {"$s0", RTYPE_GP | 16}, \
1981 {"$s1", RTYPE_GP | 17}, \
1982 {"$s2", RTYPE_GP | 18}, \
1983 {"$s3", RTYPE_GP | 19}, \
1984 {"$s4", RTYPE_GP | 20}, \
1985 {"$s5", RTYPE_GP | 21}, \
1986 {"$s6", RTYPE_GP | 22}, \
1987 {"$s7", RTYPE_GP | 23}, \
1988 {"$t8", RTYPE_GP | 24}, \
1989 {"$t9", RTYPE_GP | 25}, \
1990 {"$k0", RTYPE_GP | 26}, \
1991 {"$kt0", RTYPE_GP | 26}, \
1992 {"$k1", RTYPE_GP | 27}, \
1993 {"$kt1", RTYPE_GP | 27}, \
1994 {"$gp", RTYPE_GP | 28}, \
1995 {"$sp", RTYPE_GP | 29}, \
1996 {"$s8", RTYPE_GP | 30}, \
1997 {"$fp", RTYPE_GP | 30}, \
1998 {"$ra", RTYPE_GP | 31}
2000 #define MIPS16_SPECIAL_REGISTER_NAMES \
2001 {"$pc", RTYPE_PC | 0}
2003 #define MDMX_VECTOR_REGISTER_NAMES \
2004 /* {"$v0", RTYPE_VEC | 0}, clash with REG 2 above */ \
2005 /* {"$v1", RTYPE_VEC | 1}, clash with REG 3 above */ \
2006 {"$v2", RTYPE_VEC | 2}, \
2007 {"$v3", RTYPE_VEC | 3}, \
2008 {"$v4", RTYPE_VEC | 4}, \
2009 {"$v5", RTYPE_VEC | 5}, \
2010 {"$v6", RTYPE_VEC | 6}, \
2011 {"$v7", RTYPE_VEC | 7}, \
2012 {"$v8", RTYPE_VEC | 8}, \
2013 {"$v9", RTYPE_VEC | 9}, \
2014 {"$v10", RTYPE_VEC | 10}, \
2015 {"$v11", RTYPE_VEC | 11}, \
2016 {"$v12", RTYPE_VEC | 12}, \
2017 {"$v13", RTYPE_VEC | 13}, \
2018 {"$v14", RTYPE_VEC | 14}, \
2019 {"$v15", RTYPE_VEC | 15}, \
2020 {"$v16", RTYPE_VEC | 16}, \
2021 {"$v17", RTYPE_VEC | 17}, \
2022 {"$v18", RTYPE_VEC | 18}, \
2023 {"$v19", RTYPE_VEC | 19}, \
2024 {"$v20", RTYPE_VEC | 20}, \
2025 {"$v21", RTYPE_VEC | 21}, \
2026 {"$v22", RTYPE_VEC | 22}, \
2027 {"$v23", RTYPE_VEC | 23}, \
2028 {"$v24", RTYPE_VEC | 24}, \
2029 {"$v25", RTYPE_VEC | 25}, \
2030 {"$v26", RTYPE_VEC | 26}, \
2031 {"$v27", RTYPE_VEC | 27}, \
2032 {"$v28", RTYPE_VEC | 28}, \
2033 {"$v29", RTYPE_VEC | 29}, \
2034 {"$v30", RTYPE_VEC | 30}, \
2035 {"$v31", RTYPE_VEC | 31}
2037 #define MIPS_DSP_ACCUMULATOR_NAMES \
2038 {"$ac0", RTYPE_ACC | 0}, \
2039 {"$ac1", RTYPE_ACC | 1}, \
2040 {"$ac2", RTYPE_ACC | 2}, \
2041 {"$ac3", RTYPE_ACC | 3}
2043 static const struct regname reg_names[] = {
2044 GENERIC_REGISTER_NUMBERS,
2046 FPU_CONDITION_CODE_NAMES,
2047 COPROC_CONDITION_CODE_NAMES,
2049 /* The $txx registers depends on the abi,
2050 these will be added later into the symbol table from
2051 one of the tables below once mips_abi is set after
2052 parsing of arguments from the command line. */
2053 SYMBOLIC_REGISTER_NAMES,
2055 MIPS16_SPECIAL_REGISTER_NAMES,
2056 MDMX_VECTOR_REGISTER_NAMES,
2057 MIPS_DSP_ACCUMULATOR_NAMES,
2061 static const struct regname reg_names_o32[] = {
2062 O32_SYMBOLIC_REGISTER_NAMES,
2066 static const struct regname reg_names_n32n64[] = {
2067 N32N64_SYMBOLIC_REGISTER_NAMES,
2071 /* Check if S points at a valid register specifier according to TYPES.
2072 If so, then return 1, advance S to consume the specifier and store
2073 the register's number in REGNOP, otherwise return 0. */
2076 reg_lookup (char **s, unsigned int types, unsigned int *regnop)
2083 /* Find end of name. */
2085 if (is_name_beginner (*e))
2087 while (is_part_of_name (*e))
2090 /* Terminate name. */
2094 /* Look for a register symbol. */
2095 if ((symbolP = symbol_find (*s)) && S_GET_SEGMENT (symbolP) == reg_section)
2097 int r = S_GET_VALUE (symbolP);
2099 reg = r & RNUM_MASK;
2100 else if ((types & RTYPE_VEC) && (r & ~1) == (RTYPE_GP | 2))
2101 /* Convert GP reg $v0/1 to MDMX reg $v0/1! */
2102 reg = (r & RNUM_MASK) - 2;
2104 /* Else see if this is a register defined in an itbl entry. */
2105 else if ((types & RTYPE_GP) && itbl_have_entries)
2112 if (itbl_get_reg_val (n, &r))
2113 reg = r & RNUM_MASK;
2116 /* Advance to next token if a register was recognised. */
2119 else if (types & RWARN)
2120 as_warn (_("Unrecognized register name `%s'"), *s);
2128 /* Check if S points at a valid register list according to TYPES.
2129 If so, then return 1, advance S to consume the list and store
2130 the registers present on the list as a bitmask of ones in REGLISTP,
2131 otherwise return 0. A valid list comprises a comma-separated
2132 enumeration of valid single registers and/or dash-separated
2133 contiguous register ranges as determined by their numbers.
2135 As a special exception if one of s0-s7 registers is specified as
2136 the range's lower delimiter and s8 (fp) is its upper one, then no
2137 registers whose numbers place them between s7 and s8 (i.e. $24-$29)
2138 are selected; they have to be listed separately if needed. */
2141 reglist_lookup (char **s, unsigned int types, unsigned int *reglistp)
2143 unsigned int reglist = 0;
2144 unsigned int lastregno;
2145 bfd_boolean ok = TRUE;
2146 unsigned int regmask;
2147 char *s_endlist = *s;
2151 while (reg_lookup (s, types, ®no))
2157 ok = reg_lookup (s, types, &lastregno);
2158 if (ok && lastregno < regno)
2164 if (lastregno == FP && regno >= S0 && regno <= S7)
2169 regmask = 1 << lastregno;
2170 regmask = (regmask << 1) - 1;
2171 regmask ^= (1 << regno) - 1;
2185 *reglistp = reglist;
2186 return ok && reglist != 0;
2189 /* Return TRUE if opcode MO is valid on the currently selected ISA and
2190 architecture. Use is_opcode_valid_16 for MIPS16 opcodes. */
2193 is_opcode_valid (const struct mips_opcode *mo)
2195 int isa = mips_opts.isa;
2198 if (mips_opts.ase_mdmx)
2200 if (mips_opts.ase_dsp)
2202 if (mips_opts.ase_dsp && ISA_SUPPORTS_DSP64_ASE)
2204 if (mips_opts.ase_dspr2)
2206 if (mips_opts.ase_mt)
2208 if (mips_opts.ase_mips3d)
2210 if (mips_opts.ase_smartmips)
2211 isa |= INSN_SMARTMIPS;
2212 if (mips_opts.ase_mcu)
2215 /* Don't accept instructions based on the ISA if the CPU does not implement
2216 all the coprocessor insns. */
2217 if (NO_ISA_COP (mips_opts.arch)
2218 && COP_INSN (mo->pinfo))
2221 if (!OPCODE_IS_MEMBER (mo, isa, mips_opts.arch))
2224 /* Check whether the instruction or macro requires single-precision or
2225 double-precision floating-point support. Note that this information is
2226 stored differently in the opcode table for insns and macros. */
2227 if (mo->pinfo == INSN_MACRO)
2229 fp_s = mo->pinfo2 & INSN2_M_FP_S;
2230 fp_d = mo->pinfo2 & INSN2_M_FP_D;
2234 fp_s = mo->pinfo & FP_S;
2235 fp_d = mo->pinfo & FP_D;
2238 if (fp_d && (mips_opts.soft_float || mips_opts.single_float))
2241 if (fp_s && mips_opts.soft_float)
2247 /* Return TRUE if the MIPS16 opcode MO is valid on the currently
2248 selected ISA and architecture. */
2251 is_opcode_valid_16 (const struct mips_opcode *mo)
2253 return OPCODE_IS_MEMBER (mo, mips_opts.isa, mips_opts.arch) ? TRUE : FALSE;
2256 /* Return TRUE if the size of the microMIPS opcode MO matches one
2257 explicitly requested. Always TRUE in the standard MIPS mode. */
2260 is_size_valid (const struct mips_opcode *mo)
2262 if (!mips_opts.micromips)
2265 if (!forced_insn_length)
2267 if (mo->pinfo == INSN_MACRO)
2269 return forced_insn_length == micromips_insn_length (mo);
2272 /* Return TRUE if the microMIPS opcode MO is valid for the delay slot
2273 of the preceding instruction. Always TRUE in the standard MIPS mode. */
2276 is_delay_slot_valid (const struct mips_opcode *mo)
2278 if (!mips_opts.micromips)
2281 if (mo->pinfo == INSN_MACRO)
2283 if ((history[0].insn_mo->pinfo2 & INSN2_BRANCH_DELAY_32BIT) != 0
2284 && micromips_insn_length (mo) != 4)
2286 if ((history[0].insn_mo->pinfo2 & INSN2_BRANCH_DELAY_16BIT) != 0
2287 && micromips_insn_length (mo) != 2)
2293 /* This function is called once, at assembler startup time. It should set up
2294 all the tables, etc. that the MD part of the assembler will need. */
2299 const char *retval = NULL;
2303 if (mips_pic != NO_PIC)
2305 if (g_switch_seen && g_switch_value != 0)
2306 as_bad (_("-G may not be used in position-independent code"));
2310 if (! bfd_set_arch_mach (stdoutput, bfd_arch_mips, file_mips_arch))
2311 as_warn (_("Could not set architecture and machine"));
2313 op_hash = hash_new ();
2315 for (i = 0; i < NUMOPCODES;)
2317 const char *name = mips_opcodes[i].name;
2319 retval = hash_insert (op_hash, name, (void *) &mips_opcodes[i]);
2322 fprintf (stderr, _("internal error: can't hash `%s': %s\n"),
2323 mips_opcodes[i].name, retval);
2324 /* Probably a memory allocation problem? Give up now. */
2325 as_fatal (_("Broken assembler. No assembly attempted."));
2329 if (mips_opcodes[i].pinfo != INSN_MACRO)
2331 if (!validate_mips_insn (&mips_opcodes[i]))
2333 if (nop_insn.insn_mo == NULL && strcmp (name, "nop") == 0)
2335 create_insn (&nop_insn, mips_opcodes + i);
2336 if (mips_fix_loongson2f_nop)
2337 nop_insn.insn_opcode = LOONGSON2F_NOP_INSN;
2338 nop_insn.fixed_p = 1;
2343 while ((i < NUMOPCODES) && !strcmp (mips_opcodes[i].name, name));
2346 mips16_op_hash = hash_new ();
2349 while (i < bfd_mips16_num_opcodes)
2351 const char *name = mips16_opcodes[i].name;
2353 retval = hash_insert (mips16_op_hash, name, (void *) &mips16_opcodes[i]);
2355 as_fatal (_("internal: can't hash `%s': %s"),
2356 mips16_opcodes[i].name, retval);
2359 if (mips16_opcodes[i].pinfo != INSN_MACRO
2360 && ((mips16_opcodes[i].match & mips16_opcodes[i].mask)
2361 != mips16_opcodes[i].match))
2363 fprintf (stderr, _("internal error: bad mips16 opcode: %s %s\n"),
2364 mips16_opcodes[i].name, mips16_opcodes[i].args);
2367 if (mips16_nop_insn.insn_mo == NULL && strcmp (name, "nop") == 0)
2369 create_insn (&mips16_nop_insn, mips16_opcodes + i);
2370 mips16_nop_insn.fixed_p = 1;
2374 while (i < bfd_mips16_num_opcodes
2375 && strcmp (mips16_opcodes[i].name, name) == 0);
2378 micromips_op_hash = hash_new ();
2381 while (i < bfd_micromips_num_opcodes)
2383 const char *name = micromips_opcodes[i].name;
2385 retval = hash_insert (micromips_op_hash, name,
2386 (void *) µmips_opcodes[i]);
2388 as_fatal (_("internal: can't hash `%s': %s"),
2389 micromips_opcodes[i].name, retval);
2391 if (micromips_opcodes[i].pinfo != INSN_MACRO)
2393 struct mips_cl_insn *micromips_nop_insn;
2395 if (!validate_micromips_insn (µmips_opcodes[i]))
2398 if (micromips_insn_length (micromips_opcodes + i) == 2)
2399 micromips_nop_insn = µmips_nop16_insn;
2400 else if (micromips_insn_length (micromips_opcodes + i) == 4)
2401 micromips_nop_insn = µmips_nop32_insn;
2405 if (micromips_nop_insn->insn_mo == NULL
2406 && strcmp (name, "nop") == 0)
2408 create_insn (micromips_nop_insn, micromips_opcodes + i);
2409 micromips_nop_insn->fixed_p = 1;
2412 while (++i < bfd_micromips_num_opcodes
2413 && strcmp (micromips_opcodes[i].name, name) == 0);
2417 as_fatal (_("Broken assembler. No assembly attempted."));
2419 /* We add all the general register names to the symbol table. This
2420 helps us detect invalid uses of them. */
2421 for (i = 0; reg_names[i].name; i++)
2422 symbol_table_insert (symbol_new (reg_names[i].name, reg_section,
2423 reg_names[i].num, /* & RNUM_MASK, */
2424 &zero_address_frag));
2426 for (i = 0; reg_names_n32n64[i].name; i++)
2427 symbol_table_insert (symbol_new (reg_names_n32n64[i].name, reg_section,
2428 reg_names_n32n64[i].num, /* & RNUM_MASK, */
2429 &zero_address_frag));
2431 for (i = 0; reg_names_o32[i].name; i++)
2432 symbol_table_insert (symbol_new (reg_names_o32[i].name, reg_section,
2433 reg_names_o32[i].num, /* & RNUM_MASK, */
2434 &zero_address_frag));
2436 mips_no_prev_insn ();
2439 mips_cprmask[0] = 0;
2440 mips_cprmask[1] = 0;
2441 mips_cprmask[2] = 0;
2442 mips_cprmask[3] = 0;
2444 /* set the default alignment for the text section (2**2) */
2445 record_alignment (text_section, 2);
2447 bfd_set_gp_size (stdoutput, g_switch_value);
2452 /* On a native system other than VxWorks, sections must be aligned
2453 to 16 byte boundaries. When configured for an embedded ELF
2454 target, we don't bother. */
2455 if (strncmp (TARGET_OS, "elf", 3) != 0
2456 && strncmp (TARGET_OS, "vxworks", 7) != 0)
2458 (void) bfd_set_section_alignment (stdoutput, text_section, 4);
2459 (void) bfd_set_section_alignment (stdoutput, data_section, 4);
2460 (void) bfd_set_section_alignment (stdoutput, bss_section, 4);
2463 /* Create a .reginfo section for register masks and a .mdebug
2464 section for debugging information. */
2472 subseg = now_subseg;
2474 /* The ABI says this section should be loaded so that the
2475 running program can access it. However, we don't load it
2476 if we are configured for an embedded target */
2477 flags = SEC_READONLY | SEC_DATA;
2478 if (strncmp (TARGET_OS, "elf", 3) != 0)
2479 flags |= SEC_ALLOC | SEC_LOAD;
2481 if (mips_abi != N64_ABI)
2483 sec = subseg_new (".reginfo", (subsegT) 0);
2485 bfd_set_section_flags (stdoutput, sec, flags);
2486 bfd_set_section_alignment (stdoutput, sec, HAVE_NEWABI ? 3 : 2);
2488 mips_regmask_frag = frag_more (sizeof (Elf32_External_RegInfo));
2492 /* The 64-bit ABI uses a .MIPS.options section rather than
2493 .reginfo section. */
2494 sec = subseg_new (".MIPS.options", (subsegT) 0);
2495 bfd_set_section_flags (stdoutput, sec, flags);
2496 bfd_set_section_alignment (stdoutput, sec, 3);
2498 /* Set up the option header. */
2500 Elf_Internal_Options opthdr;
2503 opthdr.kind = ODK_REGINFO;
2504 opthdr.size = (sizeof (Elf_External_Options)
2505 + sizeof (Elf64_External_RegInfo));
2508 f = frag_more (sizeof (Elf_External_Options));
2509 bfd_mips_elf_swap_options_out (stdoutput, &opthdr,
2510 (Elf_External_Options *) f);
2512 mips_regmask_frag = frag_more (sizeof (Elf64_External_RegInfo));
2516 if (ECOFF_DEBUGGING)
2518 sec = subseg_new (".mdebug", (subsegT) 0);
2519 (void) bfd_set_section_flags (stdoutput, sec,
2520 SEC_HAS_CONTENTS | SEC_READONLY);
2521 (void) bfd_set_section_alignment (stdoutput, sec, 2);
2523 else if (mips_flag_pdr)
2525 pdr_seg = subseg_new (".pdr", (subsegT) 0);
2526 (void) bfd_set_section_flags (stdoutput, pdr_seg,
2527 SEC_READONLY | SEC_RELOC
2529 (void) bfd_set_section_alignment (stdoutput, pdr_seg, 2);
2532 subseg_set (seg, subseg);
2535 #endif /* OBJ_ELF */
2537 if (! ECOFF_DEBUGGING)
2540 if (mips_fix_vr4120)
2541 init_vr4120_conflicts ();
2547 mips_emit_delays ();
2548 if (! ECOFF_DEBUGGING)
2553 md_assemble (char *str)
2555 struct mips_cl_insn insn;
2556 bfd_reloc_code_real_type unused_reloc[3]
2557 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
2559 imm_expr.X_op = O_absent;
2560 imm2_expr.X_op = O_absent;
2561 offset_expr.X_op = O_absent;
2562 imm_reloc[0] = BFD_RELOC_UNUSED;
2563 imm_reloc[1] = BFD_RELOC_UNUSED;
2564 imm_reloc[2] = BFD_RELOC_UNUSED;
2565 offset_reloc[0] = BFD_RELOC_UNUSED;
2566 offset_reloc[1] = BFD_RELOC_UNUSED;
2567 offset_reloc[2] = BFD_RELOC_UNUSED;
2569 if (mips_opts.mips16)
2570 mips16_ip (str, &insn);
2573 mips_ip (str, &insn);
2574 DBG ((_("returned from mips_ip(%s) insn_opcode = 0x%x\n"),
2575 str, insn.insn_opcode));
2580 as_bad ("%s `%s'", insn_error, str);
2584 if (insn.insn_mo->pinfo == INSN_MACRO)
2587 if (mips_opts.mips16)
2588 mips16_macro (&insn);
2595 if (imm_expr.X_op != O_absent)
2596 append_insn (&insn, &imm_expr, imm_reloc, FALSE);
2597 else if (offset_expr.X_op != O_absent)
2598 append_insn (&insn, &offset_expr, offset_reloc, FALSE);
2600 append_insn (&insn, NULL, unused_reloc, FALSE);
2604 /* Convenience functions for abstracting away the differences between
2605 MIPS16 and non-MIPS16 relocations. */
2607 static inline bfd_boolean
2608 mips16_reloc_p (bfd_reloc_code_real_type reloc)
2612 case BFD_RELOC_MIPS16_JMP:
2613 case BFD_RELOC_MIPS16_GPREL:
2614 case BFD_RELOC_MIPS16_GOT16:
2615 case BFD_RELOC_MIPS16_CALL16:
2616 case BFD_RELOC_MIPS16_HI16_S:
2617 case BFD_RELOC_MIPS16_HI16:
2618 case BFD_RELOC_MIPS16_LO16:
2626 static inline bfd_boolean
2627 micromips_reloc_p (bfd_reloc_code_real_type reloc)
2631 case BFD_RELOC_MICROMIPS_7_PCREL_S1:
2632 case BFD_RELOC_MICROMIPS_10_PCREL_S1:
2633 case BFD_RELOC_MICROMIPS_16_PCREL_S1:
2634 case BFD_RELOC_MICROMIPS_GPREL16:
2635 case BFD_RELOC_MICROMIPS_JMP:
2636 case BFD_RELOC_MICROMIPS_HI16:
2637 case BFD_RELOC_MICROMIPS_HI16_S:
2638 case BFD_RELOC_MICROMIPS_LO16:
2639 case BFD_RELOC_MICROMIPS_LITERAL:
2640 case BFD_RELOC_MICROMIPS_GOT16:
2641 case BFD_RELOC_MICROMIPS_CALL16:
2642 case BFD_RELOC_MICROMIPS_GOT_HI16:
2643 case BFD_RELOC_MICROMIPS_GOT_LO16:
2644 case BFD_RELOC_MICROMIPS_CALL_HI16:
2645 case BFD_RELOC_MICROMIPS_CALL_LO16:
2646 case BFD_RELOC_MICROMIPS_SUB:
2647 case BFD_RELOC_MICROMIPS_GOT_PAGE:
2648 case BFD_RELOC_MICROMIPS_GOT_OFST:
2649 case BFD_RELOC_MICROMIPS_GOT_DISP:
2650 case BFD_RELOC_MICROMIPS_HIGHEST:
2651 case BFD_RELOC_MICROMIPS_HIGHER:
2652 case BFD_RELOC_MICROMIPS_SCN_DISP:
2653 case BFD_RELOC_MICROMIPS_JALR:
2661 static inline bfd_boolean
2662 jmp_reloc_p (bfd_reloc_code_real_type reloc)
2664 return reloc == BFD_RELOC_MIPS_JMP || reloc == BFD_RELOC_MICROMIPS_JMP;
2667 static inline bfd_boolean
2668 got16_reloc_p (bfd_reloc_code_real_type reloc)
2670 return (reloc == BFD_RELOC_MIPS_GOT16 || reloc == BFD_RELOC_MIPS16_GOT16
2671 || reloc == BFD_RELOC_MICROMIPS_GOT16);
2674 static inline bfd_boolean
2675 hi16_reloc_p (bfd_reloc_code_real_type reloc)
2677 return (reloc == BFD_RELOC_HI16_S || reloc == BFD_RELOC_MIPS16_HI16_S
2678 || reloc == BFD_RELOC_MICROMIPS_HI16_S);
2681 static inline bfd_boolean
2682 lo16_reloc_p (bfd_reloc_code_real_type reloc)
2684 return (reloc == BFD_RELOC_LO16 || reloc == BFD_RELOC_MIPS16_LO16
2685 || reloc == BFD_RELOC_MICROMIPS_LO16);
2688 static inline bfd_boolean
2689 jalr_reloc_p (bfd_reloc_code_real_type reloc)
2691 return reloc == BFD_RELOC_MIPS_JALR || reloc == BFD_RELOC_MICROMIPS_JALR;
2694 /* Return true if the given relocation might need a matching %lo().
2695 This is only "might" because SVR4 R_MIPS_GOT16 relocations only
2696 need a matching %lo() when applied to local symbols. */
2698 static inline bfd_boolean
2699 reloc_needs_lo_p (bfd_reloc_code_real_type reloc)
2701 return (HAVE_IN_PLACE_ADDENDS
2702 && (hi16_reloc_p (reloc)
2703 /* VxWorks R_MIPS_GOT16 relocs never need a matching %lo();
2704 all GOT16 relocations evaluate to "G". */
2705 || (got16_reloc_p (reloc) && mips_pic != VXWORKS_PIC)));
2708 /* Return the type of %lo() reloc needed by RELOC, given that
2709 reloc_needs_lo_p. */
2711 static inline bfd_reloc_code_real_type
2712 matching_lo_reloc (bfd_reloc_code_real_type reloc)
2714 return (mips16_reloc_p (reloc) ? BFD_RELOC_MIPS16_LO16
2715 : (micromips_reloc_p (reloc) ? BFD_RELOC_MICROMIPS_LO16
2719 /* Return true if the given fixup is followed by a matching R_MIPS_LO16
2722 static inline bfd_boolean
2723 fixup_has_matching_lo_p (fixS *fixp)
2725 return (fixp->fx_next != NULL
2726 && fixp->fx_next->fx_r_type == matching_lo_reloc (fixp->fx_r_type)
2727 && fixp->fx_addsy == fixp->fx_next->fx_addsy
2728 && fixp->fx_offset == fixp->fx_next->fx_offset);
2731 /* This function returns true if modifying a register requires a
2735 reg_needs_delay (unsigned int reg)
2737 unsigned long prev_pinfo;
2739 prev_pinfo = history[0].insn_mo->pinfo;
2740 if (! mips_opts.noreorder
2741 && (((prev_pinfo & INSN_LOAD_MEMORY_DELAY)
2742 && ! gpr_interlocks)
2743 || ((prev_pinfo & INSN_LOAD_COPROC_DELAY)
2744 && ! cop_interlocks)))
2746 /* A load from a coprocessor or from memory. All load delays
2747 delay the use of general register rt for one instruction. */
2748 /* Itbl support may require additional care here. */
2749 know (prev_pinfo & INSN_WRITE_GPR_T);
2750 if (reg == EXTRACT_OPERAND (mips_opts.micromips, RT, history[0]))
2757 /* Move all labels in insn_labels to the current insertion point. */
2760 mips_move_labels (void)
2762 segment_info_type *si = seg_info (now_seg);
2763 struct insn_label_list *l;
2766 for (l = si->label_list; l != NULL; l = l->next)
2768 gas_assert (S_GET_SEGMENT (l->label) == now_seg);
2769 symbol_set_frag (l->label, frag_now);
2770 val = (valueT) frag_now_fix ();
2771 /* MIPS16/microMIPS text labels are stored as odd. */
2772 if (HAVE_CODE_COMPRESSION)
2774 S_SET_VALUE (l->label, val);
2779 s_is_linkonce (symbolS *sym, segT from_seg)
2781 bfd_boolean linkonce = FALSE;
2782 segT symseg = S_GET_SEGMENT (sym);
2784 if (symseg != from_seg && !S_IS_LOCAL (sym))
2786 if ((bfd_get_section_flags (stdoutput, symseg) & SEC_LINK_ONCE))
2789 /* The GNU toolchain uses an extension for ELF: a section
2790 beginning with the magic string .gnu.linkonce is a
2791 linkonce section. */
2792 if (strncmp (segment_name (symseg), ".gnu.linkonce",
2793 sizeof ".gnu.linkonce" - 1) == 0)
2800 /* Mark instruction labels in MIPS16/microMIPS mode. This permits the
2801 linker to handle them specially, such as generating jalx instructions
2802 when needed. We also make them odd for the duration of the assembly,
2803 in order to generate the right sort of code. We will make them even
2804 in the adjust_symtab routine, while leaving them marked. This is
2805 convenient for the debugger and the disassembler. The linker knows
2806 to make them odd again. */
2809 mips_compressed_mark_labels (void)
2811 segment_info_type *si = seg_info (now_seg);
2812 struct insn_label_list *l;
2814 gas_assert (HAVE_CODE_COMPRESSION);
2816 for (l = si->label_list; l != NULL; l = l->next)
2818 symbolS *label = l->label;
2820 #if defined(OBJ_ELF) || defined(OBJ_MAYBE_ELF)
2823 if (mips_opts.mips16)
2824 S_SET_OTHER (label, ELF_ST_SET_MIPS16 (S_GET_OTHER (label)));
2826 S_SET_OTHER (label, ELF_ST_SET_MICROMIPS (S_GET_OTHER (label)));
2829 if ((S_GET_VALUE (label) & 1) == 0
2830 /* Don't adjust the address if the label is global or weak, or
2831 in a link-once section, since we'll be emitting symbol reloc
2832 references to it which will be patched up by the linker, and
2833 the final value of the symbol may or may not be MIPS16/microMIPS. */
2834 && ! S_IS_WEAK (label)
2835 && ! S_IS_EXTERNAL (label)
2836 && ! s_is_linkonce (label, now_seg))
2837 S_SET_VALUE (label, S_GET_VALUE (label) | 1);
2841 /* End the current frag. Make it a variant frag and record the
2845 relax_close_frag (void)
2847 mips_macro_warning.first_frag = frag_now;
2848 frag_var (rs_machine_dependent, 0, 0,
2849 RELAX_ENCODE (mips_relax.sizes[0], mips_relax.sizes[1]),
2850 mips_relax.symbol, 0, (char *) mips_relax.first_fixup);
2852 memset (&mips_relax.sizes, 0, sizeof (mips_relax.sizes));
2853 mips_relax.first_fixup = 0;
2856 /* Start a new relaxation sequence whose expansion depends on SYMBOL.
2857 See the comment above RELAX_ENCODE for more details. */
2860 relax_start (symbolS *symbol)
2862 gas_assert (mips_relax.sequence == 0);
2863 mips_relax.sequence = 1;
2864 mips_relax.symbol = symbol;
2867 /* Start generating the second version of a relaxable sequence.
2868 See the comment above RELAX_ENCODE for more details. */
2873 gas_assert (mips_relax.sequence == 1);
2874 mips_relax.sequence = 2;
2877 /* End the current relaxable sequence. */
2882 gas_assert (mips_relax.sequence == 2);
2883 relax_close_frag ();
2884 mips_relax.sequence = 0;
2887 /* Return true if IP is a delayed branch or jump. */
2889 static inline bfd_boolean
2890 delayed_branch_p (const struct mips_cl_insn *ip)
2892 return (ip->insn_mo->pinfo & (INSN_UNCOND_BRANCH_DELAY
2893 | INSN_COND_BRANCH_DELAY
2894 | INSN_COND_BRANCH_LIKELY)) != 0;
2897 /* Return true if IP is a compact branch or jump. */
2899 static inline bfd_boolean
2900 compact_branch_p (const struct mips_cl_insn *ip)
2902 if (mips_opts.mips16)
2903 return (ip->insn_mo->pinfo & (MIPS16_INSN_UNCOND_BRANCH
2904 | MIPS16_INSN_COND_BRANCH)) != 0;
2906 return (ip->insn_mo->pinfo2 & (INSN2_UNCOND_BRANCH
2907 | INSN2_COND_BRANCH)) != 0;
2910 /* Return true if IP is an unconditional branch or jump. */
2912 static inline bfd_boolean
2913 uncond_branch_p (const struct mips_cl_insn *ip)
2915 return ((ip->insn_mo->pinfo & INSN_UNCOND_BRANCH_DELAY) != 0
2916 || (mips_opts.mips16
2917 ? (ip->insn_mo->pinfo & MIPS16_INSN_UNCOND_BRANCH) != 0
2918 : (ip->insn_mo->pinfo2 & INSN2_UNCOND_BRANCH) != 0));
2921 /* Return true if IP is a branch-likely instruction. */
2923 static inline bfd_boolean
2924 branch_likely_p (const struct mips_cl_insn *ip)
2926 return (ip->insn_mo->pinfo & INSN_COND_BRANCH_LIKELY) != 0;
2929 /* Return the type of nop that should be used to fill the delay slot
2930 of delayed branch IP. */
2932 static struct mips_cl_insn *
2933 get_delay_slot_nop (const struct mips_cl_insn *ip)
2935 if (mips_opts.micromips
2936 && (ip->insn_mo->pinfo2 & INSN2_BRANCH_DELAY_32BIT))
2937 return µmips_nop32_insn;
2941 /* Return the mask of core registers that IP reads or writes. */
2944 gpr_mod_mask (const struct mips_cl_insn *ip)
2946 unsigned long pinfo2;
2950 pinfo2 = ip->insn_mo->pinfo2;
2951 if (mips_opts.micromips)
2953 if (pinfo2 & INSN2_MOD_GPR_MD)
2954 mask |= 1 << micromips_to_32_reg_d_map[EXTRACT_OPERAND (1, MD, *ip)];
2955 if (pinfo2 & INSN2_MOD_GPR_MF)
2956 mask |= 1 << micromips_to_32_reg_f_map[EXTRACT_OPERAND (1, MF, *ip)];
2957 if (pinfo2 & INSN2_MOD_SP)
2963 /* Return the mask of core registers that IP reads. */
2966 gpr_read_mask (const struct mips_cl_insn *ip)
2968 unsigned long pinfo, pinfo2;
2971 mask = gpr_mod_mask (ip);
2972 pinfo = ip->insn_mo->pinfo;
2973 pinfo2 = ip->insn_mo->pinfo2;
2974 if (mips_opts.mips16)
2976 if (pinfo & MIPS16_INSN_READ_X)
2977 mask |= 1 << mips16_to_32_reg_map[MIPS16_EXTRACT_OPERAND (RX, *ip)];
2978 if (pinfo & MIPS16_INSN_READ_Y)
2979 mask |= 1 << mips16_to_32_reg_map[MIPS16_EXTRACT_OPERAND (RY, *ip)];
2980 if (pinfo & MIPS16_INSN_READ_T)
2982 if (pinfo & MIPS16_INSN_READ_SP)
2984 if (pinfo & MIPS16_INSN_READ_31)
2986 if (pinfo & MIPS16_INSN_READ_Z)
2987 mask |= 1 << (mips16_to_32_reg_map
2988 [MIPS16_EXTRACT_OPERAND (MOVE32Z, *ip)]);
2989 if (pinfo & MIPS16_INSN_READ_GPR_X)
2990 mask |= 1 << MIPS16_EXTRACT_OPERAND (REGR32, *ip);
2994 if (pinfo2 & INSN2_READ_GPR_D)
2995 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RD, *ip);
2996 if (pinfo & INSN_READ_GPR_T)
2997 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RT, *ip);
2998 if (pinfo & INSN_READ_GPR_S)
2999 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RS, *ip);
3000 if (pinfo2 & INSN2_READ_GP)
3002 if (pinfo2 & INSN2_READ_GPR_31)
3004 if (pinfo2 & INSN2_READ_GPR_Z)
3005 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RZ, *ip);
3007 if (mips_opts.micromips)
3009 if (pinfo2 & INSN2_READ_GPR_MC)
3010 mask |= 1 << micromips_to_32_reg_c_map[EXTRACT_OPERAND (1, MC, *ip)];
3011 if (pinfo2 & INSN2_READ_GPR_ME)
3012 mask |= 1 << micromips_to_32_reg_e_map[EXTRACT_OPERAND (1, ME, *ip)];
3013 if (pinfo2 & INSN2_READ_GPR_MG)
3014 mask |= 1 << micromips_to_32_reg_g_map[EXTRACT_OPERAND (1, MG, *ip)];
3015 if (pinfo2 & INSN2_READ_GPR_MJ)
3016 mask |= 1 << EXTRACT_OPERAND (1, MJ, *ip);
3017 if (pinfo2 & INSN2_READ_GPR_MMN)
3019 mask |= 1 << micromips_to_32_reg_m_map[EXTRACT_OPERAND (1, MM, *ip)];
3020 mask |= 1 << micromips_to_32_reg_n_map[EXTRACT_OPERAND (1, MN, *ip)];
3022 if (pinfo2 & INSN2_READ_GPR_MP)
3023 mask |= 1 << EXTRACT_OPERAND (1, MP, *ip);
3024 if (pinfo2 & INSN2_READ_GPR_MQ)
3025 mask |= 1 << micromips_to_32_reg_q_map[EXTRACT_OPERAND (1, MQ, *ip)];
3027 /* Don't include register 0. */
3031 /* Return the mask of core registers that IP writes. */
3034 gpr_write_mask (const struct mips_cl_insn *ip)
3036 unsigned long pinfo, pinfo2;
3039 mask = gpr_mod_mask (ip);
3040 pinfo = ip->insn_mo->pinfo;
3041 pinfo2 = ip->insn_mo->pinfo2;
3042 if (mips_opts.mips16)
3044 if (pinfo & MIPS16_INSN_WRITE_X)
3045 mask |= 1 << mips16_to_32_reg_map[MIPS16_EXTRACT_OPERAND (RX, *ip)];
3046 if (pinfo & MIPS16_INSN_WRITE_Y)
3047 mask |= 1 << mips16_to_32_reg_map[MIPS16_EXTRACT_OPERAND (RY, *ip)];
3048 if (pinfo & MIPS16_INSN_WRITE_Z)
3049 mask |= 1 << mips16_to_32_reg_map[MIPS16_EXTRACT_OPERAND (RZ, *ip)];
3050 if (pinfo & MIPS16_INSN_WRITE_T)
3052 if (pinfo & MIPS16_INSN_WRITE_SP)
3054 if (pinfo & MIPS16_INSN_WRITE_31)
3056 if (pinfo & MIPS16_INSN_WRITE_GPR_Y)
3057 mask |= 1 << MIPS16OP_EXTRACT_REG32R (ip->insn_opcode);
3061 if (pinfo & INSN_WRITE_GPR_D)
3062 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RD, *ip);
3063 if (pinfo & INSN_WRITE_GPR_T)
3064 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RT, *ip);
3065 if (pinfo & INSN_WRITE_GPR_S)
3066 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RS, *ip);
3067 if (pinfo & INSN_WRITE_GPR_31)
3069 if (pinfo2 & INSN2_WRITE_GPR_Z)
3070 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RZ, *ip);
3072 if (mips_opts.micromips)
3074 if (pinfo2 & INSN2_WRITE_GPR_MB)
3075 mask |= 1 << micromips_to_32_reg_b_map[EXTRACT_OPERAND (1, MB, *ip)];
3076 if (pinfo2 & INSN2_WRITE_GPR_MHI)
3078 mask |= 1 << micromips_to_32_reg_h_map[EXTRACT_OPERAND (1, MH, *ip)];
3079 mask |= 1 << micromips_to_32_reg_i_map[EXTRACT_OPERAND (1, MI, *ip)];
3081 if (pinfo2 & INSN2_WRITE_GPR_MJ)
3082 mask |= 1 << EXTRACT_OPERAND (1, MJ, *ip);
3083 if (pinfo2 & INSN2_WRITE_GPR_MP)
3084 mask |= 1 << EXTRACT_OPERAND (1, MP, *ip);
3086 /* Don't include register 0. */
3090 /* Return the mask of floating-point registers that IP reads. */
3093 fpr_read_mask (const struct mips_cl_insn *ip)
3095 unsigned long pinfo, pinfo2;
3099 pinfo = ip->insn_mo->pinfo;
3100 pinfo2 = ip->insn_mo->pinfo2;
3101 if (!mips_opts.mips16)
3103 if (pinfo2 & INSN2_READ_FPR_D)
3104 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FD, *ip);
3105 if (pinfo & INSN_READ_FPR_S)
3106 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FS, *ip);
3107 if (pinfo & INSN_READ_FPR_T)
3108 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FT, *ip);
3109 if (pinfo & INSN_READ_FPR_R)
3110 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FR, *ip);
3111 if (pinfo2 & INSN2_READ_FPR_Z)
3112 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FZ, *ip);
3114 /* Conservatively treat all operands to an FP_D instruction are doubles.
3115 (This is overly pessimistic for things like cvt.d.s.) */
3116 if (HAVE_32BIT_FPRS && (pinfo & FP_D))
3121 /* Return the mask of floating-point registers that IP writes. */
3124 fpr_write_mask (const struct mips_cl_insn *ip)
3126 unsigned long pinfo, pinfo2;
3130 pinfo = ip->insn_mo->pinfo;
3131 pinfo2 = ip->insn_mo->pinfo2;
3132 if (!mips_opts.mips16)
3134 if (pinfo & INSN_WRITE_FPR_D)
3135 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FD, *ip);
3136 if (pinfo & INSN_WRITE_FPR_S)
3137 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FS, *ip);
3138 if (pinfo & INSN_WRITE_FPR_T)
3139 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FT, *ip);
3140 if (pinfo2 & INSN2_WRITE_FPR_Z)
3141 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FZ, *ip);
3143 /* Conservatively treat all operands to an FP_D instruction are doubles.
3144 (This is overly pessimistic for things like cvt.s.d.) */
3145 if (HAVE_32BIT_FPRS && (pinfo & FP_D))
3150 /* Classify an instruction according to the FIX_VR4120_* enumeration.
3151 Return NUM_FIX_VR4120_CLASSES if the instruction isn't affected
3152 by VR4120 errata. */
3155 classify_vr4120_insn (const char *name)
3157 if (strncmp (name, "macc", 4) == 0)
3158 return FIX_VR4120_MACC;
3159 if (strncmp (name, "dmacc", 5) == 0)
3160 return FIX_VR4120_DMACC;
3161 if (strncmp (name, "mult", 4) == 0)
3162 return FIX_VR4120_MULT;
3163 if (strncmp (name, "dmult", 5) == 0)
3164 return FIX_VR4120_DMULT;
3165 if (strstr (name, "div"))
3166 return FIX_VR4120_DIV;
3167 if (strcmp (name, "mtlo") == 0 || strcmp (name, "mthi") == 0)
3168 return FIX_VR4120_MTHILO;
3169 return NUM_FIX_VR4120_CLASSES;
3172 #define INSN_ERET 0x42000018
3173 #define INSN_DERET 0x4200001f
3175 /* Return the number of instructions that must separate INSN1 and INSN2,
3176 where INSN1 is the earlier instruction. Return the worst-case value
3177 for any INSN2 if INSN2 is null. */
3180 insns_between (const struct mips_cl_insn *insn1,
3181 const struct mips_cl_insn *insn2)
3183 unsigned long pinfo1, pinfo2;
3186 /* This function needs to know which pinfo flags are set for INSN2
3187 and which registers INSN2 uses. The former is stored in PINFO2 and
3188 the latter is tested via INSN2_USES_GPR. If INSN2 is null, PINFO2
3189 will have every flag set and INSN2_USES_GPR will always return true. */
3190 pinfo1 = insn1->insn_mo->pinfo;
3191 pinfo2 = insn2 ? insn2->insn_mo->pinfo : ~0U;
3193 #define INSN2_USES_GPR(REG) \
3194 (insn2 == NULL || (gpr_read_mask (insn2) & (1U << (REG))) != 0)
3196 /* For most targets, write-after-read dependencies on the HI and LO
3197 registers must be separated by at least two instructions. */
3198 if (!hilo_interlocks)
3200 if ((pinfo1 & INSN_READ_LO) && (pinfo2 & INSN_WRITE_LO))
3202 if ((pinfo1 & INSN_READ_HI) && (pinfo2 & INSN_WRITE_HI))
3206 /* If we're working around r7000 errata, there must be two instructions
3207 between an mfhi or mflo and any instruction that uses the result. */
3208 if (mips_7000_hilo_fix
3209 && !mips_opts.micromips
3210 && MF_HILO_INSN (pinfo1)
3211 && INSN2_USES_GPR (EXTRACT_OPERAND (0, RD, *insn1)))
3214 /* If we're working around 24K errata, one instruction is required
3215 if an ERET or DERET is followed by a branch instruction. */
3216 if (mips_fix_24k && !mips_opts.micromips)
3218 if (insn1->insn_opcode == INSN_ERET
3219 || insn1->insn_opcode == INSN_DERET)
3222 || insn2->insn_opcode == INSN_ERET
3223 || insn2->insn_opcode == INSN_DERET
3224 || delayed_branch_p (insn2))
3229 /* If working around VR4120 errata, check for combinations that need
3230 a single intervening instruction. */
3231 if (mips_fix_vr4120 && !mips_opts.micromips)
3233 unsigned int class1, class2;
3235 class1 = classify_vr4120_insn (insn1->insn_mo->name);
3236 if (class1 != NUM_FIX_VR4120_CLASSES && vr4120_conflicts[class1] != 0)
3240 class2 = classify_vr4120_insn (insn2->insn_mo->name);
3241 if (vr4120_conflicts[class1] & (1 << class2))
3246 if (!HAVE_CODE_COMPRESSION)
3248 /* Check for GPR or coprocessor load delays. All such delays
3249 are on the RT register. */
3250 /* Itbl support may require additional care here. */
3251 if ((!gpr_interlocks && (pinfo1 & INSN_LOAD_MEMORY_DELAY))
3252 || (!cop_interlocks && (pinfo1 & INSN_LOAD_COPROC_DELAY)))
3254 know (pinfo1 & INSN_WRITE_GPR_T);
3255 if (INSN2_USES_GPR (EXTRACT_OPERAND (0, RT, *insn1)))
3259 /* Check for generic coprocessor hazards.
3261 This case is not handled very well. There is no special
3262 knowledge of CP0 handling, and the coprocessors other than
3263 the floating point unit are not distinguished at all. */
3264 /* Itbl support may require additional care here. FIXME!
3265 Need to modify this to include knowledge about
3266 user specified delays! */
3267 else if ((!cop_interlocks && (pinfo1 & INSN_COPROC_MOVE_DELAY))
3268 || (!cop_mem_interlocks && (pinfo1 & INSN_COPROC_MEMORY_DELAY)))
3270 /* Handle cases where INSN1 writes to a known general coprocessor
3271 register. There must be a one instruction delay before INSN2
3272 if INSN2 reads that register, otherwise no delay is needed. */
3273 mask = fpr_write_mask (insn1);
3276 if (!insn2 || (mask & fpr_read_mask (insn2)) != 0)
3281 /* Read-after-write dependencies on the control registers
3282 require a two-instruction gap. */
3283 if ((pinfo1 & INSN_WRITE_COND_CODE)
3284 && (pinfo2 & INSN_READ_COND_CODE))
3287 /* We don't know exactly what INSN1 does. If INSN2 is
3288 also a coprocessor instruction, assume there must be
3289 a one instruction gap. */
3290 if (pinfo2 & INSN_COP)
3295 /* Check for read-after-write dependencies on the coprocessor
3296 control registers in cases where INSN1 does not need a general
3297 coprocessor delay. This means that INSN1 is a floating point
3298 comparison instruction. */
3299 /* Itbl support may require additional care here. */
3300 else if (!cop_interlocks
3301 && (pinfo1 & INSN_WRITE_COND_CODE)
3302 && (pinfo2 & INSN_READ_COND_CODE))
3306 #undef INSN2_USES_GPR
3311 /* Return the number of nops that would be needed to work around the
3312 VR4130 mflo/mfhi errata if instruction INSN immediately followed
3313 the MAX_VR4130_NOPS instructions described by HIST. Ignore hazards
3314 that are contained within the first IGNORE instructions of HIST. */
3317 nops_for_vr4130 (int ignore, const struct mips_cl_insn *hist,
3318 const struct mips_cl_insn *insn)
3323 /* Check if the instruction writes to HI or LO. MTHI and MTLO
3324 are not affected by the errata. */
3326 && ((insn->insn_mo->pinfo & (INSN_WRITE_HI | INSN_WRITE_LO)) == 0
3327 || strcmp (insn->insn_mo->name, "mtlo") == 0
3328 || strcmp (insn->insn_mo->name, "mthi") == 0))
3331 /* Search for the first MFLO or MFHI. */
3332 for (i = 0; i < MAX_VR4130_NOPS; i++)
3333 if (MF_HILO_INSN (hist[i].insn_mo->pinfo))
3335 /* Extract the destination register. */
3336 mask = gpr_write_mask (&hist[i]);
3338 /* No nops are needed if INSN reads that register. */
3339 if (insn != NULL && (gpr_read_mask (insn) & mask) != 0)
3342 /* ...or if any of the intervening instructions do. */
3343 for (j = 0; j < i; j++)
3344 if (gpr_read_mask (&hist[j]) & mask)
3348 return MAX_VR4130_NOPS - i;
3353 #define BASE_REG_EQ(INSN1, INSN2) \
3354 ((((INSN1) >> OP_SH_RS) & OP_MASK_RS) \
3355 == (((INSN2) >> OP_SH_RS) & OP_MASK_RS))
3357 /* Return the minimum alignment for this store instruction. */
3360 fix_24k_align_to (const struct mips_opcode *mo)
3362 if (strcmp (mo->name, "sh") == 0)
3365 if (strcmp (mo->name, "swc1") == 0
3366 || strcmp (mo->name, "swc2") == 0
3367 || strcmp (mo->name, "sw") == 0
3368 || strcmp (mo->name, "sc") == 0
3369 || strcmp (mo->name, "s.s") == 0)
3372 if (strcmp (mo->name, "sdc1") == 0
3373 || strcmp (mo->name, "sdc2") == 0
3374 || strcmp (mo->name, "s.d") == 0)
3381 struct fix_24k_store_info
3383 /* Immediate offset, if any, for this store instruction. */
3385 /* Alignment required by this store instruction. */
3387 /* True for register offsets. */
3388 int register_offset;
3391 /* Comparison function used by qsort. */
3394 fix_24k_sort (const void *a, const void *b)
3396 const struct fix_24k_store_info *pos1 = a;
3397 const struct fix_24k_store_info *pos2 = b;
3399 return (pos1->off - pos2->off);
3402 /* INSN is a store instruction. Try to record the store information
3403 in STINFO. Return false if the information isn't known. */
3406 fix_24k_record_store_info (struct fix_24k_store_info *stinfo,
3407 const struct mips_cl_insn *insn)
3409 /* The instruction must have a known offset. */
3410 if (!insn->complete_p || !strstr (insn->insn_mo->args, "o("))
3413 stinfo->off = (insn->insn_opcode >> OP_SH_IMMEDIATE) & OP_MASK_IMMEDIATE;
3414 stinfo->align_to = fix_24k_align_to (insn->insn_mo);
3418 /* Return the number of nops that would be needed to work around the 24k
3419 "lost data on stores during refill" errata if instruction INSN
3420 immediately followed the 2 instructions described by HIST.
3421 Ignore hazards that are contained within the first IGNORE
3422 instructions of HIST.
3424 Problem: The FSB (fetch store buffer) acts as an intermediate buffer
3425 for the data cache refills and store data. The following describes
3426 the scenario where the store data could be lost.
3428 * A data cache miss, due to either a load or a store, causing fill
3429 data to be supplied by the memory subsystem
3430 * The first three doublewords of fill data are returned and written
3432 * A sequence of four stores occurs in consecutive cycles around the
3433 final doubleword of the fill:
3437 * Zero, One or more instructions
3440 The four stores A-D must be to different doublewords of the line that
3441 is being filled. The fourth instruction in the sequence above permits
3442 the fill of the final doubleword to be transferred from the FSB into
3443 the cache. In the sequence above, the stores may be either integer
3444 (sb, sh, sw, swr, swl, sc) or coprocessor (swc1/swc2, sdc1/sdc2,
3445 swxc1, sdxc1, suxc1) stores, as long as the four stores are to
3446 different doublewords on the line. If the floating point unit is
3447 running in 1:2 mode, it is not possible to create the sequence above
3448 using only floating point store instructions.
3450 In this case, the cache line being filled is incorrectly marked
3451 invalid, thereby losing the data from any store to the line that
3452 occurs between the original miss and the completion of the five
3453 cycle sequence shown above.
3455 The workarounds are:
3457 * Run the data cache in write-through mode.
3458 * Insert a non-store instruction between
3459 Store A and Store B or Store B and Store C. */
3462 nops_for_24k (int ignore, const struct mips_cl_insn *hist,
3463 const struct mips_cl_insn *insn)
3465 struct fix_24k_store_info pos[3];
3466 int align, i, base_offset;
3471 /* If the previous instruction wasn't a store, there's nothing to
3473 if ((hist[0].insn_mo->pinfo & INSN_STORE_MEMORY) == 0)
3476 /* If the instructions after the previous one are unknown, we have
3477 to assume the worst. */
3481 /* Check whether we are dealing with three consecutive stores. */
3482 if ((insn->insn_mo->pinfo & INSN_STORE_MEMORY) == 0
3483 || (hist[1].insn_mo->pinfo & INSN_STORE_MEMORY) == 0)
3486 /* If we don't know the relationship between the store addresses,
3487 assume the worst. */
3488 if (!BASE_REG_EQ (insn->insn_opcode, hist[0].insn_opcode)
3489 || !BASE_REG_EQ (insn->insn_opcode, hist[1].insn_opcode))
3492 if (!fix_24k_record_store_info (&pos[0], insn)
3493 || !fix_24k_record_store_info (&pos[1], &hist[0])
3494 || !fix_24k_record_store_info (&pos[2], &hist[1]))
3497 qsort (&pos, 3, sizeof (struct fix_24k_store_info), fix_24k_sort);
3499 /* Pick a value of ALIGN and X such that all offsets are adjusted by
3500 X bytes and such that the base register + X is known to be aligned
3503 if (((insn->insn_opcode >> OP_SH_RS) & OP_MASK_RS) == SP)
3507 align = pos[0].align_to;
3508 base_offset = pos[0].off;
3509 for (i = 1; i < 3; i++)
3510 if (align < pos[i].align_to)
3512 align = pos[i].align_to;
3513 base_offset = pos[i].off;
3515 for (i = 0; i < 3; i++)
3516 pos[i].off -= base_offset;
3519 pos[0].off &= ~align + 1;
3520 pos[1].off &= ~align + 1;
3521 pos[2].off &= ~align + 1;
3523 /* If any two stores write to the same chunk, they also write to the
3524 same doubleword. The offsets are still sorted at this point. */
3525 if (pos[0].off == pos[1].off || pos[1].off == pos[2].off)
3528 /* A range of at least 9 bytes is needed for the stores to be in
3529 non-overlapping doublewords. */
3530 if (pos[2].off - pos[0].off <= 8)
3533 if (pos[2].off - pos[1].off >= 24
3534 || pos[1].off - pos[0].off >= 24
3535 || pos[2].off - pos[0].off >= 32)
3541 /* Return the number of nops that would be needed if instruction INSN
3542 immediately followed the MAX_NOPS instructions given by HIST,
3543 where HIST[0] is the most recent instruction. Ignore hazards
3544 between INSN and the first IGNORE instructions in HIST.
3546 If INSN is null, return the worse-case number of nops for any
3550 nops_for_insn (int ignore, const struct mips_cl_insn *hist,
3551 const struct mips_cl_insn *insn)
3553 int i, nops, tmp_nops;
3556 for (i = ignore; i < MAX_DELAY_NOPS; i++)
3558 tmp_nops = insns_between (hist + i, insn) - i;
3559 if (tmp_nops > nops)
3563 if (mips_fix_vr4130 && !mips_opts.micromips)
3565 tmp_nops = nops_for_vr4130 (ignore, hist, insn);
3566 if (tmp_nops > nops)
3570 if (mips_fix_24k && !mips_opts.micromips)
3572 tmp_nops = nops_for_24k (ignore, hist, insn);
3573 if (tmp_nops > nops)
3580 /* The variable arguments provide NUM_INSNS extra instructions that
3581 might be added to HIST. Return the largest number of nops that
3582 would be needed after the extended sequence, ignoring hazards
3583 in the first IGNORE instructions. */
3586 nops_for_sequence (int num_insns, int ignore,
3587 const struct mips_cl_insn *hist, ...)
3590 struct mips_cl_insn buffer[MAX_NOPS];
3591 struct mips_cl_insn *cursor;
3594 va_start (args, hist);
3595 cursor = buffer + num_insns;
3596 memcpy (cursor, hist, (MAX_NOPS - num_insns) * sizeof (*cursor));
3597 while (cursor > buffer)
3598 *--cursor = *va_arg (args, const struct mips_cl_insn *);
3600 nops = nops_for_insn (ignore, buffer, NULL);
3605 /* Like nops_for_insn, but if INSN is a branch, take into account the
3606 worst-case delay for the branch target. */
3609 nops_for_insn_or_target (int ignore, const struct mips_cl_insn *hist,
3610 const struct mips_cl_insn *insn)
3614 nops = nops_for_insn (ignore, hist, insn);
3615 if (delayed_branch_p (insn))
3617 tmp_nops = nops_for_sequence (2, ignore ? ignore + 2 : 0,
3618 hist, insn, get_delay_slot_nop (insn));
3619 if (tmp_nops > nops)
3622 else if (compact_branch_p (insn))
3624 tmp_nops = nops_for_sequence (1, ignore ? ignore + 1 : 0, hist, insn);
3625 if (tmp_nops > nops)
3631 /* Fix NOP issue: Replace nops by "or at,at,zero". */
3634 fix_loongson2f_nop (struct mips_cl_insn * ip)
3636 gas_assert (!HAVE_CODE_COMPRESSION);
3637 if (strcmp (ip->insn_mo->name, "nop") == 0)
3638 ip->insn_opcode = LOONGSON2F_NOP_INSN;
3641 /* Fix Jump Issue: Eliminate instruction fetch from outside 256M region
3642 jr target pc &= 'hffff_ffff_cfff_ffff. */
3645 fix_loongson2f_jump (struct mips_cl_insn * ip)
3647 gas_assert (!HAVE_CODE_COMPRESSION);
3648 if (strcmp (ip->insn_mo->name, "j") == 0
3649 || strcmp (ip->insn_mo->name, "jr") == 0
3650 || strcmp (ip->insn_mo->name, "jalr") == 0)
3658 sreg = EXTRACT_OPERAND (0, RS, *ip);
3659 if (sreg == ZERO || sreg == KT0 || sreg == KT1 || sreg == ATREG)
3662 ep.X_op = O_constant;
3663 ep.X_add_number = 0xcfff0000;
3664 macro_build (&ep, "lui", "t,u", ATREG, BFD_RELOC_HI16);
3665 ep.X_add_number = 0xffff;
3666 macro_build (&ep, "ori", "t,r,i", ATREG, ATREG, BFD_RELOC_LO16);
3667 macro_build (NULL, "and", "d,v,t", sreg, sreg, ATREG);
3672 fix_loongson2f (struct mips_cl_insn * ip)
3674 if (mips_fix_loongson2f_nop)
3675 fix_loongson2f_nop (ip);
3677 if (mips_fix_loongson2f_jump)
3678 fix_loongson2f_jump (ip);
3681 /* IP is a branch that has a delay slot, and we need to fill it
3682 automatically. Return true if we can do that by swapping IP
3683 with the previous instruction. */
3686 can_swap_branch_p (struct mips_cl_insn *ip)
3688 unsigned long pinfo, pinfo2, prev_pinfo, prev_pinfo2;
3689 unsigned int gpr_read, gpr_write, prev_gpr_read, prev_gpr_write;
3691 /* -O2 and above is required for this optimization. */
3692 if (mips_optimize < 2)
3695 /* If we have seen .set volatile or .set nomove, don't optimize. */
3696 if (mips_opts.nomove)
3699 /* We can't swap if the previous instruction's position is fixed. */
3700 if (history[0].fixed_p)
3703 /* If the previous previous insn was in a .set noreorder, we can't
3704 swap. Actually, the MIPS assembler will swap in this situation.
3705 However, gcc configured -with-gnu-as will generate code like
3713 in which we can not swap the bne and INSN. If gcc is not configured
3714 -with-gnu-as, it does not output the .set pseudo-ops. */
3715 if (history[1].noreorder_p)
3718 /* If the previous instruction had a fixup in mips16 mode, we can not swap.
3719 This means that the previous instruction was a 4-byte one anyhow. */
3720 if (mips_opts.mips16 && history[0].fixp[0])
3723 /* If the branch is itself the target of a branch, we can not swap.
3724 We cheat on this; all we check for is whether there is a label on
3725 this instruction. If there are any branches to anything other than
3726 a label, users must use .set noreorder. */
3727 if (seg_info (now_seg)->label_list)
3730 /* If the previous instruction is in a variant frag other than this
3731 branch's one, we cannot do the swap. This does not apply to
3732 MIPS16 code, which uses variant frags for different purposes. */
3733 if (!mips_opts.mips16
3735 && history[0].frag->fr_type == rs_machine_dependent)
3738 /* We do not swap with instructions that cannot architecturally
3739 be placed in a branch delay slot, such as SYNC or ERET. We
3740 also refrain from swapping with a trap instruction, since it
3741 complicates trap handlers to have the trap instruction be in
3743 prev_pinfo = history[0].insn_mo->pinfo;
3744 if (prev_pinfo & INSN_NO_DELAY_SLOT)
3747 /* Check for conflicts between the branch and the instructions
3748 before the candidate delay slot. */
3749 if (nops_for_insn (0, history + 1, ip) > 0)
3752 /* Check for conflicts between the swapped sequence and the
3753 target of the branch. */
3754 if (nops_for_sequence (2, 0, history + 1, ip, history) > 0)
3757 /* If the branch reads a register that the previous
3758 instruction sets, we can not swap. */
3759 gpr_read = gpr_read_mask (ip);
3760 prev_gpr_write = gpr_write_mask (&history[0]);
3761 if (gpr_read & prev_gpr_write)
3764 /* If the branch writes a register that the previous
3765 instruction sets, we can not swap. */
3766 gpr_write = gpr_write_mask (ip);
3767 if (gpr_write & prev_gpr_write)
3770 /* If the branch writes a register that the previous
3771 instruction reads, we can not swap. */
3772 prev_gpr_read = gpr_read_mask (&history[0]);
3773 if (gpr_write & prev_gpr_read)
3776 /* If one instruction sets a condition code and the
3777 other one uses a condition code, we can not swap. */
3778 pinfo = ip->insn_mo->pinfo;
3779 if ((pinfo & INSN_READ_COND_CODE)
3780 && (prev_pinfo & INSN_WRITE_COND_CODE))
3782 if ((pinfo & INSN_WRITE_COND_CODE)
3783 && (prev_pinfo & INSN_READ_COND_CODE))
3786 /* If the previous instruction uses the PC, we can not swap. */
3787 prev_pinfo2 = history[0].insn_mo->pinfo2;
3788 if (mips_opts.mips16 && (prev_pinfo & MIPS16_INSN_READ_PC))
3790 if (mips_opts.micromips && (prev_pinfo2 & INSN2_READ_PC))
3793 /* If the previous instruction has an incorrect size for a fixed
3794 branch delay slot in microMIPS mode, we cannot swap. */
3795 pinfo2 = ip->insn_mo->pinfo2;
3796 if (mips_opts.micromips
3797 && (pinfo2 & INSN2_BRANCH_DELAY_16BIT)
3798 && insn_length (history) != 2)
3800 if (mips_opts.micromips
3801 && (pinfo2 & INSN2_BRANCH_DELAY_32BIT)
3802 && insn_length (history) != 4)
3808 /* Decide how we should add IP to the instruction stream. */
3810 static enum append_method
3811 get_append_method (struct mips_cl_insn *ip)
3813 unsigned long pinfo;
3815 /* The relaxed version of a macro sequence must be inherently
3817 if (mips_relax.sequence == 2)
3820 /* We must not dabble with instructions in a ".set norerorder" block. */
3821 if (mips_opts.noreorder)
3824 /* Otherwise, it's our responsibility to fill branch delay slots. */
3825 if (delayed_branch_p (ip))
3827 if (!branch_likely_p (ip) && can_swap_branch_p (ip))
3830 pinfo = ip->insn_mo->pinfo;
3831 if (mips_opts.mips16
3832 && ISA_SUPPORTS_MIPS16E
3833 && (pinfo & (MIPS16_INSN_READ_X | MIPS16_INSN_READ_31)))
3834 return APPEND_ADD_COMPACT;
3836 return APPEND_ADD_WITH_NOP;
3842 /* IP is a MIPS16 instruction whose opcode we have just changed.
3843 Point IP->insn_mo to the new opcode's definition. */
3846 find_altered_mips16_opcode (struct mips_cl_insn *ip)
3848 const struct mips_opcode *mo, *end;
3850 end = &mips16_opcodes[bfd_mips16_num_opcodes];
3851 for (mo = ip->insn_mo; mo < end; mo++)
3852 if ((ip->insn_opcode & mo->mask) == mo->match)
3860 /* For microMIPS macros, we need to generate a local number label
3861 as the target of branches. */
3862 #define MICROMIPS_LABEL_CHAR '\037'
3863 static unsigned long micromips_target_label;
3864 static char micromips_target_name[32];
3867 micromips_label_name (void)
3869 char *p = micromips_target_name;
3870 char symbol_name_temporary[24];
3878 l = micromips_target_label;
3879 #ifdef LOCAL_LABEL_PREFIX
3880 *p++ = LOCAL_LABEL_PREFIX;
3883 *p++ = MICROMIPS_LABEL_CHAR;
3886 symbol_name_temporary[i++] = l % 10 + '0';
3891 *p++ = symbol_name_temporary[--i];
3894 return micromips_target_name;
3898 micromips_label_expr (expressionS *label_expr)
3900 label_expr->X_op = O_symbol;
3901 label_expr->X_add_symbol = symbol_find_or_make (micromips_label_name ());
3902 label_expr->X_add_number = 0;
3906 micromips_label_inc (void)
3908 micromips_target_label++;
3909 *micromips_target_name = '\0';
3913 micromips_add_label (void)
3917 s = colon (micromips_label_name ());
3918 micromips_label_inc ();
3919 #if defined(OBJ_ELF) || defined(OBJ_MAYBE_ELF)
3921 S_SET_OTHER (s, ELF_ST_SET_MICROMIPS (S_GET_OTHER (s)));
3927 /* If assembling microMIPS code, then return the microMIPS reloc
3928 corresponding to the requested one if any. Otherwise return
3929 the reloc unchanged. */
3931 static bfd_reloc_code_real_type
3932 micromips_map_reloc (bfd_reloc_code_real_type reloc)
3934 static const bfd_reloc_code_real_type relocs[][2] =
3936 /* Keep sorted incrementally by the left-hand key. */
3937 { BFD_RELOC_16_PCREL_S2, BFD_RELOC_MICROMIPS_16_PCREL_S1 },
3938 { BFD_RELOC_GPREL16, BFD_RELOC_MICROMIPS_GPREL16 },
3939 { BFD_RELOC_MIPS_JMP, BFD_RELOC_MICROMIPS_JMP },
3940 { BFD_RELOC_HI16, BFD_RELOC_MICROMIPS_HI16 },
3941 { BFD_RELOC_HI16_S, BFD_RELOC_MICROMIPS_HI16_S },
3942 { BFD_RELOC_LO16, BFD_RELOC_MICROMIPS_LO16 },
3943 { BFD_RELOC_MIPS_LITERAL, BFD_RELOC_MICROMIPS_LITERAL },
3944 { BFD_RELOC_MIPS_GOT16, BFD_RELOC_MICROMIPS_GOT16 },
3945 { BFD_RELOC_MIPS_CALL16, BFD_RELOC_MICROMIPS_CALL16 },
3946 { BFD_RELOC_MIPS_GOT_HI16, BFD_RELOC_MICROMIPS_GOT_HI16 },
3947 { BFD_RELOC_MIPS_GOT_LO16, BFD_RELOC_MICROMIPS_GOT_LO16 },
3948 { BFD_RELOC_MIPS_CALL_HI16, BFD_RELOC_MICROMIPS_CALL_HI16 },
3949 { BFD_RELOC_MIPS_CALL_LO16, BFD_RELOC_MICROMIPS_CALL_LO16 },
3950 { BFD_RELOC_MIPS_SUB, BFD_RELOC_MICROMIPS_SUB },
3951 { BFD_RELOC_MIPS_GOT_PAGE, BFD_RELOC_MICROMIPS_GOT_PAGE },
3952 { BFD_RELOC_MIPS_GOT_OFST, BFD_RELOC_MICROMIPS_GOT_OFST },
3953 { BFD_RELOC_MIPS_GOT_DISP, BFD_RELOC_MICROMIPS_GOT_DISP },
3954 { BFD_RELOC_MIPS_HIGHEST, BFD_RELOC_MICROMIPS_HIGHEST },
3955 { BFD_RELOC_MIPS_HIGHER, BFD_RELOC_MICROMIPS_HIGHER },
3956 { BFD_RELOC_MIPS_SCN_DISP, BFD_RELOC_MICROMIPS_SCN_DISP },
3957 { BFD_RELOC_MIPS_TLS_GD, BFD_RELOC_MICROMIPS_TLS_GD },
3958 { BFD_RELOC_MIPS_TLS_LDM, BFD_RELOC_MICROMIPS_TLS_LDM },
3959 { BFD_RELOC_MIPS_TLS_DTPREL_HI16, BFD_RELOC_MICROMIPS_TLS_DTPREL_HI16 },
3960 { BFD_RELOC_MIPS_TLS_DTPREL_LO16, BFD_RELOC_MICROMIPS_TLS_DTPREL_LO16 },
3961 { BFD_RELOC_MIPS_TLS_GOTTPREL, BFD_RELOC_MICROMIPS_TLS_GOTTPREL },
3962 { BFD_RELOC_MIPS_TLS_TPREL_HI16, BFD_RELOC_MICROMIPS_TLS_TPREL_HI16 },
3963 { BFD_RELOC_MIPS_TLS_TPREL_LO16, BFD_RELOC_MICROMIPS_TLS_TPREL_LO16 }
3965 bfd_reloc_code_real_type r;
3968 if (!mips_opts.micromips)
3970 for (i = 0; i < ARRAY_SIZE (relocs); i++)
3976 return relocs[i][1];
3981 /* Output an instruction. IP is the instruction information.
3982 ADDRESS_EXPR is an operand of the instruction to be used with
3983 RELOC_TYPE. EXPANSIONP is true if the instruction is part of
3984 a macro expansion. */
3987 append_insn (struct mips_cl_insn *ip, expressionS *address_expr,
3988 bfd_reloc_code_real_type *reloc_type, bfd_boolean expansionp)
3990 unsigned long prev_pinfo2, pinfo;
3991 bfd_boolean relaxed_branch = FALSE;
3992 enum append_method method;
3993 bfd_boolean relax32;
3996 if (mips_fix_loongson2f && !HAVE_CODE_COMPRESSION)
3997 fix_loongson2f (ip);
3999 mips_mark_labels ();
4001 file_ase_mips16 |= mips_opts.mips16;
4002 file_ase_micromips |= mips_opts.micromips;
4004 prev_pinfo2 = history[0].insn_mo->pinfo2;
4005 pinfo = ip->insn_mo->pinfo;
4007 if (mips_opts.micromips
4009 && (((prev_pinfo2 & INSN2_BRANCH_DELAY_16BIT) != 0
4010 && micromips_insn_length (ip->insn_mo) != 2)
4011 || ((prev_pinfo2 & INSN2_BRANCH_DELAY_32BIT) != 0
4012 && micromips_insn_length (ip->insn_mo) != 4)))
4013 as_warn (_("Wrong size instruction in a %u-bit branch delay slot"),
4014 (prev_pinfo2 & INSN2_BRANCH_DELAY_16BIT) != 0 ? 16 : 32);
4016 if (address_expr == NULL)
4018 else if (*reloc_type <= BFD_RELOC_UNUSED
4019 && address_expr->X_op == O_constant)
4024 switch (*reloc_type)
4027 ip->insn_opcode |= address_expr->X_add_number;
4030 case BFD_RELOC_MIPS_HIGHEST:
4031 tmp = (address_expr->X_add_number + 0x800080008000ull) >> 48;
4032 ip->insn_opcode |= tmp & 0xffff;
4035 case BFD_RELOC_MIPS_HIGHER:
4036 tmp = (address_expr->X_add_number + 0x80008000ull) >> 32;
4037 ip->insn_opcode |= tmp & 0xffff;
4040 case BFD_RELOC_HI16_S:
4041 tmp = (address_expr->X_add_number + 0x8000) >> 16;
4042 ip->insn_opcode |= tmp & 0xffff;
4045 case BFD_RELOC_HI16:
4046 ip->insn_opcode |= (address_expr->X_add_number >> 16) & 0xffff;
4049 case BFD_RELOC_UNUSED:
4050 case BFD_RELOC_LO16:
4051 case BFD_RELOC_MIPS_GOT_DISP:
4052 ip->insn_opcode |= address_expr->X_add_number & 0xffff;
4055 case BFD_RELOC_MIPS_JMP:
4059 shift = mips_opts.micromips ? 1 : 2;
4060 if ((address_expr->X_add_number & ((1 << shift) - 1)) != 0)
4061 as_bad (_("jump to misaligned address (0x%lx)"),
4062 (unsigned long) address_expr->X_add_number);
4063 ip->insn_opcode |= ((address_expr->X_add_number >> shift)
4069 case BFD_RELOC_MIPS16_JMP:
4070 if ((address_expr->X_add_number & 3) != 0)
4071 as_bad (_("jump to misaligned address (0x%lx)"),
4072 (unsigned long) address_expr->X_add_number);
4074 (((address_expr->X_add_number & 0x7c0000) << 3)
4075 | ((address_expr->X_add_number & 0xf800000) >> 7)
4076 | ((address_expr->X_add_number & 0x3fffc) >> 2));
4080 case BFD_RELOC_16_PCREL_S2:
4084 shift = mips_opts.micromips ? 1 : 2;
4085 if ((address_expr->X_add_number & ((1 << shift) - 1)) != 0)
4086 as_bad (_("branch to misaligned address (0x%lx)"),
4087 (unsigned long) address_expr->X_add_number);
4088 if (!mips_relax_branch)
4090 if ((address_expr->X_add_number + (1 << (shift + 15)))
4091 & ~((1 << (shift + 16)) - 1))
4092 as_bad (_("branch address range overflow (0x%lx)"),
4093 (unsigned long) address_expr->X_add_number);
4094 ip->insn_opcode |= ((address_expr->X_add_number >> shift)
4106 if (mips_relax.sequence != 2 && !mips_opts.noreorder)
4108 /* There are a lot of optimizations we could do that we don't.
4109 In particular, we do not, in general, reorder instructions.
4110 If you use gcc with optimization, it will reorder
4111 instructions and generally do much more optimization then we
4112 do here; repeating all that work in the assembler would only
4113 benefit hand written assembly code, and does not seem worth
4115 int nops = (mips_optimize == 0
4116 ? nops_for_insn (0, history, NULL)
4117 : nops_for_insn_or_target (0, history, ip));
4121 unsigned long old_frag_offset;
4124 old_frag = frag_now;
4125 old_frag_offset = frag_now_fix ();
4127 for (i = 0; i < nops; i++)
4128 add_fixed_insn (NOP_INSN);
4129 insert_into_history (0, nops, NOP_INSN);
4133 listing_prev_line ();
4134 /* We may be at the start of a variant frag. In case we
4135 are, make sure there is enough space for the frag
4136 after the frags created by listing_prev_line. The
4137 argument to frag_grow here must be at least as large
4138 as the argument to all other calls to frag_grow in
4139 this file. We don't have to worry about being in the
4140 middle of a variant frag, because the variants insert
4141 all needed nop instructions themselves. */
4145 mips_move_labels ();
4147 #ifndef NO_ECOFF_DEBUGGING
4148 if (ECOFF_DEBUGGING)
4149 ecoff_fix_loc (old_frag, old_frag_offset);
4153 else if (mips_relax.sequence != 2 && prev_nop_frag != NULL)
4157 /* Work out how many nops in prev_nop_frag are needed by IP,
4158 ignoring hazards generated by the first prev_nop_frag_since
4160 nops = nops_for_insn_or_target (prev_nop_frag_since, history, ip);
4161 gas_assert (nops <= prev_nop_frag_holds);
4163 /* Enforce NOPS as a minimum. */
4164 if (nops > prev_nop_frag_required)
4165 prev_nop_frag_required = nops;
4167 if (prev_nop_frag_holds == prev_nop_frag_required)
4169 /* Settle for the current number of nops. Update the history
4170 accordingly (for the benefit of any future .set reorder code). */
4171 prev_nop_frag = NULL;
4172 insert_into_history (prev_nop_frag_since,
4173 prev_nop_frag_holds, NOP_INSN);
4177 /* Allow this instruction to replace one of the nops that was
4178 tentatively added to prev_nop_frag. */
4179 prev_nop_frag->fr_fix -= NOP_INSN_SIZE;
4180 prev_nop_frag_holds--;
4181 prev_nop_frag_since++;
4185 method = get_append_method (ip);
4186 branch_disp = method == APPEND_SWAP ? insn_length (history) : 0;
4189 /* The value passed to dwarf2_emit_insn is the distance between
4190 the beginning of the current instruction and the address that
4191 should be recorded in the debug tables. This is normally the
4194 For MIPS16/microMIPS debug info we want to use ISA-encoded
4195 addresses, so we use -1 for an address higher by one than the
4198 If the instruction produced is a branch that we will swap with
4199 the preceding instruction, then we add the displacement by which
4200 the branch will be moved backwards. This is more appropriate
4201 and for MIPS16/microMIPS code also prevents a debugger from
4202 placing a breakpoint in the middle of the branch (and corrupting
4203 code if software breakpoints are used). */
4204 dwarf2_emit_insn ((HAVE_CODE_COMPRESSION ? -1 : 0) + branch_disp);
4207 relax32 = (mips_relax_branch
4208 /* Don't try branch relaxation within .set nomacro, or within
4209 .set noat if we use $at for PIC computations. If it turns
4210 out that the branch was out-of-range, we'll get an error. */
4211 && !mips_opts.warn_about_macros
4212 && (mips_opts.at || mips_pic == NO_PIC)
4213 /* Don't relax BPOSGE32/64 as they have no complementing
4215 && !(ip->insn_mo->membership & (INSN_DSP64 | INSN_DSP)));
4217 if (!HAVE_CODE_COMPRESSION
4220 && *reloc_type == BFD_RELOC_16_PCREL_S2
4221 && delayed_branch_p (ip))
4223 relaxed_branch = TRUE;
4224 add_relaxed_insn (ip, (relaxed_branch_length
4226 uncond_branch_p (ip) ? -1
4227 : branch_likely_p (ip) ? 1
4231 uncond_branch_p (ip),
4232 branch_likely_p (ip),
4233 pinfo & INSN_WRITE_GPR_31,
4235 address_expr->X_add_symbol,
4236 address_expr->X_add_number);
4237 *reloc_type = BFD_RELOC_UNUSED;
4239 else if (mips_opts.micromips
4241 && ((relax32 && *reloc_type == BFD_RELOC_16_PCREL_S2)
4242 || *reloc_type > BFD_RELOC_UNUSED)
4243 && (delayed_branch_p (ip) || compact_branch_p (ip))
4244 /* Don't try branch relaxation when users specify
4245 16-bit/32-bit instructions. */
4246 && !forced_insn_length)
4248 bfd_boolean relax16 = *reloc_type > BFD_RELOC_UNUSED;
4249 int type = relax16 ? *reloc_type - BFD_RELOC_UNUSED : 0;
4250 int uncond = uncond_branch_p (ip) ? -1 : 0;
4251 int compact = compact_branch_p (ip);
4252 int al = pinfo & INSN_WRITE_GPR_31;
4255 gas_assert (address_expr != NULL);
4256 gas_assert (!mips_relax.sequence);
4258 relaxed_branch = TRUE;
4259 length32 = relaxed_micromips_32bit_branch_length (NULL, NULL, uncond);
4260 add_relaxed_insn (ip, relax32 ? length32 : 4, relax16 ? 2 : 4,
4261 RELAX_MICROMIPS_ENCODE (type, AT, uncond, compact, al,
4263 address_expr->X_add_symbol,
4264 address_expr->X_add_number);
4265 *reloc_type = BFD_RELOC_UNUSED;
4267 else if (mips_opts.mips16 && *reloc_type > BFD_RELOC_UNUSED)
4269 /* We need to set up a variant frag. */
4270 gas_assert (address_expr != NULL);
4271 add_relaxed_insn (ip, 4, 0,
4273 (*reloc_type - BFD_RELOC_UNUSED,
4274 forced_insn_length == 2, forced_insn_length == 4,
4275 delayed_branch_p (&history[0]),
4276 history[0].mips16_absolute_jump_p),
4277 make_expr_symbol (address_expr), 0);
4279 else if (mips_opts.mips16
4281 && *reloc_type != BFD_RELOC_MIPS16_JMP)
4283 if (!delayed_branch_p (ip))
4284 /* Make sure there is enough room to swap this instruction with
4285 a following jump instruction. */
4287 add_fixed_insn (ip);
4291 if (mips_opts.mips16
4292 && mips_opts.noreorder
4293 && delayed_branch_p (&history[0]))
4294 as_warn (_("extended instruction in delay slot"));
4296 if (mips_relax.sequence)
4298 /* If we've reached the end of this frag, turn it into a variant
4299 frag and record the information for the instructions we've
4301 if (frag_room () < 4)
4302 relax_close_frag ();
4303 mips_relax.sizes[mips_relax.sequence - 1] += insn_length (ip);
4306 if (mips_relax.sequence != 2)
4308 if (mips_macro_warning.first_insn_sizes[0] == 0)
4309 mips_macro_warning.first_insn_sizes[0] = insn_length (ip);
4310 mips_macro_warning.sizes[0] += insn_length (ip);
4311 mips_macro_warning.insns[0]++;
4313 if (mips_relax.sequence != 1)
4315 if (mips_macro_warning.first_insn_sizes[1] == 0)
4316 mips_macro_warning.first_insn_sizes[1] = insn_length (ip);
4317 mips_macro_warning.sizes[1] += insn_length (ip);
4318 mips_macro_warning.insns[1]++;
4321 if (mips_opts.mips16)
4324 ip->mips16_absolute_jump_p = (*reloc_type == BFD_RELOC_MIPS16_JMP);
4326 add_fixed_insn (ip);
4329 if (!ip->complete_p && *reloc_type < BFD_RELOC_UNUSED)
4331 bfd_reloc_code_real_type final_type[3];
4332 reloc_howto_type *howto0;
4333 reloc_howto_type *howto;
4336 /* Perform any necessary conversion to microMIPS relocations
4337 and find out how many relocations there actually are. */
4338 for (i = 0; i < 3 && reloc_type[i] != BFD_RELOC_UNUSED; i++)
4339 final_type[i] = micromips_map_reloc (reloc_type[i]);
4341 /* In a compound relocation, it is the final (outermost)
4342 operator that determines the relocated field. */
4343 howto = howto0 = bfd_reloc_type_lookup (stdoutput, final_type[i - 1]);
4347 /* To reproduce this failure try assembling gas/testsuites/
4348 gas/mips/mips16-intermix.s with a mips-ecoff targeted
4350 as_bad (_("Unsupported MIPS relocation number %d"),
4352 howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_16);
4356 howto0 = bfd_reloc_type_lookup (stdoutput, final_type[0]);
4357 ip->fixp[0] = fix_new_exp (ip->frag, ip->where,
4358 bfd_get_reloc_size (howto),
4360 howto0 && howto0->pc_relative,
4363 /* Tag symbols that have a R_MIPS16_26 relocation against them. */
4364 if (final_type[0] == BFD_RELOC_MIPS16_JMP && ip->fixp[0]->fx_addsy)
4365 *symbol_get_tc (ip->fixp[0]->fx_addsy) = 1;
4367 /* These relocations can have an addend that won't fit in
4368 4 octets for 64bit assembly. */
4370 && ! howto->partial_inplace
4371 && (reloc_type[0] == BFD_RELOC_16
4372 || reloc_type[0] == BFD_RELOC_32
4373 || reloc_type[0] == BFD_RELOC_MIPS_JMP
4374 || reloc_type[0] == BFD_RELOC_GPREL16
4375 || reloc_type[0] == BFD_RELOC_MIPS_LITERAL
4376 || reloc_type[0] == BFD_RELOC_GPREL32
4377 || reloc_type[0] == BFD_RELOC_64
4378 || reloc_type[0] == BFD_RELOC_CTOR
4379 || reloc_type[0] == BFD_RELOC_MIPS_SUB
4380 || reloc_type[0] == BFD_RELOC_MIPS_HIGHEST
4381 || reloc_type[0] == BFD_RELOC_MIPS_HIGHER
4382 || reloc_type[0] == BFD_RELOC_MIPS_SCN_DISP
4383 || reloc_type[0] == BFD_RELOC_MIPS_REL16
4384 || reloc_type[0] == BFD_RELOC_MIPS_RELGOT
4385 || reloc_type[0] == BFD_RELOC_MIPS16_GPREL
4386 || hi16_reloc_p (reloc_type[0])
4387 || lo16_reloc_p (reloc_type[0])))
4388 ip->fixp[0]->fx_no_overflow = 1;
4390 if (mips_relax.sequence)
4392 if (mips_relax.first_fixup == 0)
4393 mips_relax.first_fixup = ip->fixp[0];
4395 else if (reloc_needs_lo_p (*reloc_type))
4397 struct mips_hi_fixup *hi_fixup;
4399 /* Reuse the last entry if it already has a matching %lo. */
4400 hi_fixup = mips_hi_fixup_list;
4402 || !fixup_has_matching_lo_p (hi_fixup->fixp))
4404 hi_fixup = ((struct mips_hi_fixup *)
4405 xmalloc (sizeof (struct mips_hi_fixup)));
4406 hi_fixup->next = mips_hi_fixup_list;
4407 mips_hi_fixup_list = hi_fixup;
4409 hi_fixup->fixp = ip->fixp[0];
4410 hi_fixup->seg = now_seg;
4413 /* Add fixups for the second and third relocations, if given.
4414 Note that the ABI allows the second relocation to be
4415 against RSS_UNDEF, RSS_GP, RSS_GP0 or RSS_LOC. At the
4416 moment we only use RSS_UNDEF, but we could add support
4417 for the others if it ever becomes necessary. */
4418 for (i = 1; i < 3; i++)
4419 if (reloc_type[i] != BFD_RELOC_UNUSED)
4421 ip->fixp[i] = fix_new (ip->frag, ip->where,
4422 ip->fixp[0]->fx_size, NULL, 0,
4423 FALSE, final_type[i]);
4425 /* Use fx_tcbit to mark compound relocs. */
4426 ip->fixp[0]->fx_tcbit = 1;
4427 ip->fixp[i]->fx_tcbit = 1;
4432 /* Update the register mask information. */
4433 mips_gprmask |= gpr_read_mask (ip) | gpr_write_mask (ip);
4434 mips_cprmask[1] |= fpr_read_mask (ip) | fpr_write_mask (ip);
4439 insert_into_history (0, 1, ip);
4442 case APPEND_ADD_WITH_NOP:
4444 struct mips_cl_insn *nop;
4446 insert_into_history (0, 1, ip);
4447 nop = get_delay_slot_nop (ip);
4448 add_fixed_insn (nop);
4449 insert_into_history (0, 1, nop);
4450 if (mips_relax.sequence)
4451 mips_relax.sizes[mips_relax.sequence - 1] += insn_length (nop);
4455 case APPEND_ADD_COMPACT:
4456 /* Convert MIPS16 jr/jalr into a "compact" jump. */
4457 gas_assert (mips_opts.mips16);
4458 ip->insn_opcode |= 0x0080;
4459 find_altered_mips16_opcode (ip);
4461 insert_into_history (0, 1, ip);
4466 struct mips_cl_insn delay = history[0];
4467 if (mips_opts.mips16)
4469 know (delay.frag == ip->frag);
4470 move_insn (ip, delay.frag, delay.where);
4471 move_insn (&delay, ip->frag, ip->where + insn_length (ip));
4473 else if (relaxed_branch)
4475 /* Add the delay slot instruction to the end of the
4476 current frag and shrink the fixed part of the
4477 original frag. If the branch occupies the tail of
4478 the latter, move it backwards to cover the gap. */
4479 delay.frag->fr_fix -= branch_disp;
4480 if (delay.frag == ip->frag)
4481 move_insn (ip, ip->frag, ip->where - branch_disp);
4482 add_fixed_insn (&delay);
4486 move_insn (&delay, ip->frag,
4487 ip->where - branch_disp + insn_length (ip));
4488 move_insn (ip, history[0].frag, history[0].where);
4492 insert_into_history (0, 1, &delay);
4497 /* If we have just completed an unconditional branch, clear the history. */
4498 if ((delayed_branch_p (&history[1]) && uncond_branch_p (&history[1]))
4499 || (compact_branch_p (&history[0]) && uncond_branch_p (&history[0])))
4500 mips_no_prev_insn ();
4502 /* We need to emit a label at the end of branch-likely macros. */
4503 if (emit_branch_likely_macro)
4505 emit_branch_likely_macro = FALSE;
4506 micromips_add_label ();
4509 /* We just output an insn, so the next one doesn't have a label. */
4510 mips_clear_insn_labels ();
4513 /* Forget that there was any previous instruction or label. */
4516 mips_no_prev_insn (void)
4518 prev_nop_frag = NULL;
4519 insert_into_history (0, ARRAY_SIZE (history), NOP_INSN);
4520 mips_clear_insn_labels ();
4523 /* This function must be called before we emit something other than
4524 instructions. It is like mips_no_prev_insn except that it inserts
4525 any NOPS that might be needed by previous instructions. */
4528 mips_emit_delays (void)
4530 if (! mips_opts.noreorder)
4532 int nops = nops_for_insn (0, history, NULL);
4536 add_fixed_insn (NOP_INSN);
4537 mips_move_labels ();
4540 mips_no_prev_insn ();
4543 /* Start a (possibly nested) noreorder block. */
4546 start_noreorder (void)
4548 if (mips_opts.noreorder == 0)
4553 /* None of the instructions before the .set noreorder can be moved. */
4554 for (i = 0; i < ARRAY_SIZE (history); i++)
4555 history[i].fixed_p = 1;
4557 /* Insert any nops that might be needed between the .set noreorder
4558 block and the previous instructions. We will later remove any
4559 nops that turn out not to be needed. */
4560 nops = nops_for_insn (0, history, NULL);
4563 if (mips_optimize != 0)
4565 /* Record the frag which holds the nop instructions, so
4566 that we can remove them if we don't need them. */
4567 frag_grow (nops * NOP_INSN_SIZE);
4568 prev_nop_frag = frag_now;
4569 prev_nop_frag_holds = nops;
4570 prev_nop_frag_required = 0;
4571 prev_nop_frag_since = 0;
4574 for (; nops > 0; --nops)
4575 add_fixed_insn (NOP_INSN);
4577 /* Move on to a new frag, so that it is safe to simply
4578 decrease the size of prev_nop_frag. */
4579 frag_wane (frag_now);
4581 mips_move_labels ();
4583 mips_mark_labels ();
4584 mips_clear_insn_labels ();
4586 mips_opts.noreorder++;
4587 mips_any_noreorder = 1;
4590 /* End a nested noreorder block. */
4593 end_noreorder (void)
4595 mips_opts.noreorder--;
4596 if (mips_opts.noreorder == 0 && prev_nop_frag != NULL)
4598 /* Commit to inserting prev_nop_frag_required nops and go back to
4599 handling nop insertion the .set reorder way. */
4600 prev_nop_frag->fr_fix -= ((prev_nop_frag_holds - prev_nop_frag_required)
4602 insert_into_history (prev_nop_frag_since,
4603 prev_nop_frag_required, NOP_INSN);
4604 prev_nop_frag = NULL;
4608 /* Set up global variables for the start of a new macro. */
4613 memset (&mips_macro_warning.sizes, 0, sizeof (mips_macro_warning.sizes));
4614 memset (&mips_macro_warning.first_insn_sizes, 0,
4615 sizeof (mips_macro_warning.first_insn_sizes));
4616 memset (&mips_macro_warning.insns, 0, sizeof (mips_macro_warning.insns));
4617 mips_macro_warning.delay_slot_p = (mips_opts.noreorder
4618 && delayed_branch_p (&history[0]));
4619 switch (history[0].insn_mo->pinfo2
4620 & (INSN2_BRANCH_DELAY_32BIT | INSN2_BRANCH_DELAY_16BIT))
4622 case INSN2_BRANCH_DELAY_32BIT:
4623 mips_macro_warning.delay_slot_length = 4;
4625 case INSN2_BRANCH_DELAY_16BIT:
4626 mips_macro_warning.delay_slot_length = 2;
4629 mips_macro_warning.delay_slot_length = 0;
4632 mips_macro_warning.first_frag = NULL;
4635 /* Given that a macro is longer than one instruction or of the wrong size,
4636 return the appropriate warning for it. Return null if no warning is
4637 needed. SUBTYPE is a bitmask of RELAX_DELAY_SLOT, RELAX_DELAY_SLOT_16BIT,
4638 RELAX_DELAY_SLOT_SIZE_FIRST, RELAX_DELAY_SLOT_SIZE_SECOND,
4639 and RELAX_NOMACRO. */
4642 macro_warning (relax_substateT subtype)
4644 if (subtype & RELAX_DELAY_SLOT)
4645 return _("Macro instruction expanded into multiple instructions"
4646 " in a branch delay slot");
4647 else if (subtype & RELAX_NOMACRO)
4648 return _("Macro instruction expanded into multiple instructions");
4649 else if (subtype & (RELAX_DELAY_SLOT_SIZE_FIRST
4650 | RELAX_DELAY_SLOT_SIZE_SECOND))
4651 return ((subtype & RELAX_DELAY_SLOT_16BIT)
4652 ? _("Macro instruction expanded into a wrong size instruction"
4653 " in a 16-bit branch delay slot")
4654 : _("Macro instruction expanded into a wrong size instruction"
4655 " in a 32-bit branch delay slot"));
4660 /* Finish up a macro. Emit warnings as appropriate. */
4665 /* Relaxation warning flags. */
4666 relax_substateT subtype = 0;
4668 /* Check delay slot size requirements. */
4669 if (mips_macro_warning.delay_slot_length == 2)
4670 subtype |= RELAX_DELAY_SLOT_16BIT;
4671 if (mips_macro_warning.delay_slot_length != 0)
4673 if (mips_macro_warning.delay_slot_length
4674 != mips_macro_warning.first_insn_sizes[0])
4675 subtype |= RELAX_DELAY_SLOT_SIZE_FIRST;
4676 if (mips_macro_warning.delay_slot_length
4677 != mips_macro_warning.first_insn_sizes[1])
4678 subtype |= RELAX_DELAY_SLOT_SIZE_SECOND;
4681 /* Check instruction count requirements. */
4682 if (mips_macro_warning.insns[0] > 1 || mips_macro_warning.insns[1] > 1)
4684 if (mips_macro_warning.insns[1] > mips_macro_warning.insns[0])
4685 subtype |= RELAX_SECOND_LONGER;
4686 if (mips_opts.warn_about_macros)
4687 subtype |= RELAX_NOMACRO;
4688 if (mips_macro_warning.delay_slot_p)
4689 subtype |= RELAX_DELAY_SLOT;
4692 /* If both alternatives fail to fill a delay slot correctly,
4693 emit the warning now. */
4694 if ((subtype & RELAX_DELAY_SLOT_SIZE_FIRST) != 0
4695 && (subtype & RELAX_DELAY_SLOT_SIZE_SECOND) != 0)
4700 s = subtype & (RELAX_DELAY_SLOT_16BIT
4701 | RELAX_DELAY_SLOT_SIZE_FIRST
4702 | RELAX_DELAY_SLOT_SIZE_SECOND);
4703 msg = macro_warning (s);
4705 as_warn ("%s", msg);
4709 /* If both implementations are longer than 1 instruction, then emit the
4711 if (mips_macro_warning.insns[0] > 1 && mips_macro_warning.insns[1] > 1)
4716 s = subtype & (RELAX_SECOND_LONGER | RELAX_NOMACRO | RELAX_DELAY_SLOT);
4717 msg = macro_warning (s);
4719 as_warn ("%s", msg);
4723 /* If any flags still set, then one implementation might need a warning
4724 and the other either will need one of a different kind or none at all.
4725 Pass any remaining flags over to relaxation. */
4726 if (mips_macro_warning.first_frag != NULL)
4727 mips_macro_warning.first_frag->fr_subtype |= subtype;
4730 /* Instruction operand formats used in macros that vary between
4731 standard MIPS and microMIPS code. */
4733 static const char * const brk_fmt[2] = { "c", "mF" };
4734 static const char * const cop12_fmt[2] = { "E,o(b)", "E,~(b)" };
4735 static const char * const jalr_fmt[2] = { "d,s", "t,s" };
4736 static const char * const lui_fmt[2] = { "t,u", "s,u" };
4737 static const char * const mem12_fmt[2] = { "t,o(b)", "t,~(b)" };
4738 static const char * const mfhl_fmt[2] = { "d", "mj" };
4739 static const char * const shft_fmt[2] = { "d,w,<", "t,r,<" };
4740 static const char * const trap_fmt[2] = { "s,t,q", "s,t,|" };
4742 #define BRK_FMT (brk_fmt[mips_opts.micromips])
4743 #define COP12_FMT (cop12_fmt[mips_opts.micromips])
4744 #define JALR_FMT (jalr_fmt[mips_opts.micromips])
4745 #define LUI_FMT (lui_fmt[mips_opts.micromips])
4746 #define MEM12_FMT (mem12_fmt[mips_opts.micromips])
4747 #define MFHL_FMT (mfhl_fmt[mips_opts.micromips])
4748 #define SHFT_FMT (shft_fmt[mips_opts.micromips])
4749 #define TRAP_FMT (trap_fmt[mips_opts.micromips])
4751 /* Read a macro's relocation codes from *ARGS and store them in *R.
4752 The first argument in *ARGS will be either the code for a single
4753 relocation or -1 followed by the three codes that make up a
4754 composite relocation. */
4757 macro_read_relocs (va_list *args, bfd_reloc_code_real_type *r)
4761 next = va_arg (*args, int);
4763 r[0] = (bfd_reloc_code_real_type) next;
4765 for (i = 0; i < 3; i++)
4766 r[i] = (bfd_reloc_code_real_type) va_arg (*args, int);
4769 /* Build an instruction created by a macro expansion. This is passed
4770 a pointer to the count of instructions created so far, an
4771 expression, the name of the instruction to build, an operand format
4772 string, and corresponding arguments. */
4775 macro_build (expressionS *ep, const char *name, const char *fmt, ...)
4777 const struct mips_opcode *mo = NULL;
4778 bfd_reloc_code_real_type r[3];
4779 const struct mips_opcode *amo;
4780 struct hash_control *hash;
4781 struct mips_cl_insn insn;
4784 va_start (args, fmt);
4786 if (mips_opts.mips16)
4788 mips16_macro_build (ep, name, fmt, &args);
4793 r[0] = BFD_RELOC_UNUSED;
4794 r[1] = BFD_RELOC_UNUSED;
4795 r[2] = BFD_RELOC_UNUSED;
4796 hash = mips_opts.micromips ? micromips_op_hash : op_hash;
4797 amo = (struct mips_opcode *) hash_find (hash, name);
4799 gas_assert (strcmp (name, amo->name) == 0);
4803 /* Search until we get a match for NAME. It is assumed here that
4804 macros will never generate MDMX, MIPS-3D, or MT instructions.
4805 We try to match an instruction that fulfils the branch delay
4806 slot instruction length requirement (if any) of the previous
4807 instruction. While doing this we record the first instruction
4808 seen that matches all the other conditions and use it anyway
4809 if the requirement cannot be met; we will issue an appropriate
4810 warning later on. */
4811 if (strcmp (fmt, amo->args) == 0
4812 && amo->pinfo != INSN_MACRO
4813 && is_opcode_valid (amo)
4814 && is_size_valid (amo))
4816 if (is_delay_slot_valid (amo))
4826 gas_assert (amo->name);
4828 while (strcmp (name, amo->name) == 0);
4831 create_insn (&insn, mo);
4849 INSERT_OPERAND (mips_opts.micromips,
4850 EXTLSB, insn, va_arg (args, int));
4855 /* Note that in the macro case, these arguments are already
4856 in MSB form. (When handling the instruction in the
4857 non-macro case, these arguments are sizes from which
4858 MSB values must be calculated.) */
4859 INSERT_OPERAND (mips_opts.micromips,
4860 INSMSB, insn, va_arg (args, int));
4866 /* Note that in the macro case, these arguments are already
4867 in MSBD form. (When handling the instruction in the
4868 non-macro case, these arguments are sizes from which
4869 MSBD values must be calculated.) */
4870 INSERT_OPERAND (mips_opts.micromips,
4871 EXTMSBD, insn, va_arg (args, int));
4875 gas_assert (!mips_opts.micromips);
4876 INSERT_OPERAND (0, SEQI, insn, va_arg (args, int));
4885 gas_assert (!mips_opts.micromips);
4886 INSERT_OPERAND (0, BP, insn, va_arg (args, int));
4890 gas_assert (mips_opts.micromips);
4894 INSERT_OPERAND (mips_opts.micromips, RT, insn, va_arg (args, int));
4898 gas_assert (!mips_opts.micromips);
4899 INSERT_OPERAND (0, CODE, insn, va_arg (args, int));
4903 gas_assert (!mips_opts.micromips);
4905 INSERT_OPERAND (mips_opts.micromips, FT, insn, va_arg (args, int));
4909 if (mips_opts.micromips)
4910 INSERT_OPERAND (1, RS, insn, va_arg (args, int));
4912 INSERT_OPERAND (0, RD, insn, va_arg (args, int));
4916 gas_assert (!mips_opts.micromips);
4918 INSERT_OPERAND (mips_opts.micromips, RD, insn, va_arg (args, int));
4922 gas_assert (!mips_opts.micromips);
4924 int tmp = va_arg (args, int);
4926 INSERT_OPERAND (0, RT, insn, tmp);
4927 INSERT_OPERAND (0, RD, insn, tmp);
4933 gas_assert (!mips_opts.micromips);
4934 INSERT_OPERAND (0, FS, insn, va_arg (args, int));
4941 INSERT_OPERAND (mips_opts.micromips,
4942 SHAMT, insn, va_arg (args, int));
4946 gas_assert (!mips_opts.micromips);
4947 INSERT_OPERAND (0, FD, insn, va_arg (args, int));
4951 gas_assert (!mips_opts.micromips);
4952 INSERT_OPERAND (0, CODE20, insn, va_arg (args, int));
4956 gas_assert (!mips_opts.micromips);
4957 INSERT_OPERAND (0, CODE19, insn, va_arg (args, int));
4961 gas_assert (!mips_opts.micromips);
4962 INSERT_OPERAND (0, CODE2, insn, va_arg (args, int));
4969 INSERT_OPERAND (mips_opts.micromips, RS, insn, va_arg (args, int));
4974 macro_read_relocs (&args, r);
4975 gas_assert (*r == BFD_RELOC_GPREL16
4976 || *r == BFD_RELOC_MIPS_HIGHER
4977 || *r == BFD_RELOC_HI16_S
4978 || *r == BFD_RELOC_LO16
4979 || *r == BFD_RELOC_MIPS_GOT_OFST);
4983 macro_read_relocs (&args, r);
4987 macro_read_relocs (&args, r);
4988 gas_assert (ep != NULL
4989 && (ep->X_op == O_constant
4990 || (ep->X_op == O_symbol
4991 && (*r == BFD_RELOC_MIPS_HIGHEST
4992 || *r == BFD_RELOC_HI16_S
4993 || *r == BFD_RELOC_HI16
4994 || *r == BFD_RELOC_GPREL16
4995 || *r == BFD_RELOC_MIPS_GOT_HI16
4996 || *r == BFD_RELOC_MIPS_CALL_HI16))));
5000 gas_assert (ep != NULL);
5003 * This allows macro() to pass an immediate expression for
5004 * creating short branches without creating a symbol.
5006 * We don't allow branch relaxation for these branches, as
5007 * they should only appear in ".set nomacro" anyway.
5009 if (ep->X_op == O_constant)
5011 /* For microMIPS we always use relocations for branches.
5012 So we should not resolve immediate values. */
5013 gas_assert (!mips_opts.micromips);
5015 if ((ep->X_add_number & 3) != 0)
5016 as_bad (_("branch to misaligned address (0x%lx)"),
5017 (unsigned long) ep->X_add_number);
5018 if ((ep->X_add_number + 0x20000) & ~0x3ffff)
5019 as_bad (_("branch address range overflow (0x%lx)"),
5020 (unsigned long) ep->X_add_number);
5021 insn.insn_opcode |= (ep->X_add_number >> 2) & 0xffff;
5025 *r = BFD_RELOC_16_PCREL_S2;
5029 gas_assert (ep != NULL);
5030 *r = BFD_RELOC_MIPS_JMP;
5034 gas_assert (!mips_opts.micromips);
5035 INSERT_OPERAND (0, COPZ, insn, va_arg (args, unsigned long));
5039 INSERT_OPERAND (mips_opts.micromips,
5040 CACHE, insn, va_arg (args, unsigned long));
5044 gas_assert (mips_opts.micromips);
5045 INSERT_OPERAND (1, TRAP, insn, va_arg (args, int));
5049 gas_assert (mips_opts.micromips);
5050 INSERT_OPERAND (1, OFFSET10, insn, va_arg (args, int));
5054 INSERT_OPERAND (mips_opts.micromips,
5055 3BITPOS, insn, va_arg (args, unsigned int));
5059 INSERT_OPERAND (mips_opts.micromips,
5060 OFFSET12, insn, va_arg (args, unsigned long));
5064 gas_assert (mips_opts.micromips);
5065 INSERT_OPERAND (1, BCC, insn, va_arg (args, int));
5068 case 'm': /* Opcode extension character. */
5069 gas_assert (mips_opts.micromips);
5073 INSERT_OPERAND (1, MJ, insn, va_arg (args, int));
5077 INSERT_OPERAND (1, MP, insn, va_arg (args, int));
5081 INSERT_OPERAND (1, IMMF, insn, va_arg (args, int));
5095 gas_assert (*r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL);
5097 append_insn (&insn, ep, r, TRUE);
5101 mips16_macro_build (expressionS *ep, const char *name, const char *fmt,
5104 struct mips_opcode *mo;
5105 struct mips_cl_insn insn;
5106 bfd_reloc_code_real_type r[3]
5107 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
5109 mo = (struct mips_opcode *) hash_find (mips16_op_hash, name);
5111 gas_assert (strcmp (name, mo->name) == 0);
5113 while (strcmp (fmt, mo->args) != 0 || mo->pinfo == INSN_MACRO)
5116 gas_assert (mo->name);
5117 gas_assert (strcmp (name, mo->name) == 0);
5120 create_insn (&insn, mo);
5138 MIPS16_INSERT_OPERAND (RY, insn, va_arg (*args, int));
5143 MIPS16_INSERT_OPERAND (RX, insn, va_arg (*args, int));
5147 MIPS16_INSERT_OPERAND (RZ, insn, va_arg (*args, int));
5151 MIPS16_INSERT_OPERAND (MOVE32Z, insn, va_arg (*args, int));
5161 MIPS16_INSERT_OPERAND (REGR32, insn, va_arg (*args, int));
5168 regno = va_arg (*args, int);
5169 regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3);
5170 MIPS16_INSERT_OPERAND (REG32R, insn, regno);
5191 gas_assert (ep != NULL);
5193 if (ep->X_op != O_constant)
5194 *r = (int) BFD_RELOC_UNUSED + c;
5197 mips16_immed (NULL, 0, c, ep->X_add_number, FALSE, FALSE,
5198 FALSE, &insn.insn_opcode, &insn.use_extend,
5201 *r = BFD_RELOC_UNUSED;
5207 MIPS16_INSERT_OPERAND (IMM6, insn, va_arg (*args, int));
5214 gas_assert (*r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL);
5216 append_insn (&insn, ep, r, TRUE);
5220 * Sign-extend 32-bit mode constants that have bit 31 set and all
5221 * higher bits unset.
5224 normalize_constant_expr (expressionS *ex)
5226 if (ex->X_op == O_constant
5227 && IS_ZEXT_32BIT_NUM (ex->X_add_number))
5228 ex->X_add_number = (((ex->X_add_number & 0xffffffff) ^ 0x80000000)
5233 * Sign-extend 32-bit mode address offsets that have bit 31 set and
5234 * all higher bits unset.
5237 normalize_address_expr (expressionS *ex)
5239 if (((ex->X_op == O_constant && HAVE_32BIT_ADDRESSES)
5240 || (ex->X_op == O_symbol && HAVE_32BIT_SYMBOLS))
5241 && IS_ZEXT_32BIT_NUM (ex->X_add_number))
5242 ex->X_add_number = (((ex->X_add_number & 0xffffffff) ^ 0x80000000)
5247 * Generate a "jalr" instruction with a relocation hint to the called
5248 * function. This occurs in NewABI PIC code.
5251 macro_build_jalr (expressionS *ep, int cprestore)
5253 static const bfd_reloc_code_real_type jalr_relocs[2]
5254 = { BFD_RELOC_MIPS_JALR, BFD_RELOC_MICROMIPS_JALR };
5255 bfd_reloc_code_real_type jalr_reloc = jalr_relocs[mips_opts.micromips];
5259 if (MIPS_JALR_HINT_P (ep))
5264 if (mips_opts.micromips)
5266 jalr = mips_opts.noreorder && !cprestore ? "jalr" : "jalrs";
5267 if (MIPS_JALR_HINT_P (ep))
5268 macro_build (NULL, jalr, "t,s", RA, PIC_CALL_REG);
5270 macro_build (NULL, jalr, "mj", PIC_CALL_REG);
5273 macro_build (NULL, "jalr", "d,s", RA, PIC_CALL_REG);
5274 if (MIPS_JALR_HINT_P (ep))
5275 fix_new_exp (frag_now, f - frag_now->fr_literal, 4, ep, FALSE, jalr_reloc);
5279 * Generate a "lui" instruction.
5282 macro_build_lui (expressionS *ep, int regnum)
5284 gas_assert (! mips_opts.mips16);
5286 if (ep->X_op != O_constant)
5288 gas_assert (ep->X_op == O_symbol);
5289 /* _gp_disp is a special case, used from s_cpload.
5290 __gnu_local_gp is used if mips_no_shared. */
5291 gas_assert (mips_pic == NO_PIC
5293 && strcmp (S_GET_NAME (ep->X_add_symbol), "_gp_disp") == 0)
5294 || (! mips_in_shared
5295 && strcmp (S_GET_NAME (ep->X_add_symbol),
5296 "__gnu_local_gp") == 0));
5299 macro_build (ep, "lui", LUI_FMT, regnum, BFD_RELOC_HI16_S);
5302 /* Generate a sequence of instructions to do a load or store from a constant
5303 offset off of a base register (breg) into/from a target register (treg),
5304 using AT if necessary. */
5306 macro_build_ldst_constoffset (expressionS *ep, const char *op,
5307 int treg, int breg, int dbl)
5309 gas_assert (ep->X_op == O_constant);
5311 /* Sign-extending 32-bit constants makes their handling easier. */
5313 normalize_constant_expr (ep);
5315 /* Right now, this routine can only handle signed 32-bit constants. */
5316 if (! IS_SEXT_32BIT_NUM(ep->X_add_number + 0x8000))
5317 as_warn (_("operand overflow"));
5319 if (IS_SEXT_16BIT_NUM(ep->X_add_number))
5321 /* Signed 16-bit offset will fit in the op. Easy! */
5322 macro_build (ep, op, "t,o(b)", treg, BFD_RELOC_LO16, breg);
5326 /* 32-bit offset, need multiple instructions and AT, like:
5327 lui $tempreg,const_hi (BFD_RELOC_HI16_S)
5328 addu $tempreg,$tempreg,$breg
5329 <op> $treg,const_lo($tempreg) (BFD_RELOC_LO16)
5330 to handle the complete offset. */
5331 macro_build_lui (ep, AT);
5332 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, AT, breg);
5333 macro_build (ep, op, "t,o(b)", treg, BFD_RELOC_LO16, AT);
5336 as_bad (_("Macro used $at after \".set noat\""));
5341 * Generates code to set the $at register to true (one)
5342 * if reg is less than the immediate expression.
5345 set_at (int reg, int unsignedp)
5347 if (imm_expr.X_op == O_constant
5348 && imm_expr.X_add_number >= -0x8000
5349 && imm_expr.X_add_number < 0x8000)
5350 macro_build (&imm_expr, unsignedp ? "sltiu" : "slti", "t,r,j",
5351 AT, reg, BFD_RELOC_LO16);
5354 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
5355 macro_build (NULL, unsignedp ? "sltu" : "slt", "d,v,t", AT, reg, AT);
5359 /* Warn if an expression is not a constant. */
5362 check_absolute_expr (struct mips_cl_insn *ip, expressionS *ex)
5364 if (ex->X_op == O_big)
5365 as_bad (_("unsupported large constant"));
5366 else if (ex->X_op != O_constant)
5367 as_bad (_("Instruction %s requires absolute expression"),
5370 if (HAVE_32BIT_GPRS)
5371 normalize_constant_expr (ex);
5374 /* Count the leading zeroes by performing a binary chop. This is a
5375 bulky bit of source, but performance is a LOT better for the
5376 majority of values than a simple loop to count the bits:
5377 for (lcnt = 0; (lcnt < 32); lcnt++)
5378 if ((v) & (1 << (31 - lcnt)))
5380 However it is not code size friendly, and the gain will drop a bit
5381 on certain cached systems.
5383 #define COUNT_TOP_ZEROES(v) \
5384 (((v) & ~0xffff) == 0 \
5385 ? ((v) & ~0xff) == 0 \
5386 ? ((v) & ~0xf) == 0 \
5387 ? ((v) & ~0x3) == 0 \
5388 ? ((v) & ~0x1) == 0 \
5393 : ((v) & ~0x7) == 0 \
5396 : ((v) & ~0x3f) == 0 \
5397 ? ((v) & ~0x1f) == 0 \
5400 : ((v) & ~0x7f) == 0 \
5403 : ((v) & ~0xfff) == 0 \
5404 ? ((v) & ~0x3ff) == 0 \
5405 ? ((v) & ~0x1ff) == 0 \
5408 : ((v) & ~0x7ff) == 0 \
5411 : ((v) & ~0x3fff) == 0 \
5412 ? ((v) & ~0x1fff) == 0 \
5415 : ((v) & ~0x7fff) == 0 \
5418 : ((v) & ~0xffffff) == 0 \
5419 ? ((v) & ~0xfffff) == 0 \
5420 ? ((v) & ~0x3ffff) == 0 \
5421 ? ((v) & ~0x1ffff) == 0 \
5424 : ((v) & ~0x7ffff) == 0 \
5427 : ((v) & ~0x3fffff) == 0 \
5428 ? ((v) & ~0x1fffff) == 0 \
5431 : ((v) & ~0x7fffff) == 0 \
5434 : ((v) & ~0xfffffff) == 0 \
5435 ? ((v) & ~0x3ffffff) == 0 \
5436 ? ((v) & ~0x1ffffff) == 0 \
5439 : ((v) & ~0x7ffffff) == 0 \
5442 : ((v) & ~0x3fffffff) == 0 \
5443 ? ((v) & ~0x1fffffff) == 0 \
5446 : ((v) & ~0x7fffffff) == 0 \
5451 * This routine generates the least number of instructions necessary to load
5452 * an absolute expression value into a register.
5455 load_register (int reg, expressionS *ep, int dbl)
5458 expressionS hi32, lo32;
5460 if (ep->X_op != O_big)
5462 gas_assert (ep->X_op == O_constant);
5464 /* Sign-extending 32-bit constants makes their handling easier. */
5466 normalize_constant_expr (ep);
5468 if (IS_SEXT_16BIT_NUM (ep->X_add_number))
5470 /* We can handle 16 bit signed values with an addiu to
5471 $zero. No need to ever use daddiu here, since $zero and
5472 the result are always correct in 32 bit mode. */
5473 macro_build (ep, "addiu", "t,r,j", reg, 0, BFD_RELOC_LO16);
5476 else if (ep->X_add_number >= 0 && ep->X_add_number < 0x10000)
5478 /* We can handle 16 bit unsigned values with an ori to
5480 macro_build (ep, "ori", "t,r,i", reg, 0, BFD_RELOC_LO16);
5483 else if ((IS_SEXT_32BIT_NUM (ep->X_add_number)))
5485 /* 32 bit values require an lui. */
5486 macro_build (ep, "lui", LUI_FMT, reg, BFD_RELOC_HI16);
5487 if ((ep->X_add_number & 0xffff) != 0)
5488 macro_build (ep, "ori", "t,r,i", reg, reg, BFD_RELOC_LO16);
5493 /* The value is larger than 32 bits. */
5495 if (!dbl || HAVE_32BIT_GPRS)
5499 sprintf_vma (value, ep->X_add_number);
5500 as_bad (_("Number (0x%s) larger than 32 bits"), value);
5501 macro_build (ep, "addiu", "t,r,j", reg, 0, BFD_RELOC_LO16);
5505 if (ep->X_op != O_big)
5508 hi32.X_add_number = (valueT) hi32.X_add_number >> 16;
5509 hi32.X_add_number = (valueT) hi32.X_add_number >> 16;
5510 hi32.X_add_number &= 0xffffffff;
5512 lo32.X_add_number &= 0xffffffff;
5516 gas_assert (ep->X_add_number > 2);
5517 if (ep->X_add_number == 3)
5518 generic_bignum[3] = 0;
5519 else if (ep->X_add_number > 4)
5520 as_bad (_("Number larger than 64 bits"));
5521 lo32.X_op = O_constant;
5522 lo32.X_add_number = generic_bignum[0] + (generic_bignum[1] << 16);
5523 hi32.X_op = O_constant;
5524 hi32.X_add_number = generic_bignum[2] + (generic_bignum[3] << 16);
5527 if (hi32.X_add_number == 0)
5532 unsigned long hi, lo;
5534 if (hi32.X_add_number == (offsetT) 0xffffffff)
5536 if ((lo32.X_add_number & 0xffff8000) == 0xffff8000)
5538 macro_build (&lo32, "addiu", "t,r,j", reg, 0, BFD_RELOC_LO16);
5541 if (lo32.X_add_number & 0x80000000)
5543 macro_build (&lo32, "lui", LUI_FMT, reg, BFD_RELOC_HI16);
5544 if (lo32.X_add_number & 0xffff)
5545 macro_build (&lo32, "ori", "t,r,i", reg, reg, BFD_RELOC_LO16);
5550 /* Check for 16bit shifted constant. We know that hi32 is
5551 non-zero, so start the mask on the first bit of the hi32
5556 unsigned long himask, lomask;
5560 himask = 0xffff >> (32 - shift);
5561 lomask = (0xffff << shift) & 0xffffffff;
5565 himask = 0xffff << (shift - 32);
5568 if ((hi32.X_add_number & ~(offsetT) himask) == 0
5569 && (lo32.X_add_number & ~(offsetT) lomask) == 0)
5573 tmp.X_op = O_constant;
5575 tmp.X_add_number = ((hi32.X_add_number << (32 - shift))
5576 | (lo32.X_add_number >> shift));
5578 tmp.X_add_number = hi32.X_add_number >> (shift - 32);
5579 macro_build (&tmp, "ori", "t,r,i", reg, 0, BFD_RELOC_LO16);
5580 macro_build (NULL, (shift >= 32) ? "dsll32" : "dsll", SHFT_FMT,
5581 reg, reg, (shift >= 32) ? shift - 32 : shift);
5586 while (shift <= (64 - 16));
5588 /* Find the bit number of the lowest one bit, and store the
5589 shifted value in hi/lo. */
5590 hi = (unsigned long) (hi32.X_add_number & 0xffffffff);
5591 lo = (unsigned long) (lo32.X_add_number & 0xffffffff);
5595 while ((lo & 1) == 0)
5600 lo |= (hi & (((unsigned long) 1 << bit) - 1)) << (32 - bit);
5606 while ((hi & 1) == 0)
5615 /* Optimize if the shifted value is a (power of 2) - 1. */
5616 if ((hi == 0 && ((lo + 1) & lo) == 0)
5617 || (lo == 0xffffffff && ((hi + 1) & hi) == 0))
5619 shift = COUNT_TOP_ZEROES ((unsigned int) hi32.X_add_number);
5624 /* This instruction will set the register to be all
5626 tmp.X_op = O_constant;
5627 tmp.X_add_number = (offsetT) -1;
5628 macro_build (&tmp, "addiu", "t,r,j", reg, 0, BFD_RELOC_LO16);
5632 macro_build (NULL, (bit >= 32) ? "dsll32" : "dsll", SHFT_FMT,
5633 reg, reg, (bit >= 32) ? bit - 32 : bit);
5635 macro_build (NULL, (shift >= 32) ? "dsrl32" : "dsrl", SHFT_FMT,
5636 reg, reg, (shift >= 32) ? shift - 32 : shift);
5641 /* Sign extend hi32 before calling load_register, because we can
5642 generally get better code when we load a sign extended value. */
5643 if ((hi32.X_add_number & 0x80000000) != 0)
5644 hi32.X_add_number |= ~(offsetT) 0xffffffff;
5645 load_register (reg, &hi32, 0);
5648 if ((lo32.X_add_number & 0xffff0000) == 0)
5652 macro_build (NULL, "dsll32", SHFT_FMT, reg, freg, 0);
5660 if ((freg == 0) && (lo32.X_add_number == (offsetT) 0xffffffff))
5662 macro_build (&lo32, "lui", LUI_FMT, reg, BFD_RELOC_HI16);
5663 macro_build (NULL, "dsrl32", SHFT_FMT, reg, reg, 0);
5669 macro_build (NULL, "dsll", SHFT_FMT, reg, freg, 16);
5673 mid16.X_add_number >>= 16;
5674 macro_build (&mid16, "ori", "t,r,i", reg, freg, BFD_RELOC_LO16);
5675 macro_build (NULL, "dsll", SHFT_FMT, reg, reg, 16);
5678 if ((lo32.X_add_number & 0xffff) != 0)
5679 macro_build (&lo32, "ori", "t,r,i", reg, freg, BFD_RELOC_LO16);
5683 load_delay_nop (void)
5685 if (!gpr_interlocks)
5686 macro_build (NULL, "nop", "");
5689 /* Load an address into a register. */
5692 load_address (int reg, expressionS *ep, int *used_at)
5694 if (ep->X_op != O_constant
5695 && ep->X_op != O_symbol)
5697 as_bad (_("expression too complex"));
5698 ep->X_op = O_constant;
5701 if (ep->X_op == O_constant)
5703 load_register (reg, ep, HAVE_64BIT_ADDRESSES);
5707 if (mips_pic == NO_PIC)
5709 /* If this is a reference to a GP relative symbol, we want
5710 addiu $reg,$gp,<sym> (BFD_RELOC_GPREL16)
5712 lui $reg,<sym> (BFD_RELOC_HI16_S)
5713 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
5714 If we have an addend, we always use the latter form.
5716 With 64bit address space and a usable $at we want
5717 lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5718 lui $at,<sym> (BFD_RELOC_HI16_S)
5719 daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER)
5720 daddiu $at,<sym> (BFD_RELOC_LO16)
5724 If $at is already in use, we use a path which is suboptimal
5725 on superscalar processors.
5726 lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5727 daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER)
5729 daddiu $reg,<sym> (BFD_RELOC_HI16_S)
5731 daddiu $reg,<sym> (BFD_RELOC_LO16)
5733 For GP relative symbols in 64bit address space we can use
5734 the same sequence as in 32bit address space. */
5735 if (HAVE_64BIT_SYMBOLS)
5737 if ((valueT) ep->X_add_number <= MAX_GPREL_OFFSET
5738 && !nopic_need_relax (ep->X_add_symbol, 1))
5740 relax_start (ep->X_add_symbol);
5741 macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", reg,
5742 mips_gp_register, BFD_RELOC_GPREL16);
5746 if (*used_at == 0 && mips_opts.at)
5748 macro_build (ep, "lui", LUI_FMT, reg, BFD_RELOC_MIPS_HIGHEST);
5749 macro_build (ep, "lui", LUI_FMT, AT, BFD_RELOC_HI16_S);
5750 macro_build (ep, "daddiu", "t,r,j", reg, reg,
5751 BFD_RELOC_MIPS_HIGHER);
5752 macro_build (ep, "daddiu", "t,r,j", AT, AT, BFD_RELOC_LO16);
5753 macro_build (NULL, "dsll32", SHFT_FMT, reg, reg, 0);
5754 macro_build (NULL, "daddu", "d,v,t", reg, reg, AT);
5759 macro_build (ep, "lui", LUI_FMT, reg, BFD_RELOC_MIPS_HIGHEST);
5760 macro_build (ep, "daddiu", "t,r,j", reg, reg,
5761 BFD_RELOC_MIPS_HIGHER);
5762 macro_build (NULL, "dsll", SHFT_FMT, reg, reg, 16);
5763 macro_build (ep, "daddiu", "t,r,j", reg, reg, BFD_RELOC_HI16_S);
5764 macro_build (NULL, "dsll", SHFT_FMT, reg, reg, 16);
5765 macro_build (ep, "daddiu", "t,r,j", reg, reg, BFD_RELOC_LO16);
5768 if (mips_relax.sequence)
5773 if ((valueT) ep->X_add_number <= MAX_GPREL_OFFSET
5774 && !nopic_need_relax (ep->X_add_symbol, 1))
5776 relax_start (ep->X_add_symbol);
5777 macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", reg,
5778 mips_gp_register, BFD_RELOC_GPREL16);
5781 macro_build_lui (ep, reg);
5782 macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j",
5783 reg, reg, BFD_RELOC_LO16);
5784 if (mips_relax.sequence)
5788 else if (!mips_big_got)
5792 /* If this is a reference to an external symbol, we want
5793 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5795 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5797 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
5798 If there is a constant, it must be added in after.
5800 If we have NewABI, we want
5801 lw $reg,<sym+cst>($gp) (BFD_RELOC_MIPS_GOT_DISP)
5802 unless we're referencing a global symbol with a non-zero
5803 offset, in which case cst must be added separately. */
5806 if (ep->X_add_number)
5808 ex.X_add_number = ep->X_add_number;
5809 ep->X_add_number = 0;
5810 relax_start (ep->X_add_symbol);
5811 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
5812 BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
5813 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
5814 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
5815 ex.X_op = O_constant;
5816 macro_build (&ex, ADDRESS_ADDI_INSN, "t,r,j",
5817 reg, reg, BFD_RELOC_LO16);
5818 ep->X_add_number = ex.X_add_number;
5821 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
5822 BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
5823 if (mips_relax.sequence)
5828 ex.X_add_number = ep->X_add_number;
5829 ep->X_add_number = 0;
5830 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
5831 BFD_RELOC_MIPS_GOT16, mips_gp_register);
5833 relax_start (ep->X_add_symbol);
5835 macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", reg, reg,
5839 if (ex.X_add_number != 0)
5841 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
5842 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
5843 ex.X_op = O_constant;
5844 macro_build (&ex, ADDRESS_ADDI_INSN, "t,r,j",
5845 reg, reg, BFD_RELOC_LO16);
5849 else if (mips_big_got)
5853 /* This is the large GOT case. If this is a reference to an
5854 external symbol, we want
5855 lui $reg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5857 lw $reg,<sym>($reg) (BFD_RELOC_MIPS_GOT_LO16)
5859 Otherwise, for a reference to a local symbol in old ABI, we want
5860 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5862 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
5863 If there is a constant, it must be added in after.
5865 In the NewABI, for local symbols, with or without offsets, we want:
5866 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
5867 addiu $reg,$reg,<sym> (BFD_RELOC_MIPS_GOT_OFST)
5871 ex.X_add_number = ep->X_add_number;
5872 ep->X_add_number = 0;
5873 relax_start (ep->X_add_symbol);
5874 macro_build (ep, "lui", LUI_FMT, reg, BFD_RELOC_MIPS_GOT_HI16);
5875 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
5876 reg, reg, mips_gp_register);
5877 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)",
5878 reg, BFD_RELOC_MIPS_GOT_LO16, reg);
5879 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
5880 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
5881 else if (ex.X_add_number)
5883 ex.X_op = O_constant;
5884 macro_build (&ex, ADDRESS_ADDI_INSN, "t,r,j", reg, reg,
5888 ep->X_add_number = ex.X_add_number;
5890 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
5891 BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register);
5892 macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", reg, reg,
5893 BFD_RELOC_MIPS_GOT_OFST);
5898 ex.X_add_number = ep->X_add_number;
5899 ep->X_add_number = 0;
5900 relax_start (ep->X_add_symbol);
5901 macro_build (ep, "lui", LUI_FMT, reg, BFD_RELOC_MIPS_GOT_HI16);
5902 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
5903 reg, reg, mips_gp_register);
5904 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)",
5905 reg, BFD_RELOC_MIPS_GOT_LO16, reg);
5907 if (reg_needs_delay (mips_gp_register))
5909 /* We need a nop before loading from $gp. This special
5910 check is required because the lui which starts the main
5911 instruction stream does not refer to $gp, and so will not
5912 insert the nop which may be required. */
5913 macro_build (NULL, "nop", "");
5915 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
5916 BFD_RELOC_MIPS_GOT16, mips_gp_register);
5918 macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", reg, reg,
5922 if (ex.X_add_number != 0)
5924 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
5925 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
5926 ex.X_op = O_constant;
5927 macro_build (&ex, ADDRESS_ADDI_INSN, "t,r,j", reg, reg,
5935 if (!mips_opts.at && *used_at == 1)
5936 as_bad (_("Macro used $at after \".set noat\""));
5939 /* Move the contents of register SOURCE into register DEST. */
5942 move_register (int dest, int source)
5944 /* Prefer to use a 16-bit microMIPS instruction unless the previous
5945 instruction specifically requires a 32-bit one. */
5946 if (mips_opts.micromips
5947 && !(history[0].insn_mo->pinfo2 & INSN2_BRANCH_DELAY_32BIT))
5948 macro_build (NULL, "move", "mp,mj", dest, source);
5950 macro_build (NULL, HAVE_32BIT_GPRS ? "addu" : "daddu", "d,v,t",
5954 /* Emit an SVR4 PIC sequence to load address LOCAL into DEST, where
5955 LOCAL is the sum of a symbol and a 16-bit or 32-bit displacement.
5956 The two alternatives are:
5958 Global symbol Local sybmol
5959 ------------- ------------
5960 lw DEST,%got(SYMBOL) lw DEST,%got(SYMBOL + OFFSET)
5962 addiu DEST,DEST,OFFSET addiu DEST,DEST,%lo(SYMBOL + OFFSET)
5964 load_got_offset emits the first instruction and add_got_offset
5965 emits the second for a 16-bit offset or add_got_offset_hilo emits
5966 a sequence to add a 32-bit offset using a scratch register. */
5969 load_got_offset (int dest, expressionS *local)
5974 global.X_add_number = 0;
5976 relax_start (local->X_add_symbol);
5977 macro_build (&global, ADDRESS_LOAD_INSN, "t,o(b)", dest,
5978 BFD_RELOC_MIPS_GOT16, mips_gp_register);
5980 macro_build (local, ADDRESS_LOAD_INSN, "t,o(b)", dest,
5981 BFD_RELOC_MIPS_GOT16, mips_gp_register);
5986 add_got_offset (int dest, expressionS *local)
5990 global.X_op = O_constant;
5991 global.X_op_symbol = NULL;
5992 global.X_add_symbol = NULL;
5993 global.X_add_number = local->X_add_number;
5995 relax_start (local->X_add_symbol);
5996 macro_build (&global, ADDRESS_ADDI_INSN, "t,r,j",
5997 dest, dest, BFD_RELOC_LO16);
5999 macro_build (local, ADDRESS_ADDI_INSN, "t,r,j", dest, dest, BFD_RELOC_LO16);
6004 add_got_offset_hilo (int dest, expressionS *local, int tmp)
6007 int hold_mips_optimize;
6009 global.X_op = O_constant;
6010 global.X_op_symbol = NULL;
6011 global.X_add_symbol = NULL;
6012 global.X_add_number = local->X_add_number;
6014 relax_start (local->X_add_symbol);
6015 load_register (tmp, &global, HAVE_64BIT_ADDRESSES);
6017 /* Set mips_optimize around the lui instruction to avoid
6018 inserting an unnecessary nop after the lw. */
6019 hold_mips_optimize = mips_optimize;
6021 macro_build_lui (&global, tmp);
6022 mips_optimize = hold_mips_optimize;
6023 macro_build (local, ADDRESS_ADDI_INSN, "t,r,j", tmp, tmp, BFD_RELOC_LO16);
6026 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", dest, dest, tmp);
6029 /* Emit a sequence of instructions to emulate a branch likely operation.
6030 BR is an ordinary branch corresponding to one to be emulated. BRNEG
6031 is its complementing branch with the original condition negated.
6032 CALL is set if the original branch specified the link operation.
6033 EP, FMT, SREG and TREG specify the usual macro_build() parameters.
6035 Code like this is produced in the noreorder mode:
6040 delay slot (executed only if branch taken)
6048 delay slot (executed only if branch taken)
6051 In the reorder mode the delay slot would be filled with a nop anyway,
6052 so code produced is simply:
6057 This function is used when producing code for the microMIPS ASE that
6058 does not implement branch likely instructions in hardware. */
6061 macro_build_branch_likely (const char *br, const char *brneg,
6062 int call, expressionS *ep, const char *fmt,
6063 unsigned int sreg, unsigned int treg)
6065 int noreorder = mips_opts.noreorder;
6068 gas_assert (mips_opts.micromips);
6072 micromips_label_expr (&expr1);
6073 macro_build (&expr1, brneg, fmt, sreg, treg);
6074 macro_build (NULL, "nop", "");
6075 macro_build (ep, call ? "bal" : "b", "p");
6077 /* Set to true so that append_insn adds a label. */
6078 emit_branch_likely_macro = TRUE;
6082 macro_build (ep, br, fmt, sreg, treg);
6083 macro_build (NULL, "nop", "");
6088 /* Emit a coprocessor branch-likely macro specified by TYPE, using CC as
6089 the condition code tested. EP specifies the branch target. */
6092 macro_build_branch_ccl (int type, expressionS *ep, unsigned int cc)
6119 macro_build_branch_likely (br, brneg, call, ep, "N,p", cc, ZERO);
6122 /* Emit a two-argument branch macro specified by TYPE, using SREG as
6123 the register tested. EP specifies the branch target. */
6126 macro_build_branch_rs (int type, expressionS *ep, unsigned int sreg)
6128 const char *brneg = NULL;
6138 br = mips_opts.micromips ? "bgez" : "bgezl";
6142 gas_assert (mips_opts.micromips);
6151 br = mips_opts.micromips ? "bgtz" : "bgtzl";
6158 br = mips_opts.micromips ? "blez" : "blezl";
6165 br = mips_opts.micromips ? "bltz" : "bltzl";
6169 gas_assert (mips_opts.micromips);
6177 if (mips_opts.micromips && brneg)
6178 macro_build_branch_likely (br, brneg, call, ep, "s,p", sreg, ZERO);
6180 macro_build (ep, br, "s,p", sreg);
6183 /* Emit a three-argument branch macro specified by TYPE, using SREG and
6184 TREG as the registers tested. EP specifies the branch target. */
6187 macro_build_branch_rsrt (int type, expressionS *ep,
6188 unsigned int sreg, unsigned int treg)
6190 const char *brneg = NULL;
6202 br = mips_opts.micromips ? "beq" : "beql";
6211 br = mips_opts.micromips ? "bne" : "bnel";
6217 if (mips_opts.micromips && brneg)
6218 macro_build_branch_likely (br, brneg, call, ep, "s,t,p", sreg, treg);
6220 macro_build (ep, br, "s,t,p", sreg, treg);
6225 * This routine implements the seemingly endless macro or synthesized
6226 * instructions and addressing modes in the mips assembly language. Many
6227 * of these macros are simple and are similar to each other. These could
6228 * probably be handled by some kind of table or grammar approach instead of
6229 * this verbose method. Others are not simple macros but are more like
6230 * optimizing code generation.
6231 * One interesting optimization is when several store macros appear
6232 * consecutively that would load AT with the upper half of the same address.
6233 * The ensuing load upper instructions are ommited. This implies some kind
6234 * of global optimization. We currently only optimize within a single macro.
6235 * For many of the load and store macros if the address is specified as a
6236 * constant expression in the first 64k of memory (ie ld $2,0x4000c) we
6237 * first load register 'at' with zero and use it as the base register. The
6238 * mips assembler simply uses register $zero. Just one tiny optimization
6242 macro (struct mips_cl_insn *ip)
6244 unsigned int treg, sreg, dreg, breg;
6245 unsigned int tempreg;
6248 expressionS label_expr;
6266 bfd_reloc_code_real_type r;
6267 int hold_mips_optimize;
6269 gas_assert (! mips_opts.mips16);
6271 treg = EXTRACT_OPERAND (mips_opts.micromips, RT, *ip);
6272 dreg = EXTRACT_OPERAND (mips_opts.micromips, RD, *ip);
6273 sreg = breg = EXTRACT_OPERAND (mips_opts.micromips, RS, *ip);
6274 mask = ip->insn_mo->mask;
6276 label_expr.X_op = O_constant;
6277 label_expr.X_op_symbol = NULL;
6278 label_expr.X_add_symbol = NULL;
6279 label_expr.X_add_number = 0;
6281 expr1.X_op = O_constant;
6282 expr1.X_op_symbol = NULL;
6283 expr1.X_add_symbol = NULL;
6284 expr1.X_add_number = 1;
6299 if (mips_opts.micromips)
6300 micromips_label_expr (&label_expr);
6302 label_expr.X_add_number = 8;
6303 macro_build (&label_expr, "bgez", "s,p", sreg);
6305 macro_build (NULL, "nop", "");
6307 move_register (dreg, sreg);
6308 macro_build (NULL, dbl ? "dsub" : "sub", "d,v,t", dreg, 0, sreg);
6309 if (mips_opts.micromips)
6310 micromips_add_label ();
6327 if (!mips_opts.micromips)
6329 if (imm_expr.X_op == O_constant
6330 && imm_expr.X_add_number >= -0x200
6331 && imm_expr.X_add_number < 0x200)
6333 macro_build (NULL, s, "t,r,.", treg, sreg, imm_expr.X_add_number);
6342 if (imm_expr.X_op == O_constant
6343 && imm_expr.X_add_number >= -0x8000
6344 && imm_expr.X_add_number < 0x8000)
6346 macro_build (&imm_expr, s, "t,r,j", treg, sreg, BFD_RELOC_LO16);
6351 load_register (AT, &imm_expr, dbl);
6352 macro_build (NULL, s2, "d,v,t", treg, sreg, AT);
6371 if (imm_expr.X_op == O_constant
6372 && imm_expr.X_add_number >= 0
6373 && imm_expr.X_add_number < 0x10000)
6375 if (mask != M_NOR_I)
6376 macro_build (&imm_expr, s, "t,r,i", treg, sreg, BFD_RELOC_LO16);
6379 macro_build (&imm_expr, "ori", "t,r,i",
6380 treg, sreg, BFD_RELOC_LO16);
6381 macro_build (NULL, "nor", "d,v,t", treg, treg, 0);
6387 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
6388 macro_build (NULL, s2, "d,v,t", treg, sreg, AT);
6392 switch (imm_expr.X_add_number)
6395 macro_build (NULL, "nop", "");
6398 macro_build (NULL, "packrl.ph", "d,s,t", treg, treg, sreg);
6401 macro_build (NULL, "balign", "t,s,2", treg, sreg,
6402 (int) imm_expr.X_add_number);
6411 gas_assert (mips_opts.micromips);
6412 macro_build_branch_ccl (mask, &offset_expr,
6413 EXTRACT_OPERAND (1, BCC, *ip));
6420 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
6426 load_register (treg, &imm_expr, HAVE_64BIT_GPRS);
6431 macro_build_branch_rsrt (mask, &offset_expr, sreg, treg);
6438 macro_build_branch_rs (likely ? M_BGEZL : M_BGEZ, &offset_expr, sreg);
6440 macro_build_branch_rs (likely ? M_BLEZL : M_BLEZ, &offset_expr, treg);
6444 macro_build (NULL, "slt", "d,v,t", AT, sreg, treg);
6445 macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ,
6446 &offset_expr, AT, ZERO);
6456 macro_build_branch_rs (mask, &offset_expr, sreg);
6462 /* Check for > max integer. */
6463 maxnum = 0x7fffffff;
6464 if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4)
6471 if (imm_expr.X_op == O_constant
6472 && imm_expr.X_add_number >= maxnum
6473 && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4))
6476 /* Result is always false. */
6478 macro_build (NULL, "nop", "");
6480 macro_build_branch_rsrt (M_BNEL, &offset_expr, ZERO, ZERO);
6483 if (imm_expr.X_op != O_constant)
6484 as_bad (_("Unsupported large constant"));
6485 ++imm_expr.X_add_number;
6489 if (mask == M_BGEL_I)
6491 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
6493 macro_build_branch_rs (likely ? M_BGEZL : M_BGEZ,
6494 &offset_expr, sreg);
6497 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
6499 macro_build_branch_rs (likely ? M_BGTZL : M_BGTZ,
6500 &offset_expr, sreg);
6503 maxnum = 0x7fffffff;
6504 if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4)
6511 maxnum = - maxnum - 1;
6512 if (imm_expr.X_op == O_constant
6513 && imm_expr.X_add_number <= maxnum
6514 && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4))
6517 /* result is always true */
6518 as_warn (_("Branch %s is always true"), ip->insn_mo->name);
6519 macro_build (&offset_expr, "b", "p");
6524 macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ,
6525 &offset_expr, AT, ZERO);
6534 macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ,
6535 &offset_expr, ZERO, treg);
6539 macro_build (NULL, "sltu", "d,v,t", AT, sreg, treg);
6540 macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ,
6541 &offset_expr, AT, ZERO);
6550 && imm_expr.X_op == O_constant
6551 && imm_expr.X_add_number == -1))
6553 if (imm_expr.X_op != O_constant)
6554 as_bad (_("Unsupported large constant"));
6555 ++imm_expr.X_add_number;
6559 if (mask == M_BGEUL_I)
6561 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
6563 else if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
6564 macro_build_branch_rsrt (likely ? M_BNEL : M_BNE,
6565 &offset_expr, sreg, ZERO);
6570 macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ,
6571 &offset_expr, AT, ZERO);
6579 macro_build_branch_rs (likely ? M_BGTZL : M_BGTZ, &offset_expr, sreg);
6581 macro_build_branch_rs (likely ? M_BLTZL : M_BLTZ, &offset_expr, treg);
6585 macro_build (NULL, "slt", "d,v,t", AT, treg, sreg);
6586 macro_build_branch_rsrt (likely ? M_BNEL : M_BNE,
6587 &offset_expr, AT, ZERO);
6595 macro_build_branch_rsrt (likely ? M_BNEL : M_BNE,
6596 &offset_expr, sreg, ZERO);
6602 macro_build (NULL, "sltu", "d,v,t", AT, treg, sreg);
6603 macro_build_branch_rsrt (likely ? M_BNEL : M_BNE,
6604 &offset_expr, AT, ZERO);
6612 macro_build_branch_rs (likely ? M_BLEZL : M_BLEZ, &offset_expr, sreg);
6614 macro_build_branch_rs (likely ? M_BGEZL : M_BGEZ, &offset_expr, treg);
6618 macro_build (NULL, "slt", "d,v,t", AT, treg, sreg);
6619 macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ,
6620 &offset_expr, AT, ZERO);
6627 maxnum = 0x7fffffff;
6628 if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4)
6635 if (imm_expr.X_op == O_constant
6636 && imm_expr.X_add_number >= maxnum
6637 && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4))
6639 if (imm_expr.X_op != O_constant)
6640 as_bad (_("Unsupported large constant"));
6641 ++imm_expr.X_add_number;
6645 if (mask == M_BLTL_I)
6647 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
6648 macro_build_branch_rs (likely ? M_BLTZL : M_BLTZ, &offset_expr, sreg);
6649 else if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
6650 macro_build_branch_rs (likely ? M_BLEZL : M_BLEZ, &offset_expr, sreg);
6655 macro_build_branch_rsrt (likely ? M_BNEL : M_BNE,
6656 &offset_expr, AT, ZERO);
6664 macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ,
6665 &offset_expr, sreg, ZERO);
6671 macro_build (NULL, "sltu", "d,v,t", AT, treg, sreg);
6672 macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ,
6673 &offset_expr, AT, ZERO);
6682 && imm_expr.X_op == O_constant
6683 && imm_expr.X_add_number == -1))
6685 if (imm_expr.X_op != O_constant)
6686 as_bad (_("Unsupported large constant"));
6687 ++imm_expr.X_add_number;
6691 if (mask == M_BLTUL_I)
6693 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
6695 else if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
6696 macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ,
6697 &offset_expr, sreg, ZERO);
6702 macro_build_branch_rsrt (likely ? M_BNEL : M_BNE,
6703 &offset_expr, AT, ZERO);
6711 macro_build_branch_rs (likely ? M_BLTZL : M_BLTZ, &offset_expr, sreg);
6713 macro_build_branch_rs (likely ? M_BGTZL : M_BGTZ, &offset_expr, treg);
6717 macro_build (NULL, "slt", "d,v,t", AT, sreg, treg);
6718 macro_build_branch_rsrt (likely ? M_BNEL : M_BNE,
6719 &offset_expr, AT, ZERO);
6729 macro_build_branch_rsrt (likely ? M_BNEL : M_BNE,
6730 &offset_expr, ZERO, treg);
6734 macro_build (NULL, "sltu", "d,v,t", AT, sreg, treg);
6735 macro_build_branch_rsrt (likely ? M_BNEL : M_BNE,
6736 &offset_expr, AT, ZERO);
6742 /* Use unsigned arithmetic. */
6746 if (imm_expr.X_op != O_constant || imm2_expr.X_op != O_constant)
6748 as_bad (_("Unsupported large constant"));
6753 pos = imm_expr.X_add_number;
6754 size = imm2_expr.X_add_number;
6759 as_bad (_("Improper position (%lu)"), (unsigned long) pos);
6762 if (size == 0 || size > 64 || (pos + size - 1) > 63)
6764 as_bad (_("Improper extract size (%lu, position %lu)"),
6765 (unsigned long) size, (unsigned long) pos);
6769 if (size <= 32 && pos < 32)
6774 else if (size <= 32)
6784 macro_build ((expressionS *) NULL, s, fmt, treg, sreg, (int) pos,
6791 /* Use unsigned arithmetic. */
6795 if (imm_expr.X_op != O_constant || imm2_expr.X_op != O_constant)
6797 as_bad (_("Unsupported large constant"));
6802 pos = imm_expr.X_add_number;
6803 size = imm2_expr.X_add_number;
6808 as_bad (_("Improper position (%lu)"), (unsigned long) pos);
6811 if (size == 0 || size > 64 || (pos + size - 1) > 63)
6813 as_bad (_("Improper insert size (%lu, position %lu)"),
6814 (unsigned long) size, (unsigned long) pos);
6818 if (pos < 32 && (pos + size - 1) < 32)
6833 macro_build ((expressionS *) NULL, s, fmt, treg, sreg, (int) pos,
6834 (int) (pos + size - 1));
6850 as_warn (_("Divide by zero."));
6852 macro_build (NULL, "teq", TRAP_FMT, ZERO, ZERO, 7);
6854 macro_build (NULL, "break", BRK_FMT, 7);
6861 macro_build (NULL, "teq", TRAP_FMT, treg, ZERO, 7);
6862 macro_build (NULL, dbl ? "ddiv" : "div", "z,s,t", sreg, treg);
6866 if (mips_opts.micromips)
6867 micromips_label_expr (&label_expr);
6869 label_expr.X_add_number = 8;
6870 macro_build (&label_expr, "bne", "s,t,p", treg, ZERO);
6871 macro_build (NULL, dbl ? "ddiv" : "div", "z,s,t", sreg, treg);
6872 macro_build (NULL, "break", BRK_FMT, 7);
6873 if (mips_opts.micromips)
6874 micromips_add_label ();
6876 expr1.X_add_number = -1;
6878 load_register (AT, &expr1, dbl);
6879 if (mips_opts.micromips)
6880 micromips_label_expr (&label_expr);
6882 label_expr.X_add_number = mips_trap ? (dbl ? 12 : 8) : (dbl ? 20 : 16);
6883 macro_build (&label_expr, "bne", "s,t,p", treg, AT);
6886 expr1.X_add_number = 1;
6887 load_register (AT, &expr1, dbl);
6888 macro_build (NULL, "dsll32", SHFT_FMT, AT, AT, 31);
6892 expr1.X_add_number = 0x80000000;
6893 macro_build (&expr1, "lui", LUI_FMT, AT, BFD_RELOC_HI16);
6897 macro_build (NULL, "teq", TRAP_FMT, sreg, AT, 6);
6898 /* We want to close the noreorder block as soon as possible, so
6899 that later insns are available for delay slot filling. */
6904 if (mips_opts.micromips)
6905 micromips_label_expr (&label_expr);
6907 label_expr.X_add_number = 8;
6908 macro_build (&label_expr, "bne", "s,t,p", sreg, AT);
6909 macro_build (NULL, "nop", "");
6911 /* We want to close the noreorder block as soon as possible, so
6912 that later insns are available for delay slot filling. */
6915 macro_build (NULL, "break", BRK_FMT, 6);
6917 if (mips_opts.micromips)
6918 micromips_add_label ();
6919 macro_build (NULL, s, MFHL_FMT, dreg);
6958 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
6960 as_warn (_("Divide by zero."));
6962 macro_build (NULL, "teq", TRAP_FMT, ZERO, ZERO, 7);
6964 macro_build (NULL, "break", BRK_FMT, 7);
6967 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
6969 if (strcmp (s2, "mflo") == 0)
6970 move_register (dreg, sreg);
6972 move_register (dreg, ZERO);
6975 if (imm_expr.X_op == O_constant
6976 && imm_expr.X_add_number == -1
6977 && s[strlen (s) - 1] != 'u')
6979 if (strcmp (s2, "mflo") == 0)
6981 macro_build (NULL, dbl ? "dneg" : "neg", "d,w", dreg, sreg);
6984 move_register (dreg, ZERO);
6989 load_register (AT, &imm_expr, dbl);
6990 macro_build (NULL, s, "z,s,t", sreg, AT);
6991 macro_build (NULL, s2, MFHL_FMT, dreg);
7013 macro_build (NULL, "teq", TRAP_FMT, treg, ZERO, 7);
7014 macro_build (NULL, s, "z,s,t", sreg, treg);
7015 /* We want to close the noreorder block as soon as possible, so
7016 that later insns are available for delay slot filling. */
7021 if (mips_opts.micromips)
7022 micromips_label_expr (&label_expr);
7024 label_expr.X_add_number = 8;
7025 macro_build (&label_expr, "bne", "s,t,p", treg, ZERO);
7026 macro_build (NULL, s, "z,s,t", sreg, treg);
7028 /* We want to close the noreorder block as soon as possible, so
7029 that later insns are available for delay slot filling. */
7031 macro_build (NULL, "break", BRK_FMT, 7);
7032 if (mips_opts.micromips)
7033 micromips_add_label ();
7035 macro_build (NULL, s2, MFHL_FMT, dreg);
7047 /* Load the address of a symbol into a register. If breg is not
7048 zero, we then add a base register to it. */
7050 if (dbl && HAVE_32BIT_GPRS)
7051 as_warn (_("dla used to load 32-bit register"));
7053 if (!dbl && HAVE_64BIT_OBJECTS)
7054 as_warn (_("la used to load 64-bit address"));
7056 if (offset_expr.X_op == O_constant
7057 && offset_expr.X_add_number >= -0x8000
7058 && offset_expr.X_add_number < 0x8000)
7060 macro_build (&offset_expr, ADDRESS_ADDI_INSN,
7061 "t,r,j", treg, sreg, BFD_RELOC_LO16);
7065 if (mips_opts.at && (treg == breg))
7075 if (offset_expr.X_op != O_symbol
7076 && offset_expr.X_op != O_constant)
7078 as_bad (_("Expression too complex"));
7079 offset_expr.X_op = O_constant;
7082 if (offset_expr.X_op == O_constant)
7083 load_register (tempreg, &offset_expr, HAVE_64BIT_ADDRESSES);
7084 else if (mips_pic == NO_PIC)
7086 /* If this is a reference to a GP relative symbol, we want
7087 addiu $tempreg,$gp,<sym> (BFD_RELOC_GPREL16)
7089 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
7090 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
7091 If we have a constant, we need two instructions anyhow,
7092 so we may as well always use the latter form.
7094 With 64bit address space and a usable $at we want
7095 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
7096 lui $at,<sym> (BFD_RELOC_HI16_S)
7097 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
7098 daddiu $at,<sym> (BFD_RELOC_LO16)
7100 daddu $tempreg,$tempreg,$at
7102 If $at is already in use, we use a path which is suboptimal
7103 on superscalar processors.
7104 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
7105 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
7107 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
7109 daddiu $tempreg,<sym> (BFD_RELOC_LO16)
7111 For GP relative symbols in 64bit address space we can use
7112 the same sequence as in 32bit address space. */
7113 if (HAVE_64BIT_SYMBOLS)
7115 if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
7116 && !nopic_need_relax (offset_expr.X_add_symbol, 1))
7118 relax_start (offset_expr.X_add_symbol);
7119 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
7120 tempreg, mips_gp_register, BFD_RELOC_GPREL16);
7124 if (used_at == 0 && mips_opts.at)
7126 macro_build (&offset_expr, "lui", LUI_FMT,
7127 tempreg, BFD_RELOC_MIPS_HIGHEST);
7128 macro_build (&offset_expr, "lui", LUI_FMT,
7129 AT, BFD_RELOC_HI16_S);
7130 macro_build (&offset_expr, "daddiu", "t,r,j",
7131 tempreg, tempreg, BFD_RELOC_MIPS_HIGHER);
7132 macro_build (&offset_expr, "daddiu", "t,r,j",
7133 AT, AT, BFD_RELOC_LO16);
7134 macro_build (NULL, "dsll32", SHFT_FMT, tempreg, tempreg, 0);
7135 macro_build (NULL, "daddu", "d,v,t", tempreg, tempreg, AT);
7140 macro_build (&offset_expr, "lui", LUI_FMT,
7141 tempreg, BFD_RELOC_MIPS_HIGHEST);
7142 macro_build (&offset_expr, "daddiu", "t,r,j",
7143 tempreg, tempreg, BFD_RELOC_MIPS_HIGHER);
7144 macro_build (NULL, "dsll", SHFT_FMT, tempreg, tempreg, 16);
7145 macro_build (&offset_expr, "daddiu", "t,r,j",
7146 tempreg, tempreg, BFD_RELOC_HI16_S);
7147 macro_build (NULL, "dsll", SHFT_FMT, tempreg, tempreg, 16);
7148 macro_build (&offset_expr, "daddiu", "t,r,j",
7149 tempreg, tempreg, BFD_RELOC_LO16);
7152 if (mips_relax.sequence)
7157 if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
7158 && !nopic_need_relax (offset_expr.X_add_symbol, 1))
7160 relax_start (offset_expr.X_add_symbol);
7161 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
7162 tempreg, mips_gp_register, BFD_RELOC_GPREL16);
7165 if (!IS_SEXT_32BIT_NUM (offset_expr.X_add_number))
7166 as_bad (_("Offset too large"));
7167 macro_build_lui (&offset_expr, tempreg);
7168 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
7169 tempreg, tempreg, BFD_RELOC_LO16);
7170 if (mips_relax.sequence)
7174 else if (!mips_big_got && !HAVE_NEWABI)
7176 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT16;
7178 /* If this is a reference to an external symbol, and there
7179 is no constant, we want
7180 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
7181 or for lca or if tempreg is PIC_CALL_REG
7182 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
7183 For a local symbol, we want
7184 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
7186 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
7188 If we have a small constant, and this is a reference to
7189 an external symbol, we want
7190 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
7192 addiu $tempreg,$tempreg,<constant>
7193 For a local symbol, we want the same instruction
7194 sequence, but we output a BFD_RELOC_LO16 reloc on the
7197 If we have a large constant, and this is a reference to
7198 an external symbol, we want
7199 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
7200 lui $at,<hiconstant>
7201 addiu $at,$at,<loconstant>
7202 addu $tempreg,$tempreg,$at
7203 For a local symbol, we want the same instruction
7204 sequence, but we output a BFD_RELOC_LO16 reloc on the
7208 if (offset_expr.X_add_number == 0)
7210 if (mips_pic == SVR4_PIC
7212 && (call || tempreg == PIC_CALL_REG))
7213 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL16;
7215 relax_start (offset_expr.X_add_symbol);
7216 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
7217 lw_reloc_type, mips_gp_register);
7220 /* We're going to put in an addu instruction using
7221 tempreg, so we may as well insert the nop right
7226 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
7227 tempreg, BFD_RELOC_MIPS_GOT16, mips_gp_register);
7229 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
7230 tempreg, tempreg, BFD_RELOC_LO16);
7232 /* FIXME: If breg == 0, and the next instruction uses
7233 $tempreg, then if this variant case is used an extra
7234 nop will be generated. */
7236 else if (offset_expr.X_add_number >= -0x8000
7237 && offset_expr.X_add_number < 0x8000)
7239 load_got_offset (tempreg, &offset_expr);
7241 add_got_offset (tempreg, &offset_expr);
7245 expr1.X_add_number = offset_expr.X_add_number;
7246 offset_expr.X_add_number =
7247 ((offset_expr.X_add_number + 0x8000) & 0xffff) - 0x8000;
7248 load_got_offset (tempreg, &offset_expr);
7249 offset_expr.X_add_number = expr1.X_add_number;
7250 /* If we are going to add in a base register, and the
7251 target register and the base register are the same,
7252 then we are using AT as a temporary register. Since
7253 we want to load the constant into AT, we add our
7254 current AT (from the global offset table) and the
7255 register into the register now, and pretend we were
7256 not using a base register. */
7260 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
7265 add_got_offset_hilo (tempreg, &offset_expr, AT);
7269 else if (!mips_big_got && HAVE_NEWABI)
7271 int add_breg_early = 0;
7273 /* If this is a reference to an external, and there is no
7274 constant, or local symbol (*), with or without a
7276 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
7277 or for lca or if tempreg is PIC_CALL_REG
7278 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
7280 If we have a small constant, and this is a reference to
7281 an external symbol, we want
7282 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
7283 addiu $tempreg,$tempreg,<constant>
7285 If we have a large constant, and this is a reference to
7286 an external symbol, we want
7287 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
7288 lui $at,<hiconstant>
7289 addiu $at,$at,<loconstant>
7290 addu $tempreg,$tempreg,$at
7292 (*) Other assemblers seem to prefer GOT_PAGE/GOT_OFST for
7293 local symbols, even though it introduces an additional
7296 if (offset_expr.X_add_number)
7298 expr1.X_add_number = offset_expr.X_add_number;
7299 offset_expr.X_add_number = 0;
7301 relax_start (offset_expr.X_add_symbol);
7302 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
7303 BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
7305 if (expr1.X_add_number >= -0x8000
7306 && expr1.X_add_number < 0x8000)
7308 macro_build (&expr1, ADDRESS_ADDI_INSN, "t,r,j",
7309 tempreg, tempreg, BFD_RELOC_LO16);
7311 else if (IS_SEXT_32BIT_NUM (expr1.X_add_number + 0x8000))
7313 /* If we are going to add in a base register, and the
7314 target register and the base register are the same,
7315 then we are using AT as a temporary register. Since
7316 we want to load the constant into AT, we add our
7317 current AT (from the global offset table) and the
7318 register into the register now, and pretend we were
7319 not using a base register. */
7324 gas_assert (tempreg == AT);
7325 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
7331 load_register (AT, &expr1, HAVE_64BIT_ADDRESSES);
7332 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
7338 as_bad (_("PIC code offset overflow (max 32 signed bits)"));
7341 offset_expr.X_add_number = expr1.X_add_number;
7343 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
7344 BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
7347 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
7348 treg, tempreg, breg);
7354 else if (breg == 0 && (call || tempreg == PIC_CALL_REG))
7356 relax_start (offset_expr.X_add_symbol);
7357 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
7358 BFD_RELOC_MIPS_CALL16, mips_gp_register);
7360 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
7361 BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
7366 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
7367 BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
7370 else if (mips_big_got && !HAVE_NEWABI)
7373 int lui_reloc_type = (int) BFD_RELOC_MIPS_GOT_HI16;
7374 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT_LO16;
7375 int local_reloc_type = (int) BFD_RELOC_MIPS_GOT16;
7377 /* This is the large GOT case. If this is a reference to an
7378 external symbol, and there is no constant, we want
7379 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
7380 addu $tempreg,$tempreg,$gp
7381 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
7382 or for lca or if tempreg is PIC_CALL_REG
7383 lui $tempreg,<sym> (BFD_RELOC_MIPS_CALL_HI16)
7384 addu $tempreg,$tempreg,$gp
7385 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_CALL_LO16)
7386 For a local symbol, we want
7387 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
7389 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
7391 If we have a small constant, and this is a reference to
7392 an external symbol, we want
7393 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
7394 addu $tempreg,$tempreg,$gp
7395 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
7397 addiu $tempreg,$tempreg,<constant>
7398 For a local symbol, we want
7399 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
7401 addiu $tempreg,$tempreg,<constant> (BFD_RELOC_LO16)
7403 If we have a large constant, and this is a reference to
7404 an external symbol, we want
7405 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
7406 addu $tempreg,$tempreg,$gp
7407 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
7408 lui $at,<hiconstant>
7409 addiu $at,$at,<loconstant>
7410 addu $tempreg,$tempreg,$at
7411 For a local symbol, we want
7412 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
7413 lui $at,<hiconstant>
7414 addiu $at,$at,<loconstant> (BFD_RELOC_LO16)
7415 addu $tempreg,$tempreg,$at
7418 expr1.X_add_number = offset_expr.X_add_number;
7419 offset_expr.X_add_number = 0;
7420 relax_start (offset_expr.X_add_symbol);
7421 gpdelay = reg_needs_delay (mips_gp_register);
7422 if (expr1.X_add_number == 0 && breg == 0
7423 && (call || tempreg == PIC_CALL_REG))
7425 lui_reloc_type = (int) BFD_RELOC_MIPS_CALL_HI16;
7426 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL_LO16;
7428 macro_build (&offset_expr, "lui", LUI_FMT, tempreg, lui_reloc_type);
7429 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
7430 tempreg, tempreg, mips_gp_register);
7431 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
7432 tempreg, lw_reloc_type, tempreg);
7433 if (expr1.X_add_number == 0)
7437 /* We're going to put in an addu instruction using
7438 tempreg, so we may as well insert the nop right
7443 else if (expr1.X_add_number >= -0x8000
7444 && expr1.X_add_number < 0x8000)
7447 macro_build (&expr1, ADDRESS_ADDI_INSN, "t,r,j",
7448 tempreg, tempreg, BFD_RELOC_LO16);
7452 /* If we are going to add in a base register, and the
7453 target register and the base register are the same,
7454 then we are using AT as a temporary register. Since
7455 we want to load the constant into AT, we add our
7456 current AT (from the global offset table) and the
7457 register into the register now, and pretend we were
7458 not using a base register. */
7463 gas_assert (tempreg == AT);
7465 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
7470 load_register (AT, &expr1, HAVE_64BIT_ADDRESSES);
7471 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", dreg, dreg, AT);
7475 offset_expr.X_add_number =
7476 ((expr1.X_add_number + 0x8000) & 0xffff) - 0x8000;
7481 /* This is needed because this instruction uses $gp, but
7482 the first instruction on the main stream does not. */
7483 macro_build (NULL, "nop", "");
7486 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
7487 local_reloc_type, mips_gp_register);
7488 if (expr1.X_add_number >= -0x8000
7489 && expr1.X_add_number < 0x8000)
7492 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
7493 tempreg, tempreg, BFD_RELOC_LO16);
7494 /* FIXME: If add_number is 0, and there was no base
7495 register, the external symbol case ended with a load,
7496 so if the symbol turns out to not be external, and
7497 the next instruction uses tempreg, an unnecessary nop
7498 will be inserted. */
7504 /* We must add in the base register now, as in the
7505 external symbol case. */
7506 gas_assert (tempreg == AT);
7508 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
7511 /* We set breg to 0 because we have arranged to add
7512 it in in both cases. */
7516 macro_build_lui (&expr1, AT);
7517 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
7518 AT, AT, BFD_RELOC_LO16);
7519 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
7520 tempreg, tempreg, AT);
7525 else if (mips_big_got && HAVE_NEWABI)
7527 int lui_reloc_type = (int) BFD_RELOC_MIPS_GOT_HI16;
7528 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT_LO16;
7529 int add_breg_early = 0;
7531 /* This is the large GOT case. If this is a reference to an
7532 external symbol, and there is no constant, we want
7533 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
7534 add $tempreg,$tempreg,$gp
7535 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
7536 or for lca or if tempreg is PIC_CALL_REG
7537 lui $tempreg,<sym> (BFD_RELOC_MIPS_CALL_HI16)
7538 add $tempreg,$tempreg,$gp
7539 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_CALL_LO16)
7541 If we have a small constant, and this is a reference to
7542 an external symbol, we want
7543 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
7544 add $tempreg,$tempreg,$gp
7545 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
7546 addi $tempreg,$tempreg,<constant>
7548 If we have a large constant, and this is a reference to
7549 an external symbol, we want
7550 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
7551 addu $tempreg,$tempreg,$gp
7552 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
7553 lui $at,<hiconstant>
7554 addi $at,$at,<loconstant>
7555 add $tempreg,$tempreg,$at
7557 If we have NewABI, and we know it's a local symbol, we want
7558 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
7559 addiu $reg,$reg,<sym> (BFD_RELOC_MIPS_GOT_OFST)
7560 otherwise we have to resort to GOT_HI16/GOT_LO16. */
7562 relax_start (offset_expr.X_add_symbol);
7564 expr1.X_add_number = offset_expr.X_add_number;
7565 offset_expr.X_add_number = 0;
7567 if (expr1.X_add_number == 0 && breg == 0
7568 && (call || tempreg == PIC_CALL_REG))
7570 lui_reloc_type = (int) BFD_RELOC_MIPS_CALL_HI16;
7571 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL_LO16;
7573 macro_build (&offset_expr, "lui", LUI_FMT, tempreg, lui_reloc_type);
7574 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
7575 tempreg, tempreg, mips_gp_register);
7576 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
7577 tempreg, lw_reloc_type, tempreg);
7579 if (expr1.X_add_number == 0)
7581 else if (expr1.X_add_number >= -0x8000
7582 && expr1.X_add_number < 0x8000)
7584 macro_build (&expr1, ADDRESS_ADDI_INSN, "t,r,j",
7585 tempreg, tempreg, BFD_RELOC_LO16);
7587 else if (IS_SEXT_32BIT_NUM (expr1.X_add_number + 0x8000))
7589 /* If we are going to add in a base register, and the
7590 target register and the base register are the same,
7591 then we are using AT as a temporary register. Since
7592 we want to load the constant into AT, we add our
7593 current AT (from the global offset table) and the
7594 register into the register now, and pretend we were
7595 not using a base register. */
7600 gas_assert (tempreg == AT);
7601 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
7607 load_register (AT, &expr1, HAVE_64BIT_ADDRESSES);
7608 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", dreg, dreg, AT);
7613 as_bad (_("PIC code offset overflow (max 32 signed bits)"));
7616 offset_expr.X_add_number = expr1.X_add_number;
7617 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
7618 BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register);
7619 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j", tempreg,
7620 tempreg, BFD_RELOC_MIPS_GOT_OFST);
7623 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
7624 treg, tempreg, breg);
7634 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", treg, tempreg, breg);
7638 gas_assert (!mips_opts.micromips);
7640 unsigned long temp = (treg << 16) | (0x01);
7641 macro_build (NULL, "c2", "C", temp);
7646 gas_assert (!mips_opts.micromips);
7648 unsigned long temp = (0x02);
7649 macro_build (NULL, "c2", "C", temp);
7654 gas_assert (!mips_opts.micromips);
7656 unsigned long temp = (treg << 16) | (0x02);
7657 macro_build (NULL, "c2", "C", temp);
7662 gas_assert (!mips_opts.micromips);
7663 macro_build (NULL, "c2", "C", 3);
7667 gas_assert (!mips_opts.micromips);
7669 unsigned long temp = (treg << 16) | 0x03;
7670 macro_build (NULL, "c2", "C", temp);
7675 /* The j instruction may not be used in PIC code, since it
7676 requires an absolute address. We convert it to a b
7678 if (mips_pic == NO_PIC)
7679 macro_build (&offset_expr, "j", "a");
7681 macro_build (&offset_expr, "b", "p");
7684 /* The jal instructions must be handled as macros because when
7685 generating PIC code they expand to multi-instruction
7686 sequences. Normally they are simple instructions. */
7691 gas_assert (mips_opts.micromips);
7699 if (mips_pic == NO_PIC)
7701 s = jals ? "jalrs" : "jalr";
7702 if (mips_opts.micromips && dreg == RA)
7703 macro_build (NULL, s, "mj", sreg);
7705 macro_build (NULL, s, JALR_FMT, dreg, sreg);
7709 int cprestore = (mips_pic == SVR4_PIC && !HAVE_NEWABI
7710 && mips_cprestore_offset >= 0);
7712 if (sreg != PIC_CALL_REG)
7713 as_warn (_("MIPS PIC call to register other than $25"));
7715 s = (mips_opts.micromips && (!mips_opts.noreorder || cprestore)
7716 ? "jalrs" : "jalr");
7717 if (mips_opts.micromips && dreg == RA)
7718 macro_build (NULL, s, "mj", sreg);
7720 macro_build (NULL, s, JALR_FMT, dreg, sreg);
7721 if (mips_pic == SVR4_PIC && !HAVE_NEWABI)
7723 if (mips_cprestore_offset < 0)
7724 as_warn (_("No .cprestore pseudo-op used in PIC code"));
7727 if (!mips_frame_reg_valid)
7729 as_warn (_("No .frame pseudo-op used in PIC code"));
7730 /* Quiet this warning. */
7731 mips_frame_reg_valid = 1;
7733 if (!mips_cprestore_valid)
7735 as_warn (_("No .cprestore pseudo-op used in PIC code"));
7736 /* Quiet this warning. */
7737 mips_cprestore_valid = 1;
7739 if (mips_opts.noreorder)
7740 macro_build (NULL, "nop", "");
7741 expr1.X_add_number = mips_cprestore_offset;
7742 macro_build_ldst_constoffset (&expr1, ADDRESS_LOAD_INSN,
7745 HAVE_64BIT_ADDRESSES);
7753 gas_assert (mips_opts.micromips);
7757 if (mips_pic == NO_PIC)
7758 macro_build (&offset_expr, jals ? "jals" : "jal", "a");
7759 else if (mips_pic == SVR4_PIC)
7761 /* If this is a reference to an external symbol, and we are
7762 using a small GOT, we want
7763 lw $25,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
7767 lw $gp,cprestore($sp)
7768 The cprestore value is set using the .cprestore
7769 pseudo-op. If we are using a big GOT, we want
7770 lui $25,<sym> (BFD_RELOC_MIPS_CALL_HI16)
7772 lw $25,<sym>($25) (BFD_RELOC_MIPS_CALL_LO16)
7776 lw $gp,cprestore($sp)
7777 If the symbol is not external, we want
7778 lw $25,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
7780 addiu $25,$25,<sym> (BFD_RELOC_LO16)
7783 lw $gp,cprestore($sp)
7785 For NewABI, we use the same CALL16 or CALL_HI16/CALL_LO16
7786 sequences above, minus nops, unless the symbol is local,
7787 which enables us to use GOT_PAGE/GOT_OFST (big got) or
7793 relax_start (offset_expr.X_add_symbol);
7794 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
7795 PIC_CALL_REG, BFD_RELOC_MIPS_CALL16,
7798 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
7799 PIC_CALL_REG, BFD_RELOC_MIPS_GOT_DISP,
7805 relax_start (offset_expr.X_add_symbol);
7806 macro_build (&offset_expr, "lui", LUI_FMT, PIC_CALL_REG,
7807 BFD_RELOC_MIPS_CALL_HI16);
7808 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", PIC_CALL_REG,
7809 PIC_CALL_REG, mips_gp_register);
7810 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
7811 PIC_CALL_REG, BFD_RELOC_MIPS_CALL_LO16,
7814 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
7815 PIC_CALL_REG, BFD_RELOC_MIPS_GOT_PAGE,
7817 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
7818 PIC_CALL_REG, PIC_CALL_REG,
7819 BFD_RELOC_MIPS_GOT_OFST);
7823 macro_build_jalr (&offset_expr, 0);
7827 relax_start (offset_expr.X_add_symbol);
7830 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
7831 PIC_CALL_REG, BFD_RELOC_MIPS_CALL16,
7840 gpdelay = reg_needs_delay (mips_gp_register);
7841 macro_build (&offset_expr, "lui", LUI_FMT, PIC_CALL_REG,
7842 BFD_RELOC_MIPS_CALL_HI16);
7843 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", PIC_CALL_REG,
7844 PIC_CALL_REG, mips_gp_register);
7845 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
7846 PIC_CALL_REG, BFD_RELOC_MIPS_CALL_LO16,
7851 macro_build (NULL, "nop", "");
7853 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
7854 PIC_CALL_REG, BFD_RELOC_MIPS_GOT16,
7857 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
7858 PIC_CALL_REG, PIC_CALL_REG, BFD_RELOC_LO16);
7860 macro_build_jalr (&offset_expr, mips_cprestore_offset >= 0);
7862 if (mips_cprestore_offset < 0)
7863 as_warn (_("No .cprestore pseudo-op used in PIC code"));
7866 if (!mips_frame_reg_valid)
7868 as_warn (_("No .frame pseudo-op used in PIC code"));
7869 /* Quiet this warning. */
7870 mips_frame_reg_valid = 1;
7872 if (!mips_cprestore_valid)
7874 as_warn (_("No .cprestore pseudo-op used in PIC code"));
7875 /* Quiet this warning. */
7876 mips_cprestore_valid = 1;
7878 if (mips_opts.noreorder)
7879 macro_build (NULL, "nop", "");
7880 expr1.X_add_number = mips_cprestore_offset;
7881 macro_build_ldst_constoffset (&expr1, ADDRESS_LOAD_INSN,
7884 HAVE_64BIT_ADDRESSES);
7888 else if (mips_pic == VXWORKS_PIC)
7889 as_bad (_("Non-PIC jump used in PIC library"));
7899 treg = EXTRACT_OPERAND (mips_opts.micromips, 3BITPOS, *ip);
7907 treg = EXTRACT_OPERAND (mips_opts.micromips, 3BITPOS, *ip);
7938 gas_assert (!mips_opts.micromips);
7941 /* Itbl support may require additional care here. */
7948 /* Itbl support may require additional care here. */
7956 off12 = mips_opts.micromips;
7957 /* Itbl support may require additional care here. */
7962 gas_assert (!mips_opts.micromips);
7965 /* Itbl support may require additional care here. */
7973 off12 = mips_opts.micromips;
7980 off12 = mips_opts.micromips;
7986 /* Itbl support may require additional care here. */
7994 off12 = mips_opts.micromips;
7995 /* Itbl support may require additional care here. */
8002 /* Itbl support may require additional care here. */
8010 off12 = mips_opts.micromips;
8017 off12 = mips_opts.micromips;
8024 off12 = mips_opts.micromips;
8031 off12 = mips_opts.micromips;
8038 off12 = mips_opts.micromips;
8043 gas_assert (mips_opts.micromips);
8052 gas_assert (mips_opts.micromips);
8061 gas_assert (mips_opts.micromips);
8069 gas_assert (mips_opts.micromips);
8076 if (breg == treg + lp)
8079 tempreg = treg + lp;
8099 gas_assert (!mips_opts.micromips);
8102 /* Itbl support may require additional care here. */
8109 /* Itbl support may require additional care here. */
8117 off12 = mips_opts.micromips;
8118 /* Itbl support may require additional care here. */
8123 gas_assert (!mips_opts.micromips);
8126 /* Itbl support may require additional care here. */
8134 off12 = mips_opts.micromips;
8141 off12 = mips_opts.micromips;
8148 off12 = mips_opts.micromips;
8155 off12 = mips_opts.micromips;
8161 fmt = mips_opts.micromips ? "k,~(b)" : "k,o(b)";
8162 off12 = mips_opts.micromips;
8168 fmt = !mips_opts.micromips ? "k,o(b)" : "k,~(b)";
8169 off12 = mips_opts.micromips;
8176 /* Itbl support may require additional care here. */
8183 off12 = mips_opts.micromips;
8184 /* Itbl support may require additional care here. */
8189 gas_assert (!mips_opts.micromips);
8192 /* Itbl support may require additional care here. */
8200 off12 = mips_opts.micromips;
8207 off12 = mips_opts.micromips;
8212 gas_assert (mips_opts.micromips);
8220 gas_assert (mips_opts.micromips);
8228 gas_assert (mips_opts.micromips);
8236 gas_assert (mips_opts.micromips);
8246 && NO_ISA_COP (mips_opts.arch)
8247 && (ip->insn_mo->pinfo2 & (INSN2_M_FP_S | INSN2_M_FP_D)) == 0)
8249 as_bad (_("Opcode not supported on this processor: %s"),
8250 mips_cpu_info_from_arch (mips_opts.arch)->name);
8254 if (offset_expr.X_op != O_constant
8255 && offset_expr.X_op != O_symbol)
8257 as_bad (_("Expression too complex"));
8258 offset_expr.X_op = O_constant;
8261 if (HAVE_32BIT_ADDRESSES
8262 && !IS_SEXT_32BIT_NUM (offset_expr.X_add_number))
8266 sprintf_vma (value, offset_expr.X_add_number);
8267 as_bad (_("Number (0x%s) larger than 32 bits"), value);
8270 /* A constant expression in PIC code can be handled just as it
8271 is in non PIC code. */
8272 if (offset_expr.X_op == O_constant)
8276 expr1.X_add_number = offset_expr.X_add_number;
8277 normalize_address_expr (&expr1);
8278 if (!off12 && !IS_SEXT_16BIT_NUM (expr1.X_add_number))
8280 expr1.X_add_number = ((expr1.X_add_number + 0x8000)
8281 & ~(bfd_vma) 0xffff);
8284 else if (off12 && !IS_SEXT_12BIT_NUM (expr1.X_add_number))
8286 expr1.X_add_number = ((expr1.X_add_number + 0x800)
8287 & ~(bfd_vma) 0xfff);
8292 load_register (tempreg, &expr1, HAVE_64BIT_ADDRESSES);
8294 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
8295 tempreg, tempreg, breg);
8299 macro_build (&offset_expr, s, fmt, treg, BFD_RELOC_LO16, breg);
8301 macro_build (NULL, s, fmt,
8302 treg, (unsigned long) offset_expr.X_add_number, breg);
8306 /* A 12-bit offset field is too narrow to be used for a low-part
8307 relocation, so load the whole address into the auxillary
8308 register. In the case of "A(b)" addresses, we first load
8309 absolute address "A" into the register and then add base
8310 register "b". In the case of "o(b)" addresses, we simply
8311 need to add 16-bit offset "o" to base register "b", and
8312 offset_reloc already contains the relocations associated
8316 load_address (tempreg, &offset_expr, &used_at);
8318 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
8319 tempreg, tempreg, breg);
8322 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
8324 offset_reloc[0], offset_reloc[1], offset_reloc[2]);
8325 expr1.X_add_number = 0;
8326 macro_build (NULL, s, fmt,
8327 treg, (unsigned long) expr1.X_add_number, tempreg);
8329 else if (mips_pic == NO_PIC)
8331 /* If this is a reference to a GP relative symbol, and there
8332 is no base register, we want
8333 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
8334 Otherwise, if there is no base register, we want
8335 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
8336 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
8337 If we have a constant, we need two instructions anyhow,
8338 so we always use the latter form.
8340 If we have a base register, and this is a reference to a
8341 GP relative symbol, we want
8342 addu $tempreg,$breg,$gp
8343 <op> $treg,<sym>($tempreg) (BFD_RELOC_GPREL16)
8345 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
8346 addu $tempreg,$tempreg,$breg
8347 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
8348 With a constant we always use the latter case.
8350 With 64bit address space and no base register and $at usable,
8352 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
8353 lui $at,<sym> (BFD_RELOC_HI16_S)
8354 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
8357 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
8358 If we have a base register, we want
8359 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
8360 lui $at,<sym> (BFD_RELOC_HI16_S)
8361 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
8365 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
8367 Without $at we can't generate the optimal path for superscalar
8368 processors here since this would require two temporary registers.
8369 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
8370 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
8372 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
8374 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
8375 If we have a base register, we want
8376 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
8377 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
8379 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
8381 daddu $tempreg,$tempreg,$breg
8382 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
8384 For GP relative symbols in 64bit address space we can use
8385 the same sequence as in 32bit address space. */
8386 if (HAVE_64BIT_SYMBOLS)
8388 if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
8389 && !nopic_need_relax (offset_expr.X_add_symbol, 1))
8391 relax_start (offset_expr.X_add_symbol);
8394 macro_build (&offset_expr, s, fmt, treg,
8395 BFD_RELOC_GPREL16, mips_gp_register);
8399 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
8400 tempreg, breg, mips_gp_register);
8401 macro_build (&offset_expr, s, fmt, treg,
8402 BFD_RELOC_GPREL16, tempreg);
8407 if (used_at == 0 && mips_opts.at)
8409 macro_build (&offset_expr, "lui", LUI_FMT, tempreg,
8410 BFD_RELOC_MIPS_HIGHEST);
8411 macro_build (&offset_expr, "lui", LUI_FMT, AT,
8413 macro_build (&offset_expr, "daddiu", "t,r,j", tempreg,
8414 tempreg, BFD_RELOC_MIPS_HIGHER);
8416 macro_build (NULL, "daddu", "d,v,t", AT, AT, breg);
8417 macro_build (NULL, "dsll32", SHFT_FMT, tempreg, tempreg, 0);
8418 macro_build (NULL, "daddu", "d,v,t", tempreg, tempreg, AT);
8419 macro_build (&offset_expr, s, fmt, treg, BFD_RELOC_LO16,
8425 macro_build (&offset_expr, "lui", LUI_FMT, tempreg,
8426 BFD_RELOC_MIPS_HIGHEST);
8427 macro_build (&offset_expr, "daddiu", "t,r,j", tempreg,
8428 tempreg, BFD_RELOC_MIPS_HIGHER);
8429 macro_build (NULL, "dsll", SHFT_FMT, tempreg, tempreg, 16);
8430 macro_build (&offset_expr, "daddiu", "t,r,j", tempreg,
8431 tempreg, BFD_RELOC_HI16_S);
8432 macro_build (NULL, "dsll", SHFT_FMT, tempreg, tempreg, 16);
8434 macro_build (NULL, "daddu", "d,v,t",
8435 tempreg, tempreg, breg);
8436 macro_build (&offset_expr, s, fmt, treg,
8437 BFD_RELOC_LO16, tempreg);
8440 if (mips_relax.sequence)
8447 if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
8448 && !nopic_need_relax (offset_expr.X_add_symbol, 1))
8450 relax_start (offset_expr.X_add_symbol);
8451 macro_build (&offset_expr, s, fmt, treg, BFD_RELOC_GPREL16,
8455 macro_build_lui (&offset_expr, tempreg);
8456 macro_build (&offset_expr, s, fmt, treg,
8457 BFD_RELOC_LO16, tempreg);
8458 if (mips_relax.sequence)
8463 if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
8464 && !nopic_need_relax (offset_expr.X_add_symbol, 1))
8466 relax_start (offset_expr.X_add_symbol);
8467 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
8468 tempreg, breg, mips_gp_register);
8469 macro_build (&offset_expr, s, fmt, treg,
8470 BFD_RELOC_GPREL16, tempreg);
8473 macro_build_lui (&offset_expr, tempreg);
8474 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
8475 tempreg, tempreg, breg);
8476 macro_build (&offset_expr, s, fmt, treg,
8477 BFD_RELOC_LO16, tempreg);
8478 if (mips_relax.sequence)
8482 else if (!mips_big_got)
8484 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT16;
8486 /* If this is a reference to an external symbol, we want
8487 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
8489 <op> $treg,0($tempreg)
8491 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
8493 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
8494 <op> $treg,0($tempreg)
8497 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
8498 <op> $treg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_OFST)
8500 If there is a base register, we add it to $tempreg before
8501 the <op>. If there is a constant, we stick it in the
8502 <op> instruction. We don't handle constants larger than
8503 16 bits, because we have no way to load the upper 16 bits
8504 (actually, we could handle them for the subset of cases
8505 in which we are not using $at). */
8506 gas_assert (offset_expr.X_op == O_symbol);
8509 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
8510 BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register);
8512 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
8513 tempreg, tempreg, breg);
8514 macro_build (&offset_expr, s, fmt, treg,
8515 BFD_RELOC_MIPS_GOT_OFST, tempreg);
8518 expr1.X_add_number = offset_expr.X_add_number;
8519 offset_expr.X_add_number = 0;
8520 if (expr1.X_add_number < -0x8000
8521 || expr1.X_add_number >= 0x8000)
8522 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
8523 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
8524 lw_reloc_type, mips_gp_register);
8526 relax_start (offset_expr.X_add_symbol);
8528 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j", tempreg,
8529 tempreg, BFD_RELOC_LO16);
8532 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
8533 tempreg, tempreg, breg);
8534 macro_build (&expr1, s, fmt, treg, BFD_RELOC_LO16, tempreg);
8536 else if (mips_big_got && !HAVE_NEWABI)
8540 /* If this is a reference to an external symbol, we want
8541 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
8542 addu $tempreg,$tempreg,$gp
8543 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
8544 <op> $treg,0($tempreg)
8546 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
8548 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
8549 <op> $treg,0($tempreg)
8550 If there is a base register, we add it to $tempreg before
8551 the <op>. If there is a constant, we stick it in the
8552 <op> instruction. We don't handle constants larger than
8553 16 bits, because we have no way to load the upper 16 bits
8554 (actually, we could handle them for the subset of cases
8555 in which we are not using $at). */
8556 gas_assert (offset_expr.X_op == O_symbol);
8557 expr1.X_add_number = offset_expr.X_add_number;
8558 offset_expr.X_add_number = 0;
8559 if (expr1.X_add_number < -0x8000
8560 || expr1.X_add_number >= 0x8000)
8561 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
8562 gpdelay = reg_needs_delay (mips_gp_register);
8563 relax_start (offset_expr.X_add_symbol);
8564 macro_build (&offset_expr, "lui", LUI_FMT, tempreg,
8565 BFD_RELOC_MIPS_GOT_HI16);
8566 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", tempreg, tempreg,
8568 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
8569 BFD_RELOC_MIPS_GOT_LO16, tempreg);
8572 macro_build (NULL, "nop", "");
8573 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
8574 BFD_RELOC_MIPS_GOT16, mips_gp_register);
8576 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j", tempreg,
8577 tempreg, BFD_RELOC_LO16);
8581 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
8582 tempreg, tempreg, breg);
8583 macro_build (&expr1, s, fmt, treg, BFD_RELOC_LO16, tempreg);
8585 else if (mips_big_got && HAVE_NEWABI)
8587 /* If this is a reference to an external symbol, we want
8588 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
8589 add $tempreg,$tempreg,$gp
8590 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
8591 <op> $treg,<ofst>($tempreg)
8592 Otherwise, for local symbols, we want:
8593 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
8594 <op> $treg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_OFST) */
8595 gas_assert (offset_expr.X_op == O_symbol);
8596 expr1.X_add_number = offset_expr.X_add_number;
8597 offset_expr.X_add_number = 0;
8598 if (expr1.X_add_number < -0x8000
8599 || expr1.X_add_number >= 0x8000)
8600 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
8601 relax_start (offset_expr.X_add_symbol);
8602 macro_build (&offset_expr, "lui", LUI_FMT, tempreg,
8603 BFD_RELOC_MIPS_GOT_HI16);
8604 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", tempreg, tempreg,
8606 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
8607 BFD_RELOC_MIPS_GOT_LO16, tempreg);
8609 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
8610 tempreg, tempreg, breg);
8611 macro_build (&expr1, s, fmt, treg, BFD_RELOC_LO16, tempreg);
8614 offset_expr.X_add_number = expr1.X_add_number;
8615 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
8616 BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register);
8618 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
8619 tempreg, tempreg, breg);
8620 macro_build (&offset_expr, s, fmt, treg,
8621 BFD_RELOC_MIPS_GOT_OFST, tempreg);
8631 load_register (treg, &imm_expr, 0);
8635 load_register (treg, &imm_expr, 1);
8639 if (imm_expr.X_op == O_constant)
8642 load_register (AT, &imm_expr, 0);
8643 macro_build (NULL, "mtc1", "t,G", AT, treg);
8648 gas_assert (offset_expr.X_op == O_symbol
8649 && strcmp (segment_name (S_GET_SEGMENT
8650 (offset_expr.X_add_symbol)),
8652 && offset_expr.X_add_number == 0);
8653 macro_build (&offset_expr, "lwc1", "T,o(b)", treg,
8654 BFD_RELOC_MIPS_LITERAL, mips_gp_register);
8659 /* Check if we have a constant in IMM_EXPR. If the GPRs are 64 bits
8660 wide, IMM_EXPR is the entire value. Otherwise IMM_EXPR is the high
8661 order 32 bits of the value and the low order 32 bits are either
8662 zero or in OFFSET_EXPR. */
8663 if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big)
8665 if (HAVE_64BIT_GPRS)
8666 load_register (treg, &imm_expr, 1);
8671 if (target_big_endian)
8683 load_register (hreg, &imm_expr, 0);
8686 if (offset_expr.X_op == O_absent)
8687 move_register (lreg, 0);
8690 gas_assert (offset_expr.X_op == O_constant);
8691 load_register (lreg, &offset_expr, 0);
8698 /* We know that sym is in the .rdata section. First we get the
8699 upper 16 bits of the address. */
8700 if (mips_pic == NO_PIC)
8702 macro_build_lui (&offset_expr, AT);
8707 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", AT,
8708 BFD_RELOC_MIPS_GOT16, mips_gp_register);
8712 /* Now we load the register(s). */
8713 if (HAVE_64BIT_GPRS)
8716 macro_build (&offset_expr, "ld", "t,o(b)", treg, BFD_RELOC_LO16, AT);
8721 macro_build (&offset_expr, "lw", "t,o(b)", treg, BFD_RELOC_LO16, AT);
8724 /* FIXME: How in the world do we deal with the possible
8726 offset_expr.X_add_number += 4;
8727 macro_build (&offset_expr, "lw", "t,o(b)",
8728 treg + 1, BFD_RELOC_LO16, AT);
8734 /* Check if we have a constant in IMM_EXPR. If the FPRs are 64 bits
8735 wide, IMM_EXPR is the entire value and the GPRs are known to be 64
8736 bits wide as well. Otherwise IMM_EXPR is the high order 32 bits of
8737 the value and the low order 32 bits are either zero or in
8739 if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big)
8742 load_register (AT, &imm_expr, HAVE_64BIT_FPRS);
8743 if (HAVE_64BIT_FPRS)
8745 gas_assert (HAVE_64BIT_GPRS);
8746 macro_build (NULL, "dmtc1", "t,S", AT, treg);
8750 macro_build (NULL, "mtc1", "t,G", AT, treg + 1);
8751 if (offset_expr.X_op == O_absent)
8752 macro_build (NULL, "mtc1", "t,G", 0, treg);
8755 gas_assert (offset_expr.X_op == O_constant);
8756 load_register (AT, &offset_expr, 0);
8757 macro_build (NULL, "mtc1", "t,G", AT, treg);
8763 gas_assert (offset_expr.X_op == O_symbol
8764 && offset_expr.X_add_number == 0);
8765 s = segment_name (S_GET_SEGMENT (offset_expr.X_add_symbol));
8766 if (strcmp (s, ".lit8") == 0)
8768 if (mips_opts.isa != ISA_MIPS1 || mips_opts.micromips)
8770 macro_build (&offset_expr, "ldc1", "T,o(b)", treg,
8771 BFD_RELOC_MIPS_LITERAL, mips_gp_register);
8774 breg = mips_gp_register;
8775 r = BFD_RELOC_MIPS_LITERAL;
8780 gas_assert (strcmp (s, RDATA_SECTION_NAME) == 0);
8782 if (mips_pic != NO_PIC)
8783 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", AT,
8784 BFD_RELOC_MIPS_GOT16, mips_gp_register);
8787 /* FIXME: This won't work for a 64 bit address. */
8788 macro_build_lui (&offset_expr, AT);
8791 if (mips_opts.isa != ISA_MIPS1 || mips_opts.micromips)
8793 macro_build (&offset_expr, "ldc1", "T,o(b)",
8794 treg, BFD_RELOC_LO16, AT);
8803 /* Even on a big endian machine $fn comes before $fn+1. We have
8804 to adjust when loading from memory. */
8807 gas_assert (!mips_opts.micromips);
8808 gas_assert (mips_opts.isa == ISA_MIPS1);
8809 macro_build (&offset_expr, "lwc1", "T,o(b)",
8810 target_big_endian ? treg + 1 : treg, r, breg);
8811 /* FIXME: A possible overflow which I don't know how to deal
8813 offset_expr.X_add_number += 4;
8814 macro_build (&offset_expr, "lwc1", "T,o(b)",
8815 target_big_endian ? treg : treg + 1, r, breg);
8819 gas_assert (!mips_opts.micromips);
8820 gas_assert (mips_opts.isa == ISA_MIPS1);
8821 /* Even on a big endian machine $fn comes before $fn+1. We have
8822 to adjust when storing to memory. */
8823 macro_build (&offset_expr, "swc1", "T,o(b)",
8824 target_big_endian ? treg + 1 : treg, BFD_RELOC_LO16, breg);
8825 offset_expr.X_add_number += 4;
8826 macro_build (&offset_expr, "swc1", "T,o(b)",
8827 target_big_endian ? treg : treg + 1, BFD_RELOC_LO16, breg);
8831 gas_assert (!mips_opts.micromips);
8833 * The MIPS assembler seems to check for X_add_number not
8834 * being double aligned and generating:
8837 * addiu at,at,%lo(foo+1)
8840 * But, the resulting address is the same after relocation so why
8841 * generate the extra instruction?
8843 /* Itbl support may require additional care here. */
8846 if (mips_opts.isa != ISA_MIPS1)
8855 gas_assert (!mips_opts.micromips);
8856 /* Itbl support may require additional care here. */
8859 if (mips_opts.isa != ISA_MIPS1)
8869 if (HAVE_64BIT_GPRS)
8879 if (HAVE_64BIT_GPRS)
8887 if (offset_expr.X_op != O_symbol
8888 && offset_expr.X_op != O_constant)
8890 as_bad (_("Expression too complex"));
8891 offset_expr.X_op = O_constant;
8894 if (HAVE_32BIT_ADDRESSES
8895 && !IS_SEXT_32BIT_NUM (offset_expr.X_add_number))
8899 sprintf_vma (value, offset_expr.X_add_number);
8900 as_bad (_("Number (0x%s) larger than 32 bits"), value);
8903 /* Even on a big endian machine $fn comes before $fn+1. We have
8904 to adjust when loading from memory. We set coproc if we must
8905 load $fn+1 first. */
8906 /* Itbl support may require additional care here. */
8907 if (!target_big_endian)
8910 if (mips_pic == NO_PIC || offset_expr.X_op == O_constant)
8912 /* If this is a reference to a GP relative symbol, we want
8913 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
8914 <op> $treg+1,<sym>+4($gp) (BFD_RELOC_GPREL16)
8915 If we have a base register, we use this
8917 <op> $treg,<sym>($at) (BFD_RELOC_GPREL16)
8918 <op> $treg+1,<sym>+4($at) (BFD_RELOC_GPREL16)
8919 If this is not a GP relative symbol, we want
8920 lui $at,<sym> (BFD_RELOC_HI16_S)
8921 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
8922 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
8923 If there is a base register, we add it to $at after the
8924 lui instruction. If there is a constant, we always use
8926 if (offset_expr.X_op == O_symbol
8927 && (valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
8928 && !nopic_need_relax (offset_expr.X_add_symbol, 1))
8930 relax_start (offset_expr.X_add_symbol);
8933 tempreg = mips_gp_register;
8937 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
8938 AT, breg, mips_gp_register);
8943 /* Itbl support may require additional care here. */
8944 macro_build (&offset_expr, s, fmt, coproc ? treg + 1 : treg,
8945 BFD_RELOC_GPREL16, tempreg);
8946 offset_expr.X_add_number += 4;
8948 /* Set mips_optimize to 2 to avoid inserting an
8950 hold_mips_optimize = mips_optimize;
8952 /* Itbl support may require additional care here. */
8953 macro_build (&offset_expr, s, fmt, coproc ? treg : treg + 1,
8954 BFD_RELOC_GPREL16, tempreg);
8955 mips_optimize = hold_mips_optimize;
8959 offset_expr.X_add_number -= 4;
8962 macro_build_lui (&offset_expr, AT);
8964 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, breg, AT);
8965 /* Itbl support may require additional care here. */
8966 macro_build (&offset_expr, s, fmt, coproc ? treg + 1 : treg,
8967 BFD_RELOC_LO16, AT);
8968 /* FIXME: How do we handle overflow here? */
8969 offset_expr.X_add_number += 4;
8970 /* Itbl support may require additional care here. */
8971 macro_build (&offset_expr, s, fmt, coproc ? treg : treg + 1,
8972 BFD_RELOC_LO16, AT);
8973 if (mips_relax.sequence)
8976 else if (!mips_big_got)
8978 /* If this is a reference to an external symbol, we want
8979 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
8984 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
8986 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
8987 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
8988 If there is a base register we add it to $at before the
8989 lwc1 instructions. If there is a constant we include it
8990 in the lwc1 instructions. */
8992 expr1.X_add_number = offset_expr.X_add_number;
8993 if (expr1.X_add_number < -0x8000
8994 || expr1.X_add_number >= 0x8000 - 4)
8995 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
8996 load_got_offset (AT, &offset_expr);
8999 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, breg, AT);
9001 /* Set mips_optimize to 2 to avoid inserting an undesired
9003 hold_mips_optimize = mips_optimize;
9006 /* Itbl support may require additional care here. */
9007 relax_start (offset_expr.X_add_symbol);
9008 macro_build (&expr1, s, fmt, coproc ? treg + 1 : treg,
9009 BFD_RELOC_LO16, AT);
9010 expr1.X_add_number += 4;
9011 macro_build (&expr1, s, fmt, coproc ? treg : treg + 1,
9012 BFD_RELOC_LO16, AT);
9014 macro_build (&offset_expr, s, fmt, coproc ? treg + 1 : treg,
9015 BFD_RELOC_LO16, AT);
9016 offset_expr.X_add_number += 4;
9017 macro_build (&offset_expr, s, fmt, coproc ? treg : treg + 1,
9018 BFD_RELOC_LO16, AT);
9021 mips_optimize = hold_mips_optimize;
9023 else if (mips_big_got)
9027 /* If this is a reference to an external symbol, we want
9028 lui $at,<sym> (BFD_RELOC_MIPS_GOT_HI16)
9030 lw $at,<sym>($at) (BFD_RELOC_MIPS_GOT_LO16)
9035 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
9037 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
9038 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
9039 If there is a base register we add it to $at before the
9040 lwc1 instructions. If there is a constant we include it
9041 in the lwc1 instructions. */
9043 expr1.X_add_number = offset_expr.X_add_number;
9044 offset_expr.X_add_number = 0;
9045 if (expr1.X_add_number < -0x8000
9046 || expr1.X_add_number >= 0x8000 - 4)
9047 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
9048 gpdelay = reg_needs_delay (mips_gp_register);
9049 relax_start (offset_expr.X_add_symbol);
9050 macro_build (&offset_expr, "lui", LUI_FMT,
9051 AT, BFD_RELOC_MIPS_GOT_HI16);
9052 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
9053 AT, AT, mips_gp_register);
9054 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
9055 AT, BFD_RELOC_MIPS_GOT_LO16, AT);
9058 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, breg, AT);
9059 /* Itbl support may require additional care here. */
9060 macro_build (&expr1, s, fmt, coproc ? treg + 1 : treg,
9061 BFD_RELOC_LO16, AT);
9062 expr1.X_add_number += 4;
9064 /* Set mips_optimize to 2 to avoid inserting an undesired
9066 hold_mips_optimize = mips_optimize;
9068 /* Itbl support may require additional care here. */
9069 macro_build (&expr1, s, fmt, coproc ? treg : treg + 1,
9070 BFD_RELOC_LO16, AT);
9071 mips_optimize = hold_mips_optimize;
9072 expr1.X_add_number -= 4;
9075 offset_expr.X_add_number = expr1.X_add_number;
9077 macro_build (NULL, "nop", "");
9078 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", AT,
9079 BFD_RELOC_MIPS_GOT16, mips_gp_register);
9082 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, breg, AT);
9083 /* Itbl support may require additional care here. */
9084 macro_build (&offset_expr, s, fmt, coproc ? treg + 1 : treg,
9085 BFD_RELOC_LO16, AT);
9086 offset_expr.X_add_number += 4;
9088 /* Set mips_optimize to 2 to avoid inserting an undesired
9090 hold_mips_optimize = mips_optimize;
9092 /* Itbl support may require additional care here. */
9093 macro_build (&offset_expr, s, fmt, coproc ? treg : treg + 1,
9094 BFD_RELOC_LO16, AT);
9095 mips_optimize = hold_mips_optimize;
9104 s = HAVE_64BIT_GPRS ? "ld" : "lw";
9107 s = HAVE_64BIT_GPRS ? "sd" : "sw";
9109 macro_build (&offset_expr, s, "t,o(b)", treg,
9110 -1, offset_reloc[0], offset_reloc[1], offset_reloc[2],
9112 if (!HAVE_64BIT_GPRS)
9114 offset_expr.X_add_number += 4;
9115 macro_build (&offset_expr, s, "t,o(b)", treg + 1,
9116 -1, offset_reloc[0], offset_reloc[1], offset_reloc[2],
9121 /* New code added to support COPZ instructions.
9122 This code builds table entries out of the macros in mip_opcodes.
9123 R4000 uses interlocks to handle coproc delays.
9124 Other chips (like the R3000) require nops to be inserted for delays.
9126 FIXME: Currently, we require that the user handle delays.
9127 In order to fill delay slots for non-interlocked chips,
9128 we must have a way to specify delays based on the coprocessor.
9129 Eg. 4 cycles if load coproc reg from memory, 1 if in cache, etc.
9130 What are the side-effects of the cop instruction?
9131 What cache support might we have and what are its effects?
9132 Both coprocessor & memory require delays. how long???
9133 What registers are read/set/modified?
9135 If an itbl is provided to interpret cop instructions,
9136 this knowledge can be encoded in the itbl spec. */
9150 gas_assert (!mips_opts.micromips);
9151 if (NO_ISA_COP (mips_opts.arch)
9152 && (ip->insn_mo->pinfo2 & INSN2_M_FP_S) == 0)
9154 as_bad (_("opcode not supported on this processor: %s"),
9155 mips_cpu_info_from_arch (mips_opts.arch)->name);
9159 /* For now we just do C (same as Cz). The parameter will be
9160 stored in insn_opcode by mips_ip. */
9161 macro_build (NULL, s, "C", ip->insn_opcode);
9165 move_register (dreg, sreg);
9171 macro_build (NULL, dbl ? "dmultu" : "multu", "s,t", sreg, treg);
9172 macro_build (NULL, "mflo", MFHL_FMT, dreg);
9178 /* The MIPS assembler some times generates shifts and adds. I'm
9179 not trying to be that fancy. GCC should do this for us
9182 load_register (AT, &imm_expr, dbl);
9183 macro_build (NULL, dbl ? "dmult" : "mult", "s,t", sreg, AT);
9184 macro_build (NULL, "mflo", MFHL_FMT, dreg);
9200 load_register (AT, &imm_expr, dbl);
9201 macro_build (NULL, dbl ? "dmult" : "mult", "s,t", sreg, imm ? AT : treg);
9202 macro_build (NULL, "mflo", MFHL_FMT, dreg);
9203 macro_build (NULL, dbl ? "dsra32" : "sra", SHFT_FMT, dreg, dreg, RA);
9204 macro_build (NULL, "mfhi", MFHL_FMT, AT);
9206 macro_build (NULL, "tne", TRAP_FMT, dreg, AT, 6);
9209 if (mips_opts.micromips)
9210 micromips_label_expr (&label_expr);
9212 label_expr.X_add_number = 8;
9213 macro_build (&label_expr, "beq", "s,t,p", dreg, AT);
9214 macro_build (NULL, "nop", "");
9215 macro_build (NULL, "break", BRK_FMT, 6);
9216 if (mips_opts.micromips)
9217 micromips_add_label ();
9220 macro_build (NULL, "mflo", MFHL_FMT, dreg);
9236 load_register (AT, &imm_expr, dbl);
9237 macro_build (NULL, dbl ? "dmultu" : "multu", "s,t",
9238 sreg, imm ? AT : treg);
9239 macro_build (NULL, "mfhi", MFHL_FMT, AT);
9240 macro_build (NULL, "mflo", MFHL_FMT, dreg);
9242 macro_build (NULL, "tne", TRAP_FMT, AT, ZERO, 6);
9245 if (mips_opts.micromips)
9246 micromips_label_expr (&label_expr);
9248 label_expr.X_add_number = 8;
9249 macro_build (&label_expr, "beq", "s,t,p", AT, ZERO);
9250 macro_build (NULL, "nop", "");
9251 macro_build (NULL, "break", BRK_FMT, 6);
9252 if (mips_opts.micromips)
9253 micromips_add_label ();
9259 if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_opts.arch))
9270 macro_build (NULL, "dnegu", "d,w", tempreg, treg);
9271 macro_build (NULL, "drorv", "d,t,s", dreg, sreg, tempreg);
9275 macro_build (NULL, "dsubu", "d,v,t", AT, ZERO, treg);
9276 macro_build (NULL, "dsrlv", "d,t,s", AT, sreg, AT);
9277 macro_build (NULL, "dsllv", "d,t,s", dreg, sreg, treg);
9278 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
9282 if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_opts.arch))
9293 macro_build (NULL, "negu", "d,w", tempreg, treg);
9294 macro_build (NULL, "rorv", "d,t,s", dreg, sreg, tempreg);
9298 macro_build (NULL, "subu", "d,v,t", AT, ZERO, treg);
9299 macro_build (NULL, "srlv", "d,t,s", AT, sreg, AT);
9300 macro_build (NULL, "sllv", "d,t,s", dreg, sreg, treg);
9301 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
9310 if (imm_expr.X_op != O_constant)
9311 as_bad (_("Improper rotate count"));
9312 rot = imm_expr.X_add_number & 0x3f;
9313 if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_opts.arch))
9315 rot = (64 - rot) & 0x3f;
9317 macro_build (NULL, "dror32", SHFT_FMT, dreg, sreg, rot - 32);
9319 macro_build (NULL, "dror", SHFT_FMT, dreg, sreg, rot);
9324 macro_build (NULL, "dsrl", SHFT_FMT, dreg, sreg, 0);
9327 l = (rot < 0x20) ? "dsll" : "dsll32";
9328 rr = ((0x40 - rot) < 0x20) ? "dsrl" : "dsrl32";
9331 macro_build (NULL, l, SHFT_FMT, AT, sreg, rot);
9332 macro_build (NULL, rr, SHFT_FMT, dreg, sreg, (0x20 - rot) & 0x1f);
9333 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
9341 if (imm_expr.X_op != O_constant)
9342 as_bad (_("Improper rotate count"));
9343 rot = imm_expr.X_add_number & 0x1f;
9344 if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_opts.arch))
9346 macro_build (NULL, "ror", SHFT_FMT, dreg, sreg, (32 - rot) & 0x1f);
9351 macro_build (NULL, "srl", SHFT_FMT, dreg, sreg, 0);
9355 macro_build (NULL, "sll", SHFT_FMT, AT, sreg, rot);
9356 macro_build (NULL, "srl", SHFT_FMT, dreg, sreg, (0x20 - rot) & 0x1f);
9357 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
9362 if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_opts.arch))
9364 macro_build (NULL, "drorv", "d,t,s", dreg, sreg, treg);
9368 macro_build (NULL, "dsubu", "d,v,t", AT, ZERO, treg);
9369 macro_build (NULL, "dsllv", "d,t,s", AT, sreg, AT);
9370 macro_build (NULL, "dsrlv", "d,t,s", dreg, sreg, treg);
9371 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
9375 if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_opts.arch))
9377 macro_build (NULL, "rorv", "d,t,s", dreg, sreg, treg);
9381 macro_build (NULL, "subu", "d,v,t", AT, ZERO, treg);
9382 macro_build (NULL, "sllv", "d,t,s", AT, sreg, AT);
9383 macro_build (NULL, "srlv", "d,t,s", dreg, sreg, treg);
9384 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
9393 if (imm_expr.X_op != O_constant)
9394 as_bad (_("Improper rotate count"));
9395 rot = imm_expr.X_add_number & 0x3f;
9396 if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_opts.arch))
9399 macro_build (NULL, "dror32", SHFT_FMT, dreg, sreg, rot - 32);
9401 macro_build (NULL, "dror", SHFT_FMT, dreg, sreg, rot);
9406 macro_build (NULL, "dsrl", SHFT_FMT, dreg, sreg, 0);
9409 rr = (rot < 0x20) ? "dsrl" : "dsrl32";
9410 l = ((0x40 - rot) < 0x20) ? "dsll" : "dsll32";
9413 macro_build (NULL, rr, SHFT_FMT, AT, sreg, rot);
9414 macro_build (NULL, l, SHFT_FMT, dreg, sreg, (0x20 - rot) & 0x1f);
9415 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
9423 if (imm_expr.X_op != O_constant)
9424 as_bad (_("Improper rotate count"));
9425 rot = imm_expr.X_add_number & 0x1f;
9426 if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_opts.arch))
9428 macro_build (NULL, "ror", SHFT_FMT, dreg, sreg, rot);
9433 macro_build (NULL, "srl", SHFT_FMT, dreg, sreg, 0);
9437 macro_build (NULL, "srl", SHFT_FMT, AT, sreg, rot);
9438 macro_build (NULL, "sll", SHFT_FMT, dreg, sreg, (0x20 - rot) & 0x1f);
9439 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
9445 macro_build (&expr1, "sltiu", "t,r,j", dreg, treg, BFD_RELOC_LO16);
9447 macro_build (&expr1, "sltiu", "t,r,j", dreg, sreg, BFD_RELOC_LO16);
9450 macro_build (NULL, "xor", "d,v,t", dreg, sreg, treg);
9451 macro_build (&expr1, "sltiu", "t,r,j", dreg, dreg, BFD_RELOC_LO16);
9456 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
9458 macro_build (&expr1, "sltiu", "t,r,j", dreg, sreg, BFD_RELOC_LO16);
9463 as_warn (_("Instruction %s: result is always false"),
9465 move_register (dreg, 0);
9468 if (CPU_HAS_SEQ (mips_opts.arch)
9469 && -512 <= imm_expr.X_add_number
9470 && imm_expr.X_add_number < 512)
9472 macro_build (NULL, "seqi", "t,r,+Q", dreg, sreg,
9473 (int) imm_expr.X_add_number);
9476 if (imm_expr.X_op == O_constant
9477 && imm_expr.X_add_number >= 0
9478 && imm_expr.X_add_number < 0x10000)
9480 macro_build (&imm_expr, "xori", "t,r,i", dreg, sreg, BFD_RELOC_LO16);
9482 else if (imm_expr.X_op == O_constant
9483 && imm_expr.X_add_number > -0x8000
9484 && imm_expr.X_add_number < 0)
9486 imm_expr.X_add_number = -imm_expr.X_add_number;
9487 macro_build (&imm_expr, HAVE_32BIT_GPRS ? "addiu" : "daddiu",
9488 "t,r,j", dreg, sreg, BFD_RELOC_LO16);
9490 else if (CPU_HAS_SEQ (mips_opts.arch))
9493 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
9494 macro_build (NULL, "seq", "d,v,t", dreg, sreg, AT);
9499 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
9500 macro_build (NULL, "xor", "d,v,t", dreg, sreg, AT);
9503 macro_build (&expr1, "sltiu", "t,r,j", dreg, dreg, BFD_RELOC_LO16);
9506 case M_SGE: /* sreg >= treg <==> not (sreg < treg) */
9512 macro_build (NULL, s, "d,v,t", dreg, sreg, treg);
9513 macro_build (&expr1, "xori", "t,r,i", dreg, dreg, BFD_RELOC_LO16);
9516 case M_SGE_I: /* sreg >= I <==> not (sreg < I) */
9518 if (imm_expr.X_op == O_constant
9519 && imm_expr.X_add_number >= -0x8000
9520 && imm_expr.X_add_number < 0x8000)
9522 macro_build (&imm_expr, mask == M_SGE_I ? "slti" : "sltiu", "t,r,j",
9523 dreg, sreg, BFD_RELOC_LO16);
9527 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
9528 macro_build (NULL, mask == M_SGE_I ? "slt" : "sltu", "d,v,t",
9532 macro_build (&expr1, "xori", "t,r,i", dreg, dreg, BFD_RELOC_LO16);
9535 case M_SGT: /* sreg > treg <==> treg < sreg */
9541 macro_build (NULL, s, "d,v,t", dreg, treg, sreg);
9544 case M_SGT_I: /* sreg > I <==> I < sreg */
9551 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
9552 macro_build (NULL, s, "d,v,t", dreg, AT, sreg);
9555 case M_SLE: /* sreg <= treg <==> treg >= sreg <==> not (treg < sreg) */
9561 macro_build (NULL, s, "d,v,t", dreg, treg, sreg);
9562 macro_build (&expr1, "xori", "t,r,i", dreg, dreg, BFD_RELOC_LO16);
9565 case M_SLE_I: /* sreg <= I <==> I >= sreg <==> not (I < sreg) */
9572 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
9573 macro_build (NULL, s, "d,v,t", dreg, AT, sreg);
9574 macro_build (&expr1, "xori", "t,r,i", dreg, dreg, BFD_RELOC_LO16);
9578 if (imm_expr.X_op == O_constant
9579 && imm_expr.X_add_number >= -0x8000
9580 && imm_expr.X_add_number < 0x8000)
9582 macro_build (&imm_expr, "slti", "t,r,j", dreg, sreg, BFD_RELOC_LO16);
9586 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
9587 macro_build (NULL, "slt", "d,v,t", dreg, sreg, AT);
9591 if (imm_expr.X_op == O_constant
9592 && imm_expr.X_add_number >= -0x8000
9593 && imm_expr.X_add_number < 0x8000)
9595 macro_build (&imm_expr, "sltiu", "t,r,j", dreg, sreg,
9600 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
9601 macro_build (NULL, "sltu", "d,v,t", dreg, sreg, AT);
9606 macro_build (NULL, "sltu", "d,v,t", dreg, 0, treg);
9608 macro_build (NULL, "sltu", "d,v,t", dreg, 0, sreg);
9611 macro_build (NULL, "xor", "d,v,t", dreg, sreg, treg);
9612 macro_build (NULL, "sltu", "d,v,t", dreg, 0, dreg);
9617 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
9619 macro_build (NULL, "sltu", "d,v,t", dreg, 0, sreg);
9624 as_warn (_("Instruction %s: result is always true"),
9626 macro_build (&expr1, HAVE_32BIT_GPRS ? "addiu" : "daddiu", "t,r,j",
9627 dreg, 0, BFD_RELOC_LO16);
9630 if (CPU_HAS_SEQ (mips_opts.arch)
9631 && -512 <= imm_expr.X_add_number
9632 && imm_expr.X_add_number < 512)
9634 macro_build (NULL, "snei", "t,r,+Q", dreg, sreg,
9635 (int) imm_expr.X_add_number);
9638 if (imm_expr.X_op == O_constant
9639 && imm_expr.X_add_number >= 0
9640 && imm_expr.X_add_number < 0x10000)
9642 macro_build (&imm_expr, "xori", "t,r,i", dreg, sreg, BFD_RELOC_LO16);
9644 else if (imm_expr.X_op == O_constant
9645 && imm_expr.X_add_number > -0x8000
9646 && imm_expr.X_add_number < 0)
9648 imm_expr.X_add_number = -imm_expr.X_add_number;
9649 macro_build (&imm_expr, HAVE_32BIT_GPRS ? "addiu" : "daddiu",
9650 "t,r,j", dreg, sreg, BFD_RELOC_LO16);
9652 else if (CPU_HAS_SEQ (mips_opts.arch))
9655 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
9656 macro_build (NULL, "sne", "d,v,t", dreg, sreg, AT);
9661 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
9662 macro_build (NULL, "xor", "d,v,t", dreg, sreg, AT);
9665 macro_build (NULL, "sltu", "d,v,t", dreg, 0, dreg);
9680 if (!mips_opts.micromips)
9682 if (imm_expr.X_op == O_constant
9683 && imm_expr.X_add_number > -0x200
9684 && imm_expr.X_add_number <= 0x200)
9686 macro_build (NULL, s, "t,r,.", dreg, sreg, -imm_expr.X_add_number);
9695 if (imm_expr.X_op == O_constant
9696 && imm_expr.X_add_number > -0x8000
9697 && imm_expr.X_add_number <= 0x8000)
9699 imm_expr.X_add_number = -imm_expr.X_add_number;
9700 macro_build (&imm_expr, s, "t,r,j", dreg, sreg, BFD_RELOC_LO16);
9705 load_register (AT, &imm_expr, dbl);
9706 macro_build (NULL, s2, "d,v,t", dreg, sreg, AT);
9728 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
9729 macro_build (NULL, s, "s,t", sreg, AT);
9734 gas_assert (!mips_opts.micromips);
9735 gas_assert (mips_opts.isa == ISA_MIPS1);
9737 sreg = (ip->insn_opcode >> 11) & 0x1f; /* floating reg */
9738 dreg = (ip->insn_opcode >> 06) & 0x1f; /* floating reg */
9741 * Is the double cfc1 instruction a bug in the mips assembler;
9742 * or is there a reason for it?
9745 macro_build (NULL, "cfc1", "t,G", treg, RA);
9746 macro_build (NULL, "cfc1", "t,G", treg, RA);
9747 macro_build (NULL, "nop", "");
9748 expr1.X_add_number = 3;
9749 macro_build (&expr1, "ori", "t,r,i", AT, treg, BFD_RELOC_LO16);
9750 expr1.X_add_number = 2;
9751 macro_build (&expr1, "xori", "t,r,i", AT, AT, BFD_RELOC_LO16);
9752 macro_build (NULL, "ctc1", "t,G", AT, RA);
9753 macro_build (NULL, "nop", "");
9754 macro_build (NULL, mask == M_TRUNCWD ? "cvt.w.d" : "cvt.w.s", "D,S",
9756 macro_build (NULL, "ctc1", "t,G", treg, RA);
9757 macro_build (NULL, "nop", "");
9780 off12 = mips_opts.micromips;
9788 off12 = mips_opts.micromips;
9804 off12 = mips_opts.micromips;
9813 off12 = mips_opts.micromips;
9818 if (!ab && offset_expr.X_add_number >= 0x8000 - off)
9819 as_bad (_("Operand overflow"));
9822 expr1.X_add_number = 0;
9827 load_address (tempreg, ep, &used_at);
9829 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
9830 tempreg, tempreg, breg);
9836 && (offset_expr.X_op != O_constant
9837 || !IS_SEXT_12BIT_NUM (offset_expr.X_add_number)
9838 || !IS_SEXT_12BIT_NUM (offset_expr.X_add_number + off)))
9842 macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", tempreg, breg,
9843 -1, offset_reloc[0], offset_reloc[1], offset_reloc[2]);
9848 else if (!ust && treg == breg)
9859 if (!target_big_endian)
9860 ep->X_add_number += off;
9862 macro_build (ep, s, "t,o(b)", tempreg, BFD_RELOC_LO16, breg);
9864 macro_build (NULL, s, "t,~(b)",
9865 tempreg, (unsigned long) ep->X_add_number, breg);
9867 if (!target_big_endian)
9868 ep->X_add_number -= off;
9870 ep->X_add_number += off;
9872 macro_build (ep, s2, "t,o(b)", tempreg, BFD_RELOC_LO16, breg);
9874 macro_build (NULL, s2, "t,~(b)",
9875 tempreg, (unsigned long) ep->X_add_number, breg);
9877 /* If necessary, move the result in tempreg to the final destination. */
9878 if (!ust && treg != tempreg)
9880 /* Protect second load's delay slot. */
9882 move_register (treg, tempreg);
9888 if (target_big_endian == ust)
9889 ep->X_add_number += off;
9890 tempreg = ust || ab ? treg : AT;
9891 macro_build (ep, s, "t,o(b)", tempreg, BFD_RELOC_LO16, breg);
9893 /* For halfword transfers we need a temporary register to shuffle
9894 bytes. Unfortunately for M_USH_A we have none available before
9895 the next store as AT holds the base address. We deal with this
9896 case by clobbering TREG and then restoring it as with ULH. */
9897 tempreg = ust == ab ? treg : AT;
9899 macro_build (NULL, "srl", SHFT_FMT, tempreg, treg, 8);
9901 if (target_big_endian == ust)
9902 ep->X_add_number -= off;
9904 ep->X_add_number += off;
9905 macro_build (ep, s2, "t,o(b)", tempreg, BFD_RELOC_LO16, breg);
9907 /* For M_USH_A re-retrieve the LSB. */
9910 if (target_big_endian)
9911 ep->X_add_number += off;
9913 ep->X_add_number -= off;
9914 macro_build (&expr1, "lbu", "t,o(b)", AT, BFD_RELOC_LO16, AT);
9916 /* For ULH and M_USH_A OR the LSB in. */
9919 tempreg = !ab ? AT : treg;
9920 macro_build (NULL, "sll", SHFT_FMT, tempreg, tempreg, 8);
9921 macro_build (NULL, "or", "d,v,t", treg, treg, AT);
9926 /* FIXME: Check if this is one of the itbl macros, since they
9927 are added dynamically. */
9928 as_bad (_("Macro %s not implemented yet"), ip->insn_mo->name);
9931 if (!mips_opts.at && used_at)
9932 as_bad (_("Macro used $at after \".set noat\""));
9935 /* Implement macros in mips16 mode. */
9938 mips16_macro (struct mips_cl_insn *ip)
9941 int xreg, yreg, zreg, tmp;
9944 const char *s, *s2, *s3;
9946 mask = ip->insn_mo->mask;
9948 xreg = MIPS16_EXTRACT_OPERAND (RX, *ip);
9949 yreg = MIPS16_EXTRACT_OPERAND (RY, *ip);
9950 zreg = MIPS16_EXTRACT_OPERAND (RZ, *ip);
9952 expr1.X_op = O_constant;
9953 expr1.X_op_symbol = NULL;
9954 expr1.X_add_symbol = NULL;
9955 expr1.X_add_number = 1;
9975 macro_build (NULL, dbl ? "ddiv" : "div", "0,x,y", xreg, yreg);
9976 expr1.X_add_number = 2;
9977 macro_build (&expr1, "bnez", "x,p", yreg);
9978 macro_build (NULL, "break", "6", 7);
9980 /* FIXME: The normal code checks for of -1 / -0x80000000 here,
9981 since that causes an overflow. We should do that as well,
9982 but I don't see how to do the comparisons without a temporary
9985 macro_build (NULL, s, "x", zreg);
10004 start_noreorder ();
10005 macro_build (NULL, s, "0,x,y", xreg, yreg);
10006 expr1.X_add_number = 2;
10007 macro_build (&expr1, "bnez", "x,p", yreg);
10008 macro_build (NULL, "break", "6", 7);
10010 macro_build (NULL, s2, "x", zreg);
10016 macro_build (NULL, dbl ? "dmultu" : "multu", "x,y", xreg, yreg);
10017 macro_build (NULL, "mflo", "x", zreg);
10025 if (imm_expr.X_op != O_constant)
10026 as_bad (_("Unsupported large constant"));
10027 imm_expr.X_add_number = -imm_expr.X_add_number;
10028 macro_build (&imm_expr, dbl ? "daddiu" : "addiu", "y,x,4", yreg, xreg);
10032 if (imm_expr.X_op != O_constant)
10033 as_bad (_("Unsupported large constant"));
10034 imm_expr.X_add_number = -imm_expr.X_add_number;
10035 macro_build (&imm_expr, "addiu", "x,k", xreg);
10039 if (imm_expr.X_op != O_constant)
10040 as_bad (_("Unsupported large constant"));
10041 imm_expr.X_add_number = -imm_expr.X_add_number;
10042 macro_build (&imm_expr, "daddiu", "y,j", yreg);
10064 goto do_reverse_branch;
10068 goto do_reverse_branch;
10080 goto do_reverse_branch;
10091 macro_build (NULL, s, "x,y", xreg, yreg);
10092 macro_build (&offset_expr, s2, "p");
10119 goto do_addone_branch_i;
10124 goto do_addone_branch_i;
10139 goto do_addone_branch_i;
10145 do_addone_branch_i:
10146 if (imm_expr.X_op != O_constant)
10147 as_bad (_("Unsupported large constant"));
10148 ++imm_expr.X_add_number;
10151 macro_build (&imm_expr, s, s3, xreg);
10152 macro_build (&offset_expr, s2, "p");
10156 expr1.X_add_number = 0;
10157 macro_build (&expr1, "slti", "x,8", yreg);
10159 move_register (xreg, yreg);
10160 expr1.X_add_number = 2;
10161 macro_build (&expr1, "bteqz", "p");
10162 macro_build (NULL, "neg", "x,w", xreg, xreg);
10166 /* For consistency checking, verify that all bits are specified either
10167 by the match/mask part of the instruction definition, or by the
10170 validate_mips_insn (const struct mips_opcode *opc)
10172 const char *p = opc->args;
10174 unsigned long used_bits = opc->mask;
10176 if ((used_bits & opc->match) != opc->match)
10178 as_bad (_("internal: bad mips opcode (mask error): %s %s"),
10179 opc->name, opc->args);
10182 #define USE_BITS(mask,shift) (used_bits |= ((mask) << (shift)))
10192 case '1': USE_BITS (OP_MASK_UDI1, OP_SH_UDI1); break;
10193 case '2': USE_BITS (OP_MASK_UDI2, OP_SH_UDI2); break;
10194 case '3': USE_BITS (OP_MASK_UDI3, OP_SH_UDI3); break;
10195 case '4': USE_BITS (OP_MASK_UDI4, OP_SH_UDI4); break;
10196 case 'A': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
10197 case 'B': USE_BITS (OP_MASK_INSMSB, OP_SH_INSMSB); break;
10198 case 'C': USE_BITS (OP_MASK_EXTMSBD, OP_SH_EXTMSBD); break;
10199 case 'D': USE_BITS (OP_MASK_RD, OP_SH_RD);
10200 USE_BITS (OP_MASK_SEL, OP_SH_SEL); break;
10201 case 'E': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
10202 case 'F': USE_BITS (OP_MASK_INSMSB, OP_SH_INSMSB); break;
10203 case 'G': USE_BITS (OP_MASK_EXTMSBD, OP_SH_EXTMSBD); break;
10204 case 'H': USE_BITS (OP_MASK_EXTMSBD, OP_SH_EXTMSBD); break;
10206 case 't': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
10207 case 'T': USE_BITS (OP_MASK_RT, OP_SH_RT);
10208 USE_BITS (OP_MASK_SEL, OP_SH_SEL); break;
10209 case 'x': USE_BITS (OP_MASK_BBITIND, OP_SH_BBITIND); break;
10210 case 'X': USE_BITS (OP_MASK_BBITIND, OP_SH_BBITIND); break;
10211 case 'p': USE_BITS (OP_MASK_CINSPOS, OP_SH_CINSPOS); break;
10212 case 'P': USE_BITS (OP_MASK_CINSPOS, OP_SH_CINSPOS); break;
10213 case 'Q': USE_BITS (OP_MASK_SEQI, OP_SH_SEQI); break;
10214 case 's': USE_BITS (OP_MASK_CINSLM1, OP_SH_CINSLM1); break;
10215 case 'S': USE_BITS (OP_MASK_CINSLM1, OP_SH_CINSLM1); break;
10216 case 'z': USE_BITS (OP_MASK_RZ, OP_SH_RZ); break;
10217 case 'Z': USE_BITS (OP_MASK_FZ, OP_SH_FZ); break;
10218 case 'a': USE_BITS (OP_MASK_OFFSET_A, OP_SH_OFFSET_A); break;
10219 case 'b': USE_BITS (OP_MASK_OFFSET_B, OP_SH_OFFSET_B); break;
10220 case 'c': USE_BITS (OP_MASK_OFFSET_C, OP_SH_OFFSET_C); break;
10223 as_bad (_("internal: bad mips opcode (unknown extension operand type `+%c'): %s %s"),
10224 c, opc->name, opc->args);
10228 case '<': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
10229 case '>': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
10231 case 'B': USE_BITS (OP_MASK_CODE20, OP_SH_CODE20); break;
10232 case 'C': USE_BITS (OP_MASK_COPZ, OP_SH_COPZ); break;
10233 case 'D': USE_BITS (OP_MASK_FD, OP_SH_FD); break;
10234 case 'E': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
10236 case 'G': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
10237 case 'H': USE_BITS (OP_MASK_SEL, OP_SH_SEL); break;
10239 case 'J': USE_BITS (OP_MASK_CODE19, OP_SH_CODE19); break;
10240 case 'K': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
10242 case 'M': USE_BITS (OP_MASK_CCC, OP_SH_CCC); break;
10243 case 'N': USE_BITS (OP_MASK_BCC, OP_SH_BCC); break;
10244 case 'O': USE_BITS (OP_MASK_ALN, OP_SH_ALN); break;
10245 case 'Q': USE_BITS (OP_MASK_VSEL, OP_SH_VSEL);
10246 USE_BITS (OP_MASK_FT, OP_SH_FT); break;
10247 case 'R': USE_BITS (OP_MASK_FR, OP_SH_FR); break;
10248 case 'S': USE_BITS (OP_MASK_FS, OP_SH_FS); break;
10249 case 'T': USE_BITS (OP_MASK_FT, OP_SH_FT); break;
10250 case 'V': USE_BITS (OP_MASK_FS, OP_SH_FS); break;
10251 case 'W': USE_BITS (OP_MASK_FT, OP_SH_FT); break;
10252 case 'X': USE_BITS (OP_MASK_FD, OP_SH_FD); break;
10253 case 'Y': USE_BITS (OP_MASK_FS, OP_SH_FS); break;
10254 case 'Z': USE_BITS (OP_MASK_FT, OP_SH_FT); break;
10255 case 'a': USE_BITS (OP_MASK_TARGET, OP_SH_TARGET); break;
10256 case 'b': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
10257 case 'c': USE_BITS (OP_MASK_CODE, OP_SH_CODE); break;
10258 case 'd': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
10260 case 'h': USE_BITS (OP_MASK_PREFX, OP_SH_PREFX); break;
10261 case 'i': USE_BITS (OP_MASK_IMMEDIATE, OP_SH_IMMEDIATE); break;
10262 case 'j': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
10263 case 'k': USE_BITS (OP_MASK_CACHE, OP_SH_CACHE); break;
10265 case 'o': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
10266 case 'p': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
10267 case 'q': USE_BITS (OP_MASK_CODE2, OP_SH_CODE2); break;
10268 case 'r': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
10269 case 's': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
10270 case 't': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
10271 case 'u': USE_BITS (OP_MASK_IMMEDIATE, OP_SH_IMMEDIATE); break;
10272 case 'v': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
10273 case 'w': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
10276 case 'P': USE_BITS (OP_MASK_PERFREG, OP_SH_PERFREG); break;
10277 case 'U': USE_BITS (OP_MASK_RD, OP_SH_RD);
10278 USE_BITS (OP_MASK_RT, OP_SH_RT); break;
10279 case 'e': USE_BITS (OP_MASK_VECBYTE, OP_SH_VECBYTE); break;
10280 case '%': USE_BITS (OP_MASK_VECALIGN, OP_SH_VECALIGN); break;
10283 case '1': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
10284 case '2': USE_BITS (OP_MASK_BP, OP_SH_BP); break;
10285 case '3': USE_BITS (OP_MASK_SA3, OP_SH_SA3); break;
10286 case '4': USE_BITS (OP_MASK_SA4, OP_SH_SA4); break;
10287 case '5': USE_BITS (OP_MASK_IMM8, OP_SH_IMM8); break;
10288 case '6': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
10289 case '7': USE_BITS (OP_MASK_DSPACC, OP_SH_DSPACC); break;
10290 case '8': USE_BITS (OP_MASK_WRDSP, OP_SH_WRDSP); break;
10291 case '9': USE_BITS (OP_MASK_DSPACC_S, OP_SH_DSPACC_S);break;
10292 case '0': USE_BITS (OP_MASK_DSPSFT, OP_SH_DSPSFT); break;
10293 case '\'': USE_BITS (OP_MASK_RDDSP, OP_SH_RDDSP); break;
10294 case ':': USE_BITS (OP_MASK_DSPSFT_7, OP_SH_DSPSFT_7);break;
10295 case '@': USE_BITS (OP_MASK_IMM10, OP_SH_IMM10); break;
10296 case '!': USE_BITS (OP_MASK_MT_U, OP_SH_MT_U); break;
10297 case '$': USE_BITS (OP_MASK_MT_H, OP_SH_MT_H); break;
10298 case '*': USE_BITS (OP_MASK_MTACC_T, OP_SH_MTACC_T); break;
10299 case '&': USE_BITS (OP_MASK_MTACC_D, OP_SH_MTACC_D); break;
10300 case '\\': USE_BITS (OP_MASK_3BITPOS, OP_SH_3BITPOS); break;
10301 case '~': USE_BITS (OP_MASK_OFFSET12, OP_SH_OFFSET12); break;
10302 case 'g': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
10304 as_bad (_("internal: bad mips opcode (unknown operand type `%c'): %s %s"),
10305 c, opc->name, opc->args);
10309 if (used_bits != 0xffffffff)
10311 as_bad (_("internal: bad mips opcode (bits 0x%lx undefined): %s %s"),
10312 ~used_bits & 0xffffffff, opc->name, opc->args);
10318 /* For consistency checking, verify that the length implied matches the
10319 major opcode and that all bits are specified either by the match/mask
10320 part of the instruction definition, or by the operand list. */
10323 validate_micromips_insn (const struct mips_opcode *opc)
10325 unsigned long match = opc->match;
10326 unsigned long mask = opc->mask;
10327 const char *p = opc->args;
10328 unsigned long insn_bits;
10329 unsigned long used_bits;
10330 unsigned long major;
10331 unsigned int length;
10335 if ((mask & match) != match)
10337 as_bad (_("Internal error: bad microMIPS opcode (mask error): %s %s"),
10338 opc->name, opc->args);
10341 length = micromips_insn_length (opc);
10342 if (length != 2 && length != 4)
10344 as_bad (_("Internal error: bad microMIPS opcode (incorrect length: %u): "
10345 "%s %s"), length, opc->name, opc->args);
10348 major = match >> (10 + 8 * (length - 2));
10349 if ((length == 2 && (major & 7) != 1 && (major & 6) != 2)
10350 || (length == 4 && (major & 7) != 0 && (major & 4) != 4))
10352 as_bad (_("Internal error: bad microMIPS opcode "
10353 "(opcode/length mismatch): %s %s"), opc->name, opc->args);
10357 /* Shift piecewise to avoid an overflow where unsigned long is 32-bit. */
10358 insn_bits = 1 << 4 * length;
10359 insn_bits <<= 4 * length;
10362 #define USE_BITS(field) \
10363 (used_bits |= MICROMIPSOP_MASK_##field << MICROMIPSOP_SH_##field)
10374 case 'A': USE_BITS (EXTLSB); break;
10375 case 'B': USE_BITS (INSMSB); break;
10376 case 'C': USE_BITS (EXTMSBD); break;
10377 case 'D': USE_BITS (RS); USE_BITS (SEL); break;
10378 case 'E': USE_BITS (EXTLSB); break;
10379 case 'F': USE_BITS (INSMSB); break;
10380 case 'G': USE_BITS (EXTMSBD); break;
10381 case 'H': USE_BITS (EXTMSBD); break;
10383 as_bad (_("Internal error: bad mips opcode "
10384 "(unknown extension operand type `%c%c'): %s %s"),
10385 e, c, opc->name, opc->args);
10393 case 'A': USE_BITS (IMMA); break;
10394 case 'B': USE_BITS (IMMB); break;
10395 case 'C': USE_BITS (IMMC); break;
10396 case 'D': USE_BITS (IMMD); break;
10397 case 'E': USE_BITS (IMME); break;
10398 case 'F': USE_BITS (IMMF); break;
10399 case 'G': USE_BITS (IMMG); break;
10400 case 'H': USE_BITS (IMMH); break;
10401 case 'I': USE_BITS (IMMI); break;
10402 case 'J': USE_BITS (IMMJ); break;
10403 case 'L': USE_BITS (IMML); break;
10404 case 'M': USE_BITS (IMMM); break;
10405 case 'N': USE_BITS (IMMN); break;
10406 case 'O': USE_BITS (IMMO); break;
10407 case 'P': USE_BITS (IMMP); break;
10408 case 'Q': USE_BITS (IMMQ); break;
10409 case 'U': USE_BITS (IMMU); break;
10410 case 'W': USE_BITS (IMMW); break;
10411 case 'X': USE_BITS (IMMX); break;
10412 case 'Y': USE_BITS (IMMY); break;
10415 case 'b': USE_BITS (MB); break;
10416 case 'c': USE_BITS (MC); break;
10417 case 'd': USE_BITS (MD); break;
10418 case 'e': USE_BITS (ME); break;
10419 case 'f': USE_BITS (MF); break;
10420 case 'g': USE_BITS (MG); break;
10421 case 'h': USE_BITS (MH); break;
10422 case 'i': USE_BITS (MI); break;
10423 case 'j': USE_BITS (MJ); break;
10424 case 'l': USE_BITS (ML); break;
10425 case 'm': USE_BITS (MM); break;
10426 case 'n': USE_BITS (MN); break;
10427 case 'p': USE_BITS (MP); break;
10428 case 'q': USE_BITS (MQ); break;
10436 as_bad (_("Internal error: bad mips opcode "
10437 "(unknown extension operand type `%c%c'): %s %s"),
10438 e, c, opc->name, opc->args);
10442 case '.': USE_BITS (OFFSET10); break;
10443 case '1': USE_BITS (STYPE); break;
10444 case '<': USE_BITS (SHAMT); break;
10445 case '>': USE_BITS (SHAMT); break;
10446 case 'B': USE_BITS (CODE10); break;
10447 case 'C': USE_BITS (COPZ); break;
10448 case 'D': USE_BITS (FD); break;
10449 case 'E': USE_BITS (RT); break;
10450 case 'G': USE_BITS (RS); break;
10451 case 'H': USE_BITS (SEL); break;
10452 case 'K': USE_BITS (RS); break;
10453 case 'M': USE_BITS (CCC); break;
10454 case 'N': USE_BITS (BCC); break;
10455 case 'R': USE_BITS (FR); break;
10456 case 'S': USE_BITS (FS); break;
10457 case 'T': USE_BITS (FT); break;
10458 case 'V': USE_BITS (FS); break;
10459 case '\\': USE_BITS (3BITPOS); break;
10460 case 'a': USE_BITS (TARGET); break;
10461 case 'b': USE_BITS (RS); break;
10462 case 'c': USE_BITS (CODE); break;
10463 case 'd': USE_BITS (RD); break;
10464 case 'h': USE_BITS (PREFX); break;
10465 case 'i': USE_BITS (IMMEDIATE); break;
10466 case 'j': USE_BITS (DELTA); break;
10467 case 'k': USE_BITS (CACHE); break;
10468 case 'n': USE_BITS (RT); break;
10469 case 'o': USE_BITS (DELTA); break;
10470 case 'p': USE_BITS (DELTA); break;
10471 case 'q': USE_BITS (CODE2); break;
10472 case 'r': USE_BITS (RS); break;
10473 case 's': USE_BITS (RS); break;
10474 case 't': USE_BITS (RT); break;
10475 case 'u': USE_BITS (IMMEDIATE); break;
10476 case 'v': USE_BITS (RS); break;
10477 case 'w': USE_BITS (RT); break;
10478 case 'y': USE_BITS (RS3); break;
10480 case '|': USE_BITS (TRAP); break;
10481 case '~': USE_BITS (OFFSET12); break;
10483 as_bad (_("Internal error: bad microMIPS opcode "
10484 "(unknown operand type `%c'): %s %s"),
10485 c, opc->name, opc->args);
10489 if (used_bits != insn_bits)
10491 if (~used_bits & insn_bits)
10492 as_bad (_("Internal error: bad microMIPS opcode "
10493 "(bits 0x%lx undefined): %s %s"),
10494 ~used_bits & insn_bits, opc->name, opc->args);
10495 if (used_bits & ~insn_bits)
10496 as_bad (_("Internal error: bad microMIPS opcode "
10497 "(bits 0x%lx defined): %s %s"),
10498 used_bits & ~insn_bits, opc->name, opc->args);
10504 /* UDI immediates. */
10505 struct mips_immed {
10507 unsigned int shift;
10508 unsigned long mask;
10512 static const struct mips_immed mips_immed[] = {
10513 { '1', OP_SH_UDI1, OP_MASK_UDI1, 0},
10514 { '2', OP_SH_UDI2, OP_MASK_UDI2, 0},
10515 { '3', OP_SH_UDI3, OP_MASK_UDI3, 0},
10516 { '4', OP_SH_UDI4, OP_MASK_UDI4, 0},
10520 /* Check whether an odd floating-point register is allowed. */
10522 mips_oddfpreg_ok (const struct mips_opcode *insn, int argnum)
10524 const char *s = insn->name;
10526 if (insn->pinfo == INSN_MACRO)
10527 /* Let a macro pass, we'll catch it later when it is expanded. */
10530 if (ISA_HAS_ODD_SINGLE_FPR (mips_opts.isa))
10532 /* Allow odd registers for single-precision ops. */
10533 switch (insn->pinfo & (FP_S | FP_D))
10537 return 1; /* both single precision - ok */
10539 return 0; /* both double precision - fail */
10544 /* Cvt.w.x and cvt.x.w allow an odd register for a 'w' or 's' operand. */
10545 s = strchr (insn->name, '.');
10547 s = s != NULL ? strchr (s + 1, '.') : NULL;
10548 return (s != NULL && (s[1] == 'w' || s[1] == 's'));
10551 /* Single-precision coprocessor loads and moves are OK too. */
10552 if ((insn->pinfo & FP_S)
10553 && (insn->pinfo & (INSN_COPROC_MEMORY_DELAY | INSN_STORE_MEMORY
10554 | INSN_LOAD_COPROC_DELAY | INSN_COPROC_MOVE_DELAY)))
10560 /* Check if EXPR is a constant between MIN (inclusive) and MAX (exclusive)
10561 taking bits from BIT up. */
10563 expr_const_in_range (expressionS *ep, offsetT min, offsetT max, int bit)
10565 return (ep->X_op == O_constant
10566 && (ep->X_add_number & ((1 << bit) - 1)) == 0
10567 && ep->X_add_number >= min << bit
10568 && ep->X_add_number < max << bit);
10571 /* This routine assembles an instruction into its binary format. As a
10572 side effect, it sets one of the global variables imm_reloc or
10573 offset_reloc to the type of relocation to do if one of the operands
10574 is an address expression. */
10577 mips_ip (char *str, struct mips_cl_insn *ip)
10579 bfd_boolean wrong_delay_slot_insns = FALSE;
10580 bfd_boolean need_delay_slot_ok = TRUE;
10581 struct mips_opcode *firstinsn = NULL;
10582 const struct mips_opcode *past;
10583 struct hash_control *hash;
10587 struct mips_opcode *insn;
10589 unsigned int regno;
10590 unsigned int lastregno;
10591 unsigned int destregno = 0;
10592 unsigned int lastpos = 0;
10593 unsigned int limlo, limhi;
10595 offsetT min_range, max_range;
10599 unsigned int rtype;
10605 if (mips_opts.micromips)
10607 hash = micromips_op_hash;
10608 past = µmips_opcodes[bfd_micromips_num_opcodes];
10613 past = &mips_opcodes[NUMOPCODES];
10615 forced_insn_length = 0;
10618 /* We first try to match an instruction up to a space or to the end. */
10619 for (end = 0; str[end] != '\0' && !ISSPACE (str[end]); end++)
10622 /* Make a copy of the instruction so that we can fiddle with it. */
10623 name = alloca (end + 1);
10624 memcpy (name, str, end);
10629 insn = (struct mips_opcode *) hash_find (hash, name);
10631 if (insn != NULL || !mips_opts.micromips)
10633 if (forced_insn_length)
10636 /* See if there's an instruction size override suffix,
10637 either `16' or `32', at the end of the mnemonic proper,
10638 that defines the operation, i.e. before the first `.'
10639 character if any. Strip it and retry. */
10640 dot = strchr (name, '.');
10641 opend = dot != NULL ? dot - name : end;
10644 if (name[opend - 2] == '1' && name[opend - 1] == '6')
10645 forced_insn_length = 2;
10646 else if (name[opend - 2] == '3' && name[opend - 1] == '2')
10647 forced_insn_length = 4;
10650 memcpy (name + opend - 2, name + opend, end - opend + 1);
10654 insn_error = _("Unrecognized opcode");
10658 /* For microMIPS instructions placed in a fixed-length branch delay slot
10659 we make up to two passes over the relevant fragment of the opcode
10660 table. First we try instructions that meet the delay slot's length
10661 requirement. If none matched, then we retry with the remaining ones
10662 and if one matches, then we use it and then issue an appropriate
10663 warning later on. */
10664 argsStart = s = str + end;
10667 bfd_boolean delay_slot_ok;
10668 bfd_boolean size_ok;
10671 gas_assert (strcmp (insn->name, name) == 0);
10673 ok = is_opcode_valid (insn);
10674 size_ok = is_size_valid (insn);
10675 delay_slot_ok = is_delay_slot_valid (insn);
10676 if (!delay_slot_ok && !wrong_delay_slot_insns)
10679 wrong_delay_slot_insns = TRUE;
10681 if (!ok || !size_ok || delay_slot_ok != need_delay_slot_ok)
10683 static char buf[256];
10685 if (insn + 1 < past && strcmp (insn->name, insn[1].name) == 0)
10690 if (wrong_delay_slot_insns && need_delay_slot_ok)
10692 gas_assert (firstinsn);
10693 need_delay_slot_ok = FALSE;
10703 sprintf (buf, _("opcode not supported on this processor: %s (%s)"),
10704 mips_cpu_info_from_arch (mips_opts.arch)->name,
10705 mips_cpu_info_from_isa (mips_opts.isa)->name);
10707 sprintf (buf, _("Unrecognized %u-bit version of microMIPS opcode"),
10708 8 * forced_insn_length);
10714 create_insn (ip, insn);
10717 lastregno = 0xffffffff;
10718 for (args = insn->args;; ++args)
10722 s += strspn (s, " \t");
10726 case '\0': /* end of args */
10731 case '2': /* DSP 2-bit unsigned immediate in bit 11. */
10732 gas_assert (!mips_opts.micromips);
10733 my_getExpression (&imm_expr, s);
10734 check_absolute_expr (ip, &imm_expr);
10735 if ((unsigned long) imm_expr.X_add_number != 1
10736 && (unsigned long) imm_expr.X_add_number != 3)
10738 as_bad (_("BALIGN immediate not 1 or 3 (%lu)"),
10739 (unsigned long) imm_expr.X_add_number);
10741 INSERT_OPERAND (0, BP, *ip, imm_expr.X_add_number);
10742 imm_expr.X_op = O_absent;
10746 case '3': /* DSP 3-bit unsigned immediate in bit 21. */
10747 gas_assert (!mips_opts.micromips);
10748 my_getExpression (&imm_expr, s);
10749 check_absolute_expr (ip, &imm_expr);
10750 if (imm_expr.X_add_number & ~OP_MASK_SA3)
10752 as_bad (_("DSP immediate not in range 0..%d (%lu)"),
10753 OP_MASK_SA3, (unsigned long) imm_expr.X_add_number);
10755 INSERT_OPERAND (0, SA3, *ip, imm_expr.X_add_number);
10756 imm_expr.X_op = O_absent;
10760 case '4': /* DSP 4-bit unsigned immediate in bit 21. */
10761 gas_assert (!mips_opts.micromips);
10762 my_getExpression (&imm_expr, s);
10763 check_absolute_expr (ip, &imm_expr);
10764 if (imm_expr.X_add_number & ~OP_MASK_SA4)
10766 as_bad (_("DSP immediate not in range 0..%d (%lu)"),
10767 OP_MASK_SA4, (unsigned long) imm_expr.X_add_number);
10769 INSERT_OPERAND (0, SA4, *ip, imm_expr.X_add_number);
10770 imm_expr.X_op = O_absent;
10774 case '5': /* DSP 8-bit unsigned immediate in bit 16. */
10775 gas_assert (!mips_opts.micromips);
10776 my_getExpression (&imm_expr, s);
10777 check_absolute_expr (ip, &imm_expr);
10778 if (imm_expr.X_add_number & ~OP_MASK_IMM8)
10780 as_bad (_("DSP immediate not in range 0..%d (%lu)"),
10781 OP_MASK_IMM8, (unsigned long) imm_expr.X_add_number);
10783 INSERT_OPERAND (0, IMM8, *ip, imm_expr.X_add_number);
10784 imm_expr.X_op = O_absent;
10788 case '6': /* DSP 5-bit unsigned immediate in bit 21. */
10789 gas_assert (!mips_opts.micromips);
10790 my_getExpression (&imm_expr, s);
10791 check_absolute_expr (ip, &imm_expr);
10792 if (imm_expr.X_add_number & ~OP_MASK_RS)
10794 as_bad (_("DSP immediate not in range 0..%d (%lu)"),
10795 OP_MASK_RS, (unsigned long) imm_expr.X_add_number);
10797 INSERT_OPERAND (0, RS, *ip, imm_expr.X_add_number);
10798 imm_expr.X_op = O_absent;
10802 case '7': /* Four DSP accumulators in bits 11,12. */
10803 gas_assert (!mips_opts.micromips);
10804 if (s[0] == '$' && s[1] == 'a' && s[2] == 'c' &&
10805 s[3] >= '0' && s[3] <= '3')
10807 regno = s[3] - '0';
10809 INSERT_OPERAND (0, DSPACC, *ip, regno);
10813 as_bad (_("Invalid dsp acc register"));
10816 case '8': /* DSP 6-bit unsigned immediate in bit 11. */
10817 gas_assert (!mips_opts.micromips);
10818 my_getExpression (&imm_expr, s);
10819 check_absolute_expr (ip, &imm_expr);
10820 if (imm_expr.X_add_number & ~OP_MASK_WRDSP)
10822 as_bad (_("DSP immediate not in range 0..%d (%lu)"),
10824 (unsigned long) imm_expr.X_add_number);
10826 INSERT_OPERAND (0, WRDSP, *ip, imm_expr.X_add_number);
10827 imm_expr.X_op = O_absent;
10831 case '9': /* Four DSP accumulators in bits 21,22. */
10832 gas_assert (!mips_opts.micromips);
10833 if (s[0] == '$' && s[1] == 'a' && s[2] == 'c' &&
10834 s[3] >= '0' && s[3] <= '3')
10836 regno = s[3] - '0';
10838 INSERT_OPERAND (0, DSPACC_S, *ip, regno);
10842 as_bad (_("Invalid dsp acc register"));
10845 case '0': /* DSP 6-bit signed immediate in bit 20. */
10846 gas_assert (!mips_opts.micromips);
10847 my_getExpression (&imm_expr, s);
10848 check_absolute_expr (ip, &imm_expr);
10849 min_range = -((OP_MASK_DSPSFT + 1) >> 1);
10850 max_range = ((OP_MASK_DSPSFT + 1) >> 1) - 1;
10851 if (imm_expr.X_add_number < min_range ||
10852 imm_expr.X_add_number > max_range)
10854 as_bad (_("DSP immediate not in range %ld..%ld (%ld)"),
10855 (long) min_range, (long) max_range,
10856 (long) imm_expr.X_add_number);
10858 INSERT_OPERAND (0, DSPSFT, *ip, imm_expr.X_add_number);
10859 imm_expr.X_op = O_absent;
10863 case '\'': /* DSP 6-bit unsigned immediate in bit 16. */
10864 gas_assert (!mips_opts.micromips);
10865 my_getExpression (&imm_expr, s);
10866 check_absolute_expr (ip, &imm_expr);
10867 if (imm_expr.X_add_number & ~OP_MASK_RDDSP)
10869 as_bad (_("DSP immediate not in range 0..%d (%lu)"),
10871 (unsigned long) imm_expr.X_add_number);
10873 INSERT_OPERAND (0, RDDSP, *ip, imm_expr.X_add_number);
10874 imm_expr.X_op = O_absent;
10878 case ':': /* DSP 7-bit signed immediate in bit 19. */
10879 gas_assert (!mips_opts.micromips);
10880 my_getExpression (&imm_expr, s);
10881 check_absolute_expr (ip, &imm_expr);
10882 min_range = -((OP_MASK_DSPSFT_7 + 1) >> 1);
10883 max_range = ((OP_MASK_DSPSFT_7 + 1) >> 1) - 1;
10884 if (imm_expr.X_add_number < min_range ||
10885 imm_expr.X_add_number > max_range)
10887 as_bad (_("DSP immediate not in range %ld..%ld (%ld)"),
10888 (long) min_range, (long) max_range,
10889 (long) imm_expr.X_add_number);
10891 INSERT_OPERAND (0, DSPSFT_7, *ip, imm_expr.X_add_number);
10892 imm_expr.X_op = O_absent;
10896 case '@': /* DSP 10-bit signed immediate in bit 16. */
10897 gas_assert (!mips_opts.micromips);
10898 my_getExpression (&imm_expr, s);
10899 check_absolute_expr (ip, &imm_expr);
10900 min_range = -((OP_MASK_IMM10 + 1) >> 1);
10901 max_range = ((OP_MASK_IMM10 + 1) >> 1) - 1;
10902 if (imm_expr.X_add_number < min_range ||
10903 imm_expr.X_add_number > max_range)
10905 as_bad (_("DSP immediate not in range %ld..%ld (%ld)"),
10906 (long) min_range, (long) max_range,
10907 (long) imm_expr.X_add_number);
10909 INSERT_OPERAND (0, IMM10, *ip, imm_expr.X_add_number);
10910 imm_expr.X_op = O_absent;
10914 case '!': /* MT usermode flag bit. */
10915 gas_assert (!mips_opts.micromips);
10916 my_getExpression (&imm_expr, s);
10917 check_absolute_expr (ip, &imm_expr);
10918 if (imm_expr.X_add_number & ~OP_MASK_MT_U)
10919 as_bad (_("MT usermode bit not 0 or 1 (%lu)"),
10920 (unsigned long) imm_expr.X_add_number);
10921 INSERT_OPERAND (0, MT_U, *ip, imm_expr.X_add_number);
10922 imm_expr.X_op = O_absent;
10926 case '$': /* MT load high flag bit. */
10927 gas_assert (!mips_opts.micromips);
10928 my_getExpression (&imm_expr, s);
10929 check_absolute_expr (ip, &imm_expr);
10930 if (imm_expr.X_add_number & ~OP_MASK_MT_H)
10931 as_bad (_("MT load high bit not 0 or 1 (%lu)"),
10932 (unsigned long) imm_expr.X_add_number);
10933 INSERT_OPERAND (0, MT_H, *ip, imm_expr.X_add_number);
10934 imm_expr.X_op = O_absent;
10938 case '*': /* Four DSP accumulators in bits 18,19. */
10939 gas_assert (!mips_opts.micromips);
10940 if (s[0] == '$' && s[1] == 'a' && s[2] == 'c' &&
10941 s[3] >= '0' && s[3] <= '3')
10943 regno = s[3] - '0';
10945 INSERT_OPERAND (0, MTACC_T, *ip, regno);
10949 as_bad (_("Invalid dsp/smartmips acc register"));
10952 case '&': /* Four DSP accumulators in bits 13,14. */
10953 gas_assert (!mips_opts.micromips);
10954 if (s[0] == '$' && s[1] == 'a' && s[2] == 'c' &&
10955 s[3] >= '0' && s[3] <= '3')
10957 regno = s[3] - '0';
10959 INSERT_OPERAND (0, MTACC_D, *ip, regno);
10963 as_bad (_("Invalid dsp/smartmips acc register"));
10966 case '\\': /* 3-bit bit position. */
10968 unsigned long mask = (mips_opts.micromips
10969 ? MICROMIPSOP_MASK_3BITPOS
10970 : OP_MASK_3BITPOS);
10972 my_getExpression (&imm_expr, s);
10973 check_absolute_expr (ip, &imm_expr);
10974 if ((unsigned long) imm_expr.X_add_number > mask)
10975 as_warn (_("Bit position for %s not in range 0..%lu (%lu)"),
10977 mask, (unsigned long) imm_expr.X_add_number);
10978 INSERT_OPERAND (mips_opts.micromips,
10979 3BITPOS, *ip, imm_expr.X_add_number);
10980 imm_expr.X_op = O_absent;
10994 INSERT_OPERAND (mips_opts.micromips, RS, *ip, lastregno);
10998 INSERT_OPERAND (mips_opts.micromips, RT, *ip, lastregno);
11002 gas_assert (!mips_opts.micromips);
11003 INSERT_OPERAND (0, FT, *ip, lastregno);
11007 INSERT_OPERAND (mips_opts.micromips, FS, *ip, lastregno);
11013 /* Handle optional base register.
11014 Either the base register is omitted or
11015 we must have a left paren. */
11016 /* This is dependent on the next operand specifier
11017 is a base register specification. */
11018 gas_assert (args[1] == 'b'
11019 || (mips_opts.micromips
11021 && (args[2] == 'l' || args[2] == 'n'
11022 || args[2] == 's' || args[2] == 'a')));
11023 if (*s == '\0' && args[1] == 'b')
11025 /* Fall through. */
11027 case ')': /* These must match exactly. */
11032 case '[': /* These must match exactly. */
11034 gas_assert (!mips_opts.micromips);
11039 case '+': /* Opcode extension character. */
11042 case '1': /* UDI immediates. */
11046 gas_assert (!mips_opts.micromips);
11048 const struct mips_immed *imm = mips_immed;
11050 while (imm->type && imm->type != *args)
11054 my_getExpression (&imm_expr, s);
11055 check_absolute_expr (ip, &imm_expr);
11056 if ((unsigned long) imm_expr.X_add_number & ~imm->mask)
11058 as_warn (_("Illegal %s number (%lu, 0x%lx)"),
11059 imm->desc ? imm->desc : ip->insn_mo->name,
11060 (unsigned long) imm_expr.X_add_number,
11061 (unsigned long) imm_expr.X_add_number);
11062 imm_expr.X_add_number &= imm->mask;
11064 ip->insn_opcode |= ((unsigned long) imm_expr.X_add_number
11066 imm_expr.X_op = O_absent;
11071 case 'A': /* ins/ext position, becomes LSB. */
11080 my_getExpression (&imm_expr, s);
11081 check_absolute_expr (ip, &imm_expr);
11082 if ((unsigned long) imm_expr.X_add_number < limlo
11083 || (unsigned long) imm_expr.X_add_number > limhi)
11085 as_bad (_("Improper position (%lu)"),
11086 (unsigned long) imm_expr.X_add_number);
11087 imm_expr.X_add_number = limlo;
11089 lastpos = imm_expr.X_add_number;
11090 INSERT_OPERAND (mips_opts.micromips,
11091 EXTLSB, *ip, imm_expr.X_add_number);
11092 imm_expr.X_op = O_absent;
11096 case 'B': /* ins size, becomes MSB. */
11105 my_getExpression (&imm_expr, s);
11106 check_absolute_expr (ip, &imm_expr);
11107 /* Check for negative input so that small negative numbers
11108 will not succeed incorrectly. The checks against
11109 (pos+size) transitively check "size" itself,
11110 assuming that "pos" is reasonable. */
11111 if ((long) imm_expr.X_add_number < 0
11112 || ((unsigned long) imm_expr.X_add_number
11114 || ((unsigned long) imm_expr.X_add_number
11115 + lastpos) > limhi)
11117 as_bad (_("Improper insert size (%lu, position %lu)"),
11118 (unsigned long) imm_expr.X_add_number,
11119 (unsigned long) lastpos);
11120 imm_expr.X_add_number = limlo - lastpos;
11122 INSERT_OPERAND (mips_opts.micromips, INSMSB, *ip,
11123 lastpos + imm_expr.X_add_number - 1);
11124 imm_expr.X_op = O_absent;
11128 case 'C': /* ext size, becomes MSBD. */
11141 my_getExpression (&imm_expr, s);
11142 check_absolute_expr (ip, &imm_expr);
11143 /* Check for negative input so that small negative numbers
11144 will not succeed incorrectly. The checks against
11145 (pos+size) transitively check "size" itself,
11146 assuming that "pos" is reasonable. */
11147 if ((long) imm_expr.X_add_number < 0
11148 || ((unsigned long) imm_expr.X_add_number
11150 || ((unsigned long) imm_expr.X_add_number
11151 + lastpos) > limhi)
11153 as_bad (_("Improper extract size (%lu, position %lu)"),
11154 (unsigned long) imm_expr.X_add_number,
11155 (unsigned long) lastpos);
11156 imm_expr.X_add_number = limlo - lastpos;
11158 INSERT_OPERAND (mips_opts.micromips,
11159 EXTMSBD, *ip, imm_expr.X_add_number - 1);
11160 imm_expr.X_op = O_absent;
11165 /* +D is for disassembly only; never match. */
11169 /* "+I" is like "I", except that imm2_expr is used. */
11170 my_getExpression (&imm2_expr, s);
11171 if (imm2_expr.X_op != O_big
11172 && imm2_expr.X_op != O_constant)
11173 insn_error = _("absolute expression required");
11174 if (HAVE_32BIT_GPRS)
11175 normalize_constant_expr (&imm2_expr);
11179 case 'T': /* Coprocessor register. */
11180 gas_assert (!mips_opts.micromips);
11181 /* +T is for disassembly only; never match. */
11184 case 't': /* Coprocessor register number. */
11185 gas_assert (!mips_opts.micromips);
11186 if (s[0] == '$' && ISDIGIT (s[1]))
11196 while (ISDIGIT (*s));
11198 as_bad (_("Invalid register number (%d)"), regno);
11201 INSERT_OPERAND (0, RT, *ip, regno);
11206 as_bad (_("Invalid coprocessor 0 register number"));
11210 /* bbit[01] and bbit[01]32 bit index. Give error if index
11211 is not in the valid range. */
11212 gas_assert (!mips_opts.micromips);
11213 my_getExpression (&imm_expr, s);
11214 check_absolute_expr (ip, &imm_expr);
11215 if ((unsigned) imm_expr.X_add_number > 31)
11217 as_bad (_("Improper bit index (%lu)"),
11218 (unsigned long) imm_expr.X_add_number);
11219 imm_expr.X_add_number = 0;
11221 INSERT_OPERAND (0, BBITIND, *ip, imm_expr.X_add_number);
11222 imm_expr.X_op = O_absent;
11227 /* bbit[01] bit index when bbit is used but we generate
11228 bbit[01]32 because the index is over 32. Move to the
11229 next candidate if index is not in the valid range. */
11230 gas_assert (!mips_opts.micromips);
11231 my_getExpression (&imm_expr, s);
11232 check_absolute_expr (ip, &imm_expr);
11233 if ((unsigned) imm_expr.X_add_number < 32
11234 || (unsigned) imm_expr.X_add_number > 63)
11236 INSERT_OPERAND (0, BBITIND, *ip, imm_expr.X_add_number - 32);
11237 imm_expr.X_op = O_absent;
11242 /* cins, cins32, exts and exts32 position field. Give error
11243 if it's not in the valid range. */
11244 gas_assert (!mips_opts.micromips);
11245 my_getExpression (&imm_expr, s);
11246 check_absolute_expr (ip, &imm_expr);
11247 if ((unsigned) imm_expr.X_add_number > 31)
11249 as_bad (_("Improper position (%lu)"),
11250 (unsigned long) imm_expr.X_add_number);
11251 imm_expr.X_add_number = 0;
11253 /* Make the pos explicit to simplify +S. */
11254 lastpos = imm_expr.X_add_number + 32;
11255 INSERT_OPERAND (0, CINSPOS, *ip, imm_expr.X_add_number);
11256 imm_expr.X_op = O_absent;
11261 /* cins, cins32, exts and exts32 position field. Move to
11262 the next candidate if it's not in the valid range. */
11263 gas_assert (!mips_opts.micromips);
11264 my_getExpression (&imm_expr, s);
11265 check_absolute_expr (ip, &imm_expr);
11266 if ((unsigned) imm_expr.X_add_number < 32
11267 || (unsigned) imm_expr.X_add_number > 63)
11269 lastpos = imm_expr.X_add_number;
11270 INSERT_OPERAND (0, CINSPOS, *ip, imm_expr.X_add_number - 32);
11271 imm_expr.X_op = O_absent;
11276 /* cins and exts length-minus-one field. */
11277 gas_assert (!mips_opts.micromips);
11278 my_getExpression (&imm_expr, s);
11279 check_absolute_expr (ip, &imm_expr);
11280 if ((unsigned long) imm_expr.X_add_number > 31)
11282 as_bad (_("Improper size (%lu)"),
11283 (unsigned long) imm_expr.X_add_number);
11284 imm_expr.X_add_number = 0;
11286 INSERT_OPERAND (0, CINSLM1, *ip, imm_expr.X_add_number);
11287 imm_expr.X_op = O_absent;
11292 /* cins32/exts32 and cins/exts aliasing cint32/exts32
11293 length-minus-one field. */
11294 gas_assert (!mips_opts.micromips);
11295 my_getExpression (&imm_expr, s);
11296 check_absolute_expr (ip, &imm_expr);
11297 if ((long) imm_expr.X_add_number < 0
11298 || (unsigned long) imm_expr.X_add_number + lastpos > 63)
11300 as_bad (_("Improper size (%lu)"),
11301 (unsigned long) imm_expr.X_add_number);
11302 imm_expr.X_add_number = 0;
11304 INSERT_OPERAND (0, CINSLM1, *ip, imm_expr.X_add_number);
11305 imm_expr.X_op = O_absent;
11310 /* seqi/snei immediate field. */
11311 gas_assert (!mips_opts.micromips);
11312 my_getExpression (&imm_expr, s);
11313 check_absolute_expr (ip, &imm_expr);
11314 if ((long) imm_expr.X_add_number < -512
11315 || (long) imm_expr.X_add_number >= 512)
11317 as_bad (_("Improper immediate (%ld)"),
11318 (long) imm_expr.X_add_number);
11319 imm_expr.X_add_number = 0;
11321 INSERT_OPERAND (0, SEQI, *ip, imm_expr.X_add_number);
11322 imm_expr.X_op = O_absent;
11326 case 'a': /* 8-bit signed offset in bit 6 */
11327 gas_assert (!mips_opts.micromips);
11328 my_getExpression (&imm_expr, s);
11329 check_absolute_expr (ip, &imm_expr);
11330 min_range = -((OP_MASK_OFFSET_A + 1) >> 1);
11331 max_range = ((OP_MASK_OFFSET_A + 1) >> 1) - 1;
11332 if (imm_expr.X_add_number < min_range
11333 || imm_expr.X_add_number > max_range)
11335 as_bad (_("Offset not in range %ld..%ld (%ld)"),
11336 (long) min_range, (long) max_range,
11337 (long) imm_expr.X_add_number);
11339 INSERT_OPERAND (0, OFFSET_A, *ip, imm_expr.X_add_number);
11340 imm_expr.X_op = O_absent;
11344 case 'b': /* 8-bit signed offset in bit 3 */
11345 gas_assert (!mips_opts.micromips);
11346 my_getExpression (&imm_expr, s);
11347 check_absolute_expr (ip, &imm_expr);
11348 min_range = -((OP_MASK_OFFSET_B + 1) >> 1);
11349 max_range = ((OP_MASK_OFFSET_B + 1) >> 1) - 1;
11350 if (imm_expr.X_add_number < min_range
11351 || imm_expr.X_add_number > max_range)
11353 as_bad (_("Offset not in range %ld..%ld (%ld)"),
11354 (long) min_range, (long) max_range,
11355 (long) imm_expr.X_add_number);
11357 INSERT_OPERAND (0, OFFSET_B, *ip, imm_expr.X_add_number);
11358 imm_expr.X_op = O_absent;
11362 case 'c': /* 9-bit signed offset in bit 6 */
11363 gas_assert (!mips_opts.micromips);
11364 my_getExpression (&imm_expr, s);
11365 check_absolute_expr (ip, &imm_expr);
11366 min_range = -((OP_MASK_OFFSET_C + 1) >> 1);
11367 max_range = ((OP_MASK_OFFSET_C + 1) >> 1) - 1;
11368 /* We check the offset range before adjusted. */
11371 if (imm_expr.X_add_number < min_range
11372 || imm_expr.X_add_number > max_range)
11374 as_bad (_("Offset not in range %ld..%ld (%ld)"),
11375 (long) min_range, (long) max_range,
11376 (long) imm_expr.X_add_number);
11378 if (imm_expr.X_add_number & 0xf)
11380 as_bad (_("Offset not 16 bytes alignment (%ld)"),
11381 (long) imm_expr.X_add_number);
11383 /* Right shift 4 bits to adjust the offset operand. */
11384 INSERT_OPERAND (0, OFFSET_C, *ip,
11385 imm_expr.X_add_number >> 4);
11386 imm_expr.X_op = O_absent;
11391 gas_assert (!mips_opts.micromips);
11392 if (!reg_lookup (&s, RTYPE_NUM | RTYPE_GP, ®no))
11394 if (regno == AT && mips_opts.at)
11396 if (mips_opts.at == ATREG)
11397 as_warn (_("used $at without \".set noat\""));
11399 as_warn (_("used $%u with \".set at=$%u\""),
11400 regno, mips_opts.at);
11402 INSERT_OPERAND (0, RZ, *ip, regno);
11406 gas_assert (!mips_opts.micromips);
11407 if (!reg_lookup (&s, RTYPE_FPU, ®no))
11409 INSERT_OPERAND (0, FZ, *ip, regno);
11413 as_bad (_("Internal error: bad %s opcode "
11414 "(unknown extension operand type `+%c'): %s %s"),
11415 mips_opts.micromips ? "microMIPS" : "MIPS",
11416 *args, insn->name, insn->args);
11417 /* Further processing is fruitless. */
11422 case '.': /* 10-bit offset. */
11423 gas_assert (mips_opts.micromips);
11424 case '~': /* 12-bit offset. */
11426 int shift = *args == '.' ? 9 : 11;
11429 /* Check whether there is only a single bracketed expression
11430 left. If so, it must be the base register and the
11431 constant must be zero. */
11432 if (*s == '(' && strchr (s + 1, '(') == 0)
11435 /* If this value won't fit into the offset, then go find
11436 a macro that will generate a 16- or 32-bit offset code
11438 i = my_getSmallExpression (&imm_expr, imm_reloc, s);
11439 if ((i == 0 && (imm_expr.X_op != O_constant
11440 || imm_expr.X_add_number >= 1 << shift
11441 || imm_expr.X_add_number < -1 << shift))
11444 imm_expr.X_op = O_absent;
11448 INSERT_OPERAND (1, OFFSET10, *ip, imm_expr.X_add_number);
11450 INSERT_OPERAND (mips_opts.micromips,
11451 OFFSET12, *ip, imm_expr.X_add_number);
11452 imm_expr.X_op = O_absent;
11457 case '<': /* must be at least one digit */
11459 * According to the manual, if the shift amount is greater
11460 * than 31 or less than 0, then the shift amount should be
11461 * mod 32. In reality the mips assembler issues an error.
11462 * We issue a warning and mask out all but the low 5 bits.
11464 my_getExpression (&imm_expr, s);
11465 check_absolute_expr (ip, &imm_expr);
11466 if ((unsigned long) imm_expr.X_add_number > 31)
11467 as_warn (_("Improper shift amount (%lu)"),
11468 (unsigned long) imm_expr.X_add_number);
11469 INSERT_OPERAND (mips_opts.micromips,
11470 SHAMT, *ip, imm_expr.X_add_number);
11471 imm_expr.X_op = O_absent;
11475 case '>': /* shift amount minus 32 */
11476 my_getExpression (&imm_expr, s);
11477 check_absolute_expr (ip, &imm_expr);
11478 if ((unsigned long) imm_expr.X_add_number < 32
11479 || (unsigned long) imm_expr.X_add_number > 63)
11481 INSERT_OPERAND (mips_opts.micromips,
11482 SHAMT, *ip, imm_expr.X_add_number - 32);
11483 imm_expr.X_op = O_absent;
11487 case 'k': /* CACHE code. */
11488 case 'h': /* PREFX code. */
11489 case '1': /* SYNC type. */
11490 my_getExpression (&imm_expr, s);
11491 check_absolute_expr (ip, &imm_expr);
11492 if ((unsigned long) imm_expr.X_add_number > 31)
11493 as_warn (_("Invalid value for `%s' (%lu)"),
11495 (unsigned long) imm_expr.X_add_number);
11499 if (mips_fix_cn63xxp1
11500 && !mips_opts.micromips
11501 && strcmp ("pref", insn->name) == 0)
11502 switch (imm_expr.X_add_number)
11511 case 31: /* These are ok. */
11514 default: /* The rest must be changed to 28. */
11515 imm_expr.X_add_number = 28;
11518 INSERT_OPERAND (mips_opts.micromips,
11519 CACHE, *ip, imm_expr.X_add_number);
11522 INSERT_OPERAND (mips_opts.micromips,
11523 PREFX, *ip, imm_expr.X_add_number);
11526 INSERT_OPERAND (mips_opts.micromips,
11527 STYPE, *ip, imm_expr.X_add_number);
11530 imm_expr.X_op = O_absent;
11534 case 'c': /* BREAK code. */
11536 unsigned long mask = (mips_opts.micromips
11537 ? MICROMIPSOP_MASK_CODE
11540 my_getExpression (&imm_expr, s);
11541 check_absolute_expr (ip, &imm_expr);
11542 if ((unsigned long) imm_expr.X_add_number > mask)
11543 as_warn (_("Code for %s not in range 0..%lu (%lu)"),
11545 mask, (unsigned long) imm_expr.X_add_number);
11546 INSERT_OPERAND (mips_opts.micromips,
11547 CODE, *ip, imm_expr.X_add_number);
11548 imm_expr.X_op = O_absent;
11553 case 'q': /* Lower BREAK code. */
11555 unsigned long mask = (mips_opts.micromips
11556 ? MICROMIPSOP_MASK_CODE2
11559 my_getExpression (&imm_expr, s);
11560 check_absolute_expr (ip, &imm_expr);
11561 if ((unsigned long) imm_expr.X_add_number > mask)
11562 as_warn (_("Lower code for %s not in range 0..%lu (%lu)"),
11564 mask, (unsigned long) imm_expr.X_add_number);
11565 INSERT_OPERAND (mips_opts.micromips,
11566 CODE2, *ip, imm_expr.X_add_number);
11567 imm_expr.X_op = O_absent;
11572 case 'B': /* 20- or 10-bit syscall/break/wait code. */
11574 unsigned long mask = (mips_opts.micromips
11575 ? MICROMIPSOP_MASK_CODE10
11578 my_getExpression (&imm_expr, s);
11579 check_absolute_expr (ip, &imm_expr);
11580 if ((unsigned long) imm_expr.X_add_number > mask)
11581 as_warn (_("Code for %s not in range 0..%lu (%lu)"),
11583 mask, (unsigned long) imm_expr.X_add_number);
11584 if (mips_opts.micromips)
11585 INSERT_OPERAND (1, CODE10, *ip, imm_expr.X_add_number);
11587 INSERT_OPERAND (0, CODE20, *ip, imm_expr.X_add_number);
11588 imm_expr.X_op = O_absent;
11593 case 'C': /* 25- or 23-bit coprocessor code. */
11595 unsigned long mask = (mips_opts.micromips
11596 ? MICROMIPSOP_MASK_COPZ
11599 my_getExpression (&imm_expr, s);
11600 check_absolute_expr (ip, &imm_expr);
11601 if ((unsigned long) imm_expr.X_add_number > mask)
11602 as_warn (_("Coproccesor code > %u bits (%lu)"),
11603 mips_opts.micromips ? 23U : 25U,
11604 (unsigned long) imm_expr.X_add_number);
11605 INSERT_OPERAND (mips_opts.micromips,
11606 COPZ, *ip, imm_expr.X_add_number);
11607 imm_expr.X_op = O_absent;
11612 case 'J': /* 19-bit WAIT code. */
11613 gas_assert (!mips_opts.micromips);
11614 my_getExpression (&imm_expr, s);
11615 check_absolute_expr (ip, &imm_expr);
11616 if ((unsigned long) imm_expr.X_add_number > OP_MASK_CODE19)
11618 as_warn (_("Illegal 19-bit code (%lu)"),
11619 (unsigned long) imm_expr.X_add_number);
11620 imm_expr.X_add_number &= OP_MASK_CODE19;
11622 INSERT_OPERAND (0, CODE19, *ip, imm_expr.X_add_number);
11623 imm_expr.X_op = O_absent;
11627 case 'P': /* Performance register. */
11628 gas_assert (!mips_opts.micromips);
11629 my_getExpression (&imm_expr, s);
11630 check_absolute_expr (ip, &imm_expr);
11631 if (imm_expr.X_add_number != 0 && imm_expr.X_add_number != 1)
11632 as_warn (_("Invalid performance register (%lu)"),
11633 (unsigned long) imm_expr.X_add_number);
11634 INSERT_OPERAND (0, PERFREG, *ip, imm_expr.X_add_number);
11635 imm_expr.X_op = O_absent;
11639 case 'G': /* Coprocessor destination register. */
11641 unsigned long opcode = ip->insn_opcode;
11642 unsigned long mask;
11643 unsigned int types;
11646 if (mips_opts.micromips)
11648 mask = ~((MICROMIPSOP_MASK_RT << MICROMIPSOP_SH_RT)
11649 | (MICROMIPSOP_MASK_RS << MICROMIPSOP_SH_RS)
11650 | (MICROMIPSOP_MASK_SEL << MICROMIPSOP_SH_SEL));
11654 case 0x000000fc: /* mfc0 */
11655 case 0x000002fc: /* mtc0 */
11656 case 0x580000fc: /* dmfc0 */
11657 case 0x580002fc: /* dmtc0 */
11667 opcode = (opcode >> OP_SH_OP) & OP_MASK_OP;
11668 cop0 = opcode == OP_OP_COP0;
11670 types = RTYPE_NUM | (cop0 ? RTYPE_CP0 : RTYPE_GP);
11671 ok = reg_lookup (&s, types, ®no);
11672 if (mips_opts.micromips)
11673 INSERT_OPERAND (1, RS, *ip, regno);
11675 INSERT_OPERAND (0, RD, *ip, regno);
11684 case 'y': /* ALNV.PS source register. */
11685 gas_assert (mips_opts.micromips);
11687 case 'x': /* Ignore register name. */
11688 case 'U': /* Destination register (CLO/CLZ). */
11689 case 'g': /* Coprocessor destination register. */
11690 gas_assert (!mips_opts.micromips);
11691 case 'b': /* Base register. */
11692 case 'd': /* Destination register. */
11693 case 's': /* Source register. */
11694 case 't': /* Target register. */
11695 case 'r': /* Both target and source. */
11696 case 'v': /* Both dest and source. */
11697 case 'w': /* Both dest and target. */
11698 case 'E': /* Coprocessor target register. */
11699 case 'K': /* RDHWR destination register. */
11700 case 'z': /* Must be zero register. */
11703 if (*args == 'E' || *args == 'K')
11704 ok = reg_lookup (&s, RTYPE_NUM, ®no);
11707 ok = reg_lookup (&s, RTYPE_NUM | RTYPE_GP, ®no);
11708 if (regno == AT && mips_opts.at)
11710 if (mips_opts.at == ATREG)
11711 as_warn (_("Used $at without \".set noat\""));
11713 as_warn (_("Used $%u with \".set at=$%u\""),
11714 regno, mips_opts.at);
11724 if (c == 'r' || c == 'v' || c == 'w')
11731 /* 'z' only matches $0. */
11732 if (c == 'z' && regno != 0)
11735 if (c == 's' && !strncmp (ip->insn_mo->name, "jalr", 4))
11737 if (regno == lastregno)
11740 = _("Source and destination must be different");
11743 if (regno == 31 && lastregno == 0xffffffff)
11746 = _("A destination register must be supplied");
11750 /* Now that we have assembled one operand, we use the args
11751 string to figure out where it goes in the instruction. */
11758 INSERT_OPERAND (mips_opts.micromips, RS, *ip, regno);
11762 if (mips_opts.micromips)
11763 INSERT_OPERAND (1, RS, *ip, regno);
11765 INSERT_OPERAND (0, RD, *ip, regno);
11770 INSERT_OPERAND (mips_opts.micromips, RD, *ip, regno);
11774 gas_assert (!mips_opts.micromips);
11775 INSERT_OPERAND (0, RD, *ip, regno);
11776 INSERT_OPERAND (0, RT, *ip, regno);
11782 INSERT_OPERAND (mips_opts.micromips, RT, *ip, regno);
11786 gas_assert (mips_opts.micromips);
11787 INSERT_OPERAND (1, RS3, *ip, regno);
11791 /* This case exists because on the r3000 trunc
11792 expands into a macro which requires a gp
11793 register. On the r6000 or r4000 it is
11794 assembled into a single instruction which
11795 ignores the register. Thus the insn version
11796 is MIPS_ISA2 and uses 'x', and the macro
11797 version is MIPS_ISA1 and uses 't'. */
11801 /* This case is for the div instruction, which
11802 acts differently if the destination argument
11803 is $0. This only matches $0, and is checked
11804 outside the switch. */
11814 INSERT_OPERAND (mips_opts.micromips, RS, *ip, lastregno);
11818 INSERT_OPERAND (mips_opts.micromips, RT, *ip, lastregno);
11823 case 'O': /* MDMX alignment immediate constant. */
11824 gas_assert (!mips_opts.micromips);
11825 my_getExpression (&imm_expr, s);
11826 check_absolute_expr (ip, &imm_expr);
11827 if ((unsigned long) imm_expr.X_add_number > OP_MASK_ALN)
11828 as_warn (_("Improper align amount (%ld), using low bits"),
11829 (long) imm_expr.X_add_number);
11830 INSERT_OPERAND (0, ALN, *ip, imm_expr.X_add_number);
11831 imm_expr.X_op = O_absent;
11835 case 'Q': /* MDMX vector, element sel, or const. */
11838 /* MDMX Immediate. */
11839 gas_assert (!mips_opts.micromips);
11840 my_getExpression (&imm_expr, s);
11841 check_absolute_expr (ip, &imm_expr);
11842 if ((unsigned long) imm_expr.X_add_number > OP_MASK_FT)
11843 as_warn (_("Invalid MDMX Immediate (%ld)"),
11844 (long) imm_expr.X_add_number);
11845 INSERT_OPERAND (0, FT, *ip, imm_expr.X_add_number);
11846 if (ip->insn_opcode & (OP_MASK_VSEL << OP_SH_VSEL))
11847 ip->insn_opcode |= MDMX_FMTSEL_IMM_QH << OP_SH_VSEL;
11849 ip->insn_opcode |= MDMX_FMTSEL_IMM_OB << OP_SH_VSEL;
11850 imm_expr.X_op = O_absent;
11854 /* Not MDMX Immediate. Fall through. */
11855 case 'X': /* MDMX destination register. */
11856 case 'Y': /* MDMX source register. */
11857 case 'Z': /* MDMX target register. */
11860 gas_assert (!mips_opts.micromips);
11861 case 'D': /* Floating point destination register. */
11862 case 'S': /* Floating point source register. */
11863 case 'T': /* Floating point target register. */
11864 case 'R': /* Floating point source register. */
11868 || (mips_opts.ase_mdmx
11869 && (ip->insn_mo->pinfo & FP_D)
11870 && (ip->insn_mo->pinfo & (INSN_COPROC_MOVE_DELAY
11871 | INSN_COPROC_MEMORY_DELAY
11872 | INSN_LOAD_COPROC_DELAY
11873 | INSN_LOAD_MEMORY_DELAY
11874 | INSN_STORE_MEMORY))))
11875 rtype |= RTYPE_VEC;
11877 if (reg_lookup (&s, rtype, ®no))
11879 if ((regno & 1) != 0
11881 && !mips_oddfpreg_ok (ip->insn_mo, argnum))
11882 as_warn (_("Float register should be even, was %d"),
11890 if (c == 'V' || c == 'W')
11901 INSERT_OPERAND (mips_opts.micromips, FD, *ip, regno);
11907 INSERT_OPERAND (mips_opts.micromips, FS, *ip, regno);
11911 /* This is like 'Z', but also needs to fix the MDMX
11912 vector/scalar select bits. Note that the
11913 scalar immediate case is handled above. */
11916 int is_qh = (ip->insn_opcode & (1 << OP_SH_VSEL));
11917 int max_el = (is_qh ? 3 : 7);
11919 my_getExpression(&imm_expr, s);
11920 check_absolute_expr (ip, &imm_expr);
11922 if (imm_expr.X_add_number > max_el)
11923 as_bad (_("Bad element selector %ld"),
11924 (long) imm_expr.X_add_number);
11925 imm_expr.X_add_number &= max_el;
11926 ip->insn_opcode |= (imm_expr.X_add_number
11929 imm_expr.X_op = O_absent;
11931 as_warn (_("Expecting ']' found '%s'"), s);
11937 if (ip->insn_opcode & (OP_MASK_VSEL << OP_SH_VSEL))
11938 ip->insn_opcode |= (MDMX_FMTSEL_VEC_QH
11941 ip->insn_opcode |= (MDMX_FMTSEL_VEC_OB <<
11944 /* Fall through. */
11948 INSERT_OPERAND (mips_opts.micromips, FT, *ip, regno);
11952 INSERT_OPERAND (mips_opts.micromips, FR, *ip, regno);
11962 INSERT_OPERAND (mips_opts.micromips, FS, *ip, lastregno);
11966 INSERT_OPERAND (mips_opts.micromips, FT, *ip, lastregno);
11972 my_getExpression (&imm_expr, s);
11973 if (imm_expr.X_op != O_big
11974 && imm_expr.X_op != O_constant)
11975 insn_error = _("absolute expression required");
11976 if (HAVE_32BIT_GPRS)
11977 normalize_constant_expr (&imm_expr);
11982 my_getExpression (&offset_expr, s);
11983 normalize_address_expr (&offset_expr);
11984 *imm_reloc = BFD_RELOC_32;
11997 unsigned char temp[8];
11999 unsigned int length;
12004 /* These only appear as the last operand in an
12005 instruction, and every instruction that accepts
12006 them in any variant accepts them in all variants.
12007 This means we don't have to worry about backing out
12008 any changes if the instruction does not match.
12010 The difference between them is the size of the
12011 floating point constant and where it goes. For 'F'
12012 and 'L' the constant is 64 bits; for 'f' and 'l' it
12013 is 32 bits. Where the constant is placed is based
12014 on how the MIPS assembler does things:
12017 f -- immediate value
12020 The .lit4 and .lit8 sections are only used if
12021 permitted by the -G argument.
12023 The code below needs to know whether the target register
12024 is 32 or 64 bits wide. It relies on the fact 'f' and
12025 'F' are used with GPR-based instructions and 'l' and
12026 'L' are used with FPR-based instructions. */
12028 f64 = *args == 'F' || *args == 'L';
12029 using_gprs = *args == 'F' || *args == 'f';
12031 save_in = input_line_pointer;
12032 input_line_pointer = s;
12033 err = md_atof (f64 ? 'd' : 'f', (char *) temp, &len);
12035 s = input_line_pointer;
12036 input_line_pointer = save_in;
12037 if (err != NULL && *err != '\0')
12039 as_bad (_("Bad floating point constant: %s"), err);
12040 memset (temp, '\0', sizeof temp);
12041 length = f64 ? 8 : 4;
12044 gas_assert (length == (unsigned) (f64 ? 8 : 4));
12048 && (g_switch_value < 4
12049 || (temp[0] == 0 && temp[1] == 0)
12050 || (temp[2] == 0 && temp[3] == 0))))
12052 imm_expr.X_op = O_constant;
12053 if (!target_big_endian)
12054 imm_expr.X_add_number = bfd_getl32 (temp);
12056 imm_expr.X_add_number = bfd_getb32 (temp);
12058 else if (length > 4
12059 && !mips_disable_float_construction
12060 /* Constants can only be constructed in GPRs and
12061 copied to FPRs if the GPRs are at least as wide
12062 as the FPRs. Force the constant into memory if
12063 we are using 64-bit FPRs but the GPRs are only
12066 || !(HAVE_64BIT_FPRS && HAVE_32BIT_GPRS))
12067 && ((temp[0] == 0 && temp[1] == 0)
12068 || (temp[2] == 0 && temp[3] == 0))
12069 && ((temp[4] == 0 && temp[5] == 0)
12070 || (temp[6] == 0 && temp[7] == 0)))
12072 /* The value is simple enough to load with a couple of
12073 instructions. If using 32-bit registers, set
12074 imm_expr to the high order 32 bits and offset_expr to
12075 the low order 32 bits. Otherwise, set imm_expr to
12076 the entire 64 bit constant. */
12077 if (using_gprs ? HAVE_32BIT_GPRS : HAVE_32BIT_FPRS)
12079 imm_expr.X_op = O_constant;
12080 offset_expr.X_op = O_constant;
12081 if (!target_big_endian)
12083 imm_expr.X_add_number = bfd_getl32 (temp + 4);
12084 offset_expr.X_add_number = bfd_getl32 (temp);
12088 imm_expr.X_add_number = bfd_getb32 (temp);
12089 offset_expr.X_add_number = bfd_getb32 (temp + 4);
12091 if (offset_expr.X_add_number == 0)
12092 offset_expr.X_op = O_absent;
12094 else if (sizeof (imm_expr.X_add_number) > 4)
12096 imm_expr.X_op = O_constant;
12097 if (!target_big_endian)
12098 imm_expr.X_add_number = bfd_getl64 (temp);
12100 imm_expr.X_add_number = bfd_getb64 (temp);
12104 imm_expr.X_op = O_big;
12105 imm_expr.X_add_number = 4;
12106 if (!target_big_endian)
12108 generic_bignum[0] = bfd_getl16 (temp);
12109 generic_bignum[1] = bfd_getl16 (temp + 2);
12110 generic_bignum[2] = bfd_getl16 (temp + 4);
12111 generic_bignum[3] = bfd_getl16 (temp + 6);
12115 generic_bignum[0] = bfd_getb16 (temp + 6);
12116 generic_bignum[1] = bfd_getb16 (temp + 4);
12117 generic_bignum[2] = bfd_getb16 (temp + 2);
12118 generic_bignum[3] = bfd_getb16 (temp);
12124 const char *newname;
12127 /* Switch to the right section. */
12129 subseg = now_subseg;
12132 default: /* unused default case avoids warnings. */
12134 newname = RDATA_SECTION_NAME;
12135 if (g_switch_value >= 8)
12139 newname = RDATA_SECTION_NAME;
12142 gas_assert (g_switch_value >= 4);
12146 new_seg = subseg_new (newname, (subsegT) 0);
12148 bfd_set_section_flags (stdoutput, new_seg,
12153 frag_align (*args == 'l' ? 2 : 3, 0, 0);
12154 if (IS_ELF && strncmp (TARGET_OS, "elf", 3) != 0)
12155 record_alignment (new_seg, 4);
12157 record_alignment (new_seg, *args == 'l' ? 2 : 3);
12158 if (seg == now_seg)
12159 as_bad (_("Can't use floating point insn in this section"));
12161 /* Set the argument to the current address in the
12163 offset_expr.X_op = O_symbol;
12164 offset_expr.X_add_symbol = symbol_temp_new_now ();
12165 offset_expr.X_add_number = 0;
12167 /* Put the floating point number into the section. */
12168 p = frag_more ((int) length);
12169 memcpy (p, temp, length);
12171 /* Switch back to the original section. */
12172 subseg_set (seg, subseg);
12177 case 'i': /* 16-bit unsigned immediate. */
12178 case 'j': /* 16-bit signed immediate. */
12179 *imm_reloc = BFD_RELOC_LO16;
12180 if (my_getSmallExpression (&imm_expr, imm_reloc, s) == 0)
12183 offsetT minval, maxval;
12185 more = (insn + 1 < past
12186 && strcmp (insn->name, insn[1].name) == 0);
12188 /* If the expression was written as an unsigned number,
12189 only treat it as signed if there are no more
12193 && sizeof (imm_expr.X_add_number) <= 4
12194 && imm_expr.X_op == O_constant
12195 && imm_expr.X_add_number < 0
12196 && imm_expr.X_unsigned
12197 && HAVE_64BIT_GPRS)
12200 /* For compatibility with older assemblers, we accept
12201 0x8000-0xffff as signed 16-bit numbers when only
12202 signed numbers are allowed. */
12204 minval = 0, maxval = 0xffff;
12206 minval = -0x8000, maxval = 0x7fff;
12208 minval = -0x8000, maxval = 0xffff;
12210 if (imm_expr.X_op != O_constant
12211 || imm_expr.X_add_number < minval
12212 || imm_expr.X_add_number > maxval)
12216 if (imm_expr.X_op == O_constant
12217 || imm_expr.X_op == O_big)
12218 as_bad (_("Expression out of range"));
12224 case 'o': /* 16-bit offset. */
12225 offset_reloc[0] = BFD_RELOC_LO16;
12226 offset_reloc[1] = BFD_RELOC_UNUSED;
12227 offset_reloc[2] = BFD_RELOC_UNUSED;
12229 /* Check whether there is only a single bracketed expression
12230 left. If so, it must be the base register and the
12231 constant must be zero. */
12232 if (*s == '(' && strchr (s + 1, '(') == 0)
12234 offset_expr.X_op = O_constant;
12235 offset_expr.X_add_number = 0;
12239 /* If this value won't fit into a 16 bit offset, then go
12240 find a macro that will generate the 32 bit offset
12242 if (my_getSmallExpression (&offset_expr, offset_reloc, s) == 0
12243 && (offset_expr.X_op != O_constant
12244 || offset_expr.X_add_number >= 0x8000
12245 || offset_expr.X_add_number < -0x8000))
12251 case 'p': /* PC-relative offset. */
12252 *offset_reloc = BFD_RELOC_16_PCREL_S2;
12253 my_getExpression (&offset_expr, s);
12257 case 'u': /* Upper 16 bits. */
12258 if (my_getSmallExpression (&imm_expr, imm_reloc, s) == 0
12259 && imm_expr.X_op == O_constant
12260 && (imm_expr.X_add_number < 0
12261 || imm_expr.X_add_number >= 0x10000))
12262 as_bad (_("lui expression (%lu) not in range 0..65535"),
12263 (unsigned long) imm_expr.X_add_number);
12267 case 'a': /* 26-bit address. */
12268 *offset_reloc = BFD_RELOC_MIPS_JMP;
12269 my_getExpression (&offset_expr, s);
12273 case 'N': /* 3-bit branch condition code. */
12274 case 'M': /* 3-bit compare condition code. */
12276 if (ip->insn_mo->pinfo & (FP_D | FP_S))
12277 rtype |= RTYPE_FCC;
12278 if (!reg_lookup (&s, rtype, ®no))
12280 if ((strcmp (str + strlen (str) - 3, ".ps") == 0
12281 || strcmp (str + strlen (str) - 5, "any2f") == 0
12282 || strcmp (str + strlen (str) - 5, "any2t") == 0)
12283 && (regno & 1) != 0)
12284 as_warn (_("Condition code register should be even for %s, "
12287 if ((strcmp (str + strlen (str) - 5, "any4f") == 0
12288 || strcmp (str + strlen (str) - 5, "any4t") == 0)
12289 && (regno & 3) != 0)
12290 as_warn (_("Condition code register should be 0 or 4 for %s, "
12294 INSERT_OPERAND (mips_opts.micromips, BCC, *ip, regno);
12296 INSERT_OPERAND (mips_opts.micromips, CCC, *ip, regno);
12300 if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X'))
12311 while (ISDIGIT (*s));
12314 c = 8; /* Invalid sel value. */
12317 as_bad (_("Invalid coprocessor sub-selection value (0-7)"));
12318 INSERT_OPERAND (mips_opts.micromips, SEL, *ip, c);
12322 gas_assert (!mips_opts.micromips);
12323 /* Must be at least one digit. */
12324 my_getExpression (&imm_expr, s);
12325 check_absolute_expr (ip, &imm_expr);
12327 if ((unsigned long) imm_expr.X_add_number
12328 > (unsigned long) OP_MASK_VECBYTE)
12330 as_bad (_("bad byte vector index (%ld)"),
12331 (long) imm_expr.X_add_number);
12332 imm_expr.X_add_number = 0;
12335 INSERT_OPERAND (0, VECBYTE, *ip, imm_expr.X_add_number);
12336 imm_expr.X_op = O_absent;
12341 gas_assert (!mips_opts.micromips);
12342 my_getExpression (&imm_expr, s);
12343 check_absolute_expr (ip, &imm_expr);
12345 if ((unsigned long) imm_expr.X_add_number
12346 > (unsigned long) OP_MASK_VECALIGN)
12348 as_bad (_("bad byte vector index (%ld)"),
12349 (long) imm_expr.X_add_number);
12350 imm_expr.X_add_number = 0;
12353 INSERT_OPERAND (0, VECALIGN, *ip, imm_expr.X_add_number);
12354 imm_expr.X_op = O_absent;
12358 case 'm': /* Opcode extension character. */
12359 gas_assert (mips_opts.micromips);
12364 if (strncmp (s, "$pc", 3) == 0)
12392 ok = reg_lookup (&s, RTYPE_NUM | RTYPE_GP, ®no);
12393 if (regno == AT && mips_opts.at)
12395 if (mips_opts.at == ATREG)
12396 as_warn (_("Used $at without \".set noat\""));
12398 as_warn (_("Used $%u with \".set at=$%u\""),
12399 regno, mips_opts.at);
12405 gas_assert (args[1] == ',');
12411 gas_assert (args[1] == ',');
12413 continue; /* Nothing to do. */
12419 if (c == 'j' && !strncmp (ip->insn_mo->name, "jalr", 4))
12421 if (regno == lastregno)
12424 = _("Source and destination must be different");
12427 if (regno == 31 && lastregno == 0xffffffff)
12430 = _("A destination register must be supplied");
12441 gas_assert (args[1] == ',');
12448 gas_assert (args[1] == ',');
12451 continue; /* Nothing to do. */
12455 /* Make sure regno is the same as lastregno. */
12456 if (c == 't' && regno != lastregno)
12459 /* Make sure regno is the same as destregno. */
12460 if (c == 'x' && regno != destregno)
12463 /* We need to save regno, before regno maps to the
12464 microMIPS register encoding. */
12474 regno = ILLEGAL_REG;
12478 regno = mips32_to_micromips_reg_b_map[regno];
12482 regno = mips32_to_micromips_reg_c_map[regno];
12486 regno = mips32_to_micromips_reg_d_map[regno];
12490 regno = mips32_to_micromips_reg_e_map[regno];
12494 regno = mips32_to_micromips_reg_f_map[regno];
12498 regno = mips32_to_micromips_reg_g_map[regno];
12502 regno = mips32_to_micromips_reg_h_map[regno];
12506 switch (EXTRACT_OPERAND (1, MI, *ip))
12511 else if (regno == 22)
12513 else if (regno == 5)
12515 else if (regno == 6)
12517 else if (regno == 7)
12520 regno = ILLEGAL_REG;
12526 else if (regno == 7)
12529 regno = ILLEGAL_REG;
12536 regno = ILLEGAL_REG;
12540 regno = ILLEGAL_REG;
12546 regno = mips32_to_micromips_reg_l_map[regno];
12550 regno = mips32_to_micromips_reg_m_map[regno];
12554 regno = mips32_to_micromips_reg_n_map[regno];
12558 regno = mips32_to_micromips_reg_q_map[regno];
12563 regno = ILLEGAL_REG;
12568 regno = ILLEGAL_REG;
12573 regno = ILLEGAL_REG;
12576 case 'j': /* Do nothing. */
12586 if (regno == ILLEGAL_REG)
12592 INSERT_OPERAND (1, MB, *ip, regno);
12596 INSERT_OPERAND (1, MC, *ip, regno);
12600 INSERT_OPERAND (1, MD, *ip, regno);
12604 INSERT_OPERAND (1, ME, *ip, regno);
12608 INSERT_OPERAND (1, MF, *ip, regno);
12612 INSERT_OPERAND (1, MG, *ip, regno);
12616 INSERT_OPERAND (1, MH, *ip, regno);
12620 INSERT_OPERAND (1, MI, *ip, regno);
12624 INSERT_OPERAND (1, MJ, *ip, regno);
12628 INSERT_OPERAND (1, ML, *ip, regno);
12632 INSERT_OPERAND (1, MM, *ip, regno);
12636 INSERT_OPERAND (1, MN, *ip, regno);
12640 INSERT_OPERAND (1, MP, *ip, regno);
12644 INSERT_OPERAND (1, MQ, *ip, regno);
12647 case 'a': /* Do nothing. */
12648 case 's': /* Do nothing. */
12649 case 't': /* Do nothing. */
12650 case 'x': /* Do nothing. */
12651 case 'y': /* Do nothing. */
12652 case 'z': /* Do nothing. */
12662 bfd_reloc_code_real_type r[3];
12666 /* Check whether there is only a single bracketed
12667 expression left. If so, it must be the base register
12668 and the constant must be zero. */
12669 if (*s == '(' && strchr (s + 1, '(') == 0)
12671 INSERT_OPERAND (1, IMMA, *ip, 0);
12675 if (my_getSmallExpression (&ep, r, s) > 0
12676 || !expr_const_in_range (&ep, -64, 64, 2))
12679 imm = ep.X_add_number >> 2;
12680 INSERT_OPERAND (1, IMMA, *ip, imm);
12687 bfd_reloc_code_real_type r[3];
12691 if (my_getSmallExpression (&ep, r, s) > 0
12692 || ep.X_op != O_constant)
12695 for (imm = 0; imm < 8; imm++)
12696 if (micromips_imm_b_map[imm] == ep.X_add_number)
12701 INSERT_OPERAND (1, IMMB, *ip, imm);
12708 bfd_reloc_code_real_type r[3];
12712 if (my_getSmallExpression (&ep, r, s) > 0
12713 || ep.X_op != O_constant)
12716 for (imm = 0; imm < 16; imm++)
12717 if (micromips_imm_c_map[imm] == ep.X_add_number)
12722 INSERT_OPERAND (1, IMMC, *ip, imm);
12727 case 'D': /* pc relative offset */
12728 case 'E': /* pc relative offset */
12729 my_getExpression (&offset_expr, s);
12730 if (offset_expr.X_op == O_register)
12733 if (!forced_insn_length)
12734 *offset_reloc = (int) BFD_RELOC_UNUSED + c;
12736 *offset_reloc = BFD_RELOC_MICROMIPS_10_PCREL_S1;
12738 *offset_reloc = BFD_RELOC_MICROMIPS_7_PCREL_S1;
12744 bfd_reloc_code_real_type r[3];
12748 if (my_getSmallExpression (&ep, r, s) > 0
12749 || !expr_const_in_range (&ep, 0, 16, 0))
12752 imm = ep.X_add_number;
12753 INSERT_OPERAND (1, IMMF, *ip, imm);
12760 bfd_reloc_code_real_type r[3];
12764 /* Check whether there is only a single bracketed
12765 expression left. If so, it must be the base register
12766 and the constant must be zero. */
12767 if (*s == '(' && strchr (s + 1, '(') == 0)
12769 INSERT_OPERAND (1, IMMG, *ip, 0);
12773 if (my_getSmallExpression (&ep, r, s) > 0
12774 || !expr_const_in_range (&ep, -1, 15, 0))
12777 imm = ep.X_add_number & 15;
12778 INSERT_OPERAND (1, IMMG, *ip, imm);
12785 bfd_reloc_code_real_type r[3];
12789 /* Check whether there is only a single bracketed
12790 expression left. If so, it must be the base register
12791 and the constant must be zero. */
12792 if (*s == '(' && strchr (s + 1, '(') == 0)
12794 INSERT_OPERAND (1, IMMH, *ip, 0);
12798 if (my_getSmallExpression (&ep, r, s) > 0
12799 || !expr_const_in_range (&ep, 0, 16, 1))
12802 imm = ep.X_add_number >> 1;
12803 INSERT_OPERAND (1, IMMH, *ip, imm);
12810 bfd_reloc_code_real_type r[3];
12814 if (my_getSmallExpression (&ep, r, s) > 0
12815 || !expr_const_in_range (&ep, -1, 127, 0))
12818 imm = ep.X_add_number & 127;
12819 INSERT_OPERAND (1, IMMI, *ip, imm);
12826 bfd_reloc_code_real_type r[3];
12830 /* Check whether there is only a single bracketed
12831 expression left. If so, it must be the base register
12832 and the constant must be zero. */
12833 if (*s == '(' && strchr (s + 1, '(') == 0)
12835 INSERT_OPERAND (1, IMMJ, *ip, 0);
12839 if (my_getSmallExpression (&ep, r, s) > 0
12840 || !expr_const_in_range (&ep, 0, 16, 2))
12843 imm = ep.X_add_number >> 2;
12844 INSERT_OPERAND (1, IMMJ, *ip, imm);
12851 bfd_reloc_code_real_type r[3];
12855 /* Check whether there is only a single bracketed
12856 expression left. If so, it must be the base register
12857 and the constant must be zero. */
12858 if (*s == '(' && strchr (s + 1, '(') == 0)
12860 INSERT_OPERAND (1, IMML, *ip, 0);
12864 if (my_getSmallExpression (&ep, r, s) > 0
12865 || !expr_const_in_range (&ep, 0, 16, 0))
12868 imm = ep.X_add_number;
12869 INSERT_OPERAND (1, IMML, *ip, imm);
12876 bfd_reloc_code_real_type r[3];
12880 if (my_getSmallExpression (&ep, r, s) > 0
12881 || !expr_const_in_range (&ep, 1, 9, 0))
12884 imm = ep.X_add_number & 7;
12885 INSERT_OPERAND (1, IMMM, *ip, imm);
12890 case 'N': /* Register list for lwm and swm. */
12892 /* A comma-separated list of registers and/or
12893 dash-separated contiguous ranges including
12894 both ra and a set of one or more registers
12895 starting at s0 up to s3 which have to be
12902 and any permutations of these. */
12903 unsigned int reglist;
12906 if (!reglist_lookup (&s, RTYPE_NUM | RTYPE_GP, ®list))
12909 if ((reglist & 0xfff1ffff) != 0x80010000)
12912 reglist = (reglist >> 17) & 7;
12914 if ((reglist & -reglist) != reglist)
12917 imm = ffs (reglist) - 1;
12918 INSERT_OPERAND (1, IMMN, *ip, imm);
12922 case 'O': /* sdbbp 4-bit code. */
12924 bfd_reloc_code_real_type r[3];
12928 if (my_getSmallExpression (&ep, r, s) > 0
12929 || !expr_const_in_range (&ep, 0, 16, 0))
12932 imm = ep.X_add_number;
12933 INSERT_OPERAND (1, IMMO, *ip, imm);
12940 bfd_reloc_code_real_type r[3];
12944 if (my_getSmallExpression (&ep, r, s) > 0
12945 || !expr_const_in_range (&ep, 0, 32, 2))
12948 imm = ep.X_add_number >> 2;
12949 INSERT_OPERAND (1, IMMP, *ip, imm);
12956 bfd_reloc_code_real_type r[3];
12960 if (my_getSmallExpression (&ep, r, s) > 0
12961 || !expr_const_in_range (&ep, -0x400000, 0x400000, 2))
12964 imm = ep.X_add_number >> 2;
12965 INSERT_OPERAND (1, IMMQ, *ip, imm);
12972 bfd_reloc_code_real_type r[3];
12976 /* Check whether there is only a single bracketed
12977 expression left. If so, it must be the base register
12978 and the constant must be zero. */
12979 if (*s == '(' && strchr (s + 1, '(') == 0)
12981 INSERT_OPERAND (1, IMMU, *ip, 0);
12985 if (my_getSmallExpression (&ep, r, s) > 0
12986 || !expr_const_in_range (&ep, 0, 32, 2))
12989 imm = ep.X_add_number >> 2;
12990 INSERT_OPERAND (1, IMMU, *ip, imm);
12997 bfd_reloc_code_real_type r[3];
13001 if (my_getSmallExpression (&ep, r, s) > 0
13002 || !expr_const_in_range (&ep, 0, 64, 2))
13005 imm = ep.X_add_number >> 2;
13006 INSERT_OPERAND (1, IMMW, *ip, imm);
13013 bfd_reloc_code_real_type r[3];
13017 if (my_getSmallExpression (&ep, r, s) > 0
13018 || !expr_const_in_range (&ep, -8, 8, 0))
13021 imm = ep.X_add_number;
13022 INSERT_OPERAND (1, IMMX, *ip, imm);
13029 bfd_reloc_code_real_type r[3];
13033 if (my_getSmallExpression (&ep, r, s) > 0
13034 || expr_const_in_range (&ep, -2, 2, 2)
13035 || !expr_const_in_range (&ep, -258, 258, 2))
13038 imm = ep.X_add_number >> 2;
13039 imm = ((imm >> 1) & ~0xff) | (imm & 0xff);
13040 INSERT_OPERAND (1, IMMY, *ip, imm);
13047 bfd_reloc_code_real_type r[3];
13050 if (my_getSmallExpression (&ep, r, s) > 0
13051 || !expr_const_in_range (&ep, 0, 1, 0))
13058 as_bad (_("Internal error: bad microMIPS opcode "
13059 "(unknown extension operand type `m%c'): %s %s"),
13060 *args, insn->name, insn->args);
13061 /* Further processing is fruitless. */
13066 case 'n': /* Register list for 32-bit lwm and swm. */
13067 gas_assert (mips_opts.micromips);
13069 /* A comma-separated list of registers and/or
13070 dash-separated contiguous ranges including
13071 at least one of ra and a set of one or more
13072 registers starting at s0 up to s7 and then
13073 s8 which have to be consecutive, e.g.:
13081 and any permutations of these. */
13082 unsigned int reglist;
13086 if (!reglist_lookup (&s, RTYPE_NUM | RTYPE_GP, ®list))
13089 if ((reglist & 0x3f00ffff) != 0)
13092 ra = (reglist >> 27) & 0x10;
13093 reglist = ((reglist >> 22) & 0x100) | ((reglist >> 16) & 0xff);
13095 if ((reglist & -reglist) != reglist)
13098 imm = (ffs (reglist) - 1) | ra;
13099 INSERT_OPERAND (1, RT, *ip, imm);
13100 imm_expr.X_op = O_absent;
13104 case '|': /* 4-bit trap code. */
13105 gas_assert (mips_opts.micromips);
13106 my_getExpression (&imm_expr, s);
13107 check_absolute_expr (ip, &imm_expr);
13108 if ((unsigned long) imm_expr.X_add_number
13109 > MICROMIPSOP_MASK_TRAP)
13110 as_bad (_("Trap code (%lu) for %s not in 0..15 range"),
13111 (unsigned long) imm_expr.X_add_number,
13112 ip->insn_mo->name);
13113 INSERT_OPERAND (1, TRAP, *ip, imm_expr.X_add_number);
13114 imm_expr.X_op = O_absent;
13119 as_bad (_("Bad char = '%c'\n"), *args);
13124 /* Args don't match. */
13126 insn_error = _("Illegal operands");
13127 if (insn + 1 < past && !strcmp (insn->name, insn[1].name))
13132 else if (wrong_delay_slot_insns && need_delay_slot_ok)
13134 gas_assert (firstinsn);
13135 need_delay_slot_ok = FALSE;
13144 #define SKIP_SPACE_TABS(S) { while (*(S) == ' ' || *(S) == '\t') ++(S); }
13146 /* This routine assembles an instruction into its binary format when
13147 assembling for the mips16. As a side effect, it sets one of the
13148 global variables imm_reloc or offset_reloc to the type of relocation
13149 to do if one of the operands is an address expression. It also sets
13150 forced_insn_length to the resulting instruction size in bytes if the
13151 user explicitly requested a small or extended instruction. */
13154 mips16_ip (char *str, struct mips_cl_insn *ip)
13158 struct mips_opcode *insn;
13160 unsigned int regno;
13161 unsigned int lastregno = 0;
13167 forced_insn_length = 0;
13169 for (s = str; ISLOWER (*s); ++s)
13181 if (s[1] == 't' && s[2] == ' ')
13184 forced_insn_length = 2;
13188 else if (s[1] == 'e' && s[2] == ' ')
13191 forced_insn_length = 4;
13195 /* Fall through. */
13197 insn_error = _("unknown opcode");
13201 if (mips_opts.noautoextend && !forced_insn_length)
13202 forced_insn_length = 2;
13204 if ((insn = (struct mips_opcode *) hash_find (mips16_op_hash, str)) == NULL)
13206 insn_error = _("unrecognized opcode");
13215 gas_assert (strcmp (insn->name, str) == 0);
13217 ok = is_opcode_valid_16 (insn);
13220 if (insn + 1 < &mips16_opcodes[bfd_mips16_num_opcodes]
13221 && strcmp (insn->name, insn[1].name) == 0)
13230 static char buf[100];
13232 _("opcode not supported on this processor: %s (%s)"),
13233 mips_cpu_info_from_arch (mips_opts.arch)->name,
13234 mips_cpu_info_from_isa (mips_opts.isa)->name);
13241 create_insn (ip, insn);
13242 imm_expr.X_op = O_absent;
13243 imm_reloc[0] = BFD_RELOC_UNUSED;
13244 imm_reloc[1] = BFD_RELOC_UNUSED;
13245 imm_reloc[2] = BFD_RELOC_UNUSED;
13246 imm2_expr.X_op = O_absent;
13247 offset_expr.X_op = O_absent;
13248 offset_reloc[0] = BFD_RELOC_UNUSED;
13249 offset_reloc[1] = BFD_RELOC_UNUSED;
13250 offset_reloc[2] = BFD_RELOC_UNUSED;
13251 for (args = insn->args; 1; ++args)
13258 /* In this switch statement we call break if we did not find
13259 a match, continue if we did find a match, or return if we
13268 /* Stuff the immediate value in now, if we can. */
13269 if (imm_expr.X_op == O_constant
13270 && *imm_reloc > BFD_RELOC_UNUSED
13271 && *imm_reloc != BFD_RELOC_MIPS16_GOT16
13272 && *imm_reloc != BFD_RELOC_MIPS16_CALL16
13273 && insn->pinfo != INSN_MACRO)
13277 switch (*offset_reloc)
13279 case BFD_RELOC_MIPS16_HI16_S:
13280 tmp = (imm_expr.X_add_number + 0x8000) >> 16;
13283 case BFD_RELOC_MIPS16_HI16:
13284 tmp = imm_expr.X_add_number >> 16;
13287 case BFD_RELOC_MIPS16_LO16:
13288 tmp = ((imm_expr.X_add_number + 0x8000) & 0xffff)
13292 case BFD_RELOC_UNUSED:
13293 tmp = imm_expr.X_add_number;
13299 *offset_reloc = BFD_RELOC_UNUSED;
13301 mips16_immed (NULL, 0, *imm_reloc - BFD_RELOC_UNUSED,
13302 tmp, TRUE, forced_insn_length == 2,
13303 forced_insn_length == 4, &ip->insn_opcode,
13304 &ip->use_extend, &ip->extend);
13305 imm_expr.X_op = O_absent;
13306 *imm_reloc = BFD_RELOC_UNUSED;
13320 MIPS16_INSERT_OPERAND (RX, *ip, lastregno);
13323 MIPS16_INSERT_OPERAND (RY, *ip, lastregno);
13339 MIPS16_INSERT_OPERAND (RX, *ip, lastregno);
13341 MIPS16_INSERT_OPERAND (RY, *ip, lastregno);
13345 /* Fall through. */
13356 if (!reg_lookup (&s, RTYPE_NUM | RTYPE_GP, ®no))
13358 if (c == 'v' || c == 'w')
13361 MIPS16_INSERT_OPERAND (RX, *ip, lastregno);
13363 MIPS16_INSERT_OPERAND (RY, *ip, lastregno);
13374 if (c == 'v' || c == 'w')
13376 regno = mips16_to_32_reg_map[lastregno];
13390 regno = mips32_to_16_reg_map[regno];
13395 regno = ILLEGAL_REG;
13400 regno = ILLEGAL_REG;
13405 regno = ILLEGAL_REG;
13410 if (regno == AT && mips_opts.at)
13412 if (mips_opts.at == ATREG)
13413 as_warn (_("used $at without \".set noat\""));
13415 as_warn (_("used $%u with \".set at=$%u\""),
13416 regno, mips_opts.at);
13424 if (regno == ILLEGAL_REG)
13431 MIPS16_INSERT_OPERAND (RX, *ip, regno);
13435 MIPS16_INSERT_OPERAND (RY, *ip, regno);
13438 MIPS16_INSERT_OPERAND (RZ, *ip, regno);
13441 MIPS16_INSERT_OPERAND (MOVE32Z, *ip, regno);
13447 MIPS16_INSERT_OPERAND (REGR32, *ip, regno);
13450 regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3);
13451 MIPS16_INSERT_OPERAND (REG32R, *ip, regno);
13461 if (strncmp (s, "$pc", 3) == 0)
13478 i = my_getSmallExpression (&imm_expr, imm_reloc, s);
13481 if (imm_expr.X_op != O_constant)
13483 forced_insn_length = 4;
13484 ip->use_extend = TRUE;
13489 /* We need to relax this instruction. */
13490 *offset_reloc = *imm_reloc;
13491 *imm_reloc = (int) BFD_RELOC_UNUSED + c;
13496 *imm_reloc = BFD_RELOC_UNUSED;
13497 /* Fall through. */
13504 my_getExpression (&imm_expr, s);
13505 if (imm_expr.X_op == O_register)
13507 /* What we thought was an expression turned out to
13510 if (s[0] == '(' && args[1] == '(')
13512 /* It looks like the expression was omitted
13513 before a register indirection, which means
13514 that the expression is implicitly zero. We
13515 still set up imm_expr, so that we handle
13516 explicit extensions correctly. */
13517 imm_expr.X_op = O_constant;
13518 imm_expr.X_add_number = 0;
13519 *imm_reloc = (int) BFD_RELOC_UNUSED + c;
13526 /* We need to relax this instruction. */
13527 *imm_reloc = (int) BFD_RELOC_UNUSED + c;
13536 /* We use offset_reloc rather than imm_reloc for the PC
13537 relative operands. This lets macros with both
13538 immediate and address operands work correctly. */
13539 my_getExpression (&offset_expr, s);
13541 if (offset_expr.X_op == O_register)
13544 /* We need to relax this instruction. */
13545 *offset_reloc = (int) BFD_RELOC_UNUSED + c;
13549 case '6': /* break code */
13550 my_getExpression (&imm_expr, s);
13551 check_absolute_expr (ip, &imm_expr);
13552 if ((unsigned long) imm_expr.X_add_number > 63)
13553 as_warn (_("Invalid value for `%s' (%lu)"),
13555 (unsigned long) imm_expr.X_add_number);
13556 MIPS16_INSERT_OPERAND (IMM6, *ip, imm_expr.X_add_number);
13557 imm_expr.X_op = O_absent;
13561 case 'a': /* 26 bit address */
13562 my_getExpression (&offset_expr, s);
13564 *offset_reloc = BFD_RELOC_MIPS16_JMP;
13565 ip->insn_opcode <<= 16;
13568 case 'l': /* register list for entry macro */
13569 case 'L': /* register list for exit macro */
13579 unsigned int freg, reg1, reg2;
13581 while (*s == ' ' || *s == ',')
13583 if (reg_lookup (&s, RTYPE_GP | RTYPE_NUM, ®1))
13585 else if (reg_lookup (&s, RTYPE_FPU, ®1))
13589 as_bad (_("can't parse register list"));
13599 if (!reg_lookup (&s, freg ? RTYPE_FPU
13600 : (RTYPE_GP | RTYPE_NUM), ®2))
13602 as_bad (_("invalid register list"));
13606 if (freg && reg1 == 0 && reg2 == 0 && c == 'L')
13608 mask &= ~ (7 << 3);
13611 else if (freg && reg1 == 0 && reg2 == 1 && c == 'L')
13613 mask &= ~ (7 << 3);
13616 else if (reg1 == 4 && reg2 >= 4 && reg2 <= 7 && c != 'L')
13617 mask |= (reg2 - 3) << 3;
13618 else if (reg1 == 16 && reg2 >= 16 && reg2 <= 17)
13619 mask |= (reg2 - 15) << 1;
13620 else if (reg1 == RA && reg2 == RA)
13624 as_bad (_("invalid register list"));
13628 /* The mask is filled in in the opcode table for the
13629 benefit of the disassembler. We remove it before
13630 applying the actual mask. */
13631 ip->insn_opcode &= ~ ((7 << 3) << MIPS16OP_SH_IMM6);
13632 ip->insn_opcode |= mask << MIPS16OP_SH_IMM6;
13636 case 'm': /* Register list for save insn. */
13637 case 'M': /* Register list for restore insn. */
13640 int framesz = 0, seen_framesz = 0;
13641 int nargs = 0, statics = 0, sregs = 0;
13645 unsigned int reg1, reg2;
13647 SKIP_SPACE_TABS (s);
13650 SKIP_SPACE_TABS (s);
13652 my_getExpression (&imm_expr, s);
13653 if (imm_expr.X_op == O_constant)
13655 /* Handle the frame size. */
13658 as_bad (_("more than one frame size in list"));
13662 framesz = imm_expr.X_add_number;
13663 imm_expr.X_op = O_absent;
13668 if (! reg_lookup (&s, RTYPE_GP | RTYPE_NUM, ®1))
13670 as_bad (_("can't parse register list"));
13682 if (! reg_lookup (&s, RTYPE_GP | RTYPE_NUM, ®2)
13685 as_bad (_("can't parse register list"));
13690 while (reg1 <= reg2)
13692 if (reg1 >= 4 && reg1 <= 7)
13696 nargs |= 1 << (reg1 - 4);
13698 /* statics $a0-$a3 */
13699 statics |= 1 << (reg1 - 4);
13701 else if ((reg1 >= 16 && reg1 <= 23) || reg1 == 30)
13704 sregs |= 1 << ((reg1 == 30) ? 8 : (reg1 - 16));
13706 else if (reg1 == 31)
13708 /* Add $ra to insn. */
13713 as_bad (_("unexpected register in list"));
13721 /* Encode args/statics combination. */
13722 if (nargs & statics)
13723 as_bad (_("arg/static registers overlap"));
13724 else if (nargs == 0xf)
13725 /* All $a0-$a3 are args. */
13726 opcode |= MIPS16_ALL_ARGS << 16;
13727 else if (statics == 0xf)
13728 /* All $a0-$a3 are statics. */
13729 opcode |= MIPS16_ALL_STATICS << 16;
13732 int narg = 0, nstat = 0;
13734 /* Count arg registers. */
13735 while (nargs & 0x1)
13741 as_bad (_("invalid arg register list"));
13743 /* Count static registers. */
13744 while (statics & 0x8)
13746 statics = (statics << 1) & 0xf;
13750 as_bad (_("invalid static register list"));
13752 /* Encode args/statics. */
13753 opcode |= ((narg << 2) | nstat) << 16;
13756 /* Encode $s0/$s1. */
13757 if (sregs & (1 << 0)) /* $s0 */
13759 if (sregs & (1 << 1)) /* $s1 */
13765 /* Count regs $s2-$s8. */
13773 as_bad (_("invalid static register list"));
13774 /* Encode $s2-$s8. */
13775 opcode |= nsreg << 24;
13778 /* Encode frame size. */
13780 as_bad (_("missing frame size"));
13781 else if ((framesz & 7) != 0 || framesz < 0
13782 || framesz > 0xff * 8)
13783 as_bad (_("invalid frame size"));
13784 else if (framesz != 128 || (opcode >> 16) != 0)
13787 opcode |= (((framesz & 0xf0) << 16)
13788 | (framesz & 0x0f));
13791 /* Finally build the instruction. */
13792 if ((opcode >> 16) != 0 || framesz == 0)
13794 ip->use_extend = TRUE;
13795 ip->extend = opcode >> 16;
13797 ip->insn_opcode |= opcode & 0x7f;
13801 case 'e': /* extend code */
13802 my_getExpression (&imm_expr, s);
13803 check_absolute_expr (ip, &imm_expr);
13804 if ((unsigned long) imm_expr.X_add_number > 0x7ff)
13806 as_warn (_("Invalid value for `%s' (%lu)"),
13808 (unsigned long) imm_expr.X_add_number);
13809 imm_expr.X_add_number &= 0x7ff;
13811 ip->insn_opcode |= imm_expr.X_add_number;
13812 imm_expr.X_op = O_absent;
13822 /* Args don't match. */
13823 if (insn + 1 < &mips16_opcodes[bfd_mips16_num_opcodes] &&
13824 strcmp (insn->name, insn[1].name) == 0)
13831 insn_error = _("illegal operands");
13837 /* This structure holds information we know about a mips16 immediate
13840 struct mips16_immed_operand
13842 /* The type code used in the argument string in the opcode table. */
13844 /* The number of bits in the short form of the opcode. */
13846 /* The number of bits in the extended form of the opcode. */
13848 /* The amount by which the short form is shifted when it is used;
13849 for example, the sw instruction has a shift count of 2. */
13851 /* The amount by which the short form is shifted when it is stored
13852 into the instruction code. */
13854 /* Non-zero if the short form is unsigned. */
13856 /* Non-zero if the extended form is unsigned. */
13858 /* Non-zero if the value is PC relative. */
13862 /* The mips16 immediate operand types. */
13864 static const struct mips16_immed_operand mips16_immed_operands[] =
13866 { '<', 3, 5, 0, MIPS16OP_SH_RZ, 1, 1, 0 },
13867 { '>', 3, 5, 0, MIPS16OP_SH_RX, 1, 1, 0 },
13868 { '[', 3, 6, 0, MIPS16OP_SH_RZ, 1, 1, 0 },
13869 { ']', 3, 6, 0, MIPS16OP_SH_RX, 1, 1, 0 },
13870 { '4', 4, 15, 0, MIPS16OP_SH_IMM4, 0, 0, 0 },
13871 { '5', 5, 16, 0, MIPS16OP_SH_IMM5, 1, 0, 0 },
13872 { 'H', 5, 16, 1, MIPS16OP_SH_IMM5, 1, 0, 0 },
13873 { 'W', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 0 },
13874 { 'D', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 0 },
13875 { 'j', 5, 16, 0, MIPS16OP_SH_IMM5, 0, 0, 0 },
13876 { '8', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 0, 0 },
13877 { 'V', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 0 },
13878 { 'C', 8, 16, 3, MIPS16OP_SH_IMM8, 1, 0, 0 },
13879 { 'U', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 1, 0 },
13880 { 'k', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 0 },
13881 { 'K', 8, 16, 3, MIPS16OP_SH_IMM8, 0, 0, 0 },
13882 { 'p', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 },
13883 { 'q', 11, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 },
13884 { 'A', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 1 },
13885 { 'B', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 1 },
13886 { 'E', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 1 }
13889 #define MIPS16_NUM_IMMED \
13890 (sizeof mips16_immed_operands / sizeof mips16_immed_operands[0])
13892 /* Handle a mips16 instruction with an immediate value. This or's the
13893 small immediate value into *INSN. It sets *USE_EXTEND to indicate
13894 whether an extended value is needed; if one is needed, it sets
13895 *EXTEND to the value. The argument type is TYPE. The value is VAL.
13896 If SMALL is true, an unextended opcode was explicitly requested.
13897 If EXT is true, an extended opcode was explicitly requested. If
13898 WARN is true, warn if EXT does not match reality. */
13901 mips16_immed (char *file, unsigned int line, int type, offsetT val,
13902 bfd_boolean warn, bfd_boolean small, bfd_boolean ext,
13903 unsigned long *insn, bfd_boolean *use_extend,
13904 unsigned short *extend)
13906 const struct mips16_immed_operand *op;
13907 int mintiny, maxtiny;
13908 bfd_boolean needext;
13910 op = mips16_immed_operands;
13911 while (op->type != type)
13914 gas_assert (op < mips16_immed_operands + MIPS16_NUM_IMMED);
13919 if (type == '<' || type == '>' || type == '[' || type == ']')
13922 maxtiny = 1 << op->nbits;
13927 maxtiny = (1 << op->nbits) - 1;
13932 mintiny = - (1 << (op->nbits - 1));
13933 maxtiny = (1 << (op->nbits - 1)) - 1;
13936 /* Branch offsets have an implicit 0 in the lowest bit. */
13937 if (type == 'p' || type == 'q')
13940 if ((val & ((1 << op->shift) - 1)) != 0
13941 || val < (mintiny << op->shift)
13942 || val > (maxtiny << op->shift))
13947 if (warn && ext && ! needext)
13948 as_warn_where (file, line,
13949 _("extended operand requested but not required"));
13950 if (small && needext)
13951 as_bad_where (file, line, _("invalid unextended operand value"));
13953 if (small || (! ext && ! needext))
13957 *use_extend = FALSE;
13958 insnval = ((val >> op->shift) & ((1 << op->nbits) - 1));
13959 insnval <<= op->op_shift;
13964 long minext, maxext;
13970 maxext = (1 << op->extbits) - 1;
13974 minext = - (1 << (op->extbits - 1));
13975 maxext = (1 << (op->extbits - 1)) - 1;
13977 if (val < minext || val > maxext)
13978 as_bad_where (file, line,
13979 _("operand value out of range for instruction"));
13981 *use_extend = TRUE;
13982 if (op->extbits == 16)
13984 extval = ((val >> 11) & 0x1f) | (val & 0x7e0);
13987 else if (op->extbits == 15)
13989 extval = ((val >> 11) & 0xf) | (val & 0x7f0);
13994 extval = ((val & 0x1f) << 6) | (val & 0x20);
13998 *extend = (unsigned short) extval;
14003 struct percent_op_match
14006 bfd_reloc_code_real_type reloc;
14009 static const struct percent_op_match mips_percent_op[] =
14011 {"%lo", BFD_RELOC_LO16},
14013 {"%call_hi", BFD_RELOC_MIPS_CALL_HI16},
14014 {"%call_lo", BFD_RELOC_MIPS_CALL_LO16},
14015 {"%call16", BFD_RELOC_MIPS_CALL16},
14016 {"%got_disp", BFD_RELOC_MIPS_GOT_DISP},
14017 {"%got_page", BFD_RELOC_MIPS_GOT_PAGE},
14018 {"%got_ofst", BFD_RELOC_MIPS_GOT_OFST},
14019 {"%got_hi", BFD_RELOC_MIPS_GOT_HI16},
14020 {"%got_lo", BFD_RELOC_MIPS_GOT_LO16},
14021 {"%got", BFD_RELOC_MIPS_GOT16},
14022 {"%gp_rel", BFD_RELOC_GPREL16},
14023 {"%half", BFD_RELOC_16},
14024 {"%highest", BFD_RELOC_MIPS_HIGHEST},
14025 {"%higher", BFD_RELOC_MIPS_HIGHER},
14026 {"%neg", BFD_RELOC_MIPS_SUB},
14027 {"%tlsgd", BFD_RELOC_MIPS_TLS_GD},
14028 {"%tlsldm", BFD_RELOC_MIPS_TLS_LDM},
14029 {"%dtprel_hi", BFD_RELOC_MIPS_TLS_DTPREL_HI16},
14030 {"%dtprel_lo", BFD_RELOC_MIPS_TLS_DTPREL_LO16},
14031 {"%tprel_hi", BFD_RELOC_MIPS_TLS_TPREL_HI16},
14032 {"%tprel_lo", BFD_RELOC_MIPS_TLS_TPREL_LO16},
14033 {"%gottprel", BFD_RELOC_MIPS_TLS_GOTTPREL},
14035 {"%hi", BFD_RELOC_HI16_S}
14038 static const struct percent_op_match mips16_percent_op[] =
14040 {"%lo", BFD_RELOC_MIPS16_LO16},
14041 {"%gprel", BFD_RELOC_MIPS16_GPREL},
14042 {"%got", BFD_RELOC_MIPS16_GOT16},
14043 {"%call16", BFD_RELOC_MIPS16_CALL16},
14044 {"%hi", BFD_RELOC_MIPS16_HI16_S}
14048 /* Return true if *STR points to a relocation operator. When returning true,
14049 move *STR over the operator and store its relocation code in *RELOC.
14050 Leave both *STR and *RELOC alone when returning false. */
14053 parse_relocation (char **str, bfd_reloc_code_real_type *reloc)
14055 const struct percent_op_match *percent_op;
14058 if (mips_opts.mips16)
14060 percent_op = mips16_percent_op;
14061 limit = ARRAY_SIZE (mips16_percent_op);
14065 percent_op = mips_percent_op;
14066 limit = ARRAY_SIZE (mips_percent_op);
14069 for (i = 0; i < limit; i++)
14070 if (strncasecmp (*str, percent_op[i].str, strlen (percent_op[i].str)) == 0)
14072 int len = strlen (percent_op[i].str);
14074 if (!ISSPACE ((*str)[len]) && (*str)[len] != '(')
14077 *str += strlen (percent_op[i].str);
14078 *reloc = percent_op[i].reloc;
14080 /* Check whether the output BFD supports this relocation.
14081 If not, issue an error and fall back on something safe. */
14082 if (!bfd_reloc_type_lookup (stdoutput, percent_op[i].reloc))
14084 as_bad (_("relocation %s isn't supported by the current ABI"),
14085 percent_op[i].str);
14086 *reloc = BFD_RELOC_UNUSED;
14094 /* Parse string STR as a 16-bit relocatable operand. Store the
14095 expression in *EP and the relocations in the array starting
14096 at RELOC. Return the number of relocation operators used.
14098 On exit, EXPR_END points to the first character after the expression. */
14101 my_getSmallExpression (expressionS *ep, bfd_reloc_code_real_type *reloc,
14104 bfd_reloc_code_real_type reversed_reloc[3];
14105 size_t reloc_index, i;
14106 int crux_depth, str_depth;
14109 /* Search for the start of the main expression, recoding relocations
14110 in REVERSED_RELOC. End the loop with CRUX pointing to the start
14111 of the main expression and with CRUX_DEPTH containing the number
14112 of open brackets at that point. */
14119 crux_depth = str_depth;
14121 /* Skip over whitespace and brackets, keeping count of the number
14123 while (*str == ' ' || *str == '\t' || *str == '(')
14128 && reloc_index < (HAVE_NEWABI ? 3 : 1)
14129 && parse_relocation (&str, &reversed_reloc[reloc_index]));
14131 my_getExpression (ep, crux);
14134 /* Match every open bracket. */
14135 while (crux_depth > 0 && (*str == ')' || *str == ' ' || *str == '\t'))
14139 if (crux_depth > 0)
14140 as_bad (_("unclosed '('"));
14144 if (reloc_index != 0)
14146 prev_reloc_op_frag = frag_now;
14147 for (i = 0; i < reloc_index; i++)
14148 reloc[i] = reversed_reloc[reloc_index - 1 - i];
14151 return reloc_index;
14155 my_getExpression (expressionS *ep, char *str)
14159 save_in = input_line_pointer;
14160 input_line_pointer = str;
14162 expr_end = input_line_pointer;
14163 input_line_pointer = save_in;
14167 md_atof (int type, char *litP, int *sizeP)
14169 return ieee_md_atof (type, litP, sizeP, target_big_endian);
14173 md_number_to_chars (char *buf, valueT val, int n)
14175 if (target_big_endian)
14176 number_to_chars_bigendian (buf, val, n);
14178 number_to_chars_littleendian (buf, val, n);
14182 static int support_64bit_objects(void)
14184 const char **list, **l;
14187 list = bfd_target_list ();
14188 for (l = list; *l != NULL; l++)
14189 if (strcmp (*l, ELF_TARGET ("elf64-", "big")) == 0
14190 || strcmp (*l, ELF_TARGET ("elf64-", "little")) == 0)
14192 yes = (*l != NULL);
14196 #endif /* OBJ_ELF */
14198 const char *md_shortopts = "O::g::G:";
14202 OPTION_MARCH = OPTION_MD_BASE,
14224 OPTION_NO_SMARTMIPS,
14228 OPTION_NO_MICROMIPS,
14231 OPTION_COMPAT_ARCH_BASE,
14240 OPTION_M7000_HILO_FIX,
14241 OPTION_MNO_7000_HILO_FIX,
14244 OPTION_FIX_LOONGSON2F_JUMP,
14245 OPTION_NO_FIX_LOONGSON2F_JUMP,
14246 OPTION_FIX_LOONGSON2F_NOP,
14247 OPTION_NO_FIX_LOONGSON2F_NOP,
14249 OPTION_NO_FIX_VR4120,
14251 OPTION_NO_FIX_VR4130,
14252 OPTION_FIX_CN63XXP1,
14253 OPTION_NO_FIX_CN63XXP1,
14260 OPTION_CONSTRUCT_FLOATS,
14261 OPTION_NO_CONSTRUCT_FLOATS,
14264 OPTION_RELAX_BRANCH,
14265 OPTION_NO_RELAX_BRANCH,
14272 OPTION_SINGLE_FLOAT,
14273 OPTION_DOUBLE_FLOAT,
14276 OPTION_CALL_SHARED,
14277 OPTION_CALL_NONPIC,
14287 OPTION_MVXWORKS_PIC,
14288 #endif /* OBJ_ELF */
14292 struct option md_longopts[] =
14294 /* Options which specify architecture. */
14295 {"march", required_argument, NULL, OPTION_MARCH},
14296 {"mtune", required_argument, NULL, OPTION_MTUNE},
14297 {"mips0", no_argument, NULL, OPTION_MIPS1},
14298 {"mips1", no_argument, NULL, OPTION_MIPS1},
14299 {"mips2", no_argument, NULL, OPTION_MIPS2},
14300 {"mips3", no_argument, NULL, OPTION_MIPS3},
14301 {"mips4", no_argument, NULL, OPTION_MIPS4},
14302 {"mips5", no_argument, NULL, OPTION_MIPS5},
14303 {"mips32", no_argument, NULL, OPTION_MIPS32},
14304 {"mips64", no_argument, NULL, OPTION_MIPS64},
14305 {"mips32r2", no_argument, NULL, OPTION_MIPS32R2},
14306 {"mips64r2", no_argument, NULL, OPTION_MIPS64R2},
14308 /* Options which specify Application Specific Extensions (ASEs). */
14309 {"mips16", no_argument, NULL, OPTION_MIPS16},
14310 {"no-mips16", no_argument, NULL, OPTION_NO_MIPS16},
14311 {"mips3d", no_argument, NULL, OPTION_MIPS3D},
14312 {"no-mips3d", no_argument, NULL, OPTION_NO_MIPS3D},
14313 {"mdmx", no_argument, NULL, OPTION_MDMX},
14314 {"no-mdmx", no_argument, NULL, OPTION_NO_MDMX},
14315 {"mdsp", no_argument, NULL, OPTION_DSP},
14316 {"mno-dsp", no_argument, NULL, OPTION_NO_DSP},
14317 {"mmt", no_argument, NULL, OPTION_MT},
14318 {"mno-mt", no_argument, NULL, OPTION_NO_MT},
14319 {"msmartmips", no_argument, NULL, OPTION_SMARTMIPS},
14320 {"mno-smartmips", no_argument, NULL, OPTION_NO_SMARTMIPS},
14321 {"mdspr2", no_argument, NULL, OPTION_DSPR2},
14322 {"mno-dspr2", no_argument, NULL, OPTION_NO_DSPR2},
14323 {"mmicromips", no_argument, NULL, OPTION_MICROMIPS},
14324 {"mno-micromips", no_argument, NULL, OPTION_NO_MICROMIPS},
14325 {"mmcu", no_argument, NULL, OPTION_MCU},
14326 {"mno-mcu", no_argument, NULL, OPTION_NO_MCU},
14328 /* Old-style architecture options. Don't add more of these. */
14329 {"m4650", no_argument, NULL, OPTION_M4650},
14330 {"no-m4650", no_argument, NULL, OPTION_NO_M4650},
14331 {"m4010", no_argument, NULL, OPTION_M4010},
14332 {"no-m4010", no_argument, NULL, OPTION_NO_M4010},
14333 {"m4100", no_argument, NULL, OPTION_M4100},
14334 {"no-m4100", no_argument, NULL, OPTION_NO_M4100},
14335 {"m3900", no_argument, NULL, OPTION_M3900},
14336 {"no-m3900", no_argument, NULL, OPTION_NO_M3900},
14338 /* Options which enable bug fixes. */
14339 {"mfix7000", no_argument, NULL, OPTION_M7000_HILO_FIX},
14340 {"no-fix-7000", no_argument, NULL, OPTION_MNO_7000_HILO_FIX},
14341 {"mno-fix7000", no_argument, NULL, OPTION_MNO_7000_HILO_FIX},
14342 {"mfix-loongson2f-jump", no_argument, NULL, OPTION_FIX_LOONGSON2F_JUMP},
14343 {"mno-fix-loongson2f-jump", no_argument, NULL, OPTION_NO_FIX_LOONGSON2F_JUMP},
14344 {"mfix-loongson2f-nop", no_argument, NULL, OPTION_FIX_LOONGSON2F_NOP},
14345 {"mno-fix-loongson2f-nop", no_argument, NULL, OPTION_NO_FIX_LOONGSON2F_NOP},
14346 {"mfix-vr4120", no_argument, NULL, OPTION_FIX_VR4120},
14347 {"mno-fix-vr4120", no_argument, NULL, OPTION_NO_FIX_VR4120},
14348 {"mfix-vr4130", no_argument, NULL, OPTION_FIX_VR4130},
14349 {"mno-fix-vr4130", no_argument, NULL, OPTION_NO_FIX_VR4130},
14350 {"mfix-24k", no_argument, NULL, OPTION_FIX_24K},
14351 {"mno-fix-24k", no_argument, NULL, OPTION_NO_FIX_24K},
14352 {"mfix-cn63xxp1", no_argument, NULL, OPTION_FIX_CN63XXP1},
14353 {"mno-fix-cn63xxp1", no_argument, NULL, OPTION_NO_FIX_CN63XXP1},
14355 /* Miscellaneous options. */
14356 {"trap", no_argument, NULL, OPTION_TRAP},
14357 {"no-break", no_argument, NULL, OPTION_TRAP},
14358 {"break", no_argument, NULL, OPTION_BREAK},
14359 {"no-trap", no_argument, NULL, OPTION_BREAK},
14360 {"EB", no_argument, NULL, OPTION_EB},
14361 {"EL", no_argument, NULL, OPTION_EL},
14362 {"mfp32", no_argument, NULL, OPTION_FP32},
14363 {"mgp32", no_argument, NULL, OPTION_GP32},
14364 {"construct-floats", no_argument, NULL, OPTION_CONSTRUCT_FLOATS},
14365 {"no-construct-floats", no_argument, NULL, OPTION_NO_CONSTRUCT_FLOATS},
14366 {"mfp64", no_argument, NULL, OPTION_FP64},
14367 {"mgp64", no_argument, NULL, OPTION_GP64},
14368 {"relax-branch", no_argument, NULL, OPTION_RELAX_BRANCH},
14369 {"no-relax-branch", no_argument, NULL, OPTION_NO_RELAX_BRANCH},
14370 {"mshared", no_argument, NULL, OPTION_MSHARED},
14371 {"mno-shared", no_argument, NULL, OPTION_MNO_SHARED},
14372 {"msym32", no_argument, NULL, OPTION_MSYM32},
14373 {"mno-sym32", no_argument, NULL, OPTION_MNO_SYM32},
14374 {"msoft-float", no_argument, NULL, OPTION_SOFT_FLOAT},
14375 {"mhard-float", no_argument, NULL, OPTION_HARD_FLOAT},
14376 {"msingle-float", no_argument, NULL, OPTION_SINGLE_FLOAT},
14377 {"mdouble-float", no_argument, NULL, OPTION_DOUBLE_FLOAT},
14379 /* Strictly speaking this next option is ELF specific,
14380 but we allow it for other ports as well in order to
14381 make testing easier. */
14382 {"32", no_argument, NULL, OPTION_32},
14384 /* ELF-specific options. */
14386 {"KPIC", no_argument, NULL, OPTION_CALL_SHARED},
14387 {"call_shared", no_argument, NULL, OPTION_CALL_SHARED},
14388 {"call_nonpic", no_argument, NULL, OPTION_CALL_NONPIC},
14389 {"non_shared", no_argument, NULL, OPTION_NON_SHARED},
14390 {"xgot", no_argument, NULL, OPTION_XGOT},
14391 {"mabi", required_argument, NULL, OPTION_MABI},
14392 {"n32", no_argument, NULL, OPTION_N32},
14393 {"64", no_argument, NULL, OPTION_64},
14394 {"mdebug", no_argument, NULL, OPTION_MDEBUG},
14395 {"no-mdebug", no_argument, NULL, OPTION_NO_MDEBUG},
14396 {"mpdr", no_argument, NULL, OPTION_PDR},
14397 {"mno-pdr", no_argument, NULL, OPTION_NO_PDR},
14398 {"mvxworks-pic", no_argument, NULL, OPTION_MVXWORKS_PIC},
14399 #endif /* OBJ_ELF */
14401 {NULL, no_argument, NULL, 0}
14403 size_t md_longopts_size = sizeof (md_longopts);
14405 /* Set STRING_PTR (either &mips_arch_string or &mips_tune_string) to
14406 NEW_VALUE. Warn if another value was already specified. Note:
14407 we have to defer parsing the -march and -mtune arguments in order
14408 to handle 'from-abi' correctly, since the ABI might be specified
14409 in a later argument. */
14412 mips_set_option_string (const char **string_ptr, const char *new_value)
14414 if (*string_ptr != 0 && strcasecmp (*string_ptr, new_value) != 0)
14415 as_warn (_("A different %s was already specified, is now %s"),
14416 string_ptr == &mips_arch_string ? "-march" : "-mtune",
14419 *string_ptr = new_value;
14423 md_parse_option (int c, char *arg)
14427 case OPTION_CONSTRUCT_FLOATS:
14428 mips_disable_float_construction = 0;
14431 case OPTION_NO_CONSTRUCT_FLOATS:
14432 mips_disable_float_construction = 1;
14444 target_big_endian = 1;
14448 target_big_endian = 0;
14454 else if (arg[0] == '0')
14456 else if (arg[0] == '1')
14466 mips_debug = atoi (arg);
14470 file_mips_isa = ISA_MIPS1;
14474 file_mips_isa = ISA_MIPS2;
14478 file_mips_isa = ISA_MIPS3;
14482 file_mips_isa = ISA_MIPS4;
14486 file_mips_isa = ISA_MIPS5;
14489 case OPTION_MIPS32:
14490 file_mips_isa = ISA_MIPS32;
14493 case OPTION_MIPS32R2:
14494 file_mips_isa = ISA_MIPS32R2;
14497 case OPTION_MIPS64R2:
14498 file_mips_isa = ISA_MIPS64R2;
14501 case OPTION_MIPS64:
14502 file_mips_isa = ISA_MIPS64;
14506 mips_set_option_string (&mips_tune_string, arg);
14510 mips_set_option_string (&mips_arch_string, arg);
14514 mips_set_option_string (&mips_arch_string, "4650");
14515 mips_set_option_string (&mips_tune_string, "4650");
14518 case OPTION_NO_M4650:
14522 mips_set_option_string (&mips_arch_string, "4010");
14523 mips_set_option_string (&mips_tune_string, "4010");
14526 case OPTION_NO_M4010:
14530 mips_set_option_string (&mips_arch_string, "4100");
14531 mips_set_option_string (&mips_tune_string, "4100");
14534 case OPTION_NO_M4100:
14538 mips_set_option_string (&mips_arch_string, "3900");
14539 mips_set_option_string (&mips_tune_string, "3900");
14542 case OPTION_NO_M3900:
14546 mips_opts.ase_mdmx = 1;
14549 case OPTION_NO_MDMX:
14550 mips_opts.ase_mdmx = 0;
14554 mips_opts.ase_dsp = 1;
14555 mips_opts.ase_dspr2 = 0;
14558 case OPTION_NO_DSP:
14559 mips_opts.ase_dsp = 0;
14560 mips_opts.ase_dspr2 = 0;
14564 mips_opts.ase_dspr2 = 1;
14565 mips_opts.ase_dsp = 1;
14568 case OPTION_NO_DSPR2:
14569 mips_opts.ase_dspr2 = 0;
14570 mips_opts.ase_dsp = 0;
14574 mips_opts.ase_mt = 1;
14578 mips_opts.ase_mt = 0;
14582 mips_opts.ase_mcu = 1;
14585 case OPTION_NO_MCU:
14586 mips_opts.ase_mcu = 0;
14589 case OPTION_MICROMIPS:
14590 if (mips_opts.mips16 == 1)
14592 as_bad (_("-mmicromips cannot be used with -mips16"));
14595 mips_opts.micromips = 1;
14596 mips_no_prev_insn ();
14599 case OPTION_NO_MICROMIPS:
14600 mips_opts.micromips = 0;
14601 mips_no_prev_insn ();
14604 case OPTION_MIPS16:
14605 if (mips_opts.micromips == 1)
14607 as_bad (_("-mips16 cannot be used with -micromips"));
14610 mips_opts.mips16 = 1;
14611 mips_no_prev_insn ();
14614 case OPTION_NO_MIPS16:
14615 mips_opts.mips16 = 0;
14616 mips_no_prev_insn ();
14619 case OPTION_MIPS3D:
14620 mips_opts.ase_mips3d = 1;
14623 case OPTION_NO_MIPS3D:
14624 mips_opts.ase_mips3d = 0;
14627 case OPTION_SMARTMIPS:
14628 mips_opts.ase_smartmips = 1;
14631 case OPTION_NO_SMARTMIPS:
14632 mips_opts.ase_smartmips = 0;
14635 case OPTION_FIX_24K:
14639 case OPTION_NO_FIX_24K:
14643 case OPTION_FIX_LOONGSON2F_JUMP:
14644 mips_fix_loongson2f_jump = TRUE;
14647 case OPTION_NO_FIX_LOONGSON2F_JUMP:
14648 mips_fix_loongson2f_jump = FALSE;
14651 case OPTION_FIX_LOONGSON2F_NOP:
14652 mips_fix_loongson2f_nop = TRUE;
14655 case OPTION_NO_FIX_LOONGSON2F_NOP:
14656 mips_fix_loongson2f_nop = FALSE;
14659 case OPTION_FIX_VR4120:
14660 mips_fix_vr4120 = 1;
14663 case OPTION_NO_FIX_VR4120:
14664 mips_fix_vr4120 = 0;
14667 case OPTION_FIX_VR4130:
14668 mips_fix_vr4130 = 1;
14671 case OPTION_NO_FIX_VR4130:
14672 mips_fix_vr4130 = 0;
14675 case OPTION_FIX_CN63XXP1:
14676 mips_fix_cn63xxp1 = TRUE;
14679 case OPTION_NO_FIX_CN63XXP1:
14680 mips_fix_cn63xxp1 = FALSE;
14683 case OPTION_RELAX_BRANCH:
14684 mips_relax_branch = 1;
14687 case OPTION_NO_RELAX_BRANCH:
14688 mips_relax_branch = 0;
14691 case OPTION_MSHARED:
14692 mips_in_shared = TRUE;
14695 case OPTION_MNO_SHARED:
14696 mips_in_shared = FALSE;
14699 case OPTION_MSYM32:
14700 mips_opts.sym32 = TRUE;
14703 case OPTION_MNO_SYM32:
14704 mips_opts.sym32 = FALSE;
14708 /* When generating ELF code, we permit -KPIC and -call_shared to
14709 select SVR4_PIC, and -non_shared to select no PIC. This is
14710 intended to be compatible with Irix 5. */
14711 case OPTION_CALL_SHARED:
14714 as_bad (_("-call_shared is supported only for ELF format"));
14717 mips_pic = SVR4_PIC;
14718 mips_abicalls = TRUE;
14721 case OPTION_CALL_NONPIC:
14724 as_bad (_("-call_nonpic is supported only for ELF format"));
14728 mips_abicalls = TRUE;
14731 case OPTION_NON_SHARED:
14734 as_bad (_("-non_shared is supported only for ELF format"));
14738 mips_abicalls = FALSE;
14741 /* The -xgot option tells the assembler to use 32 bit offsets
14742 when accessing the got in SVR4_PIC mode. It is for Irix
14747 #endif /* OBJ_ELF */
14750 g_switch_value = atoi (arg);
14754 /* The -32, -n32 and -64 options are shortcuts for -mabi=32, -mabi=n32
14758 mips_abi = O32_ABI;
14759 /* We silently ignore -32 for non-ELF targets. This greatly
14760 simplifies the construction of the MIPS GAS test cases. */
14767 as_bad (_("-n32 is supported for ELF format only"));
14770 mips_abi = N32_ABI;
14776 as_bad (_("-64 is supported for ELF format only"));
14779 mips_abi = N64_ABI;
14780 if (!support_64bit_objects())
14781 as_fatal (_("No compiled in support for 64 bit object file format"));
14783 #endif /* OBJ_ELF */
14786 file_mips_gp32 = 1;
14790 file_mips_gp32 = 0;
14794 file_mips_fp32 = 1;
14798 file_mips_fp32 = 0;
14801 case OPTION_SINGLE_FLOAT:
14802 file_mips_single_float = 1;
14805 case OPTION_DOUBLE_FLOAT:
14806 file_mips_single_float = 0;
14809 case OPTION_SOFT_FLOAT:
14810 file_mips_soft_float = 1;
14813 case OPTION_HARD_FLOAT:
14814 file_mips_soft_float = 0;
14821 as_bad (_("-mabi is supported for ELF format only"));
14824 if (strcmp (arg, "32") == 0)
14825 mips_abi = O32_ABI;
14826 else if (strcmp (arg, "o64") == 0)
14827 mips_abi = O64_ABI;
14828 else if (strcmp (arg, "n32") == 0)
14829 mips_abi = N32_ABI;
14830 else if (strcmp (arg, "64") == 0)
14832 mips_abi = N64_ABI;
14833 if (! support_64bit_objects())
14834 as_fatal (_("No compiled in support for 64 bit object file "
14837 else if (strcmp (arg, "eabi") == 0)
14838 mips_abi = EABI_ABI;
14841 as_fatal (_("invalid abi -mabi=%s"), arg);
14845 #endif /* OBJ_ELF */
14847 case OPTION_M7000_HILO_FIX:
14848 mips_7000_hilo_fix = TRUE;
14851 case OPTION_MNO_7000_HILO_FIX:
14852 mips_7000_hilo_fix = FALSE;
14856 case OPTION_MDEBUG:
14857 mips_flag_mdebug = TRUE;
14860 case OPTION_NO_MDEBUG:
14861 mips_flag_mdebug = FALSE;
14865 mips_flag_pdr = TRUE;
14868 case OPTION_NO_PDR:
14869 mips_flag_pdr = FALSE;
14872 case OPTION_MVXWORKS_PIC:
14873 mips_pic = VXWORKS_PIC;
14875 #endif /* OBJ_ELF */
14881 mips_fix_loongson2f = mips_fix_loongson2f_nop || mips_fix_loongson2f_jump;
14886 /* Set up globals to generate code for the ISA or processor
14887 described by INFO. */
14890 mips_set_architecture (const struct mips_cpu_info *info)
14894 file_mips_arch = info->cpu;
14895 mips_opts.arch = info->cpu;
14896 mips_opts.isa = info->isa;
14901 /* Likewise for tuning. */
14904 mips_set_tune (const struct mips_cpu_info *info)
14907 mips_tune = info->cpu;
14912 mips_after_parse_args (void)
14914 const struct mips_cpu_info *arch_info = 0;
14915 const struct mips_cpu_info *tune_info = 0;
14917 /* GP relative stuff not working for PE */
14918 if (strncmp (TARGET_OS, "pe", 2) == 0)
14920 if (g_switch_seen && g_switch_value != 0)
14921 as_bad (_("-G not supported in this configuration."));
14922 g_switch_value = 0;
14925 if (mips_abi == NO_ABI)
14926 mips_abi = MIPS_DEFAULT_ABI;
14928 /* The following code determines the architecture and register size.
14929 Similar code was added to GCC 3.3 (see override_options() in
14930 config/mips/mips.c). The GAS and GCC code should be kept in sync
14931 as much as possible. */
14933 if (mips_arch_string != 0)
14934 arch_info = mips_parse_cpu ("-march", mips_arch_string);
14936 if (file_mips_isa != ISA_UNKNOWN)
14938 /* Handle -mipsN. At this point, file_mips_isa contains the
14939 ISA level specified by -mipsN, while arch_info->isa contains
14940 the -march selection (if any). */
14941 if (arch_info != 0)
14943 /* -march takes precedence over -mipsN, since it is more descriptive.
14944 There's no harm in specifying both as long as the ISA levels
14946 if (file_mips_isa != arch_info->isa)
14947 as_bad (_("-%s conflicts with the other architecture options, which imply -%s"),
14948 mips_cpu_info_from_isa (file_mips_isa)->name,
14949 mips_cpu_info_from_isa (arch_info->isa)->name);
14952 arch_info = mips_cpu_info_from_isa (file_mips_isa);
14955 if (arch_info == 0)
14956 arch_info = mips_parse_cpu ("default CPU", MIPS_CPU_STRING_DEFAULT);
14958 if (ABI_NEEDS_64BIT_REGS (mips_abi) && !ISA_HAS_64BIT_REGS (arch_info->isa))
14959 as_bad (_("-march=%s is not compatible with the selected ABI"),
14962 mips_set_architecture (arch_info);
14964 /* Optimize for file_mips_arch, unless -mtune selects a different processor. */
14965 if (mips_tune_string != 0)
14966 tune_info = mips_parse_cpu ("-mtune", mips_tune_string);
14968 if (tune_info == 0)
14969 mips_set_tune (arch_info);
14971 mips_set_tune (tune_info);
14973 if (file_mips_gp32 >= 0)
14975 /* The user specified the size of the integer registers. Make sure
14976 it agrees with the ABI and ISA. */
14977 if (file_mips_gp32 == 0 && !ISA_HAS_64BIT_REGS (mips_opts.isa))
14978 as_bad (_("-mgp64 used with a 32-bit processor"));
14979 else if (file_mips_gp32 == 1 && ABI_NEEDS_64BIT_REGS (mips_abi))
14980 as_bad (_("-mgp32 used with a 64-bit ABI"));
14981 else if (file_mips_gp32 == 0 && ABI_NEEDS_32BIT_REGS (mips_abi))
14982 as_bad (_("-mgp64 used with a 32-bit ABI"));
14986 /* Infer the integer register size from the ABI and processor.
14987 Restrict ourselves to 32-bit registers if that's all the
14988 processor has, or if the ABI cannot handle 64-bit registers. */
14989 file_mips_gp32 = (ABI_NEEDS_32BIT_REGS (mips_abi)
14990 || !ISA_HAS_64BIT_REGS (mips_opts.isa));
14993 switch (file_mips_fp32)
14997 /* No user specified float register size.
14998 ??? GAS treats single-float processors as though they had 64-bit
14999 float registers (although it complains when double-precision
15000 instructions are used). As things stand, saying they have 32-bit
15001 registers would lead to spurious "register must be even" messages.
15002 So here we assume float registers are never smaller than the
15004 if (file_mips_gp32 == 0)
15005 /* 64-bit integer registers implies 64-bit float registers. */
15006 file_mips_fp32 = 0;
15007 else if ((mips_opts.ase_mips3d > 0 || mips_opts.ase_mdmx > 0)
15008 && ISA_HAS_64BIT_FPRS (mips_opts.isa))
15009 /* -mips3d and -mdmx imply 64-bit float registers, if possible. */
15010 file_mips_fp32 = 0;
15012 /* 32-bit float registers. */
15013 file_mips_fp32 = 1;
15016 /* The user specified the size of the float registers. Check if it
15017 agrees with the ABI and ISA. */
15019 if (!ISA_HAS_64BIT_FPRS (mips_opts.isa))
15020 as_bad (_("-mfp64 used with a 32-bit fpu"));
15021 else if (ABI_NEEDS_32BIT_REGS (mips_abi)
15022 && !ISA_HAS_MXHC1 (mips_opts.isa))
15023 as_warn (_("-mfp64 used with a 32-bit ABI"));
15026 if (ABI_NEEDS_64BIT_REGS (mips_abi))
15027 as_warn (_("-mfp32 used with a 64-bit ABI"));
15031 /* End of GCC-shared inference code. */
15033 /* This flag is set when we have a 64-bit capable CPU but use only
15034 32-bit wide registers. Note that EABI does not use it. */
15035 if (ISA_HAS_64BIT_REGS (mips_opts.isa)
15036 && ((mips_abi == NO_ABI && file_mips_gp32 == 1)
15037 || mips_abi == O32_ABI))
15038 mips_32bitmode = 1;
15040 if (mips_opts.isa == ISA_MIPS1 && mips_trap)
15041 as_bad (_("trap exception not supported at ISA 1"));
15043 /* If the selected architecture includes support for ASEs, enable
15044 generation of code for them. */
15045 if (mips_opts.mips16 == -1)
15046 mips_opts.mips16 = (CPU_HAS_MIPS16 (file_mips_arch)) ? 1 : 0;
15047 if (mips_opts.micromips == -1)
15048 mips_opts.micromips = (CPU_HAS_MICROMIPS (file_mips_arch)) ? 1 : 0;
15049 if (mips_opts.ase_mips3d == -1)
15050 mips_opts.ase_mips3d = ((arch_info->flags & MIPS_CPU_ASE_MIPS3D)
15051 && file_mips_fp32 == 0) ? 1 : 0;
15052 if (mips_opts.ase_mips3d && file_mips_fp32 == 1)
15053 as_bad (_("-mfp32 used with -mips3d"));
15055 if (mips_opts.ase_mdmx == -1)
15056 mips_opts.ase_mdmx = ((arch_info->flags & MIPS_CPU_ASE_MDMX)
15057 && file_mips_fp32 == 0) ? 1 : 0;
15058 if (mips_opts.ase_mdmx && file_mips_fp32 == 1)
15059 as_bad (_("-mfp32 used with -mdmx"));
15061 if (mips_opts.ase_smartmips == -1)
15062 mips_opts.ase_smartmips = (arch_info->flags & MIPS_CPU_ASE_SMARTMIPS) ? 1 : 0;
15063 if (mips_opts.ase_smartmips && !ISA_SUPPORTS_SMARTMIPS)
15064 as_warn (_("%s ISA does not support SmartMIPS"),
15065 mips_cpu_info_from_isa (mips_opts.isa)->name);
15067 if (mips_opts.ase_dsp == -1)
15068 mips_opts.ase_dsp = (arch_info->flags & MIPS_CPU_ASE_DSP) ? 1 : 0;
15069 if (mips_opts.ase_dsp && !ISA_SUPPORTS_DSP_ASE)
15070 as_warn (_("%s ISA does not support DSP ASE"),
15071 mips_cpu_info_from_isa (mips_opts.isa)->name);
15073 if (mips_opts.ase_dspr2 == -1)
15075 mips_opts.ase_dspr2 = (arch_info->flags & MIPS_CPU_ASE_DSPR2) ? 1 : 0;
15076 mips_opts.ase_dsp = (arch_info->flags & MIPS_CPU_ASE_DSP) ? 1 : 0;
15078 if (mips_opts.ase_dspr2 && !ISA_SUPPORTS_DSPR2_ASE)
15079 as_warn (_("%s ISA does not support DSP R2 ASE"),
15080 mips_cpu_info_from_isa (mips_opts.isa)->name);
15082 if (mips_opts.ase_mt == -1)
15083 mips_opts.ase_mt = (arch_info->flags & MIPS_CPU_ASE_MT) ? 1 : 0;
15084 if (mips_opts.ase_mt && !ISA_SUPPORTS_MT_ASE)
15085 as_warn (_("%s ISA does not support MT ASE"),
15086 mips_cpu_info_from_isa (mips_opts.isa)->name);
15088 if (mips_opts.ase_mcu == -1)
15089 mips_opts.ase_mcu = (arch_info->flags & MIPS_CPU_ASE_MCU) ? 1 : 0;
15090 if (mips_opts.ase_mcu && !ISA_SUPPORTS_MCU_ASE)
15091 as_warn (_("%s ISA does not support MCU ASE"),
15092 mips_cpu_info_from_isa (mips_opts.isa)->name);
15094 file_mips_isa = mips_opts.isa;
15095 file_ase_mips3d = mips_opts.ase_mips3d;
15096 file_ase_mdmx = mips_opts.ase_mdmx;
15097 file_ase_smartmips = mips_opts.ase_smartmips;
15098 file_ase_dsp = mips_opts.ase_dsp;
15099 file_ase_dspr2 = mips_opts.ase_dspr2;
15100 file_ase_mt = mips_opts.ase_mt;
15101 mips_opts.gp32 = file_mips_gp32;
15102 mips_opts.fp32 = file_mips_fp32;
15103 mips_opts.soft_float = file_mips_soft_float;
15104 mips_opts.single_float = file_mips_single_float;
15106 if (mips_flag_mdebug < 0)
15108 #ifdef OBJ_MAYBE_ECOFF
15109 if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour)
15110 mips_flag_mdebug = 1;
15112 #endif /* OBJ_MAYBE_ECOFF */
15113 mips_flag_mdebug = 0;
15118 mips_init_after_args (void)
15120 /* initialize opcodes */
15121 bfd_mips_num_opcodes = bfd_mips_num_builtin_opcodes;
15122 mips_opcodes = (struct mips_opcode *) mips_builtin_opcodes;
15126 md_pcrel_from (fixS *fixP)
15128 valueT addr = fixP->fx_where + fixP->fx_frag->fr_address;
15129 switch (fixP->fx_r_type)
15131 case BFD_RELOC_MICROMIPS_7_PCREL_S1:
15132 case BFD_RELOC_MICROMIPS_10_PCREL_S1:
15133 /* Return the address of the delay slot. */
15136 case BFD_RELOC_MICROMIPS_16_PCREL_S1:
15137 case BFD_RELOC_MICROMIPS_JMP:
15138 case BFD_RELOC_16_PCREL_S2:
15139 case BFD_RELOC_MIPS_JMP:
15140 /* Return the address of the delay slot. */
15144 /* We have no relocation type for PC relative MIPS16 instructions. */
15145 if (fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != now_seg)
15146 as_bad_where (fixP->fx_file, fixP->fx_line,
15147 _("PC relative MIPS16 instruction references a different section"));
15152 /* This is called before the symbol table is processed. In order to
15153 work with gcc when using mips-tfile, we must keep all local labels.
15154 However, in other cases, we want to discard them. If we were
15155 called with -g, but we didn't see any debugging information, it may
15156 mean that gcc is smuggling debugging information through to
15157 mips-tfile, in which case we must generate all local labels. */
15160 mips_frob_file_before_adjust (void)
15162 #ifndef NO_ECOFF_DEBUGGING
15163 if (ECOFF_DEBUGGING
15165 && ! ecoff_debugging_seen)
15166 flag_keep_locals = 1;
15170 /* Sort any unmatched HI16 and GOT16 relocs so that they immediately precede
15171 the corresponding LO16 reloc. This is called before md_apply_fix and
15172 tc_gen_reloc. Unmatched relocs can only be generated by use of explicit
15173 relocation operators.
15175 For our purposes, a %lo() expression matches a %got() or %hi()
15178 (a) it refers to the same symbol; and
15179 (b) the offset applied in the %lo() expression is no lower than
15180 the offset applied in the %got() or %hi().
15182 (b) allows us to cope with code like:
15185 lh $4,%lo(foo+2)($4)
15187 ...which is legal on RELA targets, and has a well-defined behaviour
15188 if the user knows that adding 2 to "foo" will not induce a carry to
15191 When several %lo()s match a particular %got() or %hi(), we use the
15192 following rules to distinguish them:
15194 (1) %lo()s with smaller offsets are a better match than %lo()s with
15197 (2) %lo()s with no matching %got() or %hi() are better than those
15198 that already have a matching %got() or %hi().
15200 (3) later %lo()s are better than earlier %lo()s.
15202 These rules are applied in order.
15204 (1) means, among other things, that %lo()s with identical offsets are
15205 chosen if they exist.
15207 (2) means that we won't associate several high-part relocations with
15208 the same low-part relocation unless there's no alternative. Having
15209 several high parts for the same low part is a GNU extension; this rule
15210 allows careful users to avoid it.
15212 (3) is purely cosmetic. mips_hi_fixup_list is is in reverse order,
15213 with the last high-part relocation being at the front of the list.
15214 It therefore makes sense to choose the last matching low-part
15215 relocation, all other things being equal. It's also easier
15216 to code that way. */
15219 mips_frob_file (void)
15221 struct mips_hi_fixup *l;
15222 bfd_reloc_code_real_type looking_for_rtype = BFD_RELOC_UNUSED;
15224 for (l = mips_hi_fixup_list; l != NULL; l = l->next)
15226 segment_info_type *seginfo;
15227 bfd_boolean matched_lo_p;
15228 fixS **hi_pos, **lo_pos, **pos;
15230 gas_assert (reloc_needs_lo_p (l->fixp->fx_r_type));
15232 /* If a GOT16 relocation turns out to be against a global symbol,
15233 there isn't supposed to be a matching LO. */
15234 if (got16_reloc_p (l->fixp->fx_r_type)
15235 && !pic_need_relax (l->fixp->fx_addsy, l->seg))
15238 /* Check quickly whether the next fixup happens to be a matching %lo. */
15239 if (fixup_has_matching_lo_p (l->fixp))
15242 seginfo = seg_info (l->seg);
15244 /* Set HI_POS to the position of this relocation in the chain.
15245 Set LO_POS to the position of the chosen low-part relocation.
15246 MATCHED_LO_P is true on entry to the loop if *POS is a low-part
15247 relocation that matches an immediately-preceding high-part
15251 matched_lo_p = FALSE;
15252 looking_for_rtype = matching_lo_reloc (l->fixp->fx_r_type);
15254 for (pos = &seginfo->fix_root; *pos != NULL; pos = &(*pos)->fx_next)
15256 if (*pos == l->fixp)
15259 if ((*pos)->fx_r_type == looking_for_rtype
15260 && symbol_same_p ((*pos)->fx_addsy, l->fixp->fx_addsy)
15261 && (*pos)->fx_offset >= l->fixp->fx_offset
15263 || (*pos)->fx_offset < (*lo_pos)->fx_offset
15265 && (*pos)->fx_offset == (*lo_pos)->fx_offset)))
15268 matched_lo_p = (reloc_needs_lo_p ((*pos)->fx_r_type)
15269 && fixup_has_matching_lo_p (*pos));
15272 /* If we found a match, remove the high-part relocation from its
15273 current position and insert it before the low-part relocation.
15274 Make the offsets match so that fixup_has_matching_lo_p()
15277 We don't warn about unmatched high-part relocations since some
15278 versions of gcc have been known to emit dead "lui ...%hi(...)"
15280 if (lo_pos != NULL)
15282 l->fixp->fx_offset = (*lo_pos)->fx_offset;
15283 if (l->fixp->fx_next != *lo_pos)
15285 *hi_pos = l->fixp->fx_next;
15286 l->fixp->fx_next = *lo_pos;
15293 /* We may have combined relocations without symbols in the N32/N64 ABI.
15294 We have to prevent gas from dropping them. */
15297 mips_force_relocation (fixS *fixp)
15299 if (generic_force_reloc (fixp))
15302 /* We want to keep BFD_RELOC_MICROMIPS_*_PCREL_S1 relocation,
15303 so that the linker relaxation can update targets. */
15304 if (fixp->fx_r_type == BFD_RELOC_MICROMIPS_7_PCREL_S1
15305 || fixp->fx_r_type == BFD_RELOC_MICROMIPS_10_PCREL_S1
15306 || fixp->fx_r_type == BFD_RELOC_MICROMIPS_16_PCREL_S1)
15310 && S_GET_SEGMENT (fixp->fx_addsy) == bfd_abs_section_ptr
15311 && (fixp->fx_r_type == BFD_RELOC_MIPS_SUB
15312 || hi16_reloc_p (fixp->fx_r_type)
15313 || lo16_reloc_p (fixp->fx_r_type)))
15319 /* Apply a fixup to the object file. */
15322 md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
15326 reloc_howto_type *howto;
15328 /* We ignore generic BFD relocations we don't know about. */
15329 howto = bfd_reloc_type_lookup (stdoutput, fixP->fx_r_type);
15333 gas_assert (fixP->fx_size == 2
15334 || fixP->fx_size == 4
15335 || fixP->fx_r_type == BFD_RELOC_16
15336 || fixP->fx_r_type == BFD_RELOC_64
15337 || fixP->fx_r_type == BFD_RELOC_CTOR
15338 || fixP->fx_r_type == BFD_RELOC_MIPS_SUB
15339 || fixP->fx_r_type == BFD_RELOC_MICROMIPS_SUB
15340 || fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
15341 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY
15342 || fixP->fx_r_type == BFD_RELOC_MIPS_TLS_DTPREL64);
15344 buf = (bfd_byte *) (fixP->fx_frag->fr_literal + fixP->fx_where);
15346 gas_assert (!fixP->fx_pcrel || fixP->fx_r_type == BFD_RELOC_16_PCREL_S2
15347 || fixP->fx_r_type == BFD_RELOC_MICROMIPS_7_PCREL_S1
15348 || fixP->fx_r_type == BFD_RELOC_MICROMIPS_10_PCREL_S1
15349 || fixP->fx_r_type == BFD_RELOC_MICROMIPS_16_PCREL_S1);
15351 /* Don't treat parts of a composite relocation as done. There are two
15354 (1) The second and third parts will be against 0 (RSS_UNDEF) but
15355 should nevertheless be emitted if the first part is.
15357 (2) In normal usage, composite relocations are never assembly-time
15358 constants. The easiest way of dealing with the pathological
15359 exceptions is to generate a relocation against STN_UNDEF and
15360 leave everything up to the linker. */
15361 if (fixP->fx_addsy == NULL && !fixP->fx_pcrel && fixP->fx_tcbit == 0)
15364 switch (fixP->fx_r_type)
15366 case BFD_RELOC_MIPS_TLS_GD:
15367 case BFD_RELOC_MIPS_TLS_LDM:
15368 case BFD_RELOC_MIPS_TLS_DTPREL32:
15369 case BFD_RELOC_MIPS_TLS_DTPREL64:
15370 case BFD_RELOC_MIPS_TLS_DTPREL_HI16:
15371 case BFD_RELOC_MIPS_TLS_DTPREL_LO16:
15372 case BFD_RELOC_MIPS_TLS_GOTTPREL:
15373 case BFD_RELOC_MIPS_TLS_TPREL_HI16:
15374 case BFD_RELOC_MIPS_TLS_TPREL_LO16:
15375 case BFD_RELOC_MICROMIPS_TLS_GD:
15376 case BFD_RELOC_MICROMIPS_TLS_LDM:
15377 case BFD_RELOC_MICROMIPS_TLS_DTPREL_HI16:
15378 case BFD_RELOC_MICROMIPS_TLS_DTPREL_LO16:
15379 case BFD_RELOC_MICROMIPS_TLS_GOTTPREL:
15380 case BFD_RELOC_MICROMIPS_TLS_TPREL_HI16:
15381 case BFD_RELOC_MICROMIPS_TLS_TPREL_LO16:
15382 S_SET_THREAD_LOCAL (fixP->fx_addsy);
15385 case BFD_RELOC_MIPS_JMP:
15386 case BFD_RELOC_MIPS_SHIFT5:
15387 case BFD_RELOC_MIPS_SHIFT6:
15388 case BFD_RELOC_MIPS_GOT_DISP:
15389 case BFD_RELOC_MIPS_GOT_PAGE:
15390 case BFD_RELOC_MIPS_GOT_OFST:
15391 case BFD_RELOC_MIPS_SUB:
15392 case BFD_RELOC_MIPS_INSERT_A:
15393 case BFD_RELOC_MIPS_INSERT_B:
15394 case BFD_RELOC_MIPS_DELETE:
15395 case BFD_RELOC_MIPS_HIGHEST:
15396 case BFD_RELOC_MIPS_HIGHER:
15397 case BFD_RELOC_MIPS_SCN_DISP:
15398 case BFD_RELOC_MIPS_REL16:
15399 case BFD_RELOC_MIPS_RELGOT:
15400 case BFD_RELOC_MIPS_JALR:
15401 case BFD_RELOC_HI16:
15402 case BFD_RELOC_HI16_S:
15403 case BFD_RELOC_GPREL16:
15404 case BFD_RELOC_MIPS_LITERAL:
15405 case BFD_RELOC_MIPS_CALL16:
15406 case BFD_RELOC_MIPS_GOT16:
15407 case BFD_RELOC_GPREL32:
15408 case BFD_RELOC_MIPS_GOT_HI16:
15409 case BFD_RELOC_MIPS_GOT_LO16:
15410 case BFD_RELOC_MIPS_CALL_HI16:
15411 case BFD_RELOC_MIPS_CALL_LO16:
15412 case BFD_RELOC_MIPS16_GPREL:
15413 case BFD_RELOC_MIPS16_GOT16:
15414 case BFD_RELOC_MIPS16_CALL16:
15415 case BFD_RELOC_MIPS16_HI16:
15416 case BFD_RELOC_MIPS16_HI16_S:
15417 case BFD_RELOC_MIPS16_JMP:
15418 case BFD_RELOC_MICROMIPS_JMP:
15419 case BFD_RELOC_MICROMIPS_GOT_DISP:
15420 case BFD_RELOC_MICROMIPS_GOT_PAGE:
15421 case BFD_RELOC_MICROMIPS_GOT_OFST:
15422 case BFD_RELOC_MICROMIPS_SUB:
15423 case BFD_RELOC_MICROMIPS_HIGHEST:
15424 case BFD_RELOC_MICROMIPS_HIGHER:
15425 case BFD_RELOC_MICROMIPS_SCN_DISP:
15426 case BFD_RELOC_MICROMIPS_JALR:
15427 case BFD_RELOC_MICROMIPS_HI16:
15428 case BFD_RELOC_MICROMIPS_HI16_S:
15429 case BFD_RELOC_MICROMIPS_GPREL16:
15430 case BFD_RELOC_MICROMIPS_LITERAL:
15431 case BFD_RELOC_MICROMIPS_CALL16:
15432 case BFD_RELOC_MICROMIPS_GOT16:
15433 case BFD_RELOC_MICROMIPS_GOT_HI16:
15434 case BFD_RELOC_MICROMIPS_GOT_LO16:
15435 case BFD_RELOC_MICROMIPS_CALL_HI16:
15436 case BFD_RELOC_MICROMIPS_CALL_LO16:
15437 /* Nothing needed to do. The value comes from the reloc entry. */
15441 /* This is handled like BFD_RELOC_32, but we output a sign
15442 extended value if we are only 32 bits. */
15445 if (8 <= sizeof (valueT))
15446 md_number_to_chars ((char *) buf, *valP, 8);
15451 if ((*valP & 0x80000000) != 0)
15455 md_number_to_chars ((char *)(buf + (target_big_endian ? 4 : 0)),
15457 md_number_to_chars ((char *)(buf + (target_big_endian ? 0 : 4)),
15463 case BFD_RELOC_RVA:
15466 /* If we are deleting this reloc entry, we must fill in the
15467 value now. This can happen if we have a .word which is not
15468 resolved when it appears but is later defined. */
15470 md_number_to_chars ((char *) buf, *valP, fixP->fx_size);
15473 case BFD_RELOC_LO16:
15474 case BFD_RELOC_MIPS16_LO16:
15475 case BFD_RELOC_MICROMIPS_LO16:
15476 /* FIXME: Now that embedded-PIC is gone, some of this code/comment
15477 may be safe to remove, but if so it's not obvious. */
15478 /* When handling an embedded PIC switch statement, we can wind
15479 up deleting a LO16 reloc. See the 'o' case in mips_ip. */
15482 if (*valP + 0x8000 > 0xffff)
15483 as_bad_where (fixP->fx_file, fixP->fx_line,
15484 _("relocation overflow"));
15485 /* 32-bit microMIPS instructions are divided into two halfwords.
15486 Relocations always refer to the second halfword, regardless
15488 if (target_big_endian || fixP->fx_r_type == BFD_RELOC_MICROMIPS_LO16)
15490 md_number_to_chars ((char *) buf, *valP, 2);
15494 case BFD_RELOC_16_PCREL_S2:
15495 if ((*valP & 0x3) != 0)
15496 as_bad_where (fixP->fx_file, fixP->fx_line,
15497 _("Branch to misaligned address (%lx)"), (long) *valP);
15499 /* We need to save the bits in the instruction since fixup_segment()
15500 might be deleting the relocation entry (i.e., a branch within
15501 the current segment). */
15502 if (! fixP->fx_done)
15505 /* Update old instruction data. */
15506 if (target_big_endian)
15507 insn = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
15509 insn = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
15511 if (*valP + 0x20000 <= 0x3ffff)
15513 insn |= (*valP >> 2) & 0xffff;
15514 md_number_to_chars ((char *) buf, insn, 4);
15516 else if (mips_pic == NO_PIC
15518 && fixP->fx_frag->fr_address >= text_section->vma
15519 && (fixP->fx_frag->fr_address
15520 < text_section->vma + bfd_get_section_size (text_section))
15521 && ((insn & 0xffff0000) == 0x10000000 /* beq $0,$0 */
15522 || (insn & 0xffff0000) == 0x04010000 /* bgez $0 */
15523 || (insn & 0xffff0000) == 0x04110000)) /* bgezal $0 */
15525 /* The branch offset is too large. If this is an
15526 unconditional branch, and we are not generating PIC code,
15527 we can convert it to an absolute jump instruction. */
15528 if ((insn & 0xffff0000) == 0x04110000) /* bgezal $0 */
15529 insn = 0x0c000000; /* jal */
15531 insn = 0x08000000; /* j */
15532 fixP->fx_r_type = BFD_RELOC_MIPS_JMP;
15534 fixP->fx_addsy = section_symbol (text_section);
15535 *valP += md_pcrel_from (fixP);
15536 md_number_to_chars ((char *) buf, insn, 4);
15540 /* If we got here, we have branch-relaxation disabled,
15541 and there's nothing we can do to fix this instruction
15542 without turning it into a longer sequence. */
15543 as_bad_where (fixP->fx_file, fixP->fx_line,
15544 _("Branch out of range"));
15548 case BFD_RELOC_MICROMIPS_7_PCREL_S1:
15549 case BFD_RELOC_MICROMIPS_10_PCREL_S1:
15550 case BFD_RELOC_MICROMIPS_16_PCREL_S1:
15551 /* We adjust the offset back to even. */
15552 if ((*valP & 0x1) != 0)
15555 if (! fixP->fx_done)
15558 /* Should never visit here, because we keep the relocation. */
15562 case BFD_RELOC_VTABLE_INHERIT:
15565 && !S_IS_DEFINED (fixP->fx_addsy)
15566 && !S_IS_WEAK (fixP->fx_addsy))
15567 S_SET_WEAK (fixP->fx_addsy);
15570 case BFD_RELOC_VTABLE_ENTRY:
15578 /* Remember value for tc_gen_reloc. */
15579 fixP->fx_addnumber = *valP;
15589 name = input_line_pointer;
15590 c = get_symbol_end ();
15591 p = (symbolS *) symbol_find_or_make (name);
15592 *input_line_pointer = c;
15596 /* Align the current frag to a given power of two. If a particular
15597 fill byte should be used, FILL points to an integer that contains
15598 that byte, otherwise FILL is null.
15600 The MIPS assembler also automatically adjusts any preceding
15604 mips_align (int to, int *fill, symbolS *label)
15606 mips_emit_delays ();
15607 mips_record_compressed_mode ();
15608 if (fill == NULL && subseg_text_p (now_seg))
15609 frag_align_code (to, 0);
15611 frag_align (to, fill ? *fill : 0, 0);
15612 record_alignment (now_seg, to);
15615 gas_assert (S_GET_SEGMENT (label) == now_seg);
15616 symbol_set_frag (label, frag_now);
15617 S_SET_VALUE (label, (valueT) frag_now_fix ());
15621 /* Align to a given power of two. .align 0 turns off the automatic
15622 alignment used by the data creating pseudo-ops. */
15625 s_align (int x ATTRIBUTE_UNUSED)
15627 int temp, fill_value, *fill_ptr;
15628 long max_alignment = 28;
15630 /* o Note that the assembler pulls down any immediately preceding label
15631 to the aligned address.
15632 o It's not documented but auto alignment is reinstated by
15633 a .align pseudo instruction.
15634 o Note also that after auto alignment is turned off the mips assembler
15635 issues an error on attempt to assemble an improperly aligned data item.
15638 temp = get_absolute_expression ();
15639 if (temp > max_alignment)
15640 as_bad (_("Alignment too large: %d. assumed."), temp = max_alignment);
15643 as_warn (_("Alignment negative: 0 assumed."));
15646 if (*input_line_pointer == ',')
15648 ++input_line_pointer;
15649 fill_value = get_absolute_expression ();
15650 fill_ptr = &fill_value;
15656 segment_info_type *si = seg_info (now_seg);
15657 struct insn_label_list *l = si->label_list;
15658 /* Auto alignment should be switched on by next section change. */
15660 mips_align (temp, fill_ptr, l != NULL ? l->label : NULL);
15667 demand_empty_rest_of_line ();
15671 s_change_sec (int sec)
15676 /* The ELF backend needs to know that we are changing sections, so
15677 that .previous works correctly. We could do something like check
15678 for an obj_section_change_hook macro, but that might be confusing
15679 as it would not be appropriate to use it in the section changing
15680 functions in read.c, since obj-elf.c intercepts those. FIXME:
15681 This should be cleaner, somehow. */
15683 obj_elf_section_change_hook ();
15686 mips_emit_delays ();
15697 subseg_set (bss_section, (subsegT) get_absolute_expression ());
15698 demand_empty_rest_of_line ();
15702 seg = subseg_new (RDATA_SECTION_NAME,
15703 (subsegT) get_absolute_expression ());
15706 bfd_set_section_flags (stdoutput, seg, (SEC_ALLOC | SEC_LOAD
15707 | SEC_READONLY | SEC_RELOC
15709 if (strncmp (TARGET_OS, "elf", 3) != 0)
15710 record_alignment (seg, 4);
15712 demand_empty_rest_of_line ();
15716 seg = subseg_new (".sdata", (subsegT) get_absolute_expression ());
15719 bfd_set_section_flags (stdoutput, seg,
15720 SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_DATA);
15721 if (strncmp (TARGET_OS, "elf", 3) != 0)
15722 record_alignment (seg, 4);
15724 demand_empty_rest_of_line ();
15728 seg = subseg_new (".sbss", (subsegT) get_absolute_expression ());
15731 bfd_set_section_flags (stdoutput, seg, SEC_ALLOC);
15732 if (strncmp (TARGET_OS, "elf", 3) != 0)
15733 record_alignment (seg, 4);
15735 demand_empty_rest_of_line ();
15743 s_change_section (int ignore ATTRIBUTE_UNUSED)
15746 char *section_name;
15751 int section_entry_size;
15752 int section_alignment;
15757 section_name = input_line_pointer;
15758 c = get_symbol_end ();
15760 next_c = *(input_line_pointer + 1);
15762 /* Do we have .section Name<,"flags">? */
15763 if (c != ',' || (c == ',' && next_c == '"'))
15765 /* just after name is now '\0'. */
15766 *input_line_pointer = c;
15767 input_line_pointer = section_name;
15768 obj_elf_section (ignore);
15771 input_line_pointer++;
15773 /* Do we have .section Name<,type><,flag><,entry_size><,alignment> */
15775 section_type = get_absolute_expression ();
15778 if (*input_line_pointer++ == ',')
15779 section_flag = get_absolute_expression ();
15782 if (*input_line_pointer++ == ',')
15783 section_entry_size = get_absolute_expression ();
15785 section_entry_size = 0;
15786 if (*input_line_pointer++ == ',')
15787 section_alignment = get_absolute_expression ();
15789 section_alignment = 0;
15790 /* FIXME: really ignore? */
15791 (void) section_alignment;
15793 section_name = xstrdup (section_name);
15795 /* When using the generic form of .section (as implemented by obj-elf.c),
15796 there's no way to set the section type to SHT_MIPS_DWARF. Users have
15797 traditionally had to fall back on the more common @progbits instead.
15799 There's nothing really harmful in this, since bfd will correct
15800 SHT_PROGBITS to SHT_MIPS_DWARF before writing out the file. But it
15801 means that, for backwards compatibility, the special_section entries
15802 for dwarf sections must use SHT_PROGBITS rather than SHT_MIPS_DWARF.
15804 Even so, we shouldn't force users of the MIPS .section syntax to
15805 incorrectly label the sections as SHT_PROGBITS. The best compromise
15806 seems to be to map SHT_MIPS_DWARF to SHT_PROGBITS before calling the
15807 generic type-checking code. */
15808 if (section_type == SHT_MIPS_DWARF)
15809 section_type = SHT_PROGBITS;
15811 obj_elf_change_section (section_name, section_type, section_flag,
15812 section_entry_size, 0, 0, 0);
15814 if (now_seg->name != section_name)
15815 free (section_name);
15816 #endif /* OBJ_ELF */
15820 mips_enable_auto_align (void)
15826 s_cons (int log_size)
15828 segment_info_type *si = seg_info (now_seg);
15829 struct insn_label_list *l = si->label_list;
15832 label = l != NULL ? l->label : NULL;
15833 mips_emit_delays ();
15834 if (log_size > 0 && auto_align)
15835 mips_align (log_size, 0, label);
15836 cons (1 << log_size);
15837 mips_clear_insn_labels ();
15841 s_float_cons (int type)
15843 segment_info_type *si = seg_info (now_seg);
15844 struct insn_label_list *l = si->label_list;
15847 label = l != NULL ? l->label : NULL;
15849 mips_emit_delays ();
15854 mips_align (3, 0, label);
15856 mips_align (2, 0, label);
15860 mips_clear_insn_labels ();
15863 /* Handle .globl. We need to override it because on Irix 5 you are
15866 where foo is an undefined symbol, to mean that foo should be
15867 considered to be the address of a function. */
15870 s_mips_globl (int x ATTRIBUTE_UNUSED)
15879 name = input_line_pointer;
15880 c = get_symbol_end ();
15881 symbolP = symbol_find_or_make (name);
15882 S_SET_EXTERNAL (symbolP);
15884 *input_line_pointer = c;
15885 SKIP_WHITESPACE ();
15887 /* On Irix 5, every global symbol that is not explicitly labelled as
15888 being a function is apparently labelled as being an object. */
15891 if (!is_end_of_line[(unsigned char) *input_line_pointer]
15892 && (*input_line_pointer != ','))
15897 secname = input_line_pointer;
15898 c = get_symbol_end ();
15899 sec = bfd_get_section_by_name (stdoutput, secname);
15901 as_bad (_("%s: no such section"), secname);
15902 *input_line_pointer = c;
15904 if (sec != NULL && (sec->flags & SEC_CODE) != 0)
15905 flag = BSF_FUNCTION;
15908 symbol_get_bfdsym (symbolP)->flags |= flag;
15910 c = *input_line_pointer;
15913 input_line_pointer++;
15914 SKIP_WHITESPACE ();
15915 if (is_end_of_line[(unsigned char) *input_line_pointer])
15921 demand_empty_rest_of_line ();
15925 s_option (int x ATTRIBUTE_UNUSED)
15930 opt = input_line_pointer;
15931 c = get_symbol_end ();
15935 /* FIXME: What does this mean? */
15937 else if (strncmp (opt, "pic", 3) == 0)
15941 i = atoi (opt + 3);
15946 mips_pic = SVR4_PIC;
15947 mips_abicalls = TRUE;
15950 as_bad (_(".option pic%d not supported"), i);
15952 if (mips_pic == SVR4_PIC)
15954 if (g_switch_seen && g_switch_value != 0)
15955 as_warn (_("-G may not be used with SVR4 PIC code"));
15956 g_switch_value = 0;
15957 bfd_set_gp_size (stdoutput, 0);
15961 as_warn (_("Unrecognized option \"%s\""), opt);
15963 *input_line_pointer = c;
15964 demand_empty_rest_of_line ();
15967 /* This structure is used to hold a stack of .set values. */
15969 struct mips_option_stack
15971 struct mips_option_stack *next;
15972 struct mips_set_options options;
15975 static struct mips_option_stack *mips_opts_stack;
15977 /* Handle the .set pseudo-op. */
15980 s_mipsset (int x ATTRIBUTE_UNUSED)
15982 char *name = input_line_pointer, ch;
15984 while (!is_end_of_line[(unsigned char) *input_line_pointer])
15985 ++input_line_pointer;
15986 ch = *input_line_pointer;
15987 *input_line_pointer = '\0';
15989 if (strcmp (name, "reorder") == 0)
15991 if (mips_opts.noreorder)
15994 else if (strcmp (name, "noreorder") == 0)
15996 if (!mips_opts.noreorder)
15997 start_noreorder ();
15999 else if (strncmp (name, "at=", 3) == 0)
16001 char *s = name + 3;
16003 if (!reg_lookup (&s, RTYPE_NUM | RTYPE_GP, &mips_opts.at))
16004 as_bad (_("Unrecognized register name `%s'"), s);
16006 else if (strcmp (name, "at") == 0)
16008 mips_opts.at = ATREG;
16010 else if (strcmp (name, "noat") == 0)
16012 mips_opts.at = ZERO;
16014 else if (strcmp (name, "macro") == 0)
16016 mips_opts.warn_about_macros = 0;
16018 else if (strcmp (name, "nomacro") == 0)
16020 if (mips_opts.noreorder == 0)
16021 as_bad (_("`noreorder' must be set before `nomacro'"));
16022 mips_opts.warn_about_macros = 1;
16024 else if (strcmp (name, "move") == 0 || strcmp (name, "novolatile") == 0)
16026 mips_opts.nomove = 0;
16028 else if (strcmp (name, "nomove") == 0 || strcmp (name, "volatile") == 0)
16030 mips_opts.nomove = 1;
16032 else if (strcmp (name, "bopt") == 0)
16034 mips_opts.nobopt = 0;
16036 else if (strcmp (name, "nobopt") == 0)
16038 mips_opts.nobopt = 1;
16040 else if (strcmp (name, "gp=default") == 0)
16041 mips_opts.gp32 = file_mips_gp32;
16042 else if (strcmp (name, "gp=32") == 0)
16043 mips_opts.gp32 = 1;
16044 else if (strcmp (name, "gp=64") == 0)
16046 if (!ISA_HAS_64BIT_REGS (mips_opts.isa))
16047 as_warn (_("%s isa does not support 64-bit registers"),
16048 mips_cpu_info_from_isa (mips_opts.isa)->name);
16049 mips_opts.gp32 = 0;
16051 else if (strcmp (name, "fp=default") == 0)
16052 mips_opts.fp32 = file_mips_fp32;
16053 else if (strcmp (name, "fp=32") == 0)
16054 mips_opts.fp32 = 1;
16055 else if (strcmp (name, "fp=64") == 0)
16057 if (!ISA_HAS_64BIT_FPRS (mips_opts.isa))
16058 as_warn (_("%s isa does not support 64-bit floating point registers"),
16059 mips_cpu_info_from_isa (mips_opts.isa)->name);
16060 mips_opts.fp32 = 0;
16062 else if (strcmp (name, "softfloat") == 0)
16063 mips_opts.soft_float = 1;
16064 else if (strcmp (name, "hardfloat") == 0)
16065 mips_opts.soft_float = 0;
16066 else if (strcmp (name, "singlefloat") == 0)
16067 mips_opts.single_float = 1;
16068 else if (strcmp (name, "doublefloat") == 0)
16069 mips_opts.single_float = 0;
16070 else if (strcmp (name, "mips16") == 0
16071 || strcmp (name, "MIPS-16") == 0)
16073 if (mips_opts.micromips == 1)
16074 as_fatal (_("`mips16' cannot be used with `micromips'"));
16075 mips_opts.mips16 = 1;
16077 else if (strcmp (name, "nomips16") == 0
16078 || strcmp (name, "noMIPS-16") == 0)
16079 mips_opts.mips16 = 0;
16080 else if (strcmp (name, "micromips") == 0)
16082 if (mips_opts.mips16 == 1)
16083 as_fatal (_("`micromips' cannot be used with `mips16'"));
16084 mips_opts.micromips = 1;
16086 else if (strcmp (name, "nomicromips") == 0)
16087 mips_opts.micromips = 0;
16088 else if (strcmp (name, "smartmips") == 0)
16090 if (!ISA_SUPPORTS_SMARTMIPS)
16091 as_warn (_("%s ISA does not support SmartMIPS ASE"),
16092 mips_cpu_info_from_isa (mips_opts.isa)->name);
16093 mips_opts.ase_smartmips = 1;
16095 else if (strcmp (name, "nosmartmips") == 0)
16096 mips_opts.ase_smartmips = 0;
16097 else if (strcmp (name, "mips3d") == 0)
16098 mips_opts.ase_mips3d = 1;
16099 else if (strcmp (name, "nomips3d") == 0)
16100 mips_opts.ase_mips3d = 0;
16101 else if (strcmp (name, "mdmx") == 0)
16102 mips_opts.ase_mdmx = 1;
16103 else if (strcmp (name, "nomdmx") == 0)
16104 mips_opts.ase_mdmx = 0;
16105 else if (strcmp (name, "dsp") == 0)
16107 if (!ISA_SUPPORTS_DSP_ASE)
16108 as_warn (_("%s ISA does not support DSP ASE"),
16109 mips_cpu_info_from_isa (mips_opts.isa)->name);
16110 mips_opts.ase_dsp = 1;
16111 mips_opts.ase_dspr2 = 0;
16113 else if (strcmp (name, "nodsp") == 0)
16115 mips_opts.ase_dsp = 0;
16116 mips_opts.ase_dspr2 = 0;
16118 else if (strcmp (name, "dspr2") == 0)
16120 if (!ISA_SUPPORTS_DSPR2_ASE)
16121 as_warn (_("%s ISA does not support DSP R2 ASE"),
16122 mips_cpu_info_from_isa (mips_opts.isa)->name);
16123 mips_opts.ase_dspr2 = 1;
16124 mips_opts.ase_dsp = 1;
16126 else if (strcmp (name, "nodspr2") == 0)
16128 mips_opts.ase_dspr2 = 0;
16129 mips_opts.ase_dsp = 0;
16131 else if (strcmp (name, "mt") == 0)
16133 if (!ISA_SUPPORTS_MT_ASE)
16134 as_warn (_("%s ISA does not support MT ASE"),
16135 mips_cpu_info_from_isa (mips_opts.isa)->name);
16136 mips_opts.ase_mt = 1;
16138 else if (strcmp (name, "nomt") == 0)
16139 mips_opts.ase_mt = 0;
16140 else if (strcmp (name, "mcu") == 0)
16141 mips_opts.ase_mcu = 1;
16142 else if (strcmp (name, "nomcu") == 0)
16143 mips_opts.ase_mcu = 0;
16144 else if (strncmp (name, "mips", 4) == 0 || strncmp (name, "arch=", 5) == 0)
16148 /* Permit the user to change the ISA and architecture on the fly.
16149 Needless to say, misuse can cause serious problems. */
16150 if (strcmp (name, "mips0") == 0 || strcmp (name, "arch=default") == 0)
16153 mips_opts.isa = file_mips_isa;
16154 mips_opts.arch = file_mips_arch;
16156 else if (strncmp (name, "arch=", 5) == 0)
16158 const struct mips_cpu_info *p;
16160 p = mips_parse_cpu("internal use", name + 5);
16162 as_bad (_("unknown architecture %s"), name + 5);
16165 mips_opts.arch = p->cpu;
16166 mips_opts.isa = p->isa;
16169 else if (strncmp (name, "mips", 4) == 0)
16171 const struct mips_cpu_info *p;
16173 p = mips_parse_cpu("internal use", name);
16175 as_bad (_("unknown ISA level %s"), name + 4);
16178 mips_opts.arch = p->cpu;
16179 mips_opts.isa = p->isa;
16183 as_bad (_("unknown ISA or architecture %s"), name);
16185 switch (mips_opts.isa)
16193 mips_opts.gp32 = 1;
16194 mips_opts.fp32 = 1;
16201 mips_opts.gp32 = 0;
16202 mips_opts.fp32 = 0;
16205 as_bad (_("unknown ISA level %s"), name + 4);
16210 mips_opts.gp32 = file_mips_gp32;
16211 mips_opts.fp32 = file_mips_fp32;
16214 else if (strcmp (name, "autoextend") == 0)
16215 mips_opts.noautoextend = 0;
16216 else if (strcmp (name, "noautoextend") == 0)
16217 mips_opts.noautoextend = 1;
16218 else if (strcmp (name, "push") == 0)
16220 struct mips_option_stack *s;
16222 s = (struct mips_option_stack *) xmalloc (sizeof *s);
16223 s->next = mips_opts_stack;
16224 s->options = mips_opts;
16225 mips_opts_stack = s;
16227 else if (strcmp (name, "pop") == 0)
16229 struct mips_option_stack *s;
16231 s = mips_opts_stack;
16233 as_bad (_(".set pop with no .set push"));
16236 /* If we're changing the reorder mode we need to handle
16237 delay slots correctly. */
16238 if (s->options.noreorder && ! mips_opts.noreorder)
16239 start_noreorder ();
16240 else if (! s->options.noreorder && mips_opts.noreorder)
16243 mips_opts = s->options;
16244 mips_opts_stack = s->next;
16248 else if (strcmp (name, "sym32") == 0)
16249 mips_opts.sym32 = TRUE;
16250 else if (strcmp (name, "nosym32") == 0)
16251 mips_opts.sym32 = FALSE;
16252 else if (strchr (name, ','))
16254 /* Generic ".set" directive; use the generic handler. */
16255 *input_line_pointer = ch;
16256 input_line_pointer = name;
16262 as_warn (_("Tried to set unrecognized symbol: %s\n"), name);
16264 *input_line_pointer = ch;
16265 demand_empty_rest_of_line ();
16268 /* Handle the .abicalls pseudo-op. I believe this is equivalent to
16269 .option pic2. It means to generate SVR4 PIC calls. */
16272 s_abicalls (int ignore ATTRIBUTE_UNUSED)
16274 mips_pic = SVR4_PIC;
16275 mips_abicalls = TRUE;
16277 if (g_switch_seen && g_switch_value != 0)
16278 as_warn (_("-G may not be used with SVR4 PIC code"));
16279 g_switch_value = 0;
16281 bfd_set_gp_size (stdoutput, 0);
16282 demand_empty_rest_of_line ();
16285 /* Handle the .cpload pseudo-op. This is used when generating SVR4
16286 PIC code. It sets the $gp register for the function based on the
16287 function address, which is in the register named in the argument.
16288 This uses a relocation against _gp_disp, which is handled specially
16289 by the linker. The result is:
16290 lui $gp,%hi(_gp_disp)
16291 addiu $gp,$gp,%lo(_gp_disp)
16292 addu $gp,$gp,.cpload argument
16293 The .cpload argument is normally $25 == $t9.
16295 The -mno-shared option changes this to:
16296 lui $gp,%hi(__gnu_local_gp)
16297 addiu $gp,$gp,%lo(__gnu_local_gp)
16298 and the argument is ignored. This saves an instruction, but the
16299 resulting code is not position independent; it uses an absolute
16300 address for __gnu_local_gp. Thus code assembled with -mno-shared
16301 can go into an ordinary executable, but not into a shared library. */
16304 s_cpload (int ignore ATTRIBUTE_UNUSED)
16310 /* If we are not generating SVR4 PIC code, or if this is NewABI code,
16311 .cpload is ignored. */
16312 if (mips_pic != SVR4_PIC || HAVE_NEWABI)
16318 /* .cpload should be in a .set noreorder section. */
16319 if (mips_opts.noreorder == 0)
16320 as_warn (_(".cpload not in noreorder section"));
16322 reg = tc_get_register (0);
16324 /* If we need to produce a 64-bit address, we are better off using
16325 the default instruction sequence. */
16326 in_shared = mips_in_shared || HAVE_64BIT_SYMBOLS;
16328 ex.X_op = O_symbol;
16329 ex.X_add_symbol = symbol_find_or_make (in_shared ? "_gp_disp" :
16331 ex.X_op_symbol = NULL;
16332 ex.X_add_number = 0;
16334 /* In ELF, this symbol is implicitly an STT_OBJECT symbol. */
16335 symbol_get_bfdsym (ex.X_add_symbol)->flags |= BSF_OBJECT;
16338 macro_build_lui (&ex, mips_gp_register);
16339 macro_build (&ex, "addiu", "t,r,j", mips_gp_register,
16340 mips_gp_register, BFD_RELOC_LO16);
16342 macro_build (NULL, "addu", "d,v,t", mips_gp_register,
16343 mips_gp_register, reg);
16346 demand_empty_rest_of_line ();
16349 /* Handle the .cpsetup pseudo-op defined for NewABI PIC code. The syntax is:
16350 .cpsetup $reg1, offset|$reg2, label
16352 If offset is given, this results in:
16353 sd $gp, offset($sp)
16354 lui $gp, %hi(%neg(%gp_rel(label)))
16355 addiu $gp, $gp, %lo(%neg(%gp_rel(label)))
16356 daddu $gp, $gp, $reg1
16358 If $reg2 is given, this results in:
16359 daddu $reg2, $gp, $0
16360 lui $gp, %hi(%neg(%gp_rel(label)))
16361 addiu $gp, $gp, %lo(%neg(%gp_rel(label)))
16362 daddu $gp, $gp, $reg1
16363 $reg1 is normally $25 == $t9.
16365 The -mno-shared option replaces the last three instructions with
16367 addiu $gp,$gp,%lo(_gp) */
16370 s_cpsetup (int ignore ATTRIBUTE_UNUSED)
16372 expressionS ex_off;
16373 expressionS ex_sym;
16376 /* If we are not generating SVR4 PIC code, .cpsetup is ignored.
16377 We also need NewABI support. */
16378 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
16384 reg1 = tc_get_register (0);
16385 SKIP_WHITESPACE ();
16386 if (*input_line_pointer != ',')
16388 as_bad (_("missing argument separator ',' for .cpsetup"));
16392 ++input_line_pointer;
16393 SKIP_WHITESPACE ();
16394 if (*input_line_pointer == '$')
16396 mips_cpreturn_register = tc_get_register (0);
16397 mips_cpreturn_offset = -1;
16401 mips_cpreturn_offset = get_absolute_expression ();
16402 mips_cpreturn_register = -1;
16404 SKIP_WHITESPACE ();
16405 if (*input_line_pointer != ',')
16407 as_bad (_("missing argument separator ',' for .cpsetup"));
16411 ++input_line_pointer;
16412 SKIP_WHITESPACE ();
16413 expression (&ex_sym);
16416 if (mips_cpreturn_register == -1)
16418 ex_off.X_op = O_constant;
16419 ex_off.X_add_symbol = NULL;
16420 ex_off.X_op_symbol = NULL;
16421 ex_off.X_add_number = mips_cpreturn_offset;
16423 macro_build (&ex_off, "sd", "t,o(b)", mips_gp_register,
16424 BFD_RELOC_LO16, SP);
16427 macro_build (NULL, "daddu", "d,v,t", mips_cpreturn_register,
16428 mips_gp_register, 0);
16430 if (mips_in_shared || HAVE_64BIT_SYMBOLS)
16432 macro_build (&ex_sym, "lui", LUI_FMT, mips_gp_register,
16433 -1, BFD_RELOC_GPREL16, BFD_RELOC_MIPS_SUB,
16436 macro_build (&ex_sym, "addiu", "t,r,j", mips_gp_register,
16437 mips_gp_register, -1, BFD_RELOC_GPREL16,
16438 BFD_RELOC_MIPS_SUB, BFD_RELOC_LO16);
16440 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", mips_gp_register,
16441 mips_gp_register, reg1);
16447 ex.X_op = O_symbol;
16448 ex.X_add_symbol = symbol_find_or_make ("__gnu_local_gp");
16449 ex.X_op_symbol = NULL;
16450 ex.X_add_number = 0;
16452 /* In ELF, this symbol is implicitly an STT_OBJECT symbol. */
16453 symbol_get_bfdsym (ex.X_add_symbol)->flags |= BSF_OBJECT;
16455 macro_build_lui (&ex, mips_gp_register);
16456 macro_build (&ex, "addiu", "t,r,j", mips_gp_register,
16457 mips_gp_register, BFD_RELOC_LO16);
16462 demand_empty_rest_of_line ();
16466 s_cplocal (int ignore ATTRIBUTE_UNUSED)
16468 /* If we are not generating SVR4 PIC code, or if this is not NewABI code,
16469 .cplocal is ignored. */
16470 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
16476 mips_gp_register = tc_get_register (0);
16477 demand_empty_rest_of_line ();
16480 /* Handle the .cprestore pseudo-op. This stores $gp into a given
16481 offset from $sp. The offset is remembered, and after making a PIC
16482 call $gp is restored from that location. */
16485 s_cprestore (int ignore ATTRIBUTE_UNUSED)
16489 /* If we are not generating SVR4 PIC code, or if this is NewABI code,
16490 .cprestore is ignored. */
16491 if (mips_pic != SVR4_PIC || HAVE_NEWABI)
16497 mips_cprestore_offset = get_absolute_expression ();
16498 mips_cprestore_valid = 1;
16500 ex.X_op = O_constant;
16501 ex.X_add_symbol = NULL;
16502 ex.X_op_symbol = NULL;
16503 ex.X_add_number = mips_cprestore_offset;
16506 macro_build_ldst_constoffset (&ex, ADDRESS_STORE_INSN, mips_gp_register,
16507 SP, HAVE_64BIT_ADDRESSES);
16510 demand_empty_rest_of_line ();
16513 /* Handle the .cpreturn pseudo-op defined for NewABI PIC code. If an offset
16514 was given in the preceding .cpsetup, it results in:
16515 ld $gp, offset($sp)
16517 If a register $reg2 was given there, it results in:
16518 daddu $gp, $reg2, $0 */
16521 s_cpreturn (int ignore ATTRIBUTE_UNUSED)
16525 /* If we are not generating SVR4 PIC code, .cpreturn is ignored.
16526 We also need NewABI support. */
16527 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
16534 if (mips_cpreturn_register == -1)
16536 ex.X_op = O_constant;
16537 ex.X_add_symbol = NULL;
16538 ex.X_op_symbol = NULL;
16539 ex.X_add_number = mips_cpreturn_offset;
16541 macro_build (&ex, "ld", "t,o(b)", mips_gp_register, BFD_RELOC_LO16, SP);
16544 macro_build (NULL, "daddu", "d,v,t", mips_gp_register,
16545 mips_cpreturn_register, 0);
16548 demand_empty_rest_of_line ();
16551 /* Handle the .dtprelword and .dtpreldword pseudo-ops. They generate
16552 a 32-bit or 64-bit DTP-relative relocation (BYTES says which) for
16553 use in DWARF debug information. */
16556 s_dtprel_internal (size_t bytes)
16563 if (ex.X_op != O_symbol)
16565 as_bad (_("Unsupported use of %s"), (bytes == 8
16568 ignore_rest_of_line ();
16571 p = frag_more (bytes);
16572 md_number_to_chars (p, 0, bytes);
16573 fix_new_exp (frag_now, p - frag_now->fr_literal, bytes, &ex, FALSE,
16575 ? BFD_RELOC_MIPS_TLS_DTPREL64
16576 : BFD_RELOC_MIPS_TLS_DTPREL32));
16578 demand_empty_rest_of_line ();
16581 /* Handle .dtprelword. */
16584 s_dtprelword (int ignore ATTRIBUTE_UNUSED)
16586 s_dtprel_internal (4);
16589 /* Handle .dtpreldword. */
16592 s_dtpreldword (int ignore ATTRIBUTE_UNUSED)
16594 s_dtprel_internal (8);
16597 /* Handle the .gpvalue pseudo-op. This is used when generating NewABI PIC
16598 code. It sets the offset to use in gp_rel relocations. */
16601 s_gpvalue (int ignore ATTRIBUTE_UNUSED)
16603 /* If we are not generating SVR4 PIC code, .gpvalue is ignored.
16604 We also need NewABI support. */
16605 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
16611 mips_gprel_offset = get_absolute_expression ();
16613 demand_empty_rest_of_line ();
16616 /* Handle the .gpword pseudo-op. This is used when generating PIC
16617 code. It generates a 32 bit GP relative reloc. */
16620 s_gpword (int ignore ATTRIBUTE_UNUSED)
16622 segment_info_type *si;
16623 struct insn_label_list *l;
16628 /* When not generating PIC code, this is treated as .word. */
16629 if (mips_pic != SVR4_PIC)
16635 si = seg_info (now_seg);
16636 l = si->label_list;
16637 label = l != NULL ? l->label : NULL;
16638 mips_emit_delays ();
16640 mips_align (2, 0, label);
16643 mips_clear_insn_labels ();
16645 if (ex.X_op != O_symbol || ex.X_add_number != 0)
16647 as_bad (_("Unsupported use of .gpword"));
16648 ignore_rest_of_line ();
16652 md_number_to_chars (p, 0, 4);
16653 fix_new_exp (frag_now, p - frag_now->fr_literal, 4, &ex, FALSE,
16654 BFD_RELOC_GPREL32);
16656 demand_empty_rest_of_line ();
16660 s_gpdword (int ignore ATTRIBUTE_UNUSED)
16662 segment_info_type *si;
16663 struct insn_label_list *l;
16668 /* When not generating PIC code, this is treated as .dword. */
16669 if (mips_pic != SVR4_PIC)
16675 si = seg_info (now_seg);
16676 l = si->label_list;
16677 label = l != NULL ? l->label : NULL;
16678 mips_emit_delays ();
16680 mips_align (3, 0, label);
16683 mips_clear_insn_labels ();
16685 if (ex.X_op != O_symbol || ex.X_add_number != 0)
16687 as_bad (_("Unsupported use of .gpdword"));
16688 ignore_rest_of_line ();
16692 md_number_to_chars (p, 0, 8);
16693 fix_new_exp (frag_now, p - frag_now->fr_literal, 4, &ex, FALSE,
16694 BFD_RELOC_GPREL32)->fx_tcbit = 1;
16696 /* GPREL32 composed with 64 gives a 64-bit GP offset. */
16697 fix_new (frag_now, p - frag_now->fr_literal, 8, NULL, 0,
16698 FALSE, BFD_RELOC_64)->fx_tcbit = 1;
16700 demand_empty_rest_of_line ();
16703 /* Handle the .cpadd pseudo-op. This is used when dealing with switch
16704 tables in SVR4 PIC code. */
16707 s_cpadd (int ignore ATTRIBUTE_UNUSED)
16711 /* This is ignored when not generating SVR4 PIC code. */
16712 if (mips_pic != SVR4_PIC)
16718 /* Add $gp to the register named as an argument. */
16720 reg = tc_get_register (0);
16721 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", reg, reg, mips_gp_register);
16724 demand_empty_rest_of_line ();
16727 /* Handle the .insn pseudo-op. This marks instruction labels in
16728 mips16/micromips mode. This permits the linker to handle them specially,
16729 such as generating jalx instructions when needed. We also make
16730 them odd for the duration of the assembly, in order to generate the
16731 right sort of code. We will make them even in the adjust_symtab
16732 routine, while leaving them marked. This is convenient for the
16733 debugger and the disassembler. The linker knows to make them odd
16737 s_insn (int ignore ATTRIBUTE_UNUSED)
16739 mips_mark_labels ();
16741 demand_empty_rest_of_line ();
16744 /* Handle a .stabn directive. We need these in order to mark a label
16745 as being a mips16 text label correctly. Sometimes the compiler
16746 will emit a label, followed by a .stabn, and then switch sections.
16747 If the label and .stabn are in mips16 mode, then the label is
16748 really a mips16 text label. */
16751 s_mips_stab (int type)
16754 mips_mark_labels ();
16759 /* Handle the .weakext pseudo-op as defined in Kane and Heinrich. */
16762 s_mips_weakext (int ignore ATTRIBUTE_UNUSED)
16769 name = input_line_pointer;
16770 c = get_symbol_end ();
16771 symbolP = symbol_find_or_make (name);
16772 S_SET_WEAK (symbolP);
16773 *input_line_pointer = c;
16775 SKIP_WHITESPACE ();
16777 if (! is_end_of_line[(unsigned char) *input_line_pointer])
16779 if (S_IS_DEFINED (symbolP))
16781 as_bad (_("ignoring attempt to redefine symbol %s"),
16782 S_GET_NAME (symbolP));
16783 ignore_rest_of_line ();
16787 if (*input_line_pointer == ',')
16789 ++input_line_pointer;
16790 SKIP_WHITESPACE ();
16794 if (exp.X_op != O_symbol)
16796 as_bad (_("bad .weakext directive"));
16797 ignore_rest_of_line ();
16800 symbol_set_value_expression (symbolP, &exp);
16803 demand_empty_rest_of_line ();
16806 /* Parse a register string into a number. Called from the ECOFF code
16807 to parse .frame. The argument is non-zero if this is the frame
16808 register, so that we can record it in mips_frame_reg. */
16811 tc_get_register (int frame)
16815 SKIP_WHITESPACE ();
16816 if (! reg_lookup (&input_line_pointer, RWARN | RTYPE_NUM | RTYPE_GP, ®))
16820 mips_frame_reg = reg != 0 ? reg : SP;
16821 mips_frame_reg_valid = 1;
16822 mips_cprestore_valid = 0;
16828 md_section_align (asection *seg, valueT addr)
16830 int align = bfd_get_section_alignment (stdoutput, seg);
16834 /* We don't need to align ELF sections to the full alignment.
16835 However, Irix 5 may prefer that we align them at least to a 16
16836 byte boundary. We don't bother to align the sections if we
16837 are targeted for an embedded system. */
16838 if (strncmp (TARGET_OS, "elf", 3) == 0)
16844 return ((addr + (1 << align) - 1) & (-1 << align));
16847 /* Utility routine, called from above as well. If called while the
16848 input file is still being read, it's only an approximation. (For
16849 example, a symbol may later become defined which appeared to be
16850 undefined earlier.) */
16853 nopic_need_relax (symbolS *sym, int before_relaxing)
16858 if (g_switch_value > 0)
16860 const char *symname;
16863 /* Find out whether this symbol can be referenced off the $gp
16864 register. It can be if it is smaller than the -G size or if
16865 it is in the .sdata or .sbss section. Certain symbols can
16866 not be referenced off the $gp, although it appears as though
16868 symname = S_GET_NAME (sym);
16869 if (symname != (const char *) NULL
16870 && (strcmp (symname, "eprol") == 0
16871 || strcmp (symname, "etext") == 0
16872 || strcmp (symname, "_gp") == 0
16873 || strcmp (symname, "edata") == 0
16874 || strcmp (symname, "_fbss") == 0
16875 || strcmp (symname, "_fdata") == 0
16876 || strcmp (symname, "_ftext") == 0
16877 || strcmp (symname, "end") == 0
16878 || strcmp (symname, "_gp_disp") == 0))
16880 else if ((! S_IS_DEFINED (sym) || S_IS_COMMON (sym))
16882 #ifndef NO_ECOFF_DEBUGGING
16883 || (symbol_get_obj (sym)->ecoff_extern_size != 0
16884 && (symbol_get_obj (sym)->ecoff_extern_size
16885 <= g_switch_value))
16887 /* We must defer this decision until after the whole
16888 file has been read, since there might be a .extern
16889 after the first use of this symbol. */
16890 || (before_relaxing
16891 #ifndef NO_ECOFF_DEBUGGING
16892 && symbol_get_obj (sym)->ecoff_extern_size == 0
16894 && S_GET_VALUE (sym) == 0)
16895 || (S_GET_VALUE (sym) != 0
16896 && S_GET_VALUE (sym) <= g_switch_value)))
16900 const char *segname;
16902 segname = segment_name (S_GET_SEGMENT (sym));
16903 gas_assert (strcmp (segname, ".lit8") != 0
16904 && strcmp (segname, ".lit4") != 0);
16905 change = (strcmp (segname, ".sdata") != 0
16906 && strcmp (segname, ".sbss") != 0
16907 && strncmp (segname, ".sdata.", 7) != 0
16908 && strncmp (segname, ".sbss.", 6) != 0
16909 && strncmp (segname, ".gnu.linkonce.sb.", 17) != 0
16910 && strncmp (segname, ".gnu.linkonce.s.", 16) != 0);
16915 /* We are not optimizing for the $gp register. */
16920 /* Return true if the given symbol should be considered local for SVR4 PIC. */
16923 pic_need_relax (symbolS *sym, asection *segtype)
16927 /* Handle the case of a symbol equated to another symbol. */
16928 while (symbol_equated_reloc_p (sym))
16932 /* It's possible to get a loop here in a badly written program. */
16933 n = symbol_get_value_expression (sym)->X_add_symbol;
16939 if (symbol_section_p (sym))
16942 symsec = S_GET_SEGMENT (sym);
16944 /* This must duplicate the test in adjust_reloc_syms. */
16945 return (symsec != &bfd_und_section
16946 && symsec != &bfd_abs_section
16947 && !bfd_is_com_section (symsec)
16948 && !s_is_linkonce (sym, segtype)
16950 /* A global or weak symbol is treated as external. */
16951 && (!IS_ELF || (! S_IS_WEAK (sym) && ! S_IS_EXTERNAL (sym)))
16957 /* Given a mips16 variant frag FRAGP, return non-zero if it needs an
16958 extended opcode. SEC is the section the frag is in. */
16961 mips16_extended_frag (fragS *fragp, asection *sec, long stretch)
16964 const struct mips16_immed_operand *op;
16966 int mintiny, maxtiny;
16970 if (RELAX_MIPS16_USER_SMALL (fragp->fr_subtype))
16972 if (RELAX_MIPS16_USER_EXT (fragp->fr_subtype))
16975 type = RELAX_MIPS16_TYPE (fragp->fr_subtype);
16976 op = mips16_immed_operands;
16977 while (op->type != type)
16980 gas_assert (op < mips16_immed_operands + MIPS16_NUM_IMMED);
16985 if (type == '<' || type == '>' || type == '[' || type == ']')
16988 maxtiny = 1 << op->nbits;
16993 maxtiny = (1 << op->nbits) - 1;
16998 mintiny = - (1 << (op->nbits - 1));
16999 maxtiny = (1 << (op->nbits - 1)) - 1;
17002 sym_frag = symbol_get_frag (fragp->fr_symbol);
17003 val = S_GET_VALUE (fragp->fr_symbol);
17004 symsec = S_GET_SEGMENT (fragp->fr_symbol);
17010 /* We won't have the section when we are called from
17011 mips_relax_frag. However, we will always have been called
17012 from md_estimate_size_before_relax first. If this is a
17013 branch to a different section, we mark it as such. If SEC is
17014 NULL, and the frag is not marked, then it must be a branch to
17015 the same section. */
17018 if (RELAX_MIPS16_LONG_BRANCH (fragp->fr_subtype))
17023 /* Must have been called from md_estimate_size_before_relax. */
17026 fragp->fr_subtype =
17027 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
17029 /* FIXME: We should support this, and let the linker
17030 catch branches and loads that are out of range. */
17031 as_bad_where (fragp->fr_file, fragp->fr_line,
17032 _("unsupported PC relative reference to different section"));
17036 if (fragp != sym_frag && sym_frag->fr_address == 0)
17037 /* Assume non-extended on the first relaxation pass.
17038 The address we have calculated will be bogus if this is
17039 a forward branch to another frag, as the forward frag
17040 will have fr_address == 0. */
17044 /* In this case, we know for sure that the symbol fragment is in
17045 the same section. If the relax_marker of the symbol fragment
17046 differs from the relax_marker of this fragment, we have not
17047 yet adjusted the symbol fragment fr_address. We want to add
17048 in STRETCH in order to get a better estimate of the address.
17049 This particularly matters because of the shift bits. */
17051 && sym_frag->relax_marker != fragp->relax_marker)
17055 /* Adjust stretch for any alignment frag. Note that if have
17056 been expanding the earlier code, the symbol may be
17057 defined in what appears to be an earlier frag. FIXME:
17058 This doesn't handle the fr_subtype field, which specifies
17059 a maximum number of bytes to skip when doing an
17061 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
17063 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
17066 stretch = - ((- stretch)
17067 & ~ ((1 << (int) f->fr_offset) - 1));
17069 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
17078 addr = fragp->fr_address + fragp->fr_fix;
17080 /* The base address rules are complicated. The base address of
17081 a branch is the following instruction. The base address of a
17082 PC relative load or add is the instruction itself, but if it
17083 is in a delay slot (in which case it can not be extended) use
17084 the address of the instruction whose delay slot it is in. */
17085 if (type == 'p' || type == 'q')
17089 /* If we are currently assuming that this frag should be
17090 extended, then, the current address is two bytes
17092 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
17095 /* Ignore the low bit in the target, since it will be set
17096 for a text label. */
17097 if ((val & 1) != 0)
17100 else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype))
17102 else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype))
17105 val -= addr & ~ ((1 << op->shift) - 1);
17107 /* Branch offsets have an implicit 0 in the lowest bit. */
17108 if (type == 'p' || type == 'q')
17111 /* If any of the shifted bits are set, we must use an extended
17112 opcode. If the address depends on the size of this
17113 instruction, this can lead to a loop, so we arrange to always
17114 use an extended opcode. We only check this when we are in
17115 the main relaxation loop, when SEC is NULL. */
17116 if ((val & ((1 << op->shift) - 1)) != 0 && sec == NULL)
17118 fragp->fr_subtype =
17119 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
17123 /* If we are about to mark a frag as extended because the value
17124 is precisely maxtiny + 1, then there is a chance of an
17125 infinite loop as in the following code:
17130 In this case when the la is extended, foo is 0x3fc bytes
17131 away, so the la can be shrunk, but then foo is 0x400 away, so
17132 the la must be extended. To avoid this loop, we mark the
17133 frag as extended if it was small, and is about to become
17134 extended with a value of maxtiny + 1. */
17135 if (val == ((maxtiny + 1) << op->shift)
17136 && ! RELAX_MIPS16_EXTENDED (fragp->fr_subtype)
17139 fragp->fr_subtype =
17140 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
17144 else if (symsec != absolute_section && sec != NULL)
17145 as_bad_where (fragp->fr_file, fragp->fr_line, _("unsupported relocation"));
17147 if ((val & ((1 << op->shift) - 1)) != 0
17148 || val < (mintiny << op->shift)
17149 || val > (maxtiny << op->shift))
17155 /* Compute the length of a branch sequence, and adjust the
17156 RELAX_BRANCH_TOOFAR bit accordingly. If FRAGP is NULL, the
17157 worst-case length is computed, with UPDATE being used to indicate
17158 whether an unconditional (-1), branch-likely (+1) or regular (0)
17159 branch is to be computed. */
17161 relaxed_branch_length (fragS *fragp, asection *sec, int update)
17163 bfd_boolean toofar;
17167 && S_IS_DEFINED (fragp->fr_symbol)
17168 && sec == S_GET_SEGMENT (fragp->fr_symbol))
17173 val = S_GET_VALUE (fragp->fr_symbol) + fragp->fr_offset;
17175 addr = fragp->fr_address + fragp->fr_fix + 4;
17179 toofar = val < - (0x8000 << 2) || val >= (0x8000 << 2);
17182 /* If the symbol is not defined or it's in a different segment,
17183 assume the user knows what's going on and emit a short
17189 if (fragp && update && toofar != RELAX_BRANCH_TOOFAR (fragp->fr_subtype))
17191 = RELAX_BRANCH_ENCODE (RELAX_BRANCH_AT (fragp->fr_subtype),
17192 RELAX_BRANCH_UNCOND (fragp->fr_subtype),
17193 RELAX_BRANCH_LIKELY (fragp->fr_subtype),
17194 RELAX_BRANCH_LINK (fragp->fr_subtype),
17200 if (fragp ? RELAX_BRANCH_LIKELY (fragp->fr_subtype) : (update > 0))
17203 if (mips_pic != NO_PIC)
17205 /* Additional space for PIC loading of target address. */
17207 if (mips_opts.isa == ISA_MIPS1)
17208 /* Additional space for $at-stabilizing nop. */
17212 /* If branch is conditional. */
17213 if (fragp ? !RELAX_BRANCH_UNCOND (fragp->fr_subtype) : (update >= 0))
17220 /* Compute the length of a branch sequence, and adjust the
17221 RELAX_MICROMIPS_TOOFAR32 bit accordingly. If FRAGP is NULL, the
17222 worst-case length is computed, with UPDATE being used to indicate
17223 whether an unconditional (-1), or regular (0) branch is to be
17227 relaxed_micromips_32bit_branch_length (fragS *fragp, asection *sec, int update)
17229 bfd_boolean toofar;
17233 && S_IS_DEFINED (fragp->fr_symbol)
17234 && sec == S_GET_SEGMENT (fragp->fr_symbol))
17239 val = S_GET_VALUE (fragp->fr_symbol) + fragp->fr_offset;
17240 /* Ignore the low bit in the target, since it will be set
17241 for a text label. */
17242 if ((val & 1) != 0)
17245 addr = fragp->fr_address + fragp->fr_fix + 4;
17249 toofar = val < - (0x8000 << 1) || val >= (0x8000 << 1);
17252 /* If the symbol is not defined or it's in a different segment,
17253 assume the user knows what's going on and emit a short
17259 if (fragp && update
17260 && toofar != RELAX_MICROMIPS_TOOFAR32 (fragp->fr_subtype))
17261 fragp->fr_subtype = (toofar
17262 ? RELAX_MICROMIPS_MARK_TOOFAR32 (fragp->fr_subtype)
17263 : RELAX_MICROMIPS_CLEAR_TOOFAR32 (fragp->fr_subtype));
17268 bfd_boolean compact_known = fragp != NULL;
17269 bfd_boolean compact = FALSE;
17270 bfd_boolean uncond;
17273 compact = RELAX_MICROMIPS_COMPACT (fragp->fr_subtype);
17275 uncond = RELAX_MICROMIPS_UNCOND (fragp->fr_subtype);
17277 uncond = update < 0;
17279 /* If label is out of range, we turn branch <br>:
17281 <br> label # 4 bytes
17287 nop # 2 bytes if compact && !PIC
17290 if (mips_pic == NO_PIC && (!compact_known || compact))
17293 /* If assembling PIC code, we further turn:
17299 lw/ld at, %got(label)(gp) # 4 bytes
17300 d/addiu at, %lo(label) # 4 bytes
17303 if (mips_pic != NO_PIC)
17306 /* If branch <br> is conditional, we prepend negated branch <brneg>:
17308 <brneg> 0f # 4 bytes
17309 nop # 2 bytes if !compact
17312 length += (compact_known && compact) ? 4 : 6;
17318 /* Compute the length of a branch, and adjust the RELAX_MICROMIPS_TOOFAR16
17319 bit accordingly. */
17322 relaxed_micromips_16bit_branch_length (fragS *fragp, asection *sec, int update)
17324 bfd_boolean toofar;
17327 && S_IS_DEFINED (fragp->fr_symbol)
17328 && sec == S_GET_SEGMENT (fragp->fr_symbol))
17334 val = S_GET_VALUE (fragp->fr_symbol) + fragp->fr_offset;
17335 /* Ignore the low bit in the target, since it will be set
17336 for a text label. */
17337 if ((val & 1) != 0)
17340 /* Assume this is a 2-byte branch. */
17341 addr = fragp->fr_address + fragp->fr_fix + 2;
17343 /* We try to avoid the infinite loop by not adding 2 more bytes for
17348 type = RELAX_MICROMIPS_TYPE (fragp->fr_subtype);
17350 toofar = val < - (0x200 << 1) || val >= (0x200 << 1);
17351 else if (type == 'E')
17352 toofar = val < - (0x40 << 1) || val >= (0x40 << 1);
17357 /* If the symbol is not defined or it's in a different segment,
17358 we emit a normal 32-bit branch. */
17361 if (fragp && update
17362 && toofar != RELAX_MICROMIPS_TOOFAR16 (fragp->fr_subtype))
17364 = toofar ? RELAX_MICROMIPS_MARK_TOOFAR16 (fragp->fr_subtype)
17365 : RELAX_MICROMIPS_CLEAR_TOOFAR16 (fragp->fr_subtype);
17373 /* Estimate the size of a frag before relaxing. Unless this is the
17374 mips16, we are not really relaxing here, and the final size is
17375 encoded in the subtype information. For the mips16, we have to
17376 decide whether we are using an extended opcode or not. */
17379 md_estimate_size_before_relax (fragS *fragp, asection *segtype)
17383 if (RELAX_BRANCH_P (fragp->fr_subtype))
17386 fragp->fr_var = relaxed_branch_length (fragp, segtype, FALSE);
17388 return fragp->fr_var;
17391 if (RELAX_MIPS16_P (fragp->fr_subtype))
17392 /* We don't want to modify the EXTENDED bit here; it might get us
17393 into infinite loops. We change it only in mips_relax_frag(). */
17394 return (RELAX_MIPS16_EXTENDED (fragp->fr_subtype) ? 4 : 2);
17396 if (RELAX_MICROMIPS_P (fragp->fr_subtype))
17400 if (RELAX_MICROMIPS_TYPE (fragp->fr_subtype) != 0)
17401 length = relaxed_micromips_16bit_branch_length (fragp, segtype, FALSE);
17402 if (length == 4 && RELAX_MICROMIPS_RELAX32 (fragp->fr_subtype))
17403 length = relaxed_micromips_32bit_branch_length (fragp, segtype, FALSE);
17404 fragp->fr_var = length;
17409 if (mips_pic == NO_PIC)
17410 change = nopic_need_relax (fragp->fr_symbol, 0);
17411 else if (mips_pic == SVR4_PIC)
17412 change = pic_need_relax (fragp->fr_symbol, segtype);
17413 else if (mips_pic == VXWORKS_PIC)
17414 /* For vxworks, GOT16 relocations never have a corresponding LO16. */
17421 fragp->fr_subtype |= RELAX_USE_SECOND;
17422 return -RELAX_FIRST (fragp->fr_subtype);
17425 return -RELAX_SECOND (fragp->fr_subtype);
17428 /* This is called to see whether a reloc against a defined symbol
17429 should be converted into a reloc against a section. */
17432 mips_fix_adjustable (fixS *fixp)
17434 if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT
17435 || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
17438 if (fixp->fx_addsy == NULL)
17441 /* If symbol SYM is in a mergeable section, relocations of the form
17442 SYM + 0 can usually be made section-relative. The mergeable data
17443 is then identified by the section offset rather than by the symbol.
17445 However, if we're generating REL LO16 relocations, the offset is split
17446 between the LO16 and parterning high part relocation. The linker will
17447 need to recalculate the complete offset in order to correctly identify
17450 The linker has traditionally not looked for the parterning high part
17451 relocation, and has thus allowed orphaned R_MIPS_LO16 relocations to be
17452 placed anywhere. Rather than break backwards compatibility by changing
17453 this, it seems better not to force the issue, and instead keep the
17454 original symbol. This will work with either linker behavior. */
17455 if ((lo16_reloc_p (fixp->fx_r_type)
17456 || reloc_needs_lo_p (fixp->fx_r_type))
17457 && HAVE_IN_PLACE_ADDENDS
17458 && (S_GET_SEGMENT (fixp->fx_addsy)->flags & SEC_MERGE) != 0)
17461 /* There is no place to store an in-place offset for JALR relocations.
17462 Likewise an in-range offset of PC-relative relocations may overflow
17463 the in-place relocatable field if recalculated against the start
17464 address of the symbol's containing section. */
17465 if (HAVE_IN_PLACE_ADDENDS
17466 && (fixp->fx_pcrel || jalr_reloc_p (fixp->fx_r_type)))
17470 /* R_MIPS16_26 relocations against non-MIPS16 functions might resolve
17471 to a floating-point stub. The same is true for non-R_MIPS16_26
17472 relocations against MIPS16 functions; in this case, the stub becomes
17473 the function's canonical address.
17475 Floating-point stubs are stored in unique .mips16.call.* or
17476 .mips16.fn.* sections. If a stub T for function F is in section S,
17477 the first relocation in section S must be against F; this is how the
17478 linker determines the target function. All relocations that might
17479 resolve to T must also be against F. We therefore have the following
17480 restrictions, which are given in an intentionally-redundant way:
17482 1. We cannot reduce R_MIPS16_26 relocations against non-MIPS16
17485 2. We cannot reduce a stub's relocations against non-MIPS16 symbols
17486 if that stub might be used.
17488 3. We cannot reduce non-R_MIPS16_26 relocations against MIPS16
17491 4. We cannot reduce a stub's relocations against MIPS16 symbols if
17492 that stub might be used.
17494 There is a further restriction:
17496 5. We cannot reduce jump relocations (R_MIPS_26, R_MIPS16_26 or
17497 R_MICROMIPS_26_S1) against MIPS16 or microMIPS symbols on
17498 targets with in-place addends; the relocation field cannot
17499 encode the low bit.
17501 For simplicity, we deal with (3)-(4) by not reducing _any_ relocation
17502 against a MIPS16 symbol. We deal with (5) by by not reducing any
17503 such relocations on REL targets.
17505 We deal with (1)-(2) by saying that, if there's a R_MIPS16_26
17506 relocation against some symbol R, no relocation against R may be
17507 reduced. (Note that this deals with (2) as well as (1) because
17508 relocations against global symbols will never be reduced on ELF
17509 targets.) This approach is a little simpler than trying to detect
17510 stub sections, and gives the "all or nothing" per-symbol consistency
17511 that we have for MIPS16 symbols. */
17513 && fixp->fx_subsy == NULL
17514 && (ELF_ST_IS_MIPS16 (S_GET_OTHER (fixp->fx_addsy))
17515 || *symbol_get_tc (fixp->fx_addsy)
17516 || (HAVE_IN_PLACE_ADDENDS
17517 && ELF_ST_IS_MICROMIPS (S_GET_OTHER (fixp->fx_addsy))
17518 && jmp_reloc_p (fixp->fx_r_type))))
17525 /* Translate internal representation of relocation info to BFD target
17529 tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixp)
17531 static arelent *retval[4];
17533 bfd_reloc_code_real_type code;
17535 memset (retval, 0, sizeof(retval));
17536 reloc = retval[0] = (arelent *) xcalloc (1, sizeof (arelent));
17537 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
17538 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
17539 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
17541 if (fixp->fx_pcrel)
17543 gas_assert (fixp->fx_r_type == BFD_RELOC_16_PCREL_S2
17544 || fixp->fx_r_type == BFD_RELOC_MICROMIPS_7_PCREL_S1
17545 || fixp->fx_r_type == BFD_RELOC_MICROMIPS_10_PCREL_S1
17546 || fixp->fx_r_type == BFD_RELOC_MICROMIPS_16_PCREL_S1);
17548 /* At this point, fx_addnumber is "symbol offset - pcrel address".
17549 Relocations want only the symbol offset. */
17550 reloc->addend = fixp->fx_addnumber + reloc->address;
17553 /* A gruesome hack which is a result of the gruesome gas
17554 reloc handling. What's worse, for COFF (as opposed to
17555 ECOFF), we might need yet another copy of reloc->address.
17556 See bfd_install_relocation. */
17557 reloc->addend += reloc->address;
17561 reloc->addend = fixp->fx_addnumber;
17563 /* Since the old MIPS ELF ABI uses Rel instead of Rela, encode the vtable
17564 entry to be used in the relocation's section offset. */
17565 if (! HAVE_NEWABI && fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
17567 reloc->address = reloc->addend;
17571 code = fixp->fx_r_type;
17573 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
17574 if (reloc->howto == NULL)
17576 as_bad_where (fixp->fx_file, fixp->fx_line,
17577 _("Can not represent %s relocation in this object file format"),
17578 bfd_get_reloc_code_name (code));
17585 /* Relax a machine dependent frag. This returns the amount by which
17586 the current size of the frag should change. */
17589 mips_relax_frag (asection *sec, fragS *fragp, long stretch)
17591 if (RELAX_BRANCH_P (fragp->fr_subtype))
17593 offsetT old_var = fragp->fr_var;
17595 fragp->fr_var = relaxed_branch_length (fragp, sec, TRUE);
17597 return fragp->fr_var - old_var;
17600 if (RELAX_MICROMIPS_P (fragp->fr_subtype))
17602 offsetT old_var = fragp->fr_var;
17603 offsetT new_var = 4;
17605 if (RELAX_MICROMIPS_TYPE (fragp->fr_subtype) != 0)
17606 new_var = relaxed_micromips_16bit_branch_length (fragp, sec, TRUE);
17607 if (new_var == 4 && RELAX_MICROMIPS_RELAX32 (fragp->fr_subtype))
17608 new_var = relaxed_micromips_32bit_branch_length (fragp, sec, TRUE);
17609 fragp->fr_var = new_var;
17611 return new_var - old_var;
17614 if (! RELAX_MIPS16_P (fragp->fr_subtype))
17617 if (mips16_extended_frag (fragp, NULL, stretch))
17619 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
17621 fragp->fr_subtype = RELAX_MIPS16_MARK_EXTENDED (fragp->fr_subtype);
17626 if (! RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
17628 fragp->fr_subtype = RELAX_MIPS16_CLEAR_EXTENDED (fragp->fr_subtype);
17635 /* Convert a machine dependent frag. */
17638 md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, segT asec, fragS *fragp)
17640 if (RELAX_BRANCH_P (fragp->fr_subtype))
17643 unsigned long insn;
17647 buf = (bfd_byte *)fragp->fr_literal + fragp->fr_fix;
17649 if (target_big_endian)
17650 insn = bfd_getb32 (buf);
17652 insn = bfd_getl32 (buf);
17654 if (!RELAX_BRANCH_TOOFAR (fragp->fr_subtype))
17656 /* We generate a fixup instead of applying it right now
17657 because, if there are linker relaxations, we're going to
17658 need the relocations. */
17659 exp.X_op = O_symbol;
17660 exp.X_add_symbol = fragp->fr_symbol;
17661 exp.X_add_number = fragp->fr_offset;
17663 fixp = fix_new_exp (fragp, buf - (bfd_byte *)fragp->fr_literal,
17664 4, &exp, TRUE, BFD_RELOC_16_PCREL_S2);
17665 fixp->fx_file = fragp->fr_file;
17666 fixp->fx_line = fragp->fr_line;
17668 md_number_to_chars ((char *) buf, insn, 4);
17675 as_warn_where (fragp->fr_file, fragp->fr_line,
17676 _("Relaxed out-of-range branch into a jump"));
17678 if (RELAX_BRANCH_UNCOND (fragp->fr_subtype))
17681 if (!RELAX_BRANCH_LIKELY (fragp->fr_subtype))
17683 /* Reverse the branch. */
17684 switch ((insn >> 28) & 0xf)
17687 /* bc[0-3][tf]l? and bc1any[24][ft] instructions can
17688 have the condition reversed by tweaking a single
17689 bit, and their opcodes all have 0x4???????. */
17690 gas_assert ((insn & 0xf1000000) == 0x41000000);
17691 insn ^= 0x00010000;
17695 /* bltz 0x04000000 bgez 0x04010000
17696 bltzal 0x04100000 bgezal 0x04110000 */
17697 gas_assert ((insn & 0xfc0e0000) == 0x04000000);
17698 insn ^= 0x00010000;
17702 /* beq 0x10000000 bne 0x14000000
17703 blez 0x18000000 bgtz 0x1c000000 */
17704 insn ^= 0x04000000;
17712 if (RELAX_BRANCH_LINK (fragp->fr_subtype))
17714 /* Clear the and-link bit. */
17715 gas_assert ((insn & 0xfc1c0000) == 0x04100000);
17717 /* bltzal 0x04100000 bgezal 0x04110000
17718 bltzall 0x04120000 bgezall 0x04130000 */
17719 insn &= ~0x00100000;
17722 /* Branch over the branch (if the branch was likely) or the
17723 full jump (not likely case). Compute the offset from the
17724 current instruction to branch to. */
17725 if (RELAX_BRANCH_LIKELY (fragp->fr_subtype))
17729 /* How many bytes in instructions we've already emitted? */
17730 i = buf - (bfd_byte *)fragp->fr_literal - fragp->fr_fix;
17731 /* How many bytes in instructions from here to the end? */
17732 i = fragp->fr_var - i;
17734 /* Convert to instruction count. */
17736 /* Branch counts from the next instruction. */
17739 /* Branch over the jump. */
17740 md_number_to_chars ((char *) buf, insn, 4);
17744 md_number_to_chars ((char *) buf, 0, 4);
17747 if (RELAX_BRANCH_LIKELY (fragp->fr_subtype))
17749 /* beql $0, $0, 2f */
17751 /* Compute the PC offset from the current instruction to
17752 the end of the variable frag. */
17753 /* How many bytes in instructions we've already emitted? */
17754 i = buf - (bfd_byte *)fragp->fr_literal - fragp->fr_fix;
17755 /* How many bytes in instructions from here to the end? */
17756 i = fragp->fr_var - i;
17757 /* Convert to instruction count. */
17759 /* Don't decrement i, because we want to branch over the
17763 md_number_to_chars ((char *) buf, insn, 4);
17766 md_number_to_chars ((char *) buf, 0, 4);
17771 if (mips_pic == NO_PIC)
17774 insn = (RELAX_BRANCH_LINK (fragp->fr_subtype)
17775 ? 0x0c000000 : 0x08000000);
17776 exp.X_op = O_symbol;
17777 exp.X_add_symbol = fragp->fr_symbol;
17778 exp.X_add_number = fragp->fr_offset;
17780 fixp = fix_new_exp (fragp, buf - (bfd_byte *)fragp->fr_literal,
17781 4, &exp, FALSE, BFD_RELOC_MIPS_JMP);
17782 fixp->fx_file = fragp->fr_file;
17783 fixp->fx_line = fragp->fr_line;
17785 md_number_to_chars ((char *) buf, insn, 4);
17790 unsigned long at = RELAX_BRANCH_AT (fragp->fr_subtype);
17792 /* lw/ld $at, <sym>($gp) R_MIPS_GOT16 */
17793 insn = HAVE_64BIT_ADDRESSES ? 0xdf800000 : 0x8f800000;
17794 insn |= at << OP_SH_RT;
17795 exp.X_op = O_symbol;
17796 exp.X_add_symbol = fragp->fr_symbol;
17797 exp.X_add_number = fragp->fr_offset;
17799 if (fragp->fr_offset)
17801 exp.X_add_symbol = make_expr_symbol (&exp);
17802 exp.X_add_number = 0;
17805 fixp = fix_new_exp (fragp, buf - (bfd_byte *)fragp->fr_literal,
17806 4, &exp, FALSE, BFD_RELOC_MIPS_GOT16);
17807 fixp->fx_file = fragp->fr_file;
17808 fixp->fx_line = fragp->fr_line;
17810 md_number_to_chars ((char *) buf, insn, 4);
17813 if (mips_opts.isa == ISA_MIPS1)
17816 md_number_to_chars ((char *) buf, 0, 4);
17820 /* d/addiu $at, $at, <sym> R_MIPS_LO16 */
17821 insn = HAVE_64BIT_ADDRESSES ? 0x64000000 : 0x24000000;
17822 insn |= at << OP_SH_RS | at << OP_SH_RT;
17824 fixp = fix_new_exp (fragp, buf - (bfd_byte *)fragp->fr_literal,
17825 4, &exp, FALSE, BFD_RELOC_LO16);
17826 fixp->fx_file = fragp->fr_file;
17827 fixp->fx_line = fragp->fr_line;
17829 md_number_to_chars ((char *) buf, insn, 4);
17833 if (RELAX_BRANCH_LINK (fragp->fr_subtype))
17837 insn |= at << OP_SH_RS;
17839 md_number_to_chars ((char *) buf, insn, 4);
17844 gas_assert (buf == (bfd_byte *)fragp->fr_literal
17845 + fragp->fr_fix + fragp->fr_var);
17847 fragp->fr_fix += fragp->fr_var;
17852 /* Relax microMIPS branches. */
17853 if (RELAX_MICROMIPS_P (fragp->fr_subtype))
17855 bfd_byte *buf = (bfd_byte *) (fragp->fr_literal + fragp->fr_fix);
17856 bfd_boolean compact = RELAX_MICROMIPS_COMPACT (fragp->fr_subtype);
17857 bfd_boolean al = RELAX_MICROMIPS_LINK (fragp->fr_subtype);
17858 int type = RELAX_MICROMIPS_TYPE (fragp->fr_subtype);
17859 bfd_boolean short_ds;
17860 unsigned long insn;
17864 exp.X_op = O_symbol;
17865 exp.X_add_symbol = fragp->fr_symbol;
17866 exp.X_add_number = fragp->fr_offset;
17868 fragp->fr_fix += fragp->fr_var;
17870 /* Handle 16-bit branches that fit or are forced to fit. */
17871 if (type != 0 && !RELAX_MICROMIPS_TOOFAR16 (fragp->fr_subtype))
17873 /* We generate a fixup instead of applying it right now,
17874 because if there is linker relaxation, we're going to
17875 need the relocations. */
17877 fixp = fix_new_exp (fragp,
17878 buf - (bfd_byte *) fragp->fr_literal,
17880 BFD_RELOC_MICROMIPS_10_PCREL_S1);
17881 else if (type == 'E')
17882 fixp = fix_new_exp (fragp,
17883 buf - (bfd_byte *) fragp->fr_literal,
17885 BFD_RELOC_MICROMIPS_7_PCREL_S1);
17889 fixp->fx_file = fragp->fr_file;
17890 fixp->fx_line = fragp->fr_line;
17892 /* These relocations can have an addend that won't fit in
17894 fixp->fx_no_overflow = 1;
17899 /* Handle 32-bit branches that fit or are forced to fit. */
17900 if (!RELAX_MICROMIPS_RELAX32 (fragp->fr_subtype)
17901 || !RELAX_MICROMIPS_TOOFAR32 (fragp->fr_subtype))
17903 /* We generate a fixup instead of applying it right now,
17904 because if there is linker relaxation, we're going to
17905 need the relocations. */
17906 fixp = fix_new_exp (fragp, buf - (bfd_byte *) fragp->fr_literal,
17907 4, &exp, TRUE, BFD_RELOC_MICROMIPS_16_PCREL_S1);
17908 fixp->fx_file = fragp->fr_file;
17909 fixp->fx_line = fragp->fr_line;
17915 /* Relax 16-bit branches to 32-bit branches. */
17918 if (target_big_endian)
17919 insn = bfd_getb16 (buf);
17921 insn = bfd_getl16 (buf);
17923 if ((insn & 0xfc00) == 0xcc00) /* b16 */
17924 insn = 0x94000000; /* beq */
17925 else if ((insn & 0xdc00) == 0x8c00) /* beqz16/bnez16 */
17927 unsigned long regno;
17929 regno = (insn >> MICROMIPSOP_SH_MD) & MICROMIPSOP_MASK_MD;
17930 regno = micromips_to_32_reg_d_map [regno];
17931 insn = ((insn & 0x2000) << 16) | 0x94000000; /* beq/bne */
17932 insn |= regno << MICROMIPSOP_SH_RS;
17937 /* Nothing else to do, just write it out. */
17938 if (!RELAX_MICROMIPS_RELAX32 (fragp->fr_subtype)
17939 || !RELAX_MICROMIPS_TOOFAR32 (fragp->fr_subtype))
17941 md_number_to_chars ((char *) buf, insn >> 16, 2);
17943 md_number_to_chars ((char *) buf, insn & 0xffff, 2);
17946 gas_assert (buf == ((bfd_byte *) fragp->fr_literal
17953 unsigned long next;
17955 if (target_big_endian)
17957 insn = bfd_getb16 (buf);
17958 next = bfd_getb16 (buf + 2);
17962 insn = bfd_getl16 (buf);
17963 next = bfd_getl16 (buf + 2);
17965 insn = (insn << 16) | next;
17968 /* Relax 32-bit branches to a sequence of instructions. */
17969 as_warn_where (fragp->fr_file, fragp->fr_line,
17970 _("Relaxed out-of-range branch into a jump"));
17972 /* Set the short-delay-slot bit. */
17973 short_ds = al && (insn & 0x02000000) != 0;
17975 if (!RELAX_MICROMIPS_UNCOND (fragp->fr_subtype))
17979 /* Reverse the branch. */
17980 if ((insn & 0xfc000000) == 0x94000000 /* beq */
17981 || (insn & 0xfc000000) == 0xb4000000) /* bne */
17982 insn ^= 0x20000000;
17983 else if ((insn & 0xffe00000) == 0x40000000 /* bltz */
17984 || (insn & 0xffe00000) == 0x40400000 /* bgez */
17985 || (insn & 0xffe00000) == 0x40800000 /* blez */
17986 || (insn & 0xffe00000) == 0x40c00000 /* bgtz */
17987 || (insn & 0xffe00000) == 0x40a00000 /* bnezc */
17988 || (insn & 0xffe00000) == 0x40e00000 /* beqzc */
17989 || (insn & 0xffe00000) == 0x40200000 /* bltzal */
17990 || (insn & 0xffe00000) == 0x40600000 /* bgezal */
17991 || (insn & 0xffe00000) == 0x42200000 /* bltzals */
17992 || (insn & 0xffe00000) == 0x42600000) /* bgezals */
17993 insn ^= 0x00400000;
17994 else if ((insn & 0xffe30000) == 0x43800000 /* bc1f */
17995 || (insn & 0xffe30000) == 0x43a00000 /* bc1t */
17996 || (insn & 0xffe30000) == 0x42800000 /* bc2f */
17997 || (insn & 0xffe30000) == 0x42a00000) /* bc2t */
17998 insn ^= 0x00200000;
18004 /* Clear the and-link and short-delay-slot bits. */
18005 gas_assert ((insn & 0xfda00000) == 0x40200000);
18007 /* bltzal 0x40200000 bgezal 0x40600000 */
18008 /* bltzals 0x42200000 bgezals 0x42600000 */
18009 insn &= ~0x02200000;
18012 /* Make a label at the end for use with the branch. */
18013 l = symbol_new (micromips_label_name (), asec, fragp->fr_fix, fragp);
18014 micromips_label_inc ();
18015 #if defined(OBJ_ELF) || defined(OBJ_MAYBE_ELF)
18017 S_SET_OTHER (l, ELF_ST_SET_MICROMIPS (S_GET_OTHER (l)));
18021 fixp = fix_new (fragp, buf - (bfd_byte *) fragp->fr_literal,
18022 4, l, 0, TRUE, BFD_RELOC_MICROMIPS_16_PCREL_S1);
18023 fixp->fx_file = fragp->fr_file;
18024 fixp->fx_line = fragp->fr_line;
18026 /* Branch over the jump. */
18027 md_number_to_chars ((char *) buf, insn >> 16, 2);
18029 md_number_to_chars ((char *) buf, insn & 0xffff, 2);
18036 md_number_to_chars ((char *) buf, insn, 2);
18041 if (mips_pic == NO_PIC)
18043 unsigned long jal = short_ds ? 0x74000000 : 0xf4000000; /* jal/s */
18045 /* j/jal/jals <sym> R_MICROMIPS_26_S1 */
18046 insn = al ? jal : 0xd4000000;
18048 fixp = fix_new_exp (fragp, buf - (bfd_byte *) fragp->fr_literal,
18049 4, &exp, FALSE, BFD_RELOC_MICROMIPS_JMP);
18050 fixp->fx_file = fragp->fr_file;
18051 fixp->fx_line = fragp->fr_line;
18053 md_number_to_chars ((char *) buf, insn >> 16, 2);
18055 md_number_to_chars ((char *) buf, insn & 0xffff, 2);
18062 md_number_to_chars ((char *) buf, insn, 2);
18068 unsigned long at = RELAX_MICROMIPS_AT (fragp->fr_subtype);
18069 unsigned long jalr = short_ds ? 0x45e0 : 0x45c0; /* jalr/s */
18070 unsigned long jr = compact ? 0x45a0 : 0x4580; /* jr/c */
18072 /* lw/ld $at, <sym>($gp) R_MICROMIPS_GOT16 */
18073 insn = HAVE_64BIT_ADDRESSES ? 0xdc1c0000 : 0xfc1c0000;
18074 insn |= at << MICROMIPSOP_SH_RT;
18076 if (exp.X_add_number)
18078 exp.X_add_symbol = make_expr_symbol (&exp);
18079 exp.X_add_number = 0;
18082 fixp = fix_new_exp (fragp, buf - (bfd_byte *) fragp->fr_literal,
18083 4, &exp, FALSE, BFD_RELOC_MICROMIPS_GOT16);
18084 fixp->fx_file = fragp->fr_file;
18085 fixp->fx_line = fragp->fr_line;
18087 md_number_to_chars ((char *) buf, insn >> 16, 2);
18089 md_number_to_chars ((char *) buf, insn & 0xffff, 2);
18092 /* d/addiu $at, $at, <sym> R_MICROMIPS_LO16 */
18093 insn = HAVE_64BIT_ADDRESSES ? 0x5c000000 : 0x30000000;
18094 insn |= at << MICROMIPSOP_SH_RT | at << MICROMIPSOP_SH_RS;
18096 fixp = fix_new_exp (fragp, buf - (bfd_byte *) fragp->fr_literal,
18097 4, &exp, FALSE, BFD_RELOC_MICROMIPS_LO16);
18098 fixp->fx_file = fragp->fr_file;
18099 fixp->fx_line = fragp->fr_line;
18101 md_number_to_chars ((char *) buf, insn >> 16, 2);
18103 md_number_to_chars ((char *) buf, insn & 0xffff, 2);
18106 /* jr/jrc/jalr/jalrs $at */
18107 insn = al ? jalr : jr;
18108 insn |= at << MICROMIPSOP_SH_MJ;
18110 md_number_to_chars ((char *) buf, insn & 0xffff, 2);
18114 gas_assert (buf == (bfd_byte *) fragp->fr_literal + fragp->fr_fix);
18118 if (RELAX_MIPS16_P (fragp->fr_subtype))
18121 const struct mips16_immed_operand *op;
18122 bfd_boolean small, ext;
18125 unsigned long insn;
18126 bfd_boolean use_extend;
18127 unsigned short extend;
18129 type = RELAX_MIPS16_TYPE (fragp->fr_subtype);
18130 op = mips16_immed_operands;
18131 while (op->type != type)
18134 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
18145 val = resolve_symbol_value (fragp->fr_symbol);
18150 addr = fragp->fr_address + fragp->fr_fix;
18152 /* The rules for the base address of a PC relative reloc are
18153 complicated; see mips16_extended_frag. */
18154 if (type == 'p' || type == 'q')
18159 /* Ignore the low bit in the target, since it will be
18160 set for a text label. */
18161 if ((val & 1) != 0)
18164 else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype))
18166 else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype))
18169 addr &= ~ (addressT) ((1 << op->shift) - 1);
18172 /* Make sure the section winds up with the alignment we have
18175 record_alignment (asec, op->shift);
18179 && (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype)
18180 || RELAX_MIPS16_DSLOT (fragp->fr_subtype)))
18181 as_warn_where (fragp->fr_file, fragp->fr_line,
18182 _("extended instruction in delay slot"));
18184 buf = (bfd_byte *) (fragp->fr_literal + fragp->fr_fix);
18186 if (target_big_endian)
18187 insn = bfd_getb16 (buf);
18189 insn = bfd_getl16 (buf);
18191 mips16_immed (fragp->fr_file, fragp->fr_line, type, val,
18192 RELAX_MIPS16_USER_EXT (fragp->fr_subtype),
18193 small, ext, &insn, &use_extend, &extend);
18197 md_number_to_chars ((char *) buf, 0xf000 | extend, 2);
18198 fragp->fr_fix += 2;
18202 md_number_to_chars ((char *) buf, insn, 2);
18203 fragp->fr_fix += 2;
18208 relax_substateT subtype = fragp->fr_subtype;
18209 bfd_boolean second_longer = (subtype & RELAX_SECOND_LONGER) != 0;
18210 bfd_boolean use_second = (subtype & RELAX_USE_SECOND) != 0;
18214 first = RELAX_FIRST (subtype);
18215 second = RELAX_SECOND (subtype);
18216 fixp = (fixS *) fragp->fr_opcode;
18218 /* If the delay slot chosen does not match the size of the instruction,
18219 then emit a warning. */
18220 if ((!use_second && (subtype & RELAX_DELAY_SLOT_SIZE_FIRST) != 0)
18221 || (use_second && (subtype & RELAX_DELAY_SLOT_SIZE_SECOND) != 0))
18226 s = subtype & (RELAX_DELAY_SLOT_16BIT
18227 | RELAX_DELAY_SLOT_SIZE_FIRST
18228 | RELAX_DELAY_SLOT_SIZE_SECOND);
18229 msg = macro_warning (s);
18231 as_warn_where (fragp->fr_file, fragp->fr_line, "%s", msg);
18235 /* Possibly emit a warning if we've chosen the longer option. */
18236 if (use_second == second_longer)
18242 & (RELAX_SECOND_LONGER | RELAX_NOMACRO | RELAX_DELAY_SLOT));
18243 msg = macro_warning (s);
18245 as_warn_where (fragp->fr_file, fragp->fr_line, "%s", msg);
18249 /* Go through all the fixups for the first sequence. Disable them
18250 (by marking them as done) if we're going to use the second
18251 sequence instead. */
18253 && fixp->fx_frag == fragp
18254 && fixp->fx_where < fragp->fr_fix - second)
18256 if (subtype & RELAX_USE_SECOND)
18258 fixp = fixp->fx_next;
18261 /* Go through the fixups for the second sequence. Disable them if
18262 we're going to use the first sequence, otherwise adjust their
18263 addresses to account for the relaxation. */
18264 while (fixp && fixp->fx_frag == fragp)
18266 if (subtype & RELAX_USE_SECOND)
18267 fixp->fx_where -= first;
18270 fixp = fixp->fx_next;
18273 /* Now modify the frag contents. */
18274 if (subtype & RELAX_USE_SECOND)
18278 start = fragp->fr_literal + fragp->fr_fix - first - second;
18279 memmove (start, start + first, second);
18280 fragp->fr_fix -= first;
18283 fragp->fr_fix -= second;
18289 /* This function is called after the relocs have been generated.
18290 We've been storing mips16 text labels as odd. Here we convert them
18291 back to even for the convenience of the debugger. */
18294 mips_frob_file_after_relocs (void)
18297 unsigned int count, i;
18302 syms = bfd_get_outsymbols (stdoutput);
18303 count = bfd_get_symcount (stdoutput);
18304 for (i = 0; i < count; i++, syms++)
18305 if (ELF_ST_IS_COMPRESSED (elf_symbol (*syms)->internal_elf_sym.st_other)
18306 && ((*syms)->value & 1) != 0)
18308 (*syms)->value &= ~1;
18309 /* If the symbol has an odd size, it was probably computed
18310 incorrectly, so adjust that as well. */
18311 if ((elf_symbol (*syms)->internal_elf_sym.st_size & 1) != 0)
18312 ++elf_symbol (*syms)->internal_elf_sym.st_size;
18318 /* This function is called whenever a label is defined, including fake
18319 labels instantiated off the dot special symbol. It is used when
18320 handling branch delays; if a branch has a label, we assume we cannot
18321 move it. This also bumps the value of the symbol by 1 in compressed
18325 mips_record_label (symbolS *sym)
18327 segment_info_type *si = seg_info (now_seg);
18328 struct insn_label_list *l;
18330 if (free_insn_labels == NULL)
18331 l = (struct insn_label_list *) xmalloc (sizeof *l);
18334 l = free_insn_labels;
18335 free_insn_labels = l->next;
18339 l->next = si->label_list;
18340 si->label_list = l;
18343 /* This function is called as tc_frob_label() whenever a label is defined
18344 and adds a DWARF-2 record we only want for true labels. */
18347 mips_define_label (symbolS *sym)
18349 mips_record_label (sym);
18351 dwarf2_emit_label (sym);
18355 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
18357 /* Some special processing for a MIPS ELF file. */
18360 mips_elf_final_processing (void)
18362 /* Write out the register information. */
18363 if (mips_abi != N64_ABI)
18367 s.ri_gprmask = mips_gprmask;
18368 s.ri_cprmask[0] = mips_cprmask[0];
18369 s.ri_cprmask[1] = mips_cprmask[1];
18370 s.ri_cprmask[2] = mips_cprmask[2];
18371 s.ri_cprmask[3] = mips_cprmask[3];
18372 /* The gp_value field is set by the MIPS ELF backend. */
18374 bfd_mips_elf32_swap_reginfo_out (stdoutput, &s,
18375 ((Elf32_External_RegInfo *)
18376 mips_regmask_frag));
18380 Elf64_Internal_RegInfo s;
18382 s.ri_gprmask = mips_gprmask;
18384 s.ri_cprmask[0] = mips_cprmask[0];
18385 s.ri_cprmask[1] = mips_cprmask[1];
18386 s.ri_cprmask[2] = mips_cprmask[2];
18387 s.ri_cprmask[3] = mips_cprmask[3];
18388 /* The gp_value field is set by the MIPS ELF backend. */
18390 bfd_mips_elf64_swap_reginfo_out (stdoutput, &s,
18391 ((Elf64_External_RegInfo *)
18392 mips_regmask_frag));
18395 /* Set the MIPS ELF flag bits. FIXME: There should probably be some
18396 sort of BFD interface for this. */
18397 if (mips_any_noreorder)
18398 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_NOREORDER;
18399 if (mips_pic != NO_PIC)
18401 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_PIC;
18402 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_CPIC;
18405 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_CPIC;
18407 /* Set MIPS ELF flags for ASEs. */
18408 /* We may need to define a new flag for DSP ASE, and set this flag when
18409 file_ase_dsp is true. */
18410 /* Same for DSP R2. */
18411 /* We may need to define a new flag for MT ASE, and set this flag when
18412 file_ase_mt is true. */
18413 if (file_ase_mips16)
18414 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ARCH_ASE_M16;
18415 if (file_ase_micromips)
18416 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ARCH_ASE_MICROMIPS;
18417 #if 0 /* XXX FIXME */
18418 if (file_ase_mips3d)
18419 elf_elfheader (stdoutput)->e_flags |= ???;
18422 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ARCH_ASE_MDMX;
18424 /* Set the MIPS ELF ABI flags. */
18425 if (mips_abi == O32_ABI && USE_E_MIPS_ABI_O32)
18426 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O32;
18427 else if (mips_abi == O64_ABI)
18428 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O64;
18429 else if (mips_abi == EABI_ABI)
18431 if (!file_mips_gp32)
18432 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI64;
18434 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI32;
18436 else if (mips_abi == N32_ABI)
18437 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ABI2;
18439 /* Nothing to do for N64_ABI. */
18441 if (mips_32bitmode)
18442 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_32BITMODE;
18444 #if 0 /* XXX FIXME */
18445 /* 32 bit code with 64 bit FP registers. */
18446 if (!file_mips_fp32 && ABI_NEEDS_32BIT_REGS (mips_abi))
18447 elf_elfheader (stdoutput)->e_flags |= ???;
18451 #endif /* OBJ_ELF || OBJ_MAYBE_ELF */
18453 typedef struct proc {
18455 symbolS *func_end_sym;
18456 unsigned long reg_mask;
18457 unsigned long reg_offset;
18458 unsigned long fpreg_mask;
18459 unsigned long fpreg_offset;
18460 unsigned long frame_offset;
18461 unsigned long frame_reg;
18462 unsigned long pc_reg;
18465 static procS cur_proc;
18466 static procS *cur_proc_ptr;
18467 static int numprocs;
18469 /* Implement NOP_OPCODE. We encode a MIPS16 nop as "1", a microMIPS nop
18470 as "2", and a normal nop as "0". */
18472 #define NOP_OPCODE_MIPS 0
18473 #define NOP_OPCODE_MIPS16 1
18474 #define NOP_OPCODE_MICROMIPS 2
18477 mips_nop_opcode (void)
18479 if (seg_info (now_seg)->tc_segment_info_data.micromips)
18480 return NOP_OPCODE_MICROMIPS;
18481 else if (seg_info (now_seg)->tc_segment_info_data.mips16)
18482 return NOP_OPCODE_MIPS16;
18484 return NOP_OPCODE_MIPS;
18487 /* Fill in an rs_align_code fragment. Unlike elsewhere we want to use
18488 32-bit microMIPS NOPs here (if applicable). */
18491 mips_handle_align (fragS *fragp)
18495 int bytes, size, excess;
18498 if (fragp->fr_type != rs_align_code)
18501 p = fragp->fr_literal + fragp->fr_fix;
18503 switch (nop_opcode)
18505 case NOP_OPCODE_MICROMIPS:
18506 opcode = micromips_nop32_insn.insn_opcode;
18509 case NOP_OPCODE_MIPS16:
18510 opcode = mips16_nop_insn.insn_opcode;
18513 case NOP_OPCODE_MIPS:
18515 opcode = nop_insn.insn_opcode;
18520 bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
18521 excess = bytes % size;
18523 /* Handle the leading part if we're not inserting a whole number of
18524 instructions, and make it the end of the fixed part of the frag.
18525 Try to fit in a short microMIPS NOP if applicable and possible,
18526 and use zeroes otherwise. */
18527 gas_assert (excess < 4);
18528 fragp->fr_fix += excess;
18533 /* Fall through. */
18535 if (nop_opcode == NOP_OPCODE_MICROMIPS)
18537 md_number_to_chars (p, micromips_nop16_insn.insn_opcode, 2);
18542 /* Fall through. */
18545 /* Fall through. */
18550 md_number_to_chars (p, opcode, size);
18551 fragp->fr_var = size;
18555 md_obj_begin (void)
18562 /* Check for premature end, nesting errors, etc. */
18564 as_warn (_("missing .end at end of assembly"));
18573 if (*input_line_pointer == '-')
18575 ++input_line_pointer;
18578 if (!ISDIGIT (*input_line_pointer))
18579 as_bad (_("expected simple number"));
18580 if (input_line_pointer[0] == '0')
18582 if (input_line_pointer[1] == 'x')
18584 input_line_pointer += 2;
18585 while (ISXDIGIT (*input_line_pointer))
18588 val |= hex_value (*input_line_pointer++);
18590 return negative ? -val : val;
18594 ++input_line_pointer;
18595 while (ISDIGIT (*input_line_pointer))
18598 val |= *input_line_pointer++ - '0';
18600 return negative ? -val : val;
18603 if (!ISDIGIT (*input_line_pointer))
18605 printf (_(" *input_line_pointer == '%c' 0x%02x\n"),
18606 *input_line_pointer, *input_line_pointer);
18607 as_warn (_("invalid number"));
18610 while (ISDIGIT (*input_line_pointer))
18613 val += *input_line_pointer++ - '0';
18615 return negative ? -val : val;
18618 /* The .file directive; just like the usual .file directive, but there
18619 is an initial number which is the ECOFF file index. In the non-ECOFF
18620 case .file implies DWARF-2. */
18623 s_mips_file (int x ATTRIBUTE_UNUSED)
18625 static int first_file_directive = 0;
18627 if (ECOFF_DEBUGGING)
18636 filename = dwarf2_directive_file (0);
18638 /* Versions of GCC up to 3.1 start files with a ".file"
18639 directive even for stabs output. Make sure that this
18640 ".file" is handled. Note that you need a version of GCC
18641 after 3.1 in order to support DWARF-2 on MIPS. */
18642 if (filename != NULL && ! first_file_directive)
18644 (void) new_logical_line (filename, -1);
18645 s_app_file_string (filename, 0);
18647 first_file_directive = 1;
18651 /* The .loc directive, implying DWARF-2. */
18654 s_mips_loc (int x ATTRIBUTE_UNUSED)
18656 if (!ECOFF_DEBUGGING)
18657 dwarf2_directive_loc (0);
18660 /* The .end directive. */
18663 s_mips_end (int x ATTRIBUTE_UNUSED)
18667 /* Following functions need their own .frame and .cprestore directives. */
18668 mips_frame_reg_valid = 0;
18669 mips_cprestore_valid = 0;
18671 if (!is_end_of_line[(unsigned char) *input_line_pointer])
18674 demand_empty_rest_of_line ();
18679 if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) == 0)
18680 as_warn (_(".end not in text section"));
18684 as_warn (_(".end directive without a preceding .ent directive."));
18685 demand_empty_rest_of_line ();
18691 gas_assert (S_GET_NAME (p));
18692 if (strcmp (S_GET_NAME (p), S_GET_NAME (cur_proc_ptr->func_sym)))
18693 as_warn (_(".end symbol does not match .ent symbol."));
18695 if (debug_type == DEBUG_STABS)
18696 stabs_generate_asm_endfunc (S_GET_NAME (p),
18700 as_warn (_(".end directive missing or unknown symbol"));
18703 /* Create an expression to calculate the size of the function. */
18704 if (p && cur_proc_ptr)
18706 OBJ_SYMFIELD_TYPE *obj = symbol_get_obj (p);
18707 expressionS *exp = xmalloc (sizeof (expressionS));
18710 exp->X_op = O_subtract;
18711 exp->X_add_symbol = symbol_temp_new_now ();
18712 exp->X_op_symbol = p;
18713 exp->X_add_number = 0;
18715 cur_proc_ptr->func_end_sym = exp->X_add_symbol;
18718 /* Generate a .pdr section. */
18719 if (IS_ELF && !ECOFF_DEBUGGING && mips_flag_pdr)
18721 segT saved_seg = now_seg;
18722 subsegT saved_subseg = now_subseg;
18726 #ifdef md_flush_pending_output
18727 md_flush_pending_output ();
18730 gas_assert (pdr_seg);
18731 subseg_set (pdr_seg, 0);
18733 /* Write the symbol. */
18734 exp.X_op = O_symbol;
18735 exp.X_add_symbol = p;
18736 exp.X_add_number = 0;
18737 emit_expr (&exp, 4);
18739 fragp = frag_more (7 * 4);
18741 md_number_to_chars (fragp, cur_proc_ptr->reg_mask, 4);
18742 md_number_to_chars (fragp + 4, cur_proc_ptr->reg_offset, 4);
18743 md_number_to_chars (fragp + 8, cur_proc_ptr->fpreg_mask, 4);
18744 md_number_to_chars (fragp + 12, cur_proc_ptr->fpreg_offset, 4);
18745 md_number_to_chars (fragp + 16, cur_proc_ptr->frame_offset, 4);
18746 md_number_to_chars (fragp + 20, cur_proc_ptr->frame_reg, 4);
18747 md_number_to_chars (fragp + 24, cur_proc_ptr->pc_reg, 4);
18749 subseg_set (saved_seg, saved_subseg);
18751 #endif /* OBJ_ELF */
18753 cur_proc_ptr = NULL;
18756 /* The .aent and .ent directives. */
18759 s_mips_ent (int aent)
18763 symbolP = get_symbol ();
18764 if (*input_line_pointer == ',')
18765 ++input_line_pointer;
18766 SKIP_WHITESPACE ();
18767 if (ISDIGIT (*input_line_pointer)
18768 || *input_line_pointer == '-')
18771 if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) == 0)
18772 as_warn (_(".ent or .aent not in text section."));
18774 if (!aent && cur_proc_ptr)
18775 as_warn (_("missing .end"));
18779 /* This function needs its own .frame and .cprestore directives. */
18780 mips_frame_reg_valid = 0;
18781 mips_cprestore_valid = 0;
18783 cur_proc_ptr = &cur_proc;
18784 memset (cur_proc_ptr, '\0', sizeof (procS));
18786 cur_proc_ptr->func_sym = symbolP;
18790 if (debug_type == DEBUG_STABS)
18791 stabs_generate_asm_func (S_GET_NAME (symbolP),
18792 S_GET_NAME (symbolP));
18795 symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION;
18797 demand_empty_rest_of_line ();
18800 /* The .frame directive. If the mdebug section is present (IRIX 5 native)
18801 then ecoff.c (ecoff_directive_frame) is used. For embedded targets,
18802 s_mips_frame is used so that we can set the PDR information correctly.
18803 We can't use the ecoff routines because they make reference to the ecoff
18804 symbol table (in the mdebug section). */
18807 s_mips_frame (int ignore ATTRIBUTE_UNUSED)
18810 if (IS_ELF && !ECOFF_DEBUGGING)
18814 if (cur_proc_ptr == (procS *) NULL)
18816 as_warn (_(".frame outside of .ent"));
18817 demand_empty_rest_of_line ();
18821 cur_proc_ptr->frame_reg = tc_get_register (1);
18823 SKIP_WHITESPACE ();
18824 if (*input_line_pointer++ != ','
18825 || get_absolute_expression_and_terminator (&val) != ',')
18827 as_warn (_("Bad .frame directive"));
18828 --input_line_pointer;
18829 demand_empty_rest_of_line ();
18833 cur_proc_ptr->frame_offset = val;
18834 cur_proc_ptr->pc_reg = tc_get_register (0);
18836 demand_empty_rest_of_line ();
18839 #endif /* OBJ_ELF */
18843 /* The .fmask and .mask directives. If the mdebug section is present
18844 (IRIX 5 native) then ecoff.c (ecoff_directive_mask) is used. For
18845 embedded targets, s_mips_mask is used so that we can set the PDR
18846 information correctly. We can't use the ecoff routines because they
18847 make reference to the ecoff symbol table (in the mdebug section). */
18850 s_mips_mask (int reg_type)
18853 if (IS_ELF && !ECOFF_DEBUGGING)
18857 if (cur_proc_ptr == (procS *) NULL)
18859 as_warn (_(".mask/.fmask outside of .ent"));
18860 demand_empty_rest_of_line ();
18864 if (get_absolute_expression_and_terminator (&mask) != ',')
18866 as_warn (_("Bad .mask/.fmask directive"));
18867 --input_line_pointer;
18868 demand_empty_rest_of_line ();
18872 off = get_absolute_expression ();
18874 if (reg_type == 'F')
18876 cur_proc_ptr->fpreg_mask = mask;
18877 cur_proc_ptr->fpreg_offset = off;
18881 cur_proc_ptr->reg_mask = mask;
18882 cur_proc_ptr->reg_offset = off;
18885 demand_empty_rest_of_line ();
18888 #endif /* OBJ_ELF */
18889 s_ignore (reg_type);
18892 /* A table describing all the processors gas knows about. Names are
18893 matched in the order listed.
18895 To ease comparison, please keep this table in the same order as
18896 gcc's mips_cpu_info_table[]. */
18897 static const struct mips_cpu_info mips_cpu_info_table[] =
18899 /* Entries for generic ISAs */
18900 { "mips1", MIPS_CPU_IS_ISA, ISA_MIPS1, CPU_R3000 },
18901 { "mips2", MIPS_CPU_IS_ISA, ISA_MIPS2, CPU_R6000 },
18902 { "mips3", MIPS_CPU_IS_ISA, ISA_MIPS3, CPU_R4000 },
18903 { "mips4", MIPS_CPU_IS_ISA, ISA_MIPS4, CPU_R8000 },
18904 { "mips5", MIPS_CPU_IS_ISA, ISA_MIPS5, CPU_MIPS5 },
18905 { "mips32", MIPS_CPU_IS_ISA, ISA_MIPS32, CPU_MIPS32 },
18906 { "mips32r2", MIPS_CPU_IS_ISA, ISA_MIPS32R2, CPU_MIPS32R2 },
18907 { "mips64", MIPS_CPU_IS_ISA, ISA_MIPS64, CPU_MIPS64 },
18908 { "mips64r2", MIPS_CPU_IS_ISA, ISA_MIPS64R2, CPU_MIPS64R2 },
18911 { "r3000", 0, ISA_MIPS1, CPU_R3000 },
18912 { "r2000", 0, ISA_MIPS1, CPU_R3000 },
18913 { "r3900", 0, ISA_MIPS1, CPU_R3900 },
18916 { "r6000", 0, ISA_MIPS2, CPU_R6000 },
18919 { "r4000", 0, ISA_MIPS3, CPU_R4000 },
18920 { "r4010", 0, ISA_MIPS2, CPU_R4010 },
18921 { "vr4100", 0, ISA_MIPS3, CPU_VR4100 },
18922 { "vr4111", 0, ISA_MIPS3, CPU_R4111 },
18923 { "vr4120", 0, ISA_MIPS3, CPU_VR4120 },
18924 { "vr4130", 0, ISA_MIPS3, CPU_VR4120 },
18925 { "vr4181", 0, ISA_MIPS3, CPU_R4111 },
18926 { "vr4300", 0, ISA_MIPS3, CPU_R4300 },
18927 { "r4400", 0, ISA_MIPS3, CPU_R4400 },
18928 { "r4600", 0, ISA_MIPS3, CPU_R4600 },
18929 { "orion", 0, ISA_MIPS3, CPU_R4600 },
18930 { "r4650", 0, ISA_MIPS3, CPU_R4650 },
18931 /* ST Microelectronics Loongson 2E and 2F cores */
18932 { "loongson2e", 0, ISA_MIPS3, CPU_LOONGSON_2E },
18933 { "loongson2f", 0, ISA_MIPS3, CPU_LOONGSON_2F },
18936 { "r8000", 0, ISA_MIPS4, CPU_R8000 },
18937 { "r10000", 0, ISA_MIPS4, CPU_R10000 },
18938 { "r12000", 0, ISA_MIPS4, CPU_R12000 },
18939 { "r14000", 0, ISA_MIPS4, CPU_R14000 },
18940 { "r16000", 0, ISA_MIPS4, CPU_R16000 },
18941 { "vr5000", 0, ISA_MIPS4, CPU_R5000 },
18942 { "vr5400", 0, ISA_MIPS4, CPU_VR5400 },
18943 { "vr5500", 0, ISA_MIPS4, CPU_VR5500 },
18944 { "rm5200", 0, ISA_MIPS4, CPU_R5000 },
18945 { "rm5230", 0, ISA_MIPS4, CPU_R5000 },
18946 { "rm5231", 0, ISA_MIPS4, CPU_R5000 },
18947 { "rm5261", 0, ISA_MIPS4, CPU_R5000 },
18948 { "rm5721", 0, ISA_MIPS4, CPU_R5000 },
18949 { "rm7000", 0, ISA_MIPS4, CPU_RM7000 },
18950 { "rm9000", 0, ISA_MIPS4, CPU_RM9000 },
18953 { "4kc", 0, ISA_MIPS32, CPU_MIPS32 },
18954 { "4km", 0, ISA_MIPS32, CPU_MIPS32 },
18955 { "4kp", 0, ISA_MIPS32, CPU_MIPS32 },
18956 { "4ksc", MIPS_CPU_ASE_SMARTMIPS, ISA_MIPS32, CPU_MIPS32 },
18958 /* MIPS 32 Release 2 */
18959 { "4kec", 0, ISA_MIPS32R2, CPU_MIPS32R2 },
18960 { "4kem", 0, ISA_MIPS32R2, CPU_MIPS32R2 },
18961 { "4kep", 0, ISA_MIPS32R2, CPU_MIPS32R2 },
18962 { "4ksd", MIPS_CPU_ASE_SMARTMIPS, ISA_MIPS32R2, CPU_MIPS32R2 },
18963 { "m4k", 0, ISA_MIPS32R2, CPU_MIPS32R2 },
18964 { "m4kp", 0, ISA_MIPS32R2, CPU_MIPS32R2 },
18965 { "m14k", MIPS_CPU_ASE_MCU, ISA_MIPS32R2, CPU_MIPS32R2 },
18966 { "m14kc", MIPS_CPU_ASE_MCU, ISA_MIPS32R2, CPU_MIPS32R2 },
18967 { "m14ke", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_DSPR2 | MIPS_CPU_ASE_MCU,
18968 ISA_MIPS32R2, CPU_MIPS32R2 },
18969 { "m14kec", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_DSPR2 | MIPS_CPU_ASE_MCU,
18970 ISA_MIPS32R2, CPU_MIPS32R2 },
18971 { "24kc", 0, ISA_MIPS32R2, CPU_MIPS32R2 },
18972 { "24kf2_1", 0, ISA_MIPS32R2, CPU_MIPS32R2 },
18973 { "24kf", 0, ISA_MIPS32R2, CPU_MIPS32R2 },
18974 { "24kf1_1", 0, ISA_MIPS32R2, CPU_MIPS32R2 },
18975 /* Deprecated forms of the above. */
18976 { "24kfx", 0, ISA_MIPS32R2, CPU_MIPS32R2 },
18977 { "24kx", 0, ISA_MIPS32R2, CPU_MIPS32R2 },
18978 /* 24KE is a 24K with DSP ASE, other ASEs are optional. */
18979 { "24kec", MIPS_CPU_ASE_DSP, ISA_MIPS32R2, CPU_MIPS32R2 },
18980 { "24kef2_1", MIPS_CPU_ASE_DSP, ISA_MIPS32R2, CPU_MIPS32R2 },
18981 { "24kef", MIPS_CPU_ASE_DSP, ISA_MIPS32R2, CPU_MIPS32R2 },
18982 { "24kef1_1", MIPS_CPU_ASE_DSP, ISA_MIPS32R2, CPU_MIPS32R2 },
18983 /* Deprecated forms of the above. */
18984 { "24kefx", MIPS_CPU_ASE_DSP, ISA_MIPS32R2, CPU_MIPS32R2 },
18985 { "24kex", MIPS_CPU_ASE_DSP, ISA_MIPS32R2, CPU_MIPS32R2 },
18986 /* 34K is a 24K with DSP and MT ASE, other ASEs are optional. */
18987 { "34kc", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_MT,
18988 ISA_MIPS32R2, CPU_MIPS32R2 },
18989 { "34kf2_1", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_MT,
18990 ISA_MIPS32R2, CPU_MIPS32R2 },
18991 { "34kf", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_MT,
18992 ISA_MIPS32R2, CPU_MIPS32R2 },
18993 { "34kf1_1", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_MT,
18994 ISA_MIPS32R2, CPU_MIPS32R2 },
18995 /* Deprecated forms of the above. */
18996 { "34kfx", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_MT,
18997 ISA_MIPS32R2, CPU_MIPS32R2 },
18998 { "34kx", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_MT,
18999 ISA_MIPS32R2, CPU_MIPS32R2 },
19000 /* 74K with DSP and DSPR2 ASE, other ASEs are optional. */
19001 { "74kc", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_DSPR2,
19002 ISA_MIPS32R2, CPU_MIPS32R2 },
19003 { "74kf2_1", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_DSPR2,
19004 ISA_MIPS32R2, CPU_MIPS32R2 },
19005 { "74kf", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_DSPR2,
19006 ISA_MIPS32R2, CPU_MIPS32R2 },
19007 { "74kf1_1", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_DSPR2,
19008 ISA_MIPS32R2, CPU_MIPS32R2 },
19009 { "74kf3_2", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_DSPR2,
19010 ISA_MIPS32R2, CPU_MIPS32R2 },
19011 /* Deprecated forms of the above. */
19012 { "74kfx", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_DSPR2,
19013 ISA_MIPS32R2, CPU_MIPS32R2 },
19014 { "74kx", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_DSPR2,
19015 ISA_MIPS32R2, CPU_MIPS32R2 },
19016 /* 1004K cores are multiprocessor versions of the 34K. */
19017 { "1004kc", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_MT,
19018 ISA_MIPS32R2, CPU_MIPS32R2 },
19019 { "1004kf2_1", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_MT,
19020 ISA_MIPS32R2, CPU_MIPS32R2 },
19021 { "1004kf", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_MT,
19022 ISA_MIPS32R2, CPU_MIPS32R2 },
19023 { "1004kf1_1", MIPS_CPU_ASE_DSP | MIPS_CPU_ASE_MT,
19024 ISA_MIPS32R2, CPU_MIPS32R2 },
19027 { "5kc", 0, ISA_MIPS64, CPU_MIPS64 },
19028 { "5kf", 0, ISA_MIPS64, CPU_MIPS64 },
19029 { "20kc", MIPS_CPU_ASE_MIPS3D, ISA_MIPS64, CPU_MIPS64 },
19030 { "25kf", MIPS_CPU_ASE_MIPS3D, ISA_MIPS64, CPU_MIPS64 },
19032 /* Broadcom SB-1 CPU core */
19033 { "sb1", MIPS_CPU_ASE_MIPS3D | MIPS_CPU_ASE_MDMX,
19034 ISA_MIPS64, CPU_SB1 },
19035 /* Broadcom SB-1A CPU core */
19036 { "sb1a", MIPS_CPU_ASE_MIPS3D | MIPS_CPU_ASE_MDMX,
19037 ISA_MIPS64, CPU_SB1 },
19039 { "loongson3a", 0, ISA_MIPS64, CPU_LOONGSON_3A },
19041 /* MIPS 64 Release 2 */
19043 /* Cavium Networks Octeon CPU core */
19044 { "octeon", 0, ISA_MIPS64R2, CPU_OCTEON },
19047 { "xlr", 0, ISA_MIPS64, CPU_XLR },
19054 /* Return true if GIVEN is the same as CANONICAL, or if it is CANONICAL
19055 with a final "000" replaced by "k". Ignore case.
19057 Note: this function is shared between GCC and GAS. */
19060 mips_strict_matching_cpu_name_p (const char *canonical, const char *given)
19062 while (*given != 0 && TOLOWER (*given) == TOLOWER (*canonical))
19063 given++, canonical++;
19065 return ((*given == 0 && *canonical == 0)
19066 || (strcmp (canonical, "000") == 0 && strcasecmp (given, "k") == 0));
19070 /* Return true if GIVEN matches CANONICAL, where GIVEN is a user-supplied
19071 CPU name. We've traditionally allowed a lot of variation here.
19073 Note: this function is shared between GCC and GAS. */
19076 mips_matching_cpu_name_p (const char *canonical, const char *given)
19078 /* First see if the name matches exactly, or with a final "000"
19079 turned into "k". */
19080 if (mips_strict_matching_cpu_name_p (canonical, given))
19083 /* If not, try comparing based on numerical designation alone.
19084 See if GIVEN is an unadorned number, or 'r' followed by a number. */
19085 if (TOLOWER (*given) == 'r')
19087 if (!ISDIGIT (*given))
19090 /* Skip over some well-known prefixes in the canonical name,
19091 hoping to find a number there too. */
19092 if (TOLOWER (canonical[0]) == 'v' && TOLOWER (canonical[1]) == 'r')
19094 else if (TOLOWER (canonical[0]) == 'r' && TOLOWER (canonical[1]) == 'm')
19096 else if (TOLOWER (canonical[0]) == 'r')
19099 return mips_strict_matching_cpu_name_p (canonical, given);
19103 /* Parse an option that takes the name of a processor as its argument.
19104 OPTION is the name of the option and CPU_STRING is the argument.
19105 Return the corresponding processor enumeration if the CPU_STRING is
19106 recognized, otherwise report an error and return null.
19108 A similar function exists in GCC. */
19110 static const struct mips_cpu_info *
19111 mips_parse_cpu (const char *option, const char *cpu_string)
19113 const struct mips_cpu_info *p;
19115 /* 'from-abi' selects the most compatible architecture for the given
19116 ABI: MIPS I for 32-bit ABIs and MIPS III for 64-bit ABIs. For the
19117 EABIs, we have to decide whether we're using the 32-bit or 64-bit
19118 version. Look first at the -mgp options, if given, otherwise base
19119 the choice on MIPS_DEFAULT_64BIT.
19121 Treat NO_ABI like the EABIs. One reason to do this is that the
19122 plain 'mips' and 'mips64' configs have 'from-abi' as their default
19123 architecture. This code picks MIPS I for 'mips' and MIPS III for
19124 'mips64', just as we did in the days before 'from-abi'. */
19125 if (strcasecmp (cpu_string, "from-abi") == 0)
19127 if (ABI_NEEDS_32BIT_REGS (mips_abi))
19128 return mips_cpu_info_from_isa (ISA_MIPS1);
19130 if (ABI_NEEDS_64BIT_REGS (mips_abi))
19131 return mips_cpu_info_from_isa (ISA_MIPS3);
19133 if (file_mips_gp32 >= 0)
19134 return mips_cpu_info_from_isa (file_mips_gp32 ? ISA_MIPS1 : ISA_MIPS3);
19136 return mips_cpu_info_from_isa (MIPS_DEFAULT_64BIT
19141 /* 'default' has traditionally been a no-op. Probably not very useful. */
19142 if (strcasecmp (cpu_string, "default") == 0)
19145 for (p = mips_cpu_info_table; p->name != 0; p++)
19146 if (mips_matching_cpu_name_p (p->name, cpu_string))
19149 as_bad (_("Bad value (%s) for %s"), cpu_string, option);
19153 /* Return the canonical processor information for ISA (a member of the
19154 ISA_MIPS* enumeration). */
19156 static const struct mips_cpu_info *
19157 mips_cpu_info_from_isa (int isa)
19161 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
19162 if ((mips_cpu_info_table[i].flags & MIPS_CPU_IS_ISA)
19163 && isa == mips_cpu_info_table[i].isa)
19164 return (&mips_cpu_info_table[i]);
19169 static const struct mips_cpu_info *
19170 mips_cpu_info_from_arch (int arch)
19174 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
19175 if (arch == mips_cpu_info_table[i].cpu)
19176 return (&mips_cpu_info_table[i]);
19182 show (FILE *stream, const char *string, int *col_p, int *first_p)
19186 fprintf (stream, "%24s", "");
19191 fprintf (stream, ", ");
19195 if (*col_p + strlen (string) > 72)
19197 fprintf (stream, "\n%24s", "");
19201 fprintf (stream, "%s", string);
19202 *col_p += strlen (string);
19208 md_show_usage (FILE *stream)
19213 fprintf (stream, _("\
19215 -EB generate big endian output\n\
19216 -EL generate little endian output\n\
19217 -g, -g2 do not remove unneeded NOPs or swap branches\n\
19218 -G NUM allow referencing objects up to NUM bytes\n\
19219 implicitly with the gp register [default 8]\n"));
19220 fprintf (stream, _("\
19221 -mips1 generate MIPS ISA I instructions\n\
19222 -mips2 generate MIPS ISA II instructions\n\
19223 -mips3 generate MIPS ISA III instructions\n\
19224 -mips4 generate MIPS ISA IV instructions\n\
19225 -mips5 generate MIPS ISA V instructions\n\
19226 -mips32 generate MIPS32 ISA instructions\n\
19227 -mips32r2 generate MIPS32 release 2 ISA instructions\n\
19228 -mips64 generate MIPS64 ISA instructions\n\
19229 -mips64r2 generate MIPS64 release 2 ISA instructions\n\
19230 -march=CPU/-mtune=CPU generate code/schedule for CPU, where CPU is one of:\n"));
19234 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
19235 show (stream, mips_cpu_info_table[i].name, &column, &first);
19236 show (stream, "from-abi", &column, &first);
19237 fputc ('\n', stream);
19239 fprintf (stream, _("\
19240 -mCPU equivalent to -march=CPU -mtune=CPU. Deprecated.\n\
19241 -no-mCPU don't generate code specific to CPU.\n\
19242 For -mCPU and -no-mCPU, CPU must be one of:\n"));
19246 show (stream, "3900", &column, &first);
19247 show (stream, "4010", &column, &first);
19248 show (stream, "4100", &column, &first);
19249 show (stream, "4650", &column, &first);
19250 fputc ('\n', stream);
19252 fprintf (stream, _("\
19253 -mips16 generate mips16 instructions\n\
19254 -no-mips16 do not generate mips16 instructions\n"));
19255 fprintf (stream, _("\
19256 -mmicromips generate microMIPS instructions\n\
19257 -mno-micromips do not generate microMIPS instructions\n"));
19258 fprintf (stream, _("\
19259 -msmartmips generate smartmips instructions\n\
19260 -mno-smartmips do not generate smartmips instructions\n"));
19261 fprintf (stream, _("\
19262 -mdsp generate DSP instructions\n\
19263 -mno-dsp do not generate DSP instructions\n"));
19264 fprintf (stream, _("\
19265 -mdspr2 generate DSP R2 instructions\n\
19266 -mno-dspr2 do not generate DSP R2 instructions\n"));
19267 fprintf (stream, _("\
19268 -mmt generate MT instructions\n\
19269 -mno-mt do not generate MT instructions\n"));
19270 fprintf (stream, _("\
19271 -mmcu generate MCU instructions\n\
19272 -mno-mcu do not generate MCU instructions\n"));
19273 fprintf (stream, _("\
19274 -mfix-loongson2f-jump work around Loongson2F JUMP instructions\n\
19275 -mfix-loongson2f-nop work around Loongson2F NOP errata\n\
19276 -mfix-vr4120 work around certain VR4120 errata\n\
19277 -mfix-vr4130 work around VR4130 mflo/mfhi errata\n\
19278 -mfix-24k insert a nop after ERET and DERET instructions\n\
19279 -mfix-cn63xxp1 work around CN63XXP1 PREF errata\n\
19280 -mgp32 use 32-bit GPRs, regardless of the chosen ISA\n\
19281 -mfp32 use 32-bit FPRs, regardless of the chosen ISA\n\
19282 -msym32 assume all symbols have 32-bit values\n\
19283 -O0 remove unneeded NOPs, do not swap branches\n\
19284 -O remove unneeded NOPs and swap branches\n\
19285 --trap, --no-break trap exception on div by 0 and mult overflow\n\
19286 --break, --no-trap break exception on div by 0 and mult overflow\n"));
19287 fprintf (stream, _("\
19288 -mhard-float allow floating-point instructions\n\
19289 -msoft-float do not allow floating-point instructions\n\
19290 -msingle-float only allow 32-bit floating-point operations\n\
19291 -mdouble-float allow 32-bit and 64-bit floating-point operations\n\
19292 --[no-]construct-floats [dis]allow floating point values to be constructed\n"
19295 fprintf (stream, _("\
19296 -KPIC, -call_shared generate SVR4 position independent code\n\
19297 -call_nonpic generate non-PIC code that can operate with DSOs\n\
19298 -mvxworks-pic generate VxWorks position independent code\n\
19299 -non_shared do not generate code that can operate with DSOs\n\
19300 -xgot assume a 32 bit GOT\n\
19301 -mpdr, -mno-pdr enable/disable creation of .pdr sections\n\
19302 -mshared, -mno-shared disable/enable .cpload optimization for\n\
19303 position dependent (non shared) code\n\
19304 -mabi=ABI create ABI conformant object file for:\n"));
19308 show (stream, "32", &column, &first);
19309 show (stream, "o64", &column, &first);
19310 show (stream, "n32", &column, &first);
19311 show (stream, "64", &column, &first);
19312 show (stream, "eabi", &column, &first);
19314 fputc ('\n', stream);
19316 fprintf (stream, _("\
19317 -32 create o32 ABI object file (default)\n\
19318 -n32 create n32 ABI object file\n\
19319 -64 create 64 ABI object file\n"));
19325 mips_dwarf2_format (asection *sec ATTRIBUTE_UNUSED)
19327 if (HAVE_64BIT_SYMBOLS)
19328 return dwarf2_format_64bit_irix;
19330 return dwarf2_format_32bit;
19335 mips_dwarf2_addr_size (void)
19337 if (HAVE_64BIT_OBJECTS)
19343 /* Standard calling conventions leave the CFA at SP on entry. */
19345 mips_cfi_frame_initial_instructions (void)
19347 cfi_add_CFA_def_cfa_register (SP);
19351 tc_mips_regname_to_dw2regnum (char *regname)
19353 unsigned int regnum = -1;
19356 if (reg_lookup (®name, RTYPE_GP | RTYPE_NUM, ®))