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 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 2, 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 /* Allow override of standard little-endian ECOFF format. */
106 #ifndef ECOFF_LITTLE_FORMAT
107 #define ECOFF_LITTLE_FORMAT "ecoff-littlemips"
110 extern int target_big_endian
;
112 /* The name of the readonly data section. */
113 #define RDATA_SECTION_NAME (OUTPUT_FLAVOR == bfd_target_ecoff_flavour \
115 : OUTPUT_FLAVOR == bfd_target_coff_flavour \
117 : OUTPUT_FLAVOR == bfd_target_elf_flavour \
121 /* Information about an instruction, including its format, operands
125 /* The opcode's entry in mips_opcodes or mips16_opcodes. */
126 const struct mips_opcode
*insn_mo
;
128 /* True if this is a mips16 instruction and if we want the extended
130 bfd_boolean use_extend
;
132 /* The 16-bit extension instruction to use when USE_EXTEND is true. */
133 unsigned short extend
;
135 /* The 16-bit or 32-bit bitstring of the instruction itself. This is
136 a copy of INSN_MO->match with the operands filled in. */
137 unsigned long insn_opcode
;
139 /* The frag that contains the instruction. */
142 /* The offset into FRAG of the first instruction byte. */
145 /* The relocs associated with the instruction, if any. */
148 /* True if this entry cannot be moved from its current position. */
149 unsigned int fixed_p
: 1;
151 /* True if this instruction occurred in a .set noreorder block. */
152 unsigned int noreorder_p
: 1;
154 /* True for mips16 instructions that jump to an absolute address. */
155 unsigned int mips16_absolute_jump_p
: 1;
158 /* The ABI to use. */
169 /* MIPS ABI we are using for this output file. */
170 static enum mips_abi_level mips_abi
= NO_ABI
;
172 /* Whether or not we have code that can call pic code. */
173 int mips_abicalls
= FALSE
;
175 /* Whether or not we have code which can be put into a shared
177 static bfd_boolean mips_in_shared
= TRUE
;
179 /* This is the set of options which may be modified by the .set
180 pseudo-op. We use a struct so that .set push and .set pop are more
183 struct mips_set_options
185 /* MIPS ISA (Instruction Set Architecture) level. This is set to -1
186 if it has not been initialized. Changed by `.set mipsN', and the
187 -mipsN command line option, and the default CPU. */
189 /* Enabled Application Specific Extensions (ASEs). These are set to -1
190 if they have not been initialized. Changed by `.set <asename>', by
191 command line options, and based on the default architecture. */
197 /* Whether we are assembling for the mips16 processor. 0 if we are
198 not, 1 if we are, and -1 if the value has not been initialized.
199 Changed by `.set mips16' and `.set nomips16', and the -mips16 and
200 -nomips16 command line options, and the default CPU. */
202 /* Non-zero if we should not reorder instructions. Changed by `.set
203 reorder' and `.set noreorder'. */
205 /* Non-zero if we should not permit the $at ($1) register to be used
206 in instructions. Changed by `.set at' and `.set noat'. */
208 /* Non-zero if we should warn when a macro instruction expands into
209 more than one machine instruction. Changed by `.set nomacro' and
211 int warn_about_macros
;
212 /* Non-zero if we should not move instructions. Changed by `.set
213 move', `.set volatile', `.set nomove', and `.set novolatile'. */
215 /* Non-zero if we should not optimize branches by moving the target
216 of the branch into the delay slot. Actually, we don't perform
217 this optimization anyhow. Changed by `.set bopt' and `.set
220 /* Non-zero if we should not autoextend mips16 instructions.
221 Changed by `.set autoextend' and `.set noautoextend'. */
223 /* Restrict general purpose registers and floating point registers
224 to 32 bit. This is initially determined when -mgp32 or -mfp32
225 is passed but can changed if the assembler code uses .set mipsN. */
228 /* MIPS architecture (CPU) type. Changed by .set arch=FOO, the -march
229 command line option, and the default CPU. */
231 /* True if ".set sym32" is in effect. */
235 /* True if -mgp32 was passed. */
236 static int file_mips_gp32
= -1;
238 /* True if -mfp32 was passed. */
239 static int file_mips_fp32
= -1;
241 /* This is the struct we use to hold the current set of options. Note
242 that we must set the isa field to ISA_UNKNOWN and the ASE fields to
243 -1 to indicate that they have not been initialized. */
245 static struct mips_set_options mips_opts
=
247 ISA_UNKNOWN
, -1, -1, 0, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, CPU_UNKNOWN
, FALSE
250 /* These variables are filled in with the masks of registers used.
251 The object format code reads them and puts them in the appropriate
253 unsigned long mips_gprmask
;
254 unsigned long mips_cprmask
[4];
256 /* MIPS ISA we are using for this output file. */
257 static int file_mips_isa
= ISA_UNKNOWN
;
259 /* True if -mips16 was passed or implied by arguments passed on the
260 command line (e.g., by -march). */
261 static int file_ase_mips16
;
263 #define ISA_SUPPORTS_MIPS16E (mips_opts.isa == ISA_MIPS32 \
264 || mips_opts.isa == ISA_MIPS32R2 \
265 || mips_opts.isa == ISA_MIPS64 \
266 || mips_opts.isa == ISA_MIPS64R2)
268 /* True if -mips3d was passed or implied by arguments passed on the
269 command line (e.g., by -march). */
270 static int file_ase_mips3d
;
272 /* True if -mdmx was passed or implied by arguments passed on the
273 command line (e.g., by -march). */
274 static int file_ase_mdmx
;
276 /* True if -msmartmips was passed or implied by arguments passed on the
277 command line (e.g., by -march). */
278 static int file_ase_smartmips
;
280 #define ISA_SUPPORTS_SMARTMIPS (mips_opts.isa == ISA_MIPS32 \
281 || mips_opts.isa == ISA_MIPS32R2)
283 /* True if -mdsp was passed or implied by arguments passed on the
284 command line (e.g., by -march). */
285 static int file_ase_dsp
;
287 #define ISA_SUPPORTS_DSP_ASE (mips_opts.isa == ISA_MIPS32R2 \
288 || mips_opts.isa == ISA_MIPS64R2)
290 #define ISA_SUPPORTS_DSP64_ASE (mips_opts.isa == ISA_MIPS64R2)
292 /* True if -mmt was passed or implied by arguments passed on the
293 command line (e.g., by -march). */
294 static int file_ase_mt
;
296 #define ISA_SUPPORTS_MT_ASE (mips_opts.isa == ISA_MIPS32R2 \
297 || mips_opts.isa == ISA_MIPS64R2)
299 /* The argument of the -march= flag. The architecture we are assembling. */
300 static int file_mips_arch
= CPU_UNKNOWN
;
301 static const char *mips_arch_string
;
303 /* The argument of the -mtune= flag. The architecture for which we
305 static int mips_tune
= CPU_UNKNOWN
;
306 static const char *mips_tune_string
;
308 /* True when generating 32-bit code for a 64-bit processor. */
309 static int mips_32bitmode
= 0;
311 /* True if the given ABI requires 32-bit registers. */
312 #define ABI_NEEDS_32BIT_REGS(ABI) ((ABI) == O32_ABI)
314 /* Likewise 64-bit registers. */
315 #define ABI_NEEDS_64BIT_REGS(ABI) \
317 || (ABI) == N64_ABI \
320 /* Return true if ISA supports 64 bit wide gp registers. */
321 #define ISA_HAS_64BIT_REGS(ISA) \
322 ((ISA) == ISA_MIPS3 \
323 || (ISA) == ISA_MIPS4 \
324 || (ISA) == ISA_MIPS5 \
325 || (ISA) == ISA_MIPS64 \
326 || (ISA) == ISA_MIPS64R2)
328 /* Return true if ISA supports 64 bit wide float registers. */
329 #define ISA_HAS_64BIT_FPRS(ISA) \
330 ((ISA) == ISA_MIPS3 \
331 || (ISA) == ISA_MIPS4 \
332 || (ISA) == ISA_MIPS5 \
333 || (ISA) == ISA_MIPS32R2 \
334 || (ISA) == ISA_MIPS64 \
335 || (ISA) == ISA_MIPS64R2)
337 /* Return true if ISA supports 64-bit right rotate (dror et al.)
339 #define ISA_HAS_DROR(ISA) \
340 ((ISA) == ISA_MIPS64R2)
342 /* Return true if ISA supports 32-bit right rotate (ror et al.)
344 #define ISA_HAS_ROR(ISA) \
345 ((ISA) == ISA_MIPS32R2 \
346 || (ISA) == ISA_MIPS64R2 \
347 || mips_opts.ase_smartmips)
349 /* Return true if ISA supports single-precision floats in odd registers. */
350 #define ISA_HAS_ODD_SINGLE_FPR(ISA) \
351 ((ISA) == ISA_MIPS32 \
352 || (ISA) == ISA_MIPS32R2 \
353 || (ISA) == ISA_MIPS64 \
354 || (ISA) == ISA_MIPS64R2)
356 /* Return true if ISA supports move to/from high part of a 64-bit
357 floating-point register. */
358 #define ISA_HAS_MXHC1(ISA) \
359 ((ISA) == ISA_MIPS32R2 \
360 || (ISA) == ISA_MIPS64R2)
362 #define HAVE_32BIT_GPRS \
363 (mips_opts.gp32 || !ISA_HAS_64BIT_REGS (mips_opts.isa))
365 #define HAVE_32BIT_FPRS \
366 (mips_opts.fp32 || !ISA_HAS_64BIT_FPRS (mips_opts.isa))
368 #define HAVE_64BIT_GPRS (!HAVE_32BIT_GPRS)
369 #define HAVE_64BIT_FPRS (!HAVE_32BIT_FPRS)
371 #define HAVE_NEWABI (mips_abi == N32_ABI || mips_abi == N64_ABI)
373 #define HAVE_64BIT_OBJECTS (mips_abi == N64_ABI)
375 /* True if relocations are stored in-place. */
376 #define HAVE_IN_PLACE_ADDENDS (!HAVE_NEWABI)
378 /* The ABI-derived address size. */
379 #define HAVE_64BIT_ADDRESSES \
380 (HAVE_64BIT_GPRS && (mips_abi == EABI_ABI || mips_abi == N64_ABI))
381 #define HAVE_32BIT_ADDRESSES (!HAVE_64BIT_ADDRESSES)
383 /* The size of symbolic constants (i.e., expressions of the form
384 "SYMBOL" or "SYMBOL + OFFSET"). */
385 #define HAVE_32BIT_SYMBOLS \
386 (HAVE_32BIT_ADDRESSES || !HAVE_64BIT_OBJECTS || mips_opts.sym32)
387 #define HAVE_64BIT_SYMBOLS (!HAVE_32BIT_SYMBOLS)
389 /* Addresses are loaded in different ways, depending on the address size
390 in use. The n32 ABI Documentation also mandates the use of additions
391 with overflow checking, but existing implementations don't follow it. */
392 #define ADDRESS_ADD_INSN \
393 (HAVE_32BIT_ADDRESSES ? "addu" : "daddu")
395 #define ADDRESS_ADDI_INSN \
396 (HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu")
398 #define ADDRESS_LOAD_INSN \
399 (HAVE_32BIT_ADDRESSES ? "lw" : "ld")
401 #define ADDRESS_STORE_INSN \
402 (HAVE_32BIT_ADDRESSES ? "sw" : "sd")
404 /* Return true if the given CPU supports the MIPS16 ASE. */
405 #define CPU_HAS_MIPS16(cpu) \
406 (strncmp (TARGET_CPU, "mips16", sizeof ("mips16") - 1) == 0 \
407 || strncmp (TARGET_CANONICAL, "mips-lsi-elf", sizeof ("mips-lsi-elf") - 1) == 0)
409 /* True if CPU has a dror instruction. */
410 #define CPU_HAS_DROR(CPU) ((CPU) == CPU_VR5400 || (CPU) == CPU_VR5500)
412 /* True if CPU has a ror instruction. */
413 #define CPU_HAS_ROR(CPU) CPU_HAS_DROR (CPU)
415 /* True if mflo and mfhi can be immediately followed by instructions
416 which write to the HI and LO registers.
418 According to MIPS specifications, MIPS ISAs I, II, and III need
419 (at least) two instructions between the reads of HI/LO and
420 instructions which write them, and later ISAs do not. Contradicting
421 the MIPS specifications, some MIPS IV processor user manuals (e.g.
422 the UM for the NEC Vr5000) document needing the instructions between
423 HI/LO reads and writes, as well. Therefore, we declare only MIPS32,
424 MIPS64 and later ISAs to have the interlocks, plus any specific
425 earlier-ISA CPUs for which CPU documentation declares that the
426 instructions are really interlocked. */
427 #define hilo_interlocks \
428 (mips_opts.isa == ISA_MIPS32 \
429 || mips_opts.isa == ISA_MIPS32R2 \
430 || mips_opts.isa == ISA_MIPS64 \
431 || mips_opts.isa == ISA_MIPS64R2 \
432 || mips_opts.arch == CPU_R4010 \
433 || mips_opts.arch == CPU_R10000 \
434 || mips_opts.arch == CPU_R12000 \
435 || mips_opts.arch == CPU_RM7000 \
436 || mips_opts.arch == CPU_VR5500 \
439 /* Whether the processor uses hardware interlocks to protect reads
440 from the GPRs after they are loaded from memory, and thus does not
441 require nops to be inserted. This applies to instructions marked
442 INSN_LOAD_MEMORY_DELAY. These nops are only required at MIPS ISA
444 #define gpr_interlocks \
445 (mips_opts.isa != ISA_MIPS1 \
446 || mips_opts.arch == CPU_R3900)
448 /* Whether the processor uses hardware interlocks to avoid delays
449 required by coprocessor instructions, and thus does not require
450 nops to be inserted. This applies to instructions marked
451 INSN_LOAD_COPROC_DELAY, INSN_COPROC_MOVE_DELAY, and to delays
452 between instructions marked INSN_WRITE_COND_CODE and ones marked
453 INSN_READ_COND_CODE. These nops are only required at MIPS ISA
454 levels I, II, and III. */
455 /* Itbl support may require additional care here. */
456 #define cop_interlocks \
457 ((mips_opts.isa != ISA_MIPS1 \
458 && mips_opts.isa != ISA_MIPS2 \
459 && mips_opts.isa != ISA_MIPS3) \
460 || mips_opts.arch == CPU_R4300 \
463 /* Whether the processor uses hardware interlocks to protect reads
464 from coprocessor registers after they are loaded from memory, and
465 thus does not require nops to be inserted. This applies to
466 instructions marked INSN_COPROC_MEMORY_DELAY. These nops are only
467 requires at MIPS ISA level I. */
468 #define cop_mem_interlocks (mips_opts.isa != ISA_MIPS1)
470 /* Is this a mfhi or mflo instruction? */
471 #define MF_HILO_INSN(PINFO) \
472 ((PINFO & INSN_READ_HI) || (PINFO & INSN_READ_LO))
474 /* MIPS PIC level. */
476 enum mips_pic_level mips_pic
;
478 /* 1 if we should generate 32 bit offsets from the $gp register in
479 SVR4_PIC mode. Currently has no meaning in other modes. */
480 static int mips_big_got
= 0;
482 /* 1 if trap instructions should used for overflow rather than break
484 static int mips_trap
= 0;
486 /* 1 if double width floating point constants should not be constructed
487 by assembling two single width halves into two single width floating
488 point registers which just happen to alias the double width destination
489 register. On some architectures this aliasing can be disabled by a bit
490 in the status register, and the setting of this bit cannot be determined
491 automatically at assemble time. */
492 static int mips_disable_float_construction
;
494 /* Non-zero if any .set noreorder directives were used. */
496 static int mips_any_noreorder
;
498 /* Non-zero if nops should be inserted when the register referenced in
499 an mfhi/mflo instruction is read in the next two instructions. */
500 static int mips_7000_hilo_fix
;
502 /* The size of the small data section. */
503 static unsigned int g_switch_value
= 8;
504 /* Whether the -G option was used. */
505 static int g_switch_seen
= 0;
510 /* If we can determine in advance that GP optimization won't be
511 possible, we can skip the relaxation stuff that tries to produce
512 GP-relative references. This makes delay slot optimization work
515 This function can only provide a guess, but it seems to work for
516 gcc output. It needs to guess right for gcc, otherwise gcc
517 will put what it thinks is a GP-relative instruction in a branch
520 I don't know if a fix is needed for the SVR4_PIC mode. I've only
521 fixed it for the non-PIC mode. KR 95/04/07 */
522 static int nopic_need_relax (symbolS
*, int);
524 /* handle of the OPCODE hash table */
525 static struct hash_control
*op_hash
= NULL
;
527 /* The opcode hash table we use for the mips16. */
528 static struct hash_control
*mips16_op_hash
= NULL
;
530 /* This array holds the chars that always start a comment. If the
531 pre-processor is disabled, these aren't very useful */
532 const char comment_chars
[] = "#";
534 /* This array holds the chars that only start a comment at the beginning of
535 a line. If the line seems to have the form '# 123 filename'
536 .line and .file directives will appear in the pre-processed output */
537 /* Note that input_file.c hand checks for '#' at the beginning of the
538 first line of the input file. This is because the compiler outputs
539 #NO_APP at the beginning of its output. */
540 /* Also note that C style comments are always supported. */
541 const char line_comment_chars
[] = "#";
543 /* This array holds machine specific line separator characters. */
544 const char line_separator_chars
[] = ";";
546 /* Chars that can be used to separate mant from exp in floating point nums */
547 const char EXP_CHARS
[] = "eE";
549 /* Chars that mean this number is a floating point constant */
552 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
554 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
555 changed in read.c . Ideally it shouldn't have to know about it at all,
556 but nothing is ideal around here.
559 static char *insn_error
;
561 static int auto_align
= 1;
563 /* When outputting SVR4 PIC code, the assembler needs to know the
564 offset in the stack frame from which to restore the $gp register.
565 This is set by the .cprestore pseudo-op, and saved in this
567 static offsetT mips_cprestore_offset
= -1;
569 /* Similar for NewABI PIC code, where $gp is callee-saved. NewABI has some
570 more optimizations, it can use a register value instead of a memory-saved
571 offset and even an other register than $gp as global pointer. */
572 static offsetT mips_cpreturn_offset
= -1;
573 static int mips_cpreturn_register
= -1;
574 static int mips_gp_register
= GP
;
575 static int mips_gprel_offset
= 0;
577 /* Whether mips_cprestore_offset has been set in the current function
578 (or whether it has already been warned about, if not). */
579 static int mips_cprestore_valid
= 0;
581 /* This is the register which holds the stack frame, as set by the
582 .frame pseudo-op. This is needed to implement .cprestore. */
583 static int mips_frame_reg
= SP
;
585 /* Whether mips_frame_reg has been set in the current function
586 (or whether it has already been warned about, if not). */
587 static int mips_frame_reg_valid
= 0;
589 /* To output NOP instructions correctly, we need to keep information
590 about the previous two instructions. */
592 /* Whether we are optimizing. The default value of 2 means to remove
593 unneeded NOPs and swap branch instructions when possible. A value
594 of 1 means to not swap branches. A value of 0 means to always
596 static int mips_optimize
= 2;
598 /* Debugging level. -g sets this to 2. -gN sets this to N. -g0 is
599 equivalent to seeing no -g option at all. */
600 static int mips_debug
= 0;
602 /* The maximum number of NOPs needed to avoid the VR4130 mflo/mfhi errata. */
603 #define MAX_VR4130_NOPS 4
605 /* The maximum number of NOPs needed to fill delay slots. */
606 #define MAX_DELAY_NOPS 2
608 /* The maximum number of NOPs needed for any purpose. */
611 /* A list of previous instructions, with index 0 being the most recent.
612 We need to look back MAX_NOPS instructions when filling delay slots
613 or working around processor errata. We need to look back one
614 instruction further if we're thinking about using history[0] to
615 fill a branch delay slot. */
616 static struct mips_cl_insn history
[1 + MAX_NOPS
];
618 /* Nop instructions used by emit_nop. */
619 static struct mips_cl_insn nop_insn
, mips16_nop_insn
;
621 /* The appropriate nop for the current mode. */
622 #define NOP_INSN (mips_opts.mips16 ? &mips16_nop_insn : &nop_insn)
624 /* If this is set, it points to a frag holding nop instructions which
625 were inserted before the start of a noreorder section. If those
626 nops turn out to be unnecessary, the size of the frag can be
628 static fragS
*prev_nop_frag
;
630 /* The number of nop instructions we created in prev_nop_frag. */
631 static int prev_nop_frag_holds
;
633 /* The number of nop instructions that we know we need in
635 static int prev_nop_frag_required
;
637 /* The number of instructions we've seen since prev_nop_frag. */
638 static int prev_nop_frag_since
;
640 /* For ECOFF and ELF, relocations against symbols are done in two
641 parts, with a HI relocation and a LO relocation. Each relocation
642 has only 16 bits of space to store an addend. This means that in
643 order for the linker to handle carries correctly, it must be able
644 to locate both the HI and the LO relocation. This means that the
645 relocations must appear in order in the relocation table.
647 In order to implement this, we keep track of each unmatched HI
648 relocation. We then sort them so that they immediately precede the
649 corresponding LO relocation. */
654 struct mips_hi_fixup
*next
;
657 /* The section this fixup is in. */
661 /* The list of unmatched HI relocs. */
663 static struct mips_hi_fixup
*mips_hi_fixup_list
;
665 /* The frag containing the last explicit relocation operator.
666 Null if explicit relocations have not been used. */
668 static fragS
*prev_reloc_op_frag
;
670 /* Map normal MIPS register numbers to mips16 register numbers. */
672 #define X ILLEGAL_REG
673 static const int mips32_to_16_reg_map
[] =
675 X
, X
, 2, 3, 4, 5, 6, 7,
676 X
, X
, X
, X
, X
, X
, X
, X
,
677 0, 1, X
, X
, X
, X
, X
, X
,
678 X
, X
, X
, X
, X
, X
, X
, X
682 /* Map mips16 register numbers to normal MIPS register numbers. */
684 static const unsigned int mips16_to_32_reg_map
[] =
686 16, 17, 2, 3, 4, 5, 6, 7
689 /* Classifies the kind of instructions we're interested in when
690 implementing -mfix-vr4120. */
691 enum fix_vr4120_class
{
698 NUM_FIX_VR4120_CLASSES
701 /* Given two FIX_VR4120_* values X and Y, bit Y of element X is set if
702 there must be at least one other instruction between an instruction
703 of type X and an instruction of type Y. */
704 static unsigned int vr4120_conflicts
[NUM_FIX_VR4120_CLASSES
];
706 /* True if -mfix-vr4120 is in force. */
707 static int mips_fix_vr4120
;
709 /* ...likewise -mfix-vr4130. */
710 static int mips_fix_vr4130
;
712 /* We don't relax branches by default, since this causes us to expand
713 `la .l2 - .l1' if there's a branch between .l1 and .l2, because we
714 fail to compute the offset before expanding the macro to the most
715 efficient expansion. */
717 static int mips_relax_branch
;
719 /* The expansion of many macros depends on the type of symbol that
720 they refer to. For example, when generating position-dependent code,
721 a macro that refers to a symbol may have two different expansions,
722 one which uses GP-relative addresses and one which uses absolute
723 addresses. When generating SVR4-style PIC, a macro may have
724 different expansions for local and global symbols.
726 We handle these situations by generating both sequences and putting
727 them in variant frags. In position-dependent code, the first sequence
728 will be the GP-relative one and the second sequence will be the
729 absolute one. In SVR4 PIC, the first sequence will be for global
730 symbols and the second will be for local symbols.
732 The frag's "subtype" is RELAX_ENCODE (FIRST, SECOND), where FIRST and
733 SECOND are the lengths of the two sequences in bytes. These fields
734 can be extracted using RELAX_FIRST() and RELAX_SECOND(). In addition,
735 the subtype has the following flags:
738 Set if it has been decided that we should use the second
739 sequence instead of the first.
742 Set in the first variant frag if the macro's second implementation
743 is longer than its first. This refers to the macro as a whole,
744 not an individual relaxation.
747 Set in the first variant frag if the macro appeared in a .set nomacro
748 block and if one alternative requires a warning but the other does not.
751 Like RELAX_NOMACRO, but indicates that the macro appears in a branch
754 The frag's "opcode" points to the first fixup for relaxable code.
756 Relaxable macros are generated using a sequence such as:
758 relax_start (SYMBOL);
759 ... generate first expansion ...
761 ... generate second expansion ...
764 The code and fixups for the unwanted alternative are discarded
765 by md_convert_frag. */
766 #define RELAX_ENCODE(FIRST, SECOND) (((FIRST) << 8) | (SECOND))
768 #define RELAX_FIRST(X) (((X) >> 8) & 0xff)
769 #define RELAX_SECOND(X) ((X) & 0xff)
770 #define RELAX_USE_SECOND 0x10000
771 #define RELAX_SECOND_LONGER 0x20000
772 #define RELAX_NOMACRO 0x40000
773 #define RELAX_DELAY_SLOT 0x80000
775 /* Branch without likely bit. If label is out of range, we turn:
777 beq reg1, reg2, label
787 with the following opcode replacements:
794 bltzal <-> bgezal (with jal label instead of j label)
796 Even though keeping the delay slot instruction in the delay slot of
797 the branch would be more efficient, it would be very tricky to do
798 correctly, because we'd have to introduce a variable frag *after*
799 the delay slot instruction, and expand that instead. Let's do it
800 the easy way for now, even if the branch-not-taken case now costs
801 one additional instruction. Out-of-range branches are not supposed
802 to be common, anyway.
804 Branch likely. If label is out of range, we turn:
806 beql reg1, reg2, label
807 delay slot (annulled if branch not taken)
816 delay slot (executed only if branch taken)
819 It would be possible to generate a shorter sequence by losing the
820 likely bit, generating something like:
825 delay slot (executed only if branch taken)
837 bltzall -> bgezal (with jal label instead of j label)
838 bgezall -> bltzal (ditto)
841 but it's not clear that it would actually improve performance. */
842 #define RELAX_BRANCH_ENCODE(uncond, likely, link, toofar) \
845 | ((toofar) ? 1 : 0) \
847 | ((likely) ? 4 : 0) \
848 | ((uncond) ? 8 : 0)))
849 #define RELAX_BRANCH_P(i) (((i) & 0xf0000000) == 0xc0000000)
850 #define RELAX_BRANCH_UNCOND(i) (((i) & 8) != 0)
851 #define RELAX_BRANCH_LIKELY(i) (((i) & 4) != 0)
852 #define RELAX_BRANCH_LINK(i) (((i) & 2) != 0)
853 #define RELAX_BRANCH_TOOFAR(i) (((i) & 1) != 0)
855 /* For mips16 code, we use an entirely different form of relaxation.
856 mips16 supports two versions of most instructions which take
857 immediate values: a small one which takes some small value, and a
858 larger one which takes a 16 bit value. Since branches also follow
859 this pattern, relaxing these values is required.
861 We can assemble both mips16 and normal MIPS code in a single
862 object. Therefore, we need to support this type of relaxation at
863 the same time that we support the relaxation described above. We
864 use the high bit of the subtype field to distinguish these cases.
866 The information we store for this type of relaxation is the
867 argument code found in the opcode file for this relocation, whether
868 the user explicitly requested a small or extended form, and whether
869 the relocation is in a jump or jal delay slot. That tells us the
870 size of the value, and how it should be stored. We also store
871 whether the fragment is considered to be extended or not. We also
872 store whether this is known to be a branch to a different section,
873 whether we have tried to relax this frag yet, and whether we have
874 ever extended a PC relative fragment because of a shift count. */
875 #define RELAX_MIPS16_ENCODE(type, small, ext, dslot, jal_dslot) \
878 | ((small) ? 0x100 : 0) \
879 | ((ext) ? 0x200 : 0) \
880 | ((dslot) ? 0x400 : 0) \
881 | ((jal_dslot) ? 0x800 : 0))
882 #define RELAX_MIPS16_P(i) (((i) & 0xc0000000) == 0x80000000)
883 #define RELAX_MIPS16_TYPE(i) ((i) & 0xff)
884 #define RELAX_MIPS16_USER_SMALL(i) (((i) & 0x100) != 0)
885 #define RELAX_MIPS16_USER_EXT(i) (((i) & 0x200) != 0)
886 #define RELAX_MIPS16_DSLOT(i) (((i) & 0x400) != 0)
887 #define RELAX_MIPS16_JAL_DSLOT(i) (((i) & 0x800) != 0)
888 #define RELAX_MIPS16_EXTENDED(i) (((i) & 0x1000) != 0)
889 #define RELAX_MIPS16_MARK_EXTENDED(i) ((i) | 0x1000)
890 #define RELAX_MIPS16_CLEAR_EXTENDED(i) ((i) &~ 0x1000)
891 #define RELAX_MIPS16_LONG_BRANCH(i) (((i) & 0x2000) != 0)
892 #define RELAX_MIPS16_MARK_LONG_BRANCH(i) ((i) | 0x2000)
893 #define RELAX_MIPS16_CLEAR_LONG_BRANCH(i) ((i) &~ 0x2000)
895 /* Is the given value a sign-extended 32-bit value? */
896 #define IS_SEXT_32BIT_NUM(x) \
897 (((x) &~ (offsetT) 0x7fffffff) == 0 \
898 || (((x) &~ (offsetT) 0x7fffffff) == ~ (offsetT) 0x7fffffff))
900 /* Is the given value a sign-extended 16-bit value? */
901 #define IS_SEXT_16BIT_NUM(x) \
902 (((x) &~ (offsetT) 0x7fff) == 0 \
903 || (((x) &~ (offsetT) 0x7fff) == ~ (offsetT) 0x7fff))
905 /* Is the given value a zero-extended 32-bit value? Or a negated one? */
906 #define IS_ZEXT_32BIT_NUM(x) \
907 (((x) &~ (offsetT) 0xffffffff) == 0 \
908 || (((x) &~ (offsetT) 0xffffffff) == ~ (offsetT) 0xffffffff))
910 /* Replace bits MASK << SHIFT of STRUCT with the equivalent bits in
911 VALUE << SHIFT. VALUE is evaluated exactly once. */
912 #define INSERT_BITS(STRUCT, VALUE, MASK, SHIFT) \
913 (STRUCT) = (((STRUCT) & ~((MASK) << (SHIFT))) \
914 | (((VALUE) & (MASK)) << (SHIFT)))
916 /* Extract bits MASK << SHIFT from STRUCT and shift them right
918 #define EXTRACT_BITS(STRUCT, MASK, SHIFT) \
919 (((STRUCT) >> (SHIFT)) & (MASK))
921 /* Change INSN's opcode so that the operand given by FIELD has value VALUE.
922 INSN is a mips_cl_insn structure and VALUE is evaluated exactly once.
924 include/opcode/mips.h specifies operand fields using the macros
925 OP_MASK_<FIELD> and OP_SH_<FIELD>. The MIPS16 equivalents start
926 with "MIPS16OP" instead of "OP". */
927 #define INSERT_OPERAND(FIELD, INSN, VALUE) \
928 INSERT_BITS ((INSN).insn_opcode, VALUE, OP_MASK_##FIELD, OP_SH_##FIELD)
929 #define MIPS16_INSERT_OPERAND(FIELD, INSN, VALUE) \
930 INSERT_BITS ((INSN).insn_opcode, VALUE, \
931 MIPS16OP_MASK_##FIELD, MIPS16OP_SH_##FIELD)
933 /* Extract the operand given by FIELD from mips_cl_insn INSN. */
934 #define EXTRACT_OPERAND(FIELD, INSN) \
935 EXTRACT_BITS ((INSN).insn_opcode, OP_MASK_##FIELD, OP_SH_##FIELD)
936 #define MIPS16_EXTRACT_OPERAND(FIELD, INSN) \
937 EXTRACT_BITS ((INSN).insn_opcode, \
938 MIPS16OP_MASK_##FIELD, \
941 /* Global variables used when generating relaxable macros. See the
942 comment above RELAX_ENCODE for more details about how relaxation
945 /* 0 if we're not emitting a relaxable macro.
946 1 if we're emitting the first of the two relaxation alternatives.
947 2 if we're emitting the second alternative. */
950 /* The first relaxable fixup in the current frag. (In other words,
951 the first fixup that refers to relaxable code.) */
954 /* sizes[0] says how many bytes of the first alternative are stored in
955 the current frag. Likewise sizes[1] for the second alternative. */
956 unsigned int sizes
[2];
958 /* The symbol on which the choice of sequence depends. */
962 /* Global variables used to decide whether a macro needs a warning. */
964 /* True if the macro is in a branch delay slot. */
965 bfd_boolean delay_slot_p
;
967 /* For relaxable macros, sizes[0] is the length of the first alternative
968 in bytes and sizes[1] is the length of the second alternative.
969 For non-relaxable macros, both elements give the length of the
971 unsigned int sizes
[2];
973 /* The first variant frag for this macro. */
975 } mips_macro_warning
;
977 /* Prototypes for static functions. */
979 #define internalError() \
980 as_fatal (_("internal Error, line %d, %s"), __LINE__, __FILE__)
982 enum mips_regclass
{ MIPS_GR_REG
, MIPS_FP_REG
, MIPS16_REG
};
984 static void append_insn
985 (struct mips_cl_insn
*ip
, expressionS
*p
, bfd_reloc_code_real_type
*r
);
986 static void mips_no_prev_insn (void);
987 static void mips16_macro_build
988 (expressionS
*, const char *, const char *, va_list);
989 static void load_register (int, expressionS
*, int);
990 static void macro_start (void);
991 static void macro_end (void);
992 static void macro (struct mips_cl_insn
* ip
);
993 static void mips16_macro (struct mips_cl_insn
* ip
);
994 #ifdef LOSING_COMPILER
995 static void macro2 (struct mips_cl_insn
* ip
);
997 static void mips_ip (char *str
, struct mips_cl_insn
* ip
);
998 static void mips16_ip (char *str
, struct mips_cl_insn
* ip
);
999 static void mips16_immed
1000 (char *, unsigned int, int, offsetT
, bfd_boolean
, bfd_boolean
, bfd_boolean
,
1001 unsigned long *, bfd_boolean
*, unsigned short *);
1002 static size_t my_getSmallExpression
1003 (expressionS
*, bfd_reloc_code_real_type
*, char *);
1004 static void my_getExpression (expressionS
*, char *);
1005 static void s_align (int);
1006 static void s_change_sec (int);
1007 static void s_change_section (int);
1008 static void s_cons (int);
1009 static void s_float_cons (int);
1010 static void s_mips_globl (int);
1011 static void s_option (int);
1012 static void s_mipsset (int);
1013 static void s_abicalls (int);
1014 static void s_cpload (int);
1015 static void s_cpsetup (int);
1016 static void s_cplocal (int);
1017 static void s_cprestore (int);
1018 static void s_cpreturn (int);
1019 static void s_gpvalue (int);
1020 static void s_gpword (int);
1021 static void s_gpdword (int);
1022 static void s_cpadd (int);
1023 static void s_insn (int);
1024 static void md_obj_begin (void);
1025 static void md_obj_end (void);
1026 static void s_mips_ent (int);
1027 static void s_mips_end (int);
1028 static void s_mips_frame (int);
1029 static void s_mips_mask (int reg_type
);
1030 static void s_mips_stab (int);
1031 static void s_mips_weakext (int);
1032 static void s_mips_file (int);
1033 static void s_mips_loc (int);
1034 static bfd_boolean
pic_need_relax (symbolS
*, asection
*);
1035 static int relaxed_branch_length (fragS
*, asection
*, int);
1036 static int validate_mips_insn (const struct mips_opcode
*);
1038 /* Table and functions used to map between CPU/ISA names, and
1039 ISA levels, and CPU numbers. */
1041 struct mips_cpu_info
1043 const char *name
; /* CPU or ISA name. */
1044 int flags
; /* ASEs available, or ISA flag. */
1045 int isa
; /* ISA level. */
1046 int cpu
; /* CPU number (default CPU if ISA). */
1049 #define MIPS_CPU_IS_ISA 0x0001 /* Is this an ISA? (If 0, a CPU.) */
1050 #define MIPS_CPU_ASE_SMARTMIPS 0x0002 /* CPU implements SmartMIPS ASE */
1051 #define MIPS_CPU_ASE_DSP 0x0004 /* CPU implements DSP ASE */
1052 #define MIPS_CPU_ASE_MT 0x0008 /* CPU implements MT ASE */
1053 #define MIPS_CPU_ASE_MIPS3D 0x0010 /* CPU implements MIPS-3D ASE */
1054 #define MIPS_CPU_ASE_MDMX 0x0020 /* CPU implements MDMX ASE */
1056 static const struct mips_cpu_info
*mips_parse_cpu (const char *, const char *);
1057 static const struct mips_cpu_info
*mips_cpu_info_from_isa (int);
1058 static const struct mips_cpu_info
*mips_cpu_info_from_arch (int);
1062 The following pseudo-ops from the Kane and Heinrich MIPS book
1063 should be defined here, but are currently unsupported: .alias,
1064 .galive, .gjaldef, .gjrlive, .livereg, .noalias.
1066 The following pseudo-ops from the Kane and Heinrich MIPS book are
1067 specific to the type of debugging information being generated, and
1068 should be defined by the object format: .aent, .begin, .bend,
1069 .bgnb, .end, .endb, .ent, .fmask, .frame, .loc, .mask, .verstamp,
1072 The following pseudo-ops from the Kane and Heinrich MIPS book are
1073 not MIPS CPU specific, but are also not specific to the object file
1074 format. This file is probably the best place to define them, but
1075 they are not currently supported: .asm0, .endr, .lab, .struct. */
1077 static const pseudo_typeS mips_pseudo_table
[] =
1079 /* MIPS specific pseudo-ops. */
1080 {"option", s_option
, 0},
1081 {"set", s_mipsset
, 0},
1082 {"rdata", s_change_sec
, 'r'},
1083 {"sdata", s_change_sec
, 's'},
1084 {"livereg", s_ignore
, 0},
1085 {"abicalls", s_abicalls
, 0},
1086 {"cpload", s_cpload
, 0},
1087 {"cpsetup", s_cpsetup
, 0},
1088 {"cplocal", s_cplocal
, 0},
1089 {"cprestore", s_cprestore
, 0},
1090 {"cpreturn", s_cpreturn
, 0},
1091 {"gpvalue", s_gpvalue
, 0},
1092 {"gpword", s_gpword
, 0},
1093 {"gpdword", s_gpdword
, 0},
1094 {"cpadd", s_cpadd
, 0},
1095 {"insn", s_insn
, 0},
1097 /* Relatively generic pseudo-ops that happen to be used on MIPS
1099 {"asciiz", stringer
, 1},
1100 {"bss", s_change_sec
, 'b'},
1102 {"half", s_cons
, 1},
1103 {"dword", s_cons
, 3},
1104 {"weakext", s_mips_weakext
, 0},
1105 {"origin", s_org
, 0},
1106 {"repeat", s_rept
, 0},
1108 /* These pseudo-ops are defined in read.c, but must be overridden
1109 here for one reason or another. */
1110 {"align", s_align
, 0},
1111 {"byte", s_cons
, 0},
1112 {"data", s_change_sec
, 'd'},
1113 {"double", s_float_cons
, 'd'},
1114 {"float", s_float_cons
, 'f'},
1115 {"globl", s_mips_globl
, 0},
1116 {"global", s_mips_globl
, 0},
1117 {"hword", s_cons
, 1},
1119 {"long", s_cons
, 2},
1120 {"octa", s_cons
, 4},
1121 {"quad", s_cons
, 3},
1122 {"section", s_change_section
, 0},
1123 {"short", s_cons
, 1},
1124 {"single", s_float_cons
, 'f'},
1125 {"stabn", s_mips_stab
, 'n'},
1126 {"text", s_change_sec
, 't'},
1127 {"word", s_cons
, 2},
1129 { "extern", ecoff_directive_extern
, 0},
1134 static const pseudo_typeS mips_nonecoff_pseudo_table
[] =
1136 /* These pseudo-ops should be defined by the object file format.
1137 However, a.out doesn't support them, so we have versions here. */
1138 {"aent", s_mips_ent
, 1},
1139 {"bgnb", s_ignore
, 0},
1140 {"end", s_mips_end
, 0},
1141 {"endb", s_ignore
, 0},
1142 {"ent", s_mips_ent
, 0},
1143 {"file", s_mips_file
, 0},
1144 {"fmask", s_mips_mask
, 'F'},
1145 {"frame", s_mips_frame
, 0},
1146 {"loc", s_mips_loc
, 0},
1147 {"mask", s_mips_mask
, 'R'},
1148 {"verstamp", s_ignore
, 0},
1152 extern void pop_insert (const pseudo_typeS
*);
1155 mips_pop_insert (void)
1157 pop_insert (mips_pseudo_table
);
1158 if (! ECOFF_DEBUGGING
)
1159 pop_insert (mips_nonecoff_pseudo_table
);
1162 /* Symbols labelling the current insn. */
1164 struct insn_label_list
1166 struct insn_label_list
*next
;
1170 static struct insn_label_list
*free_insn_labels
;
1171 #define label_list tc_segment_info_data
1173 static void mips_clear_insn_labels (void);
1176 mips_clear_insn_labels (void)
1178 register struct insn_label_list
**pl
;
1179 segment_info_type
*si
;
1183 for (pl
= &free_insn_labels
; *pl
!= NULL
; pl
= &(*pl
)->next
)
1186 si
= seg_info (now_seg
);
1187 *pl
= si
->label_list
;
1188 si
->label_list
= NULL
;
1193 static char *expr_end
;
1195 /* Expressions which appear in instructions. These are set by
1198 static expressionS imm_expr
;
1199 static expressionS imm2_expr
;
1200 static expressionS offset_expr
;
1202 /* Relocs associated with imm_expr and offset_expr. */
1204 static bfd_reloc_code_real_type imm_reloc
[3]
1205 = {BFD_RELOC_UNUSED
, BFD_RELOC_UNUSED
, BFD_RELOC_UNUSED
};
1206 static bfd_reloc_code_real_type offset_reloc
[3]
1207 = {BFD_RELOC_UNUSED
, BFD_RELOC_UNUSED
, BFD_RELOC_UNUSED
};
1209 /* These are set by mips16_ip if an explicit extension is used. */
1211 static bfd_boolean mips16_small
, mips16_ext
;
1214 /* The pdr segment for per procedure frame/regmask info. Not used for
1217 static segT pdr_seg
;
1220 /* The default target format to use. */
1223 mips_target_format (void)
1225 switch (OUTPUT_FLAVOR
)
1227 case bfd_target_ecoff_flavour
:
1228 return target_big_endian
? "ecoff-bigmips" : ECOFF_LITTLE_FORMAT
;
1229 case bfd_target_coff_flavour
:
1231 case bfd_target_elf_flavour
:
1233 if (!HAVE_64BIT_OBJECTS
&& !HAVE_NEWABI
)
1234 return (target_big_endian
1235 ? "elf32-bigmips-vxworks"
1236 : "elf32-littlemips-vxworks");
1239 /* This is traditional mips. */
1240 return (target_big_endian
1241 ? (HAVE_64BIT_OBJECTS
1242 ? "elf64-tradbigmips"
1244 ? "elf32-ntradbigmips" : "elf32-tradbigmips"))
1245 : (HAVE_64BIT_OBJECTS
1246 ? "elf64-tradlittlemips"
1248 ? "elf32-ntradlittlemips" : "elf32-tradlittlemips")));
1250 return (target_big_endian
1251 ? (HAVE_64BIT_OBJECTS
1254 ? "elf32-nbigmips" : "elf32-bigmips"))
1255 : (HAVE_64BIT_OBJECTS
1256 ? "elf64-littlemips"
1258 ? "elf32-nlittlemips" : "elf32-littlemips")));
1266 /* Return the length of instruction INSN. */
1268 static inline unsigned int
1269 insn_length (const struct mips_cl_insn
*insn
)
1271 if (!mips_opts
.mips16
)
1273 return insn
->mips16_absolute_jump_p
|| insn
->use_extend
? 4 : 2;
1276 /* Initialise INSN from opcode entry MO. Leave its position unspecified. */
1279 create_insn (struct mips_cl_insn
*insn
, const struct mips_opcode
*mo
)
1284 insn
->use_extend
= FALSE
;
1286 insn
->insn_opcode
= mo
->match
;
1289 for (i
= 0; i
< ARRAY_SIZE (insn
->fixp
); i
++)
1290 insn
->fixp
[i
] = NULL
;
1291 insn
->fixed_p
= (mips_opts
.noreorder
> 0);
1292 insn
->noreorder_p
= (mips_opts
.noreorder
> 0);
1293 insn
->mips16_absolute_jump_p
= 0;
1296 /* Install INSN at the location specified by its "frag" and "where" fields. */
1299 install_insn (const struct mips_cl_insn
*insn
)
1301 char *f
= insn
->frag
->fr_literal
+ insn
->where
;
1302 if (!mips_opts
.mips16
)
1303 md_number_to_chars (f
, insn
->insn_opcode
, 4);
1304 else if (insn
->mips16_absolute_jump_p
)
1306 md_number_to_chars (f
, insn
->insn_opcode
>> 16, 2);
1307 md_number_to_chars (f
+ 2, insn
->insn_opcode
& 0xffff, 2);
1311 if (insn
->use_extend
)
1313 md_number_to_chars (f
, 0xf000 | insn
->extend
, 2);
1316 md_number_to_chars (f
, insn
->insn_opcode
, 2);
1320 /* Move INSN to offset WHERE in FRAG. Adjust the fixups accordingly
1321 and install the opcode in the new location. */
1324 move_insn (struct mips_cl_insn
*insn
, fragS
*frag
, long where
)
1329 insn
->where
= where
;
1330 for (i
= 0; i
< ARRAY_SIZE (insn
->fixp
); i
++)
1331 if (insn
->fixp
[i
] != NULL
)
1333 insn
->fixp
[i
]->fx_frag
= frag
;
1334 insn
->fixp
[i
]->fx_where
= where
;
1336 install_insn (insn
);
1339 /* Add INSN to the end of the output. */
1342 add_fixed_insn (struct mips_cl_insn
*insn
)
1344 char *f
= frag_more (insn_length (insn
));
1345 move_insn (insn
, frag_now
, f
- frag_now
->fr_literal
);
1348 /* Start a variant frag and move INSN to the start of the variant part,
1349 marking it as fixed. The other arguments are as for frag_var. */
1352 add_relaxed_insn (struct mips_cl_insn
*insn
, int max_chars
, int var
,
1353 relax_substateT subtype
, symbolS
*symbol
, offsetT offset
)
1355 frag_grow (max_chars
);
1356 move_insn (insn
, frag_now
, frag_more (0) - frag_now
->fr_literal
);
1358 frag_var (rs_machine_dependent
, max_chars
, var
,
1359 subtype
, symbol
, offset
, NULL
);
1362 /* Insert N copies of INSN into the history buffer, starting at
1363 position FIRST. Neither FIRST nor N need to be clipped. */
1366 insert_into_history (unsigned int first
, unsigned int n
,
1367 const struct mips_cl_insn
*insn
)
1369 if (mips_relax
.sequence
!= 2)
1373 for (i
= ARRAY_SIZE (history
); i
-- > first
;)
1375 history
[i
] = history
[i
- n
];
1381 /* Emit a nop instruction, recording it in the history buffer. */
1386 add_fixed_insn (NOP_INSN
);
1387 insert_into_history (0, 1, NOP_INSN
);
1390 /* Initialize vr4120_conflicts. There is a bit of duplication here:
1391 the idea is to make it obvious at a glance that each errata is
1395 init_vr4120_conflicts (void)
1397 #define CONFLICT(FIRST, SECOND) \
1398 vr4120_conflicts[FIX_VR4120_##FIRST] |= 1 << FIX_VR4120_##SECOND
1400 /* Errata 21 - [D]DIV[U] after [D]MACC */
1401 CONFLICT (MACC
, DIV
);
1402 CONFLICT (DMACC
, DIV
);
1404 /* Errata 23 - Continuous DMULT[U]/DMACC instructions. */
1405 CONFLICT (DMULT
, DMULT
);
1406 CONFLICT (DMULT
, DMACC
);
1407 CONFLICT (DMACC
, DMULT
);
1408 CONFLICT (DMACC
, DMACC
);
1410 /* Errata 24 - MT{LO,HI} after [D]MACC */
1411 CONFLICT (MACC
, MTHILO
);
1412 CONFLICT (DMACC
, MTHILO
);
1414 /* VR4181A errata MD(1): "If a MULT, MULTU, DMULT or DMULTU
1415 instruction is executed immediately after a MACC or DMACC
1416 instruction, the result of [either instruction] is incorrect." */
1417 CONFLICT (MACC
, MULT
);
1418 CONFLICT (MACC
, DMULT
);
1419 CONFLICT (DMACC
, MULT
);
1420 CONFLICT (DMACC
, DMULT
);
1422 /* VR4181A errata MD(4): "If a MACC or DMACC instruction is
1423 executed immediately after a DMULT, DMULTU, DIV, DIVU,
1424 DDIV or DDIVU instruction, the result of the MACC or
1425 DMACC instruction is incorrect.". */
1426 CONFLICT (DMULT
, MACC
);
1427 CONFLICT (DMULT
, DMACC
);
1428 CONFLICT (DIV
, MACC
);
1429 CONFLICT (DIV
, DMACC
);
1439 #define RTYPE_MASK 0x1ff00
1440 #define RTYPE_NUM 0x00100
1441 #define RTYPE_FPU 0x00200
1442 #define RTYPE_FCC 0x00400
1443 #define RTYPE_VEC 0x00800
1444 #define RTYPE_GP 0x01000
1445 #define RTYPE_CP0 0x02000
1446 #define RTYPE_PC 0x04000
1447 #define RTYPE_ACC 0x08000
1448 #define RTYPE_CCC 0x10000
1449 #define RNUM_MASK 0x000ff
1450 #define RWARN 0x80000
1452 #define GENERIC_REGISTER_NUMBERS \
1453 {"$0", RTYPE_NUM | 0}, \
1454 {"$1", RTYPE_NUM | 1}, \
1455 {"$2", RTYPE_NUM | 2}, \
1456 {"$3", RTYPE_NUM | 3}, \
1457 {"$4", RTYPE_NUM | 4}, \
1458 {"$5", RTYPE_NUM | 5}, \
1459 {"$6", RTYPE_NUM | 6}, \
1460 {"$7", RTYPE_NUM | 7}, \
1461 {"$8", RTYPE_NUM | 8}, \
1462 {"$9", RTYPE_NUM | 9}, \
1463 {"$10", RTYPE_NUM | 10}, \
1464 {"$11", RTYPE_NUM | 11}, \
1465 {"$12", RTYPE_NUM | 12}, \
1466 {"$13", RTYPE_NUM | 13}, \
1467 {"$14", RTYPE_NUM | 14}, \
1468 {"$15", RTYPE_NUM | 15}, \
1469 {"$16", RTYPE_NUM | 16}, \
1470 {"$17", RTYPE_NUM | 17}, \
1471 {"$18", RTYPE_NUM | 18}, \
1472 {"$19", RTYPE_NUM | 19}, \
1473 {"$20", RTYPE_NUM | 20}, \
1474 {"$21", RTYPE_NUM | 21}, \
1475 {"$22", RTYPE_NUM | 22}, \
1476 {"$23", RTYPE_NUM | 23}, \
1477 {"$24", RTYPE_NUM | 24}, \
1478 {"$25", RTYPE_NUM | 25}, \
1479 {"$26", RTYPE_NUM | 26}, \
1480 {"$27", RTYPE_NUM | 27}, \
1481 {"$28", RTYPE_NUM | 28}, \
1482 {"$29", RTYPE_NUM | 29}, \
1483 {"$30", RTYPE_NUM | 30}, \
1484 {"$31", RTYPE_NUM | 31}
1486 #define FPU_REGISTER_NAMES \
1487 {"$f0", RTYPE_FPU | 0}, \
1488 {"$f1", RTYPE_FPU | 1}, \
1489 {"$f2", RTYPE_FPU | 2}, \
1490 {"$f3", RTYPE_FPU | 3}, \
1491 {"$f4", RTYPE_FPU | 4}, \
1492 {"$f5", RTYPE_FPU | 5}, \
1493 {"$f6", RTYPE_FPU | 6}, \
1494 {"$f7", RTYPE_FPU | 7}, \
1495 {"$f8", RTYPE_FPU | 8}, \
1496 {"$f9", RTYPE_FPU | 9}, \
1497 {"$f10", RTYPE_FPU | 10}, \
1498 {"$f11", RTYPE_FPU | 11}, \
1499 {"$f12", RTYPE_FPU | 12}, \
1500 {"$f13", RTYPE_FPU | 13}, \
1501 {"$f14", RTYPE_FPU | 14}, \
1502 {"$f15", RTYPE_FPU | 15}, \
1503 {"$f16", RTYPE_FPU | 16}, \
1504 {"$f17", RTYPE_FPU | 17}, \
1505 {"$f18", RTYPE_FPU | 18}, \
1506 {"$f19", RTYPE_FPU | 19}, \
1507 {"$f20", RTYPE_FPU | 20}, \
1508 {"$f21", RTYPE_FPU | 21}, \
1509 {"$f22", RTYPE_FPU | 22}, \
1510 {"$f23", RTYPE_FPU | 23}, \
1511 {"$f24", RTYPE_FPU | 24}, \
1512 {"$f25", RTYPE_FPU | 25}, \
1513 {"$f26", RTYPE_FPU | 26}, \
1514 {"$f27", RTYPE_FPU | 27}, \
1515 {"$f28", RTYPE_FPU | 28}, \
1516 {"$f29", RTYPE_FPU | 29}, \
1517 {"$f30", RTYPE_FPU | 30}, \
1518 {"$f31", RTYPE_FPU | 31}
1520 #define FPU_CONDITION_CODE_NAMES \
1521 {"$fcc0", RTYPE_FCC | 0}, \
1522 {"$fcc1", RTYPE_FCC | 1}, \
1523 {"$fcc2", RTYPE_FCC | 2}, \
1524 {"$fcc3", RTYPE_FCC | 3}, \
1525 {"$fcc4", RTYPE_FCC | 4}, \
1526 {"$fcc5", RTYPE_FCC | 5}, \
1527 {"$fcc6", RTYPE_FCC | 6}, \
1528 {"$fcc7", RTYPE_FCC | 7}
1530 #define COPROC_CONDITION_CODE_NAMES \
1531 {"$cc0", RTYPE_FCC | RTYPE_CCC | 0}, \
1532 {"$cc1", RTYPE_FCC | RTYPE_CCC | 1}, \
1533 {"$cc2", RTYPE_FCC | RTYPE_CCC | 2}, \
1534 {"$cc3", RTYPE_FCC | RTYPE_CCC | 3}, \
1535 {"$cc4", RTYPE_FCC | RTYPE_CCC | 4}, \
1536 {"$cc5", RTYPE_FCC | RTYPE_CCC | 5}, \
1537 {"$cc6", RTYPE_FCC | RTYPE_CCC | 6}, \
1538 {"$cc7", RTYPE_FCC | RTYPE_CCC | 7}
1540 #define N32N64_SYMBOLIC_REGISTER_NAMES \
1541 {"$a4", RTYPE_GP | 8}, \
1542 {"$a5", RTYPE_GP | 9}, \
1543 {"$a6", RTYPE_GP | 10}, \
1544 {"$a7", RTYPE_GP | 11}, \
1545 {"$ta0", RTYPE_GP | 8}, /* alias for $a4 */ \
1546 {"$ta1", RTYPE_GP | 9}, /* alias for $a5 */ \
1547 {"$ta2", RTYPE_GP | 10}, /* alias for $a6 */ \
1548 {"$ta3", RTYPE_GP | 11}, /* alias for $a7 */ \
1549 {"$t0", RTYPE_GP | 12}, \
1550 {"$t1", RTYPE_GP | 13}, \
1551 {"$t2", RTYPE_GP | 14}, \
1552 {"$t3", RTYPE_GP | 15}
1554 #define O32_SYMBOLIC_REGISTER_NAMES \
1555 {"$t0", RTYPE_GP | 8}, \
1556 {"$t1", RTYPE_GP | 9}, \
1557 {"$t2", RTYPE_GP | 10}, \
1558 {"$t3", RTYPE_GP | 11}, \
1559 {"$t4", RTYPE_GP | 12}, \
1560 {"$t5", RTYPE_GP | 13}, \
1561 {"$t6", RTYPE_GP | 14}, \
1562 {"$t7", RTYPE_GP | 15}, \
1563 {"$ta0", RTYPE_GP | 12}, /* alias for $t4 */ \
1564 {"$ta1", RTYPE_GP | 13}, /* alias for $t5 */ \
1565 {"$ta2", RTYPE_GP | 14}, /* alias for $t6 */ \
1566 {"$ta3", RTYPE_GP | 15} /* alias for $t7 */
1568 /* Remaining symbolic register names */
1569 #define SYMBOLIC_REGISTER_NAMES \
1570 {"$zero", RTYPE_GP | 0}, \
1571 {"$at", RTYPE_GP | 1}, \
1572 {"$AT", RTYPE_GP | 1}, \
1573 {"$v0", RTYPE_GP | 2}, \
1574 {"$v1", RTYPE_GP | 3}, \
1575 {"$a0", RTYPE_GP | 4}, \
1576 {"$a1", RTYPE_GP | 5}, \
1577 {"$a2", RTYPE_GP | 6}, \
1578 {"$a3", RTYPE_GP | 7}, \
1579 {"$s0", RTYPE_GP | 16}, \
1580 {"$s1", RTYPE_GP | 17}, \
1581 {"$s2", RTYPE_GP | 18}, \
1582 {"$s3", RTYPE_GP | 19}, \
1583 {"$s4", RTYPE_GP | 20}, \
1584 {"$s5", RTYPE_GP | 21}, \
1585 {"$s6", RTYPE_GP | 22}, \
1586 {"$s7", RTYPE_GP | 23}, \
1587 {"$t8", RTYPE_GP | 24}, \
1588 {"$t9", RTYPE_GP | 25}, \
1589 {"$k0", RTYPE_GP | 26}, \
1590 {"$kt0", RTYPE_GP | 26}, \
1591 {"$k1", RTYPE_GP | 27}, \
1592 {"$kt1", RTYPE_GP | 27}, \
1593 {"$gp", RTYPE_GP | 28}, \
1594 {"$sp", RTYPE_GP | 29}, \
1595 {"$s8", RTYPE_GP | 30}, \
1596 {"$fp", RTYPE_GP | 30}, \
1597 {"$ra", RTYPE_GP | 31}
1599 #define MIPS16_SPECIAL_REGISTER_NAMES \
1600 {"$pc", RTYPE_PC | 0}
1602 #define MDMX_VECTOR_REGISTER_NAMES \
1603 /* {"$v0", RTYPE_VEC | 0}, clash with REG 2 above */ \
1604 /* {"$v1", RTYPE_VEC | 1}, clash with REG 3 above */ \
1605 {"$v2", RTYPE_VEC | 2}, \
1606 {"$v3", RTYPE_VEC | 3}, \
1607 {"$v4", RTYPE_VEC | 4}, \
1608 {"$v5", RTYPE_VEC | 5}, \
1609 {"$v6", RTYPE_VEC | 6}, \
1610 {"$v7", RTYPE_VEC | 7}, \
1611 {"$v8", RTYPE_VEC | 8}, \
1612 {"$v9", RTYPE_VEC | 9}, \
1613 {"$v10", RTYPE_VEC | 10}, \
1614 {"$v11", RTYPE_VEC | 11}, \
1615 {"$v12", RTYPE_VEC | 12}, \
1616 {"$v13", RTYPE_VEC | 13}, \
1617 {"$v14", RTYPE_VEC | 14}, \
1618 {"$v15", RTYPE_VEC | 15}, \
1619 {"$v16", RTYPE_VEC | 16}, \
1620 {"$v17", RTYPE_VEC | 17}, \
1621 {"$v18", RTYPE_VEC | 18}, \
1622 {"$v19", RTYPE_VEC | 19}, \
1623 {"$v20", RTYPE_VEC | 20}, \
1624 {"$v21", RTYPE_VEC | 21}, \
1625 {"$v22", RTYPE_VEC | 22}, \
1626 {"$v23", RTYPE_VEC | 23}, \
1627 {"$v24", RTYPE_VEC | 24}, \
1628 {"$v25", RTYPE_VEC | 25}, \
1629 {"$v26", RTYPE_VEC | 26}, \
1630 {"$v27", RTYPE_VEC | 27}, \
1631 {"$v28", RTYPE_VEC | 28}, \
1632 {"$v29", RTYPE_VEC | 29}, \
1633 {"$v30", RTYPE_VEC | 30}, \
1634 {"$v31", RTYPE_VEC | 31}
1636 #define MIPS_DSP_ACCUMULATOR_NAMES \
1637 {"$ac0", RTYPE_ACC | 0}, \
1638 {"$ac1", RTYPE_ACC | 1}, \
1639 {"$ac2", RTYPE_ACC | 2}, \
1640 {"$ac3", RTYPE_ACC | 3}
1642 static const struct regname reg_names
[] = {
1643 GENERIC_REGISTER_NUMBERS
,
1645 FPU_CONDITION_CODE_NAMES
,
1646 COPROC_CONDITION_CODE_NAMES
,
1648 /* The $txx registers depends on the abi,
1649 these will be added later into the symbol table from
1650 one of the tables below once mips_abi is set after
1651 parsing of arguments from the command line. */
1652 SYMBOLIC_REGISTER_NAMES
,
1654 MIPS16_SPECIAL_REGISTER_NAMES
,
1655 MDMX_VECTOR_REGISTER_NAMES
,
1656 MIPS_DSP_ACCUMULATOR_NAMES
,
1660 static const struct regname reg_names_o32
[] = {
1661 O32_SYMBOLIC_REGISTER_NAMES
,
1665 static const struct regname reg_names_n32n64
[] = {
1666 N32N64_SYMBOLIC_REGISTER_NAMES
,
1671 reg_lookup (char **s
, unsigned int types
, unsigned int *regnop
)
1678 /* Find end of name. */
1680 if (is_name_beginner (*e
))
1682 while (is_part_of_name (*e
))
1685 /* Terminate name. */
1689 /* Look for a register symbol. */
1690 if ((symbolP
= symbol_find (*s
)) && S_GET_SEGMENT (symbolP
) == reg_section
)
1692 int r
= S_GET_VALUE (symbolP
);
1694 reg
= r
& RNUM_MASK
;
1695 else if ((types
& RTYPE_VEC
) && (r
& ~1) == (RTYPE_GP
| 2))
1696 /* Convert GP reg $v0/1 to MDMX reg $v0/1! */
1697 reg
= (r
& RNUM_MASK
) - 2;
1699 /* Else see if this is a register defined in an itbl entry. */
1700 else if ((types
& RTYPE_GP
) && itbl_have_entries
)
1707 if (itbl_get_reg_val (n
, &r
))
1708 reg
= r
& RNUM_MASK
;
1711 /* Advance to next token if a register was recognised. */
1714 else if (types
& RWARN
)
1715 as_warn ("Unrecognized register name `%s'", *s
);
1723 /* This function is called once, at assembler startup time. It should set up
1724 all the tables, etc. that the MD part of the assembler will need. */
1729 const char *retval
= NULL
;
1733 if (mips_pic
!= NO_PIC
)
1735 if (g_switch_seen
&& g_switch_value
!= 0)
1736 as_bad (_("-G may not be used in position-independent code"));
1740 if (! bfd_set_arch_mach (stdoutput
, bfd_arch_mips
, file_mips_arch
))
1741 as_warn (_("Could not set architecture and machine"));
1743 op_hash
= hash_new ();
1745 for (i
= 0; i
< NUMOPCODES
;)
1747 const char *name
= mips_opcodes
[i
].name
;
1749 retval
= hash_insert (op_hash
, name
, (void *) &mips_opcodes
[i
]);
1752 fprintf (stderr
, _("internal error: can't hash `%s': %s\n"),
1753 mips_opcodes
[i
].name
, retval
);
1754 /* Probably a memory allocation problem? Give up now. */
1755 as_fatal (_("Broken assembler. No assembly attempted."));
1759 if (mips_opcodes
[i
].pinfo
!= INSN_MACRO
)
1761 if (!validate_mips_insn (&mips_opcodes
[i
]))
1763 if (nop_insn
.insn_mo
== NULL
&& strcmp (name
, "nop") == 0)
1765 create_insn (&nop_insn
, mips_opcodes
+ i
);
1766 nop_insn
.fixed_p
= 1;
1771 while ((i
< NUMOPCODES
) && !strcmp (mips_opcodes
[i
].name
, name
));
1774 mips16_op_hash
= hash_new ();
1777 while (i
< bfd_mips16_num_opcodes
)
1779 const char *name
= mips16_opcodes
[i
].name
;
1781 retval
= hash_insert (mips16_op_hash
, name
, (void *) &mips16_opcodes
[i
]);
1783 as_fatal (_("internal: can't hash `%s': %s"),
1784 mips16_opcodes
[i
].name
, retval
);
1787 if (mips16_opcodes
[i
].pinfo
!= INSN_MACRO
1788 && ((mips16_opcodes
[i
].match
& mips16_opcodes
[i
].mask
)
1789 != mips16_opcodes
[i
].match
))
1791 fprintf (stderr
, _("internal error: bad mips16 opcode: %s %s\n"),
1792 mips16_opcodes
[i
].name
, mips16_opcodes
[i
].args
);
1795 if (mips16_nop_insn
.insn_mo
== NULL
&& strcmp (name
, "nop") == 0)
1797 create_insn (&mips16_nop_insn
, mips16_opcodes
+ i
);
1798 mips16_nop_insn
.fixed_p
= 1;
1802 while (i
< bfd_mips16_num_opcodes
1803 && strcmp (mips16_opcodes
[i
].name
, name
) == 0);
1807 as_fatal (_("Broken assembler. No assembly attempted."));
1809 /* We add all the general register names to the symbol table. This
1810 helps us detect invalid uses of them. */
1811 for (i
= 0; reg_names
[i
].name
; i
++)
1812 symbol_table_insert (symbol_new (reg_names
[i
].name
, reg_section
,
1813 reg_names
[i
].num
, // & RNUM_MASK,
1814 &zero_address_frag
));
1816 for (i
= 0; reg_names_n32n64
[i
].name
; i
++)
1817 symbol_table_insert (symbol_new (reg_names_n32n64
[i
].name
, reg_section
,
1818 reg_names_n32n64
[i
].num
, // & RNUM_MASK,
1819 &zero_address_frag
));
1821 for (i
= 0; reg_names_o32
[i
].name
; i
++)
1822 symbol_table_insert (symbol_new (reg_names_o32
[i
].name
, reg_section
,
1823 reg_names_o32
[i
].num
, // & RNUM_MASK,
1824 &zero_address_frag
));
1826 mips_no_prev_insn ();
1829 mips_cprmask
[0] = 0;
1830 mips_cprmask
[1] = 0;
1831 mips_cprmask
[2] = 0;
1832 mips_cprmask
[3] = 0;
1834 /* set the default alignment for the text section (2**2) */
1835 record_alignment (text_section
, 2);
1837 bfd_set_gp_size (stdoutput
, g_switch_value
);
1842 /* On a native system other than VxWorks, sections must be aligned
1843 to 16 byte boundaries. When configured for an embedded ELF
1844 target, we don't bother. */
1845 if (strcmp (TARGET_OS
, "elf") != 0
1846 && strcmp (TARGET_OS
, "vxworks") != 0)
1848 (void) bfd_set_section_alignment (stdoutput
, text_section
, 4);
1849 (void) bfd_set_section_alignment (stdoutput
, data_section
, 4);
1850 (void) bfd_set_section_alignment (stdoutput
, bss_section
, 4);
1853 /* Create a .reginfo section for register masks and a .mdebug
1854 section for debugging information. */
1862 subseg
= now_subseg
;
1864 /* The ABI says this section should be loaded so that the
1865 running program can access it. However, we don't load it
1866 if we are configured for an embedded target */
1867 flags
= SEC_READONLY
| SEC_DATA
;
1868 if (strcmp (TARGET_OS
, "elf") != 0)
1869 flags
|= SEC_ALLOC
| SEC_LOAD
;
1871 if (mips_abi
!= N64_ABI
)
1873 sec
= subseg_new (".reginfo", (subsegT
) 0);
1875 bfd_set_section_flags (stdoutput
, sec
, flags
);
1876 bfd_set_section_alignment (stdoutput
, sec
, HAVE_NEWABI
? 3 : 2);
1878 mips_regmask_frag
= frag_more (sizeof (Elf32_External_RegInfo
));
1882 /* The 64-bit ABI uses a .MIPS.options section rather than
1883 .reginfo section. */
1884 sec
= subseg_new (".MIPS.options", (subsegT
) 0);
1885 bfd_set_section_flags (stdoutput
, sec
, flags
);
1886 bfd_set_section_alignment (stdoutput
, sec
, 3);
1888 /* Set up the option header. */
1890 Elf_Internal_Options opthdr
;
1893 opthdr
.kind
= ODK_REGINFO
;
1894 opthdr
.size
= (sizeof (Elf_External_Options
)
1895 + sizeof (Elf64_External_RegInfo
));
1898 f
= frag_more (sizeof (Elf_External_Options
));
1899 bfd_mips_elf_swap_options_out (stdoutput
, &opthdr
,
1900 (Elf_External_Options
*) f
);
1902 mips_regmask_frag
= frag_more (sizeof (Elf64_External_RegInfo
));
1906 if (ECOFF_DEBUGGING
)
1908 sec
= subseg_new (".mdebug", (subsegT
) 0);
1909 (void) bfd_set_section_flags (stdoutput
, sec
,
1910 SEC_HAS_CONTENTS
| SEC_READONLY
);
1911 (void) bfd_set_section_alignment (stdoutput
, sec
, 2);
1913 else if (mips_flag_pdr
)
1915 pdr_seg
= subseg_new (".pdr", (subsegT
) 0);
1916 (void) bfd_set_section_flags (stdoutput
, pdr_seg
,
1917 SEC_READONLY
| SEC_RELOC
1919 (void) bfd_set_section_alignment (stdoutput
, pdr_seg
, 2);
1922 subseg_set (seg
, subseg
);
1925 #endif /* OBJ_ELF */
1927 if (! ECOFF_DEBUGGING
)
1930 if (mips_fix_vr4120
)
1931 init_vr4120_conflicts ();
1937 if (! ECOFF_DEBUGGING
)
1942 md_assemble (char *str
)
1944 struct mips_cl_insn insn
;
1945 bfd_reloc_code_real_type unused_reloc
[3]
1946 = {BFD_RELOC_UNUSED
, BFD_RELOC_UNUSED
, BFD_RELOC_UNUSED
};
1948 imm_expr
.X_op
= O_absent
;
1949 imm2_expr
.X_op
= O_absent
;
1950 offset_expr
.X_op
= O_absent
;
1951 imm_reloc
[0] = BFD_RELOC_UNUSED
;
1952 imm_reloc
[1] = BFD_RELOC_UNUSED
;
1953 imm_reloc
[2] = BFD_RELOC_UNUSED
;
1954 offset_reloc
[0] = BFD_RELOC_UNUSED
;
1955 offset_reloc
[1] = BFD_RELOC_UNUSED
;
1956 offset_reloc
[2] = BFD_RELOC_UNUSED
;
1958 if (mips_opts
.mips16
)
1959 mips16_ip (str
, &insn
);
1962 mips_ip (str
, &insn
);
1963 DBG ((_("returned from mips_ip(%s) insn_opcode = 0x%x\n"),
1964 str
, insn
.insn_opcode
));
1969 as_bad ("%s `%s'", insn_error
, str
);
1973 if (insn
.insn_mo
->pinfo
== INSN_MACRO
)
1976 if (mips_opts
.mips16
)
1977 mips16_macro (&insn
);
1984 if (imm_expr
.X_op
!= O_absent
)
1985 append_insn (&insn
, &imm_expr
, imm_reloc
);
1986 else if (offset_expr
.X_op
!= O_absent
)
1987 append_insn (&insn
, &offset_expr
, offset_reloc
);
1989 append_insn (&insn
, NULL
, unused_reloc
);
1993 /* Return true if the given relocation might need a matching %lo().
1994 This is only "might" because SVR4 R_MIPS_GOT16 relocations only
1995 need a matching %lo() when applied to local symbols. */
1997 static inline bfd_boolean
1998 reloc_needs_lo_p (bfd_reloc_code_real_type reloc
)
2000 return (HAVE_IN_PLACE_ADDENDS
2001 && (reloc
== BFD_RELOC_HI16_S
2002 || reloc
== BFD_RELOC_MIPS16_HI16_S
2003 /* VxWorks R_MIPS_GOT16 relocs never need a matching %lo();
2004 all GOT16 relocations evaluate to "G". */
2005 || (reloc
== BFD_RELOC_MIPS_GOT16
&& mips_pic
!= VXWORKS_PIC
)));
2008 /* Return true if the given fixup is followed by a matching R_MIPS_LO16
2011 static inline bfd_boolean
2012 fixup_has_matching_lo_p (fixS
*fixp
)
2014 return (fixp
->fx_next
!= NULL
2015 && (fixp
->fx_next
->fx_r_type
== BFD_RELOC_LO16
2016 || fixp
->fx_next
->fx_r_type
== BFD_RELOC_MIPS16_LO16
)
2017 && fixp
->fx_addsy
== fixp
->fx_next
->fx_addsy
2018 && fixp
->fx_offset
== fixp
->fx_next
->fx_offset
);
2021 /* See whether instruction IP reads register REG. CLASS is the type
2025 insn_uses_reg (const struct mips_cl_insn
*ip
, unsigned int reg
,
2026 enum mips_regclass
class)
2028 if (class == MIPS16_REG
)
2030 assert (mips_opts
.mips16
);
2031 reg
= mips16_to_32_reg_map
[reg
];
2032 class = MIPS_GR_REG
;
2035 /* Don't report on general register ZERO, since it never changes. */
2036 if (class == MIPS_GR_REG
&& reg
== ZERO
)
2039 if (class == MIPS_FP_REG
)
2041 assert (! mips_opts
.mips16
);
2042 /* If we are called with either $f0 or $f1, we must check $f0.
2043 This is not optimal, because it will introduce an unnecessary
2044 NOP between "lwc1 $f0" and "swc1 $f1". To fix this we would
2045 need to distinguish reading both $f0 and $f1 or just one of
2046 them. Note that we don't have to check the other way,
2047 because there is no instruction that sets both $f0 and $f1
2048 and requires a delay. */
2049 if ((ip
->insn_mo
->pinfo
& INSN_READ_FPR_S
)
2050 && ((EXTRACT_OPERAND (FS
, *ip
) & ~(unsigned) 1)
2051 == (reg
&~ (unsigned) 1)))
2053 if ((ip
->insn_mo
->pinfo
& INSN_READ_FPR_T
)
2054 && ((EXTRACT_OPERAND (FT
, *ip
) & ~(unsigned) 1)
2055 == (reg
&~ (unsigned) 1)))
2058 else if (! mips_opts
.mips16
)
2060 if ((ip
->insn_mo
->pinfo
& INSN_READ_GPR_S
)
2061 && EXTRACT_OPERAND (RS
, *ip
) == reg
)
2063 if ((ip
->insn_mo
->pinfo
& INSN_READ_GPR_T
)
2064 && EXTRACT_OPERAND (RT
, *ip
) == reg
)
2069 if ((ip
->insn_mo
->pinfo
& MIPS16_INSN_READ_X
)
2070 && mips16_to_32_reg_map
[MIPS16_EXTRACT_OPERAND (RX
, *ip
)] == reg
)
2072 if ((ip
->insn_mo
->pinfo
& MIPS16_INSN_READ_Y
)
2073 && mips16_to_32_reg_map
[MIPS16_EXTRACT_OPERAND (RY
, *ip
)] == reg
)
2075 if ((ip
->insn_mo
->pinfo
& MIPS16_INSN_READ_Z
)
2076 && (mips16_to_32_reg_map
[MIPS16_EXTRACT_OPERAND (MOVE32Z
, *ip
)]
2079 if ((ip
->insn_mo
->pinfo
& MIPS16_INSN_READ_T
) && reg
== TREG
)
2081 if ((ip
->insn_mo
->pinfo
& MIPS16_INSN_READ_SP
) && reg
== SP
)
2083 if ((ip
->insn_mo
->pinfo
& MIPS16_INSN_READ_31
) && reg
== RA
)
2085 if ((ip
->insn_mo
->pinfo
& MIPS16_INSN_READ_GPR_X
)
2086 && MIPS16_EXTRACT_OPERAND (REGR32
, *ip
) == reg
)
2093 /* This function returns true if modifying a register requires a
2097 reg_needs_delay (unsigned int reg
)
2099 unsigned long prev_pinfo
;
2101 prev_pinfo
= history
[0].insn_mo
->pinfo
;
2102 if (! mips_opts
.noreorder
2103 && (((prev_pinfo
& INSN_LOAD_MEMORY_DELAY
)
2104 && ! gpr_interlocks
)
2105 || ((prev_pinfo
& INSN_LOAD_COPROC_DELAY
)
2106 && ! cop_interlocks
)))
2108 /* A load from a coprocessor or from memory. All load delays
2109 delay the use of general register rt for one instruction. */
2110 /* Itbl support may require additional care here. */
2111 know (prev_pinfo
& INSN_WRITE_GPR_T
);
2112 if (reg
== EXTRACT_OPERAND (RT
, history
[0]))
2119 /* Move all labels in insn_labels to the current insertion point. */
2122 mips_move_labels (void)
2124 segment_info_type
*si
= seg_info (now_seg
);
2125 struct insn_label_list
*l
;
2128 for (l
= si
->label_list
; l
!= NULL
; l
= l
->next
)
2130 assert (S_GET_SEGMENT (l
->label
) == now_seg
);
2131 symbol_set_frag (l
->label
, frag_now
);
2132 val
= (valueT
) frag_now_fix ();
2133 /* mips16 text labels are stored as odd. */
2134 if (mips_opts
.mips16
)
2136 S_SET_VALUE (l
->label
, val
);
2141 s_is_linkonce (symbolS
*sym
, segT from_seg
)
2143 bfd_boolean linkonce
= FALSE
;
2144 segT symseg
= S_GET_SEGMENT (sym
);
2146 if (symseg
!= from_seg
&& !S_IS_LOCAL (sym
))
2148 if ((bfd_get_section_flags (stdoutput
, symseg
) & SEC_LINK_ONCE
))
2151 /* The GNU toolchain uses an extension for ELF: a section
2152 beginning with the magic string .gnu.linkonce is a
2153 linkonce section. */
2154 if (strncmp (segment_name (symseg
), ".gnu.linkonce",
2155 sizeof ".gnu.linkonce" - 1) == 0)
2162 /* Mark instruction labels in mips16 mode. This permits the linker to
2163 handle them specially, such as generating jalx instructions when
2164 needed. We also make them odd for the duration of the assembly, in
2165 order to generate the right sort of code. We will make them even
2166 in the adjust_symtab routine, while leaving them marked. This is
2167 convenient for the debugger and the disassembler. The linker knows
2168 to make them odd again. */
2171 mips16_mark_labels (void)
2173 segment_info_type
*si
= seg_info (now_seg
);
2174 struct insn_label_list
*l
;
2176 if (!mips_opts
.mips16
)
2179 for (l
= si
->label_list
; l
!= NULL
; l
= l
->next
)
2181 symbolS
*label
= l
->label
;
2183 #if defined(OBJ_ELF) || defined(OBJ_MAYBE_ELF)
2185 S_SET_OTHER (label
, STO_MIPS16
);
2187 if ((S_GET_VALUE (label
) & 1) == 0
2188 /* Don't adjust the address if the label is global or weak, or
2189 in a link-once section, since we'll be emitting symbol reloc
2190 references to it which will be patched up by the linker, and
2191 the final value of the symbol may or may not be MIPS16. */
2192 && ! S_IS_WEAK (label
)
2193 && ! S_IS_EXTERNAL (label
)
2194 && ! s_is_linkonce (label
, now_seg
))
2195 S_SET_VALUE (label
, S_GET_VALUE (label
) | 1);
2199 /* End the current frag. Make it a variant frag and record the
2203 relax_close_frag (void)
2205 mips_macro_warning
.first_frag
= frag_now
;
2206 frag_var (rs_machine_dependent
, 0, 0,
2207 RELAX_ENCODE (mips_relax
.sizes
[0], mips_relax
.sizes
[1]),
2208 mips_relax
.symbol
, 0, (char *) mips_relax
.first_fixup
);
2210 memset (&mips_relax
.sizes
, 0, sizeof (mips_relax
.sizes
));
2211 mips_relax
.first_fixup
= 0;
2214 /* Start a new relaxation sequence whose expansion depends on SYMBOL.
2215 See the comment above RELAX_ENCODE for more details. */
2218 relax_start (symbolS
*symbol
)
2220 assert (mips_relax
.sequence
== 0);
2221 mips_relax
.sequence
= 1;
2222 mips_relax
.symbol
= symbol
;
2225 /* Start generating the second version of a relaxable sequence.
2226 See the comment above RELAX_ENCODE for more details. */
2231 assert (mips_relax
.sequence
== 1);
2232 mips_relax
.sequence
= 2;
2235 /* End the current relaxable sequence. */
2240 assert (mips_relax
.sequence
== 2);
2241 relax_close_frag ();
2242 mips_relax
.sequence
= 0;
2245 /* Classify an instruction according to the FIX_VR4120_* enumeration.
2246 Return NUM_FIX_VR4120_CLASSES if the instruction isn't affected
2247 by VR4120 errata. */
2250 classify_vr4120_insn (const char *name
)
2252 if (strncmp (name
, "macc", 4) == 0)
2253 return FIX_VR4120_MACC
;
2254 if (strncmp (name
, "dmacc", 5) == 0)
2255 return FIX_VR4120_DMACC
;
2256 if (strncmp (name
, "mult", 4) == 0)
2257 return FIX_VR4120_MULT
;
2258 if (strncmp (name
, "dmult", 5) == 0)
2259 return FIX_VR4120_DMULT
;
2260 if (strstr (name
, "div"))
2261 return FIX_VR4120_DIV
;
2262 if (strcmp (name
, "mtlo") == 0 || strcmp (name
, "mthi") == 0)
2263 return FIX_VR4120_MTHILO
;
2264 return NUM_FIX_VR4120_CLASSES
;
2267 /* Return the number of instructions that must separate INSN1 and INSN2,
2268 where INSN1 is the earlier instruction. Return the worst-case value
2269 for any INSN2 if INSN2 is null. */
2272 insns_between (const struct mips_cl_insn
*insn1
,
2273 const struct mips_cl_insn
*insn2
)
2275 unsigned long pinfo1
, pinfo2
;
2277 /* This function needs to know which pinfo flags are set for INSN2
2278 and which registers INSN2 uses. The former is stored in PINFO2 and
2279 the latter is tested via INSN2_USES_REG. If INSN2 is null, PINFO2
2280 will have every flag set and INSN2_USES_REG will always return true. */
2281 pinfo1
= insn1
->insn_mo
->pinfo
;
2282 pinfo2
= insn2
? insn2
->insn_mo
->pinfo
: ~0U;
2284 #define INSN2_USES_REG(REG, CLASS) \
2285 (insn2 == NULL || insn_uses_reg (insn2, REG, CLASS))
2287 /* For most targets, write-after-read dependencies on the HI and LO
2288 registers must be separated by at least two instructions. */
2289 if (!hilo_interlocks
)
2291 if ((pinfo1
& INSN_READ_LO
) && (pinfo2
& INSN_WRITE_LO
))
2293 if ((pinfo1
& INSN_READ_HI
) && (pinfo2
& INSN_WRITE_HI
))
2297 /* If we're working around r7000 errata, there must be two instructions
2298 between an mfhi or mflo and any instruction that uses the result. */
2299 if (mips_7000_hilo_fix
2300 && MF_HILO_INSN (pinfo1
)
2301 && INSN2_USES_REG (EXTRACT_OPERAND (RD
, *insn1
), MIPS_GR_REG
))
2304 /* If working around VR4120 errata, check for combinations that need
2305 a single intervening instruction. */
2306 if (mips_fix_vr4120
)
2308 unsigned int class1
, class2
;
2310 class1
= classify_vr4120_insn (insn1
->insn_mo
->name
);
2311 if (class1
!= NUM_FIX_VR4120_CLASSES
&& vr4120_conflicts
[class1
] != 0)
2315 class2
= classify_vr4120_insn (insn2
->insn_mo
->name
);
2316 if (vr4120_conflicts
[class1
] & (1 << class2
))
2321 if (!mips_opts
.mips16
)
2323 /* Check for GPR or coprocessor load delays. All such delays
2324 are on the RT register. */
2325 /* Itbl support may require additional care here. */
2326 if ((!gpr_interlocks
&& (pinfo1
& INSN_LOAD_MEMORY_DELAY
))
2327 || (!cop_interlocks
&& (pinfo1
& INSN_LOAD_COPROC_DELAY
)))
2329 know (pinfo1
& INSN_WRITE_GPR_T
);
2330 if (INSN2_USES_REG (EXTRACT_OPERAND (RT
, *insn1
), MIPS_GR_REG
))
2334 /* Check for generic coprocessor hazards.
2336 This case is not handled very well. There is no special
2337 knowledge of CP0 handling, and the coprocessors other than
2338 the floating point unit are not distinguished at all. */
2339 /* Itbl support may require additional care here. FIXME!
2340 Need to modify this to include knowledge about
2341 user specified delays! */
2342 else if ((!cop_interlocks
&& (pinfo1
& INSN_COPROC_MOVE_DELAY
))
2343 || (!cop_mem_interlocks
&& (pinfo1
& INSN_COPROC_MEMORY_DELAY
)))
2345 /* Handle cases where INSN1 writes to a known general coprocessor
2346 register. There must be a one instruction delay before INSN2
2347 if INSN2 reads that register, otherwise no delay is needed. */
2348 if (pinfo1
& INSN_WRITE_FPR_T
)
2350 if (INSN2_USES_REG (EXTRACT_OPERAND (FT
, *insn1
), MIPS_FP_REG
))
2353 else if (pinfo1
& INSN_WRITE_FPR_S
)
2355 if (INSN2_USES_REG (EXTRACT_OPERAND (FS
, *insn1
), MIPS_FP_REG
))
2360 /* Read-after-write dependencies on the control registers
2361 require a two-instruction gap. */
2362 if ((pinfo1
& INSN_WRITE_COND_CODE
)
2363 && (pinfo2
& INSN_READ_COND_CODE
))
2366 /* We don't know exactly what INSN1 does. If INSN2 is
2367 also a coprocessor instruction, assume there must be
2368 a one instruction gap. */
2369 if (pinfo2
& INSN_COP
)
2374 /* Check for read-after-write dependencies on the coprocessor
2375 control registers in cases where INSN1 does not need a general
2376 coprocessor delay. This means that INSN1 is a floating point
2377 comparison instruction. */
2378 /* Itbl support may require additional care here. */
2379 else if (!cop_interlocks
2380 && (pinfo1
& INSN_WRITE_COND_CODE
)
2381 && (pinfo2
& INSN_READ_COND_CODE
))
2385 #undef INSN2_USES_REG
2390 /* Return the number of nops that would be needed to work around the
2391 VR4130 mflo/mfhi errata if instruction INSN immediately followed
2392 the MAX_VR4130_NOPS instructions described by HISTORY. */
2395 nops_for_vr4130 (const struct mips_cl_insn
*history
,
2396 const struct mips_cl_insn
*insn
)
2400 /* Check if the instruction writes to HI or LO. MTHI and MTLO
2401 are not affected by the errata. */
2403 && ((insn
->insn_mo
->pinfo
& (INSN_WRITE_HI
| INSN_WRITE_LO
)) == 0
2404 || strcmp (insn
->insn_mo
->name
, "mtlo") == 0
2405 || strcmp (insn
->insn_mo
->name
, "mthi") == 0))
2408 /* Search for the first MFLO or MFHI. */
2409 for (i
= 0; i
< MAX_VR4130_NOPS
; i
++)
2410 if (!history
[i
].noreorder_p
&& MF_HILO_INSN (history
[i
].insn_mo
->pinfo
))
2412 /* Extract the destination register. */
2413 if (mips_opts
.mips16
)
2414 reg
= mips16_to_32_reg_map
[MIPS16_EXTRACT_OPERAND (RX
, history
[i
])];
2416 reg
= EXTRACT_OPERAND (RD
, history
[i
]);
2418 /* No nops are needed if INSN reads that register. */
2419 if (insn
!= NULL
&& insn_uses_reg (insn
, reg
, MIPS_GR_REG
))
2422 /* ...or if any of the intervening instructions do. */
2423 for (j
= 0; j
< i
; j
++)
2424 if (insn_uses_reg (&history
[j
], reg
, MIPS_GR_REG
))
2427 return MAX_VR4130_NOPS
- i
;
2432 /* Return the number of nops that would be needed if instruction INSN
2433 immediately followed the MAX_NOPS instructions given by HISTORY,
2434 where HISTORY[0] is the most recent instruction. If INSN is null,
2435 return the worse-case number of nops for any instruction. */
2438 nops_for_insn (const struct mips_cl_insn
*history
,
2439 const struct mips_cl_insn
*insn
)
2441 int i
, nops
, tmp_nops
;
2444 for (i
= 0; i
< MAX_DELAY_NOPS
; i
++)
2445 if (!history
[i
].noreorder_p
)
2447 tmp_nops
= insns_between (history
+ i
, insn
) - i
;
2448 if (tmp_nops
> nops
)
2452 if (mips_fix_vr4130
)
2454 tmp_nops
= nops_for_vr4130 (history
, insn
);
2455 if (tmp_nops
> nops
)
2462 /* The variable arguments provide NUM_INSNS extra instructions that
2463 might be added to HISTORY. Return the largest number of nops that
2464 would be needed after the extended sequence. */
2467 nops_for_sequence (int num_insns
, const struct mips_cl_insn
*history
, ...)
2470 struct mips_cl_insn buffer
[MAX_NOPS
];
2471 struct mips_cl_insn
*cursor
;
2474 va_start (args
, history
);
2475 cursor
= buffer
+ num_insns
;
2476 memcpy (cursor
, history
, (MAX_NOPS
- num_insns
) * sizeof (*cursor
));
2477 while (cursor
> buffer
)
2478 *--cursor
= *va_arg (args
, const struct mips_cl_insn
*);
2480 nops
= nops_for_insn (buffer
, NULL
);
2485 /* Like nops_for_insn, but if INSN is a branch, take into account the
2486 worst-case delay for the branch target. */
2489 nops_for_insn_or_target (const struct mips_cl_insn
*history
,
2490 const struct mips_cl_insn
*insn
)
2494 nops
= nops_for_insn (history
, insn
);
2495 if (insn
->insn_mo
->pinfo
& (INSN_UNCOND_BRANCH_DELAY
2496 | INSN_COND_BRANCH_DELAY
2497 | INSN_COND_BRANCH_LIKELY
))
2499 tmp_nops
= nops_for_sequence (2, history
, insn
, NOP_INSN
);
2500 if (tmp_nops
> nops
)
2503 else if (mips_opts
.mips16
&& (insn
->insn_mo
->pinfo
& MIPS16_INSN_BRANCH
))
2505 tmp_nops
= nops_for_sequence (1, history
, insn
);
2506 if (tmp_nops
> nops
)
2512 /* Output an instruction. IP is the instruction information.
2513 ADDRESS_EXPR is an operand of the instruction to be used with
2517 append_insn (struct mips_cl_insn
*ip
, expressionS
*address_expr
,
2518 bfd_reloc_code_real_type
*reloc_type
)
2520 unsigned long prev_pinfo
, pinfo
;
2521 relax_stateT prev_insn_frag_type
= 0;
2522 bfd_boolean relaxed_branch
= FALSE
;
2523 segment_info_type
*si
= seg_info (now_seg
);
2525 /* Mark instruction labels in mips16 mode. */
2526 mips16_mark_labels ();
2528 prev_pinfo
= history
[0].insn_mo
->pinfo
;
2529 pinfo
= ip
->insn_mo
->pinfo
;
2531 if (mips_relax
.sequence
!= 2 && !mips_opts
.noreorder
)
2533 /* There are a lot of optimizations we could do that we don't.
2534 In particular, we do not, in general, reorder instructions.
2535 If you use gcc with optimization, it will reorder
2536 instructions and generally do much more optimization then we
2537 do here; repeating all that work in the assembler would only
2538 benefit hand written assembly code, and does not seem worth
2540 int nops
= (mips_optimize
== 0
2541 ? nops_for_insn (history
, NULL
)
2542 : nops_for_insn_or_target (history
, ip
));
2546 unsigned long old_frag_offset
;
2549 old_frag
= frag_now
;
2550 old_frag_offset
= frag_now_fix ();
2552 for (i
= 0; i
< nops
; i
++)
2557 listing_prev_line ();
2558 /* We may be at the start of a variant frag. In case we
2559 are, make sure there is enough space for the frag
2560 after the frags created by listing_prev_line. The
2561 argument to frag_grow here must be at least as large
2562 as the argument to all other calls to frag_grow in
2563 this file. We don't have to worry about being in the
2564 middle of a variant frag, because the variants insert
2565 all needed nop instructions themselves. */
2569 mips_move_labels ();
2571 #ifndef NO_ECOFF_DEBUGGING
2572 if (ECOFF_DEBUGGING
)
2573 ecoff_fix_loc (old_frag
, old_frag_offset
);
2577 else if (mips_relax
.sequence
!= 2 && prev_nop_frag
!= NULL
)
2579 /* Work out how many nops in prev_nop_frag are needed by IP. */
2580 int nops
= nops_for_insn_or_target (history
, ip
);
2581 assert (nops
<= prev_nop_frag_holds
);
2583 /* Enforce NOPS as a minimum. */
2584 if (nops
> prev_nop_frag_required
)
2585 prev_nop_frag_required
= nops
;
2587 if (prev_nop_frag_holds
== prev_nop_frag_required
)
2589 /* Settle for the current number of nops. Update the history
2590 accordingly (for the benefit of any future .set reorder code). */
2591 prev_nop_frag
= NULL
;
2592 insert_into_history (prev_nop_frag_since
,
2593 prev_nop_frag_holds
, NOP_INSN
);
2597 /* Allow this instruction to replace one of the nops that was
2598 tentatively added to prev_nop_frag. */
2599 prev_nop_frag
->fr_fix
-= mips_opts
.mips16
? 2 : 4;
2600 prev_nop_frag_holds
--;
2601 prev_nop_frag_since
++;
2606 /* The value passed to dwarf2_emit_insn is the distance between
2607 the beginning of the current instruction and the address that
2608 should be recorded in the debug tables. For MIPS16 debug info
2609 we want to use ISA-encoded addresses, so we pass -1 for an
2610 address higher by one than the current. */
2611 dwarf2_emit_insn (mips_opts
.mips16
? -1 : 0);
2614 /* Record the frag type before frag_var. */
2615 if (history
[0].frag
)
2616 prev_insn_frag_type
= history
[0].frag
->fr_type
;
2619 && *reloc_type
== BFD_RELOC_16_PCREL_S2
2620 && (pinfo
& INSN_UNCOND_BRANCH_DELAY
|| pinfo
& INSN_COND_BRANCH_DELAY
2621 || pinfo
& INSN_COND_BRANCH_LIKELY
)
2622 && mips_relax_branch
2623 /* Don't try branch relaxation within .set nomacro, or within
2624 .set noat if we use $at for PIC computations. If it turns
2625 out that the branch was out-of-range, we'll get an error. */
2626 && !mips_opts
.warn_about_macros
2627 && !(mips_opts
.noat
&& mips_pic
!= NO_PIC
)
2628 && !mips_opts
.mips16
)
2630 relaxed_branch
= TRUE
;
2631 add_relaxed_insn (ip
, (relaxed_branch_length
2633 (pinfo
& INSN_UNCOND_BRANCH_DELAY
) ? -1
2634 : (pinfo
& INSN_COND_BRANCH_LIKELY
) ? 1
2637 (pinfo
& INSN_UNCOND_BRANCH_DELAY
,
2638 pinfo
& INSN_COND_BRANCH_LIKELY
,
2639 pinfo
& INSN_WRITE_GPR_31
,
2641 address_expr
->X_add_symbol
,
2642 address_expr
->X_add_number
);
2643 *reloc_type
= BFD_RELOC_UNUSED
;
2645 else if (*reloc_type
> BFD_RELOC_UNUSED
)
2647 /* We need to set up a variant frag. */
2648 assert (mips_opts
.mips16
&& address_expr
!= NULL
);
2649 add_relaxed_insn (ip
, 4, 0,
2651 (*reloc_type
- BFD_RELOC_UNUSED
,
2652 mips16_small
, mips16_ext
,
2653 prev_pinfo
& INSN_UNCOND_BRANCH_DELAY
,
2654 history
[0].mips16_absolute_jump_p
),
2655 make_expr_symbol (address_expr
), 0);
2657 else if (mips_opts
.mips16
2659 && *reloc_type
!= BFD_RELOC_MIPS16_JMP
)
2661 if ((pinfo
& INSN_UNCOND_BRANCH_DELAY
) == 0)
2662 /* Make sure there is enough room to swap this instruction with
2663 a following jump instruction. */
2665 add_fixed_insn (ip
);
2669 if (mips_opts
.mips16
2670 && mips_opts
.noreorder
2671 && (prev_pinfo
& INSN_UNCOND_BRANCH_DELAY
) != 0)
2672 as_warn (_("extended instruction in delay slot"));
2674 if (mips_relax
.sequence
)
2676 /* If we've reached the end of this frag, turn it into a variant
2677 frag and record the information for the instructions we've
2679 if (frag_room () < 4)
2680 relax_close_frag ();
2681 mips_relax
.sizes
[mips_relax
.sequence
- 1] += 4;
2684 if (mips_relax
.sequence
!= 2)
2685 mips_macro_warning
.sizes
[0] += 4;
2686 if (mips_relax
.sequence
!= 1)
2687 mips_macro_warning
.sizes
[1] += 4;
2689 if (mips_opts
.mips16
)
2692 ip
->mips16_absolute_jump_p
= (*reloc_type
== BFD_RELOC_MIPS16_JMP
);
2694 add_fixed_insn (ip
);
2697 if (address_expr
!= NULL
&& *reloc_type
<= BFD_RELOC_UNUSED
)
2699 if (address_expr
->X_op
== O_constant
)
2703 switch (*reloc_type
)
2706 ip
->insn_opcode
|= address_expr
->X_add_number
;
2709 case BFD_RELOC_MIPS_HIGHEST
:
2710 tmp
= (address_expr
->X_add_number
+ 0x800080008000ull
) >> 48;
2711 ip
->insn_opcode
|= tmp
& 0xffff;
2714 case BFD_RELOC_MIPS_HIGHER
:
2715 tmp
= (address_expr
->X_add_number
+ 0x80008000ull
) >> 32;
2716 ip
->insn_opcode
|= tmp
& 0xffff;
2719 case BFD_RELOC_HI16_S
:
2720 tmp
= (address_expr
->X_add_number
+ 0x8000) >> 16;
2721 ip
->insn_opcode
|= tmp
& 0xffff;
2724 case BFD_RELOC_HI16
:
2725 ip
->insn_opcode
|= (address_expr
->X_add_number
>> 16) & 0xffff;
2728 case BFD_RELOC_UNUSED
:
2729 case BFD_RELOC_LO16
:
2730 case BFD_RELOC_MIPS_GOT_DISP
:
2731 ip
->insn_opcode
|= address_expr
->X_add_number
& 0xffff;
2734 case BFD_RELOC_MIPS_JMP
:
2735 if ((address_expr
->X_add_number
& 3) != 0)
2736 as_bad (_("jump to misaligned address (0x%lx)"),
2737 (unsigned long) address_expr
->X_add_number
);
2738 ip
->insn_opcode
|= (address_expr
->X_add_number
>> 2) & 0x3ffffff;
2741 case BFD_RELOC_MIPS16_JMP
:
2742 if ((address_expr
->X_add_number
& 3) != 0)
2743 as_bad (_("jump to misaligned address (0x%lx)"),
2744 (unsigned long) address_expr
->X_add_number
);
2746 (((address_expr
->X_add_number
& 0x7c0000) << 3)
2747 | ((address_expr
->X_add_number
& 0xf800000) >> 7)
2748 | ((address_expr
->X_add_number
& 0x3fffc) >> 2));
2751 case BFD_RELOC_16_PCREL_S2
:
2752 if ((address_expr
->X_add_number
& 3) != 0)
2753 as_bad (_("branch to misaligned address (0x%lx)"),
2754 (unsigned long) address_expr
->X_add_number
);
2755 if (mips_relax_branch
)
2757 if ((address_expr
->X_add_number
+ 0x20000) & ~0x3ffff)
2758 as_bad (_("branch address range overflow (0x%lx)"),
2759 (unsigned long) address_expr
->X_add_number
);
2760 ip
->insn_opcode
|= (address_expr
->X_add_number
>> 2) & 0xffff;
2767 else if (*reloc_type
< BFD_RELOC_UNUSED
)
2770 reloc_howto_type
*howto
;
2773 /* In a compound relocation, it is the final (outermost)
2774 operator that determines the relocated field. */
2775 for (i
= 1; i
< 3; i
++)
2776 if (reloc_type
[i
] == BFD_RELOC_UNUSED
)
2779 howto
= bfd_reloc_type_lookup (stdoutput
, reloc_type
[i
- 1]);
2780 ip
->fixp
[0] = fix_new_exp (ip
->frag
, ip
->where
,
2781 bfd_get_reloc_size (howto
),
2783 reloc_type
[0] == BFD_RELOC_16_PCREL_S2
,
2786 /* These relocations can have an addend that won't fit in
2787 4 octets for 64bit assembly. */
2789 && ! howto
->partial_inplace
2790 && (reloc_type
[0] == BFD_RELOC_16
2791 || reloc_type
[0] == BFD_RELOC_32
2792 || reloc_type
[0] == BFD_RELOC_MIPS_JMP
2793 || reloc_type
[0] == BFD_RELOC_HI16_S
2794 || reloc_type
[0] == BFD_RELOC_LO16
2795 || reloc_type
[0] == BFD_RELOC_GPREL16
2796 || reloc_type
[0] == BFD_RELOC_MIPS_LITERAL
2797 || reloc_type
[0] == BFD_RELOC_GPREL32
2798 || reloc_type
[0] == BFD_RELOC_64
2799 || reloc_type
[0] == BFD_RELOC_CTOR
2800 || reloc_type
[0] == BFD_RELOC_MIPS_SUB
2801 || reloc_type
[0] == BFD_RELOC_MIPS_HIGHEST
2802 || reloc_type
[0] == BFD_RELOC_MIPS_HIGHER
2803 || reloc_type
[0] == BFD_RELOC_MIPS_SCN_DISP
2804 || reloc_type
[0] == BFD_RELOC_MIPS_REL16
2805 || reloc_type
[0] == BFD_RELOC_MIPS_RELGOT
2806 || reloc_type
[0] == BFD_RELOC_MIPS16_GPREL
2807 || reloc_type
[0] == BFD_RELOC_MIPS16_HI16_S
2808 || reloc_type
[0] == BFD_RELOC_MIPS16_LO16
))
2809 ip
->fixp
[0]->fx_no_overflow
= 1;
2811 if (mips_relax
.sequence
)
2813 if (mips_relax
.first_fixup
== 0)
2814 mips_relax
.first_fixup
= ip
->fixp
[0];
2816 else if (reloc_needs_lo_p (*reloc_type
))
2818 struct mips_hi_fixup
*hi_fixup
;
2820 /* Reuse the last entry if it already has a matching %lo. */
2821 hi_fixup
= mips_hi_fixup_list
;
2823 || !fixup_has_matching_lo_p (hi_fixup
->fixp
))
2825 hi_fixup
= ((struct mips_hi_fixup
*)
2826 xmalloc (sizeof (struct mips_hi_fixup
)));
2827 hi_fixup
->next
= mips_hi_fixup_list
;
2828 mips_hi_fixup_list
= hi_fixup
;
2830 hi_fixup
->fixp
= ip
->fixp
[0];
2831 hi_fixup
->seg
= now_seg
;
2834 /* Add fixups for the second and third relocations, if given.
2835 Note that the ABI allows the second relocation to be
2836 against RSS_UNDEF, RSS_GP, RSS_GP0 or RSS_LOC. At the
2837 moment we only use RSS_UNDEF, but we could add support
2838 for the others if it ever becomes necessary. */
2839 for (i
= 1; i
< 3; i
++)
2840 if (reloc_type
[i
] != BFD_RELOC_UNUSED
)
2842 ip
->fixp
[i
] = fix_new (ip
->frag
, ip
->where
,
2843 ip
->fixp
[0]->fx_size
, NULL
, 0,
2844 FALSE
, reloc_type
[i
]);
2846 /* Use fx_tcbit to mark compound relocs. */
2847 ip
->fixp
[0]->fx_tcbit
= 1;
2848 ip
->fixp
[i
]->fx_tcbit
= 1;
2854 /* Update the register mask information. */
2855 if (! mips_opts
.mips16
)
2857 if (pinfo
& INSN_WRITE_GPR_D
)
2858 mips_gprmask
|= 1 << EXTRACT_OPERAND (RD
, *ip
);
2859 if ((pinfo
& (INSN_WRITE_GPR_T
| INSN_READ_GPR_T
)) != 0)
2860 mips_gprmask
|= 1 << EXTRACT_OPERAND (RT
, *ip
);
2861 if (pinfo
& INSN_READ_GPR_S
)
2862 mips_gprmask
|= 1 << EXTRACT_OPERAND (RS
, *ip
);
2863 if (pinfo
& INSN_WRITE_GPR_31
)
2864 mips_gprmask
|= 1 << RA
;
2865 if (pinfo
& INSN_WRITE_FPR_D
)
2866 mips_cprmask
[1] |= 1 << EXTRACT_OPERAND (FD
, *ip
);
2867 if ((pinfo
& (INSN_WRITE_FPR_S
| INSN_READ_FPR_S
)) != 0)
2868 mips_cprmask
[1] |= 1 << EXTRACT_OPERAND (FS
, *ip
);
2869 if ((pinfo
& (INSN_WRITE_FPR_T
| INSN_READ_FPR_T
)) != 0)
2870 mips_cprmask
[1] |= 1 << EXTRACT_OPERAND (FT
, *ip
);
2871 if ((pinfo
& INSN_READ_FPR_R
) != 0)
2872 mips_cprmask
[1] |= 1 << EXTRACT_OPERAND (FR
, *ip
);
2873 if (pinfo
& INSN_COP
)
2875 /* We don't keep enough information to sort these cases out.
2876 The itbl support does keep this information however, although
2877 we currently don't support itbl fprmats as part of the cop
2878 instruction. May want to add this support in the future. */
2880 /* Never set the bit for $0, which is always zero. */
2881 mips_gprmask
&= ~1 << 0;
2885 if (pinfo
& (MIPS16_INSN_WRITE_X
| MIPS16_INSN_READ_X
))
2886 mips_gprmask
|= 1 << MIPS16_EXTRACT_OPERAND (RX
, *ip
);
2887 if (pinfo
& (MIPS16_INSN_WRITE_Y
| MIPS16_INSN_READ_Y
))
2888 mips_gprmask
|= 1 << MIPS16_EXTRACT_OPERAND (RY
, *ip
);
2889 if (pinfo
& MIPS16_INSN_WRITE_Z
)
2890 mips_gprmask
|= 1 << MIPS16_EXTRACT_OPERAND (RZ
, *ip
);
2891 if (pinfo
& (MIPS16_INSN_WRITE_T
| MIPS16_INSN_READ_T
))
2892 mips_gprmask
|= 1 << TREG
;
2893 if (pinfo
& (MIPS16_INSN_WRITE_SP
| MIPS16_INSN_READ_SP
))
2894 mips_gprmask
|= 1 << SP
;
2895 if (pinfo
& (MIPS16_INSN_WRITE_31
| MIPS16_INSN_READ_31
))
2896 mips_gprmask
|= 1 << RA
;
2897 if (pinfo
& MIPS16_INSN_WRITE_GPR_Y
)
2898 mips_gprmask
|= 1 << MIPS16OP_EXTRACT_REG32R (ip
->insn_opcode
);
2899 if (pinfo
& MIPS16_INSN_READ_Z
)
2900 mips_gprmask
|= 1 << MIPS16_EXTRACT_OPERAND (MOVE32Z
, *ip
);
2901 if (pinfo
& MIPS16_INSN_READ_GPR_X
)
2902 mips_gprmask
|= 1 << MIPS16_EXTRACT_OPERAND (REGR32
, *ip
);
2905 if (mips_relax
.sequence
!= 2 && !mips_opts
.noreorder
)
2907 /* Filling the branch delay slot is more complex. We try to
2908 switch the branch with the previous instruction, which we can
2909 do if the previous instruction does not set up a condition
2910 that the branch tests and if the branch is not itself the
2911 target of any branch. */
2912 if ((pinfo
& INSN_UNCOND_BRANCH_DELAY
)
2913 || (pinfo
& INSN_COND_BRANCH_DELAY
))
2915 if (mips_optimize
< 2
2916 /* If we have seen .set volatile or .set nomove, don't
2918 || mips_opts
.nomove
!= 0
2919 /* We can't swap if the previous instruction's position
2921 || history
[0].fixed_p
2922 /* If the previous previous insn was in a .set
2923 noreorder, we can't swap. Actually, the MIPS
2924 assembler will swap in this situation. However, gcc
2925 configured -with-gnu-as will generate code like
2931 in which we can not swap the bne and INSN. If gcc is
2932 not configured -with-gnu-as, it does not output the
2934 || history
[1].noreorder_p
2935 /* If the branch is itself the target of a branch, we
2936 can not swap. We cheat on this; all we check for is
2937 whether there is a label on this instruction. If
2938 there are any branches to anything other than a
2939 label, users must use .set noreorder. */
2940 || si
->label_list
!= NULL
2941 /* If the previous instruction is in a variant frag
2942 other than this branch's one, we cannot do the swap.
2943 This does not apply to the mips16, which uses variant
2944 frags for different purposes. */
2945 || (! mips_opts
.mips16
2946 && prev_insn_frag_type
== rs_machine_dependent
)
2947 /* Check for conflicts between the branch and the instructions
2948 before the candidate delay slot. */
2949 || nops_for_insn (history
+ 1, ip
) > 0
2950 /* Check for conflicts between the swapped sequence and the
2951 target of the branch. */
2952 || nops_for_sequence (2, history
+ 1, ip
, history
) > 0
2953 /* We do not swap with a trap instruction, since it
2954 complicates trap handlers to have the trap
2955 instruction be in a delay slot. */
2956 || (prev_pinfo
& INSN_TRAP
)
2957 /* If the branch reads a register that the previous
2958 instruction sets, we can not swap. */
2959 || (! mips_opts
.mips16
2960 && (prev_pinfo
& INSN_WRITE_GPR_T
)
2961 && insn_uses_reg (ip
, EXTRACT_OPERAND (RT
, history
[0]),
2963 || (! mips_opts
.mips16
2964 && (prev_pinfo
& INSN_WRITE_GPR_D
)
2965 && insn_uses_reg (ip
, EXTRACT_OPERAND (RD
, history
[0]),
2967 || (mips_opts
.mips16
2968 && (((prev_pinfo
& MIPS16_INSN_WRITE_X
)
2970 (ip
, MIPS16_EXTRACT_OPERAND (RX
, history
[0]),
2972 || ((prev_pinfo
& MIPS16_INSN_WRITE_Y
)
2974 (ip
, MIPS16_EXTRACT_OPERAND (RY
, history
[0]),
2976 || ((prev_pinfo
& MIPS16_INSN_WRITE_Z
)
2978 (ip
, MIPS16_EXTRACT_OPERAND (RZ
, history
[0]),
2980 || ((prev_pinfo
& MIPS16_INSN_WRITE_T
)
2981 && insn_uses_reg (ip
, TREG
, MIPS_GR_REG
))
2982 || ((prev_pinfo
& MIPS16_INSN_WRITE_31
)
2983 && insn_uses_reg (ip
, RA
, MIPS_GR_REG
))
2984 || ((prev_pinfo
& MIPS16_INSN_WRITE_GPR_Y
)
2985 && insn_uses_reg (ip
,
2986 MIPS16OP_EXTRACT_REG32R
2987 (history
[0].insn_opcode
),
2989 /* If the branch writes a register that the previous
2990 instruction sets, we can not swap (we know that
2991 branches write only to RD or to $31). */
2992 || (! mips_opts
.mips16
2993 && (prev_pinfo
& INSN_WRITE_GPR_T
)
2994 && (((pinfo
& INSN_WRITE_GPR_D
)
2995 && (EXTRACT_OPERAND (RT
, history
[0])
2996 == EXTRACT_OPERAND (RD
, *ip
)))
2997 || ((pinfo
& INSN_WRITE_GPR_31
)
2998 && EXTRACT_OPERAND (RT
, history
[0]) == RA
)))
2999 || (! mips_opts
.mips16
3000 && (prev_pinfo
& INSN_WRITE_GPR_D
)
3001 && (((pinfo
& INSN_WRITE_GPR_D
)
3002 && (EXTRACT_OPERAND (RD
, history
[0])
3003 == EXTRACT_OPERAND (RD
, *ip
)))
3004 || ((pinfo
& INSN_WRITE_GPR_31
)
3005 && EXTRACT_OPERAND (RD
, history
[0]) == RA
)))
3006 || (mips_opts
.mips16
3007 && (pinfo
& MIPS16_INSN_WRITE_31
)
3008 && ((prev_pinfo
& MIPS16_INSN_WRITE_31
)
3009 || ((prev_pinfo
& MIPS16_INSN_WRITE_GPR_Y
)
3010 && (MIPS16OP_EXTRACT_REG32R (history
[0].insn_opcode
)
3012 /* If the branch writes a register that the previous
3013 instruction reads, we can not swap (we know that
3014 branches only write to RD or to $31). */
3015 || (! mips_opts
.mips16
3016 && (pinfo
& INSN_WRITE_GPR_D
)
3017 && insn_uses_reg (&history
[0],
3018 EXTRACT_OPERAND (RD
, *ip
),
3020 || (! mips_opts
.mips16
3021 && (pinfo
& INSN_WRITE_GPR_31
)
3022 && insn_uses_reg (&history
[0], RA
, MIPS_GR_REG
))
3023 || (mips_opts
.mips16
3024 && (pinfo
& MIPS16_INSN_WRITE_31
)
3025 && insn_uses_reg (&history
[0], RA
, MIPS_GR_REG
))
3026 /* If one instruction sets a condition code and the
3027 other one uses a condition code, we can not swap. */
3028 || ((pinfo
& INSN_READ_COND_CODE
)
3029 && (prev_pinfo
& INSN_WRITE_COND_CODE
))
3030 || ((pinfo
& INSN_WRITE_COND_CODE
)
3031 && (prev_pinfo
& INSN_READ_COND_CODE
))
3032 /* If the previous instruction uses the PC, we can not
3034 || (mips_opts
.mips16
3035 && (prev_pinfo
& MIPS16_INSN_READ_PC
))
3036 /* If the previous instruction had a fixup in mips16
3037 mode, we can not swap. This normally means that the
3038 previous instruction was a 4 byte branch anyhow. */
3039 || (mips_opts
.mips16
&& history
[0].fixp
[0])
3040 /* If the previous instruction is a sync, sync.l, or
3041 sync.p, we can not swap. */
3042 || (prev_pinfo
& INSN_SYNC
))
3044 if (mips_opts
.mips16
3045 && (pinfo
& INSN_UNCOND_BRANCH_DELAY
)
3046 && (pinfo
& (MIPS16_INSN_READ_X
| MIPS16_INSN_READ_31
))
3047 && ISA_SUPPORTS_MIPS16E
)
3049 /* Convert MIPS16 jr/jalr into a "compact" jump. */
3050 ip
->insn_opcode
|= 0x0080;
3052 insert_into_history (0, 1, ip
);
3056 /* We could do even better for unconditional branches to
3057 portions of this object file; we could pick up the
3058 instruction at the destination, put it in the delay
3059 slot, and bump the destination address. */
3060 insert_into_history (0, 1, ip
);
3064 if (mips_relax
.sequence
)
3065 mips_relax
.sizes
[mips_relax
.sequence
- 1] += 4;
3069 /* It looks like we can actually do the swap. */
3070 struct mips_cl_insn delay
= history
[0];
3071 if (mips_opts
.mips16
)
3073 know (delay
.frag
== ip
->frag
);
3074 move_insn (ip
, delay
.frag
, delay
.where
);
3075 move_insn (&delay
, ip
->frag
, ip
->where
+ insn_length (ip
));
3077 else if (relaxed_branch
)
3079 /* Add the delay slot instruction to the end of the
3080 current frag and shrink the fixed part of the
3081 original frag. If the branch occupies the tail of
3082 the latter, move it backwards to cover the gap. */
3083 delay
.frag
->fr_fix
-= 4;
3084 if (delay
.frag
== ip
->frag
)
3085 move_insn (ip
, ip
->frag
, ip
->where
- 4);
3086 add_fixed_insn (&delay
);
3090 move_insn (&delay
, ip
->frag
, ip
->where
);
3091 move_insn (ip
, history
[0].frag
, history
[0].where
);
3095 insert_into_history (0, 1, &delay
);
3098 /* If that was an unconditional branch, forget the previous
3099 insn information. */
3100 if (pinfo
& INSN_UNCOND_BRANCH_DELAY
)
3101 mips_no_prev_insn ();
3103 else if (pinfo
& INSN_COND_BRANCH_LIKELY
)
3105 /* We don't yet optimize a branch likely. What we should do
3106 is look at the target, copy the instruction found there
3107 into the delay slot, and increment the branch to jump to
3108 the next instruction. */
3109 insert_into_history (0, 1, ip
);
3113 insert_into_history (0, 1, ip
);
3116 insert_into_history (0, 1, ip
);
3118 /* We just output an insn, so the next one doesn't have a label. */
3119 mips_clear_insn_labels ();
3122 /* Forget that there was any previous instruction or label. */
3125 mips_no_prev_insn (void)
3127 prev_nop_frag
= NULL
;
3128 insert_into_history (0, ARRAY_SIZE (history
), NOP_INSN
);
3129 mips_clear_insn_labels ();
3132 /* This function must be called before we emit something other than
3133 instructions. It is like mips_no_prev_insn except that it inserts
3134 any NOPS that might be needed by previous instructions. */
3137 mips_emit_delays (void)
3139 if (! mips_opts
.noreorder
)
3141 int nops
= nops_for_insn (history
, NULL
);
3145 add_fixed_insn (NOP_INSN
);
3146 mips_move_labels ();
3149 mips_no_prev_insn ();
3152 /* Start a (possibly nested) noreorder block. */
3155 start_noreorder (void)
3157 if (mips_opts
.noreorder
== 0)
3162 /* None of the instructions before the .set noreorder can be moved. */
3163 for (i
= 0; i
< ARRAY_SIZE (history
); i
++)
3164 history
[i
].fixed_p
= 1;
3166 /* Insert any nops that might be needed between the .set noreorder
3167 block and the previous instructions. We will later remove any
3168 nops that turn out not to be needed. */
3169 nops
= nops_for_insn (history
, NULL
);
3172 if (mips_optimize
!= 0)
3174 /* Record the frag which holds the nop instructions, so
3175 that we can remove them if we don't need them. */
3176 frag_grow (mips_opts
.mips16
? nops
* 2 : nops
* 4);
3177 prev_nop_frag
= frag_now
;
3178 prev_nop_frag_holds
= nops
;
3179 prev_nop_frag_required
= 0;
3180 prev_nop_frag_since
= 0;
3183 for (; nops
> 0; --nops
)
3184 add_fixed_insn (NOP_INSN
);
3186 /* Move on to a new frag, so that it is safe to simply
3187 decrease the size of prev_nop_frag. */
3188 frag_wane (frag_now
);
3190 mips_move_labels ();
3192 mips16_mark_labels ();
3193 mips_clear_insn_labels ();
3195 mips_opts
.noreorder
++;
3196 mips_any_noreorder
= 1;
3199 /* End a nested noreorder block. */
3202 end_noreorder (void)
3204 mips_opts
.noreorder
--;
3205 if (mips_opts
.noreorder
== 0 && prev_nop_frag
!= NULL
)
3207 /* Commit to inserting prev_nop_frag_required nops and go back to
3208 handling nop insertion the .set reorder way. */
3209 prev_nop_frag
->fr_fix
-= ((prev_nop_frag_holds
- prev_nop_frag_required
)
3210 * (mips_opts
.mips16
? 2 : 4));
3211 insert_into_history (prev_nop_frag_since
,
3212 prev_nop_frag_required
, NOP_INSN
);
3213 prev_nop_frag
= NULL
;
3217 /* Set up global variables for the start of a new macro. */
3222 memset (&mips_macro_warning
.sizes
, 0, sizeof (mips_macro_warning
.sizes
));
3223 mips_macro_warning
.delay_slot_p
= (mips_opts
.noreorder
3224 && (history
[0].insn_mo
->pinfo
3225 & (INSN_UNCOND_BRANCH_DELAY
3226 | INSN_COND_BRANCH_DELAY
3227 | INSN_COND_BRANCH_LIKELY
)) != 0);
3230 /* Given that a macro is longer than 4 bytes, return the appropriate warning
3231 for it. Return null if no warning is needed. SUBTYPE is a bitmask of
3232 RELAX_DELAY_SLOT and RELAX_NOMACRO. */
3235 macro_warning (relax_substateT subtype
)
3237 if (subtype
& RELAX_DELAY_SLOT
)
3238 return _("Macro instruction expanded into multiple instructions"
3239 " in a branch delay slot");
3240 else if (subtype
& RELAX_NOMACRO
)
3241 return _("Macro instruction expanded into multiple instructions");
3246 /* Finish up a macro. Emit warnings as appropriate. */
3251 if (mips_macro_warning
.sizes
[0] > 4 || mips_macro_warning
.sizes
[1] > 4)
3253 relax_substateT subtype
;
3255 /* Set up the relaxation warning flags. */
3257 if (mips_macro_warning
.sizes
[1] > mips_macro_warning
.sizes
[0])
3258 subtype
|= RELAX_SECOND_LONGER
;
3259 if (mips_opts
.warn_about_macros
)
3260 subtype
|= RELAX_NOMACRO
;
3261 if (mips_macro_warning
.delay_slot_p
)
3262 subtype
|= RELAX_DELAY_SLOT
;
3264 if (mips_macro_warning
.sizes
[0] > 4 && mips_macro_warning
.sizes
[1] > 4)
3266 /* Either the macro has a single implementation or both
3267 implementations are longer than 4 bytes. Emit the
3269 const char *msg
= macro_warning (subtype
);
3275 /* One implementation might need a warning but the other
3276 definitely doesn't. */
3277 mips_macro_warning
.first_frag
->fr_subtype
|= subtype
;
3282 /* Read a macro's relocation codes from *ARGS and store them in *R.
3283 The first argument in *ARGS will be either the code for a single
3284 relocation or -1 followed by the three codes that make up a
3285 composite relocation. */
3288 macro_read_relocs (va_list *args
, bfd_reloc_code_real_type
*r
)
3292 next
= va_arg (*args
, int);
3294 r
[0] = (bfd_reloc_code_real_type
) next
;
3296 for (i
= 0; i
< 3; i
++)
3297 r
[i
] = (bfd_reloc_code_real_type
) va_arg (*args
, int);
3300 /* Build an instruction created by a macro expansion. This is passed
3301 a pointer to the count of instructions created so far, an
3302 expression, the name of the instruction to build, an operand format
3303 string, and corresponding arguments. */
3306 macro_build (expressionS
*ep
, const char *name
, const char *fmt
, ...)
3308 const struct mips_opcode
*mo
;
3309 struct mips_cl_insn insn
;
3310 bfd_reloc_code_real_type r
[3];
3313 va_start (args
, fmt
);
3315 if (mips_opts
.mips16
)
3317 mips16_macro_build (ep
, name
, fmt
, args
);
3322 r
[0] = BFD_RELOC_UNUSED
;
3323 r
[1] = BFD_RELOC_UNUSED
;
3324 r
[2] = BFD_RELOC_UNUSED
;
3325 mo
= (struct mips_opcode
*) hash_find (op_hash
, name
);
3327 assert (strcmp (name
, mo
->name
) == 0);
3329 /* Search until we get a match for NAME. It is assumed here that
3330 macros will never generate MDMX, MIPS-3D, DSP or MT instructions. */
3331 while (strcmp (fmt
, mo
->args
) != 0
3332 || mo
->pinfo
== INSN_MACRO
3333 || !OPCODE_IS_MEMBER (mo
,
3335 | (mips_opts
.mips16
? INSN_MIPS16
: 0)
3336 | (mips_opts
.ase_smartmips
? INSN_SMARTMIPS
: 0)),
3338 || (mips_opts
.arch
== CPU_R4650
&& (mo
->pinfo
& FP_D
) != 0))
3342 assert (strcmp (name
, mo
->name
) == 0);
3345 create_insn (&insn
, mo
);
3363 INSERT_OPERAND (SHAMT
, insn
, va_arg (args
, int));
3368 /* Note that in the macro case, these arguments are already
3369 in MSB form. (When handling the instruction in the
3370 non-macro case, these arguments are sizes from which
3371 MSB values must be calculated.) */
3372 INSERT_OPERAND (INSMSB
, insn
, va_arg (args
, int));
3378 /* Note that in the macro case, these arguments are already
3379 in MSBD form. (When handling the instruction in the
3380 non-macro case, these arguments are sizes from which
3381 MSBD values must be calculated.) */
3382 INSERT_OPERAND (EXTMSBD
, insn
, va_arg (args
, int));
3393 INSERT_OPERAND (RT
, insn
, va_arg (args
, int));
3397 INSERT_OPERAND (CODE
, insn
, va_arg (args
, int));
3402 INSERT_OPERAND (FT
, insn
, va_arg (args
, int));
3408 INSERT_OPERAND (RD
, insn
, va_arg (args
, int));
3413 int tmp
= va_arg (args
, int);
3415 INSERT_OPERAND (RT
, insn
, tmp
);
3416 INSERT_OPERAND (RD
, insn
, tmp
);
3422 INSERT_OPERAND (FS
, insn
, va_arg (args
, int));
3429 INSERT_OPERAND (SHAMT
, insn
, va_arg (args
, int));
3433 INSERT_OPERAND (FD
, insn
, va_arg (args
, int));
3437 INSERT_OPERAND (CODE20
, insn
, va_arg (args
, int));
3441 INSERT_OPERAND (CODE19
, insn
, va_arg (args
, int));
3445 INSERT_OPERAND (CODE2
, insn
, va_arg (args
, int));
3452 INSERT_OPERAND (RS
, insn
, va_arg (args
, int));
3458 macro_read_relocs (&args
, r
);
3459 assert (*r
== BFD_RELOC_GPREL16
3460 || *r
== BFD_RELOC_MIPS_LITERAL
3461 || *r
== BFD_RELOC_MIPS_HIGHER
3462 || *r
== BFD_RELOC_HI16_S
3463 || *r
== BFD_RELOC_LO16
3464 || *r
== BFD_RELOC_MIPS_GOT16
3465 || *r
== BFD_RELOC_MIPS_CALL16
3466 || *r
== BFD_RELOC_MIPS_GOT_DISP
3467 || *r
== BFD_RELOC_MIPS_GOT_PAGE
3468 || *r
== BFD_RELOC_MIPS_GOT_OFST
3469 || *r
== BFD_RELOC_MIPS_GOT_LO16
3470 || *r
== BFD_RELOC_MIPS_CALL_LO16
);
3474 macro_read_relocs (&args
, r
);
3476 && (ep
->X_op
== O_constant
3477 || (ep
->X_op
== O_symbol
3478 && (*r
== BFD_RELOC_MIPS_HIGHEST
3479 || *r
== BFD_RELOC_HI16_S
3480 || *r
== BFD_RELOC_HI16
3481 || *r
== BFD_RELOC_GPREL16
3482 || *r
== BFD_RELOC_MIPS_GOT_HI16
3483 || *r
== BFD_RELOC_MIPS_CALL_HI16
))));
3487 assert (ep
!= NULL
);
3490 * This allows macro() to pass an immediate expression for
3491 * creating short branches without creating a symbol.
3493 * We don't allow branch relaxation for these branches, as
3494 * they should only appear in ".set nomacro" anyway.
3496 if (ep
->X_op
== O_constant
)
3498 if ((ep
->X_add_number
& 3) != 0)
3499 as_bad (_("branch to misaligned address (0x%lx)"),
3500 (unsigned long) ep
->X_add_number
);
3501 if ((ep
->X_add_number
+ 0x20000) & ~0x3ffff)
3502 as_bad (_("branch address range overflow (0x%lx)"),
3503 (unsigned long) ep
->X_add_number
);
3504 insn
.insn_opcode
|= (ep
->X_add_number
>> 2) & 0xffff;
3508 *r
= BFD_RELOC_16_PCREL_S2
;
3512 assert (ep
!= NULL
);
3513 *r
= BFD_RELOC_MIPS_JMP
;
3517 INSERT_OPERAND (COPZ
, insn
, va_arg (args
, unsigned long));
3521 INSERT_OPERAND (CACHE
, insn
, va_arg (args
, unsigned long));
3530 assert (*r
== BFD_RELOC_UNUSED
? ep
== NULL
: ep
!= NULL
);
3532 append_insn (&insn
, ep
, r
);
3536 mips16_macro_build (expressionS
*ep
, const char *name
, const char *fmt
,
3539 struct mips_opcode
*mo
;
3540 struct mips_cl_insn insn
;
3541 bfd_reloc_code_real_type r
[3]
3542 = {BFD_RELOC_UNUSED
, BFD_RELOC_UNUSED
, BFD_RELOC_UNUSED
};
3544 mo
= (struct mips_opcode
*) hash_find (mips16_op_hash
, name
);
3546 assert (strcmp (name
, mo
->name
) == 0);
3548 while (strcmp (fmt
, mo
->args
) != 0 || mo
->pinfo
== INSN_MACRO
)
3552 assert (strcmp (name
, mo
->name
) == 0);
3555 create_insn (&insn
, mo
);
3573 MIPS16_INSERT_OPERAND (RY
, insn
, va_arg (args
, int));
3578 MIPS16_INSERT_OPERAND (RX
, insn
, va_arg (args
, int));
3582 MIPS16_INSERT_OPERAND (RZ
, insn
, va_arg (args
, int));
3586 MIPS16_INSERT_OPERAND (MOVE32Z
, insn
, va_arg (args
, int));
3596 MIPS16_INSERT_OPERAND (REGR32
, insn
, va_arg (args
, int));
3603 regno
= va_arg (args
, int);
3604 regno
= ((regno
& 7) << 2) | ((regno
& 0x18) >> 3);
3605 MIPS16_INSERT_OPERAND (REG32R
, insn
, regno
);
3626 assert (ep
!= NULL
);
3628 if (ep
->X_op
!= O_constant
)
3629 *r
= (int) BFD_RELOC_UNUSED
+ c
;
3632 mips16_immed (NULL
, 0, c
, ep
->X_add_number
, FALSE
, FALSE
,
3633 FALSE
, &insn
.insn_opcode
, &insn
.use_extend
,
3636 *r
= BFD_RELOC_UNUSED
;
3642 MIPS16_INSERT_OPERAND (IMM6
, insn
, va_arg (args
, int));
3649 assert (*r
== BFD_RELOC_UNUSED
? ep
== NULL
: ep
!= NULL
);
3651 append_insn (&insn
, ep
, r
);
3655 * Sign-extend 32-bit mode constants that have bit 31 set and all
3656 * higher bits unset.
3659 normalize_constant_expr (expressionS
*ex
)
3661 if (ex
->X_op
== O_constant
3662 && IS_ZEXT_32BIT_NUM (ex
->X_add_number
))
3663 ex
->X_add_number
= (((ex
->X_add_number
& 0xffffffff) ^ 0x80000000)
3668 * Sign-extend 32-bit mode address offsets that have bit 31 set and
3669 * all higher bits unset.
3672 normalize_address_expr (expressionS
*ex
)
3674 if (((ex
->X_op
== O_constant
&& HAVE_32BIT_ADDRESSES
)
3675 || (ex
->X_op
== O_symbol
&& HAVE_32BIT_SYMBOLS
))
3676 && IS_ZEXT_32BIT_NUM (ex
->X_add_number
))
3677 ex
->X_add_number
= (((ex
->X_add_number
& 0xffffffff) ^ 0x80000000)
3682 * Generate a "jalr" instruction with a relocation hint to the called
3683 * function. This occurs in NewABI PIC code.
3686 macro_build_jalr (expressionS
*ep
)
3695 macro_build (NULL
, "jalr", "d,s", RA
, PIC_CALL_REG
);
3697 fix_new_exp (frag_now
, f
- frag_now
->fr_literal
,
3698 4, ep
, FALSE
, BFD_RELOC_MIPS_JALR
);
3702 * Generate a "lui" instruction.
3705 macro_build_lui (expressionS
*ep
, int regnum
)
3707 expressionS high_expr
;
3708 const struct mips_opcode
*mo
;
3709 struct mips_cl_insn insn
;
3710 bfd_reloc_code_real_type r
[3]
3711 = {BFD_RELOC_UNUSED
, BFD_RELOC_UNUSED
, BFD_RELOC_UNUSED
};
3712 const char *name
= "lui";
3713 const char *fmt
= "t,u";
3715 assert (! mips_opts
.mips16
);
3719 if (high_expr
.X_op
== O_constant
)
3721 /* We can compute the instruction now without a relocation entry. */
3722 high_expr
.X_add_number
= ((high_expr
.X_add_number
+ 0x8000)
3724 *r
= BFD_RELOC_UNUSED
;
3728 assert (ep
->X_op
== O_symbol
);
3729 /* _gp_disp is a special case, used from s_cpload.
3730 __gnu_local_gp is used if mips_no_shared. */
3731 assert (mips_pic
== NO_PIC
3733 && strcmp (S_GET_NAME (ep
->X_add_symbol
), "_gp_disp") == 0)
3734 || (! mips_in_shared
3735 && strcmp (S_GET_NAME (ep
->X_add_symbol
),
3736 "__gnu_local_gp") == 0));
3737 *r
= BFD_RELOC_HI16_S
;
3740 mo
= hash_find (op_hash
, name
);
3741 assert (strcmp (name
, mo
->name
) == 0);
3742 assert (strcmp (fmt
, mo
->args
) == 0);
3743 create_insn (&insn
, mo
);
3745 insn
.insn_opcode
= insn
.insn_mo
->match
;
3746 INSERT_OPERAND (RT
, insn
, regnum
);
3747 if (*r
== BFD_RELOC_UNUSED
)
3749 insn
.insn_opcode
|= high_expr
.X_add_number
;
3750 append_insn (&insn
, NULL
, r
);
3753 append_insn (&insn
, &high_expr
, r
);
3756 /* Generate a sequence of instructions to do a load or store from a constant
3757 offset off of a base register (breg) into/from a target register (treg),
3758 using AT if necessary. */
3760 macro_build_ldst_constoffset (expressionS
*ep
, const char *op
,
3761 int treg
, int breg
, int dbl
)
3763 assert (ep
->X_op
== O_constant
);
3765 /* Sign-extending 32-bit constants makes their handling easier. */
3767 normalize_constant_expr (ep
);
3769 /* Right now, this routine can only handle signed 32-bit constants. */
3770 if (! IS_SEXT_32BIT_NUM(ep
->X_add_number
+ 0x8000))
3771 as_warn (_("operand overflow"));
3773 if (IS_SEXT_16BIT_NUM(ep
->X_add_number
))
3775 /* Signed 16-bit offset will fit in the op. Easy! */
3776 macro_build (ep
, op
, "t,o(b)", treg
, BFD_RELOC_LO16
, breg
);
3780 /* 32-bit offset, need multiple instructions and AT, like:
3781 lui $tempreg,const_hi (BFD_RELOC_HI16_S)
3782 addu $tempreg,$tempreg,$breg
3783 <op> $treg,const_lo($tempreg) (BFD_RELOC_LO16)
3784 to handle the complete offset. */
3785 macro_build_lui (ep
, AT
);
3786 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t", AT
, AT
, breg
);
3787 macro_build (ep
, op
, "t,o(b)", treg
, BFD_RELOC_LO16
, AT
);
3790 as_bad (_("Macro used $at after \".set noat\""));
3795 * Generates code to set the $at register to true (one)
3796 * if reg is less than the immediate expression.
3799 set_at (int reg
, int unsignedp
)
3801 if (imm_expr
.X_op
== O_constant
3802 && imm_expr
.X_add_number
>= -0x8000
3803 && imm_expr
.X_add_number
< 0x8000)
3804 macro_build (&imm_expr
, unsignedp
? "sltiu" : "slti", "t,r,j",
3805 AT
, reg
, BFD_RELOC_LO16
);
3808 load_register (AT
, &imm_expr
, HAVE_64BIT_GPRS
);
3809 macro_build (NULL
, unsignedp
? "sltu" : "slt", "d,v,t", AT
, reg
, AT
);
3813 /* Warn if an expression is not a constant. */
3816 check_absolute_expr (struct mips_cl_insn
*ip
, expressionS
*ex
)
3818 if (ex
->X_op
== O_big
)
3819 as_bad (_("unsupported large constant"));
3820 else if (ex
->X_op
!= O_constant
)
3821 as_bad (_("Instruction %s requires absolute expression"),
3824 if (HAVE_32BIT_GPRS
)
3825 normalize_constant_expr (ex
);
3828 /* Count the leading zeroes by performing a binary chop. This is a
3829 bulky bit of source, but performance is a LOT better for the
3830 majority of values than a simple loop to count the bits:
3831 for (lcnt = 0; (lcnt < 32); lcnt++)
3832 if ((v) & (1 << (31 - lcnt)))
3834 However it is not code size friendly, and the gain will drop a bit
3835 on certain cached systems.
3837 #define COUNT_TOP_ZEROES(v) \
3838 (((v) & ~0xffff) == 0 \
3839 ? ((v) & ~0xff) == 0 \
3840 ? ((v) & ~0xf) == 0 \
3841 ? ((v) & ~0x3) == 0 \
3842 ? ((v) & ~0x1) == 0 \
3847 : ((v) & ~0x7) == 0 \
3850 : ((v) & ~0x3f) == 0 \
3851 ? ((v) & ~0x1f) == 0 \
3854 : ((v) & ~0x7f) == 0 \
3857 : ((v) & ~0xfff) == 0 \
3858 ? ((v) & ~0x3ff) == 0 \
3859 ? ((v) & ~0x1ff) == 0 \
3862 : ((v) & ~0x7ff) == 0 \
3865 : ((v) & ~0x3fff) == 0 \
3866 ? ((v) & ~0x1fff) == 0 \
3869 : ((v) & ~0x7fff) == 0 \
3872 : ((v) & ~0xffffff) == 0 \
3873 ? ((v) & ~0xfffff) == 0 \
3874 ? ((v) & ~0x3ffff) == 0 \
3875 ? ((v) & ~0x1ffff) == 0 \
3878 : ((v) & ~0x7ffff) == 0 \
3881 : ((v) & ~0x3fffff) == 0 \
3882 ? ((v) & ~0x1fffff) == 0 \
3885 : ((v) & ~0x7fffff) == 0 \
3888 : ((v) & ~0xfffffff) == 0 \
3889 ? ((v) & ~0x3ffffff) == 0 \
3890 ? ((v) & ~0x1ffffff) == 0 \
3893 : ((v) & ~0x7ffffff) == 0 \
3896 : ((v) & ~0x3fffffff) == 0 \
3897 ? ((v) & ~0x1fffffff) == 0 \
3900 : ((v) & ~0x7fffffff) == 0 \
3905 * This routine generates the least number of instructions necessary to load
3906 * an absolute expression value into a register.
3909 load_register (int reg
, expressionS
*ep
, int dbl
)
3912 expressionS hi32
, lo32
;
3914 if (ep
->X_op
!= O_big
)
3916 assert (ep
->X_op
== O_constant
);
3918 /* Sign-extending 32-bit constants makes their handling easier. */
3920 normalize_constant_expr (ep
);
3922 if (IS_SEXT_16BIT_NUM (ep
->X_add_number
))
3924 /* We can handle 16 bit signed values with an addiu to
3925 $zero. No need to ever use daddiu here, since $zero and
3926 the result are always correct in 32 bit mode. */
3927 macro_build (ep
, "addiu", "t,r,j", reg
, 0, BFD_RELOC_LO16
);
3930 else if (ep
->X_add_number
>= 0 && ep
->X_add_number
< 0x10000)
3932 /* We can handle 16 bit unsigned values with an ori to
3934 macro_build (ep
, "ori", "t,r,i", reg
, 0, BFD_RELOC_LO16
);
3937 else if ((IS_SEXT_32BIT_NUM (ep
->X_add_number
)))
3939 /* 32 bit values require an lui. */
3940 macro_build (ep
, "lui", "t,u", reg
, BFD_RELOC_HI16
);
3941 if ((ep
->X_add_number
& 0xffff) != 0)
3942 macro_build (ep
, "ori", "t,r,i", reg
, reg
, BFD_RELOC_LO16
);
3947 /* The value is larger than 32 bits. */
3949 if (!dbl
|| HAVE_32BIT_GPRS
)
3953 sprintf_vma (value
, ep
->X_add_number
);
3954 as_bad (_("Number (0x%s) larger than 32 bits"), value
);
3955 macro_build (ep
, "addiu", "t,r,j", reg
, 0, BFD_RELOC_LO16
);
3959 if (ep
->X_op
!= O_big
)
3962 hi32
.X_add_number
= (valueT
) hi32
.X_add_number
>> 16;
3963 hi32
.X_add_number
= (valueT
) hi32
.X_add_number
>> 16;
3964 hi32
.X_add_number
&= 0xffffffff;
3966 lo32
.X_add_number
&= 0xffffffff;
3970 assert (ep
->X_add_number
> 2);
3971 if (ep
->X_add_number
== 3)
3972 generic_bignum
[3] = 0;
3973 else if (ep
->X_add_number
> 4)
3974 as_bad (_("Number larger than 64 bits"));
3975 lo32
.X_op
= O_constant
;
3976 lo32
.X_add_number
= generic_bignum
[0] + (generic_bignum
[1] << 16);
3977 hi32
.X_op
= O_constant
;
3978 hi32
.X_add_number
= generic_bignum
[2] + (generic_bignum
[3] << 16);
3981 if (hi32
.X_add_number
== 0)
3986 unsigned long hi
, lo
;
3988 if (hi32
.X_add_number
== (offsetT
) 0xffffffff)
3990 if ((lo32
.X_add_number
& 0xffff8000) == 0xffff8000)
3992 macro_build (&lo32
, "addiu", "t,r,j", reg
, 0, BFD_RELOC_LO16
);
3995 if (lo32
.X_add_number
& 0x80000000)
3997 macro_build (&lo32
, "lui", "t,u", reg
, BFD_RELOC_HI16
);
3998 if (lo32
.X_add_number
& 0xffff)
3999 macro_build (&lo32
, "ori", "t,r,i", reg
, reg
, BFD_RELOC_LO16
);
4004 /* Check for 16bit shifted constant. We know that hi32 is
4005 non-zero, so start the mask on the first bit of the hi32
4010 unsigned long himask
, lomask
;
4014 himask
= 0xffff >> (32 - shift
);
4015 lomask
= (0xffff << shift
) & 0xffffffff;
4019 himask
= 0xffff << (shift
- 32);
4022 if ((hi32
.X_add_number
& ~(offsetT
) himask
) == 0
4023 && (lo32
.X_add_number
& ~(offsetT
) lomask
) == 0)
4027 tmp
.X_op
= O_constant
;
4029 tmp
.X_add_number
= ((hi32
.X_add_number
<< (32 - shift
))
4030 | (lo32
.X_add_number
>> shift
));
4032 tmp
.X_add_number
= hi32
.X_add_number
>> (shift
- 32);
4033 macro_build (&tmp
, "ori", "t,r,i", reg
, 0, BFD_RELOC_LO16
);
4034 macro_build (NULL
, (shift
>= 32) ? "dsll32" : "dsll", "d,w,<",
4035 reg
, reg
, (shift
>= 32) ? shift
- 32 : shift
);
4040 while (shift
<= (64 - 16));
4042 /* Find the bit number of the lowest one bit, and store the
4043 shifted value in hi/lo. */
4044 hi
= (unsigned long) (hi32
.X_add_number
& 0xffffffff);
4045 lo
= (unsigned long) (lo32
.X_add_number
& 0xffffffff);
4049 while ((lo
& 1) == 0)
4054 lo
|= (hi
& (((unsigned long) 1 << bit
) - 1)) << (32 - bit
);
4060 while ((hi
& 1) == 0)
4069 /* Optimize if the shifted value is a (power of 2) - 1. */
4070 if ((hi
== 0 && ((lo
+ 1) & lo
) == 0)
4071 || (lo
== 0xffffffff && ((hi
+ 1) & hi
) == 0))
4073 shift
= COUNT_TOP_ZEROES ((unsigned int) hi32
.X_add_number
);
4078 /* This instruction will set the register to be all
4080 tmp
.X_op
= O_constant
;
4081 tmp
.X_add_number
= (offsetT
) -1;
4082 macro_build (&tmp
, "addiu", "t,r,j", reg
, 0, BFD_RELOC_LO16
);
4086 macro_build (NULL
, (bit
>= 32) ? "dsll32" : "dsll", "d,w,<",
4087 reg
, reg
, (bit
>= 32) ? bit
- 32 : bit
);
4089 macro_build (NULL
, (shift
>= 32) ? "dsrl32" : "dsrl", "d,w,<",
4090 reg
, reg
, (shift
>= 32) ? shift
- 32 : shift
);
4095 /* Sign extend hi32 before calling load_register, because we can
4096 generally get better code when we load a sign extended value. */
4097 if ((hi32
.X_add_number
& 0x80000000) != 0)
4098 hi32
.X_add_number
|= ~(offsetT
) 0xffffffff;
4099 load_register (reg
, &hi32
, 0);
4102 if ((lo32
.X_add_number
& 0xffff0000) == 0)
4106 macro_build (NULL
, "dsll32", "d,w,<", reg
, freg
, 0);
4114 if ((freg
== 0) && (lo32
.X_add_number
== (offsetT
) 0xffffffff))
4116 macro_build (&lo32
, "lui", "t,u", reg
, BFD_RELOC_HI16
);
4117 macro_build (NULL
, "dsrl32", "d,w,<", reg
, reg
, 0);
4123 macro_build (NULL
, "dsll", "d,w,<", reg
, freg
, 16);
4127 mid16
.X_add_number
>>= 16;
4128 macro_build (&mid16
, "ori", "t,r,i", reg
, freg
, BFD_RELOC_LO16
);
4129 macro_build (NULL
, "dsll", "d,w,<", reg
, reg
, 16);
4132 if ((lo32
.X_add_number
& 0xffff) != 0)
4133 macro_build (&lo32
, "ori", "t,r,i", reg
, freg
, BFD_RELOC_LO16
);
4137 load_delay_nop (void)
4139 if (!gpr_interlocks
)
4140 macro_build (NULL
, "nop", "");
4143 /* Load an address into a register. */
4146 load_address (int reg
, expressionS
*ep
, int *used_at
)
4148 if (ep
->X_op
!= O_constant
4149 && ep
->X_op
!= O_symbol
)
4151 as_bad (_("expression too complex"));
4152 ep
->X_op
= O_constant
;
4155 if (ep
->X_op
== O_constant
)
4157 load_register (reg
, ep
, HAVE_64BIT_ADDRESSES
);
4161 if (mips_pic
== NO_PIC
)
4163 /* If this is a reference to a GP relative symbol, we want
4164 addiu $reg,$gp,<sym> (BFD_RELOC_GPREL16)
4166 lui $reg,<sym> (BFD_RELOC_HI16_S)
4167 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
4168 If we have an addend, we always use the latter form.
4170 With 64bit address space and a usable $at we want
4171 lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST)
4172 lui $at,<sym> (BFD_RELOC_HI16_S)
4173 daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER)
4174 daddiu $at,<sym> (BFD_RELOC_LO16)
4178 If $at is already in use, we use a path which is suboptimal
4179 on superscalar processors.
4180 lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST)
4181 daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER)
4183 daddiu $reg,<sym> (BFD_RELOC_HI16_S)
4185 daddiu $reg,<sym> (BFD_RELOC_LO16)
4187 For GP relative symbols in 64bit address space we can use
4188 the same sequence as in 32bit address space. */
4189 if (HAVE_64BIT_SYMBOLS
)
4191 if ((valueT
) ep
->X_add_number
<= MAX_GPREL_OFFSET
4192 && !nopic_need_relax (ep
->X_add_symbol
, 1))
4194 relax_start (ep
->X_add_symbol
);
4195 macro_build (ep
, ADDRESS_ADDI_INSN
, "t,r,j", reg
,
4196 mips_gp_register
, BFD_RELOC_GPREL16
);
4200 if (*used_at
== 0 && !mips_opts
.noat
)
4202 macro_build (ep
, "lui", "t,u", reg
, BFD_RELOC_MIPS_HIGHEST
);
4203 macro_build (ep
, "lui", "t,u", AT
, BFD_RELOC_HI16_S
);
4204 macro_build (ep
, "daddiu", "t,r,j", reg
, reg
,
4205 BFD_RELOC_MIPS_HIGHER
);
4206 macro_build (ep
, "daddiu", "t,r,j", AT
, AT
, BFD_RELOC_LO16
);
4207 macro_build (NULL
, "dsll32", "d,w,<", reg
, reg
, 0);
4208 macro_build (NULL
, "daddu", "d,v,t", reg
, reg
, AT
);
4213 macro_build (ep
, "lui", "t,u", reg
, BFD_RELOC_MIPS_HIGHEST
);
4214 macro_build (ep
, "daddiu", "t,r,j", reg
, reg
,
4215 BFD_RELOC_MIPS_HIGHER
);
4216 macro_build (NULL
, "dsll", "d,w,<", reg
, reg
, 16);
4217 macro_build (ep
, "daddiu", "t,r,j", reg
, reg
, BFD_RELOC_HI16_S
);
4218 macro_build (NULL
, "dsll", "d,w,<", reg
, reg
, 16);
4219 macro_build (ep
, "daddiu", "t,r,j", reg
, reg
, BFD_RELOC_LO16
);
4222 if (mips_relax
.sequence
)
4227 if ((valueT
) ep
->X_add_number
<= MAX_GPREL_OFFSET
4228 && !nopic_need_relax (ep
->X_add_symbol
, 1))
4230 relax_start (ep
->X_add_symbol
);
4231 macro_build (ep
, ADDRESS_ADDI_INSN
, "t,r,j", reg
,
4232 mips_gp_register
, BFD_RELOC_GPREL16
);
4235 macro_build_lui (ep
, reg
);
4236 macro_build (ep
, ADDRESS_ADDI_INSN
, "t,r,j",
4237 reg
, reg
, BFD_RELOC_LO16
);
4238 if (mips_relax
.sequence
)
4242 else if (!mips_big_got
)
4246 /* If this is a reference to an external symbol, we want
4247 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4249 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4251 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
4252 If there is a constant, it must be added in after.
4254 If we have NewABI, we want
4255 lw $reg,<sym+cst>($gp) (BFD_RELOC_MIPS_GOT_DISP)
4256 unless we're referencing a global symbol with a non-zero
4257 offset, in which case cst must be added separately. */
4260 if (ep
->X_add_number
)
4262 ex
.X_add_number
= ep
->X_add_number
;
4263 ep
->X_add_number
= 0;
4264 relax_start (ep
->X_add_symbol
);
4265 macro_build (ep
, ADDRESS_LOAD_INSN
, "t,o(b)", reg
,
4266 BFD_RELOC_MIPS_GOT_DISP
, mips_gp_register
);
4267 if (ex
.X_add_number
< -0x8000 || ex
.X_add_number
>= 0x8000)
4268 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
4269 ex
.X_op
= O_constant
;
4270 macro_build (&ex
, ADDRESS_ADDI_INSN
, "t,r,j",
4271 reg
, reg
, BFD_RELOC_LO16
);
4272 ep
->X_add_number
= ex
.X_add_number
;
4275 macro_build (ep
, ADDRESS_LOAD_INSN
, "t,o(b)", reg
,
4276 BFD_RELOC_MIPS_GOT_DISP
, mips_gp_register
);
4277 if (mips_relax
.sequence
)
4282 ex
.X_add_number
= ep
->X_add_number
;
4283 ep
->X_add_number
= 0;
4284 macro_build (ep
, ADDRESS_LOAD_INSN
, "t,o(b)", reg
,
4285 BFD_RELOC_MIPS_GOT16
, mips_gp_register
);
4287 relax_start (ep
->X_add_symbol
);
4289 macro_build (ep
, ADDRESS_ADDI_INSN
, "t,r,j", reg
, reg
,
4293 if (ex
.X_add_number
!= 0)
4295 if (ex
.X_add_number
< -0x8000 || ex
.X_add_number
>= 0x8000)
4296 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
4297 ex
.X_op
= O_constant
;
4298 macro_build (&ex
, ADDRESS_ADDI_INSN
, "t,r,j",
4299 reg
, reg
, BFD_RELOC_LO16
);
4303 else if (mips_big_got
)
4307 /* This is the large GOT case. If this is a reference to an
4308 external symbol, we want
4309 lui $reg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
4311 lw $reg,<sym>($reg) (BFD_RELOC_MIPS_GOT_LO16)
4313 Otherwise, for a reference to a local symbol in old ABI, we want
4314 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4316 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
4317 If there is a constant, it must be added in after.
4319 In the NewABI, for local symbols, with or without offsets, we want:
4320 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
4321 addiu $reg,$reg,<sym> (BFD_RELOC_MIPS_GOT_OFST)
4325 ex
.X_add_number
= ep
->X_add_number
;
4326 ep
->X_add_number
= 0;
4327 relax_start (ep
->X_add_symbol
);
4328 macro_build (ep
, "lui", "t,u", reg
, BFD_RELOC_MIPS_GOT_HI16
);
4329 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t",
4330 reg
, reg
, mips_gp_register
);
4331 macro_build (ep
, ADDRESS_LOAD_INSN
, "t,o(b)",
4332 reg
, BFD_RELOC_MIPS_GOT_LO16
, reg
);
4333 if (ex
.X_add_number
< -0x8000 || ex
.X_add_number
>= 0x8000)
4334 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
4335 else if (ex
.X_add_number
)
4337 ex
.X_op
= O_constant
;
4338 macro_build (&ex
, ADDRESS_ADDI_INSN
, "t,r,j", reg
, reg
,
4342 ep
->X_add_number
= ex
.X_add_number
;
4344 macro_build (ep
, ADDRESS_LOAD_INSN
, "t,o(b)", reg
,
4345 BFD_RELOC_MIPS_GOT_PAGE
, mips_gp_register
);
4346 macro_build (ep
, ADDRESS_ADDI_INSN
, "t,r,j", reg
, reg
,
4347 BFD_RELOC_MIPS_GOT_OFST
);
4352 ex
.X_add_number
= ep
->X_add_number
;
4353 ep
->X_add_number
= 0;
4354 relax_start (ep
->X_add_symbol
);
4355 macro_build (ep
, "lui", "t,u", reg
, BFD_RELOC_MIPS_GOT_HI16
);
4356 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t",
4357 reg
, reg
, mips_gp_register
);
4358 macro_build (ep
, ADDRESS_LOAD_INSN
, "t,o(b)",
4359 reg
, BFD_RELOC_MIPS_GOT_LO16
, reg
);
4361 if (reg_needs_delay (mips_gp_register
))
4363 /* We need a nop before loading from $gp. This special
4364 check is required because the lui which starts the main
4365 instruction stream does not refer to $gp, and so will not
4366 insert the nop which may be required. */
4367 macro_build (NULL
, "nop", "");
4369 macro_build (ep
, ADDRESS_LOAD_INSN
, "t,o(b)", reg
,
4370 BFD_RELOC_MIPS_GOT16
, mips_gp_register
);
4372 macro_build (ep
, ADDRESS_ADDI_INSN
, "t,r,j", reg
, reg
,
4376 if (ex
.X_add_number
!= 0)
4378 if (ex
.X_add_number
< -0x8000 || ex
.X_add_number
>= 0x8000)
4379 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
4380 ex
.X_op
= O_constant
;
4381 macro_build (&ex
, ADDRESS_ADDI_INSN
, "t,r,j", reg
, reg
,
4389 if (mips_opts
.noat
&& *used_at
== 1)
4390 as_bad (_("Macro used $at after \".set noat\""));
4393 /* Move the contents of register SOURCE into register DEST. */
4396 move_register (int dest
, int source
)
4398 macro_build (NULL
, HAVE_32BIT_GPRS
? "addu" : "daddu", "d,v,t",
4402 /* Emit an SVR4 PIC sequence to load address LOCAL into DEST, where
4403 LOCAL is the sum of a symbol and a 16-bit or 32-bit displacement.
4404 The two alternatives are:
4406 Global symbol Local sybmol
4407 ------------- ------------
4408 lw DEST,%got(SYMBOL) lw DEST,%got(SYMBOL + OFFSET)
4410 addiu DEST,DEST,OFFSET addiu DEST,DEST,%lo(SYMBOL + OFFSET)
4412 load_got_offset emits the first instruction and add_got_offset
4413 emits the second for a 16-bit offset or add_got_offset_hilo emits
4414 a sequence to add a 32-bit offset using a scratch register. */
4417 load_got_offset (int dest
, expressionS
*local
)
4422 global
.X_add_number
= 0;
4424 relax_start (local
->X_add_symbol
);
4425 macro_build (&global
, ADDRESS_LOAD_INSN
, "t,o(b)", dest
,
4426 BFD_RELOC_MIPS_GOT16
, mips_gp_register
);
4428 macro_build (local
, ADDRESS_LOAD_INSN
, "t,o(b)", dest
,
4429 BFD_RELOC_MIPS_GOT16
, mips_gp_register
);
4434 add_got_offset (int dest
, expressionS
*local
)
4438 global
.X_op
= O_constant
;
4439 global
.X_op_symbol
= NULL
;
4440 global
.X_add_symbol
= NULL
;
4441 global
.X_add_number
= local
->X_add_number
;
4443 relax_start (local
->X_add_symbol
);
4444 macro_build (&global
, ADDRESS_ADDI_INSN
, "t,r,j",
4445 dest
, dest
, BFD_RELOC_LO16
);
4447 macro_build (local
, ADDRESS_ADDI_INSN
, "t,r,j", dest
, dest
, BFD_RELOC_LO16
);
4452 add_got_offset_hilo (int dest
, expressionS
*local
, int tmp
)
4455 int hold_mips_optimize
;
4457 global
.X_op
= O_constant
;
4458 global
.X_op_symbol
= NULL
;
4459 global
.X_add_symbol
= NULL
;
4460 global
.X_add_number
= local
->X_add_number
;
4462 relax_start (local
->X_add_symbol
);
4463 load_register (tmp
, &global
, HAVE_64BIT_ADDRESSES
);
4465 /* Set mips_optimize around the lui instruction to avoid
4466 inserting an unnecessary nop after the lw. */
4467 hold_mips_optimize
= mips_optimize
;
4469 macro_build_lui (&global
, tmp
);
4470 mips_optimize
= hold_mips_optimize
;
4471 macro_build (local
, ADDRESS_ADDI_INSN
, "t,r,j", tmp
, tmp
, BFD_RELOC_LO16
);
4474 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t", dest
, dest
, tmp
);
4479 * This routine implements the seemingly endless macro or synthesized
4480 * instructions and addressing modes in the mips assembly language. Many
4481 * of these macros are simple and are similar to each other. These could
4482 * probably be handled by some kind of table or grammar approach instead of
4483 * this verbose method. Others are not simple macros but are more like
4484 * optimizing code generation.
4485 * One interesting optimization is when several store macros appear
4486 * consecutively that would load AT with the upper half of the same address.
4487 * The ensuing load upper instructions are ommited. This implies some kind
4488 * of global optimization. We currently only optimize within a single macro.
4489 * For many of the load and store macros if the address is specified as a
4490 * constant expression in the first 64k of memory (ie ld $2,0x4000c) we
4491 * first load register 'at' with zero and use it as the base register. The
4492 * mips assembler simply uses register $zero. Just one tiny optimization
4496 macro (struct mips_cl_insn
*ip
)
4498 int treg
, sreg
, dreg
, breg
;
4514 bfd_reloc_code_real_type r
;
4515 int hold_mips_optimize
;
4517 assert (! mips_opts
.mips16
);
4519 treg
= (ip
->insn_opcode
>> 16) & 0x1f;
4520 dreg
= (ip
->insn_opcode
>> 11) & 0x1f;
4521 sreg
= breg
= (ip
->insn_opcode
>> 21) & 0x1f;
4522 mask
= ip
->insn_mo
->mask
;
4524 expr1
.X_op
= O_constant
;
4525 expr1
.X_op_symbol
= NULL
;
4526 expr1
.X_add_symbol
= NULL
;
4527 expr1
.X_add_number
= 1;
4541 expr1
.X_add_number
= 8;
4542 macro_build (&expr1
, "bgez", "s,p", sreg
);
4544 macro_build (NULL
, "nop", "", 0);
4546 move_register (dreg
, sreg
);
4547 macro_build (NULL
, dbl
? "dsub" : "sub", "d,v,t", dreg
, 0, sreg
);
4570 if (imm_expr
.X_op
== O_constant
4571 && imm_expr
.X_add_number
>= -0x8000
4572 && imm_expr
.X_add_number
< 0x8000)
4574 macro_build (&imm_expr
, s
, "t,r,j", treg
, sreg
, BFD_RELOC_LO16
);
4578 load_register (AT
, &imm_expr
, dbl
);
4579 macro_build (NULL
, s2
, "d,v,t", treg
, sreg
, AT
);
4598 if (imm_expr
.X_op
== O_constant
4599 && imm_expr
.X_add_number
>= 0
4600 && imm_expr
.X_add_number
< 0x10000)
4602 if (mask
!= M_NOR_I
)
4603 macro_build (&imm_expr
, s
, "t,r,i", treg
, sreg
, BFD_RELOC_LO16
);
4606 macro_build (&imm_expr
, "ori", "t,r,i",
4607 treg
, sreg
, BFD_RELOC_LO16
);
4608 macro_build (NULL
, "nor", "d,v,t", treg
, treg
, 0);
4614 load_register (AT
, &imm_expr
, HAVE_64BIT_GPRS
);
4615 macro_build (NULL
, s2
, "d,v,t", treg
, sreg
, AT
);
4632 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 0)
4634 macro_build (&offset_expr
, s
, "s,t,p", sreg
, 0);
4638 load_register (AT
, &imm_expr
, HAVE_64BIT_GPRS
);
4639 macro_build (&offset_expr
, s
, "s,t,p", sreg
, AT
);
4647 macro_build (&offset_expr
, likely
? "bgezl" : "bgez", "s,p", sreg
);
4652 macro_build (&offset_expr
, likely
? "blezl" : "blez", "s,p", treg
);
4656 macro_build (NULL
, "slt", "d,v,t", AT
, sreg
, treg
);
4657 macro_build (&offset_expr
, likely
? "beql" : "beq", "s,t,p", AT
, 0);
4663 /* check for > max integer */
4664 maxnum
= 0x7fffffff;
4665 if (HAVE_64BIT_GPRS
&& sizeof (maxnum
) > 4)
4672 if (imm_expr
.X_op
== O_constant
4673 && imm_expr
.X_add_number
>= maxnum
4674 && (HAVE_32BIT_GPRS
|| sizeof (maxnum
) > 4))
4677 /* result is always false */
4679 macro_build (NULL
, "nop", "", 0);
4681 macro_build (&offset_expr
, "bnel", "s,t,p", 0, 0);
4684 if (imm_expr
.X_op
!= O_constant
)
4685 as_bad (_("Unsupported large constant"));
4686 ++imm_expr
.X_add_number
;
4690 if (mask
== M_BGEL_I
)
4692 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 0)
4694 macro_build (&offset_expr
, likely
? "bgezl" : "bgez", "s,p", sreg
);
4697 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 1)
4699 macro_build (&offset_expr
, likely
? "bgtzl" : "bgtz", "s,p", sreg
);
4702 maxnum
= 0x7fffffff;
4703 if (HAVE_64BIT_GPRS
&& sizeof (maxnum
) > 4)
4710 maxnum
= - maxnum
- 1;
4711 if (imm_expr
.X_op
== O_constant
4712 && imm_expr
.X_add_number
<= maxnum
4713 && (HAVE_32BIT_GPRS
|| sizeof (maxnum
) > 4))
4716 /* result is always true */
4717 as_warn (_("Branch %s is always true"), ip
->insn_mo
->name
);
4718 macro_build (&offset_expr
, "b", "p");
4723 macro_build (&offset_expr
, likely
? "beql" : "beq", "s,t,p", AT
, 0);
4733 macro_build (&offset_expr
, likely
? "beql" : "beq",
4738 macro_build (NULL
, "sltu", "d,v,t", AT
, sreg
, treg
);
4739 macro_build (&offset_expr
, likely
? "beql" : "beq", "s,t,p", AT
, 0);
4747 && imm_expr
.X_op
== O_constant
4748 && imm_expr
.X_add_number
== (offsetT
) 0xffffffff))
4750 if (imm_expr
.X_op
!= O_constant
)
4751 as_bad (_("Unsupported large constant"));
4752 ++imm_expr
.X_add_number
;
4756 if (mask
== M_BGEUL_I
)
4758 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 0)
4760 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 1)
4762 macro_build (&offset_expr
, likely
? "bnel" : "bne",
4768 macro_build (&offset_expr
, likely
? "beql" : "beq", "s,t,p", AT
, 0);
4776 macro_build (&offset_expr
, likely
? "bgtzl" : "bgtz", "s,p", sreg
);
4781 macro_build (&offset_expr
, likely
? "bltzl" : "bltz", "s,p", treg
);
4785 macro_build (NULL
, "slt", "d,v,t", AT
, treg
, sreg
);
4786 macro_build (&offset_expr
, likely
? "bnel" : "bne", "s,t,p", AT
, 0);
4794 macro_build (&offset_expr
, likely
? "bnel" : "bne",
4801 macro_build (NULL
, "sltu", "d,v,t", AT
, treg
, sreg
);
4802 macro_build (&offset_expr
, likely
? "bnel" : "bne", "s,t,p", AT
, 0);
4810 macro_build (&offset_expr
, likely
? "blezl" : "blez", "s,p", sreg
);
4815 macro_build (&offset_expr
, likely
? "bgezl" : "bgez", "s,p", treg
);
4819 macro_build (NULL
, "slt", "d,v,t", AT
, treg
, sreg
);
4820 macro_build (&offset_expr
, likely
? "beql" : "beq", "s,t,p", AT
, 0);
4826 maxnum
= 0x7fffffff;
4827 if (HAVE_64BIT_GPRS
&& sizeof (maxnum
) > 4)
4834 if (imm_expr
.X_op
== O_constant
4835 && imm_expr
.X_add_number
>= maxnum
4836 && (HAVE_32BIT_GPRS
|| sizeof (maxnum
) > 4))
4838 if (imm_expr
.X_op
!= O_constant
)
4839 as_bad (_("Unsupported large constant"));
4840 ++imm_expr
.X_add_number
;
4844 if (mask
== M_BLTL_I
)
4846 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 0)
4848 macro_build (&offset_expr
, likely
? "bltzl" : "bltz", "s,p", sreg
);
4851 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 1)
4853 macro_build (&offset_expr
, likely
? "blezl" : "blez", "s,p", sreg
);
4858 macro_build (&offset_expr
, likely
? "bnel" : "bne", "s,t,p", AT
, 0);
4866 macro_build (&offset_expr
, likely
? "beql" : "beq",
4873 macro_build (NULL
, "sltu", "d,v,t", AT
, treg
, sreg
);
4874 macro_build (&offset_expr
, likely
? "beql" : "beq", "s,t,p", AT
, 0);
4882 && imm_expr
.X_op
== O_constant
4883 && imm_expr
.X_add_number
== (offsetT
) 0xffffffff))
4885 if (imm_expr
.X_op
!= O_constant
)
4886 as_bad (_("Unsupported large constant"));
4887 ++imm_expr
.X_add_number
;
4891 if (mask
== M_BLTUL_I
)
4893 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 0)
4895 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 1)
4897 macro_build (&offset_expr
, likely
? "beql" : "beq",
4903 macro_build (&offset_expr
, likely
? "bnel" : "bne", "s,t,p", AT
, 0);
4911 macro_build (&offset_expr
, likely
? "bltzl" : "bltz", "s,p", sreg
);
4916 macro_build (&offset_expr
, likely
? "bgtzl" : "bgtz", "s,p", treg
);
4920 macro_build (NULL
, "slt", "d,v,t", AT
, sreg
, treg
);
4921 macro_build (&offset_expr
, likely
? "bnel" : "bne", "s,t,p", AT
, 0);
4931 macro_build (&offset_expr
, likely
? "bnel" : "bne",
4936 macro_build (NULL
, "sltu", "d,v,t", AT
, sreg
, treg
);
4937 macro_build (&offset_expr
, likely
? "bnel" : "bne", "s,t,p", AT
, 0);
4945 if (imm_expr
.X_op
!= O_constant
|| imm2_expr
.X_op
!= O_constant
)
4947 as_bad (_("Unsupported large constant"));
4952 pos
= (unsigned long) imm_expr
.X_add_number
;
4953 size
= (unsigned long) imm2_expr
.X_add_number
;
4958 as_bad (_("Improper position (%lu)"), pos
);
4961 if (size
== 0 || size
> 64
4962 || (pos
+ size
- 1) > 63)
4964 as_bad (_("Improper extract size (%lu, position %lu)"),
4969 if (size
<= 32 && pos
< 32)
4974 else if (size
<= 32)
4984 macro_build ((expressionS
*) NULL
, s
, fmt
, treg
, sreg
, pos
, size
- 1);
4993 if (imm_expr
.X_op
!= O_constant
|| imm2_expr
.X_op
!= O_constant
)
4995 as_bad (_("Unsupported large constant"));
5000 pos
= (unsigned long) imm_expr
.X_add_number
;
5001 size
= (unsigned long) imm2_expr
.X_add_number
;
5006 as_bad (_("Improper position (%lu)"), pos
);
5009 if (size
== 0 || size
> 64
5010 || (pos
+ size
- 1) > 63)
5012 as_bad (_("Improper insert size (%lu, position %lu)"),
5017 if (pos
< 32 && (pos
+ size
- 1) < 32)
5032 macro_build ((expressionS
*) NULL
, s
, fmt
, treg
, sreg
, pos
,
5049 as_warn (_("Divide by zero."));
5051 macro_build (NULL
, "teq", "s,t,q", 0, 0, 7);
5053 macro_build (NULL
, "break", "c", 7);
5060 macro_build (NULL
, "teq", "s,t,q", treg
, 0, 7);
5061 macro_build (NULL
, dbl
? "ddiv" : "div", "z,s,t", sreg
, treg
);
5065 expr1
.X_add_number
= 8;
5066 macro_build (&expr1
, "bne", "s,t,p", treg
, 0);
5067 macro_build (NULL
, dbl
? "ddiv" : "div", "z,s,t", sreg
, treg
);
5068 macro_build (NULL
, "break", "c", 7);
5070 expr1
.X_add_number
= -1;
5072 load_register (AT
, &expr1
, dbl
);
5073 expr1
.X_add_number
= mips_trap
? (dbl
? 12 : 8) : (dbl
? 20 : 16);
5074 macro_build (&expr1
, "bne", "s,t,p", treg
, AT
);
5077 expr1
.X_add_number
= 1;
5078 load_register (AT
, &expr1
, dbl
);
5079 macro_build (NULL
, "dsll32", "d,w,<", AT
, AT
, 31);
5083 expr1
.X_add_number
= 0x80000000;
5084 macro_build (&expr1
, "lui", "t,u", AT
, BFD_RELOC_HI16
);
5088 macro_build (NULL
, "teq", "s,t,q", sreg
, AT
, 6);
5089 /* We want to close the noreorder block as soon as possible, so
5090 that later insns are available for delay slot filling. */
5095 expr1
.X_add_number
= 8;
5096 macro_build (&expr1
, "bne", "s,t,p", sreg
, AT
);
5097 macro_build (NULL
, "nop", "", 0);
5099 /* We want to close the noreorder block as soon as possible, so
5100 that later insns are available for delay slot filling. */
5103 macro_build (NULL
, "break", "c", 6);
5105 macro_build (NULL
, s
, "d", dreg
);
5144 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 0)
5146 as_warn (_("Divide by zero."));
5148 macro_build (NULL
, "teq", "s,t,q", 0, 0, 7);
5150 macro_build (NULL
, "break", "c", 7);
5153 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 1)
5155 if (strcmp (s2
, "mflo") == 0)
5156 move_register (dreg
, sreg
);
5158 move_register (dreg
, 0);
5161 if (imm_expr
.X_op
== O_constant
5162 && imm_expr
.X_add_number
== -1
5163 && s
[strlen (s
) - 1] != 'u')
5165 if (strcmp (s2
, "mflo") == 0)
5167 macro_build (NULL
, dbl
? "dneg" : "neg", "d,w", dreg
, sreg
);
5170 move_register (dreg
, 0);
5175 load_register (AT
, &imm_expr
, dbl
);
5176 macro_build (NULL
, s
, "z,s,t", sreg
, AT
);
5177 macro_build (NULL
, s2
, "d", dreg
);
5199 macro_build (NULL
, "teq", "s,t,q", treg
, 0, 7);
5200 macro_build (NULL
, s
, "z,s,t", sreg
, treg
);
5201 /* We want to close the noreorder block as soon as possible, so
5202 that later insns are available for delay slot filling. */
5207 expr1
.X_add_number
= 8;
5208 macro_build (&expr1
, "bne", "s,t,p", treg
, 0);
5209 macro_build (NULL
, s
, "z,s,t", sreg
, treg
);
5211 /* We want to close the noreorder block as soon as possible, so
5212 that later insns are available for delay slot filling. */
5214 macro_build (NULL
, "break", "c", 7);
5216 macro_build (NULL
, s2
, "d", dreg
);
5228 /* Load the address of a symbol into a register. If breg is not
5229 zero, we then add a base register to it. */
5231 if (dbl
&& HAVE_32BIT_GPRS
)
5232 as_warn (_("dla used to load 32-bit register"));
5234 if (! dbl
&& HAVE_64BIT_OBJECTS
)
5235 as_warn (_("la used to load 64-bit address"));
5237 if (offset_expr
.X_op
== O_constant
5238 && offset_expr
.X_add_number
>= -0x8000
5239 && offset_expr
.X_add_number
< 0x8000)
5241 macro_build (&offset_expr
, ADDRESS_ADDI_INSN
,
5242 "t,r,j", treg
, sreg
, BFD_RELOC_LO16
);
5246 if (!mips_opts
.noat
&& (treg
== breg
))
5256 if (offset_expr
.X_op
!= O_symbol
5257 && offset_expr
.X_op
!= O_constant
)
5259 as_bad (_("expression too complex"));
5260 offset_expr
.X_op
= O_constant
;
5263 if (offset_expr
.X_op
== O_constant
)
5264 load_register (tempreg
, &offset_expr
, HAVE_64BIT_ADDRESSES
);
5265 else if (mips_pic
== NO_PIC
)
5267 /* If this is a reference to a GP relative symbol, we want
5268 addiu $tempreg,$gp,<sym> (BFD_RELOC_GPREL16)
5270 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
5271 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
5272 If we have a constant, we need two instructions anyhow,
5273 so we may as well always use the latter form.
5275 With 64bit address space and a usable $at we want
5276 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5277 lui $at,<sym> (BFD_RELOC_HI16_S)
5278 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
5279 daddiu $at,<sym> (BFD_RELOC_LO16)
5281 daddu $tempreg,$tempreg,$at
5283 If $at is already in use, we use a path which is suboptimal
5284 on superscalar processors.
5285 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5286 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
5288 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
5290 daddiu $tempreg,<sym> (BFD_RELOC_LO16)
5292 For GP relative symbols in 64bit address space we can use
5293 the same sequence as in 32bit address space. */
5294 if (HAVE_64BIT_SYMBOLS
)
5296 if ((valueT
) offset_expr
.X_add_number
<= MAX_GPREL_OFFSET
5297 && !nopic_need_relax (offset_expr
.X_add_symbol
, 1))
5299 relax_start (offset_expr
.X_add_symbol
);
5300 macro_build (&offset_expr
, ADDRESS_ADDI_INSN
, "t,r,j",
5301 tempreg
, mips_gp_register
, BFD_RELOC_GPREL16
);
5305 if (used_at
== 0 && !mips_opts
.noat
)
5307 macro_build (&offset_expr
, "lui", "t,u",
5308 tempreg
, BFD_RELOC_MIPS_HIGHEST
);
5309 macro_build (&offset_expr
, "lui", "t,u",
5310 AT
, BFD_RELOC_HI16_S
);
5311 macro_build (&offset_expr
, "daddiu", "t,r,j",
5312 tempreg
, tempreg
, BFD_RELOC_MIPS_HIGHER
);
5313 macro_build (&offset_expr
, "daddiu", "t,r,j",
5314 AT
, AT
, BFD_RELOC_LO16
);
5315 macro_build (NULL
, "dsll32", "d,w,<", tempreg
, tempreg
, 0);
5316 macro_build (NULL
, "daddu", "d,v,t", tempreg
, tempreg
, AT
);
5321 macro_build (&offset_expr
, "lui", "t,u",
5322 tempreg
, BFD_RELOC_MIPS_HIGHEST
);
5323 macro_build (&offset_expr
, "daddiu", "t,r,j",
5324 tempreg
, tempreg
, BFD_RELOC_MIPS_HIGHER
);
5325 macro_build (NULL
, "dsll", "d,w,<", tempreg
, tempreg
, 16);
5326 macro_build (&offset_expr
, "daddiu", "t,r,j",
5327 tempreg
, tempreg
, BFD_RELOC_HI16_S
);
5328 macro_build (NULL
, "dsll", "d,w,<", tempreg
, tempreg
, 16);
5329 macro_build (&offset_expr
, "daddiu", "t,r,j",
5330 tempreg
, tempreg
, BFD_RELOC_LO16
);
5333 if (mips_relax
.sequence
)
5338 if ((valueT
) offset_expr
.X_add_number
<= MAX_GPREL_OFFSET
5339 && !nopic_need_relax (offset_expr
.X_add_symbol
, 1))
5341 relax_start (offset_expr
.X_add_symbol
);
5342 macro_build (&offset_expr
, ADDRESS_ADDI_INSN
, "t,r,j",
5343 tempreg
, mips_gp_register
, BFD_RELOC_GPREL16
);
5346 if (!IS_SEXT_32BIT_NUM (offset_expr
.X_add_number
))
5347 as_bad (_("offset too large"));
5348 macro_build_lui (&offset_expr
, tempreg
);
5349 macro_build (&offset_expr
, ADDRESS_ADDI_INSN
, "t,r,j",
5350 tempreg
, tempreg
, BFD_RELOC_LO16
);
5351 if (mips_relax
.sequence
)
5355 else if (!mips_big_got
&& !HAVE_NEWABI
)
5357 int lw_reloc_type
= (int) BFD_RELOC_MIPS_GOT16
;
5359 /* If this is a reference to an external symbol, and there
5360 is no constant, we want
5361 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5362 or for lca or if tempreg is PIC_CALL_REG
5363 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
5364 For a local symbol, we want
5365 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5367 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
5369 If we have a small constant, and this is a reference to
5370 an external symbol, we want
5371 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5373 addiu $tempreg,$tempreg,<constant>
5374 For a local symbol, we want the same instruction
5375 sequence, but we output a BFD_RELOC_LO16 reloc on the
5378 If we have a large constant, and this is a reference to
5379 an external symbol, we want
5380 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5381 lui $at,<hiconstant>
5382 addiu $at,$at,<loconstant>
5383 addu $tempreg,$tempreg,$at
5384 For a local symbol, we want the same instruction
5385 sequence, but we output a BFD_RELOC_LO16 reloc on the
5389 if (offset_expr
.X_add_number
== 0)
5391 if (mips_pic
== SVR4_PIC
5393 && (call
|| tempreg
== PIC_CALL_REG
))
5394 lw_reloc_type
= (int) BFD_RELOC_MIPS_CALL16
;
5396 relax_start (offset_expr
.X_add_symbol
);
5397 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)", tempreg
,
5398 lw_reloc_type
, mips_gp_register
);
5401 /* We're going to put in an addu instruction using
5402 tempreg, so we may as well insert the nop right
5407 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)",
5408 tempreg
, BFD_RELOC_MIPS_GOT16
, mips_gp_register
);
5410 macro_build (&offset_expr
, ADDRESS_ADDI_INSN
, "t,r,j",
5411 tempreg
, tempreg
, BFD_RELOC_LO16
);
5413 /* FIXME: If breg == 0, and the next instruction uses
5414 $tempreg, then if this variant case is used an extra
5415 nop will be generated. */
5417 else if (offset_expr
.X_add_number
>= -0x8000
5418 && offset_expr
.X_add_number
< 0x8000)
5420 load_got_offset (tempreg
, &offset_expr
);
5422 add_got_offset (tempreg
, &offset_expr
);
5426 expr1
.X_add_number
= offset_expr
.X_add_number
;
5427 offset_expr
.X_add_number
=
5428 ((offset_expr
.X_add_number
+ 0x8000) & 0xffff) - 0x8000;
5429 load_got_offset (tempreg
, &offset_expr
);
5430 offset_expr
.X_add_number
= expr1
.X_add_number
;
5431 /* If we are going to add in a base register, and the
5432 target register and the base register are the same,
5433 then we are using AT as a temporary register. Since
5434 we want to load the constant into AT, we add our
5435 current AT (from the global offset table) and the
5436 register into the register now, and pretend we were
5437 not using a base register. */
5441 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t",
5446 add_got_offset_hilo (tempreg
, &offset_expr
, AT
);
5450 else if (!mips_big_got
&& HAVE_NEWABI
)
5452 int add_breg_early
= 0;
5454 /* If this is a reference to an external, and there is no
5455 constant, or local symbol (*), with or without a
5457 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
5458 or for lca or if tempreg is PIC_CALL_REG
5459 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
5461 If we have a small constant, and this is a reference to
5462 an external symbol, we want
5463 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
5464 addiu $tempreg,$tempreg,<constant>
5466 If we have a large constant, and this is a reference to
5467 an external symbol, we want
5468 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
5469 lui $at,<hiconstant>
5470 addiu $at,$at,<loconstant>
5471 addu $tempreg,$tempreg,$at
5473 (*) Other assemblers seem to prefer GOT_PAGE/GOT_OFST for
5474 local symbols, even though it introduces an additional
5477 if (offset_expr
.X_add_number
)
5479 expr1
.X_add_number
= offset_expr
.X_add_number
;
5480 offset_expr
.X_add_number
= 0;
5482 relax_start (offset_expr
.X_add_symbol
);
5483 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)", tempreg
,
5484 BFD_RELOC_MIPS_GOT_DISP
, mips_gp_register
);
5486 if (expr1
.X_add_number
>= -0x8000
5487 && expr1
.X_add_number
< 0x8000)
5489 macro_build (&expr1
, ADDRESS_ADDI_INSN
, "t,r,j",
5490 tempreg
, tempreg
, BFD_RELOC_LO16
);
5492 else if (IS_SEXT_32BIT_NUM (expr1
.X_add_number
+ 0x8000))
5496 /* If we are going to add in a base register, and the
5497 target register and the base register are the same,
5498 then we are using AT as a temporary register. Since
5499 we want to load the constant into AT, we add our
5500 current AT (from the global offset table) and the
5501 register into the register now, and pretend we were
5502 not using a base register. */
5507 assert (tempreg
== AT
);
5508 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t",
5514 load_register (AT
, &expr1
, HAVE_64BIT_ADDRESSES
);
5515 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t",
5521 as_bad (_("PIC code offset overflow (max 32 signed bits)"));
5524 offset_expr
.X_add_number
= expr1
.X_add_number
;
5526 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)", tempreg
,
5527 BFD_RELOC_MIPS_GOT_DISP
, mips_gp_register
);
5530 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t",
5531 treg
, tempreg
, breg
);
5537 else if (breg
== 0 && (call
|| tempreg
== PIC_CALL_REG
))
5539 relax_start (offset_expr
.X_add_symbol
);
5540 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)", tempreg
,
5541 BFD_RELOC_MIPS_CALL16
, mips_gp_register
);
5543 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)", tempreg
,
5544 BFD_RELOC_MIPS_GOT_DISP
, mips_gp_register
);
5549 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)", tempreg
,
5550 BFD_RELOC_MIPS_GOT_DISP
, mips_gp_register
);
5553 else if (mips_big_got
&& !HAVE_NEWABI
)
5556 int lui_reloc_type
= (int) BFD_RELOC_MIPS_GOT_HI16
;
5557 int lw_reloc_type
= (int) BFD_RELOC_MIPS_GOT_LO16
;
5558 int local_reloc_type
= (int) BFD_RELOC_MIPS_GOT16
;
5560 /* This is the large GOT case. If this is a reference to an
5561 external symbol, and there is no constant, we want
5562 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5563 addu $tempreg,$tempreg,$gp
5564 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5565 or for lca or if tempreg is PIC_CALL_REG
5566 lui $tempreg,<sym> (BFD_RELOC_MIPS_CALL_HI16)
5567 addu $tempreg,$tempreg,$gp
5568 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_CALL_LO16)
5569 For a local symbol, we want
5570 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5572 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
5574 If we have a small constant, and this is a reference to
5575 an external symbol, we want
5576 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5577 addu $tempreg,$tempreg,$gp
5578 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5580 addiu $tempreg,$tempreg,<constant>
5581 For a local symbol, we want
5582 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5584 addiu $tempreg,$tempreg,<constant> (BFD_RELOC_LO16)
5586 If we have a large constant, and this is a reference to
5587 an external symbol, we want
5588 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5589 addu $tempreg,$tempreg,$gp
5590 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5591 lui $at,<hiconstant>
5592 addiu $at,$at,<loconstant>
5593 addu $tempreg,$tempreg,$at
5594 For a local symbol, we want
5595 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5596 lui $at,<hiconstant>
5597 addiu $at,$at,<loconstant> (BFD_RELOC_LO16)
5598 addu $tempreg,$tempreg,$at
5601 expr1
.X_add_number
= offset_expr
.X_add_number
;
5602 offset_expr
.X_add_number
= 0;
5603 relax_start (offset_expr
.X_add_symbol
);
5604 gpdelay
= reg_needs_delay (mips_gp_register
);
5605 if (expr1
.X_add_number
== 0 && breg
== 0
5606 && (call
|| tempreg
== PIC_CALL_REG
))
5608 lui_reloc_type
= (int) BFD_RELOC_MIPS_CALL_HI16
;
5609 lw_reloc_type
= (int) BFD_RELOC_MIPS_CALL_LO16
;
5611 macro_build (&offset_expr
, "lui", "t,u", tempreg
, lui_reloc_type
);
5612 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t",
5613 tempreg
, tempreg
, mips_gp_register
);
5614 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)",
5615 tempreg
, lw_reloc_type
, tempreg
);
5616 if (expr1
.X_add_number
== 0)
5620 /* We're going to put in an addu instruction using
5621 tempreg, so we may as well insert the nop right
5626 else if (expr1
.X_add_number
>= -0x8000
5627 && expr1
.X_add_number
< 0x8000)
5630 macro_build (&expr1
, ADDRESS_ADDI_INSN
, "t,r,j",
5631 tempreg
, tempreg
, BFD_RELOC_LO16
);
5637 /* If we are going to add in a base register, and the
5638 target register and the base register are the same,
5639 then we are using AT as a temporary register. Since
5640 we want to load the constant into AT, we add our
5641 current AT (from the global offset table) and the
5642 register into the register now, and pretend we were
5643 not using a base register. */
5648 assert (tempreg
== AT
);
5650 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t",
5655 load_register (AT
, &expr1
, HAVE_64BIT_ADDRESSES
);
5656 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t", dreg
, dreg
, AT
);
5660 offset_expr
.X_add_number
=
5661 ((expr1
.X_add_number
+ 0x8000) & 0xffff) - 0x8000;
5666 /* This is needed because this instruction uses $gp, but
5667 the first instruction on the main stream does not. */
5668 macro_build (NULL
, "nop", "");
5671 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)", tempreg
,
5672 local_reloc_type
, mips_gp_register
);
5673 if (expr1
.X_add_number
>= -0x8000
5674 && expr1
.X_add_number
< 0x8000)
5677 macro_build (&offset_expr
, ADDRESS_ADDI_INSN
, "t,r,j",
5678 tempreg
, tempreg
, BFD_RELOC_LO16
);
5679 /* FIXME: If add_number is 0, and there was no base
5680 register, the external symbol case ended with a load,
5681 so if the symbol turns out to not be external, and
5682 the next instruction uses tempreg, an unnecessary nop
5683 will be inserted. */
5689 /* We must add in the base register now, as in the
5690 external symbol case. */
5691 assert (tempreg
== AT
);
5693 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t",
5696 /* We set breg to 0 because we have arranged to add
5697 it in in both cases. */
5701 macro_build_lui (&expr1
, AT
);
5702 macro_build (&offset_expr
, ADDRESS_ADDI_INSN
, "t,r,j",
5703 AT
, AT
, BFD_RELOC_LO16
);
5704 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t",
5705 tempreg
, tempreg
, AT
);
5710 else if (mips_big_got
&& HAVE_NEWABI
)
5712 int lui_reloc_type
= (int) BFD_RELOC_MIPS_GOT_HI16
;
5713 int lw_reloc_type
= (int) BFD_RELOC_MIPS_GOT_LO16
;
5714 int add_breg_early
= 0;
5716 /* This is the large GOT case. If this is a reference to an
5717 external symbol, and there is no constant, we want
5718 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5719 add $tempreg,$tempreg,$gp
5720 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5721 or for lca or if tempreg is PIC_CALL_REG
5722 lui $tempreg,<sym> (BFD_RELOC_MIPS_CALL_HI16)
5723 add $tempreg,$tempreg,$gp
5724 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_CALL_LO16)
5726 If we have a small constant, and this is a reference to
5727 an external symbol, we want
5728 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5729 add $tempreg,$tempreg,$gp
5730 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5731 addi $tempreg,$tempreg,<constant>
5733 If we have a large constant, and this is a reference to
5734 an external symbol, we want
5735 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5736 addu $tempreg,$tempreg,$gp
5737 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5738 lui $at,<hiconstant>
5739 addi $at,$at,<loconstant>
5740 add $tempreg,$tempreg,$at
5742 If we have NewABI, and we know it's a local symbol, we want
5743 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
5744 addiu $reg,$reg,<sym> (BFD_RELOC_MIPS_GOT_OFST)
5745 otherwise we have to resort to GOT_HI16/GOT_LO16. */
5747 relax_start (offset_expr
.X_add_symbol
);
5749 expr1
.X_add_number
= offset_expr
.X_add_number
;
5750 offset_expr
.X_add_number
= 0;
5752 if (expr1
.X_add_number
== 0 && breg
== 0
5753 && (call
|| tempreg
== PIC_CALL_REG
))
5755 lui_reloc_type
= (int) BFD_RELOC_MIPS_CALL_HI16
;
5756 lw_reloc_type
= (int) BFD_RELOC_MIPS_CALL_LO16
;
5758 macro_build (&offset_expr
, "lui", "t,u", tempreg
, lui_reloc_type
);
5759 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t",
5760 tempreg
, tempreg
, mips_gp_register
);
5761 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)",
5762 tempreg
, lw_reloc_type
, tempreg
);
5764 if (expr1
.X_add_number
== 0)
5766 else if (expr1
.X_add_number
>= -0x8000
5767 && expr1
.X_add_number
< 0x8000)
5769 macro_build (&expr1
, ADDRESS_ADDI_INSN
, "t,r,j",
5770 tempreg
, tempreg
, BFD_RELOC_LO16
);
5772 else if (IS_SEXT_32BIT_NUM (expr1
.X_add_number
+ 0x8000))
5776 /* If we are going to add in a base register, and the
5777 target register and the base register are the same,
5778 then we are using AT as a temporary register. Since
5779 we want to load the constant into AT, we add our
5780 current AT (from the global offset table) and the
5781 register into the register now, and pretend we were
5782 not using a base register. */
5787 assert (tempreg
== AT
);
5788 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t",
5794 load_register (AT
, &expr1
, HAVE_64BIT_ADDRESSES
);
5795 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t", dreg
, dreg
, AT
);
5800 as_bad (_("PIC code offset overflow (max 32 signed bits)"));
5803 offset_expr
.X_add_number
= expr1
.X_add_number
;
5804 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)", tempreg
,
5805 BFD_RELOC_MIPS_GOT_PAGE
, mips_gp_register
);
5806 macro_build (&offset_expr
, ADDRESS_ADDI_INSN
, "t,r,j", tempreg
,
5807 tempreg
, BFD_RELOC_MIPS_GOT_OFST
);
5810 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t",
5811 treg
, tempreg
, breg
);
5821 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t", treg
, tempreg
, breg
);
5825 /* The j instruction may not be used in PIC code, since it
5826 requires an absolute address. We convert it to a b
5828 if (mips_pic
== NO_PIC
)
5829 macro_build (&offset_expr
, "j", "a");
5831 macro_build (&offset_expr
, "b", "p");
5834 /* The jal instructions must be handled as macros because when
5835 generating PIC code they expand to multi-instruction
5836 sequences. Normally they are simple instructions. */
5841 if (mips_pic
== NO_PIC
)
5842 macro_build (NULL
, "jalr", "d,s", dreg
, sreg
);
5845 if (sreg
!= PIC_CALL_REG
)
5846 as_warn (_("MIPS PIC call to register other than $25"));
5848 macro_build (NULL
, "jalr", "d,s", dreg
, sreg
);
5849 if (mips_pic
== SVR4_PIC
&& !HAVE_NEWABI
)
5851 if (mips_cprestore_offset
< 0)
5852 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5855 if (! mips_frame_reg_valid
)
5857 as_warn (_("No .frame pseudo-op used in PIC code"));
5858 /* Quiet this warning. */
5859 mips_frame_reg_valid
= 1;
5861 if (! mips_cprestore_valid
)
5863 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5864 /* Quiet this warning. */
5865 mips_cprestore_valid
= 1;
5867 expr1
.X_add_number
= mips_cprestore_offset
;
5868 macro_build_ldst_constoffset (&expr1
, ADDRESS_LOAD_INSN
,
5871 HAVE_64BIT_ADDRESSES
);
5879 if (mips_pic
== NO_PIC
)
5880 macro_build (&offset_expr
, "jal", "a");
5881 else if (mips_pic
== SVR4_PIC
)
5883 /* If this is a reference to an external symbol, and we are
5884 using a small GOT, we want
5885 lw $25,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
5889 lw $gp,cprestore($sp)
5890 The cprestore value is set using the .cprestore
5891 pseudo-op. If we are using a big GOT, we want
5892 lui $25,<sym> (BFD_RELOC_MIPS_CALL_HI16)
5894 lw $25,<sym>($25) (BFD_RELOC_MIPS_CALL_LO16)
5898 lw $gp,cprestore($sp)
5899 If the symbol is not external, we want
5900 lw $25,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5902 addiu $25,$25,<sym> (BFD_RELOC_LO16)
5905 lw $gp,cprestore($sp)
5907 For NewABI, we use the same CALL16 or CALL_HI16/CALL_LO16
5908 sequences above, minus nops, unless the symbol is local,
5909 which enables us to use GOT_PAGE/GOT_OFST (big got) or
5915 relax_start (offset_expr
.X_add_symbol
);
5916 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)",
5917 PIC_CALL_REG
, BFD_RELOC_MIPS_CALL16
,
5920 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)",
5921 PIC_CALL_REG
, BFD_RELOC_MIPS_GOT_DISP
,
5927 relax_start (offset_expr
.X_add_symbol
);
5928 macro_build (&offset_expr
, "lui", "t,u", PIC_CALL_REG
,
5929 BFD_RELOC_MIPS_CALL_HI16
);
5930 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t", PIC_CALL_REG
,
5931 PIC_CALL_REG
, mips_gp_register
);
5932 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)",
5933 PIC_CALL_REG
, BFD_RELOC_MIPS_CALL_LO16
,
5936 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)",
5937 PIC_CALL_REG
, BFD_RELOC_MIPS_GOT_PAGE
,
5939 macro_build (&offset_expr
, ADDRESS_ADDI_INSN
, "t,r,j",
5940 PIC_CALL_REG
, PIC_CALL_REG
,
5941 BFD_RELOC_MIPS_GOT_OFST
);
5945 macro_build_jalr (&offset_expr
);
5949 relax_start (offset_expr
.X_add_symbol
);
5952 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)",
5953 PIC_CALL_REG
, BFD_RELOC_MIPS_CALL16
,
5962 gpdelay
= reg_needs_delay (mips_gp_register
);
5963 macro_build (&offset_expr
, "lui", "t,u", PIC_CALL_REG
,
5964 BFD_RELOC_MIPS_CALL_HI16
);
5965 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t", PIC_CALL_REG
,
5966 PIC_CALL_REG
, mips_gp_register
);
5967 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)",
5968 PIC_CALL_REG
, BFD_RELOC_MIPS_CALL_LO16
,
5973 macro_build (NULL
, "nop", "");
5975 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)",
5976 PIC_CALL_REG
, BFD_RELOC_MIPS_GOT16
,
5979 macro_build (&offset_expr
, ADDRESS_ADDI_INSN
, "t,r,j",
5980 PIC_CALL_REG
, PIC_CALL_REG
, BFD_RELOC_LO16
);
5982 macro_build_jalr (&offset_expr
);
5984 if (mips_cprestore_offset
< 0)
5985 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5988 if (! mips_frame_reg_valid
)
5990 as_warn (_("No .frame pseudo-op used in PIC code"));
5991 /* Quiet this warning. */
5992 mips_frame_reg_valid
= 1;
5994 if (! mips_cprestore_valid
)
5996 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5997 /* Quiet this warning. */
5998 mips_cprestore_valid
= 1;
6000 if (mips_opts
.noreorder
)
6001 macro_build (NULL
, "nop", "");
6002 expr1
.X_add_number
= mips_cprestore_offset
;
6003 macro_build_ldst_constoffset (&expr1
, ADDRESS_LOAD_INSN
,
6006 HAVE_64BIT_ADDRESSES
);
6010 else if (mips_pic
== VXWORKS_PIC
)
6011 as_bad (_("Non-PIC jump used in PIC library"));
6034 /* Itbl support may require additional care here. */
6039 /* Itbl support may require additional care here. */
6044 /* Itbl support may require additional care here. */
6049 /* Itbl support may require additional care here. */
6061 if (mips_opts
.arch
== CPU_R4650
)
6063 as_bad (_("opcode not supported on this processor"));
6067 /* Itbl support may require additional care here. */
6072 /* Itbl support may require additional care here. */
6077 /* Itbl support may require additional care here. */
6097 if (breg
== treg
|| coproc
|| lr
)
6118 /* Itbl support may require additional care here. */
6123 /* Itbl support may require additional care here. */
6128 /* Itbl support may require additional care here. */
6133 /* Itbl support may require additional care here. */
6152 if (mips_opts
.arch
== CPU_R4650
)
6154 as_bad (_("opcode not supported on this processor"));
6159 /* Itbl support may require additional care here. */
6163 /* Itbl support may require additional care here. */
6168 /* Itbl support may require additional care here. */
6180 /* Itbl support may require additional care here. */
6181 if (mask
== M_LWC1_AB
6182 || mask
== M_SWC1_AB
6183 || mask
== M_LDC1_AB
6184 || mask
== M_SDC1_AB
6188 else if (mask
== M_CACHE_AB
)
6195 if (offset_expr
.X_op
!= O_constant
6196 && offset_expr
.X_op
!= O_symbol
)
6198 as_bad (_("expression too complex"));
6199 offset_expr
.X_op
= O_constant
;
6202 if (HAVE_32BIT_ADDRESSES
6203 && !IS_SEXT_32BIT_NUM (offset_expr
.X_add_number
))
6207 sprintf_vma (value
, offset_expr
.X_add_number
);
6208 as_bad (_("Number (0x%s) larger than 32 bits"), value
);
6211 /* A constant expression in PIC code can be handled just as it
6212 is in non PIC code. */
6213 if (offset_expr
.X_op
== O_constant
)
6215 expr1
.X_add_number
= ((offset_expr
.X_add_number
+ 0x8000)
6216 & ~(bfd_vma
) 0xffff);
6217 normalize_address_expr (&expr1
);
6218 load_register (tempreg
, &expr1
, HAVE_64BIT_ADDRESSES
);
6220 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t",
6221 tempreg
, tempreg
, breg
);
6222 macro_build (&offset_expr
, s
, fmt
, treg
, BFD_RELOC_LO16
, tempreg
);
6224 else if (mips_pic
== NO_PIC
)
6226 /* If this is a reference to a GP relative symbol, and there
6227 is no base register, we want
6228 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
6229 Otherwise, if there is no base register, we want
6230 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
6231 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
6232 If we have a constant, we need two instructions anyhow,
6233 so we always use the latter form.
6235 If we have a base register, and this is a reference to a
6236 GP relative symbol, we want
6237 addu $tempreg,$breg,$gp
6238 <op> $treg,<sym>($tempreg) (BFD_RELOC_GPREL16)
6240 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
6241 addu $tempreg,$tempreg,$breg
6242 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
6243 With a constant we always use the latter case.
6245 With 64bit address space and no base register and $at usable,
6247 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
6248 lui $at,<sym> (BFD_RELOC_HI16_S)
6249 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
6252 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
6253 If we have a base register, we want
6254 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
6255 lui $at,<sym> (BFD_RELOC_HI16_S)
6256 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
6260 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
6262 Without $at we can't generate the optimal path for superscalar
6263 processors here since this would require two temporary registers.
6264 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
6265 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
6267 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
6269 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
6270 If we have a base register, we want
6271 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
6272 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
6274 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
6276 daddu $tempreg,$tempreg,$breg
6277 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
6279 For GP relative symbols in 64bit address space we can use
6280 the same sequence as in 32bit address space. */
6281 if (HAVE_64BIT_SYMBOLS
)
6283 if ((valueT
) offset_expr
.X_add_number
<= MAX_GPREL_OFFSET
6284 && !nopic_need_relax (offset_expr
.X_add_symbol
, 1))
6286 relax_start (offset_expr
.X_add_symbol
);
6289 macro_build (&offset_expr
, s
, fmt
, treg
,
6290 BFD_RELOC_GPREL16
, mips_gp_register
);
6294 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t",
6295 tempreg
, breg
, mips_gp_register
);
6296 macro_build (&offset_expr
, s
, fmt
, treg
,
6297 BFD_RELOC_GPREL16
, tempreg
);
6302 if (used_at
== 0 && !mips_opts
.noat
)
6304 macro_build (&offset_expr
, "lui", "t,u", tempreg
,
6305 BFD_RELOC_MIPS_HIGHEST
);
6306 macro_build (&offset_expr
, "lui", "t,u", AT
,
6308 macro_build (&offset_expr
, "daddiu", "t,r,j", tempreg
,
6309 tempreg
, BFD_RELOC_MIPS_HIGHER
);
6311 macro_build (NULL
, "daddu", "d,v,t", AT
, AT
, breg
);
6312 macro_build (NULL
, "dsll32", "d,w,<", tempreg
, tempreg
, 0);
6313 macro_build (NULL
, "daddu", "d,v,t", tempreg
, tempreg
, AT
);
6314 macro_build (&offset_expr
, s
, fmt
, treg
, BFD_RELOC_LO16
,
6320 macro_build (&offset_expr
, "lui", "t,u", tempreg
,
6321 BFD_RELOC_MIPS_HIGHEST
);
6322 macro_build (&offset_expr
, "daddiu", "t,r,j", tempreg
,
6323 tempreg
, BFD_RELOC_MIPS_HIGHER
);
6324 macro_build (NULL
, "dsll", "d,w,<", tempreg
, tempreg
, 16);
6325 macro_build (&offset_expr
, "daddiu", "t,r,j", tempreg
,
6326 tempreg
, BFD_RELOC_HI16_S
);
6327 macro_build (NULL
, "dsll", "d,w,<", tempreg
, tempreg
, 16);
6329 macro_build (NULL
, "daddu", "d,v,t",
6330 tempreg
, tempreg
, breg
);
6331 macro_build (&offset_expr
, s
, fmt
, treg
,
6332 BFD_RELOC_LO16
, tempreg
);
6335 if (mips_relax
.sequence
)
6342 if ((valueT
) offset_expr
.X_add_number
<= MAX_GPREL_OFFSET
6343 && !nopic_need_relax (offset_expr
.X_add_symbol
, 1))
6345 relax_start (offset_expr
.X_add_symbol
);
6346 macro_build (&offset_expr
, s
, fmt
, treg
, BFD_RELOC_GPREL16
,
6350 macro_build_lui (&offset_expr
, tempreg
);
6351 macro_build (&offset_expr
, s
, fmt
, treg
,
6352 BFD_RELOC_LO16
, tempreg
);
6353 if (mips_relax
.sequence
)
6358 if ((valueT
) offset_expr
.X_add_number
<= MAX_GPREL_OFFSET
6359 && !nopic_need_relax (offset_expr
.X_add_symbol
, 1))
6361 relax_start (offset_expr
.X_add_symbol
);
6362 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t",
6363 tempreg
, breg
, mips_gp_register
);
6364 macro_build (&offset_expr
, s
, fmt
, treg
,
6365 BFD_RELOC_GPREL16
, tempreg
);
6368 macro_build_lui (&offset_expr
, tempreg
);
6369 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t",
6370 tempreg
, tempreg
, breg
);
6371 macro_build (&offset_expr
, s
, fmt
, treg
,
6372 BFD_RELOC_LO16
, tempreg
);
6373 if (mips_relax
.sequence
)
6377 else if (!mips_big_got
)
6379 int lw_reloc_type
= (int) BFD_RELOC_MIPS_GOT16
;
6381 /* If this is a reference to an external symbol, we want
6382 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6384 <op> $treg,0($tempreg)
6386 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6388 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
6389 <op> $treg,0($tempreg)
6392 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
6393 <op> $treg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_OFST)
6395 If there is a base register, we add it to $tempreg before
6396 the <op>. If there is a constant, we stick it in the
6397 <op> instruction. We don't handle constants larger than
6398 16 bits, because we have no way to load the upper 16 bits
6399 (actually, we could handle them for the subset of cases
6400 in which we are not using $at). */
6401 assert (offset_expr
.X_op
== O_symbol
);
6404 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)", tempreg
,
6405 BFD_RELOC_MIPS_GOT_PAGE
, mips_gp_register
);
6407 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t",
6408 tempreg
, tempreg
, breg
);
6409 macro_build (&offset_expr
, s
, fmt
, treg
,
6410 BFD_RELOC_MIPS_GOT_OFST
, tempreg
);
6413 expr1
.X_add_number
= offset_expr
.X_add_number
;
6414 offset_expr
.X_add_number
= 0;
6415 if (expr1
.X_add_number
< -0x8000
6416 || expr1
.X_add_number
>= 0x8000)
6417 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6418 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)", tempreg
,
6419 lw_reloc_type
, mips_gp_register
);
6421 relax_start (offset_expr
.X_add_symbol
);
6423 macro_build (&offset_expr
, ADDRESS_ADDI_INSN
, "t,r,j", tempreg
,
6424 tempreg
, BFD_RELOC_LO16
);
6427 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t",
6428 tempreg
, tempreg
, breg
);
6429 macro_build (&expr1
, s
, fmt
, treg
, BFD_RELOC_LO16
, tempreg
);
6431 else if (mips_big_got
&& !HAVE_NEWABI
)
6435 /* If this is a reference to an external symbol, we want
6436 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
6437 addu $tempreg,$tempreg,$gp
6438 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
6439 <op> $treg,0($tempreg)
6441 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6443 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
6444 <op> $treg,0($tempreg)
6445 If there is a base register, we add it to $tempreg before
6446 the <op>. If there is a constant, we stick it in the
6447 <op> instruction. We don't handle constants larger than
6448 16 bits, because we have no way to load the upper 16 bits
6449 (actually, we could handle them for the subset of cases
6450 in which we are not using $at). */
6451 assert (offset_expr
.X_op
== O_symbol
);
6452 expr1
.X_add_number
= offset_expr
.X_add_number
;
6453 offset_expr
.X_add_number
= 0;
6454 if (expr1
.X_add_number
< -0x8000
6455 || expr1
.X_add_number
>= 0x8000)
6456 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6457 gpdelay
= reg_needs_delay (mips_gp_register
);
6458 relax_start (offset_expr
.X_add_symbol
);
6459 macro_build (&offset_expr
, "lui", "t,u", tempreg
,
6460 BFD_RELOC_MIPS_GOT_HI16
);
6461 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t", tempreg
, tempreg
,
6463 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)", tempreg
,
6464 BFD_RELOC_MIPS_GOT_LO16
, tempreg
);
6467 macro_build (NULL
, "nop", "");
6468 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)", tempreg
,
6469 BFD_RELOC_MIPS_GOT16
, mips_gp_register
);
6471 macro_build (&offset_expr
, ADDRESS_ADDI_INSN
, "t,r,j", tempreg
,
6472 tempreg
, BFD_RELOC_LO16
);
6476 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t",
6477 tempreg
, tempreg
, breg
);
6478 macro_build (&expr1
, s
, fmt
, treg
, BFD_RELOC_LO16
, tempreg
);
6480 else if (mips_big_got
&& HAVE_NEWABI
)
6482 /* If this is a reference to an external symbol, we want
6483 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
6484 add $tempreg,$tempreg,$gp
6485 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
6486 <op> $treg,<ofst>($tempreg)
6487 Otherwise, for local symbols, we want:
6488 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
6489 <op> $treg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_OFST) */
6490 assert (offset_expr
.X_op
== O_symbol
);
6491 expr1
.X_add_number
= offset_expr
.X_add_number
;
6492 offset_expr
.X_add_number
= 0;
6493 if (expr1
.X_add_number
< -0x8000
6494 || expr1
.X_add_number
>= 0x8000)
6495 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6496 relax_start (offset_expr
.X_add_symbol
);
6497 macro_build (&offset_expr
, "lui", "t,u", tempreg
,
6498 BFD_RELOC_MIPS_GOT_HI16
);
6499 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t", tempreg
, tempreg
,
6501 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)", tempreg
,
6502 BFD_RELOC_MIPS_GOT_LO16
, tempreg
);
6504 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t",
6505 tempreg
, tempreg
, breg
);
6506 macro_build (&expr1
, s
, fmt
, treg
, BFD_RELOC_LO16
, tempreg
);
6509 offset_expr
.X_add_number
= expr1
.X_add_number
;
6510 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)", tempreg
,
6511 BFD_RELOC_MIPS_GOT_PAGE
, mips_gp_register
);
6513 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t",
6514 tempreg
, tempreg
, breg
);
6515 macro_build (&offset_expr
, s
, fmt
, treg
,
6516 BFD_RELOC_MIPS_GOT_OFST
, tempreg
);
6526 load_register (treg
, &imm_expr
, 0);
6530 load_register (treg
, &imm_expr
, 1);
6534 if (imm_expr
.X_op
== O_constant
)
6537 load_register (AT
, &imm_expr
, 0);
6538 macro_build (NULL
, "mtc1", "t,G", AT
, treg
);
6543 assert (offset_expr
.X_op
== O_symbol
6544 && strcmp (segment_name (S_GET_SEGMENT
6545 (offset_expr
.X_add_symbol
)),
6547 && offset_expr
.X_add_number
== 0);
6548 macro_build (&offset_expr
, "lwc1", "T,o(b)", treg
,
6549 BFD_RELOC_MIPS_LITERAL
, mips_gp_register
);
6554 /* Check if we have a constant in IMM_EXPR. If the GPRs are 64 bits
6555 wide, IMM_EXPR is the entire value. Otherwise IMM_EXPR is the high
6556 order 32 bits of the value and the low order 32 bits are either
6557 zero or in OFFSET_EXPR. */
6558 if (imm_expr
.X_op
== O_constant
|| imm_expr
.X_op
== O_big
)
6560 if (HAVE_64BIT_GPRS
)
6561 load_register (treg
, &imm_expr
, 1);
6566 if (target_big_endian
)
6578 load_register (hreg
, &imm_expr
, 0);
6581 if (offset_expr
.X_op
== O_absent
)
6582 move_register (lreg
, 0);
6585 assert (offset_expr
.X_op
== O_constant
);
6586 load_register (lreg
, &offset_expr
, 0);
6593 /* We know that sym is in the .rdata section. First we get the
6594 upper 16 bits of the address. */
6595 if (mips_pic
== NO_PIC
)
6597 macro_build_lui (&offset_expr
, AT
);
6602 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)", AT
,
6603 BFD_RELOC_MIPS_GOT16
, mips_gp_register
);
6607 /* Now we load the register(s). */
6608 if (HAVE_64BIT_GPRS
)
6611 macro_build (&offset_expr
, "ld", "t,o(b)", treg
, BFD_RELOC_LO16
, AT
);
6616 macro_build (&offset_expr
, "lw", "t,o(b)", treg
, BFD_RELOC_LO16
, AT
);
6619 /* FIXME: How in the world do we deal with the possible
6621 offset_expr
.X_add_number
+= 4;
6622 macro_build (&offset_expr
, "lw", "t,o(b)",
6623 treg
+ 1, BFD_RELOC_LO16
, AT
);
6629 /* Check if we have a constant in IMM_EXPR. If the FPRs are 64 bits
6630 wide, IMM_EXPR is the entire value and the GPRs are known to be 64
6631 bits wide as well. Otherwise IMM_EXPR is the high order 32 bits of
6632 the value and the low order 32 bits are either zero or in
6634 if (imm_expr
.X_op
== O_constant
|| imm_expr
.X_op
== O_big
)
6637 load_register (AT
, &imm_expr
, HAVE_64BIT_FPRS
);
6638 if (HAVE_64BIT_FPRS
)
6640 assert (HAVE_64BIT_GPRS
);
6641 macro_build (NULL
, "dmtc1", "t,S", AT
, treg
);
6645 macro_build (NULL
, "mtc1", "t,G", AT
, treg
+ 1);
6646 if (offset_expr
.X_op
== O_absent
)
6647 macro_build (NULL
, "mtc1", "t,G", 0, treg
);
6650 assert (offset_expr
.X_op
== O_constant
);
6651 load_register (AT
, &offset_expr
, 0);
6652 macro_build (NULL
, "mtc1", "t,G", AT
, treg
);
6658 assert (offset_expr
.X_op
== O_symbol
6659 && offset_expr
.X_add_number
== 0);
6660 s
= segment_name (S_GET_SEGMENT (offset_expr
.X_add_symbol
));
6661 if (strcmp (s
, ".lit8") == 0)
6663 if (mips_opts
.isa
!= ISA_MIPS1
)
6665 macro_build (&offset_expr
, "ldc1", "T,o(b)", treg
,
6666 BFD_RELOC_MIPS_LITERAL
, mips_gp_register
);
6669 breg
= mips_gp_register
;
6670 r
= BFD_RELOC_MIPS_LITERAL
;
6675 assert (strcmp (s
, RDATA_SECTION_NAME
) == 0);
6677 if (mips_pic
!= NO_PIC
)
6678 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)", AT
,
6679 BFD_RELOC_MIPS_GOT16
, mips_gp_register
);
6682 /* FIXME: This won't work for a 64 bit address. */
6683 macro_build_lui (&offset_expr
, AT
);
6686 if (mips_opts
.isa
!= ISA_MIPS1
)
6688 macro_build (&offset_expr
, "ldc1", "T,o(b)",
6689 treg
, BFD_RELOC_LO16
, AT
);
6698 if (mips_opts
.arch
== CPU_R4650
)
6700 as_bad (_("opcode not supported on this processor"));
6703 /* Even on a big endian machine $fn comes before $fn+1. We have
6704 to adjust when loading from memory. */
6707 assert (mips_opts
.isa
== ISA_MIPS1
);
6708 macro_build (&offset_expr
, "lwc1", "T,o(b)",
6709 target_big_endian
? treg
+ 1 : treg
, r
, breg
);
6710 /* FIXME: A possible overflow which I don't know how to deal
6712 offset_expr
.X_add_number
+= 4;
6713 macro_build (&offset_expr
, "lwc1", "T,o(b)",
6714 target_big_endian
? treg
: treg
+ 1, r
, breg
);
6719 * The MIPS assembler seems to check for X_add_number not
6720 * being double aligned and generating:
6723 * addiu at,at,%lo(foo+1)
6726 * But, the resulting address is the same after relocation so why
6727 * generate the extra instruction?
6729 if (mips_opts
.arch
== CPU_R4650
)
6731 as_bad (_("opcode not supported on this processor"));
6734 /* Itbl support may require additional care here. */
6736 if (mips_opts
.isa
!= ISA_MIPS1
)
6747 if (mips_opts
.arch
== CPU_R4650
)
6749 as_bad (_("opcode not supported on this processor"));
6753 if (mips_opts
.isa
!= ISA_MIPS1
)
6761 /* Itbl support may require additional care here. */
6766 if (HAVE_64BIT_GPRS
)
6777 if (HAVE_64BIT_GPRS
)
6787 if (offset_expr
.X_op
!= O_symbol
6788 && offset_expr
.X_op
!= O_constant
)
6790 as_bad (_("expression too complex"));
6791 offset_expr
.X_op
= O_constant
;
6794 if (HAVE_32BIT_ADDRESSES
6795 && !IS_SEXT_32BIT_NUM (offset_expr
.X_add_number
))
6799 sprintf_vma (value
, offset_expr
.X_add_number
);
6800 as_bad (_("Number (0x%s) larger than 32 bits"), value
);
6803 /* Even on a big endian machine $fn comes before $fn+1. We have
6804 to adjust when loading from memory. We set coproc if we must
6805 load $fn+1 first. */
6806 /* Itbl support may require additional care here. */
6807 if (! target_big_endian
)
6810 if (mips_pic
== NO_PIC
6811 || offset_expr
.X_op
== O_constant
)
6813 /* If this is a reference to a GP relative symbol, we want
6814 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
6815 <op> $treg+1,<sym>+4($gp) (BFD_RELOC_GPREL16)
6816 If we have a base register, we use this
6818 <op> $treg,<sym>($at) (BFD_RELOC_GPREL16)
6819 <op> $treg+1,<sym>+4($at) (BFD_RELOC_GPREL16)
6820 If this is not a GP relative symbol, we want
6821 lui $at,<sym> (BFD_RELOC_HI16_S)
6822 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
6823 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
6824 If there is a base register, we add it to $at after the
6825 lui instruction. If there is a constant, we always use
6827 if (offset_expr
.X_op
== O_symbol
6828 && (valueT
) offset_expr
.X_add_number
<= MAX_GPREL_OFFSET
6829 && !nopic_need_relax (offset_expr
.X_add_symbol
, 1))
6831 relax_start (offset_expr
.X_add_symbol
);
6834 tempreg
= mips_gp_register
;
6838 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t",
6839 AT
, breg
, mips_gp_register
);
6844 /* Itbl support may require additional care here. */
6845 macro_build (&offset_expr
, s
, fmt
, coproc
? treg
+ 1 : treg
,
6846 BFD_RELOC_GPREL16
, tempreg
);
6847 offset_expr
.X_add_number
+= 4;
6849 /* Set mips_optimize to 2 to avoid inserting an
6851 hold_mips_optimize
= mips_optimize
;
6853 /* Itbl support may require additional care here. */
6854 macro_build (&offset_expr
, s
, fmt
, coproc
? treg
: treg
+ 1,
6855 BFD_RELOC_GPREL16
, tempreg
);
6856 mips_optimize
= hold_mips_optimize
;
6860 /* We just generated two relocs. When tc_gen_reloc
6861 handles this case, it will skip the first reloc and
6862 handle the second. The second reloc already has an
6863 extra addend of 4, which we added above. We must
6864 subtract it out, and then subtract another 4 to make
6865 the first reloc come out right. The second reloc
6866 will come out right because we are going to add 4 to
6867 offset_expr when we build its instruction below.
6869 If we have a symbol, then we don't want to include
6870 the offset, because it will wind up being included
6871 when we generate the reloc. */
6873 if (offset_expr
.X_op
== O_constant
)
6874 offset_expr
.X_add_number
-= 8;
6877 offset_expr
.X_add_number
= -4;
6878 offset_expr
.X_op
= O_constant
;
6882 macro_build_lui (&offset_expr
, AT
);
6884 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t", AT
, breg
, AT
);
6885 /* Itbl support may require additional care here. */
6886 macro_build (&offset_expr
, s
, fmt
, coproc
? treg
+ 1 : treg
,
6887 BFD_RELOC_LO16
, AT
);
6888 /* FIXME: How do we handle overflow here? */
6889 offset_expr
.X_add_number
+= 4;
6890 /* Itbl support may require additional care here. */
6891 macro_build (&offset_expr
, s
, fmt
, coproc
? treg
: treg
+ 1,
6892 BFD_RELOC_LO16
, AT
);
6893 if (mips_relax
.sequence
)
6896 else if (!mips_big_got
)
6898 /* If this is a reference to an external symbol, we want
6899 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6904 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6906 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
6907 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
6908 If there is a base register we add it to $at before the
6909 lwc1 instructions. If there is a constant we include it
6910 in the lwc1 instructions. */
6912 expr1
.X_add_number
= offset_expr
.X_add_number
;
6913 if (expr1
.X_add_number
< -0x8000
6914 || expr1
.X_add_number
>= 0x8000 - 4)
6915 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6916 load_got_offset (AT
, &offset_expr
);
6919 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t", AT
, breg
, AT
);
6921 /* Set mips_optimize to 2 to avoid inserting an undesired
6923 hold_mips_optimize
= mips_optimize
;
6926 /* Itbl support may require additional care here. */
6927 relax_start (offset_expr
.X_add_symbol
);
6928 macro_build (&expr1
, s
, fmt
, coproc
? treg
+ 1 : treg
,
6929 BFD_RELOC_LO16
, AT
);
6930 expr1
.X_add_number
+= 4;
6931 macro_build (&expr1
, s
, fmt
, coproc
? treg
: treg
+ 1,
6932 BFD_RELOC_LO16
, AT
);
6934 macro_build (&offset_expr
, s
, fmt
, coproc
? treg
+ 1 : treg
,
6935 BFD_RELOC_LO16
, AT
);
6936 offset_expr
.X_add_number
+= 4;
6937 macro_build (&offset_expr
, s
, fmt
, coproc
? treg
: treg
+ 1,
6938 BFD_RELOC_LO16
, AT
);
6941 mips_optimize
= hold_mips_optimize
;
6943 else if (mips_big_got
)
6947 /* If this is a reference to an external symbol, we want
6948 lui $at,<sym> (BFD_RELOC_MIPS_GOT_HI16)
6950 lw $at,<sym>($at) (BFD_RELOC_MIPS_GOT_LO16)
6955 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6957 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
6958 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
6959 If there is a base register we add it to $at before the
6960 lwc1 instructions. If there is a constant we include it
6961 in the lwc1 instructions. */
6963 expr1
.X_add_number
= offset_expr
.X_add_number
;
6964 offset_expr
.X_add_number
= 0;
6965 if (expr1
.X_add_number
< -0x8000
6966 || expr1
.X_add_number
>= 0x8000 - 4)
6967 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6968 gpdelay
= reg_needs_delay (mips_gp_register
);
6969 relax_start (offset_expr
.X_add_symbol
);
6970 macro_build (&offset_expr
, "lui", "t,u",
6971 AT
, BFD_RELOC_MIPS_GOT_HI16
);
6972 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t",
6973 AT
, AT
, mips_gp_register
);
6974 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)",
6975 AT
, BFD_RELOC_MIPS_GOT_LO16
, AT
);
6978 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t", AT
, breg
, AT
);
6979 /* Itbl support may require additional care here. */
6980 macro_build (&expr1
, s
, fmt
, coproc
? treg
+ 1 : treg
,
6981 BFD_RELOC_LO16
, AT
);
6982 expr1
.X_add_number
+= 4;
6984 /* Set mips_optimize to 2 to avoid inserting an undesired
6986 hold_mips_optimize
= mips_optimize
;
6988 /* Itbl support may require additional care here. */
6989 macro_build (&expr1
, s
, fmt
, coproc
? treg
: treg
+ 1,
6990 BFD_RELOC_LO16
, AT
);
6991 mips_optimize
= hold_mips_optimize
;
6992 expr1
.X_add_number
-= 4;
6995 offset_expr
.X_add_number
= expr1
.X_add_number
;
6997 macro_build (NULL
, "nop", "");
6998 macro_build (&offset_expr
, ADDRESS_LOAD_INSN
, "t,o(b)", AT
,
6999 BFD_RELOC_MIPS_GOT16
, mips_gp_register
);
7002 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t", AT
, breg
, AT
);
7003 /* Itbl support may require additional care here. */
7004 macro_build (&offset_expr
, s
, fmt
, coproc
? treg
+ 1 : treg
,
7005 BFD_RELOC_LO16
, AT
);
7006 offset_expr
.X_add_number
+= 4;
7008 /* Set mips_optimize to 2 to avoid inserting an undesired
7010 hold_mips_optimize
= mips_optimize
;
7012 /* Itbl support may require additional care here. */
7013 macro_build (&offset_expr
, s
, fmt
, coproc
? treg
: treg
+ 1,
7014 BFD_RELOC_LO16
, AT
);
7015 mips_optimize
= hold_mips_optimize
;
7029 assert (HAVE_32BIT_ADDRESSES
);
7030 macro_build (&offset_expr
, s
, "t,o(b)", treg
, BFD_RELOC_LO16
, breg
);
7031 offset_expr
.X_add_number
+= 4;
7032 macro_build (&offset_expr
, s
, "t,o(b)", treg
+ 1, BFD_RELOC_LO16
, breg
);
7035 /* New code added to support COPZ instructions.
7036 This code builds table entries out of the macros in mip_opcodes.
7037 R4000 uses interlocks to handle coproc delays.
7038 Other chips (like the R3000) require nops to be inserted for delays.
7040 FIXME: Currently, we require that the user handle delays.
7041 In order to fill delay slots for non-interlocked chips,
7042 we must have a way to specify delays based on the coprocessor.
7043 Eg. 4 cycles if load coproc reg from memory, 1 if in cache, etc.
7044 What are the side-effects of the cop instruction?
7045 What cache support might we have and what are its effects?
7046 Both coprocessor & memory require delays. how long???
7047 What registers are read/set/modified?
7049 If an itbl is provided to interpret cop instructions,
7050 this knowledge can be encoded in the itbl spec. */
7064 /* For now we just do C (same as Cz). The parameter will be
7065 stored in insn_opcode by mips_ip. */
7066 macro_build (NULL
, s
, "C", ip
->insn_opcode
);
7070 move_register (dreg
, sreg
);
7073 #ifdef LOSING_COMPILER
7075 /* Try and see if this is a new itbl instruction.
7076 This code builds table entries out of the macros in mip_opcodes.
7077 FIXME: For now we just assemble the expression and pass it's
7078 value along as a 32-bit immediate.
7079 We may want to have the assembler assemble this value,
7080 so that we gain the assembler's knowledge of delay slots,
7082 Would it be more efficient to use mask (id) here? */
7083 if (itbl_have_entries
7084 && (immed_expr
= itbl_assemble (ip
->insn_mo
->name
, "")))
7086 s
= ip
->insn_mo
->name
;
7088 coproc
= ITBL_DECODE_PNUM (immed_expr
);;
7089 macro_build (&immed_expr
, s
, "C");
7095 if (mips_opts
.noat
&& used_at
)
7096 as_bad (_("Macro used $at after \".set noat\""));
7100 macro2 (struct mips_cl_insn
*ip
)
7102 int treg
, sreg
, dreg
, breg
;
7117 bfd_reloc_code_real_type r
;
7119 treg
= (ip
->insn_opcode
>> 16) & 0x1f;
7120 dreg
= (ip
->insn_opcode
>> 11) & 0x1f;
7121 sreg
= breg
= (ip
->insn_opcode
>> 21) & 0x1f;
7122 mask
= ip
->insn_mo
->mask
;
7124 expr1
.X_op
= O_constant
;
7125 expr1
.X_op_symbol
= NULL
;
7126 expr1
.X_add_symbol
= NULL
;
7127 expr1
.X_add_number
= 1;
7131 #endif /* LOSING_COMPILER */
7136 macro_build (NULL
, dbl
? "dmultu" : "multu", "s,t", sreg
, treg
);
7137 macro_build (NULL
, "mflo", "d", dreg
);
7143 /* The MIPS assembler some times generates shifts and adds. I'm
7144 not trying to be that fancy. GCC should do this for us
7147 load_register (AT
, &imm_expr
, dbl
);
7148 macro_build (NULL
, dbl
? "dmult" : "mult", "s,t", sreg
, AT
);
7149 macro_build (NULL
, "mflo", "d", dreg
);
7165 load_register (AT
, &imm_expr
, dbl
);
7166 macro_build (NULL
, dbl
? "dmult" : "mult", "s,t", sreg
, imm
? AT
: treg
);
7167 macro_build (NULL
, "mflo", "d", dreg
);
7168 macro_build (NULL
, dbl
? "dsra32" : "sra", "d,w,<", dreg
, dreg
, RA
);
7169 macro_build (NULL
, "mfhi", "d", AT
);
7171 macro_build (NULL
, "tne", "s,t,q", dreg
, AT
, 6);
7174 expr1
.X_add_number
= 8;
7175 macro_build (&expr1
, "beq", "s,t,p", dreg
, AT
);
7176 macro_build (NULL
, "nop", "", 0);
7177 macro_build (NULL
, "break", "c", 6);
7180 macro_build (NULL
, "mflo", "d", dreg
);
7196 load_register (AT
, &imm_expr
, dbl
);
7197 macro_build (NULL
, dbl
? "dmultu" : "multu", "s,t",
7198 sreg
, imm
? AT
: treg
);
7199 macro_build (NULL
, "mfhi", "d", AT
);
7200 macro_build (NULL
, "mflo", "d", dreg
);
7202 macro_build (NULL
, "tne", "s,t,q", AT
, 0, 6);
7205 expr1
.X_add_number
= 8;
7206 macro_build (&expr1
, "beq", "s,t,p", AT
, 0);
7207 macro_build (NULL
, "nop", "", 0);
7208 macro_build (NULL
, "break", "c", 6);
7214 if (ISA_HAS_DROR (mips_opts
.isa
) || CPU_HAS_DROR (mips_opts
.arch
))
7225 macro_build (NULL
, "dnegu", "d,w", tempreg
, treg
);
7226 macro_build (NULL
, "drorv", "d,t,s", dreg
, sreg
, tempreg
);
7230 macro_build (NULL
, "dsubu", "d,v,t", AT
, 0, treg
);
7231 macro_build (NULL
, "dsrlv", "d,t,s", AT
, sreg
, AT
);
7232 macro_build (NULL
, "dsllv", "d,t,s", dreg
, sreg
, treg
);
7233 macro_build (NULL
, "or", "d,v,t", dreg
, dreg
, AT
);
7237 if (ISA_HAS_ROR (mips_opts
.isa
) || CPU_HAS_ROR (mips_opts
.arch
))
7248 macro_build (NULL
, "negu", "d,w", tempreg
, treg
);
7249 macro_build (NULL
, "rorv", "d,t,s", dreg
, sreg
, tempreg
);
7253 macro_build (NULL
, "subu", "d,v,t", AT
, 0, treg
);
7254 macro_build (NULL
, "srlv", "d,t,s", AT
, sreg
, AT
);
7255 macro_build (NULL
, "sllv", "d,t,s", dreg
, sreg
, treg
);
7256 macro_build (NULL
, "or", "d,v,t", dreg
, dreg
, AT
);
7264 if (imm_expr
.X_op
!= O_constant
)
7265 as_bad (_("Improper rotate count"));
7266 rot
= imm_expr
.X_add_number
& 0x3f;
7267 if (ISA_HAS_DROR (mips_opts
.isa
) || CPU_HAS_DROR (mips_opts
.arch
))
7269 rot
= (64 - rot
) & 0x3f;
7271 macro_build (NULL
, "dror32", "d,w,<", dreg
, sreg
, rot
- 32);
7273 macro_build (NULL
, "dror", "d,w,<", dreg
, sreg
, rot
);
7278 macro_build (NULL
, "dsrl", "d,w,<", dreg
, sreg
, 0);
7281 l
= (rot
< 0x20) ? "dsll" : "dsll32";
7282 r
= ((0x40 - rot
) < 0x20) ? "dsrl" : "dsrl32";
7285 macro_build (NULL
, l
, "d,w,<", AT
, sreg
, rot
);
7286 macro_build (NULL
, r
, "d,w,<", dreg
, sreg
, (0x20 - rot
) & 0x1f);
7287 macro_build (NULL
, "or", "d,v,t", dreg
, dreg
, AT
);
7295 if (imm_expr
.X_op
!= O_constant
)
7296 as_bad (_("Improper rotate count"));
7297 rot
= imm_expr
.X_add_number
& 0x1f;
7298 if (ISA_HAS_ROR (mips_opts
.isa
) || CPU_HAS_ROR (mips_opts
.arch
))
7300 macro_build (NULL
, "ror", "d,w,<", dreg
, sreg
, (32 - rot
) & 0x1f);
7305 macro_build (NULL
, "srl", "d,w,<", dreg
, sreg
, 0);
7309 macro_build (NULL
, "sll", "d,w,<", AT
, sreg
, rot
);
7310 macro_build (NULL
, "srl", "d,w,<", dreg
, sreg
, (0x20 - rot
) & 0x1f);
7311 macro_build (NULL
, "or", "d,v,t", dreg
, dreg
, AT
);
7316 if (ISA_HAS_DROR (mips_opts
.isa
) || CPU_HAS_DROR (mips_opts
.arch
))
7318 macro_build (NULL
, "drorv", "d,t,s", dreg
, sreg
, treg
);
7322 macro_build (NULL
, "dsubu", "d,v,t", AT
, 0, treg
);
7323 macro_build (NULL
, "dsllv", "d,t,s", AT
, sreg
, AT
);
7324 macro_build (NULL
, "dsrlv", "d,t,s", dreg
, sreg
, treg
);
7325 macro_build (NULL
, "or", "d,v,t", dreg
, dreg
, AT
);
7329 if (ISA_HAS_ROR (mips_opts
.isa
) || CPU_HAS_ROR (mips_opts
.arch
))
7331 macro_build (NULL
, "rorv", "d,t,s", dreg
, sreg
, treg
);
7335 macro_build (NULL
, "subu", "d,v,t", AT
, 0, treg
);
7336 macro_build (NULL
, "sllv", "d,t,s", AT
, sreg
, AT
);
7337 macro_build (NULL
, "srlv", "d,t,s", dreg
, sreg
, treg
);
7338 macro_build (NULL
, "or", "d,v,t", dreg
, dreg
, AT
);
7346 if (imm_expr
.X_op
!= O_constant
)
7347 as_bad (_("Improper rotate count"));
7348 rot
= imm_expr
.X_add_number
& 0x3f;
7349 if (ISA_HAS_DROR (mips_opts
.isa
) || CPU_HAS_DROR (mips_opts
.arch
))
7352 macro_build (NULL
, "dror32", "d,w,<", dreg
, sreg
, rot
- 32);
7354 macro_build (NULL
, "dror", "d,w,<", dreg
, sreg
, rot
);
7359 macro_build (NULL
, "dsrl", "d,w,<", dreg
, sreg
, 0);
7362 r
= (rot
< 0x20) ? "dsrl" : "dsrl32";
7363 l
= ((0x40 - rot
) < 0x20) ? "dsll" : "dsll32";
7366 macro_build (NULL
, r
, "d,w,<", AT
, sreg
, rot
);
7367 macro_build (NULL
, l
, "d,w,<", dreg
, sreg
, (0x20 - rot
) & 0x1f);
7368 macro_build (NULL
, "or", "d,v,t", dreg
, dreg
, AT
);
7376 if (imm_expr
.X_op
!= O_constant
)
7377 as_bad (_("Improper rotate count"));
7378 rot
= imm_expr
.X_add_number
& 0x1f;
7379 if (ISA_HAS_ROR (mips_opts
.isa
) || CPU_HAS_ROR (mips_opts
.arch
))
7381 macro_build (NULL
, "ror", "d,w,<", dreg
, sreg
, rot
);
7386 macro_build (NULL
, "srl", "d,w,<", dreg
, sreg
, 0);
7390 macro_build (NULL
, "srl", "d,w,<", AT
, sreg
, rot
);
7391 macro_build (NULL
, "sll", "d,w,<", dreg
, sreg
, (0x20 - rot
) & 0x1f);
7392 macro_build (NULL
, "or", "d,v,t", dreg
, dreg
, AT
);
7397 if (mips_opts
.arch
== CPU_R4650
)
7399 as_bad (_("opcode not supported on this processor"));
7402 assert (mips_opts
.isa
== ISA_MIPS1
);
7403 /* Even on a big endian machine $fn comes before $fn+1. We have
7404 to adjust when storing to memory. */
7405 macro_build (&offset_expr
, "swc1", "T,o(b)",
7406 target_big_endian
? treg
+ 1 : treg
, BFD_RELOC_LO16
, breg
);
7407 offset_expr
.X_add_number
+= 4;
7408 macro_build (&offset_expr
, "swc1", "T,o(b)",
7409 target_big_endian
? treg
: treg
+ 1, BFD_RELOC_LO16
, breg
);
7414 macro_build (&expr1
, "sltiu", "t,r,j", dreg
, treg
, BFD_RELOC_LO16
);
7416 macro_build (&expr1
, "sltiu", "t,r,j", dreg
, sreg
, BFD_RELOC_LO16
);
7419 macro_build (NULL
, "xor", "d,v,t", dreg
, sreg
, treg
);
7420 macro_build (&expr1
, "sltiu", "t,r,j", dreg
, dreg
, BFD_RELOC_LO16
);
7425 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 0)
7427 macro_build (&expr1
, "sltiu", "t,r,j", dreg
, sreg
, BFD_RELOC_LO16
);
7432 as_warn (_("Instruction %s: result is always false"),
7434 move_register (dreg
, 0);
7437 if (imm_expr
.X_op
== O_constant
7438 && imm_expr
.X_add_number
>= 0
7439 && imm_expr
.X_add_number
< 0x10000)
7441 macro_build (&imm_expr
, "xori", "t,r,i", dreg
, sreg
, BFD_RELOC_LO16
);
7443 else if (imm_expr
.X_op
== O_constant
7444 && imm_expr
.X_add_number
> -0x8000
7445 && imm_expr
.X_add_number
< 0)
7447 imm_expr
.X_add_number
= -imm_expr
.X_add_number
;
7448 macro_build (&imm_expr
, HAVE_32BIT_GPRS
? "addiu" : "daddiu",
7449 "t,r,j", dreg
, sreg
, BFD_RELOC_LO16
);
7453 load_register (AT
, &imm_expr
, HAVE_64BIT_GPRS
);
7454 macro_build (NULL
, "xor", "d,v,t", dreg
, sreg
, AT
);
7457 macro_build (&expr1
, "sltiu", "t,r,j", dreg
, dreg
, BFD_RELOC_LO16
);
7460 case M_SGE
: /* sreg >= treg <==> not (sreg < treg) */
7466 macro_build (NULL
, s
, "d,v,t", dreg
, sreg
, treg
);
7467 macro_build (&expr1
, "xori", "t,r,i", dreg
, dreg
, BFD_RELOC_LO16
);
7470 case M_SGE_I
: /* sreg >= I <==> not (sreg < I) */
7472 if (imm_expr
.X_op
== O_constant
7473 && imm_expr
.X_add_number
>= -0x8000
7474 && imm_expr
.X_add_number
< 0x8000)
7476 macro_build (&imm_expr
, mask
== M_SGE_I
? "slti" : "sltiu", "t,r,j",
7477 dreg
, sreg
, BFD_RELOC_LO16
);
7481 load_register (AT
, &imm_expr
, HAVE_64BIT_GPRS
);
7482 macro_build (NULL
, mask
== M_SGE_I
? "slt" : "sltu", "d,v,t",
7486 macro_build (&expr1
, "xori", "t,r,i", dreg
, dreg
, BFD_RELOC_LO16
);
7489 case M_SGT
: /* sreg > treg <==> treg < sreg */
7495 macro_build (NULL
, s
, "d,v,t", dreg
, treg
, sreg
);
7498 case M_SGT_I
: /* sreg > I <==> I < sreg */
7505 load_register (AT
, &imm_expr
, HAVE_64BIT_GPRS
);
7506 macro_build (NULL
, s
, "d,v,t", dreg
, AT
, sreg
);
7509 case M_SLE
: /* sreg <= treg <==> treg >= sreg <==> not (treg < sreg) */
7515 macro_build (NULL
, s
, "d,v,t", dreg
, treg
, sreg
);
7516 macro_build (&expr1
, "xori", "t,r,i", dreg
, dreg
, BFD_RELOC_LO16
);
7519 case M_SLE_I
: /* sreg <= I <==> I >= sreg <==> not (I < sreg) */
7526 load_register (AT
, &imm_expr
, HAVE_64BIT_GPRS
);
7527 macro_build (NULL
, s
, "d,v,t", dreg
, AT
, sreg
);
7528 macro_build (&expr1
, "xori", "t,r,i", dreg
, dreg
, BFD_RELOC_LO16
);
7532 if (imm_expr
.X_op
== O_constant
7533 && imm_expr
.X_add_number
>= -0x8000
7534 && imm_expr
.X_add_number
< 0x8000)
7536 macro_build (&imm_expr
, "slti", "t,r,j", dreg
, sreg
, BFD_RELOC_LO16
);
7540 load_register (AT
, &imm_expr
, HAVE_64BIT_GPRS
);
7541 macro_build (NULL
, "slt", "d,v,t", dreg
, sreg
, AT
);
7545 if (imm_expr
.X_op
== O_constant
7546 && imm_expr
.X_add_number
>= -0x8000
7547 && imm_expr
.X_add_number
< 0x8000)
7549 macro_build (&imm_expr
, "sltiu", "t,r,j", dreg
, sreg
,
7554 load_register (AT
, &imm_expr
, HAVE_64BIT_GPRS
);
7555 macro_build (NULL
, "sltu", "d,v,t", dreg
, sreg
, AT
);
7560 macro_build (NULL
, "sltu", "d,v,t", dreg
, 0, treg
);
7562 macro_build (NULL
, "sltu", "d,v,t", dreg
, 0, sreg
);
7565 macro_build (NULL
, "xor", "d,v,t", dreg
, sreg
, treg
);
7566 macro_build (NULL
, "sltu", "d,v,t", dreg
, 0, dreg
);
7571 if (imm_expr
.X_op
== O_constant
&& imm_expr
.X_add_number
== 0)
7573 macro_build (NULL
, "sltu", "d,v,t", dreg
, 0, sreg
);
7578 as_warn (_("Instruction %s: result is always true"),
7580 macro_build (&expr1
, HAVE_32BIT_GPRS
? "addiu" : "daddiu", "t,r,j",
7581 dreg
, 0, BFD_RELOC_LO16
);
7584 if (imm_expr
.X_op
== O_constant
7585 && imm_expr
.X_add_number
>= 0
7586 && imm_expr
.X_add_number
< 0x10000)
7588 macro_build (&imm_expr
, "xori", "t,r,i", dreg
, sreg
, BFD_RELOC_LO16
);
7590 else if (imm_expr
.X_op
== O_constant
7591 && imm_expr
.X_add_number
> -0x8000
7592 && imm_expr
.X_add_number
< 0)
7594 imm_expr
.X_add_number
= -imm_expr
.X_add_number
;
7595 macro_build (&imm_expr
, HAVE_32BIT_GPRS
? "addiu" : "daddiu",
7596 "t,r,j", dreg
, sreg
, BFD_RELOC_LO16
);
7600 load_register (AT
, &imm_expr
, HAVE_64BIT_GPRS
);
7601 macro_build (NULL
, "xor", "d,v,t", dreg
, sreg
, AT
);
7604 macro_build (NULL
, "sltu", "d,v,t", dreg
, 0, dreg
);
7610 if (imm_expr
.X_op
== O_constant
7611 && imm_expr
.X_add_number
> -0x8000
7612 && imm_expr
.X_add_number
<= 0x8000)
7614 imm_expr
.X_add_number
= -imm_expr
.X_add_number
;
7615 macro_build (&imm_expr
, dbl
? "daddi" : "addi", "t,r,j",
7616 dreg
, sreg
, BFD_RELOC_LO16
);
7620 load_register (AT
, &imm_expr
, dbl
);
7621 macro_build (NULL
, dbl
? "dsub" : "sub", "d,v,t", dreg
, sreg
, AT
);
7627 if (imm_expr
.X_op
== O_constant
7628 && imm_expr
.X_add_number
> -0x8000
7629 && imm_expr
.X_add_number
<= 0x8000)
7631 imm_expr
.X_add_number
= -imm_expr
.X_add_number
;
7632 macro_build (&imm_expr
, dbl
? "daddiu" : "addiu", "t,r,j",
7633 dreg
, sreg
, BFD_RELOC_LO16
);
7637 load_register (AT
, &imm_expr
, dbl
);
7638 macro_build (NULL
, dbl
? "dsubu" : "subu", "d,v,t", dreg
, sreg
, AT
);
7660 load_register (AT
, &imm_expr
, HAVE_64BIT_GPRS
);
7661 macro_build (NULL
, s
, "s,t", sreg
, AT
);
7666 assert (mips_opts
.isa
== ISA_MIPS1
);
7668 sreg
= (ip
->insn_opcode
>> 11) & 0x1f; /* floating reg */
7669 dreg
= (ip
->insn_opcode
>> 06) & 0x1f; /* floating reg */
7672 * Is the double cfc1 instruction a bug in the mips assembler;
7673 * or is there a reason for it?
7676 macro_build (NULL
, "cfc1", "t,G", treg
, RA
);
7677 macro_build (NULL
, "cfc1", "t,G", treg
, RA
);
7678 macro_build (NULL
, "nop", "");
7679 expr1
.X_add_number
= 3;
7680 macro_build (&expr1
, "ori", "t,r,i", AT
, treg
, BFD_RELOC_LO16
);
7681 expr1
.X_add_number
= 2;
7682 macro_build (&expr1
, "xori", "t,r,i", AT
, AT
, BFD_RELOC_LO16
);
7683 macro_build (NULL
, "ctc1", "t,G", AT
, RA
);
7684 macro_build (NULL
, "nop", "");
7685 macro_build (NULL
, mask
== M_TRUNCWD
? "cvt.w.d" : "cvt.w.s", "D,S",
7687 macro_build (NULL
, "ctc1", "t,G", treg
, RA
);
7688 macro_build (NULL
, "nop", "");
7699 if (offset_expr
.X_add_number
>= 0x7fff)
7700 as_bad (_("operand overflow"));
7701 if (! target_big_endian
)
7702 ++offset_expr
.X_add_number
;
7703 macro_build (&offset_expr
, s
, "t,o(b)", AT
, BFD_RELOC_LO16
, breg
);
7704 if (! target_big_endian
)
7705 --offset_expr
.X_add_number
;
7707 ++offset_expr
.X_add_number
;
7708 macro_build (&offset_expr
, "lbu", "t,o(b)", treg
, BFD_RELOC_LO16
, breg
);
7709 macro_build (NULL
, "sll", "d,w,<", AT
, AT
, 8);
7710 macro_build (NULL
, "or", "d,v,t", treg
, treg
, AT
);
7723 if (offset_expr
.X_add_number
>= 0x8000 - off
)
7724 as_bad (_("operand overflow"));
7732 if (! target_big_endian
)
7733 offset_expr
.X_add_number
+= off
;
7734 macro_build (&offset_expr
, s
, "t,o(b)", tempreg
, BFD_RELOC_LO16
, breg
);
7735 if (! target_big_endian
)
7736 offset_expr
.X_add_number
-= off
;
7738 offset_expr
.X_add_number
+= off
;
7739 macro_build (&offset_expr
, s2
, "t,o(b)", tempreg
, BFD_RELOC_LO16
, breg
);
7741 /* If necessary, move the result in tempreg the final destination. */
7742 if (treg
== tempreg
)
7744 /* Protect second load's delay slot. */
7746 move_register (treg
, tempreg
);
7760 load_address (AT
, &offset_expr
, &used_at
);
7762 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t", AT
, AT
, breg
);
7763 if (! target_big_endian
)
7764 expr1
.X_add_number
= off
;
7766 expr1
.X_add_number
= 0;
7767 macro_build (&expr1
, s
, "t,o(b)", treg
, BFD_RELOC_LO16
, AT
);
7768 if (! target_big_endian
)
7769 expr1
.X_add_number
= 0;
7771 expr1
.X_add_number
= off
;
7772 macro_build (&expr1
, s2
, "t,o(b)", treg
, BFD_RELOC_LO16
, AT
);
7778 load_address (AT
, &offset_expr
, &used_at
);
7780 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t", AT
, AT
, breg
);
7781 if (target_big_endian
)
7782 expr1
.X_add_number
= 0;
7783 macro_build (&expr1
, mask
== M_ULH_A
? "lb" : "lbu", "t,o(b)",
7784 treg
, BFD_RELOC_LO16
, AT
);
7785 if (target_big_endian
)
7786 expr1
.X_add_number
= 1;
7788 expr1
.X_add_number
= 0;
7789 macro_build (&expr1
, "lbu", "t,o(b)", AT
, BFD_RELOC_LO16
, AT
);
7790 macro_build (NULL
, "sll", "d,w,<", treg
, treg
, 8);
7791 macro_build (NULL
, "or", "d,v,t", treg
, treg
, AT
);
7796 if (offset_expr
.X_add_number
>= 0x7fff)
7797 as_bad (_("operand overflow"));
7798 if (target_big_endian
)
7799 ++offset_expr
.X_add_number
;
7800 macro_build (&offset_expr
, "sb", "t,o(b)", treg
, BFD_RELOC_LO16
, breg
);
7801 macro_build (NULL
, "srl", "d,w,<", AT
, treg
, 8);
7802 if (target_big_endian
)
7803 --offset_expr
.X_add_number
;
7805 ++offset_expr
.X_add_number
;
7806 macro_build (&offset_expr
, "sb", "t,o(b)", AT
, BFD_RELOC_LO16
, breg
);
7819 if (offset_expr
.X_add_number
>= 0x8000 - off
)
7820 as_bad (_("operand overflow"));
7821 if (! target_big_endian
)
7822 offset_expr
.X_add_number
+= off
;
7823 macro_build (&offset_expr
, s
, "t,o(b)", treg
, BFD_RELOC_LO16
, breg
);
7824 if (! target_big_endian
)
7825 offset_expr
.X_add_number
-= off
;
7827 offset_expr
.X_add_number
+= off
;
7828 macro_build (&offset_expr
, s2
, "t,o(b)", treg
, BFD_RELOC_LO16
, breg
);
7842 load_address (AT
, &offset_expr
, &used_at
);
7844 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t", AT
, AT
, breg
);
7845 if (! target_big_endian
)
7846 expr1
.X_add_number
= off
;
7848 expr1
.X_add_number
= 0;
7849 macro_build (&expr1
, s
, "t,o(b)", treg
, BFD_RELOC_LO16
, AT
);
7850 if (! target_big_endian
)
7851 expr1
.X_add_number
= 0;
7853 expr1
.X_add_number
= off
;
7854 macro_build (&expr1
, s2
, "t,o(b)", treg
, BFD_RELOC_LO16
, AT
);
7859 load_address (AT
, &offset_expr
, &used_at
);
7861 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t", AT
, AT
, breg
);
7862 if (! target_big_endian
)
7863 expr1
.X_add_number
= 0;
7864 macro_build (&expr1
, "sb", "t,o(b)", treg
, BFD_RELOC_LO16
, AT
);
7865 macro_build (NULL
, "srl", "d,w,<", treg
, treg
, 8);
7866 if (! target_big_endian
)
7867 expr1
.X_add_number
= 1;
7869 expr1
.X_add_number
= 0;
7870 macro_build (&expr1
, "sb", "t,o(b)", treg
, BFD_RELOC_LO16
, AT
);
7871 if (! target_big_endian
)
7872 expr1
.X_add_number
= 0;
7874 expr1
.X_add_number
= 1;
7875 macro_build (&expr1
, "lbu", "t,o(b)", AT
, BFD_RELOC_LO16
, AT
);
7876 macro_build (NULL
, "sll", "d,w,<", treg
, treg
, 8);
7877 macro_build (NULL
, "or", "d,v,t", treg
, treg
, AT
);
7881 /* FIXME: Check if this is one of the itbl macros, since they
7882 are added dynamically. */
7883 as_bad (_("Macro %s not implemented yet"), ip
->insn_mo
->name
);
7886 if (mips_opts
.noat
&& used_at
)
7887 as_bad (_("Macro used $at after \".set noat\""));
7890 /* Implement macros in mips16 mode. */
7893 mips16_macro (struct mips_cl_insn
*ip
)
7896 int xreg
, yreg
, zreg
, tmp
;
7899 const char *s
, *s2
, *s3
;
7901 mask
= ip
->insn_mo
->mask
;
7903 xreg
= MIPS16_EXTRACT_OPERAND (RX
, *ip
);
7904 yreg
= MIPS16_EXTRACT_OPERAND (RY
, *ip
);
7905 zreg
= MIPS16_EXTRACT_OPERAND (RZ
, *ip
);
7907 expr1
.X_op
= O_constant
;
7908 expr1
.X_op_symbol
= NULL
;
7909 expr1
.X_add_symbol
= NULL
;
7910 expr1
.X_add_number
= 1;
7930 macro_build (NULL
, dbl
? "ddiv" : "div", "0,x,y", xreg
, yreg
);
7931 expr1
.X_add_number
= 2;
7932 macro_build (&expr1
, "bnez", "x,p", yreg
);
7933 macro_build (NULL
, "break", "6", 7);
7935 /* FIXME: The normal code checks for of -1 / -0x80000000 here,
7936 since that causes an overflow. We should do that as well,
7937 but I don't see how to do the comparisons without a temporary
7940 macro_build (NULL
, s
, "x", zreg
);
7960 macro_build (NULL
, s
, "0,x,y", xreg
, yreg
);
7961 expr1
.X_add_number
= 2;
7962 macro_build (&expr1
, "bnez", "x,p", yreg
);
7963 macro_build (NULL
, "break", "6", 7);
7965 macro_build (NULL
, s2
, "x", zreg
);
7971 macro_build (NULL
, dbl
? "dmultu" : "multu", "x,y", xreg
, yreg
);
7972 macro_build (NULL
, "mflo", "x", zreg
);
7980 if (imm_expr
.X_op
!= O_constant
)
7981 as_bad (_("Unsupported large constant"));
7982 imm_expr
.X_add_number
= -imm_expr
.X_add_number
;
7983 macro_build (&imm_expr
, dbl
? "daddiu" : "addiu", "y,x,4", yreg
, xreg
);
7987 if (imm_expr
.X_op
!= O_constant
)
7988 as_bad (_("Unsupported large constant"));
7989 imm_expr
.X_add_number
= -imm_expr
.X_add_number
;
7990 macro_build (&imm_expr
, "addiu", "x,k", xreg
);
7994 if (imm_expr
.X_op
!= O_constant
)
7995 as_bad (_("Unsupported large constant"));
7996 imm_expr
.X_add_number
= -imm_expr
.X_add_number
;
7997 macro_build (&imm_expr
, "daddiu", "y,j", yreg
);
8019 goto do_reverse_branch
;
8023 goto do_reverse_branch
;
8035 goto do_reverse_branch
;
8046 macro_build (NULL
, s
, "x,y", xreg
, yreg
);
8047 macro_build (&offset_expr
, s2
, "p");
8074 goto do_addone_branch_i
;
8079 goto do_addone_branch_i
;
8094 goto do_addone_branch_i
;
8101 if (imm_expr
.X_op
!= O_constant
)
8102 as_bad (_("Unsupported large constant"));
8103 ++imm_expr
.X_add_number
;
8106 macro_build (&imm_expr
, s
, s3
, xreg
);
8107 macro_build (&offset_expr
, s2
, "p");
8111 expr1
.X_add_number
= 0;
8112 macro_build (&expr1
, "slti", "x,8", yreg
);
8114 move_register (xreg
, yreg
);
8115 expr1
.X_add_number
= 2;
8116 macro_build (&expr1
, "bteqz", "p");
8117 macro_build (NULL
, "neg", "x,w", xreg
, xreg
);
8121 /* For consistency checking, verify that all bits are specified either
8122 by the match/mask part of the instruction definition, or by the
8125 validate_mips_insn (const struct mips_opcode
*opc
)
8127 const char *p
= opc
->args
;
8129 unsigned long used_bits
= opc
->mask
;
8131 if ((used_bits
& opc
->match
) != opc
->match
)
8133 as_bad (_("internal: bad mips opcode (mask error): %s %s"),
8134 opc
->name
, opc
->args
);
8137 #define USE_BITS(mask,shift) (used_bits |= ((mask) << (shift)))
8147 case '1': USE_BITS (OP_MASK_UDI1
, OP_SH_UDI1
); break;
8148 case '2': USE_BITS (OP_MASK_UDI2
, OP_SH_UDI2
); break;
8149 case '3': USE_BITS (OP_MASK_UDI3
, OP_SH_UDI3
); break;
8150 case '4': USE_BITS (OP_MASK_UDI4
, OP_SH_UDI4
); break;
8151 case 'A': USE_BITS (OP_MASK_SHAMT
, OP_SH_SHAMT
); break;
8152 case 'B': USE_BITS (OP_MASK_INSMSB
, OP_SH_INSMSB
); break;
8153 case 'C': USE_BITS (OP_MASK_EXTMSBD
, OP_SH_EXTMSBD
); break;
8154 case 'D': USE_BITS (OP_MASK_RD
, OP_SH_RD
);
8155 USE_BITS (OP_MASK_SEL
, OP_SH_SEL
); break;
8156 case 'E': USE_BITS (OP_MASK_SHAMT
, OP_SH_SHAMT
); break;
8157 case 'F': USE_BITS (OP_MASK_INSMSB
, OP_SH_INSMSB
); break;
8158 case 'G': USE_BITS (OP_MASK_EXTMSBD
, OP_SH_EXTMSBD
); break;
8159 case 'H': USE_BITS (OP_MASK_EXTMSBD
, OP_SH_EXTMSBD
); break;
8161 case 't': USE_BITS (OP_MASK_RT
, OP_SH_RT
); break;
8162 case 'T': USE_BITS (OP_MASK_RT
, OP_SH_RT
);
8163 USE_BITS (OP_MASK_SEL
, OP_SH_SEL
); break;
8165 as_bad (_("internal: bad mips opcode (unknown extension operand type `+%c'): %s %s"),
8166 c
, opc
->name
, opc
->args
);
8170 case '<': USE_BITS (OP_MASK_SHAMT
, OP_SH_SHAMT
); break;
8171 case '>': USE_BITS (OP_MASK_SHAMT
, OP_SH_SHAMT
); break;
8173 case 'B': USE_BITS (OP_MASK_CODE20
, OP_SH_CODE20
); break;
8174 case 'C': USE_BITS (OP_MASK_COPZ
, OP_SH_COPZ
); break;
8175 case 'D': USE_BITS (OP_MASK_FD
, OP_SH_FD
); break;
8176 case 'E': USE_BITS (OP_MASK_RT
, OP_SH_RT
); break;
8178 case 'G': USE_BITS (OP_MASK_RD
, OP_SH_RD
); break;
8179 case 'H': USE_BITS (OP_MASK_SEL
, OP_SH_SEL
); break;
8181 case 'J': USE_BITS (OP_MASK_CODE19
, OP_SH_CODE19
); break;
8182 case 'K': USE_BITS (OP_MASK_RD
, OP_SH_RD
); break;
8184 case 'M': USE_BITS (OP_MASK_CCC
, OP_SH_CCC
); break;
8185 case 'N': USE_BITS (OP_MASK_BCC
, OP_SH_BCC
); break;
8186 case 'O': USE_BITS (OP_MASK_ALN
, OP_SH_ALN
); break;
8187 case 'Q': USE_BITS (OP_MASK_VSEL
, OP_SH_VSEL
);
8188 USE_BITS (OP_MASK_FT
, OP_SH_FT
); break;
8189 case 'R': USE_BITS (OP_MASK_FR
, OP_SH_FR
); break;
8190 case 'S': USE_BITS (OP_MASK_FS
, OP_SH_FS
); break;
8191 case 'T': USE_BITS (OP_MASK_FT
, OP_SH_FT
); break;
8192 case 'V': USE_BITS (OP_MASK_FS
, OP_SH_FS
); break;
8193 case 'W': USE_BITS (OP_MASK_FT
, OP_SH_FT
); break;
8194 case 'X': USE_BITS (OP_MASK_FD
, OP_SH_FD
); break;
8195 case 'Y': USE_BITS (OP_MASK_FS
, OP_SH_FS
); break;
8196 case 'Z': USE_BITS (OP_MASK_FT
, OP_SH_FT
); break;
8197 case 'a': USE_BITS (OP_MASK_TARGET
, OP_SH_TARGET
); break;
8198 case 'b': USE_BITS (OP_MASK_RS
, OP_SH_RS
); break;
8199 case 'c': USE_BITS (OP_MASK_CODE
, OP_SH_CODE
); break;
8200 case 'd': USE_BITS (OP_MASK_RD
, OP_SH_RD
); break;
8202 case 'h': USE_BITS (OP_MASK_PREFX
, OP_SH_PREFX
); break;
8203 case 'i': USE_BITS (OP_MASK_IMMEDIATE
, OP_SH_IMMEDIATE
); break;
8204 case 'j': USE_BITS (OP_MASK_DELTA
, OP_SH_DELTA
); break;
8205 case 'k': USE_BITS (OP_MASK_CACHE
, OP_SH_CACHE
); break;
8207 case 'o': USE_BITS (OP_MASK_DELTA
, OP_SH_DELTA
); break;
8208 case 'p': USE_BITS (OP_MASK_DELTA
, OP_SH_DELTA
); break;
8209 case 'q': USE_BITS (OP_MASK_CODE2
, OP_SH_CODE2
); break;
8210 case 'r': USE_BITS (OP_MASK_RS
, OP_SH_RS
); break;
8211 case 's': USE_BITS (OP_MASK_RS
, OP_SH_RS
); break;
8212 case 't': USE_BITS (OP_MASK_RT
, OP_SH_RT
); break;
8213 case 'u': USE_BITS (OP_MASK_IMMEDIATE
, OP_SH_IMMEDIATE
); break;
8214 case 'v': USE_BITS (OP_MASK_RS
, OP_SH_RS
); break;
8215 case 'w': USE_BITS (OP_MASK_RT
, OP_SH_RT
); break;
8218 case 'P': USE_BITS (OP_MASK_PERFREG
, OP_SH_PERFREG
); break;
8219 case 'U': USE_BITS (OP_MASK_RD
, OP_SH_RD
);
8220 USE_BITS (OP_MASK_RT
, OP_SH_RT
); break;
8221 case 'e': USE_BITS (OP_MASK_VECBYTE
, OP_SH_VECBYTE
); break;
8222 case '%': USE_BITS (OP_MASK_VECALIGN
, OP_SH_VECALIGN
); break;
8225 case '3': USE_BITS (OP_MASK_SA3
, OP_SH_SA3
); break;
8226 case '4': USE_BITS (OP_MASK_SA4
, OP_SH_SA4
); break;
8227 case '5': USE_BITS (OP_MASK_IMM8
, OP_SH_IMM8
); break;
8228 case '6': USE_BITS (OP_MASK_RS
, OP_SH_RS
); break;
8229 case '7': USE_BITS (OP_MASK_DSPACC
, OP_SH_DSPACC
); break;
8230 case '8': USE_BITS (OP_MASK_WRDSP
, OP_SH_WRDSP
); break;
8231 case '9': USE_BITS (OP_MASK_DSPACC_S
, OP_SH_DSPACC_S
);break;
8232 case '0': USE_BITS (OP_MASK_DSPSFT
, OP_SH_DSPSFT
); break;
8233 case '\'': USE_BITS (OP_MASK_RDDSP
, OP_SH_RDDSP
); break;
8234 case ':': USE_BITS (OP_MASK_DSPSFT_7
, OP_SH_DSPSFT_7
);break;
8235 case '@': USE_BITS (OP_MASK_IMM10
, OP_SH_IMM10
); break;
8236 case '!': USE_BITS (OP_MASK_MT_U
, OP_SH_MT_U
); break;
8237 case '$': USE_BITS (OP_MASK_MT_H
, OP_SH_MT_H
); break;
8238 case '*': USE_BITS (OP_MASK_MTACC_T
, OP_SH_MTACC_T
); break;
8239 case '&': USE_BITS (OP_MASK_MTACC_D
, OP_SH_MTACC_D
); break;
8240 case 'g': USE_BITS (OP_MASK_RD
, OP_SH_RD
); break;
8242 as_bad (_("internal: bad mips opcode (unknown operand type `%c'): %s %s"),
8243 c
, opc
->name
, opc
->args
);
8247 if (used_bits
!= 0xffffffff)
8249 as_bad (_("internal: bad mips opcode (bits 0x%lx undefined): %s %s"),
8250 ~used_bits
& 0xffffffff, opc
->name
, opc
->args
);
8256 /* UDI immediates. */
8264 static const struct mips_immed mips_immed
[] = {
8265 { '1', OP_SH_UDI1
, OP_MASK_UDI1
, 0},
8266 { '2', OP_SH_UDI2
, OP_MASK_UDI2
, 0},
8267 { '3', OP_SH_UDI3
, OP_MASK_UDI3
, 0},
8268 { '4', OP_SH_UDI4
, OP_MASK_UDI4
, 0},
8272 /* Check whether an odd floating-point register is allowed. */
8274 mips_oddfpreg_ok (const struct mips_opcode
*insn
, int argnum
)
8276 const char *s
= insn
->name
;
8278 if (insn
->pinfo
== INSN_MACRO
)
8279 /* Let a macro pass, we'll catch it later when it is expanded. */
8282 if (ISA_HAS_ODD_SINGLE_FPR (mips_opts
.isa
))
8284 /* Allow odd registers for single-precision ops. */
8285 switch (insn
->pinfo
& (FP_S
| FP_D
))
8289 return 1; /* both single precision - ok */
8291 return 0; /* both double precision - fail */
8296 /* Cvt.w.x and cvt.x.w allow an odd register for a 'w' or 's' operand. */
8297 s
= strchr (insn
->name
, '.');
8299 s
= s
!= NULL
? strchr (s
+ 1, '.') : NULL
;
8300 return (s
!= NULL
&& (s
[1] == 'w' || s
[1] == 's'));
8303 /* Single-precision coprocessor loads and moves are OK too. */
8304 if ((insn
->pinfo
& FP_S
)
8305 && (insn
->pinfo
& (INSN_COPROC_MEMORY_DELAY
| INSN_STORE_MEMORY
8306 | INSN_LOAD_COPROC_DELAY
| INSN_COPROC_MOVE_DELAY
)))
8312 /* This routine assembles an instruction into its binary format. As a
8313 side effect, it sets one of the global variables imm_reloc or
8314 offset_reloc to the type of relocation to do if one of the operands
8315 is an address expression. */
8318 mips_ip (char *str
, struct mips_cl_insn
*ip
)
8323 struct mips_opcode
*insn
;
8326 unsigned int lastregno
= 0;
8327 unsigned int lastpos
= 0;
8328 unsigned int limlo
, limhi
;
8331 offsetT min_range
, max_range
;
8337 /* If the instruction contains a '.', we first try to match an instruction
8338 including the '.'. Then we try again without the '.'. */
8340 for (s
= str
; *s
!= '\0' && !ISSPACE (*s
); ++s
)
8343 /* If we stopped on whitespace, then replace the whitespace with null for
8344 the call to hash_find. Save the character we replaced just in case we
8345 have to re-parse the instruction. */
8352 insn
= (struct mips_opcode
*) hash_find (op_hash
, str
);
8354 /* If we didn't find the instruction in the opcode table, try again, but
8355 this time with just the instruction up to, but not including the
8359 /* Restore the character we overwrite above (if any). */
8363 /* Scan up to the first '.' or whitespace. */
8365 *s
!= '\0' && *s
!= '.' && !ISSPACE (*s
);
8369 /* If we did not find a '.', then we can quit now. */
8372 insn_error
= "unrecognized opcode";
8376 /* Lookup the instruction in the hash table. */
8378 if ((insn
= (struct mips_opcode
*) hash_find (op_hash
, str
)) == NULL
)
8380 insn_error
= "unrecognized opcode";
8390 assert (strcmp (insn
->name
, str
) == 0);
8392 if (OPCODE_IS_MEMBER (insn
,
8394 /* We don't check for mips_opts.mips16 here since
8395 we want to allow jalx if -mips16 was specified
8396 on the command line. */
8397 | (file_ase_mips16
? INSN_MIPS16
: 0)
8398 | (mips_opts
.ase_mdmx
? INSN_MDMX
: 0)
8399 | (mips_opts
.ase_dsp
? INSN_DSP
: 0)
8400 | ((mips_opts
.ase_dsp
&& ISA_SUPPORTS_DSP64_ASE
)
8402 | (mips_opts
.ase_mt
? INSN_MT
: 0)
8403 | (mips_opts
.ase_mips3d
? INSN_MIPS3D
: 0)
8404 | (mips_opts
.ase_smartmips
? INSN_SMARTMIPS
: 0)),
8410 if (insn
->pinfo
!= INSN_MACRO
)
8412 if (mips_opts
.arch
== CPU_R4650
&& (insn
->pinfo
& FP_D
) != 0)
8418 if (insn
+ 1 < &mips_opcodes
[NUMOPCODES
]
8419 && strcmp (insn
->name
, insn
[1].name
) == 0)
8428 static char buf
[100];
8430 _("opcode not supported on this processor: %s (%s)"),
8431 mips_cpu_info_from_arch (mips_opts
.arch
)->name
,
8432 mips_cpu_info_from_isa (mips_opts
.isa
)->name
);
8441 create_insn (ip
, insn
);
8444 for (args
= insn
->args
;; ++args
)
8448 s
+= strspn (s
, " \t");
8452 case '\0': /* end of args */
8457 case '3': /* dsp 3-bit unsigned immediate in bit 21 */
8458 my_getExpression (&imm_expr
, s
);
8459 check_absolute_expr (ip
, &imm_expr
);
8460 if (imm_expr
.X_add_number
& ~OP_MASK_SA3
)
8462 as_bad (_("DSP immediate not in range 0..%d (%lu)"),
8463 OP_MASK_SA3
, (unsigned long) imm_expr
.X_add_number
);
8465 INSERT_OPERAND (SA3
, *ip
, imm_expr
.X_add_number
);
8466 imm_expr
.X_op
= O_absent
;
8470 case '4': /* dsp 4-bit unsigned immediate in bit 21 */
8471 my_getExpression (&imm_expr
, s
);
8472 check_absolute_expr (ip
, &imm_expr
);
8473 if (imm_expr
.X_add_number
& ~OP_MASK_SA4
)
8475 as_bad (_("DSP immediate not in range 0..%d (%lu)"),
8476 OP_MASK_SA4
, (unsigned long) imm_expr
.X_add_number
);
8478 INSERT_OPERAND (SA4
, *ip
, imm_expr
.X_add_number
);
8479 imm_expr
.X_op
= O_absent
;
8483 case '5': /* dsp 8-bit unsigned immediate in bit 16 */
8484 my_getExpression (&imm_expr
, s
);
8485 check_absolute_expr (ip
, &imm_expr
);
8486 if (imm_expr
.X_add_number
& ~OP_MASK_IMM8
)
8488 as_bad (_("DSP immediate not in range 0..%d (%lu)"),
8489 OP_MASK_IMM8
, (unsigned long) imm_expr
.X_add_number
);
8491 INSERT_OPERAND (IMM8
, *ip
, imm_expr
.X_add_number
);
8492 imm_expr
.X_op
= O_absent
;
8496 case '6': /* dsp 5-bit unsigned immediate in bit 21 */
8497 my_getExpression (&imm_expr
, s
);
8498 check_absolute_expr (ip
, &imm_expr
);
8499 if (imm_expr
.X_add_number
& ~OP_MASK_RS
)
8501 as_bad (_("DSP immediate not in range 0..%d (%lu)"),
8502 OP_MASK_RS
, (unsigned long) imm_expr
.X_add_number
);
8504 INSERT_OPERAND (RS
, *ip
, imm_expr
.X_add_number
);
8505 imm_expr
.X_op
= O_absent
;
8509 case '7': /* four dsp accumulators in bits 11,12 */
8510 if (s
[0] == '$' && s
[1] == 'a' && s
[2] == 'c' &&
8511 s
[3] >= '0' && s
[3] <= '3')
8515 INSERT_OPERAND (DSPACC
, *ip
, regno
);
8519 as_bad (_("Invalid dsp acc register"));
8522 case '8': /* dsp 6-bit unsigned immediate in bit 11 */
8523 my_getExpression (&imm_expr
, s
);
8524 check_absolute_expr (ip
, &imm_expr
);
8525 if (imm_expr
.X_add_number
& ~OP_MASK_WRDSP
)
8527 as_bad (_("DSP immediate not in range 0..%d (%lu)"),
8529 (unsigned long) imm_expr
.X_add_number
);
8531 INSERT_OPERAND (WRDSP
, *ip
, imm_expr
.X_add_number
);
8532 imm_expr
.X_op
= O_absent
;
8536 case '9': /* four dsp accumulators in bits 21,22 */
8537 if (s
[0] == '$' && s
[1] == 'a' && s
[2] == 'c' &&
8538 s
[3] >= '0' && s
[3] <= '3')
8542 INSERT_OPERAND (DSPACC_S
, *ip
, regno
);
8546 as_bad (_("Invalid dsp acc register"));
8549 case '0': /* dsp 6-bit signed immediate in bit 20 */
8550 my_getExpression (&imm_expr
, s
);
8551 check_absolute_expr (ip
, &imm_expr
);
8552 min_range
= -((OP_MASK_DSPSFT
+ 1) >> 1);
8553 max_range
= ((OP_MASK_DSPSFT
+ 1) >> 1) - 1;
8554 if (imm_expr
.X_add_number
< min_range
||
8555 imm_expr
.X_add_number
> max_range
)
8557 as_bad (_("DSP immediate not in range %ld..%ld (%ld)"),
8558 (long) min_range
, (long) max_range
,
8559 (long) imm_expr
.X_add_number
);
8561 INSERT_OPERAND (DSPSFT
, *ip
, imm_expr
.X_add_number
);
8562 imm_expr
.X_op
= O_absent
;
8566 case '\'': /* dsp 6-bit unsigned immediate in bit 16 */
8567 my_getExpression (&imm_expr
, s
);
8568 check_absolute_expr (ip
, &imm_expr
);
8569 if (imm_expr
.X_add_number
& ~OP_MASK_RDDSP
)
8571 as_bad (_("DSP immediate not in range 0..%d (%lu)"),
8573 (unsigned long) imm_expr
.X_add_number
);
8575 INSERT_OPERAND (RDDSP
, *ip
, imm_expr
.X_add_number
);
8576 imm_expr
.X_op
= O_absent
;
8580 case ':': /* dsp 7-bit signed immediate in bit 19 */
8581 my_getExpression (&imm_expr
, s
);
8582 check_absolute_expr (ip
, &imm_expr
);
8583 min_range
= -((OP_MASK_DSPSFT_7
+ 1) >> 1);
8584 max_range
= ((OP_MASK_DSPSFT_7
+ 1) >> 1) - 1;
8585 if (imm_expr
.X_add_number
< min_range
||
8586 imm_expr
.X_add_number
> max_range
)
8588 as_bad (_("DSP immediate not in range %ld..%ld (%ld)"),
8589 (long) min_range
, (long) max_range
,
8590 (long) imm_expr
.X_add_number
);
8592 INSERT_OPERAND (DSPSFT_7
, *ip
, imm_expr
.X_add_number
);
8593 imm_expr
.X_op
= O_absent
;
8597 case '@': /* dsp 10-bit signed immediate in bit 16 */
8598 my_getExpression (&imm_expr
, s
);
8599 check_absolute_expr (ip
, &imm_expr
);
8600 min_range
= -((OP_MASK_IMM10
+ 1) >> 1);
8601 max_range
= ((OP_MASK_IMM10
+ 1) >> 1) - 1;
8602 if (imm_expr
.X_add_number
< min_range
||
8603 imm_expr
.X_add_number
> max_range
)
8605 as_bad (_("DSP immediate not in range %ld..%ld (%ld)"),
8606 (long) min_range
, (long) max_range
,
8607 (long) imm_expr
.X_add_number
);
8609 INSERT_OPERAND (IMM10
, *ip
, imm_expr
.X_add_number
);
8610 imm_expr
.X_op
= O_absent
;
8614 case '!': /* MT usermode flag bit. */
8615 my_getExpression (&imm_expr
, s
);
8616 check_absolute_expr (ip
, &imm_expr
);
8617 if (imm_expr
.X_add_number
& ~OP_MASK_MT_U
)
8618 as_bad (_("MT usermode bit not 0 or 1 (%lu)"),
8619 (unsigned long) imm_expr
.X_add_number
);
8620 INSERT_OPERAND (MT_U
, *ip
, imm_expr
.X_add_number
);
8621 imm_expr
.X_op
= O_absent
;
8625 case '$': /* MT load high flag bit. */
8626 my_getExpression (&imm_expr
, s
);
8627 check_absolute_expr (ip
, &imm_expr
);
8628 if (imm_expr
.X_add_number
& ~OP_MASK_MT_H
)
8629 as_bad (_("MT load high bit not 0 or 1 (%lu)"),
8630 (unsigned long) imm_expr
.X_add_number
);
8631 INSERT_OPERAND (MT_H
, *ip
, imm_expr
.X_add_number
);
8632 imm_expr
.X_op
= O_absent
;
8636 case '*': /* four dsp accumulators in bits 18,19 */
8637 if (s
[0] == '$' && s
[1] == 'a' && s
[2] == 'c' &&
8638 s
[3] >= '0' && s
[3] <= '3')
8642 INSERT_OPERAND (MTACC_T
, *ip
, regno
);
8646 as_bad (_("Invalid dsp/smartmips acc register"));
8649 case '&': /* four dsp accumulators in bits 13,14 */
8650 if (s
[0] == '$' && s
[1] == 'a' && s
[2] == 'c' &&
8651 s
[3] >= '0' && s
[3] <= '3')
8655 INSERT_OPERAND (MTACC_D
, *ip
, regno
);
8659 as_bad (_("Invalid dsp/smartmips acc register"));
8671 INSERT_OPERAND (RS
, *ip
, lastregno
);
8675 INSERT_OPERAND (RT
, *ip
, lastregno
);
8679 INSERT_OPERAND (FT
, *ip
, lastregno
);
8683 INSERT_OPERAND (FS
, *ip
, lastregno
);
8689 /* Handle optional base register.
8690 Either the base register is omitted or
8691 we must have a left paren. */
8692 /* This is dependent on the next operand specifier
8693 is a base register specification. */
8694 assert (args
[1] == 'b' || args
[1] == '5'
8695 || args
[1] == '-' || args
[1] == '4');
8699 case ')': /* these must match exactly */
8706 case '+': /* Opcode extension character. */
8709 case '1': /* UDI immediates. */
8714 const struct mips_immed
*imm
= mips_immed
;
8716 while (imm
->type
&& imm
->type
!= *args
)
8720 my_getExpression (&imm_expr
, s
);
8721 check_absolute_expr (ip
, &imm_expr
);
8722 if ((unsigned long) imm_expr
.X_add_number
& ~imm
->mask
)
8724 as_warn (_("Illegal %s number (%lu, 0x%lx)"),
8725 imm
->desc
? imm
->desc
: ip
->insn_mo
->name
,
8726 (unsigned long) imm_expr
.X_add_number
,
8727 (unsigned long) imm_expr
.X_add_number
);
8728 imm_expr
.X_add_number
&= imm
->mask
;
8730 ip
->insn_opcode
|= ((unsigned long) imm_expr
.X_add_number
8732 imm_expr
.X_op
= O_absent
;
8737 case 'A': /* ins/ext position, becomes LSB. */
8746 my_getExpression (&imm_expr
, s
);
8747 check_absolute_expr (ip
, &imm_expr
);
8748 if ((unsigned long) imm_expr
.X_add_number
< limlo
8749 || (unsigned long) imm_expr
.X_add_number
> limhi
)
8751 as_bad (_("Improper position (%lu)"),
8752 (unsigned long) imm_expr
.X_add_number
);
8753 imm_expr
.X_add_number
= limlo
;
8755 lastpos
= imm_expr
.X_add_number
;
8756 INSERT_OPERAND (SHAMT
, *ip
, imm_expr
.X_add_number
);
8757 imm_expr
.X_op
= O_absent
;
8761 case 'B': /* ins size, becomes MSB. */
8770 my_getExpression (&imm_expr
, s
);
8771 check_absolute_expr (ip
, &imm_expr
);
8772 /* Check for negative input so that small negative numbers
8773 will not succeed incorrectly. The checks against
8774 (pos+size) transitively check "size" itself,
8775 assuming that "pos" is reasonable. */
8776 if ((long) imm_expr
.X_add_number
< 0
8777 || ((unsigned long) imm_expr
.X_add_number
8779 || ((unsigned long) imm_expr
.X_add_number
8782 as_bad (_("Improper insert size (%lu, position %lu)"),
8783 (unsigned long) imm_expr
.X_add_number
,
8784 (unsigned long) lastpos
);
8785 imm_expr
.X_add_number
= limlo
- lastpos
;
8787 INSERT_OPERAND (INSMSB
, *ip
,
8788 lastpos
+ imm_expr
.X_add_number
- 1);
8789 imm_expr
.X_op
= O_absent
;
8793 case 'C': /* ext size, becomes MSBD. */
8806 my_getExpression (&imm_expr
, s
);
8807 check_absolute_expr (ip
, &imm_expr
);
8808 /* Check for negative input so that small negative numbers
8809 will not succeed incorrectly. The checks against
8810 (pos+size) transitively check "size" itself,
8811 assuming that "pos" is reasonable. */
8812 if ((long) imm_expr
.X_add_number
< 0
8813 || ((unsigned long) imm_expr
.X_add_number
8815 || ((unsigned long) imm_expr
.X_add_number
8818 as_bad (_("Improper extract size (%lu, position %lu)"),
8819 (unsigned long) imm_expr
.X_add_number
,
8820 (unsigned long) lastpos
);
8821 imm_expr
.X_add_number
= limlo
- lastpos
;
8823 INSERT_OPERAND (EXTMSBD
, *ip
, imm_expr
.X_add_number
- 1);
8824 imm_expr
.X_op
= O_absent
;
8829 /* +D is for disassembly only; never match. */
8833 /* "+I" is like "I", except that imm2_expr is used. */
8834 my_getExpression (&imm2_expr
, s
);
8835 if (imm2_expr
.X_op
!= O_big
8836 && imm2_expr
.X_op
!= O_constant
)
8837 insn_error
= _("absolute expression required");
8838 if (HAVE_32BIT_GPRS
)
8839 normalize_constant_expr (&imm2_expr
);
8843 case 'T': /* Coprocessor register. */
8844 /* +T is for disassembly only; never match. */
8847 case 't': /* Coprocessor register number. */
8848 if (s
[0] == '$' && ISDIGIT (s
[1]))
8858 while (ISDIGIT (*s
));
8860 as_bad (_("Invalid register number (%d)"), regno
);
8863 INSERT_OPERAND (RT
, *ip
, regno
);
8868 as_bad (_("Invalid coprocessor 0 register number"));
8872 as_bad (_("internal: bad mips opcode (unknown extension operand type `+%c'): %s %s"),
8873 *args
, insn
->name
, insn
->args
);
8874 /* Further processing is fruitless. */
8879 case '<': /* must be at least one digit */
8881 * According to the manual, if the shift amount is greater
8882 * than 31 or less than 0, then the shift amount should be
8883 * mod 32. In reality the mips assembler issues an error.
8884 * We issue a warning and mask out all but the low 5 bits.
8886 my_getExpression (&imm_expr
, s
);
8887 check_absolute_expr (ip
, &imm_expr
);
8888 if ((unsigned long) imm_expr
.X_add_number
> 31)
8889 as_warn (_("Improper shift amount (%lu)"),
8890 (unsigned long) imm_expr
.X_add_number
);
8891 INSERT_OPERAND (SHAMT
, *ip
, imm_expr
.X_add_number
);
8892 imm_expr
.X_op
= O_absent
;
8896 case '>': /* shift amount minus 32 */
8897 my_getExpression (&imm_expr
, s
);
8898 check_absolute_expr (ip
, &imm_expr
);
8899 if ((unsigned long) imm_expr
.X_add_number
< 32
8900 || (unsigned long) imm_expr
.X_add_number
> 63)
8902 INSERT_OPERAND (SHAMT
, *ip
, imm_expr
.X_add_number
- 32);
8903 imm_expr
.X_op
= O_absent
;
8907 case 'k': /* cache code */
8908 case 'h': /* prefx code */
8909 my_getExpression (&imm_expr
, s
);
8910 check_absolute_expr (ip
, &imm_expr
);
8911 if ((unsigned long) imm_expr
.X_add_number
> 31)
8912 as_warn (_("Invalid value for `%s' (%lu)"),
8914 (unsigned long) imm_expr
.X_add_number
);
8916 INSERT_OPERAND (CACHE
, *ip
, imm_expr
.X_add_number
);
8918 INSERT_OPERAND (PREFX
, *ip
, imm_expr
.X_add_number
);
8919 imm_expr
.X_op
= O_absent
;
8923 case 'c': /* break code */
8924 my_getExpression (&imm_expr
, s
);
8925 check_absolute_expr (ip
, &imm_expr
);
8926 if ((unsigned long) imm_expr
.X_add_number
> OP_MASK_CODE
)
8927 as_warn (_("Code for %s not in range 0..1023 (%lu)"),
8929 (unsigned long) imm_expr
.X_add_number
);
8930 INSERT_OPERAND (CODE
, *ip
, imm_expr
.X_add_number
);
8931 imm_expr
.X_op
= O_absent
;
8935 case 'q': /* lower break code */
8936 my_getExpression (&imm_expr
, s
);
8937 check_absolute_expr (ip
, &imm_expr
);
8938 if ((unsigned long) imm_expr
.X_add_number
> OP_MASK_CODE2
)
8939 as_warn (_("Lower code for %s not in range 0..1023 (%lu)"),
8941 (unsigned long) imm_expr
.X_add_number
);
8942 INSERT_OPERAND (CODE2
, *ip
, imm_expr
.X_add_number
);
8943 imm_expr
.X_op
= O_absent
;
8947 case 'B': /* 20-bit syscall/break code. */
8948 my_getExpression (&imm_expr
, s
);
8949 check_absolute_expr (ip
, &imm_expr
);
8950 if ((unsigned long) imm_expr
.X_add_number
> OP_MASK_CODE20
)
8951 as_warn (_("Code for %s not in range 0..1048575 (%lu)"),
8953 (unsigned long) imm_expr
.X_add_number
);
8954 INSERT_OPERAND (CODE20
, *ip
, imm_expr
.X_add_number
);
8955 imm_expr
.X_op
= O_absent
;
8959 case 'C': /* Coprocessor code */
8960 my_getExpression (&imm_expr
, s
);
8961 check_absolute_expr (ip
, &imm_expr
);
8962 if ((unsigned long) imm_expr
.X_add_number
> OP_MASK_COPZ
)
8964 as_warn (_("Coproccesor code > 25 bits (%lu)"),
8965 (unsigned long) imm_expr
.X_add_number
);
8966 imm_expr
.X_add_number
&= OP_MASK_COPZ
;
8968 INSERT_OPERAND (COPZ
, *ip
, imm_expr
.X_add_number
);
8969 imm_expr
.X_op
= O_absent
;
8973 case 'J': /* 19-bit wait code. */
8974 my_getExpression (&imm_expr
, s
);
8975 check_absolute_expr (ip
, &imm_expr
);
8976 if ((unsigned long) imm_expr
.X_add_number
> OP_MASK_CODE19
)
8978 as_warn (_("Illegal 19-bit code (%lu)"),
8979 (unsigned long) imm_expr
.X_add_number
);
8980 imm_expr
.X_add_number
&= OP_MASK_CODE19
;
8982 INSERT_OPERAND (CODE19
, *ip
, imm_expr
.X_add_number
);
8983 imm_expr
.X_op
= O_absent
;
8987 case 'P': /* Performance register. */
8988 my_getExpression (&imm_expr
, s
);
8989 check_absolute_expr (ip
, &imm_expr
);
8990 if (imm_expr
.X_add_number
!= 0 && imm_expr
.X_add_number
!= 1)
8991 as_warn (_("Invalid performance register (%lu)"),
8992 (unsigned long) imm_expr
.X_add_number
);
8993 INSERT_OPERAND (PERFREG
, *ip
, imm_expr
.X_add_number
);
8994 imm_expr
.X_op
= O_absent
;
8998 case 'G': /* Coprocessor destination register. */
8999 if (((ip
->insn_opcode
>> OP_SH_OP
) & OP_MASK_OP
) == OP_OP_COP0
)
9000 ok
= reg_lookup (&s
, RTYPE_NUM
| RTYPE_CP0
, ®no
);
9002 ok
= reg_lookup (&s
, RTYPE_NUM
| RTYPE_GP
, ®no
);
9003 INSERT_OPERAND (RD
, *ip
, regno
);
9012 case 'b': /* base register */
9013 case 'd': /* destination register */
9014 case 's': /* source register */
9015 case 't': /* target register */
9016 case 'r': /* both target and source */
9017 case 'v': /* both dest and source */
9018 case 'w': /* both dest and target */
9019 case 'E': /* coprocessor target register */
9020 case 'K': /* 'rdhwr' destination register */
9021 case 'x': /* ignore register name */
9022 case 'z': /* must be zero register */
9023 case 'U': /* destination register (clo/clz). */
9024 case 'g': /* coprocessor destination register */
9026 if (*args
== 'E' || *args
== 'K')
9027 ok
= reg_lookup (&s
, RTYPE_NUM
, ®no
);
9030 ok
= reg_lookup (&s
, RTYPE_NUM
| RTYPE_GP
, ®no
);
9031 if (regno
== AT
&& ! mips_opts
.noat
)
9032 as_warn ("Used $at without \".set noat\"");
9041 if (c
== 'r' || c
== 'v' || c
== 'w')
9048 /* 'z' only matches $0. */
9049 if (c
== 'z' && regno
!= 0)
9052 /* Now that we have assembled one operand, we use the args string
9053 * to figure out where it goes in the instruction. */
9060 INSERT_OPERAND (RS
, *ip
, regno
);
9066 INSERT_OPERAND (RD
, *ip
, regno
);
9069 INSERT_OPERAND (RD
, *ip
, regno
);
9070 INSERT_OPERAND (RT
, *ip
, regno
);
9075 INSERT_OPERAND (RT
, *ip
, regno
);
9078 /* This case exists because on the r3000 trunc
9079 expands into a macro which requires a gp
9080 register. On the r6000 or r4000 it is
9081 assembled into a single instruction which
9082 ignores the register. Thus the insn version
9083 is MIPS_ISA2 and uses 'x', and the macro
9084 version is MIPS_ISA1 and uses 't'. */
9087 /* This case is for the div instruction, which
9088 acts differently if the destination argument
9089 is $0. This only matches $0, and is checked
9090 outside the switch. */
9093 /* Itbl operand; not yet implemented. FIXME ?? */
9095 /* What about all other operands like 'i', which
9096 can be specified in the opcode table? */
9105 INSERT_OPERAND (RS
, *ip
, lastregno
);
9108 INSERT_OPERAND (RT
, *ip
, lastregno
);
9113 case 'O': /* MDMX alignment immediate constant. */
9114 my_getExpression (&imm_expr
, s
);
9115 check_absolute_expr (ip
, &imm_expr
);
9116 if ((unsigned long) imm_expr
.X_add_number
> OP_MASK_ALN
)
9117 as_warn ("Improper align amount (%ld), using low bits",
9118 (long) imm_expr
.X_add_number
);
9119 INSERT_OPERAND (ALN
, *ip
, imm_expr
.X_add_number
);
9120 imm_expr
.X_op
= O_absent
;
9124 case 'Q': /* MDMX vector, element sel, or const. */
9127 /* MDMX Immediate. */
9128 my_getExpression (&imm_expr
, s
);
9129 check_absolute_expr (ip
, &imm_expr
);
9130 if ((unsigned long) imm_expr
.X_add_number
> OP_MASK_FT
)
9131 as_warn (_("Invalid MDMX Immediate (%ld)"),
9132 (long) imm_expr
.X_add_number
);
9133 INSERT_OPERAND (FT
, *ip
, imm_expr
.X_add_number
);
9134 if (ip
->insn_opcode
& (OP_MASK_VSEL
<< OP_SH_VSEL
))
9135 ip
->insn_opcode
|= MDMX_FMTSEL_IMM_QH
<< OP_SH_VSEL
;
9137 ip
->insn_opcode
|= MDMX_FMTSEL_IMM_OB
<< OP_SH_VSEL
;
9138 imm_expr
.X_op
= O_absent
;
9142 /* Not MDMX Immediate. Fall through. */
9143 case 'X': /* MDMX destination register. */
9144 case 'Y': /* MDMX source register. */
9145 case 'Z': /* MDMX target register. */
9147 case 'D': /* floating point destination register */
9148 case 'S': /* floating point source register */
9149 case 'T': /* floating point target register */
9150 case 'R': /* floating point source register */
9155 || (mips_opts
.ase_mdmx
9156 && (ip
->insn_mo
->pinfo
& FP_D
)
9157 && (ip
->insn_mo
->pinfo
& (INSN_COPROC_MOVE_DELAY
9158 | INSN_COPROC_MEMORY_DELAY
9159 | INSN_LOAD_COPROC_DELAY
9160 | INSN_LOAD_MEMORY_DELAY
9161 | INSN_STORE_MEMORY
))))
9164 if (reg_lookup (&s
, rtype
, ®no
))
9166 if ((regno
& 1) != 0
9168 && ! mips_oddfpreg_ok (ip
->insn_mo
, argnum
))
9169 as_warn (_("Float register should be even, was %d"),
9177 if (c
== 'V' || c
== 'W')
9188 INSERT_OPERAND (FD
, *ip
, regno
);
9193 INSERT_OPERAND (FS
, *ip
, regno
);
9196 /* This is like 'Z', but also needs to fix the MDMX
9197 vector/scalar select bits. Note that the
9198 scalar immediate case is handled above. */
9201 int is_qh
= (ip
->insn_opcode
& (1 << OP_SH_VSEL
));
9202 int max_el
= (is_qh
? 3 : 7);
9204 my_getExpression(&imm_expr
, s
);
9205 check_absolute_expr (ip
, &imm_expr
);
9207 if (imm_expr
.X_add_number
> max_el
)
9208 as_bad(_("Bad element selector %ld"),
9209 (long) imm_expr
.X_add_number
);
9210 imm_expr
.X_add_number
&= max_el
;
9211 ip
->insn_opcode
|= (imm_expr
.X_add_number
9214 imm_expr
.X_op
= O_absent
;
9216 as_warn(_("Expecting ']' found '%s'"), s
);
9222 if (ip
->insn_opcode
& (OP_MASK_VSEL
<< OP_SH_VSEL
))
9223 ip
->insn_opcode
|= (MDMX_FMTSEL_VEC_QH
9226 ip
->insn_opcode
|= (MDMX_FMTSEL_VEC_OB
<<
9233 INSERT_OPERAND (FT
, *ip
, regno
);
9236 INSERT_OPERAND (FR
, *ip
, regno
);
9246 INSERT_OPERAND (FS
, *ip
, lastregno
);
9249 INSERT_OPERAND (FT
, *ip
, lastregno
);
9255 my_getExpression (&imm_expr
, s
);
9256 if (imm_expr
.X_op
!= O_big
9257 && imm_expr
.X_op
!= O_constant
)
9258 insn_error
= _("absolute expression required");
9259 if (HAVE_32BIT_GPRS
)
9260 normalize_constant_expr (&imm_expr
);
9265 my_getExpression (&offset_expr
, s
);
9266 normalize_address_expr (&offset_expr
);
9267 *imm_reloc
= BFD_RELOC_32
;
9280 unsigned char temp
[8];
9282 unsigned int length
;
9287 /* These only appear as the last operand in an
9288 instruction, and every instruction that accepts
9289 them in any variant accepts them in all variants.
9290 This means we don't have to worry about backing out
9291 any changes if the instruction does not match.
9293 The difference between them is the size of the
9294 floating point constant and where it goes. For 'F'
9295 and 'L' the constant is 64 bits; for 'f' and 'l' it
9296 is 32 bits. Where the constant is placed is based
9297 on how the MIPS assembler does things:
9300 f -- immediate value
9303 The .lit4 and .lit8 sections are only used if
9304 permitted by the -G argument.
9306 The code below needs to know whether the target register
9307 is 32 or 64 bits wide. It relies on the fact 'f' and
9308 'F' are used with GPR-based instructions and 'l' and
9309 'L' are used with FPR-based instructions. */
9311 f64
= *args
== 'F' || *args
== 'L';
9312 using_gprs
= *args
== 'F' || *args
== 'f';
9314 save_in
= input_line_pointer
;
9315 input_line_pointer
= s
;
9316 err
= md_atof (f64
? 'd' : 'f', (char *) temp
, &len
);
9318 s
= input_line_pointer
;
9319 input_line_pointer
= save_in
;
9320 if (err
!= NULL
&& *err
!= '\0')
9322 as_bad (_("Bad floating point constant: %s"), err
);
9323 memset (temp
, '\0', sizeof temp
);
9324 length
= f64
? 8 : 4;
9327 assert (length
== (unsigned) (f64
? 8 : 4));
9331 && (g_switch_value
< 4
9332 || (temp
[0] == 0 && temp
[1] == 0)
9333 || (temp
[2] == 0 && temp
[3] == 0))))
9335 imm_expr
.X_op
= O_constant
;
9336 if (! target_big_endian
)
9337 imm_expr
.X_add_number
= bfd_getl32 (temp
);
9339 imm_expr
.X_add_number
= bfd_getb32 (temp
);
9342 && ! mips_disable_float_construction
9343 /* Constants can only be constructed in GPRs and
9344 copied to FPRs if the GPRs are at least as wide
9345 as the FPRs. Force the constant into memory if
9346 we are using 64-bit FPRs but the GPRs are only
9349 || ! (HAVE_64BIT_FPRS
&& HAVE_32BIT_GPRS
))
9350 && ((temp
[0] == 0 && temp
[1] == 0)
9351 || (temp
[2] == 0 && temp
[3] == 0))
9352 && ((temp
[4] == 0 && temp
[5] == 0)
9353 || (temp
[6] == 0 && temp
[7] == 0)))
9355 /* The value is simple enough to load with a couple of
9356 instructions. If using 32-bit registers, set
9357 imm_expr to the high order 32 bits and offset_expr to
9358 the low order 32 bits. Otherwise, set imm_expr to
9359 the entire 64 bit constant. */
9360 if (using_gprs
? HAVE_32BIT_GPRS
: HAVE_32BIT_FPRS
)
9362 imm_expr
.X_op
= O_constant
;
9363 offset_expr
.X_op
= O_constant
;
9364 if (! target_big_endian
)
9366 imm_expr
.X_add_number
= bfd_getl32 (temp
+ 4);
9367 offset_expr
.X_add_number
= bfd_getl32 (temp
);
9371 imm_expr
.X_add_number
= bfd_getb32 (temp
);
9372 offset_expr
.X_add_number
= bfd_getb32 (temp
+ 4);
9374 if (offset_expr
.X_add_number
== 0)
9375 offset_expr
.X_op
= O_absent
;
9377 else if (sizeof (imm_expr
.X_add_number
) > 4)
9379 imm_expr
.X_op
= O_constant
;
9380 if (! target_big_endian
)
9381 imm_expr
.X_add_number
= bfd_getl64 (temp
);
9383 imm_expr
.X_add_number
= bfd_getb64 (temp
);
9387 imm_expr
.X_op
= O_big
;
9388 imm_expr
.X_add_number
= 4;
9389 if (! target_big_endian
)
9391 generic_bignum
[0] = bfd_getl16 (temp
);
9392 generic_bignum
[1] = bfd_getl16 (temp
+ 2);
9393 generic_bignum
[2] = bfd_getl16 (temp
+ 4);
9394 generic_bignum
[3] = bfd_getl16 (temp
+ 6);
9398 generic_bignum
[0] = bfd_getb16 (temp
+ 6);
9399 generic_bignum
[1] = bfd_getb16 (temp
+ 4);
9400 generic_bignum
[2] = bfd_getb16 (temp
+ 2);
9401 generic_bignum
[3] = bfd_getb16 (temp
);
9407 const char *newname
;
9410 /* Switch to the right section. */
9412 subseg
= now_subseg
;
9415 default: /* unused default case avoids warnings. */
9417 newname
= RDATA_SECTION_NAME
;
9418 if (g_switch_value
>= 8)
9422 newname
= RDATA_SECTION_NAME
;
9425 assert (g_switch_value
>= 4);
9429 new_seg
= subseg_new (newname
, (subsegT
) 0);
9431 bfd_set_section_flags (stdoutput
, new_seg
,
9436 frag_align (*args
== 'l' ? 2 : 3, 0, 0);
9437 if (IS_ELF
&& strcmp (TARGET_OS
, "elf") != 0)
9438 record_alignment (new_seg
, 4);
9440 record_alignment (new_seg
, *args
== 'l' ? 2 : 3);
9442 as_bad (_("Can't use floating point insn in this section"));
9444 /* Set the argument to the current address in the
9446 offset_expr
.X_op
= O_symbol
;
9447 offset_expr
.X_add_symbol
=
9448 symbol_new ("L0\001", now_seg
,
9449 (valueT
) frag_now_fix (), frag_now
);
9450 offset_expr
.X_add_number
= 0;
9452 /* Put the floating point number into the section. */
9453 p
= frag_more ((int) length
);
9454 memcpy (p
, temp
, length
);
9456 /* Switch back to the original section. */
9457 subseg_set (seg
, subseg
);
9462 case 'i': /* 16 bit unsigned immediate */
9463 case 'j': /* 16 bit signed immediate */
9464 *imm_reloc
= BFD_RELOC_LO16
;
9465 if (my_getSmallExpression (&imm_expr
, imm_reloc
, s
) == 0)
9468 offsetT minval
, maxval
;
9470 more
= (insn
+ 1 < &mips_opcodes
[NUMOPCODES
]
9471 && strcmp (insn
->name
, insn
[1].name
) == 0);
9473 /* If the expression was written as an unsigned number,
9474 only treat it as signed if there are no more
9478 && sizeof (imm_expr
.X_add_number
) <= 4
9479 && imm_expr
.X_op
== O_constant
9480 && imm_expr
.X_add_number
< 0
9481 && imm_expr
.X_unsigned
9485 /* For compatibility with older assemblers, we accept
9486 0x8000-0xffff as signed 16-bit numbers when only
9487 signed numbers are allowed. */
9489 minval
= 0, maxval
= 0xffff;
9491 minval
= -0x8000, maxval
= 0x7fff;
9493 minval
= -0x8000, maxval
= 0xffff;
9495 if (imm_expr
.X_op
!= O_constant
9496 || imm_expr
.X_add_number
< minval
9497 || imm_expr
.X_add_number
> maxval
)
9501 if (imm_expr
.X_op
== O_constant
9502 || imm_expr
.X_op
== O_big
)
9503 as_bad (_("expression out of range"));
9509 case 'o': /* 16 bit offset */
9510 /* Check whether there is only a single bracketed expression
9511 left. If so, it must be the base register and the
9512 constant must be zero. */
9513 if (*s
== '(' && strchr (s
+ 1, '(') == 0)
9515 offset_expr
.X_op
= O_constant
;
9516 offset_expr
.X_add_number
= 0;
9520 /* If this value won't fit into a 16 bit offset, then go
9521 find a macro that will generate the 32 bit offset
9523 if (my_getSmallExpression (&offset_expr
, offset_reloc
, s
) == 0
9524 && (offset_expr
.X_op
!= O_constant
9525 || offset_expr
.X_add_number
>= 0x8000
9526 || offset_expr
.X_add_number
< -0x8000))
9532 case 'p': /* pc relative offset */
9533 *offset_reloc
= BFD_RELOC_16_PCREL_S2
;
9534 my_getExpression (&offset_expr
, s
);
9538 case 'u': /* upper 16 bits */
9539 if (my_getSmallExpression (&imm_expr
, imm_reloc
, s
) == 0
9540 && imm_expr
.X_op
== O_constant
9541 && (imm_expr
.X_add_number
< 0
9542 || imm_expr
.X_add_number
>= 0x10000))
9543 as_bad (_("lui expression not in range 0..65535"));
9547 case 'a': /* 26 bit address */
9548 my_getExpression (&offset_expr
, s
);
9550 *offset_reloc
= BFD_RELOC_MIPS_JMP
;
9553 case 'N': /* 3 bit branch condition code */
9554 case 'M': /* 3 bit compare condition code */
9556 if (ip
->insn_mo
->pinfo
& (FP_D
| FP_S
))
9558 if (!reg_lookup (&s
, rtype
, ®no
))
9560 if ((strcmp(str
+ strlen(str
) - 3, ".ps") == 0
9561 || strcmp(str
+ strlen(str
) - 5, "any2f") == 0
9562 || strcmp(str
+ strlen(str
) - 5, "any2t") == 0)
9563 && (regno
& 1) != 0)
9564 as_warn(_("Condition code register should be even for %s, was %d"),
9566 if ((strcmp(str
+ strlen(str
) - 5, "any4f") == 0
9567 || strcmp(str
+ strlen(str
) - 5, "any4t") == 0)
9568 && (regno
& 3) != 0)
9569 as_warn(_("Condition code register should be 0 or 4 for %s, was %d"),
9572 INSERT_OPERAND (BCC
, *ip
, regno
);
9574 INSERT_OPERAND (CCC
, *ip
, regno
);
9578 if (s
[0] == '0' && (s
[1] == 'x' || s
[1] == 'X'))
9589 while (ISDIGIT (*s
));
9592 c
= 8; /* Invalid sel value. */
9595 as_bad (_("invalid coprocessor sub-selection value (0-7)"));
9596 ip
->insn_opcode
|= c
;
9600 /* Must be at least one digit. */
9601 my_getExpression (&imm_expr
, s
);
9602 check_absolute_expr (ip
, &imm_expr
);
9604 if ((unsigned long) imm_expr
.X_add_number
9605 > (unsigned long) OP_MASK_VECBYTE
)
9607 as_bad (_("bad byte vector index (%ld)"),
9608 (long) imm_expr
.X_add_number
);
9609 imm_expr
.X_add_number
= 0;
9612 INSERT_OPERAND (VECBYTE
, *ip
, imm_expr
.X_add_number
);
9613 imm_expr
.X_op
= O_absent
;
9618 my_getExpression (&imm_expr
, s
);
9619 check_absolute_expr (ip
, &imm_expr
);
9621 if ((unsigned long) imm_expr
.X_add_number
9622 > (unsigned long) OP_MASK_VECALIGN
)
9624 as_bad (_("bad byte vector index (%ld)"),
9625 (long) imm_expr
.X_add_number
);
9626 imm_expr
.X_add_number
= 0;
9629 INSERT_OPERAND (VECALIGN
, *ip
, imm_expr
.X_add_number
);
9630 imm_expr
.X_op
= O_absent
;
9635 as_bad (_("bad char = '%c'\n"), *args
);
9640 /* Args don't match. */
9641 if (insn
+ 1 < &mips_opcodes
[NUMOPCODES
] &&
9642 !strcmp (insn
->name
, insn
[1].name
))
9646 insn_error
= _("illegal operands");
9651 insn_error
= _("illegal operands");
9656 #define SKIP_SPACE_TABS(S) { while (*(S) == ' ' || *(S) == '\t') ++(S); }
9658 /* This routine assembles an instruction into its binary format when
9659 assembling for the mips16. As a side effect, it sets one of the
9660 global variables imm_reloc or offset_reloc to the type of
9661 relocation to do if one of the operands is an address expression.
9662 It also sets mips16_small and mips16_ext if the user explicitly
9663 requested a small or extended instruction. */
9666 mips16_ip (char *str
, struct mips_cl_insn
*ip
)
9670 struct mips_opcode
*insn
;
9673 unsigned int lastregno
= 0;
9679 mips16_small
= FALSE
;
9682 for (s
= str
; ISLOWER (*s
); ++s
)
9694 if (s
[1] == 't' && s
[2] == ' ')
9697 mips16_small
= TRUE
;
9701 else if (s
[1] == 'e' && s
[2] == ' ')
9710 insn_error
= _("unknown opcode");
9714 if (mips_opts
.noautoextend
&& ! mips16_ext
)
9715 mips16_small
= TRUE
;
9717 if ((insn
= (struct mips_opcode
*) hash_find (mips16_op_hash
, str
)) == NULL
)
9719 insn_error
= _("unrecognized opcode");
9728 assert (strcmp (insn
->name
, str
) == 0);
9730 if (OPCODE_IS_MEMBER (insn
, mips_opts
.isa
, mips_opts
.arch
))
9737 if (insn
+ 1 < &mips16_opcodes
[bfd_mips16_num_opcodes
]
9738 && strcmp (insn
->name
, insn
[1].name
) == 0)
9747 static char buf
[100];
9749 _("opcode not supported on this processor: %s (%s)"),
9750 mips_cpu_info_from_arch (mips_opts
.arch
)->name
,
9751 mips_cpu_info_from_isa (mips_opts
.isa
)->name
);
9758 create_insn (ip
, insn
);
9759 imm_expr
.X_op
= O_absent
;
9760 imm_reloc
[0] = BFD_RELOC_UNUSED
;
9761 imm_reloc
[1] = BFD_RELOC_UNUSED
;
9762 imm_reloc
[2] = BFD_RELOC_UNUSED
;
9763 imm2_expr
.X_op
= O_absent
;
9764 offset_expr
.X_op
= O_absent
;
9765 offset_reloc
[0] = BFD_RELOC_UNUSED
;
9766 offset_reloc
[1] = BFD_RELOC_UNUSED
;
9767 offset_reloc
[2] = BFD_RELOC_UNUSED
;
9768 for (args
= insn
->args
; 1; ++args
)
9775 /* In this switch statement we call break if we did not find
9776 a match, continue if we did find a match, or return if we
9785 /* Stuff the immediate value in now, if we can. */
9786 if (imm_expr
.X_op
== O_constant
9787 && *imm_reloc
> BFD_RELOC_UNUSED
9788 && insn
->pinfo
!= INSN_MACRO
)
9792 switch (*offset_reloc
)
9794 case BFD_RELOC_MIPS16_HI16_S
:
9795 tmp
= (imm_expr
.X_add_number
+ 0x8000) >> 16;
9798 case BFD_RELOC_MIPS16_HI16
:
9799 tmp
= imm_expr
.X_add_number
>> 16;
9802 case BFD_RELOC_MIPS16_LO16
:
9803 tmp
= ((imm_expr
.X_add_number
+ 0x8000) & 0xffff)
9807 case BFD_RELOC_UNUSED
:
9808 tmp
= imm_expr
.X_add_number
;
9814 *offset_reloc
= BFD_RELOC_UNUSED
;
9816 mips16_immed (NULL
, 0, *imm_reloc
- BFD_RELOC_UNUSED
,
9817 tmp
, TRUE
, mips16_small
,
9818 mips16_ext
, &ip
->insn_opcode
,
9819 &ip
->use_extend
, &ip
->extend
);
9820 imm_expr
.X_op
= O_absent
;
9821 *imm_reloc
= BFD_RELOC_UNUSED
;
9835 MIPS16_INSERT_OPERAND (RX
, *ip
, lastregno
);
9838 MIPS16_INSERT_OPERAND (RY
, *ip
, lastregno
);
9854 MIPS16_INSERT_OPERAND (RX
, *ip
, lastregno
);
9856 MIPS16_INSERT_OPERAND (RY
, *ip
, lastregno
);
9871 if (!reg_lookup (&s
, RTYPE_NUM
| RTYPE_GP
, ®no
))
9873 if (c
== 'v' || c
== 'w')
9876 MIPS16_INSERT_OPERAND (RX
, *ip
, lastregno
);
9878 MIPS16_INSERT_OPERAND (RY
, *ip
, lastregno
);
9889 if (c
== 'v' || c
== 'w')
9891 regno
= mips16_to_32_reg_map
[lastregno
];
9905 regno
= mips32_to_16_reg_map
[regno
];
9910 regno
= ILLEGAL_REG
;
9915 regno
= ILLEGAL_REG
;
9920 regno
= ILLEGAL_REG
;
9925 if (regno
== AT
&& ! mips_opts
.noat
)
9926 as_warn (_("used $at without \".set noat\""));
9933 if (regno
== ILLEGAL_REG
)
9940 MIPS16_INSERT_OPERAND (RX
, *ip
, regno
);
9944 MIPS16_INSERT_OPERAND (RY
, *ip
, regno
);
9947 MIPS16_INSERT_OPERAND (RZ
, *ip
, regno
);
9950 MIPS16_INSERT_OPERAND (MOVE32Z
, *ip
, regno
);
9956 MIPS16_INSERT_OPERAND (REGR32
, *ip
, regno
);
9959 regno
= ((regno
& 7) << 2) | ((regno
& 0x18) >> 3);
9960 MIPS16_INSERT_OPERAND (REG32R
, *ip
, regno
);
9970 if (strncmp (s
, "$pc", 3) == 0)
9987 i
= my_getSmallExpression (&imm_expr
, imm_reloc
, s
);
9990 if (imm_expr
.X_op
!= O_constant
)
9993 ip
->use_extend
= TRUE
;
9998 /* We need to relax this instruction. */
9999 *offset_reloc
= *imm_reloc
;
10000 *imm_reloc
= (int) BFD_RELOC_UNUSED
+ c
;
10005 *imm_reloc
= BFD_RELOC_UNUSED
;
10006 /* Fall through. */
10013 my_getExpression (&imm_expr
, s
);
10014 if (imm_expr
.X_op
== O_register
)
10016 /* What we thought was an expression turned out to
10019 if (s
[0] == '(' && args
[1] == '(')
10021 /* It looks like the expression was omitted
10022 before a register indirection, which means
10023 that the expression is implicitly zero. We
10024 still set up imm_expr, so that we handle
10025 explicit extensions correctly. */
10026 imm_expr
.X_op
= O_constant
;
10027 imm_expr
.X_add_number
= 0;
10028 *imm_reloc
= (int) BFD_RELOC_UNUSED
+ c
;
10035 /* We need to relax this instruction. */
10036 *imm_reloc
= (int) BFD_RELOC_UNUSED
+ c
;
10045 /* We use offset_reloc rather than imm_reloc for the PC
10046 relative operands. This lets macros with both
10047 immediate and address operands work correctly. */
10048 my_getExpression (&offset_expr
, s
);
10050 if (offset_expr
.X_op
== O_register
)
10053 /* We need to relax this instruction. */
10054 *offset_reloc
= (int) BFD_RELOC_UNUSED
+ c
;
10058 case '6': /* break code */
10059 my_getExpression (&imm_expr
, s
);
10060 check_absolute_expr (ip
, &imm_expr
);
10061 if ((unsigned long) imm_expr
.X_add_number
> 63)
10062 as_warn (_("Invalid value for `%s' (%lu)"),
10064 (unsigned long) imm_expr
.X_add_number
);
10065 MIPS16_INSERT_OPERAND (IMM6
, *ip
, imm_expr
.X_add_number
);
10066 imm_expr
.X_op
= O_absent
;
10070 case 'a': /* 26 bit address */
10071 my_getExpression (&offset_expr
, s
);
10073 *offset_reloc
= BFD_RELOC_MIPS16_JMP
;
10074 ip
->insn_opcode
<<= 16;
10077 case 'l': /* register list for entry macro */
10078 case 'L': /* register list for exit macro */
10088 unsigned int freg
, reg1
, reg2
;
10090 while (*s
== ' ' || *s
== ',')
10092 if (reg_lookup (&s
, RTYPE_GP
| RTYPE_NUM
, ®1
))
10094 else if (reg_lookup (&s
, RTYPE_FPU
, ®1
))
10098 as_bad (_("can't parse register list"));
10108 if (!reg_lookup (&s
, freg
? RTYPE_FPU
10109 : (RTYPE_GP
| RTYPE_NUM
), ®2
))
10111 as_bad (_("invalid register list"));
10115 if (freg
&& reg1
== 0 && reg2
== 0 && c
== 'L')
10117 mask
&= ~ (7 << 3);
10120 else if (freg
&& reg1
== 0 && reg2
== 1 && c
== 'L')
10122 mask
&= ~ (7 << 3);
10125 else if (reg1
== 4 && reg2
>= 4 && reg2
<= 7 && c
!= 'L')
10126 mask
|= (reg2
- 3) << 3;
10127 else if (reg1
== 16 && reg2
>= 16 && reg2
<= 17)
10128 mask
|= (reg2
- 15) << 1;
10129 else if (reg1
== RA
&& reg2
== RA
)
10133 as_bad (_("invalid register list"));
10137 /* The mask is filled in in the opcode table for the
10138 benefit of the disassembler. We remove it before
10139 applying the actual mask. */
10140 ip
->insn_opcode
&= ~ ((7 << 3) << MIPS16OP_SH_IMM6
);
10141 ip
->insn_opcode
|= mask
<< MIPS16OP_SH_IMM6
;
10145 case 'm': /* Register list for save insn. */
10146 case 'M': /* Register list for restore insn. */
10149 int framesz
= 0, seen_framesz
= 0;
10150 int args
= 0, statics
= 0, sregs
= 0;
10154 unsigned int reg1
, reg2
;
10156 SKIP_SPACE_TABS (s
);
10159 SKIP_SPACE_TABS (s
);
10161 my_getExpression (&imm_expr
, s
);
10162 if (imm_expr
.X_op
== O_constant
)
10164 /* Handle the frame size. */
10167 as_bad (_("more than one frame size in list"));
10171 framesz
= imm_expr
.X_add_number
;
10172 imm_expr
.X_op
= O_absent
;
10177 if (! reg_lookup (&s
, RTYPE_GP
| RTYPE_NUM
, ®1
))
10179 as_bad (_("can't parse register list"));
10191 if (! reg_lookup (&s
, RTYPE_GP
| RTYPE_NUM
, ®2
)
10194 as_bad (_("can't parse register list"));
10199 while (reg1
<= reg2
)
10201 if (reg1
>= 4 && reg1
<= 7)
10205 args
|= 1 << (reg1
- 4);
10207 /* statics $a0-$a3 */
10208 statics
|= 1 << (reg1
- 4);
10210 else if ((reg1
>= 16 && reg1
<= 23) || reg1
== 30)
10213 sregs
|= 1 << ((reg1
== 30) ? 8 : (reg1
- 16));
10215 else if (reg1
== 31)
10217 /* Add $ra to insn. */
10222 as_bad (_("unexpected register in list"));
10230 /* Encode args/statics combination. */
10231 if (args
& statics
)
10232 as_bad (_("arg/static registers overlap"));
10233 else if (args
== 0xf)
10234 /* All $a0-$a3 are args. */
10235 opcode
|= MIPS16_ALL_ARGS
<< 16;
10236 else if (statics
== 0xf)
10237 /* All $a0-$a3 are statics. */
10238 opcode
|= MIPS16_ALL_STATICS
<< 16;
10241 int narg
= 0, nstat
= 0;
10243 /* Count arg registers. */
10250 as_bad (_("invalid arg register list"));
10252 /* Count static registers. */
10253 while (statics
& 0x8)
10255 statics
= (statics
<< 1) & 0xf;
10259 as_bad (_("invalid static register list"));
10261 /* Encode args/statics. */
10262 opcode
|= ((narg
<< 2) | nstat
) << 16;
10265 /* Encode $s0/$s1. */
10266 if (sregs
& (1 << 0)) /* $s0 */
10268 if (sregs
& (1 << 1)) /* $s1 */
10274 /* Count regs $s2-$s8. */
10282 as_bad (_("invalid static register list"));
10283 /* Encode $s2-$s8. */
10284 opcode
|= nsreg
<< 24;
10287 /* Encode frame size. */
10289 as_bad (_("missing frame size"));
10290 else if ((framesz
& 7) != 0 || framesz
< 0
10291 || framesz
> 0xff * 8)
10292 as_bad (_("invalid frame size"));
10293 else if (framesz
!= 128 || (opcode
>> 16) != 0)
10296 opcode
|= (((framesz
& 0xf0) << 16)
10297 | (framesz
& 0x0f));
10300 /* Finally build the instruction. */
10301 if ((opcode
>> 16) != 0 || framesz
== 0)
10303 ip
->use_extend
= TRUE
;
10304 ip
->extend
= opcode
>> 16;
10306 ip
->insn_opcode
|= opcode
& 0x7f;
10310 case 'e': /* extend code */
10311 my_getExpression (&imm_expr
, s
);
10312 check_absolute_expr (ip
, &imm_expr
);
10313 if ((unsigned long) imm_expr
.X_add_number
> 0x7ff)
10315 as_warn (_("Invalid value for `%s' (%lu)"),
10317 (unsigned long) imm_expr
.X_add_number
);
10318 imm_expr
.X_add_number
&= 0x7ff;
10320 ip
->insn_opcode
|= imm_expr
.X_add_number
;
10321 imm_expr
.X_op
= O_absent
;
10331 /* Args don't match. */
10332 if (insn
+ 1 < &mips16_opcodes
[bfd_mips16_num_opcodes
] &&
10333 strcmp (insn
->name
, insn
[1].name
) == 0)
10340 insn_error
= _("illegal operands");
10346 /* This structure holds information we know about a mips16 immediate
10349 struct mips16_immed_operand
10351 /* The type code used in the argument string in the opcode table. */
10353 /* The number of bits in the short form of the opcode. */
10355 /* The number of bits in the extended form of the opcode. */
10357 /* The amount by which the short form is shifted when it is used;
10358 for example, the sw instruction has a shift count of 2. */
10360 /* The amount by which the short form is shifted when it is stored
10361 into the instruction code. */
10363 /* Non-zero if the short form is unsigned. */
10365 /* Non-zero if the extended form is unsigned. */
10367 /* Non-zero if the value is PC relative. */
10371 /* The mips16 immediate operand types. */
10373 static const struct mips16_immed_operand mips16_immed_operands
[] =
10375 { '<', 3, 5, 0, MIPS16OP_SH_RZ
, 1, 1, 0 },
10376 { '>', 3, 5, 0, MIPS16OP_SH_RX
, 1, 1, 0 },
10377 { '[', 3, 6, 0, MIPS16OP_SH_RZ
, 1, 1, 0 },
10378 { ']', 3, 6, 0, MIPS16OP_SH_RX
, 1, 1, 0 },
10379 { '4', 4, 15, 0, MIPS16OP_SH_IMM4
, 0, 0, 0 },
10380 { '5', 5, 16, 0, MIPS16OP_SH_IMM5
, 1, 0, 0 },
10381 { 'H', 5, 16, 1, MIPS16OP_SH_IMM5
, 1, 0, 0 },
10382 { 'W', 5, 16, 2, MIPS16OP_SH_IMM5
, 1, 0, 0 },
10383 { 'D', 5, 16, 3, MIPS16OP_SH_IMM5
, 1, 0, 0 },
10384 { 'j', 5, 16, 0, MIPS16OP_SH_IMM5
, 0, 0, 0 },
10385 { '8', 8, 16, 0, MIPS16OP_SH_IMM8
, 1, 0, 0 },
10386 { 'V', 8, 16, 2, MIPS16OP_SH_IMM8
, 1, 0, 0 },
10387 { 'C', 8, 16, 3, MIPS16OP_SH_IMM8
, 1, 0, 0 },
10388 { 'U', 8, 16, 0, MIPS16OP_SH_IMM8
, 1, 1, 0 },
10389 { 'k', 8, 16, 0, MIPS16OP_SH_IMM8
, 0, 0, 0 },
10390 { 'K', 8, 16, 3, MIPS16OP_SH_IMM8
, 0, 0, 0 },
10391 { 'p', 8, 16, 0, MIPS16OP_SH_IMM8
, 0, 0, 1 },
10392 { 'q', 11, 16, 0, MIPS16OP_SH_IMM8
, 0, 0, 1 },
10393 { 'A', 8, 16, 2, MIPS16OP_SH_IMM8
, 1, 0, 1 },
10394 { 'B', 5, 16, 3, MIPS16OP_SH_IMM5
, 1, 0, 1 },
10395 { 'E', 5, 16, 2, MIPS16OP_SH_IMM5
, 1, 0, 1 }
10398 #define MIPS16_NUM_IMMED \
10399 (sizeof mips16_immed_operands / sizeof mips16_immed_operands[0])
10401 /* Handle a mips16 instruction with an immediate value. This or's the
10402 small immediate value into *INSN. It sets *USE_EXTEND to indicate
10403 whether an extended value is needed; if one is needed, it sets
10404 *EXTEND to the value. The argument type is TYPE. The value is VAL.
10405 If SMALL is true, an unextended opcode was explicitly requested.
10406 If EXT is true, an extended opcode was explicitly requested. If
10407 WARN is true, warn if EXT does not match reality. */
10410 mips16_immed (char *file
, unsigned int line
, int type
, offsetT val
,
10411 bfd_boolean warn
, bfd_boolean small
, bfd_boolean ext
,
10412 unsigned long *insn
, bfd_boolean
*use_extend
,
10413 unsigned short *extend
)
10415 const struct mips16_immed_operand
*op
;
10416 int mintiny
, maxtiny
;
10417 bfd_boolean needext
;
10419 op
= mips16_immed_operands
;
10420 while (op
->type
!= type
)
10423 assert (op
< mips16_immed_operands
+ MIPS16_NUM_IMMED
);
10428 if (type
== '<' || type
== '>' || type
== '[' || type
== ']')
10431 maxtiny
= 1 << op
->nbits
;
10436 maxtiny
= (1 << op
->nbits
) - 1;
10441 mintiny
= - (1 << (op
->nbits
- 1));
10442 maxtiny
= (1 << (op
->nbits
- 1)) - 1;
10445 /* Branch offsets have an implicit 0 in the lowest bit. */
10446 if (type
== 'p' || type
== 'q')
10449 if ((val
& ((1 << op
->shift
) - 1)) != 0
10450 || val
< (mintiny
<< op
->shift
)
10451 || val
> (maxtiny
<< op
->shift
))
10456 if (warn
&& ext
&& ! needext
)
10457 as_warn_where (file
, line
,
10458 _("extended operand requested but not required"));
10459 if (small
&& needext
)
10460 as_bad_where (file
, line
, _("invalid unextended operand value"));
10462 if (small
|| (! ext
&& ! needext
))
10466 *use_extend
= FALSE
;
10467 insnval
= ((val
>> op
->shift
) & ((1 << op
->nbits
) - 1));
10468 insnval
<<= op
->op_shift
;
10473 long minext
, maxext
;
10479 maxext
= (1 << op
->extbits
) - 1;
10483 minext
= - (1 << (op
->extbits
- 1));
10484 maxext
= (1 << (op
->extbits
- 1)) - 1;
10486 if (val
< minext
|| val
> maxext
)
10487 as_bad_where (file
, line
,
10488 _("operand value out of range for instruction"));
10490 *use_extend
= TRUE
;
10491 if (op
->extbits
== 16)
10493 extval
= ((val
>> 11) & 0x1f) | (val
& 0x7e0);
10496 else if (op
->extbits
== 15)
10498 extval
= ((val
>> 11) & 0xf) | (val
& 0x7f0);
10503 extval
= ((val
& 0x1f) << 6) | (val
& 0x20);
10507 *extend
= (unsigned short) extval
;
10512 struct percent_op_match
10515 bfd_reloc_code_real_type reloc
;
10518 static const struct percent_op_match mips_percent_op
[] =
10520 {"%lo", BFD_RELOC_LO16
},
10522 {"%call_hi", BFD_RELOC_MIPS_CALL_HI16
},
10523 {"%call_lo", BFD_RELOC_MIPS_CALL_LO16
},
10524 {"%call16", BFD_RELOC_MIPS_CALL16
},
10525 {"%got_disp", BFD_RELOC_MIPS_GOT_DISP
},
10526 {"%got_page", BFD_RELOC_MIPS_GOT_PAGE
},
10527 {"%got_ofst", BFD_RELOC_MIPS_GOT_OFST
},
10528 {"%got_hi", BFD_RELOC_MIPS_GOT_HI16
},
10529 {"%got_lo", BFD_RELOC_MIPS_GOT_LO16
},
10530 {"%got", BFD_RELOC_MIPS_GOT16
},
10531 {"%gp_rel", BFD_RELOC_GPREL16
},
10532 {"%half", BFD_RELOC_16
},
10533 {"%highest", BFD_RELOC_MIPS_HIGHEST
},
10534 {"%higher", BFD_RELOC_MIPS_HIGHER
},
10535 {"%neg", BFD_RELOC_MIPS_SUB
},
10536 {"%tlsgd", BFD_RELOC_MIPS_TLS_GD
},
10537 {"%tlsldm", BFD_RELOC_MIPS_TLS_LDM
},
10538 {"%dtprel_hi", BFD_RELOC_MIPS_TLS_DTPREL_HI16
},
10539 {"%dtprel_lo", BFD_RELOC_MIPS_TLS_DTPREL_LO16
},
10540 {"%tprel_hi", BFD_RELOC_MIPS_TLS_TPREL_HI16
},
10541 {"%tprel_lo", BFD_RELOC_MIPS_TLS_TPREL_LO16
},
10542 {"%gottprel", BFD_RELOC_MIPS_TLS_GOTTPREL
},
10544 {"%hi", BFD_RELOC_HI16_S
}
10547 static const struct percent_op_match mips16_percent_op
[] =
10549 {"%lo", BFD_RELOC_MIPS16_LO16
},
10550 {"%gprel", BFD_RELOC_MIPS16_GPREL
},
10551 {"%hi", BFD_RELOC_MIPS16_HI16_S
}
10555 /* Return true if *STR points to a relocation operator. When returning true,
10556 move *STR over the operator and store its relocation code in *RELOC.
10557 Leave both *STR and *RELOC alone when returning false. */
10560 parse_relocation (char **str
, bfd_reloc_code_real_type
*reloc
)
10562 const struct percent_op_match
*percent_op
;
10565 if (mips_opts
.mips16
)
10567 percent_op
= mips16_percent_op
;
10568 limit
= ARRAY_SIZE (mips16_percent_op
);
10572 percent_op
= mips_percent_op
;
10573 limit
= ARRAY_SIZE (mips_percent_op
);
10576 for (i
= 0; i
< limit
; i
++)
10577 if (strncasecmp (*str
, percent_op
[i
].str
, strlen (percent_op
[i
].str
)) == 0)
10579 int len
= strlen (percent_op
[i
].str
);
10581 if (!ISSPACE ((*str
)[len
]) && (*str
)[len
] != '(')
10584 *str
+= strlen (percent_op
[i
].str
);
10585 *reloc
= percent_op
[i
].reloc
;
10587 /* Check whether the output BFD supports this relocation.
10588 If not, issue an error and fall back on something safe. */
10589 if (!bfd_reloc_type_lookup (stdoutput
, percent_op
[i
].reloc
))
10591 as_bad ("relocation %s isn't supported by the current ABI",
10592 percent_op
[i
].str
);
10593 *reloc
= BFD_RELOC_UNUSED
;
10601 /* Parse string STR as a 16-bit relocatable operand. Store the
10602 expression in *EP and the relocations in the array starting
10603 at RELOC. Return the number of relocation operators used.
10605 On exit, EXPR_END points to the first character after the expression. */
10608 my_getSmallExpression (expressionS
*ep
, bfd_reloc_code_real_type
*reloc
,
10611 bfd_reloc_code_real_type reversed_reloc
[3];
10612 size_t reloc_index
, i
;
10613 int crux_depth
, str_depth
;
10616 /* Search for the start of the main expression, recoding relocations
10617 in REVERSED_RELOC. End the loop with CRUX pointing to the start
10618 of the main expression and with CRUX_DEPTH containing the number
10619 of open brackets at that point. */
10626 crux_depth
= str_depth
;
10628 /* Skip over whitespace and brackets, keeping count of the number
10630 while (*str
== ' ' || *str
== '\t' || *str
== '(')
10635 && reloc_index
< (HAVE_NEWABI
? 3 : 1)
10636 && parse_relocation (&str
, &reversed_reloc
[reloc_index
]));
10638 my_getExpression (ep
, crux
);
10641 /* Match every open bracket. */
10642 while (crux_depth
> 0 && (*str
== ')' || *str
== ' ' || *str
== '\t'))
10646 if (crux_depth
> 0)
10647 as_bad ("unclosed '('");
10651 if (reloc_index
!= 0)
10653 prev_reloc_op_frag
= frag_now
;
10654 for (i
= 0; i
< reloc_index
; i
++)
10655 reloc
[i
] = reversed_reloc
[reloc_index
- 1 - i
];
10658 return reloc_index
;
10662 my_getExpression (expressionS
*ep
, char *str
)
10667 save_in
= input_line_pointer
;
10668 input_line_pointer
= str
;
10670 expr_end
= input_line_pointer
;
10671 input_line_pointer
= save_in
;
10673 /* If we are in mips16 mode, and this is an expression based on `.',
10674 then we bump the value of the symbol by 1 since that is how other
10675 text symbols are handled. We don't bother to handle complex
10676 expressions, just `.' plus or minus a constant. */
10677 if (mips_opts
.mips16
10678 && ep
->X_op
== O_symbol
10679 && strcmp (S_GET_NAME (ep
->X_add_symbol
), FAKE_LABEL_NAME
) == 0
10680 && S_GET_SEGMENT (ep
->X_add_symbol
) == now_seg
10681 && symbol_get_frag (ep
->X_add_symbol
) == frag_now
10682 && symbol_constant_p (ep
->X_add_symbol
)
10683 && (val
= S_GET_VALUE (ep
->X_add_symbol
)) == frag_now_fix ())
10684 S_SET_VALUE (ep
->X_add_symbol
, val
+ 1);
10687 /* Turn a string in input_line_pointer into a floating point constant
10688 of type TYPE, and store the appropriate bytes in *LITP. The number
10689 of LITTLENUMS emitted is stored in *SIZEP. An error message is
10690 returned, or NULL on OK. */
10693 md_atof (int type
, char *litP
, int *sizeP
)
10696 LITTLENUM_TYPE words
[4];
10712 return _("bad call to md_atof");
10715 t
= atof_ieee (input_line_pointer
, type
, words
);
10717 input_line_pointer
= t
;
10721 if (! target_big_endian
)
10723 for (i
= prec
- 1; i
>= 0; i
--)
10725 md_number_to_chars (litP
, words
[i
], 2);
10731 for (i
= 0; i
< prec
; i
++)
10733 md_number_to_chars (litP
, words
[i
], 2);
10742 md_number_to_chars (char *buf
, valueT val
, int n
)
10744 if (target_big_endian
)
10745 number_to_chars_bigendian (buf
, val
, n
);
10747 number_to_chars_littleendian (buf
, val
, n
);
10751 static int support_64bit_objects(void)
10753 const char **list
, **l
;
10756 list
= bfd_target_list ();
10757 for (l
= list
; *l
!= NULL
; l
++)
10759 /* This is traditional mips */
10760 if (strcmp (*l
, "elf64-tradbigmips") == 0
10761 || strcmp (*l
, "elf64-tradlittlemips") == 0)
10763 if (strcmp (*l
, "elf64-bigmips") == 0
10764 || strcmp (*l
, "elf64-littlemips") == 0)
10767 yes
= (*l
!= NULL
);
10771 #endif /* OBJ_ELF */
10773 const char *md_shortopts
= "O::g::G:";
10775 struct option md_longopts
[] =
10777 /* Options which specify architecture. */
10778 #define OPTION_ARCH_BASE (OPTION_MD_BASE)
10779 #define OPTION_MARCH (OPTION_ARCH_BASE + 0)
10780 {"march", required_argument
, NULL
, OPTION_MARCH
},
10781 #define OPTION_MTUNE (OPTION_ARCH_BASE + 1)
10782 {"mtune", required_argument
, NULL
, OPTION_MTUNE
},
10783 #define OPTION_MIPS1 (OPTION_ARCH_BASE + 2)
10784 {"mips0", no_argument
, NULL
, OPTION_MIPS1
},
10785 {"mips1", no_argument
, NULL
, OPTION_MIPS1
},
10786 #define OPTION_MIPS2 (OPTION_ARCH_BASE + 3)
10787 {"mips2", no_argument
, NULL
, OPTION_MIPS2
},
10788 #define OPTION_MIPS3 (OPTION_ARCH_BASE + 4)
10789 {"mips3", no_argument
, NULL
, OPTION_MIPS3
},
10790 #define OPTION_MIPS4 (OPTION_ARCH_BASE + 5)
10791 {"mips4", no_argument
, NULL
, OPTION_MIPS4
},
10792 #define OPTION_MIPS5 (OPTION_ARCH_BASE + 6)
10793 {"mips5", no_argument
, NULL
, OPTION_MIPS5
},
10794 #define OPTION_MIPS32 (OPTION_ARCH_BASE + 7)
10795 {"mips32", no_argument
, NULL
, OPTION_MIPS32
},
10796 #define OPTION_MIPS64 (OPTION_ARCH_BASE + 8)
10797 {"mips64", no_argument
, NULL
, OPTION_MIPS64
},
10798 #define OPTION_MIPS32R2 (OPTION_ARCH_BASE + 9)
10799 {"mips32r2", no_argument
, NULL
, OPTION_MIPS32R2
},
10800 #define OPTION_MIPS64R2 (OPTION_ARCH_BASE + 10)
10801 {"mips64r2", no_argument
, NULL
, OPTION_MIPS64R2
},
10803 /* Options which specify Application Specific Extensions (ASEs). */
10804 #define OPTION_ASE_BASE (OPTION_ARCH_BASE + 11)
10805 #define OPTION_MIPS16 (OPTION_ASE_BASE + 0)
10806 {"mips16", no_argument
, NULL
, OPTION_MIPS16
},
10807 #define OPTION_NO_MIPS16 (OPTION_ASE_BASE + 1)
10808 {"no-mips16", no_argument
, NULL
, OPTION_NO_MIPS16
},
10809 #define OPTION_MIPS3D (OPTION_ASE_BASE + 2)
10810 {"mips3d", no_argument
, NULL
, OPTION_MIPS3D
},
10811 #define OPTION_NO_MIPS3D (OPTION_ASE_BASE + 3)
10812 {"no-mips3d", no_argument
, NULL
, OPTION_NO_MIPS3D
},
10813 #define OPTION_MDMX (OPTION_ASE_BASE + 4)
10814 {"mdmx", no_argument
, NULL
, OPTION_MDMX
},
10815 #define OPTION_NO_MDMX (OPTION_ASE_BASE + 5)
10816 {"no-mdmx", no_argument
, NULL
, OPTION_NO_MDMX
},
10817 #define OPTION_DSP (OPTION_ASE_BASE + 6)
10818 {"mdsp", no_argument
, NULL
, OPTION_DSP
},
10819 #define OPTION_NO_DSP (OPTION_ASE_BASE + 7)
10820 {"mno-dsp", no_argument
, NULL
, OPTION_NO_DSP
},
10821 #define OPTION_MT (OPTION_ASE_BASE + 8)
10822 {"mmt", no_argument
, NULL
, OPTION_MT
},
10823 #define OPTION_NO_MT (OPTION_ASE_BASE + 9)
10824 {"mno-mt", no_argument
, NULL
, OPTION_NO_MT
},
10825 #define OPTION_SMARTMIPS (OPTION_ASE_BASE + 10)
10826 {"msmartmips", no_argument
, NULL
, OPTION_SMARTMIPS
},
10827 #define OPTION_NO_SMARTMIPS (OPTION_ASE_BASE + 11)
10828 {"mno-smartmips", no_argument
, NULL
, OPTION_NO_SMARTMIPS
},
10830 /* Old-style architecture options. Don't add more of these. */
10831 #define OPTION_COMPAT_ARCH_BASE (OPTION_ASE_BASE + 12)
10832 #define OPTION_M4650 (OPTION_COMPAT_ARCH_BASE + 0)
10833 {"m4650", no_argument
, NULL
, OPTION_M4650
},
10834 #define OPTION_NO_M4650 (OPTION_COMPAT_ARCH_BASE + 1)
10835 {"no-m4650", no_argument
, NULL
, OPTION_NO_M4650
},
10836 #define OPTION_M4010 (OPTION_COMPAT_ARCH_BASE + 2)
10837 {"m4010", no_argument
, NULL
, OPTION_M4010
},
10838 #define OPTION_NO_M4010 (OPTION_COMPAT_ARCH_BASE + 3)
10839 {"no-m4010", no_argument
, NULL
, OPTION_NO_M4010
},
10840 #define OPTION_M4100 (OPTION_COMPAT_ARCH_BASE + 4)
10841 {"m4100", no_argument
, NULL
, OPTION_M4100
},
10842 #define OPTION_NO_M4100 (OPTION_COMPAT_ARCH_BASE + 5)
10843 {"no-m4100", no_argument
, NULL
, OPTION_NO_M4100
},
10844 #define OPTION_M3900 (OPTION_COMPAT_ARCH_BASE + 6)
10845 {"m3900", no_argument
, NULL
, OPTION_M3900
},
10846 #define OPTION_NO_M3900 (OPTION_COMPAT_ARCH_BASE + 7)
10847 {"no-m3900", no_argument
, NULL
, OPTION_NO_M3900
},
10849 /* Options which enable bug fixes. */
10850 #define OPTION_FIX_BASE (OPTION_COMPAT_ARCH_BASE + 8)
10851 #define OPTION_M7000_HILO_FIX (OPTION_FIX_BASE + 0)
10852 {"mfix7000", no_argument
, NULL
, OPTION_M7000_HILO_FIX
},
10853 #define OPTION_MNO_7000_HILO_FIX (OPTION_FIX_BASE + 1)
10854 {"no-fix-7000", no_argument
, NULL
, OPTION_MNO_7000_HILO_FIX
},
10855 {"mno-fix7000", no_argument
, NULL
, OPTION_MNO_7000_HILO_FIX
},
10856 #define OPTION_FIX_VR4120 (OPTION_FIX_BASE + 2)
10857 #define OPTION_NO_FIX_VR4120 (OPTION_FIX_BASE + 3)
10858 {"mfix-vr4120", no_argument
, NULL
, OPTION_FIX_VR4120
},
10859 {"mno-fix-vr4120", no_argument
, NULL
, OPTION_NO_FIX_VR4120
},
10860 #define OPTION_FIX_VR4130 (OPTION_FIX_BASE + 4)
10861 #define OPTION_NO_FIX_VR4130 (OPTION_FIX_BASE + 5)
10862 {"mfix-vr4130", no_argument
, NULL
, OPTION_FIX_VR4130
},
10863 {"mno-fix-vr4130", no_argument
, NULL
, OPTION_NO_FIX_VR4130
},
10865 /* Miscellaneous options. */
10866 #define OPTION_MISC_BASE (OPTION_FIX_BASE + 6)
10867 #define OPTION_TRAP (OPTION_MISC_BASE + 0)
10868 {"trap", no_argument
, NULL
, OPTION_TRAP
},
10869 {"no-break", no_argument
, NULL
, OPTION_TRAP
},
10870 #define OPTION_BREAK (OPTION_MISC_BASE + 1)
10871 {"break", no_argument
, NULL
, OPTION_BREAK
},
10872 {"no-trap", no_argument
, NULL
, OPTION_BREAK
},
10873 #define OPTION_EB (OPTION_MISC_BASE + 2)
10874 {"EB", no_argument
, NULL
, OPTION_EB
},
10875 #define OPTION_EL (OPTION_MISC_BASE + 3)
10876 {"EL", no_argument
, NULL
, OPTION_EL
},
10877 #define OPTION_FP32 (OPTION_MISC_BASE + 4)
10878 {"mfp32", no_argument
, NULL
, OPTION_FP32
},
10879 #define OPTION_GP32 (OPTION_MISC_BASE + 5)
10880 {"mgp32", no_argument
, NULL
, OPTION_GP32
},
10881 #define OPTION_CONSTRUCT_FLOATS (OPTION_MISC_BASE + 6)
10882 {"construct-floats", no_argument
, NULL
, OPTION_CONSTRUCT_FLOATS
},
10883 #define OPTION_NO_CONSTRUCT_FLOATS (OPTION_MISC_BASE + 7)
10884 {"no-construct-floats", no_argument
, NULL
, OPTION_NO_CONSTRUCT_FLOATS
},
10885 #define OPTION_FP64 (OPTION_MISC_BASE + 8)
10886 {"mfp64", no_argument
, NULL
, OPTION_FP64
},
10887 #define OPTION_GP64 (OPTION_MISC_BASE + 9)
10888 {"mgp64", no_argument
, NULL
, OPTION_GP64
},
10889 #define OPTION_RELAX_BRANCH (OPTION_MISC_BASE + 10)
10890 #define OPTION_NO_RELAX_BRANCH (OPTION_MISC_BASE + 11)
10891 {"relax-branch", no_argument
, NULL
, OPTION_RELAX_BRANCH
},
10892 {"no-relax-branch", no_argument
, NULL
, OPTION_NO_RELAX_BRANCH
},
10893 #define OPTION_MSHARED (OPTION_MISC_BASE + 12)
10894 #define OPTION_MNO_SHARED (OPTION_MISC_BASE + 13)
10895 {"mshared", no_argument
, NULL
, OPTION_MSHARED
},
10896 {"mno-shared", no_argument
, NULL
, OPTION_MNO_SHARED
},
10897 #define OPTION_MSYM32 (OPTION_MISC_BASE + 14)
10898 #define OPTION_MNO_SYM32 (OPTION_MISC_BASE + 15)
10899 {"msym32", no_argument
, NULL
, OPTION_MSYM32
},
10900 {"mno-sym32", no_argument
, NULL
, OPTION_MNO_SYM32
},
10902 /* ELF-specific options. */
10904 #define OPTION_ELF_BASE (OPTION_MISC_BASE + 16)
10905 #define OPTION_CALL_SHARED (OPTION_ELF_BASE + 0)
10906 {"KPIC", no_argument
, NULL
, OPTION_CALL_SHARED
},
10907 {"call_shared", no_argument
, NULL
, OPTION_CALL_SHARED
},
10908 #define OPTION_NON_SHARED (OPTION_ELF_BASE + 1)
10909 {"non_shared", no_argument
, NULL
, OPTION_NON_SHARED
},
10910 #define OPTION_XGOT (OPTION_ELF_BASE + 2)
10911 {"xgot", no_argument
, NULL
, OPTION_XGOT
},
10912 #define OPTION_MABI (OPTION_ELF_BASE + 3)
10913 {"mabi", required_argument
, NULL
, OPTION_MABI
},
10914 #define OPTION_32 (OPTION_ELF_BASE + 4)
10915 {"32", no_argument
, NULL
, OPTION_32
},
10916 #define OPTION_N32 (OPTION_ELF_BASE + 5)
10917 {"n32", no_argument
, NULL
, OPTION_N32
},
10918 #define OPTION_64 (OPTION_ELF_BASE + 6)
10919 {"64", no_argument
, NULL
, OPTION_64
},
10920 #define OPTION_MDEBUG (OPTION_ELF_BASE + 7)
10921 {"mdebug", no_argument
, NULL
, OPTION_MDEBUG
},
10922 #define OPTION_NO_MDEBUG (OPTION_ELF_BASE + 8)
10923 {"no-mdebug", no_argument
, NULL
, OPTION_NO_MDEBUG
},
10924 #define OPTION_PDR (OPTION_ELF_BASE + 9)
10925 {"mpdr", no_argument
, NULL
, OPTION_PDR
},
10926 #define OPTION_NO_PDR (OPTION_ELF_BASE + 10)
10927 {"mno-pdr", no_argument
, NULL
, OPTION_NO_PDR
},
10928 #define OPTION_MVXWORKS_PIC (OPTION_ELF_BASE + 11)
10929 {"mvxworks-pic", no_argument
, NULL
, OPTION_MVXWORKS_PIC
},
10930 #endif /* OBJ_ELF */
10932 {NULL
, no_argument
, NULL
, 0}
10934 size_t md_longopts_size
= sizeof (md_longopts
);
10936 /* Set STRING_PTR (either &mips_arch_string or &mips_tune_string) to
10937 NEW_VALUE. Warn if another value was already specified. Note:
10938 we have to defer parsing the -march and -mtune arguments in order
10939 to handle 'from-abi' correctly, since the ABI might be specified
10940 in a later argument. */
10943 mips_set_option_string (const char **string_ptr
, const char *new_value
)
10945 if (*string_ptr
!= 0 && strcasecmp (*string_ptr
, new_value
) != 0)
10946 as_warn (_("A different %s was already specified, is now %s"),
10947 string_ptr
== &mips_arch_string
? "-march" : "-mtune",
10950 *string_ptr
= new_value
;
10954 md_parse_option (int c
, char *arg
)
10958 case OPTION_CONSTRUCT_FLOATS
:
10959 mips_disable_float_construction
= 0;
10962 case OPTION_NO_CONSTRUCT_FLOATS
:
10963 mips_disable_float_construction
= 1;
10975 target_big_endian
= 1;
10979 target_big_endian
= 0;
10983 if (arg
&& arg
[1] == '0')
10993 mips_debug
= atoi (arg
);
10997 file_mips_isa
= ISA_MIPS1
;
11001 file_mips_isa
= ISA_MIPS2
;
11005 file_mips_isa
= ISA_MIPS3
;
11009 file_mips_isa
= ISA_MIPS4
;
11013 file_mips_isa
= ISA_MIPS5
;
11016 case OPTION_MIPS32
:
11017 file_mips_isa
= ISA_MIPS32
;
11020 case OPTION_MIPS32R2
:
11021 file_mips_isa
= ISA_MIPS32R2
;
11024 case OPTION_MIPS64R2
:
11025 file_mips_isa
= ISA_MIPS64R2
;
11028 case OPTION_MIPS64
:
11029 file_mips_isa
= ISA_MIPS64
;
11033 mips_set_option_string (&mips_tune_string
, arg
);
11037 mips_set_option_string (&mips_arch_string
, arg
);
11041 mips_set_option_string (&mips_arch_string
, "4650");
11042 mips_set_option_string (&mips_tune_string
, "4650");
11045 case OPTION_NO_M4650
:
11049 mips_set_option_string (&mips_arch_string
, "4010");
11050 mips_set_option_string (&mips_tune_string
, "4010");
11053 case OPTION_NO_M4010
:
11057 mips_set_option_string (&mips_arch_string
, "4100");
11058 mips_set_option_string (&mips_tune_string
, "4100");
11061 case OPTION_NO_M4100
:
11065 mips_set_option_string (&mips_arch_string
, "3900");
11066 mips_set_option_string (&mips_tune_string
, "3900");
11069 case OPTION_NO_M3900
:
11073 mips_opts
.ase_mdmx
= 1;
11076 case OPTION_NO_MDMX
:
11077 mips_opts
.ase_mdmx
= 0;
11081 mips_opts
.ase_dsp
= 1;
11084 case OPTION_NO_DSP
:
11085 mips_opts
.ase_dsp
= 0;
11089 mips_opts
.ase_mt
= 1;
11093 mips_opts
.ase_mt
= 0;
11096 case OPTION_MIPS16
:
11097 mips_opts
.mips16
= 1;
11098 mips_no_prev_insn ();
11101 case OPTION_NO_MIPS16
:
11102 mips_opts
.mips16
= 0;
11103 mips_no_prev_insn ();
11106 case OPTION_MIPS3D
:
11107 mips_opts
.ase_mips3d
= 1;
11110 case OPTION_NO_MIPS3D
:
11111 mips_opts
.ase_mips3d
= 0;
11114 case OPTION_SMARTMIPS
:
11115 mips_opts
.ase_smartmips
= 1;
11118 case OPTION_NO_SMARTMIPS
:
11119 mips_opts
.ase_smartmips
= 0;
11122 case OPTION_FIX_VR4120
:
11123 mips_fix_vr4120
= 1;
11126 case OPTION_NO_FIX_VR4120
:
11127 mips_fix_vr4120
= 0;
11130 case OPTION_FIX_VR4130
:
11131 mips_fix_vr4130
= 1;
11134 case OPTION_NO_FIX_VR4130
:
11135 mips_fix_vr4130
= 0;
11138 case OPTION_RELAX_BRANCH
:
11139 mips_relax_branch
= 1;
11142 case OPTION_NO_RELAX_BRANCH
:
11143 mips_relax_branch
= 0;
11146 case OPTION_MSHARED
:
11147 mips_in_shared
= TRUE
;
11150 case OPTION_MNO_SHARED
:
11151 mips_in_shared
= FALSE
;
11154 case OPTION_MSYM32
:
11155 mips_opts
.sym32
= TRUE
;
11158 case OPTION_MNO_SYM32
:
11159 mips_opts
.sym32
= FALSE
;
11163 /* When generating ELF code, we permit -KPIC and -call_shared to
11164 select SVR4_PIC, and -non_shared to select no PIC. This is
11165 intended to be compatible with Irix 5. */
11166 case OPTION_CALL_SHARED
:
11169 as_bad (_("-call_shared is supported only for ELF format"));
11172 mips_pic
= SVR4_PIC
;
11173 mips_abicalls
= TRUE
;
11176 case OPTION_NON_SHARED
:
11179 as_bad (_("-non_shared is supported only for ELF format"));
11183 mips_abicalls
= FALSE
;
11186 /* The -xgot option tells the assembler to use 32 bit offsets
11187 when accessing the got in SVR4_PIC mode. It is for Irix
11192 #endif /* OBJ_ELF */
11195 g_switch_value
= atoi (arg
);
11200 /* The -32, -n32 and -64 options are shortcuts for -mabi=32, -mabi=n32
11205 as_bad (_("-32 is supported for ELF format only"));
11208 mips_abi
= O32_ABI
;
11214 as_bad (_("-n32 is supported for ELF format only"));
11217 mips_abi
= N32_ABI
;
11223 as_bad (_("-64 is supported for ELF format only"));
11226 mips_abi
= N64_ABI
;
11227 if (!support_64bit_objects())
11228 as_fatal (_("No compiled in support for 64 bit object file format"));
11230 #endif /* OBJ_ELF */
11233 file_mips_gp32
= 1;
11237 file_mips_gp32
= 0;
11241 file_mips_fp32
= 1;
11245 file_mips_fp32
= 0;
11252 as_bad (_("-mabi is supported for ELF format only"));
11255 if (strcmp (arg
, "32") == 0)
11256 mips_abi
= O32_ABI
;
11257 else if (strcmp (arg
, "o64") == 0)
11258 mips_abi
= O64_ABI
;
11259 else if (strcmp (arg
, "n32") == 0)
11260 mips_abi
= N32_ABI
;
11261 else if (strcmp (arg
, "64") == 0)
11263 mips_abi
= N64_ABI
;
11264 if (! support_64bit_objects())
11265 as_fatal (_("No compiled in support for 64 bit object file "
11268 else if (strcmp (arg
, "eabi") == 0)
11269 mips_abi
= EABI_ABI
;
11272 as_fatal (_("invalid abi -mabi=%s"), arg
);
11276 #endif /* OBJ_ELF */
11278 case OPTION_M7000_HILO_FIX
:
11279 mips_7000_hilo_fix
= TRUE
;
11282 case OPTION_MNO_7000_HILO_FIX
:
11283 mips_7000_hilo_fix
= FALSE
;
11287 case OPTION_MDEBUG
:
11288 mips_flag_mdebug
= TRUE
;
11291 case OPTION_NO_MDEBUG
:
11292 mips_flag_mdebug
= FALSE
;
11296 mips_flag_pdr
= TRUE
;
11299 case OPTION_NO_PDR
:
11300 mips_flag_pdr
= FALSE
;
11303 case OPTION_MVXWORKS_PIC
:
11304 mips_pic
= VXWORKS_PIC
;
11306 #endif /* OBJ_ELF */
11315 /* Set up globals to generate code for the ISA or processor
11316 described by INFO. */
11319 mips_set_architecture (const struct mips_cpu_info
*info
)
11323 file_mips_arch
= info
->cpu
;
11324 mips_opts
.arch
= info
->cpu
;
11325 mips_opts
.isa
= info
->isa
;
11330 /* Likewise for tuning. */
11333 mips_set_tune (const struct mips_cpu_info
*info
)
11336 mips_tune
= info
->cpu
;
11341 mips_after_parse_args (void)
11343 const struct mips_cpu_info
*arch_info
= 0;
11344 const struct mips_cpu_info
*tune_info
= 0;
11346 /* GP relative stuff not working for PE */
11347 if (strncmp (TARGET_OS
, "pe", 2) == 0)
11349 if (g_switch_seen
&& g_switch_value
!= 0)
11350 as_bad (_("-G not supported in this configuration."));
11351 g_switch_value
= 0;
11354 if (mips_abi
== NO_ABI
)
11355 mips_abi
= MIPS_DEFAULT_ABI
;
11357 /* The following code determines the architecture and register size.
11358 Similar code was added to GCC 3.3 (see override_options() in
11359 config/mips/mips.c). The GAS and GCC code should be kept in sync
11360 as much as possible. */
11362 if (mips_arch_string
!= 0)
11363 arch_info
= mips_parse_cpu ("-march", mips_arch_string
);
11365 if (file_mips_isa
!= ISA_UNKNOWN
)
11367 /* Handle -mipsN. At this point, file_mips_isa contains the
11368 ISA level specified by -mipsN, while arch_info->isa contains
11369 the -march selection (if any). */
11370 if (arch_info
!= 0)
11372 /* -march takes precedence over -mipsN, since it is more descriptive.
11373 There's no harm in specifying both as long as the ISA levels
11375 if (file_mips_isa
!= arch_info
->isa
)
11376 as_bad (_("-%s conflicts with the other architecture options, which imply -%s"),
11377 mips_cpu_info_from_isa (file_mips_isa
)->name
,
11378 mips_cpu_info_from_isa (arch_info
->isa
)->name
);
11381 arch_info
= mips_cpu_info_from_isa (file_mips_isa
);
11384 if (arch_info
== 0)
11385 arch_info
= mips_parse_cpu ("default CPU", MIPS_CPU_STRING_DEFAULT
);
11387 if (ABI_NEEDS_64BIT_REGS (mips_abi
) && !ISA_HAS_64BIT_REGS (arch_info
->isa
))
11388 as_bad ("-march=%s is not compatible with the selected ABI",
11391 mips_set_architecture (arch_info
);
11393 /* Optimize for file_mips_arch, unless -mtune selects a different processor. */
11394 if (mips_tune_string
!= 0)
11395 tune_info
= mips_parse_cpu ("-mtune", mips_tune_string
);
11397 if (tune_info
== 0)
11398 mips_set_tune (arch_info
);
11400 mips_set_tune (tune_info
);
11402 if (file_mips_gp32
>= 0)
11404 /* The user specified the size of the integer registers. Make sure
11405 it agrees with the ABI and ISA. */
11406 if (file_mips_gp32
== 0 && !ISA_HAS_64BIT_REGS (mips_opts
.isa
))
11407 as_bad (_("-mgp64 used with a 32-bit processor"));
11408 else if (file_mips_gp32
== 1 && ABI_NEEDS_64BIT_REGS (mips_abi
))
11409 as_bad (_("-mgp32 used with a 64-bit ABI"));
11410 else if (file_mips_gp32
== 0 && ABI_NEEDS_32BIT_REGS (mips_abi
))
11411 as_bad (_("-mgp64 used with a 32-bit ABI"));
11415 /* Infer the integer register size from the ABI and processor.
11416 Restrict ourselves to 32-bit registers if that's all the
11417 processor has, or if the ABI cannot handle 64-bit registers. */
11418 file_mips_gp32
= (ABI_NEEDS_32BIT_REGS (mips_abi
)
11419 || !ISA_HAS_64BIT_REGS (mips_opts
.isa
));
11422 switch (file_mips_fp32
)
11426 /* No user specified float register size.
11427 ??? GAS treats single-float processors as though they had 64-bit
11428 float registers (although it complains when double-precision
11429 instructions are used). As things stand, saying they have 32-bit
11430 registers would lead to spurious "register must be even" messages.
11431 So here we assume float registers are never smaller than the
11433 if (file_mips_gp32
== 0)
11434 /* 64-bit integer registers implies 64-bit float registers. */
11435 file_mips_fp32
= 0;
11436 else if ((mips_opts
.ase_mips3d
> 0 || mips_opts
.ase_mdmx
> 0)
11437 && ISA_HAS_64BIT_FPRS (mips_opts
.isa
))
11438 /* -mips3d and -mdmx imply 64-bit float registers, if possible. */
11439 file_mips_fp32
= 0;
11441 /* 32-bit float registers. */
11442 file_mips_fp32
= 1;
11445 /* The user specified the size of the float registers. Check if it
11446 agrees with the ABI and ISA. */
11448 if (!ISA_HAS_64BIT_FPRS (mips_opts
.isa
))
11449 as_bad (_("-mfp64 used with a 32-bit fpu"));
11450 else if (ABI_NEEDS_32BIT_REGS (mips_abi
)
11451 && !ISA_HAS_MXHC1 (mips_opts
.isa
))
11452 as_warn (_("-mfp64 used with a 32-bit ABI"));
11455 if (ABI_NEEDS_64BIT_REGS (mips_abi
))
11456 as_warn (_("-mfp32 used with a 64-bit ABI"));
11460 /* End of GCC-shared inference code. */
11462 /* This flag is set when we have a 64-bit capable CPU but use only
11463 32-bit wide registers. Note that EABI does not use it. */
11464 if (ISA_HAS_64BIT_REGS (mips_opts
.isa
)
11465 && ((mips_abi
== NO_ABI
&& file_mips_gp32
== 1)
11466 || mips_abi
== O32_ABI
))
11467 mips_32bitmode
= 1;
11469 if (mips_opts
.isa
== ISA_MIPS1
&& mips_trap
)
11470 as_bad (_("trap exception not supported at ISA 1"));
11472 /* If the selected architecture includes support for ASEs, enable
11473 generation of code for them. */
11474 if (mips_opts
.mips16
== -1)
11475 mips_opts
.mips16
= (CPU_HAS_MIPS16 (file_mips_arch
)) ? 1 : 0;
11476 if (mips_opts
.ase_mips3d
== -1)
11477 mips_opts
.ase_mips3d
= ((arch_info
->flags
& MIPS_CPU_ASE_MIPS3D
)
11478 && file_mips_fp32
== 0) ? 1 : 0;
11479 if (mips_opts
.ase_mips3d
&& file_mips_fp32
== 1)
11480 as_bad (_("-mfp32 used with -mips3d"));
11482 if (mips_opts
.ase_mdmx
== -1)
11483 mips_opts
.ase_mdmx
= ((arch_info
->flags
& MIPS_CPU_ASE_MDMX
)
11484 && file_mips_fp32
== 0) ? 1 : 0;
11485 if (mips_opts
.ase_mdmx
&& file_mips_fp32
== 1)
11486 as_bad (_("-mfp32 used with -mdmx"));
11488 if (mips_opts
.ase_smartmips
== -1)
11489 mips_opts
.ase_smartmips
= (arch_info
->flags
& MIPS_CPU_ASE_SMARTMIPS
) ? 1 : 0;
11490 if (mips_opts
.ase_smartmips
&& !ISA_SUPPORTS_SMARTMIPS
)
11491 as_warn ("%s ISA does not support SmartMIPS",
11492 mips_cpu_info_from_isa (mips_opts
.isa
)->name
);
11494 if (mips_opts
.ase_dsp
== -1)
11495 mips_opts
.ase_dsp
= (arch_info
->flags
& MIPS_CPU_ASE_DSP
) ? 1 : 0;
11496 if (mips_opts
.ase_dsp
&& !ISA_SUPPORTS_DSP_ASE
)
11497 as_warn ("%s ISA does not support DSP ASE",
11498 mips_cpu_info_from_isa (mips_opts
.isa
)->name
);
11500 if (mips_opts
.ase_mt
== -1)
11501 mips_opts
.ase_mt
= (arch_info
->flags
& MIPS_CPU_ASE_MT
) ? 1 : 0;
11502 if (mips_opts
.ase_mt
&& !ISA_SUPPORTS_MT_ASE
)
11503 as_warn ("%s ISA does not support MT ASE",
11504 mips_cpu_info_from_isa (mips_opts
.isa
)->name
);
11506 file_mips_isa
= mips_opts
.isa
;
11507 file_ase_mips16
= mips_opts
.mips16
;
11508 file_ase_mips3d
= mips_opts
.ase_mips3d
;
11509 file_ase_mdmx
= mips_opts
.ase_mdmx
;
11510 file_ase_smartmips
= mips_opts
.ase_smartmips
;
11511 file_ase_dsp
= mips_opts
.ase_dsp
;
11512 file_ase_mt
= mips_opts
.ase_mt
;
11513 mips_opts
.gp32
= file_mips_gp32
;
11514 mips_opts
.fp32
= file_mips_fp32
;
11516 if (mips_flag_mdebug
< 0)
11518 #ifdef OBJ_MAYBE_ECOFF
11519 if (OUTPUT_FLAVOR
== bfd_target_ecoff_flavour
)
11520 mips_flag_mdebug
= 1;
11522 #endif /* OBJ_MAYBE_ECOFF */
11523 mips_flag_mdebug
= 0;
11528 mips_init_after_args (void)
11530 /* initialize opcodes */
11531 bfd_mips_num_opcodes
= bfd_mips_num_builtin_opcodes
;
11532 mips_opcodes
= (struct mips_opcode
*) mips_builtin_opcodes
;
11536 md_pcrel_from (fixS
*fixP
)
11538 valueT addr
= fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
11539 switch (fixP
->fx_r_type
)
11541 case BFD_RELOC_16_PCREL_S2
:
11542 case BFD_RELOC_MIPS_JMP
:
11543 /* Return the address of the delay slot. */
11546 /* We have no relocation type for PC relative MIPS16 instructions. */
11547 if (fixP
->fx_addsy
&& S_GET_SEGMENT (fixP
->fx_addsy
) != now_seg
)
11548 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
11549 _("PC relative MIPS16 instruction references a different section"));
11554 /* This is called before the symbol table is processed. In order to
11555 work with gcc when using mips-tfile, we must keep all local labels.
11556 However, in other cases, we want to discard them. If we were
11557 called with -g, but we didn't see any debugging information, it may
11558 mean that gcc is smuggling debugging information through to
11559 mips-tfile, in which case we must generate all local labels. */
11562 mips_frob_file_before_adjust (void)
11564 #ifndef NO_ECOFF_DEBUGGING
11565 if (ECOFF_DEBUGGING
11567 && ! ecoff_debugging_seen
)
11568 flag_keep_locals
= 1;
11572 /* Sort any unmatched HI16 and GOT16 relocs so that they immediately precede
11573 the corresponding LO16 reloc. This is called before md_apply_fix and
11574 tc_gen_reloc. Unmatched relocs can only be generated by use of explicit
11575 relocation operators.
11577 For our purposes, a %lo() expression matches a %got() or %hi()
11580 (a) it refers to the same symbol; and
11581 (b) the offset applied in the %lo() expression is no lower than
11582 the offset applied in the %got() or %hi().
11584 (b) allows us to cope with code like:
11587 lh $4,%lo(foo+2)($4)
11589 ...which is legal on RELA targets, and has a well-defined behaviour
11590 if the user knows that adding 2 to "foo" will not induce a carry to
11593 When several %lo()s match a particular %got() or %hi(), we use the
11594 following rules to distinguish them:
11596 (1) %lo()s with smaller offsets are a better match than %lo()s with
11599 (2) %lo()s with no matching %got() or %hi() are better than those
11600 that already have a matching %got() or %hi().
11602 (3) later %lo()s are better than earlier %lo()s.
11604 These rules are applied in order.
11606 (1) means, among other things, that %lo()s with identical offsets are
11607 chosen if they exist.
11609 (2) means that we won't associate several high-part relocations with
11610 the same low-part relocation unless there's no alternative. Having
11611 several high parts for the same low part is a GNU extension; this rule
11612 allows careful users to avoid it.
11614 (3) is purely cosmetic. mips_hi_fixup_list is is in reverse order,
11615 with the last high-part relocation being at the front of the list.
11616 It therefore makes sense to choose the last matching low-part
11617 relocation, all other things being equal. It's also easier
11618 to code that way. */
11621 mips_frob_file (void)
11623 struct mips_hi_fixup
*l
;
11625 for (l
= mips_hi_fixup_list
; l
!= NULL
; l
= l
->next
)
11627 segment_info_type
*seginfo
;
11628 bfd_boolean matched_lo_p
;
11629 fixS
**hi_pos
, **lo_pos
, **pos
;
11631 assert (reloc_needs_lo_p (l
->fixp
->fx_r_type
));
11633 /* If a GOT16 relocation turns out to be against a global symbol,
11634 there isn't supposed to be a matching LO. */
11635 if (l
->fixp
->fx_r_type
== BFD_RELOC_MIPS_GOT16
11636 && !pic_need_relax (l
->fixp
->fx_addsy
, l
->seg
))
11639 /* Check quickly whether the next fixup happens to be a matching %lo. */
11640 if (fixup_has_matching_lo_p (l
->fixp
))
11643 seginfo
= seg_info (l
->seg
);
11645 /* Set HI_POS to the position of this relocation in the chain.
11646 Set LO_POS to the position of the chosen low-part relocation.
11647 MATCHED_LO_P is true on entry to the loop if *POS is a low-part
11648 relocation that matches an immediately-preceding high-part
11652 matched_lo_p
= FALSE
;
11653 for (pos
= &seginfo
->fix_root
; *pos
!= NULL
; pos
= &(*pos
)->fx_next
)
11655 if (*pos
== l
->fixp
)
11658 if (((*pos
)->fx_r_type
== BFD_RELOC_LO16
11659 || (*pos
)->fx_r_type
== BFD_RELOC_MIPS16_LO16
)
11660 && (*pos
)->fx_addsy
== l
->fixp
->fx_addsy
11661 && (*pos
)->fx_offset
>= l
->fixp
->fx_offset
11663 || (*pos
)->fx_offset
< (*lo_pos
)->fx_offset
11665 && (*pos
)->fx_offset
== (*lo_pos
)->fx_offset
)))
11668 matched_lo_p
= (reloc_needs_lo_p ((*pos
)->fx_r_type
)
11669 && fixup_has_matching_lo_p (*pos
));
11672 /* If we found a match, remove the high-part relocation from its
11673 current position and insert it before the low-part relocation.
11674 Make the offsets match so that fixup_has_matching_lo_p()
11677 We don't warn about unmatched high-part relocations since some
11678 versions of gcc have been known to emit dead "lui ...%hi(...)"
11680 if (lo_pos
!= NULL
)
11682 l
->fixp
->fx_offset
= (*lo_pos
)->fx_offset
;
11683 if (l
->fixp
->fx_next
!= *lo_pos
)
11685 *hi_pos
= l
->fixp
->fx_next
;
11686 l
->fixp
->fx_next
= *lo_pos
;
11693 /* We may have combined relocations without symbols in the N32/N64 ABI.
11694 We have to prevent gas from dropping them. */
11697 mips_force_relocation (fixS
*fixp
)
11699 if (generic_force_reloc (fixp
))
11703 && S_GET_SEGMENT (fixp
->fx_addsy
) == bfd_abs_section_ptr
11704 && (fixp
->fx_r_type
== BFD_RELOC_MIPS_SUB
11705 || fixp
->fx_r_type
== BFD_RELOC_HI16_S
11706 || fixp
->fx_r_type
== BFD_RELOC_LO16
))
11712 /* Apply a fixup to the object file. */
11715 md_apply_fix (fixS
*fixP
, valueT
*valP
, segT seg ATTRIBUTE_UNUSED
)
11719 reloc_howto_type
*howto
;
11721 /* We ignore generic BFD relocations we don't know about. */
11722 howto
= bfd_reloc_type_lookup (stdoutput
, fixP
->fx_r_type
);
11726 assert (fixP
->fx_size
== 4
11727 || fixP
->fx_r_type
== BFD_RELOC_16
11728 || fixP
->fx_r_type
== BFD_RELOC_64
11729 || fixP
->fx_r_type
== BFD_RELOC_CTOR
11730 || fixP
->fx_r_type
== BFD_RELOC_MIPS_SUB
11731 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
11732 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
);
11734 buf
= (bfd_byte
*) (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
);
11736 assert (!fixP
->fx_pcrel
|| fixP
->fx_r_type
== BFD_RELOC_16_PCREL_S2
);
11738 /* Don't treat parts of a composite relocation as done. There are two
11741 (1) The second and third parts will be against 0 (RSS_UNDEF) but
11742 should nevertheless be emitted if the first part is.
11744 (2) In normal usage, composite relocations are never assembly-time
11745 constants. The easiest way of dealing with the pathological
11746 exceptions is to generate a relocation against STN_UNDEF and
11747 leave everything up to the linker. */
11748 if (fixP
->fx_addsy
== NULL
&& !fixP
->fx_pcrel
&& fixP
->fx_tcbit
== 0)
11751 switch (fixP
->fx_r_type
)
11753 case BFD_RELOC_MIPS_TLS_GD
:
11754 case BFD_RELOC_MIPS_TLS_LDM
:
11755 case BFD_RELOC_MIPS_TLS_DTPREL_HI16
:
11756 case BFD_RELOC_MIPS_TLS_DTPREL_LO16
:
11757 case BFD_RELOC_MIPS_TLS_GOTTPREL
:
11758 case BFD_RELOC_MIPS_TLS_TPREL_HI16
:
11759 case BFD_RELOC_MIPS_TLS_TPREL_LO16
:
11760 S_SET_THREAD_LOCAL (fixP
->fx_addsy
);
11763 case BFD_RELOC_MIPS_JMP
:
11764 case BFD_RELOC_MIPS_SHIFT5
:
11765 case BFD_RELOC_MIPS_SHIFT6
:
11766 case BFD_RELOC_MIPS_GOT_DISP
:
11767 case BFD_RELOC_MIPS_GOT_PAGE
:
11768 case BFD_RELOC_MIPS_GOT_OFST
:
11769 case BFD_RELOC_MIPS_SUB
:
11770 case BFD_RELOC_MIPS_INSERT_A
:
11771 case BFD_RELOC_MIPS_INSERT_B
:
11772 case BFD_RELOC_MIPS_DELETE
:
11773 case BFD_RELOC_MIPS_HIGHEST
:
11774 case BFD_RELOC_MIPS_HIGHER
:
11775 case BFD_RELOC_MIPS_SCN_DISP
:
11776 case BFD_RELOC_MIPS_REL16
:
11777 case BFD_RELOC_MIPS_RELGOT
:
11778 case BFD_RELOC_MIPS_JALR
:
11779 case BFD_RELOC_HI16
:
11780 case BFD_RELOC_HI16_S
:
11781 case BFD_RELOC_GPREL16
:
11782 case BFD_RELOC_MIPS_LITERAL
:
11783 case BFD_RELOC_MIPS_CALL16
:
11784 case BFD_RELOC_MIPS_GOT16
:
11785 case BFD_RELOC_GPREL32
:
11786 case BFD_RELOC_MIPS_GOT_HI16
:
11787 case BFD_RELOC_MIPS_GOT_LO16
:
11788 case BFD_RELOC_MIPS_CALL_HI16
:
11789 case BFD_RELOC_MIPS_CALL_LO16
:
11790 case BFD_RELOC_MIPS16_GPREL
:
11791 case BFD_RELOC_MIPS16_HI16
:
11792 case BFD_RELOC_MIPS16_HI16_S
:
11793 case BFD_RELOC_MIPS16_JMP
:
11794 /* Nothing needed to do. The value comes from the reloc entry. */
11798 /* This is handled like BFD_RELOC_32, but we output a sign
11799 extended value if we are only 32 bits. */
11802 if (8 <= sizeof (valueT
))
11803 md_number_to_chars ((char *) buf
, *valP
, 8);
11808 if ((*valP
& 0x80000000) != 0)
11812 md_number_to_chars ((char *)(buf
+ (target_big_endian
? 4 : 0)),
11814 md_number_to_chars ((char *)(buf
+ (target_big_endian
? 0 : 4)),
11820 case BFD_RELOC_RVA
:
11823 /* If we are deleting this reloc entry, we must fill in the
11824 value now. This can happen if we have a .word which is not
11825 resolved when it appears but is later defined. */
11827 md_number_to_chars ((char *) buf
, *valP
, fixP
->fx_size
);
11830 case BFD_RELOC_LO16
:
11831 case BFD_RELOC_MIPS16_LO16
:
11832 /* FIXME: Now that embedded-PIC is gone, some of this code/comment
11833 may be safe to remove, but if so it's not obvious. */
11834 /* When handling an embedded PIC switch statement, we can wind
11835 up deleting a LO16 reloc. See the 'o' case in mips_ip. */
11838 if (*valP
+ 0x8000 > 0xffff)
11839 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
11840 _("relocation overflow"));
11841 if (target_big_endian
)
11843 md_number_to_chars ((char *) buf
, *valP
, 2);
11847 case BFD_RELOC_16_PCREL_S2
:
11848 if ((*valP
& 0x3) != 0)
11849 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
11850 _("Branch to misaligned address (%lx)"), (long) *valP
);
11852 /* We need to save the bits in the instruction since fixup_segment()
11853 might be deleting the relocation entry (i.e., a branch within
11854 the current segment). */
11855 if (! fixP
->fx_done
)
11858 /* Update old instruction data. */
11859 if (target_big_endian
)
11860 insn
= (buf
[0] << 24) | (buf
[1] << 16) | (buf
[2] << 8) | buf
[3];
11862 insn
= (buf
[3] << 24) | (buf
[2] << 16) | (buf
[1] << 8) | buf
[0];
11864 if (*valP
+ 0x20000 <= 0x3ffff)
11866 insn
|= (*valP
>> 2) & 0xffff;
11867 md_number_to_chars ((char *) buf
, insn
, 4);
11869 else if (mips_pic
== NO_PIC
11871 && fixP
->fx_frag
->fr_address
>= text_section
->vma
11872 && (fixP
->fx_frag
->fr_address
11873 < text_section
->vma
+ bfd_get_section_size (text_section
))
11874 && ((insn
& 0xffff0000) == 0x10000000 /* beq $0,$0 */
11875 || (insn
& 0xffff0000) == 0x04010000 /* bgez $0 */
11876 || (insn
& 0xffff0000) == 0x04110000)) /* bgezal $0 */
11878 /* The branch offset is too large. If this is an
11879 unconditional branch, and we are not generating PIC code,
11880 we can convert it to an absolute jump instruction. */
11881 if ((insn
& 0xffff0000) == 0x04110000) /* bgezal $0 */
11882 insn
= 0x0c000000; /* jal */
11884 insn
= 0x08000000; /* j */
11885 fixP
->fx_r_type
= BFD_RELOC_MIPS_JMP
;
11887 fixP
->fx_addsy
= section_symbol (text_section
);
11888 *valP
+= md_pcrel_from (fixP
);
11889 md_number_to_chars ((char *) buf
, insn
, 4);
11893 /* If we got here, we have branch-relaxation disabled,
11894 and there's nothing we can do to fix this instruction
11895 without turning it into a longer sequence. */
11896 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
11897 _("Branch out of range"));
11901 case BFD_RELOC_VTABLE_INHERIT
:
11904 && !S_IS_DEFINED (fixP
->fx_addsy
)
11905 && !S_IS_WEAK (fixP
->fx_addsy
))
11906 S_SET_WEAK (fixP
->fx_addsy
);
11909 case BFD_RELOC_VTABLE_ENTRY
:
11917 /* Remember value for tc_gen_reloc. */
11918 fixP
->fx_addnumber
= *valP
;
11928 name
= input_line_pointer
;
11929 c
= get_symbol_end ();
11930 p
= (symbolS
*) symbol_find_or_make (name
);
11931 *input_line_pointer
= c
;
11935 /* Align the current frag to a given power of two. The MIPS assembler
11936 also automatically adjusts any preceding label. */
11939 mips_align (int to
, int fill
, symbolS
*label
)
11941 mips_emit_delays ();
11942 frag_align (to
, fill
, 0);
11943 record_alignment (now_seg
, to
);
11946 assert (S_GET_SEGMENT (label
) == now_seg
);
11947 symbol_set_frag (label
, frag_now
);
11948 S_SET_VALUE (label
, (valueT
) frag_now_fix ());
11952 /* Align to a given power of two. .align 0 turns off the automatic
11953 alignment used by the data creating pseudo-ops. */
11956 s_align (int x ATTRIBUTE_UNUSED
)
11960 long max_alignment
= 15;
11962 /* o Note that the assembler pulls down any immediately preceding label
11963 to the aligned address.
11964 o It's not documented but auto alignment is reinstated by
11965 a .align pseudo instruction.
11966 o Note also that after auto alignment is turned off the mips assembler
11967 issues an error on attempt to assemble an improperly aligned data item.
11970 temp
= get_absolute_expression ();
11971 if (temp
> max_alignment
)
11972 as_bad (_("Alignment too large: %d. assumed."), temp
= max_alignment
);
11975 as_warn (_("Alignment negative: 0 assumed."));
11978 if (*input_line_pointer
== ',')
11980 ++input_line_pointer
;
11981 temp_fill
= get_absolute_expression ();
11987 segment_info_type
*si
= seg_info (now_seg
);
11988 struct insn_label_list
*l
= si
->label_list
;
11989 /* Auto alignment should be switched on by next section change. */
11991 mips_align (temp
, (int) temp_fill
, l
!= NULL
? l
->label
: NULL
);
11998 demand_empty_rest_of_line ();
12002 s_change_sec (int sec
)
12007 /* The ELF backend needs to know that we are changing sections, so
12008 that .previous works correctly. We could do something like check
12009 for an obj_section_change_hook macro, but that might be confusing
12010 as it would not be appropriate to use it in the section changing
12011 functions in read.c, since obj-elf.c intercepts those. FIXME:
12012 This should be cleaner, somehow. */
12014 obj_elf_section_change_hook ();
12017 mips_emit_delays ();
12027 subseg_set (bss_section
, (subsegT
) get_absolute_expression ());
12028 demand_empty_rest_of_line ();
12032 seg
= subseg_new (RDATA_SECTION_NAME
,
12033 (subsegT
) get_absolute_expression ());
12036 bfd_set_section_flags (stdoutput
, seg
, (SEC_ALLOC
| SEC_LOAD
12037 | SEC_READONLY
| SEC_RELOC
12039 if (strcmp (TARGET_OS
, "elf") != 0)
12040 record_alignment (seg
, 4);
12042 demand_empty_rest_of_line ();
12046 seg
= subseg_new (".sdata", (subsegT
) get_absolute_expression ());
12049 bfd_set_section_flags (stdoutput
, seg
,
12050 SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_DATA
);
12051 if (strcmp (TARGET_OS
, "elf") != 0)
12052 record_alignment (seg
, 4);
12054 demand_empty_rest_of_line ();
12062 s_change_section (int ignore ATTRIBUTE_UNUSED
)
12065 char *section_name
;
12070 int section_entry_size
;
12071 int section_alignment
;
12076 section_name
= input_line_pointer
;
12077 c
= get_symbol_end ();
12079 next_c
= *(input_line_pointer
+ 1);
12081 /* Do we have .section Name<,"flags">? */
12082 if (c
!= ',' || (c
== ',' && next_c
== '"'))
12084 /* just after name is now '\0'. */
12085 *input_line_pointer
= c
;
12086 input_line_pointer
= section_name
;
12087 obj_elf_section (ignore
);
12090 input_line_pointer
++;
12092 /* Do we have .section Name<,type><,flag><,entry_size><,alignment> */
12094 section_type
= get_absolute_expression ();
12097 if (*input_line_pointer
++ == ',')
12098 section_flag
= get_absolute_expression ();
12101 if (*input_line_pointer
++ == ',')
12102 section_entry_size
= get_absolute_expression ();
12104 section_entry_size
= 0;
12105 if (*input_line_pointer
++ == ',')
12106 section_alignment
= get_absolute_expression ();
12108 section_alignment
= 0;
12110 section_name
= xstrdup (section_name
);
12112 /* When using the generic form of .section (as implemented by obj-elf.c),
12113 there's no way to set the section type to SHT_MIPS_DWARF. Users have
12114 traditionally had to fall back on the more common @progbits instead.
12116 There's nothing really harmful in this, since bfd will correct
12117 SHT_PROGBITS to SHT_MIPS_DWARF before writing out the file. But it
12118 means that, for backwards compatibility, the special_section entries
12119 for dwarf sections must use SHT_PROGBITS rather than SHT_MIPS_DWARF.
12121 Even so, we shouldn't force users of the MIPS .section syntax to
12122 incorrectly label the sections as SHT_PROGBITS. The best compromise
12123 seems to be to map SHT_MIPS_DWARF to SHT_PROGBITS before calling the
12124 generic type-checking code. */
12125 if (section_type
== SHT_MIPS_DWARF
)
12126 section_type
= SHT_PROGBITS
;
12128 obj_elf_change_section (section_name
, section_type
, section_flag
,
12129 section_entry_size
, 0, 0, 0);
12131 if (now_seg
->name
!= section_name
)
12132 free (section_name
);
12133 #endif /* OBJ_ELF */
12137 mips_enable_auto_align (void)
12143 s_cons (int log_size
)
12145 segment_info_type
*si
= seg_info (now_seg
);
12146 struct insn_label_list
*l
= si
->label_list
;
12149 label
= l
!= NULL
? l
->label
: NULL
;
12150 mips_emit_delays ();
12151 if (log_size
> 0 && auto_align
)
12152 mips_align (log_size
, 0, label
);
12153 mips_clear_insn_labels ();
12154 cons (1 << log_size
);
12158 s_float_cons (int type
)
12160 segment_info_type
*si
= seg_info (now_seg
);
12161 struct insn_label_list
*l
= si
->label_list
;
12164 label
= l
!= NULL
? l
->label
: NULL
;
12166 mips_emit_delays ();
12171 mips_align (3, 0, label
);
12173 mips_align (2, 0, label
);
12176 mips_clear_insn_labels ();
12181 /* Handle .globl. We need to override it because on Irix 5 you are
12184 where foo is an undefined symbol, to mean that foo should be
12185 considered to be the address of a function. */
12188 s_mips_globl (int x ATTRIBUTE_UNUSED
)
12197 name
= input_line_pointer
;
12198 c
= get_symbol_end ();
12199 symbolP
= symbol_find_or_make (name
);
12200 S_SET_EXTERNAL (symbolP
);
12202 *input_line_pointer
= c
;
12203 SKIP_WHITESPACE ();
12205 /* On Irix 5, every global symbol that is not explicitly labelled as
12206 being a function is apparently labelled as being an object. */
12209 if (!is_end_of_line
[(unsigned char) *input_line_pointer
]
12210 && (*input_line_pointer
!= ','))
12215 secname
= input_line_pointer
;
12216 c
= get_symbol_end ();
12217 sec
= bfd_get_section_by_name (stdoutput
, secname
);
12219 as_bad (_("%s: no such section"), secname
);
12220 *input_line_pointer
= c
;
12222 if (sec
!= NULL
&& (sec
->flags
& SEC_CODE
) != 0)
12223 flag
= BSF_FUNCTION
;
12226 symbol_get_bfdsym (symbolP
)->flags
|= flag
;
12228 c
= *input_line_pointer
;
12231 input_line_pointer
++;
12232 SKIP_WHITESPACE ();
12233 if (is_end_of_line
[(unsigned char) *input_line_pointer
])
12239 demand_empty_rest_of_line ();
12243 s_option (int x ATTRIBUTE_UNUSED
)
12248 opt
= input_line_pointer
;
12249 c
= get_symbol_end ();
12253 /* FIXME: What does this mean? */
12255 else if (strncmp (opt
, "pic", 3) == 0)
12259 i
= atoi (opt
+ 3);
12264 mips_pic
= SVR4_PIC
;
12265 mips_abicalls
= TRUE
;
12268 as_bad (_(".option pic%d not supported"), i
);
12270 if (mips_pic
== SVR4_PIC
)
12272 if (g_switch_seen
&& g_switch_value
!= 0)
12273 as_warn (_("-G may not be used with SVR4 PIC code"));
12274 g_switch_value
= 0;
12275 bfd_set_gp_size (stdoutput
, 0);
12279 as_warn (_("Unrecognized option \"%s\""), opt
);
12281 *input_line_pointer
= c
;
12282 demand_empty_rest_of_line ();
12285 /* This structure is used to hold a stack of .set values. */
12287 struct mips_option_stack
12289 struct mips_option_stack
*next
;
12290 struct mips_set_options options
;
12293 static struct mips_option_stack
*mips_opts_stack
;
12295 /* Handle the .set pseudo-op. */
12298 s_mipsset (int x ATTRIBUTE_UNUSED
)
12300 char *name
= input_line_pointer
, ch
;
12302 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
12303 ++input_line_pointer
;
12304 ch
= *input_line_pointer
;
12305 *input_line_pointer
= '\0';
12307 if (strcmp (name
, "reorder") == 0)
12309 if (mips_opts
.noreorder
)
12312 else if (strcmp (name
, "noreorder") == 0)
12314 if (!mips_opts
.noreorder
)
12315 start_noreorder ();
12317 else if (strcmp (name
, "at") == 0)
12319 mips_opts
.noat
= 0;
12321 else if (strcmp (name
, "noat") == 0)
12323 mips_opts
.noat
= 1;
12325 else if (strcmp (name
, "macro") == 0)
12327 mips_opts
.warn_about_macros
= 0;
12329 else if (strcmp (name
, "nomacro") == 0)
12331 if (mips_opts
.noreorder
== 0)
12332 as_bad (_("`noreorder' must be set before `nomacro'"));
12333 mips_opts
.warn_about_macros
= 1;
12335 else if (strcmp (name
, "move") == 0 || strcmp (name
, "novolatile") == 0)
12337 mips_opts
.nomove
= 0;
12339 else if (strcmp (name
, "nomove") == 0 || strcmp (name
, "volatile") == 0)
12341 mips_opts
.nomove
= 1;
12343 else if (strcmp (name
, "bopt") == 0)
12345 mips_opts
.nobopt
= 0;
12347 else if (strcmp (name
, "nobopt") == 0)
12349 mips_opts
.nobopt
= 1;
12351 else if (strcmp (name
, "gp=default") == 0)
12352 mips_opts
.gp32
= file_mips_gp32
;
12353 else if (strcmp (name
, "gp=32") == 0)
12354 mips_opts
.gp32
= 1;
12355 else if (strcmp (name
, "gp=64") == 0)
12357 if (!ISA_HAS_64BIT_REGS (mips_opts
.isa
))
12358 as_warn ("%s isa does not support 64-bit registers",
12359 mips_cpu_info_from_isa (mips_opts
.isa
)->name
);
12360 mips_opts
.gp32
= 0;
12362 else if (strcmp (name
, "fp=default") == 0)
12363 mips_opts
.fp32
= file_mips_fp32
;
12364 else if (strcmp (name
, "fp=32") == 0)
12365 mips_opts
.fp32
= 1;
12366 else if (strcmp (name
, "fp=64") == 0)
12368 if (!ISA_HAS_64BIT_FPRS (mips_opts
.isa
))
12369 as_warn ("%s isa does not support 64-bit floating point registers",
12370 mips_cpu_info_from_isa (mips_opts
.isa
)->name
);
12371 mips_opts
.fp32
= 0;
12373 else if (strcmp (name
, "mips16") == 0
12374 || strcmp (name
, "MIPS-16") == 0)
12375 mips_opts
.mips16
= 1;
12376 else if (strcmp (name
, "nomips16") == 0
12377 || strcmp (name
, "noMIPS-16") == 0)
12378 mips_opts
.mips16
= 0;
12379 else if (strcmp (name
, "smartmips") == 0)
12381 if (!ISA_SUPPORTS_SMARTMIPS
)
12382 as_warn ("%s ISA does not support SmartMIPS ASE",
12383 mips_cpu_info_from_isa (mips_opts
.isa
)->name
);
12384 mips_opts
.ase_smartmips
= 1;
12386 else if (strcmp (name
, "nosmartmips") == 0)
12387 mips_opts
.ase_smartmips
= 0;
12388 else if (strcmp (name
, "mips3d") == 0)
12389 mips_opts
.ase_mips3d
= 1;
12390 else if (strcmp (name
, "nomips3d") == 0)
12391 mips_opts
.ase_mips3d
= 0;
12392 else if (strcmp (name
, "mdmx") == 0)
12393 mips_opts
.ase_mdmx
= 1;
12394 else if (strcmp (name
, "nomdmx") == 0)
12395 mips_opts
.ase_mdmx
= 0;
12396 else if (strcmp (name
, "dsp") == 0)
12398 if (!ISA_SUPPORTS_DSP_ASE
)
12399 as_warn ("%s ISA does not support DSP ASE",
12400 mips_cpu_info_from_isa (mips_opts
.isa
)->name
);
12401 mips_opts
.ase_dsp
= 1;
12403 else if (strcmp (name
, "nodsp") == 0)
12404 mips_opts
.ase_dsp
= 0;
12405 else if (strcmp (name
, "mt") == 0)
12407 if (!ISA_SUPPORTS_MT_ASE
)
12408 as_warn ("%s ISA does not support MT ASE",
12409 mips_cpu_info_from_isa (mips_opts
.isa
)->name
);
12410 mips_opts
.ase_mt
= 1;
12412 else if (strcmp (name
, "nomt") == 0)
12413 mips_opts
.ase_mt
= 0;
12414 else if (strncmp (name
, "mips", 4) == 0 || strncmp (name
, "arch=", 5) == 0)
12418 /* Permit the user to change the ISA and architecture on the fly.
12419 Needless to say, misuse can cause serious problems. */
12420 if (strcmp (name
, "mips0") == 0 || strcmp (name
, "arch=default") == 0)
12423 mips_opts
.isa
= file_mips_isa
;
12424 mips_opts
.arch
= file_mips_arch
;
12426 else if (strncmp (name
, "arch=", 5) == 0)
12428 const struct mips_cpu_info
*p
;
12430 p
= mips_parse_cpu("internal use", name
+ 5);
12432 as_bad (_("unknown architecture %s"), name
+ 5);
12435 mips_opts
.arch
= p
->cpu
;
12436 mips_opts
.isa
= p
->isa
;
12439 else if (strncmp (name
, "mips", 4) == 0)
12441 const struct mips_cpu_info
*p
;
12443 p
= mips_parse_cpu("internal use", name
);
12445 as_bad (_("unknown ISA level %s"), name
+ 4);
12448 mips_opts
.arch
= p
->cpu
;
12449 mips_opts
.isa
= p
->isa
;
12453 as_bad (_("unknown ISA or architecture %s"), name
);
12455 switch (mips_opts
.isa
)
12463 mips_opts
.gp32
= 1;
12464 mips_opts
.fp32
= 1;
12471 mips_opts
.gp32
= 0;
12472 mips_opts
.fp32
= 0;
12475 as_bad (_("unknown ISA level %s"), name
+ 4);
12480 mips_opts
.gp32
= file_mips_gp32
;
12481 mips_opts
.fp32
= file_mips_fp32
;
12484 else if (strcmp (name
, "autoextend") == 0)
12485 mips_opts
.noautoextend
= 0;
12486 else if (strcmp (name
, "noautoextend") == 0)
12487 mips_opts
.noautoextend
= 1;
12488 else if (strcmp (name
, "push") == 0)
12490 struct mips_option_stack
*s
;
12492 s
= (struct mips_option_stack
*) xmalloc (sizeof *s
);
12493 s
->next
= mips_opts_stack
;
12494 s
->options
= mips_opts
;
12495 mips_opts_stack
= s
;
12497 else if (strcmp (name
, "pop") == 0)
12499 struct mips_option_stack
*s
;
12501 s
= mips_opts_stack
;
12503 as_bad (_(".set pop with no .set push"));
12506 /* If we're changing the reorder mode we need to handle
12507 delay slots correctly. */
12508 if (s
->options
.noreorder
&& ! mips_opts
.noreorder
)
12509 start_noreorder ();
12510 else if (! s
->options
.noreorder
&& mips_opts
.noreorder
)
12513 mips_opts
= s
->options
;
12514 mips_opts_stack
= s
->next
;
12518 else if (strcmp (name
, "sym32") == 0)
12519 mips_opts
.sym32
= TRUE
;
12520 else if (strcmp (name
, "nosym32") == 0)
12521 mips_opts
.sym32
= FALSE
;
12524 as_warn (_("Tried to set unrecognized symbol: %s\n"), name
);
12526 *input_line_pointer
= ch
;
12527 demand_empty_rest_of_line ();
12530 /* Handle the .abicalls pseudo-op. I believe this is equivalent to
12531 .option pic2. It means to generate SVR4 PIC calls. */
12534 s_abicalls (int ignore ATTRIBUTE_UNUSED
)
12536 mips_pic
= SVR4_PIC
;
12537 mips_abicalls
= TRUE
;
12539 if (g_switch_seen
&& g_switch_value
!= 0)
12540 as_warn (_("-G may not be used with SVR4 PIC code"));
12541 g_switch_value
= 0;
12543 bfd_set_gp_size (stdoutput
, 0);
12544 demand_empty_rest_of_line ();
12547 /* Handle the .cpload pseudo-op. This is used when generating SVR4
12548 PIC code. It sets the $gp register for the function based on the
12549 function address, which is in the register named in the argument.
12550 This uses a relocation against _gp_disp, which is handled specially
12551 by the linker. The result is:
12552 lui $gp,%hi(_gp_disp)
12553 addiu $gp,$gp,%lo(_gp_disp)
12554 addu $gp,$gp,.cpload argument
12555 The .cpload argument is normally $25 == $t9.
12557 The -mno-shared option changes this to:
12558 lui $gp,%hi(__gnu_local_gp)
12559 addiu $gp,$gp,%lo(__gnu_local_gp)
12560 and the argument is ignored. This saves an instruction, but the
12561 resulting code is not position independent; it uses an absolute
12562 address for __gnu_local_gp. Thus code assembled with -mno-shared
12563 can go into an ordinary executable, but not into a shared library. */
12566 s_cpload (int ignore ATTRIBUTE_UNUSED
)
12572 /* If we are not generating SVR4 PIC code, or if this is NewABI code,
12573 .cpload is ignored. */
12574 if (mips_pic
!= SVR4_PIC
|| HAVE_NEWABI
)
12580 /* .cpload should be in a .set noreorder section. */
12581 if (mips_opts
.noreorder
== 0)
12582 as_warn (_(".cpload not in noreorder section"));
12584 reg
= tc_get_register (0);
12586 /* If we need to produce a 64-bit address, we are better off using
12587 the default instruction sequence. */
12588 in_shared
= mips_in_shared
|| HAVE_64BIT_SYMBOLS
;
12590 ex
.X_op
= O_symbol
;
12591 ex
.X_add_symbol
= symbol_find_or_make (in_shared
? "_gp_disp" :
12593 ex
.X_op_symbol
= NULL
;
12594 ex
.X_add_number
= 0;
12596 /* In ELF, this symbol is implicitly an STT_OBJECT symbol. */
12597 symbol_get_bfdsym (ex
.X_add_symbol
)->flags
|= BSF_OBJECT
;
12600 macro_build_lui (&ex
, mips_gp_register
);
12601 macro_build (&ex
, "addiu", "t,r,j", mips_gp_register
,
12602 mips_gp_register
, BFD_RELOC_LO16
);
12604 macro_build (NULL
, "addu", "d,v,t", mips_gp_register
,
12605 mips_gp_register
, reg
);
12608 demand_empty_rest_of_line ();
12611 /* Handle the .cpsetup pseudo-op defined for NewABI PIC code. The syntax is:
12612 .cpsetup $reg1, offset|$reg2, label
12614 If offset is given, this results in:
12615 sd $gp, offset($sp)
12616 lui $gp, %hi(%neg(%gp_rel(label)))
12617 addiu $gp, $gp, %lo(%neg(%gp_rel(label)))
12618 daddu $gp, $gp, $reg1
12620 If $reg2 is given, this results in:
12621 daddu $reg2, $gp, $0
12622 lui $gp, %hi(%neg(%gp_rel(label)))
12623 addiu $gp, $gp, %lo(%neg(%gp_rel(label)))
12624 daddu $gp, $gp, $reg1
12625 $reg1 is normally $25 == $t9.
12627 The -mno-shared option replaces the last three instructions with
12629 addiu $gp,$gp,%lo(_gp) */
12632 s_cpsetup (int ignore ATTRIBUTE_UNUSED
)
12634 expressionS ex_off
;
12635 expressionS ex_sym
;
12638 /* If we are not generating SVR4 PIC code, .cpsetup is ignored.
12639 We also need NewABI support. */
12640 if (mips_pic
!= SVR4_PIC
|| ! HAVE_NEWABI
)
12646 reg1
= tc_get_register (0);
12647 SKIP_WHITESPACE ();
12648 if (*input_line_pointer
!= ',')
12650 as_bad (_("missing argument separator ',' for .cpsetup"));
12654 ++input_line_pointer
;
12655 SKIP_WHITESPACE ();
12656 if (*input_line_pointer
== '$')
12658 mips_cpreturn_register
= tc_get_register (0);
12659 mips_cpreturn_offset
= -1;
12663 mips_cpreturn_offset
= get_absolute_expression ();
12664 mips_cpreturn_register
= -1;
12666 SKIP_WHITESPACE ();
12667 if (*input_line_pointer
!= ',')
12669 as_bad (_("missing argument separator ',' for .cpsetup"));
12673 ++input_line_pointer
;
12674 SKIP_WHITESPACE ();
12675 expression (&ex_sym
);
12678 if (mips_cpreturn_register
== -1)
12680 ex_off
.X_op
= O_constant
;
12681 ex_off
.X_add_symbol
= NULL
;
12682 ex_off
.X_op_symbol
= NULL
;
12683 ex_off
.X_add_number
= mips_cpreturn_offset
;
12685 macro_build (&ex_off
, "sd", "t,o(b)", mips_gp_register
,
12686 BFD_RELOC_LO16
, SP
);
12689 macro_build (NULL
, "daddu", "d,v,t", mips_cpreturn_register
,
12690 mips_gp_register
, 0);
12692 if (mips_in_shared
|| HAVE_64BIT_SYMBOLS
)
12694 macro_build (&ex_sym
, "lui", "t,u", mips_gp_register
,
12695 -1, BFD_RELOC_GPREL16
, BFD_RELOC_MIPS_SUB
,
12698 macro_build (&ex_sym
, "addiu", "t,r,j", mips_gp_register
,
12699 mips_gp_register
, -1, BFD_RELOC_GPREL16
,
12700 BFD_RELOC_MIPS_SUB
, BFD_RELOC_LO16
);
12702 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t", mips_gp_register
,
12703 mips_gp_register
, reg1
);
12709 ex
.X_op
= O_symbol
;
12710 ex
.X_add_symbol
= symbol_find_or_make ("__gnu_local_gp");
12711 ex
.X_op_symbol
= NULL
;
12712 ex
.X_add_number
= 0;
12714 /* In ELF, this symbol is implicitly an STT_OBJECT symbol. */
12715 symbol_get_bfdsym (ex
.X_add_symbol
)->flags
|= BSF_OBJECT
;
12717 macro_build_lui (&ex
, mips_gp_register
);
12718 macro_build (&ex
, "addiu", "t,r,j", mips_gp_register
,
12719 mips_gp_register
, BFD_RELOC_LO16
);
12724 demand_empty_rest_of_line ();
12728 s_cplocal (int ignore ATTRIBUTE_UNUSED
)
12730 /* If we are not generating SVR4 PIC code, or if this is not NewABI code,
12731 .cplocal is ignored. */
12732 if (mips_pic
!= SVR4_PIC
|| ! HAVE_NEWABI
)
12738 mips_gp_register
= tc_get_register (0);
12739 demand_empty_rest_of_line ();
12742 /* Handle the .cprestore pseudo-op. This stores $gp into a given
12743 offset from $sp. The offset is remembered, and after making a PIC
12744 call $gp is restored from that location. */
12747 s_cprestore (int ignore ATTRIBUTE_UNUSED
)
12751 /* If we are not generating SVR4 PIC code, or if this is NewABI code,
12752 .cprestore is ignored. */
12753 if (mips_pic
!= SVR4_PIC
|| HAVE_NEWABI
)
12759 mips_cprestore_offset
= get_absolute_expression ();
12760 mips_cprestore_valid
= 1;
12762 ex
.X_op
= O_constant
;
12763 ex
.X_add_symbol
= NULL
;
12764 ex
.X_op_symbol
= NULL
;
12765 ex
.X_add_number
= mips_cprestore_offset
;
12768 macro_build_ldst_constoffset (&ex
, ADDRESS_STORE_INSN
, mips_gp_register
,
12769 SP
, HAVE_64BIT_ADDRESSES
);
12772 demand_empty_rest_of_line ();
12775 /* Handle the .cpreturn pseudo-op defined for NewABI PIC code. If an offset
12776 was given in the preceding .cpsetup, it results in:
12777 ld $gp, offset($sp)
12779 If a register $reg2 was given there, it results in:
12780 daddu $gp, $reg2, $0 */
12783 s_cpreturn (int ignore ATTRIBUTE_UNUSED
)
12787 /* If we are not generating SVR4 PIC code, .cpreturn is ignored.
12788 We also need NewABI support. */
12789 if (mips_pic
!= SVR4_PIC
|| ! HAVE_NEWABI
)
12796 if (mips_cpreturn_register
== -1)
12798 ex
.X_op
= O_constant
;
12799 ex
.X_add_symbol
= NULL
;
12800 ex
.X_op_symbol
= NULL
;
12801 ex
.X_add_number
= mips_cpreturn_offset
;
12803 macro_build (&ex
, "ld", "t,o(b)", mips_gp_register
, BFD_RELOC_LO16
, SP
);
12806 macro_build (NULL
, "daddu", "d,v,t", mips_gp_register
,
12807 mips_cpreturn_register
, 0);
12810 demand_empty_rest_of_line ();
12813 /* Handle the .gpvalue pseudo-op. This is used when generating NewABI PIC
12814 code. It sets the offset to use in gp_rel relocations. */
12817 s_gpvalue (int ignore ATTRIBUTE_UNUSED
)
12819 /* If we are not generating SVR4 PIC code, .gpvalue is ignored.
12820 We also need NewABI support. */
12821 if (mips_pic
!= SVR4_PIC
|| ! HAVE_NEWABI
)
12827 mips_gprel_offset
= get_absolute_expression ();
12829 demand_empty_rest_of_line ();
12832 /* Handle the .gpword pseudo-op. This is used when generating PIC
12833 code. It generates a 32 bit GP relative reloc. */
12836 s_gpword (int ignore ATTRIBUTE_UNUSED
)
12838 segment_info_type
*si
;
12839 struct insn_label_list
*l
;
12844 /* When not generating PIC code, this is treated as .word. */
12845 if (mips_pic
!= SVR4_PIC
)
12851 si
= seg_info (now_seg
);
12852 l
= si
->label_list
;
12853 label
= l
!= NULL
? l
->label
: NULL
;
12854 mips_emit_delays ();
12856 mips_align (2, 0, label
);
12857 mips_clear_insn_labels ();
12861 if (ex
.X_op
!= O_symbol
|| ex
.X_add_number
!= 0)
12863 as_bad (_("Unsupported use of .gpword"));
12864 ignore_rest_of_line ();
12868 md_number_to_chars (p
, 0, 4);
12869 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
, 4, &ex
, FALSE
,
12870 BFD_RELOC_GPREL32
);
12872 demand_empty_rest_of_line ();
12876 s_gpdword (int ignore ATTRIBUTE_UNUSED
)
12878 segment_info_type
*si
;
12879 struct insn_label_list
*l
;
12884 /* When not generating PIC code, this is treated as .dword. */
12885 if (mips_pic
!= SVR4_PIC
)
12891 si
= seg_info (now_seg
);
12892 l
= si
->label_list
;
12893 label
= l
!= NULL
? l
->label
: NULL
;
12894 mips_emit_delays ();
12896 mips_align (3, 0, label
);
12897 mips_clear_insn_labels ();
12901 if (ex
.X_op
!= O_symbol
|| ex
.X_add_number
!= 0)
12903 as_bad (_("Unsupported use of .gpdword"));
12904 ignore_rest_of_line ();
12908 md_number_to_chars (p
, 0, 8);
12909 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
, 4, &ex
, FALSE
,
12910 BFD_RELOC_GPREL32
)->fx_tcbit
= 1;
12912 /* GPREL32 composed with 64 gives a 64-bit GP offset. */
12913 fix_new (frag_now
, p
- frag_now
->fr_literal
, 8, NULL
, 0,
12914 FALSE
, BFD_RELOC_64
)->fx_tcbit
= 1;
12916 demand_empty_rest_of_line ();
12919 /* Handle the .cpadd pseudo-op. This is used when dealing with switch
12920 tables in SVR4 PIC code. */
12923 s_cpadd (int ignore ATTRIBUTE_UNUSED
)
12927 /* This is ignored when not generating SVR4 PIC code. */
12928 if (mips_pic
!= SVR4_PIC
)
12934 /* Add $gp to the register named as an argument. */
12936 reg
= tc_get_register (0);
12937 macro_build (NULL
, ADDRESS_ADD_INSN
, "d,v,t", reg
, reg
, mips_gp_register
);
12940 demand_empty_rest_of_line ();
12943 /* Handle the .insn pseudo-op. This marks instruction labels in
12944 mips16 mode. This permits the linker to handle them specially,
12945 such as generating jalx instructions when needed. We also make
12946 them odd for the duration of the assembly, in order to generate the
12947 right sort of code. We will make them even in the adjust_symtab
12948 routine, while leaving them marked. This is convenient for the
12949 debugger and the disassembler. The linker knows to make them odd
12953 s_insn (int ignore ATTRIBUTE_UNUSED
)
12955 mips16_mark_labels ();
12957 demand_empty_rest_of_line ();
12960 /* Handle a .stabn directive. We need these in order to mark a label
12961 as being a mips16 text label correctly. Sometimes the compiler
12962 will emit a label, followed by a .stabn, and then switch sections.
12963 If the label and .stabn are in mips16 mode, then the label is
12964 really a mips16 text label. */
12967 s_mips_stab (int type
)
12970 mips16_mark_labels ();
12975 /* Handle the .weakext pseudo-op as defined in Kane and Heinrich. */
12978 s_mips_weakext (int ignore ATTRIBUTE_UNUSED
)
12985 name
= input_line_pointer
;
12986 c
= get_symbol_end ();
12987 symbolP
= symbol_find_or_make (name
);
12988 S_SET_WEAK (symbolP
);
12989 *input_line_pointer
= c
;
12991 SKIP_WHITESPACE ();
12993 if (! is_end_of_line
[(unsigned char) *input_line_pointer
])
12995 if (S_IS_DEFINED (symbolP
))
12997 as_bad ("ignoring attempt to redefine symbol %s",
12998 S_GET_NAME (symbolP
));
12999 ignore_rest_of_line ();
13003 if (*input_line_pointer
== ',')
13005 ++input_line_pointer
;
13006 SKIP_WHITESPACE ();
13010 if (exp
.X_op
!= O_symbol
)
13012 as_bad ("bad .weakext directive");
13013 ignore_rest_of_line ();
13016 symbol_set_value_expression (symbolP
, &exp
);
13019 demand_empty_rest_of_line ();
13022 /* Parse a register string into a number. Called from the ECOFF code
13023 to parse .frame. The argument is non-zero if this is the frame
13024 register, so that we can record it in mips_frame_reg. */
13027 tc_get_register (int frame
)
13031 SKIP_WHITESPACE ();
13032 if (! reg_lookup (&input_line_pointer
, RWARN
| RTYPE_NUM
| RTYPE_GP
, ®
))
13036 mips_frame_reg
= reg
!= 0 ? reg
: SP
;
13037 mips_frame_reg_valid
= 1;
13038 mips_cprestore_valid
= 0;
13044 md_section_align (asection
*seg
, valueT addr
)
13046 int align
= bfd_get_section_alignment (stdoutput
, seg
);
13050 /* We don't need to align ELF sections to the full alignment.
13051 However, Irix 5 may prefer that we align them at least to a 16
13052 byte boundary. We don't bother to align the sections if we
13053 are targeted for an embedded system. */
13054 if (strcmp (TARGET_OS
, "elf") == 0)
13060 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
13063 /* Utility routine, called from above as well. If called while the
13064 input file is still being read, it's only an approximation. (For
13065 example, a symbol may later become defined which appeared to be
13066 undefined earlier.) */
13069 nopic_need_relax (symbolS
*sym
, int before_relaxing
)
13074 if (g_switch_value
> 0)
13076 const char *symname
;
13079 /* Find out whether this symbol can be referenced off the $gp
13080 register. It can be if it is smaller than the -G size or if
13081 it is in the .sdata or .sbss section. Certain symbols can
13082 not be referenced off the $gp, although it appears as though
13084 symname
= S_GET_NAME (sym
);
13085 if (symname
!= (const char *) NULL
13086 && (strcmp (symname
, "eprol") == 0
13087 || strcmp (symname
, "etext") == 0
13088 || strcmp (symname
, "_gp") == 0
13089 || strcmp (symname
, "edata") == 0
13090 || strcmp (symname
, "_fbss") == 0
13091 || strcmp (symname
, "_fdata") == 0
13092 || strcmp (symname
, "_ftext") == 0
13093 || strcmp (symname
, "end") == 0
13094 || strcmp (symname
, "_gp_disp") == 0))
13096 else if ((! S_IS_DEFINED (sym
) || S_IS_COMMON (sym
))
13098 #ifndef NO_ECOFF_DEBUGGING
13099 || (symbol_get_obj (sym
)->ecoff_extern_size
!= 0
13100 && (symbol_get_obj (sym
)->ecoff_extern_size
13101 <= g_switch_value
))
13103 /* We must defer this decision until after the whole
13104 file has been read, since there might be a .extern
13105 after the first use of this symbol. */
13106 || (before_relaxing
13107 #ifndef NO_ECOFF_DEBUGGING
13108 && symbol_get_obj (sym
)->ecoff_extern_size
== 0
13110 && S_GET_VALUE (sym
) == 0)
13111 || (S_GET_VALUE (sym
) != 0
13112 && S_GET_VALUE (sym
) <= g_switch_value
)))
13116 const char *segname
;
13118 segname
= segment_name (S_GET_SEGMENT (sym
));
13119 assert (strcmp (segname
, ".lit8") != 0
13120 && strcmp (segname
, ".lit4") != 0);
13121 change
= (strcmp (segname
, ".sdata") != 0
13122 && strcmp (segname
, ".sbss") != 0
13123 && strncmp (segname
, ".sdata.", 7) != 0
13124 && strncmp (segname
, ".sbss.", 6) != 0
13125 && strncmp (segname
, ".gnu.linkonce.sb.", 17) != 0
13126 && strncmp (segname
, ".gnu.linkonce.s.", 16) != 0);
13131 /* We are not optimizing for the $gp register. */
13136 /* Return true if the given symbol should be considered local for SVR4 PIC. */
13139 pic_need_relax (symbolS
*sym
, asection
*segtype
)
13143 /* Handle the case of a symbol equated to another symbol. */
13144 while (symbol_equated_reloc_p (sym
))
13148 /* It's possible to get a loop here in a badly written program. */
13149 n
= symbol_get_value_expression (sym
)->X_add_symbol
;
13155 if (symbol_section_p (sym
))
13158 symsec
= S_GET_SEGMENT (sym
);
13160 /* This must duplicate the test in adjust_reloc_syms. */
13161 return (symsec
!= &bfd_und_section
13162 && symsec
!= &bfd_abs_section
13163 && !bfd_is_com_section (symsec
)
13164 && !s_is_linkonce (sym
, segtype
)
13166 /* A global or weak symbol is treated as external. */
13167 && (!IS_ELF
|| (! S_IS_WEAK (sym
) && ! S_IS_EXTERNAL (sym
)))
13173 /* Given a mips16 variant frag FRAGP, return non-zero if it needs an
13174 extended opcode. SEC is the section the frag is in. */
13177 mips16_extended_frag (fragS
*fragp
, asection
*sec
, long stretch
)
13180 const struct mips16_immed_operand
*op
;
13182 int mintiny
, maxtiny
;
13186 if (RELAX_MIPS16_USER_SMALL (fragp
->fr_subtype
))
13188 if (RELAX_MIPS16_USER_EXT (fragp
->fr_subtype
))
13191 type
= RELAX_MIPS16_TYPE (fragp
->fr_subtype
);
13192 op
= mips16_immed_operands
;
13193 while (op
->type
!= type
)
13196 assert (op
< mips16_immed_operands
+ MIPS16_NUM_IMMED
);
13201 if (type
== '<' || type
== '>' || type
== '[' || type
== ']')
13204 maxtiny
= 1 << op
->nbits
;
13209 maxtiny
= (1 << op
->nbits
) - 1;
13214 mintiny
= - (1 << (op
->nbits
- 1));
13215 maxtiny
= (1 << (op
->nbits
- 1)) - 1;
13218 sym_frag
= symbol_get_frag (fragp
->fr_symbol
);
13219 val
= S_GET_VALUE (fragp
->fr_symbol
);
13220 symsec
= S_GET_SEGMENT (fragp
->fr_symbol
);
13226 /* We won't have the section when we are called from
13227 mips_relax_frag. However, we will always have been called
13228 from md_estimate_size_before_relax first. If this is a
13229 branch to a different section, we mark it as such. If SEC is
13230 NULL, and the frag is not marked, then it must be a branch to
13231 the same section. */
13234 if (RELAX_MIPS16_LONG_BRANCH (fragp
->fr_subtype
))
13239 /* Must have been called from md_estimate_size_before_relax. */
13242 fragp
->fr_subtype
=
13243 RELAX_MIPS16_MARK_LONG_BRANCH (fragp
->fr_subtype
);
13245 /* FIXME: We should support this, and let the linker
13246 catch branches and loads that are out of range. */
13247 as_bad_where (fragp
->fr_file
, fragp
->fr_line
,
13248 _("unsupported PC relative reference to different section"));
13252 if (fragp
!= sym_frag
&& sym_frag
->fr_address
== 0)
13253 /* Assume non-extended on the first relaxation pass.
13254 The address we have calculated will be bogus if this is
13255 a forward branch to another frag, as the forward frag
13256 will have fr_address == 0. */
13260 /* In this case, we know for sure that the symbol fragment is in
13261 the same section. If the relax_marker of the symbol fragment
13262 differs from the relax_marker of this fragment, we have not
13263 yet adjusted the symbol fragment fr_address. We want to add
13264 in STRETCH in order to get a better estimate of the address.
13265 This particularly matters because of the shift bits. */
13267 && sym_frag
->relax_marker
!= fragp
->relax_marker
)
13271 /* Adjust stretch for any alignment frag. Note that if have
13272 been expanding the earlier code, the symbol may be
13273 defined in what appears to be an earlier frag. FIXME:
13274 This doesn't handle the fr_subtype field, which specifies
13275 a maximum number of bytes to skip when doing an
13277 for (f
= fragp
; f
!= NULL
&& f
!= sym_frag
; f
= f
->fr_next
)
13279 if (f
->fr_type
== rs_align
|| f
->fr_type
== rs_align_code
)
13282 stretch
= - ((- stretch
)
13283 & ~ ((1 << (int) f
->fr_offset
) - 1));
13285 stretch
&= ~ ((1 << (int) f
->fr_offset
) - 1);
13294 addr
= fragp
->fr_address
+ fragp
->fr_fix
;
13296 /* The base address rules are complicated. The base address of
13297 a branch is the following instruction. The base address of a
13298 PC relative load or add is the instruction itself, but if it
13299 is in a delay slot (in which case it can not be extended) use
13300 the address of the instruction whose delay slot it is in. */
13301 if (type
== 'p' || type
== 'q')
13305 /* If we are currently assuming that this frag should be
13306 extended, then, the current address is two bytes
13308 if (RELAX_MIPS16_EXTENDED (fragp
->fr_subtype
))
13311 /* Ignore the low bit in the target, since it will be set
13312 for a text label. */
13313 if ((val
& 1) != 0)
13316 else if (RELAX_MIPS16_JAL_DSLOT (fragp
->fr_subtype
))
13318 else if (RELAX_MIPS16_DSLOT (fragp
->fr_subtype
))
13321 val
-= addr
& ~ ((1 << op
->shift
) - 1);
13323 /* Branch offsets have an implicit 0 in the lowest bit. */
13324 if (type
== 'p' || type
== 'q')
13327 /* If any of the shifted bits are set, we must use an extended
13328 opcode. If the address depends on the size of this
13329 instruction, this can lead to a loop, so we arrange to always
13330 use an extended opcode. We only check this when we are in
13331 the main relaxation loop, when SEC is NULL. */
13332 if ((val
& ((1 << op
->shift
) - 1)) != 0 && sec
== NULL
)
13334 fragp
->fr_subtype
=
13335 RELAX_MIPS16_MARK_LONG_BRANCH (fragp
->fr_subtype
);
13339 /* If we are about to mark a frag as extended because the value
13340 is precisely maxtiny + 1, then there is a chance of an
13341 infinite loop as in the following code:
13346 In this case when the la is extended, foo is 0x3fc bytes
13347 away, so the la can be shrunk, but then foo is 0x400 away, so
13348 the la must be extended. To avoid this loop, we mark the
13349 frag as extended if it was small, and is about to become
13350 extended with a value of maxtiny + 1. */
13351 if (val
== ((maxtiny
+ 1) << op
->shift
)
13352 && ! RELAX_MIPS16_EXTENDED (fragp
->fr_subtype
)
13355 fragp
->fr_subtype
=
13356 RELAX_MIPS16_MARK_LONG_BRANCH (fragp
->fr_subtype
);
13360 else if (symsec
!= absolute_section
&& sec
!= NULL
)
13361 as_bad_where (fragp
->fr_file
, fragp
->fr_line
, _("unsupported relocation"));
13363 if ((val
& ((1 << op
->shift
) - 1)) != 0
13364 || val
< (mintiny
<< op
->shift
)
13365 || val
> (maxtiny
<< op
->shift
))
13371 /* Compute the length of a branch sequence, and adjust the
13372 RELAX_BRANCH_TOOFAR bit accordingly. If FRAGP is NULL, the
13373 worst-case length is computed, with UPDATE being used to indicate
13374 whether an unconditional (-1), branch-likely (+1) or regular (0)
13375 branch is to be computed. */
13377 relaxed_branch_length (fragS
*fragp
, asection
*sec
, int update
)
13379 bfd_boolean toofar
;
13383 && S_IS_DEFINED (fragp
->fr_symbol
)
13384 && sec
== S_GET_SEGMENT (fragp
->fr_symbol
))
13389 val
= S_GET_VALUE (fragp
->fr_symbol
) + fragp
->fr_offset
;
13391 addr
= fragp
->fr_address
+ fragp
->fr_fix
+ 4;
13395 toofar
= val
< - (0x8000 << 2) || val
>= (0x8000 << 2);
13398 /* If the symbol is not defined or it's in a different segment,
13399 assume the user knows what's going on and emit a short
13405 if (fragp
&& update
&& toofar
!= RELAX_BRANCH_TOOFAR (fragp
->fr_subtype
))
13407 = RELAX_BRANCH_ENCODE (RELAX_BRANCH_UNCOND (fragp
->fr_subtype
),
13408 RELAX_BRANCH_LIKELY (fragp
->fr_subtype
),
13409 RELAX_BRANCH_LINK (fragp
->fr_subtype
),
13415 if (fragp
? RELAX_BRANCH_LIKELY (fragp
->fr_subtype
) : (update
> 0))
13418 if (mips_pic
!= NO_PIC
)
13420 /* Additional space for PIC loading of target address. */
13422 if (mips_opts
.isa
== ISA_MIPS1
)
13423 /* Additional space for $at-stabilizing nop. */
13427 /* If branch is conditional. */
13428 if (fragp
? !RELAX_BRANCH_UNCOND (fragp
->fr_subtype
) : (update
>= 0))
13435 /* Estimate the size of a frag before relaxing. Unless this is the
13436 mips16, we are not really relaxing here, and the final size is
13437 encoded in the subtype information. For the mips16, we have to
13438 decide whether we are using an extended opcode or not. */
13441 md_estimate_size_before_relax (fragS
*fragp
, asection
*segtype
)
13445 if (RELAX_BRANCH_P (fragp
->fr_subtype
))
13448 fragp
->fr_var
= relaxed_branch_length (fragp
, segtype
, FALSE
);
13450 return fragp
->fr_var
;
13453 if (RELAX_MIPS16_P (fragp
->fr_subtype
))
13454 /* We don't want to modify the EXTENDED bit here; it might get us
13455 into infinite loops. We change it only in mips_relax_frag(). */
13456 return (RELAX_MIPS16_EXTENDED (fragp
->fr_subtype
) ? 4 : 2);
13458 if (mips_pic
== NO_PIC
)
13459 change
= nopic_need_relax (fragp
->fr_symbol
, 0);
13460 else if (mips_pic
== SVR4_PIC
)
13461 change
= pic_need_relax (fragp
->fr_symbol
, segtype
);
13462 else if (mips_pic
== VXWORKS_PIC
)
13463 /* For vxworks, GOT16 relocations never have a corresponding LO16. */
13470 fragp
->fr_subtype
|= RELAX_USE_SECOND
;
13471 return -RELAX_FIRST (fragp
->fr_subtype
);
13474 return -RELAX_SECOND (fragp
->fr_subtype
);
13477 /* This is called to see whether a reloc against a defined symbol
13478 should be converted into a reloc against a section. */
13481 mips_fix_adjustable (fixS
*fixp
)
13483 if (fixp
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
13484 || fixp
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
13487 if (fixp
->fx_addsy
== NULL
)
13490 /* If symbol SYM is in a mergeable section, relocations of the form
13491 SYM + 0 can usually be made section-relative. The mergeable data
13492 is then identified by the section offset rather than by the symbol.
13494 However, if we're generating REL LO16 relocations, the offset is split
13495 between the LO16 and parterning high part relocation. The linker will
13496 need to recalculate the complete offset in order to correctly identify
13499 The linker has traditionally not looked for the parterning high part
13500 relocation, and has thus allowed orphaned R_MIPS_LO16 relocations to be
13501 placed anywhere. Rather than break backwards compatibility by changing
13502 this, it seems better not to force the issue, and instead keep the
13503 original symbol. This will work with either linker behavior. */
13504 if ((fixp
->fx_r_type
== BFD_RELOC_LO16
13505 || fixp
->fx_r_type
== BFD_RELOC_MIPS16_LO16
13506 || reloc_needs_lo_p (fixp
->fx_r_type
))
13507 && HAVE_IN_PLACE_ADDENDS
13508 && (S_GET_SEGMENT (fixp
->fx_addsy
)->flags
& SEC_MERGE
) != 0)
13512 /* Don't adjust relocations against mips16 symbols, so that the linker
13513 can find them if it needs to set up a stub. */
13515 && S_GET_OTHER (fixp
->fx_addsy
) == STO_MIPS16
13516 && fixp
->fx_subsy
== NULL
)
13523 /* Translate internal representation of relocation info to BFD target
13527 tc_gen_reloc (asection
*section ATTRIBUTE_UNUSED
, fixS
*fixp
)
13529 static arelent
*retval
[4];
13531 bfd_reloc_code_real_type code
;
13533 memset (retval
, 0, sizeof(retval
));
13534 reloc
= retval
[0] = (arelent
*) xcalloc (1, sizeof (arelent
));
13535 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
13536 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
13537 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
13539 if (fixp
->fx_pcrel
)
13541 assert (fixp
->fx_r_type
== BFD_RELOC_16_PCREL_S2
);
13543 /* At this point, fx_addnumber is "symbol offset - pcrel address".
13544 Relocations want only the symbol offset. */
13545 reloc
->addend
= fixp
->fx_addnumber
+ reloc
->address
;
13548 /* A gruesome hack which is a result of the gruesome gas
13549 reloc handling. What's worse, for COFF (as opposed to
13550 ECOFF), we might need yet another copy of reloc->address.
13551 See bfd_install_relocation. */
13552 reloc
->addend
+= reloc
->address
;
13556 reloc
->addend
= fixp
->fx_addnumber
;
13558 /* Since the old MIPS ELF ABI uses Rel instead of Rela, encode the vtable
13559 entry to be used in the relocation's section offset. */
13560 if (! HAVE_NEWABI
&& fixp
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
13562 reloc
->address
= reloc
->addend
;
13566 code
= fixp
->fx_r_type
;
13568 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
13569 if (reloc
->howto
== NULL
)
13571 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
13572 _("Can not represent %s relocation in this object file format"),
13573 bfd_get_reloc_code_name (code
));
13580 /* Relax a machine dependent frag. This returns the amount by which
13581 the current size of the frag should change. */
13584 mips_relax_frag (asection
*sec
, fragS
*fragp
, long stretch
)
13586 if (RELAX_BRANCH_P (fragp
->fr_subtype
))
13588 offsetT old_var
= fragp
->fr_var
;
13590 fragp
->fr_var
= relaxed_branch_length (fragp
, sec
, TRUE
);
13592 return fragp
->fr_var
- old_var
;
13595 if (! RELAX_MIPS16_P (fragp
->fr_subtype
))
13598 if (mips16_extended_frag (fragp
, NULL
, stretch
))
13600 if (RELAX_MIPS16_EXTENDED (fragp
->fr_subtype
))
13602 fragp
->fr_subtype
= RELAX_MIPS16_MARK_EXTENDED (fragp
->fr_subtype
);
13607 if (! RELAX_MIPS16_EXTENDED (fragp
->fr_subtype
))
13609 fragp
->fr_subtype
= RELAX_MIPS16_CLEAR_EXTENDED (fragp
->fr_subtype
);
13616 /* Convert a machine dependent frag. */
13619 md_convert_frag (bfd
*abfd ATTRIBUTE_UNUSED
, segT asec
, fragS
*fragp
)
13621 if (RELAX_BRANCH_P (fragp
->fr_subtype
))
13624 unsigned long insn
;
13628 buf
= (bfd_byte
*)fragp
->fr_literal
+ fragp
->fr_fix
;
13630 if (target_big_endian
)
13631 insn
= bfd_getb32 (buf
);
13633 insn
= bfd_getl32 (buf
);
13635 if (!RELAX_BRANCH_TOOFAR (fragp
->fr_subtype
))
13637 /* We generate a fixup instead of applying it right now
13638 because, if there are linker relaxations, we're going to
13639 need the relocations. */
13640 exp
.X_op
= O_symbol
;
13641 exp
.X_add_symbol
= fragp
->fr_symbol
;
13642 exp
.X_add_number
= fragp
->fr_offset
;
13644 fixp
= fix_new_exp (fragp
, buf
- (bfd_byte
*)fragp
->fr_literal
,
13645 4, &exp
, TRUE
, BFD_RELOC_16_PCREL_S2
);
13646 fixp
->fx_file
= fragp
->fr_file
;
13647 fixp
->fx_line
= fragp
->fr_line
;
13649 md_number_to_chars ((char *) buf
, insn
, 4);
13656 as_warn_where (fragp
->fr_file
, fragp
->fr_line
,
13657 _("relaxed out-of-range branch into a jump"));
13659 if (RELAX_BRANCH_UNCOND (fragp
->fr_subtype
))
13662 if (!RELAX_BRANCH_LIKELY (fragp
->fr_subtype
))
13664 /* Reverse the branch. */
13665 switch ((insn
>> 28) & 0xf)
13668 /* bc[0-3][tf]l? and bc1any[24][ft] instructions can
13669 have the condition reversed by tweaking a single
13670 bit, and their opcodes all have 0x4???????. */
13671 assert ((insn
& 0xf1000000) == 0x41000000);
13672 insn
^= 0x00010000;
13676 /* bltz 0x04000000 bgez 0x04010000
13677 bltzal 0x04100000 bgezal 0x04110000 */
13678 assert ((insn
& 0xfc0e0000) == 0x04000000);
13679 insn
^= 0x00010000;
13683 /* beq 0x10000000 bne 0x14000000
13684 blez 0x18000000 bgtz 0x1c000000 */
13685 insn
^= 0x04000000;
13693 if (RELAX_BRANCH_LINK (fragp
->fr_subtype
))
13695 /* Clear the and-link bit. */
13696 assert ((insn
& 0xfc1c0000) == 0x04100000);
13698 /* bltzal 0x04100000 bgezal 0x04110000
13699 bltzall 0x04120000 bgezall 0x04130000 */
13700 insn
&= ~0x00100000;
13703 /* Branch over the branch (if the branch was likely) or the
13704 full jump (not likely case). Compute the offset from the
13705 current instruction to branch to. */
13706 if (RELAX_BRANCH_LIKELY (fragp
->fr_subtype
))
13710 /* How many bytes in instructions we've already emitted? */
13711 i
= buf
- (bfd_byte
*)fragp
->fr_literal
- fragp
->fr_fix
;
13712 /* How many bytes in instructions from here to the end? */
13713 i
= fragp
->fr_var
- i
;
13715 /* Convert to instruction count. */
13717 /* Branch counts from the next instruction. */
13720 /* Branch over the jump. */
13721 md_number_to_chars ((char *) buf
, insn
, 4);
13725 md_number_to_chars ((char *) buf
, 0, 4);
13728 if (RELAX_BRANCH_LIKELY (fragp
->fr_subtype
))
13730 /* beql $0, $0, 2f */
13732 /* Compute the PC offset from the current instruction to
13733 the end of the variable frag. */
13734 /* How many bytes in instructions we've already emitted? */
13735 i
= buf
- (bfd_byte
*)fragp
->fr_literal
- fragp
->fr_fix
;
13736 /* How many bytes in instructions from here to the end? */
13737 i
= fragp
->fr_var
- i
;
13738 /* Convert to instruction count. */
13740 /* Don't decrement i, because we want to branch over the
13744 md_number_to_chars ((char *) buf
, insn
, 4);
13747 md_number_to_chars ((char *) buf
, 0, 4);
13752 if (mips_pic
== NO_PIC
)
13755 insn
= (RELAX_BRANCH_LINK (fragp
->fr_subtype
)
13756 ? 0x0c000000 : 0x08000000);
13757 exp
.X_op
= O_symbol
;
13758 exp
.X_add_symbol
= fragp
->fr_symbol
;
13759 exp
.X_add_number
= fragp
->fr_offset
;
13761 fixp
= fix_new_exp (fragp
, buf
- (bfd_byte
*)fragp
->fr_literal
,
13762 4, &exp
, FALSE
, BFD_RELOC_MIPS_JMP
);
13763 fixp
->fx_file
= fragp
->fr_file
;
13764 fixp
->fx_line
= fragp
->fr_line
;
13766 md_number_to_chars ((char *) buf
, insn
, 4);
13771 /* lw/ld $at, <sym>($gp) R_MIPS_GOT16 */
13772 insn
= HAVE_64BIT_ADDRESSES
? 0xdf810000 : 0x8f810000;
13773 exp
.X_op
= O_symbol
;
13774 exp
.X_add_symbol
= fragp
->fr_symbol
;
13775 exp
.X_add_number
= fragp
->fr_offset
;
13777 if (fragp
->fr_offset
)
13779 exp
.X_add_symbol
= make_expr_symbol (&exp
);
13780 exp
.X_add_number
= 0;
13783 fixp
= fix_new_exp (fragp
, buf
- (bfd_byte
*)fragp
->fr_literal
,
13784 4, &exp
, FALSE
, BFD_RELOC_MIPS_GOT16
);
13785 fixp
->fx_file
= fragp
->fr_file
;
13786 fixp
->fx_line
= fragp
->fr_line
;
13788 md_number_to_chars ((char *) buf
, insn
, 4);
13791 if (mips_opts
.isa
== ISA_MIPS1
)
13794 md_number_to_chars ((char *) buf
, 0, 4);
13798 /* d/addiu $at, $at, <sym> R_MIPS_LO16 */
13799 insn
= HAVE_64BIT_ADDRESSES
? 0x64210000 : 0x24210000;
13801 fixp
= fix_new_exp (fragp
, buf
- (bfd_byte
*)fragp
->fr_literal
,
13802 4, &exp
, FALSE
, BFD_RELOC_LO16
);
13803 fixp
->fx_file
= fragp
->fr_file
;
13804 fixp
->fx_line
= fragp
->fr_line
;
13806 md_number_to_chars ((char *) buf
, insn
, 4);
13810 if (RELAX_BRANCH_LINK (fragp
->fr_subtype
))
13815 md_number_to_chars ((char *) buf
, insn
, 4);
13820 assert (buf
== (bfd_byte
*)fragp
->fr_literal
13821 + fragp
->fr_fix
+ fragp
->fr_var
);
13823 fragp
->fr_fix
+= fragp
->fr_var
;
13828 if (RELAX_MIPS16_P (fragp
->fr_subtype
))
13831 const struct mips16_immed_operand
*op
;
13832 bfd_boolean small
, ext
;
13835 unsigned long insn
;
13836 bfd_boolean use_extend
;
13837 unsigned short extend
;
13839 type
= RELAX_MIPS16_TYPE (fragp
->fr_subtype
);
13840 op
= mips16_immed_operands
;
13841 while (op
->type
!= type
)
13844 if (RELAX_MIPS16_EXTENDED (fragp
->fr_subtype
))
13855 resolve_symbol_value (fragp
->fr_symbol
);
13856 val
= S_GET_VALUE (fragp
->fr_symbol
);
13861 addr
= fragp
->fr_address
+ fragp
->fr_fix
;
13863 /* The rules for the base address of a PC relative reloc are
13864 complicated; see mips16_extended_frag. */
13865 if (type
== 'p' || type
== 'q')
13870 /* Ignore the low bit in the target, since it will be
13871 set for a text label. */
13872 if ((val
& 1) != 0)
13875 else if (RELAX_MIPS16_JAL_DSLOT (fragp
->fr_subtype
))
13877 else if (RELAX_MIPS16_DSLOT (fragp
->fr_subtype
))
13880 addr
&= ~ (addressT
) ((1 << op
->shift
) - 1);
13883 /* Make sure the section winds up with the alignment we have
13886 record_alignment (asec
, op
->shift
);
13890 && (RELAX_MIPS16_JAL_DSLOT (fragp
->fr_subtype
)
13891 || RELAX_MIPS16_DSLOT (fragp
->fr_subtype
)))
13892 as_warn_where (fragp
->fr_file
, fragp
->fr_line
,
13893 _("extended instruction in delay slot"));
13895 buf
= (bfd_byte
*) (fragp
->fr_literal
+ fragp
->fr_fix
);
13897 if (target_big_endian
)
13898 insn
= bfd_getb16 (buf
);
13900 insn
= bfd_getl16 (buf
);
13902 mips16_immed (fragp
->fr_file
, fragp
->fr_line
, type
, val
,
13903 RELAX_MIPS16_USER_EXT (fragp
->fr_subtype
),
13904 small
, ext
, &insn
, &use_extend
, &extend
);
13908 md_number_to_chars ((char *) buf
, 0xf000 | extend
, 2);
13909 fragp
->fr_fix
+= 2;
13913 md_number_to_chars ((char *) buf
, insn
, 2);
13914 fragp
->fr_fix
+= 2;
13922 first
= RELAX_FIRST (fragp
->fr_subtype
);
13923 second
= RELAX_SECOND (fragp
->fr_subtype
);
13924 fixp
= (fixS
*) fragp
->fr_opcode
;
13926 /* Possibly emit a warning if we've chosen the longer option. */
13927 if (((fragp
->fr_subtype
& RELAX_USE_SECOND
) != 0)
13928 == ((fragp
->fr_subtype
& RELAX_SECOND_LONGER
) != 0))
13930 const char *msg
= macro_warning (fragp
->fr_subtype
);
13932 as_warn_where (fragp
->fr_file
, fragp
->fr_line
, msg
);
13935 /* Go through all the fixups for the first sequence. Disable them
13936 (by marking them as done) if we're going to use the second
13937 sequence instead. */
13939 && fixp
->fx_frag
== fragp
13940 && fixp
->fx_where
< fragp
->fr_fix
- second
)
13942 if (fragp
->fr_subtype
& RELAX_USE_SECOND
)
13944 fixp
= fixp
->fx_next
;
13947 /* Go through the fixups for the second sequence. Disable them if
13948 we're going to use the first sequence, otherwise adjust their
13949 addresses to account for the relaxation. */
13950 while (fixp
&& fixp
->fx_frag
== fragp
)
13952 if (fragp
->fr_subtype
& RELAX_USE_SECOND
)
13953 fixp
->fx_where
-= first
;
13956 fixp
= fixp
->fx_next
;
13959 /* Now modify the frag contents. */
13960 if (fragp
->fr_subtype
& RELAX_USE_SECOND
)
13964 start
= fragp
->fr_literal
+ fragp
->fr_fix
- first
- second
;
13965 memmove (start
, start
+ first
, second
);
13966 fragp
->fr_fix
-= first
;
13969 fragp
->fr_fix
-= second
;
13975 /* This function is called after the relocs have been generated.
13976 We've been storing mips16 text labels as odd. Here we convert them
13977 back to even for the convenience of the debugger. */
13980 mips_frob_file_after_relocs (void)
13983 unsigned int count
, i
;
13988 syms
= bfd_get_outsymbols (stdoutput
);
13989 count
= bfd_get_symcount (stdoutput
);
13990 for (i
= 0; i
< count
; i
++, syms
++)
13992 if (elf_symbol (*syms
)->internal_elf_sym
.st_other
== STO_MIPS16
13993 && ((*syms
)->value
& 1) != 0)
13995 (*syms
)->value
&= ~1;
13996 /* If the symbol has an odd size, it was probably computed
13997 incorrectly, so adjust that as well. */
13998 if ((elf_symbol (*syms
)->internal_elf_sym
.st_size
& 1) != 0)
13999 ++elf_symbol (*syms
)->internal_elf_sym
.st_size
;
14006 /* This function is called whenever a label is defined. It is used
14007 when handling branch delays; if a branch has a label, we assume we
14008 can not move it. */
14011 mips_define_label (symbolS
*sym
)
14013 segment_info_type
*si
= seg_info (now_seg
);
14014 struct insn_label_list
*l
;
14016 if (free_insn_labels
== NULL
)
14017 l
= (struct insn_label_list
*) xmalloc (sizeof *l
);
14020 l
= free_insn_labels
;
14021 free_insn_labels
= l
->next
;
14025 l
->next
= si
->label_list
;
14026 si
->label_list
= l
;
14029 dwarf2_emit_label (sym
);
14033 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
14035 /* Some special processing for a MIPS ELF file. */
14038 mips_elf_final_processing (void)
14040 /* Write out the register information. */
14041 if (mips_abi
!= N64_ABI
)
14045 s
.ri_gprmask
= mips_gprmask
;
14046 s
.ri_cprmask
[0] = mips_cprmask
[0];
14047 s
.ri_cprmask
[1] = mips_cprmask
[1];
14048 s
.ri_cprmask
[2] = mips_cprmask
[2];
14049 s
.ri_cprmask
[3] = mips_cprmask
[3];
14050 /* The gp_value field is set by the MIPS ELF backend. */
14052 bfd_mips_elf32_swap_reginfo_out (stdoutput
, &s
,
14053 ((Elf32_External_RegInfo
*)
14054 mips_regmask_frag
));
14058 Elf64_Internal_RegInfo s
;
14060 s
.ri_gprmask
= mips_gprmask
;
14062 s
.ri_cprmask
[0] = mips_cprmask
[0];
14063 s
.ri_cprmask
[1] = mips_cprmask
[1];
14064 s
.ri_cprmask
[2] = mips_cprmask
[2];
14065 s
.ri_cprmask
[3] = mips_cprmask
[3];
14066 /* The gp_value field is set by the MIPS ELF backend. */
14068 bfd_mips_elf64_swap_reginfo_out (stdoutput
, &s
,
14069 ((Elf64_External_RegInfo
*)
14070 mips_regmask_frag
));
14073 /* Set the MIPS ELF flag bits. FIXME: There should probably be some
14074 sort of BFD interface for this. */
14075 if (mips_any_noreorder
)
14076 elf_elfheader (stdoutput
)->e_flags
|= EF_MIPS_NOREORDER
;
14077 if (mips_pic
!= NO_PIC
)
14079 elf_elfheader (stdoutput
)->e_flags
|= EF_MIPS_PIC
;
14080 elf_elfheader (stdoutput
)->e_flags
|= EF_MIPS_CPIC
;
14083 elf_elfheader (stdoutput
)->e_flags
|= EF_MIPS_CPIC
;
14085 /* Set MIPS ELF flags for ASEs. */
14086 /* We may need to define a new flag for DSP ASE, and set this flag when
14087 file_ase_dsp is true. */
14088 /* We may need to define a new flag for MT ASE, and set this flag when
14089 file_ase_mt is true. */
14090 if (file_ase_mips16
)
14091 elf_elfheader (stdoutput
)->e_flags
|= EF_MIPS_ARCH_ASE_M16
;
14092 #if 0 /* XXX FIXME */
14093 if (file_ase_mips3d
)
14094 elf_elfheader (stdoutput
)->e_flags
|= ???;
14097 elf_elfheader (stdoutput
)->e_flags
|= EF_MIPS_ARCH_ASE_MDMX
;
14099 /* Set the MIPS ELF ABI flags. */
14100 if (mips_abi
== O32_ABI
&& USE_E_MIPS_ABI_O32
)
14101 elf_elfheader (stdoutput
)->e_flags
|= E_MIPS_ABI_O32
;
14102 else if (mips_abi
== O64_ABI
)
14103 elf_elfheader (stdoutput
)->e_flags
|= E_MIPS_ABI_O64
;
14104 else if (mips_abi
== EABI_ABI
)
14106 if (!file_mips_gp32
)
14107 elf_elfheader (stdoutput
)->e_flags
|= E_MIPS_ABI_EABI64
;
14109 elf_elfheader (stdoutput
)->e_flags
|= E_MIPS_ABI_EABI32
;
14111 else if (mips_abi
== N32_ABI
)
14112 elf_elfheader (stdoutput
)->e_flags
|= EF_MIPS_ABI2
;
14114 /* Nothing to do for N64_ABI. */
14116 if (mips_32bitmode
)
14117 elf_elfheader (stdoutput
)->e_flags
|= EF_MIPS_32BITMODE
;
14119 #if 0 /* XXX FIXME */
14120 /* 32 bit code with 64 bit FP registers. */
14121 if (!file_mips_fp32
&& ABI_NEEDS_32BIT_REGS (mips_abi
))
14122 elf_elfheader (stdoutput
)->e_flags
|= ???;
14126 #endif /* OBJ_ELF || OBJ_MAYBE_ELF */
14128 typedef struct proc
{
14130 symbolS
*func_end_sym
;
14131 unsigned long reg_mask
;
14132 unsigned long reg_offset
;
14133 unsigned long fpreg_mask
;
14134 unsigned long fpreg_offset
;
14135 unsigned long frame_offset
;
14136 unsigned long frame_reg
;
14137 unsigned long pc_reg
;
14140 static procS cur_proc
;
14141 static procS
*cur_proc_ptr
;
14142 static int numprocs
;
14144 /* Fill in an rs_align_code fragment. */
14147 mips_handle_align (fragS
*fragp
)
14149 if (fragp
->fr_type
!= rs_align_code
)
14152 if (mips_opts
.mips16
)
14154 static const unsigned char be_nop
[] = { 0x65, 0x00 };
14155 static const unsigned char le_nop
[] = { 0x00, 0x65 };
14160 bytes
= fragp
->fr_next
->fr_address
- fragp
->fr_address
- fragp
->fr_fix
;
14161 p
= fragp
->fr_literal
+ fragp
->fr_fix
;
14169 memcpy (p
, (target_big_endian
? be_nop
: le_nop
), 2);
14173 /* For mips32, a nop is a zero, which we trivially get by doing nothing. */
14177 md_obj_begin (void)
14184 /* Check for premature end, nesting errors, etc. */
14186 as_warn (_("missing .end at end of assembly"));
14195 if (*input_line_pointer
== '-')
14197 ++input_line_pointer
;
14200 if (!ISDIGIT (*input_line_pointer
))
14201 as_bad (_("expected simple number"));
14202 if (input_line_pointer
[0] == '0')
14204 if (input_line_pointer
[1] == 'x')
14206 input_line_pointer
+= 2;
14207 while (ISXDIGIT (*input_line_pointer
))
14210 val
|= hex_value (*input_line_pointer
++);
14212 return negative
? -val
: val
;
14216 ++input_line_pointer
;
14217 while (ISDIGIT (*input_line_pointer
))
14220 val
|= *input_line_pointer
++ - '0';
14222 return negative
? -val
: val
;
14225 if (!ISDIGIT (*input_line_pointer
))
14227 printf (_(" *input_line_pointer == '%c' 0x%02x\n"),
14228 *input_line_pointer
, *input_line_pointer
);
14229 as_warn (_("invalid number"));
14232 while (ISDIGIT (*input_line_pointer
))
14235 val
+= *input_line_pointer
++ - '0';
14237 return negative
? -val
: val
;
14240 /* The .file directive; just like the usual .file directive, but there
14241 is an initial number which is the ECOFF file index. In the non-ECOFF
14242 case .file implies DWARF-2. */
14245 s_mips_file (int x ATTRIBUTE_UNUSED
)
14247 static int first_file_directive
= 0;
14249 if (ECOFF_DEBUGGING
)
14258 filename
= dwarf2_directive_file (0);
14260 /* Versions of GCC up to 3.1 start files with a ".file"
14261 directive even for stabs output. Make sure that this
14262 ".file" is handled. Note that you need a version of GCC
14263 after 3.1 in order to support DWARF-2 on MIPS. */
14264 if (filename
!= NULL
&& ! first_file_directive
)
14266 (void) new_logical_line (filename
, -1);
14267 s_app_file_string (filename
, 0);
14269 first_file_directive
= 1;
14273 /* The .loc directive, implying DWARF-2. */
14276 s_mips_loc (int x ATTRIBUTE_UNUSED
)
14278 if (!ECOFF_DEBUGGING
)
14279 dwarf2_directive_loc (0);
14282 /* The .end directive. */
14285 s_mips_end (int x ATTRIBUTE_UNUSED
)
14289 /* Following functions need their own .frame and .cprestore directives. */
14290 mips_frame_reg_valid
= 0;
14291 mips_cprestore_valid
= 0;
14293 if (!is_end_of_line
[(unsigned char) *input_line_pointer
])
14296 demand_empty_rest_of_line ();
14301 if ((bfd_get_section_flags (stdoutput
, now_seg
) & SEC_CODE
) == 0)
14302 as_warn (_(".end not in text section"));
14306 as_warn (_(".end directive without a preceding .ent directive."));
14307 demand_empty_rest_of_line ();
14313 assert (S_GET_NAME (p
));
14314 if (strcmp (S_GET_NAME (p
), S_GET_NAME (cur_proc_ptr
->func_sym
)))
14315 as_warn (_(".end symbol does not match .ent symbol."));
14317 if (debug_type
== DEBUG_STABS
)
14318 stabs_generate_asm_endfunc (S_GET_NAME (p
),
14322 as_warn (_(".end directive missing or unknown symbol"));
14325 /* Create an expression to calculate the size of the function. */
14326 if (p
&& cur_proc_ptr
)
14328 OBJ_SYMFIELD_TYPE
*obj
= symbol_get_obj (p
);
14329 expressionS
*exp
= xmalloc (sizeof (expressionS
));
14332 exp
->X_op
= O_subtract
;
14333 exp
->X_add_symbol
= symbol_temp_new_now ();
14334 exp
->X_op_symbol
= p
;
14335 exp
->X_add_number
= 0;
14337 cur_proc_ptr
->func_end_sym
= exp
->X_add_symbol
;
14340 /* Generate a .pdr section. */
14341 if (IS_ELF
&& !ECOFF_DEBUGGING
&& mips_flag_pdr
)
14343 segT saved_seg
= now_seg
;
14344 subsegT saved_subseg
= now_subseg
;
14349 dot
= frag_now_fix ();
14351 #ifdef md_flush_pending_output
14352 md_flush_pending_output ();
14356 subseg_set (pdr_seg
, 0);
14358 /* Write the symbol. */
14359 exp
.X_op
= O_symbol
;
14360 exp
.X_add_symbol
= p
;
14361 exp
.X_add_number
= 0;
14362 emit_expr (&exp
, 4);
14364 fragp
= frag_more (7 * 4);
14366 md_number_to_chars (fragp
, cur_proc_ptr
->reg_mask
, 4);
14367 md_number_to_chars (fragp
+ 4, cur_proc_ptr
->reg_offset
, 4);
14368 md_number_to_chars (fragp
+ 8, cur_proc_ptr
->fpreg_mask
, 4);
14369 md_number_to_chars (fragp
+ 12, cur_proc_ptr
->fpreg_offset
, 4);
14370 md_number_to_chars (fragp
+ 16, cur_proc_ptr
->frame_offset
, 4);
14371 md_number_to_chars (fragp
+ 20, cur_proc_ptr
->frame_reg
, 4);
14372 md_number_to_chars (fragp
+ 24, cur_proc_ptr
->pc_reg
, 4);
14374 subseg_set (saved_seg
, saved_subseg
);
14376 #endif /* OBJ_ELF */
14378 cur_proc_ptr
= NULL
;
14381 /* The .aent and .ent directives. */
14384 s_mips_ent (int aent
)
14388 symbolP
= get_symbol ();
14389 if (*input_line_pointer
== ',')
14390 ++input_line_pointer
;
14391 SKIP_WHITESPACE ();
14392 if (ISDIGIT (*input_line_pointer
)
14393 || *input_line_pointer
== '-')
14396 if ((bfd_get_section_flags (stdoutput
, now_seg
) & SEC_CODE
) == 0)
14397 as_warn (_(".ent or .aent not in text section."));
14399 if (!aent
&& cur_proc_ptr
)
14400 as_warn (_("missing .end"));
14404 /* This function needs its own .frame and .cprestore directives. */
14405 mips_frame_reg_valid
= 0;
14406 mips_cprestore_valid
= 0;
14408 cur_proc_ptr
= &cur_proc
;
14409 memset (cur_proc_ptr
, '\0', sizeof (procS
));
14411 cur_proc_ptr
->func_sym
= symbolP
;
14413 symbol_get_bfdsym (symbolP
)->flags
|= BSF_FUNCTION
;
14417 if (debug_type
== DEBUG_STABS
)
14418 stabs_generate_asm_func (S_GET_NAME (symbolP
),
14419 S_GET_NAME (symbolP
));
14422 demand_empty_rest_of_line ();
14425 /* The .frame directive. If the mdebug section is present (IRIX 5 native)
14426 then ecoff.c (ecoff_directive_frame) is used. For embedded targets,
14427 s_mips_frame is used so that we can set the PDR information correctly.
14428 We can't use the ecoff routines because they make reference to the ecoff
14429 symbol table (in the mdebug section). */
14432 s_mips_frame (int ignore ATTRIBUTE_UNUSED
)
14435 if (IS_ELF
&& !ECOFF_DEBUGGING
)
14439 if (cur_proc_ptr
== (procS
*) NULL
)
14441 as_warn (_(".frame outside of .ent"));
14442 demand_empty_rest_of_line ();
14446 cur_proc_ptr
->frame_reg
= tc_get_register (1);
14448 SKIP_WHITESPACE ();
14449 if (*input_line_pointer
++ != ','
14450 || get_absolute_expression_and_terminator (&val
) != ',')
14452 as_warn (_("Bad .frame directive"));
14453 --input_line_pointer
;
14454 demand_empty_rest_of_line ();
14458 cur_proc_ptr
->frame_offset
= val
;
14459 cur_proc_ptr
->pc_reg
= tc_get_register (0);
14461 demand_empty_rest_of_line ();
14464 #endif /* OBJ_ELF */
14468 /* The .fmask and .mask directives. If the mdebug section is present
14469 (IRIX 5 native) then ecoff.c (ecoff_directive_mask) is used. For
14470 embedded targets, s_mips_mask is used so that we can set the PDR
14471 information correctly. We can't use the ecoff routines because they
14472 make reference to the ecoff symbol table (in the mdebug section). */
14475 s_mips_mask (int reg_type
)
14478 if (IS_ELF
&& !ECOFF_DEBUGGING
)
14482 if (cur_proc_ptr
== (procS
*) NULL
)
14484 as_warn (_(".mask/.fmask outside of .ent"));
14485 demand_empty_rest_of_line ();
14489 if (get_absolute_expression_and_terminator (&mask
) != ',')
14491 as_warn (_("Bad .mask/.fmask directive"));
14492 --input_line_pointer
;
14493 demand_empty_rest_of_line ();
14497 off
= get_absolute_expression ();
14499 if (reg_type
== 'F')
14501 cur_proc_ptr
->fpreg_mask
= mask
;
14502 cur_proc_ptr
->fpreg_offset
= off
;
14506 cur_proc_ptr
->reg_mask
= mask
;
14507 cur_proc_ptr
->reg_offset
= off
;
14510 demand_empty_rest_of_line ();
14513 #endif /* OBJ_ELF */
14514 s_ignore (reg_type
);
14517 /* A table describing all the processors gas knows about. Names are
14518 matched in the order listed.
14520 To ease comparison, please keep this table in the same order as
14521 gcc's mips_cpu_info_table[]. */
14522 static const struct mips_cpu_info mips_cpu_info_table
[] =
14524 /* Entries for generic ISAs */
14525 { "mips1", MIPS_CPU_IS_ISA
, ISA_MIPS1
, CPU_R3000
},
14526 { "mips2", MIPS_CPU_IS_ISA
, ISA_MIPS2
, CPU_R6000
},
14527 { "mips3", MIPS_CPU_IS_ISA
, ISA_MIPS3
, CPU_R4000
},
14528 { "mips4", MIPS_CPU_IS_ISA
, ISA_MIPS4
, CPU_R8000
},
14529 { "mips5", MIPS_CPU_IS_ISA
, ISA_MIPS5
, CPU_MIPS5
},
14530 { "mips32", MIPS_CPU_IS_ISA
, ISA_MIPS32
, CPU_MIPS32
},
14531 { "mips32r2", MIPS_CPU_IS_ISA
, ISA_MIPS32R2
, CPU_MIPS32R2
},
14532 { "mips64", MIPS_CPU_IS_ISA
, ISA_MIPS64
, CPU_MIPS64
},
14533 { "mips64r2", MIPS_CPU_IS_ISA
, ISA_MIPS64R2
, CPU_MIPS64R2
},
14536 { "r3000", 0, ISA_MIPS1
, CPU_R3000
},
14537 { "r2000", 0, ISA_MIPS1
, CPU_R3000
},
14538 { "r3900", 0, ISA_MIPS1
, CPU_R3900
},
14541 { "r6000", 0, ISA_MIPS2
, CPU_R6000
},
14544 { "r4000", 0, ISA_MIPS3
, CPU_R4000
},
14545 { "r4010", 0, ISA_MIPS2
, CPU_R4010
},
14546 { "vr4100", 0, ISA_MIPS3
, CPU_VR4100
},
14547 { "vr4111", 0, ISA_MIPS3
, CPU_R4111
},
14548 { "vr4120", 0, ISA_MIPS3
, CPU_VR4120
},
14549 { "vr4130", 0, ISA_MIPS3
, CPU_VR4120
},
14550 { "vr4181", 0, ISA_MIPS3
, CPU_R4111
},
14551 { "vr4300", 0, ISA_MIPS3
, CPU_R4300
},
14552 { "r4400", 0, ISA_MIPS3
, CPU_R4400
},
14553 { "r4600", 0, ISA_MIPS3
, CPU_R4600
},
14554 { "orion", 0, ISA_MIPS3
, CPU_R4600
},
14555 { "r4650", 0, ISA_MIPS3
, CPU_R4650
},
14558 { "r8000", 0, ISA_MIPS4
, CPU_R8000
},
14559 { "r10000", 0, ISA_MIPS4
, CPU_R10000
},
14560 { "r12000", 0, ISA_MIPS4
, CPU_R12000
},
14561 { "vr5000", 0, ISA_MIPS4
, CPU_R5000
},
14562 { "vr5400", 0, ISA_MIPS4
, CPU_VR5400
},
14563 { "vr5500", 0, ISA_MIPS4
, CPU_VR5500
},
14564 { "rm5200", 0, ISA_MIPS4
, CPU_R5000
},
14565 { "rm5230", 0, ISA_MIPS4
, CPU_R5000
},
14566 { "rm5231", 0, ISA_MIPS4
, CPU_R5000
},
14567 { "rm5261", 0, ISA_MIPS4
, CPU_R5000
},
14568 { "rm5721", 0, ISA_MIPS4
, CPU_R5000
},
14569 { "rm7000", 0, ISA_MIPS4
, CPU_RM7000
},
14570 { "rm9000", 0, ISA_MIPS4
, CPU_RM9000
},
14573 { "4kc", 0, ISA_MIPS32
, CPU_MIPS32
},
14574 { "4km", 0, ISA_MIPS32
, CPU_MIPS32
},
14575 { "4kp", 0, ISA_MIPS32
, CPU_MIPS32
},
14576 { "4ksc", MIPS_CPU_ASE_SMARTMIPS
, ISA_MIPS32
, CPU_MIPS32
},
14578 /* MIPS 32 Release 2 */
14579 { "4kec", 0, ISA_MIPS32R2
, CPU_MIPS32R2
},
14580 { "4kem", 0, ISA_MIPS32R2
, CPU_MIPS32R2
},
14581 { "4kep", 0, ISA_MIPS32R2
, CPU_MIPS32R2
},
14582 { "4ksd", MIPS_CPU_ASE_SMARTMIPS
, ISA_MIPS32R2
, CPU_MIPS32R2
},
14583 { "m4k", 0, ISA_MIPS32R2
, CPU_MIPS32R2
},
14584 { "m4kp", 0, ISA_MIPS32R2
, CPU_MIPS32R2
},
14585 { "24kc", 0, ISA_MIPS32R2
, CPU_MIPS32R2
},
14586 { "24kf", 0, ISA_MIPS32R2
, CPU_MIPS32R2
},
14587 { "24kx", 0, ISA_MIPS32R2
, CPU_MIPS32R2
},
14588 /* 24ke is a 24k with DSP ASE, other ASEs are optional. */
14589 { "24kec", MIPS_CPU_ASE_DSP
, ISA_MIPS32R2
, CPU_MIPS32R2
},
14590 { "24kef", MIPS_CPU_ASE_DSP
, ISA_MIPS32R2
, CPU_MIPS32R2
},
14591 { "24kex", MIPS_CPU_ASE_DSP
, ISA_MIPS32R2
, CPU_MIPS32R2
},
14592 /* 34k is a 24k with DSP and MT ASE, other ASEs are optional. */
14593 { "34kc", MIPS_CPU_ASE_DSP
| MIPS_CPU_ASE_MT
,
14594 ISA_MIPS32R2
, CPU_MIPS32R2
},
14595 { "34kf", MIPS_CPU_ASE_DSP
| MIPS_CPU_ASE_MT
,
14596 ISA_MIPS32R2
, CPU_MIPS32R2
},
14597 { "34kx", MIPS_CPU_ASE_DSP
| MIPS_CPU_ASE_MT
,
14598 ISA_MIPS32R2
, CPU_MIPS32R2
},
14601 { "5kc", 0, ISA_MIPS64
, CPU_MIPS64
},
14602 { "5kf", 0, ISA_MIPS64
, CPU_MIPS64
},
14603 { "20kc", MIPS_CPU_ASE_MIPS3D
, ISA_MIPS64
, CPU_MIPS64
},
14604 { "25kf", MIPS_CPU_ASE_MIPS3D
, ISA_MIPS64
, CPU_MIPS64
},
14606 /* MIPS 64 Release 2 */
14608 /* Broadcom SB-1 CPU core */
14609 { "sb1", MIPS_CPU_ASE_MIPS3D
| MIPS_CPU_ASE_MDMX
,
14610 ISA_MIPS64
, CPU_SB1
},
14611 /* Broadcom SB-1A CPU core */
14612 { "sb1a", MIPS_CPU_ASE_MIPS3D
| MIPS_CPU_ASE_MDMX
,
14613 ISA_MIPS64
, CPU_SB1
},
14620 /* Return true if GIVEN is the same as CANONICAL, or if it is CANONICAL
14621 with a final "000" replaced by "k". Ignore case.
14623 Note: this function is shared between GCC and GAS. */
14626 mips_strict_matching_cpu_name_p (const char *canonical
, const char *given
)
14628 while (*given
!= 0 && TOLOWER (*given
) == TOLOWER (*canonical
))
14629 given
++, canonical
++;
14631 return ((*given
== 0 && *canonical
== 0)
14632 || (strcmp (canonical
, "000") == 0 && strcasecmp (given
, "k") == 0));
14636 /* Return true if GIVEN matches CANONICAL, where GIVEN is a user-supplied
14637 CPU name. We've traditionally allowed a lot of variation here.
14639 Note: this function is shared between GCC and GAS. */
14642 mips_matching_cpu_name_p (const char *canonical
, const char *given
)
14644 /* First see if the name matches exactly, or with a final "000"
14645 turned into "k". */
14646 if (mips_strict_matching_cpu_name_p (canonical
, given
))
14649 /* If not, try comparing based on numerical designation alone.
14650 See if GIVEN is an unadorned number, or 'r' followed by a number. */
14651 if (TOLOWER (*given
) == 'r')
14653 if (!ISDIGIT (*given
))
14656 /* Skip over some well-known prefixes in the canonical name,
14657 hoping to find a number there too. */
14658 if (TOLOWER (canonical
[0]) == 'v' && TOLOWER (canonical
[1]) == 'r')
14660 else if (TOLOWER (canonical
[0]) == 'r' && TOLOWER (canonical
[1]) == 'm')
14662 else if (TOLOWER (canonical
[0]) == 'r')
14665 return mips_strict_matching_cpu_name_p (canonical
, given
);
14669 /* Parse an option that takes the name of a processor as its argument.
14670 OPTION is the name of the option and CPU_STRING is the argument.
14671 Return the corresponding processor enumeration if the CPU_STRING is
14672 recognized, otherwise report an error and return null.
14674 A similar function exists in GCC. */
14676 static const struct mips_cpu_info
*
14677 mips_parse_cpu (const char *option
, const char *cpu_string
)
14679 const struct mips_cpu_info
*p
;
14681 /* 'from-abi' selects the most compatible architecture for the given
14682 ABI: MIPS I for 32-bit ABIs and MIPS III for 64-bit ABIs. For the
14683 EABIs, we have to decide whether we're using the 32-bit or 64-bit
14684 version. Look first at the -mgp options, if given, otherwise base
14685 the choice on MIPS_DEFAULT_64BIT.
14687 Treat NO_ABI like the EABIs. One reason to do this is that the
14688 plain 'mips' and 'mips64' configs have 'from-abi' as their default
14689 architecture. This code picks MIPS I for 'mips' and MIPS III for
14690 'mips64', just as we did in the days before 'from-abi'. */
14691 if (strcasecmp (cpu_string
, "from-abi") == 0)
14693 if (ABI_NEEDS_32BIT_REGS (mips_abi
))
14694 return mips_cpu_info_from_isa (ISA_MIPS1
);
14696 if (ABI_NEEDS_64BIT_REGS (mips_abi
))
14697 return mips_cpu_info_from_isa (ISA_MIPS3
);
14699 if (file_mips_gp32
>= 0)
14700 return mips_cpu_info_from_isa (file_mips_gp32
? ISA_MIPS1
: ISA_MIPS3
);
14702 return mips_cpu_info_from_isa (MIPS_DEFAULT_64BIT
14707 /* 'default' has traditionally been a no-op. Probably not very useful. */
14708 if (strcasecmp (cpu_string
, "default") == 0)
14711 for (p
= mips_cpu_info_table
; p
->name
!= 0; p
++)
14712 if (mips_matching_cpu_name_p (p
->name
, cpu_string
))
14715 as_bad ("Bad value (%s) for %s", cpu_string
, option
);
14719 /* Return the canonical processor information for ISA (a member of the
14720 ISA_MIPS* enumeration). */
14722 static const struct mips_cpu_info
*
14723 mips_cpu_info_from_isa (int isa
)
14727 for (i
= 0; mips_cpu_info_table
[i
].name
!= NULL
; i
++)
14728 if ((mips_cpu_info_table
[i
].flags
& MIPS_CPU_IS_ISA
)
14729 && isa
== mips_cpu_info_table
[i
].isa
)
14730 return (&mips_cpu_info_table
[i
]);
14735 static const struct mips_cpu_info
*
14736 mips_cpu_info_from_arch (int arch
)
14740 for (i
= 0; mips_cpu_info_table
[i
].name
!= NULL
; i
++)
14741 if (arch
== mips_cpu_info_table
[i
].cpu
)
14742 return (&mips_cpu_info_table
[i
]);
14748 show (FILE *stream
, const char *string
, int *col_p
, int *first_p
)
14752 fprintf (stream
, "%24s", "");
14757 fprintf (stream
, ", ");
14761 if (*col_p
+ strlen (string
) > 72)
14763 fprintf (stream
, "\n%24s", "");
14767 fprintf (stream
, "%s", string
);
14768 *col_p
+= strlen (string
);
14774 md_show_usage (FILE *stream
)
14779 fprintf (stream
, _("\
14781 -EB generate big endian output\n\
14782 -EL generate little endian output\n\
14783 -g, -g2 do not remove unneeded NOPs or swap branches\n\
14784 -G NUM allow referencing objects up to NUM bytes\n\
14785 implicitly with the gp register [default 8]\n"));
14786 fprintf (stream
, _("\
14787 -mips1 generate MIPS ISA I instructions\n\
14788 -mips2 generate MIPS ISA II instructions\n\
14789 -mips3 generate MIPS ISA III instructions\n\
14790 -mips4 generate MIPS ISA IV instructions\n\
14791 -mips5 generate MIPS ISA V instructions\n\
14792 -mips32 generate MIPS32 ISA instructions\n\
14793 -mips32r2 generate MIPS32 release 2 ISA instructions\n\
14794 -mips64 generate MIPS64 ISA instructions\n\
14795 -mips64r2 generate MIPS64 release 2 ISA instructions\n\
14796 -march=CPU/-mtune=CPU generate code/schedule for CPU, where CPU is one of:\n"));
14800 for (i
= 0; mips_cpu_info_table
[i
].name
!= NULL
; i
++)
14801 show (stream
, mips_cpu_info_table
[i
].name
, &column
, &first
);
14802 show (stream
, "from-abi", &column
, &first
);
14803 fputc ('\n', stream
);
14805 fprintf (stream
, _("\
14806 -mCPU equivalent to -march=CPU -mtune=CPU. Deprecated.\n\
14807 -no-mCPU don't generate code specific to CPU.\n\
14808 For -mCPU and -no-mCPU, CPU must be one of:\n"));
14812 show (stream
, "3900", &column
, &first
);
14813 show (stream
, "4010", &column
, &first
);
14814 show (stream
, "4100", &column
, &first
);
14815 show (stream
, "4650", &column
, &first
);
14816 fputc ('\n', stream
);
14818 fprintf (stream
, _("\
14819 -mips16 generate mips16 instructions\n\
14820 -no-mips16 do not generate mips16 instructions\n"));
14821 fprintf (stream
, _("\
14822 -msmartmips generate smartmips instructions\n\
14823 -mno-smartmips do not generate smartmips instructions\n"));
14824 fprintf (stream
, _("\
14825 -mdsp generate DSP instructions\n\
14826 -mno-dsp do not generate DSP instructions\n"));
14827 fprintf (stream
, _("\
14828 -mmt generate MT instructions\n\
14829 -mno-mt do not generate MT instructions\n"));
14830 fprintf (stream
, _("\
14831 -mfix-vr4120 work around certain VR4120 errata\n\
14832 -mfix-vr4130 work around VR4130 mflo/mfhi errata\n\
14833 -mgp32 use 32-bit GPRs, regardless of the chosen ISA\n\
14834 -mfp32 use 32-bit FPRs, regardless of the chosen ISA\n\
14835 -msym32 assume all symbols have 32-bit values\n\
14836 -O0 remove unneeded NOPs, do not swap branches\n\
14837 -O remove unneeded NOPs and swap branches\n\
14838 --[no-]construct-floats [dis]allow floating point values to be constructed\n\
14839 --trap, --no-break trap exception on div by 0 and mult overflow\n\
14840 --break, --no-trap break exception on div by 0 and mult overflow\n"));
14842 fprintf (stream
, _("\
14843 -KPIC, -call_shared generate SVR4 position independent code\n\
14844 -non_shared do not generate position independent code\n\
14845 -xgot assume a 32 bit GOT\n\
14846 -mpdr, -mno-pdr enable/disable creation of .pdr sections\n\
14847 -mshared, -mno-shared disable/enable .cpload optimization for\n\
14848 position dependent (non shared) code\n\
14849 -mabi=ABI create ABI conformant object file for:\n"));
14853 show (stream
, "32", &column
, &first
);
14854 show (stream
, "o64", &column
, &first
);
14855 show (stream
, "n32", &column
, &first
);
14856 show (stream
, "64", &column
, &first
);
14857 show (stream
, "eabi", &column
, &first
);
14859 fputc ('\n', stream
);
14861 fprintf (stream
, _("\
14862 -32 create o32 ABI object file (default)\n\
14863 -n32 create n32 ABI object file\n\
14864 -64 create 64 ABI object file\n"));
14869 mips_dwarf2_format (void)
14871 if (mips_abi
== N64_ABI
)
14874 return dwarf2_format_64bit_irix
;
14876 return dwarf2_format_64bit
;
14880 return dwarf2_format_32bit
;
14884 mips_dwarf2_addr_size (void)
14886 if (mips_abi
== N64_ABI
)
14892 /* Standard calling conventions leave the CFA at SP on entry. */
14894 mips_cfi_frame_initial_instructions (void)
14896 cfi_add_CFA_def_cfa_register (SP
);
14900 tc_mips_regname_to_dw2regnum (char *regname
)
14902 unsigned int regnum
= -1;
14905 if (reg_lookup (®name
, RTYPE_GP
| RTYPE_NUM
, ®
))