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 occured 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. */
198 /* Whether we are assembling for the mips16 processor. 0 if we are
199 not, 1 if we are, and -1 if the value has not been initialized.
200 Changed by `.set mips16' and `.set nomips16', and the -mips16 and
201 -nomips16 command line options, and the default CPU. */
203 /* Non-zero if we should not reorder instructions. Changed by `.set
204 reorder' and `.set noreorder'. */
206 /* Non-zero if we should not permit the $at ($1) register to be used
207 in instructions. Changed by `.set at' and `.set noat'. */
209 /* Non-zero if we should warn when a macro instruction expands into
210 more than one machine instruction. Changed by `.set nomacro' and
212 int warn_about_macros;
213 /* Non-zero if we should not move instructions. Changed by `.set
214 move', `.set volatile', `.set nomove', and `.set novolatile'. */
216 /* Non-zero if we should not optimize branches by moving the target
217 of the branch into the delay slot. Actually, we don't perform
218 this optimization anyhow. Changed by `.set bopt' and `.set
221 /* Non-zero if we should not autoextend mips16 instructions.
222 Changed by `.set autoextend' and `.set noautoextend'. */
224 /* Restrict general purpose registers and floating point registers
225 to 32 bit. This is initially determined when -mgp32 or -mfp32
226 is passed but can changed if the assembler code uses .set mipsN. */
229 /* MIPS architecture (CPU) type. Changed by .set arch=FOO, the -march
230 command line option, and the default CPU. */
232 /* True if ".set sym32" is in effect. */
236 /* True if -mgp32 was passed. */
237 static int file_mips_gp32 = -1;
239 /* True if -mfp32 was passed. */
240 static int file_mips_fp32 = -1;
242 /* This is the struct we use to hold the current set of options. Note
243 that we must set the isa field to ISA_UNKNOWN and the ASE fields to
244 -1 to indicate that they have not been initialized. */
246 static struct mips_set_options mips_opts =
248 ISA_UNKNOWN, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, CPU_UNKNOWN, FALSE
251 /* These variables are filled in with the masks of registers used.
252 The object format code reads them and puts them in the appropriate
254 unsigned long mips_gprmask;
255 unsigned long mips_cprmask[4];
257 /* MIPS ISA we are using for this output file. */
258 static int file_mips_isa = ISA_UNKNOWN;
260 /* True if -mips16 was passed or implied by arguments passed on the
261 command line (e.g., by -march). */
262 static int file_ase_mips16;
264 /* True if -mips3d was passed or implied by arguments passed on the
265 command line (e.g., by -march). */
266 static int file_ase_mips3d;
268 /* True if -mdmx was passed or implied by arguments passed on the
269 command line (e.g., by -march). */
270 static int file_ase_mdmx;
272 /* True if -mdsp was passed or implied by arguments passed on the
273 command line (e.g., by -march). */
274 static int file_ase_dsp;
276 /* True if -mmt was passed or implied by arguments passed on the
277 command line (e.g., by -march). */
278 static int file_ase_mt;
280 /* The argument of the -march= flag. The architecture we are assembling. */
281 static int file_mips_arch = CPU_UNKNOWN;
282 static const char *mips_arch_string;
284 /* The argument of the -mtune= flag. The architecture for which we
286 static int mips_tune = CPU_UNKNOWN;
287 static const char *mips_tune_string;
289 /* True when generating 32-bit code for a 64-bit processor. */
290 static int mips_32bitmode = 0;
292 /* True if the given ABI requires 32-bit registers. */
293 #define ABI_NEEDS_32BIT_REGS(ABI) ((ABI) == O32_ABI)
295 /* Likewise 64-bit registers. */
296 #define ABI_NEEDS_64BIT_REGS(ABI) \
298 || (ABI) == N64_ABI \
301 /* Return true if ISA supports 64 bit gp register instructions. */
302 #define ISA_HAS_64BIT_REGS(ISA) ( \
304 || (ISA) == ISA_MIPS4 \
305 || (ISA) == ISA_MIPS5 \
306 || (ISA) == ISA_MIPS64 \
307 || (ISA) == ISA_MIPS64R2 \
310 /* Return true if ISA supports 64-bit right rotate (dror et al.)
312 #define ISA_HAS_DROR(ISA) ( \
313 (ISA) == ISA_MIPS64R2 \
316 /* Return true if ISA supports 32-bit right rotate (ror et al.)
318 #define ISA_HAS_ROR(ISA) ( \
319 (ISA) == ISA_MIPS32R2 \
320 || (ISA) == ISA_MIPS64R2 \
323 #define HAVE_32BIT_GPRS \
324 (mips_opts.gp32 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
326 #define HAVE_32BIT_FPRS \
327 (mips_opts.fp32 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
329 #define HAVE_64BIT_GPRS (! HAVE_32BIT_GPRS)
330 #define HAVE_64BIT_FPRS (! HAVE_32BIT_FPRS)
332 #define HAVE_NEWABI (mips_abi == N32_ABI || mips_abi == N64_ABI)
334 #define HAVE_64BIT_OBJECTS (mips_abi == N64_ABI)
336 /* True if relocations are stored in-place. */
337 #define HAVE_IN_PLACE_ADDENDS (!HAVE_NEWABI)
339 /* The ABI-derived address size. */
340 #define HAVE_64BIT_ADDRESSES \
341 (HAVE_64BIT_GPRS && (mips_abi == EABI_ABI || mips_abi == N64_ABI))
342 #define HAVE_32BIT_ADDRESSES (!HAVE_64BIT_ADDRESSES)
344 /* The size of symbolic constants (i.e., expressions of the form
345 "SYMBOL" or "SYMBOL + OFFSET"). */
346 #define HAVE_32BIT_SYMBOLS \
347 (HAVE_32BIT_ADDRESSES || !HAVE_64BIT_OBJECTS || mips_opts.sym32)
348 #define HAVE_64BIT_SYMBOLS (!HAVE_32BIT_SYMBOLS)
350 /* Addresses are loaded in different ways, depending on the address size
351 in use. The n32 ABI Documentation also mandates the use of additions
352 with overflow checking, but existing implementations don't follow it. */
353 #define ADDRESS_ADD_INSN \
354 (HAVE_32BIT_ADDRESSES ? "addu" : "daddu")
356 #define ADDRESS_ADDI_INSN \
357 (HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu")
359 #define ADDRESS_LOAD_INSN \
360 (HAVE_32BIT_ADDRESSES ? "lw" : "ld")
362 #define ADDRESS_STORE_INSN \
363 (HAVE_32BIT_ADDRESSES ? "sw" : "sd")
365 /* Return true if the given CPU supports the MIPS16 ASE. */
366 #define CPU_HAS_MIPS16(cpu) \
367 (strncmp (TARGET_CPU, "mips16", sizeof ("mips16") - 1) == 0 \
368 || strncmp (TARGET_CANONICAL, "mips-lsi-elf", sizeof ("mips-lsi-elf") - 1) == 0)
370 /* Return true if the given CPU supports the MIPS3D ASE. */
371 #define CPU_HAS_MIPS3D(cpu) ((cpu) == CPU_SB1 \
374 /* Return true if the given CPU supports the MDMX ASE. */
375 #define CPU_HAS_MDMX(cpu) (FALSE \
378 /* Return true if the given CPU supports the DSP ASE. */
379 #define CPU_HAS_DSP(cpu) (FALSE \
382 /* Return true if the given CPU supports the MT ASE. */
383 #define CPU_HAS_MT(cpu) (FALSE \
386 /* True if CPU has a dror instruction. */
387 #define CPU_HAS_DROR(CPU) ((CPU) == CPU_VR5400 || (CPU) == CPU_VR5500)
389 /* True if CPU has a ror instruction. */
390 #define CPU_HAS_ROR(CPU) CPU_HAS_DROR (CPU)
392 /* True if mflo and mfhi can be immediately followed by instructions
393 which write to the HI and LO registers.
395 According to MIPS specifications, MIPS ISAs I, II, and III need
396 (at least) two instructions between the reads of HI/LO and
397 instructions which write them, and later ISAs do not. Contradicting
398 the MIPS specifications, some MIPS IV processor user manuals (e.g.
399 the UM for the NEC Vr5000) document needing the instructions between
400 HI/LO reads and writes, as well. Therefore, we declare only MIPS32,
401 MIPS64 and later ISAs to have the interlocks, plus any specific
402 earlier-ISA CPUs for which CPU documentation declares that the
403 instructions are really interlocked. */
404 #define hilo_interlocks \
405 (mips_opts.isa == ISA_MIPS32 \
406 || mips_opts.isa == ISA_MIPS32R2 \
407 || mips_opts.isa == ISA_MIPS64 \
408 || mips_opts.isa == ISA_MIPS64R2 \
409 || mips_opts.arch == CPU_R4010 \
410 || mips_opts.arch == CPU_R10000 \
411 || mips_opts.arch == CPU_R12000 \
412 || mips_opts.arch == CPU_RM7000 \
413 || mips_opts.arch == CPU_VR5500 \
416 /* Whether the processor uses hardware interlocks to protect reads
417 from the GPRs after they are loaded from memory, and thus does not
418 require nops to be inserted. This applies to instructions marked
419 INSN_LOAD_MEMORY_DELAY. These nops are only required at MIPS ISA
421 #define gpr_interlocks \
422 (mips_opts.isa != ISA_MIPS1 \
423 || mips_opts.arch == CPU_R3900)
425 /* Whether the processor uses hardware interlocks to avoid delays
426 required by coprocessor instructions, and thus does not require
427 nops to be inserted. This applies to instructions marked
428 INSN_LOAD_COPROC_DELAY, INSN_COPROC_MOVE_DELAY, and to delays
429 between instructions marked INSN_WRITE_COND_CODE and ones marked
430 INSN_READ_COND_CODE. These nops are only required at MIPS ISA
431 levels I, II, and III. */
432 /* Itbl support may require additional care here. */
433 #define cop_interlocks \
434 ((mips_opts.isa != ISA_MIPS1 \
435 && mips_opts.isa != ISA_MIPS2 \
436 && mips_opts.isa != ISA_MIPS3) \
437 || mips_opts.arch == CPU_R4300 \
440 /* Whether the processor uses hardware interlocks to protect reads
441 from coprocessor registers after they are loaded from memory, and
442 thus does not require nops to be inserted. This applies to
443 instructions marked INSN_COPROC_MEMORY_DELAY. These nops are only
444 requires at MIPS ISA level I. */
445 #define cop_mem_interlocks (mips_opts.isa != ISA_MIPS1)
447 /* Is this a mfhi or mflo instruction? */
448 #define MF_HILO_INSN(PINFO) \
449 ((PINFO & INSN_READ_HI) || (PINFO & INSN_READ_LO))
451 /* MIPS PIC level. */
453 enum mips_pic_level mips_pic;
455 /* 1 if we should generate 32 bit offsets from the $gp register in
456 SVR4_PIC mode. Currently has no meaning in other modes. */
457 static int mips_big_got = 0;
459 /* 1 if trap instructions should used for overflow rather than break
461 static int mips_trap = 0;
463 /* 1 if double width floating point constants should not be constructed
464 by assembling two single width halves into two single width floating
465 point registers which just happen to alias the double width destination
466 register. On some architectures this aliasing can be disabled by a bit
467 in the status register, and the setting of this bit cannot be determined
468 automatically at assemble time. */
469 static int mips_disable_float_construction;
471 /* Non-zero if any .set noreorder directives were used. */
473 static int mips_any_noreorder;
475 /* Non-zero if nops should be inserted when the register referenced in
476 an mfhi/mflo instruction is read in the next two instructions. */
477 static int mips_7000_hilo_fix;
479 /* The size of the small data section. */
480 static unsigned int g_switch_value = 8;
481 /* Whether the -G option was used. */
482 static int g_switch_seen = 0;
487 /* If we can determine in advance that GP optimization won't be
488 possible, we can skip the relaxation stuff that tries to produce
489 GP-relative references. This makes delay slot optimization work
492 This function can only provide a guess, but it seems to work for
493 gcc output. It needs to guess right for gcc, otherwise gcc
494 will put what it thinks is a GP-relative instruction in a branch
497 I don't know if a fix is needed for the SVR4_PIC mode. I've only
498 fixed it for the non-PIC mode. KR 95/04/07 */
499 static int nopic_need_relax (symbolS *, int);
501 /* handle of the OPCODE hash table */
502 static struct hash_control *op_hash = NULL;
504 /* The opcode hash table we use for the mips16. */
505 static struct hash_control *mips16_op_hash = NULL;
507 /* This array holds the chars that always start a comment. If the
508 pre-processor is disabled, these aren't very useful */
509 const char comment_chars[] = "#";
511 /* This array holds the chars that only start a comment at the beginning of
512 a line. If the line seems to have the form '# 123 filename'
513 .line and .file directives will appear in the pre-processed output */
514 /* Note that input_file.c hand checks for '#' at the beginning of the
515 first line of the input file. This is because the compiler outputs
516 #NO_APP at the beginning of its output. */
517 /* Also note that C style comments are always supported. */
518 const char line_comment_chars[] = "#";
520 /* This array holds machine specific line separator characters. */
521 const char line_separator_chars[] = ";";
523 /* Chars that can be used to separate mant from exp in floating point nums */
524 const char EXP_CHARS[] = "eE";
526 /* Chars that mean this number is a floating point constant */
529 const char FLT_CHARS[] = "rRsSfFdDxXpP";
531 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
532 changed in read.c . Ideally it shouldn't have to know about it at all,
533 but nothing is ideal around here.
536 static char *insn_error;
538 static int auto_align = 1;
540 /* When outputting SVR4 PIC code, the assembler needs to know the
541 offset in the stack frame from which to restore the $gp register.
542 This is set by the .cprestore pseudo-op, and saved in this
544 static offsetT mips_cprestore_offset = -1;
546 /* Similar for NewABI PIC code, where $gp is callee-saved. NewABI has some
547 more optimizations, it can use a register value instead of a memory-saved
548 offset and even an other register than $gp as global pointer. */
549 static offsetT mips_cpreturn_offset = -1;
550 static int mips_cpreturn_register = -1;
551 static int mips_gp_register = GP;
552 static int mips_gprel_offset = 0;
554 /* Whether mips_cprestore_offset has been set in the current function
555 (or whether it has already been warned about, if not). */
556 static int mips_cprestore_valid = 0;
558 /* This is the register which holds the stack frame, as set by the
559 .frame pseudo-op. This is needed to implement .cprestore. */
560 static int mips_frame_reg = SP;
562 /* Whether mips_frame_reg has been set in the current function
563 (or whether it has already been warned about, if not). */
564 static int mips_frame_reg_valid = 0;
566 /* To output NOP instructions correctly, we need to keep information
567 about the previous two instructions. */
569 /* Whether we are optimizing. The default value of 2 means to remove
570 unneeded NOPs and swap branch instructions when possible. A value
571 of 1 means to not swap branches. A value of 0 means to always
573 static int mips_optimize = 2;
575 /* Debugging level. -g sets this to 2. -gN sets this to N. -g0 is
576 equivalent to seeing no -g option at all. */
577 static int mips_debug = 0;
579 /* The maximum number of NOPs needed to avoid the VR4130 mflo/mfhi errata. */
580 #define MAX_VR4130_NOPS 4
582 /* The maximum number of NOPs needed to fill delay slots. */
583 #define MAX_DELAY_NOPS 2
585 /* The maximum number of NOPs needed for any purpose. */
588 /* A list of previous instructions, with index 0 being the most recent.
589 We need to look back MAX_NOPS instructions when filling delay slots
590 or working around processor errata. We need to look back one
591 instruction further if we're thinking about using history[0] to
592 fill a branch delay slot. */
593 static struct mips_cl_insn history[1 + MAX_NOPS];
595 /* Nop instructions used by emit_nop. */
596 static struct mips_cl_insn nop_insn, mips16_nop_insn;
598 /* The appropriate nop for the current mode. */
599 #define NOP_INSN (mips_opts.mips16 ? &mips16_nop_insn : &nop_insn)
601 /* If this is set, it points to a frag holding nop instructions which
602 were inserted before the start of a noreorder section. If those
603 nops turn out to be unnecessary, the size of the frag can be
605 static fragS *prev_nop_frag;
607 /* The number of nop instructions we created in prev_nop_frag. */
608 static int prev_nop_frag_holds;
610 /* The number of nop instructions that we know we need in
612 static int prev_nop_frag_required;
614 /* The number of instructions we've seen since prev_nop_frag. */
615 static int prev_nop_frag_since;
617 /* For ECOFF and ELF, relocations against symbols are done in two
618 parts, with a HI relocation and a LO relocation. Each relocation
619 has only 16 bits of space to store an addend. This means that in
620 order for the linker to handle carries correctly, it must be able
621 to locate both the HI and the LO relocation. This means that the
622 relocations must appear in order in the relocation table.
624 In order to implement this, we keep track of each unmatched HI
625 relocation. We then sort them so that they immediately precede the
626 corresponding LO relocation. */
631 struct mips_hi_fixup *next;
634 /* The section this fixup is in. */
638 /* The list of unmatched HI relocs. */
640 static struct mips_hi_fixup *mips_hi_fixup_list;
642 /* The frag containing the last explicit relocation operator.
643 Null if explicit relocations have not been used. */
645 static fragS *prev_reloc_op_frag;
647 /* Map normal MIPS register numbers to mips16 register numbers. */
649 #define X ILLEGAL_REG
650 static const int mips32_to_16_reg_map[] =
652 X, X, 2, 3, 4, 5, 6, 7,
653 X, X, X, X, X, X, X, X,
654 0, 1, X, X, X, X, X, X,
655 X, X, X, X, X, X, X, X
659 /* Map mips16 register numbers to normal MIPS register numbers. */
661 static const unsigned int mips16_to_32_reg_map[] =
663 16, 17, 2, 3, 4, 5, 6, 7
666 /* Classifies the kind of instructions we're interested in when
667 implementing -mfix-vr4120. */
668 enum fix_vr4120_class {
675 NUM_FIX_VR4120_CLASSES
678 /* Given two FIX_VR4120_* values X and Y, bit Y of element X is set if
679 there must be at least one other instruction between an instruction
680 of type X and an instruction of type Y. */
681 static unsigned int vr4120_conflicts[NUM_FIX_VR4120_CLASSES];
683 /* True if -mfix-vr4120 is in force. */
684 static int mips_fix_vr4120;
686 /* ...likewise -mfix-vr4130. */
687 static int mips_fix_vr4130;
689 /* We don't relax branches by default, since this causes us to expand
690 `la .l2 - .l1' if there's a branch between .l1 and .l2, because we
691 fail to compute the offset before expanding the macro to the most
692 efficient expansion. */
694 static int mips_relax_branch;
696 /* The expansion of many macros depends on the type of symbol that
697 they refer to. For example, when generating position-dependent code,
698 a macro that refers to a symbol may have two different expansions,
699 one which uses GP-relative addresses and one which uses absolute
700 addresses. When generating SVR4-style PIC, a macro may have
701 different expansions for local and global symbols.
703 We handle these situations by generating both sequences and putting
704 them in variant frags. In position-dependent code, the first sequence
705 will be the GP-relative one and the second sequence will be the
706 absolute one. In SVR4 PIC, the first sequence will be for global
707 symbols and the second will be for local symbols.
709 The frag's "subtype" is RELAX_ENCODE (FIRST, SECOND), where FIRST and
710 SECOND are the lengths of the two sequences in bytes. These fields
711 can be extracted using RELAX_FIRST() and RELAX_SECOND(). In addition,
712 the subtype has the following flags:
715 Set if it has been decided that we should use the second
716 sequence instead of the first.
719 Set in the first variant frag if the macro's second implementation
720 is longer than its first. This refers to the macro as a whole,
721 not an individual relaxation.
724 Set in the first variant frag if the macro appeared in a .set nomacro
725 block and if one alternative requires a warning but the other does not.
728 Like RELAX_NOMACRO, but indicates that the macro appears in a branch
731 The frag's "opcode" points to the first fixup for relaxable code.
733 Relaxable macros are generated using a sequence such as:
735 relax_start (SYMBOL);
736 ... generate first expansion ...
738 ... generate second expansion ...
741 The code and fixups for the unwanted alternative are discarded
742 by md_convert_frag. */
743 #define RELAX_ENCODE(FIRST, SECOND) (((FIRST) << 8) | (SECOND))
745 #define RELAX_FIRST(X) (((X) >> 8) & 0xff)
746 #define RELAX_SECOND(X) ((X) & 0xff)
747 #define RELAX_USE_SECOND 0x10000
748 #define RELAX_SECOND_LONGER 0x20000
749 #define RELAX_NOMACRO 0x40000
750 #define RELAX_DELAY_SLOT 0x80000
752 /* Branch without likely bit. If label is out of range, we turn:
754 beq reg1, reg2, label
764 with the following opcode replacements:
771 bltzal <-> bgezal (with jal label instead of j label)
773 Even though keeping the delay slot instruction in the delay slot of
774 the branch would be more efficient, it would be very tricky to do
775 correctly, because we'd have to introduce a variable frag *after*
776 the delay slot instruction, and expand that instead. Let's do it
777 the easy way for now, even if the branch-not-taken case now costs
778 one additional instruction. Out-of-range branches are not supposed
779 to be common, anyway.
781 Branch likely. If label is out of range, we turn:
783 beql reg1, reg2, label
784 delay slot (annulled if branch not taken)
793 delay slot (executed only if branch taken)
796 It would be possible to generate a shorter sequence by losing the
797 likely bit, generating something like:
802 delay slot (executed only if branch taken)
814 bltzall -> bgezal (with jal label instead of j label)
815 bgezall -> bltzal (ditto)
818 but it's not clear that it would actually improve performance. */
819 #define RELAX_BRANCH_ENCODE(uncond, likely, link, toofar) \
822 | ((toofar) ? 1 : 0) \
824 | ((likely) ? 4 : 0) \
825 | ((uncond) ? 8 : 0)))
826 #define RELAX_BRANCH_P(i) (((i) & 0xf0000000) == 0xc0000000)
827 #define RELAX_BRANCH_UNCOND(i) (((i) & 8) != 0)
828 #define RELAX_BRANCH_LIKELY(i) (((i) & 4) != 0)
829 #define RELAX_BRANCH_LINK(i) (((i) & 2) != 0)
830 #define RELAX_BRANCH_TOOFAR(i) (((i) & 1) != 0)
832 /* For mips16 code, we use an entirely different form of relaxation.
833 mips16 supports two versions of most instructions which take
834 immediate values: a small one which takes some small value, and a
835 larger one which takes a 16 bit value. Since branches also follow
836 this pattern, relaxing these values is required.
838 We can assemble both mips16 and normal MIPS code in a single
839 object. Therefore, we need to support this type of relaxation at
840 the same time that we support the relaxation described above. We
841 use the high bit of the subtype field to distinguish these cases.
843 The information we store for this type of relaxation is the
844 argument code found in the opcode file for this relocation, whether
845 the user explicitly requested a small or extended form, and whether
846 the relocation is in a jump or jal delay slot. That tells us the
847 size of the value, and how it should be stored. We also store
848 whether the fragment is considered to be extended or not. We also
849 store whether this is known to be a branch to a different section,
850 whether we have tried to relax this frag yet, and whether we have
851 ever extended a PC relative fragment because of a shift count. */
852 #define RELAX_MIPS16_ENCODE(type, small, ext, dslot, jal_dslot) \
855 | ((small) ? 0x100 : 0) \
856 | ((ext) ? 0x200 : 0) \
857 | ((dslot) ? 0x400 : 0) \
858 | ((jal_dslot) ? 0x800 : 0))
859 #define RELAX_MIPS16_P(i) (((i) & 0xc0000000) == 0x80000000)
860 #define RELAX_MIPS16_TYPE(i) ((i) & 0xff)
861 #define RELAX_MIPS16_USER_SMALL(i) (((i) & 0x100) != 0)
862 #define RELAX_MIPS16_USER_EXT(i) (((i) & 0x200) != 0)
863 #define RELAX_MIPS16_DSLOT(i) (((i) & 0x400) != 0)
864 #define RELAX_MIPS16_JAL_DSLOT(i) (((i) & 0x800) != 0)
865 #define RELAX_MIPS16_EXTENDED(i) (((i) & 0x1000) != 0)
866 #define RELAX_MIPS16_MARK_EXTENDED(i) ((i) | 0x1000)
867 #define RELAX_MIPS16_CLEAR_EXTENDED(i) ((i) &~ 0x1000)
868 #define RELAX_MIPS16_LONG_BRANCH(i) (((i) & 0x2000) != 0)
869 #define RELAX_MIPS16_MARK_LONG_BRANCH(i) ((i) | 0x2000)
870 #define RELAX_MIPS16_CLEAR_LONG_BRANCH(i) ((i) &~ 0x2000)
872 /* Is the given value a sign-extended 32-bit value? */
873 #define IS_SEXT_32BIT_NUM(x) \
874 (((x) &~ (offsetT) 0x7fffffff) == 0 \
875 || (((x) &~ (offsetT) 0x7fffffff) == ~ (offsetT) 0x7fffffff))
877 /* Is the given value a sign-extended 16-bit value? */
878 #define IS_SEXT_16BIT_NUM(x) \
879 (((x) &~ (offsetT) 0x7fff) == 0 \
880 || (((x) &~ (offsetT) 0x7fff) == ~ (offsetT) 0x7fff))
882 /* Is the given value a zero-extended 32-bit value? Or a negated one? */
883 #define IS_ZEXT_32BIT_NUM(x) \
884 (((x) &~ (offsetT) 0xffffffff) == 0 \
885 || (((x) &~ (offsetT) 0xffffffff) == ~ (offsetT) 0xffffffff))
887 /* Replace bits MASK << SHIFT of STRUCT with the equivalent bits in
888 VALUE << SHIFT. VALUE is evaluated exactly once. */
889 #define INSERT_BITS(STRUCT, VALUE, MASK, SHIFT) \
890 (STRUCT) = (((STRUCT) & ~((MASK) << (SHIFT))) \
891 | (((VALUE) & (MASK)) << (SHIFT)))
893 /* Extract bits MASK << SHIFT from STRUCT and shift them right
895 #define EXTRACT_BITS(STRUCT, MASK, SHIFT) \
896 (((STRUCT) >> (SHIFT)) & (MASK))
898 /* Change INSN's opcode so that the operand given by FIELD has value VALUE.
899 INSN is a mips_cl_insn structure and VALUE is evaluated exactly once.
901 include/opcode/mips.h specifies operand fields using the macros
902 OP_MASK_<FIELD> and OP_SH_<FIELD>. The MIPS16 equivalents start
903 with "MIPS16OP" instead of "OP". */
904 #define INSERT_OPERAND(FIELD, INSN, VALUE) \
905 INSERT_BITS ((INSN).insn_opcode, VALUE, OP_MASK_##FIELD, OP_SH_##FIELD)
906 #define MIPS16_INSERT_OPERAND(FIELD, INSN, VALUE) \
907 INSERT_BITS ((INSN).insn_opcode, VALUE, \
908 MIPS16OP_MASK_##FIELD, MIPS16OP_SH_##FIELD)
910 /* Extract the operand given by FIELD from mips_cl_insn INSN. */
911 #define EXTRACT_OPERAND(FIELD, INSN) \
912 EXTRACT_BITS ((INSN).insn_opcode, OP_MASK_##FIELD, OP_SH_##FIELD)
913 #define MIPS16_EXTRACT_OPERAND(FIELD, INSN) \
914 EXTRACT_BITS ((INSN).insn_opcode, \
915 MIPS16OP_MASK_##FIELD, \
918 /* Global variables used when generating relaxable macros. See the
919 comment above RELAX_ENCODE for more details about how relaxation
922 /* 0 if we're not emitting a relaxable macro.
923 1 if we're emitting the first of the two relaxation alternatives.
924 2 if we're emitting the second alternative. */
927 /* The first relaxable fixup in the current frag. (In other words,
928 the first fixup that refers to relaxable code.) */
931 /* sizes[0] says how many bytes of the first alternative are stored in
932 the current frag. Likewise sizes[1] for the second alternative. */
933 unsigned int sizes[2];
935 /* The symbol on which the choice of sequence depends. */
939 /* Global variables used to decide whether a macro needs a warning. */
941 /* True if the macro is in a branch delay slot. */
942 bfd_boolean delay_slot_p;
944 /* For relaxable macros, sizes[0] is the length of the first alternative
945 in bytes and sizes[1] is the length of the second alternative.
946 For non-relaxable macros, both elements give the length of the
948 unsigned int sizes[2];
950 /* The first variant frag for this macro. */
952 } mips_macro_warning;
954 /* Prototypes for static functions. */
956 #define internalError() \
957 as_fatal (_("internal Error, line %d, %s"), __LINE__, __FILE__)
959 enum mips_regclass { MIPS_GR_REG, MIPS_FP_REG, MIPS16_REG };
961 static void append_insn
962 (struct mips_cl_insn *ip, expressionS *p, bfd_reloc_code_real_type *r);
963 static void mips_no_prev_insn (void);
964 static void mips16_macro_build
965 (expressionS *, const char *, const char *, va_list);
966 static void load_register (int, expressionS *, int);
967 static void macro_start (void);
968 static void macro_end (void);
969 static void macro (struct mips_cl_insn * ip);
970 static void mips16_macro (struct mips_cl_insn * ip);
971 #ifdef LOSING_COMPILER
972 static void macro2 (struct mips_cl_insn * ip);
974 static void mips_ip (char *str, struct mips_cl_insn * ip);
975 static void mips16_ip (char *str, struct mips_cl_insn * ip);
976 static void mips16_immed
977 (char *, unsigned int, int, offsetT, bfd_boolean, bfd_boolean, bfd_boolean,
978 unsigned long *, bfd_boolean *, unsigned short *);
979 static size_t my_getSmallExpression
980 (expressionS *, bfd_reloc_code_real_type *, char *);
981 static void my_getExpression (expressionS *, char *);
982 static void s_align (int);
983 static void s_change_sec (int);
984 static void s_change_section (int);
985 static void s_cons (int);
986 static void s_float_cons (int);
987 static void s_mips_globl (int);
988 static void s_option (int);
989 static void s_mipsset (int);
990 static void s_abicalls (int);
991 static void s_cpload (int);
992 static void s_cpsetup (int);
993 static void s_cplocal (int);
994 static void s_cprestore (int);
995 static void s_cpreturn (int);
996 static void s_gpvalue (int);
997 static void s_gpword (int);
998 static void s_gpdword (int);
999 static void s_cpadd (int);
1000 static void s_insn (int);
1001 static void md_obj_begin (void);
1002 static void md_obj_end (void);
1003 static void s_mips_ent (int);
1004 static void s_mips_end (int);
1005 static void s_mips_frame (int);
1006 static void s_mips_mask (int reg_type);
1007 static void s_mips_stab (int);
1008 static void s_mips_weakext (int);
1009 static void s_mips_file (int);
1010 static void s_mips_loc (int);
1011 static bfd_boolean pic_need_relax (symbolS *, asection *);
1012 static int relaxed_branch_length (fragS *, asection *, int);
1013 static int validate_mips_insn (const struct mips_opcode *);
1015 /* Table and functions used to map between CPU/ISA names, and
1016 ISA levels, and CPU numbers. */
1018 struct mips_cpu_info
1020 const char *name; /* CPU or ISA name. */
1021 int is_isa; /* Is this an ISA? (If 0, a CPU.) */
1022 int isa; /* ISA level. */
1023 int cpu; /* CPU number (default CPU if ISA). */
1026 static const struct mips_cpu_info *mips_parse_cpu (const char *, const char *);
1027 static const struct mips_cpu_info *mips_cpu_info_from_isa (int);
1028 static const struct mips_cpu_info *mips_cpu_info_from_arch (int);
1032 The following pseudo-ops from the Kane and Heinrich MIPS book
1033 should be defined here, but are currently unsupported: .alias,
1034 .galive, .gjaldef, .gjrlive, .livereg, .noalias.
1036 The following pseudo-ops from the Kane and Heinrich MIPS book are
1037 specific to the type of debugging information being generated, and
1038 should be defined by the object format: .aent, .begin, .bend,
1039 .bgnb, .end, .endb, .ent, .fmask, .frame, .loc, .mask, .verstamp,
1042 The following pseudo-ops from the Kane and Heinrich MIPS book are
1043 not MIPS CPU specific, but are also not specific to the object file
1044 format. This file is probably the best place to define them, but
1045 they are not currently supported: .asm0, .endr, .lab, .repeat,
1048 static const pseudo_typeS mips_pseudo_table[] =
1050 /* MIPS specific pseudo-ops. */
1051 {"option", s_option, 0},
1052 {"set", s_mipsset, 0},
1053 {"rdata", s_change_sec, 'r'},
1054 {"sdata", s_change_sec, 's'},
1055 {"livereg", s_ignore, 0},
1056 {"abicalls", s_abicalls, 0},
1057 {"cpload", s_cpload, 0},
1058 {"cpsetup", s_cpsetup, 0},
1059 {"cplocal", s_cplocal, 0},
1060 {"cprestore", s_cprestore, 0},
1061 {"cpreturn", s_cpreturn, 0},
1062 {"gpvalue", s_gpvalue, 0},
1063 {"gpword", s_gpword, 0},
1064 {"gpdword", s_gpdword, 0},
1065 {"cpadd", s_cpadd, 0},
1066 {"insn", s_insn, 0},
1068 /* Relatively generic pseudo-ops that happen to be used on MIPS
1070 {"asciiz", stringer, 1},
1071 {"bss", s_change_sec, 'b'},
1073 {"half", s_cons, 1},
1074 {"dword", s_cons, 3},
1075 {"weakext", s_mips_weakext, 0},
1077 /* These pseudo-ops are defined in read.c, but must be overridden
1078 here for one reason or another. */
1079 {"align", s_align, 0},
1080 {"byte", s_cons, 0},
1081 {"data", s_change_sec, 'd'},
1082 {"double", s_float_cons, 'd'},
1083 {"float", s_float_cons, 'f'},
1084 {"globl", s_mips_globl, 0},
1085 {"global", s_mips_globl, 0},
1086 {"hword", s_cons, 1},
1088 {"long", s_cons, 2},
1089 {"octa", s_cons, 4},
1090 {"quad", s_cons, 3},
1091 {"section", s_change_section, 0},
1092 {"short", s_cons, 1},
1093 {"single", s_float_cons, 'f'},
1094 {"stabn", s_mips_stab, 'n'},
1095 {"text", s_change_sec, 't'},
1096 {"word", s_cons, 2},
1098 { "extern", ecoff_directive_extern, 0},
1103 static const pseudo_typeS mips_nonecoff_pseudo_table[] =
1105 /* These pseudo-ops should be defined by the object file format.
1106 However, a.out doesn't support them, so we have versions here. */
1107 {"aent", s_mips_ent, 1},
1108 {"bgnb", s_ignore, 0},
1109 {"end", s_mips_end, 0},
1110 {"endb", s_ignore, 0},
1111 {"ent", s_mips_ent, 0},
1112 {"file", s_mips_file, 0},
1113 {"fmask", s_mips_mask, 'F'},
1114 {"frame", s_mips_frame, 0},
1115 {"loc", s_mips_loc, 0},
1116 {"mask", s_mips_mask, 'R'},
1117 {"verstamp", s_ignore, 0},
1121 extern void pop_insert (const pseudo_typeS *);
1124 mips_pop_insert (void)
1126 pop_insert (mips_pseudo_table);
1127 if (! ECOFF_DEBUGGING)
1128 pop_insert (mips_nonecoff_pseudo_table);
1131 /* Symbols labelling the current insn. */
1133 struct insn_label_list
1135 struct insn_label_list *next;
1139 static struct insn_label_list *insn_labels;
1140 static struct insn_label_list *free_insn_labels;
1142 static void mips_clear_insn_labels (void);
1145 mips_clear_insn_labels (void)
1147 register struct insn_label_list **pl;
1149 for (pl = &free_insn_labels; *pl != NULL; pl = &(*pl)->next)
1155 static char *expr_end;
1157 /* Expressions which appear in instructions. These are set by
1160 static expressionS imm_expr;
1161 static expressionS imm2_expr;
1162 static expressionS offset_expr;
1164 /* Relocs associated with imm_expr and offset_expr. */
1166 static bfd_reloc_code_real_type imm_reloc[3]
1167 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
1168 static bfd_reloc_code_real_type offset_reloc[3]
1169 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
1171 /* These are set by mips16_ip if an explicit extension is used. */
1173 static bfd_boolean mips16_small, mips16_ext;
1176 /* The pdr segment for per procedure frame/regmask info. Not used for
1179 static segT pdr_seg;
1182 /* The default target format to use. */
1185 mips_target_format (void)
1187 switch (OUTPUT_FLAVOR)
1189 case bfd_target_ecoff_flavour:
1190 return target_big_endian ? "ecoff-bigmips" : ECOFF_LITTLE_FORMAT;
1191 case bfd_target_coff_flavour:
1193 case bfd_target_elf_flavour:
1195 /* This is traditional mips. */
1196 return (target_big_endian
1197 ? (HAVE_64BIT_OBJECTS
1198 ? "elf64-tradbigmips"
1200 ? "elf32-ntradbigmips" : "elf32-tradbigmips"))
1201 : (HAVE_64BIT_OBJECTS
1202 ? "elf64-tradlittlemips"
1204 ? "elf32-ntradlittlemips" : "elf32-tradlittlemips")));
1206 return (target_big_endian
1207 ? (HAVE_64BIT_OBJECTS
1210 ? "elf32-nbigmips" : "elf32-bigmips"))
1211 : (HAVE_64BIT_OBJECTS
1212 ? "elf64-littlemips"
1214 ? "elf32-nlittlemips" : "elf32-littlemips")));
1222 /* Return the length of instruction INSN. */
1224 static inline unsigned int
1225 insn_length (const struct mips_cl_insn *insn)
1227 if (!mips_opts.mips16)
1229 return insn->mips16_absolute_jump_p || insn->use_extend ? 4 : 2;
1232 /* Initialise INSN from opcode entry MO. Leave its position unspecified. */
1235 create_insn (struct mips_cl_insn *insn, const struct mips_opcode *mo)
1240 insn->use_extend = FALSE;
1242 insn->insn_opcode = mo->match;
1245 for (i = 0; i < ARRAY_SIZE (insn->fixp); i++)
1246 insn->fixp[i] = NULL;
1247 insn->fixed_p = (mips_opts.noreorder > 0);
1248 insn->noreorder_p = (mips_opts.noreorder > 0);
1249 insn->mips16_absolute_jump_p = 0;
1252 /* Install INSN at the location specified by its "frag" and "where" fields. */
1255 install_insn (const struct mips_cl_insn *insn)
1257 char *f = insn->frag->fr_literal + insn->where;
1258 if (!mips_opts.mips16)
1259 md_number_to_chars (f, insn->insn_opcode, 4);
1260 else if (insn->mips16_absolute_jump_p)
1262 md_number_to_chars (f, insn->insn_opcode >> 16, 2);
1263 md_number_to_chars (f + 2, insn->insn_opcode & 0xffff, 2);
1267 if (insn->use_extend)
1269 md_number_to_chars (f, 0xf000 | insn->extend, 2);
1272 md_number_to_chars (f, insn->insn_opcode, 2);
1276 /* Move INSN to offset WHERE in FRAG. Adjust the fixups accordingly
1277 and install the opcode in the new location. */
1280 move_insn (struct mips_cl_insn *insn, fragS *frag, long where)
1285 insn->where = where;
1286 for (i = 0; i < ARRAY_SIZE (insn->fixp); i++)
1287 if (insn->fixp[i] != NULL)
1289 insn->fixp[i]->fx_frag = frag;
1290 insn->fixp[i]->fx_where = where;
1292 install_insn (insn);
1295 /* Add INSN to the end of the output. */
1298 add_fixed_insn (struct mips_cl_insn *insn)
1300 char *f = frag_more (insn_length (insn));
1301 move_insn (insn, frag_now, f - frag_now->fr_literal);
1304 /* Start a variant frag and move INSN to the start of the variant part,
1305 marking it as fixed. The other arguments are as for frag_var. */
1308 add_relaxed_insn (struct mips_cl_insn *insn, int max_chars, int var,
1309 relax_substateT subtype, symbolS *symbol, offsetT offset)
1311 frag_grow (max_chars);
1312 move_insn (insn, frag_now, frag_more (0) - frag_now->fr_literal);
1314 frag_var (rs_machine_dependent, max_chars, var,
1315 subtype, symbol, offset, NULL);
1318 /* Insert N copies of INSN into the history buffer, starting at
1319 position FIRST. Neither FIRST nor N need to be clipped. */
1322 insert_into_history (unsigned int first, unsigned int n,
1323 const struct mips_cl_insn *insn)
1325 if (mips_relax.sequence != 2)
1329 for (i = ARRAY_SIZE (history); i-- > first;)
1331 history[i] = history[i - n];
1337 /* Emit a nop instruction, recording it in the history buffer. */
1342 add_fixed_insn (NOP_INSN);
1343 insert_into_history (0, 1, NOP_INSN);
1346 /* Initialize vr4120_conflicts. There is a bit of duplication here:
1347 the idea is to make it obvious at a glance that each errata is
1351 init_vr4120_conflicts (void)
1353 #define CONFLICT(FIRST, SECOND) \
1354 vr4120_conflicts[FIX_VR4120_##FIRST] |= 1 << FIX_VR4120_##SECOND
1356 /* Errata 21 - [D]DIV[U] after [D]MACC */
1357 CONFLICT (MACC, DIV);
1358 CONFLICT (DMACC, DIV);
1360 /* Errata 23 - Continuous DMULT[U]/DMACC instructions. */
1361 CONFLICT (DMULT, DMULT);
1362 CONFLICT (DMULT, DMACC);
1363 CONFLICT (DMACC, DMULT);
1364 CONFLICT (DMACC, DMACC);
1366 /* Errata 24 - MT{LO,HI} after [D]MACC */
1367 CONFLICT (MACC, MTHILO);
1368 CONFLICT (DMACC, MTHILO);
1370 /* VR4181A errata MD(1): "If a MULT, MULTU, DMULT or DMULTU
1371 instruction is executed immediately after a MACC or DMACC
1372 instruction, the result of [either instruction] is incorrect." */
1373 CONFLICT (MACC, MULT);
1374 CONFLICT (MACC, DMULT);
1375 CONFLICT (DMACC, MULT);
1376 CONFLICT (DMACC, DMULT);
1378 /* VR4181A errata MD(4): "If a MACC or DMACC instruction is
1379 executed immediately after a DMULT, DMULTU, DIV, DIVU,
1380 DDIV or DDIVU instruction, the result of the MACC or
1381 DMACC instruction is incorrect.". */
1382 CONFLICT (DMULT, MACC);
1383 CONFLICT (DMULT, DMACC);
1384 CONFLICT (DIV, MACC);
1385 CONFLICT (DIV, DMACC);
1390 /* This function is called once, at assembler startup time. It should
1391 set up all the tables, etc. that the MD part of the assembler will need. */
1396 register const char *retval = NULL;
1400 if (! bfd_set_arch_mach (stdoutput, bfd_arch_mips, file_mips_arch))
1401 as_warn (_("Could not set architecture and machine"));
1403 op_hash = hash_new ();
1405 for (i = 0; i < NUMOPCODES;)
1407 const char *name = mips_opcodes[i].name;
1409 retval = hash_insert (op_hash, name, (void *) &mips_opcodes[i]);
1412 fprintf (stderr, _("internal error: can't hash `%s': %s\n"),
1413 mips_opcodes[i].name, retval);
1414 /* Probably a memory allocation problem? Give up now. */
1415 as_fatal (_("Broken assembler. No assembly attempted."));
1419 if (mips_opcodes[i].pinfo != INSN_MACRO)
1421 if (!validate_mips_insn (&mips_opcodes[i]))
1423 if (nop_insn.insn_mo == NULL && strcmp (name, "nop") == 0)
1425 create_insn (&nop_insn, mips_opcodes + i);
1426 nop_insn.fixed_p = 1;
1431 while ((i < NUMOPCODES) && !strcmp (mips_opcodes[i].name, name));
1434 mips16_op_hash = hash_new ();
1437 while (i < bfd_mips16_num_opcodes)
1439 const char *name = mips16_opcodes[i].name;
1441 retval = hash_insert (mips16_op_hash, name, (void *) &mips16_opcodes[i]);
1443 as_fatal (_("internal: can't hash `%s': %s"),
1444 mips16_opcodes[i].name, retval);
1447 if (mips16_opcodes[i].pinfo != INSN_MACRO
1448 && ((mips16_opcodes[i].match & mips16_opcodes[i].mask)
1449 != mips16_opcodes[i].match))
1451 fprintf (stderr, _("internal error: bad mips16 opcode: %s %s\n"),
1452 mips16_opcodes[i].name, mips16_opcodes[i].args);
1455 if (mips16_nop_insn.insn_mo == NULL && strcmp (name, "nop") == 0)
1457 create_insn (&mips16_nop_insn, mips16_opcodes + i);
1458 mips16_nop_insn.fixed_p = 1;
1462 while (i < bfd_mips16_num_opcodes
1463 && strcmp (mips16_opcodes[i].name, name) == 0);
1467 as_fatal (_("Broken assembler. No assembly attempted."));
1469 /* We add all the general register names to the symbol table. This
1470 helps us detect invalid uses of them. */
1471 for (i = 0; i < 32; i++)
1475 sprintf (buf, "$%d", i);
1476 symbol_table_insert (symbol_new (buf, reg_section, i,
1477 &zero_address_frag));
1479 symbol_table_insert (symbol_new ("$ra", reg_section, RA,
1480 &zero_address_frag));
1481 symbol_table_insert (symbol_new ("$fp", reg_section, FP,
1482 &zero_address_frag));
1483 symbol_table_insert (symbol_new ("$sp", reg_section, SP,
1484 &zero_address_frag));
1485 symbol_table_insert (symbol_new ("$gp", reg_section, GP,
1486 &zero_address_frag));
1487 symbol_table_insert (symbol_new ("$at", reg_section, AT,
1488 &zero_address_frag));
1489 symbol_table_insert (symbol_new ("$kt0", reg_section, KT0,
1490 &zero_address_frag));
1491 symbol_table_insert (symbol_new ("$kt1", reg_section, KT1,
1492 &zero_address_frag));
1493 symbol_table_insert (symbol_new ("$zero", reg_section, ZERO,
1494 &zero_address_frag));
1495 symbol_table_insert (symbol_new ("$pc", reg_section, -1,
1496 &zero_address_frag));
1498 /* If we don't add these register names to the symbol table, they
1499 may end up being added as regular symbols by operand(), and then
1500 make it to the object file as undefined in case they're not
1501 regarded as local symbols. They're local in o32, since `$' is a
1502 local symbol prefix, but not in n32 or n64. */
1503 for (i = 0; i < 8; i++)
1507 sprintf (buf, "$fcc%i", i);
1508 symbol_table_insert (symbol_new (buf, reg_section, -1,
1509 &zero_address_frag));
1512 mips_no_prev_insn ();
1515 mips_cprmask[0] = 0;
1516 mips_cprmask[1] = 0;
1517 mips_cprmask[2] = 0;
1518 mips_cprmask[3] = 0;
1520 /* set the default alignment for the text section (2**2) */
1521 record_alignment (text_section, 2);
1523 bfd_set_gp_size (stdoutput, g_switch_value);
1525 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
1527 /* On a native system, sections must be aligned to 16 byte
1528 boundaries. When configured for an embedded ELF target, we
1530 if (strcmp (TARGET_OS, "elf") != 0)
1532 (void) bfd_set_section_alignment (stdoutput, text_section, 4);
1533 (void) bfd_set_section_alignment (stdoutput, data_section, 4);
1534 (void) bfd_set_section_alignment (stdoutput, bss_section, 4);
1537 /* Create a .reginfo section for register masks and a .mdebug
1538 section for debugging information. */
1546 subseg = now_subseg;
1548 /* The ABI says this section should be loaded so that the
1549 running program can access it. However, we don't load it
1550 if we are configured for an embedded target */
1551 flags = SEC_READONLY | SEC_DATA;
1552 if (strcmp (TARGET_OS, "elf") != 0)
1553 flags |= SEC_ALLOC | SEC_LOAD;
1555 if (mips_abi != N64_ABI)
1557 sec = subseg_new (".reginfo", (subsegT) 0);
1559 bfd_set_section_flags (stdoutput, sec, flags);
1560 bfd_set_section_alignment (stdoutput, sec, HAVE_NEWABI ? 3 : 2);
1563 mips_regmask_frag = frag_more (sizeof (Elf32_External_RegInfo));
1568 /* The 64-bit ABI uses a .MIPS.options section rather than
1569 .reginfo section. */
1570 sec = subseg_new (".MIPS.options", (subsegT) 0);
1571 bfd_set_section_flags (stdoutput, sec, flags);
1572 bfd_set_section_alignment (stdoutput, sec, 3);
1575 /* Set up the option header. */
1577 Elf_Internal_Options opthdr;
1580 opthdr.kind = ODK_REGINFO;
1581 opthdr.size = (sizeof (Elf_External_Options)
1582 + sizeof (Elf64_External_RegInfo));
1585 f = frag_more (sizeof (Elf_External_Options));
1586 bfd_mips_elf_swap_options_out (stdoutput, &opthdr,
1587 (Elf_External_Options *) f);
1589 mips_regmask_frag = frag_more (sizeof (Elf64_External_RegInfo));
1594 if (ECOFF_DEBUGGING)
1596 sec = subseg_new (".mdebug", (subsegT) 0);
1597 (void) bfd_set_section_flags (stdoutput, sec,
1598 SEC_HAS_CONTENTS | SEC_READONLY);
1599 (void) bfd_set_section_alignment (stdoutput, sec, 2);
1602 else if (OUTPUT_FLAVOR == bfd_target_elf_flavour && mips_flag_pdr)
1604 pdr_seg = subseg_new (".pdr", (subsegT) 0);
1605 (void) bfd_set_section_flags (stdoutput, pdr_seg,
1606 SEC_READONLY | SEC_RELOC
1608 (void) bfd_set_section_alignment (stdoutput, pdr_seg, 2);
1612 subseg_set (seg, subseg);
1616 if (! ECOFF_DEBUGGING)
1619 if (mips_fix_vr4120)
1620 init_vr4120_conflicts ();
1626 if (! ECOFF_DEBUGGING)
1631 md_assemble (char *str)
1633 struct mips_cl_insn insn;
1634 bfd_reloc_code_real_type unused_reloc[3]
1635 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
1637 imm_expr.X_op = O_absent;
1638 imm2_expr.X_op = O_absent;
1639 offset_expr.X_op = O_absent;
1640 imm_reloc[0] = BFD_RELOC_UNUSED;
1641 imm_reloc[1] = BFD_RELOC_UNUSED;
1642 imm_reloc[2] = BFD_RELOC_UNUSED;
1643 offset_reloc[0] = BFD_RELOC_UNUSED;
1644 offset_reloc[1] = BFD_RELOC_UNUSED;
1645 offset_reloc[2] = BFD_RELOC_UNUSED;
1647 if (mips_opts.mips16)
1648 mips16_ip (str, &insn);
1651 mips_ip (str, &insn);
1652 DBG ((_("returned from mips_ip(%s) insn_opcode = 0x%x\n"),
1653 str, insn.insn_opcode));
1658 as_bad ("%s `%s'", insn_error, str);
1662 if (insn.insn_mo->pinfo == INSN_MACRO)
1665 if (mips_opts.mips16)
1666 mips16_macro (&insn);
1673 if (imm_expr.X_op != O_absent)
1674 append_insn (&insn, &imm_expr, imm_reloc);
1675 else if (offset_expr.X_op != O_absent)
1676 append_insn (&insn, &offset_expr, offset_reloc);
1678 append_insn (&insn, NULL, unused_reloc);
1682 /* Return true if the given relocation might need a matching %lo().
1683 Note that R_MIPS_GOT16 relocations only need a matching %lo() when
1684 applied to local symbols. */
1686 static inline bfd_boolean
1687 reloc_needs_lo_p (bfd_reloc_code_real_type reloc)
1689 return (HAVE_IN_PLACE_ADDENDS
1690 && (reloc == BFD_RELOC_HI16_S
1691 || reloc == BFD_RELOC_MIPS_GOT16
1692 || reloc == BFD_RELOC_MIPS16_HI16_S));
1695 /* Return true if the given fixup is followed by a matching R_MIPS_LO16
1698 static inline bfd_boolean
1699 fixup_has_matching_lo_p (fixS *fixp)
1701 return (fixp->fx_next != NULL
1702 && (fixp->fx_next->fx_r_type == BFD_RELOC_LO16
1703 || fixp->fx_next->fx_r_type == BFD_RELOC_MIPS16_LO16)
1704 && fixp->fx_addsy == fixp->fx_next->fx_addsy
1705 && fixp->fx_offset == fixp->fx_next->fx_offset);
1708 /* See whether instruction IP reads register REG. CLASS is the type
1712 insn_uses_reg (const struct mips_cl_insn *ip, unsigned int reg,
1713 enum mips_regclass class)
1715 if (class == MIPS16_REG)
1717 assert (mips_opts.mips16);
1718 reg = mips16_to_32_reg_map[reg];
1719 class = MIPS_GR_REG;
1722 /* Don't report on general register ZERO, since it never changes. */
1723 if (class == MIPS_GR_REG && reg == ZERO)
1726 if (class == MIPS_FP_REG)
1728 assert (! mips_opts.mips16);
1729 /* If we are called with either $f0 or $f1, we must check $f0.
1730 This is not optimal, because it will introduce an unnecessary
1731 NOP between "lwc1 $f0" and "swc1 $f1". To fix this we would
1732 need to distinguish reading both $f0 and $f1 or just one of
1733 them. Note that we don't have to check the other way,
1734 because there is no instruction that sets both $f0 and $f1
1735 and requires a delay. */
1736 if ((ip->insn_mo->pinfo & INSN_READ_FPR_S)
1737 && ((EXTRACT_OPERAND (FS, *ip) & ~(unsigned) 1)
1738 == (reg &~ (unsigned) 1)))
1740 if ((ip->insn_mo->pinfo & INSN_READ_FPR_T)
1741 && ((EXTRACT_OPERAND (FT, *ip) & ~(unsigned) 1)
1742 == (reg &~ (unsigned) 1)))
1745 else if (! mips_opts.mips16)
1747 if ((ip->insn_mo->pinfo & INSN_READ_GPR_S)
1748 && EXTRACT_OPERAND (RS, *ip) == reg)
1750 if ((ip->insn_mo->pinfo & INSN_READ_GPR_T)
1751 && EXTRACT_OPERAND (RT, *ip) == reg)
1756 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_X)
1757 && mips16_to_32_reg_map[MIPS16_EXTRACT_OPERAND (RX, *ip)] == reg)
1759 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_Y)
1760 && mips16_to_32_reg_map[MIPS16_EXTRACT_OPERAND (RY, *ip)] == reg)
1762 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_Z)
1763 && (mips16_to_32_reg_map[MIPS16_EXTRACT_OPERAND (MOVE32Z, *ip)]
1766 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_T) && reg == TREG)
1768 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_SP) && reg == SP)
1770 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_31) && reg == RA)
1772 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_GPR_X)
1773 && MIPS16_EXTRACT_OPERAND (REGR32, *ip) == reg)
1780 /* This function returns true if modifying a register requires a
1784 reg_needs_delay (unsigned int reg)
1786 unsigned long prev_pinfo;
1788 prev_pinfo = history[0].insn_mo->pinfo;
1789 if (! mips_opts.noreorder
1790 && (((prev_pinfo & INSN_LOAD_MEMORY_DELAY)
1791 && ! gpr_interlocks)
1792 || ((prev_pinfo & INSN_LOAD_COPROC_DELAY)
1793 && ! cop_interlocks)))
1795 /* A load from a coprocessor or from memory. All load delays
1796 delay the use of general register rt for one instruction. */
1797 /* Itbl support may require additional care here. */
1798 know (prev_pinfo & INSN_WRITE_GPR_T);
1799 if (reg == EXTRACT_OPERAND (RT, history[0]))
1806 /* Move all labels in insn_labels to the current insertion point. */
1809 mips_move_labels (void)
1811 struct insn_label_list *l;
1814 for (l = insn_labels; l != NULL; l = l->next)
1816 assert (S_GET_SEGMENT (l->label) == now_seg);
1817 symbol_set_frag (l->label, frag_now);
1818 val = (valueT) frag_now_fix ();
1819 /* mips16 text labels are stored as odd. */
1820 if (mips_opts.mips16)
1822 S_SET_VALUE (l->label, val);
1826 /* Mark instruction labels in mips16 mode. This permits the linker to
1827 handle them specially, such as generating jalx instructions when
1828 needed. We also make them odd for the duration of the assembly, in
1829 order to generate the right sort of code. We will make them even
1830 in the adjust_symtab routine, while leaving them marked. This is
1831 convenient for the debugger and the disassembler. The linker knows
1832 to make them odd again. */
1835 mips16_mark_labels (void)
1837 if (mips_opts.mips16)
1839 struct insn_label_list *l;
1842 for (l = insn_labels; l != NULL; l = l->next)
1845 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
1846 S_SET_OTHER (l->label, STO_MIPS16);
1848 val = S_GET_VALUE (l->label);
1850 S_SET_VALUE (l->label, val + 1);
1855 /* End the current frag. Make it a variant frag and record the
1859 relax_close_frag (void)
1861 mips_macro_warning.first_frag = frag_now;
1862 frag_var (rs_machine_dependent, 0, 0,
1863 RELAX_ENCODE (mips_relax.sizes[0], mips_relax.sizes[1]),
1864 mips_relax.symbol, 0, (char *) mips_relax.first_fixup);
1866 memset (&mips_relax.sizes, 0, sizeof (mips_relax.sizes));
1867 mips_relax.first_fixup = 0;
1870 /* Start a new relaxation sequence whose expansion depends on SYMBOL.
1871 See the comment above RELAX_ENCODE for more details. */
1874 relax_start (symbolS *symbol)
1876 assert (mips_relax.sequence == 0);
1877 mips_relax.sequence = 1;
1878 mips_relax.symbol = symbol;
1881 /* Start generating the second version of a relaxable sequence.
1882 See the comment above RELAX_ENCODE for more details. */
1887 assert (mips_relax.sequence == 1);
1888 mips_relax.sequence = 2;
1891 /* End the current relaxable sequence. */
1896 assert (mips_relax.sequence == 2);
1897 relax_close_frag ();
1898 mips_relax.sequence = 0;
1901 /* Classify an instruction according to the FIX_VR4120_* enumeration.
1902 Return NUM_FIX_VR4120_CLASSES if the instruction isn't affected
1903 by VR4120 errata. */
1906 classify_vr4120_insn (const char *name)
1908 if (strncmp (name, "macc", 4) == 0)
1909 return FIX_VR4120_MACC;
1910 if (strncmp (name, "dmacc", 5) == 0)
1911 return FIX_VR4120_DMACC;
1912 if (strncmp (name, "mult", 4) == 0)
1913 return FIX_VR4120_MULT;
1914 if (strncmp (name, "dmult", 5) == 0)
1915 return FIX_VR4120_DMULT;
1916 if (strstr (name, "div"))
1917 return FIX_VR4120_DIV;
1918 if (strcmp (name, "mtlo") == 0 || strcmp (name, "mthi") == 0)
1919 return FIX_VR4120_MTHILO;
1920 return NUM_FIX_VR4120_CLASSES;
1923 /* Return the number of instructions that must separate INSN1 and INSN2,
1924 where INSN1 is the earlier instruction. Return the worst-case value
1925 for any INSN2 if INSN2 is null. */
1928 insns_between (const struct mips_cl_insn *insn1,
1929 const struct mips_cl_insn *insn2)
1931 unsigned long pinfo1, pinfo2;
1933 /* This function needs to know which pinfo flags are set for INSN2
1934 and which registers INSN2 uses. The former is stored in PINFO2 and
1935 the latter is tested via INSN2_USES_REG. If INSN2 is null, PINFO2
1936 will have every flag set and INSN2_USES_REG will always return true. */
1937 pinfo1 = insn1->insn_mo->pinfo;
1938 pinfo2 = insn2 ? insn2->insn_mo->pinfo : ~0U;
1940 #define INSN2_USES_REG(REG, CLASS) \
1941 (insn2 == NULL || insn_uses_reg (insn2, REG, CLASS))
1943 /* For most targets, write-after-read dependencies on the HI and LO
1944 registers must be separated by at least two instructions. */
1945 if (!hilo_interlocks)
1947 if ((pinfo1 & INSN_READ_LO) && (pinfo2 & INSN_WRITE_LO))
1949 if ((pinfo1 & INSN_READ_HI) && (pinfo2 & INSN_WRITE_HI))
1953 /* If we're working around r7000 errata, there must be two instructions
1954 between an mfhi or mflo and any instruction that uses the result. */
1955 if (mips_7000_hilo_fix
1956 && MF_HILO_INSN (pinfo1)
1957 && INSN2_USES_REG (EXTRACT_OPERAND (RD, *insn1), MIPS_GR_REG))
1960 /* If working around VR4120 errata, check for combinations that need
1961 a single intervening instruction. */
1962 if (mips_fix_vr4120)
1964 unsigned int class1, class2;
1966 class1 = classify_vr4120_insn (insn1->insn_mo->name);
1967 if (class1 != NUM_FIX_VR4120_CLASSES && vr4120_conflicts[class1] != 0)
1971 class2 = classify_vr4120_insn (insn2->insn_mo->name);
1972 if (vr4120_conflicts[class1] & (1 << class2))
1977 if (!mips_opts.mips16)
1979 /* Check for GPR or coprocessor load delays. All such delays
1980 are on the RT register. */
1981 /* Itbl support may require additional care here. */
1982 if ((!gpr_interlocks && (pinfo1 & INSN_LOAD_MEMORY_DELAY))
1983 || (!cop_interlocks && (pinfo1 & INSN_LOAD_COPROC_DELAY)))
1985 know (pinfo1 & INSN_WRITE_GPR_T);
1986 if (INSN2_USES_REG (EXTRACT_OPERAND (RT, *insn1), MIPS_GR_REG))
1990 /* Check for generic coprocessor hazards.
1992 This case is not handled very well. There is no special
1993 knowledge of CP0 handling, and the coprocessors other than
1994 the floating point unit are not distinguished at all. */
1995 /* Itbl support may require additional care here. FIXME!
1996 Need to modify this to include knowledge about
1997 user specified delays! */
1998 else if ((!cop_interlocks && (pinfo1 & INSN_COPROC_MOVE_DELAY))
1999 || (!cop_mem_interlocks && (pinfo1 & INSN_COPROC_MEMORY_DELAY)))
2001 /* Handle cases where INSN1 writes to a known general coprocessor
2002 register. There must be a one instruction delay before INSN2
2003 if INSN2 reads that register, otherwise no delay is needed. */
2004 if (pinfo1 & INSN_WRITE_FPR_T)
2006 if (INSN2_USES_REG (EXTRACT_OPERAND (FT, *insn1), MIPS_FP_REG))
2009 else if (pinfo1 & INSN_WRITE_FPR_S)
2011 if (INSN2_USES_REG (EXTRACT_OPERAND (FS, *insn1), MIPS_FP_REG))
2016 /* Read-after-write dependencies on the control registers
2017 require a two-instruction gap. */
2018 if ((pinfo1 & INSN_WRITE_COND_CODE)
2019 && (pinfo2 & INSN_READ_COND_CODE))
2022 /* We don't know exactly what INSN1 does. If INSN2 is
2023 also a coprocessor instruction, assume there must be
2024 a one instruction gap. */
2025 if (pinfo2 & INSN_COP)
2030 /* Check for read-after-write dependencies on the coprocessor
2031 control registers in cases where INSN1 does not need a general
2032 coprocessor delay. This means that INSN1 is a floating point
2033 comparison instruction. */
2034 /* Itbl support may require additional care here. */
2035 else if (!cop_interlocks
2036 && (pinfo1 & INSN_WRITE_COND_CODE)
2037 && (pinfo2 & INSN_READ_COND_CODE))
2041 #undef INSN2_USES_REG
2046 /* Return the number of nops that would be needed to work around the
2047 VR4130 mflo/mfhi errata if instruction INSN immediately followed
2048 the MAX_VR4130_NOPS instructions described by HISTORY. */
2051 nops_for_vr4130 (const struct mips_cl_insn *history,
2052 const struct mips_cl_insn *insn)
2056 /* Check if the instruction writes to HI or LO. MTHI and MTLO
2057 are not affected by the errata. */
2059 && ((insn->insn_mo->pinfo & (INSN_WRITE_HI | INSN_WRITE_LO)) == 0
2060 || strcmp (insn->insn_mo->name, "mtlo") == 0
2061 || strcmp (insn->insn_mo->name, "mthi") == 0))
2064 /* Search for the first MFLO or MFHI. */
2065 for (i = 0; i < MAX_VR4130_NOPS; i++)
2066 if (!history[i].noreorder_p && MF_HILO_INSN (history[i].insn_mo->pinfo))
2068 /* Extract the destination register. */
2069 if (mips_opts.mips16)
2070 reg = mips16_to_32_reg_map[MIPS16_EXTRACT_OPERAND (RX, history[i])];
2072 reg = EXTRACT_OPERAND (RD, history[i]);
2074 /* No nops are needed if INSN reads that register. */
2075 if (insn != NULL && insn_uses_reg (insn, reg, MIPS_GR_REG))
2078 /* ...or if any of the intervening instructions do. */
2079 for (j = 0; j < i; j++)
2080 if (insn_uses_reg (&history[j], reg, MIPS_GR_REG))
2083 return MAX_VR4130_NOPS - i;
2088 /* Return the number of nops that would be needed if instruction INSN
2089 immediately followed the MAX_NOPS instructions given by HISTORY,
2090 where HISTORY[0] is the most recent instruction. If INSN is null,
2091 return the worse-case number of nops for any instruction. */
2094 nops_for_insn (const struct mips_cl_insn *history,
2095 const struct mips_cl_insn *insn)
2097 int i, nops, tmp_nops;
2100 for (i = 0; i < MAX_DELAY_NOPS; i++)
2101 if (!history[i].noreorder_p)
2103 tmp_nops = insns_between (history + i, insn) - i;
2104 if (tmp_nops > nops)
2108 if (mips_fix_vr4130)
2110 tmp_nops = nops_for_vr4130 (history, insn);
2111 if (tmp_nops > nops)
2118 /* The variable arguments provide NUM_INSNS extra instructions that
2119 might be added to HISTORY. Return the largest number of nops that
2120 would be needed after the extended sequence. */
2123 nops_for_sequence (int num_insns, const struct mips_cl_insn *history, ...)
2126 struct mips_cl_insn buffer[MAX_NOPS];
2127 struct mips_cl_insn *cursor;
2130 va_start (args, history);
2131 cursor = buffer + num_insns;
2132 memcpy (cursor, history, (MAX_NOPS - num_insns) * sizeof (*cursor));
2133 while (cursor > buffer)
2134 *--cursor = *va_arg (args, const struct mips_cl_insn *);
2136 nops = nops_for_insn (buffer, NULL);
2141 /* Like nops_for_insn, but if INSN is a branch, take into account the
2142 worst-case delay for the branch target. */
2145 nops_for_insn_or_target (const struct mips_cl_insn *history,
2146 const struct mips_cl_insn *insn)
2150 nops = nops_for_insn (history, insn);
2151 if (insn->insn_mo->pinfo & (INSN_UNCOND_BRANCH_DELAY
2152 | INSN_COND_BRANCH_DELAY
2153 | INSN_COND_BRANCH_LIKELY))
2155 tmp_nops = nops_for_sequence (2, history, insn, NOP_INSN);
2156 if (tmp_nops > nops)
2159 else if (mips_opts.mips16 && (insn->insn_mo->pinfo & MIPS16_INSN_BRANCH))
2161 tmp_nops = nops_for_sequence (1, history, insn);
2162 if (tmp_nops > nops)
2168 /* Output an instruction. IP is the instruction information.
2169 ADDRESS_EXPR is an operand of the instruction to be used with
2173 append_insn (struct mips_cl_insn *ip, expressionS *address_expr,
2174 bfd_reloc_code_real_type *reloc_type)
2176 register unsigned long prev_pinfo, pinfo;
2177 relax_stateT prev_insn_frag_type = 0;
2178 bfd_boolean relaxed_branch = FALSE;
2180 /* Mark instruction labels in mips16 mode. */
2181 mips16_mark_labels ();
2183 prev_pinfo = history[0].insn_mo->pinfo;
2184 pinfo = ip->insn_mo->pinfo;
2186 if (mips_relax.sequence != 2 && !mips_opts.noreorder)
2188 /* There are a lot of optimizations we could do that we don't.
2189 In particular, we do not, in general, reorder instructions.
2190 If you use gcc with optimization, it will reorder
2191 instructions and generally do much more optimization then we
2192 do here; repeating all that work in the assembler would only
2193 benefit hand written assembly code, and does not seem worth
2195 int nops = (mips_optimize == 0
2196 ? nops_for_insn (history, NULL)
2197 : nops_for_insn_or_target (history, ip));
2201 unsigned long old_frag_offset;
2204 old_frag = frag_now;
2205 old_frag_offset = frag_now_fix ();
2207 for (i = 0; i < nops; i++)
2212 listing_prev_line ();
2213 /* We may be at the start of a variant frag. In case we
2214 are, make sure there is enough space for the frag
2215 after the frags created by listing_prev_line. The
2216 argument to frag_grow here must be at least as large
2217 as the argument to all other calls to frag_grow in
2218 this file. We don't have to worry about being in the
2219 middle of a variant frag, because the variants insert
2220 all needed nop instructions themselves. */
2224 mips_move_labels ();
2226 #ifndef NO_ECOFF_DEBUGGING
2227 if (ECOFF_DEBUGGING)
2228 ecoff_fix_loc (old_frag, old_frag_offset);
2232 else if (mips_relax.sequence != 2 && prev_nop_frag != NULL)
2234 /* Work out how many nops in prev_nop_frag are needed by IP. */
2235 int nops = nops_for_insn_or_target (history, ip);
2236 assert (nops <= prev_nop_frag_holds);
2238 /* Enforce NOPS as a minimum. */
2239 if (nops > prev_nop_frag_required)
2240 prev_nop_frag_required = nops;
2242 if (prev_nop_frag_holds == prev_nop_frag_required)
2244 /* Settle for the current number of nops. Update the history
2245 accordingly (for the benefit of any future .set reorder code). */
2246 prev_nop_frag = NULL;
2247 insert_into_history (prev_nop_frag_since,
2248 prev_nop_frag_holds, NOP_INSN);
2252 /* Allow this instruction to replace one of the nops that was
2253 tentatively added to prev_nop_frag. */
2254 prev_nop_frag->fr_fix -= mips_opts.mips16 ? 2 : 4;
2255 prev_nop_frag_holds--;
2256 prev_nop_frag_since++;
2261 /* The value passed to dwarf2_emit_insn is the distance between
2262 the beginning of the current instruction and the address that
2263 should be recorded in the debug tables. For MIPS16 debug info
2264 we want to use ISA-encoded addresses, so we pass -1 for an
2265 address higher by one than the current. */
2266 dwarf2_emit_insn (mips_opts.mips16 ? -1 : 0);
2269 /* Record the frag type before frag_var. */
2270 if (history[0].frag)
2271 prev_insn_frag_type = history[0].frag->fr_type;
2274 && *reloc_type == BFD_RELOC_16_PCREL_S2
2275 && (pinfo & INSN_UNCOND_BRANCH_DELAY || pinfo & INSN_COND_BRANCH_DELAY
2276 || pinfo & INSN_COND_BRANCH_LIKELY)
2277 && mips_relax_branch
2278 /* Don't try branch relaxation within .set nomacro, or within
2279 .set noat if we use $at for PIC computations. If it turns
2280 out that the branch was out-of-range, we'll get an error. */
2281 && !mips_opts.warn_about_macros
2282 && !(mips_opts.noat && mips_pic != NO_PIC)
2283 && !mips_opts.mips16)
2285 relaxed_branch = TRUE;
2286 add_relaxed_insn (ip, (relaxed_branch_length
2288 (pinfo & INSN_UNCOND_BRANCH_DELAY) ? -1
2289 : (pinfo & INSN_COND_BRANCH_LIKELY) ? 1
2292 (pinfo & INSN_UNCOND_BRANCH_DELAY,
2293 pinfo & INSN_COND_BRANCH_LIKELY,
2294 pinfo & INSN_WRITE_GPR_31,
2296 address_expr->X_add_symbol,
2297 address_expr->X_add_number);
2298 *reloc_type = BFD_RELOC_UNUSED;
2300 else if (*reloc_type > BFD_RELOC_UNUSED)
2302 /* We need to set up a variant frag. */
2303 assert (mips_opts.mips16 && address_expr != NULL);
2304 add_relaxed_insn (ip, 4, 0,
2306 (*reloc_type - BFD_RELOC_UNUSED,
2307 mips16_small, mips16_ext,
2308 prev_pinfo & INSN_UNCOND_BRANCH_DELAY,
2309 history[0].mips16_absolute_jump_p),
2310 make_expr_symbol (address_expr), 0);
2312 else if (mips_opts.mips16
2314 && *reloc_type != BFD_RELOC_MIPS16_JMP)
2316 if ((pinfo & INSN_UNCOND_BRANCH_DELAY) == 0)
2317 /* Make sure there is enough room to swap this instruction with
2318 a following jump instruction. */
2320 add_fixed_insn (ip);
2324 if (mips_opts.mips16
2325 && mips_opts.noreorder
2326 && (prev_pinfo & INSN_UNCOND_BRANCH_DELAY) != 0)
2327 as_warn (_("extended instruction in delay slot"));
2329 if (mips_relax.sequence)
2331 /* If we've reached the end of this frag, turn it into a variant
2332 frag and record the information for the instructions we've
2334 if (frag_room () < 4)
2335 relax_close_frag ();
2336 mips_relax.sizes[mips_relax.sequence - 1] += 4;
2339 if (mips_relax.sequence != 2)
2340 mips_macro_warning.sizes[0] += 4;
2341 if (mips_relax.sequence != 1)
2342 mips_macro_warning.sizes[1] += 4;
2344 if (mips_opts.mips16)
2347 ip->mips16_absolute_jump_p = (*reloc_type == BFD_RELOC_MIPS16_JMP);
2349 add_fixed_insn (ip);
2352 if (address_expr != NULL && *reloc_type <= BFD_RELOC_UNUSED)
2354 if (address_expr->X_op == O_constant)
2358 switch (*reloc_type)
2361 ip->insn_opcode |= address_expr->X_add_number;
2364 case BFD_RELOC_MIPS_HIGHEST:
2365 tmp = (address_expr->X_add_number + 0x800080008000ull) >> 48;
2366 ip->insn_opcode |= tmp & 0xffff;
2369 case BFD_RELOC_MIPS_HIGHER:
2370 tmp = (address_expr->X_add_number + 0x80008000ull) >> 32;
2371 ip->insn_opcode |= tmp & 0xffff;
2374 case BFD_RELOC_HI16_S:
2375 tmp = (address_expr->X_add_number + 0x8000) >> 16;
2376 ip->insn_opcode |= tmp & 0xffff;
2379 case BFD_RELOC_HI16:
2380 ip->insn_opcode |= (address_expr->X_add_number >> 16) & 0xffff;
2383 case BFD_RELOC_UNUSED:
2384 case BFD_RELOC_LO16:
2385 case BFD_RELOC_MIPS_GOT_DISP:
2386 ip->insn_opcode |= address_expr->X_add_number & 0xffff;
2389 case BFD_RELOC_MIPS_JMP:
2390 if ((address_expr->X_add_number & 3) != 0)
2391 as_bad (_("jump to misaligned address (0x%lx)"),
2392 (unsigned long) address_expr->X_add_number);
2393 if (address_expr->X_add_number & ~0xfffffff)
2394 as_bad (_("jump address range overflow (0x%lx)"),
2395 (unsigned long) address_expr->X_add_number);
2396 ip->insn_opcode |= (address_expr->X_add_number >> 2) & 0x3ffffff;
2399 case BFD_RELOC_MIPS16_JMP:
2400 if ((address_expr->X_add_number & 3) != 0)
2401 as_bad (_("jump to misaligned address (0x%lx)"),
2402 (unsigned long) address_expr->X_add_number);
2403 if (address_expr->X_add_number & ~0xfffffff)
2404 as_bad (_("jump address range overflow (0x%lx)"),
2405 (unsigned long) address_expr->X_add_number);
2407 (((address_expr->X_add_number & 0x7c0000) << 3)
2408 | ((address_expr->X_add_number & 0xf800000) >> 7)
2409 | ((address_expr->X_add_number & 0x3fffc) >> 2));
2412 case BFD_RELOC_16_PCREL_S2:
2419 else if (*reloc_type < BFD_RELOC_UNUSED)
2422 reloc_howto_type *howto;
2425 /* In a compound relocation, it is the final (outermost)
2426 operator that determines the relocated field. */
2427 for (i = 1; i < 3; i++)
2428 if (reloc_type[i] == BFD_RELOC_UNUSED)
2431 howto = bfd_reloc_type_lookup (stdoutput, reloc_type[i - 1]);
2432 ip->fixp[0] = fix_new_exp (ip->frag, ip->where,
2433 bfd_get_reloc_size (howto),
2435 reloc_type[0] == BFD_RELOC_16_PCREL_S2,
2438 /* These relocations can have an addend that won't fit in
2439 4 octets for 64bit assembly. */
2441 && ! howto->partial_inplace
2442 && (reloc_type[0] == BFD_RELOC_16
2443 || reloc_type[0] == BFD_RELOC_32
2444 || reloc_type[0] == BFD_RELOC_MIPS_JMP
2445 || reloc_type[0] == BFD_RELOC_HI16_S
2446 || reloc_type[0] == BFD_RELOC_LO16
2447 || reloc_type[0] == BFD_RELOC_GPREL16
2448 || reloc_type[0] == BFD_RELOC_MIPS_LITERAL
2449 || reloc_type[0] == BFD_RELOC_GPREL32
2450 || reloc_type[0] == BFD_RELOC_64
2451 || reloc_type[0] == BFD_RELOC_CTOR
2452 || reloc_type[0] == BFD_RELOC_MIPS_SUB
2453 || reloc_type[0] == BFD_RELOC_MIPS_HIGHEST
2454 || reloc_type[0] == BFD_RELOC_MIPS_HIGHER
2455 || reloc_type[0] == BFD_RELOC_MIPS_SCN_DISP
2456 || reloc_type[0] == BFD_RELOC_MIPS_REL16
2457 || reloc_type[0] == BFD_RELOC_MIPS_RELGOT
2458 || reloc_type[0] == BFD_RELOC_MIPS16_GPREL
2459 || reloc_type[0] == BFD_RELOC_MIPS16_HI16_S
2460 || reloc_type[0] == BFD_RELOC_MIPS16_LO16))
2461 ip->fixp[0]->fx_no_overflow = 1;
2463 if (mips_relax.sequence)
2465 if (mips_relax.first_fixup == 0)
2466 mips_relax.first_fixup = ip->fixp[0];
2468 else if (reloc_needs_lo_p (*reloc_type))
2470 struct mips_hi_fixup *hi_fixup;
2472 /* Reuse the last entry if it already has a matching %lo. */
2473 hi_fixup = mips_hi_fixup_list;
2475 || !fixup_has_matching_lo_p (hi_fixup->fixp))
2477 hi_fixup = ((struct mips_hi_fixup *)
2478 xmalloc (sizeof (struct mips_hi_fixup)));
2479 hi_fixup->next = mips_hi_fixup_list;
2480 mips_hi_fixup_list = hi_fixup;
2482 hi_fixup->fixp = ip->fixp[0];
2483 hi_fixup->seg = now_seg;
2486 /* Add fixups for the second and third relocations, if given.
2487 Note that the ABI allows the second relocation to be
2488 against RSS_UNDEF, RSS_GP, RSS_GP0 or RSS_LOC. At the
2489 moment we only use RSS_UNDEF, but we could add support
2490 for the others if it ever becomes necessary. */
2491 for (i = 1; i < 3; i++)
2492 if (reloc_type[i] != BFD_RELOC_UNUSED)
2494 ip->fixp[i] = fix_new (ip->frag, ip->where,
2495 ip->fixp[0]->fx_size, NULL, 0,
2496 FALSE, reloc_type[i]);
2498 /* Use fx_tcbit to mark compound relocs. */
2499 ip->fixp[0]->fx_tcbit = 1;
2500 ip->fixp[i]->fx_tcbit = 1;
2506 /* Update the register mask information. */
2507 if (! mips_opts.mips16)
2509 if (pinfo & INSN_WRITE_GPR_D)
2510 mips_gprmask |= 1 << EXTRACT_OPERAND (RD, *ip);
2511 if ((pinfo & (INSN_WRITE_GPR_T | INSN_READ_GPR_T)) != 0)
2512 mips_gprmask |= 1 << EXTRACT_OPERAND (RT, *ip);
2513 if (pinfo & INSN_READ_GPR_S)
2514 mips_gprmask |= 1 << EXTRACT_OPERAND (RS, *ip);
2515 if (pinfo & INSN_WRITE_GPR_31)
2516 mips_gprmask |= 1 << RA;
2517 if (pinfo & INSN_WRITE_FPR_D)
2518 mips_cprmask[1] |= 1 << EXTRACT_OPERAND (FD, *ip);
2519 if ((pinfo & (INSN_WRITE_FPR_S | INSN_READ_FPR_S)) != 0)
2520 mips_cprmask[1] |= 1 << EXTRACT_OPERAND (FS, *ip);
2521 if ((pinfo & (INSN_WRITE_FPR_T | INSN_READ_FPR_T)) != 0)
2522 mips_cprmask[1] |= 1 << EXTRACT_OPERAND (FT, *ip);
2523 if ((pinfo & INSN_READ_FPR_R) != 0)
2524 mips_cprmask[1] |= 1 << EXTRACT_OPERAND (FR, *ip);
2525 if (pinfo & INSN_COP)
2527 /* We don't keep enough information to sort these cases out.
2528 The itbl support does keep this information however, although
2529 we currently don't support itbl fprmats as part of the cop
2530 instruction. May want to add this support in the future. */
2532 /* Never set the bit for $0, which is always zero. */
2533 mips_gprmask &= ~1 << 0;
2537 if (pinfo & (MIPS16_INSN_WRITE_X | MIPS16_INSN_READ_X))
2538 mips_gprmask |= 1 << MIPS16_EXTRACT_OPERAND (RX, *ip);
2539 if (pinfo & (MIPS16_INSN_WRITE_Y | MIPS16_INSN_READ_Y))
2540 mips_gprmask |= 1 << MIPS16_EXTRACT_OPERAND (RY, *ip);
2541 if (pinfo & MIPS16_INSN_WRITE_Z)
2542 mips_gprmask |= 1 << MIPS16_EXTRACT_OPERAND (RZ, *ip);
2543 if (pinfo & (MIPS16_INSN_WRITE_T | MIPS16_INSN_READ_T))
2544 mips_gprmask |= 1 << TREG;
2545 if (pinfo & (MIPS16_INSN_WRITE_SP | MIPS16_INSN_READ_SP))
2546 mips_gprmask |= 1 << SP;
2547 if (pinfo & (MIPS16_INSN_WRITE_31 | MIPS16_INSN_READ_31))
2548 mips_gprmask |= 1 << RA;
2549 if (pinfo & MIPS16_INSN_WRITE_GPR_Y)
2550 mips_gprmask |= 1 << MIPS16OP_EXTRACT_REG32R (ip->insn_opcode);
2551 if (pinfo & MIPS16_INSN_READ_Z)
2552 mips_gprmask |= 1 << MIPS16_EXTRACT_OPERAND (MOVE32Z, *ip);
2553 if (pinfo & MIPS16_INSN_READ_GPR_X)
2554 mips_gprmask |= 1 << MIPS16_EXTRACT_OPERAND (REGR32, *ip);
2557 if (mips_relax.sequence != 2 && !mips_opts.noreorder)
2559 /* Filling the branch delay slot is more complex. We try to
2560 switch the branch with the previous instruction, which we can
2561 do if the previous instruction does not set up a condition
2562 that the branch tests and if the branch is not itself the
2563 target of any branch. */
2564 if ((pinfo & INSN_UNCOND_BRANCH_DELAY)
2565 || (pinfo & INSN_COND_BRANCH_DELAY))
2567 if (mips_optimize < 2
2568 /* If we have seen .set volatile or .set nomove, don't
2570 || mips_opts.nomove != 0
2571 /* We can't swap if the previous instruction's position
2573 || history[0].fixed_p
2574 /* If the previous previous insn was in a .set
2575 noreorder, we can't swap. Actually, the MIPS
2576 assembler will swap in this situation. However, gcc
2577 configured -with-gnu-as will generate code like
2583 in which we can not swap the bne and INSN. If gcc is
2584 not configured -with-gnu-as, it does not output the
2586 || history[1].noreorder_p
2587 /* If the branch is itself the target of a branch, we
2588 can not swap. We cheat on this; all we check for is
2589 whether there is a label on this instruction. If
2590 there are any branches to anything other than a
2591 label, users must use .set noreorder. */
2592 || insn_labels != NULL
2593 /* If the previous instruction is in a variant frag
2594 other than this branch's one, we cannot do the swap.
2595 This does not apply to the mips16, which uses variant
2596 frags for different purposes. */
2597 || (! mips_opts.mips16
2598 && prev_insn_frag_type == rs_machine_dependent)
2599 /* Check for conflicts between the branch and the instructions
2600 before the candidate delay slot. */
2601 || nops_for_insn (history + 1, ip) > 0
2602 /* Check for conflicts between the swapped sequence and the
2603 target of the branch. */
2604 || nops_for_sequence (2, history + 1, ip, history) > 0
2605 /* We do not swap with a trap instruction, since it
2606 complicates trap handlers to have the trap
2607 instruction be in a delay slot. */
2608 || (prev_pinfo & INSN_TRAP)
2609 /* If the branch reads a register that the previous
2610 instruction sets, we can not swap. */
2611 || (! mips_opts.mips16
2612 && (prev_pinfo & INSN_WRITE_GPR_T)
2613 && insn_uses_reg (ip, EXTRACT_OPERAND (RT, history[0]),
2615 || (! mips_opts.mips16
2616 && (prev_pinfo & INSN_WRITE_GPR_D)
2617 && insn_uses_reg (ip, EXTRACT_OPERAND (RD, history[0]),
2619 || (mips_opts.mips16
2620 && (((prev_pinfo & MIPS16_INSN_WRITE_X)
2622 (ip, MIPS16_EXTRACT_OPERAND (RX, history[0]),
2624 || ((prev_pinfo & MIPS16_INSN_WRITE_Y)
2626 (ip, MIPS16_EXTRACT_OPERAND (RY, history[0]),
2628 || ((prev_pinfo & MIPS16_INSN_WRITE_Z)
2630 (ip, MIPS16_EXTRACT_OPERAND (RZ, history[0]),
2632 || ((prev_pinfo & MIPS16_INSN_WRITE_T)
2633 && insn_uses_reg (ip, TREG, MIPS_GR_REG))
2634 || ((prev_pinfo & MIPS16_INSN_WRITE_31)
2635 && insn_uses_reg (ip, RA, MIPS_GR_REG))
2636 || ((prev_pinfo & MIPS16_INSN_WRITE_GPR_Y)
2637 && insn_uses_reg (ip,
2638 MIPS16OP_EXTRACT_REG32R
2639 (history[0].insn_opcode),
2641 /* If the branch writes a register that the previous
2642 instruction sets, we can not swap (we know that
2643 branches write only to RD or to $31). */
2644 || (! mips_opts.mips16
2645 && (prev_pinfo & INSN_WRITE_GPR_T)
2646 && (((pinfo & INSN_WRITE_GPR_D)
2647 && (EXTRACT_OPERAND (RT, history[0])
2648 == EXTRACT_OPERAND (RD, *ip)))
2649 || ((pinfo & INSN_WRITE_GPR_31)
2650 && EXTRACT_OPERAND (RT, history[0]) == RA)))
2651 || (! mips_opts.mips16
2652 && (prev_pinfo & INSN_WRITE_GPR_D)
2653 && (((pinfo & INSN_WRITE_GPR_D)
2654 && (EXTRACT_OPERAND (RD, history[0])
2655 == EXTRACT_OPERAND (RD, *ip)))
2656 || ((pinfo & INSN_WRITE_GPR_31)
2657 && EXTRACT_OPERAND (RD, history[0]) == RA)))
2658 || (mips_opts.mips16
2659 && (pinfo & MIPS16_INSN_WRITE_31)
2660 && ((prev_pinfo & MIPS16_INSN_WRITE_31)
2661 || ((prev_pinfo & MIPS16_INSN_WRITE_GPR_Y)
2662 && (MIPS16OP_EXTRACT_REG32R (history[0].insn_opcode)
2664 /* If the branch writes a register that the previous
2665 instruction reads, we can not swap (we know that
2666 branches only write to RD or to $31). */
2667 || (! mips_opts.mips16
2668 && (pinfo & INSN_WRITE_GPR_D)
2669 && insn_uses_reg (&history[0],
2670 EXTRACT_OPERAND (RD, *ip),
2672 || (! mips_opts.mips16
2673 && (pinfo & INSN_WRITE_GPR_31)
2674 && insn_uses_reg (&history[0], RA, MIPS_GR_REG))
2675 || (mips_opts.mips16
2676 && (pinfo & MIPS16_INSN_WRITE_31)
2677 && insn_uses_reg (&history[0], RA, MIPS_GR_REG))
2678 /* If one instruction sets a condition code and the
2679 other one uses a condition code, we can not swap. */
2680 || ((pinfo & INSN_READ_COND_CODE)
2681 && (prev_pinfo & INSN_WRITE_COND_CODE))
2682 || ((pinfo & INSN_WRITE_COND_CODE)
2683 && (prev_pinfo & INSN_READ_COND_CODE))
2684 /* If the previous instruction uses the PC, we can not
2686 || (mips_opts.mips16
2687 && (prev_pinfo & MIPS16_INSN_READ_PC))
2688 /* If the previous instruction had a fixup in mips16
2689 mode, we can not swap. This normally means that the
2690 previous instruction was a 4 byte branch anyhow. */
2691 || (mips_opts.mips16 && history[0].fixp[0])
2692 /* If the previous instruction is a sync, sync.l, or
2693 sync.p, we can not swap. */
2694 || (prev_pinfo & INSN_SYNC))
2696 /* We could do even better for unconditional branches to
2697 portions of this object file; we could pick up the
2698 instruction at the destination, put it in the delay
2699 slot, and bump the destination address. */
2700 insert_into_history (0, 1, ip);
2702 if (mips_relax.sequence)
2703 mips_relax.sizes[mips_relax.sequence - 1] += 4;
2707 /* It looks like we can actually do the swap. */
2708 struct mips_cl_insn delay = history[0];
2709 if (mips_opts.mips16)
2711 know (delay.frag == ip->frag);
2712 move_insn (ip, delay.frag, delay.where);
2713 move_insn (&delay, ip->frag, ip->where + insn_length (ip));
2715 else if (relaxed_branch)
2717 /* Add the delay slot instruction to the end of the
2718 current frag and shrink the fixed part of the
2719 original frag. If the branch occupies the tail of
2720 the latter, move it backwards to cover the gap. */
2721 delay.frag->fr_fix -= 4;
2722 if (delay.frag == ip->frag)
2723 move_insn (ip, ip->frag, ip->where - 4);
2724 add_fixed_insn (&delay);
2728 move_insn (&delay, ip->frag, ip->where);
2729 move_insn (ip, history[0].frag, history[0].where);
2733 insert_into_history (0, 1, &delay);
2736 /* If that was an unconditional branch, forget the previous
2737 insn information. */
2738 if (pinfo & INSN_UNCOND_BRANCH_DELAY)
2739 mips_no_prev_insn ();
2741 else if (pinfo & INSN_COND_BRANCH_LIKELY)
2743 /* We don't yet optimize a branch likely. What we should do
2744 is look at the target, copy the instruction found there
2745 into the delay slot, and increment the branch to jump to
2746 the next instruction. */
2747 insert_into_history (0, 1, ip);
2751 insert_into_history (0, 1, ip);
2754 insert_into_history (0, 1, ip);
2756 /* We just output an insn, so the next one doesn't have a label. */
2757 mips_clear_insn_labels ();
2760 /* Forget that there was any previous instruction or label. */
2763 mips_no_prev_insn (void)
2765 prev_nop_frag = NULL;
2766 insert_into_history (0, ARRAY_SIZE (history), NOP_INSN);
2767 mips_clear_insn_labels ();
2770 /* This function must be called before we emit something other than
2771 instructions. It is like mips_no_prev_insn except that it inserts
2772 any NOPS that might be needed by previous instructions. */
2775 mips_emit_delays (void)
2777 if (! mips_opts.noreorder)
2779 int nops = nops_for_insn (history, NULL);
2783 add_fixed_insn (NOP_INSN);
2784 mips_move_labels ();
2787 mips_no_prev_insn ();
2790 /* Start a (possibly nested) noreorder block. */
2793 start_noreorder (void)
2795 if (mips_opts.noreorder == 0)
2800 /* None of the instructions before the .set noreorder can be moved. */
2801 for (i = 0; i < ARRAY_SIZE (history); i++)
2802 history[i].fixed_p = 1;
2804 /* Insert any nops that might be needed between the .set noreorder
2805 block and the previous instructions. We will later remove any
2806 nops that turn out not to be needed. */
2807 nops = nops_for_insn (history, NULL);
2810 if (mips_optimize != 0)
2812 /* Record the frag which holds the nop instructions, so
2813 that we can remove them if we don't need them. */
2814 frag_grow (mips_opts.mips16 ? nops * 2 : nops * 4);
2815 prev_nop_frag = frag_now;
2816 prev_nop_frag_holds = nops;
2817 prev_nop_frag_required = 0;
2818 prev_nop_frag_since = 0;
2821 for (; nops > 0; --nops)
2822 add_fixed_insn (NOP_INSN);
2824 /* Move on to a new frag, so that it is safe to simply
2825 decrease the size of prev_nop_frag. */
2826 frag_wane (frag_now);
2828 mips_move_labels ();
2830 mips16_mark_labels ();
2831 mips_clear_insn_labels ();
2833 mips_opts.noreorder++;
2834 mips_any_noreorder = 1;
2837 /* End a nested noreorder block. */
2840 end_noreorder (void)
2842 mips_opts.noreorder--;
2843 if (mips_opts.noreorder == 0 && prev_nop_frag != NULL)
2845 /* Commit to inserting prev_nop_frag_required nops and go back to
2846 handling nop insertion the .set reorder way. */
2847 prev_nop_frag->fr_fix -= ((prev_nop_frag_holds - prev_nop_frag_required)
2848 * (mips_opts.mips16 ? 2 : 4));
2849 insert_into_history (prev_nop_frag_since,
2850 prev_nop_frag_required, NOP_INSN);
2851 prev_nop_frag = NULL;
2855 /* Set up global variables for the start of a new macro. */
2860 memset (&mips_macro_warning.sizes, 0, sizeof (mips_macro_warning.sizes));
2861 mips_macro_warning.delay_slot_p = (mips_opts.noreorder
2862 && (history[0].insn_mo->pinfo
2863 & (INSN_UNCOND_BRANCH_DELAY
2864 | INSN_COND_BRANCH_DELAY
2865 | INSN_COND_BRANCH_LIKELY)) != 0);
2868 /* Given that a macro is longer than 4 bytes, return the appropriate warning
2869 for it. Return null if no warning is needed. SUBTYPE is a bitmask of
2870 RELAX_DELAY_SLOT and RELAX_NOMACRO. */
2873 macro_warning (relax_substateT subtype)
2875 if (subtype & RELAX_DELAY_SLOT)
2876 return _("Macro instruction expanded into multiple instructions"
2877 " in a branch delay slot");
2878 else if (subtype & RELAX_NOMACRO)
2879 return _("Macro instruction expanded into multiple instructions");
2884 /* Finish up a macro. Emit warnings as appropriate. */
2889 if (mips_macro_warning.sizes[0] > 4 || mips_macro_warning.sizes[1] > 4)
2891 relax_substateT subtype;
2893 /* Set up the relaxation warning flags. */
2895 if (mips_macro_warning.sizes[1] > mips_macro_warning.sizes[0])
2896 subtype |= RELAX_SECOND_LONGER;
2897 if (mips_opts.warn_about_macros)
2898 subtype |= RELAX_NOMACRO;
2899 if (mips_macro_warning.delay_slot_p)
2900 subtype |= RELAX_DELAY_SLOT;
2902 if (mips_macro_warning.sizes[0] > 4 && mips_macro_warning.sizes[1] > 4)
2904 /* Either the macro has a single implementation or both
2905 implementations are longer than 4 bytes. Emit the
2907 const char *msg = macro_warning (subtype);
2913 /* One implementation might need a warning but the other
2914 definitely doesn't. */
2915 mips_macro_warning.first_frag->fr_subtype |= subtype;
2920 /* Read a macro's relocation codes from *ARGS and store them in *R.
2921 The first argument in *ARGS will be either the code for a single
2922 relocation or -1 followed by the three codes that make up a
2923 composite relocation. */
2926 macro_read_relocs (va_list *args, bfd_reloc_code_real_type *r)
2930 next = va_arg (*args, int);
2932 r[0] = (bfd_reloc_code_real_type) next;
2934 for (i = 0; i < 3; i++)
2935 r[i] = (bfd_reloc_code_real_type) va_arg (*args, int);
2938 /* Build an instruction created by a macro expansion. This is passed
2939 a pointer to the count of instructions created so far, an
2940 expression, the name of the instruction to build, an operand format
2941 string, and corresponding arguments. */
2944 macro_build (expressionS *ep, const char *name, const char *fmt, ...)
2946 const struct mips_opcode *mo;
2947 struct mips_cl_insn insn;
2948 bfd_reloc_code_real_type r[3];
2951 va_start (args, fmt);
2953 if (mips_opts.mips16)
2955 mips16_macro_build (ep, name, fmt, args);
2960 r[0] = BFD_RELOC_UNUSED;
2961 r[1] = BFD_RELOC_UNUSED;
2962 r[2] = BFD_RELOC_UNUSED;
2963 mo = (struct mips_opcode *) hash_find (op_hash, name);
2965 assert (strcmp (name, mo->name) == 0);
2967 /* Search until we get a match for NAME. It is assumed here that
2968 macros will never generate MDMX or MIPS-3D instructions. */
2969 while (strcmp (fmt, mo->args) != 0
2970 || mo->pinfo == INSN_MACRO
2971 || !OPCODE_IS_MEMBER (mo,
2973 | (file_ase_mips16 ? INSN_MIPS16 : 0)),
2975 || (mips_opts.arch == CPU_R4650 && (mo->pinfo & FP_D) != 0))
2979 assert (strcmp (name, mo->name) == 0);
2982 create_insn (&insn, mo);
3000 INSERT_OPERAND (SHAMT, insn, va_arg (args, int));
3005 /* Note that in the macro case, these arguments are already
3006 in MSB form. (When handling the instruction in the
3007 non-macro case, these arguments are sizes from which
3008 MSB values must be calculated.) */
3009 INSERT_OPERAND (INSMSB, insn, va_arg (args, int));
3015 /* Note that in the macro case, these arguments are already
3016 in MSBD form. (When handling the instruction in the
3017 non-macro case, these arguments are sizes from which
3018 MSBD values must be calculated.) */
3019 INSERT_OPERAND (EXTMSBD, insn, va_arg (args, int));
3030 INSERT_OPERAND (RT, insn, va_arg (args, int));
3034 INSERT_OPERAND (CODE, insn, va_arg (args, int));
3039 INSERT_OPERAND (FT, insn, va_arg (args, int));
3045 INSERT_OPERAND (RD, insn, va_arg (args, int));
3050 int tmp = va_arg (args, int);
3052 INSERT_OPERAND (RT, insn, tmp);
3053 INSERT_OPERAND (RD, insn, tmp);
3059 INSERT_OPERAND (FS, insn, va_arg (args, int));
3066 INSERT_OPERAND (SHAMT, insn, va_arg (args, int));
3070 INSERT_OPERAND (FD, insn, va_arg (args, int));
3074 INSERT_OPERAND (CODE20, insn, va_arg (args, int));
3078 INSERT_OPERAND (CODE19, insn, va_arg (args, int));
3082 INSERT_OPERAND (CODE2, insn, va_arg (args, int));
3089 INSERT_OPERAND (RS, insn, va_arg (args, int));
3095 macro_read_relocs (&args, r);
3096 assert (*r == BFD_RELOC_GPREL16
3097 || *r == BFD_RELOC_MIPS_LITERAL
3098 || *r == BFD_RELOC_MIPS_HIGHER
3099 || *r == BFD_RELOC_HI16_S
3100 || *r == BFD_RELOC_LO16
3101 || *r == BFD_RELOC_MIPS_GOT16
3102 || *r == BFD_RELOC_MIPS_CALL16
3103 || *r == BFD_RELOC_MIPS_GOT_DISP
3104 || *r == BFD_RELOC_MIPS_GOT_PAGE
3105 || *r == BFD_RELOC_MIPS_GOT_OFST
3106 || *r == BFD_RELOC_MIPS_GOT_LO16
3107 || *r == BFD_RELOC_MIPS_CALL_LO16);
3111 macro_read_relocs (&args, r);
3113 && (ep->X_op == O_constant
3114 || (ep->X_op == O_symbol
3115 && (*r == BFD_RELOC_MIPS_HIGHEST
3116 || *r == BFD_RELOC_HI16_S
3117 || *r == BFD_RELOC_HI16
3118 || *r == BFD_RELOC_GPREL16
3119 || *r == BFD_RELOC_MIPS_GOT_HI16
3120 || *r == BFD_RELOC_MIPS_CALL_HI16))));
3124 assert (ep != NULL);
3126 * This allows macro() to pass an immediate expression for
3127 * creating short branches without creating a symbol.
3128 * Note that the expression still might come from the assembly
3129 * input, in which case the value is not checked for range nor
3130 * is a relocation entry generated (yuck).
3132 if (ep->X_op == O_constant)
3134 insn.insn_opcode |= (ep->X_add_number >> 2) & 0xffff;
3138 *r = BFD_RELOC_16_PCREL_S2;
3142 assert (ep != NULL);
3143 *r = BFD_RELOC_MIPS_JMP;
3147 insn.insn_opcode |= va_arg (args, unsigned long);
3156 assert (*r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL);
3158 append_insn (&insn, ep, r);
3162 mips16_macro_build (expressionS *ep, const char *name, const char *fmt,
3165 struct mips_opcode *mo;
3166 struct mips_cl_insn insn;
3167 bfd_reloc_code_real_type r[3]
3168 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
3170 mo = (struct mips_opcode *) hash_find (mips16_op_hash, name);
3172 assert (strcmp (name, mo->name) == 0);
3174 while (strcmp (fmt, mo->args) != 0 || mo->pinfo == INSN_MACRO)
3178 assert (strcmp (name, mo->name) == 0);
3181 create_insn (&insn, mo);
3199 MIPS16_INSERT_OPERAND (RY, insn, va_arg (args, int));
3204 MIPS16_INSERT_OPERAND (RX, insn, va_arg (args, int));
3208 MIPS16_INSERT_OPERAND (RZ, insn, va_arg (args, int));
3212 MIPS16_INSERT_OPERAND (MOVE32Z, insn, va_arg (args, int));
3222 MIPS16_INSERT_OPERAND (REGR32, insn, va_arg (args, int));
3229 regno = va_arg (args, int);
3230 regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3);
3231 insn.insn_opcode |= regno << MIPS16OP_SH_REG32R;
3252 assert (ep != NULL);
3254 if (ep->X_op != O_constant)
3255 *r = (int) BFD_RELOC_UNUSED + c;
3258 mips16_immed (NULL, 0, c, ep->X_add_number, FALSE, FALSE,
3259 FALSE, &insn.insn_opcode, &insn.use_extend,
3262 *r = BFD_RELOC_UNUSED;
3268 MIPS16_INSERT_OPERAND (IMM6, insn, va_arg (args, int));
3275 assert (*r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL);
3277 append_insn (&insn, ep, r);
3281 * Sign-extend 32-bit mode constants that have bit 31 set and all
3282 * higher bits unset.
3285 normalize_constant_expr (expressionS *ex)
3287 if (ex->X_op == O_constant
3288 && IS_ZEXT_32BIT_NUM (ex->X_add_number))
3289 ex->X_add_number = (((ex->X_add_number & 0xffffffff) ^ 0x80000000)
3294 * Sign-extend 32-bit mode address offsets that have bit 31 set and
3295 * all higher bits unset.
3298 normalize_address_expr (expressionS *ex)
3300 if (((ex->X_op == O_constant && HAVE_32BIT_ADDRESSES)
3301 || (ex->X_op == O_symbol && HAVE_32BIT_SYMBOLS))
3302 && IS_ZEXT_32BIT_NUM (ex->X_add_number))
3303 ex->X_add_number = (((ex->X_add_number & 0xffffffff) ^ 0x80000000)
3308 * Generate a "jalr" instruction with a relocation hint to the called
3309 * function. This occurs in NewABI PIC code.
3312 macro_build_jalr (expressionS *ep)
3321 macro_build (NULL, "jalr", "d,s", RA, PIC_CALL_REG);
3323 fix_new_exp (frag_now, f - frag_now->fr_literal,
3324 4, ep, FALSE, BFD_RELOC_MIPS_JALR);
3328 * Generate a "lui" instruction.
3331 macro_build_lui (expressionS *ep, int regnum)
3333 expressionS high_expr;
3334 const struct mips_opcode *mo;
3335 struct mips_cl_insn insn;
3336 bfd_reloc_code_real_type r[3]
3337 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
3338 const char *name = "lui";
3339 const char *fmt = "t,u";
3341 assert (! mips_opts.mips16);
3345 if (high_expr.X_op == O_constant)
3347 /* we can compute the instruction now without a relocation entry */
3348 high_expr.X_add_number = ((high_expr.X_add_number + 0x8000)
3350 *r = BFD_RELOC_UNUSED;
3354 assert (ep->X_op == O_symbol);
3355 /* _gp_disp is a special case, used from s_cpload.
3356 __gnu_local_gp is used if mips_no_shared. */
3357 assert (mips_pic == NO_PIC
3359 && strcmp (S_GET_NAME (ep->X_add_symbol), "_gp_disp") == 0)
3360 || (! mips_in_shared
3361 && strcmp (S_GET_NAME (ep->X_add_symbol),
3362 "__gnu_local_gp") == 0));
3363 *r = BFD_RELOC_HI16_S;
3366 mo = hash_find (op_hash, name);
3367 assert (strcmp (name, mo->name) == 0);
3368 assert (strcmp (fmt, mo->args) == 0);
3369 create_insn (&insn, mo);
3371 insn.insn_opcode = insn.insn_mo->match;
3372 INSERT_OPERAND (RT, insn, regnum);
3373 if (*r == BFD_RELOC_UNUSED)
3375 insn.insn_opcode |= high_expr.X_add_number;
3376 append_insn (&insn, NULL, r);
3379 append_insn (&insn, &high_expr, r);
3382 /* Generate a sequence of instructions to do a load or store from a constant
3383 offset off of a base register (breg) into/from a target register (treg),
3384 using AT if necessary. */
3386 macro_build_ldst_constoffset (expressionS *ep, const char *op,
3387 int treg, int breg, int dbl)
3389 assert (ep->X_op == O_constant);
3391 /* Sign-extending 32-bit constants makes their handling easier. */
3393 normalize_constant_expr (ep);
3395 /* Right now, this routine can only handle signed 32-bit constants. */
3396 if (! IS_SEXT_32BIT_NUM(ep->X_add_number + 0x8000))
3397 as_warn (_("operand overflow"));
3399 if (IS_SEXT_16BIT_NUM(ep->X_add_number))
3401 /* Signed 16-bit offset will fit in the op. Easy! */
3402 macro_build (ep, op, "t,o(b)", treg, BFD_RELOC_LO16, breg);
3406 /* 32-bit offset, need multiple instructions and AT, like:
3407 lui $tempreg,const_hi (BFD_RELOC_HI16_S)
3408 addu $tempreg,$tempreg,$breg
3409 <op> $treg,const_lo($tempreg) (BFD_RELOC_LO16)
3410 to handle the complete offset. */
3411 macro_build_lui (ep, AT);
3412 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, AT, breg);
3413 macro_build (ep, op, "t,o(b)", treg, BFD_RELOC_LO16, AT);
3416 as_bad (_("Macro used $at after \".set noat\""));
3421 * Generates code to set the $at register to true (one)
3422 * if reg is less than the immediate expression.
3425 set_at (int reg, int unsignedp)
3427 if (imm_expr.X_op == O_constant
3428 && imm_expr.X_add_number >= -0x8000
3429 && imm_expr.X_add_number < 0x8000)
3430 macro_build (&imm_expr, unsignedp ? "sltiu" : "slti", "t,r,j",
3431 AT, reg, BFD_RELOC_LO16);
3434 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
3435 macro_build (NULL, unsignedp ? "sltu" : "slt", "d,v,t", AT, reg, AT);
3439 /* Warn if an expression is not a constant. */
3442 check_absolute_expr (struct mips_cl_insn *ip, expressionS *ex)
3444 if (ex->X_op == O_big)
3445 as_bad (_("unsupported large constant"));
3446 else if (ex->X_op != O_constant)
3447 as_bad (_("Instruction %s requires absolute expression"),
3450 if (HAVE_32BIT_GPRS)
3451 normalize_constant_expr (ex);
3454 /* Count the leading zeroes by performing a binary chop. This is a
3455 bulky bit of source, but performance is a LOT better for the
3456 majority of values than a simple loop to count the bits:
3457 for (lcnt = 0; (lcnt < 32); lcnt++)
3458 if ((v) & (1 << (31 - lcnt)))
3460 However it is not code size friendly, and the gain will drop a bit
3461 on certain cached systems.
3463 #define COUNT_TOP_ZEROES(v) \
3464 (((v) & ~0xffff) == 0 \
3465 ? ((v) & ~0xff) == 0 \
3466 ? ((v) & ~0xf) == 0 \
3467 ? ((v) & ~0x3) == 0 \
3468 ? ((v) & ~0x1) == 0 \
3473 : ((v) & ~0x7) == 0 \
3476 : ((v) & ~0x3f) == 0 \
3477 ? ((v) & ~0x1f) == 0 \
3480 : ((v) & ~0x7f) == 0 \
3483 : ((v) & ~0xfff) == 0 \
3484 ? ((v) & ~0x3ff) == 0 \
3485 ? ((v) & ~0x1ff) == 0 \
3488 : ((v) & ~0x7ff) == 0 \
3491 : ((v) & ~0x3fff) == 0 \
3492 ? ((v) & ~0x1fff) == 0 \
3495 : ((v) & ~0x7fff) == 0 \
3498 : ((v) & ~0xffffff) == 0 \
3499 ? ((v) & ~0xfffff) == 0 \
3500 ? ((v) & ~0x3ffff) == 0 \
3501 ? ((v) & ~0x1ffff) == 0 \
3504 : ((v) & ~0x7ffff) == 0 \
3507 : ((v) & ~0x3fffff) == 0 \
3508 ? ((v) & ~0x1fffff) == 0 \
3511 : ((v) & ~0x7fffff) == 0 \
3514 : ((v) & ~0xfffffff) == 0 \
3515 ? ((v) & ~0x3ffffff) == 0 \
3516 ? ((v) & ~0x1ffffff) == 0 \
3519 : ((v) & ~0x7ffffff) == 0 \
3522 : ((v) & ~0x3fffffff) == 0 \
3523 ? ((v) & ~0x1fffffff) == 0 \
3526 : ((v) & ~0x7fffffff) == 0 \
3531 * This routine generates the least number of instructions necessary to load
3532 * an absolute expression value into a register.
3535 load_register (int reg, expressionS *ep, int dbl)
3538 expressionS hi32, lo32;
3540 if (ep->X_op != O_big)
3542 assert (ep->X_op == O_constant);
3544 /* Sign-extending 32-bit constants makes their handling easier. */
3546 normalize_constant_expr (ep);
3548 if (IS_SEXT_16BIT_NUM (ep->X_add_number))
3550 /* We can handle 16 bit signed values with an addiu to
3551 $zero. No need to ever use daddiu here, since $zero and
3552 the result are always correct in 32 bit mode. */
3553 macro_build (ep, "addiu", "t,r,j", reg, 0, BFD_RELOC_LO16);
3556 else if (ep->X_add_number >= 0 && ep->X_add_number < 0x10000)
3558 /* We can handle 16 bit unsigned values with an ori to
3560 macro_build (ep, "ori", "t,r,i", reg, 0, BFD_RELOC_LO16);
3563 else if ((IS_SEXT_32BIT_NUM (ep->X_add_number)))
3565 /* 32 bit values require an lui. */
3566 macro_build (ep, "lui", "t,u", reg, BFD_RELOC_HI16);
3567 if ((ep->X_add_number & 0xffff) != 0)
3568 macro_build (ep, "ori", "t,r,i", reg, reg, BFD_RELOC_LO16);
3573 /* The value is larger than 32 bits. */
3575 if (!dbl || HAVE_32BIT_GPRS)
3579 sprintf_vma (value, ep->X_add_number);
3580 as_bad (_("Number (0x%s) larger than 32 bits"), value);
3581 macro_build (ep, "addiu", "t,r,j", reg, 0, BFD_RELOC_LO16);
3585 if (ep->X_op != O_big)
3588 hi32.X_add_number = (valueT) hi32.X_add_number >> 16;
3589 hi32.X_add_number = (valueT) hi32.X_add_number >> 16;
3590 hi32.X_add_number &= 0xffffffff;
3592 lo32.X_add_number &= 0xffffffff;
3596 assert (ep->X_add_number > 2);
3597 if (ep->X_add_number == 3)
3598 generic_bignum[3] = 0;
3599 else if (ep->X_add_number > 4)
3600 as_bad (_("Number larger than 64 bits"));
3601 lo32.X_op = O_constant;
3602 lo32.X_add_number = generic_bignum[0] + (generic_bignum[1] << 16);
3603 hi32.X_op = O_constant;
3604 hi32.X_add_number = generic_bignum[2] + (generic_bignum[3] << 16);
3607 if (hi32.X_add_number == 0)
3612 unsigned long hi, lo;
3614 if (hi32.X_add_number == (offsetT) 0xffffffff)
3616 if ((lo32.X_add_number & 0xffff8000) == 0xffff8000)
3618 macro_build (&lo32, "addiu", "t,r,j", reg, 0, BFD_RELOC_LO16);
3621 if (lo32.X_add_number & 0x80000000)
3623 macro_build (&lo32, "lui", "t,u", reg, BFD_RELOC_HI16);
3624 if (lo32.X_add_number & 0xffff)
3625 macro_build (&lo32, "ori", "t,r,i", reg, reg, BFD_RELOC_LO16);
3630 /* Check for 16bit shifted constant. We know that hi32 is
3631 non-zero, so start the mask on the first bit of the hi32
3636 unsigned long himask, lomask;
3640 himask = 0xffff >> (32 - shift);
3641 lomask = (0xffff << shift) & 0xffffffff;
3645 himask = 0xffff << (shift - 32);
3648 if ((hi32.X_add_number & ~(offsetT) himask) == 0
3649 && (lo32.X_add_number & ~(offsetT) lomask) == 0)
3653 tmp.X_op = O_constant;
3655 tmp.X_add_number = ((hi32.X_add_number << (32 - shift))
3656 | (lo32.X_add_number >> shift));
3658 tmp.X_add_number = hi32.X_add_number >> (shift - 32);
3659 macro_build (&tmp, "ori", "t,r,i", reg, 0, BFD_RELOC_LO16);
3660 macro_build (NULL, (shift >= 32) ? "dsll32" : "dsll", "d,w,<",
3661 reg, reg, (shift >= 32) ? shift - 32 : shift);
3666 while (shift <= (64 - 16));
3668 /* Find the bit number of the lowest one bit, and store the
3669 shifted value in hi/lo. */
3670 hi = (unsigned long) (hi32.X_add_number & 0xffffffff);
3671 lo = (unsigned long) (lo32.X_add_number & 0xffffffff);
3675 while ((lo & 1) == 0)
3680 lo |= (hi & (((unsigned long) 1 << bit) - 1)) << (32 - bit);
3686 while ((hi & 1) == 0)
3695 /* Optimize if the shifted value is a (power of 2) - 1. */
3696 if ((hi == 0 && ((lo + 1) & lo) == 0)
3697 || (lo == 0xffffffff && ((hi + 1) & hi) == 0))
3699 shift = COUNT_TOP_ZEROES ((unsigned int) hi32.X_add_number);
3704 /* This instruction will set the register to be all
3706 tmp.X_op = O_constant;
3707 tmp.X_add_number = (offsetT) -1;
3708 macro_build (&tmp, "addiu", "t,r,j", reg, 0, BFD_RELOC_LO16);
3712 macro_build (NULL, (bit >= 32) ? "dsll32" : "dsll", "d,w,<",
3713 reg, reg, (bit >= 32) ? bit - 32 : bit);
3715 macro_build (NULL, (shift >= 32) ? "dsrl32" : "dsrl", "d,w,<",
3716 reg, reg, (shift >= 32) ? shift - 32 : shift);
3721 /* Sign extend hi32 before calling load_register, because we can
3722 generally get better code when we load a sign extended value. */
3723 if ((hi32.X_add_number & 0x80000000) != 0)
3724 hi32.X_add_number |= ~(offsetT) 0xffffffff;
3725 load_register (reg, &hi32, 0);
3728 if ((lo32.X_add_number & 0xffff0000) == 0)
3732 macro_build (NULL, "dsll32", "d,w,<", reg, freg, 0);
3740 if ((freg == 0) && (lo32.X_add_number == (offsetT) 0xffffffff))
3742 macro_build (&lo32, "lui", "t,u", reg, BFD_RELOC_HI16);
3743 macro_build (NULL, "dsrl32", "d,w,<", reg, reg, 0);
3749 macro_build (NULL, "dsll", "d,w,<", reg, freg, 16);
3753 mid16.X_add_number >>= 16;
3754 macro_build (&mid16, "ori", "t,r,i", reg, freg, BFD_RELOC_LO16);
3755 macro_build (NULL, "dsll", "d,w,<", reg, reg, 16);
3758 if ((lo32.X_add_number & 0xffff) != 0)
3759 macro_build (&lo32, "ori", "t,r,i", reg, freg, BFD_RELOC_LO16);
3763 load_delay_nop (void)
3765 if (!gpr_interlocks)
3766 macro_build (NULL, "nop", "");
3769 /* Load an address into a register. */
3772 load_address (int reg, expressionS *ep, int *used_at)
3774 if (ep->X_op != O_constant
3775 && ep->X_op != O_symbol)
3777 as_bad (_("expression too complex"));
3778 ep->X_op = O_constant;
3781 if (ep->X_op == O_constant)
3783 load_register (reg, ep, HAVE_64BIT_ADDRESSES);
3787 if (mips_pic == NO_PIC)
3789 /* If this is a reference to a GP relative symbol, we want
3790 addiu $reg,$gp,<sym> (BFD_RELOC_GPREL16)
3792 lui $reg,<sym> (BFD_RELOC_HI16_S)
3793 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
3794 If we have an addend, we always use the latter form.
3796 With 64bit address space and a usable $at we want
3797 lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST)
3798 lui $at,<sym> (BFD_RELOC_HI16_S)
3799 daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER)
3800 daddiu $at,<sym> (BFD_RELOC_LO16)
3804 If $at is already in use, we use a path which is suboptimal
3805 on superscalar processors.
3806 lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST)
3807 daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER)
3809 daddiu $reg,<sym> (BFD_RELOC_HI16_S)
3811 daddiu $reg,<sym> (BFD_RELOC_LO16)
3813 For GP relative symbols in 64bit address space we can use
3814 the same sequence as in 32bit address space. */
3815 if (HAVE_64BIT_SYMBOLS)
3817 if ((valueT) ep->X_add_number <= MAX_GPREL_OFFSET
3818 && !nopic_need_relax (ep->X_add_symbol, 1))
3820 relax_start (ep->X_add_symbol);
3821 macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", reg,
3822 mips_gp_register, BFD_RELOC_GPREL16);
3826 if (*used_at == 0 && !mips_opts.noat)
3828 macro_build (ep, "lui", "t,u", reg, BFD_RELOC_MIPS_HIGHEST);
3829 macro_build (ep, "lui", "t,u", AT, BFD_RELOC_HI16_S);
3830 macro_build (ep, "daddiu", "t,r,j", reg, reg,
3831 BFD_RELOC_MIPS_HIGHER);
3832 macro_build (ep, "daddiu", "t,r,j", AT, AT, BFD_RELOC_LO16);
3833 macro_build (NULL, "dsll32", "d,w,<", reg, reg, 0);
3834 macro_build (NULL, "daddu", "d,v,t", reg, reg, AT);
3839 macro_build (ep, "lui", "t,u", reg, BFD_RELOC_MIPS_HIGHEST);
3840 macro_build (ep, "daddiu", "t,r,j", reg, reg,
3841 BFD_RELOC_MIPS_HIGHER);
3842 macro_build (NULL, "dsll", "d,w,<", reg, reg, 16);
3843 macro_build (ep, "daddiu", "t,r,j", reg, reg, BFD_RELOC_HI16_S);
3844 macro_build (NULL, "dsll", "d,w,<", reg, reg, 16);
3845 macro_build (ep, "daddiu", "t,r,j", reg, reg, BFD_RELOC_LO16);
3848 if (mips_relax.sequence)
3853 if ((valueT) ep->X_add_number <= MAX_GPREL_OFFSET
3854 && !nopic_need_relax (ep->X_add_symbol, 1))
3856 relax_start (ep->X_add_symbol);
3857 macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", reg,
3858 mips_gp_register, BFD_RELOC_GPREL16);
3861 macro_build_lui (ep, reg);
3862 macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j",
3863 reg, reg, BFD_RELOC_LO16);
3864 if (mips_relax.sequence)
3868 else if (mips_pic == SVR4_PIC && ! mips_big_got)
3872 /* If this is a reference to an external symbol, we want
3873 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3875 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3877 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
3878 If there is a constant, it must be added in after.
3880 If we have NewABI, we want
3881 lw $reg,<sym+cst>($gp) (BFD_RELOC_MIPS_GOT_DISP)
3882 unless we're referencing a global symbol with a non-zero
3883 offset, in which case cst must be added separately. */
3886 if (ep->X_add_number)
3888 ex.X_add_number = ep->X_add_number;
3889 ep->X_add_number = 0;
3890 relax_start (ep->X_add_symbol);
3891 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
3892 BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
3893 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
3894 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
3895 ex.X_op = O_constant;
3896 macro_build (&ex, ADDRESS_ADDI_INSN, "t,r,j",
3897 reg, reg, BFD_RELOC_LO16);
3898 ep->X_add_number = ex.X_add_number;
3901 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
3902 BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
3903 if (mips_relax.sequence)
3908 ex.X_add_number = ep->X_add_number;
3909 ep->X_add_number = 0;
3910 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
3911 BFD_RELOC_MIPS_GOT16, mips_gp_register);
3913 relax_start (ep->X_add_symbol);
3915 macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", reg, reg,
3919 if (ex.X_add_number != 0)
3921 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
3922 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
3923 ex.X_op = O_constant;
3924 macro_build (&ex, ADDRESS_ADDI_INSN, "t,r,j",
3925 reg, reg, BFD_RELOC_LO16);
3929 else if (mips_pic == SVR4_PIC)
3933 /* This is the large GOT case. If this is a reference to an
3934 external symbol, we want
3935 lui $reg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
3937 lw $reg,<sym>($reg) (BFD_RELOC_MIPS_GOT_LO16)
3939 Otherwise, for a reference to a local symbol in old ABI, we want
3940 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3942 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
3943 If there is a constant, it must be added in after.
3945 In the NewABI, for local symbols, with or without offsets, we want:
3946 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
3947 addiu $reg,$reg,<sym> (BFD_RELOC_MIPS_GOT_OFST)
3951 ex.X_add_number = ep->X_add_number;
3952 ep->X_add_number = 0;
3953 relax_start (ep->X_add_symbol);
3954 macro_build (ep, "lui", "t,u", reg, BFD_RELOC_MIPS_GOT_HI16);
3955 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
3956 reg, reg, mips_gp_register);
3957 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)",
3958 reg, BFD_RELOC_MIPS_GOT_LO16, reg);
3959 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
3960 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
3961 else if (ex.X_add_number)
3963 ex.X_op = O_constant;
3964 macro_build (&ex, ADDRESS_ADDI_INSN, "t,r,j", reg, reg,
3968 ep->X_add_number = ex.X_add_number;
3970 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
3971 BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register);
3972 macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", reg, reg,
3973 BFD_RELOC_MIPS_GOT_OFST);
3978 ex.X_add_number = ep->X_add_number;
3979 ep->X_add_number = 0;
3980 relax_start (ep->X_add_symbol);
3981 macro_build (ep, "lui", "t,u", reg, BFD_RELOC_MIPS_GOT_HI16);
3982 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
3983 reg, reg, mips_gp_register);
3984 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)",
3985 reg, BFD_RELOC_MIPS_GOT_LO16, reg);
3987 if (reg_needs_delay (mips_gp_register))
3989 /* We need a nop before loading from $gp. This special
3990 check is required because the lui which starts the main
3991 instruction stream does not refer to $gp, and so will not
3992 insert the nop which may be required. */
3993 macro_build (NULL, "nop", "");
3995 macro_build (ep, ADDRESS_LOAD_INSN, "t,o(b)", reg,
3996 BFD_RELOC_MIPS_GOT16, mips_gp_register);
3998 macro_build (ep, ADDRESS_ADDI_INSN, "t,r,j", reg, reg,
4002 if (ex.X_add_number != 0)
4004 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
4005 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
4006 ex.X_op = O_constant;
4007 macro_build (&ex, ADDRESS_ADDI_INSN, "t,r,j", reg, reg,
4015 if (mips_opts.noat && *used_at == 1)
4016 as_bad (_("Macro used $at after \".set noat\""));
4019 /* Move the contents of register SOURCE into register DEST. */
4022 move_register (int dest, int source)
4024 macro_build (NULL, HAVE_32BIT_GPRS ? "addu" : "daddu", "d,v,t",
4028 /* Emit an SVR4 PIC sequence to load address LOCAL into DEST, where
4029 LOCAL is the sum of a symbol and a 16-bit or 32-bit displacement.
4030 The two alternatives are:
4032 Global symbol Local sybmol
4033 ------------- ------------
4034 lw DEST,%got(SYMBOL) lw DEST,%got(SYMBOL + OFFSET)
4036 addiu DEST,DEST,OFFSET addiu DEST,DEST,%lo(SYMBOL + OFFSET)
4038 load_got_offset emits the first instruction and add_got_offset
4039 emits the second for a 16-bit offset or add_got_offset_hilo emits
4040 a sequence to add a 32-bit offset using a scratch register. */
4043 load_got_offset (int dest, expressionS *local)
4048 global.X_add_number = 0;
4050 relax_start (local->X_add_symbol);
4051 macro_build (&global, ADDRESS_LOAD_INSN, "t,o(b)", dest,
4052 BFD_RELOC_MIPS_GOT16, mips_gp_register);
4054 macro_build (local, ADDRESS_LOAD_INSN, "t,o(b)", dest,
4055 BFD_RELOC_MIPS_GOT16, mips_gp_register);
4060 add_got_offset (int dest, expressionS *local)
4064 global.X_op = O_constant;
4065 global.X_op_symbol = NULL;
4066 global.X_add_symbol = NULL;
4067 global.X_add_number = local->X_add_number;
4069 relax_start (local->X_add_symbol);
4070 macro_build (&global, ADDRESS_ADDI_INSN, "t,r,j",
4071 dest, dest, BFD_RELOC_LO16);
4073 macro_build (local, ADDRESS_ADDI_INSN, "t,r,j", dest, dest, BFD_RELOC_LO16);
4078 add_got_offset_hilo (int dest, expressionS *local, int tmp)
4081 int hold_mips_optimize;
4083 global.X_op = O_constant;
4084 global.X_op_symbol = NULL;
4085 global.X_add_symbol = NULL;
4086 global.X_add_number = local->X_add_number;
4088 relax_start (local->X_add_symbol);
4089 load_register (tmp, &global, HAVE_64BIT_ADDRESSES);
4091 /* Set mips_optimize around the lui instruction to avoid
4092 inserting an unnecessary nop after the lw. */
4093 hold_mips_optimize = mips_optimize;
4095 macro_build_lui (&global, tmp);
4096 mips_optimize = hold_mips_optimize;
4097 macro_build (local, ADDRESS_ADDI_INSN, "t,r,j", tmp, tmp, BFD_RELOC_LO16);
4100 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", dest, dest, tmp);
4105 * This routine implements the seemingly endless macro or synthesized
4106 * instructions and addressing modes in the mips assembly language. Many
4107 * of these macros are simple and are similar to each other. These could
4108 * probably be handled by some kind of table or grammar approach instead of
4109 * this verbose method. Others are not simple macros but are more like
4110 * optimizing code generation.
4111 * One interesting optimization is when several store macros appear
4112 * consecutively that would load AT with the upper half of the same address.
4113 * The ensuing load upper instructions are ommited. This implies some kind
4114 * of global optimization. We currently only optimize within a single macro.
4115 * For many of the load and store macros if the address is specified as a
4116 * constant expression in the first 64k of memory (ie ld $2,0x4000c) we
4117 * first load register 'at' with zero and use it as the base register. The
4118 * mips assembler simply uses register $zero. Just one tiny optimization
4122 macro (struct mips_cl_insn *ip)
4124 register int treg, sreg, dreg, breg;
4140 bfd_reloc_code_real_type r;
4141 int hold_mips_optimize;
4143 assert (! mips_opts.mips16);
4145 treg = (ip->insn_opcode >> 16) & 0x1f;
4146 dreg = (ip->insn_opcode >> 11) & 0x1f;
4147 sreg = breg = (ip->insn_opcode >> 21) & 0x1f;
4148 mask = ip->insn_mo->mask;
4150 expr1.X_op = O_constant;
4151 expr1.X_op_symbol = NULL;
4152 expr1.X_add_symbol = NULL;
4153 expr1.X_add_number = 1;
4167 expr1.X_add_number = 8;
4168 macro_build (&expr1, "bgez", "s,p", sreg);
4170 macro_build (NULL, "nop", "", 0);
4172 move_register (dreg, sreg);
4173 macro_build (NULL, dbl ? "dsub" : "sub", "d,v,t", dreg, 0, sreg);
4196 if (imm_expr.X_op == O_constant
4197 && imm_expr.X_add_number >= -0x8000
4198 && imm_expr.X_add_number < 0x8000)
4200 macro_build (&imm_expr, s, "t,r,j", treg, sreg, BFD_RELOC_LO16);
4204 load_register (AT, &imm_expr, dbl);
4205 macro_build (NULL, s2, "d,v,t", treg, sreg, AT);
4224 if (imm_expr.X_op == O_constant
4225 && imm_expr.X_add_number >= 0
4226 && imm_expr.X_add_number < 0x10000)
4228 if (mask != M_NOR_I)
4229 macro_build (&imm_expr, s, "t,r,i", treg, sreg, BFD_RELOC_LO16);
4232 macro_build (&imm_expr, "ori", "t,r,i",
4233 treg, sreg, BFD_RELOC_LO16);
4234 macro_build (NULL, "nor", "d,v,t", treg, treg, 0);
4240 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
4241 macro_build (NULL, s2, "d,v,t", treg, sreg, AT);
4258 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4260 macro_build (&offset_expr, s, "s,t,p", sreg, 0);
4264 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
4265 macro_build (&offset_expr, s, "s,t,p", sreg, AT);
4273 macro_build (&offset_expr, likely ? "bgezl" : "bgez", "s,p", sreg);
4278 macro_build (&offset_expr, likely ? "blezl" : "blez", "s,p", treg);
4282 macro_build (NULL, "slt", "d,v,t", AT, sreg, treg);
4283 macro_build (&offset_expr, likely ? "beql" : "beq", "s,t,p", AT, 0);
4289 /* check for > max integer */
4290 maxnum = 0x7fffffff;
4291 if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4)
4298 if (imm_expr.X_op == O_constant
4299 && imm_expr.X_add_number >= maxnum
4300 && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4))
4303 /* result is always false */
4305 macro_build (NULL, "nop", "", 0);
4307 macro_build (&offset_expr, "bnel", "s,t,p", 0, 0);
4310 if (imm_expr.X_op != O_constant)
4311 as_bad (_("Unsupported large constant"));
4312 ++imm_expr.X_add_number;
4316 if (mask == M_BGEL_I)
4318 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4320 macro_build (&offset_expr, likely ? "bgezl" : "bgez", "s,p", sreg);
4323 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4325 macro_build (&offset_expr, likely ? "bgtzl" : "bgtz", "s,p", sreg);
4328 maxnum = 0x7fffffff;
4329 if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4)
4336 maxnum = - maxnum - 1;
4337 if (imm_expr.X_op == O_constant
4338 && imm_expr.X_add_number <= maxnum
4339 && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4))
4342 /* result is always true */
4343 as_warn (_("Branch %s is always true"), ip->insn_mo->name);
4344 macro_build (&offset_expr, "b", "p");
4349 macro_build (&offset_expr, likely ? "beql" : "beq", "s,t,p", AT, 0);
4359 macro_build (&offset_expr, likely ? "beql" : "beq",
4364 macro_build (NULL, "sltu", "d,v,t", AT, sreg, treg);
4365 macro_build (&offset_expr, likely ? "beql" : "beq", "s,t,p", AT, 0);
4373 && imm_expr.X_op == O_constant
4374 && imm_expr.X_add_number == (offsetT) 0xffffffff))
4376 if (imm_expr.X_op != O_constant)
4377 as_bad (_("Unsupported large constant"));
4378 ++imm_expr.X_add_number;
4382 if (mask == M_BGEUL_I)
4384 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4386 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4388 macro_build (&offset_expr, likely ? "bnel" : "bne",
4394 macro_build (&offset_expr, likely ? "beql" : "beq", "s,t,p", AT, 0);
4402 macro_build (&offset_expr, likely ? "bgtzl" : "bgtz", "s,p", sreg);
4407 macro_build (&offset_expr, likely ? "bltzl" : "bltz", "s,p", treg);
4411 macro_build (NULL, "slt", "d,v,t", AT, treg, sreg);
4412 macro_build (&offset_expr, likely ? "bnel" : "bne", "s,t,p", AT, 0);
4420 macro_build (&offset_expr, likely ? "bnel" : "bne",
4427 macro_build (NULL, "sltu", "d,v,t", AT, treg, sreg);
4428 macro_build (&offset_expr, likely ? "bnel" : "bne", "s,t,p", AT, 0);
4436 macro_build (&offset_expr, likely ? "blezl" : "blez", "s,p", sreg);
4441 macro_build (&offset_expr, likely ? "bgezl" : "bgez", "s,p", treg);
4445 macro_build (NULL, "slt", "d,v,t", AT, treg, sreg);
4446 macro_build (&offset_expr, likely ? "beql" : "beq", "s,t,p", AT, 0);
4452 maxnum = 0x7fffffff;
4453 if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4)
4460 if (imm_expr.X_op == O_constant
4461 && imm_expr.X_add_number >= maxnum
4462 && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4))
4464 if (imm_expr.X_op != O_constant)
4465 as_bad (_("Unsupported large constant"));
4466 ++imm_expr.X_add_number;
4470 if (mask == M_BLTL_I)
4472 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4474 macro_build (&offset_expr, likely ? "bltzl" : "bltz", "s,p", sreg);
4477 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4479 macro_build (&offset_expr, likely ? "blezl" : "blez", "s,p", sreg);
4484 macro_build (&offset_expr, likely ? "bnel" : "bne", "s,t,p", AT, 0);
4492 macro_build (&offset_expr, likely ? "beql" : "beq",
4499 macro_build (NULL, "sltu", "d,v,t", AT, treg, sreg);
4500 macro_build (&offset_expr, likely ? "beql" : "beq", "s,t,p", AT, 0);
4508 && imm_expr.X_op == O_constant
4509 && imm_expr.X_add_number == (offsetT) 0xffffffff))
4511 if (imm_expr.X_op != O_constant)
4512 as_bad (_("Unsupported large constant"));
4513 ++imm_expr.X_add_number;
4517 if (mask == M_BLTUL_I)
4519 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4521 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4523 macro_build (&offset_expr, likely ? "beql" : "beq",
4529 macro_build (&offset_expr, likely ? "bnel" : "bne", "s,t,p", AT, 0);
4537 macro_build (&offset_expr, likely ? "bltzl" : "bltz", "s,p", sreg);
4542 macro_build (&offset_expr, likely ? "bgtzl" : "bgtz", "s,p", treg);
4546 macro_build (NULL, "slt", "d,v,t", AT, sreg, treg);
4547 macro_build (&offset_expr, likely ? "bnel" : "bne", "s,t,p", AT, 0);
4557 macro_build (&offset_expr, likely ? "bnel" : "bne",
4562 macro_build (NULL, "sltu", "d,v,t", AT, sreg, treg);
4563 macro_build (&offset_expr, likely ? "bnel" : "bne", "s,t,p", AT, 0);
4571 if (imm_expr.X_op != O_constant || imm2_expr.X_op != O_constant)
4573 as_bad (_("Unsupported large constant"));
4578 pos = (unsigned long) imm_expr.X_add_number;
4579 size = (unsigned long) imm2_expr.X_add_number;
4584 as_bad (_("Improper position (%lu)"), pos);
4587 if (size == 0 || size > 64
4588 || (pos + size - 1) > 63)
4590 as_bad (_("Improper extract size (%lu, position %lu)"),
4595 if (size <= 32 && pos < 32)
4600 else if (size <= 32)
4610 macro_build ((expressionS *) NULL, s, fmt, treg, sreg, pos, size - 1);
4619 if (imm_expr.X_op != O_constant || imm2_expr.X_op != O_constant)
4621 as_bad (_("Unsupported large constant"));
4626 pos = (unsigned long) imm_expr.X_add_number;
4627 size = (unsigned long) imm2_expr.X_add_number;
4632 as_bad (_("Improper position (%lu)"), pos);
4635 if (size == 0 || size > 64
4636 || (pos + size - 1) > 63)
4638 as_bad (_("Improper insert size (%lu, position %lu)"),
4643 if (pos < 32 && (pos + size - 1) < 32)
4658 macro_build ((expressionS *) NULL, s, fmt, treg, sreg, pos,
4675 as_warn (_("Divide by zero."));
4677 macro_build (NULL, "teq", "s,t,q", 0, 0, 7);
4679 macro_build (NULL, "break", "c", 7);
4686 macro_build (NULL, "teq", "s,t,q", treg, 0, 7);
4687 macro_build (NULL, dbl ? "ddiv" : "div", "z,s,t", sreg, treg);
4691 expr1.X_add_number = 8;
4692 macro_build (&expr1, "bne", "s,t,p", treg, 0);
4693 macro_build (NULL, dbl ? "ddiv" : "div", "z,s,t", sreg, treg);
4694 macro_build (NULL, "break", "c", 7);
4696 expr1.X_add_number = -1;
4698 load_register (AT, &expr1, dbl);
4699 expr1.X_add_number = mips_trap ? (dbl ? 12 : 8) : (dbl ? 20 : 16);
4700 macro_build (&expr1, "bne", "s,t,p", treg, AT);
4703 expr1.X_add_number = 1;
4704 load_register (AT, &expr1, dbl);
4705 macro_build (NULL, "dsll32", "d,w,<", AT, AT, 31);
4709 expr1.X_add_number = 0x80000000;
4710 macro_build (&expr1, "lui", "t,u", AT, BFD_RELOC_HI16);
4714 macro_build (NULL, "teq", "s,t,q", sreg, AT, 6);
4715 /* We want to close the noreorder block as soon as possible, so
4716 that later insns are available for delay slot filling. */
4721 expr1.X_add_number = 8;
4722 macro_build (&expr1, "bne", "s,t,p", sreg, AT);
4723 macro_build (NULL, "nop", "", 0);
4725 /* We want to close the noreorder block as soon as possible, so
4726 that later insns are available for delay slot filling. */
4729 macro_build (NULL, "break", "c", 6);
4731 macro_build (NULL, s, "d", dreg);
4770 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4772 as_warn (_("Divide by zero."));
4774 macro_build (NULL, "teq", "s,t,q", 0, 0, 7);
4776 macro_build (NULL, "break", "c", 7);
4779 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4781 if (strcmp (s2, "mflo") == 0)
4782 move_register (dreg, sreg);
4784 move_register (dreg, 0);
4787 if (imm_expr.X_op == O_constant
4788 && imm_expr.X_add_number == -1
4789 && s[strlen (s) - 1] != 'u')
4791 if (strcmp (s2, "mflo") == 0)
4793 macro_build (NULL, dbl ? "dneg" : "neg", "d,w", dreg, sreg);
4796 move_register (dreg, 0);
4801 load_register (AT, &imm_expr, dbl);
4802 macro_build (NULL, s, "z,s,t", sreg, AT);
4803 macro_build (NULL, s2, "d", dreg);
4825 macro_build (NULL, "teq", "s,t,q", treg, 0, 7);
4826 macro_build (NULL, s, "z,s,t", sreg, treg);
4827 /* We want to close the noreorder block as soon as possible, so
4828 that later insns are available for delay slot filling. */
4833 expr1.X_add_number = 8;
4834 macro_build (&expr1, "bne", "s,t,p", treg, 0);
4835 macro_build (NULL, s, "z,s,t", sreg, treg);
4837 /* We want to close the noreorder block as soon as possible, so
4838 that later insns are available for delay slot filling. */
4840 macro_build (NULL, "break", "c", 7);
4842 macro_build (NULL, s2, "d", dreg);
4854 /* Load the address of a symbol into a register. If breg is not
4855 zero, we then add a base register to it. */
4857 if (dbl && HAVE_32BIT_GPRS)
4858 as_warn (_("dla used to load 32-bit register"));
4860 if (! dbl && HAVE_64BIT_OBJECTS)
4861 as_warn (_("la used to load 64-bit address"));
4863 if (offset_expr.X_op == O_constant
4864 && offset_expr.X_add_number >= -0x8000
4865 && offset_expr.X_add_number < 0x8000)
4867 macro_build (&offset_expr, ADDRESS_ADDI_INSN,
4868 "t,r,j", treg, sreg, BFD_RELOC_LO16);
4872 if (!mips_opts.noat && (treg == breg))
4882 if (offset_expr.X_op != O_symbol
4883 && offset_expr.X_op != O_constant)
4885 as_bad (_("expression too complex"));
4886 offset_expr.X_op = O_constant;
4889 if (offset_expr.X_op == O_constant)
4890 load_register (tempreg, &offset_expr, HAVE_64BIT_ADDRESSES);
4891 else if (mips_pic == NO_PIC)
4893 /* If this is a reference to a GP relative symbol, we want
4894 addiu $tempreg,$gp,<sym> (BFD_RELOC_GPREL16)
4896 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
4897 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
4898 If we have a constant, we need two instructions anyhow,
4899 so we may as well always use the latter form.
4901 With 64bit address space and a usable $at we want
4902 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
4903 lui $at,<sym> (BFD_RELOC_HI16_S)
4904 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
4905 daddiu $at,<sym> (BFD_RELOC_LO16)
4907 daddu $tempreg,$tempreg,$at
4909 If $at is already in use, we use a path which is suboptimal
4910 on superscalar processors.
4911 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
4912 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
4914 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
4916 daddiu $tempreg,<sym> (BFD_RELOC_LO16)
4918 For GP relative symbols in 64bit address space we can use
4919 the same sequence as in 32bit address space. */
4920 if (HAVE_64BIT_SYMBOLS)
4922 if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
4923 && !nopic_need_relax (offset_expr.X_add_symbol, 1))
4925 relax_start (offset_expr.X_add_symbol);
4926 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
4927 tempreg, mips_gp_register, BFD_RELOC_GPREL16);
4931 if (used_at == 0 && !mips_opts.noat)
4933 macro_build (&offset_expr, "lui", "t,u",
4934 tempreg, BFD_RELOC_MIPS_HIGHEST);
4935 macro_build (&offset_expr, "lui", "t,u",
4936 AT, BFD_RELOC_HI16_S);
4937 macro_build (&offset_expr, "daddiu", "t,r,j",
4938 tempreg, tempreg, BFD_RELOC_MIPS_HIGHER);
4939 macro_build (&offset_expr, "daddiu", "t,r,j",
4940 AT, AT, BFD_RELOC_LO16);
4941 macro_build (NULL, "dsll32", "d,w,<", tempreg, tempreg, 0);
4942 macro_build (NULL, "daddu", "d,v,t", tempreg, tempreg, AT);
4947 macro_build (&offset_expr, "lui", "t,u",
4948 tempreg, BFD_RELOC_MIPS_HIGHEST);
4949 macro_build (&offset_expr, "daddiu", "t,r,j",
4950 tempreg, tempreg, BFD_RELOC_MIPS_HIGHER);
4951 macro_build (NULL, "dsll", "d,w,<", tempreg, tempreg, 16);
4952 macro_build (&offset_expr, "daddiu", "t,r,j",
4953 tempreg, tempreg, BFD_RELOC_HI16_S);
4954 macro_build (NULL, "dsll", "d,w,<", tempreg, tempreg, 16);
4955 macro_build (&offset_expr, "daddiu", "t,r,j",
4956 tempreg, tempreg, BFD_RELOC_LO16);
4959 if (mips_relax.sequence)
4964 if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
4965 && !nopic_need_relax (offset_expr.X_add_symbol, 1))
4967 relax_start (offset_expr.X_add_symbol);
4968 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
4969 tempreg, mips_gp_register, BFD_RELOC_GPREL16);
4972 if (!IS_SEXT_32BIT_NUM (offset_expr.X_add_number))
4973 as_bad (_("offset too large"));
4974 macro_build_lui (&offset_expr, tempreg);
4975 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
4976 tempreg, tempreg, BFD_RELOC_LO16);
4977 if (mips_relax.sequence)
4981 else if (mips_pic == SVR4_PIC && ! mips_big_got && ! HAVE_NEWABI)
4983 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT16;
4985 /* If this is a reference to an external symbol, and there
4986 is no constant, we want
4987 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4988 or for lca or if tempreg is PIC_CALL_REG
4989 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
4990 For a local symbol, we want
4991 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4993 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
4995 If we have a small constant, and this is a reference to
4996 an external symbol, we want
4997 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4999 addiu $tempreg,$tempreg,<constant>
5000 For a local symbol, we want the same instruction
5001 sequence, but we output a BFD_RELOC_LO16 reloc on the
5004 If we have a large constant, and this is a reference to
5005 an external symbol, we want
5006 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5007 lui $at,<hiconstant>
5008 addiu $at,$at,<loconstant>
5009 addu $tempreg,$tempreg,$at
5010 For a local symbol, we want the same instruction
5011 sequence, but we output a BFD_RELOC_LO16 reloc on the
5015 if (offset_expr.X_add_number == 0)
5017 if (breg == 0 && (call || tempreg == PIC_CALL_REG))
5018 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL16;
5020 relax_start (offset_expr.X_add_symbol);
5021 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
5022 lw_reloc_type, mips_gp_register);
5025 /* We're going to put in an addu instruction using
5026 tempreg, so we may as well insert the nop right
5031 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
5032 tempreg, BFD_RELOC_MIPS_GOT16, mips_gp_register);
5034 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
5035 tempreg, tempreg, BFD_RELOC_LO16);
5037 /* FIXME: If breg == 0, and the next instruction uses
5038 $tempreg, then if this variant case is used an extra
5039 nop will be generated. */
5041 else if (offset_expr.X_add_number >= -0x8000
5042 && offset_expr.X_add_number < 0x8000)
5044 load_got_offset (tempreg, &offset_expr);
5046 add_got_offset (tempreg, &offset_expr);
5050 expr1.X_add_number = offset_expr.X_add_number;
5051 offset_expr.X_add_number =
5052 ((offset_expr.X_add_number + 0x8000) & 0xffff) - 0x8000;
5053 load_got_offset (tempreg, &offset_expr);
5054 offset_expr.X_add_number = expr1.X_add_number;
5055 /* If we are going to add in a base register, and the
5056 target register and the base register are the same,
5057 then we are using AT as a temporary register. Since
5058 we want to load the constant into AT, we add our
5059 current AT (from the global offset table) and the
5060 register into the register now, and pretend we were
5061 not using a base register. */
5065 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
5070 add_got_offset_hilo (tempreg, &offset_expr, AT);
5074 else if (mips_pic == SVR4_PIC && ! mips_big_got && HAVE_NEWABI)
5076 int add_breg_early = 0;
5078 /* If this is a reference to an external, and there is no
5079 constant, or local symbol (*), with or without a
5081 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
5082 or for lca or if tempreg is PIC_CALL_REG
5083 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
5085 If we have a small constant, and this is a reference to
5086 an external symbol, we want
5087 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
5088 addiu $tempreg,$tempreg,<constant>
5090 If we have a large constant, and this is a reference to
5091 an external symbol, we want
5092 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
5093 lui $at,<hiconstant>
5094 addiu $at,$at,<loconstant>
5095 addu $tempreg,$tempreg,$at
5097 (*) Other assemblers seem to prefer GOT_PAGE/GOT_OFST for
5098 local symbols, even though it introduces an additional
5101 if (offset_expr.X_add_number)
5103 expr1.X_add_number = offset_expr.X_add_number;
5104 offset_expr.X_add_number = 0;
5106 relax_start (offset_expr.X_add_symbol);
5107 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
5108 BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
5110 if (expr1.X_add_number >= -0x8000
5111 && expr1.X_add_number < 0x8000)
5113 macro_build (&expr1, ADDRESS_ADDI_INSN, "t,r,j",
5114 tempreg, tempreg, BFD_RELOC_LO16);
5116 else if (IS_SEXT_32BIT_NUM (expr1.X_add_number + 0x8000))
5120 /* If we are going to add in a base register, and the
5121 target register and the base register are the same,
5122 then we are using AT as a temporary register. Since
5123 we want to load the constant into AT, we add our
5124 current AT (from the global offset table) and the
5125 register into the register now, and pretend we were
5126 not using a base register. */
5131 assert (tempreg == AT);
5132 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
5138 load_register (AT, &expr1, HAVE_64BIT_ADDRESSES);
5139 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
5145 as_bad (_("PIC code offset overflow (max 32 signed bits)"));
5148 offset_expr.X_add_number = expr1.X_add_number;
5150 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
5151 BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
5154 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
5155 treg, tempreg, breg);
5161 else if (breg == 0 && (call || tempreg == PIC_CALL_REG))
5163 relax_start (offset_expr.X_add_symbol);
5164 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
5165 BFD_RELOC_MIPS_CALL16, mips_gp_register);
5167 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
5168 BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
5173 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
5174 BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
5177 else if (mips_pic == SVR4_PIC && ! HAVE_NEWABI)
5180 int lui_reloc_type = (int) BFD_RELOC_MIPS_GOT_HI16;
5181 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT_LO16;
5182 int local_reloc_type = (int) BFD_RELOC_MIPS_GOT16;
5184 /* This is the large GOT case. If this is a reference to an
5185 external symbol, and there is no constant, we want
5186 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5187 addu $tempreg,$tempreg,$gp
5188 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5189 or for lca or if tempreg is PIC_CALL_REG
5190 lui $tempreg,<sym> (BFD_RELOC_MIPS_CALL_HI16)
5191 addu $tempreg,$tempreg,$gp
5192 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_CALL_LO16)
5193 For a local symbol, we want
5194 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5196 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
5198 If we have a small constant, and this is a reference to
5199 an external symbol, we want
5200 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5201 addu $tempreg,$tempreg,$gp
5202 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5204 addiu $tempreg,$tempreg,<constant>
5205 For a local symbol, we want
5206 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5208 addiu $tempreg,$tempreg,<constant> (BFD_RELOC_LO16)
5210 If we have a large constant, and this is a reference to
5211 an external symbol, we want
5212 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5213 addu $tempreg,$tempreg,$gp
5214 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5215 lui $at,<hiconstant>
5216 addiu $at,$at,<loconstant>
5217 addu $tempreg,$tempreg,$at
5218 For a local symbol, we want
5219 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5220 lui $at,<hiconstant>
5221 addiu $at,$at,<loconstant> (BFD_RELOC_LO16)
5222 addu $tempreg,$tempreg,$at
5225 expr1.X_add_number = offset_expr.X_add_number;
5226 offset_expr.X_add_number = 0;
5227 relax_start (offset_expr.X_add_symbol);
5228 gpdelay = reg_needs_delay (mips_gp_register);
5229 if (expr1.X_add_number == 0 && breg == 0
5230 && (call || tempreg == PIC_CALL_REG))
5232 lui_reloc_type = (int) BFD_RELOC_MIPS_CALL_HI16;
5233 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL_LO16;
5235 macro_build (&offset_expr, "lui", "t,u", tempreg, lui_reloc_type);
5236 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
5237 tempreg, tempreg, mips_gp_register);
5238 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
5239 tempreg, lw_reloc_type, tempreg);
5240 if (expr1.X_add_number == 0)
5244 /* We're going to put in an addu instruction using
5245 tempreg, so we may as well insert the nop right
5250 else if (expr1.X_add_number >= -0x8000
5251 && expr1.X_add_number < 0x8000)
5254 macro_build (&expr1, ADDRESS_ADDI_INSN, "t,r,j",
5255 tempreg, tempreg, BFD_RELOC_LO16);
5261 /* If we are going to add in a base register, and the
5262 target register and the base register are the same,
5263 then we are using AT as a temporary register. Since
5264 we want to load the constant into AT, we add our
5265 current AT (from the global offset table) and the
5266 register into the register now, and pretend we were
5267 not using a base register. */
5272 assert (tempreg == AT);
5274 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
5279 load_register (AT, &expr1, HAVE_64BIT_ADDRESSES);
5280 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", dreg, dreg, AT);
5284 offset_expr.X_add_number =
5285 ((expr1.X_add_number + 0x8000) & 0xffff) - 0x8000;
5290 /* This is needed because this instruction uses $gp, but
5291 the first instruction on the main stream does not. */
5292 macro_build (NULL, "nop", "");
5295 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
5296 local_reloc_type, mips_gp_register);
5297 if (expr1.X_add_number >= -0x8000
5298 && expr1.X_add_number < 0x8000)
5301 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
5302 tempreg, tempreg, BFD_RELOC_LO16);
5303 /* FIXME: If add_number is 0, and there was no base
5304 register, the external symbol case ended with a load,
5305 so if the symbol turns out to not be external, and
5306 the next instruction uses tempreg, an unnecessary nop
5307 will be inserted. */
5313 /* We must add in the base register now, as in the
5314 external symbol case. */
5315 assert (tempreg == AT);
5317 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
5320 /* We set breg to 0 because we have arranged to add
5321 it in in both cases. */
5325 macro_build_lui (&expr1, AT);
5326 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
5327 AT, AT, BFD_RELOC_LO16);
5328 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
5329 tempreg, tempreg, AT);
5334 else if (mips_pic == SVR4_PIC && HAVE_NEWABI)
5336 int lui_reloc_type = (int) BFD_RELOC_MIPS_GOT_HI16;
5337 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT_LO16;
5338 int add_breg_early = 0;
5340 /* This is the large GOT case. If this is a reference to an
5341 external symbol, and there is no constant, we want
5342 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5343 add $tempreg,$tempreg,$gp
5344 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5345 or for lca or if tempreg is PIC_CALL_REG
5346 lui $tempreg,<sym> (BFD_RELOC_MIPS_CALL_HI16)
5347 add $tempreg,$tempreg,$gp
5348 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_CALL_LO16)
5350 If we have a small constant, and this is a reference to
5351 an external symbol, we want
5352 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5353 add $tempreg,$tempreg,$gp
5354 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5355 addi $tempreg,$tempreg,<constant>
5357 If we have a large constant, and this is a reference to
5358 an external symbol, we want
5359 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5360 addu $tempreg,$tempreg,$gp
5361 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5362 lui $at,<hiconstant>
5363 addi $at,$at,<loconstant>
5364 add $tempreg,$tempreg,$at
5366 If we have NewABI, and we know it's a local symbol, we want
5367 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
5368 addiu $reg,$reg,<sym> (BFD_RELOC_MIPS_GOT_OFST)
5369 otherwise we have to resort to GOT_HI16/GOT_LO16. */
5371 relax_start (offset_expr.X_add_symbol);
5373 expr1.X_add_number = offset_expr.X_add_number;
5374 offset_expr.X_add_number = 0;
5376 if (expr1.X_add_number == 0 && breg == 0
5377 && (call || tempreg == PIC_CALL_REG))
5379 lui_reloc_type = (int) BFD_RELOC_MIPS_CALL_HI16;
5380 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL_LO16;
5382 macro_build (&offset_expr, "lui", "t,u", tempreg, lui_reloc_type);
5383 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
5384 tempreg, tempreg, mips_gp_register);
5385 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
5386 tempreg, lw_reloc_type, tempreg);
5388 if (expr1.X_add_number == 0)
5390 else if (expr1.X_add_number >= -0x8000
5391 && expr1.X_add_number < 0x8000)
5393 macro_build (&expr1, ADDRESS_ADDI_INSN, "t,r,j",
5394 tempreg, tempreg, BFD_RELOC_LO16);
5396 else if (IS_SEXT_32BIT_NUM (expr1.X_add_number + 0x8000))
5400 /* If we are going to add in a base register, and the
5401 target register and the base register are the same,
5402 then we are using AT as a temporary register. Since
5403 we want to load the constant into AT, we add our
5404 current AT (from the global offset table) and the
5405 register into the register now, and pretend we were
5406 not using a base register. */
5411 assert (tempreg == AT);
5412 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
5418 load_register (AT, &expr1, HAVE_64BIT_ADDRESSES);
5419 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", dreg, dreg, AT);
5424 as_bad (_("PIC code offset overflow (max 32 signed bits)"));
5427 offset_expr.X_add_number = expr1.X_add_number;
5428 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
5429 BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register);
5430 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j", tempreg,
5431 tempreg, BFD_RELOC_MIPS_GOT_OFST);
5434 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
5435 treg, tempreg, breg);
5445 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", treg, tempreg, breg);
5449 /* The j instruction may not be used in PIC code, since it
5450 requires an absolute address. We convert it to a b
5452 if (mips_pic == NO_PIC)
5453 macro_build (&offset_expr, "j", "a");
5455 macro_build (&offset_expr, "b", "p");
5458 /* The jal instructions must be handled as macros because when
5459 generating PIC code they expand to multi-instruction
5460 sequences. Normally they are simple instructions. */
5465 if (mips_pic == NO_PIC)
5466 macro_build (NULL, "jalr", "d,s", dreg, sreg);
5467 else if (mips_pic == SVR4_PIC)
5469 if (sreg != PIC_CALL_REG)
5470 as_warn (_("MIPS PIC call to register other than $25"));
5472 macro_build (NULL, "jalr", "d,s", dreg, sreg);
5475 if (mips_cprestore_offset < 0)
5476 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5479 if (! mips_frame_reg_valid)
5481 as_warn (_("No .frame pseudo-op used in PIC code"));
5482 /* Quiet this warning. */
5483 mips_frame_reg_valid = 1;
5485 if (! mips_cprestore_valid)
5487 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5488 /* Quiet this warning. */
5489 mips_cprestore_valid = 1;
5491 expr1.X_add_number = mips_cprestore_offset;
5492 macro_build_ldst_constoffset (&expr1, ADDRESS_LOAD_INSN,
5495 HAVE_64BIT_ADDRESSES);
5505 if (mips_pic == NO_PIC)
5506 macro_build (&offset_expr, "jal", "a");
5507 else if (mips_pic == SVR4_PIC)
5509 /* If this is a reference to an external symbol, and we are
5510 using a small GOT, we want
5511 lw $25,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
5515 lw $gp,cprestore($sp)
5516 The cprestore value is set using the .cprestore
5517 pseudo-op. If we are using a big GOT, we want
5518 lui $25,<sym> (BFD_RELOC_MIPS_CALL_HI16)
5520 lw $25,<sym>($25) (BFD_RELOC_MIPS_CALL_LO16)
5524 lw $gp,cprestore($sp)
5525 If the symbol is not external, we want
5526 lw $25,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5528 addiu $25,$25,<sym> (BFD_RELOC_LO16)
5531 lw $gp,cprestore($sp)
5533 For NewABI, we use the same CALL16 or CALL_HI16/CALL_LO16
5534 sequences above, minus nops, unless the symbol is local,
5535 which enables us to use GOT_PAGE/GOT_OFST (big got) or
5541 relax_start (offset_expr.X_add_symbol);
5542 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
5543 PIC_CALL_REG, BFD_RELOC_MIPS_CALL16,
5546 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
5547 PIC_CALL_REG, BFD_RELOC_MIPS_GOT_DISP,
5553 relax_start (offset_expr.X_add_symbol);
5554 macro_build (&offset_expr, "lui", "t,u", PIC_CALL_REG,
5555 BFD_RELOC_MIPS_CALL_HI16);
5556 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", PIC_CALL_REG,
5557 PIC_CALL_REG, mips_gp_register);
5558 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
5559 PIC_CALL_REG, BFD_RELOC_MIPS_CALL_LO16,
5562 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
5563 PIC_CALL_REG, BFD_RELOC_MIPS_GOT_PAGE,
5565 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
5566 PIC_CALL_REG, PIC_CALL_REG,
5567 BFD_RELOC_MIPS_GOT_OFST);
5571 macro_build_jalr (&offset_expr);
5575 relax_start (offset_expr.X_add_symbol);
5578 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
5579 PIC_CALL_REG, BFD_RELOC_MIPS_CALL16,
5588 gpdelay = reg_needs_delay (mips_gp_register);
5589 macro_build (&offset_expr, "lui", "t,u", PIC_CALL_REG,
5590 BFD_RELOC_MIPS_CALL_HI16);
5591 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", PIC_CALL_REG,
5592 PIC_CALL_REG, mips_gp_register);
5593 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
5594 PIC_CALL_REG, BFD_RELOC_MIPS_CALL_LO16,
5599 macro_build (NULL, "nop", "");
5601 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
5602 PIC_CALL_REG, BFD_RELOC_MIPS_GOT16,
5605 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j",
5606 PIC_CALL_REG, PIC_CALL_REG, BFD_RELOC_LO16);
5608 macro_build_jalr (&offset_expr);
5610 if (mips_cprestore_offset < 0)
5611 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5614 if (! mips_frame_reg_valid)
5616 as_warn (_("No .frame pseudo-op used in PIC code"));
5617 /* Quiet this warning. */
5618 mips_frame_reg_valid = 1;
5620 if (! mips_cprestore_valid)
5622 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5623 /* Quiet this warning. */
5624 mips_cprestore_valid = 1;
5626 if (mips_opts.noreorder)
5627 macro_build (NULL, "nop", "");
5628 expr1.X_add_number = mips_cprestore_offset;
5629 macro_build_ldst_constoffset (&expr1, ADDRESS_LOAD_INSN,
5632 HAVE_64BIT_ADDRESSES);
5658 /* Itbl support may require additional care here. */
5663 /* Itbl support may require additional care here. */
5668 /* Itbl support may require additional care here. */
5673 /* Itbl support may require additional care here. */
5685 if (mips_opts.arch == CPU_R4650)
5687 as_bad (_("opcode not supported on this processor"));
5691 /* Itbl support may require additional care here. */
5696 /* Itbl support may require additional care here. */
5701 /* Itbl support may require additional care here. */
5721 if (breg == treg || coproc || lr)
5742 /* Itbl support may require additional care here. */
5747 /* Itbl support may require additional care here. */
5752 /* Itbl support may require additional care here. */
5757 /* Itbl support may require additional care here. */
5773 if (mips_opts.arch == CPU_R4650)
5775 as_bad (_("opcode not supported on this processor"));
5780 /* Itbl support may require additional care here. */
5784 /* Itbl support may require additional care here. */
5789 /* Itbl support may require additional care here. */
5801 /* Itbl support may require additional care here. */
5802 if (mask == M_LWC1_AB
5803 || mask == M_SWC1_AB
5804 || mask == M_LDC1_AB
5805 || mask == M_SDC1_AB
5814 if (offset_expr.X_op != O_constant
5815 && offset_expr.X_op != O_symbol)
5817 as_bad (_("expression too complex"));
5818 offset_expr.X_op = O_constant;
5821 if (HAVE_32BIT_ADDRESSES
5822 && !IS_SEXT_32BIT_NUM (offset_expr.X_add_number))
5826 sprintf_vma (value, offset_expr.X_add_number);
5827 as_bad (_("Number (0x%s) larger than 32 bits"), value);
5830 /* A constant expression in PIC code can be handled just as it
5831 is in non PIC code. */
5832 if (offset_expr.X_op == O_constant)
5834 expr1.X_add_number = ((offset_expr.X_add_number + 0x8000)
5835 & ~(bfd_vma) 0xffff);
5836 normalize_address_expr (&expr1);
5837 load_register (tempreg, &expr1, HAVE_64BIT_ADDRESSES);
5839 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
5840 tempreg, tempreg, breg);
5841 macro_build (&offset_expr, s, fmt, treg, BFD_RELOC_LO16, tempreg);
5843 else if (mips_pic == NO_PIC)
5845 /* If this is a reference to a GP relative symbol, and there
5846 is no base register, we want
5847 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
5848 Otherwise, if there is no base register, we want
5849 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
5850 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5851 If we have a constant, we need two instructions anyhow,
5852 so we always use the latter form.
5854 If we have a base register, and this is a reference to a
5855 GP relative symbol, we want
5856 addu $tempreg,$breg,$gp
5857 <op> $treg,<sym>($tempreg) (BFD_RELOC_GPREL16)
5859 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
5860 addu $tempreg,$tempreg,$breg
5861 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5862 With a constant we always use the latter case.
5864 With 64bit address space and no base register and $at usable,
5866 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5867 lui $at,<sym> (BFD_RELOC_HI16_S)
5868 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
5871 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5872 If we have a base register, we want
5873 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5874 lui $at,<sym> (BFD_RELOC_HI16_S)
5875 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
5879 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5881 Without $at we can't generate the optimal path for superscalar
5882 processors here since this would require two temporary registers.
5883 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5884 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
5886 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
5888 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5889 If we have a base register, we want
5890 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5891 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
5893 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
5895 daddu $tempreg,$tempreg,$breg
5896 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5898 For GP relative symbols in 64bit address space we can use
5899 the same sequence as in 32bit address space. */
5900 if (HAVE_64BIT_SYMBOLS)
5902 if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
5903 && !nopic_need_relax (offset_expr.X_add_symbol, 1))
5905 relax_start (offset_expr.X_add_symbol);
5908 macro_build (&offset_expr, s, fmt, treg,
5909 BFD_RELOC_GPREL16, mips_gp_register);
5913 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
5914 tempreg, breg, mips_gp_register);
5915 macro_build (&offset_expr, s, fmt, treg,
5916 BFD_RELOC_GPREL16, tempreg);
5921 if (used_at == 0 && !mips_opts.noat)
5923 macro_build (&offset_expr, "lui", "t,u", tempreg,
5924 BFD_RELOC_MIPS_HIGHEST);
5925 macro_build (&offset_expr, "lui", "t,u", AT,
5927 macro_build (&offset_expr, "daddiu", "t,r,j", tempreg,
5928 tempreg, BFD_RELOC_MIPS_HIGHER);
5930 macro_build (NULL, "daddu", "d,v,t", AT, AT, breg);
5931 macro_build (NULL, "dsll32", "d,w,<", tempreg, tempreg, 0);
5932 macro_build (NULL, "daddu", "d,v,t", tempreg, tempreg, AT);
5933 macro_build (&offset_expr, s, fmt, treg, BFD_RELOC_LO16,
5939 macro_build (&offset_expr, "lui", "t,u", tempreg,
5940 BFD_RELOC_MIPS_HIGHEST);
5941 macro_build (&offset_expr, "daddiu", "t,r,j", tempreg,
5942 tempreg, BFD_RELOC_MIPS_HIGHER);
5943 macro_build (NULL, "dsll", "d,w,<", tempreg, tempreg, 16);
5944 macro_build (&offset_expr, "daddiu", "t,r,j", tempreg,
5945 tempreg, BFD_RELOC_HI16_S);
5946 macro_build (NULL, "dsll", "d,w,<", tempreg, tempreg, 16);
5948 macro_build (NULL, "daddu", "d,v,t",
5949 tempreg, tempreg, breg);
5950 macro_build (&offset_expr, s, fmt, treg,
5951 BFD_RELOC_LO16, tempreg);
5954 if (mips_relax.sequence)
5961 if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
5962 && !nopic_need_relax (offset_expr.X_add_symbol, 1))
5964 relax_start (offset_expr.X_add_symbol);
5965 macro_build (&offset_expr, s, fmt, treg, BFD_RELOC_GPREL16,
5969 macro_build_lui (&offset_expr, tempreg);
5970 macro_build (&offset_expr, s, fmt, treg,
5971 BFD_RELOC_LO16, tempreg);
5972 if (mips_relax.sequence)
5977 if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
5978 && !nopic_need_relax (offset_expr.X_add_symbol, 1))
5980 relax_start (offset_expr.X_add_symbol);
5981 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
5982 tempreg, breg, mips_gp_register);
5983 macro_build (&offset_expr, s, fmt, treg,
5984 BFD_RELOC_GPREL16, tempreg);
5987 macro_build_lui (&offset_expr, tempreg);
5988 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
5989 tempreg, tempreg, breg);
5990 macro_build (&offset_expr, s, fmt, treg,
5991 BFD_RELOC_LO16, tempreg);
5992 if (mips_relax.sequence)
5996 else if (mips_pic == SVR4_PIC && ! mips_big_got)
5998 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT16;
6000 /* If this is a reference to an external symbol, we want
6001 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6003 <op> $treg,0($tempreg)
6005 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6007 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
6008 <op> $treg,0($tempreg)
6011 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
6012 <op> $treg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_OFST)
6014 If there is a base register, we add it to $tempreg before
6015 the <op>. If there is a constant, we stick it in the
6016 <op> instruction. We don't handle constants larger than
6017 16 bits, because we have no way to load the upper 16 bits
6018 (actually, we could handle them for the subset of cases
6019 in which we are not using $at). */
6020 assert (offset_expr.X_op == O_symbol);
6023 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
6024 BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register);
6026 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
6027 tempreg, tempreg, breg);
6028 macro_build (&offset_expr, s, fmt, treg,
6029 BFD_RELOC_MIPS_GOT_OFST, tempreg);
6032 expr1.X_add_number = offset_expr.X_add_number;
6033 offset_expr.X_add_number = 0;
6034 if (expr1.X_add_number < -0x8000
6035 || expr1.X_add_number >= 0x8000)
6036 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6037 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
6038 lw_reloc_type, mips_gp_register);
6040 relax_start (offset_expr.X_add_symbol);
6042 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j", tempreg,
6043 tempreg, BFD_RELOC_LO16);
6046 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
6047 tempreg, tempreg, breg);
6048 macro_build (&expr1, s, fmt, treg, BFD_RELOC_LO16, tempreg);
6050 else if (mips_pic == SVR4_PIC && ! HAVE_NEWABI)
6054 /* If this is a reference to an external symbol, we want
6055 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
6056 addu $tempreg,$tempreg,$gp
6057 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
6058 <op> $treg,0($tempreg)
6060 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6062 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
6063 <op> $treg,0($tempreg)
6064 If there is a base register, we add it to $tempreg before
6065 the <op>. If there is a constant, we stick it in the
6066 <op> instruction. We don't handle constants larger than
6067 16 bits, because we have no way to load the upper 16 bits
6068 (actually, we could handle them for the subset of cases
6069 in which we are not using $at). */
6070 assert (offset_expr.X_op == O_symbol);
6071 expr1.X_add_number = offset_expr.X_add_number;
6072 offset_expr.X_add_number = 0;
6073 if (expr1.X_add_number < -0x8000
6074 || expr1.X_add_number >= 0x8000)
6075 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6076 gpdelay = reg_needs_delay (mips_gp_register);
6077 relax_start (offset_expr.X_add_symbol);
6078 macro_build (&offset_expr, "lui", "t,u", tempreg,
6079 BFD_RELOC_MIPS_GOT_HI16);
6080 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", tempreg, tempreg,
6082 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
6083 BFD_RELOC_MIPS_GOT_LO16, tempreg);
6086 macro_build (NULL, "nop", "");
6087 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
6088 BFD_RELOC_MIPS_GOT16, mips_gp_register);
6090 macro_build (&offset_expr, ADDRESS_ADDI_INSN, "t,r,j", tempreg,
6091 tempreg, BFD_RELOC_LO16);
6095 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
6096 tempreg, tempreg, breg);
6097 macro_build (&expr1, s, fmt, treg, BFD_RELOC_LO16, tempreg);
6099 else if (mips_pic == SVR4_PIC && HAVE_NEWABI)
6101 /* If this is a reference to an external symbol, we want
6102 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
6103 add $tempreg,$tempreg,$gp
6104 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
6105 <op> $treg,<ofst>($tempreg)
6106 Otherwise, for local symbols, we want:
6107 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
6108 <op> $treg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_OFST) */
6109 assert (offset_expr.X_op == O_symbol);
6110 expr1.X_add_number = offset_expr.X_add_number;
6111 offset_expr.X_add_number = 0;
6112 if (expr1.X_add_number < -0x8000
6113 || expr1.X_add_number >= 0x8000)
6114 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6115 relax_start (offset_expr.X_add_symbol);
6116 macro_build (&offset_expr, "lui", "t,u", tempreg,
6117 BFD_RELOC_MIPS_GOT_HI16);
6118 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", tempreg, tempreg,
6120 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
6121 BFD_RELOC_MIPS_GOT_LO16, tempreg);
6123 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
6124 tempreg, tempreg, breg);
6125 macro_build (&expr1, s, fmt, treg, BFD_RELOC_LO16, tempreg);
6128 offset_expr.X_add_number = expr1.X_add_number;
6129 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", tempreg,
6130 BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register);
6132 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
6133 tempreg, tempreg, breg);
6134 macro_build (&offset_expr, s, fmt, treg,
6135 BFD_RELOC_MIPS_GOT_OFST, tempreg);
6145 load_register (treg, &imm_expr, 0);
6149 load_register (treg, &imm_expr, 1);
6153 if (imm_expr.X_op == O_constant)
6156 load_register (AT, &imm_expr, 0);
6157 macro_build (NULL, "mtc1", "t,G", AT, treg);
6162 assert (offset_expr.X_op == O_symbol
6163 && strcmp (segment_name (S_GET_SEGMENT
6164 (offset_expr.X_add_symbol)),
6166 && offset_expr.X_add_number == 0);
6167 macro_build (&offset_expr, "lwc1", "T,o(b)", treg,
6168 BFD_RELOC_MIPS_LITERAL, mips_gp_register);
6173 /* Check if we have a constant in IMM_EXPR. If the GPRs are 64 bits
6174 wide, IMM_EXPR is the entire value. Otherwise IMM_EXPR is the high
6175 order 32 bits of the value and the low order 32 bits are either
6176 zero or in OFFSET_EXPR. */
6177 if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big)
6179 if (HAVE_64BIT_GPRS)
6180 load_register (treg, &imm_expr, 1);
6185 if (target_big_endian)
6197 load_register (hreg, &imm_expr, 0);
6200 if (offset_expr.X_op == O_absent)
6201 move_register (lreg, 0);
6204 assert (offset_expr.X_op == O_constant);
6205 load_register (lreg, &offset_expr, 0);
6212 /* We know that sym is in the .rdata section. First we get the
6213 upper 16 bits of the address. */
6214 if (mips_pic == NO_PIC)
6216 macro_build_lui (&offset_expr, AT);
6219 else if (mips_pic == SVR4_PIC)
6221 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", AT,
6222 BFD_RELOC_MIPS_GOT16, mips_gp_register);
6228 /* Now we load the register(s). */
6229 if (HAVE_64BIT_GPRS)
6232 macro_build (&offset_expr, "ld", "t,o(b)", treg, BFD_RELOC_LO16, AT);
6237 macro_build (&offset_expr, "lw", "t,o(b)", treg, BFD_RELOC_LO16, AT);
6240 /* FIXME: How in the world do we deal with the possible
6242 offset_expr.X_add_number += 4;
6243 macro_build (&offset_expr, "lw", "t,o(b)",
6244 treg + 1, BFD_RELOC_LO16, AT);
6250 /* Check if we have a constant in IMM_EXPR. If the FPRs are 64 bits
6251 wide, IMM_EXPR is the entire value and the GPRs are known to be 64
6252 bits wide as well. Otherwise IMM_EXPR is the high order 32 bits of
6253 the value and the low order 32 bits are either zero or in
6255 if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big)
6258 load_register (AT, &imm_expr, HAVE_64BIT_FPRS);
6259 if (HAVE_64BIT_FPRS)
6261 assert (HAVE_64BIT_GPRS);
6262 macro_build (NULL, "dmtc1", "t,S", AT, treg);
6266 macro_build (NULL, "mtc1", "t,G", AT, treg + 1);
6267 if (offset_expr.X_op == O_absent)
6268 macro_build (NULL, "mtc1", "t,G", 0, treg);
6271 assert (offset_expr.X_op == O_constant);
6272 load_register (AT, &offset_expr, 0);
6273 macro_build (NULL, "mtc1", "t,G", AT, treg);
6279 assert (offset_expr.X_op == O_symbol
6280 && offset_expr.X_add_number == 0);
6281 s = segment_name (S_GET_SEGMENT (offset_expr.X_add_symbol));
6282 if (strcmp (s, ".lit8") == 0)
6284 if (mips_opts.isa != ISA_MIPS1)
6286 macro_build (&offset_expr, "ldc1", "T,o(b)", treg,
6287 BFD_RELOC_MIPS_LITERAL, mips_gp_register);
6290 breg = mips_gp_register;
6291 r = BFD_RELOC_MIPS_LITERAL;
6296 assert (strcmp (s, RDATA_SECTION_NAME) == 0);
6298 if (mips_pic == SVR4_PIC)
6299 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", AT,
6300 BFD_RELOC_MIPS_GOT16, mips_gp_register);
6303 /* FIXME: This won't work for a 64 bit address. */
6304 macro_build_lui (&offset_expr, AT);
6307 if (mips_opts.isa != ISA_MIPS1)
6309 macro_build (&offset_expr, "ldc1", "T,o(b)",
6310 treg, BFD_RELOC_LO16, AT);
6319 if (mips_opts.arch == CPU_R4650)
6321 as_bad (_("opcode not supported on this processor"));
6324 /* Even on a big endian machine $fn comes before $fn+1. We have
6325 to adjust when loading from memory. */
6328 assert (mips_opts.isa == ISA_MIPS1);
6329 macro_build (&offset_expr, "lwc1", "T,o(b)",
6330 target_big_endian ? treg + 1 : treg, r, breg);
6331 /* FIXME: A possible overflow which I don't know how to deal
6333 offset_expr.X_add_number += 4;
6334 macro_build (&offset_expr, "lwc1", "T,o(b)",
6335 target_big_endian ? treg : treg + 1, r, breg);
6340 * The MIPS assembler seems to check for X_add_number not
6341 * being double aligned and generating:
6344 * addiu at,at,%lo(foo+1)
6347 * But, the resulting address is the same after relocation so why
6348 * generate the extra instruction?
6350 if (mips_opts.arch == CPU_R4650)
6352 as_bad (_("opcode not supported on this processor"));
6355 /* Itbl support may require additional care here. */
6357 if (mips_opts.isa != ISA_MIPS1)
6368 if (mips_opts.arch == CPU_R4650)
6370 as_bad (_("opcode not supported on this processor"));
6374 if (mips_opts.isa != ISA_MIPS1)
6382 /* Itbl support may require additional care here. */
6387 if (HAVE_64BIT_GPRS)
6398 if (HAVE_64BIT_GPRS)
6408 if (offset_expr.X_op != O_symbol
6409 && offset_expr.X_op != O_constant)
6411 as_bad (_("expression too complex"));
6412 offset_expr.X_op = O_constant;
6415 if (HAVE_32BIT_ADDRESSES
6416 && !IS_SEXT_32BIT_NUM (offset_expr.X_add_number))
6420 sprintf_vma (value, offset_expr.X_add_number);
6421 as_bad (_("Number (0x%s) larger than 32 bits"), value);
6424 /* Even on a big endian machine $fn comes before $fn+1. We have
6425 to adjust when loading from memory. We set coproc if we must
6426 load $fn+1 first. */
6427 /* Itbl support may require additional care here. */
6428 if (! target_big_endian)
6431 if (mips_pic == NO_PIC
6432 || offset_expr.X_op == O_constant)
6434 /* If this is a reference to a GP relative symbol, we want
6435 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
6436 <op> $treg+1,<sym>+4($gp) (BFD_RELOC_GPREL16)
6437 If we have a base register, we use this
6439 <op> $treg,<sym>($at) (BFD_RELOC_GPREL16)
6440 <op> $treg+1,<sym>+4($at) (BFD_RELOC_GPREL16)
6441 If this is not a GP relative symbol, we want
6442 lui $at,<sym> (BFD_RELOC_HI16_S)
6443 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
6444 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
6445 If there is a base register, we add it to $at after the
6446 lui instruction. If there is a constant, we always use
6448 if (offset_expr.X_op == O_symbol
6449 && (valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
6450 && !nopic_need_relax (offset_expr.X_add_symbol, 1))
6452 relax_start (offset_expr.X_add_symbol);
6455 tempreg = mips_gp_register;
6459 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
6460 AT, breg, mips_gp_register);
6465 /* Itbl support may require additional care here. */
6466 macro_build (&offset_expr, s, fmt, coproc ? treg + 1 : treg,
6467 BFD_RELOC_GPREL16, tempreg);
6468 offset_expr.X_add_number += 4;
6470 /* Set mips_optimize to 2 to avoid inserting an
6472 hold_mips_optimize = mips_optimize;
6474 /* Itbl support may require additional care here. */
6475 macro_build (&offset_expr, s, fmt, coproc ? treg : treg + 1,
6476 BFD_RELOC_GPREL16, tempreg);
6477 mips_optimize = hold_mips_optimize;
6481 /* We just generated two relocs. When tc_gen_reloc
6482 handles this case, it will skip the first reloc and
6483 handle the second. The second reloc already has an
6484 extra addend of 4, which we added above. We must
6485 subtract it out, and then subtract another 4 to make
6486 the first reloc come out right. The second reloc
6487 will come out right because we are going to add 4 to
6488 offset_expr when we build its instruction below.
6490 If we have a symbol, then we don't want to include
6491 the offset, because it will wind up being included
6492 when we generate the reloc. */
6494 if (offset_expr.X_op == O_constant)
6495 offset_expr.X_add_number -= 8;
6498 offset_expr.X_add_number = -4;
6499 offset_expr.X_op = O_constant;
6503 macro_build_lui (&offset_expr, AT);
6505 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, breg, AT);
6506 /* Itbl support may require additional care here. */
6507 macro_build (&offset_expr, s, fmt, coproc ? treg + 1 : treg,
6508 BFD_RELOC_LO16, AT);
6509 /* FIXME: How do we handle overflow here? */
6510 offset_expr.X_add_number += 4;
6511 /* Itbl support may require additional care here. */
6512 macro_build (&offset_expr, s, fmt, coproc ? treg : treg + 1,
6513 BFD_RELOC_LO16, AT);
6514 if (mips_relax.sequence)
6517 else if (mips_pic == SVR4_PIC && ! mips_big_got)
6519 /* If this is a reference to an external symbol, we want
6520 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6525 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6527 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
6528 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
6529 If there is a base register we add it to $at before the
6530 lwc1 instructions. If there is a constant we include it
6531 in the lwc1 instructions. */
6533 expr1.X_add_number = offset_expr.X_add_number;
6534 if (expr1.X_add_number < -0x8000
6535 || expr1.X_add_number >= 0x8000 - 4)
6536 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6537 load_got_offset (AT, &offset_expr);
6540 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, breg, AT);
6542 /* Set mips_optimize to 2 to avoid inserting an undesired
6544 hold_mips_optimize = mips_optimize;
6547 /* Itbl support may require additional care here. */
6548 relax_start (offset_expr.X_add_symbol);
6549 macro_build (&expr1, s, fmt, coproc ? treg + 1 : treg,
6550 BFD_RELOC_LO16, AT);
6551 expr1.X_add_number += 4;
6552 macro_build (&expr1, s, fmt, coproc ? treg : treg + 1,
6553 BFD_RELOC_LO16, AT);
6555 macro_build (&offset_expr, s, fmt, coproc ? treg + 1 : treg,
6556 BFD_RELOC_LO16, AT);
6557 offset_expr.X_add_number += 4;
6558 macro_build (&offset_expr, s, fmt, coproc ? treg : treg + 1,
6559 BFD_RELOC_LO16, AT);
6562 mips_optimize = hold_mips_optimize;
6564 else if (mips_pic == SVR4_PIC)
6568 /* If this is a reference to an external symbol, we want
6569 lui $at,<sym> (BFD_RELOC_MIPS_GOT_HI16)
6571 lw $at,<sym>($at) (BFD_RELOC_MIPS_GOT_LO16)
6576 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6578 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
6579 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
6580 If there is a base register we add it to $at before the
6581 lwc1 instructions. If there is a constant we include it
6582 in the lwc1 instructions. */
6584 expr1.X_add_number = offset_expr.X_add_number;
6585 offset_expr.X_add_number = 0;
6586 if (expr1.X_add_number < -0x8000
6587 || expr1.X_add_number >= 0x8000 - 4)
6588 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6589 gpdelay = reg_needs_delay (mips_gp_register);
6590 relax_start (offset_expr.X_add_symbol);
6591 macro_build (&offset_expr, "lui", "t,u",
6592 AT, BFD_RELOC_MIPS_GOT_HI16);
6593 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t",
6594 AT, AT, mips_gp_register);
6595 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)",
6596 AT, BFD_RELOC_MIPS_GOT_LO16, AT);
6599 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, breg, AT);
6600 /* Itbl support may require additional care here. */
6601 macro_build (&expr1, s, fmt, coproc ? treg + 1 : treg,
6602 BFD_RELOC_LO16, AT);
6603 expr1.X_add_number += 4;
6605 /* Set mips_optimize to 2 to avoid inserting an undesired
6607 hold_mips_optimize = mips_optimize;
6609 /* Itbl support may require additional care here. */
6610 macro_build (&expr1, s, fmt, coproc ? treg : treg + 1,
6611 BFD_RELOC_LO16, AT);
6612 mips_optimize = hold_mips_optimize;
6613 expr1.X_add_number -= 4;
6616 offset_expr.X_add_number = expr1.X_add_number;
6618 macro_build (NULL, "nop", "");
6619 macro_build (&offset_expr, ADDRESS_LOAD_INSN, "t,o(b)", AT,
6620 BFD_RELOC_MIPS_GOT16, mips_gp_register);
6623 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, breg, AT);
6624 /* Itbl support may require additional care here. */
6625 macro_build (&offset_expr, s, fmt, coproc ? treg + 1 : treg,
6626 BFD_RELOC_LO16, AT);
6627 offset_expr.X_add_number += 4;
6629 /* Set mips_optimize to 2 to avoid inserting an undesired
6631 hold_mips_optimize = mips_optimize;
6633 /* Itbl support may require additional care here. */
6634 macro_build (&offset_expr, s, fmt, coproc ? treg : treg + 1,
6635 BFD_RELOC_LO16, AT);
6636 mips_optimize = hold_mips_optimize;
6650 assert (HAVE_32BIT_ADDRESSES);
6651 macro_build (&offset_expr, s, "t,o(b)", treg, BFD_RELOC_LO16, breg);
6652 offset_expr.X_add_number += 4;
6653 macro_build (&offset_expr, s, "t,o(b)", treg + 1, BFD_RELOC_LO16, breg);
6656 /* New code added to support COPZ instructions.
6657 This code builds table entries out of the macros in mip_opcodes.
6658 R4000 uses interlocks to handle coproc delays.
6659 Other chips (like the R3000) require nops to be inserted for delays.
6661 FIXME: Currently, we require that the user handle delays.
6662 In order to fill delay slots for non-interlocked chips,
6663 we must have a way to specify delays based on the coprocessor.
6664 Eg. 4 cycles if load coproc reg from memory, 1 if in cache, etc.
6665 What are the side-effects of the cop instruction?
6666 What cache support might we have and what are its effects?
6667 Both coprocessor & memory require delays. how long???
6668 What registers are read/set/modified?
6670 If an itbl is provided to interpret cop instructions,
6671 this knowledge can be encoded in the itbl spec. */
6685 /* For now we just do C (same as Cz). The parameter will be
6686 stored in insn_opcode by mips_ip. */
6687 macro_build (NULL, s, "C", ip->insn_opcode);
6691 move_register (dreg, sreg);
6694 #ifdef LOSING_COMPILER
6696 /* Try and see if this is a new itbl instruction.
6697 This code builds table entries out of the macros in mip_opcodes.
6698 FIXME: For now we just assemble the expression and pass it's
6699 value along as a 32-bit immediate.
6700 We may want to have the assembler assemble this value,
6701 so that we gain the assembler's knowledge of delay slots,
6703 Would it be more efficient to use mask (id) here? */
6704 if (itbl_have_entries
6705 && (immed_expr = itbl_assemble (ip->insn_mo->name, "")))
6707 s = ip->insn_mo->name;
6709 coproc = ITBL_DECODE_PNUM (immed_expr);;
6710 macro_build (&immed_expr, s, "C");
6716 if (mips_opts.noat && used_at)
6717 as_bad (_("Macro used $at after \".set noat\""));
6721 macro2 (struct mips_cl_insn *ip)
6723 register int treg, sreg, dreg, breg;
6738 bfd_reloc_code_real_type r;
6740 treg = (ip->insn_opcode >> 16) & 0x1f;
6741 dreg = (ip->insn_opcode >> 11) & 0x1f;
6742 sreg = breg = (ip->insn_opcode >> 21) & 0x1f;
6743 mask = ip->insn_mo->mask;
6745 expr1.X_op = O_constant;
6746 expr1.X_op_symbol = NULL;
6747 expr1.X_add_symbol = NULL;
6748 expr1.X_add_number = 1;
6752 #endif /* LOSING_COMPILER */
6757 macro_build (NULL, dbl ? "dmultu" : "multu", "s,t", sreg, treg);
6758 macro_build (NULL, "mflo", "d", dreg);
6764 /* The MIPS assembler some times generates shifts and adds. I'm
6765 not trying to be that fancy. GCC should do this for us
6768 load_register (AT, &imm_expr, dbl);
6769 macro_build (NULL, dbl ? "dmult" : "mult", "s,t", sreg, AT);
6770 macro_build (NULL, "mflo", "d", dreg);
6786 load_register (AT, &imm_expr, dbl);
6787 macro_build (NULL, dbl ? "dmult" : "mult", "s,t", sreg, imm ? AT : treg);
6788 macro_build (NULL, "mflo", "d", dreg);
6789 macro_build (NULL, dbl ? "dsra32" : "sra", "d,w,<", dreg, dreg, RA);
6790 macro_build (NULL, "mfhi", "d", AT);
6792 macro_build (NULL, "tne", "s,t,q", dreg, AT, 6);
6795 expr1.X_add_number = 8;
6796 macro_build (&expr1, "beq", "s,t,p", dreg, AT);
6797 macro_build (NULL, "nop", "", 0);
6798 macro_build (NULL, "break", "c", 6);
6801 macro_build (NULL, "mflo", "d", dreg);
6817 load_register (AT, &imm_expr, dbl);
6818 macro_build (NULL, dbl ? "dmultu" : "multu", "s,t",
6819 sreg, imm ? AT : treg);
6820 macro_build (NULL, "mfhi", "d", AT);
6821 macro_build (NULL, "mflo", "d", dreg);
6823 macro_build (NULL, "tne", "s,t,q", AT, 0, 6);
6826 expr1.X_add_number = 8;
6827 macro_build (&expr1, "beq", "s,t,p", AT, 0);
6828 macro_build (NULL, "nop", "", 0);
6829 macro_build (NULL, "break", "c", 6);
6835 if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_opts.arch))
6846 macro_build (NULL, "dnegu", "d,w", tempreg, treg);
6847 macro_build (NULL, "drorv", "d,t,s", dreg, sreg, tempreg);
6851 macro_build (NULL, "dsubu", "d,v,t", AT, 0, treg);
6852 macro_build (NULL, "dsrlv", "d,t,s", AT, sreg, AT);
6853 macro_build (NULL, "dsllv", "d,t,s", dreg, sreg, treg);
6854 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
6858 if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_opts.arch))
6869 macro_build (NULL, "negu", "d,w", tempreg, treg);
6870 macro_build (NULL, "rorv", "d,t,s", dreg, sreg, tempreg);
6874 macro_build (NULL, "subu", "d,v,t", AT, 0, treg);
6875 macro_build (NULL, "srlv", "d,t,s", AT, sreg, AT);
6876 macro_build (NULL, "sllv", "d,t,s", dreg, sreg, treg);
6877 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
6885 if (imm_expr.X_op != O_constant)
6886 as_bad (_("Improper rotate count"));
6887 rot = imm_expr.X_add_number & 0x3f;
6888 if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_opts.arch))
6890 rot = (64 - rot) & 0x3f;
6892 macro_build (NULL, "dror32", "d,w,<", dreg, sreg, rot - 32);
6894 macro_build (NULL, "dror", "d,w,<", dreg, sreg, rot);
6899 macro_build (NULL, "dsrl", "d,w,<", dreg, sreg, 0);
6902 l = (rot < 0x20) ? "dsll" : "dsll32";
6903 r = ((0x40 - rot) < 0x20) ? "dsrl" : "dsrl32";
6906 macro_build (NULL, l, "d,w,<", AT, sreg, rot);
6907 macro_build (NULL, r, "d,w,<", dreg, sreg, (0x20 - rot) & 0x1f);
6908 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
6916 if (imm_expr.X_op != O_constant)
6917 as_bad (_("Improper rotate count"));
6918 rot = imm_expr.X_add_number & 0x1f;
6919 if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_opts.arch))
6921 macro_build (NULL, "ror", "d,w,<", dreg, sreg, (32 - rot) & 0x1f);
6926 macro_build (NULL, "srl", "d,w,<", dreg, sreg, 0);
6930 macro_build (NULL, "sll", "d,w,<", AT, sreg, rot);
6931 macro_build (NULL, "srl", "d,w,<", dreg, sreg, (0x20 - rot) & 0x1f);
6932 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
6937 if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_opts.arch))
6939 macro_build (NULL, "drorv", "d,t,s", dreg, sreg, treg);
6943 macro_build (NULL, "dsubu", "d,v,t", AT, 0, treg);
6944 macro_build (NULL, "dsllv", "d,t,s", AT, sreg, AT);
6945 macro_build (NULL, "dsrlv", "d,t,s", dreg, sreg, treg);
6946 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
6950 if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_opts.arch))
6952 macro_build (NULL, "rorv", "d,t,s", dreg, sreg, treg);
6956 macro_build (NULL, "subu", "d,v,t", AT, 0, treg);
6957 macro_build (NULL, "sllv", "d,t,s", AT, sreg, AT);
6958 macro_build (NULL, "srlv", "d,t,s", dreg, sreg, treg);
6959 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
6967 if (imm_expr.X_op != O_constant)
6968 as_bad (_("Improper rotate count"));
6969 rot = imm_expr.X_add_number & 0x3f;
6970 if (ISA_HAS_DROR (mips_opts.isa) || CPU_HAS_DROR (mips_opts.arch))
6973 macro_build (NULL, "dror32", "d,w,<", dreg, sreg, rot - 32);
6975 macro_build (NULL, "dror", "d,w,<", dreg, sreg, rot);
6980 macro_build (NULL, "dsrl", "d,w,<", dreg, sreg, 0);
6983 r = (rot < 0x20) ? "dsrl" : "dsrl32";
6984 l = ((0x40 - rot) < 0x20) ? "dsll" : "dsll32";
6987 macro_build (NULL, r, "d,w,<", AT, sreg, rot);
6988 macro_build (NULL, l, "d,w,<", dreg, sreg, (0x20 - rot) & 0x1f);
6989 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
6997 if (imm_expr.X_op != O_constant)
6998 as_bad (_("Improper rotate count"));
6999 rot = imm_expr.X_add_number & 0x1f;
7000 if (ISA_HAS_ROR (mips_opts.isa) || CPU_HAS_ROR (mips_opts.arch))
7002 macro_build (NULL, "ror", "d,w,<", dreg, sreg, rot);
7007 macro_build (NULL, "srl", "d,w,<", dreg, sreg, 0);
7011 macro_build (NULL, "srl", "d,w,<", AT, sreg, rot);
7012 macro_build (NULL, "sll", "d,w,<", dreg, sreg, (0x20 - rot) & 0x1f);
7013 macro_build (NULL, "or", "d,v,t", dreg, dreg, AT);
7018 if (mips_opts.arch == CPU_R4650)
7020 as_bad (_("opcode not supported on this processor"));
7023 assert (mips_opts.isa == ISA_MIPS1);
7024 /* Even on a big endian machine $fn comes before $fn+1. We have
7025 to adjust when storing to memory. */
7026 macro_build (&offset_expr, "swc1", "T,o(b)",
7027 target_big_endian ? treg + 1 : treg, BFD_RELOC_LO16, breg);
7028 offset_expr.X_add_number += 4;
7029 macro_build (&offset_expr, "swc1", "T,o(b)",
7030 target_big_endian ? treg : treg + 1, BFD_RELOC_LO16, breg);
7035 macro_build (&expr1, "sltiu", "t,r,j", dreg, treg, BFD_RELOC_LO16);
7037 macro_build (&expr1, "sltiu", "t,r,j", dreg, sreg, BFD_RELOC_LO16);
7040 macro_build (NULL, "xor", "d,v,t", dreg, sreg, treg);
7041 macro_build (&expr1, "sltiu", "t,r,j", dreg, dreg, BFD_RELOC_LO16);
7046 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
7048 macro_build (&expr1, "sltiu", "t,r,j", dreg, sreg, BFD_RELOC_LO16);
7053 as_warn (_("Instruction %s: result is always false"),
7055 move_register (dreg, 0);
7058 if (imm_expr.X_op == O_constant
7059 && imm_expr.X_add_number >= 0
7060 && imm_expr.X_add_number < 0x10000)
7062 macro_build (&imm_expr, "xori", "t,r,i", dreg, sreg, BFD_RELOC_LO16);
7064 else if (imm_expr.X_op == O_constant
7065 && imm_expr.X_add_number > -0x8000
7066 && imm_expr.X_add_number < 0)
7068 imm_expr.X_add_number = -imm_expr.X_add_number;
7069 macro_build (&imm_expr, HAVE_32BIT_GPRS ? "addiu" : "daddiu",
7070 "t,r,j", dreg, sreg, BFD_RELOC_LO16);
7074 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
7075 macro_build (NULL, "xor", "d,v,t", dreg, sreg, AT);
7078 macro_build (&expr1, "sltiu", "t,r,j", dreg, dreg, BFD_RELOC_LO16);
7081 case M_SGE: /* sreg >= treg <==> not (sreg < treg) */
7087 macro_build (NULL, s, "d,v,t", dreg, sreg, treg);
7088 macro_build (&expr1, "xori", "t,r,i", dreg, dreg, BFD_RELOC_LO16);
7091 case M_SGE_I: /* sreg >= I <==> not (sreg < I) */
7093 if (imm_expr.X_op == O_constant
7094 && imm_expr.X_add_number >= -0x8000
7095 && imm_expr.X_add_number < 0x8000)
7097 macro_build (&imm_expr, mask == M_SGE_I ? "slti" : "sltiu", "t,r,j",
7098 dreg, sreg, BFD_RELOC_LO16);
7102 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
7103 macro_build (NULL, mask == M_SGE_I ? "slt" : "sltu", "d,v,t",
7107 macro_build (&expr1, "xori", "t,r,i", dreg, dreg, BFD_RELOC_LO16);
7110 case M_SGT: /* sreg > treg <==> treg < sreg */
7116 macro_build (NULL, s, "d,v,t", dreg, treg, sreg);
7119 case M_SGT_I: /* sreg > I <==> I < sreg */
7126 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
7127 macro_build (NULL, s, "d,v,t", dreg, AT, sreg);
7130 case M_SLE: /* sreg <= treg <==> treg >= sreg <==> not (treg < sreg) */
7136 macro_build (NULL, s, "d,v,t", dreg, treg, sreg);
7137 macro_build (&expr1, "xori", "t,r,i", dreg, dreg, BFD_RELOC_LO16);
7140 case M_SLE_I: /* sreg <= I <==> I >= sreg <==> not (I < sreg) */
7147 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
7148 macro_build (NULL, s, "d,v,t", dreg, AT, sreg);
7149 macro_build (&expr1, "xori", "t,r,i", dreg, dreg, BFD_RELOC_LO16);
7153 if (imm_expr.X_op == O_constant
7154 && imm_expr.X_add_number >= -0x8000
7155 && imm_expr.X_add_number < 0x8000)
7157 macro_build (&imm_expr, "slti", "t,r,j", dreg, sreg, BFD_RELOC_LO16);
7161 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
7162 macro_build (NULL, "slt", "d,v,t", dreg, sreg, AT);
7166 if (imm_expr.X_op == O_constant
7167 && imm_expr.X_add_number >= -0x8000
7168 && imm_expr.X_add_number < 0x8000)
7170 macro_build (&imm_expr, "sltiu", "t,r,j", dreg, sreg,
7175 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
7176 macro_build (NULL, "sltu", "d,v,t", dreg, sreg, AT);
7181 macro_build (NULL, "sltu", "d,v,t", dreg, 0, treg);
7183 macro_build (NULL, "sltu", "d,v,t", dreg, 0, sreg);
7186 macro_build (NULL, "xor", "d,v,t", dreg, sreg, treg);
7187 macro_build (NULL, "sltu", "d,v,t", dreg, 0, dreg);
7192 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
7194 macro_build (NULL, "sltu", "d,v,t", dreg, 0, sreg);
7199 as_warn (_("Instruction %s: result is always true"),
7201 macro_build (&expr1, HAVE_32BIT_GPRS ? "addiu" : "daddiu", "t,r,j",
7202 dreg, 0, BFD_RELOC_LO16);
7205 if (imm_expr.X_op == O_constant
7206 && imm_expr.X_add_number >= 0
7207 && imm_expr.X_add_number < 0x10000)
7209 macro_build (&imm_expr, "xori", "t,r,i", dreg, sreg, BFD_RELOC_LO16);
7211 else if (imm_expr.X_op == O_constant
7212 && imm_expr.X_add_number > -0x8000
7213 && imm_expr.X_add_number < 0)
7215 imm_expr.X_add_number = -imm_expr.X_add_number;
7216 macro_build (&imm_expr, HAVE_32BIT_GPRS ? "addiu" : "daddiu",
7217 "t,r,j", dreg, sreg, BFD_RELOC_LO16);
7221 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
7222 macro_build (NULL, "xor", "d,v,t", dreg, sreg, AT);
7225 macro_build (NULL, "sltu", "d,v,t", dreg, 0, dreg);
7231 if (imm_expr.X_op == O_constant
7232 && imm_expr.X_add_number > -0x8000
7233 && imm_expr.X_add_number <= 0x8000)
7235 imm_expr.X_add_number = -imm_expr.X_add_number;
7236 macro_build (&imm_expr, dbl ? "daddi" : "addi", "t,r,j",
7237 dreg, sreg, BFD_RELOC_LO16);
7241 load_register (AT, &imm_expr, dbl);
7242 macro_build (NULL, dbl ? "dsub" : "sub", "d,v,t", dreg, sreg, AT);
7248 if (imm_expr.X_op == O_constant
7249 && imm_expr.X_add_number > -0x8000
7250 && imm_expr.X_add_number <= 0x8000)
7252 imm_expr.X_add_number = -imm_expr.X_add_number;
7253 macro_build (&imm_expr, dbl ? "daddiu" : "addiu", "t,r,j",
7254 dreg, sreg, BFD_RELOC_LO16);
7258 load_register (AT, &imm_expr, dbl);
7259 macro_build (NULL, dbl ? "dsubu" : "subu", "d,v,t", dreg, sreg, AT);
7281 load_register (AT, &imm_expr, HAVE_64BIT_GPRS);
7282 macro_build (NULL, s, "s,t", sreg, AT);
7287 assert (mips_opts.isa == ISA_MIPS1);
7289 sreg = (ip->insn_opcode >> 11) & 0x1f; /* floating reg */
7290 dreg = (ip->insn_opcode >> 06) & 0x1f; /* floating reg */
7293 * Is the double cfc1 instruction a bug in the mips assembler;
7294 * or is there a reason for it?
7297 macro_build (NULL, "cfc1", "t,G", treg, RA);
7298 macro_build (NULL, "cfc1", "t,G", treg, RA);
7299 macro_build (NULL, "nop", "");
7300 expr1.X_add_number = 3;
7301 macro_build (&expr1, "ori", "t,r,i", AT, treg, BFD_RELOC_LO16);
7302 expr1.X_add_number = 2;
7303 macro_build (&expr1, "xori", "t,r,i", AT, AT, BFD_RELOC_LO16);
7304 macro_build (NULL, "ctc1", "t,G", AT, RA);
7305 macro_build (NULL, "nop", "");
7306 macro_build (NULL, mask == M_TRUNCWD ? "cvt.w.d" : "cvt.w.s", "D,S",
7308 macro_build (NULL, "ctc1", "t,G", treg, RA);
7309 macro_build (NULL, "nop", "");
7320 if (offset_expr.X_add_number >= 0x7fff)
7321 as_bad (_("operand overflow"));
7322 if (! target_big_endian)
7323 ++offset_expr.X_add_number;
7324 macro_build (&offset_expr, s, "t,o(b)", AT, BFD_RELOC_LO16, breg);
7325 if (! target_big_endian)
7326 --offset_expr.X_add_number;
7328 ++offset_expr.X_add_number;
7329 macro_build (&offset_expr, "lbu", "t,o(b)", treg, BFD_RELOC_LO16, breg);
7330 macro_build (NULL, "sll", "d,w,<", AT, AT, 8);
7331 macro_build (NULL, "or", "d,v,t", treg, treg, AT);
7344 if (offset_expr.X_add_number >= 0x8000 - off)
7345 as_bad (_("operand overflow"));
7353 if (! target_big_endian)
7354 offset_expr.X_add_number += off;
7355 macro_build (&offset_expr, s, "t,o(b)", tempreg, BFD_RELOC_LO16, breg);
7356 if (! target_big_endian)
7357 offset_expr.X_add_number -= off;
7359 offset_expr.X_add_number += off;
7360 macro_build (&offset_expr, s2, "t,o(b)", tempreg, BFD_RELOC_LO16, breg);
7362 /* If necessary, move the result in tempreg the final destination. */
7363 if (treg == tempreg)
7365 /* Protect second load's delay slot. */
7367 move_register (treg, tempreg);
7381 load_address (AT, &offset_expr, &used_at);
7383 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, AT, breg);
7384 if (! target_big_endian)
7385 expr1.X_add_number = off;
7387 expr1.X_add_number = 0;
7388 macro_build (&expr1, s, "t,o(b)", treg, BFD_RELOC_LO16, AT);
7389 if (! target_big_endian)
7390 expr1.X_add_number = 0;
7392 expr1.X_add_number = off;
7393 macro_build (&expr1, s2, "t,o(b)", treg, BFD_RELOC_LO16, AT);
7399 load_address (AT, &offset_expr, &used_at);
7401 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, AT, breg);
7402 if (target_big_endian)
7403 expr1.X_add_number = 0;
7404 macro_build (&expr1, mask == M_ULH_A ? "lb" : "lbu", "t,o(b)",
7405 treg, BFD_RELOC_LO16, AT);
7406 if (target_big_endian)
7407 expr1.X_add_number = 1;
7409 expr1.X_add_number = 0;
7410 macro_build (&expr1, "lbu", "t,o(b)", AT, BFD_RELOC_LO16, AT);
7411 macro_build (NULL, "sll", "d,w,<", treg, treg, 8);
7412 macro_build (NULL, "or", "d,v,t", treg, treg, AT);
7417 if (offset_expr.X_add_number >= 0x7fff)
7418 as_bad (_("operand overflow"));
7419 if (target_big_endian)
7420 ++offset_expr.X_add_number;
7421 macro_build (&offset_expr, "sb", "t,o(b)", treg, BFD_RELOC_LO16, breg);
7422 macro_build (NULL, "srl", "d,w,<", AT, treg, 8);
7423 if (target_big_endian)
7424 --offset_expr.X_add_number;
7426 ++offset_expr.X_add_number;
7427 macro_build (&offset_expr, "sb", "t,o(b)", AT, BFD_RELOC_LO16, breg);
7440 if (offset_expr.X_add_number >= 0x8000 - off)
7441 as_bad (_("operand overflow"));
7442 if (! target_big_endian)
7443 offset_expr.X_add_number += off;
7444 macro_build (&offset_expr, s, "t,o(b)", treg, BFD_RELOC_LO16, breg);
7445 if (! target_big_endian)
7446 offset_expr.X_add_number -= off;
7448 offset_expr.X_add_number += off;
7449 macro_build (&offset_expr, s2, "t,o(b)", treg, BFD_RELOC_LO16, breg);
7463 load_address (AT, &offset_expr, &used_at);
7465 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, AT, breg);
7466 if (! target_big_endian)
7467 expr1.X_add_number = off;
7469 expr1.X_add_number = 0;
7470 macro_build (&expr1, s, "t,o(b)", treg, BFD_RELOC_LO16, AT);
7471 if (! target_big_endian)
7472 expr1.X_add_number = 0;
7474 expr1.X_add_number = off;
7475 macro_build (&expr1, s2, "t,o(b)", treg, BFD_RELOC_LO16, AT);
7480 load_address (AT, &offset_expr, &used_at);
7482 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", AT, AT, breg);
7483 if (! target_big_endian)
7484 expr1.X_add_number = 0;
7485 macro_build (&expr1, "sb", "t,o(b)", treg, BFD_RELOC_LO16, AT);
7486 macro_build (NULL, "srl", "d,w,<", treg, treg, 8);
7487 if (! target_big_endian)
7488 expr1.X_add_number = 1;
7490 expr1.X_add_number = 0;
7491 macro_build (&expr1, "sb", "t,o(b)", treg, BFD_RELOC_LO16, AT);
7492 if (! target_big_endian)
7493 expr1.X_add_number = 0;
7495 expr1.X_add_number = 1;
7496 macro_build (&expr1, "lbu", "t,o(b)", AT, BFD_RELOC_LO16, AT);
7497 macro_build (NULL, "sll", "d,w,<", treg, treg, 8);
7498 macro_build (NULL, "or", "d,v,t", treg, treg, AT);
7502 /* FIXME: Check if this is one of the itbl macros, since they
7503 are added dynamically. */
7504 as_bad (_("Macro %s not implemented yet"), ip->insn_mo->name);
7507 if (mips_opts.noat && used_at)
7508 as_bad (_("Macro used $at after \".set noat\""));
7511 /* Implement macros in mips16 mode. */
7514 mips16_macro (struct mips_cl_insn *ip)
7517 int xreg, yreg, zreg, tmp;
7520 const char *s, *s2, *s3;
7522 mask = ip->insn_mo->mask;
7524 xreg = MIPS16_EXTRACT_OPERAND (RX, *ip);
7525 yreg = MIPS16_EXTRACT_OPERAND (RY, *ip);
7526 zreg = MIPS16_EXTRACT_OPERAND (RZ, *ip);
7528 expr1.X_op = O_constant;
7529 expr1.X_op_symbol = NULL;
7530 expr1.X_add_symbol = NULL;
7531 expr1.X_add_number = 1;
7551 macro_build (NULL, dbl ? "ddiv" : "div", "0,x,y", xreg, yreg);
7552 expr1.X_add_number = 2;
7553 macro_build (&expr1, "bnez", "x,p", yreg);
7554 macro_build (NULL, "break", "6", 7);
7556 /* FIXME: The normal code checks for of -1 / -0x80000000 here,
7557 since that causes an overflow. We should do that as well,
7558 but I don't see how to do the comparisons without a temporary
7561 macro_build (NULL, s, "x", zreg);
7581 macro_build (NULL, s, "0,x,y", xreg, yreg);
7582 expr1.X_add_number = 2;
7583 macro_build (&expr1, "bnez", "x,p", yreg);
7584 macro_build (NULL, "break", "6", 7);
7586 macro_build (NULL, s2, "x", zreg);
7592 macro_build (NULL, dbl ? "dmultu" : "multu", "x,y", xreg, yreg);
7593 macro_build (NULL, "mflo", "x", zreg);
7601 if (imm_expr.X_op != O_constant)
7602 as_bad (_("Unsupported large constant"));
7603 imm_expr.X_add_number = -imm_expr.X_add_number;
7604 macro_build (&imm_expr, dbl ? "daddiu" : "addiu", "y,x,4", yreg, xreg);
7608 if (imm_expr.X_op != O_constant)
7609 as_bad (_("Unsupported large constant"));
7610 imm_expr.X_add_number = -imm_expr.X_add_number;
7611 macro_build (&imm_expr, "addiu", "x,k", xreg);
7615 if (imm_expr.X_op != O_constant)
7616 as_bad (_("Unsupported large constant"));
7617 imm_expr.X_add_number = -imm_expr.X_add_number;
7618 macro_build (&imm_expr, "daddiu", "y,j", yreg);
7640 goto do_reverse_branch;
7644 goto do_reverse_branch;
7656 goto do_reverse_branch;
7667 macro_build (NULL, s, "x,y", xreg, yreg);
7668 macro_build (&offset_expr, s2, "p");
7695 goto do_addone_branch_i;
7700 goto do_addone_branch_i;
7715 goto do_addone_branch_i;
7722 if (imm_expr.X_op != O_constant)
7723 as_bad (_("Unsupported large constant"));
7724 ++imm_expr.X_add_number;
7727 macro_build (&imm_expr, s, s3, xreg);
7728 macro_build (&offset_expr, s2, "p");
7732 expr1.X_add_number = 0;
7733 macro_build (&expr1, "slti", "x,8", yreg);
7735 move_register (xreg, yreg);
7736 expr1.X_add_number = 2;
7737 macro_build (&expr1, "bteqz", "p");
7738 macro_build (NULL, "neg", "x,w", xreg, xreg);
7742 /* For consistency checking, verify that all bits are specified either
7743 by the match/mask part of the instruction definition, or by the
7746 validate_mips_insn (const struct mips_opcode *opc)
7748 const char *p = opc->args;
7750 unsigned long used_bits = opc->mask;
7752 if ((used_bits & opc->match) != opc->match)
7754 as_bad (_("internal: bad mips opcode (mask error): %s %s"),
7755 opc->name, opc->args);
7758 #define USE_BITS(mask,shift) (used_bits |= ((mask) << (shift)))
7768 case 'A': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
7769 case 'B': USE_BITS (OP_MASK_INSMSB, OP_SH_INSMSB); break;
7770 case 'C': USE_BITS (OP_MASK_EXTMSBD, OP_SH_EXTMSBD); break;
7771 case 'D': USE_BITS (OP_MASK_RD, OP_SH_RD);
7772 USE_BITS (OP_MASK_SEL, OP_SH_SEL); break;
7773 case 'E': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
7774 case 'F': USE_BITS (OP_MASK_INSMSB, OP_SH_INSMSB); break;
7775 case 'G': USE_BITS (OP_MASK_EXTMSBD, OP_SH_EXTMSBD); break;
7776 case 'H': USE_BITS (OP_MASK_EXTMSBD, OP_SH_EXTMSBD); break;
7778 case 't': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
7779 case 'T': USE_BITS (OP_MASK_RT, OP_SH_RT);
7780 USE_BITS (OP_MASK_SEL, OP_SH_SEL); break;
7782 as_bad (_("internal: bad mips opcode (unknown extension operand type `+%c'): %s %s"),
7783 c, opc->name, opc->args);
7787 case '<': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
7788 case '>': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
7790 case 'B': USE_BITS (OP_MASK_CODE20, OP_SH_CODE20); break;
7791 case 'C': USE_BITS (OP_MASK_COPZ, OP_SH_COPZ); break;
7792 case 'D': USE_BITS (OP_MASK_FD, OP_SH_FD); break;
7793 case 'E': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
7795 case 'G': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
7796 case 'H': USE_BITS (OP_MASK_SEL, OP_SH_SEL); break;
7798 case 'J': USE_BITS (OP_MASK_CODE19, OP_SH_CODE19); break;
7799 case 'K': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
7801 case 'M': USE_BITS (OP_MASK_CCC, OP_SH_CCC); break;
7802 case 'N': USE_BITS (OP_MASK_BCC, OP_SH_BCC); break;
7803 case 'O': USE_BITS (OP_MASK_ALN, OP_SH_ALN); break;
7804 case 'Q': USE_BITS (OP_MASK_VSEL, OP_SH_VSEL);
7805 USE_BITS (OP_MASK_FT, OP_SH_FT); break;
7806 case 'R': USE_BITS (OP_MASK_FR, OP_SH_FR); break;
7807 case 'S': USE_BITS (OP_MASK_FS, OP_SH_FS); break;
7808 case 'T': USE_BITS (OP_MASK_FT, OP_SH_FT); break;
7809 case 'V': USE_BITS (OP_MASK_FS, OP_SH_FS); break;
7810 case 'W': USE_BITS (OP_MASK_FT, OP_SH_FT); break;
7811 case 'X': USE_BITS (OP_MASK_FD, OP_SH_FD); break;
7812 case 'Y': USE_BITS (OP_MASK_FS, OP_SH_FS); break;
7813 case 'Z': USE_BITS (OP_MASK_FT, OP_SH_FT); break;
7814 case 'a': USE_BITS (OP_MASK_TARGET, OP_SH_TARGET); break;
7815 case 'b': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
7816 case 'c': USE_BITS (OP_MASK_CODE, OP_SH_CODE); break;
7817 case 'd': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
7819 case 'h': USE_BITS (OP_MASK_PREFX, OP_SH_PREFX); break;
7820 case 'i': USE_BITS (OP_MASK_IMMEDIATE, OP_SH_IMMEDIATE); break;
7821 case 'j': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
7822 case 'k': USE_BITS (OP_MASK_CACHE, OP_SH_CACHE); break;
7824 case 'o': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
7825 case 'p': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
7826 case 'q': USE_BITS (OP_MASK_CODE2, OP_SH_CODE2); break;
7827 case 'r': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
7828 case 's': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
7829 case 't': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
7830 case 'u': USE_BITS (OP_MASK_IMMEDIATE, OP_SH_IMMEDIATE); break;
7831 case 'v': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
7832 case 'w': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
7835 case 'P': USE_BITS (OP_MASK_PERFREG, OP_SH_PERFREG); break;
7836 case 'U': USE_BITS (OP_MASK_RD, OP_SH_RD);
7837 USE_BITS (OP_MASK_RT, OP_SH_RT); break;
7838 case 'e': USE_BITS (OP_MASK_VECBYTE, OP_SH_VECBYTE); break;
7839 case '%': USE_BITS (OP_MASK_VECALIGN, OP_SH_VECALIGN); break;
7842 case '3': USE_BITS (OP_MASK_SA3, OP_SH_SA3); break;
7843 case '4': USE_BITS (OP_MASK_SA4, OP_SH_SA4); break;
7844 case '5': USE_BITS (OP_MASK_IMM8, OP_SH_IMM8); break;
7845 case '6': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
7846 case '7': USE_BITS (OP_MASK_DSPACC, OP_SH_DSPACC); break;
7847 case '8': USE_BITS (OP_MASK_WRDSP, OP_SH_WRDSP); break;
7848 case '9': USE_BITS (OP_MASK_DSPACC_S, OP_SH_DSPACC_S);break;
7849 case '0': USE_BITS (OP_MASK_DSPSFT, OP_SH_DSPSFT); break;
7850 case '\'': USE_BITS (OP_MASK_RDDSP, OP_SH_RDDSP); break;
7851 case ':': USE_BITS (OP_MASK_DSPSFT_7, OP_SH_DSPSFT_7);break;
7852 case '@': USE_BITS (OP_MASK_IMM10, OP_SH_IMM10); break;
7853 case '!': USE_BITS (OP_MASK_MT_U, OP_SH_MT_U); break;
7854 case '$': USE_BITS (OP_MASK_MT_H, OP_SH_MT_H); break;
7855 case '*': USE_BITS (OP_MASK_MTACC_T, OP_SH_MTACC_T); break;
7856 case '&': USE_BITS (OP_MASK_MTACC_D, OP_SH_MTACC_D); break;
7857 case 'g': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
7859 as_bad (_("internal: bad mips opcode (unknown operand type `%c'): %s %s"),
7860 c, opc->name, opc->args);
7864 if (used_bits != 0xffffffff)
7866 as_bad (_("internal: bad mips opcode (bits 0x%lx undefined): %s %s"),
7867 ~used_bits & 0xffffffff, opc->name, opc->args);
7873 /* This routine assembles an instruction into its binary format. As a
7874 side effect, it sets one of the global variables imm_reloc or
7875 offset_reloc to the type of relocation to do if one of the operands
7876 is an address expression. */
7879 mips_ip (char *str, struct mips_cl_insn *ip)
7884 struct mips_opcode *insn;
7887 unsigned int lastregno = 0;
7888 unsigned int lastpos = 0;
7889 unsigned int limlo, limhi;
7892 offsetT min_range, max_range;
7896 /* If the instruction contains a '.', we first try to match an instruction
7897 including the '.'. Then we try again without the '.'. */
7899 for (s = str; *s != '\0' && !ISSPACE (*s); ++s)
7902 /* If we stopped on whitespace, then replace the whitespace with null for
7903 the call to hash_find. Save the character we replaced just in case we
7904 have to re-parse the instruction. */
7911 insn = (struct mips_opcode *) hash_find (op_hash, str);
7913 /* If we didn't find the instruction in the opcode table, try again, but
7914 this time with just the instruction up to, but not including the
7918 /* Restore the character we overwrite above (if any). */
7922 /* Scan up to the first '.' or whitespace. */
7924 *s != '\0' && *s != '.' && !ISSPACE (*s);
7928 /* If we did not find a '.', then we can quit now. */
7931 insn_error = "unrecognized opcode";
7935 /* Lookup the instruction in the hash table. */
7937 if ((insn = (struct mips_opcode *) hash_find (op_hash, str)) == NULL)
7939 insn_error = "unrecognized opcode";
7949 assert (strcmp (insn->name, str) == 0);
7951 if (OPCODE_IS_MEMBER (insn,
7953 | (file_ase_mips16 ? INSN_MIPS16 : 0)
7954 | (mips_opts.ase_mdmx ? INSN_MDMX : 0)
7955 | (mips_opts.ase_dsp ? INSN_DSP : 0)
7956 | (mips_opts.ase_mt ? INSN_MT : 0)
7957 | (mips_opts.ase_mips3d ? INSN_MIPS3D : 0)),
7963 if (insn->pinfo != INSN_MACRO)
7965 if (mips_opts.arch == CPU_R4650 && (insn->pinfo & FP_D) != 0)
7971 if (insn + 1 < &mips_opcodes[NUMOPCODES]
7972 && strcmp (insn->name, insn[1].name) == 0)
7981 static char buf[100];
7983 _("opcode not supported on this processor: %s (%s)"),
7984 mips_cpu_info_from_arch (mips_opts.arch)->name,
7985 mips_cpu_info_from_isa (mips_opts.isa)->name);
7994 create_insn (ip, insn);
7996 for (args = insn->args;; ++args)
8000 s += strspn (s, " \t");
8004 case '\0': /* end of args */
8009 case '3': /* dsp 3-bit unsigned immediate in bit 21 */
8010 my_getExpression (&imm_expr, s);
8011 check_absolute_expr (ip, &imm_expr);
8012 if (imm_expr.X_add_number & ~OP_MASK_SA3)
8014 as_warn (_("DSP immediate not in range 0..%d (%lu)"),
8015 OP_MASK_SA3, (unsigned long) imm_expr.X_add_number);
8016 imm_expr.X_add_number &= OP_MASK_SA3;
8018 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_SA3;
8019 imm_expr.X_op = O_absent;
8023 case '4': /* dsp 4-bit unsigned immediate in bit 21 */
8024 my_getExpression (&imm_expr, s);
8025 check_absolute_expr (ip, &imm_expr);
8026 if (imm_expr.X_add_number & ~OP_MASK_SA4)
8028 as_warn (_("DSP immediate not in range 0..%d (%lu)"),
8029 OP_MASK_SA4, (unsigned long) imm_expr.X_add_number);
8030 imm_expr.X_add_number &= OP_MASK_SA4;
8032 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_SA4;
8033 imm_expr.X_op = O_absent;
8037 case '5': /* dsp 8-bit unsigned immediate in bit 16 */
8038 my_getExpression (&imm_expr, s);
8039 check_absolute_expr (ip, &imm_expr);
8040 if (imm_expr.X_add_number & ~OP_MASK_IMM8)
8042 as_warn (_("DSP immediate not in range 0..%d (%lu)"),
8043 OP_MASK_IMM8, (unsigned long) imm_expr.X_add_number);
8044 imm_expr.X_add_number &= OP_MASK_IMM8;
8046 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_IMM8;
8047 imm_expr.X_op = O_absent;
8051 case '6': /* dsp 5-bit unsigned immediate in bit 21 */
8052 my_getExpression (&imm_expr, s);
8053 check_absolute_expr (ip, &imm_expr);
8054 if (imm_expr.X_add_number & ~OP_MASK_RS)
8056 as_warn (_("DSP immediate not in range 0..%d (%lu)"),
8057 OP_MASK_RS, (unsigned long) imm_expr.X_add_number);
8058 imm_expr.X_add_number &= OP_MASK_RS;
8060 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_RS;
8061 imm_expr.X_op = O_absent;
8065 case '7': /* four dsp accumulators in bits 11,12 */
8066 if (s[0] == '$' && s[1] == 'a' && s[2] == 'c' &&
8067 s[3] >= '0' && s[3] <= '3')
8071 ip->insn_opcode |= regno << OP_SH_DSPACC;
8075 as_bad (_("Invalid dsp acc register"));
8078 case '8': /* dsp 6-bit unsigned immediate in bit 11 */
8079 my_getExpression (&imm_expr, s);
8080 check_absolute_expr (ip, &imm_expr);
8081 if (imm_expr.X_add_number & ~OP_MASK_WRDSP)
8083 as_warn (_("DSP immediate not in range 0..%d (%lu)"),
8085 (unsigned long) imm_expr.X_add_number);
8086 imm_expr.X_add_number &= OP_MASK_WRDSP;
8088 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_WRDSP;
8089 imm_expr.X_op = O_absent;
8093 case '9': /* four dsp accumulators in bits 21,22 */
8094 if (s[0] == '$' && s[1] == 'a' && s[2] == 'c' &&
8095 s[3] >= '0' && s[3] <= '3')
8099 ip->insn_opcode |= regno << OP_SH_DSPACC_S;
8103 as_bad (_("Invalid dsp acc register"));
8106 case '0': /* dsp 6-bit signed immediate in bit 20 */
8107 my_getExpression (&imm_expr, s);
8108 check_absolute_expr (ip, &imm_expr);
8109 min_range = -((OP_MASK_DSPSFT + 1) >> 1);
8110 max_range = ((OP_MASK_DSPSFT + 1) >> 1) - 1;
8111 if (imm_expr.X_add_number < min_range ||
8112 imm_expr.X_add_number > max_range)
8114 as_warn (_("DSP immediate not in range %ld..%ld (%ld)"),
8115 (long) min_range, (long) max_range,
8116 (long) imm_expr.X_add_number);
8118 imm_expr.X_add_number &= OP_MASK_DSPSFT;
8119 ip->insn_opcode |= ((unsigned long) imm_expr.X_add_number
8121 imm_expr.X_op = O_absent;
8125 case '\'': /* dsp 6-bit unsigned immediate in bit 16 */
8126 my_getExpression (&imm_expr, s);
8127 check_absolute_expr (ip, &imm_expr);
8128 if (imm_expr.X_add_number & ~OP_MASK_RDDSP)
8130 as_warn (_("DSP immediate not in range 0..%d (%lu)"),
8132 (unsigned long) imm_expr.X_add_number);
8133 imm_expr.X_add_number &= OP_MASK_RDDSP;
8135 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_RDDSP;
8136 imm_expr.X_op = O_absent;
8140 case ':': /* dsp 7-bit signed immediate in bit 19 */
8141 my_getExpression (&imm_expr, s);
8142 check_absolute_expr (ip, &imm_expr);
8143 min_range = -((OP_MASK_DSPSFT_7 + 1) >> 1);
8144 max_range = ((OP_MASK_DSPSFT_7 + 1) >> 1) - 1;
8145 if (imm_expr.X_add_number < min_range ||
8146 imm_expr.X_add_number > max_range)
8148 as_warn (_("DSP immediate not in range %ld..%ld (%ld)"),
8149 (long) min_range, (long) max_range,
8150 (long) imm_expr.X_add_number);
8152 imm_expr.X_add_number &= OP_MASK_DSPSFT_7;
8153 ip->insn_opcode |= ((unsigned long) imm_expr.X_add_number
8155 imm_expr.X_op = O_absent;
8159 case '@': /* dsp 10-bit signed immediate in bit 16 */
8160 my_getExpression (&imm_expr, s);
8161 check_absolute_expr (ip, &imm_expr);
8162 min_range = -((OP_MASK_IMM10 + 1) >> 1);
8163 max_range = ((OP_MASK_IMM10 + 1) >> 1) - 1;
8164 if (imm_expr.X_add_number < min_range ||
8165 imm_expr.X_add_number > max_range)
8167 as_warn (_("DSP immediate not in range %ld..%ld (%ld)"),
8168 (long) min_range, (long) max_range,
8169 (long) imm_expr.X_add_number);
8171 imm_expr.X_add_number &= OP_MASK_IMM10;
8172 ip->insn_opcode |= ((unsigned long) imm_expr.X_add_number
8174 imm_expr.X_op = O_absent;
8178 case '!': /* mt 1-bit unsigned immediate in bit 5 */
8179 my_getExpression (&imm_expr, s);
8180 check_absolute_expr (ip, &imm_expr);
8181 if (imm_expr.X_add_number & ~OP_MASK_MT_U)
8183 as_warn (_("MT immediate not in range 0..%d (%lu)"),
8184 OP_MASK_MT_U, (unsigned long) imm_expr.X_add_number);
8185 imm_expr.X_add_number &= OP_MASK_MT_U;
8187 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_MT_U;
8188 imm_expr.X_op = O_absent;
8192 case '$': /* mt 1-bit unsigned immediate in bit 4 */
8193 my_getExpression (&imm_expr, s);
8194 check_absolute_expr (ip, &imm_expr);
8195 if (imm_expr.X_add_number & ~OP_MASK_MT_H)
8197 as_warn (_("MT immediate not in range 0..%d (%lu)"),
8198 OP_MASK_MT_H, (unsigned long) imm_expr.X_add_number);
8199 imm_expr.X_add_number &= OP_MASK_MT_H;
8201 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_MT_H;
8202 imm_expr.X_op = O_absent;
8206 case '*': /* four dsp accumulators in bits 18,19 */
8207 if (s[0] == '$' && s[1] == 'a' && s[2] == 'c' &&
8208 s[3] >= '0' && s[3] <= '3')
8212 ip->insn_opcode |= regno << OP_SH_MTACC_T;
8216 as_bad (_("Invalid dsp/smartmips acc register"));
8219 case '&': /* four dsp accumulators in bits 13,14 */
8220 if (s[0] == '$' && s[1] == 'a' && s[2] == 'c' &&
8221 s[3] >= '0' && s[3] <= '3')
8225 ip->insn_opcode |= regno << OP_SH_MTACC_D;
8229 as_bad (_("Invalid dsp/smartmips acc register"));
8240 INSERT_OPERAND (RS, *ip, lastregno);
8244 INSERT_OPERAND (RT, *ip, lastregno);
8248 INSERT_OPERAND (FT, *ip, lastregno);
8252 INSERT_OPERAND (FS, *ip, lastregno);
8258 /* Handle optional base register.
8259 Either the base register is omitted or
8260 we must have a left paren. */
8261 /* This is dependent on the next operand specifier
8262 is a base register specification. */
8263 assert (args[1] == 'b' || args[1] == '5'
8264 || args[1] == '-' || args[1] == '4');
8268 case ')': /* these must match exactly */
8275 case '+': /* Opcode extension character. */
8278 case 'A': /* ins/ext position, becomes LSB. */
8287 my_getExpression (&imm_expr, s);
8288 check_absolute_expr (ip, &imm_expr);
8289 if ((unsigned long) imm_expr.X_add_number < limlo
8290 || (unsigned long) imm_expr.X_add_number > limhi)
8292 as_bad (_("Improper position (%lu)"),
8293 (unsigned long) imm_expr.X_add_number);
8294 imm_expr.X_add_number = limlo;
8296 lastpos = imm_expr.X_add_number;
8297 INSERT_OPERAND (SHAMT, *ip, imm_expr.X_add_number);
8298 imm_expr.X_op = O_absent;
8302 case 'B': /* ins size, becomes MSB. */
8311 my_getExpression (&imm_expr, s);
8312 check_absolute_expr (ip, &imm_expr);
8313 /* Check for negative input so that small negative numbers
8314 will not succeed incorrectly. The checks against
8315 (pos+size) transitively check "size" itself,
8316 assuming that "pos" is reasonable. */
8317 if ((long) imm_expr.X_add_number < 0
8318 || ((unsigned long) imm_expr.X_add_number
8320 || ((unsigned long) imm_expr.X_add_number
8323 as_bad (_("Improper insert size (%lu, position %lu)"),
8324 (unsigned long) imm_expr.X_add_number,
8325 (unsigned long) lastpos);
8326 imm_expr.X_add_number = limlo - lastpos;
8328 INSERT_OPERAND (INSMSB, *ip,
8329 lastpos + imm_expr.X_add_number - 1);
8330 imm_expr.X_op = O_absent;
8334 case 'C': /* ext size, becomes MSBD. */
8347 my_getExpression (&imm_expr, s);
8348 check_absolute_expr (ip, &imm_expr);
8349 /* Check for negative input so that small negative numbers
8350 will not succeed incorrectly. The checks against
8351 (pos+size) transitively check "size" itself,
8352 assuming that "pos" is reasonable. */
8353 if ((long) imm_expr.X_add_number < 0
8354 || ((unsigned long) imm_expr.X_add_number
8356 || ((unsigned long) imm_expr.X_add_number
8359 as_bad (_("Improper extract size (%lu, position %lu)"),
8360 (unsigned long) imm_expr.X_add_number,
8361 (unsigned long) lastpos);
8362 imm_expr.X_add_number = limlo - lastpos;
8364 INSERT_OPERAND (EXTMSBD, *ip, imm_expr.X_add_number - 1);
8365 imm_expr.X_op = O_absent;
8370 /* +D is for disassembly only; never match. */
8374 /* "+I" is like "I", except that imm2_expr is used. */
8375 my_getExpression (&imm2_expr, s);
8376 if (imm2_expr.X_op != O_big
8377 && imm2_expr.X_op != O_constant)
8378 insn_error = _("absolute expression required");
8379 if (HAVE_32BIT_GPRS)
8380 normalize_constant_expr (&imm2_expr);
8384 case 'T': /* Coprocessor register */
8385 /* +T is for disassembly only; never match. */
8388 case 't': /* Coprocessor register number */
8389 if (s[0] == '$' && ISDIGIT (s[1]))
8399 while (ISDIGIT (*s));
8401 as_bad (_("Invalid register number (%d)"), regno);
8404 ip->insn_opcode |= regno << OP_SH_RT;
8409 as_bad (_("Invalid coprocessor 0 register number"));
8413 as_bad (_("internal: bad mips opcode (unknown extension operand type `+%c'): %s %s"),
8414 *args, insn->name, insn->args);
8415 /* Further processing is fruitless. */
8420 case '<': /* must be at least one digit */
8422 * According to the manual, if the shift amount is greater
8423 * than 31 or less than 0, then the shift amount should be
8424 * mod 32. In reality the mips assembler issues an error.
8425 * We issue a warning and mask out all but the low 5 bits.
8427 my_getExpression (&imm_expr, s);
8428 check_absolute_expr (ip, &imm_expr);
8429 if ((unsigned long) imm_expr.X_add_number > 31)
8430 as_warn (_("Improper shift amount (%lu)"),
8431 (unsigned long) imm_expr.X_add_number);
8432 INSERT_OPERAND (SHAMT, *ip, imm_expr.X_add_number);
8433 imm_expr.X_op = O_absent;
8437 case '>': /* shift amount minus 32 */
8438 my_getExpression (&imm_expr, s);
8439 check_absolute_expr (ip, &imm_expr);
8440 if ((unsigned long) imm_expr.X_add_number < 32
8441 || (unsigned long) imm_expr.X_add_number > 63)
8443 INSERT_OPERAND (SHAMT, *ip, imm_expr.X_add_number - 32);
8444 imm_expr.X_op = O_absent;
8448 case 'k': /* cache code */
8449 case 'h': /* prefx code */
8450 my_getExpression (&imm_expr, s);
8451 check_absolute_expr (ip, &imm_expr);
8452 if ((unsigned long) imm_expr.X_add_number > 31)
8453 as_warn (_("Invalid value for `%s' (%lu)"),
8455 (unsigned long) imm_expr.X_add_number);
8457 INSERT_OPERAND (CACHE, *ip, imm_expr.X_add_number);
8459 INSERT_OPERAND (PREFX, *ip, imm_expr.X_add_number);
8460 imm_expr.X_op = O_absent;
8464 case 'c': /* break code */
8465 my_getExpression (&imm_expr, s);
8466 check_absolute_expr (ip, &imm_expr);
8467 if ((unsigned long) imm_expr.X_add_number > 1023)
8468 as_warn (_("Illegal break code (%lu)"),
8469 (unsigned long) imm_expr.X_add_number);
8470 INSERT_OPERAND (CODE, *ip, imm_expr.X_add_number);
8471 imm_expr.X_op = O_absent;
8475 case 'q': /* lower break code */
8476 my_getExpression (&imm_expr, s);
8477 check_absolute_expr (ip, &imm_expr);
8478 if ((unsigned long) imm_expr.X_add_number > 1023)
8479 as_warn (_("Illegal lower break code (%lu)"),
8480 (unsigned long) imm_expr.X_add_number);
8481 INSERT_OPERAND (CODE2, *ip, imm_expr.X_add_number);
8482 imm_expr.X_op = O_absent;
8486 case 'B': /* 20-bit syscall/break code. */
8487 my_getExpression (&imm_expr, s);
8488 check_absolute_expr (ip, &imm_expr);
8489 if ((unsigned long) imm_expr.X_add_number > OP_MASK_CODE20)
8490 as_warn (_("Illegal 20-bit code (%lu)"),
8491 (unsigned long) imm_expr.X_add_number);
8492 INSERT_OPERAND (CODE20, *ip, imm_expr.X_add_number);
8493 imm_expr.X_op = O_absent;
8497 case 'C': /* Coprocessor code */
8498 my_getExpression (&imm_expr, s);
8499 check_absolute_expr (ip, &imm_expr);
8500 if ((unsigned long) imm_expr.X_add_number >= (1 << 25))
8502 as_warn (_("Coproccesor code > 25 bits (%lu)"),
8503 (unsigned long) imm_expr.X_add_number);
8504 imm_expr.X_add_number &= ((1 << 25) - 1);
8506 ip->insn_opcode |= imm_expr.X_add_number;
8507 imm_expr.X_op = O_absent;
8511 case 'J': /* 19-bit wait code. */
8512 my_getExpression (&imm_expr, s);
8513 check_absolute_expr (ip, &imm_expr);
8514 if ((unsigned long) imm_expr.X_add_number > OP_MASK_CODE19)
8515 as_warn (_("Illegal 19-bit code (%lu)"),
8516 (unsigned long) imm_expr.X_add_number);
8517 INSERT_OPERAND (CODE19, *ip, imm_expr.X_add_number);
8518 imm_expr.X_op = O_absent;
8522 case 'P': /* Performance register */
8523 my_getExpression (&imm_expr, s);
8524 check_absolute_expr (ip, &imm_expr);
8525 if (imm_expr.X_add_number != 0 && imm_expr.X_add_number != 1)
8526 as_warn (_("Invalid performance register (%lu)"),
8527 (unsigned long) imm_expr.X_add_number);
8528 INSERT_OPERAND (PERFREG, *ip, imm_expr.X_add_number);
8529 imm_expr.X_op = O_absent;
8533 case 'b': /* base register */
8534 case 'd': /* destination register */
8535 case 's': /* source register */
8536 case 't': /* target register */
8537 case 'r': /* both target and source */
8538 case 'v': /* both dest and source */
8539 case 'w': /* both dest and target */
8540 case 'E': /* coprocessor target register */
8541 case 'G': /* coprocessor destination register */
8542 case 'K': /* 'rdhwr' destination register */
8543 case 'x': /* ignore register name */
8544 case 'z': /* must be zero register */
8545 case 'U': /* destination register (clo/clz). */
8546 case 'g': /* coprocessor destination register */
8561 while (ISDIGIT (*s));
8563 as_bad (_("Invalid register number (%d)"), regno);
8565 else if (*args == 'E' || *args == 'G' || *args == 'K')
8569 if (s[1] == 'r' && s[2] == 'a')
8574 else if (s[1] == 'f' && s[2] == 'p')
8579 else if (s[1] == 's' && s[2] == 'p')
8584 else if (s[1] == 'g' && s[2] == 'p')
8589 else if (s[1] == 'a' && s[2] == 't')
8594 else if (s[1] == 'k' && s[2] == 't' && s[3] == '0')
8599 else if (s[1] == 'k' && s[2] == 't' && s[3] == '1')
8604 else if (s[1] == 'z' && s[2] == 'e' && s[3] == 'r' && s[4] == 'o')
8609 else if (itbl_have_entries)
8614 p = s + 1; /* advance past '$' */
8615 n = itbl_get_field (&p); /* n is name */
8617 /* See if this is a register defined in an
8619 if (itbl_get_reg_val (n, &r))
8621 /* Get_field advances to the start of
8622 the next field, so we need to back
8623 rack to the end of the last field. */
8627 s = strchr (s, '\0');
8641 as_warn (_("Used $at without \".set noat\""));
8647 if (c == 'r' || c == 'v' || c == 'w')
8654 /* 'z' only matches $0. */
8655 if (c == 'z' && regno != 0)
8658 /* Now that we have assembled one operand, we use the args string
8659 * to figure out where it goes in the instruction. */
8666 INSERT_OPERAND (RS, *ip, regno);
8672 INSERT_OPERAND (RD, *ip, regno);
8675 INSERT_OPERAND (RD, *ip, regno);
8676 INSERT_OPERAND (RT, *ip, regno);
8681 INSERT_OPERAND (RT, *ip, regno);
8684 /* This case exists because on the r3000 trunc
8685 expands into a macro which requires a gp
8686 register. On the r6000 or r4000 it is
8687 assembled into a single instruction which
8688 ignores the register. Thus the insn version
8689 is MIPS_ISA2 and uses 'x', and the macro
8690 version is MIPS_ISA1 and uses 't'. */
8693 /* This case is for the div instruction, which
8694 acts differently if the destination argument
8695 is $0. This only matches $0, and is checked
8696 outside the switch. */
8699 /* Itbl operand; not yet implemented. FIXME ?? */
8701 /* What about all other operands like 'i', which
8702 can be specified in the opcode table? */
8712 INSERT_OPERAND (RS, *ip, lastregno);
8715 INSERT_OPERAND (RT, *ip, lastregno);
8720 case 'O': /* MDMX alignment immediate constant. */
8721 my_getExpression (&imm_expr, s);
8722 check_absolute_expr (ip, &imm_expr);
8723 if ((unsigned long) imm_expr.X_add_number > OP_MASK_ALN)
8724 as_warn ("Improper align amount (%ld), using low bits",
8725 (long) imm_expr.X_add_number);
8726 INSERT_OPERAND (ALN, *ip, imm_expr.X_add_number);
8727 imm_expr.X_op = O_absent;
8731 case 'Q': /* MDMX vector, element sel, or const. */
8734 /* MDMX Immediate. */
8735 my_getExpression (&imm_expr, s);
8736 check_absolute_expr (ip, &imm_expr);
8737 if ((unsigned long) imm_expr.X_add_number > OP_MASK_FT)
8738 as_warn (_("Invalid MDMX Immediate (%ld)"),
8739 (long) imm_expr.X_add_number);
8740 INSERT_OPERAND (FT, *ip, imm_expr.X_add_number);
8741 if (ip->insn_opcode & (OP_MASK_VSEL << OP_SH_VSEL))
8742 ip->insn_opcode |= MDMX_FMTSEL_IMM_QH << OP_SH_VSEL;
8744 ip->insn_opcode |= MDMX_FMTSEL_IMM_OB << OP_SH_VSEL;
8745 imm_expr.X_op = O_absent;
8749 /* Not MDMX Immediate. Fall through. */
8750 case 'X': /* MDMX destination register. */
8751 case 'Y': /* MDMX source register. */
8752 case 'Z': /* MDMX target register. */
8754 case 'D': /* floating point destination register */
8755 case 'S': /* floating point source register */
8756 case 'T': /* floating point target register */
8757 case 'R': /* floating point source register */
8761 /* Accept $fN for FP and MDMX register numbers, and in
8762 addition accept $vN for MDMX register numbers. */
8763 if ((s[0] == '$' && s[1] == 'f' && ISDIGIT (s[2]))
8764 || (is_mdmx != 0 && s[0] == '$' && s[1] == 'v'
8775 while (ISDIGIT (*s));
8778 as_bad (_("Invalid float register number (%d)"), regno);
8780 if ((regno & 1) != 0
8782 && ! (strcmp (str, "mtc1") == 0
8783 || strcmp (str, "mfc1") == 0
8784 || strcmp (str, "lwc1") == 0
8785 || strcmp (str, "swc1") == 0
8786 || strcmp (str, "l.s") == 0
8787 || strcmp (str, "s.s") == 0
8788 || strcmp (str, "mftc1") == 0
8789 || strcmp (str, "mfthc1") == 0
8790 || strcmp (str, "cftc1") == 0
8791 || strcmp (str, "mttc1") == 0
8792 || strcmp (str, "mtthc1") == 0
8793 || strcmp (str, "cttc1") == 0))
8794 as_warn (_("Float register should be even, was %d"),
8802 if (c == 'V' || c == 'W')
8813 INSERT_OPERAND (FD, *ip, regno);
8818 INSERT_OPERAND (FS, *ip, regno);
8821 /* This is like 'Z', but also needs to fix the MDMX
8822 vector/scalar select bits. Note that the
8823 scalar immediate case is handled above. */
8826 int is_qh = (ip->insn_opcode & (1 << OP_SH_VSEL));
8827 int max_el = (is_qh ? 3 : 7);
8829 my_getExpression(&imm_expr, s);
8830 check_absolute_expr (ip, &imm_expr);
8832 if (imm_expr.X_add_number > max_el)
8833 as_bad(_("Bad element selector %ld"),
8834 (long) imm_expr.X_add_number);
8835 imm_expr.X_add_number &= max_el;
8836 ip->insn_opcode |= (imm_expr.X_add_number
8839 imm_expr.X_op = O_absent;
8841 as_warn(_("Expecting ']' found '%s'"), s);
8847 if (ip->insn_opcode & (OP_MASK_VSEL << OP_SH_VSEL))
8848 ip->insn_opcode |= (MDMX_FMTSEL_VEC_QH
8851 ip->insn_opcode |= (MDMX_FMTSEL_VEC_OB <<
8858 INSERT_OPERAND (FT, *ip, regno);
8861 INSERT_OPERAND (FR, *ip, regno);
8871 INSERT_OPERAND (FS, *ip, lastregno);
8874 INSERT_OPERAND (FT, *ip, lastregno);
8880 my_getExpression (&imm_expr, s);
8881 if (imm_expr.X_op != O_big
8882 && imm_expr.X_op != O_constant)
8883 insn_error = _("absolute expression required");
8884 if (HAVE_32BIT_GPRS)
8885 normalize_constant_expr (&imm_expr);
8890 my_getExpression (&offset_expr, s);
8891 normalize_address_expr (&offset_expr);
8892 *imm_reloc = BFD_RELOC_32;
8905 unsigned char temp[8];
8907 unsigned int length;
8912 /* These only appear as the last operand in an
8913 instruction, and every instruction that accepts
8914 them in any variant accepts them in all variants.
8915 This means we don't have to worry about backing out
8916 any changes if the instruction does not match.
8918 The difference between them is the size of the
8919 floating point constant and where it goes. For 'F'
8920 and 'L' the constant is 64 bits; for 'f' and 'l' it
8921 is 32 bits. Where the constant is placed is based
8922 on how the MIPS assembler does things:
8925 f -- immediate value
8928 The .lit4 and .lit8 sections are only used if
8929 permitted by the -G argument.
8931 The code below needs to know whether the target register
8932 is 32 or 64 bits wide. It relies on the fact 'f' and
8933 'F' are used with GPR-based instructions and 'l' and
8934 'L' are used with FPR-based instructions. */
8936 f64 = *args == 'F' || *args == 'L';
8937 using_gprs = *args == 'F' || *args == 'f';
8939 save_in = input_line_pointer;
8940 input_line_pointer = s;
8941 err = md_atof (f64 ? 'd' : 'f', (char *) temp, &len);
8943 s = input_line_pointer;
8944 input_line_pointer = save_in;
8945 if (err != NULL && *err != '\0')
8947 as_bad (_("Bad floating point constant: %s"), err);
8948 memset (temp, '\0', sizeof temp);
8949 length = f64 ? 8 : 4;
8952 assert (length == (unsigned) (f64 ? 8 : 4));
8956 && (g_switch_value < 4
8957 || (temp[0] == 0 && temp[1] == 0)
8958 || (temp[2] == 0 && temp[3] == 0))))
8960 imm_expr.X_op = O_constant;
8961 if (! target_big_endian)
8962 imm_expr.X_add_number = bfd_getl32 (temp);
8964 imm_expr.X_add_number = bfd_getb32 (temp);
8967 && ! mips_disable_float_construction
8968 /* Constants can only be constructed in GPRs and
8969 copied to FPRs if the GPRs are at least as wide
8970 as the FPRs. Force the constant into memory if
8971 we are using 64-bit FPRs but the GPRs are only
8974 || ! (HAVE_64BIT_FPRS && HAVE_32BIT_GPRS))
8975 && ((temp[0] == 0 && temp[1] == 0)
8976 || (temp[2] == 0 && temp[3] == 0))
8977 && ((temp[4] == 0 && temp[5] == 0)
8978 || (temp[6] == 0 && temp[7] == 0)))
8980 /* The value is simple enough to load with a couple of
8981 instructions. If using 32-bit registers, set
8982 imm_expr to the high order 32 bits and offset_expr to
8983 the low order 32 bits. Otherwise, set imm_expr to
8984 the entire 64 bit constant. */
8985 if (using_gprs ? HAVE_32BIT_GPRS : HAVE_32BIT_FPRS)
8987 imm_expr.X_op = O_constant;
8988 offset_expr.X_op = O_constant;
8989 if (! target_big_endian)
8991 imm_expr.X_add_number = bfd_getl32 (temp + 4);
8992 offset_expr.X_add_number = bfd_getl32 (temp);
8996 imm_expr.X_add_number = bfd_getb32 (temp);
8997 offset_expr.X_add_number = bfd_getb32 (temp + 4);
8999 if (offset_expr.X_add_number == 0)
9000 offset_expr.X_op = O_absent;
9002 else if (sizeof (imm_expr.X_add_number) > 4)
9004 imm_expr.X_op = O_constant;
9005 if (! target_big_endian)
9006 imm_expr.X_add_number = bfd_getl64 (temp);
9008 imm_expr.X_add_number = bfd_getb64 (temp);
9012 imm_expr.X_op = O_big;
9013 imm_expr.X_add_number = 4;
9014 if (! target_big_endian)
9016 generic_bignum[0] = bfd_getl16 (temp);
9017 generic_bignum[1] = bfd_getl16 (temp + 2);
9018 generic_bignum[2] = bfd_getl16 (temp + 4);
9019 generic_bignum[3] = bfd_getl16 (temp + 6);
9023 generic_bignum[0] = bfd_getb16 (temp + 6);
9024 generic_bignum[1] = bfd_getb16 (temp + 4);
9025 generic_bignum[2] = bfd_getb16 (temp + 2);
9026 generic_bignum[3] = bfd_getb16 (temp);
9032 const char *newname;
9035 /* Switch to the right section. */
9037 subseg = now_subseg;
9040 default: /* unused default case avoids warnings. */
9042 newname = RDATA_SECTION_NAME;
9043 if (g_switch_value >= 8)
9047 newname = RDATA_SECTION_NAME;
9050 assert (g_switch_value >= 4);
9054 new_seg = subseg_new (newname, (subsegT) 0);
9055 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
9056 bfd_set_section_flags (stdoutput, new_seg,
9061 frag_align (*args == 'l' ? 2 : 3, 0, 0);
9062 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
9063 && strcmp (TARGET_OS, "elf") != 0)
9064 record_alignment (new_seg, 4);
9066 record_alignment (new_seg, *args == 'l' ? 2 : 3);
9068 as_bad (_("Can't use floating point insn in this section"));
9070 /* Set the argument to the current address in the
9072 offset_expr.X_op = O_symbol;
9073 offset_expr.X_add_symbol =
9074 symbol_new ("L0\001", now_seg,
9075 (valueT) frag_now_fix (), frag_now);
9076 offset_expr.X_add_number = 0;
9078 /* Put the floating point number into the section. */
9079 p = frag_more ((int) length);
9080 memcpy (p, temp, length);
9082 /* Switch back to the original section. */
9083 subseg_set (seg, subseg);
9088 case 'i': /* 16 bit unsigned immediate */
9089 case 'j': /* 16 bit signed immediate */
9090 *imm_reloc = BFD_RELOC_LO16;
9091 if (my_getSmallExpression (&imm_expr, imm_reloc, s) == 0)
9094 offsetT minval, maxval;
9096 more = (insn + 1 < &mips_opcodes[NUMOPCODES]
9097 && strcmp (insn->name, insn[1].name) == 0);
9099 /* If the expression was written as an unsigned number,
9100 only treat it as signed if there are no more
9104 && sizeof (imm_expr.X_add_number) <= 4
9105 && imm_expr.X_op == O_constant
9106 && imm_expr.X_add_number < 0
9107 && imm_expr.X_unsigned
9111 /* For compatibility with older assemblers, we accept
9112 0x8000-0xffff as signed 16-bit numbers when only
9113 signed numbers are allowed. */
9115 minval = 0, maxval = 0xffff;
9117 minval = -0x8000, maxval = 0x7fff;
9119 minval = -0x8000, maxval = 0xffff;
9121 if (imm_expr.X_op != O_constant
9122 || imm_expr.X_add_number < minval
9123 || imm_expr.X_add_number > maxval)
9127 if (imm_expr.X_op == O_constant
9128 || imm_expr.X_op == O_big)
9129 as_bad (_("expression out of range"));
9135 case 'o': /* 16 bit offset */
9136 /* Check whether there is only a single bracketed expression
9137 left. If so, it must be the base register and the
9138 constant must be zero. */
9139 if (*s == '(' && strchr (s + 1, '(') == 0)
9141 offset_expr.X_op = O_constant;
9142 offset_expr.X_add_number = 0;
9146 /* If this value won't fit into a 16 bit offset, then go
9147 find a macro that will generate the 32 bit offset
9149 if (my_getSmallExpression (&offset_expr, offset_reloc, s) == 0
9150 && (offset_expr.X_op != O_constant
9151 || offset_expr.X_add_number >= 0x8000
9152 || offset_expr.X_add_number < -0x8000))
9158 case 'p': /* pc relative offset */
9159 *offset_reloc = BFD_RELOC_16_PCREL_S2;
9160 my_getExpression (&offset_expr, s);
9164 case 'u': /* upper 16 bits */
9165 if (my_getSmallExpression (&imm_expr, imm_reloc, s) == 0
9166 && imm_expr.X_op == O_constant
9167 && (imm_expr.X_add_number < 0
9168 || imm_expr.X_add_number >= 0x10000))
9169 as_bad (_("lui expression not in range 0..65535"));
9173 case 'a': /* 26 bit address */
9174 my_getExpression (&offset_expr, s);
9176 *offset_reloc = BFD_RELOC_MIPS_JMP;
9179 case 'N': /* 3 bit branch condition code */
9180 case 'M': /* 3 bit compare condition code */
9181 if (strncmp (s, "$fcc", 4) != 0)
9191 while (ISDIGIT (*s));
9193 as_bad (_("Invalid condition code register $fcc%d"), regno);
9194 if ((strcmp(str + strlen(str) - 3, ".ps") == 0
9195 || strcmp(str + strlen(str) - 5, "any2f") == 0
9196 || strcmp(str + strlen(str) - 5, "any2t") == 0)
9197 && (regno & 1) != 0)
9198 as_warn(_("Condition code register should be even for %s, was %d"),
9200 if ((strcmp(str + strlen(str) - 5, "any4f") == 0
9201 || strcmp(str + strlen(str) - 5, "any4t") == 0)
9202 && (regno & 3) != 0)
9203 as_warn(_("Condition code register should be 0 or 4 for %s, was %d"),
9206 INSERT_OPERAND (BCC, *ip, regno);
9208 INSERT_OPERAND (CCC, *ip, regno);
9212 if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X'))
9223 while (ISDIGIT (*s));
9226 c = 8; /* Invalid sel value. */
9229 as_bad (_("invalid coprocessor sub-selection value (0-7)"));
9230 ip->insn_opcode |= c;
9234 /* Must be at least one digit. */
9235 my_getExpression (&imm_expr, s);
9236 check_absolute_expr (ip, &imm_expr);
9238 if ((unsigned long) imm_expr.X_add_number
9239 > (unsigned long) OP_MASK_VECBYTE)
9241 as_bad (_("bad byte vector index (%ld)"),
9242 (long) imm_expr.X_add_number);
9243 imm_expr.X_add_number = 0;
9246 INSERT_OPERAND (VECBYTE, *ip, imm_expr.X_add_number);
9247 imm_expr.X_op = O_absent;
9252 my_getExpression (&imm_expr, s);
9253 check_absolute_expr (ip, &imm_expr);
9255 if ((unsigned long) imm_expr.X_add_number
9256 > (unsigned long) OP_MASK_VECALIGN)
9258 as_bad (_("bad byte vector index (%ld)"),
9259 (long) imm_expr.X_add_number);
9260 imm_expr.X_add_number = 0;
9263 INSERT_OPERAND (VECALIGN, *ip, imm_expr.X_add_number);
9264 imm_expr.X_op = O_absent;
9269 as_bad (_("bad char = '%c'\n"), *args);
9274 /* Args don't match. */
9275 if (insn + 1 < &mips_opcodes[NUMOPCODES] &&
9276 !strcmp (insn->name, insn[1].name))
9280 insn_error = _("illegal operands");
9285 insn_error = _("illegal operands");
9290 /* This routine assembles an instruction into its binary format when
9291 assembling for the mips16. As a side effect, it sets one of the
9292 global variables imm_reloc or offset_reloc to the type of
9293 relocation to do if one of the operands is an address expression.
9294 It also sets mips16_small and mips16_ext if the user explicitly
9295 requested a small or extended instruction. */
9298 mips16_ip (char *str, struct mips_cl_insn *ip)
9302 struct mips_opcode *insn;
9305 unsigned int lastregno = 0;
9311 mips16_small = FALSE;
9314 for (s = str; ISLOWER (*s); ++s)
9326 if (s[1] == 't' && s[2] == ' ')
9329 mips16_small = TRUE;
9333 else if (s[1] == 'e' && s[2] == ' ')
9342 insn_error = _("unknown opcode");
9346 if (mips_opts.noautoextend && ! mips16_ext)
9347 mips16_small = TRUE;
9349 if ((insn = (struct mips_opcode *) hash_find (mips16_op_hash, str)) == NULL)
9351 insn_error = _("unrecognized opcode");
9358 assert (strcmp (insn->name, str) == 0);
9360 create_insn (ip, insn);
9361 imm_expr.X_op = O_absent;
9362 imm_reloc[0] = BFD_RELOC_UNUSED;
9363 imm_reloc[1] = BFD_RELOC_UNUSED;
9364 imm_reloc[2] = BFD_RELOC_UNUSED;
9365 imm2_expr.X_op = O_absent;
9366 offset_expr.X_op = O_absent;
9367 offset_reloc[0] = BFD_RELOC_UNUSED;
9368 offset_reloc[1] = BFD_RELOC_UNUSED;
9369 offset_reloc[2] = BFD_RELOC_UNUSED;
9370 for (args = insn->args; 1; ++args)
9377 /* In this switch statement we call break if we did not find
9378 a match, continue if we did find a match, or return if we
9387 /* Stuff the immediate value in now, if we can. */
9388 if (imm_expr.X_op == O_constant
9389 && *imm_reloc > BFD_RELOC_UNUSED
9390 && insn->pinfo != INSN_MACRO)
9394 switch (*offset_reloc)
9396 case BFD_RELOC_MIPS16_HI16_S:
9397 tmp = (imm_expr.X_add_number + 0x8000) >> 16;
9400 case BFD_RELOC_MIPS16_HI16:
9401 tmp = imm_expr.X_add_number >> 16;
9404 case BFD_RELOC_MIPS16_LO16:
9405 tmp = ((imm_expr.X_add_number + 0x8000) & 0xffff)
9409 case BFD_RELOC_UNUSED:
9410 tmp = imm_expr.X_add_number;
9416 *offset_reloc = BFD_RELOC_UNUSED;
9418 mips16_immed (NULL, 0, *imm_reloc - BFD_RELOC_UNUSED,
9419 tmp, TRUE, mips16_small,
9420 mips16_ext, &ip->insn_opcode,
9421 &ip->use_extend, &ip->extend);
9422 imm_expr.X_op = O_absent;
9423 *imm_reloc = BFD_RELOC_UNUSED;
9437 MIPS16_INSERT_OPERAND (RX, *ip, lastregno);
9440 MIPS16_INSERT_OPERAND (RY, *ip, lastregno);
9456 MIPS16_INSERT_OPERAND (RX, *ip, lastregno);
9458 MIPS16_INSERT_OPERAND (RY, *ip, lastregno);
9485 while (ISDIGIT (*s));
9488 as_bad (_("invalid register number (%d)"), regno);
9494 if (s[1] == 'r' && s[2] == 'a')
9499 else if (s[1] == 'f' && s[2] == 'p')
9504 else if (s[1] == 's' && s[2] == 'p')
9509 else if (s[1] == 'g' && s[2] == 'p')
9514 else if (s[1] == 'a' && s[2] == 't')
9519 else if (s[1] == 'k' && s[2] == 't' && s[3] == '0')
9524 else if (s[1] == 'k' && s[2] == 't' && s[3] == '1')
9529 else if (s[1] == 'z' && s[2] == 'e' && s[3] == 'r' && s[4] == 'o')
9542 if (c == 'v' || c == 'w')
9544 regno = mips16_to_32_reg_map[lastregno];
9558 regno = mips32_to_16_reg_map[regno];
9563 regno = ILLEGAL_REG;
9568 regno = ILLEGAL_REG;
9573 regno = ILLEGAL_REG;
9578 if (regno == AT && ! mips_opts.noat)
9579 as_warn (_("used $at without \".set noat\""));
9586 if (regno == ILLEGAL_REG)
9593 MIPS16_INSERT_OPERAND (RX, *ip, regno);
9597 MIPS16_INSERT_OPERAND (RY, *ip, regno);
9600 MIPS16_INSERT_OPERAND (RZ, *ip, regno);
9603 MIPS16_INSERT_OPERAND (MOVE32Z, *ip, regno);
9609 MIPS16_INSERT_OPERAND (REGR32, *ip, regno);
9612 regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3);
9613 MIPS16_INSERT_OPERAND (REG32R, *ip, regno);
9623 if (strncmp (s, "$pc", 3) == 0)
9640 i = my_getSmallExpression (&imm_expr, imm_reloc, s);
9643 if (imm_expr.X_op != O_constant)
9646 ip->use_extend = TRUE;
9651 /* We need to relax this instruction. */
9652 *offset_reloc = *imm_reloc;
9653 *imm_reloc = (int) BFD_RELOC_UNUSED + c;
9658 *imm_reloc = BFD_RELOC_UNUSED;
9666 my_getExpression (&imm_expr, s);
9667 if (imm_expr.X_op == O_register)
9669 /* What we thought was an expression turned out to
9672 if (s[0] == '(' && args[1] == '(')
9674 /* It looks like the expression was omitted
9675 before a register indirection, which means
9676 that the expression is implicitly zero. We
9677 still set up imm_expr, so that we handle
9678 explicit extensions correctly. */
9679 imm_expr.X_op = O_constant;
9680 imm_expr.X_add_number = 0;
9681 *imm_reloc = (int) BFD_RELOC_UNUSED + c;
9688 /* We need to relax this instruction. */
9689 *imm_reloc = (int) BFD_RELOC_UNUSED + c;
9698 /* We use offset_reloc rather than imm_reloc for the PC
9699 relative operands. This lets macros with both
9700 immediate and address operands work correctly. */
9701 my_getExpression (&offset_expr, s);
9703 if (offset_expr.X_op == O_register)
9706 /* We need to relax this instruction. */
9707 *offset_reloc = (int) BFD_RELOC_UNUSED + c;
9711 case '6': /* break code */
9712 my_getExpression (&imm_expr, s);
9713 check_absolute_expr (ip, &imm_expr);
9714 if ((unsigned long) imm_expr.X_add_number > 63)
9715 as_warn (_("Invalid value for `%s' (%lu)"),
9717 (unsigned long) imm_expr.X_add_number);
9718 MIPS16_INSERT_OPERAND (IMM6, *ip, imm_expr.X_add_number);
9719 imm_expr.X_op = O_absent;
9723 case 'a': /* 26 bit address */
9724 my_getExpression (&offset_expr, s);
9726 *offset_reloc = BFD_RELOC_MIPS16_JMP;
9727 ip->insn_opcode <<= 16;
9730 case 'l': /* register list for entry macro */
9731 case 'L': /* register list for exit macro */
9741 int freg, reg1, reg2;
9743 while (*s == ' ' || *s == ',')
9747 as_bad (_("can't parse register list"));
9759 while (ISDIGIT (*s))
9781 as_bad (_("invalid register list"));
9786 while (ISDIGIT (*s))
9793 if (freg && reg1 == 0 && reg2 == 0 && c == 'L')
9798 else if (freg && reg1 == 0 && reg2 == 1 && c == 'L')
9803 else if (reg1 == 4 && reg2 >= 4 && reg2 <= 7 && c != 'L')
9804 mask |= (reg2 - 3) << 3;
9805 else if (reg1 == 16 && reg2 >= 16 && reg2 <= 17)
9806 mask |= (reg2 - 15) << 1;
9807 else if (reg1 == RA && reg2 == RA)
9811 as_bad (_("invalid register list"));
9815 /* The mask is filled in in the opcode table for the
9816 benefit of the disassembler. We remove it before
9817 applying the actual mask. */
9818 ip->insn_opcode &= ~ ((7 << 3) << MIPS16OP_SH_IMM6);
9819 ip->insn_opcode |= mask << MIPS16OP_SH_IMM6;
9823 case 'e': /* extend code */
9824 my_getExpression (&imm_expr, s);
9825 check_absolute_expr (ip, &imm_expr);
9826 if ((unsigned long) imm_expr.X_add_number > 0x7ff)
9828 as_warn (_("Invalid value for `%s' (%lu)"),
9830 (unsigned long) imm_expr.X_add_number);
9831 imm_expr.X_add_number &= 0x7ff;
9833 ip->insn_opcode |= imm_expr.X_add_number;
9834 imm_expr.X_op = O_absent;
9844 /* Args don't match. */
9845 if (insn + 1 < &mips16_opcodes[bfd_mips16_num_opcodes] &&
9846 strcmp (insn->name, insn[1].name) == 0)
9853 insn_error = _("illegal operands");
9859 /* This structure holds information we know about a mips16 immediate
9862 struct mips16_immed_operand
9864 /* The type code used in the argument string in the opcode table. */
9866 /* The number of bits in the short form of the opcode. */
9868 /* The number of bits in the extended form of the opcode. */
9870 /* The amount by which the short form is shifted when it is used;
9871 for example, the sw instruction has a shift count of 2. */
9873 /* The amount by which the short form is shifted when it is stored
9874 into the instruction code. */
9876 /* Non-zero if the short form is unsigned. */
9878 /* Non-zero if the extended form is unsigned. */
9880 /* Non-zero if the value is PC relative. */
9884 /* The mips16 immediate operand types. */
9886 static const struct mips16_immed_operand mips16_immed_operands[] =
9888 { '<', 3, 5, 0, MIPS16OP_SH_RZ, 1, 1, 0 },
9889 { '>', 3, 5, 0, MIPS16OP_SH_RX, 1, 1, 0 },
9890 { '[', 3, 6, 0, MIPS16OP_SH_RZ, 1, 1, 0 },
9891 { ']', 3, 6, 0, MIPS16OP_SH_RX, 1, 1, 0 },
9892 { '4', 4, 15, 0, MIPS16OP_SH_IMM4, 0, 0, 0 },
9893 { '5', 5, 16, 0, MIPS16OP_SH_IMM5, 1, 0, 0 },
9894 { 'H', 5, 16, 1, MIPS16OP_SH_IMM5, 1, 0, 0 },
9895 { 'W', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 0 },
9896 { 'D', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 0 },
9897 { 'j', 5, 16, 0, MIPS16OP_SH_IMM5, 0, 0, 0 },
9898 { '8', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 0, 0 },
9899 { 'V', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 0 },
9900 { 'C', 8, 16, 3, MIPS16OP_SH_IMM8, 1, 0, 0 },
9901 { 'U', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 1, 0 },
9902 { 'k', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 0 },
9903 { 'K', 8, 16, 3, MIPS16OP_SH_IMM8, 0, 0, 0 },
9904 { 'p', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 },
9905 { 'q', 11, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 },
9906 { 'A', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 1 },
9907 { 'B', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 1 },
9908 { 'E', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 1 }
9911 #define MIPS16_NUM_IMMED \
9912 (sizeof mips16_immed_operands / sizeof mips16_immed_operands[0])
9914 /* Handle a mips16 instruction with an immediate value. This or's the
9915 small immediate value into *INSN. It sets *USE_EXTEND to indicate
9916 whether an extended value is needed; if one is needed, it sets
9917 *EXTEND to the value. The argument type is TYPE. The value is VAL.
9918 If SMALL is true, an unextended opcode was explicitly requested.
9919 If EXT is true, an extended opcode was explicitly requested. If
9920 WARN is true, warn if EXT does not match reality. */
9923 mips16_immed (char *file, unsigned int line, int type, offsetT val,
9924 bfd_boolean warn, bfd_boolean small, bfd_boolean ext,
9925 unsigned long *insn, bfd_boolean *use_extend,
9926 unsigned short *extend)
9928 register const struct mips16_immed_operand *op;
9929 int mintiny, maxtiny;
9930 bfd_boolean needext;
9932 op = mips16_immed_operands;
9933 while (op->type != type)
9936 assert (op < mips16_immed_operands + MIPS16_NUM_IMMED);
9941 if (type == '<' || type == '>' || type == '[' || type == ']')
9944 maxtiny = 1 << op->nbits;
9949 maxtiny = (1 << op->nbits) - 1;
9954 mintiny = - (1 << (op->nbits - 1));
9955 maxtiny = (1 << (op->nbits - 1)) - 1;
9958 /* Branch offsets have an implicit 0 in the lowest bit. */
9959 if (type == 'p' || type == 'q')
9962 if ((val & ((1 << op->shift) - 1)) != 0
9963 || val < (mintiny << op->shift)
9964 || val > (maxtiny << op->shift))
9969 if (warn && ext && ! needext)
9970 as_warn_where (file, line,
9971 _("extended operand requested but not required"));
9972 if (small && needext)
9973 as_bad_where (file, line, _("invalid unextended operand value"));
9975 if (small || (! ext && ! needext))
9979 *use_extend = FALSE;
9980 insnval = ((val >> op->shift) & ((1 << op->nbits) - 1));
9981 insnval <<= op->op_shift;
9986 long minext, maxext;
9992 maxext = (1 << op->extbits) - 1;
9996 minext = - (1 << (op->extbits - 1));
9997 maxext = (1 << (op->extbits - 1)) - 1;
9999 if (val < minext || val > maxext)
10000 as_bad_where (file, line,
10001 _("operand value out of range for instruction"));
10003 *use_extend = TRUE;
10004 if (op->extbits == 16)
10006 extval = ((val >> 11) & 0x1f) | (val & 0x7e0);
10009 else if (op->extbits == 15)
10011 extval = ((val >> 11) & 0xf) | (val & 0x7f0);
10016 extval = ((val & 0x1f) << 6) | (val & 0x20);
10020 *extend = (unsigned short) extval;
10025 struct percent_op_match
10028 bfd_reloc_code_real_type reloc;
10031 static const struct percent_op_match mips_percent_op[] =
10033 {"%lo", BFD_RELOC_LO16},
10035 {"%call_hi", BFD_RELOC_MIPS_CALL_HI16},
10036 {"%call_lo", BFD_RELOC_MIPS_CALL_LO16},
10037 {"%call16", BFD_RELOC_MIPS_CALL16},
10038 {"%got_disp", BFD_RELOC_MIPS_GOT_DISP},
10039 {"%got_page", BFD_RELOC_MIPS_GOT_PAGE},
10040 {"%got_ofst", BFD_RELOC_MIPS_GOT_OFST},
10041 {"%got_hi", BFD_RELOC_MIPS_GOT_HI16},
10042 {"%got_lo", BFD_RELOC_MIPS_GOT_LO16},
10043 {"%got", BFD_RELOC_MIPS_GOT16},
10044 {"%gp_rel", BFD_RELOC_GPREL16},
10045 {"%half", BFD_RELOC_16},
10046 {"%highest", BFD_RELOC_MIPS_HIGHEST},
10047 {"%higher", BFD_RELOC_MIPS_HIGHER},
10048 {"%neg", BFD_RELOC_MIPS_SUB},
10049 {"%tlsgd", BFD_RELOC_MIPS_TLS_GD},
10050 {"%tlsldm", BFD_RELOC_MIPS_TLS_LDM},
10051 {"%dtprel_hi", BFD_RELOC_MIPS_TLS_DTPREL_HI16},
10052 {"%dtprel_lo", BFD_RELOC_MIPS_TLS_DTPREL_LO16},
10053 {"%tprel_hi", BFD_RELOC_MIPS_TLS_TPREL_HI16},
10054 {"%tprel_lo", BFD_RELOC_MIPS_TLS_TPREL_LO16},
10055 {"%gottprel", BFD_RELOC_MIPS_TLS_GOTTPREL},
10057 {"%hi", BFD_RELOC_HI16_S}
10060 static const struct percent_op_match mips16_percent_op[] =
10062 {"%lo", BFD_RELOC_MIPS16_LO16},
10063 {"%gprel", BFD_RELOC_MIPS16_GPREL},
10064 {"%hi", BFD_RELOC_MIPS16_HI16_S}
10068 /* Return true if *STR points to a relocation operator. When returning true,
10069 move *STR over the operator and store its relocation code in *RELOC.
10070 Leave both *STR and *RELOC alone when returning false. */
10073 parse_relocation (char **str, bfd_reloc_code_real_type *reloc)
10075 const struct percent_op_match *percent_op;
10078 if (mips_opts.mips16)
10080 percent_op = mips16_percent_op;
10081 limit = ARRAY_SIZE (mips16_percent_op);
10085 percent_op = mips_percent_op;
10086 limit = ARRAY_SIZE (mips_percent_op);
10089 for (i = 0; i < limit; i++)
10090 if (strncasecmp (*str, percent_op[i].str, strlen (percent_op[i].str)) == 0)
10092 int len = strlen (percent_op[i].str);
10094 if (!ISSPACE ((*str)[len]) && (*str)[len] != '(')
10097 *str += strlen (percent_op[i].str);
10098 *reloc = percent_op[i].reloc;
10100 /* Check whether the output BFD supports this relocation.
10101 If not, issue an error and fall back on something safe. */
10102 if (!bfd_reloc_type_lookup (stdoutput, percent_op[i].reloc))
10104 as_bad ("relocation %s isn't supported by the current ABI",
10105 percent_op[i].str);
10106 *reloc = BFD_RELOC_UNUSED;
10114 /* Parse string STR as a 16-bit relocatable operand. Store the
10115 expression in *EP and the relocations in the array starting
10116 at RELOC. Return the number of relocation operators used.
10118 On exit, EXPR_END points to the first character after the expression. */
10121 my_getSmallExpression (expressionS *ep, bfd_reloc_code_real_type *reloc,
10124 bfd_reloc_code_real_type reversed_reloc[3];
10125 size_t reloc_index, i;
10126 int crux_depth, str_depth;
10129 /* Search for the start of the main expression, recoding relocations
10130 in REVERSED_RELOC. End the loop with CRUX pointing to the start
10131 of the main expression and with CRUX_DEPTH containing the number
10132 of open brackets at that point. */
10139 crux_depth = str_depth;
10141 /* Skip over whitespace and brackets, keeping count of the number
10143 while (*str == ' ' || *str == '\t' || *str == '(')
10148 && reloc_index < (HAVE_NEWABI ? 3 : 1)
10149 && parse_relocation (&str, &reversed_reloc[reloc_index]));
10151 my_getExpression (ep, crux);
10154 /* Match every open bracket. */
10155 while (crux_depth > 0 && (*str == ')' || *str == ' ' || *str == '\t'))
10159 if (crux_depth > 0)
10160 as_bad ("unclosed '('");
10164 if (reloc_index != 0)
10166 prev_reloc_op_frag = frag_now;
10167 for (i = 0; i < reloc_index; i++)
10168 reloc[i] = reversed_reloc[reloc_index - 1 - i];
10171 return reloc_index;
10175 my_getExpression (expressionS *ep, char *str)
10180 save_in = input_line_pointer;
10181 input_line_pointer = str;
10183 expr_end = input_line_pointer;
10184 input_line_pointer = save_in;
10186 /* If we are in mips16 mode, and this is an expression based on `.',
10187 then we bump the value of the symbol by 1 since that is how other
10188 text symbols are handled. We don't bother to handle complex
10189 expressions, just `.' plus or minus a constant. */
10190 if (mips_opts.mips16
10191 && ep->X_op == O_symbol
10192 && strcmp (S_GET_NAME (ep->X_add_symbol), FAKE_LABEL_NAME) == 0
10193 && S_GET_SEGMENT (ep->X_add_symbol) == now_seg
10194 && symbol_get_frag (ep->X_add_symbol) == frag_now
10195 && symbol_constant_p (ep->X_add_symbol)
10196 && (val = S_GET_VALUE (ep->X_add_symbol)) == frag_now_fix ())
10197 S_SET_VALUE (ep->X_add_symbol, val + 1);
10200 /* Turn a string in input_line_pointer into a floating point constant
10201 of type TYPE, and store the appropriate bytes in *LITP. The number
10202 of LITTLENUMS emitted is stored in *SIZEP. An error message is
10203 returned, or NULL on OK. */
10206 md_atof (int type, char *litP, int *sizeP)
10209 LITTLENUM_TYPE words[4];
10225 return _("bad call to md_atof");
10228 t = atof_ieee (input_line_pointer, type, words);
10230 input_line_pointer = t;
10234 if (! target_big_endian)
10236 for (i = prec - 1; i >= 0; i--)
10238 md_number_to_chars (litP, words[i], 2);
10244 for (i = 0; i < prec; i++)
10246 md_number_to_chars (litP, words[i], 2);
10255 md_number_to_chars (char *buf, valueT val, int n)
10257 if (target_big_endian)
10258 number_to_chars_bigendian (buf, val, n);
10260 number_to_chars_littleendian (buf, val, n);
10264 static int support_64bit_objects(void)
10266 const char **list, **l;
10269 list = bfd_target_list ();
10270 for (l = list; *l != NULL; l++)
10272 /* This is traditional mips */
10273 if (strcmp (*l, "elf64-tradbigmips") == 0
10274 || strcmp (*l, "elf64-tradlittlemips") == 0)
10276 if (strcmp (*l, "elf64-bigmips") == 0
10277 || strcmp (*l, "elf64-littlemips") == 0)
10280 yes = (*l != NULL);
10284 #endif /* OBJ_ELF */
10286 const char *md_shortopts = "O::g::G:";
10288 struct option md_longopts[] =
10290 /* Options which specify architecture. */
10291 #define OPTION_ARCH_BASE (OPTION_MD_BASE)
10292 #define OPTION_MARCH (OPTION_ARCH_BASE + 0)
10293 {"march", required_argument, NULL, OPTION_MARCH},
10294 #define OPTION_MTUNE (OPTION_ARCH_BASE + 1)
10295 {"mtune", required_argument, NULL, OPTION_MTUNE},
10296 #define OPTION_MIPS1 (OPTION_ARCH_BASE + 2)
10297 {"mips0", no_argument, NULL, OPTION_MIPS1},
10298 {"mips1", no_argument, NULL, OPTION_MIPS1},
10299 #define OPTION_MIPS2 (OPTION_ARCH_BASE + 3)
10300 {"mips2", no_argument, NULL, OPTION_MIPS2},
10301 #define OPTION_MIPS3 (OPTION_ARCH_BASE + 4)
10302 {"mips3", no_argument, NULL, OPTION_MIPS3},
10303 #define OPTION_MIPS4 (OPTION_ARCH_BASE + 5)
10304 {"mips4", no_argument, NULL, OPTION_MIPS4},
10305 #define OPTION_MIPS5 (OPTION_ARCH_BASE + 6)
10306 {"mips5", no_argument, NULL, OPTION_MIPS5},
10307 #define OPTION_MIPS32 (OPTION_ARCH_BASE + 7)
10308 {"mips32", no_argument, NULL, OPTION_MIPS32},
10309 #define OPTION_MIPS64 (OPTION_ARCH_BASE + 8)
10310 {"mips64", no_argument, NULL, OPTION_MIPS64},
10311 #define OPTION_MIPS32R2 (OPTION_ARCH_BASE + 9)
10312 {"mips32r2", no_argument, NULL, OPTION_MIPS32R2},
10313 #define OPTION_MIPS64R2 (OPTION_ARCH_BASE + 10)
10314 {"mips64r2", no_argument, NULL, OPTION_MIPS64R2},
10316 /* Options which specify Application Specific Extensions (ASEs). */
10317 #define OPTION_ASE_BASE (OPTION_ARCH_BASE + 11)
10318 #define OPTION_MIPS16 (OPTION_ASE_BASE + 0)
10319 {"mips16", no_argument, NULL, OPTION_MIPS16},
10320 #define OPTION_NO_MIPS16 (OPTION_ASE_BASE + 1)
10321 {"no-mips16", no_argument, NULL, OPTION_NO_MIPS16},
10322 #define OPTION_MIPS3D (OPTION_ASE_BASE + 2)
10323 {"mips3d", no_argument, NULL, OPTION_MIPS3D},
10324 #define OPTION_NO_MIPS3D (OPTION_ASE_BASE + 3)
10325 {"no-mips3d", no_argument, NULL, OPTION_NO_MIPS3D},
10326 #define OPTION_MDMX (OPTION_ASE_BASE + 4)
10327 {"mdmx", no_argument, NULL, OPTION_MDMX},
10328 #define OPTION_NO_MDMX (OPTION_ASE_BASE + 5)
10329 {"no-mdmx", no_argument, NULL, OPTION_NO_MDMX},
10330 #define OPTION_DSP (OPTION_ASE_BASE + 6)
10331 {"mdsp", no_argument, NULL, OPTION_DSP},
10332 #define OPTION_NO_DSP (OPTION_ASE_BASE + 7)
10333 {"mno-dsp", no_argument, NULL, OPTION_NO_DSP},
10334 #define OPTION_MT (OPTION_ASE_BASE + 8)
10335 {"mmt", no_argument, NULL, OPTION_MT},
10336 #define OPTION_NO_MT (OPTION_ASE_BASE + 9)
10337 {"mno-mt", no_argument, NULL, OPTION_NO_MT},
10339 /* Old-style architecture options. Don't add more of these. */
10340 #define OPTION_COMPAT_ARCH_BASE (OPTION_ASE_BASE + 10)
10341 #define OPTION_M4650 (OPTION_COMPAT_ARCH_BASE + 0)
10342 {"m4650", no_argument, NULL, OPTION_M4650},
10343 #define OPTION_NO_M4650 (OPTION_COMPAT_ARCH_BASE + 1)
10344 {"no-m4650", no_argument, NULL, OPTION_NO_M4650},
10345 #define OPTION_M4010 (OPTION_COMPAT_ARCH_BASE + 2)
10346 {"m4010", no_argument, NULL, OPTION_M4010},
10347 #define OPTION_NO_M4010 (OPTION_COMPAT_ARCH_BASE + 3)
10348 {"no-m4010", no_argument, NULL, OPTION_NO_M4010},
10349 #define OPTION_M4100 (OPTION_COMPAT_ARCH_BASE + 4)
10350 {"m4100", no_argument, NULL, OPTION_M4100},
10351 #define OPTION_NO_M4100 (OPTION_COMPAT_ARCH_BASE + 5)
10352 {"no-m4100", no_argument, NULL, OPTION_NO_M4100},
10353 #define OPTION_M3900 (OPTION_COMPAT_ARCH_BASE + 6)
10354 {"m3900", no_argument, NULL, OPTION_M3900},
10355 #define OPTION_NO_M3900 (OPTION_COMPAT_ARCH_BASE + 7)
10356 {"no-m3900", no_argument, NULL, OPTION_NO_M3900},
10358 /* Options which enable bug fixes. */
10359 #define OPTION_FIX_BASE (OPTION_COMPAT_ARCH_BASE + 8)
10360 #define OPTION_M7000_HILO_FIX (OPTION_FIX_BASE + 0)
10361 {"mfix7000", no_argument, NULL, OPTION_M7000_HILO_FIX},
10362 #define OPTION_MNO_7000_HILO_FIX (OPTION_FIX_BASE + 1)
10363 {"no-fix-7000", no_argument, NULL, OPTION_MNO_7000_HILO_FIX},
10364 {"mno-fix7000", no_argument, NULL, OPTION_MNO_7000_HILO_FIX},
10365 #define OPTION_FIX_VR4120 (OPTION_FIX_BASE + 2)
10366 #define OPTION_NO_FIX_VR4120 (OPTION_FIX_BASE + 3)
10367 {"mfix-vr4120", no_argument, NULL, OPTION_FIX_VR4120},
10368 {"mno-fix-vr4120", no_argument, NULL, OPTION_NO_FIX_VR4120},
10369 #define OPTION_FIX_VR4130 (OPTION_FIX_BASE + 4)
10370 #define OPTION_NO_FIX_VR4130 (OPTION_FIX_BASE + 5)
10371 {"mfix-vr4130", no_argument, NULL, OPTION_FIX_VR4130},
10372 {"mno-fix-vr4130", no_argument, NULL, OPTION_NO_FIX_VR4130},
10374 /* Miscellaneous options. */
10375 #define OPTION_MISC_BASE (OPTION_FIX_BASE + 6)
10376 #define OPTION_TRAP (OPTION_MISC_BASE + 0)
10377 {"trap", no_argument, NULL, OPTION_TRAP},
10378 {"no-break", no_argument, NULL, OPTION_TRAP},
10379 #define OPTION_BREAK (OPTION_MISC_BASE + 1)
10380 {"break", no_argument, NULL, OPTION_BREAK},
10381 {"no-trap", no_argument, NULL, OPTION_BREAK},
10382 #define OPTION_EB (OPTION_MISC_BASE + 2)
10383 {"EB", no_argument, NULL, OPTION_EB},
10384 #define OPTION_EL (OPTION_MISC_BASE + 3)
10385 {"EL", no_argument, NULL, OPTION_EL},
10386 #define OPTION_FP32 (OPTION_MISC_BASE + 4)
10387 {"mfp32", no_argument, NULL, OPTION_FP32},
10388 #define OPTION_GP32 (OPTION_MISC_BASE + 5)
10389 {"mgp32", no_argument, NULL, OPTION_GP32},
10390 #define OPTION_CONSTRUCT_FLOATS (OPTION_MISC_BASE + 6)
10391 {"construct-floats", no_argument, NULL, OPTION_CONSTRUCT_FLOATS},
10392 #define OPTION_NO_CONSTRUCT_FLOATS (OPTION_MISC_BASE + 7)
10393 {"no-construct-floats", no_argument, NULL, OPTION_NO_CONSTRUCT_FLOATS},
10394 #define OPTION_FP64 (OPTION_MISC_BASE + 8)
10395 {"mfp64", no_argument, NULL, OPTION_FP64},
10396 #define OPTION_GP64 (OPTION_MISC_BASE + 9)
10397 {"mgp64", no_argument, NULL, OPTION_GP64},
10398 #define OPTION_RELAX_BRANCH (OPTION_MISC_BASE + 10)
10399 #define OPTION_NO_RELAX_BRANCH (OPTION_MISC_BASE + 11)
10400 {"relax-branch", no_argument, NULL, OPTION_RELAX_BRANCH},
10401 {"no-relax-branch", no_argument, NULL, OPTION_NO_RELAX_BRANCH},
10402 #define OPTION_MSHARED (OPTION_MISC_BASE + 12)
10403 #define OPTION_MNO_SHARED (OPTION_MISC_BASE + 13)
10404 {"mshared", no_argument, NULL, OPTION_MSHARED},
10405 {"mno-shared", no_argument, NULL, OPTION_MNO_SHARED},
10406 #define OPTION_MSYM32 (OPTION_MISC_BASE + 14)
10407 #define OPTION_MNO_SYM32 (OPTION_MISC_BASE + 15)
10408 {"msym32", no_argument, NULL, OPTION_MSYM32},
10409 {"mno-sym32", no_argument, NULL, OPTION_MNO_SYM32},
10411 /* ELF-specific options. */
10413 #define OPTION_ELF_BASE (OPTION_MISC_BASE + 16)
10414 #define OPTION_CALL_SHARED (OPTION_ELF_BASE + 0)
10415 {"KPIC", no_argument, NULL, OPTION_CALL_SHARED},
10416 {"call_shared", no_argument, NULL, OPTION_CALL_SHARED},
10417 #define OPTION_NON_SHARED (OPTION_ELF_BASE + 1)
10418 {"non_shared", no_argument, NULL, OPTION_NON_SHARED},
10419 #define OPTION_XGOT (OPTION_ELF_BASE + 2)
10420 {"xgot", no_argument, NULL, OPTION_XGOT},
10421 #define OPTION_MABI (OPTION_ELF_BASE + 3)
10422 {"mabi", required_argument, NULL, OPTION_MABI},
10423 #define OPTION_32 (OPTION_ELF_BASE + 4)
10424 {"32", no_argument, NULL, OPTION_32},
10425 #define OPTION_N32 (OPTION_ELF_BASE + 5)
10426 {"n32", no_argument, NULL, OPTION_N32},
10427 #define OPTION_64 (OPTION_ELF_BASE + 6)
10428 {"64", no_argument, NULL, OPTION_64},
10429 #define OPTION_MDEBUG (OPTION_ELF_BASE + 7)
10430 {"mdebug", no_argument, NULL, OPTION_MDEBUG},
10431 #define OPTION_NO_MDEBUG (OPTION_ELF_BASE + 8)
10432 {"no-mdebug", no_argument, NULL, OPTION_NO_MDEBUG},
10433 #define OPTION_PDR (OPTION_ELF_BASE + 9)
10434 {"mpdr", no_argument, NULL, OPTION_PDR},
10435 #define OPTION_NO_PDR (OPTION_ELF_BASE + 10)
10436 {"mno-pdr", no_argument, NULL, OPTION_NO_PDR},
10437 #endif /* OBJ_ELF */
10439 {NULL, no_argument, NULL, 0}
10441 size_t md_longopts_size = sizeof (md_longopts);
10443 /* Set STRING_PTR (either &mips_arch_string or &mips_tune_string) to
10444 NEW_VALUE. Warn if another value was already specified. Note:
10445 we have to defer parsing the -march and -mtune arguments in order
10446 to handle 'from-abi' correctly, since the ABI might be specified
10447 in a later argument. */
10450 mips_set_option_string (const char **string_ptr, const char *new_value)
10452 if (*string_ptr != 0 && strcasecmp (*string_ptr, new_value) != 0)
10453 as_warn (_("A different %s was already specified, is now %s"),
10454 string_ptr == &mips_arch_string ? "-march" : "-mtune",
10457 *string_ptr = new_value;
10461 md_parse_option (int c, char *arg)
10465 case OPTION_CONSTRUCT_FLOATS:
10466 mips_disable_float_construction = 0;
10469 case OPTION_NO_CONSTRUCT_FLOATS:
10470 mips_disable_float_construction = 1;
10482 target_big_endian = 1;
10486 target_big_endian = 0;
10490 if (arg && arg[1] == '0')
10500 mips_debug = atoi (arg);
10501 /* When the MIPS assembler sees -g or -g2, it does not do
10502 optimizations which limit full symbolic debugging. We take
10503 that to be equivalent to -O0. */
10504 if (mips_debug == 2)
10509 file_mips_isa = ISA_MIPS1;
10513 file_mips_isa = ISA_MIPS2;
10517 file_mips_isa = ISA_MIPS3;
10521 file_mips_isa = ISA_MIPS4;
10525 file_mips_isa = ISA_MIPS5;
10528 case OPTION_MIPS32:
10529 file_mips_isa = ISA_MIPS32;
10532 case OPTION_MIPS32R2:
10533 file_mips_isa = ISA_MIPS32R2;
10536 case OPTION_MIPS64R2:
10537 file_mips_isa = ISA_MIPS64R2;
10540 case OPTION_MIPS64:
10541 file_mips_isa = ISA_MIPS64;
10545 mips_set_option_string (&mips_tune_string, arg);
10549 mips_set_option_string (&mips_arch_string, arg);
10553 mips_set_option_string (&mips_arch_string, "4650");
10554 mips_set_option_string (&mips_tune_string, "4650");
10557 case OPTION_NO_M4650:
10561 mips_set_option_string (&mips_arch_string, "4010");
10562 mips_set_option_string (&mips_tune_string, "4010");
10565 case OPTION_NO_M4010:
10569 mips_set_option_string (&mips_arch_string, "4100");
10570 mips_set_option_string (&mips_tune_string, "4100");
10573 case OPTION_NO_M4100:
10577 mips_set_option_string (&mips_arch_string, "3900");
10578 mips_set_option_string (&mips_tune_string, "3900");
10581 case OPTION_NO_M3900:
10585 mips_opts.ase_mdmx = 1;
10588 case OPTION_NO_MDMX:
10589 mips_opts.ase_mdmx = 0;
10593 mips_opts.ase_dsp = 1;
10596 case OPTION_NO_DSP:
10597 mips_opts.ase_dsp = 0;
10601 mips_opts.ase_mt = 1;
10605 mips_opts.ase_mt = 0;
10608 case OPTION_MIPS16:
10609 mips_opts.mips16 = 1;
10610 mips_no_prev_insn ();
10613 case OPTION_NO_MIPS16:
10614 mips_opts.mips16 = 0;
10615 mips_no_prev_insn ();
10618 case OPTION_MIPS3D:
10619 mips_opts.ase_mips3d = 1;
10622 case OPTION_NO_MIPS3D:
10623 mips_opts.ase_mips3d = 0;
10626 case OPTION_FIX_VR4120:
10627 mips_fix_vr4120 = 1;
10630 case OPTION_NO_FIX_VR4120:
10631 mips_fix_vr4120 = 0;
10634 case OPTION_FIX_VR4130:
10635 mips_fix_vr4130 = 1;
10638 case OPTION_NO_FIX_VR4130:
10639 mips_fix_vr4130 = 0;
10642 case OPTION_RELAX_BRANCH:
10643 mips_relax_branch = 1;
10646 case OPTION_NO_RELAX_BRANCH:
10647 mips_relax_branch = 0;
10650 case OPTION_MSHARED:
10651 mips_in_shared = TRUE;
10654 case OPTION_MNO_SHARED:
10655 mips_in_shared = FALSE;
10658 case OPTION_MSYM32:
10659 mips_opts.sym32 = TRUE;
10662 case OPTION_MNO_SYM32:
10663 mips_opts.sym32 = FALSE;
10667 /* When generating ELF code, we permit -KPIC and -call_shared to
10668 select SVR4_PIC, and -non_shared to select no PIC. This is
10669 intended to be compatible with Irix 5. */
10670 case OPTION_CALL_SHARED:
10671 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10673 as_bad (_("-call_shared is supported only for ELF format"));
10676 mips_pic = SVR4_PIC;
10677 mips_abicalls = TRUE;
10678 if (g_switch_seen && g_switch_value != 0)
10680 as_bad (_("-G may not be used with SVR4 PIC code"));
10683 g_switch_value = 0;
10686 case OPTION_NON_SHARED:
10687 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10689 as_bad (_("-non_shared is supported only for ELF format"));
10693 mips_abicalls = FALSE;
10696 /* The -xgot option tells the assembler to use 32 offsets when
10697 accessing the got in SVR4_PIC mode. It is for Irix
10702 #endif /* OBJ_ELF */
10705 g_switch_value = atoi (arg);
10707 if (mips_pic == SVR4_PIC && g_switch_value != 0)
10709 as_bad (_("-G may not be used with SVR4 PIC code"));
10715 /* The -32, -n32 and -64 options are shortcuts for -mabi=32, -mabi=n32
10718 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10720 as_bad (_("-32 is supported for ELF format only"));
10723 mips_abi = O32_ABI;
10727 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10729 as_bad (_("-n32 is supported for ELF format only"));
10732 mips_abi = N32_ABI;
10736 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10738 as_bad (_("-64 is supported for ELF format only"));
10741 mips_abi = N64_ABI;
10742 if (! support_64bit_objects())
10743 as_fatal (_("No compiled in support for 64 bit object file format"));
10745 #endif /* OBJ_ELF */
10748 file_mips_gp32 = 1;
10752 file_mips_gp32 = 0;
10756 file_mips_fp32 = 1;
10760 file_mips_fp32 = 0;
10765 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10767 as_bad (_("-mabi is supported for ELF format only"));
10770 if (strcmp (arg, "32") == 0)
10771 mips_abi = O32_ABI;
10772 else if (strcmp (arg, "o64") == 0)
10773 mips_abi = O64_ABI;
10774 else if (strcmp (arg, "n32") == 0)
10775 mips_abi = N32_ABI;
10776 else if (strcmp (arg, "64") == 0)
10778 mips_abi = N64_ABI;
10779 if (! support_64bit_objects())
10780 as_fatal (_("No compiled in support for 64 bit object file "
10783 else if (strcmp (arg, "eabi") == 0)
10784 mips_abi = EABI_ABI;
10787 as_fatal (_("invalid abi -mabi=%s"), arg);
10791 #endif /* OBJ_ELF */
10793 case OPTION_M7000_HILO_FIX:
10794 mips_7000_hilo_fix = TRUE;
10797 case OPTION_MNO_7000_HILO_FIX:
10798 mips_7000_hilo_fix = FALSE;
10802 case OPTION_MDEBUG:
10803 mips_flag_mdebug = TRUE;
10806 case OPTION_NO_MDEBUG:
10807 mips_flag_mdebug = FALSE;
10811 mips_flag_pdr = TRUE;
10814 case OPTION_NO_PDR:
10815 mips_flag_pdr = FALSE;
10817 #endif /* OBJ_ELF */
10826 /* Set up globals to generate code for the ISA or processor
10827 described by INFO. */
10830 mips_set_architecture (const struct mips_cpu_info *info)
10834 file_mips_arch = info->cpu;
10835 mips_opts.arch = info->cpu;
10836 mips_opts.isa = info->isa;
10841 /* Likewise for tuning. */
10844 mips_set_tune (const struct mips_cpu_info *info)
10847 mips_tune = info->cpu;
10852 mips_after_parse_args (void)
10854 const struct mips_cpu_info *arch_info = 0;
10855 const struct mips_cpu_info *tune_info = 0;
10857 /* GP relative stuff not working for PE */
10858 if (strncmp (TARGET_OS, "pe", 2) == 0)
10860 if (g_switch_seen && g_switch_value != 0)
10861 as_bad (_("-G not supported in this configuration."));
10862 g_switch_value = 0;
10865 if (mips_abi == NO_ABI)
10866 mips_abi = MIPS_DEFAULT_ABI;
10868 /* The following code determines the architecture and register size.
10869 Similar code was added to GCC 3.3 (see override_options() in
10870 config/mips/mips.c). The GAS and GCC code should be kept in sync
10871 as much as possible. */
10873 if (mips_arch_string != 0)
10874 arch_info = mips_parse_cpu ("-march", mips_arch_string);
10876 if (file_mips_isa != ISA_UNKNOWN)
10878 /* Handle -mipsN. At this point, file_mips_isa contains the
10879 ISA level specified by -mipsN, while arch_info->isa contains
10880 the -march selection (if any). */
10881 if (arch_info != 0)
10883 /* -march takes precedence over -mipsN, since it is more descriptive.
10884 There's no harm in specifying both as long as the ISA levels
10886 if (file_mips_isa != arch_info->isa)
10887 as_bad (_("-%s conflicts with the other architecture options, which imply -%s"),
10888 mips_cpu_info_from_isa (file_mips_isa)->name,
10889 mips_cpu_info_from_isa (arch_info->isa)->name);
10892 arch_info = mips_cpu_info_from_isa (file_mips_isa);
10895 if (arch_info == 0)
10896 arch_info = mips_parse_cpu ("default CPU", MIPS_CPU_STRING_DEFAULT);
10898 if (ABI_NEEDS_64BIT_REGS (mips_abi) && !ISA_HAS_64BIT_REGS (arch_info->isa))
10899 as_bad ("-march=%s is not compatible with the selected ABI",
10902 mips_set_architecture (arch_info);
10904 /* Optimize for file_mips_arch, unless -mtune selects a different processor. */
10905 if (mips_tune_string != 0)
10906 tune_info = mips_parse_cpu ("-mtune", mips_tune_string);
10908 if (tune_info == 0)
10909 mips_set_tune (arch_info);
10911 mips_set_tune (tune_info);
10913 if (file_mips_gp32 >= 0)
10915 /* The user specified the size of the integer registers. Make sure
10916 it agrees with the ABI and ISA. */
10917 if (file_mips_gp32 == 0 && !ISA_HAS_64BIT_REGS (mips_opts.isa))
10918 as_bad (_("-mgp64 used with a 32-bit processor"));
10919 else if (file_mips_gp32 == 1 && ABI_NEEDS_64BIT_REGS (mips_abi))
10920 as_bad (_("-mgp32 used with a 64-bit ABI"));
10921 else if (file_mips_gp32 == 0 && ABI_NEEDS_32BIT_REGS (mips_abi))
10922 as_bad (_("-mgp64 used with a 32-bit ABI"));
10926 /* Infer the integer register size from the ABI and processor.
10927 Restrict ourselves to 32-bit registers if that's all the
10928 processor has, or if the ABI cannot handle 64-bit registers. */
10929 file_mips_gp32 = (ABI_NEEDS_32BIT_REGS (mips_abi)
10930 || !ISA_HAS_64BIT_REGS (mips_opts.isa));
10933 /* ??? GAS treats single-float processors as though they had 64-bit
10934 float registers (although it complains when double-precision
10935 instructions are used). As things stand, saying they have 32-bit
10936 registers would lead to spurious "register must be even" messages.
10937 So here we assume float registers are always the same size as
10938 integer ones, unless the user says otherwise. */
10939 if (file_mips_fp32 < 0)
10940 file_mips_fp32 = file_mips_gp32;
10942 /* End of GCC-shared inference code. */
10944 /* This flag is set when we have a 64-bit capable CPU but use only
10945 32-bit wide registers. Note that EABI does not use it. */
10946 if (ISA_HAS_64BIT_REGS (mips_opts.isa)
10947 && ((mips_abi == NO_ABI && file_mips_gp32 == 1)
10948 || mips_abi == O32_ABI))
10949 mips_32bitmode = 1;
10951 if (mips_opts.isa == ISA_MIPS1 && mips_trap)
10952 as_bad (_("trap exception not supported at ISA 1"));
10954 /* If the selected architecture includes support for ASEs, enable
10955 generation of code for them. */
10956 if (mips_opts.mips16 == -1)
10957 mips_opts.mips16 = (CPU_HAS_MIPS16 (file_mips_arch)) ? 1 : 0;
10958 if (mips_opts.ase_mips3d == -1)
10959 mips_opts.ase_mips3d = (CPU_HAS_MIPS3D (file_mips_arch)) ? 1 : 0;
10960 if (mips_opts.ase_mdmx == -1)
10961 mips_opts.ase_mdmx = (CPU_HAS_MDMX (file_mips_arch)) ? 1 : 0;
10962 if (mips_opts.ase_dsp == -1)
10963 mips_opts.ase_dsp = (CPU_HAS_DSP (file_mips_arch)) ? 1 : 0;
10964 if (mips_opts.ase_mt == -1)
10965 mips_opts.ase_mt = (CPU_HAS_MT (file_mips_arch)) ? 1 : 0;
10967 file_mips_isa = mips_opts.isa;
10968 file_ase_mips16 = mips_opts.mips16;
10969 file_ase_mips3d = mips_opts.ase_mips3d;
10970 file_ase_mdmx = mips_opts.ase_mdmx;
10971 file_ase_dsp = mips_opts.ase_dsp;
10972 file_ase_mt = mips_opts.ase_mt;
10973 mips_opts.gp32 = file_mips_gp32;
10974 mips_opts.fp32 = file_mips_fp32;
10976 if (mips_flag_mdebug < 0)
10978 #ifdef OBJ_MAYBE_ECOFF
10979 if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour)
10980 mips_flag_mdebug = 1;
10982 #endif /* OBJ_MAYBE_ECOFF */
10983 mips_flag_mdebug = 0;
10988 mips_init_after_args (void)
10990 /* initialize opcodes */
10991 bfd_mips_num_opcodes = bfd_mips_num_builtin_opcodes;
10992 mips_opcodes = (struct mips_opcode *) mips_builtin_opcodes;
10996 md_pcrel_from (fixS *fixP)
10998 valueT addr = fixP->fx_where + fixP->fx_frag->fr_address;
10999 switch (fixP->fx_r_type)
11001 case BFD_RELOC_16_PCREL_S2:
11002 case BFD_RELOC_MIPS_JMP:
11003 /* Return the address of the delay slot. */
11010 /* This is called before the symbol table is processed. In order to
11011 work with gcc when using mips-tfile, we must keep all local labels.
11012 However, in other cases, we want to discard them. If we were
11013 called with -g, but we didn't see any debugging information, it may
11014 mean that gcc is smuggling debugging information through to
11015 mips-tfile, in which case we must generate all local labels. */
11018 mips_frob_file_before_adjust (void)
11020 #ifndef NO_ECOFF_DEBUGGING
11021 if (ECOFF_DEBUGGING
11023 && ! ecoff_debugging_seen)
11024 flag_keep_locals = 1;
11028 /* Sort any unmatched HI16 and GOT16 relocs so that they immediately precede
11029 the corresponding LO16 reloc. This is called before md_apply_fix and
11030 tc_gen_reloc. Unmatched relocs can only be generated by use of explicit
11031 relocation operators.
11033 For our purposes, a %lo() expression matches a %got() or %hi()
11036 (a) it refers to the same symbol; and
11037 (b) the offset applied in the %lo() expression is no lower than
11038 the offset applied in the %got() or %hi().
11040 (b) allows us to cope with code like:
11043 lh $4,%lo(foo+2)($4)
11045 ...which is legal on RELA targets, and has a well-defined behaviour
11046 if the user knows that adding 2 to "foo" will not induce a carry to
11049 When several %lo()s match a particular %got() or %hi(), we use the
11050 following rules to distinguish them:
11052 (1) %lo()s with smaller offsets are a better match than %lo()s with
11055 (2) %lo()s with no matching %got() or %hi() are better than those
11056 that already have a matching %got() or %hi().
11058 (3) later %lo()s are better than earlier %lo()s.
11060 These rules are applied in order.
11062 (1) means, among other things, that %lo()s with identical offsets are
11063 chosen if they exist.
11065 (2) means that we won't associate several high-part relocations with
11066 the same low-part relocation unless there's no alternative. Having
11067 several high parts for the same low part is a GNU extension; this rule
11068 allows careful users to avoid it.
11070 (3) is purely cosmetic. mips_hi_fixup_list is is in reverse order,
11071 with the last high-part relocation being at the front of the list.
11072 It therefore makes sense to choose the last matching low-part
11073 relocation, all other things being equal. It's also easier
11074 to code that way. */
11077 mips_frob_file (void)
11079 struct mips_hi_fixup *l;
11081 for (l = mips_hi_fixup_list; l != NULL; l = l->next)
11083 segment_info_type *seginfo;
11084 bfd_boolean matched_lo_p;
11085 fixS **hi_pos, **lo_pos, **pos;
11087 assert (reloc_needs_lo_p (l->fixp->fx_r_type));
11089 /* If a GOT16 relocation turns out to be against a global symbol,
11090 there isn't supposed to be a matching LO. */
11091 if (l->fixp->fx_r_type == BFD_RELOC_MIPS_GOT16
11092 && !pic_need_relax (l->fixp->fx_addsy, l->seg))
11095 /* Check quickly whether the next fixup happens to be a matching %lo. */
11096 if (fixup_has_matching_lo_p (l->fixp))
11099 seginfo = seg_info (l->seg);
11101 /* Set HI_POS to the position of this relocation in the chain.
11102 Set LO_POS to the position of the chosen low-part relocation.
11103 MATCHED_LO_P is true on entry to the loop if *POS is a low-part
11104 relocation that matches an immediately-preceding high-part
11108 matched_lo_p = FALSE;
11109 for (pos = &seginfo->fix_root; *pos != NULL; pos = &(*pos)->fx_next)
11111 if (*pos == l->fixp)
11114 if (((*pos)->fx_r_type == BFD_RELOC_LO16
11115 || (*pos)->fx_r_type == BFD_RELOC_MIPS16_LO16)
11116 && (*pos)->fx_addsy == l->fixp->fx_addsy
11117 && (*pos)->fx_offset >= l->fixp->fx_offset
11119 || (*pos)->fx_offset < (*lo_pos)->fx_offset
11121 && (*pos)->fx_offset == (*lo_pos)->fx_offset)))
11124 matched_lo_p = (reloc_needs_lo_p ((*pos)->fx_r_type)
11125 && fixup_has_matching_lo_p (*pos));
11128 /* If we found a match, remove the high-part relocation from its
11129 current position and insert it before the low-part relocation.
11130 Make the offsets match so that fixup_has_matching_lo_p()
11133 We don't warn about unmatched high-part relocations since some
11134 versions of gcc have been known to emit dead "lui ...%hi(...)"
11136 if (lo_pos != NULL)
11138 l->fixp->fx_offset = (*lo_pos)->fx_offset;
11139 if (l->fixp->fx_next != *lo_pos)
11141 *hi_pos = l->fixp->fx_next;
11142 l->fixp->fx_next = *lo_pos;
11149 /* We may have combined relocations without symbols in the N32/N64 ABI.
11150 We have to prevent gas from dropping them. */
11153 mips_force_relocation (fixS *fixp)
11155 if (generic_force_reloc (fixp))
11159 && S_GET_SEGMENT (fixp->fx_addsy) == bfd_abs_section_ptr
11160 && (fixp->fx_r_type == BFD_RELOC_MIPS_SUB
11161 || fixp->fx_r_type == BFD_RELOC_HI16_S
11162 || fixp->fx_r_type == BFD_RELOC_LO16))
11168 /* This hook is called before a fix is simplified. We don't really
11169 decide whether to skip a fix here. Rather, we turn global symbols
11170 used as branch targets into local symbols, such that they undergo
11171 simplification. We can only do this if the symbol is defined and
11172 it is in the same section as the branch. If this doesn't hold, we
11173 emit a better error message than just saying the relocation is not
11174 valid for the selected object format.
11176 FIXP is the fix-up we're going to try to simplify, SEG is the
11177 segment in which the fix up occurs. The return value should be
11178 non-zero to indicate the fix-up is valid for further
11179 simplifications. */
11182 mips_validate_fix (struct fix *fixP, asection *seg)
11184 /* There's a lot of discussion on whether it should be possible to
11185 use R_MIPS_PC16 to represent branch relocations. The outcome
11186 seems to be that it can, but gas/bfd are very broken in creating
11187 RELA relocations for this, so for now we only accept branches to
11188 symbols in the same section. Anything else is of dubious value,
11189 since there's no guarantee that at link time the symbol would be
11190 in range. Even for branches to local symbols this is arguably
11191 wrong, since it we assume the symbol is not going to be
11192 overridden, which should be possible per ELF library semantics,
11193 but then, there isn't a dynamic relocation that could be used to
11194 this effect, and the target would likely be out of range as well.
11196 Unfortunately, it seems that there is too much code out there
11197 that relies on branches to symbols that are global to be resolved
11198 as if they were local, like the IRIX tools do, so we do it as
11199 well, but with a warning so that people are reminded to fix their
11200 code. If we ever get back to using R_MIPS_PC16 for branch
11201 targets, this entire block should go away (and probably the
11202 whole function). */
11204 if (fixP->fx_r_type == BFD_RELOC_16_PCREL_S2
11205 && ((OUTPUT_FLAVOR == bfd_target_ecoff_flavour
11206 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
11207 || bfd_reloc_type_lookup (stdoutput, BFD_RELOC_16_PCREL_S2) == NULL)
11210 if (! S_IS_DEFINED (fixP->fx_addsy))
11212 as_bad_where (fixP->fx_file, fixP->fx_line,
11213 _("Cannot branch to undefined symbol."));
11214 /* Avoid any further errors about this fixup. */
11217 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
11219 as_bad_where (fixP->fx_file, fixP->fx_line,
11220 _("Cannot branch to symbol in another section."));
11223 else if (S_IS_EXTERNAL (fixP->fx_addsy))
11225 symbolS *sym = fixP->fx_addsy;
11227 if (mips_pic == SVR4_PIC)
11228 as_warn_where (fixP->fx_file, fixP->fx_line,
11229 _("Pretending global symbol used as branch target is local."));
11231 fixP->fx_addsy = symbol_create (S_GET_NAME (sym),
11232 S_GET_SEGMENT (sym),
11234 symbol_get_frag (sym));
11235 copy_symbol_attributes (fixP->fx_addsy, sym);
11236 S_CLEAR_EXTERNAL (fixP->fx_addsy);
11237 assert (symbol_resolved_p (sym));
11238 symbol_mark_resolved (fixP->fx_addsy);
11245 /* Apply a fixup to the object file. */
11248 md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
11252 reloc_howto_type *howto;
11254 /* We ignore generic BFD relocations we don't know about. */
11255 howto = bfd_reloc_type_lookup (stdoutput, fixP->fx_r_type);
11259 assert (fixP->fx_size == 4
11260 || fixP->fx_r_type == BFD_RELOC_16
11261 || fixP->fx_r_type == BFD_RELOC_64
11262 || fixP->fx_r_type == BFD_RELOC_CTOR
11263 || fixP->fx_r_type == BFD_RELOC_MIPS_SUB
11264 || fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
11265 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY);
11267 buf = (bfd_byte *) (fixP->fx_frag->fr_literal + fixP->fx_where);
11269 assert (! fixP->fx_pcrel);
11271 /* Don't treat parts of a composite relocation as done. There are two
11274 (1) The second and third parts will be against 0 (RSS_UNDEF) but
11275 should nevertheless be emitted if the first part is.
11277 (2) In normal usage, composite relocations are never assembly-time
11278 constants. The easiest way of dealing with the pathological
11279 exceptions is to generate a relocation against STN_UNDEF and
11280 leave everything up to the linker. */
11281 if (fixP->fx_addsy == NULL && fixP->fx_tcbit == 0)
11284 switch (fixP->fx_r_type)
11286 case BFD_RELOC_MIPS_TLS_GD:
11287 case BFD_RELOC_MIPS_TLS_LDM:
11288 case BFD_RELOC_MIPS_TLS_DTPREL_HI16:
11289 case BFD_RELOC_MIPS_TLS_DTPREL_LO16:
11290 case BFD_RELOC_MIPS_TLS_GOTTPREL:
11291 case BFD_RELOC_MIPS_TLS_TPREL_HI16:
11292 case BFD_RELOC_MIPS_TLS_TPREL_LO16:
11293 S_SET_THREAD_LOCAL (fixP->fx_addsy);
11296 case BFD_RELOC_MIPS_JMP:
11297 case BFD_RELOC_MIPS_SHIFT5:
11298 case BFD_RELOC_MIPS_SHIFT6:
11299 case BFD_RELOC_MIPS_GOT_DISP:
11300 case BFD_RELOC_MIPS_GOT_PAGE:
11301 case BFD_RELOC_MIPS_GOT_OFST:
11302 case BFD_RELOC_MIPS_SUB:
11303 case BFD_RELOC_MIPS_INSERT_A:
11304 case BFD_RELOC_MIPS_INSERT_B:
11305 case BFD_RELOC_MIPS_DELETE:
11306 case BFD_RELOC_MIPS_HIGHEST:
11307 case BFD_RELOC_MIPS_HIGHER:
11308 case BFD_RELOC_MIPS_SCN_DISP:
11309 case BFD_RELOC_MIPS_REL16:
11310 case BFD_RELOC_MIPS_RELGOT:
11311 case BFD_RELOC_MIPS_JALR:
11312 case BFD_RELOC_HI16:
11313 case BFD_RELOC_HI16_S:
11314 case BFD_RELOC_GPREL16:
11315 case BFD_RELOC_MIPS_LITERAL:
11316 case BFD_RELOC_MIPS_CALL16:
11317 case BFD_RELOC_MIPS_GOT16:
11318 case BFD_RELOC_GPREL32:
11319 case BFD_RELOC_MIPS_GOT_HI16:
11320 case BFD_RELOC_MIPS_GOT_LO16:
11321 case BFD_RELOC_MIPS_CALL_HI16:
11322 case BFD_RELOC_MIPS_CALL_LO16:
11323 case BFD_RELOC_MIPS16_GPREL:
11324 case BFD_RELOC_MIPS16_HI16:
11325 case BFD_RELOC_MIPS16_HI16_S:
11326 assert (! fixP->fx_pcrel);
11327 /* Nothing needed to do. The value comes from the reloc entry */
11330 case BFD_RELOC_MIPS16_JMP:
11331 /* We currently always generate a reloc against a symbol, which
11332 means that we don't want an addend even if the symbol is
11338 /* This is handled like BFD_RELOC_32, but we output a sign
11339 extended value if we are only 32 bits. */
11342 if (8 <= sizeof (valueT))
11343 md_number_to_chars ((char *) buf, *valP, 8);
11348 if ((*valP & 0x80000000) != 0)
11352 md_number_to_chars ((char *)(buf + (target_big_endian ? 4 : 0)),
11354 md_number_to_chars ((char *)(buf + (target_big_endian ? 0 : 4)),
11360 case BFD_RELOC_RVA:
11362 /* If we are deleting this reloc entry, we must fill in the
11363 value now. This can happen if we have a .word which is not
11364 resolved when it appears but is later defined. */
11366 md_number_to_chars ((char *) buf, *valP, 4);
11370 /* If we are deleting this reloc entry, we must fill in the
11373 md_number_to_chars ((char *) buf, *valP, 2);
11376 case BFD_RELOC_LO16:
11377 case BFD_RELOC_MIPS16_LO16:
11378 /* FIXME: Now that embedded-PIC is gone, some of this code/comment
11379 may be safe to remove, but if so it's not obvious. */
11380 /* When handling an embedded PIC switch statement, we can wind
11381 up deleting a LO16 reloc. See the 'o' case in mips_ip. */
11384 if (*valP + 0x8000 > 0xffff)
11385 as_bad_where (fixP->fx_file, fixP->fx_line,
11386 _("relocation overflow"));
11387 if (target_big_endian)
11389 md_number_to_chars ((char *) buf, *valP, 2);
11393 case BFD_RELOC_16_PCREL_S2:
11394 if ((*valP & 0x3) != 0)
11395 as_bad_where (fixP->fx_file, fixP->fx_line,
11396 _("Branch to odd address (%lx)"), (long) *valP);
11399 * We need to save the bits in the instruction since fixup_segment()
11400 * might be deleting the relocation entry (i.e., a branch within
11401 * the current segment).
11403 if (! fixP->fx_done)
11406 /* update old instruction data */
11407 if (target_big_endian)
11408 insn = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
11410 insn = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
11412 if (*valP + 0x20000 <= 0x3ffff)
11414 insn |= (*valP >> 2) & 0xffff;
11415 md_number_to_chars ((char *) buf, insn, 4);
11417 else if (mips_pic == NO_PIC
11419 && fixP->fx_frag->fr_address >= text_section->vma
11420 && (fixP->fx_frag->fr_address
11421 < text_section->vma + bfd_get_section_size (text_section))
11422 && ((insn & 0xffff0000) == 0x10000000 /* beq $0,$0 */
11423 || (insn & 0xffff0000) == 0x04010000 /* bgez $0 */
11424 || (insn & 0xffff0000) == 0x04110000)) /* bgezal $0 */
11426 /* The branch offset is too large. If this is an
11427 unconditional branch, and we are not generating PIC code,
11428 we can convert it to an absolute jump instruction. */
11429 if ((insn & 0xffff0000) == 0x04110000) /* bgezal $0 */
11430 insn = 0x0c000000; /* jal */
11432 insn = 0x08000000; /* j */
11433 fixP->fx_r_type = BFD_RELOC_MIPS_JMP;
11435 fixP->fx_addsy = section_symbol (text_section);
11436 *valP += md_pcrel_from (fixP);
11437 md_number_to_chars ((char *) buf, insn, 4);
11441 /* If we got here, we have branch-relaxation disabled,
11442 and there's nothing we can do to fix this instruction
11443 without turning it into a longer sequence. */
11444 as_bad_where (fixP->fx_file, fixP->fx_line,
11445 _("Branch out of range"));
11449 case BFD_RELOC_VTABLE_INHERIT:
11452 && !S_IS_DEFINED (fixP->fx_addsy)
11453 && !S_IS_WEAK (fixP->fx_addsy))
11454 S_SET_WEAK (fixP->fx_addsy);
11457 case BFD_RELOC_VTABLE_ENTRY:
11465 /* Remember value for tc_gen_reloc. */
11466 fixP->fx_addnumber = *valP;
11476 name = input_line_pointer;
11477 c = get_symbol_end ();
11478 p = (symbolS *) symbol_find_or_make (name);
11479 *input_line_pointer = c;
11483 /* Align the current frag to a given power of two. The MIPS assembler
11484 also automatically adjusts any preceding label. */
11487 mips_align (int to, int fill, symbolS *label)
11489 mips_emit_delays ();
11490 frag_align (to, fill, 0);
11491 record_alignment (now_seg, to);
11494 assert (S_GET_SEGMENT (label) == now_seg);
11495 symbol_set_frag (label, frag_now);
11496 S_SET_VALUE (label, (valueT) frag_now_fix ());
11500 /* Align to a given power of two. .align 0 turns off the automatic
11501 alignment used by the data creating pseudo-ops. */
11504 s_align (int x ATTRIBUTE_UNUSED)
11507 register long temp_fill;
11508 long max_alignment = 15;
11512 o Note that the assembler pulls down any immediately preceding label
11513 to the aligned address.
11514 o It's not documented but auto alignment is reinstated by
11515 a .align pseudo instruction.
11516 o Note also that after auto alignment is turned off the mips assembler
11517 issues an error on attempt to assemble an improperly aligned data item.
11522 temp = get_absolute_expression ();
11523 if (temp > max_alignment)
11524 as_bad (_("Alignment too large: %d. assumed."), temp = max_alignment);
11527 as_warn (_("Alignment negative: 0 assumed."));
11530 if (*input_line_pointer == ',')
11532 ++input_line_pointer;
11533 temp_fill = get_absolute_expression ();
11540 mips_align (temp, (int) temp_fill,
11541 insn_labels != NULL ? insn_labels->label : NULL);
11548 demand_empty_rest_of_line ();
11552 s_change_sec (int sec)
11557 /* The ELF backend needs to know that we are changing sections, so
11558 that .previous works correctly. We could do something like check
11559 for an obj_section_change_hook macro, but that might be confusing
11560 as it would not be appropriate to use it in the section changing
11561 functions in read.c, since obj-elf.c intercepts those. FIXME:
11562 This should be cleaner, somehow. */
11563 obj_elf_section_change_hook ();
11566 mips_emit_delays ();
11576 subseg_set (bss_section, (subsegT) get_absolute_expression ());
11577 demand_empty_rest_of_line ();
11581 seg = subseg_new (RDATA_SECTION_NAME,
11582 (subsegT) get_absolute_expression ());
11583 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
11585 bfd_set_section_flags (stdoutput, seg, (SEC_ALLOC | SEC_LOAD
11586 | SEC_READONLY | SEC_RELOC
11588 if (strcmp (TARGET_OS, "elf") != 0)
11589 record_alignment (seg, 4);
11591 demand_empty_rest_of_line ();
11595 seg = subseg_new (".sdata", (subsegT) get_absolute_expression ());
11596 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
11598 bfd_set_section_flags (stdoutput, seg,
11599 SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_DATA);
11600 if (strcmp (TARGET_OS, "elf") != 0)
11601 record_alignment (seg, 4);
11603 demand_empty_rest_of_line ();
11611 s_change_section (int ignore ATTRIBUTE_UNUSED)
11614 char *section_name;
11619 int section_entry_size;
11620 int section_alignment;
11622 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
11625 section_name = input_line_pointer;
11626 c = get_symbol_end ();
11628 next_c = *(input_line_pointer + 1);
11630 /* Do we have .section Name<,"flags">? */
11631 if (c != ',' || (c == ',' && next_c == '"'))
11633 /* just after name is now '\0'. */
11634 *input_line_pointer = c;
11635 input_line_pointer = section_name;
11636 obj_elf_section (ignore);
11639 input_line_pointer++;
11641 /* Do we have .section Name<,type><,flag><,entry_size><,alignment> */
11643 section_type = get_absolute_expression ();
11646 if (*input_line_pointer++ == ',')
11647 section_flag = get_absolute_expression ();
11650 if (*input_line_pointer++ == ',')
11651 section_entry_size = get_absolute_expression ();
11653 section_entry_size = 0;
11654 if (*input_line_pointer++ == ',')
11655 section_alignment = get_absolute_expression ();
11657 section_alignment = 0;
11659 section_name = xstrdup (section_name);
11661 /* When using the generic form of .section (as implemented by obj-elf.c),
11662 there's no way to set the section type to SHT_MIPS_DWARF. Users have
11663 traditionally had to fall back on the more common @progbits instead.
11665 There's nothing really harmful in this, since bfd will correct
11666 SHT_PROGBITS to SHT_MIPS_DWARF before writing out the file. But it
11667 means that, for backwards compatibiltiy, the special_section entries
11668 for dwarf sections must use SHT_PROGBITS rather than SHT_MIPS_DWARF.
11670 Even so, we shouldn't force users of the MIPS .section syntax to
11671 incorrectly label the sections as SHT_PROGBITS. The best compromise
11672 seems to be to map SHT_MIPS_DWARF to SHT_PROGBITS before calling the
11673 generic type-checking code. */
11674 if (section_type == SHT_MIPS_DWARF)
11675 section_type = SHT_PROGBITS;
11677 obj_elf_change_section (section_name, section_type, section_flag,
11678 section_entry_size, 0, 0, 0);
11680 if (now_seg->name != section_name)
11681 free (section_name);
11682 #endif /* OBJ_ELF */
11686 mips_enable_auto_align (void)
11692 s_cons (int log_size)
11696 label = insn_labels != NULL ? insn_labels->label : NULL;
11697 mips_emit_delays ();
11698 if (log_size > 0 && auto_align)
11699 mips_align (log_size, 0, label);
11700 mips_clear_insn_labels ();
11701 cons (1 << log_size);
11705 s_float_cons (int type)
11709 label = insn_labels != NULL ? insn_labels->label : NULL;
11711 mips_emit_delays ();
11716 mips_align (3, 0, label);
11718 mips_align (2, 0, label);
11721 mips_clear_insn_labels ();
11726 /* Handle .globl. We need to override it because on Irix 5 you are
11729 where foo is an undefined symbol, to mean that foo should be
11730 considered to be the address of a function. */
11733 s_mips_globl (int x ATTRIBUTE_UNUSED)
11742 name = input_line_pointer;
11743 c = get_symbol_end ();
11744 symbolP = symbol_find_or_make (name);
11745 S_SET_EXTERNAL (symbolP);
11747 *input_line_pointer = c;
11748 SKIP_WHITESPACE ();
11750 /* On Irix 5, every global symbol that is not explicitly labelled as
11751 being a function is apparently labelled as being an object. */
11754 if (!is_end_of_line[(unsigned char) *input_line_pointer]
11755 && (*input_line_pointer != ','))
11760 secname = input_line_pointer;
11761 c = get_symbol_end ();
11762 sec = bfd_get_section_by_name (stdoutput, secname);
11764 as_bad (_("%s: no such section"), secname);
11765 *input_line_pointer = c;
11767 if (sec != NULL && (sec->flags & SEC_CODE) != 0)
11768 flag = BSF_FUNCTION;
11771 symbol_get_bfdsym (symbolP)->flags |= flag;
11773 c = *input_line_pointer;
11776 input_line_pointer++;
11777 SKIP_WHITESPACE ();
11778 if (is_end_of_line[(unsigned char) *input_line_pointer])
11784 demand_empty_rest_of_line ();
11788 s_option (int x ATTRIBUTE_UNUSED)
11793 opt = input_line_pointer;
11794 c = get_symbol_end ();
11798 /* FIXME: What does this mean? */
11800 else if (strncmp (opt, "pic", 3) == 0)
11804 i = atoi (opt + 3);
11809 mips_pic = SVR4_PIC;
11810 mips_abicalls = TRUE;
11813 as_bad (_(".option pic%d not supported"), i);
11815 if (mips_pic == SVR4_PIC)
11817 if (g_switch_seen && g_switch_value != 0)
11818 as_warn (_("-G may not be used with SVR4 PIC code"));
11819 g_switch_value = 0;
11820 bfd_set_gp_size (stdoutput, 0);
11824 as_warn (_("Unrecognized option \"%s\""), opt);
11826 *input_line_pointer = c;
11827 demand_empty_rest_of_line ();
11830 /* This structure is used to hold a stack of .set values. */
11832 struct mips_option_stack
11834 struct mips_option_stack *next;
11835 struct mips_set_options options;
11838 static struct mips_option_stack *mips_opts_stack;
11840 /* Handle the .set pseudo-op. */
11843 s_mipsset (int x ATTRIBUTE_UNUSED)
11845 char *name = input_line_pointer, ch;
11847 while (!is_end_of_line[(unsigned char) *input_line_pointer])
11848 ++input_line_pointer;
11849 ch = *input_line_pointer;
11850 *input_line_pointer = '\0';
11852 if (strcmp (name, "reorder") == 0)
11854 if (mips_opts.noreorder)
11857 else if (strcmp (name, "noreorder") == 0)
11859 if (!mips_opts.noreorder)
11860 start_noreorder ();
11862 else if (strcmp (name, "at") == 0)
11864 mips_opts.noat = 0;
11866 else if (strcmp (name, "noat") == 0)
11868 mips_opts.noat = 1;
11870 else if (strcmp (name, "macro") == 0)
11872 mips_opts.warn_about_macros = 0;
11874 else if (strcmp (name, "nomacro") == 0)
11876 if (mips_opts.noreorder == 0)
11877 as_bad (_("`noreorder' must be set before `nomacro'"));
11878 mips_opts.warn_about_macros = 1;
11880 else if (strcmp (name, "move") == 0 || strcmp (name, "novolatile") == 0)
11882 mips_opts.nomove = 0;
11884 else if (strcmp (name, "nomove") == 0 || strcmp (name, "volatile") == 0)
11886 mips_opts.nomove = 1;
11888 else if (strcmp (name, "bopt") == 0)
11890 mips_opts.nobopt = 0;
11892 else if (strcmp (name, "nobopt") == 0)
11894 mips_opts.nobopt = 1;
11896 else if (strcmp (name, "mips16") == 0
11897 || strcmp (name, "MIPS-16") == 0)
11898 mips_opts.mips16 = 1;
11899 else if (strcmp (name, "nomips16") == 0
11900 || strcmp (name, "noMIPS-16") == 0)
11901 mips_opts.mips16 = 0;
11902 else if (strcmp (name, "mips3d") == 0)
11903 mips_opts.ase_mips3d = 1;
11904 else if (strcmp (name, "nomips3d") == 0)
11905 mips_opts.ase_mips3d = 0;
11906 else if (strcmp (name, "mdmx") == 0)
11907 mips_opts.ase_mdmx = 1;
11908 else if (strcmp (name, "nomdmx") == 0)
11909 mips_opts.ase_mdmx = 0;
11910 else if (strcmp (name, "dsp") == 0)
11911 mips_opts.ase_dsp = 1;
11912 else if (strcmp (name, "nodsp") == 0)
11913 mips_opts.ase_dsp = 0;
11914 else if (strcmp (name, "mt") == 0)
11915 mips_opts.ase_mt = 1;
11916 else if (strcmp (name, "nomt") == 0)
11917 mips_opts.ase_mt = 0;
11918 else if (strncmp (name, "mips", 4) == 0 || strncmp (name, "arch=", 5) == 0)
11922 /* Permit the user to change the ISA and architecture on the fly.
11923 Needless to say, misuse can cause serious problems. */
11924 if (strcmp (name, "mips0") == 0 || strcmp (name, "arch=default") == 0)
11927 mips_opts.isa = file_mips_isa;
11928 mips_opts.arch = file_mips_arch;
11930 else if (strncmp (name, "arch=", 5) == 0)
11932 const struct mips_cpu_info *p;
11934 p = mips_parse_cpu("internal use", name + 5);
11936 as_bad (_("unknown architecture %s"), name + 5);
11939 mips_opts.arch = p->cpu;
11940 mips_opts.isa = p->isa;
11943 else if (strncmp (name, "mips", 4) == 0)
11945 const struct mips_cpu_info *p;
11947 p = mips_parse_cpu("internal use", name);
11949 as_bad (_("unknown ISA level %s"), name + 4);
11952 mips_opts.arch = p->cpu;
11953 mips_opts.isa = p->isa;
11957 as_bad (_("unknown ISA or architecture %s"), name);
11959 switch (mips_opts.isa)
11967 mips_opts.gp32 = 1;
11968 mips_opts.fp32 = 1;
11975 mips_opts.gp32 = 0;
11976 mips_opts.fp32 = 0;
11979 as_bad (_("unknown ISA level %s"), name + 4);
11984 mips_opts.gp32 = file_mips_gp32;
11985 mips_opts.fp32 = file_mips_fp32;
11988 else if (strcmp (name, "autoextend") == 0)
11989 mips_opts.noautoextend = 0;
11990 else if (strcmp (name, "noautoextend") == 0)
11991 mips_opts.noautoextend = 1;
11992 else if (strcmp (name, "push") == 0)
11994 struct mips_option_stack *s;
11996 s = (struct mips_option_stack *) xmalloc (sizeof *s);
11997 s->next = mips_opts_stack;
11998 s->options = mips_opts;
11999 mips_opts_stack = s;
12001 else if (strcmp (name, "pop") == 0)
12003 struct mips_option_stack *s;
12005 s = mips_opts_stack;
12007 as_bad (_(".set pop with no .set push"));
12010 /* If we're changing the reorder mode we need to handle
12011 delay slots correctly. */
12012 if (s->options.noreorder && ! mips_opts.noreorder)
12013 start_noreorder ();
12014 else if (! s->options.noreorder && mips_opts.noreorder)
12017 mips_opts = s->options;
12018 mips_opts_stack = s->next;
12022 else if (strcmp (name, "sym32") == 0)
12023 mips_opts.sym32 = TRUE;
12024 else if (strcmp (name, "nosym32") == 0)
12025 mips_opts.sym32 = FALSE;
12028 as_warn (_("Tried to set unrecognized symbol: %s\n"), name);
12030 *input_line_pointer = ch;
12031 demand_empty_rest_of_line ();
12034 /* Handle the .abicalls pseudo-op. I believe this is equivalent to
12035 .option pic2. It means to generate SVR4 PIC calls. */
12038 s_abicalls (int ignore ATTRIBUTE_UNUSED)
12040 mips_pic = SVR4_PIC;
12041 mips_abicalls = TRUE;
12043 if (g_switch_seen && g_switch_value != 0)
12044 as_warn (_("-G may not be used with SVR4 PIC code"));
12045 g_switch_value = 0;
12047 bfd_set_gp_size (stdoutput, 0);
12048 demand_empty_rest_of_line ();
12051 /* Handle the .cpload pseudo-op. This is used when generating SVR4
12052 PIC code. It sets the $gp register for the function based on the
12053 function address, which is in the register named in the argument.
12054 This uses a relocation against _gp_disp, which is handled specially
12055 by the linker. The result is:
12056 lui $gp,%hi(_gp_disp)
12057 addiu $gp,$gp,%lo(_gp_disp)
12058 addu $gp,$gp,.cpload argument
12059 The .cpload argument is normally $25 == $t9.
12061 The -mno-shared option changes this to:
12062 lui $gp,%hi(__gnu_local_gp)
12063 addiu $gp,$gp,%lo(__gnu_local_gp)
12064 and the argument is ignored. This saves an instruction, but the
12065 resulting code is not position independent; it uses an absolute
12066 address for __gnu_local_gp. Thus code assembled with -mno-shared
12067 can go into an ordinary executable, but not into a shared library. */
12070 s_cpload (int ignore ATTRIBUTE_UNUSED)
12076 /* If we are not generating SVR4 PIC code, or if this is NewABI code,
12077 .cpload is ignored. */
12078 if (mips_pic != SVR4_PIC || HAVE_NEWABI)
12084 /* .cpload should be in a .set noreorder section. */
12085 if (mips_opts.noreorder == 0)
12086 as_warn (_(".cpload not in noreorder section"));
12088 reg = tc_get_register (0);
12090 /* If we need to produce a 64-bit address, we are better off using
12091 the default instruction sequence. */
12092 in_shared = mips_in_shared || HAVE_64BIT_SYMBOLS;
12094 ex.X_op = O_symbol;
12095 ex.X_add_symbol = symbol_find_or_make (in_shared ? "_gp_disp" :
12097 ex.X_op_symbol = NULL;
12098 ex.X_add_number = 0;
12100 /* In ELF, this symbol is implicitly an STT_OBJECT symbol. */
12101 symbol_get_bfdsym (ex.X_add_symbol)->flags |= BSF_OBJECT;
12104 macro_build_lui (&ex, mips_gp_register);
12105 macro_build (&ex, "addiu", "t,r,j", mips_gp_register,
12106 mips_gp_register, BFD_RELOC_LO16);
12108 macro_build (NULL, "addu", "d,v,t", mips_gp_register,
12109 mips_gp_register, reg);
12112 demand_empty_rest_of_line ();
12115 /* Handle the .cpsetup pseudo-op defined for NewABI PIC code. The syntax is:
12116 .cpsetup $reg1, offset|$reg2, label
12118 If offset is given, this results in:
12119 sd $gp, offset($sp)
12120 lui $gp, %hi(%neg(%gp_rel(label)))
12121 addiu $gp, $gp, %lo(%neg(%gp_rel(label)))
12122 daddu $gp, $gp, $reg1
12124 If $reg2 is given, this results in:
12125 daddu $reg2, $gp, $0
12126 lui $gp, %hi(%neg(%gp_rel(label)))
12127 addiu $gp, $gp, %lo(%neg(%gp_rel(label)))
12128 daddu $gp, $gp, $reg1
12129 $reg1 is normally $25 == $t9.
12131 The -mno-shared option replaces the last three instructions with
12133 addiu $gp,$gp,%lo(_gp)
12137 s_cpsetup (int ignore ATTRIBUTE_UNUSED)
12139 expressionS ex_off;
12140 expressionS ex_sym;
12143 /* If we are not generating SVR4 PIC code, .cpsetup is ignored.
12144 We also need NewABI support. */
12145 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
12151 reg1 = tc_get_register (0);
12152 SKIP_WHITESPACE ();
12153 if (*input_line_pointer != ',')
12155 as_bad (_("missing argument separator ',' for .cpsetup"));
12159 ++input_line_pointer;
12160 SKIP_WHITESPACE ();
12161 if (*input_line_pointer == '$')
12163 mips_cpreturn_register = tc_get_register (0);
12164 mips_cpreturn_offset = -1;
12168 mips_cpreturn_offset = get_absolute_expression ();
12169 mips_cpreturn_register = -1;
12171 SKIP_WHITESPACE ();
12172 if (*input_line_pointer != ',')
12174 as_bad (_("missing argument separator ',' for .cpsetup"));
12178 ++input_line_pointer;
12179 SKIP_WHITESPACE ();
12180 expression (&ex_sym);
12183 if (mips_cpreturn_register == -1)
12185 ex_off.X_op = O_constant;
12186 ex_off.X_add_symbol = NULL;
12187 ex_off.X_op_symbol = NULL;
12188 ex_off.X_add_number = mips_cpreturn_offset;
12190 macro_build (&ex_off, "sd", "t,o(b)", mips_gp_register,
12191 BFD_RELOC_LO16, SP);
12194 macro_build (NULL, "daddu", "d,v,t", mips_cpreturn_register,
12195 mips_gp_register, 0);
12197 if (mips_in_shared || HAVE_64BIT_SYMBOLS)
12199 macro_build (&ex_sym, "lui", "t,u", mips_gp_register,
12200 -1, BFD_RELOC_GPREL16, BFD_RELOC_MIPS_SUB,
12203 macro_build (&ex_sym, "addiu", "t,r,j", mips_gp_register,
12204 mips_gp_register, -1, BFD_RELOC_GPREL16,
12205 BFD_RELOC_MIPS_SUB, BFD_RELOC_LO16);
12207 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", mips_gp_register,
12208 mips_gp_register, reg1);
12214 ex.X_op = O_symbol;
12215 ex.X_add_symbol = symbol_find_or_make ("__gnu_local_gp");
12216 ex.X_op_symbol = NULL;
12217 ex.X_add_number = 0;
12219 /* In ELF, this symbol is implicitly an STT_OBJECT symbol. */
12220 symbol_get_bfdsym (ex.X_add_symbol)->flags |= BSF_OBJECT;
12222 macro_build_lui (&ex, mips_gp_register);
12223 macro_build (&ex, "addiu", "t,r,j", mips_gp_register,
12224 mips_gp_register, BFD_RELOC_LO16);
12229 demand_empty_rest_of_line ();
12233 s_cplocal (int ignore ATTRIBUTE_UNUSED)
12235 /* If we are not generating SVR4 PIC code, or if this is not NewABI code,
12236 .cplocal is ignored. */
12237 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
12243 mips_gp_register = tc_get_register (0);
12244 demand_empty_rest_of_line ();
12247 /* Handle the .cprestore pseudo-op. This stores $gp into a given
12248 offset from $sp. The offset is remembered, and after making a PIC
12249 call $gp is restored from that location. */
12252 s_cprestore (int ignore ATTRIBUTE_UNUSED)
12256 /* If we are not generating SVR4 PIC code, or if this is NewABI code,
12257 .cprestore is ignored. */
12258 if (mips_pic != SVR4_PIC || HAVE_NEWABI)
12264 mips_cprestore_offset = get_absolute_expression ();
12265 mips_cprestore_valid = 1;
12267 ex.X_op = O_constant;
12268 ex.X_add_symbol = NULL;
12269 ex.X_op_symbol = NULL;
12270 ex.X_add_number = mips_cprestore_offset;
12273 macro_build_ldst_constoffset (&ex, ADDRESS_STORE_INSN, mips_gp_register,
12274 SP, HAVE_64BIT_ADDRESSES);
12277 demand_empty_rest_of_line ();
12280 /* Handle the .cpreturn pseudo-op defined for NewABI PIC code. If an offset
12281 was given in the preceding .cpsetup, it results in:
12282 ld $gp, offset($sp)
12284 If a register $reg2 was given there, it results in:
12285 daddu $gp, $reg2, $0
12288 s_cpreturn (int ignore ATTRIBUTE_UNUSED)
12292 /* If we are not generating SVR4 PIC code, .cpreturn is ignored.
12293 We also need NewABI support. */
12294 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
12301 if (mips_cpreturn_register == -1)
12303 ex.X_op = O_constant;
12304 ex.X_add_symbol = NULL;
12305 ex.X_op_symbol = NULL;
12306 ex.X_add_number = mips_cpreturn_offset;
12308 macro_build (&ex, "ld", "t,o(b)", mips_gp_register, BFD_RELOC_LO16, SP);
12311 macro_build (NULL, "daddu", "d,v,t", mips_gp_register,
12312 mips_cpreturn_register, 0);
12315 demand_empty_rest_of_line ();
12318 /* Handle the .gpvalue pseudo-op. This is used when generating NewABI PIC
12319 code. It sets the offset to use in gp_rel relocations. */
12322 s_gpvalue (int ignore ATTRIBUTE_UNUSED)
12324 /* If we are not generating SVR4 PIC code, .gpvalue is ignored.
12325 We also need NewABI support. */
12326 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
12332 mips_gprel_offset = get_absolute_expression ();
12334 demand_empty_rest_of_line ();
12337 /* Handle the .gpword pseudo-op. This is used when generating PIC
12338 code. It generates a 32 bit GP relative reloc. */
12341 s_gpword (int ignore ATTRIBUTE_UNUSED)
12347 /* When not generating PIC code, this is treated as .word. */
12348 if (mips_pic != SVR4_PIC)
12354 label = insn_labels != NULL ? insn_labels->label : NULL;
12355 mips_emit_delays ();
12357 mips_align (2, 0, label);
12358 mips_clear_insn_labels ();
12362 if (ex.X_op != O_symbol || ex.X_add_number != 0)
12364 as_bad (_("Unsupported use of .gpword"));
12365 ignore_rest_of_line ();
12369 md_number_to_chars (p, 0, 4);
12370 fix_new_exp (frag_now, p - frag_now->fr_literal, 4, &ex, FALSE,
12371 BFD_RELOC_GPREL32);
12373 demand_empty_rest_of_line ();
12377 s_gpdword (int ignore ATTRIBUTE_UNUSED)
12383 /* When not generating PIC code, this is treated as .dword. */
12384 if (mips_pic != SVR4_PIC)
12390 label = insn_labels != NULL ? insn_labels->label : NULL;
12391 mips_emit_delays ();
12393 mips_align (3, 0, label);
12394 mips_clear_insn_labels ();
12398 if (ex.X_op != O_symbol || ex.X_add_number != 0)
12400 as_bad (_("Unsupported use of .gpdword"));
12401 ignore_rest_of_line ();
12405 md_number_to_chars (p, 0, 8);
12406 fix_new_exp (frag_now, p - frag_now->fr_literal, 4, &ex, FALSE,
12407 BFD_RELOC_GPREL32)->fx_tcbit = 1;
12409 /* GPREL32 composed with 64 gives a 64-bit GP offset. */
12410 fix_new (frag_now, p - frag_now->fr_literal, 8, NULL, 0,
12411 FALSE, BFD_RELOC_64)->fx_tcbit = 1;
12413 demand_empty_rest_of_line ();
12416 /* Handle the .cpadd pseudo-op. This is used when dealing with switch
12417 tables in SVR4 PIC code. */
12420 s_cpadd (int ignore ATTRIBUTE_UNUSED)
12424 /* This is ignored when not generating SVR4 PIC code. */
12425 if (mips_pic != SVR4_PIC)
12431 /* Add $gp to the register named as an argument. */
12433 reg = tc_get_register (0);
12434 macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", reg, reg, mips_gp_register);
12437 demand_empty_rest_of_line ();
12440 /* Handle the .insn pseudo-op. This marks instruction labels in
12441 mips16 mode. This permits the linker to handle them specially,
12442 such as generating jalx instructions when needed. We also make
12443 them odd for the duration of the assembly, in order to generate the
12444 right sort of code. We will make them even in the adjust_symtab
12445 routine, while leaving them marked. This is convenient for the
12446 debugger and the disassembler. The linker knows to make them odd
12450 s_insn (int ignore ATTRIBUTE_UNUSED)
12452 mips16_mark_labels ();
12454 demand_empty_rest_of_line ();
12457 /* Handle a .stabn directive. We need these in order to mark a label
12458 as being a mips16 text label correctly. Sometimes the compiler
12459 will emit a label, followed by a .stabn, and then switch sections.
12460 If the label and .stabn are in mips16 mode, then the label is
12461 really a mips16 text label. */
12464 s_mips_stab (int type)
12467 mips16_mark_labels ();
12472 /* Handle the .weakext pseudo-op as defined in Kane and Heinrich.
12476 s_mips_weakext (int ignore ATTRIBUTE_UNUSED)
12483 name = input_line_pointer;
12484 c = get_symbol_end ();
12485 symbolP = symbol_find_or_make (name);
12486 S_SET_WEAK (symbolP);
12487 *input_line_pointer = c;
12489 SKIP_WHITESPACE ();
12491 if (! is_end_of_line[(unsigned char) *input_line_pointer])
12493 if (S_IS_DEFINED (symbolP))
12495 as_bad ("ignoring attempt to redefine symbol %s",
12496 S_GET_NAME (symbolP));
12497 ignore_rest_of_line ();
12501 if (*input_line_pointer == ',')
12503 ++input_line_pointer;
12504 SKIP_WHITESPACE ();
12508 if (exp.X_op != O_symbol)
12510 as_bad ("bad .weakext directive");
12511 ignore_rest_of_line ();
12514 symbol_set_value_expression (symbolP, &exp);
12517 demand_empty_rest_of_line ();
12520 /* Parse a register string into a number. Called from the ECOFF code
12521 to parse .frame. The argument is non-zero if this is the frame
12522 register, so that we can record it in mips_frame_reg. */
12525 tc_get_register (int frame)
12529 SKIP_WHITESPACE ();
12530 if (*input_line_pointer++ != '$')
12532 as_warn (_("expected `$'"));
12535 else if (ISDIGIT (*input_line_pointer))
12537 reg = get_absolute_expression ();
12538 if (reg < 0 || reg >= 32)
12540 as_warn (_("Bad register number"));
12546 if (strncmp (input_line_pointer, "ra", 2) == 0)
12549 input_line_pointer += 2;
12551 else if (strncmp (input_line_pointer, "fp", 2) == 0)
12554 input_line_pointer += 2;
12556 else if (strncmp (input_line_pointer, "sp", 2) == 0)
12559 input_line_pointer += 2;
12561 else if (strncmp (input_line_pointer, "gp", 2) == 0)
12564 input_line_pointer += 2;
12566 else if (strncmp (input_line_pointer, "at", 2) == 0)
12569 input_line_pointer += 2;
12571 else if (strncmp (input_line_pointer, "kt0", 3) == 0)
12574 input_line_pointer += 3;
12576 else if (strncmp (input_line_pointer, "kt1", 3) == 0)
12579 input_line_pointer += 3;
12581 else if (strncmp (input_line_pointer, "zero", 4) == 0)
12584 input_line_pointer += 4;
12588 as_warn (_("Unrecognized register name"));
12590 while (ISALNUM(*input_line_pointer))
12591 input_line_pointer++;
12596 mips_frame_reg = reg != 0 ? reg : SP;
12597 mips_frame_reg_valid = 1;
12598 mips_cprestore_valid = 0;
12604 md_section_align (asection *seg, valueT addr)
12606 int align = bfd_get_section_alignment (stdoutput, seg);
12609 /* We don't need to align ELF sections to the full alignment.
12610 However, Irix 5 may prefer that we align them at least to a 16
12611 byte boundary. We don't bother to align the sections if we are
12612 targeted for an embedded system. */
12613 if (strcmp (TARGET_OS, "elf") == 0)
12619 return ((addr + (1 << align) - 1) & (-1 << align));
12622 /* Utility routine, called from above as well. If called while the
12623 input file is still being read, it's only an approximation. (For
12624 example, a symbol may later become defined which appeared to be
12625 undefined earlier.) */
12628 nopic_need_relax (symbolS *sym, int before_relaxing)
12633 if (g_switch_value > 0)
12635 const char *symname;
12638 /* Find out whether this symbol can be referenced off the $gp
12639 register. It can be if it is smaller than the -G size or if
12640 it is in the .sdata or .sbss section. Certain symbols can
12641 not be referenced off the $gp, although it appears as though
12643 symname = S_GET_NAME (sym);
12644 if (symname != (const char *) NULL
12645 && (strcmp (symname, "eprol") == 0
12646 || strcmp (symname, "etext") == 0
12647 || strcmp (symname, "_gp") == 0
12648 || strcmp (symname, "edata") == 0
12649 || strcmp (symname, "_fbss") == 0
12650 || strcmp (symname, "_fdata") == 0
12651 || strcmp (symname, "_ftext") == 0
12652 || strcmp (symname, "end") == 0
12653 || strcmp (symname, "_gp_disp") == 0))
12655 else if ((! S_IS_DEFINED (sym) || S_IS_COMMON (sym))
12657 #ifndef NO_ECOFF_DEBUGGING
12658 || (symbol_get_obj (sym)->ecoff_extern_size != 0
12659 && (symbol_get_obj (sym)->ecoff_extern_size
12660 <= g_switch_value))
12662 /* We must defer this decision until after the whole
12663 file has been read, since there might be a .extern
12664 after the first use of this symbol. */
12665 || (before_relaxing
12666 #ifndef NO_ECOFF_DEBUGGING
12667 && symbol_get_obj (sym)->ecoff_extern_size == 0
12669 && S_GET_VALUE (sym) == 0)
12670 || (S_GET_VALUE (sym) != 0
12671 && S_GET_VALUE (sym) <= g_switch_value)))
12675 const char *segname;
12677 segname = segment_name (S_GET_SEGMENT (sym));
12678 assert (strcmp (segname, ".lit8") != 0
12679 && strcmp (segname, ".lit4") != 0);
12680 change = (strcmp (segname, ".sdata") != 0
12681 && strcmp (segname, ".sbss") != 0
12682 && strncmp (segname, ".sdata.", 7) != 0
12683 && strncmp (segname, ".gnu.linkonce.s.", 16) != 0);
12688 /* We are not optimizing for the $gp register. */
12693 /* Return true if the given symbol should be considered local for SVR4 PIC. */
12696 pic_need_relax (symbolS *sym, asection *segtype)
12699 bfd_boolean linkonce;
12701 /* Handle the case of a symbol equated to another symbol. */
12702 while (symbol_equated_reloc_p (sym))
12706 /* It's possible to get a loop here in a badly written
12708 n = symbol_get_value_expression (sym)->X_add_symbol;
12714 symsec = S_GET_SEGMENT (sym);
12716 /* duplicate the test for LINK_ONCE sections as in adjust_reloc_syms */
12718 if (symsec != segtype && ! S_IS_LOCAL (sym))
12720 if ((bfd_get_section_flags (stdoutput, symsec) & SEC_LINK_ONCE)
12724 /* The GNU toolchain uses an extension for ELF: a section
12725 beginning with the magic string .gnu.linkonce is a linkonce
12727 if (strncmp (segment_name (symsec), ".gnu.linkonce",
12728 sizeof ".gnu.linkonce" - 1) == 0)
12732 /* This must duplicate the test in adjust_reloc_syms. */
12733 return (symsec != &bfd_und_section
12734 && symsec != &bfd_abs_section
12735 && ! bfd_is_com_section (symsec)
12738 /* A global or weak symbol is treated as external. */
12739 && (OUTPUT_FLAVOR != bfd_target_elf_flavour
12740 || (! S_IS_WEAK (sym) && ! S_IS_EXTERNAL (sym)))
12746 /* Given a mips16 variant frag FRAGP, return non-zero if it needs an
12747 extended opcode. SEC is the section the frag is in. */
12750 mips16_extended_frag (fragS *fragp, asection *sec, long stretch)
12753 register const struct mips16_immed_operand *op;
12755 int mintiny, maxtiny;
12759 if (RELAX_MIPS16_USER_SMALL (fragp->fr_subtype))
12761 if (RELAX_MIPS16_USER_EXT (fragp->fr_subtype))
12764 type = RELAX_MIPS16_TYPE (fragp->fr_subtype);
12765 op = mips16_immed_operands;
12766 while (op->type != type)
12769 assert (op < mips16_immed_operands + MIPS16_NUM_IMMED);
12774 if (type == '<' || type == '>' || type == '[' || type == ']')
12777 maxtiny = 1 << op->nbits;
12782 maxtiny = (1 << op->nbits) - 1;
12787 mintiny = - (1 << (op->nbits - 1));
12788 maxtiny = (1 << (op->nbits - 1)) - 1;
12791 sym_frag = symbol_get_frag (fragp->fr_symbol);
12792 val = S_GET_VALUE (fragp->fr_symbol);
12793 symsec = S_GET_SEGMENT (fragp->fr_symbol);
12799 /* We won't have the section when we are called from
12800 mips_relax_frag. However, we will always have been called
12801 from md_estimate_size_before_relax first. If this is a
12802 branch to a different section, we mark it as such. If SEC is
12803 NULL, and the frag is not marked, then it must be a branch to
12804 the same section. */
12807 if (RELAX_MIPS16_LONG_BRANCH (fragp->fr_subtype))
12812 /* Must have been called from md_estimate_size_before_relax. */
12815 fragp->fr_subtype =
12816 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
12818 /* FIXME: We should support this, and let the linker
12819 catch branches and loads that are out of range. */
12820 as_bad_where (fragp->fr_file, fragp->fr_line,
12821 _("unsupported PC relative reference to different section"));
12825 if (fragp != sym_frag && sym_frag->fr_address == 0)
12826 /* Assume non-extended on the first relaxation pass.
12827 The address we have calculated will be bogus if this is
12828 a forward branch to another frag, as the forward frag
12829 will have fr_address == 0. */
12833 /* In this case, we know for sure that the symbol fragment is in
12834 the same section. If the relax_marker of the symbol fragment
12835 differs from the relax_marker of this fragment, we have not
12836 yet adjusted the symbol fragment fr_address. We want to add
12837 in STRETCH in order to get a better estimate of the address.
12838 This particularly matters because of the shift bits. */
12840 && sym_frag->relax_marker != fragp->relax_marker)
12844 /* Adjust stretch for any alignment frag. Note that if have
12845 been expanding the earlier code, the symbol may be
12846 defined in what appears to be an earlier frag. FIXME:
12847 This doesn't handle the fr_subtype field, which specifies
12848 a maximum number of bytes to skip when doing an
12850 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
12852 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
12855 stretch = - ((- stretch)
12856 & ~ ((1 << (int) f->fr_offset) - 1));
12858 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
12867 addr = fragp->fr_address + fragp->fr_fix;
12869 /* The base address rules are complicated. The base address of
12870 a branch is the following instruction. The base address of a
12871 PC relative load or add is the instruction itself, but if it
12872 is in a delay slot (in which case it can not be extended) use
12873 the address of the instruction whose delay slot it is in. */
12874 if (type == 'p' || type == 'q')
12878 /* If we are currently assuming that this frag should be
12879 extended, then, the current address is two bytes
12881 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
12884 /* Ignore the low bit in the target, since it will be set
12885 for a text label. */
12886 if ((val & 1) != 0)
12889 else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype))
12891 else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype))
12894 val -= addr & ~ ((1 << op->shift) - 1);
12896 /* Branch offsets have an implicit 0 in the lowest bit. */
12897 if (type == 'p' || type == 'q')
12900 /* If any of the shifted bits are set, we must use an extended
12901 opcode. If the address depends on the size of this
12902 instruction, this can lead to a loop, so we arrange to always
12903 use an extended opcode. We only check this when we are in
12904 the main relaxation loop, when SEC is NULL. */
12905 if ((val & ((1 << op->shift) - 1)) != 0 && sec == NULL)
12907 fragp->fr_subtype =
12908 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
12912 /* If we are about to mark a frag as extended because the value
12913 is precisely maxtiny + 1, then there is a chance of an
12914 infinite loop as in the following code:
12919 In this case when the la is extended, foo is 0x3fc bytes
12920 away, so the la can be shrunk, but then foo is 0x400 away, so
12921 the la must be extended. To avoid this loop, we mark the
12922 frag as extended if it was small, and is about to become
12923 extended with a value of maxtiny + 1. */
12924 if (val == ((maxtiny + 1) << op->shift)
12925 && ! RELAX_MIPS16_EXTENDED (fragp->fr_subtype)
12928 fragp->fr_subtype =
12929 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
12933 else if (symsec != absolute_section && sec != NULL)
12934 as_bad_where (fragp->fr_file, fragp->fr_line, _("unsupported relocation"));
12936 if ((val & ((1 << op->shift) - 1)) != 0
12937 || val < (mintiny << op->shift)
12938 || val > (maxtiny << op->shift))
12944 /* Compute the length of a branch sequence, and adjust the
12945 RELAX_BRANCH_TOOFAR bit accordingly. If FRAGP is NULL, the
12946 worst-case length is computed, with UPDATE being used to indicate
12947 whether an unconditional (-1), branch-likely (+1) or regular (0)
12948 branch is to be computed. */
12950 relaxed_branch_length (fragS *fragp, asection *sec, int update)
12952 bfd_boolean toofar;
12956 && S_IS_DEFINED (fragp->fr_symbol)
12957 && sec == S_GET_SEGMENT (fragp->fr_symbol))
12962 val = S_GET_VALUE (fragp->fr_symbol) + fragp->fr_offset;
12964 addr = fragp->fr_address + fragp->fr_fix + 4;
12968 toofar = val < - (0x8000 << 2) || val >= (0x8000 << 2);
12971 /* If the symbol is not defined or it's in a different segment,
12972 assume the user knows what's going on and emit a short
12978 if (fragp && update && toofar != RELAX_BRANCH_TOOFAR (fragp->fr_subtype))
12980 = RELAX_BRANCH_ENCODE (RELAX_BRANCH_UNCOND (fragp->fr_subtype),
12981 RELAX_BRANCH_LIKELY (fragp->fr_subtype),
12982 RELAX_BRANCH_LINK (fragp->fr_subtype),
12988 if (fragp ? RELAX_BRANCH_LIKELY (fragp->fr_subtype) : (update > 0))
12991 if (mips_pic != NO_PIC)
12993 /* Additional space for PIC loading of target address. */
12995 if (mips_opts.isa == ISA_MIPS1)
12996 /* Additional space for $at-stabilizing nop. */
13000 /* If branch is conditional. */
13001 if (fragp ? !RELAX_BRANCH_UNCOND (fragp->fr_subtype) : (update >= 0))
13008 /* Estimate the size of a frag before relaxing. Unless this is the
13009 mips16, we are not really relaxing here, and the final size is
13010 encoded in the subtype information. For the mips16, we have to
13011 decide whether we are using an extended opcode or not. */
13014 md_estimate_size_before_relax (fragS *fragp, asection *segtype)
13018 if (RELAX_BRANCH_P (fragp->fr_subtype))
13021 fragp->fr_var = relaxed_branch_length (fragp, segtype, FALSE);
13023 return fragp->fr_var;
13026 if (RELAX_MIPS16_P (fragp->fr_subtype))
13027 /* We don't want to modify the EXTENDED bit here; it might get us
13028 into infinite loops. We change it only in mips_relax_frag(). */
13029 return (RELAX_MIPS16_EXTENDED (fragp->fr_subtype) ? 4 : 2);
13031 if (mips_pic == NO_PIC)
13032 change = nopic_need_relax (fragp->fr_symbol, 0);
13033 else if (mips_pic == SVR4_PIC)
13034 change = pic_need_relax (fragp->fr_symbol, segtype);
13040 fragp->fr_subtype |= RELAX_USE_SECOND;
13041 return -RELAX_FIRST (fragp->fr_subtype);
13044 return -RELAX_SECOND (fragp->fr_subtype);
13047 /* This is called to see whether a reloc against a defined symbol
13048 should be converted into a reloc against a section. */
13051 mips_fix_adjustable (fixS *fixp)
13053 /* Don't adjust MIPS16 jump relocations, so we don't have to worry
13054 about the format of the offset in the .o file. */
13055 if (fixp->fx_r_type == BFD_RELOC_MIPS16_JMP)
13058 if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT
13059 || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
13062 if (fixp->fx_addsy == NULL)
13065 /* If symbol SYM is in a mergeable section, relocations of the form
13066 SYM + 0 can usually be made section-relative. The mergeable data
13067 is then identified by the section offset rather than by the symbol.
13069 However, if we're generating REL LO16 relocations, the offset is split
13070 between the LO16 and parterning high part relocation. The linker will
13071 need to recalculate the complete offset in order to correctly identify
13074 The linker has traditionally not looked for the parterning high part
13075 relocation, and has thus allowed orphaned R_MIPS_LO16 relocations to be
13076 placed anywhere. Rather than break backwards compatibility by changing
13077 this, it seems better not to force the issue, and instead keep the
13078 original symbol. This will work with either linker behavior. */
13079 if ((fixp->fx_r_type == BFD_RELOC_LO16
13080 || fixp->fx_r_type == BFD_RELOC_MIPS16_LO16
13081 || reloc_needs_lo_p (fixp->fx_r_type))
13082 && HAVE_IN_PLACE_ADDENDS
13083 && (S_GET_SEGMENT (fixp->fx_addsy)->flags & SEC_MERGE) != 0)
13087 /* Don't adjust relocations against mips16 symbols, so that the linker
13088 can find them if it needs to set up a stub. */
13089 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
13090 && S_GET_OTHER (fixp->fx_addsy) == STO_MIPS16
13091 && fixp->fx_subsy == NULL)
13098 /* Translate internal representation of relocation info to BFD target
13102 tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixp)
13104 static arelent *retval[4];
13106 bfd_reloc_code_real_type code;
13108 memset (retval, 0, sizeof(retval));
13109 reloc = retval[0] = (arelent *) xcalloc (1, sizeof (arelent));
13110 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
13111 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
13112 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
13114 assert (! fixp->fx_pcrel);
13115 reloc->addend = fixp->fx_addnumber;
13117 /* Since the old MIPS ELF ABI uses Rel instead of Rela, encode the vtable
13118 entry to be used in the relocation's section offset. */
13119 if (! HAVE_NEWABI && fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
13121 reloc->address = reloc->addend;
13125 code = fixp->fx_r_type;
13127 /* To support a PC relative reloc, we used a Cygnus extension.
13128 We check for that here to make sure that we don't let such a
13129 reloc escape normally. (FIXME: This was formerly used by
13130 embedded-PIC support, but is now used by branch handling in
13131 general. That probably should be fixed.) */
13132 if ((OUTPUT_FLAVOR == bfd_target_ecoff_flavour
13133 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
13134 && code == BFD_RELOC_16_PCREL_S2)
13135 reloc->howto = NULL;
13137 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
13139 if (reloc->howto == NULL)
13141 as_bad_where (fixp->fx_file, fixp->fx_line,
13142 _("Can not represent %s relocation in this object file format"),
13143 bfd_get_reloc_code_name (code));
13150 /* Relax a machine dependent frag. This returns the amount by which
13151 the current size of the frag should change. */
13154 mips_relax_frag (asection *sec, fragS *fragp, long stretch)
13156 if (RELAX_BRANCH_P (fragp->fr_subtype))
13158 offsetT old_var = fragp->fr_var;
13160 fragp->fr_var = relaxed_branch_length (fragp, sec, TRUE);
13162 return fragp->fr_var - old_var;
13165 if (! RELAX_MIPS16_P (fragp->fr_subtype))
13168 if (mips16_extended_frag (fragp, NULL, stretch))
13170 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
13172 fragp->fr_subtype = RELAX_MIPS16_MARK_EXTENDED (fragp->fr_subtype);
13177 if (! RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
13179 fragp->fr_subtype = RELAX_MIPS16_CLEAR_EXTENDED (fragp->fr_subtype);
13186 /* Convert a machine dependent frag. */
13189 md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, segT asec, fragS *fragp)
13191 if (RELAX_BRANCH_P (fragp->fr_subtype))
13194 unsigned long insn;
13198 buf = (bfd_byte *)fragp->fr_literal + fragp->fr_fix;
13200 if (target_big_endian)
13201 insn = bfd_getb32 (buf);
13203 insn = bfd_getl32 (buf);
13205 if (!RELAX_BRANCH_TOOFAR (fragp->fr_subtype))
13207 /* We generate a fixup instead of applying it right now
13208 because, if there are linker relaxations, we're going to
13209 need the relocations. */
13210 exp.X_op = O_symbol;
13211 exp.X_add_symbol = fragp->fr_symbol;
13212 exp.X_add_number = fragp->fr_offset;
13214 fixp = fix_new_exp (fragp, buf - (bfd_byte *)fragp->fr_literal,
13216 BFD_RELOC_16_PCREL_S2);
13217 fixp->fx_file = fragp->fr_file;
13218 fixp->fx_line = fragp->fr_line;
13220 md_number_to_chars ((char *) buf, insn, 4);
13227 as_warn_where (fragp->fr_file, fragp->fr_line,
13228 _("relaxed out-of-range branch into a jump"));
13230 if (RELAX_BRANCH_UNCOND (fragp->fr_subtype))
13233 if (!RELAX_BRANCH_LIKELY (fragp->fr_subtype))
13235 /* Reverse the branch. */
13236 switch ((insn >> 28) & 0xf)
13239 /* bc[0-3][tf]l? and bc1any[24][ft] instructions can
13240 have the condition reversed by tweaking a single
13241 bit, and their opcodes all have 0x4???????. */
13242 assert ((insn & 0xf1000000) == 0x41000000);
13243 insn ^= 0x00010000;
13247 /* bltz 0x04000000 bgez 0x04010000
13248 bltzal 0x04100000 bgezal 0x04110000 */
13249 assert ((insn & 0xfc0e0000) == 0x04000000);
13250 insn ^= 0x00010000;
13254 /* beq 0x10000000 bne 0x14000000
13255 blez 0x18000000 bgtz 0x1c000000 */
13256 insn ^= 0x04000000;
13264 if (RELAX_BRANCH_LINK (fragp->fr_subtype))
13266 /* Clear the and-link bit. */
13267 assert ((insn & 0xfc1c0000) == 0x04100000);
13269 /* bltzal 0x04100000 bgezal 0x04110000
13270 bltzall 0x04120000 bgezall 0x04130000 */
13271 insn &= ~0x00100000;
13274 /* Branch over the branch (if the branch was likely) or the
13275 full jump (not likely case). Compute the offset from the
13276 current instruction to branch to. */
13277 if (RELAX_BRANCH_LIKELY (fragp->fr_subtype))
13281 /* How many bytes in instructions we've already emitted? */
13282 i = buf - (bfd_byte *)fragp->fr_literal - fragp->fr_fix;
13283 /* How many bytes in instructions from here to the end? */
13284 i = fragp->fr_var - i;
13286 /* Convert to instruction count. */
13288 /* Branch counts from the next instruction. */
13291 /* Branch over the jump. */
13292 md_number_to_chars ((char *) buf, insn, 4);
13296 md_number_to_chars ((char *) buf, 0, 4);
13299 if (RELAX_BRANCH_LIKELY (fragp->fr_subtype))
13301 /* beql $0, $0, 2f */
13303 /* Compute the PC offset from the current instruction to
13304 the end of the variable frag. */
13305 /* How many bytes in instructions we've already emitted? */
13306 i = buf - (bfd_byte *)fragp->fr_literal - fragp->fr_fix;
13307 /* How many bytes in instructions from here to the end? */
13308 i = fragp->fr_var - i;
13309 /* Convert to instruction count. */
13311 /* Don't decrement i, because we want to branch over the
13315 md_number_to_chars ((char *) buf, insn, 4);
13318 md_number_to_chars ((char *) buf, 0, 4);
13323 if (mips_pic == NO_PIC)
13326 insn = (RELAX_BRANCH_LINK (fragp->fr_subtype)
13327 ? 0x0c000000 : 0x08000000);
13328 exp.X_op = O_symbol;
13329 exp.X_add_symbol = fragp->fr_symbol;
13330 exp.X_add_number = fragp->fr_offset;
13332 fixp = fix_new_exp (fragp, buf - (bfd_byte *)fragp->fr_literal,
13333 4, &exp, 0, BFD_RELOC_MIPS_JMP);
13334 fixp->fx_file = fragp->fr_file;
13335 fixp->fx_line = fragp->fr_line;
13337 md_number_to_chars ((char *) buf, insn, 4);
13342 /* lw/ld $at, <sym>($gp) R_MIPS_GOT16 */
13343 insn = HAVE_64BIT_ADDRESSES ? 0xdf810000 : 0x8f810000;
13344 exp.X_op = O_symbol;
13345 exp.X_add_symbol = fragp->fr_symbol;
13346 exp.X_add_number = fragp->fr_offset;
13348 if (fragp->fr_offset)
13350 exp.X_add_symbol = make_expr_symbol (&exp);
13351 exp.X_add_number = 0;
13354 fixp = fix_new_exp (fragp, buf - (bfd_byte *)fragp->fr_literal,
13355 4, &exp, 0, BFD_RELOC_MIPS_GOT16);
13356 fixp->fx_file = fragp->fr_file;
13357 fixp->fx_line = fragp->fr_line;
13359 md_number_to_chars ((char *) buf, insn, 4);
13362 if (mips_opts.isa == ISA_MIPS1)
13365 md_number_to_chars ((char *) buf, 0, 4);
13369 /* d/addiu $at, $at, <sym> R_MIPS_LO16 */
13370 insn = HAVE_64BIT_ADDRESSES ? 0x64210000 : 0x24210000;
13372 fixp = fix_new_exp (fragp, buf - (bfd_byte *)fragp->fr_literal,
13373 4, &exp, 0, BFD_RELOC_LO16);
13374 fixp->fx_file = fragp->fr_file;
13375 fixp->fx_line = fragp->fr_line;
13377 md_number_to_chars ((char *) buf, insn, 4);
13381 if (RELAX_BRANCH_LINK (fragp->fr_subtype))
13386 md_number_to_chars ((char *) buf, insn, 4);
13391 assert (buf == (bfd_byte *)fragp->fr_literal
13392 + fragp->fr_fix + fragp->fr_var);
13394 fragp->fr_fix += fragp->fr_var;
13399 if (RELAX_MIPS16_P (fragp->fr_subtype))
13402 register const struct mips16_immed_operand *op;
13403 bfd_boolean small, ext;
13406 unsigned long insn;
13407 bfd_boolean use_extend;
13408 unsigned short extend;
13410 type = RELAX_MIPS16_TYPE (fragp->fr_subtype);
13411 op = mips16_immed_operands;
13412 while (op->type != type)
13415 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
13426 resolve_symbol_value (fragp->fr_symbol);
13427 val = S_GET_VALUE (fragp->fr_symbol);
13432 addr = fragp->fr_address + fragp->fr_fix;
13434 /* The rules for the base address of a PC relative reloc are
13435 complicated; see mips16_extended_frag. */
13436 if (type == 'p' || type == 'q')
13441 /* Ignore the low bit in the target, since it will be
13442 set for a text label. */
13443 if ((val & 1) != 0)
13446 else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype))
13448 else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype))
13451 addr &= ~ (addressT) ((1 << op->shift) - 1);
13454 /* Make sure the section winds up with the alignment we have
13457 record_alignment (asec, op->shift);
13461 && (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype)
13462 || RELAX_MIPS16_DSLOT (fragp->fr_subtype)))
13463 as_warn_where (fragp->fr_file, fragp->fr_line,
13464 _("extended instruction in delay slot"));
13466 buf = (bfd_byte *) (fragp->fr_literal + fragp->fr_fix);
13468 if (target_big_endian)
13469 insn = bfd_getb16 (buf);
13471 insn = bfd_getl16 (buf);
13473 mips16_immed (fragp->fr_file, fragp->fr_line, type, val,
13474 RELAX_MIPS16_USER_EXT (fragp->fr_subtype),
13475 small, ext, &insn, &use_extend, &extend);
13479 md_number_to_chars ((char *) buf, 0xf000 | extend, 2);
13480 fragp->fr_fix += 2;
13484 md_number_to_chars ((char *) buf, insn, 2);
13485 fragp->fr_fix += 2;
13493 first = RELAX_FIRST (fragp->fr_subtype);
13494 second = RELAX_SECOND (fragp->fr_subtype);
13495 fixp = (fixS *) fragp->fr_opcode;
13497 /* Possibly emit a warning if we've chosen the longer option. */
13498 if (((fragp->fr_subtype & RELAX_USE_SECOND) != 0)
13499 == ((fragp->fr_subtype & RELAX_SECOND_LONGER) != 0))
13501 const char *msg = macro_warning (fragp->fr_subtype);
13503 as_warn_where (fragp->fr_file, fragp->fr_line, msg);
13506 /* Go through all the fixups for the first sequence. Disable them
13507 (by marking them as done) if we're going to use the second
13508 sequence instead. */
13510 && fixp->fx_frag == fragp
13511 && fixp->fx_where < fragp->fr_fix - second)
13513 if (fragp->fr_subtype & RELAX_USE_SECOND)
13515 fixp = fixp->fx_next;
13518 /* Go through the fixups for the second sequence. Disable them if
13519 we're going to use the first sequence, otherwise adjust their
13520 addresses to account for the relaxation. */
13521 while (fixp && fixp->fx_frag == fragp)
13523 if (fragp->fr_subtype & RELAX_USE_SECOND)
13524 fixp->fx_where -= first;
13527 fixp = fixp->fx_next;
13530 /* Now modify the frag contents. */
13531 if (fragp->fr_subtype & RELAX_USE_SECOND)
13535 start = fragp->fr_literal + fragp->fr_fix - first - second;
13536 memmove (start, start + first, second);
13537 fragp->fr_fix -= first;
13540 fragp->fr_fix -= second;
13546 /* This function is called after the relocs have been generated.
13547 We've been storing mips16 text labels as odd. Here we convert them
13548 back to even for the convenience of the debugger. */
13551 mips_frob_file_after_relocs (void)
13554 unsigned int count, i;
13556 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
13559 syms = bfd_get_outsymbols (stdoutput);
13560 count = bfd_get_symcount (stdoutput);
13561 for (i = 0; i < count; i++, syms++)
13563 if (elf_symbol (*syms)->internal_elf_sym.st_other == STO_MIPS16
13564 && ((*syms)->value & 1) != 0)
13566 (*syms)->value &= ~1;
13567 /* If the symbol has an odd size, it was probably computed
13568 incorrectly, so adjust that as well. */
13569 if ((elf_symbol (*syms)->internal_elf_sym.st_size & 1) != 0)
13570 ++elf_symbol (*syms)->internal_elf_sym.st_size;
13577 /* This function is called whenever a label is defined. It is used
13578 when handling branch delays; if a branch has a label, we assume we
13579 can not move it. */
13582 mips_define_label (symbolS *sym)
13584 struct insn_label_list *l;
13586 if (free_insn_labels == NULL)
13587 l = (struct insn_label_list *) xmalloc (sizeof *l);
13590 l = free_insn_labels;
13591 free_insn_labels = l->next;
13595 l->next = insn_labels;
13599 dwarf2_emit_label (sym);
13603 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
13605 /* Some special processing for a MIPS ELF file. */
13608 mips_elf_final_processing (void)
13610 /* Write out the register information. */
13611 if (mips_abi != N64_ABI)
13615 s.ri_gprmask = mips_gprmask;
13616 s.ri_cprmask[0] = mips_cprmask[0];
13617 s.ri_cprmask[1] = mips_cprmask[1];
13618 s.ri_cprmask[2] = mips_cprmask[2];
13619 s.ri_cprmask[3] = mips_cprmask[3];
13620 /* The gp_value field is set by the MIPS ELF backend. */
13622 bfd_mips_elf32_swap_reginfo_out (stdoutput, &s,
13623 ((Elf32_External_RegInfo *)
13624 mips_regmask_frag));
13628 Elf64_Internal_RegInfo s;
13630 s.ri_gprmask = mips_gprmask;
13632 s.ri_cprmask[0] = mips_cprmask[0];
13633 s.ri_cprmask[1] = mips_cprmask[1];
13634 s.ri_cprmask[2] = mips_cprmask[2];
13635 s.ri_cprmask[3] = mips_cprmask[3];
13636 /* The gp_value field is set by the MIPS ELF backend. */
13638 bfd_mips_elf64_swap_reginfo_out (stdoutput, &s,
13639 ((Elf64_External_RegInfo *)
13640 mips_regmask_frag));
13643 /* Set the MIPS ELF flag bits. FIXME: There should probably be some
13644 sort of BFD interface for this. */
13645 if (mips_any_noreorder)
13646 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_NOREORDER;
13647 if (mips_pic != NO_PIC)
13649 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_PIC;
13650 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_CPIC;
13653 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_CPIC;
13655 /* Set MIPS ELF flags for ASEs. */
13656 /* We may need to define a new flag for DSP ASE, and set this flag when
13657 file_ase_dsp is true. */
13658 /* We may need to define a new flag for MT ASE, and set this flag when
13659 file_ase_mt is true. */
13660 if (file_ase_mips16)
13661 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ARCH_ASE_M16;
13662 #if 0 /* XXX FIXME */
13663 if (file_ase_mips3d)
13664 elf_elfheader (stdoutput)->e_flags |= ???;
13667 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ARCH_ASE_MDMX;
13669 /* Set the MIPS ELF ABI flags. */
13670 if (mips_abi == O32_ABI && USE_E_MIPS_ABI_O32)
13671 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O32;
13672 else if (mips_abi == O64_ABI)
13673 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O64;
13674 else if (mips_abi == EABI_ABI)
13676 if (!file_mips_gp32)
13677 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI64;
13679 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI32;
13681 else if (mips_abi == N32_ABI)
13682 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ABI2;
13684 /* Nothing to do for N64_ABI. */
13686 if (mips_32bitmode)
13687 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_32BITMODE;
13690 #endif /* OBJ_ELF || OBJ_MAYBE_ELF */
13692 typedef struct proc {
13694 symbolS *func_end_sym;
13695 unsigned long reg_mask;
13696 unsigned long reg_offset;
13697 unsigned long fpreg_mask;
13698 unsigned long fpreg_offset;
13699 unsigned long frame_offset;
13700 unsigned long frame_reg;
13701 unsigned long pc_reg;
13704 static procS cur_proc;
13705 static procS *cur_proc_ptr;
13706 static int numprocs;
13708 /* Fill in an rs_align_code fragment. */
13711 mips_handle_align (fragS *fragp)
13713 if (fragp->fr_type != rs_align_code)
13716 if (mips_opts.mips16)
13718 static const unsigned char be_nop[] = { 0x65, 0x00 };
13719 static const unsigned char le_nop[] = { 0x00, 0x65 };
13724 bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
13725 p = fragp->fr_literal + fragp->fr_fix;
13733 memcpy (p, (target_big_endian ? be_nop : le_nop), 2);
13737 /* For mips32, a nop is a zero, which we trivially get by doing nothing. */
13741 md_obj_begin (void)
13748 /* check for premature end, nesting errors, etc */
13750 as_warn (_("missing .end at end of assembly"));
13759 if (*input_line_pointer == '-')
13761 ++input_line_pointer;
13764 if (!ISDIGIT (*input_line_pointer))
13765 as_bad (_("expected simple number"));
13766 if (input_line_pointer[0] == '0')
13768 if (input_line_pointer[1] == 'x')
13770 input_line_pointer += 2;
13771 while (ISXDIGIT (*input_line_pointer))
13774 val |= hex_value (*input_line_pointer++);
13776 return negative ? -val : val;
13780 ++input_line_pointer;
13781 while (ISDIGIT (*input_line_pointer))
13784 val |= *input_line_pointer++ - '0';
13786 return negative ? -val : val;
13789 if (!ISDIGIT (*input_line_pointer))
13791 printf (_(" *input_line_pointer == '%c' 0x%02x\n"),
13792 *input_line_pointer, *input_line_pointer);
13793 as_warn (_("invalid number"));
13796 while (ISDIGIT (*input_line_pointer))
13799 val += *input_line_pointer++ - '0';
13801 return negative ? -val : val;
13804 /* The .file directive; just like the usual .file directive, but there
13805 is an initial number which is the ECOFF file index. In the non-ECOFF
13806 case .file implies DWARF-2. */
13809 s_mips_file (int x ATTRIBUTE_UNUSED)
13811 static int first_file_directive = 0;
13813 if (ECOFF_DEBUGGING)
13822 filename = dwarf2_directive_file (0);
13824 /* Versions of GCC up to 3.1 start files with a ".file"
13825 directive even for stabs output. Make sure that this
13826 ".file" is handled. Note that you need a version of GCC
13827 after 3.1 in order to support DWARF-2 on MIPS. */
13828 if (filename != NULL && ! first_file_directive)
13830 (void) new_logical_line (filename, -1);
13831 s_app_file_string (filename, 0);
13833 first_file_directive = 1;
13837 /* The .loc directive, implying DWARF-2. */
13840 s_mips_loc (int x ATTRIBUTE_UNUSED)
13842 if (!ECOFF_DEBUGGING)
13843 dwarf2_directive_loc (0);
13846 /* The .end directive. */
13849 s_mips_end (int x ATTRIBUTE_UNUSED)
13853 /* Following functions need their own .frame and .cprestore directives. */
13854 mips_frame_reg_valid = 0;
13855 mips_cprestore_valid = 0;
13857 if (!is_end_of_line[(unsigned char) *input_line_pointer])
13860 demand_empty_rest_of_line ();
13865 if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) == 0)
13866 as_warn (_(".end not in text section"));
13870 as_warn (_(".end directive without a preceding .ent directive."));
13871 demand_empty_rest_of_line ();
13877 assert (S_GET_NAME (p));
13878 if (strcmp (S_GET_NAME (p), S_GET_NAME (cur_proc_ptr->func_sym)))
13879 as_warn (_(".end symbol does not match .ent symbol."));
13881 if (debug_type == DEBUG_STABS)
13882 stabs_generate_asm_endfunc (S_GET_NAME (p),
13886 as_warn (_(".end directive missing or unknown symbol"));
13889 /* Create an expression to calculate the size of the function. */
13890 if (p && cur_proc_ptr)
13892 OBJ_SYMFIELD_TYPE *obj = symbol_get_obj (p);
13893 expressionS *exp = xmalloc (sizeof (expressionS));
13896 exp->X_op = O_subtract;
13897 exp->X_add_symbol = symbol_temp_new_now ();
13898 exp->X_op_symbol = p;
13899 exp->X_add_number = 0;
13901 cur_proc_ptr->func_end_sym = exp->X_add_symbol;
13904 /* Generate a .pdr section. */
13905 if (OUTPUT_FLAVOR == bfd_target_elf_flavour && ! ECOFF_DEBUGGING
13908 segT saved_seg = now_seg;
13909 subsegT saved_subseg = now_subseg;
13914 dot = frag_now_fix ();
13916 #ifdef md_flush_pending_output
13917 md_flush_pending_output ();
13921 subseg_set (pdr_seg, 0);
13923 /* Write the symbol. */
13924 exp.X_op = O_symbol;
13925 exp.X_add_symbol = p;
13926 exp.X_add_number = 0;
13927 emit_expr (&exp, 4);
13929 fragp = frag_more (7 * 4);
13931 md_number_to_chars (fragp, cur_proc_ptr->reg_mask, 4);
13932 md_number_to_chars (fragp + 4, cur_proc_ptr->reg_offset, 4);
13933 md_number_to_chars (fragp + 8, cur_proc_ptr->fpreg_mask, 4);
13934 md_number_to_chars (fragp + 12, cur_proc_ptr->fpreg_offset, 4);
13935 md_number_to_chars (fragp + 16, cur_proc_ptr->frame_offset, 4);
13936 md_number_to_chars (fragp + 20, cur_proc_ptr->frame_reg, 4);
13937 md_number_to_chars (fragp + 24, cur_proc_ptr->pc_reg, 4);
13939 subseg_set (saved_seg, saved_subseg);
13941 #endif /* OBJ_ELF */
13943 cur_proc_ptr = NULL;
13946 /* The .aent and .ent directives. */
13949 s_mips_ent (int aent)
13953 symbolP = get_symbol ();
13954 if (*input_line_pointer == ',')
13955 ++input_line_pointer;
13956 SKIP_WHITESPACE ();
13957 if (ISDIGIT (*input_line_pointer)
13958 || *input_line_pointer == '-')
13961 if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) == 0)
13962 as_warn (_(".ent or .aent not in text section."));
13964 if (!aent && cur_proc_ptr)
13965 as_warn (_("missing .end"));
13969 /* This function needs its own .frame and .cprestore directives. */
13970 mips_frame_reg_valid = 0;
13971 mips_cprestore_valid = 0;
13973 cur_proc_ptr = &cur_proc;
13974 memset (cur_proc_ptr, '\0', sizeof (procS));
13976 cur_proc_ptr->func_sym = symbolP;
13978 symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION;
13982 if (debug_type == DEBUG_STABS)
13983 stabs_generate_asm_func (S_GET_NAME (symbolP),
13984 S_GET_NAME (symbolP));
13987 demand_empty_rest_of_line ();
13990 /* The .frame directive. If the mdebug section is present (IRIX 5 native)
13991 then ecoff.c (ecoff_directive_frame) is used. For embedded targets,
13992 s_mips_frame is used so that we can set the PDR information correctly.
13993 We can't use the ecoff routines because they make reference to the ecoff
13994 symbol table (in the mdebug section). */
13997 s_mips_frame (int ignore ATTRIBUTE_UNUSED)
14000 if (OUTPUT_FLAVOR == bfd_target_elf_flavour && ! ECOFF_DEBUGGING)
14004 if (cur_proc_ptr == (procS *) NULL)
14006 as_warn (_(".frame outside of .ent"));
14007 demand_empty_rest_of_line ();
14011 cur_proc_ptr->frame_reg = tc_get_register (1);
14013 SKIP_WHITESPACE ();
14014 if (*input_line_pointer++ != ','
14015 || get_absolute_expression_and_terminator (&val) != ',')
14017 as_warn (_("Bad .frame directive"));
14018 --input_line_pointer;
14019 demand_empty_rest_of_line ();
14023 cur_proc_ptr->frame_offset = val;
14024 cur_proc_ptr->pc_reg = tc_get_register (0);
14026 demand_empty_rest_of_line ();
14029 #endif /* OBJ_ELF */
14033 /* The .fmask and .mask directives. If the mdebug section is present
14034 (IRIX 5 native) then ecoff.c (ecoff_directive_mask) is used. For
14035 embedded targets, s_mips_mask is used so that we can set the PDR
14036 information correctly. We can't use the ecoff routines because they
14037 make reference to the ecoff symbol table (in the mdebug section). */
14040 s_mips_mask (int reg_type)
14043 if (OUTPUT_FLAVOR == bfd_target_elf_flavour && ! ECOFF_DEBUGGING)
14047 if (cur_proc_ptr == (procS *) NULL)
14049 as_warn (_(".mask/.fmask outside of .ent"));
14050 demand_empty_rest_of_line ();
14054 if (get_absolute_expression_and_terminator (&mask) != ',')
14056 as_warn (_("Bad .mask/.fmask directive"));
14057 --input_line_pointer;
14058 demand_empty_rest_of_line ();
14062 off = get_absolute_expression ();
14064 if (reg_type == 'F')
14066 cur_proc_ptr->fpreg_mask = mask;
14067 cur_proc_ptr->fpreg_offset = off;
14071 cur_proc_ptr->reg_mask = mask;
14072 cur_proc_ptr->reg_offset = off;
14075 demand_empty_rest_of_line ();
14078 #endif /* OBJ_ELF */
14079 s_ignore (reg_type);
14082 /* A table describing all the processors gas knows about. Names are
14083 matched in the order listed.
14085 To ease comparison, please keep this table in the same order as
14086 gcc's mips_cpu_info_table[]. */
14087 static const struct mips_cpu_info mips_cpu_info_table[] =
14089 /* Entries for generic ISAs */
14090 { "mips1", 1, ISA_MIPS1, CPU_R3000 },
14091 { "mips2", 1, ISA_MIPS2, CPU_R6000 },
14092 { "mips3", 1, ISA_MIPS3, CPU_R4000 },
14093 { "mips4", 1, ISA_MIPS4, CPU_R8000 },
14094 { "mips5", 1, ISA_MIPS5, CPU_MIPS5 },
14095 { "mips32", 1, ISA_MIPS32, CPU_MIPS32 },
14096 { "mips32r2", 1, ISA_MIPS32R2, CPU_MIPS32R2 },
14097 { "mips64", 1, ISA_MIPS64, CPU_MIPS64 },
14098 { "mips64r2", 1, ISA_MIPS64R2, CPU_MIPS64R2 },
14101 { "r3000", 0, ISA_MIPS1, CPU_R3000 },
14102 { "r2000", 0, ISA_MIPS1, CPU_R3000 },
14103 { "r3900", 0, ISA_MIPS1, CPU_R3900 },
14106 { "r6000", 0, ISA_MIPS2, CPU_R6000 },
14109 { "r4000", 0, ISA_MIPS3, CPU_R4000 },
14110 { "r4010", 0, ISA_MIPS2, CPU_R4010 },
14111 { "vr4100", 0, ISA_MIPS3, CPU_VR4100 },
14112 { "vr4111", 0, ISA_MIPS3, CPU_R4111 },
14113 { "vr4120", 0, ISA_MIPS3, CPU_VR4120 },
14114 { "vr4130", 0, ISA_MIPS3, CPU_VR4120 },
14115 { "vr4181", 0, ISA_MIPS3, CPU_R4111 },
14116 { "vr4300", 0, ISA_MIPS3, CPU_R4300 },
14117 { "r4400", 0, ISA_MIPS3, CPU_R4400 },
14118 { "r4600", 0, ISA_MIPS3, CPU_R4600 },
14119 { "orion", 0, ISA_MIPS3, CPU_R4600 },
14120 { "r4650", 0, ISA_MIPS3, CPU_R4650 },
14123 { "r8000", 0, ISA_MIPS4, CPU_R8000 },
14124 { "r10000", 0, ISA_MIPS4, CPU_R10000 },
14125 { "r12000", 0, ISA_MIPS4, CPU_R12000 },
14126 { "vr5000", 0, ISA_MIPS4, CPU_R5000 },
14127 { "vr5400", 0, ISA_MIPS4, CPU_VR5400 },
14128 { "vr5500", 0, ISA_MIPS4, CPU_VR5500 },
14129 { "rm5200", 0, ISA_MIPS4, CPU_R5000 },
14130 { "rm5230", 0, ISA_MIPS4, CPU_R5000 },
14131 { "rm5231", 0, ISA_MIPS4, CPU_R5000 },
14132 { "rm5261", 0, ISA_MIPS4, CPU_R5000 },
14133 { "rm5721", 0, ISA_MIPS4, CPU_R5000 },
14134 { "rm7000", 0, ISA_MIPS4, CPU_RM7000 },
14135 { "rm9000", 0, ISA_MIPS4, CPU_RM9000 },
14138 { "4kc", 0, ISA_MIPS32, CPU_MIPS32 },
14139 { "4km", 0, ISA_MIPS32, CPU_MIPS32 },
14140 { "4kp", 0, ISA_MIPS32, CPU_MIPS32 },
14142 /* MIPS32 Release 2 */
14143 { "m4k", 0, ISA_MIPS32R2, CPU_MIPS32R2 },
14144 { "24k", 0, ISA_MIPS32R2, CPU_MIPS32R2 },
14145 { "24kc", 0, ISA_MIPS32R2, CPU_MIPS32R2 },
14146 { "24kf", 0, ISA_MIPS32R2, CPU_MIPS32R2 },
14147 { "24kx", 0, ISA_MIPS32R2, CPU_MIPS32R2 },
14150 { "5kc", 0, ISA_MIPS64, CPU_MIPS64 },
14151 { "5kf", 0, ISA_MIPS64, CPU_MIPS64 },
14152 { "20kc", 0, ISA_MIPS64, CPU_MIPS64 },
14154 /* Broadcom SB-1 CPU core */
14155 { "sb1", 0, ISA_MIPS64, CPU_SB1 },
14162 /* Return true if GIVEN is the same as CANONICAL, or if it is CANONICAL
14163 with a final "000" replaced by "k". Ignore case.
14165 Note: this function is shared between GCC and GAS. */
14168 mips_strict_matching_cpu_name_p (const char *canonical, const char *given)
14170 while (*given != 0 && TOLOWER (*given) == TOLOWER (*canonical))
14171 given++, canonical++;
14173 return ((*given == 0 && *canonical == 0)
14174 || (strcmp (canonical, "000") == 0 && strcasecmp (given, "k") == 0));
14178 /* Return true if GIVEN matches CANONICAL, where GIVEN is a user-supplied
14179 CPU name. We've traditionally allowed a lot of variation here.
14181 Note: this function is shared between GCC and GAS. */
14184 mips_matching_cpu_name_p (const char *canonical, const char *given)
14186 /* First see if the name matches exactly, or with a final "000"
14187 turned into "k". */
14188 if (mips_strict_matching_cpu_name_p (canonical, given))
14191 /* If not, try comparing based on numerical designation alone.
14192 See if GIVEN is an unadorned number, or 'r' followed by a number. */
14193 if (TOLOWER (*given) == 'r')
14195 if (!ISDIGIT (*given))
14198 /* Skip over some well-known prefixes in the canonical name,
14199 hoping to find a number there too. */
14200 if (TOLOWER (canonical[0]) == 'v' && TOLOWER (canonical[1]) == 'r')
14202 else if (TOLOWER (canonical[0]) == 'r' && TOLOWER (canonical[1]) == 'm')
14204 else if (TOLOWER (canonical[0]) == 'r')
14207 return mips_strict_matching_cpu_name_p (canonical, given);
14211 /* Parse an option that takes the name of a processor as its argument.
14212 OPTION is the name of the option and CPU_STRING is the argument.
14213 Return the corresponding processor enumeration if the CPU_STRING is
14214 recognized, otherwise report an error and return null.
14216 A similar function exists in GCC. */
14218 static const struct mips_cpu_info *
14219 mips_parse_cpu (const char *option, const char *cpu_string)
14221 const struct mips_cpu_info *p;
14223 /* 'from-abi' selects the most compatible architecture for the given
14224 ABI: MIPS I for 32-bit ABIs and MIPS III for 64-bit ABIs. For the
14225 EABIs, we have to decide whether we're using the 32-bit or 64-bit
14226 version. Look first at the -mgp options, if given, otherwise base
14227 the choice on MIPS_DEFAULT_64BIT.
14229 Treat NO_ABI like the EABIs. One reason to do this is that the
14230 plain 'mips' and 'mips64' configs have 'from-abi' as their default
14231 architecture. This code picks MIPS I for 'mips' and MIPS III for
14232 'mips64', just as we did in the days before 'from-abi'. */
14233 if (strcasecmp (cpu_string, "from-abi") == 0)
14235 if (ABI_NEEDS_32BIT_REGS (mips_abi))
14236 return mips_cpu_info_from_isa (ISA_MIPS1);
14238 if (ABI_NEEDS_64BIT_REGS (mips_abi))
14239 return mips_cpu_info_from_isa (ISA_MIPS3);
14241 if (file_mips_gp32 >= 0)
14242 return mips_cpu_info_from_isa (file_mips_gp32 ? ISA_MIPS1 : ISA_MIPS3);
14244 return mips_cpu_info_from_isa (MIPS_DEFAULT_64BIT
14249 /* 'default' has traditionally been a no-op. Probably not very useful. */
14250 if (strcasecmp (cpu_string, "default") == 0)
14253 for (p = mips_cpu_info_table; p->name != 0; p++)
14254 if (mips_matching_cpu_name_p (p->name, cpu_string))
14257 as_bad ("Bad value (%s) for %s", cpu_string, option);
14261 /* Return the canonical processor information for ISA (a member of the
14262 ISA_MIPS* enumeration). */
14264 static const struct mips_cpu_info *
14265 mips_cpu_info_from_isa (int isa)
14269 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
14270 if (mips_cpu_info_table[i].is_isa
14271 && isa == mips_cpu_info_table[i].isa)
14272 return (&mips_cpu_info_table[i]);
14277 static const struct mips_cpu_info *
14278 mips_cpu_info_from_arch (int arch)
14282 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
14283 if (arch == mips_cpu_info_table[i].cpu)
14284 return (&mips_cpu_info_table[i]);
14290 show (FILE *stream, const char *string, int *col_p, int *first_p)
14294 fprintf (stream, "%24s", "");
14299 fprintf (stream, ", ");
14303 if (*col_p + strlen (string) > 72)
14305 fprintf (stream, "\n%24s", "");
14309 fprintf (stream, "%s", string);
14310 *col_p += strlen (string);
14316 md_show_usage (FILE *stream)
14321 fprintf (stream, _("\
14323 -EB generate big endian output\n\
14324 -EL generate little endian output\n\
14325 -g, -g2 do not remove unneeded NOPs or swap branches\n\
14326 -G NUM allow referencing objects up to NUM bytes\n\
14327 implicitly with the gp register [default 8]\n"));
14328 fprintf (stream, _("\
14329 -mips1 generate MIPS ISA I instructions\n\
14330 -mips2 generate MIPS ISA II instructions\n\
14331 -mips3 generate MIPS ISA III instructions\n\
14332 -mips4 generate MIPS ISA IV instructions\n\
14333 -mips5 generate MIPS ISA V instructions\n\
14334 -mips32 generate MIPS32 ISA instructions\n\
14335 -mips32r2 generate MIPS32 release 2 ISA instructions\n\
14336 -mips64 generate MIPS64 ISA instructions\n\
14337 -mips64r2 generate MIPS64 release 2 ISA instructions\n\
14338 -march=CPU/-mtune=CPU generate code/schedule for CPU, where CPU is one of:\n"));
14342 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
14343 show (stream, mips_cpu_info_table[i].name, &column, &first);
14344 show (stream, "from-abi", &column, &first);
14345 fputc ('\n', stream);
14347 fprintf (stream, _("\
14348 -mCPU equivalent to -march=CPU -mtune=CPU. Deprecated.\n\
14349 -no-mCPU don't generate code specific to CPU.\n\
14350 For -mCPU and -no-mCPU, CPU must be one of:\n"));
14354 show (stream, "3900", &column, &first);
14355 show (stream, "4010", &column, &first);
14356 show (stream, "4100", &column, &first);
14357 show (stream, "4650", &column, &first);
14358 fputc ('\n', stream);
14360 fprintf (stream, _("\
14361 -mips16 generate mips16 instructions\n\
14362 -no-mips16 do not generate mips16 instructions\n"));
14363 fprintf (stream, _("\
14364 -mdsp generate DSP instructions\n\
14365 -mno-dsp do not generate DSP instructions\n"));
14366 fprintf (stream, _("\
14367 -mmt generate MT instructions\n\
14368 -mno-mt do not generate MT instructions\n"));
14369 fprintf (stream, _("\
14370 -mfix-vr4120 work around certain VR4120 errata\n\
14371 -mfix-vr4130 work around VR4130 mflo/mfhi errata\n\
14372 -mgp32 use 32-bit GPRs, regardless of the chosen ISA\n\
14373 -mfp32 use 32-bit FPRs, regardless of the chosen ISA\n\
14374 -mno-shared optimize output for executables\n\
14375 -msym32 assume all symbols have 32-bit values\n\
14376 -O0 remove unneeded NOPs, do not swap branches\n\
14377 -O remove unneeded NOPs and swap branches\n\
14378 --[no-]construct-floats [dis]allow floating point values to be constructed\n\
14379 --trap, --no-break trap exception on div by 0 and mult overflow\n\
14380 --break, --no-trap break exception on div by 0 and mult overflow\n"));
14382 fprintf (stream, _("\
14383 -KPIC, -call_shared generate SVR4 position independent code\n\
14384 -non_shared do not generate position independent code\n\
14385 -xgot assume a 32 bit GOT\n\
14386 -mpdr, -mno-pdr enable/disable creation of .pdr sections\n\
14387 -mshared, -mno-shared disable/enable .cpload optimization for\n\
14389 -mabi=ABI create ABI conformant object file for:\n"));
14393 show (stream, "32", &column, &first);
14394 show (stream, "o64", &column, &first);
14395 show (stream, "n32", &column, &first);
14396 show (stream, "64", &column, &first);
14397 show (stream, "eabi", &column, &first);
14399 fputc ('\n', stream);
14401 fprintf (stream, _("\
14402 -32 create o32 ABI object file (default)\n\
14403 -n32 create n32 ABI object file\n\
14404 -64 create 64 ABI object file\n"));
14409 mips_dwarf2_format (void)
14411 if (mips_abi == N64_ABI)
14414 return dwarf2_format_64bit_irix;
14416 return dwarf2_format_64bit;
14420 return dwarf2_format_32bit;
14424 mips_dwarf2_addr_size (void)
14426 if (mips_abi == N64_ABI)
14432 /* Standard calling conventions leave the CFA at SP on entry. */
14434 mips_cfi_frame_initial_instructions (void)
14436 cfi_add_CFA_def_cfa_register (SP);