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
43 /* Clean up namespace so we can include obj-elf.h too. */
44 static int mips_output_flavor (void);
45 static int mips_output_flavor (void) { return OUTPUT_FLAVOR; }
46 #undef OBJ_PROCESS_STAB
53 #undef obj_frob_file_after_relocs
54 #undef obj_frob_symbol
56 #undef obj_sec_sym_ok_for_reloc
57 #undef OBJ_COPY_SYMBOL_ATTRIBUTES
60 /* Fix any of them that we actually care about. */
62 #define OUTPUT_FLAVOR mips_output_flavor()
66 #ifndef ECOFF_DEBUGGING
67 #define NO_ECOFF_DEBUGGING
68 #define ECOFF_DEBUGGING 0
71 int mips_flag_mdebug = -1;
73 /* Control generation of .pdr sections. Off by default on IRIX: the native
74 linker doesn't know about and discards them, but relocations against them
75 remain, leading to rld crashes. */
77 int mips_flag_pdr = FALSE;
79 int mips_flag_pdr = TRUE;
84 static char *mips_regmask_frag;
91 #define PIC_CALL_REG 25
99 #define ILLEGAL_REG (32)
101 #define AT mips_opts.at
103 extern int target_big_endian;
105 /* The name of the readonly data section. */
106 #define RDATA_SECTION_NAME ".rodata"
108 /* Ways in which an instruction can be "appended" to the output. */
110 /* Just add it normally. */
113 /* Add it normally and then add a nop. */
116 /* Turn an instruction with a delay slot into a "compact" version. */
119 /* Insert the instruction before the last one. */
123 /* Information about an instruction, including its format, operands
127 /* The opcode's entry in mips_opcodes or mips16_opcodes. */
128 const struct mips_opcode *insn_mo;
130 /* The 16-bit or 32-bit bitstring of the instruction itself. This is
131 a copy of INSN_MO->match with the operands filled in. If we have
132 decided to use an extended MIPS16 instruction, this includes the
134 unsigned long insn_opcode;
136 /* The frag that contains the instruction. */
139 /* The offset into FRAG of the first instruction byte. */
142 /* The relocs associated with the instruction, if any. */
145 /* True if this entry cannot be moved from its current position. */
146 unsigned int fixed_p : 1;
148 /* True if this instruction occurred in a .set noreorder block. */
149 unsigned int noreorder_p : 1;
151 /* True for mips16 instructions that jump to an absolute address. */
152 unsigned int mips16_absolute_jump_p : 1;
154 /* True if this instruction is complete. */
155 unsigned int complete_p : 1;
157 /* True if this instruction is cleared from history by unconditional
159 unsigned int cleared_p : 1;
162 /* The ABI to use. */
173 /* MIPS ABI we are using for this output file. */
174 static enum mips_abi_level mips_abi = NO_ABI;
176 /* Whether or not we have code that can call pic code. */
177 int mips_abicalls = FALSE;
179 /* Whether or not we have code which can be put into a shared
181 static bfd_boolean mips_in_shared = TRUE;
183 /* This is the set of options which may be modified by the .set
184 pseudo-op. We use a struct so that .set push and .set pop are more
187 struct mips_set_options
189 /* MIPS ISA (Instruction Set Architecture) level. This is set to -1
190 if it has not been initialized. Changed by `.set mipsN', and the
191 -mipsN command line option, and the default CPU. */
193 /* Enabled Application Specific Extensions (ASEs). Changed by `.set
194 <asename>', by command line options, and based on the default
197 /* Whether we are assembling for the mips16 processor. 0 if we are
198 not, 1 if we are, and -1 if the value has not been initialized.
199 Changed by `.set mips16' and `.set nomips16', and the -mips16 and
200 -nomips16 command line options, and the default CPU. */
202 /* Whether we are assembling for the mipsMIPS ASE. 0 if we are not,
203 1 if we are, and -1 if the value has not been initialized. Changed
204 by `.set micromips' and `.set nomicromips', and the -mmicromips
205 and -mno-micromips command line options, and the default CPU. */
207 /* Non-zero if we should not reorder instructions. Changed by `.set
208 reorder' and `.set noreorder'. */
210 /* Non-zero if we should not permit the register designated "assembler
211 temporary" to be used in instructions. The value is the register
212 number, normally $at ($1). Changed by `.set at=REG', `.set noat'
213 (same as `.set at=$0') and `.set at' (same as `.set at=$1'). */
215 /* Non-zero if we should warn when a macro instruction expands into
216 more than one machine instruction. Changed by `.set nomacro' and
218 int warn_about_macros;
219 /* Non-zero if we should not move instructions. Changed by `.set
220 move', `.set volatile', `.set nomove', and `.set novolatile'. */
222 /* Non-zero if we should not optimize branches by moving the target
223 of the branch into the delay slot. Actually, we don't perform
224 this optimization anyhow. Changed by `.set bopt' and `.set
227 /* Non-zero if we should not autoextend mips16 instructions.
228 Changed by `.set autoextend' and `.set noautoextend'. */
230 /* Restrict general purpose registers and floating point registers
231 to 32 bit. This is initially determined when -mgp32 or -mfp32
232 is passed but can changed if the assembler code uses .set mipsN. */
235 /* MIPS architecture (CPU) type. Changed by .set arch=FOO, the -march
236 command line option, and the default CPU. */
238 /* True if ".set sym32" is in effect. */
240 /* True if floating-point operations are not allowed. Changed by .set
241 softfloat or .set hardfloat, by command line options -msoft-float or
242 -mhard-float. The default is false. */
243 bfd_boolean soft_float;
245 /* True if only single-precision floating-point operations are allowed.
246 Changed by .set singlefloat or .set doublefloat, command-line options
247 -msingle-float or -mdouble-float. The default is false. */
248 bfd_boolean single_float;
251 /* This is the struct we use to hold the current set of options. Note
252 that we must set the isa field to ISA_UNKNOWN and the ASE fields to
253 -1 to indicate that they have not been initialized. */
255 /* True if -mgp32 was passed. */
256 static int file_mips_gp32 = -1;
258 /* True if -mfp32 was passed. */
259 static int file_mips_fp32 = -1;
261 /* 1 if -msoft-float, 0 if -mhard-float. The default is 0. */
262 static int file_mips_soft_float = 0;
264 /* 1 if -msingle-float, 0 if -mdouble-float. The default is 0. */
265 static int file_mips_single_float = 0;
267 static struct mips_set_options mips_opts =
269 /* isa */ ISA_UNKNOWN, /* ase */ 0, /* mips16 */ -1, /* micromips */ -1,
270 /* noreorder */ 0, /* at */ ATREG, /* warn_about_macros */ 0,
271 /* nomove */ 0, /* nobopt */ 0, /* noautoextend */ 0, /* gp32 */ 0,
272 /* fp32 */ 0, /* arch */ CPU_UNKNOWN, /* sym32 */ FALSE,
273 /* soft_float */ FALSE, /* single_float */ FALSE
276 /* The set of ASEs that were selected on the command line, either
277 explicitly via ASE options or implicitly through things like -march. */
278 static unsigned int file_ase;
280 /* Which bits of file_ase were explicitly set or cleared by ASE options. */
281 static unsigned int file_ase_explicit;
283 /* These variables are filled in with the masks of registers used.
284 The object format code reads them and puts them in the appropriate
286 unsigned long mips_gprmask;
287 unsigned long mips_cprmask[4];
289 /* MIPS ISA we are using for this output file. */
290 static int file_mips_isa = ISA_UNKNOWN;
292 /* True if any MIPS16 code was produced. */
293 static int file_ase_mips16;
295 #define ISA_SUPPORTS_MIPS16E (mips_opts.isa == ISA_MIPS32 \
296 || mips_opts.isa == ISA_MIPS32R2 \
297 || mips_opts.isa == ISA_MIPS64 \
298 || mips_opts.isa == ISA_MIPS64R2)
300 /* True if any microMIPS code was produced. */
301 static int file_ase_micromips;
303 /* True if we want to create R_MIPS_JALR for jalr $25. */
305 #define MIPS_JALR_HINT_P(EXPR) HAVE_NEWABI
307 /* As a GNU extension, we use R_MIPS_JALR for o32 too. However,
308 because there's no place for any addend, the only acceptable
309 expression is a bare symbol. */
310 #define MIPS_JALR_HINT_P(EXPR) \
311 (!HAVE_IN_PLACE_ADDENDS \
312 || ((EXPR)->X_op == O_symbol && (EXPR)->X_add_number == 0))
315 /* The argument of the -march= flag. The architecture we are assembling. */
316 static int file_mips_arch = CPU_UNKNOWN;
317 static const char *mips_arch_string;
319 /* The argument of the -mtune= flag. The architecture for which we
321 static int mips_tune = CPU_UNKNOWN;
322 static const char *mips_tune_string;
324 /* True when generating 32-bit code for a 64-bit processor. */
325 static int mips_32bitmode = 0;
327 /* True if the given ABI requires 32-bit registers. */
328 #define ABI_NEEDS_32BIT_REGS(ABI) ((ABI) == O32_ABI)
330 /* Likewise 64-bit registers. */
331 #define ABI_NEEDS_64BIT_REGS(ABI) \
333 || (ABI) == N64_ABI \
336 /* Return true if ISA supports 64 bit wide gp registers. */
337 #define ISA_HAS_64BIT_REGS(ISA) \
338 ((ISA) == ISA_MIPS3 \
339 || (ISA) == ISA_MIPS4 \
340 || (ISA) == ISA_MIPS5 \
341 || (ISA) == ISA_MIPS64 \
342 || (ISA) == ISA_MIPS64R2)
344 /* Return true if ISA supports 64 bit wide float registers. */
345 #define ISA_HAS_64BIT_FPRS(ISA) \
346 ((ISA) == ISA_MIPS3 \
347 || (ISA) == ISA_MIPS4 \
348 || (ISA) == ISA_MIPS5 \
349 || (ISA) == ISA_MIPS32R2 \
350 || (ISA) == ISA_MIPS64 \
351 || (ISA) == ISA_MIPS64R2)
353 /* Return true if ISA supports 64-bit right rotate (dror et al.)
355 #define ISA_HAS_DROR(ISA) \
356 ((ISA) == ISA_MIPS64R2 \
357 || (mips_opts.micromips \
358 && ISA_HAS_64BIT_REGS (ISA)) \
361 /* Return true if ISA supports 32-bit right rotate (ror et al.)
363 #define ISA_HAS_ROR(ISA) \
364 ((ISA) == ISA_MIPS32R2 \
365 || (ISA) == ISA_MIPS64R2 \
366 || (mips_opts.ase & ASE_SMARTMIPS) \
367 || mips_opts.micromips \
370 /* Return true if ISA supports single-precision floats in odd registers. */
371 #define ISA_HAS_ODD_SINGLE_FPR(ISA) \
372 ((ISA) == ISA_MIPS32 \
373 || (ISA) == ISA_MIPS32R2 \
374 || (ISA) == ISA_MIPS64 \
375 || (ISA) == ISA_MIPS64R2)
377 /* Return true if ISA supports move to/from high part of a 64-bit
378 floating-point register. */
379 #define ISA_HAS_MXHC1(ISA) \
380 ((ISA) == ISA_MIPS32R2 \
381 || (ISA) == ISA_MIPS64R2)
383 #define HAVE_32BIT_GPRS \
384 (mips_opts.gp32 || !ISA_HAS_64BIT_REGS (mips_opts.isa))
386 #define HAVE_32BIT_FPRS \
387 (mips_opts.fp32 || !ISA_HAS_64BIT_FPRS (mips_opts.isa))
389 #define HAVE_64BIT_GPRS (!HAVE_32BIT_GPRS)
390 #define HAVE_64BIT_FPRS (!HAVE_32BIT_FPRS)
392 #define HAVE_NEWABI (mips_abi == N32_ABI || mips_abi == N64_ABI)
394 #define HAVE_64BIT_OBJECTS (mips_abi == N64_ABI)
396 /* True if relocations are stored in-place. */
397 #define HAVE_IN_PLACE_ADDENDS (!HAVE_NEWABI)
399 /* The ABI-derived address size. */
400 #define HAVE_64BIT_ADDRESSES \
401 (HAVE_64BIT_GPRS && (mips_abi == EABI_ABI || mips_abi == N64_ABI))
402 #define HAVE_32BIT_ADDRESSES (!HAVE_64BIT_ADDRESSES)
404 /* The size of symbolic constants (i.e., expressions of the form
405 "SYMBOL" or "SYMBOL + OFFSET"). */
406 #define HAVE_32BIT_SYMBOLS \
407 (HAVE_32BIT_ADDRESSES || !HAVE_64BIT_OBJECTS || mips_opts.sym32)
408 #define HAVE_64BIT_SYMBOLS (!HAVE_32BIT_SYMBOLS)
410 /* Addresses are loaded in different ways, depending on the address size
411 in use. The n32 ABI Documentation also mandates the use of additions
412 with overflow checking, but existing implementations don't follow it. */
413 #define ADDRESS_ADD_INSN \
414 (HAVE_32BIT_ADDRESSES ? "addu" : "daddu")
416 #define ADDRESS_ADDI_INSN \
417 (HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu")
419 #define ADDRESS_LOAD_INSN \
420 (HAVE_32BIT_ADDRESSES ? "lw" : "ld")
422 #define ADDRESS_STORE_INSN \
423 (HAVE_32BIT_ADDRESSES ? "sw" : "sd")
425 /* Return true if the given CPU supports the MIPS16 ASE. */
426 #define CPU_HAS_MIPS16(cpu) \
427 (strncmp (TARGET_CPU, "mips16", sizeof ("mips16") - 1) == 0 \
428 || strncmp (TARGET_CANONICAL, "mips-lsi-elf", sizeof ("mips-lsi-elf") - 1) == 0)
430 /* Return true if the given CPU supports the microMIPS ASE. */
431 #define CPU_HAS_MICROMIPS(cpu) 0
433 /* True if CPU has a dror instruction. */
434 #define CPU_HAS_DROR(CPU) ((CPU) == CPU_VR5400 || (CPU) == CPU_VR5500)
436 /* True if CPU has a ror instruction. */
437 #define CPU_HAS_ROR(CPU) CPU_HAS_DROR (CPU)
439 /* True if CPU is in the Octeon family */
440 #define CPU_IS_OCTEON(CPU) ((CPU) == CPU_OCTEON || (CPU) == CPU_OCTEONP || (CPU) == CPU_OCTEON2)
442 /* True if CPU has seq/sne and seqi/snei instructions. */
443 #define CPU_HAS_SEQ(CPU) (CPU_IS_OCTEON (CPU))
445 /* True, if CPU has support for ldc1 and sdc1. */
446 #define CPU_HAS_LDC1_SDC1(CPU) \
447 ((mips_opts.isa != ISA_MIPS1) && ((CPU) != CPU_R5900))
449 /* True if mflo and mfhi can be immediately followed by instructions
450 which write to the HI and LO registers.
452 According to MIPS specifications, MIPS ISAs I, II, and III need
453 (at least) two instructions between the reads of HI/LO and
454 instructions which write them, and later ISAs do not. Contradicting
455 the MIPS specifications, some MIPS IV processor user manuals (e.g.
456 the UM for the NEC Vr5000) document needing the instructions between
457 HI/LO reads and writes, as well. Therefore, we declare only MIPS32,
458 MIPS64 and later ISAs to have the interlocks, plus any specific
459 earlier-ISA CPUs for which CPU documentation declares that the
460 instructions are really interlocked. */
461 #define hilo_interlocks \
462 (mips_opts.isa == ISA_MIPS32 \
463 || mips_opts.isa == ISA_MIPS32R2 \
464 || mips_opts.isa == ISA_MIPS64 \
465 || mips_opts.isa == ISA_MIPS64R2 \
466 || mips_opts.arch == CPU_R4010 \
467 || mips_opts.arch == CPU_R5900 \
468 || mips_opts.arch == CPU_R10000 \
469 || mips_opts.arch == CPU_R12000 \
470 || mips_opts.arch == CPU_R14000 \
471 || mips_opts.arch == CPU_R16000 \
472 || mips_opts.arch == CPU_RM7000 \
473 || mips_opts.arch == CPU_VR5500 \
474 || mips_opts.micromips \
477 /* Whether the processor uses hardware interlocks to protect reads
478 from the GPRs after they are loaded from memory, and thus does not
479 require nops to be inserted. This applies to instructions marked
480 INSN_LOAD_MEMORY_DELAY. These nops are only required at MIPS ISA
481 level I and microMIPS mode instructions are always interlocked. */
482 #define gpr_interlocks \
483 (mips_opts.isa != ISA_MIPS1 \
484 || mips_opts.arch == CPU_R3900 \
485 || mips_opts.arch == CPU_R5900 \
486 || mips_opts.micromips \
489 /* Whether the processor uses hardware interlocks to avoid delays
490 required by coprocessor instructions, and thus does not require
491 nops to be inserted. This applies to instructions marked
492 INSN_LOAD_COPROC_DELAY, INSN_COPROC_MOVE_DELAY, and to delays
493 between instructions marked INSN_WRITE_COND_CODE and ones marked
494 INSN_READ_COND_CODE. These nops are only required at MIPS ISA
495 levels I, II, and III and microMIPS mode instructions are always
497 /* Itbl support may require additional care here. */
498 #define cop_interlocks \
499 ((mips_opts.isa != ISA_MIPS1 \
500 && mips_opts.isa != ISA_MIPS2 \
501 && mips_opts.isa != ISA_MIPS3) \
502 || mips_opts.arch == CPU_R4300 \
503 || mips_opts.micromips \
506 /* Whether the processor uses hardware interlocks to protect reads
507 from coprocessor registers after they are loaded from memory, and
508 thus does not require nops to be inserted. This applies to
509 instructions marked INSN_COPROC_MEMORY_DELAY. These nops are only
510 requires at MIPS ISA level I and microMIPS mode instructions are
511 always interlocked. */
512 #define cop_mem_interlocks \
513 (mips_opts.isa != ISA_MIPS1 \
514 || mips_opts.micromips \
517 /* Is this a mfhi or mflo instruction? */
518 #define MF_HILO_INSN(PINFO) \
519 ((PINFO & INSN_READ_HI) || (PINFO & INSN_READ_LO))
521 /* Whether code compression (either of the MIPS16 or the microMIPS ASEs)
522 has been selected. This implies, in particular, that addresses of text
523 labels have their LSB set. */
524 #define HAVE_CODE_COMPRESSION \
525 ((mips_opts.mips16 | mips_opts.micromips) != 0)
527 /* MIPS PIC level. */
529 enum mips_pic_level mips_pic;
531 /* 1 if we should generate 32 bit offsets from the $gp register in
532 SVR4_PIC mode. Currently has no meaning in other modes. */
533 static int mips_big_got = 0;
535 /* 1 if trap instructions should used for overflow rather than break
537 static int mips_trap = 0;
539 /* 1 if double width floating point constants should not be constructed
540 by assembling two single width halves into two single width floating
541 point registers which just happen to alias the double width destination
542 register. On some architectures this aliasing can be disabled by a bit
543 in the status register, and the setting of this bit cannot be determined
544 automatically at assemble time. */
545 static int mips_disable_float_construction;
547 /* Non-zero if any .set noreorder directives were used. */
549 static int mips_any_noreorder;
551 /* Non-zero if nops should be inserted when the register referenced in
552 an mfhi/mflo instruction is read in the next two instructions. */
553 static int mips_7000_hilo_fix;
555 /* The size of objects in the small data section. */
556 static unsigned int g_switch_value = 8;
557 /* Whether the -G option was used. */
558 static int g_switch_seen = 0;
563 /* If we can determine in advance that GP optimization won't be
564 possible, we can skip the relaxation stuff that tries to produce
565 GP-relative references. This makes delay slot optimization work
568 This function can only provide a guess, but it seems to work for
569 gcc output. It needs to guess right for gcc, otherwise gcc
570 will put what it thinks is a GP-relative instruction in a branch
573 I don't know if a fix is needed for the SVR4_PIC mode. I've only
574 fixed it for the non-PIC mode. KR 95/04/07 */
575 static int nopic_need_relax (symbolS *, int);
577 /* handle of the OPCODE hash table */
578 static struct hash_control *op_hash = NULL;
580 /* The opcode hash table we use for the mips16. */
581 static struct hash_control *mips16_op_hash = NULL;
583 /* The opcode hash table we use for the microMIPS ASE. */
584 static struct hash_control *micromips_op_hash = NULL;
586 /* This array holds the chars that always start a comment. If the
587 pre-processor is disabled, these aren't very useful */
588 const char comment_chars[] = "#";
590 /* This array holds the chars that only start a comment at the beginning of
591 a line. If the line seems to have the form '# 123 filename'
592 .line and .file directives will appear in the pre-processed output */
593 /* Note that input_file.c hand checks for '#' at the beginning of the
594 first line of the input file. This is because the compiler outputs
595 #NO_APP at the beginning of its output. */
596 /* Also note that C style comments are always supported. */
597 const char line_comment_chars[] = "#";
599 /* This array holds machine specific line separator characters. */
600 const char line_separator_chars[] = ";";
602 /* Chars that can be used to separate mant from exp in floating point nums */
603 const char EXP_CHARS[] = "eE";
605 /* Chars that mean this number is a floating point constant */
608 const char FLT_CHARS[] = "rRsSfFdDxXpP";
610 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
611 changed in read.c . Ideally it shouldn't have to know about it at all,
612 but nothing is ideal around here.
615 static char *insn_error;
617 static int auto_align = 1;
619 /* When outputting SVR4 PIC code, the assembler needs to know the
620 offset in the stack frame from which to restore the $gp register.
621 This is set by the .cprestore pseudo-op, and saved in this
623 static offsetT mips_cprestore_offset = -1;
625 /* Similar for NewABI PIC code, where $gp is callee-saved. NewABI has some
626 more optimizations, it can use a register value instead of a memory-saved
627 offset and even an other register than $gp as global pointer. */
628 static offsetT mips_cpreturn_offset = -1;
629 static int mips_cpreturn_register = -1;
630 static int mips_gp_register = GP;
631 static int mips_gprel_offset = 0;
633 /* Whether mips_cprestore_offset has been set in the current function
634 (or whether it has already been warned about, if not). */
635 static int mips_cprestore_valid = 0;
637 /* This is the register which holds the stack frame, as set by the
638 .frame pseudo-op. This is needed to implement .cprestore. */
639 static int mips_frame_reg = SP;
641 /* Whether mips_frame_reg has been set in the current function
642 (or whether it has already been warned about, if not). */
643 static int mips_frame_reg_valid = 0;
645 /* To output NOP instructions correctly, we need to keep information
646 about the previous two instructions. */
648 /* Whether we are optimizing. The default value of 2 means to remove
649 unneeded NOPs and swap branch instructions when possible. A value
650 of 1 means to not swap branches. A value of 0 means to always
652 static int mips_optimize = 2;
654 /* Debugging level. -g sets this to 2. -gN sets this to N. -g0 is
655 equivalent to seeing no -g option at all. */
656 static int mips_debug = 0;
658 /* The maximum number of NOPs needed to avoid the VR4130 mflo/mfhi errata. */
659 #define MAX_VR4130_NOPS 4
661 /* The maximum number of NOPs needed to fill delay slots. */
662 #define MAX_DELAY_NOPS 2
664 /* The maximum number of NOPs needed for any purpose. */
667 /* A list of previous instructions, with index 0 being the most recent.
668 We need to look back MAX_NOPS instructions when filling delay slots
669 or working around processor errata. We need to look back one
670 instruction further if we're thinking about using history[0] to
671 fill a branch delay slot. */
672 static struct mips_cl_insn history[1 + MAX_NOPS];
674 /* Nop instructions used by emit_nop. */
675 static struct mips_cl_insn nop_insn;
676 static struct mips_cl_insn mips16_nop_insn;
677 static struct mips_cl_insn micromips_nop16_insn;
678 static struct mips_cl_insn micromips_nop32_insn;
680 /* The appropriate nop for the current mode. */
681 #define NOP_INSN (mips_opts.mips16 ? &mips16_nop_insn \
682 : (mips_opts.micromips ? µmips_nop16_insn : &nop_insn))
684 /* The size of NOP_INSN in bytes. */
685 #define NOP_INSN_SIZE (HAVE_CODE_COMPRESSION ? 2 : 4)
687 /* If this is set, it points to a frag holding nop instructions which
688 were inserted before the start of a noreorder section. If those
689 nops turn out to be unnecessary, the size of the frag can be
691 static fragS *prev_nop_frag;
693 /* The number of nop instructions we created in prev_nop_frag. */
694 static int prev_nop_frag_holds;
696 /* The number of nop instructions that we know we need in
698 static int prev_nop_frag_required;
700 /* The number of instructions we've seen since prev_nop_frag. */
701 static int prev_nop_frag_since;
703 /* Relocations against symbols are sometimes done in two parts, with a HI
704 relocation and a LO relocation. Each relocation has only 16 bits of
705 space to store an addend. This means that in order for the linker to
706 handle carries correctly, it must be able to locate both the HI and
707 the LO relocation. This means that the relocations must appear in
708 order in the relocation table.
710 In order to implement this, we keep track of each unmatched HI
711 relocation. We then sort them so that they immediately precede the
712 corresponding LO relocation. */
717 struct mips_hi_fixup *next;
720 /* The section this fixup is in. */
724 /* The list of unmatched HI relocs. */
726 static struct mips_hi_fixup *mips_hi_fixup_list;
728 /* The frag containing the last explicit relocation operator.
729 Null if explicit relocations have not been used. */
731 static fragS *prev_reloc_op_frag;
733 /* Map normal MIPS register numbers to mips16 register numbers. */
735 #define X ILLEGAL_REG
736 static const int mips32_to_16_reg_map[] =
738 X, X, 2, 3, 4, 5, 6, 7,
739 X, X, X, X, X, X, X, X,
740 0, 1, X, X, X, X, X, X,
741 X, X, X, X, X, X, X, X
745 /* Map mips16 register numbers to normal MIPS register numbers. */
747 static const unsigned int mips16_to_32_reg_map[] =
749 16, 17, 2, 3, 4, 5, 6, 7
752 /* Map normal MIPS register numbers to microMIPS register numbers. */
754 #define mips32_to_micromips_reg_b_map mips32_to_16_reg_map
755 #define mips32_to_micromips_reg_c_map mips32_to_16_reg_map
756 #define mips32_to_micromips_reg_d_map mips32_to_16_reg_map
757 #define mips32_to_micromips_reg_e_map mips32_to_16_reg_map
758 #define mips32_to_micromips_reg_f_map mips32_to_16_reg_map
759 #define mips32_to_micromips_reg_g_map mips32_to_16_reg_map
760 #define mips32_to_micromips_reg_l_map mips32_to_16_reg_map
762 #define X ILLEGAL_REG
763 /* reg type h: 4, 5, 6. */
764 static const int mips32_to_micromips_reg_h_map[] =
766 X, X, X, X, 4, 5, 6, X,
767 X, X, X, X, X, X, X, X,
768 X, X, X, X, X, X, X, X,
769 X, X, X, X, X, X, X, X
772 /* reg type m: 0, 17, 2, 3, 16, 18, 19, 20. */
773 static const int mips32_to_micromips_reg_m_map[] =
775 0, X, 2, 3, X, X, X, X,
776 X, X, X, X, X, X, X, X,
777 4, 1, 5, 6, 7, X, X, X,
778 X, X, X, X, X, X, X, X
781 /* reg type q: 0, 2-7. 17. */
782 static const int mips32_to_micromips_reg_q_map[] =
784 0, X, 2, 3, 4, 5, 6, 7,
785 X, X, X, X, X, X, X, X,
786 X, 1, X, X, X, X, X, X,
787 X, X, X, X, X, X, X, X
790 #define mips32_to_micromips_reg_n_map mips32_to_micromips_reg_m_map
793 /* Map microMIPS register numbers to normal MIPS register numbers. */
795 #define micromips_to_32_reg_b_map mips16_to_32_reg_map
796 #define micromips_to_32_reg_c_map mips16_to_32_reg_map
797 #define micromips_to_32_reg_d_map mips16_to_32_reg_map
798 #define micromips_to_32_reg_e_map mips16_to_32_reg_map
799 #define micromips_to_32_reg_f_map mips16_to_32_reg_map
800 #define micromips_to_32_reg_g_map mips16_to_32_reg_map
802 /* The microMIPS registers with type h. */
803 static const unsigned int micromips_to_32_reg_h_map[] =
805 5, 5, 6, 4, 4, 4, 4, 4
808 /* The microMIPS registers with type i. */
809 static const unsigned int micromips_to_32_reg_i_map[] =
811 6, 7, 7, 21, 22, 5, 6, 7
814 #define micromips_to_32_reg_l_map mips16_to_32_reg_map
816 /* The microMIPS registers with type m. */
817 static const unsigned int micromips_to_32_reg_m_map[] =
819 0, 17, 2, 3, 16, 18, 19, 20
822 #define micromips_to_32_reg_n_map micromips_to_32_reg_m_map
824 /* The microMIPS registers with type q. */
825 static const unsigned int micromips_to_32_reg_q_map[] =
827 0, 17, 2, 3, 4, 5, 6, 7
830 /* microMIPS imm type B. */
831 static const int micromips_imm_b_map[] =
833 1, 4, 8, 12, 16, 20, 24, -1
836 /* microMIPS imm type C. */
837 static const int micromips_imm_c_map[] =
839 128, 1, 2, 3, 4, 7, 8, 15, 16, 31, 32, 63, 64, 255, 32768, 65535
842 /* Classifies the kind of instructions we're interested in when
843 implementing -mfix-vr4120. */
844 enum fix_vr4120_class
852 NUM_FIX_VR4120_CLASSES
855 /* ...likewise -mfix-loongson2f-jump. */
856 static bfd_boolean mips_fix_loongson2f_jump;
858 /* ...likewise -mfix-loongson2f-nop. */
859 static bfd_boolean mips_fix_loongson2f_nop;
861 /* True if -mfix-loongson2f-nop or -mfix-loongson2f-jump passed. */
862 static bfd_boolean mips_fix_loongson2f;
864 /* Given two FIX_VR4120_* values X and Y, bit Y of element X is set if
865 there must be at least one other instruction between an instruction
866 of type X and an instruction of type Y. */
867 static unsigned int vr4120_conflicts[NUM_FIX_VR4120_CLASSES];
869 /* True if -mfix-vr4120 is in force. */
870 static int mips_fix_vr4120;
872 /* ...likewise -mfix-vr4130. */
873 static int mips_fix_vr4130;
875 /* ...likewise -mfix-24k. */
876 static int mips_fix_24k;
878 /* ...likewise -mfix-cn63xxp1 */
879 static bfd_boolean mips_fix_cn63xxp1;
881 /* We don't relax branches by default, since this causes us to expand
882 `la .l2 - .l1' if there's a branch between .l1 and .l2, because we
883 fail to compute the offset before expanding the macro to the most
884 efficient expansion. */
886 static int mips_relax_branch;
888 /* The expansion of many macros depends on the type of symbol that
889 they refer to. For example, when generating position-dependent code,
890 a macro that refers to a symbol may have two different expansions,
891 one which uses GP-relative addresses and one which uses absolute
892 addresses. When generating SVR4-style PIC, a macro may have
893 different expansions for local and global symbols.
895 We handle these situations by generating both sequences and putting
896 them in variant frags. In position-dependent code, the first sequence
897 will be the GP-relative one and the second sequence will be the
898 absolute one. In SVR4 PIC, the first sequence will be for global
899 symbols and the second will be for local symbols.
901 The frag's "subtype" is RELAX_ENCODE (FIRST, SECOND), where FIRST and
902 SECOND are the lengths of the two sequences in bytes. These fields
903 can be extracted using RELAX_FIRST() and RELAX_SECOND(). In addition,
904 the subtype has the following flags:
907 Set if it has been decided that we should use the second
908 sequence instead of the first.
911 Set in the first variant frag if the macro's second implementation
912 is longer than its first. This refers to the macro as a whole,
913 not an individual relaxation.
916 Set in the first variant frag if the macro appeared in a .set nomacro
917 block and if one alternative requires a warning but the other does not.
920 Like RELAX_NOMACRO, but indicates that the macro appears in a branch
923 RELAX_DELAY_SLOT_16BIT
924 Like RELAX_DELAY_SLOT, but indicates that the delay slot requires a
927 RELAX_DELAY_SLOT_SIZE_FIRST
928 Like RELAX_DELAY_SLOT, but indicates that the first implementation of
929 the macro is of the wrong size for the branch delay slot.
931 RELAX_DELAY_SLOT_SIZE_SECOND
932 Like RELAX_DELAY_SLOT, but indicates that the second implementation of
933 the macro is of the wrong size for the branch delay slot.
935 The frag's "opcode" points to the first fixup for relaxable code.
937 Relaxable macros are generated using a sequence such as:
939 relax_start (SYMBOL);
940 ... generate first expansion ...
942 ... generate second expansion ...
945 The code and fixups for the unwanted alternative are discarded
946 by md_convert_frag. */
947 #define RELAX_ENCODE(FIRST, SECOND) (((FIRST) << 8) | (SECOND))
949 #define RELAX_FIRST(X) (((X) >> 8) & 0xff)
950 #define RELAX_SECOND(X) ((X) & 0xff)
951 #define RELAX_USE_SECOND 0x10000
952 #define RELAX_SECOND_LONGER 0x20000
953 #define RELAX_NOMACRO 0x40000
954 #define RELAX_DELAY_SLOT 0x80000
955 #define RELAX_DELAY_SLOT_16BIT 0x100000
956 #define RELAX_DELAY_SLOT_SIZE_FIRST 0x200000
957 #define RELAX_DELAY_SLOT_SIZE_SECOND 0x400000
959 /* Branch without likely bit. If label is out of range, we turn:
961 beq reg1, reg2, label
971 with the following opcode replacements:
978 bltzal <-> bgezal (with jal label instead of j label)
980 Even though keeping the delay slot instruction in the delay slot of
981 the branch would be more efficient, it would be very tricky to do
982 correctly, because we'd have to introduce a variable frag *after*
983 the delay slot instruction, and expand that instead. Let's do it
984 the easy way for now, even if the branch-not-taken case now costs
985 one additional instruction. Out-of-range branches are not supposed
986 to be common, anyway.
988 Branch likely. If label is out of range, we turn:
990 beql reg1, reg2, label
991 delay slot (annulled if branch not taken)
1000 delay slot (executed only if branch taken)
1003 It would be possible to generate a shorter sequence by losing the
1004 likely bit, generating something like:
1009 delay slot (executed only if branch taken)
1021 bltzall -> bgezal (with jal label instead of j label)
1022 bgezall -> bltzal (ditto)
1025 but it's not clear that it would actually improve performance. */
1026 #define RELAX_BRANCH_ENCODE(at, uncond, likely, link, toofar) \
1027 ((relax_substateT) \
1030 | ((toofar) ? 0x20 : 0) \
1031 | ((link) ? 0x40 : 0) \
1032 | ((likely) ? 0x80 : 0) \
1033 | ((uncond) ? 0x100 : 0)))
1034 #define RELAX_BRANCH_P(i) (((i) & 0xf0000000) == 0xc0000000)
1035 #define RELAX_BRANCH_UNCOND(i) (((i) & 0x100) != 0)
1036 #define RELAX_BRANCH_LIKELY(i) (((i) & 0x80) != 0)
1037 #define RELAX_BRANCH_LINK(i) (((i) & 0x40) != 0)
1038 #define RELAX_BRANCH_TOOFAR(i) (((i) & 0x20) != 0)
1039 #define RELAX_BRANCH_AT(i) ((i) & 0x1f)
1041 /* For mips16 code, we use an entirely different form of relaxation.
1042 mips16 supports two versions of most instructions which take
1043 immediate values: a small one which takes some small value, and a
1044 larger one which takes a 16 bit value. Since branches also follow
1045 this pattern, relaxing these values is required.
1047 We can assemble both mips16 and normal MIPS code in a single
1048 object. Therefore, we need to support this type of relaxation at
1049 the same time that we support the relaxation described above. We
1050 use the high bit of the subtype field to distinguish these cases.
1052 The information we store for this type of relaxation is the
1053 argument code found in the opcode file for this relocation, whether
1054 the user explicitly requested a small or extended form, and whether
1055 the relocation is in a jump or jal delay slot. That tells us the
1056 size of the value, and how it should be stored. We also store
1057 whether the fragment is considered to be extended or not. We also
1058 store whether this is known to be a branch to a different section,
1059 whether we have tried to relax this frag yet, and whether we have
1060 ever extended a PC relative fragment because of a shift count. */
1061 #define RELAX_MIPS16_ENCODE(type, small, ext, dslot, jal_dslot) \
1064 | ((small) ? 0x100 : 0) \
1065 | ((ext) ? 0x200 : 0) \
1066 | ((dslot) ? 0x400 : 0) \
1067 | ((jal_dslot) ? 0x800 : 0))
1068 #define RELAX_MIPS16_P(i) (((i) & 0xc0000000) == 0x80000000)
1069 #define RELAX_MIPS16_TYPE(i) ((i) & 0xff)
1070 #define RELAX_MIPS16_USER_SMALL(i) (((i) & 0x100) != 0)
1071 #define RELAX_MIPS16_USER_EXT(i) (((i) & 0x200) != 0)
1072 #define RELAX_MIPS16_DSLOT(i) (((i) & 0x400) != 0)
1073 #define RELAX_MIPS16_JAL_DSLOT(i) (((i) & 0x800) != 0)
1074 #define RELAX_MIPS16_EXTENDED(i) (((i) & 0x1000) != 0)
1075 #define RELAX_MIPS16_MARK_EXTENDED(i) ((i) | 0x1000)
1076 #define RELAX_MIPS16_CLEAR_EXTENDED(i) ((i) &~ 0x1000)
1077 #define RELAX_MIPS16_LONG_BRANCH(i) (((i) & 0x2000) != 0)
1078 #define RELAX_MIPS16_MARK_LONG_BRANCH(i) ((i) | 0x2000)
1079 #define RELAX_MIPS16_CLEAR_LONG_BRANCH(i) ((i) &~ 0x2000)
1081 /* For microMIPS code, we use relaxation similar to one we use for
1082 MIPS16 code. Some instructions that take immediate values support
1083 two encodings: a small one which takes some small value, and a
1084 larger one which takes a 16 bit value. As some branches also follow
1085 this pattern, relaxing these values is required.
1087 We can assemble both microMIPS and normal MIPS code in a single
1088 object. Therefore, we need to support this type of relaxation at
1089 the same time that we support the relaxation described above. We
1090 use one of the high bits of the subtype field to distinguish these
1093 The information we store for this type of relaxation is the argument
1094 code found in the opcode file for this relocation, the register
1095 selected as the assembler temporary, whether the branch is
1096 unconditional, whether it is compact, whether it stores the link
1097 address implicitly in $ra, whether relaxation of out-of-range 32-bit
1098 branches to a sequence of instructions is enabled, and whether the
1099 displacement of a branch is too large to fit as an immediate argument
1100 of a 16-bit and a 32-bit branch, respectively. */
1101 #define RELAX_MICROMIPS_ENCODE(type, at, uncond, compact, link, \
1102 relax32, toofar16, toofar32) \
1105 | (((at) & 0x1f) << 8) \
1106 | ((uncond) ? 0x2000 : 0) \
1107 | ((compact) ? 0x4000 : 0) \
1108 | ((link) ? 0x8000 : 0) \
1109 | ((relax32) ? 0x10000 : 0) \
1110 | ((toofar16) ? 0x20000 : 0) \
1111 | ((toofar32) ? 0x40000 : 0))
1112 #define RELAX_MICROMIPS_P(i) (((i) & 0xc0000000) == 0x40000000)
1113 #define RELAX_MICROMIPS_TYPE(i) ((i) & 0xff)
1114 #define RELAX_MICROMIPS_AT(i) (((i) >> 8) & 0x1f)
1115 #define RELAX_MICROMIPS_UNCOND(i) (((i) & 0x2000) != 0)
1116 #define RELAX_MICROMIPS_COMPACT(i) (((i) & 0x4000) != 0)
1117 #define RELAX_MICROMIPS_LINK(i) (((i) & 0x8000) != 0)
1118 #define RELAX_MICROMIPS_RELAX32(i) (((i) & 0x10000) != 0)
1120 #define RELAX_MICROMIPS_TOOFAR16(i) (((i) & 0x20000) != 0)
1121 #define RELAX_MICROMIPS_MARK_TOOFAR16(i) ((i) | 0x20000)
1122 #define RELAX_MICROMIPS_CLEAR_TOOFAR16(i) ((i) & ~0x20000)
1123 #define RELAX_MICROMIPS_TOOFAR32(i) (((i) & 0x40000) != 0)
1124 #define RELAX_MICROMIPS_MARK_TOOFAR32(i) ((i) | 0x40000)
1125 #define RELAX_MICROMIPS_CLEAR_TOOFAR32(i) ((i) & ~0x40000)
1127 /* Sign-extend 16-bit value X. */
1128 #define SEXT_16BIT(X) ((((X) + 0x8000) & 0xffff) - 0x8000)
1130 /* Is the given value a sign-extended 32-bit value? */
1131 #define IS_SEXT_32BIT_NUM(x) \
1132 (((x) &~ (offsetT) 0x7fffffff) == 0 \
1133 || (((x) &~ (offsetT) 0x7fffffff) == ~ (offsetT) 0x7fffffff))
1135 /* Is the given value a sign-extended 16-bit value? */
1136 #define IS_SEXT_16BIT_NUM(x) \
1137 (((x) &~ (offsetT) 0x7fff) == 0 \
1138 || (((x) &~ (offsetT) 0x7fff) == ~ (offsetT) 0x7fff))
1140 /* Is the given value a sign-extended 12-bit value? */
1141 #define IS_SEXT_12BIT_NUM(x) \
1142 (((((x) & 0xfff) ^ 0x800LL) - 0x800LL) == (x))
1144 /* Is the given value a sign-extended 9-bit value? */
1145 #define IS_SEXT_9BIT_NUM(x) \
1146 (((((x) & 0x1ff) ^ 0x100LL) - 0x100LL) == (x))
1148 /* Is the given value a zero-extended 32-bit value? Or a negated one? */
1149 #define IS_ZEXT_32BIT_NUM(x) \
1150 (((x) &~ (offsetT) 0xffffffff) == 0 \
1151 || (((x) &~ (offsetT) 0xffffffff) == ~ (offsetT) 0xffffffff))
1153 /* Replace bits MASK << SHIFT of STRUCT with the equivalent bits in
1154 VALUE << SHIFT. VALUE is evaluated exactly once. */
1155 #define INSERT_BITS(STRUCT, VALUE, MASK, SHIFT) \
1156 (STRUCT) = (((STRUCT) & ~((MASK) << (SHIFT))) \
1157 | (((VALUE) & (MASK)) << (SHIFT)))
1159 /* Extract bits MASK << SHIFT from STRUCT and shift them right
1161 #define EXTRACT_BITS(STRUCT, MASK, SHIFT) \
1162 (((STRUCT) >> (SHIFT)) & (MASK))
1164 /* Change INSN's opcode so that the operand given by FIELD has value VALUE.
1165 INSN is a mips_cl_insn structure and VALUE is evaluated exactly once.
1167 include/opcode/mips.h specifies operand fields using the macros
1168 OP_MASK_<FIELD> and OP_SH_<FIELD>. The MIPS16 equivalents start
1169 with "MIPS16OP" instead of "OP". */
1170 #define INSERT_OPERAND(MICROMIPS, FIELD, INSN, VALUE) \
1173 INSERT_BITS ((INSN).insn_opcode, VALUE, \
1174 OP_MASK_##FIELD, OP_SH_##FIELD); \
1176 INSERT_BITS ((INSN).insn_opcode, VALUE, \
1177 MICROMIPSOP_MASK_##FIELD, MICROMIPSOP_SH_##FIELD); \
1179 #define MIPS16_INSERT_OPERAND(FIELD, INSN, VALUE) \
1180 INSERT_BITS ((INSN).insn_opcode, VALUE, \
1181 MIPS16OP_MASK_##FIELD, MIPS16OP_SH_##FIELD)
1183 /* Extract the operand given by FIELD from mips_cl_insn INSN. */
1184 #define EXTRACT_OPERAND(MICROMIPS, FIELD, INSN) \
1186 ? EXTRACT_BITS ((INSN).insn_opcode, OP_MASK_##FIELD, OP_SH_##FIELD) \
1187 : EXTRACT_BITS ((INSN).insn_opcode, \
1188 MICROMIPSOP_MASK_##FIELD, MICROMIPSOP_SH_##FIELD))
1189 #define MIPS16_EXTRACT_OPERAND(FIELD, INSN) \
1190 EXTRACT_BITS ((INSN).insn_opcode, \
1191 MIPS16OP_MASK_##FIELD, \
1192 MIPS16OP_SH_##FIELD)
1194 /* The MIPS16 EXTEND opcode, shifted left 16 places. */
1195 #define MIPS16_EXTEND (0xf000U << 16)
1197 /* Whether or not we are emitting a branch-likely macro. */
1198 static bfd_boolean emit_branch_likely_macro = FALSE;
1200 /* Global variables used when generating relaxable macros. See the
1201 comment above RELAX_ENCODE for more details about how relaxation
1204 /* 0 if we're not emitting a relaxable macro.
1205 1 if we're emitting the first of the two relaxation alternatives.
1206 2 if we're emitting the second alternative. */
1209 /* The first relaxable fixup in the current frag. (In other words,
1210 the first fixup that refers to relaxable code.) */
1213 /* sizes[0] says how many bytes of the first alternative are stored in
1214 the current frag. Likewise sizes[1] for the second alternative. */
1215 unsigned int sizes[2];
1217 /* The symbol on which the choice of sequence depends. */
1221 /* Global variables used to decide whether a macro needs a warning. */
1223 /* True if the macro is in a branch delay slot. */
1224 bfd_boolean delay_slot_p;
1226 /* Set to the length in bytes required if the macro is in a delay slot
1227 that requires a specific length of instruction, otherwise zero. */
1228 unsigned int delay_slot_length;
1230 /* For relaxable macros, sizes[0] is the length of the first alternative
1231 in bytes and sizes[1] is the length of the second alternative.
1232 For non-relaxable macros, both elements give the length of the
1234 unsigned int sizes[2];
1236 /* For relaxable macros, first_insn_sizes[0] is the length of the first
1237 instruction of the first alternative in bytes and first_insn_sizes[1]
1238 is the length of the first instruction of the second alternative.
1239 For non-relaxable macros, both elements give the length of the first
1240 instruction in bytes.
1242 Set to zero if we haven't yet seen the first instruction. */
1243 unsigned int first_insn_sizes[2];
1245 /* For relaxable macros, insns[0] is the number of instructions for the
1246 first alternative and insns[1] is the number of instructions for the
1249 For non-relaxable macros, both elements give the number of
1250 instructions for the macro. */
1251 unsigned int insns[2];
1253 /* The first variant frag for this macro. */
1255 } mips_macro_warning;
1257 /* Prototypes for static functions. */
1259 enum mips_regclass { MIPS_GR_REG, MIPS_FP_REG, MIPS16_REG };
1261 static void append_insn
1262 (struct mips_cl_insn *, expressionS *, bfd_reloc_code_real_type *,
1263 bfd_boolean expansionp);
1264 static void mips_no_prev_insn (void);
1265 static void macro_build (expressionS *, const char *, const char *, ...);
1266 static void mips16_macro_build
1267 (expressionS *, const char *, const char *, va_list *);
1268 static void load_register (int, expressionS *, int);
1269 static void macro_start (void);
1270 static void macro_end (void);
1271 static void macro (struct mips_cl_insn * ip);
1272 static void mips16_macro (struct mips_cl_insn * ip);
1273 static void mips_ip (char *str, struct mips_cl_insn * ip);
1274 static void mips16_ip (char *str, struct mips_cl_insn * ip);
1275 static void mips16_immed
1276 (char *, unsigned int, int, bfd_reloc_code_real_type, offsetT,
1277 unsigned int, unsigned long *);
1278 static size_t my_getSmallExpression
1279 (expressionS *, bfd_reloc_code_real_type *, char *);
1280 static void my_getExpression (expressionS *, char *);
1281 static void s_align (int);
1282 static void s_change_sec (int);
1283 static void s_change_section (int);
1284 static void s_cons (int);
1285 static void s_float_cons (int);
1286 static void s_mips_globl (int);
1287 static void s_option (int);
1288 static void s_mipsset (int);
1289 static void s_abicalls (int);
1290 static void s_cpload (int);
1291 static void s_cpsetup (int);
1292 static void s_cplocal (int);
1293 static void s_cprestore (int);
1294 static void s_cpreturn (int);
1295 static void s_dtprelword (int);
1296 static void s_dtpreldword (int);
1297 static void s_tprelword (int);
1298 static void s_tpreldword (int);
1299 static void s_gpvalue (int);
1300 static void s_gpword (int);
1301 static void s_gpdword (int);
1302 static void s_ehword (int);
1303 static void s_cpadd (int);
1304 static void s_insn (int);
1305 static void md_obj_begin (void);
1306 static void md_obj_end (void);
1307 static void s_mips_ent (int);
1308 static void s_mips_end (int);
1309 static void s_mips_frame (int);
1310 static void s_mips_mask (int reg_type);
1311 static void s_mips_stab (int);
1312 static void s_mips_weakext (int);
1313 static void s_mips_file (int);
1314 static void s_mips_loc (int);
1315 static bfd_boolean pic_need_relax (symbolS *, asection *);
1316 static int relaxed_branch_length (fragS *, asection *, int);
1317 static int validate_mips_insn (const struct mips_opcode *);
1318 static int validate_micromips_insn (const struct mips_opcode *);
1319 static int relaxed_micromips_16bit_branch_length (fragS *, asection *, int);
1320 static int relaxed_micromips_32bit_branch_length (fragS *, asection *, int);
1322 /* Table and functions used to map between CPU/ISA names, and
1323 ISA levels, and CPU numbers. */
1325 struct mips_cpu_info
1327 const char *name; /* CPU or ISA name. */
1328 int flags; /* MIPS_CPU_* flags. */
1329 int ase; /* Set of ASEs implemented by the CPU. */
1330 int isa; /* ISA level. */
1331 int cpu; /* CPU number (default CPU if ISA). */
1334 #define MIPS_CPU_IS_ISA 0x0001 /* Is this an ISA? (If 0, a CPU.) */
1336 static const struct mips_cpu_info *mips_parse_cpu (const char *, const char *);
1337 static const struct mips_cpu_info *mips_cpu_info_from_isa (int);
1338 static const struct mips_cpu_info *mips_cpu_info_from_arch (int);
1340 /* Command-line options. */
1341 const char *md_shortopts = "O::g::G:";
1345 OPTION_MARCH = OPTION_MD_BASE,
1369 OPTION_NO_SMARTMIPS,
1375 OPTION_NO_MICROMIPS,
1378 OPTION_COMPAT_ARCH_BASE,
1387 OPTION_M7000_HILO_FIX,
1388 OPTION_MNO_7000_HILO_FIX,
1391 OPTION_FIX_LOONGSON2F_JUMP,
1392 OPTION_NO_FIX_LOONGSON2F_JUMP,
1393 OPTION_FIX_LOONGSON2F_NOP,
1394 OPTION_NO_FIX_LOONGSON2F_NOP,
1396 OPTION_NO_FIX_VR4120,
1398 OPTION_NO_FIX_VR4130,
1399 OPTION_FIX_CN63XXP1,
1400 OPTION_NO_FIX_CN63XXP1,
1407 OPTION_CONSTRUCT_FLOATS,
1408 OPTION_NO_CONSTRUCT_FLOATS,
1411 OPTION_RELAX_BRANCH,
1412 OPTION_NO_RELAX_BRANCH,
1419 OPTION_SINGLE_FLOAT,
1420 OPTION_DOUBLE_FLOAT,
1433 OPTION_MVXWORKS_PIC,
1437 struct option md_longopts[] =
1439 /* Options which specify architecture. */
1440 {"march", required_argument, NULL, OPTION_MARCH},
1441 {"mtune", required_argument, NULL, OPTION_MTUNE},
1442 {"mips0", no_argument, NULL, OPTION_MIPS1},
1443 {"mips1", no_argument, NULL, OPTION_MIPS1},
1444 {"mips2", no_argument, NULL, OPTION_MIPS2},
1445 {"mips3", no_argument, NULL, OPTION_MIPS3},
1446 {"mips4", no_argument, NULL, OPTION_MIPS4},
1447 {"mips5", no_argument, NULL, OPTION_MIPS5},
1448 {"mips32", no_argument, NULL, OPTION_MIPS32},
1449 {"mips64", no_argument, NULL, OPTION_MIPS64},
1450 {"mips32r2", no_argument, NULL, OPTION_MIPS32R2},
1451 {"mips64r2", no_argument, NULL, OPTION_MIPS64R2},
1453 /* Options which specify Application Specific Extensions (ASEs). */
1454 {"mips16", no_argument, NULL, OPTION_MIPS16},
1455 {"no-mips16", no_argument, NULL, OPTION_NO_MIPS16},
1456 {"mips3d", no_argument, NULL, OPTION_MIPS3D},
1457 {"no-mips3d", no_argument, NULL, OPTION_NO_MIPS3D},
1458 {"mdmx", no_argument, NULL, OPTION_MDMX},
1459 {"no-mdmx", no_argument, NULL, OPTION_NO_MDMX},
1460 {"mdsp", no_argument, NULL, OPTION_DSP},
1461 {"mno-dsp", no_argument, NULL, OPTION_NO_DSP},
1462 {"mmt", no_argument, NULL, OPTION_MT},
1463 {"mno-mt", no_argument, NULL, OPTION_NO_MT},
1464 {"msmartmips", no_argument, NULL, OPTION_SMARTMIPS},
1465 {"mno-smartmips", no_argument, NULL, OPTION_NO_SMARTMIPS},
1466 {"mdspr2", no_argument, NULL, OPTION_DSPR2},
1467 {"mno-dspr2", no_argument, NULL, OPTION_NO_DSPR2},
1468 {"meva", no_argument, NULL, OPTION_EVA},
1469 {"mno-eva", no_argument, NULL, OPTION_NO_EVA},
1470 {"mmicromips", no_argument, NULL, OPTION_MICROMIPS},
1471 {"mno-micromips", no_argument, NULL, OPTION_NO_MICROMIPS},
1472 {"mmcu", no_argument, NULL, OPTION_MCU},
1473 {"mno-mcu", no_argument, NULL, OPTION_NO_MCU},
1474 {"mvirt", no_argument, NULL, OPTION_VIRT},
1475 {"mno-virt", no_argument, NULL, OPTION_NO_VIRT},
1477 /* Old-style architecture options. Don't add more of these. */
1478 {"m4650", no_argument, NULL, OPTION_M4650},
1479 {"no-m4650", no_argument, NULL, OPTION_NO_M4650},
1480 {"m4010", no_argument, NULL, OPTION_M4010},
1481 {"no-m4010", no_argument, NULL, OPTION_NO_M4010},
1482 {"m4100", no_argument, NULL, OPTION_M4100},
1483 {"no-m4100", no_argument, NULL, OPTION_NO_M4100},
1484 {"m3900", no_argument, NULL, OPTION_M3900},
1485 {"no-m3900", no_argument, NULL, OPTION_NO_M3900},
1487 /* Options which enable bug fixes. */
1488 {"mfix7000", no_argument, NULL, OPTION_M7000_HILO_FIX},
1489 {"no-fix-7000", no_argument, NULL, OPTION_MNO_7000_HILO_FIX},
1490 {"mno-fix7000", no_argument, NULL, OPTION_MNO_7000_HILO_FIX},
1491 {"mfix-loongson2f-jump", no_argument, NULL, OPTION_FIX_LOONGSON2F_JUMP},
1492 {"mno-fix-loongson2f-jump", no_argument, NULL, OPTION_NO_FIX_LOONGSON2F_JUMP},
1493 {"mfix-loongson2f-nop", no_argument, NULL, OPTION_FIX_LOONGSON2F_NOP},
1494 {"mno-fix-loongson2f-nop", no_argument, NULL, OPTION_NO_FIX_LOONGSON2F_NOP},
1495 {"mfix-vr4120", no_argument, NULL, OPTION_FIX_VR4120},
1496 {"mno-fix-vr4120", no_argument, NULL, OPTION_NO_FIX_VR4120},
1497 {"mfix-vr4130", no_argument, NULL, OPTION_FIX_VR4130},
1498 {"mno-fix-vr4130", no_argument, NULL, OPTION_NO_FIX_VR4130},
1499 {"mfix-24k", no_argument, NULL, OPTION_FIX_24K},
1500 {"mno-fix-24k", no_argument, NULL, OPTION_NO_FIX_24K},
1501 {"mfix-cn63xxp1", no_argument, NULL, OPTION_FIX_CN63XXP1},
1502 {"mno-fix-cn63xxp1", no_argument, NULL, OPTION_NO_FIX_CN63XXP1},
1504 /* Miscellaneous options. */
1505 {"trap", no_argument, NULL, OPTION_TRAP},
1506 {"no-break", no_argument, NULL, OPTION_TRAP},
1507 {"break", no_argument, NULL, OPTION_BREAK},
1508 {"no-trap", no_argument, NULL, OPTION_BREAK},
1509 {"EB", no_argument, NULL, OPTION_EB},
1510 {"EL", no_argument, NULL, OPTION_EL},
1511 {"mfp32", no_argument, NULL, OPTION_FP32},
1512 {"mgp32", no_argument, NULL, OPTION_GP32},
1513 {"construct-floats", no_argument, NULL, OPTION_CONSTRUCT_FLOATS},
1514 {"no-construct-floats", no_argument, NULL, OPTION_NO_CONSTRUCT_FLOATS},
1515 {"mfp64", no_argument, NULL, OPTION_FP64},
1516 {"mgp64", no_argument, NULL, OPTION_GP64},
1517 {"relax-branch", no_argument, NULL, OPTION_RELAX_BRANCH},
1518 {"no-relax-branch", no_argument, NULL, OPTION_NO_RELAX_BRANCH},
1519 {"mshared", no_argument, NULL, OPTION_MSHARED},
1520 {"mno-shared", no_argument, NULL, OPTION_MNO_SHARED},
1521 {"msym32", no_argument, NULL, OPTION_MSYM32},
1522 {"mno-sym32", no_argument, NULL, OPTION_MNO_SYM32},
1523 {"msoft-float", no_argument, NULL, OPTION_SOFT_FLOAT},
1524 {"mhard-float", no_argument, NULL, OPTION_HARD_FLOAT},
1525 {"msingle-float", no_argument, NULL, OPTION_SINGLE_FLOAT},
1526 {"mdouble-float", no_argument, NULL, OPTION_DOUBLE_FLOAT},
1528 /* Strictly speaking this next option is ELF specific,
1529 but we allow it for other ports as well in order to
1530 make testing easier. */
1531 {"32", no_argument, NULL, OPTION_32},
1533 /* ELF-specific options. */
1534 {"KPIC", no_argument, NULL, OPTION_CALL_SHARED},
1535 {"call_shared", no_argument, NULL, OPTION_CALL_SHARED},
1536 {"call_nonpic", no_argument, NULL, OPTION_CALL_NONPIC},
1537 {"non_shared", no_argument, NULL, OPTION_NON_SHARED},
1538 {"xgot", no_argument, NULL, OPTION_XGOT},
1539 {"mabi", required_argument, NULL, OPTION_MABI},
1540 {"n32", no_argument, NULL, OPTION_N32},
1541 {"64", no_argument, NULL, OPTION_64},
1542 {"mdebug", no_argument, NULL, OPTION_MDEBUG},
1543 {"no-mdebug", no_argument, NULL, OPTION_NO_MDEBUG},
1544 {"mpdr", no_argument, NULL, OPTION_PDR},
1545 {"mno-pdr", no_argument, NULL, OPTION_NO_PDR},
1546 {"mvxworks-pic", no_argument, NULL, OPTION_MVXWORKS_PIC},
1548 {NULL, no_argument, NULL, 0}
1550 size_t md_longopts_size = sizeof (md_longopts);
1552 /* Information about either an Application Specific Extension or an
1553 optional architecture feature that, for simplicity, we treat in the
1554 same way as an ASE. */
1557 /* The name of the ASE, used in both the command-line and .set options. */
1560 /* The associated ASE_* flags. If the ASE is available on both 32-bit
1561 and 64-bit architectures, the flags here refer to the subset that
1562 is available on both. */
1565 /* The ASE_* flag used for instructions that are available on 64-bit
1566 architectures but that are not included in FLAGS. */
1567 unsigned int flags64;
1569 /* The command-line options that turn the ASE on and off. */
1573 /* The minimum required architecture revisions for MIPS32, MIPS64,
1574 microMIPS32 and microMIPS64, or -1 if the extension isn't supported. */
1577 int micromips32_rev;
1578 int micromips64_rev;
1581 /* A table of all supported ASEs. */
1582 static const struct mips_ase mips_ases[] = {
1583 { "dsp", ASE_DSP, ASE_DSP64,
1584 OPTION_DSP, OPTION_NO_DSP,
1587 { "dspr2", ASE_DSP | ASE_DSPR2, 0,
1588 OPTION_DSPR2, OPTION_NO_DSPR2,
1591 { "eva", ASE_EVA, 0,
1592 OPTION_EVA, OPTION_NO_EVA,
1595 { "mcu", ASE_MCU, 0,
1596 OPTION_MCU, OPTION_NO_MCU,
1599 /* Deprecated in MIPS64r5, but we don't implement that yet. */
1600 { "mdmx", ASE_MDMX, 0,
1601 OPTION_MDMX, OPTION_NO_MDMX,
1604 /* Requires 64-bit FPRs, so the minimum MIPS32 revision is 2. */
1605 { "mips3d", ASE_MIPS3D, 0,
1606 OPTION_MIPS3D, OPTION_NO_MIPS3D,
1610 OPTION_MT, OPTION_NO_MT,
1613 { "smartmips", ASE_SMARTMIPS, 0,
1614 OPTION_SMARTMIPS, OPTION_NO_SMARTMIPS,
1617 { "virt", ASE_VIRT, ASE_VIRT64,
1618 OPTION_VIRT, OPTION_NO_VIRT,
1622 /* The set of ASEs that require -mfp64. */
1623 #define FP64_ASES (ASE_MIPS3D | ASE_MDMX)
1625 /* Groups of ASE_* flags that represent different revisions of an ASE. */
1626 static const unsigned int mips_ase_groups[] = {
1632 The following pseudo-ops from the Kane and Heinrich MIPS book
1633 should be defined here, but are currently unsupported: .alias,
1634 .galive, .gjaldef, .gjrlive, .livereg, .noalias.
1636 The following pseudo-ops from the Kane and Heinrich MIPS book are
1637 specific to the type of debugging information being generated, and
1638 should be defined by the object format: .aent, .begin, .bend,
1639 .bgnb, .end, .endb, .ent, .fmask, .frame, .loc, .mask, .verstamp,
1642 The following pseudo-ops from the Kane and Heinrich MIPS book are
1643 not MIPS CPU specific, but are also not specific to the object file
1644 format. This file is probably the best place to define them, but
1645 they are not currently supported: .asm0, .endr, .lab, .struct. */
1647 static const pseudo_typeS mips_pseudo_table[] =
1649 /* MIPS specific pseudo-ops. */
1650 {"option", s_option, 0},
1651 {"set", s_mipsset, 0},
1652 {"rdata", s_change_sec, 'r'},
1653 {"sdata", s_change_sec, 's'},
1654 {"livereg", s_ignore, 0},
1655 {"abicalls", s_abicalls, 0},
1656 {"cpload", s_cpload, 0},
1657 {"cpsetup", s_cpsetup, 0},
1658 {"cplocal", s_cplocal, 0},
1659 {"cprestore", s_cprestore, 0},
1660 {"cpreturn", s_cpreturn, 0},
1661 {"dtprelword", s_dtprelword, 0},
1662 {"dtpreldword", s_dtpreldword, 0},
1663 {"tprelword", s_tprelword, 0},
1664 {"tpreldword", s_tpreldword, 0},
1665 {"gpvalue", s_gpvalue, 0},
1666 {"gpword", s_gpword, 0},
1667 {"gpdword", s_gpdword, 0},
1668 {"ehword", s_ehword, 0},
1669 {"cpadd", s_cpadd, 0},
1670 {"insn", s_insn, 0},
1672 /* Relatively generic pseudo-ops that happen to be used on MIPS
1674 {"asciiz", stringer, 8 + 1},
1675 {"bss", s_change_sec, 'b'},
1677 {"half", s_cons, 1},
1678 {"dword", s_cons, 3},
1679 {"weakext", s_mips_weakext, 0},
1680 {"origin", s_org, 0},
1681 {"repeat", s_rept, 0},
1683 /* For MIPS this is non-standard, but we define it for consistency. */
1684 {"sbss", s_change_sec, 'B'},
1686 /* These pseudo-ops are defined in read.c, but must be overridden
1687 here for one reason or another. */
1688 {"align", s_align, 0},
1689 {"byte", s_cons, 0},
1690 {"data", s_change_sec, 'd'},
1691 {"double", s_float_cons, 'd'},
1692 {"float", s_float_cons, 'f'},
1693 {"globl", s_mips_globl, 0},
1694 {"global", s_mips_globl, 0},
1695 {"hword", s_cons, 1},
1697 {"long", s_cons, 2},
1698 {"octa", s_cons, 4},
1699 {"quad", s_cons, 3},
1700 {"section", s_change_section, 0},
1701 {"short", s_cons, 1},
1702 {"single", s_float_cons, 'f'},
1703 {"stabd", s_mips_stab, 'd'},
1704 {"stabn", s_mips_stab, 'n'},
1705 {"stabs", s_mips_stab, 's'},
1706 {"text", s_change_sec, 't'},
1707 {"word", s_cons, 2},
1709 { "extern", ecoff_directive_extern, 0},
1714 static const pseudo_typeS mips_nonecoff_pseudo_table[] =
1716 /* These pseudo-ops should be defined by the object file format.
1717 However, a.out doesn't support them, so we have versions here. */
1718 {"aent", s_mips_ent, 1},
1719 {"bgnb", s_ignore, 0},
1720 {"end", s_mips_end, 0},
1721 {"endb", s_ignore, 0},
1722 {"ent", s_mips_ent, 0},
1723 {"file", s_mips_file, 0},
1724 {"fmask", s_mips_mask, 'F'},
1725 {"frame", s_mips_frame, 0},
1726 {"loc", s_mips_loc, 0},
1727 {"mask", s_mips_mask, 'R'},
1728 {"verstamp", s_ignore, 0},
1732 /* Export the ABI address size for use by TC_ADDRESS_BYTES for the
1733 purpose of the `.dc.a' internal pseudo-op. */
1736 mips_address_bytes (void)
1738 return HAVE_64BIT_ADDRESSES ? 8 : 4;
1741 extern void pop_insert (const pseudo_typeS *);
1744 mips_pop_insert (void)
1746 pop_insert (mips_pseudo_table);
1747 if (! ECOFF_DEBUGGING)
1748 pop_insert (mips_nonecoff_pseudo_table);
1751 /* Symbols labelling the current insn. */
1753 struct insn_label_list
1755 struct insn_label_list *next;
1759 static struct insn_label_list *free_insn_labels;
1760 #define label_list tc_segment_info_data.labels
1762 static void mips_clear_insn_labels (void);
1763 static void mips_mark_labels (void);
1764 static void mips_compressed_mark_labels (void);
1767 mips_clear_insn_labels (void)
1769 register struct insn_label_list **pl;
1770 segment_info_type *si;
1774 for (pl = &free_insn_labels; *pl != NULL; pl = &(*pl)->next)
1777 si = seg_info (now_seg);
1778 *pl = si->label_list;
1779 si->label_list = NULL;
1783 /* Mark instruction labels in MIPS16/microMIPS mode. */
1786 mips_mark_labels (void)
1788 if (HAVE_CODE_COMPRESSION)
1789 mips_compressed_mark_labels ();
1792 static char *expr_end;
1794 /* Expressions which appear in instructions. These are set by
1797 static expressionS imm_expr;
1798 static expressionS imm2_expr;
1799 static expressionS offset_expr;
1801 /* Relocs associated with imm_expr and offset_expr. */
1803 static bfd_reloc_code_real_type imm_reloc[3]
1804 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
1805 static bfd_reloc_code_real_type offset_reloc[3]
1806 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
1808 /* This is set to the resulting size of the instruction to be produced
1809 by mips16_ip if an explicit extension is used or by mips_ip if an
1810 explicit size is supplied. */
1812 static unsigned int forced_insn_length;
1814 /* True if we are assembling an instruction. All dot symbols defined during
1815 this time should be treated as code labels. */
1817 static bfd_boolean mips_assembling_insn;
1819 /* The pdr segment for per procedure frame/regmask info. Not used for
1822 static segT pdr_seg;
1824 /* The default target format to use. */
1826 #if defined (TE_FreeBSD)
1827 #define ELF_TARGET(PREFIX, ENDIAN) PREFIX "trad" ENDIAN "mips-freebsd"
1828 #elif defined (TE_TMIPS)
1829 #define ELF_TARGET(PREFIX, ENDIAN) PREFIX "trad" ENDIAN "mips"
1831 #define ELF_TARGET(PREFIX, ENDIAN) PREFIX ENDIAN "mips"
1835 mips_target_format (void)
1837 switch (OUTPUT_FLAVOR)
1839 case bfd_target_elf_flavour:
1841 if (!HAVE_64BIT_OBJECTS && !HAVE_NEWABI)
1842 return (target_big_endian
1843 ? "elf32-bigmips-vxworks"
1844 : "elf32-littlemips-vxworks");
1846 return (target_big_endian
1847 ? (HAVE_64BIT_OBJECTS
1848 ? ELF_TARGET ("elf64-", "big")
1850 ? ELF_TARGET ("elf32-n", "big")
1851 : ELF_TARGET ("elf32-", "big")))
1852 : (HAVE_64BIT_OBJECTS
1853 ? ELF_TARGET ("elf64-", "little")
1855 ? ELF_TARGET ("elf32-n", "little")
1856 : ELF_TARGET ("elf32-", "little"))));
1863 /* Return the ISA revision that is currently in use, or 0 if we are
1864 generating code for MIPS V or below. */
1869 if (mips_opts.isa == ISA_MIPS32R2 || mips_opts.isa == ISA_MIPS64R2)
1872 /* microMIPS implies revision 2 or above. */
1873 if (mips_opts.micromips)
1876 if (mips_opts.isa == ISA_MIPS32 || mips_opts.isa == ISA_MIPS64)
1882 /* Return the mask of all ASEs that are revisions of those in FLAGS. */
1885 mips_ase_mask (unsigned int flags)
1889 for (i = 0; i < ARRAY_SIZE (mips_ase_groups); i++)
1890 if (flags & mips_ase_groups[i])
1891 flags |= mips_ase_groups[i];
1895 /* Check whether the current ISA supports ASE. Issue a warning if
1899 mips_check_isa_supports_ase (const struct mips_ase *ase)
1903 static unsigned int warned_isa;
1904 static unsigned int warned_fp32;
1906 if (ISA_HAS_64BIT_REGS (mips_opts.isa))
1907 min_rev = mips_opts.micromips ? ase->micromips64_rev : ase->mips64_rev;
1909 min_rev = mips_opts.micromips ? ase->micromips32_rev : ase->mips32_rev;
1910 if ((min_rev < 0 || mips_isa_rev () < min_rev)
1911 && (warned_isa & ase->flags) != ase->flags)
1913 warned_isa |= ase->flags;
1914 base = mips_opts.micromips ? "microMIPS" : "MIPS";
1915 size = ISA_HAS_64BIT_REGS (mips_opts.isa) ? 64 : 32;
1917 as_warn (_("The %d-bit %s architecture does not support the"
1918 " `%s' extension"), size, base, ase->name);
1920 as_warn (_("The `%s' extension requires %s%d revision %d or greater"),
1921 ase->name, base, size, min_rev);
1923 if ((ase->flags & FP64_ASES)
1925 && (warned_fp32 & ase->flags) != ase->flags)
1927 warned_fp32 |= ase->flags;
1928 as_warn (_("The `%s' extension requires 64-bit FPRs"), ase->name);
1932 /* Check all enabled ASEs to see whether they are supported by the
1933 chosen architecture. */
1936 mips_check_isa_supports_ases (void)
1938 unsigned int i, mask;
1940 for (i = 0; i < ARRAY_SIZE (mips_ases); i++)
1942 mask = mips_ase_mask (mips_ases[i].flags);
1943 if ((mips_opts.ase & mask) == mips_ases[i].flags)
1944 mips_check_isa_supports_ase (&mips_ases[i]);
1948 /* Set the state of ASE to ENABLED_P. Return the mask of ASE_* flags
1949 that were affected. */
1952 mips_set_ase (const struct mips_ase *ase, bfd_boolean enabled_p)
1956 mask = mips_ase_mask (ase->flags);
1957 mips_opts.ase &= ~mask;
1959 mips_opts.ase |= ase->flags;
1963 /* Return the ASE called NAME, or null if none. */
1965 static const struct mips_ase *
1966 mips_lookup_ase (const char *name)
1970 for (i = 0; i < ARRAY_SIZE (mips_ases); i++)
1971 if (strcmp (name, mips_ases[i].name) == 0)
1972 return &mips_ases[i];
1976 /* Return the length of a microMIPS instruction in bytes. If bits of
1977 the mask beyond the low 16 are 0, then it is a 16-bit instruction.
1978 Otherwise assume a 32-bit instruction; 48-bit instructions (0x1f
1979 major opcode) will require further modifications to the opcode
1982 static inline unsigned int
1983 micromips_insn_length (const struct mips_opcode *mo)
1985 return (mo->mask >> 16) == 0 ? 2 : 4;
1988 /* Return the length of MIPS16 instruction OPCODE. */
1990 static inline unsigned int
1991 mips16_opcode_length (unsigned long opcode)
1993 return (opcode >> 16) == 0 ? 2 : 4;
1996 /* Return the length of instruction INSN. */
1998 static inline unsigned int
1999 insn_length (const struct mips_cl_insn *insn)
2001 if (mips_opts.micromips)
2002 return micromips_insn_length (insn->insn_mo);
2003 else if (mips_opts.mips16)
2004 return mips16_opcode_length (insn->insn_opcode);
2009 /* Initialise INSN from opcode entry MO. Leave its position unspecified. */
2012 create_insn (struct mips_cl_insn *insn, const struct mips_opcode *mo)
2017 insn->insn_opcode = mo->match;
2020 for (i = 0; i < ARRAY_SIZE (insn->fixp); i++)
2021 insn->fixp[i] = NULL;
2022 insn->fixed_p = (mips_opts.noreorder > 0);
2023 insn->noreorder_p = (mips_opts.noreorder > 0);
2024 insn->mips16_absolute_jump_p = 0;
2025 insn->complete_p = 0;
2026 insn->cleared_p = 0;
2029 /* Record the current MIPS16/microMIPS mode in now_seg. */
2032 mips_record_compressed_mode (void)
2034 segment_info_type *si;
2036 si = seg_info (now_seg);
2037 if (si->tc_segment_info_data.mips16 != mips_opts.mips16)
2038 si->tc_segment_info_data.mips16 = mips_opts.mips16;
2039 if (si->tc_segment_info_data.micromips != mips_opts.micromips)
2040 si->tc_segment_info_data.micromips = mips_opts.micromips;
2043 /* Read a standard MIPS instruction from BUF. */
2045 static unsigned long
2046 read_insn (char *buf)
2048 if (target_big_endian)
2049 return bfd_getb32 ((bfd_byte *) buf);
2051 return bfd_getl32 ((bfd_byte *) buf);
2054 /* Write standard MIPS instruction INSN to BUF. Return a pointer to
2058 write_insn (char *buf, unsigned int insn)
2060 md_number_to_chars (buf, insn, 4);
2064 /* Read a microMIPS or MIPS16 opcode from BUF, given that it
2065 has length LENGTH. */
2067 static unsigned long
2068 read_compressed_insn (char *buf, unsigned int length)
2074 for (i = 0; i < length; i += 2)
2077 if (target_big_endian)
2078 insn |= bfd_getb16 ((char *) buf);
2080 insn |= bfd_getl16 ((char *) buf);
2086 /* Write microMIPS or MIPS16 instruction INSN to BUF, given that the
2087 instruction is LENGTH bytes long. Return a pointer to the next byte. */
2090 write_compressed_insn (char *buf, unsigned int insn, unsigned int length)
2094 for (i = 0; i < length; i += 2)
2095 md_number_to_chars (buf + i, insn >> ((length - i - 2) * 8), 2);
2096 return buf + length;
2099 /* Install INSN at the location specified by its "frag" and "where" fields. */
2102 install_insn (const struct mips_cl_insn *insn)
2104 char *f = insn->frag->fr_literal + insn->where;
2105 if (HAVE_CODE_COMPRESSION)
2106 write_compressed_insn (f, insn->insn_opcode, insn_length (insn));
2108 write_insn (f, insn->insn_opcode);
2109 mips_record_compressed_mode ();
2112 /* Move INSN to offset WHERE in FRAG. Adjust the fixups accordingly
2113 and install the opcode in the new location. */
2116 move_insn (struct mips_cl_insn *insn, fragS *frag, long where)
2121 insn->where = where;
2122 for (i = 0; i < ARRAY_SIZE (insn->fixp); i++)
2123 if (insn->fixp[i] != NULL)
2125 insn->fixp[i]->fx_frag = frag;
2126 insn->fixp[i]->fx_where = where;
2128 install_insn (insn);
2131 /* Add INSN to the end of the output. */
2134 add_fixed_insn (struct mips_cl_insn *insn)
2136 char *f = frag_more (insn_length (insn));
2137 move_insn (insn, frag_now, f - frag_now->fr_literal);
2140 /* Start a variant frag and move INSN to the start of the variant part,
2141 marking it as fixed. The other arguments are as for frag_var. */
2144 add_relaxed_insn (struct mips_cl_insn *insn, int max_chars, int var,
2145 relax_substateT subtype, symbolS *symbol, offsetT offset)
2147 frag_grow (max_chars);
2148 move_insn (insn, frag_now, frag_more (0) - frag_now->fr_literal);
2150 frag_var (rs_machine_dependent, max_chars, var,
2151 subtype, symbol, offset, NULL);
2154 /* Insert N copies of INSN into the history buffer, starting at
2155 position FIRST. Neither FIRST nor N need to be clipped. */
2158 insert_into_history (unsigned int first, unsigned int n,
2159 const struct mips_cl_insn *insn)
2161 if (mips_relax.sequence != 2)
2165 for (i = ARRAY_SIZE (history); i-- > first;)
2167 history[i] = history[i - n];
2173 /* Initialize vr4120_conflicts. There is a bit of duplication here:
2174 the idea is to make it obvious at a glance that each errata is
2178 init_vr4120_conflicts (void)
2180 #define CONFLICT(FIRST, SECOND) \
2181 vr4120_conflicts[FIX_VR4120_##FIRST] |= 1 << FIX_VR4120_##SECOND
2183 /* Errata 21 - [D]DIV[U] after [D]MACC */
2184 CONFLICT (MACC, DIV);
2185 CONFLICT (DMACC, DIV);
2187 /* Errata 23 - Continuous DMULT[U]/DMACC instructions. */
2188 CONFLICT (DMULT, DMULT);
2189 CONFLICT (DMULT, DMACC);
2190 CONFLICT (DMACC, DMULT);
2191 CONFLICT (DMACC, DMACC);
2193 /* Errata 24 - MT{LO,HI} after [D]MACC */
2194 CONFLICT (MACC, MTHILO);
2195 CONFLICT (DMACC, MTHILO);
2197 /* VR4181A errata MD(1): "If a MULT, MULTU, DMULT or DMULTU
2198 instruction is executed immediately after a MACC or DMACC
2199 instruction, the result of [either instruction] is incorrect." */
2200 CONFLICT (MACC, MULT);
2201 CONFLICT (MACC, DMULT);
2202 CONFLICT (DMACC, MULT);
2203 CONFLICT (DMACC, DMULT);
2205 /* VR4181A errata MD(4): "If a MACC or DMACC instruction is
2206 executed immediately after a DMULT, DMULTU, DIV, DIVU,
2207 DDIV or DDIVU instruction, the result of the MACC or
2208 DMACC instruction is incorrect.". */
2209 CONFLICT (DMULT, MACC);
2210 CONFLICT (DMULT, DMACC);
2211 CONFLICT (DIV, MACC);
2212 CONFLICT (DIV, DMACC);
2222 #define RTYPE_MASK 0x1ff00
2223 #define RTYPE_NUM 0x00100
2224 #define RTYPE_FPU 0x00200
2225 #define RTYPE_FCC 0x00400
2226 #define RTYPE_VEC 0x00800
2227 #define RTYPE_GP 0x01000
2228 #define RTYPE_CP0 0x02000
2229 #define RTYPE_PC 0x04000
2230 #define RTYPE_ACC 0x08000
2231 #define RTYPE_CCC 0x10000
2232 #define RNUM_MASK 0x000ff
2233 #define RWARN 0x80000
2235 #define GENERIC_REGISTER_NUMBERS \
2236 {"$0", RTYPE_NUM | 0}, \
2237 {"$1", RTYPE_NUM | 1}, \
2238 {"$2", RTYPE_NUM | 2}, \
2239 {"$3", RTYPE_NUM | 3}, \
2240 {"$4", RTYPE_NUM | 4}, \
2241 {"$5", RTYPE_NUM | 5}, \
2242 {"$6", RTYPE_NUM | 6}, \
2243 {"$7", RTYPE_NUM | 7}, \
2244 {"$8", RTYPE_NUM | 8}, \
2245 {"$9", RTYPE_NUM | 9}, \
2246 {"$10", RTYPE_NUM | 10}, \
2247 {"$11", RTYPE_NUM | 11}, \
2248 {"$12", RTYPE_NUM | 12}, \
2249 {"$13", RTYPE_NUM | 13}, \
2250 {"$14", RTYPE_NUM | 14}, \
2251 {"$15", RTYPE_NUM | 15}, \
2252 {"$16", RTYPE_NUM | 16}, \
2253 {"$17", RTYPE_NUM | 17}, \
2254 {"$18", RTYPE_NUM | 18}, \
2255 {"$19", RTYPE_NUM | 19}, \
2256 {"$20", RTYPE_NUM | 20}, \
2257 {"$21", RTYPE_NUM | 21}, \
2258 {"$22", RTYPE_NUM | 22}, \
2259 {"$23", RTYPE_NUM | 23}, \
2260 {"$24", RTYPE_NUM | 24}, \
2261 {"$25", RTYPE_NUM | 25}, \
2262 {"$26", RTYPE_NUM | 26}, \
2263 {"$27", RTYPE_NUM | 27}, \
2264 {"$28", RTYPE_NUM | 28}, \
2265 {"$29", RTYPE_NUM | 29}, \
2266 {"$30", RTYPE_NUM | 30}, \
2267 {"$31", RTYPE_NUM | 31}
2269 #define FPU_REGISTER_NAMES \
2270 {"$f0", RTYPE_FPU | 0}, \
2271 {"$f1", RTYPE_FPU | 1}, \
2272 {"$f2", RTYPE_FPU | 2}, \
2273 {"$f3", RTYPE_FPU | 3}, \
2274 {"$f4", RTYPE_FPU | 4}, \
2275 {"$f5", RTYPE_FPU | 5}, \
2276 {"$f6", RTYPE_FPU | 6}, \
2277 {"$f7", RTYPE_FPU | 7}, \
2278 {"$f8", RTYPE_FPU | 8}, \
2279 {"$f9", RTYPE_FPU | 9}, \
2280 {"$f10", RTYPE_FPU | 10}, \
2281 {"$f11", RTYPE_FPU | 11}, \
2282 {"$f12", RTYPE_FPU | 12}, \
2283 {"$f13", RTYPE_FPU | 13}, \
2284 {"$f14", RTYPE_FPU | 14}, \
2285 {"$f15", RTYPE_FPU | 15}, \
2286 {"$f16", RTYPE_FPU | 16}, \
2287 {"$f17", RTYPE_FPU | 17}, \
2288 {"$f18", RTYPE_FPU | 18}, \
2289 {"$f19", RTYPE_FPU | 19}, \
2290 {"$f20", RTYPE_FPU | 20}, \
2291 {"$f21", RTYPE_FPU | 21}, \
2292 {"$f22", RTYPE_FPU | 22}, \
2293 {"$f23", RTYPE_FPU | 23}, \
2294 {"$f24", RTYPE_FPU | 24}, \
2295 {"$f25", RTYPE_FPU | 25}, \
2296 {"$f26", RTYPE_FPU | 26}, \
2297 {"$f27", RTYPE_FPU | 27}, \
2298 {"$f28", RTYPE_FPU | 28}, \
2299 {"$f29", RTYPE_FPU | 29}, \
2300 {"$f30", RTYPE_FPU | 30}, \
2301 {"$f31", RTYPE_FPU | 31}
2303 #define FPU_CONDITION_CODE_NAMES \
2304 {"$fcc0", RTYPE_FCC | 0}, \
2305 {"$fcc1", RTYPE_FCC | 1}, \
2306 {"$fcc2", RTYPE_FCC | 2}, \
2307 {"$fcc3", RTYPE_FCC | 3}, \
2308 {"$fcc4", RTYPE_FCC | 4}, \
2309 {"$fcc5", RTYPE_FCC | 5}, \
2310 {"$fcc6", RTYPE_FCC | 6}, \
2311 {"$fcc7", RTYPE_FCC | 7}
2313 #define COPROC_CONDITION_CODE_NAMES \
2314 {"$cc0", RTYPE_FCC | RTYPE_CCC | 0}, \
2315 {"$cc1", RTYPE_FCC | RTYPE_CCC | 1}, \
2316 {"$cc2", RTYPE_FCC | RTYPE_CCC | 2}, \
2317 {"$cc3", RTYPE_FCC | RTYPE_CCC | 3}, \
2318 {"$cc4", RTYPE_FCC | RTYPE_CCC | 4}, \
2319 {"$cc5", RTYPE_FCC | RTYPE_CCC | 5}, \
2320 {"$cc6", RTYPE_FCC | RTYPE_CCC | 6}, \
2321 {"$cc7", RTYPE_FCC | RTYPE_CCC | 7}
2323 #define N32N64_SYMBOLIC_REGISTER_NAMES \
2324 {"$a4", RTYPE_GP | 8}, \
2325 {"$a5", RTYPE_GP | 9}, \
2326 {"$a6", RTYPE_GP | 10}, \
2327 {"$a7", RTYPE_GP | 11}, \
2328 {"$ta0", RTYPE_GP | 8}, /* alias for $a4 */ \
2329 {"$ta1", RTYPE_GP | 9}, /* alias for $a5 */ \
2330 {"$ta2", RTYPE_GP | 10}, /* alias for $a6 */ \
2331 {"$ta3", RTYPE_GP | 11}, /* alias for $a7 */ \
2332 {"$t0", RTYPE_GP | 12}, \
2333 {"$t1", RTYPE_GP | 13}, \
2334 {"$t2", RTYPE_GP | 14}, \
2335 {"$t3", RTYPE_GP | 15}
2337 #define O32_SYMBOLIC_REGISTER_NAMES \
2338 {"$t0", RTYPE_GP | 8}, \
2339 {"$t1", RTYPE_GP | 9}, \
2340 {"$t2", RTYPE_GP | 10}, \
2341 {"$t3", RTYPE_GP | 11}, \
2342 {"$t4", RTYPE_GP | 12}, \
2343 {"$t5", RTYPE_GP | 13}, \
2344 {"$t6", RTYPE_GP | 14}, \
2345 {"$t7", RTYPE_GP | 15}, \
2346 {"$ta0", RTYPE_GP | 12}, /* alias for $t4 */ \
2347 {"$ta1", RTYPE_GP | 13}, /* alias for $t5 */ \
2348 {"$ta2", RTYPE_GP | 14}, /* alias for $t6 */ \
2349 {"$ta3", RTYPE_GP | 15} /* alias for $t7 */
2351 /* Remaining symbolic register names */
2352 #define SYMBOLIC_REGISTER_NAMES \
2353 {"$zero", RTYPE_GP | 0}, \
2354 {"$at", RTYPE_GP | 1}, \
2355 {"$AT", RTYPE_GP | 1}, \
2356 {"$v0", RTYPE_GP | 2}, \
2357 {"$v1", RTYPE_GP | 3}, \
2358 {"$a0", RTYPE_GP | 4}, \
2359 {"$a1", RTYPE_GP | 5}, \
2360 {"$a2", RTYPE_GP | 6}, \
2361 {"$a3", RTYPE_GP | 7}, \
2362 {"$s0", RTYPE_GP | 16}, \
2363 {"$s1", RTYPE_GP | 17}, \
2364 {"$s2", RTYPE_GP | 18}, \
2365 {"$s3", RTYPE_GP | 19}, \
2366 {"$s4", RTYPE_GP | 20}, \
2367 {"$s5", RTYPE_GP | 21}, \
2368 {"$s6", RTYPE_GP | 22}, \
2369 {"$s7", RTYPE_GP | 23}, \
2370 {"$t8", RTYPE_GP | 24}, \
2371 {"$t9", RTYPE_GP | 25}, \
2372 {"$k0", RTYPE_GP | 26}, \
2373 {"$kt0", RTYPE_GP | 26}, \
2374 {"$k1", RTYPE_GP | 27}, \
2375 {"$kt1", RTYPE_GP | 27}, \
2376 {"$gp", RTYPE_GP | 28}, \
2377 {"$sp", RTYPE_GP | 29}, \
2378 {"$s8", RTYPE_GP | 30}, \
2379 {"$fp", RTYPE_GP | 30}, \
2380 {"$ra", RTYPE_GP | 31}
2382 #define MIPS16_SPECIAL_REGISTER_NAMES \
2383 {"$pc", RTYPE_PC | 0}
2385 #define MDMX_VECTOR_REGISTER_NAMES \
2386 /* {"$v0", RTYPE_VEC | 0}, clash with REG 2 above */ \
2387 /* {"$v1", RTYPE_VEC | 1}, clash with REG 3 above */ \
2388 {"$v2", RTYPE_VEC | 2}, \
2389 {"$v3", RTYPE_VEC | 3}, \
2390 {"$v4", RTYPE_VEC | 4}, \
2391 {"$v5", RTYPE_VEC | 5}, \
2392 {"$v6", RTYPE_VEC | 6}, \
2393 {"$v7", RTYPE_VEC | 7}, \
2394 {"$v8", RTYPE_VEC | 8}, \
2395 {"$v9", RTYPE_VEC | 9}, \
2396 {"$v10", RTYPE_VEC | 10}, \
2397 {"$v11", RTYPE_VEC | 11}, \
2398 {"$v12", RTYPE_VEC | 12}, \
2399 {"$v13", RTYPE_VEC | 13}, \
2400 {"$v14", RTYPE_VEC | 14}, \
2401 {"$v15", RTYPE_VEC | 15}, \
2402 {"$v16", RTYPE_VEC | 16}, \
2403 {"$v17", RTYPE_VEC | 17}, \
2404 {"$v18", RTYPE_VEC | 18}, \
2405 {"$v19", RTYPE_VEC | 19}, \
2406 {"$v20", RTYPE_VEC | 20}, \
2407 {"$v21", RTYPE_VEC | 21}, \
2408 {"$v22", RTYPE_VEC | 22}, \
2409 {"$v23", RTYPE_VEC | 23}, \
2410 {"$v24", RTYPE_VEC | 24}, \
2411 {"$v25", RTYPE_VEC | 25}, \
2412 {"$v26", RTYPE_VEC | 26}, \
2413 {"$v27", RTYPE_VEC | 27}, \
2414 {"$v28", RTYPE_VEC | 28}, \
2415 {"$v29", RTYPE_VEC | 29}, \
2416 {"$v30", RTYPE_VEC | 30}, \
2417 {"$v31", RTYPE_VEC | 31}
2419 #define MIPS_DSP_ACCUMULATOR_NAMES \
2420 {"$ac0", RTYPE_ACC | 0}, \
2421 {"$ac1", RTYPE_ACC | 1}, \
2422 {"$ac2", RTYPE_ACC | 2}, \
2423 {"$ac3", RTYPE_ACC | 3}
2425 static const struct regname reg_names[] = {
2426 GENERIC_REGISTER_NUMBERS,
2428 FPU_CONDITION_CODE_NAMES,
2429 COPROC_CONDITION_CODE_NAMES,
2431 /* The $txx registers depends on the abi,
2432 these will be added later into the symbol table from
2433 one of the tables below once mips_abi is set after
2434 parsing of arguments from the command line. */
2435 SYMBOLIC_REGISTER_NAMES,
2437 MIPS16_SPECIAL_REGISTER_NAMES,
2438 MDMX_VECTOR_REGISTER_NAMES,
2439 MIPS_DSP_ACCUMULATOR_NAMES,
2443 static const struct regname reg_names_o32[] = {
2444 O32_SYMBOLIC_REGISTER_NAMES,
2448 static const struct regname reg_names_n32n64[] = {
2449 N32N64_SYMBOLIC_REGISTER_NAMES,
2453 /* Check if S points at a valid register specifier according to TYPES.
2454 If so, then return 1, advance S to consume the specifier and store
2455 the register's number in REGNOP, otherwise return 0. */
2458 reg_lookup (char **s, unsigned int types, unsigned int *regnop)
2465 /* Find end of name. */
2467 if (is_name_beginner (*e))
2469 while (is_part_of_name (*e))
2472 /* Terminate name. */
2476 /* Look for a register symbol. */
2477 if ((symbolP = symbol_find (*s)) && S_GET_SEGMENT (symbolP) == reg_section)
2479 int r = S_GET_VALUE (symbolP);
2481 reg = r & RNUM_MASK;
2482 else if ((types & RTYPE_VEC) && (r & ~1) == (RTYPE_GP | 2))
2483 /* Convert GP reg $v0/1 to MDMX reg $v0/1! */
2484 reg = (r & RNUM_MASK) - 2;
2486 /* Else see if this is a register defined in an itbl entry. */
2487 else if ((types & RTYPE_GP) && itbl_have_entries)
2494 if (itbl_get_reg_val (n, &r))
2495 reg = r & RNUM_MASK;
2498 /* Advance to next token if a register was recognised. */
2501 else if (types & RWARN)
2502 as_warn (_("Unrecognized register name `%s'"), *s);
2510 /* Check if S points at a valid register list according to TYPES.
2511 If so, then return 1, advance S to consume the list and store
2512 the registers present on the list as a bitmask of ones in REGLISTP,
2513 otherwise return 0. A valid list comprises a comma-separated
2514 enumeration of valid single registers and/or dash-separated
2515 contiguous register ranges as determined by their numbers.
2517 As a special exception if one of s0-s7 registers is specified as
2518 the range's lower delimiter and s8 (fp) is its upper one, then no
2519 registers whose numbers place them between s7 and s8 (i.e. $24-$29)
2520 are selected; they have to be listed separately if needed. */
2523 reglist_lookup (char **s, unsigned int types, unsigned int *reglistp)
2525 unsigned int reglist = 0;
2526 unsigned int lastregno;
2527 bfd_boolean ok = TRUE;
2528 unsigned int regmask;
2529 char *s_endlist = *s;
2533 while (reg_lookup (s, types, ®no))
2539 ok = reg_lookup (s, types, &lastregno);
2540 if (ok && lastregno < regno)
2546 if (lastregno == FP && regno >= S0 && regno <= S7)
2551 regmask = 1 << lastregno;
2552 regmask = (regmask << 1) - 1;
2553 regmask ^= (1 << regno) - 1;
2567 *reglistp = reglist;
2568 return ok && reglist != 0;
2571 /* Return TRUE if opcode MO is valid on the currently selected ISA, ASE
2572 and architecture. Use is_opcode_valid_16 for MIPS16 opcodes. */
2575 is_opcode_valid (const struct mips_opcode *mo)
2577 int isa = mips_opts.isa;
2578 int ase = mips_opts.ase;
2582 if (ISA_HAS_64BIT_REGS (mips_opts.isa))
2583 for (i = 0; i < ARRAY_SIZE (mips_ases); i++)
2584 if ((ase & mips_ases[i].flags) == mips_ases[i].flags)
2585 ase |= mips_ases[i].flags64;
2587 if (!opcode_is_member (mo, isa, ase, mips_opts.arch))
2590 /* Check whether the instruction or macro requires single-precision or
2591 double-precision floating-point support. Note that this information is
2592 stored differently in the opcode table for insns and macros. */
2593 if (mo->pinfo == INSN_MACRO)
2595 fp_s = mo->pinfo2 & INSN2_M_FP_S;
2596 fp_d = mo->pinfo2 & INSN2_M_FP_D;
2600 fp_s = mo->pinfo & FP_S;
2601 fp_d = mo->pinfo & FP_D;
2604 if (fp_d && (mips_opts.soft_float || mips_opts.single_float))
2607 if (fp_s && mips_opts.soft_float)
2613 /* Return TRUE if the MIPS16 opcode MO is valid on the currently
2614 selected ISA and architecture. */
2617 is_opcode_valid_16 (const struct mips_opcode *mo)
2619 return opcode_is_member (mo, mips_opts.isa, 0, mips_opts.arch);
2622 /* Return TRUE if the size of the microMIPS opcode MO matches one
2623 explicitly requested. Always TRUE in the standard MIPS mode. */
2626 is_size_valid (const struct mips_opcode *mo)
2628 if (!mips_opts.micromips)
2631 if (!forced_insn_length)
2633 if (mo->pinfo == INSN_MACRO)
2635 return forced_insn_length == micromips_insn_length (mo);
2638 /* Return TRUE if the microMIPS opcode MO is valid for the delay slot
2639 of the preceding instruction. Always TRUE in the standard MIPS mode.
2641 We don't accept macros in 16-bit delay slots to avoid a case where
2642 a macro expansion fails because it relies on a preceding 32-bit real
2643 instruction to have matched and does not handle the operands correctly.
2644 The only macros that may expand to 16-bit instructions are JAL that
2645 cannot be placed in a delay slot anyway, and corner cases of BALIGN
2646 and BGT (that likewise cannot be placed in a delay slot) that decay to
2647 a NOP. In all these cases the macros precede any corresponding real
2648 instruction definitions in the opcode table, so they will match in the
2649 second pass where the size of the delay slot is ignored and therefore
2650 produce correct code. */
2653 is_delay_slot_valid (const struct mips_opcode *mo)
2655 if (!mips_opts.micromips)
2658 if (mo->pinfo == INSN_MACRO)
2659 return (history[0].insn_mo->pinfo2 & INSN2_BRANCH_DELAY_16BIT) == 0;
2660 if ((history[0].insn_mo->pinfo2 & INSN2_BRANCH_DELAY_32BIT) != 0
2661 && micromips_insn_length (mo) != 4)
2663 if ((history[0].insn_mo->pinfo2 & INSN2_BRANCH_DELAY_16BIT) != 0
2664 && micromips_insn_length (mo) != 2)
2670 /* This function is called once, at assembler startup time. It should set up
2671 all the tables, etc. that the MD part of the assembler will need. */
2676 const char *retval = NULL;
2680 if (mips_pic != NO_PIC)
2682 if (g_switch_seen && g_switch_value != 0)
2683 as_bad (_("-G may not be used in position-independent code"));
2687 if (! bfd_set_arch_mach (stdoutput, bfd_arch_mips, file_mips_arch))
2688 as_warn (_("Could not set architecture and machine"));
2690 op_hash = hash_new ();
2692 for (i = 0; i < NUMOPCODES;)
2694 const char *name = mips_opcodes[i].name;
2696 retval = hash_insert (op_hash, name, (void *) &mips_opcodes[i]);
2699 fprintf (stderr, _("internal error: can't hash `%s': %s\n"),
2700 mips_opcodes[i].name, retval);
2701 /* Probably a memory allocation problem? Give up now. */
2702 as_fatal (_("Broken assembler. No assembly attempted."));
2706 if (mips_opcodes[i].pinfo != INSN_MACRO)
2708 if (!validate_mips_insn (&mips_opcodes[i]))
2710 if (nop_insn.insn_mo == NULL && strcmp (name, "nop") == 0)
2712 create_insn (&nop_insn, mips_opcodes + i);
2713 if (mips_fix_loongson2f_nop)
2714 nop_insn.insn_opcode = LOONGSON2F_NOP_INSN;
2715 nop_insn.fixed_p = 1;
2720 while ((i < NUMOPCODES) && !strcmp (mips_opcodes[i].name, name));
2723 mips16_op_hash = hash_new ();
2726 while (i < bfd_mips16_num_opcodes)
2728 const char *name = mips16_opcodes[i].name;
2730 retval = hash_insert (mips16_op_hash, name, (void *) &mips16_opcodes[i]);
2732 as_fatal (_("internal: can't hash `%s': %s"),
2733 mips16_opcodes[i].name, retval);
2736 if (mips16_opcodes[i].pinfo != INSN_MACRO
2737 && ((mips16_opcodes[i].match & mips16_opcodes[i].mask)
2738 != mips16_opcodes[i].match))
2740 fprintf (stderr, _("internal error: bad mips16 opcode: %s %s\n"),
2741 mips16_opcodes[i].name, mips16_opcodes[i].args);
2744 if (mips16_nop_insn.insn_mo == NULL && strcmp (name, "nop") == 0)
2746 create_insn (&mips16_nop_insn, mips16_opcodes + i);
2747 mips16_nop_insn.fixed_p = 1;
2751 while (i < bfd_mips16_num_opcodes
2752 && strcmp (mips16_opcodes[i].name, name) == 0);
2755 micromips_op_hash = hash_new ();
2758 while (i < bfd_micromips_num_opcodes)
2760 const char *name = micromips_opcodes[i].name;
2762 retval = hash_insert (micromips_op_hash, name,
2763 (void *) µmips_opcodes[i]);
2765 as_fatal (_("internal: can't hash `%s': %s"),
2766 micromips_opcodes[i].name, retval);
2768 if (micromips_opcodes[i].pinfo != INSN_MACRO)
2770 struct mips_cl_insn *micromips_nop_insn;
2772 if (!validate_micromips_insn (µmips_opcodes[i]))
2775 if (micromips_insn_length (micromips_opcodes + i) == 2)
2776 micromips_nop_insn = µmips_nop16_insn;
2777 else if (micromips_insn_length (micromips_opcodes + i) == 4)
2778 micromips_nop_insn = µmips_nop32_insn;
2782 if (micromips_nop_insn->insn_mo == NULL
2783 && strcmp (name, "nop") == 0)
2785 create_insn (micromips_nop_insn, micromips_opcodes + i);
2786 micromips_nop_insn->fixed_p = 1;
2789 while (++i < bfd_micromips_num_opcodes
2790 && strcmp (micromips_opcodes[i].name, name) == 0);
2794 as_fatal (_("Broken assembler. No assembly attempted."));
2796 /* We add all the general register names to the symbol table. This
2797 helps us detect invalid uses of them. */
2798 for (i = 0; reg_names[i].name; i++)
2799 symbol_table_insert (symbol_new (reg_names[i].name, reg_section,
2800 reg_names[i].num, /* & RNUM_MASK, */
2801 &zero_address_frag));
2803 for (i = 0; reg_names_n32n64[i].name; i++)
2804 symbol_table_insert (symbol_new (reg_names_n32n64[i].name, reg_section,
2805 reg_names_n32n64[i].num, /* & RNUM_MASK, */
2806 &zero_address_frag));
2808 for (i = 0; reg_names_o32[i].name; i++)
2809 symbol_table_insert (symbol_new (reg_names_o32[i].name, reg_section,
2810 reg_names_o32[i].num, /* & RNUM_MASK, */
2811 &zero_address_frag));
2813 mips_no_prev_insn ();
2816 mips_cprmask[0] = 0;
2817 mips_cprmask[1] = 0;
2818 mips_cprmask[2] = 0;
2819 mips_cprmask[3] = 0;
2821 /* set the default alignment for the text section (2**2) */
2822 record_alignment (text_section, 2);
2824 bfd_set_gp_size (stdoutput, g_switch_value);
2826 /* On a native system other than VxWorks, sections must be aligned
2827 to 16 byte boundaries. When configured for an embedded ELF
2828 target, we don't bother. */
2829 if (strncmp (TARGET_OS, "elf", 3) != 0
2830 && strncmp (TARGET_OS, "vxworks", 7) != 0)
2832 (void) bfd_set_section_alignment (stdoutput, text_section, 4);
2833 (void) bfd_set_section_alignment (stdoutput, data_section, 4);
2834 (void) bfd_set_section_alignment (stdoutput, bss_section, 4);
2837 /* Create a .reginfo section for register masks and a .mdebug
2838 section for debugging information. */
2846 subseg = now_subseg;
2848 /* The ABI says this section should be loaded so that the
2849 running program can access it. However, we don't load it
2850 if we are configured for an embedded target */
2851 flags = SEC_READONLY | SEC_DATA;
2852 if (strncmp (TARGET_OS, "elf", 3) != 0)
2853 flags |= SEC_ALLOC | SEC_LOAD;
2855 if (mips_abi != N64_ABI)
2857 sec = subseg_new (".reginfo", (subsegT) 0);
2859 bfd_set_section_flags (stdoutput, sec, flags);
2860 bfd_set_section_alignment (stdoutput, sec, HAVE_NEWABI ? 3 : 2);
2862 mips_regmask_frag = frag_more (sizeof (Elf32_External_RegInfo));
2866 /* The 64-bit ABI uses a .MIPS.options section rather than
2867 .reginfo section. */
2868 sec = subseg_new (".MIPS.options", (subsegT) 0);
2869 bfd_set_section_flags (stdoutput, sec, flags);
2870 bfd_set_section_alignment (stdoutput, sec, 3);
2872 /* Set up the option header. */
2874 Elf_Internal_Options opthdr;
2877 opthdr.kind = ODK_REGINFO;
2878 opthdr.size = (sizeof (Elf_External_Options)
2879 + sizeof (Elf64_External_RegInfo));
2882 f = frag_more (sizeof (Elf_External_Options));
2883 bfd_mips_elf_swap_options_out (stdoutput, &opthdr,
2884 (Elf_External_Options *) f);
2886 mips_regmask_frag = frag_more (sizeof (Elf64_External_RegInfo));
2890 if (ECOFF_DEBUGGING)
2892 sec = subseg_new (".mdebug", (subsegT) 0);
2893 (void) bfd_set_section_flags (stdoutput, sec,
2894 SEC_HAS_CONTENTS | SEC_READONLY);
2895 (void) bfd_set_section_alignment (stdoutput, sec, 2);
2897 else if (mips_flag_pdr)
2899 pdr_seg = subseg_new (".pdr", (subsegT) 0);
2900 (void) bfd_set_section_flags (stdoutput, pdr_seg,
2901 SEC_READONLY | SEC_RELOC
2903 (void) bfd_set_section_alignment (stdoutput, pdr_seg, 2);
2906 subseg_set (seg, subseg);
2909 if (! ECOFF_DEBUGGING)
2912 if (mips_fix_vr4120)
2913 init_vr4120_conflicts ();
2919 mips_emit_delays ();
2920 if (! ECOFF_DEBUGGING)
2925 md_assemble (char *str)
2927 struct mips_cl_insn insn;
2928 bfd_reloc_code_real_type unused_reloc[3]
2929 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
2931 imm_expr.X_op = O_absent;
2932 imm2_expr.X_op = O_absent;
2933 offset_expr.X_op = O_absent;
2934 imm_reloc[0] = BFD_RELOC_UNUSED;
2935 imm_reloc[1] = BFD_RELOC_UNUSED;
2936 imm_reloc[2] = BFD_RELOC_UNUSED;
2937 offset_reloc[0] = BFD_RELOC_UNUSED;
2938 offset_reloc[1] = BFD_RELOC_UNUSED;
2939 offset_reloc[2] = BFD_RELOC_UNUSED;
2941 mips_mark_labels ();
2942 mips_assembling_insn = TRUE;
2944 if (mips_opts.mips16)
2945 mips16_ip (str, &insn);
2948 mips_ip (str, &insn);
2949 DBG ((_("returned from mips_ip(%s) insn_opcode = 0x%x\n"),
2950 str, insn.insn_opcode));
2954 as_bad ("%s `%s'", insn_error, str);
2955 else if (insn.insn_mo->pinfo == INSN_MACRO)
2958 if (mips_opts.mips16)
2959 mips16_macro (&insn);
2966 if (imm_expr.X_op != O_absent)
2967 append_insn (&insn, &imm_expr, imm_reloc, FALSE);
2968 else if (offset_expr.X_op != O_absent)
2969 append_insn (&insn, &offset_expr, offset_reloc, FALSE);
2971 append_insn (&insn, NULL, unused_reloc, FALSE);
2974 mips_assembling_insn = FALSE;
2977 /* Convenience functions for abstracting away the differences between
2978 MIPS16 and non-MIPS16 relocations. */
2980 static inline bfd_boolean
2981 mips16_reloc_p (bfd_reloc_code_real_type reloc)
2985 case BFD_RELOC_MIPS16_JMP:
2986 case BFD_RELOC_MIPS16_GPREL:
2987 case BFD_RELOC_MIPS16_GOT16:
2988 case BFD_RELOC_MIPS16_CALL16:
2989 case BFD_RELOC_MIPS16_HI16_S:
2990 case BFD_RELOC_MIPS16_HI16:
2991 case BFD_RELOC_MIPS16_LO16:
2999 static inline bfd_boolean
3000 micromips_reloc_p (bfd_reloc_code_real_type reloc)
3004 case BFD_RELOC_MICROMIPS_7_PCREL_S1:
3005 case BFD_RELOC_MICROMIPS_10_PCREL_S1:
3006 case BFD_RELOC_MICROMIPS_16_PCREL_S1:
3007 case BFD_RELOC_MICROMIPS_GPREL16:
3008 case BFD_RELOC_MICROMIPS_JMP:
3009 case BFD_RELOC_MICROMIPS_HI16:
3010 case BFD_RELOC_MICROMIPS_HI16_S:
3011 case BFD_RELOC_MICROMIPS_LO16:
3012 case BFD_RELOC_MICROMIPS_LITERAL:
3013 case BFD_RELOC_MICROMIPS_GOT16:
3014 case BFD_RELOC_MICROMIPS_CALL16:
3015 case BFD_RELOC_MICROMIPS_GOT_HI16:
3016 case BFD_RELOC_MICROMIPS_GOT_LO16:
3017 case BFD_RELOC_MICROMIPS_CALL_HI16:
3018 case BFD_RELOC_MICROMIPS_CALL_LO16:
3019 case BFD_RELOC_MICROMIPS_SUB:
3020 case BFD_RELOC_MICROMIPS_GOT_PAGE:
3021 case BFD_RELOC_MICROMIPS_GOT_OFST:
3022 case BFD_RELOC_MICROMIPS_GOT_DISP:
3023 case BFD_RELOC_MICROMIPS_HIGHEST:
3024 case BFD_RELOC_MICROMIPS_HIGHER:
3025 case BFD_RELOC_MICROMIPS_SCN_DISP:
3026 case BFD_RELOC_MICROMIPS_JALR:
3034 static inline bfd_boolean
3035 jmp_reloc_p (bfd_reloc_code_real_type reloc)
3037 return reloc == BFD_RELOC_MIPS_JMP || reloc == BFD_RELOC_MICROMIPS_JMP;
3040 static inline bfd_boolean
3041 got16_reloc_p (bfd_reloc_code_real_type reloc)
3043 return (reloc == BFD_RELOC_MIPS_GOT16 || reloc == BFD_RELOC_MIPS16_GOT16
3044 || reloc == BFD_RELOC_MICROMIPS_GOT16);
3047 static inline bfd_boolean
3048 hi16_reloc_p (bfd_reloc_code_real_type reloc)
3050 return (reloc == BFD_RELOC_HI16_S || reloc == BFD_RELOC_MIPS16_HI16_S
3051 || reloc == BFD_RELOC_MICROMIPS_HI16_S);
3054 static inline bfd_boolean
3055 lo16_reloc_p (bfd_reloc_code_real_type reloc)
3057 return (reloc == BFD_RELOC_LO16 || reloc == BFD_RELOC_MIPS16_LO16
3058 || reloc == BFD_RELOC_MICROMIPS_LO16);
3061 static inline bfd_boolean
3062 jalr_reloc_p (bfd_reloc_code_real_type reloc)
3064 return reloc == BFD_RELOC_MIPS_JALR || reloc == BFD_RELOC_MICROMIPS_JALR;
3067 /* Return true if RELOC is a PC-relative relocation that does not have
3068 full address range. */
3070 static inline bfd_boolean
3071 limited_pcrel_reloc_p (bfd_reloc_code_real_type reloc)
3075 case BFD_RELOC_16_PCREL_S2:
3076 case BFD_RELOC_MICROMIPS_7_PCREL_S1:
3077 case BFD_RELOC_MICROMIPS_10_PCREL_S1:
3078 case BFD_RELOC_MICROMIPS_16_PCREL_S1:
3081 case BFD_RELOC_32_PCREL:
3082 return HAVE_64BIT_ADDRESSES;
3089 /* Return true if the given relocation might need a matching %lo().
3090 This is only "might" because SVR4 R_MIPS_GOT16 relocations only
3091 need a matching %lo() when applied to local symbols. */
3093 static inline bfd_boolean
3094 reloc_needs_lo_p (bfd_reloc_code_real_type reloc)
3096 return (HAVE_IN_PLACE_ADDENDS
3097 && (hi16_reloc_p (reloc)
3098 /* VxWorks R_MIPS_GOT16 relocs never need a matching %lo();
3099 all GOT16 relocations evaluate to "G". */
3100 || (got16_reloc_p (reloc) && mips_pic != VXWORKS_PIC)));
3103 /* Return the type of %lo() reloc needed by RELOC, given that
3104 reloc_needs_lo_p. */
3106 static inline bfd_reloc_code_real_type
3107 matching_lo_reloc (bfd_reloc_code_real_type reloc)
3109 return (mips16_reloc_p (reloc) ? BFD_RELOC_MIPS16_LO16
3110 : (micromips_reloc_p (reloc) ? BFD_RELOC_MICROMIPS_LO16
3114 /* Return true if the given fixup is followed by a matching R_MIPS_LO16
3117 static inline bfd_boolean
3118 fixup_has_matching_lo_p (fixS *fixp)
3120 return (fixp->fx_next != NULL
3121 && fixp->fx_next->fx_r_type == matching_lo_reloc (fixp->fx_r_type)
3122 && fixp->fx_addsy == fixp->fx_next->fx_addsy
3123 && fixp->fx_offset == fixp->fx_next->fx_offset);
3126 /* This function returns true if modifying a register requires a
3130 reg_needs_delay (unsigned int reg)
3132 unsigned long prev_pinfo;
3134 prev_pinfo = history[0].insn_mo->pinfo;
3135 if (! mips_opts.noreorder
3136 && (((prev_pinfo & INSN_LOAD_MEMORY_DELAY)
3137 && ! gpr_interlocks)
3138 || ((prev_pinfo & INSN_LOAD_COPROC_DELAY)
3139 && ! cop_interlocks)))
3141 /* A load from a coprocessor or from memory. All load delays
3142 delay the use of general register rt for one instruction. */
3143 /* Itbl support may require additional care here. */
3144 know (prev_pinfo & INSN_WRITE_GPR_T);
3145 if (reg == EXTRACT_OPERAND (mips_opts.micromips, RT, history[0]))
3152 /* Move all labels in LABELS to the current insertion point. TEXT_P
3153 says whether the labels refer to text or data. */
3156 mips_move_labels (struct insn_label_list *labels, bfd_boolean text_p)
3158 struct insn_label_list *l;
3161 for (l = labels; l != NULL; l = l->next)
3163 gas_assert (S_GET_SEGMENT (l->label) == now_seg);
3164 symbol_set_frag (l->label, frag_now);
3165 val = (valueT) frag_now_fix ();
3166 /* MIPS16/microMIPS text labels are stored as odd. */
3167 if (text_p && HAVE_CODE_COMPRESSION)
3169 S_SET_VALUE (l->label, val);
3173 /* Move all labels in insn_labels to the current insertion point
3174 and treat them as text labels. */
3177 mips_move_text_labels (void)
3179 mips_move_labels (seg_info (now_seg)->label_list, TRUE);
3183 s_is_linkonce (symbolS *sym, segT from_seg)
3185 bfd_boolean linkonce = FALSE;
3186 segT symseg = S_GET_SEGMENT (sym);
3188 if (symseg != from_seg && !S_IS_LOCAL (sym))
3190 if ((bfd_get_section_flags (stdoutput, symseg) & SEC_LINK_ONCE))
3192 /* The GNU toolchain uses an extension for ELF: a section
3193 beginning with the magic string .gnu.linkonce is a
3194 linkonce section. */
3195 if (strncmp (segment_name (symseg), ".gnu.linkonce",
3196 sizeof ".gnu.linkonce" - 1) == 0)
3202 /* Mark MIPS16 or microMIPS instruction label LABEL. This permits the
3203 linker to handle them specially, such as generating jalx instructions
3204 when needed. We also make them odd for the duration of the assembly,
3205 in order to generate the right sort of code. We will make them even
3206 in the adjust_symtab routine, while leaving them marked. This is
3207 convenient for the debugger and the disassembler. The linker knows
3208 to make them odd again. */
3211 mips_compressed_mark_label (symbolS *label)
3213 gas_assert (HAVE_CODE_COMPRESSION);
3215 if (mips_opts.mips16)
3216 S_SET_OTHER (label, ELF_ST_SET_MIPS16 (S_GET_OTHER (label)));
3218 S_SET_OTHER (label, ELF_ST_SET_MICROMIPS (S_GET_OTHER (label)));
3219 if ((S_GET_VALUE (label) & 1) == 0
3220 /* Don't adjust the address if the label is global or weak, or
3221 in a link-once section, since we'll be emitting symbol reloc
3222 references to it which will be patched up by the linker, and
3223 the final value of the symbol may or may not be MIPS16/microMIPS. */
3224 && !S_IS_WEAK (label)
3225 && !S_IS_EXTERNAL (label)
3226 && !s_is_linkonce (label, now_seg))
3227 S_SET_VALUE (label, S_GET_VALUE (label) | 1);
3230 /* Mark preceding MIPS16 or microMIPS instruction labels. */
3233 mips_compressed_mark_labels (void)
3235 struct insn_label_list *l;
3237 for (l = seg_info (now_seg)->label_list; l != NULL; l = l->next)
3238 mips_compressed_mark_label (l->label);
3241 /* End the current frag. Make it a variant frag and record the
3245 relax_close_frag (void)
3247 mips_macro_warning.first_frag = frag_now;
3248 frag_var (rs_machine_dependent, 0, 0,
3249 RELAX_ENCODE (mips_relax.sizes[0], mips_relax.sizes[1]),
3250 mips_relax.symbol, 0, (char *) mips_relax.first_fixup);
3252 memset (&mips_relax.sizes, 0, sizeof (mips_relax.sizes));
3253 mips_relax.first_fixup = 0;
3256 /* Start a new relaxation sequence whose expansion depends on SYMBOL.
3257 See the comment above RELAX_ENCODE for more details. */
3260 relax_start (symbolS *symbol)
3262 gas_assert (mips_relax.sequence == 0);
3263 mips_relax.sequence = 1;
3264 mips_relax.symbol = symbol;
3267 /* Start generating the second version of a relaxable sequence.
3268 See the comment above RELAX_ENCODE for more details. */
3273 gas_assert (mips_relax.sequence == 1);
3274 mips_relax.sequence = 2;
3277 /* End the current relaxable sequence. */
3282 gas_assert (mips_relax.sequence == 2);
3283 relax_close_frag ();
3284 mips_relax.sequence = 0;
3287 /* Return true if IP is a delayed branch or jump. */
3289 static inline bfd_boolean
3290 delayed_branch_p (const struct mips_cl_insn *ip)
3292 return (ip->insn_mo->pinfo & (INSN_UNCOND_BRANCH_DELAY
3293 | INSN_COND_BRANCH_DELAY
3294 | INSN_COND_BRANCH_LIKELY)) != 0;
3297 /* Return true if IP is a compact branch or jump. */
3299 static inline bfd_boolean
3300 compact_branch_p (const struct mips_cl_insn *ip)
3302 if (mips_opts.mips16)
3303 return (ip->insn_mo->pinfo & (MIPS16_INSN_UNCOND_BRANCH
3304 | MIPS16_INSN_COND_BRANCH)) != 0;
3306 return (ip->insn_mo->pinfo2 & (INSN2_UNCOND_BRANCH
3307 | INSN2_COND_BRANCH)) != 0;
3310 /* Return true if IP is an unconditional branch or jump. */
3312 static inline bfd_boolean
3313 uncond_branch_p (const struct mips_cl_insn *ip)
3315 return ((ip->insn_mo->pinfo & INSN_UNCOND_BRANCH_DELAY) != 0
3316 || (mips_opts.mips16
3317 ? (ip->insn_mo->pinfo & MIPS16_INSN_UNCOND_BRANCH) != 0
3318 : (ip->insn_mo->pinfo2 & INSN2_UNCOND_BRANCH) != 0));
3321 /* Return true if IP is a branch-likely instruction. */
3323 static inline bfd_boolean
3324 branch_likely_p (const struct mips_cl_insn *ip)
3326 return (ip->insn_mo->pinfo & INSN_COND_BRANCH_LIKELY) != 0;
3329 /* Return the type of nop that should be used to fill the delay slot
3330 of delayed branch IP. */
3332 static struct mips_cl_insn *
3333 get_delay_slot_nop (const struct mips_cl_insn *ip)
3335 if (mips_opts.micromips
3336 && (ip->insn_mo->pinfo2 & INSN2_BRANCH_DELAY_32BIT))
3337 return µmips_nop32_insn;
3341 /* Return the mask of core registers that IP reads or writes. */
3344 gpr_mod_mask (const struct mips_cl_insn *ip)
3346 unsigned long pinfo2;
3350 pinfo2 = ip->insn_mo->pinfo2;
3351 if (mips_opts.micromips)
3353 if (pinfo2 & INSN2_MOD_GPR_MD)
3354 mask |= 1 << micromips_to_32_reg_d_map[EXTRACT_OPERAND (1, MD, *ip)];
3355 if (pinfo2 & INSN2_MOD_GPR_MF)
3356 mask |= 1 << micromips_to_32_reg_f_map[EXTRACT_OPERAND (1, MF, *ip)];
3357 if (pinfo2 & INSN2_MOD_SP)
3363 /* Return the mask of core registers that IP reads. */
3366 gpr_read_mask (const struct mips_cl_insn *ip)
3368 unsigned long pinfo, pinfo2;
3371 mask = gpr_mod_mask (ip);
3372 pinfo = ip->insn_mo->pinfo;
3373 pinfo2 = ip->insn_mo->pinfo2;
3374 if (mips_opts.mips16)
3376 if (pinfo & MIPS16_INSN_READ_X)
3377 mask |= 1 << mips16_to_32_reg_map[MIPS16_EXTRACT_OPERAND (RX, *ip)];
3378 if (pinfo & MIPS16_INSN_READ_Y)
3379 mask |= 1 << mips16_to_32_reg_map[MIPS16_EXTRACT_OPERAND (RY, *ip)];
3380 if (pinfo & MIPS16_INSN_READ_T)
3382 if (pinfo & MIPS16_INSN_READ_SP)
3384 if (pinfo & MIPS16_INSN_READ_31)
3386 if (pinfo & MIPS16_INSN_READ_Z)
3387 mask |= 1 << (mips16_to_32_reg_map
3388 [MIPS16_EXTRACT_OPERAND (MOVE32Z, *ip)]);
3389 if (pinfo & MIPS16_INSN_READ_GPR_X)
3390 mask |= 1 << MIPS16_EXTRACT_OPERAND (REGR32, *ip);
3394 if (pinfo2 & INSN2_READ_GPR_D)
3395 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RD, *ip);
3396 if (pinfo & INSN_READ_GPR_T)
3397 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RT, *ip);
3398 if (pinfo & INSN_READ_GPR_S)
3399 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RS, *ip);
3400 if (pinfo2 & INSN2_READ_GP)
3402 if (pinfo2 & INSN2_READ_GPR_31)
3404 if (pinfo2 & INSN2_READ_GPR_Z)
3405 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RZ, *ip);
3407 if (mips_opts.micromips)
3409 if (pinfo2 & INSN2_READ_GPR_MC)
3410 mask |= 1 << micromips_to_32_reg_c_map[EXTRACT_OPERAND (1, MC, *ip)];
3411 if (pinfo2 & INSN2_READ_GPR_ME)
3412 mask |= 1 << micromips_to_32_reg_e_map[EXTRACT_OPERAND (1, ME, *ip)];
3413 if (pinfo2 & INSN2_READ_GPR_MG)
3414 mask |= 1 << micromips_to_32_reg_g_map[EXTRACT_OPERAND (1, MG, *ip)];
3415 if (pinfo2 & INSN2_READ_GPR_MJ)
3416 mask |= 1 << EXTRACT_OPERAND (1, MJ, *ip);
3417 if (pinfo2 & INSN2_READ_GPR_MMN)
3419 mask |= 1 << micromips_to_32_reg_m_map[EXTRACT_OPERAND (1, MM, *ip)];
3420 mask |= 1 << micromips_to_32_reg_n_map[EXTRACT_OPERAND (1, MN, *ip)];
3422 if (pinfo2 & INSN2_READ_GPR_MP)
3423 mask |= 1 << EXTRACT_OPERAND (1, MP, *ip);
3424 if (pinfo2 & INSN2_READ_GPR_MQ)
3425 mask |= 1 << micromips_to_32_reg_q_map[EXTRACT_OPERAND (1, MQ, *ip)];
3427 /* Don't include register 0. */
3431 /* Return the mask of core registers that IP writes. */
3434 gpr_write_mask (const struct mips_cl_insn *ip)
3436 unsigned long pinfo, pinfo2;
3439 mask = gpr_mod_mask (ip);
3440 pinfo = ip->insn_mo->pinfo;
3441 pinfo2 = ip->insn_mo->pinfo2;
3442 if (mips_opts.mips16)
3444 if (pinfo & MIPS16_INSN_WRITE_X)
3445 mask |= 1 << mips16_to_32_reg_map[MIPS16_EXTRACT_OPERAND (RX, *ip)];
3446 if (pinfo & MIPS16_INSN_WRITE_Y)
3447 mask |= 1 << mips16_to_32_reg_map[MIPS16_EXTRACT_OPERAND (RY, *ip)];
3448 if (pinfo & MIPS16_INSN_WRITE_Z)
3449 mask |= 1 << mips16_to_32_reg_map[MIPS16_EXTRACT_OPERAND (RZ, *ip)];
3450 if (pinfo & MIPS16_INSN_WRITE_T)
3452 if (pinfo & MIPS16_INSN_WRITE_SP)
3454 if (pinfo & MIPS16_INSN_WRITE_31)
3456 if (pinfo & MIPS16_INSN_WRITE_GPR_Y)
3457 mask |= 1 << MIPS16OP_EXTRACT_REG32R (ip->insn_opcode);
3461 if (pinfo & INSN_WRITE_GPR_D)
3462 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RD, *ip);
3463 if (pinfo & INSN_WRITE_GPR_T)
3464 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RT, *ip);
3465 if (pinfo & INSN_WRITE_GPR_S)
3466 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RS, *ip);
3467 if (pinfo & INSN_WRITE_GPR_31)
3469 if (pinfo2 & INSN2_WRITE_GPR_Z)
3470 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, RZ, *ip);
3472 if (mips_opts.micromips)
3474 if (pinfo2 & INSN2_WRITE_GPR_MB)
3475 mask |= 1 << micromips_to_32_reg_b_map[EXTRACT_OPERAND (1, MB, *ip)];
3476 if (pinfo2 & INSN2_WRITE_GPR_MHI)
3478 mask |= 1 << micromips_to_32_reg_h_map[EXTRACT_OPERAND (1, MH, *ip)];
3479 mask |= 1 << micromips_to_32_reg_i_map[EXTRACT_OPERAND (1, MI, *ip)];
3481 if (pinfo2 & INSN2_WRITE_GPR_MJ)
3482 mask |= 1 << EXTRACT_OPERAND (1, MJ, *ip);
3483 if (pinfo2 & INSN2_WRITE_GPR_MP)
3484 mask |= 1 << EXTRACT_OPERAND (1, MP, *ip);
3486 /* Don't include register 0. */
3490 /* Return the mask of floating-point registers that IP reads. */
3493 fpr_read_mask (const struct mips_cl_insn *ip)
3495 unsigned long pinfo, pinfo2;
3499 pinfo = ip->insn_mo->pinfo;
3500 pinfo2 = ip->insn_mo->pinfo2;
3501 if (!mips_opts.mips16)
3503 if (pinfo2 & INSN2_READ_FPR_D)
3504 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FD, *ip);
3505 if (pinfo & INSN_READ_FPR_S)
3506 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FS, *ip);
3507 if (pinfo & INSN_READ_FPR_T)
3508 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FT, *ip);
3509 if (pinfo & INSN_READ_FPR_R)
3510 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FR, *ip);
3511 if (pinfo2 & INSN2_READ_FPR_Z)
3512 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FZ, *ip);
3514 /* Conservatively treat all operands to an FP_D instruction are doubles.
3515 (This is overly pessimistic for things like cvt.d.s.) */
3516 if (HAVE_32BIT_FPRS && (pinfo & FP_D))
3521 /* Return the mask of floating-point registers that IP writes. */
3524 fpr_write_mask (const struct mips_cl_insn *ip)
3526 unsigned long pinfo, pinfo2;
3530 pinfo = ip->insn_mo->pinfo;
3531 pinfo2 = ip->insn_mo->pinfo2;
3532 if (!mips_opts.mips16)
3534 if (pinfo & INSN_WRITE_FPR_D)
3535 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FD, *ip);
3536 if (pinfo & INSN_WRITE_FPR_S)
3537 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FS, *ip);
3538 if (pinfo & INSN_WRITE_FPR_T)
3539 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FT, *ip);
3540 if (pinfo2 & INSN2_WRITE_FPR_Z)
3541 mask |= 1 << EXTRACT_OPERAND (mips_opts.micromips, FZ, *ip);
3543 /* Conservatively treat all operands to an FP_D instruction are doubles.
3544 (This is overly pessimistic for things like cvt.s.d.) */
3545 if (HAVE_32BIT_FPRS && (pinfo & FP_D))
3550 /* Classify an instruction according to the FIX_VR4120_* enumeration.
3551 Return NUM_FIX_VR4120_CLASSES if the instruction isn't affected
3552 by VR4120 errata. */
3555 classify_vr4120_insn (const char *name)
3557 if (strncmp (name, "macc", 4) == 0)
3558 return FIX_VR4120_MACC;
3559 if (strncmp (name, "dmacc", 5) == 0)
3560 return FIX_VR4120_DMACC;
3561 if (strncmp (name, "mult", 4) == 0)
3562 return FIX_VR4120_MULT;
3563 if (strncmp (name, "dmult", 5) == 0)
3564 return FIX_VR4120_DMULT;
3565 if (strstr (name, "div"))
3566 return FIX_VR4120_DIV;
3567 if (strcmp (name, "mtlo") == 0 || strcmp (name, "mthi") == 0)
3568 return FIX_VR4120_MTHILO;
3569 return NUM_FIX_VR4120_CLASSES;
3572 #define INSN_ERET 0x42000018
3573 #define INSN_DERET 0x4200001f
3575 /* Return the number of instructions that must separate INSN1 and INSN2,
3576 where INSN1 is the earlier instruction. Return the worst-case value
3577 for any INSN2 if INSN2 is null. */
3580 insns_between (const struct mips_cl_insn *insn1,
3581 const struct mips_cl_insn *insn2)
3583 unsigned long pinfo1, pinfo2;
3586 /* This function needs to know which pinfo flags are set for INSN2
3587 and which registers INSN2 uses. The former is stored in PINFO2 and
3588 the latter is tested via INSN2_USES_GPR. If INSN2 is null, PINFO2
3589 will have every flag set and INSN2_USES_GPR will always return true. */
3590 pinfo1 = insn1->insn_mo->pinfo;
3591 pinfo2 = insn2 ? insn2->insn_mo->pinfo : ~0U;
3593 #define INSN2_USES_GPR(REG) \
3594 (insn2 == NULL || (gpr_read_mask (insn2) & (1U << (REG))) != 0)
3596 /* For most targets, write-after-read dependencies on the HI and LO
3597 registers must be separated by at least two instructions. */
3598 if (!hilo_interlocks)
3600 if ((pinfo1 & INSN_READ_LO) && (pinfo2 & INSN_WRITE_LO))
3602 if ((pinfo1 & INSN_READ_HI) && (pinfo2 & INSN_WRITE_HI))
3606 /* If we're working around r7000 errata, there must be two instructions
3607 between an mfhi or mflo and any instruction that uses the result. */
3608 if (mips_7000_hilo_fix
3609 && !mips_opts.micromips
3610 && MF_HILO_INSN (pinfo1)
3611 && INSN2_USES_GPR (EXTRACT_OPERAND (0, RD, *insn1)))
3614 /* If we're working around 24K errata, one instruction is required
3615 if an ERET or DERET is followed by a branch instruction. */
3616 if (mips_fix_24k && !mips_opts.micromips)
3618 if (insn1->insn_opcode == INSN_ERET
3619 || insn1->insn_opcode == INSN_DERET)
3622 || insn2->insn_opcode == INSN_ERET
3623 || insn2->insn_opcode == INSN_DERET
3624 || delayed_branch_p (insn2))
3629 /* If working around VR4120 errata, check for combinations that need
3630 a single intervening instruction. */
3631 if (mips_fix_vr4120 && !mips_opts.micromips)
3633 unsigned int class1, class2;
3635 class1 = classify_vr4120_insn (insn1->insn_mo->name);
3636 if (class1 != NUM_FIX_VR4120_CLASSES && vr4120_conflicts[class1] != 0)
3640 class2 = classify_vr4120_insn (insn2->insn_mo->name);
3641 if (vr4120_conflicts[class1] & (1 << class2))
3646 if (!HAVE_CODE_COMPRESSION)
3648 /* Check for GPR or coprocessor load delays. All such delays
3649 are on the RT register. */
3650 /* Itbl support may require additional care here. */
3651 if ((!gpr_interlocks && (pinfo1 & INSN_LOAD_MEMORY_DELAY))
3652 || (!cop_interlocks && (pinfo1 & INSN_LOAD_COPROC_DELAY)))
3654 know (pinfo1 & INSN_WRITE_GPR_T);
3655 if (INSN2_USES_GPR (EXTRACT_OPERAND (0, RT, *insn1)))
3659 /* Check for generic coprocessor hazards.
3661 This case is not handled very well. There is no special
3662 knowledge of CP0 handling, and the coprocessors other than
3663 the floating point unit are not distinguished at all. */
3664 /* Itbl support may require additional care here. FIXME!
3665 Need to modify this to include knowledge about
3666 user specified delays! */
3667 else if ((!cop_interlocks && (pinfo1 & INSN_COPROC_MOVE_DELAY))
3668 || (!cop_mem_interlocks && (pinfo1 & INSN_COPROC_MEMORY_DELAY)))
3670 /* Handle cases where INSN1 writes to a known general coprocessor
3671 register. There must be a one instruction delay before INSN2
3672 if INSN2 reads that register, otherwise no delay is needed. */
3673 mask = fpr_write_mask (insn1);
3676 if (!insn2 || (mask & fpr_read_mask (insn2)) != 0)
3681 /* Read-after-write dependencies on the control registers
3682 require a two-instruction gap. */
3683 if ((pinfo1 & INSN_WRITE_COND_CODE)
3684 && (pinfo2 & INSN_READ_COND_CODE))
3687 /* We don't know exactly what INSN1 does. If INSN2 is
3688 also a coprocessor instruction, assume there must be
3689 a one instruction gap. */
3690 if (pinfo2 & INSN_COP)
3695 /* Check for read-after-write dependencies on the coprocessor
3696 control registers in cases where INSN1 does not need a general
3697 coprocessor delay. This means that INSN1 is a floating point
3698 comparison instruction. */
3699 /* Itbl support may require additional care here. */
3700 else if (!cop_interlocks
3701 && (pinfo1 & INSN_WRITE_COND_CODE)
3702 && (pinfo2 & INSN_READ_COND_CODE))
3706 #undef INSN2_USES_GPR
3711 /* Return the number of nops that would be needed to work around the
3712 VR4130 mflo/mfhi errata if instruction INSN immediately followed
3713 the MAX_VR4130_NOPS instructions described by HIST. Ignore hazards
3714 that are contained within the first IGNORE instructions of HIST. */
3717 nops_for_vr4130 (int ignore, const struct mips_cl_insn *hist,
3718 const struct mips_cl_insn *insn)
3723 /* Check if the instruction writes to HI or LO. MTHI and MTLO
3724 are not affected by the errata. */
3726 && ((insn->insn_mo->pinfo & (INSN_WRITE_HI | INSN_WRITE_LO)) == 0
3727 || strcmp (insn->insn_mo->name, "mtlo") == 0
3728 || strcmp (insn->insn_mo->name, "mthi") == 0))
3731 /* Search for the first MFLO or MFHI. */
3732 for (i = 0; i < MAX_VR4130_NOPS; i++)
3733 if (MF_HILO_INSN (hist[i].insn_mo->pinfo))
3735 /* Extract the destination register. */
3736 mask = gpr_write_mask (&hist[i]);
3738 /* No nops are needed if INSN reads that register. */
3739 if (insn != NULL && (gpr_read_mask (insn) & mask) != 0)
3742 /* ...or if any of the intervening instructions do. */
3743 for (j = 0; j < i; j++)
3744 if (gpr_read_mask (&hist[j]) & mask)
3748 return MAX_VR4130_NOPS - i;
3753 #define BASE_REG_EQ(INSN1, INSN2) \
3754 ((((INSN1) >> OP_SH_RS) & OP_MASK_RS) \
3755 == (((INSN2) >> OP_SH_RS) & OP_MASK_RS))
3757 /* Return the minimum alignment for this store instruction. */
3760 fix_24k_align_to (const struct mips_opcode *mo)
3762 if (strcmp (mo->name, "sh") == 0)
3765 if (strcmp (mo->name, "swc1") == 0
3766 || strcmp (mo->name, "swc2") == 0
3767 || strcmp (mo->name, "sw") == 0
3768 || strcmp (mo->name, "sc") == 0
3769 || strcmp (mo->name, "s.s") == 0)
3772 if (strcmp (mo->name, "sdc1") == 0
3773 || strcmp (mo->name, "sdc2") == 0
3774 || strcmp (mo->name, "s.d") == 0)
3781 struct fix_24k_store_info
3783 /* Immediate offset, if any, for this store instruction. */
3785 /* Alignment required by this store instruction. */
3787 /* True for register offsets. */
3788 int register_offset;
3791 /* Comparison function used by qsort. */
3794 fix_24k_sort (const void *a, const void *b)
3796 const struct fix_24k_store_info *pos1 = a;
3797 const struct fix_24k_store_info *pos2 = b;
3799 return (pos1->off - pos2->off);
3802 /* INSN is a store instruction. Try to record the store information
3803 in STINFO. Return false if the information isn't known. */
3806 fix_24k_record_store_info (struct fix_24k_store_info *stinfo,
3807 const struct mips_cl_insn *insn)
3809 /* The instruction must have a known offset. */
3810 if (!insn->complete_p || !strstr (insn->insn_mo->args, "o("))
3813 stinfo->off = (insn->insn_opcode >> OP_SH_IMMEDIATE) & OP_MASK_IMMEDIATE;
3814 stinfo->align_to = fix_24k_align_to (insn->insn_mo);
3818 /* Return the number of nops that would be needed to work around the 24k
3819 "lost data on stores during refill" errata if instruction INSN
3820 immediately followed the 2 instructions described by HIST.
3821 Ignore hazards that are contained within the first IGNORE
3822 instructions of HIST.
3824 Problem: The FSB (fetch store buffer) acts as an intermediate buffer
3825 for the data cache refills and store data. The following describes
3826 the scenario where the store data could be lost.
3828 * A data cache miss, due to either a load or a store, causing fill
3829 data to be supplied by the memory subsystem
3830 * The first three doublewords of fill data are returned and written
3832 * A sequence of four stores occurs in consecutive cycles around the
3833 final doubleword of the fill:
3837 * Zero, One or more instructions
3840 The four stores A-D must be to different doublewords of the line that
3841 is being filled. The fourth instruction in the sequence above permits
3842 the fill of the final doubleword to be transferred from the FSB into
3843 the cache. In the sequence above, the stores may be either integer
3844 (sb, sh, sw, swr, swl, sc) or coprocessor (swc1/swc2, sdc1/sdc2,
3845 swxc1, sdxc1, suxc1) stores, as long as the four stores are to
3846 different doublewords on the line. If the floating point unit is
3847 running in 1:2 mode, it is not possible to create the sequence above
3848 using only floating point store instructions.
3850 In this case, the cache line being filled is incorrectly marked
3851 invalid, thereby losing the data from any store to the line that
3852 occurs between the original miss and the completion of the five
3853 cycle sequence shown above.
3855 The workarounds are:
3857 * Run the data cache in write-through mode.
3858 * Insert a non-store instruction between
3859 Store A and Store B or Store B and Store C. */
3862 nops_for_24k (int ignore, const struct mips_cl_insn *hist,
3863 const struct mips_cl_insn *insn)
3865 struct fix_24k_store_info pos[3];
3866 int align, i, base_offset;
3871 /* If the previous instruction wasn't a store, there's nothing to
3873 if ((hist[0].insn_mo->pinfo & INSN_STORE_MEMORY) == 0)
3876 /* If the instructions after the previous one are unknown, we have
3877 to assume the worst. */
3881 /* Check whether we are dealing with three consecutive stores. */
3882 if ((insn->insn_mo->pinfo & INSN_STORE_MEMORY) == 0
3883 || (hist[1].insn_mo->pinfo & INSN_STORE_MEMORY) == 0)
3886 /* If we don't know the relationship between the store addresses,
3887 assume the worst. */
3888 if (!BASE_REG_EQ (insn->insn_opcode, hist[0].insn_opcode)
3889 || !BASE_REG_EQ (insn->insn_opcode, hist[1].insn_opcode))
3892 if (!fix_24k_record_store_info (&pos[0], insn)
3893 || !fix_24k_record_store_info (&pos[1], &hist[0])
3894 || !fix_24k_record_store_info (&pos[2], &hist[1]))
3897 qsort (&pos, 3, sizeof (struct fix_24k_store_info), fix_24k_sort);
3899 /* Pick a value of ALIGN and X such that all offsets are adjusted by
3900 X bytes and such that the base register + X is known to be aligned
3903 if (((insn->insn_opcode >> OP_SH_RS) & OP_MASK_RS) == SP)
3907 align = pos[0].align_to;
3908 base_offset = pos[0].off;
3909 for (i = 1; i < 3; i++)
3910 if (align < pos[i].align_to)
3912 align = pos[i].align_to;
3913 base_offset = pos[i].off;
3915 for (i = 0; i < 3; i++)
3916 pos[i].off -= base_offset;
3919 pos[0].off &= ~align + 1;
3920 pos[1].off &= ~align + 1;
3921 pos[2].off &= ~align + 1;
3923 /* If any two stores write to the same chunk, they also write to the
3924 same doubleword. The offsets are still sorted at this point. */
3925 if (pos[0].off == pos[1].off || pos[1].off == pos[2].off)
3928 /* A range of at least 9 bytes is needed for the stores to be in
3929 non-overlapping doublewords. */
3930 if (pos[2].off - pos[0].off <= 8)
3933 if (pos[2].off - pos[1].off >= 24
3934 || pos[1].off - pos[0].off >= 24
3935 || pos[2].off - pos[0].off >= 32)
3941 /* Return the number of nops that would be needed if instruction INSN
3942 immediately followed the MAX_NOPS instructions given by HIST,
3943 where HIST[0] is the most recent instruction. Ignore hazards
3944 between INSN and the first IGNORE instructions in HIST.
3946 If INSN is null, return the worse-case number of nops for any
3950 nops_for_insn (int ignore, const struct mips_cl_insn *hist,
3951 const struct mips_cl_insn *insn)
3953 int i, nops, tmp_nops;
3956 for (i = ignore; i < MAX_DELAY_NOPS; i++)
3958 tmp_nops = insns_between (hist + i, insn) - i;
3959 if (tmp_nops > nops)
3963 if (mips_fix_vr4130 && !mips_opts.micromips)
3965 tmp_nops = nops_for_vr4130 (ignore, hist, insn);
3966 if (tmp_nops > nops)
3970 if (mips_fix_24k && !mips_opts.micromips)
3972 tmp_nops = nops_for_24k (ignore, hist, insn);
3973 if (tmp_nops > nops)
3980 /* The variable arguments provide NUM_INSNS extra instructions that
3981 might be added to HIST. Return the largest number of nops that
3982 would be needed after the extended sequence, ignoring hazards
3983 in the first IGNORE instructions. */
3986 nops_for_sequence (int num_insns, int ignore,
3987 const struct mips_cl_insn *hist, ...)
3990 struct mips_cl_insn buffer[MAX_NOPS];
3991 struct mips_cl_insn *cursor;
3994 va_start (args, hist);
3995 cursor = buffer + num_insns;
3996 memcpy (cursor, hist, (MAX_NOPS - num_insns) * sizeof (*cursor));
3997 while (cursor > buffer)
3998 *--cursor = *va_arg (args, const struct mips_cl_insn *);
4000 nops = nops_for_insn (ignore, buffer, NULL);
4005 /* Like nops_for_insn, but if INSN is a branch, take into account the
4006 worst-case delay for the branch target. */
4009 nops_for_insn_or_target (int ignore, const struct mips_cl_insn *hist,
4010 const struct mips_cl_insn *insn)
4014 nops = nops_for_insn (ignore, hist, insn);
4015 if (delayed_branch_p (insn))
4017 tmp_nops = nops_for_sequence (2, ignore ? ignore + 2 : 0,
4018 hist, insn, get_delay_slot_nop (insn));
4019 if (tmp_nops > nops)
4022 else if (compact_branch_p (insn))
4024 tmp_nops = nops_for_sequence (1, ignore ? ignore + 1 : 0, hist, insn);
4025 if (tmp_nops > nops)
4031 /* Fix NOP issue: Replace nops by "or at,at,zero". */
4034 fix_loongson2f_nop (struct mips_cl_insn * ip)
4036 gas_assert (!HAVE_CODE_COMPRESSION);
4037 if (strcmp (ip->insn_mo->name, "nop") == 0)
4038 ip->insn_opcode = LOONGSON2F_NOP_INSN;
4041 /* Fix Jump Issue: Eliminate instruction fetch from outside 256M region
4042 jr target pc &= 'hffff_ffff_cfff_ffff. */
4045 fix_loongson2f_jump (struct mips_cl_insn * ip)
4047 gas_assert (!HAVE_CODE_COMPRESSION);
4048 if (strcmp (ip->insn_mo->name, "j") == 0
4049 || strcmp (ip->insn_mo->name, "jr") == 0
4050 || strcmp (ip->insn_mo->name, "jalr") == 0)
4058 sreg = EXTRACT_OPERAND (0, RS, *ip);
4059 if (sreg == ZERO || sreg == KT0 || sreg == KT1 || sreg == ATREG)
4062 ep.X_op = O_constant;
4063 ep.X_add_number = 0xcfff0000;
4064 macro_build (&ep, "lui", "t,u", ATREG, BFD_RELOC_HI16);
4065 ep.X_add_number = 0xffff;
4066 macro_build (&ep, "ori", "t,r,i", ATREG, ATREG, BFD_RELOC_LO16);
4067 macro_build (NULL, "and", "d,v,t", sreg, sreg, ATREG);
4072 fix_loongson2f (struct mips_cl_insn * ip)
4074 if (mips_fix_loongson2f_nop)
4075 fix_loongson2f_nop (ip);
4077 if (mips_fix_loongson2f_jump)
4078 fix_loongson2f_jump (ip);
4081 /* IP is a branch that has a delay slot, and we need to fill it
4082 automatically. Return true if we can do that by swapping IP
4083 with the previous instruction.
4084 ADDRESS_EXPR is an operand of the instruction to be used with
4088 can_swap_branch_p (struct mips_cl_insn *ip, expressionS *address_expr,
4089 bfd_reloc_code_real_type *reloc_type)
4091 unsigned long pinfo, pinfo2, prev_pinfo, prev_pinfo2;
4092 unsigned int gpr_read, gpr_write, prev_gpr_read, prev_gpr_write;
4094 /* -O2 and above is required for this optimization. */
4095 if (mips_optimize < 2)
4098 /* If we have seen .set volatile or .set nomove, don't optimize. */
4099 if (mips_opts.nomove)
4102 /* We can't swap if the previous instruction's position is fixed. */
4103 if (history[0].fixed_p)
4106 /* If the previous previous insn was in a .set noreorder, we can't
4107 swap. Actually, the MIPS assembler will swap in this situation.
4108 However, gcc configured -with-gnu-as will generate code like
4116 in which we can not swap the bne and INSN. If gcc is not configured
4117 -with-gnu-as, it does not output the .set pseudo-ops. */
4118 if (history[1].noreorder_p)
4121 /* If the previous instruction had a fixup in mips16 mode, we can not swap.
4122 This means that the previous instruction was a 4-byte one anyhow. */
4123 if (mips_opts.mips16 && history[0].fixp[0])
4126 /* If the branch is itself the target of a branch, we can not swap.
4127 We cheat on this; all we check for is whether there is a label on
4128 this instruction. If there are any branches to anything other than
4129 a label, users must use .set noreorder. */
4130 if (seg_info (now_seg)->label_list)
4133 /* If the previous instruction is in a variant frag other than this
4134 branch's one, we cannot do the swap. This does not apply to
4135 MIPS16 code, which uses variant frags for different purposes. */
4136 if (!mips_opts.mips16
4138 && history[0].frag->fr_type == rs_machine_dependent)
4141 /* We do not swap with instructions that cannot architecturally
4142 be placed in a branch delay slot, such as SYNC or ERET. We
4143 also refrain from swapping with a trap instruction, since it
4144 complicates trap handlers to have the trap instruction be in
4146 prev_pinfo = history[0].insn_mo->pinfo;
4147 if (prev_pinfo & INSN_NO_DELAY_SLOT)
4150 /* Check for conflicts between the branch and the instructions
4151 before the candidate delay slot. */
4152 if (nops_for_insn (0, history + 1, ip) > 0)
4155 /* Check for conflicts between the swapped sequence and the
4156 target of the branch. */
4157 if (nops_for_sequence (2, 0, history + 1, ip, history) > 0)
4160 /* If the branch reads a register that the previous
4161 instruction sets, we can not swap. */
4162 gpr_read = gpr_read_mask (ip);
4163 prev_gpr_write = gpr_write_mask (&history[0]);
4164 if (gpr_read & prev_gpr_write)
4167 /* If the branch writes a register that the previous
4168 instruction sets, we can not swap. */
4169 gpr_write = gpr_write_mask (ip);
4170 if (gpr_write & prev_gpr_write)
4173 /* If the branch writes a register that the previous
4174 instruction reads, we can not swap. */
4175 prev_gpr_read = gpr_read_mask (&history[0]);
4176 if (gpr_write & prev_gpr_read)
4179 /* If one instruction sets a condition code and the
4180 other one uses a condition code, we can not swap. */
4181 pinfo = ip->insn_mo->pinfo;
4182 if ((pinfo & INSN_READ_COND_CODE)
4183 && (prev_pinfo & INSN_WRITE_COND_CODE))
4185 if ((pinfo & INSN_WRITE_COND_CODE)
4186 && (prev_pinfo & INSN_READ_COND_CODE))
4189 /* If the previous instruction uses the PC, we can not swap. */
4190 prev_pinfo2 = history[0].insn_mo->pinfo2;
4191 if (mips_opts.mips16 && (prev_pinfo & MIPS16_INSN_READ_PC))
4193 if (mips_opts.micromips && (prev_pinfo2 & INSN2_READ_PC))
4196 /* If the previous instruction has an incorrect size for a fixed
4197 branch delay slot in microMIPS mode, we cannot swap. */
4198 pinfo2 = ip->insn_mo->pinfo2;
4199 if (mips_opts.micromips
4200 && (pinfo2 & INSN2_BRANCH_DELAY_16BIT)
4201 && insn_length (history) != 2)
4203 if (mips_opts.micromips
4204 && (pinfo2 & INSN2_BRANCH_DELAY_32BIT)
4205 && insn_length (history) != 4)
4208 /* On R5900 short loops need to be fixed by inserting a nop in
4209 the branch delay slots.
4210 A short loop can be terminated too early. */
4211 if (mips_opts.arch == CPU_R5900
4212 /* Check if instruction has a parameter, ignore "j $31". */
4213 && (address_expr != NULL)
4214 /* Parameter must be 16 bit. */
4215 && (*reloc_type == BFD_RELOC_16_PCREL_S2)
4216 /* Branch to same segment. */
4217 && (S_GET_SEGMENT(address_expr->X_add_symbol) == now_seg)
4218 /* Branch to same code fragment. */
4219 && (symbol_get_frag(address_expr->X_add_symbol) == frag_now)
4220 /* Can only calculate branch offset if value is known. */
4221 && symbol_constant_p(address_expr->X_add_symbol)
4222 /* Check if branch is really conditional. */
4223 && !((ip->insn_opcode & 0xffff0000) == 0x10000000 /* beq $0,$0 */
4224 || (ip->insn_opcode & 0xffff0000) == 0x04010000 /* bgez $0 */
4225 || (ip->insn_opcode & 0xffff0000) == 0x04110000)) /* bgezal $0 */
4228 /* Check if loop is shorter than 6 instructions including
4229 branch and delay slot. */
4230 distance = frag_now_fix() - S_GET_VALUE(address_expr->X_add_symbol);
4237 /* When the loop includes branches or jumps,
4238 it is not a short loop. */
4239 for (i = 0; i < (distance / 4); i++)
4241 if ((history[i].cleared_p)
4242 || delayed_branch_p(&history[i]))
4250 /* Insert nop after branch to fix short loop. */
4259 /* Decide how we should add IP to the instruction stream.
4260 ADDRESS_EXPR is an operand of the instruction to be used with
4263 static enum append_method
4264 get_append_method (struct mips_cl_insn *ip, expressionS *address_expr,
4265 bfd_reloc_code_real_type *reloc_type)
4267 unsigned long pinfo;
4269 /* The relaxed version of a macro sequence must be inherently
4271 if (mips_relax.sequence == 2)
4274 /* We must not dabble with instructions in a ".set norerorder" block. */
4275 if (mips_opts.noreorder)
4278 /* Otherwise, it's our responsibility to fill branch delay slots. */
4279 if (delayed_branch_p (ip))
4281 if (!branch_likely_p (ip)
4282 && can_swap_branch_p (ip, address_expr, reloc_type))
4285 pinfo = ip->insn_mo->pinfo;
4286 if (mips_opts.mips16
4287 && ISA_SUPPORTS_MIPS16E
4288 && (pinfo & (MIPS16_INSN_READ_X | MIPS16_INSN_READ_31)))
4289 return APPEND_ADD_COMPACT;
4291 return APPEND_ADD_WITH_NOP;
4297 /* IP is a MIPS16 instruction whose opcode we have just changed.
4298 Point IP->insn_mo to the new opcode's definition. */
4301 find_altered_mips16_opcode (struct mips_cl_insn *ip)
4303 const struct mips_opcode *mo, *end;
4305 end = &mips16_opcodes[bfd_mips16_num_opcodes];
4306 for (mo = ip->insn_mo; mo < end; mo++)
4307 if ((ip->insn_opcode & mo->mask) == mo->match)
4315 /* For microMIPS macros, we need to generate a local number label
4316 as the target of branches. */
4317 #define MICROMIPS_LABEL_CHAR '\037'
4318 static unsigned long micromips_target_label;
4319 static char micromips_target_name[32];
4322 micromips_label_name (void)
4324 char *p = micromips_target_name;
4325 char symbol_name_temporary[24];
4333 l = micromips_target_label;
4334 #ifdef LOCAL_LABEL_PREFIX
4335 *p++ = LOCAL_LABEL_PREFIX;
4338 *p++ = MICROMIPS_LABEL_CHAR;
4341 symbol_name_temporary[i++] = l % 10 + '0';
4346 *p++ = symbol_name_temporary[--i];
4349 return micromips_target_name;
4353 micromips_label_expr (expressionS *label_expr)
4355 label_expr->X_op = O_symbol;
4356 label_expr->X_add_symbol = symbol_find_or_make (micromips_label_name ());
4357 label_expr->X_add_number = 0;
4361 micromips_label_inc (void)
4363 micromips_target_label++;
4364 *micromips_target_name = '\0';
4368 micromips_add_label (void)
4372 s = colon (micromips_label_name ());
4373 micromips_label_inc ();
4374 S_SET_OTHER (s, ELF_ST_SET_MICROMIPS (S_GET_OTHER (s)));
4377 /* If assembling microMIPS code, then return the microMIPS reloc
4378 corresponding to the requested one if any. Otherwise return
4379 the reloc unchanged. */
4381 static bfd_reloc_code_real_type
4382 micromips_map_reloc (bfd_reloc_code_real_type reloc)
4384 static const bfd_reloc_code_real_type relocs[][2] =
4386 /* Keep sorted incrementally by the left-hand key. */
4387 { BFD_RELOC_16_PCREL_S2, BFD_RELOC_MICROMIPS_16_PCREL_S1 },
4388 { BFD_RELOC_GPREL16, BFD_RELOC_MICROMIPS_GPREL16 },
4389 { BFD_RELOC_MIPS_JMP, BFD_RELOC_MICROMIPS_JMP },
4390 { BFD_RELOC_HI16, BFD_RELOC_MICROMIPS_HI16 },
4391 { BFD_RELOC_HI16_S, BFD_RELOC_MICROMIPS_HI16_S },
4392 { BFD_RELOC_LO16, BFD_RELOC_MICROMIPS_LO16 },
4393 { BFD_RELOC_MIPS_LITERAL, BFD_RELOC_MICROMIPS_LITERAL },
4394 { BFD_RELOC_MIPS_GOT16, BFD_RELOC_MICROMIPS_GOT16 },
4395 { BFD_RELOC_MIPS_CALL16, BFD_RELOC_MICROMIPS_CALL16 },
4396 { BFD_RELOC_MIPS_GOT_HI16, BFD_RELOC_MICROMIPS_GOT_HI16 },
4397 { BFD_RELOC_MIPS_GOT_LO16, BFD_RELOC_MICROMIPS_GOT_LO16 },
4398 { BFD_RELOC_MIPS_CALL_HI16, BFD_RELOC_MICROMIPS_CALL_HI16 },
4399 { BFD_RELOC_MIPS_CALL_LO16, BFD_RELOC_MICROMIPS_CALL_LO16 },
4400 { BFD_RELOC_MIPS_SUB, BFD_RELOC_MICROMIPS_SUB },
4401 { BFD_RELOC_MIPS_GOT_PAGE, BFD_RELOC_MICROMIPS_GOT_PAGE },
4402 { BFD_RELOC_MIPS_GOT_OFST, BFD_RELOC_MICROMIPS_GOT_OFST },
4403 { BFD_RELOC_MIPS_GOT_DISP, BFD_RELOC_MICROMIPS_GOT_DISP },
4404 { BFD_RELOC_MIPS_HIGHEST, BFD_RELOC_MICROMIPS_HIGHEST },
4405 { BFD_RELOC_MIPS_HIGHER, BFD_RELOC_MICROMIPS_HIGHER },
4406 { BFD_RELOC_MIPS_SCN_DISP, BFD_RELOC_MICROMIPS_SCN_DISP },
4407 { BFD_RELOC_MIPS_TLS_GD, BFD_RELOC_MICROMIPS_TLS_GD },
4408 { BFD_RELOC_MIPS_TLS_LDM, BFD_RELOC_MICROMIPS_TLS_LDM },
4409 { BFD_RELOC_MIPS_TLS_DTPREL_HI16, BFD_RELOC_MICROMIPS_TLS_DTPREL_HI16 },
4410 { BFD_RELOC_MIPS_TLS_DTPREL_LO16, BFD_RELOC_MICROMIPS_TLS_DTPREL_LO16 },
4411 { BFD_RELOC_MIPS_TLS_GOTTPREL, BFD_RELOC_MICROMIPS_TLS_GOTTPREL },
4412 { BFD_RELOC_MIPS_TLS_TPREL_HI16, BFD_RELOC_MICROMIPS_TLS_TPREL_HI16 },
4413 { BFD_RELOC_MIPS_TLS_TPREL_LO16, BFD_RELOC_MICROMIPS_TLS_TPREL_LO16 }
4415 bfd_reloc_code_real_type r;
4418 if (!mips_opts.micromips)
4420 for (i = 0; i < ARRAY_SIZE (relocs); i++)
4426 return relocs[i][1];
4431 /* Try to resolve relocation RELOC against constant OPERAND at assembly time.
4432 Return true on success, storing the resolved value in RESULT. */
4435 calculate_reloc (bfd_reloc_code_real_type reloc, offsetT operand,
4440 case BFD_RELOC_MIPS_HIGHEST:
4441 case BFD_RELOC_MICROMIPS_HIGHEST:
4442 *result = ((operand + 0x800080008000ull) >> 48) & 0xffff;
4445 case BFD_RELOC_MIPS_HIGHER:
4446 case BFD_RELOC_MICROMIPS_HIGHER:
4447 *result = ((operand + 0x80008000ull) >> 32) & 0xffff;
4450 case BFD_RELOC_HI16_S:
4451 case BFD_RELOC_MICROMIPS_HI16_S:
4452 case BFD_RELOC_MIPS16_HI16_S:
4453 *result = ((operand + 0x8000) >> 16) & 0xffff;
4456 case BFD_RELOC_HI16:
4457 case BFD_RELOC_MICROMIPS_HI16:
4458 case BFD_RELOC_MIPS16_HI16:
4459 *result = (operand >> 16) & 0xffff;
4462 case BFD_RELOC_LO16:
4463 case BFD_RELOC_MICROMIPS_LO16:
4464 case BFD_RELOC_MIPS16_LO16:
4465 *result = operand & 0xffff;
4468 case BFD_RELOC_UNUSED:
4477 /* Output an instruction. IP is the instruction information.
4478 ADDRESS_EXPR is an operand of the instruction to be used with
4479 RELOC_TYPE. EXPANSIONP is true if the instruction is part of
4480 a macro expansion. */
4483 append_insn (struct mips_cl_insn *ip, expressionS *address_expr,
4484 bfd_reloc_code_real_type *reloc_type, bfd_boolean expansionp)
4486 unsigned long prev_pinfo2, pinfo;
4487 bfd_boolean relaxed_branch = FALSE;
4488 enum append_method method;
4489 bfd_boolean relax32;
4492 if (mips_fix_loongson2f && !HAVE_CODE_COMPRESSION)
4493 fix_loongson2f (ip);
4495 file_ase_mips16 |= mips_opts.mips16;
4496 file_ase_micromips |= mips_opts.micromips;
4498 prev_pinfo2 = history[0].insn_mo->pinfo2;
4499 pinfo = ip->insn_mo->pinfo;
4501 if (mips_opts.micromips
4503 && (((prev_pinfo2 & INSN2_BRANCH_DELAY_16BIT) != 0
4504 && micromips_insn_length (ip->insn_mo) != 2)
4505 || ((prev_pinfo2 & INSN2_BRANCH_DELAY_32BIT) != 0
4506 && micromips_insn_length (ip->insn_mo) != 4)))
4507 as_warn (_("Wrong size instruction in a %u-bit branch delay slot"),
4508 (prev_pinfo2 & INSN2_BRANCH_DELAY_16BIT) != 0 ? 16 : 32);
4510 if (address_expr == NULL)
4512 else if (reloc_type[0] <= BFD_RELOC_UNUSED
4513 && reloc_type[1] == BFD_RELOC_UNUSED
4514 && reloc_type[2] == BFD_RELOC_UNUSED
4515 && address_expr->X_op == O_constant)
4517 switch (*reloc_type)
4519 case BFD_RELOC_MIPS_JMP:
4523 shift = mips_opts.micromips ? 1 : 2;
4524 if ((address_expr->X_add_number & ((1 << shift) - 1)) != 0)
4525 as_bad (_("jump to misaligned address (0x%lx)"),
4526 (unsigned long) address_expr->X_add_number);
4527 ip->insn_opcode |= ((address_expr->X_add_number >> shift)
4533 case BFD_RELOC_MIPS16_JMP:
4534 if ((address_expr->X_add_number & 3) != 0)
4535 as_bad (_("jump to misaligned address (0x%lx)"),
4536 (unsigned long) address_expr->X_add_number);
4538 (((address_expr->X_add_number & 0x7c0000) << 3)
4539 | ((address_expr->X_add_number & 0xf800000) >> 7)
4540 | ((address_expr->X_add_number & 0x3fffc) >> 2));
4544 case BFD_RELOC_16_PCREL_S2:
4548 shift = mips_opts.micromips ? 1 : 2;
4549 if ((address_expr->X_add_number & ((1 << shift) - 1)) != 0)
4550 as_bad (_("branch to misaligned address (0x%lx)"),
4551 (unsigned long) address_expr->X_add_number);
4552 if (!mips_relax_branch)
4554 if ((address_expr->X_add_number + (1 << (shift + 15)))
4555 & ~((1 << (shift + 16)) - 1))
4556 as_bad (_("branch address range overflow (0x%lx)"),
4557 (unsigned long) address_expr->X_add_number);
4558 ip->insn_opcode |= ((address_expr->X_add_number >> shift)
4568 if (calculate_reloc (*reloc_type, address_expr->X_add_number,
4571 ip->insn_opcode |= value & 0xffff;
4579 if (mips_relax.sequence != 2 && !mips_opts.noreorder)
4581 /* There are a lot of optimizations we could do that we don't.
4582 In particular, we do not, in general, reorder instructions.
4583 If you use gcc with optimization, it will reorder
4584 instructions and generally do much more optimization then we
4585 do here; repeating all that work in the assembler would only
4586 benefit hand written assembly code, and does not seem worth
4588 int nops = (mips_optimize == 0
4589 ? nops_for_insn (0, history, NULL)
4590 : nops_for_insn_or_target (0, history, ip));
4594 unsigned long old_frag_offset;
4597 old_frag = frag_now;
4598 old_frag_offset = frag_now_fix ();
4600 for (i = 0; i < nops; i++)
4601 add_fixed_insn (NOP_INSN);
4602 insert_into_history (0, nops, NOP_INSN);
4606 listing_prev_line ();
4607 /* We may be at the start of a variant frag. In case we
4608 are, make sure there is enough space for the frag
4609 after the frags created by listing_prev_line. The
4610 argument to frag_grow here must be at least as large
4611 as the argument to all other calls to frag_grow in
4612 this file. We don't have to worry about being in the
4613 middle of a variant frag, because the variants insert
4614 all needed nop instructions themselves. */
4618 mips_move_text_labels ();
4620 #ifndef NO_ECOFF_DEBUGGING
4621 if (ECOFF_DEBUGGING)
4622 ecoff_fix_loc (old_frag, old_frag_offset);
4626 else if (mips_relax.sequence != 2 && prev_nop_frag != NULL)
4630 /* Work out how many nops in prev_nop_frag are needed by IP,
4631 ignoring hazards generated by the first prev_nop_frag_since
4633 nops = nops_for_insn_or_target (prev_nop_frag_since, history, ip);
4634 gas_assert (nops <= prev_nop_frag_holds);
4636 /* Enforce NOPS as a minimum. */
4637 if (nops > prev_nop_frag_required)
4638 prev_nop_frag_required = nops;
4640 if (prev_nop_frag_holds == prev_nop_frag_required)
4642 /* Settle for the current number of nops. Update the history
4643 accordingly (for the benefit of any future .set reorder code). */
4644 prev_nop_frag = NULL;
4645 insert_into_history (prev_nop_frag_since,
4646 prev_nop_frag_holds, NOP_INSN);
4650 /* Allow this instruction to replace one of the nops that was
4651 tentatively added to prev_nop_frag. */
4652 prev_nop_frag->fr_fix -= NOP_INSN_SIZE;
4653 prev_nop_frag_holds--;
4654 prev_nop_frag_since++;
4658 method = get_append_method (ip, address_expr, reloc_type);
4659 branch_disp = method == APPEND_SWAP ? insn_length (history) : 0;
4661 dwarf2_emit_insn (0);
4662 /* We want MIPS16 and microMIPS debug info to use ISA-encoded addresses,
4663 so "move" the instruction address accordingly.
4665 Also, it doesn't seem appropriate for the assembler to reorder .loc
4666 entries. If this instruction is a branch that we are going to swap
4667 with the previous instruction, the two instructions should be
4668 treated as a unit, and the debug information for both instructions
4669 should refer to the start of the branch sequence. Using the
4670 current position is certainly wrong when swapping a 32-bit branch
4671 and a 16-bit delay slot, since the current position would then be
4672 in the middle of a branch. */
4673 dwarf2_move_insn ((HAVE_CODE_COMPRESSION ? 1 : 0) - branch_disp);
4675 relax32 = (mips_relax_branch
4676 /* Don't try branch relaxation within .set nomacro, or within
4677 .set noat if we use $at for PIC computations. If it turns
4678 out that the branch was out-of-range, we'll get an error. */
4679 && !mips_opts.warn_about_macros
4680 && (mips_opts.at || mips_pic == NO_PIC)
4681 /* Don't relax BPOSGE32/64 or BC1ANY2T/F and BC1ANY4T/F
4682 as they have no complementing branches. */
4683 && !(ip->insn_mo->ase & (ASE_MIPS3D | ASE_DSP64 | ASE_DSP)));
4685 if (!HAVE_CODE_COMPRESSION
4688 && *reloc_type == BFD_RELOC_16_PCREL_S2
4689 && delayed_branch_p (ip))
4691 relaxed_branch = TRUE;
4692 add_relaxed_insn (ip, (relaxed_branch_length
4694 uncond_branch_p (ip) ? -1
4695 : branch_likely_p (ip) ? 1
4699 uncond_branch_p (ip),
4700 branch_likely_p (ip),
4701 pinfo & INSN_WRITE_GPR_31,
4703 address_expr->X_add_symbol,
4704 address_expr->X_add_number);
4705 *reloc_type = BFD_RELOC_UNUSED;
4707 else if (mips_opts.micromips
4709 && ((relax32 && *reloc_type == BFD_RELOC_16_PCREL_S2)
4710 || *reloc_type > BFD_RELOC_UNUSED)
4711 && (delayed_branch_p (ip) || compact_branch_p (ip))
4712 /* Don't try branch relaxation when users specify
4713 16-bit/32-bit instructions. */
4714 && !forced_insn_length)
4716 bfd_boolean relax16 = *reloc_type > BFD_RELOC_UNUSED;
4717 int type = relax16 ? *reloc_type - BFD_RELOC_UNUSED : 0;
4718 int uncond = uncond_branch_p (ip) ? -1 : 0;
4719 int compact = compact_branch_p (ip);
4720 int al = pinfo & INSN_WRITE_GPR_31;
4723 gas_assert (address_expr != NULL);
4724 gas_assert (!mips_relax.sequence);
4726 relaxed_branch = TRUE;
4727 length32 = relaxed_micromips_32bit_branch_length (NULL, NULL, uncond);
4728 add_relaxed_insn (ip, relax32 ? length32 : 4, relax16 ? 2 : 4,
4729 RELAX_MICROMIPS_ENCODE (type, AT, uncond, compact, al,
4731 address_expr->X_add_symbol,
4732 address_expr->X_add_number);
4733 *reloc_type = BFD_RELOC_UNUSED;
4735 else if (mips_opts.mips16 && *reloc_type > BFD_RELOC_UNUSED)
4737 /* We need to set up a variant frag. */
4738 gas_assert (address_expr != NULL);
4739 add_relaxed_insn (ip, 4, 0,
4741 (*reloc_type - BFD_RELOC_UNUSED,
4742 forced_insn_length == 2, forced_insn_length == 4,
4743 delayed_branch_p (&history[0]),
4744 history[0].mips16_absolute_jump_p),
4745 make_expr_symbol (address_expr), 0);
4747 else if (mips_opts.mips16 && insn_length (ip) == 2)
4749 if (!delayed_branch_p (ip))
4750 /* Make sure there is enough room to swap this instruction with
4751 a following jump instruction. */
4753 add_fixed_insn (ip);
4757 if (mips_opts.mips16
4758 && mips_opts.noreorder
4759 && delayed_branch_p (&history[0]))
4760 as_warn (_("extended instruction in delay slot"));
4762 if (mips_relax.sequence)
4764 /* If we've reached the end of this frag, turn it into a variant
4765 frag and record the information for the instructions we've
4767 if (frag_room () < 4)
4768 relax_close_frag ();
4769 mips_relax.sizes[mips_relax.sequence - 1] += insn_length (ip);
4772 if (mips_relax.sequence != 2)
4774 if (mips_macro_warning.first_insn_sizes[0] == 0)
4775 mips_macro_warning.first_insn_sizes[0] = insn_length (ip);
4776 mips_macro_warning.sizes[0] += insn_length (ip);
4777 mips_macro_warning.insns[0]++;
4779 if (mips_relax.sequence != 1)
4781 if (mips_macro_warning.first_insn_sizes[1] == 0)
4782 mips_macro_warning.first_insn_sizes[1] = insn_length (ip);
4783 mips_macro_warning.sizes[1] += insn_length (ip);
4784 mips_macro_warning.insns[1]++;
4787 if (mips_opts.mips16)
4790 ip->mips16_absolute_jump_p = (*reloc_type == BFD_RELOC_MIPS16_JMP);
4792 add_fixed_insn (ip);
4795 if (!ip->complete_p && *reloc_type < BFD_RELOC_UNUSED)
4797 bfd_reloc_code_real_type final_type[3];
4798 reloc_howto_type *howto0;
4799 reloc_howto_type *howto;
4802 /* Perform any necessary conversion to microMIPS relocations
4803 and find out how many relocations there actually are. */
4804 for (i = 0; i < 3 && reloc_type[i] != BFD_RELOC_UNUSED; i++)
4805 final_type[i] = micromips_map_reloc (reloc_type[i]);
4807 /* In a compound relocation, it is the final (outermost)
4808 operator that determines the relocated field. */
4809 howto = howto0 = bfd_reloc_type_lookup (stdoutput, final_type[i - 1]);
4814 howto0 = bfd_reloc_type_lookup (stdoutput, final_type[0]);
4815 ip->fixp[0] = fix_new_exp (ip->frag, ip->where,
4816 bfd_get_reloc_size (howto),
4818 howto0 && howto0->pc_relative,
4821 /* Tag symbols that have a R_MIPS16_26 relocation against them. */
4822 if (final_type[0] == BFD_RELOC_MIPS16_JMP && ip->fixp[0]->fx_addsy)
4823 *symbol_get_tc (ip->fixp[0]->fx_addsy) = 1;
4825 /* These relocations can have an addend that won't fit in
4826 4 octets for 64bit assembly. */
4828 && ! howto->partial_inplace
4829 && (reloc_type[0] == BFD_RELOC_16
4830 || reloc_type[0] == BFD_RELOC_32
4831 || reloc_type[0] == BFD_RELOC_MIPS_JMP
4832 || reloc_type[0] == BFD_RELOC_GPREL16
4833 || reloc_type[0] == BFD_RELOC_MIPS_LITERAL
4834 || reloc_type[0] == BFD_RELOC_GPREL32
4835 || reloc_type[0] == BFD_RELOC_64
4836 || reloc_type[0] == BFD_RELOC_CTOR
4837 || reloc_type[0] == BFD_RELOC_MIPS_SUB
4838 || reloc_type[0] == BFD_RELOC_MIPS_HIGHEST
4839 || reloc_type[0] == BFD_RELOC_MIPS_HIGHER
4840 || reloc_type[0] == BFD_RELOC_MIPS_SCN_DISP
4841 || reloc_type[0] == BFD_RELOC_MIPS_REL16
4842 || reloc_type[0] == BFD_RELOC_MIPS_RELGOT
4843 || reloc_type[0] == BFD_RELOC_MIPS16_GPREL
4844 || hi16_reloc_p (reloc_type[0])
4845 || lo16_reloc_p (reloc_type[0])))
4846 ip->fixp[0]->fx_no_overflow = 1;
4848 /* These relocations can have an addend that won't fit in 2 octets. */
4849 if (reloc_type[0] == BFD_RELOC_MICROMIPS_7_PCREL_S1
4850 || reloc_type[0] == BFD_RELOC_MICROMIPS_10_PCREL_S1)
4851 ip->fixp[0]->fx_no_overflow = 1;
4853 if (mips_relax.sequence)
4855 if (mips_relax.first_fixup == 0)
4856 mips_relax.first_fixup = ip->fixp[0];
4858 else if (reloc_needs_lo_p (*reloc_type))
4860 struct mips_hi_fixup *hi_fixup;
4862 /* Reuse the last entry if it already has a matching %lo. */
4863 hi_fixup = mips_hi_fixup_list;
4865 || !fixup_has_matching_lo_p (hi_fixup->fixp))
4867 hi_fixup = ((struct mips_hi_fixup *)
4868 xmalloc (sizeof (struct mips_hi_fixup)));
4869 hi_fixup->next = mips_hi_fixup_list;
4870 mips_hi_fixup_list = hi_fixup;
4872 hi_fixup->fixp = ip->fixp[0];
4873 hi_fixup->seg = now_seg;
4876 /* Add fixups for the second and third relocations, if given.
4877 Note that the ABI allows the second relocation to be
4878 against RSS_UNDEF, RSS_GP, RSS_GP0 or RSS_LOC. At the
4879 moment we only use RSS_UNDEF, but we could add support
4880 for the others if it ever becomes necessary. */
4881 for (i = 1; i < 3; i++)
4882 if (reloc_type[i] != BFD_RELOC_UNUSED)
4884 ip->fixp[i] = fix_new (ip->frag, ip->where,
4885 ip->fixp[0]->fx_size, NULL, 0,
4886 FALSE, final_type[i]);
4888 /* Use fx_tcbit to mark compound relocs. */
4889 ip->fixp[0]->fx_tcbit = 1;
4890 ip->fixp[i]->fx_tcbit = 1;
4895 /* Update the register mask information. */
4896 mips_gprmask |= gpr_read_mask (ip) | gpr_write_mask (ip);
4897 mips_cprmask[1] |= fpr_read_mask (ip) | fpr_write_mask (ip);
4902 insert_into_history (0, 1, ip);
4905 case APPEND_ADD_WITH_NOP:
4907 struct mips_cl_insn *nop;
4909 insert_into_history (0, 1, ip);
4910 nop = get_delay_slot_nop (ip);
4911 add_fixed_insn (nop);
4912 insert_into_history (0, 1, nop);
4913 if (mips_relax.sequence)
4914 mips_relax.sizes[mips_relax.sequence - 1] += insn_length (nop);
4918 case APPEND_ADD_COMPACT:
4919 /* Convert MIPS16 jr/jalr into a "compact" jump. */
4920 gas_assert (mips_opts.mips16);
4921 ip->insn_opcode |= 0x0080;
4922 find_altered_mips16_opcode (ip);
4924 insert_into_history (0, 1, ip);
4929 struct mips_cl_insn delay = history[0];
4930 if (mips_opts.mips16)
4932 know (delay.frag == ip->frag);
4933 move_insn (ip, delay.frag, delay.where);
4934 move_insn (&delay, ip->frag, ip->where + insn_length (ip));
4936 else if (relaxed_branch || delay.frag != ip->frag)
4938 /* Add the delay slot instruction to the end of the
4939 current frag and shrink the fixed part of the
4940 original frag. If the branch occupies the tail of
4941 the latter, move it backwards to cover the gap. */
4942 delay.frag->fr_fix -= branch_disp;
4943 if (delay.frag == ip->frag)
4944 move_insn (ip, ip->frag, ip->where - branch_disp);
4945 add_fixed_insn (&delay);
4949 move_insn (&delay, ip->frag,
4950 ip->where - branch_disp + insn_length (ip));
4951 move_insn (ip, history[0].frag, history[0].where);
4955 insert_into_history (0, 1, &delay);
4960 /* If we have just completed an unconditional branch, clear the history. */
4961 if ((delayed_branch_p (&history[1]) && uncond_branch_p (&history[1]))
4962 || (compact_branch_p (&history[0]) && uncond_branch_p (&history[0])))
4966 mips_no_prev_insn ();
4968 for (i = 0; i < ARRAY_SIZE (history); i++)
4969 history[i].cleared_p = 1;
4972 /* We need to emit a label at the end of branch-likely macros. */
4973 if (emit_branch_likely_macro)
4975 emit_branch_likely_macro = FALSE;
4976 micromips_add_label ();
4979 /* We just output an insn, so the next one doesn't have a label. */
4980 mips_clear_insn_labels ();
4983 /* Forget that there was any previous instruction or label.
4984 When BRANCH is true, the branch history is also flushed. */
4987 mips_no_prev_insn (void)
4989 prev_nop_frag = NULL;
4990 insert_into_history (0, ARRAY_SIZE (history), NOP_INSN);
4991 mips_clear_insn_labels ();
4994 /* This function must be called before we emit something other than
4995 instructions. It is like mips_no_prev_insn except that it inserts
4996 any NOPS that might be needed by previous instructions. */
4999 mips_emit_delays (void)
5001 if (! mips_opts.noreorder)
5003 int nops = nops_for_insn (0, history, NULL);
5007 add_fixed_insn (NOP_INSN);
5008 mips_move_text_labels ();
5011 mips_no_prev_insn ();
5014 /* Start a (possibly nested) noreorder block. */
5017 start_noreorder (void)
5019 if (mips_opts.noreorder == 0)
5024 /* None of the instructions before the .set noreorder can be moved. */
5025 for (i = 0; i < ARRAY_SIZE (history); i++)
5026 history[i].fixed_p = 1;
5028 /* Insert any nops that might be needed between the .set noreorder
5029 block and the previous instructions. We will later remove any
5030 nops that turn out not to be needed. */
5031 nops = nops_for_insn (0, history, NULL);
5034 if (mips_optimize != 0)
5036 /* Record the frag which holds the nop instructions, so
5037 that we can remove them if we don't need them. */
5038 frag_grow (nops * NOP_INSN_SIZE);
5039 prev_nop_frag = frag_now;
5040 prev_nop_frag_holds = nops;
5041 prev_nop_frag_required = 0;
5042 prev_nop_frag_since = 0;
5045 for (; nops > 0; --nops)
5046 add_fixed_insn (NOP_INSN);
5048 /* Move on to a new frag, so that it is safe to simply
5049 decrease the size of prev_nop_frag. */
5050 frag_wane (frag_now);
5052 mips_move_text_labels ();
5054 mips_mark_labels ();
5055 mips_clear_insn_labels ();
5057 mips_opts.noreorder++;
5058 mips_any_noreorder = 1;
5061 /* End a nested noreorder block. */
5064 end_noreorder (void)
5066 mips_opts.noreorder--;
5067 if (mips_opts.noreorder == 0 && prev_nop_frag != NULL)
5069 /* Commit to inserting prev_nop_frag_required nops and go back to
5070 handling nop insertion the .set reorder way. */
5071 prev_nop_frag->fr_fix -= ((prev_nop_frag_holds - prev_nop_frag_required)
5073 insert_into_history (prev_nop_frag_since,
5074 prev_nop_frag_required, NOP_INSN);
5075 prev_nop_frag = NULL;
5079 /* Set up global variables for the start of a new macro. */
5084 memset (&mips_macro_warning.sizes, 0, sizeof (mips_macro_warning.sizes));
5085 memset (&mips_macro_warning.first_insn_sizes, 0,
5086 sizeof (mips_macro_warning.first_insn_sizes));
5087 memset (&mips_macro_warning.insns, 0, sizeof (mips_macro_warning.insns));
5088 mips_macro_warning.delay_slot_p = (mips_opts.noreorder
5089 && delayed_branch_p (&history[0]));
5090 switch (history[0].insn_mo->pinfo2
5091 & (INSN2_BRANCH_DELAY_32BIT | INSN2_BRANCH_DELAY_16BIT))
5093 case INSN2_BRANCH_DELAY_32BIT:
5094 mips_macro_warning.delay_slot_length = 4;
5096 case INSN2_BRANCH_DELAY_16BIT:
5097 mips_macro_warning.delay_slot_length = 2;
5100 mips_macro_warning.delay_slot_length = 0;
5103 mips_macro_warning.first_frag = NULL;
5106 /* Given that a macro is longer than one instruction or of the wrong size,
5107 return the appropriate warning for it. Return null if no warning is
5108 needed. SUBTYPE is a bitmask of RELAX_DELAY_SLOT, RELAX_DELAY_SLOT_16BIT,
5109 RELAX_DELAY_SLOT_SIZE_FIRST, RELAX_DELAY_SLOT_SIZE_SECOND,
5110 and RELAX_NOMACRO. */
5113 macro_warning (relax_substateT subtype)
5115 if (subtype & RELAX_DELAY_SLOT)
5116 return _("Macro instruction expanded into multiple instructions"
5117 " in a branch delay slot");
5118 else if (subtype & RELAX_NOMACRO)
5119 return _("Macro instruction expanded into multiple instructions");
5120 else if (subtype & (RELAX_DELAY_SLOT_SIZE_FIRST
5121 | RELAX_DELAY_SLOT_SIZE_SECOND))
5122 return ((subtype & RELAX_DELAY_SLOT_16BIT)
5123 ? _("Macro instruction expanded into a wrong size instruction"
5124 " in a 16-bit branch delay slot")
5125 : _("Macro instruction expanded into a wrong size instruction"
5126 " in a 32-bit branch delay slot"));
5131 /* Finish up a macro. Emit warnings as appropriate. */
5136 /* Relaxation warning flags. */
5137 relax_substateT subtype = 0;
5139 /* Check delay slot size requirements. */
5140 if (mips_macro_warning.delay_slot_length == 2)
5141 subtype |= RELAX_DELAY_SLOT_16BIT;
5142 if (mips_macro_warning.delay_slot_length != 0)
5144 if (mips_macro_warning.delay_slot_length
5145 != mips_macro_warning.first_insn_sizes[0])
5146 subtype |= RELAX_DELAY_SLOT_SIZE_FIRST;
5147 if (mips_macro_warning.delay_slot_length
5148 != mips_macro_warning.first_insn_sizes[1])
5149 subtype |= RELAX_DELAY_SLOT_SIZE_SECOND;
5152 /* Check instruction count requirements. */
5153 if (mips_macro_warning.insns[0] > 1 || mips_macro_warning.insns[1] > 1)
5155 if (mips_macro_warning.insns[1] > mips_macro_warning.insns[0])
5156 subtype |= RELAX_SECOND_LONGER;
5157 if (mips_opts.warn_about_macros)
5158 subtype |= RELAX_NOMACRO;
5159 if (mips_macro_warning.delay_slot_p)
5160 subtype |= RELAX_DELAY_SLOT;
5163 /* If both alternatives fail to fill a delay slot correctly,
5164 emit the warning now. */
5165 if ((subtype & RELAX_DELAY_SLOT_SIZE_FIRST) != 0
5166 && (subtype & RELAX_DELAY_SLOT_SIZE_SECOND) != 0)
5171 s = subtype & (RELAX_DELAY_SLOT_16BIT
5172 | RELAX_DELAY_SLOT_SIZE_FIRST
5173 | RELAX_DELAY_SLOT_SIZE_SECOND);
5174 msg = macro_warning (s);
5176 as_warn ("%s", msg);
5180 /* If both implementations are longer than 1 instruction, then emit the
5182 if (mips_macro_warning.insns[0] > 1 && mips_macro_warning.insns[1] > 1)
5187 s = subtype & (RELAX_SECOND_LONGER | RELAX_NOMACRO | RELAX_DELAY_SLOT);
5188 msg = macro_warning (s);
5190 as_warn ("%s", msg);
5194 /* If any flags still set, then one implementation might need a warning
5195 and the other either will need one of a different kind or none at all.
5196 Pass any remaining flags over to relaxation. */
5197 if (mips_macro_warning.first_frag != NULL)
5198 mips_macro_warning.first_frag->fr_subtype |= subtype;
5201 /* Instruction operand formats used in macros that vary between
5202 standard MIPS and microMIPS code. */
5204 static const char * const brk_fmt[2] = { "c", "mF" };
5205 static const char * const cop12_fmt[2] = { "E,o(b)", "E,~(b)" };
5206 static const char * const jalr_fmt[2] = { "d,s", "t,s" };
5207 static const char * const lui_fmt[2] = { "t,u", "s,u" };
5208 static const char * const mem12_fmt[2] = { "t,o(b)", "t,~(b)" };
5209 static const char * const mfhl_fmt[2] = { "d", "mj" };
5210 static const char * const shft_fmt[2] = { "d,w,<", "t,r,<" };
5211 static const char * const trap_fmt[2] = { "s,t,q", "s,t,|" };
5213 #define BRK_FMT (brk_fmt[mips_opts.micromips])
5214 #define COP12_FMT (cop12_fmt[mips_opts.micromips])
5215 #define JALR_FMT (jalr_fmt[mips_opts.micromips])
5216 #define LUI_FMT (lui_fmt[mips_opts.micromips])
5217 #define MEM12_FMT (mem12_fmt[mips_opts.micromips])
5218 #define MFHL_FMT (mfhl_fmt[mips_opts.micromips])
5219 #define SHFT_FMT (shft_fmt[mips_opts.micromips])
5220 #define TRAP_FMT (trap_fmt[mips_opts.micromips])
5222 /* Read a macro's relocation codes from *ARGS and store them in *R.
5223 The first argument in *ARGS will be either the code for a single
5224 relocation or -1 followed by the three codes that make up a
5225 composite relocation. */
5228 macro_read_relocs (va_list *args, bfd_reloc_code_real_type *r)
5232 next = va_arg (*args, int);
5234 r[0] = (bfd_reloc_code_real_type) next;
5236 for (i = 0; i < 3; i++)
5237 r[i] = (bfd_reloc_code_real_type) va_arg (*args, int);
5240 /* Build an instruction created by a macro expansion. This is passed
5241 a pointer to the count of instructions created so far, an
5242 expression, the name of the instruction to build, an operand format
5243 string, and corresponding arguments. */
5246 macro_build (expressionS *ep, const char *name, const char *fmt, ...)
5248 const struct mips_opcode *mo = NULL;
5249 bfd_reloc_code_real_type r[3];
5250 const struct mips_opcode *amo;
5251 struct hash_control *hash;
5252 struct mips_cl_insn insn;
5255 va_start (args, fmt);
5257 if (mips_opts.mips16)
5259 mips16_macro_build (ep, name, fmt, &args);
5264 r[0] = BFD_RELOC_UNUSED;
5265 r[1] = BFD_RELOC_UNUSED;
5266 r[2] = BFD_RELOC_UNUSED;
5267 hash = mips_opts.micromips ? micromips_op_hash : op_hash;
5268 amo = (struct mips_opcode *) hash_find (hash, name);
5270 gas_assert (strcmp (name, amo->name) == 0);
5274 /* Search until we get a match for NAME. It is assumed here that
5275 macros will never generate MDMX, MIPS-3D, or MT instructions.
5276 We try to match an instruction that fulfils the branch delay
5277 slot instruction length requirement (if any) of the previous
5278 instruction. While doing this we record the first instruction
5279 seen that matches all the other conditions and use it anyway
5280 if the requirement cannot be met; we will issue an appropriate
5281 warning later on. */
5282 if (strcmp (fmt, amo->args) == 0
5283 && amo->pinfo != INSN_MACRO
5284 && is_opcode_valid (amo)
5285 && is_size_valid (amo))
5287 if (is_delay_slot_valid (amo))
5297 gas_assert (amo->name);
5299 while (strcmp (name, amo->name) == 0);
5302 create_insn (&insn, mo);
5320 INSERT_OPERAND (mips_opts.micromips,
5321 EXTLSB, insn, va_arg (args, int));
5326 /* Note that in the macro case, these arguments are already
5327 in MSB form. (When handling the instruction in the
5328 non-macro case, these arguments are sizes from which
5329 MSB values must be calculated.) */
5330 INSERT_OPERAND (mips_opts.micromips,
5331 INSMSB, insn, va_arg (args, int));
5335 gas_assert (!mips_opts.micromips);
5336 INSERT_OPERAND (0, CODE10, insn, va_arg (args, int));
5342 /* Note that in the macro case, these arguments are already
5343 in MSBD form. (When handling the instruction in the
5344 non-macro case, these arguments are sizes from which
5345 MSBD values must be calculated.) */
5346 INSERT_OPERAND (mips_opts.micromips,
5347 EXTMSBD, insn, va_arg (args, int));
5351 gas_assert (!mips_opts.micromips);
5352 INSERT_OPERAND (0, SEQI, insn, va_arg (args, int));
5356 INSERT_OPERAND (mips_opts.micromips, EVAOFFSET, insn, va_arg (args, int));
5365 INSERT_OPERAND (mips_opts.micromips, BP, insn, va_arg (args, int));
5369 gas_assert (mips_opts.micromips);
5373 INSERT_OPERAND (mips_opts.micromips, RT, insn, va_arg (args, int));
5377 gas_assert (!mips_opts.micromips);
5378 INSERT_OPERAND (0, CODE, insn, va_arg (args, int));
5382 gas_assert (!mips_opts.micromips);
5384 INSERT_OPERAND (mips_opts.micromips, FT, insn, va_arg (args, int));
5388 if (mips_opts.micromips)
5389 INSERT_OPERAND (1, RS, insn, va_arg (args, int));
5391 INSERT_OPERAND (0, RD, insn, va_arg (args, int));
5395 gas_assert (!mips_opts.micromips);
5397 INSERT_OPERAND (mips_opts.micromips, RD, insn, va_arg (args, int));
5401 gas_assert (!mips_opts.micromips);
5403 int tmp = va_arg (args, int);
5405 INSERT_OPERAND (0, RT, insn, tmp);
5406 INSERT_OPERAND (0, RD, insn, tmp);
5412 gas_assert (!mips_opts.micromips);
5413 INSERT_OPERAND (0, FS, insn, va_arg (args, int));
5420 INSERT_OPERAND (mips_opts.micromips,
5421 SHAMT, insn, va_arg (args, int));
5425 gas_assert (!mips_opts.micromips);
5426 INSERT_OPERAND (0, FD, insn, va_arg (args, int));
5430 gas_assert (!mips_opts.micromips);
5431 INSERT_OPERAND (0, CODE20, insn, va_arg (args, int));
5435 gas_assert (!mips_opts.micromips);
5436 INSERT_OPERAND (0, CODE19, insn, va_arg (args, int));
5440 gas_assert (!mips_opts.micromips);
5441 INSERT_OPERAND (0, CODE2, insn, va_arg (args, int));
5448 INSERT_OPERAND (mips_opts.micromips, RS, insn, va_arg (args, int));
5453 macro_read_relocs (&args, r);
5454 gas_assert (*r == BFD_RELOC_GPREL16
5455 || *r == BFD_RELOC_MIPS_HIGHER
5456 || *r == BFD_RELOC_HI16_S
5457 || *r == BFD_RELOC_LO16
5458 || *r == BFD_RELOC_MIPS_GOT_OFST);
5462 macro_read_relocs (&args, r);
5466 macro_read_relocs (&args, r);
5467 gas_assert (ep != NULL
5468 && (ep->X_op == O_constant
5469 || (ep->X_op == O_symbol
5470 && (*r == BFD_RELOC_MIPS_HIGHEST
5471 || *r == BFD_RELOC_HI16_S
5472 || *r == BFD_RELOC_HI16
5473 || *r == BFD_RELOC_GPREL16
5474 || *r == BFD_RELOC_MIPS_GOT_HI16
5475 || *r == BFD_RELOC_MIPS_CALL_HI16))));
5479 gas_assert (ep != NULL);
5482 * This allows macro() to pass an immediate expression for
5483 * creating short branches without creating a symbol.
5485 * We don't allow branch relaxation for these branches, as
5486 * they should only appear in ".set nomacro" anyway.
5488 if (ep->X_op == O_constant)
5490 /* For microMIPS we always use relocations for branches.
5491 So we should not resolve immediate values. */
5492 gas_assert (!mips_opts.micromips);
5494 if ((ep->X_add_number & 3) != 0)
5495 as_bad (_("branch to misaligned address (0x%lx)"),
5496 (unsigned long) ep->X_add_number);
5497 if ((ep->X_add_number + 0x20000) & ~0x3ffff)
5498 as_bad (_("branch address range overflow (0x%lx)"),
5499 (unsigned long) ep->X_add_number);
5500 insn.insn_opcode |= (ep->X_add_number >> 2) & 0xffff;
5504 *r = BFD_RELOC_16_PCREL_S2;
5508 gas_assert (ep != NULL);
5509 *r = BFD_RELOC_MIPS_JMP;
5513 gas_assert (!mips_opts.micromips);
5514 INSERT_OPERAND (0, COPZ, insn, va_arg (args, unsigned long));
5518 INSERT_OPERAND (mips_opts.micromips,
5519 CACHE, insn, va_arg (args, unsigned long));
5523 gas_assert (mips_opts.micromips);
5524 INSERT_OPERAND (1, TRAP, insn, va_arg (args, int));
5528 gas_assert (mips_opts.micromips);
5529 INSERT_OPERAND (1, OFFSET10, insn, va_arg (args, int));
5533 INSERT_OPERAND (mips_opts.micromips,
5534 3BITPOS, insn, va_arg (args, unsigned int));
5538 INSERT_OPERAND (mips_opts.micromips,
5539 OFFSET12, insn, va_arg (args, unsigned long));
5543 gas_assert (mips_opts.micromips);
5544 INSERT_OPERAND (1, BCC, insn, va_arg (args, int));
5547 case 'm': /* Opcode extension character. */
5548 gas_assert (mips_opts.micromips);
5552 INSERT_OPERAND (1, MJ, insn, va_arg (args, int));
5556 INSERT_OPERAND (1, MP, insn, va_arg (args, int));
5560 INSERT_OPERAND (1, IMMF, insn, va_arg (args, int));
5574 gas_assert (*r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL);
5576 append_insn (&insn, ep, r, TRUE);
5580 mips16_macro_build (expressionS *ep, const char *name, const char *fmt,
5583 struct mips_opcode *mo;
5584 struct mips_cl_insn insn;
5585 bfd_reloc_code_real_type r[3]
5586 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
5588 mo = (struct mips_opcode *) hash_find (mips16_op_hash, name);
5590 gas_assert (strcmp (name, mo->name) == 0);
5592 while (strcmp (fmt, mo->args) != 0 || mo->pinfo == INSN_MACRO)
5595 gas_assert (mo->name);
5596 gas_assert (strcmp (name, mo->name) == 0);
5599 create_insn (&insn, mo);
5617 MIPS16_INSERT_OPERAND (RY, insn, va_arg (*args, int));
5622 MIPS16_INSERT_OPERAND (RX, insn, va_arg (*args, int));
5626 MIPS16_INSERT_OPERAND (RZ, insn, va_arg (*args, int));
5630 MIPS16_INSERT_OPERAND (MOVE32Z, insn, va_arg (*args, int));
5640 MIPS16_INSERT_OPERAND (REGR32, insn, va_arg (*args, int));
5647 regno = va_arg (*args, int);
5648 regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3);
5649 MIPS16_INSERT_OPERAND (REG32R, insn, regno);
5672 gas_assert (ep != NULL);
5674 if (ep->X_op != O_constant)
5675 *r = (int) BFD_RELOC_UNUSED + c;
5676 else if (calculate_reloc (*r, ep->X_add_number, &value))
5678 mips16_immed (NULL, 0, c, *r, value, 0, &insn.insn_opcode);
5680 *r = BFD_RELOC_UNUSED;
5686 MIPS16_INSERT_OPERAND (IMM6, insn, va_arg (*args, int));
5693 gas_assert (*r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL);
5695 append_insn (&insn, ep, r, TRUE);
5699 * Sign-extend 32-bit mode constants that have bit 31 set and all
5700 * higher bits unset.
5703 normalize_constant_expr (expressionS *ex)
5705 if (ex->X_op == O_constant
5706 && IS_ZEXT_32BIT_NUM (ex->X_add_number))
5707 ex->X_add_number = (((ex->X_add_number & 0xffffffff) ^ 0x80000000)
5712 * Sign-extend 32-bit mode address offsets that have bit 31 set and
5713 * all higher bits unset.
5716 normalize_address_expr (expressionS *ex)
5718 if (((ex->X_op == O_constant && HAVE_32BIT_ADDRESSES)
5719 || (ex->X_op == O_symbol && HAVE_32BIT_SYMBOLS))
5720 && IS_ZEXT_32BIT_NUM (ex->X_add_number))
5721 ex->X_add_number = (((ex->X_add_number & 0xffffffff) ^ 0x80000000)
5726 * Generate a "jalr" instruction with a relocation hint to the called
5727 * function. This occurs in NewABI PIC code.
5730 macro_build_jalr (expressionS *ep, int cprestore)
5732 static const bfd_reloc_code_real_type jalr_relocs[2]
5733 = { BFD_RELOC_MIPS_JALR, BFD_RELOC_MICROMIPS_JALR };
5734 bfd_reloc_code_real_type jalr_reloc = jalr_relocs[mips_opts.micromips];
5738 if (MIPS_JALR_HINT_P (ep))
5743 if (mips_opts.micromips)
5745 jalr = mips_opts.noreorder && !cprestore ? "jalr" : "jalrs";
5746 if (MIPS_JALR_HINT_P (ep)
5747 || (history[0].insn_mo->pinfo2 & INSN2_BRANCH_DELAY_32BIT))
5748 macro_build (NULL, jalr, "t,s", RA, PIC_CALL_REG);
5750 macro_build (NULL, jalr, "mj", PIC_CALL_REG);
5753 macro_build (NULL, "jalr", "d,s", RA, PIC_CALL_REG);
5754 if (MIPS_JALR_HINT_P (ep))
5755 fix_new_exp (frag_now, f - frag_now->fr_literal, 4, ep, FALSE, jalr_reloc);
5759 * Generate a "lui" instruction.
5762 macro_build_lui (expressionS *ep, int regnum)
5764 gas_assert (! mips_opts.mips16);
5766 if (ep->X_op != O_constant)
5768 gas_assert (ep->X_op == O_symbol);
5769 /* _gp_disp is a special case, used from s_cpload.
5770 __gnu_local_gp is used if mips_no_shared. */
5771 gas_assert (mips_pic == NO_PIC
5773 && strcmp (S_GET_NAME (ep->X_add_symbol), "_gp_disp") == 0)
5774 || (! mips_in_shared
5775 && strcmp (S_GET_NAME (ep->X_add_symbol),
5776 "__gnu_local_gp") == 0));
5779 macro_build (ep, "lui", LUI_FMT, regnum, BFD_RELOC_HI16_S);
5782 /* Generate a sequence of instructions to do a load or store from a constant
5783 offset off of a base register (breg) into/from a target register (treg),
5784 using AT if necessary. */
5786 macro_build_ldst_constoffset (expressionS *ep, const char *op,
5787 int treg, int breg, int dbl)
5789 gas_assert (ep->X_op == O_constant);
5791 /* Sign-extending 32-bit constants makes their handling easier. */
5793 normalize_constant_expr (ep);
5795 /* Right now, this routine can only handle signed 32-bit constants. */
5796 if (! IS_SEXT_32BIT_NUM(ep->X_add_number + 0x8000))
5797 as_warn (_("operand overflow"));
5799 if (IS_SEXT_16BIT_NUM(ep->X_add_number))
5801 /* Signed 16-bit offset will fit in the op. Easy! */
5802 macro_build (ep, op, "t,o(b)", treg, BFD_RELOC_LO16, breg);
5806 /* 32-bit offset, need multiple instructions and AT, like:
5807 lui $tempreg,const_hi (BFD_RELOC_HI16_S)
5808 addu $tempreg,$tempreg,$breg
5809 <op> $treg,const_lo($tempreg) (BFD_RELOC_LO16)
5810 to handle the complete offset. */
5811 macro_build_lui (ep, AT);
5812 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, AT, breg);
5813 macro_build (ep, op, "t,o(b)", treg, BFD_RELOC_LO16, AT);
5816 as_bad (_("Macro used $at after \".set noat\""));
5821 * Generates code to set the $at register to true (one)
5822 * if reg is less than the immediate expression.
5825 set_at (int reg, int unsignedp)
5827 if (imm_expr.X_op == O_constant
5828 && imm_expr.X_add_number >= -0x8000
5829 && imm_expr.X_add_number < 0x8000)
5830 macro_build (&imm_expr, unsignedp ? "sltiu" : "slti", "t,r,j",
5831 AT, reg, BFD_RELOC_LO16);
5834 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
5835 macro_build (NULL, unsignedp ? "sltu" : "slt", "d,v,t", AT, reg, AT);
5839 /* Warn if an expression is not a constant. */
5842 check_absolute_expr (struct mips_cl_insn *ip, expressionS *ex)
5844 if (ex->X_op == O_big)
5845 as_bad (_("unsupported large constant"));
5846 else if (ex->X_op != O_constant)
5847 as_bad (_("Instruction %s requires absolute expression"),
5850 if (HAVE_32BIT_GPRS)
5851 normalize_constant_expr (ex);
5854 /* Count the leading zeroes by performing a binary chop. This is a
5855 bulky bit of source, but performance is a LOT better for the
5856 majority of values than a simple loop to count the bits:
5857 for (lcnt = 0; (lcnt < 32); lcnt++)
5858 if ((v) & (1 << (31 - lcnt)))
5860 However it is not code size friendly, and the gain will drop a bit
5861 on certain cached systems.
5863 #define COUNT_TOP_ZEROES(v) \
5864 (((v) & ~0xffff) == 0 \
5865 ? ((v) & ~0xff) == 0 \
5866 ? ((v) & ~0xf) == 0 \
5867 ? ((v) & ~0x3) == 0 \
5868 ? ((v) & ~0x1) == 0 \
5873 : ((v) & ~0x7) == 0 \
5876 : ((v) & ~0x3f) == 0 \
5877 ? ((v) & ~0x1f) == 0 \
5880 : ((v) & ~0x7f) == 0 \
5883 : ((v) & ~0xfff) == 0 \
5884 ? ((v) & ~0x3ff) == 0 \
5885 ? ((v) & ~0x1ff) == 0 \
5888 : ((v) & ~0x7ff) == 0 \
5891 : ((v) & ~0x3fff) == 0 \
5892 ? ((v) & ~0x1fff) == 0 \
5895 : ((v) & ~0x7fff) == 0 \
5898 : ((v) & ~0xffffff) == 0 \
5899 ? ((v) & ~0xfffff) == 0 \
5900 ? ((v) & ~0x3ffff) == 0 \
5901 ? ((v) & ~0x1ffff) == 0 \
5904 : ((v) & ~0x7ffff) == 0 \
5907 : ((v) & ~0x3fffff) == 0 \
5908 ? ((v) & ~0x1fffff) == 0 \
5911 : ((v) & ~0x7fffff) == 0 \
5914 : ((v) & ~0xfffffff) == 0 \
5915 ? ((v) & ~0x3ffffff) == 0 \
5916 ? ((v) & ~0x1ffffff) == 0 \
5919 : ((v) & ~0x7ffffff) == 0 \
5922 : ((v) & ~0x3fffffff) == 0 \
5923 ? ((v) & ~0x1fffffff) == 0 \
5926 : ((v) & ~0x7fffffff) == 0 \
5931 * This routine generates the least number of instructions necessary to load
5932 * an absolute expression value into a register.
5935 load_register (int reg, expressionS *ep, int dbl)
5938 expressionS hi32, lo32;
5940 if (ep->X_op != O_big)
5942 gas_assert (ep->X_op == O_constant);
5944 /* Sign-extending 32-bit constants makes their handling easier. */
5946 normalize_constant_expr (ep);
5948 if (IS_SEXT_16BIT_NUM (ep->X_add_number))
5950 /* We can handle 16 bit signed values with an addiu to
5951 $zero. No need to ever use daddiu here, since $zero and
5952 the result are always correct in 32 bit mode. */
5953 macro_build (ep, "addiu", "t,r,j", reg, 0, BFD_RELOC_LO16);
5956 else if (ep->X_add_number >= 0 && ep->X_add_number < 0x10000)
5958 /* We can handle 16 bit unsigned values with an ori to
5960 macro_build (ep, "ori", "t,r,i", reg, 0, BFD_RELOC_LO16);
5963 else if ((IS_SEXT_32BIT_NUM (ep->X_add_number)))
5965 /* 32 bit values require an lui. */
5966 macro_build (ep, "lui", LUI_FMT, reg, BFD_RELOC_HI16);
5967 if ((ep->X_add_number & 0xffff) != 0)
5968 macro_build (ep, "ori", "t,r,i", reg, reg, BFD_RELOC_LO16);
5973 /* The value is larger than 32 bits. */
5975 if (!dbl || HAVE_32BIT_GPRS)
5979 sprintf_vma (value, ep->X_add_number);
5980 as_bad (_("Number (0x%s) larger than 32 bits"), value);
5981 macro_build (ep, "addiu", "t,r,j", reg, 0, BFD_RELOC_LO16);
5985 if (ep->X_op != O_big)
5988 hi32.X_add_number = (valueT) hi32.X_add_number >> 16;
5989 hi32.X_add_number = (valueT) hi32.X_add_number >> 16;
5990 hi32.X_add_number &= 0xffffffff;
5992 lo32.X_add_number &= 0xffffffff;
5996 gas_assert (ep->X_add_number > 2);
5997 if (ep->X_add_number == 3)
5998 generic_bignum[3] = 0;
5999 else if (ep->X_add_number > 4)
6000 as_bad (_("Number larger than 64 bits"));
6001 lo32.X_op = O_constant;
6002 lo32.X_add_number = generic_bignum[0] + (generic_bignum[1] << 16);
6003 hi32.X_op = O_constant;
6004 hi32.X_add_number = generic_bignum[2] + (generic_bignum[3] << 16);
6007 if (hi32.X_add_number == 0)
6012 unsigned long hi, lo;
6014 if (hi32.X_add_number == (offsetT) 0xffffffff)
6016 if ((lo32.X_add_number & 0xffff8000) == 0xffff8000)
6018 macro_build (&lo32, "addiu", "t,r,j", reg, 0, BFD_RELOC_LO16);
6021 if (lo32.X_add_number & 0x80000000)
6023 macro_build (&lo32, "lui", LUI_FMT, reg, BFD_RELOC_HI16);
6024 if (lo32.X_add_number & 0xffff)
6025 macro_build (&lo32, "ori", "t,r,i", reg, reg, BFD_RELOC_LO16);
6030 /* Check for 16bit shifted constant. We know that hi32 is
6031 non-zero, so start the mask on the first bit of the hi32
6036 unsigned long himask, lomask;
6040 himask = 0xffff >> (32 - shift);
6041 lomask = (0xffff << shift) & 0xffffffff;
6045 himask = 0xffff << (shift - 32);
6048 if ((hi32.X_add_number & ~(offsetT) himask) == 0
6049 && (lo32.X_add_number & ~(offsetT) lomask) == 0)
6053 tmp.X_op = O_constant;
6055 tmp.X_add_number = ((hi32.X_add_number << (32 - shift))
6056 | (lo32.X_add_number >> shift));
6058 tmp.X_add_number = hi32.X_add_number >> (shift - 32);
6059 macro_build (&tmp, "ori", "t,r,i", reg, 0, BFD_RELOC_LO16);
6060 macro_build (NULL, (shift >= 32) ? "dsll32" : "dsll", SHFT_FMT,
6061 reg, reg, (shift >= 32) ? shift - 32 : shift);
6066 while (shift <= (64 - 16));
6068 /* Find the bit number of the lowest one bit, and store the
6069 shifted value in hi/lo. */
6070 hi = (unsigned long) (hi32.X_add_number & 0xffffffff);
6071 lo = (unsigned long) (lo32.X_add_number & 0xffffffff);
6075 while ((lo & 1) == 0)
6080 lo |= (hi & (((unsigned long) 1 << bit) - 1)) << (32 - bit);
6086 while ((hi & 1) == 0)
6095 /* Optimize if the shifted value is a (power of 2) - 1. */
6096 if ((hi == 0 && ((lo + 1) & lo) == 0)
6097 || (lo == 0xffffffff && ((hi + 1) & hi) == 0))
6099 shift = COUNT_TOP_ZEROES ((unsigned int) hi32.X_add_number);
6104 /* This instruction will set the register to be all
6106 tmp.X_op = O_constant;
6107 tmp.X_add_number = (offsetT) -1;
6108 macro_build (&tmp, "addiu", "t,r,j", reg, 0, BFD_RELOC_LO16);
6112 macro_build (NULL, (bit >= 32) ? "dsll32" : "dsll", SHFT_FMT,
6113 reg, reg, (bit >= 32) ? bit - 32 : bit);
6115 macro_build (NULL, (shift >= 32) ? "dsrl32" : "dsrl", SHFT_FMT,
6116 reg, reg, (shift >= 32) ? shift - 32 : shift);
6121 /* Sign extend hi32 before calling load_register, because we can
6122 generally get better code when we load a sign extended value. */
6123 if ((hi32.X_add_number & 0x80000000) != 0)
6124 hi32.X_add_number |= ~(offsetT) 0xffffffff;
6125 load_register (reg, &hi32, 0);
6128 if ((lo32.X_add_number & 0xffff0000) == 0)
6132 macro_build (NULL, "dsll32", SHFT_FMT, reg, freg, 0);
6140 if ((freg == 0) && (lo32.X_add_number == (offsetT) 0xffffffff))
6142 macro_build (&lo32, "lui", LUI_FMT, reg, BFD_RELOC_HI16);
6143 macro_build (NULL, "dsrl32", SHFT_FMT, reg, reg, 0);
6149 macro_build (NULL, "dsll", SHFT_FMT, reg, freg, 16);
6153 mid16.X_add_number >>= 16;
6154 macro_build (&mid16, "ori", "t,r,i", reg, freg, BFD_RELOC_LO16);
6155 macro_build (NULL, "dsll", SHFT_FMT, reg, reg, 16);
6158 if ((lo32.X_add_number & 0xffff) != 0)
6159 macro_build (&lo32, "ori", "t,r,i", reg, freg, BFD_RELOC_LO16);
6163 load_delay_nop (void)
6165 if (!gpr_interlocks)
6166 macro_build (NULL, "nop", "");
6169 /* Load an address into a register. */
6172 load_address (int reg, expressionS *ep, int *used_at)
6174 if (ep->X_op != O_constant
6175 && ep->X_op != O_symbol)
6177 as_bad (_("expression too complex"));
6178 ep->X_op = O_constant;
6181 if (ep->X_op == O_constant)
6183 load_register (reg, ep, HAVE_64BIT_ADDRESSES);
6187 if (mips_pic == NO_PIC)
6189 /* If this is a reference to a GP relative symbol, we want
6190 addiu $reg,$gp,<sym> (BFD_RELOC_GPREL16)
6192 lui $reg,<sym> (BFD_RELOC_HI16_S)
6193 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
6194 If we have an addend, we always use the latter form.
6196 With 64bit address space and a usable $at we want
6197 lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST)
6198 lui $at,<sym> (BFD_RELOC_HI16_S)
6199 daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER)
6200 daddiu $at,<sym> (BFD_RELOC_LO16)
6204 If $at is already in use, we use a path which is suboptimal
6205 on superscalar processors.
6206 lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST)
6207 daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER)
6209 daddiu $reg,<sym> (BFD_RELOC_HI16_S)
6211 daddiu $reg,<sym> (BFD_RELOC_LO16)
6213 For GP relative symbols in 64bit address space we can use
6214 the same sequence as in 32bit address space. */
6215 if (HAVE_64BIT_SYMBOLS)
6217 if ((valueT) ep->X_add_number <= MAX_GPREL_OFFSET
6218 && !nopic_need_relax (ep->X_add_symbol, 1))
6220 relax_start (ep->X_add_symbol);
6221 macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", reg,
6222 mips_gp_register, BFD_RELOC_GPREL16);
6226 if (*used_at == 0 && mips_opts.at)
6228 macro_build (ep, "lui", LUI_FMT, reg, BFD_RELOC_MIPS_HIGHEST);
6229 macro_build (ep, "lui", LUI_FMT, AT, BFD_RELOC_HI16_S);
6230 macro_build (ep, "daddiu", "t,r,j", reg, reg,
6231 BFD_RELOC_MIPS_HIGHER);
6232 macro_build (ep, "daddiu", "t,r,j", AT, AT, BFD_RELOC_LO16);
6233 macro_build (NULL, "dsll32", SHFT_FMT, reg, reg, 0);
6234 macro_build (NULL, "daddu", "d,v,t", reg, reg, AT);
6239 macro_build (ep, "lui", LUI_FMT, reg, BFD_RELOC_MIPS_HIGHEST);
6240 macro_build (ep, "daddiu", "t,r,j", reg, reg,
6241 BFD_RELOC_MIPS_HIGHER);
6242 macro_build (NULL, "dsll", SHFT_FMT, reg, reg, 16);
6243 macro_build (ep, "daddiu", "t,r,j", reg, reg, BFD_RELOC_HI16_S);
6244 macro_build (NULL, "dsll", SHFT_FMT, reg, reg, 16);
6245 macro_build (ep, "daddiu", "t,r,j", reg, reg, BFD_RELOC_LO16);
6248 if (mips_relax.sequence)
6253 if ((valueT) ep->X_add_number <= MAX_GPREL_OFFSET
6254 && !nopic_need_relax (ep->X_add_symbol, 1))
6256 relax_start (ep->X_add_symbol);
6257 macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", reg,
6258 mips_gp_register, BFD_RELOC_GPREL16);
6261 macro_build_lui (ep, reg);
6262 macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j",
6263 reg, reg, BFD_RELOC_LO16);
6264 if (mips_relax.sequence)
6268 else if (!mips_big_got)
6272 /* If this is a reference to an external symbol, we want
6273 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6275 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6277 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
6278 If there is a constant, it must be added in after.
6280 If we have NewABI, we want
6281 lw $reg,<sym+cst>($gp) (BFD_RELOC_MIPS_GOT_DISP)
6282 unless we're referencing a global symbol with a non-zero
6283 offset, in which case cst must be added separately. */
6286 if (ep->X_add_number)
6288 ex.X_add_number = ep->X_add_number;
6289 ep->X_add_number = 0;
6290 relax_start (ep->X_add_symbol);
6291 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
6292 BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
6293 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
6294 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6295 ex.X_op = O_constant;
6296 macro_build (&ex, ADDRESS_ADDI_INSN, "t,r,j",
6297 reg, reg, BFD_RELOC_LO16);
6298 ep->X_add_number = ex.X_add_number;
6301 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
6302 BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
6303 if (mips_relax.sequence)
6308 ex.X_add_number = ep->X_add_number;
6309 ep->X_add_number = 0;
6310 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
6311 BFD_RELOC_MIPS_GOT16, mips_gp_register);
6313 relax_start (ep->X_add_symbol);
6315 macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", reg, reg,
6319 if (ex.X_add_number != 0)
6321 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
6322 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6323 ex.X_op = O_constant;
6324 macro_build (&ex, ADDRESS_ADDI_INSN, "t,r,j",
6325 reg, reg, BFD_RELOC_LO16);
6329 else if (mips_big_got)
6333 /* This is the large GOT case. If this is a reference to an
6334 external symbol, we want
6335 lui $reg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
6337 lw $reg,<sym>($reg) (BFD_RELOC_MIPS_GOT_LO16)
6339 Otherwise, for a reference to a local symbol in old ABI, we want
6340 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6342 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
6343 If there is a constant, it must be added in after.
6345 In the NewABI, for local symbols, with or without offsets, we want:
6346 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
6347 addiu $reg,$reg,<sym> (BFD_RELOC_MIPS_GOT_OFST)
6351 ex.X_add_number = ep->X_add_number;
6352 ep->X_add_number = 0;
6353 relax_start (ep->X_add_symbol);
6354 macro_build (ep, "lui", LUI_FMT, reg, BFD_RELOC_MIPS_GOT_HI16);
6355 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
6356 reg, reg, mips_gp_register);
6357 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)",
6358 reg, BFD_RELOC_MIPS_GOT_LO16, reg);
6359 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
6360 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6361 else if (ex.X_add_number)
6363 ex.X_op = O_constant;
6364 macro_build (&ex, ADDRESS_ADDI_INSN, "t,r,j", reg, reg,
6368 ep->X_add_number = ex.X_add_number;
6370 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
6371 BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register);
6372 macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", reg, reg,
6373 BFD_RELOC_MIPS_GOT_OFST);
6378 ex.X_add_number = ep->X_add_number;
6379 ep->X_add_number = 0;
6380 relax_start (ep->X_add_symbol);
6381 macro_build (ep, "lui", LUI_FMT, reg, BFD_RELOC_MIPS_GOT_HI16);
6382 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
6383 reg, reg, mips_gp_register);
6384 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)",
6385 reg, BFD_RELOC_MIPS_GOT_LO16, reg);
6387 if (reg_needs_delay (mips_gp_register))
6389 /* We need a nop before loading from $gp. This special
6390 check is required because the lui which starts the main
6391 instruction stream does not refer to $gp, and so will not
6392 insert the nop which may be required. */
6393 macro_build (NULL, "nop", "");
6395 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
6396 BFD_RELOC_MIPS_GOT16, mips_gp_register);
6398 macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", reg, reg,
6402 if (ex.X_add_number != 0)
6404 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
6405 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6406 ex.X_op = O_constant;
6407 macro_build (&ex, ADDRESS_ADDI_INSN, "t,r,j", reg, reg,
6415 if (!mips_opts.at && *used_at == 1)
6416 as_bad (_("Macro used $at after \".set noat\""));
6419 /* Move the contents of register SOURCE into register DEST. */
6422 move_register (int dest, int source)
6424 /* Prefer to use a 16-bit microMIPS instruction unless the previous
6425 instruction specifically requires a 32-bit one. */
6426 if (mips_opts.micromips
6427 && !(history[0].insn_mo->pinfo2 & INSN2_BRANCH_DELAY_32BIT))
6428 macro_build (NULL, "move", "mp,mj", dest, source);
6430 macro_build (NULL, HAVE_32BIT_GPRS ? "addu" : "daddu", "d,v,t",
6434 /* Emit an SVR4 PIC sequence to load address LOCAL into DEST, where
6435 LOCAL is the sum of a symbol and a 16-bit or 32-bit displacement.
6436 The two alternatives are:
6438 Global symbol Local sybmol
6439 ------------- ------------
6440 lw DEST,%got(SYMBOL) lw DEST,%got(SYMBOL + OFFSET)
6442 addiu DEST,DEST,OFFSET addiu DEST,DEST,%lo(SYMBOL + OFFSET)
6444 load_got_offset emits the first instruction and add_got_offset
6445 emits the second for a 16-bit offset or add_got_offset_hilo emits
6446 a sequence to add a 32-bit offset using a scratch register. */
6449 load_got_offset (int dest, expressionS *local)
6454 global.X_add_number = 0;
6456 relax_start (local->X_add_symbol);
6457 macro_build (&global, ADDRESS_LOAD_INSN, "t,o(b)", dest,
6458 BFD_RELOC_MIPS_GOT16, mips_gp_register);
6460 macro_build (local, ADDRESS_LOAD_INSN, "t,o(b)", dest,
6461 BFD_RELOC_MIPS_GOT16, mips_gp_register);
6466 add_got_offset (int dest, expressionS *local)
6470 global.X_op = O_constant;
6471 global.X_op_symbol = NULL;
6472 global.X_add_symbol = NULL;
6473 global.X_add_number = local->X_add_number;
6475 relax_start (local->X_add_symbol);
6476 macro_build (&global, ADDRESS_ADDI_INSN, "t,r,j",
6477 dest, dest, BFD_RELOC_LO16);
6479 macro_build (local, ADDRESS_ADDI_INSN, "t,r,j", dest, dest, BFD_RELOC_LO16);
6484 add_got_offset_hilo (int dest, expressionS *local, int tmp)
6487 int hold_mips_optimize;
6489 global.X_op = O_constant;
6490 global.X_op_symbol = NULL;
6491 global.X_add_symbol = NULL;
6492 global.X_add_number = local->X_add_number;
6494 relax_start (local->X_add_symbol);
6495 load_register (tmp, &global, HAVE_64BIT_ADDRESSES);
6497 /* Set mips_optimize around the lui instruction to avoid
6498 inserting an unnecessary nop after the lw. */
6499 hold_mips_optimize = mips_optimize;
6501 macro_build_lui (&global, tmp);
6502 mips_optimize = hold_mips_optimize;
6503 macro_build (local, ADDRESS_ADDI_INSN, "t,r,j", tmp, tmp, BFD_RELOC_LO16);
6506 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", dest, dest, tmp);
6509 /* Emit a sequence of instructions to emulate a branch likely operation.
6510 BR is an ordinary branch corresponding to one to be emulated. BRNEG
6511 is its complementing branch with the original condition negated.
6512 CALL is set if the original branch specified the link operation.
6513 EP, FMT, SREG and TREG specify the usual macro_build() parameters.
6515 Code like this is produced in the noreorder mode:
6520 delay slot (executed only if branch taken)
6528 delay slot (executed only if branch taken)
6531 In the reorder mode the delay slot would be filled with a nop anyway,
6532 so code produced is simply:
6537 This function is used when producing code for the microMIPS ASE that
6538 does not implement branch likely instructions in hardware. */
6541 macro_build_branch_likely (const char *br, const char *brneg,
6542 int call, expressionS *ep, const char *fmt,
6543 unsigned int sreg, unsigned int treg)
6545 int noreorder = mips_opts.noreorder;
6548 gas_assert (mips_opts.micromips);
6552 micromips_label_expr (&expr1);
6553 macro_build (&expr1, brneg, fmt, sreg, treg);
6554 macro_build (NULL, "nop", "");
6555 macro_build (ep, call ? "bal" : "b", "p");
6557 /* Set to true so that append_insn adds a label. */
6558 emit_branch_likely_macro = TRUE;
6562 macro_build (ep, br, fmt, sreg, treg);
6563 macro_build (NULL, "nop", "");
6568 /* Emit a coprocessor branch-likely macro specified by TYPE, using CC as
6569 the condition code tested. EP specifies the branch target. */
6572 macro_build_branch_ccl (int type, expressionS *ep, unsigned int cc)
6599 macro_build_branch_likely (br, brneg, call, ep, "N,p", cc, ZERO);
6602 /* Emit a two-argument branch macro specified by TYPE, using SREG as
6603 the register tested. EP specifies the branch target. */
6606 macro_build_branch_rs (int type, expressionS *ep, unsigned int sreg)
6608 const char *brneg = NULL;
6618 br = mips_opts.micromips ? "bgez" : "bgezl";
6622 gas_assert (mips_opts.micromips);
6631 br = mips_opts.micromips ? "bgtz" : "bgtzl";
6638 br = mips_opts.micromips ? "blez" : "blezl";
6645 br = mips_opts.micromips ? "bltz" : "bltzl";
6649 gas_assert (mips_opts.micromips);
6657 if (mips_opts.micromips && brneg)
6658 macro_build_branch_likely (br, brneg, call, ep, "s,p", sreg, ZERO);
6660 macro_build (ep, br, "s,p", sreg);
6663 /* Emit a three-argument branch macro specified by TYPE, using SREG and
6664 TREG as the registers tested. EP specifies the branch target. */
6667 macro_build_branch_rsrt (int type, expressionS *ep,
6668 unsigned int sreg, unsigned int treg)
6670 const char *brneg = NULL;
6682 br = mips_opts.micromips ? "beq" : "beql";
6691 br = mips_opts.micromips ? "bne" : "bnel";
6697 if (mips_opts.micromips && brneg)
6698 macro_build_branch_likely (br, brneg, call, ep, "s,t,p", sreg, treg);
6700 macro_build (ep, br, "s,t,p", sreg, treg);
6705 * This routine implements the seemingly endless macro or synthesized
6706 * instructions and addressing modes in the mips assembly language. Many
6707 * of these macros are simple and are similar to each other. These could
6708 * probably be handled by some kind of table or grammar approach instead of
6709 * this verbose method. Others are not simple macros but are more like
6710 * optimizing code generation.
6711 * One interesting optimization is when several store macros appear
6712 * consecutively that would load AT with the upper half of the same address.
6713 * The ensuing load upper instructions are ommited. This implies some kind
6714 * of global optimization. We currently only optimize within a single macro.
6715 * For many of the load and store macros if the address is specified as a
6716 * constant expression in the first 64k of memory (ie ld $2,0x4000c) we
6717 * first load register 'at' with zero and use it as the base register. The
6718 * mips assembler simply uses register $zero. Just one tiny optimization
6722 macro (struct mips_cl_insn *ip)
6724 unsigned int treg, sreg, dreg, breg;
6725 unsigned int tempreg;
6728 expressionS label_expr;
6746 bfd_reloc_code_real_type r;
6747 int hold_mips_optimize;
6749 gas_assert (! mips_opts.mips16);
6751 treg = EXTRACT_OPERAND (mips_opts.micromips, RT, *ip);
6752 dreg = EXTRACT_OPERAND (mips_opts.micromips, RD, *ip);
6753 sreg = breg = EXTRACT_OPERAND (mips_opts.micromips, RS, *ip);
6754 mask = ip->insn_mo->mask;
6756 label_expr.X_op = O_constant;
6757 label_expr.X_op_symbol = NULL;
6758 label_expr.X_add_symbol = NULL;
6759 label_expr.X_add_number = 0;
6761 expr1.X_op = O_constant;
6762 expr1.X_op_symbol = NULL;
6763 expr1.X_add_symbol = NULL;
6764 expr1.X_add_number = 1;
6779 if (mips_opts.micromips)
6780 micromips_label_expr (&label_expr);
6782 label_expr.X_add_number = 8;
6783 macro_build (&label_expr, "bgez", "s,p", sreg);
6785 macro_build (NULL, "nop", "");
6787 move_register (dreg, sreg);
6788 macro_build (NULL, dbl ? "dsub" : "sub", "d,v,t", dreg, 0, sreg);
6789 if (mips_opts.micromips)
6790 micromips_add_label ();
6807 if (!mips_opts.micromips)
6809 if (imm_expr.X_op == O_constant
6810 && imm_expr.X_add_number >= -0x200
6811 && imm_expr.X_add_number < 0x200)
6813 macro_build (NULL, s, "t,r,.", treg, sreg, imm_expr.X_add_number);
6822 if (imm_expr.X_op == O_constant
6823 && imm_expr.X_add_number >= -0x8000
6824 && imm_expr.X_add_number < 0x8000)
6826 macro_build (&imm_expr, s, "t,r,j", treg, sreg, BFD_RELOC_LO16);
6831 load_register (AT, &imm_expr, dbl);
6832 macro_build (NULL, s2, "d,v,t", treg, sreg, AT);
6851 if (imm_expr.X_op == O_constant
6852 && imm_expr.X_add_number >= 0
6853 && imm_expr.X_add_number < 0x10000)
6855 if (mask != M_NOR_I)
6856 macro_build (&imm_expr, s, "t,r,i", treg, sreg, BFD_RELOC_LO16);
6859 macro_build (&imm_expr, "ori", "t,r,i",
6860 treg, sreg, BFD_RELOC_LO16);
6861 macro_build (NULL, "nor", "d,v,t", treg, treg, 0);
6867 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
6868 macro_build (NULL, s2, "d,v,t", treg, sreg, AT);
6872 switch (imm_expr.X_add_number)
6875 macro_build (NULL, "nop", "");
6878 macro_build (NULL, "packrl.ph", "d,s,t", treg, treg, sreg);
6882 macro_build (NULL, "balign", "t,s,2", treg, sreg,
6883 (int) imm_expr.X_add_number);
6886 as_bad (_("BALIGN immediate not 0, 1, 2 or 3 (%lu)"),
6887 (unsigned long) imm_expr.X_add_number);
6896 gas_assert (mips_opts.micromips);
6897 macro_build_branch_ccl (mask, &offset_expr,
6898 EXTRACT_OPERAND (1, BCC, *ip));
6905 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
6911 load_register (treg, &imm_expr, HAVE_64BIT_GPRS);
6916 macro_build_branch_rsrt (mask, &offset_expr, sreg, treg);
6923 macro_build_branch_rs (likely ? M_BGEZL : M_BGEZ, &offset_expr, sreg);
6925 macro_build_branch_rs (likely ? M_BLEZL : M_BLEZ, &offset_expr, treg);
6929 macro_build (NULL, "slt", "d,v,t", AT, sreg, treg);
6930 macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ,
6931 &offset_expr, AT, ZERO);
6941 macro_build_branch_rs (mask, &offset_expr, sreg);
6947 /* Check for > max integer. */
6948 maxnum = 0x7fffffff;
6949 if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4)
6956 if (imm_expr.X_op == O_constant
6957 && imm_expr.X_add_number >= maxnum
6958 && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4))
6961 /* Result is always false. */
6963 macro_build (NULL, "nop", "");
6965 macro_build_branch_rsrt (M_BNEL, &offset_expr, ZERO, ZERO);
6968 if (imm_expr.X_op != O_constant)
6969 as_bad (_("Unsupported large constant"));
6970 ++imm_expr.X_add_number;
6974 if (mask == M_BGEL_I)
6976 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
6978 macro_build_branch_rs (likely ? M_BGEZL : M_BGEZ,
6979 &offset_expr, sreg);
6982 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
6984 macro_build_branch_rs (likely ? M_BGTZL : M_BGTZ,
6985 &offset_expr, sreg);
6988 maxnum = 0x7fffffff;
6989 if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4)
6996 maxnum = - maxnum - 1;
6997 if (imm_expr.X_op == O_constant
6998 && imm_expr.X_add_number <= maxnum
6999 && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4))
7002 /* result is always true */
7003 as_warn (_("Branch %s is always true"), ip->insn_mo->name);
7004 macro_build (&offset_expr, "b", "p");
7009 macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ,
7010 &offset_expr, AT, ZERO);
7019 macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ,
7020 &offset_expr, ZERO, treg);
7024 macro_build (NULL, "sltu", "d,v,t", AT, sreg, treg);
7025 macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ,
7026 &offset_expr, AT, ZERO);
7035 && imm_expr.X_op == O_constant
7036 && imm_expr.X_add_number == -1))
7038 if (imm_expr.X_op != O_constant)
7039 as_bad (_("Unsupported large constant"));
7040 ++imm_expr.X_add_number;
7044 if (mask == M_BGEUL_I)
7046 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
7048 else if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
7049 macro_build_branch_rsrt (likely ? M_BNEL : M_BNE,
7050 &offset_expr, sreg, ZERO);
7055 macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ,
7056 &offset_expr, AT, ZERO);
7064 macro_build_branch_rs (likely ? M_BGTZL : M_BGTZ, &offset_expr, sreg);
7066 macro_build_branch_rs (likely ? M_BLTZL : M_BLTZ, &offset_expr, treg);
7070 macro_build (NULL, "slt", "d,v,t", AT, treg, sreg);
7071 macro_build_branch_rsrt (likely ? M_BNEL : M_BNE,
7072 &offset_expr, AT, ZERO);
7080 macro_build_branch_rsrt (likely ? M_BNEL : M_BNE,
7081 &offset_expr, sreg, ZERO);
7087 macro_build (NULL, "sltu", "d,v,t", AT, treg, sreg);
7088 macro_build_branch_rsrt (likely ? M_BNEL : M_BNE,
7089 &offset_expr, AT, ZERO);
7097 macro_build_branch_rs (likely ? M_BLEZL : M_BLEZ, &offset_expr, sreg);
7099 macro_build_branch_rs (likely ? M_BGEZL : M_BGEZ, &offset_expr, treg);
7103 macro_build (NULL, "slt", "d,v,t", AT, treg, sreg);
7104 macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ,
7105 &offset_expr, AT, ZERO);
7112 maxnum = 0x7fffffff;
7113 if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4)
7120 if (imm_expr.X_op == O_constant
7121 && imm_expr.X_add_number >= maxnum
7122 && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4))
7124 if (imm_expr.X_op != O_constant)
7125 as_bad (_("Unsupported large constant"));
7126 ++imm_expr.X_add_number;
7130 if (mask == M_BLTL_I)
7132 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
7133 macro_build_branch_rs (likely ? M_BLTZL : M_BLTZ, &offset_expr, sreg);
7134 else if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
7135 macro_build_branch_rs (likely ? M_BLEZL : M_BLEZ, &offset_expr, sreg);
7140 macro_build_branch_rsrt (likely ? M_BNEL : M_BNE,
7141 &offset_expr, AT, ZERO);
7149 macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ,
7150 &offset_expr, sreg, ZERO);
7156 macro_build (NULL, "sltu", "d,v,t", AT, treg, sreg);
7157 macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ,
7158 &offset_expr, AT, ZERO);
7167 && imm_expr.X_op == O_constant
7168 && imm_expr.X_add_number == -1))
7170 if (imm_expr.X_op != O_constant)
7171 as_bad (_("Unsupported large constant"));
7172 ++imm_expr.X_add_number;
7176 if (mask == M_BLTUL_I)
7178 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
7180 else if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
7181 macro_build_branch_rsrt (likely ? M_BEQL : M_BEQ,
7182 &offset_expr, sreg, ZERO);
7187 macro_build_branch_rsrt (likely ? M_BNEL : M_BNE,
7188 &offset_expr, AT, ZERO);
7196 macro_build_branch_rs (likely ? M_BLTZL : M_BLTZ, &offset_expr, sreg);
7198 macro_build_branch_rs (likely ? M_BGTZL : M_BGTZ, &offset_expr, treg);
7202 macro_build (NULL, "slt", "d,v,t", AT, sreg, treg);
7203 macro_build_branch_rsrt (likely ? M_BNEL : M_BNE,
7204 &offset_expr, AT, ZERO);
7214 macro_build_branch_rsrt (likely ? M_BNEL : M_BNE,
7215 &offset_expr, ZERO, treg);
7219 macro_build (NULL, "sltu", "d,v,t", AT, sreg, treg);
7220 macro_build_branch_rsrt (likely ? M_BNEL : M_BNE,
7221 &offset_expr, AT, ZERO);
7227 /* Use unsigned arithmetic. */
7231 if (imm_expr.X_op != O_constant || imm2_expr.X_op != O_constant)
7233 as_bad (_("Unsupported large constant"));
7238 pos = imm_expr.X_add_number;
7239 size = imm2_expr.X_add_number;
7244 as_bad (_("Improper position (%lu)"), (unsigned long) pos);
7247 if (size == 0 || size > 64 || (pos + size - 1) > 63)
7249 as_bad (_("Improper extract size (%lu, position %lu)"),
7250 (unsigned long) size, (unsigned long) pos);
7254 if (size <= 32 && pos < 32)
7259 else if (size <= 32)
7269 macro_build ((expressionS *) NULL, s, fmt, treg, sreg, (int) pos,
7276 /* Use unsigned arithmetic. */
7280 if (imm_expr.X_op != O_constant || imm2_expr.X_op != O_constant)
7282 as_bad (_("Unsupported large constant"));
7287 pos = imm_expr.X_add_number;
7288 size = imm2_expr.X_add_number;
7293 as_bad (_("Improper position (%lu)"), (unsigned long) pos);
7296 if (size == 0 || size > 64 || (pos + size - 1) > 63)
7298 as_bad (_("Improper insert size (%lu, position %lu)"),
7299 (unsigned long) size, (unsigned long) pos);
7303 if (pos < 32 && (pos + size - 1) < 32)
7318 macro_build ((expressionS *) NULL, s, fmt, treg, sreg, (int) pos,
7319 (int) (pos + size - 1));
7335 as_warn (_("Divide by zero."));
7337 macro_build (NULL, "teq", TRAP_FMT, ZERO, ZERO, 7);
7339 macro_build (NULL, "break", BRK_FMT, 7);
7346 macro_build (NULL, "teq", TRAP_FMT, treg, ZERO, 7);
7347 macro_build (NULL, dbl ? "ddiv" : "div", "z,s,t", sreg, treg);
7351 if (mips_opts.micromips)
7352 micromips_label_expr (&label_expr);
7354 label_expr.X_add_number = 8;
7355 macro_build (&label_expr, "bne", "s,t,p", treg, ZERO);
7356 macro_build (NULL, dbl ? "ddiv" : "div", "z,s,t", sreg, treg);
7357 macro_build (NULL, "break", BRK_FMT, 7);
7358 if (mips_opts.micromips)
7359 micromips_add_label ();
7361 expr1.X_add_number = -1;
7363 load_register (AT, &expr1, dbl);
7364 if (mips_opts.micromips)
7365 micromips_label_expr (&label_expr);
7367 label_expr.X_add_number = mips_trap ? (dbl ? 12 : 8) : (dbl ? 20 : 16);
7368 macro_build (&label_expr, "bne", "s,t,p", treg, AT);
7371 expr1.X_add_number = 1;
7372 load_register (AT, &expr1, dbl);
7373 macro_build (NULL, "dsll32", SHFT_FMT, AT, AT, 31);
7377 expr1.X_add_number = 0x80000000;
7378 macro_build (&expr1, "lui", LUI_FMT, AT, BFD_RELOC_HI16);
7382 macro_build (NULL, "teq", TRAP_FMT, sreg, AT, 6);
7383 /* We want to close the noreorder block as soon as possible, so
7384 that later insns are available for delay slot filling. */
7389 if (mips_opts.micromips)
7390 micromips_label_expr (&label_expr);
7392 label_expr.X_add_number = 8;
7393 macro_build (&label_expr, "bne", "s,t,p", sreg, AT);
7394 macro_build (NULL, "nop", "");
7396 /* We want to close the noreorder block as soon as possible, so
7397 that later insns are available for delay slot filling. */
7400 macro_build (NULL, "break", BRK_FMT, 6);
7402 if (mips_opts.micromips)
7403 micromips_add_label ();
7404 macro_build (NULL, s, MFHL_FMT, dreg);
7443 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
7445 as_warn (_("Divide by zero."));
7447 macro_build (NULL, "teq", TRAP_FMT, ZERO, ZERO, 7);
7449 macro_build (NULL, "break", BRK_FMT, 7);
7452 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
7454 if (strcmp (s2, "mflo") == 0)
7455 move_register (dreg, sreg);
7457 move_register (dreg, ZERO);
7460 if (imm_expr.X_op == O_constant
7461 && imm_expr.X_add_number == -1
7462 && s[strlen (s) - 1] != 'u')
7464 if (strcmp (s2, "mflo") == 0)
7466 macro_build (NULL, dbl ? "dneg" : "neg", "d,w", dreg, sreg);
7469 move_register (dreg, ZERO);
7474 load_register (AT, &imm_expr, dbl);
7475 macro_build (NULL, s, "z,s,t", sreg, AT);
7476 macro_build (NULL, s2, MFHL_FMT, dreg);
7498 macro_build (NULL, "teq", TRAP_FMT, treg, ZERO, 7);
7499 macro_build (NULL, s, "z,s,t", sreg, treg);
7500 /* We want to close the noreorder block as soon as possible, so
7501 that later insns are available for delay slot filling. */
7506 if (mips_opts.micromips)
7507 micromips_label_expr (&label_expr);
7509 label_expr.X_add_number = 8;
7510 macro_build (&label_expr, "bne", "s,t,p", treg, ZERO);
7511 macro_build (NULL, s, "z,s,t", sreg, treg);
7513 /* We want to close the noreorder block as soon as possible, so
7514 that later insns are available for delay slot filling. */
7516 macro_build (NULL, "break", BRK_FMT, 7);
7517 if (mips_opts.micromips)
7518 micromips_add_label ();
7520 macro_build (NULL, s2, MFHL_FMT, dreg);
7532 /* Load the address of a symbol into a register. If breg is not
7533 zero, we then add a base register to it. */
7535 if (dbl && HAVE_32BIT_GPRS)
7536 as_warn (_("dla used to load 32-bit register"));
7538 if (!dbl && HAVE_64BIT_OBJECTS)
7539 as_warn (_("la used to load 64-bit address"));
7541 if (offset_expr.X_op == O_constant
7542 && offset_expr.X_add_number >= -0x8000
7543 && offset_expr.X_add_number < 0x8000)
7545 macro_build (&offset_expr, ADDRESS_ADDI_INSN,
7546 "t,r,j", treg, sreg, BFD_RELOC_LO16);
7550 if (mips_opts.at && (treg == breg))
7560 if (offset_expr.X_op != O_symbol
7561 && offset_expr.X_op != O_constant)
7563 as_bad (_("Expression too complex"));
7564 offset_expr.X_op = O_constant;
7567 if (offset_expr.X_op == O_constant)
7568 load_register (tempreg, &offset_expr, HAVE_64BIT_ADDRESSES);
7569 else if (mips_pic == NO_PIC)
7571 /* If this is a reference to a GP relative symbol, we want
7572 addiu $tempreg,$gp,<sym> (BFD_RELOC_GPREL16)
7574 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
7575 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
7576 If we have a constant, we need two instructions anyhow,
7577 so we may as well always use the latter form.
7579 With 64bit address space and a usable $at we want
7580 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
7581 lui $at,<sym> (BFD_RELOC_HI16_S)
7582 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
7583 daddiu $at,<sym> (BFD_RELOC_LO16)
7585 daddu $tempreg,$tempreg,$at
7587 If $at is already in use, we use a path which is suboptimal
7588 on superscalar processors.
7589 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
7590 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
7592 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
7594 daddiu $tempreg,<sym> (BFD_RELOC_LO16)
7596 For GP relative symbols in 64bit address space we can use
7597 the same sequence as in 32bit address space. */
7598 if (HAVE_64BIT_SYMBOLS)
7600 if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
7601 && !nopic_need_relax (offset_expr.X_add_symbol, 1))
7603 relax_start (offset_expr.X_add_symbol);
7604 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
7605 tempreg, mips_gp_register, BFD_RELOC_GPREL16);
7609 if (used_at == 0 && mips_opts.at)
7611 macro_build (&offset_expr, "lui", LUI_FMT,
7612 tempreg, BFD_RELOC_MIPS_HIGHEST);
7613 macro_build (&offset_expr, "lui", LUI_FMT,
7614 AT, BFD_RELOC_HI16_S);
7615 macro_build (&offset_expr, "daddiu", "t,r,j",
7616 tempreg, tempreg, BFD_RELOC_MIPS_HIGHER);
7617 macro_build (&offset_expr, "daddiu", "t,r,j",
7618 AT, AT, BFD_RELOC_LO16);
7619 macro_build (NULL, "dsll32", SHFT_FMT, tempreg, tempreg, 0);
7620 macro_build (NULL, "daddu", "d,v,t", tempreg, tempreg, AT);
7625 macro_build (&offset_expr, "lui", LUI_FMT,
7626 tempreg, BFD_RELOC_MIPS_HIGHEST);
7627 macro_build (&offset_expr, "daddiu", "t,r,j",
7628 tempreg, tempreg, BFD_RELOC_MIPS_HIGHER);
7629 macro_build (NULL, "dsll", SHFT_FMT, tempreg, tempreg, 16);
7630 macro_build (&offset_expr, "daddiu", "t,r,j",
7631 tempreg, tempreg, BFD_RELOC_HI16_S);
7632 macro_build (NULL, "dsll", SHFT_FMT, tempreg, tempreg, 16);
7633 macro_build (&offset_expr, "daddiu", "t,r,j",
7634 tempreg, tempreg, BFD_RELOC_LO16);
7637 if (mips_relax.sequence)
7642 if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
7643 && !nopic_need_relax (offset_expr.X_add_symbol, 1))
7645 relax_start (offset_expr.X_add_symbol);
7646 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
7647 tempreg, mips_gp_register, BFD_RELOC_GPREL16);
7650 if (!IS_SEXT_32BIT_NUM (offset_expr.X_add_number))
7651 as_bad (_("Offset too large"));
7652 macro_build_lui (&offset_expr, tempreg);
7653 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
7654 tempreg, tempreg, BFD_RELOC_LO16);
7655 if (mips_relax.sequence)
7659 else if (!mips_big_got && !HAVE_NEWABI)
7661 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT16;
7663 /* If this is a reference to an external symbol, and there
7664 is no constant, we want
7665 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
7666 or for lca or if tempreg is PIC_CALL_REG
7667 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
7668 For a local symbol, we want
7669 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
7671 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
7673 If we have a small constant, and this is a reference to
7674 an external symbol, we want
7675 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
7677 addiu $tempreg,$tempreg,<constant>
7678 For a local symbol, we want the same instruction
7679 sequence, but we output a BFD_RELOC_LO16 reloc on the
7682 If we have a large constant, and this is a reference to
7683 an external symbol, we want
7684 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
7685 lui $at,<hiconstant>
7686 addiu $at,$at,<loconstant>
7687 addu $tempreg,$tempreg,$at
7688 For a local symbol, we want the same instruction
7689 sequence, but we output a BFD_RELOC_LO16 reloc on the
7693 if (offset_expr.X_add_number == 0)
7695 if (mips_pic == SVR4_PIC
7697 && (call || tempreg == PIC_CALL_REG))
7698 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL16;
7700 relax_start (offset_expr.X_add_symbol);
7701 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
7702 lw_reloc_type, mips_gp_register);
7705 /* We're going to put in an addu instruction using
7706 tempreg, so we may as well insert the nop right
7711 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
7712 tempreg, BFD_RELOC_MIPS_GOT16, mips_gp_register);
7714 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
7715 tempreg, tempreg, BFD_RELOC_LO16);
7717 /* FIXME: If breg == 0, and the next instruction uses
7718 $tempreg, then if this variant case is used an extra
7719 nop will be generated. */
7721 else if (offset_expr.X_add_number >= -0x8000
7722 && offset_expr.X_add_number < 0x8000)
7724 load_got_offset (tempreg, &offset_expr);
7726 add_got_offset (tempreg, &offset_expr);
7730 expr1.X_add_number = offset_expr.X_add_number;
7731 offset_expr.X_add_number =
7732 SEXT_16BIT (offset_expr.X_add_number);
7733 load_got_offset (tempreg, &offset_expr);
7734 offset_expr.X_add_number = expr1.X_add_number;
7735 /* If we are going to add in a base register, and the
7736 target register and the base register are the same,
7737 then we are using AT as a temporary register. Since
7738 we want to load the constant into AT, we add our
7739 current AT (from the global offset table) and the
7740 register into the register now, and pretend we were
7741 not using a base register. */
7745 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
7750 add_got_offset_hilo (tempreg, &offset_expr, AT);
7754 else if (!mips_big_got && HAVE_NEWABI)
7756 int add_breg_early = 0;
7758 /* If this is a reference to an external, and there is no
7759 constant, or local symbol (*), with or without a
7761 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
7762 or for lca or if tempreg is PIC_CALL_REG
7763 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
7765 If we have a small constant, and this is a reference to
7766 an external symbol, we want
7767 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
7768 addiu $tempreg,$tempreg,<constant>
7770 If we have a large constant, and this is a reference to
7771 an external symbol, we want
7772 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
7773 lui $at,<hiconstant>
7774 addiu $at,$at,<loconstant>
7775 addu $tempreg,$tempreg,$at
7777 (*) Other assemblers seem to prefer GOT_PAGE/GOT_OFST for
7778 local symbols, even though it introduces an additional
7781 if (offset_expr.X_add_number)
7783 expr1.X_add_number = offset_expr.X_add_number;
7784 offset_expr.X_add_number = 0;
7786 relax_start (offset_expr.X_add_symbol);
7787 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
7788 BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
7790 if (expr1.X_add_number >= -0x8000
7791 && expr1.X_add_number < 0x8000)
7793 macro_build (&expr1, ADDRESS_ADDI_INSN, "t,r,j",
7794 tempreg, tempreg, BFD_RELOC_LO16);
7796 else if (IS_SEXT_32BIT_NUM (expr1.X_add_number + 0x8000))
7798 /* If we are going to add in a base register, and the
7799 target register and the base register are the same,
7800 then we are using AT as a temporary register. Since
7801 we want to load the constant into AT, we add our
7802 current AT (from the global offset table) and the
7803 register into the register now, and pretend we were
7804 not using a base register. */
7809 gas_assert (tempreg == AT);
7810 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
7816 load_register (AT, &expr1, HAVE_64BIT_ADDRESSES);
7817 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
7823 as_bad (_("PIC code offset overflow (max 32 signed bits)"));
7826 offset_expr.X_add_number = expr1.X_add_number;
7828 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
7829 BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
7832 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
7833 treg, tempreg, breg);
7839 else if (breg == 0 && (call || tempreg == PIC_CALL_REG))
7841 relax_start (offset_expr.X_add_symbol);
7842 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
7843 BFD_RELOC_MIPS_CALL16, mips_gp_register);
7845 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
7846 BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
7851 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
7852 BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
7855 else if (mips_big_got && !HAVE_NEWABI)
7858 int lui_reloc_type = (int) BFD_RELOC_MIPS_GOT_HI16;
7859 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT_LO16;
7860 int local_reloc_type = (int) BFD_RELOC_MIPS_GOT16;
7862 /* This is the large GOT case. If this is a reference to an
7863 external symbol, and there is no constant, we want
7864 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
7865 addu $tempreg,$tempreg,$gp
7866 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
7867 or for lca or if tempreg is PIC_CALL_REG
7868 lui $tempreg,<sym> (BFD_RELOC_MIPS_CALL_HI16)
7869 addu $tempreg,$tempreg,$gp
7870 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_CALL_LO16)
7871 For a local symbol, we want
7872 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
7874 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
7876 If we have a small constant, and this is a reference to
7877 an external symbol, we want
7878 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
7879 addu $tempreg,$tempreg,$gp
7880 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
7882 addiu $tempreg,$tempreg,<constant>
7883 For a local symbol, we want
7884 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
7886 addiu $tempreg,$tempreg,<constant> (BFD_RELOC_LO16)
7888 If we have a large constant, and this is a reference to
7889 an external symbol, we want
7890 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
7891 addu $tempreg,$tempreg,$gp
7892 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
7893 lui $at,<hiconstant>
7894 addiu $at,$at,<loconstant>
7895 addu $tempreg,$tempreg,$at
7896 For a local symbol, we want
7897 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
7898 lui $at,<hiconstant>
7899 addiu $at,$at,<loconstant> (BFD_RELOC_LO16)
7900 addu $tempreg,$tempreg,$at
7903 expr1.X_add_number = offset_expr.X_add_number;
7904 offset_expr.X_add_number = 0;
7905 relax_start (offset_expr.X_add_symbol);
7906 gpdelay = reg_needs_delay (mips_gp_register);
7907 if (expr1.X_add_number == 0 && breg == 0
7908 && (call || tempreg == PIC_CALL_REG))
7910 lui_reloc_type = (int) BFD_RELOC_MIPS_CALL_HI16;
7911 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL_LO16;
7913 macro_build (&offset_expr, "lui", LUI_FMT, tempreg, lui_reloc_type);
7914 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
7915 tempreg, tempreg, mips_gp_register);
7916 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
7917 tempreg, lw_reloc_type, tempreg);
7918 if (expr1.X_add_number == 0)
7922 /* We're going to put in an addu instruction using
7923 tempreg, so we may as well insert the nop right
7928 else if (expr1.X_add_number >= -0x8000
7929 && expr1.X_add_number < 0x8000)
7932 macro_build (&expr1, ADDRESS_ADDI_INSN, "t,r,j",
7933 tempreg, tempreg, BFD_RELOC_LO16);
7937 /* If we are going to add in a base register, and the
7938 target register and the base register are the same,
7939 then we are using AT as a temporary register. Since
7940 we want to load the constant into AT, we add our
7941 current AT (from the global offset table) and the
7942 register into the register now, and pretend we were
7943 not using a base register. */
7948 gas_assert (tempreg == AT);
7950 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
7955 load_register (AT, &expr1, HAVE_64BIT_ADDRESSES);
7956 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", dreg, dreg, AT);
7960 offset_expr.X_add_number = SEXT_16BIT (expr1.X_add_number);
7965 /* This is needed because this instruction uses $gp, but
7966 the first instruction on the main stream does not. */
7967 macro_build (NULL, "nop", "");
7970 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
7971 local_reloc_type, mips_gp_register);
7972 if (expr1.X_add_number >= -0x8000
7973 && expr1.X_add_number < 0x8000)
7976 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
7977 tempreg, tempreg, BFD_RELOC_LO16);
7978 /* FIXME: If add_number is 0, and there was no base
7979 register, the external symbol case ended with a load,
7980 so if the symbol turns out to not be external, and
7981 the next instruction uses tempreg, an unnecessary nop
7982 will be inserted. */
7988 /* We must add in the base register now, as in the
7989 external symbol case. */
7990 gas_assert (tempreg == AT);
7992 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
7995 /* We set breg to 0 because we have arranged to add
7996 it in in both cases. */
8000 macro_build_lui (&expr1, AT);
8001 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
8002 AT, AT, BFD_RELOC_LO16);
8003 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
8004 tempreg, tempreg, AT);
8009 else if (mips_big_got && HAVE_NEWABI)
8011 int lui_reloc_type = (int) BFD_RELOC_MIPS_GOT_HI16;
8012 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT_LO16;
8013 int add_breg_early = 0;
8015 /* This is the large GOT case. If this is a reference to an
8016 external symbol, and there is no constant, we want
8017 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
8018 add $tempreg,$tempreg,$gp
8019 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
8020 or for lca or if tempreg is PIC_CALL_REG
8021 lui $tempreg,<sym> (BFD_RELOC_MIPS_CALL_HI16)
8022 add $tempreg,$tempreg,$gp
8023 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_CALL_LO16)
8025 If we have a small constant, and this is a reference to
8026 an external symbol, we want
8027 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
8028 add $tempreg,$tempreg,$gp
8029 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
8030 addi $tempreg,$tempreg,<constant>
8032 If we have a large constant, and this is a reference to
8033 an external symbol, we want
8034 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
8035 addu $tempreg,$tempreg,$gp
8036 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
8037 lui $at,<hiconstant>
8038 addi $at,$at,<loconstant>
8039 add $tempreg,$tempreg,$at
8041 If we have NewABI, and we know it's a local symbol, we want
8042 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
8043 addiu $reg,$reg,<sym> (BFD_RELOC_MIPS_GOT_OFST)
8044 otherwise we have to resort to GOT_HI16/GOT_LO16. */
8046 relax_start (offset_expr.X_add_symbol);
8048 expr1.X_add_number = offset_expr.X_add_number;
8049 offset_expr.X_add_number = 0;
8051 if (expr1.X_add_number == 0 && breg == 0
8052 && (call || tempreg == PIC_CALL_REG))
8054 lui_reloc_type = (int) BFD_RELOC_MIPS_CALL_HI16;
8055 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL_LO16;
8057 macro_build (&offset_expr, "lui", LUI_FMT, tempreg, lui_reloc_type);
8058 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
8059 tempreg, tempreg, mips_gp_register);
8060 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
8061 tempreg, lw_reloc_type, tempreg);
8063 if (expr1.X_add_number == 0)
8065 else if (expr1.X_add_number >= -0x8000
8066 && expr1.X_add_number < 0x8000)
8068 macro_build (&expr1, ADDRESS_ADDI_INSN, "t,r,j",
8069 tempreg, tempreg, BFD_RELOC_LO16);
8071 else if (IS_SEXT_32BIT_NUM (expr1.X_add_number + 0x8000))
8073 /* If we are going to add in a base register, and the
8074 target register and the base register are the same,
8075 then we are using AT as a temporary register. Since
8076 we want to load the constant into AT, we add our
8077 current AT (from the global offset table) and the
8078 register into the register now, and pretend we were
8079 not using a base register. */
8084 gas_assert (tempreg == AT);
8085 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
8091 load_register (AT, &expr1, HAVE_64BIT_ADDRESSES);
8092 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", dreg, dreg, AT);
8097 as_bad (_("PIC code offset overflow (max 32 signed bits)"));
8100 offset_expr.X_add_number = expr1.X_add_number;
8101 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
8102 BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register);
8103 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j", tempreg,
8104 tempreg, BFD_RELOC_MIPS_GOT_OFST);
8107 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
8108 treg, tempreg, breg);
8118 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", treg, tempreg, breg);
8122 gas_assert (!mips_opts.micromips);
8124 unsigned long temp = (treg << 16) | (0x01);
8125 macro_build (NULL, "c2", "C", temp);
8130 gas_assert (!mips_opts.micromips);
8132 unsigned long temp = (0x02);
8133 macro_build (NULL, "c2", "C", temp);
8138 gas_assert (!mips_opts.micromips);
8140 unsigned long temp = (treg << 16) | (0x02);
8141 macro_build (NULL, "c2", "C", temp);
8146 gas_assert (!mips_opts.micromips);
8147 macro_build (NULL, "c2", "C", 3);
8151 gas_assert (!mips_opts.micromips);
8153 unsigned long temp = (treg << 16) | 0x03;
8154 macro_build (NULL, "c2", "C", temp);
8159 /* The j instruction may not be used in PIC code, since it
8160 requires an absolute address. We convert it to a b
8162 if (mips_pic == NO_PIC)
8163 macro_build (&offset_expr, "j", "a");
8165 macro_build (&offset_expr, "b", "p");
8168 /* The jal instructions must be handled as macros because when
8169 generating PIC code they expand to multi-instruction
8170 sequences. Normally they are simple instructions. */
8175 gas_assert (mips_opts.micromips);
8183 if (mips_pic == NO_PIC)
8185 s = jals ? "jalrs" : "jalr";
8186 if (mips_opts.micromips
8188 && !(history[0].insn_mo->pinfo2 & INSN2_BRANCH_DELAY_32BIT))
8189 macro_build (NULL, s, "mj", sreg);
8191 macro_build (NULL, s, JALR_FMT, dreg, sreg);
8195 int cprestore = (mips_pic == SVR4_PIC && !HAVE_NEWABI
8196 && mips_cprestore_offset >= 0);
8198 if (sreg != PIC_CALL_REG)
8199 as_warn (_("MIPS PIC call to register other than $25"));
8201 s = (mips_opts.micromips && (!mips_opts.noreorder || cprestore)
8202 ? "jalrs" : "jalr");
8203 if (mips_opts.micromips
8205 && !(history[0].insn_mo->pinfo2 & INSN2_BRANCH_DELAY_32BIT))
8206 macro_build (NULL, s, "mj", sreg);
8208 macro_build (NULL, s, JALR_FMT, dreg, sreg);
8209 if (mips_pic == SVR4_PIC && !HAVE_NEWABI)
8211 if (mips_cprestore_offset < 0)
8212 as_warn (_("No .cprestore pseudo-op used in PIC code"));
8215 if (!mips_frame_reg_valid)
8217 as_warn (_("No .frame pseudo-op used in PIC code"));
8218 /* Quiet this warning. */
8219 mips_frame_reg_valid = 1;
8221 if (!mips_cprestore_valid)
8223 as_warn (_("No .cprestore pseudo-op used in PIC code"));
8224 /* Quiet this warning. */
8225 mips_cprestore_valid = 1;
8227 if (mips_opts.noreorder)
8228 macro_build (NULL, "nop", "");
8229 expr1.X_add_number = mips_cprestore_offset;
8230 macro_build_ldst_constoffset (&expr1, ADDRESS_LOAD_INSN,
8233 HAVE_64BIT_ADDRESSES);
8241 gas_assert (mips_opts.micromips);
8245 if (mips_pic == NO_PIC)
8246 macro_build (&offset_expr, jals ? "jals" : "jal", "a");
8247 else if (mips_pic == SVR4_PIC)
8249 /* If this is a reference to an external symbol, and we are
8250 using a small GOT, we want
8251 lw $25,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
8255 lw $gp,cprestore($sp)
8256 The cprestore value is set using the .cprestore
8257 pseudo-op. If we are using a big GOT, we want
8258 lui $25,<sym> (BFD_RELOC_MIPS_CALL_HI16)
8260 lw $25,<sym>($25) (BFD_RELOC_MIPS_CALL_LO16)
8264 lw $gp,cprestore($sp)
8265 If the symbol is not external, we want
8266 lw $25,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
8268 addiu $25,$25,<sym> (BFD_RELOC_LO16)
8271 lw $gp,cprestore($sp)
8273 For NewABI, we use the same CALL16 or CALL_HI16/CALL_LO16
8274 sequences above, minus nops, unless the symbol is local,
8275 which enables us to use GOT_PAGE/GOT_OFST (big got) or
8281 relax_start (offset_expr.X_add_symbol);
8282 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
8283 PIC_CALL_REG, BFD_RELOC_MIPS_CALL16,
8286 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
8287 PIC_CALL_REG, BFD_RELOC_MIPS_GOT_DISP,
8293 relax_start (offset_expr.X_add_symbol);
8294 macro_build (&offset_expr, "lui", LUI_FMT, PIC_CALL_REG,
8295 BFD_RELOC_MIPS_CALL_HI16);
8296 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", PIC_CALL_REG,
8297 PIC_CALL_REG, mips_gp_register);
8298 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
8299 PIC_CALL_REG, BFD_RELOC_MIPS_CALL_LO16,
8302 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
8303 PIC_CALL_REG, BFD_RELOC_MIPS_GOT_PAGE,
8305 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
8306 PIC_CALL_REG, PIC_CALL_REG,
8307 BFD_RELOC_MIPS_GOT_OFST);
8311 macro_build_jalr (&offset_expr, 0);
8315 relax_start (offset_expr.X_add_symbol);
8318 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
8319 PIC_CALL_REG, BFD_RELOC_MIPS_CALL16,
8328 gpdelay = reg_needs_delay (mips_gp_register);
8329 macro_build (&offset_expr, "lui", LUI_FMT, PIC_CALL_REG,
8330 BFD_RELOC_MIPS_CALL_HI16);
8331 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", PIC_CALL_REG,
8332 PIC_CALL_REG, mips_gp_register);
8333 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
8334 PIC_CALL_REG, BFD_RELOC_MIPS_CALL_LO16,
8339 macro_build (NULL, "nop", "");
8341 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
8342 PIC_CALL_REG, BFD_RELOC_MIPS_GOT16,
8345 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
8346 PIC_CALL_REG, PIC_CALL_REG, BFD_RELOC_LO16);
8348 macro_build_jalr (&offset_expr, mips_cprestore_offset >= 0);
8350 if (mips_cprestore_offset < 0)
8351 as_warn (_("No .cprestore pseudo-op used in PIC code"));
8354 if (!mips_frame_reg_valid)
8356 as_warn (_("No .frame pseudo-op used in PIC code"));
8357 /* Quiet this warning. */
8358 mips_frame_reg_valid = 1;
8360 if (!mips_cprestore_valid)
8362 as_warn (_("No .cprestore pseudo-op used in PIC code"));
8363 /* Quiet this warning. */
8364 mips_cprestore_valid = 1;
8366 if (mips_opts.noreorder)
8367 macro_build (NULL, "nop", "");
8368 expr1.X_add_number = mips_cprestore_offset;
8369 macro_build_ldst_constoffset (&expr1, ADDRESS_LOAD_INSN,
8372 HAVE_64BIT_ADDRESSES);
8376 else if (mips_pic == VXWORKS_PIC)
8377 as_bad (_("Non-PIC jump used in PIC library"));
8485 treg = EXTRACT_OPERAND (mips_opts.micromips, 3BITPOS, *ip);
8493 treg = EXTRACT_OPERAND (mips_opts.micromips, 3BITPOS, *ip);
8524 gas_assert (!mips_opts.micromips);
8527 /* Itbl support may require additional care here. */
8534 /* Itbl support may require additional care here. */
8542 offbits = (mips_opts.micromips ? 12 : 16);
8543 /* Itbl support may require additional care here. */
8548 gas_assert (!mips_opts.micromips);
8551 /* Itbl support may require additional care here. */
8559 offbits = (mips_opts.micromips ? 12 : 16);
8566 offbits = (mips_opts.micromips ? 12 : 16);
8572 /* Itbl support may require additional care here. */
8580 offbits = (mips_opts.micromips ? 12 : 16);
8581 /* Itbl support may require additional care here. */
8588 /* Itbl support may require additional care here. */
8595 /* Itbl support may require additional care here. */
8603 offbits = (mips_opts.micromips ? 12 : 16);
8610 offbits = (mips_opts.micromips ? 12 : 16);
8617 offbits = (mips_opts.micromips ? 12 : 16);
8624 offbits = (mips_opts.micromips ? 12 : 16);
8631 offbits = (mips_opts.micromips ? 12 : 16);
8636 gas_assert (mips_opts.micromips);
8645 gas_assert (mips_opts.micromips);
8654 gas_assert (mips_opts.micromips);
8662 gas_assert (mips_opts.micromips);
8669 /* We don't want to use $0 as tempreg. */
8670 if (breg == treg + lp || treg + lp == ZERO)
8673 tempreg = treg + lp;
8693 gas_assert (!mips_opts.micromips);
8696 /* Itbl support may require additional care here. */
8703 /* Itbl support may require additional care here. */
8711 offbits = (mips_opts.micromips ? 12 : 16);
8712 /* Itbl support may require additional care here. */
8717 gas_assert (!mips_opts.micromips);
8720 /* Itbl support may require additional care here. */
8728 offbits = (mips_opts.micromips ? 12 : 16);
8735 offbits = (mips_opts.micromips ? 12 : 16);
8742 offbits = (mips_opts.micromips ? 12 : 16);
8749 offbits = (mips_opts.micromips ? 12 : 16);
8755 fmt = mips_opts.micromips ? "k,~(b)" : "k,o(b)";
8756 offbits = (mips_opts.micromips ? 12 : 16);
8769 fmt = !mips_opts.micromips ? "k,o(b)" : "k,~(b)";
8770 offbits = (mips_opts.micromips ? 12 : 16);
8784 /* Itbl support may require additional care here. */
8791 offbits = (mips_opts.micromips ? 12 : 16);
8792 /* Itbl support may require additional care here. */
8799 /* Itbl support may require additional care here. */
8804 gas_assert (!mips_opts.micromips);
8807 /* Itbl support may require additional care here. */
8815 offbits = (mips_opts.micromips ? 12 : 16);
8822 offbits = (mips_opts.micromips ? 12 : 16);
8827 gas_assert (mips_opts.micromips);
8835 gas_assert (mips_opts.micromips);
8843 gas_assert (mips_opts.micromips);
8851 gas_assert (mips_opts.micromips);
8860 if (offset_expr.X_op != O_constant
8861 && offset_expr.X_op != O_symbol)
8863 as_bad (_("Expression too complex"));
8864 offset_expr.X_op = O_constant;
8867 if (HAVE_32BIT_ADDRESSES
8868 && !IS_SEXT_32BIT_NUM (offset_expr.X_add_number))
8872 sprintf_vma (value, offset_expr.X_add_number);
8873 as_bad (_("Number (0x%s) larger than 32 bits"), value);
8876 /* A constant expression in PIC code can be handled just as it
8877 is in non PIC code. */
8878 if (offset_expr.X_op == O_constant)
8882 expr1.X_add_number = offset_expr.X_add_number;
8883 normalize_address_expr (&expr1);
8884 if ((offbits == 0 || offbits == 16)
8885 && !IS_SEXT_16BIT_NUM (expr1.X_add_number))
8887 expr1.X_add_number = ((expr1.X_add_number + 0x8000)
8888 & ~(bfd_vma) 0xffff);
8891 else if (offbits == 12 && !IS_SEXT_12BIT_NUM (expr1.X_add_number))
8893 expr1.X_add_number = ((expr1.X_add_number + 0x800)
8894 & ~(bfd_vma) 0xfff);
8897 else if (offbits == 9 && !IS_SEXT_9BIT_NUM (expr1.X_add_number))
8899 expr1.X_add_number = ((expr1.X_add_number + 0x100)
8900 & ~(bfd_vma) 0x1ff);
8905 load_register (tempreg, &expr1, HAVE_64BIT_ADDRESSES);
8907 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
8908 tempreg, tempreg, breg);
8913 if (offset_expr.X_add_number == 0)
8916 macro_build (&offset_expr, ADDRESS_ADDI_INSN,
8917 "t,r,j", tempreg, breg, BFD_RELOC_LO16);
8918 macro_build (NULL, s, fmt, treg, tempreg);
8920 else if (offbits == 16)
8921 macro_build (&offset_expr, s, fmt, treg, BFD_RELOC_LO16, breg);
8923 macro_build (NULL, s, fmt,
8924 treg, (unsigned long) offset_expr.X_add_number, breg);
8926 else if (offbits != 16)
8928 /* The offset field is too narrow to be used for a low-part
8929 relocation, so load the whole address into the auxillary
8930 register. In the case of "A(b)" addresses, we first load
8931 absolute address "A" into the register and then add base
8932 register "b". In the case of "o(b)" addresses, we simply
8933 need to add 16-bit offset "o" to base register "b", and
8934 offset_reloc already contains the relocations associated
8938 load_address (tempreg, &offset_expr, &used_at);
8940 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
8941 tempreg, tempreg, breg);
8944 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
8946 offset_reloc[0], offset_reloc[1], offset_reloc[2]);
8947 expr1.X_add_number = 0;
8949 macro_build (NULL, s, fmt, treg, tempreg);
8951 macro_build (NULL, s, fmt,
8952 treg, (unsigned long) expr1.X_add_number, tempreg);
8954 else if (mips_pic == NO_PIC)
8956 /* If this is a reference to a GP relative symbol, and there
8957 is no base register, we want
8958 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
8959 Otherwise, if there is no base register, we want
8960 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
8961 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
8962 If we have a constant, we need two instructions anyhow,
8963 so we always use the latter form.
8965 If we have a base register, and this is a reference to a
8966 GP relative symbol, we want
8967 addu $tempreg,$breg,$gp
8968 <op> $treg,<sym>($tempreg) (BFD_RELOC_GPREL16)
8970 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
8971 addu $tempreg,$tempreg,$breg
8972 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
8973 With a constant we always use the latter case.
8975 With 64bit address space and no base register and $at usable,
8977 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
8978 lui $at,<sym> (BFD_RELOC_HI16_S)
8979 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
8982 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
8983 If we have a base register, we want
8984 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
8985 lui $at,<sym> (BFD_RELOC_HI16_S)
8986 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
8990 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
8992 Without $at we can't generate the optimal path for superscalar
8993 processors here since this would require two temporary registers.
8994 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
8995 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
8997 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
8999 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
9000 If we have a base register, we want
9001 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
9002 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
9004 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
9006 daddu $tempreg,$tempreg,$breg
9007 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
9009 For GP relative symbols in 64bit address space we can use
9010 the same sequence as in 32bit address space. */
9011 if (HAVE_64BIT_SYMBOLS)
9013 if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
9014 && !nopic_need_relax (offset_expr.X_add_symbol, 1))
9016 relax_start (offset_expr.X_add_symbol);
9019 macro_build (&offset_expr, s, fmt, treg,
9020 BFD_RELOC_GPREL16, mips_gp_register);
9024 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
9025 tempreg, breg, mips_gp_register);
9026 macro_build (&offset_expr, s, fmt, treg,
9027 BFD_RELOC_GPREL16, tempreg);
9032 if (used_at == 0 && mips_opts.at)
9034 macro_build (&offset_expr, "lui", LUI_FMT, tempreg,
9035 BFD_RELOC_MIPS_HIGHEST);
9036 macro_build (&offset_expr, "lui", LUI_FMT, AT,
9038 macro_build (&offset_expr, "daddiu", "t,r,j", tempreg,
9039 tempreg, BFD_RELOC_MIPS_HIGHER);
9041 macro_build (NULL, "daddu", "d,v,t", AT, AT, breg);
9042 macro_build (NULL, "dsll32", SHFT_FMT, tempreg, tempreg, 0);
9043 macro_build (NULL, "daddu", "d,v,t", tempreg, tempreg, AT);
9044 macro_build (&offset_expr, s, fmt, treg, BFD_RELOC_LO16,
9050 macro_build (&offset_expr, "lui", LUI_FMT, tempreg,
9051 BFD_RELOC_MIPS_HIGHEST);
9052 macro_build (&offset_expr, "daddiu", "t,r,j", tempreg,
9053 tempreg, BFD_RELOC_MIPS_HIGHER);
9054 macro_build (NULL, "dsll", SHFT_FMT, tempreg, tempreg, 16);
9055 macro_build (&offset_expr, "daddiu", "t,r,j", tempreg,
9056 tempreg, BFD_RELOC_HI16_S);
9057 macro_build (NULL, "dsll", SHFT_FMT, tempreg, tempreg, 16);
9059 macro_build (NULL, "daddu", "d,v,t",
9060 tempreg, tempreg, breg);
9061 macro_build (&offset_expr, s, fmt, treg,
9062 BFD_RELOC_LO16, tempreg);
9065 if (mips_relax.sequence)
9072 if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
9073 && !nopic_need_relax (offset_expr.X_add_symbol, 1))
9075 relax_start (offset_expr.X_add_symbol);
9076 macro_build (&offset_expr, s, fmt, treg, BFD_RELOC_GPREL16,
9080 macro_build_lui (&offset_expr, tempreg);
9081 macro_build (&offset_expr, s, fmt, treg,
9082 BFD_RELOC_LO16, tempreg);
9083 if (mips_relax.sequence)
9088 if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
9089 && !nopic_need_relax (offset_expr.X_add_symbol, 1))
9091 relax_start (offset_expr.X_add_symbol);
9092 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
9093 tempreg, breg, mips_gp_register);
9094 macro_build (&offset_expr, s, fmt, treg,
9095 BFD_RELOC_GPREL16, tempreg);
9098 macro_build_lui (&offset_expr, tempreg);
9099 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
9100 tempreg, tempreg, breg);
9101 macro_build (&offset_expr, s, fmt, treg,
9102 BFD_RELOC_LO16, tempreg);
9103 if (mips_relax.sequence)
9107 else if (!mips_big_got)
9109 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT16;
9111 /* If this is a reference to an external symbol, we want
9112 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
9114 <op> $treg,0($tempreg)
9116 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
9118 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
9119 <op> $treg,0($tempreg)
9122 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
9123 <op> $treg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_OFST)
9125 If there is a base register, we add it to $tempreg before
9126 the <op>. If there is a constant, we stick it in the
9127 <op> instruction. We don't handle constants larger than
9128 16 bits, because we have no way to load the upper 16 bits
9129 (actually, we could handle them for the subset of cases
9130 in which we are not using $at). */
9131 gas_assert (offset_expr.X_op == O_symbol);
9134 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
9135 BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register);
9137 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
9138 tempreg, tempreg, breg);
9139 macro_build (&offset_expr, s, fmt, treg,
9140 BFD_RELOC_MIPS_GOT_OFST, tempreg);
9143 expr1.X_add_number = offset_expr.X_add_number;
9144 offset_expr.X_add_number = 0;
9145 if (expr1.X_add_number < -0x8000
9146 || expr1.X_add_number >= 0x8000)
9147 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
9148 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
9149 lw_reloc_type, mips_gp_register);
9151 relax_start (offset_expr.X_add_symbol);
9153 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j", tempreg,
9154 tempreg, BFD_RELOC_LO16);
9157 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
9158 tempreg, tempreg, breg);
9159 macro_build (&expr1, s, fmt, treg, BFD_RELOC_LO16, tempreg);
9161 else if (mips_big_got && !HAVE_NEWABI)
9165 /* If this is a reference to an external symbol, we want
9166 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
9167 addu $tempreg,$tempreg,$gp
9168 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
9169 <op> $treg,0($tempreg)
9171 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
9173 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
9174 <op> $treg,0($tempreg)
9175 If there is a base register, we add it to $tempreg before
9176 the <op>. If there is a constant, we stick it in the
9177 <op> instruction. We don't handle constants larger than
9178 16 bits, because we have no way to load the upper 16 bits
9179 (actually, we could handle them for the subset of cases
9180 in which we are not using $at). */
9181 gas_assert (offset_expr.X_op == O_symbol);
9182 expr1.X_add_number = offset_expr.X_add_number;
9183 offset_expr.X_add_number = 0;
9184 if (expr1.X_add_number < -0x8000
9185 || expr1.X_add_number >= 0x8000)
9186 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
9187 gpdelay = reg_needs_delay (mips_gp_register);
9188 relax_start (offset_expr.X_add_symbol);
9189 macro_build (&offset_expr, "lui", LUI_FMT, tempreg,
9190 BFD_RELOC_MIPS_GOT_HI16);
9191 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", tempreg, tempreg,
9193 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
9194 BFD_RELOC_MIPS_GOT_LO16, tempreg);
9197 macro_build (NULL, "nop", "");
9198 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
9199 BFD_RELOC_MIPS_GOT16, mips_gp_register);
9201 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j", tempreg,
9202 tempreg, BFD_RELOC_LO16);
9206 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
9207 tempreg, tempreg, breg);
9208 macro_build (&expr1, s, fmt, treg, BFD_RELOC_LO16, tempreg);
9210 else if (mips_big_got && HAVE_NEWABI)
9212 /* If this is a reference to an external symbol, we want
9213 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
9214 add $tempreg,$tempreg,$gp
9215 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
9216 <op> $treg,<ofst>($tempreg)
9217 Otherwise, for local symbols, we want:
9218 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
9219 <op> $treg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_OFST) */
9220 gas_assert (offset_expr.X_op == O_symbol);
9221 expr1.X_add_number = offset_expr.X_add_number;
9222 offset_expr.X_add_number = 0;
9223 if (expr1.X_add_number < -0x8000
9224 || expr1.X_add_number >= 0x8000)
9225 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
9226 relax_start (offset_expr.X_add_symbol);
9227 macro_build (&offset_expr, "lui", LUI_FMT, tempreg,
9228 BFD_RELOC_MIPS_GOT_HI16);
9229 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", tempreg, tempreg,
9231 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
9232 BFD_RELOC_MIPS_GOT_LO16, tempreg);
9234 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
9235 tempreg, tempreg, breg);
9236 macro_build (&expr1, s, fmt, treg, BFD_RELOC_LO16, tempreg);
9239 offset_expr.X_add_number = expr1.X_add_number;
9240 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
9241 BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register);
9243 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
9244 tempreg, tempreg, breg);
9245 macro_build (&offset_expr, s, fmt, treg,
9246 BFD_RELOC_MIPS_GOT_OFST, tempreg);
9256 load_register (treg, &imm_expr, 0);
9260 load_register (treg, &imm_expr, 1);
9264 if (imm_expr.X_op == O_constant)
9267 load_register (AT, &imm_expr, 0);
9268 macro_build (NULL, "mtc1", "t,G", AT, treg);
9273 gas_assert (offset_expr.X_op == O_symbol
9274 && strcmp (segment_name (S_GET_SEGMENT
9275 (offset_expr.X_add_symbol)),
9277 && offset_expr.X_add_number == 0);
9278 macro_build (&offset_expr, "lwc1", "T,o(b)", treg,
9279 BFD_RELOC_MIPS_LITERAL, mips_gp_register);
9284 /* Check if we have a constant in IMM_EXPR. If the GPRs are 64 bits
9285 wide, IMM_EXPR is the entire value. Otherwise IMM_EXPR is the high
9286 order 32 bits of the value and the low order 32 bits are either
9287 zero or in OFFSET_EXPR. */
9288 if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big)
9290 if (HAVE_64BIT_GPRS)
9291 load_register (treg, &imm_expr, 1);
9296 if (target_big_endian)
9308 load_register (hreg, &imm_expr, 0);
9311 if (offset_expr.X_op == O_absent)
9312 move_register (lreg, 0);
9315 gas_assert (offset_expr.X_op == O_constant);
9316 load_register (lreg, &offset_expr, 0);
9323 /* We know that sym is in the .rdata section. First we get the
9324 upper 16 bits of the address. */
9325 if (mips_pic == NO_PIC)
9327 macro_build_lui (&offset_expr, AT);
9332 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", AT,
9333 BFD_RELOC_MIPS_GOT16, mips_gp_register);
9337 /* Now we load the register(s). */
9338 if (HAVE_64BIT_GPRS)
9341 macro_build (&offset_expr, "ld", "t,o(b)", treg, BFD_RELOC_LO16, AT);
9346 macro_build (&offset_expr, "lw", "t,o(b)", treg, BFD_RELOC_LO16, AT);
9349 /* FIXME: How in the world do we deal with the possible
9351 offset_expr.X_add_number += 4;
9352 macro_build (&offset_expr, "lw", "t,o(b)",
9353 treg + 1, BFD_RELOC_LO16, AT);
9359 /* Check if we have a constant in IMM_EXPR. If the FPRs are 64 bits
9360 wide, IMM_EXPR is the entire value and the GPRs are known to be 64
9361 bits wide as well. Otherwise IMM_EXPR is the high order 32 bits of
9362 the value and the low order 32 bits are either zero or in
9364 if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big)
9367 load_register (AT, &imm_expr, HAVE_64BIT_FPRS);
9368 if (HAVE_64BIT_FPRS)
9370 gas_assert (HAVE_64BIT_GPRS);
9371 macro_build (NULL, "dmtc1", "t,S", AT, treg);
9375 macro_build (NULL, "mtc1", "t,G", AT, treg + 1);
9376 if (offset_expr.X_op == O_absent)
9377 macro_build (NULL, "mtc1", "t,G", 0, treg);
9380 gas_assert (offset_expr.X_op == O_constant);
9381 load_register (AT, &offset_expr, 0);
9382 macro_build (NULL, "mtc1", "t,G", AT, treg);
9388 gas_assert (offset_expr.X_op == O_symbol
9389 && offset_expr.X_add_number == 0);
9390 s = segment_name (S_GET_SEGMENT (offset_expr.X_add_symbol));
9391 if (strcmp (s, ".lit8") == 0)
9393 if (CPU_HAS_LDC1_SDC1 (mips_opts.arch) || mips_opts.micromips)
9395 macro_build (&offset_expr, "ldc1", "T,o(b)", treg,
9396 BFD_RELOC_MIPS_LITERAL, mips_gp_register);
9399 breg = mips_gp_register;
9400 r = BFD_RELOC_MIPS_LITERAL;
9405 gas_assert (strcmp (s, RDATA_SECTION_NAME) == 0);
9407 if (mips_pic != NO_PIC)
9408 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", AT,
9409 BFD_RELOC_MIPS_GOT16, mips_gp_register);
9412 /* FIXME: This won't work for a 64 bit address. */
9413 macro_build_lui (&offset_expr, AT);
9416 if (CPU_HAS_LDC1_SDC1 (mips_opts.arch) || mips_opts.micromips)
9418 macro_build (&offset_expr, "ldc1", "T,o(b)",
9419 treg, BFD_RELOC_LO16, AT);
9428 /* Even on a big endian machine $fn comes before $fn+1. We have
9429 to adjust when loading from memory. */
9432 gas_assert (!mips_opts.micromips);
9433 gas_assert (!CPU_HAS_LDC1_SDC1 (mips_opts.arch));
9434 macro_build (&offset_expr, "lwc1", "T,o(b)",
9435 target_big_endian ? treg + 1 : treg, r, breg);
9436 /* FIXME: A possible overflow which I don't know how to deal
9438 offset_expr.X_add_number += 4;
9439 macro_build (&offset_expr, "lwc1", "T,o(b)",
9440 target_big_endian ? treg : treg + 1, r, breg);
9444 gas_assert (!mips_opts.micromips);
9445 gas_assert (!CPU_HAS_LDC1_SDC1 (mips_opts.arch));
9446 /* Even on a big endian machine $fn comes before $fn+1. We have
9447 to adjust when storing to memory. */
9448 macro_build (&offset_expr, "swc1", "T,o(b)",
9449 target_big_endian ? treg + 1 : treg, BFD_RELOC_LO16, breg);
9450 offset_expr.X_add_number += 4;
9451 macro_build (&offset_expr, "swc1", "T,o(b)",
9452 target_big_endian ? treg : treg + 1, BFD_RELOC_LO16, breg);
9456 gas_assert (!mips_opts.micromips);
9458 * The MIPS assembler seems to check for X_add_number not
9459 * being double aligned and generating:
9462 * addiu at,at,%lo(foo+1)
9465 * But, the resulting address is the same after relocation so why
9466 * generate the extra instruction?
9468 /* Itbl support may require additional care here. */
9471 if (CPU_HAS_LDC1_SDC1 (mips_opts.arch))
9480 gas_assert (!mips_opts.micromips);
9481 /* Itbl support may require additional care here. */
9484 if (CPU_HAS_LDC1_SDC1 (mips_opts.arch))
9504 if (HAVE_64BIT_GPRS)
9514 if (HAVE_64BIT_GPRS)
9522 if (offset_expr.X_op != O_symbol
9523 && offset_expr.X_op != O_constant)
9525 as_bad (_("Expression too complex"));
9526 offset_expr.X_op = O_constant;
9529 if (HAVE_32BIT_ADDRESSES
9530 && !IS_SEXT_32BIT_NUM (offset_expr.X_add_number))
9534 sprintf_vma (value, offset_expr.X_add_number);
9535 as_bad (_("Number (0x%s) larger than 32 bits"), value);
9538 /* Even on a big endian machine $fn comes before $fn+1. We have
9539 to adjust when loading from memory. We set coproc if we must
9540 load $fn+1 first. */
9541 /* Itbl support may require additional care here. */
9542 if (!target_big_endian)
9545 if (mips_pic == NO_PIC || offset_expr.X_op == O_constant)
9547 /* If this is a reference to a GP relative symbol, we want
9548 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
9549 <op> $treg+1,<sym>+4($gp) (BFD_RELOC_GPREL16)
9550 If we have a base register, we use this
9552 <op> $treg,<sym>($at) (BFD_RELOC_GPREL16)
9553 <op> $treg+1,<sym>+4($at) (BFD_RELOC_GPREL16)
9554 If this is not a GP relative symbol, we want
9555 lui $at,<sym> (BFD_RELOC_HI16_S)
9556 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
9557 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
9558 If there is a base register, we add it to $at after the
9559 lui instruction. If there is a constant, we always use
9561 if (offset_expr.X_op == O_symbol
9562 && (valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
9563 && !nopic_need_relax (offset_expr.X_add_symbol, 1))
9565 relax_start (offset_expr.X_add_symbol);
9568 tempreg = mips_gp_register;
9572 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
9573 AT, breg, mips_gp_register);
9578 /* Itbl support may require additional care here. */
9579 macro_build (&offset_expr, s, fmt, coproc ? treg + 1 : treg,
9580 BFD_RELOC_GPREL16, tempreg);
9581 offset_expr.X_add_number += 4;
9583 /* Set mips_optimize to 2 to avoid inserting an
9585 hold_mips_optimize = mips_optimize;
9587 /* Itbl support may require additional care here. */
9588 macro_build (&offset_expr, s, fmt, coproc ? treg : treg + 1,
9589 BFD_RELOC_GPREL16, tempreg);
9590 mips_optimize = hold_mips_optimize;
9594 offset_expr.X_add_number -= 4;
9597 macro_build_lui (&offset_expr, AT);
9599 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, breg, AT);
9600 /* Itbl support may require additional care here. */
9601 macro_build (&offset_expr, s, fmt, coproc ? treg + 1 : treg,
9602 BFD_RELOC_LO16, AT);
9603 /* FIXME: How do we handle overflow here? */
9604 offset_expr.X_add_number += 4;
9605 /* Itbl support may require additional care here. */
9606 macro_build (&offset_expr, s, fmt, coproc ? treg : treg + 1,
9607 BFD_RELOC_LO16, AT);
9608 if (mips_relax.sequence)
9611 else if (!mips_big_got)
9613 /* If this is a reference to an external symbol, we want
9614 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
9619 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
9621 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
9622 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
9623 If there is a base register we add it to $at before the
9624 lwc1 instructions. If there is a constant we include it
9625 in the lwc1 instructions. */
9627 expr1.X_add_number = offset_expr.X_add_number;
9628 if (expr1.X_add_number < -0x8000
9629 || expr1.X_add_number >= 0x8000 - 4)
9630 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
9631 load_got_offset (AT, &offset_expr);
9634 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, breg, AT);
9636 /* Set mips_optimize to 2 to avoid inserting an undesired
9638 hold_mips_optimize = mips_optimize;
9641 /* Itbl support may require additional care here. */
9642 relax_start (offset_expr.X_add_symbol);
9643 macro_build (&expr1, s, fmt, coproc ? treg + 1 : treg,
9644 BFD_RELOC_LO16, AT);
9645 expr1.X_add_number += 4;
9646 macro_build (&expr1, s, fmt, coproc ? treg : treg + 1,
9647 BFD_RELOC_LO16, AT);
9649 macro_build (&offset_expr, s, fmt, coproc ? treg + 1 : treg,
9650 BFD_RELOC_LO16, AT);
9651 offset_expr.X_add_number += 4;
9652 macro_build (&offset_expr, s, fmt, coproc ? treg : treg + 1,
9653 BFD_RELOC_LO16, AT);
9656 mips_optimize = hold_mips_optimize;
9658 else if (mips_big_got)
9662 /* If this is a reference to an external symbol, we want
9663 lui $at,<sym> (BFD_RELOC_MIPS_GOT_HI16)
9665 lw $at,<sym>($at) (BFD_RELOC_MIPS_GOT_LO16)
9670 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
9672 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
9673 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
9674 If there is a base register we add it to $at before the
9675 lwc1 instructions. If there is a constant we include it
9676 in the lwc1 instructions. */
9678 expr1.X_add_number = offset_expr.X_add_number;
9679 offset_expr.X_add_number = 0;
9680 if (expr1.X_add_number < -0x8000
9681 || expr1.X_add_number >= 0x8000 - 4)
9682 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
9683 gpdelay = reg_needs_delay (mips_gp_register);
9684 relax_start (offset_expr.X_add_symbol);
9685 macro_build (&offset_expr, "lui", LUI_FMT,
9686 AT, BFD_RELOC_MIPS_GOT_HI16);
9687 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
9688 AT, AT, mips_gp_register);
9689 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
9690 AT, BFD_RELOC_MIPS_GOT_LO16, AT);
9693 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, breg, AT);
9694 /* Itbl support may require additional care here. */
9695 macro_build (&expr1, s, fmt, coproc ? treg + 1 : treg,
9696 BFD_RELOC_LO16, AT);
9697 expr1.X_add_number += 4;
9699 /* Set mips_optimize to 2 to avoid inserting an undesired
9701 hold_mips_optimize = mips_optimize;
9703 /* Itbl support may require additional care here. */
9704 macro_build (&expr1, s, fmt, coproc ? treg : treg + 1,
9705 BFD_RELOC_LO16, AT);
9706 mips_optimize = hold_mips_optimize;
9707 expr1.X_add_number -= 4;
9710 offset_expr.X_add_number = expr1.X_add_number;
9712 macro_build (NULL, "nop", "");
9713 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", AT,
9714 BFD_RELOC_MIPS_GOT16, mips_gp_register);
9717 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, breg, AT);
9718 /* Itbl support may require additional care here. */
9719 macro_build (&offset_expr, s, fmt, coproc ? treg + 1 : treg,
9720 BFD_RELOC_LO16, AT);
9721 offset_expr.X_add_number += 4;
9723 /* Set mips_optimize to 2 to avoid inserting an undesired
9725 hold_mips_optimize = mips_optimize;
9727 /* Itbl support may require additional care here. */
9728 macro_build (&offset_expr, s, fmt, coproc ? treg : treg + 1,
9729 BFD_RELOC_LO16, AT);
9730 mips_optimize = hold_mips_optimize;
9739 s = HAVE_64BIT_GPRS ? "ld" : "lw";
9742 s = HAVE_64BIT_GPRS ? "sd" : "sw";
9744 macro_build (&offset_expr, s, "t,o(b)", treg,
9745 -1, offset_reloc[0], offset_reloc[1], offset_reloc[2],
9747 if (!HAVE_64BIT_GPRS)
9749 offset_expr.X_add_number += 4;
9750 macro_build (&offset_expr, s, "t,o(b)", treg + 1,
9751 -1, offset_reloc[0], offset_reloc[1], offset_reloc[2],
9772 /* New code added to support COPZ instructions.
9773 This code builds table entries out of the macros in mip_opcodes.
9774 R4000 uses interlocks to handle coproc delays.
9775 Other chips (like the R3000) require nops to be inserted for delays.
9777 FIXME: Currently, we require that the user handle delays.
9778 In order to fill delay slots for non-interlocked chips,
9779 we must have a way to specify delays based on the coprocessor.
9780 Eg. 4 cycles if load coproc reg from memory, 1 if in cache, etc.
9781 What are the side-effects of the cop instruction?
9782 What cache support might we have and what are its effects?
9783 Both coprocessor & memory require delays. how long???
9784 What registers are read/set/modified?
9786 If an itbl is provided to interpret cop instructions,
9787 this knowledge can be encoded in the itbl spec. */
9801 gas_assert (!mips_opts.micromips);
9802 /* For now we just do C (same as Cz). The parameter will be
9803 stored in insn_opcode by mips_ip. */
9804 macro_build (NULL, s, "C", ip->insn_opcode);
9808 move_register (dreg, sreg);
9814 if (mips_opts.arch == CPU_R5900)
9816 macro_build (NULL, dbl ? "dmultu" : "multu", "d,s,t", dreg, sreg, treg);
9820 macro_build (NULL, dbl ? "dmultu" : "multu", "s,t", sreg, treg);
9821 macro_build (NULL, "mflo", MFHL_FMT, dreg);
9828 /* The MIPS assembler some times generates shifts and adds. I'm
9829 not trying to be that fancy. GCC should do this for us
9832 load_register (AT, &imm_expr, dbl);
9833 macro_build (NULL, dbl ? "dmult" : "mult", "s,t", sreg, AT);
9834 macro_build (NULL, "mflo", MFHL_FMT, dreg);
9850 load_register (AT, &imm_expr, dbl);
9851 macro_build (NULL, dbl ? "dmult" : "mult", "s,t", sreg, imm ? AT : treg);
9852 macro_build (NULL, "mflo", MFHL_FMT, dreg);
9853 macro_build (NULL, dbl ? "dsra32" : "sra", SHFT_FMT, dreg, dreg, RA);
9854 macro_build (NULL, "mfhi", MFHL_FMT, AT);
9856 macro_build (NULL, "tne", TRAP_FMT, dreg, AT, 6);
9859 if (mips_opts.micromips)
9860 micromips_label_expr (&label_expr);
9862 label_expr.X_add_number = 8;
9863 macro_build (&label_expr, "beq", "s,t,p", dreg, AT);
9864 macro_build (NULL, "nop", "");
9865 macro_build (NULL, "break", BRK_FMT, 6);
9866 if (mips_opts.micromips)
9867 micromips_add_label ();
9870 macro_build (NULL, "mflo", MFHL_FMT, dreg);
9886 load_register (AT, &imm_expr, dbl);
9887 macro_build (NULL, dbl ? "dmultu" : "multu", "s,t",
9888 sreg, imm ? AT : treg);
9889 macro_build (NULL, "mfhi", MFHL_FMT, AT);
9890 macro_build (NULL, "mflo", MFHL_FMT, dreg);
9892 macro_build (NULL, "tne", TRAP_FMT, AT, ZERO, 6);
9895 if (mips_opts.micromips)
9896 micromips_label_expr (&label_expr);
9898 label_expr.X_add_number = 8;
9899 macro_build (&label_expr, "beq", "s,t,p", AT, ZERO);
9900 macro_build (NULL, "nop", "");
9901 macro_build (NULL, "break", BRK_FMT, 6);
9902 if (mips_opts.micromips)
9903 micromips_add_label ();
9909 if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_opts.arch))
9920 macro_build (NULL, "dnegu", "d,w", tempreg, treg);
9921 macro_build (NULL, "drorv", "d,t,s", dreg, sreg, tempreg);
9925 macro_build (NULL, "dsubu", "d,v,t", AT, ZERO, treg);
9926 macro_build (NULL, "dsrlv", "d,t,s", AT, sreg, AT);
9927 macro_build (NULL, "dsllv", "d,t,s", dreg, sreg, treg);
9928 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
9932 if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_opts.arch))
9943 macro_build (NULL, "negu", "d,w", tempreg, treg);
9944 macro_build (NULL, "rorv", "d,t,s", dreg, sreg, tempreg);
9948 macro_build (NULL, "subu", "d,v,t", AT, ZERO, treg);
9949 macro_build (NULL, "srlv", "d,t,s", AT, sreg, AT);
9950 macro_build (NULL, "sllv", "d,t,s", dreg, sreg, treg);
9951 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
9960 if (imm_expr.X_op != O_constant)
9961 as_bad (_("Improper rotate count"));
9962 rot = imm_expr.X_add_number & 0x3f;
9963 if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_opts.arch))
9965 rot = (64 - rot) & 0x3f;
9967 macro_build (NULL, "dror32", SHFT_FMT, dreg, sreg, rot - 32);
9969 macro_build (NULL, "dror", SHFT_FMT, dreg, sreg, rot);
9974 macro_build (NULL, "dsrl", SHFT_FMT, dreg, sreg, 0);
9977 l = (rot < 0x20) ? "dsll" : "dsll32";
9978 rr = ((0x40 - rot) < 0x20) ? "dsrl" : "dsrl32";
9981 macro_build (NULL, l, SHFT_FMT, AT, sreg, rot);
9982 macro_build (NULL, rr, SHFT_FMT, dreg, sreg, (0x20 - rot) & 0x1f);
9983 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
9991 if (imm_expr.X_op != O_constant)
9992 as_bad (_("Improper rotate count"));
9993 rot = imm_expr.X_add_number & 0x1f;
9994 if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_opts.arch))
9996 macro_build (NULL, "ror", SHFT_FMT, dreg, sreg, (32 - rot) & 0x1f);
10001 macro_build (NULL, "srl", SHFT_FMT, dreg, sreg, 0);
10005 macro_build (NULL, "sll", SHFT_FMT, AT, sreg, rot);
10006 macro_build (NULL, "srl", SHFT_FMT, dreg, sreg, (0x20 - rot) & 0x1f);
10007 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
10012 if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_opts.arch))
10014 macro_build (NULL, "drorv", "d,t,s", dreg, sreg, treg);
10018 macro_build (NULL, "dsubu", "d,v,t", AT, ZERO, treg);
10019 macro_build (NULL, "dsllv", "d,t,s", AT, sreg, AT);
10020 macro_build (NULL, "dsrlv", "d,t,s", dreg, sreg, treg);
10021 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
10025 if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_opts.arch))
10027 macro_build (NULL, "rorv", "d,t,s", dreg, sreg, treg);
10031 macro_build (NULL, "subu", "d,v,t", AT, ZERO, treg);
10032 macro_build (NULL, "sllv", "d,t,s", AT, sreg, AT);
10033 macro_build (NULL, "srlv", "d,t,s", dreg, sreg, treg);
10034 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
10043 if (imm_expr.X_op != O_constant)
10044 as_bad (_("Improper rotate count"));
10045 rot = imm_expr.X_add_number & 0x3f;
10046 if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_opts.arch))
10049 macro_build (NULL, "dror32", SHFT_FMT, dreg, sreg, rot - 32);
10051 macro_build (NULL, "dror", SHFT_FMT, dreg, sreg, rot);
10056 macro_build (NULL, "dsrl", SHFT_FMT, dreg, sreg, 0);
10059 rr = (rot < 0x20) ? "dsrl" : "dsrl32";
10060 l = ((0x40 - rot) < 0x20) ? "dsll" : "dsll32";
10063 macro_build (NULL, rr, SHFT_FMT, AT, sreg, rot);
10064 macro_build (NULL, l, SHFT_FMT, dreg, sreg, (0x20 - rot) & 0x1f);
10065 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
10073 if (imm_expr.X_op != O_constant)
10074 as_bad (_("Improper rotate count"));
10075 rot = imm_expr.X_add_number & 0x1f;
10076 if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_opts.arch))
10078 macro_build (NULL, "ror", SHFT_FMT, dreg, sreg, rot);
10083 macro_build (NULL, "srl", SHFT_FMT, dreg, sreg, 0);
10087 macro_build (NULL, "srl", SHFT_FMT, AT, sreg, rot);
10088 macro_build (NULL, "sll", SHFT_FMT, dreg, sreg, (0x20 - rot) & 0x1f);
10089 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
10095 macro_build (&expr1, "sltiu", "t,r,j", dreg, treg, BFD_RELOC_LO16);
10096 else if (treg == 0)
10097 macro_build (&expr1, "sltiu", "t,r,j", dreg, sreg, BFD_RELOC_LO16);
10100 macro_build (NULL, "xor", "d,v,t", dreg, sreg, treg);
10101 macro_build (&expr1, "sltiu", "t,r,j", dreg, dreg, BFD_RELOC_LO16);
10106 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
10108 macro_build (&expr1, "sltiu", "t,r,j", dreg, sreg, BFD_RELOC_LO16);
10113 as_warn (_("Instruction %s: result is always false"),
10114 ip->insn_mo->name);
10115 move_register (dreg, 0);
10118 if (CPU_HAS_SEQ (mips_opts.arch)
10119 && -512 <= imm_expr.X_add_number
10120 && imm_expr.X_add_number < 512)
10122 macro_build (NULL, "seqi", "t,r,+Q", dreg, sreg,
10123 (int) imm_expr.X_add_number);
10126 if (imm_expr.X_op == O_constant
10127 && imm_expr.X_add_number >= 0
10128 && imm_expr.X_add_number < 0x10000)
10130 macro_build (&imm_expr, "xori", "t,r,i", dreg, sreg, BFD_RELOC_LO16);
10132 else if (imm_expr.X_op == O_constant
10133 && imm_expr.X_add_number > -0x8000
10134 && imm_expr.X_add_number < 0)
10136 imm_expr.X_add_number = -imm_expr.X_add_number;
10137 macro_build (&imm_expr, HAVE_32BIT_GPRS ? "addiu" : "daddiu",
10138 "t,r,j", dreg, sreg, BFD_RELOC_LO16);
10140 else if (CPU_HAS_SEQ (mips_opts.arch))
10143 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
10144 macro_build (NULL, "seq", "d,v,t", dreg, sreg, AT);
10149 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
10150 macro_build (NULL, "xor", "d,v,t", dreg, sreg, AT);
10153 macro_build (&expr1, "sltiu", "t,r,j", dreg, dreg, BFD_RELOC_LO16);
10156 case M_SGE: /* sreg >= treg <==> not (sreg < treg) */
10162 macro_build (NULL, s, "d,v,t", dreg, sreg, treg);
10163 macro_build (&expr1, "xori", "t,r,i", dreg, dreg, BFD_RELOC_LO16);
10166 case M_SGE_I: /* sreg >= I <==> not (sreg < I) */
10168 if (imm_expr.X_op == O_constant
10169 && imm_expr.X_add_number >= -0x8000
10170 && imm_expr.X_add_number < 0x8000)
10172 macro_build (&imm_expr, mask == M_SGE_I ? "slti" : "sltiu", "t,r,j",
10173 dreg, sreg, BFD_RELOC_LO16);
10177 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
10178 macro_build (NULL, mask == M_SGE_I ? "slt" : "sltu", "d,v,t",
10182 macro_build (&expr1, "xori", "t,r,i", dreg, dreg, BFD_RELOC_LO16);
10185 case M_SGT: /* sreg > treg <==> treg < sreg */
10191 macro_build (NULL, s, "d,v,t", dreg, treg, sreg);
10194 case M_SGT_I: /* sreg > I <==> I < sreg */
10201 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
10202 macro_build (NULL, s, "d,v,t", dreg, AT, sreg);
10205 case M_SLE: /* sreg <= treg <==> treg >= sreg <==> not (treg < sreg) */
10211 macro_build (NULL, s, "d,v,t", dreg, treg, sreg);
10212 macro_build (&expr1, "xori", "t,r,i", dreg, dreg, BFD_RELOC_LO16);
10215 case M_SLE_I: /* sreg <= I <==> I >= sreg <==> not (I < sreg) */
10222 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
10223 macro_build (NULL, s, "d,v,t", dreg, AT, sreg);
10224 macro_build (&expr1, "xori", "t,r,i", dreg, dreg, BFD_RELOC_LO16);
10228 if (imm_expr.X_op == O_constant
10229 && imm_expr.X_add_number >= -0x8000
10230 && imm_expr.X_add_number < 0x8000)
10232 macro_build (&imm_expr, "slti", "t,r,j", dreg, sreg, BFD_RELOC_LO16);
10236 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
10237 macro_build (NULL, "slt", "d,v,t", dreg, sreg, AT);
10241 if (imm_expr.X_op == O_constant
10242 && imm_expr.X_add_number >= -0x8000
10243 && imm_expr.X_add_number < 0x8000)
10245 macro_build (&imm_expr, "sltiu", "t,r,j", dreg, sreg,
10250 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
10251 macro_build (NULL, "sltu", "d,v,t", dreg, sreg, AT);
10256 macro_build (NULL, "sltu", "d,v,t", dreg, 0, treg);
10257 else if (treg == 0)
10258 macro_build (NULL, "sltu", "d,v,t", dreg, 0, sreg);
10261 macro_build (NULL, "xor", "d,v,t", dreg, sreg, treg);
10262 macro_build (NULL, "sltu", "d,v,t", dreg, 0, dreg);
10267 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
10269 macro_build (NULL, "sltu", "d,v,t", dreg, 0, sreg);
10274 as_warn (_("Instruction %s: result is always true"),
10275 ip->insn_mo->name);
10276 macro_build (&expr1, HAVE_32BIT_GPRS ? "addiu" : "daddiu", "t,r,j",
10277 dreg, 0, BFD_RELOC_LO16);
10280 if (CPU_HAS_SEQ (mips_opts.arch)
10281 && -512 <= imm_expr.X_add_number
10282 && imm_expr.X_add_number < 512)
10284 macro_build (NULL, "snei", "t,r,+Q", dreg, sreg,
10285 (int) imm_expr.X_add_number);
10288 if (imm_expr.X_op == O_constant
10289 && imm_expr.X_add_number >= 0
10290 && imm_expr.X_add_number < 0x10000)
10292 macro_build (&imm_expr, "xori", "t,r,i", dreg, sreg, BFD_RELOC_LO16);
10294 else if (imm_expr.X_op == O_constant
10295 && imm_expr.X_add_number > -0x8000
10296 && imm_expr.X_add_number < 0)
10298 imm_expr.X_add_number = -imm_expr.X_add_number;
10299 macro_build (&imm_expr, HAVE_32BIT_GPRS ? "addiu" : "daddiu",
10300 "t,r,j", dreg, sreg, BFD_RELOC_LO16);
10302 else if (CPU_HAS_SEQ (mips_opts.arch))
10305 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
10306 macro_build (NULL, "sne", "d,v,t", dreg, sreg, AT);
10311 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
10312 macro_build (NULL, "xor", "d,v,t", dreg, sreg, AT);
10315 macro_build (NULL, "sltu", "d,v,t", dreg, 0, dreg);
10330 if (!mips_opts.micromips)
10332 if (imm_expr.X_op == O_constant
10333 && imm_expr.X_add_number > -0x200
10334 && imm_expr.X_add_number <= 0x200)
10336 macro_build (NULL, s, "t,r,.", dreg, sreg, -imm_expr.X_add_number);
10345 if (imm_expr.X_op == O_constant
10346 && imm_expr.X_add_number > -0x8000
10347 && imm_expr.X_add_number <= 0x8000)
10349 imm_expr.X_add_number = -imm_expr.X_add_number;
10350 macro_build (&imm_expr, s, "t,r,j", dreg, sreg, BFD_RELOC_LO16);
10355 load_register (AT, &imm_expr, dbl);
10356 macro_build (NULL, s2, "d,v,t", dreg, sreg, AT);
10378 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
10379 macro_build (NULL, s, "s,t", sreg, AT);
10384 gas_assert (!mips_opts.micromips);
10385 gas_assert (mips_opts.isa == ISA_MIPS1);
10387 sreg = (ip->insn_opcode >> 11) & 0x1f; /* floating reg */
10388 dreg = (ip->insn_opcode >> 06) & 0x1f; /* floating reg */
10391 * Is the double cfc1 instruction a bug in the mips assembler;
10392 * or is there a reason for it?
10394 start_noreorder ();
10395 macro_build (NULL, "cfc1", "t,G", treg, RA);
10396 macro_build (NULL, "cfc1", "t,G", treg, RA);
10397 macro_build (NULL, "nop", "");
10398 expr1.X_add_number = 3;
10399 macro_build (&expr1, "ori", "t,r,i", AT, treg, BFD_RELOC_LO16);
10400 expr1.X_add_number = 2;
10401 macro_build (&expr1, "xori", "t,r,i", AT, AT, BFD_RELOC_LO16);
10402 macro_build (NULL, "ctc1", "t,G", AT, RA);
10403 macro_build (NULL, "nop", "");
10404 macro_build (NULL, mask == M_TRUNCWD ? "cvt.w.d" : "cvt.w.s", "D,S",
10406 macro_build (NULL, "ctc1", "t,G", treg, RA);
10407 macro_build (NULL, "nop", "");
10430 offbits = (mips_opts.micromips ? 12 : 16);
10438 offbits = (mips_opts.micromips ? 12 : 16);
10454 offbits = (mips_opts.micromips ? 12 : 16);
10463 offbits = (mips_opts.micromips ? 12 : 16);
10468 if (!ab && offset_expr.X_add_number >= 0x8000 - off)
10469 as_bad (_("Operand overflow"));
10472 expr1.X_add_number = 0;
10477 load_address (tempreg, ep, &used_at);
10479 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
10480 tempreg, tempreg, breg);
10485 else if (offbits == 12
10486 && (offset_expr.X_op != O_constant
10487 || !IS_SEXT_12BIT_NUM (offset_expr.X_add_number)
10488 || !IS_SEXT_12BIT_NUM (offset_expr.X_add_number + off)))
10492 macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", tempreg, breg,
10493 -1, offset_reloc[0], offset_reloc[1], offset_reloc[2]);
10498 else if (!ust && treg == breg)
10509 if (!target_big_endian)
10510 ep->X_add_number += off;
10512 macro_build (ep, s, "t,o(b)", tempreg, BFD_RELOC_LO16, breg);
10514 macro_build (NULL, s, "t,~(b)",
10515 tempreg, (unsigned long) ep->X_add_number, breg);
10517 if (!target_big_endian)
10518 ep->X_add_number -= off;
10520 ep->X_add_number += off;
10522 macro_build (ep, s2, "t,o(b)", tempreg, BFD_RELOC_LO16, breg);
10524 macro_build (NULL, s2, "t,~(b)",
10525 tempreg, (unsigned long) ep->X_add_number, breg);
10527 /* If necessary, move the result in tempreg to the final destination. */
10528 if (!ust && treg != tempreg)
10530 /* Protect second load's delay slot. */
10532 move_register (treg, tempreg);
10538 if (target_big_endian == ust)
10539 ep->X_add_number += off;
10540 tempreg = ust || ab ? treg : AT;
10541 macro_build (ep, s, "t,o(b)", tempreg, BFD_RELOC_LO16, breg);
10543 /* For halfword transfers we need a temporary register to shuffle
10544 bytes. Unfortunately for M_USH_A we have none available before
10545 the next store as AT holds the base address. We deal with this
10546 case by clobbering TREG and then restoring it as with ULH. */
10547 tempreg = ust == ab ? treg : AT;
10549 macro_build (NULL, "srl", SHFT_FMT, tempreg, treg, 8);
10551 if (target_big_endian == ust)
10552 ep->X_add_number -= off;
10554 ep->X_add_number += off;
10555 macro_build (ep, s2, "t,o(b)", tempreg, BFD_RELOC_LO16, breg);
10557 /* For M_USH_A re-retrieve the LSB. */
10560 if (target_big_endian)
10561 ep->X_add_number += off;
10563 ep->X_add_number -= off;
10564 macro_build (&expr1, "lbu", "t,o(b)", AT, BFD_RELOC_LO16, AT);
10566 /* For ULH and M_USH_A OR the LSB in. */
10569 tempreg = !ab ? AT : treg;
10570 macro_build (NULL, "sll", SHFT_FMT, tempreg, tempreg, 8);
10571 macro_build (NULL, "or", "d,v,t", treg, treg, AT);
10576 /* FIXME: Check if this is one of the itbl macros, since they
10577 are added dynamically. */
10578 as_bad (_("Macro %s not implemented yet"), ip->insn_mo->name);
10581 if (!mips_opts.at && used_at)
10582 as_bad (_("Macro used $at after \".set noat\""));
10585 /* Implement macros in mips16 mode. */
10588 mips16_macro (struct mips_cl_insn *ip)
10591 int xreg, yreg, zreg, tmp;
10594 const char *s, *s2, *s3;
10596 mask = ip->insn_mo->mask;
10598 xreg = MIPS16_EXTRACT_OPERAND (RX, *ip);
10599 yreg = MIPS16_EXTRACT_OPERAND (RY, *ip);
10600 zreg = MIPS16_EXTRACT_OPERAND (RZ, *ip);
10602 expr1.X_op = O_constant;
10603 expr1.X_op_symbol = NULL;
10604 expr1.X_add_symbol = NULL;
10605 expr1.X_add_number = 1;
10624 start_noreorder ();
10625 macro_build (NULL, dbl ? "ddiv" : "div", "0,x,y", xreg, yreg);
10626 expr1.X_add_number = 2;
10627 macro_build (&expr1, "bnez", "x,p", yreg);
10628 macro_build (NULL, "break", "6", 7);
10630 /* FIXME: The normal code checks for of -1 / -0x80000000 here,
10631 since that causes an overflow. We should do that as well,
10632 but I don't see how to do the comparisons without a temporary
10635 macro_build (NULL, s, "x", zreg);
10654 start_noreorder ();
10655 macro_build (NULL, s, "0,x,y", xreg, yreg);
10656 expr1.X_add_number = 2;
10657 macro_build (&expr1, "bnez", "x,p", yreg);
10658 macro_build (NULL, "break", "6", 7);
10660 macro_build (NULL, s2, "x", zreg);
10666 macro_build (NULL, dbl ? "dmultu" : "multu", "x,y", xreg, yreg);
10667 macro_build (NULL, "mflo", "x", zreg);
10675 if (imm_expr.X_op != O_constant)
10676 as_bad (_("Unsupported large constant"));
10677 imm_expr.X_add_number = -imm_expr.X_add_number;
10678 macro_build (&imm_expr, dbl ? "daddiu" : "addiu", "y,x,4", yreg, xreg);
10682 if (imm_expr.X_op != O_constant)
10683 as_bad (_("Unsupported large constant"));
10684 imm_expr.X_add_number = -imm_expr.X_add_number;
10685 macro_build (&imm_expr, "addiu", "x,k", xreg);
10689 if (imm_expr.X_op != O_constant)
10690 as_bad (_("Unsupported large constant"));
10691 imm_expr.X_add_number = -imm_expr.X_add_number;
10692 macro_build (&imm_expr, "daddiu", "y,j", yreg);
10714 goto do_reverse_branch;
10718 goto do_reverse_branch;
10730 goto do_reverse_branch;
10741 macro_build (NULL, s, "x,y", xreg, yreg);
10742 macro_build (&offset_expr, s2, "p");
10769 goto do_addone_branch_i;
10774 goto do_addone_branch_i;
10789 goto do_addone_branch_i;
10795 do_addone_branch_i:
10796 if (imm_expr.X_op != O_constant)
10797 as_bad (_("Unsupported large constant"));
10798 ++imm_expr.X_add_number;
10801 macro_build (&imm_expr, s, s3, xreg);
10802 macro_build (&offset_expr, s2, "p");
10806 expr1.X_add_number = 0;
10807 macro_build (&expr1, "slti", "x,8", yreg);
10809 move_register (xreg, yreg);
10810 expr1.X_add_number = 2;
10811 macro_build (&expr1, "bteqz", "p");
10812 macro_build (NULL, "neg", "x,w", xreg, xreg);
10816 /* For consistency checking, verify that all bits are specified either
10817 by the match/mask part of the instruction definition, or by the
10820 validate_mips_insn (const struct mips_opcode *opc)
10822 const char *p = opc->args;
10824 unsigned long used_bits = opc->mask;
10826 if ((used_bits & opc->match) != opc->match)
10828 as_bad (_("internal: bad mips opcode (mask error): %s %s"),
10829 opc->name, opc->args);
10832 #define USE_BITS(mask,shift) (used_bits |= ((mask) << (shift)))
10842 case '1': USE_BITS (OP_MASK_UDI1, OP_SH_UDI1); break;
10843 case '2': USE_BITS (OP_MASK_UDI2, OP_SH_UDI2); break;
10844 case '3': USE_BITS (OP_MASK_UDI3, OP_SH_UDI3); break;
10845 case '4': USE_BITS (OP_MASK_UDI4, OP_SH_UDI4); break;
10846 case 'A': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
10847 case 'B': USE_BITS (OP_MASK_INSMSB, OP_SH_INSMSB); break;
10848 case 'C': USE_BITS (OP_MASK_EXTMSBD, OP_SH_EXTMSBD); break;
10849 case 'D': USE_BITS (OP_MASK_RD, OP_SH_RD);
10850 USE_BITS (OP_MASK_SEL, OP_SH_SEL); break;
10851 case 'E': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
10852 case 'F': USE_BITS (OP_MASK_INSMSB, OP_SH_INSMSB); break;
10853 case 'G': USE_BITS (OP_MASK_EXTMSBD, OP_SH_EXTMSBD); break;
10854 case 'H': USE_BITS (OP_MASK_EXTMSBD, OP_SH_EXTMSBD); break;
10856 case 'J': USE_BITS (OP_MASK_CODE10, OP_SH_CODE10); break;
10857 case 't': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
10858 case 'T': USE_BITS (OP_MASK_RT, OP_SH_RT);
10859 USE_BITS (OP_MASK_SEL, OP_SH_SEL); break;
10860 case 'x': USE_BITS (OP_MASK_BBITIND, OP_SH_BBITIND); break;
10861 case 'X': USE_BITS (OP_MASK_BBITIND, OP_SH_BBITIND); break;
10862 case 'p': USE_BITS (OP_MASK_CINSPOS, OP_SH_CINSPOS); break;
10863 case 'P': USE_BITS (OP_MASK_CINSPOS, OP_SH_CINSPOS); break;
10864 case 'Q': USE_BITS (OP_MASK_SEQI, OP_SH_SEQI); break;
10865 case 's': USE_BITS (OP_MASK_CINSLM1, OP_SH_CINSLM1); break;
10866 case 'S': USE_BITS (OP_MASK_CINSLM1, OP_SH_CINSLM1); break;
10867 case 'z': USE_BITS (OP_MASK_RZ, OP_SH_RZ); break;
10868 case 'Z': USE_BITS (OP_MASK_FZ, OP_SH_FZ); break;
10869 case 'a': USE_BITS (OP_MASK_OFFSET_A, OP_SH_OFFSET_A); break;
10870 case 'b': USE_BITS (OP_MASK_OFFSET_B, OP_SH_OFFSET_B); break;
10871 case 'c': USE_BITS (OP_MASK_OFFSET_C, OP_SH_OFFSET_C); break;
10872 case 'j': USE_BITS (OP_MASK_EVAOFFSET, OP_SH_EVAOFFSET); break;
10875 as_bad (_("internal: bad mips opcode (unknown extension operand type `+%c'): %s %s"),
10876 c, opc->name, opc->args);
10880 case '<': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
10881 case '>': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
10883 case 'B': USE_BITS (OP_MASK_CODE20, OP_SH_CODE20); break;
10884 case 'C': USE_BITS (OP_MASK_COPZ, OP_SH_COPZ); break;
10885 case 'D': USE_BITS (OP_MASK_FD, OP_SH_FD); break;
10886 case 'E': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
10888 case 'G': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
10889 case 'H': USE_BITS (OP_MASK_SEL, OP_SH_SEL); break;
10891 case 'J': USE_BITS (OP_MASK_CODE19, OP_SH_CODE19); break;
10892 case 'K': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
10894 case 'M': USE_BITS (OP_MASK_CCC, OP_SH_CCC); break;
10895 case 'N': USE_BITS (OP_MASK_BCC, OP_SH_BCC); break;
10896 case 'O': USE_BITS (OP_MASK_ALN, OP_SH_ALN); break;
10897 case 'Q': USE_BITS (OP_MASK_VSEL, OP_SH_VSEL);
10898 USE_BITS (OP_MASK_FT, OP_SH_FT); break;
10899 case 'R': USE_BITS (OP_MASK_FR, OP_SH_FR); break;
10900 case 'S': USE_BITS (OP_MASK_FS, OP_SH_FS); break;
10901 case 'T': USE_BITS (OP_MASK_FT, OP_SH_FT); break;
10902 case 'V': USE_BITS (OP_MASK_FS, OP_SH_FS); break;
10903 case 'W': USE_BITS (OP_MASK_FT, OP_SH_FT); break;
10904 case 'X': USE_BITS (OP_MASK_FD, OP_SH_FD); break;
10905 case 'Y': USE_BITS (OP_MASK_FS, OP_SH_FS); break;
10906 case 'Z': USE_BITS (OP_MASK_FT, OP_SH_FT); break;
10907 case 'a': USE_BITS (OP_MASK_TARGET, OP_SH_TARGET); break;
10908 case 'b': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
10909 case 'c': USE_BITS (OP_MASK_CODE, OP_SH_CODE); break;
10910 case 'd': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
10912 case 'h': USE_BITS (OP_MASK_PREFX, OP_SH_PREFX); break;
10913 case 'i': USE_BITS (OP_MASK_IMMEDIATE, OP_SH_IMMEDIATE); break;
10914 case 'j': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
10915 case 'k': USE_BITS (OP_MASK_CACHE, OP_SH_CACHE); break;
10917 case 'o': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
10918 case 'p': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
10919 case 'q': USE_BITS (OP_MASK_CODE2, OP_SH_CODE2); break;
10920 case 'r': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
10921 case 's': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
10922 case 't': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
10923 case 'u': USE_BITS (OP_MASK_IMMEDIATE, OP_SH_IMMEDIATE); break;
10924 case 'v': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
10925 case 'w': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
10928 case 'P': USE_BITS (OP_MASK_PERFREG, OP_SH_PERFREG); break;
10929 case 'U': USE_BITS (OP_MASK_RD, OP_SH_RD);
10930 USE_BITS (OP_MASK_RT, OP_SH_RT); break;
10931 case 'e': USE_BITS (OP_MASK_VECBYTE, OP_SH_VECBYTE); break;
10932 case '%': USE_BITS (OP_MASK_VECALIGN, OP_SH_VECALIGN); break;
10935 case '1': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
10936 case '2': USE_BITS (OP_MASK_BP, OP_SH_BP); break;
10937 case '3': USE_BITS (OP_MASK_SA3, OP_SH_SA3); break;
10938 case '4': USE_BITS (OP_MASK_SA4, OP_SH_SA4); break;
10939 case '5': USE_BITS (OP_MASK_IMM8, OP_SH_IMM8); break;
10940 case '6': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
10941 case '7': USE_BITS (OP_MASK_DSPACC, OP_SH_DSPACC); break;
10942 case '8': USE_BITS (OP_MASK_WRDSP, OP_SH_WRDSP); break;
10943 case '9': USE_BITS (OP_MASK_DSPACC_S, OP_SH_DSPACC_S);break;
10944 case '0': USE_BITS (OP_MASK_DSPSFT, OP_SH_DSPSFT); break;
10945 case '\'': USE_BITS (OP_MASK_RDDSP, OP_SH_RDDSP); break;
10946 case ':': USE_BITS (OP_MASK_DSPSFT_7, OP_SH_DSPSFT_7);break;
10947 case '@': USE_BITS (OP_MASK_IMM10, OP_SH_IMM10); break;
10948 case '!': USE_BITS (OP_MASK_MT_U, OP_SH_MT_U); break;
10949 case '$': USE_BITS (OP_MASK_MT_H, OP_SH_MT_H); break;
10950 case '*': USE_BITS (OP_MASK_MTACC_T, OP_SH_MTACC_T); break;
10951 case '&': USE_BITS (OP_MASK_MTACC_D, OP_SH_MTACC_D); break;
10952 case '\\': USE_BITS (OP_MASK_3BITPOS, OP_SH_3BITPOS); break;
10953 case '~': USE_BITS (OP_MASK_OFFSET12, OP_SH_OFFSET12); break;
10954 case 'g': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
10956 as_bad (_("internal: bad mips opcode (unknown operand type `%c'): %s %s"),
10957 c, opc->name, opc->args);
10961 if (used_bits != 0xffffffff)
10963 as_bad (_("internal: bad mips opcode (bits 0x%lx undefined): %s %s"),
10964 ~used_bits & 0xffffffff, opc->name, opc->args);
10970 /* For consistency checking, verify that the length implied matches the
10971 major opcode and that all bits are specified either by the match/mask
10972 part of the instruction definition, or by the operand list. */
10975 validate_micromips_insn (const struct mips_opcode *opc)
10977 unsigned long match = opc->match;
10978 unsigned long mask = opc->mask;
10979 const char *p = opc->args;
10980 unsigned long insn_bits;
10981 unsigned long used_bits;
10982 unsigned long major;
10983 unsigned int length;
10987 if ((mask & match) != match)
10989 as_bad (_("Internal error: bad microMIPS opcode (mask error): %s %s"),
10990 opc->name, opc->args);
10993 length = micromips_insn_length (opc);
10994 if (length != 2 && length != 4)
10996 as_bad (_("Internal error: bad microMIPS opcode (incorrect length: %u): "
10997 "%s %s"), length, opc->name, opc->args);
11000 major = match >> (10 + 8 * (length - 2));
11001 if ((length == 2 && (major & 7) != 1 && (major & 6) != 2)
11002 || (length == 4 && (major & 7) != 0 && (major & 4) != 4))
11004 as_bad (_("Internal error: bad microMIPS opcode "
11005 "(opcode/length mismatch): %s %s"), opc->name, opc->args);
11009 /* Shift piecewise to avoid an overflow where unsigned long is 32-bit. */
11010 insn_bits = 1 << 4 * length;
11011 insn_bits <<= 4 * length;
11014 #define USE_BITS(field) \
11015 (used_bits |= MICROMIPSOP_MASK_##field << MICROMIPSOP_SH_##field)
11026 case 'A': USE_BITS (EXTLSB); break;
11027 case 'B': USE_BITS (INSMSB); break;
11028 case 'C': USE_BITS (EXTMSBD); break;
11029 case 'D': USE_BITS (RS); USE_BITS (SEL); break;
11030 case 'E': USE_BITS (EXTLSB); break;
11031 case 'F': USE_BITS (INSMSB); break;
11032 case 'G': USE_BITS (EXTMSBD); break;
11033 case 'H': USE_BITS (EXTMSBD); break;
11034 case 'j': USE_BITS (EVAOFFSET); break;
11036 as_bad (_("Internal error: bad mips opcode "
11037 "(unknown extension operand type `%c%c'): %s %s"),
11038 e, c, opc->name, opc->args);
11046 case 'A': USE_BITS (IMMA); break;
11047 case 'B': USE_BITS (IMMB); break;
11048 case 'C': USE_BITS (IMMC); break;
11049 case 'D': USE_BITS (IMMD); break;
11050 case 'E': USE_BITS (IMME); break;
11051 case 'F': USE_BITS (IMMF); break;
11052 case 'G': USE_BITS (IMMG); break;
11053 case 'H': USE_BITS (IMMH); break;
11054 case 'I': USE_BITS (IMMI); break;
11055 case 'J': USE_BITS (IMMJ); break;
11056 case 'L': USE_BITS (IMML); break;
11057 case 'M': USE_BITS (IMMM); break;
11058 case 'N': USE_BITS (IMMN); break;
11059 case 'O': USE_BITS (IMMO); break;
11060 case 'P': USE_BITS (IMMP); break;
11061 case 'Q': USE_BITS (IMMQ); break;
11062 case 'U': USE_BITS (IMMU); break;
11063 case 'W': USE_BITS (IMMW); break;
11064 case 'X': USE_BITS (IMMX); break;
11065 case 'Y': USE_BITS (IMMY); break;
11068 case 'b': USE_BITS (MB); break;
11069 case 'c': USE_BITS (MC); break;
11070 case 'd': USE_BITS (MD); break;
11071 case 'e': USE_BITS (ME); break;
11072 case 'f': USE_BITS (MF); break;
11073 case 'g': USE_BITS (MG); break;
11074 case 'h': USE_BITS (MH); break;
11075 case 'i': USE_BITS (MI); break;
11076 case 'j': USE_BITS (MJ); break;
11077 case 'l': USE_BITS (ML); break;
11078 case 'm': USE_BITS (MM); break;
11079 case 'n': USE_BITS (MN); break;
11080 case 'p': USE_BITS (MP); break;
11081 case 'q': USE_BITS (MQ); break;
11089 as_bad (_("Internal error: bad mips opcode "
11090 "(unknown extension operand type `%c%c'): %s %s"),
11091 e, c, opc->name, opc->args);
11095 case '.': USE_BITS (OFFSET10); break;
11096 case '1': USE_BITS (STYPE); break;
11097 case '2': USE_BITS (BP); break;
11098 case '3': USE_BITS (SA3); break;
11099 case '4': USE_BITS (SA4); break;
11100 case '5': USE_BITS (IMM8); break;
11101 case '6': USE_BITS (RS); break;
11102 case '7': USE_BITS (DSPACC); break;
11103 case '8': USE_BITS (WRDSP); break;
11104 case '0': USE_BITS (DSPSFT); break;
11105 case '<': USE_BITS (SHAMT); break;
11106 case '>': USE_BITS (SHAMT); break;
11107 case '@': USE_BITS (IMM10); break;
11108 case 'B': USE_BITS (CODE10); break;
11109 case 'C': USE_BITS (COPZ); break;
11110 case 'D': USE_BITS (FD); break;
11111 case 'E': USE_BITS (RT); break;
11112 case 'G': USE_BITS (RS); break;
11113 case 'H': USE_BITS (SEL); break;
11114 case 'K': USE_BITS (RS); break;
11115 case 'M': USE_BITS (CCC); break;
11116 case 'N': USE_BITS (BCC); break;
11117 case 'R': USE_BITS (FR); break;
11118 case 'S': USE_BITS (FS); break;
11119 case 'T': USE_BITS (FT); break;
11120 case 'V': USE_BITS (FS); break;
11121 case '\\': USE_BITS (3BITPOS); break;
11122 case '^': USE_BITS (RD); break;
11123 case 'a': USE_BITS (TARGET); break;
11124 case 'b': USE_BITS (RS); break;
11125 case 'c': USE_BITS (CODE); break;
11126 case 'd': USE_BITS (RD); break;
11127 case 'h': USE_BITS (PREFX); break;
11128 case 'i': USE_BITS (IMMEDIATE); break;
11129 case 'j': USE_BITS (DELTA); break;
11130 case 'k': USE_BITS (CACHE); break;
11131 case 'n': USE_BITS (RT); break;
11132 case 'o': USE_BITS (DELTA); break;
11133 case 'p': USE_BITS (DELTA); break;
11134 case 'q': USE_BITS (CODE2); break;
11135 case 'r': USE_BITS (RS); break;
11136 case 's': USE_BITS (RS); break;
11137 case 't': USE_BITS (RT); break;
11138 case 'u': USE_BITS (IMMEDIATE); break;
11139 case 'v': USE_BITS (RS); break;
11140 case 'w': USE_BITS (RT); break;
11141 case 'y': USE_BITS (RS3); break;
11143 case '|': USE_BITS (TRAP); break;
11144 case '~': USE_BITS (OFFSET12); break;
11146 as_bad (_("Internal error: bad microMIPS opcode "
11147 "(unknown operand type `%c'): %s %s"),
11148 c, opc->name, opc->args);
11152 if (used_bits != insn_bits)
11154 if (~used_bits & insn_bits)
11155 as_bad (_("Internal error: bad microMIPS opcode "
11156 "(bits 0x%lx undefined): %s %s"),
11157 ~used_bits & insn_bits, opc->name, opc->args);
11158 if (used_bits & ~insn_bits)
11159 as_bad (_("Internal error: bad microMIPS opcode "
11160 "(bits 0x%lx defined): %s %s"),
11161 used_bits & ~insn_bits, opc->name, opc->args);
11167 /* UDI immediates. */
11168 struct mips_immed {
11170 unsigned int shift;
11171 unsigned long mask;
11175 static const struct mips_immed mips_immed[] = {
11176 { '1', OP_SH_UDI1, OP_MASK_UDI1, 0},
11177 { '2', OP_SH_UDI2, OP_MASK_UDI2, 0},
11178 { '3', OP_SH_UDI3, OP_MASK_UDI3, 0},
11179 { '4', OP_SH_UDI4, OP_MASK_UDI4, 0},
11183 /* Check whether an odd floating-point register is allowed. */
11185 mips_oddfpreg_ok (const struct mips_opcode *insn, int argnum)
11187 const char *s = insn->name;
11189 if (insn->pinfo == INSN_MACRO)
11190 /* Let a macro pass, we'll catch it later when it is expanded. */
11193 if (ISA_HAS_ODD_SINGLE_FPR (mips_opts.isa) || (mips_opts.arch == CPU_R5900))
11195 /* Allow odd registers for single-precision ops. */
11196 switch (insn->pinfo & (FP_S | FP_D))
11200 return 1; /* both single precision - ok */
11202 return 0; /* both double precision - fail */
11207 /* Cvt.w.x and cvt.x.w allow an odd register for a 'w' or 's' operand. */
11208 s = strchr (insn->name, '.');
11210 s = s != NULL ? strchr (s + 1, '.') : NULL;
11211 return (s != NULL && (s[1] == 'w' || s[1] == 's'));
11214 /* Single-precision coprocessor loads and moves are OK too. */
11215 if ((insn->pinfo & FP_S)
11216 && (insn->pinfo & (INSN_COPROC_MEMORY_DELAY | INSN_STORE_MEMORY
11217 | INSN_LOAD_COPROC_DELAY | INSN_COPROC_MOVE_DELAY)))
11223 /* Check if EXPR is a constant between MIN (inclusive) and MAX (exclusive)
11224 taking bits from BIT up. */
11226 expr_const_in_range (expressionS *ep, offsetT min, offsetT max, int bit)
11228 return (ep->X_op == O_constant
11229 && (ep->X_add_number & ((1 << bit) - 1)) == 0
11230 && ep->X_add_number >= min << bit
11231 && ep->X_add_number < max << bit);
11234 /* This routine assembles an instruction into its binary format. As a
11235 side effect, it sets one of the global variables imm_reloc or
11236 offset_reloc to the type of relocation to do if one of the operands
11237 is an address expression. */
11240 mips_ip (char *str, struct mips_cl_insn *ip)
11242 bfd_boolean wrong_delay_slot_insns = FALSE;
11243 bfd_boolean need_delay_slot_ok = TRUE;
11244 struct mips_opcode *firstinsn = NULL;
11245 const struct mips_opcode *past;
11246 struct hash_control *hash;
11250 struct mips_opcode *insn;
11252 unsigned int regno;
11253 unsigned int lastregno;
11254 unsigned int destregno = 0;
11255 unsigned int lastpos = 0;
11256 unsigned int limlo, limhi;
11259 offsetT min_range, max_range;
11263 unsigned int rtype;
11269 if (mips_opts.micromips)
11271 hash = micromips_op_hash;
11272 past = µmips_opcodes[bfd_micromips_num_opcodes];
11277 past = &mips_opcodes[NUMOPCODES];
11279 forced_insn_length = 0;
11282 /* We first try to match an instruction up to a space or to the end. */
11283 for (end = 0; str[end] != '\0' && !ISSPACE (str[end]); end++)
11286 /* Make a copy of the instruction so that we can fiddle with it. */
11287 name = alloca (end + 1);
11288 memcpy (name, str, end);
11293 insn = (struct mips_opcode *) hash_find (hash, name);
11295 if (insn != NULL || !mips_opts.micromips)
11297 if (forced_insn_length)
11300 /* See if there's an instruction size override suffix,
11301 either `16' or `32', at the end of the mnemonic proper,
11302 that defines the operation, i.e. before the first `.'
11303 character if any. Strip it and retry. */
11304 dot = strchr (name, '.');
11305 opend = dot != NULL ? dot - name : end;
11308 if (name[opend - 2] == '1' && name[opend - 1] == '6')
11309 forced_insn_length = 2;
11310 else if (name[opend - 2] == '3' && name[opend - 1] == '2')
11311 forced_insn_length = 4;
11314 memcpy (name + opend - 2, name + opend, end - opend + 1);
11318 insn_error = _("Unrecognized opcode");
11322 /* For microMIPS instructions placed in a fixed-length branch delay slot
11323 we make up to two passes over the relevant fragment of the opcode
11324 table. First we try instructions that meet the delay slot's length
11325 requirement. If none matched, then we retry with the remaining ones
11326 and if one matches, then we use it and then issue an appropriate
11327 warning later on. */
11328 argsStart = s = str + end;
11331 bfd_boolean delay_slot_ok;
11332 bfd_boolean size_ok;
11335 gas_assert (strcmp (insn->name, name) == 0);
11337 ok = is_opcode_valid (insn);
11338 size_ok = is_size_valid (insn);
11339 delay_slot_ok = is_delay_slot_valid (insn);
11340 if (!delay_slot_ok && !wrong_delay_slot_insns)
11343 wrong_delay_slot_insns = TRUE;
11345 if (!ok || !size_ok || delay_slot_ok != need_delay_slot_ok)
11347 static char buf[256];
11349 if (insn + 1 < past && strcmp (insn->name, insn[1].name) == 0)
11354 if (wrong_delay_slot_insns && need_delay_slot_ok)
11356 gas_assert (firstinsn);
11357 need_delay_slot_ok = FALSE;
11367 sprintf (buf, _("Opcode not supported on this processor: %s (%s)"),
11368 mips_cpu_info_from_arch (mips_opts.arch)->name,
11369 mips_cpu_info_from_isa (mips_opts.isa)->name);
11371 sprintf (buf, _("Unrecognized %u-bit version of microMIPS opcode"),
11372 8 * forced_insn_length);
11378 create_insn (ip, insn);
11381 lastregno = 0xffffffff;
11382 for (args = insn->args;; ++args)
11386 s += strspn (s, " \t");
11390 case '\0': /* end of args */
11396 /* DSP 2-bit unsigned immediate in bit 11 (for standard MIPS
11397 code) or 14 (for microMIPS code). */
11398 my_getExpression (&imm_expr, s);
11399 check_absolute_expr (ip, &imm_expr);
11400 if ((unsigned long) imm_expr.X_add_number != 1
11401 && (unsigned long) imm_expr.X_add_number != 3)
11403 as_bad (_("BALIGN immediate not 1 or 3 (%lu)"),
11404 (unsigned long) imm_expr.X_add_number);
11406 INSERT_OPERAND (mips_opts.micromips,
11407 BP, *ip, imm_expr.X_add_number);
11408 imm_expr.X_op = O_absent;
11413 /* DSP 3-bit unsigned immediate in bit 13 (for standard MIPS
11414 code) or 21 (for microMIPS code). */
11416 unsigned long mask = (mips_opts.micromips
11417 ? MICROMIPSOP_MASK_SA3 : OP_MASK_SA3);
11419 my_getExpression (&imm_expr, s);
11420 check_absolute_expr (ip, &imm_expr);
11421 if ((unsigned long) imm_expr.X_add_number > mask)
11422 as_bad (_("DSP immediate not in range 0..%lu (%lu)"),
11423 mask, (unsigned long) imm_expr.X_add_number);
11424 INSERT_OPERAND (mips_opts.micromips,
11425 SA3, *ip, imm_expr.X_add_number);
11426 imm_expr.X_op = O_absent;
11432 /* DSP 4-bit unsigned immediate in bit 12 (for standard MIPS
11433 code) or 21 (for microMIPS code). */
11435 unsigned long mask = (mips_opts.micromips
11436 ? MICROMIPSOP_MASK_SA4 : OP_MASK_SA4);
11438 my_getExpression (&imm_expr, s);
11439 check_absolute_expr (ip, &imm_expr);
11440 if ((unsigned long) imm_expr.X_add_number > mask)
11441 as_bad (_("DSP immediate not in range 0..%lu (%lu)"),
11442 mask, (unsigned long) imm_expr.X_add_number);
11443 INSERT_OPERAND (mips_opts.micromips,
11444 SA4, *ip, imm_expr.X_add_number);
11445 imm_expr.X_op = O_absent;
11451 /* DSP 8-bit unsigned immediate in bit 13 (for standard MIPS
11452 code) or 16 (for microMIPS code). */
11454 unsigned long mask = (mips_opts.micromips
11455 ? MICROMIPSOP_MASK_IMM8 : OP_MASK_IMM8);
11457 my_getExpression (&imm_expr, s);
11458 check_absolute_expr (ip, &imm_expr);
11459 if ((unsigned long) imm_expr.X_add_number > mask)
11460 as_bad (_("DSP immediate not in range 0..%lu (%lu)"),
11461 mask, (unsigned long) imm_expr.X_add_number);
11462 INSERT_OPERAND (mips_opts.micromips,
11463 IMM8, *ip, imm_expr.X_add_number);
11464 imm_expr.X_op = O_absent;
11470 /* DSP 5-bit unsigned immediate in bit 16 (for standard MIPS
11471 code) or 21 (for microMIPS code). */
11473 unsigned long mask = (mips_opts.micromips
11474 ? MICROMIPSOP_MASK_RS : OP_MASK_RS);
11476 my_getExpression (&imm_expr, s);
11477 check_absolute_expr (ip, &imm_expr);
11478 if ((unsigned long) imm_expr.X_add_number > mask)
11479 as_bad (_("DSP immediate not in range 0..%lu (%lu)"),
11480 mask, (unsigned long) imm_expr.X_add_number);
11481 INSERT_OPERAND (mips_opts.micromips,
11482 RS, *ip, imm_expr.X_add_number);
11483 imm_expr.X_op = O_absent;
11488 case '7': /* Four DSP accumulators in bits 11,12. */
11489 if (s[0] == '$' && s[1] == 'a' && s[2] == 'c'
11490 && s[3] >= '0' && s[3] <= '3')
11492 regno = s[3] - '0';
11494 INSERT_OPERAND (mips_opts.micromips, DSPACC, *ip, regno);
11498 as_bad (_("Invalid dsp acc register"));
11502 /* DSP 6-bit unsigned immediate in bit 11 (for standard MIPS
11503 code) or 14 (for microMIPS code). */
11505 unsigned long mask = (mips_opts.micromips
11506 ? MICROMIPSOP_MASK_WRDSP
11509 my_getExpression (&imm_expr, s);
11510 check_absolute_expr (ip, &imm_expr);
11511 if ((unsigned long) imm_expr.X_add_number > mask)
11512 as_bad (_("DSP immediate not in range 0..%lu (%lu)"),
11513 mask, (unsigned long) imm_expr.X_add_number);
11514 INSERT_OPERAND (mips_opts.micromips,
11515 WRDSP, *ip, imm_expr.X_add_number);
11516 imm_expr.X_op = O_absent;
11521 case '9': /* Four DSP accumulators in bits 21,22. */
11522 gas_assert (!mips_opts.micromips);
11523 if (s[0] == '$' && s[1] == 'a' && s[2] == 'c'
11524 && s[3] >= '0' && s[3] <= '3')
11526 regno = s[3] - '0';
11528 INSERT_OPERAND (0, DSPACC_S, *ip, regno);
11532 as_bad (_("Invalid dsp acc register"));
11536 /* DSP 6-bit signed immediate in bit 16 (for standard MIPS
11537 code) or 20 (for microMIPS code). */
11539 long mask = (mips_opts.micromips
11540 ? MICROMIPSOP_MASK_DSPSFT : OP_MASK_DSPSFT);
11542 my_getExpression (&imm_expr, s);
11543 check_absolute_expr (ip, &imm_expr);
11544 min_range = -((mask + 1) >> 1);
11545 max_range = ((mask + 1) >> 1) - 1;
11546 if (imm_expr.X_add_number < min_range
11547 || imm_expr.X_add_number > max_range)
11548 as_bad (_("DSP immediate not in range %ld..%ld (%ld)"),
11549 (long) min_range, (long) max_range,
11550 (long) imm_expr.X_add_number);
11551 INSERT_OPERAND (mips_opts.micromips,
11552 DSPSFT, *ip, imm_expr.X_add_number);
11553 imm_expr.X_op = O_absent;
11558 case '\'': /* DSP 6-bit unsigned immediate in bit 16. */
11559 gas_assert (!mips_opts.micromips);
11560 my_getExpression (&imm_expr, s);
11561 check_absolute_expr (ip, &imm_expr);
11562 if (imm_expr.X_add_number & ~OP_MASK_RDDSP)
11564 as_bad (_("DSP immediate not in range 0..%d (%lu)"),
11566 (unsigned long) imm_expr.X_add_number);
11568 INSERT_OPERAND (0, RDDSP, *ip, imm_expr.X_add_number);
11569 imm_expr.X_op = O_absent;
11573 case ':': /* DSP 7-bit signed immediate in bit 19. */
11574 gas_assert (!mips_opts.micromips);
11575 my_getExpression (&imm_expr, s);
11576 check_absolute_expr (ip, &imm_expr);
11577 min_range = -((OP_MASK_DSPSFT_7 + 1) >> 1);
11578 max_range = ((OP_MASK_DSPSFT_7 + 1) >> 1) - 1;
11579 if (imm_expr.X_add_number < min_range ||
11580 imm_expr.X_add_number > max_range)
11582 as_bad (_("DSP immediate not in range %ld..%ld (%ld)"),
11583 (long) min_range, (long) max_range,
11584 (long) imm_expr.X_add_number);
11586 INSERT_OPERAND (0, DSPSFT_7, *ip, imm_expr.X_add_number);
11587 imm_expr.X_op = O_absent;
11591 case '@': /* DSP 10-bit signed immediate in bit 16. */
11593 long mask = (mips_opts.micromips
11594 ? MICROMIPSOP_MASK_IMM10 : OP_MASK_IMM10);
11596 my_getExpression (&imm_expr, s);
11597 check_absolute_expr (ip, &imm_expr);
11598 min_range = -((mask + 1) >> 1);
11599 max_range = ((mask + 1) >> 1) - 1;
11600 if (imm_expr.X_add_number < min_range
11601 || imm_expr.X_add_number > max_range)
11602 as_bad (_("DSP immediate not in range %ld..%ld (%ld)"),
11603 (long) min_range, (long) max_range,
11604 (long) imm_expr.X_add_number);
11605 INSERT_OPERAND (mips_opts.micromips,
11606 IMM10, *ip, imm_expr.X_add_number);
11607 imm_expr.X_op = O_absent;
11612 case '^': /* DSP 5-bit unsigned immediate in bit 11. */
11613 gas_assert (mips_opts.micromips);
11614 my_getExpression (&imm_expr, s);
11615 check_absolute_expr (ip, &imm_expr);
11616 if (imm_expr.X_add_number & ~MICROMIPSOP_MASK_RD)
11617 as_bad (_("DSP immediate not in range 0..%d (%lu)"),
11618 MICROMIPSOP_MASK_RD,
11619 (unsigned long) imm_expr.X_add_number);
11620 INSERT_OPERAND (1, RD, *ip, imm_expr.X_add_number);
11621 imm_expr.X_op = O_absent;
11625 case '!': /* MT usermode flag bit. */
11626 gas_assert (!mips_opts.micromips);
11627 my_getExpression (&imm_expr, s);
11628 check_absolute_expr (ip, &imm_expr);
11629 if (imm_expr.X_add_number & ~OP_MASK_MT_U)
11630 as_bad (_("MT usermode bit not 0 or 1 (%lu)"),
11631 (unsigned long) imm_expr.X_add_number);
11632 INSERT_OPERAND (0, MT_U, *ip, imm_expr.X_add_number);
11633 imm_expr.X_op = O_absent;
11637 case '$': /* MT load high flag bit. */
11638 gas_assert (!mips_opts.micromips);
11639 my_getExpression (&imm_expr, s);
11640 check_absolute_expr (ip, &imm_expr);
11641 if (imm_expr.X_add_number & ~OP_MASK_MT_H)
11642 as_bad (_("MT load high bit not 0 or 1 (%lu)"),
11643 (unsigned long) imm_expr.X_add_number);
11644 INSERT_OPERAND (0, MT_H, *ip, imm_expr.X_add_number);
11645 imm_expr.X_op = O_absent;
11649 case '*': /* Four DSP accumulators in bits 18,19. */
11650 gas_assert (!mips_opts.micromips);
11651 if (s[0] == '$' && s[1] == 'a' && s[2] == 'c' &&
11652 s[3] >= '0' && s[3] <= '3')
11654 regno = s[3] - '0';
11656 INSERT_OPERAND (0, MTACC_T, *ip, regno);
11660 as_bad (_("Invalid dsp/smartmips acc register"));
11663 case '&': /* Four DSP accumulators in bits 13,14. */
11664 gas_assert (!mips_opts.micromips);
11665 if (s[0] == '$' && s[1] == 'a' && s[2] == 'c' &&
11666 s[3] >= '0' && s[3] <= '3')
11668 regno = s[3] - '0';
11670 INSERT_OPERAND (0, MTACC_D, *ip, regno);
11674 as_bad (_("Invalid dsp/smartmips acc register"));
11677 case '\\': /* 3-bit bit position. */
11679 unsigned long mask = (mips_opts.micromips
11680 ? MICROMIPSOP_MASK_3BITPOS
11681 : OP_MASK_3BITPOS);
11683 my_getExpression (&imm_expr, s);
11684 check_absolute_expr (ip, &imm_expr);
11685 if ((unsigned long) imm_expr.X_add_number > mask)
11686 as_warn (_("Bit position for %s not in range 0..%lu (%lu)"),
11688 mask, (unsigned long) imm_expr.X_add_number);
11689 INSERT_OPERAND (mips_opts.micromips,
11690 3BITPOS, *ip, imm_expr.X_add_number);
11691 imm_expr.X_op = O_absent;
11705 INSERT_OPERAND (mips_opts.micromips, RS, *ip, lastregno);
11709 INSERT_OPERAND (mips_opts.micromips, RT, *ip, lastregno);
11713 gas_assert (!mips_opts.micromips);
11714 INSERT_OPERAND (0, FT, *ip, lastregno);
11718 INSERT_OPERAND (mips_opts.micromips, FS, *ip, lastregno);
11724 /* Handle optional base register.
11725 Either the base register is omitted or
11726 we must have a left paren. */
11727 /* This is dependent on the next operand specifier
11728 is a base register specification. */
11729 gas_assert (args[1] == 'b'
11730 || (mips_opts.micromips
11732 && (args[2] == 'l' || args[2] == 'n'
11733 || args[2] == 's' || args[2] == 'a')));
11734 if (*s == '\0' && args[1] == 'b')
11736 /* Fall through. */
11738 case ')': /* These must match exactly. */
11743 case '[': /* These must match exactly. */
11745 gas_assert (!mips_opts.micromips);
11750 case '+': /* Opcode extension character. */
11753 case '1': /* UDI immediates. */
11757 gas_assert (!mips_opts.micromips);
11759 const struct mips_immed *imm = mips_immed;
11761 while (imm->type && imm->type != *args)
11765 my_getExpression (&imm_expr, s);
11766 check_absolute_expr (ip, &imm_expr);
11767 if ((unsigned long) imm_expr.X_add_number & ~imm->mask)
11769 as_warn (_("Illegal %s number (%lu, 0x%lx)"),
11770 imm->desc ? imm->desc : ip->insn_mo->name,
11771 (unsigned long) imm_expr.X_add_number,
11772 (unsigned long) imm_expr.X_add_number);
11773 imm_expr.X_add_number &= imm->mask;
11775 ip->insn_opcode |= ((unsigned long) imm_expr.X_add_number
11777 imm_expr.X_op = O_absent;
11782 case 'J': /* 10-bit hypcall code. */
11783 gas_assert (!mips_opts.micromips);
11785 unsigned long mask = OP_MASK_CODE10;
11787 my_getExpression (&imm_expr, s);
11788 check_absolute_expr (ip, &imm_expr);
11789 if ((unsigned long) imm_expr.X_add_number > mask)
11790 as_warn (_("Code for %s not in range 0..%lu (%lu)"),
11792 mask, (unsigned long) imm_expr.X_add_number);
11793 INSERT_OPERAND (0, CODE10, *ip, imm_expr.X_add_number);
11794 imm_expr.X_op = O_absent;
11799 case 'A': /* ins/ext position, becomes LSB. */
11808 my_getExpression (&imm_expr, s);
11809 check_absolute_expr (ip, &imm_expr);
11810 if ((unsigned long) imm_expr.X_add_number < limlo
11811 || (unsigned long) imm_expr.X_add_number > limhi)
11813 as_bad (_("Improper position (%lu)"),
11814 (unsigned long) imm_expr.X_add_number);
11815 imm_expr.X_add_number = limlo;
11817 lastpos = imm_expr.X_add_number;
11818 INSERT_OPERAND (mips_opts.micromips,
11819 EXTLSB, *ip, imm_expr.X_add_number);
11820 imm_expr.X_op = O_absent;
11824 case 'B': /* ins size, becomes MSB. */
11833 my_getExpression (&imm_expr, s);
11834 check_absolute_expr (ip, &imm_expr);
11835 /* Check for negative input so that small negative numbers
11836 will not succeed incorrectly. The checks against
11837 (pos+size) transitively check "size" itself,
11838 assuming that "pos" is reasonable. */
11839 if ((long) imm_expr.X_add_number < 0
11840 || ((unsigned long) imm_expr.X_add_number
11842 || ((unsigned long) imm_expr.X_add_number
11843 + lastpos) > limhi)
11845 as_bad (_("Improper insert size (%lu, position %lu)"),
11846 (unsigned long) imm_expr.X_add_number,
11847 (unsigned long) lastpos);
11848 imm_expr.X_add_number = limlo - lastpos;
11850 INSERT_OPERAND (mips_opts.micromips, INSMSB, *ip,
11851 lastpos + imm_expr.X_add_number - 1);
11852 imm_expr.X_op = O_absent;
11856 case 'C': /* ext size, becomes MSBD. */
11872 my_getExpression (&imm_expr, s);
11873 check_absolute_expr (ip, &imm_expr);
11874 /* The checks against (pos+size) don't transitively check
11875 "size" itself, assuming that "pos" is reasonable.
11876 We also need to check the lower bound of "size". */
11877 if ((long) imm_expr.X_add_number < sizelo
11878 || ((unsigned long) imm_expr.X_add_number
11880 || ((unsigned long) imm_expr.X_add_number
11881 + lastpos) > limhi)
11883 as_bad (_("Improper extract size (%lu, position %lu)"),
11884 (unsigned long) imm_expr.X_add_number,
11885 (unsigned long) lastpos);
11886 imm_expr.X_add_number = limlo - lastpos;
11888 INSERT_OPERAND (mips_opts.micromips,
11889 EXTMSBD, *ip, imm_expr.X_add_number - 1);
11890 imm_expr.X_op = O_absent;
11895 /* +D is for disassembly only; never match. */
11899 /* "+I" is like "I", except that imm2_expr is used. */
11900 my_getExpression (&imm2_expr, s);
11901 if (imm2_expr.X_op != O_big
11902 && imm2_expr.X_op != O_constant)
11903 insn_error = _("absolute expression required");
11904 if (HAVE_32BIT_GPRS)
11905 normalize_constant_expr (&imm2_expr);
11909 case 'T': /* Coprocessor register. */
11910 gas_assert (!mips_opts.micromips);
11911 /* +T is for disassembly only; never match. */
11914 case 't': /* Coprocessor register number. */
11915 gas_assert (!mips_opts.micromips);
11916 if (s[0] == '$' && ISDIGIT (s[1]))
11926 while (ISDIGIT (*s));
11928 as_bad (_("Invalid register number (%d)"), regno);
11931 INSERT_OPERAND (0, RT, *ip, regno);
11936 as_bad (_("Invalid coprocessor 0 register number"));
11940 /* bbit[01] and bbit[01]32 bit index. Give error if index
11941 is not in the valid range. */
11942 gas_assert (!mips_opts.micromips);
11943 my_getExpression (&imm_expr, s);
11944 check_absolute_expr (ip, &imm_expr);
11945 if ((unsigned) imm_expr.X_add_number > 31)
11947 as_bad (_("Improper bit index (%lu)"),
11948 (unsigned long) imm_expr.X_add_number);
11949 imm_expr.X_add_number = 0;
11951 INSERT_OPERAND (0, BBITIND, *ip, imm_expr.X_add_number);
11952 imm_expr.X_op = O_absent;
11957 /* bbit[01] bit index when bbit is used but we generate
11958 bbit[01]32 because the index is over 32. Move to the
11959 next candidate if index is not in the valid range. */
11960 gas_assert (!mips_opts.micromips);
11961 my_getExpression (&imm_expr, s);
11962 check_absolute_expr (ip, &imm_expr);
11963 if ((unsigned) imm_expr.X_add_number < 32
11964 || (unsigned) imm_expr.X_add_number > 63)
11966 INSERT_OPERAND (0, BBITIND, *ip, imm_expr.X_add_number - 32);
11967 imm_expr.X_op = O_absent;
11972 /* cins, cins32, exts and exts32 position field. Give error
11973 if it's not in the valid range. */
11974 gas_assert (!mips_opts.micromips);
11975 my_getExpression (&imm_expr, s);
11976 check_absolute_expr (ip, &imm_expr);
11977 if ((unsigned) imm_expr.X_add_number > 31)
11979 as_bad (_("Improper position (%lu)"),
11980 (unsigned long) imm_expr.X_add_number);
11981 imm_expr.X_add_number = 0;
11983 /* Make the pos explicit to simplify +S. */
11984 lastpos = imm_expr.X_add_number + 32;
11985 INSERT_OPERAND (0, CINSPOS, *ip, imm_expr.X_add_number);
11986 imm_expr.X_op = O_absent;
11991 /* cins, cins32, exts and exts32 position field. Move to
11992 the next candidate if it's not in the valid range. */
11993 gas_assert (!mips_opts.micromips);
11994 my_getExpression (&imm_expr, s);
11995 check_absolute_expr (ip, &imm_expr);
11996 if ((unsigned) imm_expr.X_add_number < 32
11997 || (unsigned) imm_expr.X_add_number > 63)
11999 lastpos = imm_expr.X_add_number;
12000 INSERT_OPERAND (0, CINSPOS, *ip, imm_expr.X_add_number - 32);
12001 imm_expr.X_op = O_absent;
12006 /* cins and exts length-minus-one field. */
12007 gas_assert (!mips_opts.micromips);
12008 my_getExpression (&imm_expr, s);
12009 check_absolute_expr (ip, &imm_expr);
12010 if ((unsigned long) imm_expr.X_add_number > 31)
12012 as_bad (_("Improper size (%lu)"),
12013 (unsigned long) imm_expr.X_add_number);
12014 imm_expr.X_add_number = 0;
12016 INSERT_OPERAND (0, CINSLM1, *ip, imm_expr.X_add_number);
12017 imm_expr.X_op = O_absent;
12022 /* cins32/exts32 and cins/exts aliasing cint32/exts32
12023 length-minus-one field. */
12024 gas_assert (!mips_opts.micromips);
12025 my_getExpression (&imm_expr, s);
12026 check_absolute_expr (ip, &imm_expr);
12027 if ((long) imm_expr.X_add_number < 0
12028 || (unsigned long) imm_expr.X_add_number + lastpos > 63)
12030 as_bad (_("Improper size (%lu)"),
12031 (unsigned long) imm_expr.X_add_number);
12032 imm_expr.X_add_number = 0;
12034 INSERT_OPERAND (0, CINSLM1, *ip, imm_expr.X_add_number);
12035 imm_expr.X_op = O_absent;
12040 /* seqi/snei immediate field. */
12041 gas_assert (!mips_opts.micromips);
12042 my_getExpression (&imm_expr, s);
12043 check_absolute_expr (ip, &imm_expr);
12044 if ((long) imm_expr.X_add_number < -512
12045 || (long) imm_expr.X_add_number >= 512)
12047 as_bad (_("Improper immediate (%ld)"),
12048 (long) imm_expr.X_add_number);
12049 imm_expr.X_add_number = 0;
12051 INSERT_OPERAND (0, SEQI, *ip, imm_expr.X_add_number);
12052 imm_expr.X_op = O_absent;
12056 case 'a': /* 8-bit signed offset in bit 6 */
12057 gas_assert (!mips_opts.micromips);
12058 my_getExpression (&imm_expr, s);
12059 check_absolute_expr (ip, &imm_expr);
12060 min_range = -((OP_MASK_OFFSET_A + 1) >> 1);
12061 max_range = ((OP_MASK_OFFSET_A + 1) >> 1) - 1;
12062 if (imm_expr.X_add_number < min_range
12063 || imm_expr.X_add_number > max_range)
12065 as_bad (_("Offset not in range %ld..%ld (%ld)"),
12066 (long) min_range, (long) max_range,
12067 (long) imm_expr.X_add_number);
12069 INSERT_OPERAND (0, OFFSET_A, *ip, imm_expr.X_add_number);
12070 imm_expr.X_op = O_absent;
12074 case 'b': /* 8-bit signed offset in bit 3 */
12075 gas_assert (!mips_opts.micromips);
12076 my_getExpression (&imm_expr, s);
12077 check_absolute_expr (ip, &imm_expr);
12078 min_range = -((OP_MASK_OFFSET_B + 1) >> 1);
12079 max_range = ((OP_MASK_OFFSET_B + 1) >> 1) - 1;
12080 if (imm_expr.X_add_number < min_range
12081 || imm_expr.X_add_number > max_range)
12083 as_bad (_("Offset not in range %ld..%ld (%ld)"),
12084 (long) min_range, (long) max_range,
12085 (long) imm_expr.X_add_number);
12087 INSERT_OPERAND (0, OFFSET_B, *ip, imm_expr.X_add_number);
12088 imm_expr.X_op = O_absent;
12092 case 'c': /* 9-bit signed offset in bit 6 */
12093 gas_assert (!mips_opts.micromips);
12094 my_getExpression (&imm_expr, s);
12095 check_absolute_expr (ip, &imm_expr);
12096 min_range = -((OP_MASK_OFFSET_C + 1) >> 1);
12097 max_range = ((OP_MASK_OFFSET_C + 1) >> 1) - 1;
12098 /* We check the offset range before adjusted. */
12101 if (imm_expr.X_add_number < min_range
12102 || imm_expr.X_add_number > max_range)
12104 as_bad (_("Offset not in range %ld..%ld (%ld)"),
12105 (long) min_range, (long) max_range,
12106 (long) imm_expr.X_add_number);
12108 if (imm_expr.X_add_number & 0xf)
12110 as_bad (_("Offset not 16 bytes alignment (%ld)"),
12111 (long) imm_expr.X_add_number);
12113 /* Right shift 4 bits to adjust the offset operand. */
12114 INSERT_OPERAND (0, OFFSET_C, *ip,
12115 imm_expr.X_add_number >> 4);
12116 imm_expr.X_op = O_absent;
12121 gas_assert (!mips_opts.micromips);
12122 if (!reg_lookup (&s, RTYPE_NUM | RTYPE_GP, ®no))
12124 if (regno == AT && mips_opts.at)
12126 if (mips_opts.at == ATREG)
12127 as_warn (_("used $at without \".set noat\""));
12129 as_warn (_("used $%u with \".set at=$%u\""),
12130 regno, mips_opts.at);
12132 INSERT_OPERAND (0, RZ, *ip, regno);
12136 gas_assert (!mips_opts.micromips);
12137 if (!reg_lookup (&s, RTYPE_FPU, ®no))
12139 INSERT_OPERAND (0, FZ, *ip, regno);
12146 /* Check whether there is only a single bracketed expression
12147 left. If so, it must be the base register and the
12148 constant must be zero. */
12149 if (*s == '(' && strchr (s + 1, '(') == 0)
12152 /* If this value won't fit into the offset, then go find
12153 a macro that will generate a 16- or 32-bit offset code
12155 i = my_getSmallExpression (&imm_expr, imm_reloc, s);
12156 if ((i == 0 && (imm_expr.X_op != O_constant
12157 || imm_expr.X_add_number >= 1 << shift
12158 || imm_expr.X_add_number < -1 << shift))
12161 imm_expr.X_op = O_absent;
12164 INSERT_OPERAND (mips_opts.micromips, EVAOFFSET, *ip,
12165 imm_expr.X_add_number);
12166 imm_expr.X_op = O_absent;
12172 as_bad (_("Internal error: bad %s opcode "
12173 "(unknown extension operand type `+%c'): %s %s"),
12174 mips_opts.micromips ? "microMIPS" : "MIPS",
12175 *args, insn->name, insn->args);
12176 /* Further processing is fruitless. */
12181 case '.': /* 10-bit offset. */
12182 gas_assert (mips_opts.micromips);
12183 case '~': /* 12-bit offset. */
12185 int shift = *args == '.' ? 9 : 11;
12188 /* Check whether there is only a single bracketed expression
12189 left. If so, it must be the base register and the
12190 constant must be zero. */
12191 if (*s == '(' && strchr (s + 1, '(') == 0)
12194 /* If this value won't fit into the offset, then go find
12195 a macro that will generate a 16- or 32-bit offset code
12197 i = my_getSmallExpression (&imm_expr, imm_reloc, s);
12198 if ((i == 0 && (imm_expr.X_op != O_constant
12199 || imm_expr.X_add_number >= 1 << shift
12200 || imm_expr.X_add_number < -1 << shift))
12203 imm_expr.X_op = O_absent;
12207 INSERT_OPERAND (1, OFFSET10, *ip, imm_expr.X_add_number);
12209 INSERT_OPERAND (mips_opts.micromips,
12210 OFFSET12, *ip, imm_expr.X_add_number);
12211 imm_expr.X_op = O_absent;
12216 case '<': /* must be at least one digit */
12218 * According to the manual, if the shift amount is greater
12219 * than 31 or less than 0, then the shift amount should be
12220 * mod 32. In reality the mips assembler issues an error.
12221 * We issue a warning and mask out all but the low 5 bits.
12223 my_getExpression (&imm_expr, s);
12224 check_absolute_expr (ip, &imm_expr);
12225 if ((unsigned long) imm_expr.X_add_number > 31)
12226 as_warn (_("Improper shift amount (%lu)"),
12227 (unsigned long) imm_expr.X_add_number);
12228 INSERT_OPERAND (mips_opts.micromips,
12229 SHAMT, *ip, imm_expr.X_add_number);
12230 imm_expr.X_op = O_absent;
12234 case '>': /* shift amount minus 32 */
12235 my_getExpression (&imm_expr, s);
12236 check_absolute_expr (ip, &imm_expr);
12237 if ((unsigned long) imm_expr.X_add_number < 32
12238 || (unsigned long) imm_expr.X_add_number > 63)
12240 INSERT_OPERAND (mips_opts.micromips,
12241 SHAMT, *ip, imm_expr.X_add_number - 32);
12242 imm_expr.X_op = O_absent;
12246 case 'k': /* CACHE code. */
12247 case 'h': /* PREFX code. */
12248 case '1': /* SYNC type. */
12249 my_getExpression (&imm_expr, s);
12250 check_absolute_expr (ip, &imm_expr);
12251 if ((unsigned long) imm_expr.X_add_number > 31)
12252 as_warn (_("Invalid value for `%s' (%lu)"),
12254 (unsigned long) imm_expr.X_add_number);
12258 if (mips_fix_cn63xxp1
12259 && !mips_opts.micromips
12260 && strcmp ("pref", insn->name) == 0)
12261 switch (imm_expr.X_add_number)
12270 case 31: /* These are ok. */
12273 default: /* The rest must be changed to 28. */
12274 imm_expr.X_add_number = 28;
12277 INSERT_OPERAND (mips_opts.micromips,
12278 CACHE, *ip, imm_expr.X_add_number);
12281 INSERT_OPERAND (mips_opts.micromips,
12282 PREFX, *ip, imm_expr.X_add_number);
12285 INSERT_OPERAND (mips_opts.micromips,
12286 STYPE, *ip, imm_expr.X_add_number);
12289 imm_expr.X_op = O_absent;
12293 case 'c': /* BREAK code. */
12295 unsigned long mask = (mips_opts.micromips
12296 ? MICROMIPSOP_MASK_CODE
12299 my_getExpression (&imm_expr, s);
12300 check_absolute_expr (ip, &imm_expr);
12301 if ((unsigned long) imm_expr.X_add_number > mask)
12302 as_warn (_("Code for %s not in range 0..%lu (%lu)"),
12304 mask, (unsigned long) imm_expr.X_add_number);
12305 INSERT_OPERAND (mips_opts.micromips,
12306 CODE, *ip, imm_expr.X_add_number);
12307 imm_expr.X_op = O_absent;
12312 case 'q': /* Lower BREAK code. */
12314 unsigned long mask = (mips_opts.micromips
12315 ? MICROMIPSOP_MASK_CODE2
12318 my_getExpression (&imm_expr, s);
12319 check_absolute_expr (ip, &imm_expr);
12320 if ((unsigned long) imm_expr.X_add_number > mask)
12321 as_warn (_("Lower code for %s not in range 0..%lu (%lu)"),
12323 mask, (unsigned long) imm_expr.X_add_number);
12324 INSERT_OPERAND (mips_opts.micromips,
12325 CODE2, *ip, imm_expr.X_add_number);
12326 imm_expr.X_op = O_absent;
12331 case 'B': /* 20- or 10-bit syscall/break/wait code. */
12333 unsigned long mask = (mips_opts.micromips
12334 ? MICROMIPSOP_MASK_CODE10
12337 my_getExpression (&imm_expr, s);
12338 check_absolute_expr (ip, &imm_expr);
12339 if ((unsigned long) imm_expr.X_add_number > mask)
12340 as_warn (_("Code for %s not in range 0..%lu (%lu)"),
12342 mask, (unsigned long) imm_expr.X_add_number);
12343 if (mips_opts.micromips)
12344 INSERT_OPERAND (1, CODE10, *ip, imm_expr.X_add_number);
12346 INSERT_OPERAND (0, CODE20, *ip, imm_expr.X_add_number);
12347 imm_expr.X_op = O_absent;
12352 case 'C': /* 25- or 23-bit coprocessor code. */
12354 unsigned long mask = (mips_opts.micromips
12355 ? MICROMIPSOP_MASK_COPZ
12358 my_getExpression (&imm_expr, s);
12359 check_absolute_expr (ip, &imm_expr);
12360 if ((unsigned long) imm_expr.X_add_number > mask)
12361 as_warn (_("Coproccesor code > %u bits (%lu)"),
12362 mips_opts.micromips ? 23U : 25U,
12363 (unsigned long) imm_expr.X_add_number);
12364 INSERT_OPERAND (mips_opts.micromips,
12365 COPZ, *ip, imm_expr.X_add_number);
12366 imm_expr.X_op = O_absent;
12371 case 'J': /* 19-bit WAIT code. */
12372 gas_assert (!mips_opts.micromips);
12373 my_getExpression (&imm_expr, s);
12374 check_absolute_expr (ip, &imm_expr);
12375 if ((unsigned long) imm_expr.X_add_number > OP_MASK_CODE19)
12377 as_warn (_("Illegal 19-bit code (%lu)"),
12378 (unsigned long) imm_expr.X_add_number);
12379 imm_expr.X_add_number &= OP_MASK_CODE19;
12381 INSERT_OPERAND (0, CODE19, *ip, imm_expr.X_add_number);
12382 imm_expr.X_op = O_absent;
12386 case 'P': /* Performance register. */
12387 gas_assert (!mips_opts.micromips);
12388 my_getExpression (&imm_expr, s);
12389 check_absolute_expr (ip, &imm_expr);
12390 if (imm_expr.X_add_number != 0 && imm_expr.X_add_number != 1)
12391 as_warn (_("Invalid performance register (%lu)"),
12392 (unsigned long) imm_expr.X_add_number);
12393 if (imm_expr.X_add_number != 0 && mips_opts.arch == CPU_R5900
12394 && (!strcmp(insn->name,"mfps") || !strcmp(insn->name,"mtps")))
12395 as_warn (_("Invalid performance register (%lu)"),
12396 (unsigned long) imm_expr.X_add_number);
12397 INSERT_OPERAND (0, PERFREG, *ip, imm_expr.X_add_number);
12398 imm_expr.X_op = O_absent;
12402 case 'G': /* Coprocessor destination register. */
12404 unsigned long opcode = ip->insn_opcode;
12405 unsigned long mask;
12406 unsigned int types;
12409 if (mips_opts.micromips)
12411 mask = ~((MICROMIPSOP_MASK_RT << MICROMIPSOP_SH_RT)
12412 | (MICROMIPSOP_MASK_RS << MICROMIPSOP_SH_RS)
12413 | (MICROMIPSOP_MASK_SEL << MICROMIPSOP_SH_SEL));
12417 case 0x000000fc: /* mfc0 */
12418 case 0x000002fc: /* mtc0 */
12419 case 0x580000fc: /* dmfc0 */
12420 case 0x580002fc: /* dmtc0 */
12430 opcode = (opcode >> OP_SH_OP) & OP_MASK_OP;
12431 cop0 = opcode == OP_OP_COP0;
12433 types = RTYPE_NUM | (cop0 ? RTYPE_CP0 : RTYPE_GP);
12434 ok = reg_lookup (&s, types, ®no);
12435 if (mips_opts.micromips)
12436 INSERT_OPERAND (1, RS, *ip, regno);
12438 INSERT_OPERAND (0, RD, *ip, regno);
12447 case 'y': /* ALNV.PS source register. */
12448 gas_assert (mips_opts.micromips);
12450 case 'x': /* Ignore register name. */
12451 case 'U': /* Destination register (CLO/CLZ). */
12452 case 'g': /* Coprocessor destination register. */
12453 gas_assert (!mips_opts.micromips);
12454 case 'b': /* Base register. */
12455 case 'd': /* Destination register. */
12456 case 's': /* Source register. */
12457 case 't': /* Target register. */
12458 case 'r': /* Both target and source. */
12459 case 'v': /* Both dest and source. */
12460 case 'w': /* Both dest and target. */
12461 case 'E': /* Coprocessor target register. */
12462 case 'K': /* RDHWR destination register. */
12463 case 'z': /* Must be zero register. */
12466 if (*args == 'E' || *args == 'K')
12467 ok = reg_lookup (&s, RTYPE_NUM, ®no);
12470 ok = reg_lookup (&s, RTYPE_NUM | RTYPE_GP, ®no);
12471 if (regno == AT && mips_opts.at)
12473 if (mips_opts.at == ATREG)
12474 as_warn (_("Used $at without \".set noat\""));
12476 as_warn (_("Used $%u with \".set at=$%u\""),
12477 regno, mips_opts.at);
12487 if (c == 'r' || c == 'v' || c == 'w')
12494 /* 'z' only matches $0. */
12495 if (c == 'z' && regno != 0)
12498 if (c == 's' && !strncmp (ip->insn_mo->name, "jalr", 4))
12500 if (regno == lastregno)
12503 = _("Source and destination must be different");
12506 if (regno == 31 && lastregno == 0xffffffff)
12509 = _("A destination register must be supplied");
12513 /* Now that we have assembled one operand, we use the args
12514 string to figure out where it goes in the instruction. */
12521 INSERT_OPERAND (mips_opts.micromips, RS, *ip, regno);
12525 if (mips_opts.micromips)
12526 INSERT_OPERAND (1, RS, *ip, regno);
12528 INSERT_OPERAND (0, RD, *ip, regno);
12533 INSERT_OPERAND (mips_opts.micromips, RD, *ip, regno);
12537 gas_assert (!mips_opts.micromips);
12538 INSERT_OPERAND (0, RD, *ip, regno);
12539 INSERT_OPERAND (0, RT, *ip, regno);
12545 INSERT_OPERAND (mips_opts.micromips, RT, *ip, regno);
12549 gas_assert (mips_opts.micromips);
12550 INSERT_OPERAND (1, RS3, *ip, regno);
12554 /* This case exists because on the r3000 trunc
12555 expands into a macro which requires a gp
12556 register. On the r6000 or r4000 it is
12557 assembled into a single instruction which
12558 ignores the register. Thus the insn version
12559 is MIPS_ISA2 and uses 'x', and the macro
12560 version is MIPS_ISA1 and uses 't'. */
12564 /* This case is for the div instruction, which
12565 acts differently if the destination argument
12566 is $0. This only matches $0, and is checked
12567 outside the switch. */
12577 INSERT_OPERAND (mips_opts.micromips, RS, *ip, lastregno);
12581 INSERT_OPERAND (mips_opts.micromips, RT, *ip, lastregno);
12586 case 'O': /* MDMX alignment immediate constant. */
12587 gas_assert (!mips_opts.micromips);
12588 my_getExpression (&imm_expr, s);
12589 check_absolute_expr (ip, &imm_expr);
12590 if ((unsigned long) imm_expr.X_add_number > OP_MASK_ALN)
12591 as_warn (_("Improper align amount (%ld), using low bits"),
12592 (long) imm_expr.X_add_number);
12593 INSERT_OPERAND (0, ALN, *ip, imm_expr.X_add_number);
12594 imm_expr.X_op = O_absent;
12598 case 'Q': /* MDMX vector, element sel, or const. */
12601 /* MDMX Immediate. */
12602 gas_assert (!mips_opts.micromips);
12603 my_getExpression (&imm_expr, s);
12604 check_absolute_expr (ip, &imm_expr);
12605 if ((unsigned long) imm_expr.X_add_number > OP_MASK_FT)
12606 as_warn (_("Invalid MDMX Immediate (%ld)"),
12607 (long) imm_expr.X_add_number);
12608 INSERT_OPERAND (0, FT, *ip, imm_expr.X_add_number);
12609 if (ip->insn_opcode & (OP_MASK_VSEL << OP_SH_VSEL))
12610 ip->insn_opcode |= MDMX_FMTSEL_IMM_QH << OP_SH_VSEL;
12612 ip->insn_opcode |= MDMX_FMTSEL_IMM_OB << OP_SH_VSEL;
12613 imm_expr.X_op = O_absent;
12617 /* Not MDMX Immediate. Fall through. */
12618 case 'X': /* MDMX destination register. */
12619 case 'Y': /* MDMX source register. */
12620 case 'Z': /* MDMX target register. */
12623 gas_assert (!mips_opts.micromips);
12624 case 'D': /* Floating point destination register. */
12625 case 'S': /* Floating point source register. */
12626 case 'T': /* Floating point target register. */
12627 case 'R': /* Floating point source register. */
12631 || ((mips_opts.ase & ASE_MDMX)
12632 && (ip->insn_mo->pinfo & FP_D)
12633 && (ip->insn_mo->pinfo & (INSN_COPROC_MOVE_DELAY
12634 | INSN_COPROC_MEMORY_DELAY
12635 | INSN_LOAD_COPROC_DELAY
12636 | INSN_LOAD_MEMORY_DELAY
12637 | INSN_STORE_MEMORY))))
12638 rtype |= RTYPE_VEC;
12640 if (reg_lookup (&s, rtype, ®no))
12642 if ((regno & 1) != 0
12644 && !mips_oddfpreg_ok (ip->insn_mo, argnum))
12645 as_warn (_("Float register should be even, was %d"),
12653 if (c == 'V' || c == 'W')
12664 INSERT_OPERAND (mips_opts.micromips, FD, *ip, regno);
12670 INSERT_OPERAND (mips_opts.micromips, FS, *ip, regno);
12674 /* This is like 'Z', but also needs to fix the MDMX
12675 vector/scalar select bits. Note that the
12676 scalar immediate case is handled above. */
12679 int is_qh = (ip->insn_opcode & (1 << OP_SH_VSEL));
12680 int max_el = (is_qh ? 3 : 7);
12682 my_getExpression(&imm_expr, s);
12683 check_absolute_expr (ip, &imm_expr);
12685 if (imm_expr.X_add_number > max_el)
12686 as_bad (_("Bad element selector %ld"),
12687 (long) imm_expr.X_add_number);
12688 imm_expr.X_add_number &= max_el;
12689 ip->insn_opcode |= (imm_expr.X_add_number
12692 imm_expr.X_op = O_absent;
12694 as_warn (_("Expecting ']' found '%s'"), s);
12700 if (ip->insn_opcode & (OP_MASK_VSEL << OP_SH_VSEL))
12701 ip->insn_opcode |= (MDMX_FMTSEL_VEC_QH
12704 ip->insn_opcode |= (MDMX_FMTSEL_VEC_OB <<
12707 /* Fall through. */
12711 INSERT_OPERAND (mips_opts.micromips, FT, *ip, regno);
12715 INSERT_OPERAND (mips_opts.micromips, FR, *ip, regno);
12725 INSERT_OPERAND (mips_opts.micromips, FS, *ip, lastregno);
12729 INSERT_OPERAND (mips_opts.micromips, FT, *ip, lastregno);
12735 my_getExpression (&imm_expr, s);
12736 if (imm_expr.X_op != O_big
12737 && imm_expr.X_op != O_constant)
12738 insn_error = _("absolute expression required");
12739 if (HAVE_32BIT_GPRS)
12740 normalize_constant_expr (&imm_expr);
12745 my_getExpression (&offset_expr, s);
12746 normalize_address_expr (&offset_expr);
12747 *imm_reloc = BFD_RELOC_32;
12760 unsigned char temp[8];
12762 unsigned int length;
12767 /* These only appear as the last operand in an
12768 instruction, and every instruction that accepts
12769 them in any variant accepts them in all variants.
12770 This means we don't have to worry about backing out
12771 any changes if the instruction does not match.
12773 The difference between them is the size of the
12774 floating point constant and where it goes. For 'F'
12775 and 'L' the constant is 64 bits; for 'f' and 'l' it
12776 is 32 bits. Where the constant is placed is based
12777 on how the MIPS assembler does things:
12780 f -- immediate value
12783 The .lit4 and .lit8 sections are only used if
12784 permitted by the -G argument.
12786 The code below needs to know whether the target register
12787 is 32 or 64 bits wide. It relies on the fact 'f' and
12788 'F' are used with GPR-based instructions and 'l' and
12789 'L' are used with FPR-based instructions. */
12791 f64 = *args == 'F' || *args == 'L';
12792 using_gprs = *args == 'F' || *args == 'f';
12794 save_in = input_line_pointer;
12795 input_line_pointer = s;
12796 err = md_atof (f64 ? 'd' : 'f', (char *) temp, &len);
12798 s = input_line_pointer;
12799 input_line_pointer = save_in;
12800 if (err != NULL && *err != '\0')
12802 as_bad (_("Bad floating point constant: %s"), err);
12803 memset (temp, '\0', sizeof temp);
12804 length = f64 ? 8 : 4;
12807 gas_assert (length == (unsigned) (f64 ? 8 : 4));
12811 && (g_switch_value < 4
12812 || (temp[0] == 0 && temp[1] == 0)
12813 || (temp[2] == 0 && temp[3] == 0))))
12815 imm_expr.X_op = O_constant;
12816 if (!target_big_endian)
12817 imm_expr.X_add_number = bfd_getl32 (temp);
12819 imm_expr.X_add_number = bfd_getb32 (temp);
12821 else if (length > 4
12822 && !mips_disable_float_construction
12823 /* Constants can only be constructed in GPRs and
12824 copied to FPRs if the GPRs are at least as wide
12825 as the FPRs. Force the constant into memory if
12826 we are using 64-bit FPRs but the GPRs are only
12829 || !(HAVE_64BIT_FPRS && HAVE_32BIT_GPRS))
12830 && ((temp[0] == 0 && temp[1] == 0)
12831 || (temp[2] == 0 && temp[3] == 0))
12832 && ((temp[4] == 0 && temp[5] == 0)
12833 || (temp[6] == 0 && temp[7] == 0)))
12835 /* The value is simple enough to load with a couple of
12836 instructions. If using 32-bit registers, set
12837 imm_expr to the high order 32 bits and offset_expr to
12838 the low order 32 bits. Otherwise, set imm_expr to
12839 the entire 64 bit constant. */
12840 if (using_gprs ? HAVE_32BIT_GPRS : HAVE_32BIT_FPRS)
12842 imm_expr.X_op = O_constant;
12843 offset_expr.X_op = O_constant;
12844 if (!target_big_endian)
12846 imm_expr.X_add_number = bfd_getl32 (temp + 4);
12847 offset_expr.X_add_number = bfd_getl32 (temp);
12851 imm_expr.X_add_number = bfd_getb32 (temp);
12852 offset_expr.X_add_number = bfd_getb32 (temp + 4);
12854 if (offset_expr.X_add_number == 0)
12855 offset_expr.X_op = O_absent;
12857 else if (sizeof (imm_expr.X_add_number) > 4)
12859 imm_expr.X_op = O_constant;
12860 if (!target_big_endian)
12861 imm_expr.X_add_number = bfd_getl64 (temp);
12863 imm_expr.X_add_number = bfd_getb64 (temp);
12867 imm_expr.X_op = O_big;
12868 imm_expr.X_add_number = 4;
12869 if (!target_big_endian)
12871 generic_bignum[0] = bfd_getl16 (temp);
12872 generic_bignum[1] = bfd_getl16 (temp + 2);
12873 generic_bignum[2] = bfd_getl16 (temp + 4);
12874 generic_bignum[3] = bfd_getl16 (temp + 6);
12878 generic_bignum[0] = bfd_getb16 (temp + 6);
12879 generic_bignum[1] = bfd_getb16 (temp + 4);
12880 generic_bignum[2] = bfd_getb16 (temp + 2);
12881 generic_bignum[3] = bfd_getb16 (temp);
12887 const char *newname;
12890 /* Switch to the right section. */
12892 subseg = now_subseg;
12895 default: /* unused default case avoids warnings. */
12897 newname = RDATA_SECTION_NAME;
12898 if (g_switch_value >= 8)
12902 newname = RDATA_SECTION_NAME;
12905 gas_assert (g_switch_value >= 4);
12909 new_seg = subseg_new (newname, (subsegT) 0);
12910 bfd_set_section_flags (stdoutput, new_seg,
12915 frag_align (*args == 'l' ? 2 : 3, 0, 0);
12916 if (strncmp (TARGET_OS, "elf", 3) != 0)
12917 record_alignment (new_seg, 4);
12919 record_alignment (new_seg, *args == 'l' ? 2 : 3);
12920 if (seg == now_seg)
12921 as_bad (_("Can't use floating point insn in this section"));
12923 /* Set the argument to the current address in the
12925 offset_expr.X_op = O_symbol;
12926 offset_expr.X_add_symbol = symbol_temp_new_now ();
12927 offset_expr.X_add_number = 0;
12929 /* Put the floating point number into the section. */
12930 p = frag_more ((int) length);
12931 memcpy (p, temp, length);
12933 /* Switch back to the original section. */
12934 subseg_set (seg, subseg);
12939 case 'i': /* 16-bit unsigned immediate. */
12940 case 'j': /* 16-bit signed immediate. */
12941 *imm_reloc = BFD_RELOC_LO16;
12942 if (my_getSmallExpression (&imm_expr, imm_reloc, s) == 0)
12945 offsetT minval, maxval;
12947 more = (insn + 1 < past
12948 && strcmp (insn->name, insn[1].name) == 0);
12950 /* If the expression was written as an unsigned number,
12951 only treat it as signed if there are no more
12955 && sizeof (imm_expr.X_add_number) <= 4
12956 && imm_expr.X_op == O_constant
12957 && imm_expr.X_add_number < 0
12958 && imm_expr.X_unsigned
12959 && HAVE_64BIT_GPRS)
12962 /* For compatibility with older assemblers, we accept
12963 0x8000-0xffff as signed 16-bit numbers when only
12964 signed numbers are allowed. */
12966 minval = 0, maxval = 0xffff;
12968 minval = -0x8000, maxval = 0x7fff;
12970 minval = -0x8000, maxval = 0xffff;
12972 if (imm_expr.X_op != O_constant
12973 || imm_expr.X_add_number < minval
12974 || imm_expr.X_add_number > maxval)
12978 if (imm_expr.X_op == O_constant
12979 || imm_expr.X_op == O_big)
12980 as_bad (_("Expression out of range"));
12986 case 'o': /* 16-bit offset. */
12987 offset_reloc[0] = BFD_RELOC_LO16;
12988 offset_reloc[1] = BFD_RELOC_UNUSED;
12989 offset_reloc[2] = BFD_RELOC_UNUSED;
12991 /* Check whether there is only a single bracketed expression
12992 left. If so, it must be the base register and the
12993 constant must be zero. */
12994 if (*s == '(' && strchr (s + 1, '(') == 0)
12996 offset_expr.X_op = O_constant;
12997 offset_expr.X_add_number = 0;
13001 /* If this value won't fit into a 16 bit offset, then go
13002 find a macro that will generate the 32 bit offset
13004 if (my_getSmallExpression (&offset_expr, offset_reloc, s) == 0
13005 && (offset_expr.X_op != O_constant
13006 || offset_expr.X_add_number >= 0x8000
13007 || offset_expr.X_add_number < -0x8000))
13013 case 'p': /* PC-relative offset. */
13014 *offset_reloc = BFD_RELOC_16_PCREL_S2;
13015 my_getExpression (&offset_expr, s);
13019 case 'u': /* Upper 16 bits. */
13020 *imm_reloc = BFD_RELOC_LO16;
13021 if (my_getSmallExpression (&imm_expr, imm_reloc, s) == 0
13022 && imm_expr.X_op == O_constant
13023 && (imm_expr.X_add_number < 0
13024 || imm_expr.X_add_number >= 0x10000))
13025 as_bad (_("lui expression (%lu) not in range 0..65535"),
13026 (unsigned long) imm_expr.X_add_number);
13030 case 'a': /* 26-bit address. */
13031 *offset_reloc = BFD_RELOC_MIPS_JMP;
13032 my_getExpression (&offset_expr, s);
13036 case 'N': /* 3-bit branch condition code. */
13037 case 'M': /* 3-bit compare condition code. */
13039 if (ip->insn_mo->pinfo & (FP_D | FP_S))
13040 rtype |= RTYPE_FCC;
13041 if (!reg_lookup (&s, rtype, ®no))
13043 if ((strcmp (str + strlen (str) - 3, ".ps") == 0
13044 || strcmp (str + strlen (str) - 5, "any2f") == 0
13045 || strcmp (str + strlen (str) - 5, "any2t") == 0)
13046 && (regno & 1) != 0)
13047 as_warn (_("Condition code register should be even for %s, "
13050 if ((strcmp (str + strlen (str) - 5, "any4f") == 0
13051 || strcmp (str + strlen (str) - 5, "any4t") == 0)
13052 && (regno & 3) != 0)
13053 as_warn (_("Condition code register should be 0 or 4 for %s, "
13057 INSERT_OPERAND (mips_opts.micromips, BCC, *ip, regno);
13059 INSERT_OPERAND (mips_opts.micromips, CCC, *ip, regno);
13063 if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X'))
13074 while (ISDIGIT (*s));
13077 c = 8; /* Invalid sel value. */
13080 as_bad (_("Invalid coprocessor sub-selection value (0-7)"));
13081 INSERT_OPERAND (mips_opts.micromips, SEL, *ip, c);
13085 gas_assert (!mips_opts.micromips);
13086 /* Must be at least one digit. */
13087 my_getExpression (&imm_expr, s);
13088 check_absolute_expr (ip, &imm_expr);
13090 if ((unsigned long) imm_expr.X_add_number
13091 > (unsigned long) OP_MASK_VECBYTE)
13093 as_bad (_("bad byte vector index (%ld)"),
13094 (long) imm_expr.X_add_number);
13095 imm_expr.X_add_number = 0;
13098 INSERT_OPERAND (0, VECBYTE, *ip, imm_expr.X_add_number);
13099 imm_expr.X_op = O_absent;
13104 gas_assert (!mips_opts.micromips);
13105 my_getExpression (&imm_expr, s);
13106 check_absolute_expr (ip, &imm_expr);
13108 if ((unsigned long) imm_expr.X_add_number
13109 > (unsigned long) OP_MASK_VECALIGN)
13111 as_bad (_("bad byte vector index (%ld)"),
13112 (long) imm_expr.X_add_number);
13113 imm_expr.X_add_number = 0;
13116 INSERT_OPERAND (0, VECALIGN, *ip, imm_expr.X_add_number);
13117 imm_expr.X_op = O_absent;
13121 case 'm': /* Opcode extension character. */
13122 gas_assert (mips_opts.micromips);
13127 if (strncmp (s, "$pc", 3) == 0)
13155 ok = reg_lookup (&s, RTYPE_NUM | RTYPE_GP, ®no);
13156 if (regno == AT && mips_opts.at)
13158 if (mips_opts.at == ATREG)
13159 as_warn (_("Used $at without \".set noat\""));
13161 as_warn (_("Used $%u with \".set at=$%u\""),
13162 regno, mips_opts.at);
13168 gas_assert (args[1] == ',');
13174 gas_assert (args[1] == ',');
13176 continue; /* Nothing to do. */
13182 if (c == 'j' && !strncmp (ip->insn_mo->name, "jalr", 4))
13184 if (regno == lastregno)
13187 = _("Source and destination must be different");
13190 if (regno == 31 && lastregno == 0xffffffff)
13193 = _("A destination register must be supplied");
13204 gas_assert (args[1] == ',');
13211 gas_assert (args[1] == ',');
13214 continue; /* Nothing to do. */
13218 /* Make sure regno is the same as lastregno. */
13219 if (c == 't' && regno != lastregno)
13222 /* Make sure regno is the same as destregno. */
13223 if (c == 'x' && regno != destregno)
13226 /* We need to save regno, before regno maps to the
13227 microMIPS register encoding. */
13237 regno = ILLEGAL_REG;
13241 regno = mips32_to_micromips_reg_b_map[regno];
13245 regno = mips32_to_micromips_reg_c_map[regno];
13249 regno = mips32_to_micromips_reg_d_map[regno];
13253 regno = mips32_to_micromips_reg_e_map[regno];
13257 regno = mips32_to_micromips_reg_f_map[regno];
13261 regno = mips32_to_micromips_reg_g_map[regno];
13265 regno = mips32_to_micromips_reg_h_map[regno];
13269 switch (EXTRACT_OPERAND (1, MI, *ip))
13274 else if (regno == 22)
13276 else if (regno == 5)
13278 else if (regno == 6)
13280 else if (regno == 7)
13283 regno = ILLEGAL_REG;
13289 else if (regno == 7)
13292 regno = ILLEGAL_REG;
13299 regno = ILLEGAL_REG;
13303 regno = ILLEGAL_REG;
13309 regno = mips32_to_micromips_reg_l_map[regno];
13313 regno = mips32_to_micromips_reg_m_map[regno];
13317 regno = mips32_to_micromips_reg_n_map[regno];
13321 regno = mips32_to_micromips_reg_q_map[regno];
13326 regno = ILLEGAL_REG;
13331 regno = ILLEGAL_REG;
13336 regno = ILLEGAL_REG;
13339 case 'j': /* Do nothing. */
13349 if (regno == ILLEGAL_REG)
13355 INSERT_OPERAND (1, MB, *ip, regno);
13359 INSERT_OPERAND (1, MC, *ip, regno);
13363 INSERT_OPERAND (1, MD, *ip, regno);
13367 INSERT_OPERAND (1, ME, *ip, regno);
13371 INSERT_OPERAND (1, MF, *ip, regno);
13375 INSERT_OPERAND (1, MG, *ip, regno);
13379 INSERT_OPERAND (1, MH, *ip, regno);
13383 INSERT_OPERAND (1, MI, *ip, regno);
13387 INSERT_OPERAND (1, MJ, *ip, regno);
13391 INSERT_OPERAND (1, ML, *ip, regno);
13395 INSERT_OPERAND (1, MM, *ip, regno);
13399 INSERT_OPERAND (1, MN, *ip, regno);
13403 INSERT_OPERAND (1, MP, *ip, regno);
13407 INSERT_OPERAND (1, MQ, *ip, regno);
13410 case 'a': /* Do nothing. */
13411 case 's': /* Do nothing. */
13412 case 't': /* Do nothing. */
13413 case 'x': /* Do nothing. */
13414 case 'y': /* Do nothing. */
13415 case 'z': /* Do nothing. */
13425 bfd_reloc_code_real_type r[3];
13429 /* Check whether there is only a single bracketed
13430 expression left. If so, it must be the base register
13431 and the constant must be zero. */
13432 if (*s == '(' && strchr (s + 1, '(') == 0)
13434 INSERT_OPERAND (1, IMMA, *ip, 0);
13438 if (my_getSmallExpression (&ep, r, s) > 0
13439 || !expr_const_in_range (&ep, -64, 64, 2))
13442 imm = ep.X_add_number >> 2;
13443 INSERT_OPERAND (1, IMMA, *ip, imm);
13450 bfd_reloc_code_real_type r[3];
13454 if (my_getSmallExpression (&ep, r, s) > 0
13455 || ep.X_op != O_constant)
13458 for (imm = 0; imm < 8; imm++)
13459 if (micromips_imm_b_map[imm] == ep.X_add_number)
13464 INSERT_OPERAND (1, IMMB, *ip, imm);
13471 bfd_reloc_code_real_type r[3];
13475 if (my_getSmallExpression (&ep, r, s) > 0
13476 || ep.X_op != O_constant)
13479 for (imm = 0; imm < 16; imm++)
13480 if (micromips_imm_c_map[imm] == ep.X_add_number)
13485 INSERT_OPERAND (1, IMMC, *ip, imm);
13490 case 'D': /* pc relative offset */
13491 case 'E': /* pc relative offset */
13492 my_getExpression (&offset_expr, s);
13493 if (offset_expr.X_op == O_register)
13496 if (!forced_insn_length)
13497 *offset_reloc = (int) BFD_RELOC_UNUSED + c;
13499 *offset_reloc = BFD_RELOC_MICROMIPS_10_PCREL_S1;
13501 *offset_reloc = BFD_RELOC_MICROMIPS_7_PCREL_S1;
13507 bfd_reloc_code_real_type r[3];
13511 if (my_getSmallExpression (&ep, r, s) > 0
13512 || !expr_const_in_range (&ep, 0, 16, 0))
13515 imm = ep.X_add_number;
13516 INSERT_OPERAND (1, IMMF, *ip, imm);
13523 bfd_reloc_code_real_type r[3];
13527 /* Check whether there is only a single bracketed
13528 expression left. If so, it must be the base register
13529 and the constant must be zero. */
13530 if (*s == '(' && strchr (s + 1, '(') == 0)
13532 INSERT_OPERAND (1, IMMG, *ip, 0);
13536 if (my_getSmallExpression (&ep, r, s) > 0
13537 || !expr_const_in_range (&ep, -1, 15, 0))
13540 imm = ep.X_add_number & 15;
13541 INSERT_OPERAND (1, IMMG, *ip, imm);
13548 bfd_reloc_code_real_type r[3];
13552 /* Check whether there is only a single bracketed
13553 expression left. If so, it must be the base register
13554 and the constant must be zero. */
13555 if (*s == '(' && strchr (s + 1, '(') == 0)
13557 INSERT_OPERAND (1, IMMH, *ip, 0);
13561 if (my_getSmallExpression (&ep, r, s) > 0
13562 || !expr_const_in_range (&ep, 0, 16, 1))
13565 imm = ep.X_add_number >> 1;
13566 INSERT_OPERAND (1, IMMH, *ip, imm);
13573 bfd_reloc_code_real_type r[3];
13577 if (my_getSmallExpression (&ep, r, s) > 0
13578 || !expr_const_in_range (&ep, -1, 127, 0))
13581 imm = ep.X_add_number & 127;
13582 INSERT_OPERAND (1, IMMI, *ip, imm);
13589 bfd_reloc_code_real_type r[3];
13593 /* Check whether there is only a single bracketed
13594 expression left. If so, it must be the base register
13595 and the constant must be zero. */
13596 if (*s == '(' && strchr (s + 1, '(') == 0)
13598 INSERT_OPERAND (1, IMMJ, *ip, 0);
13602 if (my_getSmallExpression (&ep, r, s) > 0
13603 || !expr_const_in_range (&ep, 0, 16, 2))
13606 imm = ep.X_add_number >> 2;
13607 INSERT_OPERAND (1, IMMJ, *ip, imm);
13614 bfd_reloc_code_real_type r[3];
13618 /* Check whether there is only a single bracketed
13619 expression left. If so, it must be the base register
13620 and the constant must be zero. */
13621 if (*s == '(' && strchr (s + 1, '(') == 0)
13623 INSERT_OPERAND (1, IMML, *ip, 0);
13627 if (my_getSmallExpression (&ep, r, s) > 0
13628 || !expr_const_in_range (&ep, 0, 16, 0))
13631 imm = ep.X_add_number;
13632 INSERT_OPERAND (1, IMML, *ip, imm);
13639 bfd_reloc_code_real_type r[3];
13643 if (my_getSmallExpression (&ep, r, s) > 0
13644 || !expr_const_in_range (&ep, 1, 9, 0))
13647 imm = ep.X_add_number & 7;
13648 INSERT_OPERAND (1, IMMM, *ip, imm);
13653 case 'N': /* Register list for lwm and swm. */
13655 /* A comma-separated list of registers and/or
13656 dash-separated contiguous ranges including
13657 both ra and a set of one or more registers
13658 starting at s0 up to s3 which have to be
13665 and any permutations of these. */
13666 unsigned int reglist;
13669 if (!reglist_lookup (&s, RTYPE_NUM | RTYPE_GP, ®list))
13672 if ((reglist & 0xfff1ffff) != 0x80010000)
13675 reglist = (reglist >> 17) & 7;
13677 if ((reglist & -reglist) != reglist)
13680 imm = ffs (reglist) - 1;
13681 INSERT_OPERAND (1, IMMN, *ip, imm);
13685 case 'O': /* sdbbp 4-bit code. */
13687 bfd_reloc_code_real_type r[3];
13691 if (my_getSmallExpression (&ep, r, s) > 0
13692 || !expr_const_in_range (&ep, 0, 16, 0))
13695 imm = ep.X_add_number;
13696 INSERT_OPERAND (1, IMMO, *ip, imm);
13703 bfd_reloc_code_real_type r[3];
13707 if (my_getSmallExpression (&ep, r, s) > 0
13708 || !expr_const_in_range (&ep, 0, 32, 2))
13711 imm = ep.X_add_number >> 2;
13712 INSERT_OPERAND (1, IMMP, *ip, imm);
13719 bfd_reloc_code_real_type r[3];
13723 if (my_getSmallExpression (&ep, r, s) > 0
13724 || !expr_const_in_range (&ep, -0x400000, 0x400000, 2))
13727 imm = ep.X_add_number >> 2;
13728 INSERT_OPERAND (1, IMMQ, *ip, imm);
13735 bfd_reloc_code_real_type r[3];
13739 /* Check whether there is only a single bracketed
13740 expression left. If so, it must be the base register
13741 and the constant must be zero. */
13742 if (*s == '(' && strchr (s + 1, '(') == 0)
13744 INSERT_OPERAND (1, IMMU, *ip, 0);
13748 if (my_getSmallExpression (&ep, r, s) > 0
13749 || !expr_const_in_range (&ep, 0, 32, 2))
13752 imm = ep.X_add_number >> 2;
13753 INSERT_OPERAND (1, IMMU, *ip, imm);
13760 bfd_reloc_code_real_type r[3];
13764 if (my_getSmallExpression (&ep, r, s) > 0
13765 || !expr_const_in_range (&ep, 0, 64, 2))
13768 imm = ep.X_add_number >> 2;
13769 INSERT_OPERAND (1, IMMW, *ip, imm);
13776 bfd_reloc_code_real_type r[3];
13780 if (my_getSmallExpression (&ep, r, s) > 0
13781 || !expr_const_in_range (&ep, -8, 8, 0))
13784 imm = ep.X_add_number;
13785 INSERT_OPERAND (1, IMMX, *ip, imm);
13792 bfd_reloc_code_real_type r[3];
13796 if (my_getSmallExpression (&ep, r, s) > 0
13797 || expr_const_in_range (&ep, -2, 2, 2)
13798 || !expr_const_in_range (&ep, -258, 258, 2))
13801 imm = ep.X_add_number >> 2;
13802 imm = ((imm >> 1) & ~0xff) | (imm & 0xff);
13803 INSERT_OPERAND (1, IMMY, *ip, imm);
13810 bfd_reloc_code_real_type r[3];
13813 if (my_getSmallExpression (&ep, r, s) > 0
13814 || !expr_const_in_range (&ep, 0, 1, 0))
13821 as_bad (_("Internal error: bad microMIPS opcode "
13822 "(unknown extension operand type `m%c'): %s %s"),
13823 *args, insn->name, insn->args);
13824 /* Further processing is fruitless. */
13829 case 'n': /* Register list for 32-bit lwm and swm. */
13830 gas_assert (mips_opts.micromips);
13832 /* A comma-separated list of registers and/or
13833 dash-separated contiguous ranges including
13834 at least one of ra and a set of one or more
13835 registers starting at s0 up to s7 and then
13836 s8 which have to be consecutive, e.g.:
13844 and any permutations of these. */
13845 unsigned int reglist;
13849 if (!reglist_lookup (&s, RTYPE_NUM | RTYPE_GP, ®list))
13852 if ((reglist & 0x3f00ffff) != 0)
13855 ra = (reglist >> 27) & 0x10;
13856 reglist = ((reglist >> 22) & 0x100) | ((reglist >> 16) & 0xff);
13858 if ((reglist & -reglist) != reglist)
13861 imm = (ffs (reglist) - 1) | ra;
13862 INSERT_OPERAND (1, RT, *ip, imm);
13863 imm_expr.X_op = O_absent;
13867 case '|': /* 4-bit trap code. */
13868 gas_assert (mips_opts.micromips);
13869 my_getExpression (&imm_expr, s);
13870 check_absolute_expr (ip, &imm_expr);
13871 if ((unsigned long) imm_expr.X_add_number
13872 > MICROMIPSOP_MASK_TRAP)
13873 as_bad (_("Trap code (%lu) for %s not in 0..15 range"),
13874 (unsigned long) imm_expr.X_add_number,
13875 ip->insn_mo->name);
13876 INSERT_OPERAND (1, TRAP, *ip, imm_expr.X_add_number);
13877 imm_expr.X_op = O_absent;
13882 as_bad (_("Bad char = '%c'\n"), *args);
13887 /* Args don't match. */
13889 insn_error = _("Illegal operands");
13890 if (insn + 1 < past && !strcmp (insn->name, insn[1].name))
13895 else if (wrong_delay_slot_insns && need_delay_slot_ok)
13897 gas_assert (firstinsn);
13898 need_delay_slot_ok = FALSE;
13907 #define SKIP_SPACE_TABS(S) { while (*(S) == ' ' || *(S) == '\t') ++(S); }
13909 /* This routine assembles an instruction into its binary format when
13910 assembling for the mips16. As a side effect, it sets one of the
13911 global variables imm_reloc or offset_reloc to the type of relocation
13912 to do if one of the operands is an address expression. It also sets
13913 forced_insn_length to the resulting instruction size in bytes if the
13914 user explicitly requested a small or extended instruction. */
13917 mips16_ip (char *str, struct mips_cl_insn *ip)
13921 struct mips_opcode *insn;
13923 unsigned int regno;
13924 unsigned int lastregno = 0;
13930 forced_insn_length = 0;
13932 for (s = str; ISLOWER (*s); ++s)
13944 if (s[1] == 't' && s[2] == ' ')
13947 forced_insn_length = 2;
13951 else if (s[1] == 'e' && s[2] == ' ')
13954 forced_insn_length = 4;
13958 /* Fall through. */
13960 insn_error = _("unknown opcode");
13964 if (mips_opts.noautoextend && !forced_insn_length)
13965 forced_insn_length = 2;
13967 if ((insn = (struct mips_opcode *) hash_find (mips16_op_hash, str)) == NULL)
13969 insn_error = _("unrecognized opcode");
13978 gas_assert (strcmp (insn->name, str) == 0);
13980 ok = is_opcode_valid_16 (insn);
13983 if (insn + 1 < &mips16_opcodes[bfd_mips16_num_opcodes]
13984 && strcmp (insn->name, insn[1].name) == 0)
13993 static char buf[100];
13995 _("Opcode not supported on this processor: %s (%s)"),
13996 mips_cpu_info_from_arch (mips_opts.arch)->name,
13997 mips_cpu_info_from_isa (mips_opts.isa)->name);
14004 create_insn (ip, insn);
14005 imm_expr.X_op = O_absent;
14006 imm_reloc[0] = BFD_RELOC_UNUSED;
14007 imm_reloc[1] = BFD_RELOC_UNUSED;
14008 imm_reloc[2] = BFD_RELOC_UNUSED;
14009 imm2_expr.X_op = O_absent;
14010 offset_expr.X_op = O_absent;
14011 offset_reloc[0] = BFD_RELOC_UNUSED;
14012 offset_reloc[1] = BFD_RELOC_UNUSED;
14013 offset_reloc[2] = BFD_RELOC_UNUSED;
14014 for (args = insn->args; 1; ++args)
14021 /* In this switch statement we call break if we did not find
14022 a match, continue if we did find a match, or return if we
14033 /* Stuff the immediate value in now, if we can. */
14034 if (imm_expr.X_op == O_constant
14035 && *imm_reloc > BFD_RELOC_UNUSED
14036 && insn->pinfo != INSN_MACRO
14037 && calculate_reloc (*offset_reloc,
14038 imm_expr.X_add_number, &value))
14040 mips16_immed (NULL, 0, *imm_reloc - BFD_RELOC_UNUSED,
14041 *offset_reloc, value, forced_insn_length,
14043 imm_expr.X_op = O_absent;
14044 *imm_reloc = BFD_RELOC_UNUSED;
14045 *offset_reloc = BFD_RELOC_UNUSED;
14059 MIPS16_INSERT_OPERAND (RX, *ip, lastregno);
14062 MIPS16_INSERT_OPERAND (RY, *ip, lastregno);
14078 MIPS16_INSERT_OPERAND (RX, *ip, lastregno);
14080 MIPS16_INSERT_OPERAND (RY, *ip, lastregno);
14084 /* Fall through. */
14095 if (!reg_lookup (&s, RTYPE_NUM | RTYPE_GP, ®no))
14097 if (c == 'v' || c == 'w')
14100 MIPS16_INSERT_OPERAND (RX, *ip, lastregno);
14102 MIPS16_INSERT_OPERAND (RY, *ip, lastregno);
14113 if (c == 'v' || c == 'w')
14115 regno = mips16_to_32_reg_map[lastregno];
14129 regno = mips32_to_16_reg_map[regno];
14134 regno = ILLEGAL_REG;
14139 regno = ILLEGAL_REG;
14144 regno = ILLEGAL_REG;
14149 if (regno == AT && mips_opts.at)
14151 if (mips_opts.at == ATREG)
14152 as_warn (_("used $at without \".set noat\""));
14154 as_warn (_("used $%u with \".set at=$%u\""),
14155 regno, mips_opts.at);
14163 if (regno == ILLEGAL_REG)
14170 MIPS16_INSERT_OPERAND (RX, *ip, regno);
14174 MIPS16_INSERT_OPERAND (RY, *ip, regno);
14177 MIPS16_INSERT_OPERAND (RZ, *ip, regno);
14180 MIPS16_INSERT_OPERAND (MOVE32Z, *ip, regno);
14186 MIPS16_INSERT_OPERAND (REGR32, *ip, regno);
14189 regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3);
14190 MIPS16_INSERT_OPERAND (REG32R, *ip, regno);
14200 if (strncmp (s, "$pc", 3) == 0)
14217 i = my_getSmallExpression (&imm_expr, imm_reloc, s);
14220 if (imm_expr.X_op != O_constant)
14222 forced_insn_length = 4;
14223 ip->insn_opcode |= MIPS16_EXTEND;
14227 /* We need to relax this instruction. */
14228 *offset_reloc = *imm_reloc;
14229 *imm_reloc = (int) BFD_RELOC_UNUSED + c;
14234 *imm_reloc = BFD_RELOC_UNUSED;
14235 /* Fall through. */
14242 my_getExpression (&imm_expr, s);
14243 if (imm_expr.X_op == O_register)
14245 /* What we thought was an expression turned out to
14248 if (s[0] == '(' && args[1] == '(')
14250 /* It looks like the expression was omitted
14251 before a register indirection, which means
14252 that the expression is implicitly zero. We
14253 still set up imm_expr, so that we handle
14254 explicit extensions correctly. */
14255 imm_expr.X_op = O_constant;
14256 imm_expr.X_add_number = 0;
14257 *imm_reloc = (int) BFD_RELOC_UNUSED + c;
14264 /* We need to relax this instruction. */
14265 *imm_reloc = (int) BFD_RELOC_UNUSED + c;
14274 /* We use offset_reloc rather than imm_reloc for the PC
14275 relative operands. This lets macros with both
14276 immediate and address operands work correctly. */
14277 my_getExpression (&offset_expr, s);
14279 if (offset_expr.X_op == O_register)
14282 /* We need to relax this instruction. */
14283 *offset_reloc = (int) BFD_RELOC_UNUSED + c;
14287 case '6': /* break code */
14288 my_getExpression (&imm_expr, s);
14289 check_absolute_expr (ip, &imm_expr);
14290 if ((unsigned long) imm_expr.X_add_number > 63)
14291 as_warn (_("Invalid value for `%s' (%lu)"),
14293 (unsigned long) imm_expr.X_add_number);
14294 MIPS16_INSERT_OPERAND (IMM6, *ip, imm_expr.X_add_number);
14295 imm_expr.X_op = O_absent;
14299 case 'a': /* 26 bit address */
14300 my_getExpression (&offset_expr, s);
14302 *offset_reloc = BFD_RELOC_MIPS16_JMP;
14303 ip->insn_opcode <<= 16;
14306 case 'l': /* register list for entry macro */
14307 case 'L': /* register list for exit macro */
14317 unsigned int freg, reg1, reg2;
14319 while (*s == ' ' || *s == ',')
14321 if (reg_lookup (&s, RTYPE_GP | RTYPE_NUM, ®1))
14323 else if (reg_lookup (&s, RTYPE_FPU, ®1))
14327 as_bad (_("can't parse register list"));
14337 if (!reg_lookup (&s, freg ? RTYPE_FPU
14338 : (RTYPE_GP | RTYPE_NUM), ®2))
14340 as_bad (_("invalid register list"));
14344 if (freg && reg1 == 0 && reg2 == 0 && c == 'L')
14346 mask &= ~ (7 << 3);
14349 else if (freg && reg1 == 0 && reg2 == 1 && c == 'L')
14351 mask &= ~ (7 << 3);
14354 else if (reg1 == 4 && reg2 >= 4 && reg2 <= 7 && c != 'L')
14355 mask |= (reg2 - 3) << 3;
14356 else if (reg1 == 16 && reg2 >= 16 && reg2 <= 17)
14357 mask |= (reg2 - 15) << 1;
14358 else if (reg1 == RA && reg2 == RA)
14362 as_bad (_("invalid register list"));
14366 /* The mask is filled in in the opcode table for the
14367 benefit of the disassembler. We remove it before
14368 applying the actual mask. */
14369 ip->insn_opcode &= ~ ((7 << 3) << MIPS16OP_SH_IMM6);
14370 ip->insn_opcode |= mask << MIPS16OP_SH_IMM6;
14374 case 'm': /* Register list for save insn. */
14375 case 'M': /* Register list for restore insn. */
14377 int opcode = ip->insn_opcode;
14378 int framesz = 0, seen_framesz = 0;
14379 int nargs = 0, statics = 0, sregs = 0;
14383 unsigned int reg1, reg2;
14385 SKIP_SPACE_TABS (s);
14388 SKIP_SPACE_TABS (s);
14390 my_getExpression (&imm_expr, s);
14391 if (imm_expr.X_op == O_constant)
14393 /* Handle the frame size. */
14396 as_bad (_("more than one frame size in list"));
14400 framesz = imm_expr.X_add_number;
14401 imm_expr.X_op = O_absent;
14406 if (! reg_lookup (&s, RTYPE_GP | RTYPE_NUM, ®1))
14408 as_bad (_("can't parse register list"));
14420 if (! reg_lookup (&s, RTYPE_GP | RTYPE_NUM, ®2)
14423 as_bad (_("can't parse register list"));
14428 while (reg1 <= reg2)
14430 if (reg1 >= 4 && reg1 <= 7)
14434 nargs |= 1 << (reg1 - 4);
14436 /* statics $a0-$a3 */
14437 statics |= 1 << (reg1 - 4);
14439 else if ((reg1 >= 16 && reg1 <= 23) || reg1 == 30)
14442 sregs |= 1 << ((reg1 == 30) ? 8 : (reg1 - 16));
14444 else if (reg1 == 31)
14446 /* Add $ra to insn. */
14451 as_bad (_("unexpected register in list"));
14459 /* Encode args/statics combination. */
14460 if (nargs & statics)
14461 as_bad (_("arg/static registers overlap"));
14462 else if (nargs == 0xf)
14463 /* All $a0-$a3 are args. */
14464 opcode |= MIPS16_ALL_ARGS << 16;
14465 else if (statics == 0xf)
14466 /* All $a0-$a3 are statics. */
14467 opcode |= MIPS16_ALL_STATICS << 16;
14470 int narg = 0, nstat = 0;
14472 /* Count arg registers. */
14473 while (nargs & 0x1)
14479 as_bad (_("invalid arg register list"));
14481 /* Count static registers. */
14482 while (statics & 0x8)
14484 statics = (statics << 1) & 0xf;
14488 as_bad (_("invalid static register list"));
14490 /* Encode args/statics. */
14491 opcode |= ((narg << 2) | nstat) << 16;
14494 /* Encode $s0/$s1. */
14495 if (sregs & (1 << 0)) /* $s0 */
14497 if (sregs & (1 << 1)) /* $s1 */
14503 /* Count regs $s2-$s8. */
14511 as_bad (_("invalid static register list"));
14512 /* Encode $s2-$s8. */
14513 opcode |= nsreg << 24;
14516 /* Encode frame size. */
14518 as_bad (_("missing frame size"));
14519 else if ((framesz & 7) != 0 || framesz < 0
14520 || framesz > 0xff * 8)
14521 as_bad (_("invalid frame size"));
14522 else if (framesz != 128 || (opcode >> 16) != 0)
14525 opcode |= (((framesz & 0xf0) << 16)
14526 | (framesz & 0x0f));
14529 /* Finally build the instruction. */
14530 if ((opcode >> 16) != 0 || framesz == 0)
14531 opcode |= MIPS16_EXTEND;
14532 ip->insn_opcode = opcode;
14536 case 'e': /* extend code */
14537 my_getExpression (&imm_expr, s);
14538 check_absolute_expr (ip, &imm_expr);
14539 if ((unsigned long) imm_expr.X_add_number > 0x7ff)
14541 as_warn (_("Invalid value for `%s' (%lu)"),
14543 (unsigned long) imm_expr.X_add_number);
14544 imm_expr.X_add_number &= 0x7ff;
14546 ip->insn_opcode |= imm_expr.X_add_number;
14547 imm_expr.X_op = O_absent;
14557 /* Args don't match. */
14558 if (insn + 1 < &mips16_opcodes[bfd_mips16_num_opcodes] &&
14559 strcmp (insn->name, insn[1].name) == 0)
14566 insn_error = _("illegal operands");
14572 /* This structure holds information we know about a mips16 immediate
14575 struct mips16_immed_operand
14577 /* The type code used in the argument string in the opcode table. */
14579 /* The number of bits in the short form of the opcode. */
14581 /* The number of bits in the extended form of the opcode. */
14583 /* The amount by which the short form is shifted when it is used;
14584 for example, the sw instruction has a shift count of 2. */
14586 /* The amount by which the short form is shifted when it is stored
14587 into the instruction code. */
14589 /* Non-zero if the short form is unsigned. */
14591 /* Non-zero if the extended form is unsigned. */
14593 /* Non-zero if the value is PC relative. */
14597 /* The mips16 immediate operand types. */
14599 static const struct mips16_immed_operand mips16_immed_operands[] =
14601 { '<', 3, 5, 0, MIPS16OP_SH_RZ, 1, 1, 0 },
14602 { '>', 3, 5, 0, MIPS16OP_SH_RX, 1, 1, 0 },
14603 { '[', 3, 6, 0, MIPS16OP_SH_RZ, 1, 1, 0 },
14604 { ']', 3, 6, 0, MIPS16OP_SH_RX, 1, 1, 0 },
14605 { '4', 4, 15, 0, MIPS16OP_SH_IMM4, 0, 0, 0 },
14606 { '5', 5, 16, 0, MIPS16OP_SH_IMM5, 1, 0, 0 },
14607 { 'H', 5, 16, 1, MIPS16OP_SH_IMM5, 1, 0, 0 },
14608 { 'W', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 0 },
14609 { 'D', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 0 },
14610 { 'j', 5, 16, 0, MIPS16OP_SH_IMM5, 0, 0, 0 },
14611 { '8', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 0, 0 },
14612 { 'V', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 0 },
14613 { 'C', 8, 16, 3, MIPS16OP_SH_IMM8, 1, 0, 0 },
14614 { 'U', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 1, 0 },
14615 { 'k', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 0 },
14616 { 'K', 8, 16, 3, MIPS16OP_SH_IMM8, 0, 0, 0 },
14617 { 'p', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 },
14618 { 'q', 11, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 },
14619 { 'A', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 1 },
14620 { 'B', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 1 },
14621 { 'E', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 1 }
14624 #define MIPS16_NUM_IMMED \
14625 (sizeof mips16_immed_operands / sizeof mips16_immed_operands[0])
14627 /* Marshal immediate value VAL for an extended MIPS16 instruction.
14628 NBITS is the number of significant bits in VAL. */
14630 static unsigned long
14631 mips16_immed_extend (offsetT val, unsigned int nbits)
14636 extval = ((val >> 11) & 0x1f) | (val & 0x7e0);
14639 else if (nbits == 15)
14641 extval = ((val >> 11) & 0xf) | (val & 0x7f0);
14646 extval = ((val & 0x1f) << 6) | (val & 0x20);
14649 return (extval << 16) | val;
14652 /* Install immediate value VAL into MIPS16 instruction *INSN,
14653 extending it if necessary. The instruction in *INSN may
14654 already be extended.
14656 RELOC is the relocation that produced VAL, or BFD_RELOC_UNUSED
14657 if none. In the former case, VAL is a 16-bit number with no
14658 defined signedness.
14660 TYPE is the type of the immediate field. USER_INSN_LENGTH
14661 is the length that the user requested, or 0 if none. */
14664 mips16_immed (char *file, unsigned int line, int type,
14665 bfd_reloc_code_real_type reloc, offsetT val,
14666 unsigned int user_insn_length, unsigned long *insn)
14668 const struct mips16_immed_operand *op;
14669 int mintiny, maxtiny;
14671 op = mips16_immed_operands;
14672 while (op->type != type)
14675 gas_assert (op < mips16_immed_operands + MIPS16_NUM_IMMED);
14680 if (type == '<' || type == '>' || type == '[' || type == ']')
14683 maxtiny = 1 << op->nbits;
14688 maxtiny = (1 << op->nbits) - 1;
14690 if (reloc != BFD_RELOC_UNUSED)
14695 mintiny = - (1 << (op->nbits - 1));
14696 maxtiny = (1 << (op->nbits - 1)) - 1;
14697 if (reloc != BFD_RELOC_UNUSED)
14698 val = SEXT_16BIT (val);
14701 /* Branch offsets have an implicit 0 in the lowest bit. */
14702 if (type == 'p' || type == 'q')
14705 if ((val & ((1 << op->shift) - 1)) != 0
14706 || val < (mintiny << op->shift)
14707 || val > (maxtiny << op->shift))
14709 /* We need an extended instruction. */
14710 if (user_insn_length == 2)
14711 as_bad_where (file, line, _("invalid unextended operand value"));
14713 *insn |= MIPS16_EXTEND;
14715 else if (user_insn_length == 4)
14717 /* The operand doesn't force an unextended instruction to be extended.
14718 Warn if the user wanted an extended instruction anyway. */
14719 *insn |= MIPS16_EXTEND;
14720 as_warn_where (file, line,
14721 _("extended operand requested but not required"));
14724 if (mips16_opcode_length (*insn) == 2)
14728 insnval = ((val >> op->shift) & ((1 << op->nbits) - 1));
14729 insnval <<= op->op_shift;
14734 long minext, maxext;
14736 if (reloc == BFD_RELOC_UNUSED)
14741 maxext = (1 << op->extbits) - 1;
14745 minext = - (1 << (op->extbits - 1));
14746 maxext = (1 << (op->extbits - 1)) - 1;
14748 if (val < minext || val > maxext)
14749 as_bad_where (file, line,
14750 _("operand value out of range for instruction"));
14753 *insn |= mips16_immed_extend (val, op->extbits);
14757 struct percent_op_match
14760 bfd_reloc_code_real_type reloc;
14763 static const struct percent_op_match mips_percent_op[] =
14765 {"%lo", BFD_RELOC_LO16},
14766 {"%call_hi", BFD_RELOC_MIPS_CALL_HI16},
14767 {"%call_lo", BFD_RELOC_MIPS_CALL_LO16},
14768 {"%call16", BFD_RELOC_MIPS_CALL16},
14769 {"%got_disp", BFD_RELOC_MIPS_GOT_DISP},
14770 {"%got_page", BFD_RELOC_MIPS_GOT_PAGE},
14771 {"%got_ofst", BFD_RELOC_MIPS_GOT_OFST},
14772 {"%got_hi", BFD_RELOC_MIPS_GOT_HI16},
14773 {"%got_lo", BFD_RELOC_MIPS_GOT_LO16},
14774 {"%got", BFD_RELOC_MIPS_GOT16},
14775 {"%gp_rel", BFD_RELOC_GPREL16},
14776 {"%half", BFD_RELOC_16},
14777 {"%highest", BFD_RELOC_MIPS_HIGHEST},
14778 {"%higher", BFD_RELOC_MIPS_HIGHER},
14779 {"%neg", BFD_RELOC_MIPS_SUB},
14780 {"%tlsgd", BFD_RELOC_MIPS_TLS_GD},
14781 {"%tlsldm", BFD_RELOC_MIPS_TLS_LDM},
14782 {"%dtprel_hi", BFD_RELOC_MIPS_TLS_DTPREL_HI16},
14783 {"%dtprel_lo", BFD_RELOC_MIPS_TLS_DTPREL_LO16},
14784 {"%tprel_hi", BFD_RELOC_MIPS_TLS_TPREL_HI16},
14785 {"%tprel_lo", BFD_RELOC_MIPS_TLS_TPREL_LO16},
14786 {"%gottprel", BFD_RELOC_MIPS_TLS_GOTTPREL},
14787 {"%hi", BFD_RELOC_HI16_S}
14790 static const struct percent_op_match mips16_percent_op[] =
14792 {"%lo", BFD_RELOC_MIPS16_LO16},
14793 {"%gprel", BFD_RELOC_MIPS16_GPREL},
14794 {"%got", BFD_RELOC_MIPS16_GOT16},
14795 {"%call16", BFD_RELOC_MIPS16_CALL16},
14796 {"%hi", BFD_RELOC_MIPS16_HI16_S},
14797 {"%tlsgd", BFD_RELOC_MIPS16_TLS_GD},
14798 {"%tlsldm", BFD_RELOC_MIPS16_TLS_LDM},
14799 {"%dtprel_hi", BFD_RELOC_MIPS16_TLS_DTPREL_HI16},
14800 {"%dtprel_lo", BFD_RELOC_MIPS16_TLS_DTPREL_LO16},
14801 {"%tprel_hi", BFD_RELOC_MIPS16_TLS_TPREL_HI16},
14802 {"%tprel_lo", BFD_RELOC_MIPS16_TLS_TPREL_LO16},
14803 {"%gottprel", BFD_RELOC_MIPS16_TLS_GOTTPREL}
14807 /* Return true if *STR points to a relocation operator. When returning true,
14808 move *STR over the operator and store its relocation code in *RELOC.
14809 Leave both *STR and *RELOC alone when returning false. */
14812 parse_relocation (char **str, bfd_reloc_code_real_type *reloc)
14814 const struct percent_op_match *percent_op;
14817 if (mips_opts.mips16)
14819 percent_op = mips16_percent_op;
14820 limit = ARRAY_SIZE (mips16_percent_op);
14824 percent_op = mips_percent_op;
14825 limit = ARRAY_SIZE (mips_percent_op);
14828 for (i = 0; i < limit; i++)
14829 if (strncasecmp (*str, percent_op[i].str, strlen (percent_op[i].str)) == 0)
14831 int len = strlen (percent_op[i].str);
14833 if (!ISSPACE ((*str)[len]) && (*str)[len] != '(')
14836 *str += strlen (percent_op[i].str);
14837 *reloc = percent_op[i].reloc;
14839 /* Check whether the output BFD supports this relocation.
14840 If not, issue an error and fall back on something safe. */
14841 if (!bfd_reloc_type_lookup (stdoutput, percent_op[i].reloc))
14843 as_bad (_("relocation %s isn't supported by the current ABI"),
14844 percent_op[i].str);
14845 *reloc = BFD_RELOC_UNUSED;
14853 /* Parse string STR as a 16-bit relocatable operand. Store the
14854 expression in *EP and the relocations in the array starting
14855 at RELOC. Return the number of relocation operators used.
14857 On exit, EXPR_END points to the first character after the expression. */
14860 my_getSmallExpression (expressionS *ep, bfd_reloc_code_real_type *reloc,
14863 bfd_reloc_code_real_type reversed_reloc[3];
14864 size_t reloc_index, i;
14865 int crux_depth, str_depth;
14868 /* Search for the start of the main expression, recoding relocations
14869 in REVERSED_RELOC. End the loop with CRUX pointing to the start
14870 of the main expression and with CRUX_DEPTH containing the number
14871 of open brackets at that point. */
14878 crux_depth = str_depth;
14880 /* Skip over whitespace and brackets, keeping count of the number
14882 while (*str == ' ' || *str == '\t' || *str == '(')
14887 && reloc_index < (HAVE_NEWABI ? 3 : 1)
14888 && parse_relocation (&str, &reversed_reloc[reloc_index]));
14890 my_getExpression (ep, crux);
14893 /* Match every open bracket. */
14894 while (crux_depth > 0 && (*str == ')' || *str == ' ' || *str == '\t'))
14898 if (crux_depth > 0)
14899 as_bad (_("unclosed '('"));
14903 if (reloc_index != 0)
14905 prev_reloc_op_frag = frag_now;
14906 for (i = 0; i < reloc_index; i++)
14907 reloc[i] = reversed_reloc[reloc_index - 1 - i];
14910 return reloc_index;
14914 my_getExpression (expressionS *ep, char *str)
14918 save_in = input_line_pointer;
14919 input_line_pointer = str;
14921 expr_end = input_line_pointer;
14922 input_line_pointer = save_in;
14926 md_atof (int type, char *litP, int *sizeP)
14928 return ieee_md_atof (type, litP, sizeP, target_big_endian);
14932 md_number_to_chars (char *buf, valueT val, int n)
14934 if (target_big_endian)
14935 number_to_chars_bigendian (buf, val, n);
14937 number_to_chars_littleendian (buf, val, n);
14940 static int support_64bit_objects(void)
14942 const char **list, **l;
14945 list = bfd_target_list ();
14946 for (l = list; *l != NULL; l++)
14947 if (strcmp (*l, ELF_TARGET ("elf64-", "big")) == 0
14948 || strcmp (*l, ELF_TARGET ("elf64-", "little")) == 0)
14950 yes = (*l != NULL);
14955 /* Set STRING_PTR (either &mips_arch_string or &mips_tune_string) to
14956 NEW_VALUE. Warn if another value was already specified. Note:
14957 we have to defer parsing the -march and -mtune arguments in order
14958 to handle 'from-abi' correctly, since the ABI might be specified
14959 in a later argument. */
14962 mips_set_option_string (const char **string_ptr, const char *new_value)
14964 if (*string_ptr != 0 && strcasecmp (*string_ptr, new_value) != 0)
14965 as_warn (_("A different %s was already specified, is now %s"),
14966 string_ptr == &mips_arch_string ? "-march" : "-mtune",
14969 *string_ptr = new_value;
14973 md_parse_option (int c, char *arg)
14977 for (i = 0; i < ARRAY_SIZE (mips_ases); i++)
14978 if (c == mips_ases[i].option_on || c == mips_ases[i].option_off)
14980 file_ase_explicit |= mips_set_ase (&mips_ases[i],
14981 c == mips_ases[i].option_on);
14987 case OPTION_CONSTRUCT_FLOATS:
14988 mips_disable_float_construction = 0;
14991 case OPTION_NO_CONSTRUCT_FLOATS:
14992 mips_disable_float_construction = 1;
15004 target_big_endian = 1;
15008 target_big_endian = 0;
15014 else if (arg[0] == '0')
15016 else if (arg[0] == '1')
15026 mips_debug = atoi (arg);
15030 file_mips_isa = ISA_MIPS1;
15034 file_mips_isa = ISA_MIPS2;
15038 file_mips_isa = ISA_MIPS3;
15042 file_mips_isa = ISA_MIPS4;
15046 file_mips_isa = ISA_MIPS5;
15049 case OPTION_MIPS32:
15050 file_mips_isa = ISA_MIPS32;
15053 case OPTION_MIPS32R2:
15054 file_mips_isa = ISA_MIPS32R2;
15057 case OPTION_MIPS64R2:
15058 file_mips_isa = ISA_MIPS64R2;
15061 case OPTION_MIPS64:
15062 file_mips_isa = ISA_MIPS64;
15066 mips_set_option_string (&mips_tune_string, arg);
15070 mips_set_option_string (&mips_arch_string, arg);
15074 mips_set_option_string (&mips_arch_string, "4650");
15075 mips_set_option_string (&mips_tune_string, "4650");
15078 case OPTION_NO_M4650:
15082 mips_set_option_string (&mips_arch_string, "4010");
15083 mips_set_option_string (&mips_tune_string, "4010");
15086 case OPTION_NO_M4010:
15090 mips_set_option_string (&mips_arch_string, "4100");
15091 mips_set_option_string (&mips_tune_string, "4100");
15094 case OPTION_NO_M4100:
15098 mips_set_option_string (&mips_arch_string, "3900");
15099 mips_set_option_string (&mips_tune_string, "3900");
15102 case OPTION_NO_M3900:
15105 case OPTION_MICROMIPS:
15106 if (mips_opts.mips16 == 1)
15108 as_bad (_("-mmicromips cannot be used with -mips16"));
15111 mips_opts.micromips = 1;
15112 mips_no_prev_insn ();
15115 case OPTION_NO_MICROMIPS:
15116 mips_opts.micromips = 0;
15117 mips_no_prev_insn ();
15120 case OPTION_MIPS16:
15121 if (mips_opts.micromips == 1)
15123 as_bad (_("-mips16 cannot be used with -micromips"));
15126 mips_opts.mips16 = 1;
15127 mips_no_prev_insn ();
15130 case OPTION_NO_MIPS16:
15131 mips_opts.mips16 = 0;
15132 mips_no_prev_insn ();
15135 case OPTION_FIX_24K:
15139 case OPTION_NO_FIX_24K:
15143 case OPTION_FIX_LOONGSON2F_JUMP:
15144 mips_fix_loongson2f_jump = TRUE;
15147 case OPTION_NO_FIX_LOONGSON2F_JUMP:
15148 mips_fix_loongson2f_jump = FALSE;
15151 case OPTION_FIX_LOONGSON2F_NOP:
15152 mips_fix_loongson2f_nop = TRUE;
15155 case OPTION_NO_FIX_LOONGSON2F_NOP:
15156 mips_fix_loongson2f_nop = FALSE;
15159 case OPTION_FIX_VR4120:
15160 mips_fix_vr4120 = 1;
15163 case OPTION_NO_FIX_VR4120:
15164 mips_fix_vr4120 = 0;
15167 case OPTION_FIX_VR4130:
15168 mips_fix_vr4130 = 1;
15171 case OPTION_NO_FIX_VR4130:
15172 mips_fix_vr4130 = 0;
15175 case OPTION_FIX_CN63XXP1:
15176 mips_fix_cn63xxp1 = TRUE;
15179 case OPTION_NO_FIX_CN63XXP1:
15180 mips_fix_cn63xxp1 = FALSE;
15183 case OPTION_RELAX_BRANCH:
15184 mips_relax_branch = 1;
15187 case OPTION_NO_RELAX_BRANCH:
15188 mips_relax_branch = 0;
15191 case OPTION_MSHARED:
15192 mips_in_shared = TRUE;
15195 case OPTION_MNO_SHARED:
15196 mips_in_shared = FALSE;
15199 case OPTION_MSYM32:
15200 mips_opts.sym32 = TRUE;
15203 case OPTION_MNO_SYM32:
15204 mips_opts.sym32 = FALSE;
15207 /* When generating ELF code, we permit -KPIC and -call_shared to
15208 select SVR4_PIC, and -non_shared to select no PIC. This is
15209 intended to be compatible with Irix 5. */
15210 case OPTION_CALL_SHARED:
15211 mips_pic = SVR4_PIC;
15212 mips_abicalls = TRUE;
15215 case OPTION_CALL_NONPIC:
15217 mips_abicalls = TRUE;
15220 case OPTION_NON_SHARED:
15222 mips_abicalls = FALSE;
15225 /* The -xgot option tells the assembler to use 32 bit offsets
15226 when accessing the got in SVR4_PIC mode. It is for Irix
15233 g_switch_value = atoi (arg);
15237 /* The -32, -n32 and -64 options are shortcuts for -mabi=32, -mabi=n32
15240 mips_abi = O32_ABI;
15244 mips_abi = N32_ABI;
15248 mips_abi = N64_ABI;
15249 if (!support_64bit_objects())
15250 as_fatal (_("No compiled in support for 64 bit object file format"));
15254 file_mips_gp32 = 1;
15258 file_mips_gp32 = 0;
15262 file_mips_fp32 = 1;
15266 file_mips_fp32 = 0;
15269 case OPTION_SINGLE_FLOAT:
15270 file_mips_single_float = 1;
15273 case OPTION_DOUBLE_FLOAT:
15274 file_mips_single_float = 0;
15277 case OPTION_SOFT_FLOAT:
15278 file_mips_soft_float = 1;
15281 case OPTION_HARD_FLOAT:
15282 file_mips_soft_float = 0;
15286 if (strcmp (arg, "32") == 0)
15287 mips_abi = O32_ABI;
15288 else if (strcmp (arg, "o64") == 0)
15289 mips_abi = O64_ABI;
15290 else if (strcmp (arg, "n32") == 0)
15291 mips_abi = N32_ABI;
15292 else if (strcmp (arg, "64") == 0)
15294 mips_abi = N64_ABI;
15295 if (! support_64bit_objects())
15296 as_fatal (_("No compiled in support for 64 bit object file "
15299 else if (strcmp (arg, "eabi") == 0)
15300 mips_abi = EABI_ABI;
15303 as_fatal (_("invalid abi -mabi=%s"), arg);
15308 case OPTION_M7000_HILO_FIX:
15309 mips_7000_hilo_fix = TRUE;
15312 case OPTION_MNO_7000_HILO_FIX:
15313 mips_7000_hilo_fix = FALSE;
15316 case OPTION_MDEBUG:
15317 mips_flag_mdebug = TRUE;
15320 case OPTION_NO_MDEBUG:
15321 mips_flag_mdebug = FALSE;
15325 mips_flag_pdr = TRUE;
15328 case OPTION_NO_PDR:
15329 mips_flag_pdr = FALSE;
15332 case OPTION_MVXWORKS_PIC:
15333 mips_pic = VXWORKS_PIC;
15340 mips_fix_loongson2f = mips_fix_loongson2f_nop || mips_fix_loongson2f_jump;
15345 /* Set up globals to generate code for the ISA or processor
15346 described by INFO. */
15349 mips_set_architecture (const struct mips_cpu_info *info)
15353 file_mips_arch = info->cpu;
15354 mips_opts.arch = info->cpu;
15355 mips_opts.isa = info->isa;
15360 /* Likewise for tuning. */
15363 mips_set_tune (const struct mips_cpu_info *info)
15366 mips_tune = info->cpu;
15371 mips_after_parse_args (void)
15373 const struct mips_cpu_info *arch_info = 0;
15374 const struct mips_cpu_info *tune_info = 0;
15376 /* GP relative stuff not working for PE */
15377 if (strncmp (TARGET_OS, "pe", 2) == 0)
15379 if (g_switch_seen && g_switch_value != 0)
15380 as_bad (_("-G not supported in this configuration."));
15381 g_switch_value = 0;
15384 if (mips_abi == NO_ABI)
15385 mips_abi = MIPS_DEFAULT_ABI;
15387 /* The following code determines the architecture and register size.
15388 Similar code was added to GCC 3.3 (see override_options() in
15389 config/mips/mips.c). The GAS and GCC code should be kept in sync
15390 as much as possible. */
15392 if (mips_arch_string != 0)
15393 arch_info = mips_parse_cpu ("-march", mips_arch_string);
15395 if (file_mips_isa != ISA_UNKNOWN)
15397 /* Handle -mipsN. At this point, file_mips_isa contains the
15398 ISA level specified by -mipsN, while arch_info->isa contains
15399 the -march selection (if any). */
15400 if (arch_info != 0)
15402 /* -march takes precedence over -mipsN, since it is more descriptive.
15403 There's no harm in specifying both as long as the ISA levels
15405 if (file_mips_isa != arch_info->isa)
15406 as_bad (_("-%s conflicts with the other architecture options, which imply -%s"),
15407 mips_cpu_info_from_isa (file_mips_isa)->name,
15408 mips_cpu_info_from_isa (arch_info->isa)->name);
15411 arch_info = mips_cpu_info_from_isa (file_mips_isa);
15414 if (arch_info == 0)
15416 arch_info = mips_parse_cpu ("default CPU", MIPS_CPU_STRING_DEFAULT);
15417 gas_assert (arch_info);
15420 if (ABI_NEEDS_64BIT_REGS (mips_abi) && !ISA_HAS_64BIT_REGS (arch_info->isa))
15421 as_bad (_("-march=%s is not compatible with the selected ABI"),
15424 mips_set_architecture (arch_info);
15426 /* Optimize for file_mips_arch, unless -mtune selects a different processor. */
15427 if (mips_tune_string != 0)
15428 tune_info = mips_parse_cpu ("-mtune", mips_tune_string);
15430 if (tune_info == 0)
15431 mips_set_tune (arch_info);
15433 mips_set_tune (tune_info);
15435 if (file_mips_gp32 >= 0)
15437 /* The user specified the size of the integer registers. Make sure
15438 it agrees with the ABI and ISA. */
15439 if (file_mips_gp32 == 0 && !ISA_HAS_64BIT_REGS (mips_opts.isa))
15440 as_bad (_("-mgp64 used with a 32-bit processor"));
15441 else if (file_mips_gp32 == 1 && ABI_NEEDS_64BIT_REGS (mips_abi))
15442 as_bad (_("-mgp32 used with a 64-bit ABI"));
15443 else if (file_mips_gp32 == 0 && ABI_NEEDS_32BIT_REGS (mips_abi))
15444 as_bad (_("-mgp64 used with a 32-bit ABI"));
15448 /* Infer the integer register size from the ABI and processor.
15449 Restrict ourselves to 32-bit registers if that's all the
15450 processor has, or if the ABI cannot handle 64-bit registers. */
15451 file_mips_gp32 = (ABI_NEEDS_32BIT_REGS (mips_abi)
15452 || !ISA_HAS_64BIT_REGS (mips_opts.isa));
15455 switch (file_mips_fp32)
15459 /* No user specified float register size.
15460 ??? GAS treats single-float processors as though they had 64-bit
15461 float registers (although it complains when double-precision
15462 instructions are used). As things stand, saying they have 32-bit
15463 registers would lead to spurious "register must be even" messages.
15464 So here we assume float registers are never smaller than the
15466 if (file_mips_gp32 == 0)
15467 /* 64-bit integer registers implies 64-bit float registers. */
15468 file_mips_fp32 = 0;
15469 else if ((mips_opts.ase & FP64_ASES)
15470 && ISA_HAS_64BIT_FPRS (mips_opts.isa))
15471 /* -mips3d and -mdmx imply 64-bit float registers, if possible. */
15472 file_mips_fp32 = 0;
15474 /* 32-bit float registers. */
15475 file_mips_fp32 = 1;
15478 /* The user specified the size of the float registers. Check if it
15479 agrees with the ABI and ISA. */
15481 if (!ISA_HAS_64BIT_FPRS (mips_opts.isa))
15482 as_bad (_("-mfp64 used with a 32-bit fpu"));
15483 else if (ABI_NEEDS_32BIT_REGS (mips_abi)
15484 && !ISA_HAS_MXHC1 (mips_opts.isa))
15485 as_warn (_("-mfp64 used with a 32-bit ABI"));
15488 if (ABI_NEEDS_64BIT_REGS (mips_abi))
15489 as_warn (_("-mfp32 used with a 64-bit ABI"));
15493 /* End of GCC-shared inference code. */
15495 /* This flag is set when we have a 64-bit capable CPU but use only
15496 32-bit wide registers. Note that EABI does not use it. */
15497 if (ISA_HAS_64BIT_REGS (mips_opts.isa)
15498 && ((mips_abi == NO_ABI && file_mips_gp32 == 1)
15499 || mips_abi == O32_ABI))
15500 mips_32bitmode = 1;
15502 if (mips_opts.isa == ISA_MIPS1 && mips_trap)
15503 as_bad (_("trap exception not supported at ISA 1"));
15505 /* If the selected architecture includes support for ASEs, enable
15506 generation of code for them. */
15507 if (mips_opts.mips16 == -1)
15508 mips_opts.mips16 = (CPU_HAS_MIPS16 (file_mips_arch)) ? 1 : 0;
15509 if (mips_opts.micromips == -1)
15510 mips_opts.micromips = (CPU_HAS_MICROMIPS (file_mips_arch)) ? 1 : 0;
15512 /* MIPS3D and MDMX require 64-bit FPRs, so -mfp32 should stop those
15513 ASEs from being selected implicitly. */
15514 if (file_mips_fp32 == 1)
15515 file_ase_explicit |= ASE_MIPS3D | ASE_MDMX;
15517 /* If the user didn't explicitly select or deselect a particular ASE,
15518 use the default setting for the CPU. */
15519 mips_opts.ase |= (arch_info->ase & ~file_ase_explicit);
15521 file_mips_isa = mips_opts.isa;
15522 file_ase = mips_opts.ase;
15523 mips_opts.gp32 = file_mips_gp32;
15524 mips_opts.fp32 = file_mips_fp32;
15525 mips_opts.soft_float = file_mips_soft_float;
15526 mips_opts.single_float = file_mips_single_float;
15528 mips_check_isa_supports_ases ();
15530 if (mips_flag_mdebug < 0)
15531 mips_flag_mdebug = 0;
15535 mips_init_after_args (void)
15537 /* initialize opcodes */
15538 bfd_mips_num_opcodes = bfd_mips_num_builtin_opcodes;
15539 mips_opcodes = (struct mips_opcode *) mips_builtin_opcodes;
15543 md_pcrel_from (fixS *fixP)
15545 valueT addr = fixP->fx_where + fixP->fx_frag->fr_address;
15546 switch (fixP->fx_r_type)
15548 case BFD_RELOC_MICROMIPS_7_PCREL_S1:
15549 case BFD_RELOC_MICROMIPS_10_PCREL_S1:
15550 /* Return the address of the delay slot. */
15553 case BFD_RELOC_MICROMIPS_16_PCREL_S1:
15554 case BFD_RELOC_MICROMIPS_JMP:
15555 case BFD_RELOC_16_PCREL_S2:
15556 case BFD_RELOC_MIPS_JMP:
15557 /* Return the address of the delay slot. */
15560 case BFD_RELOC_32_PCREL:
15564 /* We have no relocation type for PC relative MIPS16 instructions. */
15565 if (fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != now_seg)
15566 as_bad_where (fixP->fx_file, fixP->fx_line,
15567 _("PC relative MIPS16 instruction references a different section"));
15572 /* This is called before the symbol table is processed. In order to
15573 work with gcc when using mips-tfile, we must keep all local labels.
15574 However, in other cases, we want to discard them. If we were
15575 called with -g, but we didn't see any debugging information, it may
15576 mean that gcc is smuggling debugging information through to
15577 mips-tfile, in which case we must generate all local labels. */
15580 mips_frob_file_before_adjust (void)
15582 #ifndef NO_ECOFF_DEBUGGING
15583 if (ECOFF_DEBUGGING
15585 && ! ecoff_debugging_seen)
15586 flag_keep_locals = 1;
15590 /* Sort any unmatched HI16 and GOT16 relocs so that they immediately precede
15591 the corresponding LO16 reloc. This is called before md_apply_fix and
15592 tc_gen_reloc. Unmatched relocs can only be generated by use of explicit
15593 relocation operators.
15595 For our purposes, a %lo() expression matches a %got() or %hi()
15598 (a) it refers to the same symbol; and
15599 (b) the offset applied in the %lo() expression is no lower than
15600 the offset applied in the %got() or %hi().
15602 (b) allows us to cope with code like:
15605 lh $4,%lo(foo+2)($4)
15607 ...which is legal on RELA targets, and has a well-defined behaviour
15608 if the user knows that adding 2 to "foo" will not induce a carry to
15611 When several %lo()s match a particular %got() or %hi(), we use the
15612 following rules to distinguish them:
15614 (1) %lo()s with smaller offsets are a better match than %lo()s with
15617 (2) %lo()s with no matching %got() or %hi() are better than those
15618 that already have a matching %got() or %hi().
15620 (3) later %lo()s are better than earlier %lo()s.
15622 These rules are applied in order.
15624 (1) means, among other things, that %lo()s with identical offsets are
15625 chosen if they exist.
15627 (2) means that we won't associate several high-part relocations with
15628 the same low-part relocation unless there's no alternative. Having
15629 several high parts for the same low part is a GNU extension; this rule
15630 allows careful users to avoid it.
15632 (3) is purely cosmetic. mips_hi_fixup_list is is in reverse order,
15633 with the last high-part relocation being at the front of the list.
15634 It therefore makes sense to choose the last matching low-part
15635 relocation, all other things being equal. It's also easier
15636 to code that way. */
15639 mips_frob_file (void)
15641 struct mips_hi_fixup *l;
15642 bfd_reloc_code_real_type looking_for_rtype = BFD_RELOC_UNUSED;
15644 for (l = mips_hi_fixup_list; l != NULL; l = l->next)
15646 segment_info_type *seginfo;
15647 bfd_boolean matched_lo_p;
15648 fixS **hi_pos, **lo_pos, **pos;
15650 gas_assert (reloc_needs_lo_p (l->fixp->fx_r_type));
15652 /* If a GOT16 relocation turns out to be against a global symbol,
15653 there isn't supposed to be a matching LO. Ignore %gots against
15654 constants; we'll report an error for those later. */
15655 if (got16_reloc_p (l->fixp->fx_r_type)
15656 && !(l->fixp->fx_addsy
15657 && pic_need_relax (l->fixp->fx_addsy, l->seg)))
15660 /* Check quickly whether the next fixup happens to be a matching %lo. */
15661 if (fixup_has_matching_lo_p (l->fixp))
15664 seginfo = seg_info (l->seg);
15666 /* Set HI_POS to the position of this relocation in the chain.
15667 Set LO_POS to the position of the chosen low-part relocation.
15668 MATCHED_LO_P is true on entry to the loop if *POS is a low-part
15669 relocation that matches an immediately-preceding high-part
15673 matched_lo_p = FALSE;
15674 looking_for_rtype = matching_lo_reloc (l->fixp->fx_r_type);
15676 for (pos = &seginfo->fix_root; *pos != NULL; pos = &(*pos)->fx_next)
15678 if (*pos == l->fixp)
15681 if ((*pos)->fx_r_type == looking_for_rtype
15682 && symbol_same_p ((*pos)->fx_addsy, l->fixp->fx_addsy)
15683 && (*pos)->fx_offset >= l->fixp->fx_offset
15685 || (*pos)->fx_offset < (*lo_pos)->fx_offset
15687 && (*pos)->fx_offset == (*lo_pos)->fx_offset)))
15690 matched_lo_p = (reloc_needs_lo_p ((*pos)->fx_r_type)
15691 && fixup_has_matching_lo_p (*pos));
15694 /* If we found a match, remove the high-part relocation from its
15695 current position and insert it before the low-part relocation.
15696 Make the offsets match so that fixup_has_matching_lo_p()
15699 We don't warn about unmatched high-part relocations since some
15700 versions of gcc have been known to emit dead "lui ...%hi(...)"
15702 if (lo_pos != NULL)
15704 l->fixp->fx_offset = (*lo_pos)->fx_offset;
15705 if (l->fixp->fx_next != *lo_pos)
15707 *hi_pos = l->fixp->fx_next;
15708 l->fixp->fx_next = *lo_pos;
15716 mips_force_relocation (fixS *fixp)
15718 if (generic_force_reloc (fixp))
15721 /* We want to keep BFD_RELOC_MICROMIPS_*_PCREL_S1 relocation,
15722 so that the linker relaxation can update targets. */
15723 if (fixp->fx_r_type == BFD_RELOC_MICROMIPS_7_PCREL_S1
15724 || fixp->fx_r_type == BFD_RELOC_MICROMIPS_10_PCREL_S1
15725 || fixp->fx_r_type == BFD_RELOC_MICROMIPS_16_PCREL_S1)
15731 /* Read the instruction associated with RELOC from BUF. */
15733 static unsigned int
15734 read_reloc_insn (char *buf, bfd_reloc_code_real_type reloc)
15736 if (mips16_reloc_p (reloc) || micromips_reloc_p (reloc))
15737 return read_compressed_insn (buf, 4);
15739 return read_insn (buf);
15742 /* Write instruction INSN to BUF, given that it has been relocated
15746 write_reloc_insn (char *buf, bfd_reloc_code_real_type reloc,
15747 unsigned long insn)
15749 if (mips16_reloc_p (reloc) || micromips_reloc_p (reloc))
15750 write_compressed_insn (buf, insn, 4);
15752 write_insn (buf, insn);
15755 /* Apply a fixup to the object file. */
15758 md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
15761 unsigned long insn;
15762 reloc_howto_type *howto;
15764 /* We ignore generic BFD relocations we don't know about. */
15765 howto = bfd_reloc_type_lookup (stdoutput, fixP->fx_r_type);
15769 gas_assert (fixP->fx_size == 2
15770 || fixP->fx_size == 4
15771 || fixP->fx_r_type == BFD_RELOC_16
15772 || fixP->fx_r_type == BFD_RELOC_64
15773 || fixP->fx_r_type == BFD_RELOC_CTOR
15774 || fixP->fx_r_type == BFD_RELOC_MIPS_SUB
15775 || fixP->fx_r_type == BFD_RELOC_MICROMIPS_SUB
15776 || fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
15777 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY
15778 || fixP->fx_r_type == BFD_RELOC_MIPS_TLS_DTPREL64);
15780 buf = fixP->fx_frag->fr_literal + fixP->fx_where;
15782 gas_assert (!fixP->fx_pcrel || fixP->fx_r_type == BFD_RELOC_16_PCREL_S2
15783 || fixP->fx_r_type == BFD_RELOC_MICROMIPS_7_PCREL_S1
15784 || fixP->fx_r_type == BFD_RELOC_MICROMIPS_10_PCREL_S1
15785 || fixP->fx_r_type == BFD_RELOC_MICROMIPS_16_PCREL_S1
15786 || fixP->fx_r_type == BFD_RELOC_32_PCREL);
15788 /* Don't treat parts of a composite relocation as done. There are two
15791 (1) The second and third parts will be against 0 (RSS_UNDEF) but
15792 should nevertheless be emitted if the first part is.
15794 (2) In normal usage, composite relocations are never assembly-time
15795 constants. The easiest way of dealing with the pathological
15796 exceptions is to generate a relocation against STN_UNDEF and
15797 leave everything up to the linker. */
15798 if (fixP->fx_addsy == NULL && !fixP->fx_pcrel && fixP->fx_tcbit == 0)
15801 switch (fixP->fx_r_type)
15803 case BFD_RELOC_MIPS_TLS_GD:
15804 case BFD_RELOC_MIPS_TLS_LDM:
15805 case BFD_RELOC_MIPS_TLS_DTPREL32:
15806 case BFD_RELOC_MIPS_TLS_DTPREL64:
15807 case BFD_RELOC_MIPS_TLS_DTPREL_HI16:
15808 case BFD_RELOC_MIPS_TLS_DTPREL_LO16:
15809 case BFD_RELOC_MIPS_TLS_GOTTPREL:
15810 case BFD_RELOC_MIPS_TLS_TPREL32:
15811 case BFD_RELOC_MIPS_TLS_TPREL64:
15812 case BFD_RELOC_MIPS_TLS_TPREL_HI16:
15813 case BFD_RELOC_MIPS_TLS_TPREL_LO16:
15814 case BFD_RELOC_MICROMIPS_TLS_GD:
15815 case BFD_RELOC_MICROMIPS_TLS_LDM:
15816 case BFD_RELOC_MICROMIPS_TLS_DTPREL_HI16:
15817 case BFD_RELOC_MICROMIPS_TLS_DTPREL_LO16:
15818 case BFD_RELOC_MICROMIPS_TLS_GOTTPREL:
15819 case BFD_RELOC_MICROMIPS_TLS_TPREL_HI16:
15820 case BFD_RELOC_MICROMIPS_TLS_TPREL_LO16:
15821 case BFD_RELOC_MIPS16_TLS_GD:
15822 case BFD_RELOC_MIPS16_TLS_LDM:
15823 case BFD_RELOC_MIPS16_TLS_DTPREL_HI16:
15824 case BFD_RELOC_MIPS16_TLS_DTPREL_LO16:
15825 case BFD_RELOC_MIPS16_TLS_GOTTPREL:
15826 case BFD_RELOC_MIPS16_TLS_TPREL_HI16:
15827 case BFD_RELOC_MIPS16_TLS_TPREL_LO16:
15828 if (!fixP->fx_addsy)
15830 as_bad_where (fixP->fx_file, fixP->fx_line,
15831 _("TLS relocation against a constant"));
15834 S_SET_THREAD_LOCAL (fixP->fx_addsy);
15837 case BFD_RELOC_MIPS_JMP:
15838 case BFD_RELOC_MIPS_SHIFT5:
15839 case BFD_RELOC_MIPS_SHIFT6:
15840 case BFD_RELOC_MIPS_GOT_DISP:
15841 case BFD_RELOC_MIPS_GOT_PAGE:
15842 case BFD_RELOC_MIPS_GOT_OFST:
15843 case BFD_RELOC_MIPS_SUB:
15844 case BFD_RELOC_MIPS_INSERT_A:
15845 case BFD_RELOC_MIPS_INSERT_B:
15846 case BFD_RELOC_MIPS_DELETE:
15847 case BFD_RELOC_MIPS_HIGHEST:
15848 case BFD_RELOC_MIPS_HIGHER:
15849 case BFD_RELOC_MIPS_SCN_DISP:
15850 case BFD_RELOC_MIPS_REL16:
15851 case BFD_RELOC_MIPS_RELGOT:
15852 case BFD_RELOC_MIPS_JALR:
15853 case BFD_RELOC_HI16:
15854 case BFD_RELOC_HI16_S:
15855 case BFD_RELOC_LO16:
15856 case BFD_RELOC_GPREL16:
15857 case BFD_RELOC_MIPS_LITERAL:
15858 case BFD_RELOC_MIPS_CALL16:
15859 case BFD_RELOC_MIPS_GOT16:
15860 case BFD_RELOC_GPREL32:
15861 case BFD_RELOC_MIPS_GOT_HI16:
15862 case BFD_RELOC_MIPS_GOT_LO16:
15863 case BFD_RELOC_MIPS_CALL_HI16:
15864 case BFD_RELOC_MIPS_CALL_LO16:
15865 case BFD_RELOC_MIPS16_GPREL:
15866 case BFD_RELOC_MIPS16_GOT16:
15867 case BFD_RELOC_MIPS16_CALL16:
15868 case BFD_RELOC_MIPS16_HI16:
15869 case BFD_RELOC_MIPS16_HI16_S:
15870 case BFD_RELOC_MIPS16_LO16:
15871 case BFD_RELOC_MIPS16_JMP:
15872 case BFD_RELOC_MICROMIPS_JMP:
15873 case BFD_RELOC_MICROMIPS_GOT_DISP:
15874 case BFD_RELOC_MICROMIPS_GOT_PAGE:
15875 case BFD_RELOC_MICROMIPS_GOT_OFST:
15876 case BFD_RELOC_MICROMIPS_SUB:
15877 case BFD_RELOC_MICROMIPS_HIGHEST:
15878 case BFD_RELOC_MICROMIPS_HIGHER:
15879 case BFD_RELOC_MICROMIPS_SCN_DISP:
15880 case BFD_RELOC_MICROMIPS_JALR:
15881 case BFD_RELOC_MICROMIPS_HI16:
15882 case BFD_RELOC_MICROMIPS_HI16_S:
15883 case BFD_RELOC_MICROMIPS_LO16:
15884 case BFD_RELOC_MICROMIPS_GPREL16:
15885 case BFD_RELOC_MICROMIPS_LITERAL:
15886 case BFD_RELOC_MICROMIPS_CALL16:
15887 case BFD_RELOC_MICROMIPS_GOT16:
15888 case BFD_RELOC_MICROMIPS_GOT_HI16:
15889 case BFD_RELOC_MICROMIPS_GOT_LO16:
15890 case BFD_RELOC_MICROMIPS_CALL_HI16:
15891 case BFD_RELOC_MICROMIPS_CALL_LO16:
15892 case BFD_RELOC_MIPS_EH:
15897 if (calculate_reloc (fixP->fx_r_type, *valP, &value))
15899 insn = read_reloc_insn (buf, fixP->fx_r_type);
15900 if (mips16_reloc_p (fixP->fx_r_type))
15901 insn |= mips16_immed_extend (value, 16);
15903 insn |= (value & 0xffff);
15904 write_reloc_insn (buf, fixP->fx_r_type, insn);
15907 as_bad_where (fixP->fx_file, fixP->fx_line,
15908 _("Unsupported constant in relocation"));
15913 /* This is handled like BFD_RELOC_32, but we output a sign
15914 extended value if we are only 32 bits. */
15917 if (8 <= sizeof (valueT))
15918 md_number_to_chars (buf, *valP, 8);
15923 if ((*valP & 0x80000000) != 0)
15927 md_number_to_chars (buf + (target_big_endian ? 4 : 0), *valP, 4);
15928 md_number_to_chars (buf + (target_big_endian ? 0 : 4), hiv, 4);
15933 case BFD_RELOC_RVA:
15935 case BFD_RELOC_32_PCREL:
15937 /* If we are deleting this reloc entry, we must fill in the
15938 value now. This can happen if we have a .word which is not
15939 resolved when it appears but is later defined. */
15941 md_number_to_chars (buf, *valP, fixP->fx_size);
15944 case BFD_RELOC_16_PCREL_S2:
15945 if ((*valP & 0x3) != 0)
15946 as_bad_where (fixP->fx_file, fixP->fx_line,
15947 _("Branch to misaligned address (%lx)"), (long) *valP);
15949 /* We need to save the bits in the instruction since fixup_segment()
15950 might be deleting the relocation entry (i.e., a branch within
15951 the current segment). */
15952 if (! fixP->fx_done)
15955 /* Update old instruction data. */
15956 insn = read_insn (buf);
15958 if (*valP + 0x20000 <= 0x3ffff)
15960 insn |= (*valP >> 2) & 0xffff;
15961 write_insn (buf, insn);
15963 else if (mips_pic == NO_PIC
15965 && fixP->fx_frag->fr_address >= text_section->vma
15966 && (fixP->fx_frag->fr_address
15967 < text_section->vma + bfd_get_section_size (text_section))
15968 && ((insn & 0xffff0000) == 0x10000000 /* beq $0,$0 */
15969 || (insn & 0xffff0000) == 0x04010000 /* bgez $0 */
15970 || (insn & 0xffff0000) == 0x04110000)) /* bgezal $0 */
15972 /* The branch offset is too large. If this is an
15973 unconditional branch, and we are not generating PIC code,
15974 we can convert it to an absolute jump instruction. */
15975 if ((insn & 0xffff0000) == 0x04110000) /* bgezal $0 */
15976 insn = 0x0c000000; /* jal */
15978 insn = 0x08000000; /* j */
15979 fixP->fx_r_type = BFD_RELOC_MIPS_JMP;
15981 fixP->fx_addsy = section_symbol (text_section);
15982 *valP += md_pcrel_from (fixP);
15983 write_insn (buf, insn);
15987 /* If we got here, we have branch-relaxation disabled,
15988 and there's nothing we can do to fix this instruction
15989 without turning it into a longer sequence. */
15990 as_bad_where (fixP->fx_file, fixP->fx_line,
15991 _("Branch out of range"));
15995 case BFD_RELOC_MICROMIPS_7_PCREL_S1:
15996 case BFD_RELOC_MICROMIPS_10_PCREL_S1:
15997 case BFD_RELOC_MICROMIPS_16_PCREL_S1:
15998 /* We adjust the offset back to even. */
15999 if ((*valP & 0x1) != 0)
16002 if (! fixP->fx_done)
16005 /* Should never visit here, because we keep the relocation. */
16009 case BFD_RELOC_VTABLE_INHERIT:
16012 && !S_IS_DEFINED (fixP->fx_addsy)
16013 && !S_IS_WEAK (fixP->fx_addsy))
16014 S_SET_WEAK (fixP->fx_addsy);
16017 case BFD_RELOC_VTABLE_ENTRY:
16025 /* Remember value for tc_gen_reloc. */
16026 fixP->fx_addnumber = *valP;
16036 name = input_line_pointer;
16037 c = get_symbol_end ();
16038 p = (symbolS *) symbol_find_or_make (name);
16039 *input_line_pointer = c;
16043 /* Align the current frag to a given power of two. If a particular
16044 fill byte should be used, FILL points to an integer that contains
16045 that byte, otherwise FILL is null.
16047 This function used to have the comment:
16049 The MIPS assembler also automatically adjusts any preceding label.
16051 The implementation therefore applied the adjustment to a maximum of
16052 one label. However, other label adjustments are applied to batches
16053 of labels, and adjusting just one caused problems when new labels
16054 were added for the sake of debugging or unwind information.
16055 We therefore adjust all preceding labels (given as LABELS) instead. */
16058 mips_align (int to, int *fill, struct insn_label_list *labels)
16060 mips_emit_delays ();
16061 mips_record_compressed_mode ();
16062 if (fill == NULL && subseg_text_p (now_seg))
16063 frag_align_code (to, 0);
16065 frag_align (to, fill ? *fill : 0, 0);
16066 record_alignment (now_seg, to);
16067 mips_move_labels (labels, FALSE);
16070 /* Align to a given power of two. .align 0 turns off the automatic
16071 alignment used by the data creating pseudo-ops. */
16074 s_align (int x ATTRIBUTE_UNUSED)
16076 int temp, fill_value, *fill_ptr;
16077 long max_alignment = 28;
16079 /* o Note that the assembler pulls down any immediately preceding label
16080 to the aligned address.
16081 o It's not documented but auto alignment is reinstated by
16082 a .align pseudo instruction.
16083 o Note also that after auto alignment is turned off the mips assembler
16084 issues an error on attempt to assemble an improperly aligned data item.
16087 temp = get_absolute_expression ();
16088 if (temp > max_alignment)
16089 as_bad (_("Alignment too large: %d. assumed."), temp = max_alignment);
16092 as_warn (_("Alignment negative: 0 assumed."));
16095 if (*input_line_pointer == ',')
16097 ++input_line_pointer;
16098 fill_value = get_absolute_expression ();
16099 fill_ptr = &fill_value;
16105 segment_info_type *si = seg_info (now_seg);
16106 struct insn_label_list *l = si->label_list;
16107 /* Auto alignment should be switched on by next section change. */
16109 mips_align (temp, fill_ptr, l);
16116 demand_empty_rest_of_line ();
16120 s_change_sec (int sec)
16124 /* The ELF backend needs to know that we are changing sections, so
16125 that .previous works correctly. We could do something like check
16126 for an obj_section_change_hook macro, but that might be confusing
16127 as it would not be appropriate to use it in the section changing
16128 functions in read.c, since obj-elf.c intercepts those. FIXME:
16129 This should be cleaner, somehow. */
16130 obj_elf_section_change_hook ();
16132 mips_emit_delays ();
16143 subseg_set (bss_section, (subsegT) get_absolute_expression ());
16144 demand_empty_rest_of_line ();
16148 seg = subseg_new (RDATA_SECTION_NAME,
16149 (subsegT) get_absolute_expression ());
16150 bfd_set_section_flags (stdoutput, seg, (SEC_ALLOC | SEC_LOAD
16151 | SEC_READONLY | SEC_RELOC
16153 if (strncmp (TARGET_OS, "elf", 3) != 0)
16154 record_alignment (seg, 4);
16155 demand_empty_rest_of_line ();
16159 seg = subseg_new (".sdata", (subsegT) get_absolute_expression ());
16160 bfd_set_section_flags (stdoutput, seg,
16161 SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_DATA);
16162 if (strncmp (TARGET_OS, "elf", 3) != 0)
16163 record_alignment (seg, 4);
16164 demand_empty_rest_of_line ();
16168 seg = subseg_new (".sbss", (subsegT) get_absolute_expression ());
16169 bfd_set_section_flags (stdoutput, seg, SEC_ALLOC);
16170 if (strncmp (TARGET_OS, "elf", 3) != 0)
16171 record_alignment (seg, 4);
16172 demand_empty_rest_of_line ();
16180 s_change_section (int ignore ATTRIBUTE_UNUSED)
16182 char *section_name;
16187 int section_entry_size;
16188 int section_alignment;
16190 section_name = input_line_pointer;
16191 c = get_symbol_end ();
16193 next_c = *(input_line_pointer + 1);
16195 /* Do we have .section Name<,"flags">? */
16196 if (c != ',' || (c == ',' && next_c == '"'))
16198 /* just after name is now '\0'. */
16199 *input_line_pointer = c;
16200 input_line_pointer = section_name;
16201 obj_elf_section (ignore);
16204 input_line_pointer++;
16206 /* Do we have .section Name<,type><,flag><,entry_size><,alignment> */
16208 section_type = get_absolute_expression ();
16211 if (*input_line_pointer++ == ',')
16212 section_flag = get_absolute_expression ();
16215 if (*input_line_pointer++ == ',')
16216 section_entry_size = get_absolute_expression ();
16218 section_entry_size = 0;
16219 if (*input_line_pointer++ == ',')
16220 section_alignment = get_absolute_expression ();
16222 section_alignment = 0;
16223 /* FIXME: really ignore? */
16224 (void) section_alignment;
16226 section_name = xstrdup (section_name);
16228 /* When using the generic form of .section (as implemented by obj-elf.c),
16229 there's no way to set the section type to SHT_MIPS_DWARF. Users have
16230 traditionally had to fall back on the more common @progbits instead.
16232 There's nothing really harmful in this, since bfd will correct
16233 SHT_PROGBITS to SHT_MIPS_DWARF before writing out the file. But it
16234 means that, for backwards compatibility, the special_section entries
16235 for dwarf sections must use SHT_PROGBITS rather than SHT_MIPS_DWARF.
16237 Even so, we shouldn't force users of the MIPS .section syntax to
16238 incorrectly label the sections as SHT_PROGBITS. The best compromise
16239 seems to be to map SHT_MIPS_DWARF to SHT_PROGBITS before calling the
16240 generic type-checking code. */
16241 if (section_type == SHT_MIPS_DWARF)
16242 section_type = SHT_PROGBITS;
16244 obj_elf_change_section (section_name, section_type, section_flag,
16245 section_entry_size, 0, 0, 0);
16247 if (now_seg->name != section_name)
16248 free (section_name);
16252 mips_enable_auto_align (void)
16258 s_cons (int log_size)
16260 segment_info_type *si = seg_info (now_seg);
16261 struct insn_label_list *l = si->label_list;
16263 mips_emit_delays ();
16264 if (log_size > 0 && auto_align)
16265 mips_align (log_size, 0, l);
16266 cons (1 << log_size);
16267 mips_clear_insn_labels ();
16271 s_float_cons (int type)
16273 segment_info_type *si = seg_info (now_seg);
16274 struct insn_label_list *l = si->label_list;
16276 mips_emit_delays ();
16281 mips_align (3, 0, l);
16283 mips_align (2, 0, l);
16287 mips_clear_insn_labels ();
16290 /* Handle .globl. We need to override it because on Irix 5 you are
16293 where foo is an undefined symbol, to mean that foo should be
16294 considered to be the address of a function. */
16297 s_mips_globl (int x ATTRIBUTE_UNUSED)
16306 name = input_line_pointer;
16307 c = get_symbol_end ();
16308 symbolP = symbol_find_or_make (name);
16309 S_SET_EXTERNAL (symbolP);
16311 *input_line_pointer = c;
16312 SKIP_WHITESPACE ();
16314 /* On Irix 5, every global symbol that is not explicitly labelled as
16315 being a function is apparently labelled as being an object. */
16318 if (!is_end_of_line[(unsigned char) *input_line_pointer]
16319 && (*input_line_pointer != ','))
16324 secname = input_line_pointer;
16325 c = get_symbol_end ();
16326 sec = bfd_get_section_by_name (stdoutput, secname);
16328 as_bad (_("%s: no such section"), secname);
16329 *input_line_pointer = c;
16331 if (sec != NULL && (sec->flags & SEC_CODE) != 0)
16332 flag = BSF_FUNCTION;
16335 symbol_get_bfdsym (symbolP)->flags |= flag;
16337 c = *input_line_pointer;
16340 input_line_pointer++;
16341 SKIP_WHITESPACE ();
16342 if (is_end_of_line[(unsigned char) *input_line_pointer])
16348 demand_empty_rest_of_line ();
16352 s_option (int x ATTRIBUTE_UNUSED)
16357 opt = input_line_pointer;
16358 c = get_symbol_end ();
16362 /* FIXME: What does this mean? */
16364 else if (strncmp (opt, "pic", 3) == 0)
16368 i = atoi (opt + 3);
16373 mips_pic = SVR4_PIC;
16374 mips_abicalls = TRUE;
16377 as_bad (_(".option pic%d not supported"), i);
16379 if (mips_pic == SVR4_PIC)
16381 if (g_switch_seen && g_switch_value != 0)
16382 as_warn (_("-G may not be used with SVR4 PIC code"));
16383 g_switch_value = 0;
16384 bfd_set_gp_size (stdoutput, 0);
16388 as_warn (_("Unrecognized option \"%s\""), opt);
16390 *input_line_pointer = c;
16391 demand_empty_rest_of_line ();
16394 /* This structure is used to hold a stack of .set values. */
16396 struct mips_option_stack
16398 struct mips_option_stack *next;
16399 struct mips_set_options options;
16402 static struct mips_option_stack *mips_opts_stack;
16404 /* Handle the .set pseudo-op. */
16407 s_mipsset (int x ATTRIBUTE_UNUSED)
16409 char *name = input_line_pointer, ch;
16410 const struct mips_ase *ase;
16412 while (!is_end_of_line[(unsigned char) *input_line_pointer])
16413 ++input_line_pointer;
16414 ch = *input_line_pointer;
16415 *input_line_pointer = '\0';
16417 if (strcmp (name, "reorder") == 0)
16419 if (mips_opts.noreorder)
16422 else if (strcmp (name, "noreorder") == 0)
16424 if (!mips_opts.noreorder)
16425 start_noreorder ();
16427 else if (strncmp (name, "at=", 3) == 0)
16429 char *s = name + 3;
16431 if (!reg_lookup (&s, RTYPE_NUM | RTYPE_GP, &mips_opts.at))
16432 as_bad (_("Unrecognized register name `%s'"), s);
16434 else if (strcmp (name, "at") == 0)
16436 mips_opts.at = ATREG;
16438 else if (strcmp (name, "noat") == 0)
16440 mips_opts.at = ZERO;
16442 else if (strcmp (name, "macro") == 0)
16444 mips_opts.warn_about_macros = 0;
16446 else if (strcmp (name, "nomacro") == 0)
16448 if (mips_opts.noreorder == 0)
16449 as_bad (_("`noreorder' must be set before `nomacro'"));
16450 mips_opts.warn_about_macros = 1;
16452 else if (strcmp (name, "move") == 0 || strcmp (name, "novolatile") == 0)
16454 mips_opts.nomove = 0;
16456 else if (strcmp (name, "nomove") == 0 || strcmp (name, "volatile") == 0)
16458 mips_opts.nomove = 1;
16460 else if (strcmp (name, "bopt") == 0)
16462 mips_opts.nobopt = 0;
16464 else if (strcmp (name, "nobopt") == 0)
16466 mips_opts.nobopt = 1;
16468 else if (strcmp (name, "gp=default") == 0)
16469 mips_opts.gp32 = file_mips_gp32;
16470 else if (strcmp (name, "gp=32") == 0)
16471 mips_opts.gp32 = 1;
16472 else if (strcmp (name, "gp=64") == 0)
16474 if (!ISA_HAS_64BIT_REGS (mips_opts.isa))
16475 as_warn (_("%s isa does not support 64-bit registers"),
16476 mips_cpu_info_from_isa (mips_opts.isa)->name);
16477 mips_opts.gp32 = 0;
16479 else if (strcmp (name, "fp=default") == 0)
16480 mips_opts.fp32 = file_mips_fp32;
16481 else if (strcmp (name, "fp=32") == 0)
16482 mips_opts.fp32 = 1;
16483 else if (strcmp (name, "fp=64") == 0)
16485 if (!ISA_HAS_64BIT_FPRS (mips_opts.isa))
16486 as_warn (_("%s isa does not support 64-bit floating point registers"),
16487 mips_cpu_info_from_isa (mips_opts.isa)->name);
16488 mips_opts.fp32 = 0;
16490 else if (strcmp (name, "softfloat") == 0)
16491 mips_opts.soft_float = 1;
16492 else if (strcmp (name, "hardfloat") == 0)
16493 mips_opts.soft_float = 0;
16494 else if (strcmp (name, "singlefloat") == 0)
16495 mips_opts.single_float = 1;
16496 else if (strcmp (name, "doublefloat") == 0)
16497 mips_opts.single_float = 0;
16498 else if (strcmp (name, "mips16") == 0
16499 || strcmp (name, "MIPS-16") == 0)
16501 if (mips_opts.micromips == 1)
16502 as_fatal (_("`mips16' cannot be used with `micromips'"));
16503 mips_opts.mips16 = 1;
16505 else if (strcmp (name, "nomips16") == 0
16506 || strcmp (name, "noMIPS-16") == 0)
16507 mips_opts.mips16 = 0;
16508 else if (strcmp (name, "micromips") == 0)
16510 if (mips_opts.mips16 == 1)
16511 as_fatal (_("`micromips' cannot be used with `mips16'"));
16512 mips_opts.micromips = 1;
16514 else if (strcmp (name, "nomicromips") == 0)
16515 mips_opts.micromips = 0;
16516 else if (name[0] == 'n'
16518 && (ase = mips_lookup_ase (name + 2)))
16519 mips_set_ase (ase, FALSE);
16520 else if ((ase = mips_lookup_ase (name)))
16521 mips_set_ase (ase, TRUE);
16522 else if (strncmp (name, "mips", 4) == 0 || strncmp (name, "arch=", 5) == 0)
16526 /* Permit the user to change the ISA and architecture on the fly.
16527 Needless to say, misuse can cause serious problems. */
16528 if (strcmp (name, "mips0") == 0 || strcmp (name, "arch=default") == 0)
16531 mips_opts.isa = file_mips_isa;
16532 mips_opts.arch = file_mips_arch;
16534 else if (strncmp (name, "arch=", 5) == 0)
16536 const struct mips_cpu_info *p;
16538 p = mips_parse_cpu("internal use", name + 5);
16540 as_bad (_("unknown architecture %s"), name + 5);
16543 mips_opts.arch = p->cpu;
16544 mips_opts.isa = p->isa;
16547 else if (strncmp (name, "mips", 4) == 0)
16549 const struct mips_cpu_info *p;
16551 p = mips_parse_cpu("internal use", name);
16553 as_bad (_("unknown ISA level %s"), name + 4);
16556 mips_opts.arch = p->cpu;
16557 mips_opts.isa = p->isa;
16561 as_bad (_("unknown ISA or architecture %s"), name);
16563 switch (mips_opts.isa)
16571 mips_opts.gp32 = 1;
16572 mips_opts.fp32 = 1;
16579 mips_opts.gp32 = 0;
16580 if (mips_opts.arch == CPU_R5900)
16582 mips_opts.fp32 = 1;
16586 mips_opts.fp32 = 0;
16590 as_bad (_("unknown ISA level %s"), name + 4);
16595 mips_opts.gp32 = file_mips_gp32;
16596 mips_opts.fp32 = file_mips_fp32;
16599 else if (strcmp (name, "autoextend") == 0)
16600 mips_opts.noautoextend = 0;
16601 else if (strcmp (name, "noautoextend") == 0)
16602 mips_opts.noautoextend = 1;
16603 else if (strcmp (name, "push") == 0)
16605 struct mips_option_stack *s;
16607 s = (struct mips_option_stack *) xmalloc (sizeof *s);
16608 s->next = mips_opts_stack;
16609 s->options = mips_opts;
16610 mips_opts_stack = s;
16612 else if (strcmp (name, "pop") == 0)
16614 struct mips_option_stack *s;
16616 s = mips_opts_stack;
16618 as_bad (_(".set pop with no .set push"));
16621 /* If we're changing the reorder mode we need to handle
16622 delay slots correctly. */
16623 if (s->options.noreorder && ! mips_opts.noreorder)
16624 start_noreorder ();
16625 else if (! s->options.noreorder && mips_opts.noreorder)
16628 mips_opts = s->options;
16629 mips_opts_stack = s->next;
16633 else if (strcmp (name, "sym32") == 0)
16634 mips_opts.sym32 = TRUE;
16635 else if (strcmp (name, "nosym32") == 0)
16636 mips_opts.sym32 = FALSE;
16637 else if (strchr (name, ','))
16639 /* Generic ".set" directive; use the generic handler. */
16640 *input_line_pointer = ch;
16641 input_line_pointer = name;
16647 as_warn (_("Tried to set unrecognized symbol: %s\n"), name);
16649 mips_check_isa_supports_ases ();
16650 *input_line_pointer = ch;
16651 demand_empty_rest_of_line ();
16654 /* Handle the .abicalls pseudo-op. I believe this is equivalent to
16655 .option pic2. It means to generate SVR4 PIC calls. */
16658 s_abicalls (int ignore ATTRIBUTE_UNUSED)
16660 mips_pic = SVR4_PIC;
16661 mips_abicalls = TRUE;
16663 if (g_switch_seen && g_switch_value != 0)
16664 as_warn (_("-G may not be used with SVR4 PIC code"));
16665 g_switch_value = 0;
16667 bfd_set_gp_size (stdoutput, 0);
16668 demand_empty_rest_of_line ();
16671 /* Handle the .cpload pseudo-op. This is used when generating SVR4
16672 PIC code. It sets the $gp register for the function based on the
16673 function address, which is in the register named in the argument.
16674 This uses a relocation against _gp_disp, which is handled specially
16675 by the linker. The result is:
16676 lui $gp,%hi(_gp_disp)
16677 addiu $gp,$gp,%lo(_gp_disp)
16678 addu $gp,$gp,.cpload argument
16679 The .cpload argument is normally $25 == $t9.
16681 The -mno-shared option changes this to:
16682 lui $gp,%hi(__gnu_local_gp)
16683 addiu $gp,$gp,%lo(__gnu_local_gp)
16684 and the argument is ignored. This saves an instruction, but the
16685 resulting code is not position independent; it uses an absolute
16686 address for __gnu_local_gp. Thus code assembled with -mno-shared
16687 can go into an ordinary executable, but not into a shared library. */
16690 s_cpload (int ignore ATTRIBUTE_UNUSED)
16696 /* If we are not generating SVR4 PIC code, or if this is NewABI code,
16697 .cpload is ignored. */
16698 if (mips_pic != SVR4_PIC || HAVE_NEWABI)
16704 if (mips_opts.mips16)
16706 as_bad (_("%s not supported in MIPS16 mode"), ".cpload");
16707 ignore_rest_of_line ();
16711 /* .cpload should be in a .set noreorder section. */
16712 if (mips_opts.noreorder == 0)
16713 as_warn (_(".cpload not in noreorder section"));
16715 reg = tc_get_register (0);
16717 /* If we need to produce a 64-bit address, we are better off using
16718 the default instruction sequence. */
16719 in_shared = mips_in_shared || HAVE_64BIT_SYMBOLS;
16721 ex.X_op = O_symbol;
16722 ex.X_add_symbol = symbol_find_or_make (in_shared ? "_gp_disp" :
16724 ex.X_op_symbol = NULL;
16725 ex.X_add_number = 0;
16727 /* In ELF, this symbol is implicitly an STT_OBJECT symbol. */
16728 symbol_get_bfdsym (ex.X_add_symbol)->flags |= BSF_OBJECT;
16730 mips_mark_labels ();
16731 mips_assembling_insn = TRUE;
16734 macro_build_lui (&ex, mips_gp_register);
16735 macro_build (&ex, "addiu", "t,r,j", mips_gp_register,
16736 mips_gp_register, BFD_RELOC_LO16);
16738 macro_build (NULL, "addu", "d,v,t", mips_gp_register,
16739 mips_gp_register, reg);
16742 mips_assembling_insn = FALSE;
16743 demand_empty_rest_of_line ();
16746 /* Handle the .cpsetup pseudo-op defined for NewABI PIC code. The syntax is:
16747 .cpsetup $reg1, offset|$reg2, label
16749 If offset is given, this results in:
16750 sd $gp, offset($sp)
16751 lui $gp, %hi(%neg(%gp_rel(label)))
16752 addiu $gp, $gp, %lo(%neg(%gp_rel(label)))
16753 daddu $gp, $gp, $reg1
16755 If $reg2 is given, this results in:
16756 daddu $reg2, $gp, $0
16757 lui $gp, %hi(%neg(%gp_rel(label)))
16758 addiu $gp, $gp, %lo(%neg(%gp_rel(label)))
16759 daddu $gp, $gp, $reg1
16760 $reg1 is normally $25 == $t9.
16762 The -mno-shared option replaces the last three instructions with
16764 addiu $gp,$gp,%lo(_gp) */
16767 s_cpsetup (int ignore ATTRIBUTE_UNUSED)
16769 expressionS ex_off;
16770 expressionS ex_sym;
16773 /* If we are not generating SVR4 PIC code, .cpsetup is ignored.
16774 We also need NewABI support. */
16775 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
16781 if (mips_opts.mips16)
16783 as_bad (_("%s not supported in MIPS16 mode"), ".cpsetup");
16784 ignore_rest_of_line ();
16788 reg1 = tc_get_register (0);
16789 SKIP_WHITESPACE ();
16790 if (*input_line_pointer != ',')
16792 as_bad (_("missing argument separator ',' for .cpsetup"));
16796 ++input_line_pointer;
16797 SKIP_WHITESPACE ();
16798 if (*input_line_pointer == '$')
16800 mips_cpreturn_register = tc_get_register (0);
16801 mips_cpreturn_offset = -1;
16805 mips_cpreturn_offset = get_absolute_expression ();
16806 mips_cpreturn_register = -1;
16808 SKIP_WHITESPACE ();
16809 if (*input_line_pointer != ',')
16811 as_bad (_("missing argument separator ',' for .cpsetup"));
16815 ++input_line_pointer;
16816 SKIP_WHITESPACE ();
16817 expression (&ex_sym);
16819 mips_mark_labels ();
16820 mips_assembling_insn = TRUE;
16823 if (mips_cpreturn_register == -1)
16825 ex_off.X_op = O_constant;
16826 ex_off.X_add_symbol = NULL;
16827 ex_off.X_op_symbol = NULL;
16828 ex_off.X_add_number = mips_cpreturn_offset;
16830 macro_build (&ex_off, "sd", "t,o(b)", mips_gp_register,
16831 BFD_RELOC_LO16, SP);
16834 macro_build (NULL, "daddu", "d,v,t", mips_cpreturn_register,
16835 mips_gp_register, 0);
16837 if (mips_in_shared || HAVE_64BIT_SYMBOLS)
16839 macro_build (&ex_sym, "lui", LUI_FMT, mips_gp_register,
16840 -1, BFD_RELOC_GPREL16, BFD_RELOC_MIPS_SUB,
16843 macro_build (&ex_sym, "addiu", "t,r,j", mips_gp_register,
16844 mips_gp_register, -1, BFD_RELOC_GPREL16,
16845 BFD_RELOC_MIPS_SUB, BFD_RELOC_LO16);
16847 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", mips_gp_register,
16848 mips_gp_register, reg1);
16854 ex.X_op = O_symbol;
16855 ex.X_add_symbol = symbol_find_or_make ("__gnu_local_gp");
16856 ex.X_op_symbol = NULL;
16857 ex.X_add_number = 0;
16859 /* In ELF, this symbol is implicitly an STT_OBJECT symbol. */
16860 symbol_get_bfdsym (ex.X_add_symbol)->flags |= BSF_OBJECT;
16862 macro_build_lui (&ex, mips_gp_register);
16863 macro_build (&ex, "addiu", "t,r,j", mips_gp_register,
16864 mips_gp_register, BFD_RELOC_LO16);
16869 mips_assembling_insn = FALSE;
16870 demand_empty_rest_of_line ();
16874 s_cplocal (int ignore ATTRIBUTE_UNUSED)
16876 /* If we are not generating SVR4 PIC code, or if this is not NewABI code,
16877 .cplocal is ignored. */
16878 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
16884 if (mips_opts.mips16)
16886 as_bad (_("%s not supported in MIPS16 mode"), ".cplocal");
16887 ignore_rest_of_line ();
16891 mips_gp_register = tc_get_register (0);
16892 demand_empty_rest_of_line ();
16895 /* Handle the .cprestore pseudo-op. This stores $gp into a given
16896 offset from $sp. The offset is remembered, and after making a PIC
16897 call $gp is restored from that location. */
16900 s_cprestore (int ignore ATTRIBUTE_UNUSED)
16904 /* If we are not generating SVR4 PIC code, or if this is NewABI code,
16905 .cprestore is ignored. */
16906 if (mips_pic != SVR4_PIC || HAVE_NEWABI)
16912 if (mips_opts.mips16)
16914 as_bad (_("%s not supported in MIPS16 mode"), ".cprestore");
16915 ignore_rest_of_line ();
16919 mips_cprestore_offset = get_absolute_expression ();
16920 mips_cprestore_valid = 1;
16922 ex.X_op = O_constant;
16923 ex.X_add_symbol = NULL;
16924 ex.X_op_symbol = NULL;
16925 ex.X_add_number = mips_cprestore_offset;
16927 mips_mark_labels ();
16928 mips_assembling_insn = TRUE;
16931 macro_build_ldst_constoffset (&ex, ADDRESS_STORE_INSN, mips_gp_register,
16932 SP, HAVE_64BIT_ADDRESSES);
16935 mips_assembling_insn = FALSE;
16936 demand_empty_rest_of_line ();
16939 /* Handle the .cpreturn pseudo-op defined for NewABI PIC code. If an offset
16940 was given in the preceding .cpsetup, it results in:
16941 ld $gp, offset($sp)
16943 If a register $reg2 was given there, it results in:
16944 daddu $gp, $reg2, $0 */
16947 s_cpreturn (int ignore ATTRIBUTE_UNUSED)
16951 /* If we are not generating SVR4 PIC code, .cpreturn is ignored.
16952 We also need NewABI support. */
16953 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
16959 if (mips_opts.mips16)
16961 as_bad (_("%s not supported in MIPS16 mode"), ".cpreturn");
16962 ignore_rest_of_line ();
16966 mips_mark_labels ();
16967 mips_assembling_insn = TRUE;
16970 if (mips_cpreturn_register == -1)
16972 ex.X_op = O_constant;
16973 ex.X_add_symbol = NULL;
16974 ex.X_op_symbol = NULL;
16975 ex.X_add_number = mips_cpreturn_offset;
16977 macro_build (&ex, "ld", "t,o(b)", mips_gp_register, BFD_RELOC_LO16, SP);
16980 macro_build (NULL, "daddu", "d,v,t", mips_gp_register,
16981 mips_cpreturn_register, 0);
16984 mips_assembling_insn = FALSE;
16985 demand_empty_rest_of_line ();
16988 /* Handle a .dtprelword, .dtpreldword, .tprelword, or .tpreldword
16989 pseudo-op; DIRSTR says which. The pseudo-op generates a BYTES-size
16990 DTP- or TP-relative relocation of type RTYPE, for use in either DWARF
16991 debug information or MIPS16 TLS. */
16994 s_tls_rel_directive (const size_t bytes, const char *dirstr,
16995 bfd_reloc_code_real_type rtype)
17002 if (ex.X_op != O_symbol)
17004 as_bad (_("Unsupported use of %s"), dirstr);
17005 ignore_rest_of_line ();
17008 p = frag_more (bytes);
17009 md_number_to_chars (p, 0, bytes);
17010 fix_new_exp (frag_now, p - frag_now->fr_literal, bytes, &ex, FALSE, rtype);
17011 demand_empty_rest_of_line ();
17012 mips_clear_insn_labels ();
17015 /* Handle .dtprelword. */
17018 s_dtprelword (int ignore ATTRIBUTE_UNUSED)
17020 s_tls_rel_directive (4, ".dtprelword", BFD_RELOC_MIPS_TLS_DTPREL32);
17023 /* Handle .dtpreldword. */
17026 s_dtpreldword (int ignore ATTRIBUTE_UNUSED)
17028 s_tls_rel_directive (8, ".dtpreldword", BFD_RELOC_MIPS_TLS_DTPREL64);
17031 /* Handle .tprelword. */
17034 s_tprelword (int ignore ATTRIBUTE_UNUSED)
17036 s_tls_rel_directive (4, ".tprelword", BFD_RELOC_MIPS_TLS_TPREL32);
17039 /* Handle .tpreldword. */
17042 s_tpreldword (int ignore ATTRIBUTE_UNUSED)
17044 s_tls_rel_directive (8, ".tpreldword", BFD_RELOC_MIPS_TLS_TPREL64);
17047 /* Handle the .gpvalue pseudo-op. This is used when generating NewABI PIC
17048 code. It sets the offset to use in gp_rel relocations. */
17051 s_gpvalue (int ignore ATTRIBUTE_UNUSED)
17053 /* If we are not generating SVR4 PIC code, .gpvalue is ignored.
17054 We also need NewABI support. */
17055 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
17061 mips_gprel_offset = get_absolute_expression ();
17063 demand_empty_rest_of_line ();
17066 /* Handle the .gpword pseudo-op. This is used when generating PIC
17067 code. It generates a 32 bit GP relative reloc. */
17070 s_gpword (int ignore ATTRIBUTE_UNUSED)
17072 segment_info_type *si;
17073 struct insn_label_list *l;
17077 /* When not generating PIC code, this is treated as .word. */
17078 if (mips_pic != SVR4_PIC)
17084 si = seg_info (now_seg);
17085 l = si->label_list;
17086 mips_emit_delays ();
17088 mips_align (2, 0, l);
17091 mips_clear_insn_labels ();
17093 if (ex.X_op != O_symbol || ex.X_add_number != 0)
17095 as_bad (_("Unsupported use of .gpword"));
17096 ignore_rest_of_line ();
17100 md_number_to_chars (p, 0, 4);
17101 fix_new_exp (frag_now, p - frag_now->fr_literal, 4, &ex, FALSE,
17102 BFD_RELOC_GPREL32);
17104 demand_empty_rest_of_line ();
17108 s_gpdword (int ignore ATTRIBUTE_UNUSED)
17110 segment_info_type *si;
17111 struct insn_label_list *l;
17115 /* When not generating PIC code, this is treated as .dword. */
17116 if (mips_pic != SVR4_PIC)
17122 si = seg_info (now_seg);
17123 l = si->label_list;
17124 mips_emit_delays ();
17126 mips_align (3, 0, l);
17129 mips_clear_insn_labels ();
17131 if (ex.X_op != O_symbol || ex.X_add_number != 0)
17133 as_bad (_("Unsupported use of .gpdword"));
17134 ignore_rest_of_line ();
17138 md_number_to_chars (p, 0, 8);
17139 fix_new_exp (frag_now, p - frag_now->fr_literal, 4, &ex, FALSE,
17140 BFD_RELOC_GPREL32)->fx_tcbit = 1;
17142 /* GPREL32 composed with 64 gives a 64-bit GP offset. */
17143 fix_new (frag_now, p - frag_now->fr_literal, 8, NULL, 0,
17144 FALSE, BFD_RELOC_64)->fx_tcbit = 1;
17146 demand_empty_rest_of_line ();
17149 /* Handle the .ehword pseudo-op. This is used when generating unwinding
17150 tables. It generates a R_MIPS_EH reloc. */
17153 s_ehword (int ignore ATTRIBUTE_UNUSED)
17158 mips_emit_delays ();
17161 mips_clear_insn_labels ();
17163 if (ex.X_op != O_symbol || ex.X_add_number != 0)
17165 as_bad (_("Unsupported use of .ehword"));
17166 ignore_rest_of_line ();
17170 md_number_to_chars (p, 0, 4);
17171 fix_new_exp (frag_now, p - frag_now->fr_literal, 4, &ex, FALSE,
17172 BFD_RELOC_MIPS_EH);
17174 demand_empty_rest_of_line ();
17177 /* Handle the .cpadd pseudo-op. This is used when dealing with switch
17178 tables in SVR4 PIC code. */
17181 s_cpadd (int ignore ATTRIBUTE_UNUSED)
17185 /* This is ignored when not generating SVR4 PIC code. */
17186 if (mips_pic != SVR4_PIC)
17192 mips_mark_labels ();
17193 mips_assembling_insn = TRUE;
17195 /* Add $gp to the register named as an argument. */
17197 reg = tc_get_register (0);
17198 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", reg, reg, mips_gp_register);
17201 mips_assembling_insn = FALSE;
17202 demand_empty_rest_of_line ();
17205 /* Handle the .insn pseudo-op. This marks instruction labels in
17206 mips16/micromips mode. This permits the linker to handle them specially,
17207 such as generating jalx instructions when needed. We also make
17208 them odd for the duration of the assembly, in order to generate the
17209 right sort of code. We will make them even in the adjust_symtab
17210 routine, while leaving them marked. This is convenient for the
17211 debugger and the disassembler. The linker knows to make them odd
17215 s_insn (int ignore ATTRIBUTE_UNUSED)
17217 mips_mark_labels ();
17219 demand_empty_rest_of_line ();
17222 /* Handle a .stab[snd] directive. Ideally these directives would be
17223 implemented in a transparent way, so that removing them would not
17224 have any effect on the generated instructions. However, s_stab
17225 internally changes the section, so in practice we need to decide
17226 now whether the preceding label marks compressed code. We do not
17227 support changing the compression mode of a label after a .stab*
17228 directive, such as in:
17234 so the current mode wins. */
17237 s_mips_stab (int type)
17239 mips_mark_labels ();
17243 /* Handle the .weakext pseudo-op as defined in Kane and Heinrich. */
17246 s_mips_weakext (int ignore ATTRIBUTE_UNUSED)
17253 name = input_line_pointer;
17254 c = get_symbol_end ();
17255 symbolP = symbol_find_or_make (name);
17256 S_SET_WEAK (symbolP);
17257 *input_line_pointer = c;
17259 SKIP_WHITESPACE ();
17261 if (! is_end_of_line[(unsigned char) *input_line_pointer])
17263 if (S_IS_DEFINED (symbolP))
17265 as_bad (_("ignoring attempt to redefine symbol %s"),
17266 S_GET_NAME (symbolP));
17267 ignore_rest_of_line ();
17271 if (*input_line_pointer == ',')
17273 ++input_line_pointer;
17274 SKIP_WHITESPACE ();
17278 if (exp.X_op != O_symbol)
17280 as_bad (_("bad .weakext directive"));
17281 ignore_rest_of_line ();
17284 symbol_set_value_expression (symbolP, &exp);
17287 demand_empty_rest_of_line ();
17290 /* Parse a register string into a number. Called from the ECOFF code
17291 to parse .frame. The argument is non-zero if this is the frame
17292 register, so that we can record it in mips_frame_reg. */
17295 tc_get_register (int frame)
17299 SKIP_WHITESPACE ();
17300 if (! reg_lookup (&input_line_pointer, RWARN | RTYPE_NUM | RTYPE_GP, ®))
17304 mips_frame_reg = reg != 0 ? reg : SP;
17305 mips_frame_reg_valid = 1;
17306 mips_cprestore_valid = 0;
17312 md_section_align (asection *seg, valueT addr)
17314 int align = bfd_get_section_alignment (stdoutput, seg);
17316 /* We don't need to align ELF sections to the full alignment.
17317 However, Irix 5 may prefer that we align them at least to a 16
17318 byte boundary. We don't bother to align the sections if we
17319 are targeted for an embedded system. */
17320 if (strncmp (TARGET_OS, "elf", 3) == 0)
17325 return ((addr + (1 << align) - 1) & (-1 << align));
17328 /* Utility routine, called from above as well. If called while the
17329 input file is still being read, it's only an approximation. (For
17330 example, a symbol may later become defined which appeared to be
17331 undefined earlier.) */
17334 nopic_need_relax (symbolS *sym, int before_relaxing)
17339 if (g_switch_value > 0)
17341 const char *symname;
17344 /* Find out whether this symbol can be referenced off the $gp
17345 register. It can be if it is smaller than the -G size or if
17346 it is in the .sdata or .sbss section. Certain symbols can
17347 not be referenced off the $gp, although it appears as though
17349 symname = S_GET_NAME (sym);
17350 if (symname != (const char *) NULL
17351 && (strcmp (symname, "eprol") == 0
17352 || strcmp (symname, "etext") == 0
17353 || strcmp (symname, "_gp") == 0
17354 || strcmp (symname, "edata") == 0
17355 || strcmp (symname, "_fbss") == 0
17356 || strcmp (symname, "_fdata") == 0
17357 || strcmp (symname, "_ftext") == 0
17358 || strcmp (symname, "end") == 0
17359 || strcmp (symname, "_gp_disp") == 0))
17361 else if ((! S_IS_DEFINED (sym) || S_IS_COMMON (sym))
17363 #ifndef NO_ECOFF_DEBUGGING
17364 || (symbol_get_obj (sym)->ecoff_extern_size != 0
17365 && (symbol_get_obj (sym)->ecoff_extern_size
17366 <= g_switch_value))
17368 /* We must defer this decision until after the whole
17369 file has been read, since there might be a .extern
17370 after the first use of this symbol. */
17371 || (before_relaxing
17372 #ifndef NO_ECOFF_DEBUGGING
17373 && symbol_get_obj (sym)->ecoff_extern_size == 0
17375 && S_GET_VALUE (sym) == 0)
17376 || (S_GET_VALUE (sym) != 0
17377 && S_GET_VALUE (sym) <= g_switch_value)))
17381 const char *segname;
17383 segname = segment_name (S_GET_SEGMENT (sym));
17384 gas_assert (strcmp (segname, ".lit8") != 0
17385 && strcmp (segname, ".lit4") != 0);
17386 change = (strcmp (segname, ".sdata") != 0
17387 && strcmp (segname, ".sbss") != 0
17388 && strncmp (segname, ".sdata.", 7) != 0
17389 && strncmp (segname, ".sbss.", 6) != 0
17390 && strncmp (segname, ".gnu.linkonce.sb.", 17) != 0
17391 && strncmp (segname, ".gnu.linkonce.s.", 16) != 0);
17396 /* We are not optimizing for the $gp register. */
17401 /* Return true if the given symbol should be considered local for SVR4 PIC. */
17404 pic_need_relax (symbolS *sym, asection *segtype)
17408 /* Handle the case of a symbol equated to another symbol. */
17409 while (symbol_equated_reloc_p (sym))
17413 /* It's possible to get a loop here in a badly written program. */
17414 n = symbol_get_value_expression (sym)->X_add_symbol;
17420 if (symbol_section_p (sym))
17423 symsec = S_GET_SEGMENT (sym);
17425 /* This must duplicate the test in adjust_reloc_syms. */
17426 return (!bfd_is_und_section (symsec)
17427 && !bfd_is_abs_section (symsec)
17428 && !bfd_is_com_section (symsec)
17429 && !s_is_linkonce (sym, segtype)
17430 /* A global or weak symbol is treated as external. */
17431 && (!S_IS_WEAK (sym) && !S_IS_EXTERNAL (sym)));
17435 /* Given a mips16 variant frag FRAGP, return non-zero if it needs an
17436 extended opcode. SEC is the section the frag is in. */
17439 mips16_extended_frag (fragS *fragp, asection *sec, long stretch)
17442 const struct mips16_immed_operand *op;
17444 int mintiny, maxtiny;
17448 if (RELAX_MIPS16_USER_SMALL (fragp->fr_subtype))
17450 if (RELAX_MIPS16_USER_EXT (fragp->fr_subtype))
17453 type = RELAX_MIPS16_TYPE (fragp->fr_subtype);
17454 op = mips16_immed_operands;
17455 while (op->type != type)
17458 gas_assert (op < mips16_immed_operands + MIPS16_NUM_IMMED);
17463 if (type == '<' || type == '>' || type == '[' || type == ']')
17466 maxtiny = 1 << op->nbits;
17471 maxtiny = (1 << op->nbits) - 1;
17476 mintiny = - (1 << (op->nbits - 1));
17477 maxtiny = (1 << (op->nbits - 1)) - 1;
17480 sym_frag = symbol_get_frag (fragp->fr_symbol);
17481 val = S_GET_VALUE (fragp->fr_symbol);
17482 symsec = S_GET_SEGMENT (fragp->fr_symbol);
17488 /* We won't have the section when we are called from
17489 mips_relax_frag. However, we will always have been called
17490 from md_estimate_size_before_relax first. If this is a
17491 branch to a different section, we mark it as such. If SEC is
17492 NULL, and the frag is not marked, then it must be a branch to
17493 the same section. */
17496 if (RELAX_MIPS16_LONG_BRANCH (fragp->fr_subtype))
17501 /* Must have been called from md_estimate_size_before_relax. */
17504 fragp->fr_subtype =
17505 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
17507 /* FIXME: We should support this, and let the linker
17508 catch branches and loads that are out of range. */
17509 as_bad_where (fragp->fr_file, fragp->fr_line,
17510 _("unsupported PC relative reference to different section"));
17514 if (fragp != sym_frag && sym_frag->fr_address == 0)
17515 /* Assume non-extended on the first relaxation pass.
17516 The address we have calculated will be bogus if this is
17517 a forward branch to another frag, as the forward frag
17518 will have fr_address == 0. */
17522 /* In this case, we know for sure that the symbol fragment is in
17523 the same section. If the relax_marker of the symbol fragment
17524 differs from the relax_marker of this fragment, we have not
17525 yet adjusted the symbol fragment fr_address. We want to add
17526 in STRETCH in order to get a better estimate of the address.
17527 This particularly matters because of the shift bits. */
17529 && sym_frag->relax_marker != fragp->relax_marker)
17533 /* Adjust stretch for any alignment frag. Note that if have
17534 been expanding the earlier code, the symbol may be
17535 defined in what appears to be an earlier frag. FIXME:
17536 This doesn't handle the fr_subtype field, which specifies
17537 a maximum number of bytes to skip when doing an
17539 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
17541 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
17544 stretch = - ((- stretch)
17545 & ~ ((1 << (int) f->fr_offset) - 1));
17547 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
17556 addr = fragp->fr_address + fragp->fr_fix;
17558 /* The base address rules are complicated. The base address of
17559 a branch is the following instruction. The base address of a
17560 PC relative load or add is the instruction itself, but if it
17561 is in a delay slot (in which case it can not be extended) use
17562 the address of the instruction whose delay slot it is in. */
17563 if (type == 'p' || type == 'q')
17567 /* If we are currently assuming that this frag should be
17568 extended, then, the current address is two bytes
17570 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
17573 /* Ignore the low bit in the target, since it will be set
17574 for a text label. */
17575 if ((val & 1) != 0)
17578 else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype))
17580 else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype))
17583 val -= addr & ~ ((1 << op->shift) - 1);
17585 /* Branch offsets have an implicit 0 in the lowest bit. */
17586 if (type == 'p' || type == 'q')
17589 /* If any of the shifted bits are set, we must use an extended
17590 opcode. If the address depends on the size of this
17591 instruction, this can lead to a loop, so we arrange to always
17592 use an extended opcode. We only check this when we are in
17593 the main relaxation loop, when SEC is NULL. */
17594 if ((val & ((1 << op->shift) - 1)) != 0 && sec == NULL)
17596 fragp->fr_subtype =
17597 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
17601 /* If we are about to mark a frag as extended because the value
17602 is precisely maxtiny + 1, then there is a chance of an
17603 infinite loop as in the following code:
17608 In this case when the la is extended, foo is 0x3fc bytes
17609 away, so the la can be shrunk, but then foo is 0x400 away, so
17610 the la must be extended. To avoid this loop, we mark the
17611 frag as extended if it was small, and is about to become
17612 extended with a value of maxtiny + 1. */
17613 if (val == ((maxtiny + 1) << op->shift)
17614 && ! RELAX_MIPS16_EXTENDED (fragp->fr_subtype)
17617 fragp->fr_subtype =
17618 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
17622 else if (symsec != absolute_section && sec != NULL)
17623 as_bad_where (fragp->fr_file, fragp->fr_line, _("unsupported relocation"));
17625 if ((val & ((1 << op->shift) - 1)) != 0
17626 || val < (mintiny << op->shift)
17627 || val > (maxtiny << op->shift))
17633 /* Compute the length of a branch sequence, and adjust the
17634 RELAX_BRANCH_TOOFAR bit accordingly. If FRAGP is NULL, the
17635 worst-case length is computed, with UPDATE being used to indicate
17636 whether an unconditional (-1), branch-likely (+1) or regular (0)
17637 branch is to be computed. */
17639 relaxed_branch_length (fragS *fragp, asection *sec, int update)
17641 bfd_boolean toofar;
17645 && S_IS_DEFINED (fragp->fr_symbol)
17646 && sec == S_GET_SEGMENT (fragp->fr_symbol))
17651 val = S_GET_VALUE (fragp->fr_symbol) + fragp->fr_offset;
17653 addr = fragp->fr_address + fragp->fr_fix + 4;
17657 toofar = val < - (0x8000 << 2) || val >= (0x8000 << 2);
17660 /* If the symbol is not defined or it's in a different segment,
17661 assume the user knows what's going on and emit a short
17667 if (fragp && update && toofar != RELAX_BRANCH_TOOFAR (fragp->fr_subtype))
17669 = RELAX_BRANCH_ENCODE (RELAX_BRANCH_AT (fragp->fr_subtype),
17670 RELAX_BRANCH_UNCOND (fragp->fr_subtype),
17671 RELAX_BRANCH_LIKELY (fragp->fr_subtype),
17672 RELAX_BRANCH_LINK (fragp->fr_subtype),
17678 if (fragp ? RELAX_BRANCH_LIKELY (fragp->fr_subtype) : (update > 0))
17681 if (mips_pic != NO_PIC)
17683 /* Additional space for PIC loading of target address. */
17685 if (mips_opts.isa == ISA_MIPS1)
17686 /* Additional space for $at-stabilizing nop. */
17690 /* If branch is conditional. */
17691 if (fragp ? !RELAX_BRANCH_UNCOND (fragp->fr_subtype) : (update >= 0))
17698 /* Compute the length of a branch sequence, and adjust the
17699 RELAX_MICROMIPS_TOOFAR32 bit accordingly. If FRAGP is NULL, the
17700 worst-case length is computed, with UPDATE being used to indicate
17701 whether an unconditional (-1), or regular (0) branch is to be
17705 relaxed_micromips_32bit_branch_length (fragS *fragp, asection *sec, int update)
17707 bfd_boolean toofar;
17711 && S_IS_DEFINED (fragp->fr_symbol)
17712 && sec == S_GET_SEGMENT (fragp->fr_symbol))
17717 val = S_GET_VALUE (fragp->fr_symbol) + fragp->fr_offset;
17718 /* Ignore the low bit in the target, since it will be set
17719 for a text label. */
17720 if ((val & 1) != 0)
17723 addr = fragp->fr_address + fragp->fr_fix + 4;
17727 toofar = val < - (0x8000 << 1) || val >= (0x8000 << 1);
17730 /* If the symbol is not defined or it's in a different segment,
17731 assume the user knows what's going on and emit a short
17737 if (fragp && update
17738 && toofar != RELAX_MICROMIPS_TOOFAR32 (fragp->fr_subtype))
17739 fragp->fr_subtype = (toofar
17740 ? RELAX_MICROMIPS_MARK_TOOFAR32 (fragp->fr_subtype)
17741 : RELAX_MICROMIPS_CLEAR_TOOFAR32 (fragp->fr_subtype));
17746 bfd_boolean compact_known = fragp != NULL;
17747 bfd_boolean compact = FALSE;
17748 bfd_boolean uncond;
17751 compact = RELAX_MICROMIPS_COMPACT (fragp->fr_subtype);
17753 uncond = RELAX_MICROMIPS_UNCOND (fragp->fr_subtype);
17755 uncond = update < 0;
17757 /* If label is out of range, we turn branch <br>:
17759 <br> label # 4 bytes
17765 nop # 2 bytes if compact && !PIC
17768 if (mips_pic == NO_PIC && (!compact_known || compact))
17771 /* If assembling PIC code, we further turn:
17777 lw/ld at, %got(label)(gp) # 4 bytes
17778 d/addiu at, %lo(label) # 4 bytes
17781 if (mips_pic != NO_PIC)
17784 /* If branch <br> is conditional, we prepend negated branch <brneg>:
17786 <brneg> 0f # 4 bytes
17787 nop # 2 bytes if !compact
17790 length += (compact_known && compact) ? 4 : 6;
17796 /* Compute the length of a branch, and adjust the RELAX_MICROMIPS_TOOFAR16
17797 bit accordingly. */
17800 relaxed_micromips_16bit_branch_length (fragS *fragp, asection *sec, int update)
17802 bfd_boolean toofar;
17805 && S_IS_DEFINED (fragp->fr_symbol)
17806 && sec == S_GET_SEGMENT (fragp->fr_symbol))
17812 val = S_GET_VALUE (fragp->fr_symbol) + fragp->fr_offset;
17813 /* Ignore the low bit in the target, since it will be set
17814 for a text label. */
17815 if ((val & 1) != 0)
17818 /* Assume this is a 2-byte branch. */
17819 addr = fragp->fr_address + fragp->fr_fix + 2;
17821 /* We try to avoid the infinite loop by not adding 2 more bytes for
17826 type = RELAX_MICROMIPS_TYPE (fragp->fr_subtype);
17828 toofar = val < - (0x200 << 1) || val >= (0x200 << 1);
17829 else if (type == 'E')
17830 toofar = val < - (0x40 << 1) || val >= (0x40 << 1);
17835 /* If the symbol is not defined or it's in a different segment,
17836 we emit a normal 32-bit branch. */
17839 if (fragp && update
17840 && toofar != RELAX_MICROMIPS_TOOFAR16 (fragp->fr_subtype))
17842 = toofar ? RELAX_MICROMIPS_MARK_TOOFAR16 (fragp->fr_subtype)
17843 : RELAX_MICROMIPS_CLEAR_TOOFAR16 (fragp->fr_subtype);
17851 /* Estimate the size of a frag before relaxing. Unless this is the
17852 mips16, we are not really relaxing here, and the final size is
17853 encoded in the subtype information. For the mips16, we have to
17854 decide whether we are using an extended opcode or not. */
17857 md_estimate_size_before_relax (fragS *fragp, asection *segtype)
17861 if (RELAX_BRANCH_P (fragp->fr_subtype))
17864 fragp->fr_var = relaxed_branch_length (fragp, segtype, FALSE);
17866 return fragp->fr_var;
17869 if (RELAX_MIPS16_P (fragp->fr_subtype))
17870 /* We don't want to modify the EXTENDED bit here; it might get us
17871 into infinite loops. We change it only in mips_relax_frag(). */
17872 return (RELAX_MIPS16_EXTENDED (fragp->fr_subtype) ? 4 : 2);
17874 if (RELAX_MICROMIPS_P (fragp->fr_subtype))
17878 if (RELAX_MICROMIPS_TYPE (fragp->fr_subtype) != 0)
17879 length = relaxed_micromips_16bit_branch_length (fragp, segtype, FALSE);
17880 if (length == 4 && RELAX_MICROMIPS_RELAX32 (fragp->fr_subtype))
17881 length = relaxed_micromips_32bit_branch_length (fragp, segtype, FALSE);
17882 fragp->fr_var = length;
17887 if (mips_pic == NO_PIC)
17888 change = nopic_need_relax (fragp->fr_symbol, 0);
17889 else if (mips_pic == SVR4_PIC)
17890 change = pic_need_relax (fragp->fr_symbol, segtype);
17891 else if (mips_pic == VXWORKS_PIC)
17892 /* For vxworks, GOT16 relocations never have a corresponding LO16. */
17899 fragp->fr_subtype |= RELAX_USE_SECOND;
17900 return -RELAX_FIRST (fragp->fr_subtype);
17903 return -RELAX_SECOND (fragp->fr_subtype);
17906 /* This is called to see whether a reloc against a defined symbol
17907 should be converted into a reloc against a section. */
17910 mips_fix_adjustable (fixS *fixp)
17912 if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT
17913 || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
17916 if (fixp->fx_addsy == NULL)
17919 /* If symbol SYM is in a mergeable section, relocations of the form
17920 SYM + 0 can usually be made section-relative. The mergeable data
17921 is then identified by the section offset rather than by the symbol.
17923 However, if we're generating REL LO16 relocations, the offset is split
17924 between the LO16 and parterning high part relocation. The linker will
17925 need to recalculate the complete offset in order to correctly identify
17928 The linker has traditionally not looked for the parterning high part
17929 relocation, and has thus allowed orphaned R_MIPS_LO16 relocations to be
17930 placed anywhere. Rather than break backwards compatibility by changing
17931 this, it seems better not to force the issue, and instead keep the
17932 original symbol. This will work with either linker behavior. */
17933 if ((lo16_reloc_p (fixp->fx_r_type)
17934 || reloc_needs_lo_p (fixp->fx_r_type))
17935 && HAVE_IN_PLACE_ADDENDS
17936 && (S_GET_SEGMENT (fixp->fx_addsy)->flags & SEC_MERGE) != 0)
17939 /* There is no place to store an in-place offset for JALR relocations.
17940 Likewise an in-range offset of limited PC-relative relocations may
17941 overflow the in-place relocatable field if recalculated against the
17942 start address of the symbol's containing section. */
17943 if (HAVE_IN_PLACE_ADDENDS
17944 && (limited_pcrel_reloc_p (fixp->fx_r_type)
17945 || jalr_reloc_p (fixp->fx_r_type)))
17948 /* R_MIPS16_26 relocations against non-MIPS16 functions might resolve
17949 to a floating-point stub. The same is true for non-R_MIPS16_26
17950 relocations against MIPS16 functions; in this case, the stub becomes
17951 the function's canonical address.
17953 Floating-point stubs are stored in unique .mips16.call.* or
17954 .mips16.fn.* sections. If a stub T for function F is in section S,
17955 the first relocation in section S must be against F; this is how the
17956 linker determines the target function. All relocations that might
17957 resolve to T must also be against F. We therefore have the following
17958 restrictions, which are given in an intentionally-redundant way:
17960 1. We cannot reduce R_MIPS16_26 relocations against non-MIPS16
17963 2. We cannot reduce a stub's relocations against non-MIPS16 symbols
17964 if that stub might be used.
17966 3. We cannot reduce non-R_MIPS16_26 relocations against MIPS16
17969 4. We cannot reduce a stub's relocations against MIPS16 symbols if
17970 that stub might be used.
17972 There is a further restriction:
17974 5. We cannot reduce jump relocations (R_MIPS_26, R_MIPS16_26 or
17975 R_MICROMIPS_26_S1) against MIPS16 or microMIPS symbols on
17976 targets with in-place addends; the relocation field cannot
17977 encode the low bit.
17979 For simplicity, we deal with (3)-(4) by not reducing _any_ relocation
17980 against a MIPS16 symbol. We deal with (5) by by not reducing any
17981 such relocations on REL targets.
17983 We deal with (1)-(2) by saying that, if there's a R_MIPS16_26
17984 relocation against some symbol R, no relocation against R may be
17985 reduced. (Note that this deals with (2) as well as (1) because
17986 relocations against global symbols will never be reduced on ELF
17987 targets.) This approach is a little simpler than trying to detect
17988 stub sections, and gives the "all or nothing" per-symbol consistency
17989 that we have for MIPS16 symbols. */
17990 if (fixp->fx_subsy == NULL
17991 && (ELF_ST_IS_MIPS16 (S_GET_OTHER (fixp->fx_addsy))
17992 || *symbol_get_tc (fixp->fx_addsy)
17993 || (HAVE_IN_PLACE_ADDENDS
17994 && ELF_ST_IS_MICROMIPS (S_GET_OTHER (fixp->fx_addsy))
17995 && jmp_reloc_p (fixp->fx_r_type))))
18001 /* Translate internal representation of relocation info to BFD target
18005 tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixp)
18007 static arelent *retval[4];
18009 bfd_reloc_code_real_type code;
18011 memset (retval, 0, sizeof(retval));
18012 reloc = retval[0] = (arelent *) xcalloc (1, sizeof (arelent));
18013 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
18014 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
18015 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
18017 if (fixp->fx_pcrel)
18019 gas_assert (fixp->fx_r_type == BFD_RELOC_16_PCREL_S2
18020 || fixp->fx_r_type == BFD_RELOC_MICROMIPS_7_PCREL_S1
18021 || fixp->fx_r_type == BFD_RELOC_MICROMIPS_10_PCREL_S1
18022 || fixp->fx_r_type == BFD_RELOC_MICROMIPS_16_PCREL_S1
18023 || fixp->fx_r_type == BFD_RELOC_32_PCREL);
18025 /* At this point, fx_addnumber is "symbol offset - pcrel address".
18026 Relocations want only the symbol offset. */
18027 reloc->addend = fixp->fx_addnumber + reloc->address;
18030 reloc->addend = fixp->fx_addnumber;
18032 /* Since the old MIPS ELF ABI uses Rel instead of Rela, encode the vtable
18033 entry to be used in the relocation's section offset. */
18034 if (! HAVE_NEWABI && fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
18036 reloc->address = reloc->addend;
18040 code = fixp->fx_r_type;
18042 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
18043 if (reloc->howto == NULL)
18045 as_bad_where (fixp->fx_file, fixp->fx_line,
18046 _("Can not represent %s relocation in this object file format"),
18047 bfd_get_reloc_code_name (code));
18054 /* Relax a machine dependent frag. This returns the amount by which
18055 the current size of the frag should change. */
18058 mips_relax_frag (asection *sec, fragS *fragp, long stretch)
18060 if (RELAX_BRANCH_P (fragp->fr_subtype))
18062 offsetT old_var = fragp->fr_var;
18064 fragp->fr_var = relaxed_branch_length (fragp, sec, TRUE);
18066 return fragp->fr_var - old_var;
18069 if (RELAX_MICROMIPS_P (fragp->fr_subtype))
18071 offsetT old_var = fragp->fr_var;
18072 offsetT new_var = 4;
18074 if (RELAX_MICROMIPS_TYPE (fragp->fr_subtype) != 0)
18075 new_var = relaxed_micromips_16bit_branch_length (fragp, sec, TRUE);
18076 if (new_var == 4 && RELAX_MICROMIPS_RELAX32 (fragp->fr_subtype))
18077 new_var = relaxed_micromips_32bit_branch_length (fragp, sec, TRUE);
18078 fragp->fr_var = new_var;
18080 return new_var - old_var;
18083 if (! RELAX_MIPS16_P (fragp->fr_subtype))
18086 if (mips16_extended_frag (fragp, NULL, stretch))
18088 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
18090 fragp->fr_subtype = RELAX_MIPS16_MARK_EXTENDED (fragp->fr_subtype);
18095 if (! RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
18097 fragp->fr_subtype = RELAX_MIPS16_CLEAR_EXTENDED (fragp->fr_subtype);
18104 /* Convert a machine dependent frag. */
18107 md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, segT asec, fragS *fragp)
18109 if (RELAX_BRANCH_P (fragp->fr_subtype))
18112 unsigned long insn;
18116 buf = fragp->fr_literal + fragp->fr_fix;
18117 insn = read_insn (buf);
18119 if (!RELAX_BRANCH_TOOFAR (fragp->fr_subtype))
18121 /* We generate a fixup instead of applying it right now
18122 because, if there are linker relaxations, we're going to
18123 need the relocations. */
18124 exp.X_op = O_symbol;
18125 exp.X_add_symbol = fragp->fr_symbol;
18126 exp.X_add_number = fragp->fr_offset;
18128 fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 4, &exp, TRUE,
18129 BFD_RELOC_16_PCREL_S2);
18130 fixp->fx_file = fragp->fr_file;
18131 fixp->fx_line = fragp->fr_line;
18133 buf = write_insn (buf, insn);
18139 as_warn_where (fragp->fr_file, fragp->fr_line,
18140 _("Relaxed out-of-range branch into a jump"));
18142 if (RELAX_BRANCH_UNCOND (fragp->fr_subtype))
18145 if (!RELAX_BRANCH_LIKELY (fragp->fr_subtype))
18147 /* Reverse the branch. */
18148 switch ((insn >> 28) & 0xf)
18151 /* bc[0-3][tf]l? instructions can have the condition
18152 reversed by tweaking a single TF bit, and their
18153 opcodes all have 0x4???????. */
18154 gas_assert ((insn & 0xf3e00000) == 0x41000000);
18155 insn ^= 0x00010000;
18159 /* bltz 0x04000000 bgez 0x04010000
18160 bltzal 0x04100000 bgezal 0x04110000 */
18161 gas_assert ((insn & 0xfc0e0000) == 0x04000000);
18162 insn ^= 0x00010000;
18166 /* beq 0x10000000 bne 0x14000000
18167 blez 0x18000000 bgtz 0x1c000000 */
18168 insn ^= 0x04000000;
18176 if (RELAX_BRANCH_LINK (fragp->fr_subtype))
18178 /* Clear the and-link bit. */
18179 gas_assert ((insn & 0xfc1c0000) == 0x04100000);
18181 /* bltzal 0x04100000 bgezal 0x04110000
18182 bltzall 0x04120000 bgezall 0x04130000 */
18183 insn &= ~0x00100000;
18186 /* Branch over the branch (if the branch was likely) or the
18187 full jump (not likely case). Compute the offset from the
18188 current instruction to branch to. */
18189 if (RELAX_BRANCH_LIKELY (fragp->fr_subtype))
18193 /* How many bytes in instructions we've already emitted? */
18194 i = buf - fragp->fr_literal - fragp->fr_fix;
18195 /* How many bytes in instructions from here to the end? */
18196 i = fragp->fr_var - i;
18198 /* Convert to instruction count. */
18200 /* Branch counts from the next instruction. */
18203 /* Branch over the jump. */
18204 buf = write_insn (buf, insn);
18207 buf = write_insn (buf, 0);
18209 if (RELAX_BRANCH_LIKELY (fragp->fr_subtype))
18211 /* beql $0, $0, 2f */
18213 /* Compute the PC offset from the current instruction to
18214 the end of the variable frag. */
18215 /* How many bytes in instructions we've already emitted? */
18216 i = buf - fragp->fr_literal - fragp->fr_fix;
18217 /* How many bytes in instructions from here to the end? */
18218 i = fragp->fr_var - i;
18219 /* Convert to instruction count. */
18221 /* Don't decrement i, because we want to branch over the
18225 buf = write_insn (buf, insn);
18226 buf = write_insn (buf, 0);
18230 if (mips_pic == NO_PIC)
18233 insn = (RELAX_BRANCH_LINK (fragp->fr_subtype)
18234 ? 0x0c000000 : 0x08000000);
18235 exp.X_op = O_symbol;
18236 exp.X_add_symbol = fragp->fr_symbol;
18237 exp.X_add_number = fragp->fr_offset;
18239 fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 4, &exp,
18240 FALSE, BFD_RELOC_MIPS_JMP);
18241 fixp->fx_file = fragp->fr_file;
18242 fixp->fx_line = fragp->fr_line;
18244 buf = write_insn (buf, insn);
18248 unsigned long at = RELAX_BRANCH_AT (fragp->fr_subtype);
18250 /* lw/ld $at, <sym>($gp) R_MIPS_GOT16 */
18251 insn = HAVE_64BIT_ADDRESSES ? 0xdf800000 : 0x8f800000;
18252 insn |= at << OP_SH_RT;
18253 exp.X_op = O_symbol;
18254 exp.X_add_symbol = fragp->fr_symbol;
18255 exp.X_add_number = fragp->fr_offset;
18257 if (fragp->fr_offset)
18259 exp.X_add_symbol = make_expr_symbol (&exp);
18260 exp.X_add_number = 0;
18263 fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 4, &exp,
18264 FALSE, BFD_RELOC_MIPS_GOT16);
18265 fixp->fx_file = fragp->fr_file;
18266 fixp->fx_line = fragp->fr_line;
18268 buf = write_insn (buf, insn);
18270 if (mips_opts.isa == ISA_MIPS1)
18272 buf = write_insn (buf, 0);
18274 /* d/addiu $at, $at, <sym> R_MIPS_LO16 */
18275 insn = HAVE_64BIT_ADDRESSES ? 0x64000000 : 0x24000000;
18276 insn |= at << OP_SH_RS | at << OP_SH_RT;
18278 fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 4, &exp,
18279 FALSE, BFD_RELOC_LO16);
18280 fixp->fx_file = fragp->fr_file;
18281 fixp->fx_line = fragp->fr_line;
18283 buf = write_insn (buf, insn);
18286 if (RELAX_BRANCH_LINK (fragp->fr_subtype))
18290 insn |= at << OP_SH_RS;
18292 buf = write_insn (buf, insn);
18296 fragp->fr_fix += fragp->fr_var;
18297 gas_assert (buf == fragp->fr_literal + fragp->fr_fix);
18301 /* Relax microMIPS branches. */
18302 if (RELAX_MICROMIPS_P (fragp->fr_subtype))
18304 char *buf = fragp->fr_literal + fragp->fr_fix;
18305 bfd_boolean compact = RELAX_MICROMIPS_COMPACT (fragp->fr_subtype);
18306 bfd_boolean al = RELAX_MICROMIPS_LINK (fragp->fr_subtype);
18307 int type = RELAX_MICROMIPS_TYPE (fragp->fr_subtype);
18308 bfd_boolean short_ds;
18309 unsigned long insn;
18313 exp.X_op = O_symbol;
18314 exp.X_add_symbol = fragp->fr_symbol;
18315 exp.X_add_number = fragp->fr_offset;
18317 fragp->fr_fix += fragp->fr_var;
18319 /* Handle 16-bit branches that fit or are forced to fit. */
18320 if (type != 0 && !RELAX_MICROMIPS_TOOFAR16 (fragp->fr_subtype))
18322 /* We generate a fixup instead of applying it right now,
18323 because if there is linker relaxation, we're going to
18324 need the relocations. */
18326 fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 2, &exp, TRUE,
18327 BFD_RELOC_MICROMIPS_10_PCREL_S1);
18328 else if (type == 'E')
18329 fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 2, &exp, TRUE,
18330 BFD_RELOC_MICROMIPS_7_PCREL_S1);
18334 fixp->fx_file = fragp->fr_file;
18335 fixp->fx_line = fragp->fr_line;
18337 /* These relocations can have an addend that won't fit in
18339 fixp->fx_no_overflow = 1;
18344 /* Handle 32-bit branches that fit or are forced to fit. */
18345 if (!RELAX_MICROMIPS_RELAX32 (fragp->fr_subtype)
18346 || !RELAX_MICROMIPS_TOOFAR32 (fragp->fr_subtype))
18348 /* We generate a fixup instead of applying it right now,
18349 because if there is linker relaxation, we're going to
18350 need the relocations. */
18351 fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 4, &exp, TRUE,
18352 BFD_RELOC_MICROMIPS_16_PCREL_S1);
18353 fixp->fx_file = fragp->fr_file;
18354 fixp->fx_line = fragp->fr_line;
18360 /* Relax 16-bit branches to 32-bit branches. */
18363 insn = read_compressed_insn (buf, 2);
18365 if ((insn & 0xfc00) == 0xcc00) /* b16 */
18366 insn = 0x94000000; /* beq */
18367 else if ((insn & 0xdc00) == 0x8c00) /* beqz16/bnez16 */
18369 unsigned long regno;
18371 regno = (insn >> MICROMIPSOP_SH_MD) & MICROMIPSOP_MASK_MD;
18372 regno = micromips_to_32_reg_d_map [regno];
18373 insn = ((insn & 0x2000) << 16) | 0x94000000; /* beq/bne */
18374 insn |= regno << MICROMIPSOP_SH_RS;
18379 /* Nothing else to do, just write it out. */
18380 if (!RELAX_MICROMIPS_RELAX32 (fragp->fr_subtype)
18381 || !RELAX_MICROMIPS_TOOFAR32 (fragp->fr_subtype))
18383 buf = write_compressed_insn (buf, insn, 4);
18384 gas_assert (buf == fragp->fr_literal + fragp->fr_fix);
18389 insn = read_compressed_insn (buf, 4);
18391 /* Relax 32-bit branches to a sequence of instructions. */
18392 as_warn_where (fragp->fr_file, fragp->fr_line,
18393 _("Relaxed out-of-range branch into a jump"));
18395 /* Set the short-delay-slot bit. */
18396 short_ds = al && (insn & 0x02000000) != 0;
18398 if (!RELAX_MICROMIPS_UNCOND (fragp->fr_subtype))
18402 /* Reverse the branch. */
18403 if ((insn & 0xfc000000) == 0x94000000 /* beq */
18404 || (insn & 0xfc000000) == 0xb4000000) /* bne */
18405 insn ^= 0x20000000;
18406 else if ((insn & 0xffe00000) == 0x40000000 /* bltz */
18407 || (insn & 0xffe00000) == 0x40400000 /* bgez */
18408 || (insn & 0xffe00000) == 0x40800000 /* blez */
18409 || (insn & 0xffe00000) == 0x40c00000 /* bgtz */
18410 || (insn & 0xffe00000) == 0x40a00000 /* bnezc */
18411 || (insn & 0xffe00000) == 0x40e00000 /* beqzc */
18412 || (insn & 0xffe00000) == 0x40200000 /* bltzal */
18413 || (insn & 0xffe00000) == 0x40600000 /* bgezal */
18414 || (insn & 0xffe00000) == 0x42200000 /* bltzals */
18415 || (insn & 0xffe00000) == 0x42600000) /* bgezals */
18416 insn ^= 0x00400000;
18417 else if ((insn & 0xffe30000) == 0x43800000 /* bc1f */
18418 || (insn & 0xffe30000) == 0x43a00000 /* bc1t */
18419 || (insn & 0xffe30000) == 0x42800000 /* bc2f */
18420 || (insn & 0xffe30000) == 0x42a00000) /* bc2t */
18421 insn ^= 0x00200000;
18427 /* Clear the and-link and short-delay-slot bits. */
18428 gas_assert ((insn & 0xfda00000) == 0x40200000);
18430 /* bltzal 0x40200000 bgezal 0x40600000 */
18431 /* bltzals 0x42200000 bgezals 0x42600000 */
18432 insn &= ~0x02200000;
18435 /* Make a label at the end for use with the branch. */
18436 l = symbol_new (micromips_label_name (), asec, fragp->fr_fix, fragp);
18437 micromips_label_inc ();
18438 S_SET_OTHER (l, ELF_ST_SET_MICROMIPS (S_GET_OTHER (l)));
18441 fixp = fix_new (fragp, buf - fragp->fr_literal, 4, l, 0, TRUE,
18442 BFD_RELOC_MICROMIPS_16_PCREL_S1);
18443 fixp->fx_file = fragp->fr_file;
18444 fixp->fx_line = fragp->fr_line;
18446 /* Branch over the jump. */
18447 buf = write_compressed_insn (buf, insn, 4);
18450 buf = write_compressed_insn (buf, 0x0c00, 2);
18453 if (mips_pic == NO_PIC)
18455 unsigned long jal = short_ds ? 0x74000000 : 0xf4000000; /* jal/s */
18457 /* j/jal/jals <sym> R_MICROMIPS_26_S1 */
18458 insn = al ? jal : 0xd4000000;
18460 fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 4, &exp, FALSE,
18461 BFD_RELOC_MICROMIPS_JMP);
18462 fixp->fx_file = fragp->fr_file;
18463 fixp->fx_line = fragp->fr_line;
18465 buf = write_compressed_insn (buf, insn, 4);
18468 buf = write_compressed_insn (buf, 0x0c00, 2);
18472 unsigned long at = RELAX_MICROMIPS_AT (fragp->fr_subtype);
18473 unsigned long jalr = short_ds ? 0x45e0 : 0x45c0; /* jalr/s */
18474 unsigned long jr = compact ? 0x45a0 : 0x4580; /* jr/c */
18476 /* lw/ld $at, <sym>($gp) R_MICROMIPS_GOT16 */
18477 insn = HAVE_64BIT_ADDRESSES ? 0xdc1c0000 : 0xfc1c0000;
18478 insn |= at << MICROMIPSOP_SH_RT;
18480 if (exp.X_add_number)
18482 exp.X_add_symbol = make_expr_symbol (&exp);
18483 exp.X_add_number = 0;
18486 fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 4, &exp, FALSE,
18487 BFD_RELOC_MICROMIPS_GOT16);
18488 fixp->fx_file = fragp->fr_file;
18489 fixp->fx_line = fragp->fr_line;
18491 buf = write_compressed_insn (buf, insn, 4);
18493 /* d/addiu $at, $at, <sym> R_MICROMIPS_LO16 */
18494 insn = HAVE_64BIT_ADDRESSES ? 0x5c000000 : 0x30000000;
18495 insn |= at << MICROMIPSOP_SH_RT | at << MICROMIPSOP_SH_RS;
18497 fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 4, &exp, FALSE,
18498 BFD_RELOC_MICROMIPS_LO16);
18499 fixp->fx_file = fragp->fr_file;
18500 fixp->fx_line = fragp->fr_line;
18502 buf = write_compressed_insn (buf, insn, 4);
18504 /* jr/jrc/jalr/jalrs $at */
18505 insn = al ? jalr : jr;
18506 insn |= at << MICROMIPSOP_SH_MJ;
18508 buf = write_compressed_insn (buf, insn, 2);
18511 gas_assert (buf == fragp->fr_literal + fragp->fr_fix);
18515 if (RELAX_MIPS16_P (fragp->fr_subtype))
18518 const struct mips16_immed_operand *op;
18521 unsigned int user_length, length;
18522 unsigned long insn;
18525 type = RELAX_MIPS16_TYPE (fragp->fr_subtype);
18526 op = mips16_immed_operands;
18527 while (op->type != type)
18530 ext = RELAX_MIPS16_EXTENDED (fragp->fr_subtype);
18531 val = resolve_symbol_value (fragp->fr_symbol);
18536 addr = fragp->fr_address + fragp->fr_fix;
18538 /* The rules for the base address of a PC relative reloc are
18539 complicated; see mips16_extended_frag. */
18540 if (type == 'p' || type == 'q')
18545 /* Ignore the low bit in the target, since it will be
18546 set for a text label. */
18547 if ((val & 1) != 0)
18550 else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype))
18552 else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype))
18555 addr &= ~ (addressT) ((1 << op->shift) - 1);
18558 /* Make sure the section winds up with the alignment we have
18561 record_alignment (asec, op->shift);
18565 && (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype)
18566 || RELAX_MIPS16_DSLOT (fragp->fr_subtype)))
18567 as_warn_where (fragp->fr_file, fragp->fr_line,
18568 _("extended instruction in delay slot"));
18570 buf = fragp->fr_literal + fragp->fr_fix;
18572 insn = read_compressed_insn (buf, 2);
18574 insn |= MIPS16_EXTEND;
18576 if (RELAX_MIPS16_USER_EXT (fragp->fr_subtype))
18578 else if (RELAX_MIPS16_USER_SMALL (fragp->fr_subtype))
18583 mips16_immed (fragp->fr_file, fragp->fr_line, type,
18584 BFD_RELOC_UNUSED, val, user_length, &insn);
18586 length = (ext ? 4 : 2);
18587 gas_assert (mips16_opcode_length (insn) == length);
18588 write_compressed_insn (buf, insn, length);
18589 fragp->fr_fix += length;
18593 relax_substateT subtype = fragp->fr_subtype;
18594 bfd_boolean second_longer = (subtype & RELAX_SECOND_LONGER) != 0;
18595 bfd_boolean use_second = (subtype & RELAX_USE_SECOND) != 0;
18599 first = RELAX_FIRST (subtype);
18600 second = RELAX_SECOND (subtype);
18601 fixp = (fixS *) fragp->fr_opcode;
18603 /* If the delay slot chosen does not match the size of the instruction,
18604 then emit a warning. */
18605 if ((!use_second && (subtype & RELAX_DELAY_SLOT_SIZE_FIRST) != 0)
18606 || (use_second && (subtype & RELAX_DELAY_SLOT_SIZE_SECOND) != 0))
18611 s = subtype & (RELAX_DELAY_SLOT_16BIT
18612 | RELAX_DELAY_SLOT_SIZE_FIRST
18613 | RELAX_DELAY_SLOT_SIZE_SECOND);
18614 msg = macro_warning (s);
18616 as_warn_where (fragp->fr_file, fragp->fr_line, "%s", msg);
18620 /* Possibly emit a warning if we've chosen the longer option. */
18621 if (use_second == second_longer)
18627 & (RELAX_SECOND_LONGER | RELAX_NOMACRO | RELAX_DELAY_SLOT));
18628 msg = macro_warning (s);
18630 as_warn_where (fragp->fr_file, fragp->fr_line, "%s", msg);
18634 /* Go through all the fixups for the first sequence. Disable them
18635 (by marking them as done) if we're going to use the second
18636 sequence instead. */
18638 && fixp->fx_frag == fragp
18639 && fixp->fx_where < fragp->fr_fix - second)
18641 if (subtype & RELAX_USE_SECOND)
18643 fixp = fixp->fx_next;
18646 /* Go through the fixups for the second sequence. Disable them if
18647 we're going to use the first sequence, otherwise adjust their
18648 addresses to account for the relaxation. */
18649 while (fixp && fixp->fx_frag == fragp)
18651 if (subtype & RELAX_USE_SECOND)
18652 fixp->fx_where -= first;
18655 fixp = fixp->fx_next;
18658 /* Now modify the frag contents. */
18659 if (subtype & RELAX_USE_SECOND)
18663 start = fragp->fr_literal + fragp->fr_fix - first - second;
18664 memmove (start, start + first, second);
18665 fragp->fr_fix -= first;
18668 fragp->fr_fix -= second;
18672 /* This function is called after the relocs have been generated.
18673 We've been storing mips16 text labels as odd. Here we convert them
18674 back to even for the convenience of the debugger. */
18677 mips_frob_file_after_relocs (void)
18680 unsigned int count, i;
18682 syms = bfd_get_outsymbols (stdoutput);
18683 count = bfd_get_symcount (stdoutput);
18684 for (i = 0; i < count; i++, syms++)
18685 if (ELF_ST_IS_COMPRESSED (elf_symbol (*syms)->internal_elf_sym.st_other)
18686 && ((*syms)->value & 1) != 0)
18688 (*syms)->value &= ~1;
18689 /* If the symbol has an odd size, it was probably computed
18690 incorrectly, so adjust that as well. */
18691 if ((elf_symbol (*syms)->internal_elf_sym.st_size & 1) != 0)
18692 ++elf_symbol (*syms)->internal_elf_sym.st_size;
18696 /* This function is called whenever a label is defined, including fake
18697 labels instantiated off the dot special symbol. It is used when
18698 handling branch delays; if a branch has a label, we assume we cannot
18699 move it. This also bumps the value of the symbol by 1 in compressed
18703 mips_record_label (symbolS *sym)
18705 segment_info_type *si = seg_info (now_seg);
18706 struct insn_label_list *l;
18708 if (free_insn_labels == NULL)
18709 l = (struct insn_label_list *) xmalloc (sizeof *l);
18712 l = free_insn_labels;
18713 free_insn_labels = l->next;
18717 l->next = si->label_list;
18718 si->label_list = l;
18721 /* This function is called as tc_frob_label() whenever a label is defined
18722 and adds a DWARF-2 record we only want for true labels. */
18725 mips_define_label (symbolS *sym)
18727 mips_record_label (sym);
18728 dwarf2_emit_label (sym);
18731 /* This function is called by tc_new_dot_label whenever a new dot symbol
18735 mips_add_dot_label (symbolS *sym)
18737 mips_record_label (sym);
18738 if (mips_assembling_insn && HAVE_CODE_COMPRESSION)
18739 mips_compressed_mark_label (sym);
18742 /* Some special processing for a MIPS ELF file. */
18745 mips_elf_final_processing (void)
18747 /* Write out the register information. */
18748 if (mips_abi != N64_ABI)
18752 s.ri_gprmask = mips_gprmask;
18753 s.ri_cprmask[0] = mips_cprmask[0];
18754 s.ri_cprmask[1] = mips_cprmask[1];
18755 s.ri_cprmask[2] = mips_cprmask[2];
18756 s.ri_cprmask[3] = mips_cprmask[3];
18757 /* The gp_value field is set by the MIPS ELF backend. */
18759 bfd_mips_elf32_swap_reginfo_out (stdoutput, &s,
18760 ((Elf32_External_RegInfo *)
18761 mips_regmask_frag));
18765 Elf64_Internal_RegInfo s;
18767 s.ri_gprmask = mips_gprmask;
18769 s.ri_cprmask[0] = mips_cprmask[0];
18770 s.ri_cprmask[1] = mips_cprmask[1];
18771 s.ri_cprmask[2] = mips_cprmask[2];
18772 s.ri_cprmask[3] = mips_cprmask[3];
18773 /* The gp_value field is set by the MIPS ELF backend. */
18775 bfd_mips_elf64_swap_reginfo_out (stdoutput, &s,
18776 ((Elf64_External_RegInfo *)
18777 mips_regmask_frag));
18780 /* Set the MIPS ELF flag bits. FIXME: There should probably be some
18781 sort of BFD interface for this. */
18782 if (mips_any_noreorder)
18783 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_NOREORDER;
18784 if (mips_pic != NO_PIC)
18786 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_PIC;
18787 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_CPIC;
18790 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_CPIC;
18792 /* Set MIPS ELF flags for ASEs. Note that not all ASEs have flags
18793 defined at present; this might need to change in future. */
18794 if (file_ase_mips16)
18795 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ARCH_ASE_M16;
18796 if (file_ase_micromips)
18797 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ARCH_ASE_MICROMIPS;
18798 if (file_ase & ASE_MDMX)
18799 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ARCH_ASE_MDMX;
18801 /* Set the MIPS ELF ABI flags. */
18802 if (mips_abi == O32_ABI && USE_E_MIPS_ABI_O32)
18803 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O32;
18804 else if (mips_abi == O64_ABI)
18805 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O64;
18806 else if (mips_abi == EABI_ABI)
18808 if (!file_mips_gp32)
18809 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI64;
18811 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI32;
18813 else if (mips_abi == N32_ABI)
18814 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ABI2;
18816 /* Nothing to do for N64_ABI. */
18818 if (mips_32bitmode)
18819 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_32BITMODE;
18821 #if 0 /* XXX FIXME */
18822 /* 32 bit code with 64 bit FP registers. */
18823 if (!file_mips_fp32 && ABI_NEEDS_32BIT_REGS (mips_abi))
18824 elf_elfheader (stdoutput)->e_flags |= ???;
18828 typedef struct proc {
18830 symbolS *func_end_sym;
18831 unsigned long reg_mask;
18832 unsigned long reg_offset;
18833 unsigned long fpreg_mask;
18834 unsigned long fpreg_offset;
18835 unsigned long frame_offset;
18836 unsigned long frame_reg;
18837 unsigned long pc_reg;
18840 static procS cur_proc;
18841 static procS *cur_proc_ptr;
18842 static int numprocs;
18844 /* Implement NOP_OPCODE. We encode a MIPS16 nop as "1", a microMIPS nop
18845 as "2", and a normal nop as "0". */
18847 #define NOP_OPCODE_MIPS 0
18848 #define NOP_OPCODE_MIPS16 1
18849 #define NOP_OPCODE_MICROMIPS 2
18852 mips_nop_opcode (void)
18854 if (seg_info (now_seg)->tc_segment_info_data.micromips)
18855 return NOP_OPCODE_MICROMIPS;
18856 else if (seg_info (now_seg)->tc_segment_info_data.mips16)
18857 return NOP_OPCODE_MIPS16;
18859 return NOP_OPCODE_MIPS;
18862 /* Fill in an rs_align_code fragment. Unlike elsewhere we want to use
18863 32-bit microMIPS NOPs here (if applicable). */
18866 mips_handle_align (fragS *fragp)
18870 int bytes, size, excess;
18873 if (fragp->fr_type != rs_align_code)
18876 p = fragp->fr_literal + fragp->fr_fix;
18878 switch (nop_opcode)
18880 case NOP_OPCODE_MICROMIPS:
18881 opcode = micromips_nop32_insn.insn_opcode;
18884 case NOP_OPCODE_MIPS16:
18885 opcode = mips16_nop_insn.insn_opcode;
18888 case NOP_OPCODE_MIPS:
18890 opcode = nop_insn.insn_opcode;
18895 bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
18896 excess = bytes % size;
18898 /* Handle the leading part if we're not inserting a whole number of
18899 instructions, and make it the end of the fixed part of the frag.
18900 Try to fit in a short microMIPS NOP if applicable and possible,
18901 and use zeroes otherwise. */
18902 gas_assert (excess < 4);
18903 fragp->fr_fix += excess;
18908 /* Fall through. */
18910 if (nop_opcode == NOP_OPCODE_MICROMIPS)
18912 p = write_compressed_insn (p, micromips_nop16_insn.insn_opcode, 2);
18916 /* Fall through. */
18919 /* Fall through. */
18924 md_number_to_chars (p, opcode, size);
18925 fragp->fr_var = size;
18929 md_obj_begin (void)
18936 /* Check for premature end, nesting errors, etc. */
18938 as_warn (_("missing .end at end of assembly"));
18947 if (*input_line_pointer == '-')
18949 ++input_line_pointer;
18952 if (!ISDIGIT (*input_line_pointer))
18953 as_bad (_("expected simple number"));
18954 if (input_line_pointer[0] == '0')
18956 if (input_line_pointer[1] == 'x')
18958 input_line_pointer += 2;
18959 while (ISXDIGIT (*input_line_pointer))
18962 val |= hex_value (*input_line_pointer++);
18964 return negative ? -val : val;
18968 ++input_line_pointer;
18969 while (ISDIGIT (*input_line_pointer))
18972 val |= *input_line_pointer++ - '0';
18974 return negative ? -val : val;
18977 if (!ISDIGIT (*input_line_pointer))
18979 printf (_(" *input_line_pointer == '%c' 0x%02x\n"),
18980 *input_line_pointer, *input_line_pointer);
18981 as_warn (_("invalid number"));
18984 while (ISDIGIT (*input_line_pointer))
18987 val += *input_line_pointer++ - '0';
18989 return negative ? -val : val;
18992 /* The .file directive; just like the usual .file directive, but there
18993 is an initial number which is the ECOFF file index. In the non-ECOFF
18994 case .file implies DWARF-2. */
18997 s_mips_file (int x ATTRIBUTE_UNUSED)
18999 static int first_file_directive = 0;
19001 if (ECOFF_DEBUGGING)
19010 filename = dwarf2_directive_file (0);
19012 /* Versions of GCC up to 3.1 start files with a ".file"
19013 directive even for stabs output. Make sure that this
19014 ".file" is handled. Note that you need a version of GCC
19015 after 3.1 in order to support DWARF-2 on MIPS. */
19016 if (filename != NULL && ! first_file_directive)
19018 (void) new_logical_line (filename, -1);
19019 s_app_file_string (filename, 0);
19021 first_file_directive = 1;
19025 /* The .loc directive, implying DWARF-2. */
19028 s_mips_loc (int x ATTRIBUTE_UNUSED)
19030 if (!ECOFF_DEBUGGING)
19031 dwarf2_directive_loc (0);
19034 /* The .end directive. */
19037 s_mips_end (int x ATTRIBUTE_UNUSED)
19041 /* Following functions need their own .frame and .cprestore directives. */
19042 mips_frame_reg_valid = 0;
19043 mips_cprestore_valid = 0;
19045 if (!is_end_of_line[(unsigned char) *input_line_pointer])
19048 demand_empty_rest_of_line ();
19053 if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) == 0)
19054 as_warn (_(".end not in text section"));
19058 as_warn (_(".end directive without a preceding .ent directive."));
19059 demand_empty_rest_of_line ();
19065 gas_assert (S_GET_NAME (p));
19066 if (strcmp (S_GET_NAME (p), S_GET_NAME (cur_proc_ptr->func_sym)))
19067 as_warn (_(".end symbol does not match .ent symbol."));
19069 if (debug_type == DEBUG_STABS)
19070 stabs_generate_asm_endfunc (S_GET_NAME (p),
19074 as_warn (_(".end directive missing or unknown symbol"));
19076 /* Create an expression to calculate the size of the function. */
19077 if (p && cur_proc_ptr)
19079 OBJ_SYMFIELD_TYPE *obj = symbol_get_obj (p);
19080 expressionS *exp = xmalloc (sizeof (expressionS));
19083 exp->X_op = O_subtract;
19084 exp->X_add_symbol = symbol_temp_new_now ();
19085 exp->X_op_symbol = p;
19086 exp->X_add_number = 0;
19088 cur_proc_ptr->func_end_sym = exp->X_add_symbol;
19091 /* Generate a .pdr section. */
19092 if (!ECOFF_DEBUGGING && mips_flag_pdr)
19094 segT saved_seg = now_seg;
19095 subsegT saved_subseg = now_subseg;
19099 #ifdef md_flush_pending_output
19100 md_flush_pending_output ();
19103 gas_assert (pdr_seg);
19104 subseg_set (pdr_seg, 0);
19106 /* Write the symbol. */
19107 exp.X_op = O_symbol;
19108 exp.X_add_symbol = p;
19109 exp.X_add_number = 0;
19110 emit_expr (&exp, 4);
19112 fragp = frag_more (7 * 4);
19114 md_number_to_chars (fragp, cur_proc_ptr->reg_mask, 4);
19115 md_number_to_chars (fragp + 4, cur_proc_ptr->reg_offset, 4);
19116 md_number_to_chars (fragp + 8, cur_proc_ptr->fpreg_mask, 4);
19117 md_number_to_chars (fragp + 12, cur_proc_ptr->fpreg_offset, 4);
19118 md_number_to_chars (fragp + 16, cur_proc_ptr->frame_offset, 4);
19119 md_number_to_chars (fragp + 20, cur_proc_ptr->frame_reg, 4);
19120 md_number_to_chars (fragp + 24, cur_proc_ptr->pc_reg, 4);
19122 subseg_set (saved_seg, saved_subseg);
19125 cur_proc_ptr = NULL;
19128 /* The .aent and .ent directives. */
19131 s_mips_ent (int aent)
19135 symbolP = get_symbol ();
19136 if (*input_line_pointer == ',')
19137 ++input_line_pointer;
19138 SKIP_WHITESPACE ();
19139 if (ISDIGIT (*input_line_pointer)
19140 || *input_line_pointer == '-')
19143 if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) == 0)
19144 as_warn (_(".ent or .aent not in text section."));
19146 if (!aent && cur_proc_ptr)
19147 as_warn (_("missing .end"));
19151 /* This function needs its own .frame and .cprestore directives. */
19152 mips_frame_reg_valid = 0;
19153 mips_cprestore_valid = 0;
19155 cur_proc_ptr = &cur_proc;
19156 memset (cur_proc_ptr, '\0', sizeof (procS));
19158 cur_proc_ptr->func_sym = symbolP;
19162 if (debug_type == DEBUG_STABS)
19163 stabs_generate_asm_func (S_GET_NAME (symbolP),
19164 S_GET_NAME (symbolP));
19167 symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION;
19169 demand_empty_rest_of_line ();
19172 /* The .frame directive. If the mdebug section is present (IRIX 5 native)
19173 then ecoff.c (ecoff_directive_frame) is used. For embedded targets,
19174 s_mips_frame is used so that we can set the PDR information correctly.
19175 We can't use the ecoff routines because they make reference to the ecoff
19176 symbol table (in the mdebug section). */
19179 s_mips_frame (int ignore ATTRIBUTE_UNUSED)
19181 if (ECOFF_DEBUGGING)
19187 if (cur_proc_ptr == (procS *) NULL)
19189 as_warn (_(".frame outside of .ent"));
19190 demand_empty_rest_of_line ();
19194 cur_proc_ptr->frame_reg = tc_get_register (1);
19196 SKIP_WHITESPACE ();
19197 if (*input_line_pointer++ != ','
19198 || get_absolute_expression_and_terminator (&val) != ',')
19200 as_warn (_("Bad .frame directive"));
19201 --input_line_pointer;
19202 demand_empty_rest_of_line ();
19206 cur_proc_ptr->frame_offset = val;
19207 cur_proc_ptr->pc_reg = tc_get_register (0);
19209 demand_empty_rest_of_line ();
19213 /* The .fmask and .mask directives. If the mdebug section is present
19214 (IRIX 5 native) then ecoff.c (ecoff_directive_mask) is used. For
19215 embedded targets, s_mips_mask is used so that we can set the PDR
19216 information correctly. We can't use the ecoff routines because they
19217 make reference to the ecoff symbol table (in the mdebug section). */
19220 s_mips_mask (int reg_type)
19222 if (ECOFF_DEBUGGING)
19223 s_ignore (reg_type);
19228 if (cur_proc_ptr == (procS *) NULL)
19230 as_warn (_(".mask/.fmask outside of .ent"));
19231 demand_empty_rest_of_line ();
19235 if (get_absolute_expression_and_terminator (&mask) != ',')
19237 as_warn (_("Bad .mask/.fmask directive"));
19238 --input_line_pointer;
19239 demand_empty_rest_of_line ();
19243 off = get_absolute_expression ();
19245 if (reg_type == 'F')
19247 cur_proc_ptr->fpreg_mask = mask;
19248 cur_proc_ptr->fpreg_offset = off;
19252 cur_proc_ptr->reg_mask = mask;
19253 cur_proc_ptr->reg_offset = off;
19256 demand_empty_rest_of_line ();
19260 /* A table describing all the processors gas knows about. Names are
19261 matched in the order listed.
19263 To ease comparison, please keep this table in the same order as
19264 gcc's mips_cpu_info_table[]. */
19265 static const struct mips_cpu_info mips_cpu_info_table[] =
19267 /* Entries for generic ISAs */
19268 { "mips1", MIPS_CPU_IS_ISA, 0, ISA_MIPS1, CPU_R3000 },
19269 { "mips2", MIPS_CPU_IS_ISA, 0, ISA_MIPS2, CPU_R6000 },
19270 { "mips3", MIPS_CPU_IS_ISA, 0, ISA_MIPS3, CPU_R4000 },
19271 { "mips4", MIPS_CPU_IS_ISA, 0, ISA_MIPS4, CPU_R8000 },
19272 { "mips5", MIPS_CPU_IS_ISA, 0, ISA_MIPS5, CPU_MIPS5 },
19273 { "mips32", MIPS_CPU_IS_ISA, 0, ISA_MIPS32, CPU_MIPS32 },
19274 { "mips32r2", MIPS_CPU_IS_ISA, 0, ISA_MIPS32R2, CPU_MIPS32R2 },
19275 { "mips64", MIPS_CPU_IS_ISA, 0, ISA_MIPS64, CPU_MIPS64 },
19276 { "mips64r2", MIPS_CPU_IS_ISA, 0, ISA_MIPS64R2, CPU_MIPS64R2 },
19279 { "r3000", 0, 0, ISA_MIPS1, CPU_R3000 },
19280 { "r2000", 0, 0, ISA_MIPS1, CPU_R3000 },
19281 { "r3900", 0, 0, ISA_MIPS1, CPU_R3900 },
19284 { "r6000", 0, 0, ISA_MIPS2, CPU_R6000 },
19287 { "r4000", 0, 0, ISA_MIPS3, CPU_R4000 },
19288 { "r4010", 0, 0, ISA_MIPS2, CPU_R4010 },
19289 { "vr4100", 0, 0, ISA_MIPS3, CPU_VR4100 },
19290 { "vr4111", 0, 0, ISA_MIPS3, CPU_R4111 },
19291 { "vr4120", 0, 0, ISA_MIPS3, CPU_VR4120 },
19292 { "vr4130", 0, 0, ISA_MIPS3, CPU_VR4120 },
19293 { "vr4181", 0, 0, ISA_MIPS3, CPU_R4111 },
19294 { "vr4300", 0, 0, ISA_MIPS3, CPU_R4300 },
19295 { "r4400", 0, 0, ISA_MIPS3, CPU_R4400 },
19296 { "r4600", 0, 0, ISA_MIPS3, CPU_R4600 },
19297 { "orion", 0, 0, ISA_MIPS3, CPU_R4600 },
19298 { "r4650", 0, 0, ISA_MIPS3, CPU_R4650 },
19299 { "r5900", 0, 0, ISA_MIPS3, CPU_R5900 },
19300 /* ST Microelectronics Loongson 2E and 2F cores */
19301 { "loongson2e", 0, 0, ISA_MIPS3, CPU_LOONGSON_2E },
19302 { "loongson2f", 0, 0, ISA_MIPS3, CPU_LOONGSON_2F },
19305 { "r8000", 0, 0, ISA_MIPS4, CPU_R8000 },
19306 { "r10000", 0, 0, ISA_MIPS4, CPU_R10000 },
19307 { "r12000", 0, 0, ISA_MIPS4, CPU_R12000 },
19308 { "r14000", 0, 0, ISA_MIPS4, CPU_R14000 },
19309 { "r16000", 0, 0, ISA_MIPS4, CPU_R16000 },
19310 { "vr5000", 0, 0, ISA_MIPS4, CPU_R5000 },
19311 { "vr5400", 0, 0, ISA_MIPS4, CPU_VR5400 },
19312 { "vr5500", 0, 0, ISA_MIPS4, CPU_VR5500 },
19313 { "rm5200", 0, 0, ISA_MIPS4, CPU_R5000 },
19314 { "rm5230", 0, 0, ISA_MIPS4, CPU_R5000 },
19315 { "rm5231", 0, 0, ISA_MIPS4, CPU_R5000 },
19316 { "rm5261", 0, 0, ISA_MIPS4, CPU_R5000 },
19317 { "rm5721", 0, 0, ISA_MIPS4, CPU_R5000 },
19318 { "rm7000", 0, 0, ISA_MIPS4, CPU_RM7000 },
19319 { "rm9000", 0, 0, ISA_MIPS4, CPU_RM9000 },
19322 { "4kc", 0, 0, ISA_MIPS32, CPU_MIPS32 },
19323 { "4km", 0, 0, ISA_MIPS32, CPU_MIPS32 },
19324 { "4kp", 0, 0, ISA_MIPS32, CPU_MIPS32 },
19325 { "4ksc", 0, ASE_SMARTMIPS, ISA_MIPS32, CPU_MIPS32 },
19327 /* MIPS 32 Release 2 */
19328 { "4kec", 0, 0, ISA_MIPS32R2, CPU_MIPS32R2 },
19329 { "4kem", 0, 0, ISA_MIPS32R2, CPU_MIPS32R2 },
19330 { "4kep", 0, 0, ISA_MIPS32R2, CPU_MIPS32R2 },
19331 { "4ksd", 0, ASE_SMARTMIPS, ISA_MIPS32R2, CPU_MIPS32R2 },
19332 { "m4k", 0, 0, ISA_MIPS32R2, CPU_MIPS32R2 },
19333 { "m4kp", 0, 0, ISA_MIPS32R2, CPU_MIPS32R2 },
19334 { "m14k", 0, ASE_MCU, ISA_MIPS32R2, CPU_MIPS32R2 },
19335 { "m14kc", 0, ASE_MCU, ISA_MIPS32R2, CPU_MIPS32R2 },
19336 { "m14ke", 0, ASE_DSP | ASE_DSPR2 | ASE_MCU,
19337 ISA_MIPS32R2, CPU_MIPS32R2 },
19338 { "m14kec", 0, ASE_DSP | ASE_DSPR2 | ASE_MCU,
19339 ISA_MIPS32R2, CPU_MIPS32R2 },
19340 { "24kc", 0, 0, ISA_MIPS32R2, CPU_MIPS32R2 },
19341 { "24kf2_1", 0, 0, ISA_MIPS32R2, CPU_MIPS32R2 },
19342 { "24kf", 0, 0, ISA_MIPS32R2, CPU_MIPS32R2 },
19343 { "24kf1_1", 0, 0, ISA_MIPS32R2, CPU_MIPS32R2 },
19344 /* Deprecated forms of the above. */
19345 { "24kfx", 0, 0, ISA_MIPS32R2, CPU_MIPS32R2 },
19346 { "24kx", 0, 0, ISA_MIPS32R2, CPU_MIPS32R2 },
19347 /* 24KE is a 24K with DSP ASE, other ASEs are optional. */
19348 { "24kec", 0, ASE_DSP, ISA_MIPS32R2, CPU_MIPS32R2 },
19349 { "24kef2_1", 0, ASE_DSP, ISA_MIPS32R2, CPU_MIPS32R2 },
19350 { "24kef", 0, ASE_DSP, ISA_MIPS32R2, CPU_MIPS32R2 },
19351 { "24kef1_1", 0, ASE_DSP, ISA_MIPS32R2, CPU_MIPS32R2 },
19352 /* Deprecated forms of the above. */
19353 { "24kefx", 0, ASE_DSP, ISA_MIPS32R2, CPU_MIPS32R2 },
19354 { "24kex", 0, ASE_DSP, ISA_MIPS32R2, CPU_MIPS32R2 },
19355 /* 34K is a 24K with DSP and MT ASE, other ASEs are optional. */
19356 { "34kc", 0, ASE_DSP | ASE_MT, ISA_MIPS32R2, CPU_MIPS32R2 },
19357 { "34kf2_1", 0, ASE_DSP | ASE_MT, ISA_MIPS32R2, CPU_MIPS32R2 },
19358 { "34kf", 0, ASE_DSP | ASE_MT, ISA_MIPS32R2, CPU_MIPS32R2 },
19359 { "34kf1_1", 0, ASE_DSP | ASE_MT, ISA_MIPS32R2, CPU_MIPS32R2 },
19360 /* Deprecated forms of the above. */
19361 { "34kfx", 0, ASE_DSP | ASE_MT, ISA_MIPS32R2, CPU_MIPS32R2 },
19362 { "34kx", 0, ASE_DSP | ASE_MT, ISA_MIPS32R2, CPU_MIPS32R2 },
19363 /* 34Kn is a 34kc without DSP. */
19364 { "34kn", 0, ASE_MT, ISA_MIPS32R2, CPU_MIPS32R2 },
19365 /* 74K with DSP and DSPR2 ASE, other ASEs are optional. */
19366 { "74kc", 0, ASE_DSP | ASE_DSPR2, ISA_MIPS32R2, CPU_MIPS32R2 },
19367 { "74kf2_1", 0, ASE_DSP | ASE_DSPR2, ISA_MIPS32R2, CPU_MIPS32R2 },
19368 { "74kf", 0, ASE_DSP | ASE_DSPR2, ISA_MIPS32R2, CPU_MIPS32R2 },
19369 { "74kf1_1", 0, ASE_DSP | ASE_DSPR2, ISA_MIPS32R2, CPU_MIPS32R2 },
19370 { "74kf3_2", 0, ASE_DSP | ASE_DSPR2, ISA_MIPS32R2, CPU_MIPS32R2 },
19371 /* Deprecated forms of the above. */
19372 { "74kfx", 0, ASE_DSP | ASE_DSPR2, ISA_MIPS32R2, CPU_MIPS32R2 },
19373 { "74kx", 0, ASE_DSP | ASE_DSPR2, ISA_MIPS32R2, CPU_MIPS32R2 },
19374 /* 1004K cores are multiprocessor versions of the 34K. */
19375 { "1004kc", 0, ASE_DSP | ASE_MT, ISA_MIPS32R2, CPU_MIPS32R2 },
19376 { "1004kf2_1", 0, ASE_DSP | ASE_MT, ISA_MIPS32R2, CPU_MIPS32R2 },
19377 { "1004kf", 0, ASE_DSP | ASE_MT, ISA_MIPS32R2, CPU_MIPS32R2 },
19378 { "1004kf1_1", 0, ASE_DSP | ASE_MT, ISA_MIPS32R2, CPU_MIPS32R2 },
19381 { "5kc", 0, 0, ISA_MIPS64, CPU_MIPS64 },
19382 { "5kf", 0, 0, ISA_MIPS64, CPU_MIPS64 },
19383 { "20kc", 0, ASE_MIPS3D, ISA_MIPS64, CPU_MIPS64 },
19384 { "25kf", 0, ASE_MIPS3D, ISA_MIPS64, CPU_MIPS64 },
19386 /* Broadcom SB-1 CPU core */
19387 { "sb1", 0, ASE_MIPS3D | ASE_MDMX, ISA_MIPS64, CPU_SB1 },
19388 /* Broadcom SB-1A CPU core */
19389 { "sb1a", 0, ASE_MIPS3D | ASE_MDMX, ISA_MIPS64, CPU_SB1 },
19391 { "loongson3a", 0, 0, ISA_MIPS64, CPU_LOONGSON_3A },
19393 /* MIPS 64 Release 2 */
19395 /* Cavium Networks Octeon CPU core */
19396 { "octeon", 0, 0, ISA_MIPS64R2, CPU_OCTEON },
19397 { "octeon+", 0, 0, ISA_MIPS64R2, CPU_OCTEONP },
19398 { "octeon2", 0, 0, ISA_MIPS64R2, CPU_OCTEON2 },
19401 { "xlr", 0, 0, ISA_MIPS64, CPU_XLR },
19404 XLP is mostly like XLR, with the prominent exception that it is
19405 MIPS64R2 rather than MIPS64. */
19406 { "xlp", 0, 0, ISA_MIPS64R2, CPU_XLR },
19409 { NULL, 0, 0, 0, 0 }
19413 /* Return true if GIVEN is the same as CANONICAL, or if it is CANONICAL
19414 with a final "000" replaced by "k". Ignore case.
19416 Note: this function is shared between GCC and GAS. */
19419 mips_strict_matching_cpu_name_p (const char *canonical, const char *given)
19421 while (*given != 0 && TOLOWER (*given) == TOLOWER (*canonical))
19422 given++, canonical++;
19424 return ((*given == 0 && *canonical == 0)
19425 || (strcmp (canonical, "000") == 0 && strcasecmp (given, "k") == 0));
19429 /* Return true if GIVEN matches CANONICAL, where GIVEN is a user-supplied
19430 CPU name. We've traditionally allowed a lot of variation here.
19432 Note: this function is shared between GCC and GAS. */
19435 mips_matching_cpu_name_p (const char *canonical, const char *given)
19437 /* First see if the name matches exactly, or with a final "000"
19438 turned into "k". */
19439 if (mips_strict_matching_cpu_name_p (canonical, given))
19442 /* If not, try comparing based on numerical designation alone.
19443 See if GIVEN is an unadorned number, or 'r' followed by a number. */
19444 if (TOLOWER (*given) == 'r')
19446 if (!ISDIGIT (*given))
19449 /* Skip over some well-known prefixes in the canonical name,
19450 hoping to find a number there too. */
19451 if (TOLOWER (canonical[0]) == 'v' && TOLOWER (canonical[1]) == 'r')
19453 else if (TOLOWER (canonical[0]) == 'r' && TOLOWER (canonical[1]) == 'm')
19455 else if (TOLOWER (canonical[0]) == 'r')
19458 return mips_strict_matching_cpu_name_p (canonical, given);
19462 /* Parse an option that takes the name of a processor as its argument.
19463 OPTION is the name of the option and CPU_STRING is the argument.
19464 Return the corresponding processor enumeration if the CPU_STRING is
19465 recognized, otherwise report an error and return null.
19467 A similar function exists in GCC. */
19469 static const struct mips_cpu_info *
19470 mips_parse_cpu (const char *option, const char *cpu_string)
19472 const struct mips_cpu_info *p;
19474 /* 'from-abi' selects the most compatible architecture for the given
19475 ABI: MIPS I for 32-bit ABIs and MIPS III for 64-bit ABIs. For the
19476 EABIs, we have to decide whether we're using the 32-bit or 64-bit
19477 version. Look first at the -mgp options, if given, otherwise base
19478 the choice on MIPS_DEFAULT_64BIT.
19480 Treat NO_ABI like the EABIs. One reason to do this is that the
19481 plain 'mips' and 'mips64' configs have 'from-abi' as their default
19482 architecture. This code picks MIPS I for 'mips' and MIPS III for
19483 'mips64', just as we did in the days before 'from-abi'. */
19484 if (strcasecmp (cpu_string, "from-abi") == 0)
19486 if (ABI_NEEDS_32BIT_REGS (mips_abi))
19487 return mips_cpu_info_from_isa (ISA_MIPS1);
19489 if (ABI_NEEDS_64BIT_REGS (mips_abi))
19490 return mips_cpu_info_from_isa (ISA_MIPS3);
19492 if (file_mips_gp32 >= 0)
19493 return mips_cpu_info_from_isa (file_mips_gp32 ? ISA_MIPS1 : ISA_MIPS3);
19495 return mips_cpu_info_from_isa (MIPS_DEFAULT_64BIT
19500 /* 'default' has traditionally been a no-op. Probably not very useful. */
19501 if (strcasecmp (cpu_string, "default") == 0)
19504 for (p = mips_cpu_info_table; p->name != 0; p++)
19505 if (mips_matching_cpu_name_p (p->name, cpu_string))
19508 as_bad (_("Bad value (%s) for %s"), cpu_string, option);
19512 /* Return the canonical processor information for ISA (a member of the
19513 ISA_MIPS* enumeration). */
19515 static const struct mips_cpu_info *
19516 mips_cpu_info_from_isa (int isa)
19520 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
19521 if ((mips_cpu_info_table[i].flags & MIPS_CPU_IS_ISA)
19522 && isa == mips_cpu_info_table[i].isa)
19523 return (&mips_cpu_info_table[i]);
19528 static const struct mips_cpu_info *
19529 mips_cpu_info_from_arch (int arch)
19533 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
19534 if (arch == mips_cpu_info_table[i].cpu)
19535 return (&mips_cpu_info_table[i]);
19541 show (FILE *stream, const char *string, int *col_p, int *first_p)
19545 fprintf (stream, "%24s", "");
19550 fprintf (stream, ", ");
19554 if (*col_p + strlen (string) > 72)
19556 fprintf (stream, "\n%24s", "");
19560 fprintf (stream, "%s", string);
19561 *col_p += strlen (string);
19567 md_show_usage (FILE *stream)
19572 fprintf (stream, _("\
19574 -EB generate big endian output\n\
19575 -EL generate little endian output\n\
19576 -g, -g2 do not remove unneeded NOPs or swap branches\n\
19577 -G NUM allow referencing objects up to NUM bytes\n\
19578 implicitly with the gp register [default 8]\n"));
19579 fprintf (stream, _("\
19580 -mips1 generate MIPS ISA I instructions\n\
19581 -mips2 generate MIPS ISA II instructions\n\
19582 -mips3 generate MIPS ISA III instructions\n\
19583 -mips4 generate MIPS ISA IV instructions\n\
19584 -mips5 generate MIPS ISA V instructions\n\
19585 -mips32 generate MIPS32 ISA instructions\n\
19586 -mips32r2 generate MIPS32 release 2 ISA instructions\n\
19587 -mips64 generate MIPS64 ISA instructions\n\
19588 -mips64r2 generate MIPS64 release 2 ISA instructions\n\
19589 -march=CPU/-mtune=CPU generate code/schedule for CPU, where CPU is one of:\n"));
19593 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
19594 show (stream, mips_cpu_info_table[i].name, &column, &first);
19595 show (stream, "from-abi", &column, &first);
19596 fputc ('\n', stream);
19598 fprintf (stream, _("\
19599 -mCPU equivalent to -march=CPU -mtune=CPU. Deprecated.\n\
19600 -no-mCPU don't generate code specific to CPU.\n\
19601 For -mCPU and -no-mCPU, CPU must be one of:\n"));
19605 show (stream, "3900", &column, &first);
19606 show (stream, "4010", &column, &first);
19607 show (stream, "4100", &column, &first);
19608 show (stream, "4650", &column, &first);
19609 fputc ('\n', stream);
19611 fprintf (stream, _("\
19612 -mips16 generate mips16 instructions\n\
19613 -no-mips16 do not generate mips16 instructions\n"));
19614 fprintf (stream, _("\
19615 -mmicromips generate microMIPS instructions\n\
19616 -mno-micromips do not generate microMIPS instructions\n"));
19617 fprintf (stream, _("\
19618 -msmartmips generate smartmips instructions\n\
19619 -mno-smartmips do not generate smartmips instructions\n"));
19620 fprintf (stream, _("\
19621 -mdsp generate DSP instructions\n\
19622 -mno-dsp do not generate DSP instructions\n"));
19623 fprintf (stream, _("\
19624 -mdspr2 generate DSP R2 instructions\n\
19625 -mno-dspr2 do not generate DSP R2 instructions\n"));
19626 fprintf (stream, _("\
19627 -mmt generate MT instructions\n\
19628 -mno-mt do not generate MT instructions\n"));
19629 fprintf (stream, _("\
19630 -mmcu generate MCU instructions\n\
19631 -mno-mcu do not generate MCU instructions\n"));
19632 fprintf (stream, _("\
19633 -mvirt generate Virtualization instructions\n\
19634 -mno-virt do not generate Virtualization instructions\n"));
19635 fprintf (stream, _("\
19636 -mfix-loongson2f-jump work around Loongson2F JUMP instructions\n\
19637 -mfix-loongson2f-nop work around Loongson2F NOP errata\n\
19638 -mfix-vr4120 work around certain VR4120 errata\n\
19639 -mfix-vr4130 work around VR4130 mflo/mfhi errata\n\
19640 -mfix-24k insert a nop after ERET and DERET instructions\n\
19641 -mfix-cn63xxp1 work around CN63XXP1 PREF errata\n\
19642 -mgp32 use 32-bit GPRs, regardless of the chosen ISA\n\
19643 -mfp32 use 32-bit FPRs, regardless of the chosen ISA\n\
19644 -msym32 assume all symbols have 32-bit values\n\
19645 -O0 remove unneeded NOPs, do not swap branches\n\
19646 -O remove unneeded NOPs and swap branches\n\
19647 --trap, --no-break trap exception on div by 0 and mult overflow\n\
19648 --break, --no-trap break exception on div by 0 and mult overflow\n"));
19649 fprintf (stream, _("\
19650 -mhard-float allow floating-point instructions\n\
19651 -msoft-float do not allow floating-point instructions\n\
19652 -msingle-float only allow 32-bit floating-point operations\n\
19653 -mdouble-float allow 32-bit and 64-bit floating-point operations\n\
19654 --[no-]construct-floats [dis]allow floating point values to be constructed\n\
19655 --[no-]relax-branch [dis]allow out-of-range branches to be relaxed\n"
19657 fprintf (stream, _("\
19658 -KPIC, -call_shared generate SVR4 position independent code\n\
19659 -call_nonpic generate non-PIC code that can operate with DSOs\n\
19660 -mvxworks-pic generate VxWorks position independent code\n\
19661 -non_shared do not generate code that can operate with DSOs\n\
19662 -xgot assume a 32 bit GOT\n\
19663 -mpdr, -mno-pdr enable/disable creation of .pdr sections\n\
19664 -mshared, -mno-shared disable/enable .cpload optimization for\n\
19665 position dependent (non shared) code\n\
19666 -mabi=ABI create ABI conformant object file for:\n"));
19670 show (stream, "32", &column, &first);
19671 show (stream, "o64", &column, &first);
19672 show (stream, "n32", &column, &first);
19673 show (stream, "64", &column, &first);
19674 show (stream, "eabi", &column, &first);
19676 fputc ('\n', stream);
19678 fprintf (stream, _("\
19679 -32 create o32 ABI object file (default)\n\
19680 -n32 create n32 ABI object file\n\
19681 -64 create 64 ABI object file\n"));
19686 mips_dwarf2_format (asection *sec ATTRIBUTE_UNUSED)
19688 if (HAVE_64BIT_SYMBOLS)
19689 return dwarf2_format_64bit_irix;
19691 return dwarf2_format_32bit;
19696 mips_dwarf2_addr_size (void)
19698 if (HAVE_64BIT_OBJECTS)
19704 /* Standard calling conventions leave the CFA at SP on entry. */
19706 mips_cfi_frame_initial_instructions (void)
19708 cfi_add_CFA_def_cfa_register (SP);
19712 tc_mips_regname_to_dw2regnum (char *regname)
19714 unsigned int regnum = -1;
19717 if (reg_lookup (®name, RTYPE_GP | RTYPE_NUM, ®))