1 /* tc-mips.c -- assemble code for a MIPS chip.
2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013
4 Free Software Foundation, Inc.
5 Contributed by the OSF and Ralph Campbell.
6 Written by Keith Knowles and Ralph Campbell, working independently.
7 Modified for ECOFF and R4000 support by Ian Lance Taylor of Cygnus
10 This file is part of GAS.
12 GAS is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 3, or (at your option)
17 GAS is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with GAS; see the file COPYING. If not, write to the Free
24 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
30 #include "safe-ctype.h"
32 #include "opcode/mips.h"
34 #include "dwarf2dbg.h"
35 #include "dw2gencfi.h"
38 #define DBG(x) printf x
44 /* Clean up namespace so we can include obj-elf.h too. */
45 static int mips_output_flavor (void);
46 static int mips_output_flavor (void) { return OUTPUT_FLAVOR; }
47 #undef OBJ_PROCESS_STAB
54 #undef obj_frob_file_after_relocs
55 #undef obj_frob_symbol
57 #undef obj_sec_sym_ok_for_reloc
58 #undef OBJ_COPY_SYMBOL_ATTRIBUTES
61 /* Fix any of them that we actually care about. */
63 #define OUTPUT_FLAVOR mips_output_flavor()
70 #ifndef ECOFF_DEBUGGING
71 #define NO_ECOFF_DEBUGGING
72 #define ECOFF_DEBUGGING 0
75 int mips_flag_mdebug = -1;
77 /* Control generation of .pdr sections. Off by default on IRIX: the native
78 linker doesn't know about and discards them, but relocations against them
79 remain, leading to rld crashes. */
81 int mips_flag_pdr = FALSE;
83 int mips_flag_pdr = TRUE;
88 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
89 static char *mips_regmask_frag;
97 #define PIC_CALL_REG 25
105 #define ILLEGAL_REG (32)
107 #define AT mips_opts.at
109 /* Allow override of standard little-endian ECOFF format. */
111 #ifndef ECOFF_LITTLE_FORMAT
112 #define ECOFF_LITTLE_FORMAT "ecoff-littlemips"
115 extern int target_big_endian;
117 /* The name of the readonly data section. */
118 #define RDATA_SECTION_NAME (OUTPUT_FLAVOR == bfd_target_ecoff_flavour \
120 : OUTPUT_FLAVOR == bfd_target_coff_flavour \
122 : OUTPUT_FLAVOR == bfd_target_elf_flavour \
126 /* Ways in which an instruction can be "appended" to the output. */
128 /* Just add it normally. */
131 /* Add it normally and then add a nop. */
134 /* Turn an instruction with a delay slot into a "compact" version. */
137 /* Insert the instruction before the last one. */
141 /* Information about an instruction, including its format, operands
145 /* The opcode's entry in mips_opcodes or mips16_opcodes. */
146 const struct mips_opcode *insn_mo;
148 /* The 16-bit or 32-bit bitstring of the instruction itself. This is
149 a copy of INSN_MO->match with the operands filled in. If we have
150 decided to use an extended MIPS16 instruction, this includes the
152 unsigned long insn_opcode;
154 /* The frag that contains the instruction. */
157 /* The offset into FRAG of the first instruction byte. */
160 /* The relocs associated with the instruction, if any. */
163 /* True if this entry cannot be moved from its current position. */
164 unsigned int fixed_p : 1;
166 /* True if this instruction occurred in a .set noreorder block. */
167 unsigned int noreorder_p : 1;
169 /* True for mips16 instructions that jump to an absolute address. */
170 unsigned int mips16_absolute_jump_p : 1;
172 /* True if this instruction is complete. */
173 unsigned int complete_p : 1;
175 /* True if this instruction is cleared from history by unconditional
177 unsigned int cleared_p : 1;
180 /* The ABI to use. */
191 /* MIPS ABI we are using for this output file. */
192 static enum mips_abi_level mips_abi = NO_ABI;
194 /* Whether or not we have code that can call pic code. */
195 int mips_abicalls = FALSE;
197 /* Whether or not we have code which can be put into a shared
199 static bfd_boolean mips_in_shared = TRUE;
201 /* This is the set of options which may be modified by the .set
202 pseudo-op. We use a struct so that .set push and .set pop are more
205 struct mips_set_options
207 /* MIPS ISA (Instruction Set Architecture) level. This is set to -1
208 if it has not been initialized. Changed by `.set mipsN', and the
209 -mipsN command line option, and the default CPU. */
211 /* Enabled Application Specific Extensions (ASEs). These are set to -1
212 if they have not been initialized. Changed by `.set <asename>', by
213 command line options, and based on the default architecture. */
223 /* Whether we are assembling for the mips16 processor. 0 if we are
224 not, 1 if we are, and -1 if the value has not been initialized.
225 Changed by `.set mips16' and `.set nomips16', and the -mips16 and
226 -nomips16 command line options, and the default CPU. */
228 /* Whether we are assembling for the mipsMIPS ASE. 0 if we are not,
229 1 if we are, and -1 if the value has not been initialized. Changed
230 by `.set micromips' and `.set nomicromips', and the -mmicromips
231 and -mno-micromips command line options, and the default CPU. */
233 /* Non-zero if we should not reorder instructions. Changed by `.set
234 reorder' and `.set noreorder'. */
236 /* Non-zero if we should not permit the register designated "assembler
237 temporary" to be used in instructions. The value is the register
238 number, normally $at ($1). Changed by `.set at=REG', `.set noat'
239 (same as `.set at=$0') and `.set at' (same as `.set at=$1'). */
241 /* Non-zero if we should warn when a macro instruction expands into
242 more than one machine instruction. Changed by `.set nomacro' and
244 int warn_about_macros;
245 /* Non-zero if we should not move instructions. Changed by `.set
246 move', `.set volatile', `.set nomove', and `.set novolatile'. */
248 /* Non-zero if we should not optimize branches by moving the target
249 of the branch into the delay slot. Actually, we don't perform
250 this optimization anyhow. Changed by `.set bopt' and `.set
253 /* Non-zero if we should not autoextend mips16 instructions.
254 Changed by `.set autoextend' and `.set noautoextend'. */
256 /* Restrict general purpose registers and floating point registers
257 to 32 bit. This is initially determined when -mgp32 or -mfp32
258 is passed but can changed if the assembler code uses .set mipsN. */
261 /* MIPS architecture (CPU) type. Changed by .set arch=FOO, the -march
262 command line option, and the default CPU. */
264 /* True if ".set sym32" is in effect. */
266 /* True if floating-point operations are not allowed. Changed by .set
267 softfloat or .set hardfloat, by command line options -msoft-float or
268 -mhard-float. The default is false. */
269 bfd_boolean soft_float;
271 /* True if only single-precision floating-point operations are allowed.
272 Changed by .set singlefloat or .set doublefloat, command-line options
273 -msingle-float or -mdouble-float. The default is false. */
274 bfd_boolean single_float;
277 /* This is the struct we use to hold the current set of options. Note
278 that we must set the isa field to ISA_UNKNOWN and the ASE fields to
279 -1 to indicate that they have not been initialized. */
281 /* True if -mgp32 was passed. */
282 static int file_mips_gp32 = -1;
284 /* True if -mfp32 was passed. */
285 static int file_mips_fp32 = -1;
287 /* 1 if -msoft-float, 0 if -mhard-float. The default is 0. */
288 static int file_mips_soft_float = 0;
290 /* 1 if -msingle-float, 0 if -mdouble-float. The default is 0. */
291 static int file_mips_single_float = 0;
293 static struct mips_set_options mips_opts =
295 /* isa */ ISA_UNKNOWN, /* ase_mips3d */ -1, /* ase_mdmx */ -1,
296 /* ase_smartmips */ 0, /* ase_dsp */ -1, /* ase_dspr2 */ -1,
297 /* ase_eva */ -1, /* ase_mt */ -1, /* ase_mcu */ -1,
298 /* ase_virt */ -1, /* mips16 */ -1, /* micromips */ -1,
299 /* noreorder */ 0, /* at */ ATREG, /* warn_about_macros */ 0,
300 /* nomove */ 0, /* nobopt */ 0, /* noautoextend */ 0, /* gp32 */ 0,
301 /* fp32 */ 0, /* arch */ CPU_UNKNOWN, /* sym32 */ FALSE,
302 /* soft_float */ FALSE, /* single_float */ FALSE
305 /* These variables are filled in with the masks of registers used.
306 The object format code reads them and puts them in the appropriate
308 unsigned long mips_gprmask;
309 unsigned long mips_cprmask[4];
311 /* MIPS ISA we are using for this output file. */
312 static int file_mips_isa = ISA_UNKNOWN;
314 /* True if any MIPS16 code was produced. */
315 static int file_ase_mips16;
317 #define ISA_SUPPORTS_MIPS16E (mips_opts.isa == ISA_MIPS32 \
318 || mips_opts.isa == ISA_MIPS32R2 \
319 || mips_opts.isa == ISA_MIPS64 \
320 || mips_opts.isa == ISA_MIPS64R2)
322 /* True if any microMIPS code was produced. */
323 static int file_ase_micromips;
325 /* True if we want to create R_MIPS_JALR for jalr $25. */
327 #define MIPS_JALR_HINT_P(EXPR) HAVE_NEWABI
329 /* As a GNU extension, we use R_MIPS_JALR for o32 too. However,
330 because there's no place for any addend, the only acceptable
331 expression is a bare symbol. */
332 #define MIPS_JALR_HINT_P(EXPR) \
333 (!HAVE_IN_PLACE_ADDENDS \
334 || ((EXPR)->X_op == O_symbol && (EXPR)->X_add_number == 0))
337 /* True if -mips3d was passed or implied by arguments passed on the
338 command line (e.g., by -march). */
339 static int file_ase_mips3d;
341 /* True if -mdmx was passed or implied by arguments passed on the
342 command line (e.g., by -march). */
343 static int file_ase_mdmx;
345 /* True if -msmartmips was passed or implied by arguments passed on the
346 command line (e.g., by -march). */
347 static int file_ase_smartmips;
349 #define ISA_SUPPORTS_SMARTMIPS (mips_opts.isa == ISA_MIPS32 \
350 || mips_opts.isa == ISA_MIPS32R2)
352 /* True if -mdsp was passed or implied by arguments passed on the
353 command line (e.g., by -march). */
354 static int file_ase_dsp;
356 #define ISA_SUPPORTS_DSP_ASE (mips_opts.isa == ISA_MIPS32R2 \
357 || mips_opts.isa == ISA_MIPS64R2 \
358 || mips_opts.micromips)
360 #define ISA_SUPPORTS_DSP64_ASE (mips_opts.isa == ISA_MIPS64R2)
362 /* True if -mdspr2 was passed or implied by arguments passed on the
363 command line (e.g., by -march). */
364 static int file_ase_dspr2;
366 #define ISA_SUPPORTS_DSPR2_ASE (mips_opts.isa == ISA_MIPS32R2 \
367 || mips_opts.isa == ISA_MIPS64R2 \
368 || mips_opts.micromips)
370 /* True if -meva was passed or implied by arguments passed on the
371 command line (e.g., by -march). */
372 static int file_ase_eva;
374 #define ISA_SUPPORTS_EVA_ASE (mips_opts.isa == ISA_MIPS32R2 \
375 || mips_opts.isa == ISA_MIPS64R2 \
376 || mips_opts.micromips)
378 /* True if -mmt was passed or implied by arguments passed on the
379 command line (e.g., by -march). */
380 static int file_ase_mt;
382 #define ISA_SUPPORTS_MT_ASE (mips_opts.isa == ISA_MIPS32R2 \
383 || mips_opts.isa == ISA_MIPS64R2)
385 #define ISA_SUPPORTS_MCU_ASE (mips_opts.isa == ISA_MIPS32R2 \
386 || mips_opts.isa == ISA_MIPS64R2 \
387 || mips_opts.micromips)
389 /* True if -mvirt was passed or implied by arguments passed on the
390 command line (e.g., by -march). */
391 static int file_ase_virt;
393 #define ISA_SUPPORTS_VIRT_ASE (mips_opts.isa == ISA_MIPS32R2 \
394 || mips_opts.isa == ISA_MIPS64R2 \
395 || mips_opts.micromips)
397 #define ISA_SUPPORTS_VIRT64_ASE (mips_opts.isa == ISA_MIPS64R2 \
398 || (mips_opts.micromips \
399 && ISA_HAS_64BIT_REGS (mips_opts.isa)))
401 /* The argument of the -march= flag. The architecture we are assembling. */
402 static int file_mips_arch = CPU_UNKNOWN;
403 static const char *mips_arch_string;
405 /* The argument of the -mtune= flag. The architecture for which we
407 static int mips_tune = CPU_UNKNOWN;
408 static const char *mips_tune_string;
410 /* True when generating 32-bit code for a 64-bit processor. */
411 static int mips_32bitmode = 0;
413 /* True if the given ABI requires 32-bit registers. */
414 #define ABI_NEEDS_32BIT_REGS(ABI) ((ABI) == O32_ABI)
416 /* Likewise 64-bit registers. */
417 #define ABI_NEEDS_64BIT_REGS(ABI) \
419 || (ABI) == N64_ABI \
422 /* Return true if ISA supports 64 bit wide gp registers. */
423 #define ISA_HAS_64BIT_REGS(ISA) \
424 ((ISA) == ISA_MIPS3 \
425 || (ISA) == ISA_MIPS4 \
426 || (ISA) == ISA_MIPS5 \
427 || (ISA) == ISA_MIPS64 \
428 || (ISA) == ISA_MIPS64R2)
430 /* Return true if ISA supports 64 bit wide float registers. */
431 #define ISA_HAS_64BIT_FPRS(ISA) \
432 ((ISA) == ISA_MIPS3 \
433 || (ISA) == ISA_MIPS4 \
434 || (ISA) == ISA_MIPS5 \
435 || (ISA) == ISA_MIPS32R2 \
436 || (ISA) == ISA_MIPS64 \
437 || (ISA) == ISA_MIPS64R2)
439 /* Return true if ISA supports 64-bit right rotate (dror et al.)
441 #define ISA_HAS_DROR(ISA) \
442 ((ISA) == ISA_MIPS64R2 \
443 || (mips_opts.micromips \
444 && ISA_HAS_64BIT_REGS (ISA)) \
447 /* Return true if ISA supports 32-bit right rotate (ror et al.)
449 #define ISA_HAS_ROR(ISA) \
450 ((ISA) == ISA_MIPS32R2 \
451 || (ISA) == ISA_MIPS64R2 \
452 || mips_opts.ase_smartmips \
453 || mips_opts.micromips \
456 /* Return true if ISA supports single-precision floats in odd registers. */
457 #define ISA_HAS_ODD_SINGLE_FPR(ISA) \
458 ((ISA) == ISA_MIPS32 \
459 || (ISA) == ISA_MIPS32R2 \
460 || (ISA) == ISA_MIPS64 \
461 || (ISA) == ISA_MIPS64R2)
463 /* Return true if ISA supports move to/from high part of a 64-bit
464 floating-point register. */
465 #define ISA_HAS_MXHC1(ISA) \
466 ((ISA) == ISA_MIPS32R2 \
467 || (ISA) == ISA_MIPS64R2)
469 #define HAVE_32BIT_GPRS \
470 (mips_opts.gp32 || !ISA_HAS_64BIT_REGS (mips_opts.isa))
472 #define HAVE_32BIT_FPRS \
473 (mips_opts.fp32 || !ISA_HAS_64BIT_FPRS (mips_opts.isa))
475 #define HAVE_64BIT_GPRS (!HAVE_32BIT_GPRS)
476 #define HAVE_64BIT_FPRS (!HAVE_32BIT_FPRS)
478 #define HAVE_NEWABI (mips_abi == N32_ABI || mips_abi == N64_ABI)
480 #define HAVE_64BIT_OBJECTS (mips_abi == N64_ABI)
482 /* True if relocations are stored in-place. */
483 #define HAVE_IN_PLACE_ADDENDS (!HAVE_NEWABI)
485 /* The ABI-derived address size. */
486 #define HAVE_64BIT_ADDRESSES \
487 (HAVE_64BIT_GPRS && (mips_abi == EABI_ABI || mips_abi == N64_ABI))
488 #define HAVE_32BIT_ADDRESSES (!HAVE_64BIT_ADDRESSES)
490 /* The size of symbolic constants (i.e., expressions of the form
491 "SYMBOL" or "SYMBOL + OFFSET"). */
492 #define HAVE_32BIT_SYMBOLS \
493 (HAVE_32BIT_ADDRESSES || !HAVE_64BIT_OBJECTS || mips_opts.sym32)
494 #define HAVE_64BIT_SYMBOLS (!HAVE_32BIT_SYMBOLS)
496 /* Addresses are loaded in different ways, depending on the address size
497 in use. The n32 ABI Documentation also mandates the use of additions
498 with overflow checking, but existing implementations don't follow it. */
499 #define ADDRESS_ADD_INSN \
500 (HAVE_32BIT_ADDRESSES ? "addu" : "daddu")
502 #define ADDRESS_ADDI_INSN \
503 (HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu")
505 #define ADDRESS_LOAD_INSN \
506 (HAVE_32BIT_ADDRESSES ? "lw" : "ld")
508 #define ADDRESS_STORE_INSN \
509 (HAVE_32BIT_ADDRESSES ? "sw" : "sd")
511 /* Return true if the given CPU supports the MIPS16 ASE. */
512 #define CPU_HAS_MIPS16(cpu) \
513 (strncmp (TARGET_CPU, "mips16", sizeof ("mips16") - 1) == 0 \
514 || strncmp (TARGET_CANONICAL, "mips-lsi-elf", sizeof ("mips-lsi-elf") - 1) == 0)
516 /* Return true if the given CPU supports the microMIPS ASE. */
517 #define CPU_HAS_MICROMIPS(cpu) 0
519 /* True if CPU has a dror instruction. */
520 #define CPU_HAS_DROR(CPU) ((CPU) == CPU_VR5400 || (CPU) == CPU_VR5500)
522 /* True if CPU has a ror instruction. */
523 #define CPU_HAS_ROR(CPU) CPU_HAS_DROR (CPU)
525 /* True if CPU is in the Octeon family */
526 #define CPU_IS_OCTEON(CPU) ((CPU) == CPU_OCTEON || (CPU) == CPU_OCTEONP || (CPU) == CPU_OCTEON2)
528 /* True if CPU has seq/sne and seqi/snei instructions. */
529 #define CPU_HAS_SEQ(CPU) (CPU_IS_OCTEON (CPU))
531 /* True, if CPU has support for ldc1 and sdc1. */
532 #define CPU_HAS_LDC1_SDC1(CPU) \
533 ((mips_opts.isa != ISA_MIPS1) && ((CPU) != CPU_R5900))
535 /* True if mflo and mfhi can be immediately followed by instructions
536 which write to the HI and LO registers.
538 According to MIPS specifications, MIPS ISAs I, II, and III need
539 (at least) two instructions between the reads of HI/LO and
540 instructions which write them, and later ISAs do not. Contradicting
541 the MIPS specifications, some MIPS IV processor user manuals (e.g.
542 the UM for the NEC Vr5000) document needing the instructions between
543 HI/LO reads and writes, as well. Therefore, we declare only MIPS32,
544 MIPS64 and later ISAs to have the interlocks, plus any specific
545 earlier-ISA CPUs for which CPU documentation declares that the
546 instructions are really interlocked. */
547 #define hilo_interlocks \
548 (mips_opts.isa == ISA_MIPS32 \
549 || mips_opts.isa == ISA_MIPS32R2 \
550 || mips_opts.isa == ISA_MIPS64 \
551 || mips_opts.isa == ISA_MIPS64R2 \
552 || mips_opts.arch == CPU_R4010 \
553 || mips_opts.arch == CPU_R5900 \
554 || mips_opts.arch == CPU_R10000 \
555 || mips_opts.arch == CPU_R12000 \
556 || mips_opts.arch == CPU_R14000 \
557 || mips_opts.arch == CPU_R16000 \
558 || mips_opts.arch == CPU_RM7000 \
559 || mips_opts.arch == CPU_VR5500 \
560 || mips_opts.micromips \
563 /* Whether the processor uses hardware interlocks to protect reads
564 from the GPRs after they are loaded from memory, and thus does not
565 require nops to be inserted. This applies to instructions marked
566 INSN_LOAD_MEMORY_DELAY. These nops are only required at MIPS ISA
567 level I and microMIPS mode instructions are always interlocked. */
568 #define gpr_interlocks \
569 (mips_opts.isa != ISA_MIPS1 \
570 || mips_opts.arch == CPU_R3900 \
571 || mips_opts.arch == CPU_R5900 \
572 || mips_opts.micromips \
575 /* Whether the processor uses hardware interlocks to avoid delays
576 required by coprocessor instructions, and thus does not require
577 nops to be inserted. This applies to instructions marked
578 INSN_LOAD_COPROC_DELAY, INSN_COPROC_MOVE_DELAY, and to delays
579 between instructions marked INSN_WRITE_COND_CODE and ones marked
580 INSN_READ_COND_CODE. These nops are only required at MIPS ISA
581 levels I, II, and III and microMIPS mode instructions are always
583 /* Itbl support may require additional care here. */
584 #define cop_interlocks \
585 ((mips_opts.isa != ISA_MIPS1 \
586 && mips_opts.isa != ISA_MIPS2 \
587 && mips_opts.isa != ISA_MIPS3) \
588 || mips_opts.arch == CPU_R4300 \
589 || mips_opts.micromips \
592 /* Whether the processor uses hardware interlocks to protect reads
593 from coprocessor registers after they are loaded from memory, and
594 thus does not require nops to be inserted. This applies to
595 instructions marked INSN_COPROC_MEMORY_DELAY. These nops are only
596 requires at MIPS ISA level I and microMIPS mode instructions are
597 always interlocked. */
598 #define cop_mem_interlocks \
599 (mips_opts.isa != ISA_MIPS1 \
600 || mips_opts.micromips \
603 /* Is this a mfhi or mflo instruction? */
604 #define MF_HILO_INSN(PINFO) \
605 ((PINFO & INSN_READ_HI) || (PINFO & INSN_READ_LO))
607 /* Whether code compression (either of the MIPS16 or the microMIPS ASEs)
608 has been selected. This implies, in particular, that addresses of text
609 labels have their LSB set. */
610 #define HAVE_CODE_COMPRESSION \
611 ((mips_opts.mips16 | mips_opts.micromips) != 0)
613 /* MIPS PIC level. */
615 enum mips_pic_level mips_pic;
617 /* 1 if we should generate 32 bit offsets from the $gp register in
618 SVR4_PIC mode. Currently has no meaning in other modes. */
619 static int mips_big_got = 0;
621 /* 1 if trap instructions should used for overflow rather than break
623 static int mips_trap = 0;
625 /* 1 if double width floating point constants should not be constructed
626 by assembling two single width halves into two single width floating
627 point registers which just happen to alias the double width destination
628 register. On some architectures this aliasing can be disabled by a bit
629 in the status register, and the setting of this bit cannot be determined
630 automatically at assemble time. */
631 static int mips_disable_float_construction;
633 /* Non-zero if any .set noreorder directives were used. */
635 static int mips_any_noreorder;
637 /* Non-zero if nops should be inserted when the register referenced in
638 an mfhi/mflo instruction is read in the next two instructions. */
639 static int mips_7000_hilo_fix;
641 /* The size of objects in the small data section. */
642 static unsigned int g_switch_value = 8;
643 /* Whether the -G option was used. */
644 static int g_switch_seen = 0;
649 /* If we can determine in advance that GP optimization won't be
650 possible, we can skip the relaxation stuff that tries to produce
651 GP-relative references. This makes delay slot optimization work
654 This function can only provide a guess, but it seems to work for
655 gcc output. It needs to guess right for gcc, otherwise gcc
656 will put what it thinks is a GP-relative instruction in a branch
659 I don't know if a fix is needed for the SVR4_PIC mode. I've only
660 fixed it for the non-PIC mode. KR 95/04/07 */
661 static int nopic_need_relax (symbolS *, int);
663 /* handle of the OPCODE hash table */
664 static struct hash_control *op_hash = NULL;
666 /* The opcode hash table we use for the mips16. */
667 static struct hash_control *mips16_op_hash = NULL;
669 /* The opcode hash table we use for the microMIPS ASE. */
670 static struct hash_control *micromips_op_hash = NULL;
672 /* This array holds the chars that always start a comment. If the
673 pre-processor is disabled, these aren't very useful */
674 const char comment_chars[] = "#";
676 /* This array holds the chars that only start a comment at the beginning of
677 a line. If the line seems to have the form '# 123 filename'
678 .line and .file directives will appear in the pre-processed output */
679 /* Note that input_file.c hand checks for '#' at the beginning of the
680 first line of the input file. This is because the compiler outputs
681 #NO_APP at the beginning of its output. */
682 /* Also note that C style comments are always supported. */
683 const char line_comment_chars[] = "#";
685 /* This array holds machine specific line separator characters. */
686 const char line_separator_chars[] = ";";
688 /* Chars that can be used to separate mant from exp in floating point nums */
689 const char EXP_CHARS[] = "eE";
691 /* Chars that mean this number is a floating point constant */
694 const char FLT_CHARS[] = "rRsSfFdDxXpP";
696 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
697 changed in read.c . Ideally it shouldn't have to know about it at all,
698 but nothing is ideal around here.
701 static char *insn_error;
703 static int auto_align = 1;
705 /* When outputting SVR4 PIC code, the assembler needs to know the
706 offset in the stack frame from which to restore the $gp register.
707 This is set by the .cprestore pseudo-op, and saved in this
709 static offsetT mips_cprestore_offset = -1;
711 /* Similar for NewABI PIC code, where $gp is callee-saved. NewABI has some
712 more optimizations, it can use a register value instead of a memory-saved
713 offset and even an other register than $gp as global pointer. */
714 static offsetT mips_cpreturn_offset = -1;
715 static int mips_cpreturn_register = -1;
716 static int mips_gp_register = GP;
717 static int mips_gprel_offset = 0;
719 /* Whether mips_cprestore_offset has been set in the current function
720 (or whether it has already been warned about, if not). */
721 static int mips_cprestore_valid = 0;
723 /* This is the register which holds the stack frame, as set by the
724 .frame pseudo-op. This is needed to implement .cprestore. */
725 static int mips_frame_reg = SP;
727 /* Whether mips_frame_reg has been set in the current function
728 (or whether it has already been warned about, if not). */
729 static int mips_frame_reg_valid = 0;
731 /* To output NOP instructions correctly, we need to keep information
732 about the previous two instructions. */
734 /* Whether we are optimizing. The default value of 2 means to remove
735 unneeded NOPs and swap branch instructions when possible. A value
736 of 1 means to not swap branches. A value of 0 means to always
738 static int mips_optimize = 2;
740 /* Debugging level. -g sets this to 2. -gN sets this to N. -g0 is
741 equivalent to seeing no -g option at all. */
742 static int mips_debug = 0;
744 /* The maximum number of NOPs needed to avoid the VR4130 mflo/mfhi errata. */
745 #define MAX_VR4130_NOPS 4
747 /* The maximum number of NOPs needed to fill delay slots. */
748 #define MAX_DELAY_NOPS 2
750 /* The maximum number of NOPs needed for any purpose. */
753 /* A list of previous instructions, with index 0 being the most recent.
754 We need to look back MAX_NOPS instructions when filling delay slots
755 or working around processor errata. We need to look back one
756 instruction further if we're thinking about using history[0] to
757 fill a branch delay slot. */
758 static struct mips_cl_insn history[1 + MAX_NOPS];
760 /* Nop instructions used by emit_nop. */
761 static struct mips_cl_insn nop_insn;
762 static struct mips_cl_insn mips16_nop_insn;
763 static struct mips_cl_insn micromips_nop16_insn;
764 static struct mips_cl_insn micromips_nop32_insn;
766 /* The appropriate nop for the current mode. */
767 #define NOP_INSN (mips_opts.mips16 ? &mips16_nop_insn \
768 : (mips_opts.micromips ? µmips_nop16_insn : &nop_insn))
770 /* The size of NOP_INSN in bytes. */
771 #define NOP_INSN_SIZE (HAVE_CODE_COMPRESSION ? 2 : 4)
773 /* If this is set, it points to a frag holding nop instructions which
774 were inserted before the start of a noreorder section. If those
775 nops turn out to be unnecessary, the size of the frag can be
777 static fragS *prev_nop_frag;
779 /* The number of nop instructions we created in prev_nop_frag. */
780 static int prev_nop_frag_holds;
782 /* The number of nop instructions that we know we need in
784 static int prev_nop_frag_required;
786 /* The number of instructions we've seen since prev_nop_frag. */
787 static int prev_nop_frag_since;
789 /* For ECOFF and ELF, relocations against symbols are done in two
790 parts, with a HI relocation and a LO relocation. Each relocation
791 has only 16 bits of space to store an addend. This means that in
792 order for the linker to handle carries correctly, it must be able
793 to locate both the HI and the LO relocation. This means that the
794 relocations must appear in order in the relocation table.
796 In order to implement this, we keep track of each unmatched HI
797 relocation. We then sort them so that they immediately precede the
798 corresponding LO relocation. */
803 struct mips_hi_fixup *next;
806 /* The section this fixup is in. */
810 /* The list of unmatched HI relocs. */
812 static struct mips_hi_fixup *mips_hi_fixup_list;
814 /* The frag containing the last explicit relocation operator.
815 Null if explicit relocations have not been used. */
817 static fragS *prev_reloc_op_frag;
819 /* Map normal MIPS register numbers to mips16 register numbers. */
821 #define X ILLEGAL_REG
822 static const int mips32_to_16_reg_map[] =
824 X, X, 2, 3, 4, 5, 6, 7,
825 X, X, X, X, X, X, X, X,
826 0, 1, X, X, X, X, X, X,
827 X, X, X, X, X, X, X, X
831 /* Map mips16 register numbers to normal MIPS register numbers. */
833 static const unsigned int mips16_to_32_reg_map[] =
835 16, 17, 2, 3, 4, 5, 6, 7
838 /* Map normal MIPS register numbers to microMIPS register numbers. */
840 #define mips32_to_micromips_reg_b_map mips32_to_16_reg_map
841 #define mips32_to_micromips_reg_c_map mips32_to_16_reg_map
842 #define mips32_to_micromips_reg_d_map mips32_to_16_reg_map
843 #define mips32_to_micromips_reg_e_map mips32_to_16_reg_map
844 #define mips32_to_micromips_reg_f_map mips32_to_16_reg_map
845 #define mips32_to_micromips_reg_g_map mips32_to_16_reg_map
846 #define mips32_to_micromips_reg_l_map mips32_to_16_reg_map
848 #define X ILLEGAL_REG
849 /* reg type h: 4, 5, 6. */
850 static const int mips32_to_micromips_reg_h_map[] =
852 X, X, X, X, 4, 5, 6, X,
853 X, X, X, X, X, X, X, X,
854 X, X, X, X, X, X, X, X,
855 X, X, X, X, X, X, X, X
858 /* reg type m: 0, 17, 2, 3, 16, 18, 19, 20. */
859 static const int mips32_to_micromips_reg_m_map[] =
861 0, X, 2, 3, X, X, X, X,
862 X, X, X, X, X, X, X, X,
863 4, 1, 5, 6, 7, X, X, X,
864 X, X, X, X, X, X, X, X
867 /* reg type q: 0, 2-7. 17. */
868 static const int mips32_to_micromips_reg_q_map[] =
870 0, X, 2, 3, 4, 5, 6, 7,
871 X, X, X, X, X, X, X, X,
872 X, 1, X, X, X, X, X, X,
873 X, X, X, X, X, X, X, X
876 #define mips32_to_micromips_reg_n_map mips32_to_micromips_reg_m_map
879 /* Map microMIPS register numbers to normal MIPS register numbers. */
881 #define micromips_to_32_reg_b_map mips16_to_32_reg_map
882 #define micromips_to_32_reg_c_map mips16_to_32_reg_map
883 #define micromips_to_32_reg_d_map mips16_to_32_reg_map
884 #define micromips_to_32_reg_e_map mips16_to_32_reg_map
885 #define micromips_to_32_reg_f_map mips16_to_32_reg_map
886 #define micromips_to_32_reg_g_map mips16_to_32_reg_map
888 /* The microMIPS registers with type h. */
889 static const unsigned int micromips_to_32_reg_h_map[] =
891 5, 5, 6, 4, 4, 4, 4, 4
894 /* The microMIPS registers with type i. */
895 static const unsigned int micromips_to_32_reg_i_map[] =
897 6, 7, 7, 21, 22, 5, 6, 7
900 #define micromips_to_32_reg_l_map mips16_to_32_reg_map
902 /* The microMIPS registers with type m. */
903 static const unsigned int micromips_to_32_reg_m_map[] =
905 0, 17, 2, 3, 16, 18, 19, 20
908 #define micromips_to_32_reg_n_map micromips_to_32_reg_m_map
910 /* The microMIPS registers with type q. */
911 static const unsigned int micromips_to_32_reg_q_map[] =
913 0, 17, 2, 3, 4, 5, 6, 7
916 /* microMIPS imm type B. */
917 static const int micromips_imm_b_map[] =
919 1, 4, 8, 12, 16, 20, 24, -1
922 /* microMIPS imm type C. */
923 static const int micromips_imm_c_map[] =
925 128, 1, 2, 3, 4, 7, 8, 15, 16, 31, 32, 63, 64, 255, 32768, 65535
928 /* Classifies the kind of instructions we're interested in when
929 implementing -mfix-vr4120. */
930 enum fix_vr4120_class
938 NUM_FIX_VR4120_CLASSES
941 /* ...likewise -mfix-loongson2f-jump. */
942 static bfd_boolean mips_fix_loongson2f_jump;
944 /* ...likewise -mfix-loongson2f-nop. */
945 static bfd_boolean mips_fix_loongson2f_nop;
947 /* True if -mfix-loongson2f-nop or -mfix-loongson2f-jump passed. */
948 static bfd_boolean mips_fix_loongson2f;
950 /* Given two FIX_VR4120_* values X and Y, bit Y of element X is set if
951 there must be at least one other instruction between an instruction
952 of type X and an instruction of type Y. */
953 static unsigned int vr4120_conflicts[NUM_FIX_VR4120_CLASSES];
955 /* True if -mfix-vr4120 is in force. */
956 static int mips_fix_vr4120;
958 /* ...likewise -mfix-vr4130. */
959 static int mips_fix_vr4130;
961 /* ...likewise -mfix-24k. */
962 static int mips_fix_24k;
964 /* ...likewise -mfix-cn63xxp1 */
965 static bfd_boolean mips_fix_cn63xxp1;
967 /* We don't relax branches by default, since this causes us to expand
968 `la .l2 - .l1' if there's a branch between .l1 and .l2, because we
969 fail to compute the offset before expanding the macro to the most
970 efficient expansion. */
972 static int mips_relax_branch;
974 /* The expansion of many macros depends on the type of symbol that
975 they refer to. For example, when generating position-dependent code,
976 a macro that refers to a symbol may have two different expansions,
977 one which uses GP-relative addresses and one which uses absolute
978 addresses. When generating SVR4-style PIC, a macro may have
979 different expansions for local and global symbols.
981 We handle these situations by generating both sequences and putting
982 them in variant frags. In position-dependent code, the first sequence
983 will be the GP-relative one and the second sequence will be the
984 absolute one. In SVR4 PIC, the first sequence will be for global
985 symbols and the second will be for local symbols.
987 The frag's "subtype" is RELAX_ENCODE (FIRST, SECOND), where FIRST and
988 SECOND are the lengths of the two sequences in bytes. These fields
989 can be extracted using RELAX_FIRST() and RELAX_SECOND(). In addition,
990 the subtype has the following flags:
993 Set if it has been decided that we should use the second
994 sequence instead of the first.
997 Set in the first variant frag if the macro's second implementation
998 is longer than its first. This refers to the macro as a whole,
999 not an individual relaxation.
1002 Set in the first variant frag if the macro appeared in a .set nomacro
1003 block and if one alternative requires a warning but the other does not.
1006 Like RELAX_NOMACRO, but indicates that the macro appears in a branch
1009 RELAX_DELAY_SLOT_16BIT
1010 Like RELAX_DELAY_SLOT, but indicates that the delay slot requires a
1013 RELAX_DELAY_SLOT_SIZE_FIRST
1014 Like RELAX_DELAY_SLOT, but indicates that the first implementation of
1015 the macro is of the wrong size for the branch delay slot.
1017 RELAX_DELAY_SLOT_SIZE_SECOND
1018 Like RELAX_DELAY_SLOT, but indicates that the second implementation of
1019 the macro is of the wrong size for the branch delay slot.
1021 The frag's "opcode" points to the first fixup for relaxable code.
1023 Relaxable macros are generated using a sequence such as:
1025 relax_start (SYMBOL);
1026 ... generate first expansion ...
1028 ... generate second expansion ...
1031 The code and fixups for the unwanted alternative are discarded
1032 by md_convert_frag. */
1033 #define RELAX_ENCODE(FIRST, SECOND) (((FIRST) << 8) | (SECOND))
1035 #define RELAX_FIRST(X) (((X) >> 8) & 0xff)
1036 #define RELAX_SECOND(X) ((X) & 0xff)
1037 #define RELAX_USE_SECOND 0x10000
1038 #define RELAX_SECOND_LONGER 0x20000
1039 #define RELAX_NOMACRO 0x40000
1040 #define RELAX_DELAY_SLOT 0x80000
1041 #define RELAX_DELAY_SLOT_16BIT 0x100000
1042 #define RELAX_DELAY_SLOT_SIZE_FIRST 0x200000
1043 #define RELAX_DELAY_SLOT_SIZE_SECOND 0x400000
1045 /* Branch without likely bit. If label is out of range, we turn:
1047 beq reg1, reg2, label
1057 with the following opcode replacements:
1064 bltzal <-> bgezal (with jal label instead of j label)
1066 Even though keeping the delay slot instruction in the delay slot of
1067 the branch would be more efficient, it would be very tricky to do
1068 correctly, because we'd have to introduce a variable frag *after*
1069 the delay slot instruction, and expand that instead. Let's do it
1070 the easy way for now, even if the branch-not-taken case now costs
1071 one additional instruction. Out-of-range branches are not supposed
1072 to be common, anyway.
1074 Branch likely. If label is out of range, we turn:
1076 beql reg1, reg2, label
1077 delay slot (annulled if branch not taken)
1086 delay slot (executed only if branch taken)
1089 It would be possible to generate a shorter sequence by losing the
1090 likely bit, generating something like:
1095 delay slot (executed only if branch taken)
1107 bltzall -> bgezal (with jal label instead of j label)
1108 bgezall -> bltzal (ditto)
1111 but it's not clear that it would actually improve performance. */
1112 #define RELAX_BRANCH_ENCODE(at, uncond, likely, link, toofar) \
1113 ((relax_substateT) \
1116 | ((toofar) ? 0x20 : 0) \
1117 | ((link) ? 0x40 : 0) \
1118 | ((likely) ? 0x80 : 0) \
1119 | ((uncond) ? 0x100 : 0)))
1120 #define RELAX_BRANCH_P(i) (((i) & 0xf0000000) == 0xc0000000)
1121 #define RELAX_BRANCH_UNCOND(i) (((i) & 0x100) != 0)
1122 #define RELAX_BRANCH_LIKELY(i) (((i) & 0x80) != 0)
1123 #define RELAX_BRANCH_LINK(i) (((i) & 0x40) != 0)
1124 #define RELAX_BRANCH_TOOFAR(i) (((i) & 0x20) != 0)
1125 #define RELAX_BRANCH_AT(i) ((i) & 0x1f)
1127 /* For mips16 code, we use an entirely different form of relaxation.
1128 mips16 supports two versions of most instructions which take
1129 immediate values: a small one which takes some small value, and a
1130 larger one which takes a 16 bit value. Since branches also follow
1131 this pattern, relaxing these values is required.
1133 We can assemble both mips16 and normal MIPS code in a single
1134 object. Therefore, we need to support this type of relaxation at
1135 the same time that we support the relaxation described above. We
1136 use the high bit of the subtype field to distinguish these cases.
1138 The information we store for this type of relaxation is the
1139 argument code found in the opcode file for this relocation, whether
1140 the user explicitly requested a small or extended form, and whether
1141 the relocation is in a jump or jal delay slot. That tells us the
1142 size of the value, and how it should be stored. We also store
1143 whether the fragment is considered to be extended or not. We also
1144 store whether this is known to be a branch to a different section,
1145 whether we have tried to relax this frag yet, and whether we have
1146 ever extended a PC relative fragment because of a shift count. */
1147 #define RELAX_MIPS16_ENCODE(type, small, ext, dslot, jal_dslot) \
1150 | ((small) ? 0x100 : 0) \
1151 | ((ext) ? 0x200 : 0) \
1152 | ((dslot) ? 0x400 : 0) \
1153 | ((jal_dslot) ? 0x800 : 0))
1154 #define RELAX_MIPS16_P(i) (((i) & 0xc0000000) == 0x80000000)
1155 #define RELAX_MIPS16_TYPE(i) ((i) & 0xff)
1156 #define RELAX_MIPS16_USER_SMALL(i) (((i) & 0x100) != 0)
1157 #define RELAX_MIPS16_USER_EXT(i) (((i) & 0x200) != 0)
1158 #define RELAX_MIPS16_DSLOT(i) (((i) & 0x400) != 0)
1159 #define RELAX_MIPS16_JAL_DSLOT(i) (((i) & 0x800) != 0)
1160 #define RELAX_MIPS16_EXTENDED(i) (((i) & 0x1000) != 0)
1161 #define RELAX_MIPS16_MARK_EXTENDED(i) ((i) | 0x1000)
1162 #define RELAX_MIPS16_CLEAR_EXTENDED(i) ((i) &~ 0x1000)
1163 #define RELAX_MIPS16_LONG_BRANCH(i) (((i) & 0x2000) != 0)
1164 #define RELAX_MIPS16_MARK_LONG_BRANCH(i) ((i) | 0x2000)
1165 #define RELAX_MIPS16_CLEAR_LONG_BRANCH(i) ((i) &~ 0x2000)
1167 /* For microMIPS code, we use relaxation similar to one we use for
1168 MIPS16 code. Some instructions that take immediate values support
1169 two encodings: a small one which takes some small value, and a
1170 larger one which takes a 16 bit value. As some branches also follow
1171 this pattern, relaxing these values is required.
1173 We can assemble both microMIPS and normal MIPS code in a single
1174 object. Therefore, we need to support this type of relaxation at
1175 the same time that we support the relaxation described above. We
1176 use one of the high bits of the subtype field to distinguish these
1179 The information we store for this type of relaxation is the argument
1180 code found in the opcode file for this relocation, the register
1181 selected as the assembler temporary, whether the branch is
1182 unconditional, whether it is compact, whether it stores the link
1183 address implicitly in $ra, whether relaxation of out-of-range 32-bit
1184 branches to a sequence of instructions is enabled, and whether the
1185 displacement of a branch is too large to fit as an immediate argument
1186 of a 16-bit and a 32-bit branch, respectively. */
1187 #define RELAX_MICROMIPS_ENCODE(type, at, uncond, compact, link, \
1188 relax32, toofar16, toofar32) \
1191 | (((at) & 0x1f) << 8) \
1192 | ((uncond) ? 0x2000 : 0) \
1193 | ((compact) ? 0x4000 : 0) \
1194 | ((link) ? 0x8000 : 0) \
1195 | ((relax32) ? 0x10000 : 0) \
1196 | ((toofar16) ? 0x20000 : 0) \
1197 | ((toofar32) ? 0x40000 : 0))
1198 #define RELAX_MICROMIPS_P(i) (((i) & 0xc0000000) == 0x40000000)
1199 #define RELAX_MICROMIPS_TYPE(i) ((i) & 0xff)
1200 #define RELAX_MICROMIPS_AT(i) (((i) >> 8) & 0x1f)
1201 #define RELAX_MICROMIPS_UNCOND(i) (((i) & 0x2000) != 0)
1202 #define RELAX_MICROMIPS_COMPACT(i) (((i) & 0x4000) != 0)
1203 #define RELAX_MICROMIPS_LINK(i) (((i) & 0x8000) != 0)
1204 #define RELAX_MICROMIPS_RELAX32(i) (((i) & 0x10000) != 0)
1206 #define RELAX_MICROMIPS_TOOFAR16(i) (((i) & 0x20000) != 0)
1207 #define RELAX_MICROMIPS_MARK_TOOFAR16(i) ((i) | 0x20000)
1208 #define RELAX_MICROMIPS_CLEAR_TOOFAR16(i) ((i) & ~0x20000)
1209 #define RELAX_MICROMIPS_TOOFAR32(i) (((i) & 0x40000) != 0)
1210 #define RELAX_MICROMIPS_MARK_TOOFAR32(i) ((i) | 0x40000)
1211 #define RELAX_MICROMIPS_CLEAR_TOOFAR32(i) ((i) & ~0x40000)
1213 /* Sign-extend 16-bit value X. */
1214 #define SEXT_16BIT(X) ((((X) + 0x8000) & 0xffff) - 0x8000)
1216 /* Is the given value a sign-extended 32-bit value? */
1217 #define IS_SEXT_32BIT_NUM(x) \
1218 (((x) &~ (offsetT) 0x7fffffff) == 0 \
1219 || (((x) &~ (offsetT) 0x7fffffff) == ~ (offsetT) 0x7fffffff))
1221 /* Is the given value a sign-extended 16-bit value? */
1222 #define IS_SEXT_16BIT_NUM(x) \
1223 (((x) &~ (offsetT) 0x7fff) == 0 \
1224 || (((x) &~ (offsetT) 0x7fff) == ~ (offsetT) 0x7fff))
1226 /* Is the given value a sign-extended 12-bit value? */
1227 #define IS_SEXT_12BIT_NUM(x) \
1228 (((((x) & 0xfff) ^ 0x800LL) - 0x800LL) == (x))
1230 /* Is the given value a sign-extended 9-bit value? */
1231 #define IS_SEXT_9BIT_NUM(x) \
1232 (((((x) & 0x1ff) ^ 0x100LL) - 0x100LL) == (x))
1234 /* Is the given value a zero-extended 32-bit value? Or a negated one? */
1235 #define IS_ZEXT_32BIT_NUM(x) \
1236 (((x) &~ (offsetT) 0xffffffff) == 0 \
1237 || (((x) &~ (offsetT) 0xffffffff) == ~ (offsetT) 0xffffffff))
1239 /* Replace bits MASK << SHIFT of STRUCT with the equivalent bits in
1240 VALUE << SHIFT. VALUE is evaluated exactly once. */
1241 #define INSERT_BITS(STRUCT, VALUE, MASK, SHIFT) \
1242 (STRUCT) = (((STRUCT) & ~((MASK) << (SHIFT))) \
1243 | (((VALUE) & (MASK)) << (SHIFT)))
1245 /* Extract bits MASK << SHIFT from STRUCT and shift them right
1247 #define EXTRACT_BITS(STRUCT, MASK, SHIFT) \
1248 (((STRUCT) >> (SHIFT)) & (MASK))
1250 /* Change INSN's opcode so that the operand given by FIELD has value VALUE.
1251 INSN is a mips_cl_insn structure and VALUE is evaluated exactly once.
1253 include/opcode/mips.h specifies operand fields using the macros
1254 OP_MASK_<FIELD> and OP_SH_<FIELD>. The MIPS16 equivalents start
1255 with "MIPS16OP" instead of "OP". */
1256 #define INSERT_OPERAND(MICROMIPS, FIELD, INSN, VALUE) \
1259 INSERT_BITS ((INSN).insn_opcode, VALUE, \
1260 OP_MASK_##FIELD, OP_SH_##FIELD); \
1262 INSERT_BITS ((INSN).insn_opcode, VALUE, \
1263 MICROMIPSOP_MASK_##FIELD, MICROMIPSOP_SH_##FIELD); \
1265 #define MIPS16_INSERT_OPERAND(FIELD, INSN, VALUE) \
1266 INSERT_BITS ((INSN).insn_opcode, VALUE, \
1267 MIPS16OP_MASK_##FIELD, MIPS16OP_SH_##FIELD)
1269 /* Extract the operand given by FIELD from mips_cl_insn INSN. */
1270 #define EXTRACT_OPERAND(MICROMIPS, FIELD, INSN) \
1272 ? EXTRACT_BITS ((INSN).insn_opcode, OP_MASK_##FIELD, OP_SH_##FIELD) \
1273 : EXTRACT_BITS ((INSN).insn_opcode, \
1274 MICROMIPSOP_MASK_##FIELD, MICROMIPSOP_SH_##FIELD))
1275 #define MIPS16_EXTRACT_OPERAND(FIELD, INSN) \
1276 EXTRACT_BITS ((INSN).insn_opcode, \
1277 MIPS16OP_MASK_##FIELD, \
1278 MIPS16OP_SH_##FIELD)
1280 /* The MIPS16 EXTEND opcode, shifted left 16 places. */
1281 #define MIPS16_EXTEND (0xf000U << 16)
1283 /* Whether or not we are emitting a branch-likely macro. */
1284 static bfd_boolean emit_branch_likely_macro = FALSE;
1286 /* Global variables used when generating relaxable macros. See the
1287 comment above RELAX_ENCODE for more details about how relaxation
1290 /* 0 if we're not emitting a relaxable macro.
1291 1 if we're emitting the first of the two relaxation alternatives.
1292 2 if we're emitting the second alternative. */
1295 /* The first relaxable fixup in the current frag. (In other words,
1296 the first fixup that refers to relaxable code.) */
1299 /* sizes[0] says how many bytes of the first alternative are stored in
1300 the current frag. Likewise sizes[1] for the second alternative. */
1301 unsigned int sizes[2];
1303 /* The symbol on which the choice of sequence depends. */
1307 /* Global variables used to decide whether a macro needs a warning. */
1309 /* True if the macro is in a branch delay slot. */
1310 bfd_boolean delay_slot_p;
1312 /* Set to the length in bytes required if the macro is in a delay slot
1313 that requires a specific length of instruction, otherwise zero. */
1314 unsigned int delay_slot_length;
1316 /* For relaxable macros, sizes[0] is the length of the first alternative
1317 in bytes and sizes[1] is the length of the second alternative.
1318 For non-relaxable macros, both elements give the length of the
1320 unsigned int sizes[2];
1322 /* For relaxable macros, first_insn_sizes[0] is the length of the first
1323 instruction of the first alternative in bytes and first_insn_sizes[1]
1324 is the length of the first instruction of the second alternative.
1325 For non-relaxable macros, both elements give the length of the first
1326 instruction in bytes.
1328 Set to zero if we haven't yet seen the first instruction. */
1329 unsigned int first_insn_sizes[2];
1331 /* For relaxable macros, insns[0] is the number of instructions for the
1332 first alternative and insns[1] is the number of instructions for the
1335 For non-relaxable macros, both elements give the number of
1336 instructions for the macro. */
1337 unsigned int insns[2];
1339 /* The first variant frag for this macro. */
1341 } mips_macro_warning;
1343 /* Prototypes for static functions. */
1345 enum mips_regclass { MIPS_GR_REG, MIPS_FP_REG, MIPS16_REG };
1347 static void append_insn
1348 (struct mips_cl_insn *, expressionS *, bfd_reloc_code_real_type *,
1349 bfd_boolean expansionp);
1350 static void mips_no_prev_insn (void);
1351 static void macro_build (expressionS *, const char *, const char *, ...);
1352 static void mips16_macro_build
1353 (expressionS *, const char *, const char *, va_list *);
1354 static void load_register (int, expressionS *, int);
1355 static void macro_start (void);
1356 static void macro_end (void);
1357 static void macro (struct mips_cl_insn * ip);
1358 static void mips16_macro (struct mips_cl_insn * ip);
1359 static void mips_ip (char *str, struct mips_cl_insn * ip);
1360 static void mips16_ip (char *str, struct mips_cl_insn * ip);
1361 static void mips16_immed
1362 (char *, unsigned int, int, bfd_reloc_code_real_type, offsetT,
1363 unsigned int, unsigned long *);
1364 static size_t my_getSmallExpression
1365 (expressionS *, bfd_reloc_code_real_type *, char *);
1366 static void my_getExpression (expressionS *, char *);
1367 static void s_align (int);
1368 static void s_change_sec (int);
1369 static void s_change_section (int);
1370 static void s_cons (int);
1371 static void s_float_cons (int);
1372 static void s_mips_globl (int);
1373 static void s_option (int);
1374 static void s_mipsset (int);
1375 static void s_abicalls (int);
1376 static void s_cpload (int);
1377 static void s_cpsetup (int);
1378 static void s_cplocal (int);
1379 static void s_cprestore (int);
1380 static void s_cpreturn (int);
1381 static void s_dtprelword (int);
1382 static void s_dtpreldword (int);
1383 static void s_tprelword (int);
1384 static void s_tpreldword (int);
1385 static void s_gpvalue (int);
1386 static void s_gpword (int);
1387 static void s_gpdword (int);
1388 static void s_ehword (int);
1389 static void s_cpadd (int);
1390 static void s_insn (int);
1391 static void md_obj_begin (void);
1392 static void md_obj_end (void);
1393 static void s_mips_ent (int);
1394 static void s_mips_end (int);
1395 static void s_mips_frame (int);
1396 static void s_mips_mask (int reg_type);
1397 static void s_mips_stab (int);
1398 static void s_mips_weakext (int);
1399 static void s_mips_file (int);
1400 static void s_mips_loc (int);
1401 static bfd_boolean pic_need_relax (symbolS *, asection *);
1402 static int relaxed_branch_length (fragS *, asection *, int);
1403 static int validate_mips_insn (const struct mips_opcode *);
1404 static int validate_micromips_insn (const struct mips_opcode *);
1405 static int relaxed_micromips_16bit_branch_length (fragS *, asection *, int);
1406 static int relaxed_micromips_32bit_branch_length (fragS *, asection *, int);
1408 /* Table and functions used to map between CPU/ISA names, and
1409 ISA levels, and CPU numbers. */
1411 struct mips_cpu_info
1413 const char *name; /* CPU or ISA name. */
1414 int flags; /* MIPS_CPU_* flags. */
1415 int ase; /* Set of ASEs implemented by the CPU. */
1416 int isa; /* ISA level. */
1417 int cpu; /* CPU number (default CPU if ISA). */
1420 #define MIPS_CPU_IS_ISA 0x0001 /* Is this an ISA? (If 0, a CPU.) */
1422 static const struct mips_cpu_info *mips_parse_cpu (const char *, const char *);
1423 static const struct mips_cpu_info *mips_cpu_info_from_isa (int);
1424 static const struct mips_cpu_info *mips_cpu_info_from_arch (int);
1428 The following pseudo-ops from the Kane and Heinrich MIPS book
1429 should be defined here, but are currently unsupported: .alias,
1430 .galive, .gjaldef, .gjrlive, .livereg, .noalias.
1432 The following pseudo-ops from the Kane and Heinrich MIPS book are
1433 specific to the type of debugging information being generated, and
1434 should be defined by the object format: .aent, .begin, .bend,
1435 .bgnb, .end, .endb, .ent, .fmask, .frame, .loc, .mask, .verstamp,
1438 The following pseudo-ops from the Kane and Heinrich MIPS book are
1439 not MIPS CPU specific, but are also not specific to the object file
1440 format. This file is probably the best place to define them, but
1441 they are not currently supported: .asm0, .endr, .lab, .struct. */
1443 static const pseudo_typeS mips_pseudo_table[] =
1445 /* MIPS specific pseudo-ops. */
1446 {"option", s_option, 0},
1447 {"set", s_mipsset, 0},
1448 {"rdata", s_change_sec, 'r'},
1449 {"sdata", s_change_sec, 's'},
1450 {"livereg", s_ignore, 0},
1451 {"abicalls", s_abicalls, 0},
1452 {"cpload", s_cpload, 0},
1453 {"cpsetup", s_cpsetup, 0},
1454 {"cplocal", s_cplocal, 0},
1455 {"cprestore", s_cprestore, 0},
1456 {"cpreturn", s_cpreturn, 0},
1457 {"dtprelword", s_dtprelword, 0},
1458 {"dtpreldword", s_dtpreldword, 0},
1459 {"tprelword", s_tprelword, 0},
1460 {"tpreldword", s_tpreldword, 0},
1461 {"gpvalue", s_gpvalue, 0},
1462 {"gpword", s_gpword, 0},
1463 {"gpdword", s_gpdword, 0},
1464 {"ehword", s_ehword, 0},
1465 {"cpadd", s_cpadd, 0},
1466 {"insn", s_insn, 0},
1468 /* Relatively generic pseudo-ops that happen to be used on MIPS
1470 {"asciiz", stringer, 8 + 1},
1471 {"bss", s_change_sec, 'b'},
1473 {"half", s_cons, 1},
1474 {"dword", s_cons, 3},
1475 {"weakext", s_mips_weakext, 0},
1476 {"origin", s_org, 0},
1477 {"repeat", s_rept, 0},
1479 /* For MIPS this is non-standard, but we define it for consistency. */
1480 {"sbss", s_change_sec, 'B'},
1482 /* These pseudo-ops are defined in read.c, but must be overridden
1483 here for one reason or another. */
1484 {"align", s_align, 0},
1485 {"byte", s_cons, 0},
1486 {"data", s_change_sec, 'd'},
1487 {"double", s_float_cons, 'd'},
1488 {"float", s_float_cons, 'f'},
1489 {"globl", s_mips_globl, 0},
1490 {"global", s_mips_globl, 0},
1491 {"hword", s_cons, 1},
1493 {"long", s_cons, 2},
1494 {"octa", s_cons, 4},
1495 {"quad", s_cons, 3},
1496 {"section", s_change_section, 0},
1497 {"short", s_cons, 1},
1498 {"single", s_float_cons, 'f'},
1499 {"stabd", s_mips_stab, 'd'},
1500 {"stabn", s_mips_stab, 'n'},
1501 {"stabs", s_mips_stab, 's'},
1502 {"text", s_change_sec, 't'},
1503 {"word", s_cons, 2},
1505 { "extern", ecoff_directive_extern, 0},
1510 static const pseudo_typeS mips_nonecoff_pseudo_table[] =
1512 /* These pseudo-ops should be defined by the object file format.
1513 However, a.out doesn't support them, so we have versions here. */
1514 {"aent", s_mips_ent, 1},
1515 {"bgnb", s_ignore, 0},
1516 {"end", s_mips_end, 0},
1517 {"endb", s_ignore, 0},
1518 {"ent", s_mips_ent, 0},
1519 {"file", s_mips_file, 0},
1520 {"fmask", s_mips_mask, 'F'},
1521 {"frame", s_mips_frame, 0},
1522 {"loc", s_mips_loc, 0},
1523 {"mask", s_mips_mask, 'R'},
1524 {"verstamp", s_ignore, 0},
1528 /* Export the ABI address size for use by TC_ADDRESS_BYTES for the
1529 purpose of the `.dc.a' internal pseudo-op. */
1532 mips_address_bytes (void)
1534 return HAVE_64BIT_ADDRESSES ? 8 : 4;
1537 extern void pop_insert (const pseudo_typeS *);
1540 mips_pop_insert (void)
1542 pop_insert (mips_pseudo_table);
1543 if (! ECOFF_DEBUGGING)
1544 pop_insert (mips_nonecoff_pseudo_table);
1547 /* Symbols labelling the current insn. */
1549 struct insn_label_list
1551 struct insn_label_list *next;
1555 static struct insn_label_list *free_insn_labels;
1556 #define label_list tc_segment_info_data.labels
1558 static void mips_clear_insn_labels (void);
1559 static void mips_mark_labels (void);
1560 static void mips_compressed_mark_labels (void);
1563 mips_clear_insn_labels (void)
1565 register struct insn_label_list **pl;
1566 segment_info_type *si;
1570 for (pl = &free_insn_labels; *pl != NULL; pl = &(*pl)->next)
1573 si = seg_info (now_seg);
1574 *pl = si->label_list;
1575 si->label_list = NULL;
1579 /* Mark instruction labels in MIPS16/microMIPS mode. */
1582 mips_mark_labels (void)
1584 if (HAVE_CODE_COMPRESSION)
1585 mips_compressed_mark_labels ();
1588 static char *expr_end;
1590 /* Expressions which appear in instructions. These are set by
1593 static expressionS imm_expr;
1594 static expressionS imm2_expr;
1595 static expressionS offset_expr;
1597 /* Relocs associated with imm_expr and offset_expr. */
1599 static bfd_reloc_code_real_type imm_reloc[3]
1600 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
1601 static bfd_reloc_code_real_type offset_reloc[3]
1602 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
1604 /* This is set to the resulting size of the instruction to be produced
1605 by mips16_ip if an explicit extension is used or by mips_ip if an
1606 explicit size is supplied. */
1608 static unsigned int forced_insn_length;
1610 /* True if we are assembling an instruction. All dot symbols defined during
1611 this time should be treated as code labels. */
1613 static bfd_boolean mips_assembling_insn;
1616 /* The pdr segment for per procedure frame/regmask info. Not used for
1619 static segT pdr_seg;
1622 /* The default target format to use. */
1624 #if defined (TE_FreeBSD)
1625 #define ELF_TARGET(PREFIX, ENDIAN) PREFIX "trad" ENDIAN "mips-freebsd"
1626 #elif defined (TE_TMIPS)
1627 #define ELF_TARGET(PREFIX, ENDIAN) PREFIX "trad" ENDIAN "mips"
1629 #define ELF_TARGET(PREFIX, ENDIAN) PREFIX ENDIAN "mips"
1633 mips_target_format (void)
1635 switch (OUTPUT_FLAVOR)
1637 case bfd_target_ecoff_flavour:
1638 return target_big_endian ? "ecoff-bigmips" : ECOFF_LITTLE_FORMAT;
1639 case bfd_target_coff_flavour:
1641 case bfd_target_elf_flavour:
1643 if (!HAVE_64BIT_OBJECTS && !HAVE_NEWABI)
1644 return (target_big_endian
1645 ? "elf32-bigmips-vxworks"
1646 : "elf32-littlemips-vxworks");
1648 return (target_big_endian
1649 ? (HAVE_64BIT_OBJECTS
1650 ? ELF_TARGET ("elf64-", "big")
1652 ? ELF_TARGET ("elf32-n", "big")
1653 : ELF_TARGET ("elf32-", "big")))
1654 : (HAVE_64BIT_OBJECTS
1655 ? ELF_TARGET ("elf64-", "little")
1657 ? ELF_TARGET ("elf32-n", "little")
1658 : ELF_TARGET ("elf32-", "little"))));
1665 /* Return the length of a microMIPS instruction in bytes. If bits of
1666 the mask beyond the low 16 are 0, then it is a 16-bit instruction.
1667 Otherwise assume a 32-bit instruction; 48-bit instructions (0x1f
1668 major opcode) will require further modifications to the opcode
1671 static inline unsigned int
1672 micromips_insn_length (const struct mips_opcode *mo)
1674 return (mo->mask >> 16) == 0 ? 2 : 4;
1677 /* Return the length of MIPS16 instruction OPCODE. */
1679 static inline unsigned int
1680 mips16_opcode_length (unsigned long opcode)
1682 return (opcode >> 16) == 0 ? 2 : 4;
1685 /* Return the length of instruction INSN. */
1687 static inline unsigned int
1688 insn_length (const struct mips_cl_insn *insn)
1690 if (mips_opts.micromips)
1691 return micromips_insn_length (insn->insn_mo);
1692 else if (mips_opts.mips16)
1693 return mips16_opcode_length (insn->insn_opcode);
1698 /* Initialise INSN from opcode entry MO. Leave its position unspecified. */
1701 create_insn (struct mips_cl_insn *insn, const struct mips_opcode *mo)
1706 insn->insn_opcode = mo->match;
1709 for (i = 0; i < ARRAY_SIZE (insn->fixp); i++)
1710 insn->fixp[i] = NULL;
1711 insn->fixed_p = (mips_opts.noreorder > 0);
1712 insn->noreorder_p = (mips_opts.noreorder > 0);
1713 insn->mips16_absolute_jump_p = 0;
1714 insn->complete_p = 0;
1715 insn->cleared_p = 0;
1718 /* Record the current MIPS16/microMIPS mode in now_seg. */
1721 mips_record_compressed_mode (void)
1723 segment_info_type *si;
1725 si = seg_info (now_seg);
1726 if (si->tc_segment_info_data.mips16 != mips_opts.mips16)
1727 si->tc_segment_info_data.mips16 = mips_opts.mips16;
1728 if (si->tc_segment_info_data.micromips != mips_opts.micromips)
1729 si->tc_segment_info_data.micromips = mips_opts.micromips;
1732 /* Read a standard MIPS instruction from BUF. */
1734 static unsigned long
1735 read_insn (char *buf)
1737 if (target_big_endian)
1738 return bfd_getb32 ((bfd_byte *) buf);
1740 return bfd_getl32 ((bfd_byte *) buf);
1743 /* Write standard MIPS instruction INSN to BUF. Return a pointer to
1747 write_insn (char *buf, unsigned int insn)
1749 md_number_to_chars (buf, insn, 4);
1753 /* Read a microMIPS or MIPS16 opcode from BUF, given that it
1754 has length LENGTH. */
1756 static unsigned long
1757 read_compressed_insn (char *buf, unsigned int length)
1763 for (i = 0; i < length; i += 2)
1766 if (target_big_endian)
1767 insn |= bfd_getb16 ((char *) buf);
1769 insn |= bfd_getl16 ((char *) buf);
1775 /* Write microMIPS or MIPS16 instruction INSN to BUF, given that the
1776 instruction is LENGTH bytes long. Return a pointer to the next byte. */
1779 write_compressed_insn (char *buf, unsigned int insn, unsigned int length)
1783 for (i = 0; i < length; i += 2)
1784 md_number_to_chars (buf + i, insn >> ((length - i - 2) * 8), 2);
1785 return buf + length;
1788 /* Install INSN at the location specified by its "frag" and "where" fields. */
1791 install_insn (const struct mips_cl_insn *insn)
1793 char *f = insn->frag->fr_literal + insn->where;
1794 if (HAVE_CODE_COMPRESSION)
1795 write_compressed_insn (f, insn->insn_opcode, insn_length (insn));
1797 write_insn (f, insn->insn_opcode);
1798 mips_record_compressed_mode ();
1801 /* Move INSN to offset WHERE in FRAG. Adjust the fixups accordingly
1802 and install the opcode in the new location. */
1805 move_insn (struct mips_cl_insn *insn, fragS *frag, long where)
1810 insn->where = where;
1811 for (i = 0; i < ARRAY_SIZE (insn->fixp); i++)
1812 if (insn->fixp[i] != NULL)
1814 insn->fixp[i]->fx_frag = frag;
1815 insn->fixp[i]->fx_where = where;
1817 install_insn (insn);
1820 /* Add INSN to the end of the output. */
1823 add_fixed_insn (struct mips_cl_insn *insn)
1825 char *f = frag_more (insn_length (insn));
1826 move_insn (insn, frag_now, f - frag_now->fr_literal);
1829 /* Start a variant frag and move INSN to the start of the variant part,
1830 marking it as fixed. The other arguments are as for frag_var. */
1833 add_relaxed_insn (struct mips_cl_insn *insn, int max_chars, int var,
1834 relax_substateT subtype, symbolS *symbol, offsetT offset)
1836 frag_grow (max_chars);
1837 move_insn (insn, frag_now, frag_more (0) - frag_now->fr_literal);
1839 frag_var (rs_machine_dependent, max_chars, var,
1840 subtype, symbol, offset, NULL);
1843 /* Insert N copies of INSN into the history buffer, starting at
1844 position FIRST. Neither FIRST nor N need to be clipped. */
1847 insert_into_history (unsigned int first, unsigned int n,
1848 const struct mips_cl_insn *insn)
1850 if (mips_relax.sequence != 2)
1854 for (i = ARRAY_SIZE (history); i-- > first;)
1856 history[i] = history[i - n];
1862 /* Initialize vr4120_conflicts. There is a bit of duplication here:
1863 the idea is to make it obvious at a glance that each errata is
1867 init_vr4120_conflicts (void)
1869 #define CONFLICT(FIRST, SECOND) \
1870 vr4120_conflicts[FIX_VR4120_##FIRST] |= 1 << FIX_VR4120_##SECOND
1872 /* Errata 21 - [D]DIV[U] after [D]MACC */
1873 CONFLICT (MACC, DIV);
1874 CONFLICT (DMACC, DIV);
1876 /* Errata 23 - Continuous DMULT[U]/DMACC instructions. */
1877 CONFLICT (DMULT, DMULT);
1878 CONFLICT (DMULT, DMACC);
1879 CONFLICT (DMACC, DMULT);
1880 CONFLICT (DMACC, DMACC);
1882 /* Errata 24 - MT{LO,HI} after [D]MACC */
1883 CONFLICT (MACC, MTHILO);
1884 CONFLICT (DMACC, MTHILO);
1886 /* VR4181A errata MD(1): "If a MULT, MULTU, DMULT or DMULTU
1887 instruction is executed immediately after a MACC or DMACC
1888 instruction, the result of [either instruction] is incorrect." */
1889 CONFLICT (MACC, MULT);
1890 CONFLICT (MACC, DMULT);
1891 CONFLICT (DMACC, MULT);
1892 CONFLICT (DMACC, DMULT);
1894 /* VR4181A errata MD(4): "If a MACC or DMACC instruction is
1895 executed immediately after a DMULT, DMULTU, DIV, DIVU,
1896 DDIV or DDIVU instruction, the result of the MACC or
1897 DMACC instruction is incorrect.". */
1898 CONFLICT (DMULT, MACC);
1899 CONFLICT (DMULT, DMACC);
1900 CONFLICT (DIV, MACC);
1901 CONFLICT (DIV, DMACC);
1911 #define RTYPE_MASK 0x1ff00
1912 #define RTYPE_NUM 0x00100
1913 #define RTYPE_FPU 0x00200
1914 #define RTYPE_FCC 0x00400
1915 #define RTYPE_VEC 0x00800
1916 #define RTYPE_GP 0x01000
1917 #define RTYPE_CP0 0x02000
1918 #define RTYPE_PC 0x04000
1919 #define RTYPE_ACC 0x08000
1920 #define RTYPE_CCC 0x10000
1921 #define RNUM_MASK 0x000ff
1922 #define RWARN 0x80000
1924 #define GENERIC_REGISTER_NUMBERS \
1925 {"$0", RTYPE_NUM | 0}, \
1926 {"$1", RTYPE_NUM | 1}, \
1927 {"$2", RTYPE_NUM | 2}, \
1928 {"$3", RTYPE_NUM | 3}, \
1929 {"$4", RTYPE_NUM | 4}, \
1930 {"$5", RTYPE_NUM | 5}, \
1931 {"$6", RTYPE_NUM | 6}, \
1932 {"$7", RTYPE_NUM | 7}, \
1933 {"$8", RTYPE_NUM | 8}, \
1934 {"$9", RTYPE_NUM | 9}, \
1935 {"$10", RTYPE_NUM | 10}, \
1936 {"$11", RTYPE_NUM | 11}, \
1937 {"$12", RTYPE_NUM | 12}, \
1938 {"$13", RTYPE_NUM | 13}, \
1939 {"$14", RTYPE_NUM | 14}, \
1940 {"$15", RTYPE_NUM | 15}, \
1941 {"$16", RTYPE_NUM | 16}, \
1942 {"$17", RTYPE_NUM | 17}, \
1943 {"$18", RTYPE_NUM | 18}, \
1944 {"$19", RTYPE_NUM | 19}, \
1945 {"$20", RTYPE_NUM | 20}, \
1946 {"$21", RTYPE_NUM | 21}, \
1947 {"$22", RTYPE_NUM | 22}, \
1948 {"$23", RTYPE_NUM | 23}, \
1949 {"$24", RTYPE_NUM | 24}, \
1950 {"$25", RTYPE_NUM | 25}, \
1951 {"$26", RTYPE_NUM | 26}, \
1952 {"$27", RTYPE_NUM | 27}, \
1953 {"$28", RTYPE_NUM | 28}, \
1954 {"$29", RTYPE_NUM | 29}, \
1955 {"$30", RTYPE_NUM | 30}, \
1956 {"$31", RTYPE_NUM | 31}
1958 #define FPU_REGISTER_NAMES \
1959 {"$f0", RTYPE_FPU | 0}, \
1960 {"$f1", RTYPE_FPU | 1}, \
1961 {"$f2", RTYPE_FPU | 2}, \
1962 {"$f3", RTYPE_FPU | 3}, \
1963 {"$f4", RTYPE_FPU | 4}, \
1964 {"$f5", RTYPE_FPU | 5}, \
1965 {"$f6", RTYPE_FPU | 6}, \
1966 {"$f7", RTYPE_FPU | 7}, \
1967 {"$f8", RTYPE_FPU | 8}, \
1968 {"$f9", RTYPE_FPU | 9}, \
1969 {"$f10", RTYPE_FPU | 10}, \
1970 {"$f11", RTYPE_FPU | 11}, \
1971 {"$f12", RTYPE_FPU | 12}, \
1972 {"$f13", RTYPE_FPU | 13}, \
1973 {"$f14", RTYPE_FPU | 14}, \
1974 {"$f15", RTYPE_FPU | 15}, \
1975 {"$f16", RTYPE_FPU | 16}, \
1976 {"$f17", RTYPE_FPU | 17}, \
1977 {"$f18", RTYPE_FPU | 18}, \
1978 {"$f19", RTYPE_FPU | 19}, \
1979 {"$f20", RTYPE_FPU | 20}, \
1980 {"$f21", RTYPE_FPU | 21}, \
1981 {"$f22", RTYPE_FPU | 22}, \
1982 {"$f23", RTYPE_FPU | 23}, \
1983 {"$f24", RTYPE_FPU | 24}, \
1984 {"$f25", RTYPE_FPU | 25}, \
1985 {"$f26", RTYPE_FPU | 26}, \
1986 {"$f27", RTYPE_FPU | 27}, \
1987 {"$f28", RTYPE_FPU | 28}, \
1988 {"$f29", RTYPE_FPU | 29}, \
1989 {"$f30", RTYPE_FPU | 30}, \
1990 {"$f31", RTYPE_FPU | 31}
1992 #define FPU_CONDITION_CODE_NAMES \
1993 {"$fcc0", RTYPE_FCC | 0}, \
1994 {"$fcc1", RTYPE_FCC | 1}, \
1995 {"$fcc2", RTYPE_FCC | 2}, \
1996 {"$fcc3", RTYPE_FCC | 3}, \
1997 {"$fcc4", RTYPE_FCC | 4}, \
1998 {"$fcc5", RTYPE_FCC | 5}, \
1999 {"$fcc6", RTYPE_FCC | 6}, \
2000 {"$fcc7", RTYPE_FCC | 7}
2002 #define COPROC_CONDITION_CODE_NAMES \
2003 {"$cc0", RTYPE_FCC | RTYPE_CCC | 0}, \
2004 {"$cc1", RTYPE_FCC | RTYPE_CCC | 1}, \
2005 {"$cc2", RTYPE_FCC | RTYPE_CCC | 2}, \
2006 {"$cc3", RTYPE_FCC | RTYPE_CCC | 3}, \
2007 {"$cc4", RTYPE_FCC | RTYPE_CCC | 4}, \
2008 {"$cc5", RTYPE_FCC | RTYPE_CCC | 5}, \
2009 {"$cc6", RTYPE_FCC | RTYPE_CCC | 6}, \
2010 {"$cc7", RTYPE_FCC | RTYPE_CCC | 7}
2012 #define N32N64_SYMBOLIC_REGISTER_NAMES \
2013 {"$a4", RTYPE_GP | 8}, \
2014 {"$a5", RTYPE_GP | 9}, \
2015 {"$a6", RTYPE_GP | 10}, \
2016 {"$a7", RTYPE_GP | 11}, \
2017 {"$ta0", RTYPE_GP | 8}, /* alias for $a4 */ \
2018 {"$ta1", RTYPE_GP | 9}, /* alias for $a5 */ \
2019 {"$ta2", RTYPE_GP | 10}, /* alias for $a6 */ \
2020 {"$ta3", RTYPE_GP | 11}, /* alias for $a7 */ \
2021 {"$t0", RTYPE_GP | 12}, \
2022 {"$t1", RTYPE_GP | 13}, \
2023 {"$t2", RTYPE_GP | 14}, \
2024 {"$t3", RTYPE_GP | 15}
2026 #define O32_SYMBOLIC_REGISTER_NAMES \
2027 {"$t0", RTYPE_GP | 8}, \
2028 {"$t1", RTYPE_GP | 9}, \
2029 {"$t2", RTYPE_GP | 10}, \
2030 {"$t3", RTYPE_GP | 11}, \
2031 {"$t4", RTYPE_GP | 12}, \
2032 {"$t5", RTYPE_GP | 13}, \
2033 {"$t6", RTYPE_GP | 14}, \
2034 {"$t7", RTYPE_GP | 15}, \
2035 {"$ta0", RTYPE_GP | 12}, /* alias for $t4 */ \
2036 {"$ta1", RTYPE_GP | 13}, /* alias for $t5 */ \
2037 {"$ta2", RTYPE_GP | 14}, /* alias for $t6 */ \
2038 {"$ta3", RTYPE_GP | 15} /* alias for $t7 */
2040 /* Remaining symbolic register names */
2041 #define SYMBOLIC_REGISTER_NAMES \
2042 {"$zero", RTYPE_GP | 0}, \
2043 {"$at", RTYPE_GP | 1}, \
2044 {"$AT", RTYPE_GP | 1}, \
2045 {"$v0", RTYPE_GP | 2}, \
2046 {"$v1", RTYPE_GP | 3}, \
2047 {"$a0", RTYPE_GP | 4}, \
2048 {"$a1", RTYPE_GP | 5}, \
2049 {"$a2", RTYPE_GP | 6}, \
2050 {"$a3", RTYPE_GP | 7}, \
2051 {"$s0", RTYPE_GP | 16}, \
2052 {"$s1", RTYPE_GP | 17}, \
2053 {"$s2", RTYPE_GP | 18}, \
2054 {"$s3", RTYPE_GP | 19}, \
2055 {"$s4", RTYPE_GP | 20}, \
2056 {"$s5", RTYPE_GP | 21}, \
2057 {"$s6", RTYPE_GP | 22}, \
2058 {"$s7", RTYPE_GP | 23}, \
2059 {"$t8", RTYPE_GP | 24}, \
2060 {"$t9", RTYPE_GP | 25}, \
2061 {"$k0", RTYPE_GP | 26}, \
2062 {"$kt0", RTYPE_GP | 26}, \
2063 {"$k1", RTYPE_GP | 27}, \
2064 {"$kt1", RTYPE_GP | 27}, \
2065 {"$gp", RTYPE_GP | 28}, \
2066 {"$sp", RTYPE_GP | 29}, \
2067 {"$s8", RTYPE_GP | 30}, \
2068 {"$fp", RTYPE_GP | 30}, \
2069 {"$ra", RTYPE_GP | 31}
2071 #define MIPS16_SPECIAL_REGISTER_NAMES \
2072 {"$pc", RTYPE_PC | 0}
2074 #define MDMX_VECTOR_REGISTER_NAMES \
2075 /* {"$v0", RTYPE_VEC | 0}, clash with REG 2 above */ \
2076 /* {"$v1", RTYPE_VEC | 1}, clash with REG 3 above */ \
2077 {"$v2", RTYPE_VEC | 2}, \
2078 {"$v3", RTYPE_VEC | 3}, \
2079 {"$v4", RTYPE_VEC | 4}, \
2080 {"$v5", RTYPE_VEC | 5}, \
2081 {"$v6", RTYPE_VEC | 6}, \
2082 {"$v7", RTYPE_VEC | 7}, \
2083 {"$v8", RTYPE_VEC | 8}, \
2084 {"$v9", RTYPE_VEC | 9}, \
2085 {"$v10", RTYPE_VEC | 10}, \
2086 {"$v11", RTYPE_VEC | 11}, \
2087 {"$v12", RTYPE_VEC | 12}, \
2088 {"$v13", RTYPE_VEC | 13}, \
2089 {"$v14", RTYPE_VEC | 14}, \
2090 {"$v15", RTYPE_VEC | 15}, \
2091 {"$v16", RTYPE_VEC | 16}, \
2092 {"$v17", RTYPE_VEC | 17}, \
2093 {"$v18", RTYPE_VEC | 18}, \
2094 {"$v19", RTYPE_VEC | 19}, \
2095 {"$v20", RTYPE_VEC | 20}, \
2096 {"$v21", RTYPE_VEC | 21}, \
2097 {"$v22", RTYPE_VEC | 22}, \
2098 {"$v23", RTYPE_VEC | 23}, \
2099 {"$v24", RTYPE_VEC | 24}, \
2100 {"$v25", RTYPE_VEC | 25}, \
2101 {"$v26", RTYPE_VEC | 26}, \
2102 {"$v27", RTYPE_VEC | 27}, \
2103 {"$v28", RTYPE_VEC | 28}, \
2104 {"$v29", RTYPE_VEC | 29}, \
2105 {"$v30", RTYPE_VEC | 30}, \
2106 {"$v31", RTYPE_VEC | 31}
2108 #define MIPS_DSP_ACCUMULATOR_NAMES \
2109 {"$ac0", RTYPE_ACC | 0}, \
2110 {"$ac1", RTYPE_ACC | 1}, \
2111 {"$ac2", RTYPE_ACC | 2}, \
2112 {"$ac3", RTYPE_ACC | 3}
2114 static const struct regname reg_names[] = {
2115 GENERIC_REGISTER_NUMBERS,
2117 FPU_CONDITION_CODE_NAMES,
2118 COPROC_CONDITION_CODE_NAMES,
2120 /* The $txx registers depends on the abi,
2121 these will be added later into the symbol table from
2122 one of the tables below once mips_abi is set after
2123 parsing of arguments from the command line. */
2124 SYMBOLIC_REGISTER_NAMES,
2126 MIPS16_SPECIAL_REGISTER_NAMES,
2127 MDMX_VECTOR_REGISTER_NAMES,
2128 MIPS_DSP_ACCUMULATOR_NAMES,
2132 static const struct regname reg_names_o32[] = {
2133 O32_SYMBOLIC_REGISTER_NAMES,
2137 static const struct regname reg_names_n32n64[] = {
2138 N32N64_SYMBOLIC_REGISTER_NAMES,
2142 /* Check if S points at a valid register specifier according to TYPES.
2143 If so, then return 1, advance S to consume the specifier and store
2144 the register's number in REGNOP, otherwise return 0. */
2147 reg_lookup (char **s, unsigned int types, unsigned int *regnop)
2154 /* Find end of name. */
2156 if (is_name_beginner (*e))
2158 while (is_part_of_name (*e))
2161 /* Terminate name. */
2165 /* Look for a register symbol. */
2166 if ((symbolP = symbol_find (*s)) && S_GET_SEGMENT (symbolP) == reg_section)
2168 int r = S_GET_VALUE (symbolP);
2170 reg = r & RNUM_MASK;
2171 else if ((types & RTYPE_VEC) && (r & ~1) == (RTYPE_GP | 2))
2172 /* Convert GP reg $v0/1 to MDMX reg $v0/1! */
2173 reg = (r & RNUM_MASK) - 2;
2175 /* Else see if this is a register defined in an itbl entry. */
2176 else if ((types & RTYPE_GP) && itbl_have_entries)
2183 if (itbl_get_reg_val (n, &r))
2184 reg = r & RNUM_MASK;
2187 /* Advance to next token if a register was recognised. */
2190 else if (types & RWARN)
2191 as_warn (_("Unrecognized register name `%s'"), *s);
2199 /* Check if S points at a valid register list according to TYPES.
2200 If so, then return 1, advance S to consume the list and store
2201 the registers present on the list as a bitmask of ones in REGLISTP,
2202 otherwise return 0. A valid list comprises a comma-separated
2203 enumeration of valid single registers and/or dash-separated
2204 contiguous register ranges as determined by their numbers.
2206 As a special exception if one of s0-s7 registers is specified as
2207 the range's lower delimiter and s8 (fp) is its upper one, then no
2208 registers whose numbers place them between s7 and s8 (i.e. $24-$29)
2209 are selected; they have to be listed separately if needed. */
2212 reglist_lookup (char **s, unsigned int types, unsigned int *reglistp)
2214 unsigned int reglist = 0;
2215 unsigned int lastregno;
2216 bfd_boolean ok = TRUE;
2217 unsigned int regmask;
2218 char *s_endlist = *s;
2222 while (reg_lookup (s, types, ®no))
2228 ok = reg_lookup (s, types, &lastregno);
2229 if (ok && lastregno < regno)
2235 if (lastregno == FP && regno >= S0 && regno <= S7)
2240 regmask = 1 << lastregno;
2241 regmask = (regmask << 1) - 1;
2242 regmask ^= (1 << regno) - 1;
2256 *reglistp = reglist;
2257 return ok && reglist != 0;
2260 /* Return TRUE if opcode MO is valid on the currently selected ISA, ASE
2261 and architecture. Use is_opcode_valid_16 for MIPS16 opcodes. */
2264 is_opcode_valid (const struct mips_opcode *mo)
2266 int isa = mips_opts.isa;
2270 if (mips_opts.ase_mdmx)
2272 if (mips_opts.ase_dsp)
2274 if (mips_opts.ase_dsp && ISA_SUPPORTS_DSP64_ASE)
2276 if (mips_opts.ase_dspr2)
2278 if (mips_opts.ase_eva)
2280 if (mips_opts.ase_mt)
2282 if (mips_opts.ase_mips3d)
2284 if (mips_opts.ase_smartmips)
2285 ase |= ASE_SMARTMIPS;
2286 if (mips_opts.ase_mcu)
2288 if (mips_opts.ase_virt)
2290 if (mips_opts.ase_virt && ISA_SUPPORTS_VIRT64_ASE)
2293 if (!opcode_is_member (mo, isa, ase, mips_opts.arch))
2296 /* Check whether the instruction or macro requires single-precision or
2297 double-precision floating-point support. Note that this information is
2298 stored differently in the opcode table for insns and macros. */
2299 if (mo->pinfo == INSN_MACRO)
2301 fp_s = mo->pinfo2 & INSN2_M_FP_S;
2302 fp_d = mo->pinfo2 & INSN2_M_FP_D;
2306 fp_s = mo->pinfo & FP_S;
2307 fp_d = mo->pinfo & FP_D;
2310 if (fp_d && (mips_opts.soft_float || mips_opts.single_float))
2313 if (fp_s && mips_opts.soft_float)
2319 /* Return TRUE if the MIPS16 opcode MO is valid on the currently
2320 selected ISA and architecture. */
2323 is_opcode_valid_16 (const struct mips_opcode *mo)
2325 return opcode_is_member (mo, mips_opts.isa, 0, mips_opts.arch);
2328 /* Return TRUE if the size of the microMIPS opcode MO matches one
2329 explicitly requested. Always TRUE in the standard MIPS mode. */
2332 is_size_valid (const struct mips_opcode *mo)
2334 if (!mips_opts.micromips)
2337 if (!forced_insn_length)
2339 if (mo->pinfo == INSN_MACRO)
2341 return forced_insn_length == micromips_insn_length (mo);
2344 /* Return TRUE if the microMIPS opcode MO is valid for the delay slot
2345 of the preceding instruction. Always TRUE in the standard MIPS mode.
2347 We don't accept macros in 16-bit delay slots to avoid a case where
2348 a macro expansion fails because it relies on a preceding 32-bit real
2349 instruction to have matched and does not handle the operands correctly.
2350 The only macros that may expand to 16-bit instructions are JAL that
2351 cannot be placed in a delay slot anyway, and corner cases of BALIGN
2352 and BGT (that likewise cannot be placed in a delay slot) that decay to
2353 a NOP. In all these cases the macros precede any corresponding real
2354 instruction definitions in the opcode table, so they will match in the
2355 second pass where the size of the delay slot is ignored and therefore
2356 produce correct code. */
2359 is_delay_slot_valid (const struct mips_opcode *mo)
2361 if (!mips_opts.micromips)
2364 if (mo->pinfo == INSN_MACRO)
2365 return (history[0].insn_mo->pinfo2 & INSN2_BRANCH_DELAY_16BIT) == 0;
2366 if ((history[0].insn_mo->pinfo2 & INSN2_BRANCH_DELAY_32BIT) != 0
2367 && micromips_insn_length (mo) != 4)
2369 if ((history[0].insn_mo->pinfo2 & INSN2_BRANCH_DELAY_16BIT) != 0
2370 && micromips_insn_length (mo) != 2)
2376 /* This function is called once, at assembler startup time. It should set up
2377 all the tables, etc. that the MD part of the assembler will need. */
2382 const char *retval = NULL;
2386 if (mips_pic != NO_PIC)
2388 if (g_switch_seen && g_switch_value != 0)
2389 as_bad (_("-G may not be used in position-independent code"));
2393 if (! bfd_set_arch_mach (stdoutput, bfd_arch_mips, file_mips_arch))
2394 as_warn (_("Could not set architecture and machine"));
2396 op_hash = hash_new ();
2398 for (i = 0; i < NUMOPCODES;)
2400 const char *name = mips_opcodes[i].name;
2402 retval = hash_insert (op_hash, name, (void *) &mips_opcodes[i]);
2405 fprintf (stderr, _("internal error: can't hash `%s': %s\n"),
2406 mips_opcodes[i].name, retval);
2407 /* Probably a memory allocation problem? Give up now. */
2408 as_fatal (_("Broken assembler. No assembly attempted."));
2412 if (mips_opcodes[i].pinfo != INSN_MACRO)
2414 if (!validate_mips_insn (&mips_opcodes[i]))
2416 if (nop_insn.insn_mo == NULL && strcmp (name, "nop") == 0)
2418 create_insn (&nop_insn, mips_opcodes + i);
2419 if (mips_fix_loongson2f_nop)
2420 nop_insn.insn_opcode = LOONGSON2F_NOP_INSN;
2421 nop_insn.fixed_p = 1;
2426 while ((i < NUMOPCODES) && !strcmp (mips_opcodes[i].name, name));
2429 mips16_op_hash = hash_new ();
2432 while (i < bfd_mips16_num_opcodes)
2434 const char *name = mips16_opcodes[i].name;
2436 retval = hash_insert (mips16_op_hash, name, (void *) &mips16_opcodes[i]);
2438 as_fatal (_("internal: can't hash `%s': %s"),
2439 mips16_opcodes[i].name, retval);
2442 if (mips16_opcodes[i].pinfo != INSN_MACRO
2443 && ((mips16_opcodes[i].match & mips16_opcodes[i].mask)
2444 != mips16_opcodes[i].match))
2446 fprintf (stderr, _("internal error: bad mips16 opcode: %s %s\n"),
2447 mips16_opcodes[i].name, mips16_opcodes[i].args);
2450 if (mips16_nop_insn.insn_mo == NULL && strcmp (name, "nop") == 0)
2452 create_insn (&mips16_nop_insn, mips16_opcodes + i);
2453 mips16_nop_insn.fixed_p = 1;
2457 while (i < bfd_mips16_num_opcodes
2458 && strcmp (mips16_opcodes[i].name, name) == 0);
2461 micromips_op_hash = hash_new ();
2464 while (i < bfd_micromips_num_opcodes)
2466 const char *name = micromips_opcodes[i].name;
2468 retval = hash_insert (micromips_op_hash, name,
2469 (void *) µmips_opcodes[i]);
2471 as_fatal (_("internal: can't hash `%s': %s"),
2472 micromips_opcodes[i].name, retval);
2474 if (micromips_opcodes[i].pinfo != INSN_MACRO)
2476 struct mips_cl_insn *micromips_nop_insn;
2478 if (!validate_micromips_insn (µmips_opcodes[i]))
2481 if (micromips_insn_length (micromips_opcodes + i) == 2)
2482 micromips_nop_insn = µmips_nop16_insn;
2483 else if (micromips_insn_length (micromips_opcodes + i) == 4)
2484 micromips_nop_insn = µmips_nop32_insn;
2488 if (micromips_nop_insn->insn_mo == NULL
2489 && strcmp (name, "nop") == 0)
2491 create_insn (micromips_nop_insn, micromips_opcodes + i);
2492 micromips_nop_insn->fixed_p = 1;
2495 while (++i < bfd_micromips_num_opcodes
2496 && strcmp (micromips_opcodes[i].name, name) == 0);
2500 as_fatal (_("Broken assembler. No assembly attempted."));
2502 /* We add all the general register names to the symbol table. This
2503 helps us detect invalid uses of them. */
2504 for (i = 0; reg_names[i].name; i++)
2505 symbol_table_insert (symbol_new (reg_names[i].name, reg_section,
2506 reg_names[i].num, /* & RNUM_MASK, */
2507 &zero_address_frag));
2509 for (i = 0; reg_names_n32n64[i].name; i++)
2510 symbol_table_insert (symbol_new (reg_names_n32n64[i].name, reg_section,
2511 reg_names_n32n64[i].num, /* & RNUM_MASK, */
2512 &zero_address_frag));
2514 for (i = 0; reg_names_o32[i].name; i++)
2515 symbol_table_insert (symbol_new (reg_names_o32[i].name, reg_section,
2516 reg_names_o32[i].num, /* & RNUM_MASK, */
2517 &zero_address_frag));
2519 mips_no_prev_insn ();
2522 mips_cprmask[0] = 0;
2523 mips_cprmask[1] = 0;
2524 mips_cprmask[2] = 0;
2525 mips_cprmask[3] = 0;
2527 /* set the default alignment for the text section (2**2) */
2528 record_alignment (text_section, 2);
2530 bfd_set_gp_size (stdoutput, g_switch_value);
2535 /* On a native system other than VxWorks, sections must be aligned
2536 to 16 byte boundaries. When configured for an embedded ELF
2537 target, we don't bother. */
2538 if (strncmp (TARGET_OS, "elf", 3) != 0
2539 && strncmp (TARGET_OS, "vxworks", 7) != 0)
2541 (void) bfd_set_section_alignment (stdoutput, text_section, 4);
2542 (void) bfd_set_section_alignment (stdoutput, data_section, 4);
2543 (void) bfd_set_section_alignment (stdoutput, bss_section, 4);
2546 /* Create a .reginfo section for register masks and a .mdebug
2547 section for debugging information. */
2555 subseg = now_subseg;
2557 /* The ABI says this section should be loaded so that the
2558 running program can access it. However, we don't load it
2559 if we are configured for an embedded target */
2560 flags = SEC_READONLY | SEC_DATA;
2561 if (strncmp (TARGET_OS, "elf", 3) != 0)
2562 flags |= SEC_ALLOC | SEC_LOAD;
2564 if (mips_abi != N64_ABI)
2566 sec = subseg_new (".reginfo", (subsegT) 0);
2568 bfd_set_section_flags (stdoutput, sec, flags);
2569 bfd_set_section_alignment (stdoutput, sec, HAVE_NEWABI ? 3 : 2);
2571 mips_regmask_frag = frag_more (sizeof (Elf32_External_RegInfo));
2575 /* The 64-bit ABI uses a .MIPS.options section rather than
2576 .reginfo section. */
2577 sec = subseg_new (".MIPS.options", (subsegT) 0);
2578 bfd_set_section_flags (stdoutput, sec, flags);
2579 bfd_set_section_alignment (stdoutput, sec, 3);
2581 /* Set up the option header. */
2583 Elf_Internal_Options opthdr;
2586 opthdr.kind = ODK_REGINFO;
2587 opthdr.size = (sizeof (Elf_External_Options)
2588 + sizeof (Elf64_External_RegInfo));
2591 f = frag_more (sizeof (Elf_External_Options));
2592 bfd_mips_elf_swap_options_out (stdoutput, &opthdr,
2593 (Elf_External_Options *) f);
2595 mips_regmask_frag = frag_more (sizeof (Elf64_External_RegInfo));
2599 if (ECOFF_DEBUGGING)
2601 sec = subseg_new (".mdebug", (subsegT) 0);
2602 (void) bfd_set_section_flags (stdoutput, sec,
2603 SEC_HAS_CONTENTS | SEC_READONLY);
2604 (void) bfd_set_section_alignment (stdoutput, sec, 2);
2606 else if (mips_flag_pdr)
2608 pdr_seg = subseg_new (".pdr", (subsegT) 0);
2609 (void) bfd_set_section_flags (stdoutput, pdr_seg,
2610 SEC_READONLY | SEC_RELOC
2612 (void) bfd_set_section_alignment (stdoutput, pdr_seg, 2);
2615 subseg_set (seg, subseg);
2618 #endif /* OBJ_ELF */
2620 if (! ECOFF_DEBUGGING)
2623 if (mips_fix_vr4120)
2624 init_vr4120_conflicts ();
2630 mips_emit_delays ();
2631 if (! ECOFF_DEBUGGING)
2636 md_assemble (char *str)
2638 struct mips_cl_insn insn;
2639 bfd_reloc_code_real_type unused_reloc[3]
2640 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
2642 imm_expr.X_op = O_absent;
2643 imm2_expr.X_op = O_absent;
2644 offset_expr.X_op = O_absent;
2645 imm_reloc[0] = BFD_RELOC_UNUSED;
2646 imm_reloc[1] = BFD_RELOC_UNUSED;
2647 imm_reloc[2] = BFD_RELOC_UNUSED;
2648 offset_reloc[0] = BFD_RELOC_UNUSED;
2649 offset_reloc[1] = BFD_RELOC_UNUSED;
2650 offset_reloc[2] = BFD_RELOC_UNUSED;
2652 mips_mark_labels ();
2653 mips_assembling_insn = TRUE;
2655 if (mips_opts.mips16)
2656 mips16_ip (str, &insn);
2659 mips_ip (str, &insn);
2660 DBG ((_("returned from mips_ip(%s) insn_opcode = 0x%x\n"),
2661 str, insn.insn_opcode));
2665 as_bad ("%s `%s'", insn_error, str);
2666 else if (insn.insn_mo->pinfo == INSN_MACRO)
2669 if (mips_opts.mips16)
2670 mips16_macro (&insn);
2677 if (imm_expr.X_op != O_absent)
2678 append_insn (&insn, &imm_expr, imm_reloc, FALSE);
2679 else if (offset_expr.X_op != O_absent)
2680 append_insn (&insn, &offset_expr, offset_reloc, FALSE);
2682 append_insn (&insn, NULL, unused_reloc, FALSE);
2685 mips_assembling_insn = FALSE;
2688 /* Convenience functions for abstracting away the differences between
2689 MIPS16 and non-MIPS16 relocations. */
2691 static inline bfd_boolean
2692 mips16_reloc_p (bfd_reloc_code_real_type reloc)
2696 case BFD_RELOC_MIPS16_JMP:
2697 case BFD_RELOC_MIPS16_GPREL:
2698 case BFD_RELOC_MIPS16_GOT16:
2699 case BFD_RELOC_MIPS16_CALL16:
2700 case BFD_RELOC_MIPS16_HI16_S:
2701 case BFD_RELOC_MIPS16_HI16:
2702 case BFD_RELOC_MIPS16_LO16:
2710 static inline bfd_boolean
2711 micromips_reloc_p (bfd_reloc_code_real_type reloc)
2715 case BFD_RELOC_MICROMIPS_7_PCREL_S1:
2716 case BFD_RELOC_MICROMIPS_10_PCREL_S1:
2717 case BFD_RELOC_MICROMIPS_16_PCREL_S1:
2718 case BFD_RELOC_MICROMIPS_GPREL16:
2719 case BFD_RELOC_MICROMIPS_JMP:
2720 case BFD_RELOC_MICROMIPS_HI16:
2721 case BFD_RELOC_MICROMIPS_HI16_S:
2722 case BFD_RELOC_MICROMIPS_LO16:
2723 case BFD_RELOC_MICROMIPS_LITERAL:
2724 case BFD_RELOC_MICROMIPS_GOT16:
2725 case BFD_RELOC_MICROMIPS_CALL16:
2726 case BFD_RELOC_MICROMIPS_GOT_HI16:
2727 case BFD_RELOC_MICROMIPS_GOT_LO16:
2728 case BFD_RELOC_MICROMIPS_CALL_HI16:
2729 case BFD_RELOC_MICROMIPS_CALL_LO16:
2730 case BFD_RELOC_MICROMIPS_SUB:
2731 case BFD_RELOC_MICROMIPS_GOT_PAGE:
2732 case BFD_RELOC_MICROMIPS_GOT_OFST:
2733 case BFD_RELOC_MICROMIPS_GOT_DISP:
2734 case BFD_RELOC_MICROMIPS_HIGHEST:
2735 case BFD_RELOC_MICROMIPS_HIGHER:
2736 case BFD_RELOC_MICROMIPS_SCN_DISP:
2737 case BFD_RELOC_MICROMIPS_JALR:
2745 static inline bfd_boolean
2746 jmp_reloc_p (bfd_reloc_code_real_type reloc)
2748 return reloc == BFD_RELOC_MIPS_JMP || reloc == BFD_RELOC_MICROMIPS_JMP;
2751 static inline bfd_boolean
2752 got16_reloc_p (bfd_reloc_code_real_type reloc)
2754 return (reloc == BFD_RELOC_MIPS_GOT16 || reloc == BFD_RELOC_MIPS16_GOT16
2755 || reloc == BFD_RELOC_MICROMIPS_GOT16);
2758 static inline bfd_boolean
2759 hi16_reloc_p (bfd_reloc_code_real_type reloc)
2761 return (reloc == BFD_RELOC_HI16_S || reloc == BFD_RELOC_MIPS16_HI16_S
2762 || reloc == BFD_RELOC_MICROMIPS_HI16_S);
2765 static inline bfd_boolean
2766 lo16_reloc_p (bfd_reloc_code_real_type reloc)
2768 return (reloc == BFD_RELOC_LO16 || reloc == BFD_RELOC_MIPS16_LO16
2769 || reloc == BFD_RELOC_MICROMIPS_LO16);
2772 static inline bfd_boolean
2773 jalr_reloc_p (bfd_reloc_code_real_type reloc)
2775 return reloc == BFD_RELOC_MIPS_JALR || reloc == BFD_RELOC_MICROMIPS_JALR;
2778 /* Return true if RELOC is a PC-relative relocation that does not have
2779 full address range. */
2781 static inline bfd_boolean
2782 limited_pcrel_reloc_p (bfd_reloc_code_real_type reloc)
2786 case BFD_RELOC_16_PCREL_S2:
2787 case BFD_RELOC_MICROMIPS_7_PCREL_S1:
2788 case BFD_RELOC_MICROMIPS_10_PCREL_S1:
2789 case BFD_RELOC_MICROMIPS_16_PCREL_S1:
2792 case BFD_RELOC_32_PCREL:
2793 return HAVE_64BIT_ADDRESSES;
2800 /* Return true if the given relocation might need a matching %lo().
2801 This is only "might" because SVR4 R_MIPS_GOT16 relocations only
2802 need a matching %lo() when applied to local symbols. */
2804 static inline bfd_boolean
2805 reloc_needs_lo_p (bfd_reloc_code_real_type reloc)
2807 return (HAVE_IN_PLACE_ADDENDS
2808 && (hi16_reloc_p (reloc)
2809 /* VxWorks R_MIPS_GOT16 relocs never need a matching %lo();
2810 all GOT16 relocations evaluate to "G". */
2811 || (got16_reloc_p (reloc) && mips_pic != VXWORKS_PIC)));
2814 /* Return the type of %lo() reloc needed by RELOC, given that
2815 reloc_needs_lo_p. */
2817 static inline bfd_reloc_code_real_type
2818 matching_lo_reloc (bfd_reloc_code_real_type reloc)
2820 return (mips16_reloc_p (reloc) ? BFD_RELOC_MIPS16_LO16
2821 : (micromips_reloc_p (reloc) ? BFD_RELOC_MICROMIPS_LO16
2825 /* Return true if the given fixup is followed by a matching R_MIPS_LO16
2828 static inline bfd_boolean
2829 fixup_has_matching_lo_p (fixS *fixp)
2831 return (fixp->fx_next != NULL
2832 && fixp->fx_next->fx_r_type == matching_lo_reloc (fixp->fx_r_type)
2833 && fixp->fx_addsy == fixp->fx_next->fx_addsy
2834 && fixp->fx_offset == fixp->fx_next->fx_offset);
2837 /* This function returns true if modifying a register requires a
2841 reg_needs_delay (unsigned int reg)
2843 unsigned long prev_pinfo;
2845 prev_pinfo = history[0].insn_mo->pinfo;
2846 if (! mips_opts.noreorder
2847 && (((prev_pinfo & INSN_LOAD_MEMORY_DELAY)
2848 && ! gpr_interlocks)
2849 || ((prev_pinfo & INSN_LOAD_COPROC_DELAY)
2850 && ! cop_interlocks)))
2852 /* A load from a coprocessor or from memory. All load delays
2853 delay the use of general register rt for one instruction. */
2854 /* Itbl support may require additional care here. */
2855 know (prev_pinfo & INSN_WRITE_GPR_T);
2856 if (reg == EXTRACT_OPERAND (mips_opts.micromips, RT, history[0]))
2863 /* Move all labels in LABELS to the current insertion point. TEXT_P
2864 says whether the labels refer to text or data. */
2867 mips_move_labels (struct insn_label_list *labels, bfd_boolean text_p)
2869 struct insn_label_list *l;
2872 for (l = labels; l != NULL; l = l->next)
2874 gas_assert (S_GET_SEGMENT (l->label) == now_seg);
2875 symbol_set_frag (l->label, frag_now);
2876 val = (valueT) frag_now_fix ();
2877 /* MIPS16/microMIPS text labels are stored as odd. */
2878 if (text_p && HAVE_CODE_COMPRESSION)
2880 S_SET_VALUE (l->label, val);
2884 /* Move all labels in insn_labels to the current insertion point
2885 and treat them as text labels. */
2888 mips_move_text_labels (void)
2890 mips_move_labels (seg_info (now_seg)->label_list, TRUE);
2894 s_is_linkonce (symbolS *sym, segT from_seg)
2896 bfd_boolean linkonce = FALSE;
2897 segT symseg = S_GET_SEGMENT (sym);
2899 if (symseg != from_seg && !S_IS_LOCAL (sym))
2901 if ((bfd_get_section_flags (stdoutput, symseg) & SEC_LINK_ONCE))
2904 /* The GNU toolchain uses an extension for ELF: a section
2905 beginning with the magic string .gnu.linkonce is a
2906 linkonce section. */
2907 if (strncmp (segment_name (symseg), ".gnu.linkonce",
2908 sizeof ".gnu.linkonce" - 1) == 0)
2915 /* Mark MIPS16 or microMIPS instruction label LABEL. This permits the
2916 linker to handle them specially, such as generating jalx instructions
2917 when needed. We also make them odd for the duration of the assembly,
2918 in order to generate the right sort of code. We will make them even
2919 in the adjust_symtab routine, while leaving them marked. This is
2920 convenient for the debugger and the disassembler. The linker knows
2921 to make them odd again. */
2924 mips_compressed_mark_label (symbolS *label)
2926 gas_assert (HAVE_CODE_COMPRESSION);
2928 #if defined(OBJ_ELF) || defined(OBJ_MAYBE_ELF)
2931 if (mips_opts.mips16)
2932 S_SET_OTHER (label, ELF_ST_SET_MIPS16 (S_GET_OTHER (label)));
2934 S_SET_OTHER (label, ELF_ST_SET_MICROMIPS (S_GET_OTHER (label)));
2937 if ((S_GET_VALUE (label) & 1) == 0
2938 /* Don't adjust the address if the label is global or weak, or
2939 in a link-once section, since we'll be emitting symbol reloc
2940 references to it which will be patched up by the linker, and
2941 the final value of the symbol may or may not be MIPS16/microMIPS. */
2942 && !S_IS_WEAK (label)
2943 && !S_IS_EXTERNAL (label)
2944 && !s_is_linkonce (label, now_seg))
2945 S_SET_VALUE (label, S_GET_VALUE (label) | 1);
2948 /* Mark preceding MIPS16 or microMIPS instruction labels. */
2951 mips_compressed_mark_labels (void)
2953 struct insn_label_list *l;
2955 for (l = seg_info (now_seg)->label_list; l != NULL; l = l->next)
2956 mips_compressed_mark_label (l->label);
2959 /* End the current frag. Make it a variant frag and record the
2963 relax_close_frag (void)
2965 mips_macro_warning.first_frag = frag_now;
2966 frag_var (rs_machine_dependent, 0, 0,
2967 RELAX_ENCODE (mips_relax.sizes[0], mips_relax.sizes[1]),
2968 mips_relax.symbol, 0, (char *) mips_relax.first_fixup);
2970 memset (&mips_relax.sizes, 0, sizeof (mips_relax.sizes));
2971 mips_relax.first_fixup = 0;
2974 /* Start a new relaxation sequence whose expansion depends on SYMBOL.
2975 See the comment above RELAX_ENCODE for more details. */
2978 relax_start (symbolS *symbol)
2980 gas_assert (mips_relax.sequence == 0);
2981 mips_relax.sequence = 1;
2982 mips_relax.symbol = symbol;
2985 /* Start generating the second version of a relaxable sequence.
2986 See the comment above RELAX_ENCODE for more details. */
2991 gas_assert (mips_relax.sequence == 1);
2992 mips_relax.sequence = 2;
2995 /* End the current relaxable sequence. */
3000 gas_assert (mips_relax.sequence == 2);
3001 relax_close_frag ();
3002 mips_relax.sequence = 0;
3005 /* Return true if IP is a delayed branch or jump. */
3007 static inline bfd_boolean
3008 delayed_branch_p (const struct mips_cl_insn *ip)
3010 return (ip->insn_mo->pinfo & (INSN_UNCOND_BRANCH_DELAY
3011 | INSN_COND_BRANCH_DELAY
3012 | INSN_COND_BRANCH_LIKELY)) != 0;
3015 /* Return true if IP is a compact branch or jump. */
3017 static inline bfd_boolean
3018 compact_branch_p (const struct mips_cl_insn *ip)
3020 if (mips_opts.mips16)
3021 return (ip->insn_mo->pinfo & (MIPS16_INSN_UNCOND_BRANCH
3022 | MIPS16_INSN_COND_BRANCH)) != 0;
3024 return (ip->insn_mo->pinfo2 & (INSN2_UNCOND_BRANCH
3025 | INSN2_COND_BRANCH)) != 0;
3028 /* Return true if IP is an unconditional branch or jump. */
3030 static inline bfd_boolean
3031 uncond_branch_p (const struct mips_cl_insn *ip)
3033 return ((ip->insn_mo->pinfo & INSN_UNCOND_BRANCH_DELAY) != 0
3034 || (mips_opts.mips16
3035 ? (ip->insn_mo->pinfo & MIPS16_INSN_UNCOND_BRANCH) != 0
3036 : (ip->insn_mo->pinfo2 & INSN2_UNCOND_BRANCH) != 0));
3039 /* Return true if IP is a branch-likely instruction. */
3041 static inline bfd_boolean
3042 branch_likely_p (const struct mips_cl_insn *ip)
3044 return (ip->insn_mo->pinfo & INSN_COND_BRANCH_LIKELY) != 0;
3047 /* Return the type of nop that should be used to fill the delay slot
3048 of delayed branch IP. */
3050 static struct mips_cl_insn *
3051 get_delay_slot_nop (const struct mips_cl_insn *ip)
3053 if (mips_opts.micromips
3054 && (ip->insn_mo->pinfo2 & INSN2_BRANCH_DELAY_32BIT))
3055 return µmips_nop32_insn;
3059 /* Return the mask of core registers that IP reads or writes. */
3062 gpr_mod_mask (const struct mips_cl_insn *ip)
3064 unsigned long pinfo2;
3068 pinfo2 = ip->insn_mo->pinfo2;
3069 if (mips_opts.micromips)
3071 if (pinfo2 & INSN2_MOD_GPR_MD)
3072 mask |= 1 << micromips_to_32_reg_d_map[EXTRACT_OPERAND (1, MD, *ip)];
3073 if (pinfo2 & INSN2_MOD_GPR_MF)
3074 mask |= 1 << micromips_to_32_reg_f_map[EXTRACT_OPERAND (1, MF, *ip)];
3075 if (pinfo2 & INSN2_MOD_SP)
3081 /* Return the mask of core registers that IP reads. */
3084 gpr_read_mask (const struct mips_cl_insn *ip)
3086 unsigned long pinfo, pinfo2;
3089 mask = gpr_mod_mask (ip);
3090 pinfo = ip->insn_mo->pinfo;
3091 pinfo2 = ip->insn_mo->pinfo2;
3092 if (mips_opts.mips16)
3094 if (pinfo & MIPS16_INSN_READ_X)
3095 mask |= 1 << mips16_to_32_reg_map[MIPS16_EXTRACT_OPERAND (RX, *ip)];
3096 if (pinfo & MIPS16_INSN_READ_Y)
3097 mask |= 1 << mips16_to_32_reg_map[MIPS16_EXTRACT_OPERAND (RY, *ip)];
3098 if (pinfo & MIPS16_INSN_READ_T)
3100 if (pinfo & MIPS16_INSN_READ_SP)
3102 if (pinfo & MIPS16_INSN_READ_31)
3104 if (pinfo & MIPS16_INSN_READ_Z)
3105 mask |= 1 << (mips16_to_32_reg_map
3106 [MIPS16_EXTRACT_OPERAND (MOVE32Z, *ip)]);
3107 if (pinfo & MIPS16_INSN_READ_GPR_X)
3108 mask |= 1 << MIPS16_EXTRACT_OPERAND (REGR32, *ip);
3112 if (pinfo2 & INSN2_READ_GPR_D)
3113 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RD, *ip);
3114 if (pinfo & INSN_READ_GPR_T)
3115 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RT, *ip);
3116 if (pinfo & INSN_READ_GPR_S)
3117 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RS, *ip);
3118 if (pinfo2 & INSN2_READ_GP)
3120 if (pinfo2 & INSN2_READ_GPR_31)
3122 if (pinfo2 & INSN2_READ_GPR_Z)
3123 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RZ, *ip);
3125 if (mips_opts.micromips)
3127 if (pinfo2 & INSN2_READ_GPR_MC)
3128 mask |= 1 << micromips_to_32_reg_c_map[EXTRACT_OPERAND (1, MC, *ip)];
3129 if (pinfo2 & INSN2_READ_GPR_ME)
3130 mask |= 1 << micromips_to_32_reg_e_map[EXTRACT_OPERAND (1, ME, *ip)];
3131 if (pinfo2 & INSN2_READ_GPR_MG)
3132 mask |= 1 << micromips_to_32_reg_g_map[EXTRACT_OPERAND (1, MG, *ip)];
3133 if (pinfo2 & INSN2_READ_GPR_MJ)
3134 mask |= 1 << EXTRACT_OPERAND (1, MJ, *ip);
3135 if (pinfo2 & INSN2_READ_GPR_MMN)
3137 mask |= 1 << micromips_to_32_reg_m_map[EXTRACT_OPERAND (1, MM, *ip)];
3138 mask |= 1 << micromips_to_32_reg_n_map[EXTRACT_OPERAND (1, MN, *ip)];
3140 if (pinfo2 & INSN2_READ_GPR_MP)
3141 mask |= 1 << EXTRACT_OPERAND (1, MP, *ip);
3142 if (pinfo2 & INSN2_READ_GPR_MQ)
3143 mask |= 1 << micromips_to_32_reg_q_map[EXTRACT_OPERAND (1, MQ, *ip)];
3145 /* Don't include register 0. */
3149 /* Return the mask of core registers that IP writes. */
3152 gpr_write_mask (const struct mips_cl_insn *ip)
3154 unsigned long pinfo, pinfo2;
3157 mask = gpr_mod_mask (ip);
3158 pinfo = ip->insn_mo->pinfo;
3159 pinfo2 = ip->insn_mo->pinfo2;
3160 if (mips_opts.mips16)
3162 if (pinfo & MIPS16_INSN_WRITE_X)
3163 mask |= 1 << mips16_to_32_reg_map[MIPS16_EXTRACT_OPERAND (RX, *ip)];
3164 if (pinfo & MIPS16_INSN_WRITE_Y)
3165 mask |= 1 << mips16_to_32_reg_map[MIPS16_EXTRACT_OPERAND (RY, *ip)];
3166 if (pinfo & MIPS16_INSN_WRITE_Z)
3167 mask |= 1 << mips16_to_32_reg_map[MIPS16_EXTRACT_OPERAND (RZ, *ip)];
3168 if (pinfo & MIPS16_INSN_WRITE_T)
3170 if (pinfo & MIPS16_INSN_WRITE_SP)
3172 if (pinfo & MIPS16_INSN_WRITE_31)
3174 if (pinfo & MIPS16_INSN_WRITE_GPR_Y)
3175 mask |= 1 << MIPS16OP_EXTRACT_REG32R (ip->insn_opcode);
3179 if (pinfo & INSN_WRITE_GPR_D)
3180 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RD, *ip);
3181 if (pinfo & INSN_WRITE_GPR_T)
3182 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RT, *ip);
3183 if (pinfo & INSN_WRITE_GPR_S)
3184 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RS, *ip);
3185 if (pinfo & INSN_WRITE_GPR_31)
3187 if (pinfo2 & INSN2_WRITE_GPR_Z)
3188 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RZ, *ip);
3190 if (mips_opts.micromips)
3192 if (pinfo2 & INSN2_WRITE_GPR_MB)
3193 mask |= 1 << micromips_to_32_reg_b_map[EXTRACT_OPERAND (1, MB, *ip)];
3194 if (pinfo2 & INSN2_WRITE_GPR_MHI)
3196 mask |= 1 << micromips_to_32_reg_h_map[EXTRACT_OPERAND (1, MH, *ip)];
3197 mask |= 1 << micromips_to_32_reg_i_map[EXTRACT_OPERAND (1, MI, *ip)];
3199 if (pinfo2 & INSN2_WRITE_GPR_MJ)
3200 mask |= 1 << EXTRACT_OPERAND (1, MJ, *ip);
3201 if (pinfo2 & INSN2_WRITE_GPR_MP)
3202 mask |= 1 << EXTRACT_OPERAND (1, MP, *ip);
3204 /* Don't include register 0. */
3208 /* Return the mask of floating-point registers that IP reads. */
3211 fpr_read_mask (const struct mips_cl_insn *ip)
3213 unsigned long pinfo, pinfo2;
3217 pinfo = ip->insn_mo->pinfo;
3218 pinfo2 = ip->insn_mo->pinfo2;
3219 if (!mips_opts.mips16)
3221 if (pinfo2 & INSN2_READ_FPR_D)
3222 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FD, *ip);
3223 if (pinfo & INSN_READ_FPR_S)
3224 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FS, *ip);
3225 if (pinfo & INSN_READ_FPR_T)
3226 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FT, *ip);
3227 if (pinfo & INSN_READ_FPR_R)
3228 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FR, *ip);
3229 if (pinfo2 & INSN2_READ_FPR_Z)
3230 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FZ, *ip);
3232 /* Conservatively treat all operands to an FP_D instruction are doubles.
3233 (This is overly pessimistic for things like cvt.d.s.) */
3234 if (HAVE_32BIT_FPRS && (pinfo & FP_D))
3239 /* Return the mask of floating-point registers that IP writes. */
3242 fpr_write_mask (const struct mips_cl_insn *ip)
3244 unsigned long pinfo, pinfo2;
3248 pinfo = ip->insn_mo->pinfo;
3249 pinfo2 = ip->insn_mo->pinfo2;
3250 if (!mips_opts.mips16)
3252 if (pinfo & INSN_WRITE_FPR_D)
3253 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FD, *ip);
3254 if (pinfo & INSN_WRITE_FPR_S)
3255 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FS, *ip);
3256 if (pinfo & INSN_WRITE_FPR_T)
3257 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FT, *ip);
3258 if (pinfo2 & INSN2_WRITE_FPR_Z)
3259 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FZ, *ip);
3261 /* Conservatively treat all operands to an FP_D instruction are doubles.
3262 (This is overly pessimistic for things like cvt.s.d.) */
3263 if (HAVE_32BIT_FPRS && (pinfo & FP_D))
3268 /* Classify an instruction according to the FIX_VR4120_* enumeration.
3269 Return NUM_FIX_VR4120_CLASSES if the instruction isn't affected
3270 by VR4120 errata. */
3273 classify_vr4120_insn (const char *name)
3275 if (strncmp (name, "macc", 4) == 0)
3276 return FIX_VR4120_MACC;
3277 if (strncmp (name, "dmacc", 5) == 0)
3278 return FIX_VR4120_DMACC;
3279 if (strncmp (name, "mult", 4) == 0)
3280 return FIX_VR4120_MULT;
3281 if (strncmp (name, "dmult", 5) == 0)
3282 return FIX_VR4120_DMULT;
3283 if (strstr (name, "div"))
3284 return FIX_VR4120_DIV;
3285 if (strcmp (name, "mtlo") == 0 || strcmp (name, "mthi") == 0)
3286 return FIX_VR4120_MTHILO;
3287 return NUM_FIX_VR4120_CLASSES;
3290 #define INSN_ERET 0x42000018
3291 #define INSN_DERET 0x4200001f
3293 /* Return the number of instructions that must separate INSN1 and INSN2,
3294 where INSN1 is the earlier instruction. Return the worst-case value
3295 for any INSN2 if INSN2 is null. */
3298 insns_between (const struct mips_cl_insn *insn1,
3299 const struct mips_cl_insn *insn2)
3301 unsigned long pinfo1, pinfo2;
3304 /* This function needs to know which pinfo flags are set for INSN2
3305 and which registers INSN2 uses. The former is stored in PINFO2 and
3306 the latter is tested via INSN2_USES_GPR. If INSN2 is null, PINFO2
3307 will have every flag set and INSN2_USES_GPR will always return true. */
3308 pinfo1 = insn1->insn_mo->pinfo;
3309 pinfo2 = insn2 ? insn2->insn_mo->pinfo : ~0U;
3311 #define INSN2_USES_GPR(REG) \
3312 (insn2 == NULL || (gpr_read_mask (insn2) & (1U << (REG))) != 0)
3314 /* For most targets, write-after-read dependencies on the HI and LO
3315 registers must be separated by at least two instructions. */
3316 if (!hilo_interlocks)
3318 if ((pinfo1 & INSN_READ_LO) && (pinfo2 & INSN_WRITE_LO))
3320 if ((pinfo1 & INSN_READ_HI) && (pinfo2 & INSN_WRITE_HI))
3324 /* If we're working around r7000 errata, there must be two instructions
3325 between an mfhi or mflo and any instruction that uses the result. */
3326 if (mips_7000_hilo_fix
3327 && !mips_opts.micromips
3328 && MF_HILO_INSN (pinfo1)
3329 && INSN2_USES_GPR (EXTRACT_OPERAND (0, RD, *insn1)))
3332 /* If we're working around 24K errata, one instruction is required
3333 if an ERET or DERET is followed by a branch instruction. */
3334 if (mips_fix_24k && !mips_opts.micromips)
3336 if (insn1->insn_opcode == INSN_ERET
3337 || insn1->insn_opcode == INSN_DERET)
3340 || insn2->insn_opcode == INSN_ERET
3341 || insn2->insn_opcode == INSN_DERET
3342 || delayed_branch_p (insn2))
3347 /* If working around VR4120 errata, check for combinations that need
3348 a single intervening instruction. */
3349 if (mips_fix_vr4120 && !mips_opts.micromips)
3351 unsigned int class1, class2;
3353 class1 = classify_vr4120_insn (insn1->insn_mo->name);
3354 if (class1 != NUM_FIX_VR4120_CLASSES && vr4120_conflicts[class1] != 0)
3358 class2 = classify_vr4120_insn (insn2->insn_mo->name);
3359 if (vr4120_conflicts[class1] & (1 << class2))
3364 if (!HAVE_CODE_COMPRESSION)
3366 /* Check for GPR or coprocessor load delays. All such delays
3367 are on the RT register. */
3368 /* Itbl support may require additional care here. */
3369 if ((!gpr_interlocks && (pinfo1 & INSN_LOAD_MEMORY_DELAY))
3370 || (!cop_interlocks && (pinfo1 & INSN_LOAD_COPROC_DELAY)))
3372 know (pinfo1 & INSN_WRITE_GPR_T);
3373 if (INSN2_USES_GPR (EXTRACT_OPERAND (0, RT, *insn1)))
3377 /* Check for generic coprocessor hazards.
3379 This case is not handled very well. There is no special
3380 knowledge of CP0 handling, and the coprocessors other than
3381 the floating point unit are not distinguished at all. */
3382 /* Itbl support may require additional care here. FIXME!
3383 Need to modify this to include knowledge about
3384 user specified delays! */
3385 else if ((!cop_interlocks && (pinfo1 & INSN_COPROC_MOVE_DELAY))
3386 || (!cop_mem_interlocks && (pinfo1 & INSN_COPROC_MEMORY_DELAY)))
3388 /* Handle cases where INSN1 writes to a known general coprocessor
3389 register. There must be a one instruction delay before INSN2
3390 if INSN2 reads that register, otherwise no delay is needed. */
3391 mask = fpr_write_mask (insn1);
3394 if (!insn2 || (mask & fpr_read_mask (insn2)) != 0)
3399 /* Read-after-write dependencies on the control registers
3400 require a two-instruction gap. */
3401 if ((pinfo1 & INSN_WRITE_COND_CODE)
3402 && (pinfo2 & INSN_READ_COND_CODE))
3405 /* We don't know exactly what INSN1 does. If INSN2 is
3406 also a coprocessor instruction, assume there must be
3407 a one instruction gap. */
3408 if (pinfo2 & INSN_COP)
3413 /* Check for read-after-write dependencies on the coprocessor
3414 control registers in cases where INSN1 does not need a general
3415 coprocessor delay. This means that INSN1 is a floating point
3416 comparison instruction. */
3417 /* Itbl support may require additional care here. */
3418 else if (!cop_interlocks
3419 && (pinfo1 & INSN_WRITE_COND_CODE)
3420 && (pinfo2 & INSN_READ_COND_CODE))
3424 #undef INSN2_USES_GPR
3429 /* Return the number of nops that would be needed to work around the
3430 VR4130 mflo/mfhi errata if instruction INSN immediately followed
3431 the MAX_VR4130_NOPS instructions described by HIST. Ignore hazards
3432 that are contained within the first IGNORE instructions of HIST. */
3435 nops_for_vr4130 (int ignore, const struct mips_cl_insn *hist,
3436 const struct mips_cl_insn *insn)
3441 /* Check if the instruction writes to HI or LO. MTHI and MTLO
3442 are not affected by the errata. */
3444 && ((insn->insn_mo->pinfo & (INSN_WRITE_HI | INSN_WRITE_LO)) == 0
3445 || strcmp (insn->insn_mo->name, "mtlo") == 0
3446 || strcmp (insn->insn_mo->name, "mthi") == 0))
3449 /* Search for the first MFLO or MFHI. */
3450 for (i = 0; i < MAX_VR4130_NOPS; i++)
3451 if (MF_HILO_INSN (hist[i].insn_mo->pinfo))
3453 /* Extract the destination register. */
3454 mask = gpr_write_mask (&hist[i]);
3456 /* No nops are needed if INSN reads that register. */
3457 if (insn != NULL && (gpr_read_mask (insn) & mask) != 0)
3460 /* ...or if any of the intervening instructions do. */
3461 for (j = 0; j < i; j++)
3462 if (gpr_read_mask (&hist[j]) & mask)
3466 return MAX_VR4130_NOPS - i;
3471 #define BASE_REG_EQ(INSN1, INSN2) \
3472 ((((INSN1) >> OP_SH_RS) & OP_MASK_RS) \
3473 == (((INSN2) >> OP_SH_RS) & OP_MASK_RS))
3475 /* Return the minimum alignment for this store instruction. */
3478 fix_24k_align_to (const struct mips_opcode *mo)
3480 if (strcmp (mo->name, "sh") == 0)
3483 if (strcmp (mo->name, "swc1") == 0
3484 || strcmp (mo->name, "swc2") == 0
3485 || strcmp (mo->name, "sw") == 0
3486 || strcmp (mo->name, "sc") == 0
3487 || strcmp (mo->name, "s.s") == 0)
3490 if (strcmp (mo->name, "sdc1") == 0
3491 || strcmp (mo->name, "sdc2") == 0
3492 || strcmp (mo->name, "s.d") == 0)
3499 struct fix_24k_store_info
3501 /* Immediate offset, if any, for this store instruction. */
3503 /* Alignment required by this store instruction. */
3505 /* True for register offsets. */
3506 int register_offset;
3509 /* Comparison function used by qsort. */
3512 fix_24k_sort (const void *a, const void *b)
3514 const struct fix_24k_store_info *pos1 = a;
3515 const struct fix_24k_store_info *pos2 = b;
3517 return (pos1->off - pos2->off);
3520 /* INSN is a store instruction. Try to record the store information
3521 in STINFO. Return false if the information isn't known. */
3524 fix_24k_record_store_info (struct fix_24k_store_info *stinfo,
3525 const struct mips_cl_insn *insn)
3527 /* The instruction must have a known offset. */
3528 if (!insn->complete_p || !strstr (insn->insn_mo->args, "o("))
3531 stinfo->off = (insn->insn_opcode >> OP_SH_IMMEDIATE) & OP_MASK_IMMEDIATE;
3532 stinfo->align_to = fix_24k_align_to (insn->insn_mo);
3536 /* Return the number of nops that would be needed to work around the 24k
3537 "lost data on stores during refill" errata if instruction INSN
3538 immediately followed the 2 instructions described by HIST.
3539 Ignore hazards that are contained within the first IGNORE
3540 instructions of HIST.
3542 Problem: The FSB (fetch store buffer) acts as an intermediate buffer
3543 for the data cache refills and store data. The following describes
3544 the scenario where the store data could be lost.
3546 * A data cache miss, due to either a load or a store, causing fill
3547 data to be supplied by the memory subsystem
3548 * The first three doublewords of fill data are returned and written
3550 * A sequence of four stores occurs in consecutive cycles around the
3551 final doubleword of the fill:
3555 * Zero, One or more instructions
3558 The four stores A-D must be to different doublewords of the line that
3559 is being filled. The fourth instruction in the sequence above permits
3560 the fill of the final doubleword to be transferred from the FSB into
3561 the cache. In the sequence above, the stores may be either integer
3562 (sb, sh, sw, swr, swl, sc) or coprocessor (swc1/swc2, sdc1/sdc2,
3563 swxc1, sdxc1, suxc1) stores, as long as the four stores are to
3564 different doublewords on the line. If the floating point unit is
3565 running in 1:2 mode, it is not possible to create the sequence above
3566 using only floating point store instructions.
3568 In this case, the cache line being filled is incorrectly marked
3569 invalid, thereby losing the data from any store to the line that
3570 occurs between the original miss and the completion of the five
3571 cycle sequence shown above.
3573 The workarounds are:
3575 * Run the data cache in write-through mode.
3576 * Insert a non-store instruction between
3577 Store A and Store B or Store B and Store C. */
3580 nops_for_24k (int ignore, const struct mips_cl_insn *hist,
3581 const struct mips_cl_insn *insn)
3583 struct fix_24k_store_info pos[3];
3584 int align, i, base_offset;
3589 /* If the previous instruction wasn't a store, there's nothing to
3591 if ((hist[0].insn_mo->pinfo & INSN_STORE_MEMORY) == 0)
3594 /* If the instructions after the previous one are unknown, we have
3595 to assume the worst. */
3599 /* Check whether we are dealing with three consecutive stores. */
3600 if ((insn->insn_mo->pinfo & INSN_STORE_MEMORY) == 0
3601 || (hist[1].insn_mo->pinfo & INSN_STORE_MEMORY) == 0)
3604 /* If we don't know the relationship between the store addresses,
3605 assume the worst. */
3606 if (!BASE_REG_EQ (insn->insn_opcode, hist[0].insn_opcode)
3607 || !BASE_REG_EQ (insn->insn_opcode, hist[1].insn_opcode))
3610 if (!fix_24k_record_store_info (&pos[0], insn)
3611 || !fix_24k_record_store_info (&pos[1], &hist[0])
3612 || !fix_24k_record_store_info (&pos[2], &hist[1]))
3615 qsort (&pos, 3, sizeof (struct fix_24k_store_info), fix_24k_sort);
3617 /* Pick a value of ALIGN and X such that all offsets are adjusted by
3618 X bytes and such that the base register + X is known to be aligned
3621 if (((insn->insn_opcode >> OP_SH_RS) & OP_MASK_RS) == SP)
3625 align = pos[0].align_to;
3626 base_offset = pos[0].off;
3627 for (i = 1; i < 3; i++)
3628 if (align < pos[i].align_to)
3630 align = pos[i].align_to;
3631 base_offset = pos[i].off;
3633 for (i = 0; i < 3; i++)
3634 pos[i].off -= base_offset;
3637 pos[0].off &= ~align + 1;
3638 pos[1].off &= ~align + 1;
3639 pos[2].off &= ~align + 1;
3641 /* If any two stores write to the same chunk, they also write to the
3642 same doubleword. The offsets are still sorted at this point. */
3643 if (pos[0].off == pos[1].off || pos[1].off == pos[2].off)
3646 /* A range of at least 9 bytes is needed for the stores to be in
3647 non-overlapping doublewords. */
3648 if (pos[2].off - pos[0].off <= 8)
3651 if (pos[2].off - pos[1].off >= 24
3652 || pos[1].off - pos[0].off >= 24
3653 || pos[2].off - pos[0].off >= 32)
3659 /* Return the number of nops that would be needed if instruction INSN
3660 immediately followed the MAX_NOPS instructions given by HIST,
3661 where HIST[0] is the most recent instruction. Ignore hazards
3662 between INSN and the first IGNORE instructions in HIST.
3664 If INSN is null, return the worse-case number of nops for any
3668 nops_for_insn (int ignore, const struct mips_cl_insn *hist,
3669 const struct mips_cl_insn *insn)
3671 int i, nops, tmp_nops;
3674 for (i = ignore; i < MAX_DELAY_NOPS; i++)
3676 tmp_nops = insns_between (hist + i, insn) - i;
3677 if (tmp_nops > nops)
3681 if (mips_fix_vr4130 && !mips_opts.micromips)
3683 tmp_nops = nops_for_vr4130 (ignore, hist, insn);
3684 if (tmp_nops > nops)
3688 if (mips_fix_24k && !mips_opts.micromips)
3690 tmp_nops = nops_for_24k (ignore, hist, insn);
3691 if (tmp_nops > nops)
3698 /* The variable arguments provide NUM_INSNS extra instructions that
3699 might be added to HIST. Return the largest number of nops that
3700 would be needed after the extended sequence, ignoring hazards
3701 in the first IGNORE instructions. */
3704 nops_for_sequence (int num_insns, int ignore,
3705 const struct mips_cl_insn *hist, ...)
3708 struct mips_cl_insn buffer[MAX_NOPS];
3709 struct mips_cl_insn *cursor;
3712 va_start (args, hist);
3713 cursor = buffer + num_insns;
3714 memcpy (cursor, hist, (MAX_NOPS - num_insns) * sizeof (*cursor));
3715 while (cursor > buffer)
3716 *--cursor = *va_arg (args, const struct mips_cl_insn *);
3718 nops = nops_for_insn (ignore, buffer, NULL);
3723 /* Like nops_for_insn, but if INSN is a branch, take into account the
3724 worst-case delay for the branch target. */
3727 nops_for_insn_or_target (int ignore, const struct mips_cl_insn *hist,
3728 const struct mips_cl_insn *insn)
3732 nops = nops_for_insn (ignore, hist, insn);
3733 if (delayed_branch_p (insn))
3735 tmp_nops = nops_for_sequence (2, ignore ? ignore + 2 : 0,
3736 hist, insn, get_delay_slot_nop (insn));
3737 if (tmp_nops > nops)
3740 else if (compact_branch_p (insn))
3742 tmp_nops = nops_for_sequence (1, ignore ? ignore + 1 : 0, hist, insn);
3743 if (tmp_nops > nops)
3749 /* Fix NOP issue: Replace nops by "or at,at,zero". */
3752 fix_loongson2f_nop (struct mips_cl_insn * ip)
3754 gas_assert (!HAVE_CODE_COMPRESSION);
3755 if (strcmp (ip->insn_mo->name, "nop") == 0)
3756 ip->insn_opcode = LOONGSON2F_NOP_INSN;
3759 /* Fix Jump Issue: Eliminate instruction fetch from outside 256M region
3760 jr target pc &= 'hffff_ffff_cfff_ffff. */
3763 fix_loongson2f_jump (struct mips_cl_insn * ip)
3765 gas_assert (!HAVE_CODE_COMPRESSION);
3766 if (strcmp (ip->insn_mo->name, "j") == 0
3767 || strcmp (ip->insn_mo->name, "jr") == 0
3768 || strcmp (ip->insn_mo->name, "jalr") == 0)
3776 sreg = EXTRACT_OPERAND (0, RS, *ip);
3777 if (sreg == ZERO || sreg == KT0 || sreg == KT1 || sreg == ATREG)
3780 ep.X_op = O_constant;
3781 ep.X_add_number = 0xcfff0000;
3782 macro_build (&ep, "lui", "t,u", ATREG, BFD_RELOC_HI16);
3783 ep.X_add_number = 0xffff;
3784 macro_build (&ep, "ori", "t,r,i", ATREG, ATREG, BFD_RELOC_LO16);
3785 macro_build (NULL, "and", "d,v,t", sreg, sreg, ATREG);
3790 fix_loongson2f (struct mips_cl_insn * ip)
3792 if (mips_fix_loongson2f_nop)
3793 fix_loongson2f_nop (ip);
3795 if (mips_fix_loongson2f_jump)
3796 fix_loongson2f_jump (ip);
3799 /* IP is a branch that has a delay slot, and we need to fill it
3800 automatically. Return true if we can do that by swapping IP
3801 with the previous instruction.
3802 ADDRESS_EXPR is an operand of the instruction to be used with
3806 can_swap_branch_p (struct mips_cl_insn *ip, expressionS *address_expr,
3807 bfd_reloc_code_real_type *reloc_type)
3809 unsigned long pinfo, pinfo2, prev_pinfo, prev_pinfo2;
3810 unsigned int gpr_read, gpr_write, prev_gpr_read, prev_gpr_write;
3812 /* -O2 and above is required for this optimization. */
3813 if (mips_optimize < 2)
3816 /* If we have seen .set volatile or .set nomove, don't optimize. */
3817 if (mips_opts.nomove)
3820 /* We can't swap if the previous instruction's position is fixed. */
3821 if (history[0].fixed_p)
3824 /* If the previous previous insn was in a .set noreorder, we can't
3825 swap. Actually, the MIPS assembler will swap in this situation.
3826 However, gcc configured -with-gnu-as will generate code like
3834 in which we can not swap the bne and INSN. If gcc is not configured
3835 -with-gnu-as, it does not output the .set pseudo-ops. */
3836 if (history[1].noreorder_p)
3839 /* If the previous instruction had a fixup in mips16 mode, we can not swap.
3840 This means that the previous instruction was a 4-byte one anyhow. */
3841 if (mips_opts.mips16 && history[0].fixp[0])
3844 /* If the branch is itself the target of a branch, we can not swap.
3845 We cheat on this; all we check for is whether there is a label on
3846 this instruction. If there are any branches to anything other than
3847 a label, users must use .set noreorder. */
3848 if (seg_info (now_seg)->label_list)
3851 /* If the previous instruction is in a variant frag other than this
3852 branch's one, we cannot do the swap. This does not apply to
3853 MIPS16 code, which uses variant frags for different purposes. */
3854 if (!mips_opts.mips16
3856 && history[0].frag->fr_type == rs_machine_dependent)
3859 /* We do not swap with instructions that cannot architecturally
3860 be placed in a branch delay slot, such as SYNC or ERET. We
3861 also refrain from swapping with a trap instruction, since it
3862 complicates trap handlers to have the trap instruction be in
3864 prev_pinfo = history[0].insn_mo->pinfo;
3865 if (prev_pinfo & INSN_NO_DELAY_SLOT)
3868 /* Check for conflicts between the branch and the instructions
3869 before the candidate delay slot. */
3870 if (nops_for_insn (0, history + 1, ip) > 0)
3873 /* Check for conflicts between the swapped sequence and the
3874 target of the branch. */
3875 if (nops_for_sequence (2, 0, history + 1, ip, history) > 0)
3878 /* If the branch reads a register that the previous
3879 instruction sets, we can not swap. */
3880 gpr_read = gpr_read_mask (ip);
3881 prev_gpr_write = gpr_write_mask (&history[0]);
3882 if (gpr_read & prev_gpr_write)
3885 /* If the branch writes a register that the previous
3886 instruction sets, we can not swap. */
3887 gpr_write = gpr_write_mask (ip);
3888 if (gpr_write & prev_gpr_write)
3891 /* If the branch writes a register that the previous
3892 instruction reads, we can not swap. */
3893 prev_gpr_read = gpr_read_mask (&history[0]);
3894 if (gpr_write & prev_gpr_read)
3897 /* If one instruction sets a condition code and the
3898 other one uses a condition code, we can not swap. */
3899 pinfo = ip->insn_mo->pinfo;
3900 if ((pinfo & INSN_READ_COND_CODE)
3901 && (prev_pinfo & INSN_WRITE_COND_CODE))
3903 if ((pinfo & INSN_WRITE_COND_CODE)
3904 && (prev_pinfo & INSN_READ_COND_CODE))
3907 /* If the previous instruction uses the PC, we can not swap. */
3908 prev_pinfo2 = history[0].insn_mo->pinfo2;
3909 if (mips_opts.mips16 && (prev_pinfo & MIPS16_INSN_READ_PC))
3911 if (mips_opts.micromips && (prev_pinfo2 & INSN2_READ_PC))
3914 /* If the previous instruction has an incorrect size for a fixed
3915 branch delay slot in microMIPS mode, we cannot swap. */
3916 pinfo2 = ip->insn_mo->pinfo2;
3917 if (mips_opts.micromips
3918 && (pinfo2 & INSN2_BRANCH_DELAY_16BIT)
3919 && insn_length (history) != 2)
3921 if (mips_opts.micromips
3922 && (pinfo2 & INSN2_BRANCH_DELAY_32BIT)
3923 && insn_length (history) != 4)
3926 /* On R5900 short loops need to be fixed by inserting a nop in
3927 the branch delay slots.
3928 A short loop can be terminated too early. */
3929 if (mips_opts.arch == CPU_R5900
3930 /* Check if instruction has a parameter, ignore "j $31". */
3931 && (address_expr != NULL)
3932 /* Parameter must be 16 bit. */
3933 && (*reloc_type == BFD_RELOC_16_PCREL_S2)
3934 /* Branch to same segment. */
3935 && (S_GET_SEGMENT(address_expr->X_add_symbol) == now_seg)
3936 /* Branch to same code fragment. */
3937 && (symbol_get_frag(address_expr->X_add_symbol) == frag_now)
3938 /* Can only calculate branch offset if value is known. */
3939 && symbol_constant_p(address_expr->X_add_symbol)
3940 /* Check if branch is really conditional. */
3941 && !((ip->insn_opcode & 0xffff0000) == 0x10000000 /* beq $0,$0 */
3942 || (ip->insn_opcode & 0xffff0000) == 0x04010000 /* bgez $0 */
3943 || (ip->insn_opcode & 0xffff0000) == 0x04110000)) /* bgezal $0 */
3946 /* Check if loop is shorter than 6 instructions including
3947 branch and delay slot. */
3948 distance = frag_now_fix() - S_GET_VALUE(address_expr->X_add_symbol);
3955 /* When the loop includes branches or jumps,
3956 it is not a short loop. */
3957 for (i = 0; i < (distance / 4); i++)
3959 if ((history[i].cleared_p)
3960 || delayed_branch_p(&history[i]))
3968 /* Insert nop after branch to fix short loop. */
3977 /* Decide how we should add IP to the instruction stream.
3978 ADDRESS_EXPR is an operand of the instruction to be used with
3981 static enum append_method
3982 get_append_method (struct mips_cl_insn *ip, expressionS *address_expr,
3983 bfd_reloc_code_real_type *reloc_type)
3985 unsigned long pinfo;
3987 /* The relaxed version of a macro sequence must be inherently
3989 if (mips_relax.sequence == 2)
3992 /* We must not dabble with instructions in a ".set norerorder" block. */
3993 if (mips_opts.noreorder)
3996 /* Otherwise, it's our responsibility to fill branch delay slots. */
3997 if (delayed_branch_p (ip))
3999 if (!branch_likely_p (ip)
4000 && can_swap_branch_p (ip, address_expr, reloc_type))
4003 pinfo = ip->insn_mo->pinfo;
4004 if (mips_opts.mips16
4005 && ISA_SUPPORTS_MIPS16E
4006 && (pinfo & (MIPS16_INSN_READ_X | MIPS16_INSN_READ_31)))
4007 return APPEND_ADD_COMPACT;
4009 return APPEND_ADD_WITH_NOP;
4015 /* IP is a MIPS16 instruction whose opcode we have just changed.
4016 Point IP->insn_mo to the new opcode's definition. */
4019 find_altered_mips16_opcode (struct mips_cl_insn *ip)
4021 const struct mips_opcode *mo, *end;
4023 end = &mips16_opcodes[bfd_mips16_num_opcodes];
4024 for (mo = ip->insn_mo; mo < end; mo++)
4025 if ((ip->insn_opcode & mo->mask) == mo->match)
4033 /* For microMIPS macros, we need to generate a local number label
4034 as the target of branches. */
4035 #define MICROMIPS_LABEL_CHAR '\037'
4036 static unsigned long micromips_target_label;
4037 static char micromips_target_name[32];
4040 micromips_label_name (void)
4042 char *p = micromips_target_name;
4043 char symbol_name_temporary[24];
4051 l = micromips_target_label;
4052 #ifdef LOCAL_LABEL_PREFIX
4053 *p++ = LOCAL_LABEL_PREFIX;
4056 *p++ = MICROMIPS_LABEL_CHAR;
4059 symbol_name_temporary[i++] = l % 10 + '0';
4064 *p++ = symbol_name_temporary[--i];
4067 return micromips_target_name;
4071 micromips_label_expr (expressionS *label_expr)
4073 label_expr->X_op = O_symbol;
4074 label_expr->X_add_symbol = symbol_find_or_make (micromips_label_name ());
4075 label_expr->X_add_number = 0;
4079 micromips_label_inc (void)
4081 micromips_target_label++;
4082 *micromips_target_name = '\0';
4086 micromips_add_label (void)
4090 s = colon (micromips_label_name ());
4091 micromips_label_inc ();
4092 #if defined(OBJ_ELF) || defined(OBJ_MAYBE_ELF)
4094 S_SET_OTHER (s, ELF_ST_SET_MICROMIPS (S_GET_OTHER (s)));
4100 /* If assembling microMIPS code, then return the microMIPS reloc
4101 corresponding to the requested one if any. Otherwise return
4102 the reloc unchanged. */
4104 static bfd_reloc_code_real_type
4105 micromips_map_reloc (bfd_reloc_code_real_type reloc)
4107 static const bfd_reloc_code_real_type relocs[][2] =
4109 /* Keep sorted incrementally by the left-hand key. */
4110 { BFD_RELOC_16_PCREL_S2, BFD_RELOC_MICROMIPS_16_PCREL_S1 },
4111 { BFD_RELOC_GPREL16, BFD_RELOC_MICROMIPS_GPREL16 },
4112 { BFD_RELOC_MIPS_JMP, BFD_RELOC_MICROMIPS_JMP },
4113 { BFD_RELOC_HI16, BFD_RELOC_MICROMIPS_HI16 },
4114 { BFD_RELOC_HI16_S, BFD_RELOC_MICROMIPS_HI16_S },
4115 { BFD_RELOC_LO16, BFD_RELOC_MICROMIPS_LO16 },
4116 { BFD_RELOC_MIPS_LITERAL, BFD_RELOC_MICROMIPS_LITERAL },
4117 { BFD_RELOC_MIPS_GOT16, BFD_RELOC_MICROMIPS_GOT16 },
4118 { BFD_RELOC_MIPS_CALL16, BFD_RELOC_MICROMIPS_CALL16 },
4119 { BFD_RELOC_MIPS_GOT_HI16, BFD_RELOC_MICROMIPS_GOT_HI16 },
4120 { BFD_RELOC_MIPS_GOT_LO16, BFD_RELOC_MICROMIPS_GOT_LO16 },
4121 { BFD_RELOC_MIPS_CALL_HI16, BFD_RELOC_MICROMIPS_CALL_HI16 },
4122 { BFD_RELOC_MIPS_CALL_LO16, BFD_RELOC_MICROMIPS_CALL_LO16 },
4123 { BFD_RELOC_MIPS_SUB, BFD_RELOC_MICROMIPS_SUB },
4124 { BFD_RELOC_MIPS_GOT_PAGE, BFD_RELOC_MICROMIPS_GOT_PAGE },
4125 { BFD_RELOC_MIPS_GOT_OFST, BFD_RELOC_MICROMIPS_GOT_OFST },
4126 { BFD_RELOC_MIPS_GOT_DISP, BFD_RELOC_MICROMIPS_GOT_DISP },
4127 { BFD_RELOC_MIPS_HIGHEST, BFD_RELOC_MICROMIPS_HIGHEST },
4128 { BFD_RELOC_MIPS_HIGHER, BFD_RELOC_MICROMIPS_HIGHER },
4129 { BFD_RELOC_MIPS_SCN_DISP, BFD_RELOC_MICROMIPS_SCN_DISP },
4130 { BFD_RELOC_MIPS_TLS_GD, BFD_RELOC_MICROMIPS_TLS_GD },
4131 { BFD_RELOC_MIPS_TLS_LDM, BFD_RELOC_MICROMIPS_TLS_LDM },
4132 { BFD_RELOC_MIPS_TLS_DTPREL_HI16, BFD_RELOC_MICROMIPS_TLS_DTPREL_HI16 },
4133 { BFD_RELOC_MIPS_TLS_DTPREL_LO16, BFD_RELOC_MICROMIPS_TLS_DTPREL_LO16 },
4134 { BFD_RELOC_MIPS_TLS_GOTTPREL, BFD_RELOC_MICROMIPS_TLS_GOTTPREL },
4135 { BFD_RELOC_MIPS_TLS_TPREL_HI16, BFD_RELOC_MICROMIPS_TLS_TPREL_HI16 },
4136 { BFD_RELOC_MIPS_TLS_TPREL_LO16, BFD_RELOC_MICROMIPS_TLS_TPREL_LO16 }
4138 bfd_reloc_code_real_type r;
4141 if (!mips_opts.micromips)
4143 for (i = 0; i < ARRAY_SIZE (relocs); i++)
4149 return relocs[i][1];
4154 /* Try to resolve relocation RELOC against constant OPERAND at assembly time.
4155 Return true on success, storing the resolved value in RESULT. */
4158 calculate_reloc (bfd_reloc_code_real_type reloc, offsetT operand,
4163 case BFD_RELOC_MIPS_HIGHEST:
4164 case BFD_RELOC_MICROMIPS_HIGHEST:
4165 *result = ((operand + 0x800080008000ull) >> 48) & 0xffff;
4168 case BFD_RELOC_MIPS_HIGHER:
4169 case BFD_RELOC_MICROMIPS_HIGHER:
4170 *result = ((operand + 0x80008000ull) >> 32) & 0xffff;
4173 case BFD_RELOC_HI16_S:
4174 case BFD_RELOC_MICROMIPS_HI16_S:
4175 case BFD_RELOC_MIPS16_HI16_S:
4176 *result = ((operand + 0x8000) >> 16) & 0xffff;
4179 case BFD_RELOC_HI16:
4180 case BFD_RELOC_MICROMIPS_HI16:
4181 case BFD_RELOC_MIPS16_HI16:
4182 *result = (operand >> 16) & 0xffff;
4185 case BFD_RELOC_LO16:
4186 case BFD_RELOC_MICROMIPS_LO16:
4187 case BFD_RELOC_MIPS16_LO16:
4188 *result = operand & 0xffff;
4191 case BFD_RELOC_UNUSED:
4200 /* Output an instruction. IP is the instruction information.
4201 ADDRESS_EXPR is an operand of the instruction to be used with
4202 RELOC_TYPE. EXPANSIONP is true if the instruction is part of
4203 a macro expansion. */
4206 append_insn (struct mips_cl_insn *ip, expressionS *address_expr,
4207 bfd_reloc_code_real_type *reloc_type, bfd_boolean expansionp)
4209 unsigned long prev_pinfo2, pinfo;
4210 bfd_boolean relaxed_branch = FALSE;
4211 enum append_method method;
4212 bfd_boolean relax32;
4215 if (mips_fix_loongson2f && !HAVE_CODE_COMPRESSION)
4216 fix_loongson2f (ip);
4218 file_ase_mips16 |= mips_opts.mips16;
4219 file_ase_micromips |= mips_opts.micromips;
4221 prev_pinfo2 = history[0].insn_mo->pinfo2;
4222 pinfo = ip->insn_mo->pinfo;
4224 if (mips_opts.micromips
4226 && (((prev_pinfo2 & INSN2_BRANCH_DELAY_16BIT) != 0
4227 && micromips_insn_length (ip->insn_mo) != 2)
4228 || ((prev_pinfo2 & INSN2_BRANCH_DELAY_32BIT) != 0
4229 && micromips_insn_length (ip->insn_mo) != 4)))
4230 as_warn (_("Wrong size instruction in a %u-bit branch delay slot"),
4231 (prev_pinfo2 & INSN2_BRANCH_DELAY_16BIT) != 0 ? 16 : 32);
4233 if (address_expr == NULL)
4235 else if (reloc_type[0] <= BFD_RELOC_UNUSED
4236 && reloc_type[1] == BFD_RELOC_UNUSED
4237 && reloc_type[2] == BFD_RELOC_UNUSED
4238 && address_expr->X_op == O_constant)
4240 switch (*reloc_type)
4242 case BFD_RELOC_MIPS_JMP:
4246 shift = mips_opts.micromips ? 1 : 2;
4247 if ((address_expr->X_add_number & ((1 << shift) - 1)) != 0)
4248 as_bad (_("jump to misaligned address (0x%lx)"),
4249 (unsigned long) address_expr->X_add_number);
4250 ip->insn_opcode |= ((address_expr->X_add_number >> shift)
4256 case BFD_RELOC_MIPS16_JMP:
4257 if ((address_expr->X_add_number & 3) != 0)
4258 as_bad (_("jump to misaligned address (0x%lx)"),
4259 (unsigned long) address_expr->X_add_number);
4261 (((address_expr->X_add_number & 0x7c0000) << 3)
4262 | ((address_expr->X_add_number & 0xf800000) >> 7)
4263 | ((address_expr->X_add_number & 0x3fffc) >> 2));
4267 case BFD_RELOC_16_PCREL_S2:
4271 shift = mips_opts.micromips ? 1 : 2;
4272 if ((address_expr->X_add_number & ((1 << shift) - 1)) != 0)
4273 as_bad (_("branch to misaligned address (0x%lx)"),
4274 (unsigned long) address_expr->X_add_number);
4275 if (!mips_relax_branch)
4277 if ((address_expr->X_add_number + (1 << (shift + 15)))
4278 & ~((1 << (shift + 16)) - 1))
4279 as_bad (_("branch address range overflow (0x%lx)"),
4280 (unsigned long) address_expr->X_add_number);
4281 ip->insn_opcode |= ((address_expr->X_add_number >> shift)
4291 if (calculate_reloc (*reloc_type, address_expr->X_add_number,
4294 ip->insn_opcode |= value & 0xffff;
4302 if (mips_relax.sequence != 2 && !mips_opts.noreorder)
4304 /* There are a lot of optimizations we could do that we don't.
4305 In particular, we do not, in general, reorder instructions.
4306 If you use gcc with optimization, it will reorder
4307 instructions and generally do much more optimization then we
4308 do here; repeating all that work in the assembler would only
4309 benefit hand written assembly code, and does not seem worth
4311 int nops = (mips_optimize == 0
4312 ? nops_for_insn (0, history, NULL)
4313 : nops_for_insn_or_target (0, history, ip));
4317 unsigned long old_frag_offset;
4320 old_frag = frag_now;
4321 old_frag_offset = frag_now_fix ();
4323 for (i = 0; i < nops; i++)
4324 add_fixed_insn (NOP_INSN);
4325 insert_into_history (0, nops, NOP_INSN);
4329 listing_prev_line ();
4330 /* We may be at the start of a variant frag. In case we
4331 are, make sure there is enough space for the frag
4332 after the frags created by listing_prev_line. The
4333 argument to frag_grow here must be at least as large
4334 as the argument to all other calls to frag_grow in
4335 this file. We don't have to worry about being in the
4336 middle of a variant frag, because the variants insert
4337 all needed nop instructions themselves. */
4341 mips_move_text_labels ();
4343 #ifndef NO_ECOFF_DEBUGGING
4344 if (ECOFF_DEBUGGING)
4345 ecoff_fix_loc (old_frag, old_frag_offset);
4349 else if (mips_relax.sequence != 2 && prev_nop_frag != NULL)
4353 /* Work out how many nops in prev_nop_frag are needed by IP,
4354 ignoring hazards generated by the first prev_nop_frag_since
4356 nops = nops_for_insn_or_target (prev_nop_frag_since, history, ip);
4357 gas_assert (nops <= prev_nop_frag_holds);
4359 /* Enforce NOPS as a minimum. */
4360 if (nops > prev_nop_frag_required)
4361 prev_nop_frag_required = nops;
4363 if (prev_nop_frag_holds == prev_nop_frag_required)
4365 /* Settle for the current number of nops. Update the history
4366 accordingly (for the benefit of any future .set reorder code). */
4367 prev_nop_frag = NULL;
4368 insert_into_history (prev_nop_frag_since,
4369 prev_nop_frag_holds, NOP_INSN);
4373 /* Allow this instruction to replace one of the nops that was
4374 tentatively added to prev_nop_frag. */
4375 prev_nop_frag->fr_fix -= NOP_INSN_SIZE;
4376 prev_nop_frag_holds--;
4377 prev_nop_frag_since++;
4381 method = get_append_method (ip, address_expr, reloc_type);
4382 branch_disp = method == APPEND_SWAP ? insn_length (history) : 0;
4385 dwarf2_emit_insn (0);
4386 /* We want MIPS16 and microMIPS debug info to use ISA-encoded addresses,
4387 so "move" the instruction address accordingly.
4389 Also, it doesn't seem appropriate for the assembler to reorder .loc
4390 entries. If this instruction is a branch that we are going to swap
4391 with the previous instruction, the two instructions should be
4392 treated as a unit, and the debug information for both instructions
4393 should refer to the start of the branch sequence. Using the
4394 current position is certainly wrong when swapping a 32-bit branch
4395 and a 16-bit delay slot, since the current position would then be
4396 in the middle of a branch. */
4397 dwarf2_move_insn ((HAVE_CODE_COMPRESSION ? 1 : 0) - branch_disp);
4400 relax32 = (mips_relax_branch
4401 /* Don't try branch relaxation within .set nomacro, or within
4402 .set noat if we use $at for PIC computations. If it turns
4403 out that the branch was out-of-range, we'll get an error. */
4404 && !mips_opts.warn_about_macros
4405 && (mips_opts.at || mips_pic == NO_PIC)
4406 /* Don't relax BPOSGE32/64 or BC1ANY2T/F and BC1ANY4T/F
4407 as they have no complementing branches. */
4408 && !(ip->insn_mo->ase & (ASE_MIPS3D | ASE_DSP64 | ASE_DSP)));
4410 if (!HAVE_CODE_COMPRESSION
4413 && *reloc_type == BFD_RELOC_16_PCREL_S2
4414 && delayed_branch_p (ip))
4416 relaxed_branch = TRUE;
4417 add_relaxed_insn (ip, (relaxed_branch_length
4419 uncond_branch_p (ip) ? -1
4420 : branch_likely_p (ip) ? 1
4424 uncond_branch_p (ip),
4425 branch_likely_p (ip),
4426 pinfo & INSN_WRITE_GPR_31,
4428 address_expr->X_add_symbol,
4429 address_expr->X_add_number);
4430 *reloc_type = BFD_RELOC_UNUSED;
4432 else if (mips_opts.micromips
4434 && ((relax32 && *reloc_type == BFD_RELOC_16_PCREL_S2)
4435 || *reloc_type > BFD_RELOC_UNUSED)
4436 && (delayed_branch_p (ip) || compact_branch_p (ip))
4437 /* Don't try branch relaxation when users specify
4438 16-bit/32-bit instructions. */
4439 && !forced_insn_length)
4441 bfd_boolean relax16 = *reloc_type > BFD_RELOC_UNUSED;
4442 int type = relax16 ? *reloc_type - BFD_RELOC_UNUSED : 0;
4443 int uncond = uncond_branch_p (ip) ? -1 : 0;
4444 int compact = compact_branch_p (ip);
4445 int al = pinfo & INSN_WRITE_GPR_31;
4448 gas_assert (address_expr != NULL);
4449 gas_assert (!mips_relax.sequence);
4451 relaxed_branch = TRUE;
4452 length32 = relaxed_micromips_32bit_branch_length (NULL, NULL, uncond);
4453 add_relaxed_insn (ip, relax32 ? length32 : 4, relax16 ? 2 : 4,
4454 RELAX_MICROMIPS_ENCODE (type, AT, uncond, compact, al,
4456 address_expr->X_add_symbol,
4457 address_expr->X_add_number);
4458 *reloc_type = BFD_RELOC_UNUSED;
4460 else if (mips_opts.mips16 && *reloc_type > BFD_RELOC_UNUSED)
4462 /* We need to set up a variant frag. */
4463 gas_assert (address_expr != NULL);
4464 add_relaxed_insn (ip, 4, 0,
4466 (*reloc_type - BFD_RELOC_UNUSED,
4467 forced_insn_length == 2, forced_insn_length == 4,
4468 delayed_branch_p (&history[0]),
4469 history[0].mips16_absolute_jump_p),
4470 make_expr_symbol (address_expr), 0);
4472 else if (mips_opts.mips16 && insn_length (ip) == 2)
4474 if (!delayed_branch_p (ip))
4475 /* Make sure there is enough room to swap this instruction with
4476 a following jump instruction. */
4478 add_fixed_insn (ip);
4482 if (mips_opts.mips16
4483 && mips_opts.noreorder
4484 && delayed_branch_p (&history[0]))
4485 as_warn (_("extended instruction in delay slot"));
4487 if (mips_relax.sequence)
4489 /* If we've reached the end of this frag, turn it into a variant
4490 frag and record the information for the instructions we've
4492 if (frag_room () < 4)
4493 relax_close_frag ();
4494 mips_relax.sizes[mips_relax.sequence - 1] += insn_length (ip);
4497 if (mips_relax.sequence != 2)
4499 if (mips_macro_warning.first_insn_sizes[0] == 0)
4500 mips_macro_warning.first_insn_sizes[0] = insn_length (ip);
4501 mips_macro_warning.sizes[0] += insn_length (ip);
4502 mips_macro_warning.insns[0]++;
4504 if (mips_relax.sequence != 1)
4506 if (mips_macro_warning.first_insn_sizes[1] == 0)
4507 mips_macro_warning.first_insn_sizes[1] = insn_length (ip);
4508 mips_macro_warning.sizes[1] += insn_length (ip);
4509 mips_macro_warning.insns[1]++;
4512 if (mips_opts.mips16)
4515 ip->mips16_absolute_jump_p = (*reloc_type == BFD_RELOC_MIPS16_JMP);
4517 add_fixed_insn (ip);
4520 if (!ip->complete_p && *reloc_type < BFD_RELOC_UNUSED)
4522 bfd_reloc_code_real_type final_type[3];
4523 reloc_howto_type *howto0;
4524 reloc_howto_type *howto;
4527 /* Perform any necessary conversion to microMIPS relocations
4528 and find out how many relocations there actually are. */
4529 for (i = 0; i < 3 && reloc_type[i] != BFD_RELOC_UNUSED; i++)
4530 final_type[i] = micromips_map_reloc (reloc_type[i]);
4532 /* In a compound relocation, it is the final (outermost)
4533 operator that determines the relocated field. */
4534 howto = howto0 = bfd_reloc_type_lookup (stdoutput, final_type[i - 1]);
4538 /* To reproduce this failure try assembling gas/testsuites/
4539 gas/mips/mips16-intermix.s with a mips-ecoff targeted
4541 as_bad (_("Unsupported MIPS relocation number %d"),
4543 howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_16);
4547 howto0 = bfd_reloc_type_lookup (stdoutput, final_type[0]);
4548 ip->fixp[0] = fix_new_exp (ip->frag, ip->where,
4549 bfd_get_reloc_size (howto),
4551 howto0 && howto0->pc_relative,
4554 /* Tag symbols that have a R_MIPS16_26 relocation against them. */
4555 if (final_type[0] == BFD_RELOC_MIPS16_JMP && ip->fixp[0]->fx_addsy)
4556 *symbol_get_tc (ip->fixp[0]->fx_addsy) = 1;
4558 /* These relocations can have an addend that won't fit in
4559 4 octets for 64bit assembly. */
4561 && ! howto->partial_inplace
4562 && (reloc_type[0] == BFD_RELOC_16
4563 || reloc_type[0] == BFD_RELOC_32
4564 || reloc_type[0] == BFD_RELOC_MIPS_JMP
4565 || reloc_type[0] == BFD_RELOC_GPREL16
4566 || reloc_type[0] == BFD_RELOC_MIPS_LITERAL
4567 || reloc_type[0] == BFD_RELOC_GPREL32
4568 || reloc_type[0] == BFD_RELOC_64
4569 || reloc_type[0] == BFD_RELOC_CTOR
4570 || reloc_type[0] == BFD_RELOC_MIPS_SUB
4571 || reloc_type[0] == BFD_RELOC_MIPS_HIGHEST
4572 || reloc_type[0] == BFD_RELOC_MIPS_HIGHER
4573 || reloc_type[0] == BFD_RELOC_MIPS_SCN_DISP
4574 || reloc_type[0] == BFD_RELOC_MIPS_REL16
4575 || reloc_type[0] == BFD_RELOC_MIPS_RELGOT
4576 || reloc_type[0] == BFD_RELOC_MIPS16_GPREL
4577 || hi16_reloc_p (reloc_type[0])
4578 || lo16_reloc_p (reloc_type[0])))
4579 ip->fixp[0]->fx_no_overflow = 1;
4581 /* These relocations can have an addend that won't fit in 2 octets. */
4582 if (reloc_type[0] == BFD_RELOC_MICROMIPS_7_PCREL_S1
4583 || reloc_type[0] == BFD_RELOC_MICROMIPS_10_PCREL_S1)
4584 ip->fixp[0]->fx_no_overflow = 1;
4586 if (mips_relax.sequence)
4588 if (mips_relax.first_fixup == 0)
4589 mips_relax.first_fixup = ip->fixp[0];
4591 else if (reloc_needs_lo_p (*reloc_type))
4593 struct mips_hi_fixup *hi_fixup;
4595 /* Reuse the last entry if it already has a matching %lo. */
4596 hi_fixup = mips_hi_fixup_list;
4598 || !fixup_has_matching_lo_p (hi_fixup->fixp))
4600 hi_fixup = ((struct mips_hi_fixup *)
4601 xmalloc (sizeof (struct mips_hi_fixup)));
4602 hi_fixup->next = mips_hi_fixup_list;
4603 mips_hi_fixup_list = hi_fixup;
4605 hi_fixup->fixp = ip->fixp[0];
4606 hi_fixup->seg = now_seg;
4609 /* Add fixups for the second and third relocations, if given.
4610 Note that the ABI allows the second relocation to be
4611 against RSS_UNDEF, RSS_GP, RSS_GP0 or RSS_LOC. At the
4612 moment we only use RSS_UNDEF, but we could add support
4613 for the others if it ever becomes necessary. */
4614 for (i = 1; i < 3; i++)
4615 if (reloc_type[i] != BFD_RELOC_UNUSED)
4617 ip->fixp[i] = fix_new (ip->frag, ip->where,
4618 ip->fixp[0]->fx_size, NULL, 0,
4619 FALSE, final_type[i]);
4621 /* Use fx_tcbit to mark compound relocs. */
4622 ip->fixp[0]->fx_tcbit = 1;
4623 ip->fixp[i]->fx_tcbit = 1;
4628 /* Update the register mask information. */
4629 mips_gprmask |= gpr_read_mask (ip) | gpr_write_mask (ip);
4630 mips_cprmask[1] |= fpr_read_mask (ip) | fpr_write_mask (ip);
4635 insert_into_history (0, 1, ip);
4638 case APPEND_ADD_WITH_NOP:
4640 struct mips_cl_insn *nop;
4642 insert_into_history (0, 1, ip);
4643 nop = get_delay_slot_nop (ip);
4644 add_fixed_insn (nop);
4645 insert_into_history (0, 1, nop);
4646 if (mips_relax.sequence)
4647 mips_relax.sizes[mips_relax.sequence - 1] += insn_length (nop);
4651 case APPEND_ADD_COMPACT:
4652 /* Convert MIPS16 jr/jalr into a "compact" jump. */
4653 gas_assert (mips_opts.mips16);
4654 ip->insn_opcode |= 0x0080;
4655 find_altered_mips16_opcode (ip);
4657 insert_into_history (0, 1, ip);
4662 struct mips_cl_insn delay = history[0];
4663 if (mips_opts.mips16)
4665 know (delay.frag == ip->frag);
4666 move_insn (ip, delay.frag, delay.where);
4667 move_insn (&delay, ip->frag, ip->where + insn_length (ip));
4669 else if (relaxed_branch || delay.frag != ip->frag)
4671 /* Add the delay slot instruction to the end of the
4672 current frag and shrink the fixed part of the
4673 original frag. If the branch occupies the tail of
4674 the latter, move it backwards to cover the gap. */
4675 delay.frag->fr_fix -= branch_disp;
4676 if (delay.frag == ip->frag)
4677 move_insn (ip, ip->frag, ip->where - branch_disp);
4678 add_fixed_insn (&delay);
4682 move_insn (&delay, ip->frag,
4683 ip->where - branch_disp + insn_length (ip));
4684 move_insn (ip, history[0].frag, history[0].where);
4688 insert_into_history (0, 1, &delay);
4693 /* If we have just completed an unconditional branch, clear the history. */
4694 if ((delayed_branch_p (&history[1]) && uncond_branch_p (&history[1]))
4695 || (compact_branch_p (&history[0]) && uncond_branch_p (&history[0])))
4699 mips_no_prev_insn ();
4701 for (i = 0; i < ARRAY_SIZE (history); i++)
4702 history[i].cleared_p = 1;
4705 /* We need to emit a label at the end of branch-likely macros. */
4706 if (emit_branch_likely_macro)
4708 emit_branch_likely_macro = FALSE;
4709 micromips_add_label ();
4712 /* We just output an insn, so the next one doesn't have a label. */
4713 mips_clear_insn_labels ();
4716 /* Forget that there was any previous instruction or label.
4717 When BRANCH is true, the branch history is also flushed. */
4720 mips_no_prev_insn (void)
4722 prev_nop_frag = NULL;
4723 insert_into_history (0, ARRAY_SIZE (history), NOP_INSN);
4724 mips_clear_insn_labels ();
4727 /* This function must be called before we emit something other than
4728 instructions. It is like mips_no_prev_insn except that it inserts
4729 any NOPS that might be needed by previous instructions. */
4732 mips_emit_delays (void)
4734 if (! mips_opts.noreorder)
4736 int nops = nops_for_insn (0, history, NULL);
4740 add_fixed_insn (NOP_INSN);
4741 mips_move_text_labels ();
4744 mips_no_prev_insn ();
4747 /* Start a (possibly nested) noreorder block. */
4750 start_noreorder (void)
4752 if (mips_opts.noreorder == 0)
4757 /* None of the instructions before the .set noreorder can be moved. */
4758 for (i = 0; i < ARRAY_SIZE (history); i++)
4759 history[i].fixed_p = 1;
4761 /* Insert any nops that might be needed between the .set noreorder
4762 block and the previous instructions. We will later remove any
4763 nops that turn out not to be needed. */
4764 nops = nops_for_insn (0, history, NULL);
4767 if (mips_optimize != 0)
4769 /* Record the frag which holds the nop instructions, so
4770 that we can remove them if we don't need them. */
4771 frag_grow (nops * NOP_INSN_SIZE);
4772 prev_nop_frag = frag_now;
4773 prev_nop_frag_holds = nops;
4774 prev_nop_frag_required = 0;
4775 prev_nop_frag_since = 0;
4778 for (; nops > 0; --nops)
4779 add_fixed_insn (NOP_INSN);
4781 /* Move on to a new frag, so that it is safe to simply
4782 decrease the size of prev_nop_frag. */
4783 frag_wane (frag_now);
4785 mips_move_text_labels ();
4787 mips_mark_labels ();
4788 mips_clear_insn_labels ();
4790 mips_opts.noreorder++;
4791 mips_any_noreorder = 1;
4794 /* End a nested noreorder block. */
4797 end_noreorder (void)
4799 mips_opts.noreorder--;
4800 if (mips_opts.noreorder == 0 && prev_nop_frag != NULL)
4802 /* Commit to inserting prev_nop_frag_required nops and go back to
4803 handling nop insertion the .set reorder way. */
4804 prev_nop_frag->fr_fix -= ((prev_nop_frag_holds - prev_nop_frag_required)
4806 insert_into_history (prev_nop_frag_since,
4807 prev_nop_frag_required, NOP_INSN);
4808 prev_nop_frag = NULL;
4812 /* Set up global variables for the start of a new macro. */
4817 memset (&mips_macro_warning.sizes, 0, sizeof (mips_macro_warning.sizes));
4818 memset (&mips_macro_warning.first_insn_sizes, 0,
4819 sizeof (mips_macro_warning.first_insn_sizes));
4820 memset (&mips_macro_warning.insns, 0, sizeof (mips_macro_warning.insns));
4821 mips_macro_warning.delay_slot_p = (mips_opts.noreorder
4822 && delayed_branch_p (&history[0]));
4823 switch (history[0].insn_mo->pinfo2
4824 & (INSN2_BRANCH_DELAY_32BIT | INSN2_BRANCH_DELAY_16BIT))
4826 case INSN2_BRANCH_DELAY_32BIT:
4827 mips_macro_warning.delay_slot_length = 4;
4829 case INSN2_BRANCH_DELAY_16BIT:
4830 mips_macro_warning.delay_slot_length = 2;
4833 mips_macro_warning.delay_slot_length = 0;
4836 mips_macro_warning.first_frag = NULL;
4839 /* Given that a macro is longer than one instruction or of the wrong size,
4840 return the appropriate warning for it. Return null if no warning is
4841 needed. SUBTYPE is a bitmask of RELAX_DELAY_SLOT, RELAX_DELAY_SLOT_16BIT,
4842 RELAX_DELAY_SLOT_SIZE_FIRST, RELAX_DELAY_SLOT_SIZE_SECOND,
4843 and RELAX_NOMACRO. */
4846 macro_warning (relax_substateT subtype)
4848 if (subtype & RELAX_DELAY_SLOT)
4849 return _("Macro instruction expanded into multiple instructions"
4850 " in a branch delay slot");
4851 else if (subtype & RELAX_NOMACRO)
4852 return _("Macro instruction expanded into multiple instructions");
4853 else if (subtype & (RELAX_DELAY_SLOT_SIZE_FIRST
4854 | RELAX_DELAY_SLOT_SIZE_SECOND))
4855 return ((subtype & RELAX_DELAY_SLOT_16BIT)
4856 ? _("Macro instruction expanded into a wrong size instruction"
4857 " in a 16-bit branch delay slot")
4858 : _("Macro instruction expanded into a wrong size instruction"
4859 " in a 32-bit branch delay slot"));
4864 /* Finish up a macro. Emit warnings as appropriate. */
4869 /* Relaxation warning flags. */
4870 relax_substateT subtype = 0;
4872 /* Check delay slot size requirements. */
4873 if (mips_macro_warning.delay_slot_length == 2)
4874 subtype |= RELAX_DELAY_SLOT_16BIT;
4875 if (mips_macro_warning.delay_slot_length != 0)
4877 if (mips_macro_warning.delay_slot_length
4878 != mips_macro_warning.first_insn_sizes[0])
4879 subtype |= RELAX_DELAY_SLOT_SIZE_FIRST;
4880 if (mips_macro_warning.delay_slot_length
4881 != mips_macro_warning.first_insn_sizes[1])
4882 subtype |= RELAX_DELAY_SLOT_SIZE_SECOND;
4885 /* Check instruction count requirements. */
4886 if (mips_macro_warning.insns[0] > 1 || mips_macro_warning.insns[1] > 1)
4888 if (mips_macro_warning.insns[1] > mips_macro_warning.insns[0])
4889 subtype |= RELAX_SECOND_LONGER;
4890 if (mips_opts.warn_about_macros)
4891 subtype |= RELAX_NOMACRO;
4892 if (mips_macro_warning.delay_slot_p)
4893 subtype |= RELAX_DELAY_SLOT;
4896 /* If both alternatives fail to fill a delay slot correctly,
4897 emit the warning now. */
4898 if ((subtype & RELAX_DELAY_SLOT_SIZE_FIRST) != 0
4899 && (subtype & RELAX_DELAY_SLOT_SIZE_SECOND) != 0)
4904 s = subtype & (RELAX_DELAY_SLOT_16BIT
4905 | RELAX_DELAY_SLOT_SIZE_FIRST
4906 | RELAX_DELAY_SLOT_SIZE_SECOND);
4907 msg = macro_warning (s);
4909 as_warn ("%s", msg);
4913 /* If both implementations are longer than 1 instruction, then emit the
4915 if (mips_macro_warning.insns[0] > 1 && mips_macro_warning.insns[1] > 1)
4920 s = subtype & (RELAX_SECOND_LONGER | RELAX_NOMACRO | RELAX_DELAY_SLOT);
4921 msg = macro_warning (s);
4923 as_warn ("%s", msg);
4927 /* If any flags still set, then one implementation might need a warning
4928 and the other either will need one of a different kind or none at all.
4929 Pass any remaining flags over to relaxation. */
4930 if (mips_macro_warning.first_frag != NULL)
4931 mips_macro_warning.first_frag->fr_subtype |= subtype;
4934 /* Instruction operand formats used in macros that vary between
4935 standard MIPS and microMIPS code. */
4937 static const char * const brk_fmt[2] = { "c", "mF" };
4938 static const char * const cop12_fmt[2] = { "E,o(b)", "E,~(b)" };
4939 static const char * const jalr_fmt[2] = { "d,s", "t,s" };
4940 static const char * const lui_fmt[2] = { "t,u", "s,u" };
4941 static const char * const mem12_fmt[2] = { "t,o(b)", "t,~(b)" };
4942 static const char * const mfhl_fmt[2] = { "d", "mj" };
4943 static const char * const shft_fmt[2] = { "d,w,<", "t,r,<" };
4944 static const char * const trap_fmt[2] = { "s,t,q", "s,t,|" };
4946 #define BRK_FMT (brk_fmt[mips_opts.micromips])
4947 #define COP12_FMT (cop12_fmt[mips_opts.micromips])
4948 #define JALR_FMT (jalr_fmt[mips_opts.micromips])
4949 #define LUI_FMT (lui_fmt[mips_opts.micromips])
4950 #define MEM12_FMT (mem12_fmt[mips_opts.micromips])
4951 #define MFHL_FMT (mfhl_fmt[mips_opts.micromips])
4952 #define SHFT_FMT (shft_fmt[mips_opts.micromips])
4953 #define TRAP_FMT (trap_fmt[mips_opts.micromips])
4955 /* Read a macro's relocation codes from *ARGS and store them in *R.
4956 The first argument in *ARGS will be either the code for a single
4957 relocation or -1 followed by the three codes that make up a
4958 composite relocation. */
4961 macro_read_relocs (va_list *args, bfd_reloc_code_real_type *r)
4965 next = va_arg (*args, int);
4967 r[0] = (bfd_reloc_code_real_type) next;
4969 for (i = 0; i < 3; i++)
4970 r[i] = (bfd_reloc_code_real_type) va_arg (*args, int);
4973 /* Build an instruction created by a macro expansion. This is passed
4974 a pointer to the count of instructions created so far, an
4975 expression, the name of the instruction to build, an operand format
4976 string, and corresponding arguments. */
4979 macro_build (expressionS *ep, const char *name, const char *fmt, ...)
4981 const struct mips_opcode *mo = NULL;
4982 bfd_reloc_code_real_type r[3];
4983 const struct mips_opcode *amo;
4984 struct hash_control *hash;
4985 struct mips_cl_insn insn;
4988 va_start (args, fmt);
4990 if (mips_opts.mips16)
4992 mips16_macro_build (ep, name, fmt, &args);
4997 r[0] = BFD_RELOC_UNUSED;
4998 r[1] = BFD_RELOC_UNUSED;
4999 r[2] = BFD_RELOC_UNUSED;
5000 hash = mips_opts.micromips ? micromips_op_hash : op_hash;
5001 amo = (struct mips_opcode *) hash_find (hash, name);
5003 gas_assert (strcmp (name, amo->name) == 0);
5007 /* Search until we get a match for NAME. It is assumed here that
5008 macros will never generate MDMX, MIPS-3D, or MT instructions.
5009 We try to match an instruction that fulfils the branch delay
5010 slot instruction length requirement (if any) of the previous
5011 instruction. While doing this we record the first instruction
5012 seen that matches all the other conditions and use it anyway
5013 if the requirement cannot be met; we will issue an appropriate
5014 warning later on. */
5015 if (strcmp (fmt, amo->args) == 0
5016 && amo->pinfo != INSN_MACRO
5017 && is_opcode_valid (amo)
5018 && is_size_valid (amo))
5020 if (is_delay_slot_valid (amo))
5030 gas_assert (amo->name);
5032 while (strcmp (name, amo->name) == 0);
5035 create_insn (&insn, mo);
5053 INSERT_OPERAND (mips_opts.micromips,
5054 EXTLSB, insn, va_arg (args, int));
5059 /* Note that in the macro case, these arguments are already
5060 in MSB form. (When handling the instruction in the
5061 non-macro case, these arguments are sizes from which
5062 MSB values must be calculated.) */
5063 INSERT_OPERAND (mips_opts.micromips,
5064 INSMSB, insn, va_arg (args, int));
5068 gas_assert (!mips_opts.micromips);
5069 INSERT_OPERAND (0, CODE10, insn, va_arg (args, int));
5075 /* Note that in the macro case, these arguments are already
5076 in MSBD form. (When handling the instruction in the
5077 non-macro case, these arguments are sizes from which
5078 MSBD values must be calculated.) */
5079 INSERT_OPERAND (mips_opts.micromips,
5080 EXTMSBD, insn, va_arg (args, int));
5084 gas_assert (!mips_opts.micromips);
5085 INSERT_OPERAND (0, SEQI, insn, va_arg (args, int));
5089 INSERT_OPERAND (mips_opts.micromips, EVAOFFSET, insn, va_arg (args, int));
5098 INSERT_OPERAND (mips_opts.micromips, BP, insn, va_arg (args, int));
5102 gas_assert (mips_opts.micromips);
5106 INSERT_OPERAND (mips_opts.micromips, RT, insn, va_arg (args, int));
5110 gas_assert (!mips_opts.micromips);
5111 INSERT_OPERAND (0, CODE, insn, va_arg (args, int));
5115 gas_assert (!mips_opts.micromips);
5117 INSERT_OPERAND (mips_opts.micromips, FT, insn, va_arg (args, int));
5121 if (mips_opts.micromips)
5122 INSERT_OPERAND (1, RS, insn, va_arg (args, int));
5124 INSERT_OPERAND (0, RD, insn, va_arg (args, int));
5128 gas_assert (!mips_opts.micromips);
5130 INSERT_OPERAND (mips_opts.micromips, RD, insn, va_arg (args, int));
5134 gas_assert (!mips_opts.micromips);
5136 int tmp = va_arg (args, int);
5138 INSERT_OPERAND (0, RT, insn, tmp);
5139 INSERT_OPERAND (0, RD, insn, tmp);
5145 gas_assert (!mips_opts.micromips);
5146 INSERT_OPERAND (0, FS, insn, va_arg (args, int));
5153 INSERT_OPERAND (mips_opts.micromips,
5154 SHAMT, insn, va_arg (args, int));
5158 gas_assert (!mips_opts.micromips);
5159 INSERT_OPERAND (0, FD, insn, va_arg (args, int));
5163 gas_assert (!mips_opts.micromips);
5164 INSERT_OPERAND (0, CODE20, insn, va_arg (args, int));
5168 gas_assert (!mips_opts.micromips);
5169 INSERT_OPERAND (0, CODE19, insn, va_arg (args, int));
5173 gas_assert (!mips_opts.micromips);
5174 INSERT_OPERAND (0, CODE2, insn, va_arg (args, int));
5181 INSERT_OPERAND (mips_opts.micromips, RS, insn, va_arg (args, int));
5186 macro_read_relocs (&args, r);
5187 gas_assert (*r == BFD_RELOC_GPREL16
5188 || *r == BFD_RELOC_MIPS_HIGHER
5189 || *r == BFD_RELOC_HI16_S
5190 || *r == BFD_RELOC_LO16
5191 || *r == BFD_RELOC_MIPS_GOT_OFST);
5195 macro_read_relocs (&args, r);
5199 macro_read_relocs (&args, r);
5200 gas_assert (ep != NULL
5201 && (ep->X_op == O_constant
5202 || (ep->X_op == O_symbol
5203 && (*r == BFD_RELOC_MIPS_HIGHEST
5204 || *r == BFD_RELOC_HI16_S
5205 || *r == BFD_RELOC_HI16
5206 || *r == BFD_RELOC_GPREL16
5207 || *r == BFD_RELOC_MIPS_GOT_HI16
5208 || *r == BFD_RELOC_MIPS_CALL_HI16))));
5212 gas_assert (ep != NULL);
5215 * This allows macro() to pass an immediate expression for
5216 * creating short branches without creating a symbol.
5218 * We don't allow branch relaxation for these branches, as
5219 * they should only appear in ".set nomacro" anyway.
5221 if (ep->X_op == O_constant)
5223 /* For microMIPS we always use relocations for branches.
5224 So we should not resolve immediate values. */
5225 gas_assert (!mips_opts.micromips);
5227 if ((ep->X_add_number & 3) != 0)
5228 as_bad (_("branch to misaligned address (0x%lx)"),
5229 (unsigned long) ep->X_add_number);
5230 if ((ep->X_add_number + 0x20000) & ~0x3ffff)
5231 as_bad (_("branch address range overflow (0x%lx)"),
5232 (unsigned long) ep->X_add_number);
5233 insn.insn_opcode |= (ep->X_add_number >> 2) & 0xffff;
5237 *r = BFD_RELOC_16_PCREL_S2;
5241 gas_assert (ep != NULL);
5242 *r = BFD_RELOC_MIPS_JMP;
5246 gas_assert (!mips_opts.micromips);
5247 INSERT_OPERAND (0, COPZ, insn, va_arg (args, unsigned long));
5251 INSERT_OPERAND (mips_opts.micromips,
5252 CACHE, insn, va_arg (args, unsigned long));
5256 gas_assert (mips_opts.micromips);
5257 INSERT_OPERAND (1, TRAP, insn, va_arg (args, int));
5261 gas_assert (mips_opts.micromips);
5262 INSERT_OPERAND (1, OFFSET10, insn, va_arg (args, int));
5266 INSERT_OPERAND (mips_opts.micromips,
5267 3BITPOS, insn, va_arg (args, unsigned int));
5271 INSERT_OPERAND (mips_opts.micromips,
5272 OFFSET12, insn, va_arg (args, unsigned long));
5276 gas_assert (mips_opts.micromips);
5277 INSERT_OPERAND (1, BCC, insn, va_arg (args, int));
5280 case 'm': /* Opcode extension character. */
5281 gas_assert (mips_opts.micromips);
5285 INSERT_OPERAND (1, MJ, insn, va_arg (args, int));
5289 INSERT_OPERAND (1, MP, insn, va_arg (args, int));
5293 INSERT_OPERAND (1, IMMF, insn, va_arg (args, int));
5307 gas_assert (*r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL);
5309 append_insn (&insn, ep, r, TRUE);
5313 mips16_macro_build (expressionS *ep, const char *name, const char *fmt,
5316 struct mips_opcode *mo;
5317 struct mips_cl_insn insn;
5318 bfd_reloc_code_real_type r[3]
5319 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
5321 mo = (struct mips_opcode *) hash_find (mips16_op_hash, name);
5323 gas_assert (strcmp (name, mo->name) == 0);
5325 while (strcmp (fmt, mo->args) != 0 || mo->pinfo == INSN_MACRO)
5328 gas_assert (mo->name);
5329 gas_assert (strcmp (name, mo->name) == 0);
5332 create_insn (&insn, mo);
5350 MIPS16_INSERT_OPERAND (RY, insn, va_arg (*args, int));
5355 MIPS16_INSERT_OPERAND (RX, insn, va_arg (*args, int));
5359 MIPS16_INSERT_OPERAND (RZ, insn, va_arg (*args, int));
5363 MIPS16_INSERT_OPERAND (MOVE32Z, insn, va_arg (*args, int));
5373 MIPS16_INSERT_OPERAND (REGR32, insn, va_arg (*args, int));
5380 regno = va_arg (*args, int);
5381 regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3);
5382 MIPS16_INSERT_OPERAND (REG32R, insn, regno);
5405 gas_assert (ep != NULL);
5407 if (ep->X_op != O_constant)
5408 *r = (int) BFD_RELOC_UNUSED + c;
5409 else if (calculate_reloc (*r, ep->X_add_number, &value))
5411 mips16_immed (NULL, 0, c, *r, value, 0, &insn.insn_opcode);
5413 *r = BFD_RELOC_UNUSED;
5419 MIPS16_INSERT_OPERAND (IMM6, insn, va_arg (*args, int));
5426 gas_assert (*r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL);
5428 append_insn (&insn, ep, r, TRUE);
5432 * Sign-extend 32-bit mode constants that have bit 31 set and all
5433 * higher bits unset.
5436 normalize_constant_expr (expressionS *ex)
5438 if (ex->X_op == O_constant
5439 && IS_ZEXT_32BIT_NUM (ex->X_add_number))
5440 ex->X_add_number = (((ex->X_add_number & 0xffffffff) ^ 0x80000000)
5445 * Sign-extend 32-bit mode address offsets that have bit 31 set and
5446 * all higher bits unset.
5449 normalize_address_expr (expressionS *ex)
5451 if (((ex->X_op == O_constant && HAVE_32BIT_ADDRESSES)
5452 || (ex->X_op == O_symbol && HAVE_32BIT_SYMBOLS))
5453 && IS_ZEXT_32BIT_NUM (ex->X_add_number))
5454 ex->X_add_number = (((ex->X_add_number & 0xffffffff) ^ 0x80000000)
5459 * Generate a "jalr" instruction with a relocation hint to the called
5460 * function. This occurs in NewABI PIC code.
5463 macro_build_jalr (expressionS *ep, int cprestore)
5465 static const bfd_reloc_code_real_type jalr_relocs[2]
5466 = { BFD_RELOC_MIPS_JALR, BFD_RELOC_MICROMIPS_JALR };
5467 bfd_reloc_code_real_type jalr_reloc = jalr_relocs[mips_opts.micromips];
5471 if (MIPS_JALR_HINT_P (ep))
5476 if (mips_opts.micromips)
5478 jalr = mips_opts.noreorder && !cprestore ? "jalr" : "jalrs";
5479 if (MIPS_JALR_HINT_P (ep)
5480 || (history[0].insn_mo->pinfo2 & INSN2_BRANCH_DELAY_32BIT))
5481 macro_build (NULL, jalr, "t,s", RA, PIC_CALL_REG);
5483 macro_build (NULL, jalr, "mj", PIC_CALL_REG);
5486 macro_build (NULL, "jalr", "d,s", RA, PIC_CALL_REG);
5487 if (MIPS_JALR_HINT_P (ep))
5488 fix_new_exp (frag_now, f - frag_now->fr_literal, 4, ep, FALSE, jalr_reloc);
5492 * Generate a "lui" instruction.
5495 macro_build_lui (expressionS *ep, int regnum)
5497 gas_assert (! mips_opts.mips16);
5499 if (ep->X_op != O_constant)
5501 gas_assert (ep->X_op == O_symbol);
5502 /* _gp_disp is a special case, used from s_cpload.
5503 __gnu_local_gp is used if mips_no_shared. */
5504 gas_assert (mips_pic == NO_PIC
5506 && strcmp (S_GET_NAME (ep->X_add_symbol), "_gp_disp") == 0)
5507 || (! mips_in_shared
5508 && strcmp (S_GET_NAME (ep->X_add_symbol),
5509 "__gnu_local_gp") == 0));
5512 macro_build (ep, "lui", LUI_FMT, regnum, BFD_RELOC_HI16_S);
5515 /* Generate a sequence of instructions to do a load or store from a constant
5516 offset off of a base register (breg) into/from a target register (treg),
5517 using AT if necessary. */
5519 macro_build_ldst_constoffset (expressionS *ep, const char *op,
5520 int treg, int breg, int dbl)
5522 gas_assert (ep->X_op == O_constant);
5524 /* Sign-extending 32-bit constants makes their handling easier. */
5526 normalize_constant_expr (ep);
5528 /* Right now, this routine can only handle signed 32-bit constants. */
5529 if (! IS_SEXT_32BIT_NUM(ep->X_add_number + 0x8000))
5530 as_warn (_("operand overflow"));
5532 if (IS_SEXT_16BIT_NUM(ep->X_add_number))
5534 /* Signed 16-bit offset will fit in the op. Easy! */
5535 macro_build (ep, op, "t,o(b)", treg, BFD_RELOC_LO16, breg);
5539 /* 32-bit offset, need multiple instructions and AT, like:
5540 lui $tempreg,const_hi (BFD_RELOC_HI16_S)
5541 addu $tempreg,$tempreg,$breg
5542 <op> $treg,const_lo($tempreg) (BFD_RELOC_LO16)
5543 to handle the complete offset. */
5544 macro_build_lui (ep, AT);
5545 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, AT, breg);
5546 macro_build (ep, op, "t,o(b)", treg, BFD_RELOC_LO16, AT);
5549 as_bad (_("Macro used $at after \".set noat\""));
5554 * Generates code to set the $at register to true (one)
5555 * if reg is less than the immediate expression.
5558 set_at (int reg, int unsignedp)
5560 if (imm_expr.X_op == O_constant
5561 && imm_expr.X_add_number >= -0x8000
5562 && imm_expr.X_add_number < 0x8000)
5563 macro_build (&imm_expr, unsignedp ? "sltiu" : "slti", "t,r,j",
5564 AT, reg, BFD_RELOC_LO16);
5567 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
5568 macro_build (NULL, unsignedp ? "sltu" : "slt", "d,v,t", AT, reg, AT);
5572 /* Warn if an expression is not a constant. */
5575 check_absolute_expr (struct mips_cl_insn *ip, expressionS *ex)
5577 if (ex->X_op == O_big)
5578 as_bad (_("unsupported large constant"));
5579 else if (ex->X_op != O_constant)
5580 as_bad (_("Instruction %s requires absolute expression"),
5583 if (HAVE_32BIT_GPRS)
5584 normalize_constant_expr (ex);
5587 /* Count the leading zeroes by performing a binary chop. This is a
5588 bulky bit of source, but performance is a LOT better for the
5589 majority of values than a simple loop to count the bits:
5590 for (lcnt = 0; (lcnt < 32); lcnt++)
5591 if ((v) & (1 << (31 - lcnt)))
5593 However it is not code size friendly, and the gain will drop a bit
5594 on certain cached systems.
5596 #define COUNT_TOP_ZEROES(v) \
5597 (((v) & ~0xffff) == 0 \
5598 ? ((v) & ~0xff) == 0 \
5599 ? ((v) & ~0xf) == 0 \
5600 ? ((v) & ~0x3) == 0 \
5601 ? ((v) & ~0x1) == 0 \
5606 : ((v) & ~0x7) == 0 \
5609 : ((v) & ~0x3f) == 0 \
5610 ? ((v) & ~0x1f) == 0 \
5613 : ((v) & ~0x7f) == 0 \
5616 : ((v) & ~0xfff) == 0 \
5617 ? ((v) & ~0x3ff) == 0 \
5618 ? ((v) & ~0x1ff) == 0 \
5621 : ((v) & ~0x7ff) == 0 \
5624 : ((v) & ~0x3fff) == 0 \
5625 ? ((v) & ~0x1fff) == 0 \
5628 : ((v) & ~0x7fff) == 0 \
5631 : ((v) & ~0xffffff) == 0 \
5632 ? ((v) & ~0xfffff) == 0 \
5633 ? ((v) & ~0x3ffff) == 0 \
5634 ? ((v) & ~0x1ffff) == 0 \
5637 : ((v) & ~0x7ffff) == 0 \
5640 : ((v) & ~0x3fffff) == 0 \
5641 ? ((v) & ~0x1fffff) == 0 \
5644 : ((v) & ~0x7fffff) == 0 \
5647 : ((v) & ~0xfffffff) == 0 \
5648 ? ((v) & ~0x3ffffff) == 0 \
5649 ? ((v) & ~0x1ffffff) == 0 \
5652 : ((v) & ~0x7ffffff) == 0 \
5655 : ((v) & ~0x3fffffff) == 0 \
5656 ? ((v) & ~0x1fffffff) == 0 \
5659 : ((v) & ~0x7fffffff) == 0 \
5664 * This routine generates the least number of instructions necessary to load
5665 * an absolute expression value into a register.
5668 load_register (int reg, expressionS *ep, int dbl)
5671 expressionS hi32, lo32;
5673 if (ep->X_op != O_big)
5675 gas_assert (ep->X_op == O_constant);
5677 /* Sign-extending 32-bit constants makes their handling easier. */
5679 normalize_constant_expr (ep);
5681 if (IS_SEXT_16BIT_NUM (ep->X_add_number))
5683 /* We can handle 16 bit signed values with an addiu to
5684 $zero. No need to ever use daddiu here, since $zero and
5685 the result are always correct in 32 bit mode. */
5686 macro_build (ep, "addiu", "t,r,j", reg, 0, BFD_RELOC_LO16);
5689 else if (ep->X_add_number >= 0 && ep->X_add_number < 0x10000)
5691 /* We can handle 16 bit unsigned values with an ori to
5693 macro_build (ep, "ori", "t,r,i", reg, 0, BFD_RELOC_LO16);
5696 else if ((IS_SEXT_32BIT_NUM (ep->X_add_number)))
5698 /* 32 bit values require an lui. */
5699 macro_build (ep, "lui", LUI_FMT, reg, BFD_RELOC_HI16);
5700 if ((ep->X_add_number & 0xffff) != 0)
5701 macro_build (ep, "ori", "t,r,i", reg, reg, BFD_RELOC_LO16);
5706 /* The value is larger than 32 bits. */
5708 if (!dbl || HAVE_32BIT_GPRS)
5712 sprintf_vma (value, ep->X_add_number);
5713 as_bad (_("Number (0x%s) larger than 32 bits"), value);
5714 macro_build (ep, "addiu", "t,r,j", reg, 0, BFD_RELOC_LO16);
5718 if (ep->X_op != O_big)
5721 hi32.X_add_number = (valueT) hi32.X_add_number >> 16;
5722 hi32.X_add_number = (valueT) hi32.X_add_number >> 16;
5723 hi32.X_add_number &= 0xffffffff;
5725 lo32.X_add_number &= 0xffffffff;
5729 gas_assert (ep->X_add_number > 2);
5730 if (ep->X_add_number == 3)
5731 generic_bignum[3] = 0;
5732 else if (ep->X_add_number > 4)
5733 as_bad (_("Number larger than 64 bits"));
5734 lo32.X_op = O_constant;
5735 lo32.X_add_number = generic_bignum[0] + (generic_bignum[1] << 16);
5736 hi32.X_op = O_constant;
5737 hi32.X_add_number = generic_bignum[2] + (generic_bignum[3] << 16);
5740 if (hi32.X_add_number == 0)
5745 unsigned long hi, lo;
5747 if (hi32.X_add_number == (offsetT) 0xffffffff)
5749 if ((lo32.X_add_number & 0xffff8000) == 0xffff8000)
5751 macro_build (&lo32, "addiu", "t,r,j", reg, 0, BFD_RELOC_LO16);
5754 if (lo32.X_add_number & 0x80000000)
5756 macro_build (&lo32, "lui", LUI_FMT, reg, BFD_RELOC_HI16);
5757 if (lo32.X_add_number & 0xffff)
5758 macro_build (&lo32, "ori", "t,r,i", reg, reg, BFD_RELOC_LO16);
5763 /* Check for 16bit shifted constant. We know that hi32 is
5764 non-zero, so start the mask on the first bit of the hi32
5769 unsigned long himask, lomask;
5773 himask = 0xffff >> (32 - shift);
5774 lomask = (0xffff << shift) & 0xffffffff;
5778 himask = 0xffff << (shift - 32);
5781 if ((hi32.X_add_number & ~(offsetT) himask) == 0
5782 && (lo32.X_add_number & ~(offsetT) lomask) == 0)
5786 tmp.X_op = O_constant;
5788 tmp.X_add_number = ((hi32.X_add_number << (32 - shift))
5789 | (lo32.X_add_number >> shift));
5791 tmp.X_add_number = hi32.X_add_number >> (shift - 32);
5792 macro_build (&tmp, "ori", "t,r,i", reg, 0, BFD_RELOC_LO16);
5793 macro_build (NULL, (shift >= 32) ? "dsll32" : "dsll", SHFT_FMT,
5794 reg, reg, (shift >= 32) ? shift - 32 : shift);
5799 while (shift <= (64 - 16));
5801 /* Find the bit number of the lowest one bit, and store the
5802 shifted value in hi/lo. */
5803 hi = (unsigned long) (hi32.X_add_number & 0xffffffff);
5804 lo = (unsigned long) (lo32.X_add_number & 0xffffffff);
5808 while ((lo & 1) == 0)
5813 lo |= (hi & (((unsigned long) 1 << bit) - 1)) << (32 - bit);
5819 while ((hi & 1) == 0)
5828 /* Optimize if the shifted value is a (power of 2) - 1. */
5829 if ((hi == 0 && ((lo + 1) & lo) == 0)
5830 || (lo == 0xffffffff && ((hi + 1) & hi) == 0))
5832 shift = COUNT_TOP_ZEROES ((unsigned int) hi32.X_add_number);
5837 /* This instruction will set the register to be all
5839 tmp.X_op = O_constant;
5840 tmp.X_add_number = (offsetT) -1;
5841 macro_build (&tmp, "addiu", "t,r,j", reg, 0, BFD_RELOC_LO16);
5845 macro_build (NULL, (bit >= 32) ? "dsll32" : "dsll", SHFT_FMT,
5846 reg, reg, (bit >= 32) ? bit - 32 : bit);
5848 macro_build (NULL, (shift >= 32) ? "dsrl32" : "dsrl", SHFT_FMT,
5849 reg, reg, (shift >= 32) ? shift - 32 : shift);
5854 /* Sign extend hi32 before calling load_register, because we can
5855 generally get better code when we load a sign extended value. */
5856 if ((hi32.X_add_number & 0x80000000) != 0)
5857 hi32.X_add_number |= ~(offsetT) 0xffffffff;
5858 load_register (reg, &hi32, 0);
5861 if ((lo32.X_add_number & 0xffff0000) == 0)
5865 macro_build (NULL, "dsll32", SHFT_FMT, reg, freg, 0);
5873 if ((freg == 0) && (lo32.X_add_number == (offsetT) 0xffffffff))
5875 macro_build (&lo32, "lui", LUI_FMT, reg, BFD_RELOC_HI16);
5876 macro_build (NULL, "dsrl32", SHFT_FMT, reg, reg, 0);
5882 macro_build (NULL, "dsll", SHFT_FMT, reg, freg, 16);
5886 mid16.X_add_number >>= 16;
5887 macro_build (&mid16, "ori", "t,r,i", reg, freg, BFD_RELOC_LO16);
5888 macro_build (NULL, "dsll", SHFT_FMT, reg, reg, 16);
5891 if ((lo32.X_add_number & 0xffff) != 0)
5892 macro_build (&lo32, "ori", "t,r,i", reg, freg, BFD_RELOC_LO16);
5896 load_delay_nop (void)
5898 if (!gpr_interlocks)
5899 macro_build (NULL, "nop", "");
5902 /* Load an address into a register. */
5905 load_address (int reg, expressionS *ep, int *used_at)
5907 if (ep->X_op != O_constant
5908 && ep->X_op != O_symbol)
5910 as_bad (_("expression too complex"));
5911 ep->X_op = O_constant;
5914 if (ep->X_op == O_constant)
5916 load_register (reg, ep, HAVE_64BIT_ADDRESSES);
5920 if (mips_pic == NO_PIC)
5922 /* If this is a reference to a GP relative symbol, we want
5923 addiu $reg,$gp,<sym> (BFD_RELOC_GPREL16)
5925 lui $reg,<sym> (BFD_RELOC_HI16_S)
5926 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
5927 If we have an addend, we always use the latter form.
5929 With 64bit address space and a usable $at we want
5930 lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5931 lui $at,<sym> (BFD_RELOC_HI16_S)
5932 daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER)
5933 daddiu $at,<sym> (BFD_RELOC_LO16)
5937 If $at is already in use, we use a path which is suboptimal
5938 on superscalar processors.
5939 lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5940 daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER)
5942 daddiu $reg,<sym> (BFD_RELOC_HI16_S)
5944 daddiu $reg,<sym> (BFD_RELOC_LO16)
5946 For GP relative symbols in 64bit address space we can use
5947 the same sequence as in 32bit address space. */
5948 if (HAVE_64BIT_SYMBOLS)
5950 if ((valueT) ep->X_add_number <= MAX_GPREL_OFFSET
5951 && !nopic_need_relax (ep->X_add_symbol, 1))
5953 relax_start (ep->X_add_symbol);
5954 macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", reg,
5955 mips_gp_register, BFD_RELOC_GPREL16);
5959 if (*used_at == 0 && mips_opts.at)
5961 macro_build (ep, "lui", LUI_FMT, reg, BFD_RELOC_MIPS_HIGHEST);
5962 macro_build (ep, "lui", LUI_FMT, AT, BFD_RELOC_HI16_S);
5963 macro_build (ep, "daddiu", "t,r,j", reg, reg,
5964 BFD_RELOC_MIPS_HIGHER);
5965 macro_build (ep, "daddiu", "t,r,j", AT, AT, BFD_RELOC_LO16);
5966 macro_build (NULL, "dsll32", SHFT_FMT, reg, reg, 0);
5967 macro_build (NULL, "daddu", "d,v,t", reg, reg, AT);
5972 macro_build (ep, "lui", LUI_FMT, reg, BFD_RELOC_MIPS_HIGHEST);
5973 macro_build (ep, "daddiu", "t,r,j", reg, reg,
5974 BFD_RELOC_MIPS_HIGHER);
5975 macro_build (NULL, "dsll", SHFT_FMT, reg, reg, 16);
5976 macro_build (ep, "daddiu", "t,r,j", reg, reg, BFD_RELOC_HI16_S);
5977 macro_build (NULL, "dsll", SHFT_FMT, reg, reg, 16);
5978 macro_build (ep, "daddiu", "t,r,j", reg, reg, BFD_RELOC_LO16);
5981 if (mips_relax.sequence)
5986 if ((valueT) ep->X_add_number <= MAX_GPREL_OFFSET
5987 && !nopic_need_relax (ep->X_add_symbol, 1))
5989 relax_start (ep->X_add_symbol);
5990 macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", reg,
5991 mips_gp_register, BFD_RELOC_GPREL16);
5994 macro_build_lui (ep, reg);
5995 macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j",
5996 reg, reg, BFD_RELOC_LO16);
5997 if (mips_relax.sequence)
6001 else if (!mips_big_got)
6005 /* If this is a reference to an external symbol, we want
6006 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6008 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6010 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
6011 If there is a constant, it must be added in after.
6013 If we have NewABI, we want
6014 lw $reg,<sym+cst>($gp) (BFD_RELOC_MIPS_GOT_DISP)
6015 unless we're referencing a global symbol with a non-zero
6016 offset, in which case cst must be added separately. */
6019 if (ep->X_add_number)
6021 ex.X_add_number = ep->X_add_number;
6022 ep->X_add_number = 0;
6023 relax_start (ep->X_add_symbol);
6024 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
6025 BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
6026 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
6027 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6028 ex.X_op = O_constant;
6029 macro_build (&ex, ADDRESS_ADDI_INSN, "t,r,j",
6030 reg, reg, BFD_RELOC_LO16);
6031 ep->X_add_number = ex.X_add_number;
6034 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
6035 BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
6036 if (mips_relax.sequence)
6041 ex.X_add_number = ep->X_add_number;
6042 ep->X_add_number = 0;
6043 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
6044 BFD_RELOC_MIPS_GOT16, mips_gp_register);
6046 relax_start (ep->X_add_symbol);
6048 macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", reg, reg,
6052 if (ex.X_add_number != 0)
6054 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
6055 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6056 ex.X_op = O_constant;
6057 macro_build (&ex, ADDRESS_ADDI_INSN, "t,r,j",
6058 reg, reg, BFD_RELOC_LO16);
6062 else if (mips_big_got)
6066 /* This is the large GOT case. If this is a reference to an
6067 external symbol, we want
6068 lui $reg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
6070 lw $reg,<sym>($reg) (BFD_RELOC_MIPS_GOT_LO16)
6072 Otherwise, for a reference to a local symbol in old ABI, we want
6073 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6075 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
6076 If there is a constant, it must be added in after.
6078 In the NewABI, for local symbols, with or without offsets, we want:
6079 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
6080 addiu $reg,$reg,<sym> (BFD_RELOC_MIPS_GOT_OFST)
6084 ex.X_add_number = ep->X_add_number;
6085 ep->X_add_number = 0;
6086 relax_start (ep->X_add_symbol);
6087 macro_build (ep, "lui", LUI_FMT, reg, BFD_RELOC_MIPS_GOT_HI16);
6088 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
6089 reg, reg, mips_gp_register);
6090 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)",
6091 reg, BFD_RELOC_MIPS_GOT_LO16, reg);
6092 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
6093 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6094 else if (ex.X_add_number)
6096 ex.X_op = O_constant;
6097 macro_build (&ex, ADDRESS_ADDI_INSN, "t,r,j", reg, reg,
6101 ep->X_add_number = ex.X_add_number;
6103 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
6104 BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register);
6105 macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", reg, reg,
6106 BFD_RELOC_MIPS_GOT_OFST);
6111 ex.X_add_number = ep->X_add_number;
6112 ep->X_add_number = 0;
6113 relax_start (ep->X_add_symbol);
6114 macro_build (ep, "lui", LUI_FMT, reg, BFD_RELOC_MIPS_GOT_HI16);
6115 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
6116 reg, reg, mips_gp_register);
6117 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)",
6118 reg, BFD_RELOC_MIPS_GOT_LO16, reg);
6120 if (reg_needs_delay (mips_gp_register))
6122 /* We need a nop before loading from $gp. This special
6123 check is required because the lui which starts the main
6124 instruction stream does not refer to $gp, and so will not
6125 insert the nop which may be required. */
6126 macro_build (NULL, "nop", "");
6128 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
6129 BFD_RELOC_MIPS_GOT16, mips_gp_register);
6131 macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", reg, reg,
6135 if (ex.X_add_number != 0)
6137 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
6138 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6139 ex.X_op = O_constant;
6140 macro_build (&ex, ADDRESS_ADDI_INSN, "t,r,j", reg, reg,
6148 if (!mips_opts.at && *used_at == 1)
6149 as_bad (_("Macro used $at after \".set noat\""));
6152 /* Move the contents of register SOURCE into register DEST. */
6155 move_register (int dest, int source)
6157 /* Prefer to use a 16-bit microMIPS instruction unless the previous
6158 instruction specifically requires a 32-bit one. */
6159 if (mips_opts.micromips
6160 && !(history[0].insn_mo->pinfo2 & INSN2_BRANCH_DELAY_32BIT))
6161 macro_build (NULL, "move", "mp,mj", dest, source);
6163 macro_build (NULL, HAVE_32BIT_GPRS ? "addu" : "daddu", "d,v,t",
6167 /* Emit an SVR4 PIC sequence to load address LOCAL into DEST, where
6168 LOCAL is the sum of a symbol and a 16-bit or 32-bit displacement.
6169 The two alternatives are:
6171 Global symbol Local sybmol
6172 ------------- ------------
6173 lw DEST,%got(SYMBOL) lw DEST,%got(SYMBOL + OFFSET)
6175 addiu DEST,DEST,OFFSET addiu DEST,DEST,%lo(SYMBOL + OFFSET)
6177 load_got_offset emits the first instruction and add_got_offset
6178 emits the second for a 16-bit offset or add_got_offset_hilo emits
6179 a sequence to add a 32-bit offset using a scratch register. */
6182 load_got_offset (int dest, expressionS *local)
6187 global.X_add_number = 0;
6189 relax_start (local->X_add_symbol);
6190 macro_build (&global, ADDRESS_LOAD_INSN, "t,o(b)", dest,
6191 BFD_RELOC_MIPS_GOT16, mips_gp_register);
6193 macro_build (local, ADDRESS_LOAD_INSN, "t,o(b)", dest,
6194 BFD_RELOC_MIPS_GOT16, mips_gp_register);
6199 add_got_offset (int dest, expressionS *local)
6203 global.X_op = O_constant;
6204 global.X_op_symbol = NULL;
6205 global.X_add_symbol = NULL;
6206 global.X_add_number = local->X_add_number;
6208 relax_start (local->X_add_symbol);
6209 macro_build (&global, ADDRESS_ADDI_INSN, "t,r,j",
6210 dest, dest, BFD_RELOC_LO16);
6212 macro_build (local, ADDRESS_ADDI_INSN, "t,r,j", dest, dest, BFD_RELOC_LO16);
6217 add_got_offset_hilo (int dest, expressionS *local, int tmp)
6220 int hold_mips_optimize;
6222 global.X_op = O_constant;
6223 global.X_op_symbol = NULL;
6224 global.X_add_symbol = NULL;
6225 global.X_add_number = local->X_add_number;
6227 relax_start (local->X_add_symbol);
6228 load_register (tmp, &global, HAVE_64BIT_ADDRESSES);
6230 /* Set mips_optimize around the lui instruction to avoid
6231 inserting an unnecessary nop after the lw. */
6232 hold_mips_optimize = mips_optimize;
6234 macro_build_lui (&global, tmp);
6235 mips_optimize = hold_mips_optimize;
6236 macro_build (local, ADDRESS_ADDI_INSN, "t,r,j", tmp, tmp, BFD_RELOC_LO16);
6239 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", dest, dest, tmp);
6242 /* Emit a sequence of instructions to emulate a branch likely operation.
6243 BR is an ordinary branch corresponding to one to be emulated. BRNEG
6244 is its complementing branch with the original condition negated.
6245 CALL is set if the original branch specified the link operation.
6246 EP, FMT, SREG and TREG specify the usual macro_build() parameters.
6248 Code like this is produced in the noreorder mode:
6253 delay slot (executed only if branch taken)
6261 delay slot (executed only if branch taken)
6264 In the reorder mode the delay slot would be filled with a nop anyway,
6265 so code produced is simply:
6270 This function is used when producing code for the microMIPS ASE that
6271 does not implement branch likely instructions in hardware. */
6274 macro_build_branch_likely (const char *br, const char *brneg,
6275 int call, expressionS *ep, const char *fmt,
6276 unsigned int sreg, unsigned int treg)
6278 int noreorder = mips_opts.noreorder;
6281 gas_assert (mips_opts.micromips);
6285 micromips_label_expr (&expr1);
6286 macro_build (&expr1, brneg, fmt, sreg, treg);
6287 macro_build (NULL, "nop", "");
6288 macro_build (ep, call ? "bal" : "b", "p");
6290 /* Set to true so that append_insn adds a label. */
6291 emit_branch_likely_macro = TRUE;
6295 macro_build (ep, br, fmt, sreg, treg);
6296 macro_build (NULL, "nop", "");
6301 /* Emit a coprocessor branch-likely macro specified by TYPE, using CC as
6302 the condition code tested. EP specifies the branch target. */
6305 macro_build_branch_ccl (int type, expressionS *ep, unsigned int cc)
6332 macro_build_branch_likely (br, brneg, call, ep, "N,p", cc, ZERO);
6335 /* Emit a two-argument branch macro specified by TYPE, using SREG as
6336 the register tested. EP specifies the branch target. */
6339 macro_build_branch_rs (int type, expressionS *ep, unsigned int sreg)
6341 const char *brneg = NULL;
6351 br = mips_opts.micromips ? "bgez" : "bgezl";
6355 gas_assert (mips_opts.micromips);
6364 br = mips_opts.micromips ? "bgtz" : "bgtzl";
6371 br = mips_opts.micromips ? "blez" : "blezl";
6378 br = mips_opts.micromips ? "bltz" : "bltzl";
6382 gas_assert (mips_opts.micromips);
6390 if (mips_opts.micromips && brneg)
6391 macro_build_branch_likely (br, brneg, call, ep, "s,p", sreg, ZERO);
6393 macro_build (ep, br, "s,p", sreg);
6396 /* Emit a three-argument branch macro specified by TYPE, using SREG and
6397 TREG as the registers tested. EP specifies the branch target. */
6400 macro_build_branch_rsrt (int type, expressionS *ep,
6401 unsigned int sreg, unsigned int treg)
6403 const char *brneg = NULL;
6415 br = mips_opts.micromips ? "beq" : "beql";
6424 br = mips_opts.micromips ? "bne" : "bnel";
6430 if (mips_opts.micromips && brneg)
6431 macro_build_branch_likely (br, brneg, call, ep, "s,t,p", sreg, treg);
6433 macro_build (ep, br, "s,t,p", sreg, treg);
6438 * This routine implements the seemingly endless macro or synthesized
6439 * instructions and addressing modes in the mips assembly language. Many
6440 * of these macros are simple and are similar to each other. These could
6441 * probably be handled by some kind of table or grammar approach instead of
6442 * this verbose method. Others are not simple macros but are more like
6443 * optimizing code generation.
6444 * One interesting optimization is when several store macros appear
6445 * consecutively that would load AT with the upper half of the same address.
6446 * The ensuing load upper instructions are ommited. This implies some kind
6447 * of global optimization. We currently only optimize within a single macro.
6448 * For many of the load and store macros if the address is specified as a
6449 * constant expression in the first 64k of memory (ie ld $2,0x4000c) we
6450 * first load register 'at' with zero and use it as the base register. The
6451 * mips assembler simply uses register $zero. Just one tiny optimization
6455 macro (struct mips_cl_insn *ip)
6457 unsigned int treg, sreg, dreg, breg;
6458 unsigned int tempreg;
6461 expressionS label_expr;
6479 bfd_reloc_code_real_type r;
6480 int hold_mips_optimize;
6482 gas_assert (! mips_opts.mips16);
6484 treg = EXTRACT_OPERAND (mips_opts.micromips, RT, *ip);
6485 dreg = EXTRACT_OPERAND (mips_opts.micromips, RD, *ip);
6486 sreg = breg = EXTRACT_OPERAND (mips_opts.micromips, RS, *ip);
6487 mask = ip->insn_mo->mask;
6489 label_expr.X_op = O_constant;
6490 label_expr.X_op_symbol = NULL;
6491 label_expr.X_add_symbol = NULL;
6492 label_expr.X_add_number = 0;
6494 expr1.X_op = O_constant;
6495 expr1.X_op_symbol = NULL;
6496 expr1.X_add_symbol = NULL;
6497 expr1.X_add_number = 1;
6512 if (mips_opts.micromips)
6513 micromips_label_expr (&label_expr);
6515 label_expr.X_add_number = 8;
6516 macro_build (&label_expr, "bgez", "s,p", sreg);
6518 macro_build (NULL, "nop", "");
6520 move_register (dreg, sreg);
6521 macro_build (NULL, dbl ? "dsub" : "sub", "d,v,t", dreg, 0, sreg);
6522 if (mips_opts.micromips)
6523 micromips_add_label ();
6540 if (!mips_opts.micromips)
6542 if (imm_expr.X_op == O_constant
6543 && imm_expr.X_add_number >= -0x200
6544 && imm_expr.X_add_number < 0x200)
6546 macro_build (NULL, s, "t,r,.", treg, sreg, imm_expr.X_add_number);
6555 if (imm_expr.X_op == O_constant
6556 && imm_expr.X_add_number >= -0x8000
6557 && imm_expr.X_add_number < 0x8000)
6559 macro_build (&imm_expr, s, "t,r,j", treg, sreg, BFD_RELOC_LO16);
6564 load_register (AT, &imm_expr, dbl);
6565 macro_build (NULL, s2, "d,v,t", treg, sreg, AT);
6584 if (imm_expr.X_op == O_constant
6585 && imm_expr.X_add_number >= 0
6586 && imm_expr.X_add_number < 0x10000)
6588 if (mask != M_NOR_I)
6589 macro_build (&imm_expr, s, "t,r,i", treg, sreg, BFD_RELOC_LO16);
6592 macro_build (&imm_expr, "ori", "t,r,i",
6593 treg, sreg, BFD_RELOC_LO16);
6594 macro_build (NULL, "nor", "d,v,t", treg, treg, 0);
6600 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
6601 macro_build (NULL, s2, "d,v,t", treg, sreg, AT);
6605 switch (imm_expr.X_add_number)
6608 macro_build (NULL, "nop", "");
6611 macro_build (NULL, "packrl.ph", "d,s,t", treg, treg, sreg);
6615 macro_build (NULL, "balign", "t,s,2", treg, sreg,
6616 (int) imm_expr.X_add_number);
6619 as_bad (_("BALIGN immediate not 0, 1, 2 or 3 (%lu)"),
6620 (unsigned long) imm_expr.X_add_number);
6629 gas_assert (mips_opts.micromips);
6630 macro_build_branch_ccl (mask, &offset_expr,
6631 EXTRACT_OPERAND (1, BCC, *ip));
6638 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
6644 load_register (treg, &imm_expr, HAVE_64BIT_GPRS);
6649 macro_build_branch_rsrt (mask, &offset_expr, sreg, treg);
6656 macro_build_branch_rs (likely ? M_BGEZL : M_BGEZ, &offset_expr, sreg);
6658 macro_build_branch_rs (likely ? M_BLEZL : M_BLEZ, &offset_expr, treg);
6662 macro_build (NULL, "slt", "d,v,t", AT, sreg, treg);
6663 macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ,
6664 &offset_expr, AT, ZERO);
6674 macro_build_branch_rs (mask, &offset_expr, sreg);
6680 /* Check for > max integer. */
6681 maxnum = 0x7fffffff;
6682 if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4)
6689 if (imm_expr.X_op == O_constant
6690 && imm_expr.X_add_number >= maxnum
6691 && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4))
6694 /* Result is always false. */
6696 macro_build (NULL, "nop", "");
6698 macro_build_branch_rsrt (M_BNEL, &offset_expr, ZERO, ZERO);
6701 if (imm_expr.X_op != O_constant)
6702 as_bad (_("Unsupported large constant"));
6703 ++imm_expr.X_add_number;
6707 if (mask == M_BGEL_I)
6709 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
6711 macro_build_branch_rs (likely ? M_BGEZL : M_BGEZ,
6712 &offset_expr, sreg);
6715 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
6717 macro_build_branch_rs (likely ? M_BGTZL : M_BGTZ,
6718 &offset_expr, sreg);
6721 maxnum = 0x7fffffff;
6722 if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4)
6729 maxnum = - maxnum - 1;
6730 if (imm_expr.X_op == O_constant
6731 && imm_expr.X_add_number <= maxnum
6732 && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4))
6735 /* result is always true */
6736 as_warn (_("Branch %s is always true"), ip->insn_mo->name);
6737 macro_build (&offset_expr, "b", "p");
6742 macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ,
6743 &offset_expr, AT, ZERO);
6752 macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ,
6753 &offset_expr, ZERO, treg);
6757 macro_build (NULL, "sltu", "d,v,t", AT, sreg, treg);
6758 macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ,
6759 &offset_expr, AT, ZERO);
6768 && imm_expr.X_op == O_constant
6769 && imm_expr.X_add_number == -1))
6771 if (imm_expr.X_op != O_constant)
6772 as_bad (_("Unsupported large constant"));
6773 ++imm_expr.X_add_number;
6777 if (mask == M_BGEUL_I)
6779 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
6781 else if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
6782 macro_build_branch_rsrt (likely ? M_BNEL : M_BNE,
6783 &offset_expr, sreg, ZERO);
6788 macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ,
6789 &offset_expr, AT, ZERO);
6797 macro_build_branch_rs (likely ? M_BGTZL : M_BGTZ, &offset_expr, sreg);
6799 macro_build_branch_rs (likely ? M_BLTZL : M_BLTZ, &offset_expr, treg);
6803 macro_build (NULL, "slt", "d,v,t", AT, treg, sreg);
6804 macro_build_branch_rsrt (likely ? M_BNEL : M_BNE,
6805 &offset_expr, AT, ZERO);
6813 macro_build_branch_rsrt (likely ? M_BNEL : M_BNE,
6814 &offset_expr, sreg, ZERO);
6820 macro_build (NULL, "sltu", "d,v,t", AT, treg, sreg);
6821 macro_build_branch_rsrt (likely ? M_BNEL : M_BNE,
6822 &offset_expr, AT, ZERO);
6830 macro_build_branch_rs (likely ? M_BLEZL : M_BLEZ, &offset_expr, sreg);
6832 macro_build_branch_rs (likely ? M_BGEZL : M_BGEZ, &offset_expr, treg);
6836 macro_build (NULL, "slt", "d,v,t", AT, treg, sreg);
6837 macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ,
6838 &offset_expr, AT, ZERO);
6845 maxnum = 0x7fffffff;
6846 if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4)
6853 if (imm_expr.X_op == O_constant
6854 && imm_expr.X_add_number >= maxnum
6855 && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4))
6857 if (imm_expr.X_op != O_constant)
6858 as_bad (_("Unsupported large constant"));
6859 ++imm_expr.X_add_number;
6863 if (mask == M_BLTL_I)
6865 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
6866 macro_build_branch_rs (likely ? M_BLTZL : M_BLTZ, &offset_expr, sreg);
6867 else if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
6868 macro_build_branch_rs (likely ? M_BLEZL : M_BLEZ, &offset_expr, sreg);
6873 macro_build_branch_rsrt (likely ? M_BNEL : M_BNE,
6874 &offset_expr, AT, ZERO);
6882 macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ,
6883 &offset_expr, sreg, ZERO);
6889 macro_build (NULL, "sltu", "d,v,t", AT, treg, sreg);
6890 macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ,
6891 &offset_expr, AT, ZERO);
6900 && imm_expr.X_op == O_constant
6901 && imm_expr.X_add_number == -1))
6903 if (imm_expr.X_op != O_constant)
6904 as_bad (_("Unsupported large constant"));
6905 ++imm_expr.X_add_number;
6909 if (mask == M_BLTUL_I)
6911 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
6913 else if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
6914 macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ,
6915 &offset_expr, sreg, ZERO);
6920 macro_build_branch_rsrt (likely ? M_BNEL : M_BNE,
6921 &offset_expr, AT, ZERO);
6929 macro_build_branch_rs (likely ? M_BLTZL : M_BLTZ, &offset_expr, sreg);
6931 macro_build_branch_rs (likely ? M_BGTZL : M_BGTZ, &offset_expr, treg);
6935 macro_build (NULL, "slt", "d,v,t", AT, sreg, treg);
6936 macro_build_branch_rsrt (likely ? M_BNEL : M_BNE,
6937 &offset_expr, AT, ZERO);
6947 macro_build_branch_rsrt (likely ? M_BNEL : M_BNE,
6948 &offset_expr, ZERO, treg);
6952 macro_build (NULL, "sltu", "d,v,t", AT, sreg, treg);
6953 macro_build_branch_rsrt (likely ? M_BNEL : M_BNE,
6954 &offset_expr, AT, ZERO);
6960 /* Use unsigned arithmetic. */
6964 if (imm_expr.X_op != O_constant || imm2_expr.X_op != O_constant)
6966 as_bad (_("Unsupported large constant"));
6971 pos = imm_expr.X_add_number;
6972 size = imm2_expr.X_add_number;
6977 as_bad (_("Improper position (%lu)"), (unsigned long) pos);
6980 if (size == 0 || size > 64 || (pos + size - 1) > 63)
6982 as_bad (_("Improper extract size (%lu, position %lu)"),
6983 (unsigned long) size, (unsigned long) pos);
6987 if (size <= 32 && pos < 32)
6992 else if (size <= 32)
7002 macro_build ((expressionS *) NULL, s, fmt, treg, sreg, (int) pos,
7009 /* Use unsigned arithmetic. */
7013 if (imm_expr.X_op != O_constant || imm2_expr.X_op != O_constant)
7015 as_bad (_("Unsupported large constant"));
7020 pos = imm_expr.X_add_number;
7021 size = imm2_expr.X_add_number;
7026 as_bad (_("Improper position (%lu)"), (unsigned long) pos);
7029 if (size == 0 || size > 64 || (pos + size - 1) > 63)
7031 as_bad (_("Improper insert size (%lu, position %lu)"),
7032 (unsigned long) size, (unsigned long) pos);
7036 if (pos < 32 && (pos + size - 1) < 32)
7051 macro_build ((expressionS *) NULL, s, fmt, treg, sreg, (int) pos,
7052 (int) (pos + size - 1));
7068 as_warn (_("Divide by zero."));
7070 macro_build (NULL, "teq", TRAP_FMT, ZERO, ZERO, 7);
7072 macro_build (NULL, "break", BRK_FMT, 7);
7079 macro_build (NULL, "teq", TRAP_FMT, treg, ZERO, 7);
7080 macro_build (NULL, dbl ? "ddiv" : "div", "z,s,t", sreg, treg);
7084 if (mips_opts.micromips)
7085 micromips_label_expr (&label_expr);
7087 label_expr.X_add_number = 8;
7088 macro_build (&label_expr, "bne", "s,t,p", treg, ZERO);
7089 macro_build (NULL, dbl ? "ddiv" : "div", "z,s,t", sreg, treg);
7090 macro_build (NULL, "break", BRK_FMT, 7);
7091 if (mips_opts.micromips)
7092 micromips_add_label ();
7094 expr1.X_add_number = -1;
7096 load_register (AT, &expr1, dbl);
7097 if (mips_opts.micromips)
7098 micromips_label_expr (&label_expr);
7100 label_expr.X_add_number = mips_trap ? (dbl ? 12 : 8) : (dbl ? 20 : 16);
7101 macro_build (&label_expr, "bne", "s,t,p", treg, AT);
7104 expr1.X_add_number = 1;
7105 load_register (AT, &expr1, dbl);
7106 macro_build (NULL, "dsll32", SHFT_FMT, AT, AT, 31);
7110 expr1.X_add_number = 0x80000000;
7111 macro_build (&expr1, "lui", LUI_FMT, AT, BFD_RELOC_HI16);
7115 macro_build (NULL, "teq", TRAP_FMT, sreg, AT, 6);
7116 /* We want to close the noreorder block as soon as possible, so
7117 that later insns are available for delay slot filling. */
7122 if (mips_opts.micromips)
7123 micromips_label_expr (&label_expr);
7125 label_expr.X_add_number = 8;
7126 macro_build (&label_expr, "bne", "s,t,p", sreg, AT);
7127 macro_build (NULL, "nop", "");
7129 /* We want to close the noreorder block as soon as possible, so
7130 that later insns are available for delay slot filling. */
7133 macro_build (NULL, "break", BRK_FMT, 6);
7135 if (mips_opts.micromips)
7136 micromips_add_label ();
7137 macro_build (NULL, s, MFHL_FMT, dreg);
7176 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
7178 as_warn (_("Divide by zero."));
7180 macro_build (NULL, "teq", TRAP_FMT, ZERO, ZERO, 7);
7182 macro_build (NULL, "break", BRK_FMT, 7);
7185 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
7187 if (strcmp (s2, "mflo") == 0)
7188 move_register (dreg, sreg);
7190 move_register (dreg, ZERO);
7193 if (imm_expr.X_op == O_constant
7194 && imm_expr.X_add_number == -1
7195 && s[strlen (s) - 1] != 'u')
7197 if (strcmp (s2, "mflo") == 0)
7199 macro_build (NULL, dbl ? "dneg" : "neg", "d,w", dreg, sreg);
7202 move_register (dreg, ZERO);
7207 load_register (AT, &imm_expr, dbl);
7208 macro_build (NULL, s, "z,s,t", sreg, AT);
7209 macro_build (NULL, s2, MFHL_FMT, dreg);
7231 macro_build (NULL, "teq", TRAP_FMT, treg, ZERO, 7);
7232 macro_build (NULL, s, "z,s,t", sreg, treg);
7233 /* We want to close the noreorder block as soon as possible, so
7234 that later insns are available for delay slot filling. */
7239 if (mips_opts.micromips)
7240 micromips_label_expr (&label_expr);
7242 label_expr.X_add_number = 8;
7243 macro_build (&label_expr, "bne", "s,t,p", treg, ZERO);
7244 macro_build (NULL, s, "z,s,t", sreg, treg);
7246 /* We want to close the noreorder block as soon as possible, so
7247 that later insns are available for delay slot filling. */
7249 macro_build (NULL, "break", BRK_FMT, 7);
7250 if (mips_opts.micromips)
7251 micromips_add_label ();
7253 macro_build (NULL, s2, MFHL_FMT, dreg);
7265 /* Load the address of a symbol into a register. If breg is not
7266 zero, we then add a base register to it. */
7268 if (dbl && HAVE_32BIT_GPRS)
7269 as_warn (_("dla used to load 32-bit register"));
7271 if (!dbl && HAVE_64BIT_OBJECTS)
7272 as_warn (_("la used to load 64-bit address"));
7274 if (offset_expr.X_op == O_constant
7275 && offset_expr.X_add_number >= -0x8000
7276 && offset_expr.X_add_number < 0x8000)
7278 macro_build (&offset_expr, ADDRESS_ADDI_INSN,
7279 "t,r,j", treg, sreg, BFD_RELOC_LO16);
7283 if (mips_opts.at && (treg == breg))
7293 if (offset_expr.X_op != O_symbol
7294 && offset_expr.X_op != O_constant)
7296 as_bad (_("Expression too complex"));
7297 offset_expr.X_op = O_constant;
7300 if (offset_expr.X_op == O_constant)
7301 load_register (tempreg, &offset_expr, HAVE_64BIT_ADDRESSES);
7302 else if (mips_pic == NO_PIC)
7304 /* If this is a reference to a GP relative symbol, we want
7305 addiu $tempreg,$gp,<sym> (BFD_RELOC_GPREL16)
7307 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
7308 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
7309 If we have a constant, we need two instructions anyhow,
7310 so we may as well always use the latter form.
7312 With 64bit address space and a usable $at we want
7313 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
7314 lui $at,<sym> (BFD_RELOC_HI16_S)
7315 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
7316 daddiu $at,<sym> (BFD_RELOC_LO16)
7318 daddu $tempreg,$tempreg,$at
7320 If $at is already in use, we use a path which is suboptimal
7321 on superscalar processors.
7322 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
7323 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
7325 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
7327 daddiu $tempreg,<sym> (BFD_RELOC_LO16)
7329 For GP relative symbols in 64bit address space we can use
7330 the same sequence as in 32bit address space. */
7331 if (HAVE_64BIT_SYMBOLS)
7333 if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
7334 && !nopic_need_relax (offset_expr.X_add_symbol, 1))
7336 relax_start (offset_expr.X_add_symbol);
7337 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
7338 tempreg, mips_gp_register, BFD_RELOC_GPREL16);
7342 if (used_at == 0 && mips_opts.at)
7344 macro_build (&offset_expr, "lui", LUI_FMT,
7345 tempreg, BFD_RELOC_MIPS_HIGHEST);
7346 macro_build (&offset_expr, "lui", LUI_FMT,
7347 AT, BFD_RELOC_HI16_S);
7348 macro_build (&offset_expr, "daddiu", "t,r,j",
7349 tempreg, tempreg, BFD_RELOC_MIPS_HIGHER);
7350 macro_build (&offset_expr, "daddiu", "t,r,j",
7351 AT, AT, BFD_RELOC_LO16);
7352 macro_build (NULL, "dsll32", SHFT_FMT, tempreg, tempreg, 0);
7353 macro_build (NULL, "daddu", "d,v,t", tempreg, tempreg, AT);
7358 macro_build (&offset_expr, "lui", LUI_FMT,
7359 tempreg, BFD_RELOC_MIPS_HIGHEST);
7360 macro_build (&offset_expr, "daddiu", "t,r,j",
7361 tempreg, tempreg, BFD_RELOC_MIPS_HIGHER);
7362 macro_build (NULL, "dsll", SHFT_FMT, tempreg, tempreg, 16);
7363 macro_build (&offset_expr, "daddiu", "t,r,j",
7364 tempreg, tempreg, BFD_RELOC_HI16_S);
7365 macro_build (NULL, "dsll", SHFT_FMT, tempreg, tempreg, 16);
7366 macro_build (&offset_expr, "daddiu", "t,r,j",
7367 tempreg, tempreg, BFD_RELOC_LO16);
7370 if (mips_relax.sequence)
7375 if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
7376 && !nopic_need_relax (offset_expr.X_add_symbol, 1))
7378 relax_start (offset_expr.X_add_symbol);
7379 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
7380 tempreg, mips_gp_register, BFD_RELOC_GPREL16);
7383 if (!IS_SEXT_32BIT_NUM (offset_expr.X_add_number))
7384 as_bad (_("Offset too large"));
7385 macro_build_lui (&offset_expr, tempreg);
7386 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
7387 tempreg, tempreg, BFD_RELOC_LO16);
7388 if (mips_relax.sequence)
7392 else if (!mips_big_got && !HAVE_NEWABI)
7394 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT16;
7396 /* If this is a reference to an external symbol, and there
7397 is no constant, we want
7398 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
7399 or for lca or if tempreg is PIC_CALL_REG
7400 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
7401 For a local symbol, we want
7402 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
7404 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
7406 If we have a small constant, and this is a reference to
7407 an external symbol, we want
7408 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
7410 addiu $tempreg,$tempreg,<constant>
7411 For a local symbol, we want the same instruction
7412 sequence, but we output a BFD_RELOC_LO16 reloc on the
7415 If we have a large constant, and this is a reference to
7416 an external symbol, we want
7417 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
7418 lui $at,<hiconstant>
7419 addiu $at,$at,<loconstant>
7420 addu $tempreg,$tempreg,$at
7421 For a local symbol, we want the same instruction
7422 sequence, but we output a BFD_RELOC_LO16 reloc on the
7426 if (offset_expr.X_add_number == 0)
7428 if (mips_pic == SVR4_PIC
7430 && (call || tempreg == PIC_CALL_REG))
7431 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL16;
7433 relax_start (offset_expr.X_add_symbol);
7434 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
7435 lw_reloc_type, mips_gp_register);
7438 /* We're going to put in an addu instruction using
7439 tempreg, so we may as well insert the nop right
7444 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
7445 tempreg, BFD_RELOC_MIPS_GOT16, mips_gp_register);
7447 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
7448 tempreg, tempreg, BFD_RELOC_LO16);
7450 /* FIXME: If breg == 0, and the next instruction uses
7451 $tempreg, then if this variant case is used an extra
7452 nop will be generated. */
7454 else if (offset_expr.X_add_number >= -0x8000
7455 && offset_expr.X_add_number < 0x8000)
7457 load_got_offset (tempreg, &offset_expr);
7459 add_got_offset (tempreg, &offset_expr);
7463 expr1.X_add_number = offset_expr.X_add_number;
7464 offset_expr.X_add_number =
7465 SEXT_16BIT (offset_expr.X_add_number);
7466 load_got_offset (tempreg, &offset_expr);
7467 offset_expr.X_add_number = expr1.X_add_number;
7468 /* If we are going to add in a base register, and the
7469 target register and the base register are the same,
7470 then we are using AT as a temporary register. Since
7471 we want to load the constant into AT, we add our
7472 current AT (from the global offset table) and the
7473 register into the register now, and pretend we were
7474 not using a base register. */
7478 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
7483 add_got_offset_hilo (tempreg, &offset_expr, AT);
7487 else if (!mips_big_got && HAVE_NEWABI)
7489 int add_breg_early = 0;
7491 /* If this is a reference to an external, and there is no
7492 constant, or local symbol (*), with or without a
7494 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
7495 or for lca or if tempreg is PIC_CALL_REG
7496 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
7498 If we have a small constant, and this is a reference to
7499 an external symbol, we want
7500 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
7501 addiu $tempreg,$tempreg,<constant>
7503 If we have a large constant, and this is a reference to
7504 an external symbol, we want
7505 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
7506 lui $at,<hiconstant>
7507 addiu $at,$at,<loconstant>
7508 addu $tempreg,$tempreg,$at
7510 (*) Other assemblers seem to prefer GOT_PAGE/GOT_OFST for
7511 local symbols, even though it introduces an additional
7514 if (offset_expr.X_add_number)
7516 expr1.X_add_number = offset_expr.X_add_number;
7517 offset_expr.X_add_number = 0;
7519 relax_start (offset_expr.X_add_symbol);
7520 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
7521 BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
7523 if (expr1.X_add_number >= -0x8000
7524 && expr1.X_add_number < 0x8000)
7526 macro_build (&expr1, ADDRESS_ADDI_INSN, "t,r,j",
7527 tempreg, tempreg, BFD_RELOC_LO16);
7529 else if (IS_SEXT_32BIT_NUM (expr1.X_add_number + 0x8000))
7531 /* If we are going to add in a base register, and the
7532 target register and the base register are the same,
7533 then we are using AT as a temporary register. Since
7534 we want to load the constant into AT, we add our
7535 current AT (from the global offset table) and the
7536 register into the register now, and pretend we were
7537 not using a base register. */
7542 gas_assert (tempreg == AT);
7543 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
7549 load_register (AT, &expr1, HAVE_64BIT_ADDRESSES);
7550 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
7556 as_bad (_("PIC code offset overflow (max 32 signed bits)"));
7559 offset_expr.X_add_number = expr1.X_add_number;
7561 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
7562 BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
7565 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
7566 treg, tempreg, breg);
7572 else if (breg == 0 && (call || tempreg == PIC_CALL_REG))
7574 relax_start (offset_expr.X_add_symbol);
7575 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
7576 BFD_RELOC_MIPS_CALL16, mips_gp_register);
7578 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
7579 BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
7584 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
7585 BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
7588 else if (mips_big_got && !HAVE_NEWABI)
7591 int lui_reloc_type = (int) BFD_RELOC_MIPS_GOT_HI16;
7592 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT_LO16;
7593 int local_reloc_type = (int) BFD_RELOC_MIPS_GOT16;
7595 /* This is the large GOT case. If this is a reference to an
7596 external symbol, and there is no constant, we want
7597 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
7598 addu $tempreg,$tempreg,$gp
7599 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
7600 or for lca or if tempreg is PIC_CALL_REG
7601 lui $tempreg,<sym> (BFD_RELOC_MIPS_CALL_HI16)
7602 addu $tempreg,$tempreg,$gp
7603 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_CALL_LO16)
7604 For a local symbol, we want
7605 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
7607 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
7609 If we have a small constant, and this is a reference to
7610 an external symbol, we want
7611 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
7612 addu $tempreg,$tempreg,$gp
7613 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
7615 addiu $tempreg,$tempreg,<constant>
7616 For a local symbol, we want
7617 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
7619 addiu $tempreg,$tempreg,<constant> (BFD_RELOC_LO16)
7621 If we have a large constant, and this is a reference to
7622 an external symbol, we want
7623 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
7624 addu $tempreg,$tempreg,$gp
7625 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
7626 lui $at,<hiconstant>
7627 addiu $at,$at,<loconstant>
7628 addu $tempreg,$tempreg,$at
7629 For a local symbol, we want
7630 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
7631 lui $at,<hiconstant>
7632 addiu $at,$at,<loconstant> (BFD_RELOC_LO16)
7633 addu $tempreg,$tempreg,$at
7636 expr1.X_add_number = offset_expr.X_add_number;
7637 offset_expr.X_add_number = 0;
7638 relax_start (offset_expr.X_add_symbol);
7639 gpdelay = reg_needs_delay (mips_gp_register);
7640 if (expr1.X_add_number == 0 && breg == 0
7641 && (call || tempreg == PIC_CALL_REG))
7643 lui_reloc_type = (int) BFD_RELOC_MIPS_CALL_HI16;
7644 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL_LO16;
7646 macro_build (&offset_expr, "lui", LUI_FMT, tempreg, lui_reloc_type);
7647 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
7648 tempreg, tempreg, mips_gp_register);
7649 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
7650 tempreg, lw_reloc_type, tempreg);
7651 if (expr1.X_add_number == 0)
7655 /* We're going to put in an addu instruction using
7656 tempreg, so we may as well insert the nop right
7661 else if (expr1.X_add_number >= -0x8000
7662 && expr1.X_add_number < 0x8000)
7665 macro_build (&expr1, ADDRESS_ADDI_INSN, "t,r,j",
7666 tempreg, tempreg, BFD_RELOC_LO16);
7670 /* If we are going to add in a base register, and the
7671 target register and the base register are the same,
7672 then we are using AT as a temporary register. Since
7673 we want to load the constant into AT, we add our
7674 current AT (from the global offset table) and the
7675 register into the register now, and pretend we were
7676 not using a base register. */
7681 gas_assert (tempreg == AT);
7683 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
7688 load_register (AT, &expr1, HAVE_64BIT_ADDRESSES);
7689 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", dreg, dreg, AT);
7693 offset_expr.X_add_number = SEXT_16BIT (expr1.X_add_number);
7698 /* This is needed because this instruction uses $gp, but
7699 the first instruction on the main stream does not. */
7700 macro_build (NULL, "nop", "");
7703 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
7704 local_reloc_type, mips_gp_register);
7705 if (expr1.X_add_number >= -0x8000
7706 && expr1.X_add_number < 0x8000)
7709 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
7710 tempreg, tempreg, BFD_RELOC_LO16);
7711 /* FIXME: If add_number is 0, and there was no base
7712 register, the external symbol case ended with a load,
7713 so if the symbol turns out to not be external, and
7714 the next instruction uses tempreg, an unnecessary nop
7715 will be inserted. */
7721 /* We must add in the base register now, as in the
7722 external symbol case. */
7723 gas_assert (tempreg == AT);
7725 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
7728 /* We set breg to 0 because we have arranged to add
7729 it in in both cases. */
7733 macro_build_lui (&expr1, AT);
7734 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
7735 AT, AT, BFD_RELOC_LO16);
7736 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
7737 tempreg, tempreg, AT);
7742 else if (mips_big_got && HAVE_NEWABI)
7744 int lui_reloc_type = (int) BFD_RELOC_MIPS_GOT_HI16;
7745 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT_LO16;
7746 int add_breg_early = 0;
7748 /* This is the large GOT case. If this is a reference to an
7749 external symbol, and there is no constant, we want
7750 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
7751 add $tempreg,$tempreg,$gp
7752 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
7753 or for lca or if tempreg is PIC_CALL_REG
7754 lui $tempreg,<sym> (BFD_RELOC_MIPS_CALL_HI16)
7755 add $tempreg,$tempreg,$gp
7756 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_CALL_LO16)
7758 If we have a small constant, and this is a reference to
7759 an external symbol, we want
7760 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
7761 add $tempreg,$tempreg,$gp
7762 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
7763 addi $tempreg,$tempreg,<constant>
7765 If we have a large constant, and this is a reference to
7766 an external symbol, we want
7767 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
7768 addu $tempreg,$tempreg,$gp
7769 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
7770 lui $at,<hiconstant>
7771 addi $at,$at,<loconstant>
7772 add $tempreg,$tempreg,$at
7774 If we have NewABI, and we know it's a local symbol, we want
7775 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
7776 addiu $reg,$reg,<sym> (BFD_RELOC_MIPS_GOT_OFST)
7777 otherwise we have to resort to GOT_HI16/GOT_LO16. */
7779 relax_start (offset_expr.X_add_symbol);
7781 expr1.X_add_number = offset_expr.X_add_number;
7782 offset_expr.X_add_number = 0;
7784 if (expr1.X_add_number == 0 && breg == 0
7785 && (call || tempreg == PIC_CALL_REG))
7787 lui_reloc_type = (int) BFD_RELOC_MIPS_CALL_HI16;
7788 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL_LO16;
7790 macro_build (&offset_expr, "lui", LUI_FMT, tempreg, lui_reloc_type);
7791 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
7792 tempreg, tempreg, mips_gp_register);
7793 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
7794 tempreg, lw_reloc_type, tempreg);
7796 if (expr1.X_add_number == 0)
7798 else if (expr1.X_add_number >= -0x8000
7799 && expr1.X_add_number < 0x8000)
7801 macro_build (&expr1, ADDRESS_ADDI_INSN, "t,r,j",
7802 tempreg, tempreg, BFD_RELOC_LO16);
7804 else if (IS_SEXT_32BIT_NUM (expr1.X_add_number + 0x8000))
7806 /* If we are going to add in a base register, and the
7807 target register and the base register are the same,
7808 then we are using AT as a temporary register. Since
7809 we want to load the constant into AT, we add our
7810 current AT (from the global offset table) and the
7811 register into the register now, and pretend we were
7812 not using a base register. */
7817 gas_assert (tempreg == AT);
7818 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
7824 load_register (AT, &expr1, HAVE_64BIT_ADDRESSES);
7825 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", dreg, dreg, AT);
7830 as_bad (_("PIC code offset overflow (max 32 signed bits)"));
7833 offset_expr.X_add_number = expr1.X_add_number;
7834 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
7835 BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register);
7836 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j", tempreg,
7837 tempreg, BFD_RELOC_MIPS_GOT_OFST);
7840 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
7841 treg, tempreg, breg);
7851 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", treg, tempreg, breg);
7855 gas_assert (!mips_opts.micromips);
7857 unsigned long temp = (treg << 16) | (0x01);
7858 macro_build (NULL, "c2", "C", temp);
7863 gas_assert (!mips_opts.micromips);
7865 unsigned long temp = (0x02);
7866 macro_build (NULL, "c2", "C", temp);
7871 gas_assert (!mips_opts.micromips);
7873 unsigned long temp = (treg << 16) | (0x02);
7874 macro_build (NULL, "c2", "C", temp);
7879 gas_assert (!mips_opts.micromips);
7880 macro_build (NULL, "c2", "C", 3);
7884 gas_assert (!mips_opts.micromips);
7886 unsigned long temp = (treg << 16) | 0x03;
7887 macro_build (NULL, "c2", "C", temp);
7892 /* The j instruction may not be used in PIC code, since it
7893 requires an absolute address. We convert it to a b
7895 if (mips_pic == NO_PIC)
7896 macro_build (&offset_expr, "j", "a");
7898 macro_build (&offset_expr, "b", "p");
7901 /* The jal instructions must be handled as macros because when
7902 generating PIC code they expand to multi-instruction
7903 sequences. Normally they are simple instructions. */
7908 gas_assert (mips_opts.micromips);
7916 if (mips_pic == NO_PIC)
7918 s = jals ? "jalrs" : "jalr";
7919 if (mips_opts.micromips
7921 && !(history[0].insn_mo->pinfo2 & INSN2_BRANCH_DELAY_32BIT))
7922 macro_build (NULL, s, "mj", sreg);
7924 macro_build (NULL, s, JALR_FMT, dreg, sreg);
7928 int cprestore = (mips_pic == SVR4_PIC && !HAVE_NEWABI
7929 && mips_cprestore_offset >= 0);
7931 if (sreg != PIC_CALL_REG)
7932 as_warn (_("MIPS PIC call to register other than $25"));
7934 s = (mips_opts.micromips && (!mips_opts.noreorder || cprestore)
7935 ? "jalrs" : "jalr");
7936 if (mips_opts.micromips
7938 && !(history[0].insn_mo->pinfo2 & INSN2_BRANCH_DELAY_32BIT))
7939 macro_build (NULL, s, "mj", sreg);
7941 macro_build (NULL, s, JALR_FMT, dreg, sreg);
7942 if (mips_pic == SVR4_PIC && !HAVE_NEWABI)
7944 if (mips_cprestore_offset < 0)
7945 as_warn (_("No .cprestore pseudo-op used in PIC code"));
7948 if (!mips_frame_reg_valid)
7950 as_warn (_("No .frame pseudo-op used in PIC code"));
7951 /* Quiet this warning. */
7952 mips_frame_reg_valid = 1;
7954 if (!mips_cprestore_valid)
7956 as_warn (_("No .cprestore pseudo-op used in PIC code"));
7957 /* Quiet this warning. */
7958 mips_cprestore_valid = 1;
7960 if (mips_opts.noreorder)
7961 macro_build (NULL, "nop", "");
7962 expr1.X_add_number = mips_cprestore_offset;
7963 macro_build_ldst_constoffset (&expr1, ADDRESS_LOAD_INSN,
7966 HAVE_64BIT_ADDRESSES);
7974 gas_assert (mips_opts.micromips);
7978 if (mips_pic == NO_PIC)
7979 macro_build (&offset_expr, jals ? "jals" : "jal", "a");
7980 else if (mips_pic == SVR4_PIC)
7982 /* If this is a reference to an external symbol, and we are
7983 using a small GOT, we want
7984 lw $25,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
7988 lw $gp,cprestore($sp)
7989 The cprestore value is set using the .cprestore
7990 pseudo-op. If we are using a big GOT, we want
7991 lui $25,<sym> (BFD_RELOC_MIPS_CALL_HI16)
7993 lw $25,<sym>($25) (BFD_RELOC_MIPS_CALL_LO16)
7997 lw $gp,cprestore($sp)
7998 If the symbol is not external, we want
7999 lw $25,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
8001 addiu $25,$25,<sym> (BFD_RELOC_LO16)
8004 lw $gp,cprestore($sp)
8006 For NewABI, we use the same CALL16 or CALL_HI16/CALL_LO16
8007 sequences above, minus nops, unless the symbol is local,
8008 which enables us to use GOT_PAGE/GOT_OFST (big got) or
8014 relax_start (offset_expr.X_add_symbol);
8015 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
8016 PIC_CALL_REG, BFD_RELOC_MIPS_CALL16,
8019 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
8020 PIC_CALL_REG, BFD_RELOC_MIPS_GOT_DISP,
8026 relax_start (offset_expr.X_add_symbol);
8027 macro_build (&offset_expr, "lui", LUI_FMT, PIC_CALL_REG,
8028 BFD_RELOC_MIPS_CALL_HI16);
8029 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", PIC_CALL_REG,
8030 PIC_CALL_REG, mips_gp_register);
8031 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
8032 PIC_CALL_REG, BFD_RELOC_MIPS_CALL_LO16,
8035 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
8036 PIC_CALL_REG, BFD_RELOC_MIPS_GOT_PAGE,
8038 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
8039 PIC_CALL_REG, PIC_CALL_REG,
8040 BFD_RELOC_MIPS_GOT_OFST);
8044 macro_build_jalr (&offset_expr, 0);
8048 relax_start (offset_expr.X_add_symbol);
8051 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
8052 PIC_CALL_REG, BFD_RELOC_MIPS_CALL16,
8061 gpdelay = reg_needs_delay (mips_gp_register);
8062 macro_build (&offset_expr, "lui", LUI_FMT, PIC_CALL_REG,
8063 BFD_RELOC_MIPS_CALL_HI16);
8064 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", PIC_CALL_REG,
8065 PIC_CALL_REG, mips_gp_register);
8066 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
8067 PIC_CALL_REG, BFD_RELOC_MIPS_CALL_LO16,
8072 macro_build (NULL, "nop", "");
8074 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
8075 PIC_CALL_REG, BFD_RELOC_MIPS_GOT16,
8078 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
8079 PIC_CALL_REG, PIC_CALL_REG, BFD_RELOC_LO16);
8081 macro_build_jalr (&offset_expr, mips_cprestore_offset >= 0);
8083 if (mips_cprestore_offset < 0)
8084 as_warn (_("No .cprestore pseudo-op used in PIC code"));
8087 if (!mips_frame_reg_valid)
8089 as_warn (_("No .frame pseudo-op used in PIC code"));
8090 /* Quiet this warning. */
8091 mips_frame_reg_valid = 1;
8093 if (!mips_cprestore_valid)
8095 as_warn (_("No .cprestore pseudo-op used in PIC code"));
8096 /* Quiet this warning. */
8097 mips_cprestore_valid = 1;
8099 if (mips_opts.noreorder)
8100 macro_build (NULL, "nop", "");
8101 expr1.X_add_number = mips_cprestore_offset;
8102 macro_build_ldst_constoffset (&expr1, ADDRESS_LOAD_INSN,
8105 HAVE_64BIT_ADDRESSES);
8109 else if (mips_pic == VXWORKS_PIC)
8110 as_bad (_("Non-PIC jump used in PIC library"));
8218 treg = EXTRACT_OPERAND (mips_opts.micromips, 3BITPOS, *ip);
8226 treg = EXTRACT_OPERAND (mips_opts.micromips, 3BITPOS, *ip);
8257 gas_assert (!mips_opts.micromips);
8260 /* Itbl support may require additional care here. */
8267 /* Itbl support may require additional care here. */
8275 offbits = (mips_opts.micromips ? 12 : 16);
8276 /* Itbl support may require additional care here. */
8281 gas_assert (!mips_opts.micromips);
8284 /* Itbl support may require additional care here. */
8292 offbits = (mips_opts.micromips ? 12 : 16);
8299 offbits = (mips_opts.micromips ? 12 : 16);
8305 /* Itbl support may require additional care here. */
8313 offbits = (mips_opts.micromips ? 12 : 16);
8314 /* Itbl support may require additional care here. */
8321 /* Itbl support may require additional care here. */
8328 /* Itbl support may require additional care here. */
8336 offbits = (mips_opts.micromips ? 12 : 16);
8343 offbits = (mips_opts.micromips ? 12 : 16);
8350 offbits = (mips_opts.micromips ? 12 : 16);
8357 offbits = (mips_opts.micromips ? 12 : 16);
8364 offbits = (mips_opts.micromips ? 12 : 16);
8369 gas_assert (mips_opts.micromips);
8378 gas_assert (mips_opts.micromips);
8387 gas_assert (mips_opts.micromips);
8395 gas_assert (mips_opts.micromips);
8402 /* We don't want to use $0 as tempreg. */
8403 if (breg == treg + lp || treg + lp == ZERO)
8406 tempreg = treg + lp;
8426 gas_assert (!mips_opts.micromips);
8429 /* Itbl support may require additional care here. */
8436 /* Itbl support may require additional care here. */
8444 offbits = (mips_opts.micromips ? 12 : 16);
8445 /* Itbl support may require additional care here. */
8450 gas_assert (!mips_opts.micromips);
8453 /* Itbl support may require additional care here. */
8461 offbits = (mips_opts.micromips ? 12 : 16);
8468 offbits = (mips_opts.micromips ? 12 : 16);
8475 offbits = (mips_opts.micromips ? 12 : 16);
8482 offbits = (mips_opts.micromips ? 12 : 16);
8488 fmt = mips_opts.micromips ? "k,~(b)" : "k,o(b)";
8489 offbits = (mips_opts.micromips ? 12 : 16);
8502 fmt = !mips_opts.micromips ? "k,o(b)" : "k,~(b)";
8503 offbits = (mips_opts.micromips ? 12 : 16);
8517 /* Itbl support may require additional care here. */
8524 offbits = (mips_opts.micromips ? 12 : 16);
8525 /* Itbl support may require additional care here. */
8532 /* Itbl support may require additional care here. */
8537 gas_assert (!mips_opts.micromips);
8540 /* Itbl support may require additional care here. */
8548 offbits = (mips_opts.micromips ? 12 : 16);
8555 offbits = (mips_opts.micromips ? 12 : 16);
8560 gas_assert (mips_opts.micromips);
8568 gas_assert (mips_opts.micromips);
8576 gas_assert (mips_opts.micromips);
8584 gas_assert (mips_opts.micromips);
8593 if (offset_expr.X_op != O_constant
8594 && offset_expr.X_op != O_symbol)
8596 as_bad (_("Expression too complex"));
8597 offset_expr.X_op = O_constant;
8600 if (HAVE_32BIT_ADDRESSES
8601 && !IS_SEXT_32BIT_NUM (offset_expr.X_add_number))
8605 sprintf_vma (value, offset_expr.X_add_number);
8606 as_bad (_("Number (0x%s) larger than 32 bits"), value);
8609 /* A constant expression in PIC code can be handled just as it
8610 is in non PIC code. */
8611 if (offset_expr.X_op == O_constant)
8615 expr1.X_add_number = offset_expr.X_add_number;
8616 normalize_address_expr (&expr1);
8617 if ((offbits == 0 || offbits == 16)
8618 && !IS_SEXT_16BIT_NUM (expr1.X_add_number))
8620 expr1.X_add_number = ((expr1.X_add_number + 0x8000)
8621 & ~(bfd_vma) 0xffff);
8624 else if (offbits == 12 && !IS_SEXT_12BIT_NUM (expr1.X_add_number))
8626 expr1.X_add_number = ((expr1.X_add_number + 0x800)
8627 & ~(bfd_vma) 0xfff);
8630 else if (offbits == 9 && !IS_SEXT_9BIT_NUM (expr1.X_add_number))
8632 expr1.X_add_number = ((expr1.X_add_number + 0x100)
8633 & ~(bfd_vma) 0x1ff);
8638 load_register (tempreg, &expr1, HAVE_64BIT_ADDRESSES);
8640 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
8641 tempreg, tempreg, breg);
8646 if (offset_expr.X_add_number == 0)
8649 macro_build (&offset_expr, ADDRESS_ADDI_INSN,
8650 "t,r,j", tempreg, breg, BFD_RELOC_LO16);
8651 macro_build (NULL, s, fmt, treg, tempreg);
8653 else if (offbits == 16)
8654 macro_build (&offset_expr, s, fmt, treg, BFD_RELOC_LO16, breg);
8656 macro_build (NULL, s, fmt,
8657 treg, (unsigned long) offset_expr.X_add_number, breg);
8659 else if (offbits != 16)
8661 /* The offset field is too narrow to be used for a low-part
8662 relocation, so load the whole address into the auxillary
8663 register. In the case of "A(b)" addresses, we first load
8664 absolute address "A" into the register and then add base
8665 register "b". In the case of "o(b)" addresses, we simply
8666 need to add 16-bit offset "o" to base register "b", and
8667 offset_reloc already contains the relocations associated
8671 load_address (tempreg, &offset_expr, &used_at);
8673 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
8674 tempreg, tempreg, breg);
8677 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
8679 offset_reloc[0], offset_reloc[1], offset_reloc[2]);
8680 expr1.X_add_number = 0;
8682 macro_build (NULL, s, fmt, treg, tempreg);
8684 macro_build (NULL, s, fmt,
8685 treg, (unsigned long) expr1.X_add_number, tempreg);
8687 else if (mips_pic == NO_PIC)
8689 /* If this is a reference to a GP relative symbol, and there
8690 is no base register, we want
8691 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
8692 Otherwise, if there is no base register, we want
8693 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
8694 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
8695 If we have a constant, we need two instructions anyhow,
8696 so we always use the latter form.
8698 If we have a base register, and this is a reference to a
8699 GP relative symbol, we want
8700 addu $tempreg,$breg,$gp
8701 <op> $treg,<sym>($tempreg) (BFD_RELOC_GPREL16)
8703 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
8704 addu $tempreg,$tempreg,$breg
8705 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
8706 With a constant we always use the latter case.
8708 With 64bit address space and no base register and $at usable,
8710 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
8711 lui $at,<sym> (BFD_RELOC_HI16_S)
8712 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
8715 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
8716 If we have a base register, we want
8717 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
8718 lui $at,<sym> (BFD_RELOC_HI16_S)
8719 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
8723 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
8725 Without $at we can't generate the optimal path for superscalar
8726 processors here since this would require two temporary registers.
8727 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
8728 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
8730 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
8732 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
8733 If we have a base register, we want
8734 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
8735 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
8737 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
8739 daddu $tempreg,$tempreg,$breg
8740 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
8742 For GP relative symbols in 64bit address space we can use
8743 the same sequence as in 32bit address space. */
8744 if (HAVE_64BIT_SYMBOLS)
8746 if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
8747 && !nopic_need_relax (offset_expr.X_add_symbol, 1))
8749 relax_start (offset_expr.X_add_symbol);
8752 macro_build (&offset_expr, s, fmt, treg,
8753 BFD_RELOC_GPREL16, mips_gp_register);
8757 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
8758 tempreg, breg, mips_gp_register);
8759 macro_build (&offset_expr, s, fmt, treg,
8760 BFD_RELOC_GPREL16, tempreg);
8765 if (used_at == 0 && mips_opts.at)
8767 macro_build (&offset_expr, "lui", LUI_FMT, tempreg,
8768 BFD_RELOC_MIPS_HIGHEST);
8769 macro_build (&offset_expr, "lui", LUI_FMT, AT,
8771 macro_build (&offset_expr, "daddiu", "t,r,j", tempreg,
8772 tempreg, BFD_RELOC_MIPS_HIGHER);
8774 macro_build (NULL, "daddu", "d,v,t", AT, AT, breg);
8775 macro_build (NULL, "dsll32", SHFT_FMT, tempreg, tempreg, 0);
8776 macro_build (NULL, "daddu", "d,v,t", tempreg, tempreg, AT);
8777 macro_build (&offset_expr, s, fmt, treg, BFD_RELOC_LO16,
8783 macro_build (&offset_expr, "lui", LUI_FMT, tempreg,
8784 BFD_RELOC_MIPS_HIGHEST);
8785 macro_build (&offset_expr, "daddiu", "t,r,j", tempreg,
8786 tempreg, BFD_RELOC_MIPS_HIGHER);
8787 macro_build (NULL, "dsll", SHFT_FMT, tempreg, tempreg, 16);
8788 macro_build (&offset_expr, "daddiu", "t,r,j", tempreg,
8789 tempreg, BFD_RELOC_HI16_S);
8790 macro_build (NULL, "dsll", SHFT_FMT, tempreg, tempreg, 16);
8792 macro_build (NULL, "daddu", "d,v,t",
8793 tempreg, tempreg, breg);
8794 macro_build (&offset_expr, s, fmt, treg,
8795 BFD_RELOC_LO16, tempreg);
8798 if (mips_relax.sequence)
8805 if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
8806 && !nopic_need_relax (offset_expr.X_add_symbol, 1))
8808 relax_start (offset_expr.X_add_symbol);
8809 macro_build (&offset_expr, s, fmt, treg, BFD_RELOC_GPREL16,
8813 macro_build_lui (&offset_expr, tempreg);
8814 macro_build (&offset_expr, s, fmt, treg,
8815 BFD_RELOC_LO16, tempreg);
8816 if (mips_relax.sequence)
8821 if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
8822 && !nopic_need_relax (offset_expr.X_add_symbol, 1))
8824 relax_start (offset_expr.X_add_symbol);
8825 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
8826 tempreg, breg, mips_gp_register);
8827 macro_build (&offset_expr, s, fmt, treg,
8828 BFD_RELOC_GPREL16, tempreg);
8831 macro_build_lui (&offset_expr, tempreg);
8832 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
8833 tempreg, tempreg, breg);
8834 macro_build (&offset_expr, s, fmt, treg,
8835 BFD_RELOC_LO16, tempreg);
8836 if (mips_relax.sequence)
8840 else if (!mips_big_got)
8842 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT16;
8844 /* If this is a reference to an external symbol, we want
8845 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
8847 <op> $treg,0($tempreg)
8849 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
8851 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
8852 <op> $treg,0($tempreg)
8855 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
8856 <op> $treg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_OFST)
8858 If there is a base register, we add it to $tempreg before
8859 the <op>. If there is a constant, we stick it in the
8860 <op> instruction. We don't handle constants larger than
8861 16 bits, because we have no way to load the upper 16 bits
8862 (actually, we could handle them for the subset of cases
8863 in which we are not using $at). */
8864 gas_assert (offset_expr.X_op == O_symbol);
8867 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
8868 BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register);
8870 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
8871 tempreg, tempreg, breg);
8872 macro_build (&offset_expr, s, fmt, treg,
8873 BFD_RELOC_MIPS_GOT_OFST, tempreg);
8876 expr1.X_add_number = offset_expr.X_add_number;
8877 offset_expr.X_add_number = 0;
8878 if (expr1.X_add_number < -0x8000
8879 || expr1.X_add_number >= 0x8000)
8880 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
8881 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
8882 lw_reloc_type, mips_gp_register);
8884 relax_start (offset_expr.X_add_symbol);
8886 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j", tempreg,
8887 tempreg, BFD_RELOC_LO16);
8890 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
8891 tempreg, tempreg, breg);
8892 macro_build (&expr1, s, fmt, treg, BFD_RELOC_LO16, tempreg);
8894 else if (mips_big_got && !HAVE_NEWABI)
8898 /* If this is a reference to an external symbol, we want
8899 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
8900 addu $tempreg,$tempreg,$gp
8901 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
8902 <op> $treg,0($tempreg)
8904 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
8906 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
8907 <op> $treg,0($tempreg)
8908 If there is a base register, we add it to $tempreg before
8909 the <op>. If there is a constant, we stick it in the
8910 <op> instruction. We don't handle constants larger than
8911 16 bits, because we have no way to load the upper 16 bits
8912 (actually, we could handle them for the subset of cases
8913 in which we are not using $at). */
8914 gas_assert (offset_expr.X_op == O_symbol);
8915 expr1.X_add_number = offset_expr.X_add_number;
8916 offset_expr.X_add_number = 0;
8917 if (expr1.X_add_number < -0x8000
8918 || expr1.X_add_number >= 0x8000)
8919 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
8920 gpdelay = reg_needs_delay (mips_gp_register);
8921 relax_start (offset_expr.X_add_symbol);
8922 macro_build (&offset_expr, "lui", LUI_FMT, tempreg,
8923 BFD_RELOC_MIPS_GOT_HI16);
8924 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", tempreg, tempreg,
8926 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
8927 BFD_RELOC_MIPS_GOT_LO16, tempreg);
8930 macro_build (NULL, "nop", "");
8931 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
8932 BFD_RELOC_MIPS_GOT16, mips_gp_register);
8934 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j", tempreg,
8935 tempreg, BFD_RELOC_LO16);
8939 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
8940 tempreg, tempreg, breg);
8941 macro_build (&expr1, s, fmt, treg, BFD_RELOC_LO16, tempreg);
8943 else if (mips_big_got && HAVE_NEWABI)
8945 /* If this is a reference to an external symbol, we want
8946 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
8947 add $tempreg,$tempreg,$gp
8948 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
8949 <op> $treg,<ofst>($tempreg)
8950 Otherwise, for local symbols, we want:
8951 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
8952 <op> $treg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_OFST) */
8953 gas_assert (offset_expr.X_op == O_symbol);
8954 expr1.X_add_number = offset_expr.X_add_number;
8955 offset_expr.X_add_number = 0;
8956 if (expr1.X_add_number < -0x8000
8957 || expr1.X_add_number >= 0x8000)
8958 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
8959 relax_start (offset_expr.X_add_symbol);
8960 macro_build (&offset_expr, "lui", LUI_FMT, tempreg,
8961 BFD_RELOC_MIPS_GOT_HI16);
8962 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", tempreg, tempreg,
8964 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
8965 BFD_RELOC_MIPS_GOT_LO16, tempreg);
8967 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
8968 tempreg, tempreg, breg);
8969 macro_build (&expr1, s, fmt, treg, BFD_RELOC_LO16, tempreg);
8972 offset_expr.X_add_number = expr1.X_add_number;
8973 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
8974 BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register);
8976 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
8977 tempreg, tempreg, breg);
8978 macro_build (&offset_expr, s, fmt, treg,
8979 BFD_RELOC_MIPS_GOT_OFST, tempreg);
8989 load_register (treg, &imm_expr, 0);
8993 load_register (treg, &imm_expr, 1);
8997 if (imm_expr.X_op == O_constant)
9000 load_register (AT, &imm_expr, 0);
9001 macro_build (NULL, "mtc1", "t,G", AT, treg);
9006 gas_assert (offset_expr.X_op == O_symbol
9007 && strcmp (segment_name (S_GET_SEGMENT
9008 (offset_expr.X_add_symbol)),
9010 && offset_expr.X_add_number == 0);
9011 macro_build (&offset_expr, "lwc1", "T,o(b)", treg,
9012 BFD_RELOC_MIPS_LITERAL, mips_gp_register);
9017 /* Check if we have a constant in IMM_EXPR. If the GPRs are 64 bits
9018 wide, IMM_EXPR is the entire value. Otherwise IMM_EXPR is the high
9019 order 32 bits of the value and the low order 32 bits are either
9020 zero or in OFFSET_EXPR. */
9021 if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big)
9023 if (HAVE_64BIT_GPRS)
9024 load_register (treg, &imm_expr, 1);
9029 if (target_big_endian)
9041 load_register (hreg, &imm_expr, 0);
9044 if (offset_expr.X_op == O_absent)
9045 move_register (lreg, 0);
9048 gas_assert (offset_expr.X_op == O_constant);
9049 load_register (lreg, &offset_expr, 0);
9056 /* We know that sym is in the .rdata section. First we get the
9057 upper 16 bits of the address. */
9058 if (mips_pic == NO_PIC)
9060 macro_build_lui (&offset_expr, AT);
9065 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", AT,
9066 BFD_RELOC_MIPS_GOT16, mips_gp_register);
9070 /* Now we load the register(s). */
9071 if (HAVE_64BIT_GPRS)
9074 macro_build (&offset_expr, "ld", "t,o(b)", treg, BFD_RELOC_LO16, AT);
9079 macro_build (&offset_expr, "lw", "t,o(b)", treg, BFD_RELOC_LO16, AT);
9082 /* FIXME: How in the world do we deal with the possible
9084 offset_expr.X_add_number += 4;
9085 macro_build (&offset_expr, "lw", "t,o(b)",
9086 treg + 1, BFD_RELOC_LO16, AT);
9092 /* Check if we have a constant in IMM_EXPR. If the FPRs are 64 bits
9093 wide, IMM_EXPR is the entire value and the GPRs are known to be 64
9094 bits wide as well. Otherwise IMM_EXPR is the high order 32 bits of
9095 the value and the low order 32 bits are either zero or in
9097 if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big)
9100 load_register (AT, &imm_expr, HAVE_64BIT_FPRS);
9101 if (HAVE_64BIT_FPRS)
9103 gas_assert (HAVE_64BIT_GPRS);
9104 macro_build (NULL, "dmtc1", "t,S", AT, treg);
9108 macro_build (NULL, "mtc1", "t,G", AT, treg + 1);
9109 if (offset_expr.X_op == O_absent)
9110 macro_build (NULL, "mtc1", "t,G", 0, treg);
9113 gas_assert (offset_expr.X_op == O_constant);
9114 load_register (AT, &offset_expr, 0);
9115 macro_build (NULL, "mtc1", "t,G", AT, treg);
9121 gas_assert (offset_expr.X_op == O_symbol
9122 && offset_expr.X_add_number == 0);
9123 s = segment_name (S_GET_SEGMENT (offset_expr.X_add_symbol));
9124 if (strcmp (s, ".lit8") == 0)
9126 if (CPU_HAS_LDC1_SDC1 (mips_opts.arch) || mips_opts.micromips)
9128 macro_build (&offset_expr, "ldc1", "T,o(b)", treg,
9129 BFD_RELOC_MIPS_LITERAL, mips_gp_register);
9132 breg = mips_gp_register;
9133 r = BFD_RELOC_MIPS_LITERAL;
9138 gas_assert (strcmp (s, RDATA_SECTION_NAME) == 0);
9140 if (mips_pic != NO_PIC)
9141 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", AT,
9142 BFD_RELOC_MIPS_GOT16, mips_gp_register);
9145 /* FIXME: This won't work for a 64 bit address. */
9146 macro_build_lui (&offset_expr, AT);
9149 if (CPU_HAS_LDC1_SDC1 (mips_opts.arch) || mips_opts.micromips)
9151 macro_build (&offset_expr, "ldc1", "T,o(b)",
9152 treg, BFD_RELOC_LO16, AT);
9161 /* Even on a big endian machine $fn comes before $fn+1. We have
9162 to adjust when loading from memory. */
9165 gas_assert (!mips_opts.micromips);
9166 gas_assert (!CPU_HAS_LDC1_SDC1 (mips_opts.arch));
9167 macro_build (&offset_expr, "lwc1", "T,o(b)",
9168 target_big_endian ? treg + 1 : treg, r, breg);
9169 /* FIXME: A possible overflow which I don't know how to deal
9171 offset_expr.X_add_number += 4;
9172 macro_build (&offset_expr, "lwc1", "T,o(b)",
9173 target_big_endian ? treg : treg + 1, r, breg);
9177 gas_assert (!mips_opts.micromips);
9178 gas_assert (!CPU_HAS_LDC1_SDC1 (mips_opts.arch));
9179 /* Even on a big endian machine $fn comes before $fn+1. We have
9180 to adjust when storing to memory. */
9181 macro_build (&offset_expr, "swc1", "T,o(b)",
9182 target_big_endian ? treg + 1 : treg, BFD_RELOC_LO16, breg);
9183 offset_expr.X_add_number += 4;
9184 macro_build (&offset_expr, "swc1", "T,o(b)",
9185 target_big_endian ? treg : treg + 1, BFD_RELOC_LO16, breg);
9189 gas_assert (!mips_opts.micromips);
9191 * The MIPS assembler seems to check for X_add_number not
9192 * being double aligned and generating:
9195 * addiu at,at,%lo(foo+1)
9198 * But, the resulting address is the same after relocation so why
9199 * generate the extra instruction?
9201 /* Itbl support may require additional care here. */
9204 if (CPU_HAS_LDC1_SDC1 (mips_opts.arch))
9213 gas_assert (!mips_opts.micromips);
9214 /* Itbl support may require additional care here. */
9217 if (CPU_HAS_LDC1_SDC1 (mips_opts.arch))
9237 if (HAVE_64BIT_GPRS)
9247 if (HAVE_64BIT_GPRS)
9255 if (offset_expr.X_op != O_symbol
9256 && offset_expr.X_op != O_constant)
9258 as_bad (_("Expression too complex"));
9259 offset_expr.X_op = O_constant;
9262 if (HAVE_32BIT_ADDRESSES
9263 && !IS_SEXT_32BIT_NUM (offset_expr.X_add_number))
9267 sprintf_vma (value, offset_expr.X_add_number);
9268 as_bad (_("Number (0x%s) larger than 32 bits"), value);
9271 /* Even on a big endian machine $fn comes before $fn+1. We have
9272 to adjust when loading from memory. We set coproc if we must
9273 load $fn+1 first. */
9274 /* Itbl support may require additional care here. */
9275 if (!target_big_endian)
9278 if (mips_pic == NO_PIC || offset_expr.X_op == O_constant)
9280 /* If this is a reference to a GP relative symbol, we want
9281 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
9282 <op> $treg+1,<sym>+4($gp) (BFD_RELOC_GPREL16)
9283 If we have a base register, we use this
9285 <op> $treg,<sym>($at) (BFD_RELOC_GPREL16)
9286 <op> $treg+1,<sym>+4($at) (BFD_RELOC_GPREL16)
9287 If this is not a GP relative symbol, we want
9288 lui $at,<sym> (BFD_RELOC_HI16_S)
9289 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
9290 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
9291 If there is a base register, we add it to $at after the
9292 lui instruction. If there is a constant, we always use
9294 if (offset_expr.X_op == O_symbol
9295 && (valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
9296 && !nopic_need_relax (offset_expr.X_add_symbol, 1))
9298 relax_start (offset_expr.X_add_symbol);
9301 tempreg = mips_gp_register;
9305 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
9306 AT, breg, mips_gp_register);
9311 /* Itbl support may require additional care here. */
9312 macro_build (&offset_expr, s, fmt, coproc ? treg + 1 : treg,
9313 BFD_RELOC_GPREL16, tempreg);
9314 offset_expr.X_add_number += 4;
9316 /* Set mips_optimize to 2 to avoid inserting an
9318 hold_mips_optimize = mips_optimize;
9320 /* Itbl support may require additional care here. */
9321 macro_build (&offset_expr, s, fmt, coproc ? treg : treg + 1,
9322 BFD_RELOC_GPREL16, tempreg);
9323 mips_optimize = hold_mips_optimize;
9327 offset_expr.X_add_number -= 4;
9330 macro_build_lui (&offset_expr, AT);
9332 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, breg, AT);
9333 /* Itbl support may require additional care here. */
9334 macro_build (&offset_expr, s, fmt, coproc ? treg + 1 : treg,
9335 BFD_RELOC_LO16, AT);
9336 /* FIXME: How do we handle overflow here? */
9337 offset_expr.X_add_number += 4;
9338 /* Itbl support may require additional care here. */
9339 macro_build (&offset_expr, s, fmt, coproc ? treg : treg + 1,
9340 BFD_RELOC_LO16, AT);
9341 if (mips_relax.sequence)
9344 else if (!mips_big_got)
9346 /* If this is a reference to an external symbol, we want
9347 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
9352 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
9354 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
9355 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
9356 If there is a base register we add it to $at before the
9357 lwc1 instructions. If there is a constant we include it
9358 in the lwc1 instructions. */
9360 expr1.X_add_number = offset_expr.X_add_number;
9361 if (expr1.X_add_number < -0x8000
9362 || expr1.X_add_number >= 0x8000 - 4)
9363 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
9364 load_got_offset (AT, &offset_expr);
9367 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, breg, AT);
9369 /* Set mips_optimize to 2 to avoid inserting an undesired
9371 hold_mips_optimize = mips_optimize;
9374 /* Itbl support may require additional care here. */
9375 relax_start (offset_expr.X_add_symbol);
9376 macro_build (&expr1, s, fmt, coproc ? treg + 1 : treg,
9377 BFD_RELOC_LO16, AT);
9378 expr1.X_add_number += 4;
9379 macro_build (&expr1, s, fmt, coproc ? treg : treg + 1,
9380 BFD_RELOC_LO16, AT);
9382 macro_build (&offset_expr, s, fmt, coproc ? treg + 1 : treg,
9383 BFD_RELOC_LO16, AT);
9384 offset_expr.X_add_number += 4;
9385 macro_build (&offset_expr, s, fmt, coproc ? treg : treg + 1,
9386 BFD_RELOC_LO16, AT);
9389 mips_optimize = hold_mips_optimize;
9391 else if (mips_big_got)
9395 /* If this is a reference to an external symbol, we want
9396 lui $at,<sym> (BFD_RELOC_MIPS_GOT_HI16)
9398 lw $at,<sym>($at) (BFD_RELOC_MIPS_GOT_LO16)
9403 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
9405 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
9406 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
9407 If there is a base register we add it to $at before the
9408 lwc1 instructions. If there is a constant we include it
9409 in the lwc1 instructions. */
9411 expr1.X_add_number = offset_expr.X_add_number;
9412 offset_expr.X_add_number = 0;
9413 if (expr1.X_add_number < -0x8000
9414 || expr1.X_add_number >= 0x8000 - 4)
9415 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
9416 gpdelay = reg_needs_delay (mips_gp_register);
9417 relax_start (offset_expr.X_add_symbol);
9418 macro_build (&offset_expr, "lui", LUI_FMT,
9419 AT, BFD_RELOC_MIPS_GOT_HI16);
9420 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
9421 AT, AT, mips_gp_register);
9422 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
9423 AT, BFD_RELOC_MIPS_GOT_LO16, AT);
9426 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, breg, AT);
9427 /* Itbl support may require additional care here. */
9428 macro_build (&expr1, s, fmt, coproc ? treg + 1 : treg,
9429 BFD_RELOC_LO16, AT);
9430 expr1.X_add_number += 4;
9432 /* Set mips_optimize to 2 to avoid inserting an undesired
9434 hold_mips_optimize = mips_optimize;
9436 /* Itbl support may require additional care here. */
9437 macro_build (&expr1, s, fmt, coproc ? treg : treg + 1,
9438 BFD_RELOC_LO16, AT);
9439 mips_optimize = hold_mips_optimize;
9440 expr1.X_add_number -= 4;
9443 offset_expr.X_add_number = expr1.X_add_number;
9445 macro_build (NULL, "nop", "");
9446 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", AT,
9447 BFD_RELOC_MIPS_GOT16, mips_gp_register);
9450 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, breg, AT);
9451 /* Itbl support may require additional care here. */
9452 macro_build (&offset_expr, s, fmt, coproc ? treg + 1 : treg,
9453 BFD_RELOC_LO16, AT);
9454 offset_expr.X_add_number += 4;
9456 /* Set mips_optimize to 2 to avoid inserting an undesired
9458 hold_mips_optimize = mips_optimize;
9460 /* Itbl support may require additional care here. */
9461 macro_build (&offset_expr, s, fmt, coproc ? treg : treg + 1,
9462 BFD_RELOC_LO16, AT);
9463 mips_optimize = hold_mips_optimize;
9472 s = HAVE_64BIT_GPRS ? "ld" : "lw";
9475 s = HAVE_64BIT_GPRS ? "sd" : "sw";
9477 macro_build (&offset_expr, s, "t,o(b)", treg,
9478 -1, offset_reloc[0], offset_reloc[1], offset_reloc[2],
9480 if (!HAVE_64BIT_GPRS)
9482 offset_expr.X_add_number += 4;
9483 macro_build (&offset_expr, s, "t,o(b)", treg + 1,
9484 -1, offset_reloc[0], offset_reloc[1], offset_reloc[2],
9505 /* New code added to support COPZ instructions.
9506 This code builds table entries out of the macros in mip_opcodes.
9507 R4000 uses interlocks to handle coproc delays.
9508 Other chips (like the R3000) require nops to be inserted for delays.
9510 FIXME: Currently, we require that the user handle delays.
9511 In order to fill delay slots for non-interlocked chips,
9512 we must have a way to specify delays based on the coprocessor.
9513 Eg. 4 cycles if load coproc reg from memory, 1 if in cache, etc.
9514 What are the side-effects of the cop instruction?
9515 What cache support might we have and what are its effects?
9516 Both coprocessor & memory require delays. how long???
9517 What registers are read/set/modified?
9519 If an itbl is provided to interpret cop instructions,
9520 this knowledge can be encoded in the itbl spec. */
9534 gas_assert (!mips_opts.micromips);
9535 /* For now we just do C (same as Cz). The parameter will be
9536 stored in insn_opcode by mips_ip. */
9537 macro_build (NULL, s, "C", ip->insn_opcode);
9541 move_register (dreg, sreg);
9547 if (mips_opts.arch == CPU_R5900)
9549 macro_build (NULL, dbl ? "dmultu" : "multu", "d,s,t", dreg, sreg, treg);
9553 macro_build (NULL, dbl ? "dmultu" : "multu", "s,t", sreg, treg);
9554 macro_build (NULL, "mflo", MFHL_FMT, dreg);
9561 /* The MIPS assembler some times generates shifts and adds. I'm
9562 not trying to be that fancy. GCC should do this for us
9565 load_register (AT, &imm_expr, dbl);
9566 macro_build (NULL, dbl ? "dmult" : "mult", "s,t", sreg, AT);
9567 macro_build (NULL, "mflo", MFHL_FMT, dreg);
9583 load_register (AT, &imm_expr, dbl);
9584 macro_build (NULL, dbl ? "dmult" : "mult", "s,t", sreg, imm ? AT : treg);
9585 macro_build (NULL, "mflo", MFHL_FMT, dreg);
9586 macro_build (NULL, dbl ? "dsra32" : "sra", SHFT_FMT, dreg, dreg, RA);
9587 macro_build (NULL, "mfhi", MFHL_FMT, AT);
9589 macro_build (NULL, "tne", TRAP_FMT, dreg, AT, 6);
9592 if (mips_opts.micromips)
9593 micromips_label_expr (&label_expr);
9595 label_expr.X_add_number = 8;
9596 macro_build (&label_expr, "beq", "s,t,p", dreg, AT);
9597 macro_build (NULL, "nop", "");
9598 macro_build (NULL, "break", BRK_FMT, 6);
9599 if (mips_opts.micromips)
9600 micromips_add_label ();
9603 macro_build (NULL, "mflo", MFHL_FMT, dreg);
9619 load_register (AT, &imm_expr, dbl);
9620 macro_build (NULL, dbl ? "dmultu" : "multu", "s,t",
9621 sreg, imm ? AT : treg);
9622 macro_build (NULL, "mfhi", MFHL_FMT, AT);
9623 macro_build (NULL, "mflo", MFHL_FMT, dreg);
9625 macro_build (NULL, "tne", TRAP_FMT, AT, ZERO, 6);
9628 if (mips_opts.micromips)
9629 micromips_label_expr (&label_expr);
9631 label_expr.X_add_number = 8;
9632 macro_build (&label_expr, "beq", "s,t,p", AT, ZERO);
9633 macro_build (NULL, "nop", "");
9634 macro_build (NULL, "break", BRK_FMT, 6);
9635 if (mips_opts.micromips)
9636 micromips_add_label ();
9642 if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_opts.arch))
9653 macro_build (NULL, "dnegu", "d,w", tempreg, treg);
9654 macro_build (NULL, "drorv", "d,t,s", dreg, sreg, tempreg);
9658 macro_build (NULL, "dsubu", "d,v,t", AT, ZERO, treg);
9659 macro_build (NULL, "dsrlv", "d,t,s", AT, sreg, AT);
9660 macro_build (NULL, "dsllv", "d,t,s", dreg, sreg, treg);
9661 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
9665 if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_opts.arch))
9676 macro_build (NULL, "negu", "d,w", tempreg, treg);
9677 macro_build (NULL, "rorv", "d,t,s", dreg, sreg, tempreg);
9681 macro_build (NULL, "subu", "d,v,t", AT, ZERO, treg);
9682 macro_build (NULL, "srlv", "d,t,s", AT, sreg, AT);
9683 macro_build (NULL, "sllv", "d,t,s", dreg, sreg, treg);
9684 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
9693 if (imm_expr.X_op != O_constant)
9694 as_bad (_("Improper rotate count"));
9695 rot = imm_expr.X_add_number & 0x3f;
9696 if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_opts.arch))
9698 rot = (64 - rot) & 0x3f;
9700 macro_build (NULL, "dror32", SHFT_FMT, dreg, sreg, rot - 32);
9702 macro_build (NULL, "dror", SHFT_FMT, dreg, sreg, rot);
9707 macro_build (NULL, "dsrl", SHFT_FMT, dreg, sreg, 0);
9710 l = (rot < 0x20) ? "dsll" : "dsll32";
9711 rr = ((0x40 - rot) < 0x20) ? "dsrl" : "dsrl32";
9714 macro_build (NULL, l, SHFT_FMT, AT, sreg, rot);
9715 macro_build (NULL, rr, SHFT_FMT, dreg, sreg, (0x20 - rot) & 0x1f);
9716 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
9724 if (imm_expr.X_op != O_constant)
9725 as_bad (_("Improper rotate count"));
9726 rot = imm_expr.X_add_number & 0x1f;
9727 if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_opts.arch))
9729 macro_build (NULL, "ror", SHFT_FMT, dreg, sreg, (32 - rot) & 0x1f);
9734 macro_build (NULL, "srl", SHFT_FMT, dreg, sreg, 0);
9738 macro_build (NULL, "sll", SHFT_FMT, AT, sreg, rot);
9739 macro_build (NULL, "srl", SHFT_FMT, dreg, sreg, (0x20 - rot) & 0x1f);
9740 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
9745 if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_opts.arch))
9747 macro_build (NULL, "drorv", "d,t,s", dreg, sreg, treg);
9751 macro_build (NULL, "dsubu", "d,v,t", AT, ZERO, treg);
9752 macro_build (NULL, "dsllv", "d,t,s", AT, sreg, AT);
9753 macro_build (NULL, "dsrlv", "d,t,s", dreg, sreg, treg);
9754 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
9758 if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_opts.arch))
9760 macro_build (NULL, "rorv", "d,t,s", dreg, sreg, treg);
9764 macro_build (NULL, "subu", "d,v,t", AT, ZERO, treg);
9765 macro_build (NULL, "sllv", "d,t,s", AT, sreg, AT);
9766 macro_build (NULL, "srlv", "d,t,s", dreg, sreg, treg);
9767 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
9776 if (imm_expr.X_op != O_constant)
9777 as_bad (_("Improper rotate count"));
9778 rot = imm_expr.X_add_number & 0x3f;
9779 if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_opts.arch))
9782 macro_build (NULL, "dror32", SHFT_FMT, dreg, sreg, rot - 32);
9784 macro_build (NULL, "dror", SHFT_FMT, dreg, sreg, rot);
9789 macro_build (NULL, "dsrl", SHFT_FMT, dreg, sreg, 0);
9792 rr = (rot < 0x20) ? "dsrl" : "dsrl32";
9793 l = ((0x40 - rot) < 0x20) ? "dsll" : "dsll32";
9796 macro_build (NULL, rr, SHFT_FMT, AT, sreg, rot);
9797 macro_build (NULL, l, SHFT_FMT, dreg, sreg, (0x20 - rot) & 0x1f);
9798 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
9806 if (imm_expr.X_op != O_constant)
9807 as_bad (_("Improper rotate count"));
9808 rot = imm_expr.X_add_number & 0x1f;
9809 if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_opts.arch))
9811 macro_build (NULL, "ror", SHFT_FMT, dreg, sreg, rot);
9816 macro_build (NULL, "srl", SHFT_FMT, dreg, sreg, 0);
9820 macro_build (NULL, "srl", SHFT_FMT, AT, sreg, rot);
9821 macro_build (NULL, "sll", SHFT_FMT, dreg, sreg, (0x20 - rot) & 0x1f);
9822 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
9828 macro_build (&expr1, "sltiu", "t,r,j", dreg, treg, BFD_RELOC_LO16);
9830 macro_build (&expr1, "sltiu", "t,r,j", dreg, sreg, BFD_RELOC_LO16);
9833 macro_build (NULL, "xor", "d,v,t", dreg, sreg, treg);
9834 macro_build (&expr1, "sltiu", "t,r,j", dreg, dreg, BFD_RELOC_LO16);
9839 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
9841 macro_build (&expr1, "sltiu", "t,r,j", dreg, sreg, BFD_RELOC_LO16);
9846 as_warn (_("Instruction %s: result is always false"),
9848 move_register (dreg, 0);
9851 if (CPU_HAS_SEQ (mips_opts.arch)
9852 && -512 <= imm_expr.X_add_number
9853 && imm_expr.X_add_number < 512)
9855 macro_build (NULL, "seqi", "t,r,+Q", dreg, sreg,
9856 (int) imm_expr.X_add_number);
9859 if (imm_expr.X_op == O_constant
9860 && imm_expr.X_add_number >= 0
9861 && imm_expr.X_add_number < 0x10000)
9863 macro_build (&imm_expr, "xori", "t,r,i", dreg, sreg, BFD_RELOC_LO16);
9865 else if (imm_expr.X_op == O_constant
9866 && imm_expr.X_add_number > -0x8000
9867 && imm_expr.X_add_number < 0)
9869 imm_expr.X_add_number = -imm_expr.X_add_number;
9870 macro_build (&imm_expr, HAVE_32BIT_GPRS ? "addiu" : "daddiu",
9871 "t,r,j", dreg, sreg, BFD_RELOC_LO16);
9873 else if (CPU_HAS_SEQ (mips_opts.arch))
9876 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
9877 macro_build (NULL, "seq", "d,v,t", dreg, sreg, AT);
9882 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
9883 macro_build (NULL, "xor", "d,v,t", dreg, sreg, AT);
9886 macro_build (&expr1, "sltiu", "t,r,j", dreg, dreg, BFD_RELOC_LO16);
9889 case M_SGE: /* sreg >= treg <==> not (sreg < treg) */
9895 macro_build (NULL, s, "d,v,t", dreg, sreg, treg);
9896 macro_build (&expr1, "xori", "t,r,i", dreg, dreg, BFD_RELOC_LO16);
9899 case M_SGE_I: /* sreg >= I <==> not (sreg < I) */
9901 if (imm_expr.X_op == O_constant
9902 && imm_expr.X_add_number >= -0x8000
9903 && imm_expr.X_add_number < 0x8000)
9905 macro_build (&imm_expr, mask == M_SGE_I ? "slti" : "sltiu", "t,r,j",
9906 dreg, sreg, BFD_RELOC_LO16);
9910 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
9911 macro_build (NULL, mask == M_SGE_I ? "slt" : "sltu", "d,v,t",
9915 macro_build (&expr1, "xori", "t,r,i", dreg, dreg, BFD_RELOC_LO16);
9918 case M_SGT: /* sreg > treg <==> treg < sreg */
9924 macro_build (NULL, s, "d,v,t", dreg, treg, sreg);
9927 case M_SGT_I: /* sreg > I <==> I < sreg */
9934 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
9935 macro_build (NULL, s, "d,v,t", dreg, AT, sreg);
9938 case M_SLE: /* sreg <= treg <==> treg >= sreg <==> not (treg < sreg) */
9944 macro_build (NULL, s, "d,v,t", dreg, treg, sreg);
9945 macro_build (&expr1, "xori", "t,r,i", dreg, dreg, BFD_RELOC_LO16);
9948 case M_SLE_I: /* sreg <= I <==> I >= sreg <==> not (I < sreg) */
9955 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
9956 macro_build (NULL, s, "d,v,t", dreg, AT, sreg);
9957 macro_build (&expr1, "xori", "t,r,i", dreg, dreg, BFD_RELOC_LO16);
9961 if (imm_expr.X_op == O_constant
9962 && imm_expr.X_add_number >= -0x8000
9963 && imm_expr.X_add_number < 0x8000)
9965 macro_build (&imm_expr, "slti", "t,r,j", dreg, sreg, BFD_RELOC_LO16);
9969 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
9970 macro_build (NULL, "slt", "d,v,t", dreg, sreg, AT);
9974 if (imm_expr.X_op == O_constant
9975 && imm_expr.X_add_number >= -0x8000
9976 && imm_expr.X_add_number < 0x8000)
9978 macro_build (&imm_expr, "sltiu", "t,r,j", dreg, sreg,
9983 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
9984 macro_build (NULL, "sltu", "d,v,t", dreg, sreg, AT);
9989 macro_build (NULL, "sltu", "d,v,t", dreg, 0, treg);
9991 macro_build (NULL, "sltu", "d,v,t", dreg, 0, sreg);
9994 macro_build (NULL, "xor", "d,v,t", dreg, sreg, treg);
9995 macro_build (NULL, "sltu", "d,v,t", dreg, 0, dreg);
10000 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
10002 macro_build (NULL, "sltu", "d,v,t", dreg, 0, sreg);
10007 as_warn (_("Instruction %s: result is always true"),
10008 ip->insn_mo->name);
10009 macro_build (&expr1, HAVE_32BIT_GPRS ? "addiu" : "daddiu", "t,r,j",
10010 dreg, 0, BFD_RELOC_LO16);
10013 if (CPU_HAS_SEQ (mips_opts.arch)
10014 && -512 <= imm_expr.X_add_number
10015 && imm_expr.X_add_number < 512)
10017 macro_build (NULL, "snei", "t,r,+Q", dreg, sreg,
10018 (int) imm_expr.X_add_number);
10021 if (imm_expr.X_op == O_constant
10022 && imm_expr.X_add_number >= 0
10023 && imm_expr.X_add_number < 0x10000)
10025 macro_build (&imm_expr, "xori", "t,r,i", dreg, sreg, BFD_RELOC_LO16);
10027 else if (imm_expr.X_op == O_constant
10028 && imm_expr.X_add_number > -0x8000
10029 && imm_expr.X_add_number < 0)
10031 imm_expr.X_add_number = -imm_expr.X_add_number;
10032 macro_build (&imm_expr, HAVE_32BIT_GPRS ? "addiu" : "daddiu",
10033 "t,r,j", dreg, sreg, BFD_RELOC_LO16);
10035 else if (CPU_HAS_SEQ (mips_opts.arch))
10038 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
10039 macro_build (NULL, "sne", "d,v,t", dreg, sreg, AT);
10044 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
10045 macro_build (NULL, "xor", "d,v,t", dreg, sreg, AT);
10048 macro_build (NULL, "sltu", "d,v,t", dreg, 0, dreg);
10063 if (!mips_opts.micromips)
10065 if (imm_expr.X_op == O_constant
10066 && imm_expr.X_add_number > -0x200
10067 && imm_expr.X_add_number <= 0x200)
10069 macro_build (NULL, s, "t,r,.", dreg, sreg, -imm_expr.X_add_number);
10078 if (imm_expr.X_op == O_constant
10079 && imm_expr.X_add_number > -0x8000
10080 && imm_expr.X_add_number <= 0x8000)
10082 imm_expr.X_add_number = -imm_expr.X_add_number;
10083 macro_build (&imm_expr, s, "t,r,j", dreg, sreg, BFD_RELOC_LO16);
10088 load_register (AT, &imm_expr, dbl);
10089 macro_build (NULL, s2, "d,v,t", dreg, sreg, AT);
10111 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
10112 macro_build (NULL, s, "s,t", sreg, AT);
10117 gas_assert (!mips_opts.micromips);
10118 gas_assert (mips_opts.isa == ISA_MIPS1);
10120 sreg = (ip->insn_opcode >> 11) & 0x1f; /* floating reg */
10121 dreg = (ip->insn_opcode >> 06) & 0x1f; /* floating reg */
10124 * Is the double cfc1 instruction a bug in the mips assembler;
10125 * or is there a reason for it?
10127 start_noreorder ();
10128 macro_build (NULL, "cfc1", "t,G", treg, RA);
10129 macro_build (NULL, "cfc1", "t,G", treg, RA);
10130 macro_build (NULL, "nop", "");
10131 expr1.X_add_number = 3;
10132 macro_build (&expr1, "ori", "t,r,i", AT, treg, BFD_RELOC_LO16);
10133 expr1.X_add_number = 2;
10134 macro_build (&expr1, "xori", "t,r,i", AT, AT, BFD_RELOC_LO16);
10135 macro_build (NULL, "ctc1", "t,G", AT, RA);
10136 macro_build (NULL, "nop", "");
10137 macro_build (NULL, mask == M_TRUNCWD ? "cvt.w.d" : "cvt.w.s", "D,S",
10139 macro_build (NULL, "ctc1", "t,G", treg, RA);
10140 macro_build (NULL, "nop", "");
10163 offbits = (mips_opts.micromips ? 12 : 16);
10171 offbits = (mips_opts.micromips ? 12 : 16);
10187 offbits = (mips_opts.micromips ? 12 : 16);
10196 offbits = (mips_opts.micromips ? 12 : 16);
10201 if (!ab && offset_expr.X_add_number >= 0x8000 - off)
10202 as_bad (_("Operand overflow"));
10205 expr1.X_add_number = 0;
10210 load_address (tempreg, ep, &used_at);
10212 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
10213 tempreg, tempreg, breg);
10218 else if (offbits == 12
10219 && (offset_expr.X_op != O_constant
10220 || !IS_SEXT_12BIT_NUM (offset_expr.X_add_number)
10221 || !IS_SEXT_12BIT_NUM (offset_expr.X_add_number + off)))
10225 macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", tempreg, breg,
10226 -1, offset_reloc[0], offset_reloc[1], offset_reloc[2]);
10231 else if (!ust && treg == breg)
10242 if (!target_big_endian)
10243 ep->X_add_number += off;
10245 macro_build (ep, s, "t,o(b)", tempreg, BFD_RELOC_LO16, breg);
10247 macro_build (NULL, s, "t,~(b)",
10248 tempreg, (unsigned long) ep->X_add_number, breg);
10250 if (!target_big_endian)
10251 ep->X_add_number -= off;
10253 ep->X_add_number += off;
10255 macro_build (ep, s2, "t,o(b)", tempreg, BFD_RELOC_LO16, breg);
10257 macro_build (NULL, s2, "t,~(b)",
10258 tempreg, (unsigned long) ep->X_add_number, breg);
10260 /* If necessary, move the result in tempreg to the final destination. */
10261 if (!ust && treg != tempreg)
10263 /* Protect second load's delay slot. */
10265 move_register (treg, tempreg);
10271 if (target_big_endian == ust)
10272 ep->X_add_number += off;
10273 tempreg = ust || ab ? treg : AT;
10274 macro_build (ep, s, "t,o(b)", tempreg, BFD_RELOC_LO16, breg);
10276 /* For halfword transfers we need a temporary register to shuffle
10277 bytes. Unfortunately for M_USH_A we have none available before
10278 the next store as AT holds the base address. We deal with this
10279 case by clobbering TREG and then restoring it as with ULH. */
10280 tempreg = ust == ab ? treg : AT;
10282 macro_build (NULL, "srl", SHFT_FMT, tempreg, treg, 8);
10284 if (target_big_endian == ust)
10285 ep->X_add_number -= off;
10287 ep->X_add_number += off;
10288 macro_build (ep, s2, "t,o(b)", tempreg, BFD_RELOC_LO16, breg);
10290 /* For M_USH_A re-retrieve the LSB. */
10293 if (target_big_endian)
10294 ep->X_add_number += off;
10296 ep->X_add_number -= off;
10297 macro_build (&expr1, "lbu", "t,o(b)", AT, BFD_RELOC_LO16, AT);
10299 /* For ULH and M_USH_A OR the LSB in. */
10302 tempreg = !ab ? AT : treg;
10303 macro_build (NULL, "sll", SHFT_FMT, tempreg, tempreg, 8);
10304 macro_build (NULL, "or", "d,v,t", treg, treg, AT);
10309 /* FIXME: Check if this is one of the itbl macros, since they
10310 are added dynamically. */
10311 as_bad (_("Macro %s not implemented yet"), ip->insn_mo->name);
10314 if (!mips_opts.at && used_at)
10315 as_bad (_("Macro used $at after \".set noat\""));
10318 /* Implement macros in mips16 mode. */
10321 mips16_macro (struct mips_cl_insn *ip)
10324 int xreg, yreg, zreg, tmp;
10327 const char *s, *s2, *s3;
10329 mask = ip->insn_mo->mask;
10331 xreg = MIPS16_EXTRACT_OPERAND (RX, *ip);
10332 yreg = MIPS16_EXTRACT_OPERAND (RY, *ip);
10333 zreg = MIPS16_EXTRACT_OPERAND (RZ, *ip);
10335 expr1.X_op = O_constant;
10336 expr1.X_op_symbol = NULL;
10337 expr1.X_add_symbol = NULL;
10338 expr1.X_add_number = 1;
10357 start_noreorder ();
10358 macro_build (NULL, dbl ? "ddiv" : "div", "0,x,y", xreg, yreg);
10359 expr1.X_add_number = 2;
10360 macro_build (&expr1, "bnez", "x,p", yreg);
10361 macro_build (NULL, "break", "6", 7);
10363 /* FIXME: The normal code checks for of -1 / -0x80000000 here,
10364 since that causes an overflow. We should do that as well,
10365 but I don't see how to do the comparisons without a temporary
10368 macro_build (NULL, s, "x", zreg);
10387 start_noreorder ();
10388 macro_build (NULL, s, "0,x,y", xreg, yreg);
10389 expr1.X_add_number = 2;
10390 macro_build (&expr1, "bnez", "x,p", yreg);
10391 macro_build (NULL, "break", "6", 7);
10393 macro_build (NULL, s2, "x", zreg);
10399 macro_build (NULL, dbl ? "dmultu" : "multu", "x,y", xreg, yreg);
10400 macro_build (NULL, "mflo", "x", zreg);
10408 if (imm_expr.X_op != O_constant)
10409 as_bad (_("Unsupported large constant"));
10410 imm_expr.X_add_number = -imm_expr.X_add_number;
10411 macro_build (&imm_expr, dbl ? "daddiu" : "addiu", "y,x,4", yreg, xreg);
10415 if (imm_expr.X_op != O_constant)
10416 as_bad (_("Unsupported large constant"));
10417 imm_expr.X_add_number = -imm_expr.X_add_number;
10418 macro_build (&imm_expr, "addiu", "x,k", xreg);
10422 if (imm_expr.X_op != O_constant)
10423 as_bad (_("Unsupported large constant"));
10424 imm_expr.X_add_number = -imm_expr.X_add_number;
10425 macro_build (&imm_expr, "daddiu", "y,j", yreg);
10447 goto do_reverse_branch;
10451 goto do_reverse_branch;
10463 goto do_reverse_branch;
10474 macro_build (NULL, s, "x,y", xreg, yreg);
10475 macro_build (&offset_expr, s2, "p");
10502 goto do_addone_branch_i;
10507 goto do_addone_branch_i;
10522 goto do_addone_branch_i;
10528 do_addone_branch_i:
10529 if (imm_expr.X_op != O_constant)
10530 as_bad (_("Unsupported large constant"));
10531 ++imm_expr.X_add_number;
10534 macro_build (&imm_expr, s, s3, xreg);
10535 macro_build (&offset_expr, s2, "p");
10539 expr1.X_add_number = 0;
10540 macro_build (&expr1, "slti", "x,8", yreg);
10542 move_register (xreg, yreg);
10543 expr1.X_add_number = 2;
10544 macro_build (&expr1, "bteqz", "p");
10545 macro_build (NULL, "neg", "x,w", xreg, xreg);
10549 /* For consistency checking, verify that all bits are specified either
10550 by the match/mask part of the instruction definition, or by the
10553 validate_mips_insn (const struct mips_opcode *opc)
10555 const char *p = opc->args;
10557 unsigned long used_bits = opc->mask;
10559 if ((used_bits & opc->match) != opc->match)
10561 as_bad (_("internal: bad mips opcode (mask error): %s %s"),
10562 opc->name, opc->args);
10565 #define USE_BITS(mask,shift) (used_bits |= ((mask) << (shift)))
10575 case '1': USE_BITS (OP_MASK_UDI1, OP_SH_UDI1); break;
10576 case '2': USE_BITS (OP_MASK_UDI2, OP_SH_UDI2); break;
10577 case '3': USE_BITS (OP_MASK_UDI3, OP_SH_UDI3); break;
10578 case '4': USE_BITS (OP_MASK_UDI4, OP_SH_UDI4); break;
10579 case 'A': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
10580 case 'B': USE_BITS (OP_MASK_INSMSB, OP_SH_INSMSB); break;
10581 case 'C': USE_BITS (OP_MASK_EXTMSBD, OP_SH_EXTMSBD); break;
10582 case 'D': USE_BITS (OP_MASK_RD, OP_SH_RD);
10583 USE_BITS (OP_MASK_SEL, OP_SH_SEL); break;
10584 case 'E': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
10585 case 'F': USE_BITS (OP_MASK_INSMSB, OP_SH_INSMSB); break;
10586 case 'G': USE_BITS (OP_MASK_EXTMSBD, OP_SH_EXTMSBD); break;
10587 case 'H': USE_BITS (OP_MASK_EXTMSBD, OP_SH_EXTMSBD); break;
10589 case 'J': USE_BITS (OP_MASK_CODE10, OP_SH_CODE10); break;
10590 case 't': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
10591 case 'T': USE_BITS (OP_MASK_RT, OP_SH_RT);
10592 USE_BITS (OP_MASK_SEL, OP_SH_SEL); break;
10593 case 'x': USE_BITS (OP_MASK_BBITIND, OP_SH_BBITIND); break;
10594 case 'X': USE_BITS (OP_MASK_BBITIND, OP_SH_BBITIND); break;
10595 case 'p': USE_BITS (OP_MASK_CINSPOS, OP_SH_CINSPOS); break;
10596 case 'P': USE_BITS (OP_MASK_CINSPOS, OP_SH_CINSPOS); break;
10597 case 'Q': USE_BITS (OP_MASK_SEQI, OP_SH_SEQI); break;
10598 case 's': USE_BITS (OP_MASK_CINSLM1, OP_SH_CINSLM1); break;
10599 case 'S': USE_BITS (OP_MASK_CINSLM1, OP_SH_CINSLM1); break;
10600 case 'z': USE_BITS (OP_MASK_RZ, OP_SH_RZ); break;
10601 case 'Z': USE_BITS (OP_MASK_FZ, OP_SH_FZ); break;
10602 case 'a': USE_BITS (OP_MASK_OFFSET_A, OP_SH_OFFSET_A); break;
10603 case 'b': USE_BITS (OP_MASK_OFFSET_B, OP_SH_OFFSET_B); break;
10604 case 'c': USE_BITS (OP_MASK_OFFSET_C, OP_SH_OFFSET_C); break;
10605 case 'j': USE_BITS (OP_MASK_EVAOFFSET, OP_SH_EVAOFFSET); break;
10608 as_bad (_("internal: bad mips opcode (unknown extension operand type `+%c'): %s %s"),
10609 c, opc->name, opc->args);
10613 case '<': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
10614 case '>': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
10616 case 'B': USE_BITS (OP_MASK_CODE20, OP_SH_CODE20); break;
10617 case 'C': USE_BITS (OP_MASK_COPZ, OP_SH_COPZ); break;
10618 case 'D': USE_BITS (OP_MASK_FD, OP_SH_FD); break;
10619 case 'E': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
10621 case 'G': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
10622 case 'H': USE_BITS (OP_MASK_SEL, OP_SH_SEL); break;
10624 case 'J': USE_BITS (OP_MASK_CODE19, OP_SH_CODE19); break;
10625 case 'K': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
10627 case 'M': USE_BITS (OP_MASK_CCC, OP_SH_CCC); break;
10628 case 'N': USE_BITS (OP_MASK_BCC, OP_SH_BCC); break;
10629 case 'O': USE_BITS (OP_MASK_ALN, OP_SH_ALN); break;
10630 case 'Q': USE_BITS (OP_MASK_VSEL, OP_SH_VSEL);
10631 USE_BITS (OP_MASK_FT, OP_SH_FT); break;
10632 case 'R': USE_BITS (OP_MASK_FR, OP_SH_FR); break;
10633 case 'S': USE_BITS (OP_MASK_FS, OP_SH_FS); break;
10634 case 'T': USE_BITS (OP_MASK_FT, OP_SH_FT); break;
10635 case 'V': USE_BITS (OP_MASK_FS, OP_SH_FS); break;
10636 case 'W': USE_BITS (OP_MASK_FT, OP_SH_FT); break;
10637 case 'X': USE_BITS (OP_MASK_FD, OP_SH_FD); break;
10638 case 'Y': USE_BITS (OP_MASK_FS, OP_SH_FS); break;
10639 case 'Z': USE_BITS (OP_MASK_FT, OP_SH_FT); break;
10640 case 'a': USE_BITS (OP_MASK_TARGET, OP_SH_TARGET); break;
10641 case 'b': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
10642 case 'c': USE_BITS (OP_MASK_CODE, OP_SH_CODE); break;
10643 case 'd': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
10645 case 'h': USE_BITS (OP_MASK_PREFX, OP_SH_PREFX); break;
10646 case 'i': USE_BITS (OP_MASK_IMMEDIATE, OP_SH_IMMEDIATE); break;
10647 case 'j': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
10648 case 'k': USE_BITS (OP_MASK_CACHE, OP_SH_CACHE); break;
10650 case 'o': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
10651 case 'p': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
10652 case 'q': USE_BITS (OP_MASK_CODE2, OP_SH_CODE2); break;
10653 case 'r': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
10654 case 's': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
10655 case 't': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
10656 case 'u': USE_BITS (OP_MASK_IMMEDIATE, OP_SH_IMMEDIATE); break;
10657 case 'v': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
10658 case 'w': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
10661 case 'P': USE_BITS (OP_MASK_PERFREG, OP_SH_PERFREG); break;
10662 case 'U': USE_BITS (OP_MASK_RD, OP_SH_RD);
10663 USE_BITS (OP_MASK_RT, OP_SH_RT); break;
10664 case 'e': USE_BITS (OP_MASK_VECBYTE, OP_SH_VECBYTE); break;
10665 case '%': USE_BITS (OP_MASK_VECALIGN, OP_SH_VECALIGN); break;
10668 case '1': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
10669 case '2': USE_BITS (OP_MASK_BP, OP_SH_BP); break;
10670 case '3': USE_BITS (OP_MASK_SA3, OP_SH_SA3); break;
10671 case '4': USE_BITS (OP_MASK_SA4, OP_SH_SA4); break;
10672 case '5': USE_BITS (OP_MASK_IMM8, OP_SH_IMM8); break;
10673 case '6': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
10674 case '7': USE_BITS (OP_MASK_DSPACC, OP_SH_DSPACC); break;
10675 case '8': USE_BITS (OP_MASK_WRDSP, OP_SH_WRDSP); break;
10676 case '9': USE_BITS (OP_MASK_DSPACC_S, OP_SH_DSPACC_S);break;
10677 case '0': USE_BITS (OP_MASK_DSPSFT, OP_SH_DSPSFT); break;
10678 case '\'': USE_BITS (OP_MASK_RDDSP, OP_SH_RDDSP); break;
10679 case ':': USE_BITS (OP_MASK_DSPSFT_7, OP_SH_DSPSFT_7);break;
10680 case '@': USE_BITS (OP_MASK_IMM10, OP_SH_IMM10); break;
10681 case '!': USE_BITS (OP_MASK_MT_U, OP_SH_MT_U); break;
10682 case '$': USE_BITS (OP_MASK_MT_H, OP_SH_MT_H); break;
10683 case '*': USE_BITS (OP_MASK_MTACC_T, OP_SH_MTACC_T); break;
10684 case '&': USE_BITS (OP_MASK_MTACC_D, OP_SH_MTACC_D); break;
10685 case '\\': USE_BITS (OP_MASK_3BITPOS, OP_SH_3BITPOS); break;
10686 case '~': USE_BITS (OP_MASK_OFFSET12, OP_SH_OFFSET12); break;
10687 case 'g': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
10689 as_bad (_("internal: bad mips opcode (unknown operand type `%c'): %s %s"),
10690 c, opc->name, opc->args);
10694 if (used_bits != 0xffffffff)
10696 as_bad (_("internal: bad mips opcode (bits 0x%lx undefined): %s %s"),
10697 ~used_bits & 0xffffffff, opc->name, opc->args);
10703 /* For consistency checking, verify that the length implied matches the
10704 major opcode and that all bits are specified either by the match/mask
10705 part of the instruction definition, or by the operand list. */
10708 validate_micromips_insn (const struct mips_opcode *opc)
10710 unsigned long match = opc->match;
10711 unsigned long mask = opc->mask;
10712 const char *p = opc->args;
10713 unsigned long insn_bits;
10714 unsigned long used_bits;
10715 unsigned long major;
10716 unsigned int length;
10720 if ((mask & match) != match)
10722 as_bad (_("Internal error: bad microMIPS opcode (mask error): %s %s"),
10723 opc->name, opc->args);
10726 length = micromips_insn_length (opc);
10727 if (length != 2 && length != 4)
10729 as_bad (_("Internal error: bad microMIPS opcode (incorrect length: %u): "
10730 "%s %s"), length, opc->name, opc->args);
10733 major = match >> (10 + 8 * (length - 2));
10734 if ((length == 2 && (major & 7) != 1 && (major & 6) != 2)
10735 || (length == 4 && (major & 7) != 0 && (major & 4) != 4))
10737 as_bad (_("Internal error: bad microMIPS opcode "
10738 "(opcode/length mismatch): %s %s"), opc->name, opc->args);
10742 /* Shift piecewise to avoid an overflow where unsigned long is 32-bit. */
10743 insn_bits = 1 << 4 * length;
10744 insn_bits <<= 4 * length;
10747 #define USE_BITS(field) \
10748 (used_bits |= MICROMIPSOP_MASK_##field << MICROMIPSOP_SH_##field)
10759 case 'A': USE_BITS (EXTLSB); break;
10760 case 'B': USE_BITS (INSMSB); break;
10761 case 'C': USE_BITS (EXTMSBD); break;
10762 case 'D': USE_BITS (RS); USE_BITS (SEL); break;
10763 case 'E': USE_BITS (EXTLSB); break;
10764 case 'F': USE_BITS (INSMSB); break;
10765 case 'G': USE_BITS (EXTMSBD); break;
10766 case 'H': USE_BITS (EXTMSBD); break;
10767 case 'j': USE_BITS (EVAOFFSET); break;
10769 as_bad (_("Internal error: bad mips opcode "
10770 "(unknown extension operand type `%c%c'): %s %s"),
10771 e, c, opc->name, opc->args);
10779 case 'A': USE_BITS (IMMA); break;
10780 case 'B': USE_BITS (IMMB); break;
10781 case 'C': USE_BITS (IMMC); break;
10782 case 'D': USE_BITS (IMMD); break;
10783 case 'E': USE_BITS (IMME); break;
10784 case 'F': USE_BITS (IMMF); break;
10785 case 'G': USE_BITS (IMMG); break;
10786 case 'H': USE_BITS (IMMH); break;
10787 case 'I': USE_BITS (IMMI); break;
10788 case 'J': USE_BITS (IMMJ); break;
10789 case 'L': USE_BITS (IMML); break;
10790 case 'M': USE_BITS (IMMM); break;
10791 case 'N': USE_BITS (IMMN); break;
10792 case 'O': USE_BITS (IMMO); break;
10793 case 'P': USE_BITS (IMMP); break;
10794 case 'Q': USE_BITS (IMMQ); break;
10795 case 'U': USE_BITS (IMMU); break;
10796 case 'W': USE_BITS (IMMW); break;
10797 case 'X': USE_BITS (IMMX); break;
10798 case 'Y': USE_BITS (IMMY); break;
10801 case 'b': USE_BITS (MB); break;
10802 case 'c': USE_BITS (MC); break;
10803 case 'd': USE_BITS (MD); break;
10804 case 'e': USE_BITS (ME); break;
10805 case 'f': USE_BITS (MF); break;
10806 case 'g': USE_BITS (MG); break;
10807 case 'h': USE_BITS (MH); break;
10808 case 'i': USE_BITS (MI); break;
10809 case 'j': USE_BITS (MJ); break;
10810 case 'l': USE_BITS (ML); break;
10811 case 'm': USE_BITS (MM); break;
10812 case 'n': USE_BITS (MN); break;
10813 case 'p': USE_BITS (MP); break;
10814 case 'q': USE_BITS (MQ); break;
10822 as_bad (_("Internal error: bad mips opcode "
10823 "(unknown extension operand type `%c%c'): %s %s"),
10824 e, c, opc->name, opc->args);
10828 case '.': USE_BITS (OFFSET10); break;
10829 case '1': USE_BITS (STYPE); break;
10830 case '2': USE_BITS (BP); break;
10831 case '3': USE_BITS (SA3); break;
10832 case '4': USE_BITS (SA4); break;
10833 case '5': USE_BITS (IMM8); break;
10834 case '6': USE_BITS (RS); break;
10835 case '7': USE_BITS (DSPACC); break;
10836 case '8': USE_BITS (WRDSP); break;
10837 case '0': USE_BITS (DSPSFT); break;
10838 case '<': USE_BITS (SHAMT); break;
10839 case '>': USE_BITS (SHAMT); break;
10840 case '@': USE_BITS (IMM10); break;
10841 case 'B': USE_BITS (CODE10); break;
10842 case 'C': USE_BITS (COPZ); break;
10843 case 'D': USE_BITS (FD); break;
10844 case 'E': USE_BITS (RT); break;
10845 case 'G': USE_BITS (RS); break;
10846 case 'H': USE_BITS (SEL); break;
10847 case 'K': USE_BITS (RS); break;
10848 case 'M': USE_BITS (CCC); break;
10849 case 'N': USE_BITS (BCC); break;
10850 case 'R': USE_BITS (FR); break;
10851 case 'S': USE_BITS (FS); break;
10852 case 'T': USE_BITS (FT); break;
10853 case 'V': USE_BITS (FS); break;
10854 case '\\': USE_BITS (3BITPOS); break;
10855 case '^': USE_BITS (RD); break;
10856 case 'a': USE_BITS (TARGET); break;
10857 case 'b': USE_BITS (RS); break;
10858 case 'c': USE_BITS (CODE); break;
10859 case 'd': USE_BITS (RD); break;
10860 case 'h': USE_BITS (PREFX); break;
10861 case 'i': USE_BITS (IMMEDIATE); break;
10862 case 'j': USE_BITS (DELTA); break;
10863 case 'k': USE_BITS (CACHE); break;
10864 case 'n': USE_BITS (RT); break;
10865 case 'o': USE_BITS (DELTA); break;
10866 case 'p': USE_BITS (DELTA); break;
10867 case 'q': USE_BITS (CODE2); break;
10868 case 'r': USE_BITS (RS); break;
10869 case 's': USE_BITS (RS); break;
10870 case 't': USE_BITS (RT); break;
10871 case 'u': USE_BITS (IMMEDIATE); break;
10872 case 'v': USE_BITS (RS); break;
10873 case 'w': USE_BITS (RT); break;
10874 case 'y': USE_BITS (RS3); break;
10876 case '|': USE_BITS (TRAP); break;
10877 case '~': USE_BITS (OFFSET12); break;
10879 as_bad (_("Internal error: bad microMIPS opcode "
10880 "(unknown operand type `%c'): %s %s"),
10881 c, opc->name, opc->args);
10885 if (used_bits != insn_bits)
10887 if (~used_bits & insn_bits)
10888 as_bad (_("Internal error: bad microMIPS opcode "
10889 "(bits 0x%lx undefined): %s %s"),
10890 ~used_bits & insn_bits, opc->name, opc->args);
10891 if (used_bits & ~insn_bits)
10892 as_bad (_("Internal error: bad microMIPS opcode "
10893 "(bits 0x%lx defined): %s %s"),
10894 used_bits & ~insn_bits, opc->name, opc->args);
10900 /* UDI immediates. */
10901 struct mips_immed {
10903 unsigned int shift;
10904 unsigned long mask;
10908 static const struct mips_immed mips_immed[] = {
10909 { '1', OP_SH_UDI1, OP_MASK_UDI1, 0},
10910 { '2', OP_SH_UDI2, OP_MASK_UDI2, 0},
10911 { '3', OP_SH_UDI3, OP_MASK_UDI3, 0},
10912 { '4', OP_SH_UDI4, OP_MASK_UDI4, 0},
10916 /* Check whether an odd floating-point register is allowed. */
10918 mips_oddfpreg_ok (const struct mips_opcode *insn, int argnum)
10920 const char *s = insn->name;
10922 if (insn->pinfo == INSN_MACRO)
10923 /* Let a macro pass, we'll catch it later when it is expanded. */
10926 if (ISA_HAS_ODD_SINGLE_FPR (mips_opts.isa) || (mips_opts.arch == CPU_R5900))
10928 /* Allow odd registers for single-precision ops. */
10929 switch (insn->pinfo & (FP_S | FP_D))
10933 return 1; /* both single precision - ok */
10935 return 0; /* both double precision - fail */
10940 /* Cvt.w.x and cvt.x.w allow an odd register for a 'w' or 's' operand. */
10941 s = strchr (insn->name, '.');
10943 s = s != NULL ? strchr (s + 1, '.') : NULL;
10944 return (s != NULL && (s[1] == 'w' || s[1] == 's'));
10947 /* Single-precision coprocessor loads and moves are OK too. */
10948 if ((insn->pinfo & FP_S)
10949 && (insn->pinfo & (INSN_COPROC_MEMORY_DELAY | INSN_STORE_MEMORY
10950 | INSN_LOAD_COPROC_DELAY | INSN_COPROC_MOVE_DELAY)))
10956 /* Check if EXPR is a constant between MIN (inclusive) and MAX (exclusive)
10957 taking bits from BIT up. */
10959 expr_const_in_range (expressionS *ep, offsetT min, offsetT max, int bit)
10961 return (ep->X_op == O_constant
10962 && (ep->X_add_number & ((1 << bit) - 1)) == 0
10963 && ep->X_add_number >= min << bit
10964 && ep->X_add_number < max << bit);
10967 /* This routine assembles an instruction into its binary format. As a
10968 side effect, it sets one of the global variables imm_reloc or
10969 offset_reloc to the type of relocation to do if one of the operands
10970 is an address expression. */
10973 mips_ip (char *str, struct mips_cl_insn *ip)
10975 bfd_boolean wrong_delay_slot_insns = FALSE;
10976 bfd_boolean need_delay_slot_ok = TRUE;
10977 struct mips_opcode *firstinsn = NULL;
10978 const struct mips_opcode *past;
10979 struct hash_control *hash;
10983 struct mips_opcode *insn;
10985 unsigned int regno;
10986 unsigned int lastregno;
10987 unsigned int destregno = 0;
10988 unsigned int lastpos = 0;
10989 unsigned int limlo, limhi;
10992 offsetT min_range, max_range;
10996 unsigned int rtype;
11002 if (mips_opts.micromips)
11004 hash = micromips_op_hash;
11005 past = µmips_opcodes[bfd_micromips_num_opcodes];
11010 past = &mips_opcodes[NUMOPCODES];
11012 forced_insn_length = 0;
11015 /* We first try to match an instruction up to a space or to the end. */
11016 for (end = 0; str[end] != '\0' && !ISSPACE (str[end]); end++)
11019 /* Make a copy of the instruction so that we can fiddle with it. */
11020 name = alloca (end + 1);
11021 memcpy (name, str, end);
11026 insn = (struct mips_opcode *) hash_find (hash, name);
11028 if (insn != NULL || !mips_opts.micromips)
11030 if (forced_insn_length)
11033 /* See if there's an instruction size override suffix,
11034 either `16' or `32', at the end of the mnemonic proper,
11035 that defines the operation, i.e. before the first `.'
11036 character if any. Strip it and retry. */
11037 dot = strchr (name, '.');
11038 opend = dot != NULL ? dot - name : end;
11041 if (name[opend - 2] == '1' && name[opend - 1] == '6')
11042 forced_insn_length = 2;
11043 else if (name[opend - 2] == '3' && name[opend - 1] == '2')
11044 forced_insn_length = 4;
11047 memcpy (name + opend - 2, name + opend, end - opend + 1);
11051 insn_error = _("Unrecognized opcode");
11055 /* For microMIPS instructions placed in a fixed-length branch delay slot
11056 we make up to two passes over the relevant fragment of the opcode
11057 table. First we try instructions that meet the delay slot's length
11058 requirement. If none matched, then we retry with the remaining ones
11059 and if one matches, then we use it and then issue an appropriate
11060 warning later on. */
11061 argsStart = s = str + end;
11064 bfd_boolean delay_slot_ok;
11065 bfd_boolean size_ok;
11068 gas_assert (strcmp (insn->name, name) == 0);
11070 ok = is_opcode_valid (insn);
11071 size_ok = is_size_valid (insn);
11072 delay_slot_ok = is_delay_slot_valid (insn);
11073 if (!delay_slot_ok && !wrong_delay_slot_insns)
11076 wrong_delay_slot_insns = TRUE;
11078 if (!ok || !size_ok || delay_slot_ok != need_delay_slot_ok)
11080 static char buf[256];
11082 if (insn + 1 < past && strcmp (insn->name, insn[1].name) == 0)
11087 if (wrong_delay_slot_insns && need_delay_slot_ok)
11089 gas_assert (firstinsn);
11090 need_delay_slot_ok = FALSE;
11100 sprintf (buf, _("Opcode not supported on this processor: %s (%s)"),
11101 mips_cpu_info_from_arch (mips_opts.arch)->name,
11102 mips_cpu_info_from_isa (mips_opts.isa)->name);
11104 sprintf (buf, _("Unrecognized %u-bit version of microMIPS opcode"),
11105 8 * forced_insn_length);
11111 create_insn (ip, insn);
11114 lastregno = 0xffffffff;
11115 for (args = insn->args;; ++args)
11119 s += strspn (s, " \t");
11123 case '\0': /* end of args */
11129 /* DSP 2-bit unsigned immediate in bit 11 (for standard MIPS
11130 code) or 14 (for microMIPS code). */
11131 my_getExpression (&imm_expr, s);
11132 check_absolute_expr (ip, &imm_expr);
11133 if ((unsigned long) imm_expr.X_add_number != 1
11134 && (unsigned long) imm_expr.X_add_number != 3)
11136 as_bad (_("BALIGN immediate not 1 or 3 (%lu)"),
11137 (unsigned long) imm_expr.X_add_number);
11139 INSERT_OPERAND (mips_opts.micromips,
11140 BP, *ip, imm_expr.X_add_number);
11141 imm_expr.X_op = O_absent;
11146 /* DSP 3-bit unsigned immediate in bit 13 (for standard MIPS
11147 code) or 21 (for microMIPS code). */
11149 unsigned long mask = (mips_opts.micromips
11150 ? MICROMIPSOP_MASK_SA3 : OP_MASK_SA3);
11152 my_getExpression (&imm_expr, s);
11153 check_absolute_expr (ip, &imm_expr);
11154 if ((unsigned long) imm_expr.X_add_number > mask)
11155 as_bad (_("DSP immediate not in range 0..%lu (%lu)"),
11156 mask, (unsigned long) imm_expr.X_add_number);
11157 INSERT_OPERAND (mips_opts.micromips,
11158 SA3, *ip, imm_expr.X_add_number);
11159 imm_expr.X_op = O_absent;
11165 /* DSP 4-bit unsigned immediate in bit 12 (for standard MIPS
11166 code) or 21 (for microMIPS code). */
11168 unsigned long mask = (mips_opts.micromips
11169 ? MICROMIPSOP_MASK_SA4 : OP_MASK_SA4);
11171 my_getExpression (&imm_expr, s);
11172 check_absolute_expr (ip, &imm_expr);
11173 if ((unsigned long) imm_expr.X_add_number > mask)
11174 as_bad (_("DSP immediate not in range 0..%lu (%lu)"),
11175 mask, (unsigned long) imm_expr.X_add_number);
11176 INSERT_OPERAND (mips_opts.micromips,
11177 SA4, *ip, imm_expr.X_add_number);
11178 imm_expr.X_op = O_absent;
11184 /* DSP 8-bit unsigned immediate in bit 13 (for standard MIPS
11185 code) or 16 (for microMIPS code). */
11187 unsigned long mask = (mips_opts.micromips
11188 ? MICROMIPSOP_MASK_IMM8 : OP_MASK_IMM8);
11190 my_getExpression (&imm_expr, s);
11191 check_absolute_expr (ip, &imm_expr);
11192 if ((unsigned long) imm_expr.X_add_number > mask)
11193 as_bad (_("DSP immediate not in range 0..%lu (%lu)"),
11194 mask, (unsigned long) imm_expr.X_add_number);
11195 INSERT_OPERAND (mips_opts.micromips,
11196 IMM8, *ip, imm_expr.X_add_number);
11197 imm_expr.X_op = O_absent;
11203 /* DSP 5-bit unsigned immediate in bit 16 (for standard MIPS
11204 code) or 21 (for microMIPS code). */
11206 unsigned long mask = (mips_opts.micromips
11207 ? MICROMIPSOP_MASK_RS : OP_MASK_RS);
11209 my_getExpression (&imm_expr, s);
11210 check_absolute_expr (ip, &imm_expr);
11211 if ((unsigned long) imm_expr.X_add_number > mask)
11212 as_bad (_("DSP immediate not in range 0..%lu (%lu)"),
11213 mask, (unsigned long) imm_expr.X_add_number);
11214 INSERT_OPERAND (mips_opts.micromips,
11215 RS, *ip, imm_expr.X_add_number);
11216 imm_expr.X_op = O_absent;
11221 case '7': /* Four DSP accumulators in bits 11,12. */
11222 if (s[0] == '$' && s[1] == 'a' && s[2] == 'c'
11223 && s[3] >= '0' && s[3] <= '3')
11225 regno = s[3] - '0';
11227 INSERT_OPERAND (mips_opts.micromips, DSPACC, *ip, regno);
11231 as_bad (_("Invalid dsp acc register"));
11235 /* DSP 6-bit unsigned immediate in bit 11 (for standard MIPS
11236 code) or 14 (for microMIPS code). */
11238 unsigned long mask = (mips_opts.micromips
11239 ? MICROMIPSOP_MASK_WRDSP
11242 my_getExpression (&imm_expr, s);
11243 check_absolute_expr (ip, &imm_expr);
11244 if ((unsigned long) imm_expr.X_add_number > mask)
11245 as_bad (_("DSP immediate not in range 0..%lu (%lu)"),
11246 mask, (unsigned long) imm_expr.X_add_number);
11247 INSERT_OPERAND (mips_opts.micromips,
11248 WRDSP, *ip, imm_expr.X_add_number);
11249 imm_expr.X_op = O_absent;
11254 case '9': /* Four DSP accumulators in bits 21,22. */
11255 gas_assert (!mips_opts.micromips);
11256 if (s[0] == '$' && s[1] == 'a' && s[2] == 'c'
11257 && s[3] >= '0' && s[3] <= '3')
11259 regno = s[3] - '0';
11261 INSERT_OPERAND (0, DSPACC_S, *ip, regno);
11265 as_bad (_("Invalid dsp acc register"));
11269 /* DSP 6-bit signed immediate in bit 16 (for standard MIPS
11270 code) or 20 (for microMIPS code). */
11272 long mask = (mips_opts.micromips
11273 ? MICROMIPSOP_MASK_DSPSFT : OP_MASK_DSPSFT);
11275 my_getExpression (&imm_expr, s);
11276 check_absolute_expr (ip, &imm_expr);
11277 min_range = -((mask + 1) >> 1);
11278 max_range = ((mask + 1) >> 1) - 1;
11279 if (imm_expr.X_add_number < min_range
11280 || imm_expr.X_add_number > max_range)
11281 as_bad (_("DSP immediate not in range %ld..%ld (%ld)"),
11282 (long) min_range, (long) max_range,
11283 (long) imm_expr.X_add_number);
11284 INSERT_OPERAND (mips_opts.micromips,
11285 DSPSFT, *ip, imm_expr.X_add_number);
11286 imm_expr.X_op = O_absent;
11291 case '\'': /* DSP 6-bit unsigned immediate in bit 16. */
11292 gas_assert (!mips_opts.micromips);
11293 my_getExpression (&imm_expr, s);
11294 check_absolute_expr (ip, &imm_expr);
11295 if (imm_expr.X_add_number & ~OP_MASK_RDDSP)
11297 as_bad (_("DSP immediate not in range 0..%d (%lu)"),
11299 (unsigned long) imm_expr.X_add_number);
11301 INSERT_OPERAND (0, RDDSP, *ip, imm_expr.X_add_number);
11302 imm_expr.X_op = O_absent;
11306 case ':': /* DSP 7-bit signed immediate in bit 19. */
11307 gas_assert (!mips_opts.micromips);
11308 my_getExpression (&imm_expr, s);
11309 check_absolute_expr (ip, &imm_expr);
11310 min_range = -((OP_MASK_DSPSFT_7 + 1) >> 1);
11311 max_range = ((OP_MASK_DSPSFT_7 + 1) >> 1) - 1;
11312 if (imm_expr.X_add_number < min_range ||
11313 imm_expr.X_add_number > max_range)
11315 as_bad (_("DSP immediate not in range %ld..%ld (%ld)"),
11316 (long) min_range, (long) max_range,
11317 (long) imm_expr.X_add_number);
11319 INSERT_OPERAND (0, DSPSFT_7, *ip, imm_expr.X_add_number);
11320 imm_expr.X_op = O_absent;
11324 case '@': /* DSP 10-bit signed immediate in bit 16. */
11326 long mask = (mips_opts.micromips
11327 ? MICROMIPSOP_MASK_IMM10 : OP_MASK_IMM10);
11329 my_getExpression (&imm_expr, s);
11330 check_absolute_expr (ip, &imm_expr);
11331 min_range = -((mask + 1) >> 1);
11332 max_range = ((mask + 1) >> 1) - 1;
11333 if (imm_expr.X_add_number < min_range
11334 || imm_expr.X_add_number > max_range)
11335 as_bad (_("DSP immediate not in range %ld..%ld (%ld)"),
11336 (long) min_range, (long) max_range,
11337 (long) imm_expr.X_add_number);
11338 INSERT_OPERAND (mips_opts.micromips,
11339 IMM10, *ip, imm_expr.X_add_number);
11340 imm_expr.X_op = O_absent;
11345 case '^': /* DSP 5-bit unsigned immediate in bit 11. */
11346 gas_assert (mips_opts.micromips);
11347 my_getExpression (&imm_expr, s);
11348 check_absolute_expr (ip, &imm_expr);
11349 if (imm_expr.X_add_number & ~MICROMIPSOP_MASK_RD)
11350 as_bad (_("DSP immediate not in range 0..%d (%lu)"),
11351 MICROMIPSOP_MASK_RD,
11352 (unsigned long) imm_expr.X_add_number);
11353 INSERT_OPERAND (1, RD, *ip, imm_expr.X_add_number);
11354 imm_expr.X_op = O_absent;
11358 case '!': /* MT usermode flag bit. */
11359 gas_assert (!mips_opts.micromips);
11360 my_getExpression (&imm_expr, s);
11361 check_absolute_expr (ip, &imm_expr);
11362 if (imm_expr.X_add_number & ~OP_MASK_MT_U)
11363 as_bad (_("MT usermode bit not 0 or 1 (%lu)"),
11364 (unsigned long) imm_expr.X_add_number);
11365 INSERT_OPERAND (0, MT_U, *ip, imm_expr.X_add_number);
11366 imm_expr.X_op = O_absent;
11370 case '$': /* MT load high flag bit. */
11371 gas_assert (!mips_opts.micromips);
11372 my_getExpression (&imm_expr, s);
11373 check_absolute_expr (ip, &imm_expr);
11374 if (imm_expr.X_add_number & ~OP_MASK_MT_H)
11375 as_bad (_("MT load high bit not 0 or 1 (%lu)"),
11376 (unsigned long) imm_expr.X_add_number);
11377 INSERT_OPERAND (0, MT_H, *ip, imm_expr.X_add_number);
11378 imm_expr.X_op = O_absent;
11382 case '*': /* Four DSP accumulators in bits 18,19. */
11383 gas_assert (!mips_opts.micromips);
11384 if (s[0] == '$' && s[1] == 'a' && s[2] == 'c' &&
11385 s[3] >= '0' && s[3] <= '3')
11387 regno = s[3] - '0';
11389 INSERT_OPERAND (0, MTACC_T, *ip, regno);
11393 as_bad (_("Invalid dsp/smartmips acc register"));
11396 case '&': /* Four DSP accumulators in bits 13,14. */
11397 gas_assert (!mips_opts.micromips);
11398 if (s[0] == '$' && s[1] == 'a' && s[2] == 'c' &&
11399 s[3] >= '0' && s[3] <= '3')
11401 regno = s[3] - '0';
11403 INSERT_OPERAND (0, MTACC_D, *ip, regno);
11407 as_bad (_("Invalid dsp/smartmips acc register"));
11410 case '\\': /* 3-bit bit position. */
11412 unsigned long mask = (mips_opts.micromips
11413 ? MICROMIPSOP_MASK_3BITPOS
11414 : OP_MASK_3BITPOS);
11416 my_getExpression (&imm_expr, s);
11417 check_absolute_expr (ip, &imm_expr);
11418 if ((unsigned long) imm_expr.X_add_number > mask)
11419 as_warn (_("Bit position for %s not in range 0..%lu (%lu)"),
11421 mask, (unsigned long) imm_expr.X_add_number);
11422 INSERT_OPERAND (mips_opts.micromips,
11423 3BITPOS, *ip, imm_expr.X_add_number);
11424 imm_expr.X_op = O_absent;
11438 INSERT_OPERAND (mips_opts.micromips, RS, *ip, lastregno);
11442 INSERT_OPERAND (mips_opts.micromips, RT, *ip, lastregno);
11446 gas_assert (!mips_opts.micromips);
11447 INSERT_OPERAND (0, FT, *ip, lastregno);
11451 INSERT_OPERAND (mips_opts.micromips, FS, *ip, lastregno);
11457 /* Handle optional base register.
11458 Either the base register is omitted or
11459 we must have a left paren. */
11460 /* This is dependent on the next operand specifier
11461 is a base register specification. */
11462 gas_assert (args[1] == 'b'
11463 || (mips_opts.micromips
11465 && (args[2] == 'l' || args[2] == 'n'
11466 || args[2] == 's' || args[2] == 'a')));
11467 if (*s == '\0' && args[1] == 'b')
11469 /* Fall through. */
11471 case ')': /* These must match exactly. */
11476 case '[': /* These must match exactly. */
11478 gas_assert (!mips_opts.micromips);
11483 case '+': /* Opcode extension character. */
11486 case '1': /* UDI immediates. */
11490 gas_assert (!mips_opts.micromips);
11492 const struct mips_immed *imm = mips_immed;
11494 while (imm->type && imm->type != *args)
11498 my_getExpression (&imm_expr, s);
11499 check_absolute_expr (ip, &imm_expr);
11500 if ((unsigned long) imm_expr.X_add_number & ~imm->mask)
11502 as_warn (_("Illegal %s number (%lu, 0x%lx)"),
11503 imm->desc ? imm->desc : ip->insn_mo->name,
11504 (unsigned long) imm_expr.X_add_number,
11505 (unsigned long) imm_expr.X_add_number);
11506 imm_expr.X_add_number &= imm->mask;
11508 ip->insn_opcode |= ((unsigned long) imm_expr.X_add_number
11510 imm_expr.X_op = O_absent;
11515 case 'J': /* 10-bit hypcall code. */
11516 gas_assert (!mips_opts.micromips);
11518 unsigned long mask = OP_MASK_CODE10;
11520 my_getExpression (&imm_expr, s);
11521 check_absolute_expr (ip, &imm_expr);
11522 if ((unsigned long) imm_expr.X_add_number > mask)
11523 as_warn (_("Code for %s not in range 0..%lu (%lu)"),
11525 mask, (unsigned long) imm_expr.X_add_number);
11526 INSERT_OPERAND (0, CODE10, *ip, imm_expr.X_add_number);
11527 imm_expr.X_op = O_absent;
11532 case 'A': /* ins/ext position, becomes LSB. */
11541 my_getExpression (&imm_expr, s);
11542 check_absolute_expr (ip, &imm_expr);
11543 if ((unsigned long) imm_expr.X_add_number < limlo
11544 || (unsigned long) imm_expr.X_add_number > limhi)
11546 as_bad (_("Improper position (%lu)"),
11547 (unsigned long) imm_expr.X_add_number);
11548 imm_expr.X_add_number = limlo;
11550 lastpos = imm_expr.X_add_number;
11551 INSERT_OPERAND (mips_opts.micromips,
11552 EXTLSB, *ip, imm_expr.X_add_number);
11553 imm_expr.X_op = O_absent;
11557 case 'B': /* ins size, becomes MSB. */
11566 my_getExpression (&imm_expr, s);
11567 check_absolute_expr (ip, &imm_expr);
11568 /* Check for negative input so that small negative numbers
11569 will not succeed incorrectly. The checks against
11570 (pos+size) transitively check "size" itself,
11571 assuming that "pos" is reasonable. */
11572 if ((long) imm_expr.X_add_number < 0
11573 || ((unsigned long) imm_expr.X_add_number
11575 || ((unsigned long) imm_expr.X_add_number
11576 + lastpos) > limhi)
11578 as_bad (_("Improper insert size (%lu, position %lu)"),
11579 (unsigned long) imm_expr.X_add_number,
11580 (unsigned long) lastpos);
11581 imm_expr.X_add_number = limlo - lastpos;
11583 INSERT_OPERAND (mips_opts.micromips, INSMSB, *ip,
11584 lastpos + imm_expr.X_add_number - 1);
11585 imm_expr.X_op = O_absent;
11589 case 'C': /* ext size, becomes MSBD. */
11605 my_getExpression (&imm_expr, s);
11606 check_absolute_expr (ip, &imm_expr);
11607 /* The checks against (pos+size) don't transitively check
11608 "size" itself, assuming that "pos" is reasonable.
11609 We also need to check the lower bound of "size". */
11610 if ((long) imm_expr.X_add_number < sizelo
11611 || ((unsigned long) imm_expr.X_add_number
11613 || ((unsigned long) imm_expr.X_add_number
11614 + lastpos) > limhi)
11616 as_bad (_("Improper extract size (%lu, position %lu)"),
11617 (unsigned long) imm_expr.X_add_number,
11618 (unsigned long) lastpos);
11619 imm_expr.X_add_number = limlo - lastpos;
11621 INSERT_OPERAND (mips_opts.micromips,
11622 EXTMSBD, *ip, imm_expr.X_add_number - 1);
11623 imm_expr.X_op = O_absent;
11628 /* +D is for disassembly only; never match. */
11632 /* "+I" is like "I", except that imm2_expr is used. */
11633 my_getExpression (&imm2_expr, s);
11634 if (imm2_expr.X_op != O_big
11635 && imm2_expr.X_op != O_constant)
11636 insn_error = _("absolute expression required");
11637 if (HAVE_32BIT_GPRS)
11638 normalize_constant_expr (&imm2_expr);
11642 case 'T': /* Coprocessor register. */
11643 gas_assert (!mips_opts.micromips);
11644 /* +T is for disassembly only; never match. */
11647 case 't': /* Coprocessor register number. */
11648 gas_assert (!mips_opts.micromips);
11649 if (s[0] == '$' && ISDIGIT (s[1]))
11659 while (ISDIGIT (*s));
11661 as_bad (_("Invalid register number (%d)"), regno);
11664 INSERT_OPERAND (0, RT, *ip, regno);
11669 as_bad (_("Invalid coprocessor 0 register number"));
11673 /* bbit[01] and bbit[01]32 bit index. Give error if index
11674 is not in the valid range. */
11675 gas_assert (!mips_opts.micromips);
11676 my_getExpression (&imm_expr, s);
11677 check_absolute_expr (ip, &imm_expr);
11678 if ((unsigned) imm_expr.X_add_number > 31)
11680 as_bad (_("Improper bit index (%lu)"),
11681 (unsigned long) imm_expr.X_add_number);
11682 imm_expr.X_add_number = 0;
11684 INSERT_OPERAND (0, BBITIND, *ip, imm_expr.X_add_number);
11685 imm_expr.X_op = O_absent;
11690 /* bbit[01] bit index when bbit is used but we generate
11691 bbit[01]32 because the index is over 32. Move to the
11692 next candidate if index is not in the valid range. */
11693 gas_assert (!mips_opts.micromips);
11694 my_getExpression (&imm_expr, s);
11695 check_absolute_expr (ip, &imm_expr);
11696 if ((unsigned) imm_expr.X_add_number < 32
11697 || (unsigned) imm_expr.X_add_number > 63)
11699 INSERT_OPERAND (0, BBITIND, *ip, imm_expr.X_add_number - 32);
11700 imm_expr.X_op = O_absent;
11705 /* cins, cins32, exts and exts32 position field. Give error
11706 if it's not in the valid range. */
11707 gas_assert (!mips_opts.micromips);
11708 my_getExpression (&imm_expr, s);
11709 check_absolute_expr (ip, &imm_expr);
11710 if ((unsigned) imm_expr.X_add_number > 31)
11712 as_bad (_("Improper position (%lu)"),
11713 (unsigned long) imm_expr.X_add_number);
11714 imm_expr.X_add_number = 0;
11716 /* Make the pos explicit to simplify +S. */
11717 lastpos = imm_expr.X_add_number + 32;
11718 INSERT_OPERAND (0, CINSPOS, *ip, imm_expr.X_add_number);
11719 imm_expr.X_op = O_absent;
11724 /* cins, cins32, exts and exts32 position field. Move to
11725 the next candidate if it's not in the valid range. */
11726 gas_assert (!mips_opts.micromips);
11727 my_getExpression (&imm_expr, s);
11728 check_absolute_expr (ip, &imm_expr);
11729 if ((unsigned) imm_expr.X_add_number < 32
11730 || (unsigned) imm_expr.X_add_number > 63)
11732 lastpos = imm_expr.X_add_number;
11733 INSERT_OPERAND (0, CINSPOS, *ip, imm_expr.X_add_number - 32);
11734 imm_expr.X_op = O_absent;
11739 /* cins and exts length-minus-one field. */
11740 gas_assert (!mips_opts.micromips);
11741 my_getExpression (&imm_expr, s);
11742 check_absolute_expr (ip, &imm_expr);
11743 if ((unsigned long) imm_expr.X_add_number > 31)
11745 as_bad (_("Improper size (%lu)"),
11746 (unsigned long) imm_expr.X_add_number);
11747 imm_expr.X_add_number = 0;
11749 INSERT_OPERAND (0, CINSLM1, *ip, imm_expr.X_add_number);
11750 imm_expr.X_op = O_absent;
11755 /* cins32/exts32 and cins/exts aliasing cint32/exts32
11756 length-minus-one field. */
11757 gas_assert (!mips_opts.micromips);
11758 my_getExpression (&imm_expr, s);
11759 check_absolute_expr (ip, &imm_expr);
11760 if ((long) imm_expr.X_add_number < 0
11761 || (unsigned long) imm_expr.X_add_number + lastpos > 63)
11763 as_bad (_("Improper size (%lu)"),
11764 (unsigned long) imm_expr.X_add_number);
11765 imm_expr.X_add_number = 0;
11767 INSERT_OPERAND (0, CINSLM1, *ip, imm_expr.X_add_number);
11768 imm_expr.X_op = O_absent;
11773 /* seqi/snei immediate field. */
11774 gas_assert (!mips_opts.micromips);
11775 my_getExpression (&imm_expr, s);
11776 check_absolute_expr (ip, &imm_expr);
11777 if ((long) imm_expr.X_add_number < -512
11778 || (long) imm_expr.X_add_number >= 512)
11780 as_bad (_("Improper immediate (%ld)"),
11781 (long) imm_expr.X_add_number);
11782 imm_expr.X_add_number = 0;
11784 INSERT_OPERAND (0, SEQI, *ip, imm_expr.X_add_number);
11785 imm_expr.X_op = O_absent;
11789 case 'a': /* 8-bit signed offset in bit 6 */
11790 gas_assert (!mips_opts.micromips);
11791 my_getExpression (&imm_expr, s);
11792 check_absolute_expr (ip, &imm_expr);
11793 min_range = -((OP_MASK_OFFSET_A + 1) >> 1);
11794 max_range = ((OP_MASK_OFFSET_A + 1) >> 1) - 1;
11795 if (imm_expr.X_add_number < min_range
11796 || imm_expr.X_add_number > max_range)
11798 as_bad (_("Offset not in range %ld..%ld (%ld)"),
11799 (long) min_range, (long) max_range,
11800 (long) imm_expr.X_add_number);
11802 INSERT_OPERAND (0, OFFSET_A, *ip, imm_expr.X_add_number);
11803 imm_expr.X_op = O_absent;
11807 case 'b': /* 8-bit signed offset in bit 3 */
11808 gas_assert (!mips_opts.micromips);
11809 my_getExpression (&imm_expr, s);
11810 check_absolute_expr (ip, &imm_expr);
11811 min_range = -((OP_MASK_OFFSET_B + 1) >> 1);
11812 max_range = ((OP_MASK_OFFSET_B + 1) >> 1) - 1;
11813 if (imm_expr.X_add_number < min_range
11814 || imm_expr.X_add_number > max_range)
11816 as_bad (_("Offset not in range %ld..%ld (%ld)"),
11817 (long) min_range, (long) max_range,
11818 (long) imm_expr.X_add_number);
11820 INSERT_OPERAND (0, OFFSET_B, *ip, imm_expr.X_add_number);
11821 imm_expr.X_op = O_absent;
11825 case 'c': /* 9-bit signed offset in bit 6 */
11826 gas_assert (!mips_opts.micromips);
11827 my_getExpression (&imm_expr, s);
11828 check_absolute_expr (ip, &imm_expr);
11829 min_range = -((OP_MASK_OFFSET_C + 1) >> 1);
11830 max_range = ((OP_MASK_OFFSET_C + 1) >> 1) - 1;
11831 /* We check the offset range before adjusted. */
11834 if (imm_expr.X_add_number < min_range
11835 || imm_expr.X_add_number > max_range)
11837 as_bad (_("Offset not in range %ld..%ld (%ld)"),
11838 (long) min_range, (long) max_range,
11839 (long) imm_expr.X_add_number);
11841 if (imm_expr.X_add_number & 0xf)
11843 as_bad (_("Offset not 16 bytes alignment (%ld)"),
11844 (long) imm_expr.X_add_number);
11846 /* Right shift 4 bits to adjust the offset operand. */
11847 INSERT_OPERAND (0, OFFSET_C, *ip,
11848 imm_expr.X_add_number >> 4);
11849 imm_expr.X_op = O_absent;
11854 gas_assert (!mips_opts.micromips);
11855 if (!reg_lookup (&s, RTYPE_NUM | RTYPE_GP, ®no))
11857 if (regno == AT && mips_opts.at)
11859 if (mips_opts.at == ATREG)
11860 as_warn (_("used $at without \".set noat\""));
11862 as_warn (_("used $%u with \".set at=$%u\""),
11863 regno, mips_opts.at);
11865 INSERT_OPERAND (0, RZ, *ip, regno);
11869 gas_assert (!mips_opts.micromips);
11870 if (!reg_lookup (&s, RTYPE_FPU, ®no))
11872 INSERT_OPERAND (0, FZ, *ip, regno);
11879 /* Check whether there is only a single bracketed expression
11880 left. If so, it must be the base register and the
11881 constant must be zero. */
11882 if (*s == '(' && strchr (s + 1, '(') == 0)
11885 /* If this value won't fit into the offset, then go find
11886 a macro that will generate a 16- or 32-bit offset code
11888 i = my_getSmallExpression (&imm_expr, imm_reloc, s);
11889 if ((i == 0 && (imm_expr.X_op != O_constant
11890 || imm_expr.X_add_number >= 1 << shift
11891 || imm_expr.X_add_number < -1 << shift))
11894 imm_expr.X_op = O_absent;
11897 INSERT_OPERAND (mips_opts.micromips, EVAOFFSET, *ip,
11898 imm_expr.X_add_number);
11899 imm_expr.X_op = O_absent;
11905 as_bad (_("Internal error: bad %s opcode "
11906 "(unknown extension operand type `+%c'): %s %s"),
11907 mips_opts.micromips ? "microMIPS" : "MIPS",
11908 *args, insn->name, insn->args);
11909 /* Further processing is fruitless. */
11914 case '.': /* 10-bit offset. */
11915 gas_assert (mips_opts.micromips);
11916 case '~': /* 12-bit offset. */
11918 int shift = *args == '.' ? 9 : 11;
11921 /* Check whether there is only a single bracketed expression
11922 left. If so, it must be the base register and the
11923 constant must be zero. */
11924 if (*s == '(' && strchr (s + 1, '(') == 0)
11927 /* If this value won't fit into the offset, then go find
11928 a macro that will generate a 16- or 32-bit offset code
11930 i = my_getSmallExpression (&imm_expr, imm_reloc, s);
11931 if ((i == 0 && (imm_expr.X_op != O_constant
11932 || imm_expr.X_add_number >= 1 << shift
11933 || imm_expr.X_add_number < -1 << shift))
11936 imm_expr.X_op = O_absent;
11940 INSERT_OPERAND (1, OFFSET10, *ip, imm_expr.X_add_number);
11942 INSERT_OPERAND (mips_opts.micromips,
11943 OFFSET12, *ip, imm_expr.X_add_number);
11944 imm_expr.X_op = O_absent;
11949 case '<': /* must be at least one digit */
11951 * According to the manual, if the shift amount is greater
11952 * than 31 or less than 0, then the shift amount should be
11953 * mod 32. In reality the mips assembler issues an error.
11954 * We issue a warning and mask out all but the low 5 bits.
11956 my_getExpression (&imm_expr, s);
11957 check_absolute_expr (ip, &imm_expr);
11958 if ((unsigned long) imm_expr.X_add_number > 31)
11959 as_warn (_("Improper shift amount (%lu)"),
11960 (unsigned long) imm_expr.X_add_number);
11961 INSERT_OPERAND (mips_opts.micromips,
11962 SHAMT, *ip, imm_expr.X_add_number);
11963 imm_expr.X_op = O_absent;
11967 case '>': /* shift amount minus 32 */
11968 my_getExpression (&imm_expr, s);
11969 check_absolute_expr (ip, &imm_expr);
11970 if ((unsigned long) imm_expr.X_add_number < 32
11971 || (unsigned long) imm_expr.X_add_number > 63)
11973 INSERT_OPERAND (mips_opts.micromips,
11974 SHAMT, *ip, imm_expr.X_add_number - 32);
11975 imm_expr.X_op = O_absent;
11979 case 'k': /* CACHE code. */
11980 case 'h': /* PREFX code. */
11981 case '1': /* SYNC type. */
11982 my_getExpression (&imm_expr, s);
11983 check_absolute_expr (ip, &imm_expr);
11984 if ((unsigned long) imm_expr.X_add_number > 31)
11985 as_warn (_("Invalid value for `%s' (%lu)"),
11987 (unsigned long) imm_expr.X_add_number);
11991 if (mips_fix_cn63xxp1
11992 && !mips_opts.micromips
11993 && strcmp ("pref", insn->name) == 0)
11994 switch (imm_expr.X_add_number)
12003 case 31: /* These are ok. */
12006 default: /* The rest must be changed to 28. */
12007 imm_expr.X_add_number = 28;
12010 INSERT_OPERAND (mips_opts.micromips,
12011 CACHE, *ip, imm_expr.X_add_number);
12014 INSERT_OPERAND (mips_opts.micromips,
12015 PREFX, *ip, imm_expr.X_add_number);
12018 INSERT_OPERAND (mips_opts.micromips,
12019 STYPE, *ip, imm_expr.X_add_number);
12022 imm_expr.X_op = O_absent;
12026 case 'c': /* BREAK code. */
12028 unsigned long mask = (mips_opts.micromips
12029 ? MICROMIPSOP_MASK_CODE
12032 my_getExpression (&imm_expr, s);
12033 check_absolute_expr (ip, &imm_expr);
12034 if ((unsigned long) imm_expr.X_add_number > mask)
12035 as_warn (_("Code for %s not in range 0..%lu (%lu)"),
12037 mask, (unsigned long) imm_expr.X_add_number);
12038 INSERT_OPERAND (mips_opts.micromips,
12039 CODE, *ip, imm_expr.X_add_number);
12040 imm_expr.X_op = O_absent;
12045 case 'q': /* Lower BREAK code. */
12047 unsigned long mask = (mips_opts.micromips
12048 ? MICROMIPSOP_MASK_CODE2
12051 my_getExpression (&imm_expr, s);
12052 check_absolute_expr (ip, &imm_expr);
12053 if ((unsigned long) imm_expr.X_add_number > mask)
12054 as_warn (_("Lower code for %s not in range 0..%lu (%lu)"),
12056 mask, (unsigned long) imm_expr.X_add_number);
12057 INSERT_OPERAND (mips_opts.micromips,
12058 CODE2, *ip, imm_expr.X_add_number);
12059 imm_expr.X_op = O_absent;
12064 case 'B': /* 20- or 10-bit syscall/break/wait code. */
12066 unsigned long mask = (mips_opts.micromips
12067 ? MICROMIPSOP_MASK_CODE10
12070 my_getExpression (&imm_expr, s);
12071 check_absolute_expr (ip, &imm_expr);
12072 if ((unsigned long) imm_expr.X_add_number > mask)
12073 as_warn (_("Code for %s not in range 0..%lu (%lu)"),
12075 mask, (unsigned long) imm_expr.X_add_number);
12076 if (mips_opts.micromips)
12077 INSERT_OPERAND (1, CODE10, *ip, imm_expr.X_add_number);
12079 INSERT_OPERAND (0, CODE20, *ip, imm_expr.X_add_number);
12080 imm_expr.X_op = O_absent;
12085 case 'C': /* 25- or 23-bit coprocessor code. */
12087 unsigned long mask = (mips_opts.micromips
12088 ? MICROMIPSOP_MASK_COPZ
12091 my_getExpression (&imm_expr, s);
12092 check_absolute_expr (ip, &imm_expr);
12093 if ((unsigned long) imm_expr.X_add_number > mask)
12094 as_warn (_("Coproccesor code > %u bits (%lu)"),
12095 mips_opts.micromips ? 23U : 25U,
12096 (unsigned long) imm_expr.X_add_number);
12097 INSERT_OPERAND (mips_opts.micromips,
12098 COPZ, *ip, imm_expr.X_add_number);
12099 imm_expr.X_op = O_absent;
12104 case 'J': /* 19-bit WAIT code. */
12105 gas_assert (!mips_opts.micromips);
12106 my_getExpression (&imm_expr, s);
12107 check_absolute_expr (ip, &imm_expr);
12108 if ((unsigned long) imm_expr.X_add_number > OP_MASK_CODE19)
12110 as_warn (_("Illegal 19-bit code (%lu)"),
12111 (unsigned long) imm_expr.X_add_number);
12112 imm_expr.X_add_number &= OP_MASK_CODE19;
12114 INSERT_OPERAND (0, CODE19, *ip, imm_expr.X_add_number);
12115 imm_expr.X_op = O_absent;
12119 case 'P': /* Performance register. */
12120 gas_assert (!mips_opts.micromips);
12121 my_getExpression (&imm_expr, s);
12122 check_absolute_expr (ip, &imm_expr);
12123 if (imm_expr.X_add_number != 0 && imm_expr.X_add_number != 1)
12124 as_warn (_("Invalid performance register (%lu)"),
12125 (unsigned long) imm_expr.X_add_number);
12126 if (imm_expr.X_add_number != 0 && mips_opts.arch == CPU_R5900
12127 && (!strcmp(insn->name,"mfps") || !strcmp(insn->name,"mtps")))
12128 as_warn (_("Invalid performance register (%lu)"),
12129 (unsigned long) imm_expr.X_add_number);
12130 INSERT_OPERAND (0, PERFREG, *ip, imm_expr.X_add_number);
12131 imm_expr.X_op = O_absent;
12135 case 'G': /* Coprocessor destination register. */
12137 unsigned long opcode = ip->insn_opcode;
12138 unsigned long mask;
12139 unsigned int types;
12142 if (mips_opts.micromips)
12144 mask = ~((MICROMIPSOP_MASK_RT << MICROMIPSOP_SH_RT)
12145 | (MICROMIPSOP_MASK_RS << MICROMIPSOP_SH_RS)
12146 | (MICROMIPSOP_MASK_SEL << MICROMIPSOP_SH_SEL));
12150 case 0x000000fc: /* mfc0 */
12151 case 0x000002fc: /* mtc0 */
12152 case 0x580000fc: /* dmfc0 */
12153 case 0x580002fc: /* dmtc0 */
12163 opcode = (opcode >> OP_SH_OP) & OP_MASK_OP;
12164 cop0 = opcode == OP_OP_COP0;
12166 types = RTYPE_NUM | (cop0 ? RTYPE_CP0 : RTYPE_GP);
12167 ok = reg_lookup (&s, types, ®no);
12168 if (mips_opts.micromips)
12169 INSERT_OPERAND (1, RS, *ip, regno);
12171 INSERT_OPERAND (0, RD, *ip, regno);
12180 case 'y': /* ALNV.PS source register. */
12181 gas_assert (mips_opts.micromips);
12183 case 'x': /* Ignore register name. */
12184 case 'U': /* Destination register (CLO/CLZ). */
12185 case 'g': /* Coprocessor destination register. */
12186 gas_assert (!mips_opts.micromips);
12187 case 'b': /* Base register. */
12188 case 'd': /* Destination register. */
12189 case 's': /* Source register. */
12190 case 't': /* Target register. */
12191 case 'r': /* Both target and source. */
12192 case 'v': /* Both dest and source. */
12193 case 'w': /* Both dest and target. */
12194 case 'E': /* Coprocessor target register. */
12195 case 'K': /* RDHWR destination register. */
12196 case 'z': /* Must be zero register. */
12199 if (*args == 'E' || *args == 'K')
12200 ok = reg_lookup (&s, RTYPE_NUM, ®no);
12203 ok = reg_lookup (&s, RTYPE_NUM | RTYPE_GP, ®no);
12204 if (regno == AT && mips_opts.at)
12206 if (mips_opts.at == ATREG)
12207 as_warn (_("Used $at without \".set noat\""));
12209 as_warn (_("Used $%u with \".set at=$%u\""),
12210 regno, mips_opts.at);
12220 if (c == 'r' || c == 'v' || c == 'w')
12227 /* 'z' only matches $0. */
12228 if (c == 'z' && regno != 0)
12231 if (c == 's' && !strncmp (ip->insn_mo->name, "jalr", 4))
12233 if (regno == lastregno)
12236 = _("Source and destination must be different");
12239 if (regno == 31 && lastregno == 0xffffffff)
12242 = _("A destination register must be supplied");
12246 /* Now that we have assembled one operand, we use the args
12247 string to figure out where it goes in the instruction. */
12254 INSERT_OPERAND (mips_opts.micromips, RS, *ip, regno);
12258 if (mips_opts.micromips)
12259 INSERT_OPERAND (1, RS, *ip, regno);
12261 INSERT_OPERAND (0, RD, *ip, regno);
12266 INSERT_OPERAND (mips_opts.micromips, RD, *ip, regno);
12270 gas_assert (!mips_opts.micromips);
12271 INSERT_OPERAND (0, RD, *ip, regno);
12272 INSERT_OPERAND (0, RT, *ip, regno);
12278 INSERT_OPERAND (mips_opts.micromips, RT, *ip, regno);
12282 gas_assert (mips_opts.micromips);
12283 INSERT_OPERAND (1, RS3, *ip, regno);
12287 /* This case exists because on the r3000 trunc
12288 expands into a macro which requires a gp
12289 register. On the r6000 or r4000 it is
12290 assembled into a single instruction which
12291 ignores the register. Thus the insn version
12292 is MIPS_ISA2 and uses 'x', and the macro
12293 version is MIPS_ISA1 and uses 't'. */
12297 /* This case is for the div instruction, which
12298 acts differently if the destination argument
12299 is $0. This only matches $0, and is checked
12300 outside the switch. */
12310 INSERT_OPERAND (mips_opts.micromips, RS, *ip, lastregno);
12314 INSERT_OPERAND (mips_opts.micromips, RT, *ip, lastregno);
12319 case 'O': /* MDMX alignment immediate constant. */
12320 gas_assert (!mips_opts.micromips);
12321 my_getExpression (&imm_expr, s);
12322 check_absolute_expr (ip, &imm_expr);
12323 if ((unsigned long) imm_expr.X_add_number > OP_MASK_ALN)
12324 as_warn (_("Improper align amount (%ld), using low bits"),
12325 (long) imm_expr.X_add_number);
12326 INSERT_OPERAND (0, ALN, *ip, imm_expr.X_add_number);
12327 imm_expr.X_op = O_absent;
12331 case 'Q': /* MDMX vector, element sel, or const. */
12334 /* MDMX Immediate. */
12335 gas_assert (!mips_opts.micromips);
12336 my_getExpression (&imm_expr, s);
12337 check_absolute_expr (ip, &imm_expr);
12338 if ((unsigned long) imm_expr.X_add_number > OP_MASK_FT)
12339 as_warn (_("Invalid MDMX Immediate (%ld)"),
12340 (long) imm_expr.X_add_number);
12341 INSERT_OPERAND (0, FT, *ip, imm_expr.X_add_number);
12342 if (ip->insn_opcode & (OP_MASK_VSEL << OP_SH_VSEL))
12343 ip->insn_opcode |= MDMX_FMTSEL_IMM_QH << OP_SH_VSEL;
12345 ip->insn_opcode |= MDMX_FMTSEL_IMM_OB << OP_SH_VSEL;
12346 imm_expr.X_op = O_absent;
12350 /* Not MDMX Immediate. Fall through. */
12351 case 'X': /* MDMX destination register. */
12352 case 'Y': /* MDMX source register. */
12353 case 'Z': /* MDMX target register. */
12356 gas_assert (!mips_opts.micromips);
12357 case 'D': /* Floating point destination register. */
12358 case 'S': /* Floating point source register. */
12359 case 'T': /* Floating point target register. */
12360 case 'R': /* Floating point source register. */
12364 || (mips_opts.ase_mdmx
12365 && (ip->insn_mo->pinfo & FP_D)
12366 && (ip->insn_mo->pinfo & (INSN_COPROC_MOVE_DELAY
12367 | INSN_COPROC_MEMORY_DELAY
12368 | INSN_LOAD_COPROC_DELAY
12369 | INSN_LOAD_MEMORY_DELAY
12370 | INSN_STORE_MEMORY))))
12371 rtype |= RTYPE_VEC;
12373 if (reg_lookup (&s, rtype, ®no))
12375 if ((regno & 1) != 0
12377 && !mips_oddfpreg_ok (ip->insn_mo, argnum))
12378 as_warn (_("Float register should be even, was %d"),
12386 if (c == 'V' || c == 'W')
12397 INSERT_OPERAND (mips_opts.micromips, FD, *ip, regno);
12403 INSERT_OPERAND (mips_opts.micromips, FS, *ip, regno);
12407 /* This is like 'Z', but also needs to fix the MDMX
12408 vector/scalar select bits. Note that the
12409 scalar immediate case is handled above. */
12412 int is_qh = (ip->insn_opcode & (1 << OP_SH_VSEL));
12413 int max_el = (is_qh ? 3 : 7);
12415 my_getExpression(&imm_expr, s);
12416 check_absolute_expr (ip, &imm_expr);
12418 if (imm_expr.X_add_number > max_el)
12419 as_bad (_("Bad element selector %ld"),
12420 (long) imm_expr.X_add_number);
12421 imm_expr.X_add_number &= max_el;
12422 ip->insn_opcode |= (imm_expr.X_add_number
12425 imm_expr.X_op = O_absent;
12427 as_warn (_("Expecting ']' found '%s'"), s);
12433 if (ip->insn_opcode & (OP_MASK_VSEL << OP_SH_VSEL))
12434 ip->insn_opcode |= (MDMX_FMTSEL_VEC_QH
12437 ip->insn_opcode |= (MDMX_FMTSEL_VEC_OB <<
12440 /* Fall through. */
12444 INSERT_OPERAND (mips_opts.micromips, FT, *ip, regno);
12448 INSERT_OPERAND (mips_opts.micromips, FR, *ip, regno);
12458 INSERT_OPERAND (mips_opts.micromips, FS, *ip, lastregno);
12462 INSERT_OPERAND (mips_opts.micromips, FT, *ip, lastregno);
12468 my_getExpression (&imm_expr, s);
12469 if (imm_expr.X_op != O_big
12470 && imm_expr.X_op != O_constant)
12471 insn_error = _("absolute expression required");
12472 if (HAVE_32BIT_GPRS)
12473 normalize_constant_expr (&imm_expr);
12478 my_getExpression (&offset_expr, s);
12479 normalize_address_expr (&offset_expr);
12480 *imm_reloc = BFD_RELOC_32;
12493 unsigned char temp[8];
12495 unsigned int length;
12500 /* These only appear as the last operand in an
12501 instruction, and every instruction that accepts
12502 them in any variant accepts them in all variants.
12503 This means we don't have to worry about backing out
12504 any changes if the instruction does not match.
12506 The difference between them is the size of the
12507 floating point constant and where it goes. For 'F'
12508 and 'L' the constant is 64 bits; for 'f' and 'l' it
12509 is 32 bits. Where the constant is placed is based
12510 on how the MIPS assembler does things:
12513 f -- immediate value
12516 The .lit4 and .lit8 sections are only used if
12517 permitted by the -G argument.
12519 The code below needs to know whether the target register
12520 is 32 or 64 bits wide. It relies on the fact 'f' and
12521 'F' are used with GPR-based instructions and 'l' and
12522 'L' are used with FPR-based instructions. */
12524 f64 = *args == 'F' || *args == 'L';
12525 using_gprs = *args == 'F' || *args == 'f';
12527 save_in = input_line_pointer;
12528 input_line_pointer = s;
12529 err = md_atof (f64 ? 'd' : 'f', (char *) temp, &len);
12531 s = input_line_pointer;
12532 input_line_pointer = save_in;
12533 if (err != NULL && *err != '\0')
12535 as_bad (_("Bad floating point constant: %s"), err);
12536 memset (temp, '\0', sizeof temp);
12537 length = f64 ? 8 : 4;
12540 gas_assert (length == (unsigned) (f64 ? 8 : 4));
12544 && (g_switch_value < 4
12545 || (temp[0] == 0 && temp[1] == 0)
12546 || (temp[2] == 0 && temp[3] == 0))))
12548 imm_expr.X_op = O_constant;
12549 if (!target_big_endian)
12550 imm_expr.X_add_number = bfd_getl32 (temp);
12552 imm_expr.X_add_number = bfd_getb32 (temp);
12554 else if (length > 4
12555 && !mips_disable_float_construction
12556 /* Constants can only be constructed in GPRs and
12557 copied to FPRs if the GPRs are at least as wide
12558 as the FPRs. Force the constant into memory if
12559 we are using 64-bit FPRs but the GPRs are only
12562 || !(HAVE_64BIT_FPRS && HAVE_32BIT_GPRS))
12563 && ((temp[0] == 0 && temp[1] == 0)
12564 || (temp[2] == 0 && temp[3] == 0))
12565 && ((temp[4] == 0 && temp[5] == 0)
12566 || (temp[6] == 0 && temp[7] == 0)))
12568 /* The value is simple enough to load with a couple of
12569 instructions. If using 32-bit registers, set
12570 imm_expr to the high order 32 bits and offset_expr to
12571 the low order 32 bits. Otherwise, set imm_expr to
12572 the entire 64 bit constant. */
12573 if (using_gprs ? HAVE_32BIT_GPRS : HAVE_32BIT_FPRS)
12575 imm_expr.X_op = O_constant;
12576 offset_expr.X_op = O_constant;
12577 if (!target_big_endian)
12579 imm_expr.X_add_number = bfd_getl32 (temp + 4);
12580 offset_expr.X_add_number = bfd_getl32 (temp);
12584 imm_expr.X_add_number = bfd_getb32 (temp);
12585 offset_expr.X_add_number = bfd_getb32 (temp + 4);
12587 if (offset_expr.X_add_number == 0)
12588 offset_expr.X_op = O_absent;
12590 else if (sizeof (imm_expr.X_add_number) > 4)
12592 imm_expr.X_op = O_constant;
12593 if (!target_big_endian)
12594 imm_expr.X_add_number = bfd_getl64 (temp);
12596 imm_expr.X_add_number = bfd_getb64 (temp);
12600 imm_expr.X_op = O_big;
12601 imm_expr.X_add_number = 4;
12602 if (!target_big_endian)
12604 generic_bignum[0] = bfd_getl16 (temp);
12605 generic_bignum[1] = bfd_getl16 (temp + 2);
12606 generic_bignum[2] = bfd_getl16 (temp + 4);
12607 generic_bignum[3] = bfd_getl16 (temp + 6);
12611 generic_bignum[0] = bfd_getb16 (temp + 6);
12612 generic_bignum[1] = bfd_getb16 (temp + 4);
12613 generic_bignum[2] = bfd_getb16 (temp + 2);
12614 generic_bignum[3] = bfd_getb16 (temp);
12620 const char *newname;
12623 /* Switch to the right section. */
12625 subseg = now_subseg;
12628 default: /* unused default case avoids warnings. */
12630 newname = RDATA_SECTION_NAME;
12631 if (g_switch_value >= 8)
12635 newname = RDATA_SECTION_NAME;
12638 gas_assert (g_switch_value >= 4);
12642 new_seg = subseg_new (newname, (subsegT) 0);
12644 bfd_set_section_flags (stdoutput, new_seg,
12649 frag_align (*args == 'l' ? 2 : 3, 0, 0);
12650 if (IS_ELF && strncmp (TARGET_OS, "elf", 3) != 0)
12651 record_alignment (new_seg, 4);
12653 record_alignment (new_seg, *args == 'l' ? 2 : 3);
12654 if (seg == now_seg)
12655 as_bad (_("Can't use floating point insn in this section"));
12657 /* Set the argument to the current address in the
12659 offset_expr.X_op = O_symbol;
12660 offset_expr.X_add_symbol = symbol_temp_new_now ();
12661 offset_expr.X_add_number = 0;
12663 /* Put the floating point number into the section. */
12664 p = frag_more ((int) length);
12665 memcpy (p, temp, length);
12667 /* Switch back to the original section. */
12668 subseg_set (seg, subseg);
12673 case 'i': /* 16-bit unsigned immediate. */
12674 case 'j': /* 16-bit signed immediate. */
12675 *imm_reloc = BFD_RELOC_LO16;
12676 if (my_getSmallExpression (&imm_expr, imm_reloc, s) == 0)
12679 offsetT minval, maxval;
12681 more = (insn + 1 < past
12682 && strcmp (insn->name, insn[1].name) == 0);
12684 /* If the expression was written as an unsigned number,
12685 only treat it as signed if there are no more
12689 && sizeof (imm_expr.X_add_number) <= 4
12690 && imm_expr.X_op == O_constant
12691 && imm_expr.X_add_number < 0
12692 && imm_expr.X_unsigned
12693 && HAVE_64BIT_GPRS)
12696 /* For compatibility with older assemblers, we accept
12697 0x8000-0xffff as signed 16-bit numbers when only
12698 signed numbers are allowed. */
12700 minval = 0, maxval = 0xffff;
12702 minval = -0x8000, maxval = 0x7fff;
12704 minval = -0x8000, maxval = 0xffff;
12706 if (imm_expr.X_op != O_constant
12707 || imm_expr.X_add_number < minval
12708 || imm_expr.X_add_number > maxval)
12712 if (imm_expr.X_op == O_constant
12713 || imm_expr.X_op == O_big)
12714 as_bad (_("Expression out of range"));
12720 case 'o': /* 16-bit offset. */
12721 offset_reloc[0] = BFD_RELOC_LO16;
12722 offset_reloc[1] = BFD_RELOC_UNUSED;
12723 offset_reloc[2] = BFD_RELOC_UNUSED;
12725 /* Check whether there is only a single bracketed expression
12726 left. If so, it must be the base register and the
12727 constant must be zero. */
12728 if (*s == '(' && strchr (s + 1, '(') == 0)
12730 offset_expr.X_op = O_constant;
12731 offset_expr.X_add_number = 0;
12735 /* If this value won't fit into a 16 bit offset, then go
12736 find a macro that will generate the 32 bit offset
12738 if (my_getSmallExpression (&offset_expr, offset_reloc, s) == 0
12739 && (offset_expr.X_op != O_constant
12740 || offset_expr.X_add_number >= 0x8000
12741 || offset_expr.X_add_number < -0x8000))
12747 case 'p': /* PC-relative offset. */
12748 *offset_reloc = BFD_RELOC_16_PCREL_S2;
12749 my_getExpression (&offset_expr, s);
12753 case 'u': /* Upper 16 bits. */
12754 *imm_reloc = BFD_RELOC_LO16;
12755 if (my_getSmallExpression (&imm_expr, imm_reloc, s) == 0
12756 && imm_expr.X_op == O_constant
12757 && (imm_expr.X_add_number < 0
12758 || imm_expr.X_add_number >= 0x10000))
12759 as_bad (_("lui expression (%lu) not in range 0..65535"),
12760 (unsigned long) imm_expr.X_add_number);
12764 case 'a': /* 26-bit address. */
12765 *offset_reloc = BFD_RELOC_MIPS_JMP;
12766 my_getExpression (&offset_expr, s);
12770 case 'N': /* 3-bit branch condition code. */
12771 case 'M': /* 3-bit compare condition code. */
12773 if (ip->insn_mo->pinfo & (FP_D | FP_S))
12774 rtype |= RTYPE_FCC;
12775 if (!reg_lookup (&s, rtype, ®no))
12777 if ((strcmp (str + strlen (str) - 3, ".ps") == 0
12778 || strcmp (str + strlen (str) - 5, "any2f") == 0
12779 || strcmp (str + strlen (str) - 5, "any2t") == 0)
12780 && (regno & 1) != 0)
12781 as_warn (_("Condition code register should be even for %s, "
12784 if ((strcmp (str + strlen (str) - 5, "any4f") == 0
12785 || strcmp (str + strlen (str) - 5, "any4t") == 0)
12786 && (regno & 3) != 0)
12787 as_warn (_("Condition code register should be 0 or 4 for %s, "
12791 INSERT_OPERAND (mips_opts.micromips, BCC, *ip, regno);
12793 INSERT_OPERAND (mips_opts.micromips, CCC, *ip, regno);
12797 if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X'))
12808 while (ISDIGIT (*s));
12811 c = 8; /* Invalid sel value. */
12814 as_bad (_("Invalid coprocessor sub-selection value (0-7)"));
12815 INSERT_OPERAND (mips_opts.micromips, SEL, *ip, c);
12819 gas_assert (!mips_opts.micromips);
12820 /* Must be at least one digit. */
12821 my_getExpression (&imm_expr, s);
12822 check_absolute_expr (ip, &imm_expr);
12824 if ((unsigned long) imm_expr.X_add_number
12825 > (unsigned long) OP_MASK_VECBYTE)
12827 as_bad (_("bad byte vector index (%ld)"),
12828 (long) imm_expr.X_add_number);
12829 imm_expr.X_add_number = 0;
12832 INSERT_OPERAND (0, VECBYTE, *ip, imm_expr.X_add_number);
12833 imm_expr.X_op = O_absent;
12838 gas_assert (!mips_opts.micromips);
12839 my_getExpression (&imm_expr, s);
12840 check_absolute_expr (ip, &imm_expr);
12842 if ((unsigned long) imm_expr.X_add_number
12843 > (unsigned long) OP_MASK_VECALIGN)
12845 as_bad (_("bad byte vector index (%ld)"),
12846 (long) imm_expr.X_add_number);
12847 imm_expr.X_add_number = 0;
12850 INSERT_OPERAND (0, VECALIGN, *ip, imm_expr.X_add_number);
12851 imm_expr.X_op = O_absent;
12855 case 'm': /* Opcode extension character. */
12856 gas_assert (mips_opts.micromips);
12861 if (strncmp (s, "$pc", 3) == 0)
12889 ok = reg_lookup (&s, RTYPE_NUM | RTYPE_GP, ®no);
12890 if (regno == AT && mips_opts.at)
12892 if (mips_opts.at == ATREG)
12893 as_warn (_("Used $at without \".set noat\""));
12895 as_warn (_("Used $%u with \".set at=$%u\""),
12896 regno, mips_opts.at);
12902 gas_assert (args[1] == ',');
12908 gas_assert (args[1] == ',');
12910 continue; /* Nothing to do. */
12916 if (c == 'j' && !strncmp (ip->insn_mo->name, "jalr", 4))
12918 if (regno == lastregno)
12921 = _("Source and destination must be different");
12924 if (regno == 31 && lastregno == 0xffffffff)
12927 = _("A destination register must be supplied");
12938 gas_assert (args[1] == ',');
12945 gas_assert (args[1] == ',');
12948 continue; /* Nothing to do. */
12952 /* Make sure regno is the same as lastregno. */
12953 if (c == 't' && regno != lastregno)
12956 /* Make sure regno is the same as destregno. */
12957 if (c == 'x' && regno != destregno)
12960 /* We need to save regno, before regno maps to the
12961 microMIPS register encoding. */
12971 regno = ILLEGAL_REG;
12975 regno = mips32_to_micromips_reg_b_map[regno];
12979 regno = mips32_to_micromips_reg_c_map[regno];
12983 regno = mips32_to_micromips_reg_d_map[regno];
12987 regno = mips32_to_micromips_reg_e_map[regno];
12991 regno = mips32_to_micromips_reg_f_map[regno];
12995 regno = mips32_to_micromips_reg_g_map[regno];
12999 regno = mips32_to_micromips_reg_h_map[regno];
13003 switch (EXTRACT_OPERAND (1, MI, *ip))
13008 else if (regno == 22)
13010 else if (regno == 5)
13012 else if (regno == 6)
13014 else if (regno == 7)
13017 regno = ILLEGAL_REG;
13023 else if (regno == 7)
13026 regno = ILLEGAL_REG;
13033 regno = ILLEGAL_REG;
13037 regno = ILLEGAL_REG;
13043 regno = mips32_to_micromips_reg_l_map[regno];
13047 regno = mips32_to_micromips_reg_m_map[regno];
13051 regno = mips32_to_micromips_reg_n_map[regno];
13055 regno = mips32_to_micromips_reg_q_map[regno];
13060 regno = ILLEGAL_REG;
13065 regno = ILLEGAL_REG;
13070 regno = ILLEGAL_REG;
13073 case 'j': /* Do nothing. */
13083 if (regno == ILLEGAL_REG)
13089 INSERT_OPERAND (1, MB, *ip, regno);
13093 INSERT_OPERAND (1, MC, *ip, regno);
13097 INSERT_OPERAND (1, MD, *ip, regno);
13101 INSERT_OPERAND (1, ME, *ip, regno);
13105 INSERT_OPERAND (1, MF, *ip, regno);
13109 INSERT_OPERAND (1, MG, *ip, regno);
13113 INSERT_OPERAND (1, MH, *ip, regno);
13117 INSERT_OPERAND (1, MI, *ip, regno);
13121 INSERT_OPERAND (1, MJ, *ip, regno);
13125 INSERT_OPERAND (1, ML, *ip, regno);
13129 INSERT_OPERAND (1, MM, *ip, regno);
13133 INSERT_OPERAND (1, MN, *ip, regno);
13137 INSERT_OPERAND (1, MP, *ip, regno);
13141 INSERT_OPERAND (1, MQ, *ip, regno);
13144 case 'a': /* Do nothing. */
13145 case 's': /* Do nothing. */
13146 case 't': /* Do nothing. */
13147 case 'x': /* Do nothing. */
13148 case 'y': /* Do nothing. */
13149 case 'z': /* Do nothing. */
13159 bfd_reloc_code_real_type r[3];
13163 /* Check whether there is only a single bracketed
13164 expression left. If so, it must be the base register
13165 and the constant must be zero. */
13166 if (*s == '(' && strchr (s + 1, '(') == 0)
13168 INSERT_OPERAND (1, IMMA, *ip, 0);
13172 if (my_getSmallExpression (&ep, r, s) > 0
13173 || !expr_const_in_range (&ep, -64, 64, 2))
13176 imm = ep.X_add_number >> 2;
13177 INSERT_OPERAND (1, IMMA, *ip, imm);
13184 bfd_reloc_code_real_type r[3];
13188 if (my_getSmallExpression (&ep, r, s) > 0
13189 || ep.X_op != O_constant)
13192 for (imm = 0; imm < 8; imm++)
13193 if (micromips_imm_b_map[imm] == ep.X_add_number)
13198 INSERT_OPERAND (1, IMMB, *ip, imm);
13205 bfd_reloc_code_real_type r[3];
13209 if (my_getSmallExpression (&ep, r, s) > 0
13210 || ep.X_op != O_constant)
13213 for (imm = 0; imm < 16; imm++)
13214 if (micromips_imm_c_map[imm] == ep.X_add_number)
13219 INSERT_OPERAND (1, IMMC, *ip, imm);
13224 case 'D': /* pc relative offset */
13225 case 'E': /* pc relative offset */
13226 my_getExpression (&offset_expr, s);
13227 if (offset_expr.X_op == O_register)
13230 if (!forced_insn_length)
13231 *offset_reloc = (int) BFD_RELOC_UNUSED + c;
13233 *offset_reloc = BFD_RELOC_MICROMIPS_10_PCREL_S1;
13235 *offset_reloc = BFD_RELOC_MICROMIPS_7_PCREL_S1;
13241 bfd_reloc_code_real_type r[3];
13245 if (my_getSmallExpression (&ep, r, s) > 0
13246 || !expr_const_in_range (&ep, 0, 16, 0))
13249 imm = ep.X_add_number;
13250 INSERT_OPERAND (1, IMMF, *ip, imm);
13257 bfd_reloc_code_real_type r[3];
13261 /* Check whether there is only a single bracketed
13262 expression left. If so, it must be the base register
13263 and the constant must be zero. */
13264 if (*s == '(' && strchr (s + 1, '(') == 0)
13266 INSERT_OPERAND (1, IMMG, *ip, 0);
13270 if (my_getSmallExpression (&ep, r, s) > 0
13271 || !expr_const_in_range (&ep, -1, 15, 0))
13274 imm = ep.X_add_number & 15;
13275 INSERT_OPERAND (1, IMMG, *ip, imm);
13282 bfd_reloc_code_real_type r[3];
13286 /* Check whether there is only a single bracketed
13287 expression left. If so, it must be the base register
13288 and the constant must be zero. */
13289 if (*s == '(' && strchr (s + 1, '(') == 0)
13291 INSERT_OPERAND (1, IMMH, *ip, 0);
13295 if (my_getSmallExpression (&ep, r, s) > 0
13296 || !expr_const_in_range (&ep, 0, 16, 1))
13299 imm = ep.X_add_number >> 1;
13300 INSERT_OPERAND (1, IMMH, *ip, imm);
13307 bfd_reloc_code_real_type r[3];
13311 if (my_getSmallExpression (&ep, r, s) > 0
13312 || !expr_const_in_range (&ep, -1, 127, 0))
13315 imm = ep.X_add_number & 127;
13316 INSERT_OPERAND (1, IMMI, *ip, imm);
13323 bfd_reloc_code_real_type r[3];
13327 /* Check whether there is only a single bracketed
13328 expression left. If so, it must be the base register
13329 and the constant must be zero. */
13330 if (*s == '(' && strchr (s + 1, '(') == 0)
13332 INSERT_OPERAND (1, IMMJ, *ip, 0);
13336 if (my_getSmallExpression (&ep, r, s) > 0
13337 || !expr_const_in_range (&ep, 0, 16, 2))
13340 imm = ep.X_add_number >> 2;
13341 INSERT_OPERAND (1, IMMJ, *ip, imm);
13348 bfd_reloc_code_real_type r[3];
13352 /* Check whether there is only a single bracketed
13353 expression left. If so, it must be the base register
13354 and the constant must be zero. */
13355 if (*s == '(' && strchr (s + 1, '(') == 0)
13357 INSERT_OPERAND (1, IMML, *ip, 0);
13361 if (my_getSmallExpression (&ep, r, s) > 0
13362 || !expr_const_in_range (&ep, 0, 16, 0))
13365 imm = ep.X_add_number;
13366 INSERT_OPERAND (1, IMML, *ip, imm);
13373 bfd_reloc_code_real_type r[3];
13377 if (my_getSmallExpression (&ep, r, s) > 0
13378 || !expr_const_in_range (&ep, 1, 9, 0))
13381 imm = ep.X_add_number & 7;
13382 INSERT_OPERAND (1, IMMM, *ip, imm);
13387 case 'N': /* Register list for lwm and swm. */
13389 /* A comma-separated list of registers and/or
13390 dash-separated contiguous ranges including
13391 both ra and a set of one or more registers
13392 starting at s0 up to s3 which have to be
13399 and any permutations of these. */
13400 unsigned int reglist;
13403 if (!reglist_lookup (&s, RTYPE_NUM | RTYPE_GP, ®list))
13406 if ((reglist & 0xfff1ffff) != 0x80010000)
13409 reglist = (reglist >> 17) & 7;
13411 if ((reglist & -reglist) != reglist)
13414 imm = ffs (reglist) - 1;
13415 INSERT_OPERAND (1, IMMN, *ip, imm);
13419 case 'O': /* sdbbp 4-bit code. */
13421 bfd_reloc_code_real_type r[3];
13425 if (my_getSmallExpression (&ep, r, s) > 0
13426 || !expr_const_in_range (&ep, 0, 16, 0))
13429 imm = ep.X_add_number;
13430 INSERT_OPERAND (1, IMMO, *ip, imm);
13437 bfd_reloc_code_real_type r[3];
13441 if (my_getSmallExpression (&ep, r, s) > 0
13442 || !expr_const_in_range (&ep, 0, 32, 2))
13445 imm = ep.X_add_number >> 2;
13446 INSERT_OPERAND (1, IMMP, *ip, imm);
13453 bfd_reloc_code_real_type r[3];
13457 if (my_getSmallExpression (&ep, r, s) > 0
13458 || !expr_const_in_range (&ep, -0x400000, 0x400000, 2))
13461 imm = ep.X_add_number >> 2;
13462 INSERT_OPERAND (1, IMMQ, *ip, imm);
13469 bfd_reloc_code_real_type r[3];
13473 /* Check whether there is only a single bracketed
13474 expression left. If so, it must be the base register
13475 and the constant must be zero. */
13476 if (*s == '(' && strchr (s + 1, '(') == 0)
13478 INSERT_OPERAND (1, IMMU, *ip, 0);
13482 if (my_getSmallExpression (&ep, r, s) > 0
13483 || !expr_const_in_range (&ep, 0, 32, 2))
13486 imm = ep.X_add_number >> 2;
13487 INSERT_OPERAND (1, IMMU, *ip, imm);
13494 bfd_reloc_code_real_type r[3];
13498 if (my_getSmallExpression (&ep, r, s) > 0
13499 || !expr_const_in_range (&ep, 0, 64, 2))
13502 imm = ep.X_add_number >> 2;
13503 INSERT_OPERAND (1, IMMW, *ip, imm);
13510 bfd_reloc_code_real_type r[3];
13514 if (my_getSmallExpression (&ep, r, s) > 0
13515 || !expr_const_in_range (&ep, -8, 8, 0))
13518 imm = ep.X_add_number;
13519 INSERT_OPERAND (1, IMMX, *ip, imm);
13526 bfd_reloc_code_real_type r[3];
13530 if (my_getSmallExpression (&ep, r, s) > 0
13531 || expr_const_in_range (&ep, -2, 2, 2)
13532 || !expr_const_in_range (&ep, -258, 258, 2))
13535 imm = ep.X_add_number >> 2;
13536 imm = ((imm >> 1) & ~0xff) | (imm & 0xff);
13537 INSERT_OPERAND (1, IMMY, *ip, imm);
13544 bfd_reloc_code_real_type r[3];
13547 if (my_getSmallExpression (&ep, r, s) > 0
13548 || !expr_const_in_range (&ep, 0, 1, 0))
13555 as_bad (_("Internal error: bad microMIPS opcode "
13556 "(unknown extension operand type `m%c'): %s %s"),
13557 *args, insn->name, insn->args);
13558 /* Further processing is fruitless. */
13563 case 'n': /* Register list for 32-bit lwm and swm. */
13564 gas_assert (mips_opts.micromips);
13566 /* A comma-separated list of registers and/or
13567 dash-separated contiguous ranges including
13568 at least one of ra and a set of one or more
13569 registers starting at s0 up to s7 and then
13570 s8 which have to be consecutive, e.g.:
13578 and any permutations of these. */
13579 unsigned int reglist;
13583 if (!reglist_lookup (&s, RTYPE_NUM | RTYPE_GP, ®list))
13586 if ((reglist & 0x3f00ffff) != 0)
13589 ra = (reglist >> 27) & 0x10;
13590 reglist = ((reglist >> 22) & 0x100) | ((reglist >> 16) & 0xff);
13592 if ((reglist & -reglist) != reglist)
13595 imm = (ffs (reglist) - 1) | ra;
13596 INSERT_OPERAND (1, RT, *ip, imm);
13597 imm_expr.X_op = O_absent;
13601 case '|': /* 4-bit trap code. */
13602 gas_assert (mips_opts.micromips);
13603 my_getExpression (&imm_expr, s);
13604 check_absolute_expr (ip, &imm_expr);
13605 if ((unsigned long) imm_expr.X_add_number
13606 > MICROMIPSOP_MASK_TRAP)
13607 as_bad (_("Trap code (%lu) for %s not in 0..15 range"),
13608 (unsigned long) imm_expr.X_add_number,
13609 ip->insn_mo->name);
13610 INSERT_OPERAND (1, TRAP, *ip, imm_expr.X_add_number);
13611 imm_expr.X_op = O_absent;
13616 as_bad (_("Bad char = '%c'\n"), *args);
13621 /* Args don't match. */
13623 insn_error = _("Illegal operands");
13624 if (insn + 1 < past && !strcmp (insn->name, insn[1].name))
13629 else if (wrong_delay_slot_insns && need_delay_slot_ok)
13631 gas_assert (firstinsn);
13632 need_delay_slot_ok = FALSE;
13641 #define SKIP_SPACE_TABS(S) { while (*(S) == ' ' || *(S) == '\t') ++(S); }
13643 /* This routine assembles an instruction into its binary format when
13644 assembling for the mips16. As a side effect, it sets one of the
13645 global variables imm_reloc or offset_reloc to the type of relocation
13646 to do if one of the operands is an address expression. It also sets
13647 forced_insn_length to the resulting instruction size in bytes if the
13648 user explicitly requested a small or extended instruction. */
13651 mips16_ip (char *str, struct mips_cl_insn *ip)
13655 struct mips_opcode *insn;
13657 unsigned int regno;
13658 unsigned int lastregno = 0;
13664 forced_insn_length = 0;
13666 for (s = str; ISLOWER (*s); ++s)
13678 if (s[1] == 't' && s[2] == ' ')
13681 forced_insn_length = 2;
13685 else if (s[1] == 'e' && s[2] == ' ')
13688 forced_insn_length = 4;
13692 /* Fall through. */
13694 insn_error = _("unknown opcode");
13698 if (mips_opts.noautoextend && !forced_insn_length)
13699 forced_insn_length = 2;
13701 if ((insn = (struct mips_opcode *) hash_find (mips16_op_hash, str)) == NULL)
13703 insn_error = _("unrecognized opcode");
13712 gas_assert (strcmp (insn->name, str) == 0);
13714 ok = is_opcode_valid_16 (insn);
13717 if (insn + 1 < &mips16_opcodes[bfd_mips16_num_opcodes]
13718 && strcmp (insn->name, insn[1].name) == 0)
13727 static char buf[100];
13729 _("Opcode not supported on this processor: %s (%s)"),
13730 mips_cpu_info_from_arch (mips_opts.arch)->name,
13731 mips_cpu_info_from_isa (mips_opts.isa)->name);
13738 create_insn (ip, insn);
13739 imm_expr.X_op = O_absent;
13740 imm_reloc[0] = BFD_RELOC_UNUSED;
13741 imm_reloc[1] = BFD_RELOC_UNUSED;
13742 imm_reloc[2] = BFD_RELOC_UNUSED;
13743 imm2_expr.X_op = O_absent;
13744 offset_expr.X_op = O_absent;
13745 offset_reloc[0] = BFD_RELOC_UNUSED;
13746 offset_reloc[1] = BFD_RELOC_UNUSED;
13747 offset_reloc[2] = BFD_RELOC_UNUSED;
13748 for (args = insn->args; 1; ++args)
13755 /* In this switch statement we call break if we did not find
13756 a match, continue if we did find a match, or return if we
13767 /* Stuff the immediate value in now, if we can. */
13768 if (imm_expr.X_op == O_constant
13769 && *imm_reloc > BFD_RELOC_UNUSED
13770 && insn->pinfo != INSN_MACRO
13771 && calculate_reloc (*offset_reloc,
13772 imm_expr.X_add_number, &value))
13774 mips16_immed (NULL, 0, *imm_reloc - BFD_RELOC_UNUSED,
13775 *offset_reloc, value, forced_insn_length,
13777 imm_expr.X_op = O_absent;
13778 *imm_reloc = BFD_RELOC_UNUSED;
13779 *offset_reloc = BFD_RELOC_UNUSED;
13793 MIPS16_INSERT_OPERAND (RX, *ip, lastregno);
13796 MIPS16_INSERT_OPERAND (RY, *ip, lastregno);
13812 MIPS16_INSERT_OPERAND (RX, *ip, lastregno);
13814 MIPS16_INSERT_OPERAND (RY, *ip, lastregno);
13818 /* Fall through. */
13829 if (!reg_lookup (&s, RTYPE_NUM | RTYPE_GP, ®no))
13831 if (c == 'v' || c == 'w')
13834 MIPS16_INSERT_OPERAND (RX, *ip, lastregno);
13836 MIPS16_INSERT_OPERAND (RY, *ip, lastregno);
13847 if (c == 'v' || c == 'w')
13849 regno = mips16_to_32_reg_map[lastregno];
13863 regno = mips32_to_16_reg_map[regno];
13868 regno = ILLEGAL_REG;
13873 regno = ILLEGAL_REG;
13878 regno = ILLEGAL_REG;
13883 if (regno == AT && mips_opts.at)
13885 if (mips_opts.at == ATREG)
13886 as_warn (_("used $at without \".set noat\""));
13888 as_warn (_("used $%u with \".set at=$%u\""),
13889 regno, mips_opts.at);
13897 if (regno == ILLEGAL_REG)
13904 MIPS16_INSERT_OPERAND (RX, *ip, regno);
13908 MIPS16_INSERT_OPERAND (RY, *ip, regno);
13911 MIPS16_INSERT_OPERAND (RZ, *ip, regno);
13914 MIPS16_INSERT_OPERAND (MOVE32Z, *ip, regno);
13920 MIPS16_INSERT_OPERAND (REGR32, *ip, regno);
13923 regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3);
13924 MIPS16_INSERT_OPERAND (REG32R, *ip, regno);
13934 if (strncmp (s, "$pc", 3) == 0)
13951 i = my_getSmallExpression (&imm_expr, imm_reloc, s);
13954 if (imm_expr.X_op != O_constant)
13956 forced_insn_length = 4;
13957 ip->insn_opcode |= MIPS16_EXTEND;
13961 /* We need to relax this instruction. */
13962 *offset_reloc = *imm_reloc;
13963 *imm_reloc = (int) BFD_RELOC_UNUSED + c;
13968 *imm_reloc = BFD_RELOC_UNUSED;
13969 /* Fall through. */
13976 my_getExpression (&imm_expr, s);
13977 if (imm_expr.X_op == O_register)
13979 /* What we thought was an expression turned out to
13982 if (s[0] == '(' && args[1] == '(')
13984 /* It looks like the expression was omitted
13985 before a register indirection, which means
13986 that the expression is implicitly zero. We
13987 still set up imm_expr, so that we handle
13988 explicit extensions correctly. */
13989 imm_expr.X_op = O_constant;
13990 imm_expr.X_add_number = 0;
13991 *imm_reloc = (int) BFD_RELOC_UNUSED + c;
13998 /* We need to relax this instruction. */
13999 *imm_reloc = (int) BFD_RELOC_UNUSED + c;
14008 /* We use offset_reloc rather than imm_reloc for the PC
14009 relative operands. This lets macros with both
14010 immediate and address operands work correctly. */
14011 my_getExpression (&offset_expr, s);
14013 if (offset_expr.X_op == O_register)
14016 /* We need to relax this instruction. */
14017 *offset_reloc = (int) BFD_RELOC_UNUSED + c;
14021 case '6': /* break code */
14022 my_getExpression (&imm_expr, s);
14023 check_absolute_expr (ip, &imm_expr);
14024 if ((unsigned long) imm_expr.X_add_number > 63)
14025 as_warn (_("Invalid value for `%s' (%lu)"),
14027 (unsigned long) imm_expr.X_add_number);
14028 MIPS16_INSERT_OPERAND (IMM6, *ip, imm_expr.X_add_number);
14029 imm_expr.X_op = O_absent;
14033 case 'a': /* 26 bit address */
14034 my_getExpression (&offset_expr, s);
14036 *offset_reloc = BFD_RELOC_MIPS16_JMP;
14037 ip->insn_opcode <<= 16;
14040 case 'l': /* register list for entry macro */
14041 case 'L': /* register list for exit macro */
14051 unsigned int freg, reg1, reg2;
14053 while (*s == ' ' || *s == ',')
14055 if (reg_lookup (&s, RTYPE_GP | RTYPE_NUM, ®1))
14057 else if (reg_lookup (&s, RTYPE_FPU, ®1))
14061 as_bad (_("can't parse register list"));
14071 if (!reg_lookup (&s, freg ? RTYPE_FPU
14072 : (RTYPE_GP | RTYPE_NUM), ®2))
14074 as_bad (_("invalid register list"));
14078 if (freg && reg1 == 0 && reg2 == 0 && c == 'L')
14080 mask &= ~ (7 << 3);
14083 else if (freg && reg1 == 0 && reg2 == 1 && c == 'L')
14085 mask &= ~ (7 << 3);
14088 else if (reg1 == 4 && reg2 >= 4 && reg2 <= 7 && c != 'L')
14089 mask |= (reg2 - 3) << 3;
14090 else if (reg1 == 16 && reg2 >= 16 && reg2 <= 17)
14091 mask |= (reg2 - 15) << 1;
14092 else if (reg1 == RA && reg2 == RA)
14096 as_bad (_("invalid register list"));
14100 /* The mask is filled in in the opcode table for the
14101 benefit of the disassembler. We remove it before
14102 applying the actual mask. */
14103 ip->insn_opcode &= ~ ((7 << 3) << MIPS16OP_SH_IMM6);
14104 ip->insn_opcode |= mask << MIPS16OP_SH_IMM6;
14108 case 'm': /* Register list for save insn. */
14109 case 'M': /* Register list for restore insn. */
14111 int opcode = ip->insn_opcode;
14112 int framesz = 0, seen_framesz = 0;
14113 int nargs = 0, statics = 0, sregs = 0;
14117 unsigned int reg1, reg2;
14119 SKIP_SPACE_TABS (s);
14122 SKIP_SPACE_TABS (s);
14124 my_getExpression (&imm_expr, s);
14125 if (imm_expr.X_op == O_constant)
14127 /* Handle the frame size. */
14130 as_bad (_("more than one frame size in list"));
14134 framesz = imm_expr.X_add_number;
14135 imm_expr.X_op = O_absent;
14140 if (! reg_lookup (&s, RTYPE_GP | RTYPE_NUM, ®1))
14142 as_bad (_("can't parse register list"));
14154 if (! reg_lookup (&s, RTYPE_GP | RTYPE_NUM, ®2)
14157 as_bad (_("can't parse register list"));
14162 while (reg1 <= reg2)
14164 if (reg1 >= 4 && reg1 <= 7)
14168 nargs |= 1 << (reg1 - 4);
14170 /* statics $a0-$a3 */
14171 statics |= 1 << (reg1 - 4);
14173 else if ((reg1 >= 16 && reg1 <= 23) || reg1 == 30)
14176 sregs |= 1 << ((reg1 == 30) ? 8 : (reg1 - 16));
14178 else if (reg1 == 31)
14180 /* Add $ra to insn. */
14185 as_bad (_("unexpected register in list"));
14193 /* Encode args/statics combination. */
14194 if (nargs & statics)
14195 as_bad (_("arg/static registers overlap"));
14196 else if (nargs == 0xf)
14197 /* All $a0-$a3 are args. */
14198 opcode |= MIPS16_ALL_ARGS << 16;
14199 else if (statics == 0xf)
14200 /* All $a0-$a3 are statics. */
14201 opcode |= MIPS16_ALL_STATICS << 16;
14204 int narg = 0, nstat = 0;
14206 /* Count arg registers. */
14207 while (nargs & 0x1)
14213 as_bad (_("invalid arg register list"));
14215 /* Count static registers. */
14216 while (statics & 0x8)
14218 statics = (statics << 1) & 0xf;
14222 as_bad (_("invalid static register list"));
14224 /* Encode args/statics. */
14225 opcode |= ((narg << 2) | nstat) << 16;
14228 /* Encode $s0/$s1. */
14229 if (sregs & (1 << 0)) /* $s0 */
14231 if (sregs & (1 << 1)) /* $s1 */
14237 /* Count regs $s2-$s8. */
14245 as_bad (_("invalid static register list"));
14246 /* Encode $s2-$s8. */
14247 opcode |= nsreg << 24;
14250 /* Encode frame size. */
14252 as_bad (_("missing frame size"));
14253 else if ((framesz & 7) != 0 || framesz < 0
14254 || framesz > 0xff * 8)
14255 as_bad (_("invalid frame size"));
14256 else if (framesz != 128 || (opcode >> 16) != 0)
14259 opcode |= (((framesz & 0xf0) << 16)
14260 | (framesz & 0x0f));
14263 /* Finally build the instruction. */
14264 if ((opcode >> 16) != 0 || framesz == 0)
14265 opcode |= MIPS16_EXTEND;
14266 ip->insn_opcode = opcode;
14270 case 'e': /* extend code */
14271 my_getExpression (&imm_expr, s);
14272 check_absolute_expr (ip, &imm_expr);
14273 if ((unsigned long) imm_expr.X_add_number > 0x7ff)
14275 as_warn (_("Invalid value for `%s' (%lu)"),
14277 (unsigned long) imm_expr.X_add_number);
14278 imm_expr.X_add_number &= 0x7ff;
14280 ip->insn_opcode |= imm_expr.X_add_number;
14281 imm_expr.X_op = O_absent;
14291 /* Args don't match. */
14292 if (insn + 1 < &mips16_opcodes[bfd_mips16_num_opcodes] &&
14293 strcmp (insn->name, insn[1].name) == 0)
14300 insn_error = _("illegal operands");
14306 /* This structure holds information we know about a mips16 immediate
14309 struct mips16_immed_operand
14311 /* The type code used in the argument string in the opcode table. */
14313 /* The number of bits in the short form of the opcode. */
14315 /* The number of bits in the extended form of the opcode. */
14317 /* The amount by which the short form is shifted when it is used;
14318 for example, the sw instruction has a shift count of 2. */
14320 /* The amount by which the short form is shifted when it is stored
14321 into the instruction code. */
14323 /* Non-zero if the short form is unsigned. */
14325 /* Non-zero if the extended form is unsigned. */
14327 /* Non-zero if the value is PC relative. */
14331 /* The mips16 immediate operand types. */
14333 static const struct mips16_immed_operand mips16_immed_operands[] =
14335 { '<', 3, 5, 0, MIPS16OP_SH_RZ, 1, 1, 0 },
14336 { '>', 3, 5, 0, MIPS16OP_SH_RX, 1, 1, 0 },
14337 { '[', 3, 6, 0, MIPS16OP_SH_RZ, 1, 1, 0 },
14338 { ']', 3, 6, 0, MIPS16OP_SH_RX, 1, 1, 0 },
14339 { '4', 4, 15, 0, MIPS16OP_SH_IMM4, 0, 0, 0 },
14340 { '5', 5, 16, 0, MIPS16OP_SH_IMM5, 1, 0, 0 },
14341 { 'H', 5, 16, 1, MIPS16OP_SH_IMM5, 1, 0, 0 },
14342 { 'W', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 0 },
14343 { 'D', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 0 },
14344 { 'j', 5, 16, 0, MIPS16OP_SH_IMM5, 0, 0, 0 },
14345 { '8', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 0, 0 },
14346 { 'V', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 0 },
14347 { 'C', 8, 16, 3, MIPS16OP_SH_IMM8, 1, 0, 0 },
14348 { 'U', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 1, 0 },
14349 { 'k', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 0 },
14350 { 'K', 8, 16, 3, MIPS16OP_SH_IMM8, 0, 0, 0 },
14351 { 'p', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 },
14352 { 'q', 11, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 },
14353 { 'A', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 1 },
14354 { 'B', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 1 },
14355 { 'E', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 1 }
14358 #define MIPS16_NUM_IMMED \
14359 (sizeof mips16_immed_operands / sizeof mips16_immed_operands[0])
14361 /* Marshal immediate value VAL for an extended MIPS16 instruction.
14362 NBITS is the number of significant bits in VAL. */
14364 static unsigned long
14365 mips16_immed_extend (offsetT val, unsigned int nbits)
14370 extval = ((val >> 11) & 0x1f) | (val & 0x7e0);
14373 else if (nbits == 15)
14375 extval = ((val >> 11) & 0xf) | (val & 0x7f0);
14380 extval = ((val & 0x1f) << 6) | (val & 0x20);
14383 return (extval << 16) | val;
14386 /* Install immediate value VAL into MIPS16 instruction *INSN,
14387 extending it if necessary. The instruction in *INSN may
14388 already be extended.
14390 RELOC is the relocation that produced VAL, or BFD_RELOC_UNUSED
14391 if none. In the former case, VAL is a 16-bit number with no
14392 defined signedness.
14394 TYPE is the type of the immediate field. USER_INSN_LENGTH
14395 is the length that the user requested, or 0 if none. */
14398 mips16_immed (char *file, unsigned int line, int type,
14399 bfd_reloc_code_real_type reloc, offsetT val,
14400 unsigned int user_insn_length, unsigned long *insn)
14402 const struct mips16_immed_operand *op;
14403 int mintiny, maxtiny;
14405 op = mips16_immed_operands;
14406 while (op->type != type)
14409 gas_assert (op < mips16_immed_operands + MIPS16_NUM_IMMED);
14414 if (type == '<' || type == '>' || type == '[' || type == ']')
14417 maxtiny = 1 << op->nbits;
14422 maxtiny = (1 << op->nbits) - 1;
14424 if (reloc != BFD_RELOC_UNUSED)
14429 mintiny = - (1 << (op->nbits - 1));
14430 maxtiny = (1 << (op->nbits - 1)) - 1;
14431 if (reloc != BFD_RELOC_UNUSED)
14432 val = SEXT_16BIT (val);
14435 /* Branch offsets have an implicit 0 in the lowest bit. */
14436 if (type == 'p' || type == 'q')
14439 if ((val & ((1 << op->shift) - 1)) != 0
14440 || val < (mintiny << op->shift)
14441 || val > (maxtiny << op->shift))
14443 /* We need an extended instruction. */
14444 if (user_insn_length == 2)
14445 as_bad_where (file, line, _("invalid unextended operand value"));
14447 *insn |= MIPS16_EXTEND;
14449 else if (user_insn_length == 4)
14451 /* The operand doesn't force an unextended instruction to be extended.
14452 Warn if the user wanted an extended instruction anyway. */
14453 *insn |= MIPS16_EXTEND;
14454 as_warn_where (file, line,
14455 _("extended operand requested but not required"));
14458 if (mips16_opcode_length (*insn) == 2)
14462 insnval = ((val >> op->shift) & ((1 << op->nbits) - 1));
14463 insnval <<= op->op_shift;
14468 long minext, maxext;
14470 if (reloc == BFD_RELOC_UNUSED)
14475 maxext = (1 << op->extbits) - 1;
14479 minext = - (1 << (op->extbits - 1));
14480 maxext = (1 << (op->extbits - 1)) - 1;
14482 if (val < minext || val > maxext)
14483 as_bad_where (file, line,
14484 _("operand value out of range for instruction"));
14487 *insn |= mips16_immed_extend (val, op->extbits);
14491 struct percent_op_match
14494 bfd_reloc_code_real_type reloc;
14497 static const struct percent_op_match mips_percent_op[] =
14499 {"%lo", BFD_RELOC_LO16},
14501 {"%call_hi", BFD_RELOC_MIPS_CALL_HI16},
14502 {"%call_lo", BFD_RELOC_MIPS_CALL_LO16},
14503 {"%call16", BFD_RELOC_MIPS_CALL16},
14504 {"%got_disp", BFD_RELOC_MIPS_GOT_DISP},
14505 {"%got_page", BFD_RELOC_MIPS_GOT_PAGE},
14506 {"%got_ofst", BFD_RELOC_MIPS_GOT_OFST},
14507 {"%got_hi", BFD_RELOC_MIPS_GOT_HI16},
14508 {"%got_lo", BFD_RELOC_MIPS_GOT_LO16},
14509 {"%got", BFD_RELOC_MIPS_GOT16},
14510 {"%gp_rel", BFD_RELOC_GPREL16},
14511 {"%half", BFD_RELOC_16},
14512 {"%highest", BFD_RELOC_MIPS_HIGHEST},
14513 {"%higher", BFD_RELOC_MIPS_HIGHER},
14514 {"%neg", BFD_RELOC_MIPS_SUB},
14515 {"%tlsgd", BFD_RELOC_MIPS_TLS_GD},
14516 {"%tlsldm", BFD_RELOC_MIPS_TLS_LDM},
14517 {"%dtprel_hi", BFD_RELOC_MIPS_TLS_DTPREL_HI16},
14518 {"%dtprel_lo", BFD_RELOC_MIPS_TLS_DTPREL_LO16},
14519 {"%tprel_hi", BFD_RELOC_MIPS_TLS_TPREL_HI16},
14520 {"%tprel_lo", BFD_RELOC_MIPS_TLS_TPREL_LO16},
14521 {"%gottprel", BFD_RELOC_MIPS_TLS_GOTTPREL},
14523 {"%hi", BFD_RELOC_HI16_S}
14526 static const struct percent_op_match mips16_percent_op[] =
14528 {"%lo", BFD_RELOC_MIPS16_LO16},
14529 {"%gprel", BFD_RELOC_MIPS16_GPREL},
14530 {"%got", BFD_RELOC_MIPS16_GOT16},
14531 {"%call16", BFD_RELOC_MIPS16_CALL16},
14532 {"%hi", BFD_RELOC_MIPS16_HI16_S},
14533 {"%tlsgd", BFD_RELOC_MIPS16_TLS_GD},
14534 {"%tlsldm", BFD_RELOC_MIPS16_TLS_LDM},
14535 {"%dtprel_hi", BFD_RELOC_MIPS16_TLS_DTPREL_HI16},
14536 {"%dtprel_lo", BFD_RELOC_MIPS16_TLS_DTPREL_LO16},
14537 {"%tprel_hi", BFD_RELOC_MIPS16_TLS_TPREL_HI16},
14538 {"%tprel_lo", BFD_RELOC_MIPS16_TLS_TPREL_LO16},
14539 {"%gottprel", BFD_RELOC_MIPS16_TLS_GOTTPREL}
14543 /* Return true if *STR points to a relocation operator. When returning true,
14544 move *STR over the operator and store its relocation code in *RELOC.
14545 Leave both *STR and *RELOC alone when returning false. */
14548 parse_relocation (char **str, bfd_reloc_code_real_type *reloc)
14550 const struct percent_op_match *percent_op;
14553 if (mips_opts.mips16)
14555 percent_op = mips16_percent_op;
14556 limit = ARRAY_SIZE (mips16_percent_op);
14560 percent_op = mips_percent_op;
14561 limit = ARRAY_SIZE (mips_percent_op);
14564 for (i = 0; i < limit; i++)
14565 if (strncasecmp (*str, percent_op[i].str, strlen (percent_op[i].str)) == 0)
14567 int len = strlen (percent_op[i].str);
14569 if (!ISSPACE ((*str)[len]) && (*str)[len] != '(')
14572 *str += strlen (percent_op[i].str);
14573 *reloc = percent_op[i].reloc;
14575 /* Check whether the output BFD supports this relocation.
14576 If not, issue an error and fall back on something safe. */
14577 if (!bfd_reloc_type_lookup (stdoutput, percent_op[i].reloc))
14579 as_bad (_("relocation %s isn't supported by the current ABI"),
14580 percent_op[i].str);
14581 *reloc = BFD_RELOC_UNUSED;
14589 /* Parse string STR as a 16-bit relocatable operand. Store the
14590 expression in *EP and the relocations in the array starting
14591 at RELOC. Return the number of relocation operators used.
14593 On exit, EXPR_END points to the first character after the expression. */
14596 my_getSmallExpression (expressionS *ep, bfd_reloc_code_real_type *reloc,
14599 bfd_reloc_code_real_type reversed_reloc[3];
14600 size_t reloc_index, i;
14601 int crux_depth, str_depth;
14604 /* Search for the start of the main expression, recoding relocations
14605 in REVERSED_RELOC. End the loop with CRUX pointing to the start
14606 of the main expression and with CRUX_DEPTH containing the number
14607 of open brackets at that point. */
14614 crux_depth = str_depth;
14616 /* Skip over whitespace and brackets, keeping count of the number
14618 while (*str == ' ' || *str == '\t' || *str == '(')
14623 && reloc_index < (HAVE_NEWABI ? 3 : 1)
14624 && parse_relocation (&str, &reversed_reloc[reloc_index]));
14626 my_getExpression (ep, crux);
14629 /* Match every open bracket. */
14630 while (crux_depth > 0 && (*str == ')' || *str == ' ' || *str == '\t'))
14634 if (crux_depth > 0)
14635 as_bad (_("unclosed '('"));
14639 if (reloc_index != 0)
14641 prev_reloc_op_frag = frag_now;
14642 for (i = 0; i < reloc_index; i++)
14643 reloc[i] = reversed_reloc[reloc_index - 1 - i];
14646 return reloc_index;
14650 my_getExpression (expressionS *ep, char *str)
14654 save_in = input_line_pointer;
14655 input_line_pointer = str;
14657 expr_end = input_line_pointer;
14658 input_line_pointer = save_in;
14662 md_atof (int type, char *litP, int *sizeP)
14664 return ieee_md_atof (type, litP, sizeP, target_big_endian);
14668 md_number_to_chars (char *buf, valueT val, int n)
14670 if (target_big_endian)
14671 number_to_chars_bigendian (buf, val, n);
14673 number_to_chars_littleendian (buf, val, n);
14677 static int support_64bit_objects(void)
14679 const char **list, **l;
14682 list = bfd_target_list ();
14683 for (l = list; *l != NULL; l++)
14684 if (strcmp (*l, ELF_TARGET ("elf64-", "big")) == 0
14685 || strcmp (*l, ELF_TARGET ("elf64-", "little")) == 0)
14687 yes = (*l != NULL);
14691 #endif /* OBJ_ELF */
14693 const char *md_shortopts = "O::g::G:";
14697 OPTION_MARCH = OPTION_MD_BASE,
14721 OPTION_NO_SMARTMIPS,
14727 OPTION_NO_MICROMIPS,
14730 OPTION_COMPAT_ARCH_BASE,
14739 OPTION_M7000_HILO_FIX,
14740 OPTION_MNO_7000_HILO_FIX,
14743 OPTION_FIX_LOONGSON2F_JUMP,
14744 OPTION_NO_FIX_LOONGSON2F_JUMP,
14745 OPTION_FIX_LOONGSON2F_NOP,
14746 OPTION_NO_FIX_LOONGSON2F_NOP,
14748 OPTION_NO_FIX_VR4120,
14750 OPTION_NO_FIX_VR4130,
14751 OPTION_FIX_CN63XXP1,
14752 OPTION_NO_FIX_CN63XXP1,
14759 OPTION_CONSTRUCT_FLOATS,
14760 OPTION_NO_CONSTRUCT_FLOATS,
14763 OPTION_RELAX_BRANCH,
14764 OPTION_NO_RELAX_BRANCH,
14771 OPTION_SINGLE_FLOAT,
14772 OPTION_DOUBLE_FLOAT,
14775 OPTION_CALL_SHARED,
14776 OPTION_CALL_NONPIC,
14786 OPTION_MVXWORKS_PIC,
14787 #endif /* OBJ_ELF */
14791 struct option md_longopts[] =
14793 /* Options which specify architecture. */
14794 {"march", required_argument, NULL, OPTION_MARCH},
14795 {"mtune", required_argument, NULL, OPTION_MTUNE},
14796 {"mips0", no_argument, NULL, OPTION_MIPS1},
14797 {"mips1", no_argument, NULL, OPTION_MIPS1},
14798 {"mips2", no_argument, NULL, OPTION_MIPS2},
14799 {"mips3", no_argument, NULL, OPTION_MIPS3},
14800 {"mips4", no_argument, NULL, OPTION_MIPS4},
14801 {"mips5", no_argument, NULL, OPTION_MIPS5},
14802 {"mips32", no_argument, NULL, OPTION_MIPS32},
14803 {"mips64", no_argument, NULL, OPTION_MIPS64},
14804 {"mips32r2", no_argument, NULL, OPTION_MIPS32R2},
14805 {"mips64r2", no_argument, NULL, OPTION_MIPS64R2},
14807 /* Options which specify Application Specific Extensions (ASEs). */
14808 {"mips16", no_argument, NULL, OPTION_MIPS16},
14809 {"no-mips16", no_argument, NULL, OPTION_NO_MIPS16},
14810 {"mips3d", no_argument, NULL, OPTION_MIPS3D},
14811 {"no-mips3d", no_argument, NULL, OPTION_NO_MIPS3D},
14812 {"mdmx", no_argument, NULL, OPTION_MDMX},
14813 {"no-mdmx", no_argument, NULL, OPTION_NO_MDMX},
14814 {"mdsp", no_argument, NULL, OPTION_DSP},
14815 {"mno-dsp", no_argument, NULL, OPTION_NO_DSP},
14816 {"mmt", no_argument, NULL, OPTION_MT},
14817 {"mno-mt", no_argument, NULL, OPTION_NO_MT},
14818 {"msmartmips", no_argument, NULL, OPTION_SMARTMIPS},
14819 {"mno-smartmips", no_argument, NULL, OPTION_NO_SMARTMIPS},
14820 {"mdspr2", no_argument, NULL, OPTION_DSPR2},
14821 {"mno-dspr2", no_argument, NULL, OPTION_NO_DSPR2},
14822 {"meva", no_argument, NULL, OPTION_EVA},
14823 {"mno-eva", no_argument, NULL, OPTION_NO_EVA},
14824 {"mmicromips", no_argument, NULL, OPTION_MICROMIPS},
14825 {"mno-micromips", no_argument, NULL, OPTION_NO_MICROMIPS},
14826 {"mmcu", no_argument, NULL, OPTION_MCU},
14827 {"mno-mcu", no_argument, NULL, OPTION_NO_MCU},
14828 {"mvirt", no_argument, NULL, OPTION_VIRT},
14829 {"mno-virt", no_argument, NULL, OPTION_NO_VIRT},
14831 /* Old-style architecture options. Don't add more of these. */
14832 {"m4650", no_argument, NULL, OPTION_M4650},
14833 {"no-m4650", no_argument, NULL, OPTION_NO_M4650},
14834 {"m4010", no_argument, NULL, OPTION_M4010},
14835 {"no-m4010", no_argument, NULL, OPTION_NO_M4010},
14836 {"m4100", no_argument, NULL, OPTION_M4100},
14837 {"no-m4100", no_argument, NULL, OPTION_NO_M4100},
14838 {"m3900", no_argument, NULL, OPTION_M3900},
14839 {"no-m3900", no_argument, NULL, OPTION_NO_M3900},
14841 /* Options which enable bug fixes. */
14842 {"mfix7000", no_argument, NULL, OPTION_M7000_HILO_FIX},
14843 {"no-fix-7000", no_argument, NULL, OPTION_MNO_7000_HILO_FIX},
14844 {"mno-fix7000", no_argument, NULL, OPTION_MNO_7000_HILO_FIX},
14845 {"mfix-loongson2f-jump", no_argument, NULL, OPTION_FIX_LOONGSON2F_JUMP},
14846 {"mno-fix-loongson2f-jump", no_argument, NULL, OPTION_NO_FIX_LOONGSON2F_JUMP},
14847 {"mfix-loongson2f-nop", no_argument, NULL, OPTION_FIX_LOONGSON2F_NOP},
14848 {"mno-fix-loongson2f-nop", no_argument, NULL, OPTION_NO_FIX_LOONGSON2F_NOP},
14849 {"mfix-vr4120", no_argument, NULL, OPTION_FIX_VR4120},
14850 {"mno-fix-vr4120", no_argument, NULL, OPTION_NO_FIX_VR4120},
14851 {"mfix-vr4130", no_argument, NULL, OPTION_FIX_VR4130},
14852 {"mno-fix-vr4130", no_argument, NULL, OPTION_NO_FIX_VR4130},
14853 {"mfix-24k", no_argument, NULL, OPTION_FIX_24K},
14854 {"mno-fix-24k", no_argument, NULL, OPTION_NO_FIX_24K},
14855 {"mfix-cn63xxp1", no_argument, NULL, OPTION_FIX_CN63XXP1},
14856 {"mno-fix-cn63xxp1", no_argument, NULL, OPTION_NO_FIX_CN63XXP1},
14858 /* Miscellaneous options. */
14859 {"trap", no_argument, NULL, OPTION_TRAP},
14860 {"no-break", no_argument, NULL, OPTION_TRAP},
14861 {"break", no_argument, NULL, OPTION_BREAK},
14862 {"no-trap", no_argument, NULL, OPTION_BREAK},
14863 {"EB", no_argument, NULL, OPTION_EB},
14864 {"EL", no_argument, NULL, OPTION_EL},
14865 {"mfp32", no_argument, NULL, OPTION_FP32},
14866 {"mgp32", no_argument, NULL, OPTION_GP32},
14867 {"construct-floats", no_argument, NULL, OPTION_CONSTRUCT_FLOATS},
14868 {"no-construct-floats", no_argument, NULL, OPTION_NO_CONSTRUCT_FLOATS},
14869 {"mfp64", no_argument, NULL, OPTION_FP64},
14870 {"mgp64", no_argument, NULL, OPTION_GP64},
14871 {"relax-branch", no_argument, NULL, OPTION_RELAX_BRANCH},
14872 {"no-relax-branch", no_argument, NULL, OPTION_NO_RELAX_BRANCH},
14873 {"mshared", no_argument, NULL, OPTION_MSHARED},
14874 {"mno-shared", no_argument, NULL, OPTION_MNO_SHARED},
14875 {"msym32", no_argument, NULL, OPTION_MSYM32},
14876 {"mno-sym32", no_argument, NULL, OPTION_MNO_SYM32},
14877 {"msoft-float", no_argument, NULL, OPTION_SOFT_FLOAT},
14878 {"mhard-float", no_argument, NULL, OPTION_HARD_FLOAT},
14879 {"msingle-float", no_argument, NULL, OPTION_SINGLE_FLOAT},
14880 {"mdouble-float", no_argument, NULL, OPTION_DOUBLE_FLOAT},
14882 /* Strictly speaking this next option is ELF specific,
14883 but we allow it for other ports as well in order to
14884 make testing easier. */
14885 {"32", no_argument, NULL, OPTION_32},
14887 /* ELF-specific options. */
14889 {"KPIC", no_argument, NULL, OPTION_CALL_SHARED},
14890 {"call_shared", no_argument, NULL, OPTION_CALL_SHARED},
14891 {"call_nonpic", no_argument, NULL, OPTION_CALL_NONPIC},
14892 {"non_shared", no_argument, NULL, OPTION_NON_SHARED},
14893 {"xgot", no_argument, NULL, OPTION_XGOT},
14894 {"mabi", required_argument, NULL, OPTION_MABI},
14895 {"n32", no_argument, NULL, OPTION_N32},
14896 {"64", no_argument, NULL, OPTION_64},
14897 {"mdebug", no_argument, NULL, OPTION_MDEBUG},
14898 {"no-mdebug", no_argument, NULL, OPTION_NO_MDEBUG},
14899 {"mpdr", no_argument, NULL, OPTION_PDR},
14900 {"mno-pdr", no_argument, NULL, OPTION_NO_PDR},
14901 {"mvxworks-pic", no_argument, NULL, OPTION_MVXWORKS_PIC},
14902 #endif /* OBJ_ELF */
14904 {NULL, no_argument, NULL, 0}
14906 size_t md_longopts_size = sizeof (md_longopts);
14908 /* Set STRING_PTR (either &mips_arch_string or &mips_tune_string) to
14909 NEW_VALUE. Warn if another value was already specified. Note:
14910 we have to defer parsing the -march and -mtune arguments in order
14911 to handle 'from-abi' correctly, since the ABI might be specified
14912 in a later argument. */
14915 mips_set_option_string (const char **string_ptr, const char *new_value)
14917 if (*string_ptr != 0 && strcasecmp (*string_ptr, new_value) != 0)
14918 as_warn (_("A different %s was already specified, is now %s"),
14919 string_ptr == &mips_arch_string ? "-march" : "-mtune",
14922 *string_ptr = new_value;
14926 md_parse_option (int c, char *arg)
14930 case OPTION_CONSTRUCT_FLOATS:
14931 mips_disable_float_construction = 0;
14934 case OPTION_NO_CONSTRUCT_FLOATS:
14935 mips_disable_float_construction = 1;
14947 target_big_endian = 1;
14951 target_big_endian = 0;
14957 else if (arg[0] == '0')
14959 else if (arg[0] == '1')
14969 mips_debug = atoi (arg);
14973 file_mips_isa = ISA_MIPS1;
14977 file_mips_isa = ISA_MIPS2;
14981 file_mips_isa = ISA_MIPS3;
14985 file_mips_isa = ISA_MIPS4;
14989 file_mips_isa = ISA_MIPS5;
14992 case OPTION_MIPS32:
14993 file_mips_isa = ISA_MIPS32;
14996 case OPTION_MIPS32R2:
14997 file_mips_isa = ISA_MIPS32R2;
15000 case OPTION_MIPS64R2:
15001 file_mips_isa = ISA_MIPS64R2;
15004 case OPTION_MIPS64:
15005 file_mips_isa = ISA_MIPS64;
15009 mips_set_option_string (&mips_tune_string, arg);
15013 mips_set_option_string (&mips_arch_string, arg);
15017 mips_set_option_string (&mips_arch_string, "4650");
15018 mips_set_option_string (&mips_tune_string, "4650");
15021 case OPTION_NO_M4650:
15025 mips_set_option_string (&mips_arch_string, "4010");
15026 mips_set_option_string (&mips_tune_string, "4010");
15029 case OPTION_NO_M4010:
15033 mips_set_option_string (&mips_arch_string, "4100");
15034 mips_set_option_string (&mips_tune_string, "4100");
15037 case OPTION_NO_M4100:
15041 mips_set_option_string (&mips_arch_string, "3900");
15042 mips_set_option_string (&mips_tune_string, "3900");
15045 case OPTION_NO_M3900:
15049 mips_opts.ase_mdmx = 1;
15052 case OPTION_NO_MDMX:
15053 mips_opts.ase_mdmx = 0;
15057 mips_opts.ase_dsp = 1;
15058 mips_opts.ase_dspr2 = 0;
15061 case OPTION_NO_DSP:
15062 mips_opts.ase_dsp = 0;
15063 mips_opts.ase_dspr2 = 0;
15067 mips_opts.ase_dspr2 = 1;
15068 mips_opts.ase_dsp = 1;
15071 case OPTION_NO_DSPR2:
15072 mips_opts.ase_dspr2 = 0;
15073 mips_opts.ase_dsp = 0;
15077 mips_opts.ase_eva = 1;
15080 case OPTION_NO_EVA:
15081 mips_opts.ase_eva = 0;
15085 mips_opts.ase_mt = 1;
15089 mips_opts.ase_mt = 0;
15093 mips_opts.ase_mcu = 1;
15096 case OPTION_NO_MCU:
15097 mips_opts.ase_mcu = 0;
15100 case OPTION_MICROMIPS:
15101 if (mips_opts.mips16 == 1)
15103 as_bad (_("-mmicromips cannot be used with -mips16"));
15106 mips_opts.micromips = 1;
15107 mips_no_prev_insn ();
15110 case OPTION_NO_MICROMIPS:
15111 mips_opts.micromips = 0;
15112 mips_no_prev_insn ();
15116 mips_opts.ase_virt = 1;
15119 case OPTION_NO_VIRT:
15120 mips_opts.ase_virt = 0;
15123 case OPTION_MIPS16:
15124 if (mips_opts.micromips == 1)
15126 as_bad (_("-mips16 cannot be used with -micromips"));
15129 mips_opts.mips16 = 1;
15130 mips_no_prev_insn ();
15133 case OPTION_NO_MIPS16:
15134 mips_opts.mips16 = 0;
15135 mips_no_prev_insn ();
15138 case OPTION_MIPS3D:
15139 mips_opts.ase_mips3d = 1;
15142 case OPTION_NO_MIPS3D:
15143 mips_opts.ase_mips3d = 0;
15146 case OPTION_SMARTMIPS:
15147 mips_opts.ase_smartmips = 1;
15150 case OPTION_NO_SMARTMIPS:
15151 mips_opts.ase_smartmips = 0;
15154 case OPTION_FIX_24K:
15158 case OPTION_NO_FIX_24K:
15162 case OPTION_FIX_LOONGSON2F_JUMP:
15163 mips_fix_loongson2f_jump = TRUE;
15166 case OPTION_NO_FIX_LOONGSON2F_JUMP:
15167 mips_fix_loongson2f_jump = FALSE;
15170 case OPTION_FIX_LOONGSON2F_NOP:
15171 mips_fix_loongson2f_nop = TRUE;
15174 case OPTION_NO_FIX_LOONGSON2F_NOP:
15175 mips_fix_loongson2f_nop = FALSE;
15178 case OPTION_FIX_VR4120:
15179 mips_fix_vr4120 = 1;
15182 case OPTION_NO_FIX_VR4120:
15183 mips_fix_vr4120 = 0;
15186 case OPTION_FIX_VR4130:
15187 mips_fix_vr4130 = 1;
15190 case OPTION_NO_FIX_VR4130:
15191 mips_fix_vr4130 = 0;
15194 case OPTION_FIX_CN63XXP1:
15195 mips_fix_cn63xxp1 = TRUE;
15198 case OPTION_NO_FIX_CN63XXP1:
15199 mips_fix_cn63xxp1 = FALSE;
15202 case OPTION_RELAX_BRANCH:
15203 mips_relax_branch = 1;
15206 case OPTION_NO_RELAX_BRANCH:
15207 mips_relax_branch = 0;
15210 case OPTION_MSHARED:
15211 mips_in_shared = TRUE;
15214 case OPTION_MNO_SHARED:
15215 mips_in_shared = FALSE;
15218 case OPTION_MSYM32:
15219 mips_opts.sym32 = TRUE;
15222 case OPTION_MNO_SYM32:
15223 mips_opts.sym32 = FALSE;
15227 /* When generating ELF code, we permit -KPIC and -call_shared to
15228 select SVR4_PIC, and -non_shared to select no PIC. This is
15229 intended to be compatible with Irix 5. */
15230 case OPTION_CALL_SHARED:
15233 as_bad (_("-call_shared is supported only for ELF format"));
15236 mips_pic = SVR4_PIC;
15237 mips_abicalls = TRUE;
15240 case OPTION_CALL_NONPIC:
15243 as_bad (_("-call_nonpic is supported only for ELF format"));
15247 mips_abicalls = TRUE;
15250 case OPTION_NON_SHARED:
15253 as_bad (_("-non_shared is supported only for ELF format"));
15257 mips_abicalls = FALSE;
15260 /* The -xgot option tells the assembler to use 32 bit offsets
15261 when accessing the got in SVR4_PIC mode. It is for Irix
15266 #endif /* OBJ_ELF */
15269 g_switch_value = atoi (arg);
15273 /* The -32, -n32 and -64 options are shortcuts for -mabi=32, -mabi=n32
15277 mips_abi = O32_ABI;
15278 /* We silently ignore -32 for non-ELF targets. This greatly
15279 simplifies the construction of the MIPS GAS test cases. */
15286 as_bad (_("-n32 is supported for ELF format only"));
15289 mips_abi = N32_ABI;
15295 as_bad (_("-64 is supported for ELF format only"));
15298 mips_abi = N64_ABI;
15299 if (!support_64bit_objects())
15300 as_fatal (_("No compiled in support for 64 bit object file format"));
15302 #endif /* OBJ_ELF */
15305 file_mips_gp32 = 1;
15309 file_mips_gp32 = 0;
15313 file_mips_fp32 = 1;
15317 file_mips_fp32 = 0;
15320 case OPTION_SINGLE_FLOAT:
15321 file_mips_single_float = 1;
15324 case OPTION_DOUBLE_FLOAT:
15325 file_mips_single_float = 0;
15328 case OPTION_SOFT_FLOAT:
15329 file_mips_soft_float = 1;
15332 case OPTION_HARD_FLOAT:
15333 file_mips_soft_float = 0;
15340 as_bad (_("-mabi is supported for ELF format only"));
15343 if (strcmp (arg, "32") == 0)
15344 mips_abi = O32_ABI;
15345 else if (strcmp (arg, "o64") == 0)
15346 mips_abi = O64_ABI;
15347 else if (strcmp (arg, "n32") == 0)
15348 mips_abi = N32_ABI;
15349 else if (strcmp (arg, "64") == 0)
15351 mips_abi = N64_ABI;
15352 if (! support_64bit_objects())
15353 as_fatal (_("No compiled in support for 64 bit object file "
15356 else if (strcmp (arg, "eabi") == 0)
15357 mips_abi = EABI_ABI;
15360 as_fatal (_("invalid abi -mabi=%s"), arg);
15364 #endif /* OBJ_ELF */
15366 case OPTION_M7000_HILO_FIX:
15367 mips_7000_hilo_fix = TRUE;
15370 case OPTION_MNO_7000_HILO_FIX:
15371 mips_7000_hilo_fix = FALSE;
15375 case OPTION_MDEBUG:
15376 mips_flag_mdebug = TRUE;
15379 case OPTION_NO_MDEBUG:
15380 mips_flag_mdebug = FALSE;
15384 mips_flag_pdr = TRUE;
15387 case OPTION_NO_PDR:
15388 mips_flag_pdr = FALSE;
15391 case OPTION_MVXWORKS_PIC:
15392 mips_pic = VXWORKS_PIC;
15394 #endif /* OBJ_ELF */
15400 mips_fix_loongson2f = mips_fix_loongson2f_nop || mips_fix_loongson2f_jump;
15405 /* Set up globals to generate code for the ISA or processor
15406 described by INFO. */
15409 mips_set_architecture (const struct mips_cpu_info *info)
15413 file_mips_arch = info->cpu;
15414 mips_opts.arch = info->cpu;
15415 mips_opts.isa = info->isa;
15420 /* Likewise for tuning. */
15423 mips_set_tune (const struct mips_cpu_info *info)
15426 mips_tune = info->cpu;
15431 mips_after_parse_args (void)
15433 const struct mips_cpu_info *arch_info = 0;
15434 const struct mips_cpu_info *tune_info = 0;
15436 /* GP relative stuff not working for PE */
15437 if (strncmp (TARGET_OS, "pe", 2) == 0)
15439 if (g_switch_seen && g_switch_value != 0)
15440 as_bad (_("-G not supported in this configuration."));
15441 g_switch_value = 0;
15444 if (mips_abi == NO_ABI)
15445 mips_abi = MIPS_DEFAULT_ABI;
15447 /* The following code determines the architecture and register size.
15448 Similar code was added to GCC 3.3 (see override_options() in
15449 config/mips/mips.c). The GAS and GCC code should be kept in sync
15450 as much as possible. */
15452 if (mips_arch_string != 0)
15453 arch_info = mips_parse_cpu ("-march", mips_arch_string);
15455 if (file_mips_isa != ISA_UNKNOWN)
15457 /* Handle -mipsN. At this point, file_mips_isa contains the
15458 ISA level specified by -mipsN, while arch_info->isa contains
15459 the -march selection (if any). */
15460 if (arch_info != 0)
15462 /* -march takes precedence over -mipsN, since it is more descriptive.
15463 There's no harm in specifying both as long as the ISA levels
15465 if (file_mips_isa != arch_info->isa)
15466 as_bad (_("-%s conflicts with the other architecture options, which imply -%s"),
15467 mips_cpu_info_from_isa (file_mips_isa)->name,
15468 mips_cpu_info_from_isa (arch_info->isa)->name);
15471 arch_info = mips_cpu_info_from_isa (file_mips_isa);
15474 if (arch_info == 0)
15476 arch_info = mips_parse_cpu ("default CPU", MIPS_CPU_STRING_DEFAULT);
15477 gas_assert (arch_info);
15480 if (ABI_NEEDS_64BIT_REGS (mips_abi) && !ISA_HAS_64BIT_REGS (arch_info->isa))
15481 as_bad (_("-march=%s is not compatible with the selected ABI"),
15484 mips_set_architecture (arch_info);
15486 /* Optimize for file_mips_arch, unless -mtune selects a different processor. */
15487 if (mips_tune_string != 0)
15488 tune_info = mips_parse_cpu ("-mtune", mips_tune_string);
15490 if (tune_info == 0)
15491 mips_set_tune (arch_info);
15493 mips_set_tune (tune_info);
15495 if (file_mips_gp32 >= 0)
15497 /* The user specified the size of the integer registers. Make sure
15498 it agrees with the ABI and ISA. */
15499 if (file_mips_gp32 == 0 && !ISA_HAS_64BIT_REGS (mips_opts.isa))
15500 as_bad (_("-mgp64 used with a 32-bit processor"));
15501 else if (file_mips_gp32 == 1 && ABI_NEEDS_64BIT_REGS (mips_abi))
15502 as_bad (_("-mgp32 used with a 64-bit ABI"));
15503 else if (file_mips_gp32 == 0 && ABI_NEEDS_32BIT_REGS (mips_abi))
15504 as_bad (_("-mgp64 used with a 32-bit ABI"));
15508 /* Infer the integer register size from the ABI and processor.
15509 Restrict ourselves to 32-bit registers if that's all the
15510 processor has, or if the ABI cannot handle 64-bit registers. */
15511 file_mips_gp32 = (ABI_NEEDS_32BIT_REGS (mips_abi)
15512 || !ISA_HAS_64BIT_REGS (mips_opts.isa));
15515 switch (file_mips_fp32)
15519 /* No user specified float register size.
15520 ??? GAS treats single-float processors as though they had 64-bit
15521 float registers (although it complains when double-precision
15522 instructions are used). As things stand, saying they have 32-bit
15523 registers would lead to spurious "register must be even" messages.
15524 So here we assume float registers are never smaller than the
15526 if (file_mips_gp32 == 0)
15527 /* 64-bit integer registers implies 64-bit float registers. */
15528 file_mips_fp32 = 0;
15529 else if ((mips_opts.ase_mips3d > 0 || mips_opts.ase_mdmx > 0)
15530 && ISA_HAS_64BIT_FPRS (mips_opts.isa))
15531 /* -mips3d and -mdmx imply 64-bit float registers, if possible. */
15532 file_mips_fp32 = 0;
15534 /* 32-bit float registers. */
15535 file_mips_fp32 = 1;
15538 /* The user specified the size of the float registers. Check if it
15539 agrees with the ABI and ISA. */
15541 if (!ISA_HAS_64BIT_FPRS (mips_opts.isa))
15542 as_bad (_("-mfp64 used with a 32-bit fpu"));
15543 else if (ABI_NEEDS_32BIT_REGS (mips_abi)
15544 && !ISA_HAS_MXHC1 (mips_opts.isa))
15545 as_warn (_("-mfp64 used with a 32-bit ABI"));
15548 if (ABI_NEEDS_64BIT_REGS (mips_abi))
15549 as_warn (_("-mfp32 used with a 64-bit ABI"));
15553 /* End of GCC-shared inference code. */
15555 /* This flag is set when we have a 64-bit capable CPU but use only
15556 32-bit wide registers. Note that EABI does not use it. */
15557 if (ISA_HAS_64BIT_REGS (mips_opts.isa)
15558 && ((mips_abi == NO_ABI && file_mips_gp32 == 1)
15559 || mips_abi == O32_ABI))
15560 mips_32bitmode = 1;
15562 if (mips_opts.isa == ISA_MIPS1 && mips_trap)
15563 as_bad (_("trap exception not supported at ISA 1"));
15565 /* If the selected architecture includes support for ASEs, enable
15566 generation of code for them. */
15567 if (mips_opts.mips16 == -1)
15568 mips_opts.mips16 = (CPU_HAS_MIPS16 (file_mips_arch)) ? 1 : 0;
15569 if (mips_opts.micromips == -1)
15570 mips_opts.micromips = (CPU_HAS_MICROMIPS (file_mips_arch)) ? 1 : 0;
15571 if (mips_opts.ase_mips3d == -1)
15572 mips_opts.ase_mips3d = ((arch_info->ase & ASE_MIPS3D)
15573 && file_mips_fp32 == 0) ? 1 : 0;
15574 if (mips_opts.ase_mips3d && file_mips_fp32 == 1)
15575 as_bad (_("-mfp32 used with -mips3d"));
15577 if (mips_opts.ase_mdmx == -1)
15578 mips_opts.ase_mdmx = ((arch_info->ase & ASE_MDMX)
15579 && file_mips_fp32 == 0) ? 1 : 0;
15580 if (mips_opts.ase_mdmx && file_mips_fp32 == 1)
15581 as_bad (_("-mfp32 used with -mdmx"));
15583 if (mips_opts.ase_smartmips == -1)
15584 mips_opts.ase_smartmips = (arch_info->ase & ASE_SMARTMIPS) ? 1 : 0;
15585 if (mips_opts.ase_smartmips && !ISA_SUPPORTS_SMARTMIPS)
15586 as_warn (_("%s ISA does not support SmartMIPS"),
15587 mips_cpu_info_from_isa (mips_opts.isa)->name);
15589 if (mips_opts.ase_dsp == -1)
15590 mips_opts.ase_dsp = (arch_info->ase & ASE_DSP) ? 1 : 0;
15591 if (mips_opts.ase_dsp && !ISA_SUPPORTS_DSP_ASE)
15592 as_warn (_("%s ISA does not support DSP ASE"),
15593 mips_cpu_info_from_isa (mips_opts.isa)->name);
15595 if (mips_opts.ase_dspr2 == -1)
15597 mips_opts.ase_dspr2 = (arch_info->ase & ASE_DSPR2) ? 1 : 0;
15598 mips_opts.ase_dsp = (arch_info->ase & ASE_DSP) ? 1 : 0;
15600 if (mips_opts.ase_dspr2 && !ISA_SUPPORTS_DSPR2_ASE)
15601 as_warn (_("%s ISA does not support DSP R2 ASE"),
15602 mips_cpu_info_from_isa (mips_opts.isa)->name);
15604 if (mips_opts.ase_eva == -1)
15605 mips_opts.ase_eva = (arch_info->ase & ASE_EVA) ? 1 : 0;
15606 if (mips_opts.ase_eva && !ISA_SUPPORTS_EVA_ASE)
15607 as_warn (_("%s ISA does not support EVA ASE"),
15608 mips_cpu_info_from_isa (mips_opts.isa)->name);
15610 if (mips_opts.ase_mt == -1)
15611 mips_opts.ase_mt = (arch_info->ase & ASE_MT) ? 1 : 0;
15612 if (mips_opts.ase_mt && !ISA_SUPPORTS_MT_ASE)
15613 as_warn (_("%s ISA does not support MT ASE"),
15614 mips_cpu_info_from_isa (mips_opts.isa)->name);
15616 if (mips_opts.ase_mcu == -1)
15617 mips_opts.ase_mcu = (arch_info->ase & ASE_MCU) ? 1 : 0;
15618 if (mips_opts.ase_mcu && !ISA_SUPPORTS_MCU_ASE)
15619 as_warn (_("%s ISA does not support MCU ASE"),
15620 mips_cpu_info_from_isa (mips_opts.isa)->name);
15622 if (mips_opts.ase_virt == -1)
15623 mips_opts.ase_virt = (arch_info->ase & ASE_VIRT) ? 1 : 0;
15624 if (mips_opts.ase_virt && !ISA_SUPPORTS_VIRT_ASE)
15625 as_warn (_("%s ISA does not support Virtualization ASE"),
15626 mips_cpu_info_from_isa (mips_opts.isa)->name);
15628 file_mips_isa = mips_opts.isa;
15629 file_ase_mips3d = mips_opts.ase_mips3d;
15630 file_ase_mdmx = mips_opts.ase_mdmx;
15631 file_ase_smartmips = mips_opts.ase_smartmips;
15632 file_ase_dsp = mips_opts.ase_dsp;
15633 file_ase_dspr2 = mips_opts.ase_dspr2;
15634 file_ase_eva = mips_opts.ase_eva;
15635 file_ase_mt = mips_opts.ase_mt;
15636 file_ase_virt = mips_opts.ase_virt;
15637 mips_opts.gp32 = file_mips_gp32;
15638 mips_opts.fp32 = file_mips_fp32;
15639 mips_opts.soft_float = file_mips_soft_float;
15640 mips_opts.single_float = file_mips_single_float;
15642 if (mips_flag_mdebug < 0)
15644 #ifdef OBJ_MAYBE_ECOFF
15645 if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour)
15646 mips_flag_mdebug = 1;
15648 #endif /* OBJ_MAYBE_ECOFF */
15649 mips_flag_mdebug = 0;
15654 mips_init_after_args (void)
15656 /* initialize opcodes */
15657 bfd_mips_num_opcodes = bfd_mips_num_builtin_opcodes;
15658 mips_opcodes = (struct mips_opcode *) mips_builtin_opcodes;
15662 md_pcrel_from (fixS *fixP)
15664 valueT addr = fixP->fx_where + fixP->fx_frag->fr_address;
15665 switch (fixP->fx_r_type)
15667 case BFD_RELOC_MICROMIPS_7_PCREL_S1:
15668 case BFD_RELOC_MICROMIPS_10_PCREL_S1:
15669 /* Return the address of the delay slot. */
15672 case BFD_RELOC_MICROMIPS_16_PCREL_S1:
15673 case BFD_RELOC_MICROMIPS_JMP:
15674 case BFD_RELOC_16_PCREL_S2:
15675 case BFD_RELOC_MIPS_JMP:
15676 /* Return the address of the delay slot. */
15679 case BFD_RELOC_32_PCREL:
15683 /* We have no relocation type for PC relative MIPS16 instructions. */
15684 if (fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != now_seg)
15685 as_bad_where (fixP->fx_file, fixP->fx_line,
15686 _("PC relative MIPS16 instruction references a different section"));
15691 /* This is called before the symbol table is processed. In order to
15692 work with gcc when using mips-tfile, we must keep all local labels.
15693 However, in other cases, we want to discard them. If we were
15694 called with -g, but we didn't see any debugging information, it may
15695 mean that gcc is smuggling debugging information through to
15696 mips-tfile, in which case we must generate all local labels. */
15699 mips_frob_file_before_adjust (void)
15701 #ifndef NO_ECOFF_DEBUGGING
15702 if (ECOFF_DEBUGGING
15704 && ! ecoff_debugging_seen)
15705 flag_keep_locals = 1;
15709 /* Sort any unmatched HI16 and GOT16 relocs so that they immediately precede
15710 the corresponding LO16 reloc. This is called before md_apply_fix and
15711 tc_gen_reloc. Unmatched relocs can only be generated by use of explicit
15712 relocation operators.
15714 For our purposes, a %lo() expression matches a %got() or %hi()
15717 (a) it refers to the same symbol; and
15718 (b) the offset applied in the %lo() expression is no lower than
15719 the offset applied in the %got() or %hi().
15721 (b) allows us to cope with code like:
15724 lh $4,%lo(foo+2)($4)
15726 ...which is legal on RELA targets, and has a well-defined behaviour
15727 if the user knows that adding 2 to "foo" will not induce a carry to
15730 When several %lo()s match a particular %got() or %hi(), we use the
15731 following rules to distinguish them:
15733 (1) %lo()s with smaller offsets are a better match than %lo()s with
15736 (2) %lo()s with no matching %got() or %hi() are better than those
15737 that already have a matching %got() or %hi().
15739 (3) later %lo()s are better than earlier %lo()s.
15741 These rules are applied in order.
15743 (1) means, among other things, that %lo()s with identical offsets are
15744 chosen if they exist.
15746 (2) means that we won't associate several high-part relocations with
15747 the same low-part relocation unless there's no alternative. Having
15748 several high parts for the same low part is a GNU extension; this rule
15749 allows careful users to avoid it.
15751 (3) is purely cosmetic. mips_hi_fixup_list is is in reverse order,
15752 with the last high-part relocation being at the front of the list.
15753 It therefore makes sense to choose the last matching low-part
15754 relocation, all other things being equal. It's also easier
15755 to code that way. */
15758 mips_frob_file (void)
15760 struct mips_hi_fixup *l;
15761 bfd_reloc_code_real_type looking_for_rtype = BFD_RELOC_UNUSED;
15763 for (l = mips_hi_fixup_list; l != NULL; l = l->next)
15765 segment_info_type *seginfo;
15766 bfd_boolean matched_lo_p;
15767 fixS **hi_pos, **lo_pos, **pos;
15769 gas_assert (reloc_needs_lo_p (l->fixp->fx_r_type));
15771 /* If a GOT16 relocation turns out to be against a global symbol,
15772 there isn't supposed to be a matching LO. Ignore %gots against
15773 constants; we'll report an error for those later. */
15774 if (got16_reloc_p (l->fixp->fx_r_type)
15775 && !(l->fixp->fx_addsy
15776 && pic_need_relax (l->fixp->fx_addsy, l->seg)))
15779 /* Check quickly whether the next fixup happens to be a matching %lo. */
15780 if (fixup_has_matching_lo_p (l->fixp))
15783 seginfo = seg_info (l->seg);
15785 /* Set HI_POS to the position of this relocation in the chain.
15786 Set LO_POS to the position of the chosen low-part relocation.
15787 MATCHED_LO_P is true on entry to the loop if *POS is a low-part
15788 relocation that matches an immediately-preceding high-part
15792 matched_lo_p = FALSE;
15793 looking_for_rtype = matching_lo_reloc (l->fixp->fx_r_type);
15795 for (pos = &seginfo->fix_root; *pos != NULL; pos = &(*pos)->fx_next)
15797 if (*pos == l->fixp)
15800 if ((*pos)->fx_r_type == looking_for_rtype
15801 && symbol_same_p ((*pos)->fx_addsy, l->fixp->fx_addsy)
15802 && (*pos)->fx_offset >= l->fixp->fx_offset
15804 || (*pos)->fx_offset < (*lo_pos)->fx_offset
15806 && (*pos)->fx_offset == (*lo_pos)->fx_offset)))
15809 matched_lo_p = (reloc_needs_lo_p ((*pos)->fx_r_type)
15810 && fixup_has_matching_lo_p (*pos));
15813 /* If we found a match, remove the high-part relocation from its
15814 current position and insert it before the low-part relocation.
15815 Make the offsets match so that fixup_has_matching_lo_p()
15818 We don't warn about unmatched high-part relocations since some
15819 versions of gcc have been known to emit dead "lui ...%hi(...)"
15821 if (lo_pos != NULL)
15823 l->fixp->fx_offset = (*lo_pos)->fx_offset;
15824 if (l->fixp->fx_next != *lo_pos)
15826 *hi_pos = l->fixp->fx_next;
15827 l->fixp->fx_next = *lo_pos;
15835 mips_force_relocation (fixS *fixp)
15837 if (generic_force_reloc (fixp))
15840 /* We want to keep BFD_RELOC_MICROMIPS_*_PCREL_S1 relocation,
15841 so that the linker relaxation can update targets. */
15842 if (fixp->fx_r_type == BFD_RELOC_MICROMIPS_7_PCREL_S1
15843 || fixp->fx_r_type == BFD_RELOC_MICROMIPS_10_PCREL_S1
15844 || fixp->fx_r_type == BFD_RELOC_MICROMIPS_16_PCREL_S1)
15850 /* Read the instruction associated with RELOC from BUF. */
15852 static unsigned int
15853 read_reloc_insn (char *buf, bfd_reloc_code_real_type reloc)
15855 if (mips16_reloc_p (reloc) || micromips_reloc_p (reloc))
15856 return read_compressed_insn (buf, 4);
15858 return read_insn (buf);
15861 /* Write instruction INSN to BUF, given that it has been relocated
15865 write_reloc_insn (char *buf, bfd_reloc_code_real_type reloc,
15866 unsigned long insn)
15868 if (mips16_reloc_p (reloc) || micromips_reloc_p (reloc))
15869 write_compressed_insn (buf, insn, 4);
15871 write_insn (buf, insn);
15874 /* Apply a fixup to the object file. */
15877 md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
15880 unsigned long insn;
15881 reloc_howto_type *howto;
15883 /* We ignore generic BFD relocations we don't know about. */
15884 howto = bfd_reloc_type_lookup (stdoutput, fixP->fx_r_type);
15888 gas_assert (fixP->fx_size == 2
15889 || fixP->fx_size == 4
15890 || fixP->fx_r_type == BFD_RELOC_16
15891 || fixP->fx_r_type == BFD_RELOC_64
15892 || fixP->fx_r_type == BFD_RELOC_CTOR
15893 || fixP->fx_r_type == BFD_RELOC_MIPS_SUB
15894 || fixP->fx_r_type == BFD_RELOC_MICROMIPS_SUB
15895 || fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
15896 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY
15897 || fixP->fx_r_type == BFD_RELOC_MIPS_TLS_DTPREL64);
15899 buf = fixP->fx_frag->fr_literal + fixP->fx_where;
15901 gas_assert (!fixP->fx_pcrel || fixP->fx_r_type == BFD_RELOC_16_PCREL_S2
15902 || fixP->fx_r_type == BFD_RELOC_MICROMIPS_7_PCREL_S1
15903 || fixP->fx_r_type == BFD_RELOC_MICROMIPS_10_PCREL_S1
15904 || fixP->fx_r_type == BFD_RELOC_MICROMIPS_16_PCREL_S1
15905 || fixP->fx_r_type == BFD_RELOC_32_PCREL);
15907 /* Don't treat parts of a composite relocation as done. There are two
15910 (1) The second and third parts will be against 0 (RSS_UNDEF) but
15911 should nevertheless be emitted if the first part is.
15913 (2) In normal usage, composite relocations are never assembly-time
15914 constants. The easiest way of dealing with the pathological
15915 exceptions is to generate a relocation against STN_UNDEF and
15916 leave everything up to the linker. */
15917 if (fixP->fx_addsy == NULL && !fixP->fx_pcrel && fixP->fx_tcbit == 0)
15920 switch (fixP->fx_r_type)
15922 case BFD_RELOC_MIPS_TLS_GD:
15923 case BFD_RELOC_MIPS_TLS_LDM:
15924 case BFD_RELOC_MIPS_TLS_DTPREL32:
15925 case BFD_RELOC_MIPS_TLS_DTPREL64:
15926 case BFD_RELOC_MIPS_TLS_DTPREL_HI16:
15927 case BFD_RELOC_MIPS_TLS_DTPREL_LO16:
15928 case BFD_RELOC_MIPS_TLS_GOTTPREL:
15929 case BFD_RELOC_MIPS_TLS_TPREL32:
15930 case BFD_RELOC_MIPS_TLS_TPREL64:
15931 case BFD_RELOC_MIPS_TLS_TPREL_HI16:
15932 case BFD_RELOC_MIPS_TLS_TPREL_LO16:
15933 case BFD_RELOC_MICROMIPS_TLS_GD:
15934 case BFD_RELOC_MICROMIPS_TLS_LDM:
15935 case BFD_RELOC_MICROMIPS_TLS_DTPREL_HI16:
15936 case BFD_RELOC_MICROMIPS_TLS_DTPREL_LO16:
15937 case BFD_RELOC_MICROMIPS_TLS_GOTTPREL:
15938 case BFD_RELOC_MICROMIPS_TLS_TPREL_HI16:
15939 case BFD_RELOC_MICROMIPS_TLS_TPREL_LO16:
15940 case BFD_RELOC_MIPS16_TLS_GD:
15941 case BFD_RELOC_MIPS16_TLS_LDM:
15942 case BFD_RELOC_MIPS16_TLS_DTPREL_HI16:
15943 case BFD_RELOC_MIPS16_TLS_DTPREL_LO16:
15944 case BFD_RELOC_MIPS16_TLS_GOTTPREL:
15945 case BFD_RELOC_MIPS16_TLS_TPREL_HI16:
15946 case BFD_RELOC_MIPS16_TLS_TPREL_LO16:
15947 if (!fixP->fx_addsy)
15949 as_bad_where (fixP->fx_file, fixP->fx_line,
15950 _("TLS relocation against a constant"));
15953 S_SET_THREAD_LOCAL (fixP->fx_addsy);
15956 case BFD_RELOC_MIPS_JMP:
15957 case BFD_RELOC_MIPS_SHIFT5:
15958 case BFD_RELOC_MIPS_SHIFT6:
15959 case BFD_RELOC_MIPS_GOT_DISP:
15960 case BFD_RELOC_MIPS_GOT_PAGE:
15961 case BFD_RELOC_MIPS_GOT_OFST:
15962 case BFD_RELOC_MIPS_SUB:
15963 case BFD_RELOC_MIPS_INSERT_A:
15964 case BFD_RELOC_MIPS_INSERT_B:
15965 case BFD_RELOC_MIPS_DELETE:
15966 case BFD_RELOC_MIPS_HIGHEST:
15967 case BFD_RELOC_MIPS_HIGHER:
15968 case BFD_RELOC_MIPS_SCN_DISP:
15969 case BFD_RELOC_MIPS_REL16:
15970 case BFD_RELOC_MIPS_RELGOT:
15971 case BFD_RELOC_MIPS_JALR:
15972 case BFD_RELOC_HI16:
15973 case BFD_RELOC_HI16_S:
15974 case BFD_RELOC_LO16:
15975 case BFD_RELOC_GPREL16:
15976 case BFD_RELOC_MIPS_LITERAL:
15977 case BFD_RELOC_MIPS_CALL16:
15978 case BFD_RELOC_MIPS_GOT16:
15979 case BFD_RELOC_GPREL32:
15980 case BFD_RELOC_MIPS_GOT_HI16:
15981 case BFD_RELOC_MIPS_GOT_LO16:
15982 case BFD_RELOC_MIPS_CALL_HI16:
15983 case BFD_RELOC_MIPS_CALL_LO16:
15984 case BFD_RELOC_MIPS16_GPREL:
15985 case BFD_RELOC_MIPS16_GOT16:
15986 case BFD_RELOC_MIPS16_CALL16:
15987 case BFD_RELOC_MIPS16_HI16:
15988 case BFD_RELOC_MIPS16_HI16_S:
15989 case BFD_RELOC_MIPS16_LO16:
15990 case BFD_RELOC_MIPS16_JMP:
15991 case BFD_RELOC_MICROMIPS_JMP:
15992 case BFD_RELOC_MICROMIPS_GOT_DISP:
15993 case BFD_RELOC_MICROMIPS_GOT_PAGE:
15994 case BFD_RELOC_MICROMIPS_GOT_OFST:
15995 case BFD_RELOC_MICROMIPS_SUB:
15996 case BFD_RELOC_MICROMIPS_HIGHEST:
15997 case BFD_RELOC_MICROMIPS_HIGHER:
15998 case BFD_RELOC_MICROMIPS_SCN_DISP:
15999 case BFD_RELOC_MICROMIPS_JALR:
16000 case BFD_RELOC_MICROMIPS_HI16:
16001 case BFD_RELOC_MICROMIPS_HI16_S:
16002 case BFD_RELOC_MICROMIPS_LO16:
16003 case BFD_RELOC_MICROMIPS_GPREL16:
16004 case BFD_RELOC_MICROMIPS_LITERAL:
16005 case BFD_RELOC_MICROMIPS_CALL16:
16006 case BFD_RELOC_MICROMIPS_GOT16:
16007 case BFD_RELOC_MICROMIPS_GOT_HI16:
16008 case BFD_RELOC_MICROMIPS_GOT_LO16:
16009 case BFD_RELOC_MICROMIPS_CALL_HI16:
16010 case BFD_RELOC_MICROMIPS_CALL_LO16:
16011 case BFD_RELOC_MIPS_EH:
16016 if (calculate_reloc (fixP->fx_r_type, *valP, &value))
16018 insn = read_reloc_insn (buf, fixP->fx_r_type);
16019 if (mips16_reloc_p (fixP->fx_r_type))
16020 insn |= mips16_immed_extend (value, 16);
16022 insn |= (value & 0xffff);
16023 write_reloc_insn (buf, fixP->fx_r_type, insn);
16026 as_bad_where (fixP->fx_file, fixP->fx_line,
16027 _("Unsupported constant in relocation"));
16032 /* This is handled like BFD_RELOC_32, but we output a sign
16033 extended value if we are only 32 bits. */
16036 if (8 <= sizeof (valueT))
16037 md_number_to_chars (buf, *valP, 8);
16042 if ((*valP & 0x80000000) != 0)
16046 md_number_to_chars (buf + (target_big_endian ? 4 : 0), *valP, 4);
16047 md_number_to_chars (buf + (target_big_endian ? 0 : 4), hiv, 4);
16052 case BFD_RELOC_RVA:
16054 case BFD_RELOC_32_PCREL:
16056 /* If we are deleting this reloc entry, we must fill in the
16057 value now. This can happen if we have a .word which is not
16058 resolved when it appears but is later defined. */
16060 md_number_to_chars (buf, *valP, fixP->fx_size);
16063 case BFD_RELOC_16_PCREL_S2:
16064 if ((*valP & 0x3) != 0)
16065 as_bad_where (fixP->fx_file, fixP->fx_line,
16066 _("Branch to misaligned address (%lx)"), (long) *valP);
16068 /* We need to save the bits in the instruction since fixup_segment()
16069 might be deleting the relocation entry (i.e., a branch within
16070 the current segment). */
16071 if (! fixP->fx_done)
16074 /* Update old instruction data. */
16075 insn = read_insn (buf);
16077 if (*valP + 0x20000 <= 0x3ffff)
16079 insn |= (*valP >> 2) & 0xffff;
16080 write_insn (buf, insn);
16082 else if (mips_pic == NO_PIC
16084 && fixP->fx_frag->fr_address >= text_section->vma
16085 && (fixP->fx_frag->fr_address
16086 < text_section->vma + bfd_get_section_size (text_section))
16087 && ((insn & 0xffff0000) == 0x10000000 /* beq $0,$0 */
16088 || (insn & 0xffff0000) == 0x04010000 /* bgez $0 */
16089 || (insn & 0xffff0000) == 0x04110000)) /* bgezal $0 */
16091 /* The branch offset is too large. If this is an
16092 unconditional branch, and we are not generating PIC code,
16093 we can convert it to an absolute jump instruction. */
16094 if ((insn & 0xffff0000) == 0x04110000) /* bgezal $0 */
16095 insn = 0x0c000000; /* jal */
16097 insn = 0x08000000; /* j */
16098 fixP->fx_r_type = BFD_RELOC_MIPS_JMP;
16100 fixP->fx_addsy = section_symbol (text_section);
16101 *valP += md_pcrel_from (fixP);
16102 write_insn (buf, insn);
16106 /* If we got here, we have branch-relaxation disabled,
16107 and there's nothing we can do to fix this instruction
16108 without turning it into a longer sequence. */
16109 as_bad_where (fixP->fx_file, fixP->fx_line,
16110 _("Branch out of range"));
16114 case BFD_RELOC_MICROMIPS_7_PCREL_S1:
16115 case BFD_RELOC_MICROMIPS_10_PCREL_S1:
16116 case BFD_RELOC_MICROMIPS_16_PCREL_S1:
16117 /* We adjust the offset back to even. */
16118 if ((*valP & 0x1) != 0)
16121 if (! fixP->fx_done)
16124 /* Should never visit here, because we keep the relocation. */
16128 case BFD_RELOC_VTABLE_INHERIT:
16131 && !S_IS_DEFINED (fixP->fx_addsy)
16132 && !S_IS_WEAK (fixP->fx_addsy))
16133 S_SET_WEAK (fixP->fx_addsy);
16136 case BFD_RELOC_VTABLE_ENTRY:
16144 /* Remember value for tc_gen_reloc. */
16145 fixP->fx_addnumber = *valP;
16155 name = input_line_pointer;
16156 c = get_symbol_end ();
16157 p = (symbolS *) symbol_find_or_make (name);
16158 *input_line_pointer = c;
16162 /* Align the current frag to a given power of two. If a particular
16163 fill byte should be used, FILL points to an integer that contains
16164 that byte, otherwise FILL is null.
16166 This function used to have the comment:
16168 The MIPS assembler also automatically adjusts any preceding label.
16170 The implementation therefore applied the adjustment to a maximum of
16171 one label. However, other label adjustments are applied to batches
16172 of labels, and adjusting just one caused problems when new labels
16173 were added for the sake of debugging or unwind information.
16174 We therefore adjust all preceding labels (given as LABELS) instead. */
16177 mips_align (int to, int *fill, struct insn_label_list *labels)
16179 mips_emit_delays ();
16180 mips_record_compressed_mode ();
16181 if (fill == NULL && subseg_text_p (now_seg))
16182 frag_align_code (to, 0);
16184 frag_align (to, fill ? *fill : 0, 0);
16185 record_alignment (now_seg, to);
16186 mips_move_labels (labels, FALSE);
16189 /* Align to a given power of two. .align 0 turns off the automatic
16190 alignment used by the data creating pseudo-ops. */
16193 s_align (int x ATTRIBUTE_UNUSED)
16195 int temp, fill_value, *fill_ptr;
16196 long max_alignment = 28;
16198 /* o Note that the assembler pulls down any immediately preceding label
16199 to the aligned address.
16200 o It's not documented but auto alignment is reinstated by
16201 a .align pseudo instruction.
16202 o Note also that after auto alignment is turned off the mips assembler
16203 issues an error on attempt to assemble an improperly aligned data item.
16206 temp = get_absolute_expression ();
16207 if (temp > max_alignment)
16208 as_bad (_("Alignment too large: %d. assumed."), temp = max_alignment);
16211 as_warn (_("Alignment negative: 0 assumed."));
16214 if (*input_line_pointer == ',')
16216 ++input_line_pointer;
16217 fill_value = get_absolute_expression ();
16218 fill_ptr = &fill_value;
16224 segment_info_type *si = seg_info (now_seg);
16225 struct insn_label_list *l = si->label_list;
16226 /* Auto alignment should be switched on by next section change. */
16228 mips_align (temp, fill_ptr, l);
16235 demand_empty_rest_of_line ();
16239 s_change_sec (int sec)
16244 /* The ELF backend needs to know that we are changing sections, so
16245 that .previous works correctly. We could do something like check
16246 for an obj_section_change_hook macro, but that might be confusing
16247 as it would not be appropriate to use it in the section changing
16248 functions in read.c, since obj-elf.c intercepts those. FIXME:
16249 This should be cleaner, somehow. */
16251 obj_elf_section_change_hook ();
16254 mips_emit_delays ();
16265 subseg_set (bss_section, (subsegT) get_absolute_expression ());
16266 demand_empty_rest_of_line ();
16270 seg = subseg_new (RDATA_SECTION_NAME,
16271 (subsegT) get_absolute_expression ());
16274 bfd_set_section_flags (stdoutput, seg, (SEC_ALLOC | SEC_LOAD
16275 | SEC_READONLY | SEC_RELOC
16277 if (strncmp (TARGET_OS, "elf", 3) != 0)
16278 record_alignment (seg, 4);
16280 demand_empty_rest_of_line ();
16284 seg = subseg_new (".sdata", (subsegT) get_absolute_expression ());
16287 bfd_set_section_flags (stdoutput, seg,
16288 SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_DATA);
16289 if (strncmp (TARGET_OS, "elf", 3) != 0)
16290 record_alignment (seg, 4);
16292 demand_empty_rest_of_line ();
16296 seg = subseg_new (".sbss", (subsegT) get_absolute_expression ());
16299 bfd_set_section_flags (stdoutput, seg, SEC_ALLOC);
16300 if (strncmp (TARGET_OS, "elf", 3) != 0)
16301 record_alignment (seg, 4);
16303 demand_empty_rest_of_line ();
16311 s_change_section (int ignore ATTRIBUTE_UNUSED)
16314 char *section_name;
16319 int section_entry_size;
16320 int section_alignment;
16325 section_name = input_line_pointer;
16326 c = get_symbol_end ();
16328 next_c = *(input_line_pointer + 1);
16330 /* Do we have .section Name<,"flags">? */
16331 if (c != ',' || (c == ',' && next_c == '"'))
16333 /* just after name is now '\0'. */
16334 *input_line_pointer = c;
16335 input_line_pointer = section_name;
16336 obj_elf_section (ignore);
16339 input_line_pointer++;
16341 /* Do we have .section Name<,type><,flag><,entry_size><,alignment> */
16343 section_type = get_absolute_expression ();
16346 if (*input_line_pointer++ == ',')
16347 section_flag = get_absolute_expression ();
16350 if (*input_line_pointer++ == ',')
16351 section_entry_size = get_absolute_expression ();
16353 section_entry_size = 0;
16354 if (*input_line_pointer++ == ',')
16355 section_alignment = get_absolute_expression ();
16357 section_alignment = 0;
16358 /* FIXME: really ignore? */
16359 (void) section_alignment;
16361 section_name = xstrdup (section_name);
16363 /* When using the generic form of .section (as implemented by obj-elf.c),
16364 there's no way to set the section type to SHT_MIPS_DWARF. Users have
16365 traditionally had to fall back on the more common @progbits instead.
16367 There's nothing really harmful in this, since bfd will correct
16368 SHT_PROGBITS to SHT_MIPS_DWARF before writing out the file. But it
16369 means that, for backwards compatibility, the special_section entries
16370 for dwarf sections must use SHT_PROGBITS rather than SHT_MIPS_DWARF.
16372 Even so, we shouldn't force users of the MIPS .section syntax to
16373 incorrectly label the sections as SHT_PROGBITS. The best compromise
16374 seems to be to map SHT_MIPS_DWARF to SHT_PROGBITS before calling the
16375 generic type-checking code. */
16376 if (section_type == SHT_MIPS_DWARF)
16377 section_type = SHT_PROGBITS;
16379 obj_elf_change_section (section_name, section_type, section_flag,
16380 section_entry_size, 0, 0, 0);
16382 if (now_seg->name != section_name)
16383 free (section_name);
16384 #endif /* OBJ_ELF */
16388 mips_enable_auto_align (void)
16394 s_cons (int log_size)
16396 segment_info_type *si = seg_info (now_seg);
16397 struct insn_label_list *l = si->label_list;
16399 mips_emit_delays ();
16400 if (log_size > 0 && auto_align)
16401 mips_align (log_size, 0, l);
16402 cons (1 << log_size);
16403 mips_clear_insn_labels ();
16407 s_float_cons (int type)
16409 segment_info_type *si = seg_info (now_seg);
16410 struct insn_label_list *l = si->label_list;
16412 mips_emit_delays ();
16417 mips_align (3, 0, l);
16419 mips_align (2, 0, l);
16423 mips_clear_insn_labels ();
16426 /* Handle .globl. We need to override it because on Irix 5 you are
16429 where foo is an undefined symbol, to mean that foo should be
16430 considered to be the address of a function. */
16433 s_mips_globl (int x ATTRIBUTE_UNUSED)
16442 name = input_line_pointer;
16443 c = get_symbol_end ();
16444 symbolP = symbol_find_or_make (name);
16445 S_SET_EXTERNAL (symbolP);
16447 *input_line_pointer = c;
16448 SKIP_WHITESPACE ();
16450 /* On Irix 5, every global symbol that is not explicitly labelled as
16451 being a function is apparently labelled as being an object. */
16454 if (!is_end_of_line[(unsigned char) *input_line_pointer]
16455 && (*input_line_pointer != ','))
16460 secname = input_line_pointer;
16461 c = get_symbol_end ();
16462 sec = bfd_get_section_by_name (stdoutput, secname);
16464 as_bad (_("%s: no such section"), secname);
16465 *input_line_pointer = c;
16467 if (sec != NULL && (sec->flags & SEC_CODE) != 0)
16468 flag = BSF_FUNCTION;
16471 symbol_get_bfdsym (symbolP)->flags |= flag;
16473 c = *input_line_pointer;
16476 input_line_pointer++;
16477 SKIP_WHITESPACE ();
16478 if (is_end_of_line[(unsigned char) *input_line_pointer])
16484 demand_empty_rest_of_line ();
16488 s_option (int x ATTRIBUTE_UNUSED)
16493 opt = input_line_pointer;
16494 c = get_symbol_end ();
16498 /* FIXME: What does this mean? */
16500 else if (strncmp (opt, "pic", 3) == 0)
16504 i = atoi (opt + 3);
16509 mips_pic = SVR4_PIC;
16510 mips_abicalls = TRUE;
16513 as_bad (_(".option pic%d not supported"), i);
16515 if (mips_pic == SVR4_PIC)
16517 if (g_switch_seen && g_switch_value != 0)
16518 as_warn (_("-G may not be used with SVR4 PIC code"));
16519 g_switch_value = 0;
16520 bfd_set_gp_size (stdoutput, 0);
16524 as_warn (_("Unrecognized option \"%s\""), opt);
16526 *input_line_pointer = c;
16527 demand_empty_rest_of_line ();
16530 /* This structure is used to hold a stack of .set values. */
16532 struct mips_option_stack
16534 struct mips_option_stack *next;
16535 struct mips_set_options options;
16538 static struct mips_option_stack *mips_opts_stack;
16540 /* Handle the .set pseudo-op. */
16543 s_mipsset (int x ATTRIBUTE_UNUSED)
16545 char *name = input_line_pointer, ch;
16547 while (!is_end_of_line[(unsigned char) *input_line_pointer])
16548 ++input_line_pointer;
16549 ch = *input_line_pointer;
16550 *input_line_pointer = '\0';
16552 if (strcmp (name, "reorder") == 0)
16554 if (mips_opts.noreorder)
16557 else if (strcmp (name, "noreorder") == 0)
16559 if (!mips_opts.noreorder)
16560 start_noreorder ();
16562 else if (strncmp (name, "at=", 3) == 0)
16564 char *s = name + 3;
16566 if (!reg_lookup (&s, RTYPE_NUM | RTYPE_GP, &mips_opts.at))
16567 as_bad (_("Unrecognized register name `%s'"), s);
16569 else if (strcmp (name, "at") == 0)
16571 mips_opts.at = ATREG;
16573 else if (strcmp (name, "noat") == 0)
16575 mips_opts.at = ZERO;
16577 else if (strcmp (name, "macro") == 0)
16579 mips_opts.warn_about_macros = 0;
16581 else if (strcmp (name, "nomacro") == 0)
16583 if (mips_opts.noreorder == 0)
16584 as_bad (_("`noreorder' must be set before `nomacro'"));
16585 mips_opts.warn_about_macros = 1;
16587 else if (strcmp (name, "move") == 0 || strcmp (name, "novolatile") == 0)
16589 mips_opts.nomove = 0;
16591 else if (strcmp (name, "nomove") == 0 || strcmp (name, "volatile") == 0)
16593 mips_opts.nomove = 1;
16595 else if (strcmp (name, "bopt") == 0)
16597 mips_opts.nobopt = 0;
16599 else if (strcmp (name, "nobopt") == 0)
16601 mips_opts.nobopt = 1;
16603 else if (strcmp (name, "gp=default") == 0)
16604 mips_opts.gp32 = file_mips_gp32;
16605 else if (strcmp (name, "gp=32") == 0)
16606 mips_opts.gp32 = 1;
16607 else if (strcmp (name, "gp=64") == 0)
16609 if (!ISA_HAS_64BIT_REGS (mips_opts.isa))
16610 as_warn (_("%s isa does not support 64-bit registers"),
16611 mips_cpu_info_from_isa (mips_opts.isa)->name);
16612 mips_opts.gp32 = 0;
16614 else if (strcmp (name, "fp=default") == 0)
16615 mips_opts.fp32 = file_mips_fp32;
16616 else if (strcmp (name, "fp=32") == 0)
16617 mips_opts.fp32 = 1;
16618 else if (strcmp (name, "fp=64") == 0)
16620 if (!ISA_HAS_64BIT_FPRS (mips_opts.isa))
16621 as_warn (_("%s isa does not support 64-bit floating point registers"),
16622 mips_cpu_info_from_isa (mips_opts.isa)->name);
16623 mips_opts.fp32 = 0;
16625 else if (strcmp (name, "softfloat") == 0)
16626 mips_opts.soft_float = 1;
16627 else if (strcmp (name, "hardfloat") == 0)
16628 mips_opts.soft_float = 0;
16629 else if (strcmp (name, "singlefloat") == 0)
16630 mips_opts.single_float = 1;
16631 else if (strcmp (name, "doublefloat") == 0)
16632 mips_opts.single_float = 0;
16633 else if (strcmp (name, "mips16") == 0
16634 || strcmp (name, "MIPS-16") == 0)
16636 if (mips_opts.micromips == 1)
16637 as_fatal (_("`mips16' cannot be used with `micromips'"));
16638 mips_opts.mips16 = 1;
16640 else if (strcmp (name, "nomips16") == 0
16641 || strcmp (name, "noMIPS-16") == 0)
16642 mips_opts.mips16 = 0;
16643 else if (strcmp (name, "micromips") == 0)
16645 if (mips_opts.mips16 == 1)
16646 as_fatal (_("`micromips' cannot be used with `mips16'"));
16647 mips_opts.micromips = 1;
16649 else if (strcmp (name, "nomicromips") == 0)
16650 mips_opts.micromips = 0;
16651 else if (strcmp (name, "smartmips") == 0)
16653 if (!ISA_SUPPORTS_SMARTMIPS)
16654 as_warn (_("%s ISA does not support SmartMIPS ASE"),
16655 mips_cpu_info_from_isa (mips_opts.isa)->name);
16656 mips_opts.ase_smartmips = 1;
16658 else if (strcmp (name, "nosmartmips") == 0)
16659 mips_opts.ase_smartmips = 0;
16660 else if (strcmp (name, "mips3d") == 0)
16661 mips_opts.ase_mips3d = 1;
16662 else if (strcmp (name, "nomips3d") == 0)
16663 mips_opts.ase_mips3d = 0;
16664 else if (strcmp (name, "mdmx") == 0)
16665 mips_opts.ase_mdmx = 1;
16666 else if (strcmp (name, "nomdmx") == 0)
16667 mips_opts.ase_mdmx = 0;
16668 else if (strcmp (name, "dsp") == 0)
16670 if (!ISA_SUPPORTS_DSP_ASE)
16671 as_warn (_("%s ISA does not support DSP ASE"),
16672 mips_cpu_info_from_isa (mips_opts.isa)->name);
16673 mips_opts.ase_dsp = 1;
16674 mips_opts.ase_dspr2 = 0;
16676 else if (strcmp (name, "nodsp") == 0)
16678 mips_opts.ase_dsp = 0;
16679 mips_opts.ase_dspr2 = 0;
16681 else if (strcmp (name, "dspr2") == 0)
16683 if (!ISA_SUPPORTS_DSPR2_ASE)
16684 as_warn (_("%s ISA does not support DSP R2 ASE"),
16685 mips_cpu_info_from_isa (mips_opts.isa)->name);
16686 mips_opts.ase_dspr2 = 1;
16687 mips_opts.ase_dsp = 1;
16689 else if (strcmp (name, "nodspr2") == 0)
16691 mips_opts.ase_dspr2 = 0;
16692 mips_opts.ase_dsp = 0;
16694 else if (strcmp (name, "eva") == 0)
16696 if (!ISA_SUPPORTS_EVA_ASE)
16697 as_warn (_("%s ISA does not support EVA ASE"),
16698 mips_cpu_info_from_isa (mips_opts.isa)->name);
16699 mips_opts.ase_eva = 1;
16701 else if (strcmp (name, "noeva") == 0)
16702 mips_opts.ase_eva = 0;
16703 else if (strcmp (name, "mt") == 0)
16705 if (!ISA_SUPPORTS_MT_ASE)
16706 as_warn (_("%s ISA does not support MT ASE"),
16707 mips_cpu_info_from_isa (mips_opts.isa)->name);
16708 mips_opts.ase_mt = 1;
16710 else if (strcmp (name, "nomt") == 0)
16711 mips_opts.ase_mt = 0;
16712 else if (strcmp (name, "mcu") == 0)
16713 mips_opts.ase_mcu = 1;
16714 else if (strcmp (name, "nomcu") == 0)
16715 mips_opts.ase_mcu = 0;
16716 else if (strcmp (name, "virt") == 0)
16718 if (!ISA_SUPPORTS_VIRT_ASE)
16719 as_warn (_("%s ISA does not support Virtualization ASE"),
16720 mips_cpu_info_from_isa (mips_opts.isa)->name);
16721 mips_opts.ase_virt = 1;
16723 else if (strcmp (name, "novirt") == 0)
16724 mips_opts.ase_virt = 0;
16725 else if (strncmp (name, "mips", 4) == 0 || strncmp (name, "arch=", 5) == 0)
16729 /* Permit the user to change the ISA and architecture on the fly.
16730 Needless to say, misuse can cause serious problems. */
16731 if (strcmp (name, "mips0") == 0 || strcmp (name, "arch=default") == 0)
16734 mips_opts.isa = file_mips_isa;
16735 mips_opts.arch = file_mips_arch;
16737 else if (strncmp (name, "arch=", 5) == 0)
16739 const struct mips_cpu_info *p;
16741 p = mips_parse_cpu("internal use", name + 5);
16743 as_bad (_("unknown architecture %s"), name + 5);
16746 mips_opts.arch = p->cpu;
16747 mips_opts.isa = p->isa;
16750 else if (strncmp (name, "mips", 4) == 0)
16752 const struct mips_cpu_info *p;
16754 p = mips_parse_cpu("internal use", name);
16756 as_bad (_("unknown ISA level %s"), name + 4);
16759 mips_opts.arch = p->cpu;
16760 mips_opts.isa = p->isa;
16764 as_bad (_("unknown ISA or architecture %s"), name);
16766 switch (mips_opts.isa)
16774 mips_opts.gp32 = 1;
16775 mips_opts.fp32 = 1;
16782 mips_opts.gp32 = 0;
16783 if (mips_opts.arch == CPU_R5900)
16785 mips_opts.fp32 = 1;
16789 mips_opts.fp32 = 0;
16793 as_bad (_("unknown ISA level %s"), name + 4);
16798 mips_opts.gp32 = file_mips_gp32;
16799 mips_opts.fp32 = file_mips_fp32;
16802 else if (strcmp (name, "autoextend") == 0)
16803 mips_opts.noautoextend = 0;
16804 else if (strcmp (name, "noautoextend") == 0)
16805 mips_opts.noautoextend = 1;
16806 else if (strcmp (name, "push") == 0)
16808 struct mips_option_stack *s;
16810 s = (struct mips_option_stack *) xmalloc (sizeof *s);
16811 s->next = mips_opts_stack;
16812 s->options = mips_opts;
16813 mips_opts_stack = s;
16815 else if (strcmp (name, "pop") == 0)
16817 struct mips_option_stack *s;
16819 s = mips_opts_stack;
16821 as_bad (_(".set pop with no .set push"));
16824 /* If we're changing the reorder mode we need to handle
16825 delay slots correctly. */
16826 if (s->options.noreorder && ! mips_opts.noreorder)
16827 start_noreorder ();
16828 else if (! s->options.noreorder && mips_opts.noreorder)
16831 mips_opts = s->options;
16832 mips_opts_stack = s->next;
16836 else if (strcmp (name, "sym32") == 0)
16837 mips_opts.sym32 = TRUE;
16838 else if (strcmp (name, "nosym32") == 0)
16839 mips_opts.sym32 = FALSE;
16840 else if (strchr (name, ','))
16842 /* Generic ".set" directive; use the generic handler. */
16843 *input_line_pointer = ch;
16844 input_line_pointer = name;
16850 as_warn (_("Tried to set unrecognized symbol: %s\n"), name);
16852 *input_line_pointer = ch;
16853 demand_empty_rest_of_line ();
16856 /* Handle the .abicalls pseudo-op. I believe this is equivalent to
16857 .option pic2. It means to generate SVR4 PIC calls. */
16860 s_abicalls (int ignore ATTRIBUTE_UNUSED)
16862 mips_pic = SVR4_PIC;
16863 mips_abicalls = TRUE;
16865 if (g_switch_seen && g_switch_value != 0)
16866 as_warn (_("-G may not be used with SVR4 PIC code"));
16867 g_switch_value = 0;
16869 bfd_set_gp_size (stdoutput, 0);
16870 demand_empty_rest_of_line ();
16873 /* Handle the .cpload pseudo-op. This is used when generating SVR4
16874 PIC code. It sets the $gp register for the function based on the
16875 function address, which is in the register named in the argument.
16876 This uses a relocation against _gp_disp, which is handled specially
16877 by the linker. The result is:
16878 lui $gp,%hi(_gp_disp)
16879 addiu $gp,$gp,%lo(_gp_disp)
16880 addu $gp,$gp,.cpload argument
16881 The .cpload argument is normally $25 == $t9.
16883 The -mno-shared option changes this to:
16884 lui $gp,%hi(__gnu_local_gp)
16885 addiu $gp,$gp,%lo(__gnu_local_gp)
16886 and the argument is ignored. This saves an instruction, but the
16887 resulting code is not position independent; it uses an absolute
16888 address for __gnu_local_gp. Thus code assembled with -mno-shared
16889 can go into an ordinary executable, but not into a shared library. */
16892 s_cpload (int ignore ATTRIBUTE_UNUSED)
16898 /* If we are not generating SVR4 PIC code, or if this is NewABI code,
16899 .cpload is ignored. */
16900 if (mips_pic != SVR4_PIC || HAVE_NEWABI)
16906 if (mips_opts.mips16)
16908 as_bad (_("%s not supported in MIPS16 mode"), ".cpload");
16909 ignore_rest_of_line ();
16913 /* .cpload should be in a .set noreorder section. */
16914 if (mips_opts.noreorder == 0)
16915 as_warn (_(".cpload not in noreorder section"));
16917 reg = tc_get_register (0);
16919 /* If we need to produce a 64-bit address, we are better off using
16920 the default instruction sequence. */
16921 in_shared = mips_in_shared || HAVE_64BIT_SYMBOLS;
16923 ex.X_op = O_symbol;
16924 ex.X_add_symbol = symbol_find_or_make (in_shared ? "_gp_disp" :
16926 ex.X_op_symbol = NULL;
16927 ex.X_add_number = 0;
16929 /* In ELF, this symbol is implicitly an STT_OBJECT symbol. */
16930 symbol_get_bfdsym (ex.X_add_symbol)->flags |= BSF_OBJECT;
16932 mips_mark_labels ();
16933 mips_assembling_insn = TRUE;
16936 macro_build_lui (&ex, mips_gp_register);
16937 macro_build (&ex, "addiu", "t,r,j", mips_gp_register,
16938 mips_gp_register, BFD_RELOC_LO16);
16940 macro_build (NULL, "addu", "d,v,t", mips_gp_register,
16941 mips_gp_register, reg);
16944 mips_assembling_insn = FALSE;
16945 demand_empty_rest_of_line ();
16948 /* Handle the .cpsetup pseudo-op defined for NewABI PIC code. The syntax is:
16949 .cpsetup $reg1, offset|$reg2, label
16951 If offset is given, this results in:
16952 sd $gp, offset($sp)
16953 lui $gp, %hi(%neg(%gp_rel(label)))
16954 addiu $gp, $gp, %lo(%neg(%gp_rel(label)))
16955 daddu $gp, $gp, $reg1
16957 If $reg2 is given, this results in:
16958 daddu $reg2, $gp, $0
16959 lui $gp, %hi(%neg(%gp_rel(label)))
16960 addiu $gp, $gp, %lo(%neg(%gp_rel(label)))
16961 daddu $gp, $gp, $reg1
16962 $reg1 is normally $25 == $t9.
16964 The -mno-shared option replaces the last three instructions with
16966 addiu $gp,$gp,%lo(_gp) */
16969 s_cpsetup (int ignore ATTRIBUTE_UNUSED)
16971 expressionS ex_off;
16972 expressionS ex_sym;
16975 /* If we are not generating SVR4 PIC code, .cpsetup is ignored.
16976 We also need NewABI support. */
16977 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
16983 if (mips_opts.mips16)
16985 as_bad (_("%s not supported in MIPS16 mode"), ".cpsetup");
16986 ignore_rest_of_line ();
16990 reg1 = tc_get_register (0);
16991 SKIP_WHITESPACE ();
16992 if (*input_line_pointer != ',')
16994 as_bad (_("missing argument separator ',' for .cpsetup"));
16998 ++input_line_pointer;
16999 SKIP_WHITESPACE ();
17000 if (*input_line_pointer == '$')
17002 mips_cpreturn_register = tc_get_register (0);
17003 mips_cpreturn_offset = -1;
17007 mips_cpreturn_offset = get_absolute_expression ();
17008 mips_cpreturn_register = -1;
17010 SKIP_WHITESPACE ();
17011 if (*input_line_pointer != ',')
17013 as_bad (_("missing argument separator ',' for .cpsetup"));
17017 ++input_line_pointer;
17018 SKIP_WHITESPACE ();
17019 expression (&ex_sym);
17021 mips_mark_labels ();
17022 mips_assembling_insn = TRUE;
17025 if (mips_cpreturn_register == -1)
17027 ex_off.X_op = O_constant;
17028 ex_off.X_add_symbol = NULL;
17029 ex_off.X_op_symbol = NULL;
17030 ex_off.X_add_number = mips_cpreturn_offset;
17032 macro_build (&ex_off, "sd", "t,o(b)", mips_gp_register,
17033 BFD_RELOC_LO16, SP);
17036 macro_build (NULL, "daddu", "d,v,t", mips_cpreturn_register,
17037 mips_gp_register, 0);
17039 if (mips_in_shared || HAVE_64BIT_SYMBOLS)
17041 macro_build (&ex_sym, "lui", LUI_FMT, mips_gp_register,
17042 -1, BFD_RELOC_GPREL16, BFD_RELOC_MIPS_SUB,
17045 macro_build (&ex_sym, "addiu", "t,r,j", mips_gp_register,
17046 mips_gp_register, -1, BFD_RELOC_GPREL16,
17047 BFD_RELOC_MIPS_SUB, BFD_RELOC_LO16);
17049 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", mips_gp_register,
17050 mips_gp_register, reg1);
17056 ex.X_op = O_symbol;
17057 ex.X_add_symbol = symbol_find_or_make ("__gnu_local_gp");
17058 ex.X_op_symbol = NULL;
17059 ex.X_add_number = 0;
17061 /* In ELF, this symbol is implicitly an STT_OBJECT symbol. */
17062 symbol_get_bfdsym (ex.X_add_symbol)->flags |= BSF_OBJECT;
17064 macro_build_lui (&ex, mips_gp_register);
17065 macro_build (&ex, "addiu", "t,r,j", mips_gp_register,
17066 mips_gp_register, BFD_RELOC_LO16);
17071 mips_assembling_insn = FALSE;
17072 demand_empty_rest_of_line ();
17076 s_cplocal (int ignore ATTRIBUTE_UNUSED)
17078 /* If we are not generating SVR4 PIC code, or if this is not NewABI code,
17079 .cplocal is ignored. */
17080 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
17086 if (mips_opts.mips16)
17088 as_bad (_("%s not supported in MIPS16 mode"), ".cplocal");
17089 ignore_rest_of_line ();
17093 mips_gp_register = tc_get_register (0);
17094 demand_empty_rest_of_line ();
17097 /* Handle the .cprestore pseudo-op. This stores $gp into a given
17098 offset from $sp. The offset is remembered, and after making a PIC
17099 call $gp is restored from that location. */
17102 s_cprestore (int ignore ATTRIBUTE_UNUSED)
17106 /* If we are not generating SVR4 PIC code, or if this is NewABI code,
17107 .cprestore is ignored. */
17108 if (mips_pic != SVR4_PIC || HAVE_NEWABI)
17114 if (mips_opts.mips16)
17116 as_bad (_("%s not supported in MIPS16 mode"), ".cprestore");
17117 ignore_rest_of_line ();
17121 mips_cprestore_offset = get_absolute_expression ();
17122 mips_cprestore_valid = 1;
17124 ex.X_op = O_constant;
17125 ex.X_add_symbol = NULL;
17126 ex.X_op_symbol = NULL;
17127 ex.X_add_number = mips_cprestore_offset;
17129 mips_mark_labels ();
17130 mips_assembling_insn = TRUE;
17133 macro_build_ldst_constoffset (&ex, ADDRESS_STORE_INSN, mips_gp_register,
17134 SP, HAVE_64BIT_ADDRESSES);
17137 mips_assembling_insn = FALSE;
17138 demand_empty_rest_of_line ();
17141 /* Handle the .cpreturn pseudo-op defined for NewABI PIC code. If an offset
17142 was given in the preceding .cpsetup, it results in:
17143 ld $gp, offset($sp)
17145 If a register $reg2 was given there, it results in:
17146 daddu $gp, $reg2, $0 */
17149 s_cpreturn (int ignore ATTRIBUTE_UNUSED)
17153 /* If we are not generating SVR4 PIC code, .cpreturn is ignored.
17154 We also need NewABI support. */
17155 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
17161 if (mips_opts.mips16)
17163 as_bad (_("%s not supported in MIPS16 mode"), ".cpreturn");
17164 ignore_rest_of_line ();
17168 mips_mark_labels ();
17169 mips_assembling_insn = TRUE;
17172 if (mips_cpreturn_register == -1)
17174 ex.X_op = O_constant;
17175 ex.X_add_symbol = NULL;
17176 ex.X_op_symbol = NULL;
17177 ex.X_add_number = mips_cpreturn_offset;
17179 macro_build (&ex, "ld", "t,o(b)", mips_gp_register, BFD_RELOC_LO16, SP);
17182 macro_build (NULL, "daddu", "d,v,t", mips_gp_register,
17183 mips_cpreturn_register, 0);
17186 mips_assembling_insn = FALSE;
17187 demand_empty_rest_of_line ();
17190 /* Handle a .dtprelword, .dtpreldword, .tprelword, or .tpreldword
17191 pseudo-op; DIRSTR says which. The pseudo-op generates a BYTES-size
17192 DTP- or TP-relative relocation of type RTYPE, for use in either DWARF
17193 debug information or MIPS16 TLS. */
17196 s_tls_rel_directive (const size_t bytes, const char *dirstr,
17197 bfd_reloc_code_real_type rtype)
17204 if (ex.X_op != O_symbol)
17206 as_bad (_("Unsupported use of %s"), dirstr);
17207 ignore_rest_of_line ();
17210 p = frag_more (bytes);
17211 md_number_to_chars (p, 0, bytes);
17212 fix_new_exp (frag_now, p - frag_now->fr_literal, bytes, &ex, FALSE, rtype);
17213 demand_empty_rest_of_line ();
17214 mips_clear_insn_labels ();
17217 /* Handle .dtprelword. */
17220 s_dtprelword (int ignore ATTRIBUTE_UNUSED)
17222 s_tls_rel_directive (4, ".dtprelword", BFD_RELOC_MIPS_TLS_DTPREL32);
17225 /* Handle .dtpreldword. */
17228 s_dtpreldword (int ignore ATTRIBUTE_UNUSED)
17230 s_tls_rel_directive (8, ".dtpreldword", BFD_RELOC_MIPS_TLS_DTPREL64);
17233 /* Handle .tprelword. */
17236 s_tprelword (int ignore ATTRIBUTE_UNUSED)
17238 s_tls_rel_directive (4, ".tprelword", BFD_RELOC_MIPS_TLS_TPREL32);
17241 /* Handle .tpreldword. */
17244 s_tpreldword (int ignore ATTRIBUTE_UNUSED)
17246 s_tls_rel_directive (8, ".tpreldword", BFD_RELOC_MIPS_TLS_TPREL64);
17249 /* Handle the .gpvalue pseudo-op. This is used when generating NewABI PIC
17250 code. It sets the offset to use in gp_rel relocations. */
17253 s_gpvalue (int ignore ATTRIBUTE_UNUSED)
17255 /* If we are not generating SVR4 PIC code, .gpvalue is ignored.
17256 We also need NewABI support. */
17257 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
17263 mips_gprel_offset = get_absolute_expression ();
17265 demand_empty_rest_of_line ();
17268 /* Handle the .gpword pseudo-op. This is used when generating PIC
17269 code. It generates a 32 bit GP relative reloc. */
17272 s_gpword (int ignore ATTRIBUTE_UNUSED)
17274 segment_info_type *si;
17275 struct insn_label_list *l;
17279 /* When not generating PIC code, this is treated as .word. */
17280 if (mips_pic != SVR4_PIC)
17286 si = seg_info (now_seg);
17287 l = si->label_list;
17288 mips_emit_delays ();
17290 mips_align (2, 0, l);
17293 mips_clear_insn_labels ();
17295 if (ex.X_op != O_symbol || ex.X_add_number != 0)
17297 as_bad (_("Unsupported use of .gpword"));
17298 ignore_rest_of_line ();
17302 md_number_to_chars (p, 0, 4);
17303 fix_new_exp (frag_now, p - frag_now->fr_literal, 4, &ex, FALSE,
17304 BFD_RELOC_GPREL32);
17306 demand_empty_rest_of_line ();
17310 s_gpdword (int ignore ATTRIBUTE_UNUSED)
17312 segment_info_type *si;
17313 struct insn_label_list *l;
17317 /* When not generating PIC code, this is treated as .dword. */
17318 if (mips_pic != SVR4_PIC)
17324 si = seg_info (now_seg);
17325 l = si->label_list;
17326 mips_emit_delays ();
17328 mips_align (3, 0, l);
17331 mips_clear_insn_labels ();
17333 if (ex.X_op != O_symbol || ex.X_add_number != 0)
17335 as_bad (_("Unsupported use of .gpdword"));
17336 ignore_rest_of_line ();
17340 md_number_to_chars (p, 0, 8);
17341 fix_new_exp (frag_now, p - frag_now->fr_literal, 4, &ex, FALSE,
17342 BFD_RELOC_GPREL32)->fx_tcbit = 1;
17344 /* GPREL32 composed with 64 gives a 64-bit GP offset. */
17345 fix_new (frag_now, p - frag_now->fr_literal, 8, NULL, 0,
17346 FALSE, BFD_RELOC_64)->fx_tcbit = 1;
17348 demand_empty_rest_of_line ();
17351 /* Handle the .ehword pseudo-op. This is used when generating unwinding
17352 tables. It generates a R_MIPS_EH reloc. */
17355 s_ehword (int ignore ATTRIBUTE_UNUSED)
17360 mips_emit_delays ();
17363 mips_clear_insn_labels ();
17365 if (ex.X_op != O_symbol || ex.X_add_number != 0)
17367 as_bad (_("Unsupported use of .ehword"));
17368 ignore_rest_of_line ();
17372 md_number_to_chars (p, 0, 4);
17373 fix_new_exp (frag_now, p - frag_now->fr_literal, 4, &ex, FALSE,
17374 BFD_RELOC_MIPS_EH);
17376 demand_empty_rest_of_line ();
17379 /* Handle the .cpadd pseudo-op. This is used when dealing with switch
17380 tables in SVR4 PIC code. */
17383 s_cpadd (int ignore ATTRIBUTE_UNUSED)
17387 /* This is ignored when not generating SVR4 PIC code. */
17388 if (mips_pic != SVR4_PIC)
17394 mips_mark_labels ();
17395 mips_assembling_insn = TRUE;
17397 /* Add $gp to the register named as an argument. */
17399 reg = tc_get_register (0);
17400 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", reg, reg, mips_gp_register);
17403 mips_assembling_insn = FALSE;
17404 demand_empty_rest_of_line ();
17407 /* Handle the .insn pseudo-op. This marks instruction labels in
17408 mips16/micromips mode. This permits the linker to handle them specially,
17409 such as generating jalx instructions when needed. We also make
17410 them odd for the duration of the assembly, in order to generate the
17411 right sort of code. We will make them even in the adjust_symtab
17412 routine, while leaving them marked. This is convenient for the
17413 debugger and the disassembler. The linker knows to make them odd
17417 s_insn (int ignore ATTRIBUTE_UNUSED)
17419 mips_mark_labels ();
17421 demand_empty_rest_of_line ();
17424 /* Handle a .stab[snd] directive. Ideally these directives would be
17425 implemented in a transparent way, so that removing them would not
17426 have any effect on the generated instructions. However, s_stab
17427 internally changes the section, so in practice we need to decide
17428 now whether the preceding label marks compressed code. We do not
17429 support changing the compression mode of a label after a .stab*
17430 directive, such as in:
17436 so the current mode wins. */
17439 s_mips_stab (int type)
17441 mips_mark_labels ();
17445 /* Handle the .weakext pseudo-op as defined in Kane and Heinrich. */
17448 s_mips_weakext (int ignore ATTRIBUTE_UNUSED)
17455 name = input_line_pointer;
17456 c = get_symbol_end ();
17457 symbolP = symbol_find_or_make (name);
17458 S_SET_WEAK (symbolP);
17459 *input_line_pointer = c;
17461 SKIP_WHITESPACE ();
17463 if (! is_end_of_line[(unsigned char) *input_line_pointer])
17465 if (S_IS_DEFINED (symbolP))
17467 as_bad (_("ignoring attempt to redefine symbol %s"),
17468 S_GET_NAME (symbolP));
17469 ignore_rest_of_line ();
17473 if (*input_line_pointer == ',')
17475 ++input_line_pointer;
17476 SKIP_WHITESPACE ();
17480 if (exp.X_op != O_symbol)
17482 as_bad (_("bad .weakext directive"));
17483 ignore_rest_of_line ();
17486 symbol_set_value_expression (symbolP, &exp);
17489 demand_empty_rest_of_line ();
17492 /* Parse a register string into a number. Called from the ECOFF code
17493 to parse .frame. The argument is non-zero if this is the frame
17494 register, so that we can record it in mips_frame_reg. */
17497 tc_get_register (int frame)
17501 SKIP_WHITESPACE ();
17502 if (! reg_lookup (&input_line_pointer, RWARN | RTYPE_NUM | RTYPE_GP, ®))
17506 mips_frame_reg = reg != 0 ? reg : SP;
17507 mips_frame_reg_valid = 1;
17508 mips_cprestore_valid = 0;
17514 md_section_align (asection *seg, valueT addr)
17516 int align = bfd_get_section_alignment (stdoutput, seg);
17520 /* We don't need to align ELF sections to the full alignment.
17521 However, Irix 5 may prefer that we align them at least to a 16
17522 byte boundary. We don't bother to align the sections if we
17523 are targeted for an embedded system. */
17524 if (strncmp (TARGET_OS, "elf", 3) == 0)
17530 return ((addr + (1 << align) - 1) & (-1 << align));
17533 /* Utility routine, called from above as well. If called while the
17534 input file is still being read, it's only an approximation. (For
17535 example, a symbol may later become defined which appeared to be
17536 undefined earlier.) */
17539 nopic_need_relax (symbolS *sym, int before_relaxing)
17544 if (g_switch_value > 0)
17546 const char *symname;
17549 /* Find out whether this symbol can be referenced off the $gp
17550 register. It can be if it is smaller than the -G size or if
17551 it is in the .sdata or .sbss section. Certain symbols can
17552 not be referenced off the $gp, although it appears as though
17554 symname = S_GET_NAME (sym);
17555 if (symname != (const char *) NULL
17556 && (strcmp (symname, "eprol") == 0
17557 || strcmp (symname, "etext") == 0
17558 || strcmp (symname, "_gp") == 0
17559 || strcmp (symname, "edata") == 0
17560 || strcmp (symname, "_fbss") == 0
17561 || strcmp (symname, "_fdata") == 0
17562 || strcmp (symname, "_ftext") == 0
17563 || strcmp (symname, "end") == 0
17564 || strcmp (symname, "_gp_disp") == 0))
17566 else if ((! S_IS_DEFINED (sym) || S_IS_COMMON (sym))
17568 #ifndef NO_ECOFF_DEBUGGING
17569 || (symbol_get_obj (sym)->ecoff_extern_size != 0
17570 && (symbol_get_obj (sym)->ecoff_extern_size
17571 <= g_switch_value))
17573 /* We must defer this decision until after the whole
17574 file has been read, since there might be a .extern
17575 after the first use of this symbol. */
17576 || (before_relaxing
17577 #ifndef NO_ECOFF_DEBUGGING
17578 && symbol_get_obj (sym)->ecoff_extern_size == 0
17580 && S_GET_VALUE (sym) == 0)
17581 || (S_GET_VALUE (sym) != 0
17582 && S_GET_VALUE (sym) <= g_switch_value)))
17586 const char *segname;
17588 segname = segment_name (S_GET_SEGMENT (sym));
17589 gas_assert (strcmp (segname, ".lit8") != 0
17590 && strcmp (segname, ".lit4") != 0);
17591 change = (strcmp (segname, ".sdata") != 0
17592 && strcmp (segname, ".sbss") != 0
17593 && strncmp (segname, ".sdata.", 7) != 0
17594 && strncmp (segname, ".sbss.", 6) != 0
17595 && strncmp (segname, ".gnu.linkonce.sb.", 17) != 0
17596 && strncmp (segname, ".gnu.linkonce.s.", 16) != 0);
17601 /* We are not optimizing for the $gp register. */
17606 /* Return true if the given symbol should be considered local for SVR4 PIC. */
17609 pic_need_relax (symbolS *sym, asection *segtype)
17613 /* Handle the case of a symbol equated to another symbol. */
17614 while (symbol_equated_reloc_p (sym))
17618 /* It's possible to get a loop here in a badly written program. */
17619 n = symbol_get_value_expression (sym)->X_add_symbol;
17625 if (symbol_section_p (sym))
17628 symsec = S_GET_SEGMENT (sym);
17630 /* This must duplicate the test in adjust_reloc_syms. */
17631 return (!bfd_is_und_section (symsec)
17632 && !bfd_is_abs_section (symsec)
17633 && !bfd_is_com_section (symsec)
17634 && !s_is_linkonce (sym, segtype)
17636 /* A global or weak symbol is treated as external. */
17637 && (!IS_ELF || (! S_IS_WEAK (sym) && ! S_IS_EXTERNAL (sym)))
17643 /* Given a mips16 variant frag FRAGP, return non-zero if it needs an
17644 extended opcode. SEC is the section the frag is in. */
17647 mips16_extended_frag (fragS *fragp, asection *sec, long stretch)
17650 const struct mips16_immed_operand *op;
17652 int mintiny, maxtiny;
17656 if (RELAX_MIPS16_USER_SMALL (fragp->fr_subtype))
17658 if (RELAX_MIPS16_USER_EXT (fragp->fr_subtype))
17661 type = RELAX_MIPS16_TYPE (fragp->fr_subtype);
17662 op = mips16_immed_operands;
17663 while (op->type != type)
17666 gas_assert (op < mips16_immed_operands + MIPS16_NUM_IMMED);
17671 if (type == '<' || type == '>' || type == '[' || type == ']')
17674 maxtiny = 1 << op->nbits;
17679 maxtiny = (1 << op->nbits) - 1;
17684 mintiny = - (1 << (op->nbits - 1));
17685 maxtiny = (1 << (op->nbits - 1)) - 1;
17688 sym_frag = symbol_get_frag (fragp->fr_symbol);
17689 val = S_GET_VALUE (fragp->fr_symbol);
17690 symsec = S_GET_SEGMENT (fragp->fr_symbol);
17696 /* We won't have the section when we are called from
17697 mips_relax_frag. However, we will always have been called
17698 from md_estimate_size_before_relax first. If this is a
17699 branch to a different section, we mark it as such. If SEC is
17700 NULL, and the frag is not marked, then it must be a branch to
17701 the same section. */
17704 if (RELAX_MIPS16_LONG_BRANCH (fragp->fr_subtype))
17709 /* Must have been called from md_estimate_size_before_relax. */
17712 fragp->fr_subtype =
17713 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
17715 /* FIXME: We should support this, and let the linker
17716 catch branches and loads that are out of range. */
17717 as_bad_where (fragp->fr_file, fragp->fr_line,
17718 _("unsupported PC relative reference to different section"));
17722 if (fragp != sym_frag && sym_frag->fr_address == 0)
17723 /* Assume non-extended on the first relaxation pass.
17724 The address we have calculated will be bogus if this is
17725 a forward branch to another frag, as the forward frag
17726 will have fr_address == 0. */
17730 /* In this case, we know for sure that the symbol fragment is in
17731 the same section. If the relax_marker of the symbol fragment
17732 differs from the relax_marker of this fragment, we have not
17733 yet adjusted the symbol fragment fr_address. We want to add
17734 in STRETCH in order to get a better estimate of the address.
17735 This particularly matters because of the shift bits. */
17737 && sym_frag->relax_marker != fragp->relax_marker)
17741 /* Adjust stretch for any alignment frag. Note that if have
17742 been expanding the earlier code, the symbol may be
17743 defined in what appears to be an earlier frag. FIXME:
17744 This doesn't handle the fr_subtype field, which specifies
17745 a maximum number of bytes to skip when doing an
17747 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
17749 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
17752 stretch = - ((- stretch)
17753 & ~ ((1 << (int) f->fr_offset) - 1));
17755 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
17764 addr = fragp->fr_address + fragp->fr_fix;
17766 /* The base address rules are complicated. The base address of
17767 a branch is the following instruction. The base address of a
17768 PC relative load or add is the instruction itself, but if it
17769 is in a delay slot (in which case it can not be extended) use
17770 the address of the instruction whose delay slot it is in. */
17771 if (type == 'p' || type == 'q')
17775 /* If we are currently assuming that this frag should be
17776 extended, then, the current address is two bytes
17778 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
17781 /* Ignore the low bit in the target, since it will be set
17782 for a text label. */
17783 if ((val & 1) != 0)
17786 else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype))
17788 else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype))
17791 val -= addr & ~ ((1 << op->shift) - 1);
17793 /* Branch offsets have an implicit 0 in the lowest bit. */
17794 if (type == 'p' || type == 'q')
17797 /* If any of the shifted bits are set, we must use an extended
17798 opcode. If the address depends on the size of this
17799 instruction, this can lead to a loop, so we arrange to always
17800 use an extended opcode. We only check this when we are in
17801 the main relaxation loop, when SEC is NULL. */
17802 if ((val & ((1 << op->shift) - 1)) != 0 && sec == NULL)
17804 fragp->fr_subtype =
17805 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
17809 /* If we are about to mark a frag as extended because the value
17810 is precisely maxtiny + 1, then there is a chance of an
17811 infinite loop as in the following code:
17816 In this case when the la is extended, foo is 0x3fc bytes
17817 away, so the la can be shrunk, but then foo is 0x400 away, so
17818 the la must be extended. To avoid this loop, we mark the
17819 frag as extended if it was small, and is about to become
17820 extended with a value of maxtiny + 1. */
17821 if (val == ((maxtiny + 1) << op->shift)
17822 && ! RELAX_MIPS16_EXTENDED (fragp->fr_subtype)
17825 fragp->fr_subtype =
17826 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
17830 else if (symsec != absolute_section && sec != NULL)
17831 as_bad_where (fragp->fr_file, fragp->fr_line, _("unsupported relocation"));
17833 if ((val & ((1 << op->shift) - 1)) != 0
17834 || val < (mintiny << op->shift)
17835 || val > (maxtiny << op->shift))
17841 /* Compute the length of a branch sequence, and adjust the
17842 RELAX_BRANCH_TOOFAR bit accordingly. If FRAGP is NULL, the
17843 worst-case length is computed, with UPDATE being used to indicate
17844 whether an unconditional (-1), branch-likely (+1) or regular (0)
17845 branch is to be computed. */
17847 relaxed_branch_length (fragS *fragp, asection *sec, int update)
17849 bfd_boolean toofar;
17853 && S_IS_DEFINED (fragp->fr_symbol)
17854 && sec == S_GET_SEGMENT (fragp->fr_symbol))
17859 val = S_GET_VALUE (fragp->fr_symbol) + fragp->fr_offset;
17861 addr = fragp->fr_address + fragp->fr_fix + 4;
17865 toofar = val < - (0x8000 << 2) || val >= (0x8000 << 2);
17868 /* If the symbol is not defined or it's in a different segment,
17869 assume the user knows what's going on and emit a short
17875 if (fragp && update && toofar != RELAX_BRANCH_TOOFAR (fragp->fr_subtype))
17877 = RELAX_BRANCH_ENCODE (RELAX_BRANCH_AT (fragp->fr_subtype),
17878 RELAX_BRANCH_UNCOND (fragp->fr_subtype),
17879 RELAX_BRANCH_LIKELY (fragp->fr_subtype),
17880 RELAX_BRANCH_LINK (fragp->fr_subtype),
17886 if (fragp ? RELAX_BRANCH_LIKELY (fragp->fr_subtype) : (update > 0))
17889 if (mips_pic != NO_PIC)
17891 /* Additional space for PIC loading of target address. */
17893 if (mips_opts.isa == ISA_MIPS1)
17894 /* Additional space for $at-stabilizing nop. */
17898 /* If branch is conditional. */
17899 if (fragp ? !RELAX_BRANCH_UNCOND (fragp->fr_subtype) : (update >= 0))
17906 /* Compute the length of a branch sequence, and adjust the
17907 RELAX_MICROMIPS_TOOFAR32 bit accordingly. If FRAGP is NULL, the
17908 worst-case length is computed, with UPDATE being used to indicate
17909 whether an unconditional (-1), or regular (0) branch is to be
17913 relaxed_micromips_32bit_branch_length (fragS *fragp, asection *sec, int update)
17915 bfd_boolean toofar;
17919 && S_IS_DEFINED (fragp->fr_symbol)
17920 && sec == S_GET_SEGMENT (fragp->fr_symbol))
17925 val = S_GET_VALUE (fragp->fr_symbol) + fragp->fr_offset;
17926 /* Ignore the low bit in the target, since it will be set
17927 for a text label. */
17928 if ((val & 1) != 0)
17931 addr = fragp->fr_address + fragp->fr_fix + 4;
17935 toofar = val < - (0x8000 << 1) || val >= (0x8000 << 1);
17938 /* If the symbol is not defined or it's in a different segment,
17939 assume the user knows what's going on and emit a short
17945 if (fragp && update
17946 && toofar != RELAX_MICROMIPS_TOOFAR32 (fragp->fr_subtype))
17947 fragp->fr_subtype = (toofar
17948 ? RELAX_MICROMIPS_MARK_TOOFAR32 (fragp->fr_subtype)
17949 : RELAX_MICROMIPS_CLEAR_TOOFAR32 (fragp->fr_subtype));
17954 bfd_boolean compact_known = fragp != NULL;
17955 bfd_boolean compact = FALSE;
17956 bfd_boolean uncond;
17959 compact = RELAX_MICROMIPS_COMPACT (fragp->fr_subtype);
17961 uncond = RELAX_MICROMIPS_UNCOND (fragp->fr_subtype);
17963 uncond = update < 0;
17965 /* If label is out of range, we turn branch <br>:
17967 <br> label # 4 bytes
17973 nop # 2 bytes if compact && !PIC
17976 if (mips_pic == NO_PIC && (!compact_known || compact))
17979 /* If assembling PIC code, we further turn:
17985 lw/ld at, %got(label)(gp) # 4 bytes
17986 d/addiu at, %lo(label) # 4 bytes
17989 if (mips_pic != NO_PIC)
17992 /* If branch <br> is conditional, we prepend negated branch <brneg>:
17994 <brneg> 0f # 4 bytes
17995 nop # 2 bytes if !compact
17998 length += (compact_known && compact) ? 4 : 6;
18004 /* Compute the length of a branch, and adjust the RELAX_MICROMIPS_TOOFAR16
18005 bit accordingly. */
18008 relaxed_micromips_16bit_branch_length (fragS *fragp, asection *sec, int update)
18010 bfd_boolean toofar;
18013 && S_IS_DEFINED (fragp->fr_symbol)
18014 && sec == S_GET_SEGMENT (fragp->fr_symbol))
18020 val = S_GET_VALUE (fragp->fr_symbol) + fragp->fr_offset;
18021 /* Ignore the low bit in the target, since it will be set
18022 for a text label. */
18023 if ((val & 1) != 0)
18026 /* Assume this is a 2-byte branch. */
18027 addr = fragp->fr_address + fragp->fr_fix + 2;
18029 /* We try to avoid the infinite loop by not adding 2 more bytes for
18034 type = RELAX_MICROMIPS_TYPE (fragp->fr_subtype);
18036 toofar = val < - (0x200 << 1) || val >= (0x200 << 1);
18037 else if (type == 'E')
18038 toofar = val < - (0x40 << 1) || val >= (0x40 << 1);
18043 /* If the symbol is not defined or it's in a different segment,
18044 we emit a normal 32-bit branch. */
18047 if (fragp && update
18048 && toofar != RELAX_MICROMIPS_TOOFAR16 (fragp->fr_subtype))
18050 = toofar ? RELAX_MICROMIPS_MARK_TOOFAR16 (fragp->fr_subtype)
18051 : RELAX_MICROMIPS_CLEAR_TOOFAR16 (fragp->fr_subtype);
18059 /* Estimate the size of a frag before relaxing. Unless this is the
18060 mips16, we are not really relaxing here, and the final size is
18061 encoded in the subtype information. For the mips16, we have to
18062 decide whether we are using an extended opcode or not. */
18065 md_estimate_size_before_relax (fragS *fragp, asection *segtype)
18069 if (RELAX_BRANCH_P (fragp->fr_subtype))
18072 fragp->fr_var = relaxed_branch_length (fragp, segtype, FALSE);
18074 return fragp->fr_var;
18077 if (RELAX_MIPS16_P (fragp->fr_subtype))
18078 /* We don't want to modify the EXTENDED bit here; it might get us
18079 into infinite loops. We change it only in mips_relax_frag(). */
18080 return (RELAX_MIPS16_EXTENDED (fragp->fr_subtype) ? 4 : 2);
18082 if (RELAX_MICROMIPS_P (fragp->fr_subtype))
18086 if (RELAX_MICROMIPS_TYPE (fragp->fr_subtype) != 0)
18087 length = relaxed_micromips_16bit_branch_length (fragp, segtype, FALSE);
18088 if (length == 4 && RELAX_MICROMIPS_RELAX32 (fragp->fr_subtype))
18089 length = relaxed_micromips_32bit_branch_length (fragp, segtype, FALSE);
18090 fragp->fr_var = length;
18095 if (mips_pic == NO_PIC)
18096 change = nopic_need_relax (fragp->fr_symbol, 0);
18097 else if (mips_pic == SVR4_PIC)
18098 change = pic_need_relax (fragp->fr_symbol, segtype);
18099 else if (mips_pic == VXWORKS_PIC)
18100 /* For vxworks, GOT16 relocations never have a corresponding LO16. */
18107 fragp->fr_subtype |= RELAX_USE_SECOND;
18108 return -RELAX_FIRST (fragp->fr_subtype);
18111 return -RELAX_SECOND (fragp->fr_subtype);
18114 /* This is called to see whether a reloc against a defined symbol
18115 should be converted into a reloc against a section. */
18118 mips_fix_adjustable (fixS *fixp)
18120 if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT
18121 || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
18124 if (fixp->fx_addsy == NULL)
18127 /* If symbol SYM is in a mergeable section, relocations of the form
18128 SYM + 0 can usually be made section-relative. The mergeable data
18129 is then identified by the section offset rather than by the symbol.
18131 However, if we're generating REL LO16 relocations, the offset is split
18132 between the LO16 and parterning high part relocation. The linker will
18133 need to recalculate the complete offset in order to correctly identify
18136 The linker has traditionally not looked for the parterning high part
18137 relocation, and has thus allowed orphaned R_MIPS_LO16 relocations to be
18138 placed anywhere. Rather than break backwards compatibility by changing
18139 this, it seems better not to force the issue, and instead keep the
18140 original symbol. This will work with either linker behavior. */
18141 if ((lo16_reloc_p (fixp->fx_r_type)
18142 || reloc_needs_lo_p (fixp->fx_r_type))
18143 && HAVE_IN_PLACE_ADDENDS
18144 && (S_GET_SEGMENT (fixp->fx_addsy)->flags & SEC_MERGE) != 0)
18147 /* There is no place to store an in-place offset for JALR relocations.
18148 Likewise an in-range offset of limited PC-relative relocations may
18149 overflow the in-place relocatable field if recalculated against the
18150 start address of the symbol's containing section. */
18151 if (HAVE_IN_PLACE_ADDENDS
18152 && (limited_pcrel_reloc_p (fixp->fx_r_type)
18153 || jalr_reloc_p (fixp->fx_r_type)))
18157 /* R_MIPS16_26 relocations against non-MIPS16 functions might resolve
18158 to a floating-point stub. The same is true for non-R_MIPS16_26
18159 relocations against MIPS16 functions; in this case, the stub becomes
18160 the function's canonical address.
18162 Floating-point stubs are stored in unique .mips16.call.* or
18163 .mips16.fn.* sections. If a stub T for function F is in section S,
18164 the first relocation in section S must be against F; this is how the
18165 linker determines the target function. All relocations that might
18166 resolve to T must also be against F. We therefore have the following
18167 restrictions, which are given in an intentionally-redundant way:
18169 1. We cannot reduce R_MIPS16_26 relocations against non-MIPS16
18172 2. We cannot reduce a stub's relocations against non-MIPS16 symbols
18173 if that stub might be used.
18175 3. We cannot reduce non-R_MIPS16_26 relocations against MIPS16
18178 4. We cannot reduce a stub's relocations against MIPS16 symbols if
18179 that stub might be used.
18181 There is a further restriction:
18183 5. We cannot reduce jump relocations (R_MIPS_26, R_MIPS16_26 or
18184 R_MICROMIPS_26_S1) against MIPS16 or microMIPS symbols on
18185 targets with in-place addends; the relocation field cannot
18186 encode the low bit.
18188 For simplicity, we deal with (3)-(4) by not reducing _any_ relocation
18189 against a MIPS16 symbol. We deal with (5) by by not reducing any
18190 such relocations on REL targets.
18192 We deal with (1)-(2) by saying that, if there's a R_MIPS16_26
18193 relocation against some symbol R, no relocation against R may be
18194 reduced. (Note that this deals with (2) as well as (1) because
18195 relocations against global symbols will never be reduced on ELF
18196 targets.) This approach is a little simpler than trying to detect
18197 stub sections, and gives the "all or nothing" per-symbol consistency
18198 that we have for MIPS16 symbols. */
18200 && fixp->fx_subsy == NULL
18201 && (ELF_ST_IS_MIPS16 (S_GET_OTHER (fixp->fx_addsy))
18202 || *symbol_get_tc (fixp->fx_addsy)
18203 || (HAVE_IN_PLACE_ADDENDS
18204 && ELF_ST_IS_MICROMIPS (S_GET_OTHER (fixp->fx_addsy))
18205 && jmp_reloc_p (fixp->fx_r_type))))
18212 /* Translate internal representation of relocation info to BFD target
18216 tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixp)
18218 static arelent *retval[4];
18220 bfd_reloc_code_real_type code;
18222 memset (retval, 0, sizeof(retval));
18223 reloc = retval[0] = (arelent *) xcalloc (1, sizeof (arelent));
18224 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
18225 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
18226 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
18228 if (fixp->fx_pcrel)
18230 gas_assert (fixp->fx_r_type == BFD_RELOC_16_PCREL_S2
18231 || fixp->fx_r_type == BFD_RELOC_MICROMIPS_7_PCREL_S1
18232 || fixp->fx_r_type == BFD_RELOC_MICROMIPS_10_PCREL_S1
18233 || fixp->fx_r_type == BFD_RELOC_MICROMIPS_16_PCREL_S1
18234 || fixp->fx_r_type == BFD_RELOC_32_PCREL);
18236 /* At this point, fx_addnumber is "symbol offset - pcrel address".
18237 Relocations want only the symbol offset. */
18238 reloc->addend = fixp->fx_addnumber + reloc->address;
18241 /* A gruesome hack which is a result of the gruesome gas
18242 reloc handling. What's worse, for COFF (as opposed to
18243 ECOFF), we might need yet another copy of reloc->address.
18244 See bfd_install_relocation. */
18245 reloc->addend += reloc->address;
18249 reloc->addend = fixp->fx_addnumber;
18251 /* Since the old MIPS ELF ABI uses Rel instead of Rela, encode the vtable
18252 entry to be used in the relocation's section offset. */
18253 if (! HAVE_NEWABI && fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
18255 reloc->address = reloc->addend;
18259 code = fixp->fx_r_type;
18261 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
18262 if (reloc->howto == NULL)
18264 as_bad_where (fixp->fx_file, fixp->fx_line,
18265 _("Can not represent %s relocation in this object file format"),
18266 bfd_get_reloc_code_name (code));
18273 /* Relax a machine dependent frag. This returns the amount by which
18274 the current size of the frag should change. */
18277 mips_relax_frag (asection *sec, fragS *fragp, long stretch)
18279 if (RELAX_BRANCH_P (fragp->fr_subtype))
18281 offsetT old_var = fragp->fr_var;
18283 fragp->fr_var = relaxed_branch_length (fragp, sec, TRUE);
18285 return fragp->fr_var - old_var;
18288 if (RELAX_MICROMIPS_P (fragp->fr_subtype))
18290 offsetT old_var = fragp->fr_var;
18291 offsetT new_var = 4;
18293 if (RELAX_MICROMIPS_TYPE (fragp->fr_subtype) != 0)
18294 new_var = relaxed_micromips_16bit_branch_length (fragp, sec, TRUE);
18295 if (new_var == 4 && RELAX_MICROMIPS_RELAX32 (fragp->fr_subtype))
18296 new_var = relaxed_micromips_32bit_branch_length (fragp, sec, TRUE);
18297 fragp->fr_var = new_var;
18299 return new_var - old_var;
18302 if (! RELAX_MIPS16_P (fragp->fr_subtype))
18305 if (mips16_extended_frag (fragp, NULL, stretch))
18307 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
18309 fragp->fr_subtype = RELAX_MIPS16_MARK_EXTENDED (fragp->fr_subtype);
18314 if (! RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
18316 fragp->fr_subtype = RELAX_MIPS16_CLEAR_EXTENDED (fragp->fr_subtype);
18323 /* Convert a machine dependent frag. */
18326 md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, segT asec, fragS *fragp)
18328 if (RELAX_BRANCH_P (fragp->fr_subtype))
18331 unsigned long insn;
18335 buf = fragp->fr_literal + fragp->fr_fix;
18336 insn = read_insn (buf);
18338 if (!RELAX_BRANCH_TOOFAR (fragp->fr_subtype))
18340 /* We generate a fixup instead of applying it right now
18341 because, if there are linker relaxations, we're going to
18342 need the relocations. */
18343 exp.X_op = O_symbol;
18344 exp.X_add_symbol = fragp->fr_symbol;
18345 exp.X_add_number = fragp->fr_offset;
18347 fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 4, &exp, TRUE,
18348 BFD_RELOC_16_PCREL_S2);
18349 fixp->fx_file = fragp->fr_file;
18350 fixp->fx_line = fragp->fr_line;
18352 buf = write_insn (buf, insn);
18358 as_warn_where (fragp->fr_file, fragp->fr_line,
18359 _("Relaxed out-of-range branch into a jump"));
18361 if (RELAX_BRANCH_UNCOND (fragp->fr_subtype))
18364 if (!RELAX_BRANCH_LIKELY (fragp->fr_subtype))
18366 /* Reverse the branch. */
18367 switch ((insn >> 28) & 0xf)
18370 /* bc[0-3][tf]l? instructions can have the condition
18371 reversed by tweaking a single TF bit, and their
18372 opcodes all have 0x4???????. */
18373 gas_assert ((insn & 0xf3e00000) == 0x41000000);
18374 insn ^= 0x00010000;
18378 /* bltz 0x04000000 bgez 0x04010000
18379 bltzal 0x04100000 bgezal 0x04110000 */
18380 gas_assert ((insn & 0xfc0e0000) == 0x04000000);
18381 insn ^= 0x00010000;
18385 /* beq 0x10000000 bne 0x14000000
18386 blez 0x18000000 bgtz 0x1c000000 */
18387 insn ^= 0x04000000;
18395 if (RELAX_BRANCH_LINK (fragp->fr_subtype))
18397 /* Clear the and-link bit. */
18398 gas_assert ((insn & 0xfc1c0000) == 0x04100000);
18400 /* bltzal 0x04100000 bgezal 0x04110000
18401 bltzall 0x04120000 bgezall 0x04130000 */
18402 insn &= ~0x00100000;
18405 /* Branch over the branch (if the branch was likely) or the
18406 full jump (not likely case). Compute the offset from the
18407 current instruction to branch to. */
18408 if (RELAX_BRANCH_LIKELY (fragp->fr_subtype))
18412 /* How many bytes in instructions we've already emitted? */
18413 i = buf - fragp->fr_literal - fragp->fr_fix;
18414 /* How many bytes in instructions from here to the end? */
18415 i = fragp->fr_var - i;
18417 /* Convert to instruction count. */
18419 /* Branch counts from the next instruction. */
18422 /* Branch over the jump. */
18423 buf = write_insn (buf, insn);
18426 buf = write_insn (buf, 0);
18428 if (RELAX_BRANCH_LIKELY (fragp->fr_subtype))
18430 /* beql $0, $0, 2f */
18432 /* Compute the PC offset from the current instruction to
18433 the end of the variable frag. */
18434 /* How many bytes in instructions we've already emitted? */
18435 i = buf - fragp->fr_literal - fragp->fr_fix;
18436 /* How many bytes in instructions from here to the end? */
18437 i = fragp->fr_var - i;
18438 /* Convert to instruction count. */
18440 /* Don't decrement i, because we want to branch over the
18444 buf = write_insn (buf, insn);
18445 buf = write_insn (buf, 0);
18449 if (mips_pic == NO_PIC)
18452 insn = (RELAX_BRANCH_LINK (fragp->fr_subtype)
18453 ? 0x0c000000 : 0x08000000);
18454 exp.X_op = O_symbol;
18455 exp.X_add_symbol = fragp->fr_symbol;
18456 exp.X_add_number = fragp->fr_offset;
18458 fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 4, &exp,
18459 FALSE, BFD_RELOC_MIPS_JMP);
18460 fixp->fx_file = fragp->fr_file;
18461 fixp->fx_line = fragp->fr_line;
18463 buf = write_insn (buf, insn);
18467 unsigned long at = RELAX_BRANCH_AT (fragp->fr_subtype);
18469 /* lw/ld $at, <sym>($gp) R_MIPS_GOT16 */
18470 insn = HAVE_64BIT_ADDRESSES ? 0xdf800000 : 0x8f800000;
18471 insn |= at << OP_SH_RT;
18472 exp.X_op = O_symbol;
18473 exp.X_add_symbol = fragp->fr_symbol;
18474 exp.X_add_number = fragp->fr_offset;
18476 if (fragp->fr_offset)
18478 exp.X_add_symbol = make_expr_symbol (&exp);
18479 exp.X_add_number = 0;
18482 fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 4, &exp,
18483 FALSE, BFD_RELOC_MIPS_GOT16);
18484 fixp->fx_file = fragp->fr_file;
18485 fixp->fx_line = fragp->fr_line;
18487 buf = write_insn (buf, insn);
18489 if (mips_opts.isa == ISA_MIPS1)
18491 buf = write_insn (buf, 0);
18493 /* d/addiu $at, $at, <sym> R_MIPS_LO16 */
18494 insn = HAVE_64BIT_ADDRESSES ? 0x64000000 : 0x24000000;
18495 insn |= at << OP_SH_RS | at << OP_SH_RT;
18497 fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 4, &exp,
18498 FALSE, BFD_RELOC_LO16);
18499 fixp->fx_file = fragp->fr_file;
18500 fixp->fx_line = fragp->fr_line;
18502 buf = write_insn (buf, insn);
18505 if (RELAX_BRANCH_LINK (fragp->fr_subtype))
18509 insn |= at << OP_SH_RS;
18511 buf = write_insn (buf, insn);
18515 fragp->fr_fix += fragp->fr_var;
18516 gas_assert (buf == fragp->fr_literal + fragp->fr_fix);
18520 /* Relax microMIPS branches. */
18521 if (RELAX_MICROMIPS_P (fragp->fr_subtype))
18523 char *buf = fragp->fr_literal + fragp->fr_fix;
18524 bfd_boolean compact = RELAX_MICROMIPS_COMPACT (fragp->fr_subtype);
18525 bfd_boolean al = RELAX_MICROMIPS_LINK (fragp->fr_subtype);
18526 int type = RELAX_MICROMIPS_TYPE (fragp->fr_subtype);
18527 bfd_boolean short_ds;
18528 unsigned long insn;
18532 exp.X_op = O_symbol;
18533 exp.X_add_symbol = fragp->fr_symbol;
18534 exp.X_add_number = fragp->fr_offset;
18536 fragp->fr_fix += fragp->fr_var;
18538 /* Handle 16-bit branches that fit or are forced to fit. */
18539 if (type != 0 && !RELAX_MICROMIPS_TOOFAR16 (fragp->fr_subtype))
18541 /* We generate a fixup instead of applying it right now,
18542 because if there is linker relaxation, we're going to
18543 need the relocations. */
18545 fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 2, &exp, TRUE,
18546 BFD_RELOC_MICROMIPS_10_PCREL_S1);
18547 else if (type == 'E')
18548 fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 2, &exp, TRUE,
18549 BFD_RELOC_MICROMIPS_7_PCREL_S1);
18553 fixp->fx_file = fragp->fr_file;
18554 fixp->fx_line = fragp->fr_line;
18556 /* These relocations can have an addend that won't fit in
18558 fixp->fx_no_overflow = 1;
18563 /* Handle 32-bit branches that fit or are forced to fit. */
18564 if (!RELAX_MICROMIPS_RELAX32 (fragp->fr_subtype)
18565 || !RELAX_MICROMIPS_TOOFAR32 (fragp->fr_subtype))
18567 /* We generate a fixup instead of applying it right now,
18568 because if there is linker relaxation, we're going to
18569 need the relocations. */
18570 fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 4, &exp, TRUE,
18571 BFD_RELOC_MICROMIPS_16_PCREL_S1);
18572 fixp->fx_file = fragp->fr_file;
18573 fixp->fx_line = fragp->fr_line;
18579 /* Relax 16-bit branches to 32-bit branches. */
18582 insn = read_compressed_insn (buf, 2);
18584 if ((insn & 0xfc00) == 0xcc00) /* b16 */
18585 insn = 0x94000000; /* beq */
18586 else if ((insn & 0xdc00) == 0x8c00) /* beqz16/bnez16 */
18588 unsigned long regno;
18590 regno = (insn >> MICROMIPSOP_SH_MD) & MICROMIPSOP_MASK_MD;
18591 regno = micromips_to_32_reg_d_map [regno];
18592 insn = ((insn & 0x2000) << 16) | 0x94000000; /* beq/bne */
18593 insn |= regno << MICROMIPSOP_SH_RS;
18598 /* Nothing else to do, just write it out. */
18599 if (!RELAX_MICROMIPS_RELAX32 (fragp->fr_subtype)
18600 || !RELAX_MICROMIPS_TOOFAR32 (fragp->fr_subtype))
18602 buf = write_compressed_insn (buf, insn, 4);
18603 gas_assert (buf == fragp->fr_literal + fragp->fr_fix);
18608 insn = read_compressed_insn (buf, 4);
18610 /* Relax 32-bit branches to a sequence of instructions. */
18611 as_warn_where (fragp->fr_file, fragp->fr_line,
18612 _("Relaxed out-of-range branch into a jump"));
18614 /* Set the short-delay-slot bit. */
18615 short_ds = al && (insn & 0x02000000) != 0;
18617 if (!RELAX_MICROMIPS_UNCOND (fragp->fr_subtype))
18621 /* Reverse the branch. */
18622 if ((insn & 0xfc000000) == 0x94000000 /* beq */
18623 || (insn & 0xfc000000) == 0xb4000000) /* bne */
18624 insn ^= 0x20000000;
18625 else if ((insn & 0xffe00000) == 0x40000000 /* bltz */
18626 || (insn & 0xffe00000) == 0x40400000 /* bgez */
18627 || (insn & 0xffe00000) == 0x40800000 /* blez */
18628 || (insn & 0xffe00000) == 0x40c00000 /* bgtz */
18629 || (insn & 0xffe00000) == 0x40a00000 /* bnezc */
18630 || (insn & 0xffe00000) == 0x40e00000 /* beqzc */
18631 || (insn & 0xffe00000) == 0x40200000 /* bltzal */
18632 || (insn & 0xffe00000) == 0x40600000 /* bgezal */
18633 || (insn & 0xffe00000) == 0x42200000 /* bltzals */
18634 || (insn & 0xffe00000) == 0x42600000) /* bgezals */
18635 insn ^= 0x00400000;
18636 else if ((insn & 0xffe30000) == 0x43800000 /* bc1f */
18637 || (insn & 0xffe30000) == 0x43a00000 /* bc1t */
18638 || (insn & 0xffe30000) == 0x42800000 /* bc2f */
18639 || (insn & 0xffe30000) == 0x42a00000) /* bc2t */
18640 insn ^= 0x00200000;
18646 /* Clear the and-link and short-delay-slot bits. */
18647 gas_assert ((insn & 0xfda00000) == 0x40200000);
18649 /* bltzal 0x40200000 bgezal 0x40600000 */
18650 /* bltzals 0x42200000 bgezals 0x42600000 */
18651 insn &= ~0x02200000;
18654 /* Make a label at the end for use with the branch. */
18655 l = symbol_new (micromips_label_name (), asec, fragp->fr_fix, fragp);
18656 micromips_label_inc ();
18657 #if defined(OBJ_ELF) || defined(OBJ_MAYBE_ELF)
18659 S_SET_OTHER (l, ELF_ST_SET_MICROMIPS (S_GET_OTHER (l)));
18663 fixp = fix_new (fragp, buf - fragp->fr_literal, 4, l, 0, TRUE,
18664 BFD_RELOC_MICROMIPS_16_PCREL_S1);
18665 fixp->fx_file = fragp->fr_file;
18666 fixp->fx_line = fragp->fr_line;
18668 /* Branch over the jump. */
18669 buf = write_compressed_insn (buf, insn, 4);
18672 buf = write_compressed_insn (buf, 0x0c00, 2);
18675 if (mips_pic == NO_PIC)
18677 unsigned long jal = short_ds ? 0x74000000 : 0xf4000000; /* jal/s */
18679 /* j/jal/jals <sym> R_MICROMIPS_26_S1 */
18680 insn = al ? jal : 0xd4000000;
18682 fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 4, &exp, FALSE,
18683 BFD_RELOC_MICROMIPS_JMP);
18684 fixp->fx_file = fragp->fr_file;
18685 fixp->fx_line = fragp->fr_line;
18687 buf = write_compressed_insn (buf, insn, 4);
18690 buf = write_compressed_insn (buf, 0x0c00, 2);
18694 unsigned long at = RELAX_MICROMIPS_AT (fragp->fr_subtype);
18695 unsigned long jalr = short_ds ? 0x45e0 : 0x45c0; /* jalr/s */
18696 unsigned long jr = compact ? 0x45a0 : 0x4580; /* jr/c */
18698 /* lw/ld $at, <sym>($gp) R_MICROMIPS_GOT16 */
18699 insn = HAVE_64BIT_ADDRESSES ? 0xdc1c0000 : 0xfc1c0000;
18700 insn |= at << MICROMIPSOP_SH_RT;
18702 if (exp.X_add_number)
18704 exp.X_add_symbol = make_expr_symbol (&exp);
18705 exp.X_add_number = 0;
18708 fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 4, &exp, FALSE,
18709 BFD_RELOC_MICROMIPS_GOT16);
18710 fixp->fx_file = fragp->fr_file;
18711 fixp->fx_line = fragp->fr_line;
18713 buf = write_compressed_insn (buf, insn, 4);
18715 /* d/addiu $at, $at, <sym> R_MICROMIPS_LO16 */
18716 insn = HAVE_64BIT_ADDRESSES ? 0x5c000000 : 0x30000000;
18717 insn |= at << MICROMIPSOP_SH_RT | at << MICROMIPSOP_SH_RS;
18719 fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 4, &exp, FALSE,
18720 BFD_RELOC_MICROMIPS_LO16);
18721 fixp->fx_file = fragp->fr_file;
18722 fixp->fx_line = fragp->fr_line;
18724 buf = write_compressed_insn (buf, insn, 4);
18726 /* jr/jrc/jalr/jalrs $at */
18727 insn = al ? jalr : jr;
18728 insn |= at << MICROMIPSOP_SH_MJ;
18730 buf = write_compressed_insn (buf, insn, 2);
18733 gas_assert (buf == fragp->fr_literal + fragp->fr_fix);
18737 if (RELAX_MIPS16_P (fragp->fr_subtype))
18740 const struct mips16_immed_operand *op;
18743 unsigned int user_length, length;
18744 unsigned long insn;
18747 type = RELAX_MIPS16_TYPE (fragp->fr_subtype);
18748 op = mips16_immed_operands;
18749 while (op->type != type)
18752 ext = RELAX_MIPS16_EXTENDED (fragp->fr_subtype);
18753 val = resolve_symbol_value (fragp->fr_symbol);
18758 addr = fragp->fr_address + fragp->fr_fix;
18760 /* The rules for the base address of a PC relative reloc are
18761 complicated; see mips16_extended_frag. */
18762 if (type == 'p' || type == 'q')
18767 /* Ignore the low bit in the target, since it will be
18768 set for a text label. */
18769 if ((val & 1) != 0)
18772 else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype))
18774 else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype))
18777 addr &= ~ (addressT) ((1 << op->shift) - 1);
18780 /* Make sure the section winds up with the alignment we have
18783 record_alignment (asec, op->shift);
18787 && (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype)
18788 || RELAX_MIPS16_DSLOT (fragp->fr_subtype)))
18789 as_warn_where (fragp->fr_file, fragp->fr_line,
18790 _("extended instruction in delay slot"));
18792 buf = fragp->fr_literal + fragp->fr_fix;
18794 insn = read_compressed_insn (buf, 2);
18796 insn |= MIPS16_EXTEND;
18798 if (RELAX_MIPS16_USER_EXT (fragp->fr_subtype))
18800 else if (RELAX_MIPS16_USER_SMALL (fragp->fr_subtype))
18805 mips16_immed (fragp->fr_file, fragp->fr_line, type,
18806 BFD_RELOC_UNUSED, val, user_length, &insn);
18808 length = (ext ? 4 : 2);
18809 gas_assert (mips16_opcode_length (insn) == length);
18810 write_compressed_insn (buf, insn, length);
18811 fragp->fr_fix += length;
18815 relax_substateT subtype = fragp->fr_subtype;
18816 bfd_boolean second_longer = (subtype & RELAX_SECOND_LONGER) != 0;
18817 bfd_boolean use_second = (subtype & RELAX_USE_SECOND) != 0;
18821 first = RELAX_FIRST (subtype);
18822 second = RELAX_SECOND (subtype);
18823 fixp = (fixS *) fragp->fr_opcode;
18825 /* If the delay slot chosen does not match the size of the instruction,
18826 then emit a warning. */
18827 if ((!use_second && (subtype & RELAX_DELAY_SLOT_SIZE_FIRST) != 0)
18828 || (use_second && (subtype & RELAX_DELAY_SLOT_SIZE_SECOND) != 0))
18833 s = subtype & (RELAX_DELAY_SLOT_16BIT
18834 | RELAX_DELAY_SLOT_SIZE_FIRST
18835 | RELAX_DELAY_SLOT_SIZE_SECOND);
18836 msg = macro_warning (s);
18838 as_warn_where (fragp->fr_file, fragp->fr_line, "%s", msg);
18842 /* Possibly emit a warning if we've chosen the longer option. */
18843 if (use_second == second_longer)
18849 & (RELAX_SECOND_LONGER | RELAX_NOMACRO | RELAX_DELAY_SLOT));
18850 msg = macro_warning (s);
18852 as_warn_where (fragp->fr_file, fragp->fr_line, "%s", msg);
18856 /* Go through all the fixups for the first sequence. Disable them
18857 (by marking them as done) if we're going to use the second
18858 sequence instead. */
18860 && fixp->fx_frag == fragp
18861 && fixp->fx_where < fragp->fr_fix - second)
18863 if (subtype & RELAX_USE_SECOND)
18865 fixp = fixp->fx_next;
18868 /* Go through the fixups for the second sequence. Disable them if
18869 we're going to use the first sequence, otherwise adjust their
18870 addresses to account for the relaxation. */
18871 while (fixp && fixp->fx_frag == fragp)
18873 if (subtype & RELAX_USE_SECOND)
18874 fixp->fx_where -= first;
18877 fixp = fixp->fx_next;
18880 /* Now modify the frag contents. */
18881 if (subtype & RELAX_USE_SECOND)
18885 start = fragp->fr_literal + fragp->fr_fix - first - second;
18886 memmove (start, start + first, second);
18887 fragp->fr_fix -= first;
18890 fragp->fr_fix -= second;
18896 /* This function is called after the relocs have been generated.
18897 We've been storing mips16 text labels as odd. Here we convert them
18898 back to even for the convenience of the debugger. */
18901 mips_frob_file_after_relocs (void)
18904 unsigned int count, i;
18909 syms = bfd_get_outsymbols (stdoutput);
18910 count = bfd_get_symcount (stdoutput);
18911 for (i = 0; i < count; i++, syms++)
18912 if (ELF_ST_IS_COMPRESSED (elf_symbol (*syms)->internal_elf_sym.st_other)
18913 && ((*syms)->value & 1) != 0)
18915 (*syms)->value &= ~1;
18916 /* If the symbol has an odd size, it was probably computed
18917 incorrectly, so adjust that as well. */
18918 if ((elf_symbol (*syms)->internal_elf_sym.st_size & 1) != 0)
18919 ++elf_symbol (*syms)->internal_elf_sym.st_size;
18925 /* This function is called whenever a label is defined, including fake
18926 labels instantiated off the dot special symbol. It is used when
18927 handling branch delays; if a branch has a label, we assume we cannot
18928 move it. This also bumps the value of the symbol by 1 in compressed
18932 mips_record_label (symbolS *sym)
18934 segment_info_type *si = seg_info (now_seg);
18935 struct insn_label_list *l;
18937 if (free_insn_labels == NULL)
18938 l = (struct insn_label_list *) xmalloc (sizeof *l);
18941 l = free_insn_labels;
18942 free_insn_labels = l->next;
18946 l->next = si->label_list;
18947 si->label_list = l;
18950 /* This function is called as tc_frob_label() whenever a label is defined
18951 and adds a DWARF-2 record we only want for true labels. */
18954 mips_define_label (symbolS *sym)
18956 mips_record_label (sym);
18958 dwarf2_emit_label (sym);
18962 /* This function is called by tc_new_dot_label whenever a new dot symbol
18966 mips_add_dot_label (symbolS *sym)
18968 mips_record_label (sym);
18969 if (mips_assembling_insn && HAVE_CODE_COMPRESSION)
18970 mips_compressed_mark_label (sym);
18973 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
18975 /* Some special processing for a MIPS ELF file. */
18978 mips_elf_final_processing (void)
18980 /* Write out the register information. */
18981 if (mips_abi != N64_ABI)
18985 s.ri_gprmask = mips_gprmask;
18986 s.ri_cprmask[0] = mips_cprmask[0];
18987 s.ri_cprmask[1] = mips_cprmask[1];
18988 s.ri_cprmask[2] = mips_cprmask[2];
18989 s.ri_cprmask[3] = mips_cprmask[3];
18990 /* The gp_value field is set by the MIPS ELF backend. */
18992 bfd_mips_elf32_swap_reginfo_out (stdoutput, &s,
18993 ((Elf32_External_RegInfo *)
18994 mips_regmask_frag));
18998 Elf64_Internal_RegInfo s;
19000 s.ri_gprmask = mips_gprmask;
19002 s.ri_cprmask[0] = mips_cprmask[0];
19003 s.ri_cprmask[1] = mips_cprmask[1];
19004 s.ri_cprmask[2] = mips_cprmask[2];
19005 s.ri_cprmask[3] = mips_cprmask[3];
19006 /* The gp_value field is set by the MIPS ELF backend. */
19008 bfd_mips_elf64_swap_reginfo_out (stdoutput, &s,
19009 ((Elf64_External_RegInfo *)
19010 mips_regmask_frag));
19013 /* Set the MIPS ELF flag bits. FIXME: There should probably be some
19014 sort of BFD interface for this. */
19015 if (mips_any_noreorder)
19016 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_NOREORDER;
19017 if (mips_pic != NO_PIC)
19019 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_PIC;
19020 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_CPIC;
19023 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_CPIC;
19025 /* Set MIPS ELF flags for ASEs. Note that not all ASEs have flags
19026 defined at present; this might need to change in future. */
19027 if (file_ase_mips16)
19028 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ARCH_ASE_M16;
19029 if (file_ase_micromips)
19030 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ARCH_ASE_MICROMIPS;
19031 #if 0 /* XXX FIXME */
19032 if (file_ase_mips3d)
19033 elf_elfheader (stdoutput)->e_flags |= ???;
19036 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ARCH_ASE_MDMX;
19038 /* Set the MIPS ELF ABI flags. */
19039 if (mips_abi == O32_ABI && USE_E_MIPS_ABI_O32)
19040 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O32;
19041 else if (mips_abi == O64_ABI)
19042 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O64;
19043 else if (mips_abi == EABI_ABI)
19045 if (!file_mips_gp32)
19046 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI64;
19048 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI32;
19050 else if (mips_abi == N32_ABI)
19051 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ABI2;
19053 /* Nothing to do for N64_ABI. */
19055 if (mips_32bitmode)
19056 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_32BITMODE;
19058 #if 0 /* XXX FIXME */
19059 /* 32 bit code with 64 bit FP registers. */
19060 if (!file_mips_fp32 && ABI_NEEDS_32BIT_REGS (mips_abi))
19061 elf_elfheader (stdoutput)->e_flags |= ???;
19065 #endif /* OBJ_ELF || OBJ_MAYBE_ELF */
19067 typedef struct proc {
19069 symbolS *func_end_sym;
19070 unsigned long reg_mask;
19071 unsigned long reg_offset;
19072 unsigned long fpreg_mask;
19073 unsigned long fpreg_offset;
19074 unsigned long frame_offset;
19075 unsigned long frame_reg;
19076 unsigned long pc_reg;
19079 static procS cur_proc;
19080 static procS *cur_proc_ptr;
19081 static int numprocs;
19083 /* Implement NOP_OPCODE. We encode a MIPS16 nop as "1", a microMIPS nop
19084 as "2", and a normal nop as "0". */
19086 #define NOP_OPCODE_MIPS 0
19087 #define NOP_OPCODE_MIPS16 1
19088 #define NOP_OPCODE_MICROMIPS 2
19091 mips_nop_opcode (void)
19093 if (seg_info (now_seg)->tc_segment_info_data.micromips)
19094 return NOP_OPCODE_MICROMIPS;
19095 else if (seg_info (now_seg)->tc_segment_info_data.mips16)
19096 return NOP_OPCODE_MIPS16;
19098 return NOP_OPCODE_MIPS;
19101 /* Fill in an rs_align_code fragment. Unlike elsewhere we want to use
19102 32-bit microMIPS NOPs here (if applicable). */
19105 mips_handle_align (fragS *fragp)
19109 int bytes, size, excess;
19112 if (fragp->fr_type != rs_align_code)
19115 p = fragp->fr_literal + fragp->fr_fix;
19117 switch (nop_opcode)
19119 case NOP_OPCODE_MICROMIPS:
19120 opcode = micromips_nop32_insn.insn_opcode;
19123 case NOP_OPCODE_MIPS16:
19124 opcode = mips16_nop_insn.insn_opcode;
19127 case NOP_OPCODE_MIPS:
19129 opcode = nop_insn.insn_opcode;
19134 bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
19135 excess = bytes % size;
19137 /* Handle the leading part if we're not inserting a whole number of
19138 instructions, and make it the end of the fixed part of the frag.
19139 Try to fit in a short microMIPS NOP if applicable and possible,
19140 and use zeroes otherwise. */
19141 gas_assert (excess < 4);
19142 fragp->fr_fix += excess;
19147 /* Fall through. */
19149 if (nop_opcode == NOP_OPCODE_MICROMIPS)
19151 p = write_compressed_insn (p, micromips_nop16_insn.insn_opcode, 2);
19155 /* Fall through. */
19158 /* Fall through. */
19163 md_number_to_chars (p, opcode, size);
19164 fragp->fr_var = size;
19168 md_obj_begin (void)
19175 /* Check for premature end, nesting errors, etc. */
19177 as_warn (_("missing .end at end of assembly"));
19186 if (*input_line_pointer == '-')
19188 ++input_line_pointer;
19191 if (!ISDIGIT (*input_line_pointer))
19192 as_bad (_("expected simple number"));
19193 if (input_line_pointer[0] == '0')
19195 if (input_line_pointer[1] == 'x')
19197 input_line_pointer += 2;
19198 while (ISXDIGIT (*input_line_pointer))
19201 val |= hex_value (*input_line_pointer++);
19203 return negative ? -val : val;
19207 ++input_line_pointer;
19208 while (ISDIGIT (*input_line_pointer))
19211 val |= *input_line_pointer++ - '0';
19213 return negative ? -val : val;
19216 if (!ISDIGIT (*input_line_pointer))
19218 printf (_(" *input_line_pointer == '%c' 0x%02x\n"),
19219 *input_line_pointer, *input_line_pointer);
19220 as_warn (_("invalid number"));
19223 while (ISDIGIT (*input_line_pointer))
19226 val += *input_line_pointer++ - '0';
19228 return negative ? -val : val;
19231 /* The .file directive; just like the usual .file directive, but there
19232 is an initial number which is the ECOFF file index. In the non-ECOFF
19233 case .file implies DWARF-2. */
19236 s_mips_file (int x ATTRIBUTE_UNUSED)
19238 static int first_file_directive = 0;
19240 if (ECOFF_DEBUGGING)
19249 filename = dwarf2_directive_file (0);
19251 /* Versions of GCC up to 3.1 start files with a ".file"
19252 directive even for stabs output. Make sure that this
19253 ".file" is handled. Note that you need a version of GCC
19254 after 3.1 in order to support DWARF-2 on MIPS. */
19255 if (filename != NULL && ! first_file_directive)
19257 (void) new_logical_line (filename, -1);
19258 s_app_file_string (filename, 0);
19260 first_file_directive = 1;
19264 /* The .loc directive, implying DWARF-2. */
19267 s_mips_loc (int x ATTRIBUTE_UNUSED)
19269 if (!ECOFF_DEBUGGING)
19270 dwarf2_directive_loc (0);
19273 /* The .end directive. */
19276 s_mips_end (int x ATTRIBUTE_UNUSED)
19280 /* Following functions need their own .frame and .cprestore directives. */
19281 mips_frame_reg_valid = 0;
19282 mips_cprestore_valid = 0;
19284 if (!is_end_of_line[(unsigned char) *input_line_pointer])
19287 demand_empty_rest_of_line ();
19292 if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) == 0)
19293 as_warn (_(".end not in text section"));
19297 as_warn (_(".end directive without a preceding .ent directive."));
19298 demand_empty_rest_of_line ();
19304 gas_assert (S_GET_NAME (p));
19305 if (strcmp (S_GET_NAME (p), S_GET_NAME (cur_proc_ptr->func_sym)))
19306 as_warn (_(".end symbol does not match .ent symbol."));
19308 if (debug_type == DEBUG_STABS)
19309 stabs_generate_asm_endfunc (S_GET_NAME (p),
19313 as_warn (_(".end directive missing or unknown symbol"));
19316 /* Create an expression to calculate the size of the function. */
19317 if (p && cur_proc_ptr)
19319 OBJ_SYMFIELD_TYPE *obj = symbol_get_obj (p);
19320 expressionS *exp = xmalloc (sizeof (expressionS));
19323 exp->X_op = O_subtract;
19324 exp->X_add_symbol = symbol_temp_new_now ();
19325 exp->X_op_symbol = p;
19326 exp->X_add_number = 0;
19328 cur_proc_ptr->func_end_sym = exp->X_add_symbol;
19331 /* Generate a .pdr section. */
19332 if (IS_ELF && !ECOFF_DEBUGGING && mips_flag_pdr)
19334 segT saved_seg = now_seg;
19335 subsegT saved_subseg = now_subseg;
19339 #ifdef md_flush_pending_output
19340 md_flush_pending_output ();
19343 gas_assert (pdr_seg);
19344 subseg_set (pdr_seg, 0);
19346 /* Write the symbol. */
19347 exp.X_op = O_symbol;
19348 exp.X_add_symbol = p;
19349 exp.X_add_number = 0;
19350 emit_expr (&exp, 4);
19352 fragp = frag_more (7 * 4);
19354 md_number_to_chars (fragp, cur_proc_ptr->reg_mask, 4);
19355 md_number_to_chars (fragp + 4, cur_proc_ptr->reg_offset, 4);
19356 md_number_to_chars (fragp + 8, cur_proc_ptr->fpreg_mask, 4);
19357 md_number_to_chars (fragp + 12, cur_proc_ptr->fpreg_offset, 4);
19358 md_number_to_chars (fragp + 16, cur_proc_ptr->frame_offset, 4);
19359 md_number_to_chars (fragp + 20, cur_proc_ptr->frame_reg, 4);
19360 md_number_to_chars (fragp + 24, cur_proc_ptr->pc_reg, 4);
19362 subseg_set (saved_seg, saved_subseg);
19364 #endif /* OBJ_ELF */
19366 cur_proc_ptr = NULL;
19369 /* The .aent and .ent directives. */
19372 s_mips_ent (int aent)
19376 symbolP = get_symbol ();
19377 if (*input_line_pointer == ',')
19378 ++input_line_pointer;
19379 SKIP_WHITESPACE ();
19380 if (ISDIGIT (*input_line_pointer)
19381 || *input_line_pointer == '-')
19384 if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) == 0)
19385 as_warn (_(".ent or .aent not in text section."));
19387 if (!aent && cur_proc_ptr)
19388 as_warn (_("missing .end"));
19392 /* This function needs its own .frame and .cprestore directives. */
19393 mips_frame_reg_valid = 0;
19394 mips_cprestore_valid = 0;
19396 cur_proc_ptr = &cur_proc;
19397 memset (cur_proc_ptr, '\0', sizeof (procS));
19399 cur_proc_ptr->func_sym = symbolP;
19403 if (debug_type == DEBUG_STABS)
19404 stabs_generate_asm_func (S_GET_NAME (symbolP),
19405 S_GET_NAME (symbolP));
19408 symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION;
19410 demand_empty_rest_of_line ();
19413 /* The .frame directive. If the mdebug section is present (IRIX 5 native)
19414 then ecoff.c (ecoff_directive_frame) is used. For embedded targets,
19415 s_mips_frame is used so that we can set the PDR information correctly.
19416 We can't use the ecoff routines because they make reference to the ecoff
19417 symbol table (in the mdebug section). */
19420 s_mips_frame (int ignore ATTRIBUTE_UNUSED)
19423 if (IS_ELF && !ECOFF_DEBUGGING)
19427 if (cur_proc_ptr == (procS *) NULL)
19429 as_warn (_(".frame outside of .ent"));
19430 demand_empty_rest_of_line ();
19434 cur_proc_ptr->frame_reg = tc_get_register (1);
19436 SKIP_WHITESPACE ();
19437 if (*input_line_pointer++ != ','
19438 || get_absolute_expression_and_terminator (&val) != ',')
19440 as_warn (_("Bad .frame directive"));
19441 --input_line_pointer;
19442 demand_empty_rest_of_line ();
19446 cur_proc_ptr->frame_offset = val;
19447 cur_proc_ptr->pc_reg = tc_get_register (0);
19449 demand_empty_rest_of_line ();
19452 #endif /* OBJ_ELF */
19456 /* The .fmask and .mask directives. If the mdebug section is present
19457 (IRIX 5 native) then ecoff.c (ecoff_directive_mask) is used. For
19458 embedded targets, s_mips_mask is used so that we can set the PDR
19459 information correctly. We can't use the ecoff routines because they
19460 make reference to the ecoff symbol table (in the mdebug section). */
19463 s_mips_mask (int reg_type)
19466 if (IS_ELF && !ECOFF_DEBUGGING)
19470 if (cur_proc_ptr == (procS *) NULL)
19472 as_warn (_(".mask/.fmask outside of .ent"));
19473 demand_empty_rest_of_line ();
19477 if (get_absolute_expression_and_terminator (&mask) != ',')
19479 as_warn (_("Bad .mask/.fmask directive"));
19480 --input_line_pointer;
19481 demand_empty_rest_of_line ();
19485 off = get_absolute_expression ();
19487 if (reg_type == 'F')
19489 cur_proc_ptr->fpreg_mask = mask;
19490 cur_proc_ptr->fpreg_offset = off;
19494 cur_proc_ptr->reg_mask = mask;
19495 cur_proc_ptr->reg_offset = off;
19498 demand_empty_rest_of_line ();
19501 #endif /* OBJ_ELF */
19502 s_ignore (reg_type);
19505 /* A table describing all the processors gas knows about. Names are
19506 matched in the order listed.
19508 To ease comparison, please keep this table in the same order as
19509 gcc's mips_cpu_info_table[]. */
19510 static const struct mips_cpu_info mips_cpu_info_table[] =
19512 /* Entries for generic ISAs */
19513 { "mips1", MIPS_CPU_IS_ISA, 0, ISA_MIPS1, CPU_R3000 },
19514 { "mips2", MIPS_CPU_IS_ISA, 0, ISA_MIPS2, CPU_R6000 },
19515 { "mips3", MIPS_CPU_IS_ISA, 0, ISA_MIPS3, CPU_R4000 },
19516 { "mips4", MIPS_CPU_IS_ISA, 0, ISA_MIPS4, CPU_R8000 },
19517 { "mips5", MIPS_CPU_IS_ISA, 0, ISA_MIPS5, CPU_MIPS5 },
19518 { "mips32", MIPS_CPU_IS_ISA, 0, ISA_MIPS32, CPU_MIPS32 },
19519 { "mips32r2", MIPS_CPU_IS_ISA, 0, ISA_MIPS32R2, CPU_MIPS32R2 },
19520 { "mips64", MIPS_CPU_IS_ISA, 0, ISA_MIPS64, CPU_MIPS64 },
19521 { "mips64r2", MIPS_CPU_IS_ISA, 0, ISA_MIPS64R2, CPU_MIPS64R2 },
19524 { "r3000", 0, 0, ISA_MIPS1, CPU_R3000 },
19525 { "r2000", 0, 0, ISA_MIPS1, CPU_R3000 },
19526 { "r3900", 0, 0, ISA_MIPS1, CPU_R3900 },
19529 { "r6000", 0, 0, ISA_MIPS2, CPU_R6000 },
19532 { "r4000", 0, 0, ISA_MIPS3, CPU_R4000 },
19533 { "r4010", 0, 0, ISA_MIPS2, CPU_R4010 },
19534 { "vr4100", 0, 0, ISA_MIPS3, CPU_VR4100 },
19535 { "vr4111", 0, 0, ISA_MIPS3, CPU_R4111 },
19536 { "vr4120", 0, 0, ISA_MIPS3, CPU_VR4120 },
19537 { "vr4130", 0, 0, ISA_MIPS3, CPU_VR4120 },
19538 { "vr4181", 0, 0, ISA_MIPS3, CPU_R4111 },
19539 { "vr4300", 0, 0, ISA_MIPS3, CPU_R4300 },
19540 { "r4400", 0, 0, ISA_MIPS3, CPU_R4400 },
19541 { "r4600", 0, 0, ISA_MIPS3, CPU_R4600 },
19542 { "orion", 0, 0, ISA_MIPS3, CPU_R4600 },
19543 { "r4650", 0, 0, ISA_MIPS3, CPU_R4650 },
19544 { "r5900", 0, 0, ISA_MIPS3, CPU_R5900 },
19545 /* ST Microelectronics Loongson 2E and 2F cores */
19546 { "loongson2e", 0, 0, ISA_MIPS3, CPU_LOONGSON_2E },
19547 { "loongson2f", 0, 0, ISA_MIPS3, CPU_LOONGSON_2F },
19550 { "r8000", 0, 0, ISA_MIPS4, CPU_R8000 },
19551 { "r10000", 0, 0, ISA_MIPS4, CPU_R10000 },
19552 { "r12000", 0, 0, ISA_MIPS4, CPU_R12000 },
19553 { "r14000", 0, 0, ISA_MIPS4, CPU_R14000 },
19554 { "r16000", 0, 0, ISA_MIPS4, CPU_R16000 },
19555 { "vr5000", 0, 0, ISA_MIPS4, CPU_R5000 },
19556 { "vr5400", 0, 0, ISA_MIPS4, CPU_VR5400 },
19557 { "vr5500", 0, 0, ISA_MIPS4, CPU_VR5500 },
19558 { "rm5200", 0, 0, ISA_MIPS4, CPU_R5000 },
19559 { "rm5230", 0, 0, ISA_MIPS4, CPU_R5000 },
19560 { "rm5231", 0, 0, ISA_MIPS4, CPU_R5000 },
19561 { "rm5261", 0, 0, ISA_MIPS4, CPU_R5000 },
19562 { "rm5721", 0, 0, ISA_MIPS4, CPU_R5000 },
19563 { "rm7000", 0, 0, ISA_MIPS4, CPU_RM7000 },
19564 { "rm9000", 0, 0, ISA_MIPS4, CPU_RM9000 },
19567 { "4kc", 0, 0, ISA_MIPS32, CPU_MIPS32 },
19568 { "4km", 0, 0, ISA_MIPS32, CPU_MIPS32 },
19569 { "4kp", 0, 0, ISA_MIPS32, CPU_MIPS32 },
19570 { "4ksc", 0, ASE_SMARTMIPS, ISA_MIPS32, CPU_MIPS32 },
19572 /* MIPS 32 Release 2 */
19573 { "4kec", 0, 0, ISA_MIPS32R2, CPU_MIPS32R2 },
19574 { "4kem", 0, 0, ISA_MIPS32R2, CPU_MIPS32R2 },
19575 { "4kep", 0, 0, ISA_MIPS32R2, CPU_MIPS32R2 },
19576 { "4ksd", 0, ASE_SMARTMIPS, ISA_MIPS32R2, CPU_MIPS32R2 },
19577 { "m4k", 0, 0, ISA_MIPS32R2, CPU_MIPS32R2 },
19578 { "m4kp", 0, 0, ISA_MIPS32R2, CPU_MIPS32R2 },
19579 { "m14k", 0, ASE_MCU, ISA_MIPS32R2, CPU_MIPS32R2 },
19580 { "m14kc", 0, ASE_MCU, ISA_MIPS32R2, CPU_MIPS32R2 },
19581 { "m14ke", 0, ASE_DSP | ASE_DSPR2 | ASE_MCU,
19582 ISA_MIPS32R2, CPU_MIPS32R2 },
19583 { "m14kec", 0, ASE_DSP | ASE_DSPR2 | ASE_MCU,
19584 ISA_MIPS32R2, CPU_MIPS32R2 },
19585 { "24kc", 0, 0, ISA_MIPS32R2, CPU_MIPS32R2 },
19586 { "24kf2_1", 0, 0, ISA_MIPS32R2, CPU_MIPS32R2 },
19587 { "24kf", 0, 0, ISA_MIPS32R2, CPU_MIPS32R2 },
19588 { "24kf1_1", 0, 0, ISA_MIPS32R2, CPU_MIPS32R2 },
19589 /* Deprecated forms of the above. */
19590 { "24kfx", 0, 0, ISA_MIPS32R2, CPU_MIPS32R2 },
19591 { "24kx", 0, 0, ISA_MIPS32R2, CPU_MIPS32R2 },
19592 /* 24KE is a 24K with DSP ASE, other ASEs are optional. */
19593 { "24kec", 0, ASE_DSP, ISA_MIPS32R2, CPU_MIPS32R2 },
19594 { "24kef2_1", 0, ASE_DSP, ISA_MIPS32R2, CPU_MIPS32R2 },
19595 { "24kef", 0, ASE_DSP, ISA_MIPS32R2, CPU_MIPS32R2 },
19596 { "24kef1_1", 0, ASE_DSP, ISA_MIPS32R2, CPU_MIPS32R2 },
19597 /* Deprecated forms of the above. */
19598 { "24kefx", 0, ASE_DSP, ISA_MIPS32R2, CPU_MIPS32R2 },
19599 { "24kex", 0, ASE_DSP, ISA_MIPS32R2, CPU_MIPS32R2 },
19600 /* 34K is a 24K with DSP and MT ASE, other ASEs are optional. */
19601 { "34kc", 0, ASE_DSP | ASE_MT, ISA_MIPS32R2, CPU_MIPS32R2 },
19602 { "34kf2_1", 0, ASE_DSP | ASE_MT, ISA_MIPS32R2, CPU_MIPS32R2 },
19603 { "34kf", 0, ASE_DSP | ASE_MT, ISA_MIPS32R2, CPU_MIPS32R2 },
19604 { "34kf1_1", 0, ASE_DSP | ASE_MT, ISA_MIPS32R2, CPU_MIPS32R2 },
19605 /* Deprecated forms of the above. */
19606 { "34kfx", 0, ASE_DSP | ASE_MT, ISA_MIPS32R2, CPU_MIPS32R2 },
19607 { "34kx", 0, ASE_DSP | ASE_MT, ISA_MIPS32R2, CPU_MIPS32R2 },
19608 /* 34Kn is a 34kc without DSP. */
19609 { "34kn", 0, ASE_MT, ISA_MIPS32R2, CPU_MIPS32R2 },
19610 /* 74K with DSP and DSPR2 ASE, other ASEs are optional. */
19611 { "74kc", 0, ASE_DSP | ASE_DSPR2, ISA_MIPS32R2, CPU_MIPS32R2 },
19612 { "74kf2_1", 0, ASE_DSP | ASE_DSPR2, ISA_MIPS32R2, CPU_MIPS32R2 },
19613 { "74kf", 0, ASE_DSP | ASE_DSPR2, ISA_MIPS32R2, CPU_MIPS32R2 },
19614 { "74kf1_1", 0, ASE_DSP | ASE_DSPR2, ISA_MIPS32R2, CPU_MIPS32R2 },
19615 { "74kf3_2", 0, ASE_DSP | ASE_DSPR2, ISA_MIPS32R2, CPU_MIPS32R2 },
19616 /* Deprecated forms of the above. */
19617 { "74kfx", 0, ASE_DSP | ASE_DSPR2, ISA_MIPS32R2, CPU_MIPS32R2 },
19618 { "74kx", 0, ASE_DSP | ASE_DSPR2, ISA_MIPS32R2, CPU_MIPS32R2 },
19619 /* 1004K cores are multiprocessor versions of the 34K. */
19620 { "1004kc", 0, ASE_DSP | ASE_MT, ISA_MIPS32R2, CPU_MIPS32R2 },
19621 { "1004kf2_1", 0, ASE_DSP | ASE_MT, ISA_MIPS32R2, CPU_MIPS32R2 },
19622 { "1004kf", 0, ASE_DSP | ASE_MT, ISA_MIPS32R2, CPU_MIPS32R2 },
19623 { "1004kf1_1", 0, ASE_DSP | ASE_MT, ISA_MIPS32R2, CPU_MIPS32R2 },
19626 { "5kc", 0, 0, ISA_MIPS64, CPU_MIPS64 },
19627 { "5kf", 0, 0, ISA_MIPS64, CPU_MIPS64 },
19628 { "20kc", 0, ASE_MIPS3D, ISA_MIPS64, CPU_MIPS64 },
19629 { "25kf", 0, ASE_MIPS3D, ISA_MIPS64, CPU_MIPS64 },
19631 /* Broadcom SB-1 CPU core */
19632 { "sb1", 0, ASE_MIPS3D | ASE_MDMX, ISA_MIPS64, CPU_SB1 },
19633 /* Broadcom SB-1A CPU core */
19634 { "sb1a", 0, ASE_MIPS3D | ASE_MDMX, ISA_MIPS64, CPU_SB1 },
19636 { "loongson3a", 0, 0, ISA_MIPS64, CPU_LOONGSON_3A },
19638 /* MIPS 64 Release 2 */
19640 /* Cavium Networks Octeon CPU core */
19641 { "octeon", 0, 0, ISA_MIPS64R2, CPU_OCTEON },
19642 { "octeon+", 0, 0, ISA_MIPS64R2, CPU_OCTEONP },
19643 { "octeon2", 0, 0, ISA_MIPS64R2, CPU_OCTEON2 },
19646 { "xlr", 0, 0, ISA_MIPS64, CPU_XLR },
19649 XLP is mostly like XLR, with the prominent exception that it is
19650 MIPS64R2 rather than MIPS64. */
19651 { "xlp", 0, 0, ISA_MIPS64R2, CPU_XLR },
19654 { NULL, 0, 0, 0, 0 }
19658 /* Return true if GIVEN is the same as CANONICAL, or if it is CANONICAL
19659 with a final "000" replaced by "k". Ignore case.
19661 Note: this function is shared between GCC and GAS. */
19664 mips_strict_matching_cpu_name_p (const char *canonical, const char *given)
19666 while (*given != 0 && TOLOWER (*given) == TOLOWER (*canonical))
19667 given++, canonical++;
19669 return ((*given == 0 && *canonical == 0)
19670 || (strcmp (canonical, "000") == 0 && strcasecmp (given, "k") == 0));
19674 /* Return true if GIVEN matches CANONICAL, where GIVEN is a user-supplied
19675 CPU name. We've traditionally allowed a lot of variation here.
19677 Note: this function is shared between GCC and GAS. */
19680 mips_matching_cpu_name_p (const char *canonical, const char *given)
19682 /* First see if the name matches exactly, or with a final "000"
19683 turned into "k". */
19684 if (mips_strict_matching_cpu_name_p (canonical, given))
19687 /* If not, try comparing based on numerical designation alone.
19688 See if GIVEN is an unadorned number, or 'r' followed by a number. */
19689 if (TOLOWER (*given) == 'r')
19691 if (!ISDIGIT (*given))
19694 /* Skip over some well-known prefixes in the canonical name,
19695 hoping to find a number there too. */
19696 if (TOLOWER (canonical[0]) == 'v' && TOLOWER (canonical[1]) == 'r')
19698 else if (TOLOWER (canonical[0]) == 'r' && TOLOWER (canonical[1]) == 'm')
19700 else if (TOLOWER (canonical[0]) == 'r')
19703 return mips_strict_matching_cpu_name_p (canonical, given);
19707 /* Parse an option that takes the name of a processor as its argument.
19708 OPTION is the name of the option and CPU_STRING is the argument.
19709 Return the corresponding processor enumeration if the CPU_STRING is
19710 recognized, otherwise report an error and return null.
19712 A similar function exists in GCC. */
19714 static const struct mips_cpu_info *
19715 mips_parse_cpu (const char *option, const char *cpu_string)
19717 const struct mips_cpu_info *p;
19719 /* 'from-abi' selects the most compatible architecture for the given
19720 ABI: MIPS I for 32-bit ABIs and MIPS III for 64-bit ABIs. For the
19721 EABIs, we have to decide whether we're using the 32-bit or 64-bit
19722 version. Look first at the -mgp options, if given, otherwise base
19723 the choice on MIPS_DEFAULT_64BIT.
19725 Treat NO_ABI like the EABIs. One reason to do this is that the
19726 plain 'mips' and 'mips64' configs have 'from-abi' as their default
19727 architecture. This code picks MIPS I for 'mips' and MIPS III for
19728 'mips64', just as we did in the days before 'from-abi'. */
19729 if (strcasecmp (cpu_string, "from-abi") == 0)
19731 if (ABI_NEEDS_32BIT_REGS (mips_abi))
19732 return mips_cpu_info_from_isa (ISA_MIPS1);
19734 if (ABI_NEEDS_64BIT_REGS (mips_abi))
19735 return mips_cpu_info_from_isa (ISA_MIPS3);
19737 if (file_mips_gp32 >= 0)
19738 return mips_cpu_info_from_isa (file_mips_gp32 ? ISA_MIPS1 : ISA_MIPS3);
19740 return mips_cpu_info_from_isa (MIPS_DEFAULT_64BIT
19745 /* 'default' has traditionally been a no-op. Probably not very useful. */
19746 if (strcasecmp (cpu_string, "default") == 0)
19749 for (p = mips_cpu_info_table; p->name != 0; p++)
19750 if (mips_matching_cpu_name_p (p->name, cpu_string))
19753 as_bad (_("Bad value (%s) for %s"), cpu_string, option);
19757 /* Return the canonical processor information for ISA (a member of the
19758 ISA_MIPS* enumeration). */
19760 static const struct mips_cpu_info *
19761 mips_cpu_info_from_isa (int isa)
19765 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
19766 if ((mips_cpu_info_table[i].flags & MIPS_CPU_IS_ISA)
19767 && isa == mips_cpu_info_table[i].isa)
19768 return (&mips_cpu_info_table[i]);
19773 static const struct mips_cpu_info *
19774 mips_cpu_info_from_arch (int arch)
19778 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
19779 if (arch == mips_cpu_info_table[i].cpu)
19780 return (&mips_cpu_info_table[i]);
19786 show (FILE *stream, const char *string, int *col_p, int *first_p)
19790 fprintf (stream, "%24s", "");
19795 fprintf (stream, ", ");
19799 if (*col_p + strlen (string) > 72)
19801 fprintf (stream, "\n%24s", "");
19805 fprintf (stream, "%s", string);
19806 *col_p += strlen (string);
19812 md_show_usage (FILE *stream)
19817 fprintf (stream, _("\
19819 -EB generate big endian output\n\
19820 -EL generate little endian output\n\
19821 -g, -g2 do not remove unneeded NOPs or swap branches\n\
19822 -G NUM allow referencing objects up to NUM bytes\n\
19823 implicitly with the gp register [default 8]\n"));
19824 fprintf (stream, _("\
19825 -mips1 generate MIPS ISA I instructions\n\
19826 -mips2 generate MIPS ISA II instructions\n\
19827 -mips3 generate MIPS ISA III instructions\n\
19828 -mips4 generate MIPS ISA IV instructions\n\
19829 -mips5 generate MIPS ISA V instructions\n\
19830 -mips32 generate MIPS32 ISA instructions\n\
19831 -mips32r2 generate MIPS32 release 2 ISA instructions\n\
19832 -mips64 generate MIPS64 ISA instructions\n\
19833 -mips64r2 generate MIPS64 release 2 ISA instructions\n\
19834 -march=CPU/-mtune=CPU generate code/schedule for CPU, where CPU is one of:\n"));
19838 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
19839 show (stream, mips_cpu_info_table[i].name, &column, &first);
19840 show (stream, "from-abi", &column, &first);
19841 fputc ('\n', stream);
19843 fprintf (stream, _("\
19844 -mCPU equivalent to -march=CPU -mtune=CPU. Deprecated.\n\
19845 -no-mCPU don't generate code specific to CPU.\n\
19846 For -mCPU and -no-mCPU, CPU must be one of:\n"));
19850 show (stream, "3900", &column, &first);
19851 show (stream, "4010", &column, &first);
19852 show (stream, "4100", &column, &first);
19853 show (stream, "4650", &column, &first);
19854 fputc ('\n', stream);
19856 fprintf (stream, _("\
19857 -mips16 generate mips16 instructions\n\
19858 -no-mips16 do not generate mips16 instructions\n"));
19859 fprintf (stream, _("\
19860 -mmicromips generate microMIPS instructions\n\
19861 -mno-micromips do not generate microMIPS instructions\n"));
19862 fprintf (stream, _("\
19863 -msmartmips generate smartmips instructions\n\
19864 -mno-smartmips do not generate smartmips instructions\n"));
19865 fprintf (stream, _("\
19866 -mdsp generate DSP instructions\n\
19867 -mno-dsp do not generate DSP instructions\n"));
19868 fprintf (stream, _("\
19869 -mdspr2 generate DSP R2 instructions\n\
19870 -mno-dspr2 do not generate DSP R2 instructions\n"));
19871 fprintf (stream, _("\
19872 -mmt generate MT instructions\n\
19873 -mno-mt do not generate MT instructions\n"));
19874 fprintf (stream, _("\
19875 -mmcu generate MCU instructions\n\
19876 -mno-mcu do not generate MCU instructions\n"));
19877 fprintf (stream, _("\
19878 -mvirt generate Virtualization instructions\n\
19879 -mno-virt do not generate Virtualization instructions\n"));
19880 fprintf (stream, _("\
19881 -mfix-loongson2f-jump work around Loongson2F JUMP instructions\n\
19882 -mfix-loongson2f-nop work around Loongson2F NOP errata\n\
19883 -mfix-vr4120 work around certain VR4120 errata\n\
19884 -mfix-vr4130 work around VR4130 mflo/mfhi errata\n\
19885 -mfix-24k insert a nop after ERET and DERET instructions\n\
19886 -mfix-cn63xxp1 work around CN63XXP1 PREF errata\n\
19887 -mgp32 use 32-bit GPRs, regardless of the chosen ISA\n\
19888 -mfp32 use 32-bit FPRs, regardless of the chosen ISA\n\
19889 -msym32 assume all symbols have 32-bit values\n\
19890 -O0 remove unneeded NOPs, do not swap branches\n\
19891 -O remove unneeded NOPs and swap branches\n\
19892 --trap, --no-break trap exception on div by 0 and mult overflow\n\
19893 --break, --no-trap break exception on div by 0 and mult overflow\n"));
19894 fprintf (stream, _("\
19895 -mhard-float allow floating-point instructions\n\
19896 -msoft-float do not allow floating-point instructions\n\
19897 -msingle-float only allow 32-bit floating-point operations\n\
19898 -mdouble-float allow 32-bit and 64-bit floating-point operations\n\
19899 --[no-]construct-floats [dis]allow floating point values to be constructed\n\
19900 --[no-]relax-branch [dis]allow out-of-range branches to be relaxed\n"
19903 fprintf (stream, _("\
19904 -KPIC, -call_shared generate SVR4 position independent code\n\
19905 -call_nonpic generate non-PIC code that can operate with DSOs\n\
19906 -mvxworks-pic generate VxWorks position independent code\n\
19907 -non_shared do not generate code that can operate with DSOs\n\
19908 -xgot assume a 32 bit GOT\n\
19909 -mpdr, -mno-pdr enable/disable creation of .pdr sections\n\
19910 -mshared, -mno-shared disable/enable .cpload optimization for\n\
19911 position dependent (non shared) code\n\
19912 -mabi=ABI create ABI conformant object file for:\n"));
19916 show (stream, "32", &column, &first);
19917 show (stream, "o64", &column, &first);
19918 show (stream, "n32", &column, &first);
19919 show (stream, "64", &column, &first);
19920 show (stream, "eabi", &column, &first);
19922 fputc ('\n', stream);
19924 fprintf (stream, _("\
19925 -32 create o32 ABI object file (default)\n\
19926 -n32 create n32 ABI object file\n\
19927 -64 create 64 ABI object file\n"));
19933 mips_dwarf2_format (asection *sec ATTRIBUTE_UNUSED)
19935 if (HAVE_64BIT_SYMBOLS)
19936 return dwarf2_format_64bit_irix;
19938 return dwarf2_format_32bit;
19943 mips_dwarf2_addr_size (void)
19945 if (HAVE_64BIT_OBJECTS)
19951 /* Standard calling conventions leave the CFA at SP on entry. */
19953 mips_cfi_frame_initial_instructions (void)
19955 cfi_add_CFA_def_cfa_register (SP);
19959 tc_mips_regname_to_dw2regnum (char *regname)
19961 unsigned int regnum = -1;
19964 if (reg_lookup (®name, RTYPE_GP | RTYPE_NUM, ®))