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 Free Software Foundation, Inc.
4 Contributed by the OSF and Ralph Campbell.
5 Written by Keith Knowles and Ralph Campbell, working independently.
6 Modified for ECOFF and R4000 support by Ian Lance Taylor of Cygnus
9 This file is part of GAS.
11 GAS is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 3, or (at your option)
16 GAS is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with GAS; see the file COPYING. If not, write to the Free
23 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
29 #include "safe-ctype.h"
31 #include "opcode/mips.h"
33 #include "dwarf2dbg.h"
34 #include "dw2gencfi.h"
37 #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()
69 #ifndef ECOFF_DEBUGGING
70 #define NO_ECOFF_DEBUGGING
71 #define ECOFF_DEBUGGING 0
74 int mips_flag_mdebug
= -1;
76 /* Control generation of .pdr sections. Off by default on IRIX: the native
77 linker doesn't know about and discards them, but relocations against them
78 remain, leading to rld crashes. */
80 int mips_flag_pdr
= FALSE
;
82 int mips_flag_pdr
= TRUE
;
87 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
88 static char *mips_regmask_frag
;
94 #define PIC_CALL_REG 25
102 #define ILLEGAL_REG (32)
104 #define AT mips_opts.at
106 /* Allow override of standard little-endian ECOFF format. */
108 #ifndef ECOFF_LITTLE_FORMAT
109 #define ECOFF_LITTLE_FORMAT "ecoff-littlemips"
112 extern int target_big_endian
;
114 /* The name of the readonly data section. */
115 #define RDATA_SECTION_NAME (OUTPUT_FLAVOR == bfd_target_ecoff_flavour \
117 : OUTPUT_FLAVOR == bfd_target_coff_flavour \
119 : OUTPUT_FLAVOR == bfd_target_elf_flavour \
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 /* True if this is a mips16 instruction and if we want the extended
132 bfd_boolean use_extend
;
134 /* The 16-bit extension instruction to use when USE_EXTEND is true. */
135 unsigned short extend
;
137 /* The 16-bit or 32-bit bitstring of the instruction itself. This is
138 a copy of INSN_MO->match with the operands filled in. */
139 unsigned long insn_opcode
;
141 /* The frag that contains the instruction. */
144 /* The offset into FRAG of the first instruction byte. */
147 /* The relocs associated with the instruction, if any. */
150 /* True if this entry cannot be moved from its current position. */
151 unsigned int fixed_p
: 1;
153 /* True if this instruction occurred in a .set noreorder block. */
154 unsigned int noreorder_p
: 1;
156 /* True for mips16 instructions that jump to an absolute address. */
157 unsigned int mips16_absolute_jump_p
: 1;
160 /* The ABI to use. */
171 /* MIPS ABI we are using for this output file. */
172 static enum mips_abi_level mips_abi
= NO_ABI
;
174 /* Whether or not we have code that can call pic code. */
175 int mips_abicalls
= FALSE
;
177 /* Whether or not we have code which can be put into a shared
179 static bfd_boolean mips_in_shared
= TRUE
;
181 /* This is the set of options which may be modified by the .set
182 pseudo-op. We use a struct so that .set push and .set pop are more
185 struct mips_set_options
187 /* MIPS ISA (Instruction Set Architecture) level. This is set to -1
188 if it has not been initialized. Changed by `.set mipsN', and the
189 -mipsN command line option, and the default CPU. */
191 /* Enabled Application Specific Extensions (ASEs). These are set to -1
192 if they have not been initialized. Changed by `.set <asename>', by
193 command line options, and based on the default architecture. */
200 /* Whether we are assembling for the mips16 processor. 0 if we are
201 not, 1 if we are, and -1 if the value has not been initialized.
202 Changed by `.set mips16' and `.set nomips16', and the -mips16 and
203 -nomips16 command line options, and the default CPU. */
205 /* Non-zero if we should not reorder instructions. Changed by `.set
206 reorder' and `.set noreorder'. */
208 /* Non-zero if we should not permit the register designated "assembler
209 temporary" to be used in instructions. The value is the register
210 number, normally $at ($1). Changed by `.set at=REG', `.set noat'
211 (same as `.set at=$0') and `.set at' (same as `.set at=$1'). */
213 /* Non-zero if we should warn when a macro instruction expands into
214 more than one machine instruction. Changed by `.set nomacro' and
216 int warn_about_macros
;
217 /* Non-zero if we should not move instructions. Changed by `.set
218 move', `.set volatile', `.set nomove', and `.set novolatile'. */
220 /* Non-zero if we should not optimize branches by moving the target
221 of the branch into the delay slot. Actually, we don't perform
222 this optimization anyhow. Changed by `.set bopt' and `.set
225 /* Non-zero if we should not autoextend mips16 instructions.
226 Changed by `.set autoextend' and `.set noautoextend'. */
228 /* Restrict general purpose registers and floating point registers
229 to 32 bit. This is initially determined when -mgp32 or -mfp32
230 is passed but can changed if the assembler code uses .set mipsN. */
233 /* MIPS architecture (CPU) type. Changed by .set arch=FOO, the -march
234 command line option, and the default CPU. */
236 /* True if ".set sym32" is in effect. */
238 /* True if floating-point operations are not allowed. Changed by .set
239 softfloat or .set hardfloat, by command line options -msoft-float or
240 -mhard-float. The default is false. */
241 bfd_boolean soft_float
;
243 /* True if only single-precision floating-point operations are allowed.
244 Changed by .set singlefloat or .set doublefloat, command-line options
245 -msingle-float or -mdouble-float. The default is false. */
246 bfd_boolean single_float
;
249 /* This is the struct we use to hold the current set of options. Note
250 that we must set the isa field to ISA_UNKNOWN and the ASE fields to
251 -1 to indicate that they have not been initialized. */
253 /* True if -mgp32 was passed. */
254 static int file_mips_gp32
= -1;
256 /* True if -mfp32 was passed. */
257 static int file_mips_fp32
= -1;
259 /* 1 if -msoft-float, 0 if -mhard-float. The default is 0. */
260 static int file_mips_soft_float
= 0;
262 /* 1 if -msingle-float, 0 if -mdouble-float. The default is 0. */
263 static int file_mips_single_float
= 0;
265 static struct mips_set_options mips_opts
=
267 /* isa */ ISA_UNKNOWN
, /* ase_mips3d */ -1, /* ase_mdmx */ -1,
268 /* ase_smartmips */ 0, /* ase_dsp */ -1, /* ase_dspr2 */ -1, /* ase_mt */ -1,
269 /* mips16 */ -1, /* noreorder */ 0, /* at */ ATREG
,
270 /* warn_about_macros */ 0, /* nomove */ 0, /* nobopt */ 0,
271 /* noautoextend */ 0, /* gp32 */ 0, /* fp32 */ 0, /* arch */ CPU_UNKNOWN
,
272 /* sym32 */ FALSE
, /* soft_float */ FALSE
, /* single_float */ FALSE
275 /* These variables are filled in with the masks of registers used.
276 The object format code reads them and puts them in the appropriate
278 unsigned long mips_gprmask
;
279 unsigned long mips_cprmask
[4];
281 /* MIPS ISA we are using for this output file. */
282 static int file_mips_isa
= ISA_UNKNOWN
;
284 /* True if -mips16 was passed or implied by arguments passed on the
285 command line (e.g., by -march). */
286 static int file_ase_mips16
;
288 #define ISA_SUPPORTS_MIPS16E (mips_opts.isa == ISA_MIPS32 \
289 || mips_opts.isa == ISA_MIPS32R2 \
290 || mips_opts.isa == ISA_MIPS64 \
291 || mips_opts.isa == ISA_MIPS64R2)
293 /* True if we want to create R_MIPS_JALR for jalr $25. */
295 #define MIPS_JALR_HINT_P(EXPR) HAVE_NEWABI
297 /* As a GNU extension, we use R_MIPS_JALR for o32 too. However,
298 because there's no place for any addend, the only acceptable
299 expression is a bare symbol. */
300 #define MIPS_JALR_HINT_P(EXPR) \
301 (!HAVE_IN_PLACE_ADDENDS \
302 || ((EXPR)->X_op == O_symbol && (EXPR)->X_add_number == 0))
305 /* True if -mips3d was passed or implied by arguments passed on the
306 command line (e.g., by -march). */
307 static int file_ase_mips3d
;
309 /* True if -mdmx was passed or implied by arguments passed on the
310 command line (e.g., by -march). */
311 static int file_ase_mdmx
;
313 /* True if -msmartmips was passed or implied by arguments passed on the
314 command line (e.g., by -march). */
315 static int file_ase_smartmips
;
317 #define ISA_SUPPORTS_SMARTMIPS (mips_opts.isa == ISA_MIPS32 \
318 || mips_opts.isa == ISA_MIPS32R2)
320 /* True if -mdsp was passed or implied by arguments passed on the
321 command line (e.g., by -march). */
322 static int file_ase_dsp
;
324 #define ISA_SUPPORTS_DSP_ASE (mips_opts.isa == ISA_MIPS32R2 \
325 || mips_opts.isa == ISA_MIPS64R2)
327 #define ISA_SUPPORTS_DSP64_ASE (mips_opts.isa == ISA_MIPS64R2)
329 /* True if -mdspr2 was passed or implied by arguments passed on the
330 command line (e.g., by -march). */
331 static int file_ase_dspr2
;
333 #define ISA_SUPPORTS_DSPR2_ASE (mips_opts.isa == ISA_MIPS32R2 \
334 || mips_opts.isa == ISA_MIPS64R2)
336 /* True if -mmt was passed or implied by arguments passed on the
337 command line (e.g., by -march). */
338 static int file_ase_mt
;
340 #define ISA_SUPPORTS_MT_ASE (mips_opts.isa == ISA_MIPS32R2 \
341 || mips_opts.isa == ISA_MIPS64R2)
343 /* The argument of the -march= flag. The architecture we are assembling. */
344 static int file_mips_arch
= CPU_UNKNOWN
;
345 static const char *mips_arch_string
;
347 /* The argument of the -mtune= flag. The architecture for which we
349 static int mips_tune
= CPU_UNKNOWN
;
350 static const char *mips_tune_string
;
352 /* True when generating 32-bit code for a 64-bit processor. */
353 static int mips_32bitmode
= 0;
355 /* True if the given ABI requires 32-bit registers. */
356 #define ABI_NEEDS_32BIT_REGS(ABI) ((ABI) == O32_ABI)
358 /* Likewise 64-bit registers. */
359 #define ABI_NEEDS_64BIT_REGS(ABI) \
361 || (ABI) == N64_ABI \
364 /* Return true if ISA supports 64 bit wide gp registers. */
365 #define ISA_HAS_64BIT_REGS(ISA) \
366 ((ISA) == ISA_MIPS3 \
367 || (ISA) == ISA_MIPS4 \
368 || (ISA) == ISA_MIPS5 \
369 || (ISA) == ISA_MIPS64 \
370 || (ISA) == ISA_MIPS64R2)
372 /* Return true if ISA supports 64 bit wide float registers. */
373 #define ISA_HAS_64BIT_FPRS(ISA) \
374 ((ISA) == ISA_MIPS3 \
375 || (ISA) == ISA_MIPS4 \
376 || (ISA) == ISA_MIPS5 \
377 || (ISA) == ISA_MIPS32R2 \
378 || (ISA) == ISA_MIPS64 \
379 || (ISA) == ISA_MIPS64R2)
381 /* Return true if ISA supports 64-bit right rotate (dror et al.)
383 #define ISA_HAS_DROR(ISA) \
384 ((ISA) == ISA_MIPS64R2)
386 /* Return true if ISA supports 32-bit right rotate (ror et al.)
388 #define ISA_HAS_ROR(ISA) \
389 ((ISA) == ISA_MIPS32R2 \
390 || (ISA) == ISA_MIPS64R2 \
391 || mips_opts.ase_smartmips)
393 /* Return true if ISA supports single-precision floats in odd registers. */
394 #define ISA_HAS_ODD_SINGLE_FPR(ISA) \
395 ((ISA) == ISA_MIPS32 \
396 || (ISA) == ISA_MIPS32R2 \
397 || (ISA) == ISA_MIPS64 \
398 || (ISA) == ISA_MIPS64R2)
400 /* Return true if ISA supports move to/from high part of a 64-bit
401 floating-point register. */
402 #define ISA_HAS_MXHC1(ISA) \
403 ((ISA) == ISA_MIPS32R2 \
404 || (ISA) == ISA_MIPS64R2)
406 #define HAVE_32BIT_GPRS \
407 (mips_opts.gp32 || !ISA_HAS_64BIT_REGS (mips_opts.isa))
409 #define HAVE_32BIT_FPRS \
410 (mips_opts.fp32 || !ISA_HAS_64BIT_FPRS (mips_opts.isa))
412 #define HAVE_64BIT_GPRS (!HAVE_32BIT_GPRS)
413 #define HAVE_64BIT_FPRS (!HAVE_32BIT_FPRS)
415 #define HAVE_NEWABI (mips_abi == N32_ABI || mips_abi == N64_ABI)
417 #define HAVE_64BIT_OBJECTS (mips_abi == N64_ABI)
419 /* True if relocations are stored in-place. */
420 #define HAVE_IN_PLACE_ADDENDS (!HAVE_NEWABI)
422 /* The ABI-derived address size. */
423 #define HAVE_64BIT_ADDRESSES \
424 (HAVE_64BIT_GPRS && (mips_abi == EABI_ABI || mips_abi == N64_ABI))
425 #define HAVE_32BIT_ADDRESSES (!HAVE_64BIT_ADDRESSES)
427 /* The size of symbolic constants (i.e., expressions of the form
428 "SYMBOL" or "SYMBOL + OFFSET"). */
429 #define HAVE_32BIT_SYMBOLS \
430 (HAVE_32BIT_ADDRESSES || !HAVE_64BIT_OBJECTS || mips_opts.sym32)
431 #define HAVE_64BIT_SYMBOLS (!HAVE_32BIT_SYMBOLS)
433 /* Addresses are loaded in different ways, depending on the address size
434 in use. The n32 ABI Documentation also mandates the use of additions
435 with overflow checking, but existing implementations don't follow it. */
436 #define ADDRESS_ADD_INSN \
437 (HAVE_32BIT_ADDRESSES ? "addu" : "daddu")
439 #define ADDRESS_ADDI_INSN \
440 (HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu")
442 #define ADDRESS_LOAD_INSN \
443 (HAVE_32BIT_ADDRESSES ? "lw" : "ld")
445 #define ADDRESS_STORE_INSN \
446 (HAVE_32BIT_ADDRESSES ? "sw" : "sd")
448 /* Return true if the given CPU supports the MIPS16 ASE. */
449 #define CPU_HAS_MIPS16(cpu) \
450 (strncmp (TARGET_CPU, "mips16", sizeof ("mips16") - 1) == 0 \
451 || strncmp (TARGET_CANONICAL, "mips-lsi-elf", sizeof ("mips-lsi-elf") - 1) == 0)
453 /* True if CPU has a dror instruction. */
454 #define CPU_HAS_DROR(CPU) ((CPU) == CPU_VR5400 || (CPU) == CPU_VR5500)
456 /* True if CPU has a ror instruction. */
457 #define CPU_HAS_ROR(CPU) CPU_HAS_DROR (CPU)
459 /* True if CPU has seq/sne and seqi/snei instructions. */
460 #define CPU_HAS_SEQ(CPU) ((CPU) == CPU_OCTEON)
462 /* True if CPU does not implement the all the coprocessor insns. For these
463 CPUs only those COP insns are accepted that are explicitly marked to be
464 available on the CPU. ISA membership for COP insns is ignored. */
465 #define NO_ISA_COP(CPU) ((CPU) == CPU_OCTEON)
467 /* True if mflo and mfhi can be immediately followed by instructions
468 which write to the HI and LO registers.
470 According to MIPS specifications, MIPS ISAs I, II, and III need
471 (at least) two instructions between the reads of HI/LO and
472 instructions which write them, and later ISAs do not. Contradicting
473 the MIPS specifications, some MIPS IV processor user manuals (e.g.
474 the UM for the NEC Vr5000) document needing the instructions between
475 HI/LO reads and writes, as well. Therefore, we declare only MIPS32,
476 MIPS64 and later ISAs to have the interlocks, plus any specific
477 earlier-ISA CPUs for which CPU documentation declares that the
478 instructions are really interlocked. */
479 #define hilo_interlocks \
480 (mips_opts.isa == ISA_MIPS32 \
481 || mips_opts.isa == ISA_MIPS32R2 \
482 || mips_opts.isa == ISA_MIPS64 \
483 || mips_opts.isa == ISA_MIPS64R2 \
484 || mips_opts.arch == CPU_R4010 \
485 || mips_opts.arch == CPU_R10000 \
486 || mips_opts.arch == CPU_R12000 \
487 || mips_opts.arch == CPU_R14000 \
488 || mips_opts.arch == CPU_R16000 \
489 || mips_opts.arch == CPU_RM7000 \
490 || mips_opts.arch == CPU_VR5500 \
493 /* Whether the processor uses hardware interlocks to protect reads
494 from the GPRs after they are loaded from memory, and thus does not
495 require nops to be inserted. This applies to instructions marked
496 INSN_LOAD_MEMORY_DELAY. These nops are only required at MIPS ISA
498 #define gpr_interlocks \
499 (mips_opts.isa != ISA_MIPS1 \
500 || mips_opts.arch == CPU_R3900)
502 /* Whether the processor uses hardware interlocks to avoid delays
503 required by coprocessor instructions, and thus does not require
504 nops to be inserted. This applies to instructions marked
505 INSN_LOAD_COPROC_DELAY, INSN_COPROC_MOVE_DELAY, and to delays
506 between instructions marked INSN_WRITE_COND_CODE and ones marked
507 INSN_READ_COND_CODE. These nops are only required at MIPS ISA
508 levels I, II, and III. */
509 /* Itbl support may require additional care here. */
510 #define cop_interlocks \
511 ((mips_opts.isa != ISA_MIPS1 \
512 && mips_opts.isa != ISA_MIPS2 \
513 && mips_opts.isa != ISA_MIPS3) \
514 || mips_opts.arch == CPU_R4300 \
517 /* Whether the processor uses hardware interlocks to protect reads
518 from coprocessor registers after they are loaded from memory, and
519 thus does not require nops to be inserted. This applies to
520 instructions marked INSN_COPROC_MEMORY_DELAY. These nops are only
521 requires at MIPS ISA level I. */
522 #define cop_mem_interlocks (mips_opts.isa != ISA_MIPS1)
524 /* Is this a mfhi or mflo instruction? */
525 #define MF_HILO_INSN(PINFO) \
526 ((PINFO & INSN_READ_HI) || (PINFO & INSN_READ_LO))
528 /* Returns true for a (non floating-point) coprocessor instruction. Reading
529 or writing the condition code is only possible on the coprocessors and
530 these insns are not marked with INSN_COP. Thus for these insns use the
531 condition-code flags. */
532 #define COP_INSN(PINFO) \
533 (PINFO != INSN_MACRO \
534 && ((PINFO) & (FP_S | FP_D)) == 0 \
535 && ((PINFO) & (INSN_COP | INSN_READ_COND_CODE | INSN_WRITE_COND_CODE)))
537 /* MIPS PIC level. */
539 enum mips_pic_level mips_pic
;
541 /* 1 if we should generate 32 bit offsets from the $gp register in
542 SVR4_PIC mode. Currently has no meaning in other modes. */
543 static int mips_big_got
= 0;
545 /* 1 if trap instructions should used for overflow rather than break
547 static int mips_trap
= 0;
549 /* 1 if double width floating point constants should not be constructed
550 by assembling two single width halves into two single width floating
551 point registers which just happen to alias the double width destination
552 register. On some architectures this aliasing can be disabled by a bit
553 in the status register, and the setting of this bit cannot be determined
554 automatically at assemble time. */
555 static int mips_disable_float_construction
;
557 /* Non-zero if any .set noreorder directives were used. */
559 static int mips_any_noreorder
;
561 /* Non-zero if nops should be inserted when the register referenced in
562 an mfhi/mflo instruction is read in the next two instructions. */
563 static int mips_7000_hilo_fix
;
565 /* The size of objects in the small data section. */
566 static unsigned int g_switch_value
= 8;
567 /* Whether the -G option was used. */
568 static int g_switch_seen
= 0;
573 /* If we can determine in advance that GP optimization won't be
574 possible, we can skip the relaxation stuff that tries to produce
575 GP-relative references. This makes delay slot optimization work
578 This function can only provide a guess, but it seems to work for
579 gcc output. It needs to guess right for gcc, otherwise gcc
580 will put what it thinks is a GP-relative instruction in a branch
583 I don't know if a fix is needed for the SVR4_PIC mode. I've only
584 fixed it for the non-PIC mode. KR 95/04/07 */
585 static int nopic_need_relax (symbolS
*, int);
587 /* handle of the OPCODE hash table */
588 static struct hash_control
*op_hash
= NULL
;
590 /* The opcode hash table we use for the mips16. */
591 static struct hash_control
*mips16_op_hash
= NULL
;
593 /* This array holds the chars that always start a comment. If the
594 pre-processor is disabled, these aren't very useful */
595 const char comment_chars
[] = "#";
597 /* This array holds the chars that only start a comment at the beginning of
598 a line. If the line seems to have the form '# 123 filename'
599 .line and .file directives will appear in the pre-processed output */
600 /* Note that input_file.c hand checks for '#' at the beginning of the
601 first line of the input file. This is because the compiler outputs
602 #NO_APP at the beginning of its output. */
603 /* Also note that C style comments are always supported. */
604 const char line_comment_chars
[] = "#";
606 /* This array holds machine specific line separator characters. */
607 const char line_separator_chars
[] = ";";
609 /* Chars that can be used to separate mant from exp in floating point nums */
610 const char EXP_CHARS
[] = "eE";
612 /* Chars that mean this number is a floating point constant */
615 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
617 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
618 changed in read.c . Ideally it shouldn't have to know about it at all,
619 but nothing is ideal around here.
622 static char *insn_error
;
624 static int auto_align
= 1;
626 /* When outputting SVR4 PIC code, the assembler needs to know the
627 offset in the stack frame from which to restore the $gp register.
628 This is set by the .cprestore pseudo-op, and saved in this
630 static offsetT mips_cprestore_offset
= -1;
632 /* Similar for NewABI PIC code, where $gp is callee-saved. NewABI has some
633 more optimizations, it can use a register value instead of a memory-saved
634 offset and even an other register than $gp as global pointer. */
635 static offsetT mips_cpreturn_offset
= -1;
636 static int mips_cpreturn_register
= -1;
637 static int mips_gp_register
= GP
;
638 static int mips_gprel_offset
= 0;
640 /* Whether mips_cprestore_offset has been set in the current function
641 (or whether it has already been warned about, if not). */
642 static int mips_cprestore_valid
= 0;
644 /* This is the register which holds the stack frame, as set by the
645 .frame pseudo-op. This is needed to implement .cprestore. */
646 static int mips_frame_reg
= SP
;
648 /* Whether mips_frame_reg has been set in the current function
649 (or whether it has already been warned about, if not). */
650 static int mips_frame_reg_valid
= 0;
652 /* To output NOP instructions correctly, we need to keep information
653 about the previous two instructions. */
655 /* Whether we are optimizing. The default value of 2 means to remove
656 unneeded NOPs and swap branch instructions when possible. A value
657 of 1 means to not swap branches. A value of 0 means to always
659 static int mips_optimize
= 2;
661 /* Debugging level. -g sets this to 2. -gN sets this to N. -g0 is
662 equivalent to seeing no -g option at all. */
663 static int mips_debug
= 0;
665 /* The maximum number of NOPs needed to avoid the VR4130 mflo/mfhi errata. */
666 #define MAX_VR4130_NOPS 4
668 /* The maximum number of NOPs needed to fill delay slots. */
669 #define MAX_DELAY_NOPS 2
671 /* The maximum number of NOPs needed for any purpose. */
674 /* A list of previous instructions, with index 0 being the most recent.
675 We need to look back MAX_NOPS instructions when filling delay slots
676 or working around processor errata. We need to look back one
677 instruction further if we're thinking about using history[0] to
678 fill a branch delay slot. */
679 static struct mips_cl_insn history
[1 + MAX_NOPS
];
681 /* Nop instructions used by emit_nop. */
682 static struct mips_cl_insn nop_insn
, mips16_nop_insn
;
684 /* The appropriate nop for the current mode. */
685 #define NOP_INSN (mips_opts.mips16 ? &mips16_nop_insn : &nop_insn)
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 /* For ECOFF and ELF, relocations against symbols are done in two
704 parts, with a HI relocation and a LO relocation. Each relocation
705 has only 16 bits of space to store an addend. This means that in
706 order for the linker to handle carries correctly, it must be able
707 to locate both the HI and the LO relocation. This means that the
708 relocations must appear in 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 /* Classifies the kind of instructions we're interested in when
753 implementing -mfix-vr4120. */
754 enum fix_vr4120_class
{
761 NUM_FIX_VR4120_CLASSES
764 /* Given two FIX_VR4120_* values X and Y, bit Y of element X is set if
765 there must be at least one other instruction between an instruction
766 of type X and an instruction of type Y. */
767 static unsigned int vr4120_conflicts
[NUM_FIX_VR4120_CLASSES
];
769 /* True if -mfix-vr4120 is in force. */
770 static int mips_fix_vr4120
;
772 /* ...likewise -mfix-vr4130. */
773 static int mips_fix_vr4130
;
775 /* ...likewise -mfix-24k. */
776 static int mips_fix_24k
;
778 /* We don't relax branches by default, since this causes us to expand
779 `la .l2 - .l1' if there's a branch between .l1 and .l2, because we
780 fail to compute the offset before expanding the macro to the most
781 efficient expansion. */
783 static int mips_relax_branch
;
785 /* The expansion of many macros depends on the type of symbol that
786 they refer to. For example, when generating position-dependent code,
787 a macro that refers to a symbol may have two different expansions,
788 one which uses GP-relative addresses and one which uses absolute
789 addresses. When generating SVR4-style PIC, a macro may have
790 different expansions for local and global symbols.
792 We handle these situations by generating both sequences and putting
793 them in variant frags. In position-dependent code, the first sequence
794 will be the GP-relative one and the second sequence will be the
795 absolute one. In SVR4 PIC, the first sequence will be for global
796 symbols and the second will be for local symbols.
798 The frag's "subtype" is RELAX_ENCODE (FIRST, SECOND), where FIRST and
799 SECOND are the lengths of the two sequences in bytes. These fields
800 can be extracted using RELAX_FIRST() and RELAX_SECOND(). In addition,
801 the subtype has the following flags:
804 Set if it has been decided that we should use the second
805 sequence instead of the first.
808 Set in the first variant frag if the macro's second implementation
809 is longer than its first. This refers to the macro as a whole,
810 not an individual relaxation.
813 Set in the first variant frag if the macro appeared in a .set nomacro
814 block and if one alternative requires a warning but the other does not.
817 Like RELAX_NOMACRO, but indicates that the macro appears in a branch
820 The frag's "opcode" points to the first fixup for relaxable code.
822 Relaxable macros are generated using a sequence such as:
824 relax_start (SYMBOL);
825 ... generate first expansion ...
827 ... generate second expansion ...
830 The code and fixups for the unwanted alternative are discarded
831 by md_convert_frag. */
832 #define RELAX_ENCODE(FIRST, SECOND) (((FIRST) << 8) | (SECOND))
834 #define RELAX_FIRST(X) (((X) >> 8) & 0xff)
835 #define RELAX_SECOND(X) ((X) & 0xff)
836 #define RELAX_USE_SECOND 0x10000
837 #define RELAX_SECOND_LONGER 0x20000
838 #define RELAX_NOMACRO 0x40000
839 #define RELAX_DELAY_SLOT 0x80000
841 /* Branch without likely bit. If label is out of range, we turn:
843 beq reg1, reg2, label
853 with the following opcode replacements:
860 bltzal <-> bgezal (with jal label instead of j label)
862 Even though keeping the delay slot instruction in the delay slot of
863 the branch would be more efficient, it would be very tricky to do
864 correctly, because we'd have to introduce a variable frag *after*
865 the delay slot instruction, and expand that instead. Let's do it
866 the easy way for now, even if the branch-not-taken case now costs
867 one additional instruction. Out-of-range branches are not supposed
868 to be common, anyway.
870 Branch likely. If label is out of range, we turn:
872 beql reg1, reg2, label
873 delay slot (annulled if branch not taken)
882 delay slot (executed only if branch taken)
885 It would be possible to generate a shorter sequence by losing the
886 likely bit, generating something like:
891 delay slot (executed only if branch taken)
903 bltzall -> bgezal (with jal label instead of j label)
904 bgezall -> bltzal (ditto)
907 but it's not clear that it would actually improve performance. */
908 #define RELAX_BRANCH_ENCODE(uncond, likely, link, toofar) \
911 | ((toofar) ? 1 : 0) \
913 | ((likely) ? 4 : 0) \
914 | ((uncond) ? 8 : 0)))
915 #define RELAX_BRANCH_P(i) (((i) & 0xf0000000) == 0xc0000000)
916 #define RELAX_BRANCH_UNCOND(i) (((i) & 8) != 0)
917 #define RELAX_BRANCH_LIKELY(i) (((i) & 4) != 0)
918 #define RELAX_BRANCH_LINK(i) (((i) & 2) != 0)
919 #define RELAX_BRANCH_TOOFAR(i) (((i) & 1) != 0)
921 /* For mips16 code, we use an entirely different form of relaxation.
922 mips16 supports two versions of most instructions which take
923 immediate values: a small one which takes some small value, and a
924 larger one which takes a 16 bit value. Since branches also follow
925 this pattern, relaxing these values is required.
927 We can assemble both mips16 and normal MIPS code in a single
928 object. Therefore, we need to support this type of relaxation at
929 the same time that we support the relaxation described above. We
930 use the high bit of the subtype field to distinguish these cases.
932 The information we store for this type of relaxation is the
933 argument code found in the opcode file for this relocation, whether
934 the user explicitly requested a small or extended form, and whether
935 the relocation is in a jump or jal delay slot. That tells us the
936 size of the value, and how it should be stored. We also store
937 whether the fragment is considered to be extended or not. We also
938 store whether this is known to be a branch to a different section,
939 whether we have tried to relax this frag yet, and whether we have
940 ever extended a PC relative fragment because of a shift count. */
941 #define RELAX_MIPS16_ENCODE(type, small, ext, dslot, jal_dslot) \
944 | ((small) ? 0x100 : 0) \
945 | ((ext) ? 0x200 : 0) \
946 | ((dslot) ? 0x400 : 0) \
947 | ((jal_dslot) ? 0x800 : 0))
948 #define RELAX_MIPS16_P(i) (((i) & 0xc0000000) == 0x80000000)
949 #define RELAX_MIPS16_TYPE(i) ((i) & 0xff)
950 #define RELAX_MIPS16_USER_SMALL(i) (((i) & 0x100) != 0)
951 #define RELAX_MIPS16_USER_EXT(i) (((i) & 0x200) != 0)
952 #define RELAX_MIPS16_DSLOT(i) (((i) & 0x400) != 0)
953 #define RELAX_MIPS16_JAL_DSLOT(i) (((i) & 0x800) != 0)
954 #define RELAX_MIPS16_EXTENDED(i) (((i) & 0x1000) != 0)
955 #define RELAX_MIPS16_MARK_EXTENDED(i) ((i) | 0x1000)
956 #define RELAX_MIPS16_CLEAR_EXTENDED(i) ((i) &~ 0x1000)
957 #define RELAX_MIPS16_LONG_BRANCH(i) (((i) & 0x2000) != 0)
958 #define RELAX_MIPS16_MARK_LONG_BRANCH(i) ((i) | 0x2000)
959 #define RELAX_MIPS16_CLEAR_LONG_BRANCH(i) ((i) &~ 0x2000)
961 /* Is the given value a sign-extended 32-bit value? */
962 #define IS_SEXT_32BIT_NUM(x) \
963 (((x) &~ (offsetT) 0x7fffffff) == 0 \
964 || (((x) &~ (offsetT) 0x7fffffff) == ~ (offsetT) 0x7fffffff))
966 /* Is the given value a sign-extended 16-bit value? */
967 #define IS_SEXT_16BIT_NUM(x) \
968 (((x) &~ (offsetT) 0x7fff) == 0 \
969 || (((x) &~ (offsetT) 0x7fff) == ~ (offsetT) 0x7fff))
971 /* Is the given value a zero-extended 32-bit value? Or a negated one? */
972 #define IS_ZEXT_32BIT_NUM(x) \
973 (((x) &~ (offsetT) 0xffffffff) == 0 \
974 || (((x) &~ (offsetT) 0xffffffff) == ~ (offsetT) 0xffffffff))
976 /* Replace bits MASK << SHIFT of STRUCT with the equivalent bits in
977 VALUE << SHIFT. VALUE is evaluated exactly once. */
978 #define INSERT_BITS(STRUCT, VALUE, MASK, SHIFT) \
979 (STRUCT) = (((STRUCT) & ~((MASK) << (SHIFT))) \
980 | (((VALUE) & (MASK)) << (SHIFT)))
982 /* Extract bits MASK << SHIFT from STRUCT and shift them right
984 #define EXTRACT_BITS(STRUCT, MASK, SHIFT) \
985 (((STRUCT) >> (SHIFT)) & (MASK))
987 /* Change INSN's opcode so that the operand given by FIELD has value VALUE.
988 INSN is a mips_cl_insn structure and VALUE is evaluated exactly once.
990 include/opcode/mips.h specifies operand fields using the macros
991 OP_MASK_<FIELD> and OP_SH_<FIELD>. The MIPS16 equivalents start
992 with "MIPS16OP" instead of "OP". */
993 #define INSERT_OPERAND(FIELD, INSN, VALUE) \
994 INSERT_BITS ((INSN).insn_opcode, VALUE, OP_MASK_##FIELD, OP_SH_##FIELD)
995 #define MIPS16_INSERT_OPERAND(FIELD, INSN, VALUE) \
996 INSERT_BITS ((INSN).insn_opcode, VALUE, \
997 MIPS16OP_MASK_##FIELD, MIPS16OP_SH_##FIELD)
999 /* Extract the operand given by FIELD from mips_cl_insn INSN. */
1000 #define EXTRACT_OPERAND(FIELD, INSN) \
1001 EXTRACT_BITS ((INSN).insn_opcode, OP_MASK_##FIELD, OP_SH_##FIELD)
1002 #define MIPS16_EXTRACT_OPERAND(FIELD, INSN) \
1003 EXTRACT_BITS ((INSN).insn_opcode, \
1004 MIPS16OP_MASK_##FIELD, \
1005 MIPS16OP_SH_##FIELD)
1007 /* Global variables used when generating relaxable macros. See the
1008 comment above RELAX_ENCODE for more details about how relaxation
1011 /* 0 if we're not emitting a relaxable macro.
1012 1 if we're emitting the first of the two relaxation alternatives.
1013 2 if we're emitting the second alternative. */
1016 /* The first relaxable fixup in the current frag. (In other words,
1017 the first fixup that refers to relaxable code.) */
1020 /* sizes[0] says how many bytes of the first alternative are stored in
1021 the current frag. Likewise sizes[1] for the second alternative. */
1022 unsigned int sizes
[2];
1024 /* The symbol on which the choice of sequence depends. */
1028 /* Global variables used to decide whether a macro needs a warning. */
1030 /* True if the macro is in a branch delay slot. */
1031 bfd_boolean delay_slot_p
;
1033 /* For relaxable macros, sizes[0] is the length of the first alternative
1034 in bytes and sizes[1] is the length of the second alternative.
1035 For non-relaxable macros, both elements give the length of the
1037 unsigned int sizes
[2];
1039 /* The first variant frag for this macro. */
1041 } mips_macro_warning
;
1043 /* Prototypes for static functions. */
1045 #define internalError() \
1046 as_fatal (_("internal Error, line %d, %s"), __LINE__, __FILE__)
1048 enum mips_regclass
{ MIPS_GR_REG
, MIPS_FP_REG
, MIPS16_REG
};
1050 static void append_insn
1051 (struct mips_cl_insn
*ip
, expressionS
*p
, bfd_reloc_code_real_type
*r
);
1052 static void mips_no_prev_insn (void);
1053 static void mips16_macro_build
1054 (expressionS
*, const char *, const char *, va_list);
1055 static void load_register (int, expressionS
*, int);
1056 static void macro_start (void);
1057 static void macro_end (void);
1058 static void macro (struct mips_cl_insn
* ip
);
1059 static void mips16_macro (struct mips_cl_insn
* ip
);
1060 #ifdef LOSING_COMPILER
1061 static void macro2 (struct mips_cl_insn
* ip
);
1063 static void mips_ip (char *str
, struct mips_cl_insn
* ip
);
1064 static void mips16_ip (char *str
, struct mips_cl_insn
* ip
);
1065 static void mips16_immed
1066 (char *, unsigned int, int, offsetT
, bfd_boolean
, bfd_boolean
, bfd_boolean
,
1067 unsigned long *, bfd_boolean
*, unsigned short *);
1068 static size_t my_getSmallExpression
1069 (expressionS
*, bfd_reloc_code_real_type
*, char *);
1070 static void my_getExpression (expressionS
*, char *);
1071 static void s_align (int);
1072 static void s_change_sec (int);
1073 static void s_change_section (int);
1074 static void s_cons (int);
1075 static void s_float_cons (int);
1076 static void s_mips_globl (int);
1077 static void s_option (int);
1078 static void s_mipsset (int);
1079 static void s_abicalls (int);
1080 static void s_cpload (int);
1081 static void s_cpsetup (int);
1082 static void s_cplocal (int);
1083 static void s_cprestore (int);
1084 static void s_cpreturn (int);
1085 static void s_dtprelword (int);
1086 static void s_dtpreldword (int);
1087 static void s_gpvalue (int);
1088 static void s_gpword (int);
1089 static void s_gpdword (int);
1090 static void s_cpadd (int);
1091 static void s_insn (int);
1092 static void md_obj_begin (void);
1093 static void md_obj_end (void);
1094 static void s_mips_ent (int);
1095 static void s_mips_end (int);
1096 static void s_mips_frame (int);
1097 static void s_mips_mask (int reg_type
);
1098 static void s_mips_stab (int);
1099 static void s_mips_weakext (int);
1100 static void s_mips_file (int);
1101 static void s_mips_loc (int);
1102 static bfd_boolean
pic_need_relax (symbolS
*, asection
*);
1103 static int relaxed_branch_length (fragS
*, asection
*, int);
1104 static int validate_mips_insn (const struct mips_opcode
*);
1106 /* Table and functions used to map between CPU/ISA names, and
1107 ISA levels, and CPU numbers. */
1109 struct mips_cpu_info
1111 const char *name
; /* CPU or ISA name. */
1112 int flags
; /* ASEs available, or ISA flag. */
1113 int isa
; /* ISA level. */
1114 int cpu
; /* CPU number (default CPU if ISA). */
1117 #define MIPS_CPU_IS_ISA 0x0001 /* Is this an ISA? (If 0, a CPU.) */
1118 #define MIPS_CPU_ASE_SMARTMIPS 0x0002 /* CPU implements SmartMIPS ASE */
1119 #define MIPS_CPU_ASE_DSP 0x0004 /* CPU implements DSP ASE */
1120 #define MIPS_CPU_ASE_MT 0x0008 /* CPU implements MT ASE */
1121 #define MIPS_CPU_ASE_MIPS3D 0x0010 /* CPU implements MIPS-3D ASE */
1122 #define MIPS_CPU_ASE_MDMX 0x0020 /* CPU implements MDMX ASE */
1123 #define MIPS_CPU_ASE_DSPR2 0x0040 /* CPU implements DSP R2 ASE */
1125 static const struct mips_cpu_info
*mips_parse_cpu (const char *, const char *);
1126 static const struct mips_cpu_info
*mips_cpu_info_from_isa (int);
1127 static const struct mips_cpu_info
*mips_cpu_info_from_arch (int);
1131 The following pseudo-ops from the Kane and Heinrich MIPS book
1132 should be defined here, but are currently unsupported: .alias,
1133 .galive, .gjaldef, .gjrlive, .livereg, .noalias.
1135 The following pseudo-ops from the Kane and Heinrich MIPS book are
1136 specific to the type of debugging information being generated, and
1137 should be defined by the object format: .aent, .begin, .bend,
1138 .bgnb, .end, .endb, .ent, .fmask, .frame, .loc, .mask, .verstamp,
1141 The following pseudo-ops from the Kane and Heinrich MIPS book are
1142 not MIPS CPU specific, but are also not specific to the object file
1143 format. This file is probably the best place to define them, but
1144 they are not currently supported: .asm0, .endr, .lab, .struct. */
1146 static const pseudo_typeS mips_pseudo_table
[] =
1148 /* MIPS specific pseudo-ops. */
1149 {"option", s_option
, 0},
1150 {"set", s_mipsset
, 0},
1151 {"rdata", s_change_sec
, 'r'},
1152 {"sdata", s_change_sec
, 's'},
1153 {"livereg", s_ignore
, 0},
1154 {"abicalls", s_abicalls
, 0},
1155 {"cpload", s_cpload
, 0},
1156 {"cpsetup", s_cpsetup
, 0},
1157 {"cplocal", s_cplocal
, 0},
1158 {"cprestore", s_cprestore
, 0},
1159 {"cpreturn", s_cpreturn
, 0},
1160 {"dtprelword", s_dtprelword
, 0},
1161 {"dtpreldword", s_dtpreldword
, 0},
1162 {"gpvalue", s_gpvalue
, 0},
1163 {"gpword", s_gpword
, 0},
1164 {"gpdword", s_gpdword
, 0},
1165 {"cpadd", s_cpadd
, 0},
1166 {"insn", s_insn
, 0},
1168 /* Relatively generic pseudo-ops that happen to be used on MIPS
1170 {"asciiz", stringer
, 8 + 1},
1171 {"bss", s_change_sec
, 'b'},
1173 {"half", s_cons
, 1},
1174 {"dword", s_cons
, 3},
1175 {"weakext", s_mips_weakext
, 0},
1176 {"origin", s_org
, 0},
1177 {"repeat", s_rept
, 0},
1179 /* These pseudo-ops are defined in read.c, but must be overridden
1180 here for one reason or another. */
1181 {"align", s_align
, 0},
1182 {"byte", s_cons
, 0},
1183 {"data", s_change_sec
, 'd'},
1184 {"double", s_float_cons
, 'd'},
1185 {"float", s_float_cons
, 'f'},
1186 {"globl", s_mips_globl
, 0},
1187 {"global", s_mips_globl
, 0},
1188 {"hword", s_cons
, 1},
1190 {"long", s_cons
, 2},
1191 {"octa", s_cons
, 4},
1192 {"quad", s_cons
, 3},
1193 {"section", s_change_section
, 0},
1194 {"short", s_cons
, 1},
1195 {"single", s_float_cons
, 'f'},
1196 {"stabn", s_mips_stab
, 'n'},
1197 {"text", s_change_sec
, 't'},
1198 {"word", s_cons
, 2},
1200 { "extern", ecoff_directive_extern
, 0},
1205 static const pseudo_typeS mips_nonecoff_pseudo_table
[] =
1207 /* These pseudo-ops should be defined by the object file format.
1208 However, a.out doesn't support them, so we have versions here. */
1209 {"aent", s_mips_ent
, 1},
1210 {"bgnb", s_ignore
, 0},
1211 {"end", s_mips_end
, 0},
1212 {"endb", s_ignore
, 0},
1213 {"ent", s_mips_ent
, 0},
1214 {"file", s_mips_file
, 0},
1215 {"fmask", s_mips_mask
, 'F'},
1216 {"frame", s_mips_frame
, 0},
1217 {"loc", s_mips_loc
, 0},
1218 {"mask", s_mips_mask
, 'R'},
1219 {"verstamp", s_ignore
, 0},
1223 extern void pop_insert (const pseudo_typeS
*);
1226 mips_pop_insert (void)
1228 pop_insert (mips_pseudo_table
);
1229 if (! ECOFF_DEBUGGING
)
1230 pop_insert (mips_nonecoff_pseudo_table
);
1233 /* Symbols labelling the current insn. */
1235 struct insn_label_list
1237 struct insn_label_list
*next
;
1241 static struct insn_label_list
*free_insn_labels
;
1242 #define label_list tc_segment_info_data.labels
1244 static void mips_clear_insn_labels (void);
1247 mips_clear_insn_labels (void)
1249 register struct insn_label_list
**pl
;
1250 segment_info_type
*si
;
1254 for (pl
= &free_insn_labels
; *pl
!= NULL
; pl
= &(*pl
)->next
)
1257 si
= seg_info (now_seg
);
1258 *pl
= si
->label_list
;
1259 si
->label_list
= NULL
;
1264 static char *expr_end
;
1266 /* Expressions which appear in instructions. These are set by
1269 static expressionS imm_expr
;
1270 static expressionS imm2_expr
;
1271 static expressionS offset_expr
;
1273 /* Relocs associated with imm_expr and offset_expr. */
1275 static bfd_reloc_code_real_type imm_reloc
[3]
1276 = {BFD_RELOC_UNUSED
, BFD_RELOC_UNUSED
, BFD_RELOC_UNUSED
};
1277 static bfd_reloc_code_real_type offset_reloc
[3]
1278 = {BFD_RELOC_UNUSED
, BFD_RELOC_UNUSED
, BFD_RELOC_UNUSED
};
1280 /* These are set by mips16_ip if an explicit extension is used. */
1282 static bfd_boolean mips16_small
, mips16_ext
;
1285 /* The pdr segment for per procedure frame/regmask info. Not used for
1288 static segT pdr_seg
;
1291 /* The default target format to use. */
1294 mips_target_format (void)
1296 switch (OUTPUT_FLAVOR
)
1298 case bfd_target_ecoff_flavour
:
1299 return target_big_endian
? "ecoff-bigmips" : ECOFF_LITTLE_FORMAT
;
1300 case bfd_target_coff_flavour
:
1302 case bfd_target_elf_flavour
:
1304 if (!HAVE_64BIT_OBJECTS
&& !HAVE_NEWABI
)
1305 return (target_big_endian
1306 ? "elf32-bigmips-vxworks"
1307 : "elf32-littlemips-vxworks");
1310 /* This is traditional mips. */
1311 return (target_big_endian
1312 ? (HAVE_64BIT_OBJECTS
1313 ? "elf64-tradbigmips"
1315 ? "elf32-ntradbigmips" : "elf32-tradbigmips"))
1316 : (HAVE_64BIT_OBJECTS
1317 ? "elf64-tradlittlemips"
1319 ? "elf32-ntradlittlemips" : "elf32-tradlittlemips")));
1321 return (target_big_endian
1322 ? (HAVE_64BIT_OBJECTS
1325 ? "elf32-nbigmips" : "elf32-bigmips"))
1326 : (HAVE_64BIT_OBJECTS
1327 ? "elf64-littlemips"
1329 ? "elf32-nlittlemips" : "elf32-littlemips")));
1337 /* Return the length of instruction INSN. */
1339 static inline unsigned int
1340 insn_length (const struct mips_cl_insn
*insn
)
1342 if (!mips_opts
.mips16
)
1344 return insn
->mips16_absolute_jump_p
|| insn
->use_extend
? 4 : 2;
1347 /* Initialise INSN from opcode entry MO. Leave its position unspecified. */
1350 create_insn (struct mips_cl_insn
*insn
, const struct mips_opcode
*mo
)
1355 insn
->use_extend
= FALSE
;
1357 insn
->insn_opcode
= mo
->match
;
1360 for (i
= 0; i
< ARRAY_SIZE (insn
->fixp
); i
++)
1361 insn
->fixp
[i
] = NULL
;
1362 insn
->fixed_p
= (mips_opts
.noreorder
> 0);
1363 insn
->noreorder_p
= (mips_opts
.noreorder
> 0);
1364 insn
->mips16_absolute_jump_p
= 0;
1367 /* Record the current MIPS16 mode in now_seg. */
1370 mips_record_mips16_mode (void)
1372 segment_info_type
*si
;
1374 si
= seg_info (now_seg
);
1375 if (si
->tc_segment_info_data
.mips16
!= mips_opts
.mips16
)
1376 si
->tc_segment_info_data
.mips16
= mips_opts
.mips16
;
1379 /* Install INSN at the location specified by its "frag" and "where" fields. */
1382 install_insn (const struct mips_cl_insn
*insn
)
1384 char *f
= insn
->frag
->fr_literal
+ insn
->where
;
1385 if (!mips_opts
.mips16
)
1386 md_number_to_chars (f
, insn
->insn_opcode
, 4);
1387 else if (insn
->mips16_absolute_jump_p
)
1389 md_number_to_chars (f
, insn
->insn_opcode
>> 16, 2);
1390 md_number_to_chars (f
+ 2, insn
->insn_opcode
& 0xffff, 2);
1394 if (insn
->use_extend
)
1396 md_number_to_chars (f
, 0xf000 | insn
->extend
, 2);
1399 md_number_to_chars (f
, insn
->insn_opcode
, 2);
1401 mips_record_mips16_mode ();
1404 /* Move INSN to offset WHERE in FRAG. Adjust the fixups accordingly
1405 and install the opcode in the new location. */
1408 move_insn (struct mips_cl_insn
*insn
, fragS
*frag
, long where
)
1413 insn
->where
= where
;
1414 for (i
= 0; i
< ARRAY_SIZE (insn
->fixp
); i
++)
1415 if (insn
->fixp
[i
] != NULL
)
1417 insn
->fixp
[i
]->fx_frag
= frag
;
1418 insn
->fixp
[i
]->fx_where
= where
;
1420 install_insn (insn
);
1423 /* Add INSN to the end of the output. */
1426 add_fixed_insn (struct mips_cl_insn
*insn
)
1428 char *f
= frag_more (insn_length (insn
));
1429 move_insn (insn
, frag_now
, f
- frag_now
->fr_literal
);
1432 /* Start a variant frag and move INSN to the start of the variant part,
1433 marking it as fixed. The other arguments are as for frag_var. */
1436 add_relaxed_insn (struct mips_cl_insn
*insn
, int max_chars
, int var
,
1437 relax_substateT subtype
, symbolS
*symbol
, offsetT offset
)
1439 frag_grow (max_chars
);
1440 move_insn (insn
, frag_now
, frag_more (0) - frag_now
->fr_literal
);
1442 frag_var (rs_machine_dependent
, max_chars
, var
,
1443 subtype
, symbol
, offset
, NULL
);
1446 /* Insert N copies of INSN into the history buffer, starting at
1447 position FIRST. Neither FIRST nor N need to be clipped. */
1450 insert_into_history (unsigned int first
, unsigned int n
,
1451 const struct mips_cl_insn
*insn
)
1453 if (mips_relax
.sequence
!= 2)
1457 for (i
= ARRAY_SIZE (history
); i
-- > first
;)
1459 history
[i
] = history
[i
- n
];
1465 /* Emit a nop instruction, recording it in the history buffer. */
1470 add_fixed_insn (NOP_INSN
);
1471 insert_into_history (0, 1, NOP_INSN
);
1474 /* Initialize vr4120_conflicts. There is a bit of duplication here:
1475 the idea is to make it obvious at a glance that each errata is
1479 init_vr4120_conflicts (void)
1481 #define CONFLICT(FIRST, SECOND) \
1482 vr4120_conflicts[FIX_VR4120_##FIRST] |= 1 << FIX_VR4120_##SECOND
1484 /* Errata 21 - [D]DIV[U] after [D]MACC */
1485 CONFLICT (MACC
, DIV
);
1486 CONFLICT (DMACC
, DIV
);
1488 /* Errata 23 - Continuous DMULT[U]/DMACC instructions. */
1489 CONFLICT (DMULT
, DMULT
);
1490 CONFLICT (DMULT
, DMACC
);
1491 CONFLICT (DMACC
, DMULT
);
1492 CONFLICT (DMACC
, DMACC
);
1494 /* Errata 24 - MT{LO,HI} after [D]MACC */
1495 CONFLICT (MACC
, MTHILO
);
1496 CONFLICT (DMACC
, MTHILO
);
1498 /* VR4181A errata MD(1): "If a MULT, MULTU, DMULT or DMULTU
1499 instruction is executed immediately after a MACC or DMACC
1500 instruction, the result of [either instruction] is incorrect." */
1501 CONFLICT (MACC
, MULT
);
1502 CONFLICT (MACC
, DMULT
);
1503 CONFLICT (DMACC
, MULT
);
1504 CONFLICT (DMACC
, DMULT
);
1506 /* VR4181A errata MD(4): "If a MACC or DMACC instruction is
1507 executed immediately after a DMULT, DMULTU, DIV, DIVU,
1508 DDIV or DDIVU instruction, the result of the MACC or
1509 DMACC instruction is incorrect.". */
1510 CONFLICT (DMULT
, MACC
);
1511 CONFLICT (DMULT
, DMACC
);
1512 CONFLICT (DIV
, MACC
);
1513 CONFLICT (DIV
, DMACC
);
1523 #define RTYPE_MASK 0x1ff00
1524 #define RTYPE_NUM 0x00100
1525 #define RTYPE_FPU 0x00200
1526 #define RTYPE_FCC 0x00400
1527 #define RTYPE_VEC 0x00800
1528 #define RTYPE_GP 0x01000
1529 #define RTYPE_CP0 0x02000
1530 #define RTYPE_PC 0x04000
1531 #define RTYPE_ACC 0x08000
1532 #define RTYPE_CCC 0x10000
1533 #define RNUM_MASK 0x000ff
1534 #define RWARN 0x80000
1536 #define GENERIC_REGISTER_NUMBERS \
1537 {"$0", RTYPE_NUM | 0}, \
1538 {"$1", RTYPE_NUM | 1}, \
1539 {"$2", RTYPE_NUM | 2}, \
1540 {"$3", RTYPE_NUM | 3}, \
1541 {"$4", RTYPE_NUM | 4}, \
1542 {"$5", RTYPE_NUM | 5}, \
1543 {"$6", RTYPE_NUM | 6}, \
1544 {"$7", RTYPE_NUM | 7}, \
1545 {"$8", RTYPE_NUM | 8}, \
1546 {"$9", RTYPE_NUM | 9}, \
1547 {"$10", RTYPE_NUM | 10}, \
1548 {"$11", RTYPE_NUM | 11}, \
1549 {"$12", RTYPE_NUM | 12}, \
1550 {"$13", RTYPE_NUM | 13}, \
1551 {"$14", RTYPE_NUM | 14}, \
1552 {"$15", RTYPE_NUM | 15}, \
1553 {"$16", RTYPE_NUM | 16}, \
1554 {"$17", RTYPE_NUM | 17}, \
1555 {"$18", RTYPE_NUM | 18}, \
1556 {"$19", RTYPE_NUM | 19}, \
1557 {"$20", RTYPE_NUM | 20}, \
1558 {"$21", RTYPE_NUM | 21}, \
1559 {"$22", RTYPE_NUM | 22}, \
1560 {"$23", RTYPE_NUM | 23}, \
1561 {"$24", RTYPE_NUM | 24}, \
1562 {"$25", RTYPE_NUM | 25}, \
1563 {"$26", RTYPE_NUM | 26}, \
1564 {"$27", RTYPE_NUM | 27}, \
1565 {"$28", RTYPE_NUM | 28}, \
1566 {"$29", RTYPE_NUM | 29}, \
1567 {"$30", RTYPE_NUM | 30}, \
1568 {"$31", RTYPE_NUM | 31}
1570 #define FPU_REGISTER_NAMES \
1571 {"$f0", RTYPE_FPU | 0}, \
1572 {"$f1", RTYPE_FPU | 1}, \
1573 {"$f2", RTYPE_FPU | 2}, \
1574 {"$f3", RTYPE_FPU | 3}, \
1575 {"$f4", RTYPE_FPU | 4}, \
1576 {"$f5", RTYPE_FPU | 5}, \
1577 {"$f6", RTYPE_FPU | 6}, \
1578 {"$f7", RTYPE_FPU | 7}, \
1579 {"$f8", RTYPE_FPU | 8}, \
1580 {"$f9", RTYPE_FPU | 9}, \
1581 {"$f10", RTYPE_FPU | 10}, \
1582 {"$f11", RTYPE_FPU | 11}, \
1583 {"$f12", RTYPE_FPU | 12}, \
1584 {"$f13", RTYPE_FPU | 13}, \
1585 {"$f14", RTYPE_FPU | 14}, \
1586 {"$f15", RTYPE_FPU | 15}, \
1587 {"$f16", RTYPE_FPU | 16}, \
1588 {"$f17", RTYPE_FPU | 17}, \
1589 {"$f18", RTYPE_FPU | 18}, \
1590 {"$f19", RTYPE_FPU | 19}, \
1591 {"$f20", RTYPE_FPU | 20}, \
1592 {"$f21", RTYPE_FPU | 21}, \
1593 {"$f22", RTYPE_FPU | 22}, \
1594 {"$f23", RTYPE_FPU | 23}, \
1595 {"$f24", RTYPE_FPU | 24}, \
1596 {"$f25", RTYPE_FPU | 25}, \
1597 {"$f26", RTYPE_FPU | 26}, \
1598 {"$f27", RTYPE_FPU | 27}, \
1599 {"$f28", RTYPE_FPU | 28}, \
1600 {"$f29", RTYPE_FPU | 29}, \
1601 {"$f30", RTYPE_FPU | 30}, \
1602 {"$f31", RTYPE_FPU | 31}
1604 #define FPU_CONDITION_CODE_NAMES \
1605 {"$fcc0", RTYPE_FCC | 0}, \
1606 {"$fcc1", RTYPE_FCC | 1}, \
1607 {"$fcc2", RTYPE_FCC | 2}, \
1608 {"$fcc3", RTYPE_FCC | 3}, \
1609 {"$fcc4", RTYPE_FCC | 4}, \
1610 {"$fcc5", RTYPE_FCC | 5}, \
1611 {"$fcc6", RTYPE_FCC | 6}, \
1612 {"$fcc7", RTYPE_FCC | 7}
1614 #define COPROC_CONDITION_CODE_NAMES \
1615 {"$cc0", RTYPE_FCC | RTYPE_CCC | 0}, \
1616 {"$cc1", RTYPE_FCC | RTYPE_CCC | 1}, \
1617 {"$cc2", RTYPE_FCC | RTYPE_CCC | 2}, \
1618 {"$cc3", RTYPE_FCC | RTYPE_CCC | 3}, \
1619 {"$cc4", RTYPE_FCC | RTYPE_CCC | 4}, \
1620 {"$cc5", RTYPE_FCC | RTYPE_CCC | 5}, \
1621 {"$cc6", RTYPE_FCC | RTYPE_CCC | 6}, \
1622 {"$cc7", RTYPE_FCC | RTYPE_CCC | 7}
1624 #define N32N64_SYMBOLIC_REGISTER_NAMES \
1625 {"$a4", RTYPE_GP | 8}, \
1626 {"$a5", RTYPE_GP | 9}, \
1627 {"$a6", RTYPE_GP | 10}, \
1628 {"$a7", RTYPE_GP | 11}, \
1629 {"$ta0", RTYPE_GP | 8}, /* alias for $a4 */ \
1630 {"$ta1", RTYPE_GP | 9}, /* alias for $a5 */ \
1631 {"$ta2", RTYPE_GP | 10}, /* alias for $a6 */ \
1632 {"$ta3", RTYPE_GP | 11}, /* alias for $a7 */ \
1633 {"$t0", RTYPE_GP | 12}, \
1634 {"$t1", RTYPE_GP | 13}, \
1635 {"$t2", RTYPE_GP | 14}, \
1636 {"$t3", RTYPE_GP | 15}
1638 #define O32_SYMBOLIC_REGISTER_NAMES \
1639 {"$t0", RTYPE_GP | 8}, \
1640 {"$t1", RTYPE_GP | 9}, \
1641 {"$t2", RTYPE_GP | 10}, \
1642 {"$t3", RTYPE_GP | 11}, \
1643 {"$t4", RTYPE_GP | 12}, \
1644 {"$t5", RTYPE_GP | 13}, \
1645 {"$t6", RTYPE_GP | 14}, \
1646 {"$t7", RTYPE_GP | 15}, \
1647 {"$ta0", RTYPE_GP | 12}, /* alias for $t4 */ \
1648 {"$ta1", RTYPE_GP | 13}, /* alias for $t5 */ \
1649 {"$ta2", RTYPE_GP | 14}, /* alias for $t6 */ \
1650 {"$ta3", RTYPE_GP | 15} /* alias for $t7 */
1652 /* Remaining symbolic register names */
1653 #define SYMBOLIC_REGISTER_NAMES \
1654 {"$zero", RTYPE_GP | 0}, \
1655 {"$at", RTYPE_GP | 1}, \
1656 {"$AT", RTYPE_GP | 1}, \
1657 {"$v0", RTYPE_GP | 2}, \
1658 {"$v1", RTYPE_GP | 3}, \
1659 {"$a0", RTYPE_GP | 4}, \
1660 {"$a1", RTYPE_GP | 5}, \
1661 {"$a2", RTYPE_GP | 6}, \
1662 {"$a3", RTYPE_GP | 7}, \
1663 {"$s0", RTYPE_GP | 16}, \
1664 {"$s1", RTYPE_GP | 17}, \
1665 {"$s2", RTYPE_GP | 18}, \
1666 {"$s3", RTYPE_GP | 19}, \
1667 {"$s4", RTYPE_GP | 20}, \
1668 {"$s5", RTYPE_GP | 21}, \
1669 {"$s6", RTYPE_GP | 22}, \
1670 {"$s7", RTYPE_GP | 23}, \
1671 {"$t8", RTYPE_GP | 24}, \
1672 {"$t9", RTYPE_GP | 25}, \
1673 {"$k0", RTYPE_GP | 26}, \
1674 {"$kt0", RTYPE_GP | 26}, \
1675 {"$k1", RTYPE_GP | 27}, \
1676 {"$kt1", RTYPE_GP | 27}, \
1677 {"$gp", RTYPE_GP | 28}, \
1678 {"$sp", RTYPE_GP | 29}, \
1679 {"$s8", RTYPE_GP | 30}, \
1680 {"$fp", RTYPE_GP | 30}, \
1681 {"$ra", RTYPE_GP | 31}
1683 #define MIPS16_SPECIAL_REGISTER_NAMES \
1684 {"$pc", RTYPE_PC | 0}
1686 #define MDMX_VECTOR_REGISTER_NAMES \
1687 /* {"$v0", RTYPE_VEC | 0}, clash with REG 2 above */ \
1688 /* {"$v1", RTYPE_VEC | 1}, clash with REG 3 above */ \
1689 {"$v2", RTYPE_VEC | 2}, \
1690 {"$v3", RTYPE_VEC | 3}, \
1691 {"$v4", RTYPE_VEC | 4}, \
1692 {"$v5", RTYPE_VEC | 5}, \
1693 {"$v6", RTYPE_VEC | 6}, \
1694 {"$v7", RTYPE_VEC | 7}, \
1695 {"$v8", RTYPE_VEC | 8}, \
1696 {"$v9", RTYPE_VEC | 9}, \
1697 {"$v10", RTYPE_VEC | 10}, \
1698 {"$v11", RTYPE_VEC | 11}, \
1699 {"$v12", RTYPE_VEC | 12}, \
1700 {"$v13", RTYPE_VEC | 13}, \
1701 {"$v14", RTYPE_VEC | 14}, \
1702 {"$v15", RTYPE_VEC | 15}, \
1703 {"$v16", RTYPE_VEC | 16}, \
1704 {"$v17", RTYPE_VEC | 17}, \
1705 {"$v18", RTYPE_VEC | 18}, \
1706 {"$v19", RTYPE_VEC | 19}, \
1707 {"$v20", RTYPE_VEC | 20}, \
1708 {"$v21", RTYPE_VEC | 21}, \
1709 {"$v22", RTYPE_VEC | 22}, \
1710 {"$v23", RTYPE_VEC | 23}, \
1711 {"$v24", RTYPE_VEC | 24}, \
1712 {"$v25", RTYPE_VEC | 25}, \
1713 {"$v26", RTYPE_VEC | 26}, \
1714 {"$v27", RTYPE_VEC | 27}, \
1715 {"$v28", RTYPE_VEC | 28}, \
1716 {"$v29", RTYPE_VEC | 29}, \
1717 {"$v30", RTYPE_VEC | 30}, \
1718 {"$v31", RTYPE_VEC | 31}
1720 #define MIPS_DSP_ACCUMULATOR_NAMES \
1721 {"$ac0", RTYPE_ACC | 0}, \
1722 {"$ac1", RTYPE_ACC | 1}, \
1723 {"$ac2", RTYPE_ACC | 2}, \
1724 {"$ac3", RTYPE_ACC | 3}
1726 static const struct regname reg_names
[] = {
1727 GENERIC_REGISTER_NUMBERS
,
1729 FPU_CONDITION_CODE_NAMES
,
1730 COPROC_CONDITION_CODE_NAMES
,
1732 /* The $txx registers depends on the abi,
1733 these will be added later into the symbol table from
1734 one of the tables below once mips_abi is set after
1735 parsing of arguments from the command line. */
1736 SYMBOLIC_REGISTER_NAMES
,
1738 MIPS16_SPECIAL_REGISTER_NAMES
,
1739 MDMX_VECTOR_REGISTER_NAMES
,
1740 MIPS_DSP_ACCUMULATOR_NAMES
,
1744 static const struct regname reg_names_o32
[] = {
1745 O32_SYMBOLIC_REGISTER_NAMES
,
1749 static const struct regname reg_names_n32n64
[] = {
1750 N32N64_SYMBOLIC_REGISTER_NAMES
,
1755 reg_lookup (char **s
, unsigned int types
, unsigned int *regnop
)
1762 /* Find end of name. */
1764 if (is_name_beginner (*e
))
1766 while (is_part_of_name (*e
))
1769 /* Terminate name. */
1773 /* Look for a register symbol. */
1774 if ((symbolP
= symbol_find (*s
)) && S_GET_SEGMENT (symbolP
) == reg_section
)
1776 int r
= S_GET_VALUE (symbolP
);
1778 reg
= r
& RNUM_MASK
;
1779 else if ((types
& RTYPE_VEC
) && (r
& ~1) == (RTYPE_GP
| 2))
1780 /* Convert GP reg $v0/1 to MDMX reg $v0/1! */
1781 reg
= (r
& RNUM_MASK
) - 2;
1783 /* Else see if this is a register defined in an itbl entry. */
1784 else if ((types
& RTYPE_GP
) && itbl_have_entries
)
1791 if (itbl_get_reg_val (n
, &r
))
1792 reg
= r
& RNUM_MASK
;
1795 /* Advance to next token if a register was recognised. */
1798 else if (types
& RWARN
)
1799 as_warn (_("Unrecognized register name `%s'"), *s
);
1807 /* Return TRUE if opcode MO is valid on the currently selected ISA and
1808 architecture. If EXPANSIONP is TRUE then this check is done while
1809 expanding a macro. Use is_opcode_valid_16 for MIPS16 opcodes. */
1812 is_opcode_valid (const struct mips_opcode
*mo
, bfd_boolean expansionp
)
1814 int isa
= mips_opts
.isa
;
1817 if (mips_opts
.ase_mdmx
)
1819 if (mips_opts
.ase_dsp
)
1821 if (mips_opts
.ase_dsp
&& ISA_SUPPORTS_DSP64_ASE
)
1823 if (mips_opts
.ase_dspr2
)
1825 if (mips_opts
.ase_mt
)
1827 if (mips_opts
.ase_mips3d
)
1829 if (mips_opts
.ase_smartmips
)
1830 isa
|= INSN_SMARTMIPS
;
1832 /* For user code we don't check for mips_opts.mips16 since we want
1833 to allow jalx if -mips16 was specified on the command line. */
1834 if (expansionp
? mips_opts
.mips16
: file_ase_mips16
)
1837 /* Don't accept instructions based on the ISA if the CPU does not implement
1838 all the coprocessor insns. */
1839 if (NO_ISA_COP (mips_opts
.arch
)
1840 && COP_INSN (mo
->pinfo
))
1843 if (!OPCODE_IS_MEMBER (mo
, isa
, mips_opts
.arch
))
1846 /* Check whether the instruction or macro requires single-precision or
1847 double-precision floating-point support. Note that this information is
1848 stored differently in the opcode table for insns and macros. */
1849 if (mo
->pinfo
== INSN_MACRO
)
1851 fp_s
= mo
->pinfo2
& INSN2_M_FP_S
;
1852 fp_d
= mo
->pinfo2
& INSN2_M_FP_D
;
1856 fp_s
= mo
->pinfo
& FP_S
;
1857 fp_d
= mo
->pinfo
& FP_D
;
1860 if (fp_d
&& (mips_opts
.soft_float
|| mips_opts
.single_float
))
1863 if (fp_s
&& mips_opts
.soft_float
)
1869 /* Return TRUE if the MIPS16 opcode MO is valid on the currently
1870 selected ISA and architecture. */
1873 is_opcode_valid_16 (const struct mips_opcode
*mo
)
1875 return OPCODE_IS_MEMBER (mo
, mips_opts
.isa
, mips_opts
.arch
) ? TRUE
: FALSE
;
1878 /* This function is called once, at assembler startup time. It should set up
1879 all the tables, etc. that the MD part of the assembler will need. */
1884 const char *retval
= NULL
;
1888 if (mips_pic
!= NO_PIC
)
1890 if (g_switch_seen
&& g_switch_value
!= 0)
1891 as_bad (_("-G may not be used in position-independent code"));
1895 if (! bfd_set_arch_mach (stdoutput
, bfd_arch_mips
, file_mips_arch
))
1896 as_warn (_("Could not set architecture and machine"));
1898 op_hash
= hash_new ();
1900 for (i
= 0; i
< NUMOPCODES
;)
1902 const char *name
= mips_opcodes
[i
].name
;
1904 retval
= hash_insert (op_hash
, name
, (void *) &mips_opcodes
[i
]);
1907 fprintf (stderr
, _("internal error: can't hash `%s': %s\n"),
1908 mips_opcodes
[i
].name
, retval
);
1909 /* Probably a memory allocation problem? Give up now. */
1910 as_fatal (_("Broken assembler. No assembly attempted."));
1914 if (mips_opcodes
[i
].pinfo
!= INSN_MACRO
)
1916 if (!validate_mips_insn (&mips_opcodes
[i
]))
1918 if (nop_insn
.insn_mo
== NULL
&& strcmp (name
, "nop") == 0)
1920 create_insn (&nop_insn
, mips_opcodes
+ i
);
1921 nop_insn
.fixed_p
= 1;
1926 while ((i
< NUMOPCODES
) && !strcmp (mips_opcodes
[i
].name
, name
));
1929 mips16_op_hash
= hash_new ();
1932 while (i
< bfd_mips16_num_opcodes
)
1934 const char *name
= mips16_opcodes
[i
].name
;
1936 retval
= hash_insert (mips16_op_hash
, name
, (void *) &mips16_opcodes
[i
]);
1938 as_fatal (_("internal: can't hash `%s': %s"),
1939 mips16_opcodes
[i
].name
, retval
);
1942 if (mips16_opcodes
[i
].pinfo
!= INSN_MACRO
1943 && ((mips16_opcodes
[i
].match
& mips16_opcodes
[i
].mask
)
1944 != mips16_opcodes
[i
].match
))
1946 fprintf (stderr
, _("internal error: bad mips16 opcode: %s %s\n"),
1947 mips16_opcodes
[i
].name
, mips16_opcodes
[i
].args
);
1950 if (mips16_nop_insn
.insn_mo
== NULL
&& strcmp (name
, "nop") == 0)
1952 create_insn (&mips16_nop_insn
, mips16_opcodes
+ i
);
1953 mips16_nop_insn
.fixed_p
= 1;
1957 while (i
< bfd_mips16_num_opcodes
1958 && strcmp (mips16_opcodes
[i
].name
, name
) == 0);
1962 as_fatal (_("Broken assembler. No assembly attempted."));
1964 /* We add all the general register names to the symbol table. This
1965 helps us detect invalid uses of them. */
1966 for (i
= 0; reg_names
[i
].name
; i
++)
1967 symbol_table_insert (symbol_new (reg_names
[i
].name
, reg_section
,
1968 reg_names
[i
].num
, /* & RNUM_MASK, */
1969 &zero_address_frag
));
1971 for (i
= 0; reg_names_n32n64
[i
].name
; i
++)
1972 symbol_table_insert (symbol_new (reg_names_n32n64
[i
].name
, reg_section
,
1973 reg_names_n32n64
[i
].num
, /* & RNUM_MASK, */
1974 &zero_address_frag
));
1976 for (i
= 0; reg_names_o32
[i
].name
; i
++)
1977 symbol_table_insert (symbol_new (reg_names_o32
[i
].name
, reg_section
,
1978 reg_names_o32
[i
].num
, /* & RNUM_MASK, */
1979 &zero_address_frag
));
1981 mips_no_prev_insn ();
1984 mips_cprmask
[0] = 0;
1985 mips_cprmask
[1] = 0;
1986 mips_cprmask
[2] = 0;
1987 mips_cprmask
[3] = 0;
1989 /* set the default alignment for the text section (2**2) */
1990 record_alignment (text_section
, 2);
1992 bfd_set_gp_size (stdoutput
, g_switch_value
);
1997 /* On a native system other than VxWorks, sections must be aligned
1998 to 16 byte boundaries. When configured for an embedded ELF
1999 target, we don't bother. */
2000 if (strncmp (TARGET_OS
, "elf", 3) != 0
2001 && strncmp (TARGET_OS
, "vxworks", 7) != 0)
2003 (void) bfd_set_section_alignment (stdoutput
, text_section
, 4);
2004 (void) bfd_set_section_alignment (stdoutput
, data_section
, 4);
2005 (void) bfd_set_section_alignment (stdoutput
, bss_section
, 4);
2008 /* Create a .reginfo section for register masks and a .mdebug
2009 section for debugging information. */
2017 subseg
= now_subseg
;
2019 /* The ABI says this section should be loaded so that the
2020 running program can access it. However, we don't load it
2021 if we are configured for an embedded target */
2022 flags
= SEC_READONLY
| SEC_DATA
;
2023 if (strncmp (TARGET_OS
, "elf", 3) != 0)
2024 flags
|= SEC_ALLOC
| SEC_LOAD
;
2026 if (mips_abi
!= N64_ABI
)
2028 sec
= subseg_new (".reginfo", (subsegT
) 0);
2030 bfd_set_section_flags (stdoutput
, sec
, flags
);
2031 bfd_set_section_alignment (stdoutput
, sec
, HAVE_NEWABI
? 3 : 2);
2033 mips_regmask_frag
= frag_more (sizeof (Elf32_External_RegInfo
));
2037 /* The 64-bit ABI uses a .MIPS.options section rather than
2038 .reginfo section. */
2039 sec
= subseg_new (".MIPS.options", (subsegT
) 0);
2040 bfd_set_section_flags (stdoutput
, sec
, flags
);
2041 bfd_set_section_alignment (stdoutput
, sec
, 3);
2043 /* Set up the option header. */
2045 Elf_Internal_Options opthdr
;
2048 opthdr
.kind
= ODK_REGINFO
;
2049 opthdr
.size
= (sizeof (Elf_External_Options
)
2050 + sizeof (Elf64_External_RegInfo
));
2053 f
= frag_more (sizeof (Elf_External_Options
));
2054 bfd_mips_elf_swap_options_out (stdoutput
, &opthdr
,
2055 (Elf_External_Options
*) f
);
2057 mips_regmask_frag
= frag_more (sizeof (Elf64_External_RegInfo
));
2061 if (ECOFF_DEBUGGING
)
2063 sec
= subseg_new (".mdebug", (subsegT
) 0);
2064 (void) bfd_set_section_flags (stdoutput
, sec
,
2065 SEC_HAS_CONTENTS
| SEC_READONLY
);
2066 (void) bfd_set_section_alignment (stdoutput
, sec
, 2);
2068 else if (mips_flag_pdr
)
2070 pdr_seg
= subseg_new (".pdr", (subsegT
) 0);
2071 (void) bfd_set_section_flags (stdoutput
, pdr_seg
,
2072 SEC_READONLY
| SEC_RELOC
2074 (void) bfd_set_section_alignment (stdoutput
, pdr_seg
, 2);
2077 subseg_set (seg
, subseg
);
2080 #endif /* OBJ_ELF */
2082 if (! ECOFF_DEBUGGING
)
2085 if (mips_fix_vr4120
)
2086 init_vr4120_conflicts ();
2092 if (! ECOFF_DEBUGGING
)
2097 md_assemble (char *str
)
2099 struct mips_cl_insn insn
;
2100 bfd_reloc_code_real_type unused_reloc
[3]
2101 = {BFD_RELOC_UNUSED
, BFD_RELOC_UNUSED
, BFD_RELOC_UNUSED
};
2103 imm_expr
.X_op
= O_absent
;
2104 imm2_expr
.X_op
= O_absent
;
2105 offset_expr
.X_op
= O_absent
;
2106 imm_reloc
[0] = BFD_RELOC_UNUSED
;
2107 imm_reloc
[1] = BFD_RELOC_UNUSED
;
2108 imm_reloc
[2] = BFD_RELOC_UNUSED
;
2109 offset_reloc
[0] = BFD_RELOC_UNUSED
;
2110 offset_reloc
[1] = BFD_RELOC_UNUSED
;
2111 offset_reloc
[2] = BFD_RELOC_UNUSED
;
2113 if (mips_opts
.mips16
)
2114 mips16_ip (str
, &insn
);
2117 mips_ip (str
, &insn
);
2118 DBG ((_("returned from mips_ip(%s) insn_opcode = 0x%x\n"),
2119 str
, insn
.insn_opcode
));
2124 as_bad ("%s `%s'", insn_error
, str
);
2128 if (insn
.insn_mo
->pinfo
== INSN_MACRO
)
2131 if (mips_opts
.mips16
)
2132 mips16_macro (&insn
);
2139 if (imm_expr
.X_op
!= O_absent
)
2140 append_insn (&insn
, &imm_expr
, imm_reloc
);
2141 else if (offset_expr
.X_op
!= O_absent
)
2142 append_insn (&insn
, &offset_expr
, offset_reloc
);
2144 append_insn (&insn
, NULL
, unused_reloc
);
2148 /* Convenience functions for abstracting away the differences between
2149 MIPS16 and non-MIPS16 relocations. */
2151 static inline bfd_boolean
2152 mips16_reloc_p (bfd_reloc_code_real_type reloc
)
2156 case BFD_RELOC_MIPS16_JMP
:
2157 case BFD_RELOC_MIPS16_GPREL
:
2158 case BFD_RELOC_MIPS16_GOT16
:
2159 case BFD_RELOC_MIPS16_CALL16
:
2160 case BFD_RELOC_MIPS16_HI16_S
:
2161 case BFD_RELOC_MIPS16_HI16
:
2162 case BFD_RELOC_MIPS16_LO16
:
2170 static inline bfd_boolean
2171 got16_reloc_p (bfd_reloc_code_real_type reloc
)
2173 return reloc
== BFD_RELOC_MIPS_GOT16
|| reloc
== BFD_RELOC_MIPS16_GOT16
;
2176 static inline bfd_boolean
2177 hi16_reloc_p (bfd_reloc_code_real_type reloc
)
2179 return reloc
== BFD_RELOC_HI16_S
|| reloc
== BFD_RELOC_MIPS16_HI16_S
;
2182 static inline bfd_boolean
2183 lo16_reloc_p (bfd_reloc_code_real_type reloc
)
2185 return reloc
== BFD_RELOC_LO16
|| reloc
== BFD_RELOC_MIPS16_LO16
;
2188 /* Return true if the given relocation might need a matching %lo().
2189 This is only "might" because SVR4 R_MIPS_GOT16 relocations only
2190 need a matching %lo() when applied to local symbols. */
2192 static inline bfd_boolean
2193 reloc_needs_lo_p (bfd_reloc_code_real_type reloc
)
2195 return (HAVE_IN_PLACE_ADDENDS
2196 && (hi16_reloc_p (reloc
)
2197 /* VxWorks R_MIPS_GOT16 relocs never need a matching %lo();
2198 all GOT16 relocations evaluate to "G". */
2199 || (got16_reloc_p (reloc
) && mips_pic
!= VXWORKS_PIC
)));
2202 /* Return the type of %lo() reloc needed by RELOC, given that
2203 reloc_needs_lo_p. */
2205 static inline bfd_reloc_code_real_type
2206 matching_lo_reloc (bfd_reloc_code_real_type reloc
)
2208 return mips16_reloc_p (reloc
) ? BFD_RELOC_MIPS16_LO16
: BFD_RELOC_LO16
;
2211 /* Return true if the given fixup is followed by a matching R_MIPS_LO16
2214 static inline bfd_boolean
2215 fixup_has_matching_lo_p (fixS
*fixp
)
2217 return (fixp
->fx_next
!= NULL
2218 && fixp
->fx_next
->fx_r_type
== matching_lo_reloc (fixp
->fx_r_type
)
2219 && fixp
->fx_addsy
== fixp
->fx_next
->fx_addsy
2220 && fixp
->fx_offset
== fixp
->fx_next
->fx_offset
);
2223 /* See whether instruction IP reads register REG. CLASS is the type
2227 insn_uses_reg (const struct mips_cl_insn
*ip
, unsigned int reg
,
2228 enum mips_regclass regclass
)
2230 if (regclass
== MIPS16_REG
)
2232 gas_assert (mips_opts
.mips16
);
2233 reg
= mips16_to_32_reg_map
[reg
];
2234 regclass
= MIPS_GR_REG
;
2237 /* Don't report on general register ZERO, since it never changes. */
2238 if (regclass
== MIPS_GR_REG
&& reg
== ZERO
)
2241 if (regclass
== MIPS_FP_REG
)
2243 gas_assert (! mips_opts
.mips16
);
2244 /* If we are called with either $f0 or $f1, we must check $f0.
2245 This is not optimal, because it will introduce an unnecessary
2246 NOP between "lwc1 $f0" and "swc1 $f1". To fix this we would
2247 need to distinguish reading both $f0 and $f1 or just one of
2248 them. Note that we don't have to check the other way,
2249 because there is no instruction that sets both $f0 and $f1
2250 and requires a delay. */
2251 if ((ip
->insn_mo
->pinfo
& INSN_READ_FPR_S
)
2252 && ((EXTRACT_OPERAND (FS
, *ip
) & ~(unsigned) 1)
2253 == (reg
&~ (unsigned) 1)))
2255 if ((ip
->insn_mo
->pinfo
& INSN_READ_FPR_T
)
2256 && ((EXTRACT_OPERAND (FT
, *ip
) & ~(unsigned) 1)
2257 == (reg
&~ (unsigned) 1)))
2260 else if (! mips_opts
.mips16
)
2262 if ((ip
->insn_mo
->pinfo
& INSN_READ_GPR_S
)
2263 && EXTRACT_OPERAND (RS
, *ip
) == reg
)
2265 if ((ip
->insn_mo
->pinfo
& INSN_READ_GPR_T
)
2266 && EXTRACT_OPERAND (RT
, *ip
) == reg
)
2271 if ((ip
->insn_mo
->pinfo
& MIPS16_INSN_READ_X
)
2272 && mips16_to_32_reg_map
[MIPS16_EXTRACT_OPERAND (RX
, *ip
)] == reg
)
2274 if ((ip
->insn_mo
->pinfo
& MIPS16_INSN_READ_Y
)
2275 && mips16_to_32_reg_map
[MIPS16_EXTRACT_OPERAND (RY
, *ip
)] == reg
)
2277 if ((ip
->insn_mo
->pinfo
& MIPS16_INSN_READ_Z
)
2278 && (mips16_to_32_reg_map
[MIPS16_EXTRACT_OPERAND (MOVE32Z
, *ip
)]
2281 if ((ip
->insn_mo
->pinfo
& MIPS16_INSN_READ_T
) && reg
== TREG
)
2283 if ((ip
->insn_mo
->pinfo
& MIPS16_INSN_READ_SP
) && reg
== SP
)
2285 if ((ip
->insn_mo
->pinfo
& MIPS16_INSN_READ_31
) && reg
== RA
)
2287 if ((ip
->insn_mo
->pinfo
& MIPS16_INSN_READ_GPR_X
)
2288 && MIPS16_EXTRACT_OPERAND (REGR32
, *ip
) == reg
)
2295 /* This function returns true if modifying a register requires a
2299 reg_needs_delay (unsigned int reg
)
2301 unsigned long prev_pinfo
;
2303 prev_pinfo
= history
[0].insn_mo
->pinfo
;
2304 if (! mips_opts
.noreorder
2305 && (((prev_pinfo
& INSN_LOAD_MEMORY_DELAY
)
2306 && ! gpr_interlocks
)
2307 || ((prev_pinfo
& INSN_LOAD_COPROC_DELAY
)
2308 && ! cop_interlocks
)))
2310 /* A load from a coprocessor or from memory. All load delays
2311 delay the use of general register rt for one instruction. */
2312 /* Itbl support may require additional care here. */
2313 know (prev_pinfo
& INSN_WRITE_GPR_T
);
2314 if (reg
== EXTRACT_OPERAND (RT
, history
[0]))
2321 /* Move all labels in insn_labels to the current insertion point. */
2324 mips_move_labels (void)
2326 segment_info_type
*si
= seg_info (now_seg
);
2327 struct insn_label_list
*l
;
2330 for (l
= si
->label_list
; l
!= NULL
; l
= l
->next
)
2332 gas_assert (S_GET_SEGMENT (l
->label
) == now_seg
);
2333 symbol_set_frag (l
->label
, frag_now
);
2334 val
= (valueT
) frag_now_fix ();
2335 /* mips16 text labels are stored as odd. */
2336 if (mips_opts
.mips16
)
2338 S_SET_VALUE (l
->label
, val
);
2343 s_is_linkonce (symbolS
*sym
, segT from_seg
)
2345 bfd_boolean linkonce
= FALSE
;
2346 segT symseg
= S_GET_SEGMENT (sym
);
2348 if (symseg
!= from_seg
&& !S_IS_LOCAL (sym
))
2350 if ((bfd_get_section_flags (stdoutput
, symseg
) & SEC_LINK_ONCE
))
2353 /* The GNU toolchain uses an extension for ELF: a section
2354 beginning with the magic string .gnu.linkonce is a
2355 linkonce section. */
2356 if (strncmp (segment_name (symseg
), ".gnu.linkonce",
2357 sizeof ".gnu.linkonce" - 1) == 0)
2364 /* Mark instruction labels in mips16 mode. This permits the linker to
2365 handle them specially, such as generating jalx instructions when
2366 needed. We also make them odd for the duration of the assembly, in
2367 order to generate the right sort of code. We will make them even
2368 in the adjust_symtab routine, while leaving them marked. This is
2369 convenient for the debugger and the disassembler. The linker knows
2370 to make them odd again. */
2373 mips16_mark_labels (void)
2375 segment_info_type
*si
= seg_info (now_seg
);
2376 struct insn_label_list
*l
;
2378 if (!mips_opts
.mips16
)
2381 for (l
= si
->label_list
; l
!= NULL
; l
= l
->next
)
2383 symbolS
*label
= l
->label
;
2385 #if defined(OBJ_ELF) || defined(OBJ_MAYBE_ELF)
2387 S_SET_OTHER (label
, ELF_ST_SET_MIPS16 (S_GET_OTHER (label
)));
2389 if ((S_GET_VALUE (label
) & 1) == 0
2390 /* Don't adjust the address if the label is global or weak, or
2391 in a link-once section, since we'll be emitting symbol reloc
2392 references to it which will be patched up by the linker, and
2393 the final value of the symbol may or may not be MIPS16. */
2394 && ! S_IS_WEAK (label
)
2395 && ! S_IS_EXTERNAL (label
)
2396 && ! s_is_linkonce (label
, now_seg
))
2397 S_SET_VALUE (label
, S_GET_VALUE (label
) | 1);
2401 /* End the current frag. Make it a variant frag and record the
2405 relax_close_frag (void)
2407 mips_macro_warning
.first_frag
= frag_now
;
2408 frag_var (rs_machine_dependent
, 0, 0,
2409 RELAX_ENCODE (mips_relax
.sizes
[0], mips_relax
.sizes
[1]),
2410 mips_relax
.symbol
, 0, (char *) mips_relax
.first_fixup
);
2412 memset (&mips_relax
.sizes
, 0, sizeof (mips_relax
.sizes
));
2413 mips_relax
.first_fixup
= 0;
2416 /* Start a new relaxation sequence whose expansion depends on SYMBOL.
2417 See the comment above RELAX_ENCODE for more details. */
2420 relax_start (symbolS
*symbol
)
2422 gas_assert (mips_relax
.sequence
== 0);
2423 mips_relax
.sequence
= 1;
2424 mips_relax
.symbol
= symbol
;
2427 /* Start generating the second version of a relaxable sequence.
2428 See the comment above RELAX_ENCODE for more details. */
2433 gas_assert (mips_relax
.sequence
== 1);
2434 mips_relax
.sequence
= 2;
2437 /* End the current relaxable sequence. */
2442 gas_assert (mips_relax
.sequence
== 2);
2443 relax_close_frag ();
2444 mips_relax
.sequence
= 0;
2447 /* Classify an instruction according to the FIX_VR4120_* enumeration.
2448 Return NUM_FIX_VR4120_CLASSES if the instruction isn't affected
2449 by VR4120 errata. */
2452 classify_vr4120_insn (const char *name
)
2454 if (strncmp (name
, "macc", 4) == 0)
2455 return FIX_VR4120_MACC
;
2456 if (strncmp (name
, "dmacc", 5) == 0)
2457 return FIX_VR4120_DMACC
;
2458 if (strncmp (name
, "mult", 4) == 0)
2459 return FIX_VR4120_MULT
;
2460 if (strncmp (name
, "dmult", 5) == 0)
2461 return FIX_VR4120_DMULT
;
2462 if (strstr (name
, "div"))
2463 return FIX_VR4120_DIV
;
2464 if (strcmp (name
, "mtlo") == 0 || strcmp (name
, "mthi") == 0)
2465 return FIX_VR4120_MTHILO
;
2466 return NUM_FIX_VR4120_CLASSES
;
2469 #define INSN_ERET 0x42000018
2470 #define INSN_DERET 0x4200001f
2472 /* Return the number of instructions that must separate INSN1 and INSN2,
2473 where INSN1 is the earlier instruction. Return the worst-case value
2474 for any INSN2 if INSN2 is null. */
2477 insns_between (const struct mips_cl_insn
*insn1
,
2478 const struct mips_cl_insn
*insn2
)
2480 unsigned long pinfo1
, pinfo2
;
2482 /* This function needs to know which pinfo flags are set for INSN2
2483 and which registers INSN2 uses. The former is stored in PINFO2 and
2484 the latter is tested via INSN2_USES_REG. If INSN2 is null, PINFO2
2485 will have every flag set and INSN2_USES_REG will always return true. */
2486 pinfo1
= insn1
->insn_mo
->pinfo
;
2487 pinfo2
= insn2
? insn2
->insn_mo
->pinfo
: ~0U;
2489 #define INSN2_USES_REG(REG, CLASS) \
2490 (insn2 == NULL || insn_uses_reg (insn2, REG, CLASS))
2492 /* For most targets, write-after-read dependencies on the HI and LO
2493 registers must be separated by at least two instructions. */
2494 if (!hilo_interlocks
)
2496 if ((pinfo1
& INSN_READ_LO
) && (pinfo2
& INSN_WRITE_LO
))
2498 if ((pinfo1
& INSN_READ_HI
) && (pinfo2
& INSN_WRITE_HI
))
2502 /* If we're working around r7000 errata, there must be two instructions
2503 between an mfhi or mflo and any instruction that uses the result. */
2504 if (mips_7000_hilo_fix
2505 && MF_HILO_INSN (pinfo1
)
2506 && INSN2_USES_REG (EXTRACT_OPERAND (RD
, *insn1
), MIPS_GR_REG
))
2509 /* If we're working around 24K errata, one instruction is required
2510 if an ERET or DERET is followed by a branch instruction. */
2513 if (insn1
->insn_opcode
== INSN_ERET
2514 || insn1
->insn_opcode
== INSN_DERET
)
2517 || insn2
->insn_opcode
== INSN_ERET
2518 || insn2
->insn_opcode
== INSN_DERET
2519 || (insn2
->insn_mo
->pinfo
2520 & (INSN_UNCOND_BRANCH_DELAY
2521 | INSN_COND_BRANCH_DELAY
2522 | INSN_COND_BRANCH_LIKELY
)) != 0)
2527 /* If working around VR4120 errata, check for combinations that need
2528 a single intervening instruction. */
2529 if (mips_fix_vr4120
)
2531 unsigned int class1
, class2
;
2533 class1
= classify_vr4120_insn (insn1
->insn_mo
->name
);
2534 if (class1
!= NUM_FIX_VR4120_CLASSES
&& vr4120_conflicts
[class1
] != 0)
2538 class2
= classify_vr4120_insn (insn2
->insn_mo
->name
);
2539 if (vr4120_conflicts
[class1
] & (1 << class2
))
2544 if (!mips_opts
.mips16
)
2546 /* Check for GPR or coprocessor load delays. All such delays
2547 are on the RT register. */
2548 /* Itbl support may require additional care here. */
2549 if ((!gpr_interlocks
&& (pinfo1
& INSN_LOAD_MEMORY_DELAY
))
2550 || (!cop_interlocks
&& (pinfo1
& INSN_LOAD_COPROC_DELAY
)))
2552 know (pinfo1
& INSN_WRITE_GPR_T
);
2553 if (INSN2_USES_REG (EXTRACT_OPERAND (RT
, *insn1
), MIPS_GR_REG
))
2557 /* Check for generic coprocessor hazards.
2559 This case is not handled very well. There is no special
2560 knowledge of CP0 handling, and the coprocessors other than
2561 the floating point unit are not distinguished at all. */
2562 /* Itbl support may require additional care here. FIXME!
2563 Need to modify this to include knowledge about
2564 user specified delays! */
2565 else if ((!cop_interlocks
&& (pinfo1
& INSN_COPROC_MOVE_DELAY
))
2566 || (!cop_mem_interlocks
&& (pinfo1
& INSN_COPROC_MEMORY_DELAY
)))
2568 /* Handle cases where INSN1 writes to a known general coprocessor
2569 register. There must be a one instruction delay before INSN2
2570 if INSN2 reads that register, otherwise no delay is needed. */
2571 if (pinfo1
& INSN_WRITE_FPR_T
)
2573 if (INSN2_USES_REG (EXTRACT_OPERAND (FT
, *insn1
), MIPS_FP_REG
))
2576 else if (pinfo1
& INSN_WRITE_FPR_S
)
2578 if (INSN2_USES_REG (EXTRACT_OPERAND (FS
, *insn1
), MIPS_FP_REG
))
2583 /* Read-after-write dependencies on the control registers
2584 require a two-instruction gap. */
2585 if ((pinfo1
& INSN_WRITE_COND_CODE
)
2586 && (pinfo2
& INSN_READ_COND_CODE
))
2589 /* We don't know exactly what INSN1 does. If INSN2 is
2590 also a coprocessor instruction, assume there must be
2591 a one instruction gap. */
2592 if (pinfo2
& INSN_COP
)
2597 /* Check for read-after-write dependencies on the coprocessor
2598 control registers in cases where INSN1 does not need a general
2599 coprocessor delay. This means that INSN1 is a floating point
2600 comparison instruction. */
2601 /* Itbl support may require additional care here. */
2602 else if (!cop_interlocks
2603 && (pinfo1
& INSN_WRITE_COND_CODE
)
2604 && (pinfo2
& INSN_READ_COND_CODE
))
2608 #undef INSN2_USES_REG
2613 /* Return the number of nops that would be needed to work around the
2614 VR4130 mflo/mfhi errata if instruction INSN immediately followed
2615 the MAX_VR4130_NOPS instructions described by HISTORY. */
2618 nops_for_vr4130 (const struct mips_cl_insn
*history
,
2619 const struct mips_cl_insn
*insn
)
2623 /* Check if the instruction writes to HI or LO. MTHI and MTLO
2624 are not affected by the errata. */
2626 && ((insn
->insn_mo
->pinfo
& (INSN_WRITE_HI
| INSN_WRITE_LO
)) == 0
2627 || strcmp (insn
->insn_mo
->name
, "mtlo") == 0
2628 || strcmp (insn
->insn_mo
->name
, "mthi") == 0))
2631 /* Search for the first MFLO or MFHI. */
2632 for (i
= 0; i
< MAX_VR4130_NOPS
; i
++)
2633 if (MF_HILO_INSN (history
[i
].insn_mo
->pinfo
))
2635 /* Extract the destination register. */
2636 if (mips_opts
.mips16
)
2637 reg
= mips16_to_32_reg_map
[MIPS16_EXTRACT_OPERAND (RX
, history
[i
])];
2639 reg
= EXTRACT_OPERAND (RD
, history
[i
]);
2641 /* No nops are needed if INSN reads that register. */
2642 if (insn
!= NULL
&& insn_uses_reg (insn
, reg
, MIPS_GR_REG
))
2645 /* ...or if any of the intervening instructions do. */
2646 for (j
= 0; j
< i
; j
++)
2647 if (insn_uses_reg (&history
[j
], reg
, MIPS_GR_REG
))
2650 return MAX_VR4130_NOPS
- i
;
2655 /* Return the number of nops that would be needed if instruction INSN
2656 immediately followed the MAX_NOPS instructions given by HISTORY,
2657 where HISTORY[0] is the most recent instruction. If INSN is null,
2658 return the worse-case number of nops for any instruction. */
2661 nops_for_insn (const struct mips_cl_insn
*history
,
2662 const struct mips_cl_insn
*insn
)
2664 int i
, nops
, tmp_nops
;
2667 for (i
= 0; i
< MAX_DELAY_NOPS
; i
++)
2669 tmp_nops
= insns_between (history
+ i
, insn
) - i
;
2670 if (tmp_nops
> nops
)
2674 if (mips_fix_vr4130
)
2676 tmp_nops
= nops_for_vr4130 (history
, insn
);
2677 if (tmp_nops
> nops
)
2684 /* The variable arguments provide NUM_INSNS extra instructions that
2685 might be added to HISTORY. Return the largest number of nops that
2686 would be needed after the extended sequence. */
2689 nops_for_sequence (int num_insns
, const struct mips_cl_insn
*history
, ...)
2692 struct mips_cl_insn buffer
[MAX_NOPS
];
2693 struct mips_cl_insn
*cursor
;
2696 va_start (args
, history
);
2697 cursor
= buffer
+ num_insns
;
2698 memcpy (cursor
, history
, (MAX_NOPS
- num_insns
) * sizeof (*cursor
));
2699 while (cursor
> buffer
)
2700 *--cursor
= *va_arg (args
, const struct mips_cl_insn
*);
2702 nops
= nops_for_insn (buffer
, NULL
);
2707 /* Like nops_for_insn, but if INSN is a branch, take into account the
2708 worst-case delay for the branch target. */
2711 nops_for_insn_or_target (const struct mips_cl_insn
*history
,
2712 const struct mips_cl_insn
*insn
)
2716 nops
= nops_for_insn (history
, insn
);
2717 if (insn
->insn_mo
->pinfo
& (INSN_UNCOND_BRANCH_DELAY
2718 | INSN_COND_BRANCH_DELAY
2719 | INSN_COND_BRANCH_LIKELY
))
2721 tmp_nops
= nops_for_sequence (2, history
, insn
, NOP_INSN
);
2722 if (tmp_nops
> nops
)
2725 else if (mips_opts
.mips16
&& (insn
->insn_mo
->pinfo
& MIPS16_INSN_BRANCH
))
2727 tmp_nops
= nops_for_sequence (1, history
, insn
);
2728 if (tmp_nops
> nops
)
2734 /* Output an instruction. IP is the instruction information.
2735 ADDRESS_EXPR is an operand of the instruction to be used with
2739 append_insn (struct mips_cl_insn
*ip
, expressionS
*address_expr
,
2740 bfd_reloc_code_real_type
*reloc_type
)
2742 unsigned long prev_pinfo
, pinfo
;
2743 relax_stateT prev_insn_frag_type
= 0;
2744 bfd_boolean relaxed_branch
= FALSE
;
2745 segment_info_type
*si
= seg_info (now_seg
);
2747 /* Mark instruction labels in mips16 mode. */
2748 mips16_mark_labels ();
2750 prev_pinfo
= history
[0].insn_mo
->pinfo
;
2751 pinfo
= ip
->insn_mo
->pinfo
;
2753 if (mips_relax
.sequence
!= 2 && !mips_opts
.noreorder
)
2755 /* There are a lot of optimizations we could do that we don't.
2756 In particular, we do not, in general, reorder instructions.
2757 If you use gcc with optimization, it will reorder
2758 instructions and generally do much more optimization then we
2759 do here; repeating all that work in the assembler would only
2760 benefit hand written assembly code, and does not seem worth
2762 int nops
= (mips_optimize
== 0
2763 ? nops_for_insn (history
, NULL
)
2764 : nops_for_insn_or_target (history
, ip
));
2768 unsigned long old_frag_offset
;
2771 old_frag
= frag_now
;
2772 old_frag_offset
= frag_now_fix ();
2774 for (i
= 0; i
< nops
; i
++)
2779 listing_prev_line ();
2780 /* We may be at the start of a variant frag. In case we
2781 are, make sure there is enough space for the frag
2782 after the frags created by listing_prev_line. The
2783 argument to frag_grow here must be at least as large
2784 as the argument to all other calls to frag_grow in
2785 this file. We don't have to worry about being in the
2786 middle of a variant frag, because the variants insert
2787 all needed nop instructions themselves. */
2791 mips_move_labels ();
2793 #ifndef NO_ECOFF_DEBUGGING
2794 if (ECOFF_DEBUGGING
)
2795 ecoff_fix_loc (old_frag
, old_frag_offset
);
2799 else if (mips_relax
.sequence
!= 2 && prev_nop_frag
!= NULL
)
2801 /* Work out how many nops in prev_nop_frag are needed by IP. */
2802 int nops
= nops_for_insn_or_target (history
, ip
);
2803 gas_assert (nops
<= prev_nop_frag_holds
);
2805 /* Enforce NOPS as a minimum. */
2806 if (nops
> prev_nop_frag_required
)
2807 prev_nop_frag_required
= nops
;
2809 if (prev_nop_frag_holds
== prev_nop_frag_required
)
2811 /* Settle for the current number of nops. Update the history
2812 accordingly (for the benefit of any future .set reorder code). */
2813 prev_nop_frag
= NULL
;
2814 insert_into_history (prev_nop_frag_since
,
2815 prev_nop_frag_holds
, NOP_INSN
);
2819 /* Allow this instruction to replace one of the nops that was
2820 tentatively added to prev_nop_frag. */
2821 prev_nop_frag
->fr_fix
-= mips_opts
.mips16
? 2 : 4;
2822 prev_nop_frag_holds
--;
2823 prev_nop_frag_since
++;
2828 /* The value passed to dwarf2_emit_insn is the distance between
2829 the beginning of the current instruction and the address that
2830 should be recorded in the debug tables. For MIPS16 debug info
2831 we want to use ISA-encoded addresses, so we pass -1 for an
2832 address higher by one than the current. */
2833 dwarf2_emit_insn (mips_opts
.mips16
? -1 : 0);
2836 /* Record the frag type before frag_var. */
2837 if (history
[0].frag
)
2838 prev_insn_frag_type
= history
[0].frag
->fr_type
;
2841 && *reloc_type
== BFD_RELOC_16_PCREL_S2
2842 && (pinfo
& INSN_UNCOND_BRANCH_DELAY
|| pinfo
& INSN_COND_BRANCH_DELAY
2843 || pinfo
& INSN_COND_BRANCH_LIKELY
)
2844 && mips_relax_branch
2845 /* Don't try branch relaxation within .set nomacro, or within
2846 .set noat if we use $at for PIC computations. If it turns
2847 out that the branch was out-of-range, we'll get an error. */
2848 && !mips_opts
.warn_about_macros
2849 && (mips_opts
.at
|| mips_pic
== NO_PIC
)
2850 && !mips_opts
.mips16
)
2852 relaxed_branch
= TRUE
;
2853 add_relaxed_insn (ip
, (relaxed_branch_length
2855 (pinfo
& INSN_UNCOND_BRANCH_DELAY
) ? -1
2856 : (pinfo
& INSN_COND_BRANCH_LIKELY
) ? 1
2859 (pinfo
& INSN_UNCOND_BRANCH_DELAY
,
2860 pinfo
& INSN_COND_BRANCH_LIKELY
,
2861 pinfo
& INSN_WRITE_GPR_31
,
2863 address_expr
->X_add_symbol
,
2864 address_expr
->X_add_number
);
2865 *reloc_type
= BFD_RELOC_UNUSED
;
2867 else if (*reloc_type
> BFD_RELOC_UNUSED
)
2869 /* We need to set up a variant frag. */
2870 gas_assert (mips_opts
.mips16
&& address_expr
!= NULL
);
2871 add_relaxed_insn (ip
, 4, 0,
2873 (*reloc_type
- BFD_RELOC_UNUSED
,
2874 mips16_small
, mips16_ext
,
2875 prev_pinfo
& INSN_UNCOND_BRANCH_DELAY
,
2876 history
[0].mips16_absolute_jump_p
),
2877 make_expr_symbol (address_expr
), 0);
2879 else if (mips_opts
.mips16
2881 && *reloc_type
!= BFD_RELOC_MIPS16_JMP
)
2883 if ((pinfo
& INSN_UNCOND_BRANCH_DELAY
) == 0)
2884 /* Make sure there is enough room to swap this instruction with
2885 a following jump instruction. */
2887 add_fixed_insn (ip
);
2891 if (mips_opts
.mips16
2892 && mips_opts
.noreorder
2893 && (prev_pinfo
& INSN_UNCOND_BRANCH_DELAY
) != 0)
2894 as_warn (_("extended instruction in delay slot"));
2896 if (mips_relax
.sequence
)
2898 /* If we've reached the end of this frag, turn it into a variant
2899 frag and record the information for the instructions we've
2901 if (frag_room () < 4)
2902 relax_close_frag ();
2903 mips_relax
.sizes
[mips_relax
.sequence
- 1] += 4;
2906 if (mips_relax
.sequence
!= 2)
2907 mips_macro_warning
.sizes
[0] += 4;
2908 if (mips_relax
.sequence
!= 1)
2909 mips_macro_warning
.sizes
[1] += 4;
2911 if (mips_opts
.mips16
)
2914 ip
->mips16_absolute_jump_p
= (*reloc_type
== BFD_RELOC_MIPS16_JMP
);
2916 add_fixed_insn (ip
);
2919 if (address_expr
!= NULL
&& *reloc_type
<= BFD_RELOC_UNUSED
)
2921 if (address_expr
->X_op
== O_constant
)
2925 switch (*reloc_type
)
2928 ip
->insn_opcode
|= address_expr
->X_add_number
;
2931 case BFD_RELOC_MIPS_HIGHEST
:
2932 tmp
= (address_expr
->X_add_number
+ 0x800080008000ull
) >> 48;
2933 ip
->insn_opcode
|= tmp
& 0xffff;
2936 case BFD_RELOC_MIPS_HIGHER
:
2937 tmp
= (address_expr
->X_add_number
+ 0x80008000ull
) >> 32;
2938 ip
->insn_opcode
|= tmp
& 0xffff;
2941 case BFD_RELOC_HI16_S
:
2942 tmp
= (address_expr
->X_add_number
+ 0x8000) >> 16;
2943 ip
->insn_opcode
|= tmp
& 0xffff;
2946 case BFD_RELOC_HI16
:
2947 ip
->insn_opcode
|= (address_expr
->X_add_number
>> 16) & 0xffff;
2950 case BFD_RELOC_UNUSED
:
2951 case BFD_RELOC_LO16
:
2952 case BFD_RELOC_MIPS_GOT_DISP
:
2953 ip
->insn_opcode
|= address_expr
->X_add_number
& 0xffff;
2956 case BFD_RELOC_MIPS_JMP
:
2957 if ((address_expr
->X_add_number
& 3) != 0)
2958 as_bad (_("jump to misaligned address (0x%lx)"),
2959 (unsigned long) address_expr
->X_add_number
);
2960 ip
->insn_opcode
|= (address_expr
->X_add_number
>> 2) & 0x3ffffff;
2963 case BFD_RELOC_MIPS16_JMP
:
2964 if ((address_expr
->X_add_number
& 3) != 0)
2965 as_bad (_("jump to misaligned address (0x%lx)"),
2966 (unsigned long) address_expr
->X_add_number
);
2968 (((address_expr
->X_add_number
& 0x7c0000) << 3)
2969 | ((address_expr
->X_add_number
& 0xf800000) >> 7)
2970 | ((address_expr
->X_add_number
& 0x3fffc) >> 2));
2973 case BFD_RELOC_16_PCREL_S2
:
2974 if ((address_expr
->X_add_number
& 3) != 0)
2975 as_bad (_("branch to misaligned address (0x%lx)"),
2976 (unsigned long) address_expr
->X_add_number
);
2977 if (mips_relax_branch
)
2979 if ((address_expr
->X_add_number
+ 0x20000) & ~0x3ffff)
2980 as_bad (_("branch address range overflow (0x%lx)"),
2981 (unsigned long) address_expr
->X_add_number
);
2982 ip
->insn_opcode
|= (address_expr
->X_add_number
>> 2) & 0xffff;
2989 else if (*reloc_type
< BFD_RELOC_UNUSED
)
2992 reloc_howto_type
*howto
;
2995 /* In a compound relocation, it is the final (outermost)
2996 operator that determines the relocated field. */
2997 for (i
= 1; i
< 3; i
++)
2998 if (reloc_type
[i
] == BFD_RELOC_UNUSED
)
3001 howto
= bfd_reloc_type_lookup (stdoutput
, reloc_type
[i
- 1]);
3004 /* To reproduce this failure try assembling gas/testsuites/
3005 gas/mips/mips16-intermix.s with a mips-ecoff targeted
3007 as_bad (_("Unsupported MIPS relocation number %d"), reloc_type
[i
- 1]);
3008 howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_16
);
3011 ip
->fixp
[0] = fix_new_exp (ip
->frag
, ip
->where
,
3012 bfd_get_reloc_size (howto
),
3014 reloc_type
[0] == BFD_RELOC_16_PCREL_S2
,
3017 /* Tag symbols that have a R_MIPS16_26 relocation against them. */
3018 if (reloc_type
[0] == BFD_RELOC_MIPS16_JMP
3019 && ip
->fixp
[0]->fx_addsy
)
3020 *symbol_get_tc (ip
->fixp
[0]->fx_addsy
) = 1;
3022 /* These relocations can have an addend that won't fit in
3023 4 octets for 64bit assembly. */
3025 && ! howto
->partial_inplace
3026 && (reloc_type
[0] == BFD_RELOC_16
3027 || reloc_type
[0] == BFD_RELOC_32
3028 || reloc_type
[0] == BFD_RELOC_MIPS_JMP
3029 || reloc_type
[0] == BFD_RELOC_GPREL16
3030 || reloc_type
[0] == BFD_RELOC_MIPS_LITERAL
3031 || reloc_type
[0] == BFD_RELOC_GPREL32
3032 || reloc_type
[0] == BFD_RELOC_64
3033 || reloc_type
[0] == BFD_RELOC_CTOR
3034 || reloc_type
[0] == BFD_RELOC_MIPS_SUB
3035 || reloc_type
[0] == BFD_RELOC_MIPS_HIGHEST
3036 || reloc_type
[0] == BFD_RELOC_MIPS_HIGHER
3037 || reloc_type
[0] == BFD_RELOC_MIPS_SCN_DISP
3038 || reloc_type
[0] == BFD_RELOC_MIPS_REL16
3039 || reloc_type
[0] == BFD_RELOC_MIPS_RELGOT
3040 || reloc_type
[0] == BFD_RELOC_MIPS16_GPREL
3041 || hi16_reloc_p (reloc_type
[0])
3042 || lo16_reloc_p (reloc_type
[0])))
3043 ip
->fixp
[0]->fx_no_overflow
= 1;
3045 if (mips_relax
.sequence
)
3047 if (mips_relax
.first_fixup
== 0)
3048 mips_relax
.first_fixup
= ip
->fixp
[0];
3050 else if (reloc_needs_lo_p (*reloc_type
))
3052 struct mips_hi_fixup
*hi_fixup
;
3054 /* Reuse the last entry if it already has a matching %lo. */
3055 hi_fixup
= mips_hi_fixup_list
;
3057 || !fixup_has_matching_lo_p (hi_fixup
->fixp
))
3059 hi_fixup
= ((struct mips_hi_fixup
*)
3060 xmalloc (sizeof (struct mips_hi_fixup
)));
3061 hi_fixup
->next
= mips_hi_fixup_list
;
3062 mips_hi_fixup_list
= hi_fixup
;
3064 hi_fixup
->fixp
= ip
->fixp
[0];
3065 hi_fixup
->seg
= now_seg
;
3068 /* Add fixups for the second and third relocations, if given.
3069 Note that the ABI allows the second relocation to be
3070 against RSS_UNDEF, RSS_GP, RSS_GP0 or RSS_LOC. At the
3071 moment we only use RSS_UNDEF, but we could add support
3072 for the others if it ever becomes necessary. */
3073 for (i
= 1; i
< 3; i
++)
3074 if (reloc_type
[i
] != BFD_RELOC_UNUSED
)
3076 ip
->fixp
[i
] = fix_new (ip
->frag
, ip
->where
,
3077 ip
->fixp
[0]->fx_size
, NULL
, 0,
3078 FALSE
, reloc_type
[i
]);
3080 /* Use fx_tcbit to mark compound relocs. */
3081 ip
->fixp
[0]->fx_tcbit
= 1;
3082 ip
->fixp
[i
]->fx_tcbit
= 1;
3088 /* Update the register mask information. */
3089 if (! mips_opts
.mips16
)
3091 if (pinfo
& INSN_WRITE_GPR_D
)
3092 mips_gprmask
|= 1 << EXTRACT_OPERAND (RD
, *ip
);
3093 if ((pinfo
& (INSN_WRITE_GPR_T
| INSN_READ_GPR_T
)) != 0)
3094 mips_gprmask
|= 1 << EXTRACT_OPERAND (RT
, *ip
);
3095 if (pinfo
& INSN_READ_GPR_S
)
3096 mips_gprmask
|= 1 << EXTRACT_OPERAND (RS
, *ip
);
3097 if (pinfo
& INSN_WRITE_GPR_31
)
3098 mips_gprmask
|= 1 << RA
;
3099 if (pinfo
& INSN_WRITE_FPR_D
)
3100 mips_cprmask
[1] |= 1 << EXTRACT_OPERAND (FD
, *ip
);
3101 if ((pinfo
& (INSN_WRITE_FPR_S
| INSN_READ_FPR_S
)) != 0)
3102 mips_cprmask
[1] |= 1 << EXTRACT_OPERAND (FS
, *ip
);
3103 if ((pinfo
& (INSN_WRITE_FPR_T
| INSN_READ_FPR_T
)) != 0)
3104 mips_cprmask
[1] |= 1 << EXTRACT_OPERAND (FT
, *ip
);
3105 if ((pinfo
& INSN_READ_FPR_R
) != 0)
3106 mips_cprmask
[1] |= 1 << EXTRACT_OPERAND (FR
, *ip
);
3107 if (pinfo
& INSN_COP
)
3109 /* We don't keep enough information to sort these cases out.
3110 The itbl support does keep this information however, although
3111 we currently don't support itbl fprmats as part of the cop
3112 instruction. May want to add this support in the future. */
3114 /* Never set the bit for $0, which is always zero. */
3115 mips_gprmask
&= ~1 << 0;
3119 if (pinfo
& (MIPS16_INSN_WRITE_X
| MIPS16_INSN_READ_X
))
3120 mips_gprmask
|= 1 << MIPS16_EXTRACT_OPERAND (RX
, *ip
);
3121 if (pinfo
& (MIPS16_INSN_WRITE_Y
| MIPS16_INSN_READ_Y
))
3122 mips_gprmask
|= 1 << MIPS16_EXTRACT_OPERAND (RY
, *ip
);
3123 if (pinfo
& MIPS16_INSN_WRITE_Z
)
3124 mips_gprmask
|= 1 << MIPS16_EXTRACT_OPERAND (RZ
, *ip
);
3125 if (pinfo
& (MIPS16_INSN_WRITE_T
| MIPS16_INSN_READ_T
))
3126 mips_gprmask
|= 1 << TREG
;
3127 if (pinfo
& (MIPS16_INSN_WRITE_SP
| MIPS16_INSN_READ_SP
))
3128 mips_gprmask
|= 1 << SP
;
3129 if (pinfo
& (MIPS16_INSN_WRITE_31
| MIPS16_INSN_READ_31
))
3130 mips_gprmask
|= 1 << RA
;
3131 if (pinfo
& MIPS16_INSN_WRITE_GPR_Y
)
3132 mips_gprmask
|= 1 << MIPS16OP_EXTRACT_REG32R (ip
->insn_opcode
);
3133 if (pinfo
& MIPS16_INSN_READ_Z
)
3134 mips_gprmask
|= 1 << MIPS16_EXTRACT_OPERAND (MOVE32Z
, *ip
);
3135 if (pinfo
& MIPS16_INSN_READ_GPR_X
)
3136 mips_gprmask
|= 1 << MIPS16_EXTRACT_OPERAND (REGR32
, *ip
);
3139 if (mips_relax
.sequence
!= 2 && !mips_opts
.noreorder
)
3141 /* Filling the branch delay slot is more complex. We try to
3142 switch the branch with the previous instruction, which we can
3143 do if the previous instruction does not set up a condition
3144 that the branch tests and if the branch is not itself the
3145 target of any branch. */
3146 if ((pinfo
& INSN_UNCOND_BRANCH_DELAY
)
3147 || (pinfo
& INSN_COND_BRANCH_DELAY
))
3149 if (mips_optimize
< 2
3150 /* If we have seen .set volatile or .set nomove, don't
3152 || mips_opts
.nomove
!= 0
3153 /* We can't swap if the previous instruction's position
3155 || history
[0].fixed_p
3156 /* If the previous previous insn was in a .set
3157 noreorder, we can't swap. Actually, the MIPS
3158 assembler will swap in this situation. However, gcc
3159 configured -with-gnu-as will generate code like
3165 in which we can not swap the bne and INSN. If gcc is
3166 not configured -with-gnu-as, it does not output the
3168 || history
[1].noreorder_p
3169 /* If the branch is itself the target of a branch, we
3170 can not swap. We cheat on this; all we check for is
3171 whether there is a label on this instruction. If
3172 there are any branches to anything other than a
3173 label, users must use .set noreorder. */
3174 || si
->label_list
!= NULL
3175 /* If the previous instruction is in a variant frag
3176 other than this branch's one, we cannot do the swap.
3177 This does not apply to the mips16, which uses variant
3178 frags for different purposes. */
3179 || (! mips_opts
.mips16
3180 && prev_insn_frag_type
== rs_machine_dependent
)
3181 /* Check for conflicts between the branch and the instructions
3182 before the candidate delay slot. */
3183 || nops_for_insn (history
+ 1, ip
) > 0
3184 /* Check for conflicts between the swapped sequence and the
3185 target of the branch. */
3186 || nops_for_sequence (2, history
+ 1, ip
, history
) > 0
3187 /* We do not swap with a trap instruction, since it
3188 complicates trap handlers to have the trap
3189 instruction be in a delay slot. */
3190 || (prev_pinfo
& INSN_TRAP
)
3191 /* If the branch reads a register that the previous
3192 instruction sets, we can not swap. */
3193 || (! mips_opts
.mips16
3194 && (prev_pinfo
& INSN_WRITE_GPR_T
)
3195 && insn_uses_reg (ip
, EXTRACT_OPERAND (RT
, history
[0]),
3197 || (! mips_opts
.mips16
3198 && (prev_pinfo
& INSN_WRITE_GPR_D
)
3199 && insn_uses_reg (ip
, EXTRACT_OPERAND (RD
, history
[0]),
3201 || (mips_opts
.mips16
3202 && (((prev_pinfo
& MIPS16_INSN_WRITE_X
)
3204 (ip
, MIPS16_EXTRACT_OPERAND (RX
, history
[0]),
3206 || ((prev_pinfo
& MIPS16_INSN_WRITE_Y
)
3208 (ip
, MIPS16_EXTRACT_OPERAND (RY
, history
[0]),
3210 || ((prev_pinfo
& MIPS16_INSN_WRITE_Z
)
3212 (ip
, MIPS16_EXTRACT_OPERAND (RZ
, history
[0]),
3214 || ((prev_pinfo
& MIPS16_INSN_WRITE_T
)
3215 && insn_uses_reg (ip
, TREG
, MIPS_GR_REG
))
3216 || ((prev_pinfo
& MIPS16_INSN_WRITE_31
)
3217 && insn_uses_reg (ip
, RA
, MIPS_GR_REG
))
3218 || ((prev_pinfo
& MIPS16_INSN_WRITE_GPR_Y
)
3219 && insn_uses_reg (ip
,
3220 MIPS16OP_EXTRACT_REG32R
3221 (history
[0].insn_opcode
),
3223 /* If the branch writes a register that the previous
3224 instruction sets, we can not swap (we know that
3225 branches write only to RD or to $31). */
3226 || (! mips_opts
.mips16
3227 && (prev_pinfo
& INSN_WRITE_GPR_T
)
3228 && (((pinfo
& INSN_WRITE_GPR_D
)
3229 && (EXTRACT_OPERAND (RT
, history
[0])
3230 == EXTRACT_OPERAND (RD
, *ip
)))
3231 || ((pinfo
& INSN_WRITE_GPR_31
)
3232 && EXTRACT_OPERAND (RT
, history
[0]) == RA
)))
3233 || (! mips_opts
.mips16
3234 && (prev_pinfo
& INSN_WRITE_GPR_D
)
3235 && (((pinfo
& INSN_WRITE_GPR_D
)
3236 && (EXTRACT_OPERAND (RD
, history
[0])
3237 == EXTRACT_OPERAND (RD
, *ip
)))
3238 || ((pinfo
& INSN_WRITE_GPR_31
)
3239 && EXTRACT_OPERAND (RD
, history
[0]) == RA
)))
3240 || (mips_opts
.mips16
3241 && (pinfo
& MIPS16_INSN_WRITE_31
)
3242 && ((prev_pinfo
& MIPS16_INSN_WRITE_31
)
3243 || ((prev_pinfo
& MIPS16_INSN_WRITE_GPR_Y
)
3244 && (MIPS16OP_EXTRACT_REG32R (history
[0].insn_opcode
)
3246 /* If the branch writes a register that the previous
3247 instruction reads, we can not swap (we know that
3248 branches only write to RD or to $31). */
3249 || (! mips_opts
.mips16
3250 && (pinfo
& INSN_WRITE_GPR_D
)
3251 && insn_uses_reg (&history
[0],
3252 EXTRACT_OPERAND (RD
, *ip
),
3254 || (! mips_opts
.mips16
3255 && (pinfo
& INSN_WRITE_GPR_31
)
3256 && insn_uses_reg (&history
[0], RA
, MIPS_GR_REG
))
3257 || (mips_opts
.mips16
3258 && (pinfo
& MIPS16_INSN_WRITE_31
)
3259 && insn_uses_reg (&history
[0], RA
, MIPS_GR_REG
))
3260 /* If one instruction sets a condition code and the
3261 other one uses a condition code, we can not swap. */
3262 || ((pinfo
& INSN_READ_COND_CODE
)
3263 && (prev_pinfo
& INSN_WRITE_COND_CODE
))
3264 || ((pinfo
& INSN_WRITE_COND_CODE
)
3265 && (prev_pinfo
& INSN_READ_COND_CODE
))
3266 /* If the previous instruction uses the PC, we can not
3268 || (mips_opts
.mips16
3269 && (prev_pinfo
& MIPS16_INSN_READ_PC
))
3270 /* If the previous instruction had a fixup in mips16
3271 mode, we can not swap. This normally means that the
3272 previous instruction was a 4 byte branch anyhow. */
3273 || (mips_opts
.mips16
&& history
[0].fixp
[0])
3274 /* If the previous instruction is a sync, sync.l, or
3275 sync.p, we can not swap. */
3276 || (prev_pinfo
& INSN_SYNC
)
3277 /* If the previous instruction is an ERET or
3278 DERET, avoid the swap. */
3279 || (history
[0].insn_opcode
== INSN_ERET
)
3280 || (history
[0].insn_opcode
== INSN_DERET
))
3282 if (mips_opts
.mips16
3283 && (pinfo
& INSN_UNCOND_BRANCH_DELAY
)
3284 && (pinfo
& (MIPS16_INSN_READ_X
| MIPS16_INSN_READ_31
))
3285 && ISA_SUPPORTS_MIPS16E
)
3287 /* Convert MIPS16 jr/jalr into a "compact" jump. */
3288 ip
->insn_opcode
|= 0x0080;
3290 insert_into_history (0, 1, ip
);
3294 /* We could do even better for unconditional branches to
3295 portions of this object file; we could pick up the
3296 instruction at the destination, put it in the delay
3297 slot, and bump the destination address. */
3298 insert_into_history (0, 1, ip
);
3302 if (mips_relax
.sequence
)
3303 mips_relax
.sizes
[mips_relax
.sequence
- 1] += 4;
3307 /* It looks like we can actually do the swap. */
3308 struct mips_cl_insn delay
= history
[0];
3309 if (mips_opts
.mips16
)
3311 know (delay
.frag
== ip
->frag
);
3312 move_insn (ip
, delay
.frag
, delay
.where
);
3313 move_insn (&delay
, ip
->frag
, ip
->where
+ insn_length (ip
));
3315 else if (relaxed_branch
)
3317 /* Add the delay slot instruction to the end of the
3318 current frag and shrink the fixed part of the
3319 original frag. If the branch occupies the tail of
3320 the latter, move it backwards to cover the gap. */
3321 delay
.frag
->fr_fix
-= 4;
3322 if (delay
.frag
== ip
->frag
)
3323 move_insn (ip
, ip
->frag
, ip
->where
- 4);
3324 add_fixed_insn (&delay
);
3328 move_insn (&delay
, ip
->frag
, ip
->where
);
3329 move_insn (ip
, history
[0].frag
, history
[0].where
);
3333 insert_into_history (0, 1, &delay
);
3336 /* If that was an unconditional branch, forget the previous
3337 insn information. */
3338 if (pinfo
& INSN_UNCOND_BRANCH_DELAY
)
3340 mips_no_prev_insn ();
3343 else if (pinfo
& INSN_COND_BRANCH_LIKELY
)
3345 /* We don't yet optimize a branch likely. What we should do
3346 is look at the target, copy the instruction found there
3347 into the delay slot, and increment the branch to jump to
3348 the next instruction. */
3349 insert_into_history (0, 1, ip
);
3353 insert_into_history (0, 1, ip
);
3356 insert_into_history (0, 1, ip
);
3358 /* We just output an insn, so the next one doesn't have a label. */
3359 mips_clear_insn_labels ();
3362 /* Forget that there was any previous instruction or label. */
3365 mips_no_prev_insn (void)
3367 prev_nop_frag
= NULL
;
3368 insert_into_history (0, ARRAY_SIZE (history
), NOP_INSN
);
3369 mips_clear_insn_labels ();
3372 /* This function must be called before we emit something other than
3373 instructions. It is like mips_no_prev_insn except that it inserts
3374 any NOPS that might be needed by previous instructions. */
3377 mips_emit_delays (void)
3379 if (! mips_opts
.noreorder
)
3381 int nops
= nops_for_insn (history
, NULL
);
3385 add_fixed_insn (NOP_INSN
);
3386 mips_move_labels ();
3389 mips_no_prev_insn ();
3392 /* Start a (possibly nested) noreorder block. */
3395 start_noreorder (void)
3397 if (mips_opts
.noreorder
== 0)
3402 /* None of the instructions before the .set noreorder can be moved. */
3403 for (i
= 0; i
< ARRAY_SIZE (history
); i
++)
3404 history
[i
].fixed_p
= 1;
3406 /* Insert any nops that might be needed between the .set noreorder
3407 block and the previous instructions. We will later remove any
3408 nops that turn out not to be needed. */
3409 nops
= nops_for_insn (history
, NULL
);
3412 if (mips_optimize
!= 0)
3414 /* Record the frag which holds the nop instructions, so
3415 that we can remove them if we don't need them. */
3416 frag_grow (mips_opts
.mips16
? nops
* 2 : nops
* 4);
3417 prev_nop_frag
= frag_now
;
3418 prev_nop_frag_holds
= nops
;
3419 prev_nop_frag_required
= 0;
3420 prev_nop_frag_since
= 0;
3423 for (; nops
> 0; --nops
)
3424 add_fixed_insn (NOP_INSN
);
3426 /* Move on to a new frag, so that it is safe to simply
3427 decrease the size of prev_nop_frag. */
3428 frag_wane (frag_now
);
3430 mips_move_labels ();
3432 mips16_mark_labels ();
3433 mips_clear_insn_labels ();
3435 mips_opts
.noreorder
++;
3436 mips_any_noreorder
= 1;
3439 /* End a nested noreorder block. */
3442 end_noreorder (void)
3445 mips_opts
.noreorder
--;
3446 if (mips_opts
.noreorder
== 0 && prev_nop_frag
!= NULL
)
3448 /* Commit to inserting prev_nop_frag_required nops and go back to
3449 handling nop insertion the .set reorder way. */
3450 prev_nop_frag
->fr_fix
-= ((prev_nop_frag_holds
- prev_nop_frag_required
)
3451 * (mips_opts
.mips16
? 2 : 4));
3452 insert_into_history (prev_nop_frag_since
,
3453 prev_nop_frag_required
, NOP_INSN
);
3454 prev_nop_frag
= NULL
;
3458 /* Set up global variables for the start of a new macro. */
3463 memset (&mips_macro_warning
.sizes
, 0, sizeof (mips_macro_warning
.sizes
));
3464 mips_macro_warning
.delay_slot_p
= (mips_opts
.noreorder
3465 && (history
[0].insn_mo
->pinfo
3466 & (INSN_UNCOND_BRANCH_DELAY
3467 | INSN_COND_BRANCH_DELAY
3468 | INSN_COND_BRANCH_LIKELY
)) != 0);
3471 /* Given that a macro is longer than 4 bytes, return the appropriate warning
3472 for it. Return null if no warning is needed. SUBTYPE is a bitmask of
3473 RELAX_DELAY_SLOT and RELAX_NOMACRO. */
3476 macro_warning (relax_substateT subtype
)
3478 if (subtype
& RELAX_DELAY_SLOT
)
3479 return _("Macro instruction expanded into multiple instructions"
3480 " in a branch delay slot");
3481 else if (subtype
& RELAX_NOMACRO
)
3482 return _("Macro instruction expanded into multiple instructions");
3487 /* Finish up a macro. Emit warnings as appropriate. */
3492 if (mips_macro_warning
.sizes
[0] > 4 || mips_macro_warning
.sizes
[1] > 4)
3494 relax_substateT subtype
;
3496 /* Set up the relaxation warning flags. */
3498 if (mips_macro_warning
.sizes
[1] > mips_macro_warning
.sizes
[0])
3499 subtype
|= RELAX_SECOND_LONGER
;
3500 if (mips_opts
.warn_about_macros
)
3501 subtype
|= RELAX_NOMACRO
;
3502 if (mips_macro_warning
.delay_slot_p
)
3503 subtype
|= RELAX_DELAY_SLOT
;
3505 if (mips_macro_warning
.sizes
[0] > 4 && mips_macro_warning
.sizes
[1] > 4)
3507 /* Either the macro has a single implementation or both
3508 implementations are longer than 4 bytes. Emit the
3510 const char *msg
= macro_warning (subtype
);
3512 as_warn ("%s", msg
);
3516 /* One implementation might need a warning but the other
3517 definitely doesn't. */
3518 mips_macro_warning
.first_frag
->fr_subtype
|= subtype
;
3523 /* Read a macro's relocation codes from *ARGS and store them in *R.
3524 The first argument in *ARGS will be either the code for a single
3525 relocation or -1 followed by the three codes that make up a
3526 composite relocation. */
3529 macro_read_relocs (va_list *args
, bfd_reloc_code_real_type
*r
)
3533 next
= va_arg (*args
, int);
3535 r
[0] = (bfd_reloc_code_real_type
) next
;
3537 for (i
= 0; i
< 3; i
++)
3538 r
[i
] = (bfd_reloc_code_real_type
) va_arg (*args
, int);
3541 /* Build an instruction created by a macro expansion. This is passed
3542 a pointer to the count of instructions created so far, an
3543 expression, the name of the instruction to build, an operand format
3544 string, and corresponding arguments. */
3547 macro_build (expressionS
*ep
, const char *name
, const char *fmt
, ...)
3549 const struct mips_opcode
*mo
;
3550 struct mips_cl_insn insn
;
3551 bfd_reloc_code_real_type r
[3];
3554 va_start (args
, fmt
);
3556 if (mips_opts
.mips16
)
3558 mips16_macro_build (ep
, name
, fmt
, args
);
3563 r
[0] = BFD_RELOC_UNUSED
;
3564 r
[1] = BFD_RELOC_UNUSED
;
3565 r
[2] = BFD_RELOC_UNUSED
;
3566 mo
= (struct mips_opcode
*) hash_find (op_hash
, name
);
3568 gas_assert (strcmp (name
, mo
->name
) == 0);
3572 /* Search until we get a match for NAME. It is assumed here that
3573 macros will never generate MDMX, MIPS-3D, or MT instructions. */
3574 if (strcmp (fmt
, mo
->args
) == 0
3575 && mo
->pinfo
!= INSN_MACRO
3576 && is_opcode_valid (mo
, TRUE
))
3580 gas_assert (mo
->name
);
3581 gas_assert (strcmp (name
, mo
->name
) == 0);
3584 create_insn (&insn
, mo
);
3602 INSERT_OPERAND (SHAMT
, insn
, va_arg (args
, int));
3607 /* Note that in the macro case, these arguments are already
3608 in MSB form. (When handling the instruction in the
3609 non-macro case, these arguments are sizes from which
3610 MSB values must be calculated.) */
3611 INSERT_OPERAND (INSMSB
, insn
, va_arg (args
, int));
3617 /* Note that in the macro case, these arguments are already
3618 in MSBD form. (When handling the instruction in the
3619 non-macro case, these arguments are sizes from which
3620 MSBD values must be calculated.) */
3621 INSERT_OPERAND (EXTMSBD
, insn
, va_arg (args
, int));
3625 INSERT_OPERAND (SEQI
, insn
, va_arg (args
, int));
3634 INSERT_OPERAND (BP
, insn
, va_arg (args
, int));
3640 INSERT_OPERAND (RT
, insn
, va_arg (args
, int));
3644 INSERT_OPERAND (CODE
, insn
, va_arg (args
, int));
3649 INSERT_OPERAND (FT
, insn
, va_arg (args
, int));
3655 INSERT_OPERAND (RD
, insn
, va_arg (args
, int));
3660 int tmp
= va_arg (args
, int);
3662 INSERT_OPERAND (RT
, insn
, tmp
);
3663 INSERT_OPERAND (RD
, insn
, tmp
);
3669 INSERT_OPERAND (FS
, insn
, va_arg (args
, int));
3676 INSERT_OPERAND (SHAMT
, insn
, va_arg (args
, int));
3680 INSERT_OPERAND (FD
, insn
, va_arg (args
, int));
3684 INSERT_OPERAND (CODE20
, insn
, va_arg (args
, int));
3688 INSERT_OPERAND (CODE19
, insn
, va_arg (args
, int));
3692 INSERT_OPERAND (CODE2
, insn
, va_arg (args
, int));
3699 INSERT_OPERAND (RS
, insn
, va_arg (args
, int));
3705 macro_read_relocs (&args
, r
);
3706 gas_assert (*r
== BFD_RELOC_GPREL16
3707 || *r
== BFD_RELOC_MIPS_LITERAL
3708 || *r
== BFD_RELOC_MIPS_HIGHER
3709 || *r
== BFD_RELOC_HI16_S
3710 || *r
== BFD_RELOC_LO16
3711 || *r
== BFD_RELOC_MIPS_GOT16
3712 || *r
== BFD_RELOC_MIPS_CALL16
3713 || *r
== BFD_RELOC_MIPS_GOT_DISP
3714 || *r
== BFD_RELOC_MIPS_GOT_PAGE
3715 || *r
== BFD_RELOC_MIPS_GOT_OFST
3716 || *r
== BFD_RELOC_MIPS_GOT_LO16
3717 || *r
== BFD_RELOC_MIPS_CALL_LO16
);
3721 macro_read_relocs (&args
, r
);
3722 gas_assert (ep
!= NULL
3723 && (ep
->X_op
== O_constant
3724 || (ep
->X_op
== O_symbol
3725 && (*r
== BFD_RELOC_MIPS_HIGHEST
3726 || *r
== BFD_RELOC_HI16_S
3727 || *r
== BFD_RELOC_HI16
3728 || *r
== BFD_RELOC_GPREL16
3729 || *r
== BFD_RELOC_MIPS_GOT_HI16
3730 || *r
== BFD_RELOC_MIPS_CALL_HI16
))));
3734 gas_assert (ep
!= NULL
);
3737 * This allows macro() to pass an immediate expression for
3738 * creating short branches without creating a symbol.
3740 * We don't allow branch relaxation for these branches, as
3741 * they should only appear in ".set nomacro" anyway.
3743 if (ep
->X_op
== O_constant
)
3745 if ((ep
->X_add_number
& 3) != 0)
3746 as_bad (_("branch to misaligned address (0x%lx)"),
3747 (unsigned long) ep
->X_add_number
);
3748 if ((ep
->X_add_number
+ 0x20000) & ~0x3ffff)
3749 as_bad (_("branch address range overflow (0x%lx)"),
3750 (unsigned long) ep
->X_add_number
);
3751 insn
.insn_opcode
|= (ep
->X_add_number
>> 2) & 0xffff;
3755 *r
= BFD_RELOC_16_PCREL_S2
;
3759 gas_assert (ep
!= NULL
);
3760 *r
= BFD_RELOC_MIPS_JMP
;
3764 INSERT_OPERAND (COPZ
, insn
, va_arg (args
, unsigned long));
3768 INSERT_OPERAND (CACHE
, insn
, va_arg (args
, unsigned long));
3777 gas_assert (*r
== BFD_RELOC_UNUSED
? ep
== NULL
: ep
!= NULL
);
3779 append_insn (&insn
, ep
, r
);
3783 mips16_macro_build (expressionS
*ep
, const char *name
, const char *fmt
,
3786 struct mips_opcode
*mo
;
3787 struct mips_cl_insn insn
;
3788 bfd_reloc_code_real_type r
[3]
3789 = {BFD_RELOC_UNUSED
, BFD_RELOC_UNUSED
, BFD_RELOC_UNUSED
};
3791 mo
= (struct mips_opcode
*) hash_find (mips16_op_hash
, name
);
3793 gas_assert (strcmp (name
, mo
->name
) == 0);
3795 while (strcmp (fmt
, mo
->args
) != 0 || mo
->pinfo
== INSN_MACRO
)
3798 gas_assert (mo
->name
);
3799 gas_assert (strcmp (name
, mo
->name
) == 0);
3802 create_insn (&insn
, mo
);
3820 MIPS16_INSERT_OPERAND (RY
, insn
, va_arg (args
, int));
3825 MIPS16_INSERT_OPERAND (RX
, insn
, va_arg (args
, int));
3829 MIPS16_INSERT_OPERAND (RZ
, insn
, va_arg (args
, int));
3833 MIPS16_INSERT_OPERAND (MOVE32Z
, insn
, va_arg (args
, int));
3843 MIPS16_INSERT_OPERAND (REGR32
, insn
, va_arg (args
, int));
3850 regno
= va_arg (args
, int);
3851 regno
= ((regno
& 7) << 2) | ((regno
& 0x18) >> 3);
3852 MIPS16_INSERT_OPERAND (REG32R
, insn
, regno
);
3873 gas_assert (ep
!= NULL
);
3875 if (ep
->X_op
!= O_constant
)
3876 *r
= (int) BFD_RELOC_UNUSED
+ c
;
3879 mips16_immed (NULL
, 0, c
, ep
->X_add_number
, FALSE
, FALSE
,
3880 FALSE
, &insn
.insn_opcode
, &insn
.use_extend
,
3883 *r
= BFD_RELOC_UNUSED
;
3889 MIPS16_INSERT_OPERAND (IMM6
, insn
, va_arg (args
, int));
3896 gas_assert (*r
== BFD_RELOC_UNUSED
? ep
== NULL
: ep
!= NULL
);
3898 append_insn (&insn
, ep
, r
);
3902 * Sign-extend 32-bit mode constants that have bit 31 set and all
3903 * higher bits unset.
3906 normalize_constant_expr (expressionS
*ex
)
3908 if (ex
->X_op
== O_constant
3909 && IS_ZEXT_32BIT_NUM (ex
->X_add_number
))
3910 ex
->X_add_number
= (((ex
->X_add_number
& 0xffffffff) ^ 0x80000000)
3915 * Sign-extend 32-bit mode address offsets that have bit 31 set and
3916 * all higher bits unset.
3919 normalize_address_expr (expressionS
*ex
)
3921 if (((ex
->X_op
== O_constant
&& HAVE_32BIT_ADDRESSES
)
3922 || (ex
->X_op
== O_symbol
&& HAVE_32BIT_SYMBOLS
))
3923 && IS_ZEXT_32BIT_NUM (ex
->X_add_number
))
3924 ex
->X_add_number
= (((ex
->X_add_number
& 0xffffffff) ^ 0x80000000)
3929 * Generate a "jalr" instruction with a relocation hint to the called
3930 * function. This occurs in NewABI PIC code.
3933 macro_build_jalr (expressionS
*ep
)
3937 if (MIPS_JALR_HINT_P (ep
))
3942 macro_build (NULL
, "jalr", "d,s", RA
, PIC_CALL_REG
);
3943 if (MIPS_JALR_HINT_P (ep
))
3944 fix_new_exp (frag_now
, f
- frag_now
->fr_literal
,
3945 4, ep
, FALSE
, BFD_RELOC_MIPS_JALR
);
3949 * Generate a "lui" instruction.
3952 macro_build_lui (expressionS
*ep
, int regnum
)
3954 expressionS high_expr
;
3955 const struct mips_opcode
*mo
;
3956 struct mips_cl_insn insn
;
3957 bfd_reloc_code_real_type r
[3]
3958 = {BFD_RELOC_UNUSED
, BFD_RELOC_UNUSED
, BFD_RELOC_UNUSED
};
3959 const char *name
= "lui";
3960 const char *fmt
= "t,u";
3962 gas_assert (! mips_opts
.mips16
);
3966 if (high_expr
.X_op
== O_constant
)
3968 /* We can compute the instruction now without a relocation entry. */
3969 high_expr
.X_add_number
= ((high_expr
.X_add_number
+ 0x8000)
3971 *r
= BFD_RELOC_UNUSED
;
3975 gas_assert (ep
->X_op
== O_symbol
);
3976 /* _gp_disp is a special case, used from s_cpload.
3977 __gnu_local_gp is used if mips_no_shared. */
3978 gas_assert (mips_pic
== NO_PIC
3980 && strcmp (S_GET_NAME (ep
->X_add_symbol
), "_gp_disp") == 0)
3981 || (! mips_in_shared
3982 && strcmp (S_GET_NAME (ep
->X_add_symbol
),
3983 "__gnu_local_gp") == 0));
3984 *r
= BFD_RELOC_HI16_S
;
3987 mo
= hash_find (op_hash
, name
);
3988 gas_assert (strcmp (name
, mo
->name
) == 0);
3989 gas_assert (strcmp (fmt
, mo
->args
) == 0);
3990 create_insn (&insn
, mo
);
3992 insn
.insn_opcode
= insn
.insn_mo
->match
;
3993 INSERT_OPERAND (RT
, insn
, regnum
);
3994 if (*r
== BFD_RELOC_UNUSED
)
3996 insn
.insn_opcode
|= high_expr
.X_add_number
;
3997 append_insn (&insn
, NULL
, r
);
4000 append_insn (&insn
, &high_expr
, r
);
4003 /* Generate a sequence of instructions to do a load or store from a constant
4004 offset off of a base register (breg) into/from a target register (treg),
4005 using AT if necessary. */
4007 macro_build_ldst_constoffset (expressionS
*ep
, const char *op
,
4008 int treg
, int breg
, int dbl
)
4010 gas_assert (ep
->X_op
== O_constant
);
4012 /* Sign-extending 32-bit constants makes their handling easier. */
4014 normalize_constant_expr (ep
);
4016 /* Right now, this routine can only handle signed 32-bit constants. */
4017 if (! IS_SEXT_32BIT_NUM(ep
->X_add_number
+ 0x8000))
4018 as_warn (_("operand overflow"));
4020 if (IS_SEXT_16BIT_NUM(ep
->X_add_number
))
4022 /* Signed 16-bit offset will fit in the op. Easy! */
4023 macro_build (ep
, op
, "t,o(b)", treg
, BFD_RELOC_LO16
, breg
);
4027 /* 32-bit offset, need multiple instructions and AT, like:
4028 lui $tempreg,const_hi (BFD_RELOC_HI16_S)
4029 addu $tempreg,$tempreg,$breg
4030 <op> $treg,const_lo($tempreg) (BFD_RELOC_LO16)
4031 to handle the complete offset. */
4032 macro_build_lui (ep
, AT
);
4033 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t", AT
, AT
, breg
);
4034 macro_build (ep
, op
, "t,o(b)", treg
, BFD_RELOC_LO16
, AT
);
4037 as_bad (_("Macro used $at after \".set noat\""));
4042 * Generates code to set the $at register to true (one)
4043 * if reg is less than the immediate expression.
4046 set_at (int reg
, int unsignedp
)
4048 if (imm_expr
.X_op
== O_constant
4049 && imm_expr
.X_add_number
>= -0x8000
4050 && imm_expr
.X_add_number
< 0x8000)
4051 macro_build (&imm_expr
, unsignedp
? "sltiu" : "slti", "t,r,j",
4052 AT
, reg
, BFD_RELOC_LO16
);
4055 load_register (AT
, &imm_expr
, HAVE_64BIT_GPRS
);
4056 macro_build (NULL
, unsignedp
? "sltu" : "slt", "d,v,t", AT
, reg
, AT
);
4060 /* Warn if an expression is not a constant. */
4063 check_absolute_expr (struct mips_cl_insn
*ip
, expressionS
*ex
)
4065 if (ex
->X_op
== O_big
)
4066 as_bad (_("unsupported large constant"));
4067 else if (ex
->X_op
!= O_constant
)
4068 as_bad (_("Instruction %s requires absolute expression"),
4071 if (HAVE_32BIT_GPRS
)
4072 normalize_constant_expr (ex
);
4075 /* Count the leading zeroes by performing a binary chop. This is a
4076 bulky bit of source, but performance is a LOT better for the
4077 majority of values than a simple loop to count the bits:
4078 for (lcnt = 0; (lcnt < 32); lcnt++)
4079 if ((v) & (1 << (31 - lcnt)))
4081 However it is not code size friendly, and the gain will drop a bit
4082 on certain cached systems.
4084 #define COUNT_TOP_ZEROES(v) \
4085 (((v) & ~0xffff) == 0 \
4086 ? ((v) & ~0xff) == 0 \
4087 ? ((v) & ~0xf) == 0 \
4088 ? ((v) & ~0x3) == 0 \
4089 ? ((v) & ~0x1) == 0 \
4094 : ((v) & ~0x7) == 0 \
4097 : ((v) & ~0x3f) == 0 \
4098 ? ((v) & ~0x1f) == 0 \
4101 : ((v) & ~0x7f) == 0 \
4104 : ((v) & ~0xfff) == 0 \
4105 ? ((v) & ~0x3ff) == 0 \
4106 ? ((v) & ~0x1ff) == 0 \
4109 : ((v) & ~0x7ff) == 0 \
4112 : ((v) & ~0x3fff) == 0 \
4113 ? ((v) & ~0x1fff) == 0 \
4116 : ((v) & ~0x7fff) == 0 \
4119 : ((v) & ~0xffffff) == 0 \
4120 ? ((v) & ~0xfffff) == 0 \
4121 ? ((v) & ~0x3ffff) == 0 \
4122 ? ((v) & ~0x1ffff) == 0 \
4125 : ((v) & ~0x7ffff) == 0 \
4128 : ((v) & ~0x3fffff) == 0 \
4129 ? ((v) & ~0x1fffff) == 0 \
4132 : ((v) & ~0x7fffff) == 0 \
4135 : ((v) & ~0xfffffff) == 0 \
4136 ? ((v) & ~0x3ffffff) == 0 \
4137 ? ((v) & ~0x1ffffff) == 0 \
4140 : ((v) & ~0x7ffffff) == 0 \
4143 : ((v) & ~0x3fffffff) == 0 \
4144 ? ((v) & ~0x1fffffff) == 0 \
4147 : ((v) & ~0x7fffffff) == 0 \
4152 * This routine generates the least number of instructions necessary to load
4153 * an absolute expression value into a register.
4156 load_register (int reg
, expressionS
*ep
, int dbl
)
4159 expressionS hi32
, lo32
;
4161 if (ep
->X_op
!= O_big
)
4163 gas_assert (ep
->X_op
== O_constant
);
4165 /* Sign-extending 32-bit constants makes their handling easier. */
4167 normalize_constant_expr (ep
);
4169 if (IS_SEXT_16BIT_NUM (ep
->X_add_number
))
4171 /* We can handle 16 bit signed values with an addiu to
4172 $zero. No need to ever use daddiu here, since $zero and
4173 the result are always correct in 32 bit mode. */
4174 macro_build (ep
, "addiu", "t,r,j", reg
, 0, BFD_RELOC_LO16
);
4177 else if (ep
->X_add_number
>= 0 && ep
->X_add_number
< 0x10000)
4179 /* We can handle 16 bit unsigned values with an ori to
4181 macro_build (ep
, "ori", "t,r,i", reg
, 0, BFD_RELOC_LO16
);
4184 else if ((IS_SEXT_32BIT_NUM (ep
->X_add_number
)))
4186 /* 32 bit values require an lui. */
4187 macro_build (ep
, "lui", "t,u", reg
, BFD_RELOC_HI16
);
4188 if ((ep
->X_add_number
& 0xffff) != 0)
4189 macro_build (ep
, "ori", "t,r,i", reg
, reg
, BFD_RELOC_LO16
);
4194 /* The value is larger than 32 bits. */
4196 if (!dbl
|| HAVE_32BIT_GPRS
)
4200 sprintf_vma (value
, ep
->X_add_number
);
4201 as_bad (_("Number (0x%s) larger than 32 bits"), value
);
4202 macro_build (ep
, "addiu", "t,r,j", reg
, 0, BFD_RELOC_LO16
);
4206 if (ep
->X_op
!= O_big
)
4209 hi32
.X_add_number
= (valueT
) hi32
.X_add_number
>> 16;
4210 hi32
.X_add_number
= (valueT
) hi32
.X_add_number
>> 16;
4211 hi32
.X_add_number
&= 0xffffffff;
4213 lo32
.X_add_number
&= 0xffffffff;
4217 gas_assert (ep
->X_add_number
> 2);
4218 if (ep
->X_add_number
== 3)
4219 generic_bignum
[3] = 0;
4220 else if (ep
->X_add_number
> 4)
4221 as_bad (_("Number larger than 64 bits"));
4222 lo32
.X_op
= O_constant
;
4223 lo32
.X_add_number
= generic_bignum
[0] + (generic_bignum
[1] << 16);
4224 hi32
.X_op
= O_constant
;
4225 hi32
.X_add_number
= generic_bignum
[2] + (generic_bignum
[3] << 16);
4228 if (hi32
.X_add_number
== 0)
4233 unsigned long hi
, lo
;
4235 if (hi32
.X_add_number
== (offsetT
) 0xffffffff)
4237 if ((lo32
.X_add_number
& 0xffff8000) == 0xffff8000)
4239 macro_build (&lo32
, "addiu", "t,r,j", reg
, 0, BFD_RELOC_LO16
);
4242 if (lo32
.X_add_number
& 0x80000000)
4244 macro_build (&lo32
, "lui", "t,u", reg
, BFD_RELOC_HI16
);
4245 if (lo32
.X_add_number
& 0xffff)
4246 macro_build (&lo32
, "ori", "t,r,i", reg
, reg
, BFD_RELOC_LO16
);
4251 /* Check for 16bit shifted constant. We know that hi32 is
4252 non-zero, so start the mask on the first bit of the hi32
4257 unsigned long himask
, lomask
;
4261 himask
= 0xffff >> (32 - shift
);
4262 lomask
= (0xffff << shift
) & 0xffffffff;
4266 himask
= 0xffff << (shift
- 32);
4269 if ((hi32
.X_add_number
& ~(offsetT
) himask
) == 0
4270 && (lo32
.X_add_number
& ~(offsetT
) lomask
) == 0)
4274 tmp
.X_op
= O_constant
;
4276 tmp
.X_add_number
= ((hi32
.X_add_number
<< (32 - shift
))
4277 | (lo32
.X_add_number
>> shift
));
4279 tmp
.X_add_number
= hi32
.X_add_number
>> (shift
- 32);
4280 macro_build (&tmp
, "ori", "t,r,i", reg
, 0, BFD_RELOC_LO16
);
4281 macro_build (NULL
, (shift
>= 32) ? "dsll32" : "dsll", "d,w,<",
4282 reg
, reg
, (shift
>= 32) ? shift
- 32 : shift
);
4287 while (shift
<= (64 - 16));
4289 /* Find the bit number of the lowest one bit, and store the
4290 shifted value in hi/lo. */
4291 hi
= (unsigned long) (hi32
.X_add_number
& 0xffffffff);
4292 lo
= (unsigned long) (lo32
.X_add_number
& 0xffffffff);
4296 while ((lo
& 1) == 0)
4301 lo
|= (hi
& (((unsigned long) 1 << bit
) - 1)) << (32 - bit
);
4307 while ((hi
& 1) == 0)
4316 /* Optimize if the shifted value is a (power of 2) - 1. */
4317 if ((hi
== 0 && ((lo
+ 1) & lo
) == 0)
4318 || (lo
== 0xffffffff && ((hi
+ 1) & hi
) == 0))
4320 shift
= COUNT_TOP_ZEROES ((unsigned int) hi32
.X_add_number
);
4325 /* This instruction will set the register to be all
4327 tmp
.X_op
= O_constant
;
4328 tmp
.X_add_number
= (offsetT
) -1;
4329 macro_build (&tmp
, "addiu", "t,r,j", reg
, 0, BFD_RELOC_LO16
);
4333 macro_build (NULL
, (bit
>= 32) ? "dsll32" : "dsll", "d,w,<",
4334 reg
, reg
, (bit
>= 32) ? bit
- 32 : bit
);
4336 macro_build (NULL
, (shift
>= 32) ? "dsrl32" : "dsrl", "d,w,<",
4337 reg
, reg
, (shift
>= 32) ? shift
- 32 : shift
);
4342 /* Sign extend hi32 before calling load_register, because we can
4343 generally get better code when we load a sign extended value. */
4344 if ((hi32
.X_add_number
& 0x80000000) != 0)
4345 hi32
.X_add_number
|= ~(offsetT
) 0xffffffff;
4346 load_register (reg
, &hi32
, 0);
4349 if ((lo32
.X_add_number
& 0xffff0000) == 0)
4353 macro_build (NULL
, "dsll32", "d,w,<", reg
, freg
, 0);
4361 if ((freg
== 0) && (lo32
.X_add_number
== (offsetT
) 0xffffffff))
4363 macro_build (&lo32
, "lui", "t,u", reg
, BFD_RELOC_HI16
);
4364 macro_build (NULL
, "dsrl32", "d,w,<", reg
, reg
, 0);
4370 macro_build (NULL
, "dsll", "d,w,<", reg
, freg
, 16);
4374 mid16
.X_add_number
>>= 16;
4375 macro_build (&mid16
, "ori", "t,r,i", reg
, freg
, BFD_RELOC_LO16
);
4376 macro_build (NULL
, "dsll", "d,w,<", reg
, reg
, 16);
4379 if ((lo32
.X_add_number
& 0xffff) != 0)
4380 macro_build (&lo32
, "ori", "t,r,i", reg
, freg
, BFD_RELOC_LO16
);
4384 load_delay_nop (void)
4386 if (!gpr_interlocks
)
4387 macro_build (NULL
, "nop", "");
4390 /* Load an address into a register. */
4393 load_address (int reg
, expressionS
*ep
, int *used_at
)
4395 if (ep
->X_op
!= O_constant
4396 && ep
->X_op
!= O_symbol
)
4398 as_bad (_("expression too complex"));
4399 ep
->X_op
= O_constant
;
4402 if (ep
->X_op
== O_constant
)
4404 load_register (reg
, ep
, HAVE_64BIT_ADDRESSES
);
4408 if (mips_pic
== NO_PIC
)
4410 /* If this is a reference to a GP relative symbol, we want
4411 addiu $reg,$gp,<sym> (BFD_RELOC_GPREL16)
4413 lui $reg,<sym> (BFD_RELOC_HI16_S)
4414 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
4415 If we have an addend, we always use the latter form.
4417 With 64bit address space and a usable $at we want
4418 lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST)
4419 lui $at,<sym> (BFD_RELOC_HI16_S)
4420 daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER)
4421 daddiu $at,<sym> (BFD_RELOC_LO16)
4425 If $at is already in use, we use a path which is suboptimal
4426 on superscalar processors.
4427 lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST)
4428 daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER)
4430 daddiu $reg,<sym> (BFD_RELOC_HI16_S)
4432 daddiu $reg,<sym> (BFD_RELOC_LO16)
4434 For GP relative symbols in 64bit address space we can use
4435 the same sequence as in 32bit address space. */
4436 if (HAVE_64BIT_SYMBOLS
)
4438 if ((valueT
) ep
->X_add_number
<= MAX_GPREL_OFFSET
4439 && !nopic_need_relax (ep
->X_add_symbol
, 1))
4441 relax_start (ep
->X_add_symbol
);
4442 macro_build (ep
, ADDRESS_ADDI_INSN
, "t,r,j", reg
,
4443 mips_gp_register
, BFD_RELOC_GPREL16
);
4447 if (*used_at
== 0 && mips_opts
.at
)
4449 macro_build (ep
, "lui", "t,u", reg
, BFD_RELOC_MIPS_HIGHEST
);
4450 macro_build (ep
, "lui", "t,u", AT
, BFD_RELOC_HI16_S
);
4451 macro_build (ep
, "daddiu", "t,r,j", reg
, reg
,
4452 BFD_RELOC_MIPS_HIGHER
);
4453 macro_build (ep
, "daddiu", "t,r,j", AT
, AT
, BFD_RELOC_LO16
);
4454 macro_build (NULL
, "dsll32", "d,w,<", reg
, reg
, 0);
4455 macro_build (NULL
, "daddu", "d,v,t", reg
, reg
, AT
);
4460 macro_build (ep
, "lui", "t,u", reg
, BFD_RELOC_MIPS_HIGHEST
);
4461 macro_build (ep
, "daddiu", "t,r,j", reg
, reg
,
4462 BFD_RELOC_MIPS_HIGHER
);
4463 macro_build (NULL
, "dsll", "d,w,<", reg
, reg
, 16);
4464 macro_build (ep
, "daddiu", "t,r,j", reg
, reg
, BFD_RELOC_HI16_S
);
4465 macro_build (NULL
, "dsll", "d,w,<", reg
, reg
, 16);
4466 macro_build (ep
, "daddiu", "t,r,j", reg
, reg
, BFD_RELOC_LO16
);
4469 if (mips_relax
.sequence
)
4474 if ((valueT
) ep
->X_add_number
<= MAX_GPREL_OFFSET
4475 && !nopic_need_relax (ep
->X_add_symbol
, 1))
4477 relax_start (ep
->X_add_symbol
);
4478 macro_build (ep
, ADDRESS_ADDI_INSN
, "t,r,j", reg
,
4479 mips_gp_register
, BFD_RELOC_GPREL16
);
4482 macro_build_lui (ep
, reg
);
4483 macro_build (ep
, ADDRESS_ADDI_INSN
, "t,r,j",
4484 reg
, reg
, BFD_RELOC_LO16
);
4485 if (mips_relax
.sequence
)
4489 else if (!mips_big_got
)
4493 /* If this is a reference to an external symbol, we want
4494 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4496 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4498 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
4499 If there is a constant, it must be added in after.
4501 If we have NewABI, we want
4502 lw $reg,<sym+cst>($gp) (BFD_RELOC_MIPS_GOT_DISP)
4503 unless we're referencing a global symbol with a non-zero
4504 offset, in which case cst must be added separately. */
4507 if (ep
->X_add_number
)
4509 ex
.X_add_number
= ep
->X_add_number
;
4510 ep
->X_add_number
= 0;
4511 relax_start (ep
->X_add_symbol
);
4512 macro_build (ep
, ADDRESS_LOAD_INSN
, "t,o(b)", reg
,
4513 BFD_RELOC_MIPS_GOT_DISP
, mips_gp_register
);
4514 if (ex
.X_add_number
< -0x8000 || ex
.X_add_number
>= 0x8000)
4515 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
4516 ex
.X_op
= O_constant
;
4517 macro_build (&ex
, ADDRESS_ADDI_INSN
, "t,r,j",
4518 reg
, reg
, BFD_RELOC_LO16
);
4519 ep
->X_add_number
= ex
.X_add_number
;
4522 macro_build (ep
, ADDRESS_LOAD_INSN
, "t,o(b)", reg
,
4523 BFD_RELOC_MIPS_GOT_DISP
, mips_gp_register
);
4524 if (mips_relax
.sequence
)
4529 ex
.X_add_number
= ep
->X_add_number
;
4530 ep
->X_add_number
= 0;
4531 macro_build (ep
, ADDRESS_LOAD_INSN
, "t,o(b)", reg
,
4532 BFD_RELOC_MIPS_GOT16
, mips_gp_register
);
4534 relax_start (ep
->X_add_symbol
);
4536 macro_build (ep
, ADDRESS_ADDI_INSN
, "t,r,j", reg
, reg
,
4540 if (ex
.X_add_number
!= 0)
4542 if (ex
.X_add_number
< -0x8000 || ex
.X_add_number
>= 0x8000)
4543 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
4544 ex
.X_op
= O_constant
;
4545 macro_build (&ex
, ADDRESS_ADDI_INSN
, "t,r,j",
4546 reg
, reg
, BFD_RELOC_LO16
);
4550 else if (mips_big_got
)
4554 /* This is the large GOT case. If this is a reference to an
4555 external symbol, we want
4556 lui $reg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
4558 lw $reg,<sym>($reg) (BFD_RELOC_MIPS_GOT_LO16)
4560 Otherwise, for a reference to a local symbol in old ABI, we want
4561 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4563 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
4564 If there is a constant, it must be added in after.
4566 In the NewABI, for local symbols, with or without offsets, we want:
4567 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
4568 addiu $reg,$reg,<sym> (BFD_RELOC_MIPS_GOT_OFST)
4572 ex
.X_add_number
= ep
->X_add_number
;
4573 ep
->X_add_number
= 0;
4574 relax_start (ep
->X_add_symbol
);
4575 macro_build (ep
, "lui", "t,u", reg
, BFD_RELOC_MIPS_GOT_HI16
);
4576 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t",
4577 reg
, reg
, mips_gp_register
);
4578 macro_build (ep
, ADDRESS_LOAD_INSN
, "t,o(b)",
4579 reg
, BFD_RELOC_MIPS_GOT_LO16
, reg
);
4580 if (ex
.X_add_number
< -0x8000 || ex
.X_add_number
>= 0x8000)
4581 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
4582 else if (ex
.X_add_number
)
4584 ex
.X_op
= O_constant
;
4585 macro_build (&ex
, ADDRESS_ADDI_INSN
, "t,r,j", reg
, reg
,
4589 ep
->X_add_number
= ex
.X_add_number
;
4591 macro_build (ep
, ADDRESS_LOAD_INSN
, "t,o(b)", reg
,
4592 BFD_RELOC_MIPS_GOT_PAGE
, mips_gp_register
);
4593 macro_build (ep
, ADDRESS_ADDI_INSN
, "t,r,j", reg
, reg
,
4594 BFD_RELOC_MIPS_GOT_OFST
);
4599 ex
.X_add_number
= ep
->X_add_number
;
4600 ep
->X_add_number
= 0;
4601 relax_start (ep
->X_add_symbol
);
4602 macro_build (ep
, "lui", "t,u", reg
, BFD_RELOC_MIPS_GOT_HI16
);
4603 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t",
4604 reg
, reg
, mips_gp_register
);
4605 macro_build (ep
, ADDRESS_LOAD_INSN
, "t,o(b)",
4606 reg
, BFD_RELOC_MIPS_GOT_LO16
, reg
);
4608 if (reg_needs_delay (mips_gp_register
))
4610 /* We need a nop before loading from $gp. This special
4611 check is required because the lui which starts the main
4612 instruction stream does not refer to $gp, and so will not
4613 insert the nop which may be required. */
4614 macro_build (NULL
, "nop", "");
4616 macro_build (ep
, ADDRESS_LOAD_INSN
, "t,o(b)", reg
,
4617 BFD_RELOC_MIPS_GOT16
, mips_gp_register
);
4619 macro_build (ep
, ADDRESS_ADDI_INSN
, "t,r,j", reg
, reg
,
4623 if (ex
.X_add_number
!= 0)
4625 if (ex
.X_add_number
< -0x8000 || ex
.X_add_number
>= 0x8000)
4626 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
4627 ex
.X_op
= O_constant
;
4628 macro_build (&ex
, ADDRESS_ADDI_INSN
, "t,r,j", reg
, reg
,
4636 if (!mips_opts
.at
&& *used_at
== 1)
4637 as_bad (_("Macro used $at after \".set noat\""));
4640 /* Move the contents of register SOURCE into register DEST. */
4643 move_register (int dest
, int source
)
4645 macro_build (NULL
, HAVE_32BIT_GPRS
? "addu" : "daddu", "d,v,t",
4649 /* Emit an SVR4 PIC sequence to load address LOCAL into DEST, where
4650 LOCAL is the sum of a symbol and a 16-bit or 32-bit displacement.
4651 The two alternatives are:
4653 Global symbol Local sybmol
4654 ------------- ------------
4655 lw DEST,%got(SYMBOL) lw DEST,%got(SYMBOL + OFFSET)
4657 addiu DEST,DEST,OFFSET addiu DEST,DEST,%lo(SYMBOL + OFFSET)
4659 load_got_offset emits the first instruction and add_got_offset
4660 emits the second for a 16-bit offset or add_got_offset_hilo emits
4661 a sequence to add a 32-bit offset using a scratch register. */
4664 load_got_offset (int dest
, expressionS
*local
)
4669 global
.X_add_number
= 0;
4671 relax_start (local
->X_add_symbol
);
4672 macro_build (&global
, ADDRESS_LOAD_INSN
, "t,o(b)", dest
,
4673 BFD_RELOC_MIPS_GOT16
, mips_gp_register
);
4675 macro_build (local
, ADDRESS_LOAD_INSN
, "t,o(b)", dest
,
4676 BFD_RELOC_MIPS_GOT16
, mips_gp_register
);
4681 add_got_offset (int dest
, expressionS
*local
)
4685 global
.X_op
= O_constant
;
4686 global
.X_op_symbol
= NULL
;
4687 global
.X_add_symbol
= NULL
;
4688 global
.X_add_number
= local
->X_add_number
;
4690 relax_start (local
->X_add_symbol
);
4691 macro_build (&global
, ADDRESS_ADDI_INSN
, "t,r,j",
4692 dest
, dest
, BFD_RELOC_LO16
);
4694 macro_build (local
, ADDRESS_ADDI_INSN
, "t,r,j", dest
, dest
, BFD_RELOC_LO16
);
4699 add_got_offset_hilo (int dest
, expressionS
*local
, int tmp
)
4702 int hold_mips_optimize
;
4704 global
.X_op
= O_constant
;
4705 global
.X_op_symbol
= NULL
;
4706 global
.X_add_symbol
= NULL
;
4707 global
.X_add_number
= local
->X_add_number
;
4709 relax_start (local
->X_add_symbol
);
4710 load_register (tmp
, &global
, HAVE_64BIT_ADDRESSES
);
4712 /* Set mips_optimize around the lui instruction to avoid
4713 inserting an unnecessary nop after the lw. */
4714 hold_mips_optimize
= mips_optimize
;
4716 macro_build_lui (&global
, tmp
);
4717 mips_optimize
= hold_mips_optimize
;
4718 macro_build (local
, ADDRESS_ADDI_INSN
, "t,r,j", tmp
, tmp
, BFD_RELOC_LO16
);
4721 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t", dest
, dest
, tmp
);
4726 * This routine implements the seemingly endless macro or synthesized
4727 * instructions and addressing modes in the mips assembly language. Many
4728 * of these macros are simple and are similar to each other. These could
4729 * probably be handled by some kind of table or grammar approach instead of
4730 * this verbose method. Others are not simple macros but are more like
4731 * optimizing code generation.
4732 * One interesting optimization is when several store macros appear
4733 * consecutively that would load AT with the upper half of the same address.
4734 * The ensuing load upper instructions are ommited. This implies some kind
4735 * of global optimization. We currently only optimize within a single macro.
4736 * For many of the load and store macros if the address is specified as a
4737 * constant expression in the first 64k of memory (ie ld $2,0x4000c) we
4738 * first load register 'at' with zero and use it as the base register. The
4739 * mips assembler simply uses register $zero. Just one tiny optimization
4743 macro (struct mips_cl_insn
*ip
)
4745 unsigned int treg
, sreg
, dreg
, breg
;
4746 unsigned int tempreg
;
4761 bfd_reloc_code_real_type r
;
4762 int hold_mips_optimize
;
4764 gas_assert (! mips_opts
.mips16
);
4766 treg
= (ip
->insn_opcode
>> 16) & 0x1f;
4767 dreg
= (ip
->insn_opcode
>> 11) & 0x1f;
4768 sreg
= breg
= (ip
->insn_opcode
>> 21) & 0x1f;
4769 mask
= ip
->insn_mo
->mask
;
4771 expr1
.X_op
= O_constant
;
4772 expr1
.X_op_symbol
= NULL
;
4773 expr1
.X_add_symbol
= NULL
;
4774 expr1
.X_add_number
= 1;
4788 expr1
.X_add_number
= 8;
4789 macro_build (&expr1
, "bgez", "s,p", sreg
);
4791 macro_build (NULL
, "nop", "", 0);
4793 move_register (dreg
, sreg
);
4794 macro_build (NULL
, dbl
? "dsub" : "sub", "d,v,t", dreg
, 0, sreg
);
4817 if (imm_expr
.X_op
== O_constant
4818 && imm_expr
.X_add_number
>= -0x8000
4819 && imm_expr
.X_add_number
< 0x8000)
4821 macro_build (&imm_expr
, s
, "t,r,j", treg
, sreg
, BFD_RELOC_LO16
);
4825 load_register (AT
, &imm_expr
, dbl
);
4826 macro_build (NULL
, s2
, "d,v,t", treg
, sreg
, AT
);
4845 if (imm_expr
.X_op
== O_constant
4846 && imm_expr
.X_add_number
>= 0
4847 && imm_expr
.X_add_number
< 0x10000)
4849 if (mask
!= M_NOR_I
)
4850 macro_build (&imm_expr
, s
, "t,r,i", treg
, sreg
, BFD_RELOC_LO16
);
4853 macro_build (&imm_expr
, "ori", "t,r,i",
4854 treg
, sreg
, BFD_RELOC_LO16
);
4855 macro_build (NULL
, "nor", "d,v,t", treg
, treg
, 0);
4861 load_register (AT
, &imm_expr
, HAVE_64BIT_GPRS
);
4862 macro_build (NULL
, s2
, "d,v,t", treg
, sreg
, AT
);
4866 switch (imm_expr
.X_add_number
)
4869 macro_build (NULL
, "nop", "");
4872 macro_build (NULL
, "packrl.ph", "d,s,t", treg
, treg
, sreg
);
4875 macro_build (NULL
, "balign", "t,s,2", treg
, sreg
,
4876 (int)imm_expr
.X_add_number
);
4895 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 0)
4897 macro_build (&offset_expr
, s
, "s,t,p", sreg
, 0);
4901 load_register (AT
, &imm_expr
, HAVE_64BIT_GPRS
);
4902 macro_build (&offset_expr
, s
, "s,t,p", sreg
, AT
);
4910 macro_build (&offset_expr
, likely
? "bgezl" : "bgez", "s,p", sreg
);
4915 macro_build (&offset_expr
, likely
? "blezl" : "blez", "s,p", treg
);
4919 macro_build (NULL
, "slt", "d,v,t", AT
, sreg
, treg
);
4920 macro_build (&offset_expr
, likely
? "beql" : "beq", "s,t,p", AT
, 0);
4926 /* check for > max integer */
4927 maxnum
= 0x7fffffff;
4928 if (HAVE_64BIT_GPRS
&& sizeof (maxnum
) > 4)
4935 if (imm_expr
.X_op
== O_constant
4936 && imm_expr
.X_add_number
>= maxnum
4937 && (HAVE_32BIT_GPRS
|| sizeof (maxnum
) > 4))
4940 /* result is always false */
4942 macro_build (NULL
, "nop", "", 0);
4944 macro_build (&offset_expr
, "bnel", "s,t,p", 0, 0);
4947 if (imm_expr
.X_op
!= O_constant
)
4948 as_bad (_("Unsupported large constant"));
4949 ++imm_expr
.X_add_number
;
4953 if (mask
== M_BGEL_I
)
4955 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 0)
4957 macro_build (&offset_expr
, likely
? "bgezl" : "bgez", "s,p", sreg
);
4960 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 1)
4962 macro_build (&offset_expr
, likely
? "bgtzl" : "bgtz", "s,p", sreg
);
4965 maxnum
= 0x7fffffff;
4966 if (HAVE_64BIT_GPRS
&& sizeof (maxnum
) > 4)
4973 maxnum
= - maxnum
- 1;
4974 if (imm_expr
.X_op
== O_constant
4975 && imm_expr
.X_add_number
<= maxnum
4976 && (HAVE_32BIT_GPRS
|| sizeof (maxnum
) > 4))
4979 /* result is always true */
4980 as_warn (_("Branch %s is always true"), ip
->insn_mo
->name
);
4981 macro_build (&offset_expr
, "b", "p");
4986 macro_build (&offset_expr
, likely
? "beql" : "beq", "s,t,p", AT
, 0);
4996 macro_build (&offset_expr
, likely
? "beql" : "beq",
5001 macro_build (NULL
, "sltu", "d,v,t", AT
, sreg
, treg
);
5002 macro_build (&offset_expr
, likely
? "beql" : "beq", "s,t,p", AT
, 0);
5010 && imm_expr
.X_op
== O_constant
5011 && imm_expr
.X_add_number
== (offsetT
) 0xffffffff))
5013 if (imm_expr
.X_op
!= O_constant
)
5014 as_bad (_("Unsupported large constant"));
5015 ++imm_expr
.X_add_number
;
5019 if (mask
== M_BGEUL_I
)
5021 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 0)
5023 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 1)
5025 macro_build (&offset_expr
, likely
? "bnel" : "bne",
5031 macro_build (&offset_expr
, likely
? "beql" : "beq", "s,t,p", AT
, 0);
5039 macro_build (&offset_expr
, likely
? "bgtzl" : "bgtz", "s,p", sreg
);
5044 macro_build (&offset_expr
, likely
? "bltzl" : "bltz", "s,p", treg
);
5048 macro_build (NULL
, "slt", "d,v,t", AT
, treg
, sreg
);
5049 macro_build (&offset_expr
, likely
? "bnel" : "bne", "s,t,p", AT
, 0);
5057 macro_build (&offset_expr
, likely
? "bnel" : "bne",
5064 macro_build (NULL
, "sltu", "d,v,t", AT
, treg
, sreg
);
5065 macro_build (&offset_expr
, likely
? "bnel" : "bne", "s,t,p", AT
, 0);
5073 macro_build (&offset_expr
, likely
? "blezl" : "blez", "s,p", sreg
);
5078 macro_build (&offset_expr
, likely
? "bgezl" : "bgez", "s,p", treg
);
5082 macro_build (NULL
, "slt", "d,v,t", AT
, treg
, sreg
);
5083 macro_build (&offset_expr
, likely
? "beql" : "beq", "s,t,p", AT
, 0);
5089 maxnum
= 0x7fffffff;
5090 if (HAVE_64BIT_GPRS
&& sizeof (maxnum
) > 4)
5097 if (imm_expr
.X_op
== O_constant
5098 && imm_expr
.X_add_number
>= maxnum
5099 && (HAVE_32BIT_GPRS
|| sizeof (maxnum
) > 4))
5101 if (imm_expr
.X_op
!= O_constant
)
5102 as_bad (_("Unsupported large constant"));
5103 ++imm_expr
.X_add_number
;
5107 if (mask
== M_BLTL_I
)
5109 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 0)
5111 macro_build (&offset_expr
, likely
? "bltzl" : "bltz", "s,p", sreg
);
5114 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 1)
5116 macro_build (&offset_expr
, likely
? "blezl" : "blez", "s,p", sreg
);
5121 macro_build (&offset_expr
, likely
? "bnel" : "bne", "s,t,p", AT
, 0);
5129 macro_build (&offset_expr
, likely
? "beql" : "beq",
5136 macro_build (NULL
, "sltu", "d,v,t", AT
, treg
, sreg
);
5137 macro_build (&offset_expr
, likely
? "beql" : "beq", "s,t,p", AT
, 0);
5145 && imm_expr
.X_op
== O_constant
5146 && imm_expr
.X_add_number
== (offsetT
) 0xffffffff))
5148 if (imm_expr
.X_op
!= O_constant
)
5149 as_bad (_("Unsupported large constant"));
5150 ++imm_expr
.X_add_number
;
5154 if (mask
== M_BLTUL_I
)
5156 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 0)
5158 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 1)
5160 macro_build (&offset_expr
, likely
? "beql" : "beq",
5166 macro_build (&offset_expr
, likely
? "bnel" : "bne", "s,t,p", AT
, 0);
5174 macro_build (&offset_expr
, likely
? "bltzl" : "bltz", "s,p", sreg
);
5179 macro_build (&offset_expr
, likely
? "bgtzl" : "bgtz", "s,p", treg
);
5183 macro_build (NULL
, "slt", "d,v,t", AT
, sreg
, treg
);
5184 macro_build (&offset_expr
, likely
? "bnel" : "bne", "s,t,p", AT
, 0);
5194 macro_build (&offset_expr
, likely
? "bnel" : "bne",
5199 macro_build (NULL
, "sltu", "d,v,t", AT
, sreg
, treg
);
5200 macro_build (&offset_expr
, likely
? "bnel" : "bne", "s,t,p", AT
, 0);
5208 if (imm_expr
.X_op
!= O_constant
|| imm2_expr
.X_op
!= O_constant
)
5210 as_bad (_("Unsupported large constant"));
5215 pos
= (unsigned long) imm_expr
.X_add_number
;
5216 size
= (unsigned long) imm2_expr
.X_add_number
;
5221 as_bad (_("Improper position (%lu)"), pos
);
5224 if (size
== 0 || size
> 64
5225 || (pos
+ size
- 1) > 63)
5227 as_bad (_("Improper extract size (%lu, position %lu)"),
5232 if (size
<= 32 && pos
< 32)
5237 else if (size
<= 32)
5247 macro_build ((expressionS
*) NULL
, s
, fmt
, treg
, sreg
, pos
, size
- 1);
5256 if (imm_expr
.X_op
!= O_constant
|| imm2_expr
.X_op
!= O_constant
)
5258 as_bad (_("Unsupported large constant"));
5263 pos
= (unsigned long) imm_expr
.X_add_number
;
5264 size
= (unsigned long) imm2_expr
.X_add_number
;
5269 as_bad (_("Improper position (%lu)"), pos
);
5272 if (size
== 0 || size
> 64
5273 || (pos
+ size
- 1) > 63)
5275 as_bad (_("Improper insert size (%lu, position %lu)"),
5280 if (pos
< 32 && (pos
+ size
- 1) < 32)
5295 macro_build ((expressionS
*) NULL
, s
, fmt
, treg
, sreg
, (int) pos
,
5296 (int) (pos
+ size
- 1));
5312 as_warn (_("Divide by zero."));
5314 macro_build (NULL
, "teq", "s,t,q", 0, 0, 7);
5316 macro_build (NULL
, "break", "c", 7);
5323 macro_build (NULL
, "teq", "s,t,q", treg
, 0, 7);
5324 macro_build (NULL
, dbl
? "ddiv" : "div", "z,s,t", sreg
, treg
);
5328 expr1
.X_add_number
= 8;
5329 macro_build (&expr1
, "bne", "s,t,p", treg
, 0);
5330 macro_build (NULL
, dbl
? "ddiv" : "div", "z,s,t", sreg
, treg
);
5331 macro_build (NULL
, "break", "c", 7);
5333 expr1
.X_add_number
= -1;
5335 load_register (AT
, &expr1
, dbl
);
5336 expr1
.X_add_number
= mips_trap
? (dbl
? 12 : 8) : (dbl
? 20 : 16);
5337 macro_build (&expr1
, "bne", "s,t,p", treg
, AT
);
5340 expr1
.X_add_number
= 1;
5341 load_register (AT
, &expr1
, dbl
);
5342 macro_build (NULL
, "dsll32", "d,w,<", AT
, AT
, 31);
5346 expr1
.X_add_number
= 0x80000000;
5347 macro_build (&expr1
, "lui", "t,u", AT
, BFD_RELOC_HI16
);
5351 macro_build (NULL
, "teq", "s,t,q", sreg
, AT
, 6);
5352 /* We want to close the noreorder block as soon as possible, so
5353 that later insns are available for delay slot filling. */
5358 expr1
.X_add_number
= 8;
5359 macro_build (&expr1
, "bne", "s,t,p", sreg
, AT
);
5360 macro_build (NULL
, "nop", "", 0);
5362 /* We want to close the noreorder block as soon as possible, so
5363 that later insns are available for delay slot filling. */
5366 macro_build (NULL
, "break", "c", 6);
5368 macro_build (NULL
, s
, "d", dreg
);
5407 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 0)
5409 as_warn (_("Divide by zero."));
5411 macro_build (NULL
, "teq", "s,t,q", 0, 0, 7);
5413 macro_build (NULL
, "break", "c", 7);
5416 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 1)
5418 if (strcmp (s2
, "mflo") == 0)
5419 move_register (dreg
, sreg
);
5421 move_register (dreg
, 0);
5424 if (imm_expr
.X_op
== O_constant
5425 && imm_expr
.X_add_number
== -1
5426 && s
[strlen (s
) - 1] != 'u')
5428 if (strcmp (s2
, "mflo") == 0)
5430 macro_build (NULL
, dbl
? "dneg" : "neg", "d,w", dreg
, sreg
);
5433 move_register (dreg
, 0);
5438 load_register (AT
, &imm_expr
, dbl
);
5439 macro_build (NULL
, s
, "z,s,t", sreg
, AT
);
5440 macro_build (NULL
, s2
, "d", dreg
);
5462 macro_build (NULL
, "teq", "s,t,q", treg
, 0, 7);
5463 macro_build (NULL
, s
, "z,s,t", sreg
, treg
);
5464 /* We want to close the noreorder block as soon as possible, so
5465 that later insns are available for delay slot filling. */
5470 expr1
.X_add_number
= 8;
5471 macro_build (&expr1
, "bne", "s,t,p", treg
, 0);
5472 macro_build (NULL
, s
, "z,s,t", sreg
, treg
);
5474 /* We want to close the noreorder block as soon as possible, so
5475 that later insns are available for delay slot filling. */
5477 macro_build (NULL
, "break", "c", 7);
5479 macro_build (NULL
, s2
, "d", dreg
);
5491 /* Load the address of a symbol into a register. If breg is not
5492 zero, we then add a base register to it. */
5494 if (dbl
&& HAVE_32BIT_GPRS
)
5495 as_warn (_("dla used to load 32-bit register"));
5497 if (! dbl
&& HAVE_64BIT_OBJECTS
)
5498 as_warn (_("la used to load 64-bit address"));
5500 if (offset_expr
.X_op
== O_constant
5501 && offset_expr
.X_add_number
>= -0x8000
5502 && offset_expr
.X_add_number
< 0x8000)
5504 macro_build (&offset_expr
, ADDRESS_ADDI_INSN
,
5505 "t,r,j", treg
, sreg
, BFD_RELOC_LO16
);
5509 if (mips_opts
.at
&& (treg
== breg
))
5519 if (offset_expr
.X_op
!= O_symbol
5520 && offset_expr
.X_op
!= O_constant
)
5522 as_bad (_("expression too complex"));
5523 offset_expr
.X_op
= O_constant
;
5526 if (offset_expr
.X_op
== O_constant
)
5527 load_register (tempreg
, &offset_expr
, HAVE_64BIT_ADDRESSES
);
5528 else if (mips_pic
== NO_PIC
)
5530 /* If this is a reference to a GP relative symbol, we want
5531 addiu $tempreg,$gp,<sym> (BFD_RELOC_GPREL16)
5533 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
5534 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
5535 If we have a constant, we need two instructions anyhow,
5536 so we may as well always use the latter form.
5538 With 64bit address space and a usable $at we want
5539 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5540 lui $at,<sym> (BFD_RELOC_HI16_S)
5541 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
5542 daddiu $at,<sym> (BFD_RELOC_LO16)
5544 daddu $tempreg,$tempreg,$at
5546 If $at is already in use, we use a path which is suboptimal
5547 on superscalar processors.
5548 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5549 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
5551 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
5553 daddiu $tempreg,<sym> (BFD_RELOC_LO16)
5555 For GP relative symbols in 64bit address space we can use
5556 the same sequence as in 32bit address space. */
5557 if (HAVE_64BIT_SYMBOLS
)
5559 if ((valueT
) offset_expr
.X_add_number
<= MAX_GPREL_OFFSET
5560 && !nopic_need_relax (offset_expr
.X_add_symbol
, 1))
5562 relax_start (offset_expr
.X_add_symbol
);
5563 macro_build (&offset_expr
, ADDRESS_ADDI_INSN
, "t,r,j",
5564 tempreg
, mips_gp_register
, BFD_RELOC_GPREL16
);
5568 if (used_at
== 0 && mips_opts
.at
)
5570 macro_build (&offset_expr
, "lui", "t,u",
5571 tempreg
, BFD_RELOC_MIPS_HIGHEST
);
5572 macro_build (&offset_expr
, "lui", "t,u",
5573 AT
, BFD_RELOC_HI16_S
);
5574 macro_build (&offset_expr
, "daddiu", "t,r,j",
5575 tempreg
, tempreg
, BFD_RELOC_MIPS_HIGHER
);
5576 macro_build (&offset_expr
, "daddiu", "t,r,j",
5577 AT
, AT
, BFD_RELOC_LO16
);
5578 macro_build (NULL
, "dsll32", "d,w,<", tempreg
, tempreg
, 0);
5579 macro_build (NULL
, "daddu", "d,v,t", tempreg
, tempreg
, AT
);
5584 macro_build (&offset_expr
, "lui", "t,u",
5585 tempreg
, BFD_RELOC_MIPS_HIGHEST
);
5586 macro_build (&offset_expr
, "daddiu", "t,r,j",
5587 tempreg
, tempreg
, BFD_RELOC_MIPS_HIGHER
);
5588 macro_build (NULL
, "dsll", "d,w,<", tempreg
, tempreg
, 16);
5589 macro_build (&offset_expr
, "daddiu", "t,r,j",
5590 tempreg
, tempreg
, BFD_RELOC_HI16_S
);
5591 macro_build (NULL
, "dsll", "d,w,<", tempreg
, tempreg
, 16);
5592 macro_build (&offset_expr
, "daddiu", "t,r,j",
5593 tempreg
, tempreg
, BFD_RELOC_LO16
);
5596 if (mips_relax
.sequence
)
5601 if ((valueT
) offset_expr
.X_add_number
<= MAX_GPREL_OFFSET
5602 && !nopic_need_relax (offset_expr
.X_add_symbol
, 1))
5604 relax_start (offset_expr
.X_add_symbol
);
5605 macro_build (&offset_expr
, ADDRESS_ADDI_INSN
, "t,r,j",
5606 tempreg
, mips_gp_register
, BFD_RELOC_GPREL16
);
5609 if (!IS_SEXT_32BIT_NUM (offset_expr
.X_add_number
))
5610 as_bad (_("offset too large"));
5611 macro_build_lui (&offset_expr
, tempreg
);
5612 macro_build (&offset_expr
, ADDRESS_ADDI_INSN
, "t,r,j",
5613 tempreg
, tempreg
, BFD_RELOC_LO16
);
5614 if (mips_relax
.sequence
)
5618 else if (!mips_big_got
&& !HAVE_NEWABI
)
5620 int lw_reloc_type
= (int) BFD_RELOC_MIPS_GOT16
;
5622 /* If this is a reference to an external symbol, and there
5623 is no constant, we want
5624 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5625 or for lca or if tempreg is PIC_CALL_REG
5626 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
5627 For a local symbol, we want
5628 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5630 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
5632 If we have a small constant, and this is a reference to
5633 an external symbol, we want
5634 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5636 addiu $tempreg,$tempreg,<constant>
5637 For a local symbol, we want the same instruction
5638 sequence, but we output a BFD_RELOC_LO16 reloc on the
5641 If we have a large constant, and this is a reference to
5642 an external symbol, we want
5643 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5644 lui $at,<hiconstant>
5645 addiu $at,$at,<loconstant>
5646 addu $tempreg,$tempreg,$at
5647 For a local symbol, we want the same instruction
5648 sequence, but we output a BFD_RELOC_LO16 reloc on the
5652 if (offset_expr
.X_add_number
== 0)
5654 if (mips_pic
== SVR4_PIC
5656 && (call
|| tempreg
== PIC_CALL_REG
))
5657 lw_reloc_type
= (int) BFD_RELOC_MIPS_CALL16
;
5659 relax_start (offset_expr
.X_add_symbol
);
5660 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)", tempreg
,
5661 lw_reloc_type
, mips_gp_register
);
5664 /* We're going to put in an addu instruction using
5665 tempreg, so we may as well insert the nop right
5670 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)",
5671 tempreg
, BFD_RELOC_MIPS_GOT16
, mips_gp_register
);
5673 macro_build (&offset_expr
, ADDRESS_ADDI_INSN
, "t,r,j",
5674 tempreg
, tempreg
, BFD_RELOC_LO16
);
5676 /* FIXME: If breg == 0, and the next instruction uses
5677 $tempreg, then if this variant case is used an extra
5678 nop will be generated. */
5680 else if (offset_expr
.X_add_number
>= -0x8000
5681 && offset_expr
.X_add_number
< 0x8000)
5683 load_got_offset (tempreg
, &offset_expr
);
5685 add_got_offset (tempreg
, &offset_expr
);
5689 expr1
.X_add_number
= offset_expr
.X_add_number
;
5690 offset_expr
.X_add_number
=
5691 ((offset_expr
.X_add_number
+ 0x8000) & 0xffff) - 0x8000;
5692 load_got_offset (tempreg
, &offset_expr
);
5693 offset_expr
.X_add_number
= expr1
.X_add_number
;
5694 /* If we are going to add in a base register, and the
5695 target register and the base register are the same,
5696 then we are using AT as a temporary register. Since
5697 we want to load the constant into AT, we add our
5698 current AT (from the global offset table) and the
5699 register into the register now, and pretend we were
5700 not using a base register. */
5704 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t",
5709 add_got_offset_hilo (tempreg
, &offset_expr
, AT
);
5713 else if (!mips_big_got
&& HAVE_NEWABI
)
5715 int add_breg_early
= 0;
5717 /* If this is a reference to an external, and there is no
5718 constant, or local symbol (*), with or without a
5720 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
5721 or for lca or if tempreg is PIC_CALL_REG
5722 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
5724 If we have a small constant, and this is a reference to
5725 an external symbol, we want
5726 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
5727 addiu $tempreg,$tempreg,<constant>
5729 If we have a large constant, and this is a reference to
5730 an external symbol, we want
5731 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
5732 lui $at,<hiconstant>
5733 addiu $at,$at,<loconstant>
5734 addu $tempreg,$tempreg,$at
5736 (*) Other assemblers seem to prefer GOT_PAGE/GOT_OFST for
5737 local symbols, even though it introduces an additional
5740 if (offset_expr
.X_add_number
)
5742 expr1
.X_add_number
= offset_expr
.X_add_number
;
5743 offset_expr
.X_add_number
= 0;
5745 relax_start (offset_expr
.X_add_symbol
);
5746 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)", tempreg
,
5747 BFD_RELOC_MIPS_GOT_DISP
, mips_gp_register
);
5749 if (expr1
.X_add_number
>= -0x8000
5750 && expr1
.X_add_number
< 0x8000)
5752 macro_build (&expr1
, ADDRESS_ADDI_INSN
, "t,r,j",
5753 tempreg
, tempreg
, BFD_RELOC_LO16
);
5755 else if (IS_SEXT_32BIT_NUM (expr1
.X_add_number
+ 0x8000))
5759 /* If we are going to add in a base register, and the
5760 target register and the base register are the same,
5761 then we are using AT as a temporary register. Since
5762 we want to load the constant into AT, we add our
5763 current AT (from the global offset table) and the
5764 register into the register now, and pretend we were
5765 not using a base register. */
5770 gas_assert (tempreg
== AT
);
5771 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t",
5777 load_register (AT
, &expr1
, HAVE_64BIT_ADDRESSES
);
5778 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t",
5784 as_bad (_("PIC code offset overflow (max 32 signed bits)"));
5787 offset_expr
.X_add_number
= expr1
.X_add_number
;
5789 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)", tempreg
,
5790 BFD_RELOC_MIPS_GOT_DISP
, mips_gp_register
);
5793 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t",
5794 treg
, tempreg
, breg
);
5800 else if (breg
== 0 && (call
|| tempreg
== PIC_CALL_REG
))
5802 relax_start (offset_expr
.X_add_symbol
);
5803 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)", tempreg
,
5804 BFD_RELOC_MIPS_CALL16
, mips_gp_register
);
5806 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)", tempreg
,
5807 BFD_RELOC_MIPS_GOT_DISP
, mips_gp_register
);
5812 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)", tempreg
,
5813 BFD_RELOC_MIPS_GOT_DISP
, mips_gp_register
);
5816 else if (mips_big_got
&& !HAVE_NEWABI
)
5819 int lui_reloc_type
= (int) BFD_RELOC_MIPS_GOT_HI16
;
5820 int lw_reloc_type
= (int) BFD_RELOC_MIPS_GOT_LO16
;
5821 int local_reloc_type
= (int) BFD_RELOC_MIPS_GOT16
;
5823 /* This is the large GOT case. If this is a reference to an
5824 external symbol, and there is no constant, we want
5825 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5826 addu $tempreg,$tempreg,$gp
5827 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5828 or for lca or if tempreg is PIC_CALL_REG
5829 lui $tempreg,<sym> (BFD_RELOC_MIPS_CALL_HI16)
5830 addu $tempreg,$tempreg,$gp
5831 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_CALL_LO16)
5832 For a local symbol, we want
5833 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5835 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
5837 If we have a small constant, and this is a reference to
5838 an external symbol, we want
5839 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5840 addu $tempreg,$tempreg,$gp
5841 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5843 addiu $tempreg,$tempreg,<constant>
5844 For a local symbol, we want
5845 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5847 addiu $tempreg,$tempreg,<constant> (BFD_RELOC_LO16)
5849 If we have a large constant, and this is a reference to
5850 an external symbol, we want
5851 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5852 addu $tempreg,$tempreg,$gp
5853 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5854 lui $at,<hiconstant>
5855 addiu $at,$at,<loconstant>
5856 addu $tempreg,$tempreg,$at
5857 For a local symbol, we want
5858 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5859 lui $at,<hiconstant>
5860 addiu $at,$at,<loconstant> (BFD_RELOC_LO16)
5861 addu $tempreg,$tempreg,$at
5864 expr1
.X_add_number
= offset_expr
.X_add_number
;
5865 offset_expr
.X_add_number
= 0;
5866 relax_start (offset_expr
.X_add_symbol
);
5867 gpdelay
= reg_needs_delay (mips_gp_register
);
5868 if (expr1
.X_add_number
== 0 && breg
== 0
5869 && (call
|| tempreg
== PIC_CALL_REG
))
5871 lui_reloc_type
= (int) BFD_RELOC_MIPS_CALL_HI16
;
5872 lw_reloc_type
= (int) BFD_RELOC_MIPS_CALL_LO16
;
5874 macro_build (&offset_expr
, "lui", "t,u", tempreg
, lui_reloc_type
);
5875 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t",
5876 tempreg
, tempreg
, mips_gp_register
);
5877 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)",
5878 tempreg
, lw_reloc_type
, tempreg
);
5879 if (expr1
.X_add_number
== 0)
5883 /* We're going to put in an addu instruction using
5884 tempreg, so we may as well insert the nop right
5889 else if (expr1
.X_add_number
>= -0x8000
5890 && expr1
.X_add_number
< 0x8000)
5893 macro_build (&expr1
, ADDRESS_ADDI_INSN
, "t,r,j",
5894 tempreg
, tempreg
, BFD_RELOC_LO16
);
5900 /* If we are going to add in a base register, and the
5901 target register and the base register are the same,
5902 then we are using AT as a temporary register. Since
5903 we want to load the constant into AT, we add our
5904 current AT (from the global offset table) and the
5905 register into the register now, and pretend we were
5906 not using a base register. */
5911 gas_assert (tempreg
== AT
);
5913 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t",
5918 load_register (AT
, &expr1
, HAVE_64BIT_ADDRESSES
);
5919 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t", dreg
, dreg
, AT
);
5923 offset_expr
.X_add_number
=
5924 ((expr1
.X_add_number
+ 0x8000) & 0xffff) - 0x8000;
5929 /* This is needed because this instruction uses $gp, but
5930 the first instruction on the main stream does not. */
5931 macro_build (NULL
, "nop", "");
5934 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)", tempreg
,
5935 local_reloc_type
, mips_gp_register
);
5936 if (expr1
.X_add_number
>= -0x8000
5937 && expr1
.X_add_number
< 0x8000)
5940 macro_build (&offset_expr
, ADDRESS_ADDI_INSN
, "t,r,j",
5941 tempreg
, tempreg
, BFD_RELOC_LO16
);
5942 /* FIXME: If add_number is 0, and there was no base
5943 register, the external symbol case ended with a load,
5944 so if the symbol turns out to not be external, and
5945 the next instruction uses tempreg, an unnecessary nop
5946 will be inserted. */
5952 /* We must add in the base register now, as in the
5953 external symbol case. */
5954 gas_assert (tempreg
== AT
);
5956 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t",
5959 /* We set breg to 0 because we have arranged to add
5960 it in in both cases. */
5964 macro_build_lui (&expr1
, AT
);
5965 macro_build (&offset_expr
, ADDRESS_ADDI_INSN
, "t,r,j",
5966 AT
, AT
, BFD_RELOC_LO16
);
5967 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t",
5968 tempreg
, tempreg
, AT
);
5973 else if (mips_big_got
&& HAVE_NEWABI
)
5975 int lui_reloc_type
= (int) BFD_RELOC_MIPS_GOT_HI16
;
5976 int lw_reloc_type
= (int) BFD_RELOC_MIPS_GOT_LO16
;
5977 int add_breg_early
= 0;
5979 /* This is the large GOT case. If this is a reference to an
5980 external symbol, and there is no constant, we want
5981 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5982 add $tempreg,$tempreg,$gp
5983 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5984 or for lca or if tempreg is PIC_CALL_REG
5985 lui $tempreg,<sym> (BFD_RELOC_MIPS_CALL_HI16)
5986 add $tempreg,$tempreg,$gp
5987 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_CALL_LO16)
5989 If we have a small constant, and this is a reference to
5990 an external symbol, we want
5991 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5992 add $tempreg,$tempreg,$gp
5993 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5994 addi $tempreg,$tempreg,<constant>
5996 If we have a large constant, and this is a reference to
5997 an external symbol, we want
5998 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5999 addu $tempreg,$tempreg,$gp
6000 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
6001 lui $at,<hiconstant>
6002 addi $at,$at,<loconstant>
6003 add $tempreg,$tempreg,$at
6005 If we have NewABI, and we know it's a local symbol, we want
6006 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
6007 addiu $reg,$reg,<sym> (BFD_RELOC_MIPS_GOT_OFST)
6008 otherwise we have to resort to GOT_HI16/GOT_LO16. */
6010 relax_start (offset_expr
.X_add_symbol
);
6012 expr1
.X_add_number
= offset_expr
.X_add_number
;
6013 offset_expr
.X_add_number
= 0;
6015 if (expr1
.X_add_number
== 0 && breg
== 0
6016 && (call
|| tempreg
== PIC_CALL_REG
))
6018 lui_reloc_type
= (int) BFD_RELOC_MIPS_CALL_HI16
;
6019 lw_reloc_type
= (int) BFD_RELOC_MIPS_CALL_LO16
;
6021 macro_build (&offset_expr
, "lui", "t,u", tempreg
, lui_reloc_type
);
6022 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t",
6023 tempreg
, tempreg
, mips_gp_register
);
6024 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)",
6025 tempreg
, lw_reloc_type
, tempreg
);
6027 if (expr1
.X_add_number
== 0)
6029 else if (expr1
.X_add_number
>= -0x8000
6030 && expr1
.X_add_number
< 0x8000)
6032 macro_build (&expr1
, ADDRESS_ADDI_INSN
, "t,r,j",
6033 tempreg
, tempreg
, BFD_RELOC_LO16
);
6035 else if (IS_SEXT_32BIT_NUM (expr1
.X_add_number
+ 0x8000))
6039 /* If we are going to add in a base register, and the
6040 target register and the base register are the same,
6041 then we are using AT as a temporary register. Since
6042 we want to load the constant into AT, we add our
6043 current AT (from the global offset table) and the
6044 register into the register now, and pretend we were
6045 not using a base register. */
6050 gas_assert (tempreg
== AT
);
6051 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t",
6057 load_register (AT
, &expr1
, HAVE_64BIT_ADDRESSES
);
6058 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t", dreg
, dreg
, AT
);
6063 as_bad (_("PIC code offset overflow (max 32 signed bits)"));
6066 offset_expr
.X_add_number
= expr1
.X_add_number
;
6067 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)", tempreg
,
6068 BFD_RELOC_MIPS_GOT_PAGE
, mips_gp_register
);
6069 macro_build (&offset_expr
, ADDRESS_ADDI_INSN
, "t,r,j", tempreg
,
6070 tempreg
, BFD_RELOC_MIPS_GOT_OFST
);
6073 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t",
6074 treg
, tempreg
, breg
);
6084 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t", treg
, tempreg
, breg
);
6089 unsigned long temp
= (treg
<< 16) | (0x01);
6090 macro_build (NULL
, "c2", "C", temp
);
6092 /* AT is not used, just return */
6097 unsigned long temp
= (0x02);
6098 macro_build (NULL
, "c2", "C", temp
);
6100 /* AT is not used, just return */
6105 unsigned long temp
= (treg
<< 16) | (0x02);
6106 macro_build (NULL
, "c2", "C", temp
);
6108 /* AT is not used, just return */
6112 macro_build (NULL
, "c2", "C", 3);
6113 /* AT is not used, just return */
6118 unsigned long temp
= (treg
<< 16) | 0x03;
6119 macro_build (NULL
, "c2", "C", temp
);
6121 /* AT is not used, just return */
6125 /* The j instruction may not be used in PIC code, since it
6126 requires an absolute address. We convert it to a b
6128 if (mips_pic
== NO_PIC
)
6129 macro_build (&offset_expr
, "j", "a");
6131 macro_build (&offset_expr
, "b", "p");
6134 /* The jal instructions must be handled as macros because when
6135 generating PIC code they expand to multi-instruction
6136 sequences. Normally they are simple instructions. */
6141 if (mips_pic
== NO_PIC
)
6142 macro_build (NULL
, "jalr", "d,s", dreg
, sreg
);
6145 if (sreg
!= PIC_CALL_REG
)
6146 as_warn (_("MIPS PIC call to register other than $25"));
6148 macro_build (NULL
, "jalr", "d,s", dreg
, sreg
);
6149 if (mips_pic
== SVR4_PIC
&& !HAVE_NEWABI
)
6151 if (mips_cprestore_offset
< 0)
6152 as_warn (_("No .cprestore pseudo-op used in PIC code"));
6155 if (! mips_frame_reg_valid
)
6157 as_warn (_("No .frame pseudo-op used in PIC code"));
6158 /* Quiet this warning. */
6159 mips_frame_reg_valid
= 1;
6161 if (! mips_cprestore_valid
)
6163 as_warn (_("No .cprestore pseudo-op used in PIC code"));
6164 /* Quiet this warning. */
6165 mips_cprestore_valid
= 1;
6167 expr1
.X_add_number
= mips_cprestore_offset
;
6168 macro_build_ldst_constoffset (&expr1
, ADDRESS_LOAD_INSN
,
6171 HAVE_64BIT_ADDRESSES
);
6179 if (mips_pic
== NO_PIC
)
6180 macro_build (&offset_expr
, "jal", "a");
6181 else if (mips_pic
== SVR4_PIC
)
6183 /* If this is a reference to an external symbol, and we are
6184 using a small GOT, we want
6185 lw $25,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
6189 lw $gp,cprestore($sp)
6190 The cprestore value is set using the .cprestore
6191 pseudo-op. If we are using a big GOT, we want
6192 lui $25,<sym> (BFD_RELOC_MIPS_CALL_HI16)
6194 lw $25,<sym>($25) (BFD_RELOC_MIPS_CALL_LO16)
6198 lw $gp,cprestore($sp)
6199 If the symbol is not external, we want
6200 lw $25,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6202 addiu $25,$25,<sym> (BFD_RELOC_LO16)
6205 lw $gp,cprestore($sp)
6207 For NewABI, we use the same CALL16 or CALL_HI16/CALL_LO16
6208 sequences above, minus nops, unless the symbol is local,
6209 which enables us to use GOT_PAGE/GOT_OFST (big got) or
6215 relax_start (offset_expr
.X_add_symbol
);
6216 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)",
6217 PIC_CALL_REG
, BFD_RELOC_MIPS_CALL16
,
6220 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)",
6221 PIC_CALL_REG
, BFD_RELOC_MIPS_GOT_DISP
,
6227 relax_start (offset_expr
.X_add_symbol
);
6228 macro_build (&offset_expr
, "lui", "t,u", PIC_CALL_REG
,
6229 BFD_RELOC_MIPS_CALL_HI16
);
6230 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t", PIC_CALL_REG
,
6231 PIC_CALL_REG
, mips_gp_register
);
6232 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)",
6233 PIC_CALL_REG
, BFD_RELOC_MIPS_CALL_LO16
,
6236 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)",
6237 PIC_CALL_REG
, BFD_RELOC_MIPS_GOT_PAGE
,
6239 macro_build (&offset_expr
, ADDRESS_ADDI_INSN
, "t,r,j",
6240 PIC_CALL_REG
, PIC_CALL_REG
,
6241 BFD_RELOC_MIPS_GOT_OFST
);
6245 macro_build_jalr (&offset_expr
);
6249 relax_start (offset_expr
.X_add_symbol
);
6252 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)",
6253 PIC_CALL_REG
, BFD_RELOC_MIPS_CALL16
,
6262 gpdelay
= reg_needs_delay (mips_gp_register
);
6263 macro_build (&offset_expr
, "lui", "t,u", PIC_CALL_REG
,
6264 BFD_RELOC_MIPS_CALL_HI16
);
6265 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t", PIC_CALL_REG
,
6266 PIC_CALL_REG
, mips_gp_register
);
6267 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)",
6268 PIC_CALL_REG
, BFD_RELOC_MIPS_CALL_LO16
,
6273 macro_build (NULL
, "nop", "");
6275 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)",
6276 PIC_CALL_REG
, BFD_RELOC_MIPS_GOT16
,
6279 macro_build (&offset_expr
, ADDRESS_ADDI_INSN
, "t,r,j",
6280 PIC_CALL_REG
, PIC_CALL_REG
, BFD_RELOC_LO16
);
6282 macro_build_jalr (&offset_expr
);
6284 if (mips_cprestore_offset
< 0)
6285 as_warn (_("No .cprestore pseudo-op used in PIC code"));
6288 if (! mips_frame_reg_valid
)
6290 as_warn (_("No .frame pseudo-op used in PIC code"));
6291 /* Quiet this warning. */
6292 mips_frame_reg_valid
= 1;
6294 if (! mips_cprestore_valid
)
6296 as_warn (_("No .cprestore pseudo-op used in PIC code"));
6297 /* Quiet this warning. */
6298 mips_cprestore_valid
= 1;
6300 if (mips_opts
.noreorder
)
6301 macro_build (NULL
, "nop", "");
6302 expr1
.X_add_number
= mips_cprestore_offset
;
6303 macro_build_ldst_constoffset (&expr1
, ADDRESS_LOAD_INSN
,
6306 HAVE_64BIT_ADDRESSES
);
6310 else if (mips_pic
== VXWORKS_PIC
)
6311 as_bad (_("Non-PIC jump used in PIC library"));
6334 /* Itbl support may require additional care here. */
6339 /* Itbl support may require additional care here. */
6344 /* Itbl support may require additional care here. */
6349 /* Itbl support may require additional care here. */
6362 /* Itbl support may require additional care here. */
6367 /* Itbl support may require additional care here. */
6372 /* Itbl support may require additional care here. */
6392 if (breg
== treg
|| coproc
|| lr
)
6413 /* Itbl support may require additional care here. */
6418 /* Itbl support may require additional care here. */
6423 /* Itbl support may require additional care here. */
6428 /* Itbl support may require additional care here. */
6449 /* Itbl support may require additional care here. */
6453 /* Itbl support may require additional care here. */
6458 /* Itbl support may require additional care here. */
6471 && NO_ISA_COP (mips_opts
.arch
)
6472 && (ip
->insn_mo
->pinfo2
& (INSN2_M_FP_S
| INSN2_M_FP_D
)) == 0)
6474 as_bad (_("opcode not supported on this processor: %s"),
6475 mips_cpu_info_from_arch (mips_opts
.arch
)->name
);
6479 /* Itbl support may require additional care here. */
6480 if (mask
== M_LWC1_AB
6481 || mask
== M_SWC1_AB
6482 || mask
== M_LDC1_AB
6483 || mask
== M_SDC1_AB
6487 else if (mask
== M_CACHE_AB
)
6494 if (offset_expr
.X_op
!= O_constant
6495 && offset_expr
.X_op
!= O_symbol
)
6497 as_bad (_("expression too complex"));
6498 offset_expr
.X_op
= O_constant
;
6501 if (HAVE_32BIT_ADDRESSES
6502 && !IS_SEXT_32BIT_NUM (offset_expr
.X_add_number
))
6506 sprintf_vma (value
, offset_expr
.X_add_number
);
6507 as_bad (_("Number (0x%s) larger than 32 bits"), value
);
6510 /* A constant expression in PIC code can be handled just as it
6511 is in non PIC code. */
6512 if (offset_expr
.X_op
== O_constant
)
6514 expr1
.X_add_number
= ((offset_expr
.X_add_number
+ 0x8000)
6515 & ~(bfd_vma
) 0xffff);
6516 normalize_address_expr (&expr1
);
6517 load_register (tempreg
, &expr1
, HAVE_64BIT_ADDRESSES
);
6519 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t",
6520 tempreg
, tempreg
, breg
);
6521 macro_build (&offset_expr
, s
, fmt
, treg
, BFD_RELOC_LO16
, tempreg
);
6523 else if (mips_pic
== NO_PIC
)
6525 /* If this is a reference to a GP relative symbol, and there
6526 is no base register, we want
6527 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
6528 Otherwise, if there is no base register, we want
6529 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
6530 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
6531 If we have a constant, we need two instructions anyhow,
6532 so we always use the latter form.
6534 If we have a base register, and this is a reference to a
6535 GP relative symbol, we want
6536 addu $tempreg,$breg,$gp
6537 <op> $treg,<sym>($tempreg) (BFD_RELOC_GPREL16)
6539 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
6540 addu $tempreg,$tempreg,$breg
6541 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
6542 With a constant we always use the latter case.
6544 With 64bit address space and no base register and $at usable,
6546 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
6547 lui $at,<sym> (BFD_RELOC_HI16_S)
6548 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
6551 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
6552 If we have a base register, we want
6553 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
6554 lui $at,<sym> (BFD_RELOC_HI16_S)
6555 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
6559 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
6561 Without $at we can't generate the optimal path for superscalar
6562 processors here since this would require two temporary registers.
6563 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
6564 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
6566 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
6568 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
6569 If we have a base register, we want
6570 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
6571 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
6573 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
6575 daddu $tempreg,$tempreg,$breg
6576 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
6578 For GP relative symbols in 64bit address space we can use
6579 the same sequence as in 32bit address space. */
6580 if (HAVE_64BIT_SYMBOLS
)
6582 if ((valueT
) offset_expr
.X_add_number
<= MAX_GPREL_OFFSET
6583 && !nopic_need_relax (offset_expr
.X_add_symbol
, 1))
6585 relax_start (offset_expr
.X_add_symbol
);
6588 macro_build (&offset_expr
, s
, fmt
, treg
,
6589 BFD_RELOC_GPREL16
, mips_gp_register
);
6593 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t",
6594 tempreg
, breg
, mips_gp_register
);
6595 macro_build (&offset_expr
, s
, fmt
, treg
,
6596 BFD_RELOC_GPREL16
, tempreg
);
6601 if (used_at
== 0 && mips_opts
.at
)
6603 macro_build (&offset_expr
, "lui", "t,u", tempreg
,
6604 BFD_RELOC_MIPS_HIGHEST
);
6605 macro_build (&offset_expr
, "lui", "t,u", AT
,
6607 macro_build (&offset_expr
, "daddiu", "t,r,j", tempreg
,
6608 tempreg
, BFD_RELOC_MIPS_HIGHER
);
6610 macro_build (NULL
, "daddu", "d,v,t", AT
, AT
, breg
);
6611 macro_build (NULL
, "dsll32", "d,w,<", tempreg
, tempreg
, 0);
6612 macro_build (NULL
, "daddu", "d,v,t", tempreg
, tempreg
, AT
);
6613 macro_build (&offset_expr
, s
, fmt
, treg
, BFD_RELOC_LO16
,
6619 macro_build (&offset_expr
, "lui", "t,u", tempreg
,
6620 BFD_RELOC_MIPS_HIGHEST
);
6621 macro_build (&offset_expr
, "daddiu", "t,r,j", tempreg
,
6622 tempreg
, BFD_RELOC_MIPS_HIGHER
);
6623 macro_build (NULL
, "dsll", "d,w,<", tempreg
, tempreg
, 16);
6624 macro_build (&offset_expr
, "daddiu", "t,r,j", tempreg
,
6625 tempreg
, BFD_RELOC_HI16_S
);
6626 macro_build (NULL
, "dsll", "d,w,<", tempreg
, tempreg
, 16);
6628 macro_build (NULL
, "daddu", "d,v,t",
6629 tempreg
, tempreg
, breg
);
6630 macro_build (&offset_expr
, s
, fmt
, treg
,
6631 BFD_RELOC_LO16
, tempreg
);
6634 if (mips_relax
.sequence
)
6641 if ((valueT
) offset_expr
.X_add_number
<= MAX_GPREL_OFFSET
6642 && !nopic_need_relax (offset_expr
.X_add_symbol
, 1))
6644 relax_start (offset_expr
.X_add_symbol
);
6645 macro_build (&offset_expr
, s
, fmt
, treg
, BFD_RELOC_GPREL16
,
6649 macro_build_lui (&offset_expr
, tempreg
);
6650 macro_build (&offset_expr
, s
, fmt
, treg
,
6651 BFD_RELOC_LO16
, tempreg
);
6652 if (mips_relax
.sequence
)
6657 if ((valueT
) offset_expr
.X_add_number
<= MAX_GPREL_OFFSET
6658 && !nopic_need_relax (offset_expr
.X_add_symbol
, 1))
6660 relax_start (offset_expr
.X_add_symbol
);
6661 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t",
6662 tempreg
, breg
, mips_gp_register
);
6663 macro_build (&offset_expr
, s
, fmt
, treg
,
6664 BFD_RELOC_GPREL16
, tempreg
);
6667 macro_build_lui (&offset_expr
, tempreg
);
6668 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t",
6669 tempreg
, tempreg
, breg
);
6670 macro_build (&offset_expr
, s
, fmt
, treg
,
6671 BFD_RELOC_LO16
, tempreg
);
6672 if (mips_relax
.sequence
)
6676 else if (!mips_big_got
)
6678 int lw_reloc_type
= (int) BFD_RELOC_MIPS_GOT16
;
6680 /* If this is a reference to an external symbol, we want
6681 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6683 <op> $treg,0($tempreg)
6685 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6687 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
6688 <op> $treg,0($tempreg)
6691 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
6692 <op> $treg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_OFST)
6694 If there is a base register, we add it to $tempreg before
6695 the <op>. If there is a constant, we stick it in the
6696 <op> instruction. We don't handle constants larger than
6697 16 bits, because we have no way to load the upper 16 bits
6698 (actually, we could handle them for the subset of cases
6699 in which we are not using $at). */
6700 gas_assert (offset_expr
.X_op
== O_symbol
);
6703 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)", tempreg
,
6704 BFD_RELOC_MIPS_GOT_PAGE
, mips_gp_register
);
6706 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t",
6707 tempreg
, tempreg
, breg
);
6708 macro_build (&offset_expr
, s
, fmt
, treg
,
6709 BFD_RELOC_MIPS_GOT_OFST
, tempreg
);
6712 expr1
.X_add_number
= offset_expr
.X_add_number
;
6713 offset_expr
.X_add_number
= 0;
6714 if (expr1
.X_add_number
< -0x8000
6715 || expr1
.X_add_number
>= 0x8000)
6716 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6717 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)", tempreg
,
6718 lw_reloc_type
, mips_gp_register
);
6720 relax_start (offset_expr
.X_add_symbol
);
6722 macro_build (&offset_expr
, ADDRESS_ADDI_INSN
, "t,r,j", tempreg
,
6723 tempreg
, BFD_RELOC_LO16
);
6726 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t",
6727 tempreg
, tempreg
, breg
);
6728 macro_build (&expr1
, s
, fmt
, treg
, BFD_RELOC_LO16
, tempreg
);
6730 else if (mips_big_got
&& !HAVE_NEWABI
)
6734 /* If this is a reference to an external symbol, we want
6735 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
6736 addu $tempreg,$tempreg,$gp
6737 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
6738 <op> $treg,0($tempreg)
6740 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6742 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
6743 <op> $treg,0($tempreg)
6744 If there is a base register, we add it to $tempreg before
6745 the <op>. If there is a constant, we stick it in the
6746 <op> instruction. We don't handle constants larger than
6747 16 bits, because we have no way to load the upper 16 bits
6748 (actually, we could handle them for the subset of cases
6749 in which we are not using $at). */
6750 gas_assert (offset_expr
.X_op
== O_symbol
);
6751 expr1
.X_add_number
= offset_expr
.X_add_number
;
6752 offset_expr
.X_add_number
= 0;
6753 if (expr1
.X_add_number
< -0x8000
6754 || expr1
.X_add_number
>= 0x8000)
6755 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6756 gpdelay
= reg_needs_delay (mips_gp_register
);
6757 relax_start (offset_expr
.X_add_symbol
);
6758 macro_build (&offset_expr
, "lui", "t,u", tempreg
,
6759 BFD_RELOC_MIPS_GOT_HI16
);
6760 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t", tempreg
, tempreg
,
6762 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)", tempreg
,
6763 BFD_RELOC_MIPS_GOT_LO16
, tempreg
);
6766 macro_build (NULL
, "nop", "");
6767 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)", tempreg
,
6768 BFD_RELOC_MIPS_GOT16
, mips_gp_register
);
6770 macro_build (&offset_expr
, ADDRESS_ADDI_INSN
, "t,r,j", tempreg
,
6771 tempreg
, BFD_RELOC_LO16
);
6775 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t",
6776 tempreg
, tempreg
, breg
);
6777 macro_build (&expr1
, s
, fmt
, treg
, BFD_RELOC_LO16
, tempreg
);
6779 else if (mips_big_got
&& HAVE_NEWABI
)
6781 /* If this is a reference to an external symbol, we want
6782 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
6783 add $tempreg,$tempreg,$gp
6784 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
6785 <op> $treg,<ofst>($tempreg)
6786 Otherwise, for local symbols, we want:
6787 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
6788 <op> $treg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_OFST) */
6789 gas_assert (offset_expr
.X_op
== O_symbol
);
6790 expr1
.X_add_number
= offset_expr
.X_add_number
;
6791 offset_expr
.X_add_number
= 0;
6792 if (expr1
.X_add_number
< -0x8000
6793 || expr1
.X_add_number
>= 0x8000)
6794 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6795 relax_start (offset_expr
.X_add_symbol
);
6796 macro_build (&offset_expr
, "lui", "t,u", tempreg
,
6797 BFD_RELOC_MIPS_GOT_HI16
);
6798 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t", tempreg
, tempreg
,
6800 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)", tempreg
,
6801 BFD_RELOC_MIPS_GOT_LO16
, tempreg
);
6803 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t",
6804 tempreg
, tempreg
, breg
);
6805 macro_build (&expr1
, s
, fmt
, treg
, BFD_RELOC_LO16
, tempreg
);
6808 offset_expr
.X_add_number
= expr1
.X_add_number
;
6809 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)", tempreg
,
6810 BFD_RELOC_MIPS_GOT_PAGE
, mips_gp_register
);
6812 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t",
6813 tempreg
, tempreg
, breg
);
6814 macro_build (&offset_expr
, s
, fmt
, treg
,
6815 BFD_RELOC_MIPS_GOT_OFST
, tempreg
);
6825 load_register (treg
, &imm_expr
, 0);
6829 load_register (treg
, &imm_expr
, 1);
6833 if (imm_expr
.X_op
== O_constant
)
6836 load_register (AT
, &imm_expr
, 0);
6837 macro_build (NULL
, "mtc1", "t,G", AT
, treg
);
6842 gas_assert (offset_expr
.X_op
== O_symbol
6843 && strcmp (segment_name (S_GET_SEGMENT
6844 (offset_expr
.X_add_symbol
)),
6846 && offset_expr
.X_add_number
== 0);
6847 macro_build (&offset_expr
, "lwc1", "T,o(b)", treg
,
6848 BFD_RELOC_MIPS_LITERAL
, mips_gp_register
);
6853 /* Check if we have a constant in IMM_EXPR. If the GPRs are 64 bits
6854 wide, IMM_EXPR is the entire value. Otherwise IMM_EXPR is the high
6855 order 32 bits of the value and the low order 32 bits are either
6856 zero or in OFFSET_EXPR. */
6857 if (imm_expr
.X_op
== O_constant
|| imm_expr
.X_op
== O_big
)
6859 if (HAVE_64BIT_GPRS
)
6860 load_register (treg
, &imm_expr
, 1);
6865 if (target_big_endian
)
6877 load_register (hreg
, &imm_expr
, 0);
6880 if (offset_expr
.X_op
== O_absent
)
6881 move_register (lreg
, 0);
6884 gas_assert (offset_expr
.X_op
== O_constant
);
6885 load_register (lreg
, &offset_expr
, 0);
6892 /* We know that sym is in the .rdata section. First we get the
6893 upper 16 bits of the address. */
6894 if (mips_pic
== NO_PIC
)
6896 macro_build_lui (&offset_expr
, AT
);
6901 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)", AT
,
6902 BFD_RELOC_MIPS_GOT16
, mips_gp_register
);
6906 /* Now we load the register(s). */
6907 if (HAVE_64BIT_GPRS
)
6910 macro_build (&offset_expr
, "ld", "t,o(b)", treg
, BFD_RELOC_LO16
, AT
);
6915 macro_build (&offset_expr
, "lw", "t,o(b)", treg
, BFD_RELOC_LO16
, AT
);
6918 /* FIXME: How in the world do we deal with the possible
6920 offset_expr
.X_add_number
+= 4;
6921 macro_build (&offset_expr
, "lw", "t,o(b)",
6922 treg
+ 1, BFD_RELOC_LO16
, AT
);
6928 /* Check if we have a constant in IMM_EXPR. If the FPRs are 64 bits
6929 wide, IMM_EXPR is the entire value and the GPRs are known to be 64
6930 bits wide as well. Otherwise IMM_EXPR is the high order 32 bits of
6931 the value and the low order 32 bits are either zero or in
6933 if (imm_expr
.X_op
== O_constant
|| imm_expr
.X_op
== O_big
)
6936 load_register (AT
, &imm_expr
, HAVE_64BIT_FPRS
);
6937 if (HAVE_64BIT_FPRS
)
6939 gas_assert (HAVE_64BIT_GPRS
);
6940 macro_build (NULL
, "dmtc1", "t,S", AT
, treg
);
6944 macro_build (NULL
, "mtc1", "t,G", AT
, treg
+ 1);
6945 if (offset_expr
.X_op
== O_absent
)
6946 macro_build (NULL
, "mtc1", "t,G", 0, treg
);
6949 gas_assert (offset_expr
.X_op
== O_constant
);
6950 load_register (AT
, &offset_expr
, 0);
6951 macro_build (NULL
, "mtc1", "t,G", AT
, treg
);
6957 gas_assert (offset_expr
.X_op
== O_symbol
6958 && offset_expr
.X_add_number
== 0);
6959 s
= segment_name (S_GET_SEGMENT (offset_expr
.X_add_symbol
));
6960 if (strcmp (s
, ".lit8") == 0)
6962 if (mips_opts
.isa
!= ISA_MIPS1
)
6964 macro_build (&offset_expr
, "ldc1", "T,o(b)", treg
,
6965 BFD_RELOC_MIPS_LITERAL
, mips_gp_register
);
6968 breg
= mips_gp_register
;
6969 r
= BFD_RELOC_MIPS_LITERAL
;
6974 gas_assert (strcmp (s
, RDATA_SECTION_NAME
) == 0);
6976 if (mips_pic
!= NO_PIC
)
6977 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)", AT
,
6978 BFD_RELOC_MIPS_GOT16
, mips_gp_register
);
6981 /* FIXME: This won't work for a 64 bit address. */
6982 macro_build_lui (&offset_expr
, AT
);
6985 if (mips_opts
.isa
!= ISA_MIPS1
)
6987 macro_build (&offset_expr
, "ldc1", "T,o(b)",
6988 treg
, BFD_RELOC_LO16
, AT
);
6997 /* Even on a big endian machine $fn comes before $fn+1. We have
6998 to adjust when loading from memory. */
7001 gas_assert (mips_opts
.isa
== ISA_MIPS1
);
7002 macro_build (&offset_expr
, "lwc1", "T,o(b)",
7003 target_big_endian
? treg
+ 1 : treg
, r
, breg
);
7004 /* FIXME: A possible overflow which I don't know how to deal
7006 offset_expr
.X_add_number
+= 4;
7007 macro_build (&offset_expr
, "lwc1", "T,o(b)",
7008 target_big_endian
? treg
: treg
+ 1, r
, breg
);
7013 * The MIPS assembler seems to check for X_add_number not
7014 * being double aligned and generating:
7017 * addiu at,at,%lo(foo+1)
7020 * But, the resulting address is the same after relocation so why
7021 * generate the extra instruction?
7023 /* Itbl support may require additional care here. */
7025 if (mips_opts
.isa
!= ISA_MIPS1
)
7036 if (mips_opts
.isa
!= ISA_MIPS1
)
7044 /* Itbl support may require additional care here. */
7049 if (HAVE_64BIT_GPRS
)
7060 if (HAVE_64BIT_GPRS
)
7070 if (offset_expr
.X_op
!= O_symbol
7071 && offset_expr
.X_op
!= O_constant
)
7073 as_bad (_("expression too complex"));
7074 offset_expr
.X_op
= O_constant
;
7077 if (HAVE_32BIT_ADDRESSES
7078 && !IS_SEXT_32BIT_NUM (offset_expr
.X_add_number
))
7082 sprintf_vma (value
, offset_expr
.X_add_number
);
7083 as_bad (_("Number (0x%s) larger than 32 bits"), value
);
7086 /* Even on a big endian machine $fn comes before $fn+1. We have
7087 to adjust when loading from memory. We set coproc if we must
7088 load $fn+1 first. */
7089 /* Itbl support may require additional care here. */
7090 if (! target_big_endian
)
7093 if (mips_pic
== NO_PIC
7094 || offset_expr
.X_op
== O_constant
)
7096 /* If this is a reference to a GP relative symbol, we want
7097 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
7098 <op> $treg+1,<sym>+4($gp) (BFD_RELOC_GPREL16)
7099 If we have a base register, we use this
7101 <op> $treg,<sym>($at) (BFD_RELOC_GPREL16)
7102 <op> $treg+1,<sym>+4($at) (BFD_RELOC_GPREL16)
7103 If this is not a GP relative symbol, we want
7104 lui $at,<sym> (BFD_RELOC_HI16_S)
7105 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
7106 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
7107 If there is a base register, we add it to $at after the
7108 lui instruction. If there is a constant, we always use
7110 if (offset_expr
.X_op
== O_symbol
7111 && (valueT
) offset_expr
.X_add_number
<= MAX_GPREL_OFFSET
7112 && !nopic_need_relax (offset_expr
.X_add_symbol
, 1))
7114 relax_start (offset_expr
.X_add_symbol
);
7117 tempreg
= mips_gp_register
;
7121 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t",
7122 AT
, breg
, mips_gp_register
);
7127 /* Itbl support may require additional care here. */
7128 macro_build (&offset_expr
, s
, fmt
, coproc
? treg
+ 1 : treg
,
7129 BFD_RELOC_GPREL16
, tempreg
);
7130 offset_expr
.X_add_number
+= 4;
7132 /* Set mips_optimize to 2 to avoid inserting an
7134 hold_mips_optimize
= mips_optimize
;
7136 /* Itbl support may require additional care here. */
7137 macro_build (&offset_expr
, s
, fmt
, coproc
? treg
: treg
+ 1,
7138 BFD_RELOC_GPREL16
, tempreg
);
7139 mips_optimize
= hold_mips_optimize
;
7143 /* We just generated two relocs. When tc_gen_reloc
7144 handles this case, it will skip the first reloc and
7145 handle the second. The second reloc already has an
7146 extra addend of 4, which we added above. We must
7147 subtract it out, and then subtract another 4 to make
7148 the first reloc come out right. The second reloc
7149 will come out right because we are going to add 4 to
7150 offset_expr when we build its instruction below.
7152 If we have a symbol, then we don't want to include
7153 the offset, because it will wind up being included
7154 when we generate the reloc. */
7156 if (offset_expr
.X_op
== O_constant
)
7157 offset_expr
.X_add_number
-= 8;
7160 offset_expr
.X_add_number
= -4;
7161 offset_expr
.X_op
= O_constant
;
7165 macro_build_lui (&offset_expr
, AT
);
7167 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t", AT
, breg
, AT
);
7168 /* Itbl support may require additional care here. */
7169 macro_build (&offset_expr
, s
, fmt
, coproc
? treg
+ 1 : treg
,
7170 BFD_RELOC_LO16
, AT
);
7171 /* FIXME: How do we handle overflow here? */
7172 offset_expr
.X_add_number
+= 4;
7173 /* Itbl support may require additional care here. */
7174 macro_build (&offset_expr
, s
, fmt
, coproc
? treg
: treg
+ 1,
7175 BFD_RELOC_LO16
, AT
);
7176 if (mips_relax
.sequence
)
7179 else if (!mips_big_got
)
7181 /* If this is a reference to an external symbol, we want
7182 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
7187 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
7189 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
7190 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
7191 If there is a base register we add it to $at before the
7192 lwc1 instructions. If there is a constant we include it
7193 in the lwc1 instructions. */
7195 expr1
.X_add_number
= offset_expr
.X_add_number
;
7196 if (expr1
.X_add_number
< -0x8000
7197 || expr1
.X_add_number
>= 0x8000 - 4)
7198 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
7199 load_got_offset (AT
, &offset_expr
);
7202 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t", AT
, breg
, AT
);
7204 /* Set mips_optimize to 2 to avoid inserting an undesired
7206 hold_mips_optimize
= mips_optimize
;
7209 /* Itbl support may require additional care here. */
7210 relax_start (offset_expr
.X_add_symbol
);
7211 macro_build (&expr1
, s
, fmt
, coproc
? treg
+ 1 : treg
,
7212 BFD_RELOC_LO16
, AT
);
7213 expr1
.X_add_number
+= 4;
7214 macro_build (&expr1
, s
, fmt
, coproc
? treg
: treg
+ 1,
7215 BFD_RELOC_LO16
, AT
);
7217 macro_build (&offset_expr
, s
, fmt
, coproc
? treg
+ 1 : treg
,
7218 BFD_RELOC_LO16
, AT
);
7219 offset_expr
.X_add_number
+= 4;
7220 macro_build (&offset_expr
, s
, fmt
, coproc
? treg
: treg
+ 1,
7221 BFD_RELOC_LO16
, AT
);
7224 mips_optimize
= hold_mips_optimize
;
7226 else if (mips_big_got
)
7230 /* If this is a reference to an external symbol, we want
7231 lui $at,<sym> (BFD_RELOC_MIPS_GOT_HI16)
7233 lw $at,<sym>($at) (BFD_RELOC_MIPS_GOT_LO16)
7238 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
7240 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
7241 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
7242 If there is a base register we add it to $at before the
7243 lwc1 instructions. If there is a constant we include it
7244 in the lwc1 instructions. */
7246 expr1
.X_add_number
= offset_expr
.X_add_number
;
7247 offset_expr
.X_add_number
= 0;
7248 if (expr1
.X_add_number
< -0x8000
7249 || expr1
.X_add_number
>= 0x8000 - 4)
7250 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
7251 gpdelay
= reg_needs_delay (mips_gp_register
);
7252 relax_start (offset_expr
.X_add_symbol
);
7253 macro_build (&offset_expr
, "lui", "t,u",
7254 AT
, BFD_RELOC_MIPS_GOT_HI16
);
7255 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t",
7256 AT
, AT
, mips_gp_register
);
7257 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)",
7258 AT
, BFD_RELOC_MIPS_GOT_LO16
, AT
);
7261 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t", AT
, breg
, AT
);
7262 /* Itbl support may require additional care here. */
7263 macro_build (&expr1
, s
, fmt
, coproc
? treg
+ 1 : treg
,
7264 BFD_RELOC_LO16
, AT
);
7265 expr1
.X_add_number
+= 4;
7267 /* Set mips_optimize to 2 to avoid inserting an undesired
7269 hold_mips_optimize
= mips_optimize
;
7271 /* Itbl support may require additional care here. */
7272 macro_build (&expr1
, s
, fmt
, coproc
? treg
: treg
+ 1,
7273 BFD_RELOC_LO16
, AT
);
7274 mips_optimize
= hold_mips_optimize
;
7275 expr1
.X_add_number
-= 4;
7278 offset_expr
.X_add_number
= expr1
.X_add_number
;
7280 macro_build (NULL
, "nop", "");
7281 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)", AT
,
7282 BFD_RELOC_MIPS_GOT16
, mips_gp_register
);
7285 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t", AT
, breg
, AT
);
7286 /* Itbl support may require additional care here. */
7287 macro_build (&offset_expr
, s
, fmt
, coproc
? treg
+ 1 : treg
,
7288 BFD_RELOC_LO16
, AT
);
7289 offset_expr
.X_add_number
+= 4;
7291 /* Set mips_optimize to 2 to avoid inserting an undesired
7293 hold_mips_optimize
= mips_optimize
;
7295 /* Itbl support may require additional care here. */
7296 macro_build (&offset_expr
, s
, fmt
, coproc
? treg
: treg
+ 1,
7297 BFD_RELOC_LO16
, AT
);
7298 mips_optimize
= hold_mips_optimize
;
7312 gas_assert (HAVE_32BIT_ADDRESSES
);
7313 macro_build (&offset_expr
, s
, "t,o(b)", treg
, BFD_RELOC_LO16
, breg
);
7314 offset_expr
.X_add_number
+= 4;
7315 macro_build (&offset_expr
, s
, "t,o(b)", treg
+ 1, BFD_RELOC_LO16
, breg
);
7318 /* New code added to support COPZ instructions.
7319 This code builds table entries out of the macros in mip_opcodes.
7320 R4000 uses interlocks to handle coproc delays.
7321 Other chips (like the R3000) require nops to be inserted for delays.
7323 FIXME: Currently, we require that the user handle delays.
7324 In order to fill delay slots for non-interlocked chips,
7325 we must have a way to specify delays based on the coprocessor.
7326 Eg. 4 cycles if load coproc reg from memory, 1 if in cache, etc.
7327 What are the side-effects of the cop instruction?
7328 What cache support might we have and what are its effects?
7329 Both coprocessor & memory require delays. how long???
7330 What registers are read/set/modified?
7332 If an itbl is provided to interpret cop instructions,
7333 this knowledge can be encoded in the itbl spec. */
7347 if (NO_ISA_COP (mips_opts
.arch
)
7348 && (ip
->insn_mo
->pinfo2
& INSN2_M_FP_S
) == 0)
7350 as_bad (_("opcode not supported on this processor: %s"),
7351 mips_cpu_info_from_arch (mips_opts
.arch
)->name
);
7355 /* For now we just do C (same as Cz). The parameter will be
7356 stored in insn_opcode by mips_ip. */
7357 macro_build (NULL
, s
, "C", ip
->insn_opcode
);
7361 move_register (dreg
, sreg
);
7364 #ifdef LOSING_COMPILER
7366 /* Try and see if this is a new itbl instruction.
7367 This code builds table entries out of the macros in mip_opcodes.
7368 FIXME: For now we just assemble the expression and pass it's
7369 value along as a 32-bit immediate.
7370 We may want to have the assembler assemble this value,
7371 so that we gain the assembler's knowledge of delay slots,
7373 Would it be more efficient to use mask (id) here? */
7374 if (itbl_have_entries
7375 && (immed_expr
= itbl_assemble (ip
->insn_mo
->name
, "")))
7377 s
= ip
->insn_mo
->name
;
7379 coproc
= ITBL_DECODE_PNUM (immed_expr
);;
7380 macro_build (&immed_expr
, s
, "C");
7386 if (!mips_opts
.at
&& used_at
)
7387 as_bad (_("Macro used $at after \".set noat\""));
7391 macro2 (struct mips_cl_insn
*ip
)
7393 unsigned int treg
, sreg
, dreg
, breg
;
7394 unsigned int tempreg
;
7408 bfd_reloc_code_real_type r
;
7410 treg
= (ip
->insn_opcode
>> 16) & 0x1f;
7411 dreg
= (ip
->insn_opcode
>> 11) & 0x1f;
7412 sreg
= breg
= (ip
->insn_opcode
>> 21) & 0x1f;
7413 mask
= ip
->insn_mo
->mask
;
7415 expr1
.X_op
= O_constant
;
7416 expr1
.X_op_symbol
= NULL
;
7417 expr1
.X_add_symbol
= NULL
;
7418 expr1
.X_add_number
= 1;
7422 #endif /* LOSING_COMPILER */
7427 macro_build (NULL
, dbl
? "dmultu" : "multu", "s,t", sreg
, treg
);
7428 macro_build (NULL
, "mflo", "d", dreg
);
7434 /* The MIPS assembler some times generates shifts and adds. I'm
7435 not trying to be that fancy. GCC should do this for us
7438 load_register (AT
, &imm_expr
, dbl
);
7439 macro_build (NULL
, dbl
? "dmult" : "mult", "s,t", sreg
, AT
);
7440 macro_build (NULL
, "mflo", "d", dreg
);
7456 load_register (AT
, &imm_expr
, dbl
);
7457 macro_build (NULL
, dbl
? "dmult" : "mult", "s,t", sreg
, imm
? AT
: treg
);
7458 macro_build (NULL
, "mflo", "d", dreg
);
7459 macro_build (NULL
, dbl
? "dsra32" : "sra", "d,w,<", dreg
, dreg
, RA
);
7460 macro_build (NULL
, "mfhi", "d", AT
);
7462 macro_build (NULL
, "tne", "s,t,q", dreg
, AT
, 6);
7465 expr1
.X_add_number
= 8;
7466 macro_build (&expr1
, "beq", "s,t,p", dreg
, AT
);
7467 macro_build (NULL
, "nop", "", 0);
7468 macro_build (NULL
, "break", "c", 6);
7471 macro_build (NULL
, "mflo", "d", dreg
);
7487 load_register (AT
, &imm_expr
, dbl
);
7488 macro_build (NULL
, dbl
? "dmultu" : "multu", "s,t",
7489 sreg
, imm
? AT
: treg
);
7490 macro_build (NULL
, "mfhi", "d", AT
);
7491 macro_build (NULL
, "mflo", "d", dreg
);
7493 macro_build (NULL
, "tne", "s,t,q", AT
, 0, 6);
7496 expr1
.X_add_number
= 8;
7497 macro_build (&expr1
, "beq", "s,t,p", AT
, 0);
7498 macro_build (NULL
, "nop", "", 0);
7499 macro_build (NULL
, "break", "c", 6);
7505 if (ISA_HAS_DROR (mips_opts
.isa
) || CPU_HAS_DROR (mips_opts
.arch
))
7516 macro_build (NULL
, "dnegu", "d,w", tempreg
, treg
);
7517 macro_build (NULL
, "drorv", "d,t,s", dreg
, sreg
, tempreg
);
7521 macro_build (NULL
, "dsubu", "d,v,t", AT
, 0, treg
);
7522 macro_build (NULL
, "dsrlv", "d,t,s", AT
, sreg
, AT
);
7523 macro_build (NULL
, "dsllv", "d,t,s", dreg
, sreg
, treg
);
7524 macro_build (NULL
, "or", "d,v,t", dreg
, dreg
, AT
);
7528 if (ISA_HAS_ROR (mips_opts
.isa
) || CPU_HAS_ROR (mips_opts
.arch
))
7539 macro_build (NULL
, "negu", "d,w", tempreg
, treg
);
7540 macro_build (NULL
, "rorv", "d,t,s", dreg
, sreg
, tempreg
);
7544 macro_build (NULL
, "subu", "d,v,t", AT
, 0, treg
);
7545 macro_build (NULL
, "srlv", "d,t,s", AT
, sreg
, AT
);
7546 macro_build (NULL
, "sllv", "d,t,s", dreg
, sreg
, treg
);
7547 macro_build (NULL
, "or", "d,v,t", dreg
, dreg
, AT
);
7555 if (imm_expr
.X_op
!= O_constant
)
7556 as_bad (_("Improper rotate count"));
7557 rot
= imm_expr
.X_add_number
& 0x3f;
7558 if (ISA_HAS_DROR (mips_opts
.isa
) || CPU_HAS_DROR (mips_opts
.arch
))
7560 rot
= (64 - rot
) & 0x3f;
7562 macro_build (NULL
, "dror32", "d,w,<", dreg
, sreg
, rot
- 32);
7564 macro_build (NULL
, "dror", "d,w,<", dreg
, sreg
, rot
);
7569 macro_build (NULL
, "dsrl", "d,w,<", dreg
, sreg
, 0);
7572 l
= (rot
< 0x20) ? "dsll" : "dsll32";
7573 r
= ((0x40 - rot
) < 0x20) ? "dsrl" : "dsrl32";
7576 macro_build (NULL
, l
, "d,w,<", AT
, sreg
, rot
);
7577 macro_build (NULL
, r
, "d,w,<", dreg
, sreg
, (0x20 - rot
) & 0x1f);
7578 macro_build (NULL
, "or", "d,v,t", dreg
, dreg
, AT
);
7586 if (imm_expr
.X_op
!= O_constant
)
7587 as_bad (_("Improper rotate count"));
7588 rot
= imm_expr
.X_add_number
& 0x1f;
7589 if (ISA_HAS_ROR (mips_opts
.isa
) || CPU_HAS_ROR (mips_opts
.arch
))
7591 macro_build (NULL
, "ror", "d,w,<", dreg
, sreg
, (32 - rot
) & 0x1f);
7596 macro_build (NULL
, "srl", "d,w,<", dreg
, sreg
, 0);
7600 macro_build (NULL
, "sll", "d,w,<", AT
, sreg
, rot
);
7601 macro_build (NULL
, "srl", "d,w,<", dreg
, sreg
, (0x20 - rot
) & 0x1f);
7602 macro_build (NULL
, "or", "d,v,t", dreg
, dreg
, AT
);
7607 if (ISA_HAS_DROR (mips_opts
.isa
) || CPU_HAS_DROR (mips_opts
.arch
))
7609 macro_build (NULL
, "drorv", "d,t,s", dreg
, sreg
, treg
);
7613 macro_build (NULL
, "dsubu", "d,v,t", AT
, 0, treg
);
7614 macro_build (NULL
, "dsllv", "d,t,s", AT
, sreg
, AT
);
7615 macro_build (NULL
, "dsrlv", "d,t,s", dreg
, sreg
, treg
);
7616 macro_build (NULL
, "or", "d,v,t", dreg
, dreg
, AT
);
7620 if (ISA_HAS_ROR (mips_opts
.isa
) || CPU_HAS_ROR (mips_opts
.arch
))
7622 macro_build (NULL
, "rorv", "d,t,s", dreg
, sreg
, treg
);
7626 macro_build (NULL
, "subu", "d,v,t", AT
, 0, treg
);
7627 macro_build (NULL
, "sllv", "d,t,s", AT
, sreg
, AT
);
7628 macro_build (NULL
, "srlv", "d,t,s", dreg
, sreg
, treg
);
7629 macro_build (NULL
, "or", "d,v,t", dreg
, dreg
, AT
);
7637 if (imm_expr
.X_op
!= O_constant
)
7638 as_bad (_("Improper rotate count"));
7639 rot
= imm_expr
.X_add_number
& 0x3f;
7640 if (ISA_HAS_DROR (mips_opts
.isa
) || CPU_HAS_DROR (mips_opts
.arch
))
7643 macro_build (NULL
, "dror32", "d,w,<", dreg
, sreg
, rot
- 32);
7645 macro_build (NULL
, "dror", "d,w,<", dreg
, sreg
, rot
);
7650 macro_build (NULL
, "dsrl", "d,w,<", dreg
, sreg
, 0);
7653 r
= (rot
< 0x20) ? "dsrl" : "dsrl32";
7654 l
= ((0x40 - rot
) < 0x20) ? "dsll" : "dsll32";
7657 macro_build (NULL
, r
, "d,w,<", AT
, sreg
, rot
);
7658 macro_build (NULL
, l
, "d,w,<", dreg
, sreg
, (0x20 - rot
) & 0x1f);
7659 macro_build (NULL
, "or", "d,v,t", dreg
, dreg
, AT
);
7667 if (imm_expr
.X_op
!= O_constant
)
7668 as_bad (_("Improper rotate count"));
7669 rot
= imm_expr
.X_add_number
& 0x1f;
7670 if (ISA_HAS_ROR (mips_opts
.isa
) || CPU_HAS_ROR (mips_opts
.arch
))
7672 macro_build (NULL
, "ror", "d,w,<", dreg
, sreg
, rot
);
7677 macro_build (NULL
, "srl", "d,w,<", dreg
, sreg
, 0);
7681 macro_build (NULL
, "srl", "d,w,<", AT
, sreg
, rot
);
7682 macro_build (NULL
, "sll", "d,w,<", dreg
, sreg
, (0x20 - rot
) & 0x1f);
7683 macro_build (NULL
, "or", "d,v,t", dreg
, dreg
, AT
);
7688 gas_assert (mips_opts
.isa
== ISA_MIPS1
);
7689 /* Even on a big endian machine $fn comes before $fn+1. We have
7690 to adjust when storing to memory. */
7691 macro_build (&offset_expr
, "swc1", "T,o(b)",
7692 target_big_endian
? treg
+ 1 : treg
, BFD_RELOC_LO16
, breg
);
7693 offset_expr
.X_add_number
+= 4;
7694 macro_build (&offset_expr
, "swc1", "T,o(b)",
7695 target_big_endian
? treg
: treg
+ 1, BFD_RELOC_LO16
, breg
);
7700 macro_build (&expr1
, "sltiu", "t,r,j", dreg
, treg
, BFD_RELOC_LO16
);
7702 macro_build (&expr1
, "sltiu", "t,r,j", dreg
, sreg
, BFD_RELOC_LO16
);
7705 macro_build (NULL
, "xor", "d,v,t", dreg
, sreg
, treg
);
7706 macro_build (&expr1
, "sltiu", "t,r,j", dreg
, dreg
, BFD_RELOC_LO16
);
7711 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 0)
7713 macro_build (&expr1
, "sltiu", "t,r,j", dreg
, sreg
, BFD_RELOC_LO16
);
7718 as_warn (_("Instruction %s: result is always false"),
7720 move_register (dreg
, 0);
7723 if (CPU_HAS_SEQ (mips_opts
.arch
)
7724 && -512 <= imm_expr
.X_add_number
7725 && imm_expr
.X_add_number
< 512)
7727 macro_build (NULL
, "seqi", "t,r,+Q", dreg
, sreg
,
7728 (int) imm_expr
.X_add_number
);
7731 if (imm_expr
.X_op
== O_constant
7732 && imm_expr
.X_add_number
>= 0
7733 && imm_expr
.X_add_number
< 0x10000)
7735 macro_build (&imm_expr
, "xori", "t,r,i", dreg
, sreg
, BFD_RELOC_LO16
);
7737 else if (imm_expr
.X_op
== O_constant
7738 && imm_expr
.X_add_number
> -0x8000
7739 && imm_expr
.X_add_number
< 0)
7741 imm_expr
.X_add_number
= -imm_expr
.X_add_number
;
7742 macro_build (&imm_expr
, HAVE_32BIT_GPRS
? "addiu" : "daddiu",
7743 "t,r,j", dreg
, sreg
, BFD_RELOC_LO16
);
7745 else if (CPU_HAS_SEQ (mips_opts
.arch
))
7748 load_register (AT
, &imm_expr
, HAVE_64BIT_GPRS
);
7749 macro_build (NULL
, "seq", "d,v,t", dreg
, sreg
, AT
);
7754 load_register (AT
, &imm_expr
, HAVE_64BIT_GPRS
);
7755 macro_build (NULL
, "xor", "d,v,t", dreg
, sreg
, AT
);
7758 macro_build (&expr1
, "sltiu", "t,r,j", dreg
, dreg
, BFD_RELOC_LO16
);
7761 case M_SGE
: /* sreg >= treg <==> not (sreg < treg) */
7767 macro_build (NULL
, s
, "d,v,t", dreg
, sreg
, treg
);
7768 macro_build (&expr1
, "xori", "t,r,i", dreg
, dreg
, BFD_RELOC_LO16
);
7771 case M_SGE_I
: /* sreg >= I <==> not (sreg < I) */
7773 if (imm_expr
.X_op
== O_constant
7774 && imm_expr
.X_add_number
>= -0x8000
7775 && imm_expr
.X_add_number
< 0x8000)
7777 macro_build (&imm_expr
, mask
== M_SGE_I
? "slti" : "sltiu", "t,r,j",
7778 dreg
, sreg
, BFD_RELOC_LO16
);
7782 load_register (AT
, &imm_expr
, HAVE_64BIT_GPRS
);
7783 macro_build (NULL
, mask
== M_SGE_I
? "slt" : "sltu", "d,v,t",
7787 macro_build (&expr1
, "xori", "t,r,i", dreg
, dreg
, BFD_RELOC_LO16
);
7790 case M_SGT
: /* sreg > treg <==> treg < sreg */
7796 macro_build (NULL
, s
, "d,v,t", dreg
, treg
, sreg
);
7799 case M_SGT_I
: /* sreg > I <==> I < sreg */
7806 load_register (AT
, &imm_expr
, HAVE_64BIT_GPRS
);
7807 macro_build (NULL
, s
, "d,v,t", dreg
, AT
, sreg
);
7810 case M_SLE
: /* sreg <= treg <==> treg >= sreg <==> not (treg < sreg) */
7816 macro_build (NULL
, s
, "d,v,t", dreg
, treg
, sreg
);
7817 macro_build (&expr1
, "xori", "t,r,i", dreg
, dreg
, BFD_RELOC_LO16
);
7820 case M_SLE_I
: /* sreg <= I <==> I >= sreg <==> not (I < sreg) */
7827 load_register (AT
, &imm_expr
, HAVE_64BIT_GPRS
);
7828 macro_build (NULL
, s
, "d,v,t", dreg
, AT
, sreg
);
7829 macro_build (&expr1
, "xori", "t,r,i", dreg
, dreg
, BFD_RELOC_LO16
);
7833 if (imm_expr
.X_op
== O_constant
7834 && imm_expr
.X_add_number
>= -0x8000
7835 && imm_expr
.X_add_number
< 0x8000)
7837 macro_build (&imm_expr
, "slti", "t,r,j", dreg
, sreg
, BFD_RELOC_LO16
);
7841 load_register (AT
, &imm_expr
, HAVE_64BIT_GPRS
);
7842 macro_build (NULL
, "slt", "d,v,t", dreg
, sreg
, AT
);
7846 if (imm_expr
.X_op
== O_constant
7847 && imm_expr
.X_add_number
>= -0x8000
7848 && imm_expr
.X_add_number
< 0x8000)
7850 macro_build (&imm_expr
, "sltiu", "t,r,j", dreg
, sreg
,
7855 load_register (AT
, &imm_expr
, HAVE_64BIT_GPRS
);
7856 macro_build (NULL
, "sltu", "d,v,t", dreg
, sreg
, AT
);
7861 macro_build (NULL
, "sltu", "d,v,t", dreg
, 0, treg
);
7863 macro_build (NULL
, "sltu", "d,v,t", dreg
, 0, sreg
);
7866 macro_build (NULL
, "xor", "d,v,t", dreg
, sreg
, treg
);
7867 macro_build (NULL
, "sltu", "d,v,t", dreg
, 0, dreg
);
7872 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 0)
7874 macro_build (NULL
, "sltu", "d,v,t", dreg
, 0, sreg
);
7879 as_warn (_("Instruction %s: result is always true"),
7881 macro_build (&expr1
, HAVE_32BIT_GPRS
? "addiu" : "daddiu", "t,r,j",
7882 dreg
, 0, BFD_RELOC_LO16
);
7885 if (CPU_HAS_SEQ (mips_opts
.arch
)
7886 && -512 <= imm_expr
.X_add_number
7887 && imm_expr
.X_add_number
< 512)
7889 macro_build (NULL
, "snei", "t,r,+Q", dreg
, sreg
,
7890 (int) imm_expr
.X_add_number
);
7893 if (imm_expr
.X_op
== O_constant
7894 && imm_expr
.X_add_number
>= 0
7895 && imm_expr
.X_add_number
< 0x10000)
7897 macro_build (&imm_expr
, "xori", "t,r,i", dreg
, sreg
, BFD_RELOC_LO16
);
7899 else if (imm_expr
.X_op
== O_constant
7900 && imm_expr
.X_add_number
> -0x8000
7901 && imm_expr
.X_add_number
< 0)
7903 imm_expr
.X_add_number
= -imm_expr
.X_add_number
;
7904 macro_build (&imm_expr
, HAVE_32BIT_GPRS
? "addiu" : "daddiu",
7905 "t,r,j", dreg
, sreg
, BFD_RELOC_LO16
);
7907 else if (CPU_HAS_SEQ (mips_opts
.arch
))
7910 load_register (AT
, &imm_expr
, HAVE_64BIT_GPRS
);
7911 macro_build (NULL
, "sne", "d,v,t", dreg
, sreg
, AT
);
7916 load_register (AT
, &imm_expr
, HAVE_64BIT_GPRS
);
7917 macro_build (NULL
, "xor", "d,v,t", dreg
, sreg
, AT
);
7920 macro_build (NULL
, "sltu", "d,v,t", dreg
, 0, dreg
);
7926 if (imm_expr
.X_op
== O_constant
7927 && imm_expr
.X_add_number
> -0x8000
7928 && imm_expr
.X_add_number
<= 0x8000)
7930 imm_expr
.X_add_number
= -imm_expr
.X_add_number
;
7931 macro_build (&imm_expr
, dbl
? "daddi" : "addi", "t,r,j",
7932 dreg
, sreg
, BFD_RELOC_LO16
);
7936 load_register (AT
, &imm_expr
, dbl
);
7937 macro_build (NULL
, dbl
? "dsub" : "sub", "d,v,t", dreg
, sreg
, AT
);
7943 if (imm_expr
.X_op
== O_constant
7944 && imm_expr
.X_add_number
> -0x8000
7945 && imm_expr
.X_add_number
<= 0x8000)
7947 imm_expr
.X_add_number
= -imm_expr
.X_add_number
;
7948 macro_build (&imm_expr
, dbl
? "daddiu" : "addiu", "t,r,j",
7949 dreg
, sreg
, BFD_RELOC_LO16
);
7953 load_register (AT
, &imm_expr
, dbl
);
7954 macro_build (NULL
, dbl
? "dsubu" : "subu", "d,v,t", dreg
, sreg
, AT
);
7976 load_register (AT
, &imm_expr
, HAVE_64BIT_GPRS
);
7977 macro_build (NULL
, s
, "s,t", sreg
, AT
);
7982 gas_assert (mips_opts
.isa
== ISA_MIPS1
);
7984 sreg
= (ip
->insn_opcode
>> 11) & 0x1f; /* floating reg */
7985 dreg
= (ip
->insn_opcode
>> 06) & 0x1f; /* floating reg */
7988 * Is the double cfc1 instruction a bug in the mips assembler;
7989 * or is there a reason for it?
7992 macro_build (NULL
, "cfc1", "t,G", treg
, RA
);
7993 macro_build (NULL
, "cfc1", "t,G", treg
, RA
);
7994 macro_build (NULL
, "nop", "");
7995 expr1
.X_add_number
= 3;
7996 macro_build (&expr1
, "ori", "t,r,i", AT
, treg
, BFD_RELOC_LO16
);
7997 expr1
.X_add_number
= 2;
7998 macro_build (&expr1
, "xori", "t,r,i", AT
, AT
, BFD_RELOC_LO16
);
7999 macro_build (NULL
, "ctc1", "t,G", AT
, RA
);
8000 macro_build (NULL
, "nop", "");
8001 macro_build (NULL
, mask
== M_TRUNCWD
? "cvt.w.d" : "cvt.w.s", "D,S",
8003 macro_build (NULL
, "ctc1", "t,G", treg
, RA
);
8004 macro_build (NULL
, "nop", "");
8015 if (offset_expr
.X_add_number
>= 0x7fff)
8016 as_bad (_("operand overflow"));
8017 if (! target_big_endian
)
8018 ++offset_expr
.X_add_number
;
8019 macro_build (&offset_expr
, s
, "t,o(b)", AT
, BFD_RELOC_LO16
, breg
);
8020 if (! target_big_endian
)
8021 --offset_expr
.X_add_number
;
8023 ++offset_expr
.X_add_number
;
8024 macro_build (&offset_expr
, "lbu", "t,o(b)", treg
, BFD_RELOC_LO16
, breg
);
8025 macro_build (NULL
, "sll", "d,w,<", AT
, AT
, 8);
8026 macro_build (NULL
, "or", "d,v,t", treg
, treg
, AT
);
8039 if (offset_expr
.X_add_number
>= 0x8000 - off
)
8040 as_bad (_("operand overflow"));
8048 if (! target_big_endian
)
8049 offset_expr
.X_add_number
+= off
;
8050 macro_build (&offset_expr
, s
, "t,o(b)", tempreg
, BFD_RELOC_LO16
, breg
);
8051 if (! target_big_endian
)
8052 offset_expr
.X_add_number
-= off
;
8054 offset_expr
.X_add_number
+= off
;
8055 macro_build (&offset_expr
, s2
, "t,o(b)", tempreg
, BFD_RELOC_LO16
, breg
);
8057 /* If necessary, move the result in tempreg the final destination. */
8058 if (treg
== tempreg
)
8060 /* Protect second load's delay slot. */
8062 move_register (treg
, tempreg
);
8076 load_address (AT
, &offset_expr
, &used_at
);
8078 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t", AT
, AT
, breg
);
8079 if (! target_big_endian
)
8080 expr1
.X_add_number
= off
;
8082 expr1
.X_add_number
= 0;
8083 macro_build (&expr1
, s
, "t,o(b)", treg
, BFD_RELOC_LO16
, AT
);
8084 if (! target_big_endian
)
8085 expr1
.X_add_number
= 0;
8087 expr1
.X_add_number
= off
;
8088 macro_build (&expr1
, s2
, "t,o(b)", treg
, BFD_RELOC_LO16
, AT
);
8094 load_address (AT
, &offset_expr
, &used_at
);
8096 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t", AT
, AT
, breg
);
8097 if (target_big_endian
)
8098 expr1
.X_add_number
= 0;
8099 macro_build (&expr1
, mask
== M_ULH_A
? "lb" : "lbu", "t,o(b)",
8100 treg
, BFD_RELOC_LO16
, AT
);
8101 if (target_big_endian
)
8102 expr1
.X_add_number
= 1;
8104 expr1
.X_add_number
= 0;
8105 macro_build (&expr1
, "lbu", "t,o(b)", AT
, BFD_RELOC_LO16
, AT
);
8106 macro_build (NULL
, "sll", "d,w,<", treg
, treg
, 8);
8107 macro_build (NULL
, "or", "d,v,t", treg
, treg
, AT
);
8112 if (offset_expr
.X_add_number
>= 0x7fff)
8113 as_bad (_("operand overflow"));
8114 if (target_big_endian
)
8115 ++offset_expr
.X_add_number
;
8116 macro_build (&offset_expr
, "sb", "t,o(b)", treg
, BFD_RELOC_LO16
, breg
);
8117 macro_build (NULL
, "srl", "d,w,<", AT
, treg
, 8);
8118 if (target_big_endian
)
8119 --offset_expr
.X_add_number
;
8121 ++offset_expr
.X_add_number
;
8122 macro_build (&offset_expr
, "sb", "t,o(b)", AT
, BFD_RELOC_LO16
, breg
);
8135 if (offset_expr
.X_add_number
>= 0x8000 - off
)
8136 as_bad (_("operand overflow"));
8137 if (! target_big_endian
)
8138 offset_expr
.X_add_number
+= off
;
8139 macro_build (&offset_expr
, s
, "t,o(b)", treg
, BFD_RELOC_LO16
, breg
);
8140 if (! target_big_endian
)
8141 offset_expr
.X_add_number
-= off
;
8143 offset_expr
.X_add_number
+= off
;
8144 macro_build (&offset_expr
, s2
, "t,o(b)", treg
, BFD_RELOC_LO16
, breg
);
8158 load_address (AT
, &offset_expr
, &used_at
);
8160 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t", AT
, AT
, breg
);
8161 if (! target_big_endian
)
8162 expr1
.X_add_number
= off
;
8164 expr1
.X_add_number
= 0;
8165 macro_build (&expr1
, s
, "t,o(b)", treg
, BFD_RELOC_LO16
, AT
);
8166 if (! target_big_endian
)
8167 expr1
.X_add_number
= 0;
8169 expr1
.X_add_number
= off
;
8170 macro_build (&expr1
, s2
, "t,o(b)", treg
, BFD_RELOC_LO16
, AT
);
8175 load_address (AT
, &offset_expr
, &used_at
);
8177 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t", AT
, AT
, breg
);
8178 if (! target_big_endian
)
8179 expr1
.X_add_number
= 0;
8180 macro_build (&expr1
, "sb", "t,o(b)", treg
, BFD_RELOC_LO16
, AT
);
8181 macro_build (NULL
, "srl", "d,w,<", treg
, treg
, 8);
8182 if (! target_big_endian
)
8183 expr1
.X_add_number
= 1;
8185 expr1
.X_add_number
= 0;
8186 macro_build (&expr1
, "sb", "t,o(b)", treg
, BFD_RELOC_LO16
, AT
);
8187 if (! target_big_endian
)
8188 expr1
.X_add_number
= 0;
8190 expr1
.X_add_number
= 1;
8191 macro_build (&expr1
, "lbu", "t,o(b)", AT
, BFD_RELOC_LO16
, AT
);
8192 macro_build (NULL
, "sll", "d,w,<", treg
, treg
, 8);
8193 macro_build (NULL
, "or", "d,v,t", treg
, treg
, AT
);
8197 /* FIXME: Check if this is one of the itbl macros, since they
8198 are added dynamically. */
8199 as_bad (_("Macro %s not implemented yet"), ip
->insn_mo
->name
);
8202 if (!mips_opts
.at
&& used_at
)
8203 as_bad (_("Macro used $at after \".set noat\""));
8206 /* Implement macros in mips16 mode. */
8209 mips16_macro (struct mips_cl_insn
*ip
)
8212 int xreg
, yreg
, zreg
, tmp
;
8215 const char *s
, *s2
, *s3
;
8217 mask
= ip
->insn_mo
->mask
;
8219 xreg
= MIPS16_EXTRACT_OPERAND (RX
, *ip
);
8220 yreg
= MIPS16_EXTRACT_OPERAND (RY
, *ip
);
8221 zreg
= MIPS16_EXTRACT_OPERAND (RZ
, *ip
);
8223 expr1
.X_op
= O_constant
;
8224 expr1
.X_op_symbol
= NULL
;
8225 expr1
.X_add_symbol
= NULL
;
8226 expr1
.X_add_number
= 1;
8246 macro_build (NULL
, dbl
? "ddiv" : "div", "0,x,y", xreg
, yreg
);
8247 expr1
.X_add_number
= 2;
8248 macro_build (&expr1
, "bnez", "x,p", yreg
);
8249 macro_build (NULL
, "break", "6", 7);
8251 /* FIXME: The normal code checks for of -1 / -0x80000000 here,
8252 since that causes an overflow. We should do that as well,
8253 but I don't see how to do the comparisons without a temporary
8256 macro_build (NULL
, s
, "x", zreg
);
8276 macro_build (NULL
, s
, "0,x,y", xreg
, yreg
);
8277 expr1
.X_add_number
= 2;
8278 macro_build (&expr1
, "bnez", "x,p", yreg
);
8279 macro_build (NULL
, "break", "6", 7);
8281 macro_build (NULL
, s2
, "x", zreg
);
8287 macro_build (NULL
, dbl
? "dmultu" : "multu", "x,y", xreg
, yreg
);
8288 macro_build (NULL
, "mflo", "x", zreg
);
8296 if (imm_expr
.X_op
!= O_constant
)
8297 as_bad (_("Unsupported large constant"));
8298 imm_expr
.X_add_number
= -imm_expr
.X_add_number
;
8299 macro_build (&imm_expr
, dbl
? "daddiu" : "addiu", "y,x,4", yreg
, xreg
);
8303 if (imm_expr
.X_op
!= O_constant
)
8304 as_bad (_("Unsupported large constant"));
8305 imm_expr
.X_add_number
= -imm_expr
.X_add_number
;
8306 macro_build (&imm_expr
, "addiu", "x,k", xreg
);
8310 if (imm_expr
.X_op
!= O_constant
)
8311 as_bad (_("Unsupported large constant"));
8312 imm_expr
.X_add_number
= -imm_expr
.X_add_number
;
8313 macro_build (&imm_expr
, "daddiu", "y,j", yreg
);
8335 goto do_reverse_branch
;
8339 goto do_reverse_branch
;
8351 goto do_reverse_branch
;
8362 macro_build (NULL
, s
, "x,y", xreg
, yreg
);
8363 macro_build (&offset_expr
, s2
, "p");
8390 goto do_addone_branch_i
;
8395 goto do_addone_branch_i
;
8410 goto do_addone_branch_i
;
8417 if (imm_expr
.X_op
!= O_constant
)
8418 as_bad (_("Unsupported large constant"));
8419 ++imm_expr
.X_add_number
;
8422 macro_build (&imm_expr
, s
, s3
, xreg
);
8423 macro_build (&offset_expr
, s2
, "p");
8427 expr1
.X_add_number
= 0;
8428 macro_build (&expr1
, "slti", "x,8", yreg
);
8430 move_register (xreg
, yreg
);
8431 expr1
.X_add_number
= 2;
8432 macro_build (&expr1
, "bteqz", "p");
8433 macro_build (NULL
, "neg", "x,w", xreg
, xreg
);
8437 /* For consistency checking, verify that all bits are specified either
8438 by the match/mask part of the instruction definition, or by the
8441 validate_mips_insn (const struct mips_opcode
*opc
)
8443 const char *p
= opc
->args
;
8445 unsigned long used_bits
= opc
->mask
;
8447 if ((used_bits
& opc
->match
) != opc
->match
)
8449 as_bad (_("internal: bad mips opcode (mask error): %s %s"),
8450 opc
->name
, opc
->args
);
8453 #define USE_BITS(mask,shift) (used_bits |= ((mask) << (shift)))
8463 case '1': USE_BITS (OP_MASK_UDI1
, OP_SH_UDI1
); break;
8464 case '2': USE_BITS (OP_MASK_UDI2
, OP_SH_UDI2
); break;
8465 case '3': USE_BITS (OP_MASK_UDI3
, OP_SH_UDI3
); break;
8466 case '4': USE_BITS (OP_MASK_UDI4
, OP_SH_UDI4
); break;
8467 case 'A': USE_BITS (OP_MASK_SHAMT
, OP_SH_SHAMT
); break;
8468 case 'B': USE_BITS (OP_MASK_INSMSB
, OP_SH_INSMSB
); break;
8469 case 'C': USE_BITS (OP_MASK_EXTMSBD
, OP_SH_EXTMSBD
); break;
8470 case 'D': USE_BITS (OP_MASK_RD
, OP_SH_RD
);
8471 USE_BITS (OP_MASK_SEL
, OP_SH_SEL
); break;
8472 case 'E': USE_BITS (OP_MASK_SHAMT
, OP_SH_SHAMT
); break;
8473 case 'F': USE_BITS (OP_MASK_INSMSB
, OP_SH_INSMSB
); break;
8474 case 'G': USE_BITS (OP_MASK_EXTMSBD
, OP_SH_EXTMSBD
); break;
8475 case 'H': USE_BITS (OP_MASK_EXTMSBD
, OP_SH_EXTMSBD
); break;
8477 case 't': USE_BITS (OP_MASK_RT
, OP_SH_RT
); break;
8478 case 'T': USE_BITS (OP_MASK_RT
, OP_SH_RT
);
8479 USE_BITS (OP_MASK_SEL
, OP_SH_SEL
); break;
8480 case 'x': USE_BITS (OP_MASK_BBITIND
, OP_SH_BBITIND
); break;
8481 case 'X': USE_BITS (OP_MASK_BBITIND
, OP_SH_BBITIND
); break;
8482 case 'p': USE_BITS (OP_MASK_CINSPOS
, OP_SH_CINSPOS
); break;
8483 case 'P': USE_BITS (OP_MASK_CINSPOS
, OP_SH_CINSPOS
); break;
8484 case 'Q': USE_BITS (OP_MASK_SEQI
, OP_SH_SEQI
); break;
8485 case 's': USE_BITS (OP_MASK_CINSLM1
, OP_SH_CINSLM1
); break;
8486 case 'S': USE_BITS (OP_MASK_CINSLM1
, OP_SH_CINSLM1
); break;
8489 as_bad (_("internal: bad mips opcode (unknown extension operand type `+%c'): %s %s"),
8490 c
, opc
->name
, opc
->args
);
8494 case '<': USE_BITS (OP_MASK_SHAMT
, OP_SH_SHAMT
); break;
8495 case '>': USE_BITS (OP_MASK_SHAMT
, OP_SH_SHAMT
); break;
8497 case 'B': USE_BITS (OP_MASK_CODE20
, OP_SH_CODE20
); break;
8498 case 'C': USE_BITS (OP_MASK_COPZ
, OP_SH_COPZ
); break;
8499 case 'D': USE_BITS (OP_MASK_FD
, OP_SH_FD
); break;
8500 case 'E': USE_BITS (OP_MASK_RT
, OP_SH_RT
); break;
8502 case 'G': USE_BITS (OP_MASK_RD
, OP_SH_RD
); break;
8503 case 'H': USE_BITS (OP_MASK_SEL
, OP_SH_SEL
); break;
8505 case 'J': USE_BITS (OP_MASK_CODE19
, OP_SH_CODE19
); break;
8506 case 'K': USE_BITS (OP_MASK_RD
, OP_SH_RD
); break;
8508 case 'M': USE_BITS (OP_MASK_CCC
, OP_SH_CCC
); break;
8509 case 'N': USE_BITS (OP_MASK_BCC
, OP_SH_BCC
); break;
8510 case 'O': USE_BITS (OP_MASK_ALN
, OP_SH_ALN
); break;
8511 case 'Q': USE_BITS (OP_MASK_VSEL
, OP_SH_VSEL
);
8512 USE_BITS (OP_MASK_FT
, OP_SH_FT
); break;
8513 case 'R': USE_BITS (OP_MASK_FR
, OP_SH_FR
); break;
8514 case 'S': USE_BITS (OP_MASK_FS
, OP_SH_FS
); break;
8515 case 'T': USE_BITS (OP_MASK_FT
, OP_SH_FT
); break;
8516 case 'V': USE_BITS (OP_MASK_FS
, OP_SH_FS
); break;
8517 case 'W': USE_BITS (OP_MASK_FT
, OP_SH_FT
); break;
8518 case 'X': USE_BITS (OP_MASK_FD
, OP_SH_FD
); break;
8519 case 'Y': USE_BITS (OP_MASK_FS
, OP_SH_FS
); break;
8520 case 'Z': USE_BITS (OP_MASK_FT
, OP_SH_FT
); break;
8521 case 'a': USE_BITS (OP_MASK_TARGET
, OP_SH_TARGET
); break;
8522 case 'b': USE_BITS (OP_MASK_RS
, OP_SH_RS
); break;
8523 case 'c': USE_BITS (OP_MASK_CODE
, OP_SH_CODE
); break;
8524 case 'd': USE_BITS (OP_MASK_RD
, OP_SH_RD
); break;
8526 case 'h': USE_BITS (OP_MASK_PREFX
, OP_SH_PREFX
); break;
8527 case 'i': USE_BITS (OP_MASK_IMMEDIATE
, OP_SH_IMMEDIATE
); break;
8528 case 'j': USE_BITS (OP_MASK_DELTA
, OP_SH_DELTA
); break;
8529 case 'k': USE_BITS (OP_MASK_CACHE
, OP_SH_CACHE
); break;
8531 case 'o': USE_BITS (OP_MASK_DELTA
, OP_SH_DELTA
); break;
8532 case 'p': USE_BITS (OP_MASK_DELTA
, OP_SH_DELTA
); break;
8533 case 'q': USE_BITS (OP_MASK_CODE2
, OP_SH_CODE2
); break;
8534 case 'r': USE_BITS (OP_MASK_RS
, OP_SH_RS
); break;
8535 case 's': USE_BITS (OP_MASK_RS
, OP_SH_RS
); break;
8536 case 't': USE_BITS (OP_MASK_RT
, OP_SH_RT
); break;
8537 case 'u': USE_BITS (OP_MASK_IMMEDIATE
, OP_SH_IMMEDIATE
); break;
8538 case 'v': USE_BITS (OP_MASK_RS
, OP_SH_RS
); break;
8539 case 'w': USE_BITS (OP_MASK_RT
, OP_SH_RT
); break;
8542 case 'P': USE_BITS (OP_MASK_PERFREG
, OP_SH_PERFREG
); break;
8543 case 'U': USE_BITS (OP_MASK_RD
, OP_SH_RD
);
8544 USE_BITS (OP_MASK_RT
, OP_SH_RT
); break;
8545 case 'e': USE_BITS (OP_MASK_VECBYTE
, OP_SH_VECBYTE
); break;
8546 case '%': USE_BITS (OP_MASK_VECALIGN
, OP_SH_VECALIGN
); break;
8549 case '1': USE_BITS (OP_MASK_SHAMT
, OP_SH_SHAMT
); break;
8550 case '2': USE_BITS (OP_MASK_BP
, OP_SH_BP
); break;
8551 case '3': USE_BITS (OP_MASK_SA3
, OP_SH_SA3
); break;
8552 case '4': USE_BITS (OP_MASK_SA4
, OP_SH_SA4
); break;
8553 case '5': USE_BITS (OP_MASK_IMM8
, OP_SH_IMM8
); break;
8554 case '6': USE_BITS (OP_MASK_RS
, OP_SH_RS
); break;
8555 case '7': USE_BITS (OP_MASK_DSPACC
, OP_SH_DSPACC
); break;
8556 case '8': USE_BITS (OP_MASK_WRDSP
, OP_SH_WRDSP
); break;
8557 case '9': USE_BITS (OP_MASK_DSPACC_S
, OP_SH_DSPACC_S
);break;
8558 case '0': USE_BITS (OP_MASK_DSPSFT
, OP_SH_DSPSFT
); break;
8559 case '\'': USE_BITS (OP_MASK_RDDSP
, OP_SH_RDDSP
); break;
8560 case ':': USE_BITS (OP_MASK_DSPSFT_7
, OP_SH_DSPSFT_7
);break;
8561 case '@': USE_BITS (OP_MASK_IMM10
, OP_SH_IMM10
); break;
8562 case '!': USE_BITS (OP_MASK_MT_U
, OP_SH_MT_U
); break;
8563 case '$': USE_BITS (OP_MASK_MT_H
, OP_SH_MT_H
); break;
8564 case '*': USE_BITS (OP_MASK_MTACC_T
, OP_SH_MTACC_T
); break;
8565 case '&': USE_BITS (OP_MASK_MTACC_D
, OP_SH_MTACC_D
); break;
8566 case 'g': USE_BITS (OP_MASK_RD
, OP_SH_RD
); break;
8568 as_bad (_("internal: bad mips opcode (unknown operand type `%c'): %s %s"),
8569 c
, opc
->name
, opc
->args
);
8573 if (used_bits
!= 0xffffffff)
8575 as_bad (_("internal: bad mips opcode (bits 0x%lx undefined): %s %s"),
8576 ~used_bits
& 0xffffffff, opc
->name
, opc
->args
);
8582 /* UDI immediates. */
8590 static const struct mips_immed mips_immed
[] = {
8591 { '1', OP_SH_UDI1
, OP_MASK_UDI1
, 0},
8592 { '2', OP_SH_UDI2
, OP_MASK_UDI2
, 0},
8593 { '3', OP_SH_UDI3
, OP_MASK_UDI3
, 0},
8594 { '4', OP_SH_UDI4
, OP_MASK_UDI4
, 0},
8598 /* Check whether an odd floating-point register is allowed. */
8600 mips_oddfpreg_ok (const struct mips_opcode
*insn
, int argnum
)
8602 const char *s
= insn
->name
;
8604 if (insn
->pinfo
== INSN_MACRO
)
8605 /* Let a macro pass, we'll catch it later when it is expanded. */
8608 if (ISA_HAS_ODD_SINGLE_FPR (mips_opts
.isa
))
8610 /* Allow odd registers for single-precision ops. */
8611 switch (insn
->pinfo
& (FP_S
| FP_D
))
8615 return 1; /* both single precision - ok */
8617 return 0; /* both double precision - fail */
8622 /* Cvt.w.x and cvt.x.w allow an odd register for a 'w' or 's' operand. */
8623 s
= strchr (insn
->name
, '.');
8625 s
= s
!= NULL
? strchr (s
+ 1, '.') : NULL
;
8626 return (s
!= NULL
&& (s
[1] == 'w' || s
[1] == 's'));
8629 /* Single-precision coprocessor loads and moves are OK too. */
8630 if ((insn
->pinfo
& FP_S
)
8631 && (insn
->pinfo
& (INSN_COPROC_MEMORY_DELAY
| INSN_STORE_MEMORY
8632 | INSN_LOAD_COPROC_DELAY
| INSN_COPROC_MOVE_DELAY
)))
8638 /* This routine assembles an instruction into its binary format. As a
8639 side effect, it sets one of the global variables imm_reloc or
8640 offset_reloc to the type of relocation to do if one of the operands
8641 is an address expression. */
8644 mips_ip (char *str
, struct mips_cl_insn
*ip
)
8649 struct mips_opcode
*insn
;
8652 unsigned int lastregno
= 0;
8653 unsigned int lastpos
= 0;
8654 unsigned int limlo
, limhi
;
8657 offsetT min_range
, max_range
;
8663 /* If the instruction contains a '.', we first try to match an instruction
8664 including the '.'. Then we try again without the '.'. */
8666 for (s
= str
; *s
!= '\0' && !ISSPACE (*s
); ++s
)
8669 /* If we stopped on whitespace, then replace the whitespace with null for
8670 the call to hash_find. Save the character we replaced just in case we
8671 have to re-parse the instruction. */
8678 insn
= (struct mips_opcode
*) hash_find (op_hash
, str
);
8680 /* If we didn't find the instruction in the opcode table, try again, but
8681 this time with just the instruction up to, but not including the
8685 /* Restore the character we overwrite above (if any). */
8689 /* Scan up to the first '.' or whitespace. */
8691 *s
!= '\0' && *s
!= '.' && !ISSPACE (*s
);
8695 /* If we did not find a '.', then we can quit now. */
8698 insn_error
= _("unrecognized opcode");
8702 /* Lookup the instruction in the hash table. */
8704 if ((insn
= (struct mips_opcode
*) hash_find (op_hash
, str
)) == NULL
)
8706 insn_error
= _("unrecognized opcode");
8716 gas_assert (strcmp (insn
->name
, str
) == 0);
8718 ok
= is_opcode_valid (insn
, FALSE
);
8721 if (insn
+ 1 < &mips_opcodes
[NUMOPCODES
]
8722 && strcmp (insn
->name
, insn
[1].name
) == 0)
8731 static char buf
[100];
8733 _("opcode not supported on this processor: %s (%s)"),
8734 mips_cpu_info_from_arch (mips_opts
.arch
)->name
,
8735 mips_cpu_info_from_isa (mips_opts
.isa
)->name
);
8744 create_insn (ip
, insn
);
8747 lastregno
= 0xffffffff;
8748 for (args
= insn
->args
;; ++args
)
8752 s
+= strspn (s
, " \t");
8756 case '\0': /* end of args */
8761 case '2': /* dsp 2-bit unsigned immediate in bit 11 */
8762 my_getExpression (&imm_expr
, s
);
8763 check_absolute_expr (ip
, &imm_expr
);
8764 if ((unsigned long) imm_expr
.X_add_number
!= 1
8765 && (unsigned long) imm_expr
.X_add_number
!= 3)
8767 as_bad (_("BALIGN immediate not 1 or 3 (%lu)"),
8768 (unsigned long) imm_expr
.X_add_number
);
8770 INSERT_OPERAND (BP
, *ip
, imm_expr
.X_add_number
);
8771 imm_expr
.X_op
= O_absent
;
8775 case '3': /* dsp 3-bit unsigned immediate in bit 21 */
8776 my_getExpression (&imm_expr
, s
);
8777 check_absolute_expr (ip
, &imm_expr
);
8778 if (imm_expr
.X_add_number
& ~OP_MASK_SA3
)
8780 as_bad (_("DSP immediate not in range 0..%d (%lu)"),
8781 OP_MASK_SA3
, (unsigned long) imm_expr
.X_add_number
);
8783 INSERT_OPERAND (SA3
, *ip
, imm_expr
.X_add_number
);
8784 imm_expr
.X_op
= O_absent
;
8788 case '4': /* dsp 4-bit unsigned immediate in bit 21 */
8789 my_getExpression (&imm_expr
, s
);
8790 check_absolute_expr (ip
, &imm_expr
);
8791 if (imm_expr
.X_add_number
& ~OP_MASK_SA4
)
8793 as_bad (_("DSP immediate not in range 0..%d (%lu)"),
8794 OP_MASK_SA4
, (unsigned long) imm_expr
.X_add_number
);
8796 INSERT_OPERAND (SA4
, *ip
, imm_expr
.X_add_number
);
8797 imm_expr
.X_op
= O_absent
;
8801 case '5': /* dsp 8-bit unsigned immediate in bit 16 */
8802 my_getExpression (&imm_expr
, s
);
8803 check_absolute_expr (ip
, &imm_expr
);
8804 if (imm_expr
.X_add_number
& ~OP_MASK_IMM8
)
8806 as_bad (_("DSP immediate not in range 0..%d (%lu)"),
8807 OP_MASK_IMM8
, (unsigned long) imm_expr
.X_add_number
);
8809 INSERT_OPERAND (IMM8
, *ip
, imm_expr
.X_add_number
);
8810 imm_expr
.X_op
= O_absent
;
8814 case '6': /* dsp 5-bit unsigned immediate in bit 21 */
8815 my_getExpression (&imm_expr
, s
);
8816 check_absolute_expr (ip
, &imm_expr
);
8817 if (imm_expr
.X_add_number
& ~OP_MASK_RS
)
8819 as_bad (_("DSP immediate not in range 0..%d (%lu)"),
8820 OP_MASK_RS
, (unsigned long) imm_expr
.X_add_number
);
8822 INSERT_OPERAND (RS
, *ip
, imm_expr
.X_add_number
);
8823 imm_expr
.X_op
= O_absent
;
8827 case '7': /* four dsp accumulators in bits 11,12 */
8828 if (s
[0] == '$' && s
[1] == 'a' && s
[2] == 'c' &&
8829 s
[3] >= '0' && s
[3] <= '3')
8833 INSERT_OPERAND (DSPACC
, *ip
, regno
);
8837 as_bad (_("Invalid dsp acc register"));
8840 case '8': /* dsp 6-bit unsigned immediate in bit 11 */
8841 my_getExpression (&imm_expr
, s
);
8842 check_absolute_expr (ip
, &imm_expr
);
8843 if (imm_expr
.X_add_number
& ~OP_MASK_WRDSP
)
8845 as_bad (_("DSP immediate not in range 0..%d (%lu)"),
8847 (unsigned long) imm_expr
.X_add_number
);
8849 INSERT_OPERAND (WRDSP
, *ip
, imm_expr
.X_add_number
);
8850 imm_expr
.X_op
= O_absent
;
8854 case '9': /* four dsp accumulators in bits 21,22 */
8855 if (s
[0] == '$' && s
[1] == 'a' && s
[2] == 'c' &&
8856 s
[3] >= '0' && s
[3] <= '3')
8860 INSERT_OPERAND (DSPACC_S
, *ip
, regno
);
8864 as_bad (_("Invalid dsp acc register"));
8867 case '0': /* dsp 6-bit signed immediate in bit 20 */
8868 my_getExpression (&imm_expr
, s
);
8869 check_absolute_expr (ip
, &imm_expr
);
8870 min_range
= -((OP_MASK_DSPSFT
+ 1) >> 1);
8871 max_range
= ((OP_MASK_DSPSFT
+ 1) >> 1) - 1;
8872 if (imm_expr
.X_add_number
< min_range
||
8873 imm_expr
.X_add_number
> max_range
)
8875 as_bad (_("DSP immediate not in range %ld..%ld (%ld)"),
8876 (long) min_range
, (long) max_range
,
8877 (long) imm_expr
.X_add_number
);
8879 INSERT_OPERAND (DSPSFT
, *ip
, imm_expr
.X_add_number
);
8880 imm_expr
.X_op
= O_absent
;
8884 case '\'': /* dsp 6-bit unsigned immediate in bit 16 */
8885 my_getExpression (&imm_expr
, s
);
8886 check_absolute_expr (ip
, &imm_expr
);
8887 if (imm_expr
.X_add_number
& ~OP_MASK_RDDSP
)
8889 as_bad (_("DSP immediate not in range 0..%d (%lu)"),
8891 (unsigned long) imm_expr
.X_add_number
);
8893 INSERT_OPERAND (RDDSP
, *ip
, imm_expr
.X_add_number
);
8894 imm_expr
.X_op
= O_absent
;
8898 case ':': /* dsp 7-bit signed immediate in bit 19 */
8899 my_getExpression (&imm_expr
, s
);
8900 check_absolute_expr (ip
, &imm_expr
);
8901 min_range
= -((OP_MASK_DSPSFT_7
+ 1) >> 1);
8902 max_range
= ((OP_MASK_DSPSFT_7
+ 1) >> 1) - 1;
8903 if (imm_expr
.X_add_number
< min_range
||
8904 imm_expr
.X_add_number
> max_range
)
8906 as_bad (_("DSP immediate not in range %ld..%ld (%ld)"),
8907 (long) min_range
, (long) max_range
,
8908 (long) imm_expr
.X_add_number
);
8910 INSERT_OPERAND (DSPSFT_7
, *ip
, imm_expr
.X_add_number
);
8911 imm_expr
.X_op
= O_absent
;
8915 case '@': /* dsp 10-bit signed immediate in bit 16 */
8916 my_getExpression (&imm_expr
, s
);
8917 check_absolute_expr (ip
, &imm_expr
);
8918 min_range
= -((OP_MASK_IMM10
+ 1) >> 1);
8919 max_range
= ((OP_MASK_IMM10
+ 1) >> 1) - 1;
8920 if (imm_expr
.X_add_number
< min_range
||
8921 imm_expr
.X_add_number
> max_range
)
8923 as_bad (_("DSP immediate not in range %ld..%ld (%ld)"),
8924 (long) min_range
, (long) max_range
,
8925 (long) imm_expr
.X_add_number
);
8927 INSERT_OPERAND (IMM10
, *ip
, imm_expr
.X_add_number
);
8928 imm_expr
.X_op
= O_absent
;
8932 case '!': /* MT usermode flag bit. */
8933 my_getExpression (&imm_expr
, s
);
8934 check_absolute_expr (ip
, &imm_expr
);
8935 if (imm_expr
.X_add_number
& ~OP_MASK_MT_U
)
8936 as_bad (_("MT usermode bit not 0 or 1 (%lu)"),
8937 (unsigned long) imm_expr
.X_add_number
);
8938 INSERT_OPERAND (MT_U
, *ip
, imm_expr
.X_add_number
);
8939 imm_expr
.X_op
= O_absent
;
8943 case '$': /* MT load high flag bit. */
8944 my_getExpression (&imm_expr
, s
);
8945 check_absolute_expr (ip
, &imm_expr
);
8946 if (imm_expr
.X_add_number
& ~OP_MASK_MT_H
)
8947 as_bad (_("MT load high bit not 0 or 1 (%lu)"),
8948 (unsigned long) imm_expr
.X_add_number
);
8949 INSERT_OPERAND (MT_H
, *ip
, imm_expr
.X_add_number
);
8950 imm_expr
.X_op
= O_absent
;
8954 case '*': /* four dsp accumulators in bits 18,19 */
8955 if (s
[0] == '$' && s
[1] == 'a' && s
[2] == 'c' &&
8956 s
[3] >= '0' && s
[3] <= '3')
8960 INSERT_OPERAND (MTACC_T
, *ip
, regno
);
8964 as_bad (_("Invalid dsp/smartmips acc register"));
8967 case '&': /* four dsp accumulators in bits 13,14 */
8968 if (s
[0] == '$' && s
[1] == 'a' && s
[2] == 'c' &&
8969 s
[3] >= '0' && s
[3] <= '3')
8973 INSERT_OPERAND (MTACC_D
, *ip
, regno
);
8977 as_bad (_("Invalid dsp/smartmips acc register"));
8989 INSERT_OPERAND (RS
, *ip
, lastregno
);
8993 INSERT_OPERAND (RT
, *ip
, lastregno
);
8997 INSERT_OPERAND (FT
, *ip
, lastregno
);
9001 INSERT_OPERAND (FS
, *ip
, lastregno
);
9007 /* Handle optional base register.
9008 Either the base register is omitted or
9009 we must have a left paren. */
9010 /* This is dependent on the next operand specifier
9011 is a base register specification. */
9012 gas_assert (args
[1] == 'b' || args
[1] == '5'
9013 || args
[1] == '-' || args
[1] == '4');
9017 case ')': /* these must match exactly */
9024 case '+': /* Opcode extension character. */
9027 case '1': /* UDI immediates. */
9032 const struct mips_immed
*imm
= mips_immed
;
9034 while (imm
->type
&& imm
->type
!= *args
)
9038 my_getExpression (&imm_expr
, s
);
9039 check_absolute_expr (ip
, &imm_expr
);
9040 if ((unsigned long) imm_expr
.X_add_number
& ~imm
->mask
)
9042 as_warn (_("Illegal %s number (%lu, 0x%lx)"),
9043 imm
->desc
? imm
->desc
: ip
->insn_mo
->name
,
9044 (unsigned long) imm_expr
.X_add_number
,
9045 (unsigned long) imm_expr
.X_add_number
);
9046 imm_expr
.X_add_number
&= imm
->mask
;
9048 ip
->insn_opcode
|= ((unsigned long) imm_expr
.X_add_number
9050 imm_expr
.X_op
= O_absent
;
9055 case 'A': /* ins/ext position, becomes LSB. */
9064 my_getExpression (&imm_expr
, s
);
9065 check_absolute_expr (ip
, &imm_expr
);
9066 if ((unsigned long) imm_expr
.X_add_number
< limlo
9067 || (unsigned long) imm_expr
.X_add_number
> limhi
)
9069 as_bad (_("Improper position (%lu)"),
9070 (unsigned long) imm_expr
.X_add_number
);
9071 imm_expr
.X_add_number
= limlo
;
9073 lastpos
= imm_expr
.X_add_number
;
9074 INSERT_OPERAND (SHAMT
, *ip
, imm_expr
.X_add_number
);
9075 imm_expr
.X_op
= O_absent
;
9079 case 'B': /* ins size, becomes MSB. */
9088 my_getExpression (&imm_expr
, s
);
9089 check_absolute_expr (ip
, &imm_expr
);
9090 /* Check for negative input so that small negative numbers
9091 will not succeed incorrectly. The checks against
9092 (pos+size) transitively check "size" itself,
9093 assuming that "pos" is reasonable. */
9094 if ((long) imm_expr
.X_add_number
< 0
9095 || ((unsigned long) imm_expr
.X_add_number
9097 || ((unsigned long) imm_expr
.X_add_number
9100 as_bad (_("Improper insert size (%lu, position %lu)"),
9101 (unsigned long) imm_expr
.X_add_number
,
9102 (unsigned long) lastpos
);
9103 imm_expr
.X_add_number
= limlo
- lastpos
;
9105 INSERT_OPERAND (INSMSB
, *ip
,
9106 lastpos
+ imm_expr
.X_add_number
- 1);
9107 imm_expr
.X_op
= O_absent
;
9111 case 'C': /* ext size, becomes MSBD. */
9124 my_getExpression (&imm_expr
, s
);
9125 check_absolute_expr (ip
, &imm_expr
);
9126 /* Check for negative input so that small negative numbers
9127 will not succeed incorrectly. The checks against
9128 (pos+size) transitively check "size" itself,
9129 assuming that "pos" is reasonable. */
9130 if ((long) imm_expr
.X_add_number
< 0
9131 || ((unsigned long) imm_expr
.X_add_number
9133 || ((unsigned long) imm_expr
.X_add_number
9136 as_bad (_("Improper extract size (%lu, position %lu)"),
9137 (unsigned long) imm_expr
.X_add_number
,
9138 (unsigned long) lastpos
);
9139 imm_expr
.X_add_number
= limlo
- lastpos
;
9141 INSERT_OPERAND (EXTMSBD
, *ip
, imm_expr
.X_add_number
- 1);
9142 imm_expr
.X_op
= O_absent
;
9147 /* +D is for disassembly only; never match. */
9151 /* "+I" is like "I", except that imm2_expr is used. */
9152 my_getExpression (&imm2_expr
, s
);
9153 if (imm2_expr
.X_op
!= O_big
9154 && imm2_expr
.X_op
!= O_constant
)
9155 insn_error
= _("absolute expression required");
9156 if (HAVE_32BIT_GPRS
)
9157 normalize_constant_expr (&imm2_expr
);
9161 case 'T': /* Coprocessor register. */
9162 /* +T is for disassembly only; never match. */
9165 case 't': /* Coprocessor register number. */
9166 if (s
[0] == '$' && ISDIGIT (s
[1]))
9176 while (ISDIGIT (*s
));
9178 as_bad (_("Invalid register number (%d)"), regno
);
9181 INSERT_OPERAND (RT
, *ip
, regno
);
9186 as_bad (_("Invalid coprocessor 0 register number"));
9190 /* bbit[01] and bbit[01]32 bit index. Give error if index
9191 is not in the valid range. */
9192 my_getExpression (&imm_expr
, s
);
9193 check_absolute_expr (ip
, &imm_expr
);
9194 if ((unsigned) imm_expr
.X_add_number
> 31)
9196 as_bad (_("Improper bit index (%lu)"),
9197 (unsigned long) imm_expr
.X_add_number
);
9198 imm_expr
.X_add_number
= 0;
9200 INSERT_OPERAND (BBITIND
, *ip
, imm_expr
.X_add_number
);
9201 imm_expr
.X_op
= O_absent
;
9206 /* bbit[01] bit index when bbit is used but we generate
9207 bbit[01]32 because the index is over 32. Move to the
9208 next candidate if index is not in the valid range. */
9209 my_getExpression (&imm_expr
, s
);
9210 check_absolute_expr (ip
, &imm_expr
);
9211 if ((unsigned) imm_expr
.X_add_number
< 32
9212 || (unsigned) imm_expr
.X_add_number
> 63)
9214 INSERT_OPERAND (BBITIND
, *ip
, imm_expr
.X_add_number
- 32);
9215 imm_expr
.X_op
= O_absent
;
9220 /* cins, cins32, exts and exts32 position field. Give error
9221 if it's not in the valid range. */
9222 my_getExpression (&imm_expr
, s
);
9223 check_absolute_expr (ip
, &imm_expr
);
9224 if ((unsigned) imm_expr
.X_add_number
> 31)
9226 as_bad (_("Improper position (%lu)"),
9227 (unsigned long) imm_expr
.X_add_number
);
9228 imm_expr
.X_add_number
= 0;
9230 /* Make the pos explicit to simplify +S. */
9231 lastpos
= imm_expr
.X_add_number
+ 32;
9232 INSERT_OPERAND (CINSPOS
, *ip
, imm_expr
.X_add_number
);
9233 imm_expr
.X_op
= O_absent
;
9238 /* cins, cins32, exts and exts32 position field. Move to
9239 the next candidate if it's not in the valid range. */
9240 my_getExpression (&imm_expr
, s
);
9241 check_absolute_expr (ip
, &imm_expr
);
9242 if ((unsigned) imm_expr
.X_add_number
< 32
9243 || (unsigned) imm_expr
.X_add_number
> 63)
9245 lastpos
= imm_expr
.X_add_number
;
9246 INSERT_OPERAND (CINSPOS
, *ip
, imm_expr
.X_add_number
- 32);
9247 imm_expr
.X_op
= O_absent
;
9252 /* cins and exts length-minus-one field. */
9253 my_getExpression (&imm_expr
, s
);
9254 check_absolute_expr (ip
, &imm_expr
);
9255 if ((unsigned long) imm_expr
.X_add_number
> 31)
9257 as_bad (_("Improper size (%lu)"),
9258 (unsigned long) imm_expr
.X_add_number
);
9259 imm_expr
.X_add_number
= 0;
9261 INSERT_OPERAND (CINSLM1
, *ip
, imm_expr
.X_add_number
);
9262 imm_expr
.X_op
= O_absent
;
9267 /* cins32/exts32 and cins/exts aliasing cint32/exts32
9268 length-minus-one field. */
9269 my_getExpression (&imm_expr
, s
);
9270 check_absolute_expr (ip
, &imm_expr
);
9271 if ((long) imm_expr
.X_add_number
< 0
9272 || (unsigned long) imm_expr
.X_add_number
+ lastpos
> 63)
9274 as_bad (_("Improper size (%lu)"),
9275 (unsigned long) imm_expr
.X_add_number
);
9276 imm_expr
.X_add_number
= 0;
9278 INSERT_OPERAND (CINSLM1
, *ip
, imm_expr
.X_add_number
);
9279 imm_expr
.X_op
= O_absent
;
9284 /* seqi/snei immediate field. */
9285 my_getExpression (&imm_expr
, s
);
9286 check_absolute_expr (ip
, &imm_expr
);
9287 if ((long) imm_expr
.X_add_number
< -512
9288 || (long) imm_expr
.X_add_number
>= 512)
9290 as_bad (_("Improper immediate (%ld)"),
9291 (long) imm_expr
.X_add_number
);
9292 imm_expr
.X_add_number
= 0;
9294 INSERT_OPERAND (SEQI
, *ip
, imm_expr
.X_add_number
);
9295 imm_expr
.X_op
= O_absent
;
9300 as_bad (_("internal: bad mips opcode (unknown extension operand type `+%c'): %s %s"),
9301 *args
, insn
->name
, insn
->args
);
9302 /* Further processing is fruitless. */
9307 case '<': /* must be at least one digit */
9309 * According to the manual, if the shift amount is greater
9310 * than 31 or less than 0, then the shift amount should be
9311 * mod 32. In reality the mips assembler issues an error.
9312 * We issue a warning and mask out all but the low 5 bits.
9314 my_getExpression (&imm_expr
, s
);
9315 check_absolute_expr (ip
, &imm_expr
);
9316 if ((unsigned long) imm_expr
.X_add_number
> 31)
9317 as_warn (_("Improper shift amount (%lu)"),
9318 (unsigned long) imm_expr
.X_add_number
);
9319 INSERT_OPERAND (SHAMT
, *ip
, imm_expr
.X_add_number
);
9320 imm_expr
.X_op
= O_absent
;
9324 case '>': /* shift amount minus 32 */
9325 my_getExpression (&imm_expr
, s
);
9326 check_absolute_expr (ip
, &imm_expr
);
9327 if ((unsigned long) imm_expr
.X_add_number
< 32
9328 || (unsigned long) imm_expr
.X_add_number
> 63)
9330 INSERT_OPERAND (SHAMT
, *ip
, imm_expr
.X_add_number
- 32);
9331 imm_expr
.X_op
= O_absent
;
9335 case 'k': /* cache code */
9336 case 'h': /* prefx code */
9337 case '1': /* sync type */
9338 my_getExpression (&imm_expr
, s
);
9339 check_absolute_expr (ip
, &imm_expr
);
9340 if ((unsigned long) imm_expr
.X_add_number
> 31)
9341 as_warn (_("Invalid value for `%s' (%lu)"),
9343 (unsigned long) imm_expr
.X_add_number
);
9345 INSERT_OPERAND (CACHE
, *ip
, imm_expr
.X_add_number
);
9346 else if (*args
== 'h')
9347 INSERT_OPERAND (PREFX
, *ip
, imm_expr
.X_add_number
);
9349 INSERT_OPERAND (SHAMT
, *ip
, imm_expr
.X_add_number
);
9350 imm_expr
.X_op
= O_absent
;
9354 case 'c': /* break code */
9355 my_getExpression (&imm_expr
, s
);
9356 check_absolute_expr (ip
, &imm_expr
);
9357 if ((unsigned long) imm_expr
.X_add_number
> OP_MASK_CODE
)
9358 as_warn (_("Code for %s not in range 0..1023 (%lu)"),
9360 (unsigned long) imm_expr
.X_add_number
);
9361 INSERT_OPERAND (CODE
, *ip
, imm_expr
.X_add_number
);
9362 imm_expr
.X_op
= O_absent
;
9366 case 'q': /* lower break code */
9367 my_getExpression (&imm_expr
, s
);
9368 check_absolute_expr (ip
, &imm_expr
);
9369 if ((unsigned long) imm_expr
.X_add_number
> OP_MASK_CODE2
)
9370 as_warn (_("Lower code for %s not in range 0..1023 (%lu)"),
9372 (unsigned long) imm_expr
.X_add_number
);
9373 INSERT_OPERAND (CODE2
, *ip
, imm_expr
.X_add_number
);
9374 imm_expr
.X_op
= O_absent
;
9378 case 'B': /* 20-bit syscall/break code. */
9379 my_getExpression (&imm_expr
, s
);
9380 check_absolute_expr (ip
, &imm_expr
);
9381 if ((unsigned long) imm_expr
.X_add_number
> OP_MASK_CODE20
)
9382 as_warn (_("Code for %s not in range 0..1048575 (%lu)"),
9384 (unsigned long) imm_expr
.X_add_number
);
9385 INSERT_OPERAND (CODE20
, *ip
, imm_expr
.X_add_number
);
9386 imm_expr
.X_op
= O_absent
;
9390 case 'C': /* Coprocessor code */
9391 my_getExpression (&imm_expr
, s
);
9392 check_absolute_expr (ip
, &imm_expr
);
9393 if ((unsigned long) imm_expr
.X_add_number
> OP_MASK_COPZ
)
9395 as_warn (_("Coproccesor code > 25 bits (%lu)"),
9396 (unsigned long) imm_expr
.X_add_number
);
9397 imm_expr
.X_add_number
&= OP_MASK_COPZ
;
9399 INSERT_OPERAND (COPZ
, *ip
, imm_expr
.X_add_number
);
9400 imm_expr
.X_op
= O_absent
;
9404 case 'J': /* 19-bit wait code. */
9405 my_getExpression (&imm_expr
, s
);
9406 check_absolute_expr (ip
, &imm_expr
);
9407 if ((unsigned long) imm_expr
.X_add_number
> OP_MASK_CODE19
)
9409 as_warn (_("Illegal 19-bit code (%lu)"),
9410 (unsigned long) imm_expr
.X_add_number
);
9411 imm_expr
.X_add_number
&= OP_MASK_CODE19
;
9413 INSERT_OPERAND (CODE19
, *ip
, imm_expr
.X_add_number
);
9414 imm_expr
.X_op
= O_absent
;
9418 case 'P': /* Performance register. */
9419 my_getExpression (&imm_expr
, s
);
9420 check_absolute_expr (ip
, &imm_expr
);
9421 if (imm_expr
.X_add_number
!= 0 && imm_expr
.X_add_number
!= 1)
9422 as_warn (_("Invalid performance register (%lu)"),
9423 (unsigned long) imm_expr
.X_add_number
);
9424 INSERT_OPERAND (PERFREG
, *ip
, imm_expr
.X_add_number
);
9425 imm_expr
.X_op
= O_absent
;
9429 case 'G': /* Coprocessor destination register. */
9430 if (((ip
->insn_opcode
>> OP_SH_OP
) & OP_MASK_OP
) == OP_OP_COP0
)
9431 ok
= reg_lookup (&s
, RTYPE_NUM
| RTYPE_CP0
, ®no
);
9433 ok
= reg_lookup (&s
, RTYPE_NUM
| RTYPE_GP
, ®no
);
9434 INSERT_OPERAND (RD
, *ip
, regno
);
9443 case 'b': /* base register */
9444 case 'd': /* destination register */
9445 case 's': /* source register */
9446 case 't': /* target register */
9447 case 'r': /* both target and source */
9448 case 'v': /* both dest and source */
9449 case 'w': /* both dest and target */
9450 case 'E': /* coprocessor target register */
9451 case 'K': /* 'rdhwr' destination register */
9452 case 'x': /* ignore register name */
9453 case 'z': /* must be zero register */
9454 case 'U': /* destination register (clo/clz). */
9455 case 'g': /* coprocessor destination register */
9457 if (*args
== 'E' || *args
== 'K')
9458 ok
= reg_lookup (&s
, RTYPE_NUM
, ®no
);
9461 ok
= reg_lookup (&s
, RTYPE_NUM
| RTYPE_GP
, ®no
);
9462 if (regno
== AT
&& mips_opts
.at
)
9464 if (mips_opts
.at
== ATREG
)
9465 as_warn (_("used $at without \".set noat\""));
9467 as_warn (_("used $%u with \".set at=$%u\""),
9468 regno
, mips_opts
.at
);
9478 if (c
== 'r' || c
== 'v' || c
== 'w')
9485 /* 'z' only matches $0. */
9486 if (c
== 'z' && regno
!= 0)
9489 if (c
== 's' && !strncmp (ip
->insn_mo
->name
, "jalr", 4))
9491 if (regno
== lastregno
)
9493 insn_error
= _("source and destination must be different");
9496 if (regno
== 31 && lastregno
== 0xffffffff)
9498 insn_error
= _("a destination register must be supplied");
9502 /* Now that we have assembled one operand, we use the args string
9503 * to figure out where it goes in the instruction. */
9510 INSERT_OPERAND (RS
, *ip
, regno
);
9516 INSERT_OPERAND (RD
, *ip
, regno
);
9519 INSERT_OPERAND (RD
, *ip
, regno
);
9520 INSERT_OPERAND (RT
, *ip
, regno
);
9525 INSERT_OPERAND (RT
, *ip
, regno
);
9528 /* This case exists because on the r3000 trunc
9529 expands into a macro which requires a gp
9530 register. On the r6000 or r4000 it is
9531 assembled into a single instruction which
9532 ignores the register. Thus the insn version
9533 is MIPS_ISA2 and uses 'x', and the macro
9534 version is MIPS_ISA1 and uses 't'. */
9537 /* This case is for the div instruction, which
9538 acts differently if the destination argument
9539 is $0. This only matches $0, and is checked
9540 outside the switch. */
9543 /* Itbl operand; not yet implemented. FIXME ?? */
9545 /* What about all other operands like 'i', which
9546 can be specified in the opcode table? */
9555 INSERT_OPERAND (RS
, *ip
, lastregno
);
9558 INSERT_OPERAND (RT
, *ip
, lastregno
);
9563 case 'O': /* MDMX alignment immediate constant. */
9564 my_getExpression (&imm_expr
, s
);
9565 check_absolute_expr (ip
, &imm_expr
);
9566 if ((unsigned long) imm_expr
.X_add_number
> OP_MASK_ALN
)
9567 as_warn (_("Improper align amount (%ld), using low bits"),
9568 (long) imm_expr
.X_add_number
);
9569 INSERT_OPERAND (ALN
, *ip
, imm_expr
.X_add_number
);
9570 imm_expr
.X_op
= O_absent
;
9574 case 'Q': /* MDMX vector, element sel, or const. */
9577 /* MDMX Immediate. */
9578 my_getExpression (&imm_expr
, s
);
9579 check_absolute_expr (ip
, &imm_expr
);
9580 if ((unsigned long) imm_expr
.X_add_number
> OP_MASK_FT
)
9581 as_warn (_("Invalid MDMX Immediate (%ld)"),
9582 (long) imm_expr
.X_add_number
);
9583 INSERT_OPERAND (FT
, *ip
, imm_expr
.X_add_number
);
9584 if (ip
->insn_opcode
& (OP_MASK_VSEL
<< OP_SH_VSEL
))
9585 ip
->insn_opcode
|= MDMX_FMTSEL_IMM_QH
<< OP_SH_VSEL
;
9587 ip
->insn_opcode
|= MDMX_FMTSEL_IMM_OB
<< OP_SH_VSEL
;
9588 imm_expr
.X_op
= O_absent
;
9592 /* Not MDMX Immediate. Fall through. */
9593 case 'X': /* MDMX destination register. */
9594 case 'Y': /* MDMX source register. */
9595 case 'Z': /* MDMX target register. */
9597 case 'D': /* floating point destination register */
9598 case 'S': /* floating point source register */
9599 case 'T': /* floating point target register */
9600 case 'R': /* floating point source register */
9605 || (mips_opts
.ase_mdmx
9606 && (ip
->insn_mo
->pinfo
& FP_D
)
9607 && (ip
->insn_mo
->pinfo
& (INSN_COPROC_MOVE_DELAY
9608 | INSN_COPROC_MEMORY_DELAY
9609 | INSN_LOAD_COPROC_DELAY
9610 | INSN_LOAD_MEMORY_DELAY
9611 | INSN_STORE_MEMORY
))))
9614 if (reg_lookup (&s
, rtype
, ®no
))
9616 if ((regno
& 1) != 0
9618 && ! mips_oddfpreg_ok (ip
->insn_mo
, argnum
))
9619 as_warn (_("Float register should be even, was %d"),
9627 if (c
== 'V' || c
== 'W')
9638 INSERT_OPERAND (FD
, *ip
, regno
);
9643 INSERT_OPERAND (FS
, *ip
, regno
);
9646 /* This is like 'Z', but also needs to fix the MDMX
9647 vector/scalar select bits. Note that the
9648 scalar immediate case is handled above. */
9651 int is_qh
= (ip
->insn_opcode
& (1 << OP_SH_VSEL
));
9652 int max_el
= (is_qh
? 3 : 7);
9654 my_getExpression(&imm_expr
, s
);
9655 check_absolute_expr (ip
, &imm_expr
);
9657 if (imm_expr
.X_add_number
> max_el
)
9658 as_bad (_("Bad element selector %ld"),
9659 (long) imm_expr
.X_add_number
);
9660 imm_expr
.X_add_number
&= max_el
;
9661 ip
->insn_opcode
|= (imm_expr
.X_add_number
9664 imm_expr
.X_op
= O_absent
;
9666 as_warn (_("Expecting ']' found '%s'"), s
);
9672 if (ip
->insn_opcode
& (OP_MASK_VSEL
<< OP_SH_VSEL
))
9673 ip
->insn_opcode
|= (MDMX_FMTSEL_VEC_QH
9676 ip
->insn_opcode
|= (MDMX_FMTSEL_VEC_OB
<<
9683 INSERT_OPERAND (FT
, *ip
, regno
);
9686 INSERT_OPERAND (FR
, *ip
, regno
);
9696 INSERT_OPERAND (FS
, *ip
, lastregno
);
9699 INSERT_OPERAND (FT
, *ip
, lastregno
);
9705 my_getExpression (&imm_expr
, s
);
9706 if (imm_expr
.X_op
!= O_big
9707 && imm_expr
.X_op
!= O_constant
)
9708 insn_error
= _("absolute expression required");
9709 if (HAVE_32BIT_GPRS
)
9710 normalize_constant_expr (&imm_expr
);
9715 my_getExpression (&offset_expr
, s
);
9716 normalize_address_expr (&offset_expr
);
9717 *imm_reloc
= BFD_RELOC_32
;
9730 unsigned char temp
[8];
9732 unsigned int length
;
9737 /* These only appear as the last operand in an
9738 instruction, and every instruction that accepts
9739 them in any variant accepts them in all variants.
9740 This means we don't have to worry about backing out
9741 any changes if the instruction does not match.
9743 The difference between them is the size of the
9744 floating point constant and where it goes. For 'F'
9745 and 'L' the constant is 64 bits; for 'f' and 'l' it
9746 is 32 bits. Where the constant is placed is based
9747 on how the MIPS assembler does things:
9750 f -- immediate value
9753 The .lit4 and .lit8 sections are only used if
9754 permitted by the -G argument.
9756 The code below needs to know whether the target register
9757 is 32 or 64 bits wide. It relies on the fact 'f' and
9758 'F' are used with GPR-based instructions and 'l' and
9759 'L' are used with FPR-based instructions. */
9761 f64
= *args
== 'F' || *args
== 'L';
9762 using_gprs
= *args
== 'F' || *args
== 'f';
9764 save_in
= input_line_pointer
;
9765 input_line_pointer
= s
;
9766 err
= md_atof (f64
? 'd' : 'f', (char *) temp
, &len
);
9768 s
= input_line_pointer
;
9769 input_line_pointer
= save_in
;
9770 if (err
!= NULL
&& *err
!= '\0')
9772 as_bad (_("Bad floating point constant: %s"), err
);
9773 memset (temp
, '\0', sizeof temp
);
9774 length
= f64
? 8 : 4;
9777 gas_assert (length
== (unsigned) (f64
? 8 : 4));
9781 && (g_switch_value
< 4
9782 || (temp
[0] == 0 && temp
[1] == 0)
9783 || (temp
[2] == 0 && temp
[3] == 0))))
9785 imm_expr
.X_op
= O_constant
;
9786 if (! target_big_endian
)
9787 imm_expr
.X_add_number
= bfd_getl32 (temp
);
9789 imm_expr
.X_add_number
= bfd_getb32 (temp
);
9792 && ! mips_disable_float_construction
9793 /* Constants can only be constructed in GPRs and
9794 copied to FPRs if the GPRs are at least as wide
9795 as the FPRs. Force the constant into memory if
9796 we are using 64-bit FPRs but the GPRs are only
9799 || ! (HAVE_64BIT_FPRS
&& HAVE_32BIT_GPRS
))
9800 && ((temp
[0] == 0 && temp
[1] == 0)
9801 || (temp
[2] == 0 && temp
[3] == 0))
9802 && ((temp
[4] == 0 && temp
[5] == 0)
9803 || (temp
[6] == 0 && temp
[7] == 0)))
9805 /* The value is simple enough to load with a couple of
9806 instructions. If using 32-bit registers, set
9807 imm_expr to the high order 32 bits and offset_expr to
9808 the low order 32 bits. Otherwise, set imm_expr to
9809 the entire 64 bit constant. */
9810 if (using_gprs
? HAVE_32BIT_GPRS
: HAVE_32BIT_FPRS
)
9812 imm_expr
.X_op
= O_constant
;
9813 offset_expr
.X_op
= O_constant
;
9814 if (! target_big_endian
)
9816 imm_expr
.X_add_number
= bfd_getl32 (temp
+ 4);
9817 offset_expr
.X_add_number
= bfd_getl32 (temp
);
9821 imm_expr
.X_add_number
= bfd_getb32 (temp
);
9822 offset_expr
.X_add_number
= bfd_getb32 (temp
+ 4);
9824 if (offset_expr
.X_add_number
== 0)
9825 offset_expr
.X_op
= O_absent
;
9827 else if (sizeof (imm_expr
.X_add_number
) > 4)
9829 imm_expr
.X_op
= O_constant
;
9830 if (! target_big_endian
)
9831 imm_expr
.X_add_number
= bfd_getl64 (temp
);
9833 imm_expr
.X_add_number
= bfd_getb64 (temp
);
9837 imm_expr
.X_op
= O_big
;
9838 imm_expr
.X_add_number
= 4;
9839 if (! target_big_endian
)
9841 generic_bignum
[0] = bfd_getl16 (temp
);
9842 generic_bignum
[1] = bfd_getl16 (temp
+ 2);
9843 generic_bignum
[2] = bfd_getl16 (temp
+ 4);
9844 generic_bignum
[3] = bfd_getl16 (temp
+ 6);
9848 generic_bignum
[0] = bfd_getb16 (temp
+ 6);
9849 generic_bignum
[1] = bfd_getb16 (temp
+ 4);
9850 generic_bignum
[2] = bfd_getb16 (temp
+ 2);
9851 generic_bignum
[3] = bfd_getb16 (temp
);
9857 const char *newname
;
9860 /* Switch to the right section. */
9862 subseg
= now_subseg
;
9865 default: /* unused default case avoids warnings. */
9867 newname
= RDATA_SECTION_NAME
;
9868 if (g_switch_value
>= 8)
9872 newname
= RDATA_SECTION_NAME
;
9875 gas_assert (g_switch_value
>= 4);
9879 new_seg
= subseg_new (newname
, (subsegT
) 0);
9881 bfd_set_section_flags (stdoutput
, new_seg
,
9886 frag_align (*args
== 'l' ? 2 : 3, 0, 0);
9887 if (IS_ELF
&& strncmp (TARGET_OS
, "elf", 3) != 0)
9888 record_alignment (new_seg
, 4);
9890 record_alignment (new_seg
, *args
== 'l' ? 2 : 3);
9892 as_bad (_("Can't use floating point insn in this section"));
9894 /* Set the argument to the current address in the
9896 offset_expr
.X_op
= O_symbol
;
9897 offset_expr
.X_add_symbol
=
9898 symbol_new ("L0\001", now_seg
,
9899 (valueT
) frag_now_fix (), frag_now
);
9900 offset_expr
.X_add_number
= 0;
9902 /* Put the floating point number into the section. */
9903 p
= frag_more ((int) length
);
9904 memcpy (p
, temp
, length
);
9906 /* Switch back to the original section. */
9907 subseg_set (seg
, subseg
);
9912 case 'i': /* 16 bit unsigned immediate */
9913 case 'j': /* 16 bit signed immediate */
9914 *imm_reloc
= BFD_RELOC_LO16
;
9915 if (my_getSmallExpression (&imm_expr
, imm_reloc
, s
) == 0)
9918 offsetT minval
, maxval
;
9920 more
= (insn
+ 1 < &mips_opcodes
[NUMOPCODES
]
9921 && strcmp (insn
->name
, insn
[1].name
) == 0);
9923 /* If the expression was written as an unsigned number,
9924 only treat it as signed if there are no more
9928 && sizeof (imm_expr
.X_add_number
) <= 4
9929 && imm_expr
.X_op
== O_constant
9930 && imm_expr
.X_add_number
< 0
9931 && imm_expr
.X_unsigned
9935 /* For compatibility with older assemblers, we accept
9936 0x8000-0xffff as signed 16-bit numbers when only
9937 signed numbers are allowed. */
9939 minval
= 0, maxval
= 0xffff;
9941 minval
= -0x8000, maxval
= 0x7fff;
9943 minval
= -0x8000, maxval
= 0xffff;
9945 if (imm_expr
.X_op
!= O_constant
9946 || imm_expr
.X_add_number
< minval
9947 || imm_expr
.X_add_number
> maxval
)
9951 if (imm_expr
.X_op
== O_constant
9952 || imm_expr
.X_op
== O_big
)
9953 as_bad (_("expression out of range"));
9959 case 'o': /* 16 bit offset */
9960 /* Check whether there is only a single bracketed expression
9961 left. If so, it must be the base register and the
9962 constant must be zero. */
9963 if (*s
== '(' && strchr (s
+ 1, '(') == 0)
9965 offset_expr
.X_op
= O_constant
;
9966 offset_expr
.X_add_number
= 0;
9970 /* If this value won't fit into a 16 bit offset, then go
9971 find a macro that will generate the 32 bit offset
9973 if (my_getSmallExpression (&offset_expr
, offset_reloc
, s
) == 0
9974 && (offset_expr
.X_op
!= O_constant
9975 || offset_expr
.X_add_number
>= 0x8000
9976 || offset_expr
.X_add_number
< -0x8000))
9982 case 'p': /* pc relative offset */
9983 *offset_reloc
= BFD_RELOC_16_PCREL_S2
;
9984 my_getExpression (&offset_expr
, s
);
9988 case 'u': /* upper 16 bits */
9989 if (my_getSmallExpression (&imm_expr
, imm_reloc
, s
) == 0
9990 && imm_expr
.X_op
== O_constant
9991 && (imm_expr
.X_add_number
< 0
9992 || imm_expr
.X_add_number
>= 0x10000))
9993 as_bad (_("lui expression not in range 0..65535"));
9997 case 'a': /* 26 bit address */
9998 my_getExpression (&offset_expr
, s
);
10000 *offset_reloc
= BFD_RELOC_MIPS_JMP
;
10003 case 'N': /* 3 bit branch condition code */
10004 case 'M': /* 3 bit compare condition code */
10006 if (ip
->insn_mo
->pinfo
& (FP_D
| FP_S
))
10007 rtype
|= RTYPE_FCC
;
10008 if (!reg_lookup (&s
, rtype
, ®no
))
10010 if ((strcmp(str
+ strlen(str
) - 3, ".ps") == 0
10011 || strcmp(str
+ strlen(str
) - 5, "any2f") == 0
10012 || strcmp(str
+ strlen(str
) - 5, "any2t") == 0)
10013 && (regno
& 1) != 0)
10014 as_warn (_("Condition code register should be even for %s, was %d"),
10016 if ((strcmp(str
+ strlen(str
) - 5, "any4f") == 0
10017 || strcmp(str
+ strlen(str
) - 5, "any4t") == 0)
10018 && (regno
& 3) != 0)
10019 as_warn (_("Condition code register should be 0 or 4 for %s, was %d"),
10022 INSERT_OPERAND (BCC
, *ip
, regno
);
10024 INSERT_OPERAND (CCC
, *ip
, regno
);
10028 if (s
[0] == '0' && (s
[1] == 'x' || s
[1] == 'X'))
10039 while (ISDIGIT (*s
));
10042 c
= 8; /* Invalid sel value. */
10045 as_bad (_("invalid coprocessor sub-selection value (0-7)"));
10046 ip
->insn_opcode
|= c
;
10050 /* Must be at least one digit. */
10051 my_getExpression (&imm_expr
, s
);
10052 check_absolute_expr (ip
, &imm_expr
);
10054 if ((unsigned long) imm_expr
.X_add_number
10055 > (unsigned long) OP_MASK_VECBYTE
)
10057 as_bad (_("bad byte vector index (%ld)"),
10058 (long) imm_expr
.X_add_number
);
10059 imm_expr
.X_add_number
= 0;
10062 INSERT_OPERAND (VECBYTE
, *ip
, imm_expr
.X_add_number
);
10063 imm_expr
.X_op
= O_absent
;
10068 my_getExpression (&imm_expr
, s
);
10069 check_absolute_expr (ip
, &imm_expr
);
10071 if ((unsigned long) imm_expr
.X_add_number
10072 > (unsigned long) OP_MASK_VECALIGN
)
10074 as_bad (_("bad byte vector index (%ld)"),
10075 (long) imm_expr
.X_add_number
);
10076 imm_expr
.X_add_number
= 0;
10079 INSERT_OPERAND (VECALIGN
, *ip
, imm_expr
.X_add_number
);
10080 imm_expr
.X_op
= O_absent
;
10085 as_bad (_("bad char = '%c'\n"), *args
);
10090 /* Args don't match. */
10091 if (insn
+ 1 < &mips_opcodes
[NUMOPCODES
] &&
10092 !strcmp (insn
->name
, insn
[1].name
))
10096 insn_error
= _("illegal operands");
10100 *(--argsStart
) = save_c
;
10101 insn_error
= _("illegal operands");
10106 #define SKIP_SPACE_TABS(S) { while (*(S) == ' ' || *(S) == '\t') ++(S); }
10108 /* This routine assembles an instruction into its binary format when
10109 assembling for the mips16. As a side effect, it sets one of the
10110 global variables imm_reloc or offset_reloc to the type of
10111 relocation to do if one of the operands is an address expression.
10112 It also sets mips16_small and mips16_ext if the user explicitly
10113 requested a small or extended instruction. */
10116 mips16_ip (char *str
, struct mips_cl_insn
*ip
)
10120 struct mips_opcode
*insn
;
10122 unsigned int regno
;
10123 unsigned int lastregno
= 0;
10129 mips16_small
= FALSE
;
10130 mips16_ext
= FALSE
;
10132 for (s
= str
; ISLOWER (*s
); ++s
)
10144 if (s
[1] == 't' && s
[2] == ' ')
10147 mips16_small
= TRUE
;
10151 else if (s
[1] == 'e' && s
[2] == ' ')
10158 /* Fall through. */
10160 insn_error
= _("unknown opcode");
10164 if (mips_opts
.noautoextend
&& ! mips16_ext
)
10165 mips16_small
= TRUE
;
10167 if ((insn
= (struct mips_opcode
*) hash_find (mips16_op_hash
, str
)) == NULL
)
10169 insn_error
= _("unrecognized opcode");
10178 gas_assert (strcmp (insn
->name
, str
) == 0);
10180 ok
= is_opcode_valid_16 (insn
);
10183 if (insn
+ 1 < &mips16_opcodes
[bfd_mips16_num_opcodes
]
10184 && strcmp (insn
->name
, insn
[1].name
) == 0)
10193 static char buf
[100];
10195 _("opcode not supported on this processor: %s (%s)"),
10196 mips_cpu_info_from_arch (mips_opts
.arch
)->name
,
10197 mips_cpu_info_from_isa (mips_opts
.isa
)->name
);
10204 create_insn (ip
, insn
);
10205 imm_expr
.X_op
= O_absent
;
10206 imm_reloc
[0] = BFD_RELOC_UNUSED
;
10207 imm_reloc
[1] = BFD_RELOC_UNUSED
;
10208 imm_reloc
[2] = BFD_RELOC_UNUSED
;
10209 imm2_expr
.X_op
= O_absent
;
10210 offset_expr
.X_op
= O_absent
;
10211 offset_reloc
[0] = BFD_RELOC_UNUSED
;
10212 offset_reloc
[1] = BFD_RELOC_UNUSED
;
10213 offset_reloc
[2] = BFD_RELOC_UNUSED
;
10214 for (args
= insn
->args
; 1; ++args
)
10221 /* In this switch statement we call break if we did not find
10222 a match, continue if we did find a match, or return if we
10231 /* Stuff the immediate value in now, if we can. */
10232 if (imm_expr
.X_op
== O_constant
10233 && *imm_reloc
> BFD_RELOC_UNUSED
10234 && *imm_reloc
!= BFD_RELOC_MIPS16_GOT16
10235 && *imm_reloc
!= BFD_RELOC_MIPS16_CALL16
10236 && insn
->pinfo
!= INSN_MACRO
)
10240 switch (*offset_reloc
)
10242 case BFD_RELOC_MIPS16_HI16_S
:
10243 tmp
= (imm_expr
.X_add_number
+ 0x8000) >> 16;
10246 case BFD_RELOC_MIPS16_HI16
:
10247 tmp
= imm_expr
.X_add_number
>> 16;
10250 case BFD_RELOC_MIPS16_LO16
:
10251 tmp
= ((imm_expr
.X_add_number
+ 0x8000) & 0xffff)
10255 case BFD_RELOC_UNUSED
:
10256 tmp
= imm_expr
.X_add_number
;
10262 *offset_reloc
= BFD_RELOC_UNUSED
;
10264 mips16_immed (NULL
, 0, *imm_reloc
- BFD_RELOC_UNUSED
,
10265 tmp
, TRUE
, mips16_small
,
10266 mips16_ext
, &ip
->insn_opcode
,
10267 &ip
->use_extend
, &ip
->extend
);
10268 imm_expr
.X_op
= O_absent
;
10269 *imm_reloc
= BFD_RELOC_UNUSED
;
10283 MIPS16_INSERT_OPERAND (RX
, *ip
, lastregno
);
10286 MIPS16_INSERT_OPERAND (RY
, *ip
, lastregno
);
10302 MIPS16_INSERT_OPERAND (RX
, *ip
, lastregno
);
10304 MIPS16_INSERT_OPERAND (RY
, *ip
, lastregno
);
10308 /* Fall through. */
10319 if (!reg_lookup (&s
, RTYPE_NUM
| RTYPE_GP
, ®no
))
10321 if (c
== 'v' || c
== 'w')
10324 MIPS16_INSERT_OPERAND (RX
, *ip
, lastregno
);
10326 MIPS16_INSERT_OPERAND (RY
, *ip
, lastregno
);
10337 if (c
== 'v' || c
== 'w')
10339 regno
= mips16_to_32_reg_map
[lastregno
];
10353 regno
= mips32_to_16_reg_map
[regno
];
10358 regno
= ILLEGAL_REG
;
10363 regno
= ILLEGAL_REG
;
10368 regno
= ILLEGAL_REG
;
10373 if (regno
== AT
&& mips_opts
.at
)
10375 if (mips_opts
.at
== ATREG
)
10376 as_warn (_("used $at without \".set noat\""));
10378 as_warn (_("used $%u with \".set at=$%u\""),
10379 regno
, mips_opts
.at
);
10387 if (regno
== ILLEGAL_REG
)
10394 MIPS16_INSERT_OPERAND (RX
, *ip
, regno
);
10398 MIPS16_INSERT_OPERAND (RY
, *ip
, regno
);
10401 MIPS16_INSERT_OPERAND (RZ
, *ip
, regno
);
10404 MIPS16_INSERT_OPERAND (MOVE32Z
, *ip
, regno
);
10410 MIPS16_INSERT_OPERAND (REGR32
, *ip
, regno
);
10413 regno
= ((regno
& 7) << 2) | ((regno
& 0x18) >> 3);
10414 MIPS16_INSERT_OPERAND (REG32R
, *ip
, regno
);
10424 if (strncmp (s
, "$pc", 3) == 0)
10441 i
= my_getSmallExpression (&imm_expr
, imm_reloc
, s
);
10444 if (imm_expr
.X_op
!= O_constant
)
10447 ip
->use_extend
= TRUE
;
10452 /* We need to relax this instruction. */
10453 *offset_reloc
= *imm_reloc
;
10454 *imm_reloc
= (int) BFD_RELOC_UNUSED
+ c
;
10459 *imm_reloc
= BFD_RELOC_UNUSED
;
10460 /* Fall through. */
10467 my_getExpression (&imm_expr
, s
);
10468 if (imm_expr
.X_op
== O_register
)
10470 /* What we thought was an expression turned out to
10473 if (s
[0] == '(' && args
[1] == '(')
10475 /* It looks like the expression was omitted
10476 before a register indirection, which means
10477 that the expression is implicitly zero. We
10478 still set up imm_expr, so that we handle
10479 explicit extensions correctly. */
10480 imm_expr
.X_op
= O_constant
;
10481 imm_expr
.X_add_number
= 0;
10482 *imm_reloc
= (int) BFD_RELOC_UNUSED
+ c
;
10489 /* We need to relax this instruction. */
10490 *imm_reloc
= (int) BFD_RELOC_UNUSED
+ c
;
10499 /* We use offset_reloc rather than imm_reloc for the PC
10500 relative operands. This lets macros with both
10501 immediate and address operands work correctly. */
10502 my_getExpression (&offset_expr
, s
);
10504 if (offset_expr
.X_op
== O_register
)
10507 /* We need to relax this instruction. */
10508 *offset_reloc
= (int) BFD_RELOC_UNUSED
+ c
;
10512 case '6': /* break code */
10513 my_getExpression (&imm_expr
, s
);
10514 check_absolute_expr (ip
, &imm_expr
);
10515 if ((unsigned long) imm_expr
.X_add_number
> 63)
10516 as_warn (_("Invalid value for `%s' (%lu)"),
10518 (unsigned long) imm_expr
.X_add_number
);
10519 MIPS16_INSERT_OPERAND (IMM6
, *ip
, imm_expr
.X_add_number
);
10520 imm_expr
.X_op
= O_absent
;
10524 case 'a': /* 26 bit address */
10525 my_getExpression (&offset_expr
, s
);
10527 *offset_reloc
= BFD_RELOC_MIPS16_JMP
;
10528 ip
->insn_opcode
<<= 16;
10531 case 'l': /* register list for entry macro */
10532 case 'L': /* register list for exit macro */
10542 unsigned int freg
, reg1
, reg2
;
10544 while (*s
== ' ' || *s
== ',')
10546 if (reg_lookup (&s
, RTYPE_GP
| RTYPE_NUM
, ®1
))
10548 else if (reg_lookup (&s
, RTYPE_FPU
, ®1
))
10552 as_bad (_("can't parse register list"));
10562 if (!reg_lookup (&s
, freg
? RTYPE_FPU
10563 : (RTYPE_GP
| RTYPE_NUM
), ®2
))
10565 as_bad (_("invalid register list"));
10569 if (freg
&& reg1
== 0 && reg2
== 0 && c
== 'L')
10571 mask
&= ~ (7 << 3);
10574 else if (freg
&& reg1
== 0 && reg2
== 1 && c
== 'L')
10576 mask
&= ~ (7 << 3);
10579 else if (reg1
== 4 && reg2
>= 4 && reg2
<= 7 && c
!= 'L')
10580 mask
|= (reg2
- 3) << 3;
10581 else if (reg1
== 16 && reg2
>= 16 && reg2
<= 17)
10582 mask
|= (reg2
- 15) << 1;
10583 else if (reg1
== RA
&& reg2
== RA
)
10587 as_bad (_("invalid register list"));
10591 /* The mask is filled in in the opcode table for the
10592 benefit of the disassembler. We remove it before
10593 applying the actual mask. */
10594 ip
->insn_opcode
&= ~ ((7 << 3) << MIPS16OP_SH_IMM6
);
10595 ip
->insn_opcode
|= mask
<< MIPS16OP_SH_IMM6
;
10599 case 'm': /* Register list for save insn. */
10600 case 'M': /* Register list for restore insn. */
10603 int framesz
= 0, seen_framesz
= 0;
10604 int args
= 0, statics
= 0, sregs
= 0;
10608 unsigned int reg1
, reg2
;
10610 SKIP_SPACE_TABS (s
);
10613 SKIP_SPACE_TABS (s
);
10615 my_getExpression (&imm_expr
, s
);
10616 if (imm_expr
.X_op
== O_constant
)
10618 /* Handle the frame size. */
10621 as_bad (_("more than one frame size in list"));
10625 framesz
= imm_expr
.X_add_number
;
10626 imm_expr
.X_op
= O_absent
;
10631 if (! reg_lookup (&s
, RTYPE_GP
| RTYPE_NUM
, ®1
))
10633 as_bad (_("can't parse register list"));
10645 if (! reg_lookup (&s
, RTYPE_GP
| RTYPE_NUM
, ®2
)
10648 as_bad (_("can't parse register list"));
10653 while (reg1
<= reg2
)
10655 if (reg1
>= 4 && reg1
<= 7)
10659 args
|= 1 << (reg1
- 4);
10661 /* statics $a0-$a3 */
10662 statics
|= 1 << (reg1
- 4);
10664 else if ((reg1
>= 16 && reg1
<= 23) || reg1
== 30)
10667 sregs
|= 1 << ((reg1
== 30) ? 8 : (reg1
- 16));
10669 else if (reg1
== 31)
10671 /* Add $ra to insn. */
10676 as_bad (_("unexpected register in list"));
10684 /* Encode args/statics combination. */
10685 if (args
& statics
)
10686 as_bad (_("arg/static registers overlap"));
10687 else if (args
== 0xf)
10688 /* All $a0-$a3 are args. */
10689 opcode
|= MIPS16_ALL_ARGS
<< 16;
10690 else if (statics
== 0xf)
10691 /* All $a0-$a3 are statics. */
10692 opcode
|= MIPS16_ALL_STATICS
<< 16;
10695 int narg
= 0, nstat
= 0;
10697 /* Count arg registers. */
10704 as_bad (_("invalid arg register list"));
10706 /* Count static registers. */
10707 while (statics
& 0x8)
10709 statics
= (statics
<< 1) & 0xf;
10713 as_bad (_("invalid static register list"));
10715 /* Encode args/statics. */
10716 opcode
|= ((narg
<< 2) | nstat
) << 16;
10719 /* Encode $s0/$s1. */
10720 if (sregs
& (1 << 0)) /* $s0 */
10722 if (sregs
& (1 << 1)) /* $s1 */
10728 /* Count regs $s2-$s8. */
10736 as_bad (_("invalid static register list"));
10737 /* Encode $s2-$s8. */
10738 opcode
|= nsreg
<< 24;
10741 /* Encode frame size. */
10743 as_bad (_("missing frame size"));
10744 else if ((framesz
& 7) != 0 || framesz
< 0
10745 || framesz
> 0xff * 8)
10746 as_bad (_("invalid frame size"));
10747 else if (framesz
!= 128 || (opcode
>> 16) != 0)
10750 opcode
|= (((framesz
& 0xf0) << 16)
10751 | (framesz
& 0x0f));
10754 /* Finally build the instruction. */
10755 if ((opcode
>> 16) != 0 || framesz
== 0)
10757 ip
->use_extend
= TRUE
;
10758 ip
->extend
= opcode
>> 16;
10760 ip
->insn_opcode
|= opcode
& 0x7f;
10764 case 'e': /* extend code */
10765 my_getExpression (&imm_expr
, s
);
10766 check_absolute_expr (ip
, &imm_expr
);
10767 if ((unsigned long) imm_expr
.X_add_number
> 0x7ff)
10769 as_warn (_("Invalid value for `%s' (%lu)"),
10771 (unsigned long) imm_expr
.X_add_number
);
10772 imm_expr
.X_add_number
&= 0x7ff;
10774 ip
->insn_opcode
|= imm_expr
.X_add_number
;
10775 imm_expr
.X_op
= O_absent
;
10785 /* Args don't match. */
10786 if (insn
+ 1 < &mips16_opcodes
[bfd_mips16_num_opcodes
] &&
10787 strcmp (insn
->name
, insn
[1].name
) == 0)
10794 insn_error
= _("illegal operands");
10800 /* This structure holds information we know about a mips16 immediate
10803 struct mips16_immed_operand
10805 /* The type code used in the argument string in the opcode table. */
10807 /* The number of bits in the short form of the opcode. */
10809 /* The number of bits in the extended form of the opcode. */
10811 /* The amount by which the short form is shifted when it is used;
10812 for example, the sw instruction has a shift count of 2. */
10814 /* The amount by which the short form is shifted when it is stored
10815 into the instruction code. */
10817 /* Non-zero if the short form is unsigned. */
10819 /* Non-zero if the extended form is unsigned. */
10821 /* Non-zero if the value is PC relative. */
10825 /* The mips16 immediate operand types. */
10827 static const struct mips16_immed_operand mips16_immed_operands
[] =
10829 { '<', 3, 5, 0, MIPS16OP_SH_RZ
, 1, 1, 0 },
10830 { '>', 3, 5, 0, MIPS16OP_SH_RX
, 1, 1, 0 },
10831 { '[', 3, 6, 0, MIPS16OP_SH_RZ
, 1, 1, 0 },
10832 { ']', 3, 6, 0, MIPS16OP_SH_RX
, 1, 1, 0 },
10833 { '4', 4, 15, 0, MIPS16OP_SH_IMM4
, 0, 0, 0 },
10834 { '5', 5, 16, 0, MIPS16OP_SH_IMM5
, 1, 0, 0 },
10835 { 'H', 5, 16, 1, MIPS16OP_SH_IMM5
, 1, 0, 0 },
10836 { 'W', 5, 16, 2, MIPS16OP_SH_IMM5
, 1, 0, 0 },
10837 { 'D', 5, 16, 3, MIPS16OP_SH_IMM5
, 1, 0, 0 },
10838 { 'j', 5, 16, 0, MIPS16OP_SH_IMM5
, 0, 0, 0 },
10839 { '8', 8, 16, 0, MIPS16OP_SH_IMM8
, 1, 0, 0 },
10840 { 'V', 8, 16, 2, MIPS16OP_SH_IMM8
, 1, 0, 0 },
10841 { 'C', 8, 16, 3, MIPS16OP_SH_IMM8
, 1, 0, 0 },
10842 { 'U', 8, 16, 0, MIPS16OP_SH_IMM8
, 1, 1, 0 },
10843 { 'k', 8, 16, 0, MIPS16OP_SH_IMM8
, 0, 0, 0 },
10844 { 'K', 8, 16, 3, MIPS16OP_SH_IMM8
, 0, 0, 0 },
10845 { 'p', 8, 16, 0, MIPS16OP_SH_IMM8
, 0, 0, 1 },
10846 { 'q', 11, 16, 0, MIPS16OP_SH_IMM8
, 0, 0, 1 },
10847 { 'A', 8, 16, 2, MIPS16OP_SH_IMM8
, 1, 0, 1 },
10848 { 'B', 5, 16, 3, MIPS16OP_SH_IMM5
, 1, 0, 1 },
10849 { 'E', 5, 16, 2, MIPS16OP_SH_IMM5
, 1, 0, 1 }
10852 #define MIPS16_NUM_IMMED \
10853 (sizeof mips16_immed_operands / sizeof mips16_immed_operands[0])
10855 /* Handle a mips16 instruction with an immediate value. This or's the
10856 small immediate value into *INSN. It sets *USE_EXTEND to indicate
10857 whether an extended value is needed; if one is needed, it sets
10858 *EXTEND to the value. The argument type is TYPE. The value is VAL.
10859 If SMALL is true, an unextended opcode was explicitly requested.
10860 If EXT is true, an extended opcode was explicitly requested. If
10861 WARN is true, warn if EXT does not match reality. */
10864 mips16_immed (char *file
, unsigned int line
, int type
, offsetT val
,
10865 bfd_boolean warn
, bfd_boolean small
, bfd_boolean ext
,
10866 unsigned long *insn
, bfd_boolean
*use_extend
,
10867 unsigned short *extend
)
10869 const struct mips16_immed_operand
*op
;
10870 int mintiny
, maxtiny
;
10871 bfd_boolean needext
;
10873 op
= mips16_immed_operands
;
10874 while (op
->type
!= type
)
10877 gas_assert (op
< mips16_immed_operands
+ MIPS16_NUM_IMMED
);
10882 if (type
== '<' || type
== '>' || type
== '[' || type
== ']')
10885 maxtiny
= 1 << op
->nbits
;
10890 maxtiny
= (1 << op
->nbits
) - 1;
10895 mintiny
= - (1 << (op
->nbits
- 1));
10896 maxtiny
= (1 << (op
->nbits
- 1)) - 1;
10899 /* Branch offsets have an implicit 0 in the lowest bit. */
10900 if (type
== 'p' || type
== 'q')
10903 if ((val
& ((1 << op
->shift
) - 1)) != 0
10904 || val
< (mintiny
<< op
->shift
)
10905 || val
> (maxtiny
<< op
->shift
))
10910 if (warn
&& ext
&& ! needext
)
10911 as_warn_where (file
, line
,
10912 _("extended operand requested but not required"));
10913 if (small
&& needext
)
10914 as_bad_where (file
, line
, _("invalid unextended operand value"));
10916 if (small
|| (! ext
&& ! needext
))
10920 *use_extend
= FALSE
;
10921 insnval
= ((val
>> op
->shift
) & ((1 << op
->nbits
) - 1));
10922 insnval
<<= op
->op_shift
;
10927 long minext
, maxext
;
10933 maxext
= (1 << op
->extbits
) - 1;
10937 minext
= - (1 << (op
->extbits
- 1));
10938 maxext
= (1 << (op
->extbits
- 1)) - 1;
10940 if (val
< minext
|| val
> maxext
)
10941 as_bad_where (file
, line
,
10942 _("operand value out of range for instruction"));
10944 *use_extend
= TRUE
;
10945 if (op
->extbits
== 16)
10947 extval
= ((val
>> 11) & 0x1f) | (val
& 0x7e0);
10950 else if (op
->extbits
== 15)
10952 extval
= ((val
>> 11) & 0xf) | (val
& 0x7f0);
10957 extval
= ((val
& 0x1f) << 6) | (val
& 0x20);
10961 *extend
= (unsigned short) extval
;
10966 struct percent_op_match
10969 bfd_reloc_code_real_type reloc
;
10972 static const struct percent_op_match mips_percent_op
[] =
10974 {"%lo", BFD_RELOC_LO16
},
10976 {"%call_hi", BFD_RELOC_MIPS_CALL_HI16
},
10977 {"%call_lo", BFD_RELOC_MIPS_CALL_LO16
},
10978 {"%call16", BFD_RELOC_MIPS_CALL16
},
10979 {"%got_disp", BFD_RELOC_MIPS_GOT_DISP
},
10980 {"%got_page", BFD_RELOC_MIPS_GOT_PAGE
},
10981 {"%got_ofst", BFD_RELOC_MIPS_GOT_OFST
},
10982 {"%got_hi", BFD_RELOC_MIPS_GOT_HI16
},
10983 {"%got_lo", BFD_RELOC_MIPS_GOT_LO16
},
10984 {"%got", BFD_RELOC_MIPS_GOT16
},
10985 {"%gp_rel", BFD_RELOC_GPREL16
},
10986 {"%half", BFD_RELOC_16
},
10987 {"%highest", BFD_RELOC_MIPS_HIGHEST
},
10988 {"%higher", BFD_RELOC_MIPS_HIGHER
},
10989 {"%neg", BFD_RELOC_MIPS_SUB
},
10990 {"%tlsgd", BFD_RELOC_MIPS_TLS_GD
},
10991 {"%tlsldm", BFD_RELOC_MIPS_TLS_LDM
},
10992 {"%dtprel_hi", BFD_RELOC_MIPS_TLS_DTPREL_HI16
},
10993 {"%dtprel_lo", BFD_RELOC_MIPS_TLS_DTPREL_LO16
},
10994 {"%tprel_hi", BFD_RELOC_MIPS_TLS_TPREL_HI16
},
10995 {"%tprel_lo", BFD_RELOC_MIPS_TLS_TPREL_LO16
},
10996 {"%gottprel", BFD_RELOC_MIPS_TLS_GOTTPREL
},
10998 {"%hi", BFD_RELOC_HI16_S
}
11001 static const struct percent_op_match mips16_percent_op
[] =
11003 {"%lo", BFD_RELOC_MIPS16_LO16
},
11004 {"%gprel", BFD_RELOC_MIPS16_GPREL
},
11005 {"%got", BFD_RELOC_MIPS16_GOT16
},
11006 {"%call16", BFD_RELOC_MIPS16_CALL16
},
11007 {"%hi", BFD_RELOC_MIPS16_HI16_S
}
11011 /* Return true if *STR points to a relocation operator. When returning true,
11012 move *STR over the operator and store its relocation code in *RELOC.
11013 Leave both *STR and *RELOC alone when returning false. */
11016 parse_relocation (char **str
, bfd_reloc_code_real_type
*reloc
)
11018 const struct percent_op_match
*percent_op
;
11021 if (mips_opts
.mips16
)
11023 percent_op
= mips16_percent_op
;
11024 limit
= ARRAY_SIZE (mips16_percent_op
);
11028 percent_op
= mips_percent_op
;
11029 limit
= ARRAY_SIZE (mips_percent_op
);
11032 for (i
= 0; i
< limit
; i
++)
11033 if (strncasecmp (*str
, percent_op
[i
].str
, strlen (percent_op
[i
].str
)) == 0)
11035 int len
= strlen (percent_op
[i
].str
);
11037 if (!ISSPACE ((*str
)[len
]) && (*str
)[len
] != '(')
11040 *str
+= strlen (percent_op
[i
].str
);
11041 *reloc
= percent_op
[i
].reloc
;
11043 /* Check whether the output BFD supports this relocation.
11044 If not, issue an error and fall back on something safe. */
11045 if (!bfd_reloc_type_lookup (stdoutput
, percent_op
[i
].reloc
))
11047 as_bad (_("relocation %s isn't supported by the current ABI"),
11048 percent_op
[i
].str
);
11049 *reloc
= BFD_RELOC_UNUSED
;
11057 /* Parse string STR as a 16-bit relocatable operand. Store the
11058 expression in *EP and the relocations in the array starting
11059 at RELOC. Return the number of relocation operators used.
11061 On exit, EXPR_END points to the first character after the expression. */
11064 my_getSmallExpression (expressionS
*ep
, bfd_reloc_code_real_type
*reloc
,
11067 bfd_reloc_code_real_type reversed_reloc
[3];
11068 size_t reloc_index
, i
;
11069 int crux_depth
, str_depth
;
11072 /* Search for the start of the main expression, recoding relocations
11073 in REVERSED_RELOC. End the loop with CRUX pointing to the start
11074 of the main expression and with CRUX_DEPTH containing the number
11075 of open brackets at that point. */
11082 crux_depth
= str_depth
;
11084 /* Skip over whitespace and brackets, keeping count of the number
11086 while (*str
== ' ' || *str
== '\t' || *str
== '(')
11091 && reloc_index
< (HAVE_NEWABI
? 3 : 1)
11092 && parse_relocation (&str
, &reversed_reloc
[reloc_index
]));
11094 my_getExpression (ep
, crux
);
11097 /* Match every open bracket. */
11098 while (crux_depth
> 0 && (*str
== ')' || *str
== ' ' || *str
== '\t'))
11102 if (crux_depth
> 0)
11103 as_bad (_("unclosed '('"));
11107 if (reloc_index
!= 0)
11109 prev_reloc_op_frag
= frag_now
;
11110 for (i
= 0; i
< reloc_index
; i
++)
11111 reloc
[i
] = reversed_reloc
[reloc_index
- 1 - i
];
11114 return reloc_index
;
11118 my_getExpression (expressionS
*ep
, char *str
)
11123 save_in
= input_line_pointer
;
11124 input_line_pointer
= str
;
11126 expr_end
= input_line_pointer
;
11127 input_line_pointer
= save_in
;
11129 /* If we are in mips16 mode, and this is an expression based on `.',
11130 then we bump the value of the symbol by 1 since that is how other
11131 text symbols are handled. We don't bother to handle complex
11132 expressions, just `.' plus or minus a constant. */
11133 if (mips_opts
.mips16
11134 && ep
->X_op
== O_symbol
11135 && strcmp (S_GET_NAME (ep
->X_add_symbol
), FAKE_LABEL_NAME
) == 0
11136 && S_GET_SEGMENT (ep
->X_add_symbol
) == now_seg
11137 && symbol_get_frag (ep
->X_add_symbol
) == frag_now
11138 && symbol_constant_p (ep
->X_add_symbol
)
11139 && (val
= S_GET_VALUE (ep
->X_add_symbol
)) == frag_now_fix ())
11140 S_SET_VALUE (ep
->X_add_symbol
, val
+ 1);
11144 md_atof (int type
, char *litP
, int *sizeP
)
11146 return ieee_md_atof (type
, litP
, sizeP
, target_big_endian
);
11150 md_number_to_chars (char *buf
, valueT val
, int n
)
11152 if (target_big_endian
)
11153 number_to_chars_bigendian (buf
, val
, n
);
11155 number_to_chars_littleendian (buf
, val
, n
);
11159 static int support_64bit_objects(void)
11161 const char **list
, **l
;
11164 list
= bfd_target_list ();
11165 for (l
= list
; *l
!= NULL
; l
++)
11167 /* This is traditional mips */
11168 if (strcmp (*l
, "elf64-tradbigmips") == 0
11169 || strcmp (*l
, "elf64-tradlittlemips") == 0)
11171 if (strcmp (*l
, "elf64-bigmips") == 0
11172 || strcmp (*l
, "elf64-littlemips") == 0)
11175 yes
= (*l
!= NULL
);
11179 #endif /* OBJ_ELF */
11181 const char *md_shortopts
= "O::g::G:";
11185 OPTION_MARCH
= OPTION_MD_BASE
,
11207 OPTION_NO_SMARTMIPS
,
11210 OPTION_COMPAT_ARCH_BASE
,
11219 OPTION_M7000_HILO_FIX
,
11220 OPTION_MNO_7000_HILO_FIX
,
11224 OPTION_NO_FIX_VR4120
,
11226 OPTION_NO_FIX_VR4130
,
11233 OPTION_CONSTRUCT_FLOATS
,
11234 OPTION_NO_CONSTRUCT_FLOATS
,
11237 OPTION_RELAX_BRANCH
,
11238 OPTION_NO_RELAX_BRANCH
,
11245 OPTION_SINGLE_FLOAT
,
11246 OPTION_DOUBLE_FLOAT
,
11249 OPTION_CALL_SHARED
,
11250 OPTION_CALL_NONPIC
,
11260 OPTION_MVXWORKS_PIC
,
11261 #endif /* OBJ_ELF */
11265 struct option md_longopts
[] =
11267 /* Options which specify architecture. */
11268 {"march", required_argument
, NULL
, OPTION_MARCH
},
11269 {"mtune", required_argument
, NULL
, OPTION_MTUNE
},
11270 {"mips0", no_argument
, NULL
, OPTION_MIPS1
},
11271 {"mips1", no_argument
, NULL
, OPTION_MIPS1
},
11272 {"mips2", no_argument
, NULL
, OPTION_MIPS2
},
11273 {"mips3", no_argument
, NULL
, OPTION_MIPS3
},
11274 {"mips4", no_argument
, NULL
, OPTION_MIPS4
},
11275 {"mips5", no_argument
, NULL
, OPTION_MIPS5
},
11276 {"mips32", no_argument
, NULL
, OPTION_MIPS32
},
11277 {"mips64", no_argument
, NULL
, OPTION_MIPS64
},
11278 {"mips32r2", no_argument
, NULL
, OPTION_MIPS32R2
},
11279 {"mips64r2", no_argument
, NULL
, OPTION_MIPS64R2
},
11281 /* Options which specify Application Specific Extensions (ASEs). */
11282 {"mips16", no_argument
, NULL
, OPTION_MIPS16
},
11283 {"no-mips16", no_argument
, NULL
, OPTION_NO_MIPS16
},
11284 {"mips3d", no_argument
, NULL
, OPTION_MIPS3D
},
11285 {"no-mips3d", no_argument
, NULL
, OPTION_NO_MIPS3D
},
11286 {"mdmx", no_argument
, NULL
, OPTION_MDMX
},
11287 {"no-mdmx", no_argument
, NULL
, OPTION_NO_MDMX
},
11288 {"mdsp", no_argument
, NULL
, OPTION_DSP
},
11289 {"mno-dsp", no_argument
, NULL
, OPTION_NO_DSP
},
11290 {"mmt", no_argument
, NULL
, OPTION_MT
},
11291 {"mno-mt", no_argument
, NULL
, OPTION_NO_MT
},
11292 {"msmartmips", no_argument
, NULL
, OPTION_SMARTMIPS
},
11293 {"mno-smartmips", no_argument
, NULL
, OPTION_NO_SMARTMIPS
},
11294 {"mdspr2", no_argument
, NULL
, OPTION_DSPR2
},
11295 {"mno-dspr2", no_argument
, NULL
, OPTION_NO_DSPR2
},
11297 /* Old-style architecture options. Don't add more of these. */
11298 {"m4650", no_argument
, NULL
, OPTION_M4650
},
11299 {"no-m4650", no_argument
, NULL
, OPTION_NO_M4650
},
11300 {"m4010", no_argument
, NULL
, OPTION_M4010
},
11301 {"no-m4010", no_argument
, NULL
, OPTION_NO_M4010
},
11302 {"m4100", no_argument
, NULL
, OPTION_M4100
},
11303 {"no-m4100", no_argument
, NULL
, OPTION_NO_M4100
},
11304 {"m3900", no_argument
, NULL
, OPTION_M3900
},
11305 {"no-m3900", no_argument
, NULL
, OPTION_NO_M3900
},
11307 /* Options which enable bug fixes. */
11308 {"mfix7000", no_argument
, NULL
, OPTION_M7000_HILO_FIX
},
11309 {"no-fix-7000", no_argument
, NULL
, OPTION_MNO_7000_HILO_FIX
},
11310 {"mno-fix7000", no_argument
, NULL
, OPTION_MNO_7000_HILO_FIX
},
11311 {"mfix-vr4120", no_argument
, NULL
, OPTION_FIX_VR4120
},
11312 {"mno-fix-vr4120", no_argument
, NULL
, OPTION_NO_FIX_VR4120
},
11313 {"mfix-vr4130", no_argument
, NULL
, OPTION_FIX_VR4130
},
11314 {"mno-fix-vr4130", no_argument
, NULL
, OPTION_NO_FIX_VR4130
},
11315 {"mfix-24k", no_argument
, NULL
, OPTION_FIX_24K
},
11316 {"mno-fix-24k", no_argument
, NULL
, OPTION_NO_FIX_24K
},
11318 /* Miscellaneous options. */
11319 {"trap", no_argument
, NULL
, OPTION_TRAP
},
11320 {"no-break", no_argument
, NULL
, OPTION_TRAP
},
11321 {"break", no_argument
, NULL
, OPTION_BREAK
},
11322 {"no-trap", no_argument
, NULL
, OPTION_BREAK
},
11323 {"EB", no_argument
, NULL
, OPTION_EB
},
11324 {"EL", no_argument
, NULL
, OPTION_EL
},
11325 {"mfp32", no_argument
, NULL
, OPTION_FP32
},
11326 {"mgp32", no_argument
, NULL
, OPTION_GP32
},
11327 {"construct-floats", no_argument
, NULL
, OPTION_CONSTRUCT_FLOATS
},
11328 {"no-construct-floats", no_argument
, NULL
, OPTION_NO_CONSTRUCT_FLOATS
},
11329 {"mfp64", no_argument
, NULL
, OPTION_FP64
},
11330 {"mgp64", no_argument
, NULL
, OPTION_GP64
},
11331 {"relax-branch", no_argument
, NULL
, OPTION_RELAX_BRANCH
},
11332 {"no-relax-branch", no_argument
, NULL
, OPTION_NO_RELAX_BRANCH
},
11333 {"mshared", no_argument
, NULL
, OPTION_MSHARED
},
11334 {"mno-shared", no_argument
, NULL
, OPTION_MNO_SHARED
},
11335 {"msym32", no_argument
, NULL
, OPTION_MSYM32
},
11336 {"mno-sym32", no_argument
, NULL
, OPTION_MNO_SYM32
},
11337 {"msoft-float", no_argument
, NULL
, OPTION_SOFT_FLOAT
},
11338 {"mhard-float", no_argument
, NULL
, OPTION_HARD_FLOAT
},
11339 {"msingle-float", no_argument
, NULL
, OPTION_SINGLE_FLOAT
},
11340 {"mdouble-float", no_argument
, NULL
, OPTION_DOUBLE_FLOAT
},
11342 /* Strictly speaking this next option is ELF specific,
11343 but we allow it for other ports as well in order to
11344 make testing easier. */
11345 {"32", no_argument
, NULL
, OPTION_32
},
11347 /* ELF-specific options. */
11349 {"KPIC", no_argument
, NULL
, OPTION_CALL_SHARED
},
11350 {"call_shared", no_argument
, NULL
, OPTION_CALL_SHARED
},
11351 {"call_nonpic", no_argument
, NULL
, OPTION_CALL_NONPIC
},
11352 {"non_shared", no_argument
, NULL
, OPTION_NON_SHARED
},
11353 {"xgot", no_argument
, NULL
, OPTION_XGOT
},
11354 {"mabi", required_argument
, NULL
, OPTION_MABI
},
11355 {"n32", no_argument
, NULL
, OPTION_N32
},
11356 {"64", no_argument
, NULL
, OPTION_64
},
11357 {"mdebug", no_argument
, NULL
, OPTION_MDEBUG
},
11358 {"no-mdebug", no_argument
, NULL
, OPTION_NO_MDEBUG
},
11359 {"mpdr", no_argument
, NULL
, OPTION_PDR
},
11360 {"mno-pdr", no_argument
, NULL
, OPTION_NO_PDR
},
11361 {"mvxworks-pic", no_argument
, NULL
, OPTION_MVXWORKS_PIC
},
11362 #endif /* OBJ_ELF */
11364 {NULL
, no_argument
, NULL
, 0}
11366 size_t md_longopts_size
= sizeof (md_longopts
);
11368 /* Set STRING_PTR (either &mips_arch_string or &mips_tune_string) to
11369 NEW_VALUE. Warn if another value was already specified. Note:
11370 we have to defer parsing the -march and -mtune arguments in order
11371 to handle 'from-abi' correctly, since the ABI might be specified
11372 in a later argument. */
11375 mips_set_option_string (const char **string_ptr
, const char *new_value
)
11377 if (*string_ptr
!= 0 && strcasecmp (*string_ptr
, new_value
) != 0)
11378 as_warn (_("A different %s was already specified, is now %s"),
11379 string_ptr
== &mips_arch_string
? "-march" : "-mtune",
11382 *string_ptr
= new_value
;
11386 md_parse_option (int c
, char *arg
)
11390 case OPTION_CONSTRUCT_FLOATS
:
11391 mips_disable_float_construction
= 0;
11394 case OPTION_NO_CONSTRUCT_FLOATS
:
11395 mips_disable_float_construction
= 1;
11407 target_big_endian
= 1;
11411 target_big_endian
= 0;
11417 else if (arg
[0] == '0')
11419 else if (arg
[0] == '1')
11429 mips_debug
= atoi (arg
);
11433 file_mips_isa
= ISA_MIPS1
;
11437 file_mips_isa
= ISA_MIPS2
;
11441 file_mips_isa
= ISA_MIPS3
;
11445 file_mips_isa
= ISA_MIPS4
;
11449 file_mips_isa
= ISA_MIPS5
;
11452 case OPTION_MIPS32
:
11453 file_mips_isa
= ISA_MIPS32
;
11456 case OPTION_MIPS32R2
:
11457 file_mips_isa
= ISA_MIPS32R2
;
11460 case OPTION_MIPS64R2
:
11461 file_mips_isa
= ISA_MIPS64R2
;
11464 case OPTION_MIPS64
:
11465 file_mips_isa
= ISA_MIPS64
;
11469 mips_set_option_string (&mips_tune_string
, arg
);
11473 mips_set_option_string (&mips_arch_string
, arg
);
11477 mips_set_option_string (&mips_arch_string
, "4650");
11478 mips_set_option_string (&mips_tune_string
, "4650");
11481 case OPTION_NO_M4650
:
11485 mips_set_option_string (&mips_arch_string
, "4010");
11486 mips_set_option_string (&mips_tune_string
, "4010");
11489 case OPTION_NO_M4010
:
11493 mips_set_option_string (&mips_arch_string
, "4100");
11494 mips_set_option_string (&mips_tune_string
, "4100");
11497 case OPTION_NO_M4100
:
11501 mips_set_option_string (&mips_arch_string
, "3900");
11502 mips_set_option_string (&mips_tune_string
, "3900");
11505 case OPTION_NO_M3900
:
11509 mips_opts
.ase_mdmx
= 1;
11512 case OPTION_NO_MDMX
:
11513 mips_opts
.ase_mdmx
= 0;
11517 mips_opts
.ase_dsp
= 1;
11518 mips_opts
.ase_dspr2
= 0;
11521 case OPTION_NO_DSP
:
11522 mips_opts
.ase_dsp
= 0;
11523 mips_opts
.ase_dspr2
= 0;
11527 mips_opts
.ase_dspr2
= 1;
11528 mips_opts
.ase_dsp
= 1;
11531 case OPTION_NO_DSPR2
:
11532 mips_opts
.ase_dspr2
= 0;
11533 mips_opts
.ase_dsp
= 0;
11537 mips_opts
.ase_mt
= 1;
11541 mips_opts
.ase_mt
= 0;
11544 case OPTION_MIPS16
:
11545 mips_opts
.mips16
= 1;
11546 mips_no_prev_insn ();
11549 case OPTION_NO_MIPS16
:
11550 mips_opts
.mips16
= 0;
11551 mips_no_prev_insn ();
11554 case OPTION_MIPS3D
:
11555 mips_opts
.ase_mips3d
= 1;
11558 case OPTION_NO_MIPS3D
:
11559 mips_opts
.ase_mips3d
= 0;
11562 case OPTION_SMARTMIPS
:
11563 mips_opts
.ase_smartmips
= 1;
11566 case OPTION_NO_SMARTMIPS
:
11567 mips_opts
.ase_smartmips
= 0;
11570 case OPTION_FIX_24K
:
11574 case OPTION_NO_FIX_24K
:
11578 case OPTION_FIX_VR4120
:
11579 mips_fix_vr4120
= 1;
11582 case OPTION_NO_FIX_VR4120
:
11583 mips_fix_vr4120
= 0;
11586 case OPTION_FIX_VR4130
:
11587 mips_fix_vr4130
= 1;
11590 case OPTION_NO_FIX_VR4130
:
11591 mips_fix_vr4130
= 0;
11594 case OPTION_RELAX_BRANCH
:
11595 mips_relax_branch
= 1;
11598 case OPTION_NO_RELAX_BRANCH
:
11599 mips_relax_branch
= 0;
11602 case OPTION_MSHARED
:
11603 mips_in_shared
= TRUE
;
11606 case OPTION_MNO_SHARED
:
11607 mips_in_shared
= FALSE
;
11610 case OPTION_MSYM32
:
11611 mips_opts
.sym32
= TRUE
;
11614 case OPTION_MNO_SYM32
:
11615 mips_opts
.sym32
= FALSE
;
11619 /* When generating ELF code, we permit -KPIC and -call_shared to
11620 select SVR4_PIC, and -non_shared to select no PIC. This is
11621 intended to be compatible with Irix 5. */
11622 case OPTION_CALL_SHARED
:
11625 as_bad (_("-call_shared is supported only for ELF format"));
11628 mips_pic
= SVR4_PIC
;
11629 mips_abicalls
= TRUE
;
11632 case OPTION_CALL_NONPIC
:
11635 as_bad (_("-call_nonpic is supported only for ELF format"));
11639 mips_abicalls
= TRUE
;
11642 case OPTION_NON_SHARED
:
11645 as_bad (_("-non_shared is supported only for ELF format"));
11649 mips_abicalls
= FALSE
;
11652 /* The -xgot option tells the assembler to use 32 bit offsets
11653 when accessing the got in SVR4_PIC mode. It is for Irix
11658 #endif /* OBJ_ELF */
11661 g_switch_value
= atoi (arg
);
11665 /* The -32, -n32 and -64 options are shortcuts for -mabi=32, -mabi=n32
11669 mips_abi
= O32_ABI
;
11670 /* We silently ignore -32 for non-ELF targets. This greatly
11671 simplifies the construction of the MIPS GAS test cases. */
11678 as_bad (_("-n32 is supported for ELF format only"));
11681 mips_abi
= N32_ABI
;
11687 as_bad (_("-64 is supported for ELF format only"));
11690 mips_abi
= N64_ABI
;
11691 if (!support_64bit_objects())
11692 as_fatal (_("No compiled in support for 64 bit object file format"));
11694 #endif /* OBJ_ELF */
11697 file_mips_gp32
= 1;
11701 file_mips_gp32
= 0;
11705 file_mips_fp32
= 1;
11709 file_mips_fp32
= 0;
11712 case OPTION_SINGLE_FLOAT
:
11713 file_mips_single_float
= 1;
11716 case OPTION_DOUBLE_FLOAT
:
11717 file_mips_single_float
= 0;
11720 case OPTION_SOFT_FLOAT
:
11721 file_mips_soft_float
= 1;
11724 case OPTION_HARD_FLOAT
:
11725 file_mips_soft_float
= 0;
11732 as_bad (_("-mabi is supported for ELF format only"));
11735 if (strcmp (arg
, "32") == 0)
11736 mips_abi
= O32_ABI
;
11737 else if (strcmp (arg
, "o64") == 0)
11738 mips_abi
= O64_ABI
;
11739 else if (strcmp (arg
, "n32") == 0)
11740 mips_abi
= N32_ABI
;
11741 else if (strcmp (arg
, "64") == 0)
11743 mips_abi
= N64_ABI
;
11744 if (! support_64bit_objects())
11745 as_fatal (_("No compiled in support for 64 bit object file "
11748 else if (strcmp (arg
, "eabi") == 0)
11749 mips_abi
= EABI_ABI
;
11752 as_fatal (_("invalid abi -mabi=%s"), arg
);
11756 #endif /* OBJ_ELF */
11758 case OPTION_M7000_HILO_FIX
:
11759 mips_7000_hilo_fix
= TRUE
;
11762 case OPTION_MNO_7000_HILO_FIX
:
11763 mips_7000_hilo_fix
= FALSE
;
11767 case OPTION_MDEBUG
:
11768 mips_flag_mdebug
= TRUE
;
11771 case OPTION_NO_MDEBUG
:
11772 mips_flag_mdebug
= FALSE
;
11776 mips_flag_pdr
= TRUE
;
11779 case OPTION_NO_PDR
:
11780 mips_flag_pdr
= FALSE
;
11783 case OPTION_MVXWORKS_PIC
:
11784 mips_pic
= VXWORKS_PIC
;
11786 #endif /* OBJ_ELF */
11795 /* Set up globals to generate code for the ISA or processor
11796 described by INFO. */
11799 mips_set_architecture (const struct mips_cpu_info
*info
)
11803 file_mips_arch
= info
->cpu
;
11804 mips_opts
.arch
= info
->cpu
;
11805 mips_opts
.isa
= info
->isa
;
11810 /* Likewise for tuning. */
11813 mips_set_tune (const struct mips_cpu_info
*info
)
11816 mips_tune
= info
->cpu
;
11821 mips_after_parse_args (void)
11823 const struct mips_cpu_info
*arch_info
= 0;
11824 const struct mips_cpu_info
*tune_info
= 0;
11826 /* GP relative stuff not working for PE */
11827 if (strncmp (TARGET_OS
, "pe", 2) == 0)
11829 if (g_switch_seen
&& g_switch_value
!= 0)
11830 as_bad (_("-G not supported in this configuration."));
11831 g_switch_value
= 0;
11834 if (mips_abi
== NO_ABI
)
11835 mips_abi
= MIPS_DEFAULT_ABI
;
11837 /* The following code determines the architecture and register size.
11838 Similar code was added to GCC 3.3 (see override_options() in
11839 config/mips/mips.c). The GAS and GCC code should be kept in sync
11840 as much as possible. */
11842 if (mips_arch_string
!= 0)
11843 arch_info
= mips_parse_cpu ("-march", mips_arch_string
);
11845 if (file_mips_isa
!= ISA_UNKNOWN
)
11847 /* Handle -mipsN. At this point, file_mips_isa contains the
11848 ISA level specified by -mipsN, while arch_info->isa contains
11849 the -march selection (if any). */
11850 if (arch_info
!= 0)
11852 /* -march takes precedence over -mipsN, since it is more descriptive.
11853 There's no harm in specifying both as long as the ISA levels
11855 if (file_mips_isa
!= arch_info
->isa
)
11856 as_bad (_("-%s conflicts with the other architecture options, which imply -%s"),
11857 mips_cpu_info_from_isa (file_mips_isa
)->name
,
11858 mips_cpu_info_from_isa (arch_info
->isa
)->name
);
11861 arch_info
= mips_cpu_info_from_isa (file_mips_isa
);
11864 if (arch_info
== 0)
11865 arch_info
= mips_parse_cpu ("default CPU", MIPS_CPU_STRING_DEFAULT
);
11867 if (ABI_NEEDS_64BIT_REGS (mips_abi
) && !ISA_HAS_64BIT_REGS (arch_info
->isa
))
11868 as_bad (_("-march=%s is not compatible with the selected ABI"),
11871 mips_set_architecture (arch_info
);
11873 /* Optimize for file_mips_arch, unless -mtune selects a different processor. */
11874 if (mips_tune_string
!= 0)
11875 tune_info
= mips_parse_cpu ("-mtune", mips_tune_string
);
11877 if (tune_info
== 0)
11878 mips_set_tune (arch_info
);
11880 mips_set_tune (tune_info
);
11882 if (file_mips_gp32
>= 0)
11884 /* The user specified the size of the integer registers. Make sure
11885 it agrees with the ABI and ISA. */
11886 if (file_mips_gp32
== 0 && !ISA_HAS_64BIT_REGS (mips_opts
.isa
))
11887 as_bad (_("-mgp64 used with a 32-bit processor"));
11888 else if (file_mips_gp32
== 1 && ABI_NEEDS_64BIT_REGS (mips_abi
))
11889 as_bad (_("-mgp32 used with a 64-bit ABI"));
11890 else if (file_mips_gp32
== 0 && ABI_NEEDS_32BIT_REGS (mips_abi
))
11891 as_bad (_("-mgp64 used with a 32-bit ABI"));
11895 /* Infer the integer register size from the ABI and processor.
11896 Restrict ourselves to 32-bit registers if that's all the
11897 processor has, or if the ABI cannot handle 64-bit registers. */
11898 file_mips_gp32
= (ABI_NEEDS_32BIT_REGS (mips_abi
)
11899 || !ISA_HAS_64BIT_REGS (mips_opts
.isa
));
11902 switch (file_mips_fp32
)
11906 /* No user specified float register size.
11907 ??? GAS treats single-float processors as though they had 64-bit
11908 float registers (although it complains when double-precision
11909 instructions are used). As things stand, saying they have 32-bit
11910 registers would lead to spurious "register must be even" messages.
11911 So here we assume float registers are never smaller than the
11913 if (file_mips_gp32
== 0)
11914 /* 64-bit integer registers implies 64-bit float registers. */
11915 file_mips_fp32
= 0;
11916 else if ((mips_opts
.ase_mips3d
> 0 || mips_opts
.ase_mdmx
> 0)
11917 && ISA_HAS_64BIT_FPRS (mips_opts
.isa
))
11918 /* -mips3d and -mdmx imply 64-bit float registers, if possible. */
11919 file_mips_fp32
= 0;
11921 /* 32-bit float registers. */
11922 file_mips_fp32
= 1;
11925 /* The user specified the size of the float registers. Check if it
11926 agrees with the ABI and ISA. */
11928 if (!ISA_HAS_64BIT_FPRS (mips_opts
.isa
))
11929 as_bad (_("-mfp64 used with a 32-bit fpu"));
11930 else if (ABI_NEEDS_32BIT_REGS (mips_abi
)
11931 && !ISA_HAS_MXHC1 (mips_opts
.isa
))
11932 as_warn (_("-mfp64 used with a 32-bit ABI"));
11935 if (ABI_NEEDS_64BIT_REGS (mips_abi
))
11936 as_warn (_("-mfp32 used with a 64-bit ABI"));
11940 /* End of GCC-shared inference code. */
11942 /* This flag is set when we have a 64-bit capable CPU but use only
11943 32-bit wide registers. Note that EABI does not use it. */
11944 if (ISA_HAS_64BIT_REGS (mips_opts
.isa
)
11945 && ((mips_abi
== NO_ABI
&& file_mips_gp32
== 1)
11946 || mips_abi
== O32_ABI
))
11947 mips_32bitmode
= 1;
11949 if (mips_opts
.isa
== ISA_MIPS1
&& mips_trap
)
11950 as_bad (_("trap exception not supported at ISA 1"));
11952 /* If the selected architecture includes support for ASEs, enable
11953 generation of code for them. */
11954 if (mips_opts
.mips16
== -1)
11955 mips_opts
.mips16
= (CPU_HAS_MIPS16 (file_mips_arch
)) ? 1 : 0;
11956 if (mips_opts
.ase_mips3d
== -1)
11957 mips_opts
.ase_mips3d
= ((arch_info
->flags
& MIPS_CPU_ASE_MIPS3D
)
11958 && file_mips_fp32
== 0) ? 1 : 0;
11959 if (mips_opts
.ase_mips3d
&& file_mips_fp32
== 1)
11960 as_bad (_("-mfp32 used with -mips3d"));
11962 if (mips_opts
.ase_mdmx
== -1)
11963 mips_opts
.ase_mdmx
= ((arch_info
->flags
& MIPS_CPU_ASE_MDMX
)
11964 && file_mips_fp32
== 0) ? 1 : 0;
11965 if (mips_opts
.ase_mdmx
&& file_mips_fp32
== 1)
11966 as_bad (_("-mfp32 used with -mdmx"));
11968 if (mips_opts
.ase_smartmips
== -1)
11969 mips_opts
.ase_smartmips
= (arch_info
->flags
& MIPS_CPU_ASE_SMARTMIPS
) ? 1 : 0;
11970 if (mips_opts
.ase_smartmips
&& !ISA_SUPPORTS_SMARTMIPS
)
11971 as_warn (_("%s ISA does not support SmartMIPS"),
11972 mips_cpu_info_from_isa (mips_opts
.isa
)->name
);
11974 if (mips_opts
.ase_dsp
== -1)
11975 mips_opts
.ase_dsp
= (arch_info
->flags
& MIPS_CPU_ASE_DSP
) ? 1 : 0;
11976 if (mips_opts
.ase_dsp
&& !ISA_SUPPORTS_DSP_ASE
)
11977 as_warn (_("%s ISA does not support DSP ASE"),
11978 mips_cpu_info_from_isa (mips_opts
.isa
)->name
);
11980 if (mips_opts
.ase_dspr2
== -1)
11982 mips_opts
.ase_dspr2
= (arch_info
->flags
& MIPS_CPU_ASE_DSPR2
) ? 1 : 0;
11983 mips_opts
.ase_dsp
= (arch_info
->flags
& MIPS_CPU_ASE_DSP
) ? 1 : 0;
11985 if (mips_opts
.ase_dspr2
&& !ISA_SUPPORTS_DSPR2_ASE
)
11986 as_warn (_("%s ISA does not support DSP R2 ASE"),
11987 mips_cpu_info_from_isa (mips_opts
.isa
)->name
);
11989 if (mips_opts
.ase_mt
== -1)
11990 mips_opts
.ase_mt
= (arch_info
->flags
& MIPS_CPU_ASE_MT
) ? 1 : 0;
11991 if (mips_opts
.ase_mt
&& !ISA_SUPPORTS_MT_ASE
)
11992 as_warn (_("%s ISA does not support MT ASE"),
11993 mips_cpu_info_from_isa (mips_opts
.isa
)->name
);
11995 file_mips_isa
= mips_opts
.isa
;
11996 file_ase_mips16
= mips_opts
.mips16
;
11997 file_ase_mips3d
= mips_opts
.ase_mips3d
;
11998 file_ase_mdmx
= mips_opts
.ase_mdmx
;
11999 file_ase_smartmips
= mips_opts
.ase_smartmips
;
12000 file_ase_dsp
= mips_opts
.ase_dsp
;
12001 file_ase_dspr2
= mips_opts
.ase_dspr2
;
12002 file_ase_mt
= mips_opts
.ase_mt
;
12003 mips_opts
.gp32
= file_mips_gp32
;
12004 mips_opts
.fp32
= file_mips_fp32
;
12005 mips_opts
.soft_float
= file_mips_soft_float
;
12006 mips_opts
.single_float
= file_mips_single_float
;
12008 if (mips_flag_mdebug
< 0)
12010 #ifdef OBJ_MAYBE_ECOFF
12011 if (OUTPUT_FLAVOR
== bfd_target_ecoff_flavour
)
12012 mips_flag_mdebug
= 1;
12014 #endif /* OBJ_MAYBE_ECOFF */
12015 mips_flag_mdebug
= 0;
12020 mips_init_after_args (void)
12022 /* initialize opcodes */
12023 bfd_mips_num_opcodes
= bfd_mips_num_builtin_opcodes
;
12024 mips_opcodes
= (struct mips_opcode
*) mips_builtin_opcodes
;
12028 md_pcrel_from (fixS
*fixP
)
12030 valueT addr
= fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
12031 switch (fixP
->fx_r_type
)
12033 case BFD_RELOC_16_PCREL_S2
:
12034 case BFD_RELOC_MIPS_JMP
:
12035 /* Return the address of the delay slot. */
12038 /* We have no relocation type for PC relative MIPS16 instructions. */
12039 if (fixP
->fx_addsy
&& S_GET_SEGMENT (fixP
->fx_addsy
) != now_seg
)
12040 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
12041 _("PC relative MIPS16 instruction references a different section"));
12046 /* This is called before the symbol table is processed. In order to
12047 work with gcc when using mips-tfile, we must keep all local labels.
12048 However, in other cases, we want to discard them. If we were
12049 called with -g, but we didn't see any debugging information, it may
12050 mean that gcc is smuggling debugging information through to
12051 mips-tfile, in which case we must generate all local labels. */
12054 mips_frob_file_before_adjust (void)
12056 #ifndef NO_ECOFF_DEBUGGING
12057 if (ECOFF_DEBUGGING
12059 && ! ecoff_debugging_seen
)
12060 flag_keep_locals
= 1;
12064 /* Sort any unmatched HI16 and GOT16 relocs so that they immediately precede
12065 the corresponding LO16 reloc. This is called before md_apply_fix and
12066 tc_gen_reloc. Unmatched relocs can only be generated by use of explicit
12067 relocation operators.
12069 For our purposes, a %lo() expression matches a %got() or %hi()
12072 (a) it refers to the same symbol; and
12073 (b) the offset applied in the %lo() expression is no lower than
12074 the offset applied in the %got() or %hi().
12076 (b) allows us to cope with code like:
12079 lh $4,%lo(foo+2)($4)
12081 ...which is legal on RELA targets, and has a well-defined behaviour
12082 if the user knows that adding 2 to "foo" will not induce a carry to
12085 When several %lo()s match a particular %got() or %hi(), we use the
12086 following rules to distinguish them:
12088 (1) %lo()s with smaller offsets are a better match than %lo()s with
12091 (2) %lo()s with no matching %got() or %hi() are better than those
12092 that already have a matching %got() or %hi().
12094 (3) later %lo()s are better than earlier %lo()s.
12096 These rules are applied in order.
12098 (1) means, among other things, that %lo()s with identical offsets are
12099 chosen if they exist.
12101 (2) means that we won't associate several high-part relocations with
12102 the same low-part relocation unless there's no alternative. Having
12103 several high parts for the same low part is a GNU extension; this rule
12104 allows careful users to avoid it.
12106 (3) is purely cosmetic. mips_hi_fixup_list is is in reverse order,
12107 with the last high-part relocation being at the front of the list.
12108 It therefore makes sense to choose the last matching low-part
12109 relocation, all other things being equal. It's also easier
12110 to code that way. */
12113 mips_frob_file (void)
12115 struct mips_hi_fixup
*l
;
12116 bfd_reloc_code_real_type looking_for_rtype
= BFD_RELOC_UNUSED
;
12118 for (l
= mips_hi_fixup_list
; l
!= NULL
; l
= l
->next
)
12120 segment_info_type
*seginfo
;
12121 bfd_boolean matched_lo_p
;
12122 fixS
**hi_pos
, **lo_pos
, **pos
;
12124 gas_assert (reloc_needs_lo_p (l
->fixp
->fx_r_type
));
12126 /* If a GOT16 relocation turns out to be against a global symbol,
12127 there isn't supposed to be a matching LO. */
12128 if (got16_reloc_p (l
->fixp
->fx_r_type
)
12129 && !pic_need_relax (l
->fixp
->fx_addsy
, l
->seg
))
12132 /* Check quickly whether the next fixup happens to be a matching %lo. */
12133 if (fixup_has_matching_lo_p (l
->fixp
))
12136 seginfo
= seg_info (l
->seg
);
12138 /* Set HI_POS to the position of this relocation in the chain.
12139 Set LO_POS to the position of the chosen low-part relocation.
12140 MATCHED_LO_P is true on entry to the loop if *POS is a low-part
12141 relocation that matches an immediately-preceding high-part
12145 matched_lo_p
= FALSE
;
12146 looking_for_rtype
= matching_lo_reloc (l
->fixp
->fx_r_type
);
12148 for (pos
= &seginfo
->fix_root
; *pos
!= NULL
; pos
= &(*pos
)->fx_next
)
12150 if (*pos
== l
->fixp
)
12153 if ((*pos
)->fx_r_type
== looking_for_rtype
12154 && (*pos
)->fx_addsy
== l
->fixp
->fx_addsy
12155 && (*pos
)->fx_offset
>= l
->fixp
->fx_offset
12157 || (*pos
)->fx_offset
< (*lo_pos
)->fx_offset
12159 && (*pos
)->fx_offset
== (*lo_pos
)->fx_offset
)))
12162 matched_lo_p
= (reloc_needs_lo_p ((*pos
)->fx_r_type
)
12163 && fixup_has_matching_lo_p (*pos
));
12166 /* If we found a match, remove the high-part relocation from its
12167 current position and insert it before the low-part relocation.
12168 Make the offsets match so that fixup_has_matching_lo_p()
12171 We don't warn about unmatched high-part relocations since some
12172 versions of gcc have been known to emit dead "lui ...%hi(...)"
12174 if (lo_pos
!= NULL
)
12176 l
->fixp
->fx_offset
= (*lo_pos
)->fx_offset
;
12177 if (l
->fixp
->fx_next
!= *lo_pos
)
12179 *hi_pos
= l
->fixp
->fx_next
;
12180 l
->fixp
->fx_next
= *lo_pos
;
12187 /* We may have combined relocations without symbols in the N32/N64 ABI.
12188 We have to prevent gas from dropping them. */
12191 mips_force_relocation (fixS
*fixp
)
12193 if (generic_force_reloc (fixp
))
12197 && S_GET_SEGMENT (fixp
->fx_addsy
) == bfd_abs_section_ptr
12198 && (fixp
->fx_r_type
== BFD_RELOC_MIPS_SUB
12199 || hi16_reloc_p (fixp
->fx_r_type
)
12200 || lo16_reloc_p (fixp
->fx_r_type
)))
12206 /* Apply a fixup to the object file. */
12209 md_apply_fix (fixS
*fixP
, valueT
*valP
, segT seg ATTRIBUTE_UNUSED
)
12213 reloc_howto_type
*howto
;
12215 /* We ignore generic BFD relocations we don't know about. */
12216 howto
= bfd_reloc_type_lookup (stdoutput
, fixP
->fx_r_type
);
12220 gas_assert (fixP
->fx_size
== 4
12221 || fixP
->fx_r_type
== BFD_RELOC_16
12222 || fixP
->fx_r_type
== BFD_RELOC_64
12223 || fixP
->fx_r_type
== BFD_RELOC_CTOR
12224 || fixP
->fx_r_type
== BFD_RELOC_MIPS_SUB
12225 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
12226 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
12227 || fixP
->fx_r_type
== BFD_RELOC_MIPS_TLS_DTPREL64
);
12229 buf
= (bfd_byte
*) (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
);
12231 gas_assert (!fixP
->fx_pcrel
|| fixP
->fx_r_type
== BFD_RELOC_16_PCREL_S2
);
12233 /* Don't treat parts of a composite relocation as done. There are two
12236 (1) The second and third parts will be against 0 (RSS_UNDEF) but
12237 should nevertheless be emitted if the first part is.
12239 (2) In normal usage, composite relocations are never assembly-time
12240 constants. The easiest way of dealing with the pathological
12241 exceptions is to generate a relocation against STN_UNDEF and
12242 leave everything up to the linker. */
12243 if (fixP
->fx_addsy
== NULL
&& !fixP
->fx_pcrel
&& fixP
->fx_tcbit
== 0)
12246 switch (fixP
->fx_r_type
)
12248 case BFD_RELOC_MIPS_TLS_GD
:
12249 case BFD_RELOC_MIPS_TLS_LDM
:
12250 case BFD_RELOC_MIPS_TLS_DTPREL32
:
12251 case BFD_RELOC_MIPS_TLS_DTPREL64
:
12252 case BFD_RELOC_MIPS_TLS_DTPREL_HI16
:
12253 case BFD_RELOC_MIPS_TLS_DTPREL_LO16
:
12254 case BFD_RELOC_MIPS_TLS_GOTTPREL
:
12255 case BFD_RELOC_MIPS_TLS_TPREL_HI16
:
12256 case BFD_RELOC_MIPS_TLS_TPREL_LO16
:
12257 S_SET_THREAD_LOCAL (fixP
->fx_addsy
);
12260 case BFD_RELOC_MIPS_JMP
:
12261 case BFD_RELOC_MIPS_SHIFT5
:
12262 case BFD_RELOC_MIPS_SHIFT6
:
12263 case BFD_RELOC_MIPS_GOT_DISP
:
12264 case BFD_RELOC_MIPS_GOT_PAGE
:
12265 case BFD_RELOC_MIPS_GOT_OFST
:
12266 case BFD_RELOC_MIPS_SUB
:
12267 case BFD_RELOC_MIPS_INSERT_A
:
12268 case BFD_RELOC_MIPS_INSERT_B
:
12269 case BFD_RELOC_MIPS_DELETE
:
12270 case BFD_RELOC_MIPS_HIGHEST
:
12271 case BFD_RELOC_MIPS_HIGHER
:
12272 case BFD_RELOC_MIPS_SCN_DISP
:
12273 case BFD_RELOC_MIPS_REL16
:
12274 case BFD_RELOC_MIPS_RELGOT
:
12275 case BFD_RELOC_MIPS_JALR
:
12276 case BFD_RELOC_HI16
:
12277 case BFD_RELOC_HI16_S
:
12278 case BFD_RELOC_GPREL16
:
12279 case BFD_RELOC_MIPS_LITERAL
:
12280 case BFD_RELOC_MIPS_CALL16
:
12281 case BFD_RELOC_MIPS_GOT16
:
12282 case BFD_RELOC_GPREL32
:
12283 case BFD_RELOC_MIPS_GOT_HI16
:
12284 case BFD_RELOC_MIPS_GOT_LO16
:
12285 case BFD_RELOC_MIPS_CALL_HI16
:
12286 case BFD_RELOC_MIPS_CALL_LO16
:
12287 case BFD_RELOC_MIPS16_GPREL
:
12288 case BFD_RELOC_MIPS16_GOT16
:
12289 case BFD_RELOC_MIPS16_CALL16
:
12290 case BFD_RELOC_MIPS16_HI16
:
12291 case BFD_RELOC_MIPS16_HI16_S
:
12292 case BFD_RELOC_MIPS16_JMP
:
12293 /* Nothing needed to do. The value comes from the reloc entry. */
12297 /* This is handled like BFD_RELOC_32, but we output a sign
12298 extended value if we are only 32 bits. */
12301 if (8 <= sizeof (valueT
))
12302 md_number_to_chars ((char *) buf
, *valP
, 8);
12307 if ((*valP
& 0x80000000) != 0)
12311 md_number_to_chars ((char *)(buf
+ (target_big_endian
? 4 : 0)),
12313 md_number_to_chars ((char *)(buf
+ (target_big_endian
? 0 : 4)),
12319 case BFD_RELOC_RVA
:
12322 /* If we are deleting this reloc entry, we must fill in the
12323 value now. This can happen if we have a .word which is not
12324 resolved when it appears but is later defined. */
12326 md_number_to_chars ((char *) buf
, *valP
, fixP
->fx_size
);
12329 case BFD_RELOC_LO16
:
12330 case BFD_RELOC_MIPS16_LO16
:
12331 /* FIXME: Now that embedded-PIC is gone, some of this code/comment
12332 may be safe to remove, but if so it's not obvious. */
12333 /* When handling an embedded PIC switch statement, we can wind
12334 up deleting a LO16 reloc. See the 'o' case in mips_ip. */
12337 if (*valP
+ 0x8000 > 0xffff)
12338 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
12339 _("relocation overflow"));
12340 if (target_big_endian
)
12342 md_number_to_chars ((char *) buf
, *valP
, 2);
12346 case BFD_RELOC_16_PCREL_S2
:
12347 if ((*valP
& 0x3) != 0)
12348 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
12349 _("Branch to misaligned address (%lx)"), (long) *valP
);
12351 /* We need to save the bits in the instruction since fixup_segment()
12352 might be deleting the relocation entry (i.e., a branch within
12353 the current segment). */
12354 if (! fixP
->fx_done
)
12357 /* Update old instruction data. */
12358 if (target_big_endian
)
12359 insn
= (buf
[0] << 24) | (buf
[1] << 16) | (buf
[2] << 8) | buf
[3];
12361 insn
= (buf
[3] << 24) | (buf
[2] << 16) | (buf
[1] << 8) | buf
[0];
12363 if (*valP
+ 0x20000 <= 0x3ffff)
12365 insn
|= (*valP
>> 2) & 0xffff;
12366 md_number_to_chars ((char *) buf
, insn
, 4);
12368 else if (mips_pic
== NO_PIC
12370 && fixP
->fx_frag
->fr_address
>= text_section
->vma
12371 && (fixP
->fx_frag
->fr_address
12372 < text_section
->vma
+ bfd_get_section_size (text_section
))
12373 && ((insn
& 0xffff0000) == 0x10000000 /* beq $0,$0 */
12374 || (insn
& 0xffff0000) == 0x04010000 /* bgez $0 */
12375 || (insn
& 0xffff0000) == 0x04110000)) /* bgezal $0 */
12377 /* The branch offset is too large. If this is an
12378 unconditional branch, and we are not generating PIC code,
12379 we can convert it to an absolute jump instruction. */
12380 if ((insn
& 0xffff0000) == 0x04110000) /* bgezal $0 */
12381 insn
= 0x0c000000; /* jal */
12383 insn
= 0x08000000; /* j */
12384 fixP
->fx_r_type
= BFD_RELOC_MIPS_JMP
;
12386 fixP
->fx_addsy
= section_symbol (text_section
);
12387 *valP
+= md_pcrel_from (fixP
);
12388 md_number_to_chars ((char *) buf
, insn
, 4);
12392 /* If we got here, we have branch-relaxation disabled,
12393 and there's nothing we can do to fix this instruction
12394 without turning it into a longer sequence. */
12395 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
12396 _("Branch out of range"));
12400 case BFD_RELOC_VTABLE_INHERIT
:
12403 && !S_IS_DEFINED (fixP
->fx_addsy
)
12404 && !S_IS_WEAK (fixP
->fx_addsy
))
12405 S_SET_WEAK (fixP
->fx_addsy
);
12408 case BFD_RELOC_VTABLE_ENTRY
:
12416 /* Remember value for tc_gen_reloc. */
12417 fixP
->fx_addnumber
= *valP
;
12427 name
= input_line_pointer
;
12428 c
= get_symbol_end ();
12429 p
= (symbolS
*) symbol_find_or_make (name
);
12430 *input_line_pointer
= c
;
12434 /* Align the current frag to a given power of two. If a particular
12435 fill byte should be used, FILL points to an integer that contains
12436 that byte, otherwise FILL is null.
12438 The MIPS assembler also automatically adjusts any preceding
12442 mips_align (int to
, int *fill
, symbolS
*label
)
12444 mips_emit_delays ();
12445 mips_record_mips16_mode ();
12446 if (fill
== NULL
&& subseg_text_p (now_seg
))
12447 frag_align_code (to
, 0);
12449 frag_align (to
, fill
? *fill
: 0, 0);
12450 record_alignment (now_seg
, to
);
12453 gas_assert (S_GET_SEGMENT (label
) == now_seg
);
12454 symbol_set_frag (label
, frag_now
);
12455 S_SET_VALUE (label
, (valueT
) frag_now_fix ());
12459 /* Align to a given power of two. .align 0 turns off the automatic
12460 alignment used by the data creating pseudo-ops. */
12463 s_align (int x ATTRIBUTE_UNUSED
)
12465 int temp
, fill_value
, *fill_ptr
;
12466 long max_alignment
= 28;
12468 /* o Note that the assembler pulls down any immediately preceding label
12469 to the aligned address.
12470 o It's not documented but auto alignment is reinstated by
12471 a .align pseudo instruction.
12472 o Note also that after auto alignment is turned off the mips assembler
12473 issues an error on attempt to assemble an improperly aligned data item.
12476 temp
= get_absolute_expression ();
12477 if (temp
> max_alignment
)
12478 as_bad (_("Alignment too large: %d. assumed."), temp
= max_alignment
);
12481 as_warn (_("Alignment negative: 0 assumed."));
12484 if (*input_line_pointer
== ',')
12486 ++input_line_pointer
;
12487 fill_value
= get_absolute_expression ();
12488 fill_ptr
= &fill_value
;
12494 segment_info_type
*si
= seg_info (now_seg
);
12495 struct insn_label_list
*l
= si
->label_list
;
12496 /* Auto alignment should be switched on by next section change. */
12498 mips_align (temp
, fill_ptr
, l
!= NULL
? l
->label
: NULL
);
12505 demand_empty_rest_of_line ();
12509 s_change_sec (int sec
)
12514 /* The ELF backend needs to know that we are changing sections, so
12515 that .previous works correctly. We could do something like check
12516 for an obj_section_change_hook macro, but that might be confusing
12517 as it would not be appropriate to use it in the section changing
12518 functions in read.c, since obj-elf.c intercepts those. FIXME:
12519 This should be cleaner, somehow. */
12521 obj_elf_section_change_hook ();
12524 mips_emit_delays ();
12535 subseg_set (bss_section
, (subsegT
) get_absolute_expression ());
12536 demand_empty_rest_of_line ();
12540 seg
= subseg_new (RDATA_SECTION_NAME
,
12541 (subsegT
) get_absolute_expression ());
12544 bfd_set_section_flags (stdoutput
, seg
, (SEC_ALLOC
| SEC_LOAD
12545 | SEC_READONLY
| SEC_RELOC
12547 if (strncmp (TARGET_OS
, "elf", 3) != 0)
12548 record_alignment (seg
, 4);
12550 demand_empty_rest_of_line ();
12554 seg
= subseg_new (".sdata", (subsegT
) get_absolute_expression ());
12557 bfd_set_section_flags (stdoutput
, seg
,
12558 SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_DATA
);
12559 if (strncmp (TARGET_OS
, "elf", 3) != 0)
12560 record_alignment (seg
, 4);
12562 demand_empty_rest_of_line ();
12570 s_change_section (int ignore ATTRIBUTE_UNUSED
)
12573 char *section_name
;
12578 int section_entry_size
;
12579 int section_alignment
;
12584 section_name
= input_line_pointer
;
12585 c
= get_symbol_end ();
12587 next_c
= *(input_line_pointer
+ 1);
12589 /* Do we have .section Name<,"flags">? */
12590 if (c
!= ',' || (c
== ',' && next_c
== '"'))
12592 /* just after name is now '\0'. */
12593 *input_line_pointer
= c
;
12594 input_line_pointer
= section_name
;
12595 obj_elf_section (ignore
);
12598 input_line_pointer
++;
12600 /* Do we have .section Name<,type><,flag><,entry_size><,alignment> */
12602 section_type
= get_absolute_expression ();
12605 if (*input_line_pointer
++ == ',')
12606 section_flag
= get_absolute_expression ();
12609 if (*input_line_pointer
++ == ',')
12610 section_entry_size
= get_absolute_expression ();
12612 section_entry_size
= 0;
12613 if (*input_line_pointer
++ == ',')
12614 section_alignment
= get_absolute_expression ();
12616 section_alignment
= 0;
12618 section_name
= xstrdup (section_name
);
12620 /* When using the generic form of .section (as implemented by obj-elf.c),
12621 there's no way to set the section type to SHT_MIPS_DWARF. Users have
12622 traditionally had to fall back on the more common @progbits instead.
12624 There's nothing really harmful in this, since bfd will correct
12625 SHT_PROGBITS to SHT_MIPS_DWARF before writing out the file. But it
12626 means that, for backwards compatibility, the special_section entries
12627 for dwarf sections must use SHT_PROGBITS rather than SHT_MIPS_DWARF.
12629 Even so, we shouldn't force users of the MIPS .section syntax to
12630 incorrectly label the sections as SHT_PROGBITS. The best compromise
12631 seems to be to map SHT_MIPS_DWARF to SHT_PROGBITS before calling the
12632 generic type-checking code. */
12633 if (section_type
== SHT_MIPS_DWARF
)
12634 section_type
= SHT_PROGBITS
;
12636 obj_elf_change_section (section_name
, section_type
, section_flag
,
12637 section_entry_size
, 0, 0, 0);
12639 if (now_seg
->name
!= section_name
)
12640 free (section_name
);
12641 #endif /* OBJ_ELF */
12645 mips_enable_auto_align (void)
12651 s_cons (int log_size
)
12653 segment_info_type
*si
= seg_info (now_seg
);
12654 struct insn_label_list
*l
= si
->label_list
;
12657 label
= l
!= NULL
? l
->label
: NULL
;
12658 mips_emit_delays ();
12659 if (log_size
> 0 && auto_align
)
12660 mips_align (log_size
, 0, label
);
12661 mips_clear_insn_labels ();
12662 cons (1 << log_size
);
12666 s_float_cons (int type
)
12668 segment_info_type
*si
= seg_info (now_seg
);
12669 struct insn_label_list
*l
= si
->label_list
;
12672 label
= l
!= NULL
? l
->label
: NULL
;
12674 mips_emit_delays ();
12679 mips_align (3, 0, label
);
12681 mips_align (2, 0, label
);
12684 mips_clear_insn_labels ();
12689 /* Handle .globl. We need to override it because on Irix 5 you are
12692 where foo is an undefined symbol, to mean that foo should be
12693 considered to be the address of a function. */
12696 s_mips_globl (int x ATTRIBUTE_UNUSED
)
12705 name
= input_line_pointer
;
12706 c
= get_symbol_end ();
12707 symbolP
= symbol_find_or_make (name
);
12708 S_SET_EXTERNAL (symbolP
);
12710 *input_line_pointer
= c
;
12711 SKIP_WHITESPACE ();
12713 /* On Irix 5, every global symbol that is not explicitly labelled as
12714 being a function is apparently labelled as being an object. */
12717 if (!is_end_of_line
[(unsigned char) *input_line_pointer
]
12718 && (*input_line_pointer
!= ','))
12723 secname
= input_line_pointer
;
12724 c
= get_symbol_end ();
12725 sec
= bfd_get_section_by_name (stdoutput
, secname
);
12727 as_bad (_("%s: no such section"), secname
);
12728 *input_line_pointer
= c
;
12730 if (sec
!= NULL
&& (sec
->flags
& SEC_CODE
) != 0)
12731 flag
= BSF_FUNCTION
;
12734 symbol_get_bfdsym (symbolP
)->flags
|= flag
;
12736 c
= *input_line_pointer
;
12739 input_line_pointer
++;
12740 SKIP_WHITESPACE ();
12741 if (is_end_of_line
[(unsigned char) *input_line_pointer
])
12747 demand_empty_rest_of_line ();
12751 s_option (int x ATTRIBUTE_UNUSED
)
12756 opt
= input_line_pointer
;
12757 c
= get_symbol_end ();
12761 /* FIXME: What does this mean? */
12763 else if (strncmp (opt
, "pic", 3) == 0)
12767 i
= atoi (opt
+ 3);
12772 mips_pic
= SVR4_PIC
;
12773 mips_abicalls
= TRUE
;
12776 as_bad (_(".option pic%d not supported"), i
);
12778 if (mips_pic
== SVR4_PIC
)
12780 if (g_switch_seen
&& g_switch_value
!= 0)
12781 as_warn (_("-G may not be used with SVR4 PIC code"));
12782 g_switch_value
= 0;
12783 bfd_set_gp_size (stdoutput
, 0);
12787 as_warn (_("Unrecognized option \"%s\""), opt
);
12789 *input_line_pointer
= c
;
12790 demand_empty_rest_of_line ();
12793 /* This structure is used to hold a stack of .set values. */
12795 struct mips_option_stack
12797 struct mips_option_stack
*next
;
12798 struct mips_set_options options
;
12801 static struct mips_option_stack
*mips_opts_stack
;
12803 /* Handle the .set pseudo-op. */
12806 s_mipsset (int x ATTRIBUTE_UNUSED
)
12808 char *name
= input_line_pointer
, ch
;
12810 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
12811 ++input_line_pointer
;
12812 ch
= *input_line_pointer
;
12813 *input_line_pointer
= '\0';
12815 if (strcmp (name
, "reorder") == 0)
12817 if (mips_opts
.noreorder
)
12820 else if (strcmp (name
, "noreorder") == 0)
12822 if (!mips_opts
.noreorder
)
12823 start_noreorder ();
12825 else if (strncmp (name
, "at=", 3) == 0)
12827 char *s
= name
+ 3;
12829 if (!reg_lookup (&s
, RTYPE_NUM
| RTYPE_GP
, &mips_opts
.at
))
12830 as_bad (_("Unrecognized register name `%s'"), s
);
12832 else if (strcmp (name
, "at") == 0)
12834 mips_opts
.at
= ATREG
;
12836 else if (strcmp (name
, "noat") == 0)
12838 mips_opts
.at
= ZERO
;
12840 else if (strcmp (name
, "macro") == 0)
12842 mips_opts
.warn_about_macros
= 0;
12844 else if (strcmp (name
, "nomacro") == 0)
12846 if (mips_opts
.noreorder
== 0)
12847 as_bad (_("`noreorder' must be set before `nomacro'"));
12848 mips_opts
.warn_about_macros
= 1;
12850 else if (strcmp (name
, "move") == 0 || strcmp (name
, "novolatile") == 0)
12852 mips_opts
.nomove
= 0;
12854 else if (strcmp (name
, "nomove") == 0 || strcmp (name
, "volatile") == 0)
12856 mips_opts
.nomove
= 1;
12858 else if (strcmp (name
, "bopt") == 0)
12860 mips_opts
.nobopt
= 0;
12862 else if (strcmp (name
, "nobopt") == 0)
12864 mips_opts
.nobopt
= 1;
12866 else if (strcmp (name
, "gp=default") == 0)
12867 mips_opts
.gp32
= file_mips_gp32
;
12868 else if (strcmp (name
, "gp=32") == 0)
12869 mips_opts
.gp32
= 1;
12870 else if (strcmp (name
, "gp=64") == 0)
12872 if (!ISA_HAS_64BIT_REGS (mips_opts
.isa
))
12873 as_warn (_("%s isa does not support 64-bit registers"),
12874 mips_cpu_info_from_isa (mips_opts
.isa
)->name
);
12875 mips_opts
.gp32
= 0;
12877 else if (strcmp (name
, "fp=default") == 0)
12878 mips_opts
.fp32
= file_mips_fp32
;
12879 else if (strcmp (name
, "fp=32") == 0)
12880 mips_opts
.fp32
= 1;
12881 else if (strcmp (name
, "fp=64") == 0)
12883 if (!ISA_HAS_64BIT_FPRS (mips_opts
.isa
))
12884 as_warn (_("%s isa does not support 64-bit floating point registers"),
12885 mips_cpu_info_from_isa (mips_opts
.isa
)->name
);
12886 mips_opts
.fp32
= 0;
12888 else if (strcmp (name
, "softfloat") == 0)
12889 mips_opts
.soft_float
= 1;
12890 else if (strcmp (name
, "hardfloat") == 0)
12891 mips_opts
.soft_float
= 0;
12892 else if (strcmp (name
, "singlefloat") == 0)
12893 mips_opts
.single_float
= 1;
12894 else if (strcmp (name
, "doublefloat") == 0)
12895 mips_opts
.single_float
= 0;
12896 else if (strcmp (name
, "mips16") == 0
12897 || strcmp (name
, "MIPS-16") == 0)
12898 mips_opts
.mips16
= 1;
12899 else if (strcmp (name
, "nomips16") == 0
12900 || strcmp (name
, "noMIPS-16") == 0)
12901 mips_opts
.mips16
= 0;
12902 else if (strcmp (name
, "smartmips") == 0)
12904 if (!ISA_SUPPORTS_SMARTMIPS
)
12905 as_warn (_("%s ISA does not support SmartMIPS ASE"),
12906 mips_cpu_info_from_isa (mips_opts
.isa
)->name
);
12907 mips_opts
.ase_smartmips
= 1;
12909 else if (strcmp (name
, "nosmartmips") == 0)
12910 mips_opts
.ase_smartmips
= 0;
12911 else if (strcmp (name
, "mips3d") == 0)
12912 mips_opts
.ase_mips3d
= 1;
12913 else if (strcmp (name
, "nomips3d") == 0)
12914 mips_opts
.ase_mips3d
= 0;
12915 else if (strcmp (name
, "mdmx") == 0)
12916 mips_opts
.ase_mdmx
= 1;
12917 else if (strcmp (name
, "nomdmx") == 0)
12918 mips_opts
.ase_mdmx
= 0;
12919 else if (strcmp (name
, "dsp") == 0)
12921 if (!ISA_SUPPORTS_DSP_ASE
)
12922 as_warn (_("%s ISA does not support DSP ASE"),
12923 mips_cpu_info_from_isa (mips_opts
.isa
)->name
);
12924 mips_opts
.ase_dsp
= 1;
12925 mips_opts
.ase_dspr2
= 0;
12927 else if (strcmp (name
, "nodsp") == 0)
12929 mips_opts
.ase_dsp
= 0;
12930 mips_opts
.ase_dspr2
= 0;
12932 else if (strcmp (name
, "dspr2") == 0)
12934 if (!ISA_SUPPORTS_DSPR2_ASE
)
12935 as_warn (_("%s ISA does not support DSP R2 ASE"),
12936 mips_cpu_info_from_isa (mips_opts
.isa
)->name
);
12937 mips_opts
.ase_dspr2
= 1;
12938 mips_opts
.ase_dsp
= 1;
12940 else if (strcmp (name
, "nodspr2") == 0)
12942 mips_opts
.ase_dspr2
= 0;
12943 mips_opts
.ase_dsp
= 0;
12945 else if (strcmp (name
, "mt") == 0)
12947 if (!ISA_SUPPORTS_MT_ASE
)
12948 as_warn (_("%s ISA does not support MT ASE"),
12949 mips_cpu_info_from_isa (mips_opts
.isa
)->name
);
12950 mips_opts
.ase_mt
= 1;
12952 else if (strcmp (name
, "nomt") == 0)
12953 mips_opts
.ase_mt
= 0;
12954 else if (strncmp (name
, "mips", 4) == 0 || strncmp (name
, "arch=", 5) == 0)
12958 /* Permit the user to change the ISA and architecture on the fly.
12959 Needless to say, misuse can cause serious problems. */
12960 if (strcmp (name
, "mips0") == 0 || strcmp (name
, "arch=default") == 0)
12963 mips_opts
.isa
= file_mips_isa
;
12964 mips_opts
.arch
= file_mips_arch
;
12966 else if (strncmp (name
, "arch=", 5) == 0)
12968 const struct mips_cpu_info
*p
;
12970 p
= mips_parse_cpu("internal use", name
+ 5);
12972 as_bad (_("unknown architecture %s"), name
+ 5);
12975 mips_opts
.arch
= p
->cpu
;
12976 mips_opts
.isa
= p
->isa
;
12979 else if (strncmp (name
, "mips", 4) == 0)
12981 const struct mips_cpu_info
*p
;
12983 p
= mips_parse_cpu("internal use", name
);
12985 as_bad (_("unknown ISA level %s"), name
+ 4);
12988 mips_opts
.arch
= p
->cpu
;
12989 mips_opts
.isa
= p
->isa
;
12993 as_bad (_("unknown ISA or architecture %s"), name
);
12995 switch (mips_opts
.isa
)
13003 mips_opts
.gp32
= 1;
13004 mips_opts
.fp32
= 1;
13011 mips_opts
.gp32
= 0;
13012 mips_opts
.fp32
= 0;
13015 as_bad (_("unknown ISA level %s"), name
+ 4);
13020 mips_opts
.gp32
= file_mips_gp32
;
13021 mips_opts
.fp32
= file_mips_fp32
;
13024 else if (strcmp (name
, "autoextend") == 0)
13025 mips_opts
.noautoextend
= 0;
13026 else if (strcmp (name
, "noautoextend") == 0)
13027 mips_opts
.noautoextend
= 1;
13028 else if (strcmp (name
, "push") == 0)
13030 struct mips_option_stack
*s
;
13032 s
= (struct mips_option_stack
*) xmalloc (sizeof *s
);
13033 s
->next
= mips_opts_stack
;
13034 s
->options
= mips_opts
;
13035 mips_opts_stack
= s
;
13037 else if (strcmp (name
, "pop") == 0)
13039 struct mips_option_stack
*s
;
13041 s
= mips_opts_stack
;
13043 as_bad (_(".set pop with no .set push"));
13046 /* If we're changing the reorder mode we need to handle
13047 delay slots correctly. */
13048 if (s
->options
.noreorder
&& ! mips_opts
.noreorder
)
13049 start_noreorder ();
13050 else if (! s
->options
.noreorder
&& mips_opts
.noreorder
)
13053 mips_opts
= s
->options
;
13054 mips_opts_stack
= s
->next
;
13058 else if (strcmp (name
, "sym32") == 0)
13059 mips_opts
.sym32
= TRUE
;
13060 else if (strcmp (name
, "nosym32") == 0)
13061 mips_opts
.sym32
= FALSE
;
13062 else if (strchr (name
, ','))
13064 /* Generic ".set" directive; use the generic handler. */
13065 *input_line_pointer
= ch
;
13066 input_line_pointer
= name
;
13072 as_warn (_("Tried to set unrecognized symbol: %s\n"), name
);
13074 *input_line_pointer
= ch
;
13075 demand_empty_rest_of_line ();
13078 /* Handle the .abicalls pseudo-op. I believe this is equivalent to
13079 .option pic2. It means to generate SVR4 PIC calls. */
13082 s_abicalls (int ignore ATTRIBUTE_UNUSED
)
13084 mips_pic
= SVR4_PIC
;
13085 mips_abicalls
= TRUE
;
13087 if (g_switch_seen
&& g_switch_value
!= 0)
13088 as_warn (_("-G may not be used with SVR4 PIC code"));
13089 g_switch_value
= 0;
13091 bfd_set_gp_size (stdoutput
, 0);
13092 demand_empty_rest_of_line ();
13095 /* Handle the .cpload pseudo-op. This is used when generating SVR4
13096 PIC code. It sets the $gp register for the function based on the
13097 function address, which is in the register named in the argument.
13098 This uses a relocation against _gp_disp, which is handled specially
13099 by the linker. The result is:
13100 lui $gp,%hi(_gp_disp)
13101 addiu $gp,$gp,%lo(_gp_disp)
13102 addu $gp,$gp,.cpload argument
13103 The .cpload argument is normally $25 == $t9.
13105 The -mno-shared option changes this to:
13106 lui $gp,%hi(__gnu_local_gp)
13107 addiu $gp,$gp,%lo(__gnu_local_gp)
13108 and the argument is ignored. This saves an instruction, but the
13109 resulting code is not position independent; it uses an absolute
13110 address for __gnu_local_gp. Thus code assembled with -mno-shared
13111 can go into an ordinary executable, but not into a shared library. */
13114 s_cpload (int ignore ATTRIBUTE_UNUSED
)
13120 /* If we are not generating SVR4 PIC code, or if this is NewABI code,
13121 .cpload is ignored. */
13122 if (mips_pic
!= SVR4_PIC
|| HAVE_NEWABI
)
13128 /* .cpload should be in a .set noreorder section. */
13129 if (mips_opts
.noreorder
== 0)
13130 as_warn (_(".cpload not in noreorder section"));
13132 reg
= tc_get_register (0);
13134 /* If we need to produce a 64-bit address, we are better off using
13135 the default instruction sequence. */
13136 in_shared
= mips_in_shared
|| HAVE_64BIT_SYMBOLS
;
13138 ex
.X_op
= O_symbol
;
13139 ex
.X_add_symbol
= symbol_find_or_make (in_shared
? "_gp_disp" :
13141 ex
.X_op_symbol
= NULL
;
13142 ex
.X_add_number
= 0;
13144 /* In ELF, this symbol is implicitly an STT_OBJECT symbol. */
13145 symbol_get_bfdsym (ex
.X_add_symbol
)->flags
|= BSF_OBJECT
;
13148 macro_build_lui (&ex
, mips_gp_register
);
13149 macro_build (&ex
, "addiu", "t,r,j", mips_gp_register
,
13150 mips_gp_register
, BFD_RELOC_LO16
);
13152 macro_build (NULL
, "addu", "d,v,t", mips_gp_register
,
13153 mips_gp_register
, reg
);
13156 demand_empty_rest_of_line ();
13159 /* Handle the .cpsetup pseudo-op defined for NewABI PIC code. The syntax is:
13160 .cpsetup $reg1, offset|$reg2, label
13162 If offset is given, this results in:
13163 sd $gp, offset($sp)
13164 lui $gp, %hi(%neg(%gp_rel(label)))
13165 addiu $gp, $gp, %lo(%neg(%gp_rel(label)))
13166 daddu $gp, $gp, $reg1
13168 If $reg2 is given, this results in:
13169 daddu $reg2, $gp, $0
13170 lui $gp, %hi(%neg(%gp_rel(label)))
13171 addiu $gp, $gp, %lo(%neg(%gp_rel(label)))
13172 daddu $gp, $gp, $reg1
13173 $reg1 is normally $25 == $t9.
13175 The -mno-shared option replaces the last three instructions with
13177 addiu $gp,$gp,%lo(_gp) */
13180 s_cpsetup (int ignore ATTRIBUTE_UNUSED
)
13182 expressionS ex_off
;
13183 expressionS ex_sym
;
13186 /* If we are not generating SVR4 PIC code, .cpsetup is ignored.
13187 We also need NewABI support. */
13188 if (mips_pic
!= SVR4_PIC
|| ! HAVE_NEWABI
)
13194 reg1
= tc_get_register (0);
13195 SKIP_WHITESPACE ();
13196 if (*input_line_pointer
!= ',')
13198 as_bad (_("missing argument separator ',' for .cpsetup"));
13202 ++input_line_pointer
;
13203 SKIP_WHITESPACE ();
13204 if (*input_line_pointer
== '$')
13206 mips_cpreturn_register
= tc_get_register (0);
13207 mips_cpreturn_offset
= -1;
13211 mips_cpreturn_offset
= get_absolute_expression ();
13212 mips_cpreturn_register
= -1;
13214 SKIP_WHITESPACE ();
13215 if (*input_line_pointer
!= ',')
13217 as_bad (_("missing argument separator ',' for .cpsetup"));
13221 ++input_line_pointer
;
13222 SKIP_WHITESPACE ();
13223 expression (&ex_sym
);
13226 if (mips_cpreturn_register
== -1)
13228 ex_off
.X_op
= O_constant
;
13229 ex_off
.X_add_symbol
= NULL
;
13230 ex_off
.X_op_symbol
= NULL
;
13231 ex_off
.X_add_number
= mips_cpreturn_offset
;
13233 macro_build (&ex_off
, "sd", "t,o(b)", mips_gp_register
,
13234 BFD_RELOC_LO16
, SP
);
13237 macro_build (NULL
, "daddu", "d,v,t", mips_cpreturn_register
,
13238 mips_gp_register
, 0);
13240 if (mips_in_shared
|| HAVE_64BIT_SYMBOLS
)
13242 macro_build (&ex_sym
, "lui", "t,u", mips_gp_register
,
13243 -1, BFD_RELOC_GPREL16
, BFD_RELOC_MIPS_SUB
,
13246 macro_build (&ex_sym
, "addiu", "t,r,j", mips_gp_register
,
13247 mips_gp_register
, -1, BFD_RELOC_GPREL16
,
13248 BFD_RELOC_MIPS_SUB
, BFD_RELOC_LO16
);
13250 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t", mips_gp_register
,
13251 mips_gp_register
, reg1
);
13257 ex
.X_op
= O_symbol
;
13258 ex
.X_add_symbol
= symbol_find_or_make ("__gnu_local_gp");
13259 ex
.X_op_symbol
= NULL
;
13260 ex
.X_add_number
= 0;
13262 /* In ELF, this symbol is implicitly an STT_OBJECT symbol. */
13263 symbol_get_bfdsym (ex
.X_add_symbol
)->flags
|= BSF_OBJECT
;
13265 macro_build_lui (&ex
, mips_gp_register
);
13266 macro_build (&ex
, "addiu", "t,r,j", mips_gp_register
,
13267 mips_gp_register
, BFD_RELOC_LO16
);
13272 demand_empty_rest_of_line ();
13276 s_cplocal (int ignore ATTRIBUTE_UNUSED
)
13278 /* If we are not generating SVR4 PIC code, or if this is not NewABI code,
13279 .cplocal is ignored. */
13280 if (mips_pic
!= SVR4_PIC
|| ! HAVE_NEWABI
)
13286 mips_gp_register
= tc_get_register (0);
13287 demand_empty_rest_of_line ();
13290 /* Handle the .cprestore pseudo-op. This stores $gp into a given
13291 offset from $sp. The offset is remembered, and after making a PIC
13292 call $gp is restored from that location. */
13295 s_cprestore (int ignore ATTRIBUTE_UNUSED
)
13299 /* If we are not generating SVR4 PIC code, or if this is NewABI code,
13300 .cprestore is ignored. */
13301 if (mips_pic
!= SVR4_PIC
|| HAVE_NEWABI
)
13307 mips_cprestore_offset
= get_absolute_expression ();
13308 mips_cprestore_valid
= 1;
13310 ex
.X_op
= O_constant
;
13311 ex
.X_add_symbol
= NULL
;
13312 ex
.X_op_symbol
= NULL
;
13313 ex
.X_add_number
= mips_cprestore_offset
;
13316 macro_build_ldst_constoffset (&ex
, ADDRESS_STORE_INSN
, mips_gp_register
,
13317 SP
, HAVE_64BIT_ADDRESSES
);
13320 demand_empty_rest_of_line ();
13323 /* Handle the .cpreturn pseudo-op defined for NewABI PIC code. If an offset
13324 was given in the preceding .cpsetup, it results in:
13325 ld $gp, offset($sp)
13327 If a register $reg2 was given there, it results in:
13328 daddu $gp, $reg2, $0 */
13331 s_cpreturn (int ignore ATTRIBUTE_UNUSED
)
13335 /* If we are not generating SVR4 PIC code, .cpreturn is ignored.
13336 We also need NewABI support. */
13337 if (mips_pic
!= SVR4_PIC
|| ! HAVE_NEWABI
)
13344 if (mips_cpreturn_register
== -1)
13346 ex
.X_op
= O_constant
;
13347 ex
.X_add_symbol
= NULL
;
13348 ex
.X_op_symbol
= NULL
;
13349 ex
.X_add_number
= mips_cpreturn_offset
;
13351 macro_build (&ex
, "ld", "t,o(b)", mips_gp_register
, BFD_RELOC_LO16
, SP
);
13354 macro_build (NULL
, "daddu", "d,v,t", mips_gp_register
,
13355 mips_cpreturn_register
, 0);
13358 demand_empty_rest_of_line ();
13361 /* Handle the .dtprelword and .dtpreldword pseudo-ops. They generate
13362 a 32-bit or 64-bit DTP-relative relocation (BYTES says which) for
13363 use in DWARF debug information. */
13366 s_dtprel_internal (size_t bytes
)
13373 if (ex
.X_op
!= O_symbol
)
13375 as_bad (_("Unsupported use of %s"), (bytes
== 8
13378 ignore_rest_of_line ();
13381 p
= frag_more (bytes
);
13382 md_number_to_chars (p
, 0, bytes
);
13383 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
, bytes
, &ex
, FALSE
,
13385 ? BFD_RELOC_MIPS_TLS_DTPREL64
13386 : BFD_RELOC_MIPS_TLS_DTPREL32
));
13388 demand_empty_rest_of_line ();
13391 /* Handle .dtprelword. */
13394 s_dtprelword (int ignore ATTRIBUTE_UNUSED
)
13396 s_dtprel_internal (4);
13399 /* Handle .dtpreldword. */
13402 s_dtpreldword (int ignore ATTRIBUTE_UNUSED
)
13404 s_dtprel_internal (8);
13407 /* Handle the .gpvalue pseudo-op. This is used when generating NewABI PIC
13408 code. It sets the offset to use in gp_rel relocations. */
13411 s_gpvalue (int ignore ATTRIBUTE_UNUSED
)
13413 /* If we are not generating SVR4 PIC code, .gpvalue is ignored.
13414 We also need NewABI support. */
13415 if (mips_pic
!= SVR4_PIC
|| ! HAVE_NEWABI
)
13421 mips_gprel_offset
= get_absolute_expression ();
13423 demand_empty_rest_of_line ();
13426 /* Handle the .gpword pseudo-op. This is used when generating PIC
13427 code. It generates a 32 bit GP relative reloc. */
13430 s_gpword (int ignore ATTRIBUTE_UNUSED
)
13432 segment_info_type
*si
;
13433 struct insn_label_list
*l
;
13438 /* When not generating PIC code, this is treated as .word. */
13439 if (mips_pic
!= SVR4_PIC
)
13445 si
= seg_info (now_seg
);
13446 l
= si
->label_list
;
13447 label
= l
!= NULL
? l
->label
: NULL
;
13448 mips_emit_delays ();
13450 mips_align (2, 0, label
);
13451 mips_clear_insn_labels ();
13455 if (ex
.X_op
!= O_symbol
|| ex
.X_add_number
!= 0)
13457 as_bad (_("Unsupported use of .gpword"));
13458 ignore_rest_of_line ();
13462 md_number_to_chars (p
, 0, 4);
13463 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
, 4, &ex
, FALSE
,
13464 BFD_RELOC_GPREL32
);
13466 demand_empty_rest_of_line ();
13470 s_gpdword (int ignore ATTRIBUTE_UNUSED
)
13472 segment_info_type
*si
;
13473 struct insn_label_list
*l
;
13478 /* When not generating PIC code, this is treated as .dword. */
13479 if (mips_pic
!= SVR4_PIC
)
13485 si
= seg_info (now_seg
);
13486 l
= si
->label_list
;
13487 label
= l
!= NULL
? l
->label
: NULL
;
13488 mips_emit_delays ();
13490 mips_align (3, 0, label
);
13491 mips_clear_insn_labels ();
13495 if (ex
.X_op
!= O_symbol
|| ex
.X_add_number
!= 0)
13497 as_bad (_("Unsupported use of .gpdword"));
13498 ignore_rest_of_line ();
13502 md_number_to_chars (p
, 0, 8);
13503 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
, 4, &ex
, FALSE
,
13504 BFD_RELOC_GPREL32
)->fx_tcbit
= 1;
13506 /* GPREL32 composed with 64 gives a 64-bit GP offset. */
13507 fix_new (frag_now
, p
- frag_now
->fr_literal
, 8, NULL
, 0,
13508 FALSE
, BFD_RELOC_64
)->fx_tcbit
= 1;
13510 demand_empty_rest_of_line ();
13513 /* Handle the .cpadd pseudo-op. This is used when dealing with switch
13514 tables in SVR4 PIC code. */
13517 s_cpadd (int ignore ATTRIBUTE_UNUSED
)
13521 /* This is ignored when not generating SVR4 PIC code. */
13522 if (mips_pic
!= SVR4_PIC
)
13528 /* Add $gp to the register named as an argument. */
13530 reg
= tc_get_register (0);
13531 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t", reg
, reg
, mips_gp_register
);
13534 demand_empty_rest_of_line ();
13537 /* Handle the .insn pseudo-op. This marks instruction labels in
13538 mips16 mode. This permits the linker to handle them specially,
13539 such as generating jalx instructions when needed. We also make
13540 them odd for the duration of the assembly, in order to generate the
13541 right sort of code. We will make them even in the adjust_symtab
13542 routine, while leaving them marked. This is convenient for the
13543 debugger and the disassembler. The linker knows to make them odd
13547 s_insn (int ignore ATTRIBUTE_UNUSED
)
13549 mips16_mark_labels ();
13551 demand_empty_rest_of_line ();
13554 /* Handle a .stabn directive. We need these in order to mark a label
13555 as being a mips16 text label correctly. Sometimes the compiler
13556 will emit a label, followed by a .stabn, and then switch sections.
13557 If the label and .stabn are in mips16 mode, then the label is
13558 really a mips16 text label. */
13561 s_mips_stab (int type
)
13564 mips16_mark_labels ();
13569 /* Handle the .weakext pseudo-op as defined in Kane and Heinrich. */
13572 s_mips_weakext (int ignore ATTRIBUTE_UNUSED
)
13579 name
= input_line_pointer
;
13580 c
= get_symbol_end ();
13581 symbolP
= symbol_find_or_make (name
);
13582 S_SET_WEAK (symbolP
);
13583 *input_line_pointer
= c
;
13585 SKIP_WHITESPACE ();
13587 if (! is_end_of_line
[(unsigned char) *input_line_pointer
])
13589 if (S_IS_DEFINED (symbolP
))
13591 as_bad (_("ignoring attempt to redefine symbol %s"),
13592 S_GET_NAME (symbolP
));
13593 ignore_rest_of_line ();
13597 if (*input_line_pointer
== ',')
13599 ++input_line_pointer
;
13600 SKIP_WHITESPACE ();
13604 if (exp
.X_op
!= O_symbol
)
13606 as_bad (_("bad .weakext directive"));
13607 ignore_rest_of_line ();
13610 symbol_set_value_expression (symbolP
, &exp
);
13613 demand_empty_rest_of_line ();
13616 /* Parse a register string into a number. Called from the ECOFF code
13617 to parse .frame. The argument is non-zero if this is the frame
13618 register, so that we can record it in mips_frame_reg. */
13621 tc_get_register (int frame
)
13625 SKIP_WHITESPACE ();
13626 if (! reg_lookup (&input_line_pointer
, RWARN
| RTYPE_NUM
| RTYPE_GP
, ®
))
13630 mips_frame_reg
= reg
!= 0 ? reg
: SP
;
13631 mips_frame_reg_valid
= 1;
13632 mips_cprestore_valid
= 0;
13638 md_section_align (asection
*seg
, valueT addr
)
13640 int align
= bfd_get_section_alignment (stdoutput
, seg
);
13644 /* We don't need to align ELF sections to the full alignment.
13645 However, Irix 5 may prefer that we align them at least to a 16
13646 byte boundary. We don't bother to align the sections if we
13647 are targeted for an embedded system. */
13648 if (strncmp (TARGET_OS
, "elf", 3) == 0)
13654 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
13657 /* Utility routine, called from above as well. If called while the
13658 input file is still being read, it's only an approximation. (For
13659 example, a symbol may later become defined which appeared to be
13660 undefined earlier.) */
13663 nopic_need_relax (symbolS
*sym
, int before_relaxing
)
13668 if (g_switch_value
> 0)
13670 const char *symname
;
13673 /* Find out whether this symbol can be referenced off the $gp
13674 register. It can be if it is smaller than the -G size or if
13675 it is in the .sdata or .sbss section. Certain symbols can
13676 not be referenced off the $gp, although it appears as though
13678 symname
= S_GET_NAME (sym
);
13679 if (symname
!= (const char *) NULL
13680 && (strcmp (symname
, "eprol") == 0
13681 || strcmp (symname
, "etext") == 0
13682 || strcmp (symname
, "_gp") == 0
13683 || strcmp (symname
, "edata") == 0
13684 || strcmp (symname
, "_fbss") == 0
13685 || strcmp (symname
, "_fdata") == 0
13686 || strcmp (symname
, "_ftext") == 0
13687 || strcmp (symname
, "end") == 0
13688 || strcmp (symname
, "_gp_disp") == 0))
13690 else if ((! S_IS_DEFINED (sym
) || S_IS_COMMON (sym
))
13692 #ifndef NO_ECOFF_DEBUGGING
13693 || (symbol_get_obj (sym
)->ecoff_extern_size
!= 0
13694 && (symbol_get_obj (sym
)->ecoff_extern_size
13695 <= g_switch_value
))
13697 /* We must defer this decision until after the whole
13698 file has been read, since there might be a .extern
13699 after the first use of this symbol. */
13700 || (before_relaxing
13701 #ifndef NO_ECOFF_DEBUGGING
13702 && symbol_get_obj (sym
)->ecoff_extern_size
== 0
13704 && S_GET_VALUE (sym
) == 0)
13705 || (S_GET_VALUE (sym
) != 0
13706 && S_GET_VALUE (sym
) <= g_switch_value
)))
13710 const char *segname
;
13712 segname
= segment_name (S_GET_SEGMENT (sym
));
13713 gas_assert (strcmp (segname
, ".lit8") != 0
13714 && strcmp (segname
, ".lit4") != 0);
13715 change
= (strcmp (segname
, ".sdata") != 0
13716 && strcmp (segname
, ".sbss") != 0
13717 && strncmp (segname
, ".sdata.", 7) != 0
13718 && strncmp (segname
, ".sbss.", 6) != 0
13719 && strncmp (segname
, ".gnu.linkonce.sb.", 17) != 0
13720 && strncmp (segname
, ".gnu.linkonce.s.", 16) != 0);
13725 /* We are not optimizing for the $gp register. */
13730 /* Return true if the given symbol should be considered local for SVR4 PIC. */
13733 pic_need_relax (symbolS
*sym
, asection
*segtype
)
13737 /* Handle the case of a symbol equated to another symbol. */
13738 while (symbol_equated_reloc_p (sym
))
13742 /* It's possible to get a loop here in a badly written program. */
13743 n
= symbol_get_value_expression (sym
)->X_add_symbol
;
13749 if (symbol_section_p (sym
))
13752 symsec
= S_GET_SEGMENT (sym
);
13754 /* This must duplicate the test in adjust_reloc_syms. */
13755 return (symsec
!= &bfd_und_section
13756 && symsec
!= &bfd_abs_section
13757 && !bfd_is_com_section (symsec
)
13758 && !s_is_linkonce (sym
, segtype
)
13760 /* A global or weak symbol is treated as external. */
13761 && (!IS_ELF
|| (! S_IS_WEAK (sym
) && ! S_IS_EXTERNAL (sym
)))
13767 /* Given a mips16 variant frag FRAGP, return non-zero if it needs an
13768 extended opcode. SEC is the section the frag is in. */
13771 mips16_extended_frag (fragS
*fragp
, asection
*sec
, long stretch
)
13774 const struct mips16_immed_operand
*op
;
13776 int mintiny
, maxtiny
;
13780 if (RELAX_MIPS16_USER_SMALL (fragp
->fr_subtype
))
13782 if (RELAX_MIPS16_USER_EXT (fragp
->fr_subtype
))
13785 type
= RELAX_MIPS16_TYPE (fragp
->fr_subtype
);
13786 op
= mips16_immed_operands
;
13787 while (op
->type
!= type
)
13790 gas_assert (op
< mips16_immed_operands
+ MIPS16_NUM_IMMED
);
13795 if (type
== '<' || type
== '>' || type
== '[' || type
== ']')
13798 maxtiny
= 1 << op
->nbits
;
13803 maxtiny
= (1 << op
->nbits
) - 1;
13808 mintiny
= - (1 << (op
->nbits
- 1));
13809 maxtiny
= (1 << (op
->nbits
- 1)) - 1;
13812 sym_frag
= symbol_get_frag (fragp
->fr_symbol
);
13813 val
= S_GET_VALUE (fragp
->fr_symbol
);
13814 symsec
= S_GET_SEGMENT (fragp
->fr_symbol
);
13820 /* We won't have the section when we are called from
13821 mips_relax_frag. However, we will always have been called
13822 from md_estimate_size_before_relax first. If this is a
13823 branch to a different section, we mark it as such. If SEC is
13824 NULL, and the frag is not marked, then it must be a branch to
13825 the same section. */
13828 if (RELAX_MIPS16_LONG_BRANCH (fragp
->fr_subtype
))
13833 /* Must have been called from md_estimate_size_before_relax. */
13836 fragp
->fr_subtype
=
13837 RELAX_MIPS16_MARK_LONG_BRANCH (fragp
->fr_subtype
);
13839 /* FIXME: We should support this, and let the linker
13840 catch branches and loads that are out of range. */
13841 as_bad_where (fragp
->fr_file
, fragp
->fr_line
,
13842 _("unsupported PC relative reference to different section"));
13846 if (fragp
!= sym_frag
&& sym_frag
->fr_address
== 0)
13847 /* Assume non-extended on the first relaxation pass.
13848 The address we have calculated will be bogus if this is
13849 a forward branch to another frag, as the forward frag
13850 will have fr_address == 0. */
13854 /* In this case, we know for sure that the symbol fragment is in
13855 the same section. If the relax_marker of the symbol fragment
13856 differs from the relax_marker of this fragment, we have not
13857 yet adjusted the symbol fragment fr_address. We want to add
13858 in STRETCH in order to get a better estimate of the address.
13859 This particularly matters because of the shift bits. */
13861 && sym_frag
->relax_marker
!= fragp
->relax_marker
)
13865 /* Adjust stretch for any alignment frag. Note that if have
13866 been expanding the earlier code, the symbol may be
13867 defined in what appears to be an earlier frag. FIXME:
13868 This doesn't handle the fr_subtype field, which specifies
13869 a maximum number of bytes to skip when doing an
13871 for (f
= fragp
; f
!= NULL
&& f
!= sym_frag
; f
= f
->fr_next
)
13873 if (f
->fr_type
== rs_align
|| f
->fr_type
== rs_align_code
)
13876 stretch
= - ((- stretch
)
13877 & ~ ((1 << (int) f
->fr_offset
) - 1));
13879 stretch
&= ~ ((1 << (int) f
->fr_offset
) - 1);
13888 addr
= fragp
->fr_address
+ fragp
->fr_fix
;
13890 /* The base address rules are complicated. The base address of
13891 a branch is the following instruction. The base address of a
13892 PC relative load or add is the instruction itself, but if it
13893 is in a delay slot (in which case it can not be extended) use
13894 the address of the instruction whose delay slot it is in. */
13895 if (type
== 'p' || type
== 'q')
13899 /* If we are currently assuming that this frag should be
13900 extended, then, the current address is two bytes
13902 if (RELAX_MIPS16_EXTENDED (fragp
->fr_subtype
))
13905 /* Ignore the low bit in the target, since it will be set
13906 for a text label. */
13907 if ((val
& 1) != 0)
13910 else if (RELAX_MIPS16_JAL_DSLOT (fragp
->fr_subtype
))
13912 else if (RELAX_MIPS16_DSLOT (fragp
->fr_subtype
))
13915 val
-= addr
& ~ ((1 << op
->shift
) - 1);
13917 /* Branch offsets have an implicit 0 in the lowest bit. */
13918 if (type
== 'p' || type
== 'q')
13921 /* If any of the shifted bits are set, we must use an extended
13922 opcode. If the address depends on the size of this
13923 instruction, this can lead to a loop, so we arrange to always
13924 use an extended opcode. We only check this when we are in
13925 the main relaxation loop, when SEC is NULL. */
13926 if ((val
& ((1 << op
->shift
) - 1)) != 0 && sec
== NULL
)
13928 fragp
->fr_subtype
=
13929 RELAX_MIPS16_MARK_LONG_BRANCH (fragp
->fr_subtype
);
13933 /* If we are about to mark a frag as extended because the value
13934 is precisely maxtiny + 1, then there is a chance of an
13935 infinite loop as in the following code:
13940 In this case when the la is extended, foo is 0x3fc bytes
13941 away, so the la can be shrunk, but then foo is 0x400 away, so
13942 the la must be extended. To avoid this loop, we mark the
13943 frag as extended if it was small, and is about to become
13944 extended with a value of maxtiny + 1. */
13945 if (val
== ((maxtiny
+ 1) << op
->shift
)
13946 && ! RELAX_MIPS16_EXTENDED (fragp
->fr_subtype
)
13949 fragp
->fr_subtype
=
13950 RELAX_MIPS16_MARK_LONG_BRANCH (fragp
->fr_subtype
);
13954 else if (symsec
!= absolute_section
&& sec
!= NULL
)
13955 as_bad_where (fragp
->fr_file
, fragp
->fr_line
, _("unsupported relocation"));
13957 if ((val
& ((1 << op
->shift
) - 1)) != 0
13958 || val
< (mintiny
<< op
->shift
)
13959 || val
> (maxtiny
<< op
->shift
))
13965 /* Compute the length of a branch sequence, and adjust the
13966 RELAX_BRANCH_TOOFAR bit accordingly. If FRAGP is NULL, the
13967 worst-case length is computed, with UPDATE being used to indicate
13968 whether an unconditional (-1), branch-likely (+1) or regular (0)
13969 branch is to be computed. */
13971 relaxed_branch_length (fragS
*fragp
, asection
*sec
, int update
)
13973 bfd_boolean toofar
;
13977 && S_IS_DEFINED (fragp
->fr_symbol
)
13978 && sec
== S_GET_SEGMENT (fragp
->fr_symbol
))
13983 val
= S_GET_VALUE (fragp
->fr_symbol
) + fragp
->fr_offset
;
13985 addr
= fragp
->fr_address
+ fragp
->fr_fix
+ 4;
13989 toofar
= val
< - (0x8000 << 2) || val
>= (0x8000 << 2);
13992 /* If the symbol is not defined or it's in a different segment,
13993 assume the user knows what's going on and emit a short
13999 if (fragp
&& update
&& toofar
!= RELAX_BRANCH_TOOFAR (fragp
->fr_subtype
))
14001 = RELAX_BRANCH_ENCODE (RELAX_BRANCH_UNCOND (fragp
->fr_subtype
),
14002 RELAX_BRANCH_LIKELY (fragp
->fr_subtype
),
14003 RELAX_BRANCH_LINK (fragp
->fr_subtype
),
14009 if (fragp
? RELAX_BRANCH_LIKELY (fragp
->fr_subtype
) : (update
> 0))
14012 if (mips_pic
!= NO_PIC
)
14014 /* Additional space for PIC loading of target address. */
14016 if (mips_opts
.isa
== ISA_MIPS1
)
14017 /* Additional space for $at-stabilizing nop. */
14021 /* If branch is conditional. */
14022 if (fragp
? !RELAX_BRANCH_UNCOND (fragp
->fr_subtype
) : (update
>= 0))
14029 /* Estimate the size of a frag before relaxing. Unless this is the
14030 mips16, we are not really relaxing here, and the final size is
14031 encoded in the subtype information. For the mips16, we have to
14032 decide whether we are using an extended opcode or not. */
14035 md_estimate_size_before_relax (fragS
*fragp
, asection
*segtype
)
14039 if (RELAX_BRANCH_P (fragp
->fr_subtype
))
14042 fragp
->fr_var
= relaxed_branch_length (fragp
, segtype
, FALSE
);
14044 return fragp
->fr_var
;
14047 if (RELAX_MIPS16_P (fragp
->fr_subtype
))
14048 /* We don't want to modify the EXTENDED bit here; it might get us
14049 into infinite loops. We change it only in mips_relax_frag(). */
14050 return (RELAX_MIPS16_EXTENDED (fragp
->fr_subtype
) ? 4 : 2);
14052 if (mips_pic
== NO_PIC
)
14053 change
= nopic_need_relax (fragp
->fr_symbol
, 0);
14054 else if (mips_pic
== SVR4_PIC
)
14055 change
= pic_need_relax (fragp
->fr_symbol
, segtype
);
14056 else if (mips_pic
== VXWORKS_PIC
)
14057 /* For vxworks, GOT16 relocations never have a corresponding LO16. */
14064 fragp
->fr_subtype
|= RELAX_USE_SECOND
;
14065 return -RELAX_FIRST (fragp
->fr_subtype
);
14068 return -RELAX_SECOND (fragp
->fr_subtype
);
14071 /* This is called to see whether a reloc against a defined symbol
14072 should be converted into a reloc against a section. */
14075 mips_fix_adjustable (fixS
*fixp
)
14077 if (fixp
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
14078 || fixp
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
14081 if (fixp
->fx_addsy
== NULL
)
14084 /* If symbol SYM is in a mergeable section, relocations of the form
14085 SYM + 0 can usually be made section-relative. The mergeable data
14086 is then identified by the section offset rather than by the symbol.
14088 However, if we're generating REL LO16 relocations, the offset is split
14089 between the LO16 and parterning high part relocation. The linker will
14090 need to recalculate the complete offset in order to correctly identify
14093 The linker has traditionally not looked for the parterning high part
14094 relocation, and has thus allowed orphaned R_MIPS_LO16 relocations to be
14095 placed anywhere. Rather than break backwards compatibility by changing
14096 this, it seems better not to force the issue, and instead keep the
14097 original symbol. This will work with either linker behavior. */
14098 if ((lo16_reloc_p (fixp
->fx_r_type
)
14099 || reloc_needs_lo_p (fixp
->fx_r_type
))
14100 && HAVE_IN_PLACE_ADDENDS
14101 && (S_GET_SEGMENT (fixp
->fx_addsy
)->flags
& SEC_MERGE
) != 0)
14104 /* There is no place to store an in-place offset for JALR relocations. */
14105 if (fixp
->fx_r_type
== BFD_RELOC_MIPS_JALR
&& HAVE_IN_PLACE_ADDENDS
)
14109 /* R_MIPS16_26 relocations against non-MIPS16 functions might resolve
14110 to a floating-point stub. The same is true for non-R_MIPS16_26
14111 relocations against MIPS16 functions; in this case, the stub becomes
14112 the function's canonical address.
14114 Floating-point stubs are stored in unique .mips16.call.* or
14115 .mips16.fn.* sections. If a stub T for function F is in section S,
14116 the first relocation in section S must be against F; this is how the
14117 linker determines the target function. All relocations that might
14118 resolve to T must also be against F. We therefore have the following
14119 restrictions, which are given in an intentionally-redundant way:
14121 1. We cannot reduce R_MIPS16_26 relocations against non-MIPS16
14124 2. We cannot reduce a stub's relocations against non-MIPS16 symbols
14125 if that stub might be used.
14127 3. We cannot reduce non-R_MIPS16_26 relocations against MIPS16
14130 4. We cannot reduce a stub's relocations against MIPS16 symbols if
14131 that stub might be used.
14133 There is a further restriction:
14135 5. We cannot reduce R_MIPS16_26 relocations against MIPS16 symbols
14136 on targets with in-place addends; the relocation field cannot
14137 encode the low bit.
14139 For simplicity, we deal with (3)-(5) by not reducing _any_ relocation
14140 against a MIPS16 symbol.
14142 We deal with (1)-(2) by saying that, if there's a R_MIPS16_26
14143 relocation against some symbol R, no relocation against R may be
14144 reduced. (Note that this deals with (2) as well as (1) because
14145 relocations against global symbols will never be reduced on ELF
14146 targets.) This approach is a little simpler than trying to detect
14147 stub sections, and gives the "all or nothing" per-symbol consistency
14148 that we have for MIPS16 symbols. */
14150 && fixp
->fx_subsy
== NULL
14151 && (ELF_ST_IS_MIPS16 (S_GET_OTHER (fixp
->fx_addsy
))
14152 || *symbol_get_tc (fixp
->fx_addsy
)))
14159 /* Translate internal representation of relocation info to BFD target
14163 tc_gen_reloc (asection
*section ATTRIBUTE_UNUSED
, fixS
*fixp
)
14165 static arelent
*retval
[4];
14167 bfd_reloc_code_real_type code
;
14169 memset (retval
, 0, sizeof(retval
));
14170 reloc
= retval
[0] = (arelent
*) xcalloc (1, sizeof (arelent
));
14171 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
14172 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
14173 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
14175 if (fixp
->fx_pcrel
)
14177 gas_assert (fixp
->fx_r_type
== BFD_RELOC_16_PCREL_S2
);
14179 /* At this point, fx_addnumber is "symbol offset - pcrel address".
14180 Relocations want only the symbol offset. */
14181 reloc
->addend
= fixp
->fx_addnumber
+ reloc
->address
;
14184 /* A gruesome hack which is a result of the gruesome gas
14185 reloc handling. What's worse, for COFF (as opposed to
14186 ECOFF), we might need yet another copy of reloc->address.
14187 See bfd_install_relocation. */
14188 reloc
->addend
+= reloc
->address
;
14192 reloc
->addend
= fixp
->fx_addnumber
;
14194 /* Since the old MIPS ELF ABI uses Rel instead of Rela, encode the vtable
14195 entry to be used in the relocation's section offset. */
14196 if (! HAVE_NEWABI
&& fixp
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
14198 reloc
->address
= reloc
->addend
;
14202 code
= fixp
->fx_r_type
;
14204 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
14205 if (reloc
->howto
== NULL
)
14207 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
14208 _("Can not represent %s relocation in this object file format"),
14209 bfd_get_reloc_code_name (code
));
14216 /* Relax a machine dependent frag. This returns the amount by which
14217 the current size of the frag should change. */
14220 mips_relax_frag (asection
*sec
, fragS
*fragp
, long stretch
)
14222 if (RELAX_BRANCH_P (fragp
->fr_subtype
))
14224 offsetT old_var
= fragp
->fr_var
;
14226 fragp
->fr_var
= relaxed_branch_length (fragp
, sec
, TRUE
);
14228 return fragp
->fr_var
- old_var
;
14231 if (! RELAX_MIPS16_P (fragp
->fr_subtype
))
14234 if (mips16_extended_frag (fragp
, NULL
, stretch
))
14236 if (RELAX_MIPS16_EXTENDED (fragp
->fr_subtype
))
14238 fragp
->fr_subtype
= RELAX_MIPS16_MARK_EXTENDED (fragp
->fr_subtype
);
14243 if (! RELAX_MIPS16_EXTENDED (fragp
->fr_subtype
))
14245 fragp
->fr_subtype
= RELAX_MIPS16_CLEAR_EXTENDED (fragp
->fr_subtype
);
14252 /* Convert a machine dependent frag. */
14255 md_convert_frag (bfd
*abfd ATTRIBUTE_UNUSED
, segT asec
, fragS
*fragp
)
14257 if (RELAX_BRANCH_P (fragp
->fr_subtype
))
14260 unsigned long insn
;
14264 buf
= (bfd_byte
*)fragp
->fr_literal
+ fragp
->fr_fix
;
14266 if (target_big_endian
)
14267 insn
= bfd_getb32 (buf
);
14269 insn
= bfd_getl32 (buf
);
14271 if (!RELAX_BRANCH_TOOFAR (fragp
->fr_subtype
))
14273 /* We generate a fixup instead of applying it right now
14274 because, if there are linker relaxations, we're going to
14275 need the relocations. */
14276 exp
.X_op
= O_symbol
;
14277 exp
.X_add_symbol
= fragp
->fr_symbol
;
14278 exp
.X_add_number
= fragp
->fr_offset
;
14280 fixp
= fix_new_exp (fragp
, buf
- (bfd_byte
*)fragp
->fr_literal
,
14281 4, &exp
, TRUE
, BFD_RELOC_16_PCREL_S2
);
14282 fixp
->fx_file
= fragp
->fr_file
;
14283 fixp
->fx_line
= fragp
->fr_line
;
14285 md_number_to_chars ((char *) buf
, insn
, 4);
14292 as_warn_where (fragp
->fr_file
, fragp
->fr_line
,
14293 _("relaxed out-of-range branch into a jump"));
14295 if (RELAX_BRANCH_UNCOND (fragp
->fr_subtype
))
14298 if (!RELAX_BRANCH_LIKELY (fragp
->fr_subtype
))
14300 /* Reverse the branch. */
14301 switch ((insn
>> 28) & 0xf)
14304 /* bc[0-3][tf]l? and bc1any[24][ft] instructions can
14305 have the condition reversed by tweaking a single
14306 bit, and their opcodes all have 0x4???????. */
14307 gas_assert ((insn
& 0xf1000000) == 0x41000000);
14308 insn
^= 0x00010000;
14312 /* bltz 0x04000000 bgez 0x04010000
14313 bltzal 0x04100000 bgezal 0x04110000 */
14314 gas_assert ((insn
& 0xfc0e0000) == 0x04000000);
14315 insn
^= 0x00010000;
14319 /* beq 0x10000000 bne 0x14000000
14320 blez 0x18000000 bgtz 0x1c000000 */
14321 insn
^= 0x04000000;
14329 if (RELAX_BRANCH_LINK (fragp
->fr_subtype
))
14331 /* Clear the and-link bit. */
14332 gas_assert ((insn
& 0xfc1c0000) == 0x04100000);
14334 /* bltzal 0x04100000 bgezal 0x04110000
14335 bltzall 0x04120000 bgezall 0x04130000 */
14336 insn
&= ~0x00100000;
14339 /* Branch over the branch (if the branch was likely) or the
14340 full jump (not likely case). Compute the offset from the
14341 current instruction to branch to. */
14342 if (RELAX_BRANCH_LIKELY (fragp
->fr_subtype
))
14346 /* How many bytes in instructions we've already emitted? */
14347 i
= buf
- (bfd_byte
*)fragp
->fr_literal
- fragp
->fr_fix
;
14348 /* How many bytes in instructions from here to the end? */
14349 i
= fragp
->fr_var
- i
;
14351 /* Convert to instruction count. */
14353 /* Branch counts from the next instruction. */
14356 /* Branch over the jump. */
14357 md_number_to_chars ((char *) buf
, insn
, 4);
14361 md_number_to_chars ((char *) buf
, 0, 4);
14364 if (RELAX_BRANCH_LIKELY (fragp
->fr_subtype
))
14366 /* beql $0, $0, 2f */
14368 /* Compute the PC offset from the current instruction to
14369 the end of the variable frag. */
14370 /* How many bytes in instructions we've already emitted? */
14371 i
= buf
- (bfd_byte
*)fragp
->fr_literal
- fragp
->fr_fix
;
14372 /* How many bytes in instructions from here to the end? */
14373 i
= fragp
->fr_var
- i
;
14374 /* Convert to instruction count. */
14376 /* Don't decrement i, because we want to branch over the
14380 md_number_to_chars ((char *) buf
, insn
, 4);
14383 md_number_to_chars ((char *) buf
, 0, 4);
14388 if (mips_pic
== NO_PIC
)
14391 insn
= (RELAX_BRANCH_LINK (fragp
->fr_subtype
)
14392 ? 0x0c000000 : 0x08000000);
14393 exp
.X_op
= O_symbol
;
14394 exp
.X_add_symbol
= fragp
->fr_symbol
;
14395 exp
.X_add_number
= fragp
->fr_offset
;
14397 fixp
= fix_new_exp (fragp
, buf
- (bfd_byte
*)fragp
->fr_literal
,
14398 4, &exp
, FALSE
, BFD_RELOC_MIPS_JMP
);
14399 fixp
->fx_file
= fragp
->fr_file
;
14400 fixp
->fx_line
= fragp
->fr_line
;
14402 md_number_to_chars ((char *) buf
, insn
, 4);
14407 /* lw/ld $at, <sym>($gp) R_MIPS_GOT16 */
14408 insn
= HAVE_64BIT_ADDRESSES
? 0xdf810000 : 0x8f810000;
14409 exp
.X_op
= O_symbol
;
14410 exp
.X_add_symbol
= fragp
->fr_symbol
;
14411 exp
.X_add_number
= fragp
->fr_offset
;
14413 if (fragp
->fr_offset
)
14415 exp
.X_add_symbol
= make_expr_symbol (&exp
);
14416 exp
.X_add_number
= 0;
14419 fixp
= fix_new_exp (fragp
, buf
- (bfd_byte
*)fragp
->fr_literal
,
14420 4, &exp
, FALSE
, BFD_RELOC_MIPS_GOT16
);
14421 fixp
->fx_file
= fragp
->fr_file
;
14422 fixp
->fx_line
= fragp
->fr_line
;
14424 md_number_to_chars ((char *) buf
, insn
, 4);
14427 if (mips_opts
.isa
== ISA_MIPS1
)
14430 md_number_to_chars ((char *) buf
, 0, 4);
14434 /* d/addiu $at, $at, <sym> R_MIPS_LO16 */
14435 insn
= HAVE_64BIT_ADDRESSES
? 0x64210000 : 0x24210000;
14437 fixp
= fix_new_exp (fragp
, buf
- (bfd_byte
*)fragp
->fr_literal
,
14438 4, &exp
, FALSE
, BFD_RELOC_LO16
);
14439 fixp
->fx_file
= fragp
->fr_file
;
14440 fixp
->fx_line
= fragp
->fr_line
;
14442 md_number_to_chars ((char *) buf
, insn
, 4);
14446 if (RELAX_BRANCH_LINK (fragp
->fr_subtype
))
14451 md_number_to_chars ((char *) buf
, insn
, 4);
14456 gas_assert (buf
== (bfd_byte
*)fragp
->fr_literal
14457 + fragp
->fr_fix
+ fragp
->fr_var
);
14459 fragp
->fr_fix
+= fragp
->fr_var
;
14464 if (RELAX_MIPS16_P (fragp
->fr_subtype
))
14467 const struct mips16_immed_operand
*op
;
14468 bfd_boolean small
, ext
;
14471 unsigned long insn
;
14472 bfd_boolean use_extend
;
14473 unsigned short extend
;
14475 type
= RELAX_MIPS16_TYPE (fragp
->fr_subtype
);
14476 op
= mips16_immed_operands
;
14477 while (op
->type
!= type
)
14480 if (RELAX_MIPS16_EXTENDED (fragp
->fr_subtype
))
14491 resolve_symbol_value (fragp
->fr_symbol
);
14492 val
= S_GET_VALUE (fragp
->fr_symbol
);
14497 addr
= fragp
->fr_address
+ fragp
->fr_fix
;
14499 /* The rules for the base address of a PC relative reloc are
14500 complicated; see mips16_extended_frag. */
14501 if (type
== 'p' || type
== 'q')
14506 /* Ignore the low bit in the target, since it will be
14507 set for a text label. */
14508 if ((val
& 1) != 0)
14511 else if (RELAX_MIPS16_JAL_DSLOT (fragp
->fr_subtype
))
14513 else if (RELAX_MIPS16_DSLOT (fragp
->fr_subtype
))
14516 addr
&= ~ (addressT
) ((1 << op
->shift
) - 1);
14519 /* Make sure the section winds up with the alignment we have
14522 record_alignment (asec
, op
->shift
);
14526 && (RELAX_MIPS16_JAL_DSLOT (fragp
->fr_subtype
)
14527 || RELAX_MIPS16_DSLOT (fragp
->fr_subtype
)))
14528 as_warn_where (fragp
->fr_file
, fragp
->fr_line
,
14529 _("extended instruction in delay slot"));
14531 buf
= (bfd_byte
*) (fragp
->fr_literal
+ fragp
->fr_fix
);
14533 if (target_big_endian
)
14534 insn
= bfd_getb16 (buf
);
14536 insn
= bfd_getl16 (buf
);
14538 mips16_immed (fragp
->fr_file
, fragp
->fr_line
, type
, val
,
14539 RELAX_MIPS16_USER_EXT (fragp
->fr_subtype
),
14540 small
, ext
, &insn
, &use_extend
, &extend
);
14544 md_number_to_chars ((char *) buf
, 0xf000 | extend
, 2);
14545 fragp
->fr_fix
+= 2;
14549 md_number_to_chars ((char *) buf
, insn
, 2);
14550 fragp
->fr_fix
+= 2;
14558 first
= RELAX_FIRST (fragp
->fr_subtype
);
14559 second
= RELAX_SECOND (fragp
->fr_subtype
);
14560 fixp
= (fixS
*) fragp
->fr_opcode
;
14562 /* Possibly emit a warning if we've chosen the longer option. */
14563 if (((fragp
->fr_subtype
& RELAX_USE_SECOND
) != 0)
14564 == ((fragp
->fr_subtype
& RELAX_SECOND_LONGER
) != 0))
14566 const char *msg
= macro_warning (fragp
->fr_subtype
);
14568 as_warn_where (fragp
->fr_file
, fragp
->fr_line
, "%s", msg
);
14571 /* Go through all the fixups for the first sequence. Disable them
14572 (by marking them as done) if we're going to use the second
14573 sequence instead. */
14575 && fixp
->fx_frag
== fragp
14576 && fixp
->fx_where
< fragp
->fr_fix
- second
)
14578 if (fragp
->fr_subtype
& RELAX_USE_SECOND
)
14580 fixp
= fixp
->fx_next
;
14583 /* Go through the fixups for the second sequence. Disable them if
14584 we're going to use the first sequence, otherwise adjust their
14585 addresses to account for the relaxation. */
14586 while (fixp
&& fixp
->fx_frag
== fragp
)
14588 if (fragp
->fr_subtype
& RELAX_USE_SECOND
)
14589 fixp
->fx_where
-= first
;
14592 fixp
= fixp
->fx_next
;
14595 /* Now modify the frag contents. */
14596 if (fragp
->fr_subtype
& RELAX_USE_SECOND
)
14600 start
= fragp
->fr_literal
+ fragp
->fr_fix
- first
- second
;
14601 memmove (start
, start
+ first
, second
);
14602 fragp
->fr_fix
-= first
;
14605 fragp
->fr_fix
-= second
;
14611 /* This function is called after the relocs have been generated.
14612 We've been storing mips16 text labels as odd. Here we convert them
14613 back to even for the convenience of the debugger. */
14616 mips_frob_file_after_relocs (void)
14619 unsigned int count
, i
;
14624 syms
= bfd_get_outsymbols (stdoutput
);
14625 count
= bfd_get_symcount (stdoutput
);
14626 for (i
= 0; i
< count
; i
++, syms
++)
14628 if (ELF_ST_IS_MIPS16 (elf_symbol (*syms
)->internal_elf_sym
.st_other
)
14629 && ((*syms
)->value
& 1) != 0)
14631 (*syms
)->value
&= ~1;
14632 /* If the symbol has an odd size, it was probably computed
14633 incorrectly, so adjust that as well. */
14634 if ((elf_symbol (*syms
)->internal_elf_sym
.st_size
& 1) != 0)
14635 ++elf_symbol (*syms
)->internal_elf_sym
.st_size
;
14642 /* This function is called whenever a label is defined. It is used
14643 when handling branch delays; if a branch has a label, we assume we
14644 can not move it. */
14647 mips_define_label (symbolS
*sym
)
14649 segment_info_type
*si
= seg_info (now_seg
);
14650 struct insn_label_list
*l
;
14652 if (free_insn_labels
== NULL
)
14653 l
= (struct insn_label_list
*) xmalloc (sizeof *l
);
14656 l
= free_insn_labels
;
14657 free_insn_labels
= l
->next
;
14661 l
->next
= si
->label_list
;
14662 si
->label_list
= l
;
14665 dwarf2_emit_label (sym
);
14669 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
14671 /* Some special processing for a MIPS ELF file. */
14674 mips_elf_final_processing (void)
14676 /* Write out the register information. */
14677 if (mips_abi
!= N64_ABI
)
14681 s
.ri_gprmask
= mips_gprmask
;
14682 s
.ri_cprmask
[0] = mips_cprmask
[0];
14683 s
.ri_cprmask
[1] = mips_cprmask
[1];
14684 s
.ri_cprmask
[2] = mips_cprmask
[2];
14685 s
.ri_cprmask
[3] = mips_cprmask
[3];
14686 /* The gp_value field is set by the MIPS ELF backend. */
14688 bfd_mips_elf32_swap_reginfo_out (stdoutput
, &s
,
14689 ((Elf32_External_RegInfo
*)
14690 mips_regmask_frag
));
14694 Elf64_Internal_RegInfo s
;
14696 s
.ri_gprmask
= mips_gprmask
;
14698 s
.ri_cprmask
[0] = mips_cprmask
[0];
14699 s
.ri_cprmask
[1] = mips_cprmask
[1];
14700 s
.ri_cprmask
[2] = mips_cprmask
[2];
14701 s
.ri_cprmask
[3] = mips_cprmask
[3];
14702 /* The gp_value field is set by the MIPS ELF backend. */
14704 bfd_mips_elf64_swap_reginfo_out (stdoutput
, &s
,
14705 ((Elf64_External_RegInfo
*)
14706 mips_regmask_frag
));
14709 /* Set the MIPS ELF flag bits. FIXME: There should probably be some
14710 sort of BFD interface for this. */
14711 if (mips_any_noreorder
)
14712 elf_elfheader (stdoutput
)->e_flags
|= EF_MIPS_NOREORDER
;
14713 if (mips_pic
!= NO_PIC
)
14715 elf_elfheader (stdoutput
)->e_flags
|= EF_MIPS_PIC
;
14716 elf_elfheader (stdoutput
)->e_flags
|= EF_MIPS_CPIC
;
14719 elf_elfheader (stdoutput
)->e_flags
|= EF_MIPS_CPIC
;
14721 /* Set MIPS ELF flags for ASEs. */
14722 /* We may need to define a new flag for DSP ASE, and set this flag when
14723 file_ase_dsp is true. */
14724 /* Same for DSP R2. */
14725 /* We may need to define a new flag for MT ASE, and set this flag when
14726 file_ase_mt is true. */
14727 if (file_ase_mips16
)
14728 elf_elfheader (stdoutput
)->e_flags
|= EF_MIPS_ARCH_ASE_M16
;
14729 #if 0 /* XXX FIXME */
14730 if (file_ase_mips3d
)
14731 elf_elfheader (stdoutput
)->e_flags
|= ???;
14734 elf_elfheader (stdoutput
)->e_flags
|= EF_MIPS_ARCH_ASE_MDMX
;
14736 /* Set the MIPS ELF ABI flags. */
14737 if (mips_abi
== O32_ABI
&& USE_E_MIPS_ABI_O32
)
14738 elf_elfheader (stdoutput
)->e_flags
|= E_MIPS_ABI_O32
;
14739 else if (mips_abi
== O64_ABI
)
14740 elf_elfheader (stdoutput
)->e_flags
|= E_MIPS_ABI_O64
;
14741 else if (mips_abi
== EABI_ABI
)
14743 if (!file_mips_gp32
)
14744 elf_elfheader (stdoutput
)->e_flags
|= E_MIPS_ABI_EABI64
;
14746 elf_elfheader (stdoutput
)->e_flags
|= E_MIPS_ABI_EABI32
;
14748 else if (mips_abi
== N32_ABI
)
14749 elf_elfheader (stdoutput
)->e_flags
|= EF_MIPS_ABI2
;
14751 /* Nothing to do for N64_ABI. */
14753 if (mips_32bitmode
)
14754 elf_elfheader (stdoutput
)->e_flags
|= EF_MIPS_32BITMODE
;
14756 #if 0 /* XXX FIXME */
14757 /* 32 bit code with 64 bit FP registers. */
14758 if (!file_mips_fp32
&& ABI_NEEDS_32BIT_REGS (mips_abi
))
14759 elf_elfheader (stdoutput
)->e_flags
|= ???;
14763 #endif /* OBJ_ELF || OBJ_MAYBE_ELF */
14765 typedef struct proc
{
14767 symbolS
*func_end_sym
;
14768 unsigned long reg_mask
;
14769 unsigned long reg_offset
;
14770 unsigned long fpreg_mask
;
14771 unsigned long fpreg_offset
;
14772 unsigned long frame_offset
;
14773 unsigned long frame_reg
;
14774 unsigned long pc_reg
;
14777 static procS cur_proc
;
14778 static procS
*cur_proc_ptr
;
14779 static int numprocs
;
14781 /* Implement NOP_OPCODE. We encode a MIPS16 nop as "1" and a normal
14785 mips_nop_opcode (void)
14787 return seg_info (now_seg
)->tc_segment_info_data
.mips16
;
14790 /* Fill in an rs_align_code fragment. This only needs to do something
14791 for MIPS16 code, where 0 is not a nop. */
14794 mips_handle_align (fragS
*fragp
)
14798 if (fragp
->fr_type
!= rs_align_code
)
14801 p
= fragp
->fr_literal
+ fragp
->fr_fix
;
14806 bytes
= fragp
->fr_next
->fr_address
- fragp
->fr_address
- fragp
->fr_fix
;
14812 md_number_to_chars (p
, mips16_nop_insn
.insn_opcode
, 2);
14818 md_obj_begin (void)
14825 /* Check for premature end, nesting errors, etc. */
14827 as_warn (_("missing .end at end of assembly"));
14836 if (*input_line_pointer
== '-')
14838 ++input_line_pointer
;
14841 if (!ISDIGIT (*input_line_pointer
))
14842 as_bad (_("expected simple number"));
14843 if (input_line_pointer
[0] == '0')
14845 if (input_line_pointer
[1] == 'x')
14847 input_line_pointer
+= 2;
14848 while (ISXDIGIT (*input_line_pointer
))
14851 val
|= hex_value (*input_line_pointer
++);
14853 return negative
? -val
: val
;
14857 ++input_line_pointer
;
14858 while (ISDIGIT (*input_line_pointer
))
14861 val
|= *input_line_pointer
++ - '0';
14863 return negative
? -val
: val
;
14866 if (!ISDIGIT (*input_line_pointer
))
14868 printf (_(" *input_line_pointer == '%c' 0x%02x\n"),
14869 *input_line_pointer
, *input_line_pointer
);
14870 as_warn (_("invalid number"));
14873 while (ISDIGIT (*input_line_pointer
))
14876 val
+= *input_line_pointer
++ - '0';
14878 return negative
? -val
: val
;
14881 /* The .file directive; just like the usual .file directive, but there
14882 is an initial number which is the ECOFF file index. In the non-ECOFF
14883 case .file implies DWARF-2. */
14886 s_mips_file (int x ATTRIBUTE_UNUSED
)
14888 static int first_file_directive
= 0;
14890 if (ECOFF_DEBUGGING
)
14899 filename
= dwarf2_directive_file (0);
14901 /* Versions of GCC up to 3.1 start files with a ".file"
14902 directive even for stabs output. Make sure that this
14903 ".file" is handled. Note that you need a version of GCC
14904 after 3.1 in order to support DWARF-2 on MIPS. */
14905 if (filename
!= NULL
&& ! first_file_directive
)
14907 (void) new_logical_line (filename
, -1);
14908 s_app_file_string (filename
, 0);
14910 first_file_directive
= 1;
14914 /* The .loc directive, implying DWARF-2. */
14917 s_mips_loc (int x ATTRIBUTE_UNUSED
)
14919 if (!ECOFF_DEBUGGING
)
14920 dwarf2_directive_loc (0);
14923 /* The .end directive. */
14926 s_mips_end (int x ATTRIBUTE_UNUSED
)
14930 /* Following functions need their own .frame and .cprestore directives. */
14931 mips_frame_reg_valid
= 0;
14932 mips_cprestore_valid
= 0;
14934 if (!is_end_of_line
[(unsigned char) *input_line_pointer
])
14937 demand_empty_rest_of_line ();
14942 if ((bfd_get_section_flags (stdoutput
, now_seg
) & SEC_CODE
) == 0)
14943 as_warn (_(".end not in text section"));
14947 as_warn (_(".end directive without a preceding .ent directive."));
14948 demand_empty_rest_of_line ();
14954 gas_assert (S_GET_NAME (p
));
14955 if (strcmp (S_GET_NAME (p
), S_GET_NAME (cur_proc_ptr
->func_sym
)))
14956 as_warn (_(".end symbol does not match .ent symbol."));
14958 if (debug_type
== DEBUG_STABS
)
14959 stabs_generate_asm_endfunc (S_GET_NAME (p
),
14963 as_warn (_(".end directive missing or unknown symbol"));
14966 /* Create an expression to calculate the size of the function. */
14967 if (p
&& cur_proc_ptr
)
14969 OBJ_SYMFIELD_TYPE
*obj
= symbol_get_obj (p
);
14970 expressionS
*exp
= xmalloc (sizeof (expressionS
));
14973 exp
->X_op
= O_subtract
;
14974 exp
->X_add_symbol
= symbol_temp_new_now ();
14975 exp
->X_op_symbol
= p
;
14976 exp
->X_add_number
= 0;
14978 cur_proc_ptr
->func_end_sym
= exp
->X_add_symbol
;
14981 /* Generate a .pdr section. */
14982 if (IS_ELF
&& !ECOFF_DEBUGGING
&& mips_flag_pdr
)
14984 segT saved_seg
= now_seg
;
14985 subsegT saved_subseg
= now_subseg
;
14990 dot
= frag_now_fix ();
14992 #ifdef md_flush_pending_output
14993 md_flush_pending_output ();
14996 gas_assert (pdr_seg
);
14997 subseg_set (pdr_seg
, 0);
14999 /* Write the symbol. */
15000 exp
.X_op
= O_symbol
;
15001 exp
.X_add_symbol
= p
;
15002 exp
.X_add_number
= 0;
15003 emit_expr (&exp
, 4);
15005 fragp
= frag_more (7 * 4);
15007 md_number_to_chars (fragp
, cur_proc_ptr
->reg_mask
, 4);
15008 md_number_to_chars (fragp
+ 4, cur_proc_ptr
->reg_offset
, 4);
15009 md_number_to_chars (fragp
+ 8, cur_proc_ptr
->fpreg_mask
, 4);
15010 md_number_to_chars (fragp
+ 12, cur_proc_ptr
->fpreg_offset
, 4);
15011 md_number_to_chars (fragp
+ 16, cur_proc_ptr
->frame_offset
, 4);
15012 md_number_to_chars (fragp
+ 20, cur_proc_ptr
->frame_reg
, 4);
15013 md_number_to_chars (fragp
+ 24, cur_proc_ptr
->pc_reg
, 4);
15015 subseg_set (saved_seg
, saved_subseg
);
15017 #endif /* OBJ_ELF */
15019 cur_proc_ptr
= NULL
;
15022 /* The .aent and .ent directives. */
15025 s_mips_ent (int aent
)
15029 symbolP
= get_symbol ();
15030 if (*input_line_pointer
== ',')
15031 ++input_line_pointer
;
15032 SKIP_WHITESPACE ();
15033 if (ISDIGIT (*input_line_pointer
)
15034 || *input_line_pointer
== '-')
15037 if ((bfd_get_section_flags (stdoutput
, now_seg
) & SEC_CODE
) == 0)
15038 as_warn (_(".ent or .aent not in text section."));
15040 if (!aent
&& cur_proc_ptr
)
15041 as_warn (_("missing .end"));
15045 /* This function needs its own .frame and .cprestore directives. */
15046 mips_frame_reg_valid
= 0;
15047 mips_cprestore_valid
= 0;
15049 cur_proc_ptr
= &cur_proc
;
15050 memset (cur_proc_ptr
, '\0', sizeof (procS
));
15052 cur_proc_ptr
->func_sym
= symbolP
;
15054 symbol_get_bfdsym (symbolP
)->flags
|= BSF_FUNCTION
;
15058 if (debug_type
== DEBUG_STABS
)
15059 stabs_generate_asm_func (S_GET_NAME (symbolP
),
15060 S_GET_NAME (symbolP
));
15063 demand_empty_rest_of_line ();
15066 /* The .frame directive. If the mdebug section is present (IRIX 5 native)
15067 then ecoff.c (ecoff_directive_frame) is used. For embedded targets,
15068 s_mips_frame is used so that we can set the PDR information correctly.
15069 We can't use the ecoff routines because they make reference to the ecoff
15070 symbol table (in the mdebug section). */
15073 s_mips_frame (int ignore ATTRIBUTE_UNUSED
)
15076 if (IS_ELF
&& !ECOFF_DEBUGGING
)
15080 if (cur_proc_ptr
== (procS
*) NULL
)
15082 as_warn (_(".frame outside of .ent"));
15083 demand_empty_rest_of_line ();
15087 cur_proc_ptr
->frame_reg
= tc_get_register (1);
15089 SKIP_WHITESPACE ();
15090 if (*input_line_pointer
++ != ','
15091 || get_absolute_expression_and_terminator (&val
) != ',')
15093 as_warn (_("Bad .frame directive"));
15094 --input_line_pointer
;
15095 demand_empty_rest_of_line ();
15099 cur_proc_ptr
->frame_offset
= val
;
15100 cur_proc_ptr
->pc_reg
= tc_get_register (0);
15102 demand_empty_rest_of_line ();
15105 #endif /* OBJ_ELF */
15109 /* The .fmask and .mask directives. If the mdebug section is present
15110 (IRIX 5 native) then ecoff.c (ecoff_directive_mask) is used. For
15111 embedded targets, s_mips_mask is used so that we can set the PDR
15112 information correctly. We can't use the ecoff routines because they
15113 make reference to the ecoff symbol table (in the mdebug section). */
15116 s_mips_mask (int reg_type
)
15119 if (IS_ELF
&& !ECOFF_DEBUGGING
)
15123 if (cur_proc_ptr
== (procS
*) NULL
)
15125 as_warn (_(".mask/.fmask outside of .ent"));
15126 demand_empty_rest_of_line ();
15130 if (get_absolute_expression_and_terminator (&mask
) != ',')
15132 as_warn (_("Bad .mask/.fmask directive"));
15133 --input_line_pointer
;
15134 demand_empty_rest_of_line ();
15138 off
= get_absolute_expression ();
15140 if (reg_type
== 'F')
15142 cur_proc_ptr
->fpreg_mask
= mask
;
15143 cur_proc_ptr
->fpreg_offset
= off
;
15147 cur_proc_ptr
->reg_mask
= mask
;
15148 cur_proc_ptr
->reg_offset
= off
;
15151 demand_empty_rest_of_line ();
15154 #endif /* OBJ_ELF */
15155 s_ignore (reg_type
);
15158 /* A table describing all the processors gas knows about. Names are
15159 matched in the order listed.
15161 To ease comparison, please keep this table in the same order as
15162 gcc's mips_cpu_info_table[]. */
15163 static const struct mips_cpu_info mips_cpu_info_table
[] =
15165 /* Entries for generic ISAs */
15166 { "mips1", MIPS_CPU_IS_ISA
, ISA_MIPS1
, CPU_R3000
},
15167 { "mips2", MIPS_CPU_IS_ISA
, ISA_MIPS2
, CPU_R6000
},
15168 { "mips3", MIPS_CPU_IS_ISA
, ISA_MIPS3
, CPU_R4000
},
15169 { "mips4", MIPS_CPU_IS_ISA
, ISA_MIPS4
, CPU_R8000
},
15170 { "mips5", MIPS_CPU_IS_ISA
, ISA_MIPS5
, CPU_MIPS5
},
15171 { "mips32", MIPS_CPU_IS_ISA
, ISA_MIPS32
, CPU_MIPS32
},
15172 { "mips32r2", MIPS_CPU_IS_ISA
, ISA_MIPS32R2
, CPU_MIPS32R2
},
15173 { "mips64", MIPS_CPU_IS_ISA
, ISA_MIPS64
, CPU_MIPS64
},
15174 { "mips64r2", MIPS_CPU_IS_ISA
, ISA_MIPS64R2
, CPU_MIPS64R2
},
15177 { "r3000", 0, ISA_MIPS1
, CPU_R3000
},
15178 { "r2000", 0, ISA_MIPS1
, CPU_R3000
},
15179 { "r3900", 0, ISA_MIPS1
, CPU_R3900
},
15182 { "r6000", 0, ISA_MIPS2
, CPU_R6000
},
15185 { "r4000", 0, ISA_MIPS3
, CPU_R4000
},
15186 { "r4010", 0, ISA_MIPS2
, CPU_R4010
},
15187 { "vr4100", 0, ISA_MIPS3
, CPU_VR4100
},
15188 { "vr4111", 0, ISA_MIPS3
, CPU_R4111
},
15189 { "vr4120", 0, ISA_MIPS3
, CPU_VR4120
},
15190 { "vr4130", 0, ISA_MIPS3
, CPU_VR4120
},
15191 { "vr4181", 0, ISA_MIPS3
, CPU_R4111
},
15192 { "vr4300", 0, ISA_MIPS3
, CPU_R4300
},
15193 { "r4400", 0, ISA_MIPS3
, CPU_R4400
},
15194 { "r4600", 0, ISA_MIPS3
, CPU_R4600
},
15195 { "orion", 0, ISA_MIPS3
, CPU_R4600
},
15196 { "r4650", 0, ISA_MIPS3
, CPU_R4650
},
15197 /* ST Microelectronics Loongson 2E and 2F cores */
15198 { "loongson2e", 0, ISA_MIPS3
, CPU_LOONGSON_2E
},
15199 { "loongson2f", 0, ISA_MIPS3
, CPU_LOONGSON_2F
},
15202 { "r8000", 0, ISA_MIPS4
, CPU_R8000
},
15203 { "r10000", 0, ISA_MIPS4
, CPU_R10000
},
15204 { "r12000", 0, ISA_MIPS4
, CPU_R12000
},
15205 { "r14000", 0, ISA_MIPS4
, CPU_R14000
},
15206 { "r16000", 0, ISA_MIPS4
, CPU_R16000
},
15207 { "vr5000", 0, ISA_MIPS4
, CPU_R5000
},
15208 { "vr5400", 0, ISA_MIPS4
, CPU_VR5400
},
15209 { "vr5500", 0, ISA_MIPS4
, CPU_VR5500
},
15210 { "rm5200", 0, ISA_MIPS4
, CPU_R5000
},
15211 { "rm5230", 0, ISA_MIPS4
, CPU_R5000
},
15212 { "rm5231", 0, ISA_MIPS4
, CPU_R5000
},
15213 { "rm5261", 0, ISA_MIPS4
, CPU_R5000
},
15214 { "rm5721", 0, ISA_MIPS4
, CPU_R5000
},
15215 { "rm7000", 0, ISA_MIPS4
, CPU_RM7000
},
15216 { "rm9000", 0, ISA_MIPS4
, CPU_RM9000
},
15219 { "4kc", 0, ISA_MIPS32
, CPU_MIPS32
},
15220 { "4km", 0, ISA_MIPS32
, CPU_MIPS32
},
15221 { "4kp", 0, ISA_MIPS32
, CPU_MIPS32
},
15222 { "4ksc", MIPS_CPU_ASE_SMARTMIPS
, ISA_MIPS32
, CPU_MIPS32
},
15224 /* MIPS 32 Release 2 */
15225 { "4kec", 0, ISA_MIPS32R2
, CPU_MIPS32R2
},
15226 { "4kem", 0, ISA_MIPS32R2
, CPU_MIPS32R2
},
15227 { "4kep", 0, ISA_MIPS32R2
, CPU_MIPS32R2
},
15228 { "4ksd", MIPS_CPU_ASE_SMARTMIPS
, ISA_MIPS32R2
, CPU_MIPS32R2
},
15229 { "m4k", 0, ISA_MIPS32R2
, CPU_MIPS32R2
},
15230 { "m4kp", 0, ISA_MIPS32R2
, CPU_MIPS32R2
},
15231 { "24kc", 0, ISA_MIPS32R2
, CPU_MIPS32R2
},
15232 { "24kf2_1", 0, ISA_MIPS32R2
, CPU_MIPS32R2
},
15233 { "24kf", 0, ISA_MIPS32R2
, CPU_MIPS32R2
},
15234 { "24kf1_1", 0, ISA_MIPS32R2
, CPU_MIPS32R2
},
15235 /* Deprecated forms of the above. */
15236 { "24kfx", 0, ISA_MIPS32R2
, CPU_MIPS32R2
},
15237 { "24kx", 0, ISA_MIPS32R2
, CPU_MIPS32R2
},
15238 /* 24KE is a 24K with DSP ASE, other ASEs are optional. */
15239 { "24kec", MIPS_CPU_ASE_DSP
, ISA_MIPS32R2
, CPU_MIPS32R2
},
15240 { "24kef2_1", MIPS_CPU_ASE_DSP
, ISA_MIPS32R2
, CPU_MIPS32R2
},
15241 { "24kef", MIPS_CPU_ASE_DSP
, ISA_MIPS32R2
, CPU_MIPS32R2
},
15242 { "24kef1_1", MIPS_CPU_ASE_DSP
, ISA_MIPS32R2
, CPU_MIPS32R2
},
15243 /* Deprecated forms of the above. */
15244 { "24kefx", MIPS_CPU_ASE_DSP
, ISA_MIPS32R2
, CPU_MIPS32R2
},
15245 { "24kex", MIPS_CPU_ASE_DSP
, ISA_MIPS32R2
, CPU_MIPS32R2
},
15246 /* 34K is a 24K with DSP and MT ASE, other ASEs are optional. */
15247 { "34kc", MIPS_CPU_ASE_DSP
| MIPS_CPU_ASE_MT
,
15248 ISA_MIPS32R2
, CPU_MIPS32R2
},
15249 { "34kf2_1", MIPS_CPU_ASE_DSP
| MIPS_CPU_ASE_MT
,
15250 ISA_MIPS32R2
, CPU_MIPS32R2
},
15251 { "34kf", MIPS_CPU_ASE_DSP
| MIPS_CPU_ASE_MT
,
15252 ISA_MIPS32R2
, CPU_MIPS32R2
},
15253 { "34kf1_1", MIPS_CPU_ASE_DSP
| MIPS_CPU_ASE_MT
,
15254 ISA_MIPS32R2
, CPU_MIPS32R2
},
15255 /* Deprecated forms of the above. */
15256 { "34kfx", MIPS_CPU_ASE_DSP
| MIPS_CPU_ASE_MT
,
15257 ISA_MIPS32R2
, CPU_MIPS32R2
},
15258 { "34kx", MIPS_CPU_ASE_DSP
| MIPS_CPU_ASE_MT
,
15259 ISA_MIPS32R2
, CPU_MIPS32R2
},
15260 /* 74K with DSP and DSPR2 ASE, other ASEs are optional. */
15261 { "74kc", MIPS_CPU_ASE_DSP
| MIPS_CPU_ASE_DSPR2
,
15262 ISA_MIPS32R2
, CPU_MIPS32R2
},
15263 { "74kf2_1", MIPS_CPU_ASE_DSP
| MIPS_CPU_ASE_DSPR2
,
15264 ISA_MIPS32R2
, CPU_MIPS32R2
},
15265 { "74kf", MIPS_CPU_ASE_DSP
| MIPS_CPU_ASE_DSPR2
,
15266 ISA_MIPS32R2
, CPU_MIPS32R2
},
15267 { "74kf1_1", MIPS_CPU_ASE_DSP
| MIPS_CPU_ASE_DSPR2
,
15268 ISA_MIPS32R2
, CPU_MIPS32R2
},
15269 { "74kf3_2", MIPS_CPU_ASE_DSP
| MIPS_CPU_ASE_DSPR2
,
15270 ISA_MIPS32R2
, CPU_MIPS32R2
},
15271 /* Deprecated forms of the above. */
15272 { "74kfx", MIPS_CPU_ASE_DSP
| MIPS_CPU_ASE_DSPR2
,
15273 ISA_MIPS32R2
, CPU_MIPS32R2
},
15274 { "74kx", MIPS_CPU_ASE_DSP
| MIPS_CPU_ASE_DSPR2
,
15275 ISA_MIPS32R2
, CPU_MIPS32R2
},
15276 /* 1004K cores are multiprocessor versions of the 34K. */
15277 { "1004kc", MIPS_CPU_ASE_DSP
| MIPS_CPU_ASE_MT
,
15278 ISA_MIPS32R2
, CPU_MIPS32R2
},
15279 { "1004kf2_1", MIPS_CPU_ASE_DSP
| MIPS_CPU_ASE_MT
,
15280 ISA_MIPS32R2
, CPU_MIPS32R2
},
15281 { "1004kf", MIPS_CPU_ASE_DSP
| MIPS_CPU_ASE_MT
,
15282 ISA_MIPS32R2
, CPU_MIPS32R2
},
15283 { "1004kf1_1", MIPS_CPU_ASE_DSP
| MIPS_CPU_ASE_MT
,
15284 ISA_MIPS32R2
, CPU_MIPS32R2
},
15287 { "5kc", 0, ISA_MIPS64
, CPU_MIPS64
},
15288 { "5kf", 0, ISA_MIPS64
, CPU_MIPS64
},
15289 { "20kc", MIPS_CPU_ASE_MIPS3D
, ISA_MIPS64
, CPU_MIPS64
},
15290 { "25kf", MIPS_CPU_ASE_MIPS3D
, ISA_MIPS64
, CPU_MIPS64
},
15292 /* Broadcom SB-1 CPU core */
15293 { "sb1", MIPS_CPU_ASE_MIPS3D
| MIPS_CPU_ASE_MDMX
,
15294 ISA_MIPS64
, CPU_SB1
},
15295 /* Broadcom SB-1A CPU core */
15296 { "sb1a", MIPS_CPU_ASE_MIPS3D
| MIPS_CPU_ASE_MDMX
,
15297 ISA_MIPS64
, CPU_SB1
},
15299 /* MIPS 64 Release 2 */
15301 /* Cavium Networks Octeon CPU core */
15302 { "octeon", 0, ISA_MIPS64R2
, CPU_OCTEON
},
15305 { "xlr", 0, ISA_MIPS64
, CPU_XLR
},
15312 /* Return true if GIVEN is the same as CANONICAL, or if it is CANONICAL
15313 with a final "000" replaced by "k". Ignore case.
15315 Note: this function is shared between GCC and GAS. */
15318 mips_strict_matching_cpu_name_p (const char *canonical
, const char *given
)
15320 while (*given
!= 0 && TOLOWER (*given
) == TOLOWER (*canonical
))
15321 given
++, canonical
++;
15323 return ((*given
== 0 && *canonical
== 0)
15324 || (strcmp (canonical
, "000") == 0 && strcasecmp (given
, "k") == 0));
15328 /* Return true if GIVEN matches CANONICAL, where GIVEN is a user-supplied
15329 CPU name. We've traditionally allowed a lot of variation here.
15331 Note: this function is shared between GCC and GAS. */
15334 mips_matching_cpu_name_p (const char *canonical
, const char *given
)
15336 /* First see if the name matches exactly, or with a final "000"
15337 turned into "k". */
15338 if (mips_strict_matching_cpu_name_p (canonical
, given
))
15341 /* If not, try comparing based on numerical designation alone.
15342 See if GIVEN is an unadorned number, or 'r' followed by a number. */
15343 if (TOLOWER (*given
) == 'r')
15345 if (!ISDIGIT (*given
))
15348 /* Skip over some well-known prefixes in the canonical name,
15349 hoping to find a number there too. */
15350 if (TOLOWER (canonical
[0]) == 'v' && TOLOWER (canonical
[1]) == 'r')
15352 else if (TOLOWER (canonical
[0]) == 'r' && TOLOWER (canonical
[1]) == 'm')
15354 else if (TOLOWER (canonical
[0]) == 'r')
15357 return mips_strict_matching_cpu_name_p (canonical
, given
);
15361 /* Parse an option that takes the name of a processor as its argument.
15362 OPTION is the name of the option and CPU_STRING is the argument.
15363 Return the corresponding processor enumeration if the CPU_STRING is
15364 recognized, otherwise report an error and return null.
15366 A similar function exists in GCC. */
15368 static const struct mips_cpu_info
*
15369 mips_parse_cpu (const char *option
, const char *cpu_string
)
15371 const struct mips_cpu_info
*p
;
15373 /* 'from-abi' selects the most compatible architecture for the given
15374 ABI: MIPS I for 32-bit ABIs and MIPS III for 64-bit ABIs. For the
15375 EABIs, we have to decide whether we're using the 32-bit or 64-bit
15376 version. Look first at the -mgp options, if given, otherwise base
15377 the choice on MIPS_DEFAULT_64BIT.
15379 Treat NO_ABI like the EABIs. One reason to do this is that the
15380 plain 'mips' and 'mips64' configs have 'from-abi' as their default
15381 architecture. This code picks MIPS I for 'mips' and MIPS III for
15382 'mips64', just as we did in the days before 'from-abi'. */
15383 if (strcasecmp (cpu_string
, "from-abi") == 0)
15385 if (ABI_NEEDS_32BIT_REGS (mips_abi
))
15386 return mips_cpu_info_from_isa (ISA_MIPS1
);
15388 if (ABI_NEEDS_64BIT_REGS (mips_abi
))
15389 return mips_cpu_info_from_isa (ISA_MIPS3
);
15391 if (file_mips_gp32
>= 0)
15392 return mips_cpu_info_from_isa (file_mips_gp32
? ISA_MIPS1
: ISA_MIPS3
);
15394 return mips_cpu_info_from_isa (MIPS_DEFAULT_64BIT
15399 /* 'default' has traditionally been a no-op. Probably not very useful. */
15400 if (strcasecmp (cpu_string
, "default") == 0)
15403 for (p
= mips_cpu_info_table
; p
->name
!= 0; p
++)
15404 if (mips_matching_cpu_name_p (p
->name
, cpu_string
))
15407 as_bad (_("Bad value (%s) for %s"), cpu_string
, option
);
15411 /* Return the canonical processor information for ISA (a member of the
15412 ISA_MIPS* enumeration). */
15414 static const struct mips_cpu_info
*
15415 mips_cpu_info_from_isa (int isa
)
15419 for (i
= 0; mips_cpu_info_table
[i
].name
!= NULL
; i
++)
15420 if ((mips_cpu_info_table
[i
].flags
& MIPS_CPU_IS_ISA
)
15421 && isa
== mips_cpu_info_table
[i
].isa
)
15422 return (&mips_cpu_info_table
[i
]);
15427 static const struct mips_cpu_info
*
15428 mips_cpu_info_from_arch (int arch
)
15432 for (i
= 0; mips_cpu_info_table
[i
].name
!= NULL
; i
++)
15433 if (arch
== mips_cpu_info_table
[i
].cpu
)
15434 return (&mips_cpu_info_table
[i
]);
15440 show (FILE *stream
, const char *string
, int *col_p
, int *first_p
)
15444 fprintf (stream
, "%24s", "");
15449 fprintf (stream
, ", ");
15453 if (*col_p
+ strlen (string
) > 72)
15455 fprintf (stream
, "\n%24s", "");
15459 fprintf (stream
, "%s", string
);
15460 *col_p
+= strlen (string
);
15466 md_show_usage (FILE *stream
)
15471 fprintf (stream
, _("\
15473 -EB generate big endian output\n\
15474 -EL generate little endian output\n\
15475 -g, -g2 do not remove unneeded NOPs or swap branches\n\
15476 -G NUM allow referencing objects up to NUM bytes\n\
15477 implicitly with the gp register [default 8]\n"));
15478 fprintf (stream
, _("\
15479 -mips1 generate MIPS ISA I instructions\n\
15480 -mips2 generate MIPS ISA II instructions\n\
15481 -mips3 generate MIPS ISA III instructions\n\
15482 -mips4 generate MIPS ISA IV instructions\n\
15483 -mips5 generate MIPS ISA V instructions\n\
15484 -mips32 generate MIPS32 ISA instructions\n\
15485 -mips32r2 generate MIPS32 release 2 ISA instructions\n\
15486 -mips64 generate MIPS64 ISA instructions\n\
15487 -mips64r2 generate MIPS64 release 2 ISA instructions\n\
15488 -march=CPU/-mtune=CPU generate code/schedule for CPU, where CPU is one of:\n"));
15492 for (i
= 0; mips_cpu_info_table
[i
].name
!= NULL
; i
++)
15493 show (stream
, mips_cpu_info_table
[i
].name
, &column
, &first
);
15494 show (stream
, "from-abi", &column
, &first
);
15495 fputc ('\n', stream
);
15497 fprintf (stream
, _("\
15498 -mCPU equivalent to -march=CPU -mtune=CPU. Deprecated.\n\
15499 -no-mCPU don't generate code specific to CPU.\n\
15500 For -mCPU and -no-mCPU, CPU must be one of:\n"));
15504 show (stream
, "3900", &column
, &first
);
15505 show (stream
, "4010", &column
, &first
);
15506 show (stream
, "4100", &column
, &first
);
15507 show (stream
, "4650", &column
, &first
);
15508 fputc ('\n', stream
);
15510 fprintf (stream
, _("\
15511 -mips16 generate mips16 instructions\n\
15512 -no-mips16 do not generate mips16 instructions\n"));
15513 fprintf (stream
, _("\
15514 -msmartmips generate smartmips instructions\n\
15515 -mno-smartmips do not generate smartmips instructions\n"));
15516 fprintf (stream
, _("\
15517 -mdsp generate DSP instructions\n\
15518 -mno-dsp do not generate DSP instructions\n"));
15519 fprintf (stream
, _("\
15520 -mdspr2 generate DSP R2 instructions\n\
15521 -mno-dspr2 do not generate DSP R2 instructions\n"));
15522 fprintf (stream
, _("\
15523 -mmt generate MT instructions\n\
15524 -mno-mt do not generate MT instructions\n"));
15525 fprintf (stream
, _("\
15526 -mfix-vr4120 work around certain VR4120 errata\n\
15527 -mfix-vr4130 work around VR4130 mflo/mfhi errata\n\
15528 -mfix-24k insert a nop after ERET and DERET instructions\n\
15529 -mgp32 use 32-bit GPRs, regardless of the chosen ISA\n\
15530 -mfp32 use 32-bit FPRs, regardless of the chosen ISA\n\
15531 -msym32 assume all symbols have 32-bit values\n\
15532 -O0 remove unneeded NOPs, do not swap branches\n\
15533 -O remove unneeded NOPs and swap branches\n\
15534 --trap, --no-break trap exception on div by 0 and mult overflow\n\
15535 --break, --no-trap break exception on div by 0 and mult overflow\n"));
15536 fprintf (stream
, _("\
15537 -mhard-float allow floating-point instructions\n\
15538 -msoft-float do not allow floating-point instructions\n\
15539 -msingle-float only allow 32-bit floating-point operations\n\
15540 -mdouble-float allow 32-bit and 64-bit floating-point operations\n\
15541 --[no-]construct-floats [dis]allow floating point values to be constructed\n"
15544 fprintf (stream
, _("\
15545 -KPIC, -call_shared generate SVR4 position independent code\n\
15546 -call_nonpic generate non-PIC code that can operate with DSOs\n\
15547 -mvxworks-pic generate VxWorks position independent code\n\
15548 -non_shared do not generate code that can operate with DSOs\n\
15549 -xgot assume a 32 bit GOT\n\
15550 -mpdr, -mno-pdr enable/disable creation of .pdr sections\n\
15551 -mshared, -mno-shared disable/enable .cpload optimization for\n\
15552 position dependent (non shared) code\n\
15553 -mabi=ABI create ABI conformant object file for:\n"));
15557 show (stream
, "32", &column
, &first
);
15558 show (stream
, "o64", &column
, &first
);
15559 show (stream
, "n32", &column
, &first
);
15560 show (stream
, "64", &column
, &first
);
15561 show (stream
, "eabi", &column
, &first
);
15563 fputc ('\n', stream
);
15565 fprintf (stream
, _("\
15566 -32 create o32 ABI object file (default)\n\
15567 -n32 create n32 ABI object file\n\
15568 -64 create 64 ABI object file\n"));
15573 mips_dwarf2_format (asection
*sec ATTRIBUTE_UNUSED
)
15575 if (HAVE_64BIT_SYMBOLS
)
15578 return dwarf2_format_64bit_irix
;
15580 return dwarf2_format_64bit
;
15584 return dwarf2_format_32bit
;
15588 mips_dwarf2_addr_size (void)
15590 if (HAVE_64BIT_OBJECTS
)
15596 /* Standard calling conventions leave the CFA at SP on entry. */
15598 mips_cfi_frame_initial_instructions (void)
15600 cfi_add_CFA_def_cfa_register (SP
);
15604 tc_mips_regname_to_dw2regnum (char *regname
)
15606 unsigned int regnum
= -1;
15609 if (reg_lookup (®name
, RTYPE_GP
| RTYPE_NUM
, ®
))