1 /* tc-mips.c -- assemble code for a MIPS chip.
2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
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;
87 #define PIC_CALL_REG 25
95 #define ILLEGAL_REG (32)
97 /* Allow override of standard little-endian ECOFF format. */
99 #ifndef ECOFF_LITTLE_FORMAT
100 #define ECOFF_LITTLE_FORMAT "ecoff-littlemips"
103 extern int target_big_endian;
105 /* The name of the readonly data section. */
106 #define RDATA_SECTION_NAME (OUTPUT_FLAVOR == bfd_target_aout_flavour \
108 : OUTPUT_FLAVOR == bfd_target_ecoff_flavour \
110 : OUTPUT_FLAVOR == bfd_target_coff_flavour \
112 : OUTPUT_FLAVOR == bfd_target_elf_flavour \
116 /* The ABI to use. */
127 /* MIPS ABI we are using for this output file. */
128 static enum mips_abi_level file_mips_abi = NO_ABI;
130 /* This is the set of options which may be modified by the .set
131 pseudo-op. We use a struct so that .set push and .set pop are more
134 struct mips_set_options
136 /* MIPS ISA (Instruction Set Architecture) level. This is set to -1
137 if it has not been initialized. Changed by `.set mipsN', and the
138 -mipsN command line option, and the default CPU. */
140 /* Whether we are assembling for the mips16 processor. 0 if we are
141 not, 1 if we are, and -1 if the value has not been initialized.
142 Changed by `.set mips16' and `.set nomips16', and the -mips16 and
143 -nomips16 command line options, and the default CPU. */
145 /* Non-zero if we should not reorder instructions. Changed by `.set
146 reorder' and `.set noreorder'. */
148 /* Non-zero if we should not permit the $at ($1) register to be used
149 in instructions. Changed by `.set at' and `.set noat'. */
151 /* Non-zero if we should warn when a macro instruction expands into
152 more than one machine instruction. Changed by `.set nomacro' and
154 int warn_about_macros;
155 /* Non-zero if we should not move instructions. Changed by `.set
156 move', `.set volatile', `.set nomove', and `.set novolatile'. */
158 /* Non-zero if we should not optimize branches by moving the target
159 of the branch into the delay slot. Actually, we don't perform
160 this optimization anyhow. Changed by `.set bopt' and `.set
163 /* Non-zero if we should not autoextend mips16 instructions.
164 Changed by `.set autoextend' and `.set noautoextend'. */
166 /* Restrict general purpose registers and floating point registers
167 to 32 bit. This is initially determined when -mgp32 or -mfp32
168 is passed but can changed if the assembler code uses .set mipsN. */
171 /* The ABI currently in use. This is changed by .set mipsN to loosen
172 restrictions and doesn't affect the whole file. */
173 enum mips_abi_level abi;
176 /* True if -mgp32 was passed. */
177 static int file_mips_gp32 = 0;
179 /* True if -mfp32 was passed. */
180 static int file_mips_fp32 = 0;
182 /* This is the struct we use to hold the current set of options. Note
183 that we must set the isa field to ISA_UNKNOWN and the mips16 field to
184 -1 to indicate that they have not been initialized. */
186 static struct mips_set_options mips_opts =
188 ISA_UNKNOWN, -1, 0, 0, 0, 0, 0, 0, 0, 0, NO_ABI
191 /* These variables are filled in with the masks of registers used.
192 The object format code reads them and puts them in the appropriate
194 unsigned long mips_gprmask;
195 unsigned long mips_cprmask[4];
197 /* MIPS ISA we are using for this output file. */
198 static int file_mips_isa = ISA_UNKNOWN;
200 /* The argument of the -mcpu= flag. Historical for code generation. */
201 static int mips_cpu = CPU_UNKNOWN;
203 /* The argument of the -march= flag. The architecture we are assembling. */
204 static int mips_arch = CPU_UNKNOWN;
206 /* The argument of the -mtune= flag. The architecture for which we
208 static int mips_tune = CPU_UNKNOWN;
210 /* Whether we should mark the file EABI64 or EABI32. */
211 static int mips_eabi64 = 0;
213 /* If they asked for mips1 or mips2 and a cpu that is
214 mips3 or greater, then mark the object file 32BITMODE. */
215 static int mips_32bitmode = 0;
217 /* Some ISA's have delay slots for instructions which read or write
218 from a coprocessor (eg. mips1-mips3); some don't (eg mips4).
219 Return true if instructions marked INSN_LOAD_COPROC_DELAY,
220 INSN_COPROC_MOVE_DELAY, or INSN_WRITE_COND_CODE actually have a
221 delay slot in this ISA. The uses of this macro assume that any
222 ISA that has delay slots for one of these, has them for all. They
223 also assume that ISAs which don't have delays for these insns, don't
224 have delays for the INSN_LOAD_MEMORY_DELAY instructions either. */
225 #define ISA_HAS_COPROC_DELAYS(ISA) ( \
227 || (ISA) == ISA_MIPS2 \
228 || (ISA) == ISA_MIPS3 \
231 /* Return true if ISA supports 64 bit gp register instructions. */
232 #define ISA_HAS_64BIT_REGS(ISA) ( \
234 || (ISA) == ISA_MIPS4 \
235 || (ISA) == ISA_MIPS5 \
236 || (ISA) == ISA_MIPS64 \
239 #define HAVE_32BIT_GPRS \
241 || mips_opts.abi == O32_ABI \
242 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
244 #define HAVE_32BIT_FPRS \
246 || mips_opts.abi == O32_ABI \
247 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
249 #define HAVE_64BIT_GPRS (! HAVE_32BIT_GPRS)
250 #define HAVE_64BIT_FPRS (! HAVE_32BIT_FPRS)
252 #define HAVE_NEWABI (mips_opts.abi == N32_ABI || mips_opts.abi == N64_ABI)
254 #define HAVE_64BIT_OBJECTS (mips_opts.abi == N64_ABI)
256 /* We can only have 64bit addresses if the object file format
258 #define HAVE_32BIT_ADDRESSES \
260 || ((bfd_arch_bits_per_address (stdoutput) == 32 \
261 || ! HAVE_64BIT_OBJECTS) \
262 && mips_pic != EMBEDDED_PIC))
264 #define HAVE_64BIT_ADDRESSES (! HAVE_32BIT_ADDRESSES)
266 /* Whether the processor uses hardware interlocks to protect
267 reads from the HI and LO registers, and thus does not
268 require nops to be inserted. */
270 #define hilo_interlocks (mips_arch == CPU_R4010 \
271 || mips_arch == CPU_SB1 \
274 /* Whether the processor uses hardware interlocks to protect reads
275 from the GPRs, and thus does not require nops to be inserted. */
276 #define gpr_interlocks \
277 (mips_opts.isa != ISA_MIPS1 \
278 || mips_arch == CPU_R3900)
280 /* As with other "interlocks" this is used by hardware that has FP
281 (co-processor) interlocks. */
282 /* Itbl support may require additional care here. */
283 #define cop_interlocks (mips_arch == CPU_R4300 \
284 || mips_arch == CPU_SB1 \
287 /* Is this a mfhi or mflo instruction? */
288 #define MF_HILO_INSN(PINFO) \
289 ((PINFO & INSN_READ_HI) || (PINFO & INSN_READ_LO))
291 /* MIPS PIC level. */
295 /* Do not generate PIC code. */
298 /* Generate PIC code as in Irix 4. This is not implemented, and I'm
299 not sure what it is supposed to do. */
302 /* Generate PIC code as in the SVR4 MIPS ABI. */
305 /* Generate PIC code without using a global offset table: the data
306 segment has a maximum size of 64K, all data references are off
307 the $gp register, and all text references are PC relative. This
308 is used on some embedded systems. */
312 static enum mips_pic_level mips_pic;
314 /* Warn about all NOPS that the assembler generates. */
315 static int warn_nops = 0;
317 /* 1 if we should generate 32 bit offsets from the GP register in
318 SVR4_PIC mode. Currently has no meaning in other modes. */
319 static int mips_big_got;
321 /* 1 if trap instructions should used for overflow rather than break
323 static int mips_trap;
325 /* 1 if double width floating point constants should not be constructed
326 by assembling two single width halves into two single width floating
327 point registers which just happen to alias the double width destination
328 register. On some architectures this aliasing can be disabled by a bit
329 in the status register, and the setting of this bit cannot be determined
330 automatically at assemble time. */
331 static int mips_disable_float_construction;
333 /* Non-zero if any .set noreorder directives were used. */
335 static int mips_any_noreorder;
337 /* Non-zero if nops should be inserted when the register referenced in
338 an mfhi/mflo instruction is read in the next two instructions. */
339 static int mips_7000_hilo_fix;
341 /* The size of the small data section. */
342 static unsigned int g_switch_value = 8;
343 /* Whether the -G option was used. */
344 static int g_switch_seen = 0;
349 /* If we can determine in advance that GP optimization won't be
350 possible, we can skip the relaxation stuff that tries to produce
351 GP-relative references. This makes delay slot optimization work
354 This function can only provide a guess, but it seems to work for
355 gcc output. It needs to guess right for gcc, otherwise gcc
356 will put what it thinks is a GP-relative instruction in a branch
359 I don't know if a fix is needed for the SVR4_PIC mode. I've only
360 fixed it for the non-PIC mode. KR 95/04/07 */
361 static int nopic_need_relax PARAMS ((symbolS *, int));
363 /* handle of the OPCODE hash table */
364 static struct hash_control *op_hash = NULL;
366 /* The opcode hash table we use for the mips16. */
367 static struct hash_control *mips16_op_hash = NULL;
369 /* This array holds the chars that always start a comment. If the
370 pre-processor is disabled, these aren't very useful */
371 const char comment_chars[] = "#";
373 /* This array holds the chars that only start a comment at the beginning of
374 a line. If the line seems to have the form '# 123 filename'
375 .line and .file directives will appear in the pre-processed output */
376 /* Note that input_file.c hand checks for '#' at the beginning of the
377 first line of the input file. This is because the compiler outputs
378 #NO_APP at the beginning of its output. */
379 /* Also note that C style comments are always supported. */
380 const char line_comment_chars[] = "#";
382 /* This array holds machine specific line separator characters. */
383 const char line_separator_chars[] = ";";
385 /* Chars that can be used to separate mant from exp in floating point nums */
386 const char EXP_CHARS[] = "eE";
388 /* Chars that mean this number is a floating point constant */
391 const char FLT_CHARS[] = "rRsSfFdDxXpP";
393 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
394 changed in read.c . Ideally it shouldn't have to know about it at all,
395 but nothing is ideal around here.
398 static char *insn_error;
400 static int auto_align = 1;
402 /* When outputting SVR4 PIC code, the assembler needs to know the
403 offset in the stack frame from which to restore the $gp register.
404 This is set by the .cprestore pseudo-op, and saved in this
406 static offsetT mips_cprestore_offset = -1;
408 /* Similiar for NewABI PIC code, where $gp is callee-saved. NewABI has some
409 more optimizations, it can use a register value instead of a memory-saved
410 offset and even an other register than $gp as global pointer. */
411 static offsetT mips_cpreturn_offset = -1;
412 static int mips_cpreturn_register = -1;
413 static int mips_gp_register = GP;
415 /* This is the register which holds the stack frame, as set by the
416 .frame pseudo-op. This is needed to implement .cprestore. */
417 static int mips_frame_reg = SP;
419 /* To output NOP instructions correctly, we need to keep information
420 about the previous two instructions. */
422 /* Whether we are optimizing. The default value of 2 means to remove
423 unneeded NOPs and swap branch instructions when possible. A value
424 of 1 means to not swap branches. A value of 0 means to always
426 static int mips_optimize = 2;
428 /* Debugging level. -g sets this to 2. -gN sets this to N. -g0 is
429 equivalent to seeing no -g option at all. */
430 static int mips_debug = 0;
432 /* The previous instruction. */
433 static struct mips_cl_insn prev_insn;
435 /* The instruction before prev_insn. */
436 static struct mips_cl_insn prev_prev_insn;
438 /* If we don't want information for prev_insn or prev_prev_insn, we
439 point the insn_mo field at this dummy integer. */
440 static const struct mips_opcode dummy_opcode = { NULL, NULL, 0, 0, 0, 0 };
442 /* Non-zero if prev_insn is valid. */
443 static int prev_insn_valid;
445 /* The frag for the previous instruction. */
446 static struct frag *prev_insn_frag;
448 /* The offset into prev_insn_frag for the previous instruction. */
449 static long prev_insn_where;
451 /* The reloc type for the previous instruction, if any. */
452 static bfd_reloc_code_real_type prev_insn_reloc_type[3];
454 /* The reloc for the previous instruction, if any. */
455 static fixS *prev_insn_fixp[3];
457 /* Non-zero if the previous instruction was in a delay slot. */
458 static int prev_insn_is_delay_slot;
460 /* Non-zero if the previous instruction was in a .set noreorder. */
461 static int prev_insn_unreordered;
463 /* Non-zero if the previous instruction uses an extend opcode (if
465 static int prev_insn_extended;
467 /* Non-zero if the previous previous instruction was in a .set
469 static int prev_prev_insn_unreordered;
471 /* If this is set, it points to a frag holding nop instructions which
472 were inserted before the start of a noreorder section. If those
473 nops turn out to be unnecessary, the size of the frag can be
475 static fragS *prev_nop_frag;
477 /* The number of nop instructions we created in prev_nop_frag. */
478 static int prev_nop_frag_holds;
480 /* The number of nop instructions that we know we need in
482 static int prev_nop_frag_required;
484 /* The number of instructions we've seen since prev_nop_frag. */
485 static int prev_nop_frag_since;
487 /* For ECOFF and ELF, relocations against symbols are done in two
488 parts, with a HI relocation and a LO relocation. Each relocation
489 has only 16 bits of space to store an addend. This means that in
490 order for the linker to handle carries correctly, it must be able
491 to locate both the HI and the LO relocation. This means that the
492 relocations must appear in order in the relocation table.
494 In order to implement this, we keep track of each unmatched HI
495 relocation. We then sort them so that they immediately precede the
496 corresponding LO relocation. */
501 struct mips_hi_fixup *next;
504 /* The section this fixup is in. */
508 /* The list of unmatched HI relocs. */
510 static struct mips_hi_fixup *mips_hi_fixup_list;
512 /* Map normal MIPS register numbers to mips16 register numbers. */
514 #define X ILLEGAL_REG
515 static const int mips32_to_16_reg_map[] =
517 X, X, 2, 3, 4, 5, 6, 7,
518 X, X, X, X, X, X, X, X,
519 0, 1, X, X, X, X, X, X,
520 X, X, X, X, X, X, X, X
524 /* Map mips16 register numbers to normal MIPS register numbers. */
526 static const unsigned int mips16_to_32_reg_map[] =
528 16, 17, 2, 3, 4, 5, 6, 7
531 /* Since the MIPS does not have multiple forms of PC relative
532 instructions, we do not have to do relaxing as is done on other
533 platforms. However, we do have to handle GP relative addressing
534 correctly, which turns out to be a similar problem.
536 Every macro that refers to a symbol can occur in (at least) two
537 forms, one with GP relative addressing and one without. For
538 example, loading a global variable into a register generally uses
539 a macro instruction like this:
541 If i can be addressed off the GP register (this is true if it is in
542 the .sbss or .sdata section, or if it is known to be smaller than
543 the -G argument) this will generate the following instruction:
545 This instruction will use a GPREL reloc. If i can not be addressed
546 off the GP register, the following instruction sequence will be used:
549 In this case the first instruction will have a HI16 reloc, and the
550 second reloc will have a LO16 reloc. Both relocs will be against
553 The issue here is that we may not know whether i is GP addressable
554 until after we see the instruction that uses it. Therefore, we
555 want to be able to choose the final instruction sequence only at
556 the end of the assembly. This is similar to the way other
557 platforms choose the size of a PC relative instruction only at the
560 When generating position independent code we do not use GP
561 addressing in quite the same way, but the issue still arises as
562 external symbols and local symbols must be handled differently.
564 We handle these issues by actually generating both possible
565 instruction sequences. The longer one is put in a frag_var with
566 type rs_machine_dependent. We encode what to do with the frag in
567 the subtype field. We encode (1) the number of existing bytes to
568 replace, (2) the number of new bytes to use, (3) the offset from
569 the start of the existing bytes to the first reloc we must generate
570 (that is, the offset is applied from the start of the existing
571 bytes after they are replaced by the new bytes, if any), (4) the
572 offset from the start of the existing bytes to the second reloc,
573 (5) whether a third reloc is needed (the third reloc is always four
574 bytes after the second reloc), and (6) whether to warn if this
575 variant is used (this is sometimes needed if .set nomacro or .set
576 noat is in effect). All these numbers are reasonably small.
578 Generating two instruction sequences must be handled carefully to
579 ensure that delay slots are handled correctly. Fortunately, there
580 are a limited number of cases. When the second instruction
581 sequence is generated, append_insn is directed to maintain the
582 existing delay slot information, so it continues to apply to any
583 code after the second instruction sequence. This means that the
584 second instruction sequence must not impose any requirements not
585 required by the first instruction sequence.
587 These variant frags are then handled in functions called by the
588 machine independent code. md_estimate_size_before_relax returns
589 the final size of the frag. md_convert_frag sets up the final form
590 of the frag. tc_gen_reloc adjust the first reloc and adds a second
592 #define RELAX_ENCODE(old, new, reloc1, reloc2, reloc3, warn) \
596 | (((reloc1) + 64) << 9) \
597 | (((reloc2) + 64) << 2) \
598 | ((reloc3) ? (1 << 1) : 0) \
600 #define RELAX_OLD(i) (((i) >> 23) & 0x7f)
601 #define RELAX_NEW(i) (((i) >> 16) & 0x7f)
602 #define RELAX_RELOC1(i) ((valueT) (((i) >> 9) & 0x7f) - 64)
603 #define RELAX_RELOC2(i) ((valueT) (((i) >> 2) & 0x7f) - 64)
604 #define RELAX_RELOC3(i) (((i) >> 1) & 1)
605 #define RELAX_WARN(i) ((i) & 1)
607 /* For mips16 code, we use an entirely different form of relaxation.
608 mips16 supports two versions of most instructions which take
609 immediate values: a small one which takes some small value, and a
610 larger one which takes a 16 bit value. Since branches also follow
611 this pattern, relaxing these values is required.
613 We can assemble both mips16 and normal MIPS code in a single
614 object. Therefore, we need to support this type of relaxation at
615 the same time that we support the relaxation described above. We
616 use the high bit of the subtype field to distinguish these cases.
618 The information we store for this type of relaxation is the
619 argument code found in the opcode file for this relocation, whether
620 the user explicitly requested a small or extended form, and whether
621 the relocation is in a jump or jal delay slot. That tells us the
622 size of the value, and how it should be stored. We also store
623 whether the fragment is considered to be extended or not. We also
624 store whether this is known to be a branch to a different section,
625 whether we have tried to relax this frag yet, and whether we have
626 ever extended a PC relative fragment because of a shift count. */
627 #define RELAX_MIPS16_ENCODE(type, small, ext, dslot, jal_dslot) \
630 | ((small) ? 0x100 : 0) \
631 | ((ext) ? 0x200 : 0) \
632 | ((dslot) ? 0x400 : 0) \
633 | ((jal_dslot) ? 0x800 : 0))
634 #define RELAX_MIPS16_P(i) (((i) & 0x80000000) != 0)
635 #define RELAX_MIPS16_TYPE(i) ((i) & 0xff)
636 #define RELAX_MIPS16_USER_SMALL(i) (((i) & 0x100) != 0)
637 #define RELAX_MIPS16_USER_EXT(i) (((i) & 0x200) != 0)
638 #define RELAX_MIPS16_DSLOT(i) (((i) & 0x400) != 0)
639 #define RELAX_MIPS16_JAL_DSLOT(i) (((i) & 0x800) != 0)
640 #define RELAX_MIPS16_EXTENDED(i) (((i) & 0x1000) != 0)
641 #define RELAX_MIPS16_MARK_EXTENDED(i) ((i) | 0x1000)
642 #define RELAX_MIPS16_CLEAR_EXTENDED(i) ((i) &~ 0x1000)
643 #define RELAX_MIPS16_LONG_BRANCH(i) (((i) & 0x2000) != 0)
644 #define RELAX_MIPS16_MARK_LONG_BRANCH(i) ((i) | 0x2000)
645 #define RELAX_MIPS16_CLEAR_LONG_BRANCH(i) ((i) &~ 0x2000)
647 /* Prototypes for static functions. */
650 #define internalError() \
651 as_fatal (_("internal Error, line %d, %s"), __LINE__, __FILE__)
653 #define internalError() as_fatal (_("MIPS internal Error"));
656 enum mips_regclass { MIPS_GR_REG, MIPS_FP_REG, MIPS16_REG };
658 static int insn_uses_reg PARAMS ((struct mips_cl_insn *ip,
659 unsigned int reg, enum mips_regclass class));
660 static int reg_needs_delay PARAMS ((unsigned int));
661 static void mips16_mark_labels PARAMS ((void));
662 static void append_insn PARAMS ((char *place,
663 struct mips_cl_insn * ip,
665 bfd_reloc_code_real_type *r,
667 static void mips_no_prev_insn PARAMS ((int));
668 static void mips_emit_delays PARAMS ((boolean));
670 static void macro_build PARAMS ((char *place, int *counter, expressionS * ep,
671 const char *name, const char *fmt,
674 static void macro_build ();
676 static void mips16_macro_build PARAMS ((char *, int *, expressionS *,
677 const char *, const char *,
679 static void macro_build_lui PARAMS ((char *place, int *counter,
680 expressionS * ep, int regnum));
681 static void set_at PARAMS ((int *counter, int reg, int unsignedp));
682 static void check_absolute_expr PARAMS ((struct mips_cl_insn * ip,
684 static void load_register PARAMS ((int *, int, expressionS *, int));
685 static void load_address PARAMS ((int *, int, expressionS *, int, int *));
686 static void move_register PARAMS ((int *, int, int));
687 static void macro PARAMS ((struct mips_cl_insn * ip));
688 static void mips16_macro PARAMS ((struct mips_cl_insn * ip));
689 #ifdef LOSING_COMPILER
690 static void macro2 PARAMS ((struct mips_cl_insn * ip));
692 static void mips_ip PARAMS ((char *str, struct mips_cl_insn * ip));
693 static void mips16_ip PARAMS ((char *str, struct mips_cl_insn * ip));
694 static void mips16_immed PARAMS ((char *, unsigned int, int, offsetT, boolean,
695 boolean, boolean, unsigned long *,
696 boolean *, unsigned short *));
697 static int my_getSmallParser PARAMS ((char **, unsigned int *, int *));
698 static int my_getSmallExpression PARAMS ((expressionS *, char *));
699 static void my_getExpression PARAMS ((expressionS *, char *));
701 static int support_64bit_objects PARAMS((void));
703 static symbolS *get_symbol PARAMS ((void));
704 static void mips_align PARAMS ((int to, int fill, symbolS *label));
705 static void s_align PARAMS ((int));
706 static void s_change_sec PARAMS ((int));
707 static void s_cons PARAMS ((int));
708 static void s_float_cons PARAMS ((int));
709 static void s_mips_globl PARAMS ((int));
710 static void s_option PARAMS ((int));
711 static void s_mipsset PARAMS ((int));
712 static void s_abicalls PARAMS ((int));
713 static void s_cpload PARAMS ((int));
714 static void s_cpsetup PARAMS ((int));
715 static void s_cplocal PARAMS ((int));
716 static void s_cprestore PARAMS ((int));
717 static void s_cpreturn PARAMS ((int));
718 static void s_gpvalue PARAMS ((int));
719 static void s_gpword PARAMS ((int));
720 static void s_cpadd PARAMS ((int));
721 static void s_insn PARAMS ((int));
722 static void md_obj_begin PARAMS ((void));
723 static void md_obj_end PARAMS ((void));
724 static long get_number PARAMS ((void));
725 static void s_mips_ent PARAMS ((int));
726 static void s_mips_end PARAMS ((int));
727 static void s_mips_frame PARAMS ((int));
728 static void s_mips_mask PARAMS ((int));
729 static void s_mips_stab PARAMS ((int));
730 static void s_mips_weakext PARAMS ((int));
731 static void s_file PARAMS ((int));
732 static int mips16_extended_frag PARAMS ((fragS *, asection *, long));
733 static const char *mips_isa_to_str PARAMS ((int));
734 static const char *mips_cpu_to_str PARAMS ((int));
735 static int validate_mips_insn PARAMS ((const struct mips_opcode *));
736 static void show PARAMS ((FILE *, char *, int *, int *));
738 static int mips_need_elf_addend_fixup PARAMS ((fixS *));
741 /* Return values of my_getSmallExpression(). */
748 /* Direct relocation creation by %percent_op(). */
767 /* Table and functions used to map between CPU/ISA names, and
768 ISA levels, and CPU numbers. */
772 const char *name; /* CPU or ISA name. */
773 int is_isa; /* Is this an ISA? (If 0, a CPU.) */
774 int isa; /* ISA level. */
775 int cpu; /* CPU number (default CPU if ISA). */
778 static const struct mips_cpu_info *mips_cpu_info_from_name PARAMS ((const char *));
779 static const struct mips_cpu_info *mips_cpu_info_from_isa PARAMS ((int));
780 static const struct mips_cpu_info *mips_cpu_info_from_cpu PARAMS ((int));
784 The following pseudo-ops from the Kane and Heinrich MIPS book
785 should be defined here, but are currently unsupported: .alias,
786 .galive, .gjaldef, .gjrlive, .livereg, .noalias.
788 The following pseudo-ops from the Kane and Heinrich MIPS book are
789 specific to the type of debugging information being generated, and
790 should be defined by the object format: .aent, .begin, .bend,
791 .bgnb, .end, .endb, .ent, .fmask, .frame, .loc, .mask, .verstamp,
794 The following pseudo-ops from the Kane and Heinrich MIPS book are
795 not MIPS CPU specific, but are also not specific to the object file
796 format. This file is probably the best place to define them, but
797 they are not currently supported: .asm0, .endr, .lab, .repeat,
800 static const pseudo_typeS mips_pseudo_table[] =
802 /* MIPS specific pseudo-ops. */
803 {"option", s_option, 0},
804 {"set", s_mipsset, 0},
805 {"rdata", s_change_sec, 'r'},
806 {"sdata", s_change_sec, 's'},
807 {"livereg", s_ignore, 0},
808 {"abicalls", s_abicalls, 0},
809 {"cpload", s_cpload, 0},
810 {"cpsetup", s_cpsetup, 0},
811 {"cplocal", s_cplocal, 0},
812 {"cprestore", s_cprestore, 0},
813 {"cpreturn", s_cpreturn, 0},
814 {"gpvalue", s_gpvalue, 0},
815 {"gpword", s_gpword, 0},
816 {"cpadd", s_cpadd, 0},
819 /* Relatively generic pseudo-ops that happen to be used on MIPS
821 {"asciiz", stringer, 1},
822 {"bss", s_change_sec, 'b'},
825 {"dword", s_cons, 3},
826 {"weakext", s_mips_weakext, 0},
828 /* These pseudo-ops are defined in read.c, but must be overridden
829 here for one reason or another. */
830 {"align", s_align, 0},
832 {"data", s_change_sec, 'd'},
833 {"double", s_float_cons, 'd'},
834 {"float", s_float_cons, 'f'},
835 {"globl", s_mips_globl, 0},
836 {"global", s_mips_globl, 0},
837 {"hword", s_cons, 1},
842 {"short", s_cons, 1},
843 {"single", s_float_cons, 'f'},
844 {"stabn", s_mips_stab, 'n'},
845 {"text", s_change_sec, 't'},
848 #ifdef MIPS_STABS_ELF
849 { "extern", ecoff_directive_extern, 0},
855 static const pseudo_typeS mips_nonecoff_pseudo_table[] =
857 /* These pseudo-ops should be defined by the object file format.
858 However, a.out doesn't support them, so we have versions here. */
859 {"aent", s_mips_ent, 1},
860 {"bgnb", s_ignore, 0},
861 {"end", s_mips_end, 0},
862 {"endb", s_ignore, 0},
863 {"ent", s_mips_ent, 0},
865 {"fmask", s_mips_mask, 'F'},
866 {"frame", s_mips_frame, 0},
867 {"loc", s_ignore, 0},
868 {"mask", s_mips_mask, 'R'},
869 {"verstamp", s_ignore, 0},
873 extern void pop_insert PARAMS ((const pseudo_typeS *));
878 pop_insert (mips_pseudo_table);
879 if (! ECOFF_DEBUGGING)
880 pop_insert (mips_nonecoff_pseudo_table);
883 /* Symbols labelling the current insn. */
885 struct insn_label_list
887 struct insn_label_list *next;
891 static struct insn_label_list *insn_labels;
892 static struct insn_label_list *free_insn_labels;
894 static void mips_clear_insn_labels PARAMS ((void));
897 mips_clear_insn_labels ()
899 register struct insn_label_list **pl;
901 for (pl = &free_insn_labels; *pl != NULL; pl = &(*pl)->next)
907 static char *expr_end;
909 /* Expressions which appear in instructions. These are set by
912 static expressionS imm_expr;
913 static expressionS offset_expr;
915 /* Relocs associated with imm_expr and offset_expr. */
917 static bfd_reloc_code_real_type imm_reloc[3]
918 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
919 static bfd_reloc_code_real_type offset_reloc[3]
920 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
922 /* This is set by mips_ip if imm_reloc is an unmatched HI16_S reloc. */
924 static boolean imm_unmatched_hi;
926 /* These are set by mips16_ip if an explicit extension is used. */
928 static boolean mips16_small, mips16_ext;
930 #ifdef MIPS_STABS_ELF
931 /* The pdr segment for per procedure frame/regmask info */
937 mips_isa_to_str (isa)
940 const struct mips_cpu_info *ci;
943 ci = mips_cpu_info_from_isa (isa);
947 sprintf (s, "ISA#%d", isa);
952 mips_cpu_to_str (cpu)
955 const struct mips_cpu_info *ci;
958 ci = mips_cpu_info_from_cpu (cpu);
962 sprintf (s, "CPU#%d", cpu);
966 /* The default target format to use. */
969 mips_target_format ()
971 switch (OUTPUT_FLAVOR)
973 case bfd_target_aout_flavour:
974 return target_big_endian ? "a.out-mips-big" : "a.out-mips-little";
975 case bfd_target_ecoff_flavour:
976 return target_big_endian ? "ecoff-bigmips" : ECOFF_LITTLE_FORMAT;
977 case bfd_target_coff_flavour:
979 case bfd_target_elf_flavour:
981 /* This is traditional mips */
982 return (target_big_endian
983 ? (HAVE_64BIT_OBJECTS ? "elf64-tradbigmips"
984 : "elf32-tradbigmips")
985 : (HAVE_64BIT_OBJECTS ? "elf64-tradlittlemips"
986 : "elf32-tradlittlemips"));
988 return (target_big_endian
989 ? (HAVE_64BIT_OBJECTS ? "elf64-bigmips" : "elf32-bigmips")
990 : (HAVE_64BIT_OBJECTS ? "elf64-littlemips"
991 : "elf32-littlemips"));
999 /* This function is called once, at assembler startup time. It should
1000 set up all the tables, etc. that the MD part of the assembler will need. */
1005 register const char *retval = NULL;
1010 int mips_isa_from_cpu;
1011 int target_cpu_had_mips16 = 0;
1012 const struct mips_cpu_info *ci;
1014 /* GP relative stuff not working for PE */
1015 if (strncmp (TARGET_OS, "pe", 2) == 0
1016 && g_switch_value != 0)
1019 as_bad (_("-G not supported in this configuration."));
1024 if (strcmp (cpu + (sizeof TARGET_CPU) - 3, "el") == 0)
1026 a = xmalloc (sizeof TARGET_CPU);
1027 strcpy (a, TARGET_CPU);
1028 a[(sizeof TARGET_CPU) - 3] = '\0';
1032 if (strncmp (cpu, "mips16", sizeof "mips16" - 1) == 0)
1034 target_cpu_had_mips16 = 1;
1035 cpu += sizeof "mips16" - 1;
1038 if (mips_opts.mips16 < 0)
1039 mips_opts.mips16 = target_cpu_had_mips16;
1041 /* Backward compatibility for historic -mcpu= option. Check for
1042 incompatible options, warn if -mcpu is used. */
1043 if (mips_cpu != CPU_UNKNOWN
1044 && mips_arch != CPU_UNKNOWN
1045 && mips_cpu != mips_arch)
1047 as_fatal (_("The -mcpu option can't be used together with -march. "
1048 "Use -mtune instead of -mcpu."));
1051 if (mips_cpu != CPU_UNKNOWN
1052 && mips_tune != CPU_UNKNOWN
1053 && mips_cpu != mips_tune)
1055 as_fatal (_("The -mcpu option can't be used together with -mtune. "
1056 "Use -march instead of -mcpu."));
1059 if (mips_arch == CPU_UNKNOWN && mips_cpu != CPU_UNKNOWN)
1061 ci = mips_cpu_info_from_cpu (mips_cpu);
1062 assert (ci != NULL);
1063 mips_arch = ci->cpu;
1064 as_warn (_("The -mcpu option is deprecated. Please use -march and "
1065 "-mtune instead."));
1068 /* At this point, mips_arch will either be CPU_UNKNOWN if no ARCH was
1069 specified on the command line, or some other value if one was.
1070 Similarly, mips_opts.isa will be ISA_UNKNOWN if not specified on
1071 the command line, or will be set otherwise if one was. */
1072 if (mips_arch != CPU_UNKNOWN && mips_opts.isa != ISA_UNKNOWN)
1074 /* We have to check if the isa is the default isa of arch. Otherwise
1075 we'll get invalid object file headers. */
1076 ci = mips_cpu_info_from_cpu (mips_arch);
1077 assert (ci != NULL);
1078 if (mips_opts.isa != ci->isa)
1080 /* This really should be an error instead of a warning, but old
1081 compilers only have -mcpu which sets both arch and tune. For
1082 now, we discard arch and preserve tune. */
1083 as_warn (_("The -march option is incompatible to -mipsN and "
1084 "therefore ignored."));
1085 if (mips_tune == CPU_UNKNOWN)
1086 mips_tune = mips_arch;
1087 ci = mips_cpu_info_from_isa (mips_opts.isa);
1088 assert (ci != NULL);
1089 mips_arch = ci->cpu;
1092 else if (mips_arch != CPU_UNKNOWN && mips_opts.isa == ISA_UNKNOWN)
1094 /* We have ARCH, we need ISA. */
1095 ci = mips_cpu_info_from_cpu (mips_arch);
1096 assert (ci != NULL);
1097 mips_opts.isa = ci->isa;
1099 else if (mips_arch == CPU_UNKNOWN && mips_opts.isa != ISA_UNKNOWN)
1101 /* We have ISA, we need default ARCH. */
1102 ci = mips_cpu_info_from_isa (mips_opts.isa);
1103 assert (ci != NULL);
1104 mips_arch = ci->cpu;
1108 /* We need to set both ISA and ARCH from target cpu. */
1109 ci = mips_cpu_info_from_name (cpu);
1111 ci = mips_cpu_info_from_cpu (CPU_R3000);
1112 assert (ci != NULL);
1113 mips_opts.isa = ci->isa;
1114 mips_arch = ci->cpu;
1117 if (mips_tune == CPU_UNKNOWN)
1118 mips_tune = mips_arch;
1120 ci = mips_cpu_info_from_cpu (mips_arch);
1121 assert (ci != NULL);
1122 mips_isa_from_cpu = ci->isa;
1124 /* End of TARGET_CPU processing, get rid of malloced memory
1133 if (mips_opts.isa == ISA_MIPS1 && mips_trap)
1134 as_bad (_("trap exception not supported at ISA 1"));
1136 /* Set the EABI kind based on the ISA before the user gets
1137 to change the ISA with directives. This isn't really
1138 the best, but then neither is basing the abi on the isa. */
1139 if (ISA_HAS_64BIT_REGS (mips_opts.isa)
1140 && mips_opts.abi == EABI_ABI)
1143 /* If they asked for mips1 or mips2 and a cpu that is
1144 mips3 or greater, then mark the object file 32BITMODE. */
1145 if (mips_isa_from_cpu != ISA_UNKNOWN
1146 && ! ISA_HAS_64BIT_REGS (mips_opts.isa)
1147 && ISA_HAS_64BIT_REGS (mips_isa_from_cpu))
1150 if (! bfd_set_arch_mach (stdoutput, bfd_arch_mips, mips_arch))
1151 as_warn (_("Could not set architecture and machine"));
1153 file_mips_isa = mips_opts.isa;
1154 file_mips_abi = mips_opts.abi;
1155 mips_opts.gp32 = file_mips_gp32;
1156 mips_opts.fp32 = file_mips_fp32;
1158 op_hash = hash_new ();
1160 for (i = 0; i < NUMOPCODES;)
1162 const char *name = mips_opcodes[i].name;
1164 retval = hash_insert (op_hash, name, (PTR) &mips_opcodes[i]);
1167 fprintf (stderr, _("internal error: can't hash `%s': %s\n"),
1168 mips_opcodes[i].name, retval);
1169 /* Probably a memory allocation problem? Give up now. */
1170 as_fatal (_("Broken assembler. No assembly attempted."));
1174 if (mips_opcodes[i].pinfo != INSN_MACRO)
1176 if (!validate_mips_insn (&mips_opcodes[i]))
1181 while ((i < NUMOPCODES) && !strcmp (mips_opcodes[i].name, name));
1184 mips16_op_hash = hash_new ();
1187 while (i < bfd_mips16_num_opcodes)
1189 const char *name = mips16_opcodes[i].name;
1191 retval = hash_insert (mips16_op_hash, name, (PTR) &mips16_opcodes[i]);
1193 as_fatal (_("internal: can't hash `%s': %s"),
1194 mips16_opcodes[i].name, retval);
1197 if (mips16_opcodes[i].pinfo != INSN_MACRO
1198 && ((mips16_opcodes[i].match & mips16_opcodes[i].mask)
1199 != mips16_opcodes[i].match))
1201 fprintf (stderr, _("internal error: bad mips16 opcode: %s %s\n"),
1202 mips16_opcodes[i].name, mips16_opcodes[i].args);
1207 while (i < bfd_mips16_num_opcodes
1208 && strcmp (mips16_opcodes[i].name, name) == 0);
1212 as_fatal (_("Broken assembler. No assembly attempted."));
1214 /* We add all the general register names to the symbol table. This
1215 helps us detect invalid uses of them. */
1216 for (i = 0; i < 32; i++)
1220 sprintf (buf, "$%d", i);
1221 symbol_table_insert (symbol_new (buf, reg_section, i,
1222 &zero_address_frag));
1224 symbol_table_insert (symbol_new ("$fp", reg_section, FP,
1225 &zero_address_frag));
1226 symbol_table_insert (symbol_new ("$sp", reg_section, SP,
1227 &zero_address_frag));
1228 symbol_table_insert (symbol_new ("$gp", reg_section, GP,
1229 &zero_address_frag));
1230 symbol_table_insert (symbol_new ("$at", reg_section, AT,
1231 &zero_address_frag));
1232 symbol_table_insert (symbol_new ("$kt0", reg_section, KT0,
1233 &zero_address_frag));
1234 symbol_table_insert (symbol_new ("$kt1", reg_section, KT1,
1235 &zero_address_frag));
1236 symbol_table_insert (symbol_new ("$pc", reg_section, -1,
1237 &zero_address_frag));
1239 mips_no_prev_insn (false);
1242 mips_cprmask[0] = 0;
1243 mips_cprmask[1] = 0;
1244 mips_cprmask[2] = 0;
1245 mips_cprmask[3] = 0;
1247 /* set the default alignment for the text section (2**2) */
1248 record_alignment (text_section, 2);
1250 if (USE_GLOBAL_POINTER_OPT)
1251 bfd_set_gp_size (stdoutput, g_switch_value);
1253 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
1255 /* On a native system, sections must be aligned to 16 byte
1256 boundaries. When configured for an embedded ELF target, we
1258 if (strcmp (TARGET_OS, "elf") != 0)
1260 (void) bfd_set_section_alignment (stdoutput, text_section, 4);
1261 (void) bfd_set_section_alignment (stdoutput, data_section, 4);
1262 (void) bfd_set_section_alignment (stdoutput, bss_section, 4);
1265 /* Create a .reginfo section for register masks and a .mdebug
1266 section for debugging information. */
1274 subseg = now_subseg;
1276 /* The ABI says this section should be loaded so that the
1277 running program can access it. However, we don't load it
1278 if we are configured for an embedded target */
1279 flags = SEC_READONLY | SEC_DATA;
1280 if (strcmp (TARGET_OS, "elf") != 0)
1281 flags |= SEC_ALLOC | SEC_LOAD;
1285 sec = subseg_new (".reginfo", (subsegT) 0);
1287 (void) bfd_set_section_flags (stdoutput, sec, flags);
1288 (void) bfd_set_section_alignment (stdoutput, sec, 2);
1291 mips_regmask_frag = frag_more (sizeof (Elf32_External_RegInfo));
1296 /* The 64-bit ABI uses a .MIPS.options section rather than
1297 .reginfo section. */
1298 sec = subseg_new (".MIPS.options", (subsegT) 0);
1299 (void) bfd_set_section_flags (stdoutput, sec, flags);
1300 (void) bfd_set_section_alignment (stdoutput, sec, 3);
1303 /* Set up the option header. */
1305 Elf_Internal_Options opthdr;
1308 opthdr.kind = ODK_REGINFO;
1309 opthdr.size = (sizeof (Elf_External_Options)
1310 + sizeof (Elf64_External_RegInfo));
1313 f = frag_more (sizeof (Elf_External_Options));
1314 bfd_mips_elf_swap_options_out (stdoutput, &opthdr,
1315 (Elf_External_Options *) f);
1317 mips_regmask_frag = frag_more (sizeof (Elf64_External_RegInfo));
1322 if (ECOFF_DEBUGGING)
1324 sec = subseg_new (".mdebug", (subsegT) 0);
1325 (void) bfd_set_section_flags (stdoutput, sec,
1326 SEC_HAS_CONTENTS | SEC_READONLY);
1327 (void) bfd_set_section_alignment (stdoutput, sec, 2);
1330 #ifdef MIPS_STABS_ELF
1331 pdr_seg = subseg_new (".pdr", (subsegT) 0);
1332 (void) bfd_set_section_flags (stdoutput, pdr_seg,
1333 SEC_READONLY | SEC_RELOC | SEC_DEBUGGING);
1334 (void) bfd_set_section_alignment (stdoutput, pdr_seg, 2);
1337 subseg_set (seg, subseg);
1341 if (! ECOFF_DEBUGGING)
1348 if (! ECOFF_DEBUGGING)
1356 struct mips_cl_insn insn;
1357 bfd_reloc_code_real_type unused_reloc[3]
1358 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
1360 imm_expr.X_op = O_absent;
1361 imm_unmatched_hi = false;
1362 offset_expr.X_op = O_absent;
1363 imm_reloc[0] = BFD_RELOC_UNUSED;
1364 imm_reloc[1] = BFD_RELOC_UNUSED;
1365 imm_reloc[2] = BFD_RELOC_UNUSED;
1366 offset_reloc[0] = BFD_RELOC_UNUSED;
1367 offset_reloc[1] = BFD_RELOC_UNUSED;
1368 offset_reloc[2] = BFD_RELOC_UNUSED;
1370 if (mips_opts.mips16)
1371 mips16_ip (str, &insn);
1374 mips_ip (str, &insn);
1375 DBG ((_("returned from mips_ip(%s) insn_opcode = 0x%x\n"),
1376 str, insn.insn_opcode));
1381 as_bad ("%s `%s'", insn_error, str);
1385 if (insn.insn_mo->pinfo == INSN_MACRO)
1387 if (mips_opts.mips16)
1388 mips16_macro (&insn);
1394 if (imm_expr.X_op != O_absent)
1395 append_insn (NULL, &insn, &imm_expr, imm_reloc, imm_unmatched_hi);
1396 else if (offset_expr.X_op != O_absent)
1397 append_insn (NULL, &insn, &offset_expr, offset_reloc, false);
1399 append_insn (NULL, &insn, NULL, unused_reloc, false);
1403 /* See whether instruction IP reads register REG. CLASS is the type
1407 insn_uses_reg (ip, reg, class)
1408 struct mips_cl_insn *ip;
1410 enum mips_regclass class;
1412 if (class == MIPS16_REG)
1414 assert (mips_opts.mips16);
1415 reg = mips16_to_32_reg_map[reg];
1416 class = MIPS_GR_REG;
1419 /* Don't report on general register 0, since it never changes. */
1420 if (class == MIPS_GR_REG && reg == 0)
1423 if (class == MIPS_FP_REG)
1425 assert (! mips_opts.mips16);
1426 /* If we are called with either $f0 or $f1, we must check $f0.
1427 This is not optimal, because it will introduce an unnecessary
1428 NOP between "lwc1 $f0" and "swc1 $f1". To fix this we would
1429 need to distinguish reading both $f0 and $f1 or just one of
1430 them. Note that we don't have to check the other way,
1431 because there is no instruction that sets both $f0 and $f1
1432 and requires a delay. */
1433 if ((ip->insn_mo->pinfo & INSN_READ_FPR_S)
1434 && ((((ip->insn_opcode >> OP_SH_FS) & OP_MASK_FS) &~(unsigned)1)
1435 == (reg &~ (unsigned) 1)))
1437 if ((ip->insn_mo->pinfo & INSN_READ_FPR_T)
1438 && ((((ip->insn_opcode >> OP_SH_FT) & OP_MASK_FT) &~(unsigned)1)
1439 == (reg &~ (unsigned) 1)))
1442 else if (! mips_opts.mips16)
1444 if ((ip->insn_mo->pinfo & INSN_READ_GPR_S)
1445 && ((ip->insn_opcode >> OP_SH_RS) & OP_MASK_RS) == reg)
1447 if ((ip->insn_mo->pinfo & INSN_READ_GPR_T)
1448 && ((ip->insn_opcode >> OP_SH_RT) & OP_MASK_RT) == reg)
1453 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_X)
1454 && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_RX)
1455 & MIPS16OP_MASK_RX)]
1458 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_Y)
1459 && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_RY)
1460 & MIPS16OP_MASK_RY)]
1463 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_Z)
1464 && (mips16_to_32_reg_map[((ip->insn_opcode >> MIPS16OP_SH_MOVE32Z)
1465 & MIPS16OP_MASK_MOVE32Z)]
1468 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_T) && reg == TREG)
1470 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_SP) && reg == SP)
1472 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_31) && reg == RA)
1474 if ((ip->insn_mo->pinfo & MIPS16_INSN_READ_GPR_X)
1475 && ((ip->insn_opcode >> MIPS16OP_SH_REGR32)
1476 & MIPS16OP_MASK_REGR32) == reg)
1483 /* This function returns true if modifying a register requires a
1487 reg_needs_delay (reg)
1490 unsigned long prev_pinfo;
1492 prev_pinfo = prev_insn.insn_mo->pinfo;
1493 if (! mips_opts.noreorder
1494 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1495 && ((prev_pinfo & INSN_LOAD_COPROC_DELAY)
1496 || (! gpr_interlocks
1497 && (prev_pinfo & INSN_LOAD_MEMORY_DELAY))))
1499 /* A load from a coprocessor or from memory. All load
1500 delays delay the use of general register rt for one
1501 instruction on the r3000. The r6000 and r4000 use
1503 /* Itbl support may require additional care here. */
1504 know (prev_pinfo & INSN_WRITE_GPR_T);
1505 if (reg == ((prev_insn.insn_opcode >> OP_SH_RT) & OP_MASK_RT))
1512 /* Mark instruction labels in mips16 mode. This permits the linker to
1513 handle them specially, such as generating jalx instructions when
1514 needed. We also make them odd for the duration of the assembly, in
1515 order to generate the right sort of code. We will make them even
1516 in the adjust_symtab routine, while leaving them marked. This is
1517 convenient for the debugger and the disassembler. The linker knows
1518 to make them odd again. */
1521 mips16_mark_labels ()
1523 if (mips_opts.mips16)
1525 struct insn_label_list *l;
1528 for (l = insn_labels; l != NULL; l = l->next)
1531 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
1532 S_SET_OTHER (l->label, STO_MIPS16);
1534 val = S_GET_VALUE (l->label);
1536 S_SET_VALUE (l->label, val + 1);
1541 /* Output an instruction. PLACE is where to put the instruction; if
1542 it is NULL, this uses frag_more to get room. IP is the instruction
1543 information. ADDRESS_EXPR is an operand of the instruction to be
1544 used with RELOC_TYPE. */
1547 append_insn (place, ip, address_expr, reloc_type, unmatched_hi)
1549 struct mips_cl_insn *ip;
1550 expressionS *address_expr;
1551 bfd_reloc_code_real_type *reloc_type;
1552 boolean unmatched_hi;
1554 register unsigned long prev_pinfo, pinfo;
1559 /* Mark instruction labels in mips16 mode. */
1560 if (mips_opts.mips16)
1561 mips16_mark_labels ();
1563 prev_pinfo = prev_insn.insn_mo->pinfo;
1564 pinfo = ip->insn_mo->pinfo;
1566 if (place == NULL && (! mips_opts.noreorder || prev_nop_frag != NULL))
1570 /* If the previous insn required any delay slots, see if we need
1571 to insert a NOP or two. There are eight kinds of possible
1572 hazards, of which an instruction can have at most one type.
1573 (1) a load from memory delay
1574 (2) a load from a coprocessor delay
1575 (3) an unconditional branch delay
1576 (4) a conditional branch delay
1577 (5) a move to coprocessor register delay
1578 (6) a load coprocessor register from memory delay
1579 (7) a coprocessor condition code delay
1580 (8) a HI/LO special register delay
1582 There are a lot of optimizations we could do that we don't.
1583 In particular, we do not, in general, reorder instructions.
1584 If you use gcc with optimization, it will reorder
1585 instructions and generally do much more optimization then we
1586 do here; repeating all that work in the assembler would only
1587 benefit hand written assembly code, and does not seem worth
1590 /* This is how a NOP is emitted. */
1591 #define emit_nop() \
1593 ? md_number_to_chars (frag_more (2), 0x6500, 2) \
1594 : md_number_to_chars (frag_more (4), 0, 4))
1596 /* The previous insn might require a delay slot, depending upon
1597 the contents of the current insn. */
1598 if (! mips_opts.mips16
1599 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1600 && (((prev_pinfo & INSN_LOAD_COPROC_DELAY)
1601 && ! cop_interlocks)
1602 || (! gpr_interlocks
1603 && (prev_pinfo & INSN_LOAD_MEMORY_DELAY))))
1605 /* A load from a coprocessor or from memory. All load
1606 delays delay the use of general register rt for one
1607 instruction on the r3000. The r6000 and r4000 use
1609 /* Itbl support may require additional care here. */
1610 know (prev_pinfo & INSN_WRITE_GPR_T);
1611 if (mips_optimize == 0
1612 || insn_uses_reg (ip,
1613 ((prev_insn.insn_opcode >> OP_SH_RT)
1618 else if (! mips_opts.mips16
1619 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1620 && (((prev_pinfo & INSN_COPROC_MOVE_DELAY)
1621 && ! cop_interlocks)
1622 || (mips_opts.isa == ISA_MIPS1
1623 && (prev_pinfo & INSN_COPROC_MEMORY_DELAY))))
1625 /* A generic coprocessor delay. The previous instruction
1626 modified a coprocessor general or control register. If
1627 it modified a control register, we need to avoid any
1628 coprocessor instruction (this is probably not always
1629 required, but it sometimes is). If it modified a general
1630 register, we avoid using that register.
1632 On the r6000 and r4000 loading a coprocessor register
1633 from memory is interlocked, and does not require a delay.
1635 This case is not handled very well. There is no special
1636 knowledge of CP0 handling, and the coprocessors other
1637 than the floating point unit are not distinguished at
1639 /* Itbl support may require additional care here. FIXME!
1640 Need to modify this to include knowledge about
1641 user specified delays! */
1642 if (prev_pinfo & INSN_WRITE_FPR_T)
1644 if (mips_optimize == 0
1645 || insn_uses_reg (ip,
1646 ((prev_insn.insn_opcode >> OP_SH_FT)
1651 else if (prev_pinfo & INSN_WRITE_FPR_S)
1653 if (mips_optimize == 0
1654 || insn_uses_reg (ip,
1655 ((prev_insn.insn_opcode >> OP_SH_FS)
1662 /* We don't know exactly what the previous instruction
1663 does. If the current instruction uses a coprocessor
1664 register, we must insert a NOP. If previous
1665 instruction may set the condition codes, and the
1666 current instruction uses them, we must insert two
1668 /* Itbl support may require additional care here. */
1669 if (mips_optimize == 0
1670 || ((prev_pinfo & INSN_WRITE_COND_CODE)
1671 && (pinfo & INSN_READ_COND_CODE)))
1673 else if (pinfo & INSN_COP)
1677 else if (! mips_opts.mips16
1678 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1679 && (prev_pinfo & INSN_WRITE_COND_CODE)
1680 && ! cop_interlocks)
1682 /* The previous instruction sets the coprocessor condition
1683 codes, but does not require a general coprocessor delay
1684 (this means it is a floating point comparison
1685 instruction). If this instruction uses the condition
1686 codes, we need to insert a single NOP. */
1687 /* Itbl support may require additional care here. */
1688 if (mips_optimize == 0
1689 || (pinfo & INSN_READ_COND_CODE))
1693 /* If we're fixing up mfhi/mflo for the r7000 and the
1694 previous insn was an mfhi/mflo and the current insn
1695 reads the register that the mfhi/mflo wrote to, then
1698 else if (mips_7000_hilo_fix
1699 && MF_HILO_INSN (prev_pinfo)
1700 && insn_uses_reg (ip, ((prev_insn.insn_opcode >> OP_SH_RD)
1707 /* If we're fixing up mfhi/mflo for the r7000 and the
1708 2nd previous insn was an mfhi/mflo and the current insn
1709 reads the register that the mfhi/mflo wrote to, then
1712 else if (mips_7000_hilo_fix
1713 && MF_HILO_INSN (prev_prev_insn.insn_opcode)
1714 && insn_uses_reg (ip, ((prev_prev_insn.insn_opcode >> OP_SH_RD)
1722 else if (prev_pinfo & INSN_READ_LO)
1724 /* The previous instruction reads the LO register; if the
1725 current instruction writes to the LO register, we must
1726 insert two NOPS. Some newer processors have interlocks.
1727 Also the tx39's multiply instructions can be exectuted
1728 immediatly after a read from HI/LO (without the delay),
1729 though the tx39's divide insns still do require the
1731 if (! (hilo_interlocks
1732 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT)))
1733 && (mips_optimize == 0
1734 || (pinfo & INSN_WRITE_LO)))
1736 /* Most mips16 branch insns don't have a delay slot.
1737 If a read from LO is immediately followed by a branch
1738 to a write to LO we have a read followed by a write
1739 less than 2 insns away. We assume the target of
1740 a branch might be a write to LO, and insert a nop
1741 between a read and an immediately following branch. */
1742 else if (mips_opts.mips16
1743 && (mips_optimize == 0
1744 || (pinfo & MIPS16_INSN_BRANCH)))
1747 else if (prev_insn.insn_mo->pinfo & INSN_READ_HI)
1749 /* The previous instruction reads the HI register; if the
1750 current instruction writes to the HI register, we must
1751 insert a NOP. Some newer processors have interlocks.
1752 Also the note tx39's multiply above. */
1753 if (! (hilo_interlocks
1754 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT)))
1755 && (mips_optimize == 0
1756 || (pinfo & INSN_WRITE_HI)))
1758 /* Most mips16 branch insns don't have a delay slot.
1759 If a read from HI is immediately followed by a branch
1760 to a write to HI we have a read followed by a write
1761 less than 2 insns away. We assume the target of
1762 a branch might be a write to HI, and insert a nop
1763 between a read and an immediately following branch. */
1764 else if (mips_opts.mips16
1765 && (mips_optimize == 0
1766 || (pinfo & MIPS16_INSN_BRANCH)))
1770 /* If the previous instruction was in a noreorder section, then
1771 we don't want to insert the nop after all. */
1772 /* Itbl support may require additional care here. */
1773 if (prev_insn_unreordered)
1776 /* There are two cases which require two intervening
1777 instructions: 1) setting the condition codes using a move to
1778 coprocessor instruction which requires a general coprocessor
1779 delay and then reading the condition codes 2) reading the HI
1780 or LO register and then writing to it (except on processors
1781 which have interlocks). If we are not already emitting a NOP
1782 instruction, we must check for these cases compared to the
1783 instruction previous to the previous instruction. */
1784 if ((! mips_opts.mips16
1785 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
1786 && (prev_prev_insn.insn_mo->pinfo & INSN_COPROC_MOVE_DELAY)
1787 && (prev_prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE)
1788 && (pinfo & INSN_READ_COND_CODE)
1789 && ! cop_interlocks)
1790 || ((prev_prev_insn.insn_mo->pinfo & INSN_READ_LO)
1791 && (pinfo & INSN_WRITE_LO)
1792 && ! (hilo_interlocks
1793 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT))))
1794 || ((prev_prev_insn.insn_mo->pinfo & INSN_READ_HI)
1795 && (pinfo & INSN_WRITE_HI)
1796 && ! (hilo_interlocks
1797 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT)))))
1802 if (prev_prev_insn_unreordered)
1805 if (prev_prev_nop && nops == 0)
1808 /* If we are being given a nop instruction, don't bother with
1809 one of the nops we would otherwise output. This will only
1810 happen when a nop instruction is used with mips_optimize set
1813 && ! mips_opts.noreorder
1814 && ip->insn_opcode == (unsigned) (mips_opts.mips16 ? 0x6500 : 0))
1817 /* Now emit the right number of NOP instructions. */
1818 if (nops > 0 && ! mips_opts.noreorder)
1821 unsigned long old_frag_offset;
1823 struct insn_label_list *l;
1825 old_frag = frag_now;
1826 old_frag_offset = frag_now_fix ();
1828 for (i = 0; i < nops; i++)
1833 listing_prev_line ();
1834 /* We may be at the start of a variant frag. In case we
1835 are, make sure there is enough space for the frag
1836 after the frags created by listing_prev_line. The
1837 argument to frag_grow here must be at least as large
1838 as the argument to all other calls to frag_grow in
1839 this file. We don't have to worry about being in the
1840 middle of a variant frag, because the variants insert
1841 all needed nop instructions themselves. */
1845 for (l = insn_labels; l != NULL; l = l->next)
1849 assert (S_GET_SEGMENT (l->label) == now_seg);
1850 symbol_set_frag (l->label, frag_now);
1851 val = (valueT) frag_now_fix ();
1852 /* mips16 text labels are stored as odd. */
1853 if (mips_opts.mips16)
1855 S_SET_VALUE (l->label, val);
1858 #ifndef NO_ECOFF_DEBUGGING
1859 if (ECOFF_DEBUGGING)
1860 ecoff_fix_loc (old_frag, old_frag_offset);
1863 else if (prev_nop_frag != NULL)
1865 /* We have a frag holding nops we may be able to remove. If
1866 we don't need any nops, we can decrease the size of
1867 prev_nop_frag by the size of one instruction. If we do
1868 need some nops, we count them in prev_nops_required. */
1869 if (prev_nop_frag_since == 0)
1873 prev_nop_frag->fr_fix -= mips_opts.mips16 ? 2 : 4;
1874 --prev_nop_frag_holds;
1877 prev_nop_frag_required += nops;
1881 if (prev_prev_nop == 0)
1883 prev_nop_frag->fr_fix -= mips_opts.mips16 ? 2 : 4;
1884 --prev_nop_frag_holds;
1887 ++prev_nop_frag_required;
1890 if (prev_nop_frag_holds <= prev_nop_frag_required)
1891 prev_nop_frag = NULL;
1893 ++prev_nop_frag_since;
1895 /* Sanity check: by the time we reach the second instruction
1896 after prev_nop_frag, we should have used up all the nops
1897 one way or another. */
1898 assert (prev_nop_frag_since <= 1 || prev_nop_frag == NULL);
1902 if (*reloc_type > BFD_RELOC_UNUSED)
1904 /* We need to set up a variant frag. */
1905 assert (mips_opts.mips16 && address_expr != NULL);
1906 f = frag_var (rs_machine_dependent, 4, 0,
1907 RELAX_MIPS16_ENCODE (*reloc_type - BFD_RELOC_UNUSED,
1908 mips16_small, mips16_ext,
1910 & INSN_UNCOND_BRANCH_DELAY),
1911 (*prev_insn_reloc_type
1912 == BFD_RELOC_MIPS16_JMP)),
1913 make_expr_symbol (address_expr), 0, NULL);
1915 else if (place != NULL)
1917 else if (mips_opts.mips16
1919 && *reloc_type != BFD_RELOC_MIPS16_JMP)
1921 /* Make sure there is enough room to swap this instruction with
1922 a following jump instruction. */
1928 if (mips_opts.mips16
1929 && mips_opts.noreorder
1930 && (prev_pinfo & INSN_UNCOND_BRANCH_DELAY) != 0)
1931 as_warn (_("extended instruction in delay slot"));
1936 fixp[0] = fixp[1] = fixp[2] = NULL;
1937 if (address_expr != NULL && *reloc_type < BFD_RELOC_UNUSED)
1939 if (address_expr->X_op == O_constant)
1943 switch (*reloc_type)
1946 ip->insn_opcode |= address_expr->X_add_number;
1949 case BFD_RELOC_MIPS_HIGHEST:
1950 tmp = (address_expr->X_add_number + 0x800080008000) >> 16;
1952 ip->insn_opcode |= (tmp >> 16) & 0xffff;
1955 case BFD_RELOC_MIPS_HIGHER:
1956 tmp = (address_expr->X_add_number + 0x80008000) >> 16;
1957 ip->insn_opcode |= (tmp >> 16) & 0xffff;
1960 case BFD_RELOC_HI16_S:
1961 ip->insn_opcode |= ((address_expr->X_add_number + 0x8000)
1965 case BFD_RELOC_HI16:
1966 ip->insn_opcode |= (address_expr->X_add_number >> 16) & 0xffff;
1969 case BFD_RELOC_LO16:
1970 ip->insn_opcode |= address_expr->X_add_number & 0xffff;
1973 case BFD_RELOC_MIPS_JMP:
1974 if ((address_expr->X_add_number & 3) != 0)
1975 as_bad (_("jump to misaligned address (0x%lx)"),
1976 (unsigned long) address_expr->X_add_number);
1977 if (address_expr->X_add_number & ~0xfffffff
1978 || address_expr->X_add_number > 0x7fffffc)
1979 as_bad (_("jump address range overflow (0x%lx)"),
1980 (unsigned long) address_expr->X_add_number);
1981 ip->insn_opcode |= (address_expr->X_add_number >> 2) & 0x3ffffff;
1984 case BFD_RELOC_MIPS16_JMP:
1985 if ((address_expr->X_add_number & 3) != 0)
1986 as_bad (_("jump to misaligned address (0x%lx)"),
1987 (unsigned long) address_expr->X_add_number);
1988 if (address_expr->X_add_number & ~0xfffffff
1989 || address_expr->X_add_number > 0x7fffffc)
1990 as_bad (_("jump address range overflow (0x%lx)"),
1991 (unsigned long) address_expr->X_add_number);
1993 (((address_expr->X_add_number & 0x7c0000) << 3)
1994 | ((address_expr->X_add_number & 0xf800000) >> 7)
1995 | ((address_expr->X_add_number & 0x3fffc) >> 2));
1998 case BFD_RELOC_16_PCREL:
1999 ip->insn_opcode |= address_expr->X_add_number & 0xffff;
2002 case BFD_RELOC_16_PCREL_S2:
2012 /* Don't generate a reloc if we are writing into a variant frag. */
2015 fixp[0] = fix_new_exp (frag_now, f - frag_now->fr_literal, 4,
2017 (*reloc_type == BFD_RELOC_16_PCREL
2018 || *reloc_type == BFD_RELOC_16_PCREL_S2),
2021 /* These relocations can have an addend that won't fit in
2022 4 octets for 64bit assembly. */
2023 if (HAVE_64BIT_GPRS &&
2024 (*reloc_type == BFD_RELOC_16
2025 || *reloc_type == BFD_RELOC_32
2026 || *reloc_type == BFD_RELOC_MIPS_JMP
2027 || *reloc_type == BFD_RELOC_HI16_S
2028 || *reloc_type == BFD_RELOC_LO16
2029 || *reloc_type == BFD_RELOC_GPREL16
2030 || *reloc_type == BFD_RELOC_MIPS_LITERAL
2031 || *reloc_type == BFD_RELOC_GPREL32
2032 || *reloc_type == BFD_RELOC_64
2033 || *reloc_type == BFD_RELOC_CTOR
2034 || *reloc_type == BFD_RELOC_MIPS_SUB
2035 || *reloc_type == BFD_RELOC_MIPS_HIGHEST
2036 || *reloc_type == BFD_RELOC_MIPS_HIGHER
2037 || *reloc_type == BFD_RELOC_MIPS_SCN_DISP
2038 || *reloc_type == BFD_RELOC_MIPS_REL16
2039 || *reloc_type == BFD_RELOC_MIPS_RELGOT))
2040 fixp[0]->fx_no_overflow = 1;
2044 struct mips_hi_fixup *hi_fixup;
2046 assert (*reloc_type == BFD_RELOC_HI16_S);
2047 hi_fixup = ((struct mips_hi_fixup *)
2048 xmalloc (sizeof (struct mips_hi_fixup)));
2049 hi_fixup->fixp = fixp[0];
2050 hi_fixup->seg = now_seg;
2051 hi_fixup->next = mips_hi_fixup_list;
2052 mips_hi_fixup_list = hi_fixup;
2055 if (reloc_type[1] != BFD_RELOC_UNUSED)
2057 /* FIXME: This symbol can be one of
2058 RSS_UNDEF, RSS_GP, RSS_GP0, RSS_LOC. */
2059 address_expr->X_op = O_absent;
2060 address_expr->X_add_symbol = 0;
2061 address_expr->X_add_number = 0;
2063 fixp[1] = fix_new_exp (frag_now, f - frag_now->fr_literal,
2064 4, address_expr, false,
2067 /* These relocations can have an addend that won't fit in
2068 4 octets for 64bit assembly. */
2069 if (HAVE_64BIT_GPRS &&
2070 (*reloc_type == BFD_RELOC_16
2071 || *reloc_type == BFD_RELOC_32
2072 || *reloc_type == BFD_RELOC_MIPS_JMP
2073 || *reloc_type == BFD_RELOC_HI16_S
2074 || *reloc_type == BFD_RELOC_LO16
2075 || *reloc_type == BFD_RELOC_GPREL16
2076 || *reloc_type == BFD_RELOC_MIPS_LITERAL
2077 || *reloc_type == BFD_RELOC_GPREL32
2078 || *reloc_type == BFD_RELOC_64
2079 || *reloc_type == BFD_RELOC_CTOR
2080 || *reloc_type == BFD_RELOC_MIPS_SUB
2081 || *reloc_type == BFD_RELOC_MIPS_HIGHEST
2082 || *reloc_type == BFD_RELOC_MIPS_HIGHER
2083 || *reloc_type == BFD_RELOC_MIPS_SCN_DISP
2084 || *reloc_type == BFD_RELOC_MIPS_REL16
2085 || *reloc_type == BFD_RELOC_MIPS_RELGOT))
2086 fixp[1]->fx_no_overflow = 1;
2088 if (reloc_type[2] != BFD_RELOC_UNUSED)
2090 address_expr->X_op = O_absent;
2091 address_expr->X_add_symbol = 0;
2092 address_expr->X_add_number = 0;
2094 fixp[2] = fix_new_exp (frag_now,
2095 f - frag_now->fr_literal, 4,
2096 address_expr, false,
2099 /* These relocations can have an addend that won't fit in
2100 4 octets for 64bit assembly. */
2101 if (HAVE_64BIT_GPRS &&
2102 (*reloc_type == BFD_RELOC_16
2103 || *reloc_type == BFD_RELOC_32
2104 || *reloc_type == BFD_RELOC_MIPS_JMP
2105 || *reloc_type == BFD_RELOC_HI16_S
2106 || *reloc_type == BFD_RELOC_LO16
2107 || *reloc_type == BFD_RELOC_GPREL16
2108 || *reloc_type == BFD_RELOC_MIPS_LITERAL
2109 || *reloc_type == BFD_RELOC_GPREL32
2110 || *reloc_type == BFD_RELOC_64
2111 || *reloc_type == BFD_RELOC_CTOR
2112 || *reloc_type == BFD_RELOC_MIPS_SUB
2113 || *reloc_type == BFD_RELOC_MIPS_HIGHEST
2114 || *reloc_type == BFD_RELOC_MIPS_HIGHER
2115 || *reloc_type == BFD_RELOC_MIPS_SCN_DISP
2116 || *reloc_type == BFD_RELOC_MIPS_REL16
2117 || *reloc_type == BFD_RELOC_MIPS_RELGOT))
2118 fixp[2]->fx_no_overflow = 1;
2125 if (! mips_opts.mips16)
2126 md_number_to_chars (f, ip->insn_opcode, 4);
2127 else if (*reloc_type == BFD_RELOC_MIPS16_JMP)
2129 md_number_to_chars (f, ip->insn_opcode >> 16, 2);
2130 md_number_to_chars (f + 2, ip->insn_opcode & 0xffff, 2);
2136 md_number_to_chars (f, 0xf000 | ip->extend, 2);
2139 md_number_to_chars (f, ip->insn_opcode, 2);
2142 /* Update the register mask information. */
2143 if (! mips_opts.mips16)
2145 if (pinfo & INSN_WRITE_GPR_D)
2146 mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD);
2147 if ((pinfo & (INSN_WRITE_GPR_T | INSN_READ_GPR_T)) != 0)
2148 mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RT) & OP_MASK_RT);
2149 if (pinfo & INSN_READ_GPR_S)
2150 mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RS) & OP_MASK_RS);
2151 if (pinfo & INSN_WRITE_GPR_31)
2152 mips_gprmask |= 1 << 31;
2153 if (pinfo & INSN_WRITE_FPR_D)
2154 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FD) & OP_MASK_FD);
2155 if ((pinfo & (INSN_WRITE_FPR_S | INSN_READ_FPR_S)) != 0)
2156 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FS) & OP_MASK_FS);
2157 if ((pinfo & (INSN_WRITE_FPR_T | INSN_READ_FPR_T)) != 0)
2158 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FT) & OP_MASK_FT);
2159 if ((pinfo & INSN_READ_FPR_R) != 0)
2160 mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FR) & OP_MASK_FR);
2161 if (pinfo & INSN_COP)
2163 /* We don't keep enough information to sort these cases out.
2164 The itbl support does keep this information however, although
2165 we currently don't support itbl fprmats as part of the cop
2166 instruction. May want to add this support in the future. */
2168 /* Never set the bit for $0, which is always zero. */
2169 mips_gprmask &= ~1 << 0;
2173 if (pinfo & (MIPS16_INSN_WRITE_X | MIPS16_INSN_READ_X))
2174 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RX)
2175 & MIPS16OP_MASK_RX);
2176 if (pinfo & (MIPS16_INSN_WRITE_Y | MIPS16_INSN_READ_Y))
2177 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RY)
2178 & MIPS16OP_MASK_RY);
2179 if (pinfo & MIPS16_INSN_WRITE_Z)
2180 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_RZ)
2181 & MIPS16OP_MASK_RZ);
2182 if (pinfo & (MIPS16_INSN_WRITE_T | MIPS16_INSN_READ_T))
2183 mips_gprmask |= 1 << TREG;
2184 if (pinfo & (MIPS16_INSN_WRITE_SP | MIPS16_INSN_READ_SP))
2185 mips_gprmask |= 1 << SP;
2186 if (pinfo & (MIPS16_INSN_WRITE_31 | MIPS16_INSN_READ_31))
2187 mips_gprmask |= 1 << RA;
2188 if (pinfo & MIPS16_INSN_WRITE_GPR_Y)
2189 mips_gprmask |= 1 << MIPS16OP_EXTRACT_REG32R (ip->insn_opcode);
2190 if (pinfo & MIPS16_INSN_READ_Z)
2191 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_MOVE32Z)
2192 & MIPS16OP_MASK_MOVE32Z);
2193 if (pinfo & MIPS16_INSN_READ_GPR_X)
2194 mips_gprmask |= 1 << ((ip->insn_opcode >> MIPS16OP_SH_REGR32)
2195 & MIPS16OP_MASK_REGR32);
2198 if (place == NULL && ! mips_opts.noreorder)
2200 /* Filling the branch delay slot is more complex. We try to
2201 switch the branch with the previous instruction, which we can
2202 do if the previous instruction does not set up a condition
2203 that the branch tests and if the branch is not itself the
2204 target of any branch. */
2205 if ((pinfo & INSN_UNCOND_BRANCH_DELAY)
2206 || (pinfo & INSN_COND_BRANCH_DELAY))
2208 if (mips_optimize < 2
2209 /* If we have seen .set volatile or .set nomove, don't
2211 || mips_opts.nomove != 0
2212 /* If we had to emit any NOP instructions, then we
2213 already know we can not swap. */
2215 /* If we don't even know the previous insn, we can not
2217 || ! prev_insn_valid
2218 /* If the previous insn is already in a branch delay
2219 slot, then we can not swap. */
2220 || prev_insn_is_delay_slot
2221 /* If the previous previous insn was in a .set
2222 noreorder, we can't swap. Actually, the MIPS
2223 assembler will swap in this situation. However, gcc
2224 configured -with-gnu-as will generate code like
2230 in which we can not swap the bne and INSN. If gcc is
2231 not configured -with-gnu-as, it does not output the
2232 .set pseudo-ops. We don't have to check
2233 prev_insn_unreordered, because prev_insn_valid will
2234 be 0 in that case. We don't want to use
2235 prev_prev_insn_valid, because we do want to be able
2236 to swap at the start of a function. */
2237 || prev_prev_insn_unreordered
2238 /* If the branch is itself the target of a branch, we
2239 can not swap. We cheat on this; all we check for is
2240 whether there is a label on this instruction. If
2241 there are any branches to anything other than a
2242 label, users must use .set noreorder. */
2243 || insn_labels != NULL
2244 /* If the previous instruction is in a variant frag, we
2245 can not do the swap. This does not apply to the
2246 mips16, which uses variant frags for different
2248 || (! mips_opts.mips16
2249 && prev_insn_frag->fr_type == rs_machine_dependent)
2250 /* If the branch reads the condition codes, we don't
2251 even try to swap, because in the sequence
2256 we can not swap, and I don't feel like handling that
2258 || (! mips_opts.mips16
2259 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2260 && (pinfo & INSN_READ_COND_CODE))
2261 /* We can not swap with an instruction that requires a
2262 delay slot, becase the target of the branch might
2263 interfere with that instruction. */
2264 || (! mips_opts.mips16
2265 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2267 /* Itbl support may require additional care here. */
2268 & (INSN_LOAD_COPROC_DELAY
2269 | INSN_COPROC_MOVE_DELAY
2270 | INSN_WRITE_COND_CODE)))
2271 || (! (hilo_interlocks
2272 || (mips_tune == CPU_R3900 && (pinfo & INSN_MULT)))
2276 || (! mips_opts.mips16
2278 && (prev_pinfo & INSN_LOAD_MEMORY_DELAY))
2279 || (! mips_opts.mips16
2280 && mips_opts.isa == ISA_MIPS1
2281 /* Itbl support may require additional care here. */
2282 && (prev_pinfo & INSN_COPROC_MEMORY_DELAY))
2283 /* We can not swap with a branch instruction. */
2285 & (INSN_UNCOND_BRANCH_DELAY
2286 | INSN_COND_BRANCH_DELAY
2287 | INSN_COND_BRANCH_LIKELY))
2288 /* We do not swap with a trap instruction, since it
2289 complicates trap handlers to have the trap
2290 instruction be in a delay slot. */
2291 || (prev_pinfo & INSN_TRAP)
2292 /* If the branch reads a register that the previous
2293 instruction sets, we can not swap. */
2294 || (! mips_opts.mips16
2295 && (prev_pinfo & INSN_WRITE_GPR_T)
2296 && insn_uses_reg (ip,
2297 ((prev_insn.insn_opcode >> OP_SH_RT)
2300 || (! mips_opts.mips16
2301 && (prev_pinfo & INSN_WRITE_GPR_D)
2302 && insn_uses_reg (ip,
2303 ((prev_insn.insn_opcode >> OP_SH_RD)
2306 || (mips_opts.mips16
2307 && (((prev_pinfo & MIPS16_INSN_WRITE_X)
2308 && insn_uses_reg (ip,
2309 ((prev_insn.insn_opcode
2311 & MIPS16OP_MASK_RX),
2313 || ((prev_pinfo & MIPS16_INSN_WRITE_Y)
2314 && insn_uses_reg (ip,
2315 ((prev_insn.insn_opcode
2317 & MIPS16OP_MASK_RY),
2319 || ((prev_pinfo & MIPS16_INSN_WRITE_Z)
2320 && insn_uses_reg (ip,
2321 ((prev_insn.insn_opcode
2323 & MIPS16OP_MASK_RZ),
2325 || ((prev_pinfo & MIPS16_INSN_WRITE_T)
2326 && insn_uses_reg (ip, TREG, MIPS_GR_REG))
2327 || ((prev_pinfo & MIPS16_INSN_WRITE_31)
2328 && insn_uses_reg (ip, RA, MIPS_GR_REG))
2329 || ((prev_pinfo & MIPS16_INSN_WRITE_GPR_Y)
2330 && insn_uses_reg (ip,
2331 MIPS16OP_EXTRACT_REG32R (prev_insn.
2334 /* If the branch writes a register that the previous
2335 instruction sets, we can not swap (we know that
2336 branches write only to RD or to $31). */
2337 || (! mips_opts.mips16
2338 && (prev_pinfo & INSN_WRITE_GPR_T)
2339 && (((pinfo & INSN_WRITE_GPR_D)
2340 && (((prev_insn.insn_opcode >> OP_SH_RT) & OP_MASK_RT)
2341 == ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD)))
2342 || ((pinfo & INSN_WRITE_GPR_31)
2343 && (((prev_insn.insn_opcode >> OP_SH_RT)
2346 || (! mips_opts.mips16
2347 && (prev_pinfo & INSN_WRITE_GPR_D)
2348 && (((pinfo & INSN_WRITE_GPR_D)
2349 && (((prev_insn.insn_opcode >> OP_SH_RD) & OP_MASK_RD)
2350 == ((ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD)))
2351 || ((pinfo & INSN_WRITE_GPR_31)
2352 && (((prev_insn.insn_opcode >> OP_SH_RD)
2355 || (mips_opts.mips16
2356 && (pinfo & MIPS16_INSN_WRITE_31)
2357 && ((prev_pinfo & MIPS16_INSN_WRITE_31)
2358 || ((prev_pinfo & MIPS16_INSN_WRITE_GPR_Y)
2359 && (MIPS16OP_EXTRACT_REG32R (prev_insn.insn_opcode)
2361 /* If the branch writes a register that the previous
2362 instruction reads, we can not swap (we know that
2363 branches only write to RD or to $31). */
2364 || (! mips_opts.mips16
2365 && (pinfo & INSN_WRITE_GPR_D)
2366 && insn_uses_reg (&prev_insn,
2367 ((ip->insn_opcode >> OP_SH_RD)
2370 || (! mips_opts.mips16
2371 && (pinfo & INSN_WRITE_GPR_31)
2372 && insn_uses_reg (&prev_insn, 31, MIPS_GR_REG))
2373 || (mips_opts.mips16
2374 && (pinfo & MIPS16_INSN_WRITE_31)
2375 && insn_uses_reg (&prev_insn, RA, MIPS_GR_REG))
2376 /* If we are generating embedded PIC code, the branch
2377 might be expanded into a sequence which uses $at, so
2378 we can't swap with an instruction which reads it. */
2379 || (mips_pic == EMBEDDED_PIC
2380 && insn_uses_reg (&prev_insn, AT, MIPS_GR_REG))
2381 /* If the previous previous instruction has a load
2382 delay, and sets a register that the branch reads, we
2384 || (! mips_opts.mips16
2385 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2386 /* Itbl support may require additional care here. */
2387 && ((prev_prev_insn.insn_mo->pinfo & INSN_LOAD_COPROC_DELAY)
2388 || (! gpr_interlocks
2389 && (prev_prev_insn.insn_mo->pinfo
2390 & INSN_LOAD_MEMORY_DELAY)))
2391 && insn_uses_reg (ip,
2392 ((prev_prev_insn.insn_opcode >> OP_SH_RT)
2395 /* If one instruction sets a condition code and the
2396 other one uses a condition code, we can not swap. */
2397 || ((pinfo & INSN_READ_COND_CODE)
2398 && (prev_pinfo & INSN_WRITE_COND_CODE))
2399 || ((pinfo & INSN_WRITE_COND_CODE)
2400 && (prev_pinfo & INSN_READ_COND_CODE))
2401 /* If the previous instruction uses the PC, we can not
2403 || (mips_opts.mips16
2404 && (prev_pinfo & MIPS16_INSN_READ_PC))
2405 /* If the previous instruction was extended, we can not
2407 || (mips_opts.mips16 && prev_insn_extended)
2408 /* If the previous instruction had a fixup in mips16
2409 mode, we can not swap. This normally means that the
2410 previous instruction was a 4 byte branch anyhow. */
2411 || (mips_opts.mips16 && prev_insn_fixp[0])
2412 /* If the previous instruction is a sync, sync.l, or
2413 sync.p, we can not swap. */
2414 || (prev_pinfo & INSN_SYNC))
2416 /* We could do even better for unconditional branches to
2417 portions of this object file; we could pick up the
2418 instruction at the destination, put it in the delay
2419 slot, and bump the destination address. */
2421 /* Update the previous insn information. */
2422 prev_prev_insn = *ip;
2423 prev_insn.insn_mo = &dummy_opcode;
2427 /* It looks like we can actually do the swap. */
2428 if (! mips_opts.mips16)
2433 prev_f = prev_insn_frag->fr_literal + prev_insn_where;
2434 memcpy (temp, prev_f, 4);
2435 memcpy (prev_f, f, 4);
2436 memcpy (f, temp, 4);
2437 if (prev_insn_fixp[0])
2439 prev_insn_fixp[0]->fx_frag = frag_now;
2440 prev_insn_fixp[0]->fx_where = f - frag_now->fr_literal;
2442 if (prev_insn_fixp[1])
2444 prev_insn_fixp[1]->fx_frag = frag_now;
2445 prev_insn_fixp[1]->fx_where = f - frag_now->fr_literal;
2447 if (prev_insn_fixp[2])
2449 prev_insn_fixp[2]->fx_frag = frag_now;
2450 prev_insn_fixp[2]->fx_where = f - frag_now->fr_literal;
2454 fixp[0]->fx_frag = prev_insn_frag;
2455 fixp[0]->fx_where = prev_insn_where;
2459 fixp[1]->fx_frag = prev_insn_frag;
2460 fixp[1]->fx_where = prev_insn_where;
2464 fixp[2]->fx_frag = prev_insn_frag;
2465 fixp[2]->fx_where = prev_insn_where;
2473 assert (prev_insn_fixp[0] == NULL);
2474 assert (prev_insn_fixp[1] == NULL);
2475 assert (prev_insn_fixp[2] == NULL);
2476 prev_f = prev_insn_frag->fr_literal + prev_insn_where;
2477 memcpy (temp, prev_f, 2);
2478 memcpy (prev_f, f, 2);
2479 if (*reloc_type != BFD_RELOC_MIPS16_JMP)
2481 assert (*reloc_type == BFD_RELOC_UNUSED);
2482 memcpy (f, temp, 2);
2486 memcpy (f, f + 2, 2);
2487 memcpy (f + 2, temp, 2);
2491 fixp[0]->fx_frag = prev_insn_frag;
2492 fixp[0]->fx_where = prev_insn_where;
2496 fixp[1]->fx_frag = prev_insn_frag;
2497 fixp[1]->fx_where = prev_insn_where;
2501 fixp[2]->fx_frag = prev_insn_frag;
2502 fixp[2]->fx_where = prev_insn_where;
2506 /* Update the previous insn information; leave prev_insn
2508 prev_prev_insn = *ip;
2510 prev_insn_is_delay_slot = 1;
2512 /* If that was an unconditional branch, forget the previous
2513 insn information. */
2514 if (pinfo & INSN_UNCOND_BRANCH_DELAY)
2516 prev_prev_insn.insn_mo = &dummy_opcode;
2517 prev_insn.insn_mo = &dummy_opcode;
2520 prev_insn_fixp[0] = NULL;
2521 prev_insn_fixp[1] = NULL;
2522 prev_insn_fixp[2] = NULL;
2523 prev_insn_reloc_type[0] = BFD_RELOC_UNUSED;
2524 prev_insn_reloc_type[1] = BFD_RELOC_UNUSED;
2525 prev_insn_reloc_type[2] = BFD_RELOC_UNUSED;
2526 prev_insn_extended = 0;
2528 else if (pinfo & INSN_COND_BRANCH_LIKELY)
2530 /* We don't yet optimize a branch likely. What we should do
2531 is look at the target, copy the instruction found there
2532 into the delay slot, and increment the branch to jump to
2533 the next instruction. */
2535 /* Update the previous insn information. */
2536 prev_prev_insn = *ip;
2537 prev_insn.insn_mo = &dummy_opcode;
2538 prev_insn_fixp[0] = NULL;
2539 prev_insn_fixp[1] = NULL;
2540 prev_insn_fixp[2] = NULL;
2541 prev_insn_reloc_type[0] = BFD_RELOC_UNUSED;
2542 prev_insn_reloc_type[1] = BFD_RELOC_UNUSED;
2543 prev_insn_reloc_type[2] = BFD_RELOC_UNUSED;
2544 prev_insn_extended = 0;
2548 /* Update the previous insn information. */
2550 prev_prev_insn.insn_mo = &dummy_opcode;
2552 prev_prev_insn = prev_insn;
2555 /* Any time we see a branch, we always fill the delay slot
2556 immediately; since this insn is not a branch, we know it
2557 is not in a delay slot. */
2558 prev_insn_is_delay_slot = 0;
2560 prev_insn_fixp[0] = fixp[0];
2561 prev_insn_fixp[1] = fixp[1];
2562 prev_insn_fixp[2] = fixp[2];
2563 prev_insn_reloc_type[0] = reloc_type[0];
2564 prev_insn_reloc_type[1] = reloc_type[1];
2565 prev_insn_reloc_type[2] = reloc_type[2];
2566 if (mips_opts.mips16)
2567 prev_insn_extended = (ip->use_extend
2568 || *reloc_type > BFD_RELOC_UNUSED);
2571 prev_prev_insn_unreordered = prev_insn_unreordered;
2572 prev_insn_unreordered = 0;
2573 prev_insn_frag = frag_now;
2574 prev_insn_where = f - frag_now->fr_literal;
2575 prev_insn_valid = 1;
2577 else if (place == NULL)
2579 /* We need to record a bit of information even when we are not
2580 reordering, in order to determine the base address for mips16
2581 PC relative relocs. */
2582 prev_prev_insn = prev_insn;
2584 prev_insn_reloc_type[0] = reloc_type[0];
2585 prev_insn_reloc_type[1] = reloc_type[1];
2586 prev_insn_reloc_type[2] = reloc_type[2];
2587 prev_prev_insn_unreordered = prev_insn_unreordered;
2588 prev_insn_unreordered = 1;
2591 /* We just output an insn, so the next one doesn't have a label. */
2592 mips_clear_insn_labels ();
2594 /* We must ensure that a fixup associated with an unmatched %hi
2595 reloc does not become a variant frag. Otherwise, the
2596 rearrangement of %hi relocs in frob_file may confuse
2600 frag_wane (frag_now);
2605 /* This function forgets that there was any previous instruction or
2606 label. If PRESERVE is non-zero, it remembers enough information to
2607 know whether nops are needed before a noreorder section. */
2610 mips_no_prev_insn (preserve)
2615 prev_insn.insn_mo = &dummy_opcode;
2616 prev_prev_insn.insn_mo = &dummy_opcode;
2617 prev_nop_frag = NULL;
2618 prev_nop_frag_holds = 0;
2619 prev_nop_frag_required = 0;
2620 prev_nop_frag_since = 0;
2622 prev_insn_valid = 0;
2623 prev_insn_is_delay_slot = 0;
2624 prev_insn_unreordered = 0;
2625 prev_insn_extended = 0;
2626 prev_insn_reloc_type[0] = BFD_RELOC_UNUSED;
2627 prev_insn_reloc_type[1] = BFD_RELOC_UNUSED;
2628 prev_insn_reloc_type[2] = BFD_RELOC_UNUSED;
2629 prev_prev_insn_unreordered = 0;
2630 mips_clear_insn_labels ();
2633 /* This function must be called whenever we turn on noreorder or emit
2634 something other than instructions. It inserts any NOPS which might
2635 be needed by the previous instruction, and clears the information
2636 kept for the previous instructions. The INSNS parameter is true if
2637 instructions are to follow. */
2640 mips_emit_delays (insns)
2643 if (! mips_opts.noreorder)
2648 if ((! mips_opts.mips16
2649 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2650 && (! cop_interlocks
2651 && (prev_insn.insn_mo->pinfo
2652 & (INSN_LOAD_COPROC_DELAY
2653 | INSN_COPROC_MOVE_DELAY
2654 | INSN_WRITE_COND_CODE))))
2655 || (! hilo_interlocks
2656 && (prev_insn.insn_mo->pinfo
2659 || (! mips_opts.mips16
2661 && (prev_insn.insn_mo->pinfo
2662 & INSN_LOAD_MEMORY_DELAY))
2663 || (! mips_opts.mips16
2664 && mips_opts.isa == ISA_MIPS1
2665 && (prev_insn.insn_mo->pinfo
2666 & INSN_COPROC_MEMORY_DELAY)))
2668 /* Itbl support may require additional care here. */
2670 if ((! mips_opts.mips16
2671 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2672 && (! cop_interlocks
2673 && prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE))
2674 || (! hilo_interlocks
2675 && ((prev_insn.insn_mo->pinfo & INSN_READ_HI)
2676 || (prev_insn.insn_mo->pinfo & INSN_READ_LO))))
2679 if (prev_insn_unreordered)
2682 else if ((! mips_opts.mips16
2683 && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
2684 && (! cop_interlocks
2685 && prev_prev_insn.insn_mo->pinfo & INSN_WRITE_COND_CODE))
2686 || (! hilo_interlocks
2687 && ((prev_prev_insn.insn_mo->pinfo & INSN_READ_HI)
2688 || (prev_prev_insn.insn_mo->pinfo & INSN_READ_LO))))
2690 /* Itbl support may require additional care here. */
2691 if (! prev_prev_insn_unreordered)
2697 struct insn_label_list *l;
2701 /* Record the frag which holds the nop instructions, so
2702 that we can remove them if we don't need them. */
2703 frag_grow (mips_opts.mips16 ? nops * 2 : nops * 4);
2704 prev_nop_frag = frag_now;
2705 prev_nop_frag_holds = nops;
2706 prev_nop_frag_required = 0;
2707 prev_nop_frag_since = 0;
2710 for (; nops > 0; --nops)
2715 /* Move on to a new frag, so that it is safe to simply
2716 decrease the size of prev_nop_frag. */
2717 frag_wane (frag_now);
2721 for (l = insn_labels; l != NULL; l = l->next)
2725 assert (S_GET_SEGMENT (l->label) == now_seg);
2726 symbol_set_frag (l->label, frag_now);
2727 val = (valueT) frag_now_fix ();
2728 /* mips16 text labels are stored as odd. */
2729 if (mips_opts.mips16)
2731 S_SET_VALUE (l->label, val);
2736 /* Mark instruction labels in mips16 mode. */
2737 if (mips_opts.mips16 && insns)
2738 mips16_mark_labels ();
2740 mips_no_prev_insn (insns);
2743 /* Build an instruction created by a macro expansion. This is passed
2744 a pointer to the count of instructions created so far, an
2745 expression, the name of the instruction to build, an operand format
2746 string, and corresponding arguments. */
2750 macro_build (char *place,
2758 macro_build (place, counter, ep, name, fmt, va_alist)
2767 struct mips_cl_insn insn;
2768 bfd_reloc_code_real_type r[3];
2772 va_start (args, fmt);
2778 * If the macro is about to expand into a second instruction,
2779 * print a warning if needed. We need to pass ip as a parameter
2780 * to generate a better warning message here...
2782 if (mips_opts.warn_about_macros && place == NULL && *counter == 1)
2783 as_warn (_("Macro instruction expanded into multiple instructions"));
2786 *counter += 1; /* bump instruction counter */
2788 if (mips_opts.mips16)
2790 mips16_macro_build (place, counter, ep, name, fmt, args);
2795 r[0] = BFD_RELOC_UNUSED;
2796 r[1] = BFD_RELOC_UNUSED;
2797 r[2] = BFD_RELOC_UNUSED;
2798 insn.insn_mo = (struct mips_opcode *) hash_find (op_hash, name);
2799 assert (insn.insn_mo);
2800 assert (strcmp (name, insn.insn_mo->name) == 0);
2802 /* Search until we get a match for NAME. */
2805 if (strcmp (fmt, insn.insn_mo->args) == 0
2806 && insn.insn_mo->pinfo != INSN_MACRO
2807 && OPCODE_IS_MEMBER (insn.insn_mo, mips_opts.isa, mips_arch)
2808 && (mips_arch != CPU_R4650 || (insn.insn_mo->pinfo & FP_D) == 0))
2812 assert (insn.insn_mo->name);
2813 assert (strcmp (name, insn.insn_mo->name) == 0);
2816 insn.insn_opcode = insn.insn_mo->match;
2832 insn.insn_opcode |= va_arg (args, int) << OP_SH_RT;
2836 insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE;
2841 insn.insn_opcode |= va_arg (args, int) << OP_SH_FT;
2846 insn.insn_opcode |= va_arg (args, int) << OP_SH_RD;
2851 int tmp = va_arg (args, int);
2853 insn.insn_opcode |= tmp << OP_SH_RT;
2854 insn.insn_opcode |= tmp << OP_SH_RD;
2860 insn.insn_opcode |= va_arg (args, int) << OP_SH_FS;
2867 insn.insn_opcode |= va_arg (args, int) << OP_SH_SHAMT;
2871 insn.insn_opcode |= va_arg (args, int) << OP_SH_FD;
2875 insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE20;
2879 insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE19;
2883 insn.insn_opcode |= va_arg (args, int) << OP_SH_CODE2;
2890 insn.insn_opcode |= va_arg (args, int) << OP_SH_RS;
2896 *r = (bfd_reloc_code_real_type) va_arg (args, int);
2897 assert (*r == BFD_RELOC_GPREL16
2898 || *r == BFD_RELOC_MIPS_LITERAL
2899 || *r == BFD_RELOC_MIPS_HIGHER
2900 || *r == BFD_RELOC_HI16_S
2901 || *r == BFD_RELOC_LO16
2902 || *r == BFD_RELOC_MIPS_GOT16
2903 || *r == BFD_RELOC_MIPS_CALL16
2904 || *r == BFD_RELOC_MIPS_GOT_LO16
2905 || *r == BFD_RELOC_MIPS_CALL_LO16
2906 || (ep->X_op == O_subtract
2907 && *r == BFD_RELOC_PCREL_LO16));
2911 *r = (bfd_reloc_code_real_type) va_arg (args, int);
2913 && (ep->X_op == O_constant
2914 || (ep->X_op == O_symbol
2915 && (*r == BFD_RELOC_MIPS_HIGHEST
2916 || *r == BFD_RELOC_HI16_S
2917 || *r == BFD_RELOC_HI16
2918 || *r == BFD_RELOC_GPREL16
2919 || *r == BFD_RELOC_MIPS_GOT_HI16
2920 || *r == BFD_RELOC_MIPS_CALL_HI16))
2921 || (ep->X_op == O_subtract
2922 && *r == BFD_RELOC_PCREL_HI16_S)));
2926 assert (ep != NULL);
2928 * This allows macro() to pass an immediate expression for
2929 * creating short branches without creating a symbol.
2930 * Note that the expression still might come from the assembly
2931 * input, in which case the value is not checked for range nor
2932 * is a relocation entry generated (yuck).
2934 if (ep->X_op == O_constant)
2936 insn.insn_opcode |= (ep->X_add_number >> 2) & 0xffff;
2940 if (mips_pic == EMBEDDED_PIC)
2941 *r = BFD_RELOC_16_PCREL_S2;
2943 *r = BFD_RELOC_16_PCREL;
2947 assert (ep != NULL);
2948 *r = BFD_RELOC_MIPS_JMP;
2952 insn.insn_opcode |= va_arg (args, unsigned long);
2961 assert (*r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL);
2963 append_insn (place, &insn, ep, r, false);
2967 mips16_macro_build (place, counter, ep, name, fmt, args)
2969 int *counter ATTRIBUTE_UNUSED;
2975 struct mips_cl_insn insn;
2976 bfd_reloc_code_real_type r[3]
2977 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
2979 insn.insn_mo = (struct mips_opcode *) hash_find (mips16_op_hash, name);
2980 assert (insn.insn_mo);
2981 assert (strcmp (name, insn.insn_mo->name) == 0);
2983 while (strcmp (fmt, insn.insn_mo->args) != 0
2984 || insn.insn_mo->pinfo == INSN_MACRO)
2987 assert (insn.insn_mo->name);
2988 assert (strcmp (name, insn.insn_mo->name) == 0);
2991 insn.insn_opcode = insn.insn_mo->match;
2992 insn.use_extend = false;
3011 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RY;
3016 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RX;
3020 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_RZ;
3024 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_MOVE32Z;
3034 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_REGR32;
3041 regno = va_arg (args, int);
3042 regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3);
3043 insn.insn_opcode |= regno << MIPS16OP_SH_REG32R;
3064 assert (ep != NULL);
3066 if (ep->X_op != O_constant)
3067 *r = BFD_RELOC_UNUSED + c;
3070 mips16_immed (NULL, 0, c, ep->X_add_number, false, false,
3071 false, &insn.insn_opcode, &insn.use_extend,
3074 *r = BFD_RELOC_UNUSED;
3080 insn.insn_opcode |= va_arg (args, int) << MIPS16OP_SH_IMM6;
3087 assert (*r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL);
3089 append_insn (place, &insn, ep, r, false);
3093 * Generate a "lui" instruction.
3096 macro_build_lui (place, counter, ep, regnum)
3102 expressionS high_expr;
3103 struct mips_cl_insn insn;
3104 bfd_reloc_code_real_type r[3]
3105 = {BFD_RELOC_UNUSED, BFD_RELOC_UNUSED, BFD_RELOC_UNUSED};
3106 CONST char *name = "lui";
3107 CONST char *fmt = "t,u";
3109 assert (! mips_opts.mips16);
3115 high_expr.X_op = O_constant;
3116 high_expr.X_add_number = ep->X_add_number;
3119 if (high_expr.X_op == O_constant)
3121 /* we can compute the instruction now without a relocation entry */
3122 high_expr.X_add_number = ((high_expr.X_add_number + 0x8000)
3124 *r = BFD_RELOC_UNUSED;
3126 else if (! HAVE_NEWABI)
3128 assert (ep->X_op == O_symbol);
3129 /* _gp_disp is a special case, used from s_cpload. */
3130 assert (mips_pic == NO_PIC
3131 || strcmp (S_GET_NAME (ep->X_add_symbol), "_gp_disp") == 0);
3132 *r = BFD_RELOC_HI16_S;
3136 * If the macro is about to expand into a second instruction,
3137 * print a warning if needed. We need to pass ip as a parameter
3138 * to generate a better warning message here...
3140 if (mips_opts.warn_about_macros && place == NULL && *counter == 1)
3141 as_warn (_("Macro instruction expanded into multiple instructions"));
3144 *counter += 1; /* bump instruction counter */
3146 insn.insn_mo = (struct mips_opcode *) hash_find (op_hash, name);
3147 assert (insn.insn_mo);
3148 assert (strcmp (name, insn.insn_mo->name) == 0);
3149 assert (strcmp (fmt, insn.insn_mo->args) == 0);
3151 insn.insn_opcode = insn.insn_mo->match | (regnum << OP_SH_RT);
3152 if (*r == BFD_RELOC_UNUSED)
3154 insn.insn_opcode |= high_expr.X_add_number;
3155 append_insn (place, &insn, NULL, r, false);
3158 append_insn (place, &insn, &high_expr, r, false);
3162 * Generates code to set the $at register to true (one)
3163 * if reg is less than the immediate expression.
3166 set_at (counter, reg, unsignedp)
3171 if (imm_expr.X_op == O_constant
3172 && imm_expr.X_add_number >= -0x8000
3173 && imm_expr.X_add_number < 0x8000)
3174 macro_build ((char *) NULL, counter, &imm_expr,
3175 unsignedp ? "sltiu" : "slti",
3176 "t,r,j", AT, reg, (int) BFD_RELOC_LO16);
3179 load_register (counter, AT, &imm_expr, 0);
3180 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3181 unsignedp ? "sltu" : "slt",
3182 "d,v,t", AT, reg, AT);
3186 /* Warn if an expression is not a constant. */
3189 check_absolute_expr (ip, ex)
3190 struct mips_cl_insn *ip;
3193 if (ex->X_op == O_big)
3194 as_bad (_("unsupported large constant"));
3195 else if (ex->X_op != O_constant)
3196 as_bad (_("Instruction %s requires absolute expression"), ip->insn_mo->name);
3199 /* Count the leading zeroes by performing a binary chop. This is a
3200 bulky bit of source, but performance is a LOT better for the
3201 majority of values than a simple loop to count the bits:
3202 for (lcnt = 0; (lcnt < 32); lcnt++)
3203 if ((v) & (1 << (31 - lcnt)))
3205 However it is not code size friendly, and the gain will drop a bit
3206 on certain cached systems.
3208 #define COUNT_TOP_ZEROES(v) \
3209 (((v) & ~0xffff) == 0 \
3210 ? ((v) & ~0xff) == 0 \
3211 ? ((v) & ~0xf) == 0 \
3212 ? ((v) & ~0x3) == 0 \
3213 ? ((v) & ~0x1) == 0 \
3218 : ((v) & ~0x7) == 0 \
3221 : ((v) & ~0x3f) == 0 \
3222 ? ((v) & ~0x1f) == 0 \
3225 : ((v) & ~0x7f) == 0 \
3228 : ((v) & ~0xfff) == 0 \
3229 ? ((v) & ~0x3ff) == 0 \
3230 ? ((v) & ~0x1ff) == 0 \
3233 : ((v) & ~0x7ff) == 0 \
3236 : ((v) & ~0x3fff) == 0 \
3237 ? ((v) & ~0x1fff) == 0 \
3240 : ((v) & ~0x7fff) == 0 \
3243 : ((v) & ~0xffffff) == 0 \
3244 ? ((v) & ~0xfffff) == 0 \
3245 ? ((v) & ~0x3ffff) == 0 \
3246 ? ((v) & ~0x1ffff) == 0 \
3249 : ((v) & ~0x7ffff) == 0 \
3252 : ((v) & ~0x3fffff) == 0 \
3253 ? ((v) & ~0x1fffff) == 0 \
3256 : ((v) & ~0x7fffff) == 0 \
3259 : ((v) & ~0xfffffff) == 0 \
3260 ? ((v) & ~0x3ffffff) == 0 \
3261 ? ((v) & ~0x1ffffff) == 0 \
3264 : ((v) & ~0x7ffffff) == 0 \
3267 : ((v) & ~0x3fffffff) == 0 \
3268 ? ((v) & ~0x1fffffff) == 0 \
3271 : ((v) & ~0x7fffffff) == 0 \
3276 * This routine generates the least number of instructions neccessary to load
3277 * an absolute expression value into a register.
3280 load_register (counter, reg, ep, dbl)
3287 expressionS hi32, lo32;
3289 if (ep->X_op != O_big)
3291 assert (ep->X_op == O_constant);
3292 if (ep->X_add_number < 0x8000
3293 && (ep->X_add_number >= 0
3294 || (ep->X_add_number >= -0x8000
3297 || sizeof (ep->X_add_number) > 4))))
3299 /* We can handle 16 bit signed values with an addiu to
3300 $zero. No need to ever use daddiu here, since $zero and
3301 the result are always correct in 32 bit mode. */
3302 macro_build ((char *) NULL, counter, ep, "addiu", "t,r,j", reg, 0,
3303 (int) BFD_RELOC_LO16);
3306 else if (ep->X_add_number >= 0 && ep->X_add_number < 0x10000)
3308 /* We can handle 16 bit unsigned values with an ori to
3310 macro_build ((char *) NULL, counter, ep, "ori", "t,r,i", reg, 0,
3311 (int) BFD_RELOC_LO16);
3314 else if ((((ep->X_add_number &~ (offsetT) 0x7fffffff) == 0
3315 || ((ep->X_add_number &~ (offsetT) 0x7fffffff)
3316 == ~ (offsetT) 0x7fffffff))
3319 || sizeof (ep->X_add_number) > 4
3320 || (ep->X_add_number & 0x80000000) == 0))
3321 || ((HAVE_32BIT_GPRS || ! dbl)
3322 && (ep->X_add_number &~ (offsetT) 0xffffffff) == 0)
3325 && ((ep->X_add_number &~ (offsetT) 0xffffffff)
3326 == ~ (offsetT) 0xffffffff)))
3328 /* 32 bit values require an lui. */
3329 macro_build ((char *) NULL, counter, ep, "lui", "t,u", reg,
3330 (int) BFD_RELOC_HI16);
3331 if ((ep->X_add_number & 0xffff) != 0)
3332 macro_build ((char *) NULL, counter, ep, "ori", "t,r,i", reg, reg,
3333 (int) BFD_RELOC_LO16);
3338 /* The value is larger than 32 bits. */
3340 if (HAVE_32BIT_GPRS)
3342 as_bad (_("Number (0x%lx) larger than 32 bits"),
3343 (unsigned long) ep->X_add_number);
3344 macro_build ((char *) NULL, counter, ep, "addiu", "t,r,j", reg, 0,
3345 (int) BFD_RELOC_LO16);
3349 if (ep->X_op != O_big)
3352 hi32.X_add_number = (valueT) hi32.X_add_number >> 16;
3353 hi32.X_add_number = (valueT) hi32.X_add_number >> 16;
3354 hi32.X_add_number &= 0xffffffff;
3356 lo32.X_add_number &= 0xffffffff;
3360 assert (ep->X_add_number > 2);
3361 if (ep->X_add_number == 3)
3362 generic_bignum[3] = 0;
3363 else if (ep->X_add_number > 4)
3364 as_bad (_("Number larger than 64 bits"));
3365 lo32.X_op = O_constant;
3366 lo32.X_add_number = generic_bignum[0] + (generic_bignum[1] << 16);
3367 hi32.X_op = O_constant;
3368 hi32.X_add_number = generic_bignum[2] + (generic_bignum[3] << 16);
3371 if (hi32.X_add_number == 0)
3376 unsigned long hi, lo;
3378 if (hi32.X_add_number == (offsetT) 0xffffffff)
3380 if ((lo32.X_add_number & 0xffff8000) == 0xffff8000)
3382 macro_build ((char *) NULL, counter, &lo32, "addiu", "t,r,j",
3383 reg, 0, (int) BFD_RELOC_LO16);
3386 if (lo32.X_add_number & 0x80000000)
3388 macro_build ((char *) NULL, counter, &lo32, "lui", "t,u", reg,
3389 (int) BFD_RELOC_HI16);
3390 if (lo32.X_add_number & 0xffff)
3391 macro_build ((char *) NULL, counter, &lo32, "ori", "t,r,i",
3392 reg, reg, (int) BFD_RELOC_LO16);
3397 /* Check for 16bit shifted constant. We know that hi32 is
3398 non-zero, so start the mask on the first bit of the hi32
3403 unsigned long himask, lomask;
3407 himask = 0xffff >> (32 - shift);
3408 lomask = (0xffff << shift) & 0xffffffff;
3412 himask = 0xffff << (shift - 32);
3415 if ((hi32.X_add_number & ~(offsetT) himask) == 0
3416 && (lo32.X_add_number & ~(offsetT) lomask) == 0)
3420 tmp.X_op = O_constant;
3422 tmp.X_add_number = ((hi32.X_add_number << (32 - shift))
3423 | (lo32.X_add_number >> shift));
3425 tmp.X_add_number = hi32.X_add_number >> (shift - 32);
3426 macro_build ((char *) NULL, counter, &tmp,
3427 "ori", "t,r,i", reg, 0,
3428 (int) BFD_RELOC_LO16);
3429 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3430 (shift >= 32) ? "dsll32" : "dsll",
3432 (shift >= 32) ? shift - 32 : shift);
3437 while (shift <= (64 - 16));
3439 /* Find the bit number of the lowest one bit, and store the
3440 shifted value in hi/lo. */
3441 hi = (unsigned long) (hi32.X_add_number & 0xffffffff);
3442 lo = (unsigned long) (lo32.X_add_number & 0xffffffff);
3446 while ((lo & 1) == 0)
3451 lo |= (hi & (((unsigned long) 1 << bit) - 1)) << (32 - bit);
3457 while ((hi & 1) == 0)
3466 /* Optimize if the shifted value is a (power of 2) - 1. */
3467 if ((hi == 0 && ((lo + 1) & lo) == 0)
3468 || (lo == 0xffffffff && ((hi + 1) & hi) == 0))
3470 shift = COUNT_TOP_ZEROES ((unsigned int) hi32.X_add_number);
3475 /* This instruction will set the register to be all
3477 tmp.X_op = O_constant;
3478 tmp.X_add_number = (offsetT) -1;
3479 macro_build ((char *) NULL, counter, &tmp, "addiu", "t,r,j",
3480 reg, 0, (int) BFD_RELOC_LO16);
3484 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3485 (bit >= 32) ? "dsll32" : "dsll",
3487 (bit >= 32) ? bit - 32 : bit);
3489 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3490 (shift >= 32) ? "dsrl32" : "dsrl",
3492 (shift >= 32) ? shift - 32 : shift);
3497 /* Sign extend hi32 before calling load_register, because we can
3498 generally get better code when we load a sign extended value. */
3499 if ((hi32.X_add_number & 0x80000000) != 0)
3500 hi32.X_add_number |= ~(offsetT) 0xffffffff;
3501 load_register (counter, reg, &hi32, 0);
3504 if ((lo32.X_add_number & 0xffff0000) == 0)
3508 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3509 "dsll32", "d,w,<", reg, freg, 0);
3517 if ((freg == 0) && (lo32.X_add_number == (offsetT) 0xffffffff))
3519 macro_build ((char *) NULL, counter, &lo32, "lui", "t,u", reg,
3520 (int) BFD_RELOC_HI16);
3521 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3522 "dsrl32", "d,w,<", reg, reg, 0);
3528 macro_build ((char *) NULL, counter, (expressionS *) NULL, "dsll",
3529 "d,w,<", reg, freg, 16);
3533 mid16.X_add_number >>= 16;
3534 macro_build ((char *) NULL, counter, &mid16, "ori", "t,r,i", reg,
3535 freg, (int) BFD_RELOC_LO16);
3536 macro_build ((char *) NULL, counter, (expressionS *) NULL, "dsll",
3537 "d,w,<", reg, reg, 16);
3540 if ((lo32.X_add_number & 0xffff) != 0)
3541 macro_build ((char *) NULL, counter, &lo32, "ori", "t,r,i", reg, freg,
3542 (int) BFD_RELOC_LO16);
3545 /* Load an address into a register. */
3548 load_address (counter, reg, ep, dbl, used_at)
3557 if (ep->X_op != O_constant
3558 && ep->X_op != O_symbol)
3560 as_bad (_("expression too complex"));
3561 ep->X_op = O_constant;
3564 if (ep->X_op == O_constant)
3566 load_register (counter, reg, ep, dbl);
3570 if (mips_pic == NO_PIC)
3572 /* If this is a reference to a GP relative symbol, we want
3573 addiu $reg,$gp,<sym> (BFD_RELOC_GPREL16)
3575 lui $reg,<sym> (BFD_RELOC_HI16_S)
3576 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
3577 If we have an addend, we always use the latter form.
3579 With 64bit address space and a usable $at we want
3580 lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST)
3581 lui $at,<sym> (BFD_RELOC_HI16_S)
3582 daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER)
3583 daddiu $at,<sym> (BFD_RELOC_LO16)
3587 If $at is already in use, we use an path which is suboptimal
3588 on superscalar processors.
3589 lui $reg,<sym> (BFD_RELOC_MIPS_HIGHEST)
3590 daddiu $reg,<sym> (BFD_RELOC_MIPS_HIGHER)
3592 daddiu $reg,<sym> (BFD_RELOC_HI16_S)
3594 daddiu $reg,<sym> (BFD_RELOC_LO16)
3600 /* We don't do GP optimization for now because RELAX_ENCODE can't
3601 hold the data for such large chunks. */
3605 macro_build (p, counter, ep, "lui", "t,u",
3606 reg, (int) BFD_RELOC_MIPS_HIGHEST);
3607 macro_build (p, counter, ep, "lui", "t,u",
3608 AT, (int) BFD_RELOC_HI16_S);
3609 macro_build (p, counter, ep, "daddiu", "t,r,j",
3610 reg, reg, (int) BFD_RELOC_MIPS_HIGHER);
3611 macro_build (p, counter, ep, "daddiu", "t,r,j",
3612 AT, AT, (int) BFD_RELOC_LO16);
3613 macro_build (p, counter, (expressionS *) NULL, "dsll32",
3614 "d,w,<", reg, reg, 0);
3615 macro_build (p, counter, (expressionS *) NULL, "dadd",
3616 "d,v,t", reg, reg, AT);
3621 macro_build (p, counter, ep, "lui", "t,u",
3622 reg, (int) BFD_RELOC_MIPS_HIGHEST);
3623 macro_build (p, counter, ep, "daddiu", "t,r,j",
3624 reg, reg, (int) BFD_RELOC_MIPS_HIGHER);
3625 macro_build (p, counter, (expressionS *) NULL, "dsll",
3626 "d,w,<", reg, reg, 16);
3627 macro_build (p, counter, ep, "daddiu", "t,r,j",
3628 reg, reg, (int) BFD_RELOC_HI16_S);
3629 macro_build (p, counter, (expressionS *) NULL, "dsll",
3630 "d,w,<", reg, reg, 16);
3631 macro_build (p, counter, ep, "daddiu", "t,r,j",
3632 reg, reg, (int) BFD_RELOC_LO16);
3638 if ((valueT) ep->X_add_number <= MAX_GPREL_OFFSET
3639 && ! nopic_need_relax (ep->X_add_symbol, 1))
3642 macro_build ((char *) NULL, counter, ep,
3643 dbl ? "daddiu" : "addiu", "t,r,j", reg, GP,
3644 (int) BFD_RELOC_GPREL16);
3645 p = frag_var (rs_machine_dependent, 8, 0,
3646 RELAX_ENCODE (4, 8, 0, 4, 0,
3647 mips_opts.warn_about_macros),
3648 ep->X_add_symbol, 0, NULL);
3650 macro_build_lui (p, counter, ep, reg);
3653 macro_build (p, counter, ep, dbl ? "daddiu" : "addiu",
3654 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
3657 else if (mips_pic == SVR4_PIC && ! mips_big_got)
3661 /* If this is a reference to an external symbol, we want
3662 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3664 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3666 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
3667 If there is a constant, it must be added in after. */
3668 ex.X_add_number = ep->X_add_number;
3669 ep->X_add_number = 0;
3671 macro_build ((char *) NULL, counter, ep,
3672 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
3673 "t,o(b)", reg, (int) BFD_RELOC_MIPS_GOT16, GP);
3674 macro_build ((char *) NULL, counter, (expressionS *) NULL, "nop", "");
3675 p = frag_var (rs_machine_dependent, 4, 0,
3676 RELAX_ENCODE (0, 4, -8, 0, 0, mips_opts.warn_about_macros),
3677 ep->X_add_symbol, (offsetT) 0, (char *) NULL);
3678 macro_build (p, counter, ep,
3679 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
3680 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
3681 if (ex.X_add_number != 0)
3683 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
3684 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
3685 ex.X_op = O_constant;
3686 macro_build ((char *) NULL, counter, &ex,
3687 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
3688 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
3691 else if (mips_pic == SVR4_PIC)
3696 /* This is the large GOT case. If this is a reference to an
3697 external symbol, we want
3698 lui $reg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
3700 lw $reg,<sym>($reg) (BFD_RELOC_MIPS_GOT_LO16)
3701 Otherwise, for a reference to a local symbol, we want
3702 lw $reg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
3704 addiu $reg,$reg,<sym> (BFD_RELOC_LO16)
3705 If there is a constant, it must be added in after. */
3706 ex.X_add_number = ep->X_add_number;
3707 ep->X_add_number = 0;
3708 if (reg_needs_delay (GP))
3713 macro_build ((char *) NULL, counter, ep, "lui", "t,u", reg,
3714 (int) BFD_RELOC_MIPS_GOT_HI16);
3715 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3716 dbl ? "daddu" : "addu", "d,v,t", reg, reg, GP);
3717 macro_build ((char *) NULL, counter, ep, dbl ? "ld" : "lw",
3718 "t,o(b)", reg, (int) BFD_RELOC_MIPS_GOT_LO16, reg);
3719 p = frag_var (rs_machine_dependent, 12 + off, 0,
3720 RELAX_ENCODE (12, 12 + off, off, 8 + off, 0,
3721 mips_opts.warn_about_macros),
3722 ep->X_add_symbol, 0, NULL);
3725 /* We need a nop before loading from $gp. This special
3726 check is required because the lui which starts the main
3727 instruction stream does not refer to $gp, and so will not
3728 insert the nop which may be required. */
3729 macro_build (p, counter, (expressionS *) NULL, "nop", "");
3732 macro_build (p, counter, ep, dbl ? "ld" : "lw",
3733 "t,o(b)", reg, (int) BFD_RELOC_MIPS_GOT16, GP);
3735 macro_build (p, counter, (expressionS *) NULL, "nop", "");
3737 macro_build (p, counter, ep, dbl ? "daddiu" : "addiu",
3738 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
3739 if (ex.X_add_number != 0)
3741 if (ex.X_add_number < -0x8000 || ex.X_add_number >= 0x8000)
3742 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
3743 ex.X_op = O_constant;
3744 macro_build ((char *) NULL, counter, &ex, dbl ? "daddiu" : "addiu",
3745 "t,r,j", reg, reg, (int) BFD_RELOC_LO16);
3748 else if (mips_pic == EMBEDDED_PIC)
3751 addiu $reg,$gp,<sym> (BFD_RELOC_GPREL16)
3753 macro_build ((char *) NULL, counter, ep, dbl ? "daddiu" : "addiu",
3754 "t,r,j", reg, GP, (int) BFD_RELOC_GPREL16);
3760 /* Move the contents of register SOURCE into register DEST. */
3763 move_register (counter, dest, source)
3768 macro_build ((char *) NULL, counter, (expressionS *) NULL,
3769 HAVE_32BIT_GPRS ? "addu" : "daddu",
3770 "d,v,t", dest, source, 0);
3775 * This routine implements the seemingly endless macro or synthesized
3776 * instructions and addressing modes in the mips assembly language. Many
3777 * of these macros are simple and are similar to each other. These could
3778 * probably be handled by some kind of table or grammer aproach instead of
3779 * this verbose method. Others are not simple macros but are more like
3780 * optimizing code generation.
3781 * One interesting optimization is when several store macros appear
3782 * consecutivly that would load AT with the upper half of the same address.
3783 * The ensuing load upper instructions are ommited. This implies some kind
3784 * of global optimization. We currently only optimize within a single macro.
3785 * For many of the load and store macros if the address is specified as a
3786 * constant expression in the first 64k of memory (ie ld $2,0x4000c) we
3787 * first load register 'at' with zero and use it as the base register. The
3788 * mips assembler simply uses register $zero. Just one tiny optimization
3793 struct mips_cl_insn *ip;
3795 register int treg, sreg, dreg, breg;
3811 bfd_reloc_code_real_type r;
3813 int hold_mips_optimize;
3815 assert (! mips_opts.mips16);
3817 treg = (ip->insn_opcode >> 16) & 0x1f;
3818 dreg = (ip->insn_opcode >> 11) & 0x1f;
3819 sreg = breg = (ip->insn_opcode >> 21) & 0x1f;
3820 mask = ip->insn_mo->mask;
3822 expr1.X_op = O_constant;
3823 expr1.X_op_symbol = NULL;
3824 expr1.X_add_symbol = NULL;
3825 expr1.X_add_number = 1;
3837 mips_emit_delays (true);
3838 ++mips_opts.noreorder;
3839 mips_any_noreorder = 1;
3841 expr1.X_add_number = 8;
3842 macro_build ((char *) NULL, &icnt, &expr1, "bgez", "s,p", sreg);
3844 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "",
3847 move_register (&icnt, dreg, sreg);
3848 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
3849 dbl ? "dsub" : "sub", "d,v,t", dreg, 0, sreg);
3851 --mips_opts.noreorder;
3872 if (imm_expr.X_op == O_constant
3873 && imm_expr.X_add_number >= -0x8000
3874 && imm_expr.X_add_number < 0x8000)
3876 macro_build ((char *) NULL, &icnt, &imm_expr, s, "t,r,j", treg, sreg,
3877 (int) BFD_RELOC_LO16);
3880 load_register (&icnt, AT, &imm_expr, dbl);
3881 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s2, "d,v,t",
3901 if (imm_expr.X_op == O_constant
3902 && imm_expr.X_add_number >= 0
3903 && imm_expr.X_add_number < 0x10000)
3905 if (mask != M_NOR_I)
3906 macro_build ((char *) NULL, &icnt, &imm_expr, s, "t,r,i", treg,
3907 sreg, (int) BFD_RELOC_LO16);
3910 macro_build ((char *) NULL, &icnt, &imm_expr, "ori", "t,r,i",
3911 treg, sreg, (int) BFD_RELOC_LO16);
3912 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nor",
3913 "d,v,t", treg, treg, 0);
3918 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_GPRS);
3919 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s2, "d,v,t",
3937 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
3939 macro_build ((char *) NULL, &icnt, &offset_expr, s, "s,t,p", sreg,
3943 load_register (&icnt, AT, &imm_expr, 0);
3944 macro_build ((char *) NULL, &icnt, &offset_expr, s, "s,t,p", sreg, AT);
3952 macro_build ((char *) NULL, &icnt, &offset_expr,
3953 likely ? "bgezl" : "bgez", "s,p", sreg);
3958 macro_build ((char *) NULL, &icnt, &offset_expr,
3959 likely ? "blezl" : "blez", "s,p", treg);
3962 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "slt", "d,v,t",
3964 macro_build ((char *) NULL, &icnt, &offset_expr,
3965 likely ? "beql" : "beq", "s,t,p", AT, 0);
3971 /* check for > max integer */
3972 maxnum = 0x7fffffff;
3973 if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4)
3980 if (imm_expr.X_op == O_constant
3981 && imm_expr.X_add_number >= maxnum
3982 && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4))
3985 /* result is always false */
3989 as_warn (_("Branch %s is always false (nop)"),
3991 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop",
3997 as_warn (_("Branch likely %s is always false"),
3999 macro_build ((char *) NULL, &icnt, &offset_expr, "bnel",
4004 if (imm_expr.X_op != O_constant)
4005 as_bad (_("Unsupported large constant"));
4006 imm_expr.X_add_number++;
4010 if (mask == M_BGEL_I)
4012 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4014 macro_build ((char *) NULL, &icnt, &offset_expr,
4015 likely ? "bgezl" : "bgez", "s,p", sreg);
4018 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4020 macro_build ((char *) NULL, &icnt, &offset_expr,
4021 likely ? "bgtzl" : "bgtz", "s,p", sreg);
4024 maxnum = 0x7fffffff;
4025 if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4)
4032 maxnum = - maxnum - 1;
4033 if (imm_expr.X_op == O_constant
4034 && imm_expr.X_add_number <= maxnum
4035 && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4))
4038 /* result is always true */
4039 as_warn (_("Branch %s is always true"), ip->insn_mo->name);
4040 macro_build ((char *) NULL, &icnt, &offset_expr, "b", "p");
4043 set_at (&icnt, sreg, 0);
4044 macro_build ((char *) NULL, &icnt, &offset_expr,
4045 likely ? "beql" : "beq", "s,t,p", AT, 0);
4055 macro_build ((char *) NULL, &icnt, &offset_expr,
4056 likely ? "beql" : "beq", "s,t,p", 0, treg);
4059 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
4060 "d,v,t", AT, sreg, treg);
4061 macro_build ((char *) NULL, &icnt, &offset_expr,
4062 likely ? "beql" : "beq", "s,t,p", AT, 0);
4070 && imm_expr.X_op == O_constant
4071 && imm_expr.X_add_number == (offsetT) 0xffffffff))
4073 if (imm_expr.X_op != O_constant)
4074 as_bad (_("Unsupported large constant"));
4075 imm_expr.X_add_number++;
4079 if (mask == M_BGEUL_I)
4081 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4083 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4085 macro_build ((char *) NULL, &icnt, &offset_expr,
4086 likely ? "bnel" : "bne", "s,t,p", sreg, 0);
4089 set_at (&icnt, sreg, 1);
4090 macro_build ((char *) NULL, &icnt, &offset_expr,
4091 likely ? "beql" : "beq", "s,t,p", AT, 0);
4099 macro_build ((char *) NULL, &icnt, &offset_expr,
4100 likely ? "bgtzl" : "bgtz", "s,p", sreg);
4105 macro_build ((char *) NULL, &icnt, &offset_expr,
4106 likely ? "bltzl" : "bltz", "s,p", treg);
4109 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "slt", "d,v,t",
4111 macro_build ((char *) NULL, &icnt, &offset_expr,
4112 likely ? "bnel" : "bne", "s,t,p", AT, 0);
4120 macro_build ((char *) NULL, &icnt, &offset_expr,
4121 likely ? "bnel" : "bne", "s,t,p", sreg, 0);
4126 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
4127 "d,v,t", AT, treg, sreg);
4128 macro_build ((char *) NULL, &icnt, &offset_expr,
4129 likely ? "bnel" : "bne", "s,t,p", AT, 0);
4137 macro_build ((char *) NULL, &icnt, &offset_expr,
4138 likely ? "blezl" : "blez", "s,p", sreg);
4143 macro_build ((char *) NULL, &icnt, &offset_expr,
4144 likely ? "bgezl" : "bgez", "s,p", treg);
4147 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "slt", "d,v,t",
4149 macro_build ((char *) NULL, &icnt, &offset_expr,
4150 likely ? "beql" : "beq", "s,t,p", AT, 0);
4156 maxnum = 0x7fffffff;
4157 if (HAVE_64BIT_GPRS && sizeof (maxnum) > 4)
4164 if (imm_expr.X_op == O_constant
4165 && imm_expr.X_add_number >= maxnum
4166 && (HAVE_32BIT_GPRS || sizeof (maxnum) > 4))
4168 if (imm_expr.X_op != O_constant)
4169 as_bad (_("Unsupported large constant"));
4170 imm_expr.X_add_number++;
4174 if (mask == M_BLTL_I)
4176 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4178 macro_build ((char *) NULL, &icnt, &offset_expr,
4179 likely ? "bltzl" : "bltz", "s,p", sreg);
4182 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4184 macro_build ((char *) NULL, &icnt, &offset_expr,
4185 likely ? "blezl" : "blez", "s,p", sreg);
4188 set_at (&icnt, sreg, 0);
4189 macro_build ((char *) NULL, &icnt, &offset_expr,
4190 likely ? "bnel" : "bne", "s,t,p", AT, 0);
4198 macro_build ((char *) NULL, &icnt, &offset_expr,
4199 likely ? "beql" : "beq", "s,t,p", sreg, 0);
4204 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
4205 "d,v,t", AT, treg, sreg);
4206 macro_build ((char *) NULL, &icnt, &offset_expr,
4207 likely ? "beql" : "beq", "s,t,p", AT, 0);
4215 && imm_expr.X_op == O_constant
4216 && imm_expr.X_add_number == (offsetT) 0xffffffff))
4218 if (imm_expr.X_op != O_constant)
4219 as_bad (_("Unsupported large constant"));
4220 imm_expr.X_add_number++;
4224 if (mask == M_BLTUL_I)
4226 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4228 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4230 macro_build ((char *) NULL, &icnt, &offset_expr,
4231 likely ? "beql" : "beq",
4235 set_at (&icnt, sreg, 1);
4236 macro_build ((char *) NULL, &icnt, &offset_expr,
4237 likely ? "bnel" : "bne", "s,t,p", AT, 0);
4245 macro_build ((char *) NULL, &icnt, &offset_expr,
4246 likely ? "bltzl" : "bltz", "s,p", sreg);
4251 macro_build ((char *) NULL, &icnt, &offset_expr,
4252 likely ? "bgtzl" : "bgtz", "s,p", treg);
4255 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "slt", "d,v,t",
4257 macro_build ((char *) NULL, &icnt, &offset_expr,
4258 likely ? "bnel" : "bne", "s,t,p", AT, 0);
4268 macro_build ((char *) NULL, &icnt, &offset_expr,
4269 likely ? "bnel" : "bne", "s,t,p", 0, treg);
4272 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
4275 macro_build ((char *) NULL, &icnt, &offset_expr,
4276 likely ? "bnel" : "bne", "s,t,p", AT, 0);
4291 as_warn (_("Divide by zero."));
4293 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "teq",
4296 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
4301 mips_emit_delays (true);
4302 ++mips_opts.noreorder;
4303 mips_any_noreorder = 1;
4306 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "teq",
4308 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4309 dbl ? "ddiv" : "div", "z,s,t", sreg, treg);
4313 expr1.X_add_number = 8;
4314 macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, 0);
4315 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4316 dbl ? "ddiv" : "div", "z,s,t", sreg, treg);
4317 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
4320 expr1.X_add_number = -1;
4321 macro_build ((char *) NULL, &icnt, &expr1,
4322 dbl ? "daddiu" : "addiu",
4323 "t,r,j", AT, 0, (int) BFD_RELOC_LO16);
4324 expr1.X_add_number = mips_trap ? (dbl ? 12 : 8) : (dbl ? 20 : 16);
4325 macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, AT);
4328 expr1.X_add_number = 1;
4329 macro_build ((char *) NULL, &icnt, &expr1, "daddiu", "t,r,j", AT, 0,
4330 (int) BFD_RELOC_LO16);
4331 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "dsll32",
4332 "d,w,<", AT, AT, 31);
4336 expr1.X_add_number = 0x80000000;
4337 macro_build ((char *) NULL, &icnt, &expr1, "lui", "t,u", AT,
4338 (int) BFD_RELOC_HI16);
4342 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "teq",
4344 /* We want to close the noreorder block as soon as possible, so
4345 that later insns are available for delay slot filling. */
4346 --mips_opts.noreorder;
4350 expr1.X_add_number = 8;
4351 macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", sreg, AT);
4352 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "",
4355 /* We want to close the noreorder block as soon as possible, so
4356 that later insns are available for delay slot filling. */
4357 --mips_opts.noreorder;
4359 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
4362 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d", dreg);
4401 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
4403 as_warn (_("Divide by zero."));
4405 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "teq",
4408 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
4412 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
4414 if (strcmp (s2, "mflo") == 0)
4415 move_register (&icnt, dreg, sreg);
4417 move_register (&icnt, dreg, 0);
4420 if (imm_expr.X_op == O_constant
4421 && imm_expr.X_add_number == -1
4422 && s[strlen (s) - 1] != 'u')
4424 if (strcmp (s2, "mflo") == 0)
4426 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4427 dbl ? "dneg" : "neg", "d,w", dreg, sreg);
4430 move_register (&icnt, dreg, 0);
4434 load_register (&icnt, AT, &imm_expr, dbl);
4435 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "z,s,t",
4437 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s2, "d", dreg);
4456 mips_emit_delays (true);
4457 ++mips_opts.noreorder;
4458 mips_any_noreorder = 1;
4461 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "teq",
4463 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "z,s,t",
4465 /* We want to close the noreorder block as soon as possible, so
4466 that later insns are available for delay slot filling. */
4467 --mips_opts.noreorder;
4471 expr1.X_add_number = 8;
4472 macro_build ((char *) NULL, &icnt, &expr1, "bne", "s,t,p", treg, 0);
4473 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "z,s,t",
4476 /* We want to close the noreorder block as soon as possible, so
4477 that later insns are available for delay slot filling. */
4478 --mips_opts.noreorder;
4479 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
4482 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s2, "d", dreg);
4488 /* Load the address of a symbol into a register. If breg is not
4489 zero, we then add a base register to it. */
4502 /* When generating embedded PIC code, we permit expressions of
4505 la $treg,foo-bar($breg)
4506 where bar is an address in the current section. These are used
4507 when getting the addresses of functions. We don't permit
4508 X_add_number to be non-zero, because if the symbol is
4509 external the relaxing code needs to know that any addend is
4510 purely the offset to X_op_symbol. */
4511 if (mips_pic == EMBEDDED_PIC
4512 && offset_expr.X_op == O_subtract
4513 && (symbol_constant_p (offset_expr.X_op_symbol)
4514 ? S_GET_SEGMENT (offset_expr.X_op_symbol) == now_seg
4515 : (symbol_equated_p (offset_expr.X_op_symbol)
4517 (symbol_get_value_expression (offset_expr.X_op_symbol)
4520 && (offset_expr.X_add_number == 0
4521 || OUTPUT_FLAVOR == bfd_target_elf_flavour))
4527 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
4528 tempreg, (int) BFD_RELOC_PCREL_HI16_S);
4532 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
4533 tempreg, (int) BFD_RELOC_PCREL_HI16_S);
4534 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4535 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
4536 "d,v,t", tempreg, tempreg, breg);
4538 macro_build ((char *) NULL, &icnt, &offset_expr,
4539 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
4540 "t,r,j", treg, tempreg, (int) BFD_RELOC_PCREL_LO16);
4546 if (offset_expr.X_op != O_symbol
4547 && offset_expr.X_op != O_constant)
4549 as_bad (_("expression too complex"));
4550 offset_expr.X_op = O_constant;
4553 if (offset_expr.X_op == O_constant)
4554 load_register (&icnt, tempreg, &offset_expr, dbl);
4555 else if (mips_pic == NO_PIC)
4557 /* If this is a reference to a GP relative symbol, we want
4558 addiu $tempreg,$gp,<sym> (BFD_RELOC_GPREL16)
4560 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
4561 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
4562 If we have a constant, we need two instructions anyhow,
4563 so we may as well always use the latter form.
4565 With 64bit address space and a usable $at we want
4566 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
4567 lui $at,<sym> (BFD_RELOC_HI16_S)
4568 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
4569 daddiu $at,<sym> (BFD_RELOC_LO16)
4571 dadd $tempreg,$tempreg,$at
4573 If $at is already in use, we use an path which is suboptimal
4574 on superscalar processors.
4575 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
4576 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
4578 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
4580 daddiu $tempreg,<sym> (BFD_RELOC_LO16)
4583 if (HAVE_64BIT_ADDRESSES)
4585 /* We don't do GP optimization for now because RELAX_ENCODE can't
4586 hold the data for such large chunks. */
4590 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
4591 tempreg, (int) BFD_RELOC_MIPS_HIGHEST);
4592 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
4593 AT, (int) BFD_RELOC_HI16_S);
4594 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4595 tempreg, tempreg, (int) BFD_RELOC_MIPS_HIGHER);
4596 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4597 AT, AT, (int) BFD_RELOC_LO16);
4598 macro_build (p, &icnt, (expressionS *) NULL, "dsll32",
4599 "d,w,<", tempreg, tempreg, 0);
4600 macro_build (p, &icnt, (expressionS *) NULL, "dadd", "d,v,t",
4601 tempreg, tempreg, AT);
4606 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
4607 tempreg, (int) BFD_RELOC_MIPS_HIGHEST);
4608 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4609 tempreg, tempreg, (int) BFD_RELOC_MIPS_HIGHER);
4610 macro_build (p, &icnt, (expressionS *) NULL, "dsll", "d,w,<",
4611 tempreg, tempreg, 16);
4612 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4613 tempreg, tempreg, (int) BFD_RELOC_HI16_S);
4614 macro_build (p, &icnt, (expressionS *) NULL, "dsll", "d,w,<",
4615 tempreg, tempreg, 16);
4616 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
4617 tempreg, tempreg, (int) BFD_RELOC_LO16);
4622 if ((valueT) offset_expr.X_add_number <= MAX_GPREL_OFFSET
4623 && ! nopic_need_relax (offset_expr.X_add_symbol, 1))
4626 macro_build ((char *) NULL, &icnt, &offset_expr,
4627 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
4628 "t,r,j", tempreg, GP, (int) BFD_RELOC_GPREL16);
4629 p = frag_var (rs_machine_dependent, 8, 0,
4630 RELAX_ENCODE (4, 8, 0, 4, 0,
4631 mips_opts.warn_about_macros),
4632 offset_expr.X_add_symbol, 0, NULL);
4634 macro_build_lui (p, &icnt, &offset_expr, tempreg);
4637 macro_build (p, &icnt, &offset_expr,
4638 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
4639 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
4642 else if (mips_pic == SVR4_PIC && ! mips_big_got)
4644 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT16;
4646 /* If this is a reference to an external symbol, and there
4647 is no constant, we want
4648 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4649 or if tempreg is PIC_CALL_REG
4650 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
4651 For a local symbol, we want
4652 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4654 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
4656 If we have a small constant, and this is a reference to
4657 an external symbol, we want
4658 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4660 addiu $tempreg,$tempreg,<constant>
4661 For a local symbol, we want the same instruction
4662 sequence, but we output a BFD_RELOC_LO16 reloc on the
4665 If we have a large constant, and this is a reference to
4666 an external symbol, we want
4667 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4668 lui $at,<hiconstant>
4669 addiu $at,$at,<loconstant>
4670 addu $tempreg,$tempreg,$at
4671 For a local symbol, we want the same instruction
4672 sequence, but we output a BFD_RELOC_LO16 reloc on the
4673 addiu instruction. */
4674 expr1.X_add_number = offset_expr.X_add_number;
4675 offset_expr.X_add_number = 0;
4677 if (expr1.X_add_number == 0 && tempreg == PIC_CALL_REG)
4678 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL16;
4679 macro_build ((char *) NULL, &icnt, &offset_expr, dbl ? "ld" : "lw",
4680 "t,o(b)", tempreg, lw_reloc_type, GP);
4681 if (expr1.X_add_number == 0)
4689 /* We're going to put in an addu instruction using
4690 tempreg, so we may as well insert the nop right
4692 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4696 p = frag_var (rs_machine_dependent, 8 - off, 0,
4697 RELAX_ENCODE (0, 8 - off, -4 - off, 4 - off, 0,
4699 ? mips_opts.warn_about_macros
4701 offset_expr.X_add_symbol, 0, NULL);
4704 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
4707 macro_build (p, &icnt, &expr1,
4708 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
4709 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
4710 /* FIXME: If breg == 0, and the next instruction uses
4711 $tempreg, then if this variant case is used an extra
4712 nop will be generated. */
4714 else if (expr1.X_add_number >= -0x8000
4715 && expr1.X_add_number < 0x8000)
4717 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4719 macro_build ((char *) NULL, &icnt, &expr1,
4720 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
4721 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
4722 frag_var (rs_machine_dependent, 0, 0,
4723 RELAX_ENCODE (0, 0, -12, -4, 0, 0),
4724 offset_expr.X_add_symbol, 0, NULL);
4730 /* If we are going to add in a base register, and the
4731 target register and the base register are the same,
4732 then we are using AT as a temporary register. Since
4733 we want to load the constant into AT, we add our
4734 current AT (from the global offset table) and the
4735 register into the register now, and pretend we were
4736 not using a base register. */
4741 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4743 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4744 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
4745 "d,v,t", treg, AT, breg);
4751 /* Set mips_optimize around the lui instruction to avoid
4752 inserting an unnecessary nop after the lw. */
4753 hold_mips_optimize = mips_optimize;
4755 macro_build_lui (NULL, &icnt, &expr1, AT);
4756 mips_optimize = hold_mips_optimize;
4758 macro_build ((char *) NULL, &icnt, &expr1,
4759 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
4760 "t,r,j", AT, AT, (int) BFD_RELOC_LO16);
4761 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4762 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
4763 "d,v,t", tempreg, tempreg, AT);
4764 frag_var (rs_machine_dependent, 0, 0,
4765 RELAX_ENCODE (0, 0, -16 + off1, -8, 0, 0),
4766 offset_expr.X_add_symbol, 0, NULL);
4770 else if (mips_pic == SVR4_PIC)
4773 int lui_reloc_type = (int) BFD_RELOC_MIPS_GOT_HI16;
4774 int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT_LO16;
4776 /* This is the large GOT case. If this is a reference to an
4777 external symbol, and there is no constant, we want
4778 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
4779 addu $tempreg,$tempreg,$gp
4780 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
4781 or if tempreg is PIC_CALL_REG
4782 lui $tempreg,<sym> (BFD_RELOC_MIPS_CALL_HI16)
4783 addu $tempreg,$tempreg,$gp
4784 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_CALL_LO16)
4785 For a local symbol, we want
4786 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4788 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
4790 If we have a small constant, and this is a reference to
4791 an external symbol, we want
4792 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
4793 addu $tempreg,$tempreg,$gp
4794 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
4796 addiu $tempreg,$tempreg,<constant>
4797 For a local symbol, we want
4798 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4800 addiu $tempreg,$tempreg,<constant> (BFD_RELOC_LO16)
4802 If we have a large constant, and this is a reference to
4803 an external symbol, we want
4804 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
4805 addu $tempreg,$tempreg,$gp
4806 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
4807 lui $at,<hiconstant>
4808 addiu $at,$at,<loconstant>
4809 addu $tempreg,$tempreg,$at
4810 For a local symbol, we want
4811 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
4812 lui $at,<hiconstant>
4813 addiu $at,$at,<loconstant> (BFD_RELOC_LO16)
4814 addu $tempreg,$tempreg,$at
4816 expr1.X_add_number = offset_expr.X_add_number;
4817 offset_expr.X_add_number = 0;
4819 if (reg_needs_delay (GP))
4823 if (expr1.X_add_number == 0 && tempreg == PIC_CALL_REG)
4825 lui_reloc_type = (int) BFD_RELOC_MIPS_CALL_HI16;
4826 lw_reloc_type = (int) BFD_RELOC_MIPS_CALL_LO16;
4828 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
4829 tempreg, lui_reloc_type);
4830 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4831 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
4832 "d,v,t", tempreg, tempreg, GP);
4833 macro_build ((char *) NULL, &icnt, &offset_expr,
4835 "t,o(b)", tempreg, lw_reloc_type, tempreg);
4836 if (expr1.X_add_number == 0)
4844 /* We're going to put in an addu instruction using
4845 tempreg, so we may as well insert the nop right
4847 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4852 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
4853 RELAX_ENCODE (12 + off, 12 + gpdel, gpdel,
4856 ? mips_opts.warn_about_macros
4858 offset_expr.X_add_symbol, 0, NULL);
4860 else if (expr1.X_add_number >= -0x8000
4861 && expr1.X_add_number < 0x8000)
4863 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4865 macro_build ((char *) NULL, &icnt, &expr1,
4866 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
4867 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
4869 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
4870 RELAX_ENCODE (20, 12 + gpdel, gpdel, 8 + gpdel, 0,
4872 ? mips_opts.warn_about_macros
4874 offset_expr.X_add_symbol, 0, NULL);
4880 /* If we are going to add in a base register, and the
4881 target register and the base register are the same,
4882 then we are using AT as a temporary register. Since
4883 we want to load the constant into AT, we add our
4884 current AT (from the global offset table) and the
4885 register into the register now, and pretend we were
4886 not using a base register. */
4894 assert (tempreg == AT);
4895 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4897 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4898 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
4899 "d,v,t", treg, AT, breg);
4904 /* Set mips_optimize around the lui instruction to avoid
4905 inserting an unnecessary nop after the lw. */
4906 hold_mips_optimize = mips_optimize;
4908 macro_build_lui (NULL, &icnt, &expr1, AT);
4909 mips_optimize = hold_mips_optimize;
4911 macro_build ((char *) NULL, &icnt, &expr1,
4912 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
4913 "t,r,j", AT, AT, (int) BFD_RELOC_LO16);
4914 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4915 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
4916 "d,v,t", dreg, dreg, AT);
4918 p = frag_var (rs_machine_dependent, 16 + gpdel + adj, 0,
4919 RELAX_ENCODE (24 + adj, 16 + gpdel + adj, gpdel,
4922 ? mips_opts.warn_about_macros
4924 offset_expr.X_add_symbol, 0, NULL);
4931 /* This is needed because this instruction uses $gp, but
4932 the first instruction on the main stream does not. */
4933 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
4936 macro_build (p, &icnt, &offset_expr,
4938 "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT16, GP);
4940 if (expr1.X_add_number >= -0x8000
4941 && expr1.X_add_number < 0x8000)
4943 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
4945 macro_build (p, &icnt, &expr1,
4946 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
4947 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
4948 /* FIXME: If add_number is 0, and there was no base
4949 register, the external symbol case ended with a load,
4950 so if the symbol turns out to not be external, and
4951 the next instruction uses tempreg, an unnecessary nop
4952 will be inserted. */
4958 /* We must add in the base register now, as in the
4959 external symbol case. */
4960 assert (tempreg == AT);
4961 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
4963 macro_build (p, &icnt, (expressionS *) NULL,
4964 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
4965 "d,v,t", treg, AT, breg);
4968 /* We set breg to 0 because we have arranged to add
4969 it in in both cases. */
4973 macro_build_lui (p, &icnt, &expr1, AT);
4975 macro_build (p, &icnt, &expr1,
4976 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
4977 "t,r,j", AT, AT, (int) BFD_RELOC_LO16);
4979 macro_build (p, &icnt, (expressionS *) NULL,
4980 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
4981 "d,v,t", tempreg, tempreg, AT);
4985 else if (mips_pic == EMBEDDED_PIC)
4988 addiu $tempreg,$gp,<sym> (BFD_RELOC_GPREL16)
4990 macro_build ((char *) NULL, &icnt, &offset_expr,
4991 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
4992 "t,r,j", tempreg, GP, (int) BFD_RELOC_GPREL16);
4998 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
4999 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5000 "d,v,t", treg, tempreg, breg);
5008 /* The j instruction may not be used in PIC code, since it
5009 requires an absolute address. We convert it to a b
5011 if (mips_pic == NO_PIC)
5012 macro_build ((char *) NULL, &icnt, &offset_expr, "j", "a");
5014 macro_build ((char *) NULL, &icnt, &offset_expr, "b", "p");
5017 /* The jal instructions must be handled as macros because when
5018 generating PIC code they expand to multi-instruction
5019 sequences. Normally they are simple instructions. */
5024 if (mips_pic == NO_PIC
5025 || mips_pic == EMBEDDED_PIC)
5026 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "jalr",
5028 else if (mips_pic == SVR4_PIC)
5030 if (sreg != PIC_CALL_REG)
5031 as_warn (_("MIPS PIC call to register other than $25"));
5033 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "jalr",
5037 if (mips_cprestore_offset < 0)
5038 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5041 expr1.X_add_number = mips_cprestore_offset;
5042 macro_build ((char *) NULL, &icnt, &expr1,
5043 HAVE_32BIT_ADDRESSES ? "lw" : "ld", "t,o(b)",
5044 GP, (int) BFD_RELOC_LO16, mips_frame_reg);
5054 if (mips_pic == NO_PIC)
5055 macro_build ((char *) NULL, &icnt, &offset_expr, "jal", "a");
5056 else if (mips_pic == SVR4_PIC)
5058 /* If this is a reference to an external symbol, and we are
5059 using a small GOT, we want
5060 lw $25,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
5064 lw $gp,cprestore($sp)
5065 The cprestore value is set using the .cprestore
5066 pseudo-op. If we are using a big GOT, we want
5067 lui $25,<sym> (BFD_RELOC_MIPS_CALL_HI16)
5069 lw $25,<sym>($25) (BFD_RELOC_MIPS_CALL_LO16)
5073 lw $gp,cprestore($sp)
5074 If the symbol is not external, we want
5075 lw $25,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5077 addiu $25,$25,<sym> (BFD_RELOC_LO16)
5080 lw $gp,cprestore($sp) */
5084 macro_build ((char *) NULL, &icnt, &offset_expr,
5085 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5086 "t,o(b)", PIC_CALL_REG,
5087 (int) BFD_RELOC_MIPS_CALL16, GP);
5088 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5090 p = frag_var (rs_machine_dependent, 4, 0,
5091 RELAX_ENCODE (0, 4, -8, 0, 0, 0),
5092 offset_expr.X_add_symbol, 0, NULL);
5098 if (reg_needs_delay (GP))
5102 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
5103 PIC_CALL_REG, (int) BFD_RELOC_MIPS_CALL_HI16);
5104 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5105 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5106 "d,v,t", PIC_CALL_REG, PIC_CALL_REG, GP);
5107 macro_build ((char *) NULL, &icnt, &offset_expr,
5108 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5109 "t,o(b)", PIC_CALL_REG,
5110 (int) BFD_RELOC_MIPS_CALL_LO16, PIC_CALL_REG);
5111 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5113 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
5114 RELAX_ENCODE (16, 12 + gpdel, gpdel, 8 + gpdel,
5116 offset_expr.X_add_symbol, 0, NULL);
5119 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
5122 macro_build (p, &icnt, &offset_expr,
5123 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5124 "t,o(b)", PIC_CALL_REG,
5125 (int) BFD_RELOC_MIPS_GOT16, GP);
5127 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
5130 macro_build (p, &icnt, &offset_expr,
5131 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
5132 "t,r,j", PIC_CALL_REG, PIC_CALL_REG,
5133 (int) BFD_RELOC_LO16);
5134 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5135 "jalr", "s", PIC_CALL_REG);
5138 if (mips_cprestore_offset < 0)
5139 as_warn (_("No .cprestore pseudo-op used in PIC code"));
5142 if (mips_opts.noreorder)
5143 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5145 expr1.X_add_number = mips_cprestore_offset;
5146 macro_build ((char *) NULL, &icnt, &expr1,
5147 HAVE_32BIT_ADDRESSES ? "lw" : "ld", "t,o(b)",
5148 GP, (int) BFD_RELOC_LO16, mips_frame_reg);
5152 else if (mips_pic == EMBEDDED_PIC)
5154 macro_build ((char *) NULL, &icnt, &offset_expr, "bal", "p");
5155 /* The linker may expand the call to a longer sequence which
5156 uses $at, so we must break rather than return. */
5181 /* Itbl support may require additional care here. */
5186 /* Itbl support may require additional care here. */
5191 /* Itbl support may require additional care here. */
5196 /* Itbl support may require additional care here. */
5208 if (mips_arch == CPU_R4650)
5210 as_bad (_("opcode not supported on this processor"));
5214 /* Itbl support may require additional care here. */
5219 /* Itbl support may require additional care here. */
5224 /* Itbl support may require additional care here. */
5244 if (breg == treg || coproc || lr)
5266 /* Itbl support may require additional care here. */
5271 /* Itbl support may require additional care here. */
5276 /* Itbl support may require additional care here. */
5281 /* Itbl support may require additional care here. */
5297 if (mips_arch == CPU_R4650)
5299 as_bad (_("opcode not supported on this processor"));
5304 /* Itbl support may require additional care here. */
5308 /* Itbl support may require additional care here. */
5313 /* Itbl support may require additional care here. */
5325 /* Itbl support may require additional care here. */
5326 if (mask == M_LWC1_AB
5327 || mask == M_SWC1_AB
5328 || mask == M_LDC1_AB
5329 || mask == M_SDC1_AB
5338 /* For embedded PIC, we allow loads where the offset is calculated
5339 by subtracting a symbol in the current segment from an unknown
5340 symbol, relative to a base register, e.g.:
5341 <op> $treg, <sym>-<localsym>($breg)
5342 This is used by the compiler for switch statements. */
5343 if (mips_pic == EMBEDDED_PIC
5344 && offset_expr.X_op == O_subtract
5345 && (symbol_constant_p (offset_expr.X_op_symbol)
5346 ? S_GET_SEGMENT (offset_expr.X_op_symbol) == now_seg
5347 : (symbol_equated_p (offset_expr.X_op_symbol)
5349 (symbol_get_value_expression (offset_expr.X_op_symbol)
5353 && (offset_expr.X_add_number == 0
5354 || OUTPUT_FLAVOR == bfd_target_elf_flavour))
5356 /* For this case, we output the instructions:
5357 lui $tempreg,<sym> (BFD_RELOC_PCREL_HI16_S)
5358 addiu $tempreg,$tempreg,$breg
5359 <op> $treg,<sym>($tempreg) (BFD_RELOC_PCREL_LO16)
5360 If the relocation would fit entirely in 16 bits, it would be
5362 <op> $treg,<sym>($breg) (BFD_RELOC_PCREL_LO16)
5363 instead, but that seems quite difficult. */
5364 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
5365 tempreg, (int) BFD_RELOC_PCREL_HI16_S);
5366 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5367 ((bfd_arch_bits_per_address (stdoutput) == 32
5368 || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
5369 ? "addu" : "daddu"),
5370 "d,v,t", tempreg, tempreg, breg);
5371 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt, treg,
5372 (int) BFD_RELOC_PCREL_LO16, tempreg);
5378 if (offset_expr.X_op != O_constant
5379 && offset_expr.X_op != O_symbol)
5381 as_bad (_("expression too complex"));
5382 offset_expr.X_op = O_constant;
5385 /* A constant expression in PIC code can be handled just as it
5386 is in non PIC code. */
5387 if (mips_pic == NO_PIC
5388 || offset_expr.X_op == O_constant)
5390 /* If this is a reference to a GP relative symbol, and there
5391 is no base register, we want
5392 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
5393 Otherwise, if there is no base register, we want
5394 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
5395 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5396 If we have a constant, we need two instructions anyhow,
5397 so we always use the latter form.
5399 If we have a base register, and this is a reference to a
5400 GP relative symbol, we want
5401 addu $tempreg,$breg,$gp
5402 <op> $treg,<sym>($tempreg) (BFD_RELOC_GPREL16)
5404 lui $tempreg,<sym> (BFD_RELOC_HI16_S)
5405 addu $tempreg,$tempreg,$breg
5406 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5407 With a constant we always use the latter case.
5409 With 64bit address space and no base register and $at usable,
5411 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5412 lui $at,<sym> (BFD_RELOC_HI16_S)
5413 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
5416 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5417 If we have a base register, we want
5418 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5419 lui $at,<sym> (BFD_RELOC_HI16_S)
5420 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
5424 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5426 Without $at we can't generate the optimal path for superscalar
5427 processors here since this would require two temporary registers.
5428 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5429 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
5431 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
5433 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5434 If we have a base register, we want
5435 lui $tempreg,<sym> (BFD_RELOC_MIPS_HIGHEST)
5436 daddiu $tempreg,<sym> (BFD_RELOC_MIPS_HIGHER)
5438 daddiu $tempreg,<sym> (BFD_RELOC_HI16_S)
5440 daddu $tempreg,$tempreg,$breg
5441 <op> $treg,<sym>($tempreg) (BFD_RELOC_LO16)
5443 if (HAVE_64BIT_ADDRESSES)
5447 /* We don't do GP optimization for now because RELAX_ENCODE can't
5448 hold the data for such large chunks. */
5452 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
5453 tempreg, (int) BFD_RELOC_MIPS_HIGHEST);
5454 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
5455 AT, (int) BFD_RELOC_HI16_S);
5456 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
5457 tempreg, tempreg, (int) BFD_RELOC_MIPS_HIGHER);
5459 macro_build (p, &icnt, (expressionS *) NULL, "daddu",
5460 "d,v,t", AT, AT, breg);
5461 macro_build (p, &icnt, (expressionS *) NULL, "dsll32",
5462 "d,w,<", tempreg, tempreg, 0);
5463 macro_build (p, &icnt, (expressionS *) NULL, "daddu",
5464 "d,v,t", tempreg, tempreg, AT);
5465 macro_build (p, &icnt, &offset_expr, s,
5466 fmt, treg, (int) BFD_RELOC_LO16, tempreg);
5471 macro_build (p, &icnt, &offset_expr, "lui", "t,u",
5472 tempreg, (int) BFD_RELOC_MIPS_HIGHEST);
5473 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
5474 tempreg, tempreg, (int) BFD_RELOC_MIPS_HIGHER);
5475 macro_build (p, &icnt, (expressionS *) NULL, "dsll",
5476 "d,w,<", tempreg, tempreg, 16);
5477 macro_build (p, &icnt, &offset_expr, "daddiu", "t,r,j",
5478 tempreg, tempreg, (int) BFD_RELOC_HI16_S);
5479 macro_build (p, &icnt, (expressionS *) NULL, "dsll",
5480 "d,w,<", tempreg, tempreg, 16);
5482 macro_build (p, &icnt, (expressionS *) NULL, "daddu",
5483 "d,v,t", tempreg, tempreg, breg);
5484 macro_build (p, &icnt, &offset_expr, s,
5485 fmt, treg, (int) BFD_RELOC_LO16, tempreg);
5493 if ((valueT) offset_expr.X_add_number > MAX_GPREL_OFFSET
5494 || nopic_need_relax (offset_expr.X_add_symbol, 1))
5499 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
5500 treg, (int) BFD_RELOC_GPREL16, GP);
5501 p = frag_var (rs_machine_dependent, 8, 0,
5502 RELAX_ENCODE (4, 8, 0, 4, 0,
5503 (mips_opts.warn_about_macros
5505 && mips_opts.noat))),
5506 offset_expr.X_add_symbol, 0, NULL);
5509 macro_build_lui (p, &icnt, &offset_expr, tempreg);
5512 macro_build (p, &icnt, &offset_expr, s, fmt, treg,
5513 (int) BFD_RELOC_LO16, tempreg);
5517 if ((valueT) offset_expr.X_add_number > MAX_GPREL_OFFSET
5518 || nopic_need_relax (offset_expr.X_add_symbol, 1))
5523 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5524 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5525 "d,v,t", tempreg, breg, GP);
5526 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
5527 treg, (int) BFD_RELOC_GPREL16, tempreg);
5528 p = frag_var (rs_machine_dependent, 12, 0,
5529 RELAX_ENCODE (8, 12, 0, 8, 0, 0),
5530 offset_expr.X_add_symbol, 0, NULL);
5532 macro_build_lui (p, &icnt, &offset_expr, tempreg);
5535 macro_build (p, &icnt, (expressionS *) NULL,
5536 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5537 "d,v,t", tempreg, tempreg, breg);
5540 macro_build (p, &icnt, &offset_expr, s, fmt, treg,
5541 (int) BFD_RELOC_LO16, tempreg);
5544 else if (mips_pic == SVR4_PIC && ! mips_big_got)
5546 /* If this is a reference to an external symbol, we want
5547 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5549 <op> $treg,0($tempreg)
5551 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5553 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
5554 <op> $treg,0($tempreg)
5555 If there is a base register, we add it to $tempreg before
5556 the <op>. If there is a constant, we stick it in the
5557 <op> instruction. We don't handle constants larger than
5558 16 bits, because we have no way to load the upper 16 bits
5559 (actually, we could handle them for the subset of cases
5560 in which we are not using $at). */
5561 assert (offset_expr.X_op == O_symbol);
5562 expr1.X_add_number = offset_expr.X_add_number;
5563 offset_expr.X_add_number = 0;
5564 if (expr1.X_add_number < -0x8000
5565 || expr1.X_add_number >= 0x8000)
5566 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
5568 macro_build ((char *) NULL, &icnt, &offset_expr,
5569 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5570 "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT16, GP);
5571 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
5572 p = frag_var (rs_machine_dependent, 4, 0,
5573 RELAX_ENCODE (0, 4, -8, 0, 0, 0),
5574 offset_expr.X_add_symbol, 0, NULL);
5575 macro_build (p, &icnt, &offset_expr,
5576 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
5577 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
5579 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5580 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5581 "d,v,t", tempreg, tempreg, breg);
5582 macro_build ((char *) NULL, &icnt, &expr1, s, fmt, treg,
5583 (int) BFD_RELOC_LO16, tempreg);
5585 else if (mips_pic == SVR4_PIC)
5589 /* If this is a reference to an external symbol, we want
5590 lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
5591 addu $tempreg,$tempreg,$gp
5592 lw $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
5593 <op> $treg,0($tempreg)
5595 lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
5597 addiu $tempreg,$tempreg,<sym> (BFD_RELOC_LO16)
5598 <op> $treg,0($tempreg)
5599 If there is a base register, we add it to $tempreg before
5600 the <op>. If there is a constant, we stick it in the
5601 <op> instruction. We don't handle constants larger than
5602 16 bits, because we have no way to load the upper 16 bits
5603 (actually, we could handle them for the subset of cases
5604 in which we are not using $at). */
5605 assert (offset_expr.X_op == O_symbol);
5606 expr1.X_add_number = offset_expr.X_add_number;
5607 offset_expr.X_add_number = 0;
5608 if (expr1.X_add_number < -0x8000
5609 || expr1.X_add_number >= 0x8000)
5610 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
5611 if (reg_needs_delay (GP))
5616 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
5617 tempreg, (int) BFD_RELOC_MIPS_GOT_HI16);
5618 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5619 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5620 "d,v,t", tempreg, tempreg, GP);
5621 macro_build ((char *) NULL, &icnt, &offset_expr,
5622 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5623 "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT_LO16,
5625 p = frag_var (rs_machine_dependent, 12 + gpdel, 0,
5626 RELAX_ENCODE (12, 12 + gpdel, gpdel, 8 + gpdel, 0, 0),
5627 offset_expr.X_add_symbol, 0, NULL);
5630 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
5633 macro_build (p, &icnt, &offset_expr,
5634 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5635 "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT16, GP);
5637 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
5639 macro_build (p, &icnt, &offset_expr,
5640 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
5641 "t,r,j", tempreg, tempreg, (int) BFD_RELOC_LO16);
5643 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5644 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5645 "d,v,t", tempreg, tempreg, breg);
5646 macro_build ((char *) NULL, &icnt, &expr1, s, fmt, treg,
5647 (int) BFD_RELOC_LO16, tempreg);
5649 else if (mips_pic == EMBEDDED_PIC)
5651 /* If there is no base register, we want
5652 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
5653 If there is a base register, we want
5654 addu $tempreg,$breg,$gp
5655 <op> $treg,<sym>($tempreg) (BFD_RELOC_GPREL16)
5657 assert (offset_expr.X_op == O_symbol);
5660 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
5661 treg, (int) BFD_RELOC_GPREL16, GP);
5666 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5667 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
5668 "d,v,t", tempreg, breg, GP);
5669 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
5670 treg, (int) BFD_RELOC_GPREL16, tempreg);
5683 load_register (&icnt, treg, &imm_expr, 0);
5687 load_register (&icnt, treg, &imm_expr, 1);
5691 if (imm_expr.X_op == O_constant)
5693 load_register (&icnt, AT, &imm_expr, 0);
5694 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5695 "mtc1", "t,G", AT, treg);
5700 assert (offset_expr.X_op == O_symbol
5701 && strcmp (segment_name (S_GET_SEGMENT
5702 (offset_expr.X_add_symbol)),
5704 && offset_expr.X_add_number == 0);
5705 macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)",
5706 treg, (int) BFD_RELOC_MIPS_LITERAL, GP);
5711 /* Check if we have a constant in IMM_EXPR. If the GPRs are 64 bits
5712 wide, IMM_EXPR is the entire value. Otherwise IMM_EXPR is the high
5713 order 32 bits of the value and the low order 32 bits are either
5714 zero or in OFFSET_EXPR. */
5715 if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big)
5717 if (HAVE_64BIT_GPRS)
5718 load_register (&icnt, treg, &imm_expr, 1);
5723 if (target_big_endian)
5735 load_register (&icnt, hreg, &imm_expr, 0);
5738 if (offset_expr.X_op == O_absent)
5739 move_register (&icnt, lreg, 0);
5742 assert (offset_expr.X_op == O_constant);
5743 load_register (&icnt, lreg, &offset_expr, 0);
5750 /* We know that sym is in the .rdata section. First we get the
5751 upper 16 bits of the address. */
5752 if (mips_pic == NO_PIC)
5754 macro_build_lui (NULL, &icnt, &offset_expr, AT);
5756 else if (mips_pic == SVR4_PIC)
5758 macro_build ((char *) NULL, &icnt, &offset_expr,
5759 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5760 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16, GP);
5762 else if (mips_pic == EMBEDDED_PIC)
5764 /* For embedded PIC we pick up the entire address off $gp in
5765 a single instruction. */
5766 macro_build ((char *) NULL, &icnt, &offset_expr,
5767 HAVE_32BIT_ADDRESSES ? "addiu" : "daddiu",
5768 "t,r,j", AT, GP, (int) BFD_RELOC_GPREL16);
5769 offset_expr.X_op = O_constant;
5770 offset_expr.X_add_number = 0;
5775 /* Now we load the register(s). */
5776 if (HAVE_64BIT_GPRS)
5777 macro_build ((char *) NULL, &icnt, &offset_expr, "ld", "t,o(b)",
5778 treg, (int) BFD_RELOC_LO16, AT);
5781 macro_build ((char *) NULL, &icnt, &offset_expr, "lw", "t,o(b)",
5782 treg, (int) BFD_RELOC_LO16, AT);
5785 /* FIXME: How in the world do we deal with the possible
5787 offset_expr.X_add_number += 4;
5788 macro_build ((char *) NULL, &icnt, &offset_expr, "lw", "t,o(b)",
5789 treg + 1, (int) BFD_RELOC_LO16, AT);
5793 /* To avoid confusion in tc_gen_reloc, we must ensure that this
5794 does not become a variant frag. */
5795 frag_wane (frag_now);
5801 /* Check if we have a constant in IMM_EXPR. If the FPRs are 64 bits
5802 wide, IMM_EXPR is the entire value and the GPRs are known to be 64
5803 bits wide as well. Otherwise IMM_EXPR is the high order 32 bits of
5804 the value and the low order 32 bits are either zero or in
5806 if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big)
5808 load_register (&icnt, AT, &imm_expr, HAVE_64BIT_FPRS);
5809 if (HAVE_64BIT_FPRS)
5811 assert (HAVE_64BIT_GPRS);
5812 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5813 "dmtc1", "t,S", AT, treg);
5817 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5818 "mtc1", "t,G", AT, treg + 1);
5819 if (offset_expr.X_op == O_absent)
5820 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5821 "mtc1", "t,G", 0, treg);
5824 assert (offset_expr.X_op == O_constant);
5825 load_register (&icnt, AT, &offset_expr, 0);
5826 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
5827 "mtc1", "t,G", AT, treg);
5833 assert (offset_expr.X_op == O_symbol
5834 && offset_expr.X_add_number == 0);
5835 s = segment_name (S_GET_SEGMENT (offset_expr.X_add_symbol));
5836 if (strcmp (s, ".lit8") == 0)
5838 if (mips_opts.isa != ISA_MIPS1)
5840 macro_build ((char *) NULL, &icnt, &offset_expr, "ldc1",
5841 "T,o(b)", treg, (int) BFD_RELOC_MIPS_LITERAL, GP);
5845 r = BFD_RELOC_MIPS_LITERAL;
5850 assert (strcmp (s, RDATA_SECTION_NAME) == 0);
5851 if (mips_pic == SVR4_PIC)
5852 macro_build ((char *) NULL, &icnt, &offset_expr,
5853 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
5854 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16, GP);
5857 /* FIXME: This won't work for a 64 bit address. */
5858 macro_build_lui (NULL, &icnt, &offset_expr, AT);
5861 if (mips_opts.isa != ISA_MIPS1)
5863 macro_build ((char *) NULL, &icnt, &offset_expr, "ldc1",
5864 "T,o(b)", treg, (int) BFD_RELOC_LO16, AT);
5866 /* To avoid confusion in tc_gen_reloc, we must ensure
5867 that this does not become a variant frag. */
5868 frag_wane (frag_now);
5879 if (mips_arch == CPU_R4650)
5881 as_bad (_("opcode not supported on this processor"));
5884 /* Even on a big endian machine $fn comes before $fn+1. We have
5885 to adjust when loading from memory. */
5888 assert (mips_opts.isa == ISA_MIPS1);
5889 macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)",
5890 target_big_endian ? treg + 1 : treg,
5892 /* FIXME: A possible overflow which I don't know how to deal
5894 offset_expr.X_add_number += 4;
5895 macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)",
5896 target_big_endian ? treg : treg + 1,
5899 /* To avoid confusion in tc_gen_reloc, we must ensure that this
5900 does not become a variant frag. */
5901 frag_wane (frag_now);
5910 * The MIPS assembler seems to check for X_add_number not
5911 * being double aligned and generating:
5914 * addiu at,at,%lo(foo+1)
5917 * But, the resulting address is the same after relocation so why
5918 * generate the extra instruction?
5920 if (mips_arch == CPU_R4650)
5922 as_bad (_("opcode not supported on this processor"));
5925 /* Itbl support may require additional care here. */
5927 if (mips_opts.isa != ISA_MIPS1)
5938 if (mips_arch == CPU_R4650)
5940 as_bad (_("opcode not supported on this processor"));
5944 if (mips_opts.isa != ISA_MIPS1)
5952 /* Itbl support may require additional care here. */
5957 if (HAVE_64BIT_GPRS)
5968 if (HAVE_64BIT_GPRS)
5978 /* We do _not_ bother to allow embedded PIC (symbol-local_symbol)
5979 loads for the case of doing a pair of loads to simulate an 'ld'.
5980 This is not currently done by the compiler, and assembly coders
5981 writing embedded-pic code can cope. */
5983 if (offset_expr.X_op != O_symbol
5984 && offset_expr.X_op != O_constant)
5986 as_bad (_("expression too complex"));
5987 offset_expr.X_op = O_constant;
5990 /* Even on a big endian machine $fn comes before $fn+1. We have
5991 to adjust when loading from memory. We set coproc if we must
5992 load $fn+1 first. */
5993 /* Itbl support may require additional care here. */
5994 if (! target_big_endian)
5997 if (mips_pic == NO_PIC
5998 || offset_expr.X_op == O_constant)
6000 /* If this is a reference to a GP relative symbol, we want
6001 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
6002 <op> $treg+1,<sym>+4($gp) (BFD_RELOC_GPREL16)
6003 If we have a base register, we use this
6005 <op> $treg,<sym>($at) (BFD_RELOC_GPREL16)
6006 <op> $treg+1,<sym>+4($at) (BFD_RELOC_GPREL16)
6007 If this is not a GP relative symbol, we want
6008 lui $at,<sym> (BFD_RELOC_HI16_S)
6009 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
6010 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
6011 If there is a base register, we add it to $at after the
6012 lui instruction. If there is a constant, we always use
6014 if ((valueT) offset_expr.X_add_number > MAX_GPREL_OFFSET
6015 || nopic_need_relax (offset_expr.X_add_symbol, 1))
6034 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6035 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
6036 "d,v,t", AT, breg, GP);
6042 /* Itbl support may require additional care here. */
6043 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
6044 coproc ? treg + 1 : treg,
6045 (int) BFD_RELOC_GPREL16, tempreg);
6046 offset_expr.X_add_number += 4;
6048 /* Set mips_optimize to 2 to avoid inserting an
6050 hold_mips_optimize = mips_optimize;
6052 /* Itbl support may require additional care here. */
6053 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
6054 coproc ? treg : treg + 1,
6055 (int) BFD_RELOC_GPREL16, tempreg);
6056 mips_optimize = hold_mips_optimize;
6058 p = frag_var (rs_machine_dependent, 12 + off, 0,
6059 RELAX_ENCODE (8 + off, 12 + off, 0, 4 + off, 1,
6060 used_at && mips_opts.noat),
6061 offset_expr.X_add_symbol, 0, NULL);
6063 /* We just generated two relocs. When tc_gen_reloc
6064 handles this case, it will skip the first reloc and
6065 handle the second. The second reloc already has an
6066 extra addend of 4, which we added above. We must
6067 subtract it out, and then subtract another 4 to make
6068 the first reloc come out right. The second reloc
6069 will come out right because we are going to add 4 to
6070 offset_expr when we build its instruction below.
6072 If we have a symbol, then we don't want to include
6073 the offset, because it will wind up being included
6074 when we generate the reloc. */
6076 if (offset_expr.X_op == O_constant)
6077 offset_expr.X_add_number -= 8;
6080 offset_expr.X_add_number = -4;
6081 offset_expr.X_op = O_constant;
6084 macro_build_lui (p, &icnt, &offset_expr, AT);
6089 macro_build (p, &icnt, (expressionS *) NULL,
6090 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
6091 "d,v,t", AT, breg, AT);
6095 /* Itbl support may require additional care here. */
6096 macro_build (p, &icnt, &offset_expr, s, fmt,
6097 coproc ? treg + 1 : treg,
6098 (int) BFD_RELOC_LO16, AT);
6101 /* FIXME: How do we handle overflow here? */
6102 offset_expr.X_add_number += 4;
6103 /* Itbl support may require additional care here. */
6104 macro_build (p, &icnt, &offset_expr, s, fmt,
6105 coproc ? treg : treg + 1,
6106 (int) BFD_RELOC_LO16, AT);
6108 else if (mips_pic == SVR4_PIC && ! mips_big_got)
6112 /* If this is a reference to an external symbol, we want
6113 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6118 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6120 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
6121 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
6122 If there is a base register we add it to $at before the
6123 lwc1 instructions. If there is a constant we include it
6124 in the lwc1 instructions. */
6126 expr1.X_add_number = offset_expr.X_add_number;
6127 offset_expr.X_add_number = 0;
6128 if (expr1.X_add_number < -0x8000
6129 || expr1.X_add_number >= 0x8000 - 4)
6130 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6135 frag_grow (24 + off);
6136 macro_build ((char *) NULL, &icnt, &offset_expr,
6137 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
6138 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16, GP);
6139 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
6141 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6142 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
6143 "d,v,t", AT, breg, AT);
6144 /* Itbl support may require additional care here. */
6145 macro_build ((char *) NULL, &icnt, &expr1, s, fmt,
6146 coproc ? treg + 1 : treg,
6147 (int) BFD_RELOC_LO16, AT);
6148 expr1.X_add_number += 4;
6150 /* Set mips_optimize to 2 to avoid inserting an undesired
6152 hold_mips_optimize = mips_optimize;
6154 /* Itbl support may require additional care here. */
6155 macro_build ((char *) NULL, &icnt, &expr1, s, fmt,
6156 coproc ? treg : treg + 1,
6157 (int) BFD_RELOC_LO16, AT);
6158 mips_optimize = hold_mips_optimize;
6160 (void) frag_var (rs_machine_dependent, 0, 0,
6161 RELAX_ENCODE (0, 0, -16 - off, -8, 1, 0),
6162 offset_expr.X_add_symbol, 0, NULL);
6164 else if (mips_pic == SVR4_PIC)
6168 /* If this is a reference to an external symbol, we want
6169 lui $at,<sym> (BFD_RELOC_MIPS_GOT_HI16)
6171 lw $at,<sym>($at) (BFD_RELOC_MIPS_GOT_LO16)
6176 lw $at,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
6178 <op> $treg,<sym>($at) (BFD_RELOC_LO16)
6179 <op> $treg+1,<sym>+4($at) (BFD_RELOC_LO16)
6180 If there is a base register we add it to $at before the
6181 lwc1 instructions. If there is a constant we include it
6182 in the lwc1 instructions. */
6184 expr1.X_add_number = offset_expr.X_add_number;
6185 offset_expr.X_add_number = 0;
6186 if (expr1.X_add_number < -0x8000
6187 || expr1.X_add_number >= 0x8000 - 4)
6188 as_bad (_("PIC code offset overflow (max 16 signed bits)"));
6189 if (reg_needs_delay (GP))
6198 macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
6199 AT, (int) BFD_RELOC_MIPS_GOT_HI16);
6200 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6201 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
6202 "d,v,t", AT, AT, GP);
6203 macro_build ((char *) NULL, &icnt, &offset_expr,
6204 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
6205 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT_LO16, AT);
6206 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
6208 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6209 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
6210 "d,v,t", AT, breg, AT);
6211 /* Itbl support may require additional care here. */
6212 macro_build ((char *) NULL, &icnt, &expr1, s, fmt,
6213 coproc ? treg + 1 : treg,
6214 (int) BFD_RELOC_LO16, AT);
6215 expr1.X_add_number += 4;
6217 /* Set mips_optimize to 2 to avoid inserting an undesired
6219 hold_mips_optimize = mips_optimize;
6221 /* Itbl support may require additional care here. */
6222 macro_build ((char *) NULL, &icnt, &expr1, s, fmt,
6223 coproc ? treg : treg + 1,
6224 (int) BFD_RELOC_LO16, AT);
6225 mips_optimize = hold_mips_optimize;
6226 expr1.X_add_number -= 4;
6228 p = frag_var (rs_machine_dependent, 16 + gpdel + off, 0,
6229 RELAX_ENCODE (24 + off, 16 + gpdel + off, gpdel,
6230 8 + gpdel + off, 1, 0),
6231 offset_expr.X_add_symbol, 0, NULL);
6234 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
6237 macro_build (p, &icnt, &offset_expr,
6238 HAVE_32BIT_ADDRESSES ? "lw" : "ld",
6239 "t,o(b)", AT, (int) BFD_RELOC_MIPS_GOT16, GP);
6241 macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
6245 macro_build (p, &icnt, (expressionS *) NULL,
6246 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
6247 "d,v,t", AT, breg, AT);
6250 /* Itbl support may require additional care here. */
6251 macro_build (p, &icnt, &expr1, s, fmt,
6252 coproc ? treg + 1 : treg,
6253 (int) BFD_RELOC_LO16, AT);
6255 expr1.X_add_number += 4;
6257 /* Set mips_optimize to 2 to avoid inserting an undesired
6259 hold_mips_optimize = mips_optimize;
6261 /* Itbl support may require additional care here. */
6262 macro_build (p, &icnt, &expr1, s, fmt,
6263 coproc ? treg : treg + 1,
6264 (int) BFD_RELOC_LO16, AT);
6265 mips_optimize = hold_mips_optimize;
6267 else if (mips_pic == EMBEDDED_PIC)
6269 /* If there is no base register, we use
6270 <op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
6271 <op> $treg+1,<sym>+4($gp) (BFD_RELOC_GPREL16)
6272 If we have a base register, we use
6274 <op> $treg,<sym>($at) (BFD_RELOC_GPREL16)
6275 <op> $treg+1,<sym>+4($at) (BFD_RELOC_GPREL16)
6284 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6285 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
6286 "d,v,t", AT, breg, GP);
6291 /* Itbl support may require additional care here. */
6292 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
6293 coproc ? treg + 1 : treg,
6294 (int) BFD_RELOC_GPREL16, tempreg);
6295 offset_expr.X_add_number += 4;
6296 /* Itbl support may require additional care here. */
6297 macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
6298 coproc ? treg : treg + 1,
6299 (int) BFD_RELOC_GPREL16, tempreg);
6315 assert (HAVE_32BIT_ADDRESSES);
6316 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg,
6317 (int) BFD_RELOC_LO16, breg);
6318 offset_expr.X_add_number += 4;
6319 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg + 1,
6320 (int) BFD_RELOC_LO16, breg);
6323 /* New code added to support COPZ instructions.
6324 This code builds table entries out of the macros in mip_opcodes.
6325 R4000 uses interlocks to handle coproc delays.
6326 Other chips (like the R3000) require nops to be inserted for delays.
6328 FIXME: Currently, we require that the user handle delays.
6329 In order to fill delay slots for non-interlocked chips,
6330 we must have a way to specify delays based on the coprocessor.
6331 Eg. 4 cycles if load coproc reg from memory, 1 if in cache, etc.
6332 What are the side-effects of the cop instruction?
6333 What cache support might we have and what are its effects?
6334 Both coprocessor & memory require delays. how long???
6335 What registers are read/set/modified?
6337 If an itbl is provided to interpret cop instructions,
6338 this knowledge can be encoded in the itbl spec. */
6352 /* For now we just do C (same as Cz). The parameter will be
6353 stored in insn_opcode by mips_ip. */
6354 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "C",
6359 move_register (&icnt, dreg, sreg);
6362 #ifdef LOSING_COMPILER
6364 /* Try and see if this is a new itbl instruction.
6365 This code builds table entries out of the macros in mip_opcodes.
6366 FIXME: For now we just assemble the expression and pass it's
6367 value along as a 32-bit immediate.
6368 We may want to have the assembler assemble this value,
6369 so that we gain the assembler's knowledge of delay slots,
6371 Would it be more efficient to use mask (id) here? */
6372 if (itbl_have_entries
6373 && (immed_expr = itbl_assemble (ip->insn_mo->name, "")))
6375 s = ip->insn_mo->name;
6377 coproc = ITBL_DECODE_PNUM (immed_expr);;
6378 macro_build ((char *) NULL, &icnt, &immed_expr, s, "C");
6385 as_warn (_("Macro used $at after \".set noat\""));
6390 struct mips_cl_insn *ip;
6392 register int treg, sreg, dreg, breg;
6408 bfd_reloc_code_real_type r;
6411 treg = (ip->insn_opcode >> 16) & 0x1f;
6412 dreg = (ip->insn_opcode >> 11) & 0x1f;
6413 sreg = breg = (ip->insn_opcode >> 21) & 0x1f;
6414 mask = ip->insn_mo->mask;
6416 expr1.X_op = O_constant;
6417 expr1.X_op_symbol = NULL;
6418 expr1.X_add_symbol = NULL;
6419 expr1.X_add_number = 1;
6423 #endif /* LOSING_COMPILER */
6428 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6429 dbl ? "dmultu" : "multu", "s,t", sreg, treg);
6430 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "d",
6437 /* The MIPS assembler some times generates shifts and adds. I'm
6438 not trying to be that fancy. GCC should do this for us
6440 load_register (&icnt, AT, &imm_expr, dbl);
6441 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6442 dbl ? "dmult" : "mult", "s,t", sreg, AT);
6443 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "d",
6457 mips_emit_delays (true);
6458 ++mips_opts.noreorder;
6459 mips_any_noreorder = 1;
6461 load_register (&icnt, AT, &imm_expr, dbl);
6462 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6463 dbl ? "dmult" : "mult", "s,t", sreg, imm ? AT : treg);
6464 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "d",
6466 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6467 dbl ? "dsra32" : "sra", "d,w,<", dreg, dreg, 31);
6468 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mfhi", "d",
6471 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "tne", "s,t",
6475 expr1.X_add_number = 8;
6476 macro_build ((char *) NULL, &icnt, &expr1, "beq", "s,t,p", dreg,
6478 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "",
6480 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
6483 --mips_opts.noreorder;
6484 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "d", dreg);
6497 mips_emit_delays (true);
6498 ++mips_opts.noreorder;
6499 mips_any_noreorder = 1;
6501 load_register (&icnt, AT, &imm_expr, dbl);
6502 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6503 dbl ? "dmultu" : "multu",
6504 "s,t", sreg, imm ? AT : treg);
6505 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mfhi", "d",
6507 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "d",
6510 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "tne", "s,t",
6514 expr1.X_add_number = 8;
6515 macro_build ((char *) NULL, &icnt, &expr1, "beq", "s,t,p", AT, 0);
6516 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "",
6518 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
6521 --mips_opts.noreorder;
6525 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "subu",
6526 "d,v,t", AT, 0, treg);
6527 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srlv",
6528 "d,t,s", AT, sreg, AT);
6529 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sllv",
6530 "d,t,s", dreg, sreg, treg);
6531 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or",
6532 "d,v,t", dreg, dreg, AT);
6536 if (imm_expr.X_op != O_constant)
6537 as_bad (_("rotate count too large"));
6538 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sll", "d,w,<",
6539 AT, sreg, (int) (imm_expr.X_add_number & 0x1f));
6540 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srl", "d,w,<",
6541 dreg, sreg, (int) ((0 - imm_expr.X_add_number) & 0x1f));
6542 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or", "d,v,t",
6547 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "subu",
6548 "d,v,t", AT, 0, treg);
6549 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sllv",
6550 "d,t,s", AT, sreg, AT);
6551 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srlv",
6552 "d,t,s", dreg, sreg, treg);
6553 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or",
6554 "d,v,t", dreg, dreg, AT);
6558 if (imm_expr.X_op != O_constant)
6559 as_bad (_("rotate count too large"));
6560 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srl", "d,w,<",
6561 AT, sreg, (int) (imm_expr.X_add_number & 0x1f));
6562 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sll", "d,w,<",
6563 dreg, sreg, (int) ((0 - imm_expr.X_add_number) & 0x1f));
6564 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or", "d,v,t",
6569 if (mips_arch == CPU_R4650)
6571 as_bad (_("opcode not supported on this processor"));
6574 assert (mips_opts.isa == ISA_MIPS1);
6575 /* Even on a big endian machine $fn comes before $fn+1. We have
6576 to adjust when storing to memory. */
6577 macro_build ((char *) NULL, &icnt, &offset_expr, "swc1", "T,o(b)",
6578 target_big_endian ? treg + 1 : treg,
6579 (int) BFD_RELOC_LO16, breg);
6580 offset_expr.X_add_number += 4;
6581 macro_build ((char *) NULL, &icnt, &offset_expr, "swc1", "T,o(b)",
6582 target_big_endian ? treg : treg + 1,
6583 (int) BFD_RELOC_LO16, breg);
6588 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg,
6589 treg, (int) BFD_RELOC_LO16);
6591 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg,
6592 sreg, (int) BFD_RELOC_LO16);
6595 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "xor",
6596 "d,v,t", dreg, sreg, treg);
6597 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg,
6598 dreg, (int) BFD_RELOC_LO16);
6603 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
6605 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg,
6606 sreg, (int) BFD_RELOC_LO16);
6611 as_warn (_("Instruction %s: result is always false"),
6613 move_register (&icnt, dreg, 0);
6616 if (imm_expr.X_op == O_constant
6617 && imm_expr.X_add_number >= 0
6618 && imm_expr.X_add_number < 0x10000)
6620 macro_build ((char *) NULL, &icnt, &imm_expr, "xori", "t,r,i", dreg,
6621 sreg, (int) BFD_RELOC_LO16);
6624 else if (imm_expr.X_op == O_constant
6625 && imm_expr.X_add_number > -0x8000
6626 && imm_expr.X_add_number < 0)
6628 imm_expr.X_add_number = -imm_expr.X_add_number;
6629 macro_build ((char *) NULL, &icnt, &imm_expr,
6630 HAVE_32BIT_GPRS ? "addiu" : "daddiu",
6631 "t,r,j", dreg, sreg,
6632 (int) BFD_RELOC_LO16);
6637 load_register (&icnt, AT, &imm_expr, 0);
6638 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "xor",
6639 "d,v,t", dreg, sreg, AT);
6642 macro_build ((char *) NULL, &icnt, &expr1, "sltiu", "t,r,j", dreg, dreg,
6643 (int) BFD_RELOC_LO16);
6648 case M_SGE: /* sreg >= treg <==> not (sreg < treg) */
6654 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d,v,t",
6656 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
6657 (int) BFD_RELOC_LO16);
6660 case M_SGE_I: /* sreg >= I <==> not (sreg < I) */
6662 if (imm_expr.X_op == O_constant
6663 && imm_expr.X_add_number >= -0x8000
6664 && imm_expr.X_add_number < 0x8000)
6666 macro_build ((char *) NULL, &icnt, &imm_expr,
6667 mask == M_SGE_I ? "slti" : "sltiu",
6668 "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16);
6673 load_register (&icnt, AT, &imm_expr, 0);
6674 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6675 mask == M_SGE_I ? "slt" : "sltu", "d,v,t", dreg, sreg,
6679 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
6680 (int) BFD_RELOC_LO16);
6685 case M_SGT: /* sreg > treg <==> treg < sreg */
6691 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d,v,t",
6695 case M_SGT_I: /* sreg > I <==> I < sreg */
6701 load_register (&icnt, AT, &imm_expr, 0);
6702 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d,v,t",
6706 case M_SLE: /* sreg <= treg <==> treg >= sreg <==> not (treg < sreg) */
6712 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d,v,t",
6714 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
6715 (int) BFD_RELOC_LO16);
6718 case M_SLE_I: /* sreg <= I <==> I >= sreg <==> not (I < sreg) */
6724 load_register (&icnt, AT, &imm_expr, 0);
6725 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "d,v,t",
6727 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", dreg, dreg,
6728 (int) BFD_RELOC_LO16);
6732 if (imm_expr.X_op == O_constant
6733 && imm_expr.X_add_number >= -0x8000
6734 && imm_expr.X_add_number < 0x8000)
6736 macro_build ((char *) NULL, &icnt, &imm_expr, "slti", "t,r,j",
6737 dreg, sreg, (int) BFD_RELOC_LO16);
6740 load_register (&icnt, AT, &imm_expr, 0);
6741 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "slt", "d,v,t",
6746 if (imm_expr.X_op == O_constant
6747 && imm_expr.X_add_number >= -0x8000
6748 && imm_expr.X_add_number < 0x8000)
6750 macro_build ((char *) NULL, &icnt, &imm_expr, "sltiu", "t,r,j",
6751 dreg, sreg, (int) BFD_RELOC_LO16);
6754 load_register (&icnt, AT, &imm_expr, 0);
6755 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
6756 "d,v,t", dreg, sreg, AT);
6761 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
6762 "d,v,t", dreg, 0, treg);
6764 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
6765 "d,v,t", dreg, 0, sreg);
6768 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "xor",
6769 "d,v,t", dreg, sreg, treg);
6770 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
6771 "d,v,t", dreg, 0, dreg);
6776 if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 0)
6778 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
6779 "d,v,t", dreg, 0, sreg);
6784 as_warn (_("Instruction %s: result is always true"),
6786 macro_build ((char *) NULL, &icnt, &expr1,
6787 HAVE_32BIT_GPRS ? "addiu" : "daddiu",
6788 "t,r,j", dreg, 0, (int) BFD_RELOC_LO16);
6791 if (imm_expr.X_op == O_constant
6792 && imm_expr.X_add_number >= 0
6793 && imm_expr.X_add_number < 0x10000)
6795 macro_build ((char *) NULL, &icnt, &imm_expr, "xori", "t,r,i",
6796 dreg, sreg, (int) BFD_RELOC_LO16);
6799 else if (imm_expr.X_op == O_constant
6800 && imm_expr.X_add_number > -0x8000
6801 && imm_expr.X_add_number < 0)
6803 imm_expr.X_add_number = -imm_expr.X_add_number;
6804 macro_build ((char *) NULL, &icnt, &imm_expr,
6805 HAVE_32BIT_GPRS ? "addiu" : "daddiu",
6806 "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16);
6811 load_register (&icnt, AT, &imm_expr, 0);
6812 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "xor",
6813 "d,v,t", dreg, sreg, AT);
6816 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sltu",
6817 "d,v,t", dreg, 0, dreg);
6825 if (imm_expr.X_op == O_constant
6826 && imm_expr.X_add_number > -0x8000
6827 && imm_expr.X_add_number <= 0x8000)
6829 imm_expr.X_add_number = -imm_expr.X_add_number;
6830 macro_build ((char *) NULL, &icnt, &imm_expr,
6831 dbl ? "daddi" : "addi",
6832 "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16);
6835 load_register (&icnt, AT, &imm_expr, dbl);
6836 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6837 dbl ? "dsub" : "sub", "d,v,t", dreg, sreg, AT);
6843 if (imm_expr.X_op == O_constant
6844 && imm_expr.X_add_number > -0x8000
6845 && imm_expr.X_add_number <= 0x8000)
6847 imm_expr.X_add_number = -imm_expr.X_add_number;
6848 macro_build ((char *) NULL, &icnt, &imm_expr,
6849 dbl ? "daddiu" : "addiu",
6850 "t,r,j", dreg, sreg, (int) BFD_RELOC_LO16);
6853 load_register (&icnt, AT, &imm_expr, dbl);
6854 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6855 dbl ? "dsubu" : "subu", "d,v,t", dreg, sreg, AT);
6876 load_register (&icnt, AT, &imm_expr, 0);
6877 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "s,t", sreg,
6883 assert (mips_opts.isa == ISA_MIPS1);
6884 sreg = (ip->insn_opcode >> 11) & 0x1f; /* floating reg */
6885 dreg = (ip->insn_opcode >> 06) & 0x1f; /* floating reg */
6888 * Is the double cfc1 instruction a bug in the mips assembler;
6889 * or is there a reason for it?
6891 mips_emit_delays (true);
6892 ++mips_opts.noreorder;
6893 mips_any_noreorder = 1;
6894 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "cfc1", "t,G",
6896 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "cfc1", "t,G",
6898 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
6899 expr1.X_add_number = 3;
6900 macro_build ((char *) NULL, &icnt, &expr1, "ori", "t,r,i", AT, treg,
6901 (int) BFD_RELOC_LO16);
6902 expr1.X_add_number = 2;
6903 macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", AT, AT,
6904 (int) BFD_RELOC_LO16);
6905 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "ctc1", "t,G",
6907 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
6908 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6909 mask == M_TRUNCWD ? "cvt.w.d" : "cvt.w.s", "D,S", dreg, sreg);
6910 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "ctc1", "t,G",
6912 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
6913 --mips_opts.noreorder;
6922 if (offset_expr.X_add_number >= 0x7fff)
6923 as_bad (_("operand overflow"));
6924 /* avoid load delay */
6925 if (! target_big_endian)
6926 offset_expr.X_add_number += 1;
6927 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg,
6928 (int) BFD_RELOC_LO16, breg);
6929 if (! target_big_endian)
6930 offset_expr.X_add_number -= 1;
6932 offset_expr.X_add_number += 1;
6933 macro_build ((char *) NULL, &icnt, &offset_expr, "lbu", "t,o(b)", AT,
6934 (int) BFD_RELOC_LO16, breg);
6935 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sll", "d,w,<",
6937 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or", "d,v,t",
6951 if (offset_expr.X_add_number >= 0x8000 - off)
6952 as_bad (_("operand overflow"));
6953 if (! target_big_endian)
6954 offset_expr.X_add_number += off;
6955 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg,
6956 (int) BFD_RELOC_LO16, breg);
6957 if (! target_big_endian)
6958 offset_expr.X_add_number -= off;
6960 offset_expr.X_add_number += off;
6961 macro_build ((char *) NULL, &icnt, &offset_expr, s2, "t,o(b)", treg,
6962 (int) BFD_RELOC_LO16, breg);
6976 load_address (&icnt, AT, &offset_expr, HAVE_64BIT_ADDRESSES, &used_at);
6978 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
6979 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
6980 "d,v,t", AT, AT, breg);
6981 if (! target_big_endian)
6982 expr1.X_add_number = off;
6984 expr1.X_add_number = 0;
6985 macro_build ((char *) NULL, &icnt, &expr1, s, "t,o(b)", treg,
6986 (int) BFD_RELOC_LO16, AT);
6987 if (! target_big_endian)
6988 expr1.X_add_number = 0;
6990 expr1.X_add_number = off;
6991 macro_build ((char *) NULL, &icnt, &expr1, s2, "t,o(b)", treg,
6992 (int) BFD_RELOC_LO16, AT);
6998 load_address (&icnt, AT, &offset_expr, HAVE_64BIT_ADDRESSES, &used_at);
7000 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7001 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
7002 "d,v,t", AT, AT, breg);
7003 if (target_big_endian)
7004 expr1.X_add_number = 0;
7005 macro_build ((char *) NULL, &icnt, &expr1,
7006 mask == M_ULH_A ? "lb" : "lbu", "t,o(b)", treg,
7007 (int) BFD_RELOC_LO16, AT);
7008 if (target_big_endian)
7009 expr1.X_add_number = 1;
7011 expr1.X_add_number = 0;
7012 macro_build ((char *) NULL, &icnt, &expr1, "lbu", "t,o(b)", AT,
7013 (int) BFD_RELOC_LO16, AT);
7014 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sll", "d,w,<",
7016 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or", "d,v,t",
7021 if (offset_expr.X_add_number >= 0x7fff)
7022 as_bad (_("operand overflow"));
7023 if (target_big_endian)
7024 offset_expr.X_add_number += 1;
7025 macro_build ((char *) NULL, &icnt, &offset_expr, "sb", "t,o(b)", treg,
7026 (int) BFD_RELOC_LO16, breg);
7027 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srl", "d,w,<",
7029 if (target_big_endian)
7030 offset_expr.X_add_number -= 1;
7032 offset_expr.X_add_number += 1;
7033 macro_build ((char *) NULL, &icnt, &offset_expr, "sb", "t,o(b)", AT,
7034 (int) BFD_RELOC_LO16, breg);
7047 if (offset_expr.X_add_number >= 0x8000 - off)
7048 as_bad (_("operand overflow"));
7049 if (! target_big_endian)
7050 offset_expr.X_add_number += off;
7051 macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg,
7052 (int) BFD_RELOC_LO16, breg);
7053 if (! target_big_endian)
7054 offset_expr.X_add_number -= off;
7056 offset_expr.X_add_number += off;
7057 macro_build ((char *) NULL, &icnt, &offset_expr, s2, "t,o(b)", treg,
7058 (int) BFD_RELOC_LO16, breg);
7072 load_address (&icnt, AT, &offset_expr, HAVE_64BIT_ADDRESSES, &used_at);
7074 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7075 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
7076 "d,v,t", AT, AT, breg);
7077 if (! target_big_endian)
7078 expr1.X_add_number = off;
7080 expr1.X_add_number = 0;
7081 macro_build ((char *) NULL, &icnt, &expr1, s, "t,o(b)", treg,
7082 (int) BFD_RELOC_LO16, AT);
7083 if (! target_big_endian)
7084 expr1.X_add_number = 0;
7086 expr1.X_add_number = off;
7087 macro_build ((char *) NULL, &icnt, &expr1, s2, "t,o(b)", treg,
7088 (int) BFD_RELOC_LO16, AT);
7093 load_address (&icnt, AT, &offset_expr, HAVE_64BIT_ADDRESSES, &used_at);
7095 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7096 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
7097 "d,v,t", AT, AT, breg);
7098 if (! target_big_endian)
7099 expr1.X_add_number = 0;
7100 macro_build ((char *) NULL, &icnt, &expr1, "sb", "t,o(b)", treg,
7101 (int) BFD_RELOC_LO16, AT);
7102 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srl", "d,w,<",
7104 if (! target_big_endian)
7105 expr1.X_add_number = 1;
7107 expr1.X_add_number = 0;
7108 macro_build ((char *) NULL, &icnt, &expr1, "sb", "t,o(b)", treg,
7109 (int) BFD_RELOC_LO16, AT);
7110 if (! target_big_endian)
7111 expr1.X_add_number = 0;
7113 expr1.X_add_number = 1;
7114 macro_build ((char *) NULL, &icnt, &expr1, "lbu", "t,o(b)", AT,
7115 (int) BFD_RELOC_LO16, AT);
7116 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sll", "d,w,<",
7118 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "or", "d,v,t",
7123 /* FIXME: Check if this is one of the itbl macros, since they
7124 are added dynamically. */
7125 as_bad (_("Macro %s not implemented yet"), ip->insn_mo->name);
7129 as_warn (_("Macro used $at after \".set noat\""));
7132 /* Implement macros in mips16 mode. */
7136 struct mips_cl_insn *ip;
7139 int xreg, yreg, zreg, tmp;
7143 const char *s, *s2, *s3;
7145 mask = ip->insn_mo->mask;
7147 xreg = (ip->insn_opcode >> MIPS16OP_SH_RX) & MIPS16OP_MASK_RX;
7148 yreg = (ip->insn_opcode >> MIPS16OP_SH_RY) & MIPS16OP_MASK_RY;
7149 zreg = (ip->insn_opcode >> MIPS16OP_SH_RZ) & MIPS16OP_MASK_RZ;
7153 expr1.X_op = O_constant;
7154 expr1.X_op_symbol = NULL;
7155 expr1.X_add_symbol = NULL;
7156 expr1.X_add_number = 1;
7175 mips_emit_delays (true);
7176 ++mips_opts.noreorder;
7177 mips_any_noreorder = 1;
7178 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7179 dbl ? "ddiv" : "div",
7180 "0,x,y", xreg, yreg);
7181 expr1.X_add_number = 2;
7182 macro_build ((char *) NULL, &icnt, &expr1, "bnez", "x,p", yreg);
7183 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break", "6",
7186 /* FIXME: The normal code checks for of -1 / -0x80000000 here,
7187 since that causes an overflow. We should do that as well,
7188 but I don't see how to do the comparisons without a temporary
7190 --mips_opts.noreorder;
7191 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "x", zreg);
7210 mips_emit_delays (true);
7211 ++mips_opts.noreorder;
7212 mips_any_noreorder = 1;
7213 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "0,x,y",
7215 expr1.X_add_number = 2;
7216 macro_build ((char *) NULL, &icnt, &expr1, "bnez", "x,p", yreg);
7217 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "break",
7219 --mips_opts.noreorder;
7220 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s2, "x", zreg);
7226 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7227 dbl ? "dmultu" : "multu", "x,y", xreg, yreg);
7228 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "x",
7237 if (imm_expr.X_op != O_constant)
7238 as_bad (_("Unsupported large constant"));
7239 imm_expr.X_add_number = -imm_expr.X_add_number;
7240 macro_build ((char *) NULL, &icnt, &imm_expr,
7241 dbl ? "daddiu" : "addiu", "y,x,4", yreg, xreg);
7245 if (imm_expr.X_op != O_constant)
7246 as_bad (_("Unsupported large constant"));
7247 imm_expr.X_add_number = -imm_expr.X_add_number;
7248 macro_build ((char *) NULL, &icnt, &imm_expr, "addiu",
7253 if (imm_expr.X_op != O_constant)
7254 as_bad (_("Unsupported large constant"));
7255 imm_expr.X_add_number = -imm_expr.X_add_number;
7256 macro_build ((char *) NULL, &icnt, &imm_expr, "daddiu",
7279 goto do_reverse_branch;
7283 goto do_reverse_branch;
7295 goto do_reverse_branch;
7306 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, s, "x,y",
7308 macro_build ((char *) NULL, &icnt, &offset_expr, s2, "p");
7335 goto do_addone_branch_i;
7340 goto do_addone_branch_i;
7355 goto do_addone_branch_i;
7362 if (imm_expr.X_op != O_constant)
7363 as_bad (_("Unsupported large constant"));
7364 ++imm_expr.X_add_number;
7367 macro_build ((char *) NULL, &icnt, &imm_expr, s, s3, xreg);
7368 macro_build ((char *) NULL, &icnt, &offset_expr, s2, "p");
7372 expr1.X_add_number = 0;
7373 macro_build ((char *) NULL, &icnt, &expr1, "slti", "x,8", yreg);
7375 move_register (&icnt, xreg, yreg);
7376 expr1.X_add_number = 2;
7377 macro_build ((char *) NULL, &icnt, &expr1, "bteqz", "p");
7378 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
7379 "neg", "x,w", xreg, xreg);
7383 /* For consistency checking, verify that all bits are specified either
7384 by the match/mask part of the instruction definition, or by the
7387 validate_mips_insn (opc)
7388 const struct mips_opcode *opc;
7390 const char *p = opc->args;
7392 unsigned long used_bits = opc->mask;
7394 if ((used_bits & opc->match) != opc->match)
7396 as_bad (_("internal: bad mips opcode (mask error): %s %s"),
7397 opc->name, opc->args);
7400 #define USE_BITS(mask,shift) (used_bits |= ((mask) << (shift)))
7407 case '<': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
7408 case '>': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
7410 case 'B': USE_BITS (OP_MASK_CODE20, OP_SH_CODE20); break;
7411 case 'C': USE_BITS (OP_MASK_COPZ, OP_SH_COPZ); break;
7412 case 'D': USE_BITS (OP_MASK_FD, OP_SH_FD); break;
7413 case 'E': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
7415 case 'G': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
7416 case 'H': USE_BITS (OP_MASK_SEL, OP_SH_SEL); break;
7418 case 'J': USE_BITS (OP_MASK_CODE19, OP_SH_CODE19); break;
7420 case 'M': USE_BITS (OP_MASK_CCC, OP_SH_CCC); break;
7421 case 'N': USE_BITS (OP_MASK_BCC, OP_SH_BCC); break;
7422 case 'R': USE_BITS (OP_MASK_FR, OP_SH_FR); break;
7423 case 'S': USE_BITS (OP_MASK_FS, OP_SH_FS); break;
7424 case 'T': USE_BITS (OP_MASK_FT, OP_SH_FT); break;
7425 case 'V': USE_BITS (OP_MASK_FS, OP_SH_FS); break;
7426 case 'W': USE_BITS (OP_MASK_FT, OP_SH_FT); break;
7427 case 'a': USE_BITS (OP_MASK_TARGET, OP_SH_TARGET); break;
7428 case 'b': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
7429 case 'c': USE_BITS (OP_MASK_CODE, OP_SH_CODE); break;
7430 case 'd': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
7432 case 'h': USE_BITS (OP_MASK_PREFX, OP_SH_PREFX); break;
7433 case 'i': USE_BITS (OP_MASK_IMMEDIATE, OP_SH_IMMEDIATE); break;
7434 case 'j': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
7435 case 'k': USE_BITS (OP_MASK_CACHE, OP_SH_CACHE); break;
7437 case 'o': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
7438 case 'p': USE_BITS (OP_MASK_DELTA, OP_SH_DELTA); break;
7439 case 'q': USE_BITS (OP_MASK_CODE2, OP_SH_CODE2); break;
7440 case 'r': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
7441 case 's': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
7442 case 't': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
7443 case 'u': USE_BITS (OP_MASK_IMMEDIATE, OP_SH_IMMEDIATE); break;
7444 case 'v': USE_BITS (OP_MASK_RS, OP_SH_RS); break;
7445 case 'w': USE_BITS (OP_MASK_RT, OP_SH_RT); break;
7448 case 'P': USE_BITS (OP_MASK_PERFREG, OP_SH_PERFREG); break;
7449 case 'U': USE_BITS (OP_MASK_RD, OP_SH_RD);
7450 USE_BITS (OP_MASK_RT, OP_SH_RT); break;
7452 as_bad (_("internal: bad mips opcode (unknown operand type `%c'): %s %s"),
7453 c, opc->name, opc->args);
7457 if (used_bits != 0xffffffff)
7459 as_bad (_("internal: bad mips opcode (bits 0x%lx undefined): %s %s"),
7460 ~used_bits & 0xffffffff, opc->name, opc->args);
7466 /* This routine assembles an instruction into its binary format. As a
7467 side effect, it sets one of the global variables imm_reloc or
7468 offset_reloc to the type of relocation to do if one of the operands
7469 is an address expression. */
7474 struct mips_cl_insn *ip;
7479 struct mips_opcode *insn;
7482 unsigned int lastregno = 0;
7485 int full_opcode_match = 1;
7489 /* If the instruction contains a '.', we first try to match an instruction
7490 including the '.'. Then we try again without the '.'. */
7492 for (s = str; *s != '\0' && !ISSPACE (*s); ++s)
7495 /* If we stopped on whitespace, then replace the whitespace with null for
7496 the call to hash_find. Save the character we replaced just in case we
7497 have to re-parse the instruction. */
7504 insn = (struct mips_opcode *) hash_find (op_hash, str);
7506 /* If we didn't find the instruction in the opcode table, try again, but
7507 this time with just the instruction up to, but not including the
7511 /* Restore the character we overwrite above (if any). */
7515 /* Scan up to the first '.' or whitespace. */
7517 *s != '\0' && *s != '.' && !ISSPACE (*s);
7521 /* If we did not find a '.', then we can quit now. */
7524 insn_error = "unrecognized opcode";
7528 /* Lookup the instruction in the hash table. */
7530 if ((insn = (struct mips_opcode *) hash_find (op_hash, str)) == NULL)
7532 insn_error = "unrecognized opcode";
7536 full_opcode_match = 0;
7544 assert (strcmp (insn->name, str) == 0);
7546 if (OPCODE_IS_MEMBER (insn, mips_opts.isa, mips_arch))
7551 if (insn->pinfo != INSN_MACRO)
7553 if (mips_arch == CPU_R4650 && (insn->pinfo & FP_D) != 0)
7559 if (insn + 1 < &mips_opcodes[NUMOPCODES]
7560 && strcmp (insn->name, insn[1].name) == 0)
7569 static char buf[100];
7571 _("opcode not supported on this processor: %s (%s)"),
7572 mips_cpu_to_str (mips_arch),
7573 mips_isa_to_str (mips_opts.isa));
7584 ip->insn_opcode = insn->match;
7586 for (args = insn->args;; ++args)
7588 s += strspn (s, " \t");
7591 case '\0': /* end of args */
7604 ip->insn_opcode |= lastregno << OP_SH_RS;
7608 ip->insn_opcode |= lastregno << OP_SH_RT;
7612 ip->insn_opcode |= lastregno << OP_SH_FT;
7616 ip->insn_opcode |= lastregno << OP_SH_FS;
7622 /* Handle optional base register.
7623 Either the base register is omitted or
7624 we must have a left paren. */
7625 /* This is dependent on the next operand specifier
7626 is a base register specification. */
7627 assert (args[1] == 'b' || args[1] == '5'
7628 || args[1] == '-' || args[1] == '4');
7632 case ')': /* these must match exactly */
7637 case '<': /* must be at least one digit */
7639 * According to the manual, if the shift amount is greater
7640 * than 31 or less than 0, then the shift amount should be
7641 * mod 32. In reality the mips assembler issues an error.
7642 * We issue a warning and mask out all but the low 5 bits.
7644 my_getExpression (&imm_expr, s);
7645 check_absolute_expr (ip, &imm_expr);
7646 if ((unsigned long) imm_expr.X_add_number > 31)
7648 as_warn (_("Improper shift amount (%ld)"),
7649 (long) imm_expr.X_add_number);
7650 imm_expr.X_add_number &= OP_MASK_SHAMT;
7652 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_SHAMT;
7653 imm_expr.X_op = O_absent;
7657 case '>': /* shift amount minus 32 */
7658 my_getExpression (&imm_expr, s);
7659 check_absolute_expr (ip, &imm_expr);
7660 if ((unsigned long) imm_expr.X_add_number < 32
7661 || (unsigned long) imm_expr.X_add_number > 63)
7663 ip->insn_opcode |= (imm_expr.X_add_number - 32) << OP_SH_SHAMT;
7664 imm_expr.X_op = O_absent;
7668 case 'k': /* cache code */
7669 case 'h': /* prefx code */
7670 my_getExpression (&imm_expr, s);
7671 check_absolute_expr (ip, &imm_expr);
7672 if ((unsigned long) imm_expr.X_add_number > 31)
7674 as_warn (_("Invalid value for `%s' (%lu)"),
7676 (unsigned long) imm_expr.X_add_number);
7677 imm_expr.X_add_number &= 0x1f;
7680 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CACHE;
7682 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_PREFX;
7683 imm_expr.X_op = O_absent;
7687 case 'c': /* break code */
7688 my_getExpression (&imm_expr, s);
7689 check_absolute_expr (ip, &imm_expr);
7690 if ((unsigned) imm_expr.X_add_number > 1023)
7692 as_warn (_("Illegal break code (%ld)"),
7693 (long) imm_expr.X_add_number);
7694 imm_expr.X_add_number &= OP_MASK_CODE;
7696 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE;
7697 imm_expr.X_op = O_absent;
7701 case 'q': /* lower break code */
7702 my_getExpression (&imm_expr, s);
7703 check_absolute_expr (ip, &imm_expr);
7704 if ((unsigned) imm_expr.X_add_number > 1023)
7706 as_warn (_("Illegal lower break code (%ld)"),
7707 (long) imm_expr.X_add_number);
7708 imm_expr.X_add_number &= OP_MASK_CODE2;
7710 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE2;
7711 imm_expr.X_op = O_absent;
7715 case 'B': /* 20-bit syscall/break code. */
7716 my_getExpression (&imm_expr, s);
7717 check_absolute_expr (ip, &imm_expr);
7718 if ((unsigned) imm_expr.X_add_number > OP_MASK_CODE20)
7719 as_warn (_("Illegal 20-bit code (%ld)"),
7720 (long) imm_expr.X_add_number);
7721 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE20;
7722 imm_expr.X_op = O_absent;
7726 case 'C': /* Coprocessor code */
7727 my_getExpression (&imm_expr, s);
7728 check_absolute_expr (ip, &imm_expr);
7729 if ((unsigned long) imm_expr.X_add_number >= (1<<25))
7731 as_warn (_("Coproccesor code > 25 bits (%ld)"),
7732 (long) imm_expr.X_add_number);
7733 imm_expr.X_add_number &= ((1<<25) - 1);
7735 ip->insn_opcode |= imm_expr.X_add_number;
7736 imm_expr.X_op = O_absent;
7740 case 'J': /* 19-bit wait code. */
7741 my_getExpression (&imm_expr, s);
7742 check_absolute_expr (ip, &imm_expr);
7743 if ((unsigned) imm_expr.X_add_number > OP_MASK_CODE19)
7744 as_warn (_("Illegal 19-bit code (%ld)"),
7745 (long) imm_expr.X_add_number);
7746 ip->insn_opcode |= imm_expr.X_add_number << OP_SH_CODE19;
7747 imm_expr.X_op = O_absent;
7751 case 'P': /* Performance register */
7752 my_getExpression (&imm_expr, s);
7753 check_absolute_expr (ip, &imm_expr);
7754 if (imm_expr.X_add_number != 0 && imm_expr.X_add_number != 1)
7756 as_warn (_("Invalid performance register (%ld)"),
7757 (long) imm_expr.X_add_number);
7758 imm_expr.X_add_number &= OP_MASK_PERFREG;
7760 ip->insn_opcode |= (imm_expr.X_add_number << OP_SH_PERFREG);
7761 imm_expr.X_op = O_absent;
7765 case 'b': /* base register */
7766 case 'd': /* destination register */
7767 case 's': /* source register */
7768 case 't': /* target register */
7769 case 'r': /* both target and source */
7770 case 'v': /* both dest and source */
7771 case 'w': /* both dest and target */
7772 case 'E': /* coprocessor target register */
7773 case 'G': /* coprocessor destination register */
7774 case 'x': /* ignore register name */
7775 case 'z': /* must be zero register */
7776 case 'U': /* destination register (clo/clz). */
7791 while (ISDIGIT (*s));
7793 as_bad (_("Invalid register number (%d)"), regno);
7795 else if (*args == 'E' || *args == 'G')
7799 if (s[1] == 'f' && s[2] == 'p')
7804 else if (s[1] == 's' && s[2] == 'p')
7809 else if (s[1] == 'g' && s[2] == 'p')
7814 else if (s[1] == 'a' && s[2] == 't')
7819 else if (s[1] == 'k' && s[2] == 't' && s[3] == '0')
7824 else if (s[1] == 'k' && s[2] == 't' && s[3] == '1')
7829 else if (itbl_have_entries)
7834 p = s + 1; /* advance past '$' */
7835 n = itbl_get_field (&p); /* n is name */
7837 /* See if this is a register defined in an
7839 if (itbl_get_reg_val (n, &r))
7841 /* Get_field advances to the start of
7842 the next field, so we need to back
7843 rack to the end of the last field. */
7847 s = strchr (s, '\0');
7860 as_warn (_("Used $at without \".set noat\""));
7866 if (c == 'r' || c == 'v' || c == 'w')
7873 /* 'z' only matches $0. */
7874 if (c == 'z' && regno != 0)
7877 /* Now that we have assembled one operand, we use the args string
7878 * to figure out where it goes in the instruction. */
7885 ip->insn_opcode |= regno << OP_SH_RS;
7889 ip->insn_opcode |= regno << OP_SH_RD;
7892 ip->insn_opcode |= regno << OP_SH_RD;
7893 ip->insn_opcode |= regno << OP_SH_RT;
7898 ip->insn_opcode |= regno << OP_SH_RT;
7901 /* This case exists because on the r3000 trunc
7902 expands into a macro which requires a gp
7903 register. On the r6000 or r4000 it is
7904 assembled into a single instruction which
7905 ignores the register. Thus the insn version
7906 is MIPS_ISA2 and uses 'x', and the macro
7907 version is MIPS_ISA1 and uses 't'. */
7910 /* This case is for the div instruction, which
7911 acts differently if the destination argument
7912 is $0. This only matches $0, and is checked
7913 outside the switch. */
7916 /* Itbl operand; not yet implemented. FIXME ?? */
7918 /* What about all other operands like 'i', which
7919 can be specified in the opcode table? */
7929 ip->insn_opcode |= lastregno << OP_SH_RS;
7932 ip->insn_opcode |= lastregno << OP_SH_RT;
7937 case 'D': /* floating point destination register */
7938 case 'S': /* floating point source register */
7939 case 'T': /* floating point target register */
7940 case 'R': /* floating point source register */
7944 if (s[0] == '$' && s[1] == 'f'
7955 while (ISDIGIT (*s));
7958 as_bad (_("Invalid float register number (%d)"), regno);
7960 if ((regno & 1) != 0
7962 && ! (strcmp (str, "mtc1") == 0
7963 || strcmp (str, "mfc1") == 0
7964 || strcmp (str, "lwc1") == 0
7965 || strcmp (str, "swc1") == 0
7966 || strcmp (str, "l.s") == 0
7967 || strcmp (str, "s.s") == 0))
7968 as_warn (_("Float register should be even, was %d"),
7976 if (c == 'V' || c == 'W')
7986 ip->insn_opcode |= regno << OP_SH_FD;
7990 ip->insn_opcode |= regno << OP_SH_FS;
7994 ip->insn_opcode |= regno << OP_SH_FT;
7997 ip->insn_opcode |= regno << OP_SH_FR;
8007 ip->insn_opcode |= lastregno << OP_SH_FS;
8010 ip->insn_opcode |= lastregno << OP_SH_FT;
8016 my_getExpression (&imm_expr, s);
8017 if (imm_expr.X_op != O_big
8018 && imm_expr.X_op != O_constant)
8019 insn_error = _("absolute expression required");
8024 my_getExpression (&offset_expr, s);
8025 *imm_reloc = BFD_RELOC_32;
8038 unsigned char temp[8];
8040 unsigned int length;
8045 /* These only appear as the last operand in an
8046 instruction, and every instruction that accepts
8047 them in any variant accepts them in all variants.
8048 This means we don't have to worry about backing out
8049 any changes if the instruction does not match.
8051 The difference between them is the size of the
8052 floating point constant and where it goes. For 'F'
8053 and 'L' the constant is 64 bits; for 'f' and 'l' it
8054 is 32 bits. Where the constant is placed is based
8055 on how the MIPS assembler does things:
8058 f -- immediate value
8061 The .lit4 and .lit8 sections are only used if
8062 permitted by the -G argument.
8064 When generating embedded PIC code, we use the
8065 .lit8 section but not the .lit4 section (we can do
8066 .lit4 inline easily; we need to put .lit8
8067 somewhere in the data segment, and using .lit8
8068 permits the linker to eventually combine identical
8071 The code below needs to know whether the target register
8072 is 32 or 64 bits wide. It relies on the fact 'f' and
8073 'F' are used with GPR-based instructions and 'l' and
8074 'L' are used with FPR-based instructions. */
8076 f64 = *args == 'F' || *args == 'L';
8077 using_gprs = *args == 'F' || *args == 'f';
8079 save_in = input_line_pointer;
8080 input_line_pointer = s;
8081 err = md_atof (f64 ? 'd' : 'f', (char *) temp, &len);
8083 s = input_line_pointer;
8084 input_line_pointer = save_in;
8085 if (err != NULL && *err != '\0')
8087 as_bad (_("Bad floating point constant: %s"), err);
8088 memset (temp, '\0', sizeof temp);
8089 length = f64 ? 8 : 4;
8092 assert (length == (unsigned) (f64 ? 8 : 4));
8096 && (! USE_GLOBAL_POINTER_OPT
8097 || mips_pic == EMBEDDED_PIC
8098 || g_switch_value < 4
8099 || (temp[0] == 0 && temp[1] == 0)
8100 || (temp[2] == 0 && temp[3] == 0))))
8102 imm_expr.X_op = O_constant;
8103 if (! target_big_endian)
8104 imm_expr.X_add_number = bfd_getl32 (temp);
8106 imm_expr.X_add_number = bfd_getb32 (temp);
8109 && ! mips_disable_float_construction
8110 /* Constants can only be constructed in GPRs and
8111 copied to FPRs if the GPRs are at least as wide
8112 as the FPRs. Force the constant into memory if
8113 we are using 64-bit FPRs but the GPRs are only
8116 || ! (HAVE_64BIT_FPRS && HAVE_32BIT_GPRS))
8117 && ((temp[0] == 0 && temp[1] == 0)
8118 || (temp[2] == 0 && temp[3] == 0))
8119 && ((temp[4] == 0 && temp[5] == 0)
8120 || (temp[6] == 0 && temp[7] == 0)))
8122 /* The value is simple enough to load with a couple of
8123 instructions. If using 32-bit registers, set
8124 imm_expr to the high order 32 bits and offset_expr to
8125 the low order 32 bits. Otherwise, set imm_expr to
8126 the entire 64 bit constant. */
8127 if (using_gprs ? HAVE_32BIT_GPRS : HAVE_32BIT_FPRS)
8129 imm_expr.X_op = O_constant;
8130 offset_expr.X_op = O_constant;
8131 if (! target_big_endian)
8133 imm_expr.X_add_number = bfd_getl32 (temp + 4);
8134 offset_expr.X_add_number = bfd_getl32 (temp);
8138 imm_expr.X_add_number = bfd_getb32 (temp);
8139 offset_expr.X_add_number = bfd_getb32 (temp + 4);
8141 if (offset_expr.X_add_number == 0)
8142 offset_expr.X_op = O_absent;
8144 else if (sizeof (imm_expr.X_add_number) > 4)
8146 imm_expr.X_op = O_constant;
8147 if (! target_big_endian)
8148 imm_expr.X_add_number = bfd_getl64 (temp);
8150 imm_expr.X_add_number = bfd_getb64 (temp);
8154 imm_expr.X_op = O_big;
8155 imm_expr.X_add_number = 4;
8156 if (! target_big_endian)
8158 generic_bignum[0] = bfd_getl16 (temp);
8159 generic_bignum[1] = bfd_getl16 (temp + 2);
8160 generic_bignum[2] = bfd_getl16 (temp + 4);
8161 generic_bignum[3] = bfd_getl16 (temp + 6);
8165 generic_bignum[0] = bfd_getb16 (temp + 6);
8166 generic_bignum[1] = bfd_getb16 (temp + 4);
8167 generic_bignum[2] = bfd_getb16 (temp + 2);
8168 generic_bignum[3] = bfd_getb16 (temp);
8174 const char *newname;
8177 /* Switch to the right section. */
8179 subseg = now_subseg;
8182 default: /* unused default case avoids warnings. */
8184 newname = RDATA_SECTION_NAME;
8185 if ((USE_GLOBAL_POINTER_OPT && g_switch_value >= 8)
8186 || mips_pic == EMBEDDED_PIC)
8190 if (mips_pic == EMBEDDED_PIC)
8193 newname = RDATA_SECTION_NAME;
8196 assert (!USE_GLOBAL_POINTER_OPT
8197 || g_switch_value >= 4);
8201 new_seg = subseg_new (newname, (subsegT) 0);
8202 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
8203 bfd_set_section_flags (stdoutput, new_seg,
8208 frag_align (*args == 'l' ? 2 : 3, 0, 0);
8209 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
8210 && strcmp (TARGET_OS, "elf") != 0)
8211 record_alignment (new_seg, 4);
8213 record_alignment (new_seg, *args == 'l' ? 2 : 3);
8215 as_bad (_("Can't use floating point insn in this section"));
8217 /* Set the argument to the current address in the
8219 offset_expr.X_op = O_symbol;
8220 offset_expr.X_add_symbol =
8221 symbol_new ("L0\001", now_seg,
8222 (valueT) frag_now_fix (), frag_now);
8223 offset_expr.X_add_number = 0;
8225 /* Put the floating point number into the section. */
8226 p = frag_more ((int) length);
8227 memcpy (p, temp, length);
8229 /* Switch back to the original section. */
8230 subseg_set (seg, subseg);
8235 case 'i': /* 16 bit unsigned immediate */
8236 case 'j': /* 16 bit signed immediate */
8237 *imm_reloc = BFD_RELOC_LO16;
8238 c = my_getSmallExpression (&imm_expr, s);
8243 if (imm_expr.X_op == O_constant)
8244 imm_expr.X_add_number =
8245 (imm_expr.X_add_number >> 16) & 0xffff;
8247 else if (c == S_EX_HIGHEST)
8248 *imm_reloc = BFD_RELOC_MIPS_HIGHEST;
8249 else if (c == S_EX_HIGHER)
8250 *imm_reloc = BFD_RELOC_MIPS_HIGHER;
8251 else if (c == S_EX_GP_REL)
8253 /* This occurs in NewABI only. */
8254 c = my_getSmallExpression (&imm_expr, s);
8256 as_bad (_("bad composition of relocations"));
8259 c = my_getSmallExpression (&imm_expr, s);
8261 as_bad (_("bad composition of relocations"));
8264 imm_reloc[0] = BFD_RELOC_GPREL16;
8265 imm_reloc[1] = BFD_RELOC_MIPS_SUB;
8266 imm_reloc[2] = BFD_RELOC_LO16;
8271 else if (c == S_EX_HI)
8273 *imm_reloc = BFD_RELOC_HI16_S;
8274 imm_unmatched_hi = true;
8277 *imm_reloc = BFD_RELOC_HI16;
8279 else if (imm_expr.X_op == O_constant)
8280 imm_expr.X_add_number &= 0xffff;
8284 if ((c == S_EX_NONE && imm_expr.X_op != O_constant)
8285 || ((imm_expr.X_add_number < 0
8286 || imm_expr.X_add_number >= 0x10000)
8287 && imm_expr.X_op == O_constant))
8289 if (insn + 1 < &mips_opcodes[NUMOPCODES] &&
8290 !strcmp (insn->name, insn[1].name))
8292 if (imm_expr.X_op == O_constant
8293 || imm_expr.X_op == O_big)
8294 as_bad (_("16 bit expression not in range 0..65535"));
8302 /* The upper bound should be 0x8000, but
8303 unfortunately the MIPS assembler accepts numbers
8304 from 0x8000 to 0xffff and sign extends them, and
8305 we want to be compatible. We only permit this
8306 extended range for an instruction which does not
8307 provide any further alternates, since those
8308 alternates may handle other cases. People should
8309 use the numbers they mean, rather than relying on
8310 a mysterious sign extension. */
8311 more = (insn + 1 < &mips_opcodes[NUMOPCODES] &&
8312 strcmp (insn->name, insn[1].name) == 0);
8317 if ((c == S_EX_NONE && imm_expr.X_op != O_constant)
8318 || ((imm_expr.X_add_number < -0x8000
8319 || imm_expr.X_add_number >= max)
8320 && imm_expr.X_op == O_constant)
8322 && imm_expr.X_add_number < 0
8324 && imm_expr.X_unsigned
8325 && sizeof (imm_expr.X_add_number) <= 4))
8329 if (imm_expr.X_op == O_constant
8330 || imm_expr.X_op == O_big)
8331 as_bad (_("16 bit expression not in range -32768..32767"));
8337 case 'o': /* 16 bit offset */
8338 c = my_getSmallExpression (&offset_expr, s);
8340 /* If this value won't fit into a 16 bit offset, then go
8341 find a macro that will generate the 32 bit offset
8344 && (offset_expr.X_op != O_constant
8345 || offset_expr.X_add_number >= 0x8000
8346 || offset_expr.X_add_number < -0x8000))
8351 if (offset_expr.X_op != O_constant)
8353 offset_expr.X_add_number =
8354 (offset_expr.X_add_number >> 16) & 0xffff;
8356 *offset_reloc = BFD_RELOC_LO16;
8360 case 'p': /* pc relative offset */
8361 if (mips_pic == EMBEDDED_PIC)
8362 *offset_reloc = BFD_RELOC_16_PCREL_S2;
8364 *offset_reloc = BFD_RELOC_16_PCREL;
8365 my_getExpression (&offset_expr, s);
8369 case 'u': /* upper 16 bits */
8370 c = my_getSmallExpression (&imm_expr, s);
8371 *imm_reloc = BFD_RELOC_LO16;
8376 if (imm_expr.X_op == O_constant)
8377 imm_expr.X_add_number =
8378 (imm_expr.X_add_number >> 16) & 0xffff;
8379 else if (c == S_EX_HI)
8381 *imm_reloc = BFD_RELOC_HI16_S;
8382 imm_unmatched_hi = true;
8385 else if (c == S_EX_HIGHEST)
8386 *imm_reloc = BFD_RELOC_MIPS_HIGHEST;
8387 else if (c == S_EX_GP_REL)
8389 /* This occurs in NewABI only. */
8390 c = my_getSmallExpression (&imm_expr, s);
8392 as_bad (_("bad composition of relocations"));
8395 c = my_getSmallExpression (&imm_expr, s);
8397 as_bad (_("bad composition of relocations"));
8400 imm_reloc[0] = BFD_RELOC_GPREL16;
8401 imm_reloc[1] = BFD_RELOC_MIPS_SUB;
8402 imm_reloc[2] = BFD_RELOC_HI16_S;
8408 *imm_reloc = BFD_RELOC_HI16;
8410 else if (imm_expr.X_op == O_constant)
8411 imm_expr.X_add_number &= 0xffff;
8413 if (imm_expr.X_op == O_constant
8414 && (imm_expr.X_add_number < 0
8415 || imm_expr.X_add_number >= 0x10000))
8416 as_bad (_("lui expression not in range 0..65535"));
8420 case 'a': /* 26 bit address */
8421 my_getExpression (&offset_expr, s);
8423 *offset_reloc = BFD_RELOC_MIPS_JMP;
8426 case 'N': /* 3 bit branch condition code */
8427 case 'M': /* 3 bit compare condition code */
8428 if (strncmp (s, "$fcc", 4) != 0)
8438 while (ISDIGIT (*s));
8440 as_bad (_("invalid condition code register $fcc%d"), regno);
8442 ip->insn_opcode |= regno << OP_SH_BCC;
8444 ip->insn_opcode |= regno << OP_SH_CCC;
8448 if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X'))
8459 while (ISDIGIT (*s));
8462 c = 8; /* Invalid sel value. */
8465 as_bad (_("invalid coprocessor sub-selection value (0-7)"));
8466 ip->insn_opcode |= c;
8470 as_bad (_("bad char = '%c'\n"), *args);
8475 /* Args don't match. */
8476 if (insn + 1 < &mips_opcodes[NUMOPCODES] &&
8477 !strcmp (insn->name, insn[1].name))
8481 insn_error = _("illegal operands");
8486 insn_error = _("illegal operands");
8491 /* This routine assembles an instruction into its binary format when
8492 assembling for the mips16. As a side effect, it sets one of the
8493 global variables imm_reloc or offset_reloc to the type of
8494 relocation to do if one of the operands is an address expression.
8495 It also sets mips16_small and mips16_ext if the user explicitly
8496 requested a small or extended instruction. */
8501 struct mips_cl_insn *ip;
8505 struct mips_opcode *insn;
8508 unsigned int lastregno = 0;
8513 mips16_small = false;
8516 for (s = str; ISLOWER (*s); ++s)
8528 if (s[1] == 't' && s[2] == ' ')
8531 mips16_small = true;
8535 else if (s[1] == 'e' && s[2] == ' ')
8544 insn_error = _("unknown opcode");
8548 if (mips_opts.noautoextend && ! mips16_ext)
8549 mips16_small = true;
8551 if ((insn = (struct mips_opcode *) hash_find (mips16_op_hash, str)) == NULL)
8553 insn_error = _("unrecognized opcode");
8560 assert (strcmp (insn->name, str) == 0);
8563 ip->insn_opcode = insn->match;
8564 ip->use_extend = false;
8565 imm_expr.X_op = O_absent;
8566 imm_reloc[0] = BFD_RELOC_UNUSED;
8567 imm_reloc[1] = BFD_RELOC_UNUSED;
8568 imm_reloc[2] = BFD_RELOC_UNUSED;
8569 offset_expr.X_op = O_absent;
8570 offset_reloc[0] = BFD_RELOC_UNUSED;
8571 offset_reloc[1] = BFD_RELOC_UNUSED;
8572 offset_reloc[2] = BFD_RELOC_UNUSED;
8573 for (args = insn->args; 1; ++args)
8580 /* In this switch statement we call break if we did not find
8581 a match, continue if we did find a match, or return if we
8590 /* Stuff the immediate value in now, if we can. */
8591 if (imm_expr.X_op == O_constant
8592 && *imm_reloc > BFD_RELOC_UNUSED
8593 && insn->pinfo != INSN_MACRO)
8595 mips16_immed (NULL, 0, *imm_reloc - BFD_RELOC_UNUSED,
8596 imm_expr.X_add_number, true, mips16_small,
8597 mips16_ext, &ip->insn_opcode,
8598 &ip->use_extend, &ip->extend);
8599 imm_expr.X_op = O_absent;
8600 *imm_reloc = BFD_RELOC_UNUSED;
8614 ip->insn_opcode |= lastregno << MIPS16OP_SH_RX;
8617 ip->insn_opcode |= lastregno << MIPS16OP_SH_RY;
8633 ip->insn_opcode |= lastregno << MIPS16OP_SH_RX;
8635 ip->insn_opcode |= lastregno << MIPS16OP_SH_RY;
8662 while (ISDIGIT (*s));
8665 as_bad (_("invalid register number (%d)"), regno);
8671 if (s[1] == 'f' && s[2] == 'p')
8676 else if (s[1] == 's' && s[2] == 'p')
8681 else if (s[1] == 'g' && s[2] == 'p')
8686 else if (s[1] == 'a' && s[2] == 't')
8691 else if (s[1] == 'k' && s[2] == 't' && s[3] == '0')
8696 else if (s[1] == 'k' && s[2] == 't' && s[3] == '1')
8709 if (c == 'v' || c == 'w')
8711 regno = mips16_to_32_reg_map[lastregno];
8725 regno = mips32_to_16_reg_map[regno];
8730 regno = ILLEGAL_REG;
8735 regno = ILLEGAL_REG;
8740 regno = ILLEGAL_REG;
8745 if (regno == AT && ! mips_opts.noat)
8746 as_warn (_("used $at without \".set noat\""));
8753 if (regno == ILLEGAL_REG)
8760 ip->insn_opcode |= regno << MIPS16OP_SH_RX;
8764 ip->insn_opcode |= regno << MIPS16OP_SH_RY;
8767 ip->insn_opcode |= regno << MIPS16OP_SH_RZ;
8770 ip->insn_opcode |= regno << MIPS16OP_SH_MOVE32Z;
8776 ip->insn_opcode |= regno << MIPS16OP_SH_REGR32;
8779 regno = ((regno & 7) << 2) | ((regno & 0x18) >> 3);
8780 ip->insn_opcode |= regno << MIPS16OP_SH_REG32R;
8790 if (strncmp (s, "$pc", 3) == 0)
8814 && strncmp (s + 1, "gprel(", sizeof "gprel(" - 1) == 0)
8816 /* This is %gprel(SYMBOL). We need to read SYMBOL,
8817 and generate the appropriate reloc. If the text
8818 inside %gprel is not a symbol name with an
8819 optional offset, then we generate a normal reloc
8820 and will probably fail later. */
8821 my_getExpression (&imm_expr, s + sizeof "%gprel" - 1);
8822 if (imm_expr.X_op == O_symbol)
8825 *imm_reloc = BFD_RELOC_MIPS16_GPREL;
8827 ip->use_extend = true;
8834 /* Just pick up a normal expression. */
8835 my_getExpression (&imm_expr, s);
8838 if (imm_expr.X_op == O_register)
8840 /* What we thought was an expression turned out to
8843 if (s[0] == '(' && args[1] == '(')
8845 /* It looks like the expression was omitted
8846 before a register indirection, which means
8847 that the expression is implicitly zero. We
8848 still set up imm_expr, so that we handle
8849 explicit extensions correctly. */
8850 imm_expr.X_op = O_constant;
8851 imm_expr.X_add_number = 0;
8852 *imm_reloc = (int) BFD_RELOC_UNUSED + c;
8859 /* We need to relax this instruction. */
8860 *imm_reloc = (int) BFD_RELOC_UNUSED + c;
8869 /* We use offset_reloc rather than imm_reloc for the PC
8870 relative operands. This lets macros with both
8871 immediate and address operands work correctly. */
8872 my_getExpression (&offset_expr, s);
8874 if (offset_expr.X_op == O_register)
8877 /* We need to relax this instruction. */
8878 *offset_reloc = (int) BFD_RELOC_UNUSED + c;
8882 case '6': /* break code */
8883 my_getExpression (&imm_expr, s);
8884 check_absolute_expr (ip, &imm_expr);
8885 if ((unsigned long) imm_expr.X_add_number > 63)
8887 as_warn (_("Invalid value for `%s' (%lu)"),
8889 (unsigned long) imm_expr.X_add_number);
8890 imm_expr.X_add_number &= 0x3f;
8892 ip->insn_opcode |= imm_expr.X_add_number << MIPS16OP_SH_IMM6;
8893 imm_expr.X_op = O_absent;
8897 case 'a': /* 26 bit address */
8898 my_getExpression (&offset_expr, s);
8900 *offset_reloc = BFD_RELOC_MIPS16_JMP;
8901 ip->insn_opcode <<= 16;
8904 case 'l': /* register list for entry macro */
8905 case 'L': /* register list for exit macro */
8915 int freg, reg1, reg2;
8917 while (*s == ' ' || *s == ',')
8921 as_bad (_("can't parse register list"));
8933 while (ISDIGIT (*s))
8955 as_bad (_("invalid register list"));
8960 while (ISDIGIT (*s))
8967 if (freg && reg1 == 0 && reg2 == 0 && c == 'L')
8972 else if (freg && reg1 == 0 && reg2 == 1 && c == 'L')
8977 else if (reg1 == 4 && reg2 >= 4 && reg2 <= 7 && c != 'L')
8978 mask |= (reg2 - 3) << 3;
8979 else if (reg1 == 16 && reg2 >= 16 && reg2 <= 17)
8980 mask |= (reg2 - 15) << 1;
8981 else if (reg1 == 31 && reg2 == 31)
8985 as_bad (_("invalid register list"));
8989 /* The mask is filled in in the opcode table for the
8990 benefit of the disassembler. We remove it before
8991 applying the actual mask. */
8992 ip->insn_opcode &= ~ ((7 << 3) << MIPS16OP_SH_IMM6);
8993 ip->insn_opcode |= mask << MIPS16OP_SH_IMM6;
8997 case 'e': /* extend code */
8998 my_getExpression (&imm_expr, s);
8999 check_absolute_expr (ip, &imm_expr);
9000 if ((unsigned long) imm_expr.X_add_number > 0x7ff)
9002 as_warn (_("Invalid value for `%s' (%lu)"),
9004 (unsigned long) imm_expr.X_add_number);
9005 imm_expr.X_add_number &= 0x7ff;
9007 ip->insn_opcode |= imm_expr.X_add_number;
9008 imm_expr.X_op = O_absent;
9018 /* Args don't match. */
9019 if (insn + 1 < &mips16_opcodes[bfd_mips16_num_opcodes] &&
9020 strcmp (insn->name, insn[1].name) == 0)
9027 insn_error = _("illegal operands");
9033 /* This structure holds information we know about a mips16 immediate
9036 struct mips16_immed_operand
9038 /* The type code used in the argument string in the opcode table. */
9040 /* The number of bits in the short form of the opcode. */
9042 /* The number of bits in the extended form of the opcode. */
9044 /* The amount by which the short form is shifted when it is used;
9045 for example, the sw instruction has a shift count of 2. */
9047 /* The amount by which the short form is shifted when it is stored
9048 into the instruction code. */
9050 /* Non-zero if the short form is unsigned. */
9052 /* Non-zero if the extended form is unsigned. */
9054 /* Non-zero if the value is PC relative. */
9058 /* The mips16 immediate operand types. */
9060 static const struct mips16_immed_operand mips16_immed_operands[] =
9062 { '<', 3, 5, 0, MIPS16OP_SH_RZ, 1, 1, 0 },
9063 { '>', 3, 5, 0, MIPS16OP_SH_RX, 1, 1, 0 },
9064 { '[', 3, 6, 0, MIPS16OP_SH_RZ, 1, 1, 0 },
9065 { ']', 3, 6, 0, MIPS16OP_SH_RX, 1, 1, 0 },
9066 { '4', 4, 15, 0, MIPS16OP_SH_IMM4, 0, 0, 0 },
9067 { '5', 5, 16, 0, MIPS16OP_SH_IMM5, 1, 0, 0 },
9068 { 'H', 5, 16, 1, MIPS16OP_SH_IMM5, 1, 0, 0 },
9069 { 'W', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 0 },
9070 { 'D', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 0 },
9071 { 'j', 5, 16, 0, MIPS16OP_SH_IMM5, 0, 0, 0 },
9072 { '8', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 0, 0 },
9073 { 'V', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 0 },
9074 { 'C', 8, 16, 3, MIPS16OP_SH_IMM8, 1, 0, 0 },
9075 { 'U', 8, 16, 0, MIPS16OP_SH_IMM8, 1, 1, 0 },
9076 { 'k', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 0 },
9077 { 'K', 8, 16, 3, MIPS16OP_SH_IMM8, 0, 0, 0 },
9078 { 'p', 8, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 },
9079 { 'q', 11, 16, 0, MIPS16OP_SH_IMM8, 0, 0, 1 },
9080 { 'A', 8, 16, 2, MIPS16OP_SH_IMM8, 1, 0, 1 },
9081 { 'B', 5, 16, 3, MIPS16OP_SH_IMM5, 1, 0, 1 },
9082 { 'E', 5, 16, 2, MIPS16OP_SH_IMM5, 1, 0, 1 }
9085 #define MIPS16_NUM_IMMED \
9086 (sizeof mips16_immed_operands / sizeof mips16_immed_operands[0])
9088 /* Handle a mips16 instruction with an immediate value. This or's the
9089 small immediate value into *INSN. It sets *USE_EXTEND to indicate
9090 whether an extended value is needed; if one is needed, it sets
9091 *EXTEND to the value. The argument type is TYPE. The value is VAL.
9092 If SMALL is true, an unextended opcode was explicitly requested.
9093 If EXT is true, an extended opcode was explicitly requested. If
9094 WARN is true, warn if EXT does not match reality. */
9097 mips16_immed (file, line, type, val, warn, small, ext, insn, use_extend,
9106 unsigned long *insn;
9107 boolean *use_extend;
9108 unsigned short *extend;
9110 register const struct mips16_immed_operand *op;
9111 int mintiny, maxtiny;
9114 op = mips16_immed_operands;
9115 while (op->type != type)
9118 assert (op < mips16_immed_operands + MIPS16_NUM_IMMED);
9123 if (type == '<' || type == '>' || type == '[' || type == ']')
9126 maxtiny = 1 << op->nbits;
9131 maxtiny = (1 << op->nbits) - 1;
9136 mintiny = - (1 << (op->nbits - 1));
9137 maxtiny = (1 << (op->nbits - 1)) - 1;
9140 /* Branch offsets have an implicit 0 in the lowest bit. */
9141 if (type == 'p' || type == 'q')
9144 if ((val & ((1 << op->shift) - 1)) != 0
9145 || val < (mintiny << op->shift)
9146 || val > (maxtiny << op->shift))
9151 if (warn && ext && ! needext)
9152 as_warn_where (file, line,
9153 _("extended operand requested but not required"));
9154 if (small && needext)
9155 as_bad_where (file, line, _("invalid unextended operand value"));
9157 if (small || (! ext && ! needext))
9161 *use_extend = false;
9162 insnval = ((val >> op->shift) & ((1 << op->nbits) - 1));
9163 insnval <<= op->op_shift;
9168 long minext, maxext;
9174 maxext = (1 << op->extbits) - 1;
9178 minext = - (1 << (op->extbits - 1));
9179 maxext = (1 << (op->extbits - 1)) - 1;
9181 if (val < minext || val > maxext)
9182 as_bad_where (file, line,
9183 _("operand value out of range for instruction"));
9186 if (op->extbits == 16)
9188 extval = ((val >> 11) & 0x1f) | (val & 0x7e0);
9191 else if (op->extbits == 15)
9193 extval = ((val >> 11) & 0xf) | (val & 0x7f0);
9198 extval = ((val & 0x1f) << 6) | (val & 0x20);
9202 *extend = (unsigned short) extval;
9207 static struct percent_op_match
9210 const enum small_ex_type type;
9214 {"%half", S_EX_HALF},
9219 {"%gp_rel", S_EX_GP_REL},
9221 {"%call16", S_EX_CALL16},
9222 {"%got_disp", S_EX_GOT_DISP},
9223 {"%got_page", S_EX_GOT_PAGE},
9224 {"%got_ofst", S_EX_GOT_OFST},
9225 {"%got_hi", S_EX_GOT_HI},
9226 {"%got_lo", S_EX_GOT_LO},
9228 {"%higher", S_EX_HIGHER},
9229 {"%highest", S_EX_HIGHEST},
9230 {"%call_hi", S_EX_CALL_HI},
9231 {"%call_lo", S_EX_CALL_LO}
9235 /* Parse small expression input. STR gets adjusted to eat up whitespace.
9236 It detects valid "%percent_op(...)" and "($reg)" strings. Percent_op's
9237 can be nested, this is handled by blanking the innermost, parsing the
9238 rest by subsequent calls. */
9241 my_getSmallParser (str, len, nestlevel)
9246 int type = S_EX_NONE;
9249 *str += strspn (*str, " \t");
9252 char *b = *str + 1 + strspn (*str + 1, " \t");
9255 /* Check for base register. */
9259 && (e = b + strcspn (b, ") \t"))
9260 && e - b > 1 && e - b < 4)
9263 && ((b[1] == 'f' && b[2] == 'p')
9264 || (b[1] == 's' && b[2] == 'p')
9265 || (b[1] == 'g' && b[2] == 'p')
9266 || (b[1] == 'a' && b[2] == 't')
9268 && ISDIGIT (b[2]))))
9269 || (ISDIGIT (b[1])))
9271 *len = strcspn (*str, ")") + 1;
9272 return S_EX_REGISTER;
9276 else if (b[0] == '%')
9282 /* Some other expression in the braces. */
9283 *len = strcspn (*str, ")") + 1;
9285 /* Check for percent_op. */
9286 else if (*str[0] == '%')
9295 while (ISALPHA (*tmp) || *tmp == '_')
9297 *tmp = TOLOWER (*tmp);
9300 while (i < (sizeof (percent_op) / sizeof (struct percent_op_match)))
9302 if (strncmp (*str, percent_op[i].str, strlen (percent_op[i].str)))
9306 type = percent_op[i].type;
9308 /* Only %hi and %lo are allowed for OldABI. */
9309 if (! HAVE_NEWABI && type != S_EX_HI && type != S_EX_LO)
9312 *len = strlen (percent_op[i].str);
9319 /* Any other expression. */
9324 my_getSmallExpression (ep, str)
9328 static char *oldstr = NULL;
9334 /* Don't update oldstr if the last call had nested percent_op's. */
9341 c = my_getSmallParser (&str, &len, &nest_level);
9342 if (c != S_EX_NONE && c != S_EX_REGISTER)
9345 while (c != S_EX_NONE && c != S_EX_REGISTER);
9347 /* A percent_op was encountered. */
9350 /* Don't try to get an expression if it is already blanked out. */
9351 if (*(str + strspn (str + 1, " )")) != ')')
9355 save = *(str + len);
9356 *(str + len) = '\0';
9357 my_getExpression (ep, str);
9358 *(str + len) = save;
9362 /* blank out including the % sign. */
9363 char *p = strrchr (oldstr, '%');
9364 memset (p, ' ', str - p + len);
9369 expr_end = strchr (str, ')') + 1;
9373 else if (c == S_EX_NONE)
9375 my_getExpression (ep, str);
9377 else if (c == S_EX_REGISTER)
9379 ep->X_op = O_constant;
9381 ep->X_add_symbol = NULL;
9382 ep->X_op_symbol = NULL;
9383 ep->X_add_number = 0;
9387 as_fatal(_("internal error"));
9390 if (nest_level <= 1)
9397 my_getExpression (ep, str)
9404 save_in = input_line_pointer;
9405 input_line_pointer = str;
9407 expr_end = input_line_pointer;
9408 input_line_pointer = save_in;
9410 /* If we are in mips16 mode, and this is an expression based on `.',
9411 then we bump the value of the symbol by 1 since that is how other
9412 text symbols are handled. We don't bother to handle complex
9413 expressions, just `.' plus or minus a constant. */
9414 if (mips_opts.mips16
9415 && ep->X_op == O_symbol
9416 && strcmp (S_GET_NAME (ep->X_add_symbol), FAKE_LABEL_NAME) == 0
9417 && S_GET_SEGMENT (ep->X_add_symbol) == now_seg
9418 && symbol_get_frag (ep->X_add_symbol) == frag_now
9419 && symbol_constant_p (ep->X_add_symbol)
9420 && (val = S_GET_VALUE (ep->X_add_symbol)) == frag_now_fix ())
9421 S_SET_VALUE (ep->X_add_symbol, val + 1);
9424 /* Turn a string in input_line_pointer into a floating point constant
9425 of type TYPE, and store the appropriate bytes in *LITP. The number
9426 of LITTLENUMS emitted is stored in *SIZEP. An error message is
9427 returned, or NULL on OK. */
9430 md_atof (type, litP, sizeP)
9436 LITTLENUM_TYPE words[4];
9452 return _("bad call to md_atof");
9455 t = atof_ieee (input_line_pointer, type, words);
9457 input_line_pointer = t;
9461 if (! target_big_endian)
9463 for (i = prec - 1; i >= 0; i--)
9465 md_number_to_chars (litP, (valueT) words[i], 2);
9471 for (i = 0; i < prec; i++)
9473 md_number_to_chars (litP, (valueT) words[i], 2);
9482 md_number_to_chars (buf, val, n)
9487 if (target_big_endian)
9488 number_to_chars_bigendian (buf, val, n);
9490 number_to_chars_littleendian (buf, val, n);
9494 static int support_64bit_objects(void)
9496 const char **list, **l;
9498 list = bfd_target_list ();
9499 for (l = list; *l != NULL; l++)
9501 /* This is traditional mips */
9502 if (strcmp (*l, "elf64-tradbigmips") == 0
9503 || strcmp (*l, "elf64-tradlittlemips") == 0)
9505 if (strcmp (*l, "elf64-bigmips") == 0
9506 || strcmp (*l, "elf64-littlemips") == 0)
9510 return (*l != NULL);
9512 #endif /* OBJ_ELF */
9514 CONST char *md_shortopts = "nO::g::G:";
9516 struct option md_longopts[] =
9518 #define OPTION_MIPS1 (OPTION_MD_BASE + 1)
9519 {"mips0", no_argument, NULL, OPTION_MIPS1},
9520 {"mips1", no_argument, NULL, OPTION_MIPS1},
9521 #define OPTION_MIPS2 (OPTION_MD_BASE + 2)
9522 {"mips2", no_argument, NULL, OPTION_MIPS2},
9523 #define OPTION_MIPS3 (OPTION_MD_BASE + 3)
9524 {"mips3", no_argument, NULL, OPTION_MIPS3},
9525 #define OPTION_MIPS4 (OPTION_MD_BASE + 4)
9526 {"mips4", no_argument, NULL, OPTION_MIPS4},
9527 #define OPTION_MIPS5 (OPTION_MD_BASE + 5)
9528 {"mips5", no_argument, NULL, OPTION_MIPS5},
9529 #define OPTION_MIPS32 (OPTION_MD_BASE + 6)
9530 {"mips32", no_argument, NULL, OPTION_MIPS32},
9531 #define OPTION_MIPS64 (OPTION_MD_BASE + 7)
9532 {"mips64", no_argument, NULL, OPTION_MIPS64},
9533 #define OPTION_MEMBEDDED_PIC (OPTION_MD_BASE + 8)
9534 {"membedded-pic", no_argument, NULL, OPTION_MEMBEDDED_PIC},
9535 #define OPTION_TRAP (OPTION_MD_BASE + 9)
9536 {"trap", no_argument, NULL, OPTION_TRAP},
9537 {"no-break", no_argument, NULL, OPTION_TRAP},
9538 #define OPTION_BREAK (OPTION_MD_BASE + 10)
9539 {"break", no_argument, NULL, OPTION_BREAK},
9540 {"no-trap", no_argument, NULL, OPTION_BREAK},
9541 #define OPTION_EB (OPTION_MD_BASE + 11)
9542 {"EB", no_argument, NULL, OPTION_EB},
9543 #define OPTION_EL (OPTION_MD_BASE + 12)
9544 {"EL", no_argument, NULL, OPTION_EL},
9545 #define OPTION_MIPS16 (OPTION_MD_BASE + 13)
9546 {"mips16", no_argument, NULL, OPTION_MIPS16},
9547 #define OPTION_NO_MIPS16 (OPTION_MD_BASE + 14)
9548 {"no-mips16", no_argument, NULL, OPTION_NO_MIPS16},
9549 #define OPTION_M7000_HILO_FIX (OPTION_MD_BASE + 15)
9550 {"mfix7000", no_argument, NULL, OPTION_M7000_HILO_FIX},
9551 #define OPTION_NO_M7000_HILO_FIX (OPTION_MD_BASE + 16)
9552 {"no-fix-7000", no_argument, NULL, OPTION_NO_M7000_HILO_FIX},
9553 #define OPTION_FP32 (OPTION_MD_BASE + 17)
9554 {"mfp32", no_argument, NULL, OPTION_FP32},
9555 #define OPTION_GP32 (OPTION_MD_BASE + 18)
9556 {"mgp32", no_argument, NULL, OPTION_GP32},
9557 #define OPTION_CONSTRUCT_FLOATS (OPTION_MD_BASE + 19)
9558 {"construct-floats", no_argument, NULL, OPTION_CONSTRUCT_FLOATS},
9559 #define OPTION_NO_CONSTRUCT_FLOATS (OPTION_MD_BASE + 20)
9560 {"no-construct-floats", no_argument, NULL, OPTION_NO_CONSTRUCT_FLOATS},
9561 #define OPTION_MARCH (OPTION_MD_BASE + 21)
9562 {"march", required_argument, NULL, OPTION_MARCH},
9563 #define OPTION_MTUNE (OPTION_MD_BASE + 22)
9564 {"mtune", required_argument, NULL, OPTION_MTUNE},
9565 #define OPTION_MCPU (OPTION_MD_BASE + 23)
9566 {"mcpu", required_argument, NULL, OPTION_MCPU},
9567 #define OPTION_M4650 (OPTION_MD_BASE + 24)
9568 {"m4650", no_argument, NULL, OPTION_M4650},
9569 #define OPTION_NO_M4650 (OPTION_MD_BASE + 25)
9570 {"no-m4650", no_argument, NULL, OPTION_NO_M4650},
9571 #define OPTION_M4010 (OPTION_MD_BASE + 26)
9572 {"m4010", no_argument, NULL, OPTION_M4010},
9573 #define OPTION_NO_M4010 (OPTION_MD_BASE + 27)
9574 {"no-m4010", no_argument, NULL, OPTION_NO_M4010},
9575 #define OPTION_M4100 (OPTION_MD_BASE + 28)
9576 {"m4100", no_argument, NULL, OPTION_M4100},
9577 #define OPTION_NO_M4100 (OPTION_MD_BASE + 29)
9578 {"no-m4100", no_argument, NULL, OPTION_NO_M4100},
9579 #define OPTION_M3900 (OPTION_MD_BASE + 30)
9580 {"m3900", no_argument, NULL, OPTION_M3900},
9581 #define OPTION_NO_M3900 (OPTION_MD_BASE + 31)
9582 {"no-m3900", no_argument, NULL, OPTION_NO_M3900},
9583 #define OPTION_GP64 (OPTION_MD_BASE + 32)
9584 {"mgp64", no_argument, NULL, OPTION_GP64},
9586 #define OPTION_ELF_BASE (OPTION_MD_BASE + 33)
9587 #define OPTION_CALL_SHARED (OPTION_ELF_BASE + 0)
9588 {"KPIC", no_argument, NULL, OPTION_CALL_SHARED},
9589 {"call_shared", no_argument, NULL, OPTION_CALL_SHARED},
9590 #define OPTION_NON_SHARED (OPTION_ELF_BASE + 1)
9591 {"non_shared", no_argument, NULL, OPTION_NON_SHARED},
9592 #define OPTION_XGOT (OPTION_ELF_BASE + 2)
9593 {"xgot", no_argument, NULL, OPTION_XGOT},
9594 #define OPTION_MABI (OPTION_ELF_BASE + 3)
9595 {"mabi", required_argument, NULL, OPTION_MABI},
9596 #define OPTION_32 (OPTION_ELF_BASE + 4)
9597 {"32", no_argument, NULL, OPTION_32},
9598 #define OPTION_N32 (OPTION_ELF_BASE + 5)
9599 {"n32", no_argument, NULL, OPTION_N32},
9600 #define OPTION_64 (OPTION_ELF_BASE + 6)
9601 {"64", no_argument, NULL, OPTION_64},
9602 #endif /* OBJ_ELF */
9603 {NULL, no_argument, NULL, 0}
9605 size_t md_longopts_size = sizeof (md_longopts);
9608 md_parse_option (c, arg)
9614 case OPTION_CONSTRUCT_FLOATS:
9615 mips_disable_float_construction = 0;
9618 case OPTION_NO_CONSTRUCT_FLOATS:
9619 mips_disable_float_construction = 1;
9631 target_big_endian = 1;
9635 target_big_endian = 0;
9643 if (arg && arg[1] == '0')
9653 mips_debug = atoi (arg);
9654 /* When the MIPS assembler sees -g or -g2, it does not do
9655 optimizations which limit full symbolic debugging. We take
9656 that to be equivalent to -O0. */
9657 if (mips_debug == 2)
9662 mips_opts.isa = ISA_MIPS1;
9666 mips_opts.isa = ISA_MIPS2;
9670 mips_opts.isa = ISA_MIPS3;
9674 mips_opts.isa = ISA_MIPS4;
9678 mips_opts.isa = ISA_MIPS5;
9682 mips_opts.isa = ISA_MIPS32;
9686 mips_opts.isa = ISA_MIPS64;
9693 int cpu = CPU_UNKNOWN;
9695 /* Identify the processor type. */
9696 if (strcasecmp (arg, "default") != 0)
9698 const struct mips_cpu_info *ci;
9700 ci = mips_cpu_info_from_name (arg);
9701 if (ci == NULL || ci->is_isa)
9706 as_fatal (_("invalid architecture -mtune=%s"), arg);
9709 as_fatal (_("invalid architecture -march=%s"), arg);
9712 as_fatal (_("invalid architecture -mcpu=%s"), arg);
9723 if (mips_tune != CPU_UNKNOWN && mips_tune != cpu)
9724 as_warn(_("A different -mtune= was already specified, is now "
9729 if (mips_arch != CPU_UNKNOWN && mips_arch != cpu)
9730 as_warn(_("A different -march= was already specified, is now "
9735 if (mips_cpu != CPU_UNKNOWN && mips_cpu != cpu)
9736 as_warn(_("A different -mcpu= was already specified, is now "
9744 if ((mips_arch != CPU_UNKNOWN && mips_arch != CPU_R4650)
9745 || (mips_tune != CPU_UNKNOWN && mips_tune != CPU_R4650))
9746 as_warn(_("A different -march= or -mtune= was already specified, "
9748 mips_arch = CPU_R4650;
9749 mips_tune = CPU_R4650;
9752 case OPTION_NO_M4650:
9756 if ((mips_arch != CPU_UNKNOWN && mips_arch != CPU_R4010)
9757 || (mips_tune != CPU_UNKNOWN && mips_tune != CPU_R4010))
9758 as_warn(_("A different -march= or -mtune= was already specified, "
9760 mips_arch = CPU_R4010;
9761 mips_tune = CPU_R4010;
9764 case OPTION_NO_M4010:
9768 if ((mips_arch != CPU_UNKNOWN && mips_arch != CPU_VR4100)
9769 || (mips_tune != CPU_UNKNOWN && mips_tune != CPU_VR4100))
9770 as_warn(_("A different -march= or -mtune= was already specified, "
9772 mips_arch = CPU_VR4100;
9773 mips_tune = CPU_VR4100;
9776 case OPTION_NO_M4100:
9780 if ((mips_arch != CPU_UNKNOWN && mips_arch != CPU_R3900)
9781 || (mips_tune != CPU_UNKNOWN && mips_tune != CPU_R3900))
9782 as_warn(_("A different -march= or -mtune= was already specified, "
9784 mips_arch = CPU_R3900;
9785 mips_tune = CPU_R3900;
9788 case OPTION_NO_M3900:
9792 mips_opts.mips16 = 1;
9793 mips_no_prev_insn (false);
9796 case OPTION_NO_MIPS16:
9797 mips_opts.mips16 = 0;
9798 mips_no_prev_insn (false);
9801 case OPTION_MEMBEDDED_PIC:
9802 mips_pic = EMBEDDED_PIC;
9803 if (USE_GLOBAL_POINTER_OPT && g_switch_seen)
9805 as_bad (_("-G may not be used with embedded PIC code"));
9808 g_switch_value = 0x7fffffff;
9812 /* When generating ELF code, we permit -KPIC and -call_shared to
9813 select SVR4_PIC, and -non_shared to select no PIC. This is
9814 intended to be compatible with Irix 5. */
9815 case OPTION_CALL_SHARED:
9816 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
9818 as_bad (_("-call_shared is supported only for ELF format"));
9821 mips_pic = SVR4_PIC;
9822 if (g_switch_seen && g_switch_value != 0)
9824 as_bad (_("-G may not be used with SVR4 PIC code"));
9830 case OPTION_NON_SHARED:
9831 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
9833 as_bad (_("-non_shared is supported only for ELF format"));
9839 /* The -xgot option tells the assembler to use 32 offsets when
9840 accessing the got in SVR4_PIC mode. It is for Irix
9845 #endif /* OBJ_ELF */
9848 if (! USE_GLOBAL_POINTER_OPT)
9850 as_bad (_("-G is not supported for this configuration"));
9853 else if (mips_pic == SVR4_PIC || mips_pic == EMBEDDED_PIC)
9855 as_bad (_("-G may not be used with SVR4 or embedded PIC code"));
9859 g_switch_value = atoi (arg);
9864 /* The -32, -n32 and -64 options are shortcuts for -mabi=32, -mabi=n32
9867 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
9869 as_bad (_("-32 is supported for ELF format only"));
9872 mips_opts.abi = O32_ABI;
9876 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
9878 as_bad (_("-n32 is supported for ELF format only"));
9881 mips_opts.abi = N32_ABI;
9885 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
9887 as_bad (_("-64 is supported for ELF format only"));
9890 mips_opts.abi = N64_ABI;
9891 if (! support_64bit_objects())
9892 as_fatal (_("No compiled in support for 64 bit object file format"));
9894 #endif /* OBJ_ELF */
9898 if (mips_opts.abi != O32_ABI)
9899 mips_opts.abi = NO_ABI;
9904 if (mips_opts.abi == O32_ABI)
9905 mips_opts.abi = NO_ABI;
9910 if (mips_opts.abi != O32_ABI)
9911 mips_opts.abi = NO_ABI;
9916 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
9918 as_bad (_("-mabi is supported for ELF format only"));
9921 if (strcmp (arg, "32") == 0)
9922 mips_opts.abi = O32_ABI;
9923 else if (strcmp (arg, "o64") == 0)
9924 mips_opts.abi = O64_ABI;
9925 else if (strcmp (arg, "n32") == 0)
9926 mips_opts.abi = N32_ABI;
9927 else if (strcmp (arg, "64") == 0)
9929 mips_opts.abi = N64_ABI;
9930 if (! support_64bit_objects())
9931 as_fatal (_("No compiled in support for 64 bit object file "
9934 else if (strcmp (arg, "eabi") == 0)
9935 mips_opts.abi = EABI_ABI;
9937 mips_opts.abi = NO_ABI;
9939 #endif /* OBJ_ELF */
9941 case OPTION_M7000_HILO_FIX:
9942 mips_7000_hilo_fix = true;
9945 case OPTION_NO_M7000_HILO_FIX:
9946 mips_7000_hilo_fix = false;
9957 show (stream, string, col_p, first_p)
9965 fprintf (stream, "%24s", "");
9970 fprintf (stream, ", ");
9974 if (*col_p + strlen (string) > 72)
9976 fprintf (stream, "\n%24s", "");
9980 fprintf (stream, "%s", string);
9981 *col_p += strlen (string);
9987 md_show_usage (stream)
9992 fprintf (stream, _("\
9994 -membedded-pic generate embedded position independent code\n\
9995 -EB generate big endian output\n\
9996 -EL generate little endian output\n\
9997 -g, -g2 do not remove unneeded NOPs or swap branches\n\
9998 -G NUM allow referencing objects up to NUM bytes\n\
9999 implicitly with the gp register [default 8]\n"));
10000 fprintf (stream, _("\
10001 -mips1 generate MIPS ISA I instructions\n\
10002 -mips2 generate MIPS ISA II instructions\n\
10003 -mips3 generate MIPS ISA III instructions\n\
10004 -mips4 generate MIPS ISA IV instructions\n\
10005 -mips5 generate MIPS ISA V instructions\n\
10006 -mips32 generate MIPS32 ISA instructions\n\
10007 -mips64 generate MIPS64 ISA instructions\n\
10008 -march=CPU/-mtune=CPU generate code/schedule for CPU, where CPU is one of:\n"));
10012 show (stream, "2000", &column, &first);
10013 show (stream, "3000", &column, &first);
10014 show (stream, "3900", &column, &first);
10015 show (stream, "4000", &column, &first);
10016 show (stream, "4010", &column, &first);
10017 show (stream, "4100", &column, &first);
10018 show (stream, "4111", &column, &first);
10019 show (stream, "4300", &column, &first);
10020 show (stream, "4400", &column, &first);
10021 show (stream, "4600", &column, &first);
10022 show (stream, "4650", &column, &first);
10023 show (stream, "5000", &column, &first);
10024 show (stream, "5200", &column, &first);
10025 show (stream, "5230", &column, &first);
10026 show (stream, "5231", &column, &first);
10027 show (stream, "5261", &column, &first);
10028 show (stream, "5721", &column, &first);
10029 show (stream, "6000", &column, &first);
10030 show (stream, "8000", &column, &first);
10031 show (stream, "10000", &column, &first);
10032 show (stream, "12000", &column, &first);
10033 show (stream, "sb1", &column, &first);
10034 fputc ('\n', stream);
10036 fprintf (stream, _("\
10037 -mCPU equivalent to -march=CPU -mtune=CPU. Deprecated.\n\
10038 -no-mCPU don't generate code specific to CPU.\n\
10039 For -mCPU and -no-mCPU, CPU must be one of:\n"));
10043 show (stream, "3900", &column, &first);
10044 show (stream, "4010", &column, &first);
10045 show (stream, "4100", &column, &first);
10046 show (stream, "4650", &column, &first);
10047 fputc ('\n', stream);
10049 fprintf (stream, _("\
10050 -mips16 generate mips16 instructions\n\
10051 -no-mips16 do not generate mips16 instructions\n"));
10052 fprintf (stream, _("\
10053 -mgp32 use 32-bit GPRs, regardless of the chosen ISA\n\
10054 -mfp32 use 32-bit FPRs, regardless of the chosen ISA\n\
10055 -O0 remove unneeded NOPs, do not swap branches\n\
10056 -O remove unneeded NOPs and swap branches\n\
10057 -n warn about NOPs generated from macros\n\
10058 --[no-]construct-floats [dis]allow floating point values to be constructed\n\
10059 --trap, --no-break trap exception on div by 0 and mult overflow\n\
10060 --break, --no-trap break exception on div by 0 and mult overflow\n"));
10062 fprintf (stream, _("\
10063 -KPIC, -call_shared generate SVR4 position independent code\n\
10064 -non_shared do not generate position independent code\n\
10065 -xgot assume a 32 bit GOT\n\
10066 -mabi=ABI create ABI conformant object file for:\n"));
10070 show (stream, "32", &column, &first);
10071 show (stream, "o64", &column, &first);
10072 show (stream, "n32", &column, &first);
10073 show (stream, "64", &column, &first);
10074 show (stream, "eabi", &column, &first);
10076 fputc ('\n', stream);
10078 fprintf (stream, _("\
10079 -32 create o32 ABI object file (default)\n\
10080 -n32 create n32 ABI object file\n\
10081 -64 create 64 ABI object file\n"));
10086 mips_init_after_args ()
10088 /* initialize opcodes */
10089 bfd_mips_num_opcodes = bfd_mips_num_builtin_opcodes;
10090 mips_opcodes = (struct mips_opcode *) mips_builtin_opcodes;
10094 md_pcrel_from (fixP)
10097 if (OUTPUT_FLAVOR != bfd_target_aout_flavour
10098 && fixP->fx_addsy != (symbolS *) NULL
10099 && ! S_IS_DEFINED (fixP->fx_addsy))
10101 /* This makes a branch to an undefined symbol be a branch to the
10102 current location. */
10103 if (mips_pic == EMBEDDED_PIC)
10109 /* return the address of the delay slot */
10110 return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address;
10113 /* This is called before the symbol table is processed. In order to
10114 work with gcc when using mips-tfile, we must keep all local labels.
10115 However, in other cases, we want to discard them. If we were
10116 called with -g, but we didn't see any debugging information, it may
10117 mean that gcc is smuggling debugging information through to
10118 mips-tfile, in which case we must generate all local labels. */
10121 mips_frob_file_before_adjust ()
10123 #ifndef NO_ECOFF_DEBUGGING
10124 if (ECOFF_DEBUGGING
10126 && ! ecoff_debugging_seen)
10127 flag_keep_locals = 1;
10131 /* Sort any unmatched HI16_S relocs so that they immediately precede
10132 the corresponding LO reloc. This is called before md_apply_fix3 and
10133 tc_gen_reloc. Unmatched HI16_S relocs can only be generated by
10134 explicit use of the %hi modifier. */
10139 struct mips_hi_fixup *l;
10141 for (l = mips_hi_fixup_list; l != NULL; l = l->next)
10143 segment_info_type *seginfo;
10146 assert (l->fixp->fx_r_type == BFD_RELOC_HI16_S);
10148 /* Check quickly whether the next fixup happens to be a matching
10150 if (l->fixp->fx_next != NULL
10151 && l->fixp->fx_next->fx_r_type == BFD_RELOC_LO16
10152 && l->fixp->fx_addsy == l->fixp->fx_next->fx_addsy
10153 && l->fixp->fx_offset == l->fixp->fx_next->fx_offset)
10156 /* Look through the fixups for this segment for a matching %lo.
10157 When we find one, move the %hi just in front of it. We do
10158 this in two passes. In the first pass, we try to find a
10159 unique %lo. In the second pass, we permit multiple %hi
10160 relocs for a single %lo (this is a GNU extension). */
10161 seginfo = seg_info (l->seg);
10162 for (pass = 0; pass < 2; pass++)
10167 for (f = seginfo->fix_root; f != NULL; f = f->fx_next)
10169 /* Check whether this is a %lo fixup which matches l->fixp. */
10170 if (f->fx_r_type == BFD_RELOC_LO16
10171 && f->fx_addsy == l->fixp->fx_addsy
10172 && f->fx_offset == l->fixp->fx_offset
10175 || prev->fx_r_type != BFD_RELOC_HI16_S
10176 || prev->fx_addsy != f->fx_addsy
10177 || prev->fx_offset != f->fx_offset))
10181 /* Move l->fixp before f. */
10182 for (pf = &seginfo->fix_root;
10184 pf = &(*pf)->fx_next)
10185 assert (*pf != NULL);
10187 *pf = l->fixp->fx_next;
10189 l->fixp->fx_next = f;
10191 seginfo->fix_root = l->fixp;
10193 prev->fx_next = l->fixp;
10204 #if 0 /* GCC code motion plus incomplete dead code elimination
10205 can leave a %hi without a %lo. */
10207 as_warn_where (l->fixp->fx_file, l->fixp->fx_line,
10208 _("Unmatched %%hi reloc"));
10214 /* When generating embedded PIC code we need to use a special
10215 relocation to represent the difference of two symbols in the .text
10216 section (switch tables use a difference of this sort). See
10217 include/coff/mips.h for details. This macro checks whether this
10218 fixup requires the special reloc. */
10219 #define SWITCH_TABLE(fixp) \
10220 ((fixp)->fx_r_type == BFD_RELOC_32 \
10221 && OUTPUT_FLAVOR != bfd_target_elf_flavour \
10222 && (fixp)->fx_addsy != NULL \
10223 && (fixp)->fx_subsy != NULL \
10224 && S_GET_SEGMENT ((fixp)->fx_addsy) == text_section \
10225 && S_GET_SEGMENT ((fixp)->fx_subsy) == text_section)
10227 /* When generating embedded PIC code we must keep all PC relative
10228 relocations, in case the linker has to relax a call. We also need
10229 to keep relocations for switch table entries.
10231 We may have combined relocations without symbols in the N32/N64 ABI.
10232 We have to prevent gas from dropping them. */
10235 mips_force_relocation (fixp)
10238 if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT
10239 || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
10243 && S_GET_SEGMENT (fixp->fx_addsy) == bfd_abs_section_ptr
10244 && (fixp->fx_r_type == BFD_RELOC_MIPS_SUB
10245 || fixp->fx_r_type == BFD_RELOC_HI16_S
10246 || fixp->fx_r_type == BFD_RELOC_LO16))
10249 return (mips_pic == EMBEDDED_PIC
10251 || SWITCH_TABLE (fixp)
10252 || fixp->fx_r_type == BFD_RELOC_PCREL_HI16_S
10253 || fixp->fx_r_type == BFD_RELOC_PCREL_LO16));
10258 mips_need_elf_addend_fixup (fixP)
10261 return (S_GET_OTHER (fixP->fx_addsy) == STO_MIPS16
10262 || ((S_IS_WEAK (fixP->fx_addsy)
10263 || S_IS_EXTERN (fixP->fx_addsy))
10264 && !S_IS_COMMON (fixP->fx_addsy))
10265 || (symbol_used_in_reloc_p (fixP->fx_addsy)
10266 && (((bfd_get_section_flags (stdoutput,
10267 S_GET_SEGMENT (fixP->fx_addsy))
10268 & SEC_LINK_ONCE) != 0)
10269 || !strncmp (segment_name (S_GET_SEGMENT (fixP->fx_addsy)),
10271 sizeof (".gnu.linkonce") - 1))));
10275 /* Apply a fixup to the object file. */
10278 md_apply_fix3 (fixP, valP, seg)
10281 segT seg ATTRIBUTE_UNUSED;
10283 unsigned char *buf;
10287 assert (fixP->fx_size == 4
10288 || fixP->fx_r_type == BFD_RELOC_16
10289 || fixP->fx_r_type == BFD_RELOC_32
10290 || fixP->fx_r_type == BFD_RELOC_MIPS_JMP
10291 || fixP->fx_r_type == BFD_RELOC_HI16_S
10292 || fixP->fx_r_type == BFD_RELOC_LO16
10293 || fixP->fx_r_type == BFD_RELOC_GPREL16
10294 || fixP->fx_r_type == BFD_RELOC_MIPS_LITERAL
10295 || fixP->fx_r_type == BFD_RELOC_GPREL32
10296 || fixP->fx_r_type == BFD_RELOC_64
10297 || fixP->fx_r_type == BFD_RELOC_CTOR
10298 || fixP->fx_r_type == BFD_RELOC_MIPS_SUB
10299 || fixP->fx_r_type == BFD_RELOC_MIPS_HIGHEST
10300 || fixP->fx_r_type == BFD_RELOC_MIPS_HIGHER
10301 || fixP->fx_r_type == BFD_RELOC_MIPS_SCN_DISP
10302 || fixP->fx_r_type == BFD_RELOC_MIPS_REL16
10303 || fixP->fx_r_type == BFD_RELOC_MIPS_RELGOT
10304 || fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
10305 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY);
10309 /* If we aren't adjusting this fixup to be against the section
10310 symbol, we need to adjust the value. */
10312 if (fixP->fx_addsy != NULL && OUTPUT_FLAVOR == bfd_target_elf_flavour)
10314 if (mips_need_elf_addend_fixup (fixP))
10316 valueT symval = S_GET_VALUE (fixP->fx_addsy);
10319 if (value != 0 && ! fixP->fx_pcrel)
10321 /* In this case, the bfd_install_relocation routine will
10322 incorrectly add the symbol value back in. We just want
10323 the addend to appear in the object file. */
10326 /* Make sure the addend is still non-zero. If it became zero
10327 after the last operation, set it to a spurious value and
10328 subtract the same value from the object file's contents. */
10333 /* The in-place addends for LO16 relocations are signed;
10334 leave the matching HI16 in-place addends as zero. */
10335 if (fixP->fx_r_type != BFD_RELOC_HI16_S)
10337 reloc_howto_type *howto;
10338 bfd_vma contents, mask, field;
10340 howto = bfd_reloc_type_lookup (stdoutput,
10343 contents = bfd_get_bits (fixP->fx_frag->fr_literal
10346 target_big_endian);
10348 /* MASK has bits set where the relocation should go.
10349 FIELD is -value, shifted into the appropriate place
10350 for this relocation. */
10351 mask = 1 << (howto->bitsize - 1);
10352 mask = (((mask - 1) << 1) | 1) << howto->bitpos;
10353 field = (-value >> howto->rightshift) << howto->bitpos;
10355 bfd_put_bits ((field & mask) | (contents & ~mask),
10356 fixP->fx_frag->fr_literal + fixP->fx_where,
10358 target_big_endian);
10364 /* This code was generated using trial and error and so is
10365 fragile and not trustworthy. If you change it, you should
10366 rerun the elf-rel, elf-rel2, and empic testcases and ensure
10367 they still pass. */
10368 if (fixP->fx_pcrel || fixP->fx_subsy != NULL)
10370 value += fixP->fx_frag->fr_address + fixP->fx_where;
10372 /* BFD's REL handling, for MIPS, is _very_ weird.
10373 This gives the right results, but it can't possibly
10374 be the way things are supposed to work. */
10375 if ((fixP->fx_r_type != BFD_RELOC_16_PCREL
10376 && fixP->fx_r_type != BFD_RELOC_16_PCREL_S2)
10377 || S_GET_SEGMENT (fixP->fx_addsy) != undefined_section)
10378 value += fixP->fx_frag->fr_address + fixP->fx_where;
10383 fixP->fx_addnumber = value; /* Remember value for tc_gen_reloc. */
10385 if (fixP->fx_addsy == NULL && ! fixP->fx_pcrel)
10388 switch (fixP->fx_r_type)
10390 case BFD_RELOC_MIPS_JMP:
10391 case BFD_RELOC_MIPS_SHIFT5:
10392 case BFD_RELOC_MIPS_SHIFT6:
10393 case BFD_RELOC_MIPS_GOT_DISP:
10394 case BFD_RELOC_MIPS_GOT_PAGE:
10395 case BFD_RELOC_MIPS_GOT_OFST:
10396 case BFD_RELOC_MIPS_SUB:
10397 case BFD_RELOC_MIPS_INSERT_A:
10398 case BFD_RELOC_MIPS_INSERT_B:
10399 case BFD_RELOC_MIPS_DELETE:
10400 case BFD_RELOC_MIPS_HIGHEST:
10401 case BFD_RELOC_MIPS_HIGHER:
10402 case BFD_RELOC_MIPS_SCN_DISP:
10403 case BFD_RELOC_MIPS_REL16:
10404 case BFD_RELOC_MIPS_RELGOT:
10405 case BFD_RELOC_MIPS_JALR:
10406 case BFD_RELOC_HI16:
10407 case BFD_RELOC_HI16_S:
10408 case BFD_RELOC_GPREL16:
10409 case BFD_RELOC_MIPS_LITERAL:
10410 case BFD_RELOC_MIPS_CALL16:
10411 case BFD_RELOC_MIPS_GOT16:
10412 case BFD_RELOC_GPREL32:
10413 case BFD_RELOC_MIPS_GOT_HI16:
10414 case BFD_RELOC_MIPS_GOT_LO16:
10415 case BFD_RELOC_MIPS_CALL_HI16:
10416 case BFD_RELOC_MIPS_CALL_LO16:
10417 case BFD_RELOC_MIPS16_GPREL:
10418 if (fixP->fx_pcrel)
10419 as_bad_where (fixP->fx_file, fixP->fx_line,
10420 _("Invalid PC relative reloc"));
10421 /* Nothing needed to do. The value comes from the reloc entry */
10424 case BFD_RELOC_MIPS16_JMP:
10425 /* We currently always generate a reloc against a symbol, which
10426 means that we don't want an addend even if the symbol is
10428 fixP->fx_addnumber = 0;
10431 case BFD_RELOC_PCREL_HI16_S:
10432 /* The addend for this is tricky if it is internal, so we just
10433 do everything here rather than in bfd_install_relocation. */
10434 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
10439 && (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_SECTION_SYM) == 0)
10441 /* For an external symbol adjust by the address to make it
10442 pcrel_offset. We use the address of the RELLO reloc
10443 which follows this one. */
10444 value += (fixP->fx_next->fx_frag->fr_address
10445 + fixP->fx_next->fx_where);
10447 value = ((value + 0x8000) >> 16) & 0xffff;
10448 buf = (unsigned char *) fixP->fx_frag->fr_literal + fixP->fx_where;
10449 if (target_big_endian)
10451 md_number_to_chars (buf, value, 2);
10454 case BFD_RELOC_PCREL_LO16:
10455 /* The addend for this is tricky if it is internal, so we just
10456 do everything here rather than in bfd_install_relocation. */
10457 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
10462 && (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_SECTION_SYM) == 0)
10463 value += fixP->fx_frag->fr_address + fixP->fx_where;
10464 buf = (unsigned char *) fixP->fx_frag->fr_literal + fixP->fx_where;
10465 if (target_big_endian)
10467 md_number_to_chars (buf, value, 2);
10471 /* This is handled like BFD_RELOC_32, but we output a sign
10472 extended value if we are only 32 bits. */
10474 || (mips_pic == EMBEDDED_PIC && SWITCH_TABLE (fixP)))
10476 if (8 <= sizeof (valueT))
10477 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
10484 w1 = w2 = fixP->fx_where;
10485 if (target_big_endian)
10489 md_number_to_chars (fixP->fx_frag->fr_literal + w1, value, 4);
10490 if ((value & 0x80000000) != 0)
10494 md_number_to_chars (fixP->fx_frag->fr_literal + w2, hiv, 4);
10499 case BFD_RELOC_RVA:
10501 /* If we are deleting this reloc entry, we must fill in the
10502 value now. This can happen if we have a .word which is not
10503 resolved when it appears but is later defined. We also need
10504 to fill in the value if this is an embedded PIC switch table
10507 || (mips_pic == EMBEDDED_PIC && SWITCH_TABLE (fixP)))
10508 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
10513 /* If we are deleting this reloc entry, we must fill in the
10515 assert (fixP->fx_size == 2);
10517 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
10521 case BFD_RELOC_LO16:
10522 /* When handling an embedded PIC switch statement, we can wind
10523 up deleting a LO16 reloc. See the 'o' case in mips_ip. */
10526 if (value + 0x8000 > 0xffff)
10527 as_bad_where (fixP->fx_file, fixP->fx_line,
10528 _("relocation overflow"));
10529 buf = (unsigned char *) fixP->fx_frag->fr_literal + fixP->fx_where;
10530 if (target_big_endian)
10532 md_number_to_chars (buf, value, 2);
10536 case BFD_RELOC_16_PCREL_S2:
10537 if ((value & 0x3) != 0)
10538 as_bad_where (fixP->fx_file, fixP->fx_line,
10539 _("Branch to odd address (%lx)"), (long) value);
10541 /* Fall through. */
10543 case BFD_RELOC_16_PCREL:
10545 * We need to save the bits in the instruction since fixup_segment()
10546 * might be deleting the relocation entry (i.e., a branch within
10547 * the current segment).
10549 if (!fixP->fx_done && value != 0)
10551 /* If 'value' is zero, the remaining reloc code won't actually
10552 do the store, so it must be done here. This is probably
10553 a bug somewhere. */
10554 if (!fixP->fx_done)
10555 value -= fixP->fx_frag->fr_address + fixP->fx_where;
10557 value = (offsetT) value >> 2;
10559 /* update old instruction data */
10560 buf = (unsigned char *) (fixP->fx_where + fixP->fx_frag->fr_literal);
10561 if (target_big_endian)
10562 insn = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
10564 insn = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
10566 if (value + 0x8000 <= 0xffff)
10567 insn |= value & 0xffff;
10570 /* The branch offset is too large. If this is an
10571 unconditional branch, and we are not generating PIC code,
10572 we can convert it to an absolute jump instruction. */
10573 if (mips_pic == NO_PIC
10575 && fixP->fx_frag->fr_address >= text_section->vma
10576 && (fixP->fx_frag->fr_address
10577 < text_section->vma + text_section->_raw_size)
10578 && ((insn & 0xffff0000) == 0x10000000 /* beq $0,$0 */
10579 || (insn & 0xffff0000) == 0x04010000 /* bgez $0 */
10580 || (insn & 0xffff0000) == 0x04110000)) /* bgezal $0 */
10582 if ((insn & 0xffff0000) == 0x04110000) /* bgezal $0 */
10583 insn = 0x0c000000; /* jal */
10585 insn = 0x08000000; /* j */
10586 fixP->fx_r_type = BFD_RELOC_MIPS_JMP;
10588 fixP->fx_addsy = section_symbol (text_section);
10589 fixP->fx_addnumber = (value << 2) + md_pcrel_from (fixP);
10593 /* FIXME. It would be possible in principle to handle
10594 conditional branches which overflow. They could be
10595 transformed into a branch around a jump. This would
10596 require setting up variant frags for each different
10597 branch type. The native MIPS assembler attempts to
10598 handle these cases, but it appears to do it
10600 as_bad_where (fixP->fx_file, fixP->fx_line,
10601 _("Branch out of range"));
10605 md_number_to_chars ((char *) buf, (valueT) insn, 4);
10608 case BFD_RELOC_VTABLE_INHERIT:
10611 && !S_IS_DEFINED (fixP->fx_addsy)
10612 && !S_IS_WEAK (fixP->fx_addsy))
10613 S_SET_WEAK (fixP->fx_addsy);
10616 case BFD_RELOC_VTABLE_ENTRY:
10630 const struct mips_opcode *p;
10631 int treg, sreg, dreg, shamt;
10636 for (i = 0; i < NUMOPCODES; ++i)
10638 p = &mips_opcodes[i];
10639 if (((oc & p->mask) == p->match) && (p->pinfo != INSN_MACRO))
10641 printf ("%08lx %s\t", oc, p->name);
10642 treg = (oc >> 16) & 0x1f;
10643 sreg = (oc >> 21) & 0x1f;
10644 dreg = (oc >> 11) & 0x1f;
10645 shamt = (oc >> 6) & 0x1f;
10647 for (args = p->args;; ++args)
10658 printf ("%c", *args);
10662 assert (treg == sreg);
10663 printf ("$%d,$%d", treg, sreg);
10668 printf ("$%d", dreg);
10673 printf ("$%d", treg);
10677 printf ("0x%x", treg);
10682 printf ("$%d", sreg);
10686 printf ("0x%08lx", oc & 0x1ffffff);
10693 printf ("%d", imm);
10698 printf ("$%d", shamt);
10709 printf (_("%08lx UNDEFINED\n"), oc);
10720 name = input_line_pointer;
10721 c = get_symbol_end ();
10722 p = (symbolS *) symbol_find_or_make (name);
10723 *input_line_pointer = c;
10727 /* Align the current frag to a given power of two. The MIPS assembler
10728 also automatically adjusts any preceding label. */
10731 mips_align (to, fill, label)
10736 mips_emit_delays (false);
10737 frag_align (to, fill, 0);
10738 record_alignment (now_seg, to);
10741 assert (S_GET_SEGMENT (label) == now_seg);
10742 symbol_set_frag (label, frag_now);
10743 S_SET_VALUE (label, (valueT) frag_now_fix ());
10747 /* Align to a given power of two. .align 0 turns off the automatic
10748 alignment used by the data creating pseudo-ops. */
10752 int x ATTRIBUTE_UNUSED;
10755 register long temp_fill;
10756 long max_alignment = 15;
10760 o Note that the assembler pulls down any immediately preceeding label
10761 to the aligned address.
10762 o It's not documented but auto alignment is reinstated by
10763 a .align pseudo instruction.
10764 o Note also that after auto alignment is turned off the mips assembler
10765 issues an error on attempt to assemble an improperly aligned data item.
10770 temp = get_absolute_expression ();
10771 if (temp > max_alignment)
10772 as_bad (_("Alignment too large: %d. assumed."), temp = max_alignment);
10775 as_warn (_("Alignment negative: 0 assumed."));
10778 if (*input_line_pointer == ',')
10780 input_line_pointer++;
10781 temp_fill = get_absolute_expression ();
10788 mips_align (temp, (int) temp_fill,
10789 insn_labels != NULL ? insn_labels->label : NULL);
10796 demand_empty_rest_of_line ();
10800 mips_flush_pending_output ()
10802 mips_emit_delays (false);
10803 mips_clear_insn_labels ();
10812 /* When generating embedded PIC code, we only use the .text, .lit8,
10813 .sdata and .sbss sections. We change the .data and .rdata
10814 pseudo-ops to use .sdata. */
10815 if (mips_pic == EMBEDDED_PIC
10816 && (sec == 'd' || sec == 'r'))
10820 /* The ELF backend needs to know that we are changing sections, so
10821 that .previous works correctly. We could do something like check
10822 for an obj_section_change_hook macro, but that might be confusing
10823 as it would not be appropriate to use it in the section changing
10824 functions in read.c, since obj-elf.c intercepts those. FIXME:
10825 This should be cleaner, somehow. */
10826 obj_elf_section_change_hook ();
10829 mips_emit_delays (false);
10839 subseg_set (bss_section, (subsegT) get_absolute_expression ());
10840 demand_empty_rest_of_line ();
10844 if (USE_GLOBAL_POINTER_OPT)
10846 seg = subseg_new (RDATA_SECTION_NAME,
10847 (subsegT) get_absolute_expression ());
10848 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
10850 bfd_set_section_flags (stdoutput, seg,
10856 if (strcmp (TARGET_OS, "elf") != 0)
10857 record_alignment (seg, 4);
10859 demand_empty_rest_of_line ();
10863 as_bad (_("No read only data section in this object file format"));
10864 demand_empty_rest_of_line ();
10870 if (USE_GLOBAL_POINTER_OPT)
10872 seg = subseg_new (".sdata", (subsegT) get_absolute_expression ());
10873 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
10875 bfd_set_section_flags (stdoutput, seg,
10876 SEC_ALLOC | SEC_LOAD | SEC_RELOC
10878 if (strcmp (TARGET_OS, "elf") != 0)
10879 record_alignment (seg, 4);
10881 demand_empty_rest_of_line ();
10886 as_bad (_("Global pointers not supported; recompile -G 0"));
10887 demand_empty_rest_of_line ();
10896 mips_enable_auto_align ()
10907 label = insn_labels != NULL ? insn_labels->label : NULL;
10908 mips_emit_delays (false);
10909 if (log_size > 0 && auto_align)
10910 mips_align (log_size, 0, label);
10911 mips_clear_insn_labels ();
10912 cons (1 << log_size);
10916 s_float_cons (type)
10921 label = insn_labels != NULL ? insn_labels->label : NULL;
10923 mips_emit_delays (false);
10928 mips_align (3, 0, label);
10930 mips_align (2, 0, label);
10933 mips_clear_insn_labels ();
10938 /* Handle .globl. We need to override it because on Irix 5 you are
10941 where foo is an undefined symbol, to mean that foo should be
10942 considered to be the address of a function. */
10946 int x ATTRIBUTE_UNUSED;
10953 name = input_line_pointer;
10954 c = get_symbol_end ();
10955 symbolP = symbol_find_or_make (name);
10956 *input_line_pointer = c;
10957 SKIP_WHITESPACE ();
10959 /* On Irix 5, every global symbol that is not explicitly labelled as
10960 being a function is apparently labelled as being an object. */
10963 if (! is_end_of_line[(unsigned char) *input_line_pointer])
10968 secname = input_line_pointer;
10969 c = get_symbol_end ();
10970 sec = bfd_get_section_by_name (stdoutput, secname);
10972 as_bad (_("%s: no such section"), secname);
10973 *input_line_pointer = c;
10975 if (sec != NULL && (sec->flags & SEC_CODE) != 0)
10976 flag = BSF_FUNCTION;
10979 symbol_get_bfdsym (symbolP)->flags |= flag;
10981 S_SET_EXTERNAL (symbolP);
10982 demand_empty_rest_of_line ();
10987 int x ATTRIBUTE_UNUSED;
10992 opt = input_line_pointer;
10993 c = get_symbol_end ();
10997 /* FIXME: What does this mean? */
10999 else if (strncmp (opt, "pic", 3) == 0)
11003 i = atoi (opt + 3);
11007 mips_pic = SVR4_PIC;
11009 as_bad (_(".option pic%d not supported"), i);
11011 if (USE_GLOBAL_POINTER_OPT && mips_pic == SVR4_PIC)
11013 if (g_switch_seen && g_switch_value != 0)
11014 as_warn (_("-G may not be used with SVR4 PIC code"));
11015 g_switch_value = 0;
11016 bfd_set_gp_size (stdoutput, 0);
11020 as_warn (_("Unrecognized option \"%s\""), opt);
11022 *input_line_pointer = c;
11023 demand_empty_rest_of_line ();
11026 /* This structure is used to hold a stack of .set values. */
11028 struct mips_option_stack
11030 struct mips_option_stack *next;
11031 struct mips_set_options options;
11034 static struct mips_option_stack *mips_opts_stack;
11036 /* Handle the .set pseudo-op. */
11040 int x ATTRIBUTE_UNUSED;
11042 char *name = input_line_pointer, ch;
11044 while (!is_end_of_line[(unsigned char) *input_line_pointer])
11045 input_line_pointer++;
11046 ch = *input_line_pointer;
11047 *input_line_pointer = '\0';
11049 if (strcmp (name, "reorder") == 0)
11051 if (mips_opts.noreorder && prev_nop_frag != NULL)
11053 /* If we still have pending nops, we can discard them. The
11054 usual nop handling will insert any that are still
11056 prev_nop_frag->fr_fix -= (prev_nop_frag_holds
11057 * (mips_opts.mips16 ? 2 : 4));
11058 prev_nop_frag = NULL;
11060 mips_opts.noreorder = 0;
11062 else if (strcmp (name, "noreorder") == 0)
11064 mips_emit_delays (true);
11065 mips_opts.noreorder = 1;
11066 mips_any_noreorder = 1;
11068 else if (strcmp (name, "at") == 0)
11070 mips_opts.noat = 0;
11072 else if (strcmp (name, "noat") == 0)
11074 mips_opts.noat = 1;
11076 else if (strcmp (name, "macro") == 0)
11078 mips_opts.warn_about_macros = 0;
11080 else if (strcmp (name, "nomacro") == 0)
11082 if (mips_opts.noreorder == 0)
11083 as_bad (_("`noreorder' must be set before `nomacro'"));
11084 mips_opts.warn_about_macros = 1;
11086 else if (strcmp (name, "move") == 0 || strcmp (name, "novolatile") == 0)
11088 mips_opts.nomove = 0;
11090 else if (strcmp (name, "nomove") == 0 || strcmp (name, "volatile") == 0)
11092 mips_opts.nomove = 1;
11094 else if (strcmp (name, "bopt") == 0)
11096 mips_opts.nobopt = 0;
11098 else if (strcmp (name, "nobopt") == 0)
11100 mips_opts.nobopt = 1;
11102 else if (strcmp (name, "mips16") == 0
11103 || strcmp (name, "MIPS-16") == 0)
11104 mips_opts.mips16 = 1;
11105 else if (strcmp (name, "nomips16") == 0
11106 || strcmp (name, "noMIPS-16") == 0)
11107 mips_opts.mips16 = 0;
11108 else if (strncmp (name, "mips", 4) == 0)
11112 /* Permit the user to change the ISA on the fly. Needless to
11113 say, misuse can cause serious problems. */
11114 isa = atoi (name + 4);
11118 mips_opts.gp32 = file_mips_gp32;
11119 mips_opts.fp32 = file_mips_fp32;
11120 mips_opts.abi = file_mips_abi;
11125 mips_opts.gp32 = 1;
11126 mips_opts.fp32 = 1;
11132 /* Loosen ABI register width restriction. */
11133 if (mips_opts.abi == O32_ABI)
11134 mips_opts.abi = NO_ABI;
11135 mips_opts.gp32 = 0;
11136 mips_opts.fp32 = 0;
11139 as_bad (_("unknown ISA level %s"), name + 4);
11145 case 0: mips_opts.isa = file_mips_isa; break;
11146 case 1: mips_opts.isa = ISA_MIPS1; break;
11147 case 2: mips_opts.isa = ISA_MIPS2; break;
11148 case 3: mips_opts.isa = ISA_MIPS3; break;
11149 case 4: mips_opts.isa = ISA_MIPS4; break;
11150 case 5: mips_opts.isa = ISA_MIPS5; break;
11151 case 32: mips_opts.isa = ISA_MIPS32; break;
11152 case 64: mips_opts.isa = ISA_MIPS64; break;
11153 default: as_bad (_("unknown ISA level %s"), name + 4); break;
11156 else if (strcmp (name, "autoextend") == 0)
11157 mips_opts.noautoextend = 0;
11158 else if (strcmp (name, "noautoextend") == 0)
11159 mips_opts.noautoextend = 1;
11160 else if (strcmp (name, "push") == 0)
11162 struct mips_option_stack *s;
11164 s = (struct mips_option_stack *) xmalloc (sizeof *s);
11165 s->next = mips_opts_stack;
11166 s->options = mips_opts;
11167 mips_opts_stack = s;
11169 else if (strcmp (name, "pop") == 0)
11171 struct mips_option_stack *s;
11173 s = mips_opts_stack;
11175 as_bad (_(".set pop with no .set push"));
11178 /* If we're changing the reorder mode we need to handle
11179 delay slots correctly. */
11180 if (s->options.noreorder && ! mips_opts.noreorder)
11181 mips_emit_delays (true);
11182 else if (! s->options.noreorder && mips_opts.noreorder)
11184 if (prev_nop_frag != NULL)
11186 prev_nop_frag->fr_fix -= (prev_nop_frag_holds
11187 * (mips_opts.mips16 ? 2 : 4));
11188 prev_nop_frag = NULL;
11192 mips_opts = s->options;
11193 mips_opts_stack = s->next;
11199 as_warn (_("Tried to set unrecognized symbol: %s\n"), name);
11201 *input_line_pointer = ch;
11202 demand_empty_rest_of_line ();
11205 /* Handle the .abicalls pseudo-op. I believe this is equivalent to
11206 .option pic2. It means to generate SVR4 PIC calls. */
11209 s_abicalls (ignore)
11210 int ignore ATTRIBUTE_UNUSED;
11212 mips_pic = SVR4_PIC;
11213 if (USE_GLOBAL_POINTER_OPT)
11215 if (g_switch_seen && g_switch_value != 0)
11216 as_warn (_("-G may not be used with SVR4 PIC code"));
11217 g_switch_value = 0;
11219 bfd_set_gp_size (stdoutput, 0);
11220 demand_empty_rest_of_line ();
11223 /* Handle the .cpload pseudo-op. This is used when generating SVR4
11224 PIC code. It sets the $gp register for the function based on the
11225 function address, which is in the register named in the argument.
11226 This uses a relocation against _gp_disp, which is handled specially
11227 by the linker. The result is:
11228 lui $gp,%hi(_gp_disp)
11229 addiu $gp,$gp,%lo(_gp_disp)
11230 addu $gp,$gp,.cpload argument
11231 The .cpload argument is normally $25 == $t9. */
11235 int ignore ATTRIBUTE_UNUSED;
11240 /* If we are not generating SVR4 PIC code, or if this is NewABI code,
11241 .cpload is ignored. */
11242 if (mips_pic != SVR4_PIC || HAVE_NEWABI)
11248 /* .cpload should be in a .set noreorder section. */
11249 if (mips_opts.noreorder == 0)
11250 as_warn (_(".cpload not in noreorder section"));
11252 ex.X_op = O_symbol;
11253 ex.X_add_symbol = symbol_find_or_make ("_gp_disp");
11254 ex.X_op_symbol = NULL;
11255 ex.X_add_number = 0;
11257 /* In ELF, this symbol is implicitly an STT_OBJECT symbol. */
11258 symbol_get_bfdsym (ex.X_add_symbol)->flags |= BSF_OBJECT;
11260 macro_build_lui (NULL, &icnt, &ex, GP);
11261 macro_build ((char *) NULL, &icnt, &ex, "addiu", "t,r,j", GP, GP,
11262 (int) BFD_RELOC_LO16);
11264 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "addu", "d,v,t",
11265 GP, GP, tc_get_register (0));
11267 demand_empty_rest_of_line ();
11270 /* Handle the .cpsetup pseudo-op defined for NewABI PIC code. The syntax is:
11271 .cpsetup $reg1, offset|$reg2, label
11273 If offset is given, this results in:
11274 sd $gp, offset($sp)
11275 lui $gp, %hi(%neg(%gp_rel(label)))
11276 daddiu $gp, $gp, %lo(%neg(%gp_rel(label)))
11277 addu $gp, $gp, $reg1
11279 If $reg2 is given, this results in:
11280 daddu $reg2, $gp, $0
11281 lui $gp, %hi(%neg(%gp_rel(label)))
11282 daddiu $gp, $gp, %lo(%neg(%gp_rel(label)))
11283 addu $gp, $gp, $reg1
11287 int ignore ATTRIBUTE_UNUSED;
11289 expressionS ex_off;
11290 expressionS ex_sym;
11295 /* If we are not generating SVR4 PIC code, .cpload is ignored.
11296 We also need NewABI support. */
11297 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
11303 reg1 = tc_get_register (0);
11304 SKIP_WHITESPACE ();
11305 if (*input_line_pointer != ',')
11307 as_bad (_("missing argument separator ',' for .cpsetup"));
11311 input_line_pointer++;
11312 SKIP_WHITESPACE ();
11313 if (*input_line_pointer == '$')
11314 mips_cpreturn_register = tc_get_register (0);
11316 mips_cpreturn_offset = get_absolute_expression ();
11317 SKIP_WHITESPACE ();
11318 if (*input_line_pointer != ',')
11320 as_bad (_("missing argument separator ',' for .cpsetup"));
11324 input_line_pointer++;
11325 SKIP_WHITESPACE ();
11326 sym = input_line_pointer;
11327 while (ISALNUM (*input_line_pointer))
11328 input_line_pointer++;
11329 *input_line_pointer = 0;
11331 ex_sym.X_op = O_symbol;
11332 ex_sym.X_add_symbol = symbol_find_or_make (sym);
11333 ex_sym.X_op_symbol = NULL;
11334 ex_sym.X_add_number = 0;
11336 if (mips_cpreturn_register == -1)
11338 ex_off.X_op = O_constant;
11339 ex_off.X_add_symbol = NULL;
11340 ex_off.X_op_symbol = NULL;
11341 ex_off.X_add_number = mips_cpreturn_offset;
11343 macro_build ((char *) NULL, &icnt, &ex_off, "sd", "t,o(b)",
11344 mips_gp_register, (int) BFD_RELOC_LO16, SP);
11347 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "daddu",
11348 "d,v,t", mips_cpreturn_register, mips_gp_register, 0);
11350 macro_build ((char *) NULL, &icnt, &ex_sym, "lui", "t,u", mips_gp_register,
11351 (int) BFD_RELOC_GPREL16);
11352 fix_new (frag_now, (char *) prev_insn_fixp - 4 - frag_now->fr_literal, 0,
11353 NULL, 0, 0, BFD_RELOC_MIPS_SUB);
11354 fix_new (frag_now, (char *) prev_insn_fixp - 4 - frag_now->fr_literal, 0,
11355 NULL, 0, 0, BFD_RELOC_HI16_S);
11356 macro_build ((char *) NULL, &icnt, &ex_sym, "addiu", "t,r,j",
11357 mips_gp_register, mips_gp_register, (int) BFD_RELOC_GPREL16);
11358 fix_new (frag_now, (char *) prev_insn_fixp - 4 - frag_now->fr_literal, 0,
11359 NULL, 0, 0, BFD_RELOC_MIPS_SUB);
11360 fix_new (frag_now, (char *) prev_insn_fixp - 4 - frag_now->fr_literal, 0,
11361 NULL, 0, 0, BFD_RELOC_LO16);
11362 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "daddu",
11363 "d,v,t", mips_gp_register, mips_gp_register, reg1);
11365 demand_empty_rest_of_line ();
11370 int ignore ATTRIBUTE_UNUSED;
11372 /* If we are not generating SVR4 PIC code, or if this is not NewABI code,
11373 .cplocal is ignored. */
11374 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
11380 mips_gp_register = tc_get_register (0);
11383 /* Handle the .cprestore pseudo-op. This stores $gp into a given
11384 offset from $sp. The offset is remembered, and after making a PIC
11385 call $gp is restored from that location. */
11388 s_cprestore (ignore)
11389 int ignore ATTRIBUTE_UNUSED;
11394 /* If we are not generating SVR4 PIC code, or if this is NewABI code,
11395 .cprestore is ignored. */
11396 if (mips_pic != SVR4_PIC || HAVE_NEWABI)
11402 mips_cprestore_offset = get_absolute_expression ();
11404 ex.X_op = O_constant;
11405 ex.X_add_symbol = NULL;
11406 ex.X_op_symbol = NULL;
11407 ex.X_add_number = mips_cprestore_offset;
11409 macro_build ((char *) NULL, &icnt, &ex,
11410 HAVE_32BIT_ADDRESSES ? "sw" : "sd",
11411 "t,o(b)", GP, (int) BFD_RELOC_LO16, SP);
11413 demand_empty_rest_of_line ();
11416 /* Handle the .cpreturn pseudo-op defined for NewABI PIC code. If an offset
11417 was given in the preceeding .gpsetup, it results in:
11418 ld $gp, offset($sp)
11420 If a register $reg2 was given there, it results in:
11421 daddiu $gp, $gp, $reg2
11424 s_cpreturn (ignore)
11425 int ignore ATTRIBUTE_UNUSED;
11430 /* If we are not generating SVR4 PIC code, .cpreturn is ignored.
11431 We also need NewABI support. */
11432 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
11438 if (mips_cpreturn_register == -1)
11440 ex.X_op = O_constant;
11441 ex.X_add_symbol = NULL;
11442 ex.X_op_symbol = NULL;
11443 ex.X_add_number = mips_cpreturn_offset;
11445 macro_build ((char *) NULL, &icnt, &ex, "ld", "t,o(b)",
11446 mips_gp_register, (int) BFD_RELOC_LO16, SP);
11449 macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "daddu",
11450 "d,v,t", mips_gp_register, mips_cpreturn_register, 0);
11452 demand_empty_rest_of_line ();
11455 /* Handle the .gpvalue pseudo-op. This is used when generating NewABI PIC
11456 code. It sets the offset to use in gp_rel relocations. */
11460 int ignore ATTRIBUTE_UNUSED;
11462 /* If we are not generating SVR4 PIC code, .gpvalue is ignored.
11463 We also need NewABI support. */
11464 if (mips_pic != SVR4_PIC || ! HAVE_NEWABI)
11470 mips_cpreturn_offset = get_absolute_expression ();
11472 demand_empty_rest_of_line ();
11475 /* Handle the .gpword pseudo-op. This is used when generating PIC
11476 code. It generates a 32 bit GP relative reloc. */
11480 int ignore ATTRIBUTE_UNUSED;
11486 /* When not generating PIC code, this is treated as .word. */
11487 if (mips_pic != SVR4_PIC)
11493 label = insn_labels != NULL ? insn_labels->label : NULL;
11494 mips_emit_delays (true);
11496 mips_align (2, 0, label);
11497 mips_clear_insn_labels ();
11501 if (ex.X_op != O_symbol || ex.X_add_number != 0)
11503 as_bad (_("Unsupported use of .gpword"));
11504 ignore_rest_of_line ();
11508 md_number_to_chars (p, (valueT) 0, 4);
11509 fix_new_exp (frag_now, p - frag_now->fr_literal, 4, &ex, 0,
11510 BFD_RELOC_GPREL32);
11512 demand_empty_rest_of_line ();
11515 /* Handle the .cpadd pseudo-op. This is used when dealing with switch
11516 tables in SVR4 PIC code. */
11520 int ignore ATTRIBUTE_UNUSED;
11525 /* This is ignored when not generating SVR4 PIC code or if this is NewABI
11527 if (mips_pic != SVR4_PIC || HAVE_NEWABI)
11533 /* Add $gp to the register named as an argument. */
11534 reg = tc_get_register (0);
11535 macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
11536 HAVE_32BIT_ADDRESSES ? "addu" : "daddu",
11537 "d,v,t", reg, reg, GP);
11539 demand_empty_rest_of_line ();
11542 /* Handle the .insn pseudo-op. This marks instruction labels in
11543 mips16 mode. This permits the linker to handle them specially,
11544 such as generating jalx instructions when needed. We also make
11545 them odd for the duration of the assembly, in order to generate the
11546 right sort of code. We will make them even in the adjust_symtab
11547 routine, while leaving them marked. This is convenient for the
11548 debugger and the disassembler. The linker knows to make them odd
11553 int ignore ATTRIBUTE_UNUSED;
11555 if (mips_opts.mips16)
11556 mips16_mark_labels ();
11558 demand_empty_rest_of_line ();
11561 /* Handle a .stabn directive. We need these in order to mark a label
11562 as being a mips16 text label correctly. Sometimes the compiler
11563 will emit a label, followed by a .stabn, and then switch sections.
11564 If the label and .stabn are in mips16 mode, then the label is
11565 really a mips16 text label. */
11571 if (type == 'n' && mips_opts.mips16)
11572 mips16_mark_labels ();
11577 /* Handle the .weakext pseudo-op as defined in Kane and Heinrich.
11581 s_mips_weakext (ignore)
11582 int ignore ATTRIBUTE_UNUSED;
11589 name = input_line_pointer;
11590 c = get_symbol_end ();
11591 symbolP = symbol_find_or_make (name);
11592 S_SET_WEAK (symbolP);
11593 *input_line_pointer = c;
11595 SKIP_WHITESPACE ();
11597 if (! is_end_of_line[(unsigned char) *input_line_pointer])
11599 if (S_IS_DEFINED (symbolP))
11601 as_bad ("ignoring attempt to redefine symbol %s",
11602 S_GET_NAME (symbolP));
11603 ignore_rest_of_line ();
11607 if (*input_line_pointer == ',')
11609 ++input_line_pointer;
11610 SKIP_WHITESPACE ();
11614 if (exp.X_op != O_symbol)
11616 as_bad ("bad .weakext directive");
11617 ignore_rest_of_line();
11620 symbol_set_value_expression (symbolP, &exp);
11623 demand_empty_rest_of_line ();
11626 /* Parse a register string into a number. Called from the ECOFF code
11627 to parse .frame. The argument is non-zero if this is the frame
11628 register, so that we can record it in mips_frame_reg. */
11631 tc_get_register (frame)
11636 SKIP_WHITESPACE ();
11637 if (*input_line_pointer++ != '$')
11639 as_warn (_("expected `$'"));
11642 else if (ISDIGIT (*input_line_pointer))
11644 reg = get_absolute_expression ();
11645 if (reg < 0 || reg >= 32)
11647 as_warn (_("Bad register number"));
11653 if (strncmp (input_line_pointer, "fp", 2) == 0)
11655 else if (strncmp (input_line_pointer, "sp", 2) == 0)
11657 else if (strncmp (input_line_pointer, "gp", 2) == 0)
11659 else if (strncmp (input_line_pointer, "at", 2) == 0)
11663 as_warn (_("Unrecognized register name"));
11666 input_line_pointer += 2;
11669 mips_frame_reg = reg != 0 ? reg : SP;
11674 md_section_align (seg, addr)
11678 int align = bfd_get_section_alignment (stdoutput, seg);
11681 /* We don't need to align ELF sections to the full alignment.
11682 However, Irix 5 may prefer that we align them at least to a 16
11683 byte boundary. We don't bother to align the sections if we are
11684 targeted for an embedded system. */
11685 if (strcmp (TARGET_OS, "elf") == 0)
11691 return ((addr + (1 << align) - 1) & (-1 << align));
11694 /* Utility routine, called from above as well. If called while the
11695 input file is still being read, it's only an approximation. (For
11696 example, a symbol may later become defined which appeared to be
11697 undefined earlier.) */
11700 nopic_need_relax (sym, before_relaxing)
11702 int before_relaxing;
11707 if (USE_GLOBAL_POINTER_OPT && g_switch_value > 0)
11709 const char *symname;
11712 /* Find out whether this symbol can be referenced off the GP
11713 register. It can be if it is smaller than the -G size or if
11714 it is in the .sdata or .sbss section. Certain symbols can
11715 not be referenced off the GP, although it appears as though
11717 symname = S_GET_NAME (sym);
11718 if (symname != (const char *) NULL
11719 && (strcmp (symname, "eprol") == 0
11720 || strcmp (symname, "etext") == 0
11721 || strcmp (symname, "_gp") == 0
11722 || strcmp (symname, "edata") == 0
11723 || strcmp (symname, "_fbss") == 0
11724 || strcmp (symname, "_fdata") == 0
11725 || strcmp (symname, "_ftext") == 0
11726 || strcmp (symname, "end") == 0
11727 || strcmp (symname, "_gp_disp") == 0))
11729 else if ((! S_IS_DEFINED (sym) || S_IS_COMMON (sym))
11731 #ifndef NO_ECOFF_DEBUGGING
11732 || (symbol_get_obj (sym)->ecoff_extern_size != 0
11733 && (symbol_get_obj (sym)->ecoff_extern_size
11734 <= g_switch_value))
11736 /* We must defer this decision until after the whole
11737 file has been read, since there might be a .extern
11738 after the first use of this symbol. */
11739 || (before_relaxing
11740 #ifndef NO_ECOFF_DEBUGGING
11741 && symbol_get_obj (sym)->ecoff_extern_size == 0
11743 && S_GET_VALUE (sym) == 0)
11744 || (S_GET_VALUE (sym) != 0
11745 && S_GET_VALUE (sym) <= g_switch_value)))
11749 const char *segname;
11751 segname = segment_name (S_GET_SEGMENT (sym));
11752 assert (strcmp (segname, ".lit8") != 0
11753 && strcmp (segname, ".lit4") != 0);
11754 change = (strcmp (segname, ".sdata") != 0
11755 && strcmp (segname, ".sbss") != 0
11756 && strncmp (segname, ".sdata.", 7) != 0
11757 && strncmp (segname, ".gnu.linkonce.s.", 16) != 0);
11762 /* We are not optimizing for the GP register. */
11766 /* Given a mips16 variant frag FRAGP, return non-zero if it needs an
11767 extended opcode. SEC is the section the frag is in. */
11770 mips16_extended_frag (fragp, sec, stretch)
11776 register const struct mips16_immed_operand *op;
11778 int mintiny, maxtiny;
11782 if (RELAX_MIPS16_USER_SMALL (fragp->fr_subtype))
11784 if (RELAX_MIPS16_USER_EXT (fragp->fr_subtype))
11787 type = RELAX_MIPS16_TYPE (fragp->fr_subtype);
11788 op = mips16_immed_operands;
11789 while (op->type != type)
11792 assert (op < mips16_immed_operands + MIPS16_NUM_IMMED);
11797 if (type == '<' || type == '>' || type == '[' || type == ']')
11800 maxtiny = 1 << op->nbits;
11805 maxtiny = (1 << op->nbits) - 1;
11810 mintiny = - (1 << (op->nbits - 1));
11811 maxtiny = (1 << (op->nbits - 1)) - 1;
11814 sym_frag = symbol_get_frag (fragp->fr_symbol);
11815 val = S_GET_VALUE (fragp->fr_symbol);
11816 symsec = S_GET_SEGMENT (fragp->fr_symbol);
11822 /* We won't have the section when we are called from
11823 mips_relax_frag. However, we will always have been called
11824 from md_estimate_size_before_relax first. If this is a
11825 branch to a different section, we mark it as such. If SEC is
11826 NULL, and the frag is not marked, then it must be a branch to
11827 the same section. */
11830 if (RELAX_MIPS16_LONG_BRANCH (fragp->fr_subtype))
11835 /* Must have been called from md_estimate_size_before_relax. */
11838 fragp->fr_subtype =
11839 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
11841 /* FIXME: We should support this, and let the linker
11842 catch branches and loads that are out of range. */
11843 as_bad_where (fragp->fr_file, fragp->fr_line,
11844 _("unsupported PC relative reference to different section"));
11848 if (fragp != sym_frag && sym_frag->fr_address == 0)
11849 /* Assume non-extended on the first relaxation pass.
11850 The address we have calculated will be bogus if this is
11851 a forward branch to another frag, as the forward frag
11852 will have fr_address == 0. */
11856 /* In this case, we know for sure that the symbol fragment is in
11857 the same section. If the relax_marker of the symbol fragment
11858 differs from the relax_marker of this fragment, we have not
11859 yet adjusted the symbol fragment fr_address. We want to add
11860 in STRETCH in order to get a better estimate of the address.
11861 This particularly matters because of the shift bits. */
11863 && sym_frag->relax_marker != fragp->relax_marker)
11867 /* Adjust stretch for any alignment frag. Note that if have
11868 been expanding the earlier code, the symbol may be
11869 defined in what appears to be an earlier frag. FIXME:
11870 This doesn't handle the fr_subtype field, which specifies
11871 a maximum number of bytes to skip when doing an
11873 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
11875 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
11878 stretch = - ((- stretch)
11879 & ~ ((1 << (int) f->fr_offset) - 1));
11881 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
11890 addr = fragp->fr_address + fragp->fr_fix;
11892 /* The base address rules are complicated. The base address of
11893 a branch is the following instruction. The base address of a
11894 PC relative load or add is the instruction itself, but if it
11895 is in a delay slot (in which case it can not be extended) use
11896 the address of the instruction whose delay slot it is in. */
11897 if (type == 'p' || type == 'q')
11901 /* If we are currently assuming that this frag should be
11902 extended, then, the current address is two bytes
11904 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
11907 /* Ignore the low bit in the target, since it will be set
11908 for a text label. */
11909 if ((val & 1) != 0)
11912 else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype))
11914 else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype))
11917 val -= addr & ~ ((1 << op->shift) - 1);
11919 /* Branch offsets have an implicit 0 in the lowest bit. */
11920 if (type == 'p' || type == 'q')
11923 /* If any of the shifted bits are set, we must use an extended
11924 opcode. If the address depends on the size of this
11925 instruction, this can lead to a loop, so we arrange to always
11926 use an extended opcode. We only check this when we are in
11927 the main relaxation loop, when SEC is NULL. */
11928 if ((val & ((1 << op->shift) - 1)) != 0 && sec == NULL)
11930 fragp->fr_subtype =
11931 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
11935 /* If we are about to mark a frag as extended because the value
11936 is precisely maxtiny + 1, then there is a chance of an
11937 infinite loop as in the following code:
11942 In this case when the la is extended, foo is 0x3fc bytes
11943 away, so the la can be shrunk, but then foo is 0x400 away, so
11944 the la must be extended. To avoid this loop, we mark the
11945 frag as extended if it was small, and is about to become
11946 extended with a value of maxtiny + 1. */
11947 if (val == ((maxtiny + 1) << op->shift)
11948 && ! RELAX_MIPS16_EXTENDED (fragp->fr_subtype)
11951 fragp->fr_subtype =
11952 RELAX_MIPS16_MARK_LONG_BRANCH (fragp->fr_subtype);
11956 else if (symsec != absolute_section && sec != NULL)
11957 as_bad_where (fragp->fr_file, fragp->fr_line, _("unsupported relocation"));
11959 if ((val & ((1 << op->shift) - 1)) != 0
11960 || val < (mintiny << op->shift)
11961 || val > (maxtiny << op->shift))
11967 /* Estimate the size of a frag before relaxing. Unless this is the
11968 mips16, we are not really relaxing here, and the final size is
11969 encoded in the subtype information. For the mips16, we have to
11970 decide whether we are using an extended opcode or not. */
11973 md_estimate_size_before_relax (fragp, segtype)
11978 boolean linkonce = false;
11980 if (RELAX_MIPS16_P (fragp->fr_subtype))
11982 if (mips16_extended_frag (fragp, segtype, 0))
11984 fragp->fr_subtype = RELAX_MIPS16_MARK_EXTENDED (fragp->fr_subtype);
11989 fragp->fr_subtype = RELAX_MIPS16_CLEAR_EXTENDED (fragp->fr_subtype);
11994 if (mips_pic == NO_PIC)
11996 change = nopic_need_relax (fragp->fr_symbol, 0);
11998 else if (mips_pic == SVR4_PIC)
12003 sym = fragp->fr_symbol;
12005 /* Handle the case of a symbol equated to another symbol. */
12006 while (symbol_equated_reloc_p (sym))
12010 /* It's possible to get a loop here in a badly written
12012 n = symbol_get_value_expression (sym)->X_add_symbol;
12018 symsec = S_GET_SEGMENT (sym);
12020 /* duplicate the test for LINK_ONCE sections as in adjust_reloc_syms */
12021 if (symsec != segtype && ! S_IS_LOCAL (sym))
12023 if ((bfd_get_section_flags (stdoutput, symsec) & SEC_LINK_ONCE)
12027 /* The GNU toolchain uses an extension for ELF: a section
12028 beginning with the magic string .gnu.linkonce is a linkonce
12030 if (strncmp (segment_name (symsec), ".gnu.linkonce",
12031 sizeof ".gnu.linkonce" - 1) == 0)
12035 /* This must duplicate the test in adjust_reloc_syms. */
12036 change = (symsec != &bfd_und_section
12037 && symsec != &bfd_abs_section
12038 && ! bfd_is_com_section (symsec)
12041 /* A global or weak symbol is treated as external. */
12042 && (OUTPUT_FLAVOR == bfd_target_elf_flavour
12043 && ! (S_IS_EXTERN (sym) || S_IS_WEAK (sym)))
12052 /* Record the offset to the first reloc in the fr_opcode field.
12053 This lets md_convert_frag and tc_gen_reloc know that the code
12054 must be expanded. */
12055 fragp->fr_opcode = (fragp->fr_literal
12057 - RELAX_OLD (fragp->fr_subtype)
12058 + RELAX_RELOC1 (fragp->fr_subtype));
12059 /* FIXME: This really needs as_warn_where. */
12060 if (RELAX_WARN (fragp->fr_subtype))
12061 as_warn (_("AT used after \".set noat\" or macro used after "
12062 "\".set nomacro\""));
12064 return RELAX_NEW (fragp->fr_subtype) - RELAX_OLD (fragp->fr_subtype);
12070 /* This is called to see whether a reloc against a defined symbol
12071 should be converted into a reloc against a section. Don't adjust
12072 MIPS16 jump relocations, so we don't have to worry about the format
12073 of the offset in the .o file. Don't adjust relocations against
12074 mips16 symbols, so that the linker can find them if it needs to set
12078 mips_fix_adjustable (fixp)
12082 /* Prevent all adjustments to global symbols. */
12083 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
12084 && (S_IS_EXTERN (fixp->fx_addsy) || S_IS_WEAK (fixp->fx_addsy)))
12087 if (fixp->fx_r_type == BFD_RELOC_MIPS16_JMP)
12089 if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT
12090 || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
12092 if (fixp->fx_addsy == NULL)
12095 if (OUTPUT_FLAVOR == bfd_target_elf_flavour
12096 && S_GET_OTHER (fixp->fx_addsy) == STO_MIPS16
12097 && fixp->fx_subsy == NULL)
12103 /* Translate internal representation of relocation info to BFD target
12107 tc_gen_reloc (section, fixp)
12108 asection *section ATTRIBUTE_UNUSED;
12111 static arelent *retval[4];
12113 bfd_reloc_code_real_type code;
12115 reloc = retval[0] = (arelent *) xmalloc (sizeof (arelent));
12118 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
12119 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
12120 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
12122 if (mips_pic == EMBEDDED_PIC
12123 && SWITCH_TABLE (fixp))
12125 /* For a switch table entry we use a special reloc. The addend
12126 is actually the difference between the reloc address and the
12128 reloc->addend = reloc->address - S_GET_VALUE (fixp->fx_subsy);
12129 if (OUTPUT_FLAVOR != bfd_target_ecoff_flavour)
12130 as_fatal (_("Double check fx_r_type in tc-mips.c:tc_gen_reloc"));
12131 fixp->fx_r_type = BFD_RELOC_GPREL32;
12133 else if (fixp->fx_pcrel == 0 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
12134 reloc->addend = fixp->fx_addnumber;
12135 else if (fixp->fx_r_type == BFD_RELOC_PCREL_LO16)
12137 /* We use a special addend for an internal RELLO reloc. */
12138 if (symbol_section_p (fixp->fx_addsy))
12139 reloc->addend = reloc->address - S_GET_VALUE (fixp->fx_subsy);
12141 reloc->addend = fixp->fx_addnumber + reloc->address;
12143 else if (fixp->fx_r_type == BFD_RELOC_PCREL_HI16_S)
12145 assert (fixp->fx_next != NULL
12146 && fixp->fx_next->fx_r_type == BFD_RELOC_PCREL_LO16);
12147 /* We use a special addend for an internal RELHI reloc. The
12148 reloc is relative to the RELLO; adjust the addend
12150 if (symbol_section_p (fixp->fx_addsy))
12151 reloc->addend = (fixp->fx_next->fx_frag->fr_address
12152 + fixp->fx_next->fx_where
12153 - S_GET_VALUE (fixp->fx_subsy));
12155 reloc->addend = (fixp->fx_addnumber
12156 + fixp->fx_next->fx_frag->fr_address
12157 + fixp->fx_next->fx_where);
12161 if (OUTPUT_FLAVOR != bfd_target_aout_flavour)
12162 /* A gruesome hack which is a result of the gruesome gas reloc
12164 reloc->addend = reloc->address;
12166 reloc->addend = -reloc->address;
12169 /* If this is a variant frag, we may need to adjust the existing
12170 reloc and generate a new one. */
12171 if (fixp->fx_frag->fr_opcode != NULL
12172 && (fixp->fx_r_type == BFD_RELOC_GPREL16
12173 || fixp->fx_r_type == BFD_RELOC_MIPS_GOT16
12174 || fixp->fx_r_type == BFD_RELOC_MIPS_CALL16
12175 || fixp->fx_r_type == BFD_RELOC_MIPS_GOT_HI16
12176 || fixp->fx_r_type == BFD_RELOC_MIPS_GOT_LO16
12177 || fixp->fx_r_type == BFD_RELOC_MIPS_CALL_HI16
12178 || fixp->fx_r_type == BFD_RELOC_MIPS_CALL_LO16)
12183 assert (! RELAX_MIPS16_P (fixp->fx_frag->fr_subtype));
12185 /* If this is not the last reloc in this frag, then we have two
12186 GPREL relocs, or a GOT_HI16/GOT_LO16 pair, or a
12187 CALL_HI16/CALL_LO16, both of which are being replaced. Let
12188 the second one handle all of them. */
12189 if (fixp->fx_next != NULL
12190 && fixp->fx_frag == fixp->fx_next->fx_frag)
12192 assert ((fixp->fx_r_type == BFD_RELOC_GPREL16
12193 && fixp->fx_next->fx_r_type == BFD_RELOC_GPREL16)
12194 || (fixp->fx_r_type == BFD_RELOC_MIPS_GOT_HI16
12195 && (fixp->fx_next->fx_r_type
12196 == BFD_RELOC_MIPS_GOT_LO16))
12197 || (fixp->fx_r_type == BFD_RELOC_MIPS_CALL_HI16
12198 && (fixp->fx_next->fx_r_type
12199 == BFD_RELOC_MIPS_CALL_LO16)));
12204 fixp->fx_where = fixp->fx_frag->fr_opcode - fixp->fx_frag->fr_literal;
12205 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
12206 reloc2 = retval[1] = (arelent *) xmalloc (sizeof (arelent));
12208 reloc2->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
12209 *reloc2->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
12210 reloc2->address = (reloc->address
12211 + (RELAX_RELOC2 (fixp->fx_frag->fr_subtype)
12212 - RELAX_RELOC1 (fixp->fx_frag->fr_subtype)));
12213 reloc2->addend = fixp->fx_addnumber;
12214 reloc2->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_LO16);
12215 assert (reloc2->howto != NULL);
12217 if (RELAX_RELOC3 (fixp->fx_frag->fr_subtype))
12221 reloc3 = retval[2] = (arelent *) xmalloc (sizeof (arelent));
12224 reloc3->address += 4;
12227 if (mips_pic == NO_PIC)
12229 assert (fixp->fx_r_type == BFD_RELOC_GPREL16);
12230 fixp->fx_r_type = BFD_RELOC_HI16_S;
12232 else if (mips_pic == SVR4_PIC)
12234 switch (fixp->fx_r_type)
12238 case BFD_RELOC_MIPS_GOT16:
12240 case BFD_RELOC_MIPS_CALL16:
12241 case BFD_RELOC_MIPS_GOT_LO16:
12242 case BFD_RELOC_MIPS_CALL_LO16:
12243 fixp->fx_r_type = BFD_RELOC_MIPS_GOT16;
12251 /* Since MIPS ELF uses Rel instead of Rela, encode the vtable entry
12252 to be used in the relocation's section offset. */
12253 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
12255 reloc->address = reloc->addend;
12259 /* Since DIFF_EXPR_OK is defined in tc-mips.h, it is possible that
12260 fixup_segment converted a non-PC relative reloc into a PC
12261 relative reloc. In such a case, we need to convert the reloc
12263 code = fixp->fx_r_type;
12264 if (fixp->fx_pcrel)
12269 code = BFD_RELOC_8_PCREL;
12272 code = BFD_RELOC_16_PCREL;
12275 code = BFD_RELOC_32_PCREL;
12278 code = BFD_RELOC_64_PCREL;
12280 case BFD_RELOC_8_PCREL:
12281 case BFD_RELOC_16_PCREL:
12282 case BFD_RELOC_32_PCREL:
12283 case BFD_RELOC_64_PCREL:
12284 case BFD_RELOC_16_PCREL_S2:
12285 case BFD_RELOC_PCREL_HI16_S:
12286 case BFD_RELOC_PCREL_LO16:
12289 as_bad_where (fixp->fx_file, fixp->fx_line,
12290 _("Cannot make %s relocation PC relative"),
12291 bfd_get_reloc_code_name (code));
12296 /* md_apply_fix3 has a double-subtraction hack to get
12297 bfd_install_relocation to behave nicely. GPREL relocations are
12298 handled correctly without this hack, so undo it here. We can't
12299 stop md_apply_fix3 from subtracting twice in the first place since
12300 the fake addend is required for variant frags above. */
12301 if (fixp->fx_addsy != NULL && OUTPUT_FLAVOR == bfd_target_elf_flavour
12302 && code == BFD_RELOC_GPREL16
12303 && reloc->addend != 0
12304 && mips_need_elf_addend_fixup (fixp))
12305 reloc->addend += S_GET_VALUE (fixp->fx_addsy);
12308 /* To support a PC relative reloc when generating embedded PIC code
12309 for ECOFF, we use a Cygnus extension. We check for that here to
12310 make sure that we don't let such a reloc escape normally. */
12311 if ((OUTPUT_FLAVOR == bfd_target_ecoff_flavour
12312 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
12313 && code == BFD_RELOC_16_PCREL_S2
12314 && mips_pic != EMBEDDED_PIC)
12315 reloc->howto = NULL;
12317 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
12319 if (reloc->howto == NULL)
12321 as_bad_where (fixp->fx_file, fixp->fx_line,
12322 _("Can not represent %s relocation in this object file format"),
12323 bfd_get_reloc_code_name (code));
12330 /* Relax a machine dependent frag. This returns the amount by which
12331 the current size of the frag should change. */
12334 mips_relax_frag (fragp, stretch)
12338 if (! RELAX_MIPS16_P (fragp->fr_subtype))
12341 if (mips16_extended_frag (fragp, NULL, stretch))
12343 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
12345 fragp->fr_subtype = RELAX_MIPS16_MARK_EXTENDED (fragp->fr_subtype);
12350 if (! RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
12352 fragp->fr_subtype = RELAX_MIPS16_CLEAR_EXTENDED (fragp->fr_subtype);
12359 /* Convert a machine dependent frag. */
12362 md_convert_frag (abfd, asec, fragp)
12363 bfd *abfd ATTRIBUTE_UNUSED;
12370 if (RELAX_MIPS16_P (fragp->fr_subtype))
12373 register const struct mips16_immed_operand *op;
12374 boolean small, ext;
12377 unsigned long insn;
12378 boolean use_extend;
12379 unsigned short extend;
12381 type = RELAX_MIPS16_TYPE (fragp->fr_subtype);
12382 op = mips16_immed_operands;
12383 while (op->type != type)
12386 if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
12397 resolve_symbol_value (fragp->fr_symbol);
12398 val = S_GET_VALUE (fragp->fr_symbol);
12403 addr = fragp->fr_address + fragp->fr_fix;
12405 /* The rules for the base address of a PC relative reloc are
12406 complicated; see mips16_extended_frag. */
12407 if (type == 'p' || type == 'q')
12412 /* Ignore the low bit in the target, since it will be
12413 set for a text label. */
12414 if ((val & 1) != 0)
12417 else if (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype))
12419 else if (RELAX_MIPS16_DSLOT (fragp->fr_subtype))
12422 addr &= ~ (addressT) ((1 << op->shift) - 1);
12425 /* Make sure the section winds up with the alignment we have
12428 record_alignment (asec, op->shift);
12432 && (RELAX_MIPS16_JAL_DSLOT (fragp->fr_subtype)
12433 || RELAX_MIPS16_DSLOT (fragp->fr_subtype)))
12434 as_warn_where (fragp->fr_file, fragp->fr_line,
12435 _("extended instruction in delay slot"));
12437 buf = (bfd_byte *) (fragp->fr_literal + fragp->fr_fix);
12439 if (target_big_endian)
12440 insn = bfd_getb16 (buf);
12442 insn = bfd_getl16 (buf);
12444 mips16_immed (fragp->fr_file, fragp->fr_line, type, val,
12445 RELAX_MIPS16_USER_EXT (fragp->fr_subtype),
12446 small, ext, &insn, &use_extend, &extend);
12450 md_number_to_chars (buf, 0xf000 | extend, 2);
12451 fragp->fr_fix += 2;
12455 md_number_to_chars (buf, insn, 2);
12456 fragp->fr_fix += 2;
12461 if (fragp->fr_opcode == NULL)
12464 old = RELAX_OLD (fragp->fr_subtype);
12465 new = RELAX_NEW (fragp->fr_subtype);
12466 fixptr = fragp->fr_literal + fragp->fr_fix;
12469 memcpy (fixptr - old, fixptr, new);
12471 fragp->fr_fix += new - old;
12477 /* This function is called after the relocs have been generated.
12478 We've been storing mips16 text labels as odd. Here we convert them
12479 back to even for the convenience of the debugger. */
12482 mips_frob_file_after_relocs ()
12485 unsigned int count, i;
12487 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
12490 syms = bfd_get_outsymbols (stdoutput);
12491 count = bfd_get_symcount (stdoutput);
12492 for (i = 0; i < count; i++, syms++)
12494 if (elf_symbol (*syms)->internal_elf_sym.st_other == STO_MIPS16
12495 && ((*syms)->value & 1) != 0)
12497 (*syms)->value &= ~1;
12498 /* If the symbol has an odd size, it was probably computed
12499 incorrectly, so adjust that as well. */
12500 if ((elf_symbol (*syms)->internal_elf_sym.st_size & 1) != 0)
12501 ++elf_symbol (*syms)->internal_elf_sym.st_size;
12508 /* This function is called whenever a label is defined. It is used
12509 when handling branch delays; if a branch has a label, we assume we
12510 can not move it. */
12513 mips_define_label (sym)
12516 struct insn_label_list *l;
12518 if (free_insn_labels == NULL)
12519 l = (struct insn_label_list *) xmalloc (sizeof *l);
12522 l = free_insn_labels;
12523 free_insn_labels = l->next;
12527 l->next = insn_labels;
12531 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
12533 /* Some special processing for a MIPS ELF file. */
12536 mips_elf_final_processing ()
12538 /* Write out the register information. */
12543 s.ri_gprmask = mips_gprmask;
12544 s.ri_cprmask[0] = mips_cprmask[0];
12545 s.ri_cprmask[1] = mips_cprmask[1];
12546 s.ri_cprmask[2] = mips_cprmask[2];
12547 s.ri_cprmask[3] = mips_cprmask[3];
12548 /* The gp_value field is set by the MIPS ELF backend. */
12550 bfd_mips_elf32_swap_reginfo_out (stdoutput, &s,
12551 ((Elf32_External_RegInfo *)
12552 mips_regmask_frag));
12556 Elf64_Internal_RegInfo s;
12558 s.ri_gprmask = mips_gprmask;
12560 s.ri_cprmask[0] = mips_cprmask[0];
12561 s.ri_cprmask[1] = mips_cprmask[1];
12562 s.ri_cprmask[2] = mips_cprmask[2];
12563 s.ri_cprmask[3] = mips_cprmask[3];
12564 /* The gp_value field is set by the MIPS ELF backend. */
12566 bfd_mips_elf64_swap_reginfo_out (stdoutput, &s,
12567 ((Elf64_External_RegInfo *)
12568 mips_regmask_frag));
12571 /* Set the MIPS ELF flag bits. FIXME: There should probably be some
12572 sort of BFD interface for this. */
12573 if (mips_any_noreorder)
12574 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_NOREORDER;
12575 if (mips_pic != NO_PIC)
12576 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_PIC;
12578 /* Set the MIPS ELF ABI flags. */
12579 if (file_mips_abi == NO_ABI)
12581 else if (file_mips_abi == O32_ABI)
12582 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O32;
12583 else if (file_mips_abi == O64_ABI)
12584 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O64;
12585 else if (file_mips_abi == EABI_ABI)
12588 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI64;
12590 elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI32;
12592 else if (file_mips_abi == N32_ABI)
12593 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ABI2;
12595 /* Nothing to do for "64". */
12597 if (mips_32bitmode)
12598 elf_elfheader (stdoutput)->e_flags |= EF_MIPS_32BITMODE;
12601 #endif /* OBJ_ELF || OBJ_MAYBE_ELF */
12603 typedef struct proc {
12605 unsigned long reg_mask;
12606 unsigned long reg_offset;
12607 unsigned long fpreg_mask;
12608 unsigned long fpreg_offset;
12609 unsigned long frame_offset;
12610 unsigned long frame_reg;
12611 unsigned long pc_reg;
12614 static procS cur_proc;
12615 static procS *cur_proc_ptr;
12616 static int numprocs;
12618 /* Fill in an rs_align_code fragment. */
12621 mips_handle_align (fragp)
12624 if (fragp->fr_type != rs_align_code)
12627 if (mips_opts.mips16)
12629 static const unsigned char be_nop[] = { 0x65, 0x00 };
12630 static const unsigned char le_nop[] = { 0x00, 0x65 };
12635 bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
12636 p = fragp->fr_literal + fragp->fr_fix;
12641 fragp->fr_fix += 1;
12644 memcpy (p, (target_big_endian ? be_nop : le_nop), 2);
12648 /* For mips32, a nop is a zero, which we trivially get by doing nothing. */
12659 /* check for premature end, nesting errors, etc */
12661 as_warn (_("missing .end at end of assembly"));
12670 if (*input_line_pointer == '-')
12672 ++input_line_pointer;
12675 if (!ISDIGIT (*input_line_pointer))
12676 as_bad (_("expected simple number"));
12677 if (input_line_pointer[0] == '0')
12679 if (input_line_pointer[1] == 'x')
12681 input_line_pointer += 2;
12682 while (ISXDIGIT (*input_line_pointer))
12685 val |= hex_value (*input_line_pointer++);
12687 return negative ? -val : val;
12691 ++input_line_pointer;
12692 while (ISDIGIT (*input_line_pointer))
12695 val |= *input_line_pointer++ - '0';
12697 return negative ? -val : val;
12700 if (!ISDIGIT (*input_line_pointer))
12702 printf (_(" *input_line_pointer == '%c' 0x%02x\n"),
12703 *input_line_pointer, *input_line_pointer);
12704 as_warn (_("invalid number"));
12707 while (ISDIGIT (*input_line_pointer))
12710 val += *input_line_pointer++ - '0';
12712 return negative ? -val : val;
12715 /* The .file directive; just like the usual .file directive, but there
12716 is an initial number which is the ECOFF file index. */
12720 int x ATTRIBUTE_UNUSED;
12724 line = get_number ();
12728 /* The .end directive. */
12732 int x ATTRIBUTE_UNUSED;
12737 if (!is_end_of_line[(unsigned char) *input_line_pointer])
12740 demand_empty_rest_of_line ();
12745 #ifdef BFD_ASSEMBLER
12746 if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
12751 if (now_seg != data_section && now_seg != bss_section)
12758 as_warn (_(".end not in text section"));
12762 as_warn (_(".end directive without a preceding .ent directive."));
12763 demand_empty_rest_of_line ();
12769 assert (S_GET_NAME (p));
12770 if (strcmp (S_GET_NAME (p), S_GET_NAME (cur_proc_ptr->isym)))
12771 as_warn (_(".end symbol does not match .ent symbol."));
12774 as_warn (_(".end directive missing or unknown symbol"));
12776 #ifdef MIPS_STABS_ELF
12778 segT saved_seg = now_seg;
12779 subsegT saved_subseg = now_subseg;
12784 dot = frag_now_fix ();
12786 #ifdef md_flush_pending_output
12787 md_flush_pending_output ();
12791 subseg_set (pdr_seg, 0);
12793 /* Write the symbol. */
12794 exp.X_op = O_symbol;
12795 exp.X_add_symbol = p;
12796 exp.X_add_number = 0;
12797 emit_expr (&exp, 4);
12799 fragp = frag_more (7 * 4);
12801 md_number_to_chars (fragp, (valueT) cur_proc_ptr->reg_mask, 4);
12802 md_number_to_chars (fragp + 4, (valueT) cur_proc_ptr->reg_offset, 4);
12803 md_number_to_chars (fragp + 8, (valueT) cur_proc_ptr->fpreg_mask, 4);
12804 md_number_to_chars (fragp + 12, (valueT) cur_proc_ptr->fpreg_offset, 4);
12805 md_number_to_chars (fragp + 16, (valueT) cur_proc_ptr->frame_offset, 4);
12806 md_number_to_chars (fragp + 20, (valueT) cur_proc_ptr->frame_reg, 4);
12807 md_number_to_chars (fragp + 24, (valueT) cur_proc_ptr->pc_reg, 4);
12809 subseg_set (saved_seg, saved_subseg);
12813 cur_proc_ptr = NULL;
12816 /* The .aent and .ent directives. */
12826 symbolP = get_symbol ();
12827 if (*input_line_pointer == ',')
12828 input_line_pointer++;
12829 SKIP_WHITESPACE ();
12830 if (ISDIGIT (*input_line_pointer)
12831 || *input_line_pointer == '-')
12832 number = get_number ();
12834 #ifdef BFD_ASSEMBLER
12835 if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
12840 if (now_seg != data_section && now_seg != bss_section)
12847 as_warn (_(".ent or .aent not in text section."));
12849 if (!aent && cur_proc_ptr)
12850 as_warn (_("missing .end"));
12854 cur_proc_ptr = &cur_proc;
12855 memset (cur_proc_ptr, '\0', sizeof (procS));
12857 cur_proc_ptr->isym = symbolP;
12859 symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION;
12864 demand_empty_rest_of_line ();
12867 /* The .frame directive. If the mdebug section is present (IRIX 5 native)
12868 then ecoff.c (ecoff_directive_frame) is used. For embedded targets,
12869 s_mips_frame is used so that we can set the PDR information correctly.
12870 We can't use the ecoff routines because they make reference to the ecoff
12871 symbol table (in the mdebug section). */
12874 s_mips_frame (ignore)
12875 int ignore ATTRIBUTE_UNUSED;
12877 #ifdef MIPS_STABS_ELF
12881 if (cur_proc_ptr == (procS *) NULL)
12883 as_warn (_(".frame outside of .ent"));
12884 demand_empty_rest_of_line ();
12888 cur_proc_ptr->frame_reg = tc_get_register (1);
12890 SKIP_WHITESPACE ();
12891 if (*input_line_pointer++ != ','
12892 || get_absolute_expression_and_terminator (&val) != ',')
12894 as_warn (_("Bad .frame directive"));
12895 --input_line_pointer;
12896 demand_empty_rest_of_line ();
12900 cur_proc_ptr->frame_offset = val;
12901 cur_proc_ptr->pc_reg = tc_get_register (0);
12903 demand_empty_rest_of_line ();
12906 #endif /* MIPS_STABS_ELF */
12909 /* The .fmask and .mask directives. If the mdebug section is present
12910 (IRIX 5 native) then ecoff.c (ecoff_directive_mask) is used. For
12911 embedded targets, s_mips_mask is used so that we can set the PDR
12912 information correctly. We can't use the ecoff routines because they
12913 make reference to the ecoff symbol table (in the mdebug section). */
12916 s_mips_mask (reg_type)
12919 #ifdef MIPS_STABS_ELF
12922 if (cur_proc_ptr == (procS *) NULL)
12924 as_warn (_(".mask/.fmask outside of .ent"));
12925 demand_empty_rest_of_line ();
12929 if (get_absolute_expression_and_terminator (&mask) != ',')
12931 as_warn (_("Bad .mask/.fmask directive"));
12932 --input_line_pointer;
12933 demand_empty_rest_of_line ();
12937 off = get_absolute_expression ();
12939 if (reg_type == 'F')
12941 cur_proc_ptr->fpreg_mask = mask;
12942 cur_proc_ptr->fpreg_offset = off;
12946 cur_proc_ptr->reg_mask = mask;
12947 cur_proc_ptr->reg_offset = off;
12950 demand_empty_rest_of_line ();
12952 s_ignore (reg_type);
12953 #endif /* MIPS_STABS_ELF */
12956 /* The .loc directive. */
12967 assert (now_seg == text_section);
12969 lineno = get_number ();
12970 addroff = frag_now_fix ();
12972 symbolP = symbol_new ("", N_SLINE, addroff, frag_now);
12973 S_SET_TYPE (symbolP, N_SLINE);
12974 S_SET_OTHER (symbolP, 0);
12975 S_SET_DESC (symbolP, lineno);
12976 symbolP->sy_segment = now_seg;
12980 /* CPU name/ISA/number mapping table.
12982 Entries are grouped by type. The first matching CPU or ISA entry
12983 gets chosen by CPU or ISA, so it should be the 'canonical' name
12984 for that type. Entries after that within the type are sorted
12987 Case is ignored in comparison, so put the canonical entry in the
12988 appropriate case but everything else in lower case to ease eye pain. */
12989 static const struct mips_cpu_info mips_cpu_info_table[] =
12992 { "MIPS1", 1, ISA_MIPS1, CPU_R3000, },
12993 { "mips", 1, ISA_MIPS1, CPU_R3000, },
12996 { "MIPS2", 1, ISA_MIPS2, CPU_R6000, },
12999 { "MIPS3", 1, ISA_MIPS3, CPU_R4000, },
13002 { "MIPS4", 1, ISA_MIPS4, CPU_R8000, },
13005 { "MIPS5", 1, ISA_MIPS5, CPU_MIPS5, },
13006 { "Generic-MIPS5", 0, ISA_MIPS5, CPU_MIPS5, },
13009 { "MIPS32", 1, ISA_MIPS32, CPU_MIPS32, },
13010 { "mipsisa32", 0, ISA_MIPS32, CPU_MIPS32, },
13011 { "Generic-MIPS32", 0, ISA_MIPS32, CPU_MIPS32, },
13012 { "4kc", 0, ISA_MIPS32, CPU_MIPS32, },
13013 { "4km", 0, ISA_MIPS32, CPU_MIPS32, },
13014 { "4kp", 0, ISA_MIPS32, CPU_MIPS32, },
13016 /* For historical reasons. */
13017 { "MIPS64", 1, ISA_MIPS3, CPU_R4000, },
13020 { "mipsisa64", 1, ISA_MIPS64, CPU_MIPS64, },
13021 { "Generic-MIPS64", 0, ISA_MIPS64, CPU_MIPS64, },
13022 { "5kc", 0, ISA_MIPS64, CPU_MIPS64, },
13023 { "20kc", 0, ISA_MIPS64, CPU_MIPS64, },
13026 { "R2000", 0, ISA_MIPS1, CPU_R2000, },
13027 { "2000", 0, ISA_MIPS1, CPU_R2000, },
13028 { "2k", 0, ISA_MIPS1, CPU_R2000, },
13029 { "r2k", 0, ISA_MIPS1, CPU_R2000, },
13032 { "R3000", 0, ISA_MIPS1, CPU_R3000, },
13033 { "3000", 0, ISA_MIPS1, CPU_R3000, },
13034 { "3k", 0, ISA_MIPS1, CPU_R3000, },
13035 { "r3k", 0, ISA_MIPS1, CPU_R3000, },
13038 { "R3900", 0, ISA_MIPS1, CPU_R3900, },
13039 { "3900", 0, ISA_MIPS1, CPU_R3900, },
13040 { "mipstx39", 0, ISA_MIPS1, CPU_R3900, },
13043 { "R4000", 0, ISA_MIPS3, CPU_R4000, },
13044 { "4000", 0, ISA_MIPS3, CPU_R4000, },
13045 { "4k", 0, ISA_MIPS3, CPU_R4000, }, /* beware */
13046 { "r4k", 0, ISA_MIPS3, CPU_R4000, },
13049 { "R4010", 0, ISA_MIPS2, CPU_R4010, },
13050 { "4010", 0, ISA_MIPS2, CPU_R4010, },
13053 { "R4400", 0, ISA_MIPS3, CPU_R4400, },
13054 { "4400", 0, ISA_MIPS3, CPU_R4400, },
13057 { "R4600", 0, ISA_MIPS3, CPU_R4600, },
13058 { "4600", 0, ISA_MIPS3, CPU_R4600, },
13059 { "mips64orion", 0, ISA_MIPS3, CPU_R4600, },
13060 { "orion", 0, ISA_MIPS3, CPU_R4600, },
13063 { "R4650", 0, ISA_MIPS3, CPU_R4650, },
13064 { "4650", 0, ISA_MIPS3, CPU_R4650, },
13067 { "R6000", 0, ISA_MIPS2, CPU_R6000, },
13068 { "6000", 0, ISA_MIPS2, CPU_R6000, },
13069 { "6k", 0, ISA_MIPS2, CPU_R6000, },
13070 { "r6k", 0, ISA_MIPS2, CPU_R6000, },
13073 { "R8000", 0, ISA_MIPS4, CPU_R8000, },
13074 { "8000", 0, ISA_MIPS4, CPU_R8000, },
13075 { "8k", 0, ISA_MIPS4, CPU_R8000, },
13076 { "r8k", 0, ISA_MIPS4, CPU_R8000, },
13079 { "R10000", 0, ISA_MIPS4, CPU_R10000, },
13080 { "10000", 0, ISA_MIPS4, CPU_R10000, },
13081 { "10k", 0, ISA_MIPS4, CPU_R10000, },
13082 { "r10k", 0, ISA_MIPS4, CPU_R10000, },
13085 { "R12000", 0, ISA_MIPS4, CPU_R12000, },
13086 { "12000", 0, ISA_MIPS4, CPU_R12000, },
13087 { "12k", 0, ISA_MIPS4, CPU_R12000, },
13088 { "r12k", 0, ISA_MIPS4, CPU_R12000, },
13091 { "VR4100", 0, ISA_MIPS3, CPU_VR4100, },
13092 { "4100", 0, ISA_MIPS3, CPU_VR4100, },
13093 { "mips64vr4100", 0, ISA_MIPS3, CPU_VR4100, },
13094 { "r4100", 0, ISA_MIPS3, CPU_VR4100, },
13097 { "VR4111", 0, ISA_MIPS3, CPU_R4111, },
13098 { "4111", 0, ISA_MIPS3, CPU_R4111, },
13099 { "mips64vr4111", 0, ISA_MIPS3, CPU_R4111, },
13100 { "r4111", 0, ISA_MIPS3, CPU_R4111, },
13103 { "VR4300", 0, ISA_MIPS3, CPU_R4300, },
13104 { "4300", 0, ISA_MIPS3, CPU_R4300, },
13105 { "mips64vr4300", 0, ISA_MIPS3, CPU_R4300, },
13106 { "r4300", 0, ISA_MIPS3, CPU_R4300, },
13109 { "VR5000", 0, ISA_MIPS4, CPU_R5000, },
13110 { "5000", 0, ISA_MIPS4, CPU_R5000, },
13111 { "5k", 0, ISA_MIPS4, CPU_R5000, },
13112 { "mips64vr5000", 0, ISA_MIPS4, CPU_R5000, },
13113 { "r5000", 0, ISA_MIPS4, CPU_R5000, },
13114 { "r5200", 0, ISA_MIPS4, CPU_R5000, },
13115 { "rm5200", 0, ISA_MIPS4, CPU_R5000, },
13116 { "r5230", 0, ISA_MIPS4, CPU_R5000, },
13117 { "rm5230", 0, ISA_MIPS4, CPU_R5000, },
13118 { "r5231", 0, ISA_MIPS4, CPU_R5000, },
13119 { "rm5231", 0, ISA_MIPS4, CPU_R5000, },
13120 { "r5261", 0, ISA_MIPS4, CPU_R5000, },
13121 { "rm5261", 0, ISA_MIPS4, CPU_R5000, },
13122 { "r5721", 0, ISA_MIPS4, CPU_R5000, },
13123 { "rm5721", 0, ISA_MIPS4, CPU_R5000, },
13124 { "r5k", 0, ISA_MIPS4, CPU_R5000, },
13125 { "r7000", 0, ISA_MIPS4, CPU_R5000, },
13127 /* Broadcom SB-1 CPU */
13128 { "SB-1", 0, ISA_MIPS64, CPU_SB1, },
13129 { "sb-1250", 0, ISA_MIPS64, CPU_SB1, },
13130 { "sb1", 0, ISA_MIPS64, CPU_SB1, },
13131 { "sb1250", 0, ISA_MIPS64, CPU_SB1, },
13134 { NULL, 0, 0, 0, },
13137 static const struct mips_cpu_info *
13138 mips_cpu_info_from_name (name)
13143 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
13144 if (strcasecmp (name, mips_cpu_info_table[i].name) == 0)
13145 return (&mips_cpu_info_table[i]);
13150 static const struct mips_cpu_info *
13151 mips_cpu_info_from_isa (isa)
13156 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
13157 if (mips_cpu_info_table[i].is_isa
13158 && isa == mips_cpu_info_table[i].isa)
13159 return (&mips_cpu_info_table[i]);
13164 static const struct mips_cpu_info *
13165 mips_cpu_info_from_cpu (cpu)
13170 for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
13171 if (!mips_cpu_info_table[i].is_isa
13172 && cpu == mips_cpu_info_table[i].cpu)
13173 return (&mips_cpu_info_table[i]);