1 /* tc-mips.c -- assemble code for a MIPS chip.
2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 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, 59 Temple Place - Suite 330, Boston, MA
29 #include "safe-ctype.h"
38 #include "opcode/mips.h"
40 #include "dwarf2dbg.h"
43 #define DBG(x) printf x
49 /* Clean up namespace so we can include obj-elf.h too. */
50 static int mips_output_flavor PARAMS ((void));
51 static int mips_output_flavor () { return OUTPUT_FLAVOR; }
52 #undef OBJ_PROCESS_STAB
59 #undef obj_frob_file_after_relocs
60 #undef obj_frob_symbol
62 #undef obj_sec_sym_ok_for_reloc
63 #undef OBJ_COPY_SYMBOL_ATTRIBUTES
66 /* Fix any of them that we actually care about. */
68 #define OUTPUT_FLAVOR mips_output_flavor()
75 #ifndef ECOFF_DEBUGGING
76 #define NO_ECOFF_DEBUGGING
77 #define ECOFF_DEBUGGING 0
80 int mips_flag_mdebug = -1;
84 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
85 static char *mips_regmask_frag;
91 #define PIC_CALL_REG 25
99 #define ILLEGAL_REG (32)
101 /* Allow override of standard little-endian ECOFF format. */
103 #ifndef ECOFF_LITTLE_FORMAT
104 #define ECOFF_LITTLE_FORMAT "ecoff-littlemips"
107 extern int target_big_endian;
109 /* The name of the readonly data section. */
110 #define RDATA_SECTION_NAME (OUTPUT_FLAVOR == bfd_target_aout_flavour \
112 : OUTPUT_FLAVOR == bfd_target_ecoff_flavour \
114 : OUTPUT_FLAVOR == bfd_target_coff_flavour \
116 : OUTPUT_FLAVOR == bfd_target_elf_flavour \
120 /* The ABI to use. */
131 /* MIPS ABI we are using for this output file. */
132 static enum mips_abi_level file_mips_abi = NO_ABI;
134 /* This is the set of options which may be modified by the .set
135 pseudo-op. We use a struct so that .set push and .set pop are more
138 struct mips_set_options
140 /* MIPS ISA (Instruction Set Architecture) level. This is set to -1
141 if it has not been initialized. Changed by `.set mipsN', and the
142 -mipsN command line option, and the default CPU. */
144 /* Enabled Application Specific Extensions (ASEs). These are set to -1
145 if they have not been initialized. Changed by `.set <asename>', by
146 command line options, and based on the default architecture. */
149 /* Whether we are assembling for the mips16 processor. 0 if we are
150 not, 1 if we are, and -1 if the value has not been initialized.
151 Changed by `.set mips16' and `.set nomips16', and the -mips16 and
152 -nomips16 command line options, and the default CPU. */
154 /* Non-zero if we should not reorder instructions. Changed by `.set
155 reorder' and `.set noreorder'. */
157 /* Non-zero if we should not permit the $at ($1) register to be used
158 in instructions. Changed by `.set at' and `.set noat'. */
160 /* Non-zero if we should warn when a macro instruction expands into
161 more than one machine instruction. Changed by `.set nomacro' and
163 int warn_about_macros;
164 /* Non-zero if we should not move instructions. Changed by `.set
165 move', `.set volatile', `.set nomove', and `.set novolatile'. */
167 /* Non-zero if we should not optimize branches by moving the target
168 of the branch into the delay slot. Actually, we don't perform
169 this optimization anyhow. Changed by `.set bopt' and `.set
172 /* Non-zero if we should not autoextend mips16 instructions.
173 Changed by `.set autoextend' and `.set noautoextend'. */
175 /* Restrict general purpose registers and floating point registers
176 to 32 bit. This is initially determined when -mgp32 or -mfp32
177 is passed but can changed if the assembler code uses .set mipsN. */
180 /* The ABI currently in use. This is changed by .set mipsN to loosen
181 restrictions and doesn't affect the whole file. */
182 enum mips_abi_level abi;
185 /* True if -mgp32 was passed. */
186 static int file_mips_gp32 = -1;
188 /* True if -mfp32 was passed. */
189 static int file_mips_fp32 = -1;
191 /* This is the struct we use to hold the current set of options. Note
192 that we must set the isa field to ISA_UNKNOWN and the ASE fields to
193 -1 to indicate that they have not been initialized. */
195 static struct mips_set_options mips_opts =
197 ISA_UNKNOWN, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, NO_ABI
200 /* These variables are filled in with the masks of registers used.
201 The object format code reads them and puts them in the appropriate
203 unsigned long mips_gprmask;
204 unsigned long mips_cprmask[4];
206 /* MIPS ISA we are using for this output file. */
207 static int file_mips_isa = ISA_UNKNOWN;
209 /* True if -mips16 was passed or implied by arguments passed on the
210 command line (e.g., by -march). */
211 static int file_ase_mips16;
213 /* True if -mips3d was passed or implied by arguments passed on the
214 command line (e.g., by -march). */
215 static int file_ase_mips3d;
217 /* True if -mdmx was passed or implied by arguments passed on the
218 command line (e.g., by -march). */
219 static int file_ase_mdmx;
221 /* The argument of the -mcpu= flag. Historical for code generation. */
222 static int mips_cpu = CPU_UNKNOWN;
224 /* The argument of the -march= flag. The architecture we are assembling. */
225 static int mips_arch = CPU_UNKNOWN;
227 /* The argument of the -mtune= flag. The architecture for which we
229 static int mips_tune = CPU_UNKNOWN;
231 /* If they asked for mips1 or mips2 and a cpu that is
232 mips3 or greater, then mark the object file 32BITMODE. */
233 static int mips_32bitmode = 0;
235 /* Some ISA's have delay slots for instructions which read or write
236 from a coprocessor (eg. mips1-mips3); some don't (eg mips4).
237 Return true if instructions marked INSN_LOAD_COPROC_DELAY,
238 INSN_COPROC_MOVE_DELAY, or INSN_WRITE_COND_CODE actually have a
239 delay slot in this ISA. The uses of this macro assume that any
240 ISA that has delay slots for one of these, has them for all. They
241 also assume that ISAs which don't have delays for these insns, don't
242 have delays for the INSN_LOAD_MEMORY_DELAY instructions either. */
243 #define ISA_HAS_COPROC_DELAYS(ISA) ( \
245 || (ISA) == ISA_MIPS2 \
246 || (ISA) == ISA_MIPS3 \
249 /* Return true if ISA supports 64 bit gp register instructions. */
250 #define ISA_HAS_64BIT_REGS(ISA) ( \
252 || (ISA) == ISA_MIPS4 \
253 || (ISA) == ISA_MIPS5 \
254 || (ISA) == ISA_MIPS64 \
257 #define HAVE_32BIT_GPRS \
259 || mips_opts.abi == O32_ABI \
260 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
262 #define HAVE_32BIT_FPRS \
264 || mips_opts.abi == O32_ABI \
265 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
267 #define HAVE_64BIT_GPRS (! HAVE_32BIT_GPRS)
268 #define HAVE_64BIT_FPRS (! HAVE_32BIT_FPRS)
270 #define HAVE_NEWABI (mips_opts.abi == N32_ABI || mips_opts.abi == N64_ABI)
272 #define HAVE_64BIT_OBJECTS (mips_opts.abi == N64_ABI)
274 /* We can only have 64bit addresses if the object file format
276 #define HAVE_32BIT_ADDRESSES \
278 || ((bfd_arch_bits_per_address (stdoutput) == 32 \
279 || ! HAVE_64BIT_OBJECTS) \
280 && mips_pic != EMBEDDED_PIC))
282 #define HAVE_64BIT_ADDRESSES (! HAVE_32BIT_ADDRESSES)
284 /* Return true if the given CPU supports the MIPS16 ASE. */
285 #define CPU_HAS_MIPS16(cpu) \
286 (strncmp (TARGET_CPU, "mips16", sizeof ("mips16") - 1) == 0)
288 /* Return true if the given CPU supports the MIPS3D ASE. */
289 #define CPU_HAS_MIPS3D(cpu) ((cpu) == CPU_SB1 \
292 /* Return true if the given CPU supports the MDMX ASE. */
293 #define CPU_HAS_MDMX(cpu) (false \
296 /* Whether the processor uses hardware interlocks to protect
297 reads from the HI and LO registers, and thus does not
298 require nops to be inserted. */
300 #define hilo_interlocks (mips_arch == CPU_R4010 \
301 || mips_arch == CPU_SB1 \
304 /* Whether the processor uses hardware interlocks to protect reads
305 from the GPRs, and thus does not require nops to be inserted. */
306 #define gpr_interlocks \
307 (mips_opts.isa != ISA_MIPS1 \
308 || mips_arch == CPU_R3900)
310 /* As with other "interlocks" this is used by hardware that has FP
311 (co-processor) interlocks. */
312 /* Itbl support may require additional care here. */
313 #define cop_interlocks (mips_arch == CPU_R4300 \
314 || mips_arch == CPU_SB1 \
317 /* Is this a mfhi or mflo instruction? */
318 #define MF_HILO_INSN(PINFO) \
319 ((PINFO & INSN_READ_HI) || (PINFO & INSN_READ_LO))
321 /* MIPS PIC level. */
325 /* Do not generate PIC code. */
328 /* Generate PIC code as in Irix 4. This is not implemented, and I'm
329 not sure what it is supposed to do. */
332 /* Generate PIC code as in the SVR4 MIPS ABI. */
335 /* Generate PIC code without using a global offset table: the data
336 segment has a maximum size of 64K, all data references are off
337 the $gp register, and all text references are PC relative. This
338 is used on some embedded systems. */
342 static enum mips_pic_level mips_pic;
344 /* Warn about all NOPS that the assembler generates. */
345 static int warn_nops = 0;
347 /* 1 if we should generate 32 bit offsets from the $gp register in
348 SVR4_PIC mode. Currently has no meaning in other modes. */
349 static int mips_big_got = 0;
351 /* 1 if trap instructions should used for overflow rather than break
353 static int mips_trap = 0;
355 /* 1 if double width floating point constants should not be constructed
356 by assembling two single width halves into two single width floating
357 point registers which just happen to alias the double width destination
358 register. On some architectures this aliasing can be disabled by a bit
359 in the status register, and the setting of this bit cannot be determined
360 automatically at assemble time. */
361 static int mips_disable_float_construction;
363 /* Non-zero if any .set noreorder directives were used. */
365 static int mips_any_noreorder;
367 /* Non-zero if nops should be inserted when the register referenced in
368 an mfhi/mflo instruction is read in the next two instructions. */
369 static int mips_7000_hilo_fix;
371 /* The size of the small data section. */
372 static unsigned int g_switch_value = 8;
373 /* Whether the -G option was used. */
374 static int g_switch_seen = 0;
379 /* If we can determine in advance that GP optimization won't be
380 possible, we can skip the relaxation stuff that tries to produce
381 GP-relative references. This makes delay slot optimization work
384 This function can only provide a guess, but it seems to work for
385 gcc output. It needs to guess right for gcc, otherwise gcc
386 will put what it thinks is a GP-relative instruction in a branch
389 I don't know if a fix is needed for the SVR4_PIC mode. I've only
390 fixed it for the non-PIC mode. KR 95/04/07 */
391 static int nopic_need_relax PARAMS ((symbolS *, int));
393 /* handle of the OPCODE hash table */
394 static struct hash_control *op_hash = NULL;
396 /* The opcode hash table we use for the mips16. */
397 static struct hash_control *mips16_op_hash = NULL;
399 /* This array holds the chars that always start a comment. If the
400 pre-processor is disabled, these aren't very useful */
401 const char comment_chars[] = "#";
403 /* This array holds the chars that only start a comment at the beginning of
404 a line. If the line seems to have the form '# 123 filename'
405 .line and .file directives will appear in the pre-processed output */
406 /* Note that input_file.c hand checks for '#' at the beginning of the
407 first line of the input file. This is because the compiler outputs
408 #NO_APP at the beginning of its output. */
409 /* Also note that C style comments are always supported. */
410 const char line_comment_chars[] = "#";
412 /* This array holds machine specific line separator characters. */
413 const char line_separator_chars[] = ";";
415 /* Chars that can be used to separate mant from exp in floating point nums */
416 const char EXP_CHARS[] = "eE";
418 /* Chars that mean this number is a floating point constant */
421 const char FLT_CHARS[] = "rRsSfFdDxXpP";
423 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
424 changed in read.c . Ideally it shouldn't have to know about it at all,
425 but nothing is ideal around here.
428 static char *insn_error;
430 static int auto_align = 1;
432 /* When outputting SVR4 PIC code, the assembler needs to know the
433 offset in the stack frame from which to restore the $gp register.
434 This is set by the .cprestore pseudo-op, and saved in this
436 static offsetT mips_cprestore_offset = -1;
438 /* Similiar for NewABI PIC code, where $gp is callee-saved. NewABI has some
439 more optimizations, it can use a register value instead of a memory-saved
440 offset and even an other register than $gp as global pointer. */
441 static offsetT mips_cpreturn_offset = -1;
442 static int mips_cpreturn_register = -1;
443 static int mips_gp_register = GP;
444 static int mips_gprel_offset = 0;
446 /* Whether mips_cprestore_offset has been set in the current function
447 (or whether it has already been warned about, if not). */
448 static int mips_cprestore_valid = 0;
450 /* This is the register which holds the stack frame, as set by the
451 .frame pseudo-op. This is needed to implement .cprestore. */
452 static int mips_frame_reg = SP;
454 /* Whether mips_frame_reg has been set in the current function
455 (or whether it has already been warned about, if not). */
456 static int mips_frame_reg_valid = 0;
458 /* To output NOP instructions correctly, we need to keep information
459 about the previous two instructions. */
461 /* Whether we are optimizing. The default value of 2 means to remove
462 unneeded NOPs and swap branch instructions when possible. A value
463 of 1 means to not swap branches. A value of 0 means to always
465 static int mips_optimize = 2;
467 /* Debugging level. -g sets this to 2. -gN sets this to N. -g0 is
468 equivalent to seeing no -g option at all. */
469 static int mips_debug = 0;
471 /* The previous instruction. */
472 static struct mips_cl_insn prev_insn;
474 /* The instruction before prev_insn. */
475 static struct mips_cl_insn prev_prev_insn;
477 /* If we don't want information for prev_insn or prev_prev_insn, we
478 point the insn_mo field at this dummy integer. */
479 static const struct mips_opcode dummy_opcode = { NULL, NULL, 0, 0, 0, 0 };
481 /* Non-zero if prev_insn is valid. */
482 static int prev_insn_valid;
484 /* The frag for the previous instruction. */
485 static struct frag *prev_insn_frag;
487 /* The offset into prev_insn_frag for the previous instruction. */
488 static long prev_insn_where;
490 /* The reloc type for the previous instruction, if any. */
491 static bfd_reloc_code_real_type prev_insn_reloc_type[3];
493 /* The reloc for the previous instruction, if any. */
494 static fixS *prev_insn_fixp[3];
496 /* Non-zero if the previous instruction was in a delay slot. */
497 static int prev_insn_is_delay_slot;
499 /* Non-zero if the previous instruction was in a .set noreorder. */
500 static int prev_insn_unreordered;
502 /* Non-zero if the previous instruction uses an extend opcode (if
504 static int prev_insn_extended;
506 /* Non-zero if the previous previous instruction was in a .set
508 static int prev_prev_insn_unreordered;
510 /* If this is set, it points to a frag holding nop instructions which
511 were inserted before the start of a noreorder section. If those
512 nops turn out to be unnecessary, the size of the frag can be
514 static fragS *prev_nop_frag;
516 /* The number of nop instructions we created in prev_nop_frag. */
517 static int prev_nop_frag_holds;
519 /* The number of nop instructions that we know we need in
521 static int prev_nop_frag_required;
523 /* The number of instructions we've seen since prev_nop_frag. */
524 static int prev_nop_frag_since;
526 /* For ECOFF and ELF, relocations against symbols are done in two
527 parts, with a HI relocation and a LO relocation. Each relocation
528 has only 16 bits of space to store an addend. This means that in
529 order for the linker to handle carries correctly, it must be able
530 to locate both the HI and the LO relocation. This means that the
531 relocations must appear in order in the relocation table.
533 In order to implement this, we keep track of each unmatched HI
534 relocation. We then sort them so that they immediately precede the
535 corresponding LO relocation. */
540 struct mips_hi_fixup *next;
543 /* The section this fixup is in. */
547 /* The list of unmatched HI relocs. */
549 static struct mips_hi_fixup *mips_hi_fixup_list;
551 /* Map normal MIPS register numbers to mips16 register numbers. */
553 #define X ILLEGAL_REG
554 static const int mips32_to_16_reg_map[] =
556 X, X, 2, 3, 4, 5, 6, 7,
557 X, X, X, X, X, X, X, X,
558 0, 1, X, X, X, X, X, X,
559 X, X, X, X, X, X, X, X
563 /* Map mips16 register numbers to normal MIPS register numbers. */
565 static const unsigned int mips16_to_32_reg_map[] =
567 16, 17, 2, 3, 4, 5, 6, 7
570 /* Since the MIPS does not have multiple forms of PC relative
571 instructions, we do not have to do relaxing as is done on other
572 platforms. However, we do have to handle GP relative addressing
573 correctly, which turns out to be a similar problem.
575 Every macro that refers to a symbol can occur in (at least) two
576 forms, one with GP relative addressing and one without. For
577 example, loading a global variable into a register generally uses
578 a macro instruction like this:
580 If i can be addressed off the GP register (this is true if it is in
581 the .sbss or .sdata section, or if it is known to be smaller than
582 the -G argument) this will generate the following instruction:
584 This instruction will use a GPREL reloc. If i can not be addressed
585 off the GP register, the following instruction sequence will be used:
588 In this case the first instruction will have a HI16 reloc, and the
589 second reloc will have a LO16 reloc. Both relocs will be against
592 The issue here is that we may not know whether i is GP addressable
593 until after we see the instruction that uses it. Therefore, we
594 want to be able to choose the final instruction sequence only at
595 the end of the assembly. This is similar to the way other
596 platforms choose the size of a PC relative instruction only at the
599 When generating position independent code we do not use GP
600 addressing in quite the same way, but the issue still arises as
601 external symbols and local symbols must be handled differently.
603 We handle these issues by actually generating both possible
604 instruction sequences. The longer one is put in a frag_var with
605 type rs_machine_dependent. We encode what to do with the frag in
606 the subtype field. We encode (1) the number of existing bytes to
607 replace, (2) the number of new bytes to use, (3) the offset from
608 the start of the existing bytes to the first reloc we must generate
609 (that is, the offset is applied from the start of the existing
610 bytes after they are replaced by the new bytes, if any), (4) the
611 offset from the start of the existing bytes to the second reloc,
612 (5) whether a third reloc is needed (the third reloc is always four
613 bytes after the second reloc), and (6) whether to warn if this
614 variant is used (this is sometimes needed if .set nomacro or .set
615 noat is in effect). All these numbers are reasonably small.
617 Generating two instruction sequences must be handled carefully to
618 ensure that delay slots are handled correctly. Fortunately, there
619 are a limited number of cases. When the second instruction
620 sequence is generated, append_insn is directed to maintain the
621 existing delay slot information, so it continues to apply to any
622 code after the second instruction sequence. This means that the
623 second instruction sequence must not impose any requirements not
624 required by the first instruction sequence.
626 These variant frags are then handled in functions called by the
627 machine independent code. md_estimate_size_before_relax returns
628 the final size of the frag. md_convert_frag sets up the final form
629 of the frag. tc_gen_reloc adjust the first reloc and adds a second
631 #define RELAX_ENCODE(old, new, reloc1, reloc2, reloc3, warn) \
635 | (((reloc1) + 64) << 9) \
636 | (((reloc2) + 64) << 2) \
637 | ((reloc3) ? (1 << 1) : 0) \
639 #define RELAX_OLD(i) (((i) >> 23) & 0x7f)
640 #define RELAX_NEW(i) (((i) >> 16) & 0x7f)
641 #define RELAX_RELOC1(i) ((valueT) (((i) >> 9) & 0x7f) - 64)
642 #define RELAX_RELOC2(i) ((valueT) (((i) >> 2) & 0x7f) - 64)
643 #define RELAX_RELOC3(i) (((i) >> 1) & 1)
644 #define RELAX_WARN(i) ((i) & 1)
646 /* For mips16 code, we use an entirely different form of relaxation.
647 mips16 supports two versions of most instructions which take
648 immediate values: a small one which takes some small value, and a
649 larger one which takes a 16 bit value. Since branches also follow
650 this pattern, relaxing these values is required.
652 We can assemble both mips16 and normal MIPS code in a single
653 object. Therefore, we need to support this type of relaxation at
654 the same time that we support the relaxation described above. We
655 use the high bit of the subtype field to distinguish these cases.
657 The information we store for this type of relaxation is the
658 argument code found in the opcode file for this relocation, whether
659 the user explicitly requested a small or extended form, and whether
660 the relocation is in a jump or jal delay slot. That tells us the
661 size of the value, and how it should be stored. We also store
662 whether the fragment is considered to be extended or not. We also
663 store whether this is known to be a branch to a different section,
664 whether we have tried to relax this frag yet, and whether we have
665 ever extended a PC relative fragment because of a shift count. */
666 #define RELAX_MIPS16_ENCODE(type, small, ext, dslot, jal_dslot) \
669 | ((small) ? 0x100 : 0) \
670 | ((ext) ? 0x200 : 0) \
671 | ((dslot) ? 0x400 : 0) \
672 | ((jal_dslot) ? 0x800 : 0))
673 #define RELAX_MIPS16_P(i) (((i) & 0x80000000) != 0)
674 #define RELAX_MIPS16_TYPE(i) ((i) & 0xff)
675 #define RELAX_MIPS16_USER_SMALL(i) (((i) & 0x100) != 0)
676 #define RELAX_MIPS16_USER_EXT(i) (((i) & 0x200) != 0)
677 #define RELAX_MIPS16_DSLOT(i) (((i) & 0x400) != 0)
678 #define RELAX_MIPS16_JAL_DSLOT(i) (((i) & 0x800) != 0)
679 #define RELAX_MIPS16_EXTENDED(i) (((i) & 0x1000) != 0)
680 #define RELAX_MIPS16_MARK_EXTENDED(i) ((i) | 0x1000)
681 #define RELAX_MIPS16_CLEAR_EXTENDED(i) ((i) &~ 0x1000)
682 #define RELAX_MIPS16_LONG_BRANCH(i) (((i) & 0x2000) != 0)
683 #define RELAX_MIPS16_MARK_LONG_BRANCH(i) ((i) | 0x2000)
684 #define RELAX_MIPS16_CLEAR_LONG_BRANCH(i) ((i) &~ 0x2000)
686 /* Prototypes for static functions. */
689 #define internalError() \
690 as_fatal (_("internal Error, line %d, %s"), __LINE__, __FILE__)
692 #define internalError() as_fatal (_("MIPS internal Error"));
695 enum mips_regclass { MIPS_GR_REG, MIPS_FP_REG, MIPS16_REG };
697 static int insn_uses_reg PARAMS ((struct mips_cl_insn *ip,
698 unsigned int reg, enum mips_regclass class));
699 static int reg_needs_delay PARAMS ((unsigned int));
700 static void mips16_mark_labels PARAMS ((void));
701 static void append_insn PARAMS ((char *place,
702 struct mips_cl_insn * ip,
704 bfd_reloc_code_real_type *r,
706 static void mips_no_prev_insn PARAMS ((int));
707 static void mips_emit_delays PARAMS ((boolean));
709 static void macro_build PARAMS ((char *place, int *counter, expressionS * ep,
710 const char *name, const char *fmt,
713 static void macro_build ();
715 static void mips16_macro_build PARAMS ((char *, int *, expressionS *,
716 const char *, const char *,
718 static void macro_build_jalr PARAMS ((int, expressionS *));
719 static void macro_build_lui PARAMS ((char *place, int *counter,
720 expressionS * ep, int regnum));
721 static void set_at PARAMS ((int *counter, int reg, int unsignedp));
722 static void check_absolute_expr PARAMS ((struct mips_cl_insn * ip,
724 static void load_register PARAMS ((int *, int, expressionS *, int));
725 static void load_address PARAMS ((int *, int, expressionS *, int *));
726 static void move_register PARAMS ((int *, int, int));
727 static void macro PARAMS ((struct mips_cl_insn * ip));
728 static void mips16_macro PARAMS ((struct mips_cl_insn * ip));
729 #ifdef LOSING_COMPILER
730 static void macro2 PARAMS ((struct mips_cl_insn * ip));
732 static void mips_ip PARAMS ((char *str, struct mips_cl_insn * ip));
733 static void mips16_ip PARAMS ((char *str, struct mips_cl_insn * ip));
734 static void mips16_immed PARAMS ((char *, unsigned int, int, offsetT, boolean,
735 boolean, boolean, unsigned long *,
736 boolean *, unsigned short *));
737 static int my_getPercentOp PARAMS ((char **, unsigned int *, int *));
738 static int my_getSmallParser PARAMS ((char **, unsigned int *, int *));
739 static int my_getSmallExpression PARAMS ((expressionS *, char *));
740 static void my_getExpression PARAMS ((expressionS *, char *));
742 static int support_64bit_objects PARAMS((void));
744 static symbolS *get_symbol PARAMS ((void));
745 static void mips_align PARAMS ((int to, int fill, symbolS *label));
746 static void s_align PARAMS ((int));
747 static void s_change_sec PARAMS ((int));
748 static void s_cons PARAMS ((int));
749 static void s_float_cons PARAMS ((int));
750 static void s_mips_globl PARAMS ((int));
751 static void s_option PARAMS ((int));
752 static void s_mipsset PARAMS ((int));
753 static void s_abicalls PARAMS ((int));
754 static void s_cpload PARAMS ((int));
755 static void s_cpsetup PARAMS ((int));
756 static void s_cplocal PARAMS ((int));
757 static void s_cprestore PARAMS ((int));
758 static void s_cpreturn PARAMS ((int));
759 static void s_gpvalue PARAMS ((int));
760 static void s_gpword PARAMS ((int));
761 static void s_cpadd PARAMS ((int));
762 static void s_insn PARAMS ((int));
763 static void md_obj_begin PARAMS ((void));
764 static void md_obj_end PARAMS ((void));
765 static long get_number PARAMS ((void));
766 static void s_mips_ent PARAMS ((int));
767 static void s_mips_end PARAMS ((int));
768 static void s_mips_frame PARAMS ((int));
769 static void s_mips_mask PARAMS ((int));
770 static void s_mips_stab PARAMS ((int));
771 static void s_mips_weakext PARAMS ((int));
772 static void s_mips_file PARAMS ((int));
773 static void s_mips_loc PARAMS ((int));
774 static int mips16_extended_frag PARAMS ((fragS *, asection *, long));
775 static const char *mips_isa_to_str PARAMS ((int));
776 static const char *mips_cpu_to_str PARAMS ((int));
777 static int validate_mips_insn PARAMS ((const struct mips_opcode *));
778 static void show PARAMS ((FILE *, char *, int *, int *));
780 static int mips_need_elf_addend_fixup PARAMS ((fixS *));
783 /* Return values of my_getSmallExpression(). */
790 /* Direct relocation creation by %percent_op(). */
809 /* Table and functions used to map between CPU/ISA names, and
810 ISA levels, and CPU numbers. */
814 const char *name; /* CPU or ISA name. */
815 int is_isa; /* Is this an ISA? (If 0, a CPU.) */
816 int isa; /* ISA level. */
817 int cpu; /* CPU number (default CPU if ISA). */
820 static const struct mips_cpu_info *mips_cpu_info_from_name PARAMS ((const char *));
821 static const struct mips_cpu_info *mips_cpu_info_from_isa PARAMS ((int));
822 static const struct mips_cpu_info *mips_cpu_info_from_cpu PARAMS ((int));
826 The following pseudo-ops from the Kane and Heinrich MIPS book
827 should be defined here, but are currently unsupported: .alias,
828 .galive, .gjaldef, .gjrlive, .livereg, .noalias.
830 The following pseudo-ops from the Kane and Heinrich MIPS book are
831 specific to the type of debugging information being generated, and
832 should be defined by the object format: .aent, .begin, .bend,
833 .bgnb, .end, .endb, .ent, .fmask, .frame, .loc, .mask, .verstamp,
836 The following pseudo-ops from the Kane and Heinrich MIPS book are
837 not MIPS CPU specific, but are also not specific to the object file
838 format. This file is probably the best place to define them, but
839 they are not currently supported: .asm0, .endr, .lab, .repeat,
842 static const pseudo_typeS mips_pseudo_table[] =
844 /* MIPS specific pseudo-ops. */
845 {"option", s_option, 0},
846 {"set", s_mipsset, 0},
847 {"rdata", s_change_sec, 'r'},
848 {"sdata", s_change_sec, 's'},
849 {"livereg", s_ignore, 0},
850 {"abicalls", s_abicalls, 0},
851 {"cpload", s_cpload, 0},
852 {"cpsetup", s_cpsetup, 0},
853 {"cplocal", s_cplocal, 0},
854 {"cprestore", s_cprestore, 0},
855 {"cpreturn", s_cpreturn, 0},
856 {"gpvalue", s_gpvalue, 0},
857 {"gpword", s_gpword, 0},
858 {"cpadd", s_cpadd, 0},
861 /* Relatively generic pseudo-ops that happen to be used on MIPS
863 {"asciiz", stringer, 1},
864 {"bss", s_change_sec, 'b'},
867 {"dword", s_cons, 3},
868 {"weakext", s_mips_weakext, 0},
870 /* These pseudo-ops are defined in read.c, but must be overridden
871 here for one reason or another. */
872 {"align", s_align, 0},
874 {"data", s_change_sec, 'd'},
875 {"double", s_float_cons, 'd'},
876 {"float", s_float_cons, 'f'},
877 {"globl", s_mips_globl, 0},
878 {"global", s_mips_globl, 0},
879 {"hword", s_cons, 1},
884 {"short", s_cons, 1},
885 {"single", s_float_cons, 'f'},
886 {"stabn", s_mips_stab, 'n'},
887 {"text", s_change_sec, 't'},
890 { "extern", ecoff_directive_extern, 0},
895 static const pseudo_typeS mips_nonecoff_pseudo_table[] =
897 /* These pseudo-ops should be defined by the object file format.
898 However, a.out doesn't support them, so we have versions here. */
899 {"aent", s_mips_ent, 1},
900 {"bgnb", s_ignore, 0},
901 {"end", s_mips_end, 0},
902 {"endb", s_ignore, 0},
903 {"ent", s_mips_ent, 0},
904 {"file", s_mips_file, 0},
905 {"fmask", s_mips_mask, 'F'},
906 {"frame", s_mips_frame, 0},
907 {"loc", s_mips_loc, 0},
908 {"mask", s_mips_mask, 'R'},
909 {"verstamp", s_ignore, 0},
913 extern void pop_insert PARAMS ((const pseudo_typeS *));
918 pop_insert (mips_pseudo_table);
919 if (! ECOFF_DEBUGGING)
920 pop_insert (mips_nonecoff_pseudo_table);
923 /* Symbols labelling the current insn. */
925 struct insn_label_list
927 struct insn_label_list *next;
931 static struct insn_label_list *insn_labels;
932 static struct insn_label_list *free_insn_labels;
934 static void mips_clear_insn_labels PARAMS ((void));
937 mips_clear_insn_labels ()
939 register struct insn_label_list **pl;
941 for (pl = &free_insn_labels; *pl != NULL; pl = &(*pl)->next)
947 static char *expr_end;
949 /* Expressions which appear in instructions. These are set by
952 static expressionS imm_expr;
953 static expressionS offset_expr;
955 /* Relocs associated with imm_expr and offset_expr. */
957 static bfd_reloc_code_real_type imm_reloc[3]
958 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
959 static bfd_reloc_code_real_type offset_reloc[3]
960 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
962 /* This is set by mips_ip if imm_reloc is an unmatched HI16_S reloc. */
964 static boolean imm_unmatched_hi;
966 /* These are set by mips16_ip if an explicit extension is used. */
968 static boolean mips16_small, mips16_ext;
970 /* The pdr segment for per procedure frame/regmask info. Not used for
976 mips_isa_to_str (isa)
979 const struct mips_cpu_info *ci;
982 ci = mips_cpu_info_from_isa (isa);
986 sprintf (s, "ISA#%d", isa);
991 mips_cpu_to_str (cpu)
994 const struct mips_cpu_info *ci;
997 ci = mips_cpu_info_from_cpu (cpu);
1001 sprintf (s, "CPU#%d", cpu);
1005 /* The default target format to use. */
1008 mips_target_format ()
1010 switch (OUTPUT_FLAVOR)
1012 case bfd_target_aout_flavour:
1013 return target_big_endian ? "a.out-mips-big" : "a.out-mips-little";
1014 case bfd_target_ecoff_flavour:
1015 return target_big_endian ? "ecoff-bigmips" : ECOFF_LITTLE_FORMAT;
1016 case bfd_target_coff_flavour:
1018 case bfd_target_elf_flavour:
1020 /* This is traditional mips */
1021 return (target_big_endian
1022 ? (HAVE_64BIT_OBJECTS ? "elf64-tradbigmips"
1023 : "elf32-tradbigmips")
1024 : (HAVE_64BIT_OBJECTS ? "elf64-tradlittlemips"
1025 : "elf32-tradlittlemips"));
1027 return (target_big_endian
1028 ? (HAVE_64BIT_OBJECTS ? "elf64-bigmips" : "elf32-bigmips")
1029 : (HAVE_64BIT_OBJECTS ? "elf64-littlemips"
1030 : "elf32-littlemips"));
1038 /* This function is called once, at assembler startup time. It should
1039 set up all the tables, etc. that the MD part of the assembler will need. */
1044 register const char *retval = NULL;
1048 if (! bfd_set_arch_mach (stdoutput, bfd_arch_mips, mips_arch))
1049 as_warn (_("Could not set architecture and machine"));
1051 op_hash = hash_new ();
1053 for (i = 0; i < NUMOPCODES;)
1055 const char *name = mips_opcodes[i].name;
1057 retval = hash_insert (op_hash, name, (PTR) &mips_opcodes[i]);
1060 fprintf (stderr, _("internal error: can't hash `%s': %s\n"),
1061 mips_opcodes[i].name, retval);
1062 /* Probably a memory allocation problem? Give up now. */
1063 as_fatal (_("Broken assembler. No assembly attempted."));
1067 if (mips_opcodes[i].pinfo != INSN_MACRO)
1069 if (!validate_mips_insn (&mips_opcodes[i]))
1074 while ((i < NUMOPCODES) && !strcmp (mips_opcodes[i].name, name));
1077 mips16_op_hash = hash_new ();
1080 while (i < bfd_mips16_num_opcodes)
1082 const char *name = mips16_opcodes[i].name;
1084 retval = hash_insert (mips16_op_hash, name, (PTR) &mips16_opcodes[i]);
1086 as_fatal (_("internal: can't hash `%s': %s"),
1087 mips16_opcodes[i].name, retval);
1090 if (mips16_opcodes[i].pinfo != INSN_MACRO
1091 && ((mips16_opcodes[i].match & mips16_opcodes[i].mask)
1092 != mips16_opcodes[i].match))
1094 fprintf (stderr, _("internal error: bad mips16 opcode: %s %s\n"),
1095 mips16_opcodes[i].name, mips16_opcodes[i].args);
1100 while (i < bfd_mips16_num_opcodes
1101 && strcmp (mips16_opcodes[i].name, name) == 0);
1105 as_fatal (_("Broken assembler. No assembly attempted."));
1107 /* We add all the general register names to the symbol table. This
1108 helps us detect invalid uses of them. */
1109 for (i = 0; i < 32; i++)
1113 sprintf (buf, "$%d", i);
1114 symbol_table_insert (symbol_new (buf, reg_section, i,
1115 &zero_address_frag));
1117 symbol_table_insert (symbol_new ("$ra", reg_section, RA,
1118 &zero_address_frag));
1119 symbol_table_insert (symbol_new ("$fp", reg_section, FP,
1120 &zero_address_frag));
1121 symbol_table_insert (symbol_new ("$sp", reg_section, SP,
1122 &zero_address_frag));
1123 symbol_table_insert (symbol_new ("$gp", reg_section, GP,
1124 &zero_address_frag));
1125 symbol_table_insert (symbol_new ("$at", reg_section, AT,
1126 &zero_address_frag));
1127 symbol_table_insert (symbol_new ("$kt0", reg_section, KT0,
1128 &zero_address_frag));
1129 symbol_table_insert (symbol_new ("$kt1", reg_section, KT1,
1130 &zero_address_frag));
1131 symbol_table_insert (symbol_new ("$zero", reg_section, ZERO,
1132 &zero_address_frag));
1133 symbol_table_insert (symbol_new ("$pc", reg_section, -1,
1134 &zero_address_frag));
1136 mips_no_prev_insn (false);
1139 mips_cprmask[0] = 0;
1140 mips_cprmask[1] = 0;
1141 mips_cprmask[2] = 0;
1142 mips_cprmask[3] = 0;
1144 /* set the default alignment for the text section (2**2) */
1145 record_alignment (text_section, 2);
1147 if (USE_GLOBAL_POINTER_OPT)
1148 bfd_set_gp_size (stdoutput, g_switch_value);
1150 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
1152 /* On a native system, sections must be aligned to 16 byte
1153 boundaries. When configured for an embedded ELF target, we
1155 if (strcmp (TARGET_OS, "elf") != 0)
1157 (void) bfd_set_section_alignment (stdoutput, text_section, 4);
1158 (void) bfd_set_section_alignment (stdoutput, data_section, 4);
1159 (void) bfd_set_section_alignment (stdoutput, bss_section, 4);
1162 /* Create a .reginfo section for register masks and a .mdebug
1163 section for debugging information. */
1171 subseg = now_subseg;
1173 /* The ABI says this section should be loaded so that the
1174 running program can access it. However, we don't load it
1175 if we are configured for an embedded target */
1176 flags = SEC_READONLY | SEC_DATA;
1177 if (strcmp (TARGET_OS, "elf") != 0)
1178 flags |= SEC_ALLOC | SEC_LOAD;
1180 if (file_mips_abi != N64_ABI)
1182 sec = subseg_new (".reginfo", (subsegT) 0);
1184 bfd_set_section_flags (stdoutput, sec, flags);
1185 bfd_set_section_alignment (stdoutput, sec, HAVE_NEWABI ? 3 : 2);
1188 mips_regmask_frag = frag_more (sizeof (Elf32_External_RegInfo));
1193 /* The 64-bit ABI uses a .MIPS.options section rather than
1194 .reginfo section. */
1195 sec = subseg_new (".MIPS.options", (subsegT) 0);
1196 bfd_set_section_flags (stdoutput, sec, flags);
1197 bfd_set_section_alignment (stdoutput, sec, 3);
1200 /* Set up the option header. */
1202 Elf_Internal_Options opthdr;
1205 opthdr.kind = ODK_REGINFO;
1206 opthdr.size = (sizeof (Elf_External_Options)
1207 + sizeof (Elf64_External_RegInfo));
1210 f = frag_more (sizeof (Elf_External_Options));
1211 bfd_mips_elf_swap_options_out (stdoutput, &opthdr,
1212 (Elf_External_Options *) f);
1214 mips_regmask_frag = frag_more (sizeof (Elf64_External_RegInfo));
1219 if (ECOFF_DEBUGGING)
1221 sec = subseg_new (".mdebug", (subsegT) 0);
1222 (void) bfd_set_section_flags (stdoutput, sec,
1223 SEC_HAS_CONTENTS | SEC_READONLY);
1224 (void) bfd_set_section_alignment (stdoutput, sec, 2);
1227 else if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
1229 pdr_seg = subseg_new (".pdr", (subsegT) 0);
1230 (void) bfd_set_section_flags (stdoutput, pdr_seg,
1231 SEC_READONLY | SEC_RELOC
1233 (void) bfd_set_section_alignment (stdoutput, pdr_seg, 2);
1237 subseg_set (seg, subseg);
1241 if (! ECOFF_DEBUGGING)
1248 if (! ECOFF_DEBUGGING)
1256 struct mips_cl_insn insn;
1257 bfd_reloc_code_real_type unused_reloc[3]
1258 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
1260 imm_expr.X_op = O_absent;
1261 imm_unmatched_hi = false;
1262 offset_expr.X_op = O_absent;
1263 imm_reloc[0] = BFD_RELOC_UNUSED;
1264 imm_reloc[1] = BFD_RELOC_UNUSED;
1265 imm_reloc[2] = BFD_RELOC_UNUSED;
1266 offset_reloc[0] = BFD_RELOC_UNUSED;
1267 offset_reloc[1] = BFD_RELOC_UNUSED;
1268 offset_reloc[2] = BFD_RELOC_UNUSED;
1270 if (mips_opts.mips16)
1271 mips16_ip (str, &insn);
1274 mips_ip (str, &insn);
1275 DBG ((_("returned from mips_ip(%s) insn_opcode = 0x%x\n"),
1276 str, insn.insn_opcode));
1281 as_bad ("%s `%s'", insn_error, str);
1285 if (insn.insn_mo->pinfo == INSN_MACRO)
1287 if (mips_opts.mips16)
1288 mips16_macro (&insn);
1294 if (imm_expr.X_op != O_absent)
1295 append_insn (NULL, &insn, &imm_expr, imm_reloc, imm_unmatched_hi);
1296 else if (offset_expr.X_op != O_absent)
1297 append_insn (NULL, &insn, &offset_expr, offset_reloc, false);
1299 append_insn (NULL, &insn, NULL, unused_reloc, false);
1303 /* See whether instruction IP reads register REG. CLASS is the type
1307 insn_uses_reg (ip, reg, class)
1308 struct mips_cl_insn *ip;
1310 enum mips_regclass class;
1312 if (class == MIPS16_REG)
1314 assert (mips_opts.mips16);
1315 reg = mips16_to_32_reg_map[reg];
1316 class = MIPS_GR_REG;
1319 /* Don't report on general register ZERO, since it never changes. */
1320 if (class == MIPS_GR_REG && reg == ZERO)
1323 if (class == MIPS_FP_REG)
1325 assert (! mips_opts.mips16);
1326 /* If we are called with either $f0 or $f1, we must check $f0.
1327 This is not optimal, because it will introduce an unnecessary
1328 NOP between "lwc1 $f0" and "swc1 $f1". To fix this we would
1329 need to distinguish reading both $f0 and $f1 or just one of
1330 them. Note that we don't have to check the other way,
1331 because there is no instruction that sets both $f0 and $f1
1332 and requires a delay. */
1333 if ((ip->insn_mo->pinfo & INSN_READ_FPR_S)
1334 && ((((ip->insn_opcode >> OP_SH_FS) & OP_MASK_FS) &~(unsigned)1)
1335 == (reg &~ (unsigned) 1)))
1337 if ((ip->insn_mo->pinfo & INSN_READ_FPR_T)
1338 && ((((ip->insn_opcode >> OP_SH_FT) & OP_MASK_FT) &~(unsigned)1)
1339 == (reg &~ (unsigned) 1)))
1342 else if (! mips_opts.mips16)
1344 if ((ip->insn_mo->pinfo & INSN_READ_GPR_S)
1345 && ((ip->insn_opcode >> OP_SH_RS) & OP_MASK_RS) == reg)
1347 if ((ip->insn_mo->pinfo & INSN_READ_GPR_T)
1348 && ((ip->insn_opcode >> OP_SH_RT) & OP_MASK_RT) == reg)
1353 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_X)
1354 && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_RX)
1355 & MIPS16OP_MASK_RX)]
1358 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_Y)
1359 && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_RY)
1360 & MIPS16OP_MASK_RY)]
1363 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_Z)
1364 && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_MOVE32Z)
1365 & MIPS16OP_MASK_MOVE32Z)]
1368 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_T) && reg == TREG)
1370 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_SP) && reg == SP)
1372 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_31) && reg == RA)
1374 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_GPR_X)
1375 && ((ip->insn_opcode >> MIPS16OP_SH_REGR32)
1376 & MIPS16OP_MASK_REGR32) == reg)
1383 /* This function returns true if modifying a register requires a
1387 reg_needs_delay (reg)
1390 unsigned long prev_pinfo;
1392 prev_pinfo = prev_insn.insn_mo->pinfo;
1393 if (! mips_opts.noreorder
1394 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1395 && ((prev_pinfo & INSN_LOAD_COPROC_DELAY)
1396 || (! gpr_interlocks
1397 && (prev_pinfo & INSN_LOAD_MEMORY_DELAY))))
1399 /* A load from a coprocessor or from memory. All load
1400 delays delay the use of general register rt for one
1401 instruction on the r3000. The r6000 and r4000 use
1403 /* Itbl support may require additional care here. */
1404 know (prev_pinfo & INSN_WRITE_GPR_T);
1405 if (reg == ((prev_insn.insn_opcode >> OP_SH_RT) & OP_MASK_RT))
1412 /* Mark instruction labels in mips16 mode. This permits the linker to
1413 handle them specially, such as generating jalx instructions when
1414 needed. We also make them odd for the duration of the assembly, in
1415 order to generate the right sort of code. We will make them even
1416 in the adjust_symtab routine, while leaving them marked. This is
1417 convenient for the debugger and the disassembler. The linker knows
1418 to make them odd again. */
1421 mips16_mark_labels ()
1423 if (mips_opts.mips16)
1425 struct insn_label_list *l;
1428 for (l = insn_labels; l != NULL; l = l->next)
1431 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
1432 S_SET_OTHER (l->label, STO_MIPS16);
1434 val = S_GET_VALUE (l->label);
1436 S_SET_VALUE (l->label, val + 1);
1441 /* Output an instruction. PLACE is where to put the instruction; if
1442 it is NULL, this uses frag_more to get room. IP is the instruction
1443 information. ADDRESS_EXPR is an operand of the instruction to be
1444 used with RELOC_TYPE. */
1447 append_insn (place, ip, address_expr, reloc_type, unmatched_hi)
1449 struct mips_cl_insn *ip;
1450 expressionS *address_expr;
1451 bfd_reloc_code_real_type *reloc_type;
1452 boolean unmatched_hi;
1454 register unsigned long prev_pinfo, pinfo;
1459 /* Mark instruction labels in mips16 mode. */
1460 mips16_mark_labels ();
1462 prev_pinfo = prev_insn.insn_mo->pinfo;
1463 pinfo = ip->insn_mo->pinfo;
1465 if (place == NULL && (! mips_opts.noreorder || prev_nop_frag != NULL))
1469 /* If the previous insn required any delay slots, see if we need
1470 to insert a NOP or two. There are eight kinds of possible
1471 hazards, of which an instruction can have at most one type.
1472 (1) a load from memory delay
1473 (2) a load from a coprocessor delay
1474 (3) an unconditional branch delay
1475 (4) a conditional branch delay
1476 (5) a move to coprocessor register delay
1477 (6) a load coprocessor register from memory delay
1478 (7) a coprocessor condition code delay
1479 (8) a HI/LO special register delay
1481 There are a lot of optimizations we could do that we don't.
1482 In particular, we do not, in general, reorder instructions.
1483 If you use gcc with optimization, it will reorder
1484 instructions and generally do much more optimization then we
1485 do here; repeating all that work in the assembler would only
1486 benefit hand written assembly code, and does not seem worth
1489 /* This is how a NOP is emitted. */
1490 #define emit_nop() \
1492 ? md_number_to_chars (frag_more (2), 0x6500, 2) \
1493 : md_number_to_chars (frag_more (4), 0, 4))
1495 /* The previous insn might require a delay slot, depending upon
1496 the contents of the current insn. */
1497 if (! mips_opts.mips16
1498 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1499 && (((prev_pinfo & INSN_LOAD_COPROC_DELAY)
1500 && ! cop_interlocks)
1501 || (! gpr_interlocks
1502 && (prev_pinfo & INSN_LOAD_MEMORY_DELAY))))
1504 /* A load from a coprocessor or from memory. All load
1505 delays delay the use of general register rt for one
1506 instruction on the r3000. The r6000 and r4000 use
1508 /* Itbl support may require additional care here. */
1509 know (prev_pinfo & INSN_WRITE_GPR_T);
1510 if (mips_optimize == 0
1511 || insn_uses_reg (ip,
1512 ((prev_insn.insn_opcode >> OP_SH_RT)
1517 else if (! mips_opts.mips16
1518 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1519 && (((prev_pinfo & INSN_COPROC_MOVE_DELAY)
1520 && ! cop_interlocks)
1521 || (mips_opts.isa == ISA_MIPS1
1522 && (prev_pinfo & INSN_COPROC_MEMORY_DELAY))))
1524 /* A generic coprocessor delay. The previous instruction
1525 modified a coprocessor general or control register. If
1526 it modified a control register, we need to avoid any
1527 coprocessor instruction (this is probably not always
1528 required, but it sometimes is). If it modified a general
1529 register, we avoid using that register.
1531 On the r6000 and r4000 loading a coprocessor register
1532 from memory is interlocked, and does not require a delay.
1534 This case is not handled very well. There is no special
1535 knowledge of CP0 handling, and the coprocessors other
1536 than the floating point unit are not distinguished at
1538 /* Itbl support may require additional care here. FIXME!
1539 Need to modify this to include knowledge about
1540 user specified delays! */
1541 if (prev_pinfo & INSN_WRITE_FPR_T)
1543 if (mips_optimize == 0
1544 || insn_uses_reg (ip,
1545 ((prev_insn.insn_opcode >> OP_SH_FT)
1550 else if (prev_pinfo & INSN_WRITE_FPR_S)
1552 if (mips_optimize == 0
1553 || insn_uses_reg (ip,
1554 ((prev_insn.insn_opcode >> OP_SH_FS)
1561 /* We don't know exactly what the previous instruction
1562 does. If the current instruction uses a coprocessor
1563 register, we must insert a NOP. If previous
1564 instruction may set the condition codes, and the
1565 current instruction uses them, we must insert two
1567 /* Itbl support may require additional care here. */
1568 if (mips_optimize == 0
1569 || ((prev_pinfo & INSN_WRITE_COND_CODE)
1570 && (pinfo & INSN_READ_COND_CODE)))
1572 else if (pinfo & INSN_COP)
1576 else if (! mips_opts.mips16
1577 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1578 && (prev_pinfo & INSN_WRITE_COND_CODE)
1579 && ! cop_interlocks)
1581 /* The previous instruction sets the coprocessor condition
1582 codes, but does not require a general coprocessor delay
1583 (this means it is a floating point comparison
1584 instruction). If this instruction uses the condition
1585 codes, we need to insert a single NOP. */
1586 /* Itbl support may require additional care here. */
1587 if (mips_optimize == 0
1588 || (pinfo & INSN_READ_COND_CODE))
1592 /* If we're fixing up mfhi/mflo for the r7000 and the
1593 previous insn was an mfhi/mflo and the current insn
1594 reads the register that the mfhi/mflo wrote to, then
1597 else if (mips_7000_hilo_fix
1598 && MF_HILO_INSN (prev_pinfo)
1599 && insn_uses_reg (ip, ((prev_insn.insn_opcode >> OP_SH_RD)
1606 /* If we're fixing up mfhi/mflo for the r7000 and the
1607 2nd previous insn was an mfhi/mflo and the current insn
1608 reads the register that the mfhi/mflo wrote to, then
1611 else if (mips_7000_hilo_fix
1612 && MF_HILO_INSN (prev_prev_insn.insn_opcode)
1613 && insn_uses_reg (ip, ((prev_prev_insn.insn_opcode >> OP_SH_RD)
1621 else if (prev_pinfo & INSN_READ_LO)
1623 /* The previous instruction reads the LO register; if the
1624 current instruction writes to the LO register, we must
1625 insert two NOPS. Some newer processors have interlocks.
1626 Also the tx39's multiply instructions can be exectuted
1627 immediatly after a read from HI/LO (without the delay),
1628 though the tx39's divide insns still do require the
1630 if (! (hilo_interlocks
1631 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT)))
1632 && (mips_optimize == 0
1633 || (pinfo & INSN_WRITE_LO)))
1635 /* Most mips16 branch insns don't have a delay slot.
1636 If a read from LO is immediately followed by a branch
1637 to a write to LO we have a read followed by a write
1638 less than 2 insns away. We assume the target of
1639 a branch might be a write to LO, and insert a nop
1640 between a read and an immediately following branch. */
1641 else if (mips_opts.mips16
1642 && (mips_optimize == 0
1643 || (pinfo & MIPS16_INSN_BRANCH)))
1646 else if (prev_insn.insn_mo->pinfo & INSN_READ_HI)
1648 /* The previous instruction reads the HI register; if the
1649 current instruction writes to the HI register, we must
1650 insert a NOP. Some newer processors have interlocks.
1651 Also the note tx39's multiply above. */
1652 if (! (hilo_interlocks
1653 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT)))
1654 && (mips_optimize == 0
1655 || (pinfo & INSN_WRITE_HI)))
1657 /* Most mips16 branch insns don't have a delay slot.
1658 If a read from HI is immediately followed by a branch
1659 to a write to HI we have a read followed by a write
1660 less than 2 insns away. We assume the target of
1661 a branch might be a write to HI, and insert a nop
1662 between a read and an immediately following branch. */
1663 else if (mips_opts.mips16
1664 && (mips_optimize == 0
1665 || (pinfo & MIPS16_INSN_BRANCH)))
1669 /* If the previous instruction was in a noreorder section, then
1670 we don't want to insert the nop after all. */
1671 /* Itbl support may require additional care here. */
1672 if (prev_insn_unreordered)
1675 /* There are two cases which require two intervening
1676 instructions: 1) setting the condition codes using a move to
1677 coprocessor instruction which requires a general coprocessor
1678 delay and then reading the condition codes 2) reading the HI
1679 or LO register and then writing to it (except on processors
1680 which have interlocks). If we are not already emitting a NOP
1681 instruction, we must check for these cases compared to the
1682 instruction previous to the previous instruction. */
1683 if ((! mips_opts.mips16
1684 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1685 && (prev_prev_insn.insn_mo->pinfo & INSN_COPROC_MOVE_DELAY)
1686 && (prev_prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE)
1687 && (pinfo & INSN_READ_COND_CODE)
1688 && ! cop_interlocks)
1689 || ((prev_prev_insn.insn_mo->pinfo & INSN_READ_LO)
1690 && (pinfo & INSN_WRITE_LO)
1691 && ! (hilo_interlocks
1692 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT))))
1693 || ((prev_prev_insn.insn_mo->pinfo & INSN_READ_HI)
1694 && (pinfo & INSN_WRITE_HI)
1695 && ! (hilo_interlocks
1696 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT)))))
1701 if (prev_prev_insn_unreordered)
1704 if (prev_prev_nop && nops == 0)
1707 /* If we are being given a nop instruction, don't bother with
1708 one of the nops we would otherwise output. This will only
1709 happen when a nop instruction is used with mips_optimize set
1712 && ! mips_opts.noreorder
1713 && ip->insn_opcode == (unsigned) (mips_opts.mips16 ? 0x6500 : 0))
1716 /* Now emit the right number of NOP instructions. */
1717 if (nops > 0 && ! mips_opts.noreorder)
1720 unsigned long old_frag_offset;
1722 struct insn_label_list *l;
1724 old_frag = frag_now;
1725 old_frag_offset = frag_now_fix ();
1727 for (i = 0; i < nops; i++)
1732 listing_prev_line ();
1733 /* We may be at the start of a variant frag. In case we
1734 are, make sure there is enough space for the frag
1735 after the frags created by listing_prev_line. The
1736 argument to frag_grow here must be at least as large
1737 as the argument to all other calls to frag_grow in
1738 this file. We don't have to worry about being in the
1739 middle of a variant frag, because the variants insert
1740 all needed nop instructions themselves. */
1744 for (l = insn_labels; l != NULL; l = l->next)
1748 assert (S_GET_SEGMENT (l->label) == now_seg);
1749 symbol_set_frag (l->label, frag_now);
1750 val = (valueT) frag_now_fix ();
1751 /* mips16 text labels are stored as odd. */
1752 if (mips_opts.mips16)
1754 S_SET_VALUE (l->label, val);
1757 #ifndef NO_ECOFF_DEBUGGING
1758 if (ECOFF_DEBUGGING)
1759 ecoff_fix_loc (old_frag, old_frag_offset);
1762 else if (prev_nop_frag != NULL)
1764 /* We have a frag holding nops we may be able to remove. If
1765 we don't need any nops, we can decrease the size of
1766 prev_nop_frag by the size of one instruction. If we do
1767 need some nops, we count them in prev_nops_required. */
1768 if (prev_nop_frag_since == 0)
1772 prev_nop_frag->fr_fix -= mips_opts.mips16 ? 2 : 4;
1773 --prev_nop_frag_holds;
1776 prev_nop_frag_required += nops;
1780 if (prev_prev_nop == 0)
1782 prev_nop_frag->fr_fix -= mips_opts.mips16 ? 2 : 4;
1783 --prev_nop_frag_holds;
1786 ++prev_nop_frag_required;
1789 if (prev_nop_frag_holds <= prev_nop_frag_required)
1790 prev_nop_frag = NULL;
1792 ++prev_nop_frag_since;
1794 /* Sanity check: by the time we reach the second instruction
1795 after prev_nop_frag, we should have used up all the nops
1796 one way or another. */
1797 assert (prev_nop_frag_since <= 1 || prev_nop_frag == NULL);
1801 if (*reloc_type > BFD_RELOC_UNUSED)
1803 /* We need to set up a variant frag. */
1804 assert (mips_opts.mips16 && address_expr != NULL);
1805 f = frag_var (rs_machine_dependent, 4, 0,
1806 RELAX_MIPS16_ENCODE (*reloc_type - BFD_RELOC_UNUSED,
1807 mips16_small, mips16_ext,
1809 & INSN_UNCOND_BRANCH_DELAY),
1810 (*prev_insn_reloc_type
1811 == BFD_RELOC_MIPS16_JMP)),
1812 make_expr_symbol (address_expr), 0, NULL);
1814 else if (place != NULL)
1816 else if (mips_opts.mips16
1818 && *reloc_type != BFD_RELOC_MIPS16_JMP)
1820 /* Make sure there is enough room to swap this instruction with
1821 a following jump instruction. */
1827 if (mips_opts.mips16
1828 && mips_opts.noreorder
1829 && (prev_pinfo & INSN_UNCOND_BRANCH_DELAY) != 0)
1830 as_warn (_("extended instruction in delay slot"));
1835 fixp[0] = fixp[1] = fixp[2] = NULL;
1836 if (address_expr != NULL && *reloc_type < BFD_RELOC_UNUSED)
1838 if (address_expr->X_op == O_constant)
1842 switch (*reloc_type)
1845 ip->insn_opcode |= address_expr->X_add_number;
1848 case BFD_RELOC_MIPS_HIGHEST:
1849 tmp = (address_expr->X_add_number + 0x800080008000) >> 16;
1851 ip->insn_opcode |= (tmp >> 16) & 0xffff;
1854 case BFD_RELOC_MIPS_HIGHER:
1855 tmp = (address_expr->X_add_number + 0x80008000) >> 16;
1856 ip->insn_opcode |= (tmp >> 16) & 0xffff;
1859 case BFD_RELOC_HI16_S:
1860 ip->insn_opcode |= ((address_expr->X_add_number + 0x8000)
1864 case BFD_RELOC_HI16:
1865 ip->insn_opcode |= (address_expr->X_add_number >> 16) & 0xffff;
1868 case BFD_RELOC_LO16:
1869 ip->insn_opcode |= address_expr->X_add_number & 0xffff;
1872 case BFD_RELOC_MIPS_JMP:
1873 if ((address_expr->X_add_number & 3) != 0)
1874 as_bad (_("jump to misaligned address (0x%lx)"),
1875 (unsigned long) address_expr->X_add_number);
1876 if (address_expr->X_add_number & ~0xfffffff
1877 || address_expr->X_add_number > 0x7fffffc)
1878 as_bad (_("jump address range overflow (0x%lx)"),
1879 (unsigned long) address_expr->X_add_number);
1880 ip->insn_opcode |= (address_expr->X_add_number >> 2) & 0x3ffffff;
1883 case BFD_RELOC_MIPS16_JMP:
1884 if ((address_expr->X_add_number & 3) != 0)
1885 as_bad (_("jump to misaligned address (0x%lx)"),
1886 (unsigned long) address_expr->X_add_number);
1887 if (address_expr->X_add_number & ~0xfffffff
1888 || address_expr->X_add_number > 0x7fffffc)
1889 as_bad (_("jump address range overflow (0x%lx)"),
1890 (unsigned long) address_expr->X_add_number);
1892 (((address_expr->X_add_number & 0x7c0000) << 3)
1893 | ((address_expr->X_add_number & 0xf800000) >> 7)
1894 | ((address_expr->X_add_number & 0x3fffc) >> 2));
1897 case BFD_RELOC_16_PCREL:
1898 ip->insn_opcode |= address_expr->X_add_number & 0xffff;
1901 case BFD_RELOC_16_PCREL_S2:
1911 /* Don't generate a reloc if we are writing into a variant frag. */
1914 fixp[0] = fix_new_exp (frag_now, f - frag_now->fr_literal, 4,
1916 (*reloc_type == BFD_RELOC_16_PCREL
1917 || *reloc_type == BFD_RELOC_16_PCREL_S2),
1920 /* These relocations can have an addend that won't fit in
1921 4 octets for 64bit assembly. */
1922 if (HAVE_64BIT_GPRS &&
1923 (*reloc_type == BFD_RELOC_16
1924 || *reloc_type == BFD_RELOC_32
1925 || *reloc_type == BFD_RELOC_MIPS_JMP
1926 || *reloc_type == BFD_RELOC_HI16_S
1927 || *reloc_type == BFD_RELOC_LO16
1928 || *reloc_type == BFD_RELOC_GPREL16
1929 || *reloc_type == BFD_RELOC_MIPS_LITERAL
1930 || *reloc_type == BFD_RELOC_GPREL32
1931 || *reloc_type == BFD_RELOC_64
1932 || *reloc_type == BFD_RELOC_CTOR
1933 || *reloc_type == BFD_RELOC_MIPS_SUB
1934 || *reloc_type == BFD_RELOC_MIPS_HIGHEST
1935 || *reloc_type == BFD_RELOC_MIPS_HIGHER
1936 || *reloc_type == BFD_RELOC_MIPS_SCN_DISP
1937 || *reloc_type == BFD_RELOC_MIPS_REL16
1938 || *reloc_type == BFD_RELOC_MIPS_RELGOT))
1939 fixp[0]->fx_no_overflow = 1;
1943 struct mips_hi_fixup *hi_fixup;
1945 assert (*reloc_type == BFD_RELOC_HI16_S);
1946 hi_fixup = ((struct mips_hi_fixup *)
1947 xmalloc (sizeof (struct mips_hi_fixup)));
1948 hi_fixup->fixp = fixp[0];
1949 hi_fixup->seg = now_seg;
1950 hi_fixup->next = mips_hi_fixup_list;
1951 mips_hi_fixup_list = hi_fixup;
1954 if (reloc_type[1] != BFD_RELOC_UNUSED)
1956 /* FIXME: This symbol can be one of
1957 RSS_UNDEF, RSS_GP, RSS_GP0, RSS_LOC. */
1958 address_expr->X_op = O_absent;
1959 address_expr->X_add_symbol = 0;
1960 address_expr->X_add_number = 0;
1962 fixp[1] = fix_new_exp (frag_now, f - frag_now->fr_literal,
1963 4, address_expr, false,
1966 /* These relocations can have an addend that won't fit in
1967 4 octets for 64bit assembly. */
1968 if (HAVE_64BIT_GPRS &&
1969 (*reloc_type == BFD_RELOC_16
1970 || *reloc_type == BFD_RELOC_32
1971 || *reloc_type == BFD_RELOC_MIPS_JMP
1972 || *reloc_type == BFD_RELOC_HI16_S
1973 || *reloc_type == BFD_RELOC_LO16
1974 || *reloc_type == BFD_RELOC_GPREL16
1975 || *reloc_type == BFD_RELOC_MIPS_LITERAL
1976 || *reloc_type == BFD_RELOC_GPREL32
1977 || *reloc_type == BFD_RELOC_64
1978 || *reloc_type == BFD_RELOC_CTOR
1979 || *reloc_type == BFD_RELOC_MIPS_SUB
1980 || *reloc_type == BFD_RELOC_MIPS_HIGHEST
1981 || *reloc_type == BFD_RELOC_MIPS_HIGHER
1982 || *reloc_type == BFD_RELOC_MIPS_SCN_DISP
1983 || *reloc_type == BFD_RELOC_MIPS_REL16
1984 || *reloc_type == BFD_RELOC_MIPS_RELGOT))
1985 fixp[1]->fx_no_overflow = 1;
1987 if (reloc_type[2] != BFD_RELOC_UNUSED)
1989 address_expr->X_op = O_absent;
1990 address_expr->X_add_symbol = 0;
1991 address_expr->X_add_number = 0;
1993 fixp[2] = fix_new_exp (frag_now,
1994 f - frag_now->fr_literal, 4,
1995 address_expr, false,
1998 /* These relocations can have an addend that won't fit in
1999 4 octets for 64bit assembly. */
2000 if (HAVE_64BIT_GPRS &&
2001 (*reloc_type == BFD_RELOC_16
2002 || *reloc_type == BFD_RELOC_32
2003 || *reloc_type == BFD_RELOC_MIPS_JMP
2004 || *reloc_type == BFD_RELOC_HI16_S
2005 || *reloc_type == BFD_RELOC_LO16
2006 || *reloc_type == BFD_RELOC_GPREL16
2007 || *reloc_type == BFD_RELOC_MIPS_LITERAL
2008 || *reloc_type == BFD_RELOC_GPREL32
2009 || *reloc_type == BFD_RELOC_64
2010 || *reloc_type == BFD_RELOC_CTOR
2011 || *reloc_type == BFD_RELOC_MIPS_SUB
2012 || *reloc_type == BFD_RELOC_MIPS_HIGHEST
2013 || *reloc_type == BFD_RELOC_MIPS_HIGHER
2014 || *reloc_type == BFD_RELOC_MIPS_SCN_DISP
2015 || *reloc_type == BFD_RELOC_MIPS_REL16
2016 || *reloc_type == BFD_RELOC_MIPS_RELGOT))
2017 fixp[2]->fx_no_overflow = 1;
2024 if (! mips_opts.mips16)
2026 md_number_to_chars (f, ip->insn_opcode, 4);
2028 dwarf2_emit_insn (4);
2031 else if (*reloc_type == BFD_RELOC_MIPS16_JMP)
2033 md_number_to_chars (f, ip->insn_opcode >> 16, 2);
2034 md_number_to_chars (f + 2, ip->insn_opcode & 0xffff, 2);
2036 dwarf2_emit_insn (4);
2043 md_number_to_chars (f, 0xf000 | ip->extend, 2);
2046 md_number_to_chars (f, ip->insn_opcode, 2);
2048 dwarf2_emit_insn (ip->use_extend ? 4 : 2);
2052 /* Update the register mask information. */
2053 if (! mips_opts.mips16)
2055 if (pinfo & INSN_WRITE_GPR_D)
2056 mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD);
2057 if ((pinfo & (INSN_WRITE_GPR_T | INSN_READ_GPR_T)) != 0)
2058 mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RT) & OP_MASK_RT);
2059 if (pinfo & INSN_READ_GPR_S)
2060 mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RS) & OP_MASK_RS);
2061 if (pinfo & INSN_WRITE_GPR_31)
2062 mips_gprmask |= 1 << RA;
2063 if (pinfo & INSN_WRITE_FPR_D)
2064 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FD) & OP_MASK_FD);
2065 if ((pinfo & (INSN_WRITE_FPR_S | INSN_READ_FPR_S)) != 0)
2066 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FS) & OP_MASK_FS);
2067 if ((pinfo & (INSN_WRITE_FPR_T | INSN_READ_FPR_T)) != 0)
2068 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FT) & OP_MASK_FT);
2069 if ((pinfo & INSN_READ_FPR_R) != 0)
2070 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FR) & OP_MASK_FR);
2071 if (pinfo & INSN_COP)
2073 /* We don't keep enough information to sort these cases out.
2074 The itbl support does keep this information however, although
2075 we currently don't support itbl fprmats as part of the cop
2076 instruction. May want to add this support in the future. */
2078 /* Never set the bit for $0, which is always zero. */
2079 mips_gprmask &= ~1 << 0;
2083 if (pinfo & (MIPS16_INSN_WRITE_X | MIPS16_INSN_READ_X))
2084 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RX)
2085 & MIPS16OP_MASK_RX);
2086 if (pinfo & (MIPS16_INSN_WRITE_Y | MIPS16_INSN_READ_Y))
2087 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RY)
2088 & MIPS16OP_MASK_RY);
2089 if (pinfo & MIPS16_INSN_WRITE_Z)
2090 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RZ)
2091 & MIPS16OP_MASK_RZ);
2092 if (pinfo & (MIPS16_INSN_WRITE_T | MIPS16_INSN_READ_T))
2093 mips_gprmask |= 1 << TREG;
2094 if (pinfo & (MIPS16_INSN_WRITE_SP | MIPS16_INSN_READ_SP))
2095 mips_gprmask |= 1 << SP;
2096 if (pinfo & (MIPS16_INSN_WRITE_31 | MIPS16_INSN_READ_31))
2097 mips_gprmask |= 1 << RA;
2098 if (pinfo & MIPS16_INSN_WRITE_GPR_Y)
2099 mips_gprmask |= 1 << MIPS16OP_EXTRACT_REG32R (ip->insn_opcode);
2100 if (pinfo & MIPS16_INSN_READ_Z)
2101 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_MOVE32Z)
2102 & MIPS16OP_MASK_MOVE32Z);
2103 if (pinfo & MIPS16_INSN_READ_GPR_X)
2104 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_REGR32)
2105 & MIPS16OP_MASK_REGR32);
2108 if (place == NULL && ! mips_opts.noreorder)
2110 /* Filling the branch delay slot is more complex. We try to
2111 switch the branch with the previous instruction, which we can
2112 do if the previous instruction does not set up a condition
2113 that the branch tests and if the branch is not itself the
2114 target of any branch. */
2115 if ((pinfo & INSN_UNCOND_BRANCH_DELAY)
2116 || (pinfo & INSN_COND_BRANCH_DELAY))
2118 if (mips_optimize < 2
2119 /* If we have seen .set volatile or .set nomove, don't
2121 || mips_opts.nomove != 0
2122 /* If we had to emit any NOP instructions, then we
2123 already know we can not swap. */
2125 /* If we don't even know the previous insn, we can not
2127 || ! prev_insn_valid
2128 /* If the previous insn is already in a branch delay
2129 slot, then we can not swap. */
2130 || prev_insn_is_delay_slot
2131 /* If the previous previous insn was in a .set
2132 noreorder, we can't swap. Actually, the MIPS
2133 assembler will swap in this situation. However, gcc
2134 configured -with-gnu-as will generate code like
2140 in which we can not swap the bne and INSN. If gcc is
2141 not configured -with-gnu-as, it does not output the
2142 .set pseudo-ops. We don't have to check
2143 prev_insn_unreordered, because prev_insn_valid will
2144 be 0 in that case. We don't want to use
2145 prev_prev_insn_valid, because we do want to be able
2146 to swap at the start of a function. */
2147 || prev_prev_insn_unreordered
2148 /* If the branch is itself the target of a branch, we
2149 can not swap. We cheat on this; all we check for is
2150 whether there is a label on this instruction. If
2151 there are any branches to anything other than a
2152 label, users must use .set noreorder. */
2153 || insn_labels != NULL
2154 /* If the previous instruction is in a variant frag, we
2155 can not do the swap. This does not apply to the
2156 mips16, which uses variant frags for different
2158 || (! mips_opts.mips16
2159 && prev_insn_frag->fr_type == rs_machine_dependent)
2160 /* If the branch reads the condition codes, we don't
2161 even try to swap, because in the sequence
2166 we can not swap, and I don't feel like handling that
2168 || (! mips_opts.mips16
2169 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2170 && (pinfo & INSN_READ_COND_CODE))
2171 /* We can not swap with an instruction that requires a
2172 delay slot, becase the target of the branch might
2173 interfere with that instruction. */
2174 || (! mips_opts.mips16
2175 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2177 /* Itbl support may require additional care here. */
2178 & (INSN_LOAD_COPROC_DELAY
2179 | INSN_COPROC_MOVE_DELAY
2180 | INSN_WRITE_COND_CODE)))
2181 || (! (hilo_interlocks
2182 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT)))
2186 || (! mips_opts.mips16
2188 && (prev_pinfo & INSN_LOAD_MEMORY_DELAY))
2189 || (! mips_opts.mips16
2190 && mips_opts.isa == ISA_MIPS1
2191 /* Itbl support may require additional care here. */
2192 && (prev_pinfo & INSN_COPROC_MEMORY_DELAY))
2193 /* We can not swap with a branch instruction. */
2195 & (INSN_UNCOND_BRANCH_DELAY
2196 | INSN_COND_BRANCH_DELAY
2197 | INSN_COND_BRANCH_LIKELY))
2198 /* We do not swap with a trap instruction, since it
2199 complicates trap handlers to have the trap
2200 instruction be in a delay slot. */
2201 || (prev_pinfo & INSN_TRAP)
2202 /* If the branch reads a register that the previous
2203 instruction sets, we can not swap. */
2204 || (! mips_opts.mips16
2205 && (prev_pinfo & INSN_WRITE_GPR_T)
2206 && insn_uses_reg (ip,
2207 ((prev_insn.insn_opcode >> OP_SH_RT)
2210 || (! mips_opts.mips16
2211 && (prev_pinfo & INSN_WRITE_GPR_D)
2212 && insn_uses_reg (ip,
2213 ((prev_insn.insn_opcode >> OP_SH_RD)
2216 || (mips_opts.mips16
2217 && (((prev_pinfo & MIPS16_INSN_WRITE_X)
2218 && insn_uses_reg (ip,
2219 ((prev_insn.insn_opcode
2221 & MIPS16OP_MASK_RX),
2223 || ((prev_pinfo & MIPS16_INSN_WRITE_Y)
2224 && insn_uses_reg (ip,
2225 ((prev_insn.insn_opcode
2227 & MIPS16OP_MASK_RY),
2229 || ((prev_pinfo & MIPS16_INSN_WRITE_Z)
2230 && insn_uses_reg (ip,
2231 ((prev_insn.insn_opcode
2233 & MIPS16OP_MASK_RZ),
2235 || ((prev_pinfo & MIPS16_INSN_WRITE_T)
2236 && insn_uses_reg (ip, TREG, MIPS_GR_REG))
2237 || ((prev_pinfo & MIPS16_INSN_WRITE_31)
2238 && insn_uses_reg (ip, RA, MIPS_GR_REG))
2239 || ((prev_pinfo & MIPS16_INSN_WRITE_GPR_Y)
2240 && insn_uses_reg (ip,
2241 MIPS16OP_EXTRACT_REG32R (prev_insn.
2244 /* If the branch writes a register that the previous
2245 instruction sets, we can not swap (we know that
2246 branches write only to RD or to $31). */
2247 || (! mips_opts.mips16
2248 && (prev_pinfo & INSN_WRITE_GPR_T)
2249 && (((pinfo & INSN_WRITE_GPR_D)
2250 && (((prev_insn.insn_opcode >> OP_SH_RT) & OP_MASK_RT)
2251 == ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD)))
2252 || ((pinfo & INSN_WRITE_GPR_31)
2253 && (((prev_insn.insn_opcode >> OP_SH_RT)
2256 || (! mips_opts.mips16
2257 && (prev_pinfo & INSN_WRITE_GPR_D)
2258 && (((pinfo & INSN_WRITE_GPR_D)
2259 && (((prev_insn.insn_opcode >> OP_SH_RD) & OP_MASK_RD)
2260 == ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD)))
2261 || ((pinfo & INSN_WRITE_GPR_31)
2262 && (((prev_insn.insn_opcode >> OP_SH_RD)
2265 || (mips_opts.mips16
2266 && (pinfo & MIPS16_INSN_WRITE_31)
2267 && ((prev_pinfo & MIPS16_INSN_WRITE_31)
2268 || ((prev_pinfo & MIPS16_INSN_WRITE_GPR_Y)
2269 && (MIPS16OP_EXTRACT_REG32R (prev_insn.insn_opcode)
2271 /* If the branch writes a register that the previous
2272 instruction reads, we can not swap (we know that
2273 branches only write to RD or to $31). */
2274 || (! mips_opts.mips16
2275 && (pinfo & INSN_WRITE_GPR_D)
2276 && insn_uses_reg (&prev_insn,
2277 ((ip->insn_opcode >> OP_SH_RD)
2280 || (! mips_opts.mips16
2281 && (pinfo & INSN_WRITE_GPR_31)
2282 && insn_uses_reg (&prev_insn, RA, MIPS_GR_REG))
2283 || (mips_opts.mips16
2284 && (pinfo & MIPS16_INSN_WRITE_31)
2285 && insn_uses_reg (&prev_insn, RA, MIPS_GR_REG))
2286 /* If we are generating embedded PIC code, the branch
2287 might be expanded into a sequence which uses $at, so
2288 we can't swap with an instruction which reads it. */
2289 || (mips_pic == EMBEDDED_PIC
2290 && insn_uses_reg (&prev_insn, AT, MIPS_GR_REG))
2291 /* If the previous previous instruction has a load
2292 delay, and sets a register that the branch reads, we
2294 || (! mips_opts.mips16
2295 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2296 /* Itbl support may require additional care here. */
2297 && ((prev_prev_insn.insn_mo->pinfo & INSN_LOAD_COPROC_DELAY)
2298 || (! gpr_interlocks
2299 && (prev_prev_insn.insn_mo->pinfo
2300 & INSN_LOAD_MEMORY_DELAY)))
2301 && insn_uses_reg (ip,
2302 ((prev_prev_insn.insn_opcode >> OP_SH_RT)
2305 /* If one instruction sets a condition code and the
2306 other one uses a condition code, we can not swap. */
2307 || ((pinfo & INSN_READ_COND_CODE)
2308 && (prev_pinfo & INSN_WRITE_COND_CODE))
2309 || ((pinfo & INSN_WRITE_COND_CODE)
2310 && (prev_pinfo & INSN_READ_COND_CODE))
2311 /* If the previous instruction uses the PC, we can not
2313 || (mips_opts.mips16
2314 && (prev_pinfo & MIPS16_INSN_READ_PC))
2315 /* If the previous instruction was extended, we can not
2317 || (mips_opts.mips16 && prev_insn_extended)
2318 /* If the previous instruction had a fixup in mips16
2319 mode, we can not swap. This normally means that the
2320 previous instruction was a 4 byte branch anyhow. */
2321 || (mips_opts.mips16 && prev_insn_fixp[0])
2322 /* If the previous instruction is a sync, sync.l, or
2323 sync.p, we can not swap. */
2324 || (prev_pinfo & INSN_SYNC))
2326 /* We could do even better for unconditional branches to
2327 portions of this object file; we could pick up the
2328 instruction at the destination, put it in the delay
2329 slot, and bump the destination address. */
2331 /* Update the previous insn information. */
2332 prev_prev_insn = *ip;
2333 prev_insn.insn_mo = &dummy_opcode;
2337 /* It looks like we can actually do the swap. */
2338 if (! mips_opts.mips16)
2343 prev_f = prev_insn_frag->fr_literal + prev_insn_where;
2344 memcpy (temp, prev_f, 4);
2345 memcpy (prev_f, f, 4);
2346 memcpy (f, temp, 4);
2347 if (prev_insn_fixp[0])
2349 prev_insn_fixp[0]->fx_frag = frag_now;
2350 prev_insn_fixp[0]->fx_where = f - frag_now->fr_literal;
2352 if (prev_insn_fixp[1])
2354 prev_insn_fixp[1]->fx_frag = frag_now;
2355 prev_insn_fixp[1]->fx_where = f - frag_now->fr_literal;
2357 if (prev_insn_fixp[2])
2359 prev_insn_fixp[2]->fx_frag = frag_now;
2360 prev_insn_fixp[2]->fx_where = f - frag_now->fr_literal;
2364 fixp[0]->fx_frag = prev_insn_frag;
2365 fixp[0]->fx_where = prev_insn_where;
2369 fixp[1]->fx_frag = prev_insn_frag;
2370 fixp[1]->fx_where = prev_insn_where;
2374 fixp[2]->fx_frag = prev_insn_frag;
2375 fixp[2]->fx_where = prev_insn_where;
2383 assert (prev_insn_fixp[0] == NULL);
2384 assert (prev_insn_fixp[1] == NULL);
2385 assert (prev_insn_fixp[2] == NULL);
2386 prev_f = prev_insn_frag->fr_literal + prev_insn_where;
2387 memcpy (temp, prev_f, 2);
2388 memcpy (prev_f, f, 2);
2389 if (*reloc_type != BFD_RELOC_MIPS16_JMP)
2391 assert (*reloc_type == BFD_RELOC_UNUSED);
2392 memcpy (f, temp, 2);
2396 memcpy (f, f + 2, 2);
2397 memcpy (f + 2, temp, 2);
2401 fixp[0]->fx_frag = prev_insn_frag;
2402 fixp[0]->fx_where = prev_insn_where;
2406 fixp[1]->fx_frag = prev_insn_frag;
2407 fixp[1]->fx_where = prev_insn_where;
2411 fixp[2]->fx_frag = prev_insn_frag;
2412 fixp[2]->fx_where = prev_insn_where;
2416 /* Update the previous insn information; leave prev_insn
2418 prev_prev_insn = *ip;
2420 prev_insn_is_delay_slot = 1;
2422 /* If that was an unconditional branch, forget the previous
2423 insn information. */
2424 if (pinfo & INSN_UNCOND_BRANCH_DELAY)
2426 prev_prev_insn.insn_mo = &dummy_opcode;
2427 prev_insn.insn_mo = &dummy_opcode;
2430 prev_insn_fixp[0] = NULL;
2431 prev_insn_fixp[1] = NULL;
2432 prev_insn_fixp[2] = NULL;
2433 prev_insn_reloc_type[0] = BFD_RELOC_UNUSED;
2434 prev_insn_reloc_type[1] = BFD_RELOC_UNUSED;
2435 prev_insn_reloc_type[2] = BFD_RELOC_UNUSED;
2436 prev_insn_extended = 0;
2438 else if (pinfo & INSN_COND_BRANCH_LIKELY)
2440 /* We don't yet optimize a branch likely. What we should do
2441 is look at the target, copy the instruction found there
2442 into the delay slot, and increment the branch to jump to
2443 the next instruction. */
2445 /* Update the previous insn information. */
2446 prev_prev_insn = *ip;
2447 prev_insn.insn_mo = &dummy_opcode;
2448 prev_insn_fixp[0] = NULL;
2449 prev_insn_fixp[1] = NULL;
2450 prev_insn_fixp[2] = NULL;
2451 prev_insn_reloc_type[0] = BFD_RELOC_UNUSED;
2452 prev_insn_reloc_type[1] = BFD_RELOC_UNUSED;
2453 prev_insn_reloc_type[2] = BFD_RELOC_UNUSED;
2454 prev_insn_extended = 0;
2458 /* Update the previous insn information. */
2460 prev_prev_insn.insn_mo = &dummy_opcode;
2462 prev_prev_insn = prev_insn;
2465 /* Any time we see a branch, we always fill the delay slot
2466 immediately; since this insn is not a branch, we know it
2467 is not in a delay slot. */
2468 prev_insn_is_delay_slot = 0;
2470 prev_insn_fixp[0] = fixp[0];
2471 prev_insn_fixp[1] = fixp[1];
2472 prev_insn_fixp[2] = fixp[2];
2473 prev_insn_reloc_type[0] = reloc_type[0];
2474 prev_insn_reloc_type[1] = reloc_type[1];
2475 prev_insn_reloc_type[2] = reloc_type[2];
2476 if (mips_opts.mips16)
2477 prev_insn_extended = (ip->use_extend
2478 || *reloc_type > BFD_RELOC_UNUSED);
2481 prev_prev_insn_unreordered = prev_insn_unreordered;
2482 prev_insn_unreordered = 0;
2483 prev_insn_frag = frag_now;
2484 prev_insn_where = f - frag_now->fr_literal;
2485 prev_insn_valid = 1;
2487 else if (place == NULL)
2489 /* We need to record a bit of information even when we are not
2490 reordering, in order to determine the base address for mips16
2491 PC relative relocs. */
2492 prev_prev_insn = prev_insn;
2494 prev_insn_reloc_type[0] = reloc_type[0];
2495 prev_insn_reloc_type[1] = reloc_type[1];
2496 prev_insn_reloc_type[2] = reloc_type[2];
2497 prev_prev_insn_unreordered = prev_insn_unreordered;
2498 prev_insn_unreordered = 1;
2501 /* We just output an insn, so the next one doesn't have a label. */
2502 mips_clear_insn_labels ();
2504 /* We must ensure that a fixup associated with an unmatched %hi
2505 reloc does not become a variant frag. Otherwise, the
2506 rearrangement of %hi relocs in frob_file may confuse
2510 frag_wane (frag_now);
2515 /* This function forgets that there was any previous instruction or
2516 label. If PRESERVE is non-zero, it remembers enough information to
2517 know whether nops are needed before a noreorder section. */
2520 mips_no_prev_insn (preserve)
2525 prev_insn.insn_mo = &dummy_opcode;
2526 prev_prev_insn.insn_mo = &dummy_opcode;
2527 prev_nop_frag = NULL;
2528 prev_nop_frag_holds = 0;
2529 prev_nop_frag_required = 0;
2530 prev_nop_frag_since = 0;
2532 prev_insn_valid = 0;
2533 prev_insn_is_delay_slot = 0;
2534 prev_insn_unreordered = 0;
2535 prev_insn_extended = 0;
2536 prev_insn_reloc_type[0] = BFD_RELOC_UNUSED;
2537 prev_insn_reloc_type[1] = BFD_RELOC_UNUSED;
2538 prev_insn_reloc_type[2] = BFD_RELOC_UNUSED;
2539 prev_prev_insn_unreordered = 0;
2540 mips_clear_insn_labels ();
2543 /* This function must be called whenever we turn on noreorder or emit
2544 something other than instructions. It inserts any NOPS which might
2545 be needed by the previous instruction, and clears the information
2546 kept for the previous instructions. The INSNS parameter is true if
2547 instructions are to follow. */
2550 mips_emit_delays (insns)
2553 if (! mips_opts.noreorder)
2558 if ((! mips_opts.mips16
2559 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2560 && (! cop_interlocks
2561 && (prev_insn.insn_mo->pinfo
2562 & (INSN_LOAD_COPROC_DELAY
2563 | INSN_COPROC_MOVE_DELAY
2564 | INSN_WRITE_COND_CODE))))
2565 || (! hilo_interlocks
2566 && (prev_insn.insn_mo->pinfo
2569 || (! mips_opts.mips16
2571 && (prev_insn.insn_mo->pinfo
2572 & INSN_LOAD_MEMORY_DELAY))
2573 || (! mips_opts.mips16
2574 && mips_opts.isa == ISA_MIPS1
2575 && (prev_insn.insn_mo->pinfo
2576 & INSN_COPROC_MEMORY_DELAY)))
2578 /* Itbl support may require additional care here. */
2580 if ((! mips_opts.mips16
2581 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2582 && (! cop_interlocks
2583 && prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE))
2584 || (! hilo_interlocks
2585 && ((prev_insn.insn_mo->pinfo & INSN_READ_HI)
2586 || (prev_insn.insn_mo->pinfo & INSN_READ_LO))))
2589 if (prev_insn_unreordered)
2592 else if ((! mips_opts.mips16
2593 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2594 && (! cop_interlocks
2595 && prev_prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE))
2596 || (! hilo_interlocks
2597 && ((prev_prev_insn.insn_mo->pinfo & INSN_READ_HI)
2598 || (prev_prev_insn.insn_mo->pinfo & INSN_READ_LO))))
2600 /* Itbl support may require additional care here. */
2601 if (! prev_prev_insn_unreordered)
2607 struct insn_label_list *l;
2611 /* Record the frag which holds the nop instructions, so
2612 that we can remove them if we don't need them. */
2613 frag_grow (mips_opts.mips16 ? nops * 2 : nops * 4);
2614 prev_nop_frag = frag_now;
2615 prev_nop_frag_holds = nops;
2616 prev_nop_frag_required = 0;
2617 prev_nop_frag_since = 0;
2620 for (; nops > 0; --nops)
2625 /* Move on to a new frag, so that it is safe to simply
2626 decrease the size of prev_nop_frag. */
2627 frag_wane (frag_now);
2631 for (l = insn_labels; l != NULL; l = l->next)
2635 assert (S_GET_SEGMENT (l->label) == now_seg);
2636 symbol_set_frag (l->label, frag_now);
2637 val = (valueT) frag_now_fix ();
2638 /* mips16 text labels are stored as odd. */
2639 if (mips_opts.mips16)
2641 S_SET_VALUE (l->label, val);
2646 /* Mark instruction labels in mips16 mode. */
2648 mips16_mark_labels ();
2650 mips_no_prev_insn (insns);
2653 /* Build an instruction created by a macro expansion. This is passed
2654 a pointer to the count of instructions created so far, an
2655 expression, the name of the instruction to build, an operand format
2656 string, and corresponding arguments. */
2660 macro_build (char *place,
2668 macro_build (place, counter, ep, name, fmt, va_alist)
2677 struct mips_cl_insn insn;
2678 bfd_reloc_code_real_type r[3];
2682 va_start (args, fmt);
2688 * If the macro is about to expand into a second instruction,
2689 * print a warning if needed. We need to pass ip as a parameter
2690 * to generate a better warning message here...
2692 if (mips_opts.warn_about_macros && place == NULL && *counter == 1)
2693 as_warn (_("Macro instruction expanded into multiple instructions"));
2696 * If the macro is about to expand into a second instruction,
2697 * and it is in a delay slot, print a warning.
2701 && mips_opts.noreorder
2702 && (prev_prev_insn.insn_mo->pinfo
2703 & (INSN_UNCOND_BRANCH_DELAY | INSN_COND_BRANCH_DELAY
2704 | INSN_COND_BRANCH_LIKELY)) != 0)
2705 as_warn (_("Macro instruction expanded into multiple instructions in a branch delay slot"));
2708 ++*counter; /* bump instruction counter */
2710 if (mips_opts.mips16)
2712 mips16_macro_build (place, counter, ep, name, fmt, args);
2717 r[0] = BFD_RELOC_UNUSED;
2718 r[1] = BFD_RELOC_UNUSED;
2719 r[2] = BFD_RELOC_UNUSED;
2720 insn.insn_mo = (struct mips_opcode *) hash_find (op_hash, name);
2721 assert (insn.insn_mo);
2722 assert (strcmp (name, insn.insn_mo->name) == 0);
2724 /* Search until we get a match for NAME. */
2727 /* It is assumed here that macros will never generate
2728 MDMX or MIPS-3D instructions. */
2729 if (strcmp (fmt, insn.insn_mo->args) == 0
2730 && insn.insn_mo->pinfo != INSN_MACRO
2731 && OPCODE_IS_MEMBER (insn.insn_mo, mips_opts.isa, mips_arch)
2732 && (mips_arch != CPU_R4650 || (insn.insn_mo->pinfo & FP_D) == 0))
2736 assert (insn.insn_mo->name);
2737 assert (strcmp (name, insn.insn_mo->name) == 0);
2740 insn.insn_opcode = insn.insn_mo->match;
2756 insn.insn_opcode |= va_arg (args, int) << OP_SH_RT;
2760 insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE;
2765 insn.insn_opcode |= va_arg (args, int) << OP_SH_FT;
2770 insn.insn_opcode |= va_arg (args, int) << OP_SH_RD;
2775 int tmp = va_arg (args, int);
2777 insn.insn_opcode |= tmp << OP_SH_RT;
2778 insn.insn_opcode |= tmp << OP_SH_RD;
2784 insn.insn_opcode |= va_arg (args, int) << OP_SH_FS;
2791 insn.insn_opcode |= va_arg (args, int) << OP_SH_SHAMT;
2795 insn.insn_opcode |= va_arg (args, int) << OP_SH_FD;
2799 insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE20;
2803 insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE19;
2807 insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE2;
2814 insn.insn_opcode |= va_arg (args, int) << OP_SH_RS;
2820 *r = (bfd_reloc_code_real_type) va_arg (args, int);
2821 assert (*r == BFD_RELOC_GPREL16
2822 || *r == BFD_RELOC_MIPS_LITERAL
2823 || *r == BFD_RELOC_MIPS_HIGHER
2824 || *r == BFD_RELOC_HI16_S
2825 || *r == BFD_RELOC_LO16
2826 || *r == BFD_RELOC_MIPS_GOT16
2827 || *r == BFD_RELOC_MIPS_CALL16
2828 || *r == BFD_RELOC_MIPS_GOT_DISP
2829 || *r == BFD_RELOC_MIPS_GOT_PAGE
2830 || *r == BFD_RELOC_MIPS_GOT_OFST
2831 || *r == BFD_RELOC_MIPS_GOT_LO16
2832 || *r == BFD_RELOC_MIPS_CALL_LO16
2833 || (ep->X_op == O_subtract
2834 && *r == BFD_RELOC_PCREL_LO16));
2838 *r = (bfd_reloc_code_real_type) va_arg (args, int);
2840 && (ep->X_op == O_constant
2841 || (ep->X_op == O_symbol
2842 && (*r == BFD_RELOC_MIPS_HIGHEST
2843 || *r == BFD_RELOC_HI16_S
2844 || *r == BFD_RELOC_HI16
2845 || *r == BFD_RELOC_GPREL16
2846 || *r == BFD_RELOC_MIPS_GOT_HI16
2847 || *r == BFD_RELOC_MIPS_CALL_HI16))
2848 || (ep->X_op == O_subtract
2849 && *r == BFD_RELOC_PCREL_HI16_S)));
2853 assert (ep != NULL);
2855 * This allows macro() to pass an immediate expression for
2856 * creating short branches without creating a symbol.
2857 * Note that the expression still might come from the assembly
2858 * input, in which case the value is not checked for range nor
2859 * is a relocation entry generated (yuck).
2861 if (ep->X_op == O_constant)
2863 insn.insn_opcode |= (ep->X_add_number >> 2) & 0xffff;
2867 if (mips_pic == EMBEDDED_PIC)
2868 *r = BFD_RELOC_16_PCREL_S2;
2870 *r = BFD_RELOC_16_PCREL;
2874 assert (ep != NULL);
2875 *r = BFD_RELOC_MIPS_JMP;
2879 insn.insn_opcode |= va_arg (args, unsigned long);
2888 assert (*r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL);
2890 append_insn (place, &insn, ep, r, false);
2894 mips16_macro_build (place, counter, ep, name, fmt, args)
2896 int *counter ATTRIBUTE_UNUSED;
2902 struct mips_cl_insn insn;
2903 bfd_reloc_code_real_type r[3]
2904 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
2906 insn.insn_mo = (struct mips_opcode *) hash_find (mips16_op_hash, name);
2907 assert (insn.insn_mo);
2908 assert (strcmp (name, insn.insn_mo->name) == 0);
2910 while (strcmp (fmt, insn.insn_mo->args) != 0
2911 || insn.insn_mo->pinfo == INSN_MACRO)
2914 assert (insn.insn_mo->name);
2915 assert (strcmp (name, insn.insn_mo->name) == 0);
2918 insn.insn_opcode = insn.insn_mo->match;
2919 insn.use_extend = false;
2938 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RY;
2943 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RX;
2947 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RZ;
2951 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_MOVE32Z;
2961 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_REGR32;
2968 regno = va_arg (args, int);
2969 regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3);
2970 insn.insn_opcode |= regno << MIPS16OP_SH_REG32R;
2991 assert (ep != NULL);
2993 if (ep->X_op != O_constant)
2994 *r = (int) BFD_RELOC_UNUSED + c;
2997 mips16_immed (NULL, 0, c, ep->X_add_number, false, false,
2998 false, &insn.insn_opcode, &insn.use_extend,
3001 *r = BFD_RELOC_UNUSED;
3007 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_IMM6;
3014 assert (*r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL);
3016 append_insn (place, &insn, ep, r, false);
3020 * Generate a "jalr" instruction with a relocation hint to the called
3021 * function. This occurs in NewABI PIC code.
3024 macro_build_jalr (icnt, ep)
3030 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "jalr", "d,s",
3033 fix_new_exp (frag_now, 0, 0, ep, false, BFD_RELOC_MIPS_JALR);
3037 * Generate a "lui" instruction.
3040 macro_build_lui (place, counter, ep, regnum)
3046 expressionS high_expr;
3047 struct mips_cl_insn insn;
3048 bfd_reloc_code_real_type r[3]
3049 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
3050 const char *name = "lui";
3051 const char *fmt = "t,u";
3053 assert (! mips_opts.mips16);
3059 high_expr.X_op = O_constant;
3060 high_expr.X_add_number = ep->X_add_number;
3063 if (high_expr.X_op == O_constant)
3065 /* we can compute the instruction now without a relocation entry */
3066 high_expr.X_add_number = ((high_expr.X_add_number + 0x8000)
3068 *r = BFD_RELOC_UNUSED;
3070 else if (! HAVE_NEWABI)
3072 assert (ep->X_op == O_symbol);
3073 /* _gp_disp is a special case, used from s_cpload. */
3074 assert (mips_pic == NO_PIC
3075 || strcmp (S_GET_NAME (ep->X_add_symbol), "_gp_disp") == 0);
3076 *r = BFD_RELOC_HI16_S;
3080 * If the macro is about to expand into a second instruction,
3081 * print a warning if needed. We need to pass ip as a parameter
3082 * to generate a better warning message here...
3084 if (mips_opts.warn_about_macros && place == NULL && *counter == 1)
3085 as_warn (_("Macro instruction expanded into multiple instructions"));
3088 ++*counter; /* bump instruction counter */
3090 insn.insn_mo = (struct mips_opcode *) hash_find (op_hash, name);
3091 assert (insn.insn_mo);
3092 assert (strcmp (name, insn.insn_mo->name) == 0);
3093 assert (strcmp (fmt, insn.insn_mo->args) == 0);
3095 insn.insn_opcode = insn.insn_mo->match | (regnum << OP_SH_RT);
3096 if (*r == BFD_RELOC_UNUSED)
3098 insn.insn_opcode |= high_expr.X_add_number;
3099 append_insn (place, &insn, NULL, r, false);
3102 append_insn (place, &insn, &high_expr, r, false);
3106 * Generates code to set the $at register to true (one)
3107 * if reg is less than the immediate expression.
3110 set_at (counter, reg, unsignedp)
3115 if (imm_expr.X_op == O_constant
3116 && imm_expr.X_add_number >= -0x8000
3117 && imm_expr.X_add_number < 0x8000)
3118 macro_build ((char *) NULL, counter, &imm_expr,
3119 unsignedp ? "sltiu" : "slti",
3120 "t,r,j", AT, reg, (int) BFD_RELOC_LO16);
3123 load_register (counter, AT, &imm_expr, HAVE_64BIT_GPRS);
3124 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3125 unsignedp ? "sltu" : "slt",
3126 "d,v,t", AT, reg, AT);
3130 /* Warn if an expression is not a constant. */
3133 check_absolute_expr (ip, ex)
3134 struct mips_cl_insn *ip;
3137 if (ex->X_op == O_big)
3138 as_bad (_("unsupported large constant"));
3139 else if (ex->X_op != O_constant)
3140 as_bad (_("Instruction %s requires absolute expression"), ip->insn_mo->name);
3143 /* Count the leading zeroes by performing a binary chop. This is a
3144 bulky bit of source, but performance is a LOT better for the
3145 majority of values than a simple loop to count the bits:
3146 for (lcnt = 0; (lcnt < 32); lcnt++)
3147 if ((v) & (1 << (31 - lcnt)))
3149 However it is not code size friendly, and the gain will drop a bit
3150 on certain cached systems.
3152 #define COUNT_TOP_ZEROES(v) \
3153 (((v) & ~0xffff) == 0 \
3154 ? ((v) & ~0xff) == 0 \
3155 ? ((v) & ~0xf) == 0 \
3156 ? ((v) & ~0x3) == 0 \
3157 ? ((v) & ~0x1) == 0 \
3162 : ((v) & ~0x7) == 0 \
3165 : ((v) & ~0x3f) == 0 \
3166 ? ((v) & ~0x1f) == 0 \
3169 : ((v) & ~0x7f) == 0 \
3172 : ((v) & ~0xfff) == 0 \
3173 ? ((v) & ~0x3ff) == 0 \
3174 ? ((v) & ~0x1ff) == 0 \
3177 : ((v) & ~0x7ff) == 0 \
3180 : ((v) & ~0x3fff) == 0 \
3181 ? ((v) & ~0x1fff) == 0 \
3184 : ((v) & ~0x7fff) == 0 \
3187 : ((v) & ~0xffffff) == 0 \
3188 ? ((v) & ~0xfffff) == 0 \
3189 ? ((v) & ~0x3ffff) == 0 \
3190 ? ((v) & ~0x1ffff) == 0 \
3193 : ((v) & ~0x7ffff) == 0 \
3196 : ((v) & ~0x3fffff) == 0 \
3197 ? ((v) & ~0x1fffff) == 0 \
3200 : ((v) & ~0x7fffff) == 0 \
3203 : ((v) & ~0xfffffff) == 0 \
3204 ? ((v) & ~0x3ffffff) == 0 \
3205 ? ((v) & ~0x1ffffff) == 0 \
3208 : ((v) & ~0x7ffffff) == 0 \
3211 : ((v) & ~0x3fffffff) == 0 \
3212 ? ((v) & ~0x1fffffff) == 0 \
3215 : ((v) & ~0x7fffffff) == 0 \
3219 /* Is the given value a sign-extended 32-bit value? */
3220 #define IS_SEXT_32BIT_NUM(x) \
3221 (((x) &~ (offsetT) 0x7fffffff) == 0 \
3222 || (((x) &~ (offsetT) 0x7fffffff) == ~ (offsetT) 0x7fffffff))
3225 * This routine generates the least number of instructions neccessary to load
3226 * an absolute expression value into a register.
3229 load_register (counter, reg, ep, dbl)
3236 expressionS hi32, lo32;
3238 if (ep->X_op != O_big)
3240 assert (ep->X_op == O_constant);
3241 if (ep->X_add_number < 0x8000
3242 && (ep->X_add_number >= 0
3243 || (ep->X_add_number >= -0x8000
3246 || sizeof (ep->X_add_number) > 4))))
3248 /* We can handle 16 bit signed values with an addiu to
3249 $zero. No need to ever use daddiu here, since $zero and
3250 the result are always correct in 32 bit mode. */
3251 macro_build ((char *) NULL, counter, ep, "addiu", "t,r,j", reg, 0,
3252 (int) BFD_RELOC_LO16);
3255 else if (ep->X_add_number >= 0 && ep->X_add_number < 0x10000)
3257 /* We can handle 16 bit unsigned values with an ori to
3259 macro_build ((char *) NULL, counter, ep, "ori", "t,r,i", reg, 0,
3260 (int) BFD_RELOC_LO16);
3263 else if ((IS_SEXT_32BIT_NUM (ep->X_add_number)
3266 || sizeof (ep->X_add_number) > 4
3267 || (ep->X_add_number & 0x80000000) == 0))
3268 || ((HAVE_32BIT_GPRS || ! dbl)
3269 && (ep->X_add_number &~ (offsetT) 0xffffffff) == 0)
3272 && ((ep->X_add_number &~ (offsetT) 0xffffffff)
3273 == ~ (offsetT) 0xffffffff)))
3275 /* 32 bit values require an lui. */
3276 macro_build ((char *) NULL, counter, ep, "lui", "t,u", reg,
3277 (int) BFD_RELOC_HI16);
3278 if ((ep->X_add_number & 0xffff) != 0)
3279 macro_build ((char *) NULL, counter, ep, "ori", "t,r,i", reg, reg,
3280 (int) BFD_RELOC_LO16);
3285 /* The value is larger than 32 bits. */
3287 if (HAVE_32BIT_GPRS)
3289 as_bad (_("Number (0x%lx) larger than 32 bits"),
3290 (unsigned long) ep->X_add_number);
3291 macro_build ((char *) NULL, counter, ep, "addiu", "t,r,j", reg, 0,
3292 (int) BFD_RELOC_LO16);
3296 if (ep->X_op != O_big)
3299 hi32.X_add_number = (valueT) hi32.X_add_number >> 16;
3300 hi32.X_add_number = (valueT) hi32.X_add_number >> 16;
3301 hi32.X_add_number &= 0xffffffff;
3303 lo32.X_add_number &= 0xffffffff;
3307 assert (ep->X_add_number > 2);
3308 if (ep->X_add_number == 3)
3309 generic_bignum[3] = 0;
3310 else if (ep->X_add_number > 4)
3311 as_bad (_("Number larger than 64 bits"));
3312 lo32.X_op = O_constant;
3313 lo32.X_add_number = generic_bignum[0] + (generic_bignum[1] << 16);
3314 hi32.X_op = O_constant;
3315 hi32.X_add_number = generic_bignum[2] + (generic_bignum[3] << 16);
3318 if (hi32.X_add_number == 0)
3323 unsigned long hi, lo;
3325 if (hi32.X_add_number == (offsetT) 0xffffffff)
3327 if ((lo32.X_add_number & 0xffff8000) == 0xffff8000)
3329 macro_build ((char *) NULL, counter, &lo32, "addiu", "t,r,j",
3330 reg, 0, (int) BFD_RELOC_LO16);
3333 if (lo32.X_add_number & 0x80000000)
3335 macro_build ((char *) NULL, counter, &lo32, "lui", "t,u", reg,
3336 (int) BFD_RELOC_HI16);
3337 if (lo32.X_add_number & 0xffff)
3338 macro_build ((char *) NULL, counter, &lo32, "ori", "t,r,i",
3339 reg, reg, (int) BFD_RELOC_LO16);
3344 /* Check for 16bit shifted constant. We know that hi32 is
3345 non-zero, so start the mask on the first bit of the hi32
3350 unsigned long himask, lomask;
3354 himask = 0xffff >> (32 - shift);
3355 lomask = (0xffff << shift) & 0xffffffff;
3359 himask = 0xffff << (shift - 32);
3362 if ((hi32.X_add_number & ~(offsetT) himask) == 0
3363 && (lo32.X_add_number & ~(offsetT) lomask) == 0)
3367 tmp.X_op = O_constant;
3369 tmp.X_add_number = ((hi32.X_add_number << (32 - shift))
3370 | (lo32.X_add_number >> shift));
3372 tmp.X_add_number = hi32.X_add_number >> (shift - 32);
3373 macro_build ((char *) NULL, counter, &tmp,
3374 "ori", "t,r,i", reg, 0,
3375 (int) BFD_RELOC_LO16);
3376 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3377 (shift >= 32) ? "dsll32" : "dsll",
3379 (shift >= 32) ? shift - 32 : shift);
3384 while (shift <= (64 - 16));
3386 /* Find the bit number of the lowest one bit, and store the
3387 shifted value in hi/lo. */
3388 hi = (unsigned long) (hi32.X_add_number & 0xffffffff);
3389 lo = (unsigned long) (lo32.X_add_number & 0xffffffff);
3393 while ((lo & 1) == 0)
3398 lo |= (hi & (((unsigned long) 1 << bit) - 1)) << (32 - bit);
3404 while ((hi & 1) == 0)
3413 /* Optimize if the shifted value is a (power of 2) - 1. */
3414 if ((hi == 0 && ((lo + 1) & lo) == 0)
3415 || (lo == 0xffffffff && ((hi + 1) & hi) == 0))
3417 shift = COUNT_TOP_ZEROES ((unsigned int) hi32.X_add_number);
3422 /* This instruction will set the register to be all
3424 tmp.X_op = O_constant;
3425 tmp.X_add_number = (offsetT) -1;
3426 macro_build ((char *) NULL, counter, &tmp, "addiu", "t,r,j",
3427 reg, 0, (int) BFD_RELOC_LO16);
3431 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3432 (bit >= 32) ? "dsll32" : "dsll",
3434 (bit >= 32) ? bit - 32 : bit);
3436 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3437 (shift >= 32) ? "dsrl32" : "dsrl",
3439 (shift >= 32) ? shift - 32 : shift);
3444 /* Sign extend hi32 before calling load_register, because we can
3445 generally get better code when we load a sign extended value. */
3446 if ((hi32.X_add_number & 0x80000000) != 0)
3447 hi32.X_add_number |= ~(offsetT) 0xffffffff;
3448 load_register (counter, reg, &hi32, 0);
3451 if ((lo32.X_add_number & 0xffff0000) == 0)
3455 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3456 "dsll32", "d,w,<", reg, freg, 0);
3464 if ((freg == 0) && (lo32.X_add_number == (offsetT) 0xffffffff))
3466 macro_build ((char *) NULL, counter, &lo32, "lui", "t,u", reg,
3467 (int) BFD_RELOC_HI16);
3468 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3469 "dsrl32", "d,w,<", reg, reg, 0);
3475 macro_build ((char *) NULL, counter, (expressionS *) NULL, "dsll",
3476 "d,w,<", reg, freg, 16);
3480 mid16.X_add_number >>= 16;
3481 macro_build ((char *) NULL, counter, &mid16, "ori", "t,r,i", reg,
3482 freg, (int) BFD_RELOC_LO16);
3483 macro_build ((char *) NULL, counter, (expressionS *) NULL, "dsll",
3484 "d,w,<", reg, reg, 16);
3487 if ((lo32.X_add_number & 0xffff) != 0)
3488 macro_build ((char *) NULL, counter, &lo32, "ori", "t,r,i", reg, freg,
3489 (int) BFD_RELOC_LO16);
3492 /* Load an address into a register. */
3495 load_address (counter, reg, ep, used_at)
3503 if (ep->X_op != O_constant
3504 && ep->X_op != O_symbol)
3506 as_bad (_("expression too complex"));
3507 ep->X_op = O_constant;
3510 if (ep->X_op == O_constant)
3512 load_register (counter, reg, ep, HAVE_64BIT_ADDRESSES);
3516 if (mips_pic == NO_PIC)
3518 /* If this is a reference to a GP relative symbol, we want
3519 addiu $reg,$gp,<sym> (BFD_RELOC_GPREL16)
3521 lui $reg,<sym> (BFD_RELOC_HI16_S)
3522 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
3523 If we have an addend, we always use the latter form.
3525 With 64bit address space and a usable $at we want
3526 lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST)
3527 lui $at,<sym> (BFD_RELOC_HI16_S)
3528 daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER)
3529 daddiu $at,<sym> (BFD_RELOC_LO16)
3533 If $at is already in use, we use an path which is suboptimal
3534 on superscalar processors.
3535 lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST)
3536 daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER)
3538 daddiu $reg,<sym> (BFD_RELOC_HI16_S)
3540 daddiu $reg,<sym> (BFD_RELOC_LO16)
3542 if (HAVE_64BIT_ADDRESSES)
3544 /* We don't do GP optimization for now because RELAX_ENCODE can't
3545 hold the data for such large chunks. */
3549 macro_build (p, counter, ep, "lui", "t,u",
3550 reg, (int) BFD_RELOC_MIPS_HIGHEST);
3551 macro_build (p, counter, ep, "lui", "t,u",
3552 AT, (int) BFD_RELOC_HI16_S);
3553 macro_build (p, counter, ep, "daddiu", "t,r,j",
3554 reg, reg, (int) BFD_RELOC_MIPS_HIGHER);
3555 macro_build (p, counter, ep, "daddiu", "t,r,j",
3556 AT, AT, (int) BFD_RELOC_LO16);
3557 macro_build (p, counter, (expressionS *) NULL, "dsll32",
3558 "d,w,<", reg, reg, 0);
3559 macro_build (p, counter, (expressionS *) NULL, "daddu",
3560 "d,v,t", reg, reg, AT);
3565 macro_build (p, counter, ep, "lui", "t,u",
3566 reg, (int) BFD_RELOC_MIPS_HIGHEST);
3567 macro_build (p, counter, ep, "daddiu", "t,r,j",
3568 reg, reg, (int) BFD_RELOC_MIPS_HIGHER);
3569 macro_build (p, counter, (expressionS *) NULL, "dsll",
3570 "d,w,<", reg, reg, 16);
3571 macro_build (p, counter, ep, "daddiu", "t,r,j",
3572 reg, reg, (int) BFD_RELOC_HI16_S);
3573 macro_build (p, counter, (expressionS *) NULL, "dsll",
3574 "d,w,<", reg, reg, 16);
3575 macro_build (p, counter, ep, "daddiu", "t,r,j",
3576 reg, reg, (int) BFD_RELOC_LO16);
3581 if ((valueT) ep->X_add_number <= MAX_GPREL_OFFSET
3582 && ! nopic_need_relax (ep->X_add_symbol, 1))
3585 macro_build ((char *) NULL, counter, ep,
3586 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", "t,r,j",
3587 reg, mips_gp_register, (int) BFD_RELOC_GPREL16);
3588 p = frag_var (rs_machine_dependent, 8, 0,
3589 RELAX_ENCODE (4, 8, 0, 4, 0,
3590 mips_opts.warn_about_macros),
3591 ep->X_add_symbol, 0, NULL);
3593 macro_build_lui (p, counter, ep, reg);
3596 macro_build (p, counter, ep,
3597 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
3598 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
3601 else if (mips_pic == SVR4_PIC && ! mips_big_got)
3605 /* If this is a reference to an external symbol, we want
3606 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3608 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3610 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
3611 If there is a constant, it must be added in after. */
3612 ex.X_add_number = ep->X_add_number;
3613 ep->X_add_number = 0;
3615 macro_build ((char *) NULL, counter, ep,
3616 HAVE_32BIT_ADDRESSES ? "lw" : "ld", "t,o(b)",
3617 reg, (int) BFD_RELOC_MIPS_GOT16, mips_gp_register);
3618 macro_build ((char *) NULL, counter, (expressionS *) NULL, "nop", "");
3619 p = frag_var (rs_machine_dependent, 4, 0,
3620 RELAX_ENCODE (0, 4, -8, 0, 0, mips_opts.warn_about_macros),
3621 ep->X_add_symbol, (offsetT) 0, (char *) NULL);
3622 macro_build (p, counter, ep,
3623 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
3624 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
3625 if (ex.X_add_number != 0)
3627 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
3628 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
3629 ex.X_op = O_constant;
3630 macro_build ((char *) NULL, counter, &ex,
3631 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
3632 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
3635 else if (mips_pic == SVR4_PIC)
3640 /* This is the large GOT case. If this is a reference to an
3641 external symbol, we want
3642 lui $reg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
3644 lw $reg,<sym>($reg) (BFD_RELOC_MIPS_GOT_LO16)
3645 Otherwise, for a reference to a local symbol, we want
3646 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3648 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
3649 If we have NewABI, we want
3650 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
3651 addiu $reg,$reg,<sym> (BFD_RELOC_MIPS_GOT_OFST)
3652 If there is a constant, it must be added in after. */
3653 ex.X_add_number = ep->X_add_number;
3654 ep->X_add_number = 0;
3657 macro_build ((char *) NULL, counter, ep,
3658 HAVE_32BIT_ADDRESSES ? "lw" : "ld", "t,o(b)", reg,
3659 (int) BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register);
3660 macro_build (p, counter, ep,
3661 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", "t,r,j",
3662 reg, reg, (int) BFD_RELOC_MIPS_GOT_OFST);
3666 if (reg_needs_delay (mips_gp_register))
3671 macro_build ((char *) NULL, counter, ep, "lui", "t,u", reg,
3672 (int) BFD_RELOC_MIPS_GOT_HI16);
3673 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3674 HAVE_32BIT_ADDRESSES ? "addu" : "daddu", "d,v,t", reg,
3675 reg, mips_gp_register);
3676 macro_build ((char *) NULL, counter, ep,
3677 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
3678 "t,o(b)", reg, (int) BFD_RELOC_MIPS_GOT_LO16, reg);
3679 p = frag_var (rs_machine_dependent, 12 + off, 0,
3680 RELAX_ENCODE (12, 12 + off, off, 8 + off, 0,
3681 mips_opts.warn_about_macros),
3682 ep->X_add_symbol, 0, NULL);
3685 /* We need a nop before loading from $gp. This special
3686 check is required because the lui which starts the main
3687 instruction stream does not refer to $gp, and so will not
3688 insert the nop which may be required. */
3689 macro_build (p, counter, (expressionS *) NULL, "nop", "");
3692 macro_build (p, counter, ep,
3693 HAVE_32BIT_ADDRESSES ? "lw" : "ld", "t,o(b)", reg,
3694 (int) BFD_RELOC_MIPS_GOT16, mips_gp_register);
3696 macro_build (p, counter, (expressionS *) NULL, "nop", "");
3698 macro_build (p, counter, ep,
3699 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
3700 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
3703 if (ex.X_add_number != 0)
3705 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
3706 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
3707 ex.X_op = O_constant;
3708 macro_build ((char *) NULL, counter, &ex,
3709 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
3710 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
3713 else if (mips_pic == EMBEDDED_PIC)
3716 addiu $reg,$gp,<sym> (BFD_RELOC_GPREL16)
3718 macro_build ((char *) NULL, counter, ep,
3719 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
3720 "t,r,j", reg, mips_gp_register, (int) BFD_RELOC_GPREL16);
3726 /* Move the contents of register SOURCE into register DEST. */
3729 move_register (counter, dest, source)
3734 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3735 HAVE_32BIT_GPRS ? "addu" : "daddu",
3736 "d,v,t", dest, source, 0);
3741 * This routine implements the seemingly endless macro or synthesized
3742 * instructions and addressing modes in the mips assembly language. Many
3743 * of these macros are simple and are similar to each other. These could
3744 * probably be handled by some kind of table or grammer aproach instead of
3745 * this verbose method. Others are not simple macros but are more like
3746 * optimizing code generation.
3747 * One interesting optimization is when several store macros appear
3748 * consecutivly that would load AT with the upper half of the same address.
3749 * The ensuing load upper instructions are ommited. This implies some kind
3750 * of global optimization. We currently only optimize within a single macro.
3751 * For many of the load and store macros if the address is specified as a
3752 * constant expression in the first 64k of memory (ie ld $2,0x4000c) we
3753 * first load register 'at' with zero and use it as the base register. The
3754 * mips assembler simply uses register $zero. Just one tiny optimization
3759 struct mips_cl_insn *ip;
3761 register int treg, sreg, dreg, breg;
3777 bfd_reloc_code_real_type r;
3778 int hold_mips_optimize;
3780 assert (! mips_opts.mips16);
3782 treg = (ip->insn_opcode >> 16) & 0x1f;
3783 dreg = (ip->insn_opcode >> 11) & 0x1f;
3784 sreg = breg = (ip->insn_opcode >> 21) & 0x1f;
3785 mask = ip->insn_mo->mask;
3787 expr1.X_op = O_constant;
3788 expr1.X_op_symbol = NULL;
3789 expr1.X_add_symbol = NULL;
3790 expr1.X_add_number = 1;
3802 mips_emit_delays (true);
3803 ++mips_opts.noreorder;
3804 mips_any_noreorder = 1;
3806 expr1.X_add_number = 8;
3807 macro_build ((char *) NULL, &icnt, &expr1, "bgez", "s,p", sreg);
3809 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "",
3812 move_register (&icnt, dreg, sreg);
3813 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
3814 dbl ? "dsub" : "sub", "d,v,t", dreg, 0, sreg);
3816 --mips_opts.noreorder;
3837 if (imm_expr.X_op == O_constant
3838 && imm_expr.X_add_number >= -0x8000
3839 && imm_expr.X_add_number < 0x8000)
3841 macro_build ((char *) NULL, &icnt, &imm_expr, s, "t,r,j", treg, sreg,
3842 (int) BFD_RELOC_LO16);
3845 load_register (&icnt, AT, &imm_expr, dbl);
3846 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s2, "d,v,t",
3866 if (imm_expr.X_op == O_constant
3867 && imm_expr.X_add_number >= 0
3868 && imm_expr.X_add_number < 0x10000)
3870 if (mask != M_NOR_I)
3871 macro_build ((char *) NULL, &icnt, &imm_expr, s, "t,r,i", treg,
3872 sreg, (int) BFD_RELOC_LO16);
3875 macro_build ((char *) NULL, &icnt, &imm_expr, "ori", "t,r,i",
3876 treg, sreg, (int) BFD_RELOC_LO16);
3877 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nor",
3878 "d,v,t", treg, treg, 0);
3883 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
3884 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s2, "d,v,t",
3902 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
3904 macro_build ((char *) NULL, &icnt, &offset_expr, s, "s,t,p", sreg,
3908 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
3909 macro_build ((char *) NULL, &icnt, &offset_expr, s, "s,t,p", sreg, AT);
3917 macro_build ((char *) NULL, &icnt, &offset_expr,
3918 likely ? "bgezl" : "bgez", "s,p", sreg);
3923 macro_build ((char *) NULL, &icnt, &offset_expr,
3924 likely ? "blezl" : "blez", "s,p", treg);
3927 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "slt", "d,v,t",
3929 macro_build ((char *) NULL, &icnt, &offset_expr,
3930 likely ? "beql" : "beq", "s,t,p", AT, 0);
3936 /* check for > max integer */
3937 maxnum = 0x7fffffff;
3938 if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4)
3945 if (imm_expr.X_op == O_constant
3946 && imm_expr.X_add_number >= maxnum
3947 && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4))
3950 /* result is always false */
3954 as_warn (_("Branch %s is always false (nop)"),
3956 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop",
3962 as_warn (_("Branch likely %s is always false"),
3964 macro_build ((char *) NULL, &icnt, &offset_expr, "bnel",
3969 if (imm_expr.X_op != O_constant)
3970 as_bad (_("Unsupported large constant"));
3971 ++imm_expr.X_add_number;
3975 if (mask == M_BGEL_I)
3977 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
3979 macro_build ((char *) NULL, &icnt, &offset_expr,
3980 likely ? "bgezl" : "bgez", "s,p", sreg);
3983 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
3985 macro_build ((char *) NULL, &icnt, &offset_expr,
3986 likely ? "bgtzl" : "bgtz", "s,p", sreg);
3989 maxnum = 0x7fffffff;
3990 if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4)
3997 maxnum = - maxnum - 1;
3998 if (imm_expr.X_op == O_constant
3999 && imm_expr.X_add_number <= maxnum
4000 && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4))
4003 /* result is always true */
4004 as_warn (_("Branch %s is always true"), ip->insn_mo->name);
4005 macro_build ((char *) NULL, &icnt, &offset_expr, "b", "p");
4008 set_at (&icnt, sreg, 0);
4009 macro_build ((char *) NULL, &icnt, &offset_expr,
4010 likely ? "beql" : "beq", "s,t,p", AT, 0);
4020 macro_build ((char *) NULL, &icnt, &offset_expr,
4021 likely ? "beql" : "beq", "s,t,p", 0, treg);
4024 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
4025 "d,v,t", AT, sreg, treg);
4026 macro_build ((char *) NULL, &icnt, &offset_expr,
4027 likely ? "beql" : "beq", "s,t,p", AT, 0);
4035 && imm_expr.X_op == O_constant
4036 && imm_expr.X_add_number == (offsetT) 0xffffffff))
4038 if (imm_expr.X_op != O_constant)
4039 as_bad (_("Unsupported large constant"));
4040 ++imm_expr.X_add_number;
4044 if (mask == M_BGEUL_I)
4046 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4048 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4050 macro_build ((char *) NULL, &icnt, &offset_expr,
4051 likely ? "bnel" : "bne", "s,t,p", sreg, 0);
4054 set_at (&icnt, sreg, 1);
4055 macro_build ((char *) NULL, &icnt, &offset_expr,
4056 likely ? "beql" : "beq", "s,t,p", AT, 0);
4064 macro_build ((char *) NULL, &icnt, &offset_expr,
4065 likely ? "bgtzl" : "bgtz", "s,p", sreg);
4070 macro_build ((char *) NULL, &icnt, &offset_expr,
4071 likely ? "bltzl" : "bltz", "s,p", treg);
4074 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "slt", "d,v,t",
4076 macro_build ((char *) NULL, &icnt, &offset_expr,
4077 likely ? "bnel" : "bne", "s,t,p", AT, 0);
4085 macro_build ((char *) NULL, &icnt, &offset_expr,
4086 likely ? "bnel" : "bne", "s,t,p", sreg, 0);
4091 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
4092 "d,v,t", AT, treg, sreg);
4093 macro_build ((char *) NULL, &icnt, &offset_expr,
4094 likely ? "bnel" : "bne", "s,t,p", AT, 0);
4102 macro_build ((char *) NULL, &icnt, &offset_expr,
4103 likely ? "blezl" : "blez", "s,p", sreg);
4108 macro_build ((char *) NULL, &icnt, &offset_expr,
4109 likely ? "bgezl" : "bgez", "s,p", treg);
4112 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "slt", "d,v,t",
4114 macro_build ((char *) NULL, &icnt, &offset_expr,
4115 likely ? "beql" : "beq", "s,t,p", AT, 0);
4121 maxnum = 0x7fffffff;
4122 if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4)
4129 if (imm_expr.X_op == O_constant
4130 && imm_expr.X_add_number >= maxnum
4131 && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4))
4133 if (imm_expr.X_op != O_constant)
4134 as_bad (_("Unsupported large constant"));
4135 ++imm_expr.X_add_number;
4139 if (mask == M_BLTL_I)
4141 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4143 macro_build ((char *) NULL, &icnt, &offset_expr,
4144 likely ? "bltzl" : "bltz", "s,p", sreg);
4147 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4149 macro_build ((char *) NULL, &icnt, &offset_expr,
4150 likely ? "blezl" : "blez", "s,p", sreg);
4153 set_at (&icnt, sreg, 0);
4154 macro_build ((char *) NULL, &icnt, &offset_expr,
4155 likely ? "bnel" : "bne", "s,t,p", AT, 0);
4163 macro_build ((char *) NULL, &icnt, &offset_expr,
4164 likely ? "beql" : "beq", "s,t,p", sreg, 0);
4169 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
4170 "d,v,t", AT, treg, sreg);
4171 macro_build ((char *) NULL, &icnt, &offset_expr,
4172 likely ? "beql" : "beq", "s,t,p", AT, 0);
4180 && imm_expr.X_op == O_constant
4181 && imm_expr.X_add_number == (offsetT) 0xffffffff))
4183 if (imm_expr.X_op != O_constant)
4184 as_bad (_("Unsupported large constant"));
4185 ++imm_expr.X_add_number;
4189 if (mask == M_BLTUL_I)
4191 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4193 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4195 macro_build ((char *) NULL, &icnt, &offset_expr,
4196 likely ? "beql" : "beq",
4200 set_at (&icnt, sreg, 1);
4201 macro_build ((char *) NULL, &icnt, &offset_expr,
4202 likely ? "bnel" : "bne", "s,t,p", AT, 0);
4210 macro_build ((char *) NULL, &icnt, &offset_expr,
4211 likely ? "bltzl" : "bltz", "s,p", sreg);
4216 macro_build ((char *) NULL, &icnt, &offset_expr,
4217 likely ? "bgtzl" : "bgtz", "s,p", treg);
4220 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "slt", "d,v,t",
4222 macro_build ((char *) NULL, &icnt, &offset_expr,
4223 likely ? "bnel" : "bne", "s,t,p", AT, 0);
4233 macro_build ((char *) NULL, &icnt, &offset_expr,
4234 likely ? "bnel" : "bne", "s,t,p", 0, treg);
4237 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
4240 macro_build ((char *) NULL, &icnt, &offset_expr,
4241 likely ? "bnel" : "bne", "s,t,p", AT, 0);
4256 as_warn (_("Divide by zero."));
4258 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "teq",
4261 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
4266 mips_emit_delays (true);
4267 ++mips_opts.noreorder;
4268 mips_any_noreorder = 1;
4271 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "teq",
4273 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4274 dbl ? "ddiv" : "div", "z,s,t", sreg, treg);
4278 expr1.X_add_number = 8;
4279 macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, 0);
4280 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4281 dbl ? "ddiv" : "div", "z,s,t", sreg, treg);
4282 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
4285 expr1.X_add_number = -1;
4286 macro_build ((char *) NULL, &icnt, &expr1,
4287 dbl ? "daddiu" : "addiu",
4288 "t,r,j", AT, 0, (int) BFD_RELOC_LO16);
4289 expr1.X_add_number = mips_trap ? (dbl ? 12 : 8) : (dbl ? 20 : 16);
4290 macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, AT);
4293 expr1.X_add_number = 1;
4294 macro_build ((char *) NULL, &icnt, &expr1, "daddiu", "t,r,j", AT, 0,
4295 (int) BFD_RELOC_LO16);
4296 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "dsll32",
4297 "d,w,<", AT, AT, 31);
4301 expr1.X_add_number = 0x80000000;
4302 macro_build ((char *) NULL, &icnt, &expr1, "lui", "t,u", AT,
4303 (int) BFD_RELOC_HI16);
4307 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "teq",
4309 /* We want to close the noreorder block as soon as possible, so
4310 that later insns are available for delay slot filling. */
4311 --mips_opts.noreorder;
4315 expr1.X_add_number = 8;
4316 macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", sreg, AT);
4317 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "",
4320 /* We want to close the noreorder block as soon as possible, so
4321 that later insns are available for delay slot filling. */
4322 --mips_opts.noreorder;
4324 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
4327 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d", dreg);
4366 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4368 as_warn (_("Divide by zero."));
4370 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "teq",
4373 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
4377 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4379 if (strcmp (s2, "mflo") == 0)
4380 move_register (&icnt, dreg, sreg);
4382 move_register (&icnt, dreg, 0);
4385 if (imm_expr.X_op == O_constant
4386 && imm_expr.X_add_number == -1
4387 && s[strlen (s) - 1] != 'u')
4389 if (strcmp (s2, "mflo") == 0)
4391 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4392 dbl ? "dneg" : "neg", "d,w", dreg, sreg);
4395 move_register (&icnt, dreg, 0);
4399 load_register (&icnt, AT, &imm_expr, dbl);
4400 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "z,s,t",
4402 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s2, "d", dreg);
4421 mips_emit_delays (true);
4422 ++mips_opts.noreorder;
4423 mips_any_noreorder = 1;
4426 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "teq",
4428 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "z,s,t",
4430 /* We want to close the noreorder block as soon as possible, so
4431 that later insns are available for delay slot filling. */
4432 --mips_opts.noreorder;
4436 expr1.X_add_number = 8;
4437 macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, 0);
4438 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "z,s,t",
4441 /* We want to close the noreorder block as soon as possible, so
4442 that later insns are available for delay slot filling. */
4443 --mips_opts.noreorder;
4444 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
4447 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s2, "d", dreg);
4453 /* Load the address of a symbol into a register. If breg is not
4454 zero, we then add a base register to it. */
4456 if (dbl && HAVE_32BIT_GPRS)
4457 as_warn (_("dla used to load 32-bit register"));
4459 if (! dbl && HAVE_64BIT_OBJECTS)
4460 as_warn (_("la used to load 64-bit address"));
4473 /* When generating embedded PIC code, we permit expressions of
4476 la $treg,foo-bar($breg)
4477 where bar is an address in the current section. These are used
4478 when getting the addresses of functions. We don't permit
4479 X_add_number to be non-zero, because if the symbol is
4480 external the relaxing code needs to know that any addend is
4481 purely the offset to X_op_symbol. */
4482 if (mips_pic == EMBEDDED_PIC
4483 && offset_expr.X_op == O_subtract
4484 && (symbol_constant_p (offset_expr.X_op_symbol)
4485 ? S_GET_SEGMENT (offset_expr.X_op_symbol) == now_seg
4486 : (symbol_equated_p (offset_expr.X_op_symbol)
4488 (symbol_get_value_expression (offset_expr.X_op_symbol)
4491 && (offset_expr.X_add_number == 0
4492 || OUTPUT_FLAVOR == bfd_target_elf_flavour))
4498 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
4499 tempreg, (int) BFD_RELOC_PCREL_HI16_S);
4503 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
4504 tempreg, (int) BFD_RELOC_PCREL_HI16_S);
4505 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4506 (dbl || HAVE_64BIT_ADDRESSES) ? "daddu" : "addu",
4507 "d,v,t", tempreg, tempreg, breg);
4509 macro_build ((char *) NULL, &icnt, &offset_expr,
4510 (dbl || HAVE_64BIT_ADDRESSES) ? "daddiu" : "addiu",
4511 "t,r,j", treg, tempreg, (int) BFD_RELOC_PCREL_LO16);
4517 if (offset_expr.X_op != O_symbol
4518 && offset_expr.X_op != O_constant)
4520 as_bad (_("expression too complex"));
4521 offset_expr.X_op = O_constant;
4524 if (offset_expr.X_op == O_constant)
4525 load_register (&icnt, tempreg, &offset_expr,
4526 ((mips_pic == EMBEDDED_PIC || mips_pic == NO_PIC)
4527 ? (dbl || HAVE_64BIT_ADDRESSES)
4528 : HAVE_64BIT_ADDRESSES));
4529 else if (mips_pic == NO_PIC)
4531 /* If this is a reference to a GP relative symbol, we want
4532 addiu $tempreg,$gp,<sym> (BFD_RELOC_GPREL16)
4534 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
4535 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
4536 If we have a constant, we need two instructions anyhow,
4537 so we may as well always use the latter form.
4539 With 64bit address space and a usable $at we want
4540 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
4541 lui $at,<sym> (BFD_RELOC_HI16_S)
4542 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
4543 daddiu $at,<sym> (BFD_RELOC_LO16)
4545 daddu $tempreg,$tempreg,$at
4547 If $at is already in use, we use an path which is suboptimal
4548 on superscalar processors.
4549 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
4550 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
4552 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
4554 daddiu $tempreg,<sym> (BFD_RELOC_LO16)
4557 if (HAVE_64BIT_ADDRESSES)
4559 /* We don't do GP optimization for now because RELAX_ENCODE can't
4560 hold the data for such large chunks. */
4564 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
4565 tempreg, (int) BFD_RELOC_MIPS_HIGHEST);
4566 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
4567 AT, (int) BFD_RELOC_HI16_S);
4568 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4569 tempreg, tempreg, (int) BFD_RELOC_MIPS_HIGHER);
4570 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4571 AT, AT, (int) BFD_RELOC_LO16);
4572 macro_build (p, &icnt, (expressionS *) NULL, "dsll32",
4573 "d,w,<", tempreg, tempreg, 0);
4574 macro_build (p, &icnt, (expressionS *) NULL, "daddu",
4575 "d,v,t", tempreg, tempreg, AT);
4580 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
4581 tempreg, (int) BFD_RELOC_MIPS_HIGHEST);
4582 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4583 tempreg, tempreg, (int) BFD_RELOC_MIPS_HIGHER);
4584 macro_build (p, &icnt, (expressionS *) NULL, "dsll", "d,w,<",
4585 tempreg, tempreg, 16);
4586 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4587 tempreg, tempreg, (int) BFD_RELOC_HI16_S);
4588 macro_build (p, &icnt, (expressionS *) NULL, "dsll", "d,w,<",
4589 tempreg, tempreg, 16);
4590 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4591 tempreg, tempreg, (int) BFD_RELOC_LO16);
4596 if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
4597 && ! nopic_need_relax (offset_expr.X_add_symbol, 1))
4600 macro_build ((char *) NULL, &icnt, &offset_expr, "addiu",
4601 "t,r,j", tempreg, mips_gp_register,
4602 (int) BFD_RELOC_GPREL16);
4603 p = frag_var (rs_machine_dependent, 8, 0,
4604 RELAX_ENCODE (4, 8, 0, 4, 0,
4605 mips_opts.warn_about_macros),
4606 offset_expr.X_add_symbol, 0, NULL);
4608 macro_build_lui (p, &icnt, &offset_expr, tempreg);
4611 macro_build (p, &icnt, &offset_expr, "addiu",
4612 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
4615 else if (mips_pic == SVR4_PIC && ! mips_big_got)
4617 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT16;
4619 /* If this is a reference to an external symbol, and there
4620 is no constant, we want
4621 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4622 or if tempreg is PIC_CALL_REG
4623 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
4624 For a local symbol, we want
4625 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4627 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
4629 If we have a small constant, and this is a reference to
4630 an external symbol, we want
4631 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4633 addiu $tempreg,$tempreg,<constant>
4634 For a local symbol, we want the same instruction
4635 sequence, but we output a BFD_RELOC_LO16 reloc on the
4638 If we have a large constant, and this is a reference to
4639 an external symbol, we want
4640 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4641 lui $at,<hiconstant>
4642 addiu $at,$at,<loconstant>
4643 addu $tempreg,$tempreg,$at
4644 For a local symbol, we want the same instruction
4645 sequence, but we output a BFD_RELOC_LO16 reloc on the
4646 addiu instruction. */
4647 expr1.X_add_number = offset_expr.X_add_number;
4648 offset_expr.X_add_number = 0;
4650 if (expr1.X_add_number == 0 && tempreg == PIC_CALL_REG)
4651 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL16;
4652 macro_build ((char *) NULL, &icnt, &offset_expr,
4653 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
4654 "t,o(b)", tempreg, lw_reloc_type, mips_gp_register);
4655 if (expr1.X_add_number == 0)
4664 /* We're going to put in an addu instruction using
4665 tempreg, so we may as well insert the nop right
4667 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4671 p = frag_var (rs_machine_dependent, 8 - off, 0,
4672 RELAX_ENCODE (0, 8 - off, -4 - off, 4 - off, 0,
4674 ? mips_opts.warn_about_macros
4676 offset_expr.X_add_symbol, 0, NULL);
4679 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
4682 macro_build (p, &icnt, &expr1,
4683 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
4684 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
4685 /* FIXME: If breg == 0, and the next instruction uses
4686 $tempreg, then if this variant case is used an extra
4687 nop will be generated. */
4689 else if (expr1.X_add_number >= -0x8000
4690 && expr1.X_add_number < 0x8000)
4692 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4694 macro_build ((char *) NULL, &icnt, &expr1,
4695 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
4696 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
4697 frag_var (rs_machine_dependent, 0, 0,
4698 RELAX_ENCODE (0, 0, -12, -4, 0, 0),
4699 offset_expr.X_add_symbol, 0, NULL);
4705 /* If we are going to add in a base register, and the
4706 target register and the base register are the same,
4707 then we are using AT as a temporary register. Since
4708 we want to load the constant into AT, we add our
4709 current AT (from the global offset table) and the
4710 register into the register now, and pretend we were
4711 not using a base register. */
4716 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4718 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4719 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
4720 "d,v,t", treg, AT, breg);
4726 /* Set mips_optimize around the lui instruction to avoid
4727 inserting an unnecessary nop after the lw. */
4728 hold_mips_optimize = mips_optimize;
4730 macro_build_lui (NULL, &icnt, &expr1, AT);
4731 mips_optimize = hold_mips_optimize;
4733 macro_build ((char *) NULL, &icnt, &expr1,
4734 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
4735 "t,r,j", AT, AT, (int) BFD_RELOC_LO16);
4736 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4737 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
4738 "d,v,t", tempreg, tempreg, AT);
4739 frag_var (rs_machine_dependent, 0, 0,
4740 RELAX_ENCODE (0, 0, -16 + off1, -8, 0, 0),
4741 offset_expr.X_add_symbol, 0, NULL);
4745 else if (mips_pic == SVR4_PIC)
4749 int lui_reloc_type = (int) BFD_RELOC_MIPS_GOT_HI16;
4750 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT_LO16;
4752 /* This is the large GOT case. If this is a reference to an
4753 external symbol, and there is no constant, we want
4754 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
4755 addu $tempreg,$tempreg,$gp
4756 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
4757 or if tempreg is PIC_CALL_REG
4758 lui $tempreg,<sym> (BFD_RELOC_MIPS_CALL_HI16)
4759 addu $tempreg,$tempreg,$gp
4760 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_CALL_LO16)
4761 For a local symbol, we want
4762 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4764 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
4766 If we have a small constant, and this is a reference to
4767 an external symbol, we want
4768 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
4769 addu $tempreg,$tempreg,$gp
4770 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
4772 addiu $tempreg,$tempreg,<constant>
4773 For a local symbol, we want
4774 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4776 addiu $tempreg,$tempreg,<constant> (BFD_RELOC_LO16)
4778 If we have a large constant, and this is a reference to
4779 an external symbol, we want
4780 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
4781 addu $tempreg,$tempreg,$gp
4782 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
4783 lui $at,<hiconstant>
4784 addiu $at,$at,<loconstant>
4785 addu $tempreg,$tempreg,$at
4786 For a local symbol, we want
4787 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4788 lui $at,<hiconstant>
4789 addiu $at,$at,<loconstant> (BFD_RELOC_LO16)
4790 addu $tempreg,$tempreg,$at
4792 For NewABI, we want for data addresses
4793 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
4794 If tempreg is PIC_CALL_REG pointing to a external symbol, we want
4795 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
4799 int reloc_type = (tempreg == PIC_CALL_REG
4800 ? BFD_RELOC_MIPS_CALL16
4801 : BFD_RELOC_MIPS_GOT_DISP);
4803 macro_build ((char *) NULL, &icnt, &offset_expr,
4804 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
4805 "t,o(b)", tempreg, reloc_type, mips_gp_register);
4808 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4809 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
4810 "d,v,t", treg, tempreg, breg);
4817 expr1.X_add_number = offset_expr.X_add_number;
4818 offset_expr.X_add_number = 0;
4820 if (reg_needs_delay (mips_gp_register))
4824 if (expr1.X_add_number == 0 && tempreg == PIC_CALL_REG)
4826 lui_reloc_type = (int) BFD_RELOC_MIPS_CALL_HI16;
4827 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL_LO16;
4829 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
4830 tempreg, lui_reloc_type);
4831 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4832 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
4833 "d,v,t", tempreg, tempreg, mips_gp_register);
4834 macro_build ((char *) NULL, &icnt, &offset_expr,
4835 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
4836 "t,o(b)", tempreg, lw_reloc_type, tempreg);
4837 if (expr1.X_add_number == 0)
4845 /* We're going to put in an addu instruction using
4846 tempreg, so we may as well insert the nop right
4848 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4853 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
4854 RELAX_ENCODE (12 + off, 12 + gpdel, gpdel,
4857 ? mips_opts.warn_about_macros
4859 offset_expr.X_add_symbol, 0, NULL);
4861 else if (expr1.X_add_number >= -0x8000
4862 && expr1.X_add_number < 0x8000)
4864 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4866 macro_build ((char *) NULL, &icnt, &expr1,
4867 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
4868 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
4870 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
4871 RELAX_ENCODE (20, 12 + gpdel, gpdel, 8 + gpdel, 0,
4873 ? mips_opts.warn_about_macros
4875 offset_expr.X_add_symbol, 0, NULL);
4881 /* If we are going to add in a base register, and the
4882 target register and the base register are the same,
4883 then we are using AT as a temporary register. Since
4884 we want to load the constant into AT, we add our
4885 current AT (from the global offset table) and the
4886 register into the register now, and pretend we were
4887 not using a base register. */
4895 assert (tempreg == AT);
4896 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4898 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4899 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
4900 "d,v,t", treg, AT, breg);
4905 /* Set mips_optimize around the lui instruction to avoid
4906 inserting an unnecessary nop after the lw. */
4907 hold_mips_optimize = mips_optimize;
4909 macro_build_lui (NULL, &icnt, &expr1, AT);
4910 mips_optimize = hold_mips_optimize;
4912 macro_build ((char *) NULL, &icnt, &expr1,
4913 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
4914 "t,r,j", AT, AT, (int) BFD_RELOC_LO16);
4915 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4916 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
4917 "d,v,t", dreg, dreg, AT);
4919 p = frag_var (rs_machine_dependent, 16 + gpdel + adj, 0,
4920 RELAX_ENCODE (24 + adj, 16 + gpdel + adj, gpdel,
4923 ? mips_opts.warn_about_macros
4925 offset_expr.X_add_symbol, 0, NULL);
4932 /* This is needed because this instruction uses $gp, but
4933 the first instruction on the main stream does not. */
4934 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
4937 macro_build (p, &icnt, &offset_expr,
4938 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
4939 "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT16,
4942 if (expr1.X_add_number >= -0x8000
4943 && expr1.X_add_number < 0x8000)
4945 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
4947 macro_build (p, &icnt, &expr1,
4948 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
4949 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
4950 /* FIXME: If add_number is 0, and there was no base
4951 register, the external symbol case ended with a load,
4952 so if the symbol turns out to not be external, and
4953 the next instruction uses tempreg, an unnecessary nop
4954 will be inserted. */
4960 /* We must add in the base register now, as in the
4961 external symbol case. */
4962 assert (tempreg == AT);
4963 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
4965 macro_build (p, &icnt, (expressionS *) NULL,
4966 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
4967 "d,v,t", treg, AT, breg);
4970 /* We set breg to 0 because we have arranged to add
4971 it in in both cases. */
4975 macro_build_lui (p, &icnt, &expr1, AT);
4977 macro_build (p, &icnt, &expr1,
4978 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
4979 "t,r,j", AT, AT, (int) BFD_RELOC_LO16);
4981 macro_build (p, &icnt, (expressionS *) NULL,
4982 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
4983 "d,v,t", tempreg, tempreg, AT);
4987 else if (mips_pic == EMBEDDED_PIC)
4990 addiu $tempreg,$gp,<sym> (BFD_RELOC_GPREL16)
4992 macro_build ((char *) NULL, &icnt, &offset_expr,
4993 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", "t,r,j",
4994 tempreg, mips_gp_register, (int) BFD_RELOC_GPREL16);
5003 if (mips_pic == EMBEDDED_PIC || mips_pic == NO_PIC)
5004 s = (dbl || HAVE_64BIT_ADDRESSES) ? "daddu" : "addu";
5006 s = HAVE_64BIT_ADDRESSES ? "daddu" : "addu";
5008 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s,
5009 "d,v,t", treg, tempreg, breg);
5018 /* The j instruction may not be used in PIC code, since it
5019 requires an absolute address. We convert it to a b
5021 if (mips_pic == NO_PIC)
5022 macro_build ((char *) NULL, &icnt, &offset_expr, "j", "a");
5024 macro_build ((char *) NULL, &icnt, &offset_expr, "b", "p");
5027 /* The jal instructions must be handled as macros because when
5028 generating PIC code they expand to multi-instruction
5029 sequences. Normally they are simple instructions. */
5034 if (mips_pic == NO_PIC
5035 || mips_pic == EMBEDDED_PIC)
5036 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "jalr",
5038 else if (mips_pic == SVR4_PIC)
5040 if (sreg != PIC_CALL_REG)
5041 as_warn (_("MIPS PIC call to register other than $25"));
5043 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "jalr",
5047 if (mips_cprestore_offset < 0)
5048 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5051 if (! mips_frame_reg_valid)
5053 as_warn (_("No .frame pseudo-op used in PIC code"));
5054 /* Quiet this warning. */
5055 mips_frame_reg_valid = 1;
5057 if (! mips_cprestore_valid)
5059 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5060 /* Quiet this warning. */
5061 mips_cprestore_valid = 1;
5063 expr1.X_add_number = mips_cprestore_offset;
5064 macro_build ((char *) NULL, &icnt, &expr1,
5065 HAVE_32BIT_ADDRESSES ? "lw" : "ld", "t,o(b)",
5066 mips_gp_register, (int) BFD_RELOC_LO16,
5077 if (mips_pic == NO_PIC)
5078 macro_build ((char *) NULL, &icnt, &offset_expr, "jal", "a");
5079 else if (mips_pic == SVR4_PIC)
5083 /* If this is a reference to an external symbol, and we are
5084 using a small GOT, we want
5085 lw $25,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
5089 lw $gp,cprestore($sp)
5090 The cprestore value is set using the .cprestore
5091 pseudo-op. If we are using a big GOT, we want
5092 lui $25,<sym> (BFD_RELOC_MIPS_CALL_HI16)
5094 lw $25,<sym>($25) (BFD_RELOC_MIPS_CALL_LO16)
5098 lw $gp,cprestore($sp)
5099 If the symbol is not external, we want
5100 lw $25,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5102 addiu $25,$25,<sym> (BFD_RELOC_LO16)
5105 lw $gp,cprestore($sp)
5107 lw $25,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
5108 jalr $ra,$25 (BFD_RELOC_MIPS_JALR)
5112 macro_build ((char *) NULL, &icnt, &offset_expr,
5113 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5114 "t,o(b)", PIC_CALL_REG,
5115 (int) BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
5116 macro_build_jalr (icnt, &offset_expr);
5123 macro_build ((char *) NULL, &icnt, &offset_expr,
5124 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5125 "t,o(b)", PIC_CALL_REG,
5126 (int) BFD_RELOC_MIPS_CALL16, mips_gp_register);
5127 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5129 p = frag_var (rs_machine_dependent, 4, 0,
5130 RELAX_ENCODE (0, 4, -8, 0, 0, 0),
5131 offset_expr.X_add_symbol, 0, NULL);
5137 if (reg_needs_delay (mips_gp_register))
5141 macro_build ((char *) NULL, &icnt, &offset_expr, "lui",
5142 "t,u", PIC_CALL_REG,
5143 (int) BFD_RELOC_MIPS_CALL_HI16);
5144 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5145 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5146 "d,v,t", PIC_CALL_REG, PIC_CALL_REG,
5148 macro_build ((char *) NULL, &icnt, &offset_expr,
5149 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5150 "t,o(b)", PIC_CALL_REG,
5151 (int) BFD_RELOC_MIPS_CALL_LO16, PIC_CALL_REG);
5152 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5154 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
5155 RELAX_ENCODE (16, 12 + gpdel, gpdel,
5157 offset_expr.X_add_symbol, 0, NULL);
5160 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
5163 macro_build (p, &icnt, &offset_expr,
5164 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5165 "t,o(b)", PIC_CALL_REG,
5166 (int) BFD_RELOC_MIPS_GOT16, mips_gp_register);
5168 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
5171 macro_build (p, &icnt, &offset_expr,
5172 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
5173 "t,r,j", PIC_CALL_REG, PIC_CALL_REG,
5174 (int) BFD_RELOC_LO16);
5175 macro_build_jalr (icnt, &offset_expr);
5177 if (mips_cprestore_offset < 0)
5178 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5181 if (! mips_frame_reg_valid)
5183 as_warn (_("No .frame pseudo-op used in PIC code"));
5184 /* Quiet this warning. */
5185 mips_frame_reg_valid = 1;
5187 if (! mips_cprestore_valid)
5189 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5190 /* Quiet this warning. */
5191 mips_cprestore_valid = 1;
5193 if (mips_opts.noreorder)
5194 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5196 expr1.X_add_number = mips_cprestore_offset;
5197 macro_build ((char *) NULL, &icnt, &expr1,
5198 HAVE_32BIT_ADDRESSES ? "lw" : "ld", "t,o(b)",
5199 mips_gp_register, (int) BFD_RELOC_LO16,
5204 else if (mips_pic == EMBEDDED_PIC)
5206 macro_build ((char *) NULL, &icnt, &offset_expr, "bal", "p");
5207 /* The linker may expand the call to a longer sequence which
5208 uses $at, so we must break rather than return. */
5233 /* Itbl support may require additional care here. */
5238 /* Itbl support may require additional care here. */
5243 /* Itbl support may require additional care here. */
5248 /* Itbl support may require additional care here. */
5260 if (mips_arch == CPU_R4650)
5262 as_bad (_("opcode not supported on this processor"));
5266 /* Itbl support may require additional care here. */
5271 /* Itbl support may require additional care here. */
5276 /* Itbl support may require additional care here. */
5296 if (breg == treg || coproc || lr)
5318 /* Itbl support may require additional care here. */
5323 /* Itbl support may require additional care here. */
5328 /* Itbl support may require additional care here. */
5333 /* Itbl support may require additional care here. */
5349 if (mips_arch == CPU_R4650)
5351 as_bad (_("opcode not supported on this processor"));
5356 /* Itbl support may require additional care here. */
5360 /* Itbl support may require additional care here. */
5365 /* Itbl support may require additional care here. */
5377 /* Itbl support may require additional care here. */
5378 if (mask == M_LWC1_AB
5379 || mask == M_SWC1_AB
5380 || mask == M_LDC1_AB
5381 || mask == M_SDC1_AB
5390 /* For embedded PIC, we allow loads where the offset is calculated
5391 by subtracting a symbol in the current segment from an unknown
5392 symbol, relative to a base register, e.g.:
5393 <op> $treg, <sym>-<localsym>($breg)
5394 This is used by the compiler for switch statements. */
5395 if (mips_pic == EMBEDDED_PIC
5396 && offset_expr.X_op == O_subtract
5397 && (symbol_constant_p (offset_expr.X_op_symbol)
5398 ? S_GET_SEGMENT (offset_expr.X_op_symbol) == now_seg
5399 : (symbol_equated_p (offset_expr.X_op_symbol)
5401 (symbol_get_value_expression (offset_expr.X_op_symbol)
5405 && (offset_expr.X_add_number == 0
5406 || OUTPUT_FLAVOR == bfd_target_elf_flavour))
5408 /* For this case, we output the instructions:
5409 lui $tempreg,<sym> (BFD_RELOC_PCREL_HI16_S)
5410 addiu $tempreg,$tempreg,$breg
5411 <op> $treg,<sym>($tempreg) (BFD_RELOC_PCREL_LO16)
5412 If the relocation would fit entirely in 16 bits, it would be
5414 <op> $treg,<sym>($breg) (BFD_RELOC_PCREL_LO16)
5415 instead, but that seems quite difficult. */
5416 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
5417 tempreg, (int) BFD_RELOC_PCREL_HI16_S);
5418 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5419 ((bfd_arch_bits_per_address (stdoutput) == 32
5420 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5421 ? "addu" : "daddu"),
5422 "d,v,t", tempreg, tempreg, breg);
5423 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, treg,
5424 (int) BFD_RELOC_PCREL_LO16, tempreg);
5430 if (offset_expr.X_op != O_constant
5431 && offset_expr.X_op != O_symbol)
5433 as_bad (_("expression too complex"));
5434 offset_expr.X_op = O_constant;
5437 /* A constant expression in PIC code can be handled just as it
5438 is in non PIC code. */
5439 if (mips_pic == NO_PIC
5440 || offset_expr.X_op == O_constant)
5444 /* If this is a reference to a GP relative symbol, and there
5445 is no base register, we want
5446 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
5447 Otherwise, if there is no base register, we want
5448 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
5449 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5450 If we have a constant, we need two instructions anyhow,
5451 so we always use the latter form.
5453 If we have a base register, and this is a reference to a
5454 GP relative symbol, we want
5455 addu $tempreg,$breg,$gp
5456 <op> $treg,<sym>($tempreg) (BFD_RELOC_GPREL16)
5458 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
5459 addu $tempreg,$tempreg,$breg
5460 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5461 With a constant we always use the latter case.
5463 With 64bit address space and no base register and $at usable,
5465 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5466 lui $at,<sym> (BFD_RELOC_HI16_S)
5467 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
5470 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5471 If we have a base register, we want
5472 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5473 lui $at,<sym> (BFD_RELOC_HI16_S)
5474 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
5478 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5480 Without $at we can't generate the optimal path for superscalar
5481 processors here since this would require two temporary registers.
5482 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5483 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
5485 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
5487 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5488 If we have a base register, we want
5489 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5490 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
5492 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
5494 daddu $tempreg,$tempreg,$breg
5495 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5497 If we have 64-bit addresses, as an optimization, for
5498 addresses which are 32-bit constants (e.g. kseg0/kseg1
5499 addresses) we fall back to the 32-bit address generation
5500 mechanism since it is more efficient. This code should
5501 probably attempt to generate 64-bit constants more
5502 efficiently in general.
5504 if (HAVE_64BIT_ADDRESSES
5505 && !(offset_expr.X_op == O_constant
5506 && IS_SEXT_32BIT_NUM (offset_expr.X_add_number)))
5510 /* We don't do GP optimization for now because RELAX_ENCODE can't
5511 hold the data for such large chunks. */
5515 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
5516 tempreg, (int) BFD_RELOC_MIPS_HIGHEST);
5517 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
5518 AT, (int) BFD_RELOC_HI16_S);
5519 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
5520 tempreg, tempreg, (int) BFD_RELOC_MIPS_HIGHER);
5522 macro_build (p, &icnt, (expressionS *) NULL, "daddu",
5523 "d,v,t", AT, AT, breg);
5524 macro_build (p, &icnt, (expressionS *) NULL, "dsll32",
5525 "d,w,<", tempreg, tempreg, 0);
5526 macro_build (p, &icnt, (expressionS *) NULL, "daddu",
5527 "d,v,t", tempreg, tempreg, AT);
5528 macro_build (p, &icnt, &offset_expr, s,
5529 fmt, treg, (int) BFD_RELOC_LO16, tempreg);
5534 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
5535 tempreg, (int) BFD_RELOC_MIPS_HIGHEST);
5536 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
5537 tempreg, tempreg, (int) BFD_RELOC_MIPS_HIGHER);
5538 macro_build (p, &icnt, (expressionS *) NULL, "dsll",
5539 "d,w,<", tempreg, tempreg, 16);
5540 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
5541 tempreg, tempreg, (int) BFD_RELOC_HI16_S);
5542 macro_build (p, &icnt, (expressionS *) NULL, "dsll",
5543 "d,w,<", tempreg, tempreg, 16);
5545 macro_build (p, &icnt, (expressionS *) NULL, "daddu",
5546 "d,v,t", tempreg, tempreg, breg);
5547 macro_build (p, &icnt, &offset_expr, s,
5548 fmt, treg, (int) BFD_RELOC_LO16, tempreg);
5556 if ((valueT) offset_expr.X_add_number > MAX_GPREL_OFFSET
5557 || nopic_need_relax (offset_expr.X_add_symbol, 1))
5562 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
5563 treg, (int) BFD_RELOC_GPREL16,
5565 p = frag_var (rs_machine_dependent, 8, 0,
5566 RELAX_ENCODE (4, 8, 0, 4, 0,
5567 (mips_opts.warn_about_macros
5569 && mips_opts.noat))),
5570 offset_expr.X_add_symbol, 0, NULL);
5573 macro_build_lui (p, &icnt, &offset_expr, tempreg);
5576 macro_build (p, &icnt, &offset_expr, s, fmt, treg,
5577 (int) BFD_RELOC_LO16, tempreg);
5581 if ((valueT) offset_expr.X_add_number > MAX_GPREL_OFFSET
5582 || nopic_need_relax (offset_expr.X_add_symbol, 1))
5587 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5588 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5589 "d,v,t", tempreg, breg, mips_gp_register);
5590 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
5591 treg, (int) BFD_RELOC_GPREL16, tempreg);
5592 p = frag_var (rs_machine_dependent, 12, 0,
5593 RELAX_ENCODE (8, 12, 0, 8, 0, 0),
5594 offset_expr.X_add_symbol, 0, NULL);
5596 macro_build_lui (p, &icnt, &offset_expr, tempreg);
5599 macro_build (p, &icnt, (expressionS *) NULL,
5600 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5601 "d,v,t", tempreg, tempreg, breg);
5604 macro_build (p, &icnt, &offset_expr, s, fmt, treg,
5605 (int) BFD_RELOC_LO16, tempreg);
5608 else if (mips_pic == SVR4_PIC && ! mips_big_got)
5612 /* If this is a reference to an external symbol, we want
5613 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5615 <op> $treg,0($tempreg)
5617 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5619 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
5620 <op> $treg,0($tempreg)
5621 If there is a base register, we add it to $tempreg before
5622 the <op>. If there is a constant, we stick it in the
5623 <op> instruction. We don't handle constants larger than
5624 16 bits, because we have no way to load the upper 16 bits
5625 (actually, we could handle them for the subset of cases
5626 in which we are not using $at). */
5627 assert (offset_expr.X_op == O_symbol);
5628 expr1.X_add_number = offset_expr.X_add_number;
5629 offset_expr.X_add_number = 0;
5630 if (expr1.X_add_number < -0x8000
5631 || expr1.X_add_number >= 0x8000)
5632 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
5634 macro_build ((char *) NULL, &icnt, &offset_expr,
5635 HAVE_32BIT_ADDRESSES ? "lw" : "ld", "t,o(b)", tempreg,
5636 (int) BFD_RELOC_MIPS_GOT16, mips_gp_register);
5637 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
5638 p = frag_var (rs_machine_dependent, 4, 0,
5639 RELAX_ENCODE (0, 4, -8, 0, 0, 0),
5640 offset_expr.X_add_symbol, 0, NULL);
5641 macro_build (p, &icnt, &offset_expr,
5642 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
5643 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
5645 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5646 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5647 "d,v,t", tempreg, tempreg, breg);
5648 macro_build ((char *) NULL, &icnt, &expr1, s, fmt, treg,
5649 (int) BFD_RELOC_LO16, tempreg);
5651 else if (mips_pic == SVR4_PIC)
5656 /* If this is a reference to an external symbol, we want
5657 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5658 addu $tempreg,$tempreg,$gp
5659 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5660 <op> $treg,0($tempreg)
5662 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5664 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
5665 <op> $treg,0($tempreg)
5666 If there is a base register, we add it to $tempreg before
5667 the <op>. If there is a constant, we stick it in the
5668 <op> instruction. We don't handle constants larger than
5669 16 bits, because we have no way to load the upper 16 bits
5670 (actually, we could handle them for the subset of cases
5671 in which we are not using $at).
5674 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
5675 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_MIPS_GOT_OFST)
5676 <op> $treg,0($tempreg)
5678 assert (offset_expr.X_op == O_symbol);
5679 expr1.X_add_number = offset_expr.X_add_number;
5680 offset_expr.X_add_number = 0;
5681 if (expr1.X_add_number < -0x8000
5682 || expr1.X_add_number >= 0x8000)
5683 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
5686 macro_build ((char *) NULL, &icnt, &offset_expr,
5687 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5688 "t,o(b)", tempreg, BFD_RELOC_MIPS_GOT_PAGE,
5690 macro_build ((char *) NULL, &icnt, &offset_expr,
5691 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
5692 "t,r,j", tempreg, tempreg,
5693 BFD_RELOC_MIPS_GOT_OFST);
5695 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5696 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5697 "d,v,t", tempreg, tempreg, breg);
5698 macro_build ((char *) NULL, &icnt, &expr1, s, fmt, treg,
5699 (int) BFD_RELOC_LO16, tempreg);
5706 if (reg_needs_delay (mips_gp_register))
5711 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
5712 tempreg, (int) BFD_RELOC_MIPS_GOT_HI16);
5713 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5714 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5715 "d,v,t", tempreg, tempreg, mips_gp_register);
5716 macro_build ((char *) NULL, &icnt, &offset_expr,
5717 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5718 "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT_LO16,
5720 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
5721 RELAX_ENCODE (12, 12 + gpdel, gpdel, 8 + gpdel, 0, 0),
5722 offset_expr.X_add_symbol, 0, NULL);
5725 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
5728 macro_build (p, &icnt, &offset_expr,
5729 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5730 "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT16,
5733 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
5735 macro_build (p, &icnt, &offset_expr,
5736 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
5737 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
5739 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5740 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5741 "d,v,t", tempreg, tempreg, breg);
5742 macro_build ((char *) NULL, &icnt, &expr1, s, fmt, treg,
5743 (int) BFD_RELOC_LO16, tempreg);
5745 else if (mips_pic == EMBEDDED_PIC)
5747 /* If there is no base register, we want
5748 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
5749 If there is a base register, we want
5750 addu $tempreg,$breg,$gp
5751 <op> $treg,<sym>($tempreg) (BFD_RELOC_GPREL16)
5753 assert (offset_expr.X_op == O_symbol);
5756 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
5757 treg, (int) BFD_RELOC_GPREL16, mips_gp_register);
5762 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5763 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5764 "d,v,t", tempreg, breg, mips_gp_register);
5765 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
5766 treg, (int) BFD_RELOC_GPREL16, tempreg);
5779 load_register (&icnt, treg, &imm_expr, 0);
5783 load_register (&icnt, treg, &imm_expr, 1);
5787 if (imm_expr.X_op == O_constant)
5789 load_register (&icnt, AT, &imm_expr, 0);
5790 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5791 "mtc1", "t,G", AT, treg);
5796 assert (offset_expr.X_op == O_symbol
5797 && strcmp (segment_name (S_GET_SEGMENT
5798 (offset_expr.X_add_symbol)),
5800 && offset_expr.X_add_number == 0);
5801 macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)",
5802 treg, (int) BFD_RELOC_MIPS_LITERAL, mips_gp_register);
5807 /* Check if we have a constant in IMM_EXPR. If the GPRs are 64 bits
5808 wide, IMM_EXPR is the entire value. Otherwise IMM_EXPR is the high
5809 order 32 bits of the value and the low order 32 bits are either
5810 zero or in OFFSET_EXPR. */
5811 if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big)
5813 if (HAVE_64BIT_GPRS)
5814 load_register (&icnt, treg, &imm_expr, 1);
5819 if (target_big_endian)
5831 load_register (&icnt, hreg, &imm_expr, 0);
5834 if (offset_expr.X_op == O_absent)
5835 move_register (&icnt, lreg, 0);
5838 assert (offset_expr.X_op == O_constant);
5839 load_register (&icnt, lreg, &offset_expr, 0);
5846 /* We know that sym is in the .rdata section. First we get the
5847 upper 16 bits of the address. */
5848 if (mips_pic == NO_PIC)
5850 macro_build_lui (NULL, &icnt, &offset_expr, AT);
5852 else if (mips_pic == SVR4_PIC)
5854 macro_build ((char *) NULL, &icnt, &offset_expr,
5855 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5856 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16,
5859 else if (mips_pic == EMBEDDED_PIC)
5861 /* For embedded PIC we pick up the entire address off $gp in
5862 a single instruction. */
5863 macro_build ((char *) NULL, &icnt, &offset_expr,
5864 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", "t,r,j", AT,
5865 mips_gp_register, (int) BFD_RELOC_GPREL16);
5866 offset_expr.X_op = O_constant;
5867 offset_expr.X_add_number = 0;
5872 /* Now we load the register(s). */
5873 if (HAVE_64BIT_GPRS)
5874 macro_build ((char *) NULL, &icnt, &offset_expr, "ld", "t,o(b)",
5875 treg, (int) BFD_RELOC_LO16, AT);
5878 macro_build ((char *) NULL, &icnt, &offset_expr, "lw", "t,o(b)",
5879 treg, (int) BFD_RELOC_LO16, AT);
5882 /* FIXME: How in the world do we deal with the possible
5884 offset_expr.X_add_number += 4;
5885 macro_build ((char *) NULL, &icnt, &offset_expr, "lw", "t,o(b)",
5886 treg + 1, (int) BFD_RELOC_LO16, AT);
5890 /* To avoid confusion in tc_gen_reloc, we must ensure that this
5891 does not become a variant frag. */
5892 frag_wane (frag_now);
5898 /* Check if we have a constant in IMM_EXPR. If the FPRs are 64 bits
5899 wide, IMM_EXPR is the entire value and the GPRs are known to be 64
5900 bits wide as well. Otherwise IMM_EXPR is the high order 32 bits of
5901 the value and the low order 32 bits are either zero or in
5903 if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big)
5905 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_FPRS);
5906 if (HAVE_64BIT_FPRS)
5908 assert (HAVE_64BIT_GPRS);
5909 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5910 "dmtc1", "t,S", AT, treg);
5914 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5915 "mtc1", "t,G", AT, treg + 1);
5916 if (offset_expr.X_op == O_absent)
5917 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5918 "mtc1", "t,G", 0, treg);
5921 assert (offset_expr.X_op == O_constant);
5922 load_register (&icnt, AT, &offset_expr, 0);
5923 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5924 "mtc1", "t,G", AT, treg);
5930 assert (offset_expr.X_op == O_symbol
5931 && offset_expr.X_add_number == 0);
5932 s = segment_name (S_GET_SEGMENT (offset_expr.X_add_symbol));
5933 if (strcmp (s, ".lit8") == 0)
5935 if (mips_opts.isa != ISA_MIPS1)
5937 macro_build ((char *) NULL, &icnt, &offset_expr, "ldc1",
5938 "T,o(b)", treg, (int) BFD_RELOC_MIPS_LITERAL,
5942 breg = mips_gp_register;
5943 r = BFD_RELOC_MIPS_LITERAL;
5948 assert (strcmp (s, RDATA_SECTION_NAME) == 0);
5949 if (mips_pic == SVR4_PIC)
5950 macro_build ((char *) NULL, &icnt, &offset_expr,
5951 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5952 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16,
5956 /* FIXME: This won't work for a 64 bit address. */
5957 macro_build_lui (NULL, &icnt, &offset_expr, AT);
5960 if (mips_opts.isa != ISA_MIPS1)
5962 macro_build ((char *) NULL, &icnt, &offset_expr, "ldc1",
5963 "T,o(b)", treg, (int) BFD_RELOC_LO16, AT);
5965 /* To avoid confusion in tc_gen_reloc, we must ensure
5966 that this does not become a variant frag. */
5967 frag_wane (frag_now);
5978 if (mips_arch == CPU_R4650)
5980 as_bad (_("opcode not supported on this processor"));
5983 /* Even on a big endian machine $fn comes before $fn+1. We have
5984 to adjust when loading from memory. */
5987 assert (mips_opts.isa == ISA_MIPS1);
5988 macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)",
5989 target_big_endian ? treg + 1 : treg,
5991 /* FIXME: A possible overflow which I don't know how to deal
5993 offset_expr.X_add_number += 4;
5994 macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)",
5995 target_big_endian ? treg : treg + 1,
5998 /* To avoid confusion in tc_gen_reloc, we must ensure that this
5999 does not become a variant frag. */
6000 frag_wane (frag_now);
6009 * The MIPS assembler seems to check for X_add_number not
6010 * being double aligned and generating:
6013 * addiu at,at,%lo(foo+1)
6016 * But, the resulting address is the same after relocation so why
6017 * generate the extra instruction?
6019 if (mips_arch == CPU_R4650)
6021 as_bad (_("opcode not supported on this processor"));
6024 /* Itbl support may require additional care here. */
6026 if (mips_opts.isa != ISA_MIPS1)
6037 if (mips_arch == CPU_R4650)
6039 as_bad (_("opcode not supported on this processor"));
6043 if (mips_opts.isa != ISA_MIPS1)
6051 /* Itbl support may require additional care here. */
6056 if (HAVE_64BIT_GPRS)
6067 if (HAVE_64BIT_GPRS)
6077 /* We do _not_ bother to allow embedded PIC (symbol-local_symbol)
6078 loads for the case of doing a pair of loads to simulate an 'ld'.
6079 This is not currently done by the compiler, and assembly coders
6080 writing embedded-pic code can cope. */
6082 if (offset_expr.X_op != O_symbol
6083 && offset_expr.X_op != O_constant)
6085 as_bad (_("expression too complex"));
6086 offset_expr.X_op = O_constant;
6089 /* Even on a big endian machine $fn comes before $fn+1. We have
6090 to adjust when loading from memory. We set coproc if we must
6091 load $fn+1 first. */
6092 /* Itbl support may require additional care here. */
6093 if (! target_big_endian)
6096 if (mips_pic == NO_PIC
6097 || offset_expr.X_op == O_constant)
6101 /* If this is a reference to a GP relative symbol, we want
6102 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
6103 <op> $treg+1,<sym>+4($gp) (BFD_RELOC_GPREL16)
6104 If we have a base register, we use this
6106 <op> $treg,<sym>($at) (BFD_RELOC_GPREL16)
6107 <op> $treg+1,<sym>+4($at) (BFD_RELOC_GPREL16)
6108 If this is not a GP relative symbol, we want
6109 lui $at,<sym> (BFD_RELOC_HI16_S)
6110 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
6111 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
6112 If there is a base register, we add it to $at after the
6113 lui instruction. If there is a constant, we always use
6115 if ((valueT) offset_expr.X_add_number > MAX_GPREL_OFFSET
6116 || nopic_need_relax (offset_expr.X_add_symbol, 1))
6128 tempreg = mips_gp_register;
6135 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6136 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
6137 "d,v,t", AT, breg, mips_gp_register);
6143 /* Itbl support may require additional care here. */
6144 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
6145 coproc ? treg + 1 : treg,
6146 (int) BFD_RELOC_GPREL16, tempreg);
6147 offset_expr.X_add_number += 4;
6149 /* Set mips_optimize to 2 to avoid inserting an
6151 hold_mips_optimize = mips_optimize;
6153 /* Itbl support may require additional care here. */
6154 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
6155 coproc ? treg : treg + 1,
6156 (int) BFD_RELOC_GPREL16, tempreg);
6157 mips_optimize = hold_mips_optimize;
6159 p = frag_var (rs_machine_dependent, 12 + off, 0,
6160 RELAX_ENCODE (8 + off, 12 + off, 0, 4 + off, 1,
6161 used_at && mips_opts.noat),
6162 offset_expr.X_add_symbol, 0, NULL);
6164 /* We just generated two relocs. When tc_gen_reloc
6165 handles this case, it will skip the first reloc and
6166 handle the second. The second reloc already has an
6167 extra addend of 4, which we added above. We must
6168 subtract it out, and then subtract another 4 to make
6169 the first reloc come out right. The second reloc
6170 will come out right because we are going to add 4 to
6171 offset_expr when we build its instruction below.
6173 If we have a symbol, then we don't want to include
6174 the offset, because it will wind up being included
6175 when we generate the reloc. */
6177 if (offset_expr.X_op == O_constant)
6178 offset_expr.X_add_number -= 8;
6181 offset_expr.X_add_number = -4;
6182 offset_expr.X_op = O_constant;
6185 macro_build_lui (p, &icnt, &offset_expr, AT);
6190 macro_build (p, &icnt, (expressionS *) NULL,
6191 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
6192 "d,v,t", AT, breg, AT);
6196 /* Itbl support may require additional care here. */
6197 macro_build (p, &icnt, &offset_expr, s, fmt,
6198 coproc ? treg + 1 : treg,
6199 (int) BFD_RELOC_LO16, AT);
6202 /* FIXME: How do we handle overflow here? */
6203 offset_expr.X_add_number += 4;
6204 /* Itbl support may require additional care here. */
6205 macro_build (p, &icnt, &offset_expr, s, fmt,
6206 coproc ? treg : treg + 1,
6207 (int) BFD_RELOC_LO16, AT);
6209 else if (mips_pic == SVR4_PIC && ! mips_big_got)
6213 /* If this is a reference to an external symbol, we want
6214 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6219 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6221 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
6222 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
6223 If there is a base register we add it to $at before the
6224 lwc1 instructions. If there is a constant we include it
6225 in the lwc1 instructions. */
6227 expr1.X_add_number = offset_expr.X_add_number;
6228 offset_expr.X_add_number = 0;
6229 if (expr1.X_add_number < -0x8000
6230 || expr1.X_add_number >= 0x8000 - 4)
6231 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6236 frag_grow (24 + off);
6237 macro_build ((char *) NULL, &icnt, &offset_expr,
6238 HAVE_32BIT_ADDRESSES ? "lw" : "ld", "t,o(b)", AT,
6239 (int) BFD_RELOC_MIPS_GOT16, mips_gp_register);
6240 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
6242 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6243 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
6244 "d,v,t", AT, breg, AT);
6245 /* Itbl support may require additional care here. */
6246 macro_build ((char *) NULL, &icnt, &expr1, s, fmt,
6247 coproc ? treg + 1 : treg,
6248 (int) BFD_RELOC_LO16, AT);
6249 expr1.X_add_number += 4;
6251 /* Set mips_optimize to 2 to avoid inserting an undesired
6253 hold_mips_optimize = mips_optimize;
6255 /* Itbl support may require additional care here. */
6256 macro_build ((char *) NULL, &icnt, &expr1, s, fmt,
6257 coproc ? treg : treg + 1,
6258 (int) BFD_RELOC_LO16, AT);
6259 mips_optimize = hold_mips_optimize;
6261 (void) frag_var (rs_machine_dependent, 0, 0,
6262 RELAX_ENCODE (0, 0, -16 - off, -8, 1, 0),
6263 offset_expr.X_add_symbol, 0, NULL);
6265 else if (mips_pic == SVR4_PIC)
6270 /* If this is a reference to an external symbol, we want
6271 lui $at,<sym> (BFD_RELOC_MIPS_GOT_HI16)
6273 lw $at,<sym>($at) (BFD_RELOC_MIPS_GOT_LO16)
6278 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6280 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
6281 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
6282 If there is a base register we add it to $at before the
6283 lwc1 instructions. If there is a constant we include it
6284 in the lwc1 instructions. */
6286 expr1.X_add_number = offset_expr.X_add_number;
6287 offset_expr.X_add_number = 0;
6288 if (expr1.X_add_number < -0x8000
6289 || expr1.X_add_number >= 0x8000 - 4)
6290 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6291 if (reg_needs_delay (mips_gp_register))
6300 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
6301 AT, (int) BFD_RELOC_MIPS_GOT_HI16);
6302 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6303 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
6304 "d,v,t", AT, AT, mips_gp_register);
6305 macro_build ((char *) NULL, &icnt, &offset_expr,
6306 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
6307 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT_LO16, AT);
6308 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
6310 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6311 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
6312 "d,v,t", AT, breg, AT);
6313 /* Itbl support may require additional care here. */
6314 macro_build ((char *) NULL, &icnt, &expr1, s, fmt,
6315 coproc ? treg + 1 : treg,
6316 (int) BFD_RELOC_LO16, AT);
6317 expr1.X_add_number += 4;
6319 /* Set mips_optimize to 2 to avoid inserting an undesired
6321 hold_mips_optimize = mips_optimize;
6323 /* Itbl support may require additional care here. */
6324 macro_build ((char *) NULL, &icnt, &expr1, s, fmt,
6325 coproc ? treg : treg + 1,
6326 (int) BFD_RELOC_LO16, AT);
6327 mips_optimize = hold_mips_optimize;
6328 expr1.X_add_number -= 4;
6330 p = frag_var (rs_machine_dependent, 16 + gpdel + off, 0,
6331 RELAX_ENCODE (24 + off, 16 + gpdel + off, gpdel,
6332 8 + gpdel + off, 1, 0),
6333 offset_expr.X_add_symbol, 0, NULL);
6336 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
6339 macro_build (p, &icnt, &offset_expr,
6340 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
6341 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16,
6344 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
6348 macro_build (p, &icnt, (expressionS *) NULL,
6349 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
6350 "d,v,t", AT, breg, AT);
6353 /* Itbl support may require additional care here. */
6354 macro_build (p, &icnt, &expr1, s, fmt,
6355 coproc ? treg + 1 : treg,
6356 (int) BFD_RELOC_LO16, AT);
6358 expr1.X_add_number += 4;
6360 /* Set mips_optimize to 2 to avoid inserting an undesired
6362 hold_mips_optimize = mips_optimize;
6364 /* Itbl support may require additional care here. */
6365 macro_build (p, &icnt, &expr1, s, fmt,
6366 coproc ? treg : treg + 1,
6367 (int) BFD_RELOC_LO16, AT);
6368 mips_optimize = hold_mips_optimize;
6370 else if (mips_pic == EMBEDDED_PIC)
6372 /* If there is no base register, we use
6373 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
6374 <op> $treg+1,<sym>+4($gp) (BFD_RELOC_GPREL16)
6375 If we have a base register, we use
6377 <op> $treg,<sym>($at) (BFD_RELOC_GPREL16)
6378 <op> $treg+1,<sym>+4($at) (BFD_RELOC_GPREL16)
6382 tempreg = mips_gp_register;
6387 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6388 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
6389 "d,v,t", AT, breg, mips_gp_register);
6394 /* Itbl support may require additional care here. */
6395 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
6396 coproc ? treg + 1 : treg,
6397 (int) BFD_RELOC_GPREL16, tempreg);
6398 offset_expr.X_add_number += 4;
6399 /* Itbl support may require additional care here. */
6400 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
6401 coproc ? treg : treg + 1,
6402 (int) BFD_RELOC_GPREL16, tempreg);
6418 assert (HAVE_32BIT_ADDRESSES);
6419 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg,
6420 (int) BFD_RELOC_LO16, breg);
6421 offset_expr.X_add_number += 4;
6422 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg + 1,
6423 (int) BFD_RELOC_LO16, breg);
6426 /* New code added to support COPZ instructions.
6427 This code builds table entries out of the macros in mip_opcodes.
6428 R4000 uses interlocks to handle coproc delays.
6429 Other chips (like the R3000) require nops to be inserted for delays.
6431 FIXME: Currently, we require that the user handle delays.
6432 In order to fill delay slots for non-interlocked chips,
6433 we must have a way to specify delays based on the coprocessor.
6434 Eg. 4 cycles if load coproc reg from memory, 1 if in cache, etc.
6435 What are the side-effects of the cop instruction?
6436 What cache support might we have and what are its effects?
6437 Both coprocessor & memory require delays. how long???
6438 What registers are read/set/modified?
6440 If an itbl is provided to interpret cop instructions,
6441 this knowledge can be encoded in the itbl spec. */
6455 /* For now we just do C (same as Cz). The parameter will be
6456 stored in insn_opcode by mips_ip. */
6457 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "C",
6462 move_register (&icnt, dreg, sreg);
6465 #ifdef LOSING_COMPILER
6467 /* Try and see if this is a new itbl instruction.
6468 This code builds table entries out of the macros in mip_opcodes.
6469 FIXME: For now we just assemble the expression and pass it's
6470 value along as a 32-bit immediate.
6471 We may want to have the assembler assemble this value,
6472 so that we gain the assembler's knowledge of delay slots,
6474 Would it be more efficient to use mask (id) here? */
6475 if (itbl_have_entries
6476 && (immed_expr = itbl_assemble (ip->insn_mo->name, "")))
6478 s = ip->insn_mo->name;
6480 coproc = ITBL_DECODE_PNUM (immed_expr);;
6481 macro_build ((char *) NULL, &icnt, &immed_expr, s, "C");
6488 as_warn (_("Macro used $at after \".set noat\""));
6493 struct mips_cl_insn *ip;
6495 register int treg, sreg, dreg, breg;
6511 bfd_reloc_code_real_type r;
6514 treg = (ip->insn_opcode >> 16) & 0x1f;
6515 dreg = (ip->insn_opcode >> 11) & 0x1f;
6516 sreg = breg = (ip->insn_opcode >> 21) & 0x1f;
6517 mask = ip->insn_mo->mask;
6519 expr1.X_op = O_constant;
6520 expr1.X_op_symbol = NULL;
6521 expr1.X_add_symbol = NULL;
6522 expr1.X_add_number = 1;
6526 #endif /* LOSING_COMPILER */
6531 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6532 dbl ? "dmultu" : "multu", "s,t", sreg, treg);
6533 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "d",
6540 /* The MIPS assembler some times generates shifts and adds. I'm
6541 not trying to be that fancy. GCC should do this for us
6543 load_register (&icnt, AT, &imm_expr, dbl);
6544 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6545 dbl ? "dmult" : "mult", "s,t", sreg, AT);
6546 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "d",
6560 mips_emit_delays (true);
6561 ++mips_opts.noreorder;
6562 mips_any_noreorder = 1;
6564 load_register (&icnt, AT, &imm_expr, dbl);
6565 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6566 dbl ? "dmult" : "mult", "s,t", sreg, imm ? AT : treg);
6567 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "d",
6569 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6570 dbl ? "dsra32" : "sra", "d,w,<", dreg, dreg, RA);
6571 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mfhi", "d",
6574 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "tne", "s,t",
6578 expr1.X_add_number = 8;
6579 macro_build ((char *) NULL, &icnt, &expr1, "beq", "s,t,p", dreg,
6581 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "",
6583 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
6586 --mips_opts.noreorder;
6587 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "d", dreg);
6600 mips_emit_delays (true);
6601 ++mips_opts.noreorder;
6602 mips_any_noreorder = 1;
6604 load_register (&icnt, AT, &imm_expr, dbl);
6605 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6606 dbl ? "dmultu" : "multu",
6607 "s,t", sreg, imm ? AT : treg);
6608 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mfhi", "d",
6610 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "d",
6613 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "tne", "s,t",
6617 expr1.X_add_number = 8;
6618 macro_build ((char *) NULL, &icnt, &expr1, "beq", "s,t,p", AT, 0);
6619 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "",
6621 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
6624 --mips_opts.noreorder;
6628 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "dsubu",
6629 "d,v,t", AT, 0, treg);
6630 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "dsrlv",
6631 "d,t,s", AT, sreg, AT);
6632 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "dsllv",
6633 "d,t,s", dreg, sreg, treg);
6634 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or",
6635 "d,v,t", dreg, dreg, AT);
6639 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "subu",
6640 "d,v,t", AT, 0, treg);
6641 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srlv",
6642 "d,t,s", AT, sreg, AT);
6643 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sllv",
6644 "d,t,s", dreg, sreg, treg);
6645 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or",
6646 "d,v,t", dreg, dreg, AT);
6654 if (imm_expr.X_op != O_constant)
6655 as_bad (_("rotate count too large"));
6656 rot = imm_expr.X_add_number & 0x3f;
6659 l = (rot < 0x20) ? "dsll" : "dsll32";
6660 r = ((0x40 - rot) < 0x20) ? "dsrl" : "dsrl32";
6662 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, l,
6663 "d,w,<", AT, sreg, rot);
6664 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, r,
6665 "d,w,<", dreg, sreg, (0x20 - rot) & 0x1f);
6666 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or",
6667 "d,v,t", dreg, dreg, AT);
6675 if (imm_expr.X_op != O_constant)
6676 as_bad (_("rotate count too large"));
6677 rot = imm_expr.X_add_number & 0x1f;
6680 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sll",
6681 "d,w,<", AT, sreg, rot);
6682 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srl",
6683 "d,w,<", dreg, sreg, (0x20 - rot) & 0x1f);
6684 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or",
6685 "d,v,t", dreg, dreg, AT);
6690 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "dsubu",
6691 "d,v,t", AT, 0, treg);
6692 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "dsllv",
6693 "d,t,s", AT, sreg, AT);
6694 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "dsrlv",
6695 "d,t,s", dreg, sreg, treg);
6696 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or",
6697 "d,v,t", dreg, dreg, AT);
6701 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "subu",
6702 "d,v,t", AT, 0, treg);
6703 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sllv",
6704 "d,t,s", AT, sreg, AT);
6705 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srlv",
6706 "d,t,s", dreg, sreg, treg);
6707 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or",
6708 "d,v,t", dreg, dreg, AT);
6716 if (imm_expr.X_op != O_constant)
6717 as_bad (_("rotate count too large"));
6718 rot = imm_expr.X_add_number & 0x3f;
6721 r = (rot < 0x20) ? "dsrl" : "dsrl32";
6722 l = ((0x40 - rot) < 0x20) ? "dsll" : "dsll32";
6724 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, r,
6725 "d,w,<", AT, sreg, rot);
6726 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, l,
6727 "d,w,<", dreg, sreg, (0x20 - rot) & 0x1f);
6728 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or",
6729 "d,v,t", dreg, dreg, AT);
6737 if (imm_expr.X_op != O_constant)
6738 as_bad (_("rotate count too large"));
6739 rot = imm_expr.X_add_number & 0x1f;
6742 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srl",
6743 "d,w,<", AT, sreg, rot);
6744 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sll",
6745 "d,w,<", dreg, sreg, (0x20 - rot) & 0x1f);
6746 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or",
6747 "d,v,t", dreg, dreg, AT);
6752 if (mips_arch == CPU_R4650)
6754 as_bad (_("opcode not supported on this processor"));
6757 assert (mips_opts.isa == ISA_MIPS1);
6758 /* Even on a big endian machine $fn comes before $fn+1. We have
6759 to adjust when storing to memory. */
6760 macro_build ((char *) NULL, &icnt, &offset_expr, "swc1", "T,o(b)",
6761 target_big_endian ? treg + 1 : treg,
6762 (int) BFD_RELOC_LO16, breg);
6763 offset_expr.X_add_number += 4;
6764 macro_build ((char *) NULL, &icnt, &offset_expr, "swc1", "T,o(b)",
6765 target_big_endian ? treg : treg + 1,
6766 (int) BFD_RELOC_LO16, breg);
6771 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg,
6772 treg, (int) BFD_RELOC_LO16);
6774 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg,
6775 sreg, (int) BFD_RELOC_LO16);
6778 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "xor",
6779 "d,v,t", dreg, sreg, treg);
6780 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg,
6781 dreg, (int) BFD_RELOC_LO16);
6786 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
6788 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg,
6789 sreg, (int) BFD_RELOC_LO16);
6794 as_warn (_("Instruction %s: result is always false"),
6796 move_register (&icnt, dreg, 0);
6799 if (imm_expr.X_op == O_constant
6800 && imm_expr.X_add_number >= 0
6801 && imm_expr.X_add_number < 0x10000)
6803 macro_build ((char *) NULL, &icnt, &imm_expr, "xori", "t,r,i", dreg,
6804 sreg, (int) BFD_RELOC_LO16);
6807 else if (imm_expr.X_op == O_constant
6808 && imm_expr.X_add_number > -0x8000
6809 && imm_expr.X_add_number < 0)
6811 imm_expr.X_add_number = -imm_expr.X_add_number;
6812 macro_build ((char *) NULL, &icnt, &imm_expr,
6813 HAVE_32BIT_GPRS ? "addiu" : "daddiu",
6814 "t,r,j", dreg, sreg,
6815 (int) BFD_RELOC_LO16);
6820 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
6821 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "xor",
6822 "d,v,t", dreg, sreg, AT);
6825 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, dreg,
6826 (int) BFD_RELOC_LO16);
6831 case M_SGE: /* sreg >= treg <==> not (sreg < treg) */
6837 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d,v,t",
6839 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
6840 (int) BFD_RELOC_LO16);
6843 case M_SGE_I: /* sreg >= I <==> not (sreg < I) */
6845 if (imm_expr.X_op == O_constant
6846 && imm_expr.X_add_number >= -0x8000
6847 && imm_expr.X_add_number < 0x8000)
6849 macro_build ((char *) NULL, &icnt, &imm_expr,
6850 mask == M_SGE_I ? "slti" : "sltiu",
6851 "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16);
6856 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
6857 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6858 mask == M_SGE_I ? "slt" : "sltu", "d,v,t", dreg, sreg,
6862 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
6863 (int) BFD_RELOC_LO16);
6868 case M_SGT: /* sreg > treg <==> treg < sreg */
6874 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d,v,t",
6878 case M_SGT_I: /* sreg > I <==> I < sreg */
6884 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
6885 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d,v,t",
6889 case M_SLE: /* sreg <= treg <==> treg >= sreg <==> not (treg < sreg) */
6895 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d,v,t",
6897 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
6898 (int) BFD_RELOC_LO16);
6901 case M_SLE_I: /* sreg <= I <==> I >= sreg <==> not (I < sreg) */
6907 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
6908 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d,v,t",
6910 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
6911 (int) BFD_RELOC_LO16);
6915 if (imm_expr.X_op == O_constant
6916 && imm_expr.X_add_number >= -0x8000
6917 && imm_expr.X_add_number < 0x8000)
6919 macro_build ((char *) NULL, &icnt, &imm_expr, "slti", "t,r,j",
6920 dreg, sreg, (int) BFD_RELOC_LO16);
6923 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
6924 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "slt", "d,v,t",
6929 if (imm_expr.X_op == O_constant
6930 && imm_expr.X_add_number >= -0x8000
6931 && imm_expr.X_add_number < 0x8000)
6933 macro_build ((char *) NULL, &icnt, &imm_expr, "sltiu", "t,r,j",
6934 dreg, sreg, (int) BFD_RELOC_LO16);
6937 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
6938 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
6939 "d,v,t", dreg, sreg, AT);
6944 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
6945 "d,v,t", dreg, 0, treg);
6947 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
6948 "d,v,t", dreg, 0, sreg);
6951 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "xor",
6952 "d,v,t", dreg, sreg, treg);
6953 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
6954 "d,v,t", dreg, 0, dreg);
6959 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
6961 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
6962 "d,v,t", dreg, 0, sreg);
6967 as_warn (_("Instruction %s: result is always true"),
6969 macro_build ((char *) NULL, &icnt, &expr1,
6970 HAVE_32BIT_GPRS ? "addiu" : "daddiu",
6971 "t,r,j", dreg, 0, (int) BFD_RELOC_LO16);
6974 if (imm_expr.X_op == O_constant
6975 && imm_expr.X_add_number >= 0
6976 && imm_expr.X_add_number < 0x10000)
6978 macro_build ((char *) NULL, &icnt, &imm_expr, "xori", "t,r,i",
6979 dreg, sreg, (int) BFD_RELOC_LO16);
6982 else if (imm_expr.X_op == O_constant
6983 && imm_expr.X_add_number > -0x8000
6984 && imm_expr.X_add_number < 0)
6986 imm_expr.X_add_number = -imm_expr.X_add_number;
6987 macro_build ((char *) NULL, &icnt, &imm_expr,
6988 HAVE_32BIT_GPRS ? "addiu" : "daddiu",
6989 "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16);
6994 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
6995 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "xor",
6996 "d,v,t", dreg, sreg, AT);
6999 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
7000 "d,v,t", dreg, 0, dreg);
7008 if (imm_expr.X_op == O_constant
7009 && imm_expr.X_add_number > -0x8000
7010 && imm_expr.X_add_number <= 0x8000)
7012 imm_expr.X_add_number = -imm_expr.X_add_number;
7013 macro_build ((char *) NULL, &icnt, &imm_expr,
7014 dbl ? "daddi" : "addi",
7015 "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16);
7018 load_register (&icnt, AT, &imm_expr, dbl);
7019 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7020 dbl ? "dsub" : "sub", "d,v,t", dreg, sreg, AT);
7026 if (imm_expr.X_op == O_constant
7027 && imm_expr.X_add_number > -0x8000
7028 && imm_expr.X_add_number <= 0x8000)
7030 imm_expr.X_add_number = -imm_expr.X_add_number;
7031 macro_build ((char *) NULL, &icnt, &imm_expr,
7032 dbl ? "daddiu" : "addiu",
7033 "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16);
7036 load_register (&icnt, AT, &imm_expr, dbl);
7037 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7038 dbl ? "dsubu" : "subu", "d,v,t", dreg, sreg, AT);
7059 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
7060 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "s,t", sreg,
7066 assert (mips_opts.isa == ISA_MIPS1);
7067 sreg = (ip->insn_opcode >> 11) & 0x1f; /* floating reg */
7068 dreg = (ip->insn_opcode >> 06) & 0x1f; /* floating reg */
7071 * Is the double cfc1 instruction a bug in the mips assembler;
7072 * or is there a reason for it?
7074 mips_emit_delays (true);
7075 ++mips_opts.noreorder;
7076 mips_any_noreorder = 1;
7077 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "cfc1", "t,G",
7079 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "cfc1", "t,G",
7081 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
7082 expr1.X_add_number = 3;
7083 macro_build ((char *) NULL, &icnt, &expr1, "ori", "t,r,i", AT, treg,
7084 (int) BFD_RELOC_LO16);
7085 expr1.X_add_number = 2;
7086 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", AT, AT,
7087 (int) BFD_RELOC_LO16);
7088 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "ctc1", "t,G",
7090 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
7091 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7092 mask == M_TRUNCWD ? "cvt.w.d" : "cvt.w.s", "D,S", dreg, sreg);
7093 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "ctc1", "t,G",
7095 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
7096 --mips_opts.noreorder;
7105 if (offset_expr.X_add_number >= 0x7fff)
7106 as_bad (_("operand overflow"));
7107 /* avoid load delay */
7108 if (! target_big_endian)
7109 ++offset_expr.X_add_number;
7110 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg,
7111 (int) BFD_RELOC_LO16, breg);
7112 if (! target_big_endian)
7113 --offset_expr.X_add_number;
7115 ++offset_expr.X_add_number;
7116 macro_build ((char *) NULL, &icnt, &offset_expr, "lbu", "t,o(b)", AT,
7117 (int) BFD_RELOC_LO16, breg);
7118 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sll", "d,w,<",
7120 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or", "d,v,t",
7134 if (offset_expr.X_add_number >= 0x8000 - off)
7135 as_bad (_("operand overflow"));
7136 if (! target_big_endian)
7137 offset_expr.X_add_number += off;
7138 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg,
7139 (int) BFD_RELOC_LO16, breg);
7140 if (! target_big_endian)
7141 offset_expr.X_add_number -= off;
7143 offset_expr.X_add_number += off;
7144 macro_build ((char *) NULL, &icnt, &offset_expr, s2, "t,o(b)", treg,
7145 (int) BFD_RELOC_LO16, breg);
7159 load_address (&icnt, AT, &offset_expr, &used_at);
7161 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7162 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
7163 "d,v,t", AT, AT, breg);
7164 if (! target_big_endian)
7165 expr1.X_add_number = off;
7167 expr1.X_add_number = 0;
7168 macro_build ((char *) NULL, &icnt, &expr1, s, "t,o(b)", treg,
7169 (int) BFD_RELOC_LO16, AT);
7170 if (! target_big_endian)
7171 expr1.X_add_number = 0;
7173 expr1.X_add_number = off;
7174 macro_build ((char *) NULL, &icnt, &expr1, s2, "t,o(b)", treg,
7175 (int) BFD_RELOC_LO16, AT);
7181 load_address (&icnt, AT, &offset_expr, &used_at);
7183 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7184 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
7185 "d,v,t", AT, AT, breg);
7186 if (target_big_endian)
7187 expr1.X_add_number = 0;
7188 macro_build ((char *) NULL, &icnt, &expr1,
7189 mask == M_ULH_A ? "lb" : "lbu", "t,o(b)", treg,
7190 (int) BFD_RELOC_LO16, AT);
7191 if (target_big_endian)
7192 expr1.X_add_number = 1;
7194 expr1.X_add_number = 0;
7195 macro_build ((char *) NULL, &icnt, &expr1, "lbu", "t,o(b)", AT,
7196 (int) BFD_RELOC_LO16, AT);
7197 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sll", "d,w,<",
7199 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or", "d,v,t",
7204 if (offset_expr.X_add_number >= 0x7fff)
7205 as_bad (_("operand overflow"));
7206 if (target_big_endian)
7207 ++offset_expr.X_add_number;
7208 macro_build ((char *) NULL, &icnt, &offset_expr, "sb", "t,o(b)", treg,
7209 (int) BFD_RELOC_LO16, breg);
7210 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srl", "d,w,<",
7212 if (target_big_endian)
7213 --offset_expr.X_add_number;
7215 ++offset_expr.X_add_number;
7216 macro_build ((char *) NULL, &icnt, &offset_expr, "sb", "t,o(b)", AT,
7217 (int) BFD_RELOC_LO16, breg);
7230 if (offset_expr.X_add_number >= 0x8000 - off)
7231 as_bad (_("operand overflow"));
7232 if (! target_big_endian)
7233 offset_expr.X_add_number += off;
7234 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg,
7235 (int) BFD_RELOC_LO16, breg);
7236 if (! target_big_endian)
7237 offset_expr.X_add_number -= off;
7239 offset_expr.X_add_number += off;
7240 macro_build ((char *) NULL, &icnt, &offset_expr, s2, "t,o(b)", treg,
7241 (int) BFD_RELOC_LO16, breg);
7255 load_address (&icnt, AT, &offset_expr, &used_at);
7257 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7258 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
7259 "d,v,t", AT, AT, breg);
7260 if (! target_big_endian)
7261 expr1.X_add_number = off;
7263 expr1.X_add_number = 0;
7264 macro_build ((char *) NULL, &icnt, &expr1, s, "t,o(b)", treg,
7265 (int) BFD_RELOC_LO16, AT);
7266 if (! target_big_endian)
7267 expr1.X_add_number = 0;
7269 expr1.X_add_number = off;
7270 macro_build ((char *) NULL, &icnt, &expr1, s2, "t,o(b)", treg,
7271 (int) BFD_RELOC_LO16, AT);
7276 load_address (&icnt, AT, &offset_expr, &used_at);
7278 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7279 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
7280 "d,v,t", AT, AT, breg);
7281 if (! target_big_endian)
7282 expr1.X_add_number = 0;
7283 macro_build ((char *) NULL, &icnt, &expr1, "sb", "t,o(b)", treg,
7284 (int) BFD_RELOC_LO16, AT);
7285 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srl", "d,w,<",
7287 if (! target_big_endian)
7288 expr1.X_add_number = 1;
7290 expr1.X_add_number = 0;
7291 macro_build ((char *) NULL, &icnt, &expr1, "sb", "t,o(b)", treg,
7292 (int) BFD_RELOC_LO16, AT);
7293 if (! target_big_endian)
7294 expr1.X_add_number = 0;
7296 expr1.X_add_number = 1;
7297 macro_build ((char *) NULL, &icnt, &expr1, "lbu", "t,o(b)", AT,
7298 (int) BFD_RELOC_LO16, AT);
7299 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sll", "d,w,<",
7301 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or", "d,v,t",
7306 /* FIXME: Check if this is one of the itbl macros, since they
7307 are added dynamically. */
7308 as_bad (_("Macro %s not implemented yet"), ip->insn_mo->name);
7312 as_warn (_("Macro used $at after \".set noat\""));
7315 /* Implement macros in mips16 mode. */
7319 struct mips_cl_insn *ip;
7322 int xreg, yreg, zreg, tmp;
7326 const char *s, *s2, *s3;
7328 mask = ip->insn_mo->mask;
7330 xreg = (ip->insn_opcode >> MIPS16OP_SH_RX) & MIPS16OP_MASK_RX;
7331 yreg = (ip->insn_opcode >> MIPS16OP_SH_RY) & MIPS16OP_MASK_RY;
7332 zreg = (ip->insn_opcode >> MIPS16OP_SH_RZ) & MIPS16OP_MASK_RZ;
7336 expr1.X_op = O_constant;
7337 expr1.X_op_symbol = NULL;
7338 expr1.X_add_symbol = NULL;
7339 expr1.X_add_number = 1;
7358 mips_emit_delays (true);
7359 ++mips_opts.noreorder;
7360 mips_any_noreorder = 1;
7361 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7362 dbl ? "ddiv" : "div",
7363 "0,x,y", xreg, yreg);
7364 expr1.X_add_number = 2;
7365 macro_build ((char *) NULL, &icnt, &expr1, "bnez", "x,p", yreg);
7366 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break", "6",
7369 /* FIXME: The normal code checks for of -1 / -0x80000000 here,
7370 since that causes an overflow. We should do that as well,
7371 but I don't see how to do the comparisons without a temporary
7373 --mips_opts.noreorder;
7374 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "x", zreg);
7393 mips_emit_delays (true);
7394 ++mips_opts.noreorder;
7395 mips_any_noreorder = 1;
7396 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "0,x,y",
7398 expr1.X_add_number = 2;
7399 macro_build ((char *) NULL, &icnt, &expr1, "bnez", "x,p", yreg);
7400 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
7402 --mips_opts.noreorder;
7403 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s2, "x", zreg);
7409 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7410 dbl ? "dmultu" : "multu", "x,y", xreg, yreg);
7411 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "x",
7420 if (imm_expr.X_op != O_constant)
7421 as_bad (_("Unsupported large constant"));
7422 imm_expr.X_add_number = -imm_expr.X_add_number;
7423 macro_build ((char *) NULL, &icnt, &imm_expr,
7424 dbl ? "daddiu" : "addiu", "y,x,4", yreg, xreg);
7428 if (imm_expr.X_op != O_constant)
7429 as_bad (_("Unsupported large constant"));
7430 imm_expr.X_add_number = -imm_expr.X_add_number;
7431 macro_build ((char *) NULL, &icnt, &imm_expr, "addiu",
7436 if (imm_expr.X_op != O_constant)
7437 as_bad (_("Unsupported large constant"));
7438 imm_expr.X_add_number = -imm_expr.X_add_number;
7439 macro_build ((char *) NULL, &icnt, &imm_expr, "daddiu",
7462 goto do_reverse_branch;
7466 goto do_reverse_branch;
7478 goto do_reverse_branch;
7489 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "x,y",
7491 macro_build ((char *) NULL, &icnt, &offset_expr, s2, "p");
7518 goto do_addone_branch_i;
7523 goto do_addone_branch_i;
7538 goto do_addone_branch_i;
7545 if (imm_expr.X_op != O_constant)
7546 as_bad (_("Unsupported large constant"));
7547 ++imm_expr.X_add_number;
7550 macro_build ((char *) NULL, &icnt, &imm_expr, s, s3, xreg);
7551 macro_build ((char *) NULL, &icnt, &offset_expr, s2, "p");
7555 expr1.X_add_number = 0;
7556 macro_build ((char *) NULL, &icnt, &expr1, "slti", "x,8", yreg);
7558 move_register (&icnt, xreg, yreg);
7559 expr1.X_add_number = 2;
7560 macro_build ((char *) NULL, &icnt, &expr1, "bteqz", "p");
7561 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7562 "neg", "x,w", xreg, xreg);
7566 /* For consistency checking, verify that all bits are specified either
7567 by the match/mask part of the instruction definition, or by the
7570 validate_mips_insn (opc)
7571 const struct mips_opcode *opc;
7573 const char *p = opc->args;
7575 unsigned long used_bits = opc->mask;
7577 if ((used_bits & opc->match) != opc->match)
7579 as_bad (_("internal: bad mips opcode (mask error): %s %s"),
7580 opc->name, opc->args);
7583 #define USE_BITS(mask,shift) (used_bits |= ((mask) << (shift)))
7590 case '<': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
7591 case '>': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
7593 case 'B': USE_BITS (OP_MASK_CODE20, OP_SH_CODE20); break;
7594 case 'C': USE_BITS (OP_MASK_COPZ, OP_SH_COPZ); break;
7595 case 'D': USE_BITS (OP_MASK_FD, OP_SH_FD); break;
7596 case 'E': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
7598 case 'G': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
7599 case 'H': USE_BITS (OP_MASK_SEL, OP_SH_SEL); break;
7601 case 'J': USE_BITS (OP_MASK_CODE19, OP_SH_CODE19); break;
7603 case 'M': USE_BITS (OP_MASK_CCC, OP_SH_CCC); break;
7604 case 'N': USE_BITS (OP_MASK_BCC, OP_SH_BCC); break;
7605 case 'O': USE_BITS (OP_MASK_ALN, OP_SH_ALN); break;
7606 case 'Q': USE_BITS (OP_MASK_VSEL, OP_SH_VSEL);
7607 USE_BITS (OP_MASK_FT, OP_SH_FT); break;
7608 case 'R': USE_BITS (OP_MASK_FR, OP_SH_FR); break;
7609 case 'S': USE_BITS (OP_MASK_FS, OP_SH_FS); break;
7610 case 'T': USE_BITS (OP_MASK_FT, OP_SH_FT); break;
7611 case 'V': USE_BITS (OP_MASK_FS, OP_SH_FS); break;
7612 case 'W': USE_BITS (OP_MASK_FT, OP_SH_FT); break;
7613 case 'X': USE_BITS (OP_MASK_FD, OP_SH_FD); break;
7614 case 'Y': USE_BITS (OP_MASK_FS, OP_SH_FS); break;
7615 case 'Z': USE_BITS (OP_MASK_FT, OP_SH_FT); break;
7616 case 'a': USE_BITS (OP_MASK_TARGET, OP_SH_TARGET); break;
7617 case 'b': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
7618 case 'c': USE_BITS (OP_MASK_CODE, OP_SH_CODE); break;
7619 case 'd': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
7621 case 'h': USE_BITS (OP_MASK_PREFX, OP_SH_PREFX); break;
7622 case 'i': USE_BITS (OP_MASK_IMMEDIATE, OP_SH_IMMEDIATE); break;
7623 case 'j': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
7624 case 'k': USE_BITS (OP_MASK_CACHE, OP_SH_CACHE); break;
7626 case 'o': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
7627 case 'p': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
7628 case 'q': USE_BITS (OP_MASK_CODE2, OP_SH_CODE2); break;
7629 case 'r': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
7630 case 's': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
7631 case 't': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
7632 case 'u': USE_BITS (OP_MASK_IMMEDIATE, OP_SH_IMMEDIATE); break;
7633 case 'v': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
7634 case 'w': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
7637 case 'P': USE_BITS (OP_MASK_PERFREG, OP_SH_PERFREG); break;
7638 case 'U': USE_BITS (OP_MASK_RD, OP_SH_RD);
7639 USE_BITS (OP_MASK_RT, OP_SH_RT); break;
7641 as_bad (_("internal: bad mips opcode (unknown operand type `%c'): %s %s"),
7642 c, opc->name, opc->args);
7646 if (used_bits != 0xffffffff)
7648 as_bad (_("internal: bad mips opcode (bits 0x%lx undefined): %s %s"),
7649 ~used_bits & 0xffffffff, opc->name, opc->args);
7655 /* This routine assembles an instruction into its binary format. As a
7656 side effect, it sets one of the global variables imm_reloc or
7657 offset_reloc to the type of relocation to do if one of the operands
7658 is an address expression. */
7663 struct mips_cl_insn *ip;
7668 struct mips_opcode *insn;
7671 unsigned int lastregno = 0;
7677 /* If the instruction contains a '.', we first try to match an instruction
7678 including the '.'. Then we try again without the '.'. */
7680 for (s = str; *s != '\0' && !ISSPACE (*s); ++s)
7683 /* If we stopped on whitespace, then replace the whitespace with null for
7684 the call to hash_find. Save the character we replaced just in case we
7685 have to re-parse the instruction. */
7692 insn = (struct mips_opcode *) hash_find (op_hash, str);
7694 /* If we didn't find the instruction in the opcode table, try again, but
7695 this time with just the instruction up to, but not including the
7699 /* Restore the character we overwrite above (if any). */
7703 /* Scan up to the first '.' or whitespace. */
7705 *s != '\0' && *s != '.' && !ISSPACE (*s);
7709 /* If we did not find a '.', then we can quit now. */
7712 insn_error = "unrecognized opcode";
7716 /* Lookup the instruction in the hash table. */
7718 if ((insn = (struct mips_opcode *) hash_find (op_hash, str)) == NULL)
7720 insn_error = "unrecognized opcode";
7730 assert (strcmp (insn->name, str) == 0);
7732 if (OPCODE_IS_MEMBER (insn,
7734 | (mips_opts.ase_mdmx ? INSN_MDMX : 0)
7735 | (mips_opts.ase_mips3d ? INSN_MIPS3D : 0)),
7741 if (insn->pinfo != INSN_MACRO)
7743 if (mips_arch == CPU_R4650 && (insn->pinfo & FP_D) != 0)
7749 if (insn + 1 < &mips_opcodes[NUMOPCODES]
7750 && strcmp (insn->name, insn[1].name) == 0)
7759 static char buf[100];
7761 _("opcode not supported on this processor: %s (%s)"),
7762 mips_cpu_to_str (mips_arch),
7763 mips_isa_to_str (mips_opts.isa));
7774 ip->insn_opcode = insn->match;
7776 for (args = insn->args;; ++args)
7780 s += strspn (s, " \t");
7784 case '\0': /* end of args */
7797 ip->insn_opcode |= lastregno << OP_SH_RS;
7801 ip->insn_opcode |= lastregno << OP_SH_RT;
7805 ip->insn_opcode |= lastregno << OP_SH_FT;
7809 ip->insn_opcode |= lastregno << OP_SH_FS;
7815 /* Handle optional base register.
7816 Either the base register is omitted or
7817 we must have a left paren. */
7818 /* This is dependent on the next operand specifier
7819 is a base register specification. */
7820 assert (args[1] == 'b' || args[1] == '5'
7821 || args[1] == '-' || args[1] == '4');
7825 case ')': /* these must match exactly */
7830 case '<': /* must be at least one digit */
7832 * According to the manual, if the shift amount is greater
7833 * than 31 or less than 0, then the shift amount should be
7834 * mod 32. In reality the mips assembler issues an error.
7835 * We issue a warning and mask out all but the low 5 bits.
7837 my_getExpression (&imm_expr, s);
7838 check_absolute_expr (ip, &imm_expr);
7839 if ((unsigned long) imm_expr.X_add_number > 31)
7841 as_warn (_("Improper shift amount (%lu)"),
7842 (unsigned long) imm_expr.X_add_number);
7843 imm_expr.X_add_number &= OP_MASK_SHAMT;
7845 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_SHAMT;
7846 imm_expr.X_op = O_absent;
7850 case '>': /* shift amount minus 32 */
7851 my_getExpression (&imm_expr, s);
7852 check_absolute_expr (ip, &imm_expr);
7853 if ((unsigned long) imm_expr.X_add_number < 32
7854 || (unsigned long) imm_expr.X_add_number > 63)
7856 ip->insn_opcode |= (imm_expr.X_add_number - 32) << OP_SH_SHAMT;
7857 imm_expr.X_op = O_absent;
7861 case 'k': /* cache code */
7862 case 'h': /* prefx code */
7863 my_getExpression (&imm_expr, s);
7864 check_absolute_expr (ip, &imm_expr);
7865 if ((unsigned long) imm_expr.X_add_number > 31)
7867 as_warn (_("Invalid value for `%s' (%lu)"),
7869 (unsigned long) imm_expr.X_add_number);
7870 imm_expr.X_add_number &= 0x1f;
7873 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CACHE;
7875 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_PREFX;
7876 imm_expr.X_op = O_absent;
7880 case 'c': /* break code */
7881 my_getExpression (&imm_expr, s);
7882 check_absolute_expr (ip, &imm_expr);
7883 if ((unsigned long) imm_expr.X_add_number > 1023)
7885 as_warn (_("Illegal break code (%lu)"),
7886 (unsigned long) imm_expr.X_add_number);
7887 imm_expr.X_add_number &= OP_MASK_CODE;
7889 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE;
7890 imm_expr.X_op = O_absent;
7894 case 'q': /* lower break code */
7895 my_getExpression (&imm_expr, s);
7896 check_absolute_expr (ip, &imm_expr);
7897 if ((unsigned long) imm_expr.X_add_number > 1023)
7899 as_warn (_("Illegal lower break code (%lu)"),
7900 (unsigned long) imm_expr.X_add_number);
7901 imm_expr.X_add_number &= OP_MASK_CODE2;
7903 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE2;
7904 imm_expr.X_op = O_absent;
7908 case 'B': /* 20-bit syscall/break code. */
7909 my_getExpression (&imm_expr, s);
7910 check_absolute_expr (ip, &imm_expr);
7911 if ((unsigned long) imm_expr.X_add_number > OP_MASK_CODE20)
7912 as_warn (_("Illegal 20-bit code (%lu)"),
7913 (unsigned long) imm_expr.X_add_number);
7914 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE20;
7915 imm_expr.X_op = O_absent;
7919 case 'C': /* Coprocessor code */
7920 my_getExpression (&imm_expr, s);
7921 check_absolute_expr (ip, &imm_expr);
7922 if ((unsigned long) imm_expr.X_add_number >= (1 << 25))
7924 as_warn (_("Coproccesor code > 25 bits (%lu)"),
7925 (unsigned long) imm_expr.X_add_number);
7926 imm_expr.X_add_number &= ((1 << 25) - 1);
7928 ip->insn_opcode |= imm_expr.X_add_number;
7929 imm_expr.X_op = O_absent;
7933 case 'J': /* 19-bit wait code. */
7934 my_getExpression (&imm_expr, s);
7935 check_absolute_expr (ip, &imm_expr);
7936 if ((unsigned long) imm_expr.X_add_number > OP_MASK_CODE19)
7937 as_warn (_("Illegal 19-bit code (%lu)"),
7938 (unsigned long) imm_expr.X_add_number);
7939 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE19;
7940 imm_expr.X_op = O_absent;
7944 case 'P': /* Performance register */
7945 my_getExpression (&imm_expr, s);
7946 check_absolute_expr (ip, &imm_expr);
7947 if (imm_expr.X_add_number != 0 && imm_expr.X_add_number != 1)
7949 as_warn (_("Invalid performance register (%lu)"),
7950 (unsigned long) imm_expr.X_add_number);
7951 imm_expr.X_add_number &= OP_MASK_PERFREG;
7953 ip->insn_opcode |= (imm_expr.X_add_number << OP_SH_PERFREG);
7954 imm_expr.X_op = O_absent;
7958 case 'b': /* base register */
7959 case 'd': /* destination register */
7960 case 's': /* source register */
7961 case 't': /* target register */
7962 case 'r': /* both target and source */
7963 case 'v': /* both dest and source */
7964 case 'w': /* both dest and target */
7965 case 'E': /* coprocessor target register */
7966 case 'G': /* coprocessor destination register */
7967 case 'x': /* ignore register name */
7968 case 'z': /* must be zero register */
7969 case 'U': /* destination register (clo/clz). */
7984 while (ISDIGIT (*s));
7986 as_bad (_("Invalid register number (%d)"), regno);
7988 else if (*args == 'E' || *args == 'G')
7992 if (s[1] == 'r' && s[2] == 'a')
7997 else if (s[1] == 'f' && s[2] == 'p')
8002 else if (s[1] == 's' && s[2] == 'p')
8007 else if (s[1] == 'g' && s[2] == 'p')
8012 else if (s[1] == 'a' && s[2] == 't')
8017 else if (s[1] == 'k' && s[2] == 't' && s[3] == '0')
8022 else if (s[1] == 'k' && s[2] == 't' && s[3] == '1')
8027 else if (s[1] == 'z' && s[2] == 'e' && s[3] == 'r' && s[4] == 'o')
8032 else if (itbl_have_entries)
8037 p = s + 1; /* advance past '$' */
8038 n = itbl_get_field (&p); /* n is name */
8040 /* See if this is a register defined in an
8042 if (itbl_get_reg_val (n, &r))
8044 /* Get_field advances to the start of
8045 the next field, so we need to back
8046 rack to the end of the last field. */
8050 s = strchr (s, '\0');
8063 as_warn (_("Used $at without \".set noat\""));
8069 if (c == 'r' || c == 'v' || c == 'w')
8076 /* 'z' only matches $0. */
8077 if (c == 'z' && regno != 0)
8080 /* Now that we have assembled one operand, we use the args string
8081 * to figure out where it goes in the instruction. */
8088 ip->insn_opcode |= regno << OP_SH_RS;
8092 ip->insn_opcode |= regno << OP_SH_RD;
8095 ip->insn_opcode |= regno << OP_SH_RD;
8096 ip->insn_opcode |= regno << OP_SH_RT;
8101 ip->insn_opcode |= regno << OP_SH_RT;
8104 /* This case exists because on the r3000 trunc
8105 expands into a macro which requires a gp
8106 register. On the r6000 or r4000 it is
8107 assembled into a single instruction which
8108 ignores the register. Thus the insn version
8109 is MIPS_ISA2 and uses 'x', and the macro
8110 version is MIPS_ISA1 and uses 't'. */
8113 /* This case is for the div instruction, which
8114 acts differently if the destination argument
8115 is $0. This only matches $0, and is checked
8116 outside the switch. */
8119 /* Itbl operand; not yet implemented. FIXME ?? */
8121 /* What about all other operands like 'i', which
8122 can be specified in the opcode table? */
8132 ip->insn_opcode |= lastregno << OP_SH_RS;
8135 ip->insn_opcode |= lastregno << OP_SH_RT;
8140 case 'O': /* MDMX alignment immediate constant. */
8141 my_getExpression (&imm_expr, s);
8142 check_absolute_expr (ip, &imm_expr);
8143 if ((unsigned long) imm_expr.X_add_number > OP_MASK_ALN)
8145 as_warn ("Improper align amount (%ld), using low bits",
8146 (long) imm_expr.X_add_number);
8147 imm_expr.X_add_number &= OP_MASK_ALN;
8149 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_ALN;
8150 imm_expr.X_op = O_absent;
8154 case 'Q': /* MDMX vector, element sel, or const. */
8157 /* MDMX Immediate. */
8158 my_getExpression (&imm_expr, s);
8159 check_absolute_expr (ip, &imm_expr);
8160 if ((unsigned long) imm_expr.X_add_number > OP_MASK_FT)
8162 as_warn (_("Invalid MDMX Immediate (%ld)"),
8163 (long) imm_expr.X_add_number);
8164 imm_expr.X_add_number &= OP_MASK_FT;
8166 imm_expr.X_add_number &= OP_MASK_FT;
8167 if (ip->insn_opcode & (OP_MASK_VSEL << OP_SH_VSEL))
8168 ip->insn_opcode |= MDMX_FMTSEL_IMM_QH << OP_SH_VSEL;
8170 ip->insn_opcode |= MDMX_FMTSEL_IMM_OB << OP_SH_VSEL;
8171 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_FT;
8172 imm_expr.X_op = O_absent;
8176 /* Not MDMX Immediate. Fall through. */
8177 case 'X': /* MDMX destination register. */
8178 case 'Y': /* MDMX source register. */
8179 case 'Z': /* MDMX target register. */
8181 case 'D': /* floating point destination register */
8182 case 'S': /* floating point source register */
8183 case 'T': /* floating point target register */
8184 case 'R': /* floating point source register */
8188 /* Accept $fN for FP and MDMX register numbers, and in
8189 addition accept $vN for MDMX register numbers. */
8190 if ((s[0] == '$' && s[1] == 'f' && ISDIGIT (s[2]))
8191 || (is_mdmx != 0 && s[0] == '$' && s[1] == 'v'
8202 while (ISDIGIT (*s));
8205 as_bad (_("Invalid float register number (%d)"), regno);
8207 if ((regno & 1) != 0
8209 && ! (strcmp (str, "mtc1") == 0
8210 || strcmp (str, "mfc1") == 0
8211 || strcmp (str, "lwc1") == 0
8212 || strcmp (str, "swc1") == 0
8213 || strcmp (str, "l.s") == 0
8214 || strcmp (str, "s.s") == 0))
8215 as_warn (_("Float register should be even, was %d"),
8223 if (c == 'V' || c == 'W')
8234 ip->insn_opcode |= regno << OP_SH_FD;
8239 ip->insn_opcode |= regno << OP_SH_FS;
8242 /* This is like 'Z', but also needs to fix the MDMX
8243 vector/scalar select bits. Note that the
8244 scalar immediate case is handled above. */
8247 int is_qh = (ip->insn_opcode & (1 << OP_SH_VSEL));
8248 int max_el = (is_qh ? 3 : 7);
8250 my_getExpression(&imm_expr, s);
8251 check_absolute_expr (ip, &imm_expr);
8253 if (imm_expr.X_add_number > max_el)
8254 as_bad(_("Bad element selector %ld"),
8255 (long) imm_expr.X_add_number);
8256 imm_expr.X_add_number &= max_el;
8257 ip->insn_opcode |= (imm_expr.X_add_number
8261 as_warn(_("Expecting ']' found '%s'"), s);
8267 if (ip->insn_opcode & (OP_MASK_VSEL << OP_SH_VSEL))
8268 ip->insn_opcode |= (MDMX_FMTSEL_VEC_QH
8271 ip->insn_opcode |= (MDMX_FMTSEL_VEC_OB <<
8278 ip->insn_opcode |= regno << OP_SH_FT;
8281 ip->insn_opcode |= regno << OP_SH_FR;
8291 ip->insn_opcode |= lastregno << OP_SH_FS;
8294 ip->insn_opcode |= lastregno << OP_SH_FT;
8300 my_getExpression (&imm_expr, s);
8301 if (imm_expr.X_op != O_big
8302 && imm_expr.X_op != O_constant)
8303 insn_error = _("absolute expression required");
8308 my_getExpression (&offset_expr, s);
8309 *imm_reloc = BFD_RELOC_32;
8322 unsigned char temp[8];
8324 unsigned int length;
8329 /* These only appear as the last operand in an
8330 instruction, and every instruction that accepts
8331 them in any variant accepts them in all variants.
8332 This means we don't have to worry about backing out
8333 any changes if the instruction does not match.
8335 The difference between them is the size of the
8336 floating point constant and where it goes. For 'F'
8337 and 'L' the constant is 64 bits; for 'f' and 'l' it
8338 is 32 bits. Where the constant is placed is based
8339 on how the MIPS assembler does things:
8342 f -- immediate value
8345 The .lit4 and .lit8 sections are only used if
8346 permitted by the -G argument.
8348 When generating embedded PIC code, we use the
8349 .lit8 section but not the .lit4 section (we can do
8350 .lit4 inline easily; we need to put .lit8
8351 somewhere in the data segment, and using .lit8
8352 permits the linker to eventually combine identical
8355 The code below needs to know whether the target register
8356 is 32 or 64 bits wide. It relies on the fact 'f' and
8357 'F' are used with GPR-based instructions and 'l' and
8358 'L' are used with FPR-based instructions. */
8360 f64 = *args == 'F' || *args == 'L';
8361 using_gprs = *args == 'F' || *args == 'f';
8363 save_in = input_line_pointer;
8364 input_line_pointer = s;
8365 err = md_atof (f64 ? 'd' : 'f', (char *) temp, &len);
8367 s = input_line_pointer;
8368 input_line_pointer = save_in;
8369 if (err != NULL && *err != '\0')
8371 as_bad (_("Bad floating point constant: %s"), err);
8372 memset (temp, '\0', sizeof temp);
8373 length = f64 ? 8 : 4;
8376 assert (length == (unsigned) (f64 ? 8 : 4));
8380 && (! USE_GLOBAL_POINTER_OPT
8381 || mips_pic == EMBEDDED_PIC
8382 || g_switch_value < 4
8383 || (temp[0] == 0 && temp[1] == 0)
8384 || (temp[2] == 0 && temp[3] == 0))))
8386 imm_expr.X_op = O_constant;
8387 if (! target_big_endian)
8388 imm_expr.X_add_number = bfd_getl32 (temp);
8390 imm_expr.X_add_number = bfd_getb32 (temp);
8393 && ! mips_disable_float_construction
8394 /* Constants can only be constructed in GPRs and
8395 copied to FPRs if the GPRs are at least as wide
8396 as the FPRs. Force the constant into memory if
8397 we are using 64-bit FPRs but the GPRs are only
8400 || ! (HAVE_64BIT_FPRS && HAVE_32BIT_GPRS))
8401 && ((temp[0] == 0 && temp[1] == 0)
8402 || (temp[2] == 0 && temp[3] == 0))
8403 && ((temp[4] == 0 && temp[5] == 0)
8404 || (temp[6] == 0 && temp[7] == 0)))
8406 /* The value is simple enough to load with a couple of
8407 instructions. If using 32-bit registers, set
8408 imm_expr to the high order 32 bits and offset_expr to
8409 the low order 32 bits. Otherwise, set imm_expr to
8410 the entire 64 bit constant. */
8411 if (using_gprs ? HAVE_32BIT_GPRS : HAVE_32BIT_FPRS)
8413 imm_expr.X_op = O_constant;
8414 offset_expr.X_op = O_constant;
8415 if (! target_big_endian)
8417 imm_expr.X_add_number = bfd_getl32 (temp + 4);
8418 offset_expr.X_add_number = bfd_getl32 (temp);
8422 imm_expr.X_add_number = bfd_getb32 (temp);
8423 offset_expr.X_add_number = bfd_getb32 (temp + 4);
8425 if (offset_expr.X_add_number == 0)
8426 offset_expr.X_op = O_absent;
8428 else if (sizeof (imm_expr.X_add_number) > 4)
8430 imm_expr.X_op = O_constant;
8431 if (! target_big_endian)
8432 imm_expr.X_add_number = bfd_getl64 (temp);
8434 imm_expr.X_add_number = bfd_getb64 (temp);
8438 imm_expr.X_op = O_big;
8439 imm_expr.X_add_number = 4;
8440 if (! target_big_endian)
8442 generic_bignum[0] = bfd_getl16 (temp);
8443 generic_bignum[1] = bfd_getl16 (temp + 2);
8444 generic_bignum[2] = bfd_getl16 (temp + 4);
8445 generic_bignum[3] = bfd_getl16 (temp + 6);
8449 generic_bignum[0] = bfd_getb16 (temp + 6);
8450 generic_bignum[1] = bfd_getb16 (temp + 4);
8451 generic_bignum[2] = bfd_getb16 (temp + 2);
8452 generic_bignum[3] = bfd_getb16 (temp);
8458 const char *newname;
8461 /* Switch to the right section. */
8463 subseg = now_subseg;
8466 default: /* unused default case avoids warnings. */
8468 newname = RDATA_SECTION_NAME;
8469 if ((USE_GLOBAL_POINTER_OPT && g_switch_value >= 8)
8470 || mips_pic == EMBEDDED_PIC)
8474 if (mips_pic == EMBEDDED_PIC)
8477 newname = RDATA_SECTION_NAME;
8480 assert (!USE_GLOBAL_POINTER_OPT
8481 || g_switch_value >= 4);
8485 new_seg = subseg_new (newname, (subsegT) 0);
8486 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
8487 bfd_set_section_flags (stdoutput, new_seg,
8492 frag_align (*args == 'l' ? 2 : 3, 0, 0);
8493 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
8494 && strcmp (TARGET_OS, "elf") != 0)
8495 record_alignment (new_seg, 4);
8497 record_alignment (new_seg, *args == 'l' ? 2 : 3);
8499 as_bad (_("Can't use floating point insn in this section"));
8501 /* Set the argument to the current address in the
8503 offset_expr.X_op = O_symbol;
8504 offset_expr.X_add_symbol =
8505 symbol_new ("L0\001", now_seg,
8506 (valueT) frag_now_fix (), frag_now);
8507 offset_expr.X_add_number = 0;
8509 /* Put the floating point number into the section. */
8510 p = frag_more ((int) length);
8511 memcpy (p, temp, length);
8513 /* Switch back to the original section. */
8514 subseg_set (seg, subseg);
8519 case 'i': /* 16 bit unsigned immediate */
8520 case 'j': /* 16 bit signed immediate */
8521 *imm_reloc = BFD_RELOC_LO16;
8522 c = my_getSmallExpression (&imm_expr, s);
8527 if (imm_expr.X_op == O_constant)
8528 imm_expr.X_add_number =
8529 (imm_expr.X_add_number >> 16) & 0xffff;
8531 else if (c == S_EX_HIGHEST)
8532 *imm_reloc = BFD_RELOC_MIPS_HIGHEST;
8533 else if (c == S_EX_HIGHER)
8534 *imm_reloc = BFD_RELOC_MIPS_HIGHER;
8535 else if (c == S_EX_GP_REL)
8537 /* This occurs in NewABI only. */
8538 c = my_getSmallExpression (&imm_expr, s);
8540 as_bad (_("bad composition of relocations"));
8543 c = my_getSmallExpression (&imm_expr, s);
8545 as_bad (_("bad composition of relocations"));
8548 imm_reloc[0] = BFD_RELOC_GPREL16;
8549 imm_reloc[1] = BFD_RELOC_MIPS_SUB;
8550 imm_reloc[2] = BFD_RELOC_LO16;
8555 else if (c == S_EX_HI)
8557 *imm_reloc = BFD_RELOC_HI16_S;
8558 imm_unmatched_hi = true;
8561 *imm_reloc = BFD_RELOC_HI16;
8563 else if (imm_expr.X_op == O_constant)
8564 imm_expr.X_add_number &= 0xffff;
8568 if ((c == S_EX_NONE && imm_expr.X_op != O_constant)
8569 || ((imm_expr.X_add_number < 0
8570 || imm_expr.X_add_number >= 0x10000)
8571 && imm_expr.X_op == O_constant))
8573 if (insn + 1 < &mips_opcodes[NUMOPCODES] &&
8574 !strcmp (insn->name, insn[1].name))
8576 if (imm_expr.X_op == O_constant
8577 || imm_expr.X_op == O_big)
8578 as_bad (_("16 bit expression not in range 0..65535"));
8586 /* The upper bound should be 0x8000, but
8587 unfortunately the MIPS assembler accepts numbers
8588 from 0x8000 to 0xffff and sign extends them, and
8589 we want to be compatible. We only permit this
8590 extended range for an instruction which does not
8591 provide any further alternates, since those
8592 alternates may handle other cases. People should
8593 use the numbers they mean, rather than relying on
8594 a mysterious sign extension. */
8595 more = (insn + 1 < &mips_opcodes[NUMOPCODES] &&
8596 strcmp (insn->name, insn[1].name) == 0);
8601 if ((c == S_EX_NONE && imm_expr.X_op != O_constant)
8602 || ((imm_expr.X_add_number < -0x8000
8603 || imm_expr.X_add_number >= max)
8604 && imm_expr.X_op == O_constant)
8606 && imm_expr.X_add_number < 0
8608 && imm_expr.X_unsigned
8609 && sizeof (imm_expr.X_add_number) <= 4))
8613 if (imm_expr.X_op == O_constant
8614 || imm_expr.X_op == O_big)
8615 as_bad (_("16 bit expression not in range -32768..32767"));
8621 case 'o': /* 16 bit offset */
8622 c = my_getSmallExpression (&offset_expr, s);
8624 /* If this value won't fit into a 16 bit offset, then go
8625 find a macro that will generate the 32 bit offset
8628 && (offset_expr.X_op != O_constant
8629 || offset_expr.X_add_number >= 0x8000
8630 || offset_expr.X_add_number < -0x8000))
8635 if (offset_expr.X_op != O_constant)
8637 offset_expr.X_add_number =
8638 (offset_expr.X_add_number >> 16) & 0xffff;
8640 *offset_reloc = BFD_RELOC_LO16;
8644 case 'p': /* pc relative offset */
8645 if (mips_pic == EMBEDDED_PIC)
8646 *offset_reloc = BFD_RELOC_16_PCREL_S2;
8648 *offset_reloc = BFD_RELOC_16_PCREL;
8649 my_getExpression (&offset_expr, s);
8653 case 'u': /* upper 16 bits */
8654 c = my_getSmallExpression (&imm_expr, s);
8655 *imm_reloc = BFD_RELOC_LO16;
8660 if (imm_expr.X_op == O_constant)
8661 imm_expr.X_add_number =
8662 (imm_expr.X_add_number >> 16) & 0xffff;
8663 else if (c == S_EX_HI)
8665 *imm_reloc = BFD_RELOC_HI16_S;
8666 imm_unmatched_hi = true;
8669 else if (c == S_EX_HIGHEST)
8670 *imm_reloc = BFD_RELOC_MIPS_HIGHEST;
8671 else if (c == S_EX_GP_REL)
8673 /* This occurs in NewABI only. */
8674 c = my_getSmallExpression (&imm_expr, s);
8676 as_bad (_("bad composition of relocations"));
8679 c = my_getSmallExpression (&imm_expr, s);
8681 as_bad (_("bad composition of relocations"));
8684 imm_reloc[0] = BFD_RELOC_GPREL16;
8685 imm_reloc[1] = BFD_RELOC_MIPS_SUB;
8686 imm_reloc[2] = BFD_RELOC_HI16_S;
8692 *imm_reloc = BFD_RELOC_HI16;
8694 else if (imm_expr.X_op == O_constant)
8695 imm_expr.X_add_number &= 0xffff;
8697 if (imm_expr.X_op == O_constant
8698 && (imm_expr.X_add_number < 0
8699 || imm_expr.X_add_number >= 0x10000))
8700 as_bad (_("lui expression not in range 0..65535"));
8704 case 'a': /* 26 bit address */
8705 my_getExpression (&offset_expr, s);
8707 *offset_reloc = BFD_RELOC_MIPS_JMP;
8710 case 'N': /* 3 bit branch condition code */
8711 case 'M': /* 3 bit compare condition code */
8712 if (strncmp (s, "$fcc", 4) != 0)
8722 while (ISDIGIT (*s));
8724 as_bad (_("invalid condition code register $fcc%d"), regno);
8726 ip->insn_opcode |= regno << OP_SH_BCC;
8728 ip->insn_opcode |= regno << OP_SH_CCC;
8732 if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X'))
8743 while (ISDIGIT (*s));
8746 c = 8; /* Invalid sel value. */
8749 as_bad (_("invalid coprocessor sub-selection value (0-7)"));
8750 ip->insn_opcode |= c;
8754 as_bad (_("bad char = '%c'\n"), *args);
8759 /* Args don't match. */
8760 if (insn + 1 < &mips_opcodes[NUMOPCODES] &&
8761 !strcmp (insn->name, insn[1].name))
8765 insn_error = _("illegal operands");
8770 insn_error = _("illegal operands");
8775 /* This routine assembles an instruction into its binary format when
8776 assembling for the mips16. As a side effect, it sets one of the
8777 global variables imm_reloc or offset_reloc to the type of
8778 relocation to do if one of the operands is an address expression.
8779 It also sets mips16_small and mips16_ext if the user explicitly
8780 requested a small or extended instruction. */
8785 struct mips_cl_insn *ip;
8789 struct mips_opcode *insn;
8792 unsigned int lastregno = 0;
8797 mips16_small = false;
8800 for (s = str; ISLOWER (*s); ++s)
8812 if (s[1] == 't' && s[2] == ' ')
8815 mips16_small = true;
8819 else if (s[1] == 'e' && s[2] == ' ')
8828 insn_error = _("unknown opcode");
8832 if (mips_opts.noautoextend && ! mips16_ext)
8833 mips16_small = true;
8835 if ((insn = (struct mips_opcode *) hash_find (mips16_op_hash, str)) == NULL)
8837 insn_error = _("unrecognized opcode");
8844 assert (strcmp (insn->name, str) == 0);
8847 ip->insn_opcode = insn->match;
8848 ip->use_extend = false;
8849 imm_expr.X_op = O_absent;
8850 imm_reloc[0] = BFD_RELOC_UNUSED;
8851 imm_reloc[1] = BFD_RELOC_UNUSED;
8852 imm_reloc[2] = BFD_RELOC_UNUSED;
8853 offset_expr.X_op = O_absent;
8854 offset_reloc[0] = BFD_RELOC_UNUSED;
8855 offset_reloc[1] = BFD_RELOC_UNUSED;
8856 offset_reloc[2] = BFD_RELOC_UNUSED;
8857 for (args = insn->args; 1; ++args)
8864 /* In this switch statement we call break if we did not find
8865 a match, continue if we did find a match, or return if we
8874 /* Stuff the immediate value in now, if we can. */
8875 if (imm_expr.X_op == O_constant
8876 && *imm_reloc > BFD_RELOC_UNUSED
8877 && insn->pinfo != INSN_MACRO)
8879 mips16_immed (NULL, 0, *imm_reloc - BFD_RELOC_UNUSED,
8880 imm_expr.X_add_number, true, mips16_small,
8881 mips16_ext, &ip->insn_opcode,
8882 &ip->use_extend, &ip->extend);
8883 imm_expr.X_op = O_absent;
8884 *imm_reloc = BFD_RELOC_UNUSED;
8898 ip->insn_opcode |= lastregno << MIPS16OP_SH_RX;
8901 ip->insn_opcode |= lastregno << MIPS16OP_SH_RY;
8917 ip->insn_opcode |= lastregno << MIPS16OP_SH_RX;
8919 ip->insn_opcode |= lastregno << MIPS16OP_SH_RY;
8946 while (ISDIGIT (*s));
8949 as_bad (_("invalid register number (%d)"), regno);
8955 if (s[1] == 'r' && s[2] == 'a')
8960 else if (s[1] == 'f' && s[2] == 'p')
8965 else if (s[1] == 's' && s[2] == 'p')
8970 else if (s[1] == 'g' && s[2] == 'p')
8975 else if (s[1] == 'a' && s[2] == 't')
8980 else if (s[1] == 'k' && s[2] == 't' && s[3] == '0')
8985 else if (s[1] == 'k' && s[2] == 't' && s[3] == '1')
8990 else if (s[1] == 'z' && s[2] == 'e' && s[3] == 'r' && s[4] == 'o')
9003 if (c == 'v' || c == 'w')
9005 regno = mips16_to_32_reg_map[lastregno];
9019 regno = mips32_to_16_reg_map[regno];
9024 regno = ILLEGAL_REG;
9029 regno = ILLEGAL_REG;
9034 regno = ILLEGAL_REG;
9039 if (regno == AT && ! mips_opts.noat)
9040 as_warn (_("used $at without \".set noat\""));
9047 if (regno == ILLEGAL_REG)
9054 ip->insn_opcode |= regno << MIPS16OP_SH_RX;
9058 ip->insn_opcode |= regno << MIPS16OP_SH_RY;
9061 ip->insn_opcode |= regno << MIPS16OP_SH_RZ;
9064 ip->insn_opcode |= regno << MIPS16OP_SH_MOVE32Z;
9070 ip->insn_opcode |= regno << MIPS16OP_SH_REGR32;
9073 regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3);
9074 ip->insn_opcode |= regno << MIPS16OP_SH_REG32R;
9084 if (strncmp (s, "$pc", 3) == 0)
9108 && strncmp (s + 1, "gprel(", sizeof "gprel(" - 1) == 0)
9110 /* This is %gprel(SYMBOL). We need to read SYMBOL,
9111 and generate the appropriate reloc. If the text
9112 inside %gprel is not a symbol name with an
9113 optional offset, then we generate a normal reloc
9114 and will probably fail later. */
9115 my_getExpression (&imm_expr, s + sizeof "%gprel" - 1);
9116 if (imm_expr.X_op == O_symbol)
9119 *imm_reloc = BFD_RELOC_MIPS16_GPREL;
9121 ip->use_extend = true;
9128 /* Just pick up a normal expression. */
9129 my_getExpression (&imm_expr, s);
9132 if (imm_expr.X_op == O_register)
9134 /* What we thought was an expression turned out to
9137 if (s[0] == '(' && args[1] == '(')
9139 /* It looks like the expression was omitted
9140 before a register indirection, which means
9141 that the expression is implicitly zero. We
9142 still set up imm_expr, so that we handle
9143 explicit extensions correctly. */
9144 imm_expr.X_op = O_constant;
9145 imm_expr.X_add_number = 0;
9146 *imm_reloc = (int) BFD_RELOC_UNUSED + c;
9153 /* We need to relax this instruction. */
9154 *imm_reloc = (int) BFD_RELOC_UNUSED + c;
9163 /* We use offset_reloc rather than imm_reloc for the PC
9164 relative operands. This lets macros with both
9165 immediate and address operands work correctly. */
9166 my_getExpression (&offset_expr, s);
9168 if (offset_expr.X_op == O_register)
9171 /* We need to relax this instruction. */
9172 *offset_reloc = (int) BFD_RELOC_UNUSED + c;
9176 case '6': /* break code */
9177 my_getExpression (&imm_expr, s);
9178 check_absolute_expr (ip, &imm_expr);
9179 if ((unsigned long) imm_expr.X_add_number > 63)
9181 as_warn (_("Invalid value for `%s' (%lu)"),
9183 (unsigned long) imm_expr.X_add_number);
9184 imm_expr.X_add_number &= 0x3f;
9186 ip->insn_opcode |= imm_expr.X_add_number << MIPS16OP_SH_IMM6;
9187 imm_expr.X_op = O_absent;
9191 case 'a': /* 26 bit address */
9192 my_getExpression (&offset_expr, s);
9194 *offset_reloc = BFD_RELOC_MIPS16_JMP;
9195 ip->insn_opcode <<= 16;
9198 case 'l': /* register list for entry macro */
9199 case 'L': /* register list for exit macro */
9209 int freg, reg1, reg2;
9211 while (*s == ' ' || *s == ',')
9215 as_bad (_("can't parse register list"));
9227 while (ISDIGIT (*s))
9249 as_bad (_("invalid register list"));
9254 while (ISDIGIT (*s))
9261 if (freg && reg1 == 0 && reg2 == 0 && c == 'L')
9266 else if (freg && reg1 == 0 && reg2 == 1 && c == 'L')
9271 else if (reg1 == 4 && reg2 >= 4 && reg2 <= 7 && c != 'L')
9272 mask |= (reg2 - 3) << 3;
9273 else if (reg1 == 16 && reg2 >= 16 && reg2 <= 17)
9274 mask |= (reg2 - 15) << 1;
9275 else if (reg1 == RA && reg2 == RA)
9279 as_bad (_("invalid register list"));
9283 /* The mask is filled in in the opcode table for the
9284 benefit of the disassembler. We remove it before
9285 applying the actual mask. */
9286 ip->insn_opcode &= ~ ((7 << 3) << MIPS16OP_SH_IMM6);
9287 ip->insn_opcode |= mask << MIPS16OP_SH_IMM6;
9291 case 'e': /* extend code */
9292 my_getExpression (&imm_expr, s);
9293 check_absolute_expr (ip, &imm_expr);
9294 if ((unsigned long) imm_expr.X_add_number > 0x7ff)
9296 as_warn (_("Invalid value for `%s' (%lu)"),
9298 (unsigned long) imm_expr.X_add_number);
9299 imm_expr.X_add_number &= 0x7ff;
9301 ip->insn_opcode |= imm_expr.X_add_number;
9302 imm_expr.X_op = O_absent;
9312 /* Args don't match. */
9313 if (insn + 1 < &mips16_opcodes[bfd_mips16_num_opcodes] &&
9314 strcmp (insn->name, insn[1].name) == 0)
9321 insn_error = _("illegal operands");
9327 /* This structure holds information we know about a mips16 immediate
9330 struct mips16_immed_operand
9332 /* The type code used in the argument string in the opcode table. */
9334 /* The number of bits in the short form of the opcode. */
9336 /* The number of bits in the extended form of the opcode. */
9338 /* The amount by which the short form is shifted when it is used;
9339 for example, the sw instruction has a shift count of 2. */
9341 /* The amount by which the short form is shifted when it is stored
9342 into the instruction code. */
9344 /* Non-zero if the short form is unsigned. */
9346 /* Non-zero if the extended form is unsigned. */
9348 /* Non-zero if the value is PC relative. */
9352 /* The mips16 immediate operand types. */
9354 static const struct mips16_immed_operand mips16_immed_operands[] =
9356 { '<', 3, 5, 0, MIPS16OP_SH_RZ, 1, 1, 0 },
9357 { '>', 3, 5, 0, MIPS16OP_SH_RX, 1, 1, 0 },
9358 { '[', 3, 6, 0, MIPS16OP_SH_RZ, 1, 1, 0 },
9359 { ']', 3, 6, 0, MIPS16OP_SH_RX, 1, 1, 0 },
9360 { '4', 4, 15, 0, MIPS16OP_SH_IMM4, 0, 0, 0 },
9361 { '5', 5, 16, 0, MIPS16OP_SH_IMM5, 1, 0, 0 },
9362 { 'H', 5, 16, 1, MIPS16OP_SH_IMM5, 1, 0, 0 },
9363 { 'W', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 0 },
9364 { 'D', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 0 },
9365 { 'j', 5, 16, 0, MIPS16OP_SH_IMM5, 0, 0, 0 },
9366 { '8', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 0, 0 },
9367 { 'V', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 0 },
9368 { 'C', 8, 16, 3, MIPS16OP_SH_IMM8, 1, 0, 0 },
9369 { 'U', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 1, 0 },
9370 { 'k', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 0 },
9371 { 'K', 8, 16, 3, MIPS16OP_SH_IMM8, 0, 0, 0 },
9372 { 'p', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 },
9373 { 'q', 11, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 },
9374 { 'A', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 1 },
9375 { 'B', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 1 },
9376 { 'E', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 1 }
9379 #define MIPS16_NUM_IMMED \
9380 (sizeof mips16_immed_operands / sizeof mips16_immed_operands[0])
9382 /* Handle a mips16 instruction with an immediate value. This or's the
9383 small immediate value into *INSN. It sets *USE_EXTEND to indicate
9384 whether an extended value is needed; if one is needed, it sets
9385 *EXTEND to the value. The argument type is TYPE. The value is VAL.
9386 If SMALL is true, an unextended opcode was explicitly requested.
9387 If EXT is true, an extended opcode was explicitly requested. If
9388 WARN is true, warn if EXT does not match reality. */
9391 mips16_immed (file, line, type, val, warn, small, ext, insn, use_extend,
9400 unsigned long *insn;
9401 boolean *use_extend;
9402 unsigned short *extend;
9404 register const struct mips16_immed_operand *op;
9405 int mintiny, maxtiny;
9408 op = mips16_immed_operands;
9409 while (op->type != type)
9412 assert (op < mips16_immed_operands + MIPS16_NUM_IMMED);
9417 if (type == '<' || type == '>' || type == '[' || type == ']')
9420 maxtiny = 1 << op->nbits;
9425 maxtiny = (1 << op->nbits) - 1;
9430 mintiny = - (1 << (op->nbits - 1));
9431 maxtiny = (1 << (op->nbits - 1)) - 1;
9434 /* Branch offsets have an implicit 0 in the lowest bit. */
9435 if (type == 'p' || type == 'q')
9438 if ((val & ((1 << op->shift) - 1)) != 0
9439 || val < (mintiny << op->shift)
9440 || val > (maxtiny << op->shift))
9445 if (warn && ext && ! needext)
9446 as_warn_where (file, line,
9447 _("extended operand requested but not required"));
9448 if (small && needext)
9449 as_bad_where (file, line, _("invalid unextended operand value"));
9451 if (small || (! ext && ! needext))
9455 *use_extend = false;
9456 insnval = ((val >> op->shift) & ((1 << op->nbits) - 1));
9457 insnval <<= op->op_shift;
9462 long minext, maxext;
9468 maxext = (1 << op->extbits) - 1;
9472 minext = - (1 << (op->extbits - 1));
9473 maxext = (1 << (op->extbits - 1)) - 1;
9475 if (val < minext || val > maxext)
9476 as_bad_where (file, line,
9477 _("operand value out of range for instruction"));
9480 if (op->extbits == 16)
9482 extval = ((val >> 11) & 0x1f) | (val & 0x7e0);
9485 else if (op->extbits == 15)
9487 extval = ((val >> 11) & 0xf) | (val & 0x7f0);
9492 extval = ((val & 0x1f) << 6) | (val & 0x20);
9496 *extend = (unsigned short) extval;
9501 static struct percent_op_match
9504 const enum small_ex_type type;
9509 {"%call_hi", S_EX_CALL_HI},
9510 {"%call_lo", S_EX_CALL_LO},
9511 {"%call16", S_EX_CALL16},
9512 {"%got_disp", S_EX_GOT_DISP},
9513 {"%got_page", S_EX_GOT_PAGE},
9514 {"%got_ofst", S_EX_GOT_OFST},
9515 {"%got_hi", S_EX_GOT_HI},
9516 {"%got_lo", S_EX_GOT_LO},
9518 {"%gp_rel", S_EX_GP_REL},
9519 {"%half", S_EX_HALF},
9520 {"%highest", S_EX_HIGHEST},
9521 {"%higher", S_EX_HIGHER},
9527 /* Parse small expression input. STR gets adjusted to eat up whitespace.
9528 It detects valid "%percent_op(...)" and "($reg)" strings. Percent_op's
9529 can be nested, this is handled by blanking the innermost, parsing the
9530 rest by subsequent calls. */
9533 my_getSmallParser (str, len, nestlevel)
9539 *str += strspn (*str, " \t");
9540 /* Check for expression in parentheses. */
9543 char *b = *str + 1 + strspn (*str + 1, " \t");
9546 /* Check for base register. */
9550 && (e = b + strcspn (b, ") \t"))
9551 && e - b > 1 && e - b < 4)
9554 && ((b[1] == 'f' && b[2] == 'p')
9555 || (b[1] == 's' && b[2] == 'p')
9556 || (b[1] == 'g' && b[2] == 'p')
9557 || (b[1] == 'a' && b[2] == 't')
9559 && ISDIGIT (b[2]))))
9560 || (ISDIGIT (b[1])))
9562 *len = strcspn (*str, ")") + 1;
9563 return S_EX_REGISTER;
9567 /* Check for percent_op (in parentheses). */
9568 else if (b[0] == '%')
9571 return my_getPercentOp (str, len, nestlevel);
9574 /* Some other expression in the parentheses, which can contain
9575 parentheses itself. Attempt to find the matching one. */
9581 for (s = *str + 1; *s && pcnt; s++, (*len)++)
9590 /* Check for percent_op (outside of parentheses). */
9591 else if (*str[0] == '%')
9592 return my_getPercentOp (str, len, nestlevel);
9594 /* Any other expression. */
9599 my_getPercentOp (str, len, nestlevel)
9604 char *tmp = *str + 1;
9607 while (ISALPHA (*tmp) || *tmp == '_')
9609 *tmp = TOLOWER (*tmp);
9612 while (i < (sizeof (percent_op) / sizeof (struct percent_op_match)))
9614 if (strncmp (*str, percent_op[i].str, strlen (percent_op[i].str)))
9618 int type = percent_op[i].type;
9620 /* Only %hi and %lo are allowed for OldABI. */
9621 if (! HAVE_NEWABI && type != S_EX_HI && type != S_EX_LO)
9624 *len = strlen (percent_op[i].str);
9633 my_getSmallExpression (ep, str)
9637 static char *oldstr = NULL;
9643 /* Don't update oldstr if the last call had nested percent_op's. We need
9644 it to parse the outer ones later. */
9651 c = my_getSmallParser (&str, &len, &nestlevel);
9652 if (c != S_EX_NONE && c != S_EX_REGISTER)
9655 while (c != S_EX_NONE && c != S_EX_REGISTER);
9659 /* A percent_op was encountered. Don't try to get an expression if
9660 it is already blanked out. */
9661 if (*(str + strspn (str + 1, " )")) != ')')
9665 /* Let my_getExpression() stop at the closing parenthesis. */
9666 save = *(str + len);
9667 *(str + len) = '\0';
9668 my_getExpression (ep, str);
9669 *(str + len) = save;
9673 /* Blank out including the % sign and the proper matching
9676 char *s = strrchr (oldstr, '%');
9679 for (end = strchr (s, '(') + 1; *end && pcnt; end++)
9683 else if (*end == ')')
9687 memset (s, ' ', end - s);
9691 expr_end = str + len;
9695 else if (c == S_EX_NONE)
9697 my_getExpression (ep, str);
9699 else if (c == S_EX_REGISTER)
9701 ep->X_op = O_constant;
9703 ep->X_add_symbol = NULL;
9704 ep->X_op_symbol = NULL;
9705 ep->X_add_number = 0;
9709 as_fatal (_("internal error"));
9713 /* All percent_op's have been handled. */
9720 my_getExpression (ep, str)
9727 save_in = input_line_pointer;
9728 input_line_pointer = str;
9730 expr_end = input_line_pointer;
9731 input_line_pointer = save_in;
9733 /* If we are in mips16 mode, and this is an expression based on `.',
9734 then we bump the value of the symbol by 1 since that is how other
9735 text symbols are handled. We don't bother to handle complex
9736 expressions, just `.' plus or minus a constant. */
9737 if (mips_opts.mips16
9738 && ep->X_op == O_symbol
9739 && strcmp (S_GET_NAME (ep->X_add_symbol), FAKE_LABEL_NAME) == 0
9740 && S_GET_SEGMENT (ep->X_add_symbol) == now_seg
9741 && symbol_get_frag (ep->X_add_symbol) == frag_now
9742 && symbol_constant_p (ep->X_add_symbol)
9743 && (val = S_GET_VALUE (ep->X_add_symbol)) == frag_now_fix ())
9744 S_SET_VALUE (ep->X_add_symbol, val + 1);
9747 /* Turn a string in input_line_pointer into a floating point constant
9748 of type TYPE, and store the appropriate bytes in *LITP. The number
9749 of LITTLENUMS emitted is stored in *SIZEP. An error message is
9750 returned, or NULL on OK. */
9753 md_atof (type, litP, sizeP)
9759 LITTLENUM_TYPE words[4];
9775 return _("bad call to md_atof");
9778 t = atof_ieee (input_line_pointer, type, words);
9780 input_line_pointer = t;
9784 if (! target_big_endian)
9786 for (i = prec - 1; i >= 0; i--)
9788 md_number_to_chars (litP, (valueT) words[i], 2);
9794 for (i = 0; i < prec; i++)
9796 md_number_to_chars (litP, (valueT) words[i], 2);
9805 md_number_to_chars (buf, val, n)
9810 if (target_big_endian)
9811 number_to_chars_bigendian (buf, val, n);
9813 number_to_chars_littleendian (buf, val, n);
9817 static int support_64bit_objects(void)
9819 const char **list, **l;
9821 list = bfd_target_list ();
9822 for (l = list; *l != NULL; l++)
9824 /* This is traditional mips */
9825 if (strcmp (*l, "elf64-tradbigmips") == 0
9826 || strcmp (*l, "elf64-tradlittlemips") == 0)
9828 if (strcmp (*l, "elf64-bigmips") == 0
9829 || strcmp (*l, "elf64-littlemips") == 0)
9833 return (*l != NULL);
9835 #endif /* OBJ_ELF */
9837 const char *md_shortopts = "nO::g::G:";
9839 struct option md_longopts[] =
9841 #define OPTION_MIPS1 (OPTION_MD_BASE + 1)
9842 {"mips0", no_argument, NULL, OPTION_MIPS1},
9843 {"mips1", no_argument, NULL, OPTION_MIPS1},
9844 #define OPTION_MIPS2 (OPTION_MD_BASE + 2)
9845 {"mips2", no_argument, NULL, OPTION_MIPS2},
9846 #define OPTION_MIPS3 (OPTION_MD_BASE + 3)
9847 {"mips3", no_argument, NULL, OPTION_MIPS3},
9848 #define OPTION_MIPS4 (OPTION_MD_BASE + 4)
9849 {"mips4", no_argument, NULL, OPTION_MIPS4},
9850 #define OPTION_MIPS5 (OPTION_MD_BASE + 5)
9851 {"mips5", no_argument, NULL, OPTION_MIPS5},
9852 #define OPTION_MIPS32 (OPTION_MD_BASE + 6)
9853 {"mips32", no_argument, NULL, OPTION_MIPS32},
9854 #define OPTION_MIPS64 (OPTION_MD_BASE + 7)
9855 {"mips64", no_argument, NULL, OPTION_MIPS64},
9856 #define OPTION_MEMBEDDED_PIC (OPTION_MD_BASE + 8)
9857 {"membedded-pic", no_argument, NULL, OPTION_MEMBEDDED_PIC},
9858 #define OPTION_TRAP (OPTION_MD_BASE + 9)
9859 {"trap", no_argument, NULL, OPTION_TRAP},
9860 {"no-break", no_argument, NULL, OPTION_TRAP},
9861 #define OPTION_BREAK (OPTION_MD_BASE + 10)
9862 {"break", no_argument, NULL, OPTION_BREAK},
9863 {"no-trap", no_argument, NULL, OPTION_BREAK},
9864 #define OPTION_EB (OPTION_MD_BASE + 11)
9865 {"EB", no_argument, NULL, OPTION_EB},
9866 #define OPTION_EL (OPTION_MD_BASE + 12)
9867 {"EL", no_argument, NULL, OPTION_EL},
9868 #define OPTION_MIPS16 (OPTION_MD_BASE + 13)
9869 {"mips16", no_argument, NULL, OPTION_MIPS16},
9870 #define OPTION_NO_MIPS16 (OPTION_MD_BASE + 14)
9871 {"no-mips16", no_argument, NULL, OPTION_NO_MIPS16},
9872 #define OPTION_M7000_HILO_FIX (OPTION_MD_BASE + 15)
9873 {"mfix7000", no_argument, NULL, OPTION_M7000_HILO_FIX},
9874 #define OPTION_MNO_7000_HILO_FIX (OPTION_MD_BASE + 16)
9875 {"no-fix-7000", no_argument, NULL, OPTION_MNO_7000_HILO_FIX},
9876 {"mno-fix7000", no_argument, NULL, OPTION_MNO_7000_HILO_FIX},
9877 #define OPTION_FP32 (OPTION_MD_BASE + 17)
9878 {"mfp32", no_argument, NULL, OPTION_FP32},
9879 #define OPTION_GP32 (OPTION_MD_BASE + 18)
9880 {"mgp32", no_argument, NULL, OPTION_GP32},
9881 #define OPTION_CONSTRUCT_FLOATS (OPTION_MD_BASE + 19)
9882 {"construct-floats", no_argument, NULL, OPTION_CONSTRUCT_FLOATS},
9883 #define OPTION_NO_CONSTRUCT_FLOATS (OPTION_MD_BASE + 20)
9884 {"no-construct-floats", no_argument, NULL, OPTION_NO_CONSTRUCT_FLOATS},
9885 #define OPTION_MARCH (OPTION_MD_BASE + 21)
9886 {"march", required_argument, NULL, OPTION_MARCH},
9887 #define OPTION_MTUNE (OPTION_MD_BASE + 22)
9888 {"mtune", required_argument, NULL, OPTION_MTUNE},
9889 #define OPTION_MCPU (OPTION_MD_BASE + 23)
9890 {"mcpu", required_argument, NULL, OPTION_MCPU},
9891 #define OPTION_M4650 (OPTION_MD_BASE + 24)
9892 {"m4650", no_argument, NULL, OPTION_M4650},
9893 #define OPTION_NO_M4650 (OPTION_MD_BASE + 25)
9894 {"no-m4650", no_argument, NULL, OPTION_NO_M4650},
9895 #define OPTION_M4010 (OPTION_MD_BASE + 26)
9896 {"m4010", no_argument, NULL, OPTION_M4010},
9897 #define OPTION_NO_M4010 (OPTION_MD_BASE + 27)
9898 {"no-m4010", no_argument, NULL, OPTION_NO_M4010},
9899 #define OPTION_M4100 (OPTION_MD_BASE + 28)
9900 {"m4100", no_argument, NULL, OPTION_M4100},
9901 #define OPTION_NO_M4100 (OPTION_MD_BASE + 29)
9902 {"no-m4100", no_argument, NULL, OPTION_NO_M4100},
9903 #define OPTION_M3900 (OPTION_MD_BASE + 30)
9904 {"m3900", no_argument, NULL, OPTION_M3900},
9905 #define OPTION_NO_M3900 (OPTION_MD_BASE + 31)
9906 {"no-m3900", no_argument, NULL, OPTION_NO_M3900},
9907 #define OPTION_GP64 (OPTION_MD_BASE + 32)
9908 {"mgp64", no_argument, NULL, OPTION_GP64},
9909 #define OPTION_MIPS3D (OPTION_MD_BASE + 33)
9910 {"mips3d", no_argument, NULL, OPTION_MIPS3D},
9911 #define OPTION_NO_MIPS3D (OPTION_MD_BASE + 34)
9912 {"no-mips3d", no_argument, NULL, OPTION_NO_MIPS3D},
9913 #define OPTION_MDMX (OPTION_MD_BASE + 35)
9914 {"mdmx", no_argument, NULL, OPTION_MDMX},
9915 #define OPTION_NO_MDMX (OPTION_MD_BASE + 36)
9916 {"no-mdmx", no_argument, NULL, OPTION_NO_MDMX},
9918 #define OPTION_ELF_BASE (OPTION_MD_BASE + 37)
9919 #define OPTION_CALL_SHARED (OPTION_ELF_BASE + 0)
9920 {"KPIC", no_argument, NULL, OPTION_CALL_SHARED},
9921 {"call_shared", no_argument, NULL, OPTION_CALL_SHARED},
9922 #define OPTION_NON_SHARED (OPTION_ELF_BASE + 1)
9923 {"non_shared", no_argument, NULL, OPTION_NON_SHARED},
9924 #define OPTION_XGOT (OPTION_ELF_BASE + 2)
9925 {"xgot", no_argument, NULL, OPTION_XGOT},
9926 #define OPTION_MABI (OPTION_ELF_BASE + 3)
9927 {"mabi", required_argument, NULL, OPTION_MABI},
9928 #define OPTION_32 (OPTION_ELF_BASE + 4)
9929 {"32", no_argument, NULL, OPTION_32},
9930 #define OPTION_N32 (OPTION_ELF_BASE + 5)
9931 {"n32", no_argument, NULL, OPTION_N32},
9932 #define OPTION_64 (OPTION_ELF_BASE + 6)
9933 {"64", no_argument, NULL, OPTION_64},
9934 #define OPTION_MDEBUG (OPTION_ELF_BASE + 7)
9935 {"mdebug", no_argument, NULL, OPTION_MDEBUG},
9936 #define OPTION_NO_MDEBUG (OPTION_ELF_BASE + 8)
9937 {"no-mdebug", no_argument, NULL, OPTION_NO_MDEBUG},
9938 #endif /* OBJ_ELF */
9939 {NULL, no_argument, NULL, 0}
9941 size_t md_longopts_size = sizeof (md_longopts);
9944 md_parse_option (c, arg)
9950 case OPTION_CONSTRUCT_FLOATS:
9951 mips_disable_float_construction = 0;
9954 case OPTION_NO_CONSTRUCT_FLOATS:
9955 mips_disable_float_construction = 1;
9967 target_big_endian = 1;
9971 target_big_endian = 0;
9979 if (arg && arg[1] == '0')
9989 mips_debug = atoi (arg);
9990 /* When the MIPS assembler sees -g or -g2, it does not do
9991 optimizations which limit full symbolic debugging. We take
9992 that to be equivalent to -O0. */
9993 if (mips_debug == 2)
9998 mips_opts.isa = ISA_MIPS1;
10002 mips_opts.isa = ISA_MIPS2;
10006 mips_opts.isa = ISA_MIPS3;
10010 mips_opts.isa = ISA_MIPS4;
10014 mips_opts.isa = ISA_MIPS5;
10017 case OPTION_MIPS32:
10018 mips_opts.isa = ISA_MIPS32;
10021 case OPTION_MIPS64:
10022 mips_opts.isa = ISA_MIPS64;
10029 int cpu = CPU_UNKNOWN;
10031 /* Identify the processor type. */
10032 if (strcasecmp (arg, "default") != 0)
10034 const struct mips_cpu_info *ci;
10036 ci = mips_cpu_info_from_name (arg);
10037 if (ci == NULL || ci->is_isa)
10042 as_fatal (_("invalid architecture -mtune=%s"), arg);
10045 as_fatal (_("invalid architecture -march=%s"), arg);
10048 as_fatal (_("invalid architecture -mcpu=%s"), arg);
10059 if (mips_tune != CPU_UNKNOWN && mips_tune != cpu)
10060 as_warn (_("A different -mtune= was already specified, is now "
10061 "-mtune=%s"), arg);
10065 if (mips_arch != CPU_UNKNOWN && mips_arch != cpu)
10066 as_warn (_("A different -march= was already specified, is now "
10067 "-march=%s"), arg);
10071 if (mips_cpu != CPU_UNKNOWN && mips_cpu != cpu)
10072 as_warn (_("A different -mcpu= was already specified, is now "
10080 if ((mips_arch != CPU_UNKNOWN && mips_arch != CPU_R4650)
10081 || (mips_tune != CPU_UNKNOWN && mips_tune != CPU_R4650))
10082 as_warn (_("A different -march= or -mtune= was already specified, "
10084 mips_arch = CPU_R4650;
10085 mips_tune = CPU_R4650;
10088 case OPTION_NO_M4650:
10092 if ((mips_arch != CPU_UNKNOWN && mips_arch != CPU_R4010)
10093 || (mips_tune != CPU_UNKNOWN && mips_tune != CPU_R4010))
10094 as_warn (_("A different -march= or -mtune= was already specified, "
10096 mips_arch = CPU_R4010;
10097 mips_tune = CPU_R4010;
10100 case OPTION_NO_M4010:
10104 if ((mips_arch != CPU_UNKNOWN && mips_arch != CPU_VR4100)
10105 || (mips_tune != CPU_UNKNOWN && mips_tune != CPU_VR4100))
10106 as_warn (_("A different -march= or -mtune= was already specified, "
10108 mips_arch = CPU_VR4100;
10109 mips_tune = CPU_VR4100;
10112 case OPTION_NO_M4100:
10116 if ((mips_arch != CPU_UNKNOWN && mips_arch != CPU_R3900)
10117 || (mips_tune != CPU_UNKNOWN && mips_tune != CPU_R3900))
10118 as_warn (_("A different -march= or -mtune= was already specified, "
10120 mips_arch = CPU_R3900;
10121 mips_tune = CPU_R3900;
10124 case OPTION_NO_M3900:
10128 mips_opts.ase_mdmx = 1;
10131 case OPTION_NO_MDMX:
10132 mips_opts.ase_mdmx = 0;
10135 case OPTION_MIPS16:
10136 mips_opts.mips16 = 1;
10137 mips_no_prev_insn (false);
10140 case OPTION_NO_MIPS16:
10141 mips_opts.mips16 = 0;
10142 mips_no_prev_insn (false);
10145 case OPTION_MIPS3D:
10146 mips_opts.ase_mips3d = 1;
10149 case OPTION_NO_MIPS3D:
10150 mips_opts.ase_mips3d = 0;
10153 case OPTION_MEMBEDDED_PIC:
10154 mips_pic = EMBEDDED_PIC;
10155 if (USE_GLOBAL_POINTER_OPT && g_switch_seen)
10157 as_bad (_("-G may not be used with embedded PIC code"));
10160 g_switch_value = 0x7fffffff;
10164 /* When generating ELF code, we permit -KPIC and -call_shared to
10165 select SVR4_PIC, and -non_shared to select no PIC. This is
10166 intended to be compatible with Irix 5. */
10167 case OPTION_CALL_SHARED:
10168 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10170 as_bad (_("-call_shared is supported only for ELF format"));
10173 mips_pic = SVR4_PIC;
10174 if (g_switch_seen && g_switch_value != 0)
10176 as_bad (_("-G may not be used with SVR4 PIC code"));
10179 g_switch_value = 0;
10182 case OPTION_NON_SHARED:
10183 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10185 as_bad (_("-non_shared is supported only for ELF format"));
10191 /* The -xgot option tells the assembler to use 32 offsets when
10192 accessing the got in SVR4_PIC mode. It is for Irix
10197 #endif /* OBJ_ELF */
10200 if (! USE_GLOBAL_POINTER_OPT)
10202 as_bad (_("-G is not supported for this configuration"));
10205 else if (mips_pic == SVR4_PIC || mips_pic == EMBEDDED_PIC)
10207 as_bad (_("-G may not be used with SVR4 or embedded PIC code"));
10211 g_switch_value = atoi (arg);
10216 /* The -32, -n32 and -64 options are shortcuts for -mabi=32, -mabi=n32
10219 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10221 as_bad (_("-32 is supported for ELF format only"));
10224 mips_opts.abi = O32_ABI;
10228 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10230 as_bad (_("-n32 is supported for ELF format only"));
10233 mips_opts.abi = N32_ABI;
10237 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10239 as_bad (_("-64 is supported for ELF format only"));
10242 mips_opts.abi = N64_ABI;
10243 if (! support_64bit_objects())
10244 as_fatal (_("No compiled in support for 64 bit object file format"));
10246 #endif /* OBJ_ELF */
10249 file_mips_gp32 = 1;
10250 if (mips_opts.abi != O32_ABI)
10251 mips_opts.abi = NO_ABI;
10255 file_mips_gp32 = 0;
10256 if (mips_opts.abi == O32_ABI)
10257 mips_opts.abi = NO_ABI;
10261 file_mips_fp32 = 1;
10262 if (mips_opts.abi != O32_ABI)
10263 mips_opts.abi = NO_ABI;
10268 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10270 as_bad (_("-mabi is supported for ELF format only"));
10273 if (strcmp (arg, "32") == 0)
10274 mips_opts.abi = O32_ABI;
10275 else if (strcmp (arg, "o64") == 0)
10276 mips_opts.abi = O64_ABI;
10277 else if (strcmp (arg, "n32") == 0)
10278 mips_opts.abi = N32_ABI;
10279 else if (strcmp (arg, "64") == 0)
10281 mips_opts.abi = N64_ABI;
10282 if (! support_64bit_objects())
10283 as_fatal (_("No compiled in support for 64 bit object file "
10286 else if (strcmp (arg, "eabi") == 0)
10287 mips_opts.abi = EABI_ABI;
10290 as_fatal (_("invalid abi -mabi=%s"), arg);
10294 #endif /* OBJ_ELF */
10296 case OPTION_M7000_HILO_FIX:
10297 mips_7000_hilo_fix = true;
10300 case OPTION_MNO_7000_HILO_FIX:
10301 mips_7000_hilo_fix = false;
10305 case OPTION_MDEBUG:
10306 mips_flag_mdebug = true;
10309 case OPTION_NO_MDEBUG:
10310 mips_flag_mdebug = false;
10312 #endif /* OBJ_ELF */
10322 show (stream, string, col_p, first_p)
10330 fprintf (stream, "%24s", "");
10335 fprintf (stream, ", ");
10339 if (*col_p + strlen (string) > 72)
10341 fprintf (stream, "\n%24s", "");
10345 fprintf (stream, "%s", string);
10346 *col_p += strlen (string);
10352 md_show_usage (stream)
10357 fprintf (stream, _("\
10359 -membedded-pic generate embedded position independent code\n\
10360 -EB generate big endian output\n\
10361 -EL generate little endian output\n\
10362 -g, -g2 do not remove unneeded NOPs or swap branches\n\
10363 -G NUM allow referencing objects up to NUM bytes\n\
10364 implicitly with the gp register [default 8]\n"));
10365 fprintf (stream, _("\
10366 -mips1 generate MIPS ISA I instructions\n\
10367 -mips2 generate MIPS ISA II instructions\n\
10368 -mips3 generate MIPS ISA III instructions\n\
10369 -mips4 generate MIPS ISA IV instructions\n\
10370 -mips5 generate MIPS ISA V instructions\n\
10371 -mips32 generate MIPS32 ISA instructions\n\
10372 -mips64 generate MIPS64 ISA instructions\n\
10373 -march=CPU/-mtune=CPU generate code/schedule for CPU, where CPU is one of:\n"));
10377 show (stream, "2000", &column, &first);
10378 show (stream, "3000", &column, &first);
10379 show (stream, "3900", &column, &first);
10380 show (stream, "4000", &column, &first);
10381 show (stream, "4010", &column, &first);
10382 show (stream, "4100", &column, &first);
10383 show (stream, "4111", &column, &first);
10384 show (stream, "4300", &column, &first);
10385 show (stream, "4400", &column, &first);
10386 show (stream, "4600", &column, &first);
10387 show (stream, "4650", &column, &first);
10388 show (stream, "5000", &column, &first);
10389 show (stream, "5200", &column, &first);
10390 show (stream, "5230", &column, &first);
10391 show (stream, "5231", &column, &first);
10392 show (stream, "5261", &column, &first);
10393 show (stream, "5721", &column, &first);
10394 show (stream, "6000", &column, &first);
10395 show (stream, "8000", &column, &first);
10396 show (stream, "10000", &column, &first);
10397 show (stream, "12000", &column, &first);
10398 show (stream, "sb1", &column, &first);
10399 fputc ('\n', stream);
10401 fprintf (stream, _("\
10402 -mCPU equivalent to -march=CPU -mtune=CPU. Deprecated.\n\
10403 -no-mCPU don't generate code specific to CPU.\n\
10404 For -mCPU and -no-mCPU, CPU must be one of:\n"));
10408 show (stream, "3900", &column, &first);
10409 show (stream, "4010", &column, &first);
10410 show (stream, "4100", &column, &first);
10411 show (stream, "4650", &column, &first);
10412 fputc ('\n', stream);
10414 fprintf (stream, _("\
10415 -mips16 generate mips16 instructions\n\
10416 -no-mips16 do not generate mips16 instructions\n"));
10417 fprintf (stream, _("\
10418 -mgp32 use 32-bit GPRs, regardless of the chosen ISA\n\
10419 -mfp32 use 32-bit FPRs, regardless of the chosen ISA\n\
10420 -O0 remove unneeded NOPs, do not swap branches\n\
10421 -O remove unneeded NOPs and swap branches\n\
10422 -n warn about NOPs generated from macros\n\
10423 --[no-]construct-floats [dis]allow floating point values to be constructed\n\
10424 --trap, --no-break trap exception on div by 0 and mult overflow\n\
10425 --break, --no-trap break exception on div by 0 and mult overflow\n"));
10427 fprintf (stream, _("\
10428 -KPIC, -call_shared generate SVR4 position independent code\n\
10429 -non_shared do not generate position independent code\n\
10430 -xgot assume a 32 bit GOT\n\
10431 -mabi=ABI create ABI conformant object file for:\n"));
10435 show (stream, "32", &column, &first);
10436 show (stream, "o64", &column, &first);
10437 show (stream, "n32", &column, &first);
10438 show (stream, "64", &column, &first);
10439 show (stream, "eabi", &column, &first);
10441 fputc ('\n', stream);
10443 fprintf (stream, _("\
10444 -32 create o32 ABI object file (default)\n\
10445 -n32 create n32 ABI object file\n\
10446 -64 create 64 ABI object file\n"));
10451 mips_after_parse_args ()
10455 int mips_isa_from_cpu;
10456 const struct mips_cpu_info *ci;
10458 /* GP relative stuff not working for PE */
10459 if (strncmp (TARGET_OS, "pe", 2) == 0
10460 && g_switch_value != 0)
10463 as_bad (_("-G not supported in this configuration."));
10464 g_switch_value = 0;
10468 if (strcmp (cpu + (sizeof TARGET_CPU) - 3, "el") == 0)
10470 a = xmalloc (sizeof TARGET_CPU);
10471 strcpy (a, TARGET_CPU);
10472 a[(sizeof TARGET_CPU) - 3] = '\0';
10476 /* Backward compatibility for historic -mcpu= option. Check for
10477 incompatible options, warn if -mcpu is used. */
10478 if (mips_cpu != CPU_UNKNOWN
10479 && mips_arch != CPU_UNKNOWN
10480 && mips_cpu != mips_arch)
10482 as_fatal (_("The -mcpu option can't be used together with -march. "
10483 "Use -mtune instead of -mcpu."));
10486 if (mips_cpu != CPU_UNKNOWN
10487 && mips_tune != CPU_UNKNOWN
10488 && mips_cpu != mips_tune)
10490 as_fatal (_("The -mcpu option can't be used together with -mtune. "
10491 "Use -march instead of -mcpu."));
10495 /* For backward compatibility, let -mipsN set various defaults. */
10496 /* This code should go away, to be replaced with something rather more
10497 draconian. Until GCC 3.1 has been released for some reasonable
10498 amount of time, however, we need to support this. */
10499 if (mips_opts.isa != ISA_UNKNOWN)
10501 /* Translate -mipsN to the appropriate settings of file_mips_gp32
10502 and file_mips_fp32. Tag binaries as using the mipsN ISA. */
10503 if (file_mips_gp32 < 0)
10505 if (ISA_HAS_64BIT_REGS (mips_opts.isa))
10506 file_mips_gp32 = 0;
10508 file_mips_gp32 = 1;
10510 if (file_mips_fp32 < 0)
10512 if (ISA_HAS_64BIT_REGS (mips_opts.isa))
10513 file_mips_fp32 = 0;
10515 file_mips_fp32 = 1;
10518 ci = mips_cpu_info_from_isa (mips_opts.isa);
10519 assert (ci != NULL);
10520 /* -mipsN has higher priority than -mcpu but lower than -march. */
10521 if (mips_arch == CPU_UNKNOWN)
10522 mips_arch = ci->cpu;
10524 /* Default mips_abi. */
10525 if (mips_opts.abi == NO_ABI)
10527 if (mips_opts.isa == ISA_MIPS1 || mips_opts.isa == ISA_MIPS2)
10528 mips_opts.abi = O32_ABI;
10529 else if (mips_opts.isa == ISA_MIPS3 || mips_opts.isa == ISA_MIPS4)
10530 mips_opts.abi = O64_ABI;
10534 if (mips_arch == CPU_UNKNOWN && mips_cpu != CPU_UNKNOWN)
10536 ci = mips_cpu_info_from_cpu (mips_cpu);
10537 assert (ci != NULL);
10538 mips_arch = ci->cpu;
10539 as_warn (_("The -mcpu option is deprecated. Please use -march and "
10540 "-mtune instead."));
10543 /* Set tune from -mcpu, not from -mipsN. */
10544 if (mips_tune == CPU_UNKNOWN && mips_cpu != CPU_UNKNOWN)
10546 ci = mips_cpu_info_from_cpu (mips_cpu);
10547 assert (ci != NULL);
10548 mips_tune = ci->cpu;
10551 /* At this point, mips_arch will either be CPU_UNKNOWN if no ARCH was
10552 specified on the command line, or some other value if one was.
10553 Similarly, mips_opts.isa will be ISA_UNKNOWN if not specified on
10554 the command line, or will be set otherwise if one was. */
10556 if (mips_arch != CPU_UNKNOWN && mips_opts.isa != ISA_UNKNOWN)
10557 /* Handled above. */;
10559 if (mips_arch == CPU_UNKNOWN && mips_cpu != CPU_UNKNOWN)
10561 ci = mips_cpu_info_from_cpu (mips_cpu);
10562 assert (ci != NULL);
10563 mips_arch = ci->cpu;
10564 as_warn (_("The -mcpu option is deprecated. Please use -march and "
10565 "-mtune instead."));
10568 /* At this point, mips_arch will either be CPU_UNKNOWN if no ARCH was
10569 specified on the command line, or some other value if one was.
10570 Similarly, mips_opts.isa will be ISA_UNKNOWN if not specified on
10571 the command line, or will be set otherwise if one was. */
10573 if (mips_arch != CPU_UNKNOWN && mips_opts.isa != ISA_UNKNOWN)
10575 /* We have to check if the isa is the default isa of arch. Otherwise
10576 we'll get invalid object file headers. */
10577 ci = mips_cpu_info_from_cpu (mips_arch);
10578 assert (ci != NULL);
10579 if (mips_opts.isa != ci->isa)
10581 /* This really should be an error instead of a warning, but old
10582 compilers only have -mcpu which sets both arch and tune. For
10583 now, we discard arch and preserve tune. */
10584 as_warn (_("The -march option is incompatible to -mipsN and "
10585 "therefore ignored."));
10586 if (mips_tune == CPU_UNKNOWN)
10587 mips_tune = mips_arch;
10588 ci = mips_cpu_info_from_isa (mips_opts.isa);
10589 assert (ci != NULL);
10590 mips_arch = ci->cpu;
10594 else if (mips_arch != CPU_UNKNOWN && mips_opts.isa == ISA_UNKNOWN)
10596 /* We have ARCH, we need ISA. */
10597 ci = mips_cpu_info_from_cpu (mips_arch);
10598 assert (ci != NULL);
10599 mips_opts.isa = ci->isa;
10601 else if (mips_arch == CPU_UNKNOWN && mips_opts.isa != ISA_UNKNOWN)
10603 /* We have ISA, we need default ARCH. */
10604 ci = mips_cpu_info_from_isa (mips_opts.isa);
10605 assert (ci != NULL);
10606 mips_arch = ci->cpu;
10610 /* We need to set both ISA and ARCH from target cpu. */
10611 ci = mips_cpu_info_from_name (cpu);
10613 ci = mips_cpu_info_from_cpu (CPU_R3000);
10614 assert (ci != NULL);
10615 mips_opts.isa = ci->isa;
10616 mips_arch = ci->cpu;
10619 if (mips_tune == CPU_UNKNOWN)
10620 mips_tune = mips_arch;
10622 ci = mips_cpu_info_from_cpu (mips_arch);
10623 assert (ci != NULL);
10624 mips_isa_from_cpu = ci->isa;
10626 /* End of TARGET_CPU processing, get rid of malloced memory
10635 if (mips_opts.isa == ISA_MIPS1 && mips_trap)
10636 as_bad (_("trap exception not supported at ISA 1"));
10638 /* If they asked for mips1 or mips2 and a cpu that is
10639 mips3 or greater, then mark the object file 32BITMODE. */
10640 if (mips_isa_from_cpu != ISA_UNKNOWN
10641 && ! ISA_HAS_64BIT_REGS (mips_opts.isa)
10642 && ISA_HAS_64BIT_REGS (mips_isa_from_cpu))
10643 mips_32bitmode = 1;
10645 /* If the selected architecture includes support for ASEs, enable
10646 generation of code for them. */
10647 if (mips_opts.mips16 == -1)
10648 mips_opts.mips16 = (CPU_HAS_MIPS16 (mips_arch)) ? 1 : 0;
10649 if (mips_opts.ase_mips3d == -1)
10650 mips_opts.ase_mips3d = (CPU_HAS_MIPS3D (mips_arch)) ? 1 : 0;
10651 if (mips_opts.ase_mdmx == -1)
10652 mips_opts.ase_mdmx = (CPU_HAS_MDMX (mips_arch)) ? 1 : 0;
10654 if (file_mips_gp32 < 0)
10655 file_mips_gp32 = 0;
10656 if (file_mips_fp32 < 0)
10657 file_mips_fp32 = 0;
10659 file_mips_isa = mips_opts.isa;
10660 file_mips_abi = mips_opts.abi;
10661 file_ase_mips16 = mips_opts.mips16;
10662 file_ase_mips3d = mips_opts.ase_mips3d;
10663 file_ase_mdmx = mips_opts.ase_mdmx;
10664 mips_opts.gp32 = file_mips_gp32;
10665 mips_opts.fp32 = file_mips_fp32;
10670 if (mips_flag_mdebug < 0)
10672 #ifdef OBJ_MAYBE_ECOFF
10673 if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour)
10674 mips_flag_mdebug = 1;
10676 #endif /* OBJ_MAYBE_ECOFF */
10677 mips_flag_mdebug = 0;
10682 mips_init_after_args ()
10684 /* initialize opcodes */
10685 bfd_mips_num_opcodes = bfd_mips_num_builtin_opcodes;
10686 mips_opcodes = (struct mips_opcode *) mips_builtin_opcodes;
10690 md_pcrel_from (fixP)
10693 if (OUTPUT_FLAVOR != bfd_target_aout_flavour
10694 && fixP->fx_addsy != (symbolS *) NULL
10695 && ! S_IS_DEFINED (fixP->fx_addsy))
10697 /* This makes a branch to an undefined symbol be a branch to the
10698 current location. */
10699 if (mips_pic == EMBEDDED_PIC)
10705 /* Return the address of the delay slot. */
10706 return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address;
10709 /* This is called before the symbol table is processed. In order to
10710 work with gcc when using mips-tfile, we must keep all local labels.
10711 However, in other cases, we want to discard them. If we were
10712 called with -g, but we didn't see any debugging information, it may
10713 mean that gcc is smuggling debugging information through to
10714 mips-tfile, in which case we must generate all local labels. */
10717 mips_frob_file_before_adjust ()
10719 #ifndef NO_ECOFF_DEBUGGING
10720 if (ECOFF_DEBUGGING
10722 && ! ecoff_debugging_seen)
10723 flag_keep_locals = 1;
10727 /* Sort any unmatched HI16_S relocs so that they immediately precede
10728 the corresponding LO reloc. This is called before md_apply_fix3 and
10729 tc_gen_reloc. Unmatched HI16_S relocs can only be generated by
10730 explicit use of the %hi modifier. */
10735 struct mips_hi_fixup *l;
10737 for (l = mips_hi_fixup_list; l != NULL; l = l->next)
10739 segment_info_type *seginfo;
10742 assert (l->fixp->fx_r_type == BFD_RELOC_HI16_S);
10744 /* Check quickly whether the next fixup happens to be a matching
10746 if (l->fixp->fx_next != NULL
10747 && l->fixp->fx_next->fx_r_type == BFD_RELOC_LO16
10748 && l->fixp->fx_addsy == l->fixp->fx_next->fx_addsy
10749 && l->fixp->fx_offset == l->fixp->fx_next->fx_offset)
10752 /* Look through the fixups for this segment for a matching %lo.
10753 When we find one, move the %hi just in front of it. We do
10754 this in two passes. In the first pass, we try to find a
10755 unique %lo. In the second pass, we permit multiple %hi
10756 relocs for a single %lo (this is a GNU extension). */
10757 seginfo = seg_info (l->seg);
10758 for (pass = 0; pass < 2; pass++)
10763 for (f = seginfo->fix_root; f != NULL; f = f->fx_next)
10765 /* Check whether this is a %lo fixup which matches l->fixp. */
10766 if (f->fx_r_type == BFD_RELOC_LO16
10767 && f->fx_addsy == l->fixp->fx_addsy
10768 && f->fx_offset == l->fixp->fx_offset
10771 || prev->fx_r_type != BFD_RELOC_HI16_S
10772 || prev->fx_addsy != f->fx_addsy
10773 || prev->fx_offset != f->fx_offset))
10777 /* Move l->fixp before f. */
10778 for (pf = &seginfo->fix_root;
10780 pf = &(*pf)->fx_next)
10781 assert (*pf != NULL);
10783 *pf = l->fixp->fx_next;
10785 l->fixp->fx_next = f;
10787 seginfo->fix_root = l->fixp;
10789 prev->fx_next = l->fixp;
10800 #if 0 /* GCC code motion plus incomplete dead code elimination
10801 can leave a %hi without a %lo. */
10803 as_warn_where (l->fixp->fx_file, l->fixp->fx_line,
10804 _("Unmatched %%hi reloc"));
10810 /* When generating embedded PIC code we need to use a special
10811 relocation to represent the difference of two symbols in the .text
10812 section (switch tables use a difference of this sort). See
10813 include/coff/mips.h for details. This macro checks whether this
10814 fixup requires the special reloc. */
10815 #define SWITCH_TABLE(fixp) \
10816 ((fixp)->fx_r_type == BFD_RELOC_32 \
10817 && OUTPUT_FLAVOR != bfd_target_elf_flavour \
10818 && (fixp)->fx_addsy != NULL \
10819 && (fixp)->fx_subsy != NULL \
10820 && S_GET_SEGMENT ((fixp)->fx_addsy) == text_section \
10821 && S_GET_SEGMENT ((fixp)->fx_subsy) == text_section)
10823 /* When generating embedded PIC code we must keep all PC relative
10824 relocations, in case the linker has to relax a call. We also need
10825 to keep relocations for switch table entries.
10827 We may have combined relocations without symbols in the N32/N64 ABI.
10828 We have to prevent gas from dropping them. */
10831 mips_force_relocation (fixp)
10834 if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT
10835 || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
10839 && S_GET_SEGMENT (fixp->fx_addsy) == bfd_abs_section_ptr
10840 && (fixp->fx_r_type == BFD_RELOC_MIPS_SUB
10841 || fixp->fx_r_type == BFD_RELOC_HI16_S
10842 || fixp->fx_r_type == BFD_RELOC_LO16))
10845 return (mips_pic == EMBEDDED_PIC
10847 || SWITCH_TABLE (fixp)
10848 || fixp->fx_r_type == BFD_RELOC_PCREL_HI16_S
10849 || fixp->fx_r_type == BFD_RELOC_PCREL_LO16));
10854 mips_need_elf_addend_fixup (fixP)
10857 if (S_GET_OTHER (fixP->fx_addsy) == STO_MIPS16)
10859 if (mips_pic == EMBEDDED_PIC
10860 && S_IS_WEAK (fixP->fx_addsy))
10862 if (mips_pic != EMBEDDED_PIC
10863 && (S_IS_WEAK (fixP->fx_addsy)
10864 || S_IS_EXTERN (fixP->fx_addsy))
10865 && !S_IS_COMMON (fixP->fx_addsy))
10867 if (symbol_used_in_reloc_p (fixP->fx_addsy)
10868 && (((bfd_get_section_flags (stdoutput,
10869 S_GET_SEGMENT (fixP->fx_addsy))
10870 & SEC_LINK_ONCE) != 0)
10871 || !strncmp (segment_name (S_GET_SEGMENT (fixP->fx_addsy)),
10873 sizeof (".gnu.linkonce") - 1)))
10879 /* Apply a fixup to the object file. */
10882 md_apply_fix3 (fixP, valP, seg)
10885 segT seg ATTRIBUTE_UNUSED;
10891 assert (fixP->fx_size == 4
10892 || fixP->fx_r_type == BFD_RELOC_16
10893 || fixP->fx_r_type == BFD_RELOC_32
10894 || fixP->fx_r_type == BFD_RELOC_MIPS_JMP
10895 || fixP->fx_r_type == BFD_RELOC_HI16_S
10896 || fixP->fx_r_type == BFD_RELOC_LO16
10897 || fixP->fx_r_type == BFD_RELOC_GPREL16
10898 || fixP->fx_r_type == BFD_RELOC_MIPS_LITERAL
10899 || fixP->fx_r_type == BFD_RELOC_GPREL32
10900 || fixP->fx_r_type == BFD_RELOC_64
10901 || fixP->fx_r_type == BFD_RELOC_CTOR
10902 || fixP->fx_r_type == BFD_RELOC_MIPS_SUB
10903 || fixP->fx_r_type == BFD_RELOC_MIPS_HIGHEST
10904 || fixP->fx_r_type == BFD_RELOC_MIPS_HIGHER
10905 || fixP->fx_r_type == BFD_RELOC_MIPS_SCN_DISP
10906 || fixP->fx_r_type == BFD_RELOC_MIPS_REL16
10907 || fixP->fx_r_type == BFD_RELOC_MIPS_RELGOT
10908 || fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
10909 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY
10910 || fixP->fx_r_type == BFD_RELOC_MIPS_JALR);
10914 /* If we aren't adjusting this fixup to be against the section
10915 symbol, we need to adjust the value. */
10917 if (fixP->fx_addsy != NULL && OUTPUT_FLAVOR == bfd_target_elf_flavour)
10919 if (mips_need_elf_addend_fixup (fixP))
10921 reloc_howto_type *howto;
10922 valueT symval = S_GET_VALUE (fixP->fx_addsy);
10926 howto = bfd_reloc_type_lookup (stdoutput, fixP->fx_r_type);
10927 if (value != 0 && howto->partial_inplace && ! fixP->fx_pcrel)
10929 /* In this case, the bfd_install_relocation routine will
10930 incorrectly add the symbol value back in. We just want
10931 the addend to appear in the object file. */
10934 /* Make sure the addend is still non-zero. If it became zero
10935 after the last operation, set it to a spurious value and
10936 subtract the same value from the object file's contents. */
10941 /* The in-place addends for LO16 relocations are signed;
10942 leave the matching HI16 in-place addends as zero. */
10943 if (fixP->fx_r_type != BFD_RELOC_HI16_S)
10945 bfd_vma contents, mask, field;
10947 contents = bfd_get_bits (fixP->fx_frag->fr_literal
10950 target_big_endian);
10952 /* MASK has bits set where the relocation should go.
10953 FIELD is -value, shifted into the appropriate place
10954 for this relocation. */
10955 mask = 1 << (howto->bitsize - 1);
10956 mask = (((mask - 1) << 1) | 1) << howto->bitpos;
10957 field = (-value >> howto->rightshift) << howto->bitpos;
10959 bfd_put_bits ((field & mask) | (contents & ~mask),
10960 fixP->fx_frag->fr_literal + fixP->fx_where,
10962 target_big_endian);
10968 /* This code was generated using trial and error and so is
10969 fragile and not trustworthy. If you change it, you should
10970 rerun the elf-rel, elf-rel2, and empic testcases and ensure
10971 they still pass. */
10972 if (fixP->fx_pcrel || fixP->fx_subsy != NULL)
10974 value += fixP->fx_frag->fr_address + fixP->fx_where;
10976 /* BFD's REL handling, for MIPS, is _very_ weird.
10977 This gives the right results, but it can't possibly
10978 be the way things are supposed to work. */
10979 if ((fixP->fx_r_type != BFD_RELOC_16_PCREL
10980 && fixP->fx_r_type != BFD_RELOC_16_PCREL_S2)
10981 || S_GET_SEGMENT (fixP->fx_addsy) != undefined_section)
10982 value += fixP->fx_frag->fr_address + fixP->fx_where;
10987 fixP->fx_addnumber = value; /* Remember value for tc_gen_reloc. */
10989 if (fixP->fx_addsy == NULL && ! fixP->fx_pcrel)
10992 switch (fixP->fx_r_type)
10994 case BFD_RELOC_MIPS_JMP:
10995 case BFD_RELOC_MIPS_SHIFT5:
10996 case BFD_RELOC_MIPS_SHIFT6:
10997 case BFD_RELOC_MIPS_GOT_DISP:
10998 case BFD_RELOC_MIPS_GOT_PAGE:
10999 case BFD_RELOC_MIPS_GOT_OFST:
11000 case BFD_RELOC_MIPS_SUB:
11001 case BFD_RELOC_MIPS_INSERT_A:
11002 case BFD_RELOC_MIPS_INSERT_B:
11003 case BFD_RELOC_MIPS_DELETE:
11004 case BFD_RELOC_MIPS_HIGHEST:
11005 case BFD_RELOC_MIPS_HIGHER:
11006 case BFD_RELOC_MIPS_SCN_DISP:
11007 case BFD_RELOC_MIPS_REL16:
11008 case BFD_RELOC_MIPS_RELGOT:
11009 case BFD_RELOC_MIPS_JALR:
11010 case BFD_RELOC_HI16:
11011 case BFD_RELOC_HI16_S:
11012 case BFD_RELOC_GPREL16:
11013 case BFD_RELOC_MIPS_LITERAL:
11014 case BFD_RELOC_MIPS_CALL16:
11015 case BFD_RELOC_MIPS_GOT16:
11016 case BFD_RELOC_GPREL32:
11017 case BFD_RELOC_MIPS_GOT_HI16:
11018 case BFD_RELOC_MIPS_GOT_LO16:
11019 case BFD_RELOC_MIPS_CALL_HI16:
11020 case BFD_RELOC_MIPS_CALL_LO16:
11021 case BFD_RELOC_MIPS16_GPREL:
11022 if (fixP->fx_pcrel)
11023 as_bad_where (fixP->fx_file, fixP->fx_line,
11024 _("Invalid PC relative reloc"));
11025 /* Nothing needed to do. The value comes from the reloc entry */
11028 case BFD_RELOC_MIPS16_JMP:
11029 /* We currently always generate a reloc against a symbol, which
11030 means that we don't want an addend even if the symbol is
11032 fixP->fx_addnumber = 0;
11035 case BFD_RELOC_PCREL_HI16_S:
11036 /* The addend for this is tricky if it is internal, so we just
11037 do everything here rather than in bfd_install_relocation. */
11038 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
11043 && (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_SECTION_SYM) == 0)
11045 /* For an external symbol adjust by the address to make it
11046 pcrel_offset. We use the address of the RELLO reloc
11047 which follows this one. */
11048 value += (fixP->fx_next->fx_frag->fr_address
11049 + fixP->fx_next->fx_where);
11051 value = ((value + 0x8000) >> 16) & 0xffff;
11052 buf = (bfd_byte *) fixP->fx_frag->fr_literal + fixP->fx_where;
11053 if (target_big_endian)
11055 md_number_to_chars ((char *) buf, value, 2);
11058 case BFD_RELOC_PCREL_LO16:
11059 /* The addend for this is tricky if it is internal, so we just
11060 do everything here rather than in bfd_install_relocation. */
11061 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
11066 && (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_SECTION_SYM) == 0)
11067 value += fixP->fx_frag->fr_address + fixP->fx_where;
11068 buf = (bfd_byte *) fixP->fx_frag->fr_literal + fixP->fx_where;
11069 if (target_big_endian)
11071 md_number_to_chars ((char *) buf, value, 2);
11075 /* This is handled like BFD_RELOC_32, but we output a sign
11076 extended value if we are only 32 bits. */
11078 || (mips_pic == EMBEDDED_PIC && SWITCH_TABLE (fixP)))
11080 if (8 <= sizeof (valueT))
11081 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
11088 w1 = w2 = fixP->fx_where;
11089 if (target_big_endian)
11093 md_number_to_chars (fixP->fx_frag->fr_literal + w1, value, 4);
11094 if ((value & 0x80000000) != 0)
11098 md_number_to_chars (fixP->fx_frag->fr_literal + w2, hiv, 4);
11103 case BFD_RELOC_RVA:
11105 /* If we are deleting this reloc entry, we must fill in the
11106 value now. This can happen if we have a .word which is not
11107 resolved when it appears but is later defined. We also need
11108 to fill in the value if this is an embedded PIC switch table
11111 || (mips_pic == EMBEDDED_PIC && SWITCH_TABLE (fixP)))
11112 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
11117 /* If we are deleting this reloc entry, we must fill in the
11119 assert (fixP->fx_size == 2);
11121 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
11125 case BFD_RELOC_LO16:
11126 /* When handling an embedded PIC switch statement, we can wind
11127 up deleting a LO16 reloc. See the 'o' case in mips_ip. */
11130 if (value + 0x8000 > 0xffff)
11131 as_bad_where (fixP->fx_file, fixP->fx_line,
11132 _("relocation overflow"));
11133 buf = (bfd_byte *) fixP->fx_frag->fr_literal + fixP->fx_where;
11134 if (target_big_endian)
11136 md_number_to_chars ((char *) buf, value, 2);
11140 case BFD_RELOC_16_PCREL_S2:
11141 if ((value & 0x3) != 0)
11142 as_bad_where (fixP->fx_file, fixP->fx_line,
11143 _("Branch to odd address (%lx)"), (long) value);
11145 /* Fall through. */
11147 case BFD_RELOC_16_PCREL:
11149 * We need to save the bits in the instruction since fixup_segment()
11150 * might be deleting the relocation entry (i.e., a branch within
11151 * the current segment).
11153 if (!fixP->fx_done && value != 0)
11155 /* If 'value' is zero, the remaining reloc code won't actually
11156 do the store, so it must be done here. This is probably
11157 a bug somewhere. */
11159 && (fixP->fx_r_type != BFD_RELOC_16_PCREL_S2
11160 || fixP->fx_addsy == NULL /* ??? */
11161 || ! S_IS_DEFINED (fixP->fx_addsy)))
11162 value -= fixP->fx_frag->fr_address + fixP->fx_where;
11164 value = (offsetT) value >> 2;
11166 /* update old instruction data */
11167 buf = (bfd_byte *) (fixP->fx_where + fixP->fx_frag->fr_literal);
11168 if (target_big_endian)
11169 insn = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
11171 insn = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
11173 if (value + 0x8000 <= 0xffff)
11174 insn |= value & 0xffff;
11177 /* The branch offset is too large. If this is an
11178 unconditional branch, and we are not generating PIC code,
11179 we can convert it to an absolute jump instruction. */
11180 if (mips_pic == NO_PIC
11182 && fixP->fx_frag->fr_address >= text_section->vma
11183 && (fixP->fx_frag->fr_address
11184 < text_section->vma + text_section->_raw_size)
11185 && ((insn & 0xffff0000) == 0x10000000 /* beq $0,$0 */
11186 || (insn & 0xffff0000) == 0x04010000 /* bgez $0 */
11187 || (insn & 0xffff0000) == 0x04110000)) /* bgezal $0 */
11189 if ((insn & 0xffff0000) == 0x04110000) /* bgezal $0 */
11190 insn = 0x0c000000; /* jal */
11192 insn = 0x08000000; /* j */
11193 fixP->fx_r_type = BFD_RELOC_MIPS_JMP;
11195 fixP->fx_addsy = section_symbol (text_section);
11196 fixP->fx_addnumber = (value << 2) + md_pcrel_from (fixP);
11200 /* FIXME. It would be possible in principle to handle
11201 conditional branches which overflow. They could be
11202 transformed into a branch around a jump. This would
11203 require setting up variant frags for each different
11204 branch type. The native MIPS assembler attempts to
11205 handle these cases, but it appears to do it
11207 as_bad_where (fixP->fx_file, fixP->fx_line,
11208 _("Branch out of range"));
11212 md_number_to_chars ((char *) buf, (valueT) insn, 4);
11215 case BFD_RELOC_VTABLE_INHERIT:
11218 && !S_IS_DEFINED (fixP->fx_addsy)
11219 && !S_IS_WEAK (fixP->fx_addsy))
11220 S_SET_WEAK (fixP->fx_addsy);
11223 case BFD_RELOC_VTABLE_ENTRY:
11237 const struct mips_opcode *p;
11238 int treg, sreg, dreg, shamt;
11243 for (i = 0; i < NUMOPCODES; ++i)
11245 p = &mips_opcodes[i];
11246 if (((oc & p->mask) == p->match) && (p->pinfo != INSN_MACRO))
11248 printf ("%08lx %s\t", oc, p->name);
11249 treg = (oc >> 16) & 0x1f;
11250 sreg = (oc >> 21) & 0x1f;
11251 dreg = (oc >> 11) & 0x1f;
11252 shamt = (oc >> 6) & 0x1f;
11254 for (args = p->args;; ++args)
11265 printf ("%c", *args);
11269 assert (treg == sreg);
11270 printf ("$%d,$%d", treg, sreg);
11275 printf ("$%d", dreg);
11280 printf ("$%d", treg);
11284 printf ("0x%x", treg);
11289 printf ("$%d", sreg);
11293 printf ("0x%08lx", oc & 0x1ffffff);
11300 printf ("%d", imm);
11305 printf ("$%d", shamt);
11316 printf (_("%08lx UNDEFINED\n"), oc);
11327 name = input_line_pointer;
11328 c = get_symbol_end ();
11329 p = (symbolS *) symbol_find_or_make (name);
11330 *input_line_pointer = c;
11334 /* Align the current frag to a given power of two. The MIPS assembler
11335 also automatically adjusts any preceding label. */
11338 mips_align (to, fill, label)
11343 mips_emit_delays (false);
11344 frag_align (to, fill, 0);
11345 record_alignment (now_seg, to);
11348 assert (S_GET_SEGMENT (label) == now_seg);
11349 symbol_set_frag (label, frag_now);
11350 S_SET_VALUE (label, (valueT) frag_now_fix ());
11354 /* Align to a given power of two. .align 0 turns off the automatic
11355 alignment used by the data creating pseudo-ops. */
11359 int x ATTRIBUTE_UNUSED;
11362 register long temp_fill;
11363 long max_alignment = 15;
11367 o Note that the assembler pulls down any immediately preceeding label
11368 to the aligned address.
11369 o It's not documented but auto alignment is reinstated by
11370 a .align pseudo instruction.
11371 o Note also that after auto alignment is turned off the mips assembler
11372 issues an error on attempt to assemble an improperly aligned data item.
11377 temp = get_absolute_expression ();
11378 if (temp > max_alignment)
11379 as_bad (_("Alignment too large: %d. assumed."), temp = max_alignment);
11382 as_warn (_("Alignment negative: 0 assumed."));
11385 if (*input_line_pointer == ',')
11387 ++input_line_pointer;
11388 temp_fill = get_absolute_expression ();
11395 mips_align (temp, (int) temp_fill,
11396 insn_labels != NULL ? insn_labels->label : NULL);
11403 demand_empty_rest_of_line ();
11407 mips_flush_pending_output ()
11409 mips_emit_delays (false);
11410 mips_clear_insn_labels ();
11419 /* When generating embedded PIC code, we only use the .text, .lit8,
11420 .sdata and .sbss sections. We change the .data and .rdata
11421 pseudo-ops to use .sdata. */
11422 if (mips_pic == EMBEDDED_PIC
11423 && (sec == 'd' || sec == 'r'))
11427 /* The ELF backend needs to know that we are changing sections, so
11428 that .previous works correctly. We could do something like check
11429 for an obj_section_change_hook macro, but that might be confusing
11430 as it would not be appropriate to use it in the section changing
11431 functions in read.c, since obj-elf.c intercepts those. FIXME:
11432 This should be cleaner, somehow. */
11433 obj_elf_section_change_hook ();
11436 mips_emit_delays (false);
11446 subseg_set (bss_section, (subsegT) get_absolute_expression ());
11447 demand_empty_rest_of_line ();
11451 if (USE_GLOBAL_POINTER_OPT)
11453 seg = subseg_new (RDATA_SECTION_NAME,
11454 (subsegT) get_absolute_expression ());
11455 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
11457 bfd_set_section_flags (stdoutput, seg,
11463 if (strcmp (TARGET_OS, "elf") != 0)
11464 record_alignment (seg, 4);
11466 demand_empty_rest_of_line ();
11470 as_bad (_("No read only data section in this object file format"));
11471 demand_empty_rest_of_line ();
11477 if (USE_GLOBAL_POINTER_OPT)
11479 seg = subseg_new (".sdata", (subsegT) get_absolute_expression ());
11480 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
11482 bfd_set_section_flags (stdoutput, seg,
11483 SEC_ALLOC | SEC_LOAD | SEC_RELOC
11485 if (strcmp (TARGET_OS, "elf") != 0)
11486 record_alignment (seg, 4);
11488 demand_empty_rest_of_line ();
11493 as_bad (_("Global pointers not supported; recompile -G 0"));
11494 demand_empty_rest_of_line ();
11503 mips_enable_auto_align ()
11514 label = insn_labels != NULL ? insn_labels->label : NULL;
11515 mips_emit_delays (false);
11516 if (log_size > 0 && auto_align)
11517 mips_align (log_size, 0, label);
11518 mips_clear_insn_labels ();
11519 cons (1 << log_size);
11523 s_float_cons (type)
11528 label = insn_labels != NULL ? insn_labels->label : NULL;
11530 mips_emit_delays (false);
11535 mips_align (3, 0, label);
11537 mips_align (2, 0, label);
11540 mips_clear_insn_labels ();
11545 /* Handle .globl. We need to override it because on Irix 5 you are
11548 where foo is an undefined symbol, to mean that foo should be
11549 considered to be the address of a function. */
11553 int x ATTRIBUTE_UNUSED;
11560 name = input_line_pointer;
11561 c = get_symbol_end ();
11562 symbolP = symbol_find_or_make (name);
11563 *input_line_pointer = c;
11564 SKIP_WHITESPACE ();
11566 /* On Irix 5, every global symbol that is not explicitly labelled as
11567 being a function is apparently labelled as being an object. */
11570 if (! is_end_of_line[(unsigned char) *input_line_pointer])
11575 secname = input_line_pointer;
11576 c = get_symbol_end ();
11577 sec = bfd_get_section_by_name (stdoutput, secname);
11579 as_bad (_("%s: no such section"), secname);
11580 *input_line_pointer = c;
11582 if (sec != NULL && (sec->flags & SEC_CODE) != 0)
11583 flag = BSF_FUNCTION;
11586 symbol_get_bfdsym (symbolP)->flags |= flag;
11588 S_SET_EXTERNAL (symbolP);
11589 demand_empty_rest_of_line ();
11594 int x ATTRIBUTE_UNUSED;
11599 opt = input_line_pointer;
11600 c = get_symbol_end ();
11604 /* FIXME: What does this mean? */
11606 else if (strncmp (opt, "pic", 3) == 0)
11610 i = atoi (opt + 3);
11614 mips_pic = SVR4_PIC;
11616 as_bad (_(".option pic%d not supported"), i);
11618 if (USE_GLOBAL_POINTER_OPT && mips_pic == SVR4_PIC)
11620 if (g_switch_seen && g_switch_value != 0)
11621 as_warn (_("-G may not be used with SVR4 PIC code"));
11622 g_switch_value = 0;
11623 bfd_set_gp_size (stdoutput, 0);
11627 as_warn (_("Unrecognized option \"%s\""), opt);
11629 *input_line_pointer = c;
11630 demand_empty_rest_of_line ();
11633 /* This structure is used to hold a stack of .set values. */
11635 struct mips_option_stack
11637 struct mips_option_stack *next;
11638 struct mips_set_options options;
11641 static struct mips_option_stack *mips_opts_stack;
11643 /* Handle the .set pseudo-op. */
11647 int x ATTRIBUTE_UNUSED;
11649 char *name = input_line_pointer, ch;
11651 while (!is_end_of_line[(unsigned char) *input_line_pointer])
11652 ++input_line_pointer;
11653 ch = *input_line_pointer;
11654 *input_line_pointer = '\0';
11656 if (strcmp (name, "reorder") == 0)
11658 if (mips_opts.noreorder && prev_nop_frag != NULL)
11660 /* If we still have pending nops, we can discard them. The
11661 usual nop handling will insert any that are still
11663 prev_nop_frag->fr_fix -= (prev_nop_frag_holds
11664 * (mips_opts.mips16 ? 2 : 4));
11665 prev_nop_frag = NULL;
11667 mips_opts.noreorder = 0;
11669 else if (strcmp (name, "noreorder") == 0)
11671 mips_emit_delays (true);
11672 mips_opts.noreorder = 1;
11673 mips_any_noreorder = 1;
11675 else if (strcmp (name, "at") == 0)
11677 mips_opts.noat = 0;
11679 else if (strcmp (name, "noat") == 0)
11681 mips_opts.noat = 1;
11683 else if (strcmp (name, "macro") == 0)
11685 mips_opts.warn_about_macros = 0;
11687 else if (strcmp (name, "nomacro") == 0)
11689 if (mips_opts.noreorder == 0)
11690 as_bad (_("`noreorder' must be set before `nomacro'"));
11691 mips_opts.warn_about_macros = 1;
11693 else if (strcmp (name, "move") == 0 || strcmp (name, "novolatile") == 0)
11695 mips_opts.nomove = 0;
11697 else if (strcmp (name, "nomove") == 0 || strcmp (name, "volatile") == 0)
11699 mips_opts.nomove = 1;
11701 else if (strcmp (name, "bopt") == 0)
11703 mips_opts.nobopt = 0;
11705 else if (strcmp (name, "nobopt") == 0)
11707 mips_opts.nobopt = 1;
11709 else if (strcmp (name, "mips16") == 0
11710 || strcmp (name, "MIPS-16") == 0)
11711 mips_opts.mips16 = 1;
11712 else if (strcmp (name, "nomips16") == 0
11713 || strcmp (name, "noMIPS-16") == 0)
11714 mips_opts.mips16 = 0;
11715 else if (strcmp (name, "mips3d") == 0)
11716 mips_opts.ase_mips3d = 1;
11717 else if (strcmp (name, "nomips3d") == 0)
11718 mips_opts.ase_mips3d = 0;
11719 else if (strcmp (name, "mdmx") == 0)
11720 mips_opts.ase_mdmx = 1;
11721 else if (strcmp (name, "nomdmx") == 0)
11722 mips_opts.ase_mdmx = 0;
11723 else if (strncmp (name, "mips", 4) == 0)
11727 /* Permit the user to change the ISA on the fly. Needless to
11728 say, misuse can cause serious problems. */
11729 isa = atoi (name + 4);
11733 mips_opts.gp32 = file_mips_gp32;
11734 mips_opts.fp32 = file_mips_fp32;
11735 mips_opts.abi = file_mips_abi;
11740 mips_opts.gp32 = 1;
11741 mips_opts.fp32 = 1;
11747 /* Loosen ABI register width restriction. */
11748 if (mips_opts.abi == O32_ABI)
11749 mips_opts.abi = NO_ABI;
11750 mips_opts.gp32 = 0;
11751 mips_opts.fp32 = 0;
11754 as_bad (_("unknown ISA level %s"), name + 4);
11760 case 0: mips_opts.isa = file_mips_isa; break;
11761 case 1: mips_opts.isa = ISA_MIPS1; break;
11762 case 2: mips_opts.isa = ISA_MIPS2; break;
11763 case 3: mips_opts.isa = ISA_MIPS3; break;
11764 case 4: mips_opts.isa = ISA_MIPS4; break;
11765 case 5: mips_opts.isa = ISA_MIPS5; break;
11766 case 32: mips_opts.isa = ISA_MIPS32; break;
11767 case 64: mips_opts.isa = ISA_MIPS64; break;
11768 default: as_bad (_("unknown ISA level %s"), name + 4); break;
11771 else if (strcmp (name, "autoextend") == 0)
11772 mips_opts.noautoextend = 0;
11773 else if (strcmp (name, "noautoextend") == 0)
11774 mips_opts.noautoextend = 1;
11775 else if (strcmp (name, "push") == 0)
11777 struct mips_option_stack *s;
11779 s = (struct mips_option_stack *) xmalloc (sizeof *s);
11780 s->next = mips_opts_stack;
11781 s->options = mips_opts;
11782 mips_opts_stack = s;
11784 else if (strcmp (name, "pop") == 0)
11786 struct mips_option_stack *s;
11788 s = mips_opts_stack;
11790 as_bad (_(".set pop with no .set push"));
11793 /* If we're changing the reorder mode we need to handle
11794 delay slots correctly. */
11795 if (s->options.noreorder && ! mips_opts.noreorder)
11796 mips_emit_delays (true);
11797 else if (! s->options.noreorder && mips_opts.noreorder)
11799 if (prev_nop_frag != NULL)
11801 prev_nop_frag->fr_fix -= (prev_nop_frag_holds
11802 * (mips_opts.mips16 ? 2 : 4));
11803 prev_nop_frag = NULL;
11807 mips_opts = s->options;
11808 mips_opts_stack = s->next;
11814 as_warn (_("Tried to set unrecognized symbol: %s\n"), name);
11816 *input_line_pointer = ch;
11817 demand_empty_rest_of_line ();
11820 /* Handle the .abicalls pseudo-op. I believe this is equivalent to
11821 .option pic2. It means to generate SVR4 PIC calls. */
11824 s_abicalls (ignore)
11825 int ignore ATTRIBUTE_UNUSED;
11827 mips_pic = SVR4_PIC;
11828 if (USE_GLOBAL_POINTER_OPT)
11830 if (g_switch_seen && g_switch_value != 0)
11831 as_warn (_("-G may not be used with SVR4 PIC code"));
11832 g_switch_value = 0;
11834 bfd_set_gp_size (stdoutput, 0);
11835 demand_empty_rest_of_line ();
11838 /* Handle the .cpload pseudo-op. This is used when generating SVR4
11839 PIC code. It sets the $gp register for the function based on the
11840 function address, which is in the register named in the argument.
11841 This uses a relocation against _gp_disp, which is handled specially
11842 by the linker. The result is:
11843 lui $gp,%hi(_gp_disp)
11844 addiu $gp,$gp,%lo(_gp_disp)
11845 addu $gp,$gp,.cpload argument
11846 The .cpload argument is normally $25 == $t9. */
11850 int ignore ATTRIBUTE_UNUSED;
11855 /* If we are not generating SVR4 PIC code, or if this is NewABI code,
11856 .cpload is ignored. */
11857 if (mips_pic != SVR4_PIC || HAVE_NEWABI)
11863 /* .cpload should be in a .set noreorder section. */
11864 if (mips_opts.noreorder == 0)
11865 as_warn (_(".cpload not in noreorder section"));
11867 ex.X_op = O_symbol;
11868 ex.X_add_symbol = symbol_find_or_make ("_gp_disp");
11869 ex.X_op_symbol = NULL;
11870 ex.X_add_number = 0;
11872 /* In ELF, this symbol is implicitly an STT_OBJECT symbol. */
11873 symbol_get_bfdsym (ex.X_add_symbol)->flags |= BSF_OBJECT;
11875 macro_build_lui (NULL, &icnt, &ex, mips_gp_register);
11876 macro_build ((char *) NULL, &icnt, &ex, "addiu", "t,r,j",
11877 mips_gp_register, mips_gp_register, (int) BFD_RELOC_LO16);
11879 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "addu", "d,v,t",
11880 mips_gp_register, mips_gp_register, tc_get_register (0));
11882 demand_empty_rest_of_line ();
11885 /* Handle the .cpsetup pseudo-op defined for NewABI PIC code. The syntax is:
11886 .cpsetup $reg1, offset|$reg2, label
11888 If offset is given, this results in:
11889 sd $gp, offset($sp)
11890 lui $gp, %hi(%neg(%gp_rel(label)))
11891 addiu $gp, $gp, %lo(%neg(%gp_rel(label)))
11892 daddu $gp, $gp, $reg1
11894 If $reg2 is given, this results in:
11895 daddu $reg2, $gp, $0
11896 lui $gp, %hi(%neg(%gp_rel(label)))
11897 addiu $gp, $gp, %lo(%neg(%gp_rel(label)))
11898 daddu $gp, $gp, $reg1
11899 $reg1 is normally $25 == $t9. */
11902 int ignore ATTRIBUTE_UNUSED;
11904 expressionS ex_off;
11905 expressionS ex_sym;
11910 /* If we are not generating SVR4 PIC code, .cpsetup is ignored.
11911 We also need NewABI support. */
11912 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
11918 reg1 = tc_get_register (0);
11919 SKIP_WHITESPACE ();
11920 if (*input_line_pointer != ',')
11922 as_bad (_("missing argument separator ',' for .cpsetup"));
11926 ++input_line_pointer;
11927 SKIP_WHITESPACE ();
11928 if (*input_line_pointer == '$')
11930 mips_cpreturn_register = tc_get_register (0);
11931 mips_cpreturn_offset = -1;
11935 mips_cpreturn_offset = get_absolute_expression ();
11936 mips_cpreturn_register = -1;
11938 SKIP_WHITESPACE ();
11939 if (*input_line_pointer != ',')
11941 as_bad (_("missing argument separator ',' for .cpsetup"));
11945 ++input_line_pointer;
11946 SKIP_WHITESPACE ();
11947 sym = input_line_pointer;
11948 while (ISALNUM (*input_line_pointer))
11949 ++input_line_pointer;
11950 *input_line_pointer = 0;
11952 ex_sym.X_op = O_symbol;
11953 ex_sym.X_add_symbol = symbol_find_or_make (sym);
11954 ex_sym.X_op_symbol = NULL;
11955 ex_sym.X_add_number = 0;
11957 if (mips_cpreturn_register == -1)
11959 ex_off.X_op = O_constant;
11960 ex_off.X_add_symbol = NULL;
11961 ex_off.X_op_symbol = NULL;
11962 ex_off.X_add_number = mips_cpreturn_offset;
11964 macro_build ((char *) NULL, &icnt, &ex_off, "sd", "t,o(b)",
11965 mips_gp_register, (int) BFD_RELOC_LO16, SP);
11968 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "daddu",
11969 "d,v,t", mips_cpreturn_register, mips_gp_register, 0);
11971 macro_build ((char *) NULL, &icnt, &ex_sym, "lui", "t,u", mips_gp_register,
11972 (int) BFD_RELOC_GPREL16);
11973 fix_new (frag_now, prev_insn_where, 0, NULL, 0, 0, BFD_RELOC_MIPS_SUB);
11974 fix_new (frag_now, prev_insn_where, 0, NULL, 0, 0, BFD_RELOC_HI16_S);
11975 macro_build ((char *) NULL, &icnt, &ex_sym, "addiu", "t,r,j",
11976 mips_gp_register, mips_gp_register, (int) BFD_RELOC_GPREL16);
11977 fix_new (frag_now, prev_insn_where, 0, NULL, 0, 0, BFD_RELOC_MIPS_SUB);
11978 fix_new (frag_now, prev_insn_where, 0, NULL, 0, 0, BFD_RELOC_LO16);
11979 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
11980 HAVE_64BIT_ADDRESSES ? "daddu" : "addu", "d,v,t",
11981 mips_gp_register, mips_gp_register, reg1);
11983 demand_empty_rest_of_line ();
11988 int ignore ATTRIBUTE_UNUSED;
11990 /* If we are not generating SVR4 PIC code, or if this is not NewABI code,
11991 .cplocal is ignored. */
11992 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
11998 mips_gp_register = tc_get_register (0);
11999 demand_empty_rest_of_line ();
12002 /* Handle the .cprestore pseudo-op. This stores $gp into a given
12003 offset from $sp. The offset is remembered, and after making a PIC
12004 call $gp is restored from that location. */
12007 s_cprestore (ignore)
12008 int ignore ATTRIBUTE_UNUSED;
12013 /* If we are not generating SVR4 PIC code, or if this is NewABI code,
12014 .cprestore is ignored. */
12015 if (mips_pic != SVR4_PIC || HAVE_NEWABI)
12021 mips_cprestore_offset = get_absolute_expression ();
12022 mips_cprestore_valid = 1;
12024 ex.X_op = O_constant;
12025 ex.X_add_symbol = NULL;
12026 ex.X_op_symbol = NULL;
12027 ex.X_add_number = mips_cprestore_offset;
12029 macro_build ((char *) NULL, &icnt, &ex, HAVE_32BIT_ADDRESSES ? "sw" : "sd",
12030 "t,o(b)", mips_gp_register, (int) BFD_RELOC_LO16, SP);
12032 demand_empty_rest_of_line ();
12035 /* Handle the .cpreturn pseudo-op defined for NewABI PIC code. If an offset
12036 was given in the preceeding .gpsetup, it results in:
12037 ld $gp, offset($sp)
12039 If a register $reg2 was given there, it results in:
12040 daddiu $gp, $gp, $reg2
12043 s_cpreturn (ignore)
12044 int ignore ATTRIBUTE_UNUSED;
12049 /* If we are not generating SVR4 PIC code, .cpreturn is ignored.
12050 We also need NewABI support. */
12051 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
12057 if (mips_cpreturn_register == -1)
12059 ex.X_op = O_constant;
12060 ex.X_add_symbol = NULL;
12061 ex.X_op_symbol = NULL;
12062 ex.X_add_number = mips_cpreturn_offset;
12064 macro_build ((char *) NULL, &icnt, &ex, "ld", "t,o(b)",
12065 mips_gp_register, (int) BFD_RELOC_LO16, SP);
12068 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "daddu",
12069 "d,v,t", mips_gp_register, mips_cpreturn_register, 0);
12071 demand_empty_rest_of_line ();
12074 /* Handle the .gpvalue pseudo-op. This is used when generating NewABI PIC
12075 code. It sets the offset to use in gp_rel relocations. */
12079 int ignore ATTRIBUTE_UNUSED;
12081 /* If we are not generating SVR4 PIC code, .gpvalue is ignored.
12082 We also need NewABI support. */
12083 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
12089 mips_gprel_offset = get_absolute_expression ();
12091 demand_empty_rest_of_line ();
12094 /* Handle the .gpword pseudo-op. This is used when generating PIC
12095 code. It generates a 32 bit GP relative reloc. */
12099 int ignore ATTRIBUTE_UNUSED;
12105 /* When not generating PIC code, this is treated as .word. */
12106 if (mips_pic != SVR4_PIC)
12112 label = insn_labels != NULL ? insn_labels->label : NULL;
12113 mips_emit_delays (true);
12115 mips_align (2, 0, label);
12116 mips_clear_insn_labels ();
12120 if (ex.X_op != O_symbol || ex.X_add_number != 0)
12122 as_bad (_("Unsupported use of .gpword"));
12123 ignore_rest_of_line ();
12127 md_number_to_chars (p, (valueT) 0, 4);
12128 fix_new_exp (frag_now, p - frag_now->fr_literal, 4, &ex, false,
12129 BFD_RELOC_GPREL32);
12131 demand_empty_rest_of_line ();
12134 /* Handle the .cpadd pseudo-op. This is used when dealing with switch
12135 tables in SVR4 PIC code. */
12139 int ignore ATTRIBUTE_UNUSED;
12144 /* This is ignored when not generating SVR4 PIC code or if this is NewABI
12146 if (mips_pic != SVR4_PIC || HAVE_NEWABI)
12152 /* Add $gp to the register named as an argument. */
12153 reg = tc_get_register (0);
12154 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
12155 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
12156 "d,v,t", reg, reg, mips_gp_register);
12158 demand_empty_rest_of_line ();
12161 /* Handle the .insn pseudo-op. This marks instruction labels in
12162 mips16 mode. This permits the linker to handle them specially,
12163 such as generating jalx instructions when needed. We also make
12164 them odd for the duration of the assembly, in order to generate the
12165 right sort of code. We will make them even in the adjust_symtab
12166 routine, while leaving them marked. This is convenient for the
12167 debugger and the disassembler. The linker knows to make them odd
12172 int ignore ATTRIBUTE_UNUSED;
12174 mips16_mark_labels ();
12176 demand_empty_rest_of_line ();
12179 /* Handle a .stabn directive. We need these in order to mark a label
12180 as being a mips16 text label correctly. Sometimes the compiler
12181 will emit a label, followed by a .stabn, and then switch sections.
12182 If the label and .stabn are in mips16 mode, then the label is
12183 really a mips16 text label. */
12190 mips16_mark_labels ();
12195 /* Handle the .weakext pseudo-op as defined in Kane and Heinrich.
12199 s_mips_weakext (ignore)
12200 int ignore ATTRIBUTE_UNUSED;
12207 name = input_line_pointer;
12208 c = get_symbol_end ();
12209 symbolP = symbol_find_or_make (name);
12210 S_SET_WEAK (symbolP);
12211 *input_line_pointer = c;
12213 SKIP_WHITESPACE ();
12215 if (! is_end_of_line[(unsigned char) *input_line_pointer])
12217 if (S_IS_DEFINED (symbolP))
12219 as_bad ("ignoring attempt to redefine symbol %s",
12220 S_GET_NAME (symbolP));
12221 ignore_rest_of_line ();
12225 if (*input_line_pointer == ',')
12227 ++input_line_pointer;
12228 SKIP_WHITESPACE ();
12232 if (exp.X_op != O_symbol)
12234 as_bad ("bad .weakext directive");
12235 ignore_rest_of_line ();
12238 symbol_set_value_expression (symbolP, &exp);
12241 demand_empty_rest_of_line ();
12244 /* Parse a register string into a number. Called from the ECOFF code
12245 to parse .frame. The argument is non-zero if this is the frame
12246 register, so that we can record it in mips_frame_reg. */
12249 tc_get_register (frame)
12254 SKIP_WHITESPACE ();
12255 if (*input_line_pointer++ != '$')
12257 as_warn (_("expected `$'"));
12260 else if (ISDIGIT (*input_line_pointer))
12262 reg = get_absolute_expression ();
12263 if (reg < 0 || reg >= 32)
12265 as_warn (_("Bad register number"));
12271 if (strncmp (input_line_pointer, "ra", 2) == 0)
12274 input_line_pointer += 2;
12276 else if (strncmp (input_line_pointer, "fp", 2) == 0)
12279 input_line_pointer += 2;
12281 else if (strncmp (input_line_pointer, "sp", 2) == 0)
12284 input_line_pointer += 2;
12286 else if (strncmp (input_line_pointer, "gp", 2) == 0)
12289 input_line_pointer += 2;
12291 else if (strncmp (input_line_pointer, "at", 2) == 0)
12294 input_line_pointer += 2;
12296 else if (strncmp (input_line_pointer, "kt0", 3) == 0)
12299 input_line_pointer += 3;
12301 else if (strncmp (input_line_pointer, "kt1", 3) == 0)
12304 input_line_pointer += 3;
12306 else if (strncmp (input_line_pointer, "zero", 4) == 0)
12309 input_line_pointer += 4;
12313 as_warn (_("Unrecognized register name"));
12315 while (ISALNUM(*input_line_pointer))
12316 input_line_pointer++;
12321 mips_frame_reg = reg != 0 ? reg : SP;
12322 mips_frame_reg_valid = 1;
12323 mips_cprestore_valid = 0;
12329 md_section_align (seg, addr)
12333 int align = bfd_get_section_alignment (stdoutput, seg);
12336 /* We don't need to align ELF sections to the full alignment.
12337 However, Irix 5 may prefer that we align them at least to a 16
12338 byte boundary. We don't bother to align the sections if we are
12339 targeted for an embedded system. */
12340 if (strcmp (TARGET_OS, "elf") == 0)
12346 return ((addr + (1 << align) - 1) & (-1 << align));
12349 /* Utility routine, called from above as well. If called while the
12350 input file is still being read, it's only an approximation. (For
12351 example, a symbol may later become defined which appeared to be
12352 undefined earlier.) */
12355 nopic_need_relax (sym, before_relaxing)
12357 int before_relaxing;
12362 if (USE_GLOBAL_POINTER_OPT && g_switch_value > 0)
12364 const char *symname;
12367 /* Find out whether this symbol can be referenced off the $gp
12368 register. It can be if it is smaller than the -G size or if
12369 it is in the .sdata or .sbss section. Certain symbols can
12370 not be referenced off the $gp, although it appears as though
12372 symname = S_GET_NAME (sym);
12373 if (symname != (const char *) NULL
12374 && (strcmp (symname, "eprol") == 0
12375 || strcmp (symname, "etext") == 0
12376 || strcmp (symname, "_gp") == 0
12377 || strcmp (symname, "edata") == 0
12378 || strcmp (symname, "_fbss") == 0
12379 || strcmp (symname, "_fdata") == 0
12380 || strcmp (symname, "_ftext") == 0
12381 || strcmp (symname, "end") == 0
12382 || strcmp (symname, "_gp_disp") == 0))
12384 else if ((! S_IS_DEFINED (sym) || S_IS_COMMON (sym))
12386 #ifndef NO_ECOFF_DEBUGGING
12387 || (symbol_get_obj (sym)->ecoff_extern_size != 0
12388 && (symbol_get_obj (sym)->ecoff_extern_size
12389 <= g_switch_value))
12391 /* We must defer this decision until after the whole
12392 file has been read, since there might be a .extern
12393 after the first use of this symbol. */
12394 || (before_relaxing
12395 #ifndef NO_ECOFF_DEBUGGING
12396 && symbol_get_obj (sym)->ecoff_extern_size == 0
12398 && S_GET_VALUE (sym) == 0)
12399 || (S_GET_VALUE (sym) != 0
12400 && S_GET_VALUE (sym) <= g_switch_value)))
12404 const char *segname;
12406 segname = segment_name (S_GET_SEGMENT (sym));
12407 assert (strcmp (segname, ".lit8") != 0
12408 && strcmp (segname, ".lit4") != 0);
12409 change = (strcmp (segname, ".sdata") != 0
12410 && strcmp (segname, ".sbss") != 0
12411 && strncmp (segname, ".sdata.", 7) != 0
12412 && strncmp (segname, ".gnu.linkonce.s.", 16) != 0);
12417 /* We are not optimizing for the $gp register. */
12421 /* Given a mips16 variant frag FRAGP, return non-zero if it needs an
12422 extended opcode. SEC is the section the frag is in. */
12425 mips16_extended_frag (fragp, sec, stretch)
12431 register const struct mips16_immed_operand *op;
12433 int mintiny, maxtiny;
12437 if (RELAX_MIPS16_USER_SMALL (fragp->fr_subtype))
12439 if (RELAX_MIPS16_USER_EXT (fragp->fr_subtype))
12442 type = RELAX_MIPS16_TYPE (fragp->fr_subtype);
12443 op = mips16_immed_operands;
12444 while (op->type != type)
12447 assert (op < mips16_immed_operands + MIPS16_NUM_IMMED);
12452 if (type == '<' || type == '>' || type == '[' || type == ']')
12455 maxtiny = 1 << op->nbits;
12460 maxtiny = (1 << op->nbits) - 1;
12465 mintiny = - (1 << (op->nbits - 1));
12466 maxtiny = (1 << (op->nbits - 1)) - 1;
12469 sym_frag = symbol_get_frag (fragp->fr_symbol);
12470 val = S_GET_VALUE (fragp->fr_symbol);
12471 symsec = S_GET_SEGMENT (fragp->fr_symbol);
12477 /* We won't have the section when we are called from
12478 mips_relax_frag. However, we will always have been called
12479 from md_estimate_size_before_relax first. If this is a
12480 branch to a different section, we mark it as such. If SEC is
12481 NULL, and the frag is not marked, then it must be a branch to
12482 the same section. */
12485 if (RELAX_MIPS16_LONG_BRANCH (fragp->fr_subtype))
12490 /* Must have been called from md_estimate_size_before_relax. */
12493 fragp->fr_subtype =
12494 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
12496 /* FIXME: We should support this, and let the linker
12497 catch branches and loads that are out of range. */
12498 as_bad_where (fragp->fr_file, fragp->fr_line,
12499 _("unsupported PC relative reference to different section"));
12503 if (fragp != sym_frag && sym_frag->fr_address == 0)
12504 /* Assume non-extended on the first relaxation pass.
12505 The address we have calculated will be bogus if this is
12506 a forward branch to another frag, as the forward frag
12507 will have fr_address == 0. */
12511 /* In this case, we know for sure that the symbol fragment is in
12512 the same section. If the relax_marker of the symbol fragment
12513 differs from the relax_marker of this fragment, we have not
12514 yet adjusted the symbol fragment fr_address. We want to add
12515 in STRETCH in order to get a better estimate of the address.
12516 This particularly matters because of the shift bits. */
12518 && sym_frag->relax_marker != fragp->relax_marker)
12522 /* Adjust stretch for any alignment frag. Note that if have
12523 been expanding the earlier code, the symbol may be
12524 defined in what appears to be an earlier frag. FIXME:
12525 This doesn't handle the fr_subtype field, which specifies
12526 a maximum number of bytes to skip when doing an
12528 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
12530 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
12533 stretch = - ((- stretch)
12534 & ~ ((1 << (int) f->fr_offset) - 1));
12536 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
12545 addr = fragp->fr_address + fragp->fr_fix;
12547 /* The base address rules are complicated. The base address of
12548 a branch is the following instruction. The base address of a
12549 PC relative load or add is the instruction itself, but if it
12550 is in a delay slot (in which case it can not be extended) use
12551 the address of the instruction whose delay slot it is in. */
12552 if (type == 'p' || type == 'q')
12556 /* If we are currently assuming that this frag should be
12557 extended, then, the current address is two bytes
12559 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
12562 /* Ignore the low bit in the target, since it will be set
12563 for a text label. */
12564 if ((val & 1) != 0)
12567 else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype))
12569 else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype))
12572 val -= addr & ~ ((1 << op->shift) - 1);
12574 /* Branch offsets have an implicit 0 in the lowest bit. */
12575 if (type == 'p' || type == 'q')
12578 /* If any of the shifted bits are set, we must use an extended
12579 opcode. If the address depends on the size of this
12580 instruction, this can lead to a loop, so we arrange to always
12581 use an extended opcode. We only check this when we are in
12582 the main relaxation loop, when SEC is NULL. */
12583 if ((val & ((1 << op->shift) - 1)) != 0 && sec == NULL)
12585 fragp->fr_subtype =
12586 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
12590 /* If we are about to mark a frag as extended because the value
12591 is precisely maxtiny + 1, then there is a chance of an
12592 infinite loop as in the following code:
12597 In this case when the la is extended, foo is 0x3fc bytes
12598 away, so the la can be shrunk, but then foo is 0x400 away, so
12599 the la must be extended. To avoid this loop, we mark the
12600 frag as extended if it was small, and is about to become
12601 extended with a value of maxtiny + 1. */
12602 if (val == ((maxtiny + 1) << op->shift)
12603 && ! RELAX_MIPS16_EXTENDED (fragp->fr_subtype)
12606 fragp->fr_subtype =
12607 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
12611 else if (symsec != absolute_section && sec != NULL)
12612 as_bad_where (fragp->fr_file, fragp->fr_line, _("unsupported relocation"));
12614 if ((val & ((1 << op->shift) - 1)) != 0
12615 || val < (mintiny << op->shift)
12616 || val > (maxtiny << op->shift))
12622 /* Estimate the size of a frag before relaxing. Unless this is the
12623 mips16, we are not really relaxing here, and the final size is
12624 encoded in the subtype information. For the mips16, we have to
12625 decide whether we are using an extended opcode or not. */
12628 md_estimate_size_before_relax (fragp, segtype)
12633 boolean linkonce = false;
12635 if (RELAX_MIPS16_P (fragp->fr_subtype))
12636 /* We don't want to modify the EXTENDED bit here; it might get us
12637 into infinite loops. We change it only in mips_relax_frag(). */
12638 return (RELAX_MIPS16_EXTENDED (fragp->fr_subtype) ? 4 : 2);
12640 if (mips_pic == NO_PIC)
12642 change = nopic_need_relax (fragp->fr_symbol, 0);
12644 else if (mips_pic == SVR4_PIC)
12649 sym = fragp->fr_symbol;
12651 /* Handle the case of a symbol equated to another symbol. */
12652 while (symbol_equated_reloc_p (sym))
12656 /* It's possible to get a loop here in a badly written
12658 n = symbol_get_value_expression (sym)->X_add_symbol;
12664 symsec = S_GET_SEGMENT (sym);
12666 /* duplicate the test for LINK_ONCE sections as in adjust_reloc_syms */
12667 if (symsec != segtype && ! S_IS_LOCAL (sym))
12669 if ((bfd_get_section_flags (stdoutput, symsec) & SEC_LINK_ONCE)
12673 /* The GNU toolchain uses an extension for ELF: a section
12674 beginning with the magic string .gnu.linkonce is a linkonce
12676 if (strncmp (segment_name (symsec), ".gnu.linkonce",
12677 sizeof ".gnu.linkonce" - 1) == 0)
12681 /* This must duplicate the test in adjust_reloc_syms. */
12682 change = (symsec != &bfd_und_section
12683 && symsec != &bfd_abs_section
12684 && ! bfd_is_com_section (symsec)
12687 /* A global or weak symbol is treated as external. */
12688 && (OUTPUT_FLAVOR != bfd_target_elf_flavour
12689 || (! S_IS_WEAK (sym)
12690 && (! S_IS_EXTERN (sym) || mips_pic == EMBEDDED_PIC)))
12699 /* Record the offset to the first reloc in the fr_opcode field.
12700 This lets md_convert_frag and tc_gen_reloc know that the code
12701 must be expanded. */
12702 fragp->fr_opcode = (fragp->fr_literal
12704 - RELAX_OLD (fragp->fr_subtype)
12705 + RELAX_RELOC1 (fragp->fr_subtype));
12706 /* FIXME: This really needs as_warn_where. */
12707 if (RELAX_WARN (fragp->fr_subtype))
12708 as_warn (_("AT used after \".set noat\" or macro used after "
12709 "\".set nomacro\""));
12711 return RELAX_NEW (fragp->fr_subtype) - RELAX_OLD (fragp->fr_subtype);
12717 /* This is called to see whether a reloc against a defined symbol
12718 should be converted into a reloc against a section. Don't adjust
12719 MIPS16 jump relocations, so we don't have to worry about the format
12720 of the offset in the .o file. Don't adjust relocations against
12721 mips16 symbols, so that the linker can find them if it needs to set
12725 mips_fix_adjustable (fixp)
12729 /* Prevent all adjustments to global symbols. */
12730 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
12731 && mips_pic != EMBEDDED_PIC
12732 && (S_IS_EXTERN (fixp->fx_addsy) || S_IS_WEAK (fixp->fx_addsy)))
12735 if (fixp->fx_r_type == BFD_RELOC_MIPS16_JMP)
12737 if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT
12738 || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
12740 if (fixp->fx_addsy == NULL)
12743 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
12744 && S_GET_OTHER (fixp->fx_addsy) == STO_MIPS16
12745 && fixp->fx_subsy == NULL)
12751 /* Translate internal representation of relocation info to BFD target
12755 tc_gen_reloc (section, fixp)
12756 asection *section ATTRIBUTE_UNUSED;
12759 static arelent *retval[4];
12761 bfd_reloc_code_real_type code;
12763 reloc = retval[0] = (arelent *) xmalloc (sizeof (arelent));
12766 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
12767 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
12768 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
12770 if (mips_pic == EMBEDDED_PIC
12771 && SWITCH_TABLE (fixp))
12773 /* For a switch table entry we use a special reloc. The addend
12774 is actually the difference between the reloc address and the
12776 reloc->addend = reloc->address - S_GET_VALUE (fixp->fx_subsy);
12777 if (OUTPUT_FLAVOR != bfd_target_ecoff_flavour)
12778 as_fatal (_("Double check fx_r_type in tc-mips.c:tc_gen_reloc"));
12779 fixp->fx_r_type = BFD_RELOC_GPREL32;
12781 else if (fixp->fx_r_type == BFD_RELOC_PCREL_LO16)
12783 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
12784 reloc->addend = fixp->fx_addnumber;
12787 /* We use a special addend for an internal RELLO reloc. */
12788 if (symbol_section_p (fixp->fx_addsy))
12789 reloc->addend = reloc->address - S_GET_VALUE (fixp->fx_subsy);
12791 reloc->addend = fixp->fx_addnumber + reloc->address;
12794 else if (fixp->fx_r_type == BFD_RELOC_PCREL_HI16_S)
12796 assert (fixp->fx_next != NULL
12797 && fixp->fx_next->fx_r_type == BFD_RELOC_PCREL_LO16);
12799 /* The reloc is relative to the RELLO; adjust the addend
12801 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
12802 reloc->addend = fixp->fx_next->fx_addnumber;
12805 /* We use a special addend for an internal RELHI reloc. */
12806 if (symbol_section_p (fixp->fx_addsy))
12807 reloc->addend = (fixp->fx_next->fx_frag->fr_address
12808 + fixp->fx_next->fx_where
12809 - S_GET_VALUE (fixp->fx_subsy));
12811 reloc->addend = (fixp->fx_addnumber
12812 + fixp->fx_next->fx_frag->fr_address
12813 + fixp->fx_next->fx_where);
12816 else if (fixp->fx_pcrel == 0 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
12817 reloc->addend = fixp->fx_addnumber;
12820 if (OUTPUT_FLAVOR != bfd_target_aout_flavour)
12821 /* A gruesome hack which is a result of the gruesome gas reloc
12823 reloc->addend = reloc->address;
12825 reloc->addend = -reloc->address;
12828 /* If this is a variant frag, we may need to adjust the existing
12829 reloc and generate a new one. */
12830 if (fixp->fx_frag->fr_opcode != NULL
12831 && (fixp->fx_r_type == BFD_RELOC_GPREL16
12832 || fixp->fx_r_type == BFD_RELOC_MIPS_GOT16
12833 || fixp->fx_r_type == BFD_RELOC_MIPS_CALL16
12834 || fixp->fx_r_type == BFD_RELOC_MIPS_GOT_HI16
12835 || fixp->fx_r_type == BFD_RELOC_MIPS_GOT_LO16
12836 || fixp->fx_r_type == BFD_RELOC_MIPS_CALL_HI16
12837 || fixp->fx_r_type == BFD_RELOC_MIPS_CALL_LO16)
12842 assert (! RELAX_MIPS16_P (fixp->fx_frag->fr_subtype));
12844 /* If this is not the last reloc in this frag, then we have two
12845 GPREL relocs, or a GOT_HI16/GOT_LO16 pair, or a
12846 CALL_HI16/CALL_LO16, both of which are being replaced. Let
12847 the second one handle all of them. */
12848 if (fixp->fx_next != NULL
12849 && fixp->fx_frag == fixp->fx_next->fx_frag)
12851 assert ((fixp->fx_r_type == BFD_RELOC_GPREL16
12852 && fixp->fx_next->fx_r_type == BFD_RELOC_GPREL16)
12853 || (fixp->fx_r_type == BFD_RELOC_MIPS_GOT_HI16
12854 && (fixp->fx_next->fx_r_type
12855 == BFD_RELOC_MIPS_GOT_LO16))
12856 || (fixp->fx_r_type == BFD_RELOC_MIPS_CALL_HI16
12857 && (fixp->fx_next->fx_r_type
12858 == BFD_RELOC_MIPS_CALL_LO16)));
12863 fixp->fx_where = fixp->fx_frag->fr_opcode - fixp->fx_frag->fr_literal;
12864 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
12865 reloc2 = retval[1] = (arelent *) xmalloc (sizeof (arelent));
12867 reloc2->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
12868 *reloc2->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
12869 reloc2->address = (reloc->address
12870 + (RELAX_RELOC2 (fixp->fx_frag->fr_subtype)
12871 - RELAX_RELOC1 (fixp->fx_frag->fr_subtype)));
12872 reloc2->addend = fixp->fx_addnumber;
12873 reloc2->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_LO16);
12874 assert (reloc2->howto != NULL);
12876 if (RELAX_RELOC3 (fixp->fx_frag->fr_subtype))
12880 reloc3 = retval[2] = (arelent *) xmalloc (sizeof (arelent));
12883 reloc3->address += 4;
12886 if (mips_pic == NO_PIC)
12888 assert (fixp->fx_r_type == BFD_RELOC_GPREL16);
12889 fixp->fx_r_type = BFD_RELOC_HI16_S;
12891 else if (mips_pic == SVR4_PIC)
12893 switch (fixp->fx_r_type)
12897 case BFD_RELOC_MIPS_GOT16:
12899 case BFD_RELOC_MIPS_CALL16:
12900 case BFD_RELOC_MIPS_GOT_LO16:
12901 case BFD_RELOC_MIPS_CALL_LO16:
12902 fixp->fx_r_type = BFD_RELOC_MIPS_GOT16;
12910 /* Since the old MIPS ELF ABI uses Rel instead of Rela, encode the vtable
12911 entry to be used in the relocation's section offset. */
12912 if (! HAVE_NEWABI && fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
12914 reloc->address = reloc->addend;
12918 /* Since DIFF_EXPR_OK is defined in tc-mips.h, it is possible that
12919 fixup_segment converted a non-PC relative reloc into a PC
12920 relative reloc. In such a case, we need to convert the reloc
12922 code = fixp->fx_r_type;
12923 if (fixp->fx_pcrel)
12928 code = BFD_RELOC_8_PCREL;
12931 code = BFD_RELOC_16_PCREL;
12934 code = BFD_RELOC_32_PCREL;
12937 code = BFD_RELOC_64_PCREL;
12939 case BFD_RELOC_8_PCREL:
12940 case BFD_RELOC_16_PCREL:
12941 case BFD_RELOC_32_PCREL:
12942 case BFD_RELOC_64_PCREL:
12943 case BFD_RELOC_16_PCREL_S2:
12944 case BFD_RELOC_PCREL_HI16_S:
12945 case BFD_RELOC_PCREL_LO16:
12948 as_bad_where (fixp->fx_file, fixp->fx_line,
12949 _("Cannot make %s relocation PC relative"),
12950 bfd_get_reloc_code_name (code));
12955 /* md_apply_fix3 has a double-subtraction hack to get
12956 bfd_install_relocation to behave nicely. GPREL relocations are
12957 handled correctly without this hack, so undo it here. We can't
12958 stop md_apply_fix3 from subtracting twice in the first place since
12959 the fake addend is required for variant frags above. */
12960 if (fixp->fx_addsy != NULL && OUTPUT_FLAVOR == bfd_target_elf_flavour
12961 && code == BFD_RELOC_GPREL16
12962 && reloc->addend != 0
12963 && mips_need_elf_addend_fixup (fixp))
12964 reloc->addend += S_GET_VALUE (fixp->fx_addsy);
12967 /* To support a PC relative reloc when generating embedded PIC code
12968 for ECOFF, we use a Cygnus extension. We check for that here to
12969 make sure that we don't let such a reloc escape normally. */
12970 if ((OUTPUT_FLAVOR == bfd_target_ecoff_flavour
12971 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
12972 && code == BFD_RELOC_16_PCREL_S2
12973 && mips_pic != EMBEDDED_PIC)
12974 reloc->howto = NULL;
12976 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
12978 if (reloc->howto == NULL)
12980 as_bad_where (fixp->fx_file, fixp->fx_line,
12981 _("Can not represent %s relocation in this object file format"),
12982 bfd_get_reloc_code_name (code));
12989 /* Relax a machine dependent frag. This returns the amount by which
12990 the current size of the frag should change. */
12993 mips_relax_frag (fragp, stretch)
12997 if (! RELAX_MIPS16_P (fragp->fr_subtype))
13000 if (mips16_extended_frag (fragp, NULL, stretch))
13002 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
13004 fragp->fr_subtype = RELAX_MIPS16_MARK_EXTENDED (fragp->fr_subtype);
13009 if (! RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
13011 fragp->fr_subtype = RELAX_MIPS16_CLEAR_EXTENDED (fragp->fr_subtype);
13018 /* Convert a machine dependent frag. */
13021 md_convert_frag (abfd, asec, fragp)
13022 bfd *abfd ATTRIBUTE_UNUSED;
13029 if (RELAX_MIPS16_P (fragp->fr_subtype))
13032 register const struct mips16_immed_operand *op;
13033 boolean small, ext;
13036 unsigned long insn;
13037 boolean use_extend;
13038 unsigned short extend;
13040 type = RELAX_MIPS16_TYPE (fragp->fr_subtype);
13041 op = mips16_immed_operands;
13042 while (op->type != type)
13045 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
13056 resolve_symbol_value (fragp->fr_symbol);
13057 val = S_GET_VALUE (fragp->fr_symbol);
13062 addr = fragp->fr_address + fragp->fr_fix;
13064 /* The rules for the base address of a PC relative reloc are
13065 complicated; see mips16_extended_frag. */
13066 if (type == 'p' || type == 'q')
13071 /* Ignore the low bit in the target, since it will be
13072 set for a text label. */
13073 if ((val & 1) != 0)
13076 else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype))
13078 else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype))
13081 addr &= ~ (addressT) ((1 << op->shift) - 1);
13084 /* Make sure the section winds up with the alignment we have
13087 record_alignment (asec, op->shift);
13091 && (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype)
13092 || RELAX_MIPS16_DSLOT (fragp->fr_subtype)))
13093 as_warn_where (fragp->fr_file, fragp->fr_line,
13094 _("extended instruction in delay slot"));
13096 buf = (bfd_byte *) (fragp->fr_literal + fragp->fr_fix);
13098 if (target_big_endian)
13099 insn = bfd_getb16 (buf);
13101 insn = bfd_getl16 (buf);
13103 mips16_immed (fragp->fr_file, fragp->fr_line, type, val,
13104 RELAX_MIPS16_USER_EXT (fragp->fr_subtype),
13105 small, ext, &insn, &use_extend, &extend);
13109 md_number_to_chars ((char *) buf, 0xf000 | extend, 2);
13110 fragp->fr_fix += 2;
13114 md_number_to_chars ((char *) buf, insn, 2);
13115 fragp->fr_fix += 2;
13120 if (fragp->fr_opcode == NULL)
13123 old = RELAX_OLD (fragp->fr_subtype);
13124 new = RELAX_NEW (fragp->fr_subtype);
13125 fixptr = fragp->fr_literal + fragp->fr_fix;
13128 memcpy (fixptr - old, fixptr, new);
13130 fragp->fr_fix += new - old;
13136 /* This function is called after the relocs have been generated.
13137 We've been storing mips16 text labels as odd. Here we convert them
13138 back to even for the convenience of the debugger. */
13141 mips_frob_file_after_relocs ()
13144 unsigned int count, i;
13146 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
13149 syms = bfd_get_outsymbols (stdoutput);
13150 count = bfd_get_symcount (stdoutput);
13151 for (i = 0; i < count; i++, syms++)
13153 if (elf_symbol (*syms)->internal_elf_sym.st_other == STO_MIPS16
13154 && ((*syms)->value & 1) != 0)
13156 (*syms)->value &= ~1;
13157 /* If the symbol has an odd size, it was probably computed
13158 incorrectly, so adjust that as well. */
13159 if ((elf_symbol (*syms)->internal_elf_sym.st_size & 1) != 0)
13160 ++elf_symbol (*syms)->internal_elf_sym.st_size;
13167 /* This function is called whenever a label is defined. It is used
13168 when handling branch delays; if a branch has a label, we assume we
13169 can not move it. */
13172 mips_define_label (sym)
13175 struct insn_label_list *l;
13177 if (free_insn_labels == NULL)
13178 l = (struct insn_label_list *) xmalloc (sizeof *l);
13181 l = free_insn_labels;
13182 free_insn_labels = l->next;
13186 l->next = insn_labels;
13190 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
13192 /* Some special processing for a MIPS ELF file. */
13195 mips_elf_final_processing ()
13197 /* Write out the register information. */
13198 if (file_mips_abi != N64_ABI)
13202 s.ri_gprmask = mips_gprmask;
13203 s.ri_cprmask[0] = mips_cprmask[0];
13204 s.ri_cprmask[1] = mips_cprmask[1];
13205 s.ri_cprmask[2] = mips_cprmask[2];
13206 s.ri_cprmask[3] = mips_cprmask[3];
13207 /* The gp_value field is set by the MIPS ELF backend. */
13209 bfd_mips_elf32_swap_reginfo_out (stdoutput, &s,
13210 ((Elf32_External_RegInfo *)
13211 mips_regmask_frag));
13215 Elf64_Internal_RegInfo s;
13217 s.ri_gprmask = mips_gprmask;
13219 s.ri_cprmask[0] = mips_cprmask[0];
13220 s.ri_cprmask[1] = mips_cprmask[1];
13221 s.ri_cprmask[2] = mips_cprmask[2];
13222 s.ri_cprmask[3] = mips_cprmask[3];
13223 /* The gp_value field is set by the MIPS ELF backend. */
13225 bfd_mips_elf64_swap_reginfo_out (stdoutput, &s,
13226 ((Elf64_External_RegInfo *)
13227 mips_regmask_frag));
13230 /* Set the MIPS ELF flag bits. FIXME: There should probably be some
13231 sort of BFD interface for this. */
13232 if (mips_any_noreorder)
13233 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_NOREORDER;
13234 if (mips_pic != NO_PIC)
13235 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_PIC;
13237 /* Set MIPS ELF flags for ASEs. */
13238 if (file_ase_mips16)
13239 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ARCH_ASE_M16;
13240 #if 0 /* XXX FIXME */
13241 if (file_ase_mips3d)
13242 elf_elfheader (stdoutput)->e_flags |= ???;
13245 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ARCH_ASE_MDMX;
13247 /* Set the MIPS ELF ABI flags. */
13248 if (file_mips_abi == NO_ABI)
13250 else if (file_mips_abi == O32_ABI)
13251 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O32;
13252 else if (file_mips_abi == O64_ABI)
13253 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O64;
13254 else if (file_mips_abi == EABI_ABI)
13256 /* Set the EABI kind based on the ISA. This isn't really
13257 the best, but then neither is basing the abi on the isa. */
13258 if (ISA_HAS_64BIT_REGS (file_mips_isa))
13259 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI64;
13261 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI32;
13263 else if (file_mips_abi == N32_ABI)
13264 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ABI2;
13266 /* Nothing to do for N64_ABI. */
13268 if (mips_32bitmode)
13269 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_32BITMODE;
13272 #endif /* OBJ_ELF || OBJ_MAYBE_ELF */
13274 typedef struct proc {
13276 unsigned long reg_mask;
13277 unsigned long reg_offset;
13278 unsigned long fpreg_mask;
13279 unsigned long fpreg_offset;
13280 unsigned long frame_offset;
13281 unsigned long frame_reg;
13282 unsigned long pc_reg;
13285 static procS cur_proc;
13286 static procS *cur_proc_ptr;
13287 static int numprocs;
13289 /* Fill in an rs_align_code fragment. */
13292 mips_handle_align (fragp)
13295 if (fragp->fr_type != rs_align_code)
13298 if (mips_opts.mips16)
13300 static const unsigned char be_nop[] = { 0x65, 0x00 };
13301 static const unsigned char le_nop[] = { 0x00, 0x65 };
13306 bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
13307 p = fragp->fr_literal + fragp->fr_fix;
13315 memcpy (p, (target_big_endian ? be_nop : le_nop), 2);
13319 /* For mips32, a nop is a zero, which we trivially get by doing nothing. */
13330 /* check for premature end, nesting errors, etc */
13332 as_warn (_("missing .end at end of assembly"));
13341 if (*input_line_pointer == '-')
13343 ++input_line_pointer;
13346 if (!ISDIGIT (*input_line_pointer))
13347 as_bad (_("expected simple number"));
13348 if (input_line_pointer[0] == '0')
13350 if (input_line_pointer[1] == 'x')
13352 input_line_pointer += 2;
13353 while (ISXDIGIT (*input_line_pointer))
13356 val |= hex_value (*input_line_pointer++);
13358 return negative ? -val : val;
13362 ++input_line_pointer;
13363 while (ISDIGIT (*input_line_pointer))
13366 val |= *input_line_pointer++ - '0';
13368 return negative ? -val : val;
13371 if (!ISDIGIT (*input_line_pointer))
13373 printf (_(" *input_line_pointer == '%c' 0x%02x\n"),
13374 *input_line_pointer, *input_line_pointer);
13375 as_warn (_("invalid number"));
13378 while (ISDIGIT (*input_line_pointer))
13381 val += *input_line_pointer++ - '0';
13383 return negative ? -val : val;
13386 /* The .file directive; just like the usual .file directive, but there
13387 is an initial number which is the ECOFF file index. In the non-ECOFF
13388 case .file implies DWARF-2. */
13392 int x ATTRIBUTE_UNUSED;
13394 static int first_file_directive = 0;
13396 if (ECOFF_DEBUGGING)
13405 filename = dwarf2_directive_file (0);
13407 /* Versions of GCC up to 3.1 start files with a ".file"
13408 directive even for stabs output. Make sure that this
13409 ".file" is handled. Note that you need a version of GCC
13410 after 3.1 in order to support DWARF-2 on MIPS. */
13411 if (filename != NULL && ! first_file_directive)
13413 (void) new_logical_line (filename, -1);
13414 s_app_file_string (filename);
13416 first_file_directive = 1;
13420 /* The .loc directive, implying DWARF-2. */
13424 int x ATTRIBUTE_UNUSED;
13426 if (!ECOFF_DEBUGGING)
13427 dwarf2_directive_loc (0);
13430 /* The .end directive. */
13434 int x ATTRIBUTE_UNUSED;
13439 /* Following functions need their own .frame and .cprestore directives. */
13440 mips_frame_reg_valid = 0;
13441 mips_cprestore_valid = 0;
13443 if (!is_end_of_line[(unsigned char) *input_line_pointer])
13446 demand_empty_rest_of_line ();
13451 #ifdef BFD_ASSEMBLER
13452 if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
13457 if (now_seg != data_section && now_seg != bss_section)
13464 as_warn (_(".end not in text section"));
13468 as_warn (_(".end directive without a preceding .ent directive."));
13469 demand_empty_rest_of_line ();
13475 assert (S_GET_NAME (p));
13476 if (strcmp (S_GET_NAME (p), S_GET_NAME (cur_proc_ptr->isym)))
13477 as_warn (_(".end symbol does not match .ent symbol."));
13479 if (debug_type == DEBUG_STABS)
13480 stabs_generate_asm_endfunc (S_GET_NAME (p),
13484 as_warn (_(".end directive missing or unknown symbol"));
13487 /* Generate a .pdr section. */
13488 if (OUTPUT_FLAVOR == bfd_target_elf_flavour && ! ECOFF_DEBUGGING)
13490 segT saved_seg = now_seg;
13491 subsegT saved_subseg = now_subseg;
13496 dot = frag_now_fix ();
13498 #ifdef md_flush_pending_output
13499 md_flush_pending_output ();
13503 subseg_set (pdr_seg, 0);
13505 /* Write the symbol. */
13506 exp.X_op = O_symbol;
13507 exp.X_add_symbol = p;
13508 exp.X_add_number = 0;
13509 emit_expr (&exp, 4);
13511 fragp = frag_more (7 * 4);
13513 md_number_to_chars (fragp, (valueT) cur_proc_ptr->reg_mask, 4);
13514 md_number_to_chars (fragp + 4, (valueT) cur_proc_ptr->reg_offset, 4);
13515 md_number_to_chars (fragp + 8, (valueT) cur_proc_ptr->fpreg_mask, 4);
13516 md_number_to_chars (fragp + 12, (valueT) cur_proc_ptr->fpreg_offset, 4);
13517 md_number_to_chars (fragp + 16, (valueT) cur_proc_ptr->frame_offset, 4);
13518 md_number_to_chars (fragp + 20, (valueT) cur_proc_ptr->frame_reg, 4);
13519 md_number_to_chars (fragp + 24, (valueT) cur_proc_ptr->pc_reg, 4);
13521 subseg_set (saved_seg, saved_subseg);
13523 #endif /* OBJ_ELF */
13525 cur_proc_ptr = NULL;
13528 /* The .aent and .ent directives. */
13537 symbolP = get_symbol ();
13538 if (*input_line_pointer == ',')
13539 ++input_line_pointer;
13540 SKIP_WHITESPACE ();
13541 if (ISDIGIT (*input_line_pointer)
13542 || *input_line_pointer == '-')
13545 #ifdef BFD_ASSEMBLER
13546 if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
13551 if (now_seg != data_section && now_seg != bss_section)
13558 as_warn (_(".ent or .aent not in text section."));
13560 if (!aent && cur_proc_ptr)
13561 as_warn (_("missing .end"));
13565 /* This function needs its own .frame and .cprestore directives. */
13566 mips_frame_reg_valid = 0;
13567 mips_cprestore_valid = 0;
13569 cur_proc_ptr = &cur_proc;
13570 memset (cur_proc_ptr, '\0', sizeof (procS));
13572 cur_proc_ptr->isym = symbolP;
13574 symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION;
13578 if (debug_type == DEBUG_STABS)
13579 stabs_generate_asm_func (S_GET_NAME (symbolP),
13580 S_GET_NAME (symbolP));
13583 demand_empty_rest_of_line ();
13586 /* The .frame directive. If the mdebug section is present (IRIX 5 native)
13587 then ecoff.c (ecoff_directive_frame) is used. For embedded targets,
13588 s_mips_frame is used so that we can set the PDR information correctly.
13589 We can't use the ecoff routines because they make reference to the ecoff
13590 symbol table (in the mdebug section). */
13593 s_mips_frame (ignore)
13594 int ignore ATTRIBUTE_UNUSED;
13597 if (OUTPUT_FLAVOR == bfd_target_elf_flavour && ! ECOFF_DEBUGGING)
13601 if (cur_proc_ptr == (procS *) NULL)
13603 as_warn (_(".frame outside of .ent"));
13604 demand_empty_rest_of_line ();
13608 cur_proc_ptr->frame_reg = tc_get_register (1);
13610 SKIP_WHITESPACE ();
13611 if (*input_line_pointer++ != ','
13612 || get_absolute_expression_and_terminator (&val) != ',')
13614 as_warn (_("Bad .frame directive"));
13615 --input_line_pointer;
13616 demand_empty_rest_of_line ();
13620 cur_proc_ptr->frame_offset = val;
13621 cur_proc_ptr->pc_reg = tc_get_register (0);
13623 demand_empty_rest_of_line ();
13626 #endif /* OBJ_ELF */
13630 /* The .fmask and .mask directives. If the mdebug section is present
13631 (IRIX 5 native) then ecoff.c (ecoff_directive_mask) is used. For
13632 embedded targets, s_mips_mask is used so that we can set the PDR
13633 information correctly. We can't use the ecoff routines because they
13634 make reference to the ecoff symbol table (in the mdebug section). */
13637 s_mips_mask (reg_type)
13641 if (OUTPUT_FLAVOR == bfd_target_elf_flavour && ! ECOFF_DEBUGGING)
13645 if (cur_proc_ptr == (procS *) NULL)
13647 as_warn (_(".mask/.fmask outside of .ent"));
13648 demand_empty_rest_of_line ();
13652 if (get_absolute_expression_and_terminator (&mask) != ',')
13654 as_warn (_("Bad .mask/.fmask directive"));
13655 --input_line_pointer;
13656 demand_empty_rest_of_line ();
13660 off = get_absolute_expression ();
13662 if (reg_type == 'F')
13664 cur_proc_ptr->fpreg_mask = mask;
13665 cur_proc_ptr->fpreg_offset = off;
13669 cur_proc_ptr->reg_mask = mask;
13670 cur_proc_ptr->reg_offset = off;
13673 demand_empty_rest_of_line ();
13676 #endif /* OBJ_ELF */
13677 s_ignore (reg_type);
13680 /* The .loc directive. */
13691 assert (now_seg == text_section);
13693 lineno = get_number ();
13694 addroff = frag_now_fix ();
13696 symbolP = symbol_new ("", N_SLINE, addroff, frag_now);
13697 S_SET_TYPE (symbolP, N_SLINE);
13698 S_SET_OTHER (symbolP, 0);
13699 S_SET_DESC (symbolP, lineno);
13700 symbolP->sy_segment = now_seg;
13704 /* CPU name/ISA/number mapping table.
13706 Entries are grouped by type. The first matching CPU or ISA entry
13707 gets chosen by CPU or ISA, so it should be the 'canonical' name
13708 for that type. Entries after that within the type are sorted
13711 Case is ignored in comparison, so put the canonical entry in the
13712 appropriate case but everything else in lower case to ease eye pain. */
13713 static const struct mips_cpu_info mips_cpu_info_table[] =
13716 { "MIPS1", 1, ISA_MIPS1, CPU_R3000, },
13717 { "mips", 1, ISA_MIPS1, CPU_R3000, },
13720 { "MIPS2", 1, ISA_MIPS2, CPU_R6000, },
13723 { "MIPS3", 1, ISA_MIPS3, CPU_R4000, },
13726 { "MIPS4", 1, ISA_MIPS4, CPU_R8000, },
13729 { "MIPS5", 1, ISA_MIPS5, CPU_MIPS5, },
13730 { "Generic-MIPS5", 0, ISA_MIPS5, CPU_MIPS5, },
13733 { "MIPS32", 1, ISA_MIPS32, CPU_MIPS32, },
13734 { "mipsisa32", 0, ISA_MIPS32, CPU_MIPS32, },
13735 { "Generic-MIPS32", 0, ISA_MIPS32, CPU_MIPS32, },
13736 { "4kc", 0, ISA_MIPS32, CPU_MIPS32, },
13737 { "4km", 0, ISA_MIPS32, CPU_MIPS32, },
13738 { "4kp", 0, ISA_MIPS32, CPU_MIPS32, },
13740 /* For historical reasons. */
13741 { "MIPS64", 1, ISA_MIPS3, CPU_R4000, },
13744 { "mipsisa64", 1, ISA_MIPS64, CPU_MIPS64, },
13745 { "Generic-MIPS64", 0, ISA_MIPS64, CPU_MIPS64, },
13746 { "5kc", 0, ISA_MIPS64, CPU_MIPS64, },
13747 { "20kc", 0, ISA_MIPS64, CPU_MIPS64, },
13750 { "R2000", 0, ISA_MIPS1, CPU_R2000, },
13751 { "2000", 0, ISA_MIPS1, CPU_R2000, },
13752 { "2k", 0, ISA_MIPS1, CPU_R2000, },
13753 { "r2k", 0, ISA_MIPS1, CPU_R2000, },
13756 { "R3000", 0, ISA_MIPS1, CPU_R3000, },
13757 { "3000", 0, ISA_MIPS1, CPU_R3000, },
13758 { "3k", 0, ISA_MIPS1, CPU_R3000, },
13759 { "r3k", 0, ISA_MIPS1, CPU_R3000, },
13762 { "R3900", 0, ISA_MIPS1, CPU_R3900, },
13763 { "3900", 0, ISA_MIPS1, CPU_R3900, },
13764 { "mipstx39", 0, ISA_MIPS1, CPU_R3900, },
13767 { "R4000", 0, ISA_MIPS3, CPU_R4000, },
13768 { "4000", 0, ISA_MIPS3, CPU_R4000, },
13769 { "4k", 0, ISA_MIPS3, CPU_R4000, }, /* beware */
13770 { "r4k", 0, ISA_MIPS3, CPU_R4000, },
13773 { "R4010", 0, ISA_MIPS2, CPU_R4010, },
13774 { "4010", 0, ISA_MIPS2, CPU_R4010, },
13777 { "R4400", 0, ISA_MIPS3, CPU_R4400, },
13778 { "4400", 0, ISA_MIPS3, CPU_R4400, },
13781 { "R4600", 0, ISA_MIPS3, CPU_R4600, },
13782 { "4600", 0, ISA_MIPS3, CPU_R4600, },
13783 { "mips64orion", 0, ISA_MIPS3, CPU_R4600, },
13784 { "orion", 0, ISA_MIPS3, CPU_R4600, },
13787 { "R4650", 0, ISA_MIPS3, CPU_R4650, },
13788 { "4650", 0, ISA_MIPS3, CPU_R4650, },
13791 { "R6000", 0, ISA_MIPS2, CPU_R6000, },
13792 { "6000", 0, ISA_MIPS2, CPU_R6000, },
13793 { "6k", 0, ISA_MIPS2, CPU_R6000, },
13794 { "r6k", 0, ISA_MIPS2, CPU_R6000, },
13797 { "R8000", 0, ISA_MIPS4, CPU_R8000, },
13798 { "8000", 0, ISA_MIPS4, CPU_R8000, },
13799 { "8k", 0, ISA_MIPS4, CPU_R8000, },
13800 { "r8k", 0, ISA_MIPS4, CPU_R8000, },
13803 { "R10000", 0, ISA_MIPS4, CPU_R10000, },
13804 { "10000", 0, ISA_MIPS4, CPU_R10000, },
13805 { "10k", 0, ISA_MIPS4, CPU_R10000, },
13806 { "r10k", 0, ISA_MIPS4, CPU_R10000, },
13809 { "R12000", 0, ISA_MIPS4, CPU_R12000, },
13810 { "12000", 0, ISA_MIPS4, CPU_R12000, },
13811 { "12k", 0, ISA_MIPS4, CPU_R12000, },
13812 { "r12k", 0, ISA_MIPS4, CPU_R12000, },
13815 { "VR4100", 0, ISA_MIPS3, CPU_VR4100, },
13816 { "4100", 0, ISA_MIPS3, CPU_VR4100, },
13817 { "mips64vr4100", 0, ISA_MIPS3, CPU_VR4100, },
13818 { "r4100", 0, ISA_MIPS3, CPU_VR4100, },
13821 { "VR4111", 0, ISA_MIPS3, CPU_R4111, },
13822 { "4111", 0, ISA_MIPS3, CPU_R4111, },
13823 { "mips64vr4111", 0, ISA_MIPS3, CPU_R4111, },
13824 { "r4111", 0, ISA_MIPS3, CPU_R4111, },
13827 { "VR4300", 0, ISA_MIPS3, CPU_R4300, },
13828 { "4300", 0, ISA_MIPS3, CPU_R4300, },
13829 { "mips64vr4300", 0, ISA_MIPS3, CPU_R4300, },
13830 { "r4300", 0, ISA_MIPS3, CPU_R4300, },
13833 { "VR5000", 0, ISA_MIPS4, CPU_R5000, },
13834 { "5000", 0, ISA_MIPS4, CPU_R5000, },
13835 { "5k", 0, ISA_MIPS4, CPU_R5000, },
13836 { "mips64vr5000", 0, ISA_MIPS4, CPU_R5000, },
13837 { "r5000", 0, ISA_MIPS4, CPU_R5000, },
13838 { "r5200", 0, ISA_MIPS4, CPU_R5000, },
13839 { "rm5200", 0, ISA_MIPS4, CPU_R5000, },
13840 { "r5230", 0, ISA_MIPS4, CPU_R5000, },
13841 { "rm5230", 0, ISA_MIPS4, CPU_R5000, },
13842 { "r5231", 0, ISA_MIPS4, CPU_R5000, },
13843 { "rm5231", 0, ISA_MIPS4, CPU_R5000, },
13844 { "r5261", 0, ISA_MIPS4, CPU_R5000, },
13845 { "rm5261", 0, ISA_MIPS4, CPU_R5000, },
13846 { "r5721", 0, ISA_MIPS4, CPU_R5000, },
13847 { "rm5721", 0, ISA_MIPS4, CPU_R5000, },
13848 { "r5k", 0, ISA_MIPS4, CPU_R5000, },
13849 { "r7000", 0, ISA_MIPS4, CPU_R5000, },
13851 /* Broadcom SB-1 CPU */
13852 { "SB-1", 0, ISA_MIPS64, CPU_SB1, },
13853 { "sb-1250", 0, ISA_MIPS64, CPU_SB1, },
13854 { "sb1", 0, ISA_MIPS64, CPU_SB1, },
13855 { "sb1250", 0, ISA_MIPS64, CPU_SB1, },
13858 { NULL, 0, 0, 0, },
13861 static const struct mips_cpu_info *
13862 mips_cpu_info_from_name (name)
13867 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
13868 if (strcasecmp (name, mips_cpu_info_table[i].name) == 0)
13869 return (&mips_cpu_info_table[i]);
13874 static const struct mips_cpu_info *
13875 mips_cpu_info_from_isa (isa)
13880 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
13881 if (mips_cpu_info_table[i].is_isa
13882 && isa == mips_cpu_info_table[i].isa)
13883 return (&mips_cpu_info_table[i]);
13888 static const struct mips_cpu_info *
13889 mips_cpu_info_from_cpu (cpu)
13894 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
13895 if (!mips_cpu_info_table[i].is_isa
13896 && cpu == mips_cpu_info_table[i].cpu)
13897 return (&mips_cpu_info_table[i]);