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"
42 #define DBG(x) printf x
48 /* Clean up namespace so we can include obj-elf.h too. */
49 static int mips_output_flavor PARAMS ((void));
50 static int mips_output_flavor () { return OUTPUT_FLAVOR; }
51 #undef OBJ_PROCESS_STAB
58 #undef obj_frob_file_after_relocs
59 #undef obj_frob_symbol
61 #undef obj_sec_sym_ok_for_reloc
62 #undef OBJ_COPY_SYMBOL_ATTRIBUTES
65 /* Fix any of them that we actually care about. */
67 #define OUTPUT_FLAVOR mips_output_flavor()
74 #ifndef ECOFF_DEBUGGING
75 #define NO_ECOFF_DEBUGGING
76 #define ECOFF_DEBUGGING 0
81 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
82 static char *mips_regmask_frag;
88 #define PIC_CALL_REG 25
96 #define ILLEGAL_REG (32)
98 /* Allow override of standard little-endian ECOFF format. */
100 #ifndef ECOFF_LITTLE_FORMAT
101 #define ECOFF_LITTLE_FORMAT "ecoff-littlemips"
104 extern int target_big_endian;
106 /* The name of the readonly data section. */
107 #define RDATA_SECTION_NAME (OUTPUT_FLAVOR == bfd_target_aout_flavour \
109 : OUTPUT_FLAVOR == bfd_target_ecoff_flavour \
111 : OUTPUT_FLAVOR == bfd_target_coff_flavour \
113 : OUTPUT_FLAVOR == bfd_target_elf_flavour \
117 /* The ABI to use. */
128 /* MIPS ABI we are using for this output file. */
129 static enum mips_abi_level file_mips_abi = NO_ABI;
131 /* This is the set of options which may be modified by the .set
132 pseudo-op. We use a struct so that .set push and .set pop are more
135 struct mips_set_options
137 /* MIPS ISA (Instruction Set Architecture) level. This is set to -1
138 if it has not been initialized. Changed by `.set mipsN', and the
139 -mipsN command line option, and the default CPU. */
141 /* Enabled Application Specific Extensions (ASEs). These are set to -1
142 if they have not been initialized. Changed by `.set <asename>', by
143 command line options, and based on the default architecture. */
146 /* Whether we are assembling for the mips16 processor. 0 if we are
147 not, 1 if we are, and -1 if the value has not been initialized.
148 Changed by `.set mips16' and `.set nomips16', and the -mips16 and
149 -nomips16 command line options, and the default CPU. */
151 /* Non-zero if we should not reorder instructions. Changed by `.set
152 reorder' and `.set noreorder'. */
154 /* Non-zero if we should not permit the $at ($1) register to be used
155 in instructions. Changed by `.set at' and `.set noat'. */
157 /* Non-zero if we should warn when a macro instruction expands into
158 more than one machine instruction. Changed by `.set nomacro' and
160 int warn_about_macros;
161 /* Non-zero if we should not move instructions. Changed by `.set
162 move', `.set volatile', `.set nomove', and `.set novolatile'. */
164 /* Non-zero if we should not optimize branches by moving the target
165 of the branch into the delay slot. Actually, we don't perform
166 this optimization anyhow. Changed by `.set bopt' and `.set
169 /* Non-zero if we should not autoextend mips16 instructions.
170 Changed by `.set autoextend' and `.set noautoextend'. */
172 /* Restrict general purpose registers and floating point registers
173 to 32 bit. This is initially determined when -mgp32 or -mfp32
174 is passed but can changed if the assembler code uses .set mipsN. */
177 /* The ABI currently in use. This is changed by .set mipsN to loosen
178 restrictions and doesn't affect the whole file. */
179 enum mips_abi_level abi;
182 /* True if -mgp32 was passed. */
183 static int file_mips_gp32 = -1;
185 /* True if -mfp32 was passed. */
186 static int file_mips_fp32 = -1;
188 /* This is the struct we use to hold the current set of options. Note
189 that we must set the isa field to ISA_UNKNOWN and the mips16 field to
190 -1 to indicate that they have not been initialized. */
192 static struct mips_set_options mips_opts =
194 ISA_UNKNOWN, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, NO_ABI
197 /* These variables are filled in with the masks of registers used.
198 The object format code reads them and puts them in the appropriate
200 unsigned long mips_gprmask;
201 unsigned long mips_cprmask[4];
203 /* MIPS ISA we are using for this output file. */
204 static int file_mips_isa = ISA_UNKNOWN;
206 /* True if -mips3d was passed or implied by arguments passed on the
207 command line (e.g., by -march). */
208 static int file_ase_mips3d;
210 /* True if -mdmx was passed or implied by arguments passed on the
211 command line (e.g., by -march). */
212 static int file_ase_mdmx;
214 /* The argument of the -mcpu= flag. Historical for code generation. */
215 static int mips_cpu = CPU_UNKNOWN;
217 /* The argument of the -march= flag. The architecture we are assembling. */
218 static int mips_arch = CPU_UNKNOWN;
220 /* The argument of the -mtune= flag. The architecture for which we
222 static int mips_tune = CPU_UNKNOWN;
224 /* Whether we should mark the file EABI64 or EABI32. */
225 static int mips_eabi64 = 0;
227 /* If they asked for mips1 or mips2 and a cpu that is
228 mips3 or greater, then mark the object file 32BITMODE. */
229 static int mips_32bitmode = 0;
231 /* Some ISA's have delay slots for instructions which read or write
232 from a coprocessor (eg. mips1-mips3); some don't (eg mips4).
233 Return true if instructions marked INSN_LOAD_COPROC_DELAY,
234 INSN_COPROC_MOVE_DELAY, or INSN_WRITE_COND_CODE actually have a
235 delay slot in this ISA. The uses of this macro assume that any
236 ISA that has delay slots for one of these, has them for all. They
237 also assume that ISAs which don't have delays for these insns, don't
238 have delays for the INSN_LOAD_MEMORY_DELAY instructions either. */
239 #define ISA_HAS_COPROC_DELAYS(ISA) ( \
241 || (ISA) == ISA_MIPS2 \
242 || (ISA) == ISA_MIPS3 \
245 /* Return true if ISA supports 64 bit gp register instructions. */
246 #define ISA_HAS_64BIT_REGS(ISA) ( \
248 || (ISA) == ISA_MIPS4 \
249 || (ISA) == ISA_MIPS5 \
250 || (ISA) == ISA_MIPS64 \
253 #define HAVE_32BIT_GPRS \
255 || mips_opts.abi == O32_ABI \
256 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
258 #define HAVE_32BIT_FPRS \
260 || mips_opts.abi == O32_ABI \
261 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
263 #define HAVE_64BIT_GPRS (! HAVE_32BIT_GPRS)
264 #define HAVE_64BIT_FPRS (! HAVE_32BIT_FPRS)
266 #define HAVE_NEWABI (mips_opts.abi == N32_ABI || mips_opts.abi == N64_ABI)
268 #define HAVE_64BIT_OBJECTS (mips_opts.abi == N64_ABI)
270 /* We can only have 64bit addresses if the object file format
272 #define HAVE_32BIT_ADDRESSES \
274 || ((bfd_arch_bits_per_address (stdoutput) == 32 \
275 || ! HAVE_64BIT_OBJECTS) \
276 && mips_pic != EMBEDDED_PIC))
278 #define HAVE_64BIT_ADDRESSES (! HAVE_32BIT_ADDRESSES)
280 /* Return true if the given CPU supports the MIPS3D ASE. */
281 #define CPU_HAS_MIPS3D(cpu) ((cpu) == CPU_SB1 \
284 /* Return true if the given CPU supports the MDMX ASE. */
285 #define CPU_HAS_MDMX(cpu) (0 \
288 /* Whether the processor uses hardware interlocks to protect
289 reads from the HI and LO registers, and thus does not
290 require nops to be inserted. */
292 #define hilo_interlocks (mips_arch == CPU_R4010 \
293 || mips_arch == CPU_SB1 \
296 /* Whether the processor uses hardware interlocks to protect reads
297 from the GPRs, and thus does not require nops to be inserted. */
298 #define gpr_interlocks \
299 (mips_opts.isa != ISA_MIPS1 \
300 || mips_arch == CPU_R3900)
302 /* As with other "interlocks" this is used by hardware that has FP
303 (co-processor) interlocks. */
304 /* Itbl support may require additional care here. */
305 #define cop_interlocks (mips_arch == CPU_R4300 \
306 || mips_arch == CPU_SB1 \
309 /* Is this a mfhi or mflo instruction? */
310 #define MF_HILO_INSN(PINFO) \
311 ((PINFO & INSN_READ_HI) || (PINFO & INSN_READ_LO))
313 /* MIPS PIC level. */
317 /* Do not generate PIC code. */
320 /* Generate PIC code as in Irix 4. This is not implemented, and I'm
321 not sure what it is supposed to do. */
324 /* Generate PIC code as in the SVR4 MIPS ABI. */
327 /* Generate PIC code without using a global offset table: the data
328 segment has a maximum size of 64K, all data references are off
329 the $gp register, and all text references are PC relative. This
330 is used on some embedded systems. */
334 static enum mips_pic_level mips_pic;
336 /* Warn about all NOPS that the assembler generates. */
337 static int warn_nops = 0;
339 /* 1 if we should generate 32 bit offsets from the $gp register in
340 SVR4_PIC mode. Currently has no meaning in other modes. */
341 static int mips_big_got = 0;
343 /* 1 if trap instructions should used for overflow rather than break
345 static int mips_trap = 0;
347 /* 1 if double width floating point constants should not be constructed
348 by assembling two single width halves into two single width floating
349 point registers which just happen to alias the double width destination
350 register. On some architectures this aliasing can be disabled by a bit
351 in the status register, and the setting of this bit cannot be determined
352 automatically at assemble time. */
353 static int mips_disable_float_construction;
355 /* Non-zero if any .set noreorder directives were used. */
357 static int mips_any_noreorder;
359 /* Non-zero if nops should be inserted when the register referenced in
360 an mfhi/mflo instruction is read in the next two instructions. */
361 static int mips_7000_hilo_fix;
363 /* The size of the small data section. */
364 static unsigned int g_switch_value = 8;
365 /* Whether the -G option was used. */
366 static int g_switch_seen = 0;
371 /* If we can determine in advance that GP optimization won't be
372 possible, we can skip the relaxation stuff that tries to produce
373 GP-relative references. This makes delay slot optimization work
376 This function can only provide a guess, but it seems to work for
377 gcc output. It needs to guess right for gcc, otherwise gcc
378 will put what it thinks is a GP-relative instruction in a branch
381 I don't know if a fix is needed for the SVR4_PIC mode. I've only
382 fixed it for the non-PIC mode. KR 95/04/07 */
383 static int nopic_need_relax PARAMS ((symbolS *, int));
385 /* handle of the OPCODE hash table */
386 static struct hash_control *op_hash = NULL;
388 /* The opcode hash table we use for the mips16. */
389 static struct hash_control *mips16_op_hash = NULL;
391 /* This array holds the chars that always start a comment. If the
392 pre-processor is disabled, these aren't very useful */
393 const char comment_chars[] = "#";
395 /* This array holds the chars that only start a comment at the beginning of
396 a line. If the line seems to have the form '# 123 filename'
397 .line and .file directives will appear in the pre-processed output */
398 /* Note that input_file.c hand checks for '#' at the beginning of the
399 first line of the input file. This is because the compiler outputs
400 #NO_APP at the beginning of its output. */
401 /* Also note that C style comments are always supported. */
402 const char line_comment_chars[] = "#";
404 /* This array holds machine specific line separator characters. */
405 const char line_separator_chars[] = ";";
407 /* Chars that can be used to separate mant from exp in floating point nums */
408 const char EXP_CHARS[] = "eE";
410 /* Chars that mean this number is a floating point constant */
413 const char FLT_CHARS[] = "rRsSfFdDxXpP";
415 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
416 changed in read.c . Ideally it shouldn't have to know about it at all,
417 but nothing is ideal around here.
420 static char *insn_error;
422 static int auto_align = 1;
424 /* When outputting SVR4 PIC code, the assembler needs to know the
425 offset in the stack frame from which to restore the $gp register.
426 This is set by the .cprestore pseudo-op, and saved in this
428 static offsetT mips_cprestore_offset = -1;
430 /* Similiar for NewABI PIC code, where $gp is callee-saved. NewABI has some
431 more optimizations, it can use a register value instead of a memory-saved
432 offset and even an other register than $gp as global pointer. */
433 static offsetT mips_cpreturn_offset = -1;
434 static int mips_cpreturn_register = -1;
435 static int mips_gp_register = GP;
436 static int mips_gprel_offset = 0;
438 /* Whether mips_cprestore_offset has been set in the current function
439 (or whether it has already been warned about, if not). */
440 static int mips_cprestore_valid = 0;
442 /* This is the register which holds the stack frame, as set by the
443 .frame pseudo-op. This is needed to implement .cprestore. */
444 static int mips_frame_reg = SP;
446 /* Whether mips_frame_reg has been set in the current function
447 (or whether it has already been warned about, if not). */
448 static int mips_frame_reg_valid = 0;
450 /* To output NOP instructions correctly, we need to keep information
451 about the previous two instructions. */
453 /* Whether we are optimizing. The default value of 2 means to remove
454 unneeded NOPs and swap branch instructions when possible. A value
455 of 1 means to not swap branches. A value of 0 means to always
457 static int mips_optimize = 2;
459 /* Debugging level. -g sets this to 2. -gN sets this to N. -g0 is
460 equivalent to seeing no -g option at all. */
461 static int mips_debug = 0;
463 /* The previous instruction. */
464 static struct mips_cl_insn prev_insn;
466 /* The instruction before prev_insn. */
467 static struct mips_cl_insn prev_prev_insn;
469 /* If we don't want information for prev_insn or prev_prev_insn, we
470 point the insn_mo field at this dummy integer. */
471 static const struct mips_opcode dummy_opcode = { NULL, NULL, 0, 0, 0, 0 };
473 /* Non-zero if prev_insn is valid. */
474 static int prev_insn_valid;
476 /* The frag for the previous instruction. */
477 static struct frag *prev_insn_frag;
479 /* The offset into prev_insn_frag for the previous instruction. */
480 static long prev_insn_where;
482 /* The reloc type for the previous instruction, if any. */
483 static bfd_reloc_code_real_type prev_insn_reloc_type[3];
485 /* The reloc for the previous instruction, if any. */
486 static fixS *prev_insn_fixp[3];
488 /* Non-zero if the previous instruction was in a delay slot. */
489 static int prev_insn_is_delay_slot;
491 /* Non-zero if the previous instruction was in a .set noreorder. */
492 static int prev_insn_unreordered;
494 /* Non-zero if the previous instruction uses an extend opcode (if
496 static int prev_insn_extended;
498 /* Non-zero if the previous previous instruction was in a .set
500 static int prev_prev_insn_unreordered;
502 /* If this is set, it points to a frag holding nop instructions which
503 were inserted before the start of a noreorder section. If those
504 nops turn out to be unnecessary, the size of the frag can be
506 static fragS *prev_nop_frag;
508 /* The number of nop instructions we created in prev_nop_frag. */
509 static int prev_nop_frag_holds;
511 /* The number of nop instructions that we know we need in
513 static int prev_nop_frag_required;
515 /* The number of instructions we've seen since prev_nop_frag. */
516 static int prev_nop_frag_since;
518 /* For ECOFF and ELF, relocations against symbols are done in two
519 parts, with a HI relocation and a LO relocation. Each relocation
520 has only 16 bits of space to store an addend. This means that in
521 order for the linker to handle carries correctly, it must be able
522 to locate both the HI and the LO relocation. This means that the
523 relocations must appear in order in the relocation table.
525 In order to implement this, we keep track of each unmatched HI
526 relocation. We then sort them so that they immediately precede the
527 corresponding LO relocation. */
532 struct mips_hi_fixup *next;
535 /* The section this fixup is in. */
539 /* The list of unmatched HI relocs. */
541 static struct mips_hi_fixup *mips_hi_fixup_list;
543 /* Map normal MIPS register numbers to mips16 register numbers. */
545 #define X ILLEGAL_REG
546 static const int mips32_to_16_reg_map[] =
548 X, X, 2, 3, 4, 5, 6, 7,
549 X, X, X, X, X, X, X, X,
550 0, 1, X, X, X, X, X, X,
551 X, X, X, X, X, X, X, X
555 /* Map mips16 register numbers to normal MIPS register numbers. */
557 static const unsigned int mips16_to_32_reg_map[] =
559 16, 17, 2, 3, 4, 5, 6, 7
562 /* Since the MIPS does not have multiple forms of PC relative
563 instructions, we do not have to do relaxing as is done on other
564 platforms. However, we do have to handle GP relative addressing
565 correctly, which turns out to be a similar problem.
567 Every macro that refers to a symbol can occur in (at least) two
568 forms, one with GP relative addressing and one without. For
569 example, loading a global variable into a register generally uses
570 a macro instruction like this:
572 If i can be addressed off the GP register (this is true if it is in
573 the .sbss or .sdata section, or if it is known to be smaller than
574 the -G argument) this will generate the following instruction:
576 This instruction will use a GPREL reloc. If i can not be addressed
577 off the GP register, the following instruction sequence will be used:
580 In this case the first instruction will have a HI16 reloc, and the
581 second reloc will have a LO16 reloc. Both relocs will be against
584 The issue here is that we may not know whether i is GP addressable
585 until after we see the instruction that uses it. Therefore, we
586 want to be able to choose the final instruction sequence only at
587 the end of the assembly. This is similar to the way other
588 platforms choose the size of a PC relative instruction only at the
591 When generating position independent code we do not use GP
592 addressing in quite the same way, but the issue still arises as
593 external symbols and local symbols must be handled differently.
595 We handle these issues by actually generating both possible
596 instruction sequences. The longer one is put in a frag_var with
597 type rs_machine_dependent. We encode what to do with the frag in
598 the subtype field. We encode (1) the number of existing bytes to
599 replace, (2) the number of new bytes to use, (3) the offset from
600 the start of the existing bytes to the first reloc we must generate
601 (that is, the offset is applied from the start of the existing
602 bytes after they are replaced by the new bytes, if any), (4) the
603 offset from the start of the existing bytes to the second reloc,
604 (5) whether a third reloc is needed (the third reloc is always four
605 bytes after the second reloc), and (6) whether to warn if this
606 variant is used (this is sometimes needed if .set nomacro or .set
607 noat is in effect). All these numbers are reasonably small.
609 Generating two instruction sequences must be handled carefully to
610 ensure that delay slots are handled correctly. Fortunately, there
611 are a limited number of cases. When the second instruction
612 sequence is generated, append_insn is directed to maintain the
613 existing delay slot information, so it continues to apply to any
614 code after the second instruction sequence. This means that the
615 second instruction sequence must not impose any requirements not
616 required by the first instruction sequence.
618 These variant frags are then handled in functions called by the
619 machine independent code. md_estimate_size_before_relax returns
620 the final size of the frag. md_convert_frag sets up the final form
621 of the frag. tc_gen_reloc adjust the first reloc and adds a second
623 #define RELAX_ENCODE(old, new, reloc1, reloc2, reloc3, warn) \
627 | (((reloc1) + 64) << 9) \
628 | (((reloc2) + 64) << 2) \
629 | ((reloc3) ? (1 << 1) : 0) \
631 #define RELAX_OLD(i) (((i) >> 23) & 0x7f)
632 #define RELAX_NEW(i) (((i) >> 16) & 0x7f)
633 #define RELAX_RELOC1(i) ((valueT) (((i) >> 9) & 0x7f) - 64)
634 #define RELAX_RELOC2(i) ((valueT) (((i) >> 2) & 0x7f) - 64)
635 #define RELAX_RELOC3(i) (((i) >> 1) & 1)
636 #define RELAX_WARN(i) ((i) & 1)
638 /* For mips16 code, we use an entirely different form of relaxation.
639 mips16 supports two versions of most instructions which take
640 immediate values: a small one which takes some small value, and a
641 larger one which takes a 16 bit value. Since branches also follow
642 this pattern, relaxing these values is required.
644 We can assemble both mips16 and normal MIPS code in a single
645 object. Therefore, we need to support this type of relaxation at
646 the same time that we support the relaxation described above. We
647 use the high bit of the subtype field to distinguish these cases.
649 The information we store for this type of relaxation is the
650 argument code found in the opcode file for this relocation, whether
651 the user explicitly requested a small or extended form, and whether
652 the relocation is in a jump or jal delay slot. That tells us the
653 size of the value, and how it should be stored. We also store
654 whether the fragment is considered to be extended or not. We also
655 store whether this is known to be a branch to a different section,
656 whether we have tried to relax this frag yet, and whether we have
657 ever extended a PC relative fragment because of a shift count. */
658 #define RELAX_MIPS16_ENCODE(type, small, ext, dslot, jal_dslot) \
661 | ((small) ? 0x100 : 0) \
662 | ((ext) ? 0x200 : 0) \
663 | ((dslot) ? 0x400 : 0) \
664 | ((jal_dslot) ? 0x800 : 0))
665 #define RELAX_MIPS16_P(i) (((i) & 0x80000000) != 0)
666 #define RELAX_MIPS16_TYPE(i) ((i) & 0xff)
667 #define RELAX_MIPS16_USER_SMALL(i) (((i) & 0x100) != 0)
668 #define RELAX_MIPS16_USER_EXT(i) (((i) & 0x200) != 0)
669 #define RELAX_MIPS16_DSLOT(i) (((i) & 0x400) != 0)
670 #define RELAX_MIPS16_JAL_DSLOT(i) (((i) & 0x800) != 0)
671 #define RELAX_MIPS16_EXTENDED(i) (((i) & 0x1000) != 0)
672 #define RELAX_MIPS16_MARK_EXTENDED(i) ((i) | 0x1000)
673 #define RELAX_MIPS16_CLEAR_EXTENDED(i) ((i) &~ 0x1000)
674 #define RELAX_MIPS16_LONG_BRANCH(i) (((i) & 0x2000) != 0)
675 #define RELAX_MIPS16_MARK_LONG_BRANCH(i) ((i) | 0x2000)
676 #define RELAX_MIPS16_CLEAR_LONG_BRANCH(i) ((i) &~ 0x2000)
678 /* Prototypes for static functions. */
681 #define internalError() \
682 as_fatal (_("internal Error, line %d, %s"), __LINE__, __FILE__)
684 #define internalError() as_fatal (_("MIPS internal Error"));
687 enum mips_regclass { MIPS_GR_REG, MIPS_FP_REG, MIPS16_REG };
689 static int insn_uses_reg PARAMS ((struct mips_cl_insn *ip,
690 unsigned int reg, enum mips_regclass class));
691 static int reg_needs_delay PARAMS ((unsigned int));
692 static void mips16_mark_labels PARAMS ((void));
693 static void append_insn PARAMS ((char *place,
694 struct mips_cl_insn * ip,
696 bfd_reloc_code_real_type *r,
698 static void mips_no_prev_insn PARAMS ((int));
699 static void mips_emit_delays PARAMS ((boolean));
701 static void macro_build PARAMS ((char *place, int *counter, expressionS * ep,
702 const char *name, const char *fmt,
705 static void macro_build ();
707 static void mips16_macro_build PARAMS ((char *, int *, expressionS *,
708 const char *, const char *,
710 static void macro_build_jalr PARAMS ((int, expressionS *));
711 static void macro_build_lui PARAMS ((char *place, int *counter,
712 expressionS * ep, int regnum));
713 static void set_at PARAMS ((int *counter, int reg, int unsignedp));
714 static void check_absolute_expr PARAMS ((struct mips_cl_insn * ip,
716 static void load_register PARAMS ((int *, int, expressionS *, int));
717 static void load_address PARAMS ((int *, int, expressionS *, int *));
718 static void move_register PARAMS ((int *, int, int));
719 static void macro PARAMS ((struct mips_cl_insn * ip));
720 static void mips16_macro PARAMS ((struct mips_cl_insn * ip));
721 #ifdef LOSING_COMPILER
722 static void macro2 PARAMS ((struct mips_cl_insn * ip));
724 static void mips_ip PARAMS ((char *str, struct mips_cl_insn * ip));
725 static void mips16_ip PARAMS ((char *str, struct mips_cl_insn * ip));
726 static void mips16_immed PARAMS ((char *, unsigned int, int, offsetT, boolean,
727 boolean, boolean, unsigned long *,
728 boolean *, unsigned short *));
729 static int my_getPercentOp PARAMS ((char **, unsigned int *, int *));
730 static int my_getSmallParser PARAMS ((char **, unsigned int *, int *));
731 static int my_getSmallExpression PARAMS ((expressionS *, char *));
732 static void my_getExpression PARAMS ((expressionS *, char *));
734 static int support_64bit_objects PARAMS((void));
736 static symbolS *get_symbol PARAMS ((void));
737 static void mips_align PARAMS ((int to, int fill, symbolS *label));
738 static void s_align PARAMS ((int));
739 static void s_change_sec PARAMS ((int));
740 static void s_cons PARAMS ((int));
741 static void s_float_cons PARAMS ((int));
742 static void s_mips_globl PARAMS ((int));
743 static void s_option PARAMS ((int));
744 static void s_mipsset PARAMS ((int));
745 static void s_abicalls PARAMS ((int));
746 static void s_cpload PARAMS ((int));
747 static void s_cpsetup PARAMS ((int));
748 static void s_cplocal PARAMS ((int));
749 static void s_cprestore PARAMS ((int));
750 static void s_cpreturn PARAMS ((int));
751 static void s_gpvalue PARAMS ((int));
752 static void s_gpword PARAMS ((int));
753 static void s_cpadd PARAMS ((int));
754 static void s_insn PARAMS ((int));
755 static void md_obj_begin PARAMS ((void));
756 static void md_obj_end PARAMS ((void));
757 static long get_number PARAMS ((void));
758 static void s_mips_ent PARAMS ((int));
759 static void s_mips_end PARAMS ((int));
760 static void s_mips_frame PARAMS ((int));
761 static void s_mips_mask PARAMS ((int));
762 static void s_mips_stab PARAMS ((int));
763 static void s_mips_weakext PARAMS ((int));
764 static void s_file PARAMS ((int));
765 static int mips16_extended_frag PARAMS ((fragS *, asection *, long));
766 static const char *mips_isa_to_str PARAMS ((int));
767 static const char *mips_cpu_to_str PARAMS ((int));
768 static int validate_mips_insn PARAMS ((const struct mips_opcode *));
769 static void show PARAMS ((FILE *, char *, int *, int *));
771 static int mips_need_elf_addend_fixup PARAMS ((fixS *));
774 /* Return values of my_getSmallExpression(). */
781 /* Direct relocation creation by %percent_op(). */
800 /* Table and functions used to map between CPU/ISA names, and
801 ISA levels, and CPU numbers. */
805 const char *name; /* CPU or ISA name. */
806 int is_isa; /* Is this an ISA? (If 0, a CPU.) */
807 int isa; /* ISA level. */
808 int cpu; /* CPU number (default CPU if ISA). */
811 static const struct mips_cpu_info *mips_cpu_info_from_name PARAMS ((const char *));
812 static const struct mips_cpu_info *mips_cpu_info_from_isa PARAMS ((int));
813 static const struct mips_cpu_info *mips_cpu_info_from_cpu PARAMS ((int));
817 The following pseudo-ops from the Kane and Heinrich MIPS book
818 should be defined here, but are currently unsupported: .alias,
819 .galive, .gjaldef, .gjrlive, .livereg, .noalias.
821 The following pseudo-ops from the Kane and Heinrich MIPS book are
822 specific to the type of debugging information being generated, and
823 should be defined by the object format: .aent, .begin, .bend,
824 .bgnb, .end, .endb, .ent, .fmask, .frame, .loc, .mask, .verstamp,
827 The following pseudo-ops from the Kane and Heinrich MIPS book are
828 not MIPS CPU specific, but are also not specific to the object file
829 format. This file is probably the best place to define them, but
830 they are not currently supported: .asm0, .endr, .lab, .repeat,
833 static const pseudo_typeS mips_pseudo_table[] =
835 /* MIPS specific pseudo-ops. */
836 {"option", s_option, 0},
837 {"set", s_mipsset, 0},
838 {"rdata", s_change_sec, 'r'},
839 {"sdata", s_change_sec, 's'},
840 {"livereg", s_ignore, 0},
841 {"abicalls", s_abicalls, 0},
842 {"cpload", s_cpload, 0},
843 {"cpsetup", s_cpsetup, 0},
844 {"cplocal", s_cplocal, 0},
845 {"cprestore", s_cprestore, 0},
846 {"cpreturn", s_cpreturn, 0},
847 {"gpvalue", s_gpvalue, 0},
848 {"gpword", s_gpword, 0},
849 {"cpadd", s_cpadd, 0},
852 /* Relatively generic pseudo-ops that happen to be used on MIPS
854 {"asciiz", stringer, 1},
855 {"bss", s_change_sec, 'b'},
858 {"dword", s_cons, 3},
859 {"weakext", s_mips_weakext, 0},
861 /* These pseudo-ops are defined in read.c, but must be overridden
862 here for one reason or another. */
863 {"align", s_align, 0},
865 {"data", s_change_sec, 'd'},
866 {"double", s_float_cons, 'd'},
867 {"float", s_float_cons, 'f'},
868 {"globl", s_mips_globl, 0},
869 {"global", s_mips_globl, 0},
870 {"hword", s_cons, 1},
875 {"short", s_cons, 1},
876 {"single", s_float_cons, 'f'},
877 {"stabn", s_mips_stab, 'n'},
878 {"text", s_change_sec, 't'},
881 #ifdef MIPS_STABS_ELF
882 { "extern", ecoff_directive_extern, 0},
888 static const pseudo_typeS mips_nonecoff_pseudo_table[] =
890 /* These pseudo-ops should be defined by the object file format.
891 However, a.out doesn't support them, so we have versions here. */
892 {"aent", s_mips_ent, 1},
893 {"bgnb", s_ignore, 0},
894 {"end", s_mips_end, 0},
895 {"endb", s_ignore, 0},
896 {"ent", s_mips_ent, 0},
898 {"fmask", s_mips_mask, 'F'},
899 {"frame", s_mips_frame, 0},
900 {"loc", s_ignore, 0},
901 {"mask", s_mips_mask, 'R'},
902 {"verstamp", s_ignore, 0},
906 extern void pop_insert PARAMS ((const pseudo_typeS *));
911 pop_insert (mips_pseudo_table);
912 if (! ECOFF_DEBUGGING)
913 pop_insert (mips_nonecoff_pseudo_table);
916 /* Symbols labelling the current insn. */
918 struct insn_label_list
920 struct insn_label_list *next;
924 static struct insn_label_list *insn_labels;
925 static struct insn_label_list *free_insn_labels;
927 static void mips_clear_insn_labels PARAMS ((void));
930 mips_clear_insn_labels ()
932 register struct insn_label_list **pl;
934 for (pl = &free_insn_labels; *pl != NULL; pl = &(*pl)->next)
940 static char *expr_end;
942 /* Expressions which appear in instructions. These are set by
945 static expressionS imm_expr;
946 static expressionS offset_expr;
948 /* Relocs associated with imm_expr and offset_expr. */
950 static bfd_reloc_code_real_type imm_reloc[3]
951 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
952 static bfd_reloc_code_real_type offset_reloc[3]
953 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
955 /* This is set by mips_ip if imm_reloc is an unmatched HI16_S reloc. */
957 static boolean imm_unmatched_hi;
959 /* These are set by mips16_ip if an explicit extension is used. */
961 static boolean mips16_small, mips16_ext;
963 #ifdef MIPS_STABS_ELF
964 /* The pdr segment for per procedure frame/regmask info */
970 mips_isa_to_str (isa)
973 const struct mips_cpu_info *ci;
976 ci = mips_cpu_info_from_isa (isa);
980 sprintf (s, "ISA#%d", isa);
985 mips_cpu_to_str (cpu)
988 const struct mips_cpu_info *ci;
991 ci = mips_cpu_info_from_cpu (cpu);
995 sprintf (s, "CPU#%d", cpu);
999 /* The default target format to use. */
1002 mips_target_format ()
1004 switch (OUTPUT_FLAVOR)
1006 case bfd_target_aout_flavour:
1007 return target_big_endian ? "a.out-mips-big" : "a.out-mips-little";
1008 case bfd_target_ecoff_flavour:
1009 return target_big_endian ? "ecoff-bigmips" : ECOFF_LITTLE_FORMAT;
1010 case bfd_target_coff_flavour:
1012 case bfd_target_elf_flavour:
1014 /* This is traditional mips */
1015 return (target_big_endian
1016 ? (HAVE_64BIT_OBJECTS ? "elf64-tradbigmips"
1017 : "elf32-tradbigmips")
1018 : (HAVE_64BIT_OBJECTS ? "elf64-tradlittlemips"
1019 : "elf32-tradlittlemips"));
1021 return (target_big_endian
1022 ? (HAVE_64BIT_OBJECTS ? "elf64-bigmips" : "elf32-bigmips")
1023 : (HAVE_64BIT_OBJECTS ? "elf64-littlemips"
1024 : "elf32-littlemips"));
1032 /* This function is called once, at assembler startup time. It should
1033 set up all the tables, etc. that the MD part of the assembler will need. */
1038 register const char *retval = NULL;
1042 if (! bfd_set_arch_mach (stdoutput, bfd_arch_mips, mips_arch))
1043 as_warn (_("Could not set architecture and machine"));
1045 op_hash = hash_new ();
1047 for (i = 0; i < NUMOPCODES;)
1049 const char *name = mips_opcodes[i].name;
1051 retval = hash_insert (op_hash, name, (PTR) &mips_opcodes[i]);
1054 fprintf (stderr, _("internal error: can't hash `%s': %s\n"),
1055 mips_opcodes[i].name, retval);
1056 /* Probably a memory allocation problem? Give up now. */
1057 as_fatal (_("Broken assembler. No assembly attempted."));
1061 if (mips_opcodes[i].pinfo != INSN_MACRO)
1063 if (!validate_mips_insn (&mips_opcodes[i]))
1068 while ((i < NUMOPCODES) && !strcmp (mips_opcodes[i].name, name));
1071 mips16_op_hash = hash_new ();
1074 while (i < bfd_mips16_num_opcodes)
1076 const char *name = mips16_opcodes[i].name;
1078 retval = hash_insert (mips16_op_hash, name, (PTR) &mips16_opcodes[i]);
1080 as_fatal (_("internal: can't hash `%s': %s"),
1081 mips16_opcodes[i].name, retval);
1084 if (mips16_opcodes[i].pinfo != INSN_MACRO
1085 && ((mips16_opcodes[i].match & mips16_opcodes[i].mask)
1086 != mips16_opcodes[i].match))
1088 fprintf (stderr, _("internal error: bad mips16 opcode: %s %s\n"),
1089 mips16_opcodes[i].name, mips16_opcodes[i].args);
1094 while (i < bfd_mips16_num_opcodes
1095 && strcmp (mips16_opcodes[i].name, name) == 0);
1099 as_fatal (_("Broken assembler. No assembly attempted."));
1101 /* We add all the general register names to the symbol table. This
1102 helps us detect invalid uses of them. */
1103 for (i = 0; i < 32; i++)
1107 sprintf (buf, "$%d", i);
1108 symbol_table_insert (symbol_new (buf, reg_section, i,
1109 &zero_address_frag));
1111 symbol_table_insert (symbol_new ("$ra", reg_section, RA,
1112 &zero_address_frag));
1113 symbol_table_insert (symbol_new ("$fp", reg_section, FP,
1114 &zero_address_frag));
1115 symbol_table_insert (symbol_new ("$sp", reg_section, SP,
1116 &zero_address_frag));
1117 symbol_table_insert (symbol_new ("$gp", reg_section, GP,
1118 &zero_address_frag));
1119 symbol_table_insert (symbol_new ("$at", reg_section, AT,
1120 &zero_address_frag));
1121 symbol_table_insert (symbol_new ("$kt0", reg_section, KT0,
1122 &zero_address_frag));
1123 symbol_table_insert (symbol_new ("$kt1", reg_section, KT1,
1124 &zero_address_frag));
1125 symbol_table_insert (symbol_new ("$zero", reg_section, ZERO,
1126 &zero_address_frag));
1127 symbol_table_insert (symbol_new ("$pc", reg_section, -1,
1128 &zero_address_frag));
1130 mips_no_prev_insn (false);
1133 mips_cprmask[0] = 0;
1134 mips_cprmask[1] = 0;
1135 mips_cprmask[2] = 0;
1136 mips_cprmask[3] = 0;
1138 /* set the default alignment for the text section (2**2) */
1139 record_alignment (text_section, 2);
1141 if (USE_GLOBAL_POINTER_OPT)
1142 bfd_set_gp_size (stdoutput, g_switch_value);
1144 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
1146 /* On a native system, sections must be aligned to 16 byte
1147 boundaries. When configured for an embedded ELF target, we
1149 if (strcmp (TARGET_OS, "elf") != 0)
1151 (void) bfd_set_section_alignment (stdoutput, text_section, 4);
1152 (void) bfd_set_section_alignment (stdoutput, data_section, 4);
1153 (void) bfd_set_section_alignment (stdoutput, bss_section, 4);
1156 /* Create a .reginfo section for register masks and a .mdebug
1157 section for debugging information. */
1165 subseg = now_subseg;
1167 /* The ABI says this section should be loaded so that the
1168 running program can access it. However, we don't load it
1169 if we are configured for an embedded target */
1170 flags = SEC_READONLY | SEC_DATA;
1171 if (strcmp (TARGET_OS, "elf") != 0)
1172 flags |= SEC_ALLOC | SEC_LOAD;
1174 if (file_mips_abi != N64_ABI)
1176 sec = subseg_new (".reginfo", (subsegT) 0);
1178 bfd_set_section_flags (stdoutput, sec, flags);
1179 bfd_set_section_alignment (stdoutput, sec, HAVE_NEWABI ? 3 : 2);
1182 mips_regmask_frag = frag_more (sizeof (Elf32_External_RegInfo));
1187 /* The 64-bit ABI uses a .MIPS.options section rather than
1188 .reginfo section. */
1189 sec = subseg_new (".MIPS.options", (subsegT) 0);
1190 bfd_set_section_flags (stdoutput, sec, flags);
1191 bfd_set_section_alignment (stdoutput, sec, 3);
1194 /* Set up the option header. */
1196 Elf_Internal_Options opthdr;
1199 opthdr.kind = ODK_REGINFO;
1200 opthdr.size = (sizeof (Elf_External_Options)
1201 + sizeof (Elf64_External_RegInfo));
1204 f = frag_more (sizeof (Elf_External_Options));
1205 bfd_mips_elf_swap_options_out (stdoutput, &opthdr,
1206 (Elf_External_Options *) f);
1208 mips_regmask_frag = frag_more (sizeof (Elf64_External_RegInfo));
1213 if (ECOFF_DEBUGGING)
1215 sec = subseg_new (".mdebug", (subsegT) 0);
1216 (void) bfd_set_section_flags (stdoutput, sec,
1217 SEC_HAS_CONTENTS | SEC_READONLY);
1218 (void) bfd_set_section_alignment (stdoutput, sec, 2);
1221 #ifdef MIPS_STABS_ELF
1222 pdr_seg = subseg_new (".pdr", (subsegT) 0);
1223 (void) bfd_set_section_flags (stdoutput, pdr_seg,
1224 SEC_READONLY | SEC_RELOC | SEC_DEBUGGING);
1225 (void) bfd_set_section_alignment (stdoutput, pdr_seg, 2);
1228 subseg_set (seg, subseg);
1232 if (! ECOFF_DEBUGGING)
1239 if (! ECOFF_DEBUGGING)
1247 struct mips_cl_insn insn;
1248 bfd_reloc_code_real_type unused_reloc[3]
1249 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
1251 imm_expr.X_op = O_absent;
1252 imm_unmatched_hi = false;
1253 offset_expr.X_op = O_absent;
1254 imm_reloc[0] = BFD_RELOC_UNUSED;
1255 imm_reloc[1] = BFD_RELOC_UNUSED;
1256 imm_reloc[2] = BFD_RELOC_UNUSED;
1257 offset_reloc[0] = BFD_RELOC_UNUSED;
1258 offset_reloc[1] = BFD_RELOC_UNUSED;
1259 offset_reloc[2] = BFD_RELOC_UNUSED;
1261 if (mips_opts.mips16)
1262 mips16_ip (str, &insn);
1265 mips_ip (str, &insn);
1266 DBG ((_("returned from mips_ip(%s) insn_opcode = 0x%x\n"),
1267 str, insn.insn_opcode));
1272 as_bad ("%s `%s'", insn_error, str);
1276 if (insn.insn_mo->pinfo == INSN_MACRO)
1278 if (mips_opts.mips16)
1279 mips16_macro (&insn);
1285 if (imm_expr.X_op != O_absent)
1286 append_insn (NULL, &insn, &imm_expr, imm_reloc, imm_unmatched_hi);
1287 else if (offset_expr.X_op != O_absent)
1288 append_insn (NULL, &insn, &offset_expr, offset_reloc, false);
1290 append_insn (NULL, &insn, NULL, unused_reloc, false);
1294 /* See whether instruction IP reads register REG. CLASS is the type
1298 insn_uses_reg (ip, reg, class)
1299 struct mips_cl_insn *ip;
1301 enum mips_regclass class;
1303 if (class == MIPS16_REG)
1305 assert (mips_opts.mips16);
1306 reg = mips16_to_32_reg_map[reg];
1307 class = MIPS_GR_REG;
1310 /* Don't report on general register ZERO, since it never changes. */
1311 if (class == MIPS_GR_REG && reg == ZERO)
1314 if (class == MIPS_FP_REG)
1316 assert (! mips_opts.mips16);
1317 /* If we are called with either $f0 or $f1, we must check $f0.
1318 This is not optimal, because it will introduce an unnecessary
1319 NOP between "lwc1 $f0" and "swc1 $f1". To fix this we would
1320 need to distinguish reading both $f0 and $f1 or just one of
1321 them. Note that we don't have to check the other way,
1322 because there is no instruction that sets both $f0 and $f1
1323 and requires a delay. */
1324 if ((ip->insn_mo->pinfo & INSN_READ_FPR_S)
1325 && ((((ip->insn_opcode >> OP_SH_FS) & OP_MASK_FS) &~(unsigned)1)
1326 == (reg &~ (unsigned) 1)))
1328 if ((ip->insn_mo->pinfo & INSN_READ_FPR_T)
1329 && ((((ip->insn_opcode >> OP_SH_FT) & OP_MASK_FT) &~(unsigned)1)
1330 == (reg &~ (unsigned) 1)))
1333 else if (! mips_opts.mips16)
1335 if ((ip->insn_mo->pinfo & INSN_READ_GPR_S)
1336 && ((ip->insn_opcode >> OP_SH_RS) & OP_MASK_RS) == reg)
1338 if ((ip->insn_mo->pinfo & INSN_READ_GPR_T)
1339 && ((ip->insn_opcode >> OP_SH_RT) & OP_MASK_RT) == reg)
1344 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_X)
1345 && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_RX)
1346 & MIPS16OP_MASK_RX)]
1349 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_Y)
1350 && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_RY)
1351 & MIPS16OP_MASK_RY)]
1354 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_Z)
1355 && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_MOVE32Z)
1356 & MIPS16OP_MASK_MOVE32Z)]
1359 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_T) && reg == TREG)
1361 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_SP) && reg == SP)
1363 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_31) && reg == RA)
1365 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_GPR_X)
1366 && ((ip->insn_opcode >> MIPS16OP_SH_REGR32)
1367 & MIPS16OP_MASK_REGR32) == reg)
1374 /* This function returns true if modifying a register requires a
1378 reg_needs_delay (reg)
1381 unsigned long prev_pinfo;
1383 prev_pinfo = prev_insn.insn_mo->pinfo;
1384 if (! mips_opts.noreorder
1385 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1386 && ((prev_pinfo & INSN_LOAD_COPROC_DELAY)
1387 || (! gpr_interlocks
1388 && (prev_pinfo & INSN_LOAD_MEMORY_DELAY))))
1390 /* A load from a coprocessor or from memory. All load
1391 delays delay the use of general register rt for one
1392 instruction on the r3000. The r6000 and r4000 use
1394 /* Itbl support may require additional care here. */
1395 know (prev_pinfo & INSN_WRITE_GPR_T);
1396 if (reg == ((prev_insn.insn_opcode >> OP_SH_RT) & OP_MASK_RT))
1403 /* Mark instruction labels in mips16 mode. This permits the linker to
1404 handle them specially, such as generating jalx instructions when
1405 needed. We also make them odd for the duration of the assembly, in
1406 order to generate the right sort of code. We will make them even
1407 in the adjust_symtab routine, while leaving them marked. This is
1408 convenient for the debugger and the disassembler. The linker knows
1409 to make them odd again. */
1412 mips16_mark_labels ()
1414 if (mips_opts.mips16)
1416 struct insn_label_list *l;
1419 for (l = insn_labels; l != NULL; l = l->next)
1422 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
1423 S_SET_OTHER (l->label, STO_MIPS16);
1425 val = S_GET_VALUE (l->label);
1427 S_SET_VALUE (l->label, val + 1);
1432 /* Output an instruction. PLACE is where to put the instruction; if
1433 it is NULL, this uses frag_more to get room. IP is the instruction
1434 information. ADDRESS_EXPR is an operand of the instruction to be
1435 used with RELOC_TYPE. */
1438 append_insn (place, ip, address_expr, reloc_type, unmatched_hi)
1440 struct mips_cl_insn *ip;
1441 expressionS *address_expr;
1442 bfd_reloc_code_real_type *reloc_type;
1443 boolean unmatched_hi;
1445 register unsigned long prev_pinfo, pinfo;
1450 /* Mark instruction labels in mips16 mode. */
1451 mips16_mark_labels ();
1453 prev_pinfo = prev_insn.insn_mo->pinfo;
1454 pinfo = ip->insn_mo->pinfo;
1456 if (place == NULL && (! mips_opts.noreorder || prev_nop_frag != NULL))
1460 /* If the previous insn required any delay slots, see if we need
1461 to insert a NOP or two. There are eight kinds of possible
1462 hazards, of which an instruction can have at most one type.
1463 (1) a load from memory delay
1464 (2) a load from a coprocessor delay
1465 (3) an unconditional branch delay
1466 (4) a conditional branch delay
1467 (5) a move to coprocessor register delay
1468 (6) a load coprocessor register from memory delay
1469 (7) a coprocessor condition code delay
1470 (8) a HI/LO special register delay
1472 There are a lot of optimizations we could do that we don't.
1473 In particular, we do not, in general, reorder instructions.
1474 If you use gcc with optimization, it will reorder
1475 instructions and generally do much more optimization then we
1476 do here; repeating all that work in the assembler would only
1477 benefit hand written assembly code, and does not seem worth
1480 /* This is how a NOP is emitted. */
1481 #define emit_nop() \
1483 ? md_number_to_chars (frag_more (2), 0x6500, 2) \
1484 : md_number_to_chars (frag_more (4), 0, 4))
1486 /* The previous insn might require a delay slot, depending upon
1487 the contents of the current insn. */
1488 if (! mips_opts.mips16
1489 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1490 && (((prev_pinfo & INSN_LOAD_COPROC_DELAY)
1491 && ! cop_interlocks)
1492 || (! gpr_interlocks
1493 && (prev_pinfo & INSN_LOAD_MEMORY_DELAY))))
1495 /* A load from a coprocessor or from memory. All load
1496 delays delay the use of general register rt for one
1497 instruction on the r3000. The r6000 and r4000 use
1499 /* Itbl support may require additional care here. */
1500 know (prev_pinfo & INSN_WRITE_GPR_T);
1501 if (mips_optimize == 0
1502 || insn_uses_reg (ip,
1503 ((prev_insn.insn_opcode >> OP_SH_RT)
1508 else if (! mips_opts.mips16
1509 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1510 && (((prev_pinfo & INSN_COPROC_MOVE_DELAY)
1511 && ! cop_interlocks)
1512 || (mips_opts.isa == ISA_MIPS1
1513 && (prev_pinfo & INSN_COPROC_MEMORY_DELAY))))
1515 /* A generic coprocessor delay. The previous instruction
1516 modified a coprocessor general or control register. If
1517 it modified a control register, we need to avoid any
1518 coprocessor instruction (this is probably not always
1519 required, but it sometimes is). If it modified a general
1520 register, we avoid using that register.
1522 On the r6000 and r4000 loading a coprocessor register
1523 from memory is interlocked, and does not require a delay.
1525 This case is not handled very well. There is no special
1526 knowledge of CP0 handling, and the coprocessors other
1527 than the floating point unit are not distinguished at
1529 /* Itbl support may require additional care here. FIXME!
1530 Need to modify this to include knowledge about
1531 user specified delays! */
1532 if (prev_pinfo & INSN_WRITE_FPR_T)
1534 if (mips_optimize == 0
1535 || insn_uses_reg (ip,
1536 ((prev_insn.insn_opcode >> OP_SH_FT)
1541 else if (prev_pinfo & INSN_WRITE_FPR_S)
1543 if (mips_optimize == 0
1544 || insn_uses_reg (ip,
1545 ((prev_insn.insn_opcode >> OP_SH_FS)
1552 /* We don't know exactly what the previous instruction
1553 does. If the current instruction uses a coprocessor
1554 register, we must insert a NOP. If previous
1555 instruction may set the condition codes, and the
1556 current instruction uses them, we must insert two
1558 /* Itbl support may require additional care here. */
1559 if (mips_optimize == 0
1560 || ((prev_pinfo & INSN_WRITE_COND_CODE)
1561 && (pinfo & INSN_READ_COND_CODE)))
1563 else if (pinfo & INSN_COP)
1567 else if (! mips_opts.mips16
1568 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1569 && (prev_pinfo & INSN_WRITE_COND_CODE)
1570 && ! cop_interlocks)
1572 /* The previous instruction sets the coprocessor condition
1573 codes, but does not require a general coprocessor delay
1574 (this means it is a floating point comparison
1575 instruction). If this instruction uses the condition
1576 codes, we need to insert a single NOP. */
1577 /* Itbl support may require additional care here. */
1578 if (mips_optimize == 0
1579 || (pinfo & INSN_READ_COND_CODE))
1583 /* If we're fixing up mfhi/mflo for the r7000 and the
1584 previous insn was an mfhi/mflo and the current insn
1585 reads the register that the mfhi/mflo wrote to, then
1588 else if (mips_7000_hilo_fix
1589 && MF_HILO_INSN (prev_pinfo)
1590 && insn_uses_reg (ip, ((prev_insn.insn_opcode >> OP_SH_RD)
1597 /* If we're fixing up mfhi/mflo for the r7000 and the
1598 2nd previous insn was an mfhi/mflo and the current insn
1599 reads the register that the mfhi/mflo wrote to, then
1602 else if (mips_7000_hilo_fix
1603 && MF_HILO_INSN (prev_prev_insn.insn_opcode)
1604 && insn_uses_reg (ip, ((prev_prev_insn.insn_opcode >> OP_SH_RD)
1612 else if (prev_pinfo & INSN_READ_LO)
1614 /* The previous instruction reads the LO register; if the
1615 current instruction writes to the LO register, we must
1616 insert two NOPS. Some newer processors have interlocks.
1617 Also the tx39's multiply instructions can be exectuted
1618 immediatly after a read from HI/LO (without the delay),
1619 though the tx39's divide insns still do require the
1621 if (! (hilo_interlocks
1622 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT)))
1623 && (mips_optimize == 0
1624 || (pinfo & INSN_WRITE_LO)))
1626 /* Most mips16 branch insns don't have a delay slot.
1627 If a read from LO is immediately followed by a branch
1628 to a write to LO we have a read followed by a write
1629 less than 2 insns away. We assume the target of
1630 a branch might be a write to LO, and insert a nop
1631 between a read and an immediately following branch. */
1632 else if (mips_opts.mips16
1633 && (mips_optimize == 0
1634 || (pinfo & MIPS16_INSN_BRANCH)))
1637 else if (prev_insn.insn_mo->pinfo & INSN_READ_HI)
1639 /* The previous instruction reads the HI register; if the
1640 current instruction writes to the HI register, we must
1641 insert a NOP. Some newer processors have interlocks.
1642 Also the note tx39's multiply above. */
1643 if (! (hilo_interlocks
1644 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT)))
1645 && (mips_optimize == 0
1646 || (pinfo & INSN_WRITE_HI)))
1648 /* Most mips16 branch insns don't have a delay slot.
1649 If a read from HI is immediately followed by a branch
1650 to a write to HI we have a read followed by a write
1651 less than 2 insns away. We assume the target of
1652 a branch might be a write to HI, and insert a nop
1653 between a read and an immediately following branch. */
1654 else if (mips_opts.mips16
1655 && (mips_optimize == 0
1656 || (pinfo & MIPS16_INSN_BRANCH)))
1660 /* If the previous instruction was in a noreorder section, then
1661 we don't want to insert the nop after all. */
1662 /* Itbl support may require additional care here. */
1663 if (prev_insn_unreordered)
1666 /* There are two cases which require two intervening
1667 instructions: 1) setting the condition codes using a move to
1668 coprocessor instruction which requires a general coprocessor
1669 delay and then reading the condition codes 2) reading the HI
1670 or LO register and then writing to it (except on processors
1671 which have interlocks). If we are not already emitting a NOP
1672 instruction, we must check for these cases compared to the
1673 instruction previous to the previous instruction. */
1674 if ((! mips_opts.mips16
1675 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1676 && (prev_prev_insn.insn_mo->pinfo & INSN_COPROC_MOVE_DELAY)
1677 && (prev_prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE)
1678 && (pinfo & INSN_READ_COND_CODE)
1679 && ! cop_interlocks)
1680 || ((prev_prev_insn.insn_mo->pinfo & INSN_READ_LO)
1681 && (pinfo & INSN_WRITE_LO)
1682 && ! (hilo_interlocks
1683 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT))))
1684 || ((prev_prev_insn.insn_mo->pinfo & INSN_READ_HI)
1685 && (pinfo & INSN_WRITE_HI)
1686 && ! (hilo_interlocks
1687 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT)))))
1692 if (prev_prev_insn_unreordered)
1695 if (prev_prev_nop && nops == 0)
1698 /* If we are being given a nop instruction, don't bother with
1699 one of the nops we would otherwise output. This will only
1700 happen when a nop instruction is used with mips_optimize set
1703 && ! mips_opts.noreorder
1704 && ip->insn_opcode == (unsigned) (mips_opts.mips16 ? 0x6500 : 0))
1707 /* Now emit the right number of NOP instructions. */
1708 if (nops > 0 && ! mips_opts.noreorder)
1711 unsigned long old_frag_offset;
1713 struct insn_label_list *l;
1715 old_frag = frag_now;
1716 old_frag_offset = frag_now_fix ();
1718 for (i = 0; i < nops; i++)
1723 listing_prev_line ();
1724 /* We may be at the start of a variant frag. In case we
1725 are, make sure there is enough space for the frag
1726 after the frags created by listing_prev_line. The
1727 argument to frag_grow here must be at least as large
1728 as the argument to all other calls to frag_grow in
1729 this file. We don't have to worry about being in the
1730 middle of a variant frag, because the variants insert
1731 all needed nop instructions themselves. */
1735 for (l = insn_labels; l != NULL; l = l->next)
1739 assert (S_GET_SEGMENT (l->label) == now_seg);
1740 symbol_set_frag (l->label, frag_now);
1741 val = (valueT) frag_now_fix ();
1742 /* mips16 text labels are stored as odd. */
1743 if (mips_opts.mips16)
1745 S_SET_VALUE (l->label, val);
1748 #ifndef NO_ECOFF_DEBUGGING
1749 if (ECOFF_DEBUGGING)
1750 ecoff_fix_loc (old_frag, old_frag_offset);
1753 else if (prev_nop_frag != NULL)
1755 /* We have a frag holding nops we may be able to remove. If
1756 we don't need any nops, we can decrease the size of
1757 prev_nop_frag by the size of one instruction. If we do
1758 need some nops, we count them in prev_nops_required. */
1759 if (prev_nop_frag_since == 0)
1763 prev_nop_frag->fr_fix -= mips_opts.mips16 ? 2 : 4;
1764 --prev_nop_frag_holds;
1767 prev_nop_frag_required += nops;
1771 if (prev_prev_nop == 0)
1773 prev_nop_frag->fr_fix -= mips_opts.mips16 ? 2 : 4;
1774 --prev_nop_frag_holds;
1777 ++prev_nop_frag_required;
1780 if (prev_nop_frag_holds <= prev_nop_frag_required)
1781 prev_nop_frag = NULL;
1783 ++prev_nop_frag_since;
1785 /* Sanity check: by the time we reach the second instruction
1786 after prev_nop_frag, we should have used up all the nops
1787 one way or another. */
1788 assert (prev_nop_frag_since <= 1 || prev_nop_frag == NULL);
1792 if (*reloc_type > BFD_RELOC_UNUSED)
1794 /* We need to set up a variant frag. */
1795 assert (mips_opts.mips16 && address_expr != NULL);
1796 f = frag_var (rs_machine_dependent, 4, 0,
1797 RELAX_MIPS16_ENCODE (*reloc_type - BFD_RELOC_UNUSED,
1798 mips16_small, mips16_ext,
1800 & INSN_UNCOND_BRANCH_DELAY),
1801 (*prev_insn_reloc_type
1802 == BFD_RELOC_MIPS16_JMP)),
1803 make_expr_symbol (address_expr), 0, NULL);
1805 else if (place != NULL)
1807 else if (mips_opts.mips16
1809 && *reloc_type != BFD_RELOC_MIPS16_JMP)
1811 /* Make sure there is enough room to swap this instruction with
1812 a following jump instruction. */
1818 if (mips_opts.mips16
1819 && mips_opts.noreorder
1820 && (prev_pinfo & INSN_UNCOND_BRANCH_DELAY) != 0)
1821 as_warn (_("extended instruction in delay slot"));
1826 fixp[0] = fixp[1] = fixp[2] = NULL;
1827 if (address_expr != NULL && *reloc_type < BFD_RELOC_UNUSED)
1829 if (address_expr->X_op == O_constant)
1833 switch (*reloc_type)
1836 ip->insn_opcode |= address_expr->X_add_number;
1839 case BFD_RELOC_MIPS_HIGHEST:
1840 tmp = (address_expr->X_add_number + 0x800080008000) >> 16;
1842 ip->insn_opcode |= (tmp >> 16) & 0xffff;
1845 case BFD_RELOC_MIPS_HIGHER:
1846 tmp = (address_expr->X_add_number + 0x80008000) >> 16;
1847 ip->insn_opcode |= (tmp >> 16) & 0xffff;
1850 case BFD_RELOC_HI16_S:
1851 ip->insn_opcode |= ((address_expr->X_add_number + 0x8000)
1855 case BFD_RELOC_HI16:
1856 ip->insn_opcode |= (address_expr->X_add_number >> 16) & 0xffff;
1859 case BFD_RELOC_LO16:
1860 ip->insn_opcode |= address_expr->X_add_number & 0xffff;
1863 case BFD_RELOC_MIPS_JMP:
1864 if ((address_expr->X_add_number & 3) != 0)
1865 as_bad (_("jump to misaligned address (0x%lx)"),
1866 (unsigned long) address_expr->X_add_number);
1867 if (address_expr->X_add_number & ~0xfffffff
1868 || address_expr->X_add_number > 0x7fffffc)
1869 as_bad (_("jump address range overflow (0x%lx)"),
1870 (unsigned long) address_expr->X_add_number);
1871 ip->insn_opcode |= (address_expr->X_add_number >> 2) & 0x3ffffff;
1874 case BFD_RELOC_MIPS16_JMP:
1875 if ((address_expr->X_add_number & 3) != 0)
1876 as_bad (_("jump to misaligned address (0x%lx)"),
1877 (unsigned long) address_expr->X_add_number);
1878 if (address_expr->X_add_number & ~0xfffffff
1879 || address_expr->X_add_number > 0x7fffffc)
1880 as_bad (_("jump address range overflow (0x%lx)"),
1881 (unsigned long) address_expr->X_add_number);
1883 (((address_expr->X_add_number & 0x7c0000) << 3)
1884 | ((address_expr->X_add_number & 0xf800000) >> 7)
1885 | ((address_expr->X_add_number & 0x3fffc) >> 2));
1888 case BFD_RELOC_16_PCREL:
1889 ip->insn_opcode |= address_expr->X_add_number & 0xffff;
1892 case BFD_RELOC_16_PCREL_S2:
1902 /* Don't generate a reloc if we are writing into a variant frag. */
1905 fixp[0] = fix_new_exp (frag_now, f - frag_now->fr_literal, 4,
1907 (*reloc_type == BFD_RELOC_16_PCREL
1908 || *reloc_type == BFD_RELOC_16_PCREL_S2),
1911 /* These relocations can have an addend that won't fit in
1912 4 octets for 64bit assembly. */
1913 if (HAVE_64BIT_GPRS &&
1914 (*reloc_type == BFD_RELOC_16
1915 || *reloc_type == BFD_RELOC_32
1916 || *reloc_type == BFD_RELOC_MIPS_JMP
1917 || *reloc_type == BFD_RELOC_HI16_S
1918 || *reloc_type == BFD_RELOC_LO16
1919 || *reloc_type == BFD_RELOC_GPREL16
1920 || *reloc_type == BFD_RELOC_MIPS_LITERAL
1921 || *reloc_type == BFD_RELOC_GPREL32
1922 || *reloc_type == BFD_RELOC_64
1923 || *reloc_type == BFD_RELOC_CTOR
1924 || *reloc_type == BFD_RELOC_MIPS_SUB
1925 || *reloc_type == BFD_RELOC_MIPS_HIGHEST
1926 || *reloc_type == BFD_RELOC_MIPS_HIGHER
1927 || *reloc_type == BFD_RELOC_MIPS_SCN_DISP
1928 || *reloc_type == BFD_RELOC_MIPS_REL16
1929 || *reloc_type == BFD_RELOC_MIPS_RELGOT))
1930 fixp[0]->fx_no_overflow = 1;
1934 struct mips_hi_fixup *hi_fixup;
1936 assert (*reloc_type == BFD_RELOC_HI16_S);
1937 hi_fixup = ((struct mips_hi_fixup *)
1938 xmalloc (sizeof (struct mips_hi_fixup)));
1939 hi_fixup->fixp = fixp[0];
1940 hi_fixup->seg = now_seg;
1941 hi_fixup->next = mips_hi_fixup_list;
1942 mips_hi_fixup_list = hi_fixup;
1945 if (reloc_type[1] != BFD_RELOC_UNUSED)
1947 /* FIXME: This symbol can be one of
1948 RSS_UNDEF, RSS_GP, RSS_GP0, RSS_LOC. */
1949 address_expr->X_op = O_absent;
1950 address_expr->X_add_symbol = 0;
1951 address_expr->X_add_number = 0;
1953 fixp[1] = fix_new_exp (frag_now, f - frag_now->fr_literal,
1954 4, address_expr, false,
1957 /* These relocations can have an addend that won't fit in
1958 4 octets for 64bit assembly. */
1959 if (HAVE_64BIT_GPRS &&
1960 (*reloc_type == BFD_RELOC_16
1961 || *reloc_type == BFD_RELOC_32
1962 || *reloc_type == BFD_RELOC_MIPS_JMP
1963 || *reloc_type == BFD_RELOC_HI16_S
1964 || *reloc_type == BFD_RELOC_LO16
1965 || *reloc_type == BFD_RELOC_GPREL16
1966 || *reloc_type == BFD_RELOC_MIPS_LITERAL
1967 || *reloc_type == BFD_RELOC_GPREL32
1968 || *reloc_type == BFD_RELOC_64
1969 || *reloc_type == BFD_RELOC_CTOR
1970 || *reloc_type == BFD_RELOC_MIPS_SUB
1971 || *reloc_type == BFD_RELOC_MIPS_HIGHEST
1972 || *reloc_type == BFD_RELOC_MIPS_HIGHER
1973 || *reloc_type == BFD_RELOC_MIPS_SCN_DISP
1974 || *reloc_type == BFD_RELOC_MIPS_REL16
1975 || *reloc_type == BFD_RELOC_MIPS_RELGOT))
1976 fixp[1]->fx_no_overflow = 1;
1978 if (reloc_type[2] != BFD_RELOC_UNUSED)
1980 address_expr->X_op = O_absent;
1981 address_expr->X_add_symbol = 0;
1982 address_expr->X_add_number = 0;
1984 fixp[2] = fix_new_exp (frag_now,
1985 f - frag_now->fr_literal, 4,
1986 address_expr, false,
1989 /* These relocations can have an addend that won't fit in
1990 4 octets for 64bit assembly. */
1991 if (HAVE_64BIT_GPRS &&
1992 (*reloc_type == BFD_RELOC_16
1993 || *reloc_type == BFD_RELOC_32
1994 || *reloc_type == BFD_RELOC_MIPS_JMP
1995 || *reloc_type == BFD_RELOC_HI16_S
1996 || *reloc_type == BFD_RELOC_LO16
1997 || *reloc_type == BFD_RELOC_GPREL16
1998 || *reloc_type == BFD_RELOC_MIPS_LITERAL
1999 || *reloc_type == BFD_RELOC_GPREL32
2000 || *reloc_type == BFD_RELOC_64
2001 || *reloc_type == BFD_RELOC_CTOR
2002 || *reloc_type == BFD_RELOC_MIPS_SUB
2003 || *reloc_type == BFD_RELOC_MIPS_HIGHEST
2004 || *reloc_type == BFD_RELOC_MIPS_HIGHER
2005 || *reloc_type == BFD_RELOC_MIPS_SCN_DISP
2006 || *reloc_type == BFD_RELOC_MIPS_REL16
2007 || *reloc_type == BFD_RELOC_MIPS_RELGOT))
2008 fixp[2]->fx_no_overflow = 1;
2015 if (! mips_opts.mips16)
2016 md_number_to_chars (f, ip->insn_opcode, 4);
2017 else if (*reloc_type == BFD_RELOC_MIPS16_JMP)
2019 md_number_to_chars (f, ip->insn_opcode >> 16, 2);
2020 md_number_to_chars (f + 2, ip->insn_opcode & 0xffff, 2);
2026 md_number_to_chars (f, 0xf000 | ip->extend, 2);
2029 md_number_to_chars (f, ip->insn_opcode, 2);
2032 /* Update the register mask information. */
2033 if (! mips_opts.mips16)
2035 if (pinfo & INSN_WRITE_GPR_D)
2036 mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD);
2037 if ((pinfo & (INSN_WRITE_GPR_T | INSN_READ_GPR_T)) != 0)
2038 mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RT) & OP_MASK_RT);
2039 if (pinfo & INSN_READ_GPR_S)
2040 mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RS) & OP_MASK_RS);
2041 if (pinfo & INSN_WRITE_GPR_31)
2042 mips_gprmask |= 1 << RA;
2043 if (pinfo & INSN_WRITE_FPR_D)
2044 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FD) & OP_MASK_FD);
2045 if ((pinfo & (INSN_WRITE_FPR_S | INSN_READ_FPR_S)) != 0)
2046 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FS) & OP_MASK_FS);
2047 if ((pinfo & (INSN_WRITE_FPR_T | INSN_READ_FPR_T)) != 0)
2048 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FT) & OP_MASK_FT);
2049 if ((pinfo & INSN_READ_FPR_R) != 0)
2050 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FR) & OP_MASK_FR);
2051 if (pinfo & INSN_COP)
2053 /* We don't keep enough information to sort these cases out.
2054 The itbl support does keep this information however, although
2055 we currently don't support itbl fprmats as part of the cop
2056 instruction. May want to add this support in the future. */
2058 /* Never set the bit for $0, which is always zero. */
2059 mips_gprmask &= ~1 << 0;
2063 if (pinfo & (MIPS16_INSN_WRITE_X | MIPS16_INSN_READ_X))
2064 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RX)
2065 & MIPS16OP_MASK_RX);
2066 if (pinfo & (MIPS16_INSN_WRITE_Y | MIPS16_INSN_READ_Y))
2067 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RY)
2068 & MIPS16OP_MASK_RY);
2069 if (pinfo & MIPS16_INSN_WRITE_Z)
2070 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RZ)
2071 & MIPS16OP_MASK_RZ);
2072 if (pinfo & (MIPS16_INSN_WRITE_T | MIPS16_INSN_READ_T))
2073 mips_gprmask |= 1 << TREG;
2074 if (pinfo & (MIPS16_INSN_WRITE_SP | MIPS16_INSN_READ_SP))
2075 mips_gprmask |= 1 << SP;
2076 if (pinfo & (MIPS16_INSN_WRITE_31 | MIPS16_INSN_READ_31))
2077 mips_gprmask |= 1 << RA;
2078 if (pinfo & MIPS16_INSN_WRITE_GPR_Y)
2079 mips_gprmask |= 1 << MIPS16OP_EXTRACT_REG32R (ip->insn_opcode);
2080 if (pinfo & MIPS16_INSN_READ_Z)
2081 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_MOVE32Z)
2082 & MIPS16OP_MASK_MOVE32Z);
2083 if (pinfo & MIPS16_INSN_READ_GPR_X)
2084 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_REGR32)
2085 & MIPS16OP_MASK_REGR32);
2088 if (place == NULL && ! mips_opts.noreorder)
2090 /* Filling the branch delay slot is more complex. We try to
2091 switch the branch with the previous instruction, which we can
2092 do if the previous instruction does not set up a condition
2093 that the branch tests and if the branch is not itself the
2094 target of any branch. */
2095 if ((pinfo & INSN_UNCOND_BRANCH_DELAY)
2096 || (pinfo & INSN_COND_BRANCH_DELAY))
2098 if (mips_optimize < 2
2099 /* If we have seen .set volatile or .set nomove, don't
2101 || mips_opts.nomove != 0
2102 /* If we had to emit any NOP instructions, then we
2103 already know we can not swap. */
2105 /* If we don't even know the previous insn, we can not
2107 || ! prev_insn_valid
2108 /* If the previous insn is already in a branch delay
2109 slot, then we can not swap. */
2110 || prev_insn_is_delay_slot
2111 /* If the previous previous insn was in a .set
2112 noreorder, we can't swap. Actually, the MIPS
2113 assembler will swap in this situation. However, gcc
2114 configured -with-gnu-as will generate code like
2120 in which we can not swap the bne and INSN. If gcc is
2121 not configured -with-gnu-as, it does not output the
2122 .set pseudo-ops. We don't have to check
2123 prev_insn_unreordered, because prev_insn_valid will
2124 be 0 in that case. We don't want to use
2125 prev_prev_insn_valid, because we do want to be able
2126 to swap at the start of a function. */
2127 || prev_prev_insn_unreordered
2128 /* If the branch is itself the target of a branch, we
2129 can not swap. We cheat on this; all we check for is
2130 whether there is a label on this instruction. If
2131 there are any branches to anything other than a
2132 label, users must use .set noreorder. */
2133 || insn_labels != NULL
2134 /* If the previous instruction is in a variant frag, we
2135 can not do the swap. This does not apply to the
2136 mips16, which uses variant frags for different
2138 || (! mips_opts.mips16
2139 && prev_insn_frag->fr_type == rs_machine_dependent)
2140 /* If the branch reads the condition codes, we don't
2141 even try to swap, because in the sequence
2146 we can not swap, and I don't feel like handling that
2148 || (! mips_opts.mips16
2149 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2150 && (pinfo & INSN_READ_COND_CODE))
2151 /* We can not swap with an instruction that requires a
2152 delay slot, becase the target of the branch might
2153 interfere with that instruction. */
2154 || (! mips_opts.mips16
2155 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2157 /* Itbl support may require additional care here. */
2158 & (INSN_LOAD_COPROC_DELAY
2159 | INSN_COPROC_MOVE_DELAY
2160 | INSN_WRITE_COND_CODE)))
2161 || (! (hilo_interlocks
2162 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT)))
2166 || (! mips_opts.mips16
2168 && (prev_pinfo & INSN_LOAD_MEMORY_DELAY))
2169 || (! mips_opts.mips16
2170 && mips_opts.isa == ISA_MIPS1
2171 /* Itbl support may require additional care here. */
2172 && (prev_pinfo & INSN_COPROC_MEMORY_DELAY))
2173 /* We can not swap with a branch instruction. */
2175 & (INSN_UNCOND_BRANCH_DELAY
2176 | INSN_COND_BRANCH_DELAY
2177 | INSN_COND_BRANCH_LIKELY))
2178 /* We do not swap with a trap instruction, since it
2179 complicates trap handlers to have the trap
2180 instruction be in a delay slot. */
2181 || (prev_pinfo & INSN_TRAP)
2182 /* If the branch reads a register that the previous
2183 instruction sets, we can not swap. */
2184 || (! mips_opts.mips16
2185 && (prev_pinfo & INSN_WRITE_GPR_T)
2186 && insn_uses_reg (ip,
2187 ((prev_insn.insn_opcode >> OP_SH_RT)
2190 || (! mips_opts.mips16
2191 && (prev_pinfo & INSN_WRITE_GPR_D)
2192 && insn_uses_reg (ip,
2193 ((prev_insn.insn_opcode >> OP_SH_RD)
2196 || (mips_opts.mips16
2197 && (((prev_pinfo & MIPS16_INSN_WRITE_X)
2198 && insn_uses_reg (ip,
2199 ((prev_insn.insn_opcode
2201 & MIPS16OP_MASK_RX),
2203 || ((prev_pinfo & MIPS16_INSN_WRITE_Y)
2204 && insn_uses_reg (ip,
2205 ((prev_insn.insn_opcode
2207 & MIPS16OP_MASK_RY),
2209 || ((prev_pinfo & MIPS16_INSN_WRITE_Z)
2210 && insn_uses_reg (ip,
2211 ((prev_insn.insn_opcode
2213 & MIPS16OP_MASK_RZ),
2215 || ((prev_pinfo & MIPS16_INSN_WRITE_T)
2216 && insn_uses_reg (ip, TREG, MIPS_GR_REG))
2217 || ((prev_pinfo & MIPS16_INSN_WRITE_31)
2218 && insn_uses_reg (ip, RA, MIPS_GR_REG))
2219 || ((prev_pinfo & MIPS16_INSN_WRITE_GPR_Y)
2220 && insn_uses_reg (ip,
2221 MIPS16OP_EXTRACT_REG32R (prev_insn.
2224 /* If the branch writes a register that the previous
2225 instruction sets, we can not swap (we know that
2226 branches write only to RD or to $31). */
2227 || (! mips_opts.mips16
2228 && (prev_pinfo & INSN_WRITE_GPR_T)
2229 && (((pinfo & INSN_WRITE_GPR_D)
2230 && (((prev_insn.insn_opcode >> OP_SH_RT) & OP_MASK_RT)
2231 == ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD)))
2232 || ((pinfo & INSN_WRITE_GPR_31)
2233 && (((prev_insn.insn_opcode >> OP_SH_RT)
2236 || (! mips_opts.mips16
2237 && (prev_pinfo & INSN_WRITE_GPR_D)
2238 && (((pinfo & INSN_WRITE_GPR_D)
2239 && (((prev_insn.insn_opcode >> OP_SH_RD) & OP_MASK_RD)
2240 == ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD)))
2241 || ((pinfo & INSN_WRITE_GPR_31)
2242 && (((prev_insn.insn_opcode >> OP_SH_RD)
2245 || (mips_opts.mips16
2246 && (pinfo & MIPS16_INSN_WRITE_31)
2247 && ((prev_pinfo & MIPS16_INSN_WRITE_31)
2248 || ((prev_pinfo & MIPS16_INSN_WRITE_GPR_Y)
2249 && (MIPS16OP_EXTRACT_REG32R (prev_insn.insn_opcode)
2251 /* If the branch writes a register that the previous
2252 instruction reads, we can not swap (we know that
2253 branches only write to RD or to $31). */
2254 || (! mips_opts.mips16
2255 && (pinfo & INSN_WRITE_GPR_D)
2256 && insn_uses_reg (&prev_insn,
2257 ((ip->insn_opcode >> OP_SH_RD)
2260 || (! mips_opts.mips16
2261 && (pinfo & INSN_WRITE_GPR_31)
2262 && insn_uses_reg (&prev_insn, RA, MIPS_GR_REG))
2263 || (mips_opts.mips16
2264 && (pinfo & MIPS16_INSN_WRITE_31)
2265 && insn_uses_reg (&prev_insn, RA, MIPS_GR_REG))
2266 /* If we are generating embedded PIC code, the branch
2267 might be expanded into a sequence which uses $at, so
2268 we can't swap with an instruction which reads it. */
2269 || (mips_pic == EMBEDDED_PIC
2270 && insn_uses_reg (&prev_insn, AT, MIPS_GR_REG))
2271 /* If the previous previous instruction has a load
2272 delay, and sets a register that the branch reads, we
2274 || (! mips_opts.mips16
2275 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2276 /* Itbl support may require additional care here. */
2277 && ((prev_prev_insn.insn_mo->pinfo & INSN_LOAD_COPROC_DELAY)
2278 || (! gpr_interlocks
2279 && (prev_prev_insn.insn_mo->pinfo
2280 & INSN_LOAD_MEMORY_DELAY)))
2281 && insn_uses_reg (ip,
2282 ((prev_prev_insn.insn_opcode >> OP_SH_RT)
2285 /* If one instruction sets a condition code and the
2286 other one uses a condition code, we can not swap. */
2287 || ((pinfo & INSN_READ_COND_CODE)
2288 && (prev_pinfo & INSN_WRITE_COND_CODE))
2289 || ((pinfo & INSN_WRITE_COND_CODE)
2290 && (prev_pinfo & INSN_READ_COND_CODE))
2291 /* If the previous instruction uses the PC, we can not
2293 || (mips_opts.mips16
2294 && (prev_pinfo & MIPS16_INSN_READ_PC))
2295 /* If the previous instruction was extended, we can not
2297 || (mips_opts.mips16 && prev_insn_extended)
2298 /* If the previous instruction had a fixup in mips16
2299 mode, we can not swap. This normally means that the
2300 previous instruction was a 4 byte branch anyhow. */
2301 || (mips_opts.mips16 && prev_insn_fixp[0])
2302 /* If the previous instruction is a sync, sync.l, or
2303 sync.p, we can not swap. */
2304 || (prev_pinfo & INSN_SYNC))
2306 /* We could do even better for unconditional branches to
2307 portions of this object file; we could pick up the
2308 instruction at the destination, put it in the delay
2309 slot, and bump the destination address. */
2311 /* Update the previous insn information. */
2312 prev_prev_insn = *ip;
2313 prev_insn.insn_mo = &dummy_opcode;
2317 /* It looks like we can actually do the swap. */
2318 if (! mips_opts.mips16)
2323 prev_f = prev_insn_frag->fr_literal + prev_insn_where;
2324 memcpy (temp, prev_f, 4);
2325 memcpy (prev_f, f, 4);
2326 memcpy (f, temp, 4);
2327 if (prev_insn_fixp[0])
2329 prev_insn_fixp[0]->fx_frag = frag_now;
2330 prev_insn_fixp[0]->fx_where = f - frag_now->fr_literal;
2332 if (prev_insn_fixp[1])
2334 prev_insn_fixp[1]->fx_frag = frag_now;
2335 prev_insn_fixp[1]->fx_where = f - frag_now->fr_literal;
2337 if (prev_insn_fixp[2])
2339 prev_insn_fixp[2]->fx_frag = frag_now;
2340 prev_insn_fixp[2]->fx_where = f - frag_now->fr_literal;
2344 fixp[0]->fx_frag = prev_insn_frag;
2345 fixp[0]->fx_where = prev_insn_where;
2349 fixp[1]->fx_frag = prev_insn_frag;
2350 fixp[1]->fx_where = prev_insn_where;
2354 fixp[2]->fx_frag = prev_insn_frag;
2355 fixp[2]->fx_where = prev_insn_where;
2363 assert (prev_insn_fixp[0] == NULL);
2364 assert (prev_insn_fixp[1] == NULL);
2365 assert (prev_insn_fixp[2] == NULL);
2366 prev_f = prev_insn_frag->fr_literal + prev_insn_where;
2367 memcpy (temp, prev_f, 2);
2368 memcpy (prev_f, f, 2);
2369 if (*reloc_type != BFD_RELOC_MIPS16_JMP)
2371 assert (*reloc_type == BFD_RELOC_UNUSED);
2372 memcpy (f, temp, 2);
2376 memcpy (f, f + 2, 2);
2377 memcpy (f + 2, temp, 2);
2381 fixp[0]->fx_frag = prev_insn_frag;
2382 fixp[0]->fx_where = prev_insn_where;
2386 fixp[1]->fx_frag = prev_insn_frag;
2387 fixp[1]->fx_where = prev_insn_where;
2391 fixp[2]->fx_frag = prev_insn_frag;
2392 fixp[2]->fx_where = prev_insn_where;
2396 /* Update the previous insn information; leave prev_insn
2398 prev_prev_insn = *ip;
2400 prev_insn_is_delay_slot = 1;
2402 /* If that was an unconditional branch, forget the previous
2403 insn information. */
2404 if (pinfo & INSN_UNCOND_BRANCH_DELAY)
2406 prev_prev_insn.insn_mo = &dummy_opcode;
2407 prev_insn.insn_mo = &dummy_opcode;
2410 prev_insn_fixp[0] = NULL;
2411 prev_insn_fixp[1] = NULL;
2412 prev_insn_fixp[2] = NULL;
2413 prev_insn_reloc_type[0] = BFD_RELOC_UNUSED;
2414 prev_insn_reloc_type[1] = BFD_RELOC_UNUSED;
2415 prev_insn_reloc_type[2] = BFD_RELOC_UNUSED;
2416 prev_insn_extended = 0;
2418 else if (pinfo & INSN_COND_BRANCH_LIKELY)
2420 /* We don't yet optimize a branch likely. What we should do
2421 is look at the target, copy the instruction found there
2422 into the delay slot, and increment the branch to jump to
2423 the next instruction. */
2425 /* Update the previous insn information. */
2426 prev_prev_insn = *ip;
2427 prev_insn.insn_mo = &dummy_opcode;
2428 prev_insn_fixp[0] = NULL;
2429 prev_insn_fixp[1] = NULL;
2430 prev_insn_fixp[2] = NULL;
2431 prev_insn_reloc_type[0] = BFD_RELOC_UNUSED;
2432 prev_insn_reloc_type[1] = BFD_RELOC_UNUSED;
2433 prev_insn_reloc_type[2] = BFD_RELOC_UNUSED;
2434 prev_insn_extended = 0;
2438 /* Update the previous insn information. */
2440 prev_prev_insn.insn_mo = &dummy_opcode;
2442 prev_prev_insn = prev_insn;
2445 /* Any time we see a branch, we always fill the delay slot
2446 immediately; since this insn is not a branch, we know it
2447 is not in a delay slot. */
2448 prev_insn_is_delay_slot = 0;
2450 prev_insn_fixp[0] = fixp[0];
2451 prev_insn_fixp[1] = fixp[1];
2452 prev_insn_fixp[2] = fixp[2];
2453 prev_insn_reloc_type[0] = reloc_type[0];
2454 prev_insn_reloc_type[1] = reloc_type[1];
2455 prev_insn_reloc_type[2] = reloc_type[2];
2456 if (mips_opts.mips16)
2457 prev_insn_extended = (ip->use_extend
2458 || *reloc_type > BFD_RELOC_UNUSED);
2461 prev_prev_insn_unreordered = prev_insn_unreordered;
2462 prev_insn_unreordered = 0;
2463 prev_insn_frag = frag_now;
2464 prev_insn_where = f - frag_now->fr_literal;
2465 prev_insn_valid = 1;
2467 else if (place == NULL)
2469 /* We need to record a bit of information even when we are not
2470 reordering, in order to determine the base address for mips16
2471 PC relative relocs. */
2472 prev_prev_insn = prev_insn;
2474 prev_insn_reloc_type[0] = reloc_type[0];
2475 prev_insn_reloc_type[1] = reloc_type[1];
2476 prev_insn_reloc_type[2] = reloc_type[2];
2477 prev_prev_insn_unreordered = prev_insn_unreordered;
2478 prev_insn_unreordered = 1;
2481 /* We just output an insn, so the next one doesn't have a label. */
2482 mips_clear_insn_labels ();
2484 /* We must ensure that a fixup associated with an unmatched %hi
2485 reloc does not become a variant frag. Otherwise, the
2486 rearrangement of %hi relocs in frob_file may confuse
2490 frag_wane (frag_now);
2495 /* This function forgets that there was any previous instruction or
2496 label. If PRESERVE is non-zero, it remembers enough information to
2497 know whether nops are needed before a noreorder section. */
2500 mips_no_prev_insn (preserve)
2505 prev_insn.insn_mo = &dummy_opcode;
2506 prev_prev_insn.insn_mo = &dummy_opcode;
2507 prev_nop_frag = NULL;
2508 prev_nop_frag_holds = 0;
2509 prev_nop_frag_required = 0;
2510 prev_nop_frag_since = 0;
2512 prev_insn_valid = 0;
2513 prev_insn_is_delay_slot = 0;
2514 prev_insn_unreordered = 0;
2515 prev_insn_extended = 0;
2516 prev_insn_reloc_type[0] = BFD_RELOC_UNUSED;
2517 prev_insn_reloc_type[1] = BFD_RELOC_UNUSED;
2518 prev_insn_reloc_type[2] = BFD_RELOC_UNUSED;
2519 prev_prev_insn_unreordered = 0;
2520 mips_clear_insn_labels ();
2523 /* This function must be called whenever we turn on noreorder or emit
2524 something other than instructions. It inserts any NOPS which might
2525 be needed by the previous instruction, and clears the information
2526 kept for the previous instructions. The INSNS parameter is true if
2527 instructions are to follow. */
2530 mips_emit_delays (insns)
2533 if (! mips_opts.noreorder)
2538 if ((! mips_opts.mips16
2539 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2540 && (! cop_interlocks
2541 && (prev_insn.insn_mo->pinfo
2542 & (INSN_LOAD_COPROC_DELAY
2543 | INSN_COPROC_MOVE_DELAY
2544 | INSN_WRITE_COND_CODE))))
2545 || (! hilo_interlocks
2546 && (prev_insn.insn_mo->pinfo
2549 || (! mips_opts.mips16
2551 && (prev_insn.insn_mo->pinfo
2552 & INSN_LOAD_MEMORY_DELAY))
2553 || (! mips_opts.mips16
2554 && mips_opts.isa == ISA_MIPS1
2555 && (prev_insn.insn_mo->pinfo
2556 & INSN_COPROC_MEMORY_DELAY)))
2558 /* Itbl support may require additional care here. */
2560 if ((! mips_opts.mips16
2561 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2562 && (! cop_interlocks
2563 && prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE))
2564 || (! hilo_interlocks
2565 && ((prev_insn.insn_mo->pinfo & INSN_READ_HI)
2566 || (prev_insn.insn_mo->pinfo & INSN_READ_LO))))
2569 if (prev_insn_unreordered)
2572 else if ((! mips_opts.mips16
2573 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2574 && (! cop_interlocks
2575 && prev_prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE))
2576 || (! hilo_interlocks
2577 && ((prev_prev_insn.insn_mo->pinfo & INSN_READ_HI)
2578 || (prev_prev_insn.insn_mo->pinfo & INSN_READ_LO))))
2580 /* Itbl support may require additional care here. */
2581 if (! prev_prev_insn_unreordered)
2587 struct insn_label_list *l;
2591 /* Record the frag which holds the nop instructions, so
2592 that we can remove them if we don't need them. */
2593 frag_grow (mips_opts.mips16 ? nops * 2 : nops * 4);
2594 prev_nop_frag = frag_now;
2595 prev_nop_frag_holds = nops;
2596 prev_nop_frag_required = 0;
2597 prev_nop_frag_since = 0;
2600 for (; nops > 0; --nops)
2605 /* Move on to a new frag, so that it is safe to simply
2606 decrease the size of prev_nop_frag. */
2607 frag_wane (frag_now);
2611 for (l = insn_labels; l != NULL; l = l->next)
2615 assert (S_GET_SEGMENT (l->label) == now_seg);
2616 symbol_set_frag (l->label, frag_now);
2617 val = (valueT) frag_now_fix ();
2618 /* mips16 text labels are stored as odd. */
2619 if (mips_opts.mips16)
2621 S_SET_VALUE (l->label, val);
2626 /* Mark instruction labels in mips16 mode. */
2628 mips16_mark_labels ();
2630 mips_no_prev_insn (insns);
2633 /* Build an instruction created by a macro expansion. This is passed
2634 a pointer to the count of instructions created so far, an
2635 expression, the name of the instruction to build, an operand format
2636 string, and corresponding arguments. */
2640 macro_build (char *place,
2648 macro_build (place, counter, ep, name, fmt, va_alist)
2657 struct mips_cl_insn insn;
2658 bfd_reloc_code_real_type r[3];
2662 va_start (args, fmt);
2668 * If the macro is about to expand into a second instruction,
2669 * print a warning if needed. We need to pass ip as a parameter
2670 * to generate a better warning message here...
2672 if (mips_opts.warn_about_macros && place == NULL && *counter == 1)
2673 as_warn (_("Macro instruction expanded into multiple instructions"));
2676 * If the macro is about to expand into a second instruction,
2677 * and it is in a delay slot, print a warning.
2681 && mips_opts.noreorder
2682 && (prev_prev_insn.insn_mo->pinfo
2683 & (INSN_UNCOND_BRANCH_DELAY | INSN_COND_BRANCH_DELAY
2684 | INSN_COND_BRANCH_LIKELY)) != 0)
2685 as_warn (_("Macro instruction expanded into multiple instructions in a branch delay slot"));
2688 ++*counter; /* bump instruction counter */
2690 if (mips_opts.mips16)
2692 mips16_macro_build (place, counter, ep, name, fmt, args);
2697 r[0] = BFD_RELOC_UNUSED;
2698 r[1] = BFD_RELOC_UNUSED;
2699 r[2] = BFD_RELOC_UNUSED;
2700 insn.insn_mo = (struct mips_opcode *) hash_find (op_hash, name);
2701 assert (insn.insn_mo);
2702 assert (strcmp (name, insn.insn_mo->name) == 0);
2704 /* Search until we get a match for NAME. */
2707 /* It is assumed here that macros will never generate
2708 MDMX or MIPS-3D instructions. */
2709 if (strcmp (fmt, insn.insn_mo->args) == 0
2710 && insn.insn_mo->pinfo != INSN_MACRO
2711 && OPCODE_IS_MEMBER (insn.insn_mo, mips_opts.isa, mips_arch)
2712 && (mips_arch != CPU_R4650 || (insn.insn_mo->pinfo & FP_D) == 0))
2716 assert (insn.insn_mo->name);
2717 assert (strcmp (name, insn.insn_mo->name) == 0);
2720 insn.insn_opcode = insn.insn_mo->match;
2736 insn.insn_opcode |= va_arg (args, int) << OP_SH_RT;
2740 insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE;
2745 insn.insn_opcode |= va_arg (args, int) << OP_SH_FT;
2750 insn.insn_opcode |= va_arg (args, int) << OP_SH_RD;
2755 int tmp = va_arg (args, int);
2757 insn.insn_opcode |= tmp << OP_SH_RT;
2758 insn.insn_opcode |= tmp << OP_SH_RD;
2764 insn.insn_opcode |= va_arg (args, int) << OP_SH_FS;
2771 insn.insn_opcode |= va_arg (args, int) << OP_SH_SHAMT;
2775 insn.insn_opcode |= va_arg (args, int) << OP_SH_FD;
2779 insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE20;
2783 insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE19;
2787 insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE2;
2794 insn.insn_opcode |= va_arg (args, int) << OP_SH_RS;
2800 *r = (bfd_reloc_code_real_type) va_arg (args, int);
2801 assert (*r == BFD_RELOC_GPREL16
2802 || *r == BFD_RELOC_MIPS_LITERAL
2803 || *r == BFD_RELOC_MIPS_HIGHER
2804 || *r == BFD_RELOC_HI16_S
2805 || *r == BFD_RELOC_LO16
2806 || *r == BFD_RELOC_MIPS_GOT16
2807 || *r == BFD_RELOC_MIPS_CALL16
2808 || *r == BFD_RELOC_MIPS_GOT_DISP
2809 || *r == BFD_RELOC_MIPS_GOT_PAGE
2810 || *r == BFD_RELOC_MIPS_GOT_OFST
2811 || *r == BFD_RELOC_MIPS_GOT_LO16
2812 || *r == BFD_RELOC_MIPS_CALL_LO16
2813 || (ep->X_op == O_subtract
2814 && *r == BFD_RELOC_PCREL_LO16));
2818 *r = (bfd_reloc_code_real_type) va_arg (args, int);
2820 && (ep->X_op == O_constant
2821 || (ep->X_op == O_symbol
2822 && (*r == BFD_RELOC_MIPS_HIGHEST
2823 || *r == BFD_RELOC_HI16_S
2824 || *r == BFD_RELOC_HI16
2825 || *r == BFD_RELOC_GPREL16
2826 || *r == BFD_RELOC_MIPS_GOT_HI16
2827 || *r == BFD_RELOC_MIPS_CALL_HI16))
2828 || (ep->X_op == O_subtract
2829 && *r == BFD_RELOC_PCREL_HI16_S)));
2833 assert (ep != NULL);
2835 * This allows macro() to pass an immediate expression for
2836 * creating short branches without creating a symbol.
2837 * Note that the expression still might come from the assembly
2838 * input, in which case the value is not checked for range nor
2839 * is a relocation entry generated (yuck).
2841 if (ep->X_op == O_constant)
2843 insn.insn_opcode |= (ep->X_add_number >> 2) & 0xffff;
2847 if (mips_pic == EMBEDDED_PIC)
2848 *r = BFD_RELOC_16_PCREL_S2;
2850 *r = BFD_RELOC_16_PCREL;
2854 assert (ep != NULL);
2855 *r = BFD_RELOC_MIPS_JMP;
2859 insn.insn_opcode |= va_arg (args, unsigned long);
2868 assert (*r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL);
2870 append_insn (place, &insn, ep, r, false);
2874 mips16_macro_build (place, counter, ep, name, fmt, args)
2876 int *counter ATTRIBUTE_UNUSED;
2882 struct mips_cl_insn insn;
2883 bfd_reloc_code_real_type r[3]
2884 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
2886 insn.insn_mo = (struct mips_opcode *) hash_find (mips16_op_hash, name);
2887 assert (insn.insn_mo);
2888 assert (strcmp (name, insn.insn_mo->name) == 0);
2890 while (strcmp (fmt, insn.insn_mo->args) != 0
2891 || insn.insn_mo->pinfo == INSN_MACRO)
2894 assert (insn.insn_mo->name);
2895 assert (strcmp (name, insn.insn_mo->name) == 0);
2898 insn.insn_opcode = insn.insn_mo->match;
2899 insn.use_extend = false;
2918 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RY;
2923 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RX;
2927 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RZ;
2931 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_MOVE32Z;
2941 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_REGR32;
2948 regno = va_arg (args, int);
2949 regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3);
2950 insn.insn_opcode |= regno << MIPS16OP_SH_REG32R;
2971 assert (ep != NULL);
2973 if (ep->X_op != O_constant)
2974 *r = (int) BFD_RELOC_UNUSED + c;
2977 mips16_immed (NULL, 0, c, ep->X_add_number, false, false,
2978 false, &insn.insn_opcode, &insn.use_extend,
2981 *r = BFD_RELOC_UNUSED;
2987 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_IMM6;
2994 assert (*r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL);
2996 append_insn (place, &insn, ep, r, false);
3000 * Generate a "jalr" instruction with a relocation hint to the called
3001 * function. This occurs in NewABI PIC code.
3004 macro_build_jalr (icnt, ep)
3010 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "jalr", "d,s",
3013 fix_new_exp (frag_now, 0, 0, ep, false, BFD_RELOC_MIPS_JALR);
3017 * Generate a "lui" instruction.
3020 macro_build_lui (place, counter, ep, regnum)
3026 expressionS high_expr;
3027 struct mips_cl_insn insn;
3028 bfd_reloc_code_real_type r[3]
3029 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
3030 CONST char *name = "lui";
3031 CONST char *fmt = "t,u";
3033 assert (! mips_opts.mips16);
3039 high_expr.X_op = O_constant;
3040 high_expr.X_add_number = ep->X_add_number;
3043 if (high_expr.X_op == O_constant)
3045 /* we can compute the instruction now without a relocation entry */
3046 high_expr.X_add_number = ((high_expr.X_add_number + 0x8000)
3048 *r = BFD_RELOC_UNUSED;
3050 else if (! HAVE_NEWABI)
3052 assert (ep->X_op == O_symbol);
3053 /* _gp_disp is a special case, used from s_cpload. */
3054 assert (mips_pic == NO_PIC
3055 || strcmp (S_GET_NAME (ep->X_add_symbol), "_gp_disp") == 0);
3056 *r = BFD_RELOC_HI16_S;
3060 * If the macro is about to expand into a second instruction,
3061 * print a warning if needed. We need to pass ip as a parameter
3062 * to generate a better warning message here...
3064 if (mips_opts.warn_about_macros && place == NULL && *counter == 1)
3065 as_warn (_("Macro instruction expanded into multiple instructions"));
3068 ++*counter; /* bump instruction counter */
3070 insn.insn_mo = (struct mips_opcode *) hash_find (op_hash, name);
3071 assert (insn.insn_mo);
3072 assert (strcmp (name, insn.insn_mo->name) == 0);
3073 assert (strcmp (fmt, insn.insn_mo->args) == 0);
3075 insn.insn_opcode = insn.insn_mo->match | (regnum << OP_SH_RT);
3076 if (*r == BFD_RELOC_UNUSED)
3078 insn.insn_opcode |= high_expr.X_add_number;
3079 append_insn (place, &insn, NULL, r, false);
3082 append_insn (place, &insn, &high_expr, r, false);
3086 * Generates code to set the $at register to true (one)
3087 * if reg is less than the immediate expression.
3090 set_at (counter, reg, unsignedp)
3095 if (imm_expr.X_op == O_constant
3096 && imm_expr.X_add_number >= -0x8000
3097 && imm_expr.X_add_number < 0x8000)
3098 macro_build ((char *) NULL, counter, &imm_expr,
3099 unsignedp ? "sltiu" : "slti",
3100 "t,r,j", AT, reg, (int) BFD_RELOC_LO16);
3103 load_register (counter, AT, &imm_expr, HAVE_64BIT_GPRS);
3104 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3105 unsignedp ? "sltu" : "slt",
3106 "d,v,t", AT, reg, AT);
3110 /* Warn if an expression is not a constant. */
3113 check_absolute_expr (ip, ex)
3114 struct mips_cl_insn *ip;
3117 if (ex->X_op == O_big)
3118 as_bad (_("unsupported large constant"));
3119 else if (ex->X_op != O_constant)
3120 as_bad (_("Instruction %s requires absolute expression"), ip->insn_mo->name);
3123 /* Count the leading zeroes by performing a binary chop. This is a
3124 bulky bit of source, but performance is a LOT better for the
3125 majority of values than a simple loop to count the bits:
3126 for (lcnt = 0; (lcnt < 32); lcnt++)
3127 if ((v) & (1 << (31 - lcnt)))
3129 However it is not code size friendly, and the gain will drop a bit
3130 on certain cached systems.
3132 #define COUNT_TOP_ZEROES(v) \
3133 (((v) & ~0xffff) == 0 \
3134 ? ((v) & ~0xff) == 0 \
3135 ? ((v) & ~0xf) == 0 \
3136 ? ((v) & ~0x3) == 0 \
3137 ? ((v) & ~0x1) == 0 \
3142 : ((v) & ~0x7) == 0 \
3145 : ((v) & ~0x3f) == 0 \
3146 ? ((v) & ~0x1f) == 0 \
3149 : ((v) & ~0x7f) == 0 \
3152 : ((v) & ~0xfff) == 0 \
3153 ? ((v) & ~0x3ff) == 0 \
3154 ? ((v) & ~0x1ff) == 0 \
3157 : ((v) & ~0x7ff) == 0 \
3160 : ((v) & ~0x3fff) == 0 \
3161 ? ((v) & ~0x1fff) == 0 \
3164 : ((v) & ~0x7fff) == 0 \
3167 : ((v) & ~0xffffff) == 0 \
3168 ? ((v) & ~0xfffff) == 0 \
3169 ? ((v) & ~0x3ffff) == 0 \
3170 ? ((v) & ~0x1ffff) == 0 \
3173 : ((v) & ~0x7ffff) == 0 \
3176 : ((v) & ~0x3fffff) == 0 \
3177 ? ((v) & ~0x1fffff) == 0 \
3180 : ((v) & ~0x7fffff) == 0 \
3183 : ((v) & ~0xfffffff) == 0 \
3184 ? ((v) & ~0x3ffffff) == 0 \
3185 ? ((v) & ~0x1ffffff) == 0 \
3188 : ((v) & ~0x7ffffff) == 0 \
3191 : ((v) & ~0x3fffffff) == 0 \
3192 ? ((v) & ~0x1fffffff) == 0 \
3195 : ((v) & ~0x7fffffff) == 0 \
3199 /* Is the given value a sign-extended 32-bit value? */
3200 #define IS_SEXT_32BIT_NUM(x) \
3201 (((x) &~ (offsetT) 0x7fffffff) == 0 \
3202 || (((x) &~ (offsetT) 0x7fffffff) == ~ (offsetT) 0x7fffffff))
3205 * This routine generates the least number of instructions neccessary to load
3206 * an absolute expression value into a register.
3209 load_register (counter, reg, ep, dbl)
3216 expressionS hi32, lo32;
3218 if (ep->X_op != O_big)
3220 assert (ep->X_op == O_constant);
3221 if (ep->X_add_number < 0x8000
3222 && (ep->X_add_number >= 0
3223 || (ep->X_add_number >= -0x8000
3226 || sizeof (ep->X_add_number) > 4))))
3228 /* We can handle 16 bit signed values with an addiu to
3229 $zero. No need to ever use daddiu here, since $zero and
3230 the result are always correct in 32 bit mode. */
3231 macro_build ((char *) NULL, counter, ep, "addiu", "t,r,j", reg, 0,
3232 (int) BFD_RELOC_LO16);
3235 else if (ep->X_add_number >= 0 && ep->X_add_number < 0x10000)
3237 /* We can handle 16 bit unsigned values with an ori to
3239 macro_build ((char *) NULL, counter, ep, "ori", "t,r,i", reg, 0,
3240 (int) BFD_RELOC_LO16);
3243 else if ((IS_SEXT_32BIT_NUM (ep->X_add_number)
3246 || sizeof (ep->X_add_number) > 4
3247 || (ep->X_add_number & 0x80000000) == 0))
3248 || ((HAVE_32BIT_GPRS || ! dbl)
3249 && (ep->X_add_number &~ (offsetT) 0xffffffff) == 0)
3252 && ((ep->X_add_number &~ (offsetT) 0xffffffff)
3253 == ~ (offsetT) 0xffffffff)))
3255 /* 32 bit values require an lui. */
3256 macro_build ((char *) NULL, counter, ep, "lui", "t,u", reg,
3257 (int) BFD_RELOC_HI16);
3258 if ((ep->X_add_number & 0xffff) != 0)
3259 macro_build ((char *) NULL, counter, ep, "ori", "t,r,i", reg, reg,
3260 (int) BFD_RELOC_LO16);
3265 /* The value is larger than 32 bits. */
3267 if (HAVE_32BIT_GPRS)
3269 as_bad (_("Number (0x%lx) larger than 32 bits"),
3270 (unsigned long) ep->X_add_number);
3271 macro_build ((char *) NULL, counter, ep, "addiu", "t,r,j", reg, 0,
3272 (int) BFD_RELOC_LO16);
3276 if (ep->X_op != O_big)
3279 hi32.X_add_number = (valueT) hi32.X_add_number >> 16;
3280 hi32.X_add_number = (valueT) hi32.X_add_number >> 16;
3281 hi32.X_add_number &= 0xffffffff;
3283 lo32.X_add_number &= 0xffffffff;
3287 assert (ep->X_add_number > 2);
3288 if (ep->X_add_number == 3)
3289 generic_bignum[3] = 0;
3290 else if (ep->X_add_number > 4)
3291 as_bad (_("Number larger than 64 bits"));
3292 lo32.X_op = O_constant;
3293 lo32.X_add_number = generic_bignum[0] + (generic_bignum[1] << 16);
3294 hi32.X_op = O_constant;
3295 hi32.X_add_number = generic_bignum[2] + (generic_bignum[3] << 16);
3298 if (hi32.X_add_number == 0)
3303 unsigned long hi, lo;
3305 if (hi32.X_add_number == (offsetT) 0xffffffff)
3307 if ((lo32.X_add_number & 0xffff8000) == 0xffff8000)
3309 macro_build ((char *) NULL, counter, &lo32, "addiu", "t,r,j",
3310 reg, 0, (int) BFD_RELOC_LO16);
3313 if (lo32.X_add_number & 0x80000000)
3315 macro_build ((char *) NULL, counter, &lo32, "lui", "t,u", reg,
3316 (int) BFD_RELOC_HI16);
3317 if (lo32.X_add_number & 0xffff)
3318 macro_build ((char *) NULL, counter, &lo32, "ori", "t,r,i",
3319 reg, reg, (int) BFD_RELOC_LO16);
3324 /* Check for 16bit shifted constant. We know that hi32 is
3325 non-zero, so start the mask on the first bit of the hi32
3330 unsigned long himask, lomask;
3334 himask = 0xffff >> (32 - shift);
3335 lomask = (0xffff << shift) & 0xffffffff;
3339 himask = 0xffff << (shift - 32);
3342 if ((hi32.X_add_number & ~(offsetT) himask) == 0
3343 && (lo32.X_add_number & ~(offsetT) lomask) == 0)
3347 tmp.X_op = O_constant;
3349 tmp.X_add_number = ((hi32.X_add_number << (32 - shift))
3350 | (lo32.X_add_number >> shift));
3352 tmp.X_add_number = hi32.X_add_number >> (shift - 32);
3353 macro_build ((char *) NULL, counter, &tmp,
3354 "ori", "t,r,i", reg, 0,
3355 (int) BFD_RELOC_LO16);
3356 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3357 (shift >= 32) ? "dsll32" : "dsll",
3359 (shift >= 32) ? shift - 32 : shift);
3364 while (shift <= (64 - 16));
3366 /* Find the bit number of the lowest one bit, and store the
3367 shifted value in hi/lo. */
3368 hi = (unsigned long) (hi32.X_add_number & 0xffffffff);
3369 lo = (unsigned long) (lo32.X_add_number & 0xffffffff);
3373 while ((lo & 1) == 0)
3378 lo |= (hi & (((unsigned long) 1 << bit) - 1)) << (32 - bit);
3384 while ((hi & 1) == 0)
3393 /* Optimize if the shifted value is a (power of 2) - 1. */
3394 if ((hi == 0 && ((lo + 1) & lo) == 0)
3395 || (lo == 0xffffffff && ((hi + 1) & hi) == 0))
3397 shift = COUNT_TOP_ZEROES ((unsigned int) hi32.X_add_number);
3402 /* This instruction will set the register to be all
3404 tmp.X_op = O_constant;
3405 tmp.X_add_number = (offsetT) -1;
3406 macro_build ((char *) NULL, counter, &tmp, "addiu", "t,r,j",
3407 reg, 0, (int) BFD_RELOC_LO16);
3411 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3412 (bit >= 32) ? "dsll32" : "dsll",
3414 (bit >= 32) ? bit - 32 : bit);
3416 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3417 (shift >= 32) ? "dsrl32" : "dsrl",
3419 (shift >= 32) ? shift - 32 : shift);
3424 /* Sign extend hi32 before calling load_register, because we can
3425 generally get better code when we load a sign extended value. */
3426 if ((hi32.X_add_number & 0x80000000) != 0)
3427 hi32.X_add_number |= ~(offsetT) 0xffffffff;
3428 load_register (counter, reg, &hi32, 0);
3431 if ((lo32.X_add_number & 0xffff0000) == 0)
3435 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3436 "dsll32", "d,w,<", reg, freg, 0);
3444 if ((freg == 0) && (lo32.X_add_number == (offsetT) 0xffffffff))
3446 macro_build ((char *) NULL, counter, &lo32, "lui", "t,u", reg,
3447 (int) BFD_RELOC_HI16);
3448 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3449 "dsrl32", "d,w,<", reg, reg, 0);
3455 macro_build ((char *) NULL, counter, (expressionS *) NULL, "dsll",
3456 "d,w,<", reg, freg, 16);
3460 mid16.X_add_number >>= 16;
3461 macro_build ((char *) NULL, counter, &mid16, "ori", "t,r,i", reg,
3462 freg, (int) BFD_RELOC_LO16);
3463 macro_build ((char *) NULL, counter, (expressionS *) NULL, "dsll",
3464 "d,w,<", reg, reg, 16);
3467 if ((lo32.X_add_number & 0xffff) != 0)
3468 macro_build ((char *) NULL, counter, &lo32, "ori", "t,r,i", reg, freg,
3469 (int) BFD_RELOC_LO16);
3472 /* Load an address into a register. */
3475 load_address (counter, reg, ep, used_at)
3483 if (ep->X_op != O_constant
3484 && ep->X_op != O_symbol)
3486 as_bad (_("expression too complex"));
3487 ep->X_op = O_constant;
3490 if (ep->X_op == O_constant)
3492 load_register (counter, reg, ep, HAVE_64BIT_ADDRESSES);
3496 if (mips_pic == NO_PIC)
3498 /* If this is a reference to a GP relative symbol, we want
3499 addiu $reg,$gp,<sym> (BFD_RELOC_GPREL16)
3501 lui $reg,<sym> (BFD_RELOC_HI16_S)
3502 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
3503 If we have an addend, we always use the latter form.
3505 With 64bit address space and a usable $at we want
3506 lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST)
3507 lui $at,<sym> (BFD_RELOC_HI16_S)
3508 daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER)
3509 daddiu $at,<sym> (BFD_RELOC_LO16)
3513 If $at is already in use, we use an path which is suboptimal
3514 on superscalar processors.
3515 lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST)
3516 daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER)
3518 daddiu $reg,<sym> (BFD_RELOC_HI16_S)
3520 daddiu $reg,<sym> (BFD_RELOC_LO16)
3522 if (HAVE_64BIT_ADDRESSES)
3524 /* We don't do GP optimization for now because RELAX_ENCODE can't
3525 hold the data for such large chunks. */
3529 macro_build (p, counter, ep, "lui", "t,u",
3530 reg, (int) BFD_RELOC_MIPS_HIGHEST);
3531 macro_build (p, counter, ep, "lui", "t,u",
3532 AT, (int) BFD_RELOC_HI16_S);
3533 macro_build (p, counter, ep, "daddiu", "t,r,j",
3534 reg, reg, (int) BFD_RELOC_MIPS_HIGHER);
3535 macro_build (p, counter, ep, "daddiu", "t,r,j",
3536 AT, AT, (int) BFD_RELOC_LO16);
3537 macro_build (p, counter, (expressionS *) NULL, "dsll32",
3538 "d,w,<", reg, reg, 0);
3539 macro_build (p, counter, (expressionS *) NULL, "dadd",
3540 "d,v,t", reg, reg, AT);
3545 macro_build (p, counter, ep, "lui", "t,u",
3546 reg, (int) BFD_RELOC_MIPS_HIGHEST);
3547 macro_build (p, counter, ep, "daddiu", "t,r,j",
3548 reg, reg, (int) BFD_RELOC_MIPS_HIGHER);
3549 macro_build (p, counter, (expressionS *) NULL, "dsll",
3550 "d,w,<", reg, reg, 16);
3551 macro_build (p, counter, ep, "daddiu", "t,r,j",
3552 reg, reg, (int) BFD_RELOC_HI16_S);
3553 macro_build (p, counter, (expressionS *) NULL, "dsll",
3554 "d,w,<", reg, reg, 16);
3555 macro_build (p, counter, ep, "daddiu", "t,r,j",
3556 reg, reg, (int) BFD_RELOC_LO16);
3561 if ((valueT) ep->X_add_number <= MAX_GPREL_OFFSET
3562 && ! nopic_need_relax (ep->X_add_symbol, 1))
3565 macro_build ((char *) NULL, counter, ep,
3566 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", "t,r,j",
3567 reg, mips_gp_register, (int) BFD_RELOC_GPREL16);
3568 p = frag_var (rs_machine_dependent, 8, 0,
3569 RELAX_ENCODE (4, 8, 0, 4, 0,
3570 mips_opts.warn_about_macros),
3571 ep->X_add_symbol, 0, NULL);
3573 macro_build_lui (p, counter, ep, reg);
3576 macro_build (p, counter, ep,
3577 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
3578 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
3581 else if (mips_pic == SVR4_PIC && ! mips_big_got)
3585 /* If this is a reference to an external symbol, we want
3586 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3588 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3590 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
3591 If there is a constant, it must be added in after. */
3592 ex.X_add_number = ep->X_add_number;
3593 ep->X_add_number = 0;
3595 macro_build ((char *) NULL, counter, ep,
3596 HAVE_32BIT_ADDRESSES ? "lw" : "ld", "t,o(b)",
3597 reg, (int) BFD_RELOC_MIPS_GOT16, mips_gp_register);
3598 macro_build ((char *) NULL, counter, (expressionS *) NULL, "nop", "");
3599 p = frag_var (rs_machine_dependent, 4, 0,
3600 RELAX_ENCODE (0, 4, -8, 0, 0, mips_opts.warn_about_macros),
3601 ep->X_add_symbol, (offsetT) 0, (char *) NULL);
3602 macro_build (p, counter, ep,
3603 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
3604 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
3605 if (ex.X_add_number != 0)
3607 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
3608 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
3609 ex.X_op = O_constant;
3610 macro_build ((char *) NULL, counter, &ex,
3611 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
3612 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
3615 else if (mips_pic == SVR4_PIC)
3620 /* This is the large GOT case. If this is a reference to an
3621 external symbol, we want
3622 lui $reg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
3624 lw $reg,<sym>($reg) (BFD_RELOC_MIPS_GOT_LO16)
3625 Otherwise, for a reference to a local symbol, we want
3626 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3628 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
3629 If we have NewABI, we want
3630 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
3631 addiu $reg,$reg,<sym> (BFD_RELOC_MIPS_GOT_OFST)
3632 If there is a constant, it must be added in after. */
3633 ex.X_add_number = ep->X_add_number;
3634 ep->X_add_number = 0;
3637 macro_build ((char *) NULL, counter, ep,
3638 HAVE_32BIT_ADDRESSES ? "lw" : "ld", "t,o(b)", reg,
3639 (int) BFD_RELOC_MIPS_GOT_PAGE, mips_gp_register);
3640 macro_build (p, counter, ep,
3641 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", "t,r,j",
3642 reg, reg, (int) BFD_RELOC_MIPS_GOT_OFST);
3646 if (reg_needs_delay (mips_gp_register))
3651 macro_build ((char *) NULL, counter, ep, "lui", "t,u", reg,
3652 (int) BFD_RELOC_MIPS_GOT_HI16);
3653 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3654 HAVE_32BIT_ADDRESSES ? "addu" : "daddu", "d,v,t", reg,
3655 reg, mips_gp_register);
3656 macro_build ((char *) NULL, counter, ep,
3657 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
3658 "t,o(b)", reg, (int) BFD_RELOC_MIPS_GOT_LO16, reg);
3659 p = frag_var (rs_machine_dependent, 12 + off, 0,
3660 RELAX_ENCODE (12, 12 + off, off, 8 + off, 0,
3661 mips_opts.warn_about_macros),
3662 ep->X_add_symbol, 0, NULL);
3665 /* We need a nop before loading from $gp. This special
3666 check is required because the lui which starts the main
3667 instruction stream does not refer to $gp, and so will not
3668 insert the nop which may be required. */
3669 macro_build (p, counter, (expressionS *) NULL, "nop", "");
3672 macro_build (p, counter, ep,
3673 HAVE_32BIT_ADDRESSES ? "lw" : "ld", "t,o(b)", reg,
3674 (int) BFD_RELOC_MIPS_GOT16, mips_gp_register);
3676 macro_build (p, counter, (expressionS *) NULL, "nop", "");
3678 macro_build (p, counter, ep,
3679 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
3680 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
3683 if (ex.X_add_number != 0)
3685 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
3686 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
3687 ex.X_op = O_constant;
3688 macro_build ((char *) NULL, counter, &ex,
3689 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
3690 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
3693 else if (mips_pic == EMBEDDED_PIC)
3696 addiu $reg,$gp,<sym> (BFD_RELOC_GPREL16)
3698 macro_build ((char *) NULL, counter, ep,
3699 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
3700 "t,r,j", reg, mips_gp_register, (int) BFD_RELOC_GPREL16);
3706 /* Move the contents of register SOURCE into register DEST. */
3709 move_register (counter, dest, source)
3714 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3715 HAVE_32BIT_GPRS ? "addu" : "daddu",
3716 "d,v,t", dest, source, 0);
3721 * This routine implements the seemingly endless macro or synthesized
3722 * instructions and addressing modes in the mips assembly language. Many
3723 * of these macros are simple and are similar to each other. These could
3724 * probably be handled by some kind of table or grammer aproach instead of
3725 * this verbose method. Others are not simple macros but are more like
3726 * optimizing code generation.
3727 * One interesting optimization is when several store macros appear
3728 * consecutivly that would load AT with the upper half of the same address.
3729 * The ensuing load upper instructions are ommited. This implies some kind
3730 * of global optimization. We currently only optimize within a single macro.
3731 * For many of the load and store macros if the address is specified as a
3732 * constant expression in the first 64k of memory (ie ld $2,0x4000c) we
3733 * first load register 'at' with zero and use it as the base register. The
3734 * mips assembler simply uses register $zero. Just one tiny optimization
3739 struct mips_cl_insn *ip;
3741 register int treg, sreg, dreg, breg;
3757 bfd_reloc_code_real_type r;
3758 int hold_mips_optimize;
3760 assert (! mips_opts.mips16);
3762 treg = (ip->insn_opcode >> 16) & 0x1f;
3763 dreg = (ip->insn_opcode >> 11) & 0x1f;
3764 sreg = breg = (ip->insn_opcode >> 21) & 0x1f;
3765 mask = ip->insn_mo->mask;
3767 expr1.X_op = O_constant;
3768 expr1.X_op_symbol = NULL;
3769 expr1.X_add_symbol = NULL;
3770 expr1.X_add_number = 1;
3782 mips_emit_delays (true);
3783 ++mips_opts.noreorder;
3784 mips_any_noreorder = 1;
3786 expr1.X_add_number = 8;
3787 macro_build ((char *) NULL, &icnt, &expr1, "bgez", "s,p", sreg);
3789 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "",
3792 move_register (&icnt, dreg, sreg);
3793 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
3794 dbl ? "dsub" : "sub", "d,v,t", dreg, 0, sreg);
3796 --mips_opts.noreorder;
3817 if (imm_expr.X_op == O_constant
3818 && imm_expr.X_add_number >= -0x8000
3819 && imm_expr.X_add_number < 0x8000)
3821 macro_build ((char *) NULL, &icnt, &imm_expr, s, "t,r,j", treg, sreg,
3822 (int) BFD_RELOC_LO16);
3825 load_register (&icnt, AT, &imm_expr, dbl);
3826 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s2, "d,v,t",
3846 if (imm_expr.X_op == O_constant
3847 && imm_expr.X_add_number >= 0
3848 && imm_expr.X_add_number < 0x10000)
3850 if (mask != M_NOR_I)
3851 macro_build ((char *) NULL, &icnt, &imm_expr, s, "t,r,i", treg,
3852 sreg, (int) BFD_RELOC_LO16);
3855 macro_build ((char *) NULL, &icnt, &imm_expr, "ori", "t,r,i",
3856 treg, sreg, (int) BFD_RELOC_LO16);
3857 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nor",
3858 "d,v,t", treg, treg, 0);
3863 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
3864 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s2, "d,v,t",
3882 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
3884 macro_build ((char *) NULL, &icnt, &offset_expr, s, "s,t,p", sreg,
3888 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
3889 macro_build ((char *) NULL, &icnt, &offset_expr, s, "s,t,p", sreg, AT);
3897 macro_build ((char *) NULL, &icnt, &offset_expr,
3898 likely ? "bgezl" : "bgez", "s,p", sreg);
3903 macro_build ((char *) NULL, &icnt, &offset_expr,
3904 likely ? "blezl" : "blez", "s,p", treg);
3907 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "slt", "d,v,t",
3909 macro_build ((char *) NULL, &icnt, &offset_expr,
3910 likely ? "beql" : "beq", "s,t,p", AT, 0);
3916 /* check for > max integer */
3917 maxnum = 0x7fffffff;
3918 if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4)
3925 if (imm_expr.X_op == O_constant
3926 && imm_expr.X_add_number >= maxnum
3927 && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4))
3930 /* result is always false */
3934 as_warn (_("Branch %s is always false (nop)"),
3936 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop",
3942 as_warn (_("Branch likely %s is always false"),
3944 macro_build ((char *) NULL, &icnt, &offset_expr, "bnel",
3949 if (imm_expr.X_op != O_constant)
3950 as_bad (_("Unsupported large constant"));
3951 ++imm_expr.X_add_number;
3955 if (mask == M_BGEL_I)
3957 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
3959 macro_build ((char *) NULL, &icnt, &offset_expr,
3960 likely ? "bgezl" : "bgez", "s,p", sreg);
3963 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
3965 macro_build ((char *) NULL, &icnt, &offset_expr,
3966 likely ? "bgtzl" : "bgtz", "s,p", sreg);
3969 maxnum = 0x7fffffff;
3970 if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4)
3977 maxnum = - maxnum - 1;
3978 if (imm_expr.X_op == O_constant
3979 && imm_expr.X_add_number <= maxnum
3980 && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4))
3983 /* result is always true */
3984 as_warn (_("Branch %s is always true"), ip->insn_mo->name);
3985 macro_build ((char *) NULL, &icnt, &offset_expr, "b", "p");
3988 set_at (&icnt, sreg, 0);
3989 macro_build ((char *) NULL, &icnt, &offset_expr,
3990 likely ? "beql" : "beq", "s,t,p", AT, 0);
4000 macro_build ((char *) NULL, &icnt, &offset_expr,
4001 likely ? "beql" : "beq", "s,t,p", 0, treg);
4004 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
4005 "d,v,t", AT, sreg, treg);
4006 macro_build ((char *) NULL, &icnt, &offset_expr,
4007 likely ? "beql" : "beq", "s,t,p", AT, 0);
4015 && imm_expr.X_op == O_constant
4016 && imm_expr.X_add_number == (offsetT) 0xffffffff))
4018 if (imm_expr.X_op != O_constant)
4019 as_bad (_("Unsupported large constant"));
4020 ++imm_expr.X_add_number;
4024 if (mask == M_BGEUL_I)
4026 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4028 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4030 macro_build ((char *) NULL, &icnt, &offset_expr,
4031 likely ? "bnel" : "bne", "s,t,p", sreg, 0);
4034 set_at (&icnt, sreg, 1);
4035 macro_build ((char *) NULL, &icnt, &offset_expr,
4036 likely ? "beql" : "beq", "s,t,p", AT, 0);
4044 macro_build ((char *) NULL, &icnt, &offset_expr,
4045 likely ? "bgtzl" : "bgtz", "s,p", sreg);
4050 macro_build ((char *) NULL, &icnt, &offset_expr,
4051 likely ? "bltzl" : "bltz", "s,p", treg);
4054 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "slt", "d,v,t",
4056 macro_build ((char *) NULL, &icnt, &offset_expr,
4057 likely ? "bnel" : "bne", "s,t,p", AT, 0);
4065 macro_build ((char *) NULL, &icnt, &offset_expr,
4066 likely ? "bnel" : "bne", "s,t,p", sreg, 0);
4071 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
4072 "d,v,t", AT, treg, sreg);
4073 macro_build ((char *) NULL, &icnt, &offset_expr,
4074 likely ? "bnel" : "bne", "s,t,p", AT, 0);
4082 macro_build ((char *) NULL, &icnt, &offset_expr,
4083 likely ? "blezl" : "blez", "s,p", sreg);
4088 macro_build ((char *) NULL, &icnt, &offset_expr,
4089 likely ? "bgezl" : "bgez", "s,p", treg);
4092 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "slt", "d,v,t",
4094 macro_build ((char *) NULL, &icnt, &offset_expr,
4095 likely ? "beql" : "beq", "s,t,p", AT, 0);
4101 maxnum = 0x7fffffff;
4102 if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4)
4109 if (imm_expr.X_op == O_constant
4110 && imm_expr.X_add_number >= maxnum
4111 && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4))
4113 if (imm_expr.X_op != O_constant)
4114 as_bad (_("Unsupported large constant"));
4115 ++imm_expr.X_add_number;
4119 if (mask == M_BLTL_I)
4121 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4123 macro_build ((char *) NULL, &icnt, &offset_expr,
4124 likely ? "bltzl" : "bltz", "s,p", sreg);
4127 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4129 macro_build ((char *) NULL, &icnt, &offset_expr,
4130 likely ? "blezl" : "blez", "s,p", sreg);
4133 set_at (&icnt, sreg, 0);
4134 macro_build ((char *) NULL, &icnt, &offset_expr,
4135 likely ? "bnel" : "bne", "s,t,p", AT, 0);
4143 macro_build ((char *) NULL, &icnt, &offset_expr,
4144 likely ? "beql" : "beq", "s,t,p", sreg, 0);
4149 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
4150 "d,v,t", AT, treg, sreg);
4151 macro_build ((char *) NULL, &icnt, &offset_expr,
4152 likely ? "beql" : "beq", "s,t,p", AT, 0);
4160 && imm_expr.X_op == O_constant
4161 && imm_expr.X_add_number == (offsetT) 0xffffffff))
4163 if (imm_expr.X_op != O_constant)
4164 as_bad (_("Unsupported large constant"));
4165 ++imm_expr.X_add_number;
4169 if (mask == M_BLTUL_I)
4171 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4173 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4175 macro_build ((char *) NULL, &icnt, &offset_expr,
4176 likely ? "beql" : "beq",
4180 set_at (&icnt, sreg, 1);
4181 macro_build ((char *) NULL, &icnt, &offset_expr,
4182 likely ? "bnel" : "bne", "s,t,p", AT, 0);
4190 macro_build ((char *) NULL, &icnt, &offset_expr,
4191 likely ? "bltzl" : "bltz", "s,p", sreg);
4196 macro_build ((char *) NULL, &icnt, &offset_expr,
4197 likely ? "bgtzl" : "bgtz", "s,p", treg);
4200 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "slt", "d,v,t",
4202 macro_build ((char *) NULL, &icnt, &offset_expr,
4203 likely ? "bnel" : "bne", "s,t,p", AT, 0);
4213 macro_build ((char *) NULL, &icnt, &offset_expr,
4214 likely ? "bnel" : "bne", "s,t,p", 0, treg);
4217 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
4220 macro_build ((char *) NULL, &icnt, &offset_expr,
4221 likely ? "bnel" : "bne", "s,t,p", AT, 0);
4236 as_warn (_("Divide by zero."));
4238 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "teq",
4241 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
4246 mips_emit_delays (true);
4247 ++mips_opts.noreorder;
4248 mips_any_noreorder = 1;
4251 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "teq",
4253 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4254 dbl ? "ddiv" : "div", "z,s,t", sreg, treg);
4258 expr1.X_add_number = 8;
4259 macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, 0);
4260 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4261 dbl ? "ddiv" : "div", "z,s,t", sreg, treg);
4262 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
4265 expr1.X_add_number = -1;
4266 macro_build ((char *) NULL, &icnt, &expr1,
4267 dbl ? "daddiu" : "addiu",
4268 "t,r,j", AT, 0, (int) BFD_RELOC_LO16);
4269 expr1.X_add_number = mips_trap ? (dbl ? 12 : 8) : (dbl ? 20 : 16);
4270 macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, AT);
4273 expr1.X_add_number = 1;
4274 macro_build ((char *) NULL, &icnt, &expr1, "daddiu", "t,r,j", AT, 0,
4275 (int) BFD_RELOC_LO16);
4276 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "dsll32",
4277 "d,w,<", AT, AT, 31);
4281 expr1.X_add_number = 0x80000000;
4282 macro_build ((char *) NULL, &icnt, &expr1, "lui", "t,u", AT,
4283 (int) BFD_RELOC_HI16);
4287 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "teq",
4289 /* We want to close the noreorder block as soon as possible, so
4290 that later insns are available for delay slot filling. */
4291 --mips_opts.noreorder;
4295 expr1.X_add_number = 8;
4296 macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", sreg, AT);
4297 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "",
4300 /* We want to close the noreorder block as soon as possible, so
4301 that later insns are available for delay slot filling. */
4302 --mips_opts.noreorder;
4304 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
4307 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d", dreg);
4346 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4348 as_warn (_("Divide by zero."));
4350 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "teq",
4353 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
4357 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4359 if (strcmp (s2, "mflo") == 0)
4360 move_register (&icnt, dreg, sreg);
4362 move_register (&icnt, dreg, 0);
4365 if (imm_expr.X_op == O_constant
4366 && imm_expr.X_add_number == -1
4367 && s[strlen (s) - 1] != 'u')
4369 if (strcmp (s2, "mflo") == 0)
4371 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4372 dbl ? "dneg" : "neg", "d,w", dreg, sreg);
4375 move_register (&icnt, dreg, 0);
4379 load_register (&icnt, AT, &imm_expr, dbl);
4380 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "z,s,t",
4382 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s2, "d", dreg);
4401 mips_emit_delays (true);
4402 ++mips_opts.noreorder;
4403 mips_any_noreorder = 1;
4406 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "teq",
4408 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "z,s,t",
4410 /* We want to close the noreorder block as soon as possible, so
4411 that later insns are available for delay slot filling. */
4412 --mips_opts.noreorder;
4416 expr1.X_add_number = 8;
4417 macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, 0);
4418 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "z,s,t",
4421 /* We want to close the noreorder block as soon as possible, so
4422 that later insns are available for delay slot filling. */
4423 --mips_opts.noreorder;
4424 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
4427 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s2, "d", dreg);
4433 /* Load the address of a symbol into a register. If breg is not
4434 zero, we then add a base register to it. */
4436 if (dbl && HAVE_32BIT_GPRS)
4437 as_warn (_("dla used to load 32-bit register"));
4439 if (! dbl && HAVE_64BIT_OBJECTS)
4440 as_warn (_("la used to load 64-bit address"));
4453 /* When generating embedded PIC code, we permit expressions of
4456 la $treg,foo-bar($breg)
4457 where bar is an address in the current section. These are used
4458 when getting the addresses of functions. We don't permit
4459 X_add_number to be non-zero, because if the symbol is
4460 external the relaxing code needs to know that any addend is
4461 purely the offset to X_op_symbol. */
4462 if (mips_pic == EMBEDDED_PIC
4463 && offset_expr.X_op == O_subtract
4464 && (symbol_constant_p (offset_expr.X_op_symbol)
4465 ? S_GET_SEGMENT (offset_expr.X_op_symbol) == now_seg
4466 : (symbol_equated_p (offset_expr.X_op_symbol)
4468 (symbol_get_value_expression (offset_expr.X_op_symbol)
4471 && (offset_expr.X_add_number == 0
4472 || OUTPUT_FLAVOR == bfd_target_elf_flavour))
4478 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
4479 tempreg, (int) BFD_RELOC_PCREL_HI16_S);
4483 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
4484 tempreg, (int) BFD_RELOC_PCREL_HI16_S);
4485 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4486 (dbl || HAVE_64BIT_ADDRESSES) ? "daddu" : "addu",
4487 "d,v,t", tempreg, tempreg, breg);
4489 macro_build ((char *) NULL, &icnt, &offset_expr,
4490 (dbl || HAVE_64BIT_ADDRESSES) ? "daddiu" : "addiu",
4491 "t,r,j", treg, tempreg, (int) BFD_RELOC_PCREL_LO16);
4497 if (offset_expr.X_op != O_symbol
4498 && offset_expr.X_op != O_constant)
4500 as_bad (_("expression too complex"));
4501 offset_expr.X_op = O_constant;
4504 if (offset_expr.X_op == O_constant)
4505 load_register (&icnt, tempreg, &offset_expr,
4506 ((mips_pic == EMBEDDED_PIC || mips_pic == NO_PIC)
4507 ? (dbl || HAVE_64BIT_ADDRESSES)
4508 : HAVE_64BIT_ADDRESSES));
4509 else if (mips_pic == NO_PIC)
4511 /* If this is a reference to a GP relative symbol, we want
4512 addiu $tempreg,$gp,<sym> (BFD_RELOC_GPREL16)
4514 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
4515 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
4516 If we have a constant, we need two instructions anyhow,
4517 so we may as well always use the latter form.
4519 With 64bit address space and a usable $at we want
4520 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
4521 lui $at,<sym> (BFD_RELOC_HI16_S)
4522 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
4523 daddiu $at,<sym> (BFD_RELOC_LO16)
4525 dadd $tempreg,$tempreg,$at
4527 If $at is already in use, we use an path which is suboptimal
4528 on superscalar processors.
4529 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
4530 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
4532 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
4534 daddiu $tempreg,<sym> (BFD_RELOC_LO16)
4537 if (HAVE_64BIT_ADDRESSES)
4539 /* We don't do GP optimization for now because RELAX_ENCODE can't
4540 hold the data for such large chunks. */
4544 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
4545 tempreg, (int) BFD_RELOC_MIPS_HIGHEST);
4546 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
4547 AT, (int) BFD_RELOC_HI16_S);
4548 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4549 tempreg, tempreg, (int) BFD_RELOC_MIPS_HIGHER);
4550 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4551 AT, AT, (int) BFD_RELOC_LO16);
4552 macro_build (p, &icnt, (expressionS *) NULL, "dsll32",
4553 "d,w,<", tempreg, tempreg, 0);
4554 macro_build (p, &icnt, (expressionS *) NULL, "dadd", "d,v,t",
4555 tempreg, tempreg, AT);
4560 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
4561 tempreg, (int) BFD_RELOC_MIPS_HIGHEST);
4562 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4563 tempreg, tempreg, (int) BFD_RELOC_MIPS_HIGHER);
4564 macro_build (p, &icnt, (expressionS *) NULL, "dsll", "d,w,<",
4565 tempreg, tempreg, 16);
4566 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4567 tempreg, tempreg, (int) BFD_RELOC_HI16_S);
4568 macro_build (p, &icnt, (expressionS *) NULL, "dsll", "d,w,<",
4569 tempreg, tempreg, 16);
4570 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4571 tempreg, tempreg, (int) BFD_RELOC_LO16);
4576 if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
4577 && ! nopic_need_relax (offset_expr.X_add_symbol, 1))
4580 macro_build ((char *) NULL, &icnt, &offset_expr, "addiu",
4581 "t,r,j", tempreg, mips_gp_register,
4582 (int) BFD_RELOC_GPREL16);
4583 p = frag_var (rs_machine_dependent, 8, 0,
4584 RELAX_ENCODE (4, 8, 0, 4, 0,
4585 mips_opts.warn_about_macros),
4586 offset_expr.X_add_symbol, 0, NULL);
4588 macro_build_lui (p, &icnt, &offset_expr, tempreg);
4591 macro_build (p, &icnt, &offset_expr, "addiu",
4592 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
4595 else if (mips_pic == SVR4_PIC && ! mips_big_got)
4597 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT16;
4599 /* If this is a reference to an external symbol, and there
4600 is no constant, we want
4601 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4602 or if tempreg is PIC_CALL_REG
4603 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
4604 For a local symbol, we want
4605 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4607 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
4609 If we have a small constant, and this is a reference to
4610 an external symbol, we want
4611 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4613 addiu $tempreg,$tempreg,<constant>
4614 For a local symbol, we want the same instruction
4615 sequence, but we output a BFD_RELOC_LO16 reloc on the
4618 If we have a large constant, and this is a reference to
4619 an external symbol, we want
4620 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4621 lui $at,<hiconstant>
4622 addiu $at,$at,<loconstant>
4623 addu $tempreg,$tempreg,$at
4624 For a local symbol, we want the same instruction
4625 sequence, but we output a BFD_RELOC_LO16 reloc on the
4626 addiu instruction. */
4627 expr1.X_add_number = offset_expr.X_add_number;
4628 offset_expr.X_add_number = 0;
4630 if (expr1.X_add_number == 0 && tempreg == PIC_CALL_REG)
4631 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL16;
4632 macro_build ((char *) NULL, &icnt, &offset_expr,
4633 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
4634 "t,o(b)", tempreg, lw_reloc_type, mips_gp_register);
4635 if (expr1.X_add_number == 0)
4644 /* We're going to put in an addu instruction using
4645 tempreg, so we may as well insert the nop right
4647 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4651 p = frag_var (rs_machine_dependent, 8 - off, 0,
4652 RELAX_ENCODE (0, 8 - off, -4 - off, 4 - off, 0,
4654 ? mips_opts.warn_about_macros
4656 offset_expr.X_add_symbol, 0, NULL);
4659 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
4662 macro_build (p, &icnt, &expr1,
4663 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
4664 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
4665 /* FIXME: If breg == 0, and the next instruction uses
4666 $tempreg, then if this variant case is used an extra
4667 nop will be generated. */
4669 else if (expr1.X_add_number >= -0x8000
4670 && expr1.X_add_number < 0x8000)
4672 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4674 macro_build ((char *) NULL, &icnt, &expr1,
4675 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
4676 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
4677 frag_var (rs_machine_dependent, 0, 0,
4678 RELAX_ENCODE (0, 0, -12, -4, 0, 0),
4679 offset_expr.X_add_symbol, 0, NULL);
4685 /* If we are going to add in a base register, and the
4686 target register and the base register are the same,
4687 then we are using AT as a temporary register. Since
4688 we want to load the constant into AT, we add our
4689 current AT (from the global offset table) and the
4690 register into the register now, and pretend we were
4691 not using a base register. */
4696 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4698 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4699 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
4700 "d,v,t", treg, AT, breg);
4706 /* Set mips_optimize around the lui instruction to avoid
4707 inserting an unnecessary nop after the lw. */
4708 hold_mips_optimize = mips_optimize;
4710 macro_build_lui (NULL, &icnt, &expr1, AT);
4711 mips_optimize = hold_mips_optimize;
4713 macro_build ((char *) NULL, &icnt, &expr1,
4714 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
4715 "t,r,j", AT, AT, (int) BFD_RELOC_LO16);
4716 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4717 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
4718 "d,v,t", tempreg, tempreg, AT);
4719 frag_var (rs_machine_dependent, 0, 0,
4720 RELAX_ENCODE (0, 0, -16 + off1, -8, 0, 0),
4721 offset_expr.X_add_symbol, 0, NULL);
4725 else if (mips_pic == SVR4_PIC)
4729 int lui_reloc_type = (int) BFD_RELOC_MIPS_GOT_HI16;
4730 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT_LO16;
4732 /* This is the large GOT case. If this is a reference to an
4733 external symbol, and there is no constant, we want
4734 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
4735 addu $tempreg,$tempreg,$gp
4736 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
4737 or if tempreg is PIC_CALL_REG
4738 lui $tempreg,<sym> (BFD_RELOC_MIPS_CALL_HI16)
4739 addu $tempreg,$tempreg,$gp
4740 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_CALL_LO16)
4741 For a local symbol, we want
4742 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4744 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
4746 If we have a small constant, and this is a reference to
4747 an external symbol, we want
4748 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
4749 addu $tempreg,$tempreg,$gp
4750 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
4752 addiu $tempreg,$tempreg,<constant>
4753 For a local symbol, we want
4754 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4756 addiu $tempreg,$tempreg,<constant> (BFD_RELOC_LO16)
4758 If we have a large constant, and this is a reference to
4759 an external symbol, we want
4760 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
4761 addu $tempreg,$tempreg,$gp
4762 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
4763 lui $at,<hiconstant>
4764 addiu $at,$at,<loconstant>
4765 addu $tempreg,$tempreg,$at
4766 For a local symbol, we want
4767 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4768 lui $at,<hiconstant>
4769 addiu $at,$at,<loconstant> (BFD_RELOC_LO16)
4770 addu $tempreg,$tempreg,$at
4772 For NewABI, we want for data addresses
4773 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
4774 If tempreg is PIC_CALL_REG pointing to a external symbol, we want
4775 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
4779 int reloc_type = (tempreg == PIC_CALL_REG
4780 ? BFD_RELOC_MIPS_CALL16
4781 : BFD_RELOC_MIPS_GOT_DISP);
4783 macro_build ((char *) NULL, &icnt, &offset_expr,
4784 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
4785 "t,o(b)", tempreg, reloc_type, mips_gp_register);
4788 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4789 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
4790 "d,v,t", treg, tempreg, breg);
4797 expr1.X_add_number = offset_expr.X_add_number;
4798 offset_expr.X_add_number = 0;
4800 if (reg_needs_delay (mips_gp_register))
4804 if (expr1.X_add_number == 0 && tempreg == PIC_CALL_REG)
4806 lui_reloc_type = (int) BFD_RELOC_MIPS_CALL_HI16;
4807 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL_LO16;
4809 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
4810 tempreg, lui_reloc_type);
4811 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4812 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
4813 "d,v,t", tempreg, tempreg, mips_gp_register);
4814 macro_build ((char *) NULL, &icnt, &offset_expr,
4815 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
4816 "t,o(b)", tempreg, lw_reloc_type, tempreg);
4817 if (expr1.X_add_number == 0)
4825 /* We're going to put in an addu instruction using
4826 tempreg, so we may as well insert the nop right
4828 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4833 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
4834 RELAX_ENCODE (12 + off, 12 + gpdel, gpdel,
4837 ? mips_opts.warn_about_macros
4839 offset_expr.X_add_symbol, 0, NULL);
4841 else if (expr1.X_add_number >= -0x8000
4842 && expr1.X_add_number < 0x8000)
4844 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4846 macro_build ((char *) NULL, &icnt, &expr1,
4847 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
4848 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
4850 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
4851 RELAX_ENCODE (20, 12 + gpdel, gpdel, 8 + gpdel, 0,
4853 ? mips_opts.warn_about_macros
4855 offset_expr.X_add_symbol, 0, NULL);
4861 /* If we are going to add in a base register, and the
4862 target register and the base register are the same,
4863 then we are using AT as a temporary register. Since
4864 we want to load the constant into AT, we add our
4865 current AT (from the global offset table) and the
4866 register into the register now, and pretend we were
4867 not using a base register. */
4875 assert (tempreg == AT);
4876 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4878 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4879 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
4880 "d,v,t", treg, AT, breg);
4885 /* Set mips_optimize around the lui instruction to avoid
4886 inserting an unnecessary nop after the lw. */
4887 hold_mips_optimize = mips_optimize;
4889 macro_build_lui (NULL, &icnt, &expr1, AT);
4890 mips_optimize = hold_mips_optimize;
4892 macro_build ((char *) NULL, &icnt, &expr1,
4893 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
4894 "t,r,j", AT, AT, (int) BFD_RELOC_LO16);
4895 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4896 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
4897 "d,v,t", dreg, dreg, AT);
4899 p = frag_var (rs_machine_dependent, 16 + gpdel + adj, 0,
4900 RELAX_ENCODE (24 + adj, 16 + gpdel + adj, gpdel,
4903 ? mips_opts.warn_about_macros
4905 offset_expr.X_add_symbol, 0, NULL);
4912 /* This is needed because this instruction uses $gp, but
4913 the first instruction on the main stream does not. */
4914 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
4917 macro_build (p, &icnt, &offset_expr,
4918 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
4919 "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT16,
4922 if (expr1.X_add_number >= -0x8000
4923 && expr1.X_add_number < 0x8000)
4925 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
4927 macro_build (p, &icnt, &expr1,
4928 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
4929 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
4930 /* FIXME: If add_number is 0, and there was no base
4931 register, the external symbol case ended with a load,
4932 so if the symbol turns out to not be external, and
4933 the next instruction uses tempreg, an unnecessary nop
4934 will be inserted. */
4940 /* We must add in the base register now, as in the
4941 external symbol case. */
4942 assert (tempreg == AT);
4943 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
4945 macro_build (p, &icnt, (expressionS *) NULL,
4946 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
4947 "d,v,t", treg, AT, breg);
4950 /* We set breg to 0 because we have arranged to add
4951 it in in both cases. */
4955 macro_build_lui (p, &icnt, &expr1, AT);
4957 macro_build (p, &icnt, &expr1,
4958 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
4959 "t,r,j", AT, AT, (int) BFD_RELOC_LO16);
4961 macro_build (p, &icnt, (expressionS *) NULL,
4962 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
4963 "d,v,t", tempreg, tempreg, AT);
4967 else if (mips_pic == EMBEDDED_PIC)
4970 addiu $tempreg,$gp,<sym> (BFD_RELOC_GPREL16)
4972 macro_build ((char *) NULL, &icnt, &offset_expr,
4973 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", "t,r,j",
4974 tempreg, mips_gp_register, (int) BFD_RELOC_GPREL16);
4983 if (mips_pic == EMBEDDED_PIC || mips_pic == NO_PIC)
4984 s = (dbl || HAVE_64BIT_ADDRESSES) ? "daddu" : "addu";
4986 s = HAVE_64BIT_ADDRESSES ? "daddu" : "addu";
4988 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s,
4989 "d,v,t", treg, tempreg, breg);
4998 /* The j instruction may not be used in PIC code, since it
4999 requires an absolute address. We convert it to a b
5001 if (mips_pic == NO_PIC)
5002 macro_build ((char *) NULL, &icnt, &offset_expr, "j", "a");
5004 macro_build ((char *) NULL, &icnt, &offset_expr, "b", "p");
5007 /* The jal instructions must be handled as macros because when
5008 generating PIC code they expand to multi-instruction
5009 sequences. Normally they are simple instructions. */
5014 if (mips_pic == NO_PIC
5015 || mips_pic == EMBEDDED_PIC)
5016 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "jalr",
5018 else if (mips_pic == SVR4_PIC)
5020 if (sreg != PIC_CALL_REG)
5021 as_warn (_("MIPS PIC call to register other than $25"));
5023 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "jalr",
5027 if (mips_cprestore_offset < 0)
5028 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5031 if (! mips_frame_reg_valid)
5033 as_warn (_("No .frame pseudo-op used in PIC code"));
5034 /* Quiet this warning. */
5035 mips_frame_reg_valid = 1;
5037 if (! mips_cprestore_valid)
5039 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5040 /* Quiet this warning. */
5041 mips_cprestore_valid = 1;
5043 expr1.X_add_number = mips_cprestore_offset;
5044 macro_build ((char *) NULL, &icnt, &expr1,
5045 HAVE_32BIT_ADDRESSES ? "lw" : "ld", "t,o(b)",
5046 mips_gp_register, (int) BFD_RELOC_LO16,
5057 if (mips_pic == NO_PIC)
5058 macro_build ((char *) NULL, &icnt, &offset_expr, "jal", "a");
5059 else if (mips_pic == SVR4_PIC)
5063 /* If this is a reference to an external symbol, and we are
5064 using a small GOT, we want
5065 lw $25,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
5069 lw $gp,cprestore($sp)
5070 The cprestore value is set using the .cprestore
5071 pseudo-op. If we are using a big GOT, we want
5072 lui $25,<sym> (BFD_RELOC_MIPS_CALL_HI16)
5074 lw $25,<sym>($25) (BFD_RELOC_MIPS_CALL_LO16)
5078 lw $gp,cprestore($sp)
5079 If the symbol is not external, we want
5080 lw $25,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5082 addiu $25,$25,<sym> (BFD_RELOC_LO16)
5085 lw $gp,cprestore($sp)
5087 lw $25,<sym>($gp) (BFD_RELOC_MIPS_GOT_DISP)
5088 jalr $ra,$25 (BFD_RELOC_MIPS_JALR)
5092 macro_build ((char *) NULL, &icnt, &offset_expr,
5093 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5094 "t,o(b)", PIC_CALL_REG,
5095 (int) BFD_RELOC_MIPS_GOT_DISP, mips_gp_register);
5096 macro_build_jalr (icnt, &offset_expr);
5103 macro_build ((char *) NULL, &icnt, &offset_expr,
5104 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5105 "t,o(b)", PIC_CALL_REG,
5106 (int) BFD_RELOC_MIPS_CALL16, mips_gp_register);
5107 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5109 p = frag_var (rs_machine_dependent, 4, 0,
5110 RELAX_ENCODE (0, 4, -8, 0, 0, 0),
5111 offset_expr.X_add_symbol, 0, NULL);
5117 if (reg_needs_delay (mips_gp_register))
5121 macro_build ((char *) NULL, &icnt, &offset_expr, "lui",
5122 "t,u", PIC_CALL_REG,
5123 (int) BFD_RELOC_MIPS_CALL_HI16);
5124 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5125 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5126 "d,v,t", PIC_CALL_REG, PIC_CALL_REG,
5128 macro_build ((char *) NULL, &icnt, &offset_expr,
5129 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5130 "t,o(b)", PIC_CALL_REG,
5131 (int) BFD_RELOC_MIPS_CALL_LO16, PIC_CALL_REG);
5132 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5134 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
5135 RELAX_ENCODE (16, 12 + gpdel, gpdel,
5137 offset_expr.X_add_symbol, 0, NULL);
5140 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
5143 macro_build (p, &icnt, &offset_expr,
5144 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5145 "t,o(b)", PIC_CALL_REG,
5146 (int) BFD_RELOC_MIPS_GOT16, mips_gp_register);
5148 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
5151 macro_build (p, &icnt, &offset_expr,
5152 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
5153 "t,r,j", PIC_CALL_REG, PIC_CALL_REG,
5154 (int) BFD_RELOC_LO16);
5155 macro_build_jalr (icnt, &offset_expr);
5157 if (mips_cprestore_offset < 0)
5158 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5161 if (! mips_frame_reg_valid)
5163 as_warn (_("No .frame pseudo-op used in PIC code"));
5164 /* Quiet this warning. */
5165 mips_frame_reg_valid = 1;
5167 if (! mips_cprestore_valid)
5169 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5170 /* Quiet this warning. */
5171 mips_cprestore_valid = 1;
5173 if (mips_opts.noreorder)
5174 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5176 expr1.X_add_number = mips_cprestore_offset;
5177 macro_build ((char *) NULL, &icnt, &expr1,
5178 HAVE_32BIT_ADDRESSES ? "lw" : "ld", "t,o(b)",
5179 mips_gp_register, (int) BFD_RELOC_LO16,
5184 else if (mips_pic == EMBEDDED_PIC)
5186 macro_build ((char *) NULL, &icnt, &offset_expr, "bal", "p");
5187 /* The linker may expand the call to a longer sequence which
5188 uses $at, so we must break rather than return. */
5213 /* Itbl support may require additional care here. */
5218 /* Itbl support may require additional care here. */
5223 /* Itbl support may require additional care here. */
5228 /* Itbl support may require additional care here. */
5240 if (mips_arch == CPU_R4650)
5242 as_bad (_("opcode not supported on this processor"));
5246 /* Itbl support may require additional care here. */
5251 /* Itbl support may require additional care here. */
5256 /* Itbl support may require additional care here. */
5276 if (breg == treg || coproc || lr)
5298 /* Itbl support may require additional care here. */
5303 /* Itbl support may require additional care here. */
5308 /* Itbl support may require additional care here. */
5313 /* Itbl support may require additional care here. */
5329 if (mips_arch == CPU_R4650)
5331 as_bad (_("opcode not supported on this processor"));
5336 /* Itbl support may require additional care here. */
5340 /* Itbl support may require additional care here. */
5345 /* Itbl support may require additional care here. */
5357 /* Itbl support may require additional care here. */
5358 if (mask == M_LWC1_AB
5359 || mask == M_SWC1_AB
5360 || mask == M_LDC1_AB
5361 || mask == M_SDC1_AB
5370 /* For embedded PIC, we allow loads where the offset is calculated
5371 by subtracting a symbol in the current segment from an unknown
5372 symbol, relative to a base register, e.g.:
5373 <op> $treg, <sym>-<localsym>($breg)
5374 This is used by the compiler for switch statements. */
5375 if (mips_pic == EMBEDDED_PIC
5376 && offset_expr.X_op == O_subtract
5377 && (symbol_constant_p (offset_expr.X_op_symbol)
5378 ? S_GET_SEGMENT (offset_expr.X_op_symbol) == now_seg
5379 : (symbol_equated_p (offset_expr.X_op_symbol)
5381 (symbol_get_value_expression (offset_expr.X_op_symbol)
5385 && (offset_expr.X_add_number == 0
5386 || OUTPUT_FLAVOR == bfd_target_elf_flavour))
5388 /* For this case, we output the instructions:
5389 lui $tempreg,<sym> (BFD_RELOC_PCREL_HI16_S)
5390 addiu $tempreg,$tempreg,$breg
5391 <op> $treg,<sym>($tempreg) (BFD_RELOC_PCREL_LO16)
5392 If the relocation would fit entirely in 16 bits, it would be
5394 <op> $treg,<sym>($breg) (BFD_RELOC_PCREL_LO16)
5395 instead, but that seems quite difficult. */
5396 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
5397 tempreg, (int) BFD_RELOC_PCREL_HI16_S);
5398 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5399 ((bfd_arch_bits_per_address (stdoutput) == 32
5400 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5401 ? "addu" : "daddu"),
5402 "d,v,t", tempreg, tempreg, breg);
5403 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, treg,
5404 (int) BFD_RELOC_PCREL_LO16, tempreg);
5410 if (offset_expr.X_op != O_constant
5411 && offset_expr.X_op != O_symbol)
5413 as_bad (_("expression too complex"));
5414 offset_expr.X_op = O_constant;
5417 /* A constant expression in PIC code can be handled just as it
5418 is in non PIC code. */
5419 if (mips_pic == NO_PIC
5420 || offset_expr.X_op == O_constant)
5424 /* If this is a reference to a GP relative symbol, and there
5425 is no base register, we want
5426 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
5427 Otherwise, if there is no base register, we want
5428 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
5429 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5430 If we have a constant, we need two instructions anyhow,
5431 so we always use the latter form.
5433 If we have a base register, and this is a reference to a
5434 GP relative symbol, we want
5435 addu $tempreg,$breg,$gp
5436 <op> $treg,<sym>($tempreg) (BFD_RELOC_GPREL16)
5438 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
5439 addu $tempreg,$tempreg,$breg
5440 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5441 With a constant we always use the latter case.
5443 With 64bit address space and no base register and $at usable,
5445 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5446 lui $at,<sym> (BFD_RELOC_HI16_S)
5447 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
5450 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5451 If we have a base register, we want
5452 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5453 lui $at,<sym> (BFD_RELOC_HI16_S)
5454 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
5458 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5460 Without $at we can't generate the optimal path for superscalar
5461 processors here since this would require two temporary registers.
5462 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5463 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
5465 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
5467 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5468 If we have a base register, we want
5469 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5470 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
5472 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
5474 daddu $tempreg,$tempreg,$breg
5475 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5477 If we have 64-bit addresses, as an optimization, for
5478 addresses which are 32-bit constants (e.g. kseg0/kseg1
5479 addresses) we fall back to the 32-bit address generation
5480 mechanism since it is more efficient. This code should
5481 probably attempt to generate 64-bit constants more
5482 efficiently in general.
5484 if (HAVE_64BIT_ADDRESSES
5485 && !(offset_expr.X_op == O_constant
5486 && IS_SEXT_32BIT_NUM (offset_expr.X_add_number)))
5490 /* We don't do GP optimization for now because RELAX_ENCODE can't
5491 hold the data for such large chunks. */
5495 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
5496 tempreg, (int) BFD_RELOC_MIPS_HIGHEST);
5497 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
5498 AT, (int) BFD_RELOC_HI16_S);
5499 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
5500 tempreg, tempreg, (int) BFD_RELOC_MIPS_HIGHER);
5502 macro_build (p, &icnt, (expressionS *) NULL, "daddu",
5503 "d,v,t", AT, AT, breg);
5504 macro_build (p, &icnt, (expressionS *) NULL, "dsll32",
5505 "d,w,<", tempreg, tempreg, 0);
5506 macro_build (p, &icnt, (expressionS *) NULL, "daddu",
5507 "d,v,t", tempreg, tempreg, AT);
5508 macro_build (p, &icnt, &offset_expr, s,
5509 fmt, treg, (int) BFD_RELOC_LO16, tempreg);
5514 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
5515 tempreg, (int) BFD_RELOC_MIPS_HIGHEST);
5516 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
5517 tempreg, tempreg, (int) BFD_RELOC_MIPS_HIGHER);
5518 macro_build (p, &icnt, (expressionS *) NULL, "dsll",
5519 "d,w,<", tempreg, tempreg, 16);
5520 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
5521 tempreg, tempreg, (int) BFD_RELOC_HI16_S);
5522 macro_build (p, &icnt, (expressionS *) NULL, "dsll",
5523 "d,w,<", tempreg, tempreg, 16);
5525 macro_build (p, &icnt, (expressionS *) NULL, "daddu",
5526 "d,v,t", tempreg, tempreg, breg);
5527 macro_build (p, &icnt, &offset_expr, s,
5528 fmt, treg, (int) BFD_RELOC_LO16, tempreg);
5536 if ((valueT) offset_expr.X_add_number > MAX_GPREL_OFFSET
5537 || nopic_need_relax (offset_expr.X_add_symbol, 1))
5542 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
5543 treg, (int) BFD_RELOC_GPREL16,
5545 p = frag_var (rs_machine_dependent, 8, 0,
5546 RELAX_ENCODE (4, 8, 0, 4, 0,
5547 (mips_opts.warn_about_macros
5549 && mips_opts.noat))),
5550 offset_expr.X_add_symbol, 0, NULL);
5553 macro_build_lui (p, &icnt, &offset_expr, tempreg);
5556 macro_build (p, &icnt, &offset_expr, s, fmt, treg,
5557 (int) BFD_RELOC_LO16, tempreg);
5561 if ((valueT) offset_expr.X_add_number > MAX_GPREL_OFFSET
5562 || nopic_need_relax (offset_expr.X_add_symbol, 1))
5567 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5568 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5569 "d,v,t", tempreg, breg, mips_gp_register);
5570 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
5571 treg, (int) BFD_RELOC_GPREL16, tempreg);
5572 p = frag_var (rs_machine_dependent, 12, 0,
5573 RELAX_ENCODE (8, 12, 0, 8, 0, 0),
5574 offset_expr.X_add_symbol, 0, NULL);
5576 macro_build_lui (p, &icnt, &offset_expr, tempreg);
5579 macro_build (p, &icnt, (expressionS *) NULL,
5580 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5581 "d,v,t", tempreg, tempreg, breg);
5584 macro_build (p, &icnt, &offset_expr, s, fmt, treg,
5585 (int) BFD_RELOC_LO16, tempreg);
5588 else if (mips_pic == SVR4_PIC && ! mips_big_got)
5592 /* If this is a reference to an external symbol, we want
5593 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5595 <op> $treg,0($tempreg)
5597 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5599 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
5600 <op> $treg,0($tempreg)
5601 If there is a base register, we add it to $tempreg before
5602 the <op>. If there is a constant, we stick it in the
5603 <op> instruction. We don't handle constants larger than
5604 16 bits, because we have no way to load the upper 16 bits
5605 (actually, we could handle them for the subset of cases
5606 in which we are not using $at). */
5607 assert (offset_expr.X_op == O_symbol);
5608 expr1.X_add_number = offset_expr.X_add_number;
5609 offset_expr.X_add_number = 0;
5610 if (expr1.X_add_number < -0x8000
5611 || expr1.X_add_number >= 0x8000)
5612 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
5614 macro_build ((char *) NULL, &icnt, &offset_expr,
5615 HAVE_32BIT_ADDRESSES ? "lw" : "ld", "t,o(b)", tempreg,
5616 (int) BFD_RELOC_MIPS_GOT16, mips_gp_register);
5617 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
5618 p = frag_var (rs_machine_dependent, 4, 0,
5619 RELAX_ENCODE (0, 4, -8, 0, 0, 0),
5620 offset_expr.X_add_symbol, 0, NULL);
5621 macro_build (p, &icnt, &offset_expr,
5622 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
5623 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
5625 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5626 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5627 "d,v,t", tempreg, tempreg, breg);
5628 macro_build ((char *) NULL, &icnt, &expr1, s, fmt, treg,
5629 (int) BFD_RELOC_LO16, tempreg);
5631 else if (mips_pic == SVR4_PIC)
5636 /* If this is a reference to an external symbol, we want
5637 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5638 addu $tempreg,$tempreg,$gp
5639 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5640 <op> $treg,0($tempreg)
5642 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5644 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
5645 <op> $treg,0($tempreg)
5646 If there is a base register, we add it to $tempreg before
5647 the <op>. If there is a constant, we stick it in the
5648 <op> instruction. We don't handle constants larger than
5649 16 bits, because we have no way to load the upper 16 bits
5650 (actually, we could handle them for the subset of cases
5651 in which we are not using $at).
5654 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT_PAGE)
5655 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_MIPS_GOT_OFST)
5656 <op> $treg,0($tempreg)
5658 assert (offset_expr.X_op == O_symbol);
5659 expr1.X_add_number = offset_expr.X_add_number;
5660 offset_expr.X_add_number = 0;
5661 if (expr1.X_add_number < -0x8000
5662 || expr1.X_add_number >= 0x8000)
5663 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
5666 macro_build ((char *) NULL, &icnt, &offset_expr,
5667 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5668 "t,o(b)", tempreg, BFD_RELOC_MIPS_GOT_PAGE,
5670 macro_build ((char *) NULL, &icnt, &offset_expr,
5671 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
5672 "t,r,j", tempreg, tempreg,
5673 BFD_RELOC_MIPS_GOT_OFST);
5675 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5676 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5677 "d,v,t", tempreg, tempreg, breg);
5678 macro_build ((char *) NULL, &icnt, &expr1, s, fmt, treg,
5679 (int) BFD_RELOC_LO16, tempreg);
5686 if (reg_needs_delay (mips_gp_register))
5691 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
5692 tempreg, (int) BFD_RELOC_MIPS_GOT_HI16);
5693 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5694 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5695 "d,v,t", tempreg, tempreg, mips_gp_register);
5696 macro_build ((char *) NULL, &icnt, &offset_expr,
5697 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5698 "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT_LO16,
5700 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
5701 RELAX_ENCODE (12, 12 + gpdel, gpdel, 8 + gpdel, 0, 0),
5702 offset_expr.X_add_symbol, 0, NULL);
5705 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
5708 macro_build (p, &icnt, &offset_expr,
5709 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5710 "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT16,
5713 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
5715 macro_build (p, &icnt, &offset_expr,
5716 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
5717 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
5719 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5720 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5721 "d,v,t", tempreg, tempreg, breg);
5722 macro_build ((char *) NULL, &icnt, &expr1, s, fmt, treg,
5723 (int) BFD_RELOC_LO16, tempreg);
5725 else if (mips_pic == EMBEDDED_PIC)
5727 /* If there is no base register, we want
5728 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
5729 If there is a base register, we want
5730 addu $tempreg,$breg,$gp
5731 <op> $treg,<sym>($tempreg) (BFD_RELOC_GPREL16)
5733 assert (offset_expr.X_op == O_symbol);
5736 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
5737 treg, (int) BFD_RELOC_GPREL16, mips_gp_register);
5742 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5743 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5744 "d,v,t", tempreg, breg, mips_gp_register);
5745 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
5746 treg, (int) BFD_RELOC_GPREL16, tempreg);
5759 load_register (&icnt, treg, &imm_expr, 0);
5763 load_register (&icnt, treg, &imm_expr, 1);
5767 if (imm_expr.X_op == O_constant)
5769 load_register (&icnt, AT, &imm_expr, 0);
5770 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5771 "mtc1", "t,G", AT, treg);
5776 assert (offset_expr.X_op == O_symbol
5777 && strcmp (segment_name (S_GET_SEGMENT
5778 (offset_expr.X_add_symbol)),
5780 && offset_expr.X_add_number == 0);
5781 macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)",
5782 treg, (int) BFD_RELOC_MIPS_LITERAL, mips_gp_register);
5787 /* Check if we have a constant in IMM_EXPR. If the GPRs are 64 bits
5788 wide, IMM_EXPR is the entire value. Otherwise IMM_EXPR is the high
5789 order 32 bits of the value and the low order 32 bits are either
5790 zero or in OFFSET_EXPR. */
5791 if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big)
5793 if (HAVE_64BIT_GPRS)
5794 load_register (&icnt, treg, &imm_expr, 1);
5799 if (target_big_endian)
5811 load_register (&icnt, hreg, &imm_expr, 0);
5814 if (offset_expr.X_op == O_absent)
5815 move_register (&icnt, lreg, 0);
5818 assert (offset_expr.X_op == O_constant);
5819 load_register (&icnt, lreg, &offset_expr, 0);
5826 /* We know that sym is in the .rdata section. First we get the
5827 upper 16 bits of the address. */
5828 if (mips_pic == NO_PIC)
5830 macro_build_lui (NULL, &icnt, &offset_expr, AT);
5832 else if (mips_pic == SVR4_PIC)
5834 macro_build ((char *) NULL, &icnt, &offset_expr,
5835 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5836 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16,
5839 else if (mips_pic == EMBEDDED_PIC)
5841 /* For embedded PIC we pick up the entire address off $gp in
5842 a single instruction. */
5843 macro_build ((char *) NULL, &icnt, &offset_expr,
5844 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu", "t,r,j", AT,
5845 mips_gp_register, (int) BFD_RELOC_GPREL16);
5846 offset_expr.X_op = O_constant;
5847 offset_expr.X_add_number = 0;
5852 /* Now we load the register(s). */
5853 if (HAVE_64BIT_GPRS)
5854 macro_build ((char *) NULL, &icnt, &offset_expr, "ld", "t,o(b)",
5855 treg, (int) BFD_RELOC_LO16, AT);
5858 macro_build ((char *) NULL, &icnt, &offset_expr, "lw", "t,o(b)",
5859 treg, (int) BFD_RELOC_LO16, AT);
5862 /* FIXME: How in the world do we deal with the possible
5864 offset_expr.X_add_number += 4;
5865 macro_build ((char *) NULL, &icnt, &offset_expr, "lw", "t,o(b)",
5866 treg + 1, (int) BFD_RELOC_LO16, AT);
5870 /* To avoid confusion in tc_gen_reloc, we must ensure that this
5871 does not become a variant frag. */
5872 frag_wane (frag_now);
5878 /* Check if we have a constant in IMM_EXPR. If the FPRs are 64 bits
5879 wide, IMM_EXPR is the entire value and the GPRs are known to be 64
5880 bits wide as well. Otherwise IMM_EXPR is the high order 32 bits of
5881 the value and the low order 32 bits are either zero or in
5883 if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big)
5885 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_FPRS);
5886 if (HAVE_64BIT_FPRS)
5888 assert (HAVE_64BIT_GPRS);
5889 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5890 "dmtc1", "t,S", AT, treg);
5894 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5895 "mtc1", "t,G", AT, treg + 1);
5896 if (offset_expr.X_op == O_absent)
5897 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5898 "mtc1", "t,G", 0, treg);
5901 assert (offset_expr.X_op == O_constant);
5902 load_register (&icnt, AT, &offset_expr, 0);
5903 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5904 "mtc1", "t,G", AT, treg);
5910 assert (offset_expr.X_op == O_symbol
5911 && offset_expr.X_add_number == 0);
5912 s = segment_name (S_GET_SEGMENT (offset_expr.X_add_symbol));
5913 if (strcmp (s, ".lit8") == 0)
5915 if (mips_opts.isa != ISA_MIPS1)
5917 macro_build ((char *) NULL, &icnt, &offset_expr, "ldc1",
5918 "T,o(b)", treg, (int) BFD_RELOC_MIPS_LITERAL,
5922 breg = mips_gp_register;
5923 r = BFD_RELOC_MIPS_LITERAL;
5928 assert (strcmp (s, RDATA_SECTION_NAME) == 0);
5929 if (mips_pic == SVR4_PIC)
5930 macro_build ((char *) NULL, &icnt, &offset_expr,
5931 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5932 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16,
5936 /* FIXME: This won't work for a 64 bit address. */
5937 macro_build_lui (NULL, &icnt, &offset_expr, AT);
5940 if (mips_opts.isa != ISA_MIPS1)
5942 macro_build ((char *) NULL, &icnt, &offset_expr, "ldc1",
5943 "T,o(b)", treg, (int) BFD_RELOC_LO16, AT);
5945 /* To avoid confusion in tc_gen_reloc, we must ensure
5946 that this does not become a variant frag. */
5947 frag_wane (frag_now);
5958 if (mips_arch == CPU_R4650)
5960 as_bad (_("opcode not supported on this processor"));
5963 /* Even on a big endian machine $fn comes before $fn+1. We have
5964 to adjust when loading from memory. */
5967 assert (mips_opts.isa == ISA_MIPS1);
5968 macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)",
5969 target_big_endian ? treg + 1 : treg,
5971 /* FIXME: A possible overflow which I don't know how to deal
5973 offset_expr.X_add_number += 4;
5974 macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)",
5975 target_big_endian ? treg : treg + 1,
5978 /* To avoid confusion in tc_gen_reloc, we must ensure that this
5979 does not become a variant frag. */
5980 frag_wane (frag_now);
5989 * The MIPS assembler seems to check for X_add_number not
5990 * being double aligned and generating:
5993 * addiu at,at,%lo(foo+1)
5996 * But, the resulting address is the same after relocation so why
5997 * generate the extra instruction?
5999 if (mips_arch == CPU_R4650)
6001 as_bad (_("opcode not supported on this processor"));
6004 /* Itbl support may require additional care here. */
6006 if (mips_opts.isa != ISA_MIPS1)
6017 if (mips_arch == CPU_R4650)
6019 as_bad (_("opcode not supported on this processor"));
6023 if (mips_opts.isa != ISA_MIPS1)
6031 /* Itbl support may require additional care here. */
6036 if (HAVE_64BIT_GPRS)
6047 if (HAVE_64BIT_GPRS)
6057 /* We do _not_ bother to allow embedded PIC (symbol-local_symbol)
6058 loads for the case of doing a pair of loads to simulate an 'ld'.
6059 This is not currently done by the compiler, and assembly coders
6060 writing embedded-pic code can cope. */
6062 if (offset_expr.X_op != O_symbol
6063 && offset_expr.X_op != O_constant)
6065 as_bad (_("expression too complex"));
6066 offset_expr.X_op = O_constant;
6069 /* Even on a big endian machine $fn comes before $fn+1. We have
6070 to adjust when loading from memory. We set coproc if we must
6071 load $fn+1 first. */
6072 /* Itbl support may require additional care here. */
6073 if (! target_big_endian)
6076 if (mips_pic == NO_PIC
6077 || offset_expr.X_op == O_constant)
6081 /* If this is a reference to a GP relative symbol, we want
6082 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
6083 <op> $treg+1,<sym>+4($gp) (BFD_RELOC_GPREL16)
6084 If we have a base register, we use this
6086 <op> $treg,<sym>($at) (BFD_RELOC_GPREL16)
6087 <op> $treg+1,<sym>+4($at) (BFD_RELOC_GPREL16)
6088 If this is not a GP relative symbol, we want
6089 lui $at,<sym> (BFD_RELOC_HI16_S)
6090 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
6091 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
6092 If there is a base register, we add it to $at after the
6093 lui instruction. If there is a constant, we always use
6095 if ((valueT) offset_expr.X_add_number > MAX_GPREL_OFFSET
6096 || nopic_need_relax (offset_expr.X_add_symbol, 1))
6108 tempreg = mips_gp_register;
6115 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6116 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
6117 "d,v,t", AT, breg, mips_gp_register);
6123 /* Itbl support may require additional care here. */
6124 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
6125 coproc ? treg + 1 : treg,
6126 (int) BFD_RELOC_GPREL16, tempreg);
6127 offset_expr.X_add_number += 4;
6129 /* Set mips_optimize to 2 to avoid inserting an
6131 hold_mips_optimize = mips_optimize;
6133 /* Itbl support may require additional care here. */
6134 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
6135 coproc ? treg : treg + 1,
6136 (int) BFD_RELOC_GPREL16, tempreg);
6137 mips_optimize = hold_mips_optimize;
6139 p = frag_var (rs_machine_dependent, 12 + off, 0,
6140 RELAX_ENCODE (8 + off, 12 + off, 0, 4 + off, 1,
6141 used_at && mips_opts.noat),
6142 offset_expr.X_add_symbol, 0, NULL);
6144 /* We just generated two relocs. When tc_gen_reloc
6145 handles this case, it will skip the first reloc and
6146 handle the second. The second reloc already has an
6147 extra addend of 4, which we added above. We must
6148 subtract it out, and then subtract another 4 to make
6149 the first reloc come out right. The second reloc
6150 will come out right because we are going to add 4 to
6151 offset_expr when we build its instruction below.
6153 If we have a symbol, then we don't want to include
6154 the offset, because it will wind up being included
6155 when we generate the reloc. */
6157 if (offset_expr.X_op == O_constant)
6158 offset_expr.X_add_number -= 8;
6161 offset_expr.X_add_number = -4;
6162 offset_expr.X_op = O_constant;
6165 macro_build_lui (p, &icnt, &offset_expr, AT);
6170 macro_build (p, &icnt, (expressionS *) NULL,
6171 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
6172 "d,v,t", AT, breg, AT);
6176 /* Itbl support may require additional care here. */
6177 macro_build (p, &icnt, &offset_expr, s, fmt,
6178 coproc ? treg + 1 : treg,
6179 (int) BFD_RELOC_LO16, AT);
6182 /* FIXME: How do we handle overflow here? */
6183 offset_expr.X_add_number += 4;
6184 /* Itbl support may require additional care here. */
6185 macro_build (p, &icnt, &offset_expr, s, fmt,
6186 coproc ? treg : treg + 1,
6187 (int) BFD_RELOC_LO16, AT);
6189 else if (mips_pic == SVR4_PIC && ! mips_big_got)
6193 /* If this is a reference to an external symbol, we want
6194 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6199 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6201 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
6202 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
6203 If there is a base register we add it to $at before the
6204 lwc1 instructions. If there is a constant we include it
6205 in the lwc1 instructions. */
6207 expr1.X_add_number = offset_expr.X_add_number;
6208 offset_expr.X_add_number = 0;
6209 if (expr1.X_add_number < -0x8000
6210 || expr1.X_add_number >= 0x8000 - 4)
6211 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6216 frag_grow (24 + off);
6217 macro_build ((char *) NULL, &icnt, &offset_expr,
6218 HAVE_32BIT_ADDRESSES ? "lw" : "ld", "t,o(b)", AT,
6219 (int) BFD_RELOC_MIPS_GOT16, mips_gp_register);
6220 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
6222 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6223 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
6224 "d,v,t", AT, breg, AT);
6225 /* Itbl support may require additional care here. */
6226 macro_build ((char *) NULL, &icnt, &expr1, s, fmt,
6227 coproc ? treg + 1 : treg,
6228 (int) BFD_RELOC_LO16, AT);
6229 expr1.X_add_number += 4;
6231 /* Set mips_optimize to 2 to avoid inserting an undesired
6233 hold_mips_optimize = mips_optimize;
6235 /* Itbl support may require additional care here. */
6236 macro_build ((char *) NULL, &icnt, &expr1, s, fmt,
6237 coproc ? treg : treg + 1,
6238 (int) BFD_RELOC_LO16, AT);
6239 mips_optimize = hold_mips_optimize;
6241 (void) frag_var (rs_machine_dependent, 0, 0,
6242 RELAX_ENCODE (0, 0, -16 - off, -8, 1, 0),
6243 offset_expr.X_add_symbol, 0, NULL);
6245 else if (mips_pic == SVR4_PIC)
6250 /* If this is a reference to an external symbol, we want
6251 lui $at,<sym> (BFD_RELOC_MIPS_GOT_HI16)
6253 lw $at,<sym>($at) (BFD_RELOC_MIPS_GOT_LO16)
6258 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6260 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
6261 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
6262 If there is a base register we add it to $at before the
6263 lwc1 instructions. If there is a constant we include it
6264 in the lwc1 instructions. */
6266 expr1.X_add_number = offset_expr.X_add_number;
6267 offset_expr.X_add_number = 0;
6268 if (expr1.X_add_number < -0x8000
6269 || expr1.X_add_number >= 0x8000 - 4)
6270 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6271 if (reg_needs_delay (mips_gp_register))
6280 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
6281 AT, (int) BFD_RELOC_MIPS_GOT_HI16);
6282 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6283 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
6284 "d,v,t", AT, AT, mips_gp_register);
6285 macro_build ((char *) NULL, &icnt, &offset_expr,
6286 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
6287 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT_LO16, AT);
6288 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
6290 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6291 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
6292 "d,v,t", AT, breg, AT);
6293 /* Itbl support may require additional care here. */
6294 macro_build ((char *) NULL, &icnt, &expr1, s, fmt,
6295 coproc ? treg + 1 : treg,
6296 (int) BFD_RELOC_LO16, AT);
6297 expr1.X_add_number += 4;
6299 /* Set mips_optimize to 2 to avoid inserting an undesired
6301 hold_mips_optimize = mips_optimize;
6303 /* Itbl support may require additional care here. */
6304 macro_build ((char *) NULL, &icnt, &expr1, s, fmt,
6305 coproc ? treg : treg + 1,
6306 (int) BFD_RELOC_LO16, AT);
6307 mips_optimize = hold_mips_optimize;
6308 expr1.X_add_number -= 4;
6310 p = frag_var (rs_machine_dependent, 16 + gpdel + off, 0,
6311 RELAX_ENCODE (24 + off, 16 + gpdel + off, gpdel,
6312 8 + gpdel + off, 1, 0),
6313 offset_expr.X_add_symbol, 0, NULL);
6316 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
6319 macro_build (p, &icnt, &offset_expr,
6320 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
6321 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16,
6324 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
6328 macro_build (p, &icnt, (expressionS *) NULL,
6329 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
6330 "d,v,t", AT, breg, AT);
6333 /* Itbl support may require additional care here. */
6334 macro_build (p, &icnt, &expr1, s, fmt,
6335 coproc ? treg + 1 : treg,
6336 (int) BFD_RELOC_LO16, AT);
6338 expr1.X_add_number += 4;
6340 /* Set mips_optimize to 2 to avoid inserting an undesired
6342 hold_mips_optimize = mips_optimize;
6344 /* Itbl support may require additional care here. */
6345 macro_build (p, &icnt, &expr1, s, fmt,
6346 coproc ? treg : treg + 1,
6347 (int) BFD_RELOC_LO16, AT);
6348 mips_optimize = hold_mips_optimize;
6350 else if (mips_pic == EMBEDDED_PIC)
6352 /* If there is no base register, we use
6353 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
6354 <op> $treg+1,<sym>+4($gp) (BFD_RELOC_GPREL16)
6355 If we have a base register, we use
6357 <op> $treg,<sym>($at) (BFD_RELOC_GPREL16)
6358 <op> $treg+1,<sym>+4($at) (BFD_RELOC_GPREL16)
6362 tempreg = mips_gp_register;
6367 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6368 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
6369 "d,v,t", AT, breg, mips_gp_register);
6374 /* Itbl support may require additional care here. */
6375 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
6376 coproc ? treg + 1 : treg,
6377 (int) BFD_RELOC_GPREL16, tempreg);
6378 offset_expr.X_add_number += 4;
6379 /* Itbl support may require additional care here. */
6380 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
6381 coproc ? treg : treg + 1,
6382 (int) BFD_RELOC_GPREL16, tempreg);
6398 assert (HAVE_32BIT_ADDRESSES);
6399 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg,
6400 (int) BFD_RELOC_LO16, breg);
6401 offset_expr.X_add_number += 4;
6402 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg + 1,
6403 (int) BFD_RELOC_LO16, breg);
6406 /* New code added to support COPZ instructions.
6407 This code builds table entries out of the macros in mip_opcodes.
6408 R4000 uses interlocks to handle coproc delays.
6409 Other chips (like the R3000) require nops to be inserted for delays.
6411 FIXME: Currently, we require that the user handle delays.
6412 In order to fill delay slots for non-interlocked chips,
6413 we must have a way to specify delays based on the coprocessor.
6414 Eg. 4 cycles if load coproc reg from memory, 1 if in cache, etc.
6415 What are the side-effects of the cop instruction?
6416 What cache support might we have and what are its effects?
6417 Both coprocessor & memory require delays. how long???
6418 What registers are read/set/modified?
6420 If an itbl is provided to interpret cop instructions,
6421 this knowledge can be encoded in the itbl spec. */
6435 /* For now we just do C (same as Cz). The parameter will be
6436 stored in insn_opcode by mips_ip. */
6437 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "C",
6442 move_register (&icnt, dreg, sreg);
6445 #ifdef LOSING_COMPILER
6447 /* Try and see if this is a new itbl instruction.
6448 This code builds table entries out of the macros in mip_opcodes.
6449 FIXME: For now we just assemble the expression and pass it's
6450 value along as a 32-bit immediate.
6451 We may want to have the assembler assemble this value,
6452 so that we gain the assembler's knowledge of delay slots,
6454 Would it be more efficient to use mask (id) here? */
6455 if (itbl_have_entries
6456 && (immed_expr = itbl_assemble (ip->insn_mo->name, "")))
6458 s = ip->insn_mo->name;
6460 coproc = ITBL_DECODE_PNUM (immed_expr);;
6461 macro_build ((char *) NULL, &icnt, &immed_expr, s, "C");
6468 as_warn (_("Macro used $at after \".set noat\""));
6473 struct mips_cl_insn *ip;
6475 register int treg, sreg, dreg, breg;
6491 bfd_reloc_code_real_type r;
6494 treg = (ip->insn_opcode >> 16) & 0x1f;
6495 dreg = (ip->insn_opcode >> 11) & 0x1f;
6496 sreg = breg = (ip->insn_opcode >> 21) & 0x1f;
6497 mask = ip->insn_mo->mask;
6499 expr1.X_op = O_constant;
6500 expr1.X_op_symbol = NULL;
6501 expr1.X_add_symbol = NULL;
6502 expr1.X_add_number = 1;
6506 #endif /* LOSING_COMPILER */
6511 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6512 dbl ? "dmultu" : "multu", "s,t", sreg, treg);
6513 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "d",
6520 /* The MIPS assembler some times generates shifts and adds. I'm
6521 not trying to be that fancy. GCC should do this for us
6523 load_register (&icnt, AT, &imm_expr, dbl);
6524 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6525 dbl ? "dmult" : "mult", "s,t", sreg, AT);
6526 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "d",
6540 mips_emit_delays (true);
6541 ++mips_opts.noreorder;
6542 mips_any_noreorder = 1;
6544 load_register (&icnt, AT, &imm_expr, dbl);
6545 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6546 dbl ? "dmult" : "mult", "s,t", sreg, imm ? AT : treg);
6547 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "d",
6549 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6550 dbl ? "dsra32" : "sra", "d,w,<", dreg, dreg, RA);
6551 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mfhi", "d",
6554 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "tne", "s,t",
6558 expr1.X_add_number = 8;
6559 macro_build ((char *) NULL, &icnt, &expr1, "beq", "s,t,p", dreg,
6561 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "",
6563 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
6566 --mips_opts.noreorder;
6567 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "d", dreg);
6580 mips_emit_delays (true);
6581 ++mips_opts.noreorder;
6582 mips_any_noreorder = 1;
6584 load_register (&icnt, AT, &imm_expr, dbl);
6585 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6586 dbl ? "dmultu" : "multu",
6587 "s,t", sreg, imm ? AT : treg);
6588 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mfhi", "d",
6590 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "d",
6593 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "tne", "s,t",
6597 expr1.X_add_number = 8;
6598 macro_build ((char *) NULL, &icnt, &expr1, "beq", "s,t,p", AT, 0);
6599 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "",
6601 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
6604 --mips_opts.noreorder;
6608 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "dsubu",
6609 "d,v,t", AT, 0, treg);
6610 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "dsrlv",
6611 "d,t,s", AT, sreg, AT);
6612 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "dsllv",
6613 "d,t,s", dreg, sreg, treg);
6614 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or",
6615 "d,v,t", dreg, dreg, AT);
6619 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "subu",
6620 "d,v,t", AT, 0, treg);
6621 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srlv",
6622 "d,t,s", AT, sreg, AT);
6623 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sllv",
6624 "d,t,s", dreg, sreg, treg);
6625 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or",
6626 "d,v,t", dreg, dreg, AT);
6634 if (imm_expr.X_op != O_constant)
6635 as_bad (_("rotate count too large"));
6636 rot = imm_expr.X_add_number & 0x3f;
6639 l = (rot < 0x20) ? "dsll" : "dsll32";
6640 r = ((0x40 - rot) < 0x20) ? "dsrl" : "dsrl32";
6642 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, l,
6643 "d,w,<", AT, sreg, rot);
6644 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, r,
6645 "d,w,<", dreg, sreg, (0x20 - rot) & 0x1f);
6646 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or",
6647 "d,v,t", dreg, dreg, AT);
6655 if (imm_expr.X_op != O_constant)
6656 as_bad (_("rotate count too large"));
6657 rot = imm_expr.X_add_number & 0x1f;
6660 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sll",
6661 "d,w,<", AT, sreg, rot);
6662 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srl",
6663 "d,w,<", dreg, sreg, (0x20 - rot) & 0x1f);
6664 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or",
6665 "d,v,t", dreg, dreg, AT);
6670 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "dsubu",
6671 "d,v,t", AT, 0, treg);
6672 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "dsllv",
6673 "d,t,s", AT, sreg, AT);
6674 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "dsrlv",
6675 "d,t,s", dreg, sreg, treg);
6676 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or",
6677 "d,v,t", dreg, dreg, AT);
6681 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "subu",
6682 "d,v,t", AT, 0, treg);
6683 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sllv",
6684 "d,t,s", AT, sreg, AT);
6685 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srlv",
6686 "d,t,s", dreg, sreg, treg);
6687 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or",
6688 "d,v,t", dreg, dreg, AT);
6696 if (imm_expr.X_op != O_constant)
6697 as_bad (_("rotate count too large"));
6698 rot = imm_expr.X_add_number & 0x3f;
6701 r = (rot < 0x20) ? "dsrl" : "dsrl32";
6702 l = ((0x40 - rot) < 0x20) ? "dsll" : "dsll32";
6704 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, r,
6705 "d,w,<", AT, sreg, rot);
6706 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, l,
6707 "d,w,<", dreg, sreg, (0x20 - rot) & 0x1f);
6708 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or",
6709 "d,v,t", dreg, dreg, AT);
6717 if (imm_expr.X_op != O_constant)
6718 as_bad (_("rotate count too large"));
6719 rot = imm_expr.X_add_number & 0x1f;
6722 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srl",
6723 "d,w,<", AT, sreg, rot);
6724 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sll",
6725 "d,w,<", dreg, sreg, (0x20 - rot) & 0x1f);
6726 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or",
6727 "d,v,t", dreg, dreg, AT);
6732 if (mips_arch == CPU_R4650)
6734 as_bad (_("opcode not supported on this processor"));
6737 assert (mips_opts.isa == ISA_MIPS1);
6738 /* Even on a big endian machine $fn comes before $fn+1. We have
6739 to adjust when storing to memory. */
6740 macro_build ((char *) NULL, &icnt, &offset_expr, "swc1", "T,o(b)",
6741 target_big_endian ? treg + 1 : treg,
6742 (int) BFD_RELOC_LO16, breg);
6743 offset_expr.X_add_number += 4;
6744 macro_build ((char *) NULL, &icnt, &offset_expr, "swc1", "T,o(b)",
6745 target_big_endian ? treg : treg + 1,
6746 (int) BFD_RELOC_LO16, breg);
6751 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg,
6752 treg, (int) BFD_RELOC_LO16);
6754 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg,
6755 sreg, (int) BFD_RELOC_LO16);
6758 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "xor",
6759 "d,v,t", dreg, sreg, treg);
6760 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg,
6761 dreg, (int) BFD_RELOC_LO16);
6766 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
6768 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg,
6769 sreg, (int) BFD_RELOC_LO16);
6774 as_warn (_("Instruction %s: result is always false"),
6776 move_register (&icnt, dreg, 0);
6779 if (imm_expr.X_op == O_constant
6780 && imm_expr.X_add_number >= 0
6781 && imm_expr.X_add_number < 0x10000)
6783 macro_build ((char *) NULL, &icnt, &imm_expr, "xori", "t,r,i", dreg,
6784 sreg, (int) BFD_RELOC_LO16);
6787 else if (imm_expr.X_op == O_constant
6788 && imm_expr.X_add_number > -0x8000
6789 && imm_expr.X_add_number < 0)
6791 imm_expr.X_add_number = -imm_expr.X_add_number;
6792 macro_build ((char *) NULL, &icnt, &imm_expr,
6793 HAVE_32BIT_GPRS ? "addiu" : "daddiu",
6794 "t,r,j", dreg, sreg,
6795 (int) BFD_RELOC_LO16);
6800 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
6801 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "xor",
6802 "d,v,t", dreg, sreg, AT);
6805 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, dreg,
6806 (int) BFD_RELOC_LO16);
6811 case M_SGE: /* sreg >= treg <==> not (sreg < treg) */
6817 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d,v,t",
6819 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
6820 (int) BFD_RELOC_LO16);
6823 case M_SGE_I: /* sreg >= I <==> not (sreg < I) */
6825 if (imm_expr.X_op == O_constant
6826 && imm_expr.X_add_number >= -0x8000
6827 && imm_expr.X_add_number < 0x8000)
6829 macro_build ((char *) NULL, &icnt, &imm_expr,
6830 mask == M_SGE_I ? "slti" : "sltiu",
6831 "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16);
6836 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
6837 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6838 mask == M_SGE_I ? "slt" : "sltu", "d,v,t", dreg, sreg,
6842 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
6843 (int) BFD_RELOC_LO16);
6848 case M_SGT: /* sreg > treg <==> treg < sreg */
6854 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d,v,t",
6858 case M_SGT_I: /* sreg > I <==> I < sreg */
6864 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
6865 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d,v,t",
6869 case M_SLE: /* sreg <= treg <==> treg >= sreg <==> not (treg < sreg) */
6875 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d,v,t",
6877 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
6878 (int) BFD_RELOC_LO16);
6881 case M_SLE_I: /* sreg <= I <==> I >= sreg <==> not (I < sreg) */
6887 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
6888 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d,v,t",
6890 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
6891 (int) BFD_RELOC_LO16);
6895 if (imm_expr.X_op == O_constant
6896 && imm_expr.X_add_number >= -0x8000
6897 && imm_expr.X_add_number < 0x8000)
6899 macro_build ((char *) NULL, &icnt, &imm_expr, "slti", "t,r,j",
6900 dreg, sreg, (int) BFD_RELOC_LO16);
6903 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
6904 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "slt", "d,v,t",
6909 if (imm_expr.X_op == O_constant
6910 && imm_expr.X_add_number >= -0x8000
6911 && imm_expr.X_add_number < 0x8000)
6913 macro_build ((char *) NULL, &icnt, &imm_expr, "sltiu", "t,r,j",
6914 dreg, sreg, (int) BFD_RELOC_LO16);
6917 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
6918 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
6919 "d,v,t", dreg, sreg, AT);
6924 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
6925 "d,v,t", dreg, 0, treg);
6927 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
6928 "d,v,t", dreg, 0, sreg);
6931 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "xor",
6932 "d,v,t", dreg, sreg, treg);
6933 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
6934 "d,v,t", dreg, 0, dreg);
6939 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
6941 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
6942 "d,v,t", dreg, 0, sreg);
6947 as_warn (_("Instruction %s: result is always true"),
6949 macro_build ((char *) NULL, &icnt, &expr1,
6950 HAVE_32BIT_GPRS ? "addiu" : "daddiu",
6951 "t,r,j", dreg, 0, (int) BFD_RELOC_LO16);
6954 if (imm_expr.X_op == O_constant
6955 && imm_expr.X_add_number >= 0
6956 && imm_expr.X_add_number < 0x10000)
6958 macro_build ((char *) NULL, &icnt, &imm_expr, "xori", "t,r,i",
6959 dreg, sreg, (int) BFD_RELOC_LO16);
6962 else if (imm_expr.X_op == O_constant
6963 && imm_expr.X_add_number > -0x8000
6964 && imm_expr.X_add_number < 0)
6966 imm_expr.X_add_number = -imm_expr.X_add_number;
6967 macro_build ((char *) NULL, &icnt, &imm_expr,
6968 HAVE_32BIT_GPRS ? "addiu" : "daddiu",
6969 "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16);
6974 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
6975 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "xor",
6976 "d,v,t", dreg, sreg, AT);
6979 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
6980 "d,v,t", dreg, 0, dreg);
6988 if (imm_expr.X_op == O_constant
6989 && imm_expr.X_add_number > -0x8000
6990 && imm_expr.X_add_number <= 0x8000)
6992 imm_expr.X_add_number = -imm_expr.X_add_number;
6993 macro_build ((char *) NULL, &icnt, &imm_expr,
6994 dbl ? "daddi" : "addi",
6995 "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16);
6998 load_register (&icnt, AT, &imm_expr, dbl);
6999 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7000 dbl ? "dsub" : "sub", "d,v,t", dreg, sreg, AT);
7006 if (imm_expr.X_op == O_constant
7007 && imm_expr.X_add_number > -0x8000
7008 && imm_expr.X_add_number <= 0x8000)
7010 imm_expr.X_add_number = -imm_expr.X_add_number;
7011 macro_build ((char *) NULL, &icnt, &imm_expr,
7012 dbl ? "daddiu" : "addiu",
7013 "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16);
7016 load_register (&icnt, AT, &imm_expr, dbl);
7017 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7018 dbl ? "dsubu" : "subu", "d,v,t", dreg, sreg, AT);
7039 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
7040 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "s,t", sreg,
7046 assert (mips_opts.isa == ISA_MIPS1);
7047 sreg = (ip->insn_opcode >> 11) & 0x1f; /* floating reg */
7048 dreg = (ip->insn_opcode >> 06) & 0x1f; /* floating reg */
7051 * Is the double cfc1 instruction a bug in the mips assembler;
7052 * or is there a reason for it?
7054 mips_emit_delays (true);
7055 ++mips_opts.noreorder;
7056 mips_any_noreorder = 1;
7057 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "cfc1", "t,G",
7059 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "cfc1", "t,G",
7061 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
7062 expr1.X_add_number = 3;
7063 macro_build ((char *) NULL, &icnt, &expr1, "ori", "t,r,i", AT, treg,
7064 (int) BFD_RELOC_LO16);
7065 expr1.X_add_number = 2;
7066 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", AT, AT,
7067 (int) BFD_RELOC_LO16);
7068 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "ctc1", "t,G",
7070 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
7071 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7072 mask == M_TRUNCWD ? "cvt.w.d" : "cvt.w.s", "D,S", dreg, sreg);
7073 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "ctc1", "t,G",
7075 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
7076 --mips_opts.noreorder;
7085 if (offset_expr.X_add_number >= 0x7fff)
7086 as_bad (_("operand overflow"));
7087 /* avoid load delay */
7088 if (! target_big_endian)
7089 ++offset_expr.X_add_number;
7090 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg,
7091 (int) BFD_RELOC_LO16, breg);
7092 if (! target_big_endian)
7093 --offset_expr.X_add_number;
7095 ++offset_expr.X_add_number;
7096 macro_build ((char *) NULL, &icnt, &offset_expr, "lbu", "t,o(b)", AT,
7097 (int) BFD_RELOC_LO16, breg);
7098 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sll", "d,w,<",
7100 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or", "d,v,t",
7114 if (offset_expr.X_add_number >= 0x8000 - off)
7115 as_bad (_("operand overflow"));
7116 if (! target_big_endian)
7117 offset_expr.X_add_number += off;
7118 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg,
7119 (int) BFD_RELOC_LO16, breg);
7120 if (! target_big_endian)
7121 offset_expr.X_add_number -= off;
7123 offset_expr.X_add_number += off;
7124 macro_build ((char *) NULL, &icnt, &offset_expr, s2, "t,o(b)", treg,
7125 (int) BFD_RELOC_LO16, breg);
7139 load_address (&icnt, AT, &offset_expr, &used_at);
7141 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7142 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
7143 "d,v,t", AT, AT, breg);
7144 if (! target_big_endian)
7145 expr1.X_add_number = off;
7147 expr1.X_add_number = 0;
7148 macro_build ((char *) NULL, &icnt, &expr1, s, "t,o(b)", treg,
7149 (int) BFD_RELOC_LO16, AT);
7150 if (! target_big_endian)
7151 expr1.X_add_number = 0;
7153 expr1.X_add_number = off;
7154 macro_build ((char *) NULL, &icnt, &expr1, s2, "t,o(b)", treg,
7155 (int) BFD_RELOC_LO16, AT);
7161 load_address (&icnt, AT, &offset_expr, &used_at);
7163 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7164 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
7165 "d,v,t", AT, AT, breg);
7166 if (target_big_endian)
7167 expr1.X_add_number = 0;
7168 macro_build ((char *) NULL, &icnt, &expr1,
7169 mask == M_ULH_A ? "lb" : "lbu", "t,o(b)", treg,
7170 (int) BFD_RELOC_LO16, AT);
7171 if (target_big_endian)
7172 expr1.X_add_number = 1;
7174 expr1.X_add_number = 0;
7175 macro_build ((char *) NULL, &icnt, &expr1, "lbu", "t,o(b)", AT,
7176 (int) BFD_RELOC_LO16, AT);
7177 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sll", "d,w,<",
7179 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or", "d,v,t",
7184 if (offset_expr.X_add_number >= 0x7fff)
7185 as_bad (_("operand overflow"));
7186 if (target_big_endian)
7187 ++offset_expr.X_add_number;
7188 macro_build ((char *) NULL, &icnt, &offset_expr, "sb", "t,o(b)", treg,
7189 (int) BFD_RELOC_LO16, breg);
7190 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srl", "d,w,<",
7192 if (target_big_endian)
7193 --offset_expr.X_add_number;
7195 ++offset_expr.X_add_number;
7196 macro_build ((char *) NULL, &icnt, &offset_expr, "sb", "t,o(b)", AT,
7197 (int) BFD_RELOC_LO16, breg);
7210 if (offset_expr.X_add_number >= 0x8000 - off)
7211 as_bad (_("operand overflow"));
7212 if (! target_big_endian)
7213 offset_expr.X_add_number += off;
7214 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg,
7215 (int) BFD_RELOC_LO16, breg);
7216 if (! target_big_endian)
7217 offset_expr.X_add_number -= off;
7219 offset_expr.X_add_number += off;
7220 macro_build ((char *) NULL, &icnt, &offset_expr, s2, "t,o(b)", treg,
7221 (int) BFD_RELOC_LO16, breg);
7235 load_address (&icnt, AT, &offset_expr, &used_at);
7237 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7238 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
7239 "d,v,t", AT, AT, breg);
7240 if (! target_big_endian)
7241 expr1.X_add_number = off;
7243 expr1.X_add_number = 0;
7244 macro_build ((char *) NULL, &icnt, &expr1, s, "t,o(b)", treg,
7245 (int) BFD_RELOC_LO16, AT);
7246 if (! target_big_endian)
7247 expr1.X_add_number = 0;
7249 expr1.X_add_number = off;
7250 macro_build ((char *) NULL, &icnt, &expr1, s2, "t,o(b)", treg,
7251 (int) BFD_RELOC_LO16, AT);
7256 load_address (&icnt, AT, &offset_expr, &used_at);
7258 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7259 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
7260 "d,v,t", AT, AT, breg);
7261 if (! target_big_endian)
7262 expr1.X_add_number = 0;
7263 macro_build ((char *) NULL, &icnt, &expr1, "sb", "t,o(b)", treg,
7264 (int) BFD_RELOC_LO16, AT);
7265 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srl", "d,w,<",
7267 if (! target_big_endian)
7268 expr1.X_add_number = 1;
7270 expr1.X_add_number = 0;
7271 macro_build ((char *) NULL, &icnt, &expr1, "sb", "t,o(b)", treg,
7272 (int) BFD_RELOC_LO16, AT);
7273 if (! target_big_endian)
7274 expr1.X_add_number = 0;
7276 expr1.X_add_number = 1;
7277 macro_build ((char *) NULL, &icnt, &expr1, "lbu", "t,o(b)", AT,
7278 (int) BFD_RELOC_LO16, AT);
7279 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sll", "d,w,<",
7281 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or", "d,v,t",
7286 /* FIXME: Check if this is one of the itbl macros, since they
7287 are added dynamically. */
7288 as_bad (_("Macro %s not implemented yet"), ip->insn_mo->name);
7292 as_warn (_("Macro used $at after \".set noat\""));
7295 /* Implement macros in mips16 mode. */
7299 struct mips_cl_insn *ip;
7302 int xreg, yreg, zreg, tmp;
7306 const char *s, *s2, *s3;
7308 mask = ip->insn_mo->mask;
7310 xreg = (ip->insn_opcode >> MIPS16OP_SH_RX) & MIPS16OP_MASK_RX;
7311 yreg = (ip->insn_opcode >> MIPS16OP_SH_RY) & MIPS16OP_MASK_RY;
7312 zreg = (ip->insn_opcode >> MIPS16OP_SH_RZ) & MIPS16OP_MASK_RZ;
7316 expr1.X_op = O_constant;
7317 expr1.X_op_symbol = NULL;
7318 expr1.X_add_symbol = NULL;
7319 expr1.X_add_number = 1;
7338 mips_emit_delays (true);
7339 ++mips_opts.noreorder;
7340 mips_any_noreorder = 1;
7341 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7342 dbl ? "ddiv" : "div",
7343 "0,x,y", xreg, yreg);
7344 expr1.X_add_number = 2;
7345 macro_build ((char *) NULL, &icnt, &expr1, "bnez", "x,p", yreg);
7346 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break", "6",
7349 /* FIXME: The normal code checks for of -1 / -0x80000000 here,
7350 since that causes an overflow. We should do that as well,
7351 but I don't see how to do the comparisons without a temporary
7353 --mips_opts.noreorder;
7354 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "x", zreg);
7373 mips_emit_delays (true);
7374 ++mips_opts.noreorder;
7375 mips_any_noreorder = 1;
7376 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "0,x,y",
7378 expr1.X_add_number = 2;
7379 macro_build ((char *) NULL, &icnt, &expr1, "bnez", "x,p", yreg);
7380 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
7382 --mips_opts.noreorder;
7383 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s2, "x", zreg);
7389 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7390 dbl ? "dmultu" : "multu", "x,y", xreg, yreg);
7391 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "x",
7400 if (imm_expr.X_op != O_constant)
7401 as_bad (_("Unsupported large constant"));
7402 imm_expr.X_add_number = -imm_expr.X_add_number;
7403 macro_build ((char *) NULL, &icnt, &imm_expr,
7404 dbl ? "daddiu" : "addiu", "y,x,4", yreg, xreg);
7408 if (imm_expr.X_op != O_constant)
7409 as_bad (_("Unsupported large constant"));
7410 imm_expr.X_add_number = -imm_expr.X_add_number;
7411 macro_build ((char *) NULL, &icnt, &imm_expr, "addiu",
7416 if (imm_expr.X_op != O_constant)
7417 as_bad (_("Unsupported large constant"));
7418 imm_expr.X_add_number = -imm_expr.X_add_number;
7419 macro_build ((char *) NULL, &icnt, &imm_expr, "daddiu",
7442 goto do_reverse_branch;
7446 goto do_reverse_branch;
7458 goto do_reverse_branch;
7469 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "x,y",
7471 macro_build ((char *) NULL, &icnt, &offset_expr, s2, "p");
7498 goto do_addone_branch_i;
7503 goto do_addone_branch_i;
7518 goto do_addone_branch_i;
7525 if (imm_expr.X_op != O_constant)
7526 as_bad (_("Unsupported large constant"));
7527 ++imm_expr.X_add_number;
7530 macro_build ((char *) NULL, &icnt, &imm_expr, s, s3, xreg);
7531 macro_build ((char *) NULL, &icnt, &offset_expr, s2, "p");
7535 expr1.X_add_number = 0;
7536 macro_build ((char *) NULL, &icnt, &expr1, "slti", "x,8", yreg);
7538 move_register (&icnt, xreg, yreg);
7539 expr1.X_add_number = 2;
7540 macro_build ((char *) NULL, &icnt, &expr1, "bteqz", "p");
7541 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7542 "neg", "x,w", xreg, xreg);
7546 /* For consistency checking, verify that all bits are specified either
7547 by the match/mask part of the instruction definition, or by the
7550 validate_mips_insn (opc)
7551 const struct mips_opcode *opc;
7553 const char *p = opc->args;
7555 unsigned long used_bits = opc->mask;
7557 if ((used_bits & opc->match) != opc->match)
7559 as_bad (_("internal: bad mips opcode (mask error): %s %s"),
7560 opc->name, opc->args);
7563 #define USE_BITS(mask,shift) (used_bits |= ((mask) << (shift)))
7570 case '<': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
7571 case '>': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
7573 case 'B': USE_BITS (OP_MASK_CODE20, OP_SH_CODE20); break;
7574 case 'C': USE_BITS (OP_MASK_COPZ, OP_SH_COPZ); break;
7575 case 'D': USE_BITS (OP_MASK_FD, OP_SH_FD); break;
7576 case 'E': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
7578 case 'G': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
7579 case 'H': USE_BITS (OP_MASK_SEL, OP_SH_SEL); break;
7581 case 'J': USE_BITS (OP_MASK_CODE19, OP_SH_CODE19); break;
7583 case 'M': USE_BITS (OP_MASK_CCC, OP_SH_CCC); break;
7584 case 'N': USE_BITS (OP_MASK_BCC, OP_SH_BCC); break;
7585 case 'O': USE_BITS (OP_MASK_ALN, OP_SH_ALN); break;
7586 case 'Q': USE_BITS (OP_MASK_VSEL, OP_SH_VSEL);
7587 USE_BITS (OP_MASK_FT, OP_SH_FT); break;
7588 case 'R': USE_BITS (OP_MASK_FR, OP_SH_FR); break;
7589 case 'S': USE_BITS (OP_MASK_FS, OP_SH_FS); break;
7590 case 'T': USE_BITS (OP_MASK_FT, OP_SH_FT); break;
7591 case 'V': USE_BITS (OP_MASK_FS, OP_SH_FS); break;
7592 case 'W': USE_BITS (OP_MASK_FT, OP_SH_FT); break;
7593 case 'X': USE_BITS (OP_MASK_FD, OP_SH_FD); break;
7594 case 'Y': USE_BITS (OP_MASK_FS, OP_SH_FS); break;
7595 case 'Z': USE_BITS (OP_MASK_FT, OP_SH_FT); break;
7596 case 'a': USE_BITS (OP_MASK_TARGET, OP_SH_TARGET); break;
7597 case 'b': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
7598 case 'c': USE_BITS (OP_MASK_CODE, OP_SH_CODE); break;
7599 case 'd': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
7601 case 'h': USE_BITS (OP_MASK_PREFX, OP_SH_PREFX); break;
7602 case 'i': USE_BITS (OP_MASK_IMMEDIATE, OP_SH_IMMEDIATE); break;
7603 case 'j': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
7604 case 'k': USE_BITS (OP_MASK_CACHE, OP_SH_CACHE); break;
7606 case 'o': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
7607 case 'p': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
7608 case 'q': USE_BITS (OP_MASK_CODE2, OP_SH_CODE2); break;
7609 case 'r': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
7610 case 's': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
7611 case 't': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
7612 case 'u': USE_BITS (OP_MASK_IMMEDIATE, OP_SH_IMMEDIATE); break;
7613 case 'v': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
7614 case 'w': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
7617 case 'P': USE_BITS (OP_MASK_PERFREG, OP_SH_PERFREG); break;
7618 case 'U': USE_BITS (OP_MASK_RD, OP_SH_RD);
7619 USE_BITS (OP_MASK_RT, OP_SH_RT); break;
7621 as_bad (_("internal: bad mips opcode (unknown operand type `%c'): %s %s"),
7622 c, opc->name, opc->args);
7626 if (used_bits != 0xffffffff)
7628 as_bad (_("internal: bad mips opcode (bits 0x%lx undefined): %s %s"),
7629 ~used_bits & 0xffffffff, opc->name, opc->args);
7635 /* This routine assembles an instruction into its binary format. As a
7636 side effect, it sets one of the global variables imm_reloc or
7637 offset_reloc to the type of relocation to do if one of the operands
7638 is an address expression. */
7643 struct mips_cl_insn *ip;
7648 struct mips_opcode *insn;
7651 unsigned int lastregno = 0;
7657 /* If the instruction contains a '.', we first try to match an instruction
7658 including the '.'. Then we try again without the '.'. */
7660 for (s = str; *s != '\0' && !ISSPACE (*s); ++s)
7663 /* If we stopped on whitespace, then replace the whitespace with null for
7664 the call to hash_find. Save the character we replaced just in case we
7665 have to re-parse the instruction. */
7672 insn = (struct mips_opcode *) hash_find (op_hash, str);
7674 /* If we didn't find the instruction in the opcode table, try again, but
7675 this time with just the instruction up to, but not including the
7679 /* Restore the character we overwrite above (if any). */
7683 /* Scan up to the first '.' or whitespace. */
7685 *s != '\0' && *s != '.' && !ISSPACE (*s);
7689 /* If we did not find a '.', then we can quit now. */
7692 insn_error = "unrecognized opcode";
7696 /* Lookup the instruction in the hash table. */
7698 if ((insn = (struct mips_opcode *) hash_find (op_hash, str)) == NULL)
7700 insn_error = "unrecognized opcode";
7710 assert (strcmp (insn->name, str) == 0);
7712 if (OPCODE_IS_MEMBER (insn,
7714 | (mips_opts.ase_mdmx ? INSN_MDMX : 0)
7715 | (mips_opts.ase_mips3d ? INSN_MIPS3D : 0)),
7721 if (insn->pinfo != INSN_MACRO)
7723 if (mips_arch == CPU_R4650 && (insn->pinfo & FP_D) != 0)
7729 if (insn + 1 < &mips_opcodes[NUMOPCODES]
7730 && strcmp (insn->name, insn[1].name) == 0)
7739 static char buf[100];
7741 _("opcode not supported on this processor: %s (%s)"),
7742 mips_cpu_to_str (mips_arch),
7743 mips_isa_to_str (mips_opts.isa));
7754 ip->insn_opcode = insn->match;
7756 for (args = insn->args;; ++args)
7760 s += strspn (s, " \t");
7764 case '\0': /* end of args */
7777 ip->insn_opcode |= lastregno << OP_SH_RS;
7781 ip->insn_opcode |= lastregno << OP_SH_RT;
7785 ip->insn_opcode |= lastregno << OP_SH_FT;
7789 ip->insn_opcode |= lastregno << OP_SH_FS;
7795 /* Handle optional base register.
7796 Either the base register is omitted or
7797 we must have a left paren. */
7798 /* This is dependent on the next operand specifier
7799 is a base register specification. */
7800 assert (args[1] == 'b' || args[1] == '5'
7801 || args[1] == '-' || args[1] == '4');
7805 case ')': /* these must match exactly */
7810 case '<': /* must be at least one digit */
7812 * According to the manual, if the shift amount is greater
7813 * than 31 or less than 0, then the shift amount should be
7814 * mod 32. In reality the mips assembler issues an error.
7815 * We issue a warning and mask out all but the low 5 bits.
7817 my_getExpression (&imm_expr, s);
7818 check_absolute_expr (ip, &imm_expr);
7819 if ((unsigned long) imm_expr.X_add_number > 31)
7821 as_warn (_("Improper shift amount (%lu)"),
7822 (unsigned long) imm_expr.X_add_number);
7823 imm_expr.X_add_number &= OP_MASK_SHAMT;
7825 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_SHAMT;
7826 imm_expr.X_op = O_absent;
7830 case '>': /* shift amount minus 32 */
7831 my_getExpression (&imm_expr, s);
7832 check_absolute_expr (ip, &imm_expr);
7833 if ((unsigned long) imm_expr.X_add_number < 32
7834 || (unsigned long) imm_expr.X_add_number > 63)
7836 ip->insn_opcode |= (imm_expr.X_add_number - 32) << OP_SH_SHAMT;
7837 imm_expr.X_op = O_absent;
7841 case 'k': /* cache code */
7842 case 'h': /* prefx code */
7843 my_getExpression (&imm_expr, s);
7844 check_absolute_expr (ip, &imm_expr);
7845 if ((unsigned long) imm_expr.X_add_number > 31)
7847 as_warn (_("Invalid value for `%s' (%lu)"),
7849 (unsigned long) imm_expr.X_add_number);
7850 imm_expr.X_add_number &= 0x1f;
7853 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CACHE;
7855 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_PREFX;
7856 imm_expr.X_op = O_absent;
7860 case 'c': /* break code */
7861 my_getExpression (&imm_expr, s);
7862 check_absolute_expr (ip, &imm_expr);
7863 if ((unsigned long) imm_expr.X_add_number > 1023)
7865 as_warn (_("Illegal break code (%lu)"),
7866 (unsigned long) imm_expr.X_add_number);
7867 imm_expr.X_add_number &= OP_MASK_CODE;
7869 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE;
7870 imm_expr.X_op = O_absent;
7874 case 'q': /* lower break code */
7875 my_getExpression (&imm_expr, s);
7876 check_absolute_expr (ip, &imm_expr);
7877 if ((unsigned long) imm_expr.X_add_number > 1023)
7879 as_warn (_("Illegal lower break code (%lu)"),
7880 (unsigned long) imm_expr.X_add_number);
7881 imm_expr.X_add_number &= OP_MASK_CODE2;
7883 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE2;
7884 imm_expr.X_op = O_absent;
7888 case 'B': /* 20-bit syscall/break code. */
7889 my_getExpression (&imm_expr, s);
7890 check_absolute_expr (ip, &imm_expr);
7891 if ((unsigned long) imm_expr.X_add_number > OP_MASK_CODE20)
7892 as_warn (_("Illegal 20-bit code (%lu)"),
7893 (unsigned long) imm_expr.X_add_number);
7894 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE20;
7895 imm_expr.X_op = O_absent;
7899 case 'C': /* Coprocessor code */
7900 my_getExpression (&imm_expr, s);
7901 check_absolute_expr (ip, &imm_expr);
7902 if ((unsigned long) imm_expr.X_add_number >= (1 << 25))
7904 as_warn (_("Coproccesor code > 25 bits (%lu)"),
7905 (unsigned long) imm_expr.X_add_number);
7906 imm_expr.X_add_number &= ((1 << 25) - 1);
7908 ip->insn_opcode |= imm_expr.X_add_number;
7909 imm_expr.X_op = O_absent;
7913 case 'J': /* 19-bit wait code. */
7914 my_getExpression (&imm_expr, s);
7915 check_absolute_expr (ip, &imm_expr);
7916 if ((unsigned long) imm_expr.X_add_number > OP_MASK_CODE19)
7917 as_warn (_("Illegal 19-bit code (%lu)"),
7918 (unsigned long) imm_expr.X_add_number);
7919 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE19;
7920 imm_expr.X_op = O_absent;
7924 case 'P': /* Performance register */
7925 my_getExpression (&imm_expr, s);
7926 check_absolute_expr (ip, &imm_expr);
7927 if (imm_expr.X_add_number != 0 && imm_expr.X_add_number != 1)
7929 as_warn (_("Invalid performance register (%lu)"),
7930 (unsigned long) imm_expr.X_add_number);
7931 imm_expr.X_add_number &= OP_MASK_PERFREG;
7933 ip->insn_opcode |= (imm_expr.X_add_number << OP_SH_PERFREG);
7934 imm_expr.X_op = O_absent;
7938 case 'b': /* base register */
7939 case 'd': /* destination register */
7940 case 's': /* source register */
7941 case 't': /* target register */
7942 case 'r': /* both target and source */
7943 case 'v': /* both dest and source */
7944 case 'w': /* both dest and target */
7945 case 'E': /* coprocessor target register */
7946 case 'G': /* coprocessor destination register */
7947 case 'x': /* ignore register name */
7948 case 'z': /* must be zero register */
7949 case 'U': /* destination register (clo/clz). */
7964 while (ISDIGIT (*s));
7966 as_bad (_("Invalid register number (%d)"), regno);
7968 else if (*args == 'E' || *args == 'G')
7972 if (s[1] == 'r' && s[2] == 'a')
7977 else if (s[1] == 'f' && s[2] == 'p')
7982 else if (s[1] == 's' && s[2] == 'p')
7987 else if (s[1] == 'g' && s[2] == 'p')
7992 else if (s[1] == 'a' && s[2] == 't')
7997 else if (s[1] == 'k' && s[2] == 't' && s[3] == '0')
8002 else if (s[1] == 'k' && s[2] == 't' && s[3] == '1')
8007 else if (s[1] == 'z' && s[2] == 'e' && s[3] == 'r' && s[4] == 'o')
8012 else if (itbl_have_entries)
8017 p = s + 1; /* advance past '$' */
8018 n = itbl_get_field (&p); /* n is name */
8020 /* See if this is a register defined in an
8022 if (itbl_get_reg_val (n, &r))
8024 /* Get_field advances to the start of
8025 the next field, so we need to back
8026 rack to the end of the last field. */
8030 s = strchr (s, '\0');
8043 as_warn (_("Used $at without \".set noat\""));
8049 if (c == 'r' || c == 'v' || c == 'w')
8056 /* 'z' only matches $0. */
8057 if (c == 'z' && regno != 0)
8060 /* Now that we have assembled one operand, we use the args string
8061 * to figure out where it goes in the instruction. */
8068 ip->insn_opcode |= regno << OP_SH_RS;
8072 ip->insn_opcode |= regno << OP_SH_RD;
8075 ip->insn_opcode |= regno << OP_SH_RD;
8076 ip->insn_opcode |= regno << OP_SH_RT;
8081 ip->insn_opcode |= regno << OP_SH_RT;
8084 /* This case exists because on the r3000 trunc
8085 expands into a macro which requires a gp
8086 register. On the r6000 or r4000 it is
8087 assembled into a single instruction which
8088 ignores the register. Thus the insn version
8089 is MIPS_ISA2 and uses 'x', and the macro
8090 version is MIPS_ISA1 and uses 't'. */
8093 /* This case is for the div instruction, which
8094 acts differently if the destination argument
8095 is $0. This only matches $0, and is checked
8096 outside the switch. */
8099 /* Itbl operand; not yet implemented. FIXME ?? */
8101 /* What about all other operands like 'i', which
8102 can be specified in the opcode table? */
8112 ip->insn_opcode |= lastregno << OP_SH_RS;
8115 ip->insn_opcode |= lastregno << OP_SH_RT;
8120 case 'O': /* MDMX alignment immediate constant. */
8121 my_getExpression (&imm_expr, s);
8122 check_absolute_expr (ip, &imm_expr);
8123 if ((unsigned long) imm_expr.X_add_number > OP_MASK_ALN)
8125 as_warn ("Improper align amount (%ld), using low bits",
8126 (long) imm_expr.X_add_number);
8127 imm_expr.X_add_number &= OP_MASK_ALN;
8129 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_ALN;
8130 imm_expr.X_op = O_absent;
8134 case 'Q': /* MDMX vector, element sel, or const. */
8137 /* MDMX Immediate. */
8138 my_getExpression (&imm_expr, s);
8139 check_absolute_expr (ip, &imm_expr);
8140 if ((unsigned long) imm_expr.X_add_number > OP_MASK_FT)
8142 as_warn (_("Invalid MDMX Immediate (%ld)"),
8143 (long) imm_expr.X_add_number);
8144 imm_expr.X_add_number &= OP_MASK_FT;
8146 imm_expr.X_add_number &= OP_MASK_FT;
8147 if (ip->insn_opcode & (OP_MASK_VSEL << OP_SH_VSEL))
8148 ip->insn_opcode |= MDMX_FMTSEL_IMM_QH << OP_SH_VSEL;
8150 ip->insn_opcode |= MDMX_FMTSEL_IMM_OB << OP_SH_VSEL;
8151 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_FT;
8152 imm_expr.X_op = O_absent;
8156 /* Not MDMX Immediate. Fall through. */
8157 case 'X': /* MDMX destination register. */
8158 case 'Y': /* MDMX source register. */
8159 case 'Z': /* MDMX target register. */
8161 case 'D': /* floating point destination register */
8162 case 'S': /* floating point source register */
8163 case 'T': /* floating point target register */
8164 case 'R': /* floating point source register */
8168 /* Accept $fN for FP and MDMX register numbers, and in
8169 addition accept $vN for MDMX register numbers. */
8170 if ((s[0] == '$' && s[1] == 'f' && ISDIGIT (s[2]))
8171 || (is_mdmx != 0 && s[0] == '$' && s[1] == 'v'
8182 while (ISDIGIT (*s));
8185 as_bad (_("Invalid float register number (%d)"), regno);
8187 if ((regno & 1) != 0
8189 && ! (strcmp (str, "mtc1") == 0
8190 || strcmp (str, "mfc1") == 0
8191 || strcmp (str, "lwc1") == 0
8192 || strcmp (str, "swc1") == 0
8193 || strcmp (str, "l.s") == 0
8194 || strcmp (str, "s.s") == 0))
8195 as_warn (_("Float register should be even, was %d"),
8203 if (c == 'V' || c == 'W')
8214 ip->insn_opcode |= regno << OP_SH_FD;
8219 ip->insn_opcode |= regno << OP_SH_FS;
8222 /* This is like 'Z', but also needs to fix the MDMX
8223 vector/scalar select bits. Note that the
8224 scalar immediate case is handled above. */
8227 int is_qh = (ip->insn_opcode & (1 << OP_SH_VSEL));
8228 int max_el = (is_qh ? 3 : 7);
8230 my_getExpression(&imm_expr, s);
8231 check_absolute_expr (ip, &imm_expr);
8233 if (imm_expr.X_add_number > max_el)
8234 as_bad(_("Bad element selector %ld"),
8235 (long) imm_expr.X_add_number);
8236 imm_expr.X_add_number &= max_el;
8237 ip->insn_opcode |= (imm_expr.X_add_number
8241 as_warn(_("Expecting ']' found '%s'"), s);
8247 if (ip->insn_opcode & (OP_MASK_VSEL << OP_SH_VSEL))
8248 ip->insn_opcode |= (MDMX_FMTSEL_VEC_QH
8251 ip->insn_opcode |= (MDMX_FMTSEL_VEC_OB <<
8258 ip->insn_opcode |= regno << OP_SH_FT;
8261 ip->insn_opcode |= regno << OP_SH_FR;
8271 ip->insn_opcode |= lastregno << OP_SH_FS;
8274 ip->insn_opcode |= lastregno << OP_SH_FT;
8280 my_getExpression (&imm_expr, s);
8281 if (imm_expr.X_op != O_big
8282 && imm_expr.X_op != O_constant)
8283 insn_error = _("absolute expression required");
8288 my_getExpression (&offset_expr, s);
8289 *imm_reloc = BFD_RELOC_32;
8302 unsigned char temp[8];
8304 unsigned int length;
8309 /* These only appear as the last operand in an
8310 instruction, and every instruction that accepts
8311 them in any variant accepts them in all variants.
8312 This means we don't have to worry about backing out
8313 any changes if the instruction does not match.
8315 The difference between them is the size of the
8316 floating point constant and where it goes. For 'F'
8317 and 'L' the constant is 64 bits; for 'f' and 'l' it
8318 is 32 bits. Where the constant is placed is based
8319 on how the MIPS assembler does things:
8322 f -- immediate value
8325 The .lit4 and .lit8 sections are only used if
8326 permitted by the -G argument.
8328 When generating embedded PIC code, we use the
8329 .lit8 section but not the .lit4 section (we can do
8330 .lit4 inline easily; we need to put .lit8
8331 somewhere in the data segment, and using .lit8
8332 permits the linker to eventually combine identical
8335 The code below needs to know whether the target register
8336 is 32 or 64 bits wide. It relies on the fact 'f' and
8337 'F' are used with GPR-based instructions and 'l' and
8338 'L' are used with FPR-based instructions. */
8340 f64 = *args == 'F' || *args == 'L';
8341 using_gprs = *args == 'F' || *args == 'f';
8343 save_in = input_line_pointer;
8344 input_line_pointer = s;
8345 err = md_atof (f64 ? 'd' : 'f', (char *) temp, &len);
8347 s = input_line_pointer;
8348 input_line_pointer = save_in;
8349 if (err != NULL && *err != '\0')
8351 as_bad (_("Bad floating point constant: %s"), err);
8352 memset (temp, '\0', sizeof temp);
8353 length = f64 ? 8 : 4;
8356 assert (length == (unsigned) (f64 ? 8 : 4));
8360 && (! USE_GLOBAL_POINTER_OPT
8361 || mips_pic == EMBEDDED_PIC
8362 || g_switch_value < 4
8363 || (temp[0] == 0 && temp[1] == 0)
8364 || (temp[2] == 0 && temp[3] == 0))))
8366 imm_expr.X_op = O_constant;
8367 if (! target_big_endian)
8368 imm_expr.X_add_number = bfd_getl32 (temp);
8370 imm_expr.X_add_number = bfd_getb32 (temp);
8373 && ! mips_disable_float_construction
8374 /* Constants can only be constructed in GPRs and
8375 copied to FPRs if the GPRs are at least as wide
8376 as the FPRs. Force the constant into memory if
8377 we are using 64-bit FPRs but the GPRs are only
8380 || ! (HAVE_64BIT_FPRS && HAVE_32BIT_GPRS))
8381 && ((temp[0] == 0 && temp[1] == 0)
8382 || (temp[2] == 0 && temp[3] == 0))
8383 && ((temp[4] == 0 && temp[5] == 0)
8384 || (temp[6] == 0 && temp[7] == 0)))
8386 /* The value is simple enough to load with a couple of
8387 instructions. If using 32-bit registers, set
8388 imm_expr to the high order 32 bits and offset_expr to
8389 the low order 32 bits. Otherwise, set imm_expr to
8390 the entire 64 bit constant. */
8391 if (using_gprs ? HAVE_32BIT_GPRS : HAVE_32BIT_FPRS)
8393 imm_expr.X_op = O_constant;
8394 offset_expr.X_op = O_constant;
8395 if (! target_big_endian)
8397 imm_expr.X_add_number = bfd_getl32 (temp + 4);
8398 offset_expr.X_add_number = bfd_getl32 (temp);
8402 imm_expr.X_add_number = bfd_getb32 (temp);
8403 offset_expr.X_add_number = bfd_getb32 (temp + 4);
8405 if (offset_expr.X_add_number == 0)
8406 offset_expr.X_op = O_absent;
8408 else if (sizeof (imm_expr.X_add_number) > 4)
8410 imm_expr.X_op = O_constant;
8411 if (! target_big_endian)
8412 imm_expr.X_add_number = bfd_getl64 (temp);
8414 imm_expr.X_add_number = bfd_getb64 (temp);
8418 imm_expr.X_op = O_big;
8419 imm_expr.X_add_number = 4;
8420 if (! target_big_endian)
8422 generic_bignum[0] = bfd_getl16 (temp);
8423 generic_bignum[1] = bfd_getl16 (temp + 2);
8424 generic_bignum[2] = bfd_getl16 (temp + 4);
8425 generic_bignum[3] = bfd_getl16 (temp + 6);
8429 generic_bignum[0] = bfd_getb16 (temp + 6);
8430 generic_bignum[1] = bfd_getb16 (temp + 4);
8431 generic_bignum[2] = bfd_getb16 (temp + 2);
8432 generic_bignum[3] = bfd_getb16 (temp);
8438 const char *newname;
8441 /* Switch to the right section. */
8443 subseg = now_subseg;
8446 default: /* unused default case avoids warnings. */
8448 newname = RDATA_SECTION_NAME;
8449 if ((USE_GLOBAL_POINTER_OPT && g_switch_value >= 8)
8450 || mips_pic == EMBEDDED_PIC)
8454 if (mips_pic == EMBEDDED_PIC)
8457 newname = RDATA_SECTION_NAME;
8460 assert (!USE_GLOBAL_POINTER_OPT
8461 || g_switch_value >= 4);
8465 new_seg = subseg_new (newname, (subsegT) 0);
8466 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
8467 bfd_set_section_flags (stdoutput, new_seg,
8472 frag_align (*args == 'l' ? 2 : 3, 0, 0);
8473 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
8474 && strcmp (TARGET_OS, "elf") != 0)
8475 record_alignment (new_seg, 4);
8477 record_alignment (new_seg, *args == 'l' ? 2 : 3);
8479 as_bad (_("Can't use floating point insn in this section"));
8481 /* Set the argument to the current address in the
8483 offset_expr.X_op = O_symbol;
8484 offset_expr.X_add_symbol =
8485 symbol_new ("L0\001", now_seg,
8486 (valueT) frag_now_fix (), frag_now);
8487 offset_expr.X_add_number = 0;
8489 /* Put the floating point number into the section. */
8490 p = frag_more ((int) length);
8491 memcpy (p, temp, length);
8493 /* Switch back to the original section. */
8494 subseg_set (seg, subseg);
8499 case 'i': /* 16 bit unsigned immediate */
8500 case 'j': /* 16 bit signed immediate */
8501 *imm_reloc = BFD_RELOC_LO16;
8502 c = my_getSmallExpression (&imm_expr, s);
8507 if (imm_expr.X_op == O_constant)
8508 imm_expr.X_add_number =
8509 (imm_expr.X_add_number >> 16) & 0xffff;
8511 else if (c == S_EX_HIGHEST)
8512 *imm_reloc = BFD_RELOC_MIPS_HIGHEST;
8513 else if (c == S_EX_HIGHER)
8514 *imm_reloc = BFD_RELOC_MIPS_HIGHER;
8515 else if (c == S_EX_GP_REL)
8517 /* This occurs in NewABI only. */
8518 c = my_getSmallExpression (&imm_expr, s);
8520 as_bad (_("bad composition of relocations"));
8523 c = my_getSmallExpression (&imm_expr, s);
8525 as_bad (_("bad composition of relocations"));
8528 imm_reloc[0] = BFD_RELOC_GPREL16;
8529 imm_reloc[1] = BFD_RELOC_MIPS_SUB;
8530 imm_reloc[2] = BFD_RELOC_LO16;
8535 else if (c == S_EX_HI)
8537 *imm_reloc = BFD_RELOC_HI16_S;
8538 imm_unmatched_hi = true;
8541 *imm_reloc = BFD_RELOC_HI16;
8543 else if (imm_expr.X_op == O_constant)
8544 imm_expr.X_add_number &= 0xffff;
8548 if ((c == S_EX_NONE && imm_expr.X_op != O_constant)
8549 || ((imm_expr.X_add_number < 0
8550 || imm_expr.X_add_number >= 0x10000)
8551 && imm_expr.X_op == O_constant))
8553 if (insn + 1 < &mips_opcodes[NUMOPCODES] &&
8554 !strcmp (insn->name, insn[1].name))
8556 if (imm_expr.X_op == O_constant
8557 || imm_expr.X_op == O_big)
8558 as_bad (_("16 bit expression not in range 0..65535"));
8566 /* The upper bound should be 0x8000, but
8567 unfortunately the MIPS assembler accepts numbers
8568 from 0x8000 to 0xffff and sign extends them, and
8569 we want to be compatible. We only permit this
8570 extended range for an instruction which does not
8571 provide any further alternates, since those
8572 alternates may handle other cases. People should
8573 use the numbers they mean, rather than relying on
8574 a mysterious sign extension. */
8575 more = (insn + 1 < &mips_opcodes[NUMOPCODES] &&
8576 strcmp (insn->name, insn[1].name) == 0);
8581 if ((c == S_EX_NONE && imm_expr.X_op != O_constant)
8582 || ((imm_expr.X_add_number < -0x8000
8583 || imm_expr.X_add_number >= max)
8584 && imm_expr.X_op == O_constant)
8586 && imm_expr.X_add_number < 0
8588 && imm_expr.X_unsigned
8589 && sizeof (imm_expr.X_add_number) <= 4))
8593 if (imm_expr.X_op == O_constant
8594 || imm_expr.X_op == O_big)
8595 as_bad (_("16 bit expression not in range -32768..32767"));
8601 case 'o': /* 16 bit offset */
8602 c = my_getSmallExpression (&offset_expr, s);
8604 /* If this value won't fit into a 16 bit offset, then go
8605 find a macro that will generate the 32 bit offset
8608 && (offset_expr.X_op != O_constant
8609 || offset_expr.X_add_number >= 0x8000
8610 || offset_expr.X_add_number < -0x8000))
8615 if (offset_expr.X_op != O_constant)
8617 offset_expr.X_add_number =
8618 (offset_expr.X_add_number >> 16) & 0xffff;
8620 *offset_reloc = BFD_RELOC_LO16;
8624 case 'p': /* pc relative offset */
8625 if (mips_pic == EMBEDDED_PIC)
8626 *offset_reloc = BFD_RELOC_16_PCREL_S2;
8628 *offset_reloc = BFD_RELOC_16_PCREL;
8629 my_getExpression (&offset_expr, s);
8633 case 'u': /* upper 16 bits */
8634 c = my_getSmallExpression (&imm_expr, s);
8635 *imm_reloc = BFD_RELOC_LO16;
8640 if (imm_expr.X_op == O_constant)
8641 imm_expr.X_add_number =
8642 (imm_expr.X_add_number >> 16) & 0xffff;
8643 else if (c == S_EX_HI)
8645 *imm_reloc = BFD_RELOC_HI16_S;
8646 imm_unmatched_hi = true;
8649 else if (c == S_EX_HIGHEST)
8650 *imm_reloc = BFD_RELOC_MIPS_HIGHEST;
8651 else if (c == S_EX_GP_REL)
8653 /* This occurs in NewABI only. */
8654 c = my_getSmallExpression (&imm_expr, s);
8656 as_bad (_("bad composition of relocations"));
8659 c = my_getSmallExpression (&imm_expr, s);
8661 as_bad (_("bad composition of relocations"));
8664 imm_reloc[0] = BFD_RELOC_GPREL16;
8665 imm_reloc[1] = BFD_RELOC_MIPS_SUB;
8666 imm_reloc[2] = BFD_RELOC_HI16_S;
8672 *imm_reloc = BFD_RELOC_HI16;
8674 else if (imm_expr.X_op == O_constant)
8675 imm_expr.X_add_number &= 0xffff;
8677 if (imm_expr.X_op == O_constant
8678 && (imm_expr.X_add_number < 0
8679 || imm_expr.X_add_number >= 0x10000))
8680 as_bad (_("lui expression not in range 0..65535"));
8684 case 'a': /* 26 bit address */
8685 my_getExpression (&offset_expr, s);
8687 *offset_reloc = BFD_RELOC_MIPS_JMP;
8690 case 'N': /* 3 bit branch condition code */
8691 case 'M': /* 3 bit compare condition code */
8692 if (strncmp (s, "$fcc", 4) != 0)
8702 while (ISDIGIT (*s));
8704 as_bad (_("invalid condition code register $fcc%d"), regno);
8706 ip->insn_opcode |= regno << OP_SH_BCC;
8708 ip->insn_opcode |= regno << OP_SH_CCC;
8712 if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X'))
8723 while (ISDIGIT (*s));
8726 c = 8; /* Invalid sel value. */
8729 as_bad (_("invalid coprocessor sub-selection value (0-7)"));
8730 ip->insn_opcode |= c;
8734 as_bad (_("bad char = '%c'\n"), *args);
8739 /* Args don't match. */
8740 if (insn + 1 < &mips_opcodes[NUMOPCODES] &&
8741 !strcmp (insn->name, insn[1].name))
8745 insn_error = _("illegal operands");
8750 insn_error = _("illegal operands");
8755 /* This routine assembles an instruction into its binary format when
8756 assembling for the mips16. As a side effect, it sets one of the
8757 global variables imm_reloc or offset_reloc to the type of
8758 relocation to do if one of the operands is an address expression.
8759 It also sets mips16_small and mips16_ext if the user explicitly
8760 requested a small or extended instruction. */
8765 struct mips_cl_insn *ip;
8769 struct mips_opcode *insn;
8772 unsigned int lastregno = 0;
8777 mips16_small = false;
8780 for (s = str; ISLOWER (*s); ++s)
8792 if (s[1] == 't' && s[2] == ' ')
8795 mips16_small = true;
8799 else if (s[1] == 'e' && s[2] == ' ')
8808 insn_error = _("unknown opcode");
8812 if (mips_opts.noautoextend && ! mips16_ext)
8813 mips16_small = true;
8815 if ((insn = (struct mips_opcode *) hash_find (mips16_op_hash, str)) == NULL)
8817 insn_error = _("unrecognized opcode");
8824 assert (strcmp (insn->name, str) == 0);
8827 ip->insn_opcode = insn->match;
8828 ip->use_extend = false;
8829 imm_expr.X_op = O_absent;
8830 imm_reloc[0] = BFD_RELOC_UNUSED;
8831 imm_reloc[1] = BFD_RELOC_UNUSED;
8832 imm_reloc[2] = BFD_RELOC_UNUSED;
8833 offset_expr.X_op = O_absent;
8834 offset_reloc[0] = BFD_RELOC_UNUSED;
8835 offset_reloc[1] = BFD_RELOC_UNUSED;
8836 offset_reloc[2] = BFD_RELOC_UNUSED;
8837 for (args = insn->args; 1; ++args)
8844 /* In this switch statement we call break if we did not find
8845 a match, continue if we did find a match, or return if we
8854 /* Stuff the immediate value in now, if we can. */
8855 if (imm_expr.X_op == O_constant
8856 && *imm_reloc > BFD_RELOC_UNUSED
8857 && insn->pinfo != INSN_MACRO)
8859 mips16_immed (NULL, 0, *imm_reloc - BFD_RELOC_UNUSED,
8860 imm_expr.X_add_number, true, mips16_small,
8861 mips16_ext, &ip->insn_opcode,
8862 &ip->use_extend, &ip->extend);
8863 imm_expr.X_op = O_absent;
8864 *imm_reloc = BFD_RELOC_UNUSED;
8878 ip->insn_opcode |= lastregno << MIPS16OP_SH_RX;
8881 ip->insn_opcode |= lastregno << MIPS16OP_SH_RY;
8897 ip->insn_opcode |= lastregno << MIPS16OP_SH_RX;
8899 ip->insn_opcode |= lastregno << MIPS16OP_SH_RY;
8926 while (ISDIGIT (*s));
8929 as_bad (_("invalid register number (%d)"), regno);
8935 if (s[1] == 'r' && s[2] == 'a')
8940 else if (s[1] == 'f' && s[2] == 'p')
8945 else if (s[1] == 's' && s[2] == 'p')
8950 else if (s[1] == 'g' && s[2] == 'p')
8955 else if (s[1] == 'a' && s[2] == 't')
8960 else if (s[1] == 'k' && s[2] == 't' && s[3] == '0')
8965 else if (s[1] == 'k' && s[2] == 't' && s[3] == '1')
8970 else if (s[1] == 'z' && s[2] == 'e' && s[3] == 'r' && s[4] == 'o')
8983 if (c == 'v' || c == 'w')
8985 regno = mips16_to_32_reg_map[lastregno];
8999 regno = mips32_to_16_reg_map[regno];
9004 regno = ILLEGAL_REG;
9009 regno = ILLEGAL_REG;
9014 regno = ILLEGAL_REG;
9019 if (regno == AT && ! mips_opts.noat)
9020 as_warn (_("used $at without \".set noat\""));
9027 if (regno == ILLEGAL_REG)
9034 ip->insn_opcode |= regno << MIPS16OP_SH_RX;
9038 ip->insn_opcode |= regno << MIPS16OP_SH_RY;
9041 ip->insn_opcode |= regno << MIPS16OP_SH_RZ;
9044 ip->insn_opcode |= regno << MIPS16OP_SH_MOVE32Z;
9050 ip->insn_opcode |= regno << MIPS16OP_SH_REGR32;
9053 regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3);
9054 ip->insn_opcode |= regno << MIPS16OP_SH_REG32R;
9064 if (strncmp (s, "$pc", 3) == 0)
9088 && strncmp (s + 1, "gprel(", sizeof "gprel(" - 1) == 0)
9090 /* This is %gprel(SYMBOL). We need to read SYMBOL,
9091 and generate the appropriate reloc. If the text
9092 inside %gprel is not a symbol name with an
9093 optional offset, then we generate a normal reloc
9094 and will probably fail later. */
9095 my_getExpression (&imm_expr, s + sizeof "%gprel" - 1);
9096 if (imm_expr.X_op == O_symbol)
9099 *imm_reloc = BFD_RELOC_MIPS16_GPREL;
9101 ip->use_extend = true;
9108 /* Just pick up a normal expression. */
9109 my_getExpression (&imm_expr, s);
9112 if (imm_expr.X_op == O_register)
9114 /* What we thought was an expression turned out to
9117 if (s[0] == '(' && args[1] == '(')
9119 /* It looks like the expression was omitted
9120 before a register indirection, which means
9121 that the expression is implicitly zero. We
9122 still set up imm_expr, so that we handle
9123 explicit extensions correctly. */
9124 imm_expr.X_op = O_constant;
9125 imm_expr.X_add_number = 0;
9126 *imm_reloc = (int) BFD_RELOC_UNUSED + c;
9133 /* We need to relax this instruction. */
9134 *imm_reloc = (int) BFD_RELOC_UNUSED + c;
9143 /* We use offset_reloc rather than imm_reloc for the PC
9144 relative operands. This lets macros with both
9145 immediate and address operands work correctly. */
9146 my_getExpression (&offset_expr, s);
9148 if (offset_expr.X_op == O_register)
9151 /* We need to relax this instruction. */
9152 *offset_reloc = (int) BFD_RELOC_UNUSED + c;
9156 case '6': /* break code */
9157 my_getExpression (&imm_expr, s);
9158 check_absolute_expr (ip, &imm_expr);
9159 if ((unsigned long) imm_expr.X_add_number > 63)
9161 as_warn (_("Invalid value for `%s' (%lu)"),
9163 (unsigned long) imm_expr.X_add_number);
9164 imm_expr.X_add_number &= 0x3f;
9166 ip->insn_opcode |= imm_expr.X_add_number << MIPS16OP_SH_IMM6;
9167 imm_expr.X_op = O_absent;
9171 case 'a': /* 26 bit address */
9172 my_getExpression (&offset_expr, s);
9174 *offset_reloc = BFD_RELOC_MIPS16_JMP;
9175 ip->insn_opcode <<= 16;
9178 case 'l': /* register list for entry macro */
9179 case 'L': /* register list for exit macro */
9189 int freg, reg1, reg2;
9191 while (*s == ' ' || *s == ',')
9195 as_bad (_("can't parse register list"));
9207 while (ISDIGIT (*s))
9229 as_bad (_("invalid register list"));
9234 while (ISDIGIT (*s))
9241 if (freg && reg1 == 0 && reg2 == 0 && c == 'L')
9246 else if (freg && reg1 == 0 && reg2 == 1 && c == 'L')
9251 else if (reg1 == 4 && reg2 >= 4 && reg2 <= 7 && c != 'L')
9252 mask |= (reg2 - 3) << 3;
9253 else if (reg1 == 16 && reg2 >= 16 && reg2 <= 17)
9254 mask |= (reg2 - 15) << 1;
9255 else if (reg1 == RA && reg2 == RA)
9259 as_bad (_("invalid register list"));
9263 /* The mask is filled in in the opcode table for the
9264 benefit of the disassembler. We remove it before
9265 applying the actual mask. */
9266 ip->insn_opcode &= ~ ((7 << 3) << MIPS16OP_SH_IMM6);
9267 ip->insn_opcode |= mask << MIPS16OP_SH_IMM6;
9271 case 'e': /* extend code */
9272 my_getExpression (&imm_expr, s);
9273 check_absolute_expr (ip, &imm_expr);
9274 if ((unsigned long) imm_expr.X_add_number > 0x7ff)
9276 as_warn (_("Invalid value for `%s' (%lu)"),
9278 (unsigned long) imm_expr.X_add_number);
9279 imm_expr.X_add_number &= 0x7ff;
9281 ip->insn_opcode |= imm_expr.X_add_number;
9282 imm_expr.X_op = O_absent;
9292 /* Args don't match. */
9293 if (insn + 1 < &mips16_opcodes[bfd_mips16_num_opcodes] &&
9294 strcmp (insn->name, insn[1].name) == 0)
9301 insn_error = _("illegal operands");
9307 /* This structure holds information we know about a mips16 immediate
9310 struct mips16_immed_operand
9312 /* The type code used in the argument string in the opcode table. */
9314 /* The number of bits in the short form of the opcode. */
9316 /* The number of bits in the extended form of the opcode. */
9318 /* The amount by which the short form is shifted when it is used;
9319 for example, the sw instruction has a shift count of 2. */
9321 /* The amount by which the short form is shifted when it is stored
9322 into the instruction code. */
9324 /* Non-zero if the short form is unsigned. */
9326 /* Non-zero if the extended form is unsigned. */
9328 /* Non-zero if the value is PC relative. */
9332 /* The mips16 immediate operand types. */
9334 static const struct mips16_immed_operand mips16_immed_operands[] =
9336 { '<', 3, 5, 0, MIPS16OP_SH_RZ, 1, 1, 0 },
9337 { '>', 3, 5, 0, MIPS16OP_SH_RX, 1, 1, 0 },
9338 { '[', 3, 6, 0, MIPS16OP_SH_RZ, 1, 1, 0 },
9339 { ']', 3, 6, 0, MIPS16OP_SH_RX, 1, 1, 0 },
9340 { '4', 4, 15, 0, MIPS16OP_SH_IMM4, 0, 0, 0 },
9341 { '5', 5, 16, 0, MIPS16OP_SH_IMM5, 1, 0, 0 },
9342 { 'H', 5, 16, 1, MIPS16OP_SH_IMM5, 1, 0, 0 },
9343 { 'W', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 0 },
9344 { 'D', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 0 },
9345 { 'j', 5, 16, 0, MIPS16OP_SH_IMM5, 0, 0, 0 },
9346 { '8', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 0, 0 },
9347 { 'V', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 0 },
9348 { 'C', 8, 16, 3, MIPS16OP_SH_IMM8, 1, 0, 0 },
9349 { 'U', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 1, 0 },
9350 { 'k', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 0 },
9351 { 'K', 8, 16, 3, MIPS16OP_SH_IMM8, 0, 0, 0 },
9352 { 'p', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 },
9353 { 'q', 11, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 },
9354 { 'A', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 1 },
9355 { 'B', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 1 },
9356 { 'E', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 1 }
9359 #define MIPS16_NUM_IMMED \
9360 (sizeof mips16_immed_operands / sizeof mips16_immed_operands[0])
9362 /* Handle a mips16 instruction with an immediate value. This or's the
9363 small immediate value into *INSN. It sets *USE_EXTEND to indicate
9364 whether an extended value is needed; if one is needed, it sets
9365 *EXTEND to the value. The argument type is TYPE. The value is VAL.
9366 If SMALL is true, an unextended opcode was explicitly requested.
9367 If EXT is true, an extended opcode was explicitly requested. If
9368 WARN is true, warn if EXT does not match reality. */
9371 mips16_immed (file, line, type, val, warn, small, ext, insn, use_extend,
9380 unsigned long *insn;
9381 boolean *use_extend;
9382 unsigned short *extend;
9384 register const struct mips16_immed_operand *op;
9385 int mintiny, maxtiny;
9388 op = mips16_immed_operands;
9389 while (op->type != type)
9392 assert (op < mips16_immed_operands + MIPS16_NUM_IMMED);
9397 if (type == '<' || type == '>' || type == '[' || type == ']')
9400 maxtiny = 1 << op->nbits;
9405 maxtiny = (1 << op->nbits) - 1;
9410 mintiny = - (1 << (op->nbits - 1));
9411 maxtiny = (1 << (op->nbits - 1)) - 1;
9414 /* Branch offsets have an implicit 0 in the lowest bit. */
9415 if (type == 'p' || type == 'q')
9418 if ((val & ((1 << op->shift) - 1)) != 0
9419 || val < (mintiny << op->shift)
9420 || val > (maxtiny << op->shift))
9425 if (warn && ext && ! needext)
9426 as_warn_where (file, line,
9427 _("extended operand requested but not required"));
9428 if (small && needext)
9429 as_bad_where (file, line, _("invalid unextended operand value"));
9431 if (small || (! ext && ! needext))
9435 *use_extend = false;
9436 insnval = ((val >> op->shift) & ((1 << op->nbits) - 1));
9437 insnval <<= op->op_shift;
9442 long minext, maxext;
9448 maxext = (1 << op->extbits) - 1;
9452 minext = - (1 << (op->extbits - 1));
9453 maxext = (1 << (op->extbits - 1)) - 1;
9455 if (val < minext || val > maxext)
9456 as_bad_where (file, line,
9457 _("operand value out of range for instruction"));
9460 if (op->extbits == 16)
9462 extval = ((val >> 11) & 0x1f) | (val & 0x7e0);
9465 else if (op->extbits == 15)
9467 extval = ((val >> 11) & 0xf) | (val & 0x7f0);
9472 extval = ((val & 0x1f) << 6) | (val & 0x20);
9476 *extend = (unsigned short) extval;
9481 static struct percent_op_match
9484 const enum small_ex_type type;
9489 {"%call_hi", S_EX_CALL_HI},
9490 {"%call_lo", S_EX_CALL_LO},
9491 {"%call16", S_EX_CALL16},
9492 {"%got_disp", S_EX_GOT_DISP},
9493 {"%got_page", S_EX_GOT_PAGE},
9494 {"%got_ofst", S_EX_GOT_OFST},
9495 {"%got_hi", S_EX_GOT_HI},
9496 {"%got_lo", S_EX_GOT_LO},
9498 {"%gp_rel", S_EX_GP_REL},
9499 {"%half", S_EX_HALF},
9500 {"%highest", S_EX_HIGHEST},
9501 {"%higher", S_EX_HIGHER},
9507 /* Parse small expression input. STR gets adjusted to eat up whitespace.
9508 It detects valid "%percent_op(...)" and "($reg)" strings. Percent_op's
9509 can be nested, this is handled by blanking the innermost, parsing the
9510 rest by subsequent calls. */
9513 my_getSmallParser (str, len, nestlevel)
9519 *str += strspn (*str, " \t");
9520 /* Check for expression in parentheses. */
9523 char *b = *str + 1 + strspn (*str + 1, " \t");
9526 /* Check for base register. */
9530 && (e = b + strcspn (b, ") \t"))
9531 && e - b > 1 && e - b < 4)
9534 && ((b[1] == 'f' && b[2] == 'p')
9535 || (b[1] == 's' && b[2] == 'p')
9536 || (b[1] == 'g' && b[2] == 'p')
9537 || (b[1] == 'a' && b[2] == 't')
9539 && ISDIGIT (b[2]))))
9540 || (ISDIGIT (b[1])))
9542 *len = strcspn (*str, ")") + 1;
9543 return S_EX_REGISTER;
9547 /* Check for percent_op (in parentheses). */
9548 else if (b[0] == '%')
9551 return my_getPercentOp (str, len, nestlevel);
9554 /* Some other expression in the parentheses, which can contain
9555 parentheses itself. Attempt to find the matching one. */
9561 for (s = *str + 1; *s && pcnt; s++, (*len)++)
9570 /* Check for percent_op (outside of parentheses). */
9571 else if (*str[0] == '%')
9572 return my_getPercentOp (str, len, nestlevel);
9574 /* Any other expression. */
9579 my_getPercentOp (str, len, nestlevel)
9584 char *tmp = *str + 1;
9587 while (ISALPHA (*tmp) || *tmp == '_')
9589 *tmp = TOLOWER (*tmp);
9592 while (i < (sizeof (percent_op) / sizeof (struct percent_op_match)))
9594 if (strncmp (*str, percent_op[i].str, strlen (percent_op[i].str)))
9598 int type = percent_op[i].type;
9600 /* Only %hi and %lo are allowed for OldABI. */
9601 if (! HAVE_NEWABI && type != S_EX_HI && type != S_EX_LO)
9604 *len = strlen (percent_op[i].str);
9613 my_getSmallExpression (ep, str)
9617 static char *oldstr = NULL;
9623 /* Don't update oldstr if the last call had nested percent_op's. We need
9624 it to parse the outer ones later. */
9631 c = my_getSmallParser (&str, &len, &nestlevel);
9632 if (c != S_EX_NONE && c != S_EX_REGISTER)
9635 while (c != S_EX_NONE && c != S_EX_REGISTER);
9639 /* A percent_op was encountered. Don't try to get an expression if
9640 it is already blanked out. */
9641 if (*(str + strspn (str + 1, " )")) != ')')
9645 /* Let my_getExpression() stop at the closing parenthesis. */
9646 save = *(str + len);
9647 *(str + len) = '\0';
9648 my_getExpression (ep, str);
9649 *(str + len) = save;
9653 /* Blank out including the % sign and the proper matching
9656 char *s = strrchr (oldstr, '%');
9659 for (end = strchr (s, '(') + 1; *end && pcnt; end++)
9663 else if (*end == ')')
9667 memset (s, ' ', end - s);
9671 expr_end = str + len;
9675 else if (c == S_EX_NONE)
9677 my_getExpression (ep, str);
9679 else if (c == S_EX_REGISTER)
9681 ep->X_op = O_constant;
9683 ep->X_add_symbol = NULL;
9684 ep->X_op_symbol = NULL;
9685 ep->X_add_number = 0;
9689 as_fatal (_("internal error"));
9693 /* All percent_op's have been handled. */
9700 my_getExpression (ep, str)
9707 save_in = input_line_pointer;
9708 input_line_pointer = str;
9710 expr_end = input_line_pointer;
9711 input_line_pointer = save_in;
9713 /* If we are in mips16 mode, and this is an expression based on `.',
9714 then we bump the value of the symbol by 1 since that is how other
9715 text symbols are handled. We don't bother to handle complex
9716 expressions, just `.' plus or minus a constant. */
9717 if (mips_opts.mips16
9718 && ep->X_op == O_symbol
9719 && strcmp (S_GET_NAME (ep->X_add_symbol), FAKE_LABEL_NAME) == 0
9720 && S_GET_SEGMENT (ep->X_add_symbol) == now_seg
9721 && symbol_get_frag (ep->X_add_symbol) == frag_now
9722 && symbol_constant_p (ep->X_add_symbol)
9723 && (val = S_GET_VALUE (ep->X_add_symbol)) == frag_now_fix ())
9724 S_SET_VALUE (ep->X_add_symbol, val + 1);
9727 /* Turn a string in input_line_pointer into a floating point constant
9728 of type TYPE, and store the appropriate bytes in *LITP. The number
9729 of LITTLENUMS emitted is stored in *SIZEP. An error message is
9730 returned, or NULL on OK. */
9733 md_atof (type, litP, sizeP)
9739 LITTLENUM_TYPE words[4];
9755 return _("bad call to md_atof");
9758 t = atof_ieee (input_line_pointer, type, words);
9760 input_line_pointer = t;
9764 if (! target_big_endian)
9766 for (i = prec - 1; i >= 0; i--)
9768 md_number_to_chars (litP, (valueT) words[i], 2);
9774 for (i = 0; i < prec; i++)
9776 md_number_to_chars (litP, (valueT) words[i], 2);
9785 md_number_to_chars (buf, val, n)
9790 if (target_big_endian)
9791 number_to_chars_bigendian (buf, val, n);
9793 number_to_chars_littleendian (buf, val, n);
9797 static int support_64bit_objects(void)
9799 const char **list, **l;
9801 list = bfd_target_list ();
9802 for (l = list; *l != NULL; l++)
9804 /* This is traditional mips */
9805 if (strcmp (*l, "elf64-tradbigmips") == 0
9806 || strcmp (*l, "elf64-tradlittlemips") == 0)
9808 if (strcmp (*l, "elf64-bigmips") == 0
9809 || strcmp (*l, "elf64-littlemips") == 0)
9813 return (*l != NULL);
9815 #endif /* OBJ_ELF */
9817 CONST char *md_shortopts = "nO::g::G:";
9819 struct option md_longopts[] =
9821 #define OPTION_MIPS1 (OPTION_MD_BASE + 1)
9822 {"mips0", no_argument, NULL, OPTION_MIPS1},
9823 {"mips1", no_argument, NULL, OPTION_MIPS1},
9824 #define OPTION_MIPS2 (OPTION_MD_BASE + 2)
9825 {"mips2", no_argument, NULL, OPTION_MIPS2},
9826 #define OPTION_MIPS3 (OPTION_MD_BASE + 3)
9827 {"mips3", no_argument, NULL, OPTION_MIPS3},
9828 #define OPTION_MIPS4 (OPTION_MD_BASE + 4)
9829 {"mips4", no_argument, NULL, OPTION_MIPS4},
9830 #define OPTION_MIPS5 (OPTION_MD_BASE + 5)
9831 {"mips5", no_argument, NULL, OPTION_MIPS5},
9832 #define OPTION_MIPS32 (OPTION_MD_BASE + 6)
9833 {"mips32", no_argument, NULL, OPTION_MIPS32},
9834 #define OPTION_MIPS64 (OPTION_MD_BASE + 7)
9835 {"mips64", no_argument, NULL, OPTION_MIPS64},
9836 #define OPTION_MEMBEDDED_PIC (OPTION_MD_BASE + 8)
9837 {"membedded-pic", no_argument, NULL, OPTION_MEMBEDDED_PIC},
9838 #define OPTION_TRAP (OPTION_MD_BASE + 9)
9839 {"trap", no_argument, NULL, OPTION_TRAP},
9840 {"no-break", no_argument, NULL, OPTION_TRAP},
9841 #define OPTION_BREAK (OPTION_MD_BASE + 10)
9842 {"break", no_argument, NULL, OPTION_BREAK},
9843 {"no-trap", no_argument, NULL, OPTION_BREAK},
9844 #define OPTION_EB (OPTION_MD_BASE + 11)
9845 {"EB", no_argument, NULL, OPTION_EB},
9846 #define OPTION_EL (OPTION_MD_BASE + 12)
9847 {"EL", no_argument, NULL, OPTION_EL},
9848 #define OPTION_MIPS16 (OPTION_MD_BASE + 13)
9849 {"mips16", no_argument, NULL, OPTION_MIPS16},
9850 #define OPTION_NO_MIPS16 (OPTION_MD_BASE + 14)
9851 {"no-mips16", no_argument, NULL, OPTION_NO_MIPS16},
9852 #define OPTION_M7000_HILO_FIX (OPTION_MD_BASE + 15)
9853 {"mfix7000", no_argument, NULL, OPTION_M7000_HILO_FIX},
9854 #define OPTION_MNO_7000_HILO_FIX (OPTION_MD_BASE + 16)
9855 {"no-fix-7000", no_argument, NULL, OPTION_MNO_7000_HILO_FIX},
9856 {"mno-fix7000", no_argument, NULL, OPTION_MNO_7000_HILO_FIX},
9857 #define OPTION_FP32 (OPTION_MD_BASE + 17)
9858 {"mfp32", no_argument, NULL, OPTION_FP32},
9859 #define OPTION_GP32 (OPTION_MD_BASE + 18)
9860 {"mgp32", no_argument, NULL, OPTION_GP32},
9861 #define OPTION_CONSTRUCT_FLOATS (OPTION_MD_BASE + 19)
9862 {"construct-floats", no_argument, NULL, OPTION_CONSTRUCT_FLOATS},
9863 #define OPTION_NO_CONSTRUCT_FLOATS (OPTION_MD_BASE + 20)
9864 {"no-construct-floats", no_argument, NULL, OPTION_NO_CONSTRUCT_FLOATS},
9865 #define OPTION_MARCH (OPTION_MD_BASE + 21)
9866 {"march", required_argument, NULL, OPTION_MARCH},
9867 #define OPTION_MTUNE (OPTION_MD_BASE + 22)
9868 {"mtune", required_argument, NULL, OPTION_MTUNE},
9869 #define OPTION_MCPU (OPTION_MD_BASE + 23)
9870 {"mcpu", required_argument, NULL, OPTION_MCPU},
9871 #define OPTION_M4650 (OPTION_MD_BASE + 24)
9872 {"m4650", no_argument, NULL, OPTION_M4650},
9873 #define OPTION_NO_M4650 (OPTION_MD_BASE + 25)
9874 {"no-m4650", no_argument, NULL, OPTION_NO_M4650},
9875 #define OPTION_M4010 (OPTION_MD_BASE + 26)
9876 {"m4010", no_argument, NULL, OPTION_M4010},
9877 #define OPTION_NO_M4010 (OPTION_MD_BASE + 27)
9878 {"no-m4010", no_argument, NULL, OPTION_NO_M4010},
9879 #define OPTION_M4100 (OPTION_MD_BASE + 28)
9880 {"m4100", no_argument, NULL, OPTION_M4100},
9881 #define OPTION_NO_M4100 (OPTION_MD_BASE + 29)
9882 {"no-m4100", no_argument, NULL, OPTION_NO_M4100},
9883 #define OPTION_M3900 (OPTION_MD_BASE + 30)
9884 {"m3900", no_argument, NULL, OPTION_M3900},
9885 #define OPTION_NO_M3900 (OPTION_MD_BASE + 31)
9886 {"no-m3900", no_argument, NULL, OPTION_NO_M3900},
9887 #define OPTION_GP64 (OPTION_MD_BASE + 32)
9888 {"mgp64", no_argument, NULL, OPTION_GP64},
9889 #define OPTION_MIPS3D (OPTION_MD_BASE + 33)
9890 {"mips3d", no_argument, NULL, OPTION_MIPS3D},
9891 #define OPTION_NO_MIPS3D (OPTION_MD_BASE + 34)
9892 {"no-mips3d", no_argument, NULL, OPTION_NO_MIPS3D},
9893 #define OPTION_MDMX (OPTION_MD_BASE + 35)
9894 {"mdmx", no_argument, NULL, OPTION_MDMX},
9895 #define OPTION_NO_MDMX (OPTION_MD_BASE + 36)
9896 {"no-mdmx", no_argument, NULL, OPTION_NO_MDMX},
9898 #define OPTION_ELF_BASE (OPTION_MD_BASE + 37)
9899 #define OPTION_CALL_SHARED (OPTION_ELF_BASE + 0)
9900 {"KPIC", no_argument, NULL, OPTION_CALL_SHARED},
9901 {"call_shared", no_argument, NULL, OPTION_CALL_SHARED},
9902 #define OPTION_NON_SHARED (OPTION_ELF_BASE + 1)
9903 {"non_shared", no_argument, NULL, OPTION_NON_SHARED},
9904 #define OPTION_XGOT (OPTION_ELF_BASE + 2)
9905 {"xgot", no_argument, NULL, OPTION_XGOT},
9906 #define OPTION_MABI (OPTION_ELF_BASE + 3)
9907 {"mabi", required_argument, NULL, OPTION_MABI},
9908 #define OPTION_32 (OPTION_ELF_BASE + 4)
9909 {"32", no_argument, NULL, OPTION_32},
9910 #define OPTION_N32 (OPTION_ELF_BASE + 5)
9911 {"n32", no_argument, NULL, OPTION_N32},
9912 #define OPTION_64 (OPTION_ELF_BASE + 6)
9913 {"64", no_argument, NULL, OPTION_64},
9914 #endif /* OBJ_ELF */
9915 {NULL, no_argument, NULL, 0}
9917 size_t md_longopts_size = sizeof (md_longopts);
9920 md_parse_option (c, arg)
9926 case OPTION_CONSTRUCT_FLOATS:
9927 mips_disable_float_construction = 0;
9930 case OPTION_NO_CONSTRUCT_FLOATS:
9931 mips_disable_float_construction = 1;
9943 target_big_endian = 1;
9947 target_big_endian = 0;
9955 if (arg && arg[1] == '0')
9965 mips_debug = atoi (arg);
9966 /* When the MIPS assembler sees -g or -g2, it does not do
9967 optimizations which limit full symbolic debugging. We take
9968 that to be equivalent to -O0. */
9969 if (mips_debug == 2)
9974 mips_opts.isa = ISA_MIPS1;
9978 mips_opts.isa = ISA_MIPS2;
9982 mips_opts.isa = ISA_MIPS3;
9986 mips_opts.isa = ISA_MIPS4;
9990 mips_opts.isa = ISA_MIPS5;
9994 mips_opts.isa = ISA_MIPS32;
9998 mips_opts.isa = ISA_MIPS64;
10005 int cpu = CPU_UNKNOWN;
10007 /* Identify the processor type. */
10008 if (strcasecmp (arg, "default") != 0)
10010 const struct mips_cpu_info *ci;
10012 ci = mips_cpu_info_from_name (arg);
10013 if (ci == NULL || ci->is_isa)
10018 as_fatal (_("invalid architecture -mtune=%s"), arg);
10021 as_fatal (_("invalid architecture -march=%s"), arg);
10024 as_fatal (_("invalid architecture -mcpu=%s"), arg);
10035 if (mips_tune != CPU_UNKNOWN && mips_tune != cpu)
10036 as_warn (_("A different -mtune= was already specified, is now "
10037 "-mtune=%s"), arg);
10041 if (mips_arch != CPU_UNKNOWN && mips_arch != cpu)
10042 as_warn (_("A different -march= was already specified, is now "
10043 "-march=%s"), arg);
10047 if (mips_cpu != CPU_UNKNOWN && mips_cpu != cpu)
10048 as_warn (_("A different -mcpu= was already specified, is now "
10056 if ((mips_arch != CPU_UNKNOWN && mips_arch != CPU_R4650)
10057 || (mips_tune != CPU_UNKNOWN && mips_tune != CPU_R4650))
10058 as_warn (_("A different -march= or -mtune= was already specified, "
10060 mips_arch = CPU_R4650;
10061 mips_tune = CPU_R4650;
10064 case OPTION_NO_M4650:
10068 if ((mips_arch != CPU_UNKNOWN && mips_arch != CPU_R4010)
10069 || (mips_tune != CPU_UNKNOWN && mips_tune != CPU_R4010))
10070 as_warn (_("A different -march= or -mtune= was already specified, "
10072 mips_arch = CPU_R4010;
10073 mips_tune = CPU_R4010;
10076 case OPTION_NO_M4010:
10080 if ((mips_arch != CPU_UNKNOWN && mips_arch != CPU_VR4100)
10081 || (mips_tune != CPU_UNKNOWN && mips_tune != CPU_VR4100))
10082 as_warn (_("A different -march= or -mtune= was already specified, "
10084 mips_arch = CPU_VR4100;
10085 mips_tune = CPU_VR4100;
10088 case OPTION_NO_M4100:
10092 if ((mips_arch != CPU_UNKNOWN && mips_arch != CPU_R3900)
10093 || (mips_tune != CPU_UNKNOWN && mips_tune != CPU_R3900))
10094 as_warn (_("A different -march= or -mtune= was already specified, "
10096 mips_arch = CPU_R3900;
10097 mips_tune = CPU_R3900;
10100 case OPTION_NO_M3900:
10104 mips_opts.ase_mdmx = 1;
10107 case OPTION_NO_MDMX:
10108 mips_opts.ase_mdmx = 0;
10111 case OPTION_MIPS16:
10112 mips_opts.mips16 = 1;
10113 mips_no_prev_insn (false);
10116 case OPTION_NO_MIPS16:
10117 mips_opts.mips16 = 0;
10118 mips_no_prev_insn (false);
10121 case OPTION_MIPS3D:
10122 mips_opts.ase_mips3d = 1;
10125 case OPTION_NO_MIPS3D:
10126 mips_opts.ase_mips3d = 0;
10129 case OPTION_MEMBEDDED_PIC:
10130 mips_pic = EMBEDDED_PIC;
10131 if (USE_GLOBAL_POINTER_OPT && g_switch_seen)
10133 as_bad (_("-G may not be used with embedded PIC code"));
10136 g_switch_value = 0x7fffffff;
10140 /* When generating ELF code, we permit -KPIC and -call_shared to
10141 select SVR4_PIC, and -non_shared to select no PIC. This is
10142 intended to be compatible with Irix 5. */
10143 case OPTION_CALL_SHARED:
10144 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10146 as_bad (_("-call_shared is supported only for ELF format"));
10149 mips_pic = SVR4_PIC;
10150 if (g_switch_seen && g_switch_value != 0)
10152 as_bad (_("-G may not be used with SVR4 PIC code"));
10155 g_switch_value = 0;
10158 case OPTION_NON_SHARED:
10159 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10161 as_bad (_("-non_shared is supported only for ELF format"));
10167 /* The -xgot option tells the assembler to use 32 offsets when
10168 accessing the got in SVR4_PIC mode. It is for Irix
10173 #endif /* OBJ_ELF */
10176 if (! USE_GLOBAL_POINTER_OPT)
10178 as_bad (_("-G is not supported for this configuration"));
10181 else if (mips_pic == SVR4_PIC || mips_pic == EMBEDDED_PIC)
10183 as_bad (_("-G may not be used with SVR4 or embedded PIC code"));
10187 g_switch_value = atoi (arg);
10192 /* The -32, -n32 and -64 options are shortcuts for -mabi=32, -mabi=n32
10195 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10197 as_bad (_("-32 is supported for ELF format only"));
10200 mips_opts.abi = O32_ABI;
10204 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10206 as_bad (_("-n32 is supported for ELF format only"));
10209 mips_opts.abi = N32_ABI;
10213 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10215 as_bad (_("-64 is supported for ELF format only"));
10218 mips_opts.abi = N64_ABI;
10219 if (! support_64bit_objects())
10220 as_fatal (_("No compiled in support for 64 bit object file format"));
10222 #endif /* OBJ_ELF */
10225 file_mips_gp32 = 1;
10226 if (mips_opts.abi != O32_ABI)
10227 mips_opts.abi = NO_ABI;
10231 file_mips_gp32 = 0;
10232 if (mips_opts.abi == O32_ABI)
10233 mips_opts.abi = NO_ABI;
10237 file_mips_fp32 = 1;
10238 if (mips_opts.abi != O32_ABI)
10239 mips_opts.abi = NO_ABI;
10244 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
10246 as_bad (_("-mabi is supported for ELF format only"));
10249 if (strcmp (arg, "32") == 0)
10250 mips_opts.abi = O32_ABI;
10251 else if (strcmp (arg, "o64") == 0)
10252 mips_opts.abi = O64_ABI;
10253 else if (strcmp (arg, "n32") == 0)
10254 mips_opts.abi = N32_ABI;
10255 else if (strcmp (arg, "64") == 0)
10257 mips_opts.abi = N64_ABI;
10258 if (! support_64bit_objects())
10259 as_fatal (_("No compiled in support for 64 bit object file "
10262 else if (strcmp (arg, "eabi") == 0)
10263 mips_opts.abi = EABI_ABI;
10266 as_fatal (_("invalid abi -mabi=%s"), arg);
10270 #endif /* OBJ_ELF */
10272 case OPTION_M7000_HILO_FIX:
10273 mips_7000_hilo_fix = true;
10276 case OPTION_MNO_7000_HILO_FIX:
10277 mips_7000_hilo_fix = false;
10288 show (stream, string, col_p, first_p)
10296 fprintf (stream, "%24s", "");
10301 fprintf (stream, ", ");
10305 if (*col_p + strlen (string) > 72)
10307 fprintf (stream, "\n%24s", "");
10311 fprintf (stream, "%s", string);
10312 *col_p += strlen (string);
10318 md_show_usage (stream)
10323 fprintf (stream, _("\
10325 -membedded-pic generate embedded position independent code\n\
10326 -EB generate big endian output\n\
10327 -EL generate little endian output\n\
10328 -g, -g2 do not remove unneeded NOPs or swap branches\n\
10329 -G NUM allow referencing objects up to NUM bytes\n\
10330 implicitly with the gp register [default 8]\n"));
10331 fprintf (stream, _("\
10332 -mips1 generate MIPS ISA I instructions\n\
10333 -mips2 generate MIPS ISA II instructions\n\
10334 -mips3 generate MIPS ISA III instructions\n\
10335 -mips4 generate MIPS ISA IV instructions\n\
10336 -mips5 generate MIPS ISA V instructions\n\
10337 -mips32 generate MIPS32 ISA instructions\n\
10338 -mips64 generate MIPS64 ISA instructions\n\
10339 -march=CPU/-mtune=CPU generate code/schedule for CPU, where CPU is one of:\n"));
10343 show (stream, "2000", &column, &first);
10344 show (stream, "3000", &column, &first);
10345 show (stream, "3900", &column, &first);
10346 show (stream, "4000", &column, &first);
10347 show (stream, "4010", &column, &first);
10348 show (stream, "4100", &column, &first);
10349 show (stream, "4111", &column, &first);
10350 show (stream, "4300", &column, &first);
10351 show (stream, "4400", &column, &first);
10352 show (stream, "4600", &column, &first);
10353 show (stream, "4650", &column, &first);
10354 show (stream, "5000", &column, &first);
10355 show (stream, "5200", &column, &first);
10356 show (stream, "5230", &column, &first);
10357 show (stream, "5231", &column, &first);
10358 show (stream, "5261", &column, &first);
10359 show (stream, "5721", &column, &first);
10360 show (stream, "6000", &column, &first);
10361 show (stream, "8000", &column, &first);
10362 show (stream, "10000", &column, &first);
10363 show (stream, "12000", &column, &first);
10364 show (stream, "sb1", &column, &first);
10365 fputc ('\n', stream);
10367 fprintf (stream, _("\
10368 -mCPU equivalent to -march=CPU -mtune=CPU. Deprecated.\n\
10369 -no-mCPU don't generate code specific to CPU.\n\
10370 For -mCPU and -no-mCPU, CPU must be one of:\n"));
10374 show (stream, "3900", &column, &first);
10375 show (stream, "4010", &column, &first);
10376 show (stream, "4100", &column, &first);
10377 show (stream, "4650", &column, &first);
10378 fputc ('\n', stream);
10380 fprintf (stream, _("\
10381 -mips16 generate mips16 instructions\n\
10382 -no-mips16 do not generate mips16 instructions\n"));
10383 fprintf (stream, _("\
10384 -mgp32 use 32-bit GPRs, regardless of the chosen ISA\n\
10385 -mfp32 use 32-bit FPRs, regardless of the chosen ISA\n\
10386 -O0 remove unneeded NOPs, do not swap branches\n\
10387 -O remove unneeded NOPs and swap branches\n\
10388 -n warn about NOPs generated from macros\n\
10389 --[no-]construct-floats [dis]allow floating point values to be constructed\n\
10390 --trap, --no-break trap exception on div by 0 and mult overflow\n\
10391 --break, --no-trap break exception on div by 0 and mult overflow\n"));
10393 fprintf (stream, _("\
10394 -KPIC, -call_shared generate SVR4 position independent code\n\
10395 -non_shared do not generate position independent code\n\
10396 -xgot assume a 32 bit GOT\n\
10397 -mabi=ABI create ABI conformant object file for:\n"));
10401 show (stream, "32", &column, &first);
10402 show (stream, "o64", &column, &first);
10403 show (stream, "n32", &column, &first);
10404 show (stream, "64", &column, &first);
10405 show (stream, "eabi", &column, &first);
10407 fputc ('\n', stream);
10409 fprintf (stream, _("\
10410 -32 create o32 ABI object file (default)\n\
10411 -n32 create n32 ABI object file\n\
10412 -64 create 64 ABI object file\n"));
10417 mips_after_parse_args ()
10421 int mips_isa_from_cpu;
10422 int target_cpu_had_mips16 = 0;
10423 const struct mips_cpu_info *ci;
10425 /* GP relative stuff not working for PE */
10426 if (strncmp (TARGET_OS, "pe", 2) == 0
10427 && g_switch_value != 0)
10430 as_bad (_("-G not supported in this configuration."));
10431 g_switch_value = 0;
10435 if (strcmp (cpu + (sizeof TARGET_CPU) - 3, "el") == 0)
10437 a = xmalloc (sizeof TARGET_CPU);
10438 strcpy (a, TARGET_CPU);
10439 a[(sizeof TARGET_CPU) - 3] = '\0';
10443 if (strncmp (cpu, "mips16", sizeof "mips16" - 1) == 0)
10445 target_cpu_had_mips16 = 1;
10446 cpu += sizeof "mips16" - 1;
10449 if (mips_opts.mips16 < 0)
10450 mips_opts.mips16 = target_cpu_had_mips16;
10452 /* Backward compatibility for historic -mcpu= option. Check for
10453 incompatible options, warn if -mcpu is used. */
10454 if (mips_cpu != CPU_UNKNOWN
10455 && mips_arch != CPU_UNKNOWN
10456 && mips_cpu != mips_arch)
10458 as_fatal (_("The -mcpu option can't be used together with -march. "
10459 "Use -mtune instead of -mcpu."));
10462 if (mips_cpu != CPU_UNKNOWN
10463 && mips_tune != CPU_UNKNOWN
10464 && mips_cpu != mips_tune)
10466 as_fatal (_("The -mcpu option can't be used together with -mtune. "
10467 "Use -march instead of -mcpu."));
10471 /* For backward compatibility, let -mipsN set various defaults. */
10472 /* This code should go away, to be replaced with something rather more
10473 draconian. Until GCC 3.1 has been released for some reasonable
10474 amount of time, however, we need to support this. */
10475 if (mips_opts.isa != ISA_UNKNOWN)
10477 /* Translate -mipsN to the appropriate settings of file_mips_gp32
10478 and file_mips_fp32. Tag binaries as using the mipsN ISA. */
10479 if (file_mips_gp32 < 0)
10481 if (ISA_HAS_64BIT_REGS (mips_opts.isa))
10482 file_mips_gp32 = 0;
10484 file_mips_gp32 = 1;
10486 if (file_mips_fp32 < 0)
10488 if (ISA_HAS_64BIT_REGS (mips_opts.isa))
10489 file_mips_fp32 = 0;
10491 file_mips_fp32 = 1;
10494 ci = mips_cpu_info_from_isa (mips_opts.isa);
10495 assert (ci != NULL);
10496 /* -mipsN has higher priority than -mcpu but lower than -march. */
10497 if (mips_arch == CPU_UNKNOWN)
10498 mips_arch = ci->cpu;
10500 /* Default mips_abi. */
10501 if (mips_opts.abi == NO_ABI)
10503 if (mips_opts.isa == ISA_MIPS1 || mips_opts.isa == ISA_MIPS2)
10504 mips_opts.abi = O32_ABI;
10505 else if (mips_opts.isa == ISA_MIPS3 || mips_opts.isa == ISA_MIPS4)
10506 mips_opts.abi = O64_ABI;
10510 if (mips_arch == CPU_UNKNOWN && mips_cpu != CPU_UNKNOWN)
10512 ci = mips_cpu_info_from_cpu (mips_cpu);
10513 assert (ci != NULL);
10514 mips_arch = ci->cpu;
10515 as_warn (_("The -mcpu option is deprecated. Please use -march and "
10516 "-mtune instead."));
10519 /* Set tune from -mcpu, not from -mipsN. */
10520 if (mips_tune == CPU_UNKNOWN && mips_cpu != CPU_UNKNOWN)
10522 ci = mips_cpu_info_from_cpu (mips_cpu);
10523 assert (ci != NULL);
10524 mips_tune = ci->cpu;
10527 /* At this point, mips_arch will either be CPU_UNKNOWN if no ARCH was
10528 specified on the command line, or some other value if one was.
10529 Similarly, mips_opts.isa will be ISA_UNKNOWN if not specified on
10530 the command line, or will be set otherwise if one was. */
10532 if (mips_arch != CPU_UNKNOWN && mips_opts.isa != ISA_UNKNOWN)
10533 /* Handled above. */;
10535 if (mips_arch == CPU_UNKNOWN && mips_cpu != CPU_UNKNOWN)
10537 ci = mips_cpu_info_from_cpu (mips_cpu);
10538 assert (ci != NULL);
10539 mips_arch = ci->cpu;
10540 as_warn (_("The -mcpu option is deprecated. Please use -march and "
10541 "-mtune instead."));
10544 /* At this point, mips_arch will either be CPU_UNKNOWN if no ARCH was
10545 specified on the command line, or some other value if one was.
10546 Similarly, mips_opts.isa will be ISA_UNKNOWN if not specified on
10547 the command line, or will be set otherwise if one was. */
10549 if (mips_arch != CPU_UNKNOWN && mips_opts.isa != ISA_UNKNOWN)
10551 /* We have to check if the isa is the default isa of arch. Otherwise
10552 we'll get invalid object file headers. */
10553 ci = mips_cpu_info_from_cpu (mips_arch);
10554 assert (ci != NULL);
10555 if (mips_opts.isa != ci->isa)
10557 /* This really should be an error instead of a warning, but old
10558 compilers only have -mcpu which sets both arch and tune. For
10559 now, we discard arch and preserve tune. */
10560 as_warn (_("The -march option is incompatible to -mipsN and "
10561 "therefore ignored."));
10562 if (mips_tune == CPU_UNKNOWN)
10563 mips_tune = mips_arch;
10564 ci = mips_cpu_info_from_isa (mips_opts.isa);
10565 assert (ci != NULL);
10566 mips_arch = ci->cpu;
10570 else if (mips_arch != CPU_UNKNOWN && mips_opts.isa == ISA_UNKNOWN)
10572 /* We have ARCH, we need ISA. */
10573 ci = mips_cpu_info_from_cpu (mips_arch);
10574 assert (ci != NULL);
10575 mips_opts.isa = ci->isa;
10577 else if (mips_arch == CPU_UNKNOWN && mips_opts.isa != ISA_UNKNOWN)
10579 /* We have ISA, we need default ARCH. */
10580 ci = mips_cpu_info_from_isa (mips_opts.isa);
10581 assert (ci != NULL);
10582 mips_arch = ci->cpu;
10586 /* We need to set both ISA and ARCH from target cpu. */
10587 ci = mips_cpu_info_from_name (cpu);
10589 ci = mips_cpu_info_from_cpu (CPU_R3000);
10590 assert (ci != NULL);
10591 mips_opts.isa = ci->isa;
10592 mips_arch = ci->cpu;
10595 if (mips_tune == CPU_UNKNOWN)
10596 mips_tune = mips_arch;
10598 ci = mips_cpu_info_from_cpu (mips_arch);
10599 assert (ci != NULL);
10600 mips_isa_from_cpu = ci->isa;
10602 /* End of TARGET_CPU processing, get rid of malloced memory
10611 if (mips_opts.isa == ISA_MIPS1 && mips_trap)
10612 as_bad (_("trap exception not supported at ISA 1"));
10614 /* Set the EABI kind based on the ISA before the user gets
10615 to change the ISA with directives. This isn't really
10616 the best, but then neither is basing the abi on the isa. */
10617 if (ISA_HAS_64BIT_REGS (mips_opts.isa)
10618 && mips_opts.abi == EABI_ABI)
10621 /* If they asked for mips1 or mips2 and a cpu that is
10622 mips3 or greater, then mark the object file 32BITMODE. */
10623 if (mips_isa_from_cpu != ISA_UNKNOWN
10624 && ! ISA_HAS_64BIT_REGS (mips_opts.isa)
10625 && ISA_HAS_64BIT_REGS (mips_isa_from_cpu))
10626 mips_32bitmode = 1;
10628 /* If the selected architecture includes support for ASEs, enable
10629 generation of code for them. */
10630 if (mips_opts.ase_mips3d == -1)
10631 mips_opts.ase_mips3d = CPU_HAS_MIPS3D (mips_arch);
10632 if (mips_opts.ase_mdmx == -1)
10633 mips_opts.ase_mdmx = CPU_HAS_MDMX (mips_arch);
10635 if (file_mips_gp32 < 0)
10636 file_mips_gp32 = 0;
10637 if (file_mips_fp32 < 0)
10638 file_mips_fp32 = 0;
10640 file_mips_isa = mips_opts.isa;
10641 file_mips_abi = mips_opts.abi;
10642 file_ase_mips3d = mips_opts.ase_mips3d;
10643 file_ase_mdmx = mips_opts.ase_mdmx;
10644 mips_opts.gp32 = file_mips_gp32;
10645 mips_opts.fp32 = file_mips_fp32;
10652 mips_init_after_args ()
10654 /* initialize opcodes */
10655 bfd_mips_num_opcodes = bfd_mips_num_builtin_opcodes;
10656 mips_opcodes = (struct mips_opcode *) mips_builtin_opcodes;
10660 md_pcrel_from (fixP)
10663 if (OUTPUT_FLAVOR != bfd_target_aout_flavour
10664 && fixP->fx_addsy != (symbolS *) NULL
10665 && ! S_IS_DEFINED (fixP->fx_addsy))
10667 /* This makes a branch to an undefined symbol be a branch to the
10668 current location. */
10669 if (mips_pic == EMBEDDED_PIC)
10675 /* Return the address of the delay slot. */
10676 return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address;
10679 /* This is called before the symbol table is processed. In order to
10680 work with gcc when using mips-tfile, we must keep all local labels.
10681 However, in other cases, we want to discard them. If we were
10682 called with -g, but we didn't see any debugging information, it may
10683 mean that gcc is smuggling debugging information through to
10684 mips-tfile, in which case we must generate all local labels. */
10687 mips_frob_file_before_adjust ()
10689 #ifndef NO_ECOFF_DEBUGGING
10690 if (ECOFF_DEBUGGING
10692 && ! ecoff_debugging_seen)
10693 flag_keep_locals = 1;
10697 /* Sort any unmatched HI16_S relocs so that they immediately precede
10698 the corresponding LO reloc. This is called before md_apply_fix3 and
10699 tc_gen_reloc. Unmatched HI16_S relocs can only be generated by
10700 explicit use of the %hi modifier. */
10705 struct mips_hi_fixup *l;
10707 for (l = mips_hi_fixup_list; l != NULL; l = l->next)
10709 segment_info_type *seginfo;
10712 assert (l->fixp->fx_r_type == BFD_RELOC_HI16_S);
10714 /* Check quickly whether the next fixup happens to be a matching
10716 if (l->fixp->fx_next != NULL
10717 && l->fixp->fx_next->fx_r_type == BFD_RELOC_LO16
10718 && l->fixp->fx_addsy == l->fixp->fx_next->fx_addsy
10719 && l->fixp->fx_offset == l->fixp->fx_next->fx_offset)
10722 /* Look through the fixups for this segment for a matching %lo.
10723 When we find one, move the %hi just in front of it. We do
10724 this in two passes. In the first pass, we try to find a
10725 unique %lo. In the second pass, we permit multiple %hi
10726 relocs for a single %lo (this is a GNU extension). */
10727 seginfo = seg_info (l->seg);
10728 for (pass = 0; pass < 2; pass++)
10733 for (f = seginfo->fix_root; f != NULL; f = f->fx_next)
10735 /* Check whether this is a %lo fixup which matches l->fixp. */
10736 if (f->fx_r_type == BFD_RELOC_LO16
10737 && f->fx_addsy == l->fixp->fx_addsy
10738 && f->fx_offset == l->fixp->fx_offset
10741 || prev->fx_r_type != BFD_RELOC_HI16_S
10742 || prev->fx_addsy != f->fx_addsy
10743 || prev->fx_offset != f->fx_offset))
10747 /* Move l->fixp before f. */
10748 for (pf = &seginfo->fix_root;
10750 pf = &(*pf)->fx_next)
10751 assert (*pf != NULL);
10753 *pf = l->fixp->fx_next;
10755 l->fixp->fx_next = f;
10757 seginfo->fix_root = l->fixp;
10759 prev->fx_next = l->fixp;
10770 #if 0 /* GCC code motion plus incomplete dead code elimination
10771 can leave a %hi without a %lo. */
10773 as_warn_where (l->fixp->fx_file, l->fixp->fx_line,
10774 _("Unmatched %%hi reloc"));
10780 /* When generating embedded PIC code we need to use a special
10781 relocation to represent the difference of two symbols in the .text
10782 section (switch tables use a difference of this sort). See
10783 include/coff/mips.h for details. This macro checks whether this
10784 fixup requires the special reloc. */
10785 #define SWITCH_TABLE(fixp) \
10786 ((fixp)->fx_r_type == BFD_RELOC_32 \
10787 && OUTPUT_FLAVOR != bfd_target_elf_flavour \
10788 && (fixp)->fx_addsy != NULL \
10789 && (fixp)->fx_subsy != NULL \
10790 && S_GET_SEGMENT ((fixp)->fx_addsy) == text_section \
10791 && S_GET_SEGMENT ((fixp)->fx_subsy) == text_section)
10793 /* When generating embedded PIC code we must keep all PC relative
10794 relocations, in case the linker has to relax a call. We also need
10795 to keep relocations for switch table entries.
10797 We may have combined relocations without symbols in the N32/N64 ABI.
10798 We have to prevent gas from dropping them. */
10801 mips_force_relocation (fixp)
10804 if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT
10805 || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
10809 && S_GET_SEGMENT (fixp->fx_addsy) == bfd_abs_section_ptr
10810 && (fixp->fx_r_type == BFD_RELOC_MIPS_SUB
10811 || fixp->fx_r_type == BFD_RELOC_HI16_S
10812 || fixp->fx_r_type == BFD_RELOC_LO16))
10815 return (mips_pic == EMBEDDED_PIC
10817 || SWITCH_TABLE (fixp)
10818 || fixp->fx_r_type == BFD_RELOC_PCREL_HI16_S
10819 || fixp->fx_r_type == BFD_RELOC_PCREL_LO16));
10824 mips_need_elf_addend_fixup (fixP)
10827 if (S_GET_OTHER (fixP->fx_addsy) == STO_MIPS16)
10829 if (mips_pic == EMBEDDED_PIC
10830 && S_IS_WEAK (fixP->fx_addsy))
10832 if (mips_pic != EMBEDDED_PIC
10833 && (S_IS_WEAK (fixP->fx_addsy)
10834 || S_IS_EXTERN (fixP->fx_addsy))
10835 && !S_IS_COMMON (fixP->fx_addsy))
10837 if (symbol_used_in_reloc_p (fixP->fx_addsy)
10838 && (((bfd_get_section_flags (stdoutput,
10839 S_GET_SEGMENT (fixP->fx_addsy))
10840 & SEC_LINK_ONCE) != 0)
10841 || !strncmp (segment_name (S_GET_SEGMENT (fixP->fx_addsy)),
10843 sizeof (".gnu.linkonce") - 1)))
10849 /* Apply a fixup to the object file. */
10852 md_apply_fix3 (fixP, valP, seg)
10855 segT seg ATTRIBUTE_UNUSED;
10861 assert (fixP->fx_size == 4
10862 || fixP->fx_r_type == BFD_RELOC_16
10863 || fixP->fx_r_type == BFD_RELOC_32
10864 || fixP->fx_r_type == BFD_RELOC_MIPS_JMP
10865 || fixP->fx_r_type == BFD_RELOC_HI16_S
10866 || fixP->fx_r_type == BFD_RELOC_LO16
10867 || fixP->fx_r_type == BFD_RELOC_GPREL16
10868 || fixP->fx_r_type == BFD_RELOC_MIPS_LITERAL
10869 || fixP->fx_r_type == BFD_RELOC_GPREL32
10870 || fixP->fx_r_type == BFD_RELOC_64
10871 || fixP->fx_r_type == BFD_RELOC_CTOR
10872 || fixP->fx_r_type == BFD_RELOC_MIPS_SUB
10873 || fixP->fx_r_type == BFD_RELOC_MIPS_HIGHEST
10874 || fixP->fx_r_type == BFD_RELOC_MIPS_HIGHER
10875 || fixP->fx_r_type == BFD_RELOC_MIPS_SCN_DISP
10876 || fixP->fx_r_type == BFD_RELOC_MIPS_REL16
10877 || fixP->fx_r_type == BFD_RELOC_MIPS_RELGOT
10878 || fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
10879 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY
10880 || fixP->fx_r_type == BFD_RELOC_MIPS_JALR);
10884 /* If we aren't adjusting this fixup to be against the section
10885 symbol, we need to adjust the value. */
10887 if (fixP->fx_addsy != NULL && OUTPUT_FLAVOR == bfd_target_elf_flavour)
10889 if (mips_need_elf_addend_fixup (fixP))
10891 valueT symval = S_GET_VALUE (fixP->fx_addsy);
10894 if (value != 0 && ! fixP->fx_pcrel)
10896 /* In this case, the bfd_install_relocation routine will
10897 incorrectly add the symbol value back in. We just want
10898 the addend to appear in the object file. */
10901 /* Make sure the addend is still non-zero. If it became zero
10902 after the last operation, set it to a spurious value and
10903 subtract the same value from the object file's contents. */
10908 /* The in-place addends for LO16 relocations are signed;
10909 leave the matching HI16 in-place addends as zero. */
10910 if (fixP->fx_r_type != BFD_RELOC_HI16_S)
10912 reloc_howto_type *howto;
10913 bfd_vma contents, mask, field;
10915 howto = bfd_reloc_type_lookup (stdoutput,
10918 contents = bfd_get_bits (fixP->fx_frag->fr_literal
10921 target_big_endian);
10923 /* MASK has bits set where the relocation should go.
10924 FIELD is -value, shifted into the appropriate place
10925 for this relocation. */
10926 mask = 1 << (howto->bitsize - 1);
10927 mask = (((mask - 1) << 1) | 1) << howto->bitpos;
10928 field = (-value >> howto->rightshift) << howto->bitpos;
10930 bfd_put_bits ((field & mask) | (contents & ~mask),
10931 fixP->fx_frag->fr_literal + fixP->fx_where,
10933 target_big_endian);
10939 /* This code was generated using trial and error and so is
10940 fragile and not trustworthy. If you change it, you should
10941 rerun the elf-rel, elf-rel2, and empic testcases and ensure
10942 they still pass. */
10943 if (fixP->fx_pcrel || fixP->fx_subsy != NULL)
10945 value += fixP->fx_frag->fr_address + fixP->fx_where;
10947 /* BFD's REL handling, for MIPS, is _very_ weird.
10948 This gives the right results, but it can't possibly
10949 be the way things are supposed to work. */
10950 if ((fixP->fx_r_type != BFD_RELOC_16_PCREL
10951 && fixP->fx_r_type != BFD_RELOC_16_PCREL_S2)
10952 || S_GET_SEGMENT (fixP->fx_addsy) != undefined_section)
10953 value += fixP->fx_frag->fr_address + fixP->fx_where;
10958 fixP->fx_addnumber = value; /* Remember value for tc_gen_reloc. */
10960 if (fixP->fx_addsy == NULL && ! fixP->fx_pcrel)
10963 switch (fixP->fx_r_type)
10965 case BFD_RELOC_MIPS_JMP:
10966 case BFD_RELOC_MIPS_SHIFT5:
10967 case BFD_RELOC_MIPS_SHIFT6:
10968 case BFD_RELOC_MIPS_GOT_DISP:
10969 case BFD_RELOC_MIPS_GOT_PAGE:
10970 case BFD_RELOC_MIPS_GOT_OFST:
10971 case BFD_RELOC_MIPS_SUB:
10972 case BFD_RELOC_MIPS_INSERT_A:
10973 case BFD_RELOC_MIPS_INSERT_B:
10974 case BFD_RELOC_MIPS_DELETE:
10975 case BFD_RELOC_MIPS_HIGHEST:
10976 case BFD_RELOC_MIPS_HIGHER:
10977 case BFD_RELOC_MIPS_SCN_DISP:
10978 case BFD_RELOC_MIPS_REL16:
10979 case BFD_RELOC_MIPS_RELGOT:
10980 case BFD_RELOC_MIPS_JALR:
10981 case BFD_RELOC_HI16:
10982 case BFD_RELOC_HI16_S:
10983 case BFD_RELOC_GPREL16:
10984 case BFD_RELOC_MIPS_LITERAL:
10985 case BFD_RELOC_MIPS_CALL16:
10986 case BFD_RELOC_MIPS_GOT16:
10987 case BFD_RELOC_GPREL32:
10988 case BFD_RELOC_MIPS_GOT_HI16:
10989 case BFD_RELOC_MIPS_GOT_LO16:
10990 case BFD_RELOC_MIPS_CALL_HI16:
10991 case BFD_RELOC_MIPS_CALL_LO16:
10992 case BFD_RELOC_MIPS16_GPREL:
10993 if (fixP->fx_pcrel)
10994 as_bad_where (fixP->fx_file, fixP->fx_line,
10995 _("Invalid PC relative reloc"));
10996 /* Nothing needed to do. The value comes from the reloc entry */
10999 case BFD_RELOC_MIPS16_JMP:
11000 /* We currently always generate a reloc against a symbol, which
11001 means that we don't want an addend even if the symbol is
11003 fixP->fx_addnumber = 0;
11006 case BFD_RELOC_PCREL_HI16_S:
11007 /* The addend for this is tricky if it is internal, so we just
11008 do everything here rather than in bfd_install_relocation. */
11009 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
11014 && (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_SECTION_SYM) == 0)
11016 /* For an external symbol adjust by the address to make it
11017 pcrel_offset. We use the address of the RELLO reloc
11018 which follows this one. */
11019 value += (fixP->fx_next->fx_frag->fr_address
11020 + fixP->fx_next->fx_where);
11022 value = ((value + 0x8000) >> 16) & 0xffff;
11023 buf = (bfd_byte *) fixP->fx_frag->fr_literal + fixP->fx_where;
11024 if (target_big_endian)
11026 md_number_to_chars ((char *) buf, value, 2);
11029 case BFD_RELOC_PCREL_LO16:
11030 /* The addend for this is tricky if it is internal, so we just
11031 do everything here rather than in bfd_install_relocation. */
11032 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
11037 && (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_SECTION_SYM) == 0)
11038 value += fixP->fx_frag->fr_address + fixP->fx_where;
11039 buf = (bfd_byte *) fixP->fx_frag->fr_literal + fixP->fx_where;
11040 if (target_big_endian)
11042 md_number_to_chars ((char *) buf, value, 2);
11046 /* This is handled like BFD_RELOC_32, but we output a sign
11047 extended value if we are only 32 bits. */
11049 || (mips_pic == EMBEDDED_PIC && SWITCH_TABLE (fixP)))
11051 if (8 <= sizeof (valueT))
11052 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
11059 w1 = w2 = fixP->fx_where;
11060 if (target_big_endian)
11064 md_number_to_chars (fixP->fx_frag->fr_literal + w1, value, 4);
11065 if ((value & 0x80000000) != 0)
11069 md_number_to_chars (fixP->fx_frag->fr_literal + w2, hiv, 4);
11074 case BFD_RELOC_RVA:
11076 /* If we are deleting this reloc entry, we must fill in the
11077 value now. This can happen if we have a .word which is not
11078 resolved when it appears but is later defined. We also need
11079 to fill in the value if this is an embedded PIC switch table
11082 || (mips_pic == EMBEDDED_PIC && SWITCH_TABLE (fixP)))
11083 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
11088 /* If we are deleting this reloc entry, we must fill in the
11090 assert (fixP->fx_size == 2);
11092 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
11096 case BFD_RELOC_LO16:
11097 /* When handling an embedded PIC switch statement, we can wind
11098 up deleting a LO16 reloc. See the 'o' case in mips_ip. */
11101 if (value + 0x8000 > 0xffff)
11102 as_bad_where (fixP->fx_file, fixP->fx_line,
11103 _("relocation overflow"));
11104 buf = (bfd_byte *) fixP->fx_frag->fr_literal + fixP->fx_where;
11105 if (target_big_endian)
11107 md_number_to_chars ((char *) buf, value, 2);
11111 case BFD_RELOC_16_PCREL_S2:
11112 if ((value & 0x3) != 0)
11113 as_bad_where (fixP->fx_file, fixP->fx_line,
11114 _("Branch to odd address (%lx)"), (long) value);
11116 /* Fall through. */
11118 case BFD_RELOC_16_PCREL:
11120 * We need to save the bits in the instruction since fixup_segment()
11121 * might be deleting the relocation entry (i.e., a branch within
11122 * the current segment).
11124 if (!fixP->fx_done && value != 0)
11126 /* If 'value' is zero, the remaining reloc code won't actually
11127 do the store, so it must be done here. This is probably
11128 a bug somewhere. */
11130 && (fixP->fx_r_type != BFD_RELOC_16_PCREL_S2
11131 || fixP->fx_addsy == NULL /* ??? */
11132 || ! S_IS_DEFINED (fixP->fx_addsy)))
11133 value -= fixP->fx_frag->fr_address + fixP->fx_where;
11135 value = (offsetT) value >> 2;
11137 /* update old instruction data */
11138 buf = (bfd_byte *) (fixP->fx_where + fixP->fx_frag->fr_literal);
11139 if (target_big_endian)
11140 insn = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
11142 insn = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
11144 if (value + 0x8000 <= 0xffff)
11145 insn |= value & 0xffff;
11148 /* The branch offset is too large. If this is an
11149 unconditional branch, and we are not generating PIC code,
11150 we can convert it to an absolute jump instruction. */
11151 if (mips_pic == NO_PIC
11153 && fixP->fx_frag->fr_address >= text_section->vma
11154 && (fixP->fx_frag->fr_address
11155 < text_section->vma + text_section->_raw_size)
11156 && ((insn & 0xffff0000) == 0x10000000 /* beq $0,$0 */
11157 || (insn & 0xffff0000) == 0x04010000 /* bgez $0 */
11158 || (insn & 0xffff0000) == 0x04110000)) /* bgezal $0 */
11160 if ((insn & 0xffff0000) == 0x04110000) /* bgezal $0 */
11161 insn = 0x0c000000; /* jal */
11163 insn = 0x08000000; /* j */
11164 fixP->fx_r_type = BFD_RELOC_MIPS_JMP;
11166 fixP->fx_addsy = section_symbol (text_section);
11167 fixP->fx_addnumber = (value << 2) + md_pcrel_from (fixP);
11171 /* FIXME. It would be possible in principle to handle
11172 conditional branches which overflow. They could be
11173 transformed into a branch around a jump. This would
11174 require setting up variant frags for each different
11175 branch type. The native MIPS assembler attempts to
11176 handle these cases, but it appears to do it
11178 as_bad_where (fixP->fx_file, fixP->fx_line,
11179 _("Branch out of range"));
11183 md_number_to_chars ((char *) buf, (valueT) insn, 4);
11186 case BFD_RELOC_VTABLE_INHERIT:
11189 && !S_IS_DEFINED (fixP->fx_addsy)
11190 && !S_IS_WEAK (fixP->fx_addsy))
11191 S_SET_WEAK (fixP->fx_addsy);
11194 case BFD_RELOC_VTABLE_ENTRY:
11208 const struct mips_opcode *p;
11209 int treg, sreg, dreg, shamt;
11214 for (i = 0; i < NUMOPCODES; ++i)
11216 p = &mips_opcodes[i];
11217 if (((oc & p->mask) == p->match) && (p->pinfo != INSN_MACRO))
11219 printf ("%08lx %s\t", oc, p->name);
11220 treg = (oc >> 16) & 0x1f;
11221 sreg = (oc >> 21) & 0x1f;
11222 dreg = (oc >> 11) & 0x1f;
11223 shamt = (oc >> 6) & 0x1f;
11225 for (args = p->args;; ++args)
11236 printf ("%c", *args);
11240 assert (treg == sreg);
11241 printf ("$%d,$%d", treg, sreg);
11246 printf ("$%d", dreg);
11251 printf ("$%d", treg);
11255 printf ("0x%x", treg);
11260 printf ("$%d", sreg);
11264 printf ("0x%08lx", oc & 0x1ffffff);
11271 printf ("%d", imm);
11276 printf ("$%d", shamt);
11287 printf (_("%08lx UNDEFINED\n"), oc);
11298 name = input_line_pointer;
11299 c = get_symbol_end ();
11300 p = (symbolS *) symbol_find_or_make (name);
11301 *input_line_pointer = c;
11305 /* Align the current frag to a given power of two. The MIPS assembler
11306 also automatically adjusts any preceding label. */
11309 mips_align (to, fill, label)
11314 mips_emit_delays (false);
11315 frag_align (to, fill, 0);
11316 record_alignment (now_seg, to);
11319 assert (S_GET_SEGMENT (label) == now_seg);
11320 symbol_set_frag (label, frag_now);
11321 S_SET_VALUE (label, (valueT) frag_now_fix ());
11325 /* Align to a given power of two. .align 0 turns off the automatic
11326 alignment used by the data creating pseudo-ops. */
11330 int x ATTRIBUTE_UNUSED;
11333 register long temp_fill;
11334 long max_alignment = 15;
11338 o Note that the assembler pulls down any immediately preceeding label
11339 to the aligned address.
11340 o It's not documented but auto alignment is reinstated by
11341 a .align pseudo instruction.
11342 o Note also that after auto alignment is turned off the mips assembler
11343 issues an error on attempt to assemble an improperly aligned data item.
11348 temp = get_absolute_expression ();
11349 if (temp > max_alignment)
11350 as_bad (_("Alignment too large: %d. assumed."), temp = max_alignment);
11353 as_warn (_("Alignment negative: 0 assumed."));
11356 if (*input_line_pointer == ',')
11358 ++input_line_pointer;
11359 temp_fill = get_absolute_expression ();
11366 mips_align (temp, (int) temp_fill,
11367 insn_labels != NULL ? insn_labels->label : NULL);
11374 demand_empty_rest_of_line ();
11378 mips_flush_pending_output ()
11380 mips_emit_delays (false);
11381 mips_clear_insn_labels ();
11390 /* When generating embedded PIC code, we only use the .text, .lit8,
11391 .sdata and .sbss sections. We change the .data and .rdata
11392 pseudo-ops to use .sdata. */
11393 if (mips_pic == EMBEDDED_PIC
11394 && (sec == 'd' || sec == 'r'))
11398 /* The ELF backend needs to know that we are changing sections, so
11399 that .previous works correctly. We could do something like check
11400 for an obj_section_change_hook macro, but that might be confusing
11401 as it would not be appropriate to use it in the section changing
11402 functions in read.c, since obj-elf.c intercepts those. FIXME:
11403 This should be cleaner, somehow. */
11404 obj_elf_section_change_hook ();
11407 mips_emit_delays (false);
11417 subseg_set (bss_section, (subsegT) get_absolute_expression ());
11418 demand_empty_rest_of_line ();
11422 if (USE_GLOBAL_POINTER_OPT)
11424 seg = subseg_new (RDATA_SECTION_NAME,
11425 (subsegT) get_absolute_expression ());
11426 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
11428 bfd_set_section_flags (stdoutput, seg,
11434 if (strcmp (TARGET_OS, "elf") != 0)
11435 record_alignment (seg, 4);
11437 demand_empty_rest_of_line ();
11441 as_bad (_("No read only data section in this object file format"));
11442 demand_empty_rest_of_line ();
11448 if (USE_GLOBAL_POINTER_OPT)
11450 seg = subseg_new (".sdata", (subsegT) get_absolute_expression ());
11451 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
11453 bfd_set_section_flags (stdoutput, seg,
11454 SEC_ALLOC | SEC_LOAD | SEC_RELOC
11456 if (strcmp (TARGET_OS, "elf") != 0)
11457 record_alignment (seg, 4);
11459 demand_empty_rest_of_line ();
11464 as_bad (_("Global pointers not supported; recompile -G 0"));
11465 demand_empty_rest_of_line ();
11474 mips_enable_auto_align ()
11485 label = insn_labels != NULL ? insn_labels->label : NULL;
11486 mips_emit_delays (false);
11487 if (log_size > 0 && auto_align)
11488 mips_align (log_size, 0, label);
11489 mips_clear_insn_labels ();
11490 cons (1 << log_size);
11494 s_float_cons (type)
11499 label = insn_labels != NULL ? insn_labels->label : NULL;
11501 mips_emit_delays (false);
11506 mips_align (3, 0, label);
11508 mips_align (2, 0, label);
11511 mips_clear_insn_labels ();
11516 /* Handle .globl. We need to override it because on Irix 5 you are
11519 where foo is an undefined symbol, to mean that foo should be
11520 considered to be the address of a function. */
11524 int x ATTRIBUTE_UNUSED;
11531 name = input_line_pointer;
11532 c = get_symbol_end ();
11533 symbolP = symbol_find_or_make (name);
11534 *input_line_pointer = c;
11535 SKIP_WHITESPACE ();
11537 /* On Irix 5, every global symbol that is not explicitly labelled as
11538 being a function is apparently labelled as being an object. */
11541 if (! is_end_of_line[(unsigned char) *input_line_pointer])
11546 secname = input_line_pointer;
11547 c = get_symbol_end ();
11548 sec = bfd_get_section_by_name (stdoutput, secname);
11550 as_bad (_("%s: no such section"), secname);
11551 *input_line_pointer = c;
11553 if (sec != NULL && (sec->flags & SEC_CODE) != 0)
11554 flag = BSF_FUNCTION;
11557 symbol_get_bfdsym (symbolP)->flags |= flag;
11559 S_SET_EXTERNAL (symbolP);
11560 demand_empty_rest_of_line ();
11565 int x ATTRIBUTE_UNUSED;
11570 opt = input_line_pointer;
11571 c = get_symbol_end ();
11575 /* FIXME: What does this mean? */
11577 else if (strncmp (opt, "pic", 3) == 0)
11581 i = atoi (opt + 3);
11585 mips_pic = SVR4_PIC;
11587 as_bad (_(".option pic%d not supported"), i);
11589 if (USE_GLOBAL_POINTER_OPT && mips_pic == SVR4_PIC)
11591 if (g_switch_seen && g_switch_value != 0)
11592 as_warn (_("-G may not be used with SVR4 PIC code"));
11593 g_switch_value = 0;
11594 bfd_set_gp_size (stdoutput, 0);
11598 as_warn (_("Unrecognized option \"%s\""), opt);
11600 *input_line_pointer = c;
11601 demand_empty_rest_of_line ();
11604 /* This structure is used to hold a stack of .set values. */
11606 struct mips_option_stack
11608 struct mips_option_stack *next;
11609 struct mips_set_options options;
11612 static struct mips_option_stack *mips_opts_stack;
11614 /* Handle the .set pseudo-op. */
11618 int x ATTRIBUTE_UNUSED;
11620 char *name = input_line_pointer, ch;
11622 while (!is_end_of_line[(unsigned char) *input_line_pointer])
11623 ++input_line_pointer;
11624 ch = *input_line_pointer;
11625 *input_line_pointer = '\0';
11627 if (strcmp (name, "reorder") == 0)
11629 if (mips_opts.noreorder && prev_nop_frag != NULL)
11631 /* If we still have pending nops, we can discard them. The
11632 usual nop handling will insert any that are still
11634 prev_nop_frag->fr_fix -= (prev_nop_frag_holds
11635 * (mips_opts.mips16 ? 2 : 4));
11636 prev_nop_frag = NULL;
11638 mips_opts.noreorder = 0;
11640 else if (strcmp (name, "noreorder") == 0)
11642 mips_emit_delays (true);
11643 mips_opts.noreorder = 1;
11644 mips_any_noreorder = 1;
11646 else if (strcmp (name, "at") == 0)
11648 mips_opts.noat = 0;
11650 else if (strcmp (name, "noat") == 0)
11652 mips_opts.noat = 1;
11654 else if (strcmp (name, "macro") == 0)
11656 mips_opts.warn_about_macros = 0;
11658 else if (strcmp (name, "nomacro") == 0)
11660 if (mips_opts.noreorder == 0)
11661 as_bad (_("`noreorder' must be set before `nomacro'"));
11662 mips_opts.warn_about_macros = 1;
11664 else if (strcmp (name, "move") == 0 || strcmp (name, "novolatile") == 0)
11666 mips_opts.nomove = 0;
11668 else if (strcmp (name, "nomove") == 0 || strcmp (name, "volatile") == 0)
11670 mips_opts.nomove = 1;
11672 else if (strcmp (name, "bopt") == 0)
11674 mips_opts.nobopt = 0;
11676 else if (strcmp (name, "nobopt") == 0)
11678 mips_opts.nobopt = 1;
11680 else if (strcmp (name, "mdmx") == 0)
11681 mips_opts.ase_mdmx = 1;
11682 else if (strcmp (name, "nomdmx") == 0)
11683 mips_opts.ase_mdmx = 0;
11684 else if (strcmp (name, "mips16") == 0
11685 || strcmp (name, "MIPS-16") == 0)
11686 mips_opts.mips16 = 1;
11687 else if (strcmp (name, "nomips16") == 0
11688 || strcmp (name, "noMIPS-16") == 0)
11689 mips_opts.mips16 = 0;
11690 else if (strcmp (name, "mips3d") == 0)
11691 mips_opts.ase_mips3d = 1;
11692 else if (strcmp (name, "nomips3d") == 0)
11693 mips_opts.ase_mips3d = 0;
11694 else if (strncmp (name, "mips", 4) == 0)
11698 /* Permit the user to change the ISA on the fly. Needless to
11699 say, misuse can cause serious problems. */
11700 isa = atoi (name + 4);
11704 mips_opts.gp32 = file_mips_gp32;
11705 mips_opts.fp32 = file_mips_fp32;
11706 mips_opts.abi = file_mips_abi;
11711 mips_opts.gp32 = 1;
11712 mips_opts.fp32 = 1;
11718 /* Loosen ABI register width restriction. */
11719 if (mips_opts.abi == O32_ABI)
11720 mips_opts.abi = NO_ABI;
11721 mips_opts.gp32 = 0;
11722 mips_opts.fp32 = 0;
11725 as_bad (_("unknown ISA level %s"), name + 4);
11731 case 0: mips_opts.isa = file_mips_isa; break;
11732 case 1: mips_opts.isa = ISA_MIPS1; break;
11733 case 2: mips_opts.isa = ISA_MIPS2; break;
11734 case 3: mips_opts.isa = ISA_MIPS3; break;
11735 case 4: mips_opts.isa = ISA_MIPS4; break;
11736 case 5: mips_opts.isa = ISA_MIPS5; break;
11737 case 32: mips_opts.isa = ISA_MIPS32; break;
11738 case 64: mips_opts.isa = ISA_MIPS64; break;
11739 default: as_bad (_("unknown ISA level %s"), name + 4); break;
11742 else if (strcmp (name, "autoextend") == 0)
11743 mips_opts.noautoextend = 0;
11744 else if (strcmp (name, "noautoextend") == 0)
11745 mips_opts.noautoextend = 1;
11746 else if (strcmp (name, "push") == 0)
11748 struct mips_option_stack *s;
11750 s = (struct mips_option_stack *) xmalloc (sizeof *s);
11751 s->next = mips_opts_stack;
11752 s->options = mips_opts;
11753 mips_opts_stack = s;
11755 else if (strcmp (name, "pop") == 0)
11757 struct mips_option_stack *s;
11759 s = mips_opts_stack;
11761 as_bad (_(".set pop with no .set push"));
11764 /* If we're changing the reorder mode we need to handle
11765 delay slots correctly. */
11766 if (s->options.noreorder && ! mips_opts.noreorder)
11767 mips_emit_delays (true);
11768 else if (! s->options.noreorder && mips_opts.noreorder)
11770 if (prev_nop_frag != NULL)
11772 prev_nop_frag->fr_fix -= (prev_nop_frag_holds
11773 * (mips_opts.mips16 ? 2 : 4));
11774 prev_nop_frag = NULL;
11778 mips_opts = s->options;
11779 mips_opts_stack = s->next;
11785 as_warn (_("Tried to set unrecognized symbol: %s\n"), name);
11787 *input_line_pointer = ch;
11788 demand_empty_rest_of_line ();
11791 /* Handle the .abicalls pseudo-op. I believe this is equivalent to
11792 .option pic2. It means to generate SVR4 PIC calls. */
11795 s_abicalls (ignore)
11796 int ignore ATTRIBUTE_UNUSED;
11798 mips_pic = SVR4_PIC;
11799 if (USE_GLOBAL_POINTER_OPT)
11801 if (g_switch_seen && g_switch_value != 0)
11802 as_warn (_("-G may not be used with SVR4 PIC code"));
11803 g_switch_value = 0;
11805 bfd_set_gp_size (stdoutput, 0);
11806 demand_empty_rest_of_line ();
11809 /* Handle the .cpload pseudo-op. This is used when generating SVR4
11810 PIC code. It sets the $gp register for the function based on the
11811 function address, which is in the register named in the argument.
11812 This uses a relocation against _gp_disp, which is handled specially
11813 by the linker. The result is:
11814 lui $gp,%hi(_gp_disp)
11815 addiu $gp,$gp,%lo(_gp_disp)
11816 addu $gp,$gp,.cpload argument
11817 The .cpload argument is normally $25 == $t9. */
11821 int ignore ATTRIBUTE_UNUSED;
11826 /* If we are not generating SVR4 PIC code, or if this is NewABI code,
11827 .cpload is ignored. */
11828 if (mips_pic != SVR4_PIC || HAVE_NEWABI)
11834 /* .cpload should be in a .set noreorder section. */
11835 if (mips_opts.noreorder == 0)
11836 as_warn (_(".cpload not in noreorder section"));
11838 ex.X_op = O_symbol;
11839 ex.X_add_symbol = symbol_find_or_make ("_gp_disp");
11840 ex.X_op_symbol = NULL;
11841 ex.X_add_number = 0;
11843 /* In ELF, this symbol is implicitly an STT_OBJECT symbol. */
11844 symbol_get_bfdsym (ex.X_add_symbol)->flags |= BSF_OBJECT;
11846 macro_build_lui (NULL, &icnt, &ex, mips_gp_register);
11847 macro_build ((char *) NULL, &icnt, &ex, "addiu", "t,r,j",
11848 mips_gp_register, mips_gp_register, (int) BFD_RELOC_LO16);
11850 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "addu", "d,v,t",
11851 mips_gp_register, mips_gp_register, tc_get_register (0));
11853 demand_empty_rest_of_line ();
11856 /* Handle the .cpsetup pseudo-op defined for NewABI PIC code. The syntax is:
11857 .cpsetup $reg1, offset|$reg2, label
11859 If offset is given, this results in:
11860 sd $gp, offset($sp)
11861 lui $gp, %hi(%neg(%gp_rel(label)))
11862 addiu $gp, $gp, %lo(%neg(%gp_rel(label)))
11863 daddu $gp, $gp, $reg1
11865 If $reg2 is given, this results in:
11866 daddu $reg2, $gp, $0
11867 lui $gp, %hi(%neg(%gp_rel(label)))
11868 addiu $gp, $gp, %lo(%neg(%gp_rel(label)))
11869 daddu $gp, $gp, $reg1
11870 $reg1 is normally $25 == $t9. */
11873 int ignore ATTRIBUTE_UNUSED;
11875 expressionS ex_off;
11876 expressionS ex_sym;
11881 /* If we are not generating SVR4 PIC code, .cpsetup is ignored.
11882 We also need NewABI support. */
11883 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
11889 reg1 = tc_get_register (0);
11890 SKIP_WHITESPACE ();
11891 if (*input_line_pointer != ',')
11893 as_bad (_("missing argument separator ',' for .cpsetup"));
11897 ++input_line_pointer;
11898 SKIP_WHITESPACE ();
11899 if (*input_line_pointer == '$')
11901 mips_cpreturn_register = tc_get_register (0);
11902 mips_cpreturn_offset = -1;
11906 mips_cpreturn_offset = get_absolute_expression ();
11907 mips_cpreturn_register = -1;
11909 SKIP_WHITESPACE ();
11910 if (*input_line_pointer != ',')
11912 as_bad (_("missing argument separator ',' for .cpsetup"));
11916 ++input_line_pointer;
11917 SKIP_WHITESPACE ();
11918 sym = input_line_pointer;
11919 while (ISALNUM (*input_line_pointer))
11920 ++input_line_pointer;
11921 *input_line_pointer = 0;
11923 ex_sym.X_op = O_symbol;
11924 ex_sym.X_add_symbol = symbol_find_or_make (sym);
11925 ex_sym.X_op_symbol = NULL;
11926 ex_sym.X_add_number = 0;
11928 if (mips_cpreturn_register == -1)
11930 ex_off.X_op = O_constant;
11931 ex_off.X_add_symbol = NULL;
11932 ex_off.X_op_symbol = NULL;
11933 ex_off.X_add_number = mips_cpreturn_offset;
11935 macro_build ((char *) NULL, &icnt, &ex_off, "sd", "t,o(b)",
11936 mips_gp_register, (int) BFD_RELOC_LO16, SP);
11939 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "daddu",
11940 "d,v,t", mips_cpreturn_register, mips_gp_register, 0);
11942 macro_build ((char *) NULL, &icnt, &ex_sym, "lui", "t,u", mips_gp_register,
11943 (int) BFD_RELOC_GPREL16);
11944 fix_new (frag_now, prev_insn_where, 0, NULL, 0, 0, BFD_RELOC_MIPS_SUB);
11945 fix_new (frag_now, prev_insn_where, 0, NULL, 0, 0, BFD_RELOC_HI16_S);
11946 macro_build ((char *) NULL, &icnt, &ex_sym, "addiu", "t,r,j",
11947 mips_gp_register, mips_gp_register, (int) BFD_RELOC_GPREL16);
11948 fix_new (frag_now, prev_insn_where, 0, NULL, 0, 0, BFD_RELOC_MIPS_SUB);
11949 fix_new (frag_now, prev_insn_where, 0, NULL, 0, 0, BFD_RELOC_LO16);
11950 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
11951 HAVE_64BIT_ADDRESSES ? "daddu" : "addu", "d,v,t",
11952 mips_gp_register, mips_gp_register, reg1);
11954 demand_empty_rest_of_line ();
11959 int ignore ATTRIBUTE_UNUSED;
11961 /* If we are not generating SVR4 PIC code, or if this is not NewABI code,
11962 .cplocal is ignored. */
11963 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
11969 mips_gp_register = tc_get_register (0);
11970 demand_empty_rest_of_line ();
11973 /* Handle the .cprestore pseudo-op. This stores $gp into a given
11974 offset from $sp. The offset is remembered, and after making a PIC
11975 call $gp is restored from that location. */
11978 s_cprestore (ignore)
11979 int ignore ATTRIBUTE_UNUSED;
11984 /* If we are not generating SVR4 PIC code, or if this is NewABI code,
11985 .cprestore is ignored. */
11986 if (mips_pic != SVR4_PIC || HAVE_NEWABI)
11992 mips_cprestore_offset = get_absolute_expression ();
11993 mips_cprestore_valid = 1;
11995 ex.X_op = O_constant;
11996 ex.X_add_symbol = NULL;
11997 ex.X_op_symbol = NULL;
11998 ex.X_add_number = mips_cprestore_offset;
12000 macro_build ((char *) NULL, &icnt, &ex, HAVE_32BIT_ADDRESSES ? "sw" : "sd",
12001 "t,o(b)", mips_gp_register, (int) BFD_RELOC_LO16, SP);
12003 demand_empty_rest_of_line ();
12006 /* Handle the .cpreturn pseudo-op defined for NewABI PIC code. If an offset
12007 was given in the preceeding .gpsetup, it results in:
12008 ld $gp, offset($sp)
12010 If a register $reg2 was given there, it results in:
12011 daddiu $gp, $gp, $reg2
12014 s_cpreturn (ignore)
12015 int ignore ATTRIBUTE_UNUSED;
12020 /* If we are not generating SVR4 PIC code, .cpreturn is ignored.
12021 We also need NewABI support. */
12022 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
12028 if (mips_cpreturn_register == -1)
12030 ex.X_op = O_constant;
12031 ex.X_add_symbol = NULL;
12032 ex.X_op_symbol = NULL;
12033 ex.X_add_number = mips_cpreturn_offset;
12035 macro_build ((char *) NULL, &icnt, &ex, "ld", "t,o(b)",
12036 mips_gp_register, (int) BFD_RELOC_LO16, SP);
12039 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "daddu",
12040 "d,v,t", mips_gp_register, mips_cpreturn_register, 0);
12042 demand_empty_rest_of_line ();
12045 /* Handle the .gpvalue pseudo-op. This is used when generating NewABI PIC
12046 code. It sets the offset to use in gp_rel relocations. */
12050 int ignore ATTRIBUTE_UNUSED;
12052 /* If we are not generating SVR4 PIC code, .gpvalue is ignored.
12053 We also need NewABI support. */
12054 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
12060 mips_gprel_offset = get_absolute_expression ();
12062 demand_empty_rest_of_line ();
12065 /* Handle the .gpword pseudo-op. This is used when generating PIC
12066 code. It generates a 32 bit GP relative reloc. */
12070 int ignore ATTRIBUTE_UNUSED;
12076 /* When not generating PIC code, this is treated as .word. */
12077 if (mips_pic != SVR4_PIC)
12083 label = insn_labels != NULL ? insn_labels->label : NULL;
12084 mips_emit_delays (true);
12086 mips_align (2, 0, label);
12087 mips_clear_insn_labels ();
12091 if (ex.X_op != O_symbol || ex.X_add_number != 0)
12093 as_bad (_("Unsupported use of .gpword"));
12094 ignore_rest_of_line ();
12098 md_number_to_chars (p, (valueT) 0, 4);
12099 fix_new_exp (frag_now, p - frag_now->fr_literal, 4, &ex, false,
12100 BFD_RELOC_GPREL32);
12102 demand_empty_rest_of_line ();
12105 /* Handle the .cpadd pseudo-op. This is used when dealing with switch
12106 tables in SVR4 PIC code. */
12110 int ignore ATTRIBUTE_UNUSED;
12115 /* This is ignored when not generating SVR4 PIC code or if this is NewABI
12117 if (mips_pic != SVR4_PIC || HAVE_NEWABI)
12123 /* Add $gp to the register named as an argument. */
12124 reg = tc_get_register (0);
12125 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
12126 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
12127 "d,v,t", reg, reg, mips_gp_register);
12129 demand_empty_rest_of_line ();
12132 /* Handle the .insn pseudo-op. This marks instruction labels in
12133 mips16 mode. This permits the linker to handle them specially,
12134 such as generating jalx instructions when needed. We also make
12135 them odd for the duration of the assembly, in order to generate the
12136 right sort of code. We will make them even in the adjust_symtab
12137 routine, while leaving them marked. This is convenient for the
12138 debugger and the disassembler. The linker knows to make them odd
12143 int ignore ATTRIBUTE_UNUSED;
12145 mips16_mark_labels ();
12147 demand_empty_rest_of_line ();
12150 /* Handle a .stabn directive. We need these in order to mark a label
12151 as being a mips16 text label correctly. Sometimes the compiler
12152 will emit a label, followed by a .stabn, and then switch sections.
12153 If the label and .stabn are in mips16 mode, then the label is
12154 really a mips16 text label. */
12161 mips16_mark_labels ();
12166 /* Handle the .weakext pseudo-op as defined in Kane and Heinrich.
12170 s_mips_weakext (ignore)
12171 int ignore ATTRIBUTE_UNUSED;
12178 name = input_line_pointer;
12179 c = get_symbol_end ();
12180 symbolP = symbol_find_or_make (name);
12181 S_SET_WEAK (symbolP);
12182 *input_line_pointer = c;
12184 SKIP_WHITESPACE ();
12186 if (! is_end_of_line[(unsigned char) *input_line_pointer])
12188 if (S_IS_DEFINED (symbolP))
12190 as_bad ("ignoring attempt to redefine symbol %s",
12191 S_GET_NAME (symbolP));
12192 ignore_rest_of_line ();
12196 if (*input_line_pointer == ',')
12198 ++input_line_pointer;
12199 SKIP_WHITESPACE ();
12203 if (exp.X_op != O_symbol)
12205 as_bad ("bad .weakext directive");
12206 ignore_rest_of_line ();
12209 symbol_set_value_expression (symbolP, &exp);
12212 demand_empty_rest_of_line ();
12215 /* Parse a register string into a number. Called from the ECOFF code
12216 to parse .frame. The argument is non-zero if this is the frame
12217 register, so that we can record it in mips_frame_reg. */
12220 tc_get_register (frame)
12225 SKIP_WHITESPACE ();
12226 if (*input_line_pointer++ != '$')
12228 as_warn (_("expected `$'"));
12231 else if (ISDIGIT (*input_line_pointer))
12233 reg = get_absolute_expression ();
12234 if (reg < 0 || reg >= 32)
12236 as_warn (_("Bad register number"));
12242 if (strncmp (input_line_pointer, "ra", 2) == 0)
12245 input_line_pointer += 2;
12247 else if (strncmp (input_line_pointer, "fp", 2) == 0)
12250 input_line_pointer += 2;
12252 else if (strncmp (input_line_pointer, "sp", 2) == 0)
12255 input_line_pointer += 2;
12257 else if (strncmp (input_line_pointer, "gp", 2) == 0)
12260 input_line_pointer += 2;
12262 else if (strncmp (input_line_pointer, "at", 2) == 0)
12265 input_line_pointer += 2;
12267 else if (strncmp (input_line_pointer, "kt0", 3) == 0)
12270 input_line_pointer += 3;
12272 else if (strncmp (input_line_pointer, "kt1", 3) == 0)
12275 input_line_pointer += 3;
12277 else if (strncmp (input_line_pointer, "zero", 4) == 0)
12280 input_line_pointer += 4;
12284 as_warn (_("Unrecognized register name"));
12286 while (ISALNUM(*input_line_pointer))
12287 input_line_pointer++;
12292 mips_frame_reg = reg != 0 ? reg : SP;
12293 mips_frame_reg_valid = 1;
12294 mips_cprestore_valid = 0;
12300 md_section_align (seg, addr)
12304 int align = bfd_get_section_alignment (stdoutput, seg);
12307 /* We don't need to align ELF sections to the full alignment.
12308 However, Irix 5 may prefer that we align them at least to a 16
12309 byte boundary. We don't bother to align the sections if we are
12310 targeted for an embedded system. */
12311 if (strcmp (TARGET_OS, "elf") == 0)
12317 return ((addr + (1 << align) - 1) & (-1 << align));
12320 /* Utility routine, called from above as well. If called while the
12321 input file is still being read, it's only an approximation. (For
12322 example, a symbol may later become defined which appeared to be
12323 undefined earlier.) */
12326 nopic_need_relax (sym, before_relaxing)
12328 int before_relaxing;
12333 if (USE_GLOBAL_POINTER_OPT && g_switch_value > 0)
12335 const char *symname;
12338 /* Find out whether this symbol can be referenced off the $gp
12339 register. It can be if it is smaller than the -G size or if
12340 it is in the .sdata or .sbss section. Certain symbols can
12341 not be referenced off the $gp, although it appears as though
12343 symname = S_GET_NAME (sym);
12344 if (symname != (const char *) NULL
12345 && (strcmp (symname, "eprol") == 0
12346 || strcmp (symname, "etext") == 0
12347 || strcmp (symname, "_gp") == 0
12348 || strcmp (symname, "edata") == 0
12349 || strcmp (symname, "_fbss") == 0
12350 || strcmp (symname, "_fdata") == 0
12351 || strcmp (symname, "_ftext") == 0
12352 || strcmp (symname, "end") == 0
12353 || strcmp (symname, "_gp_disp") == 0))
12355 else if ((! S_IS_DEFINED (sym) || S_IS_COMMON (sym))
12357 #ifndef NO_ECOFF_DEBUGGING
12358 || (symbol_get_obj (sym)->ecoff_extern_size != 0
12359 && (symbol_get_obj (sym)->ecoff_extern_size
12360 <= g_switch_value))
12362 /* We must defer this decision until after the whole
12363 file has been read, since there might be a .extern
12364 after the first use of this symbol. */
12365 || (before_relaxing
12366 #ifndef NO_ECOFF_DEBUGGING
12367 && symbol_get_obj (sym)->ecoff_extern_size == 0
12369 && S_GET_VALUE (sym) == 0)
12370 || (S_GET_VALUE (sym) != 0
12371 && S_GET_VALUE (sym) <= g_switch_value)))
12375 const char *segname;
12377 segname = segment_name (S_GET_SEGMENT (sym));
12378 assert (strcmp (segname, ".lit8") != 0
12379 && strcmp (segname, ".lit4") != 0);
12380 change = (strcmp (segname, ".sdata") != 0
12381 && strcmp (segname, ".sbss") != 0
12382 && strncmp (segname, ".sdata.", 7) != 0
12383 && strncmp (segname, ".gnu.linkonce.s.", 16) != 0);
12388 /* We are not optimizing for the $gp register. */
12392 /* Given a mips16 variant frag FRAGP, return non-zero if it needs an
12393 extended opcode. SEC is the section the frag is in. */
12396 mips16_extended_frag (fragp, sec, stretch)
12402 register const struct mips16_immed_operand *op;
12404 int mintiny, maxtiny;
12408 if (RELAX_MIPS16_USER_SMALL (fragp->fr_subtype))
12410 if (RELAX_MIPS16_USER_EXT (fragp->fr_subtype))
12413 type = RELAX_MIPS16_TYPE (fragp->fr_subtype);
12414 op = mips16_immed_operands;
12415 while (op->type != type)
12418 assert (op < mips16_immed_operands + MIPS16_NUM_IMMED);
12423 if (type == '<' || type == '>' || type == '[' || type == ']')
12426 maxtiny = 1 << op->nbits;
12431 maxtiny = (1 << op->nbits) - 1;
12436 mintiny = - (1 << (op->nbits - 1));
12437 maxtiny = (1 << (op->nbits - 1)) - 1;
12440 sym_frag = symbol_get_frag (fragp->fr_symbol);
12441 val = S_GET_VALUE (fragp->fr_symbol);
12442 symsec = S_GET_SEGMENT (fragp->fr_symbol);
12448 /* We won't have the section when we are called from
12449 mips_relax_frag. However, we will always have been called
12450 from md_estimate_size_before_relax first. If this is a
12451 branch to a different section, we mark it as such. If SEC is
12452 NULL, and the frag is not marked, then it must be a branch to
12453 the same section. */
12456 if (RELAX_MIPS16_LONG_BRANCH (fragp->fr_subtype))
12461 /* Must have been called from md_estimate_size_before_relax. */
12464 fragp->fr_subtype =
12465 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
12467 /* FIXME: We should support this, and let the linker
12468 catch branches and loads that are out of range. */
12469 as_bad_where (fragp->fr_file, fragp->fr_line,
12470 _("unsupported PC relative reference to different section"));
12474 if (fragp != sym_frag && sym_frag->fr_address == 0)
12475 /* Assume non-extended on the first relaxation pass.
12476 The address we have calculated will be bogus if this is
12477 a forward branch to another frag, as the forward frag
12478 will have fr_address == 0. */
12482 /* In this case, we know for sure that the symbol fragment is in
12483 the same section. If the relax_marker of the symbol fragment
12484 differs from the relax_marker of this fragment, we have not
12485 yet adjusted the symbol fragment fr_address. We want to add
12486 in STRETCH in order to get a better estimate of the address.
12487 This particularly matters because of the shift bits. */
12489 && sym_frag->relax_marker != fragp->relax_marker)
12493 /* Adjust stretch for any alignment frag. Note that if have
12494 been expanding the earlier code, the symbol may be
12495 defined in what appears to be an earlier frag. FIXME:
12496 This doesn't handle the fr_subtype field, which specifies
12497 a maximum number of bytes to skip when doing an
12499 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
12501 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
12504 stretch = - ((- stretch)
12505 & ~ ((1 << (int) f->fr_offset) - 1));
12507 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
12516 addr = fragp->fr_address + fragp->fr_fix;
12518 /* The base address rules are complicated. The base address of
12519 a branch is the following instruction. The base address of a
12520 PC relative load or add is the instruction itself, but if it
12521 is in a delay slot (in which case it can not be extended) use
12522 the address of the instruction whose delay slot it is in. */
12523 if (type == 'p' || type == 'q')
12527 /* If we are currently assuming that this frag should be
12528 extended, then, the current address is two bytes
12530 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
12533 /* Ignore the low bit in the target, since it will be set
12534 for a text label. */
12535 if ((val & 1) != 0)
12538 else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype))
12540 else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype))
12543 val -= addr & ~ ((1 << op->shift) - 1);
12545 /* Branch offsets have an implicit 0 in the lowest bit. */
12546 if (type == 'p' || type == 'q')
12549 /* If any of the shifted bits are set, we must use an extended
12550 opcode. If the address depends on the size of this
12551 instruction, this can lead to a loop, so we arrange to always
12552 use an extended opcode. We only check this when we are in
12553 the main relaxation loop, when SEC is NULL. */
12554 if ((val & ((1 << op->shift) - 1)) != 0 && sec == NULL)
12556 fragp->fr_subtype =
12557 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
12561 /* If we are about to mark a frag as extended because the value
12562 is precisely maxtiny + 1, then there is a chance of an
12563 infinite loop as in the following code:
12568 In this case when the la is extended, foo is 0x3fc bytes
12569 away, so the la can be shrunk, but then foo is 0x400 away, so
12570 the la must be extended. To avoid this loop, we mark the
12571 frag as extended if it was small, and is about to become
12572 extended with a value of maxtiny + 1. */
12573 if (val == ((maxtiny + 1) << op->shift)
12574 && ! RELAX_MIPS16_EXTENDED (fragp->fr_subtype)
12577 fragp->fr_subtype =
12578 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
12582 else if (symsec != absolute_section && sec != NULL)
12583 as_bad_where (fragp->fr_file, fragp->fr_line, _("unsupported relocation"));
12585 if ((val & ((1 << op->shift) - 1)) != 0
12586 || val < (mintiny << op->shift)
12587 || val > (maxtiny << op->shift))
12593 /* Estimate the size of a frag before relaxing. Unless this is the
12594 mips16, we are not really relaxing here, and the final size is
12595 encoded in the subtype information. For the mips16, we have to
12596 decide whether we are using an extended opcode or not. */
12599 md_estimate_size_before_relax (fragp, segtype)
12604 boolean linkonce = false;
12606 if (RELAX_MIPS16_P (fragp->fr_subtype))
12607 /* We don't want to modify the EXTENDED bit here; it might get us
12608 into infinite loops. We change it only in mips_relax_frag(). */
12609 return (RELAX_MIPS16_EXTENDED (fragp->fr_subtype) ? 4 : 2);
12611 if (mips_pic == NO_PIC)
12613 change = nopic_need_relax (fragp->fr_symbol, 0);
12615 else if (mips_pic == SVR4_PIC)
12620 sym = fragp->fr_symbol;
12622 /* Handle the case of a symbol equated to another symbol. */
12623 while (symbol_equated_reloc_p (sym))
12627 /* It's possible to get a loop here in a badly written
12629 n = symbol_get_value_expression (sym)->X_add_symbol;
12635 symsec = S_GET_SEGMENT (sym);
12637 /* duplicate the test for LINK_ONCE sections as in adjust_reloc_syms */
12638 if (symsec != segtype && ! S_IS_LOCAL (sym))
12640 if ((bfd_get_section_flags (stdoutput, symsec) & SEC_LINK_ONCE)
12644 /* The GNU toolchain uses an extension for ELF: a section
12645 beginning with the magic string .gnu.linkonce is a linkonce
12647 if (strncmp (segment_name (symsec), ".gnu.linkonce",
12648 sizeof ".gnu.linkonce" - 1) == 0)
12652 /* This must duplicate the test in adjust_reloc_syms. */
12653 change = (symsec != &bfd_und_section
12654 && symsec != &bfd_abs_section
12655 && ! bfd_is_com_section (symsec)
12658 /* A global or weak symbol is treated as external. */
12659 && (OUTPUT_FLAVOR != bfd_target_elf_flavour
12660 || (! S_IS_WEAK (sym)
12661 && (! S_IS_EXTERN (sym) || mips_pic == EMBEDDED_PIC)))
12670 /* Record the offset to the first reloc in the fr_opcode field.
12671 This lets md_convert_frag and tc_gen_reloc know that the code
12672 must be expanded. */
12673 fragp->fr_opcode = (fragp->fr_literal
12675 - RELAX_OLD (fragp->fr_subtype)
12676 + RELAX_RELOC1 (fragp->fr_subtype));
12677 /* FIXME: This really needs as_warn_where. */
12678 if (RELAX_WARN (fragp->fr_subtype))
12679 as_warn (_("AT used after \".set noat\" or macro used after "
12680 "\".set nomacro\""));
12682 return RELAX_NEW (fragp->fr_subtype) - RELAX_OLD (fragp->fr_subtype);
12688 /* This is called to see whether a reloc against a defined symbol
12689 should be converted into a reloc against a section. Don't adjust
12690 MIPS16 jump relocations, so we don't have to worry about the format
12691 of the offset in the .o file. Don't adjust relocations against
12692 mips16 symbols, so that the linker can find them if it needs to set
12696 mips_fix_adjustable (fixp)
12700 /* Prevent all adjustments to global symbols. */
12701 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
12702 && mips_pic != EMBEDDED_PIC
12703 && (S_IS_EXTERN (fixp->fx_addsy) || S_IS_WEAK (fixp->fx_addsy)))
12706 if (fixp->fx_r_type == BFD_RELOC_MIPS16_JMP)
12708 if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT
12709 || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
12711 if (fixp->fx_addsy == NULL)
12714 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
12715 && S_GET_OTHER (fixp->fx_addsy) == STO_MIPS16
12716 && fixp->fx_subsy == NULL)
12722 /* Translate internal representation of relocation info to BFD target
12726 tc_gen_reloc (section, fixp)
12727 asection *section ATTRIBUTE_UNUSED;
12730 static arelent *retval[4];
12732 bfd_reloc_code_real_type code;
12734 reloc = retval[0] = (arelent *) xmalloc (sizeof (arelent));
12737 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
12738 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
12739 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
12741 if (mips_pic == EMBEDDED_PIC
12742 && SWITCH_TABLE (fixp))
12744 /* For a switch table entry we use a special reloc. The addend
12745 is actually the difference between the reloc address and the
12747 reloc->addend = reloc->address - S_GET_VALUE (fixp->fx_subsy);
12748 if (OUTPUT_FLAVOR != bfd_target_ecoff_flavour)
12749 as_fatal (_("Double check fx_r_type in tc-mips.c:tc_gen_reloc"));
12750 fixp->fx_r_type = BFD_RELOC_GPREL32;
12752 else if (fixp->fx_r_type == BFD_RELOC_PCREL_LO16)
12754 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
12755 reloc->addend = fixp->fx_addnumber;
12758 /* We use a special addend for an internal RELLO reloc. */
12759 if (symbol_section_p (fixp->fx_addsy))
12760 reloc->addend = reloc->address - S_GET_VALUE (fixp->fx_subsy);
12762 reloc->addend = fixp->fx_addnumber + reloc->address;
12765 else if (fixp->fx_r_type == BFD_RELOC_PCREL_HI16_S)
12767 assert (fixp->fx_next != NULL
12768 && fixp->fx_next->fx_r_type == BFD_RELOC_PCREL_LO16);
12770 /* The reloc is relative to the RELLO; adjust the addend
12772 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
12773 reloc->addend = fixp->fx_next->fx_addnumber;
12776 /* We use a special addend for an internal RELHI reloc. */
12777 if (symbol_section_p (fixp->fx_addsy))
12778 reloc->addend = (fixp->fx_next->fx_frag->fr_address
12779 + fixp->fx_next->fx_where
12780 - S_GET_VALUE (fixp->fx_subsy));
12782 reloc->addend = (fixp->fx_addnumber
12783 + fixp->fx_next->fx_frag->fr_address
12784 + fixp->fx_next->fx_where);
12787 else if (fixp->fx_pcrel == 0 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
12788 reloc->addend = fixp->fx_addnumber;
12791 if (OUTPUT_FLAVOR != bfd_target_aout_flavour)
12792 /* A gruesome hack which is a result of the gruesome gas reloc
12794 reloc->addend = reloc->address;
12796 reloc->addend = -reloc->address;
12799 /* If this is a variant frag, we may need to adjust the existing
12800 reloc and generate a new one. */
12801 if (fixp->fx_frag->fr_opcode != NULL
12802 && (fixp->fx_r_type == BFD_RELOC_GPREL16
12803 || fixp->fx_r_type == BFD_RELOC_MIPS_GOT16
12804 || fixp->fx_r_type == BFD_RELOC_MIPS_CALL16
12805 || fixp->fx_r_type == BFD_RELOC_MIPS_GOT_HI16
12806 || fixp->fx_r_type == BFD_RELOC_MIPS_GOT_LO16
12807 || fixp->fx_r_type == BFD_RELOC_MIPS_CALL_HI16
12808 || fixp->fx_r_type == BFD_RELOC_MIPS_CALL_LO16)
12813 assert (! RELAX_MIPS16_P (fixp->fx_frag->fr_subtype));
12815 /* If this is not the last reloc in this frag, then we have two
12816 GPREL relocs, or a GOT_HI16/GOT_LO16 pair, or a
12817 CALL_HI16/CALL_LO16, both of which are being replaced. Let
12818 the second one handle all of them. */
12819 if (fixp->fx_next != NULL
12820 && fixp->fx_frag == fixp->fx_next->fx_frag)
12822 assert ((fixp->fx_r_type == BFD_RELOC_GPREL16
12823 && fixp->fx_next->fx_r_type == BFD_RELOC_GPREL16)
12824 || (fixp->fx_r_type == BFD_RELOC_MIPS_GOT_HI16
12825 && (fixp->fx_next->fx_r_type
12826 == BFD_RELOC_MIPS_GOT_LO16))
12827 || (fixp->fx_r_type == BFD_RELOC_MIPS_CALL_HI16
12828 && (fixp->fx_next->fx_r_type
12829 == BFD_RELOC_MIPS_CALL_LO16)));
12834 fixp->fx_where = fixp->fx_frag->fr_opcode - fixp->fx_frag->fr_literal;
12835 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
12836 reloc2 = retval[1] = (arelent *) xmalloc (sizeof (arelent));
12838 reloc2->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
12839 *reloc2->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
12840 reloc2->address = (reloc->address
12841 + (RELAX_RELOC2 (fixp->fx_frag->fr_subtype)
12842 - RELAX_RELOC1 (fixp->fx_frag->fr_subtype)));
12843 reloc2->addend = fixp->fx_addnumber;
12844 reloc2->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_LO16);
12845 assert (reloc2->howto != NULL);
12847 if (RELAX_RELOC3 (fixp->fx_frag->fr_subtype))
12851 reloc3 = retval[2] = (arelent *) xmalloc (sizeof (arelent));
12854 reloc3->address += 4;
12857 if (mips_pic == NO_PIC)
12859 assert (fixp->fx_r_type == BFD_RELOC_GPREL16);
12860 fixp->fx_r_type = BFD_RELOC_HI16_S;
12862 else if (mips_pic == SVR4_PIC)
12864 switch (fixp->fx_r_type)
12868 case BFD_RELOC_MIPS_GOT16:
12870 case BFD_RELOC_MIPS_CALL16:
12871 case BFD_RELOC_MIPS_GOT_LO16:
12872 case BFD_RELOC_MIPS_CALL_LO16:
12873 fixp->fx_r_type = BFD_RELOC_MIPS_GOT16;
12881 /* Since the old MIPS ELF ABI uses Rel instead of Rela, encode the vtable
12882 entry to be used in the relocation's section offset. */
12883 if (! HAVE_NEWABI && fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
12885 reloc->address = reloc->addend;
12889 /* Since DIFF_EXPR_OK is defined in tc-mips.h, it is possible that
12890 fixup_segment converted a non-PC relative reloc into a PC
12891 relative reloc. In such a case, we need to convert the reloc
12893 code = fixp->fx_r_type;
12894 if (fixp->fx_pcrel)
12899 code = BFD_RELOC_8_PCREL;
12902 code = BFD_RELOC_16_PCREL;
12905 code = BFD_RELOC_32_PCREL;
12908 code = BFD_RELOC_64_PCREL;
12910 case BFD_RELOC_8_PCREL:
12911 case BFD_RELOC_16_PCREL:
12912 case BFD_RELOC_32_PCREL:
12913 case BFD_RELOC_64_PCREL:
12914 case BFD_RELOC_16_PCREL_S2:
12915 case BFD_RELOC_PCREL_HI16_S:
12916 case BFD_RELOC_PCREL_LO16:
12919 as_bad_where (fixp->fx_file, fixp->fx_line,
12920 _("Cannot make %s relocation PC relative"),
12921 bfd_get_reloc_code_name (code));
12926 /* md_apply_fix3 has a double-subtraction hack to get
12927 bfd_install_relocation to behave nicely. GPREL relocations are
12928 handled correctly without this hack, so undo it here. We can't
12929 stop md_apply_fix3 from subtracting twice in the first place since
12930 the fake addend is required for variant frags above. */
12931 if (fixp->fx_addsy != NULL && OUTPUT_FLAVOR == bfd_target_elf_flavour
12932 && code == BFD_RELOC_GPREL16
12933 && reloc->addend != 0
12934 && mips_need_elf_addend_fixup (fixp))
12935 reloc->addend += S_GET_VALUE (fixp->fx_addsy);
12938 /* To support a PC relative reloc when generating embedded PIC code
12939 for ECOFF, we use a Cygnus extension. We check for that here to
12940 make sure that we don't let such a reloc escape normally. */
12941 if ((OUTPUT_FLAVOR == bfd_target_ecoff_flavour
12942 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
12943 && code == BFD_RELOC_16_PCREL_S2
12944 && mips_pic != EMBEDDED_PIC)
12945 reloc->howto = NULL;
12947 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
12949 if (reloc->howto == NULL)
12951 as_bad_where (fixp->fx_file, fixp->fx_line,
12952 _("Can not represent %s relocation in this object file format"),
12953 bfd_get_reloc_code_name (code));
12960 /* Relax a machine dependent frag. This returns the amount by which
12961 the current size of the frag should change. */
12964 mips_relax_frag (fragp, stretch)
12968 if (! RELAX_MIPS16_P (fragp->fr_subtype))
12971 if (mips16_extended_frag (fragp, NULL, stretch))
12973 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
12975 fragp->fr_subtype = RELAX_MIPS16_MARK_EXTENDED (fragp->fr_subtype);
12980 if (! RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
12982 fragp->fr_subtype = RELAX_MIPS16_CLEAR_EXTENDED (fragp->fr_subtype);
12989 /* Convert a machine dependent frag. */
12992 md_convert_frag (abfd, asec, fragp)
12993 bfd *abfd ATTRIBUTE_UNUSED;
13000 if (RELAX_MIPS16_P (fragp->fr_subtype))
13003 register const struct mips16_immed_operand *op;
13004 boolean small, ext;
13007 unsigned long insn;
13008 boolean use_extend;
13009 unsigned short extend;
13011 type = RELAX_MIPS16_TYPE (fragp->fr_subtype);
13012 op = mips16_immed_operands;
13013 while (op->type != type)
13016 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
13027 resolve_symbol_value (fragp->fr_symbol);
13028 val = S_GET_VALUE (fragp->fr_symbol);
13033 addr = fragp->fr_address + fragp->fr_fix;
13035 /* The rules for the base address of a PC relative reloc are
13036 complicated; see mips16_extended_frag. */
13037 if (type == 'p' || type == 'q')
13042 /* Ignore the low bit in the target, since it will be
13043 set for a text label. */
13044 if ((val & 1) != 0)
13047 else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype))
13049 else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype))
13052 addr &= ~ (addressT) ((1 << op->shift) - 1);
13055 /* Make sure the section winds up with the alignment we have
13058 record_alignment (asec, op->shift);
13062 && (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype)
13063 || RELAX_MIPS16_DSLOT (fragp->fr_subtype)))
13064 as_warn_where (fragp->fr_file, fragp->fr_line,
13065 _("extended instruction in delay slot"));
13067 buf = (bfd_byte *) (fragp->fr_literal + fragp->fr_fix);
13069 if (target_big_endian)
13070 insn = bfd_getb16 (buf);
13072 insn = bfd_getl16 (buf);
13074 mips16_immed (fragp->fr_file, fragp->fr_line, type, val,
13075 RELAX_MIPS16_USER_EXT (fragp->fr_subtype),
13076 small, ext, &insn, &use_extend, &extend);
13080 md_number_to_chars ((char *) buf, 0xf000 | extend, 2);
13081 fragp->fr_fix += 2;
13085 md_number_to_chars ((char *) buf, insn, 2);
13086 fragp->fr_fix += 2;
13091 if (fragp->fr_opcode == NULL)
13094 old = RELAX_OLD (fragp->fr_subtype);
13095 new = RELAX_NEW (fragp->fr_subtype);
13096 fixptr = fragp->fr_literal + fragp->fr_fix;
13099 memcpy (fixptr - old, fixptr, new);
13101 fragp->fr_fix += new - old;
13107 /* This function is called after the relocs have been generated.
13108 We've been storing mips16 text labels as odd. Here we convert them
13109 back to even for the convenience of the debugger. */
13112 mips_frob_file_after_relocs ()
13115 unsigned int count, i;
13117 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
13120 syms = bfd_get_outsymbols (stdoutput);
13121 count = bfd_get_symcount (stdoutput);
13122 for (i = 0; i < count; i++, syms++)
13124 if (elf_symbol (*syms)->internal_elf_sym.st_other == STO_MIPS16
13125 && ((*syms)->value & 1) != 0)
13127 (*syms)->value &= ~1;
13128 /* If the symbol has an odd size, it was probably computed
13129 incorrectly, so adjust that as well. */
13130 if ((elf_symbol (*syms)->internal_elf_sym.st_size & 1) != 0)
13131 ++elf_symbol (*syms)->internal_elf_sym.st_size;
13138 /* This function is called whenever a label is defined. It is used
13139 when handling branch delays; if a branch has a label, we assume we
13140 can not move it. */
13143 mips_define_label (sym)
13146 struct insn_label_list *l;
13148 if (free_insn_labels == NULL)
13149 l = (struct insn_label_list *) xmalloc (sizeof *l);
13152 l = free_insn_labels;
13153 free_insn_labels = l->next;
13157 l->next = insn_labels;
13161 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
13163 /* Some special processing for a MIPS ELF file. */
13166 mips_elf_final_processing ()
13168 /* Write out the register information. */
13169 if (file_mips_abi != N64_ABI)
13173 s.ri_gprmask = mips_gprmask;
13174 s.ri_cprmask[0] = mips_cprmask[0];
13175 s.ri_cprmask[1] = mips_cprmask[1];
13176 s.ri_cprmask[2] = mips_cprmask[2];
13177 s.ri_cprmask[3] = mips_cprmask[3];
13178 /* The gp_value field is set by the MIPS ELF backend. */
13180 bfd_mips_elf32_swap_reginfo_out (stdoutput, &s,
13181 ((Elf32_External_RegInfo *)
13182 mips_regmask_frag));
13186 Elf64_Internal_RegInfo s;
13188 s.ri_gprmask = mips_gprmask;
13190 s.ri_cprmask[0] = mips_cprmask[0];
13191 s.ri_cprmask[1] = mips_cprmask[1];
13192 s.ri_cprmask[2] = mips_cprmask[2];
13193 s.ri_cprmask[3] = mips_cprmask[3];
13194 /* The gp_value field is set by the MIPS ELF backend. */
13196 bfd_mips_elf64_swap_reginfo_out (stdoutput, &s,
13197 ((Elf64_External_RegInfo *)
13198 mips_regmask_frag));
13201 /* Set the MIPS ELF flag bits. FIXME: There should probably be some
13202 sort of BFD interface for this. */
13203 if (mips_any_noreorder)
13204 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_NOREORDER;
13205 if (mips_pic != NO_PIC)
13206 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_PIC;
13208 /* Set MIPS ELF flags for ASEs. */
13209 #if 0 /* XXX FIXME */
13210 if (file_ase_mips3d)
13211 elf_elfheader (stdoutput)->e_flags |= ???;
13214 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ARCH_ASE_MDMX;
13216 /* Set the MIPS ELF ABI flags. */
13217 if (file_mips_abi == NO_ABI)
13219 else if (file_mips_abi == O32_ABI)
13220 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O32;
13221 else if (file_mips_abi == O64_ABI)
13222 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O64;
13223 else if (file_mips_abi == EABI_ABI)
13226 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI64;
13228 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI32;
13230 else if (file_mips_abi == N32_ABI)
13231 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ABI2;
13233 /* Nothing to do for N64_ABI. */
13235 if (mips_32bitmode)
13236 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_32BITMODE;
13239 #endif /* OBJ_ELF || OBJ_MAYBE_ELF */
13241 typedef struct proc {
13243 unsigned long reg_mask;
13244 unsigned long reg_offset;
13245 unsigned long fpreg_mask;
13246 unsigned long fpreg_offset;
13247 unsigned long frame_offset;
13248 unsigned long frame_reg;
13249 unsigned long pc_reg;
13252 static procS cur_proc;
13253 static procS *cur_proc_ptr;
13254 static int numprocs;
13256 /* Fill in an rs_align_code fragment. */
13259 mips_handle_align (fragp)
13262 if (fragp->fr_type != rs_align_code)
13265 if (mips_opts.mips16)
13267 static const unsigned char be_nop[] = { 0x65, 0x00 };
13268 static const unsigned char le_nop[] = { 0x00, 0x65 };
13273 bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
13274 p = fragp->fr_literal + fragp->fr_fix;
13282 memcpy (p, (target_big_endian ? be_nop : le_nop), 2);
13286 /* For mips32, a nop is a zero, which we trivially get by doing nothing. */
13297 /* check for premature end, nesting errors, etc */
13299 as_warn (_("missing .end at end of assembly"));
13308 if (*input_line_pointer == '-')
13310 ++input_line_pointer;
13313 if (!ISDIGIT (*input_line_pointer))
13314 as_bad (_("expected simple number"));
13315 if (input_line_pointer[0] == '0')
13317 if (input_line_pointer[1] == 'x')
13319 input_line_pointer += 2;
13320 while (ISXDIGIT (*input_line_pointer))
13323 val |= hex_value (*input_line_pointer++);
13325 return negative ? -val : val;
13329 ++input_line_pointer;
13330 while (ISDIGIT (*input_line_pointer))
13333 val |= *input_line_pointer++ - '0';
13335 return negative ? -val : val;
13338 if (!ISDIGIT (*input_line_pointer))
13340 printf (_(" *input_line_pointer == '%c' 0x%02x\n"),
13341 *input_line_pointer, *input_line_pointer);
13342 as_warn (_("invalid number"));
13345 while (ISDIGIT (*input_line_pointer))
13348 val += *input_line_pointer++ - '0';
13350 return negative ? -val : val;
13353 /* The .file directive; just like the usual .file directive, but there
13354 is an initial number which is the ECOFF file index. */
13358 int x ATTRIBUTE_UNUSED;
13364 /* The .end directive. */
13368 int x ATTRIBUTE_UNUSED;
13373 /* Following functions need their own .frame and .cprestore directives. */
13374 mips_frame_reg_valid = 0;
13375 mips_cprestore_valid = 0;
13377 if (!is_end_of_line[(unsigned char) *input_line_pointer])
13380 demand_empty_rest_of_line ();
13385 #ifdef BFD_ASSEMBLER
13386 if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
13391 if (now_seg != data_section && now_seg != bss_section)
13398 as_warn (_(".end not in text section"));
13402 as_warn (_(".end directive without a preceding .ent directive."));
13403 demand_empty_rest_of_line ();
13409 assert (S_GET_NAME (p));
13410 if (strcmp (S_GET_NAME (p), S_GET_NAME (cur_proc_ptr->isym)))
13411 as_warn (_(".end symbol does not match .ent symbol."));
13414 as_warn (_(".end directive missing or unknown symbol"));
13416 #ifdef MIPS_STABS_ELF
13418 segT saved_seg = now_seg;
13419 subsegT saved_subseg = now_subseg;
13424 dot = frag_now_fix ();
13426 #ifdef md_flush_pending_output
13427 md_flush_pending_output ();
13431 subseg_set (pdr_seg, 0);
13433 /* Write the symbol. */
13434 exp.X_op = O_symbol;
13435 exp.X_add_symbol = p;
13436 exp.X_add_number = 0;
13437 emit_expr (&exp, 4);
13439 fragp = frag_more (7 * 4);
13441 md_number_to_chars (fragp, (valueT) cur_proc_ptr->reg_mask, 4);
13442 md_number_to_chars (fragp + 4, (valueT) cur_proc_ptr->reg_offset, 4);
13443 md_number_to_chars (fragp + 8, (valueT) cur_proc_ptr->fpreg_mask, 4);
13444 md_number_to_chars (fragp + 12, (valueT) cur_proc_ptr->fpreg_offset, 4);
13445 md_number_to_chars (fragp + 16, (valueT) cur_proc_ptr->frame_offset, 4);
13446 md_number_to_chars (fragp + 20, (valueT) cur_proc_ptr->frame_reg, 4);
13447 md_number_to_chars (fragp + 24, (valueT) cur_proc_ptr->pc_reg, 4);
13449 subseg_set (saved_seg, saved_subseg);
13451 #endif /* MIPS_STABS_ELF */
13453 cur_proc_ptr = NULL;
13456 /* The .aent and .ent directives. */
13465 symbolP = get_symbol ();
13466 if (*input_line_pointer == ',')
13467 ++input_line_pointer;
13468 SKIP_WHITESPACE ();
13469 if (ISDIGIT (*input_line_pointer)
13470 || *input_line_pointer == '-')
13473 #ifdef BFD_ASSEMBLER
13474 if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
13479 if (now_seg != data_section && now_seg != bss_section)
13486 as_warn (_(".ent or .aent not in text section."));
13488 if (!aent && cur_proc_ptr)
13489 as_warn (_("missing .end"));
13493 /* This function needs its own .frame and .cprestore directives. */
13494 mips_frame_reg_valid = 0;
13495 mips_cprestore_valid = 0;
13497 cur_proc_ptr = &cur_proc;
13498 memset (cur_proc_ptr, '\0', sizeof (procS));
13500 cur_proc_ptr->isym = symbolP;
13502 symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION;
13507 demand_empty_rest_of_line ();
13510 /* The .frame directive. If the mdebug section is present (IRIX 5 native)
13511 then ecoff.c (ecoff_directive_frame) is used. For embedded targets,
13512 s_mips_frame is used so that we can set the PDR information correctly.
13513 We can't use the ecoff routines because they make reference to the ecoff
13514 symbol table (in the mdebug section). */
13517 s_mips_frame (ignore)
13518 int ignore ATTRIBUTE_UNUSED;
13520 #ifdef MIPS_STABS_ELF
13524 if (cur_proc_ptr == (procS *) NULL)
13526 as_warn (_(".frame outside of .ent"));
13527 demand_empty_rest_of_line ();
13531 cur_proc_ptr->frame_reg = tc_get_register (1);
13533 SKIP_WHITESPACE ();
13534 if (*input_line_pointer++ != ','
13535 || get_absolute_expression_and_terminator (&val) != ',')
13537 as_warn (_("Bad .frame directive"));
13538 --input_line_pointer;
13539 demand_empty_rest_of_line ();
13543 cur_proc_ptr->frame_offset = val;
13544 cur_proc_ptr->pc_reg = tc_get_register (0);
13546 demand_empty_rest_of_line ();
13549 #endif /* MIPS_STABS_ELF */
13552 /* The .fmask and .mask directives. If the mdebug section is present
13553 (IRIX 5 native) then ecoff.c (ecoff_directive_mask) is used. For
13554 embedded targets, s_mips_mask is used so that we can set the PDR
13555 information correctly. We can't use the ecoff routines because they
13556 make reference to the ecoff symbol table (in the mdebug section). */
13559 s_mips_mask (reg_type)
13562 #ifdef MIPS_STABS_ELF
13565 if (cur_proc_ptr == (procS *) NULL)
13567 as_warn (_(".mask/.fmask outside of .ent"));
13568 demand_empty_rest_of_line ();
13572 if (get_absolute_expression_and_terminator (&mask) != ',')
13574 as_warn (_("Bad .mask/.fmask directive"));
13575 --input_line_pointer;
13576 demand_empty_rest_of_line ();
13580 off = get_absolute_expression ();
13582 if (reg_type == 'F')
13584 cur_proc_ptr->fpreg_mask = mask;
13585 cur_proc_ptr->fpreg_offset = off;
13589 cur_proc_ptr->reg_mask = mask;
13590 cur_proc_ptr->reg_offset = off;
13593 demand_empty_rest_of_line ();
13595 s_ignore (reg_type);
13596 #endif /* MIPS_STABS_ELF */
13599 /* The .loc directive. */
13610 assert (now_seg == text_section);
13612 lineno = get_number ();
13613 addroff = frag_now_fix ();
13615 symbolP = symbol_new ("", N_SLINE, addroff, frag_now);
13616 S_SET_TYPE (symbolP, N_SLINE);
13617 S_SET_OTHER (symbolP, 0);
13618 S_SET_DESC (symbolP, lineno);
13619 symbolP->sy_segment = now_seg;
13623 /* CPU name/ISA/number mapping table.
13625 Entries are grouped by type. The first matching CPU or ISA entry
13626 gets chosen by CPU or ISA, so it should be the 'canonical' name
13627 for that type. Entries after that within the type are sorted
13630 Case is ignored in comparison, so put the canonical entry in the
13631 appropriate case but everything else in lower case to ease eye pain. */
13632 static const struct mips_cpu_info mips_cpu_info_table[] =
13635 { "MIPS1", 1, ISA_MIPS1, CPU_R3000, },
13636 { "mips", 1, ISA_MIPS1, CPU_R3000, },
13639 { "MIPS2", 1, ISA_MIPS2, CPU_R6000, },
13642 { "MIPS3", 1, ISA_MIPS3, CPU_R4000, },
13645 { "MIPS4", 1, ISA_MIPS4, CPU_R8000, },
13648 { "MIPS5", 1, ISA_MIPS5, CPU_MIPS5, },
13649 { "Generic-MIPS5", 0, ISA_MIPS5, CPU_MIPS5, },
13652 { "MIPS32", 1, ISA_MIPS32, CPU_MIPS32, },
13653 { "mipsisa32", 0, ISA_MIPS32, CPU_MIPS32, },
13654 { "Generic-MIPS32", 0, ISA_MIPS32, CPU_MIPS32, },
13655 { "4kc", 0, ISA_MIPS32, CPU_MIPS32, },
13656 { "4km", 0, ISA_MIPS32, CPU_MIPS32, },
13657 { "4kp", 0, ISA_MIPS32, CPU_MIPS32, },
13659 /* For historical reasons. */
13660 { "MIPS64", 1, ISA_MIPS3, CPU_R4000, },
13663 { "mipsisa64", 1, ISA_MIPS64, CPU_MIPS64, },
13664 { "Generic-MIPS64", 0, ISA_MIPS64, CPU_MIPS64, },
13665 { "5kc", 0, ISA_MIPS64, CPU_MIPS64, },
13666 { "20kc", 0, ISA_MIPS64, CPU_MIPS64, },
13669 { "R2000", 0, ISA_MIPS1, CPU_R2000, },
13670 { "2000", 0, ISA_MIPS1, CPU_R2000, },
13671 { "2k", 0, ISA_MIPS1, CPU_R2000, },
13672 { "r2k", 0, ISA_MIPS1, CPU_R2000, },
13675 { "R3000", 0, ISA_MIPS1, CPU_R3000, },
13676 { "3000", 0, ISA_MIPS1, CPU_R3000, },
13677 { "3k", 0, ISA_MIPS1, CPU_R3000, },
13678 { "r3k", 0, ISA_MIPS1, CPU_R3000, },
13681 { "R3900", 0, ISA_MIPS1, CPU_R3900, },
13682 { "3900", 0, ISA_MIPS1, CPU_R3900, },
13683 { "mipstx39", 0, ISA_MIPS1, CPU_R3900, },
13686 { "R4000", 0, ISA_MIPS3, CPU_R4000, },
13687 { "4000", 0, ISA_MIPS3, CPU_R4000, },
13688 { "4k", 0, ISA_MIPS3, CPU_R4000, }, /* beware */
13689 { "r4k", 0, ISA_MIPS3, CPU_R4000, },
13692 { "R4010", 0, ISA_MIPS2, CPU_R4010, },
13693 { "4010", 0, ISA_MIPS2, CPU_R4010, },
13696 { "R4400", 0, ISA_MIPS3, CPU_R4400, },
13697 { "4400", 0, ISA_MIPS3, CPU_R4400, },
13700 { "R4600", 0, ISA_MIPS3, CPU_R4600, },
13701 { "4600", 0, ISA_MIPS3, CPU_R4600, },
13702 { "mips64orion", 0, ISA_MIPS3, CPU_R4600, },
13703 { "orion", 0, ISA_MIPS3, CPU_R4600, },
13706 { "R4650", 0, ISA_MIPS3, CPU_R4650, },
13707 { "4650", 0, ISA_MIPS3, CPU_R4650, },
13710 { "R6000", 0, ISA_MIPS2, CPU_R6000, },
13711 { "6000", 0, ISA_MIPS2, CPU_R6000, },
13712 { "6k", 0, ISA_MIPS2, CPU_R6000, },
13713 { "r6k", 0, ISA_MIPS2, CPU_R6000, },
13716 { "R8000", 0, ISA_MIPS4, CPU_R8000, },
13717 { "8000", 0, ISA_MIPS4, CPU_R8000, },
13718 { "8k", 0, ISA_MIPS4, CPU_R8000, },
13719 { "r8k", 0, ISA_MIPS4, CPU_R8000, },
13722 { "R10000", 0, ISA_MIPS4, CPU_R10000, },
13723 { "10000", 0, ISA_MIPS4, CPU_R10000, },
13724 { "10k", 0, ISA_MIPS4, CPU_R10000, },
13725 { "r10k", 0, ISA_MIPS4, CPU_R10000, },
13728 { "R12000", 0, ISA_MIPS4, CPU_R12000, },
13729 { "12000", 0, ISA_MIPS4, CPU_R12000, },
13730 { "12k", 0, ISA_MIPS4, CPU_R12000, },
13731 { "r12k", 0, ISA_MIPS4, CPU_R12000, },
13734 { "VR4100", 0, ISA_MIPS3, CPU_VR4100, },
13735 { "4100", 0, ISA_MIPS3, CPU_VR4100, },
13736 { "mips64vr4100", 0, ISA_MIPS3, CPU_VR4100, },
13737 { "r4100", 0, ISA_MIPS3, CPU_VR4100, },
13740 { "VR4111", 0, ISA_MIPS3, CPU_R4111, },
13741 { "4111", 0, ISA_MIPS3, CPU_R4111, },
13742 { "mips64vr4111", 0, ISA_MIPS3, CPU_R4111, },
13743 { "r4111", 0, ISA_MIPS3, CPU_R4111, },
13746 { "VR4300", 0, ISA_MIPS3, CPU_R4300, },
13747 { "4300", 0, ISA_MIPS3, CPU_R4300, },
13748 { "mips64vr4300", 0, ISA_MIPS3, CPU_R4300, },
13749 { "r4300", 0, ISA_MIPS3, CPU_R4300, },
13752 { "VR5000", 0, ISA_MIPS4, CPU_R5000, },
13753 { "5000", 0, ISA_MIPS4, CPU_R5000, },
13754 { "5k", 0, ISA_MIPS4, CPU_R5000, },
13755 { "mips64vr5000", 0, ISA_MIPS4, CPU_R5000, },
13756 { "r5000", 0, ISA_MIPS4, CPU_R5000, },
13757 { "r5200", 0, ISA_MIPS4, CPU_R5000, },
13758 { "rm5200", 0, ISA_MIPS4, CPU_R5000, },
13759 { "r5230", 0, ISA_MIPS4, CPU_R5000, },
13760 { "rm5230", 0, ISA_MIPS4, CPU_R5000, },
13761 { "r5231", 0, ISA_MIPS4, CPU_R5000, },
13762 { "rm5231", 0, ISA_MIPS4, CPU_R5000, },
13763 { "r5261", 0, ISA_MIPS4, CPU_R5000, },
13764 { "rm5261", 0, ISA_MIPS4, CPU_R5000, },
13765 { "r5721", 0, ISA_MIPS4, CPU_R5000, },
13766 { "rm5721", 0, ISA_MIPS4, CPU_R5000, },
13767 { "r5k", 0, ISA_MIPS4, CPU_R5000, },
13768 { "r7000", 0, ISA_MIPS4, CPU_R5000, },
13770 /* Broadcom SB-1 CPU */
13771 { "SB-1", 0, ISA_MIPS64, CPU_SB1, },
13772 { "sb-1250", 0, ISA_MIPS64, CPU_SB1, },
13773 { "sb1", 0, ISA_MIPS64, CPU_SB1, },
13774 { "sb1250", 0, ISA_MIPS64, CPU_SB1, },
13777 { NULL, 0, 0, 0, },
13780 static const struct mips_cpu_info *
13781 mips_cpu_info_from_name (name)
13786 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
13787 if (strcasecmp (name, mips_cpu_info_table[i].name) == 0)
13788 return (&mips_cpu_info_table[i]);
13793 static const struct mips_cpu_info *
13794 mips_cpu_info_from_isa (isa)
13799 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
13800 if (mips_cpu_info_table[i].is_isa
13801 && isa == mips_cpu_info_table[i].isa)
13802 return (&mips_cpu_info_table[i]);
13807 static const struct mips_cpu_info *
13808 mips_cpu_info_from_cpu (cpu)
13813 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
13814 if (!mips_cpu_info_table[i].is_isa
13815 && cpu == mips_cpu_info_table[i].cpu)
13816 return (&mips_cpu_info_table[i]);