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 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"
33 #include "opcode/mips.h"
35 #include "dwarf2dbg.h"
36 #include "dw2gencfi.h"
39 #define DBG(x) printf x
45 /* Clean up namespace so we can include obj-elf.h too. */
46 static int mips_output_flavor (void);
47 static int mips_output_flavor (void) { return OUTPUT_FLAVOR; }
48 #undef OBJ_PROCESS_STAB
55 #undef obj_frob_file_after_relocs
56 #undef obj_frob_symbol
58 #undef obj_sec_sym_ok_for_reloc
59 #undef OBJ_COPY_SYMBOL_ATTRIBUTES
62 /* Fix any of them that we actually care about. */
64 #define OUTPUT_FLAVOR mips_output_flavor()
71 #ifndef ECOFF_DEBUGGING
72 #define NO_ECOFF_DEBUGGING
73 #define ECOFF_DEBUGGING 0
76 int mips_flag_mdebug = -1;
78 /* Control generation of .pdr sections. Off by default on IRIX: the native
79 linker doesn't know about and discards them, but relocations against them
80 remain, leading to rld crashes. */
82 int mips_flag_pdr = FALSE;
84 int mips_flag_pdr = TRUE;
89 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
90 static char *mips_regmask_frag;
96 #define PIC_CALL_REG 25
104 #define ILLEGAL_REG (32)
106 /* Allow override of standard little-endian ECOFF format. */
108 #ifndef ECOFF_LITTLE_FORMAT
109 #define ECOFF_LITTLE_FORMAT "ecoff-littlemips"
112 extern int target_big_endian;
114 /* The name of the readonly data section. */
115 #define RDATA_SECTION_NAME (OUTPUT_FLAVOR == bfd_target_ecoff_flavour \
117 : OUTPUT_FLAVOR == bfd_target_coff_flavour \
119 : OUTPUT_FLAVOR == bfd_target_elf_flavour \
123 /* Information about an instruction, including its format, operands
127 /* The opcode's entry in mips_opcodes or mips16_opcodes. */
128 const struct mips_opcode *insn_mo;
130 /* True if this is a mips16 instruction and if we want the extended
132 bfd_boolean use_extend;
134 /* The 16-bit extension instruction to use when USE_EXTEND is true. */
135 unsigned short extend;
137 /* The 16-bit or 32-bit bitstring of the instruction itself. This is
138 a copy of INSN_MO->match with the operands filled in. */
139 unsigned long insn_opcode;
141 /* The frag that contains the instruction. */
144 /* The offset into FRAG of the first instruction byte. */
147 /* The relocs associated with the instruction, if any. */
150 /* True if this entry cannot be moved from its current position. */
151 unsigned int fixed_p : 1;
153 /* True if this instruction occurred in a .set noreorder block. */
154 unsigned int noreorder_p : 1;
156 /* True for mips16 instructions that jump to an absolute address. */
157 unsigned int mips16_absolute_jump_p : 1;
160 /* The ABI to use. */
171 /* MIPS ABI we are using for this output file. */
172 static enum mips_abi_level mips_abi = NO_ABI;
174 /* Whether or not we have code that can call pic code. */
175 int mips_abicalls = FALSE;
177 /* Whether or not we have code which can be put into a shared
179 static bfd_boolean mips_in_shared = TRUE;
181 /* This is the set of options which may be modified by the .set
182 pseudo-op. We use a struct so that .set push and .set pop are more
185 struct mips_set_options
187 /* MIPS ISA (Instruction Set Architecture) level. This is set to -1
188 if it has not been initialized. Changed by `.set mipsN', and the
189 -mipsN command line option, and the default CPU. */
191 /* Enabled Application Specific Extensions (ASEs). These are set to -1
192 if they have not been initialized. Changed by `.set <asename>', by
193 command line options, and based on the default architecture. */
199 /* Whether we are assembling for the mips16 processor. 0 if we are
200 not, 1 if we are, and -1 if the value has not been initialized.
201 Changed by `.set mips16' and `.set nomips16', and the -mips16 and
202 -nomips16 command line options, and the default CPU. */
204 /* Non-zero if we should not reorder instructions. Changed by `.set
205 reorder' and `.set noreorder'. */
207 /* Non-zero if we should not permit the $at ($1) register to be used
208 in instructions. Changed by `.set at' and `.set noat'. */
210 /* Non-zero if we should warn when a macro instruction expands into
211 more than one machine instruction. Changed by `.set nomacro' and
213 int warn_about_macros;
214 /* Non-zero if we should not move instructions. Changed by `.set
215 move', `.set volatile', `.set nomove', and `.set novolatile'. */
217 /* Non-zero if we should not optimize branches by moving the target
218 of the branch into the delay slot. Actually, we don't perform
219 this optimization anyhow. Changed by `.set bopt' and `.set
222 /* Non-zero if we should not autoextend mips16 instructions.
223 Changed by `.set autoextend' and `.set noautoextend'. */
225 /* Restrict general purpose registers and floating point registers
226 to 32 bit. This is initially determined when -mgp32 or -mfp32
227 is passed but can changed if the assembler code uses .set mipsN. */
230 /* MIPS architecture (CPU) type. Changed by .set arch=FOO, the -march
231 command line option, and the default CPU. */
233 /* True if ".set sym32" is in effect. */
237 /* True if -mgp32 was passed. */
238 static int file_mips_gp32 = -1;
240 /* True if -mfp32 was passed. */
241 static int file_mips_fp32 = -1;
243 /* This is the struct we use to hold the current set of options. Note
244 that we must set the isa field to ISA_UNKNOWN and the ASE fields to
245 -1 to indicate that they have not been initialized. */
247 static struct mips_set_options mips_opts =
249 ISA_UNKNOWN, -1, -1, 0, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, CPU_UNKNOWN, FALSE
252 /* These variables are filled in with the masks of registers used.
253 The object format code reads them and puts them in the appropriate
255 unsigned long mips_gprmask;
256 unsigned long mips_cprmask[4];
258 /* MIPS ISA we are using for this output file. */
259 static int file_mips_isa = ISA_UNKNOWN;
261 /* True if -mips16 was passed or implied by arguments passed on the
262 command line (e.g., by -march). */
263 static int file_ase_mips16;
265 /* True if -mips3d was passed or implied by arguments passed on the
266 command line (e.g., by -march). */
267 static int file_ase_mips3d;
269 /* True if -mdmx was passed or implied by arguments passed on the
270 command line (e.g., by -march). */
271 static int file_ase_mdmx;
273 /* True if -msmartmips was passed or implied by arguments passed on the
274 command line (e.g., by -march). */
275 static int file_ase_smartmips;
277 #define ISA_SUPPORT_SMARTMIPS (mips_opts.isa == ISA_MIPS32 \
278 || mips_opts.isa == ISA_MIPS32R2)
280 /* True if -mdsp was passed or implied by arguments passed on the
281 command line (e.g., by -march). */
282 static int file_ase_dsp;
284 /* True if -mmt was passed or implied by arguments passed on the
285 command line (e.g., by -march). */
286 static int file_ase_mt;
288 /* The argument of the -march= flag. The architecture we are assembling. */
289 static int file_mips_arch = CPU_UNKNOWN;
290 static const char *mips_arch_string;
292 /* The argument of the -mtune= flag. The architecture for which we
294 static int mips_tune = CPU_UNKNOWN;
295 static const char *mips_tune_string;
297 /* True when generating 32-bit code for a 64-bit processor. */
298 static int mips_32bitmode = 0;
300 /* True if the given ABI requires 32-bit registers. */
301 #define ABI_NEEDS_32BIT_REGS(ABI) ((ABI) == O32_ABI)
303 /* Likewise 64-bit registers. */
304 #define ABI_NEEDS_64BIT_REGS(ABI) \
306 || (ABI) == N64_ABI \
309 /* Return true if ISA supports 64 bit gp register instructions. */
310 #define ISA_HAS_64BIT_REGS(ISA) \
311 ((ISA) == ISA_MIPS3 \
312 || (ISA) == ISA_MIPS4 \
313 || (ISA) == ISA_MIPS5 \
314 || (ISA) == ISA_MIPS64 \
315 || (ISA) == ISA_MIPS64R2)
317 /* Return true if ISA supports 64-bit right rotate (dror et al.)
319 #define ISA_HAS_DROR(ISA) \
320 ((ISA) == ISA_MIPS64R2)
322 /* Return true if ISA supports 32-bit right rotate (ror et al.)
324 #define ISA_HAS_ROR(ISA) \
325 ((ISA) == ISA_MIPS32R2 \
326 || (ISA) == ISA_MIPS64R2 \
327 || mips_opts.ase_smartmips)
330 #define HAVE_32BIT_GPRS \
331 (mips_opts.gp32 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
333 #define HAVE_32BIT_FPRS \
334 (mips_opts.fp32 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
336 #define HAVE_64BIT_GPRS (! HAVE_32BIT_GPRS)
337 #define HAVE_64BIT_FPRS (! HAVE_32BIT_FPRS)
339 #define HAVE_NEWABI (mips_abi == N32_ABI || mips_abi == N64_ABI)
341 #define HAVE_64BIT_OBJECTS (mips_abi == N64_ABI)
343 /* True if relocations are stored in-place. */
344 #define HAVE_IN_PLACE_ADDENDS (!HAVE_NEWABI)
346 /* The ABI-derived address size. */
347 #define HAVE_64BIT_ADDRESSES \
348 (HAVE_64BIT_GPRS && (mips_abi == EABI_ABI || mips_abi == N64_ABI))
349 #define HAVE_32BIT_ADDRESSES (!HAVE_64BIT_ADDRESSES)
351 /* The size of symbolic constants (i.e., expressions of the form
352 "SYMBOL" or "SYMBOL + OFFSET"). */
353 #define HAVE_32BIT_SYMBOLS \
354 (HAVE_32BIT_ADDRESSES || !HAVE_64BIT_OBJECTS || mips_opts.sym32)
355 #define HAVE_64BIT_SYMBOLS (!HAVE_32BIT_SYMBOLS)
357 /* Addresses are loaded in different ways, depending on the address size
358 in use. The n32 ABI Documentation also mandates the use of additions
359 with overflow checking, but existing implementations don't follow it. */
360 #define ADDRESS_ADD_INSN \
361 (HAVE_32BIT_ADDRESSES ? "addu" : "daddu")
363 #define ADDRESS_ADDI_INSN \
364 (HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu")
366 #define ADDRESS_LOAD_INSN \
367 (HAVE_32BIT_ADDRESSES ? "lw" : "ld")
369 #define ADDRESS_STORE_INSN \
370 (HAVE_32BIT_ADDRESSES ? "sw" : "sd")
372 /* Return true if the given CPU supports the MIPS16 ASE. */
373 #define CPU_HAS_MIPS16(cpu) \
374 (strncmp (TARGET_CPU, "mips16", sizeof ("mips16") - 1) == 0 \
375 || strncmp (TARGET_CANONICAL, "mips-lsi-elf", sizeof ("mips-lsi-elf") - 1) == 0)
377 /* Return true if the given CPU supports the MIPS3D ASE. */
378 #define CPU_HAS_MIPS3D(cpu) ((cpu) == CPU_SB1 \
381 /* Return true if the given CPU supports the MDMX ASE. */
382 #define CPU_HAS_MDMX(cpu) (FALSE \
385 /* Return true if the given CPU supports the DSP ASE. */
386 #define CPU_HAS_DSP(cpu) (FALSE \
389 /* Return true if the given CPU supports the MT ASE. */
390 #define CPU_HAS_MT(cpu) (FALSE \
393 /* True if CPU has a dror instruction. */
394 #define CPU_HAS_DROR(CPU) ((CPU) == CPU_VR5400 || (CPU) == CPU_VR5500)
396 /* True if CPU has a ror instruction. */
397 #define CPU_HAS_ROR(CPU) CPU_HAS_DROR (CPU)
399 /* True if mflo and mfhi can be immediately followed by instructions
400 which write to the HI and LO registers.
402 According to MIPS specifications, MIPS ISAs I, II, and III need
403 (at least) two instructions between the reads of HI/LO and
404 instructions which write them, and later ISAs do not. Contradicting
405 the MIPS specifications, some MIPS IV processor user manuals (e.g.
406 the UM for the NEC Vr5000) document needing the instructions between
407 HI/LO reads and writes, as well. Therefore, we declare only MIPS32,
408 MIPS64 and later ISAs to have the interlocks, plus any specific
409 earlier-ISA CPUs for which CPU documentation declares that the
410 instructions are really interlocked. */
411 #define hilo_interlocks \
412 (mips_opts.isa == ISA_MIPS32 \
413 || mips_opts.isa == ISA_MIPS32R2 \
414 || mips_opts.isa == ISA_MIPS64 \
415 || mips_opts.isa == ISA_MIPS64R2 \
416 || mips_opts.arch == CPU_R4010 \
417 || mips_opts.arch == CPU_R10000 \
418 || mips_opts.arch == CPU_R12000 \
419 || mips_opts.arch == CPU_RM7000 \
420 || mips_opts.arch == CPU_VR5500 \
423 /* Whether the processor uses hardware interlocks to protect reads
424 from the GPRs after they are loaded from memory, and thus does not
425 require nops to be inserted. This applies to instructions marked
426 INSN_LOAD_MEMORY_DELAY. These nops are only required at MIPS ISA
428 #define gpr_interlocks \
429 (mips_opts.isa != ISA_MIPS1 \
430 || mips_opts.arch == CPU_R3900)
432 /* Whether the processor uses hardware interlocks to avoid delays
433 required by coprocessor instructions, and thus does not require
434 nops to be inserted. This applies to instructions marked
435 INSN_LOAD_COPROC_DELAY, INSN_COPROC_MOVE_DELAY, and to delays
436 between instructions marked INSN_WRITE_COND_CODE and ones marked
437 INSN_READ_COND_CODE. These nops are only required at MIPS ISA
438 levels I, II, and III. */
439 /* Itbl support may require additional care here. */
440 #define cop_interlocks \
441 ((mips_opts.isa != ISA_MIPS1 \
442 && mips_opts.isa != ISA_MIPS2 \
443 && mips_opts.isa != ISA_MIPS3) \
444 || mips_opts.arch == CPU_R4300 \
447 /* Whether the processor uses hardware interlocks to protect reads
448 from coprocessor registers after they are loaded from memory, and
449 thus does not require nops to be inserted. This applies to
450 instructions marked INSN_COPROC_MEMORY_DELAY. These nops are only
451 requires at MIPS ISA level I. */
452 #define cop_mem_interlocks (mips_opts.isa != ISA_MIPS1)
454 /* Is this a mfhi or mflo instruction? */
455 #define MF_HILO_INSN(PINFO) \
456 ((PINFO & INSN_READ_HI) || (PINFO & INSN_READ_LO))
458 /* MIPS PIC level. */
460 enum mips_pic_level mips_pic;
462 /* 1 if we should generate 32 bit offsets from the $gp register in
463 SVR4_PIC mode. Currently has no meaning in other modes. */
464 static int mips_big_got = 0;
466 /* 1 if trap instructions should used for overflow rather than break
468 static int mips_trap = 0;
470 /* 1 if double width floating point constants should not be constructed
471 by assembling two single width halves into two single width floating
472 point registers which just happen to alias the double width destination
473 register. On some architectures this aliasing can be disabled by a bit
474 in the status register, and the setting of this bit cannot be determined
475 automatically at assemble time. */
476 static int mips_disable_float_construction;
478 /* Non-zero if any .set noreorder directives were used. */
480 static int mips_any_noreorder;
482 /* Non-zero if nops should be inserted when the register referenced in
483 an mfhi/mflo instruction is read in the next two instructions. */
484 static int mips_7000_hilo_fix;
486 /* The size of the small data section. */
487 static unsigned int g_switch_value = 8;
488 /* Whether the -G option was used. */
489 static int g_switch_seen = 0;
494 /* If we can determine in advance that GP optimization won't be
495 possible, we can skip the relaxation stuff that tries to produce
496 GP-relative references. This makes delay slot optimization work
499 This function can only provide a guess, but it seems to work for
500 gcc output. It needs to guess right for gcc, otherwise gcc
501 will put what it thinks is a GP-relative instruction in a branch
504 I don't know if a fix is needed for the SVR4_PIC mode. I've only
505 fixed it for the non-PIC mode. KR 95/04/07 */
506 static int nopic_need_relax (symbolS *, int);
508 /* handle of the OPCODE hash table */
509 static struct hash_control *op_hash = NULL;
511 /* The opcode hash table we use for the mips16. */
512 static struct hash_control *mips16_op_hash = NULL;
514 /* This array holds the chars that always start a comment. If the
515 pre-processor is disabled, these aren't very useful */
516 const char comment_chars[] = "#";
518 /* This array holds the chars that only start a comment at the beginning of
519 a line. If the line seems to have the form '# 123 filename'
520 .line and .file directives will appear in the pre-processed output */
521 /* Note that input_file.c hand checks for '#' at the beginning of the
522 first line of the input file. This is because the compiler outputs
523 #NO_APP at the beginning of its output. */
524 /* Also note that C style comments are always supported. */
525 const char line_comment_chars[] = "#";
527 /* This array holds machine specific line separator characters. */
528 const char line_separator_chars[] = ";";
530 /* Chars that can be used to separate mant from exp in floating point nums */
531 const char EXP_CHARS[] = "eE";
533 /* Chars that mean this number is a floating point constant */
536 const char FLT_CHARS[] = "rRsSfFdDxXpP";
538 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
539 changed in read.c . Ideally it shouldn't have to know about it at all,
540 but nothing is ideal around here.
543 static char *insn_error;
545 static int auto_align = 1;
547 /* When outputting SVR4 PIC code, the assembler needs to know the
548 offset in the stack frame from which to restore the $gp register.
549 This is set by the .cprestore pseudo-op, and saved in this
551 static offsetT mips_cprestore_offset = -1;
553 /* Similar for NewABI PIC code, where $gp is callee-saved. NewABI has some
554 more optimizations, it can use a register value instead of a memory-saved
555 offset and even an other register than $gp as global pointer. */
556 static offsetT mips_cpreturn_offset = -1;
557 static int mips_cpreturn_register = -1;
558 static int mips_gp_register = GP;
559 static int mips_gprel_offset = 0;
561 /* Whether mips_cprestore_offset has been set in the current function
562 (or whether it has already been warned about, if not). */
563 static int mips_cprestore_valid = 0;
565 /* This is the register which holds the stack frame, as set by the
566 .frame pseudo-op. This is needed to implement .cprestore. */
567 static int mips_frame_reg = SP;
569 /* Whether mips_frame_reg has been set in the current function
570 (or whether it has already been warned about, if not). */
571 static int mips_frame_reg_valid = 0;
573 /* To output NOP instructions correctly, we need to keep information
574 about the previous two instructions. */
576 /* Whether we are optimizing. The default value of 2 means to remove
577 unneeded NOPs and swap branch instructions when possible. A value
578 of 1 means to not swap branches. A value of 0 means to always
580 static int mips_optimize = 2;
582 /* Debugging level. -g sets this to 2. -gN sets this to N. -g0 is
583 equivalent to seeing no -g option at all. */
584 static int mips_debug = 0;
586 /* The maximum number of NOPs needed to avoid the VR4130 mflo/mfhi errata. */
587 #define MAX_VR4130_NOPS 4
589 /* The maximum number of NOPs needed to fill delay slots. */
590 #define MAX_DELAY_NOPS 2
592 /* The maximum number of NOPs needed for any purpose. */
595 /* A list of previous instructions, with index 0 being the most recent.
596 We need to look back MAX_NOPS instructions when filling delay slots
597 or working around processor errata. We need to look back one
598 instruction further if we're thinking about using history[0] to
599 fill a branch delay slot. */
600 static struct mips_cl_insn history[1 + MAX_NOPS];
602 /* Nop instructions used by emit_nop. */
603 static struct mips_cl_insn nop_insn, mips16_nop_insn;
605 /* The appropriate nop for the current mode. */
606 #define NOP_INSN (mips_opts.mips16 ? &mips16_nop_insn : &nop_insn)
608 /* If this is set, it points to a frag holding nop instructions which
609 were inserted before the start of a noreorder section. If those
610 nops turn out to be unnecessary, the size of the frag can be
612 static fragS *prev_nop_frag;
614 /* The number of nop instructions we created in prev_nop_frag. */
615 static int prev_nop_frag_holds;
617 /* The number of nop instructions that we know we need in
619 static int prev_nop_frag_required;
621 /* The number of instructions we've seen since prev_nop_frag. */
622 static int prev_nop_frag_since;
624 /* For ECOFF and ELF, relocations against symbols are done in two
625 parts, with a HI relocation and a LO relocation. Each relocation
626 has only 16 bits of space to store an addend. This means that in
627 order for the linker to handle carries correctly, it must be able
628 to locate both the HI and the LO relocation. This means that the
629 relocations must appear in order in the relocation table.
631 In order to implement this, we keep track of each unmatched HI
632 relocation. We then sort them so that they immediately precede the
633 corresponding LO relocation. */
638 struct mips_hi_fixup *next;
641 /* The section this fixup is in. */
645 /* The list of unmatched HI relocs. */
647 static struct mips_hi_fixup *mips_hi_fixup_list;
649 /* The frag containing the last explicit relocation operator.
650 Null if explicit relocations have not been used. */
652 static fragS *prev_reloc_op_frag;
654 /* Map normal MIPS register numbers to mips16 register numbers. */
656 #define X ILLEGAL_REG
657 static const int mips32_to_16_reg_map[] =
659 X, X, 2, 3, 4, 5, 6, 7,
660 X, X, X, X, X, X, X, X,
661 0, 1, X, X, X, X, X, X,
662 X, X, X, X, X, X, X, X
666 /* Map mips16 register numbers to normal MIPS register numbers. */
668 static const unsigned int mips16_to_32_reg_map[] =
670 16, 17, 2, 3, 4, 5, 6, 7
673 /* Classifies the kind of instructions we're interested in when
674 implementing -mfix-vr4120. */
675 enum fix_vr4120_class {
682 NUM_FIX_VR4120_CLASSES
685 /* Given two FIX_VR4120_* values X and Y, bit Y of element X is set if
686 there must be at least one other instruction between an instruction
687 of type X and an instruction of type Y. */
688 static unsigned int vr4120_conflicts[NUM_FIX_VR4120_CLASSES];
690 /* True if -mfix-vr4120 is in force. */
691 static int mips_fix_vr4120;
693 /* ...likewise -mfix-vr4130. */
694 static int mips_fix_vr4130;
696 /* We don't relax branches by default, since this causes us to expand
697 `la .l2 - .l1' if there's a branch between .l1 and .l2, because we
698 fail to compute the offset before expanding the macro to the most
699 efficient expansion. */
701 static int mips_relax_branch;
703 /* The expansion of many macros depends on the type of symbol that
704 they refer to. For example, when generating position-dependent code,
705 a macro that refers to a symbol may have two different expansions,
706 one which uses GP-relative addresses and one which uses absolute
707 addresses. When generating SVR4-style PIC, a macro may have
708 different expansions for local and global symbols.
710 We handle these situations by generating both sequences and putting
711 them in variant frags. In position-dependent code, the first sequence
712 will be the GP-relative one and the second sequence will be the
713 absolute one. In SVR4 PIC, the first sequence will be for global
714 symbols and the second will be for local symbols.
716 The frag's "subtype" is RELAX_ENCODE (FIRST, SECOND), where FIRST and
717 SECOND are the lengths of the two sequences in bytes. These fields
718 can be extracted using RELAX_FIRST() and RELAX_SECOND(). In addition,
719 the subtype has the following flags:
722 Set if it has been decided that we should use the second
723 sequence instead of the first.
726 Set in the first variant frag if the macro's second implementation
727 is longer than its first. This refers to the macro as a whole,
728 not an individual relaxation.
731 Set in the first variant frag if the macro appeared in a .set nomacro
732 block and if one alternative requires a warning but the other does not.
735 Like RELAX_NOMACRO, but indicates that the macro appears in a branch
738 The frag's "opcode" points to the first fixup for relaxable code.
740 Relaxable macros are generated using a sequence such as:
742 relax_start (SYMBOL);
743 ... generate first expansion ...
745 ... generate second expansion ...
748 The code and fixups for the unwanted alternative are discarded
749 by md_convert_frag. */
750 #define RELAX_ENCODE(FIRST, SECOND) (((FIRST) << 8) | (SECOND))
752 #define RELAX_FIRST(X) (((X) >> 8) & 0xff)
753 #define RELAX_SECOND(X) ((X) & 0xff)
754 #define RELAX_USE_SECOND 0x10000
755 #define RELAX_SECOND_LONGER 0x20000
756 #define RELAX_NOMACRO 0x40000
757 #define RELAX_DELAY_SLOT 0x80000
759 /* Branch without likely bit. If label is out of range, we turn:
761 beq reg1, reg2, label
771 with the following opcode replacements:
778 bltzal <-> bgezal (with jal label instead of j label)
780 Even though keeping the delay slot instruction in the delay slot of
781 the branch would be more efficient, it would be very tricky to do
782 correctly, because we'd have to introduce a variable frag *after*
783 the delay slot instruction, and expand that instead. Let's do it
784 the easy way for now, even if the branch-not-taken case now costs
785 one additional instruction. Out-of-range branches are not supposed
786 to be common, anyway.
788 Branch likely. If label is out of range, we turn:
790 beql reg1, reg2, label
791 delay slot (annulled if branch not taken)
800 delay slot (executed only if branch taken)
803 It would be possible to generate a shorter sequence by losing the
804 likely bit, generating something like:
809 delay slot (executed only if branch taken)
821 bltzall -> bgezal (with jal label instead of j label)
822 bgezall -> bltzal (ditto)
825 but it's not clear that it would actually improve performance. */
826 #define RELAX_BRANCH_ENCODE(uncond, likely, link, toofar) \
829 | ((toofar) ? 1 : 0) \
831 | ((likely) ? 4 : 0) \
832 | ((uncond) ? 8 : 0)))
833 #define RELAX_BRANCH_P(i) (((i) & 0xf0000000) == 0xc0000000)
834 #define RELAX_BRANCH_UNCOND(i) (((i) & 8) != 0)
835 #define RELAX_BRANCH_LIKELY(i) (((i) & 4) != 0)
836 #define RELAX_BRANCH_LINK(i) (((i) & 2) != 0)
837 #define RELAX_BRANCH_TOOFAR(i) (((i) & 1) != 0)
839 /* For mips16 code, we use an entirely different form of relaxation.
840 mips16 supports two versions of most instructions which take
841 immediate values: a small one which takes some small value, and a
842 larger one which takes a 16 bit value. Since branches also follow
843 this pattern, relaxing these values is required.
845 We can assemble both mips16 and normal MIPS code in a single
846 object. Therefore, we need to support this type of relaxation at
847 the same time that we support the relaxation described above. We
848 use the high bit of the subtype field to distinguish these cases.
850 The information we store for this type of relaxation is the
851 argument code found in the opcode file for this relocation, whether
852 the user explicitly requested a small or extended form, and whether
853 the relocation is in a jump or jal delay slot. That tells us the
854 size of the value, and how it should be stored. We also store
855 whether the fragment is considered to be extended or not. We also
856 store whether this is known to be a branch to a different section,
857 whether we have tried to relax this frag yet, and whether we have
858 ever extended a PC relative fragment because of a shift count. */
859 #define RELAX_MIPS16_ENCODE(type, small, ext, dslot, jal_dslot) \
862 | ((small) ? 0x100 : 0) \
863 | ((ext) ? 0x200 : 0) \
864 | ((dslot) ? 0x400 : 0) \
865 | ((jal_dslot) ? 0x800 : 0))
866 #define RELAX_MIPS16_P(i) (((i) & 0xc0000000) == 0x80000000)
867 #define RELAX_MIPS16_TYPE(i) ((i) & 0xff)
868 #define RELAX_MIPS16_USER_SMALL(i) (((i) & 0x100) != 0)
869 #define RELAX_MIPS16_USER_EXT(i) (((i) & 0x200) != 0)
870 #define RELAX_MIPS16_DSLOT(i) (((i) & 0x400) != 0)
871 #define RELAX_MIPS16_JAL_DSLOT(i) (((i) & 0x800) != 0)
872 #define RELAX_MIPS16_EXTENDED(i) (((i) & 0x1000) != 0)
873 #define RELAX_MIPS16_MARK_EXTENDED(i) ((i) | 0x1000)
874 #define RELAX_MIPS16_CLEAR_EXTENDED(i) ((i) &~ 0x1000)
875 #define RELAX_MIPS16_LONG_BRANCH(i) (((i) & 0x2000) != 0)
876 #define RELAX_MIPS16_MARK_LONG_BRANCH(i) ((i) | 0x2000)
877 #define RELAX_MIPS16_CLEAR_LONG_BRANCH(i) ((i) &~ 0x2000)
879 /* Is the given value a sign-extended 32-bit value? */
880 #define IS_SEXT_32BIT_NUM(x) \
881 (((x) &~ (offsetT) 0x7fffffff) == 0 \
882 || (((x) &~ (offsetT) 0x7fffffff) == ~ (offsetT) 0x7fffffff))
884 /* Is the given value a sign-extended 16-bit value? */
885 #define IS_SEXT_16BIT_NUM(x) \
886 (((x) &~ (offsetT) 0x7fff) == 0 \
887 || (((x) &~ (offsetT) 0x7fff) == ~ (offsetT) 0x7fff))
889 /* Is the given value a zero-extended 32-bit value? Or a negated one? */
890 #define IS_ZEXT_32BIT_NUM(x) \
891 (((x) &~ (offsetT) 0xffffffff) == 0 \
892 || (((x) &~ (offsetT) 0xffffffff) == ~ (offsetT) 0xffffffff))
894 /* Replace bits MASK << SHIFT of STRUCT with the equivalent bits in
895 VALUE << SHIFT. VALUE is evaluated exactly once. */
896 #define INSERT_BITS(STRUCT, VALUE, MASK, SHIFT) \
897 (STRUCT) = (((STRUCT) & ~((MASK) << (SHIFT))) \
898 | (((VALUE) & (MASK)) << (SHIFT)))
900 /* Extract bits MASK << SHIFT from STRUCT and shift them right
902 #define EXTRACT_BITS(STRUCT, MASK, SHIFT) \
903 (((STRUCT) >> (SHIFT)) & (MASK))
905 /* Change INSN's opcode so that the operand given by FIELD has value VALUE.
906 INSN is a mips_cl_insn structure and VALUE is evaluated exactly once.
908 include/opcode/mips.h specifies operand fields using the macros
909 OP_MASK_<FIELD> and OP_SH_<FIELD>. The MIPS16 equivalents start
910 with "MIPS16OP" instead of "OP". */
911 #define INSERT_OPERAND(FIELD, INSN, VALUE) \
912 INSERT_BITS ((INSN).insn_opcode, VALUE, OP_MASK_##FIELD, OP_SH_##FIELD)
913 #define MIPS16_INSERT_OPERAND(FIELD, INSN, VALUE) \
914 INSERT_BITS ((INSN).insn_opcode, VALUE, \
915 MIPS16OP_MASK_##FIELD, MIPS16OP_SH_##FIELD)
917 /* Extract the operand given by FIELD from mips_cl_insn INSN. */
918 #define EXTRACT_OPERAND(FIELD, INSN) \
919 EXTRACT_BITS ((INSN).insn_opcode, OP_MASK_##FIELD, OP_SH_##FIELD)
920 #define MIPS16_EXTRACT_OPERAND(FIELD, INSN) \
921 EXTRACT_BITS ((INSN).insn_opcode, \
922 MIPS16OP_MASK_##FIELD, \
925 /* Global variables used when generating relaxable macros. See the
926 comment above RELAX_ENCODE for more details about how relaxation
929 /* 0 if we're not emitting a relaxable macro.
930 1 if we're emitting the first of the two relaxation alternatives.
931 2 if we're emitting the second alternative. */
934 /* The first relaxable fixup in the current frag. (In other words,
935 the first fixup that refers to relaxable code.) */
938 /* sizes[0] says how many bytes of the first alternative are stored in
939 the current frag. Likewise sizes[1] for the second alternative. */
940 unsigned int sizes[2];
942 /* The symbol on which the choice of sequence depends. */
946 /* Global variables used to decide whether a macro needs a warning. */
948 /* True if the macro is in a branch delay slot. */
949 bfd_boolean delay_slot_p;
951 /* For relaxable macros, sizes[0] is the length of the first alternative
952 in bytes and sizes[1] is the length of the second alternative.
953 For non-relaxable macros, both elements give the length of the
955 unsigned int sizes[2];
957 /* The first variant frag for this macro. */
959 } mips_macro_warning;
961 /* Prototypes for static functions. */
963 #define internalError() \
964 as_fatal (_("internal Error, line %d, %s"), __LINE__, __FILE__)
966 enum mips_regclass { MIPS_GR_REG, MIPS_FP_REG, MIPS16_REG };
968 static void append_insn
969 (struct mips_cl_insn *ip, expressionS *p, bfd_reloc_code_real_type *r);
970 static void mips_no_prev_insn (void);
971 static void mips16_macro_build
972 (expressionS *, const char *, const char *, va_list);
973 static void load_register (int, expressionS *, int);
974 static void macro_start (void);
975 static void macro_end (void);
976 static void macro (struct mips_cl_insn * ip);
977 static void mips16_macro (struct mips_cl_insn * ip);
978 #ifdef LOSING_COMPILER
979 static void macro2 (struct mips_cl_insn * ip);
981 static void mips_ip (char *str, struct mips_cl_insn * ip);
982 static void mips16_ip (char *str, struct mips_cl_insn * ip);
983 static void mips16_immed
984 (char *, unsigned int, int, offsetT, bfd_boolean, bfd_boolean, bfd_boolean,
985 unsigned long *, bfd_boolean *, unsigned short *);
986 static size_t my_getSmallExpression
987 (expressionS *, bfd_reloc_code_real_type *, char *);
988 static void my_getExpression (expressionS *, char *);
989 static void s_align (int);
990 static void s_change_sec (int);
991 static void s_change_section (int);
992 static void s_cons (int);
993 static void s_float_cons (int);
994 static void s_mips_globl (int);
995 static void s_option (int);
996 static void s_mipsset (int);
997 static void s_abicalls (int);
998 static void s_cpload (int);
999 static void s_cpsetup (int);
1000 static void s_cplocal (int);
1001 static void s_cprestore (int);
1002 static void s_cpreturn (int);
1003 static void s_gpvalue (int);
1004 static void s_gpword (int);
1005 static void s_gpdword (int);
1006 static void s_cpadd (int);
1007 static void s_insn (int);
1008 static void md_obj_begin (void);
1009 static void md_obj_end (void);
1010 static void s_mips_ent (int);
1011 static void s_mips_end (int);
1012 static void s_mips_frame (int);
1013 static void s_mips_mask (int reg_type);
1014 static void s_mips_stab (int);
1015 static void s_mips_weakext (int);
1016 static void s_mips_file (int);
1017 static void s_mips_loc (int);
1018 static bfd_boolean pic_need_relax (symbolS *, asection *);
1019 static int relaxed_branch_length (fragS *, asection *, int);
1020 static int validate_mips_insn (const struct mips_opcode *);
1022 /* Table and functions used to map between CPU/ISA names, and
1023 ISA levels, and CPU numbers. */
1025 struct mips_cpu_info
1027 const char *name; /* CPU or ISA name. */
1028 int is_isa; /* Is this an ISA? (If 0, a CPU.) */
1029 int isa; /* ISA level. */
1030 int cpu; /* CPU number (default CPU if ISA). */
1033 static const struct mips_cpu_info *mips_parse_cpu (const char *, const char *);
1034 static const struct mips_cpu_info *mips_cpu_info_from_isa (int);
1035 static const struct mips_cpu_info *mips_cpu_info_from_arch (int);
1039 The following pseudo-ops from the Kane and Heinrich MIPS book
1040 should be defined here, but are currently unsupported: .alias,
1041 .galive, .gjaldef, .gjrlive, .livereg, .noalias.
1043 The following pseudo-ops from the Kane and Heinrich MIPS book are
1044 specific to the type of debugging information being generated, and
1045 should be defined by the object format: .aent, .begin, .bend,
1046 .bgnb, .end, .endb, .ent, .fmask, .frame, .loc, .mask, .verstamp,
1049 The following pseudo-ops from the Kane and Heinrich MIPS book are
1050 not MIPS CPU specific, but are also not specific to the object file
1051 format. This file is probably the best place to define them, but
1052 they are not currently supported: .asm0, .endr, .lab, .repeat,
1055 static const pseudo_typeS mips_pseudo_table[] =
1057 /* MIPS specific pseudo-ops. */
1058 {"option", s_option, 0},
1059 {"set", s_mipsset, 0},
1060 {"rdata", s_change_sec, 'r'},
1061 {"sdata", s_change_sec, 's'},
1062 {"livereg", s_ignore, 0},
1063 {"abicalls", s_abicalls, 0},
1064 {"cpload", s_cpload, 0},
1065 {"cpsetup", s_cpsetup, 0},
1066 {"cplocal", s_cplocal, 0},
1067 {"cprestore", s_cprestore, 0},
1068 {"cpreturn", s_cpreturn, 0},
1069 {"gpvalue", s_gpvalue, 0},
1070 {"gpword", s_gpword, 0},
1071 {"gpdword", s_gpdword, 0},
1072 {"cpadd", s_cpadd, 0},
1073 {"insn", s_insn, 0},
1075 /* Relatively generic pseudo-ops that happen to be used on MIPS
1077 {"asciiz", stringer, 1},
1078 {"bss", s_change_sec, 'b'},
1080 {"half", s_cons, 1},
1081 {"dword", s_cons, 3},
1082 {"weakext", s_mips_weakext, 0},
1084 /* These pseudo-ops are defined in read.c, but must be overridden
1085 here for one reason or another. */
1086 {"align", s_align, 0},
1087 {"byte", s_cons, 0},
1088 {"data", s_change_sec, 'd'},
1089 {"double", s_float_cons, 'd'},
1090 {"float", s_float_cons, 'f'},
1091 {"globl", s_mips_globl, 0},
1092 {"global", s_mips_globl, 0},
1093 {"hword", s_cons, 1},
1095 {"long", s_cons, 2},
1096 {"octa", s_cons, 4},
1097 {"quad", s_cons, 3},
1098 {"section", s_change_section, 0},
1099 {"short", s_cons, 1},
1100 {"single", s_float_cons, 'f'},
1101 {"stabn", s_mips_stab, 'n'},
1102 {"text", s_change_sec, 't'},
1103 {"word", s_cons, 2},
1105 { "extern", ecoff_directive_extern, 0},
1110 static const pseudo_typeS mips_nonecoff_pseudo_table[] =
1112 /* These pseudo-ops should be defined by the object file format.
1113 However, a.out doesn't support them, so we have versions here. */
1114 {"aent", s_mips_ent, 1},
1115 {"bgnb", s_ignore, 0},
1116 {"end", s_mips_end, 0},
1117 {"endb", s_ignore, 0},
1118 {"ent", s_mips_ent, 0},
1119 {"file", s_mips_file, 0},
1120 {"fmask", s_mips_mask, 'F'},
1121 {"frame", s_mips_frame, 0},
1122 {"loc", s_mips_loc, 0},
1123 {"mask", s_mips_mask, 'R'},
1124 {"verstamp", s_ignore, 0},
1128 extern void pop_insert (const pseudo_typeS *);
1131 mips_pop_insert (void)
1133 pop_insert (mips_pseudo_table);
1134 if (! ECOFF_DEBUGGING)
1135 pop_insert (mips_nonecoff_pseudo_table);
1138 /* Symbols labelling the current insn. */
1140 struct insn_label_list
1142 struct insn_label_list *next;
1146 static struct insn_label_list *insn_labels;
1147 static struct insn_label_list *free_insn_labels;
1149 static void mips_clear_insn_labels (void);
1152 mips_clear_insn_labels (void)
1154 register struct insn_label_list **pl;
1156 for (pl = &free_insn_labels; *pl != NULL; pl = &(*pl)->next)
1162 static char *expr_end;
1164 /* Expressions which appear in instructions. These are set by
1167 static expressionS imm_expr;
1168 static expressionS imm2_expr;
1169 static expressionS offset_expr;
1171 /* Relocs associated with imm_expr and offset_expr. */
1173 static bfd_reloc_code_real_type imm_reloc[3]
1174 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
1175 static bfd_reloc_code_real_type offset_reloc[3]
1176 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
1178 /* These are set by mips16_ip if an explicit extension is used. */
1180 static bfd_boolean mips16_small, mips16_ext;
1183 /* The pdr segment for per procedure frame/regmask info. Not used for
1186 static segT pdr_seg;
1189 /* The default target format to use. */
1192 mips_target_format (void)
1194 switch (OUTPUT_FLAVOR)
1196 case bfd_target_ecoff_flavour:
1197 return target_big_endian ? "ecoff-bigmips" : ECOFF_LITTLE_FORMAT;
1198 case bfd_target_coff_flavour:
1200 case bfd_target_elf_flavour:
1202 if (!HAVE_64BIT_OBJECTS && !HAVE_NEWABI)
1203 return (target_big_endian
1204 ? "elf32-bigmips-vxworks"
1205 : "elf32-littlemips-vxworks");
1208 /* This is traditional mips. */
1209 return (target_big_endian
1210 ? (HAVE_64BIT_OBJECTS
1211 ? "elf64-tradbigmips"
1213 ? "elf32-ntradbigmips" : "elf32-tradbigmips"))
1214 : (HAVE_64BIT_OBJECTS
1215 ? "elf64-tradlittlemips"
1217 ? "elf32-ntradlittlemips" : "elf32-tradlittlemips")));
1219 return (target_big_endian
1220 ? (HAVE_64BIT_OBJECTS
1223 ? "elf32-nbigmips" : "elf32-bigmips"))
1224 : (HAVE_64BIT_OBJECTS
1225 ? "elf64-littlemips"
1227 ? "elf32-nlittlemips" : "elf32-littlemips")));
1235 /* Return the length of instruction INSN. */
1237 static inline unsigned int
1238 insn_length (const struct mips_cl_insn *insn)
1240 if (!mips_opts.mips16)
1242 return insn->mips16_absolute_jump_p || insn->use_extend ? 4 : 2;
1245 /* Initialise INSN from opcode entry MO. Leave its position unspecified. */
1248 create_insn (struct mips_cl_insn *insn, const struct mips_opcode *mo)
1253 insn->use_extend = FALSE;
1255 insn->insn_opcode = mo->match;
1258 for (i = 0; i < ARRAY_SIZE (insn->fixp); i++)
1259 insn->fixp[i] = NULL;
1260 insn->fixed_p = (mips_opts.noreorder > 0);
1261 insn->noreorder_p = (mips_opts.noreorder > 0);
1262 insn->mips16_absolute_jump_p = 0;
1265 /* Install INSN at the location specified by its "frag" and "where" fields. */
1268 install_insn (const struct mips_cl_insn *insn)
1270 char *f = insn->frag->fr_literal + insn->where;
1271 if (!mips_opts.mips16)
1272 md_number_to_chars (f, insn->insn_opcode, 4);
1273 else if (insn->mips16_absolute_jump_p)
1275 md_number_to_chars (f, insn->insn_opcode >> 16, 2);
1276 md_number_to_chars (f + 2, insn->insn_opcode & 0xffff, 2);
1280 if (insn->use_extend)
1282 md_number_to_chars (f, 0xf000 | insn->extend, 2);
1285 md_number_to_chars (f, insn->insn_opcode, 2);
1289 /* Move INSN to offset WHERE in FRAG. Adjust the fixups accordingly
1290 and install the opcode in the new location. */
1293 move_insn (struct mips_cl_insn *insn, fragS *frag, long where)
1298 insn->where = where;
1299 for (i = 0; i < ARRAY_SIZE (insn->fixp); i++)
1300 if (insn->fixp[i] != NULL)
1302 insn->fixp[i]->fx_frag = frag;
1303 insn->fixp[i]->fx_where = where;
1305 install_insn (insn);
1308 /* Add INSN to the end of the output. */
1311 add_fixed_insn (struct mips_cl_insn *insn)
1313 char *f = frag_more (insn_length (insn));
1314 move_insn (insn, frag_now, f - frag_now->fr_literal);
1317 /* Start a variant frag and move INSN to the start of the variant part,
1318 marking it as fixed. The other arguments are as for frag_var. */
1321 add_relaxed_insn (struct mips_cl_insn *insn, int max_chars, int var,
1322 relax_substateT subtype, symbolS *symbol, offsetT offset)
1324 frag_grow (max_chars);
1325 move_insn (insn, frag_now, frag_more (0) - frag_now->fr_literal);
1327 frag_var (rs_machine_dependent, max_chars, var,
1328 subtype, symbol, offset, NULL);
1331 /* Insert N copies of INSN into the history buffer, starting at
1332 position FIRST. Neither FIRST nor N need to be clipped. */
1335 insert_into_history (unsigned int first, unsigned int n,
1336 const struct mips_cl_insn *insn)
1338 if (mips_relax.sequence != 2)
1342 for (i = ARRAY_SIZE (history); i-- > first;)
1344 history[i] = history[i - n];
1350 /* Emit a nop instruction, recording it in the history buffer. */
1355 add_fixed_insn (NOP_INSN);
1356 insert_into_history (0, 1, NOP_INSN);
1359 /* Initialize vr4120_conflicts. There is a bit of duplication here:
1360 the idea is to make it obvious at a glance that each errata is
1364 init_vr4120_conflicts (void)
1366 #define CONFLICT(FIRST, SECOND) \
1367 vr4120_conflicts[FIX_VR4120_##FIRST] |= 1 << FIX_VR4120_##SECOND
1369 /* Errata 21 - [D]DIV[U] after [D]MACC */
1370 CONFLICT (MACC, DIV);
1371 CONFLICT (DMACC, DIV);
1373 /* Errata 23 - Continuous DMULT[U]/DMACC instructions. */
1374 CONFLICT (DMULT, DMULT);
1375 CONFLICT (DMULT, DMACC);
1376 CONFLICT (DMACC, DMULT);
1377 CONFLICT (DMACC, DMACC);
1379 /* Errata 24 - MT{LO,HI} after [D]MACC */
1380 CONFLICT (MACC, MTHILO);
1381 CONFLICT (DMACC, MTHILO);
1383 /* VR4181A errata MD(1): "If a MULT, MULTU, DMULT or DMULTU
1384 instruction is executed immediately after a MACC or DMACC
1385 instruction, the result of [either instruction] is incorrect." */
1386 CONFLICT (MACC, MULT);
1387 CONFLICT (MACC, DMULT);
1388 CONFLICT (DMACC, MULT);
1389 CONFLICT (DMACC, DMULT);
1391 /* VR4181A errata MD(4): "If a MACC or DMACC instruction is
1392 executed immediately after a DMULT, DMULTU, DIV, DIVU,
1393 DDIV or DDIVU instruction, the result of the MACC or
1394 DMACC instruction is incorrect.". */
1395 CONFLICT (DMULT, MACC);
1396 CONFLICT (DMULT, DMACC);
1397 CONFLICT (DIV, MACC);
1398 CONFLICT (DIV, DMACC);
1408 #define RTYPE_MASK 0x1ff00
1409 #define RTYPE_NUM 0x00100
1410 #define RTYPE_FPU 0x00200
1411 #define RTYPE_FCC 0x00400
1412 #define RTYPE_VEC 0x00800
1413 #define RTYPE_GP 0x01000
1414 #define RTYPE_CP0 0x02000
1415 #define RTYPE_PC 0x04000
1416 #define RTYPE_ACC 0x08000
1417 #define RTYPE_CCC 0x10000
1418 #define RNUM_MASK 0x000ff
1419 #define RWARN 0x80000
1421 #define GENERIC_REGISTER_NUMBERS \
1422 {"$0", RTYPE_NUM | 0}, \
1423 {"$1", RTYPE_NUM | 1}, \
1424 {"$2", RTYPE_NUM | 2}, \
1425 {"$3", RTYPE_NUM | 3}, \
1426 {"$4", RTYPE_NUM | 4}, \
1427 {"$5", RTYPE_NUM | 5}, \
1428 {"$6", RTYPE_NUM | 6}, \
1429 {"$7", RTYPE_NUM | 7}, \
1430 {"$8", RTYPE_NUM | 8}, \
1431 {"$9", RTYPE_NUM | 9}, \
1432 {"$10", RTYPE_NUM | 10}, \
1433 {"$11", RTYPE_NUM | 11}, \
1434 {"$12", RTYPE_NUM | 12}, \
1435 {"$13", RTYPE_NUM | 13}, \
1436 {"$14", RTYPE_NUM | 14}, \
1437 {"$15", RTYPE_NUM | 15}, \
1438 {"$16", RTYPE_NUM | 16}, \
1439 {"$17", RTYPE_NUM | 17}, \
1440 {"$18", RTYPE_NUM | 18}, \
1441 {"$19", RTYPE_NUM | 19}, \
1442 {"$20", RTYPE_NUM | 20}, \
1443 {"$21", RTYPE_NUM | 21}, \
1444 {"$22", RTYPE_NUM | 22}, \
1445 {"$23", RTYPE_NUM | 23}, \
1446 {"$24", RTYPE_NUM | 24}, \
1447 {"$25", RTYPE_NUM | 25}, \
1448 {"$26", RTYPE_NUM | 26}, \
1449 {"$27", RTYPE_NUM | 27}, \
1450 {"$28", RTYPE_NUM | 28}, \
1451 {"$29", RTYPE_NUM | 29}, \
1452 {"$30", RTYPE_NUM | 30}, \
1453 {"$31", RTYPE_NUM | 31}
1455 #define FPU_REGISTER_NAMES \
1456 {"$f0", RTYPE_FPU | 0}, \
1457 {"$f1", RTYPE_FPU | 1}, \
1458 {"$f2", RTYPE_FPU | 2}, \
1459 {"$f3", RTYPE_FPU | 3}, \
1460 {"$f4", RTYPE_FPU | 4}, \
1461 {"$f5", RTYPE_FPU | 5}, \
1462 {"$f6", RTYPE_FPU | 6}, \
1463 {"$f7", RTYPE_FPU | 7}, \
1464 {"$f8", RTYPE_FPU | 8}, \
1465 {"$f9", RTYPE_FPU | 9}, \
1466 {"$f10", RTYPE_FPU | 10}, \
1467 {"$f11", RTYPE_FPU | 11}, \
1468 {"$f12", RTYPE_FPU | 12}, \
1469 {"$f13", RTYPE_FPU | 13}, \
1470 {"$f14", RTYPE_FPU | 14}, \
1471 {"$f15", RTYPE_FPU | 15}, \
1472 {"$f16", RTYPE_FPU | 16}, \
1473 {"$f17", RTYPE_FPU | 17}, \
1474 {"$f18", RTYPE_FPU | 18}, \
1475 {"$f19", RTYPE_FPU | 19}, \
1476 {"$f20", RTYPE_FPU | 20}, \
1477 {"$f21", RTYPE_FPU | 21}, \
1478 {"$f22", RTYPE_FPU | 22}, \
1479 {"$f23", RTYPE_FPU | 23}, \
1480 {"$f24", RTYPE_FPU | 24}, \
1481 {"$f25", RTYPE_FPU | 25}, \
1482 {"$f26", RTYPE_FPU | 26}, \
1483 {"$f27", RTYPE_FPU | 27}, \
1484 {"$f28", RTYPE_FPU | 28}, \
1485 {"$f29", RTYPE_FPU | 29}, \
1486 {"$f30", RTYPE_FPU | 30}, \
1487 {"$f31", RTYPE_FPU | 31}
1489 #define FPU_CONDITION_CODE_NAMES \
1490 {"$fcc0", RTYPE_FCC | 0}, \
1491 {"$fcc1", RTYPE_FCC | 1}, \
1492 {"$fcc2", RTYPE_FCC | 2}, \
1493 {"$fcc3", RTYPE_FCC | 3}, \
1494 {"$fcc4", RTYPE_FCC | 4}, \
1495 {"$fcc5", RTYPE_FCC | 5}, \
1496 {"$fcc6", RTYPE_FCC | 6}, \
1497 {"$fcc7", RTYPE_FCC | 7}
1499 #define COPROC_CONDITION_CODE_NAMES \
1500 {"$cc0", RTYPE_FCC | RTYPE_CCC | 0}, \
1501 {"$cc1", RTYPE_FCC | RTYPE_CCC | 1}, \
1502 {"$cc2", RTYPE_FCC | RTYPE_CCC | 2}, \
1503 {"$cc3", RTYPE_FCC | RTYPE_CCC | 3}, \
1504 {"$cc4", RTYPE_FCC | RTYPE_CCC | 4}, \
1505 {"$cc5", RTYPE_FCC | RTYPE_CCC | 5}, \
1506 {"$cc6", RTYPE_FCC | RTYPE_CCC | 6}, \
1507 {"$cc7", RTYPE_FCC | RTYPE_CCC | 7}
1509 #define N32N64_SYMBOLIC_REGISTER_NAMES \
1510 {"$a4", RTYPE_GP | 8}, \
1511 {"$a5", RTYPE_GP | 9}, \
1512 {"$a6", RTYPE_GP | 10}, \
1513 {"$a7", RTYPE_GP | 11}, \
1514 {"$ta0", RTYPE_GP | 8}, /* alias for $a4 */ \
1515 {"$ta1", RTYPE_GP | 9}, /* alias for $a5 */ \
1516 {"$ta2", RTYPE_GP | 10}, /* alias for $a6 */ \
1517 {"$ta3", RTYPE_GP | 11}, /* alias for $a7 */ \
1518 {"$t0", RTYPE_GP | 12}, \
1519 {"$t1", RTYPE_GP | 13}, \
1520 {"$t2", RTYPE_GP | 14}, \
1521 {"$t3", RTYPE_GP | 15}
1523 #define O32_SYMBOLIC_REGISTER_NAMES \
1524 {"$t0", RTYPE_GP | 8}, \
1525 {"$t1", RTYPE_GP | 9}, \
1526 {"$t2", RTYPE_GP | 10}, \
1527 {"$t3", RTYPE_GP | 11}, \
1528 {"$t4", RTYPE_GP | 12}, \
1529 {"$t5", RTYPE_GP | 13}, \
1530 {"$t6", RTYPE_GP | 14}, \
1531 {"$t7", RTYPE_GP | 15}, \
1532 {"$ta0", RTYPE_GP | 12}, /* alias for $t4 */ \
1533 {"$ta1", RTYPE_GP | 13}, /* alias for $t5 */ \
1534 {"$ta2", RTYPE_GP | 14}, /* alias for $t6 */ \
1535 {"$ta3", RTYPE_GP | 15} /* alias for $t7 */
1537 /* Remaining symbolic register names */
1538 #define SYMBOLIC_REGISTER_NAMES \
1539 {"$zero", RTYPE_GP | 0}, \
1540 {"$at", RTYPE_GP | 1}, \
1541 {"$AT", RTYPE_GP | 1}, \
1542 {"$v0", RTYPE_GP | 2}, \
1543 {"$v1", RTYPE_GP | 3}, \
1544 {"$a0", RTYPE_GP | 4}, \
1545 {"$a1", RTYPE_GP | 5}, \
1546 {"$a2", RTYPE_GP | 6}, \
1547 {"$a3", RTYPE_GP | 7}, \
1548 {"$s0", RTYPE_GP | 16}, \
1549 {"$s1", RTYPE_GP | 17}, \
1550 {"$s2", RTYPE_GP | 18}, \
1551 {"$s3", RTYPE_GP | 19}, \
1552 {"$s4", RTYPE_GP | 20}, \
1553 {"$s5", RTYPE_GP | 21}, \
1554 {"$s6", RTYPE_GP | 22}, \
1555 {"$s7", RTYPE_GP | 23}, \
1556 {"$t8", RTYPE_GP | 24}, \
1557 {"$t9", RTYPE_GP | 25}, \
1558 {"$k0", RTYPE_GP | 26}, \
1559 {"$kt0", RTYPE_GP | 26}, \
1560 {"$k1", RTYPE_GP | 27}, \
1561 {"$kt1", RTYPE_GP | 27}, \
1562 {"$gp", RTYPE_GP | 28}, \
1563 {"$sp", RTYPE_GP | 29}, \
1564 {"$s8", RTYPE_GP | 30}, \
1565 {"$fp", RTYPE_GP | 30}, \
1566 {"$ra", RTYPE_GP | 31}
1568 #define MIPS16_SPECIAL_REGISTER_NAMES \
1569 {"$pc", RTYPE_PC | 0}
1571 #define MDMX_VECTOR_REGISTER_NAMES \
1572 /* {"$v0", RTYPE_VEC | 0}, clash with REG 2 above */ \
1573 /* {"$v1", RTYPE_VEC | 1}, clash with REG 3 above */ \
1574 {"$v2", RTYPE_VEC | 2}, \
1575 {"$v3", RTYPE_VEC | 3}, \
1576 {"$v4", RTYPE_VEC | 4}, \
1577 {"$v5", RTYPE_VEC | 5}, \
1578 {"$v6", RTYPE_VEC | 6}, \
1579 {"$v7", RTYPE_VEC | 7}, \
1580 {"$v8", RTYPE_VEC | 8}, \
1581 {"$v9", RTYPE_VEC | 9}, \
1582 {"$v10", RTYPE_VEC | 10}, \
1583 {"$v11", RTYPE_VEC | 11}, \
1584 {"$v12", RTYPE_VEC | 12}, \
1585 {"$v13", RTYPE_VEC | 13}, \
1586 {"$v14", RTYPE_VEC | 14}, \
1587 {"$v15", RTYPE_VEC | 15}, \
1588 {"$v16", RTYPE_VEC | 16}, \
1589 {"$v17", RTYPE_VEC | 17}, \
1590 {"$v18", RTYPE_VEC | 18}, \
1591 {"$v19", RTYPE_VEC | 19}, \
1592 {"$v20", RTYPE_VEC | 20}, \
1593 {"$v21", RTYPE_VEC | 21}, \
1594 {"$v22", RTYPE_VEC | 22}, \
1595 {"$v23", RTYPE_VEC | 23}, \
1596 {"$v24", RTYPE_VEC | 24}, \
1597 {"$v25", RTYPE_VEC | 25}, \
1598 {"$v26", RTYPE_VEC | 26}, \
1599 {"$v27", RTYPE_VEC | 27}, \
1600 {"$v28", RTYPE_VEC | 28}, \
1601 {"$v29", RTYPE_VEC | 29}, \
1602 {"$v30", RTYPE_VEC | 30}, \
1603 {"$v31", RTYPE_VEC | 31}
1605 #define MIPS_DSP_ACCUMULATOR_NAMES \
1606 {"$ac0", RTYPE_ACC | 0}, \
1607 {"$ac1", RTYPE_ACC | 1}, \
1608 {"$ac2", RTYPE_ACC | 2}, \
1609 {"$ac3", RTYPE_ACC | 3}
1611 static const struct regname reg_names[] = {
1612 GENERIC_REGISTER_NUMBERS,
1614 FPU_CONDITION_CODE_NAMES,
1615 COPROC_CONDITION_CODE_NAMES,
1617 /* The $txx registers depends on the abi,
1618 these will be added later into the symbol table from
1619 one of the tables below once mips_abi is set after
1620 parsing of arguments from the command line. */
1621 SYMBOLIC_REGISTER_NAMES,
1623 MIPS16_SPECIAL_REGISTER_NAMES,
1624 MDMX_VECTOR_REGISTER_NAMES,
1625 MIPS_DSP_ACCUMULATOR_NAMES,
1629 static const struct regname reg_names_o32[] = {
1630 O32_SYMBOLIC_REGISTER_NAMES,
1634 static const struct regname reg_names_n32n64[] = {
1635 N32N64_SYMBOLIC_REGISTER_NAMES,
1640 reg_lookup (char **s, unsigned int types, unsigned int *regnop)
1647 /* Find end of name. */
1649 if (is_name_beginner (*e))
1651 while (is_part_of_name (*e))
1654 /* Terminate name. */
1658 /* Look for a register symbol. */
1659 if ((symbolP = symbol_find (*s)) && S_GET_SEGMENT (symbolP) == reg_section)
1661 int r = S_GET_VALUE (symbolP);
1663 reg = r & RNUM_MASK;
1664 else if ((types & RTYPE_VEC) && (r & ~1) == (RTYPE_GP | 2))
1665 /* Convert GP reg $v0/1 to MDMX reg $v0/1! */
1666 reg = (r & RNUM_MASK) - 2;
1668 /* Else see if this is a register defined in an itbl entry. */
1669 else if ((types & RTYPE_GP) && itbl_have_entries)
1676 if (itbl_get_reg_val (n, &r))
1677 reg = r & RNUM_MASK;
1680 /* Advance to next token if a register was recognised. */
1683 else if (types & RWARN)
1684 as_warn ("Unrecognized register name `%s'", *s);
1692 /* This function is called once, at assembler startup time. It should set up
1693 all the tables, etc. that the MD part of the assembler will need. */
1698 register const char *retval = NULL;
1702 if (mips_pic != NO_PIC)
1704 if (g_switch_seen && g_switch_value != 0)
1705 as_bad (_("-G may not be used in position-independent code"));
1709 if (! bfd_set_arch_mach (stdoutput, bfd_arch_mips, file_mips_arch))
1710 as_warn (_("Could not set architecture and machine"));
1712 op_hash = hash_new ();
1714 for (i = 0; i < NUMOPCODES;)
1716 const char *name = mips_opcodes[i].name;
1718 retval = hash_insert (op_hash, name, (void *) &mips_opcodes[i]);
1721 fprintf (stderr, _("internal error: can't hash `%s': %s\n"),
1722 mips_opcodes[i].name, retval);
1723 /* Probably a memory allocation problem? Give up now. */
1724 as_fatal (_("Broken assembler. No assembly attempted."));
1728 if (mips_opcodes[i].pinfo != INSN_MACRO)
1730 if (!validate_mips_insn (&mips_opcodes[i]))
1732 if (nop_insn.insn_mo == NULL && strcmp (name, "nop") == 0)
1734 create_insn (&nop_insn, mips_opcodes + i);
1735 nop_insn.fixed_p = 1;
1740 while ((i < NUMOPCODES) && !strcmp (mips_opcodes[i].name, name));
1743 mips16_op_hash = hash_new ();
1746 while (i < bfd_mips16_num_opcodes)
1748 const char *name = mips16_opcodes[i].name;
1750 retval = hash_insert (mips16_op_hash, name, (void *) &mips16_opcodes[i]);
1752 as_fatal (_("internal: can't hash `%s': %s"),
1753 mips16_opcodes[i].name, retval);
1756 if (mips16_opcodes[i].pinfo != INSN_MACRO
1757 && ((mips16_opcodes[i].match & mips16_opcodes[i].mask)
1758 != mips16_opcodes[i].match))
1760 fprintf (stderr, _("internal error: bad mips16 opcode: %s %s\n"),
1761 mips16_opcodes[i].name, mips16_opcodes[i].args);
1764 if (mips16_nop_insn.insn_mo == NULL && strcmp (name, "nop") == 0)
1766 create_insn (&mips16_nop_insn, mips16_opcodes + i);
1767 mips16_nop_insn.fixed_p = 1;
1771 while (i < bfd_mips16_num_opcodes
1772 && strcmp (mips16_opcodes[i].name, name) == 0);
1776 as_fatal (_("Broken assembler. No assembly attempted."));
1778 /* We add all the general register names to the symbol table. This
1779 helps us detect invalid uses of them. */
1780 for (i = 0; reg_names[i].name; i++)
1781 symbol_table_insert (symbol_new (reg_names[i].name, reg_section,
1782 reg_names[i].num, // & RNUM_MASK,
1783 &zero_address_frag));
1785 for (i = 0; reg_names_n32n64[i].name; i++)
1786 symbol_table_insert (symbol_new (reg_names_n32n64[i].name, reg_section,
1787 reg_names_n32n64[i].num, // & RNUM_MASK,
1788 &zero_address_frag));
1790 for (i = 0; reg_names_o32[i].name; i++)
1791 symbol_table_insert (symbol_new (reg_names_o32[i].name, reg_section,
1792 reg_names_o32[i].num, // & RNUM_MASK,
1793 &zero_address_frag));
1795 mips_no_prev_insn ();
1798 mips_cprmask[0] = 0;
1799 mips_cprmask[1] = 0;
1800 mips_cprmask[2] = 0;
1801 mips_cprmask[3] = 0;
1803 /* set the default alignment for the text section (2**2) */
1804 record_alignment (text_section, 2);
1806 bfd_set_gp_size (stdoutput, g_switch_value);
1809 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
1811 /* On a native system other than VxWorks, sections must be aligned
1812 to 16 byte boundaries. When configured for an embedded ELF
1813 target, we don't bother. */
1814 if (strcmp (TARGET_OS, "elf") != 0
1815 && strcmp (TARGET_OS, "vxworks") != 0)
1817 (void) bfd_set_section_alignment (stdoutput, text_section, 4);
1818 (void) bfd_set_section_alignment (stdoutput, data_section, 4);
1819 (void) bfd_set_section_alignment (stdoutput, bss_section, 4);
1822 /* Create a .reginfo section for register masks and a .mdebug
1823 section for debugging information. */
1831 subseg = now_subseg;
1833 /* The ABI says this section should be loaded so that the
1834 running program can access it. However, we don't load it
1835 if we are configured for an embedded target */
1836 flags = SEC_READONLY | SEC_DATA;
1837 if (strcmp (TARGET_OS, "elf") != 0)
1838 flags |= SEC_ALLOC | SEC_LOAD;
1840 if (mips_abi != N64_ABI)
1842 sec = subseg_new (".reginfo", (subsegT) 0);
1844 bfd_set_section_flags (stdoutput, sec, flags);
1845 bfd_set_section_alignment (stdoutput, sec, HAVE_NEWABI ? 3 : 2);
1847 mips_regmask_frag = frag_more (sizeof (Elf32_External_RegInfo));
1851 /* The 64-bit ABI uses a .MIPS.options section rather than
1852 .reginfo section. */
1853 sec = subseg_new (".MIPS.options", (subsegT) 0);
1854 bfd_set_section_flags (stdoutput, sec, flags);
1855 bfd_set_section_alignment (stdoutput, sec, 3);
1857 /* Set up the option header. */
1859 Elf_Internal_Options opthdr;
1862 opthdr.kind = ODK_REGINFO;
1863 opthdr.size = (sizeof (Elf_External_Options)
1864 + sizeof (Elf64_External_RegInfo));
1867 f = frag_more (sizeof (Elf_External_Options));
1868 bfd_mips_elf_swap_options_out (stdoutput, &opthdr,
1869 (Elf_External_Options *) f);
1871 mips_regmask_frag = frag_more (sizeof (Elf64_External_RegInfo));
1875 if (ECOFF_DEBUGGING)
1877 sec = subseg_new (".mdebug", (subsegT) 0);
1878 (void) bfd_set_section_flags (stdoutput, sec,
1879 SEC_HAS_CONTENTS | SEC_READONLY);
1880 (void) bfd_set_section_alignment (stdoutput, sec, 2);
1882 else if (OUTPUT_FLAVOR == bfd_target_elf_flavour && mips_flag_pdr)
1884 pdr_seg = subseg_new (".pdr", (subsegT) 0);
1885 (void) bfd_set_section_flags (stdoutput, pdr_seg,
1886 SEC_READONLY | SEC_RELOC
1888 (void) bfd_set_section_alignment (stdoutput, pdr_seg, 2);
1891 subseg_set (seg, subseg);
1894 #endif /* OBJ_ELF */
1896 if (! ECOFF_DEBUGGING)
1899 if (mips_fix_vr4120)
1900 init_vr4120_conflicts ();
1906 if (! ECOFF_DEBUGGING)
1911 md_assemble (char *str)
1913 struct mips_cl_insn insn;
1914 bfd_reloc_code_real_type unused_reloc[3]
1915 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
1917 imm_expr.X_op = O_absent;
1918 imm2_expr.X_op = O_absent;
1919 offset_expr.X_op = O_absent;
1920 imm_reloc[0] = BFD_RELOC_UNUSED;
1921 imm_reloc[1] = BFD_RELOC_UNUSED;
1922 imm_reloc[2] = BFD_RELOC_UNUSED;
1923 offset_reloc[0] = BFD_RELOC_UNUSED;
1924 offset_reloc[1] = BFD_RELOC_UNUSED;
1925 offset_reloc[2] = BFD_RELOC_UNUSED;
1927 if (mips_opts.mips16)
1928 mips16_ip (str, &insn);
1931 mips_ip (str, &insn);
1932 DBG ((_("returned from mips_ip(%s) insn_opcode = 0x%x\n"),
1933 str, insn.insn_opcode));
1938 as_bad ("%s `%s'", insn_error, str);
1942 if (insn.insn_mo->pinfo == INSN_MACRO)
1945 if (mips_opts.mips16)
1946 mips16_macro (&insn);
1953 if (imm_expr.X_op != O_absent)
1954 append_insn (&insn, &imm_expr, imm_reloc);
1955 else if (offset_expr.X_op != O_absent)
1956 append_insn (&insn, &offset_expr, offset_reloc);
1958 append_insn (&insn, NULL, unused_reloc);
1962 /* Return true if the given relocation might need a matching %lo().
1963 This is only "might" because SVR4 R_MIPS_GOT16 relocations only
1964 need a matching %lo() when applied to local symbols. */
1966 static inline bfd_boolean
1967 reloc_needs_lo_p (bfd_reloc_code_real_type reloc)
1969 return (HAVE_IN_PLACE_ADDENDS
1970 && (reloc == BFD_RELOC_HI16_S
1971 || reloc == BFD_RELOC_MIPS16_HI16_S
1972 /* VxWorks R_MIPS_GOT16 relocs never need a matching %lo();
1973 all GOT16 relocations evaluate to "G". */
1974 || (reloc == BFD_RELOC_MIPS_GOT16 && mips_pic != VXWORKS_PIC)));
1977 /* Return true if the given fixup is followed by a matching R_MIPS_LO16
1980 static inline bfd_boolean
1981 fixup_has_matching_lo_p (fixS *fixp)
1983 return (fixp->fx_next != NULL
1984 && (fixp->fx_next->fx_r_type == BFD_RELOC_LO16
1985 || fixp->fx_next->fx_r_type == BFD_RELOC_MIPS16_LO16)
1986 && fixp->fx_addsy == fixp->fx_next->fx_addsy
1987 && fixp->fx_offset == fixp->fx_next->fx_offset);
1990 /* See whether instruction IP reads register REG. CLASS is the type
1994 insn_uses_reg (const struct mips_cl_insn *ip, unsigned int reg,
1995 enum mips_regclass class)
1997 if (class == MIPS16_REG)
1999 assert (mips_opts.mips16);
2000 reg = mips16_to_32_reg_map[reg];
2001 class = MIPS_GR_REG;
2004 /* Don't report on general register ZERO, since it never changes. */
2005 if (class == MIPS_GR_REG && reg == ZERO)
2008 if (class == MIPS_FP_REG)
2010 assert (! mips_opts.mips16);
2011 /* If we are called with either $f0 or $f1, we must check $f0.
2012 This is not optimal, because it will introduce an unnecessary
2013 NOP between "lwc1 $f0" and "swc1 $f1". To fix this we would
2014 need to distinguish reading both $f0 and $f1 or just one of
2015 them. Note that we don't have to check the other way,
2016 because there is no instruction that sets both $f0 and $f1
2017 and requires a delay. */
2018 if ((ip->insn_mo->pinfo & INSN_READ_FPR_S)
2019 && ((EXTRACT_OPERAND (FS, *ip) & ~(unsigned) 1)
2020 == (reg &~ (unsigned) 1)))
2022 if ((ip->insn_mo->pinfo & INSN_READ_FPR_T)
2023 && ((EXTRACT_OPERAND (FT, *ip) & ~(unsigned) 1)
2024 == (reg &~ (unsigned) 1)))
2027 else if (! mips_opts.mips16)
2029 if ((ip->insn_mo->pinfo & INSN_READ_GPR_S)
2030 && EXTRACT_OPERAND (RS, *ip) == reg)
2032 if ((ip->insn_mo->pinfo & INSN_READ_GPR_T)
2033 && EXTRACT_OPERAND (RT, *ip) == reg)
2038 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_X)
2039 && mips16_to_32_reg_map[MIPS16_EXTRACT_OPERAND (RX, *ip)] == reg)
2041 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_Y)
2042 && mips16_to_32_reg_map[MIPS16_EXTRACT_OPERAND (RY, *ip)] == reg)
2044 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_Z)
2045 && (mips16_to_32_reg_map[MIPS16_EXTRACT_OPERAND (MOVE32Z, *ip)]
2048 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_T) && reg == TREG)
2050 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_SP) && reg == SP)
2052 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_31) && reg == RA)
2054 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_GPR_X)
2055 && MIPS16_EXTRACT_OPERAND (REGR32, *ip) == reg)
2062 /* This function returns true if modifying a register requires a
2066 reg_needs_delay (unsigned int reg)
2068 unsigned long prev_pinfo;
2070 prev_pinfo = history[0].insn_mo->pinfo;
2071 if (! mips_opts.noreorder
2072 && (((prev_pinfo & INSN_LOAD_MEMORY_DELAY)
2073 && ! gpr_interlocks)
2074 || ((prev_pinfo & INSN_LOAD_COPROC_DELAY)
2075 && ! cop_interlocks)))
2077 /* A load from a coprocessor or from memory. All load delays
2078 delay the use of general register rt for one instruction. */
2079 /* Itbl support may require additional care here. */
2080 know (prev_pinfo & INSN_WRITE_GPR_T);
2081 if (reg == EXTRACT_OPERAND (RT, history[0]))
2088 /* Move all labels in insn_labels to the current insertion point. */
2091 mips_move_labels (void)
2093 struct insn_label_list *l;
2096 for (l = insn_labels; l != NULL; l = l->next)
2098 assert (S_GET_SEGMENT (l->label) == now_seg);
2099 symbol_set_frag (l->label, frag_now);
2100 val = (valueT) frag_now_fix ();
2101 /* mips16 text labels are stored as odd. */
2102 if (mips_opts.mips16)
2104 S_SET_VALUE (l->label, val);
2108 /* Mark instruction labels in mips16 mode. This permits the linker to
2109 handle them specially, such as generating jalx instructions when
2110 needed. We also make them odd for the duration of the assembly, in
2111 order to generate the right sort of code. We will make them even
2112 in the adjust_symtab routine, while leaving them marked. This is
2113 convenient for the debugger and the disassembler. The linker knows
2114 to make them odd again. */
2117 mips16_mark_labels (void)
2119 if (mips_opts.mips16)
2121 struct insn_label_list *l;
2124 for (l = insn_labels; l != NULL; l = l->next)
2127 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
2128 S_SET_OTHER (l->label, STO_MIPS16);
2130 val = S_GET_VALUE (l->label);
2132 S_SET_VALUE (l->label, val + 1);
2137 /* End the current frag. Make it a variant frag and record the
2141 relax_close_frag (void)
2143 mips_macro_warning.first_frag = frag_now;
2144 frag_var (rs_machine_dependent, 0, 0,
2145 RELAX_ENCODE (mips_relax.sizes[0], mips_relax.sizes[1]),
2146 mips_relax.symbol, 0, (char *) mips_relax.first_fixup);
2148 memset (&mips_relax.sizes, 0, sizeof (mips_relax.sizes));
2149 mips_relax.first_fixup = 0;
2152 /* Start a new relaxation sequence whose expansion depends on SYMBOL.
2153 See the comment above RELAX_ENCODE for more details. */
2156 relax_start (symbolS *symbol)
2158 assert (mips_relax.sequence == 0);
2159 mips_relax.sequence = 1;
2160 mips_relax.symbol = symbol;
2163 /* Start generating the second version of a relaxable sequence.
2164 See the comment above RELAX_ENCODE for more details. */
2169 assert (mips_relax.sequence == 1);
2170 mips_relax.sequence = 2;
2173 /* End the current relaxable sequence. */
2178 assert (mips_relax.sequence == 2);
2179 relax_close_frag ();
2180 mips_relax.sequence = 0;
2183 /* Classify an instruction according to the FIX_VR4120_* enumeration.
2184 Return NUM_FIX_VR4120_CLASSES if the instruction isn't affected
2185 by VR4120 errata. */
2188 classify_vr4120_insn (const char *name)
2190 if (strncmp (name, "macc", 4) == 0)
2191 return FIX_VR4120_MACC;
2192 if (strncmp (name, "dmacc", 5) == 0)
2193 return FIX_VR4120_DMACC;
2194 if (strncmp (name, "mult", 4) == 0)
2195 return FIX_VR4120_MULT;
2196 if (strncmp (name, "dmult", 5) == 0)
2197 return FIX_VR4120_DMULT;
2198 if (strstr (name, "div"))
2199 return FIX_VR4120_DIV;
2200 if (strcmp (name, "mtlo") == 0 || strcmp (name, "mthi") == 0)
2201 return FIX_VR4120_MTHILO;
2202 return NUM_FIX_VR4120_CLASSES;
2205 /* Return the number of instructions that must separate INSN1 and INSN2,
2206 where INSN1 is the earlier instruction. Return the worst-case value
2207 for any INSN2 if INSN2 is null. */
2210 insns_between (const struct mips_cl_insn *insn1,
2211 const struct mips_cl_insn *insn2)
2213 unsigned long pinfo1, pinfo2;
2215 /* This function needs to know which pinfo flags are set for INSN2
2216 and which registers INSN2 uses. The former is stored in PINFO2 and
2217 the latter is tested via INSN2_USES_REG. If INSN2 is null, PINFO2
2218 will have every flag set and INSN2_USES_REG will always return true. */
2219 pinfo1 = insn1->insn_mo->pinfo;
2220 pinfo2 = insn2 ? insn2->insn_mo->pinfo : ~0U;
2222 #define INSN2_USES_REG(REG, CLASS) \
2223 (insn2 == NULL || insn_uses_reg (insn2, REG, CLASS))
2225 /* For most targets, write-after-read dependencies on the HI and LO
2226 registers must be separated by at least two instructions. */
2227 if (!hilo_interlocks)
2229 if ((pinfo1 & INSN_READ_LO) && (pinfo2 & INSN_WRITE_LO))
2231 if ((pinfo1 & INSN_READ_HI) && (pinfo2 & INSN_WRITE_HI))
2235 /* If we're working around r7000 errata, there must be two instructions
2236 between an mfhi or mflo and any instruction that uses the result. */
2237 if (mips_7000_hilo_fix
2238 && MF_HILO_INSN (pinfo1)
2239 && INSN2_USES_REG (EXTRACT_OPERAND (RD, *insn1), MIPS_GR_REG))
2242 /* If working around VR4120 errata, check for combinations that need
2243 a single intervening instruction. */
2244 if (mips_fix_vr4120)
2246 unsigned int class1, class2;
2248 class1 = classify_vr4120_insn (insn1->insn_mo->name);
2249 if (class1 != NUM_FIX_VR4120_CLASSES && vr4120_conflicts[class1] != 0)
2253 class2 = classify_vr4120_insn (insn2->insn_mo->name);
2254 if (vr4120_conflicts[class1] & (1 << class2))
2259 if (!mips_opts.mips16)
2261 /* Check for GPR or coprocessor load delays. All such delays
2262 are on the RT register. */
2263 /* Itbl support may require additional care here. */
2264 if ((!gpr_interlocks && (pinfo1 & INSN_LOAD_MEMORY_DELAY))
2265 || (!cop_interlocks && (pinfo1 & INSN_LOAD_COPROC_DELAY)))
2267 know (pinfo1 & INSN_WRITE_GPR_T);
2268 if (INSN2_USES_REG (EXTRACT_OPERAND (RT, *insn1), MIPS_GR_REG))
2272 /* Check for generic coprocessor hazards.
2274 This case is not handled very well. There is no special
2275 knowledge of CP0 handling, and the coprocessors other than
2276 the floating point unit are not distinguished at all. */
2277 /* Itbl support may require additional care here. FIXME!
2278 Need to modify this to include knowledge about
2279 user specified delays! */
2280 else if ((!cop_interlocks && (pinfo1 & INSN_COPROC_MOVE_DELAY))
2281 || (!cop_mem_interlocks && (pinfo1 & INSN_COPROC_MEMORY_DELAY)))
2283 /* Handle cases where INSN1 writes to a known general coprocessor
2284 register. There must be a one instruction delay before INSN2
2285 if INSN2 reads that register, otherwise no delay is needed. */
2286 if (pinfo1 & INSN_WRITE_FPR_T)
2288 if (INSN2_USES_REG (EXTRACT_OPERAND (FT, *insn1), MIPS_FP_REG))
2291 else if (pinfo1 & INSN_WRITE_FPR_S)
2293 if (INSN2_USES_REG (EXTRACT_OPERAND (FS, *insn1), MIPS_FP_REG))
2298 /* Read-after-write dependencies on the control registers
2299 require a two-instruction gap. */
2300 if ((pinfo1 & INSN_WRITE_COND_CODE)
2301 && (pinfo2 & INSN_READ_COND_CODE))
2304 /* We don't know exactly what INSN1 does. If INSN2 is
2305 also a coprocessor instruction, assume there must be
2306 a one instruction gap. */
2307 if (pinfo2 & INSN_COP)
2312 /* Check for read-after-write dependencies on the coprocessor
2313 control registers in cases where INSN1 does not need a general
2314 coprocessor delay. This means that INSN1 is a floating point
2315 comparison instruction. */
2316 /* Itbl support may require additional care here. */
2317 else if (!cop_interlocks
2318 && (pinfo1 & INSN_WRITE_COND_CODE)
2319 && (pinfo2 & INSN_READ_COND_CODE))
2323 #undef INSN2_USES_REG
2328 /* Return the number of nops that would be needed to work around the
2329 VR4130 mflo/mfhi errata if instruction INSN immediately followed
2330 the MAX_VR4130_NOPS instructions described by HISTORY. */
2333 nops_for_vr4130 (const struct mips_cl_insn *history,
2334 const struct mips_cl_insn *insn)
2338 /* Check if the instruction writes to HI or LO. MTHI and MTLO
2339 are not affected by the errata. */
2341 && ((insn->insn_mo->pinfo & (INSN_WRITE_HI | INSN_WRITE_LO)) == 0
2342 || strcmp (insn->insn_mo->name, "mtlo") == 0
2343 || strcmp (insn->insn_mo->name, "mthi") == 0))
2346 /* Search for the first MFLO or MFHI. */
2347 for (i = 0; i < MAX_VR4130_NOPS; i++)
2348 if (!history[i].noreorder_p && MF_HILO_INSN (history[i].insn_mo->pinfo))
2350 /* Extract the destination register. */
2351 if (mips_opts.mips16)
2352 reg = mips16_to_32_reg_map[MIPS16_EXTRACT_OPERAND (RX, history[i])];
2354 reg = EXTRACT_OPERAND (RD, history[i]);
2356 /* No nops are needed if INSN reads that register. */
2357 if (insn != NULL && insn_uses_reg (insn, reg, MIPS_GR_REG))
2360 /* ...or if any of the intervening instructions do. */
2361 for (j = 0; j < i; j++)
2362 if (insn_uses_reg (&history[j], reg, MIPS_GR_REG))
2365 return MAX_VR4130_NOPS - i;
2370 /* Return the number of nops that would be needed if instruction INSN
2371 immediately followed the MAX_NOPS instructions given by HISTORY,
2372 where HISTORY[0] is the most recent instruction. If INSN is null,
2373 return the worse-case number of nops for any instruction. */
2376 nops_for_insn (const struct mips_cl_insn *history,
2377 const struct mips_cl_insn *insn)
2379 int i, nops, tmp_nops;
2382 for (i = 0; i < MAX_DELAY_NOPS; i++)
2383 if (!history[i].noreorder_p)
2385 tmp_nops = insns_between (history + i, insn) - i;
2386 if (tmp_nops > nops)
2390 if (mips_fix_vr4130)
2392 tmp_nops = nops_for_vr4130 (history, insn);
2393 if (tmp_nops > nops)
2400 /* The variable arguments provide NUM_INSNS extra instructions that
2401 might be added to HISTORY. Return the largest number of nops that
2402 would be needed after the extended sequence. */
2405 nops_for_sequence (int num_insns, const struct mips_cl_insn *history, ...)
2408 struct mips_cl_insn buffer[MAX_NOPS];
2409 struct mips_cl_insn *cursor;
2412 va_start (args, history);
2413 cursor = buffer + num_insns;
2414 memcpy (cursor, history, (MAX_NOPS - num_insns) * sizeof (*cursor));
2415 while (cursor > buffer)
2416 *--cursor = *va_arg (args, const struct mips_cl_insn *);
2418 nops = nops_for_insn (buffer, NULL);
2423 /* Like nops_for_insn, but if INSN is a branch, take into account the
2424 worst-case delay for the branch target. */
2427 nops_for_insn_or_target (const struct mips_cl_insn *history,
2428 const struct mips_cl_insn *insn)
2432 nops = nops_for_insn (history, insn);
2433 if (insn->insn_mo->pinfo & (INSN_UNCOND_BRANCH_DELAY
2434 | INSN_COND_BRANCH_DELAY
2435 | INSN_COND_BRANCH_LIKELY))
2437 tmp_nops = nops_for_sequence (2, history, insn, NOP_INSN);
2438 if (tmp_nops > nops)
2441 else if (mips_opts.mips16 && (insn->insn_mo->pinfo & MIPS16_INSN_BRANCH))
2443 tmp_nops = nops_for_sequence (1, history, insn);
2444 if (tmp_nops > nops)
2450 /* Output an instruction. IP is the instruction information.
2451 ADDRESS_EXPR is an operand of the instruction to be used with
2455 append_insn (struct mips_cl_insn *ip, expressionS *address_expr,
2456 bfd_reloc_code_real_type *reloc_type)
2458 register unsigned long prev_pinfo, pinfo;
2459 relax_stateT prev_insn_frag_type = 0;
2460 bfd_boolean relaxed_branch = FALSE;
2462 /* Mark instruction labels in mips16 mode. */
2463 mips16_mark_labels ();
2465 prev_pinfo = history[0].insn_mo->pinfo;
2466 pinfo = ip->insn_mo->pinfo;
2468 if (mips_relax.sequence != 2 && !mips_opts.noreorder)
2470 /* There are a lot of optimizations we could do that we don't.
2471 In particular, we do not, in general, reorder instructions.
2472 If you use gcc with optimization, it will reorder
2473 instructions and generally do much more optimization then we
2474 do here; repeating all that work in the assembler would only
2475 benefit hand written assembly code, and does not seem worth
2477 int nops = (mips_optimize == 0
2478 ? nops_for_insn (history, NULL)
2479 : nops_for_insn_or_target (history, ip));
2483 unsigned long old_frag_offset;
2486 old_frag = frag_now;
2487 old_frag_offset = frag_now_fix ();
2489 for (i = 0; i < nops; i++)
2494 listing_prev_line ();
2495 /* We may be at the start of a variant frag. In case we
2496 are, make sure there is enough space for the frag
2497 after the frags created by listing_prev_line. The
2498 argument to frag_grow here must be at least as large
2499 as the argument to all other calls to frag_grow in
2500 this file. We don't have to worry about being in the
2501 middle of a variant frag, because the variants insert
2502 all needed nop instructions themselves. */
2506 mips_move_labels ();
2508 #ifndef NO_ECOFF_DEBUGGING
2509 if (ECOFF_DEBUGGING)
2510 ecoff_fix_loc (old_frag, old_frag_offset);
2514 else if (mips_relax.sequence != 2 && prev_nop_frag != NULL)
2516 /* Work out how many nops in prev_nop_frag are needed by IP. */
2517 int nops = nops_for_insn_or_target (history, ip);
2518 assert (nops <= prev_nop_frag_holds);
2520 /* Enforce NOPS as a minimum. */
2521 if (nops > prev_nop_frag_required)
2522 prev_nop_frag_required = nops;
2524 if (prev_nop_frag_holds == prev_nop_frag_required)
2526 /* Settle for the current number of nops. Update the history
2527 accordingly (for the benefit of any future .set reorder code). */
2528 prev_nop_frag = NULL;
2529 insert_into_history (prev_nop_frag_since,
2530 prev_nop_frag_holds, NOP_INSN);
2534 /* Allow this instruction to replace one of the nops that was
2535 tentatively added to prev_nop_frag. */
2536 prev_nop_frag->fr_fix -= mips_opts.mips16 ? 2 : 4;
2537 prev_nop_frag_holds--;
2538 prev_nop_frag_since++;
2543 /* The value passed to dwarf2_emit_insn is the distance between
2544 the beginning of the current instruction and the address that
2545 should be recorded in the debug tables. For MIPS16 debug info
2546 we want to use ISA-encoded addresses, so we pass -1 for an
2547 address higher by one than the current. */
2548 dwarf2_emit_insn (mips_opts.mips16 ? -1 : 0);
2551 /* Record the frag type before frag_var. */
2552 if (history[0].frag)
2553 prev_insn_frag_type = history[0].frag->fr_type;
2556 && *reloc_type == BFD_RELOC_16_PCREL_S2
2557 && (pinfo & INSN_UNCOND_BRANCH_DELAY || pinfo & INSN_COND_BRANCH_DELAY
2558 || pinfo & INSN_COND_BRANCH_LIKELY)
2559 && mips_relax_branch
2560 /* Don't try branch relaxation within .set nomacro, or within
2561 .set noat if we use $at for PIC computations. If it turns
2562 out that the branch was out-of-range, we'll get an error. */
2563 && !mips_opts.warn_about_macros
2564 && !(mips_opts.noat && mips_pic != NO_PIC)
2565 && !mips_opts.mips16)
2567 relaxed_branch = TRUE;
2568 add_relaxed_insn (ip, (relaxed_branch_length
2570 (pinfo & INSN_UNCOND_BRANCH_DELAY) ? -1
2571 : (pinfo & INSN_COND_BRANCH_LIKELY) ? 1
2574 (pinfo & INSN_UNCOND_BRANCH_DELAY,
2575 pinfo & INSN_COND_BRANCH_LIKELY,
2576 pinfo & INSN_WRITE_GPR_31,
2578 address_expr->X_add_symbol,
2579 address_expr->X_add_number);
2580 *reloc_type = BFD_RELOC_UNUSED;
2582 else if (*reloc_type > BFD_RELOC_UNUSED)
2584 /* We need to set up a variant frag. */
2585 assert (mips_opts.mips16 && address_expr != NULL);
2586 add_relaxed_insn (ip, 4, 0,
2588 (*reloc_type - BFD_RELOC_UNUSED,
2589 mips16_small, mips16_ext,
2590 prev_pinfo & INSN_UNCOND_BRANCH_DELAY,
2591 history[0].mips16_absolute_jump_p),
2592 make_expr_symbol (address_expr), 0);
2594 else if (mips_opts.mips16
2596 && *reloc_type != BFD_RELOC_MIPS16_JMP)
2598 if ((pinfo & INSN_UNCOND_BRANCH_DELAY) == 0)
2599 /* Make sure there is enough room to swap this instruction with
2600 a following jump instruction. */
2602 add_fixed_insn (ip);
2606 if (mips_opts.mips16
2607 && mips_opts.noreorder
2608 && (prev_pinfo & INSN_UNCOND_BRANCH_DELAY) != 0)
2609 as_warn (_("extended instruction in delay slot"));
2611 if (mips_relax.sequence)
2613 /* If we've reached the end of this frag, turn it into a variant
2614 frag and record the information for the instructions we've
2616 if (frag_room () < 4)
2617 relax_close_frag ();
2618 mips_relax.sizes[mips_relax.sequence - 1] += 4;
2621 if (mips_relax.sequence != 2)
2622 mips_macro_warning.sizes[0] += 4;
2623 if (mips_relax.sequence != 1)
2624 mips_macro_warning.sizes[1] += 4;
2626 if (mips_opts.mips16)
2629 ip->mips16_absolute_jump_p = (*reloc_type == BFD_RELOC_MIPS16_JMP);
2631 add_fixed_insn (ip);
2634 if (address_expr != NULL && *reloc_type <= BFD_RELOC_UNUSED)
2636 if (address_expr->X_op == O_constant)
2640 switch (*reloc_type)
2643 ip->insn_opcode |= address_expr->X_add_number;
2646 case BFD_RELOC_MIPS_HIGHEST:
2647 tmp = (address_expr->X_add_number + 0x800080008000ull) >> 48;
2648 ip->insn_opcode |= tmp & 0xffff;
2651 case BFD_RELOC_MIPS_HIGHER:
2652 tmp = (address_expr->X_add_number + 0x80008000ull) >> 32;
2653 ip->insn_opcode |= tmp & 0xffff;
2656 case BFD_RELOC_HI16_S:
2657 tmp = (address_expr->X_add_number + 0x8000) >> 16;
2658 ip->insn_opcode |= tmp & 0xffff;
2661 case BFD_RELOC_HI16:
2662 ip->insn_opcode |= (address_expr->X_add_number >> 16) & 0xffff;
2665 case BFD_RELOC_UNUSED:
2666 case BFD_RELOC_LO16:
2667 case BFD_RELOC_MIPS_GOT_DISP:
2668 ip->insn_opcode |= address_expr->X_add_number & 0xffff;
2671 case BFD_RELOC_MIPS_JMP:
2672 if ((address_expr->X_add_number & 3) != 0)
2673 as_bad (_("jump to misaligned address (0x%lx)"),
2674 (unsigned long) address_expr->X_add_number);
2675 ip->insn_opcode |= (address_expr->X_add_number >> 2) & 0x3ffffff;
2678 case BFD_RELOC_MIPS16_JMP:
2679 if ((address_expr->X_add_number & 3) != 0)
2680 as_bad (_("jump to misaligned address (0x%lx)"),
2681 (unsigned long) address_expr->X_add_number);
2683 (((address_expr->X_add_number & 0x7c0000) << 3)
2684 | ((address_expr->X_add_number & 0xf800000) >> 7)
2685 | ((address_expr->X_add_number & 0x3fffc) >> 2));
2688 case BFD_RELOC_16_PCREL_S2:
2689 if ((address_expr->X_add_number & 3) != 0)
2690 as_bad (_("branch to misaligned address (0x%lx)"),
2691 (unsigned long) address_expr->X_add_number);
2692 if (mips_relax_branch)
2694 if ((address_expr->X_add_number + 0x20000) & ~0x3ffff)
2695 as_bad (_("branch address range overflow (0x%lx)"),
2696 (unsigned long) address_expr->X_add_number);
2697 ip->insn_opcode |= (address_expr->X_add_number >> 2) & 0xffff;
2704 else if (*reloc_type < BFD_RELOC_UNUSED)
2707 reloc_howto_type *howto;
2710 /* In a compound relocation, it is the final (outermost)
2711 operator that determines the relocated field. */
2712 for (i = 1; i < 3; i++)
2713 if (reloc_type[i] == BFD_RELOC_UNUSED)
2716 howto = bfd_reloc_type_lookup (stdoutput, reloc_type[i - 1]);
2717 ip->fixp[0] = fix_new_exp (ip->frag, ip->where,
2718 bfd_get_reloc_size (howto),
2720 reloc_type[0] == BFD_RELOC_16_PCREL_S2,
2723 /* These relocations can have an addend that won't fit in
2724 4 octets for 64bit assembly. */
2726 && ! howto->partial_inplace
2727 && (reloc_type[0] == BFD_RELOC_16
2728 || reloc_type[0] == BFD_RELOC_32
2729 || reloc_type[0] == BFD_RELOC_MIPS_JMP
2730 || reloc_type[0] == BFD_RELOC_HI16_S
2731 || reloc_type[0] == BFD_RELOC_LO16
2732 || reloc_type[0] == BFD_RELOC_GPREL16
2733 || reloc_type[0] == BFD_RELOC_MIPS_LITERAL
2734 || reloc_type[0] == BFD_RELOC_GPREL32
2735 || reloc_type[0] == BFD_RELOC_64
2736 || reloc_type[0] == BFD_RELOC_CTOR
2737 || reloc_type[0] == BFD_RELOC_MIPS_SUB
2738 || reloc_type[0] == BFD_RELOC_MIPS_HIGHEST
2739 || reloc_type[0] == BFD_RELOC_MIPS_HIGHER
2740 || reloc_type[0] == BFD_RELOC_MIPS_SCN_DISP
2741 || reloc_type[0] == BFD_RELOC_MIPS_REL16
2742 || reloc_type[0] == BFD_RELOC_MIPS_RELGOT
2743 || reloc_type[0] == BFD_RELOC_MIPS16_GPREL
2744 || reloc_type[0] == BFD_RELOC_MIPS16_HI16_S
2745 || reloc_type[0] == BFD_RELOC_MIPS16_LO16))
2746 ip->fixp[0]->fx_no_overflow = 1;
2748 if (mips_relax.sequence)
2750 if (mips_relax.first_fixup == 0)
2751 mips_relax.first_fixup = ip->fixp[0];
2753 else if (reloc_needs_lo_p (*reloc_type))
2755 struct mips_hi_fixup *hi_fixup;
2757 /* Reuse the last entry if it already has a matching %lo. */
2758 hi_fixup = mips_hi_fixup_list;
2760 || !fixup_has_matching_lo_p (hi_fixup->fixp))
2762 hi_fixup = ((struct mips_hi_fixup *)
2763 xmalloc (sizeof (struct mips_hi_fixup)));
2764 hi_fixup->next = mips_hi_fixup_list;
2765 mips_hi_fixup_list = hi_fixup;
2767 hi_fixup->fixp = ip->fixp[0];
2768 hi_fixup->seg = now_seg;
2771 /* Add fixups for the second and third relocations, if given.
2772 Note that the ABI allows the second relocation to be
2773 against RSS_UNDEF, RSS_GP, RSS_GP0 or RSS_LOC. At the
2774 moment we only use RSS_UNDEF, but we could add support
2775 for the others if it ever becomes necessary. */
2776 for (i = 1; i < 3; i++)
2777 if (reloc_type[i] != BFD_RELOC_UNUSED)
2779 ip->fixp[i] = fix_new (ip->frag, ip->where,
2780 ip->fixp[0]->fx_size, NULL, 0,
2781 FALSE, reloc_type[i]);
2783 /* Use fx_tcbit to mark compound relocs. */
2784 ip->fixp[0]->fx_tcbit = 1;
2785 ip->fixp[i]->fx_tcbit = 1;
2791 /* Update the register mask information. */
2792 if (! mips_opts.mips16)
2794 if (pinfo & INSN_WRITE_GPR_D)
2795 mips_gprmask |= 1 << EXTRACT_OPERAND (RD, *ip);
2796 if ((pinfo & (INSN_WRITE_GPR_T | INSN_READ_GPR_T)) != 0)
2797 mips_gprmask |= 1 << EXTRACT_OPERAND (RT, *ip);
2798 if (pinfo & INSN_READ_GPR_S)
2799 mips_gprmask |= 1 << EXTRACT_OPERAND (RS, *ip);
2800 if (pinfo & INSN_WRITE_GPR_31)
2801 mips_gprmask |= 1 << RA;
2802 if (pinfo & INSN_WRITE_FPR_D)
2803 mips_cprmask[1] |= 1 << EXTRACT_OPERAND (FD, *ip);
2804 if ((pinfo & (INSN_WRITE_FPR_S | INSN_READ_FPR_S)) != 0)
2805 mips_cprmask[1] |= 1 << EXTRACT_OPERAND (FS, *ip);
2806 if ((pinfo & (INSN_WRITE_FPR_T | INSN_READ_FPR_T)) != 0)
2807 mips_cprmask[1] |= 1 << EXTRACT_OPERAND (FT, *ip);
2808 if ((pinfo & INSN_READ_FPR_R) != 0)
2809 mips_cprmask[1] |= 1 << EXTRACT_OPERAND (FR, *ip);
2810 if (pinfo & INSN_COP)
2812 /* We don't keep enough information to sort these cases out.
2813 The itbl support does keep this information however, although
2814 we currently don't support itbl fprmats as part of the cop
2815 instruction. May want to add this support in the future. */
2817 /* Never set the bit for $0, which is always zero. */
2818 mips_gprmask &= ~1 << 0;
2822 if (pinfo & (MIPS16_INSN_WRITE_X | MIPS16_INSN_READ_X))
2823 mips_gprmask |= 1 << MIPS16_EXTRACT_OPERAND (RX, *ip);
2824 if (pinfo & (MIPS16_INSN_WRITE_Y | MIPS16_INSN_READ_Y))
2825 mips_gprmask |= 1 << MIPS16_EXTRACT_OPERAND (RY, *ip);
2826 if (pinfo & MIPS16_INSN_WRITE_Z)
2827 mips_gprmask |= 1 << MIPS16_EXTRACT_OPERAND (RZ, *ip);
2828 if (pinfo & (MIPS16_INSN_WRITE_T | MIPS16_INSN_READ_T))
2829 mips_gprmask |= 1 << TREG;
2830 if (pinfo & (MIPS16_INSN_WRITE_SP | MIPS16_INSN_READ_SP))
2831 mips_gprmask |= 1 << SP;
2832 if (pinfo & (MIPS16_INSN_WRITE_31 | MIPS16_INSN_READ_31))
2833 mips_gprmask |= 1 << RA;
2834 if (pinfo & MIPS16_INSN_WRITE_GPR_Y)
2835 mips_gprmask |= 1 << MIPS16OP_EXTRACT_REG32R (ip->insn_opcode);
2836 if (pinfo & MIPS16_INSN_READ_Z)
2837 mips_gprmask |= 1 << MIPS16_EXTRACT_OPERAND (MOVE32Z, *ip);
2838 if (pinfo & MIPS16_INSN_READ_GPR_X)
2839 mips_gprmask |= 1 << MIPS16_EXTRACT_OPERAND (REGR32, *ip);
2842 if (mips_relax.sequence != 2 && !mips_opts.noreorder)
2844 /* Filling the branch delay slot is more complex. We try to
2845 switch the branch with the previous instruction, which we can
2846 do if the previous instruction does not set up a condition
2847 that the branch tests and if the branch is not itself the
2848 target of any branch. */
2849 if ((pinfo & INSN_UNCOND_BRANCH_DELAY)
2850 || (pinfo & INSN_COND_BRANCH_DELAY))
2852 if (mips_optimize < 2
2853 /* If we have seen .set volatile or .set nomove, don't
2855 || mips_opts.nomove != 0
2856 /* We can't swap if the previous instruction's position
2858 || history[0].fixed_p
2859 /* If the previous previous insn was in a .set
2860 noreorder, we can't swap. Actually, the MIPS
2861 assembler will swap in this situation. However, gcc
2862 configured -with-gnu-as will generate code like
2868 in which we can not swap the bne and INSN. If gcc is
2869 not configured -with-gnu-as, it does not output the
2871 || history[1].noreorder_p
2872 /* If the branch is itself the target of a branch, we
2873 can not swap. We cheat on this; all we check for is
2874 whether there is a label on this instruction. If
2875 there are any branches to anything other than a
2876 label, users must use .set noreorder. */
2877 || insn_labels != NULL
2878 /* If the previous instruction is in a variant frag
2879 other than this branch's one, we cannot do the swap.
2880 This does not apply to the mips16, which uses variant
2881 frags for different purposes. */
2882 || (! mips_opts.mips16
2883 && prev_insn_frag_type == rs_machine_dependent)
2884 /* Check for conflicts between the branch and the instructions
2885 before the candidate delay slot. */
2886 || nops_for_insn (history + 1, ip) > 0
2887 /* Check for conflicts between the swapped sequence and the
2888 target of the branch. */
2889 || nops_for_sequence (2, history + 1, ip, history) > 0
2890 /* We do not swap with a trap instruction, since it
2891 complicates trap handlers to have the trap
2892 instruction be in a delay slot. */
2893 || (prev_pinfo & INSN_TRAP)
2894 /* If the branch reads a register that the previous
2895 instruction sets, we can not swap. */
2896 || (! mips_opts.mips16
2897 && (prev_pinfo & INSN_WRITE_GPR_T)
2898 && insn_uses_reg (ip, EXTRACT_OPERAND (RT, history[0]),
2900 || (! mips_opts.mips16
2901 && (prev_pinfo & INSN_WRITE_GPR_D)
2902 && insn_uses_reg (ip, EXTRACT_OPERAND (RD, history[0]),
2904 || (mips_opts.mips16
2905 && (((prev_pinfo & MIPS16_INSN_WRITE_X)
2907 (ip, MIPS16_EXTRACT_OPERAND (RX, history[0]),
2909 || ((prev_pinfo & MIPS16_INSN_WRITE_Y)
2911 (ip, MIPS16_EXTRACT_OPERAND (RY, history[0]),
2913 || ((prev_pinfo & MIPS16_INSN_WRITE_Z)
2915 (ip, MIPS16_EXTRACT_OPERAND (RZ, history[0]),
2917 || ((prev_pinfo & MIPS16_INSN_WRITE_T)
2918 && insn_uses_reg (ip, TREG, MIPS_GR_REG))
2919 || ((prev_pinfo & MIPS16_INSN_WRITE_31)
2920 && insn_uses_reg (ip, RA, MIPS_GR_REG))
2921 || ((prev_pinfo & MIPS16_INSN_WRITE_GPR_Y)
2922 && insn_uses_reg (ip,
2923 MIPS16OP_EXTRACT_REG32R
2924 (history[0].insn_opcode),
2926 /* If the branch writes a register that the previous
2927 instruction sets, we can not swap (we know that
2928 branches write only to RD or to $31). */
2929 || (! mips_opts.mips16
2930 && (prev_pinfo & INSN_WRITE_GPR_T)
2931 && (((pinfo & INSN_WRITE_GPR_D)
2932 && (EXTRACT_OPERAND (RT, history[0])
2933 == EXTRACT_OPERAND (RD, *ip)))
2934 || ((pinfo & INSN_WRITE_GPR_31)
2935 && EXTRACT_OPERAND (RT, history[0]) == RA)))
2936 || (! mips_opts.mips16
2937 && (prev_pinfo & INSN_WRITE_GPR_D)
2938 && (((pinfo & INSN_WRITE_GPR_D)
2939 && (EXTRACT_OPERAND (RD, history[0])
2940 == EXTRACT_OPERAND (RD, *ip)))
2941 || ((pinfo & INSN_WRITE_GPR_31)
2942 && EXTRACT_OPERAND (RD, history[0]) == RA)))
2943 || (mips_opts.mips16
2944 && (pinfo & MIPS16_INSN_WRITE_31)
2945 && ((prev_pinfo & MIPS16_INSN_WRITE_31)
2946 || ((prev_pinfo & MIPS16_INSN_WRITE_GPR_Y)
2947 && (MIPS16OP_EXTRACT_REG32R (history[0].insn_opcode)
2949 /* If the branch writes a register that the previous
2950 instruction reads, we can not swap (we know that
2951 branches only write to RD or to $31). */
2952 || (! mips_opts.mips16
2953 && (pinfo & INSN_WRITE_GPR_D)
2954 && insn_uses_reg (&history[0],
2955 EXTRACT_OPERAND (RD, *ip),
2957 || (! mips_opts.mips16
2958 && (pinfo & INSN_WRITE_GPR_31)
2959 && insn_uses_reg (&history[0], RA, MIPS_GR_REG))
2960 || (mips_opts.mips16
2961 && (pinfo & MIPS16_INSN_WRITE_31)
2962 && insn_uses_reg (&history[0], RA, MIPS_GR_REG))
2963 /* If one instruction sets a condition code and the
2964 other one uses a condition code, we can not swap. */
2965 || ((pinfo & INSN_READ_COND_CODE)
2966 && (prev_pinfo & INSN_WRITE_COND_CODE))
2967 || ((pinfo & INSN_WRITE_COND_CODE)
2968 && (prev_pinfo & INSN_READ_COND_CODE))
2969 /* If the previous instruction uses the PC, we can not
2971 || (mips_opts.mips16
2972 && (prev_pinfo & MIPS16_INSN_READ_PC))
2973 /* If the previous instruction had a fixup in mips16
2974 mode, we can not swap. This normally means that the
2975 previous instruction was a 4 byte branch anyhow. */
2976 || (mips_opts.mips16 && history[0].fixp[0])
2977 /* If the previous instruction is a sync, sync.l, or
2978 sync.p, we can not swap. */
2979 || (prev_pinfo & INSN_SYNC))
2981 if (mips_opts.mips16
2982 && (pinfo & INSN_UNCOND_BRANCH_DELAY)
2983 && (pinfo & (MIPS16_INSN_READ_X | MIPS16_INSN_READ_31))
2984 && (mips_opts.isa == ISA_MIPS32
2985 || mips_opts.isa == ISA_MIPS32R2
2986 || mips_opts.isa == ISA_MIPS64
2987 || mips_opts.isa == ISA_MIPS64R2))
2989 /* Convert MIPS16 jr/jalr into a "compact" jump. */
2990 ip->insn_opcode |= 0x0080;
2992 insert_into_history (0, 1, ip);
2996 /* We could do even better for unconditional branches to
2997 portions of this object file; we could pick up the
2998 instruction at the destination, put it in the delay
2999 slot, and bump the destination address. */
3000 insert_into_history (0, 1, ip);
3004 if (mips_relax.sequence)
3005 mips_relax.sizes[mips_relax.sequence - 1] += 4;
3009 /* It looks like we can actually do the swap. */
3010 struct mips_cl_insn delay = history[0];
3011 if (mips_opts.mips16)
3013 know (delay.frag == ip->frag);
3014 move_insn (ip, delay.frag, delay.where);
3015 move_insn (&delay, ip->frag, ip->where + insn_length (ip));
3017 else if (relaxed_branch)
3019 /* Add the delay slot instruction to the end of the
3020 current frag and shrink the fixed part of the
3021 original frag. If the branch occupies the tail of
3022 the latter, move it backwards to cover the gap. */
3023 delay.frag->fr_fix -= 4;
3024 if (delay.frag == ip->frag)
3025 move_insn (ip, ip->frag, ip->where - 4);
3026 add_fixed_insn (&delay);
3030 move_insn (&delay, ip->frag, ip->where);
3031 move_insn (ip, history[0].frag, history[0].where);
3035 insert_into_history (0, 1, &delay);
3038 /* If that was an unconditional branch, forget the previous
3039 insn information. */
3040 if (pinfo & INSN_UNCOND_BRANCH_DELAY)
3041 mips_no_prev_insn ();
3043 else if (pinfo & INSN_COND_BRANCH_LIKELY)
3045 /* We don't yet optimize a branch likely. What we should do
3046 is look at the target, copy the instruction found there
3047 into the delay slot, and increment the branch to jump to
3048 the next instruction. */
3049 insert_into_history (0, 1, ip);
3053 insert_into_history (0, 1, ip);
3056 insert_into_history (0, 1, ip);
3058 /* We just output an insn, so the next one doesn't have a label. */
3059 mips_clear_insn_labels ();
3062 /* Forget that there was any previous instruction or label. */
3065 mips_no_prev_insn (void)
3067 prev_nop_frag = NULL;
3068 insert_into_history (0, ARRAY_SIZE (history), NOP_INSN);
3069 mips_clear_insn_labels ();
3072 /* This function must be called before we emit something other than
3073 instructions. It is like mips_no_prev_insn except that it inserts
3074 any NOPS that might be needed by previous instructions. */
3077 mips_emit_delays (void)
3079 if (! mips_opts.noreorder)
3081 int nops = nops_for_insn (history, NULL);
3085 add_fixed_insn (NOP_INSN);
3086 mips_move_labels ();
3089 mips_no_prev_insn ();
3092 /* Start a (possibly nested) noreorder block. */
3095 start_noreorder (void)
3097 if (mips_opts.noreorder == 0)
3102 /* None of the instructions before the .set noreorder can be moved. */
3103 for (i = 0; i < ARRAY_SIZE (history); i++)
3104 history[i].fixed_p = 1;
3106 /* Insert any nops that might be needed between the .set noreorder
3107 block and the previous instructions. We will later remove any
3108 nops that turn out not to be needed. */
3109 nops = nops_for_insn (history, NULL);
3112 if (mips_optimize != 0)
3114 /* Record the frag which holds the nop instructions, so
3115 that we can remove them if we don't need them. */
3116 frag_grow (mips_opts.mips16 ? nops * 2 : nops * 4);
3117 prev_nop_frag = frag_now;
3118 prev_nop_frag_holds = nops;
3119 prev_nop_frag_required = 0;
3120 prev_nop_frag_since = 0;
3123 for (; nops > 0; --nops)
3124 add_fixed_insn (NOP_INSN);
3126 /* Move on to a new frag, so that it is safe to simply
3127 decrease the size of prev_nop_frag. */
3128 frag_wane (frag_now);
3130 mips_move_labels ();
3132 mips16_mark_labels ();
3133 mips_clear_insn_labels ();
3135 mips_opts.noreorder++;
3136 mips_any_noreorder = 1;
3139 /* End a nested noreorder block. */
3142 end_noreorder (void)
3144 mips_opts.noreorder--;
3145 if (mips_opts.noreorder == 0 && prev_nop_frag != NULL)
3147 /* Commit to inserting prev_nop_frag_required nops and go back to
3148 handling nop insertion the .set reorder way. */
3149 prev_nop_frag->fr_fix -= ((prev_nop_frag_holds - prev_nop_frag_required)
3150 * (mips_opts.mips16 ? 2 : 4));
3151 insert_into_history (prev_nop_frag_since,
3152 prev_nop_frag_required, NOP_INSN);
3153 prev_nop_frag = NULL;
3157 /* Set up global variables for the start of a new macro. */
3162 memset (&mips_macro_warning.sizes, 0, sizeof (mips_macro_warning.sizes));
3163 mips_macro_warning.delay_slot_p = (mips_opts.noreorder
3164 && (history[0].insn_mo->pinfo
3165 & (INSN_UNCOND_BRANCH_DELAY
3166 | INSN_COND_BRANCH_DELAY
3167 | INSN_COND_BRANCH_LIKELY)) != 0);
3170 /* Given that a macro is longer than 4 bytes, return the appropriate warning
3171 for it. Return null if no warning is needed. SUBTYPE is a bitmask of
3172 RELAX_DELAY_SLOT and RELAX_NOMACRO. */
3175 macro_warning (relax_substateT subtype)
3177 if (subtype & RELAX_DELAY_SLOT)
3178 return _("Macro instruction expanded into multiple instructions"
3179 " in a branch delay slot");
3180 else if (subtype & RELAX_NOMACRO)
3181 return _("Macro instruction expanded into multiple instructions");
3186 /* Finish up a macro. Emit warnings as appropriate. */
3191 if (mips_macro_warning.sizes[0] > 4 || mips_macro_warning.sizes[1] > 4)
3193 relax_substateT subtype;
3195 /* Set up the relaxation warning flags. */
3197 if (mips_macro_warning.sizes[1] > mips_macro_warning.sizes[0])
3198 subtype |= RELAX_SECOND_LONGER;
3199 if (mips_opts.warn_about_macros)
3200 subtype |= RELAX_NOMACRO;
3201 if (mips_macro_warning.delay_slot_p)
3202 subtype |= RELAX_DELAY_SLOT;
3204 if (mips_macro_warning.sizes[0] > 4 && mips_macro_warning.sizes[1] > 4)
3206 /* Either the macro has a single implementation or both
3207 implementations are longer than 4 bytes. Emit the
3209 const char *msg = macro_warning (subtype);
3215 /* One implementation might need a warning but the other
3216 definitely doesn't. */
3217 mips_macro_warning.first_frag->fr_subtype |= subtype;
3222 /* Read a macro's relocation codes from *ARGS and store them in *R.
3223 The first argument in *ARGS will be either the code for a single
3224 relocation or -1 followed by the three codes that make up a
3225 composite relocation. */
3228 macro_read_relocs (va_list *args, bfd_reloc_code_real_type *r)
3232 next = va_arg (*args, int);
3234 r[0] = (bfd_reloc_code_real_type) next;
3236 for (i = 0; i < 3; i++)
3237 r[i] = (bfd_reloc_code_real_type) va_arg (*args, int);
3240 /* Build an instruction created by a macro expansion. This is passed
3241 a pointer to the count of instructions created so far, an
3242 expression, the name of the instruction to build, an operand format
3243 string, and corresponding arguments. */
3246 macro_build (expressionS *ep, const char *name, const char *fmt, ...)
3248 const struct mips_opcode *mo;
3249 struct mips_cl_insn insn;
3250 bfd_reloc_code_real_type r[3];
3253 va_start (args, fmt);
3255 if (mips_opts.mips16)
3257 mips16_macro_build (ep, name, fmt, args);
3262 r[0] = BFD_RELOC_UNUSED;
3263 r[1] = BFD_RELOC_UNUSED;
3264 r[2] = BFD_RELOC_UNUSED;
3265 mo = (struct mips_opcode *) hash_find (op_hash, name);
3267 assert (strcmp (name, mo->name) == 0);
3269 /* Search until we get a match for NAME. It is assumed here that
3270 macros will never generate MDMX or MIPS-3D instructions. */
3271 while (strcmp (fmt, mo->args) != 0
3272 || mo->pinfo == INSN_MACRO
3273 || !OPCODE_IS_MEMBER (mo,
3275 | (mips_opts.mips16 ? INSN_MIPS16 : 0)
3276 | (mips_opts.ase_smartmips ? INSN_SMARTMIPS : 0)),
3278 || (mips_opts.arch == CPU_R4650 && (mo->pinfo & FP_D) != 0))
3282 assert (strcmp (name, mo->name) == 0);
3285 create_insn (&insn, mo);
3303 INSERT_OPERAND (SHAMT, insn, va_arg (args, int));
3308 /* Note that in the macro case, these arguments are already
3309 in MSB form. (When handling the instruction in the
3310 non-macro case, these arguments are sizes from which
3311 MSB values must be calculated.) */
3312 INSERT_OPERAND (INSMSB, insn, va_arg (args, int));
3318 /* Note that in the macro case, these arguments are already
3319 in MSBD form. (When handling the instruction in the
3320 non-macro case, these arguments are sizes from which
3321 MSBD values must be calculated.) */
3322 INSERT_OPERAND (EXTMSBD, insn, va_arg (args, int));
3333 INSERT_OPERAND (RT, insn, va_arg (args, int));
3337 INSERT_OPERAND (CODE, insn, va_arg (args, int));
3342 INSERT_OPERAND (FT, insn, va_arg (args, int));
3348 INSERT_OPERAND (RD, insn, va_arg (args, int));
3353 int tmp = va_arg (args, int);
3355 INSERT_OPERAND (RT, insn, tmp);
3356 INSERT_OPERAND (RD, insn, tmp);
3362 INSERT_OPERAND (FS, insn, va_arg (args, int));
3369 INSERT_OPERAND (SHAMT, insn, va_arg (args, int));
3373 INSERT_OPERAND (FD, insn, va_arg (args, int));
3377 INSERT_OPERAND (CODE20, insn, va_arg (args, int));
3381 INSERT_OPERAND (CODE19, insn, va_arg (args, int));
3385 INSERT_OPERAND (CODE2, insn, va_arg (args, int));
3392 INSERT_OPERAND (RS, insn, va_arg (args, int));
3398 macro_read_relocs (&args, r);
3399 assert (*r == BFD_RELOC_GPREL16
3400 || *r == BFD_RELOC_MIPS_LITERAL
3401 || *r == BFD_RELOC_MIPS_HIGHER
3402 || *r == BFD_RELOC_HI16_S
3403 || *r == BFD_RELOC_LO16
3404 || *r == BFD_RELOC_MIPS_GOT16
3405 || *r == BFD_RELOC_MIPS_CALL16
3406 || *r == BFD_RELOC_MIPS_GOT_DISP
3407 || *r == BFD_RELOC_MIPS_GOT_PAGE
3408 || *r == BFD_RELOC_MIPS_GOT_OFST
3409 || *r == BFD_RELOC_MIPS_GOT_LO16
3410 || *r == BFD_RELOC_MIPS_CALL_LO16);
3414 macro_read_relocs (&args, r);
3416 && (ep->X_op == O_constant
3417 || (ep->X_op == O_symbol
3418 && (*r == BFD_RELOC_MIPS_HIGHEST
3419 || *r == BFD_RELOC_HI16_S
3420 || *r == BFD_RELOC_HI16
3421 || *r == BFD_RELOC_GPREL16
3422 || *r == BFD_RELOC_MIPS_GOT_HI16
3423 || *r == BFD_RELOC_MIPS_CALL_HI16))));
3427 assert (ep != NULL);
3430 * This allows macro() to pass an immediate expression for
3431 * creating short branches without creating a symbol.
3433 * We don't allow branch relaxation for these branches, as
3434 * they should only appear in ".set nomacro" anyway.
3436 if (ep->X_op == O_constant)
3438 if ((ep->X_add_number & 3) != 0)
3439 as_bad (_("branch to misaligned address (0x%lx)"),
3440 (unsigned long) ep->X_add_number);
3441 if ((ep->X_add_number + 0x20000) & ~0x3ffff)
3442 as_bad (_("branch address range overflow (0x%lx)"),
3443 (unsigned long) ep->X_add_number);
3444 insn.insn_opcode |= (ep->X_add_number >> 2) & 0xffff;
3448 *r = BFD_RELOC_16_PCREL_S2;
3452 assert (ep != NULL);
3453 *r = BFD_RELOC_MIPS_JMP;
3457 insn.insn_opcode |= va_arg (args, unsigned long);
3461 insn.insn_opcode |= va_arg (args, unsigned long) << OP_SH_CACHE;
3470 assert (*r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL);
3472 append_insn (&insn, ep, r);
3476 mips16_macro_build (expressionS *ep, const char *name, const char *fmt,
3479 struct mips_opcode *mo;
3480 struct mips_cl_insn insn;
3481 bfd_reloc_code_real_type r[3]
3482 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
3484 mo = (struct mips_opcode *) hash_find (mips16_op_hash, name);
3486 assert (strcmp (name, mo->name) == 0);
3488 while (strcmp (fmt, mo->args) != 0 || mo->pinfo == INSN_MACRO)
3492 assert (strcmp (name, mo->name) == 0);
3495 create_insn (&insn, mo);
3513 MIPS16_INSERT_OPERAND (RY, insn, va_arg (args, int));
3518 MIPS16_INSERT_OPERAND (RX, insn, va_arg (args, int));
3522 MIPS16_INSERT_OPERAND (RZ, insn, va_arg (args, int));
3526 MIPS16_INSERT_OPERAND (MOVE32Z, insn, va_arg (args, int));
3536 MIPS16_INSERT_OPERAND (REGR32, insn, va_arg (args, int));
3543 regno = va_arg (args, int);
3544 regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3);
3545 insn.insn_opcode |= regno << MIPS16OP_SH_REG32R;
3566 assert (ep != NULL);
3568 if (ep->X_op != O_constant)
3569 *r = (int) BFD_RELOC_UNUSED + c;
3572 mips16_immed (NULL, 0, c, ep->X_add_number, FALSE, FALSE,
3573 FALSE, &insn.insn_opcode, &insn.use_extend,
3576 *r = BFD_RELOC_UNUSED;
3582 MIPS16_INSERT_OPERAND (IMM6, insn, va_arg (args, int));
3589 assert (*r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL);
3591 append_insn (&insn, ep, r);
3595 * Sign-extend 32-bit mode constants that have bit 31 set and all
3596 * higher bits unset.
3599 normalize_constant_expr (expressionS *ex)
3601 if (ex->X_op == O_constant
3602 && IS_ZEXT_32BIT_NUM (ex->X_add_number))
3603 ex->X_add_number = (((ex->X_add_number & 0xffffffff) ^ 0x80000000)
3608 * Sign-extend 32-bit mode address offsets that have bit 31 set and
3609 * all higher bits unset.
3612 normalize_address_expr (expressionS *ex)
3614 if (((ex->X_op == O_constant && HAVE_32BIT_ADDRESSES)
3615 || (ex->X_op == O_symbol && HAVE_32BIT_SYMBOLS))
3616 && IS_ZEXT_32BIT_NUM (ex->X_add_number))
3617 ex->X_add_number = (((ex->X_add_number & 0xffffffff) ^ 0x80000000)
3622 * Generate a "jalr" instruction with a relocation hint to the called
3623 * function. This occurs in NewABI PIC code.
3626 macro_build_jalr (expressionS *ep)
3635 macro_build (NULL, "jalr", "d,s", RA, PIC_CALL_REG);
3637 fix_new_exp (frag_now, f - frag_now->fr_literal,
3638 4, ep, FALSE, BFD_RELOC_MIPS_JALR);
3642 * Generate a "lui" instruction.
3645 macro_build_lui (expressionS *ep, int regnum)
3647 expressionS high_expr;
3648 const struct mips_opcode *mo;
3649 struct mips_cl_insn insn;
3650 bfd_reloc_code_real_type r[3]
3651 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
3652 const char *name = "lui";
3653 const char *fmt = "t,u";
3655 assert (! mips_opts.mips16);
3659 if (high_expr.X_op == O_constant)
3661 /* we can compute the instruction now without a relocation entry */
3662 high_expr.X_add_number = ((high_expr.X_add_number + 0x8000)
3664 *r = BFD_RELOC_UNUSED;
3668 assert (ep->X_op == O_symbol);
3669 /* _gp_disp is a special case, used from s_cpload.
3670 __gnu_local_gp is used if mips_no_shared. */
3671 assert (mips_pic == NO_PIC
3673 && strcmp (S_GET_NAME (ep->X_add_symbol), "_gp_disp") == 0)
3674 || (! mips_in_shared
3675 && strcmp (S_GET_NAME (ep->X_add_symbol),
3676 "__gnu_local_gp") == 0));
3677 *r = BFD_RELOC_HI16_S;
3680 mo = hash_find (op_hash, name);
3681 assert (strcmp (name, mo->name) == 0);
3682 assert (strcmp (fmt, mo->args) == 0);
3683 create_insn (&insn, mo);
3685 insn.insn_opcode = insn.insn_mo->match;
3686 INSERT_OPERAND (RT, insn, regnum);
3687 if (*r == BFD_RELOC_UNUSED)
3689 insn.insn_opcode |= high_expr.X_add_number;
3690 append_insn (&insn, NULL, r);
3693 append_insn (&insn, &high_expr, r);
3696 /* Generate a sequence of instructions to do a load or store from a constant
3697 offset off of a base register (breg) into/from a target register (treg),
3698 using AT if necessary. */
3700 macro_build_ldst_constoffset (expressionS *ep, const char *op,
3701 int treg, int breg, int dbl)
3703 assert (ep->X_op == O_constant);
3705 /* Sign-extending 32-bit constants makes their handling easier. */
3707 normalize_constant_expr (ep);
3709 /* Right now, this routine can only handle signed 32-bit constants. */
3710 if (! IS_SEXT_32BIT_NUM(ep->X_add_number + 0x8000))
3711 as_warn (_("operand overflow"));
3713 if (IS_SEXT_16BIT_NUM(ep->X_add_number))
3715 /* Signed 16-bit offset will fit in the op. Easy! */
3716 macro_build (ep, op, "t,o(b)", treg, BFD_RELOC_LO16, breg);
3720 /* 32-bit offset, need multiple instructions and AT, like:
3721 lui $tempreg,const_hi (BFD_RELOC_HI16_S)
3722 addu $tempreg,$tempreg,$breg
3723 <op> $treg,const_lo($tempreg) (BFD_RELOC_LO16)
3724 to handle the complete offset. */
3725 macro_build_lui (ep, AT);
3726 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, AT, breg);
3727 macro_build (ep, op, "t,o(b)", treg, BFD_RELOC_LO16, AT);
3730 as_bad (_("Macro used $at after \".set noat\""));
3735 * Generates code to set the $at register to true (one)
3736 * if reg is less than the immediate expression.
3739 set_at (int reg, int unsignedp)
3741 if (imm_expr.X_op == O_constant
3742 && imm_expr.X_add_number >= -0x8000
3743 && imm_expr.X_add_number < 0x8000)
3744 macro_build (&imm_expr, unsignedp ? "sltiu" : "slti", "t,r,j",
3745 AT, reg, BFD_RELOC_LO16);
3748 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
3749 macro_build (NULL, unsignedp ? "sltu" : "slt", "d,v,t", AT, reg, AT);
3753 /* Warn if an expression is not a constant. */
3756 check_absolute_expr (struct mips_cl_insn *ip, expressionS *ex)
3758 if (ex->X_op == O_big)
3759 as_bad (_("unsupported large constant"));
3760 else if (ex->X_op != O_constant)
3761 as_bad (_("Instruction %s requires absolute expression"),
3764 if (HAVE_32BIT_GPRS)
3765 normalize_constant_expr (ex);
3768 /* Count the leading zeroes by performing a binary chop. This is a
3769 bulky bit of source, but performance is a LOT better for the
3770 majority of values than a simple loop to count the bits:
3771 for (lcnt = 0; (lcnt < 32); lcnt++)
3772 if ((v) & (1 << (31 - lcnt)))
3774 However it is not code size friendly, and the gain will drop a bit
3775 on certain cached systems.
3777 #define COUNT_TOP_ZEROES(v) \
3778 (((v) & ~0xffff) == 0 \
3779 ? ((v) & ~0xff) == 0 \
3780 ? ((v) & ~0xf) == 0 \
3781 ? ((v) & ~0x3) == 0 \
3782 ? ((v) & ~0x1) == 0 \
3787 : ((v) & ~0x7) == 0 \
3790 : ((v) & ~0x3f) == 0 \
3791 ? ((v) & ~0x1f) == 0 \
3794 : ((v) & ~0x7f) == 0 \
3797 : ((v) & ~0xfff) == 0 \
3798 ? ((v) & ~0x3ff) == 0 \
3799 ? ((v) & ~0x1ff) == 0 \
3802 : ((v) & ~0x7ff) == 0 \
3805 : ((v) & ~0x3fff) == 0 \
3806 ? ((v) & ~0x1fff) == 0 \
3809 : ((v) & ~0x7fff) == 0 \
3812 : ((v) & ~0xffffff) == 0 \
3813 ? ((v) & ~0xfffff) == 0 \
3814 ? ((v) & ~0x3ffff) == 0 \
3815 ? ((v) & ~0x1ffff) == 0 \
3818 : ((v) & ~0x7ffff) == 0 \
3821 : ((v) & ~0x3fffff) == 0 \
3822 ? ((v) & ~0x1fffff) == 0 \
3825 : ((v) & ~0x7fffff) == 0 \
3828 : ((v) & ~0xfffffff) == 0 \
3829 ? ((v) & ~0x3ffffff) == 0 \
3830 ? ((v) & ~0x1ffffff) == 0 \
3833 : ((v) & ~0x7ffffff) == 0 \
3836 : ((v) & ~0x3fffffff) == 0 \
3837 ? ((v) & ~0x1fffffff) == 0 \
3840 : ((v) & ~0x7fffffff) == 0 \
3845 * This routine generates the least number of instructions necessary to load
3846 * an absolute expression value into a register.
3849 load_register (int reg, expressionS *ep, int dbl)
3852 expressionS hi32, lo32;
3854 if (ep->X_op != O_big)
3856 assert (ep->X_op == O_constant);
3858 /* Sign-extending 32-bit constants makes their handling easier. */
3860 normalize_constant_expr (ep);
3862 if (IS_SEXT_16BIT_NUM (ep->X_add_number))
3864 /* We can handle 16 bit signed values with an addiu to
3865 $zero. No need to ever use daddiu here, since $zero and
3866 the result are always correct in 32 bit mode. */
3867 macro_build (ep, "addiu", "t,r,j", reg, 0, BFD_RELOC_LO16);
3870 else if (ep->X_add_number >= 0 && ep->X_add_number < 0x10000)
3872 /* We can handle 16 bit unsigned values with an ori to
3874 macro_build (ep, "ori", "t,r,i", reg, 0, BFD_RELOC_LO16);
3877 else if ((IS_SEXT_32BIT_NUM (ep->X_add_number)))
3879 /* 32 bit values require an lui. */
3880 macro_build (ep, "lui", "t,u", reg, BFD_RELOC_HI16);
3881 if ((ep->X_add_number & 0xffff) != 0)
3882 macro_build (ep, "ori", "t,r,i", reg, reg, BFD_RELOC_LO16);
3887 /* The value is larger than 32 bits. */
3889 if (!dbl || HAVE_32BIT_GPRS)
3893 sprintf_vma (value, ep->X_add_number);
3894 as_bad (_("Number (0x%s) larger than 32 bits"), value);
3895 macro_build (ep, "addiu", "t,r,j", reg, 0, BFD_RELOC_LO16);
3899 if (ep->X_op != O_big)
3902 hi32.X_add_number = (valueT) hi32.X_add_number >> 16;
3903 hi32.X_add_number = (valueT) hi32.X_add_number >> 16;
3904 hi32.X_add_number &= 0xffffffff;
3906 lo32.X_add_number &= 0xffffffff;
3910 assert (ep->X_add_number > 2);
3911 if (ep->X_add_number == 3)
3912 generic_bignum[3] = 0;
3913 else if (ep->X_add_number > 4)
3914 as_bad (_("Number larger than 64 bits"));
3915 lo32.X_op = O_constant;
3916 lo32.X_add_number = generic_bignum[0] + (generic_bignum[1] << 16);
3917 hi32.X_op = O_constant;
3918 hi32.X_add_number = generic_bignum[2] + (generic_bignum[3] << 16);
3921 if (hi32.X_add_number == 0)
3926 unsigned long hi, lo;
3928 if (hi32.X_add_number == (offsetT) 0xffffffff)
3930 if ((lo32.X_add_number & 0xffff8000) == 0xffff8000)
3932 macro_build (&lo32, "addiu", "t,r,j", reg, 0, BFD_RELOC_LO16);
3935 if (lo32.X_add_number & 0x80000000)
3937 macro_build (&lo32, "lui", "t,u", reg, BFD_RELOC_HI16);
3938 if (lo32.X_add_number & 0xffff)
3939 macro_build (&lo32, "ori", "t,r,i", reg, reg, BFD_RELOC_LO16);
3944 /* Check for 16bit shifted constant. We know that hi32 is
3945 non-zero, so start the mask on the first bit of the hi32
3950 unsigned long himask, lomask;
3954 himask = 0xffff >> (32 - shift);
3955 lomask = (0xffff << shift) & 0xffffffff;
3959 himask = 0xffff << (shift - 32);
3962 if ((hi32.X_add_number & ~(offsetT) himask) == 0
3963 && (lo32.X_add_number & ~(offsetT) lomask) == 0)
3967 tmp.X_op = O_constant;
3969 tmp.X_add_number = ((hi32.X_add_number << (32 - shift))
3970 | (lo32.X_add_number >> shift));
3972 tmp.X_add_number = hi32.X_add_number >> (shift - 32);
3973 macro_build (&tmp, "ori", "t,r,i", reg, 0, BFD_RELOC_LO16);
3974 macro_build (NULL, (shift >= 32) ? "dsll32" : "dsll", "d,w,<",
3975 reg, reg, (shift >= 32) ? shift - 32 : shift);
3980 while (shift <= (64 - 16));
3982 /* Find the bit number of the lowest one bit, and store the
3983 shifted value in hi/lo. */
3984 hi = (unsigned long) (hi32.X_add_number & 0xffffffff);
3985 lo = (unsigned long) (lo32.X_add_number & 0xffffffff);
3989 while ((lo & 1) == 0)
3994 lo |= (hi & (((unsigned long) 1 << bit) - 1)) << (32 - bit);
4000 while ((hi & 1) == 0)
4009 /* Optimize if the shifted value is a (power of 2) - 1. */
4010 if ((hi == 0 && ((lo + 1) & lo) == 0)
4011 || (lo == 0xffffffff && ((hi + 1) & hi) == 0))
4013 shift = COUNT_TOP_ZEROES ((unsigned int) hi32.X_add_number);
4018 /* This instruction will set the register to be all
4020 tmp.X_op = O_constant;
4021 tmp.X_add_number = (offsetT) -1;
4022 macro_build (&tmp, "addiu", "t,r,j", reg, 0, BFD_RELOC_LO16);
4026 macro_build (NULL, (bit >= 32) ? "dsll32" : "dsll", "d,w,<",
4027 reg, reg, (bit >= 32) ? bit - 32 : bit);
4029 macro_build (NULL, (shift >= 32) ? "dsrl32" : "dsrl", "d,w,<",
4030 reg, reg, (shift >= 32) ? shift - 32 : shift);
4035 /* Sign extend hi32 before calling load_register, because we can
4036 generally get better code when we load a sign extended value. */
4037 if ((hi32.X_add_number & 0x80000000) != 0)
4038 hi32.X_add_number |= ~(offsetT) 0xffffffff;
4039 load_register (reg, &hi32, 0);
4042 if ((lo32.X_add_number & 0xffff0000) == 0)
4046 macro_build (NULL, "dsll32", "d,w,<", reg, freg, 0);
4054 if ((freg == 0) && (lo32.X_add_number == (offsetT) 0xffffffff))
4056 macro_build (&lo32, "lui", "t,u", reg, BFD_RELOC_HI16);
4057 macro_build (NULL, "dsrl32", "d,w,<", reg, reg, 0);
4063 macro_build (NULL, "dsll", "d,w,<", reg, freg, 16);
4067 mid16.X_add_number >>= 16;
4068 macro_build (&mid16, "ori", "t,r,i", reg, freg, BFD_RELOC_LO16);
4069 macro_build (NULL, "dsll", "d,w,<", reg, reg, 16);
4072 if ((lo32.X_add_number & 0xffff) != 0)
4073 macro_build (&lo32, "ori", "t,r,i", reg, freg, BFD_RELOC_LO16);
4077 load_delay_nop (void)
4079 if (!gpr_interlocks)
4080 macro_build (NULL, "nop", "");
4083 /* Load an address into a register. */
4086 load_address (int reg, expressionS *ep, int *used_at)
4088 if (ep->X_op != O_constant
4089 && ep->X_op != O_symbol)
4091 as_bad (_("expression too complex"));
4092 ep->X_op = O_constant;
4095 if (ep->X_op == O_constant)
4097 load_register (reg, ep, HAVE_64BIT_ADDRESSES);
4101 if (mips_pic == NO_PIC)
4103 /* If this is a reference to a GP relative symbol, we want
4104 addiu $reg,$gp,<sym> (BFD_RELOC_GPREL16)
4106 lui $reg,<sym> (BFD_RELOC_HI16_S)
4107 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
4108 If we have an addend, we always use the latter form.
4110 With 64bit address space and a usable $at we want
4111 lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST)
4112 lui $at,<sym> (BFD_RELOC_HI16_S)
4113 daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER)
4114 daddiu $at,<sym> (BFD_RELOC_LO16)
4118 If $at is already in use, we use a path which is suboptimal
4119 on superscalar processors.
4120 lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST)
4121 daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER)
4123 daddiu $reg,<sym> (BFD_RELOC_HI16_S)
4125 daddiu $reg,<sym> (BFD_RELOC_LO16)
4127 For GP relative symbols in 64bit address space we can use
4128 the same sequence as in 32bit address space. */
4129 if (HAVE_64BIT_SYMBOLS)
4131 if ((valueT) ep->X_add_number <= MAX_GPREL_OFFSET
4132 && !nopic_need_relax (ep->X_add_symbol, 1))
4134 relax_start (ep->X_add_symbol);
4135 macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", reg,
4136 mips_gp_register, BFD_RELOC_GPREL16);
4140 if (*used_at == 0 && !mips_opts.noat)
4142 macro_build (ep, "lui", "t,u", reg, BFD_RELOC_MIPS_HIGHEST);
4143 macro_build (ep, "lui", "t,u", AT, BFD_RELOC_HI16_S);
4144 macro_build (ep, "daddiu", "t,r,j", reg, reg,
4145 BFD_RELOC_MIPS_HIGHER);
4146 macro_build (ep, "daddiu", "t,r,j", AT, AT, BFD_RELOC_LO16);
4147 macro_build (NULL, "dsll32", "d,w,<", reg, reg, 0);
4148 macro_build (NULL, "daddu", "d,v,t", reg, reg, AT);
4153 macro_build (ep, "lui", "t,u", reg, BFD_RELOC_MIPS_HIGHEST);
4154 macro_build (ep, "daddiu", "t,r,j", reg, reg,
4155 BFD_RELOC_MIPS_HIGHER);
4156 macro_build (NULL, "dsll", "d,w,<", reg, reg, 16);
4157 macro_build (ep, "daddiu", "t,r,j", reg, reg, BFD_RELOC_HI16_S);
4158 macro_build (NULL, "dsll", "d,w,<", reg, reg, 16);
4159 macro_build (ep, "daddiu", "t,r,j", reg, reg, BFD_RELOC_LO16);
4162 if (mips_relax.sequence)
4167 if ((valueT) ep->X_add_number <= MAX_GPREL_OFFSET
4168 && !nopic_need_relax (ep->X_add_symbol, 1))
4170 relax_start (ep->X_add_symbol);
4171 macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", reg,
4172 mips_gp_register, BFD_RELOC_GPREL16);
4175 macro_build_lui (ep, reg);
4176 macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j",
4177 reg, reg, BFD_RELOC_LO16);
4178 if (mips_relax.sequence)
4182 else if (!mips_big_got)
4186 /* If this is a reference to an external symbol, we want
4187 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4189 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4191 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
4192 If there is a constant, it must be added in after.
4194 If we have NewABI, we want
4195 lw $reg,<sym+cst>($gp) (BFD_RELOC_MIPS_GOT_DISP)
4196 unless we're referencing a global symbol with a non-zero
4197 offset, in which case cst must be added separately. */
4200 if (ep->X_add_number)
4202 ex.X_add_number = ep->X_add_number;
4203 ep->X_add_number = 0;
4204 relax_start (ep->X_add_symbol);
4205 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
4206 BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
4207 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
4208 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
4209 ex.X_op = O_constant;
4210 macro_build (&ex, ADDRESS_ADDI_INSN, "t,r,j",
4211 reg, reg, BFD_RELOC_LO16);
4212 ep->X_add_number = ex.X_add_number;
4215 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
4216 BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
4217 if (mips_relax.sequence)
4222 ex.X_add_number = ep->X_add_number;
4223 ep->X_add_number = 0;
4224 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
4225 BFD_RELOC_MIPS_GOT16, mips_gp_register);
4227 relax_start (ep->X_add_symbol);
4229 macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", reg, reg,
4233 if (ex.X_add_number != 0)
4235 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
4236 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
4237 ex.X_op = O_constant;
4238 macro_build (&ex, ADDRESS_ADDI_INSN, "t,r,j",
4239 reg, reg, BFD_RELOC_LO16);
4243 else if (mips_big_got)
4247 /* This is the large GOT case. If this is a reference to an
4248 external symbol, we want
4249 lui $reg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
4251 lw $reg,<sym>($reg) (BFD_RELOC_MIPS_GOT_LO16)
4253 Otherwise, for a reference to a local symbol in old ABI, we want
4254 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4256 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
4257 If there is a constant, it must be added in after.
4259 In the NewABI, for local symbols, with or without offsets, we want:
4260 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
4261 addiu $reg,$reg,<sym> (BFD_RELOC_MIPS_GOT_OFST)
4265 ex.X_add_number = ep->X_add_number;
4266 ep->X_add_number = 0;
4267 relax_start (ep->X_add_symbol);
4268 macro_build (ep, "lui", "t,u", reg, BFD_RELOC_MIPS_GOT_HI16);
4269 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
4270 reg, reg, mips_gp_register);
4271 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)",
4272 reg, BFD_RELOC_MIPS_GOT_LO16, reg);
4273 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
4274 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
4275 else if (ex.X_add_number)
4277 ex.X_op = O_constant;
4278 macro_build (&ex, ADDRESS_ADDI_INSN, "t,r,j", reg, reg,
4282 ep->X_add_number = ex.X_add_number;
4284 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
4285 BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register);
4286 macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", reg, reg,
4287 BFD_RELOC_MIPS_GOT_OFST);
4292 ex.X_add_number = ep->X_add_number;
4293 ep->X_add_number = 0;
4294 relax_start (ep->X_add_symbol);
4295 macro_build (ep, "lui", "t,u", reg, BFD_RELOC_MIPS_GOT_HI16);
4296 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
4297 reg, reg, mips_gp_register);
4298 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)",
4299 reg, BFD_RELOC_MIPS_GOT_LO16, reg);
4301 if (reg_needs_delay (mips_gp_register))
4303 /* We need a nop before loading from $gp. This special
4304 check is required because the lui which starts the main
4305 instruction stream does not refer to $gp, and so will not
4306 insert the nop which may be required. */
4307 macro_build (NULL, "nop", "");
4309 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
4310 BFD_RELOC_MIPS_GOT16, mips_gp_register);
4312 macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", reg, reg,
4316 if (ex.X_add_number != 0)
4318 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
4319 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
4320 ex.X_op = O_constant;
4321 macro_build (&ex, ADDRESS_ADDI_INSN, "t,r,j", reg, reg,
4329 if (mips_opts.noat && *used_at == 1)
4330 as_bad (_("Macro used $at after \".set noat\""));
4333 /* Move the contents of register SOURCE into register DEST. */
4336 move_register (int dest, int source)
4338 macro_build (NULL, HAVE_32BIT_GPRS ? "addu" : "daddu", "d,v,t",
4342 /* Emit an SVR4 PIC sequence to load address LOCAL into DEST, where
4343 LOCAL is the sum of a symbol and a 16-bit or 32-bit displacement.
4344 The two alternatives are:
4346 Global symbol Local sybmol
4347 ------------- ------------
4348 lw DEST,%got(SYMBOL) lw DEST,%got(SYMBOL + OFFSET)
4350 addiu DEST,DEST,OFFSET addiu DEST,DEST,%lo(SYMBOL + OFFSET)
4352 load_got_offset emits the first instruction and add_got_offset
4353 emits the second for a 16-bit offset or add_got_offset_hilo emits
4354 a sequence to add a 32-bit offset using a scratch register. */
4357 load_got_offset (int dest, expressionS *local)
4362 global.X_add_number = 0;
4364 relax_start (local->X_add_symbol);
4365 macro_build (&global, ADDRESS_LOAD_INSN, "t,o(b)", dest,
4366 BFD_RELOC_MIPS_GOT16, mips_gp_register);
4368 macro_build (local, ADDRESS_LOAD_INSN, "t,o(b)", dest,
4369 BFD_RELOC_MIPS_GOT16, mips_gp_register);
4374 add_got_offset (int dest, expressionS *local)
4378 global.X_op = O_constant;
4379 global.X_op_symbol = NULL;
4380 global.X_add_symbol = NULL;
4381 global.X_add_number = local->X_add_number;
4383 relax_start (local->X_add_symbol);
4384 macro_build (&global, ADDRESS_ADDI_INSN, "t,r,j",
4385 dest, dest, BFD_RELOC_LO16);
4387 macro_build (local, ADDRESS_ADDI_INSN, "t,r,j", dest, dest, BFD_RELOC_LO16);
4392 add_got_offset_hilo (int dest, expressionS *local, int tmp)
4395 int hold_mips_optimize;
4397 global.X_op = O_constant;
4398 global.X_op_symbol = NULL;
4399 global.X_add_symbol = NULL;
4400 global.X_add_number = local->X_add_number;
4402 relax_start (local->X_add_symbol);
4403 load_register (tmp, &global, HAVE_64BIT_ADDRESSES);
4405 /* Set mips_optimize around the lui instruction to avoid
4406 inserting an unnecessary nop after the lw. */
4407 hold_mips_optimize = mips_optimize;
4409 macro_build_lui (&global, tmp);
4410 mips_optimize = hold_mips_optimize;
4411 macro_build (local, ADDRESS_ADDI_INSN, "t,r,j", tmp, tmp, BFD_RELOC_LO16);
4414 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", dest, dest, tmp);
4419 * This routine implements the seemingly endless macro or synthesized
4420 * instructions and addressing modes in the mips assembly language. Many
4421 * of these macros are simple and are similar to each other. These could
4422 * probably be handled by some kind of table or grammar approach instead of
4423 * this verbose method. Others are not simple macros but are more like
4424 * optimizing code generation.
4425 * One interesting optimization is when several store macros appear
4426 * consecutively that would load AT with the upper half of the same address.
4427 * The ensuing load upper instructions are ommited. This implies some kind
4428 * of global optimization. We currently only optimize within a single macro.
4429 * For many of the load and store macros if the address is specified as a
4430 * constant expression in the first 64k of memory (ie ld $2,0x4000c) we
4431 * first load register 'at' with zero and use it as the base register. The
4432 * mips assembler simply uses register $zero. Just one tiny optimization
4436 macro (struct mips_cl_insn *ip)
4438 register int treg, sreg, dreg, breg;
4454 bfd_reloc_code_real_type r;
4455 int hold_mips_optimize;
4457 assert (! mips_opts.mips16);
4459 treg = (ip->insn_opcode >> 16) & 0x1f;
4460 dreg = (ip->insn_opcode >> 11) & 0x1f;
4461 sreg = breg = (ip->insn_opcode >> 21) & 0x1f;
4462 mask = ip->insn_mo->mask;
4464 expr1.X_op = O_constant;
4465 expr1.X_op_symbol = NULL;
4466 expr1.X_add_symbol = NULL;
4467 expr1.X_add_number = 1;
4481 expr1.X_add_number = 8;
4482 macro_build (&expr1, "bgez", "s,p", sreg);
4484 macro_build (NULL, "nop", "", 0);
4486 move_register (dreg, sreg);
4487 macro_build (NULL, dbl ? "dsub" : "sub", "d,v,t", dreg, 0, sreg);
4510 if (imm_expr.X_op == O_constant
4511 && imm_expr.X_add_number >= -0x8000
4512 && imm_expr.X_add_number < 0x8000)
4514 macro_build (&imm_expr, s, "t,r,j", treg, sreg, BFD_RELOC_LO16);
4518 load_register (AT, &imm_expr, dbl);
4519 macro_build (NULL, s2, "d,v,t", treg, sreg, AT);
4538 if (imm_expr.X_op == O_constant
4539 && imm_expr.X_add_number >= 0
4540 && imm_expr.X_add_number < 0x10000)
4542 if (mask != M_NOR_I)
4543 macro_build (&imm_expr, s, "t,r,i", treg, sreg, BFD_RELOC_LO16);
4546 macro_build (&imm_expr, "ori", "t,r,i",
4547 treg, sreg, BFD_RELOC_LO16);
4548 macro_build (NULL, "nor", "d,v,t", treg, treg, 0);
4554 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
4555 macro_build (NULL, s2, "d,v,t", treg, sreg, AT);
4572 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4574 macro_build (&offset_expr, s, "s,t,p", sreg, 0);
4578 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
4579 macro_build (&offset_expr, s, "s,t,p", sreg, AT);
4587 macro_build (&offset_expr, likely ? "bgezl" : "bgez", "s,p", sreg);
4592 macro_build (&offset_expr, likely ? "blezl" : "blez", "s,p", treg);
4596 macro_build (NULL, "slt", "d,v,t", AT, sreg, treg);
4597 macro_build (&offset_expr, likely ? "beql" : "beq", "s,t,p", AT, 0);
4603 /* check for > max integer */
4604 maxnum = 0x7fffffff;
4605 if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4)
4612 if (imm_expr.X_op == O_constant
4613 && imm_expr.X_add_number >= maxnum
4614 && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4))
4617 /* result is always false */
4619 macro_build (NULL, "nop", "", 0);
4621 macro_build (&offset_expr, "bnel", "s,t,p", 0, 0);
4624 if (imm_expr.X_op != O_constant)
4625 as_bad (_("Unsupported large constant"));
4626 ++imm_expr.X_add_number;
4630 if (mask == M_BGEL_I)
4632 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4634 macro_build (&offset_expr, likely ? "bgezl" : "bgez", "s,p", sreg);
4637 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4639 macro_build (&offset_expr, likely ? "bgtzl" : "bgtz", "s,p", sreg);
4642 maxnum = 0x7fffffff;
4643 if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4)
4650 maxnum = - maxnum - 1;
4651 if (imm_expr.X_op == O_constant
4652 && imm_expr.X_add_number <= maxnum
4653 && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4))
4656 /* result is always true */
4657 as_warn (_("Branch %s is always true"), ip->insn_mo->name);
4658 macro_build (&offset_expr, "b", "p");
4663 macro_build (&offset_expr, likely ? "beql" : "beq", "s,t,p", AT, 0);
4673 macro_build (&offset_expr, likely ? "beql" : "beq",
4678 macro_build (NULL, "sltu", "d,v,t", AT, sreg, treg);
4679 macro_build (&offset_expr, likely ? "beql" : "beq", "s,t,p", AT, 0);
4687 && imm_expr.X_op == O_constant
4688 && imm_expr.X_add_number == (offsetT) 0xffffffff))
4690 if (imm_expr.X_op != O_constant)
4691 as_bad (_("Unsupported large constant"));
4692 ++imm_expr.X_add_number;
4696 if (mask == M_BGEUL_I)
4698 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4700 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4702 macro_build (&offset_expr, likely ? "bnel" : "bne",
4708 macro_build (&offset_expr, likely ? "beql" : "beq", "s,t,p", AT, 0);
4716 macro_build (&offset_expr, likely ? "bgtzl" : "bgtz", "s,p", sreg);
4721 macro_build (&offset_expr, likely ? "bltzl" : "bltz", "s,p", treg);
4725 macro_build (NULL, "slt", "d,v,t", AT, treg, sreg);
4726 macro_build (&offset_expr, likely ? "bnel" : "bne", "s,t,p", AT, 0);
4734 macro_build (&offset_expr, likely ? "bnel" : "bne",
4741 macro_build (NULL, "sltu", "d,v,t", AT, treg, sreg);
4742 macro_build (&offset_expr, likely ? "bnel" : "bne", "s,t,p", AT, 0);
4750 macro_build (&offset_expr, likely ? "blezl" : "blez", "s,p", sreg);
4755 macro_build (&offset_expr, likely ? "bgezl" : "bgez", "s,p", treg);
4759 macro_build (NULL, "slt", "d,v,t", AT, treg, sreg);
4760 macro_build (&offset_expr, likely ? "beql" : "beq", "s,t,p", AT, 0);
4766 maxnum = 0x7fffffff;
4767 if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4)
4774 if (imm_expr.X_op == O_constant
4775 && imm_expr.X_add_number >= maxnum
4776 && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4))
4778 if (imm_expr.X_op != O_constant)
4779 as_bad (_("Unsupported large constant"));
4780 ++imm_expr.X_add_number;
4784 if (mask == M_BLTL_I)
4786 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4788 macro_build (&offset_expr, likely ? "bltzl" : "bltz", "s,p", sreg);
4791 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4793 macro_build (&offset_expr, likely ? "blezl" : "blez", "s,p", sreg);
4798 macro_build (&offset_expr, likely ? "bnel" : "bne", "s,t,p", AT, 0);
4806 macro_build (&offset_expr, likely ? "beql" : "beq",
4813 macro_build (NULL, "sltu", "d,v,t", AT, treg, sreg);
4814 macro_build (&offset_expr, likely ? "beql" : "beq", "s,t,p", AT, 0);
4822 && imm_expr.X_op == O_constant
4823 && imm_expr.X_add_number == (offsetT) 0xffffffff))
4825 if (imm_expr.X_op != O_constant)
4826 as_bad (_("Unsupported large constant"));
4827 ++imm_expr.X_add_number;
4831 if (mask == M_BLTUL_I)
4833 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4835 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4837 macro_build (&offset_expr, likely ? "beql" : "beq",
4843 macro_build (&offset_expr, likely ? "bnel" : "bne", "s,t,p", AT, 0);
4851 macro_build (&offset_expr, likely ? "bltzl" : "bltz", "s,p", sreg);
4856 macro_build (&offset_expr, likely ? "bgtzl" : "bgtz", "s,p", treg);
4860 macro_build (NULL, "slt", "d,v,t", AT, sreg, treg);
4861 macro_build (&offset_expr, likely ? "bnel" : "bne", "s,t,p", AT, 0);
4871 macro_build (&offset_expr, likely ? "bnel" : "bne",
4876 macro_build (NULL, "sltu", "d,v,t", AT, sreg, treg);
4877 macro_build (&offset_expr, likely ? "bnel" : "bne", "s,t,p", AT, 0);
4885 if (imm_expr.X_op != O_constant || imm2_expr.X_op != O_constant)
4887 as_bad (_("Unsupported large constant"));
4892 pos = (unsigned long) imm_expr.X_add_number;
4893 size = (unsigned long) imm2_expr.X_add_number;
4898 as_bad (_("Improper position (%lu)"), pos);
4901 if (size == 0 || size > 64
4902 || (pos + size - 1) > 63)
4904 as_bad (_("Improper extract size (%lu, position %lu)"),
4909 if (size <= 32 && pos < 32)
4914 else if (size <= 32)
4924 macro_build ((expressionS *) NULL, s, fmt, treg, sreg, pos, size - 1);
4933 if (imm_expr.X_op != O_constant || imm2_expr.X_op != O_constant)
4935 as_bad (_("Unsupported large constant"));
4940 pos = (unsigned long) imm_expr.X_add_number;
4941 size = (unsigned long) imm2_expr.X_add_number;
4946 as_bad (_("Improper position (%lu)"), pos);
4949 if (size == 0 || size > 64
4950 || (pos + size - 1) > 63)
4952 as_bad (_("Improper insert size (%lu, position %lu)"),
4957 if (pos < 32 && (pos + size - 1) < 32)
4972 macro_build ((expressionS *) NULL, s, fmt, treg, sreg, pos,
4989 as_warn (_("Divide by zero."));
4991 macro_build (NULL, "teq", "s,t,q", 0, 0, 7);
4993 macro_build (NULL, "break", "c", 7);
5000 macro_build (NULL, "teq", "s,t,q", treg, 0, 7);
5001 macro_build (NULL, dbl ? "ddiv" : "div", "z,s,t", sreg, treg);
5005 expr1.X_add_number = 8;
5006 macro_build (&expr1, "bne", "s,t,p", treg, 0);
5007 macro_build (NULL, dbl ? "ddiv" : "div", "z,s,t", sreg, treg);
5008 macro_build (NULL, "break", "c", 7);
5010 expr1.X_add_number = -1;
5012 load_register (AT, &expr1, dbl);
5013 expr1.X_add_number = mips_trap ? (dbl ? 12 : 8) : (dbl ? 20 : 16);
5014 macro_build (&expr1, "bne", "s,t,p", treg, AT);
5017 expr1.X_add_number = 1;
5018 load_register (AT, &expr1, dbl);
5019 macro_build (NULL, "dsll32", "d,w,<", AT, AT, 31);
5023 expr1.X_add_number = 0x80000000;
5024 macro_build (&expr1, "lui", "t,u", AT, BFD_RELOC_HI16);
5028 macro_build (NULL, "teq", "s,t,q", sreg, AT, 6);
5029 /* We want to close the noreorder block as soon as possible, so
5030 that later insns are available for delay slot filling. */
5035 expr1.X_add_number = 8;
5036 macro_build (&expr1, "bne", "s,t,p", sreg, AT);
5037 macro_build (NULL, "nop", "", 0);
5039 /* We want to close the noreorder block as soon as possible, so
5040 that later insns are available for delay slot filling. */
5043 macro_build (NULL, "break", "c", 6);
5045 macro_build (NULL, s, "d", dreg);
5084 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
5086 as_warn (_("Divide by zero."));
5088 macro_build (NULL, "teq", "s,t,q", 0, 0, 7);
5090 macro_build (NULL, "break", "c", 7);
5093 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
5095 if (strcmp (s2, "mflo") == 0)
5096 move_register (dreg, sreg);
5098 move_register (dreg, 0);
5101 if (imm_expr.X_op == O_constant
5102 && imm_expr.X_add_number == -1
5103 && s[strlen (s) - 1] != 'u')
5105 if (strcmp (s2, "mflo") == 0)
5107 macro_build (NULL, dbl ? "dneg" : "neg", "d,w", dreg, sreg);
5110 move_register (dreg, 0);
5115 load_register (AT, &imm_expr, dbl);
5116 macro_build (NULL, s, "z,s,t", sreg, AT);
5117 macro_build (NULL, s2, "d", dreg);
5139 macro_build (NULL, "teq", "s,t,q", treg, 0, 7);
5140 macro_build (NULL, s, "z,s,t", sreg, treg);
5141 /* We want to close the noreorder block as soon as possible, so
5142 that later insns are available for delay slot filling. */
5147 expr1.X_add_number = 8;
5148 macro_build (&expr1, "bne", "s,t,p", treg, 0);
5149 macro_build (NULL, s, "z,s,t", sreg, treg);
5151 /* We want to close the noreorder block as soon as possible, so
5152 that later insns are available for delay slot filling. */
5154 macro_build (NULL, "break", "c", 7);
5156 macro_build (NULL, s2, "d", dreg);
5168 /* Load the address of a symbol into a register. If breg is not
5169 zero, we then add a base register to it. */
5171 if (dbl && HAVE_32BIT_GPRS)
5172 as_warn (_("dla used to load 32-bit register"));
5174 if (! dbl && HAVE_64BIT_OBJECTS)
5175 as_warn (_("la used to load 64-bit address"));
5177 if (offset_expr.X_op == O_constant
5178 && offset_expr.X_add_number >= -0x8000
5179 && offset_expr.X_add_number < 0x8000)
5181 macro_build (&offset_expr, ADDRESS_ADDI_INSN,
5182 "t,r,j", treg, sreg, BFD_RELOC_LO16);
5186 if (!mips_opts.noat && (treg == breg))
5196 if (offset_expr.X_op != O_symbol
5197 && offset_expr.X_op != O_constant)
5199 as_bad (_("expression too complex"));
5200 offset_expr.X_op = O_constant;
5203 if (offset_expr.X_op == O_constant)
5204 load_register (tempreg, &offset_expr, HAVE_64BIT_ADDRESSES);
5205 else if (mips_pic == NO_PIC)
5207 /* If this is a reference to a GP relative symbol, we want
5208 addiu $tempreg,$gp,<sym> (BFD_RELOC_GPREL16)
5210 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
5211 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
5212 If we have a constant, we need two instructions anyhow,
5213 so we may as well always use the latter form.
5215 With 64bit address space and a usable $at we want
5216 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5217 lui $at,<sym> (BFD_RELOC_HI16_S)
5218 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
5219 daddiu $at,<sym> (BFD_RELOC_LO16)
5221 daddu $tempreg,$tempreg,$at
5223 If $at is already in use, we use a path which is suboptimal
5224 on superscalar processors.
5225 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5226 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
5228 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
5230 daddiu $tempreg,<sym> (BFD_RELOC_LO16)
5232 For GP relative symbols in 64bit address space we can use
5233 the same sequence as in 32bit address space. */
5234 if (HAVE_64BIT_SYMBOLS)
5236 if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
5237 && !nopic_need_relax (offset_expr.X_add_symbol, 1))
5239 relax_start (offset_expr.X_add_symbol);
5240 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
5241 tempreg, mips_gp_register, BFD_RELOC_GPREL16);
5245 if (used_at == 0 && !mips_opts.noat)
5247 macro_build (&offset_expr, "lui", "t,u",
5248 tempreg, BFD_RELOC_MIPS_HIGHEST);
5249 macro_build (&offset_expr, "lui", "t,u",
5250 AT, BFD_RELOC_HI16_S);
5251 macro_build (&offset_expr, "daddiu", "t,r,j",
5252 tempreg, tempreg, BFD_RELOC_MIPS_HIGHER);
5253 macro_build (&offset_expr, "daddiu", "t,r,j",
5254 AT, AT, BFD_RELOC_LO16);
5255 macro_build (NULL, "dsll32", "d,w,<", tempreg, tempreg, 0);
5256 macro_build (NULL, "daddu", "d,v,t", tempreg, tempreg, AT);
5261 macro_build (&offset_expr, "lui", "t,u",
5262 tempreg, BFD_RELOC_MIPS_HIGHEST);
5263 macro_build (&offset_expr, "daddiu", "t,r,j",
5264 tempreg, tempreg, BFD_RELOC_MIPS_HIGHER);
5265 macro_build (NULL, "dsll", "d,w,<", tempreg, tempreg, 16);
5266 macro_build (&offset_expr, "daddiu", "t,r,j",
5267 tempreg, tempreg, BFD_RELOC_HI16_S);
5268 macro_build (NULL, "dsll", "d,w,<", tempreg, tempreg, 16);
5269 macro_build (&offset_expr, "daddiu", "t,r,j",
5270 tempreg, tempreg, BFD_RELOC_LO16);
5273 if (mips_relax.sequence)
5278 if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
5279 && !nopic_need_relax (offset_expr.X_add_symbol, 1))
5281 relax_start (offset_expr.X_add_symbol);
5282 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
5283 tempreg, mips_gp_register, BFD_RELOC_GPREL16);
5286 if (!IS_SEXT_32BIT_NUM (offset_expr.X_add_number))
5287 as_bad (_("offset too large"));
5288 macro_build_lui (&offset_expr, tempreg);
5289 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
5290 tempreg, tempreg, BFD_RELOC_LO16);
5291 if (mips_relax.sequence)
5295 else if (!mips_big_got && !HAVE_NEWABI)
5297 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT16;
5299 /* If this is a reference to an external symbol, and there
5300 is no constant, we want
5301 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5302 or for lca or if tempreg is PIC_CALL_REG
5303 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
5304 For a local symbol, we want
5305 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5307 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
5309 If we have a small constant, and this is a reference to
5310 an external symbol, we want
5311 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5313 addiu $tempreg,$tempreg,<constant>
5314 For a local symbol, we want the same instruction
5315 sequence, but we output a BFD_RELOC_LO16 reloc on the
5318 If we have a large constant, and this is a reference to
5319 an external symbol, we want
5320 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5321 lui $at,<hiconstant>
5322 addiu $at,$at,<loconstant>
5323 addu $tempreg,$tempreg,$at
5324 For a local symbol, we want the same instruction
5325 sequence, but we output a BFD_RELOC_LO16 reloc on the
5329 if (offset_expr.X_add_number == 0)
5331 if (mips_pic == SVR4_PIC
5333 && (call || tempreg == PIC_CALL_REG))
5334 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL16;
5336 relax_start (offset_expr.X_add_symbol);
5337 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
5338 lw_reloc_type, mips_gp_register);
5341 /* We're going to put in an addu instruction using
5342 tempreg, so we may as well insert the nop right
5347 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
5348 tempreg, BFD_RELOC_MIPS_GOT16, mips_gp_register);
5350 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
5351 tempreg, tempreg, BFD_RELOC_LO16);
5353 /* FIXME: If breg == 0, and the next instruction uses
5354 $tempreg, then if this variant case is used an extra
5355 nop will be generated. */
5357 else if (offset_expr.X_add_number >= -0x8000
5358 && offset_expr.X_add_number < 0x8000)
5360 load_got_offset (tempreg, &offset_expr);
5362 add_got_offset (tempreg, &offset_expr);
5366 expr1.X_add_number = offset_expr.X_add_number;
5367 offset_expr.X_add_number =
5368 ((offset_expr.X_add_number + 0x8000) & 0xffff) - 0x8000;
5369 load_got_offset (tempreg, &offset_expr);
5370 offset_expr.X_add_number = expr1.X_add_number;
5371 /* If we are going to add in a base register, and the
5372 target register and the base register are the same,
5373 then we are using AT as a temporary register. Since
5374 we want to load the constant into AT, we add our
5375 current AT (from the global offset table) and the
5376 register into the register now, and pretend we were
5377 not using a base register. */
5381 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
5386 add_got_offset_hilo (tempreg, &offset_expr, AT);
5390 else if (!mips_big_got && HAVE_NEWABI)
5392 int add_breg_early = 0;
5394 /* If this is a reference to an external, and there is no
5395 constant, or local symbol (*), with or without a
5397 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
5398 or for lca or if tempreg is PIC_CALL_REG
5399 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
5401 If we have a small constant, and this is a reference to
5402 an external symbol, we want
5403 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
5404 addiu $tempreg,$tempreg,<constant>
5406 If we have a large constant, and this is a reference to
5407 an external symbol, we want
5408 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
5409 lui $at,<hiconstant>
5410 addiu $at,$at,<loconstant>
5411 addu $tempreg,$tempreg,$at
5413 (*) Other assemblers seem to prefer GOT_PAGE/GOT_OFST for
5414 local symbols, even though it introduces an additional
5417 if (offset_expr.X_add_number)
5419 expr1.X_add_number = offset_expr.X_add_number;
5420 offset_expr.X_add_number = 0;
5422 relax_start (offset_expr.X_add_symbol);
5423 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
5424 BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
5426 if (expr1.X_add_number >= -0x8000
5427 && expr1.X_add_number < 0x8000)
5429 macro_build (&expr1, ADDRESS_ADDI_INSN, "t,r,j",
5430 tempreg, tempreg, BFD_RELOC_LO16);
5432 else if (IS_SEXT_32BIT_NUM (expr1.X_add_number + 0x8000))
5436 /* If we are going to add in a base register, and the
5437 target register and the base register are the same,
5438 then we are using AT as a temporary register. Since
5439 we want to load the constant into AT, we add our
5440 current AT (from the global offset table) and the
5441 register into the register now, and pretend we were
5442 not using a base register. */
5447 assert (tempreg == AT);
5448 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
5454 load_register (AT, &expr1, HAVE_64BIT_ADDRESSES);
5455 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
5461 as_bad (_("PIC code offset overflow (max 32 signed bits)"));
5464 offset_expr.X_add_number = expr1.X_add_number;
5466 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
5467 BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
5470 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
5471 treg, tempreg, breg);
5477 else if (breg == 0 && (call || tempreg == PIC_CALL_REG))
5479 relax_start (offset_expr.X_add_symbol);
5480 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
5481 BFD_RELOC_MIPS_CALL16, mips_gp_register);
5483 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
5484 BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
5489 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
5490 BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
5493 else if (mips_big_got && !HAVE_NEWABI)
5496 int lui_reloc_type = (int) BFD_RELOC_MIPS_GOT_HI16;
5497 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT_LO16;
5498 int local_reloc_type = (int) BFD_RELOC_MIPS_GOT16;
5500 /* This is the large GOT case. If this is a reference to an
5501 external symbol, and there is no constant, we want
5502 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5503 addu $tempreg,$tempreg,$gp
5504 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5505 or for lca or if tempreg is PIC_CALL_REG
5506 lui $tempreg,<sym> (BFD_RELOC_MIPS_CALL_HI16)
5507 addu $tempreg,$tempreg,$gp
5508 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_CALL_LO16)
5509 For a local symbol, we want
5510 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5512 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
5514 If we have a small constant, and this is a reference to
5515 an external symbol, we want
5516 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5517 addu $tempreg,$tempreg,$gp
5518 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5520 addiu $tempreg,$tempreg,<constant>
5521 For a local symbol, we want
5522 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5524 addiu $tempreg,$tempreg,<constant> (BFD_RELOC_LO16)
5526 If we have a large constant, and this is a reference to
5527 an external symbol, we want
5528 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5529 addu $tempreg,$tempreg,$gp
5530 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5531 lui $at,<hiconstant>
5532 addiu $at,$at,<loconstant>
5533 addu $tempreg,$tempreg,$at
5534 For a local symbol, we want
5535 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5536 lui $at,<hiconstant>
5537 addiu $at,$at,<loconstant> (BFD_RELOC_LO16)
5538 addu $tempreg,$tempreg,$at
5541 expr1.X_add_number = offset_expr.X_add_number;
5542 offset_expr.X_add_number = 0;
5543 relax_start (offset_expr.X_add_symbol);
5544 gpdelay = reg_needs_delay (mips_gp_register);
5545 if (expr1.X_add_number == 0 && breg == 0
5546 && (call || tempreg == PIC_CALL_REG))
5548 lui_reloc_type = (int) BFD_RELOC_MIPS_CALL_HI16;
5549 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL_LO16;
5551 macro_build (&offset_expr, "lui", "t,u", tempreg, lui_reloc_type);
5552 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
5553 tempreg, tempreg, mips_gp_register);
5554 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
5555 tempreg, lw_reloc_type, tempreg);
5556 if (expr1.X_add_number == 0)
5560 /* We're going to put in an addu instruction using
5561 tempreg, so we may as well insert the nop right
5566 else if (expr1.X_add_number >= -0x8000
5567 && expr1.X_add_number < 0x8000)
5570 macro_build (&expr1, ADDRESS_ADDI_INSN, "t,r,j",
5571 tempreg, tempreg, BFD_RELOC_LO16);
5577 /* If we are going to add in a base register, and the
5578 target register and the base register are the same,
5579 then we are using AT as a temporary register. Since
5580 we want to load the constant into AT, we add our
5581 current AT (from the global offset table) and the
5582 register into the register now, and pretend we were
5583 not using a base register. */
5588 assert (tempreg == AT);
5590 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
5595 load_register (AT, &expr1, HAVE_64BIT_ADDRESSES);
5596 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", dreg, dreg, AT);
5600 offset_expr.X_add_number =
5601 ((expr1.X_add_number + 0x8000) & 0xffff) - 0x8000;
5606 /* This is needed because this instruction uses $gp, but
5607 the first instruction on the main stream does not. */
5608 macro_build (NULL, "nop", "");
5611 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
5612 local_reloc_type, mips_gp_register);
5613 if (expr1.X_add_number >= -0x8000
5614 && expr1.X_add_number < 0x8000)
5617 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
5618 tempreg, tempreg, BFD_RELOC_LO16);
5619 /* FIXME: If add_number is 0, and there was no base
5620 register, the external symbol case ended with a load,
5621 so if the symbol turns out to not be external, and
5622 the next instruction uses tempreg, an unnecessary nop
5623 will be inserted. */
5629 /* We must add in the base register now, as in the
5630 external symbol case. */
5631 assert (tempreg == AT);
5633 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
5636 /* We set breg to 0 because we have arranged to add
5637 it in in both cases. */
5641 macro_build_lui (&expr1, AT);
5642 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
5643 AT, AT, BFD_RELOC_LO16);
5644 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
5645 tempreg, tempreg, AT);
5650 else if (mips_big_got && HAVE_NEWABI)
5652 int lui_reloc_type = (int) BFD_RELOC_MIPS_GOT_HI16;
5653 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT_LO16;
5654 int add_breg_early = 0;
5656 /* This is the large GOT case. If this is a reference to an
5657 external symbol, and there is no constant, we want
5658 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5659 add $tempreg,$tempreg,$gp
5660 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5661 or for lca or if tempreg is PIC_CALL_REG
5662 lui $tempreg,<sym> (BFD_RELOC_MIPS_CALL_HI16)
5663 add $tempreg,$tempreg,$gp
5664 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_CALL_LO16)
5666 If we have a small constant, and this is a reference to
5667 an external symbol, we want
5668 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5669 add $tempreg,$tempreg,$gp
5670 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5671 addi $tempreg,$tempreg,<constant>
5673 If we have a large constant, and this is a reference to
5674 an external symbol, we want
5675 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5676 addu $tempreg,$tempreg,$gp
5677 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5678 lui $at,<hiconstant>
5679 addi $at,$at,<loconstant>
5680 add $tempreg,$tempreg,$at
5682 If we have NewABI, and we know it's a local symbol, we want
5683 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
5684 addiu $reg,$reg,<sym> (BFD_RELOC_MIPS_GOT_OFST)
5685 otherwise we have to resort to GOT_HI16/GOT_LO16. */
5687 relax_start (offset_expr.X_add_symbol);
5689 expr1.X_add_number = offset_expr.X_add_number;
5690 offset_expr.X_add_number = 0;
5692 if (expr1.X_add_number == 0 && breg == 0
5693 && (call || tempreg == PIC_CALL_REG))
5695 lui_reloc_type = (int) BFD_RELOC_MIPS_CALL_HI16;
5696 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL_LO16;
5698 macro_build (&offset_expr, "lui", "t,u", tempreg, lui_reloc_type);
5699 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
5700 tempreg, tempreg, mips_gp_register);
5701 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
5702 tempreg, lw_reloc_type, tempreg);
5704 if (expr1.X_add_number == 0)
5706 else if (expr1.X_add_number >= -0x8000
5707 && expr1.X_add_number < 0x8000)
5709 macro_build (&expr1, ADDRESS_ADDI_INSN, "t,r,j",
5710 tempreg, tempreg, BFD_RELOC_LO16);
5712 else if (IS_SEXT_32BIT_NUM (expr1.X_add_number + 0x8000))
5716 /* If we are going to add in a base register, and the
5717 target register and the base register are the same,
5718 then we are using AT as a temporary register. Since
5719 we want to load the constant into AT, we add our
5720 current AT (from the global offset table) and the
5721 register into the register now, and pretend we were
5722 not using a base register. */
5727 assert (tempreg == AT);
5728 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
5734 load_register (AT, &expr1, HAVE_64BIT_ADDRESSES);
5735 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", dreg, dreg, AT);
5740 as_bad (_("PIC code offset overflow (max 32 signed bits)"));
5743 offset_expr.X_add_number = expr1.X_add_number;
5744 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
5745 BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register);
5746 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j", tempreg,
5747 tempreg, BFD_RELOC_MIPS_GOT_OFST);
5750 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
5751 treg, tempreg, breg);
5761 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", treg, tempreg, breg);
5765 /* The j instruction may not be used in PIC code, since it
5766 requires an absolute address. We convert it to a b
5768 if (mips_pic == NO_PIC)
5769 macro_build (&offset_expr, "j", "a");
5771 macro_build (&offset_expr, "b", "p");
5774 /* The jal instructions must be handled as macros because when
5775 generating PIC code they expand to multi-instruction
5776 sequences. Normally they are simple instructions. */
5781 if (mips_pic == NO_PIC)
5782 macro_build (NULL, "jalr", "d,s", dreg, sreg);
5785 if (sreg != PIC_CALL_REG)
5786 as_warn (_("MIPS PIC call to register other than $25"));
5788 macro_build (NULL, "jalr", "d,s", dreg, sreg);
5789 if (mips_pic == SVR4_PIC && !HAVE_NEWABI)
5791 if (mips_cprestore_offset < 0)
5792 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5795 if (! mips_frame_reg_valid)
5797 as_warn (_("No .frame pseudo-op used in PIC code"));
5798 /* Quiet this warning. */
5799 mips_frame_reg_valid = 1;
5801 if (! mips_cprestore_valid)
5803 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5804 /* Quiet this warning. */
5805 mips_cprestore_valid = 1;
5807 expr1.X_add_number = mips_cprestore_offset;
5808 macro_build_ldst_constoffset (&expr1, ADDRESS_LOAD_INSN,
5811 HAVE_64BIT_ADDRESSES);
5819 if (mips_pic == NO_PIC)
5820 macro_build (&offset_expr, "jal", "a");
5821 else if (mips_pic == SVR4_PIC)
5823 /* If this is a reference to an external symbol, and we are
5824 using a small GOT, we want
5825 lw $25,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
5829 lw $gp,cprestore($sp)
5830 The cprestore value is set using the .cprestore
5831 pseudo-op. If we are using a big GOT, we want
5832 lui $25,<sym> (BFD_RELOC_MIPS_CALL_HI16)
5834 lw $25,<sym>($25) (BFD_RELOC_MIPS_CALL_LO16)
5838 lw $gp,cprestore($sp)
5839 If the symbol is not external, we want
5840 lw $25,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5842 addiu $25,$25,<sym> (BFD_RELOC_LO16)
5845 lw $gp,cprestore($sp)
5847 For NewABI, we use the same CALL16 or CALL_HI16/CALL_LO16
5848 sequences above, minus nops, unless the symbol is local,
5849 which enables us to use GOT_PAGE/GOT_OFST (big got) or
5855 relax_start (offset_expr.X_add_symbol);
5856 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
5857 PIC_CALL_REG, BFD_RELOC_MIPS_CALL16,
5860 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
5861 PIC_CALL_REG, BFD_RELOC_MIPS_GOT_DISP,
5867 relax_start (offset_expr.X_add_symbol);
5868 macro_build (&offset_expr, "lui", "t,u", PIC_CALL_REG,
5869 BFD_RELOC_MIPS_CALL_HI16);
5870 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", PIC_CALL_REG,
5871 PIC_CALL_REG, mips_gp_register);
5872 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
5873 PIC_CALL_REG, BFD_RELOC_MIPS_CALL_LO16,
5876 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
5877 PIC_CALL_REG, BFD_RELOC_MIPS_GOT_PAGE,
5879 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
5880 PIC_CALL_REG, PIC_CALL_REG,
5881 BFD_RELOC_MIPS_GOT_OFST);
5885 macro_build_jalr (&offset_expr);
5889 relax_start (offset_expr.X_add_symbol);
5892 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
5893 PIC_CALL_REG, BFD_RELOC_MIPS_CALL16,
5902 gpdelay = reg_needs_delay (mips_gp_register);
5903 macro_build (&offset_expr, "lui", "t,u", PIC_CALL_REG,
5904 BFD_RELOC_MIPS_CALL_HI16);
5905 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", PIC_CALL_REG,
5906 PIC_CALL_REG, mips_gp_register);
5907 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
5908 PIC_CALL_REG, BFD_RELOC_MIPS_CALL_LO16,
5913 macro_build (NULL, "nop", "");
5915 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
5916 PIC_CALL_REG, BFD_RELOC_MIPS_GOT16,
5919 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
5920 PIC_CALL_REG, PIC_CALL_REG, BFD_RELOC_LO16);
5922 macro_build_jalr (&offset_expr);
5924 if (mips_cprestore_offset < 0)
5925 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5928 if (! mips_frame_reg_valid)
5930 as_warn (_("No .frame pseudo-op used in PIC code"));
5931 /* Quiet this warning. */
5932 mips_frame_reg_valid = 1;
5934 if (! mips_cprestore_valid)
5936 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5937 /* Quiet this warning. */
5938 mips_cprestore_valid = 1;
5940 if (mips_opts.noreorder)
5941 macro_build (NULL, "nop", "");
5942 expr1.X_add_number = mips_cprestore_offset;
5943 macro_build_ldst_constoffset (&expr1, ADDRESS_LOAD_INSN,
5946 HAVE_64BIT_ADDRESSES);
5950 else if (mips_pic == VXWORKS_PIC)
5951 as_bad (_("Non-PIC jump used in PIC library"));
5974 /* Itbl support may require additional care here. */
5979 /* Itbl support may require additional care here. */
5984 /* Itbl support may require additional care here. */
5989 /* Itbl support may require additional care here. */
6001 if (mips_opts.arch == CPU_R4650)
6003 as_bad (_("opcode not supported on this processor"));
6007 /* Itbl support may require additional care here. */
6012 /* Itbl support may require additional care here. */
6017 /* Itbl support may require additional care here. */
6037 if (breg == treg || coproc || lr)
6058 /* Itbl support may require additional care here. */
6063 /* Itbl support may require additional care here. */
6068 /* Itbl support may require additional care here. */
6073 /* Itbl support may require additional care here. */
6092 if (mips_opts.arch == CPU_R4650)
6094 as_bad (_("opcode not supported on this processor"));
6099 /* Itbl support may require additional care here. */
6103 /* Itbl support may require additional care here. */
6108 /* Itbl support may require additional care here. */
6120 /* Itbl support may require additional care here. */
6121 if (mask == M_LWC1_AB
6122 || mask == M_SWC1_AB
6123 || mask == M_LDC1_AB
6124 || mask == M_SDC1_AB
6128 else if (mask == M_CACHE_AB)
6135 if (offset_expr.X_op != O_constant
6136 && offset_expr.X_op != O_symbol)
6138 as_bad (_("expression too complex"));
6139 offset_expr.X_op = O_constant;
6142 if (HAVE_32BIT_ADDRESSES
6143 && !IS_SEXT_32BIT_NUM (offset_expr.X_add_number))
6147 sprintf_vma (value, offset_expr.X_add_number);
6148 as_bad (_("Number (0x%s) larger than 32 bits"), value);
6151 /* A constant expression in PIC code can be handled just as it
6152 is in non PIC code. */
6153 if (offset_expr.X_op == O_constant)
6155 expr1.X_add_number = ((offset_expr.X_add_number + 0x8000)
6156 & ~(bfd_vma) 0xffff);
6157 normalize_address_expr (&expr1);
6158 load_register (tempreg, &expr1, HAVE_64BIT_ADDRESSES);
6160 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
6161 tempreg, tempreg, breg);
6162 macro_build (&offset_expr, s, fmt, treg, BFD_RELOC_LO16, tempreg);
6164 else if (mips_pic == NO_PIC)
6166 /* If this is a reference to a GP relative symbol, and there
6167 is no base register, we want
6168 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
6169 Otherwise, if there is no base register, we want
6170 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
6171 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
6172 If we have a constant, we need two instructions anyhow,
6173 so we always use the latter form.
6175 If we have a base register, and this is a reference to a
6176 GP relative symbol, we want
6177 addu $tempreg,$breg,$gp
6178 <op> $treg,<sym>($tempreg) (BFD_RELOC_GPREL16)
6180 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
6181 addu $tempreg,$tempreg,$breg
6182 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
6183 With a constant we always use the latter case.
6185 With 64bit address space and no base register and $at usable,
6187 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
6188 lui $at,<sym> (BFD_RELOC_HI16_S)
6189 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
6192 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
6193 If we have a base register, we want
6194 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
6195 lui $at,<sym> (BFD_RELOC_HI16_S)
6196 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
6200 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
6202 Without $at we can't generate the optimal path for superscalar
6203 processors here since this would require two temporary registers.
6204 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
6205 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
6207 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
6209 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
6210 If we have a base register, we want
6211 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
6212 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
6214 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
6216 daddu $tempreg,$tempreg,$breg
6217 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
6219 For GP relative symbols in 64bit address space we can use
6220 the same sequence as in 32bit address space. */
6221 if (HAVE_64BIT_SYMBOLS)
6223 if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
6224 && !nopic_need_relax (offset_expr.X_add_symbol, 1))
6226 relax_start (offset_expr.X_add_symbol);
6229 macro_build (&offset_expr, s, fmt, treg,
6230 BFD_RELOC_GPREL16, mips_gp_register);
6234 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
6235 tempreg, breg, mips_gp_register);
6236 macro_build (&offset_expr, s, fmt, treg,
6237 BFD_RELOC_GPREL16, tempreg);
6242 if (used_at == 0 && !mips_opts.noat)
6244 macro_build (&offset_expr, "lui", "t,u", tempreg,
6245 BFD_RELOC_MIPS_HIGHEST);
6246 macro_build (&offset_expr, "lui", "t,u", AT,
6248 macro_build (&offset_expr, "daddiu", "t,r,j", tempreg,
6249 tempreg, BFD_RELOC_MIPS_HIGHER);
6251 macro_build (NULL, "daddu", "d,v,t", AT, AT, breg);
6252 macro_build (NULL, "dsll32", "d,w,<", tempreg, tempreg, 0);
6253 macro_build (NULL, "daddu", "d,v,t", tempreg, tempreg, AT);
6254 macro_build (&offset_expr, s, fmt, treg, BFD_RELOC_LO16,
6260 macro_build (&offset_expr, "lui", "t,u", tempreg,
6261 BFD_RELOC_MIPS_HIGHEST);
6262 macro_build (&offset_expr, "daddiu", "t,r,j", tempreg,
6263 tempreg, BFD_RELOC_MIPS_HIGHER);
6264 macro_build (NULL, "dsll", "d,w,<", tempreg, tempreg, 16);
6265 macro_build (&offset_expr, "daddiu", "t,r,j", tempreg,
6266 tempreg, BFD_RELOC_HI16_S);
6267 macro_build (NULL, "dsll", "d,w,<", tempreg, tempreg, 16);
6269 macro_build (NULL, "daddu", "d,v,t",
6270 tempreg, tempreg, breg);
6271 macro_build (&offset_expr, s, fmt, treg,
6272 BFD_RELOC_LO16, tempreg);
6275 if (mips_relax.sequence)
6282 if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
6283 && !nopic_need_relax (offset_expr.X_add_symbol, 1))
6285 relax_start (offset_expr.X_add_symbol);
6286 macro_build (&offset_expr, s, fmt, treg, BFD_RELOC_GPREL16,
6290 macro_build_lui (&offset_expr, tempreg);
6291 macro_build (&offset_expr, s, fmt, treg,
6292 BFD_RELOC_LO16, tempreg);
6293 if (mips_relax.sequence)
6298 if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
6299 && !nopic_need_relax (offset_expr.X_add_symbol, 1))
6301 relax_start (offset_expr.X_add_symbol);
6302 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
6303 tempreg, breg, mips_gp_register);
6304 macro_build (&offset_expr, s, fmt, treg,
6305 BFD_RELOC_GPREL16, tempreg);
6308 macro_build_lui (&offset_expr, tempreg);
6309 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
6310 tempreg, tempreg, breg);
6311 macro_build (&offset_expr, s, fmt, treg,
6312 BFD_RELOC_LO16, tempreg);
6313 if (mips_relax.sequence)
6317 else if (!mips_big_got)
6319 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT16;
6321 /* If this is a reference to an external symbol, we want
6322 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6324 <op> $treg,0($tempreg)
6326 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6328 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
6329 <op> $treg,0($tempreg)
6332 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
6333 <op> $treg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_OFST)
6335 If there is a base register, we add it to $tempreg before
6336 the <op>. If there is a constant, we stick it in the
6337 <op> instruction. We don't handle constants larger than
6338 16 bits, because we have no way to load the upper 16 bits
6339 (actually, we could handle them for the subset of cases
6340 in which we are not using $at). */
6341 assert (offset_expr.X_op == O_symbol);
6344 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
6345 BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register);
6347 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
6348 tempreg, tempreg, breg);
6349 macro_build (&offset_expr, s, fmt, treg,
6350 BFD_RELOC_MIPS_GOT_OFST, tempreg);
6353 expr1.X_add_number = offset_expr.X_add_number;
6354 offset_expr.X_add_number = 0;
6355 if (expr1.X_add_number < -0x8000
6356 || expr1.X_add_number >= 0x8000)
6357 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6358 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
6359 lw_reloc_type, mips_gp_register);
6361 relax_start (offset_expr.X_add_symbol);
6363 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j", tempreg,
6364 tempreg, BFD_RELOC_LO16);
6367 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
6368 tempreg, tempreg, breg);
6369 macro_build (&expr1, s, fmt, treg, BFD_RELOC_LO16, tempreg);
6371 else if (mips_big_got && !HAVE_NEWABI)
6375 /* If this is a reference to an external symbol, we want
6376 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
6377 addu $tempreg,$tempreg,$gp
6378 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
6379 <op> $treg,0($tempreg)
6381 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6383 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
6384 <op> $treg,0($tempreg)
6385 If there is a base register, we add it to $tempreg before
6386 the <op>. If there is a constant, we stick it in the
6387 <op> instruction. We don't handle constants larger than
6388 16 bits, because we have no way to load the upper 16 bits
6389 (actually, we could handle them for the subset of cases
6390 in which we are not using $at). */
6391 assert (offset_expr.X_op == O_symbol);
6392 expr1.X_add_number = offset_expr.X_add_number;
6393 offset_expr.X_add_number = 0;
6394 if (expr1.X_add_number < -0x8000
6395 || expr1.X_add_number >= 0x8000)
6396 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6397 gpdelay = reg_needs_delay (mips_gp_register);
6398 relax_start (offset_expr.X_add_symbol);
6399 macro_build (&offset_expr, "lui", "t,u", tempreg,
6400 BFD_RELOC_MIPS_GOT_HI16);
6401 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", tempreg, tempreg,
6403 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
6404 BFD_RELOC_MIPS_GOT_LO16, tempreg);
6407 macro_build (NULL, "nop", "");
6408 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
6409 BFD_RELOC_MIPS_GOT16, mips_gp_register);
6411 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j", tempreg,
6412 tempreg, BFD_RELOC_LO16);
6416 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
6417 tempreg, tempreg, breg);
6418 macro_build (&expr1, s, fmt, treg, BFD_RELOC_LO16, tempreg);
6420 else if (mips_big_got && HAVE_NEWABI)
6422 /* If this is a reference to an external symbol, we want
6423 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
6424 add $tempreg,$tempreg,$gp
6425 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
6426 <op> $treg,<ofst>($tempreg)
6427 Otherwise, for local symbols, we want:
6428 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
6429 <op> $treg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_OFST) */
6430 assert (offset_expr.X_op == O_symbol);
6431 expr1.X_add_number = offset_expr.X_add_number;
6432 offset_expr.X_add_number = 0;
6433 if (expr1.X_add_number < -0x8000
6434 || expr1.X_add_number >= 0x8000)
6435 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6436 relax_start (offset_expr.X_add_symbol);
6437 macro_build (&offset_expr, "lui", "t,u", tempreg,
6438 BFD_RELOC_MIPS_GOT_HI16);
6439 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", tempreg, tempreg,
6441 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
6442 BFD_RELOC_MIPS_GOT_LO16, tempreg);
6444 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
6445 tempreg, tempreg, breg);
6446 macro_build (&expr1, s, fmt, treg, BFD_RELOC_LO16, tempreg);
6449 offset_expr.X_add_number = expr1.X_add_number;
6450 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
6451 BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register);
6453 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
6454 tempreg, tempreg, breg);
6455 macro_build (&offset_expr, s, fmt, treg,
6456 BFD_RELOC_MIPS_GOT_OFST, tempreg);
6466 load_register (treg, &imm_expr, 0);
6470 load_register (treg, &imm_expr, 1);
6474 if (imm_expr.X_op == O_constant)
6477 load_register (AT, &imm_expr, 0);
6478 macro_build (NULL, "mtc1", "t,G", AT, treg);
6483 assert (offset_expr.X_op == O_symbol
6484 && strcmp (segment_name (S_GET_SEGMENT
6485 (offset_expr.X_add_symbol)),
6487 && offset_expr.X_add_number == 0);
6488 macro_build (&offset_expr, "lwc1", "T,o(b)", treg,
6489 BFD_RELOC_MIPS_LITERAL, mips_gp_register);
6494 /* Check if we have a constant in IMM_EXPR. If the GPRs are 64 bits
6495 wide, IMM_EXPR is the entire value. Otherwise IMM_EXPR is the high
6496 order 32 bits of the value and the low order 32 bits are either
6497 zero or in OFFSET_EXPR. */
6498 if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big)
6500 if (HAVE_64BIT_GPRS)
6501 load_register (treg, &imm_expr, 1);
6506 if (target_big_endian)
6518 load_register (hreg, &imm_expr, 0);
6521 if (offset_expr.X_op == O_absent)
6522 move_register (lreg, 0);
6525 assert (offset_expr.X_op == O_constant);
6526 load_register (lreg, &offset_expr, 0);
6533 /* We know that sym is in the .rdata section. First we get the
6534 upper 16 bits of the address. */
6535 if (mips_pic == NO_PIC)
6537 macro_build_lui (&offset_expr, AT);
6542 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", AT,
6543 BFD_RELOC_MIPS_GOT16, mips_gp_register);
6547 /* Now we load the register(s). */
6548 if (HAVE_64BIT_GPRS)
6551 macro_build (&offset_expr, "ld", "t,o(b)", treg, BFD_RELOC_LO16, AT);
6556 macro_build (&offset_expr, "lw", "t,o(b)", treg, BFD_RELOC_LO16, AT);
6559 /* FIXME: How in the world do we deal with the possible
6561 offset_expr.X_add_number += 4;
6562 macro_build (&offset_expr, "lw", "t,o(b)",
6563 treg + 1, BFD_RELOC_LO16, AT);
6569 /* Check if we have a constant in IMM_EXPR. If the FPRs are 64 bits
6570 wide, IMM_EXPR is the entire value and the GPRs are known to be 64
6571 bits wide as well. Otherwise IMM_EXPR is the high order 32 bits of
6572 the value and the low order 32 bits are either zero or in
6574 if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big)
6577 load_register (AT, &imm_expr, HAVE_64BIT_FPRS);
6578 if (HAVE_64BIT_FPRS)
6580 assert (HAVE_64BIT_GPRS);
6581 macro_build (NULL, "dmtc1", "t,S", AT, treg);
6585 macro_build (NULL, "mtc1", "t,G", AT, treg + 1);
6586 if (offset_expr.X_op == O_absent)
6587 macro_build (NULL, "mtc1", "t,G", 0, treg);
6590 assert (offset_expr.X_op == O_constant);
6591 load_register (AT, &offset_expr, 0);
6592 macro_build (NULL, "mtc1", "t,G", AT, treg);
6598 assert (offset_expr.X_op == O_symbol
6599 && offset_expr.X_add_number == 0);
6600 s = segment_name (S_GET_SEGMENT (offset_expr.X_add_symbol));
6601 if (strcmp (s, ".lit8") == 0)
6603 if (mips_opts.isa != ISA_MIPS1)
6605 macro_build (&offset_expr, "ldc1", "T,o(b)", treg,
6606 BFD_RELOC_MIPS_LITERAL, mips_gp_register);
6609 breg = mips_gp_register;
6610 r = BFD_RELOC_MIPS_LITERAL;
6615 assert (strcmp (s, RDATA_SECTION_NAME) == 0);
6617 if (mips_pic != NO_PIC)
6618 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", AT,
6619 BFD_RELOC_MIPS_GOT16, mips_gp_register);
6622 /* FIXME: This won't work for a 64 bit address. */
6623 macro_build_lui (&offset_expr, AT);
6626 if (mips_opts.isa != ISA_MIPS1)
6628 macro_build (&offset_expr, "ldc1", "T,o(b)",
6629 treg, BFD_RELOC_LO16, AT);
6638 if (mips_opts.arch == CPU_R4650)
6640 as_bad (_("opcode not supported on this processor"));
6643 /* Even on a big endian machine $fn comes before $fn+1. We have
6644 to adjust when loading from memory. */
6647 assert (mips_opts.isa == ISA_MIPS1);
6648 macro_build (&offset_expr, "lwc1", "T,o(b)",
6649 target_big_endian ? treg + 1 : treg, r, breg);
6650 /* FIXME: A possible overflow which I don't know how to deal
6652 offset_expr.X_add_number += 4;
6653 macro_build (&offset_expr, "lwc1", "T,o(b)",
6654 target_big_endian ? treg : treg + 1, r, breg);
6659 * The MIPS assembler seems to check for X_add_number not
6660 * being double aligned and generating:
6663 * addiu at,at,%lo(foo+1)
6666 * But, the resulting address is the same after relocation so why
6667 * generate the extra instruction?
6669 if (mips_opts.arch == CPU_R4650)
6671 as_bad (_("opcode not supported on this processor"));
6674 /* Itbl support may require additional care here. */
6676 if (mips_opts.isa != ISA_MIPS1)
6687 if (mips_opts.arch == CPU_R4650)
6689 as_bad (_("opcode not supported on this processor"));
6693 if (mips_opts.isa != ISA_MIPS1)
6701 /* Itbl support may require additional care here. */
6706 if (HAVE_64BIT_GPRS)
6717 if (HAVE_64BIT_GPRS)
6727 if (offset_expr.X_op != O_symbol
6728 && offset_expr.X_op != O_constant)
6730 as_bad (_("expression too complex"));
6731 offset_expr.X_op = O_constant;
6734 if (HAVE_32BIT_ADDRESSES
6735 && !IS_SEXT_32BIT_NUM (offset_expr.X_add_number))
6739 sprintf_vma (value, offset_expr.X_add_number);
6740 as_bad (_("Number (0x%s) larger than 32 bits"), value);
6743 /* Even on a big endian machine $fn comes before $fn+1. We have
6744 to adjust when loading from memory. We set coproc if we must
6745 load $fn+1 first. */
6746 /* Itbl support may require additional care here. */
6747 if (! target_big_endian)
6750 if (mips_pic == NO_PIC
6751 || offset_expr.X_op == O_constant)
6753 /* If this is a reference to a GP relative symbol, we want
6754 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
6755 <op> $treg+1,<sym>+4($gp) (BFD_RELOC_GPREL16)
6756 If we have a base register, we use this
6758 <op> $treg,<sym>($at) (BFD_RELOC_GPREL16)
6759 <op> $treg+1,<sym>+4($at) (BFD_RELOC_GPREL16)
6760 If this is not a GP relative symbol, we want
6761 lui $at,<sym> (BFD_RELOC_HI16_S)
6762 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
6763 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
6764 If there is a base register, we add it to $at after the
6765 lui instruction. If there is a constant, we always use
6767 if (offset_expr.X_op == O_symbol
6768 && (valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
6769 && !nopic_need_relax (offset_expr.X_add_symbol, 1))
6771 relax_start (offset_expr.X_add_symbol);
6774 tempreg = mips_gp_register;
6778 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
6779 AT, breg, mips_gp_register);
6784 /* Itbl support may require additional care here. */
6785 macro_build (&offset_expr, s, fmt, coproc ? treg + 1 : treg,
6786 BFD_RELOC_GPREL16, tempreg);
6787 offset_expr.X_add_number += 4;
6789 /* Set mips_optimize to 2 to avoid inserting an
6791 hold_mips_optimize = mips_optimize;
6793 /* Itbl support may require additional care here. */
6794 macro_build (&offset_expr, s, fmt, coproc ? treg : treg + 1,
6795 BFD_RELOC_GPREL16, tempreg);
6796 mips_optimize = hold_mips_optimize;
6800 /* We just generated two relocs. When tc_gen_reloc
6801 handles this case, it will skip the first reloc and
6802 handle the second. The second reloc already has an
6803 extra addend of 4, which we added above. We must
6804 subtract it out, and then subtract another 4 to make
6805 the first reloc come out right. The second reloc
6806 will come out right because we are going to add 4 to
6807 offset_expr when we build its instruction below.
6809 If we have a symbol, then we don't want to include
6810 the offset, because it will wind up being included
6811 when we generate the reloc. */
6813 if (offset_expr.X_op == O_constant)
6814 offset_expr.X_add_number -= 8;
6817 offset_expr.X_add_number = -4;
6818 offset_expr.X_op = O_constant;
6822 macro_build_lui (&offset_expr, AT);
6824 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, breg, AT);
6825 /* Itbl support may require additional care here. */
6826 macro_build (&offset_expr, s, fmt, coproc ? treg + 1 : treg,
6827 BFD_RELOC_LO16, AT);
6828 /* FIXME: How do we handle overflow here? */
6829 offset_expr.X_add_number += 4;
6830 /* Itbl support may require additional care here. */
6831 macro_build (&offset_expr, s, fmt, coproc ? treg : treg + 1,
6832 BFD_RELOC_LO16, AT);
6833 if (mips_relax.sequence)
6836 else if (!mips_big_got)
6838 /* If this is a reference to an external symbol, we want
6839 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6844 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6846 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
6847 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
6848 If there is a base register we add it to $at before the
6849 lwc1 instructions. If there is a constant we include it
6850 in the lwc1 instructions. */
6852 expr1.X_add_number = offset_expr.X_add_number;
6853 if (expr1.X_add_number < -0x8000
6854 || expr1.X_add_number >= 0x8000 - 4)
6855 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6856 load_got_offset (AT, &offset_expr);
6859 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, breg, AT);
6861 /* Set mips_optimize to 2 to avoid inserting an undesired
6863 hold_mips_optimize = mips_optimize;
6866 /* Itbl support may require additional care here. */
6867 relax_start (offset_expr.X_add_symbol);
6868 macro_build (&expr1, s, fmt, coproc ? treg + 1 : treg,
6869 BFD_RELOC_LO16, AT);
6870 expr1.X_add_number += 4;
6871 macro_build (&expr1, s, fmt, coproc ? treg : treg + 1,
6872 BFD_RELOC_LO16, AT);
6874 macro_build (&offset_expr, s, fmt, coproc ? treg + 1 : treg,
6875 BFD_RELOC_LO16, AT);
6876 offset_expr.X_add_number += 4;
6877 macro_build (&offset_expr, s, fmt, coproc ? treg : treg + 1,
6878 BFD_RELOC_LO16, AT);
6881 mips_optimize = hold_mips_optimize;
6883 else if (mips_big_got)
6887 /* If this is a reference to an external symbol, we want
6888 lui $at,<sym> (BFD_RELOC_MIPS_GOT_HI16)
6890 lw $at,<sym>($at) (BFD_RELOC_MIPS_GOT_LO16)
6895 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6897 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
6898 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
6899 If there is a base register we add it to $at before the
6900 lwc1 instructions. If there is a constant we include it
6901 in the lwc1 instructions. */
6903 expr1.X_add_number = offset_expr.X_add_number;
6904 offset_expr.X_add_number = 0;
6905 if (expr1.X_add_number < -0x8000
6906 || expr1.X_add_number >= 0x8000 - 4)
6907 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6908 gpdelay = reg_needs_delay (mips_gp_register);
6909 relax_start (offset_expr.X_add_symbol);
6910 macro_build (&offset_expr, "lui", "t,u",
6911 AT, BFD_RELOC_MIPS_GOT_HI16);
6912 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
6913 AT, AT, mips_gp_register);
6914 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
6915 AT, BFD_RELOC_MIPS_GOT_LO16, AT);
6918 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, breg, AT);
6919 /* Itbl support may require additional care here. */
6920 macro_build (&expr1, s, fmt, coproc ? treg + 1 : treg,
6921 BFD_RELOC_LO16, AT);
6922 expr1.X_add_number += 4;
6924 /* Set mips_optimize to 2 to avoid inserting an undesired
6926 hold_mips_optimize = mips_optimize;
6928 /* Itbl support may require additional care here. */
6929 macro_build (&expr1, s, fmt, coproc ? treg : treg + 1,
6930 BFD_RELOC_LO16, AT);
6931 mips_optimize = hold_mips_optimize;
6932 expr1.X_add_number -= 4;
6935 offset_expr.X_add_number = expr1.X_add_number;
6937 macro_build (NULL, "nop", "");
6938 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", AT,
6939 BFD_RELOC_MIPS_GOT16, mips_gp_register);
6942 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, breg, AT);
6943 /* Itbl support may require additional care here. */
6944 macro_build (&offset_expr, s, fmt, coproc ? treg + 1 : treg,
6945 BFD_RELOC_LO16, AT);
6946 offset_expr.X_add_number += 4;
6948 /* Set mips_optimize to 2 to avoid inserting an undesired
6950 hold_mips_optimize = mips_optimize;
6952 /* Itbl support may require additional care here. */
6953 macro_build (&offset_expr, s, fmt, coproc ? treg : treg + 1,
6954 BFD_RELOC_LO16, AT);
6955 mips_optimize = hold_mips_optimize;
6969 assert (HAVE_32BIT_ADDRESSES);
6970 macro_build (&offset_expr, s, "t,o(b)", treg, BFD_RELOC_LO16, breg);
6971 offset_expr.X_add_number += 4;
6972 macro_build (&offset_expr, s, "t,o(b)", treg + 1, BFD_RELOC_LO16, breg);
6975 /* New code added to support COPZ instructions.
6976 This code builds table entries out of the macros in mip_opcodes.
6977 R4000 uses interlocks to handle coproc delays.
6978 Other chips (like the R3000) require nops to be inserted for delays.
6980 FIXME: Currently, we require that the user handle delays.
6981 In order to fill delay slots for non-interlocked chips,
6982 we must have a way to specify delays based on the coprocessor.
6983 Eg. 4 cycles if load coproc reg from memory, 1 if in cache, etc.
6984 What are the side-effects of the cop instruction?
6985 What cache support might we have and what are its effects?
6986 Both coprocessor & memory require delays. how long???
6987 What registers are read/set/modified?
6989 If an itbl is provided to interpret cop instructions,
6990 this knowledge can be encoded in the itbl spec. */
7004 /* For now we just do C (same as Cz). The parameter will be
7005 stored in insn_opcode by mips_ip. */
7006 macro_build (NULL, s, "C", ip->insn_opcode);
7010 move_register (dreg, sreg);
7013 #ifdef LOSING_COMPILER
7015 /* Try and see if this is a new itbl instruction.
7016 This code builds table entries out of the macros in mip_opcodes.
7017 FIXME: For now we just assemble the expression and pass it's
7018 value along as a 32-bit immediate.
7019 We may want to have the assembler assemble this value,
7020 so that we gain the assembler's knowledge of delay slots,
7022 Would it be more efficient to use mask (id) here? */
7023 if (itbl_have_entries
7024 && (immed_expr = itbl_assemble (ip->insn_mo->name, "")))
7026 s = ip->insn_mo->name;
7028 coproc = ITBL_DECODE_PNUM (immed_expr);;
7029 macro_build (&immed_expr, s, "C");
7035 if (mips_opts.noat && used_at)
7036 as_bad (_("Macro used $at after \".set noat\""));
7040 macro2 (struct mips_cl_insn *ip)
7042 register int treg, sreg, dreg, breg;
7057 bfd_reloc_code_real_type r;
7059 treg = (ip->insn_opcode >> 16) & 0x1f;
7060 dreg = (ip->insn_opcode >> 11) & 0x1f;
7061 sreg = breg = (ip->insn_opcode >> 21) & 0x1f;
7062 mask = ip->insn_mo->mask;
7064 expr1.X_op = O_constant;
7065 expr1.X_op_symbol = NULL;
7066 expr1.X_add_symbol = NULL;
7067 expr1.X_add_number = 1;
7071 #endif /* LOSING_COMPILER */
7076 macro_build (NULL, dbl ? "dmultu" : "multu", "s,t", sreg, treg);
7077 macro_build (NULL, "mflo", "d", dreg);
7083 /* The MIPS assembler some times generates shifts and adds. I'm
7084 not trying to be that fancy. GCC should do this for us
7087 load_register (AT, &imm_expr, dbl);
7088 macro_build (NULL, dbl ? "dmult" : "mult", "s,t", sreg, AT);
7089 macro_build (NULL, "mflo", "d", dreg);
7105 load_register (AT, &imm_expr, dbl);
7106 macro_build (NULL, dbl ? "dmult" : "mult", "s,t", sreg, imm ? AT : treg);
7107 macro_build (NULL, "mflo", "d", dreg);
7108 macro_build (NULL, dbl ? "dsra32" : "sra", "d,w,<", dreg, dreg, RA);
7109 macro_build (NULL, "mfhi", "d", AT);
7111 macro_build (NULL, "tne", "s,t,q", dreg, AT, 6);
7114 expr1.X_add_number = 8;
7115 macro_build (&expr1, "beq", "s,t,p", dreg, AT);
7116 macro_build (NULL, "nop", "", 0);
7117 macro_build (NULL, "break", "c", 6);
7120 macro_build (NULL, "mflo", "d", dreg);
7136 load_register (AT, &imm_expr, dbl);
7137 macro_build (NULL, dbl ? "dmultu" : "multu", "s,t",
7138 sreg, imm ? AT : treg);
7139 macro_build (NULL, "mfhi", "d", AT);
7140 macro_build (NULL, "mflo", "d", dreg);
7142 macro_build (NULL, "tne", "s,t,q", AT, 0, 6);
7145 expr1.X_add_number = 8;
7146 macro_build (&expr1, "beq", "s,t,p", AT, 0);
7147 macro_build (NULL, "nop", "", 0);
7148 macro_build (NULL, "break", "c", 6);
7154 if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_opts.arch))
7165 macro_build (NULL, "dnegu", "d,w", tempreg, treg);
7166 macro_build (NULL, "drorv", "d,t,s", dreg, sreg, tempreg);
7170 macro_build (NULL, "dsubu", "d,v,t", AT, 0, treg);
7171 macro_build (NULL, "dsrlv", "d,t,s", AT, sreg, AT);
7172 macro_build (NULL, "dsllv", "d,t,s", dreg, sreg, treg);
7173 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
7177 if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_opts.arch))
7188 macro_build (NULL, "negu", "d,w", tempreg, treg);
7189 macro_build (NULL, "rorv", "d,t,s", dreg, sreg, tempreg);
7193 macro_build (NULL, "subu", "d,v,t", AT, 0, treg);
7194 macro_build (NULL, "srlv", "d,t,s", AT, sreg, AT);
7195 macro_build (NULL, "sllv", "d,t,s", dreg, sreg, treg);
7196 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
7204 if (imm_expr.X_op != O_constant)
7205 as_bad (_("Improper rotate count"));
7206 rot = imm_expr.X_add_number & 0x3f;
7207 if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_opts.arch))
7209 rot = (64 - rot) & 0x3f;
7211 macro_build (NULL, "dror32", "d,w,<", dreg, sreg, rot - 32);
7213 macro_build (NULL, "dror", "d,w,<", dreg, sreg, rot);
7218 macro_build (NULL, "dsrl", "d,w,<", dreg, sreg, 0);
7221 l = (rot < 0x20) ? "dsll" : "dsll32";
7222 r = ((0x40 - rot) < 0x20) ? "dsrl" : "dsrl32";
7225 macro_build (NULL, l, "d,w,<", AT, sreg, rot);
7226 macro_build (NULL, r, "d,w,<", dreg, sreg, (0x20 - rot) & 0x1f);
7227 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
7235 if (imm_expr.X_op != O_constant)
7236 as_bad (_("Improper rotate count"));
7237 rot = imm_expr.X_add_number & 0x1f;
7238 if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_opts.arch))
7240 macro_build (NULL, "ror", "d,w,<", dreg, sreg, (32 - rot) & 0x1f);
7245 macro_build (NULL, "srl", "d,w,<", dreg, sreg, 0);
7249 macro_build (NULL, "sll", "d,w,<", AT, sreg, rot);
7250 macro_build (NULL, "srl", "d,w,<", dreg, sreg, (0x20 - rot) & 0x1f);
7251 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
7256 if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_opts.arch))
7258 macro_build (NULL, "drorv", "d,t,s", dreg, sreg, treg);
7262 macro_build (NULL, "dsubu", "d,v,t", AT, 0, treg);
7263 macro_build (NULL, "dsllv", "d,t,s", AT, sreg, AT);
7264 macro_build (NULL, "dsrlv", "d,t,s", dreg, sreg, treg);
7265 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
7269 if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_opts.arch))
7271 macro_build (NULL, "rorv", "d,t,s", dreg, sreg, treg);
7275 macro_build (NULL, "subu", "d,v,t", AT, 0, treg);
7276 macro_build (NULL, "sllv", "d,t,s", AT, sreg, AT);
7277 macro_build (NULL, "srlv", "d,t,s", dreg, sreg, treg);
7278 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
7286 if (imm_expr.X_op != O_constant)
7287 as_bad (_("Improper rotate count"));
7288 rot = imm_expr.X_add_number & 0x3f;
7289 if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_opts.arch))
7292 macro_build (NULL, "dror32", "d,w,<", dreg, sreg, rot - 32);
7294 macro_build (NULL, "dror", "d,w,<", dreg, sreg, rot);
7299 macro_build (NULL, "dsrl", "d,w,<", dreg, sreg, 0);
7302 r = (rot < 0x20) ? "dsrl" : "dsrl32";
7303 l = ((0x40 - rot) < 0x20) ? "dsll" : "dsll32";
7306 macro_build (NULL, r, "d,w,<", AT, sreg, rot);
7307 macro_build (NULL, l, "d,w,<", dreg, sreg, (0x20 - rot) & 0x1f);
7308 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
7316 if (imm_expr.X_op != O_constant)
7317 as_bad (_("Improper rotate count"));
7318 rot = imm_expr.X_add_number & 0x1f;
7319 if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_opts.arch))
7321 macro_build (NULL, "ror", "d,w,<", dreg, sreg, rot);
7326 macro_build (NULL, "srl", "d,w,<", dreg, sreg, 0);
7330 macro_build (NULL, "srl", "d,w,<", AT, sreg, rot);
7331 macro_build (NULL, "sll", "d,w,<", dreg, sreg, (0x20 - rot) & 0x1f);
7332 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
7337 if (mips_opts.arch == CPU_R4650)
7339 as_bad (_("opcode not supported on this processor"));
7342 assert (mips_opts.isa == ISA_MIPS1);
7343 /* Even on a big endian machine $fn comes before $fn+1. We have
7344 to adjust when storing to memory. */
7345 macro_build (&offset_expr, "swc1", "T,o(b)",
7346 target_big_endian ? treg + 1 : treg, BFD_RELOC_LO16, breg);
7347 offset_expr.X_add_number += 4;
7348 macro_build (&offset_expr, "swc1", "T,o(b)",
7349 target_big_endian ? treg : treg + 1, BFD_RELOC_LO16, breg);
7354 macro_build (&expr1, "sltiu", "t,r,j", dreg, treg, BFD_RELOC_LO16);
7356 macro_build (&expr1, "sltiu", "t,r,j", dreg, sreg, BFD_RELOC_LO16);
7359 macro_build (NULL, "xor", "d,v,t", dreg, sreg, treg);
7360 macro_build (&expr1, "sltiu", "t,r,j", dreg, dreg, BFD_RELOC_LO16);
7365 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
7367 macro_build (&expr1, "sltiu", "t,r,j", dreg, sreg, BFD_RELOC_LO16);
7372 as_warn (_("Instruction %s: result is always false"),
7374 move_register (dreg, 0);
7377 if (imm_expr.X_op == O_constant
7378 && imm_expr.X_add_number >= 0
7379 && imm_expr.X_add_number < 0x10000)
7381 macro_build (&imm_expr, "xori", "t,r,i", dreg, sreg, BFD_RELOC_LO16);
7383 else if (imm_expr.X_op == O_constant
7384 && imm_expr.X_add_number > -0x8000
7385 && imm_expr.X_add_number < 0)
7387 imm_expr.X_add_number = -imm_expr.X_add_number;
7388 macro_build (&imm_expr, HAVE_32BIT_GPRS ? "addiu" : "daddiu",
7389 "t,r,j", dreg, sreg, BFD_RELOC_LO16);
7393 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
7394 macro_build (NULL, "xor", "d,v,t", dreg, sreg, AT);
7397 macro_build (&expr1, "sltiu", "t,r,j", dreg, dreg, BFD_RELOC_LO16);
7400 case M_SGE: /* sreg >= treg <==> not (sreg < treg) */
7406 macro_build (NULL, s, "d,v,t", dreg, sreg, treg);
7407 macro_build (&expr1, "xori", "t,r,i", dreg, dreg, BFD_RELOC_LO16);
7410 case M_SGE_I: /* sreg >= I <==> not (sreg < I) */
7412 if (imm_expr.X_op == O_constant
7413 && imm_expr.X_add_number >= -0x8000
7414 && imm_expr.X_add_number < 0x8000)
7416 macro_build (&imm_expr, mask == M_SGE_I ? "slti" : "sltiu", "t,r,j",
7417 dreg, sreg, BFD_RELOC_LO16);
7421 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
7422 macro_build (NULL, mask == M_SGE_I ? "slt" : "sltu", "d,v,t",
7426 macro_build (&expr1, "xori", "t,r,i", dreg, dreg, BFD_RELOC_LO16);
7429 case M_SGT: /* sreg > treg <==> treg < sreg */
7435 macro_build (NULL, s, "d,v,t", dreg, treg, sreg);
7438 case M_SGT_I: /* sreg > I <==> I < sreg */
7445 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
7446 macro_build (NULL, s, "d,v,t", dreg, AT, sreg);
7449 case M_SLE: /* sreg <= treg <==> treg >= sreg <==> not (treg < sreg) */
7455 macro_build (NULL, s, "d,v,t", dreg, treg, sreg);
7456 macro_build (&expr1, "xori", "t,r,i", dreg, dreg, BFD_RELOC_LO16);
7459 case M_SLE_I: /* sreg <= I <==> I >= sreg <==> not (I < sreg) */
7466 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
7467 macro_build (NULL, s, "d,v,t", dreg, AT, sreg);
7468 macro_build (&expr1, "xori", "t,r,i", dreg, dreg, BFD_RELOC_LO16);
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, "slti", "t,r,j", dreg, sreg, BFD_RELOC_LO16);
7480 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
7481 macro_build (NULL, "slt", "d,v,t", dreg, sreg, AT);
7485 if (imm_expr.X_op == O_constant
7486 && imm_expr.X_add_number >= -0x8000
7487 && imm_expr.X_add_number < 0x8000)
7489 macro_build (&imm_expr, "sltiu", "t,r,j", dreg, sreg,
7494 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
7495 macro_build (NULL, "sltu", "d,v,t", dreg, sreg, AT);
7500 macro_build (NULL, "sltu", "d,v,t", dreg, 0, treg);
7502 macro_build (NULL, "sltu", "d,v,t", dreg, 0, sreg);
7505 macro_build (NULL, "xor", "d,v,t", dreg, sreg, treg);
7506 macro_build (NULL, "sltu", "d,v,t", dreg, 0, dreg);
7511 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
7513 macro_build (NULL, "sltu", "d,v,t", dreg, 0, sreg);
7518 as_warn (_("Instruction %s: result is always true"),
7520 macro_build (&expr1, HAVE_32BIT_GPRS ? "addiu" : "daddiu", "t,r,j",
7521 dreg, 0, BFD_RELOC_LO16);
7524 if (imm_expr.X_op == O_constant
7525 && imm_expr.X_add_number >= 0
7526 && imm_expr.X_add_number < 0x10000)
7528 macro_build (&imm_expr, "xori", "t,r,i", dreg, sreg, BFD_RELOC_LO16);
7530 else if (imm_expr.X_op == O_constant
7531 && imm_expr.X_add_number > -0x8000
7532 && imm_expr.X_add_number < 0)
7534 imm_expr.X_add_number = -imm_expr.X_add_number;
7535 macro_build (&imm_expr, HAVE_32BIT_GPRS ? "addiu" : "daddiu",
7536 "t,r,j", dreg, sreg, BFD_RELOC_LO16);
7540 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
7541 macro_build (NULL, "xor", "d,v,t", dreg, sreg, AT);
7544 macro_build (NULL, "sltu", "d,v,t", dreg, 0, dreg);
7550 if (imm_expr.X_op == O_constant
7551 && imm_expr.X_add_number > -0x8000
7552 && imm_expr.X_add_number <= 0x8000)
7554 imm_expr.X_add_number = -imm_expr.X_add_number;
7555 macro_build (&imm_expr, dbl ? "daddi" : "addi", "t,r,j",
7556 dreg, sreg, BFD_RELOC_LO16);
7560 load_register (AT, &imm_expr, dbl);
7561 macro_build (NULL, dbl ? "dsub" : "sub", "d,v,t", dreg, sreg, AT);
7567 if (imm_expr.X_op == O_constant
7568 && imm_expr.X_add_number > -0x8000
7569 && imm_expr.X_add_number <= 0x8000)
7571 imm_expr.X_add_number = -imm_expr.X_add_number;
7572 macro_build (&imm_expr, dbl ? "daddiu" : "addiu", "t,r,j",
7573 dreg, sreg, BFD_RELOC_LO16);
7577 load_register (AT, &imm_expr, dbl);
7578 macro_build (NULL, dbl ? "dsubu" : "subu", "d,v,t", dreg, sreg, AT);
7600 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
7601 macro_build (NULL, s, "s,t", sreg, AT);
7606 assert (mips_opts.isa == ISA_MIPS1);
7608 sreg = (ip->insn_opcode >> 11) & 0x1f; /* floating reg */
7609 dreg = (ip->insn_opcode >> 06) & 0x1f; /* floating reg */
7612 * Is the double cfc1 instruction a bug in the mips assembler;
7613 * or is there a reason for it?
7616 macro_build (NULL, "cfc1", "t,G", treg, RA);
7617 macro_build (NULL, "cfc1", "t,G", treg, RA);
7618 macro_build (NULL, "nop", "");
7619 expr1.X_add_number = 3;
7620 macro_build (&expr1, "ori", "t,r,i", AT, treg, BFD_RELOC_LO16);
7621 expr1.X_add_number = 2;
7622 macro_build (&expr1, "xori", "t,r,i", AT, AT, BFD_RELOC_LO16);
7623 macro_build (NULL, "ctc1", "t,G", AT, RA);
7624 macro_build (NULL, "nop", "");
7625 macro_build (NULL, mask == M_TRUNCWD ? "cvt.w.d" : "cvt.w.s", "D,S",
7627 macro_build (NULL, "ctc1", "t,G", treg, RA);
7628 macro_build (NULL, "nop", "");
7639 if (offset_expr.X_add_number >= 0x7fff)
7640 as_bad (_("operand overflow"));
7641 if (! target_big_endian)
7642 ++offset_expr.X_add_number;
7643 macro_build (&offset_expr, s, "t,o(b)", AT, BFD_RELOC_LO16, breg);
7644 if (! target_big_endian)
7645 --offset_expr.X_add_number;
7647 ++offset_expr.X_add_number;
7648 macro_build (&offset_expr, "lbu", "t,o(b)", treg, BFD_RELOC_LO16, breg);
7649 macro_build (NULL, "sll", "d,w,<", AT, AT, 8);
7650 macro_build (NULL, "or", "d,v,t", treg, treg, AT);
7663 if (offset_expr.X_add_number >= 0x8000 - off)
7664 as_bad (_("operand overflow"));
7672 if (! target_big_endian)
7673 offset_expr.X_add_number += off;
7674 macro_build (&offset_expr, s, "t,o(b)", tempreg, BFD_RELOC_LO16, breg);
7675 if (! target_big_endian)
7676 offset_expr.X_add_number -= off;
7678 offset_expr.X_add_number += off;
7679 macro_build (&offset_expr, s2, "t,o(b)", tempreg, BFD_RELOC_LO16, breg);
7681 /* If necessary, move the result in tempreg the final destination. */
7682 if (treg == tempreg)
7684 /* Protect second load's delay slot. */
7686 move_register (treg, tempreg);
7700 load_address (AT, &offset_expr, &used_at);
7702 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, AT, breg);
7703 if (! target_big_endian)
7704 expr1.X_add_number = off;
7706 expr1.X_add_number = 0;
7707 macro_build (&expr1, s, "t,o(b)", treg, BFD_RELOC_LO16, AT);
7708 if (! target_big_endian)
7709 expr1.X_add_number = 0;
7711 expr1.X_add_number = off;
7712 macro_build (&expr1, s2, "t,o(b)", treg, BFD_RELOC_LO16, AT);
7718 load_address (AT, &offset_expr, &used_at);
7720 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, AT, breg);
7721 if (target_big_endian)
7722 expr1.X_add_number = 0;
7723 macro_build (&expr1, mask == M_ULH_A ? "lb" : "lbu", "t,o(b)",
7724 treg, BFD_RELOC_LO16, AT);
7725 if (target_big_endian)
7726 expr1.X_add_number = 1;
7728 expr1.X_add_number = 0;
7729 macro_build (&expr1, "lbu", "t,o(b)", AT, BFD_RELOC_LO16, AT);
7730 macro_build (NULL, "sll", "d,w,<", treg, treg, 8);
7731 macro_build (NULL, "or", "d,v,t", treg, treg, AT);
7736 if (offset_expr.X_add_number >= 0x7fff)
7737 as_bad (_("operand overflow"));
7738 if (target_big_endian)
7739 ++offset_expr.X_add_number;
7740 macro_build (&offset_expr, "sb", "t,o(b)", treg, BFD_RELOC_LO16, breg);
7741 macro_build (NULL, "srl", "d,w,<", AT, treg, 8);
7742 if (target_big_endian)
7743 --offset_expr.X_add_number;
7745 ++offset_expr.X_add_number;
7746 macro_build (&offset_expr, "sb", "t,o(b)", AT, BFD_RELOC_LO16, breg);
7759 if (offset_expr.X_add_number >= 0x8000 - off)
7760 as_bad (_("operand overflow"));
7761 if (! target_big_endian)
7762 offset_expr.X_add_number += off;
7763 macro_build (&offset_expr, s, "t,o(b)", treg, BFD_RELOC_LO16, breg);
7764 if (! target_big_endian)
7765 offset_expr.X_add_number -= off;
7767 offset_expr.X_add_number += off;
7768 macro_build (&offset_expr, s2, "t,o(b)", treg, BFD_RELOC_LO16, breg);
7782 load_address (AT, &offset_expr, &used_at);
7784 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, AT, breg);
7785 if (! target_big_endian)
7786 expr1.X_add_number = off;
7788 expr1.X_add_number = 0;
7789 macro_build (&expr1, s, "t,o(b)", treg, BFD_RELOC_LO16, AT);
7790 if (! target_big_endian)
7791 expr1.X_add_number = 0;
7793 expr1.X_add_number = off;
7794 macro_build (&expr1, s2, "t,o(b)", treg, BFD_RELOC_LO16, AT);
7799 load_address (AT, &offset_expr, &used_at);
7801 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, AT, breg);
7802 if (! target_big_endian)
7803 expr1.X_add_number = 0;
7804 macro_build (&expr1, "sb", "t,o(b)", treg, BFD_RELOC_LO16, AT);
7805 macro_build (NULL, "srl", "d,w,<", treg, treg, 8);
7806 if (! target_big_endian)
7807 expr1.X_add_number = 1;
7809 expr1.X_add_number = 0;
7810 macro_build (&expr1, "sb", "t,o(b)", treg, BFD_RELOC_LO16, AT);
7811 if (! target_big_endian)
7812 expr1.X_add_number = 0;
7814 expr1.X_add_number = 1;
7815 macro_build (&expr1, "lbu", "t,o(b)", AT, BFD_RELOC_LO16, AT);
7816 macro_build (NULL, "sll", "d,w,<", treg, treg, 8);
7817 macro_build (NULL, "or", "d,v,t", treg, treg, AT);
7821 /* FIXME: Check if this is one of the itbl macros, since they
7822 are added dynamically. */
7823 as_bad (_("Macro %s not implemented yet"), ip->insn_mo->name);
7826 if (mips_opts.noat && used_at)
7827 as_bad (_("Macro used $at after \".set noat\""));
7830 /* Implement macros in mips16 mode. */
7833 mips16_macro (struct mips_cl_insn *ip)
7836 int xreg, yreg, zreg, tmp;
7839 const char *s, *s2, *s3;
7841 mask = ip->insn_mo->mask;
7843 xreg = MIPS16_EXTRACT_OPERAND (RX, *ip);
7844 yreg = MIPS16_EXTRACT_OPERAND (RY, *ip);
7845 zreg = MIPS16_EXTRACT_OPERAND (RZ, *ip);
7847 expr1.X_op = O_constant;
7848 expr1.X_op_symbol = NULL;
7849 expr1.X_add_symbol = NULL;
7850 expr1.X_add_number = 1;
7870 macro_build (NULL, dbl ? "ddiv" : "div", "0,x,y", xreg, yreg);
7871 expr1.X_add_number = 2;
7872 macro_build (&expr1, "bnez", "x,p", yreg);
7873 macro_build (NULL, "break", "6", 7);
7875 /* FIXME: The normal code checks for of -1 / -0x80000000 here,
7876 since that causes an overflow. We should do that as well,
7877 but I don't see how to do the comparisons without a temporary
7880 macro_build (NULL, s, "x", zreg);
7900 macro_build (NULL, s, "0,x,y", xreg, yreg);
7901 expr1.X_add_number = 2;
7902 macro_build (&expr1, "bnez", "x,p", yreg);
7903 macro_build (NULL, "break", "6", 7);
7905 macro_build (NULL, s2, "x", zreg);
7911 macro_build (NULL, dbl ? "dmultu" : "multu", "x,y", xreg, yreg);
7912 macro_build (NULL, "mflo", "x", zreg);
7920 if (imm_expr.X_op != O_constant)
7921 as_bad (_("Unsupported large constant"));
7922 imm_expr.X_add_number = -imm_expr.X_add_number;
7923 macro_build (&imm_expr, dbl ? "daddiu" : "addiu", "y,x,4", yreg, xreg);
7927 if (imm_expr.X_op != O_constant)
7928 as_bad (_("Unsupported large constant"));
7929 imm_expr.X_add_number = -imm_expr.X_add_number;
7930 macro_build (&imm_expr, "addiu", "x,k", xreg);
7934 if (imm_expr.X_op != O_constant)
7935 as_bad (_("Unsupported large constant"));
7936 imm_expr.X_add_number = -imm_expr.X_add_number;
7937 macro_build (&imm_expr, "daddiu", "y,j", yreg);
7959 goto do_reverse_branch;
7963 goto do_reverse_branch;
7975 goto do_reverse_branch;
7986 macro_build (NULL, s, "x,y", xreg, yreg);
7987 macro_build (&offset_expr, s2, "p");
8014 goto do_addone_branch_i;
8019 goto do_addone_branch_i;
8034 goto do_addone_branch_i;
8041 if (imm_expr.X_op != O_constant)
8042 as_bad (_("Unsupported large constant"));
8043 ++imm_expr.X_add_number;
8046 macro_build (&imm_expr, s, s3, xreg);
8047 macro_build (&offset_expr, s2, "p");
8051 expr1.X_add_number = 0;
8052 macro_build (&expr1, "slti", "x,8", yreg);
8054 move_register (xreg, yreg);
8055 expr1.X_add_number = 2;
8056 macro_build (&expr1, "bteqz", "p");
8057 macro_build (NULL, "neg", "x,w", xreg, xreg);
8061 /* For consistency checking, verify that all bits are specified either
8062 by the match/mask part of the instruction definition, or by the
8065 validate_mips_insn (const struct mips_opcode *opc)
8067 const char *p = opc->args;
8069 unsigned long used_bits = opc->mask;
8071 if ((used_bits & opc->match) != opc->match)
8073 as_bad (_("internal: bad mips opcode (mask error): %s %s"),
8074 opc->name, opc->args);
8077 #define USE_BITS(mask,shift) (used_bits |= ((mask) << (shift)))
8087 case '1': USE_BITS (OP_MASK_UDI1, OP_SH_UDI1); break;
8088 case '2': USE_BITS (OP_MASK_UDI2, OP_SH_UDI2); break;
8089 case '3': USE_BITS (OP_MASK_UDI3, OP_SH_UDI3); break;
8090 case '4': USE_BITS (OP_MASK_UDI4, OP_SH_UDI4); break;
8091 case 'A': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
8092 case 'B': USE_BITS (OP_MASK_INSMSB, OP_SH_INSMSB); break;
8093 case 'C': USE_BITS (OP_MASK_EXTMSBD, OP_SH_EXTMSBD); break;
8094 case 'D': USE_BITS (OP_MASK_RD, OP_SH_RD);
8095 USE_BITS (OP_MASK_SEL, OP_SH_SEL); break;
8096 case 'E': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
8097 case 'F': USE_BITS (OP_MASK_INSMSB, OP_SH_INSMSB); break;
8098 case 'G': USE_BITS (OP_MASK_EXTMSBD, OP_SH_EXTMSBD); break;
8099 case 'H': USE_BITS (OP_MASK_EXTMSBD, OP_SH_EXTMSBD); break;
8101 case 't': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
8102 case 'T': USE_BITS (OP_MASK_RT, OP_SH_RT);
8103 USE_BITS (OP_MASK_SEL, OP_SH_SEL); break;
8105 as_bad (_("internal: bad mips opcode (unknown extension operand type `+%c'): %s %s"),
8106 c, opc->name, opc->args);
8110 case '<': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
8111 case '>': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
8113 case 'B': USE_BITS (OP_MASK_CODE20, OP_SH_CODE20); break;
8114 case 'C': USE_BITS (OP_MASK_COPZ, OP_SH_COPZ); break;
8115 case 'D': USE_BITS (OP_MASK_FD, OP_SH_FD); break;
8116 case 'E': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
8118 case 'G': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
8119 case 'H': USE_BITS (OP_MASK_SEL, OP_SH_SEL); break;
8121 case 'J': USE_BITS (OP_MASK_CODE19, OP_SH_CODE19); break;
8122 case 'K': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
8124 case 'M': USE_BITS (OP_MASK_CCC, OP_SH_CCC); break;
8125 case 'N': USE_BITS (OP_MASK_BCC, OP_SH_BCC); break;
8126 case 'O': USE_BITS (OP_MASK_ALN, OP_SH_ALN); break;
8127 case 'Q': USE_BITS (OP_MASK_VSEL, OP_SH_VSEL);
8128 USE_BITS (OP_MASK_FT, OP_SH_FT); break;
8129 case 'R': USE_BITS (OP_MASK_FR, OP_SH_FR); break;
8130 case 'S': USE_BITS (OP_MASK_FS, OP_SH_FS); break;
8131 case 'T': USE_BITS (OP_MASK_FT, OP_SH_FT); break;
8132 case 'V': USE_BITS (OP_MASK_FS, OP_SH_FS); break;
8133 case 'W': USE_BITS (OP_MASK_FT, OP_SH_FT); break;
8134 case 'X': USE_BITS (OP_MASK_FD, OP_SH_FD); break;
8135 case 'Y': USE_BITS (OP_MASK_FS, OP_SH_FS); break;
8136 case 'Z': USE_BITS (OP_MASK_FT, OP_SH_FT); break;
8137 case 'a': USE_BITS (OP_MASK_TARGET, OP_SH_TARGET); break;
8138 case 'b': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
8139 case 'c': USE_BITS (OP_MASK_CODE, OP_SH_CODE); break;
8140 case 'd': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
8142 case 'h': USE_BITS (OP_MASK_PREFX, OP_SH_PREFX); break;
8143 case 'i': USE_BITS (OP_MASK_IMMEDIATE, OP_SH_IMMEDIATE); break;
8144 case 'j': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
8145 case 'k': USE_BITS (OP_MASK_CACHE, OP_SH_CACHE); break;
8147 case 'o': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
8148 case 'p': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
8149 case 'q': USE_BITS (OP_MASK_CODE2, OP_SH_CODE2); break;
8150 case 'r': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
8151 case 's': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
8152 case 't': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
8153 case 'u': USE_BITS (OP_MASK_IMMEDIATE, OP_SH_IMMEDIATE); break;
8154 case 'v': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
8155 case 'w': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
8158 case 'P': USE_BITS (OP_MASK_PERFREG, OP_SH_PERFREG); break;
8159 case 'U': USE_BITS (OP_MASK_RD, OP_SH_RD);
8160 USE_BITS (OP_MASK_RT, OP_SH_RT); break;
8161 case 'e': USE_BITS (OP_MASK_VECBYTE, OP_SH_VECBYTE); break;
8162 case '%': USE_BITS (OP_MASK_VECALIGN, OP_SH_VECALIGN); break;
8165 case '3': USE_BITS (OP_MASK_SA3, OP_SH_SA3); break;
8166 case '4': USE_BITS (OP_MASK_SA4, OP_SH_SA4); break;
8167 case '5': USE_BITS (OP_MASK_IMM8, OP_SH_IMM8); break;
8168 case '6': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
8169 case '7': USE_BITS (OP_MASK_DSPACC, OP_SH_DSPACC); break;
8170 case '8': USE_BITS (OP_MASK_WRDSP, OP_SH_WRDSP); break;
8171 case '9': USE_BITS (OP_MASK_DSPACC_S, OP_SH_DSPACC_S);break;
8172 case '0': USE_BITS (OP_MASK_DSPSFT, OP_SH_DSPSFT); break;
8173 case '\'': USE_BITS (OP_MASK_RDDSP, OP_SH_RDDSP); break;
8174 case ':': USE_BITS (OP_MASK_DSPSFT_7, OP_SH_DSPSFT_7);break;
8175 case '@': USE_BITS (OP_MASK_IMM10, OP_SH_IMM10); break;
8176 case '!': USE_BITS (OP_MASK_MT_U, OP_SH_MT_U); break;
8177 case '$': USE_BITS (OP_MASK_MT_H, OP_SH_MT_H); break;
8178 case '*': USE_BITS (OP_MASK_MTACC_T, OP_SH_MTACC_T); break;
8179 case '&': USE_BITS (OP_MASK_MTACC_D, OP_SH_MTACC_D); break;
8180 case 'g': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
8182 as_bad (_("internal: bad mips opcode (unknown operand type `%c'): %s %s"),
8183 c, opc->name, opc->args);
8187 if (used_bits != 0xffffffff)
8189 as_bad (_("internal: bad mips opcode (bits 0x%lx undefined): %s %s"),
8190 ~used_bits & 0xffffffff, opc->name, opc->args);
8196 /* UDI immediates. */
8204 static const struct mips_immed mips_immed[] = {
8205 { '1', OP_SH_UDI1, OP_MASK_UDI1, 0},
8206 { '2', OP_SH_UDI2, OP_MASK_UDI2, 0},
8207 { '3', OP_SH_UDI3, OP_MASK_UDI3, 0},
8208 { '4', OP_SH_UDI4, OP_MASK_UDI4, 0},
8212 /* This routine assembles an instruction into its binary format. As a
8213 side effect, it sets one of the global variables imm_reloc or
8214 offset_reloc to the type of relocation to do if one of the operands
8215 is an address expression. */
8218 mips_ip (char *str, struct mips_cl_insn *ip)
8223 struct mips_opcode *insn;
8226 unsigned int lastregno = 0;
8227 unsigned int lastpos = 0;
8228 unsigned int limlo, limhi;
8231 offsetT min_range, max_range;
8237 /* If the instruction contains a '.', we first try to match an instruction
8238 including the '.'. Then we try again without the '.'. */
8240 for (s = str; *s != '\0' && !ISSPACE (*s); ++s)
8243 /* If we stopped on whitespace, then replace the whitespace with null for
8244 the call to hash_find. Save the character we replaced just in case we
8245 have to re-parse the instruction. */
8252 insn = (struct mips_opcode *) hash_find (op_hash, str);
8254 /* If we didn't find the instruction in the opcode table, try again, but
8255 this time with just the instruction up to, but not including the
8259 /* Restore the character we overwrite above (if any). */
8263 /* Scan up to the first '.' or whitespace. */
8265 *s != '\0' && *s != '.' && !ISSPACE (*s);
8269 /* If we did not find a '.', then we can quit now. */
8272 insn_error = "unrecognized opcode";
8276 /* Lookup the instruction in the hash table. */
8278 if ((insn = (struct mips_opcode *) hash_find (op_hash, str)) == NULL)
8280 insn_error = "unrecognized opcode";
8290 assert (strcmp (insn->name, str) == 0);
8292 if (OPCODE_IS_MEMBER (insn,
8294 /* We don't check for mips_opts.mips16 here since
8295 we want to allow jalx if -mips16 was specified
8296 on the command line. */
8297 | (file_ase_mips16 ? INSN_MIPS16 : 0)
8298 | (mips_opts.ase_mdmx ? INSN_MDMX : 0)
8299 | (mips_opts.ase_dsp ? INSN_DSP : 0)
8300 | (mips_opts.ase_mt ? INSN_MT : 0)
8301 | (mips_opts.ase_mips3d ? INSN_MIPS3D : 0)
8302 | (mips_opts.ase_smartmips ? INSN_SMARTMIPS : 0)),
8308 if (insn->pinfo != INSN_MACRO)
8310 if (mips_opts.arch == CPU_R4650 && (insn->pinfo & FP_D) != 0)
8316 if (insn + 1 < &mips_opcodes[NUMOPCODES]
8317 && strcmp (insn->name, insn[1].name) == 0)
8326 static char buf[100];
8328 _("opcode not supported on this processor: %s (%s)"),
8329 mips_cpu_info_from_arch (mips_opts.arch)->name,
8330 mips_cpu_info_from_isa (mips_opts.isa)->name);
8339 create_insn (ip, insn);
8342 for (args = insn->args;; ++args)
8346 s += strspn (s, " \t");
8350 case '\0': /* end of args */
8355 case '3': /* dsp 3-bit unsigned immediate in bit 21 */
8356 my_getExpression (&imm_expr, s);
8357 check_absolute_expr (ip, &imm_expr);
8358 if (imm_expr.X_add_number & ~OP_MASK_SA3)
8360 as_warn (_("DSP immediate not in range 0..%d (%lu)"),
8361 OP_MASK_SA3, (unsigned long) imm_expr.X_add_number);
8362 imm_expr.X_add_number &= OP_MASK_SA3;
8364 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_SA3;
8365 imm_expr.X_op = O_absent;
8369 case '4': /* dsp 4-bit unsigned immediate in bit 21 */
8370 my_getExpression (&imm_expr, s);
8371 check_absolute_expr (ip, &imm_expr);
8372 if (imm_expr.X_add_number & ~OP_MASK_SA4)
8374 as_warn (_("DSP immediate not in range 0..%d (%lu)"),
8375 OP_MASK_SA4, (unsigned long) imm_expr.X_add_number);
8376 imm_expr.X_add_number &= OP_MASK_SA4;
8378 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_SA4;
8379 imm_expr.X_op = O_absent;
8383 case '5': /* dsp 8-bit unsigned immediate in bit 16 */
8384 my_getExpression (&imm_expr, s);
8385 check_absolute_expr (ip, &imm_expr);
8386 if (imm_expr.X_add_number & ~OP_MASK_IMM8)
8388 as_warn (_("DSP immediate not in range 0..%d (%lu)"),
8389 OP_MASK_IMM8, (unsigned long) imm_expr.X_add_number);
8390 imm_expr.X_add_number &= OP_MASK_IMM8;
8392 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_IMM8;
8393 imm_expr.X_op = O_absent;
8397 case '6': /* dsp 5-bit unsigned immediate in bit 21 */
8398 my_getExpression (&imm_expr, s);
8399 check_absolute_expr (ip, &imm_expr);
8400 if (imm_expr.X_add_number & ~OP_MASK_RS)
8402 as_warn (_("DSP immediate not in range 0..%d (%lu)"),
8403 OP_MASK_RS, (unsigned long) imm_expr.X_add_number);
8404 imm_expr.X_add_number &= OP_MASK_RS;
8406 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_RS;
8407 imm_expr.X_op = O_absent;
8411 case '7': /* four dsp accumulators in bits 11,12 */
8412 if (s[0] == '$' && s[1] == 'a' && s[2] == 'c' &&
8413 s[3] >= '0' && s[3] <= '3')
8417 ip->insn_opcode |= regno << OP_SH_DSPACC;
8421 as_bad (_("Invalid dsp acc register"));
8424 case '8': /* dsp 6-bit unsigned immediate in bit 11 */
8425 my_getExpression (&imm_expr, s);
8426 check_absolute_expr (ip, &imm_expr);
8427 if (imm_expr.X_add_number & ~OP_MASK_WRDSP)
8429 as_warn (_("DSP immediate not in range 0..%d (%lu)"),
8431 (unsigned long) imm_expr.X_add_number);
8432 imm_expr.X_add_number &= OP_MASK_WRDSP;
8434 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_WRDSP;
8435 imm_expr.X_op = O_absent;
8439 case '9': /* four dsp accumulators in bits 21,22 */
8440 if (s[0] == '$' && s[1] == 'a' && s[2] == 'c' &&
8441 s[3] >= '0' && s[3] <= '3')
8445 ip->insn_opcode |= regno << OP_SH_DSPACC_S;
8449 as_bad (_("Invalid dsp acc register"));
8452 case '0': /* dsp 6-bit signed immediate in bit 20 */
8453 my_getExpression (&imm_expr, s);
8454 check_absolute_expr (ip, &imm_expr);
8455 min_range = -((OP_MASK_DSPSFT + 1) >> 1);
8456 max_range = ((OP_MASK_DSPSFT + 1) >> 1) - 1;
8457 if (imm_expr.X_add_number < min_range ||
8458 imm_expr.X_add_number > max_range)
8460 as_warn (_("DSP immediate not in range %ld..%ld (%ld)"),
8461 (long) min_range, (long) max_range,
8462 (long) imm_expr.X_add_number);
8464 imm_expr.X_add_number &= OP_MASK_DSPSFT;
8465 ip->insn_opcode |= ((unsigned long) imm_expr.X_add_number
8467 imm_expr.X_op = O_absent;
8471 case '\'': /* dsp 6-bit unsigned immediate in bit 16 */
8472 my_getExpression (&imm_expr, s);
8473 check_absolute_expr (ip, &imm_expr);
8474 if (imm_expr.X_add_number & ~OP_MASK_RDDSP)
8476 as_warn (_("DSP immediate not in range 0..%d (%lu)"),
8478 (unsigned long) imm_expr.X_add_number);
8479 imm_expr.X_add_number &= OP_MASK_RDDSP;
8481 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_RDDSP;
8482 imm_expr.X_op = O_absent;
8486 case ':': /* dsp 7-bit signed immediate in bit 19 */
8487 my_getExpression (&imm_expr, s);
8488 check_absolute_expr (ip, &imm_expr);
8489 min_range = -((OP_MASK_DSPSFT_7 + 1) >> 1);
8490 max_range = ((OP_MASK_DSPSFT_7 + 1) >> 1) - 1;
8491 if (imm_expr.X_add_number < min_range ||
8492 imm_expr.X_add_number > max_range)
8494 as_warn (_("DSP immediate not in range %ld..%ld (%ld)"),
8495 (long) min_range, (long) max_range,
8496 (long) imm_expr.X_add_number);
8498 imm_expr.X_add_number &= OP_MASK_DSPSFT_7;
8499 ip->insn_opcode |= ((unsigned long) imm_expr.X_add_number
8501 imm_expr.X_op = O_absent;
8505 case '@': /* dsp 10-bit signed immediate in bit 16 */
8506 my_getExpression (&imm_expr, s);
8507 check_absolute_expr (ip, &imm_expr);
8508 min_range = -((OP_MASK_IMM10 + 1) >> 1);
8509 max_range = ((OP_MASK_IMM10 + 1) >> 1) - 1;
8510 if (imm_expr.X_add_number < min_range ||
8511 imm_expr.X_add_number > max_range)
8513 as_warn (_("DSP immediate not in range %ld..%ld (%ld)"),
8514 (long) min_range, (long) max_range,
8515 (long) imm_expr.X_add_number);
8517 imm_expr.X_add_number &= OP_MASK_IMM10;
8518 ip->insn_opcode |= ((unsigned long) imm_expr.X_add_number
8520 imm_expr.X_op = O_absent;
8524 case '!': /* mt 1-bit unsigned immediate in bit 5 */
8525 my_getExpression (&imm_expr, s);
8526 check_absolute_expr (ip, &imm_expr);
8527 if (imm_expr.X_add_number & ~OP_MASK_MT_U)
8529 as_warn (_("MT immediate not in range 0..%d (%lu)"),
8530 OP_MASK_MT_U, (unsigned long) imm_expr.X_add_number);
8531 imm_expr.X_add_number &= OP_MASK_MT_U;
8533 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_MT_U;
8534 imm_expr.X_op = O_absent;
8538 case '$': /* mt 1-bit unsigned immediate in bit 4 */
8539 my_getExpression (&imm_expr, s);
8540 check_absolute_expr (ip, &imm_expr);
8541 if (imm_expr.X_add_number & ~OP_MASK_MT_H)
8543 as_warn (_("MT immediate not in range 0..%d (%lu)"),
8544 OP_MASK_MT_H, (unsigned long) imm_expr.X_add_number);
8545 imm_expr.X_add_number &= OP_MASK_MT_H;
8547 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_MT_H;
8548 imm_expr.X_op = O_absent;
8552 case '*': /* four dsp accumulators in bits 18,19 */
8553 if (s[0] == '$' && s[1] == 'a' && s[2] == 'c' &&
8554 s[3] >= '0' && s[3] <= '3')
8558 ip->insn_opcode |= regno << OP_SH_MTACC_T;
8562 as_bad (_("Invalid dsp/smartmips acc register"));
8565 case '&': /* four dsp accumulators in bits 13,14 */
8566 if (s[0] == '$' && s[1] == 'a' && s[2] == 'c' &&
8567 s[3] >= '0' && s[3] <= '3')
8571 ip->insn_opcode |= regno << OP_SH_MTACC_D;
8575 as_bad (_("Invalid dsp/smartmips acc register"));
8586 INSERT_OPERAND (RS, *ip, lastregno);
8590 INSERT_OPERAND (RT, *ip, lastregno);
8594 INSERT_OPERAND (FT, *ip, lastregno);
8598 INSERT_OPERAND (FS, *ip, lastregno);
8604 /* Handle optional base register.
8605 Either the base register is omitted or
8606 we must have a left paren. */
8607 /* This is dependent on the next operand specifier
8608 is a base register specification. */
8609 assert (args[1] == 'b' || args[1] == '5'
8610 || args[1] == '-' || args[1] == '4');
8614 case ')': /* these must match exactly */
8621 case '+': /* Opcode extension character. */
8624 case '1': /* UDI immediates. */
8629 const struct mips_immed *imm = mips_immed;
8631 while (imm->type && imm->type != *args)
8635 my_getExpression (&imm_expr, s);
8636 check_absolute_expr (ip, &imm_expr);
8637 if ((unsigned long) imm_expr.X_add_number & ~imm->mask)
8639 as_warn (_("Illegal %s number (%lu, 0x%lx)"),
8640 imm->desc ? imm->desc : ip->insn_mo->name,
8641 (unsigned long) imm_expr.X_add_number,
8642 (unsigned long) imm_expr.X_add_number);
8643 imm_expr.X_add_number &= imm->mask;
8645 ip->insn_opcode |= ((unsigned long) imm_expr.X_add_number
8647 imm_expr.X_op = O_absent;
8652 case 'A': /* ins/ext position, becomes LSB. */
8661 my_getExpression (&imm_expr, s);
8662 check_absolute_expr (ip, &imm_expr);
8663 if ((unsigned long) imm_expr.X_add_number < limlo
8664 || (unsigned long) imm_expr.X_add_number > limhi)
8666 as_bad (_("Improper position (%lu)"),
8667 (unsigned long) imm_expr.X_add_number);
8668 imm_expr.X_add_number = limlo;
8670 lastpos = imm_expr.X_add_number;
8671 INSERT_OPERAND (SHAMT, *ip, imm_expr.X_add_number);
8672 imm_expr.X_op = O_absent;
8676 case 'B': /* ins size, becomes MSB. */
8685 my_getExpression (&imm_expr, s);
8686 check_absolute_expr (ip, &imm_expr);
8687 /* Check for negative input so that small negative numbers
8688 will not succeed incorrectly. The checks against
8689 (pos+size) transitively check "size" itself,
8690 assuming that "pos" is reasonable. */
8691 if ((long) imm_expr.X_add_number < 0
8692 || ((unsigned long) imm_expr.X_add_number
8694 || ((unsigned long) imm_expr.X_add_number
8697 as_bad (_("Improper insert size (%lu, position %lu)"),
8698 (unsigned long) imm_expr.X_add_number,
8699 (unsigned long) lastpos);
8700 imm_expr.X_add_number = limlo - lastpos;
8702 INSERT_OPERAND (INSMSB, *ip,
8703 lastpos + imm_expr.X_add_number - 1);
8704 imm_expr.X_op = O_absent;
8708 case 'C': /* ext size, becomes MSBD. */
8721 my_getExpression (&imm_expr, s);
8722 check_absolute_expr (ip, &imm_expr);
8723 /* Check for negative input so that small negative numbers
8724 will not succeed incorrectly. The checks against
8725 (pos+size) transitively check "size" itself,
8726 assuming that "pos" is reasonable. */
8727 if ((long) imm_expr.X_add_number < 0
8728 || ((unsigned long) imm_expr.X_add_number
8730 || ((unsigned long) imm_expr.X_add_number
8733 as_bad (_("Improper extract size (%lu, position %lu)"),
8734 (unsigned long) imm_expr.X_add_number,
8735 (unsigned long) lastpos);
8736 imm_expr.X_add_number = limlo - lastpos;
8738 INSERT_OPERAND (EXTMSBD, *ip, imm_expr.X_add_number - 1);
8739 imm_expr.X_op = O_absent;
8744 /* +D is for disassembly only; never match. */
8748 /* "+I" is like "I", except that imm2_expr is used. */
8749 my_getExpression (&imm2_expr, s);
8750 if (imm2_expr.X_op != O_big
8751 && imm2_expr.X_op != O_constant)
8752 insn_error = _("absolute expression required");
8753 if (HAVE_32BIT_GPRS)
8754 normalize_constant_expr (&imm2_expr);
8758 case 'T': /* Coprocessor register. */
8759 /* +T is for disassembly only; never match. */
8762 case 't': /* Coprocessor register number. */
8763 if (s[0] == '$' && ISDIGIT (s[1]))
8773 while (ISDIGIT (*s));
8775 as_bad (_("Invalid register number (%d)"), regno);
8778 ip->insn_opcode |= regno << OP_SH_RT;
8783 as_bad (_("Invalid coprocessor 0 register number"));
8787 as_bad (_("internal: bad mips opcode (unknown extension operand type `+%c'): %s %s"),
8788 *args, insn->name, insn->args);
8789 /* Further processing is fruitless. */
8794 case '<': /* must be at least one digit */
8796 * According to the manual, if the shift amount is greater
8797 * than 31 or less than 0, then the shift amount should be
8798 * mod 32. In reality the mips assembler issues an error.
8799 * We issue a warning and mask out all but the low 5 bits.
8801 my_getExpression (&imm_expr, s);
8802 check_absolute_expr (ip, &imm_expr);
8803 if ((unsigned long) imm_expr.X_add_number > 31)
8804 as_warn (_("Improper shift amount (%lu)"),
8805 (unsigned long) imm_expr.X_add_number);
8806 INSERT_OPERAND (SHAMT, *ip, imm_expr.X_add_number);
8807 imm_expr.X_op = O_absent;
8811 case '>': /* shift amount minus 32 */
8812 my_getExpression (&imm_expr, s);
8813 check_absolute_expr (ip, &imm_expr);
8814 if ((unsigned long) imm_expr.X_add_number < 32
8815 || (unsigned long) imm_expr.X_add_number > 63)
8817 INSERT_OPERAND (SHAMT, *ip, imm_expr.X_add_number - 32);
8818 imm_expr.X_op = O_absent;
8822 case 'k': /* cache code */
8823 case 'h': /* prefx code */
8824 my_getExpression (&imm_expr, s);
8825 check_absolute_expr (ip, &imm_expr);
8826 if ((unsigned long) imm_expr.X_add_number > 31)
8827 as_warn (_("Invalid value for `%s' (%lu)"),
8829 (unsigned long) imm_expr.X_add_number);
8831 INSERT_OPERAND (CACHE, *ip, imm_expr.X_add_number);
8833 INSERT_OPERAND (PREFX, *ip, imm_expr.X_add_number);
8834 imm_expr.X_op = O_absent;
8838 case 'c': /* break code */
8839 my_getExpression (&imm_expr, s);
8840 check_absolute_expr (ip, &imm_expr);
8841 if ((unsigned long) imm_expr.X_add_number > 1023)
8842 as_warn (_("Illegal break code (%lu)"),
8843 (unsigned long) imm_expr.X_add_number);
8844 INSERT_OPERAND (CODE, *ip, imm_expr.X_add_number);
8845 imm_expr.X_op = O_absent;
8849 case 'q': /* lower break code */
8850 my_getExpression (&imm_expr, s);
8851 check_absolute_expr (ip, &imm_expr);
8852 if ((unsigned long) imm_expr.X_add_number > 1023)
8853 as_warn (_("Illegal lower break code (%lu)"),
8854 (unsigned long) imm_expr.X_add_number);
8855 INSERT_OPERAND (CODE2, *ip, imm_expr.X_add_number);
8856 imm_expr.X_op = O_absent;
8860 case 'B': /* 20-bit syscall/break code. */
8861 my_getExpression (&imm_expr, s);
8862 check_absolute_expr (ip, &imm_expr);
8863 if ((unsigned long) imm_expr.X_add_number > OP_MASK_CODE20)
8864 as_warn (_("Illegal 20-bit code (%lu)"),
8865 (unsigned long) imm_expr.X_add_number);
8866 INSERT_OPERAND (CODE20, *ip, imm_expr.X_add_number);
8867 imm_expr.X_op = O_absent;
8871 case 'C': /* Coprocessor code */
8872 my_getExpression (&imm_expr, s);
8873 check_absolute_expr (ip, &imm_expr);
8874 if ((unsigned long) imm_expr.X_add_number >= (1 << 25))
8876 as_warn (_("Coproccesor code > 25 bits (%lu)"),
8877 (unsigned long) imm_expr.X_add_number);
8878 imm_expr.X_add_number &= ((1 << 25) - 1);
8880 ip->insn_opcode |= imm_expr.X_add_number;
8881 imm_expr.X_op = O_absent;
8885 case 'J': /* 19-bit wait code. */
8886 my_getExpression (&imm_expr, s);
8887 check_absolute_expr (ip, &imm_expr);
8888 if ((unsigned long) imm_expr.X_add_number > OP_MASK_CODE19)
8889 as_warn (_("Illegal 19-bit code (%lu)"),
8890 (unsigned long) imm_expr.X_add_number);
8891 INSERT_OPERAND (CODE19, *ip, imm_expr.X_add_number);
8892 imm_expr.X_op = O_absent;
8896 case 'P': /* Performance register. */
8897 my_getExpression (&imm_expr, s);
8898 check_absolute_expr (ip, &imm_expr);
8899 if (imm_expr.X_add_number != 0 && imm_expr.X_add_number != 1)
8900 as_warn (_("Invalid performance register (%lu)"),
8901 (unsigned long) imm_expr.X_add_number);
8902 INSERT_OPERAND (PERFREG, *ip, imm_expr.X_add_number);
8903 imm_expr.X_op = O_absent;
8907 case 'G': /* Coprocessor destination register. */
8908 if (((ip->insn_opcode >> OP_SH_OP) & OP_MASK_OP) == OP_OP_COP0)
8909 ok = reg_lookup (&s, RTYPE_NUM | RTYPE_CP0, ®no);
8911 ok = reg_lookup (&s, RTYPE_NUM | RTYPE_GP, ®no);
8912 ip->insn_opcode |= regno << OP_SH_RD;
8921 case 'b': /* base register */
8922 case 'd': /* destination register */
8923 case 's': /* source register */
8924 case 't': /* target register */
8925 case 'r': /* both target and source */
8926 case 'v': /* both dest and source */
8927 case 'w': /* both dest and target */
8928 case 'E': /* coprocessor target register */
8929 case 'K': /* 'rdhwr' destination register */
8930 case 'x': /* ignore register name */
8931 case 'z': /* must be zero register */
8932 case 'U': /* destination register (clo/clz). */
8933 case 'g': /* coprocessor destination register */
8935 if (*args == 'E' || *args == 'K')
8936 ok = reg_lookup (&s, RTYPE_NUM, ®no);
8939 ok = reg_lookup (&s, RTYPE_NUM | RTYPE_GP, ®no);
8940 if (regno == AT && ! mips_opts.noat)
8941 as_warn ("Used $at without \".set noat\"");
8950 if (c == 'r' || c == 'v' || c == 'w')
8957 /* 'z' only matches $0. */
8958 if (c == 'z' && regno != 0)
8961 /* Now that we have assembled one operand, we use the args string
8962 * to figure out where it goes in the instruction. */
8969 INSERT_OPERAND (RS, *ip, regno);
8975 INSERT_OPERAND (RD, *ip, regno);
8978 INSERT_OPERAND (RD, *ip, regno);
8979 INSERT_OPERAND (RT, *ip, regno);
8984 INSERT_OPERAND (RT, *ip, regno);
8987 /* This case exists because on the r3000 trunc
8988 expands into a macro which requires a gp
8989 register. On the r6000 or r4000 it is
8990 assembled into a single instruction which
8991 ignores the register. Thus the insn version
8992 is MIPS_ISA2 and uses 'x', and the macro
8993 version is MIPS_ISA1 and uses 't'. */
8996 /* This case is for the div instruction, which
8997 acts differently if the destination argument
8998 is $0. This only matches $0, and is checked
8999 outside the switch. */
9002 /* Itbl operand; not yet implemented. FIXME ?? */
9004 /* What about all other operands like 'i', which
9005 can be specified in the opcode table? */
9014 INSERT_OPERAND (RS, *ip, lastregno);
9017 INSERT_OPERAND (RT, *ip, lastregno);
9022 case 'O': /* MDMX alignment immediate constant. */
9023 my_getExpression (&imm_expr, s);
9024 check_absolute_expr (ip, &imm_expr);
9025 if ((unsigned long) imm_expr.X_add_number > OP_MASK_ALN)
9026 as_warn ("Improper align amount (%ld), using low bits",
9027 (long) imm_expr.X_add_number);
9028 INSERT_OPERAND (ALN, *ip, imm_expr.X_add_number);
9029 imm_expr.X_op = O_absent;
9033 case 'Q': /* MDMX vector, element sel, or const. */
9036 /* MDMX Immediate. */
9037 my_getExpression (&imm_expr, s);
9038 check_absolute_expr (ip, &imm_expr);
9039 if ((unsigned long) imm_expr.X_add_number > OP_MASK_FT)
9040 as_warn (_("Invalid MDMX Immediate (%ld)"),
9041 (long) imm_expr.X_add_number);
9042 INSERT_OPERAND (FT, *ip, imm_expr.X_add_number);
9043 if (ip->insn_opcode & (OP_MASK_VSEL << OP_SH_VSEL))
9044 ip->insn_opcode |= MDMX_FMTSEL_IMM_QH << OP_SH_VSEL;
9046 ip->insn_opcode |= MDMX_FMTSEL_IMM_OB << OP_SH_VSEL;
9047 imm_expr.X_op = O_absent;
9051 /* Not MDMX Immediate. Fall through. */
9052 case 'X': /* MDMX destination register. */
9053 case 'Y': /* MDMX source register. */
9054 case 'Z': /* MDMX target register. */
9056 case 'D': /* floating point destination register */
9057 case 'S': /* floating point source register */
9058 case 'T': /* floating point target register */
9059 case 'R': /* floating point source register */
9064 || (mips_opts.ase_mdmx
9065 && (ip->insn_mo->pinfo & FP_D)
9066 && (ip->insn_mo->pinfo & (INSN_COPROC_MOVE_DELAY
9067 | INSN_COPROC_MEMORY_DELAY
9068 | INSN_LOAD_COPROC_DELAY
9069 | INSN_LOAD_MEMORY_DELAY
9070 | INSN_STORE_MEMORY))))
9073 if (reg_lookup (&s, rtype, ®no))
9075 if ((regno & 1) != 0
9077 && ! (strcmp (str, "mtc1") == 0
9078 || strcmp (str, "mfc1") == 0
9079 || strcmp (str, "lwc1") == 0
9080 || strcmp (str, "swc1") == 0
9081 || strcmp (str, "l.s") == 0
9082 || strcmp (str, "s.s") == 0
9083 || strcmp (str, "mftc1") == 0
9084 || strcmp (str, "mfthc1") == 0
9085 || strcmp (str, "cftc1") == 0
9086 || strcmp (str, "mttc1") == 0
9087 || strcmp (str, "mtthc1") == 0
9088 || strcmp (str, "cttc1") == 0))
9089 as_warn (_("Float register should be even, was %d"),
9097 if (c == 'V' || c == 'W')
9108 INSERT_OPERAND (FD, *ip, regno);
9113 INSERT_OPERAND (FS, *ip, regno);
9116 /* This is like 'Z', but also needs to fix the MDMX
9117 vector/scalar select bits. Note that the
9118 scalar immediate case is handled above. */
9121 int is_qh = (ip->insn_opcode & (1 << OP_SH_VSEL));
9122 int max_el = (is_qh ? 3 : 7);
9124 my_getExpression(&imm_expr, s);
9125 check_absolute_expr (ip, &imm_expr);
9127 if (imm_expr.X_add_number > max_el)
9128 as_bad(_("Bad element selector %ld"),
9129 (long) imm_expr.X_add_number);
9130 imm_expr.X_add_number &= max_el;
9131 ip->insn_opcode |= (imm_expr.X_add_number
9134 imm_expr.X_op = O_absent;
9136 as_warn(_("Expecting ']' found '%s'"), s);
9142 if (ip->insn_opcode & (OP_MASK_VSEL << OP_SH_VSEL))
9143 ip->insn_opcode |= (MDMX_FMTSEL_VEC_QH
9146 ip->insn_opcode |= (MDMX_FMTSEL_VEC_OB <<
9153 INSERT_OPERAND (FT, *ip, regno);
9156 INSERT_OPERAND (FR, *ip, regno);
9166 INSERT_OPERAND (FS, *ip, lastregno);
9169 INSERT_OPERAND (FT, *ip, lastregno);
9175 my_getExpression (&imm_expr, s);
9176 if (imm_expr.X_op != O_big
9177 && imm_expr.X_op != O_constant)
9178 insn_error = _("absolute expression required");
9179 if (HAVE_32BIT_GPRS)
9180 normalize_constant_expr (&imm_expr);
9185 my_getExpression (&offset_expr, s);
9186 normalize_address_expr (&offset_expr);
9187 *imm_reloc = BFD_RELOC_32;
9200 unsigned char temp[8];
9202 unsigned int length;
9207 /* These only appear as the last operand in an
9208 instruction, and every instruction that accepts
9209 them in any variant accepts them in all variants.
9210 This means we don't have to worry about backing out
9211 any changes if the instruction does not match.
9213 The difference between them is the size of the
9214 floating point constant and where it goes. For 'F'
9215 and 'L' the constant is 64 bits; for 'f' and 'l' it
9216 is 32 bits. Where the constant is placed is based
9217 on how the MIPS assembler does things:
9220 f -- immediate value
9223 The .lit4 and .lit8 sections are only used if
9224 permitted by the -G argument.
9226 The code below needs to know whether the target register
9227 is 32 or 64 bits wide. It relies on the fact 'f' and
9228 'F' are used with GPR-based instructions and 'l' and
9229 'L' are used with FPR-based instructions. */
9231 f64 = *args == 'F' || *args == 'L';
9232 using_gprs = *args == 'F' || *args == 'f';
9234 save_in = input_line_pointer;
9235 input_line_pointer = s;
9236 err = md_atof (f64 ? 'd' : 'f', (char *) temp, &len);
9238 s = input_line_pointer;
9239 input_line_pointer = save_in;
9240 if (err != NULL && *err != '\0')
9242 as_bad (_("Bad floating point constant: %s"), err);
9243 memset (temp, '\0', sizeof temp);
9244 length = f64 ? 8 : 4;
9247 assert (length == (unsigned) (f64 ? 8 : 4));
9251 && (g_switch_value < 4
9252 || (temp[0] == 0 && temp[1] == 0)
9253 || (temp[2] == 0 && temp[3] == 0))))
9255 imm_expr.X_op = O_constant;
9256 if (! target_big_endian)
9257 imm_expr.X_add_number = bfd_getl32 (temp);
9259 imm_expr.X_add_number = bfd_getb32 (temp);
9262 && ! mips_disable_float_construction
9263 /* Constants can only be constructed in GPRs and
9264 copied to FPRs if the GPRs are at least as wide
9265 as the FPRs. Force the constant into memory if
9266 we are using 64-bit FPRs but the GPRs are only
9269 || ! (HAVE_64BIT_FPRS && HAVE_32BIT_GPRS))
9270 && ((temp[0] == 0 && temp[1] == 0)
9271 || (temp[2] == 0 && temp[3] == 0))
9272 && ((temp[4] == 0 && temp[5] == 0)
9273 || (temp[6] == 0 && temp[7] == 0)))
9275 /* The value is simple enough to load with a couple of
9276 instructions. If using 32-bit registers, set
9277 imm_expr to the high order 32 bits and offset_expr to
9278 the low order 32 bits. Otherwise, set imm_expr to
9279 the entire 64 bit constant. */
9280 if (using_gprs ? HAVE_32BIT_GPRS : HAVE_32BIT_FPRS)
9282 imm_expr.X_op = O_constant;
9283 offset_expr.X_op = O_constant;
9284 if (! target_big_endian)
9286 imm_expr.X_add_number = bfd_getl32 (temp + 4);
9287 offset_expr.X_add_number = bfd_getl32 (temp);
9291 imm_expr.X_add_number = bfd_getb32 (temp);
9292 offset_expr.X_add_number = bfd_getb32 (temp + 4);
9294 if (offset_expr.X_add_number == 0)
9295 offset_expr.X_op = O_absent;
9297 else if (sizeof (imm_expr.X_add_number) > 4)
9299 imm_expr.X_op = O_constant;
9300 if (! target_big_endian)
9301 imm_expr.X_add_number = bfd_getl64 (temp);
9303 imm_expr.X_add_number = bfd_getb64 (temp);
9307 imm_expr.X_op = O_big;
9308 imm_expr.X_add_number = 4;
9309 if (! target_big_endian)
9311 generic_bignum[0] = bfd_getl16 (temp);
9312 generic_bignum[1] = bfd_getl16 (temp + 2);
9313 generic_bignum[2] = bfd_getl16 (temp + 4);
9314 generic_bignum[3] = bfd_getl16 (temp + 6);
9318 generic_bignum[0] = bfd_getb16 (temp + 6);
9319 generic_bignum[1] = bfd_getb16 (temp + 4);
9320 generic_bignum[2] = bfd_getb16 (temp + 2);
9321 generic_bignum[3] = bfd_getb16 (temp);
9327 const char *newname;
9330 /* Switch to the right section. */
9332 subseg = now_subseg;
9335 default: /* unused default case avoids warnings. */
9337 newname = RDATA_SECTION_NAME;
9338 if (g_switch_value >= 8)
9342 newname = RDATA_SECTION_NAME;
9345 assert (g_switch_value >= 4);
9349 new_seg = subseg_new (newname, (subsegT) 0);
9350 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
9351 bfd_set_section_flags (stdoutput, new_seg,
9356 frag_align (*args == 'l' ? 2 : 3, 0, 0);
9357 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
9358 && strcmp (TARGET_OS, "elf") != 0)
9359 record_alignment (new_seg, 4);
9361 record_alignment (new_seg, *args == 'l' ? 2 : 3);
9363 as_bad (_("Can't use floating point insn in this section"));
9365 /* Set the argument to the current address in the
9367 offset_expr.X_op = O_symbol;
9368 offset_expr.X_add_symbol =
9369 symbol_new ("L0\001", now_seg,
9370 (valueT) frag_now_fix (), frag_now);
9371 offset_expr.X_add_number = 0;
9373 /* Put the floating point number into the section. */
9374 p = frag_more ((int) length);
9375 memcpy (p, temp, length);
9377 /* Switch back to the original section. */
9378 subseg_set (seg, subseg);
9383 case 'i': /* 16 bit unsigned immediate */
9384 case 'j': /* 16 bit signed immediate */
9385 *imm_reloc = BFD_RELOC_LO16;
9386 if (my_getSmallExpression (&imm_expr, imm_reloc, s) == 0)
9389 offsetT minval, maxval;
9391 more = (insn + 1 < &mips_opcodes[NUMOPCODES]
9392 && strcmp (insn->name, insn[1].name) == 0);
9394 /* If the expression was written as an unsigned number,
9395 only treat it as signed if there are no more
9399 && sizeof (imm_expr.X_add_number) <= 4
9400 && imm_expr.X_op == O_constant
9401 && imm_expr.X_add_number < 0
9402 && imm_expr.X_unsigned
9406 /* For compatibility with older assemblers, we accept
9407 0x8000-0xffff as signed 16-bit numbers when only
9408 signed numbers are allowed. */
9410 minval = 0, maxval = 0xffff;
9412 minval = -0x8000, maxval = 0x7fff;
9414 minval = -0x8000, maxval = 0xffff;
9416 if (imm_expr.X_op != O_constant
9417 || imm_expr.X_add_number < minval
9418 || imm_expr.X_add_number > maxval)
9422 if (imm_expr.X_op == O_constant
9423 || imm_expr.X_op == O_big)
9424 as_bad (_("expression out of range"));
9430 case 'o': /* 16 bit offset */
9431 /* Check whether there is only a single bracketed expression
9432 left. If so, it must be the base register and the
9433 constant must be zero. */
9434 if (*s == '(' && strchr (s + 1, '(') == 0)
9436 offset_expr.X_op = O_constant;
9437 offset_expr.X_add_number = 0;
9441 /* If this value won't fit into a 16 bit offset, then go
9442 find a macro that will generate the 32 bit offset
9444 if (my_getSmallExpression (&offset_expr, offset_reloc, s) == 0
9445 && (offset_expr.X_op != O_constant
9446 || offset_expr.X_add_number >= 0x8000
9447 || offset_expr.X_add_number < -0x8000))
9453 case 'p': /* pc relative offset */
9454 *offset_reloc = BFD_RELOC_16_PCREL_S2;
9455 my_getExpression (&offset_expr, s);
9459 case 'u': /* upper 16 bits */
9460 if (my_getSmallExpression (&imm_expr, imm_reloc, s) == 0
9461 && imm_expr.X_op == O_constant
9462 && (imm_expr.X_add_number < 0
9463 || imm_expr.X_add_number >= 0x10000))
9464 as_bad (_("lui expression not in range 0..65535"));
9468 case 'a': /* 26 bit address */
9469 my_getExpression (&offset_expr, s);
9471 *offset_reloc = BFD_RELOC_MIPS_JMP;
9474 case 'N': /* 3 bit branch condition code */
9475 case 'M': /* 3 bit compare condition code */
9477 if (ip->insn_mo->pinfo & (FP_D| FP_S))
9479 if (!reg_lookup (&s, rtype, ®no))
9481 if ((strcmp(str + strlen(str) - 3, ".ps") == 0
9482 || strcmp(str + strlen(str) - 5, "any2f") == 0
9483 || strcmp(str + strlen(str) - 5, "any2t") == 0)
9484 && (regno & 1) != 0)
9485 as_warn(_("Condition code register should be even for %s, was %d"),
9487 if ((strcmp(str + strlen(str) - 5, "any4f") == 0
9488 || strcmp(str + strlen(str) - 5, "any4t") == 0)
9489 && (regno & 3) != 0)
9490 as_warn(_("Condition code register should be 0 or 4 for %s, was %d"),
9493 INSERT_OPERAND (BCC, *ip, regno);
9495 INSERT_OPERAND (CCC, *ip, regno);
9499 if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X'))
9510 while (ISDIGIT (*s));
9513 c = 8; /* Invalid sel value. */
9516 as_bad (_("invalid coprocessor sub-selection value (0-7)"));
9517 ip->insn_opcode |= c;
9521 /* Must be at least one digit. */
9522 my_getExpression (&imm_expr, s);
9523 check_absolute_expr (ip, &imm_expr);
9525 if ((unsigned long) imm_expr.X_add_number
9526 > (unsigned long) OP_MASK_VECBYTE)
9528 as_bad (_("bad byte vector index (%ld)"),
9529 (long) imm_expr.X_add_number);
9530 imm_expr.X_add_number = 0;
9533 INSERT_OPERAND (VECBYTE, *ip, imm_expr.X_add_number);
9534 imm_expr.X_op = O_absent;
9539 my_getExpression (&imm_expr, s);
9540 check_absolute_expr (ip, &imm_expr);
9542 if ((unsigned long) imm_expr.X_add_number
9543 > (unsigned long) OP_MASK_VECALIGN)
9545 as_bad (_("bad byte vector index (%ld)"),
9546 (long) imm_expr.X_add_number);
9547 imm_expr.X_add_number = 0;
9550 INSERT_OPERAND (VECALIGN, *ip, imm_expr.X_add_number);
9551 imm_expr.X_op = O_absent;
9556 as_bad (_("bad char = '%c'\n"), *args);
9561 /* Args don't match. */
9562 if (insn + 1 < &mips_opcodes[NUMOPCODES] &&
9563 !strcmp (insn->name, insn[1].name))
9567 insn_error = _("illegal operands");
9572 insn_error = _("illegal operands");
9577 #define SKIP_SPACE_TABS(S) { while (*(S) == ' ' || *(S) == '\t') ++(S); }
9579 /* This routine assembles an instruction into its binary format when
9580 assembling for the mips16. As a side effect, it sets one of the
9581 global variables imm_reloc or offset_reloc to the type of
9582 relocation to do if one of the operands is an address expression.
9583 It also sets mips16_small and mips16_ext if the user explicitly
9584 requested a small or extended instruction. */
9587 mips16_ip (char *str, struct mips_cl_insn *ip)
9591 struct mips_opcode *insn;
9594 unsigned int lastregno = 0;
9600 mips16_small = FALSE;
9603 for (s = str; ISLOWER (*s); ++s)
9615 if (s[1] == 't' && s[2] == ' ')
9618 mips16_small = TRUE;
9622 else if (s[1] == 'e' && s[2] == ' ')
9631 insn_error = _("unknown opcode");
9635 if (mips_opts.noautoextend && ! mips16_ext)
9636 mips16_small = TRUE;
9638 if ((insn = (struct mips_opcode *) hash_find (mips16_op_hash, str)) == NULL)
9640 insn_error = _("unrecognized opcode");
9649 assert (strcmp (insn->name, str) == 0);
9651 if (OPCODE_IS_MEMBER (insn, mips_opts.isa, mips_opts.arch))
9658 if (insn + 1 < &mips16_opcodes[bfd_mips16_num_opcodes]
9659 && strcmp (insn->name, insn[1].name) == 0)
9668 static char buf[100];
9670 _("opcode not supported on this processor: %s (%s)"),
9671 mips_cpu_info_from_arch (mips_opts.arch)->name,
9672 mips_cpu_info_from_isa (mips_opts.isa)->name);
9679 create_insn (ip, insn);
9680 imm_expr.X_op = O_absent;
9681 imm_reloc[0] = BFD_RELOC_UNUSED;
9682 imm_reloc[1] = BFD_RELOC_UNUSED;
9683 imm_reloc[2] = BFD_RELOC_UNUSED;
9684 imm2_expr.X_op = O_absent;
9685 offset_expr.X_op = O_absent;
9686 offset_reloc[0] = BFD_RELOC_UNUSED;
9687 offset_reloc[1] = BFD_RELOC_UNUSED;
9688 offset_reloc[2] = BFD_RELOC_UNUSED;
9689 for (args = insn->args; 1; ++args)
9696 /* In this switch statement we call break if we did not find
9697 a match, continue if we did find a match, or return if we
9706 /* Stuff the immediate value in now, if we can. */
9707 if (imm_expr.X_op == O_constant
9708 && *imm_reloc > BFD_RELOC_UNUSED
9709 && insn->pinfo != INSN_MACRO)
9713 switch (*offset_reloc)
9715 case BFD_RELOC_MIPS16_HI16_S:
9716 tmp = (imm_expr.X_add_number + 0x8000) >> 16;
9719 case BFD_RELOC_MIPS16_HI16:
9720 tmp = imm_expr.X_add_number >> 16;
9723 case BFD_RELOC_MIPS16_LO16:
9724 tmp = ((imm_expr.X_add_number + 0x8000) & 0xffff)
9728 case BFD_RELOC_UNUSED:
9729 tmp = imm_expr.X_add_number;
9735 *offset_reloc = BFD_RELOC_UNUSED;
9737 mips16_immed (NULL, 0, *imm_reloc - BFD_RELOC_UNUSED,
9738 tmp, TRUE, mips16_small,
9739 mips16_ext, &ip->insn_opcode,
9740 &ip->use_extend, &ip->extend);
9741 imm_expr.X_op = O_absent;
9742 *imm_reloc = BFD_RELOC_UNUSED;
9756 MIPS16_INSERT_OPERAND (RX, *ip, lastregno);
9759 MIPS16_INSERT_OPERAND (RY, *ip, lastregno);
9775 MIPS16_INSERT_OPERAND (RX, *ip, lastregno);
9777 MIPS16_INSERT_OPERAND (RY, *ip, lastregno);
9792 if (!reg_lookup (&s, RTYPE_NUM | RTYPE_GP, ®no))
9794 if (c == 'v' || c == 'w')
9797 ip->insn_opcode |= lastregno << MIPS16OP_SH_RX;
9799 ip->insn_opcode |= lastregno << MIPS16OP_SH_RY;
9810 if (c == 'v' || c == 'w')
9812 regno = mips16_to_32_reg_map[lastregno];
9826 regno = mips32_to_16_reg_map[regno];
9831 regno = ILLEGAL_REG;
9836 regno = ILLEGAL_REG;
9841 regno = ILLEGAL_REG;
9846 if (regno == AT && ! mips_opts.noat)
9847 as_warn (_("used $at without \".set noat\""));
9854 if (regno == ILLEGAL_REG)
9861 MIPS16_INSERT_OPERAND (RX, *ip, regno);
9865 MIPS16_INSERT_OPERAND (RY, *ip, regno);
9868 MIPS16_INSERT_OPERAND (RZ, *ip, regno);
9871 MIPS16_INSERT_OPERAND (MOVE32Z, *ip, regno);
9877 MIPS16_INSERT_OPERAND (REGR32, *ip, regno);
9880 regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3);
9881 MIPS16_INSERT_OPERAND (REG32R, *ip, regno);
9891 if (strncmp (s, "$pc", 3) == 0)
9908 i = my_getSmallExpression (&imm_expr, imm_reloc, s);
9911 if (imm_expr.X_op != O_constant)
9914 ip->use_extend = TRUE;
9919 /* We need to relax this instruction. */
9920 *offset_reloc = *imm_reloc;
9921 *imm_reloc = (int) BFD_RELOC_UNUSED + c;
9926 *imm_reloc = BFD_RELOC_UNUSED;
9934 my_getExpression (&imm_expr, s);
9935 if (imm_expr.X_op == O_register)
9937 /* What we thought was an expression turned out to
9940 if (s[0] == '(' && args[1] == '(')
9942 /* It looks like the expression was omitted
9943 before a register indirection, which means
9944 that the expression is implicitly zero. We
9945 still set up imm_expr, so that we handle
9946 explicit extensions correctly. */
9947 imm_expr.X_op = O_constant;
9948 imm_expr.X_add_number = 0;
9949 *imm_reloc = (int) BFD_RELOC_UNUSED + c;
9956 /* We need to relax this instruction. */
9957 *imm_reloc = (int) BFD_RELOC_UNUSED + c;
9966 /* We use offset_reloc rather than imm_reloc for the PC
9967 relative operands. This lets macros with both
9968 immediate and address operands work correctly. */
9969 my_getExpression (&offset_expr, s);
9971 if (offset_expr.X_op == O_register)
9974 /* We need to relax this instruction. */
9975 *offset_reloc = (int) BFD_RELOC_UNUSED + c;
9979 case '6': /* break code */
9980 my_getExpression (&imm_expr, s);
9981 check_absolute_expr (ip, &imm_expr);
9982 if ((unsigned long) imm_expr.X_add_number > 63)
9983 as_warn (_("Invalid value for `%s' (%lu)"),
9985 (unsigned long) imm_expr.X_add_number);
9986 MIPS16_INSERT_OPERAND (IMM6, *ip, imm_expr.X_add_number);
9987 imm_expr.X_op = O_absent;
9991 case 'a': /* 26 bit address */
9992 my_getExpression (&offset_expr, s);
9994 *offset_reloc = BFD_RELOC_MIPS16_JMP;
9995 ip->insn_opcode <<= 16;
9998 case 'l': /* register list for entry macro */
9999 case 'L': /* register list for exit macro */
10009 unsigned int freg, reg1, reg2;
10011 while (*s == ' ' || *s == ',')
10013 if (reg_lookup (&s, RTYPE_GP | RTYPE_NUM, ®1))
10015 else if (reg_lookup (&s, RTYPE_FPU, ®1))
10019 as_bad (_("can't parse register list"));
10029 if (!reg_lookup (&s, freg ? RTYPE_FPU
10030 : (RTYPE_GP | RTYPE_NUM), ®2))
10032 as_bad (_("invalid register list"));
10036 if (freg && reg1 == 0 && reg2 == 0 && c == 'L')
10038 mask &= ~ (7 << 3);
10041 else if (freg && reg1 == 0 && reg2 == 1 && c == 'L')
10043 mask &= ~ (7 << 3);
10046 else if (reg1 == 4 && reg2 >= 4 && reg2 <= 7 && c != 'L')
10047 mask |= (reg2 - 3) << 3;
10048 else if (reg1 == 16 && reg2 >= 16 && reg2 <= 17)
10049 mask |= (reg2 - 15) << 1;
10050 else if (reg1 == RA && reg2 == RA)
10054 as_bad (_("invalid register list"));
10058 /* The mask is filled in in the opcode table for the
10059 benefit of the disassembler. We remove it before
10060 applying the actual mask. */
10061 ip->insn_opcode &= ~ ((7 << 3) << MIPS16OP_SH_IMM6);
10062 ip->insn_opcode |= mask << MIPS16OP_SH_IMM6;
10066 case 'm': /* Register list for save insn. */
10067 case 'M': /* Register list for restore insn. */
10070 int framesz = 0, seen_framesz = 0;
10071 int args = 0, statics = 0, sregs = 0;
10075 unsigned int reg1, reg2;
10077 SKIP_SPACE_TABS (s);
10080 SKIP_SPACE_TABS (s);
10082 my_getExpression (&imm_expr, s);
10083 if (imm_expr.X_op == O_constant)
10085 /* Handle the frame size. */
10088 as_bad (_("more than one frame size in list"));
10092 framesz = imm_expr.X_add_number;
10093 imm_expr.X_op = O_absent;
10098 if (! reg_lookup (&s, RTYPE_GP | RTYPE_NUM, ®1))
10100 as_bad (_("can't parse register list"));
10112 if (! reg_lookup (&s, RTYPE_GP | RTYPE_NUM, ®2)
10115 as_bad (_("can't parse register list"));
10120 while (reg1 <= reg2)
10122 if (reg1 >= 4 && reg1 <= 7)
10124 if (c == 'm' && !seen_framesz)
10126 args |= 1 << (reg1 - 4);
10128 /* statics $a0-$a3 */
10129 statics |= 1 << (reg1 - 4);
10131 else if ((reg1 >= 16 && reg1 <= 23) || reg1 == 30)
10134 sregs |= 1 << ((reg1 == 30) ? 8 : (reg1 - 16));
10136 else if (reg1 == 31)
10138 /* Add $ra to insn. */
10143 as_bad (_("unexpected register in list"));
10151 /* Encode args/statics combination. */
10152 if (args & statics)
10153 as_bad (_("arg/static registers overlap"));
10154 else if (args == 0xf)
10155 /* All $a0-$a3 are args. */
10156 opcode |= MIPS16_ALL_ARGS << 16;
10157 else if (statics == 0xf)
10158 /* All $a0-$a3 are statics. */
10159 opcode |= MIPS16_ALL_STATICS << 16;
10162 int narg = 0, nstat = 0;
10164 /* Count arg registers. */
10171 as_bad (_("invalid arg register list"));
10173 /* Count static registers. */
10174 while (statics & 0x8)
10176 statics = (statics << 1) & 0xf;
10180 as_bad (_("invalid static register list"));
10182 /* Encode args/statics. */
10183 opcode |= ((narg << 2) | nstat) << 16;
10186 /* Encode $s0/$s1. */
10187 if (sregs & (1 << 0)) /* $s0 */
10189 if (sregs & (1 << 1)) /* $s1 */
10195 /* Count regs $s2-$s8. */
10203 as_bad (_("invalid static register list"));
10204 /* Encode $s2-$s8. */
10205 opcode |= nsreg << 24;
10208 /* Encode frame size. */
10210 as_bad (_("missing frame size"));
10211 else if ((framesz & 7) != 0 || framesz < 0
10212 || framesz > 0xff * 8)
10213 as_bad (_("invalid frame size"));
10214 else if (framesz != 128 || (opcode >> 16) != 0)
10217 opcode |= (((framesz & 0xf0) << 16)
10218 | (framesz & 0x0f));
10221 /* Finally build the instruction. */
10222 if ((opcode >> 16) != 0 || framesz == 0)
10224 ip->use_extend = TRUE;
10225 ip->extend = opcode >> 16;
10227 ip->insn_opcode |= opcode & 0x7f;
10231 case 'e': /* extend code */
10232 my_getExpression (&imm_expr, s);
10233 check_absolute_expr (ip, &imm_expr);
10234 if ((unsigned long) imm_expr.X_add_number > 0x7ff)
10236 as_warn (_("Invalid value for `%s' (%lu)"),
10238 (unsigned long) imm_expr.X_add_number);
10239 imm_expr.X_add_number &= 0x7ff;
10241 ip->insn_opcode |= imm_expr.X_add_number;
10242 imm_expr.X_op = O_absent;
10252 /* Args don't match. */
10253 if (insn + 1 < &mips16_opcodes[bfd_mips16_num_opcodes] &&
10254 strcmp (insn->name, insn[1].name) == 0)
10261 insn_error = _("illegal operands");
10267 /* This structure holds information we know about a mips16 immediate
10270 struct mips16_immed_operand
10272 /* The type code used in the argument string in the opcode table. */
10274 /* The number of bits in the short form of the opcode. */
10276 /* The number of bits in the extended form of the opcode. */
10278 /* The amount by which the short form is shifted when it is used;
10279 for example, the sw instruction has a shift count of 2. */
10281 /* The amount by which the short form is shifted when it is stored
10282 into the instruction code. */
10284 /* Non-zero if the short form is unsigned. */
10286 /* Non-zero if the extended form is unsigned. */
10288 /* Non-zero if the value is PC relative. */
10292 /* The mips16 immediate operand types. */
10294 static const struct mips16_immed_operand mips16_immed_operands[] =
10296 { '<', 3, 5, 0, MIPS16OP_SH_RZ, 1, 1, 0 },
10297 { '>', 3, 5, 0, MIPS16OP_SH_RX, 1, 1, 0 },
10298 { '[', 3, 6, 0, MIPS16OP_SH_RZ, 1, 1, 0 },
10299 { ']', 3, 6, 0, MIPS16OP_SH_RX, 1, 1, 0 },
10300 { '4', 4, 15, 0, MIPS16OP_SH_IMM4, 0, 0, 0 },
10301 { '5', 5, 16, 0, MIPS16OP_SH_IMM5, 1, 0, 0 },
10302 { 'H', 5, 16, 1, MIPS16OP_SH_IMM5, 1, 0, 0 },
10303 { 'W', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 0 },
10304 { 'D', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 0 },
10305 { 'j', 5, 16, 0, MIPS16OP_SH_IMM5, 0, 0, 0 },
10306 { '8', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 0, 0 },
10307 { 'V', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 0 },
10308 { 'C', 8, 16, 3, MIPS16OP_SH_IMM8, 1, 0, 0 },
10309 { 'U', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 1, 0 },
10310 { 'k', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 0 },
10311 { 'K', 8, 16, 3, MIPS16OP_SH_IMM8, 0, 0, 0 },
10312 { 'p', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 },
10313 { 'q', 11, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 },
10314 { 'A', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 1 },
10315 { 'B', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 1 },
10316 { 'E', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 1 }
10319 #define MIPS16_NUM_IMMED \
10320 (sizeof mips16_immed_operands / sizeof mips16_immed_operands[0])
10322 /* Handle a mips16 instruction with an immediate value. This or's the
10323 small immediate value into *INSN. It sets *USE_EXTEND to indicate
10324 whether an extended value is needed; if one is needed, it sets
10325 *EXTEND to the value. The argument type is TYPE. The value is VAL.
10326 If SMALL is true, an unextended opcode was explicitly requested.
10327 If EXT is true, an extended opcode was explicitly requested. If
10328 WARN is true, warn if EXT does not match reality. */
10331 mips16_immed (char *file, unsigned int line, int type, offsetT val,
10332 bfd_boolean warn, bfd_boolean small, bfd_boolean ext,
10333 unsigned long *insn, bfd_boolean *use_extend,
10334 unsigned short *extend)
10336 register const struct mips16_immed_operand *op;
10337 int mintiny, maxtiny;
10338 bfd_boolean needext;
10340 op = mips16_immed_operands;
10341 while (op->type != type)
10344 assert (op < mips16_immed_operands + MIPS16_NUM_IMMED);
10349 if (type == '<' || type == '>' || type == '[' || type == ']')
10352 maxtiny = 1 << op->nbits;
10357 maxtiny = (1 << op->nbits) - 1;
10362 mintiny = - (1 << (op->nbits - 1));
10363 maxtiny = (1 << (op->nbits - 1)) - 1;
10366 /* Branch offsets have an implicit 0 in the lowest bit. */
10367 if (type == 'p' || type == 'q')
10370 if ((val & ((1 << op->shift) - 1)) != 0
10371 || val < (mintiny << op->shift)
10372 || val > (maxtiny << op->shift))
10377 if (warn && ext && ! needext)
10378 as_warn_where (file, line,
10379 _("extended operand requested but not required"));
10380 if (small && needext)
10381 as_bad_where (file, line, _("invalid unextended operand value"));
10383 if (small || (! ext && ! needext))
10387 *use_extend = FALSE;
10388 insnval = ((val >> op->shift) & ((1 << op->nbits) - 1));
10389 insnval <<= op->op_shift;
10394 long minext, maxext;
10400 maxext = (1 << op->extbits) - 1;
10404 minext = - (1 << (op->extbits - 1));
10405 maxext = (1 << (op->extbits - 1)) - 1;
10407 if (val < minext || val > maxext)
10408 as_bad_where (file, line,
10409 _("operand value out of range for instruction"));
10411 *use_extend = TRUE;
10412 if (op->extbits == 16)
10414 extval = ((val >> 11) & 0x1f) | (val & 0x7e0);
10417 else if (op->extbits == 15)
10419 extval = ((val >> 11) & 0xf) | (val & 0x7f0);
10424 extval = ((val & 0x1f) << 6) | (val & 0x20);
10428 *extend = (unsigned short) extval;
10433 struct percent_op_match
10436 bfd_reloc_code_real_type reloc;
10439 static const struct percent_op_match mips_percent_op[] =
10441 {"%lo", BFD_RELOC_LO16},
10443 {"%call_hi", BFD_RELOC_MIPS_CALL_HI16},
10444 {"%call_lo", BFD_RELOC_MIPS_CALL_LO16},
10445 {"%call16", BFD_RELOC_MIPS_CALL16},
10446 {"%got_disp", BFD_RELOC_MIPS_GOT_DISP},
10447 {"%got_page", BFD_RELOC_MIPS_GOT_PAGE},
10448 {"%got_ofst", BFD_RELOC_MIPS_GOT_OFST},
10449 {"%got_hi", BFD_RELOC_MIPS_GOT_HI16},
10450 {"%got_lo", BFD_RELOC_MIPS_GOT_LO16},
10451 {"%got", BFD_RELOC_MIPS_GOT16},
10452 {"%gp_rel", BFD_RELOC_GPREL16},
10453 {"%half", BFD_RELOC_16},
10454 {"%highest", BFD_RELOC_MIPS_HIGHEST},
10455 {"%higher", BFD_RELOC_MIPS_HIGHER},
10456 {"%neg", BFD_RELOC_MIPS_SUB},
10457 {"%tlsgd", BFD_RELOC_MIPS_TLS_GD},
10458 {"%tlsldm", BFD_RELOC_MIPS_TLS_LDM},
10459 {"%dtprel_hi", BFD_RELOC_MIPS_TLS_DTPREL_HI16},
10460 {"%dtprel_lo", BFD_RELOC_MIPS_TLS_DTPREL_LO16},
10461 {"%tprel_hi", BFD_RELOC_MIPS_TLS_TPREL_HI16},
10462 {"%tprel_lo", BFD_RELOC_MIPS_TLS_TPREL_LO16},
10463 {"%gottprel", BFD_RELOC_MIPS_TLS_GOTTPREL},
10465 {"%hi", BFD_RELOC_HI16_S}
10468 static const struct percent_op_match mips16_percent_op[] =
10470 {"%lo", BFD_RELOC_MIPS16_LO16},
10471 {"%gprel", BFD_RELOC_MIPS16_GPREL},
10472 {"%hi", BFD_RELOC_MIPS16_HI16_S}
10476 /* Return true if *STR points to a relocation operator. When returning true,
10477 move *STR over the operator and store its relocation code in *RELOC.
10478 Leave both *STR and *RELOC alone when returning false. */
10481 parse_relocation (char **str, bfd_reloc_code_real_type *reloc)
10483 const struct percent_op_match *percent_op;
10486 if (mips_opts.mips16)
10488 percent_op = mips16_percent_op;
10489 limit = ARRAY_SIZE (mips16_percent_op);
10493 percent_op = mips_percent_op;
10494 limit = ARRAY_SIZE (mips_percent_op);
10497 for (i = 0; i < limit; i++)
10498 if (strncasecmp (*str, percent_op[i].str, strlen (percent_op[i].str)) == 0)
10500 int len = strlen (percent_op[i].str);
10502 if (!ISSPACE ((*str)[len]) && (*str)[len] != '(')
10505 *str += strlen (percent_op[i].str);
10506 *reloc = percent_op[i].reloc;
10508 /* Check whether the output BFD supports this relocation.
10509 If not, issue an error and fall back on something safe. */
10510 if (!bfd_reloc_type_lookup (stdoutput, percent_op[i].reloc))
10512 as_bad ("relocation %s isn't supported by the current ABI",
10513 percent_op[i].str);
10514 *reloc = BFD_RELOC_UNUSED;
10522 /* Parse string STR as a 16-bit relocatable operand. Store the
10523 expression in *EP and the relocations in the array starting
10524 at RELOC. Return the number of relocation operators used.
10526 On exit, EXPR_END points to the first character after the expression. */
10529 my_getSmallExpression (expressionS *ep, bfd_reloc_code_real_type *reloc,
10532 bfd_reloc_code_real_type reversed_reloc[3];
10533 size_t reloc_index, i;
10534 int crux_depth, str_depth;
10537 /* Search for the start of the main expression, recoding relocations
10538 in REVERSED_RELOC. End the loop with CRUX pointing to the start
10539 of the main expression and with CRUX_DEPTH containing the number
10540 of open brackets at that point. */
10547 crux_depth = str_depth;
10549 /* Skip over whitespace and brackets, keeping count of the number
10551 while (*str == ' ' || *str == '\t' || *str == '(')
10556 && reloc_index < (HAVE_NEWABI ? 3 : 1)
10557 && parse_relocation (&str, &reversed_reloc[reloc_index]));
10559 my_getExpression (ep, crux);
10562 /* Match every open bracket. */
10563 while (crux_depth > 0 && (*str == ')' || *str == ' ' || *str == '\t'))
10567 if (crux_depth > 0)
10568 as_bad ("unclosed '('");
10572 if (reloc_index != 0)
10574 prev_reloc_op_frag = frag_now;
10575 for (i = 0; i < reloc_index; i++)
10576 reloc[i] = reversed_reloc[reloc_index - 1 - i];
10579 return reloc_index;
10583 my_getExpression (expressionS *ep, char *str)
10588 save_in = input_line_pointer;
10589 input_line_pointer = str;
10591 expr_end = input_line_pointer;
10592 input_line_pointer = save_in;
10594 /* If we are in mips16 mode, and this is an expression based on `.',
10595 then we bump the value of the symbol by 1 since that is how other
10596 text symbols are handled. We don't bother to handle complex
10597 expressions, just `.' plus or minus a constant. */
10598 if (mips_opts.mips16
10599 && ep->X_op == O_symbol
10600 && strcmp (S_GET_NAME (ep->X_add_symbol), FAKE_LABEL_NAME) == 0
10601 && S_GET_SEGMENT (ep->X_add_symbol) == now_seg
10602 && symbol_get_frag (ep->X_add_symbol) == frag_now
10603 && symbol_constant_p (ep->X_add_symbol)
10604 && (val = S_GET_VALUE (ep->X_add_symbol)) == frag_now_fix ())
10605 S_SET_VALUE (ep->X_add_symbol, val + 1);
10608 /* Turn a string in input_line_pointer into a floating point constant
10609 of type TYPE, and store the appropriate bytes in *LITP. The number
10610 of LITTLENUMS emitted is stored in *SIZEP. An error message is
10611 returned, or NULL on OK. */
10614 md_atof (int type, char *litP, int *sizeP)
10617 LITTLENUM_TYPE words[4];
10633 return _("bad call to md_atof");
10636 t = atof_ieee (input_line_pointer, type, words);
10638 input_line_pointer = t;
10642 if (! target_big_endian)
10644 for (i = prec - 1; i >= 0; i--)
10646 md_number_to_chars (litP, words[i], 2);
10652 for (i = 0; i < prec; i++)
10654 md_number_to_chars (litP, words[i], 2);
10663 md_number_to_chars (char *buf, valueT val, int n)
10665 if (target_big_endian)
10666 number_to_chars_bigendian (buf, val, n);
10668 number_to_chars_littleendian (buf, val, n);
10672 static int support_64bit_objects(void)
10674 const char **list, **l;
10677 list = bfd_target_list ();
10678 for (l = list; *l != NULL; l++)
10680 /* This is traditional mips */
10681 if (strcmp (*l, "elf64-tradbigmips") == 0
10682 || strcmp (*l, "elf64-tradlittlemips") == 0)
10684 if (strcmp (*l, "elf64-bigmips") == 0
10685 || strcmp (*l, "elf64-littlemips") == 0)
10688 yes = (*l != NULL);
10692 #endif /* OBJ_ELF */
10694 const char *md_shortopts = "O::g::G:";
10696 struct option md_longopts[] =
10698 /* Options which specify architecture. */
10699 #define OPTION_ARCH_BASE (OPTION_MD_BASE)
10700 #define OPTION_MARCH (OPTION_ARCH_BASE + 0)
10701 {"march", required_argument, NULL, OPTION_MARCH},
10702 #define OPTION_MTUNE (OPTION_ARCH_BASE + 1)
10703 {"mtune", required_argument, NULL, OPTION_MTUNE},
10704 #define OPTION_MIPS1 (OPTION_ARCH_BASE + 2)
10705 {"mips0", no_argument, NULL, OPTION_MIPS1},
10706 {"mips1", no_argument, NULL, OPTION_MIPS1},
10707 #define OPTION_MIPS2 (OPTION_ARCH_BASE + 3)
10708 {"mips2", no_argument, NULL, OPTION_MIPS2},
10709 #define OPTION_MIPS3 (OPTION_ARCH_BASE + 4)
10710 {"mips3", no_argument, NULL, OPTION_MIPS3},
10711 #define OPTION_MIPS4 (OPTION_ARCH_BASE + 5)
10712 {"mips4", no_argument, NULL, OPTION_MIPS4},
10713 #define OPTION_MIPS5 (OPTION_ARCH_BASE + 6)
10714 {"mips5", no_argument, NULL, OPTION_MIPS5},
10715 #define OPTION_MIPS32 (OPTION_ARCH_BASE + 7)
10716 {"mips32", no_argument, NULL, OPTION_MIPS32},
10717 #define OPTION_MIPS64 (OPTION_ARCH_BASE + 8)
10718 {"mips64", no_argument, NULL, OPTION_MIPS64},
10719 #define OPTION_MIPS32R2 (OPTION_ARCH_BASE + 9)
10720 {"mips32r2", no_argument, NULL, OPTION_MIPS32R2},
10721 #define OPTION_MIPS64R2 (OPTION_ARCH_BASE + 10)
10722 {"mips64r2", no_argument, NULL, OPTION_MIPS64R2},
10724 /* Options which specify Application Specific Extensions (ASEs). */
10725 #define OPTION_ASE_BASE (OPTION_ARCH_BASE + 11)
10726 #define OPTION_MIPS16 (OPTION_ASE_BASE + 0)
10727 {"mips16", no_argument, NULL, OPTION_MIPS16},
10728 #define OPTION_NO_MIPS16 (OPTION_ASE_BASE + 1)
10729 {"no-mips16", no_argument, NULL, OPTION_NO_MIPS16},
10730 #define OPTION_MIPS3D (OPTION_ASE_BASE + 2)
10731 {"mips3d", no_argument, NULL, OPTION_MIPS3D},
10732 #define OPTION_NO_MIPS3D (OPTION_ASE_BASE + 3)
10733 {"no-mips3d", no_argument, NULL, OPTION_NO_MIPS3D},
10734 #define OPTION_MDMX (OPTION_ASE_BASE + 4)
10735 {"mdmx", no_argument, NULL, OPTION_MDMX},
10736 #define OPTION_NO_MDMX (OPTION_ASE_BASE + 5)
10737 {"no-mdmx", no_argument, NULL, OPTION_NO_MDMX},
10738 #define OPTION_DSP (OPTION_ASE_BASE + 6)
10739 {"mdsp", no_argument, NULL, OPTION_DSP},
10740 #define OPTION_NO_DSP (OPTION_ASE_BASE + 7)
10741 {"mno-dsp", no_argument, NULL, OPTION_NO_DSP},
10742 #define OPTION_MT (OPTION_ASE_BASE + 8)
10743 {"mmt", no_argument, NULL, OPTION_MT},
10744 #define OPTION_NO_MT (OPTION_ASE_BASE + 9)
10745 {"mno-mt", no_argument, NULL, OPTION_NO_MT},
10746 #define OPTION_SMARTMIPS (OPTION_ASE_BASE + 10)
10747 {"msmartmips", no_argument, NULL, OPTION_SMARTMIPS},
10748 #define OPTION_NO_SMARTMIPS (OPTION_ASE_BASE + 11)
10749 {"mno-smartmips", no_argument, NULL, OPTION_NO_SMARTMIPS},
10751 /* Old-style architecture options. Don't add more of these. */
10752 #define OPTION_COMPAT_ARCH_BASE (OPTION_ASE_BASE + 12)
10753 #define OPTION_M4650 (OPTION_COMPAT_ARCH_BASE + 0)
10754 {"m4650", no_argument, NULL, OPTION_M4650},
10755 #define OPTION_NO_M4650 (OPTION_COMPAT_ARCH_BASE + 1)
10756 {"no-m4650", no_argument, NULL, OPTION_NO_M4650},
10757 #define OPTION_M4010 (OPTION_COMPAT_ARCH_BASE + 2)
10758 {"m4010", no_argument, NULL, OPTION_M4010},
10759 #define OPTION_NO_M4010 (OPTION_COMPAT_ARCH_BASE + 3)
10760 {"no-m4010", no_argument, NULL, OPTION_NO_M4010},
10761 #define OPTION_M4100 (OPTION_COMPAT_ARCH_BASE + 4)
10762 {"m4100", no_argument, NULL, OPTION_M4100},
10763 #define OPTION_NO_M4100 (OPTION_COMPAT_ARCH_BASE + 5)
10764 {"no-m4100", no_argument, NULL, OPTION_NO_M4100},
10765 #define OPTION_M3900 (OPTION_COMPAT_ARCH_BASE + 6)
10766 {"m3900", no_argument, NULL, OPTION_M3900},
10767 #define OPTION_NO_M3900 (OPTION_COMPAT_ARCH_BASE + 7)
10768 {"no-m3900", no_argument, NULL, OPTION_NO_M3900},
10770 /* Options which enable bug fixes. */
10771 #define OPTION_FIX_BASE (OPTION_COMPAT_ARCH_BASE + 8)
10772 #define OPTION_M7000_HILO_FIX (OPTION_FIX_BASE + 0)
10773 {"mfix7000", no_argument, NULL, OPTION_M7000_HILO_FIX},
10774 #define OPTION_MNO_7000_HILO_FIX (OPTION_FIX_BASE + 1)
10775 {"no-fix-7000", no_argument, NULL, OPTION_MNO_7000_HILO_FIX},
10776 {"mno-fix7000", no_argument, NULL, OPTION_MNO_7000_HILO_FIX},
10777 #define OPTION_FIX_VR4120 (OPTION_FIX_BASE + 2)
10778 #define OPTION_NO_FIX_VR4120 (OPTION_FIX_BASE + 3)
10779 {"mfix-vr4120", no_argument, NULL, OPTION_FIX_VR4120},
10780 {"mno-fix-vr4120", no_argument, NULL, OPTION_NO_FIX_VR4120},
10781 #define OPTION_FIX_VR4130 (OPTION_FIX_BASE + 4)
10782 #define OPTION_NO_FIX_VR4130 (OPTION_FIX_BASE + 5)
10783 {"mfix-vr4130", no_argument, NULL, OPTION_FIX_VR4130},
10784 {"mno-fix-vr4130", no_argument, NULL, OPTION_NO_FIX_VR4130},
10786 /* Miscellaneous options. */
10787 #define OPTION_MISC_BASE (OPTION_FIX_BASE + 6)
10788 #define OPTION_TRAP (OPTION_MISC_BASE + 0)
10789 {"trap", no_argument, NULL, OPTION_TRAP},
10790 {"no-break", no_argument, NULL, OPTION_TRAP},
10791 #define OPTION_BREAK (OPTION_MISC_BASE + 1)
10792 {"break", no_argument, NULL, OPTION_BREAK},
10793 {"no-trap", no_argument, NULL, OPTION_BREAK},
10794 #define OPTION_EB (OPTION_MISC_BASE + 2)
10795 {"EB", no_argument, NULL, OPTION_EB},
10796 #define OPTION_EL (OPTION_MISC_BASE + 3)
10797 {"EL", no_argument, NULL, OPTION_EL},
10798 #define OPTION_FP32 (OPTION_MISC_BASE + 4)
10799 {"mfp32", no_argument, NULL, OPTION_FP32},
10800 #define OPTION_GP32 (OPTION_MISC_BASE + 5)
10801 {"mgp32", no_argument, NULL, OPTION_GP32},
10802 #define OPTION_CONSTRUCT_FLOATS (OPTION_MISC_BASE + 6)
10803 {"construct-floats", no_argument, NULL, OPTION_CONSTRUCT_FLOATS},
10804 #define OPTION_NO_CONSTRUCT_FLOATS (OPTION_MISC_BASE + 7)
10805 {"no-construct-floats", no_argument, NULL, OPTION_NO_CONSTRUCT_FLOATS},
10806 #define OPTION_FP64 (OPTION_MISC_BASE + 8)
10807 {"mfp64", no_argument, NULL, OPTION_FP64},
10808 #define OPTION_GP64 (OPTION_MISC_BASE + 9)
10809 {"mgp64", no_argument, NULL, OPTION_GP64},
10810 #define OPTION_RELAX_BRANCH (OPTION_MISC_BASE + 10)
10811 #define OPTION_NO_RELAX_BRANCH (OPTION_MISC_BASE + 11)
10812 {"relax-branch", no_argument, NULL, OPTION_RELAX_BRANCH},
10813 {"no-relax-branch", no_argument, NULL, OPTION_NO_RELAX_BRANCH},
10814 #define OPTION_MSHARED (OPTION_MISC_BASE + 12)
10815 #define OPTION_MNO_SHARED (OPTION_MISC_BASE + 13)
10816 {"mshared", no_argument, NULL, OPTION_MSHARED},
10817 {"mno-shared", no_argument, NULL, OPTION_MNO_SHARED},
10818 #define OPTION_MSYM32 (OPTION_MISC_BASE + 14)
10819 #define OPTION_MNO_SYM32 (OPTION_MISC_BASE + 15)
10820 {"msym32", no_argument, NULL, OPTION_MSYM32},
10821 {"mno-sym32", no_argument, NULL, OPTION_MNO_SYM32},
10823 /* ELF-specific options. */
10825 #define OPTION_ELF_BASE (OPTION_MISC_BASE + 16)
10826 #define OPTION_CALL_SHARED (OPTION_ELF_BASE + 0)
10827 {"KPIC", no_argument, NULL, OPTION_CALL_SHARED},
10828 {"call_shared", no_argument, NULL, OPTION_CALL_SHARED},
10829 #define OPTION_NON_SHARED (OPTION_ELF_BASE + 1)
10830 {"non_shared", no_argument, NULL, OPTION_NON_SHARED},
10831 #define OPTION_XGOT (OPTION_ELF_BASE + 2)
10832 {"xgot", no_argument, NULL, OPTION_XGOT},
10833 #define OPTION_MABI (OPTION_ELF_BASE + 3)
10834 {"mabi", required_argument, NULL, OPTION_MABI},
10835 #define OPTION_32 (OPTION_ELF_BASE + 4)
10836 {"32", no_argument, NULL, OPTION_32},
10837 #define OPTION_N32 (OPTION_ELF_BASE + 5)
10838 {"n32", no_argument, NULL, OPTION_N32},
10839 #define OPTION_64 (OPTION_ELF_BASE + 6)
10840 {"64", no_argument, NULL, OPTION_64},
10841 #define OPTION_MDEBUG (OPTION_ELF_BASE + 7)
10842 {"mdebug", no_argument, NULL, OPTION_MDEBUG},
10843 #define OPTION_NO_MDEBUG (OPTION_ELF_BASE + 8)
10844 {"no-mdebug", no_argument, NULL, OPTION_NO_MDEBUG},
10845 #define OPTION_PDR (OPTION_ELF_BASE + 9)
10846 {"mpdr", no_argument, NULL, OPTION_PDR},
10847 #define OPTION_NO_PDR (OPTION_ELF_BASE + 10)
10848 {"mno-pdr", no_argument, NULL, OPTION_NO_PDR},
10849 #define OPTION_MVXWORKS_PIC (OPTION_ELF_BASE + 11)
10850 {"mvxworks-pic", no_argument, NULL, OPTION_MVXWORKS_PIC},
10851 #endif /* OBJ_ELF */
10853 {NULL, no_argument, NULL, 0}
10855 size_t md_longopts_size = sizeof (md_longopts);
10857 /* Set STRING_PTR (either &mips_arch_string or &mips_tune_string) to
10858 NEW_VALUE. Warn if another value was already specified. Note:
10859 we have to defer parsing the -march and -mtune arguments in order
10860 to handle 'from-abi' correctly, since the ABI might be specified
10861 in a later argument. */
10864 mips_set_option_string (const char **string_ptr, const char *new_value)
10866 if (*string_ptr != 0 && strcasecmp (*string_ptr, new_value) != 0)
10867 as_warn (_("A different %s was already specified, is now %s"),
10868 string_ptr == &mips_arch_string ? "-march" : "-mtune",
10871 *string_ptr = new_value;
10875 md_parse_option (int c, char *arg)
10879 case OPTION_CONSTRUCT_FLOATS:
10880 mips_disable_float_construction = 0;
10883 case OPTION_NO_CONSTRUCT_FLOATS:
10884 mips_disable_float_construction = 1;
10896 target_big_endian = 1;
10900 target_big_endian = 0;
10904 if (arg && arg[1] == '0')
10914 mips_debug = atoi (arg);
10915 /* When the MIPS assembler sees -g or -g2, it does not do
10916 optimizations which limit full symbolic debugging. We take
10917 that to be equivalent to -O0. */
10918 if (mips_debug == 2)
10923 file_mips_isa = ISA_MIPS1;
10927 file_mips_isa = ISA_MIPS2;
10931 file_mips_isa = ISA_MIPS3;
10935 file_mips_isa = ISA_MIPS4;
10939 file_mips_isa = ISA_MIPS5;
10942 case OPTION_MIPS32:
10943 file_mips_isa = ISA_MIPS32;
10946 case OPTION_MIPS32R2:
10947 file_mips_isa = ISA_MIPS32R2;
10950 case OPTION_MIPS64R2:
10951 file_mips_isa = ISA_MIPS64R2;
10954 case OPTION_MIPS64:
10955 file_mips_isa = ISA_MIPS64;
10959 mips_set_option_string (&mips_tune_string, arg);
10963 mips_set_option_string (&mips_arch_string, arg);
10967 mips_set_option_string (&mips_arch_string, "4650");
10968 mips_set_option_string (&mips_tune_string, "4650");
10971 case OPTION_NO_M4650:
10975 mips_set_option_string (&mips_arch_string, "4010");
10976 mips_set_option_string (&mips_tune_string, "4010");
10979 case OPTION_NO_M4010:
10983 mips_set_option_string (&mips_arch_string, "4100");
10984 mips_set_option_string (&mips_tune_string, "4100");
10987 case OPTION_NO_M4100:
10991 mips_set_option_string (&mips_arch_string, "3900");
10992 mips_set_option_string (&mips_tune_string, "3900");
10995 case OPTION_NO_M3900:
10999 mips_opts.ase_mdmx = 1;
11002 case OPTION_NO_MDMX:
11003 mips_opts.ase_mdmx = 0;
11007 mips_opts.ase_dsp = 1;
11010 case OPTION_NO_DSP:
11011 mips_opts.ase_dsp = 0;
11015 mips_opts.ase_mt = 1;
11019 mips_opts.ase_mt = 0;
11022 case OPTION_MIPS16:
11023 mips_opts.mips16 = 1;
11024 mips_no_prev_insn ();
11027 case OPTION_NO_MIPS16:
11028 mips_opts.mips16 = 0;
11029 mips_no_prev_insn ();
11032 case OPTION_MIPS3D:
11033 mips_opts.ase_mips3d = 1;
11036 case OPTION_NO_MIPS3D:
11037 mips_opts.ase_mips3d = 0;
11040 case OPTION_SMARTMIPS:
11041 mips_opts.ase_smartmips = 1;
11044 case OPTION_NO_SMARTMIPS:
11045 mips_opts.ase_smartmips = 0;
11048 case OPTION_FIX_VR4120:
11049 mips_fix_vr4120 = 1;
11052 case OPTION_NO_FIX_VR4120:
11053 mips_fix_vr4120 = 0;
11056 case OPTION_FIX_VR4130:
11057 mips_fix_vr4130 = 1;
11060 case OPTION_NO_FIX_VR4130:
11061 mips_fix_vr4130 = 0;
11064 case OPTION_RELAX_BRANCH:
11065 mips_relax_branch = 1;
11068 case OPTION_NO_RELAX_BRANCH:
11069 mips_relax_branch = 0;
11072 case OPTION_MSHARED:
11073 mips_in_shared = TRUE;
11076 case OPTION_MNO_SHARED:
11077 mips_in_shared = FALSE;
11080 case OPTION_MSYM32:
11081 mips_opts.sym32 = TRUE;
11084 case OPTION_MNO_SYM32:
11085 mips_opts.sym32 = FALSE;
11089 /* When generating ELF code, we permit -KPIC and -call_shared to
11090 select SVR4_PIC, and -non_shared to select no PIC. This is
11091 intended to be compatible with Irix 5. */
11092 case OPTION_CALL_SHARED:
11093 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
11095 as_bad (_("-call_shared is supported only for ELF format"));
11098 mips_pic = SVR4_PIC;
11099 mips_abicalls = TRUE;
11102 case OPTION_NON_SHARED:
11103 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
11105 as_bad (_("-non_shared is supported only for ELF format"));
11109 mips_abicalls = FALSE;
11112 /* The -xgot option tells the assembler to use 32 bit offsets
11113 when accessing the got in SVR4_PIC mode. It is for Irix
11118 #endif /* OBJ_ELF */
11121 g_switch_value = atoi (arg);
11126 /* The -32, -n32 and -64 options are shortcuts for -mabi=32, -mabi=n32
11129 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
11131 as_bad (_("-32 is supported for ELF format only"));
11134 mips_abi = O32_ABI;
11138 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
11140 as_bad (_("-n32 is supported for ELF format only"));
11143 mips_abi = N32_ABI;
11147 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
11149 as_bad (_("-64 is supported for ELF format only"));
11152 mips_abi = N64_ABI;
11153 if (! support_64bit_objects())
11154 as_fatal (_("No compiled in support for 64 bit object file format"));
11156 #endif /* OBJ_ELF */
11159 file_mips_gp32 = 1;
11163 file_mips_gp32 = 0;
11167 file_mips_fp32 = 1;
11171 file_mips_fp32 = 0;
11176 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
11178 as_bad (_("-mabi is supported for ELF format only"));
11181 if (strcmp (arg, "32") == 0)
11182 mips_abi = O32_ABI;
11183 else if (strcmp (arg, "o64") == 0)
11184 mips_abi = O64_ABI;
11185 else if (strcmp (arg, "n32") == 0)
11186 mips_abi = N32_ABI;
11187 else if (strcmp (arg, "64") == 0)
11189 mips_abi = N64_ABI;
11190 if (! support_64bit_objects())
11191 as_fatal (_("No compiled in support for 64 bit object file "
11194 else if (strcmp (arg, "eabi") == 0)
11195 mips_abi = EABI_ABI;
11198 as_fatal (_("invalid abi -mabi=%s"), arg);
11202 #endif /* OBJ_ELF */
11204 case OPTION_M7000_HILO_FIX:
11205 mips_7000_hilo_fix = TRUE;
11208 case OPTION_MNO_7000_HILO_FIX:
11209 mips_7000_hilo_fix = FALSE;
11213 case OPTION_MDEBUG:
11214 mips_flag_mdebug = TRUE;
11217 case OPTION_NO_MDEBUG:
11218 mips_flag_mdebug = FALSE;
11222 mips_flag_pdr = TRUE;
11225 case OPTION_NO_PDR:
11226 mips_flag_pdr = FALSE;
11229 case OPTION_MVXWORKS_PIC:
11230 mips_pic = VXWORKS_PIC;
11232 #endif /* OBJ_ELF */
11241 /* Set up globals to generate code for the ISA or processor
11242 described by INFO. */
11245 mips_set_architecture (const struct mips_cpu_info *info)
11249 file_mips_arch = info->cpu;
11250 mips_opts.arch = info->cpu;
11251 mips_opts.isa = info->isa;
11256 /* Likewise for tuning. */
11259 mips_set_tune (const struct mips_cpu_info *info)
11262 mips_tune = info->cpu;
11267 mips_after_parse_args (void)
11269 const struct mips_cpu_info *arch_info = 0;
11270 const struct mips_cpu_info *tune_info = 0;
11272 /* GP relative stuff not working for PE */
11273 if (strncmp (TARGET_OS, "pe", 2) == 0)
11275 if (g_switch_seen && g_switch_value != 0)
11276 as_bad (_("-G not supported in this configuration."));
11277 g_switch_value = 0;
11280 if (mips_abi == NO_ABI)
11281 mips_abi = MIPS_DEFAULT_ABI;
11283 /* The following code determines the architecture and register size.
11284 Similar code was added to GCC 3.3 (see override_options() in
11285 config/mips/mips.c). The GAS and GCC code should be kept in sync
11286 as much as possible. */
11288 if (mips_arch_string != 0)
11289 arch_info = mips_parse_cpu ("-march", mips_arch_string);
11291 if (file_mips_isa != ISA_UNKNOWN)
11293 /* Handle -mipsN. At this point, file_mips_isa contains the
11294 ISA level specified by -mipsN, while arch_info->isa contains
11295 the -march selection (if any). */
11296 if (arch_info != 0)
11298 /* -march takes precedence over -mipsN, since it is more descriptive.
11299 There's no harm in specifying both as long as the ISA levels
11301 if (file_mips_isa != arch_info->isa)
11302 as_bad (_("-%s conflicts with the other architecture options, which imply -%s"),
11303 mips_cpu_info_from_isa (file_mips_isa)->name,
11304 mips_cpu_info_from_isa (arch_info->isa)->name);
11307 arch_info = mips_cpu_info_from_isa (file_mips_isa);
11310 if (arch_info == 0)
11311 arch_info = mips_parse_cpu ("default CPU", MIPS_CPU_STRING_DEFAULT);
11313 if (ABI_NEEDS_64BIT_REGS (mips_abi) && !ISA_HAS_64BIT_REGS (arch_info->isa))
11314 as_bad ("-march=%s is not compatible with the selected ABI",
11317 mips_set_architecture (arch_info);
11319 /* Optimize for file_mips_arch, unless -mtune selects a different processor. */
11320 if (mips_tune_string != 0)
11321 tune_info = mips_parse_cpu ("-mtune", mips_tune_string);
11323 if (tune_info == 0)
11324 mips_set_tune (arch_info);
11326 mips_set_tune (tune_info);
11328 if (file_mips_gp32 >= 0)
11330 /* The user specified the size of the integer registers. Make sure
11331 it agrees with the ABI and ISA. */
11332 if (file_mips_gp32 == 0 && !ISA_HAS_64BIT_REGS (mips_opts.isa))
11333 as_bad (_("-mgp64 used with a 32-bit processor"));
11334 else if (file_mips_gp32 == 1 && ABI_NEEDS_64BIT_REGS (mips_abi))
11335 as_bad (_("-mgp32 used with a 64-bit ABI"));
11336 else if (file_mips_gp32 == 0 && ABI_NEEDS_32BIT_REGS (mips_abi))
11337 as_bad (_("-mgp64 used with a 32-bit ABI"));
11341 /* Infer the integer register size from the ABI and processor.
11342 Restrict ourselves to 32-bit registers if that's all the
11343 processor has, or if the ABI cannot handle 64-bit registers. */
11344 file_mips_gp32 = (ABI_NEEDS_32BIT_REGS (mips_abi)
11345 || !ISA_HAS_64BIT_REGS (mips_opts.isa));
11348 /* ??? GAS treats single-float processors as though they had 64-bit
11349 float registers (although it complains when double-precision
11350 instructions are used). As things stand, saying they have 32-bit
11351 registers would lead to spurious "register must be even" messages.
11352 So here we assume float registers are always the same size as
11353 integer ones, unless the user says otherwise. */
11354 if (file_mips_fp32 < 0)
11355 file_mips_fp32 = file_mips_gp32;
11357 /* End of GCC-shared inference code. */
11359 /* This flag is set when we have a 64-bit capable CPU but use only
11360 32-bit wide registers. Note that EABI does not use it. */
11361 if (ISA_HAS_64BIT_REGS (mips_opts.isa)
11362 && ((mips_abi == NO_ABI && file_mips_gp32 == 1)
11363 || mips_abi == O32_ABI))
11364 mips_32bitmode = 1;
11366 if (mips_opts.isa == ISA_MIPS1 && mips_trap)
11367 as_bad (_("trap exception not supported at ISA 1"));
11369 /* If the selected architecture includes support for ASEs, enable
11370 generation of code for them. */
11371 if (mips_opts.mips16 == -1)
11372 mips_opts.mips16 = (CPU_HAS_MIPS16 (file_mips_arch)) ? 1 : 0;
11373 if (mips_opts.ase_mips3d == -1)
11374 mips_opts.ase_mips3d = (CPU_HAS_MIPS3D (file_mips_arch)) ? 1 : 0;
11375 if (mips_opts.ase_mdmx == -1)
11376 mips_opts.ase_mdmx = (CPU_HAS_MDMX (file_mips_arch)) ? 1 : 0;
11377 if (mips_opts.ase_dsp == -1)
11378 mips_opts.ase_dsp = (CPU_HAS_DSP (file_mips_arch)) ? 1 : 0;
11379 if (mips_opts.ase_mt == -1)
11380 mips_opts.ase_mt = (CPU_HAS_MT (file_mips_arch)) ? 1 : 0;
11382 file_mips_isa = mips_opts.isa;
11383 file_ase_mips16 = mips_opts.mips16;
11384 file_ase_mips3d = mips_opts.ase_mips3d;
11385 file_ase_mdmx = mips_opts.ase_mdmx;
11386 file_ase_smartmips = mips_opts.ase_smartmips;
11387 file_ase_dsp = mips_opts.ase_dsp;
11388 file_ase_mt = mips_opts.ase_mt;
11389 mips_opts.gp32 = file_mips_gp32;
11390 mips_opts.fp32 = file_mips_fp32;
11392 if (mips_flag_mdebug < 0)
11394 #ifdef OBJ_MAYBE_ECOFF
11395 if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour)
11396 mips_flag_mdebug = 1;
11398 #endif /* OBJ_MAYBE_ECOFF */
11399 mips_flag_mdebug = 0;
11404 mips_init_after_args (void)
11406 /* initialize opcodes */
11407 bfd_mips_num_opcodes = bfd_mips_num_builtin_opcodes;
11408 mips_opcodes = (struct mips_opcode *) mips_builtin_opcodes;
11412 md_pcrel_from (fixS *fixP)
11414 valueT addr = fixP->fx_where + fixP->fx_frag->fr_address;
11415 switch (fixP->fx_r_type)
11417 case BFD_RELOC_16_PCREL_S2:
11418 case BFD_RELOC_MIPS_JMP:
11419 /* Return the address of the delay slot. */
11426 /* This is called before the symbol table is processed. In order to
11427 work with gcc when using mips-tfile, we must keep all local labels.
11428 However, in other cases, we want to discard them. If we were
11429 called with -g, but we didn't see any debugging information, it may
11430 mean that gcc is smuggling debugging information through to
11431 mips-tfile, in which case we must generate all local labels. */
11434 mips_frob_file_before_adjust (void)
11436 #ifndef NO_ECOFF_DEBUGGING
11437 if (ECOFF_DEBUGGING
11439 && ! ecoff_debugging_seen)
11440 flag_keep_locals = 1;
11444 /* Sort any unmatched HI16 and GOT16 relocs so that they immediately precede
11445 the corresponding LO16 reloc. This is called before md_apply_fix and
11446 tc_gen_reloc. Unmatched relocs can only be generated by use of explicit
11447 relocation operators.
11449 For our purposes, a %lo() expression matches a %got() or %hi()
11452 (a) it refers to the same symbol; and
11453 (b) the offset applied in the %lo() expression is no lower than
11454 the offset applied in the %got() or %hi().
11456 (b) allows us to cope with code like:
11459 lh $4,%lo(foo+2)($4)
11461 ...which is legal on RELA targets, and has a well-defined behaviour
11462 if the user knows that adding 2 to "foo" will not induce a carry to
11465 When several %lo()s match a particular %got() or %hi(), we use the
11466 following rules to distinguish them:
11468 (1) %lo()s with smaller offsets are a better match than %lo()s with
11471 (2) %lo()s with no matching %got() or %hi() are better than those
11472 that already have a matching %got() or %hi().
11474 (3) later %lo()s are better than earlier %lo()s.
11476 These rules are applied in order.
11478 (1) means, among other things, that %lo()s with identical offsets are
11479 chosen if they exist.
11481 (2) means that we won't associate several high-part relocations with
11482 the same low-part relocation unless there's no alternative. Having
11483 several high parts for the same low part is a GNU extension; this rule
11484 allows careful users to avoid it.
11486 (3) is purely cosmetic. mips_hi_fixup_list is is in reverse order,
11487 with the last high-part relocation being at the front of the list.
11488 It therefore makes sense to choose the last matching low-part
11489 relocation, all other things being equal. It's also easier
11490 to code that way. */
11493 mips_frob_file (void)
11495 struct mips_hi_fixup *l;
11497 for (l = mips_hi_fixup_list; l != NULL; l = l->next)
11499 segment_info_type *seginfo;
11500 bfd_boolean matched_lo_p;
11501 fixS **hi_pos, **lo_pos, **pos;
11503 assert (reloc_needs_lo_p (l->fixp->fx_r_type));
11505 /* If a GOT16 relocation turns out to be against a global symbol,
11506 there isn't supposed to be a matching LO. */
11507 if (l->fixp->fx_r_type == BFD_RELOC_MIPS_GOT16
11508 && !pic_need_relax (l->fixp->fx_addsy, l->seg))
11511 /* Check quickly whether the next fixup happens to be a matching %lo. */
11512 if (fixup_has_matching_lo_p (l->fixp))
11515 seginfo = seg_info (l->seg);
11517 /* Set HI_POS to the position of this relocation in the chain.
11518 Set LO_POS to the position of the chosen low-part relocation.
11519 MATCHED_LO_P is true on entry to the loop if *POS is a low-part
11520 relocation that matches an immediately-preceding high-part
11524 matched_lo_p = FALSE;
11525 for (pos = &seginfo->fix_root; *pos != NULL; pos = &(*pos)->fx_next)
11527 if (*pos == l->fixp)
11530 if (((*pos)->fx_r_type == BFD_RELOC_LO16
11531 || (*pos)->fx_r_type == BFD_RELOC_MIPS16_LO16)
11532 && (*pos)->fx_addsy == l->fixp->fx_addsy
11533 && (*pos)->fx_offset >= l->fixp->fx_offset
11535 || (*pos)->fx_offset < (*lo_pos)->fx_offset
11537 && (*pos)->fx_offset == (*lo_pos)->fx_offset)))
11540 matched_lo_p = (reloc_needs_lo_p ((*pos)->fx_r_type)
11541 && fixup_has_matching_lo_p (*pos));
11544 /* If we found a match, remove the high-part relocation from its
11545 current position and insert it before the low-part relocation.
11546 Make the offsets match so that fixup_has_matching_lo_p()
11549 We don't warn about unmatched high-part relocations since some
11550 versions of gcc have been known to emit dead "lui ...%hi(...)"
11552 if (lo_pos != NULL)
11554 l->fixp->fx_offset = (*lo_pos)->fx_offset;
11555 if (l->fixp->fx_next != *lo_pos)
11557 *hi_pos = l->fixp->fx_next;
11558 l->fixp->fx_next = *lo_pos;
11565 /* We may have combined relocations without symbols in the N32/N64 ABI.
11566 We have to prevent gas from dropping them. */
11569 mips_force_relocation (fixS *fixp)
11571 if (generic_force_reloc (fixp))
11575 && S_GET_SEGMENT (fixp->fx_addsy) == bfd_abs_section_ptr
11576 && (fixp->fx_r_type == BFD_RELOC_MIPS_SUB
11577 || fixp->fx_r_type == BFD_RELOC_HI16_S
11578 || fixp->fx_r_type == BFD_RELOC_LO16))
11584 /* Apply a fixup to the object file. */
11587 md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
11591 reloc_howto_type *howto;
11593 /* We ignore generic BFD relocations we don't know about. */
11594 howto = bfd_reloc_type_lookup (stdoutput, fixP->fx_r_type);
11598 assert (fixP->fx_size == 4
11599 || fixP->fx_r_type == BFD_RELOC_16
11600 || fixP->fx_r_type == BFD_RELOC_64
11601 || fixP->fx_r_type == BFD_RELOC_CTOR
11602 || fixP->fx_r_type == BFD_RELOC_MIPS_SUB
11603 || fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
11604 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY);
11606 buf = (bfd_byte *) (fixP->fx_frag->fr_literal + fixP->fx_where);
11608 assert (! fixP->fx_pcrel || fixP->fx_r_type == BFD_RELOC_16_PCREL_S2);
11610 /* Don't treat parts of a composite relocation as done. There are two
11613 (1) The second and third parts will be against 0 (RSS_UNDEF) but
11614 should nevertheless be emitted if the first part is.
11616 (2) In normal usage, composite relocations are never assembly-time
11617 constants. The easiest way of dealing with the pathological
11618 exceptions is to generate a relocation against STN_UNDEF and
11619 leave everything up to the linker. */
11620 if (fixP->fx_addsy == NULL && ! fixP->fx_pcrel && fixP->fx_tcbit == 0)
11623 switch (fixP->fx_r_type)
11625 case BFD_RELOC_MIPS_TLS_GD:
11626 case BFD_RELOC_MIPS_TLS_LDM:
11627 case BFD_RELOC_MIPS_TLS_DTPREL_HI16:
11628 case BFD_RELOC_MIPS_TLS_DTPREL_LO16:
11629 case BFD_RELOC_MIPS_TLS_GOTTPREL:
11630 case BFD_RELOC_MIPS_TLS_TPREL_HI16:
11631 case BFD_RELOC_MIPS_TLS_TPREL_LO16:
11632 S_SET_THREAD_LOCAL (fixP->fx_addsy);
11635 case BFD_RELOC_MIPS_JMP:
11636 case BFD_RELOC_MIPS_SHIFT5:
11637 case BFD_RELOC_MIPS_SHIFT6:
11638 case BFD_RELOC_MIPS_GOT_DISP:
11639 case BFD_RELOC_MIPS_GOT_PAGE:
11640 case BFD_RELOC_MIPS_GOT_OFST:
11641 case BFD_RELOC_MIPS_SUB:
11642 case BFD_RELOC_MIPS_INSERT_A:
11643 case BFD_RELOC_MIPS_INSERT_B:
11644 case BFD_RELOC_MIPS_DELETE:
11645 case BFD_RELOC_MIPS_HIGHEST:
11646 case BFD_RELOC_MIPS_HIGHER:
11647 case BFD_RELOC_MIPS_SCN_DISP:
11648 case BFD_RELOC_MIPS_REL16:
11649 case BFD_RELOC_MIPS_RELGOT:
11650 case BFD_RELOC_MIPS_JALR:
11651 case BFD_RELOC_HI16:
11652 case BFD_RELOC_HI16_S:
11653 case BFD_RELOC_GPREL16:
11654 case BFD_RELOC_MIPS_LITERAL:
11655 case BFD_RELOC_MIPS_CALL16:
11656 case BFD_RELOC_MIPS_GOT16:
11657 case BFD_RELOC_GPREL32:
11658 case BFD_RELOC_MIPS_GOT_HI16:
11659 case BFD_RELOC_MIPS_GOT_LO16:
11660 case BFD_RELOC_MIPS_CALL_HI16:
11661 case BFD_RELOC_MIPS_CALL_LO16:
11662 case BFD_RELOC_MIPS16_GPREL:
11663 case BFD_RELOC_MIPS16_HI16:
11664 case BFD_RELOC_MIPS16_HI16_S:
11665 /* Nothing needed to do. The value comes from the reloc entry */
11668 case BFD_RELOC_MIPS16_JMP:
11669 /* We currently always generate a reloc against a symbol, which
11670 means that we don't want an addend even if the symbol is
11676 /* This is handled like BFD_RELOC_32, but we output a sign
11677 extended value if we are only 32 bits. */
11680 if (8 <= sizeof (valueT))
11681 md_number_to_chars ((char *) buf, *valP, 8);
11686 if ((*valP & 0x80000000) != 0)
11690 md_number_to_chars ((char *)(buf + (target_big_endian ? 4 : 0)),
11692 md_number_to_chars ((char *)(buf + (target_big_endian ? 0 : 4)),
11698 case BFD_RELOC_RVA:
11700 /* If we are deleting this reloc entry, we must fill in the
11701 value now. This can happen if we have a .word which is not
11702 resolved when it appears but is later defined. */
11704 md_number_to_chars ((char *) buf, *valP, 4);
11708 /* If we are deleting this reloc entry, we must fill in the
11711 md_number_to_chars ((char *) buf, *valP, 2);
11714 case BFD_RELOC_LO16:
11715 case BFD_RELOC_MIPS16_LO16:
11716 /* FIXME: Now that embedded-PIC is gone, some of this code/comment
11717 may be safe to remove, but if so it's not obvious. */
11718 /* When handling an embedded PIC switch statement, we can wind
11719 up deleting a LO16 reloc. See the 'o' case in mips_ip. */
11722 if (*valP + 0x8000 > 0xffff)
11723 as_bad_where (fixP->fx_file, fixP->fx_line,
11724 _("relocation overflow"));
11725 if (target_big_endian)
11727 md_number_to_chars ((char *) buf, *valP, 2);
11731 case BFD_RELOC_16_PCREL_S2:
11732 if ((*valP & 0x3) != 0)
11733 as_bad_where (fixP->fx_file, fixP->fx_line,
11734 _("Branch to misaligned address (%lx)"), (long) *valP);
11737 * We need to save the bits in the instruction since fixup_segment()
11738 * might be deleting the relocation entry (i.e., a branch within
11739 * the current segment).
11741 if (! fixP->fx_done)
11744 /* update old instruction data */
11745 if (target_big_endian)
11746 insn = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
11748 insn = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
11750 if (*valP + 0x20000 <= 0x3ffff)
11752 insn |= (*valP >> 2) & 0xffff;
11753 md_number_to_chars ((char *) buf, insn, 4);
11755 else if (mips_pic == NO_PIC
11757 && fixP->fx_frag->fr_address >= text_section->vma
11758 && (fixP->fx_frag->fr_address
11759 < text_section->vma + bfd_get_section_size (text_section))
11760 && ((insn & 0xffff0000) == 0x10000000 /* beq $0,$0 */
11761 || (insn & 0xffff0000) == 0x04010000 /* bgez $0 */
11762 || (insn & 0xffff0000) == 0x04110000)) /* bgezal $0 */
11764 /* The branch offset is too large. If this is an
11765 unconditional branch, and we are not generating PIC code,
11766 we can convert it to an absolute jump instruction. */
11767 if ((insn & 0xffff0000) == 0x04110000) /* bgezal $0 */
11768 insn = 0x0c000000; /* jal */
11770 insn = 0x08000000; /* j */
11771 fixP->fx_r_type = BFD_RELOC_MIPS_JMP;
11773 fixP->fx_addsy = section_symbol (text_section);
11774 *valP += md_pcrel_from (fixP);
11775 md_number_to_chars ((char *) buf, insn, 4);
11779 /* If we got here, we have branch-relaxation disabled,
11780 and there's nothing we can do to fix this instruction
11781 without turning it into a longer sequence. */
11782 as_bad_where (fixP->fx_file, fixP->fx_line,
11783 _("Branch out of range"));
11787 case BFD_RELOC_VTABLE_INHERIT:
11790 && !S_IS_DEFINED (fixP->fx_addsy)
11791 && !S_IS_WEAK (fixP->fx_addsy))
11792 S_SET_WEAK (fixP->fx_addsy);
11795 case BFD_RELOC_VTABLE_ENTRY:
11803 /* Remember value for tc_gen_reloc. */
11804 fixP->fx_addnumber = *valP;
11814 name = input_line_pointer;
11815 c = get_symbol_end ();
11816 p = (symbolS *) symbol_find_or_make (name);
11817 *input_line_pointer = c;
11821 /* Align the current frag to a given power of two. The MIPS assembler
11822 also automatically adjusts any preceding label. */
11825 mips_align (int to, int fill, symbolS *label)
11827 mips_emit_delays ();
11828 frag_align (to, fill, 0);
11829 record_alignment (now_seg, to);
11832 assert (S_GET_SEGMENT (label) == now_seg);
11833 symbol_set_frag (label, frag_now);
11834 S_SET_VALUE (label, (valueT) frag_now_fix ());
11838 /* Align to a given power of two. .align 0 turns off the automatic
11839 alignment used by the data creating pseudo-ops. */
11842 s_align (int x ATTRIBUTE_UNUSED)
11845 register long temp_fill;
11846 long max_alignment = 15;
11850 o Note that the assembler pulls down any immediately preceding label
11851 to the aligned address.
11852 o It's not documented but auto alignment is reinstated by
11853 a .align pseudo instruction.
11854 o Note also that after auto alignment is turned off the mips assembler
11855 issues an error on attempt to assemble an improperly aligned data item.
11860 temp = get_absolute_expression ();
11861 if (temp > max_alignment)
11862 as_bad (_("Alignment too large: %d. assumed."), temp = max_alignment);
11865 as_warn (_("Alignment negative: 0 assumed."));
11868 if (*input_line_pointer == ',')
11870 ++input_line_pointer;
11871 temp_fill = get_absolute_expression ();
11878 mips_align (temp, (int) temp_fill,
11879 insn_labels != NULL ? insn_labels->label : NULL);
11886 demand_empty_rest_of_line ();
11890 s_change_sec (int sec)
11895 /* The ELF backend needs to know that we are changing sections, so
11896 that .previous works correctly. We could do something like check
11897 for an obj_section_change_hook macro, but that might be confusing
11898 as it would not be appropriate to use it in the section changing
11899 functions in read.c, since obj-elf.c intercepts those. FIXME:
11900 This should be cleaner, somehow. */
11901 obj_elf_section_change_hook ();
11904 mips_emit_delays ();
11914 subseg_set (bss_section, (subsegT) get_absolute_expression ());
11915 demand_empty_rest_of_line ();
11919 seg = subseg_new (RDATA_SECTION_NAME,
11920 (subsegT) get_absolute_expression ());
11921 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
11923 bfd_set_section_flags (stdoutput, seg, (SEC_ALLOC | SEC_LOAD
11924 | SEC_READONLY | SEC_RELOC
11926 if (strcmp (TARGET_OS, "elf") != 0)
11927 record_alignment (seg, 4);
11929 demand_empty_rest_of_line ();
11933 seg = subseg_new (".sdata", (subsegT) get_absolute_expression ());
11934 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
11936 bfd_set_section_flags (stdoutput, seg,
11937 SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_DATA);
11938 if (strcmp (TARGET_OS, "elf") != 0)
11939 record_alignment (seg, 4);
11941 demand_empty_rest_of_line ();
11949 s_change_section (int ignore ATTRIBUTE_UNUSED)
11952 char *section_name;
11957 int section_entry_size;
11958 int section_alignment;
11960 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
11963 section_name = input_line_pointer;
11964 c = get_symbol_end ();
11966 next_c = *(input_line_pointer + 1);
11968 /* Do we have .section Name<,"flags">? */
11969 if (c != ',' || (c == ',' && next_c == '"'))
11971 /* just after name is now '\0'. */
11972 *input_line_pointer = c;
11973 input_line_pointer = section_name;
11974 obj_elf_section (ignore);
11977 input_line_pointer++;
11979 /* Do we have .section Name<,type><,flag><,entry_size><,alignment> */
11981 section_type = get_absolute_expression ();
11984 if (*input_line_pointer++ == ',')
11985 section_flag = get_absolute_expression ();
11988 if (*input_line_pointer++ == ',')
11989 section_entry_size = get_absolute_expression ();
11991 section_entry_size = 0;
11992 if (*input_line_pointer++ == ',')
11993 section_alignment = get_absolute_expression ();
11995 section_alignment = 0;
11997 section_name = xstrdup (section_name);
11999 /* When using the generic form of .section (as implemented by obj-elf.c),
12000 there's no way to set the section type to SHT_MIPS_DWARF. Users have
12001 traditionally had to fall back on the more common @progbits instead.
12003 There's nothing really harmful in this, since bfd will correct
12004 SHT_PROGBITS to SHT_MIPS_DWARF before writing out the file. But it
12005 means that, for backwards compatibility, the special_section entries
12006 for dwarf sections must use SHT_PROGBITS rather than SHT_MIPS_DWARF.
12008 Even so, we shouldn't force users of the MIPS .section syntax to
12009 incorrectly label the sections as SHT_PROGBITS. The best compromise
12010 seems to be to map SHT_MIPS_DWARF to SHT_PROGBITS before calling the
12011 generic type-checking code. */
12012 if (section_type == SHT_MIPS_DWARF)
12013 section_type = SHT_PROGBITS;
12015 obj_elf_change_section (section_name, section_type, section_flag,
12016 section_entry_size, 0, 0, 0);
12018 if (now_seg->name != section_name)
12019 free (section_name);
12020 #endif /* OBJ_ELF */
12024 mips_enable_auto_align (void)
12030 s_cons (int log_size)
12034 label = insn_labels != NULL ? insn_labels->label : NULL;
12035 mips_emit_delays ();
12036 if (log_size > 0 && auto_align)
12037 mips_align (log_size, 0, label);
12038 mips_clear_insn_labels ();
12039 cons (1 << log_size);
12043 s_float_cons (int type)
12047 label = insn_labels != NULL ? insn_labels->label : NULL;
12049 mips_emit_delays ();
12054 mips_align (3, 0, label);
12056 mips_align (2, 0, label);
12059 mips_clear_insn_labels ();
12064 /* Handle .globl. We need to override it because on Irix 5 you are
12067 where foo is an undefined symbol, to mean that foo should be
12068 considered to be the address of a function. */
12071 s_mips_globl (int x ATTRIBUTE_UNUSED)
12080 name = input_line_pointer;
12081 c = get_symbol_end ();
12082 symbolP = symbol_find_or_make (name);
12083 S_SET_EXTERNAL (symbolP);
12085 *input_line_pointer = c;
12086 SKIP_WHITESPACE ();
12088 /* On Irix 5, every global symbol that is not explicitly labelled as
12089 being a function is apparently labelled as being an object. */
12092 if (!is_end_of_line[(unsigned char) *input_line_pointer]
12093 && (*input_line_pointer != ','))
12098 secname = input_line_pointer;
12099 c = get_symbol_end ();
12100 sec = bfd_get_section_by_name (stdoutput, secname);
12102 as_bad (_("%s: no such section"), secname);
12103 *input_line_pointer = c;
12105 if (sec != NULL && (sec->flags & SEC_CODE) != 0)
12106 flag = BSF_FUNCTION;
12109 symbol_get_bfdsym (symbolP)->flags |= flag;
12111 c = *input_line_pointer;
12114 input_line_pointer++;
12115 SKIP_WHITESPACE ();
12116 if (is_end_of_line[(unsigned char) *input_line_pointer])
12122 demand_empty_rest_of_line ();
12126 s_option (int x ATTRIBUTE_UNUSED)
12131 opt = input_line_pointer;
12132 c = get_symbol_end ();
12136 /* FIXME: What does this mean? */
12138 else if (strncmp (opt, "pic", 3) == 0)
12142 i = atoi (opt + 3);
12147 mips_pic = SVR4_PIC;
12148 mips_abicalls = TRUE;
12151 as_bad (_(".option pic%d not supported"), i);
12153 if (mips_pic == SVR4_PIC)
12155 if (g_switch_seen && g_switch_value != 0)
12156 as_warn (_("-G may not be used with SVR4 PIC code"));
12157 g_switch_value = 0;
12158 bfd_set_gp_size (stdoutput, 0);
12162 as_warn (_("Unrecognized option \"%s\""), opt);
12164 *input_line_pointer = c;
12165 demand_empty_rest_of_line ();
12168 /* This structure is used to hold a stack of .set values. */
12170 struct mips_option_stack
12172 struct mips_option_stack *next;
12173 struct mips_set_options options;
12176 static struct mips_option_stack *mips_opts_stack;
12178 /* Handle the .set pseudo-op. */
12181 s_mipsset (int x ATTRIBUTE_UNUSED)
12183 char *name = input_line_pointer, ch;
12185 while (!is_end_of_line[(unsigned char) *input_line_pointer])
12186 ++input_line_pointer;
12187 ch = *input_line_pointer;
12188 *input_line_pointer = '\0';
12190 if (strcmp (name, "reorder") == 0)
12192 if (mips_opts.noreorder)
12195 else if (strcmp (name, "noreorder") == 0)
12197 if (!mips_opts.noreorder)
12198 start_noreorder ();
12200 else if (strcmp (name, "at") == 0)
12202 mips_opts.noat = 0;
12204 else if (strcmp (name, "noat") == 0)
12206 mips_opts.noat = 1;
12208 else if (strcmp (name, "macro") == 0)
12210 mips_opts.warn_about_macros = 0;
12212 else if (strcmp (name, "nomacro") == 0)
12214 if (mips_opts.noreorder == 0)
12215 as_bad (_("`noreorder' must be set before `nomacro'"));
12216 mips_opts.warn_about_macros = 1;
12218 else if (strcmp (name, "move") == 0 || strcmp (name, "novolatile") == 0)
12220 mips_opts.nomove = 0;
12222 else if (strcmp (name, "nomove") == 0 || strcmp (name, "volatile") == 0)
12224 mips_opts.nomove = 1;
12226 else if (strcmp (name, "bopt") == 0)
12228 mips_opts.nobopt = 0;
12230 else if (strcmp (name, "nobopt") == 0)
12232 mips_opts.nobopt = 1;
12234 else if (strcmp (name, "mips16") == 0
12235 || strcmp (name, "MIPS-16") == 0)
12236 mips_opts.mips16 = 1;
12237 else if (strcmp (name, "nomips16") == 0
12238 || strcmp (name, "noMIPS-16") == 0)
12239 mips_opts.mips16 = 0;
12240 else if (strcmp (name, "smartmips") == 0)
12242 if (!ISA_SUPPORT_SMARTMIPS)
12243 as_warn ("%s ISA does not support SmartMIPS ASE",
12244 mips_cpu_info_from_isa (mips_opts.isa)->name);
12245 mips_opts.ase_smartmips = 1;
12247 else if (strcmp (name, "nosmartmips") == 0)
12248 mips_opts.ase_smartmips = 0;
12249 else if (strcmp (name, "mips3d") == 0)
12250 mips_opts.ase_mips3d = 1;
12251 else if (strcmp (name, "nomips3d") == 0)
12252 mips_opts.ase_mips3d = 0;
12253 else if (strcmp (name, "mdmx") == 0)
12254 mips_opts.ase_mdmx = 1;
12255 else if (strcmp (name, "nomdmx") == 0)
12256 mips_opts.ase_mdmx = 0;
12257 else if (strcmp (name, "dsp") == 0)
12258 mips_opts.ase_dsp = 1;
12259 else if (strcmp (name, "nodsp") == 0)
12260 mips_opts.ase_dsp = 0;
12261 else if (strcmp (name, "mt") == 0)
12262 mips_opts.ase_mt = 1;
12263 else if (strcmp (name, "nomt") == 0)
12264 mips_opts.ase_mt = 0;
12265 else if (strncmp (name, "mips", 4) == 0 || strncmp (name, "arch=", 5) == 0)
12269 /* Permit the user to change the ISA and architecture on the fly.
12270 Needless to say, misuse can cause serious problems. */
12271 if (strcmp (name, "mips0") == 0 || strcmp (name, "arch=default") == 0)
12274 mips_opts.isa = file_mips_isa;
12275 mips_opts.arch = file_mips_arch;
12277 else if (strncmp (name, "arch=", 5) == 0)
12279 const struct mips_cpu_info *p;
12281 p = mips_parse_cpu("internal use", name + 5);
12283 as_bad (_("unknown architecture %s"), name + 5);
12286 mips_opts.arch = p->cpu;
12287 mips_opts.isa = p->isa;
12290 else if (strncmp (name, "mips", 4) == 0)
12292 const struct mips_cpu_info *p;
12294 p = mips_parse_cpu("internal use", name);
12296 as_bad (_("unknown ISA level %s"), name + 4);
12299 mips_opts.arch = p->cpu;
12300 mips_opts.isa = p->isa;
12304 as_bad (_("unknown ISA or architecture %s"), name);
12306 switch (mips_opts.isa)
12314 mips_opts.gp32 = 1;
12315 mips_opts.fp32 = 1;
12322 mips_opts.gp32 = 0;
12323 mips_opts.fp32 = 0;
12326 as_bad (_("unknown ISA level %s"), name + 4);
12331 mips_opts.gp32 = file_mips_gp32;
12332 mips_opts.fp32 = file_mips_fp32;
12335 else if (strcmp (name, "autoextend") == 0)
12336 mips_opts.noautoextend = 0;
12337 else if (strcmp (name, "noautoextend") == 0)
12338 mips_opts.noautoextend = 1;
12339 else if (strcmp (name, "push") == 0)
12341 struct mips_option_stack *s;
12343 s = (struct mips_option_stack *) xmalloc (sizeof *s);
12344 s->next = mips_opts_stack;
12345 s->options = mips_opts;
12346 mips_opts_stack = s;
12348 else if (strcmp (name, "pop") == 0)
12350 struct mips_option_stack *s;
12352 s = mips_opts_stack;
12354 as_bad (_(".set pop with no .set push"));
12357 /* If we're changing the reorder mode we need to handle
12358 delay slots correctly. */
12359 if (s->options.noreorder && ! mips_opts.noreorder)
12360 start_noreorder ();
12361 else if (! s->options.noreorder && mips_opts.noreorder)
12364 mips_opts = s->options;
12365 mips_opts_stack = s->next;
12369 else if (strcmp (name, "sym32") == 0)
12370 mips_opts.sym32 = TRUE;
12371 else if (strcmp (name, "nosym32") == 0)
12372 mips_opts.sym32 = FALSE;
12375 as_warn (_("Tried to set unrecognized symbol: %s\n"), name);
12377 *input_line_pointer = ch;
12378 demand_empty_rest_of_line ();
12381 /* Handle the .abicalls pseudo-op. I believe this is equivalent to
12382 .option pic2. It means to generate SVR4 PIC calls. */
12385 s_abicalls (int ignore ATTRIBUTE_UNUSED)
12387 mips_pic = SVR4_PIC;
12388 mips_abicalls = TRUE;
12390 if (g_switch_seen && g_switch_value != 0)
12391 as_warn (_("-G may not be used with SVR4 PIC code"));
12392 g_switch_value = 0;
12394 bfd_set_gp_size (stdoutput, 0);
12395 demand_empty_rest_of_line ();
12398 /* Handle the .cpload pseudo-op. This is used when generating SVR4
12399 PIC code. It sets the $gp register for the function based on the
12400 function address, which is in the register named in the argument.
12401 This uses a relocation against _gp_disp, which is handled specially
12402 by the linker. The result is:
12403 lui $gp,%hi(_gp_disp)
12404 addiu $gp,$gp,%lo(_gp_disp)
12405 addu $gp,$gp,.cpload argument
12406 The .cpload argument is normally $25 == $t9.
12408 The -mno-shared option changes this to:
12409 lui $gp,%hi(__gnu_local_gp)
12410 addiu $gp,$gp,%lo(__gnu_local_gp)
12411 and the argument is ignored. This saves an instruction, but the
12412 resulting code is not position independent; it uses an absolute
12413 address for __gnu_local_gp. Thus code assembled with -mno-shared
12414 can go into an ordinary executable, but not into a shared library. */
12417 s_cpload (int ignore ATTRIBUTE_UNUSED)
12423 /* If we are not generating SVR4 PIC code, or if this is NewABI code,
12424 .cpload is ignored. */
12425 if (mips_pic != SVR4_PIC || HAVE_NEWABI)
12431 /* .cpload should be in a .set noreorder section. */
12432 if (mips_opts.noreorder == 0)
12433 as_warn (_(".cpload not in noreorder section"));
12435 reg = tc_get_register (0);
12437 /* If we need to produce a 64-bit address, we are better off using
12438 the default instruction sequence. */
12439 in_shared = mips_in_shared || HAVE_64BIT_SYMBOLS;
12441 ex.X_op = O_symbol;
12442 ex.X_add_symbol = symbol_find_or_make (in_shared ? "_gp_disp" :
12444 ex.X_op_symbol = NULL;
12445 ex.X_add_number = 0;
12447 /* In ELF, this symbol is implicitly an STT_OBJECT symbol. */
12448 symbol_get_bfdsym (ex.X_add_symbol)->flags |= BSF_OBJECT;
12451 macro_build_lui (&ex, mips_gp_register);
12452 macro_build (&ex, "addiu", "t,r,j", mips_gp_register,
12453 mips_gp_register, BFD_RELOC_LO16);
12455 macro_build (NULL, "addu", "d,v,t", mips_gp_register,
12456 mips_gp_register, reg);
12459 demand_empty_rest_of_line ();
12462 /* Handle the .cpsetup pseudo-op defined for NewABI PIC code. The syntax is:
12463 .cpsetup $reg1, offset|$reg2, label
12465 If offset is given, this results in:
12466 sd $gp, offset($sp)
12467 lui $gp, %hi(%neg(%gp_rel(label)))
12468 addiu $gp, $gp, %lo(%neg(%gp_rel(label)))
12469 daddu $gp, $gp, $reg1
12471 If $reg2 is given, this results in:
12472 daddu $reg2, $gp, $0
12473 lui $gp, %hi(%neg(%gp_rel(label)))
12474 addiu $gp, $gp, %lo(%neg(%gp_rel(label)))
12475 daddu $gp, $gp, $reg1
12476 $reg1 is normally $25 == $t9.
12478 The -mno-shared option replaces the last three instructions with
12480 addiu $gp,$gp,%lo(_gp)
12484 s_cpsetup (int ignore ATTRIBUTE_UNUSED)
12486 expressionS ex_off;
12487 expressionS ex_sym;
12490 /* If we are not generating SVR4 PIC code, .cpsetup is ignored.
12491 We also need NewABI support. */
12492 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
12498 reg1 = tc_get_register (0);
12499 SKIP_WHITESPACE ();
12500 if (*input_line_pointer != ',')
12502 as_bad (_("missing argument separator ',' for .cpsetup"));
12506 ++input_line_pointer;
12507 SKIP_WHITESPACE ();
12508 if (*input_line_pointer == '$')
12510 mips_cpreturn_register = tc_get_register (0);
12511 mips_cpreturn_offset = -1;
12515 mips_cpreturn_offset = get_absolute_expression ();
12516 mips_cpreturn_register = -1;
12518 SKIP_WHITESPACE ();
12519 if (*input_line_pointer != ',')
12521 as_bad (_("missing argument separator ',' for .cpsetup"));
12525 ++input_line_pointer;
12526 SKIP_WHITESPACE ();
12527 expression (&ex_sym);
12530 if (mips_cpreturn_register == -1)
12532 ex_off.X_op = O_constant;
12533 ex_off.X_add_symbol = NULL;
12534 ex_off.X_op_symbol = NULL;
12535 ex_off.X_add_number = mips_cpreturn_offset;
12537 macro_build (&ex_off, "sd", "t,o(b)", mips_gp_register,
12538 BFD_RELOC_LO16, SP);
12541 macro_build (NULL, "daddu", "d,v,t", mips_cpreturn_register,
12542 mips_gp_register, 0);
12544 if (mips_in_shared || HAVE_64BIT_SYMBOLS)
12546 macro_build (&ex_sym, "lui", "t,u", mips_gp_register,
12547 -1, BFD_RELOC_GPREL16, BFD_RELOC_MIPS_SUB,
12550 macro_build (&ex_sym, "addiu", "t,r,j", mips_gp_register,
12551 mips_gp_register, -1, BFD_RELOC_GPREL16,
12552 BFD_RELOC_MIPS_SUB, BFD_RELOC_LO16);
12554 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", mips_gp_register,
12555 mips_gp_register, reg1);
12561 ex.X_op = O_symbol;
12562 ex.X_add_symbol = symbol_find_or_make ("__gnu_local_gp");
12563 ex.X_op_symbol = NULL;
12564 ex.X_add_number = 0;
12566 /* In ELF, this symbol is implicitly an STT_OBJECT symbol. */
12567 symbol_get_bfdsym (ex.X_add_symbol)->flags |= BSF_OBJECT;
12569 macro_build_lui (&ex, mips_gp_register);
12570 macro_build (&ex, "addiu", "t,r,j", mips_gp_register,
12571 mips_gp_register, BFD_RELOC_LO16);
12576 demand_empty_rest_of_line ();
12580 s_cplocal (int ignore ATTRIBUTE_UNUSED)
12582 /* If we are not generating SVR4 PIC code, or if this is not NewABI code,
12583 .cplocal is ignored. */
12584 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
12590 mips_gp_register = tc_get_register (0);
12591 demand_empty_rest_of_line ();
12594 /* Handle the .cprestore pseudo-op. This stores $gp into a given
12595 offset from $sp. The offset is remembered, and after making a PIC
12596 call $gp is restored from that location. */
12599 s_cprestore (int ignore ATTRIBUTE_UNUSED)
12603 /* If we are not generating SVR4 PIC code, or if this is NewABI code,
12604 .cprestore is ignored. */
12605 if (mips_pic != SVR4_PIC || HAVE_NEWABI)
12611 mips_cprestore_offset = get_absolute_expression ();
12612 mips_cprestore_valid = 1;
12614 ex.X_op = O_constant;
12615 ex.X_add_symbol = NULL;
12616 ex.X_op_symbol = NULL;
12617 ex.X_add_number = mips_cprestore_offset;
12620 macro_build_ldst_constoffset (&ex, ADDRESS_STORE_INSN, mips_gp_register,
12621 SP, HAVE_64BIT_ADDRESSES);
12624 demand_empty_rest_of_line ();
12627 /* Handle the .cpreturn pseudo-op defined for NewABI PIC code. If an offset
12628 was given in the preceding .cpsetup, it results in:
12629 ld $gp, offset($sp)
12631 If a register $reg2 was given there, it results in:
12632 daddu $gp, $reg2, $0
12635 s_cpreturn (int ignore ATTRIBUTE_UNUSED)
12639 /* If we are not generating SVR4 PIC code, .cpreturn is ignored.
12640 We also need NewABI support. */
12641 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
12648 if (mips_cpreturn_register == -1)
12650 ex.X_op = O_constant;
12651 ex.X_add_symbol = NULL;
12652 ex.X_op_symbol = NULL;
12653 ex.X_add_number = mips_cpreturn_offset;
12655 macro_build (&ex, "ld", "t,o(b)", mips_gp_register, BFD_RELOC_LO16, SP);
12658 macro_build (NULL, "daddu", "d,v,t", mips_gp_register,
12659 mips_cpreturn_register, 0);
12662 demand_empty_rest_of_line ();
12665 /* Handle the .gpvalue pseudo-op. This is used when generating NewABI PIC
12666 code. It sets the offset to use in gp_rel relocations. */
12669 s_gpvalue (int ignore ATTRIBUTE_UNUSED)
12671 /* If we are not generating SVR4 PIC code, .gpvalue is ignored.
12672 We also need NewABI support. */
12673 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
12679 mips_gprel_offset = get_absolute_expression ();
12681 demand_empty_rest_of_line ();
12684 /* Handle the .gpword pseudo-op. This is used when generating PIC
12685 code. It generates a 32 bit GP relative reloc. */
12688 s_gpword (int ignore ATTRIBUTE_UNUSED)
12694 /* When not generating PIC code, this is treated as .word. */
12695 if (mips_pic != SVR4_PIC)
12701 label = insn_labels != NULL ? insn_labels->label : NULL;
12702 mips_emit_delays ();
12704 mips_align (2, 0, label);
12705 mips_clear_insn_labels ();
12709 if (ex.X_op != O_symbol || ex.X_add_number != 0)
12711 as_bad (_("Unsupported use of .gpword"));
12712 ignore_rest_of_line ();
12716 md_number_to_chars (p, 0, 4);
12717 fix_new_exp (frag_now, p - frag_now->fr_literal, 4, &ex, FALSE,
12718 BFD_RELOC_GPREL32);
12720 demand_empty_rest_of_line ();
12724 s_gpdword (int ignore ATTRIBUTE_UNUSED)
12730 /* When not generating PIC code, this is treated as .dword. */
12731 if (mips_pic != SVR4_PIC)
12737 label = insn_labels != NULL ? insn_labels->label : NULL;
12738 mips_emit_delays ();
12740 mips_align (3, 0, label);
12741 mips_clear_insn_labels ();
12745 if (ex.X_op != O_symbol || ex.X_add_number != 0)
12747 as_bad (_("Unsupported use of .gpdword"));
12748 ignore_rest_of_line ();
12752 md_number_to_chars (p, 0, 8);
12753 fix_new_exp (frag_now, p - frag_now->fr_literal, 4, &ex, FALSE,
12754 BFD_RELOC_GPREL32)->fx_tcbit = 1;
12756 /* GPREL32 composed with 64 gives a 64-bit GP offset. */
12757 fix_new (frag_now, p - frag_now->fr_literal, 8, NULL, 0,
12758 FALSE, BFD_RELOC_64)->fx_tcbit = 1;
12760 demand_empty_rest_of_line ();
12763 /* Handle the .cpadd pseudo-op. This is used when dealing with switch
12764 tables in SVR4 PIC code. */
12767 s_cpadd (int ignore ATTRIBUTE_UNUSED)
12771 /* This is ignored when not generating SVR4 PIC code. */
12772 if (mips_pic != SVR4_PIC)
12778 /* Add $gp to the register named as an argument. */
12780 reg = tc_get_register (0);
12781 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", reg, reg, mips_gp_register);
12784 demand_empty_rest_of_line ();
12787 /* Handle the .insn pseudo-op. This marks instruction labels in
12788 mips16 mode. This permits the linker to handle them specially,
12789 such as generating jalx instructions when needed. We also make
12790 them odd for the duration of the assembly, in order to generate the
12791 right sort of code. We will make them even in the adjust_symtab
12792 routine, while leaving them marked. This is convenient for the
12793 debugger and the disassembler. The linker knows to make them odd
12797 s_insn (int ignore ATTRIBUTE_UNUSED)
12799 mips16_mark_labels ();
12801 demand_empty_rest_of_line ();
12804 /* Handle a .stabn directive. We need these in order to mark a label
12805 as being a mips16 text label correctly. Sometimes the compiler
12806 will emit a label, followed by a .stabn, and then switch sections.
12807 If the label and .stabn are in mips16 mode, then the label is
12808 really a mips16 text label. */
12811 s_mips_stab (int type)
12814 mips16_mark_labels ();
12819 /* Handle the .weakext pseudo-op as defined in Kane and Heinrich.
12823 s_mips_weakext (int ignore ATTRIBUTE_UNUSED)
12830 name = input_line_pointer;
12831 c = get_symbol_end ();
12832 symbolP = symbol_find_or_make (name);
12833 S_SET_WEAK (symbolP);
12834 *input_line_pointer = c;
12836 SKIP_WHITESPACE ();
12838 if (! is_end_of_line[(unsigned char) *input_line_pointer])
12840 if (S_IS_DEFINED (symbolP))
12842 as_bad ("ignoring attempt to redefine symbol %s",
12843 S_GET_NAME (symbolP));
12844 ignore_rest_of_line ();
12848 if (*input_line_pointer == ',')
12850 ++input_line_pointer;
12851 SKIP_WHITESPACE ();
12855 if (exp.X_op != O_symbol)
12857 as_bad ("bad .weakext directive");
12858 ignore_rest_of_line ();
12861 symbol_set_value_expression (symbolP, &exp);
12864 demand_empty_rest_of_line ();
12867 /* Parse a register string into a number. Called from the ECOFF code
12868 to parse .frame. The argument is non-zero if this is the frame
12869 register, so that we can record it in mips_frame_reg. */
12872 tc_get_register (int frame)
12876 SKIP_WHITESPACE ();
12877 if (! reg_lookup (&input_line_pointer, RWARN | RTYPE_NUM | RTYPE_GP, ®))
12881 mips_frame_reg = reg != 0 ? reg : SP;
12882 mips_frame_reg_valid = 1;
12883 mips_cprestore_valid = 0;
12889 md_section_align (asection *seg, valueT addr)
12891 int align = bfd_get_section_alignment (stdoutput, seg);
12894 /* We don't need to align ELF sections to the full alignment.
12895 However, Irix 5 may prefer that we align them at least to a 16
12896 byte boundary. We don't bother to align the sections if we are
12897 targeted for an embedded system. */
12898 if (strcmp (TARGET_OS, "elf") == 0)
12904 return ((addr + (1 << align) - 1) & (-1 << align));
12907 /* Utility routine, called from above as well. If called while the
12908 input file is still being read, it's only an approximation. (For
12909 example, a symbol may later become defined which appeared to be
12910 undefined earlier.) */
12913 nopic_need_relax (symbolS *sym, int before_relaxing)
12918 if (g_switch_value > 0)
12920 const char *symname;
12923 /* Find out whether this symbol can be referenced off the $gp
12924 register. It can be if it is smaller than the -G size or if
12925 it is in the .sdata or .sbss section. Certain symbols can
12926 not be referenced off the $gp, although it appears as though
12928 symname = S_GET_NAME (sym);
12929 if (symname != (const char *) NULL
12930 && (strcmp (symname, "eprol") == 0
12931 || strcmp (symname, "etext") == 0
12932 || strcmp (symname, "_gp") == 0
12933 || strcmp (symname, "edata") == 0
12934 || strcmp (symname, "_fbss") == 0
12935 || strcmp (symname, "_fdata") == 0
12936 || strcmp (symname, "_ftext") == 0
12937 || strcmp (symname, "end") == 0
12938 || strcmp (symname, "_gp_disp") == 0))
12940 else if ((! S_IS_DEFINED (sym) || S_IS_COMMON (sym))
12942 #ifndef NO_ECOFF_DEBUGGING
12943 || (symbol_get_obj (sym)->ecoff_extern_size != 0
12944 && (symbol_get_obj (sym)->ecoff_extern_size
12945 <= g_switch_value))
12947 /* We must defer this decision until after the whole
12948 file has been read, since there might be a .extern
12949 after the first use of this symbol. */
12950 || (before_relaxing
12951 #ifndef NO_ECOFF_DEBUGGING
12952 && symbol_get_obj (sym)->ecoff_extern_size == 0
12954 && S_GET_VALUE (sym) == 0)
12955 || (S_GET_VALUE (sym) != 0
12956 && S_GET_VALUE (sym) <= g_switch_value)))
12960 const char *segname;
12962 segname = segment_name (S_GET_SEGMENT (sym));
12963 assert (strcmp (segname, ".lit8") != 0
12964 && strcmp (segname, ".lit4") != 0);
12965 change = (strcmp (segname, ".sdata") != 0
12966 && strcmp (segname, ".sbss") != 0
12967 && strncmp (segname, ".sdata.", 7) != 0
12968 && strncmp (segname, ".gnu.linkonce.s.", 16) != 0);
12973 /* We are not optimizing for the $gp register. */
12978 /* Return true if the given symbol should be considered local for SVR4 PIC. */
12981 pic_need_relax (symbolS *sym, asection *segtype)
12984 bfd_boolean linkonce;
12986 /* Handle the case of a symbol equated to another symbol. */
12987 while (symbol_equated_reloc_p (sym))
12991 /* It's possible to get a loop here in a badly written
12993 n = symbol_get_value_expression (sym)->X_add_symbol;
12999 symsec = S_GET_SEGMENT (sym);
13001 /* duplicate the test for LINK_ONCE sections as in adjust_reloc_syms */
13003 if (symsec != segtype && ! S_IS_LOCAL (sym))
13005 if ((bfd_get_section_flags (stdoutput, symsec) & SEC_LINK_ONCE)
13009 /* The GNU toolchain uses an extension for ELF: a section
13010 beginning with the magic string .gnu.linkonce is a linkonce
13012 if (strncmp (segment_name (symsec), ".gnu.linkonce",
13013 sizeof ".gnu.linkonce" - 1) == 0)
13017 /* This must duplicate the test in adjust_reloc_syms. */
13018 return (symsec != &bfd_und_section
13019 && symsec != &bfd_abs_section
13020 && ! bfd_is_com_section (symsec)
13023 /* A global or weak symbol is treated as external. */
13024 && (OUTPUT_FLAVOR != bfd_target_elf_flavour
13025 || (! S_IS_WEAK (sym) && ! S_IS_EXTERNAL (sym)))
13031 /* Given a mips16 variant frag FRAGP, return non-zero if it needs an
13032 extended opcode. SEC is the section the frag is in. */
13035 mips16_extended_frag (fragS *fragp, asection *sec, long stretch)
13038 register const struct mips16_immed_operand *op;
13040 int mintiny, maxtiny;
13044 if (RELAX_MIPS16_USER_SMALL (fragp->fr_subtype))
13046 if (RELAX_MIPS16_USER_EXT (fragp->fr_subtype))
13049 type = RELAX_MIPS16_TYPE (fragp->fr_subtype);
13050 op = mips16_immed_operands;
13051 while (op->type != type)
13054 assert (op < mips16_immed_operands + MIPS16_NUM_IMMED);
13059 if (type == '<' || type == '>' || type == '[' || type == ']')
13062 maxtiny = 1 << op->nbits;
13067 maxtiny = (1 << op->nbits) - 1;
13072 mintiny = - (1 << (op->nbits - 1));
13073 maxtiny = (1 << (op->nbits - 1)) - 1;
13076 sym_frag = symbol_get_frag (fragp->fr_symbol);
13077 val = S_GET_VALUE (fragp->fr_symbol);
13078 symsec = S_GET_SEGMENT (fragp->fr_symbol);
13084 /* We won't have the section when we are called from
13085 mips_relax_frag. However, we will always have been called
13086 from md_estimate_size_before_relax first. If this is a
13087 branch to a different section, we mark it as such. If SEC is
13088 NULL, and the frag is not marked, then it must be a branch to
13089 the same section. */
13092 if (RELAX_MIPS16_LONG_BRANCH (fragp->fr_subtype))
13097 /* Must have been called from md_estimate_size_before_relax. */
13100 fragp->fr_subtype =
13101 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
13103 /* FIXME: We should support this, and let the linker
13104 catch branches and loads that are out of range. */
13105 as_bad_where (fragp->fr_file, fragp->fr_line,
13106 _("unsupported PC relative reference to different section"));
13110 if (fragp != sym_frag && sym_frag->fr_address == 0)
13111 /* Assume non-extended on the first relaxation pass.
13112 The address we have calculated will be bogus if this is
13113 a forward branch to another frag, as the forward frag
13114 will have fr_address == 0. */
13118 /* In this case, we know for sure that the symbol fragment is in
13119 the same section. If the relax_marker of the symbol fragment
13120 differs from the relax_marker of this fragment, we have not
13121 yet adjusted the symbol fragment fr_address. We want to add
13122 in STRETCH in order to get a better estimate of the address.
13123 This particularly matters because of the shift bits. */
13125 && sym_frag->relax_marker != fragp->relax_marker)
13129 /* Adjust stretch for any alignment frag. Note that if have
13130 been expanding the earlier code, the symbol may be
13131 defined in what appears to be an earlier frag. FIXME:
13132 This doesn't handle the fr_subtype field, which specifies
13133 a maximum number of bytes to skip when doing an
13135 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
13137 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
13140 stretch = - ((- stretch)
13141 & ~ ((1 << (int) f->fr_offset) - 1));
13143 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
13152 addr = fragp->fr_address + fragp->fr_fix;
13154 /* The base address rules are complicated. The base address of
13155 a branch is the following instruction. The base address of a
13156 PC relative load or add is the instruction itself, but if it
13157 is in a delay slot (in which case it can not be extended) use
13158 the address of the instruction whose delay slot it is in. */
13159 if (type == 'p' || type == 'q')
13163 /* If we are currently assuming that this frag should be
13164 extended, then, the current address is two bytes
13166 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
13169 /* Ignore the low bit in the target, since it will be set
13170 for a text label. */
13171 if ((val & 1) != 0)
13174 else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype))
13176 else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype))
13179 val -= addr & ~ ((1 << op->shift) - 1);
13181 /* Branch offsets have an implicit 0 in the lowest bit. */
13182 if (type == 'p' || type == 'q')
13185 /* If any of the shifted bits are set, we must use an extended
13186 opcode. If the address depends on the size of this
13187 instruction, this can lead to a loop, so we arrange to always
13188 use an extended opcode. We only check this when we are in
13189 the main relaxation loop, when SEC is NULL. */
13190 if ((val & ((1 << op->shift) - 1)) != 0 && sec == NULL)
13192 fragp->fr_subtype =
13193 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
13197 /* If we are about to mark a frag as extended because the value
13198 is precisely maxtiny + 1, then there is a chance of an
13199 infinite loop as in the following code:
13204 In this case when the la is extended, foo is 0x3fc bytes
13205 away, so the la can be shrunk, but then foo is 0x400 away, so
13206 the la must be extended. To avoid this loop, we mark the
13207 frag as extended if it was small, and is about to become
13208 extended with a value of maxtiny + 1. */
13209 if (val == ((maxtiny + 1) << op->shift)
13210 && ! RELAX_MIPS16_EXTENDED (fragp->fr_subtype)
13213 fragp->fr_subtype =
13214 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
13218 else if (symsec != absolute_section && sec != NULL)
13219 as_bad_where (fragp->fr_file, fragp->fr_line, _("unsupported relocation"));
13221 if ((val & ((1 << op->shift) - 1)) != 0
13222 || val < (mintiny << op->shift)
13223 || val > (maxtiny << op->shift))
13229 /* Compute the length of a branch sequence, and adjust the
13230 RELAX_BRANCH_TOOFAR bit accordingly. If FRAGP is NULL, the
13231 worst-case length is computed, with UPDATE being used to indicate
13232 whether an unconditional (-1), branch-likely (+1) or regular (0)
13233 branch is to be computed. */
13235 relaxed_branch_length (fragS *fragp, asection *sec, int update)
13237 bfd_boolean toofar;
13241 && S_IS_DEFINED (fragp->fr_symbol)
13242 && sec == S_GET_SEGMENT (fragp->fr_symbol))
13247 val = S_GET_VALUE (fragp->fr_symbol) + fragp->fr_offset;
13249 addr = fragp->fr_address + fragp->fr_fix + 4;
13253 toofar = val < - (0x8000 << 2) || val >= (0x8000 << 2);
13256 /* If the symbol is not defined or it's in a different segment,
13257 assume the user knows what's going on and emit a short
13263 if (fragp && update && toofar != RELAX_BRANCH_TOOFAR (fragp->fr_subtype))
13265 = RELAX_BRANCH_ENCODE (RELAX_BRANCH_UNCOND (fragp->fr_subtype),
13266 RELAX_BRANCH_LIKELY (fragp->fr_subtype),
13267 RELAX_BRANCH_LINK (fragp->fr_subtype),
13273 if (fragp ? RELAX_BRANCH_LIKELY (fragp->fr_subtype) : (update > 0))
13276 if (mips_pic != NO_PIC)
13278 /* Additional space for PIC loading of target address. */
13280 if (mips_opts.isa == ISA_MIPS1)
13281 /* Additional space for $at-stabilizing nop. */
13285 /* If branch is conditional. */
13286 if (fragp ? !RELAX_BRANCH_UNCOND (fragp->fr_subtype) : (update >= 0))
13293 /* Estimate the size of a frag before relaxing. Unless this is the
13294 mips16, we are not really relaxing here, and the final size is
13295 encoded in the subtype information. For the mips16, we have to
13296 decide whether we are using an extended opcode or not. */
13299 md_estimate_size_before_relax (fragS *fragp, asection *segtype)
13303 if (RELAX_BRANCH_P (fragp->fr_subtype))
13306 fragp->fr_var = relaxed_branch_length (fragp, segtype, FALSE);
13308 return fragp->fr_var;
13311 if (RELAX_MIPS16_P (fragp->fr_subtype))
13312 /* We don't want to modify the EXTENDED bit here; it might get us
13313 into infinite loops. We change it only in mips_relax_frag(). */
13314 return (RELAX_MIPS16_EXTENDED (fragp->fr_subtype) ? 4 : 2);
13316 if (mips_pic == NO_PIC)
13317 change = nopic_need_relax (fragp->fr_symbol, 0);
13318 else if (mips_pic == SVR4_PIC)
13319 change = pic_need_relax (fragp->fr_symbol, segtype);
13320 else if (mips_pic == VXWORKS_PIC)
13321 /* For vxworks, GOT16 relocations never have a corresponding LO16. */
13328 fragp->fr_subtype |= RELAX_USE_SECOND;
13329 return -RELAX_FIRST (fragp->fr_subtype);
13332 return -RELAX_SECOND (fragp->fr_subtype);
13335 /* This is called to see whether a reloc against a defined symbol
13336 should be converted into a reloc against a section. */
13339 mips_fix_adjustable (fixS *fixp)
13341 /* Don't adjust MIPS16 jump relocations, so we don't have to worry
13342 about the format of the offset in the .o file. */
13343 if (fixp->fx_r_type == BFD_RELOC_MIPS16_JMP)
13346 if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT
13347 || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
13350 if (fixp->fx_addsy == NULL)
13353 /* If symbol SYM is in a mergeable section, relocations of the form
13354 SYM + 0 can usually be made section-relative. The mergeable data
13355 is then identified by the section offset rather than by the symbol.
13357 However, if we're generating REL LO16 relocations, the offset is split
13358 between the LO16 and parterning high part relocation. The linker will
13359 need to recalculate the complete offset in order to correctly identify
13362 The linker has traditionally not looked for the parterning high part
13363 relocation, and has thus allowed orphaned R_MIPS_LO16 relocations to be
13364 placed anywhere. Rather than break backwards compatibility by changing
13365 this, it seems better not to force the issue, and instead keep the
13366 original symbol. This will work with either linker behavior. */
13367 if ((fixp->fx_r_type == BFD_RELOC_LO16
13368 || fixp->fx_r_type == BFD_RELOC_MIPS16_LO16
13369 || reloc_needs_lo_p (fixp->fx_r_type))
13370 && HAVE_IN_PLACE_ADDENDS
13371 && (S_GET_SEGMENT (fixp->fx_addsy)->flags & SEC_MERGE) != 0)
13375 /* Don't adjust relocations against mips16 symbols, so that the linker
13376 can find them if it needs to set up a stub. */
13377 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
13378 && S_GET_OTHER (fixp->fx_addsy) == STO_MIPS16
13379 && fixp->fx_subsy == NULL)
13386 /* Translate internal representation of relocation info to BFD target
13390 tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixp)
13392 static arelent *retval[4];
13394 bfd_reloc_code_real_type code;
13396 memset (retval, 0, sizeof(retval));
13397 reloc = retval[0] = (arelent *) xcalloc (1, sizeof (arelent));
13398 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
13399 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
13400 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
13402 if (fixp->fx_pcrel)
13404 assert (fixp->fx_r_type == BFD_RELOC_16_PCREL_S2);
13406 /* At this point, fx_addnumber is "symbol offset - pcrel address".
13407 Relocations want only the symbol offset. */
13408 reloc->addend = fixp->fx_addnumber + reloc->address;
13409 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
13411 /* A gruesome hack which is a result of the gruesome gas
13412 reloc handling. What's worse, for COFF (as opposed to
13413 ECOFF), we might need yet another copy of reloc->address.
13414 See bfd_install_relocation. */
13415 reloc->addend += reloc->address;
13419 reloc->addend = fixp->fx_addnumber;
13421 /* Since the old MIPS ELF ABI uses Rel instead of Rela, encode the vtable
13422 entry to be used in the relocation's section offset. */
13423 if (! HAVE_NEWABI && fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
13425 reloc->address = reloc->addend;
13429 code = fixp->fx_r_type;
13431 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
13432 if (reloc->howto == NULL)
13434 as_bad_where (fixp->fx_file, fixp->fx_line,
13435 _("Can not represent %s relocation in this object file format"),
13436 bfd_get_reloc_code_name (code));
13443 /* Relax a machine dependent frag. This returns the amount by which
13444 the current size of the frag should change. */
13447 mips_relax_frag (asection *sec, fragS *fragp, long stretch)
13449 if (RELAX_BRANCH_P (fragp->fr_subtype))
13451 offsetT old_var = fragp->fr_var;
13453 fragp->fr_var = relaxed_branch_length (fragp, sec, TRUE);
13455 return fragp->fr_var - old_var;
13458 if (! RELAX_MIPS16_P (fragp->fr_subtype))
13461 if (mips16_extended_frag (fragp, NULL, stretch))
13463 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
13465 fragp->fr_subtype = RELAX_MIPS16_MARK_EXTENDED (fragp->fr_subtype);
13470 if (! RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
13472 fragp->fr_subtype = RELAX_MIPS16_CLEAR_EXTENDED (fragp->fr_subtype);
13479 /* Convert a machine dependent frag. */
13482 md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, segT asec, fragS *fragp)
13484 if (RELAX_BRANCH_P (fragp->fr_subtype))
13487 unsigned long insn;
13491 buf = (bfd_byte *)fragp->fr_literal + fragp->fr_fix;
13493 if (target_big_endian)
13494 insn = bfd_getb32 (buf);
13496 insn = bfd_getl32 (buf);
13498 if (!RELAX_BRANCH_TOOFAR (fragp->fr_subtype))
13500 /* We generate a fixup instead of applying it right now
13501 because, if there are linker relaxations, we're going to
13502 need the relocations. */
13503 exp.X_op = O_symbol;
13504 exp.X_add_symbol = fragp->fr_symbol;
13505 exp.X_add_number = fragp->fr_offset;
13507 fixp = fix_new_exp (fragp, buf - (bfd_byte *)fragp->fr_literal,
13508 4, &exp, 1, BFD_RELOC_16_PCREL_S2);
13509 fixp->fx_file = fragp->fr_file;
13510 fixp->fx_line = fragp->fr_line;
13512 md_number_to_chars ((char *) buf, insn, 4);
13519 as_warn_where (fragp->fr_file, fragp->fr_line,
13520 _("relaxed out-of-range branch into a jump"));
13522 if (RELAX_BRANCH_UNCOND (fragp->fr_subtype))
13525 if (!RELAX_BRANCH_LIKELY (fragp->fr_subtype))
13527 /* Reverse the branch. */
13528 switch ((insn >> 28) & 0xf)
13531 /* bc[0-3][tf]l? and bc1any[24][ft] instructions can
13532 have the condition reversed by tweaking a single
13533 bit, and their opcodes all have 0x4???????. */
13534 assert ((insn & 0xf1000000) == 0x41000000);
13535 insn ^= 0x00010000;
13539 /* bltz 0x04000000 bgez 0x04010000
13540 bltzal 0x04100000 bgezal 0x04110000 */
13541 assert ((insn & 0xfc0e0000) == 0x04000000);
13542 insn ^= 0x00010000;
13546 /* beq 0x10000000 bne 0x14000000
13547 blez 0x18000000 bgtz 0x1c000000 */
13548 insn ^= 0x04000000;
13556 if (RELAX_BRANCH_LINK (fragp->fr_subtype))
13558 /* Clear the and-link bit. */
13559 assert ((insn & 0xfc1c0000) == 0x04100000);
13561 /* bltzal 0x04100000 bgezal 0x04110000
13562 bltzall 0x04120000 bgezall 0x04130000 */
13563 insn &= ~0x00100000;
13566 /* Branch over the branch (if the branch was likely) or the
13567 full jump (not likely case). Compute the offset from the
13568 current instruction to branch to. */
13569 if (RELAX_BRANCH_LIKELY (fragp->fr_subtype))
13573 /* How many bytes in instructions we've already emitted? */
13574 i = buf - (bfd_byte *)fragp->fr_literal - fragp->fr_fix;
13575 /* How many bytes in instructions from here to the end? */
13576 i = fragp->fr_var - i;
13578 /* Convert to instruction count. */
13580 /* Branch counts from the next instruction. */
13583 /* Branch over the jump. */
13584 md_number_to_chars ((char *) buf, insn, 4);
13588 md_number_to_chars ((char *) buf, 0, 4);
13591 if (RELAX_BRANCH_LIKELY (fragp->fr_subtype))
13593 /* beql $0, $0, 2f */
13595 /* Compute the PC offset from the current instruction to
13596 the end of the variable frag. */
13597 /* How many bytes in instructions we've already emitted? */
13598 i = buf - (bfd_byte *)fragp->fr_literal - fragp->fr_fix;
13599 /* How many bytes in instructions from here to the end? */
13600 i = fragp->fr_var - i;
13601 /* Convert to instruction count. */
13603 /* Don't decrement i, because we want to branch over the
13607 md_number_to_chars ((char *) buf, insn, 4);
13610 md_number_to_chars ((char *) buf, 0, 4);
13615 if (mips_pic == NO_PIC)
13618 insn = (RELAX_BRANCH_LINK (fragp->fr_subtype)
13619 ? 0x0c000000 : 0x08000000);
13620 exp.X_op = O_symbol;
13621 exp.X_add_symbol = fragp->fr_symbol;
13622 exp.X_add_number = fragp->fr_offset;
13624 fixp = fix_new_exp (fragp, buf - (bfd_byte *)fragp->fr_literal,
13625 4, &exp, 0, BFD_RELOC_MIPS_JMP);
13626 fixp->fx_file = fragp->fr_file;
13627 fixp->fx_line = fragp->fr_line;
13629 md_number_to_chars ((char *) buf, insn, 4);
13634 /* lw/ld $at, <sym>($gp) R_MIPS_GOT16 */
13635 insn = HAVE_64BIT_ADDRESSES ? 0xdf810000 : 0x8f810000;
13636 exp.X_op = O_symbol;
13637 exp.X_add_symbol = fragp->fr_symbol;
13638 exp.X_add_number = fragp->fr_offset;
13640 if (fragp->fr_offset)
13642 exp.X_add_symbol = make_expr_symbol (&exp);
13643 exp.X_add_number = 0;
13646 fixp = fix_new_exp (fragp, buf - (bfd_byte *)fragp->fr_literal,
13647 4, &exp, 0, BFD_RELOC_MIPS_GOT16);
13648 fixp->fx_file = fragp->fr_file;
13649 fixp->fx_line = fragp->fr_line;
13651 md_number_to_chars ((char *) buf, insn, 4);
13654 if (mips_opts.isa == ISA_MIPS1)
13657 md_number_to_chars ((char *) buf, 0, 4);
13661 /* d/addiu $at, $at, <sym> R_MIPS_LO16 */
13662 insn = HAVE_64BIT_ADDRESSES ? 0x64210000 : 0x24210000;
13664 fixp = fix_new_exp (fragp, buf - (bfd_byte *)fragp->fr_literal,
13665 4, &exp, 0, BFD_RELOC_LO16);
13666 fixp->fx_file = fragp->fr_file;
13667 fixp->fx_line = fragp->fr_line;
13669 md_number_to_chars ((char *) buf, insn, 4);
13673 if (RELAX_BRANCH_LINK (fragp->fr_subtype))
13678 md_number_to_chars ((char *) buf, insn, 4);
13683 assert (buf == (bfd_byte *)fragp->fr_literal
13684 + fragp->fr_fix + fragp->fr_var);
13686 fragp->fr_fix += fragp->fr_var;
13691 if (RELAX_MIPS16_P (fragp->fr_subtype))
13694 register const struct mips16_immed_operand *op;
13695 bfd_boolean small, ext;
13698 unsigned long insn;
13699 bfd_boolean use_extend;
13700 unsigned short extend;
13702 type = RELAX_MIPS16_TYPE (fragp->fr_subtype);
13703 op = mips16_immed_operands;
13704 while (op->type != type)
13707 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
13718 resolve_symbol_value (fragp->fr_symbol);
13719 val = S_GET_VALUE (fragp->fr_symbol);
13724 addr = fragp->fr_address + fragp->fr_fix;
13726 /* The rules for the base address of a PC relative reloc are
13727 complicated; see mips16_extended_frag. */
13728 if (type == 'p' || type == 'q')
13733 /* Ignore the low bit in the target, since it will be
13734 set for a text label. */
13735 if ((val & 1) != 0)
13738 else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype))
13740 else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype))
13743 addr &= ~ (addressT) ((1 << op->shift) - 1);
13746 /* Make sure the section winds up with the alignment we have
13749 record_alignment (asec, op->shift);
13753 && (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype)
13754 || RELAX_MIPS16_DSLOT (fragp->fr_subtype)))
13755 as_warn_where (fragp->fr_file, fragp->fr_line,
13756 _("extended instruction in delay slot"));
13758 buf = (bfd_byte *) (fragp->fr_literal + fragp->fr_fix);
13760 if (target_big_endian)
13761 insn = bfd_getb16 (buf);
13763 insn = bfd_getl16 (buf);
13765 mips16_immed (fragp->fr_file, fragp->fr_line, type, val,
13766 RELAX_MIPS16_USER_EXT (fragp->fr_subtype),
13767 small, ext, &insn, &use_extend, &extend);
13771 md_number_to_chars ((char *) buf, 0xf000 | extend, 2);
13772 fragp->fr_fix += 2;
13776 md_number_to_chars ((char *) buf, insn, 2);
13777 fragp->fr_fix += 2;
13785 first = RELAX_FIRST (fragp->fr_subtype);
13786 second = RELAX_SECOND (fragp->fr_subtype);
13787 fixp = (fixS *) fragp->fr_opcode;
13789 /* Possibly emit a warning if we've chosen the longer option. */
13790 if (((fragp->fr_subtype & RELAX_USE_SECOND) != 0)
13791 == ((fragp->fr_subtype & RELAX_SECOND_LONGER) != 0))
13793 const char *msg = macro_warning (fragp->fr_subtype);
13795 as_warn_where (fragp->fr_file, fragp->fr_line, msg);
13798 /* Go through all the fixups for the first sequence. Disable them
13799 (by marking them as done) if we're going to use the second
13800 sequence instead. */
13802 && fixp->fx_frag == fragp
13803 && fixp->fx_where < fragp->fr_fix - second)
13805 if (fragp->fr_subtype & RELAX_USE_SECOND)
13807 fixp = fixp->fx_next;
13810 /* Go through the fixups for the second sequence. Disable them if
13811 we're going to use the first sequence, otherwise adjust their
13812 addresses to account for the relaxation. */
13813 while (fixp && fixp->fx_frag == fragp)
13815 if (fragp->fr_subtype & RELAX_USE_SECOND)
13816 fixp->fx_where -= first;
13819 fixp = fixp->fx_next;
13822 /* Now modify the frag contents. */
13823 if (fragp->fr_subtype & RELAX_USE_SECOND)
13827 start = fragp->fr_literal + fragp->fr_fix - first - second;
13828 memmove (start, start + first, second);
13829 fragp->fr_fix -= first;
13832 fragp->fr_fix -= second;
13838 /* This function is called after the relocs have been generated.
13839 We've been storing mips16 text labels as odd. Here we convert them
13840 back to even for the convenience of the debugger. */
13843 mips_frob_file_after_relocs (void)
13846 unsigned int count, i;
13848 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
13851 syms = bfd_get_outsymbols (stdoutput);
13852 count = bfd_get_symcount (stdoutput);
13853 for (i = 0; i < count; i++, syms++)
13855 if (elf_symbol (*syms)->internal_elf_sym.st_other == STO_MIPS16
13856 && ((*syms)->value & 1) != 0)
13858 (*syms)->value &= ~1;
13859 /* If the symbol has an odd size, it was probably computed
13860 incorrectly, so adjust that as well. */
13861 if ((elf_symbol (*syms)->internal_elf_sym.st_size & 1) != 0)
13862 ++elf_symbol (*syms)->internal_elf_sym.st_size;
13869 /* This function is called whenever a label is defined. It is used
13870 when handling branch delays; if a branch has a label, we assume we
13871 can not move it. */
13874 mips_define_label (symbolS *sym)
13876 struct insn_label_list *l;
13878 if (free_insn_labels == NULL)
13879 l = (struct insn_label_list *) xmalloc (sizeof *l);
13882 l = free_insn_labels;
13883 free_insn_labels = l->next;
13887 l->next = insn_labels;
13891 dwarf2_emit_label (sym);
13895 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
13897 /* Some special processing for a MIPS ELF file. */
13900 mips_elf_final_processing (void)
13902 /* Write out the register information. */
13903 if (mips_abi != N64_ABI)
13907 s.ri_gprmask = mips_gprmask;
13908 s.ri_cprmask[0] = mips_cprmask[0];
13909 s.ri_cprmask[1] = mips_cprmask[1];
13910 s.ri_cprmask[2] = mips_cprmask[2];
13911 s.ri_cprmask[3] = mips_cprmask[3];
13912 /* The gp_value field is set by the MIPS ELF backend. */
13914 bfd_mips_elf32_swap_reginfo_out (stdoutput, &s,
13915 ((Elf32_External_RegInfo *)
13916 mips_regmask_frag));
13920 Elf64_Internal_RegInfo s;
13922 s.ri_gprmask = mips_gprmask;
13924 s.ri_cprmask[0] = mips_cprmask[0];
13925 s.ri_cprmask[1] = mips_cprmask[1];
13926 s.ri_cprmask[2] = mips_cprmask[2];
13927 s.ri_cprmask[3] = mips_cprmask[3];
13928 /* The gp_value field is set by the MIPS ELF backend. */
13930 bfd_mips_elf64_swap_reginfo_out (stdoutput, &s,
13931 ((Elf64_External_RegInfo *)
13932 mips_regmask_frag));
13935 /* Set the MIPS ELF flag bits. FIXME: There should probably be some
13936 sort of BFD interface for this. */
13937 if (mips_any_noreorder)
13938 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_NOREORDER;
13939 if (mips_pic != NO_PIC)
13941 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_PIC;
13942 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_CPIC;
13945 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_CPIC;
13947 /* Set MIPS ELF flags for ASEs. */
13948 /* We may need to define a new flag for DSP ASE, and set this flag when
13949 file_ase_dsp is true. */
13950 /* We may need to define a new flag for MT ASE, and set this flag when
13951 file_ase_mt is true. */
13952 if (file_ase_mips16)
13953 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ARCH_ASE_M16;
13954 #if 0 /* XXX FIXME */
13955 if (file_ase_mips3d)
13956 elf_elfheader (stdoutput)->e_flags |= ???;
13959 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ARCH_ASE_MDMX;
13961 /* Set the MIPS ELF ABI flags. */
13962 if (mips_abi == O32_ABI && USE_E_MIPS_ABI_O32)
13963 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O32;
13964 else if (mips_abi == O64_ABI)
13965 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O64;
13966 else if (mips_abi == EABI_ABI)
13968 if (!file_mips_gp32)
13969 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI64;
13971 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI32;
13973 else if (mips_abi == N32_ABI)
13974 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ABI2;
13976 /* Nothing to do for N64_ABI. */
13978 if (mips_32bitmode)
13979 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_32BITMODE;
13982 #endif /* OBJ_ELF || OBJ_MAYBE_ELF */
13984 typedef struct proc {
13986 symbolS *func_end_sym;
13987 unsigned long reg_mask;
13988 unsigned long reg_offset;
13989 unsigned long fpreg_mask;
13990 unsigned long fpreg_offset;
13991 unsigned long frame_offset;
13992 unsigned long frame_reg;
13993 unsigned long pc_reg;
13996 static procS cur_proc;
13997 static procS *cur_proc_ptr;
13998 static int numprocs;
14000 /* Fill in an rs_align_code fragment. */
14003 mips_handle_align (fragS *fragp)
14005 if (fragp->fr_type != rs_align_code)
14008 if (mips_opts.mips16)
14010 static const unsigned char be_nop[] = { 0x65, 0x00 };
14011 static const unsigned char le_nop[] = { 0x00, 0x65 };
14016 bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
14017 p = fragp->fr_literal + fragp->fr_fix;
14025 memcpy (p, (target_big_endian ? be_nop : le_nop), 2);
14029 /* For mips32, a nop is a zero, which we trivially get by doing nothing. */
14033 md_obj_begin (void)
14040 /* check for premature end, nesting errors, etc */
14042 as_warn (_("missing .end at end of assembly"));
14051 if (*input_line_pointer == '-')
14053 ++input_line_pointer;
14056 if (!ISDIGIT (*input_line_pointer))
14057 as_bad (_("expected simple number"));
14058 if (input_line_pointer[0] == '0')
14060 if (input_line_pointer[1] == 'x')
14062 input_line_pointer += 2;
14063 while (ISXDIGIT (*input_line_pointer))
14066 val |= hex_value (*input_line_pointer++);
14068 return negative ? -val : val;
14072 ++input_line_pointer;
14073 while (ISDIGIT (*input_line_pointer))
14076 val |= *input_line_pointer++ - '0';
14078 return negative ? -val : val;
14081 if (!ISDIGIT (*input_line_pointer))
14083 printf (_(" *input_line_pointer == '%c' 0x%02x\n"),
14084 *input_line_pointer, *input_line_pointer);
14085 as_warn (_("invalid number"));
14088 while (ISDIGIT (*input_line_pointer))
14091 val += *input_line_pointer++ - '0';
14093 return negative ? -val : val;
14096 /* The .file directive; just like the usual .file directive, but there
14097 is an initial number which is the ECOFF file index. In the non-ECOFF
14098 case .file implies DWARF-2. */
14101 s_mips_file (int x ATTRIBUTE_UNUSED)
14103 static int first_file_directive = 0;
14105 if (ECOFF_DEBUGGING)
14114 filename = dwarf2_directive_file (0);
14116 /* Versions of GCC up to 3.1 start files with a ".file"
14117 directive even for stabs output. Make sure that this
14118 ".file" is handled. Note that you need a version of GCC
14119 after 3.1 in order to support DWARF-2 on MIPS. */
14120 if (filename != NULL && ! first_file_directive)
14122 (void) new_logical_line (filename, -1);
14123 s_app_file_string (filename, 0);
14125 first_file_directive = 1;
14129 /* The .loc directive, implying DWARF-2. */
14132 s_mips_loc (int x ATTRIBUTE_UNUSED)
14134 if (!ECOFF_DEBUGGING)
14135 dwarf2_directive_loc (0);
14138 /* The .end directive. */
14141 s_mips_end (int x ATTRIBUTE_UNUSED)
14145 /* Following functions need their own .frame and .cprestore directives. */
14146 mips_frame_reg_valid = 0;
14147 mips_cprestore_valid = 0;
14149 if (!is_end_of_line[(unsigned char) *input_line_pointer])
14152 demand_empty_rest_of_line ();
14157 if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) == 0)
14158 as_warn (_(".end not in text section"));
14162 as_warn (_(".end directive without a preceding .ent directive."));
14163 demand_empty_rest_of_line ();
14169 assert (S_GET_NAME (p));
14170 if (strcmp (S_GET_NAME (p), S_GET_NAME (cur_proc_ptr->func_sym)))
14171 as_warn (_(".end symbol does not match .ent symbol."));
14173 if (debug_type == DEBUG_STABS)
14174 stabs_generate_asm_endfunc (S_GET_NAME (p),
14178 as_warn (_(".end directive missing or unknown symbol"));
14181 /* Create an expression to calculate the size of the function. */
14182 if (p && cur_proc_ptr)
14184 OBJ_SYMFIELD_TYPE *obj = symbol_get_obj (p);
14185 expressionS *exp = xmalloc (sizeof (expressionS));
14188 exp->X_op = O_subtract;
14189 exp->X_add_symbol = symbol_temp_new_now ();
14190 exp->X_op_symbol = p;
14191 exp->X_add_number = 0;
14193 cur_proc_ptr->func_end_sym = exp->X_add_symbol;
14196 /* Generate a .pdr section. */
14197 if (OUTPUT_FLAVOR == bfd_target_elf_flavour && ! ECOFF_DEBUGGING
14200 segT saved_seg = now_seg;
14201 subsegT saved_subseg = now_subseg;
14206 dot = frag_now_fix ();
14208 #ifdef md_flush_pending_output
14209 md_flush_pending_output ();
14213 subseg_set (pdr_seg, 0);
14215 /* Write the symbol. */
14216 exp.X_op = O_symbol;
14217 exp.X_add_symbol = p;
14218 exp.X_add_number = 0;
14219 emit_expr (&exp, 4);
14221 fragp = frag_more (7 * 4);
14223 md_number_to_chars (fragp, cur_proc_ptr->reg_mask, 4);
14224 md_number_to_chars (fragp + 4, cur_proc_ptr->reg_offset, 4);
14225 md_number_to_chars (fragp + 8, cur_proc_ptr->fpreg_mask, 4);
14226 md_number_to_chars (fragp + 12, cur_proc_ptr->fpreg_offset, 4);
14227 md_number_to_chars (fragp + 16, cur_proc_ptr->frame_offset, 4);
14228 md_number_to_chars (fragp + 20, cur_proc_ptr->frame_reg, 4);
14229 md_number_to_chars (fragp + 24, cur_proc_ptr->pc_reg, 4);
14231 subseg_set (saved_seg, saved_subseg);
14233 #endif /* OBJ_ELF */
14235 cur_proc_ptr = NULL;
14238 /* The .aent and .ent directives. */
14241 s_mips_ent (int aent)
14245 symbolP = get_symbol ();
14246 if (*input_line_pointer == ',')
14247 ++input_line_pointer;
14248 SKIP_WHITESPACE ();
14249 if (ISDIGIT (*input_line_pointer)
14250 || *input_line_pointer == '-')
14253 if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) == 0)
14254 as_warn (_(".ent or .aent not in text section."));
14256 if (!aent && cur_proc_ptr)
14257 as_warn (_("missing .end"));
14261 /* This function needs its own .frame and .cprestore directives. */
14262 mips_frame_reg_valid = 0;
14263 mips_cprestore_valid = 0;
14265 cur_proc_ptr = &cur_proc;
14266 memset (cur_proc_ptr, '\0', sizeof (procS));
14268 cur_proc_ptr->func_sym = symbolP;
14270 symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION;
14274 if (debug_type == DEBUG_STABS)
14275 stabs_generate_asm_func (S_GET_NAME (symbolP),
14276 S_GET_NAME (symbolP));
14279 demand_empty_rest_of_line ();
14282 /* The .frame directive. If the mdebug section is present (IRIX 5 native)
14283 then ecoff.c (ecoff_directive_frame) is used. For embedded targets,
14284 s_mips_frame is used so that we can set the PDR information correctly.
14285 We can't use the ecoff routines because they make reference to the ecoff
14286 symbol table (in the mdebug section). */
14289 s_mips_frame (int ignore ATTRIBUTE_UNUSED)
14292 if (OUTPUT_FLAVOR == bfd_target_elf_flavour && ! ECOFF_DEBUGGING)
14296 if (cur_proc_ptr == (procS *) NULL)
14298 as_warn (_(".frame outside of .ent"));
14299 demand_empty_rest_of_line ();
14303 cur_proc_ptr->frame_reg = tc_get_register (1);
14305 SKIP_WHITESPACE ();
14306 if (*input_line_pointer++ != ','
14307 || get_absolute_expression_and_terminator (&val) != ',')
14309 as_warn (_("Bad .frame directive"));
14310 --input_line_pointer;
14311 demand_empty_rest_of_line ();
14315 cur_proc_ptr->frame_offset = val;
14316 cur_proc_ptr->pc_reg = tc_get_register (0);
14318 demand_empty_rest_of_line ();
14321 #endif /* OBJ_ELF */
14325 /* The .fmask and .mask directives. If the mdebug section is present
14326 (IRIX 5 native) then ecoff.c (ecoff_directive_mask) is used. For
14327 embedded targets, s_mips_mask is used so that we can set the PDR
14328 information correctly. We can't use the ecoff routines because they
14329 make reference to the ecoff symbol table (in the mdebug section). */
14332 s_mips_mask (int reg_type)
14335 if (OUTPUT_FLAVOR == bfd_target_elf_flavour && ! ECOFF_DEBUGGING)
14339 if (cur_proc_ptr == (procS *) NULL)
14341 as_warn (_(".mask/.fmask outside of .ent"));
14342 demand_empty_rest_of_line ();
14346 if (get_absolute_expression_and_terminator (&mask) != ',')
14348 as_warn (_("Bad .mask/.fmask directive"));
14349 --input_line_pointer;
14350 demand_empty_rest_of_line ();
14354 off = get_absolute_expression ();
14356 if (reg_type == 'F')
14358 cur_proc_ptr->fpreg_mask = mask;
14359 cur_proc_ptr->fpreg_offset = off;
14363 cur_proc_ptr->reg_mask = mask;
14364 cur_proc_ptr->reg_offset = off;
14367 demand_empty_rest_of_line ();
14370 #endif /* OBJ_ELF */
14371 s_ignore (reg_type);
14374 /* A table describing all the processors gas knows about. Names are
14375 matched in the order listed.
14377 To ease comparison, please keep this table in the same order as
14378 gcc's mips_cpu_info_table[]. */
14379 static const struct mips_cpu_info mips_cpu_info_table[] =
14381 /* Entries for generic ISAs */
14382 { "mips1", 1, ISA_MIPS1, CPU_R3000 },
14383 { "mips2", 1, ISA_MIPS2, CPU_R6000 },
14384 { "mips3", 1, ISA_MIPS3, CPU_R4000 },
14385 { "mips4", 1, ISA_MIPS4, CPU_R8000 },
14386 { "mips5", 1, ISA_MIPS5, CPU_MIPS5 },
14387 { "mips32", 1, ISA_MIPS32, CPU_MIPS32 },
14388 { "mips32r2", 1, ISA_MIPS32R2, CPU_MIPS32R2 },
14389 { "mips64", 1, ISA_MIPS64, CPU_MIPS64 },
14390 { "mips64r2", 1, ISA_MIPS64R2, CPU_MIPS64R2 },
14393 { "r3000", 0, ISA_MIPS1, CPU_R3000 },
14394 { "r2000", 0, ISA_MIPS1, CPU_R3000 },
14395 { "r3900", 0, ISA_MIPS1, CPU_R3900 },
14398 { "r6000", 0, ISA_MIPS2, CPU_R6000 },
14401 { "r4000", 0, ISA_MIPS3, CPU_R4000 },
14402 { "r4010", 0, ISA_MIPS2, CPU_R4010 },
14403 { "vr4100", 0, ISA_MIPS3, CPU_VR4100 },
14404 { "vr4111", 0, ISA_MIPS3, CPU_R4111 },
14405 { "vr4120", 0, ISA_MIPS3, CPU_VR4120 },
14406 { "vr4130", 0, ISA_MIPS3, CPU_VR4120 },
14407 { "vr4181", 0, ISA_MIPS3, CPU_R4111 },
14408 { "vr4300", 0, ISA_MIPS3, CPU_R4300 },
14409 { "r4400", 0, ISA_MIPS3, CPU_R4400 },
14410 { "r4600", 0, ISA_MIPS3, CPU_R4600 },
14411 { "orion", 0, ISA_MIPS3, CPU_R4600 },
14412 { "r4650", 0, ISA_MIPS3, CPU_R4650 },
14415 { "r8000", 0, ISA_MIPS4, CPU_R8000 },
14416 { "r10000", 0, ISA_MIPS4, CPU_R10000 },
14417 { "r12000", 0, ISA_MIPS4, CPU_R12000 },
14418 { "vr5000", 0, ISA_MIPS4, CPU_R5000 },
14419 { "vr5400", 0, ISA_MIPS4, CPU_VR5400 },
14420 { "vr5500", 0, ISA_MIPS4, CPU_VR5500 },
14421 { "rm5200", 0, ISA_MIPS4, CPU_R5000 },
14422 { "rm5230", 0, ISA_MIPS4, CPU_R5000 },
14423 { "rm5231", 0, ISA_MIPS4, CPU_R5000 },
14424 { "rm5261", 0, ISA_MIPS4, CPU_R5000 },
14425 { "rm5721", 0, ISA_MIPS4, CPU_R5000 },
14426 { "rm7000", 0, ISA_MIPS4, CPU_RM7000 },
14427 { "rm9000", 0, ISA_MIPS4, CPU_RM9000 },
14430 { "4kc", 0, ISA_MIPS32, CPU_MIPS32 },
14431 { "4km", 0, ISA_MIPS32, CPU_MIPS32 },
14432 { "4kp", 0, ISA_MIPS32, CPU_MIPS32 },
14434 /* MIPS32 Release 2 */
14435 { "m4k", 0, ISA_MIPS32R2, CPU_MIPS32R2 },
14436 { "24k", 0, ISA_MIPS32R2, CPU_MIPS32R2 },
14437 { "24kc", 0, ISA_MIPS32R2, CPU_MIPS32R2 },
14438 { "24kf", 0, ISA_MIPS32R2, CPU_MIPS32R2 },
14439 { "24kx", 0, ISA_MIPS32R2, CPU_MIPS32R2 },
14442 { "5kc", 0, ISA_MIPS64, CPU_MIPS64 },
14443 { "5kf", 0, ISA_MIPS64, CPU_MIPS64 },
14444 { "20kc", 0, ISA_MIPS64, CPU_MIPS64 },
14446 /* Broadcom SB-1 CPU core */
14447 { "sb1", 0, ISA_MIPS64, CPU_SB1 },
14454 /* Return true if GIVEN is the same as CANONICAL, or if it is CANONICAL
14455 with a final "000" replaced by "k". Ignore case.
14457 Note: this function is shared between GCC and GAS. */
14460 mips_strict_matching_cpu_name_p (const char *canonical, const char *given)
14462 while (*given != 0 && TOLOWER (*given) == TOLOWER (*canonical))
14463 given++, canonical++;
14465 return ((*given == 0 && *canonical == 0)
14466 || (strcmp (canonical, "000") == 0 && strcasecmp (given, "k") == 0));
14470 /* Return true if GIVEN matches CANONICAL, where GIVEN is a user-supplied
14471 CPU name. We've traditionally allowed a lot of variation here.
14473 Note: this function is shared between GCC and GAS. */
14476 mips_matching_cpu_name_p (const char *canonical, const char *given)
14478 /* First see if the name matches exactly, or with a final "000"
14479 turned into "k". */
14480 if (mips_strict_matching_cpu_name_p (canonical, given))
14483 /* If not, try comparing based on numerical designation alone.
14484 See if GIVEN is an unadorned number, or 'r' followed by a number. */
14485 if (TOLOWER (*given) == 'r')
14487 if (!ISDIGIT (*given))
14490 /* Skip over some well-known prefixes in the canonical name,
14491 hoping to find a number there too. */
14492 if (TOLOWER (canonical[0]) == 'v' && TOLOWER (canonical[1]) == 'r')
14494 else if (TOLOWER (canonical[0]) == 'r' && TOLOWER (canonical[1]) == 'm')
14496 else if (TOLOWER (canonical[0]) == 'r')
14499 return mips_strict_matching_cpu_name_p (canonical, given);
14503 /* Parse an option that takes the name of a processor as its argument.
14504 OPTION is the name of the option and CPU_STRING is the argument.
14505 Return the corresponding processor enumeration if the CPU_STRING is
14506 recognized, otherwise report an error and return null.
14508 A similar function exists in GCC. */
14510 static const struct mips_cpu_info *
14511 mips_parse_cpu (const char *option, const char *cpu_string)
14513 const struct mips_cpu_info *p;
14515 /* 'from-abi' selects the most compatible architecture for the given
14516 ABI: MIPS I for 32-bit ABIs and MIPS III for 64-bit ABIs. For the
14517 EABIs, we have to decide whether we're using the 32-bit or 64-bit
14518 version. Look first at the -mgp options, if given, otherwise base
14519 the choice on MIPS_DEFAULT_64BIT.
14521 Treat NO_ABI like the EABIs. One reason to do this is that the
14522 plain 'mips' and 'mips64' configs have 'from-abi' as their default
14523 architecture. This code picks MIPS I for 'mips' and MIPS III for
14524 'mips64', just as we did in the days before 'from-abi'. */
14525 if (strcasecmp (cpu_string, "from-abi") == 0)
14527 if (ABI_NEEDS_32BIT_REGS (mips_abi))
14528 return mips_cpu_info_from_isa (ISA_MIPS1);
14530 if (ABI_NEEDS_64BIT_REGS (mips_abi))
14531 return mips_cpu_info_from_isa (ISA_MIPS3);
14533 if (file_mips_gp32 >= 0)
14534 return mips_cpu_info_from_isa (file_mips_gp32 ? ISA_MIPS1 : ISA_MIPS3);
14536 return mips_cpu_info_from_isa (MIPS_DEFAULT_64BIT
14541 /* 'default' has traditionally been a no-op. Probably not very useful. */
14542 if (strcasecmp (cpu_string, "default") == 0)
14545 for (p = mips_cpu_info_table; p->name != 0; p++)
14546 if (mips_matching_cpu_name_p (p->name, cpu_string))
14549 as_bad ("Bad value (%s) for %s", cpu_string, option);
14553 /* Return the canonical processor information for ISA (a member of the
14554 ISA_MIPS* enumeration). */
14556 static const struct mips_cpu_info *
14557 mips_cpu_info_from_isa (int isa)
14561 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
14562 if (mips_cpu_info_table[i].is_isa
14563 && isa == mips_cpu_info_table[i].isa)
14564 return (&mips_cpu_info_table[i]);
14569 static const struct mips_cpu_info *
14570 mips_cpu_info_from_arch (int arch)
14574 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
14575 if (arch == mips_cpu_info_table[i].cpu)
14576 return (&mips_cpu_info_table[i]);
14582 show (FILE *stream, const char *string, int *col_p, int *first_p)
14586 fprintf (stream, "%24s", "");
14591 fprintf (stream, ", ");
14595 if (*col_p + strlen (string) > 72)
14597 fprintf (stream, "\n%24s", "");
14601 fprintf (stream, "%s", string);
14602 *col_p += strlen (string);
14608 md_show_usage (FILE *stream)
14613 fprintf (stream, _("\
14615 -EB generate big endian output\n\
14616 -EL generate little endian output\n\
14617 -g, -g2 do not remove unneeded NOPs or swap branches\n\
14618 -G NUM allow referencing objects up to NUM bytes\n\
14619 implicitly with the gp register [default 8]\n"));
14620 fprintf (stream, _("\
14621 -mips1 generate MIPS ISA I instructions\n\
14622 -mips2 generate MIPS ISA II instructions\n\
14623 -mips3 generate MIPS ISA III instructions\n\
14624 -mips4 generate MIPS ISA IV instructions\n\
14625 -mips5 generate MIPS ISA V instructions\n\
14626 -mips32 generate MIPS32 ISA instructions\n\
14627 -mips32r2 generate MIPS32 release 2 ISA instructions\n\
14628 -mips64 generate MIPS64 ISA instructions\n\
14629 -mips64r2 generate MIPS64 release 2 ISA instructions\n\
14630 -march=CPU/-mtune=CPU generate code/schedule for CPU, where CPU is one of:\n"));
14634 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
14635 show (stream, mips_cpu_info_table[i].name, &column, &first);
14636 show (stream, "from-abi", &column, &first);
14637 fputc ('\n', stream);
14639 fprintf (stream, _("\
14640 -mCPU equivalent to -march=CPU -mtune=CPU. Deprecated.\n\
14641 -no-mCPU don't generate code specific to CPU.\n\
14642 For -mCPU and -no-mCPU, CPU must be one of:\n"));
14646 show (stream, "3900", &column, &first);
14647 show (stream, "4010", &column, &first);
14648 show (stream, "4100", &column, &first);
14649 show (stream, "4650", &column, &first);
14650 fputc ('\n', stream);
14652 fprintf (stream, _("\
14653 -mips16 generate mips16 instructions\n\
14654 -no-mips16 do not generate mips16 instructions\n"));
14655 fprintf (stream, _("\
14656 -msmartmips generate smartmips instructions\n\
14657 -mno-smartmips do not generate smartmips instructions\n"));
14658 fprintf (stream, _("\
14659 -mdsp generate DSP instructions\n\
14660 -mno-dsp do not generate DSP instructions\n"));
14661 fprintf (stream, _("\
14662 -mmt generate MT instructions\n\
14663 -mno-mt do not generate MT instructions\n"));
14664 fprintf (stream, _("\
14665 -mfix-vr4120 work around certain VR4120 errata\n\
14666 -mfix-vr4130 work around VR4130 mflo/mfhi errata\n\
14667 -mgp32 use 32-bit GPRs, regardless of the chosen ISA\n\
14668 -mfp32 use 32-bit FPRs, regardless of the chosen ISA\n\
14669 -mno-shared optimize output for executables\n\
14670 -msym32 assume all symbols have 32-bit values\n\
14671 -O0 remove unneeded NOPs, do not swap branches\n\
14672 -O remove unneeded NOPs and swap branches\n\
14673 --[no-]construct-floats [dis]allow floating point values to be constructed\n\
14674 --trap, --no-break trap exception on div by 0 and mult overflow\n\
14675 --break, --no-trap break exception on div by 0 and mult overflow\n"));
14677 fprintf (stream, _("\
14678 -KPIC, -call_shared generate SVR4 position independent code\n\
14679 -non_shared do not generate position independent code\n\
14680 -xgot assume a 32 bit GOT\n\
14681 -mpdr, -mno-pdr enable/disable creation of .pdr sections\n\
14682 -mshared, -mno-shared disable/enable .cpload optimization for\n\
14684 -mabi=ABI create ABI conformant object file for:\n"));
14688 show (stream, "32", &column, &first);
14689 show (stream, "o64", &column, &first);
14690 show (stream, "n32", &column, &first);
14691 show (stream, "64", &column, &first);
14692 show (stream, "eabi", &column, &first);
14694 fputc ('\n', stream);
14696 fprintf (stream, _("\
14697 -32 create o32 ABI object file (default)\n\
14698 -n32 create n32 ABI object file\n\
14699 -64 create 64 ABI object file\n"));
14704 mips_dwarf2_format (void)
14706 if (mips_abi == N64_ABI)
14709 return dwarf2_format_64bit_irix;
14711 return dwarf2_format_64bit;
14715 return dwarf2_format_32bit;
14719 mips_dwarf2_addr_size (void)
14721 if (mips_abi == N64_ABI)
14727 /* Standard calling conventions leave the CFA at SP on entry. */
14729 mips_cfi_frame_initial_instructions (void)
14731 cfi_add_CFA_def_cfa_register (SP);
14735 tc_mips_regname_to_dw2regnum (char *regname)
14737 unsigned int regnum = -1;
14740 if (reg_lookup (®name, RTYPE_GP | RTYPE_NUM, ®))